1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Amlogic Meson Reset Controller driver 4 * 5 * Copyright (c) 2016-2024 BayLibre, SAS. 6 * Authors: Neil Armstrong <narmstrong@baylibre.com> 7 * Jerome Brunet <jbrunet@baylibre.com> 8 */ 9 10 #include <linux/err.h> 11 #include <linux/io.h> 12 #include <linux/of.h> 13 #include <linux/module.h> 14 #include <linux/platform_device.h> 15 #include <linux/regmap.h> 16 #include <linux/reset-controller.h> 17 18 #include "reset-meson.h" 19 20 static const struct meson_reset_param meson8b_param = { 21 .reset_ops = &meson_reset_ops, 22 .reset_num = 256, 23 .reset_offset = 0x0, 24 .level_offset = 0x7c, 25 .level_low_reset = true, 26 }; 27 28 static const struct meson_reset_param meson_a1_param = { 29 .reset_ops = &meson_reset_ops, 30 .reset_num = 96, 31 .reset_offset = 0x0, 32 .level_offset = 0x40, 33 .level_low_reset = true, 34 }; 35 36 static const struct meson_reset_param meson_s4_param = { 37 .reset_ops = &meson_reset_ops, 38 .reset_num = 192, 39 .reset_offset = 0x0, 40 .level_offset = 0x40, 41 .level_low_reset = true, 42 }; 43 44 static const struct meson_reset_param t7_param = { 45 .reset_num = 224, 46 .reset_offset = 0x0, 47 .level_offset = 0x40, 48 .level_low_reset = true, 49 }; 50 51 static const struct of_device_id meson_reset_dt_ids[] = { 52 { .compatible = "amlogic,meson8b-reset", .data = &meson8b_param}, 53 { .compatible = "amlogic,meson-gxbb-reset", .data = &meson8b_param}, 54 { .compatible = "amlogic,meson-axg-reset", .data = &meson8b_param}, 55 { .compatible = "amlogic,meson-a1-reset", .data = &meson_a1_param}, 56 { .compatible = "amlogic,meson-s4-reset", .data = &meson_s4_param}, 57 { .compatible = "amlogic,c3-reset", .data = &meson_s4_param}, 58 { .compatible = "amlogic,t7-reset", .data = &t7_param}, 59 { /* sentinel */ }, 60 }; 61 MODULE_DEVICE_TABLE(of, meson_reset_dt_ids); 62 63 static const struct regmap_config regmap_config = { 64 .reg_bits = 32, 65 .val_bits = 32, 66 .reg_stride = 4, 67 }; 68 69 static int meson_reset_probe(struct platform_device *pdev) 70 { 71 const struct meson_reset_param *param; 72 struct device *dev = &pdev->dev; 73 struct regmap *map; 74 void __iomem *base; 75 76 base = devm_platform_ioremap_resource(pdev, 0); 77 if (IS_ERR(base)) 78 return PTR_ERR(base); 79 80 param = device_get_match_data(dev); 81 if (!param) 82 return -ENODEV; 83 84 map = devm_regmap_init_mmio(dev, base, ®map_config); 85 if (IS_ERR(map)) 86 return dev_err_probe(dev, PTR_ERR(map), 87 "can't init regmap mmio region\n"); 88 89 return meson_reset_controller_register(dev, map, param); 90 } 91 92 static struct platform_driver meson_reset_driver = { 93 .probe = meson_reset_probe, 94 .driver = { 95 .name = "meson_reset", 96 .of_match_table = meson_reset_dt_ids, 97 }, 98 }; 99 module_platform_driver(meson_reset_driver); 100 101 MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver"); 102 MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>"); 103 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>"); 104 MODULE_LICENSE("Dual BSD/GPL"); 105 MODULE_IMPORT_NS(MESON_RESET); 106