12c138ee3SJerome Brunet // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 22c138ee3SJerome Brunet /* 32c138ee3SJerome Brunet * Amlogic Meson Reset Controller driver 42c138ee3SJerome Brunet * 5*c38ae95cSJerome Brunet * Copyright (c) 2016-2024 BayLibre, SAS. 6*c38ae95cSJerome Brunet * Authors: Neil Armstrong <narmstrong@baylibre.com> 7*c38ae95cSJerome Brunet * Jerome Brunet <jbrunet@baylibre.com> 82c138ee3SJerome Brunet */ 9*c38ae95cSJerome 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 18*c38ae95cSJerome Brunet #include "reset-meson.h" 192c138ee3SJerome Brunet 202c138ee3SJerome Brunet static const struct meson_reset_param meson8b_param = { 212c138ee3SJerome Brunet .reset_num = 256, 222c138ee3SJerome Brunet .reset_offset = 0x0, 232c138ee3SJerome Brunet .level_offset = 0x7c, 242c138ee3SJerome Brunet .level_low_reset = true, 252c138ee3SJerome Brunet }; 262c138ee3SJerome Brunet 272c138ee3SJerome Brunet static const struct meson_reset_param meson_a1_param = { 282c138ee3SJerome Brunet .reset_num = 96, 292c138ee3SJerome Brunet .reset_offset = 0x0, 302c138ee3SJerome Brunet .level_offset = 0x40, 312c138ee3SJerome Brunet .level_low_reset = true, 322c138ee3SJerome Brunet }; 332c138ee3SJerome Brunet 342c138ee3SJerome Brunet static const struct meson_reset_param meson_s4_param = { 352c138ee3SJerome Brunet .reset_num = 192, 362c138ee3SJerome Brunet .reset_offset = 0x0, 372c138ee3SJerome Brunet .level_offset = 0x40, 382c138ee3SJerome Brunet .level_low_reset = true, 392c138ee3SJerome Brunet }; 402c138ee3SJerome Brunet 412c138ee3SJerome Brunet static const struct meson_reset_param t7_param = { 422c138ee3SJerome Brunet .reset_num = 224, 432c138ee3SJerome Brunet .reset_offset = 0x0, 442c138ee3SJerome Brunet .level_offset = 0x40, 452c138ee3SJerome Brunet .level_low_reset = true, 462c138ee3SJerome Brunet }; 472c138ee3SJerome Brunet 482c138ee3SJerome Brunet static const struct of_device_id meson_reset_dt_ids[] = { 492c138ee3SJerome Brunet { .compatible = "amlogic,meson8b-reset", .data = &meson8b_param}, 502c138ee3SJerome Brunet { .compatible = "amlogic,meson-gxbb-reset", .data = &meson8b_param}, 512c138ee3SJerome Brunet { .compatible = "amlogic,meson-axg-reset", .data = &meson8b_param}, 522c138ee3SJerome Brunet { .compatible = "amlogic,meson-a1-reset", .data = &meson_a1_param}, 532c138ee3SJerome Brunet { .compatible = "amlogic,meson-s4-reset", .data = &meson_s4_param}, 542c138ee3SJerome Brunet { .compatible = "amlogic,c3-reset", .data = &meson_s4_param}, 552c138ee3SJerome Brunet { .compatible = "amlogic,t7-reset", .data = &t7_param}, 562c138ee3SJerome Brunet { /* sentinel */ }, 572c138ee3SJerome Brunet }; 582c138ee3SJerome Brunet MODULE_DEVICE_TABLE(of, meson_reset_dt_ids); 592c138ee3SJerome Brunet 602c138ee3SJerome Brunet static const struct regmap_config regmap_config = { 612c138ee3SJerome Brunet .reg_bits = 32, 622c138ee3SJerome Brunet .val_bits = 32, 632c138ee3SJerome Brunet .reg_stride = 4, 642c138ee3SJerome Brunet }; 652c138ee3SJerome Brunet 662c138ee3SJerome Brunet static int meson_reset_probe(struct platform_device *pdev) 672c138ee3SJerome Brunet { 68*c38ae95cSJerome Brunet const struct meson_reset_param *param; 692c138ee3SJerome Brunet struct device *dev = &pdev->dev; 70*c38ae95cSJerome Brunet struct regmap *map; 712c138ee3SJerome Brunet void __iomem *base; 722c138ee3SJerome Brunet 732c138ee3SJerome Brunet base = devm_platform_ioremap_resource(pdev, 0); 742c138ee3SJerome Brunet if (IS_ERR(base)) 752c138ee3SJerome Brunet return PTR_ERR(base); 762c138ee3SJerome Brunet 77*c38ae95cSJerome Brunet param = device_get_match_data(dev); 78*c38ae95cSJerome Brunet if (!param) 792c138ee3SJerome Brunet return -ENODEV; 802c138ee3SJerome Brunet 81*c38ae95cSJerome Brunet map = devm_regmap_init_mmio(dev, base, ®map_config); 82*c38ae95cSJerome Brunet if (IS_ERR(map)) 83*c38ae95cSJerome Brunet return dev_err_probe(dev, PTR_ERR(map), 842c138ee3SJerome Brunet "can't init regmap mmio region\n"); 852c138ee3SJerome Brunet 86*c38ae95cSJerome Brunet return meson_reset_controller_register(dev, map, param); 872c138ee3SJerome Brunet } 882c138ee3SJerome Brunet 892c138ee3SJerome Brunet static struct platform_driver meson_reset_driver = { 902c138ee3SJerome Brunet .probe = meson_reset_probe, 912c138ee3SJerome Brunet .driver = { 922c138ee3SJerome Brunet .name = "meson_reset", 932c138ee3SJerome Brunet .of_match_table = meson_reset_dt_ids, 942c138ee3SJerome Brunet }, 952c138ee3SJerome Brunet }; 962c138ee3SJerome Brunet module_platform_driver(meson_reset_driver); 972c138ee3SJerome Brunet 982c138ee3SJerome Brunet MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver"); 992c138ee3SJerome Brunet MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); 100*c38ae95cSJerome Brunet MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>"); 1012c138ee3SJerome Brunet MODULE_LICENSE("Dual BSD/GPL"); 102*c38ae95cSJerome Brunet MODULE_IMPORT_NS(MESON_RESET); 103