12c138ee3SJerome Brunet // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
22c138ee3SJerome Brunet /*
32c138ee3SJerome Brunet * Amlogic Meson Reset Controller driver
42c138ee3SJerome Brunet *
5c38ae95cSJerome Brunet * Copyright (c) 2016-2024 BayLibre, SAS.
6c38ae95cSJerome Brunet * Authors: Neil Armstrong <narmstrong@baylibre.com>
7c38ae95cSJerome Brunet * Jerome Brunet <jbrunet@baylibre.com>
82c138ee3SJerome Brunet */
9c38ae95cSJerome Brunet
102c138ee3SJerome Brunet #include <linux/err.h>
112c138ee3SJerome Brunet #include <linux/io.h>
122c138ee3SJerome Brunet #include <linux/of.h>
132c138ee3SJerome Brunet #include <linux/module.h>
142c138ee3SJerome Brunet #include <linux/platform_device.h>
152c138ee3SJerome Brunet #include <linux/regmap.h>
162c138ee3SJerome Brunet #include <linux/reset-controller.h>
172c138ee3SJerome Brunet
18c38ae95cSJerome Brunet #include "reset-meson.h"
192c138ee3SJerome Brunet
202c138ee3SJerome Brunet static const struct meson_reset_param meson8b_param = {
21fb4c3158SJerome Brunet .reset_ops = &meson_reset_ops,
222c138ee3SJerome Brunet .reset_num = 256,
232c138ee3SJerome Brunet .reset_offset = 0x0,
242c138ee3SJerome Brunet .level_offset = 0x7c,
252c138ee3SJerome Brunet .level_low_reset = true,
262c138ee3SJerome Brunet };
272c138ee3SJerome Brunet
282c138ee3SJerome Brunet static const struct meson_reset_param meson_a1_param = {
29fb4c3158SJerome Brunet .reset_ops = &meson_reset_ops,
302c138ee3SJerome Brunet .reset_num = 96,
312c138ee3SJerome Brunet .reset_offset = 0x0,
322c138ee3SJerome Brunet .level_offset = 0x40,
332c138ee3SJerome Brunet .level_low_reset = true,
342c138ee3SJerome Brunet };
352c138ee3SJerome Brunet
362c138ee3SJerome Brunet static const struct meson_reset_param meson_s4_param = {
37fb4c3158SJerome Brunet .reset_ops = &meson_reset_ops,
382c138ee3SJerome Brunet .reset_num = 192,
392c138ee3SJerome Brunet .reset_offset = 0x0,
402c138ee3SJerome Brunet .level_offset = 0x40,
412c138ee3SJerome Brunet .level_low_reset = true,
422c138ee3SJerome Brunet };
432c138ee3SJerome Brunet
442c138ee3SJerome Brunet static const struct meson_reset_param t7_param = {
452c138ee3SJerome Brunet .reset_num = 224,
462c138ee3SJerome Brunet .reset_offset = 0x0,
472c138ee3SJerome Brunet .level_offset = 0x40,
482c138ee3SJerome Brunet .level_low_reset = true,
492c138ee3SJerome Brunet };
502c138ee3SJerome Brunet
512c138ee3SJerome Brunet static const struct of_device_id meson_reset_dt_ids[] = {
522c138ee3SJerome Brunet { .compatible = "amlogic,meson8b-reset", .data = &meson8b_param},
532c138ee3SJerome Brunet { .compatible = "amlogic,meson-gxbb-reset", .data = &meson8b_param},
542c138ee3SJerome Brunet { .compatible = "amlogic,meson-axg-reset", .data = &meson8b_param},
552c138ee3SJerome Brunet { .compatible = "amlogic,meson-a1-reset", .data = &meson_a1_param},
562c138ee3SJerome Brunet { .compatible = "amlogic,meson-s4-reset", .data = &meson_s4_param},
572c138ee3SJerome Brunet { .compatible = "amlogic,c3-reset", .data = &meson_s4_param},
582c138ee3SJerome Brunet { .compatible = "amlogic,t7-reset", .data = &t7_param},
592c138ee3SJerome Brunet { /* sentinel */ },
602c138ee3SJerome Brunet };
612c138ee3SJerome Brunet MODULE_DEVICE_TABLE(of, meson_reset_dt_ids);
622c138ee3SJerome Brunet
632c138ee3SJerome Brunet static const struct regmap_config regmap_config = {
642c138ee3SJerome Brunet .reg_bits = 32,
652c138ee3SJerome Brunet .val_bits = 32,
662c138ee3SJerome Brunet .reg_stride = 4,
672c138ee3SJerome Brunet };
682c138ee3SJerome Brunet
meson_reset_probe(struct platform_device * pdev)692c138ee3SJerome Brunet static int meson_reset_probe(struct platform_device *pdev)
702c138ee3SJerome Brunet {
71c38ae95cSJerome Brunet const struct meson_reset_param *param;
722c138ee3SJerome Brunet struct device *dev = &pdev->dev;
73c38ae95cSJerome Brunet struct regmap *map;
742c138ee3SJerome Brunet void __iomem *base;
752c138ee3SJerome Brunet
762c138ee3SJerome Brunet base = devm_platform_ioremap_resource(pdev, 0);
772c138ee3SJerome Brunet if (IS_ERR(base))
782c138ee3SJerome Brunet return PTR_ERR(base);
792c138ee3SJerome Brunet
80c38ae95cSJerome Brunet param = device_get_match_data(dev);
81c38ae95cSJerome Brunet if (!param)
822c138ee3SJerome Brunet return -ENODEV;
832c138ee3SJerome Brunet
84c38ae95cSJerome Brunet map = devm_regmap_init_mmio(dev, base, ®map_config);
85c38ae95cSJerome Brunet if (IS_ERR(map))
86c38ae95cSJerome Brunet return dev_err_probe(dev, PTR_ERR(map),
872c138ee3SJerome Brunet "can't init regmap mmio region\n");
882c138ee3SJerome Brunet
89c38ae95cSJerome Brunet return meson_reset_controller_register(dev, map, param);
902c138ee3SJerome Brunet }
912c138ee3SJerome Brunet
922c138ee3SJerome Brunet static struct platform_driver meson_reset_driver = {
932c138ee3SJerome Brunet .probe = meson_reset_probe,
942c138ee3SJerome Brunet .driver = {
952c138ee3SJerome Brunet .name = "meson_reset",
962c138ee3SJerome Brunet .of_match_table = meson_reset_dt_ids,
972c138ee3SJerome Brunet },
982c138ee3SJerome Brunet };
992c138ee3SJerome Brunet module_platform_driver(meson_reset_driver);
1002c138ee3SJerome Brunet
1012c138ee3SJerome Brunet MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver");
1022c138ee3SJerome Brunet MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
103c38ae95cSJerome Brunet MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
1042c138ee3SJerome Brunet MODULE_LICENSE("Dual BSD/GPL");
105*cdd30ebbSPeter Zijlstra MODULE_IMPORT_NS("MESON_RESET");
106