aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/watchdog/mena21_wdt.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
index 0be7f50e8ff9..6db69883ece6 100644
--- a/drivers/watchdog/mena21_wdt.c
+++ b/drivers/watchdog/mena21_wdt.c
@@ -13,10 +13,10 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/watchdog.h> 14#include <linux/watchdog.h>
15#include <linux/uaccess.h> 15#include <linux/uaccess.h>
16#include <linux/gpio.h> 16#include <linux/gpio/consumer.h>
17#include <linux/of_gpio.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/bitops.h> 18#include <linux/bitops.h>
19#include <linux/of.h>
20 20
21#define NUM_GPIOS 6 21#define NUM_GPIOS 6
22 22
@@ -31,7 +31,7 @@ enum a21_wdt_gpios {
31 31
32struct a21_wdt_drv { 32struct a21_wdt_drv {
33 struct watchdog_device wdt; 33 struct watchdog_device wdt;
34 unsigned gpios[NUM_GPIOS]; 34 struct gpio_desc *gpios[NUM_GPIOS];
35}; 35};
36 36
37static bool nowayout = WATCHDOG_NOWAYOUT; 37static bool nowayout = WATCHDOG_NOWAYOUT;
@@ -43,9 +43,9 @@ static unsigned int a21_wdt_get_bootstatus(struct a21_wdt_drv *drv)
43{ 43{
44 int reset = 0; 44 int reset = 0;
45 45
46 reset |= gpio_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0; 46 reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0;
47 reset |= gpio_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0; 47 reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0;
48 reset |= gpio_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0; 48 reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0;
49 49
50 return reset; 50 return reset;
51} 51}
@@ -54,7 +54,7 @@ static int a21_wdt_start(struct watchdog_device *wdt)
54{ 54{
55 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); 55 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
56 56
57 gpio_set_value(drv->gpios[GPIO_WD_ENAB], 1); 57 gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 1);
58 58
59 return 0; 59 return 0;
60} 60}
@@ -63,7 +63,7 @@ static int a21_wdt_stop(struct watchdog_device *wdt)
63{ 63{
64 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); 64 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
65 65
66 gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0); 66 gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0);
67 67
68 return 0; 68 return 0;
69} 69}
@@ -72,9 +72,9 @@ static int a21_wdt_ping(struct watchdog_device *wdt)
72{ 72{
73 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt); 73 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
74 74
75 gpio_set_value(drv->gpios[GPIO_WD_TRIG], 0); 75 gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 0);
76 ndelay(10); 76 ndelay(10);
77 gpio_set_value(drv->gpios[GPIO_WD_TRIG], 1); 77 gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 1);
78 78
79 return 0; 79 return 0;
80} 80}
@@ -96,9 +96,9 @@ static int a21_wdt_set_timeout(struct watchdog_device *wdt,
96 } 96 }
97 97
98 if (timeout == 1) 98 if (timeout == 1)
99 gpio_set_value(drv->gpios[GPIO_WD_FAST], 1); 99 gpiod_set_value(drv->gpios[GPIO_WD_FAST], 1);
100 else 100 else
101 gpio_set_value(drv->gpios[GPIO_WD_FAST], 0); 101 gpiod_set_value(drv->gpios[GPIO_WD_FAST], 0);
102 102
103 wdt->timeout = timeout; 103 wdt->timeout = timeout;
104 104
@@ -127,7 +127,6 @@ static struct watchdog_device a21_wdt = {
127 127
128static int a21_wdt_probe(struct platform_device *pdev) 128static int a21_wdt_probe(struct platform_device *pdev)
129{ 129{
130 struct device_node *node;
131 struct a21_wdt_drv *drv; 130 struct a21_wdt_drv *drv;
132 unsigned int reset = 0; 131 unsigned int reset = 0;
133 int num_gpios; 132 int num_gpios;
@@ -138,40 +137,40 @@ static int a21_wdt_probe(struct platform_device *pdev)
138 if (!drv) 137 if (!drv)
139 return -ENOMEM; 138 return -ENOMEM;
140 139
141 /* Fill GPIO pin array */ 140 num_gpios = gpiod_count(&pdev->dev, NULL);
142 node = pdev->dev.of_node;
143
144 num_gpios = of_gpio_count(node);
145 if (num_gpios != NUM_GPIOS) { 141 if (num_gpios != NUM_GPIOS) {
146 dev_err(&pdev->dev, "gpios DT property wrong, got %d want %d", 142 dev_err(&pdev->dev, "gpios DT property wrong, got %d want %d",
147 num_gpios, NUM_GPIOS); 143 num_gpios, NUM_GPIOS);
148 return -ENODEV; 144 return -ENODEV;
149 } 145 }
150 146
151 for (i = 0; i < num_gpios; i++) {
152 int val;
153
154 val = of_get_gpio(node, i);
155 if (val < 0)
156 return val;
157
158 drv->gpios[i] = val;
159 }
160
161 /* Request the used GPIOs */ 147 /* Request the used GPIOs */
162 for (i = 0; i < num_gpios; i++) { 148 for (i = 0; i < num_gpios; i++) {
163 ret = devm_gpio_request(&pdev->dev, drv->gpios[i], 149 enum gpiod_flags gflags;
164 "MEN A21 Watchdog");
165 if (ret)
166 return ret;
167 150
168 if (i < GPIO_WD_RST0) 151 if (i < GPIO_WD_RST0)
169 ret = gpio_direction_output(drv->gpios[i], 152 gflags = GPIOD_ASIS;
170 gpio_get_value(drv->gpios[i])); 153 else
171 else /* GPIO_WD_RST[0..2] are inputs */ 154 gflags = GPIOD_IN;
172 ret = gpio_direction_input(drv->gpios[i]); 155 drv->gpios[i] = devm_gpiod_get_index(&pdev->dev, NULL, i,
173 if (ret) 156 gflags);
157 if (IS_ERR(drv->gpios[i])) {
158 ret = PTR_ERR(drv->gpios[i]);
174 return ret; 159 return ret;
160 }
161
162 gpiod_set_consumer_name(drv->gpios[i], "MEN A21 Watchdog");
163
164 /*
165 * Retrieve the initial value from the GPIOs that should be
166 * output, then set up the line as output with that value.
167 */
168 if (i < GPIO_WD_RST0) {
169 int val;
170
171 val = gpiod_get_value(drv->gpios[i]);
172 gpiod_direction_output(drv->gpios[i], val);
173 }
175 } 174 }
176 175
177 watchdog_init_timeout(&a21_wdt, 30, &pdev->dev); 176 watchdog_init_timeout(&a21_wdt, 30, &pdev->dev);
@@ -207,7 +206,7 @@ static void a21_wdt_shutdown(struct platform_device *pdev)
207{ 206{
208 struct a21_wdt_drv *drv = dev_get_drvdata(&pdev->dev); 207 struct a21_wdt_drv *drv = dev_get_drvdata(&pdev->dev);
209 208
210 gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0); 209 gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0);
211} 210}
212 211
213static const struct of_device_id a21_wdt_ids[] = { 212static const struct of_device_id a21_wdt_ids[] = {