xref: /linux/drivers/reset/amlogic/reset-meson.c (revision c38ae95cd31c636ae21fff3e6a9250df680f0cdd)
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_num	= 256,
22 	.reset_offset	= 0x0,
23 	.level_offset	= 0x7c,
24 	.level_low_reset = true,
25 };
26 
27 static const struct meson_reset_param meson_a1_param = {
28 	.reset_num	= 96,
29 	.reset_offset	= 0x0,
30 	.level_offset	= 0x40,
31 	.level_low_reset = true,
32 };
33 
34 static const struct meson_reset_param meson_s4_param = {
35 	.reset_num	= 192,
36 	.reset_offset	= 0x0,
37 	.level_offset	= 0x40,
38 	.level_low_reset = true,
39 };
40 
41 static const struct meson_reset_param t7_param = {
42 	.reset_num      = 224,
43 	.reset_offset	= 0x0,
44 	.level_offset   = 0x40,
45 	.level_low_reset = true,
46 };
47 
48 static const struct of_device_id meson_reset_dt_ids[] = {
49 	 { .compatible = "amlogic,meson8b-reset",    .data = &meson8b_param},
50 	 { .compatible = "amlogic,meson-gxbb-reset", .data = &meson8b_param},
51 	 { .compatible = "amlogic,meson-axg-reset",  .data = &meson8b_param},
52 	 { .compatible = "amlogic,meson-a1-reset",   .data = &meson_a1_param},
53 	 { .compatible = "amlogic,meson-s4-reset",   .data = &meson_s4_param},
54 	 { .compatible = "amlogic,c3-reset",   .data = &meson_s4_param},
55 	 { .compatible = "amlogic,t7-reset",   .data = &t7_param},
56 	 { /* sentinel */ },
57 };
58 MODULE_DEVICE_TABLE(of, meson_reset_dt_ids);
59 
60 static const struct regmap_config regmap_config = {
61 	.reg_bits   = 32,
62 	.val_bits   = 32,
63 	.reg_stride = 4,
64 };
65 
66 static int meson_reset_probe(struct platform_device *pdev)
67 {
68 	const struct meson_reset_param *param;
69 	struct device *dev = &pdev->dev;
70 	struct regmap *map;
71 	void __iomem *base;
72 
73 	base = devm_platform_ioremap_resource(pdev, 0);
74 	if (IS_ERR(base))
75 		return PTR_ERR(base);
76 
77 	param = device_get_match_data(dev);
78 	if (!param)
79 		return -ENODEV;
80 
81 	map = devm_regmap_init_mmio(dev, base, &regmap_config);
82 	if (IS_ERR(map))
83 		return dev_err_probe(dev, PTR_ERR(map),
84 				     "can't init regmap mmio region\n");
85 
86 	return meson_reset_controller_register(dev, map, param);
87 }
88 
89 static struct platform_driver meson_reset_driver = {
90 	.probe	= meson_reset_probe,
91 	.driver = {
92 		.name		= "meson_reset",
93 		.of_match_table	= meson_reset_dt_ids,
94 	},
95 };
96 module_platform_driver(meson_reset_driver);
97 
98 MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver");
99 MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
100 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
101 MODULE_LICENSE("Dual BSD/GPL");
102 MODULE_IMPORT_NS(MESON_RESET);
103