xref: /linux/drivers/reset/starfive/reset-starfive-jh7110.c (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Reset driver for the StarFive JH7110 SoC
4  *
5  * Copyright (C) 2022 StarFive Technology Co., Ltd.
6  */
7 
8 #include <linux/auxiliary_bus.h>
9 
10 #include <soc/starfive/reset-starfive-jh71x0.h>
11 
12 #include "reset-starfive-jh71x0.h"
13 
14 #include <dt-bindings/reset/starfive,jh7110-crg.h>
15 
16 struct jh7110_reset_info {
17 	unsigned int nr_resets;
18 	unsigned int assert_offset;
19 	unsigned int status_offset;
20 };
21 
22 static const struct jh7110_reset_info jh7110_sys_info = {
23 	.nr_resets = JH7110_SYSRST_END,
24 	.assert_offset = 0x2F8,
25 	.status_offset = 0x308,
26 };
27 
28 static const struct jh7110_reset_info jh7110_aon_info = {
29 	.nr_resets = JH7110_AONRST_END,
30 	.assert_offset = 0x38,
31 	.status_offset = 0x3C,
32 };
33 
34 static const struct jh7110_reset_info jh7110_stg_info = {
35 	.nr_resets = JH7110_STGRST_END,
36 	.assert_offset = 0x74,
37 	.status_offset = 0x78,
38 };
39 
40 static const struct jh7110_reset_info jh7110_isp_info = {
41 	.nr_resets = JH7110_ISPRST_END,
42 	.assert_offset = 0x38,
43 	.status_offset = 0x3C,
44 };
45 
46 static const struct jh7110_reset_info jh7110_vout_info = {
47 	.nr_resets = JH7110_VOUTRST_END,
48 	.assert_offset = 0x48,
49 	.status_offset = 0x4C,
50 };
51 
52 static int jh7110_reset_probe(struct auxiliary_device *adev,
53 			      const struct auxiliary_device_id *id)
54 {
55 	struct jh7110_reset_info *info = (struct jh7110_reset_info *)(id->driver_data);
56 	struct jh71x0_reset_adev *rdev = to_jh71x0_reset_adev(adev);
57 	void __iomem *base = rdev->base;
58 
59 	if (!info || !base)
60 		return -ENODEV;
61 
62 	return reset_starfive_jh71x0_register(&adev->dev, adev->dev.parent->of_node,
63 					      base + info->assert_offset,
64 					      base + info->status_offset,
65 					      NULL,
66 					      info->nr_resets,
67 					      NULL);
68 }
69 
70 static const struct auxiliary_device_id jh7110_reset_ids[] = {
71 	{
72 		.name = "clk_starfive_jh7110_sys.rst-sys",
73 		.driver_data = (kernel_ulong_t)&jh7110_sys_info,
74 	},
75 	{
76 		.name = "clk_starfive_jh7110_sys.rst-aon",
77 		.driver_data = (kernel_ulong_t)&jh7110_aon_info,
78 	},
79 	{
80 		.name = "clk_starfive_jh7110_sys.rst-stg",
81 		.driver_data = (kernel_ulong_t)&jh7110_stg_info,
82 	},
83 	{
84 		.name = "clk_starfive_jh7110_sys.rst-isp",
85 		.driver_data = (kernel_ulong_t)&jh7110_isp_info,
86 	},
87 	{
88 		.name = "clk_starfive_jh7110_sys.rst-vo",
89 		.driver_data = (kernel_ulong_t)&jh7110_vout_info,
90 	},
91 	{ /* sentinel */ }
92 };
93 MODULE_DEVICE_TABLE(auxiliary, jh7110_reset_ids);
94 
95 static struct auxiliary_driver jh7110_reset_driver = {
96 	.probe		= jh7110_reset_probe,
97 	.id_table	= jh7110_reset_ids,
98 };
99 module_auxiliary_driver(jh7110_reset_driver);
100 
101 MODULE_AUTHOR("Hal Feng <hal.feng@starfivetech.com>");
102 MODULE_DESCRIPTION("StarFive JH7110 reset driver");
103 MODULE_LICENSE("GPL");
104