aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/reset/gpio-reset.txt35
-rw-r--r--drivers/reset/Kconfig11
-rw-r--r--drivers/reset/Makefile1
-rw-r--r--drivers/reset/gpio-reset.c174
4 files changed, 221 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/reset/gpio-reset.txt b/Documentation/devicetree/bindings/reset/gpio-reset.txt
new file mode 100644
index 000000000000..bca5348a5131
--- /dev/null
+++ b/Documentation/devicetree/bindings/reset/gpio-reset.txt
@@ -0,0 +1,35 @@
1GPIO reset controller
2=====================
3
4A GPIO reset controller controls a single GPIO that is connected to the reset
5pin of a peripheral IC. Please also refer to reset.txt in this directory for
6common reset controller binding usage.
7
8Required properties:
9- compatible: Should be "gpio-reset"
10- reset-gpios: A gpio used as reset line. The gpio specifier for this property
11 depends on the gpio controller that provides the gpio.
12- #reset-cells: 0, see below
13
14Optional properties:
15- reset-delay-us: delay in microseconds. The gpio reset line will be asserted for
16 this duration to reset.
17- initially-in-reset: boolean. If not set, the initial state should be a
18 deasserted reset line. If this property exists, the
19 reset line should be kept in reset.
20
21example:
22
23sii902x_reset: gpio-reset {
24 compatible = "gpio-reset";
25 reset-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>;
26 reset-delay-us = <10000>;
27 initially-in-reset;
28 #reset-cells = <0>;
29};
30
31/* Device with nRESET pin connected to GPIO5_0 */
32sii902x@39 {
33 /* ... */
34 resets = <&sii902x_reset>; /* active-low GPIO5_0, 10 ms delay */
35};
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index c9d04f797862..1a862dfe62f6 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -11,3 +11,14 @@ menuconfig RESET_CONTROLLER
11 via GPIOs or SoC-internal reset controller modules. 11 via GPIOs or SoC-internal reset controller modules.
12 12
13 If unsure, say no. 13 If unsure, say no.
14
15if RESET_CONTROLLER
16
17config RESET_GPIO
18 tristate "GPIO reset controller support"
19 depends on GPIOLIB && OF
20 help
21 This driver provides support for reset lines that are controlled
22 directly by GPIOs.
23
24endif
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 1e2d83f2b995..b854f208dfa1 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -1 +1,2 @@
1obj-$(CONFIG_RESET_CONTROLLER) += core.o 1obj-$(CONFIG_RESET_CONTROLLER) += core.o
2obj-$(CONFIG_RESET_GPIO) += gpio-reset.o
diff --git a/drivers/reset/gpio-reset.c b/drivers/reset/gpio-reset.c
new file mode 100644
index 000000000000..5d2515af6a5f
--- /dev/null
+++ b/drivers/reset/gpio-reset.c
@@ -0,0 +1,174 @@
1/*
2 * GPIO Reset Controller driver
3 *
4 * Copyright 2013 Philipp Zabel, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11#include <linux/delay.h>
12#include <linux/err.h>
13#include <linux/gpio.h>
14#include <linux/module.h>
15#include <linux/of_gpio.h>
16#include <linux/platform_device.h>
17#include <linux/reset-controller.h>
18
19struct gpio_reset_data {
20 struct reset_controller_dev rcdev;
21 unsigned int gpio;
22 bool active_low;
23 s32 delay_us;
24};
25
26static void gpio_reset_set(struct reset_controller_dev *rcdev, int asserted)
27{
28 struct gpio_reset_data *drvdata = container_of(rcdev,
29 struct gpio_reset_data, rcdev);
30 int value = asserted;
31
32 if (drvdata->active_low)
33 value = !value;
34
35 gpio_set_value(drvdata->gpio, value);
36}
37
38static int gpio_reset(struct reset_controller_dev *rcdev, unsigned long id)
39{
40 struct gpio_reset_data *drvdata = container_of(rcdev,
41 struct gpio_reset_data, rcdev);
42
43 if (drvdata->delay_us < 0)
44 return -ENOSYS;
45
46 gpio_reset_set(rcdev, 1);
47 udelay(drvdata->delay_us);
48 gpio_reset_set(rcdev, 0);
49
50 return 0;
51}
52
53static int gpio_reset_assert(struct reset_controller_dev *rcdev,
54 unsigned long id)
55{
56 gpio_reset_set(rcdev, 1);
57
58 return 0;
59}
60
61static int gpio_reset_deassert(struct reset_controller_dev *rcdev,
62 unsigned long id)
63{
64 gpio_reset_set(rcdev, 0);
65
66 return 0;
67}
68
69static struct reset_control_ops gpio_reset_ops = {
70 .reset = gpio_reset,
71 .assert = gpio_reset_assert,
72 .deassert = gpio_reset_deassert,
73};
74
75static int of_gpio_reset_xlate(struct reset_controller_dev *rcdev,
76 const struct of_phandle_args *reset_spec)
77{
78 if (WARN_ON(reset_spec->args_count != 0))
79 return -EINVAL;
80
81 return 0;
82}
83
84static int gpio_reset_probe(struct platform_device *pdev)
85{
86 struct device_node *np = pdev->dev.of_node;
87 struct gpio_reset_data *drvdata;
88 enum of_gpio_flags flags;
89 unsigned long gpio_flags;
90 bool initially_in_reset;
91 int ret;
92
93 drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
94 if (drvdata == NULL)
95 return -ENOMEM;
96
97 if (of_gpio_named_count(np, "reset-gpios") != 1) {
98 dev_err(&pdev->dev,
99 "reset-gpios property missing, or not a single gpio\n");
100 return -EINVAL;
101 }
102
103 drvdata->gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &flags);
104 if (drvdata->gpio == -EPROBE_DEFER) {
105 return drvdata->gpio;
106 } else if (!gpio_is_valid(drvdata->gpio)) {
107 dev_err(&pdev->dev, "invalid reset gpio: %d\n", drvdata->gpio);
108 return drvdata->gpio;
109 }
110
111 drvdata->active_low = flags & OF_GPIO_ACTIVE_LOW;
112
113 ret = of_property_read_u32(np, "reset-delay-us", &drvdata->delay_us);
114 if (ret < 0)
115 drvdata->delay_us = -1;
116 else if (drvdata->delay_us < 0)
117 dev_warn(&pdev->dev, "reset delay too high\n");
118
119 initially_in_reset = of_property_read_bool(np, "initially-in-reset");
120 if (drvdata->active_low ^ initially_in_reset)
121 gpio_flags = GPIOF_OUT_INIT_HIGH;
122 else
123 gpio_flags = GPIOF_OUT_INIT_LOW;
124
125 ret = devm_gpio_request_one(&pdev->dev, drvdata->gpio, gpio_flags, NULL);
126 if (ret < 0) {
127 dev_err(&pdev->dev, "failed to request gpio %d: %d\n",
128 drvdata->gpio, ret);
129 return ret;
130 }
131
132 platform_set_drvdata(pdev, drvdata);
133
134 drvdata->rcdev.of_node = np;
135 drvdata->rcdev.owner = THIS_MODULE;
136 drvdata->rcdev.nr_resets = 1;
137 drvdata->rcdev.ops = &gpio_reset_ops;
138 drvdata->rcdev.of_xlate = of_gpio_reset_xlate;
139 reset_controller_register(&drvdata->rcdev);
140
141 return 0;
142}
143
144static int gpio_reset_remove(struct platform_device *pdev)
145{
146 struct gpio_reset_data *drvdata = platform_get_drvdata(pdev);
147
148 reset_controller_unregister(&drvdata->rcdev);
149
150 return 0;
151}
152
153static struct of_device_id gpio_reset_dt_ids[] = {
154 { .compatible = "gpio-reset" },
155 { }
156};
157
158static struct platform_driver gpio_reset_driver = {
159 .probe = gpio_reset_probe,
160 .remove = gpio_reset_remove,
161 .driver = {
162 .name = "gpio-reset",
163 .owner = THIS_MODULE,
164 .of_match_table = of_match_ptr(gpio_reset_dt_ids),
165 },
166};
167
168module_platform_driver(gpio_reset_driver);
169
170MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>");
171MODULE_DESCRIPTION("gpio reset controller");
172MODULE_LICENSE("GPL");
173MODULE_ALIAS("platform:gpio-reset");
174MODULE_DEVICE_TABLE(of, gpio_reset_dt_ids);