xref: /linux/drivers/reset/starfive/reset-starfive-jh7110.c (revision 82327b127d4117e5b867cca945f97a5074aef786)
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 "reset-starfive-jh71x0.h"
11 
12 #include <dt-bindings/reset/starfive,jh7110-crg.h>
13 
14 struct jh7110_reset_info {
15 	unsigned int nr_resets;
16 	unsigned int assert_offset;
17 	unsigned int status_offset;
18 };
19 
20 static const struct jh7110_reset_info jh7110_sys_info = {
21 	.nr_resets = JH7110_SYSRST_END,
22 	.assert_offset = 0x2F8,
23 	.status_offset = 0x308,
24 };
25 
26 static const struct jh7110_reset_info jh7110_aon_info = {
27 	.nr_resets = JH7110_AONRST_END,
28 	.assert_offset = 0x38,
29 	.status_offset = 0x3C,
30 };
31 
32 static int jh7110_reset_probe(struct auxiliary_device *adev,
33 			      const struct auxiliary_device_id *id)
34 {
35 	struct jh7110_reset_info *info = (struct jh7110_reset_info *)(id->driver_data);
36 	void __iomem **base = (void __iomem **)dev_get_drvdata(adev->dev.parent);
37 
38 	if (!info || !base)
39 		return -ENODEV;
40 
41 	return reset_starfive_jh71x0_register(&adev->dev, adev->dev.parent->of_node,
42 					      *base + info->assert_offset,
43 					      *base + info->status_offset,
44 					      NULL,
45 					      info->nr_resets,
46 					      NULL);
47 }
48 
49 static const struct auxiliary_device_id jh7110_reset_ids[] = {
50 	{
51 		.name = "clk_starfive_jh7110_sys.rst-sys",
52 		.driver_data = (kernel_ulong_t)&jh7110_sys_info,
53 	},
54 	{
55 		.name = "clk_starfive_jh7110_sys.rst-aon",
56 		.driver_data = (kernel_ulong_t)&jh7110_aon_info,
57 	},
58 	{ /* sentinel */ }
59 };
60 MODULE_DEVICE_TABLE(auxiliary, jh7110_reset_ids);
61 
62 static struct auxiliary_driver jh7110_reset_driver = {
63 	.probe		= jh7110_reset_probe,
64 	.id_table	= jh7110_reset_ids,
65 };
66 module_auxiliary_driver(jh7110_reset_driver);
67 
68 MODULE_AUTHOR("Hal Feng <hal.feng@starfivetech.com>");
69 MODULE_DESCRIPTION("StarFive JH7110 reset driver");
70 MODULE_LICENSE("GPL");
71