1 From d8d7a5805579db687fdfdfda4125b43d6a50e616 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Tue, 24 Sep 2013 11:07:43 +0300
4 Subject: [PATCH] reset: Add Allwinner A31 Reset Controller Driver
6 The Allwinner A31 has an IP maintaining a few other IPs in the SoC in
7 reset by default. Among these IPs are the High Speed Timers, hence why
8 we can't use the regular driver construct, and need to call the
9 registering function directly during machine initialisation.
11 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
13 drivers/reset/Makefile | 1 +
14 drivers/reset/reset-sunxi.c | 156 ++++++++++++++++++++++++++++++++++++++++++++
15 2 files changed, 157 insertions(+)
16 create mode 100644 drivers/reset/reset-sunxi.c
18 diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
19 index 1e2d83f..f216b74 100644
20 --- a/drivers/reset/Makefile
21 +++ b/drivers/reset/Makefile
23 obj-$(CONFIG_RESET_CONTROLLER) += core.o
24 +obj-$(CONFIG_ARCH_SUNXI) += reset-sun6i.o
25 diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c
27 index 0000000..5bbd59a
29 +++ b/drivers/reset/reset-sunxi.c
32 + * Allwinner SoCs Reset Controller driver
34 + * Copyright 2013 Maxime Ripard
36 + * Maxime Ripard <maxime.ripard@free-electrons.com>
38 + * This program is free software; you can redistribute it and/or modify
39 + * it under the terms of the GNU General Public License as published by
40 + * the Free Software Foundation; either version 2 of the License, or
41 + * (at your option) any later version.
44 +#include <linux/err.h>
45 +#include <linux/io.h>
46 +#include <linux/module.h>
47 +#include <linux/of.h>
48 +#include <linux/of_address.h>
49 +#include <linux/platform_device.h>
50 +#include <linux/reset-controller.h>
51 +#include <linux/slab.h>
52 +#include <linux/types.h>
54 +struct sunxi_reset_data {
55 + void __iomem *membase;
56 + struct reset_controller_dev rcdev;
59 +static int sunxi_reset_assert(struct reset_controller_dev *rcdev,
62 + struct sunxi_reset_data *data = container_of(rcdev,
63 + struct sunxi_reset_data,
65 + int bank = id / BITS_PER_LONG;
66 + int offset = id % BITS_PER_LONG;
67 + u32 reg = readl(data->membase + (bank * 4));
69 + writel(reg & ~BIT(offset), data->membase + (bank * 4));
74 +static int sunxi_reset_deassert(struct reset_controller_dev *rcdev,
77 + struct sunxi_reset_data *data = container_of(rcdev,
78 + struct sunxi_reset_data,
80 + int bank = id / BITS_PER_LONG;
81 + int offset = id % BITS_PER_LONG;
82 + u32 reg = readl(data->membase + (bank * 4));
84 + writel(reg | BIT(offset), data->membase + (bank * 4));
89 +static struct reset_control_ops sunxi_reset_ops = {
90 + .assert = sunxi_reset_assert,
91 + .deassert = sunxi_reset_deassert,
94 +static int sunxi_reset_init(struct device_node *np)
96 + struct sunxi_reset_data *data;
97 + struct resource res;
98 + resource_size_t size;
101 + data = kzalloc(sizeof(*data), GFP_KERNEL);
105 + ret = of_address_to_resource(np, 0, &res);
109 + size = resource_size(&res);
110 + data->membase = ioremap(res.start, size);
111 + if (!data->membase) {
116 + data->rcdev.owner = THIS_MODULE;
117 + data->rcdev.nr_resets = size * 32;
118 + data->rcdev.ops = &sunxi_reset_ops;
119 + data->rcdev.of_node = np;
120 + reset_controller_register(&data->rcdev);
130 + * These are the reset controller we need to initialize early on in
131 + * our system, before we can even think of using a regular device
134 +static const struct of_device_id sunxi_early_reset_dt_ids[] __initdata = {
135 + { .compatible = "allwinner,sun6i-a31-ahb1-reset", },
136 + { /* sentinel */ },
139 +void __init sun6i_reset_init(void)
141 + struct device_node *np;
143 + for_each_matching_node(np, sunxi_early_reset_dt_ids)
144 + sunxi_reset_init(np);
148 + * And these are the controllers we can register through the regular
151 +static const struct of_device_id sunxi_reset_dt_ids[] = {
152 + { .compatible = "allwinner,sun4i-clock-reset", },
153 + { /* sentinel */ },
155 +MODULE_DEVICE_TABLE(of, sunxi_reset_dt_ids);
157 +static int sunxi_reset_probe(struct platform_device *pdev)
159 + return sunxi_reset_init(pdev->dev.of_node);
162 +static int sunxi_reset_remove(struct platform_device *pdev)
164 + struct sunxi_reset_data *data = platform_get_drvdata(pdev);
166 + reset_controller_unregister(&data->rcdev);
167 + iounmap(data->membase);
173 +static struct platform_driver sunxi_reset_driver = {
174 + .probe = sunxi_reset_probe,
175 + .remove = sunxi_reset_remove,
177 + .name = "sunxi-reset",
178 + .owner = THIS_MODULE,
179 + .of_match_table = sunxi_reset_dt_ids,
182 +module_platform_driver(sunxi_reset_driver);
184 +MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com");
185 +MODULE_DESCRIPTION("Allwinner SoCs Reset Controller Driver");
186 +MODULE_LICENSE("GPL");