reset: starfive: jh7110: Add StarFive Image-Signal-Process reset support
[platform/kernel/linux-starfive.git] / drivers / reset / starfive / reset-starfive-jh7110.c
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 const struct jh7110_reset_info jh7110_stg_info = {
33         .nr_resets = JH7110_STGRST_END,
34         .assert_offset = 0x74,
35         .status_offset = 0x78,
36 };
37
38 static const struct jh7110_reset_info jh7110_isp_info = {
39         .nr_resets = JH7110_ISPRST_END,
40         .assert_offset = 0x38,
41         .status_offset = 0x3C,
42 };
43
44 static int jh7110_reset_probe(struct auxiliary_device *adev,
45                               const struct auxiliary_device_id *id)
46 {
47         struct jh7110_reset_info *info = (struct jh7110_reset_info *)(id->driver_data);
48         void __iomem **base = (void __iomem **)dev_get_drvdata(adev->dev.parent);
49
50         if (!info || !base)
51                 return -ENODEV;
52
53         return reset_starfive_jh71x0_register(&adev->dev, adev->dev.parent->of_node,
54                                               *base + info->assert_offset,
55                                               *base + info->status_offset,
56                                               NULL,
57                                               info->nr_resets,
58                                               NULL);
59 }
60
61 static const struct auxiliary_device_id jh7110_reset_ids[] = {
62         {
63                 .name = "clk_starfive_jh71x0.reset-sys",
64                 .driver_data = (kernel_ulong_t)&jh7110_sys_info,
65         },
66         {
67                 .name = "clk_starfive_jh71x0.reset-aon",
68                 .driver_data = (kernel_ulong_t)&jh7110_aon_info,
69         },
70         {
71                 .name = "clk_starfive_jh71x0.reset-stg",
72                 .driver_data = (kernel_ulong_t)&jh7110_stg_info,
73         },
74         {
75                 .name = "clk_starfive_jh71x0.reset-isp",
76                 .driver_data = (kernel_ulong_t)&jh7110_isp_info,
77         },
78         { /* sentinel */ }
79 };
80 MODULE_DEVICE_TABLE(auxiliary, jh7110_reset_ids);
81
82 static struct auxiliary_driver jh7110_reset_driver = {
83         .probe          = jh7110_reset_probe,
84         .id_table       = jh7110_reset_ids,
85 };
86 module_auxiliary_driver(jh7110_reset_driver);
87
88 MODULE_AUTHOR("Hal Feng <hal.feng@starfivetech.com>");
89 MODULE_DESCRIPTION("StarFive JH7110 reset driver");
90 MODULE_LICENSE("GPL");