aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Zabel <p.zabel@pengutronix.de>2017-08-11 06:58:43 -0400
committerPhilipp Zabel <p.zabel@pengutronix.de>2017-10-17 09:35:24 -0400
commite13c205ac358d4c956c36572b6b660b9e45b3bda (patch)
treee55a53fd17433af9d452d0eb22a4ab77bdfbd18e
parent81c22ad0cc7db056408d6089c9303b2f6e486518 (diff)
reset: sunxi: use reset-simple driver
Use the newly created copies in the reset-simple driver to replace the sunxi platform driver code and reset operations. The separate sunxi driver still remains to register the early reset controllers, but it reuses the reset operations in reset-simple. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> Reviewed-by: Alexandru Gagniuc <alex.g@adaptrum.com> Reviewed-by: Chen-Yu Tsai <wens@csie.org>
-rw-r--r--drivers/reset/Kconfig1
-rw-r--r--drivers/reset/reset-sunxi.c104
2 files changed, 7 insertions, 98 deletions
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 392e65187cd5..a14c0fe49877 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -100,6 +100,7 @@ config RESET_STM32
100config RESET_SUNXI 100config RESET_SUNXI
101 bool "Allwinner SoCs Reset Driver" if COMPILE_TEST && !ARCH_SUNXI 101 bool "Allwinner SoCs Reset Driver" if COMPILE_TEST && !ARCH_SUNXI
102 default ARCH_SUNXI 102 default ARCH_SUNXI
103 select RESET_SIMPLE
103 help 104 help
104 This enables the reset driver for Allwinner SoCs. 105 This enables the reset driver for Allwinner SoCs.
105 106
diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
index 2c7dd1fd08df..db9a1a75523f 100644
--- a/drivers/reset/reset-sunxi.c
+++ b/drivers/reset/reset-sunxi.c
@@ -22,64 +22,11 @@
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
23#include <linux/types.h> 23#include <linux/types.h>
24 24
25struct sunxi_reset_data { 25#include "reset-simple.h"
26 spinlock_t lock;
27 void __iomem *membase;
28 struct reset_controller_dev rcdev;
29};
30
31static int sunxi_reset_assert(struct reset_controller_dev *rcdev,
32 unsigned long id)
33{
34 struct sunxi_reset_data *data = container_of(rcdev,
35 struct sunxi_reset_data,
36 rcdev);
37 int reg_width = sizeof(u32);
38 int bank = id / (reg_width * BITS_PER_BYTE);
39 int offset = id % (reg_width * BITS_PER_BYTE);
40 unsigned long flags;
41 u32 reg;
42
43 spin_lock_irqsave(&data->lock, flags);
44
45 reg = readl(data->membase + (bank * reg_width));
46 writel(reg & ~BIT(offset), data->membase + (bank * reg_width));
47
48 spin_unlock_irqrestore(&data->lock, flags);
49
50 return 0;
51}
52
53static int sunxi_reset_deassert(struct reset_controller_dev *rcdev,
54 unsigned long id)
55{
56 struct sunxi_reset_data *data = container_of(rcdev,
57 struct sunxi_reset_data,
58 rcdev);
59 int reg_width = sizeof(u32);
60 int bank = id / (reg_width * BITS_PER_BYTE);
61 int offset = id % (reg_width * BITS_PER_BYTE);
62 unsigned long flags;
63 u32 reg;
64
65 spin_lock_irqsave(&data->lock, flags);
66
67 reg = readl(data->membase + (bank * reg_width));
68 writel(reg | BIT(offset), data->membase + (bank * reg_width));
69
70 spin_unlock_irqrestore(&data->lock, flags);
71
72 return 0;
73}
74
75static const struct reset_control_ops sunxi_reset_ops = {
76 .assert = sunxi_reset_assert,
77 .deassert = sunxi_reset_deassert,
78};
79 26
80static int sunxi_reset_init(struct device_node *np) 27static int sunxi_reset_init(struct device_node *np)
81{ 28{
82 struct sunxi_reset_data *data; 29 struct reset_simple_data *data;
83 struct resource res; 30 struct resource res;
84 resource_size_t size; 31 resource_size_t size;
85 int ret; 32 int ret;
@@ -108,8 +55,9 @@ static int sunxi_reset_init(struct device_node *np)
108 55
109 data->rcdev.owner = THIS_MODULE; 56 data->rcdev.owner = THIS_MODULE;
110 data->rcdev.nr_resets = size * 8; 57 data->rcdev.nr_resets = size * 8;
111 data->rcdev.ops = &sunxi_reset_ops; 58 data->rcdev.ops = &reset_simple_ops;
112 data->rcdev.of_node = np; 59 data->rcdev.of_node = np;
60 data->active_low = true;
113 61
114 return reset_controller_register(&data->rcdev); 62 return reset_controller_register(&data->rcdev);
115 63
@@ -122,6 +70,8 @@ err_alloc:
122 * These are the reset controller we need to initialize early on in 70 * These are the reset controller we need to initialize early on in
123 * our system, before we can even think of using a regular device 71 * our system, before we can even think of using a regular device
124 * driver for it. 72 * driver for it.
73 * The controllers that we can register through the regular device
74 * model are handled by the simple reset driver directly.
125 */ 75 */
126static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = { 76static const struct of_device_id sunxi_early_reset_dt_ids[] __initconst = {
127 { .compatible = "allwinner,sun6i-a31-ahb1-reset", }, 77 { .compatible = "allwinner,sun6i-a31-ahb1-reset", },
@@ -135,45 +85,3 @@ void __init sun6i_reset_init(void)
135 for_each_matching_node(np, sunxi_early_reset_dt_ids) 85 for_each_matching_node(np, sunxi_early_reset_dt_ids)
136 sunxi_reset_init(np); 86 sunxi_reset_init(np);
137} 87}
138
139/*
140 * And these are the controllers we can register through the regular
141 * device model.
142 */
143static const struct of_device_id sunxi_reset_dt_ids[] = {
144 { .compatible = "allwinner,sun6i-a31-clock-reset", },
145 { /* sentinel */ },
146};
147
148static int sunxi_reset_probe(struct platform_device *pdev)
149{
150 struct sunxi_reset_data *data;
151 struct resource *res;
152
153 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
154 if (!data)
155 return -ENOMEM;
156
157 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
158 data->membase = devm_ioremap_resource(&pdev->dev, res);
159 if (IS_ERR(data->membase))
160 return PTR_ERR(data->membase);
161
162 spin_lock_init(&data->lock);
163
164 data->rcdev.owner = THIS_MODULE;
165 data->rcdev.nr_resets = resource_size(res) * 8;
166 data->rcdev.ops = &sunxi_reset_ops;
167 data->rcdev.of_node = pdev->dev.of_node;
168
169 return devm_reset_controller_register(&pdev->dev, &data->rcdev);
170}
171
172static struct platform_driver sunxi_reset_driver = {
173 .probe = sunxi_reset_probe,
174 .driver = {
175 .name = "sunxi-reset",
176 .of_match_table = sunxi_reset_dt_ids,
177 },
178};
179builtin_platform_driver(sunxi_reset_driver);