1010#include <linux/io.h>
1111#include <linux/io-64-nonatomic-lo-hi.h>
1212#include <linux/iopoll.h>
13- #include <linux/platform_device.h>
1413#include <linux/reset-controller.h>
1514#include <linux/spinlock.h>
1615
1716#include "reset-starfive-jh71x0.h"
1817
19- #include <dt-bindings/reset/starfive-jh7100.h>
20-
21- /* register offsets */
22- #define JH7100_RESET_ASSERT0 0x00
23- #define JH7100_RESET_ASSERT1 0x04
24- #define JH7100_RESET_ASSERT2 0x08
25- #define JH7100_RESET_ASSERT3 0x0c
26- #define JH7100_RESET_STATUS0 0x10
27- #define JH7100_RESET_STATUS1 0x14
28- #define JH7100_RESET_STATUS2 0x18
29- #define JH7100_RESET_STATUS3 0x1c
30-
31- /*
32- * Writing a 1 to the n'th bit of the m'th ASSERT register asserts
33- * line 32m + n, and writing a 0 deasserts the same line.
34- * Most reset lines have their status inverted so a 0 bit in the STATUS
35- * register means the line is asserted and a 1 means it's deasserted. A few
36- * lines don't though, so store the expected value of the status registers when
37- * all lines are asserted.
38- */
39- static const u64 jh7100_reset_asserted [2 ] = {
40- /* STATUS0 */
41- BIT_ULL_MASK (JH7100_RST_U74 ) |
42- BIT_ULL_MASK (JH7100_RST_VP6_DRESET ) |
43- BIT_ULL_MASK (JH7100_RST_VP6_BRESET ) |
44- /* STATUS1 */
45- BIT_ULL_MASK (JH7100_RST_HIFI4_DRESET ) |
46- BIT_ULL_MASK (JH7100_RST_HIFI4_BRESET ),
47- /* STATUS2 */
48- BIT_ULL_MASK (JH7100_RST_E24 ) |
49- /* STATUS3 */
50- 0 ,
51- };
52-
5318struct jh7100_reset {
5419 struct reset_controller_dev rcdev ;
5520 /* protect registers against concurrent read-modify-write */
5621 spinlock_t lock ;
57- void __iomem * base ;
22+ void __iomem * assert ;
23+ void __iomem * status ;
24+ const u64 * asserted ;
5825};
5926
6027static inline struct jh7100_reset *
@@ -69,9 +36,9 @@ static int jh7100_reset_update(struct reset_controller_dev *rcdev,
6936 struct jh7100_reset * data = jh7100_reset_from (rcdev );
7037 unsigned long offset = BIT_ULL_WORD (id );
7138 u64 mask = BIT_ULL_MASK (id );
72- void __iomem * reg_assert = data -> base + JH7100_RESET_ASSERT0 + offset * sizeof (u64 );
73- void __iomem * reg_status = data -> base + JH7100_RESET_STATUS0 + offset * sizeof (u64 );
74- u64 done = jh7100_reset_asserted [offset ] & mask ;
39+ void __iomem * reg_assert = data -> assert + offset * sizeof (u64 );
40+ void __iomem * reg_status = data -> status + offset * sizeof (u64 );
41+ u64 done = data -> asserted ? data -> asserted [offset ] & mask : 0 ;
7542 u64 value ;
7643 unsigned long flags ;
7744 int ret ;
@@ -125,10 +92,10 @@ static int jh7100_reset_status(struct reset_controller_dev *rcdev,
12592 struct jh7100_reset * data = jh7100_reset_from (rcdev );
12693 unsigned long offset = BIT_ULL_WORD (id );
12794 u64 mask = BIT_ULL_MASK (id );
128- void __iomem * reg_status = data -> base + JH7100_RESET_STATUS0 + offset * sizeof (u64 );
95+ void __iomem * reg_status = data -> status + offset * sizeof (u64 );
12996 u64 value = readq (reg_status );
13097
131- return !((value ^ jh7100_reset_asserted [offset ]) & mask );
98+ return !((value ^ data -> asserted [offset ]) & mask );
13299}
133100
134101static const struct reset_control_ops jh7100_reset_ops = {
@@ -138,25 +105,28 @@ static const struct reset_control_ops jh7100_reset_ops = {
138105 .status = jh7100_reset_status ,
139106};
140107
141- int jh7100_reset_probe (struct platform_device * pdev )
108+ int reset_starfive_jh7100_register (struct device * dev , struct device_node * of_node ,
109+ void __iomem * assert , void __iomem * status ,
110+ const u64 * asserted , unsigned int nr_resets ,
111+ struct module * owner )
142112{
143113 struct jh7100_reset * data ;
144114
145- data = devm_kzalloc (& pdev -> dev , sizeof (* data ), GFP_KERNEL );
115+ data = devm_kzalloc (dev , sizeof (* data ), GFP_KERNEL );
146116 if (!data )
147117 return - ENOMEM ;
148118
149- data -> base = devm_platform_ioremap_resource (pdev , 0 );
150- if (IS_ERR (data -> base ))
151- return PTR_ERR (data -> base );
152-
153119 data -> rcdev .ops = & jh7100_reset_ops ;
154- data -> rcdev .owner = THIS_MODULE ;
155- data -> rcdev .nr_resets = JH7100_RSTN_END ;
156- data -> rcdev .dev = & pdev -> dev ;
157- data -> rcdev .of_node = pdev -> dev .of_node ;
120+ data -> rcdev .owner = owner ;
121+ data -> rcdev .nr_resets = nr_resets ;
122+ data -> rcdev .dev = dev ;
123+ data -> rcdev .of_node = of_node ;
124+
158125 spin_lock_init (& data -> lock );
126+ data -> assert = assert ;
127+ data -> status = status ;
128+ data -> asserted = asserted ;
159129
160- return devm_reset_controller_register (& pdev -> dev , & data -> rcdev );
130+ return devm_reset_controller_register (dev , & data -> rcdev );
161131}
162- EXPORT_SYMBOL_GPL (jh7100_reset_probe );
132+ EXPORT_SYMBOL_GPL (reset_starfive_jh7100_register );
0 commit comments