hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/watchdog/mena21_wdt.c
....@@ -13,10 +13,10 @@
1313 #include <linux/platform_device.h>
1414 #include <linux/watchdog.h>
1515 #include <linux/uaccess.h>
16
-#include <linux/gpio.h>
17
-#include <linux/of_gpio.h>
16
+#include <linux/gpio/consumer.h>
1817 #include <linux/delay.h>
1918 #include <linux/bitops.h>
19
+#include <linux/of.h>
2020
2121 #define NUM_GPIOS 6
2222
....@@ -31,7 +31,7 @@
3131
3232 struct a21_wdt_drv {
3333 struct watchdog_device wdt;
34
- unsigned gpios[NUM_GPIOS];
34
+ struct gpio_desc *gpios[NUM_GPIOS];
3535 };
3636
3737 static bool nowayout = WATCHDOG_NOWAYOUT;
....@@ -43,9 +43,9 @@
4343 {
4444 int reset = 0;
4545
46
- reset |= gpio_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0;
47
- reset |= gpio_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0;
48
- reset |= gpio_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0;
46
+ reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST0]) ? (1 << 0) : 0;
47
+ reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST1]) ? (1 << 1) : 0;
48
+ reset |= gpiod_get_value(drv->gpios[GPIO_WD_RST2]) ? (1 << 2) : 0;
4949
5050 return reset;
5151 }
....@@ -54,7 +54,7 @@
5454 {
5555 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
5656
57
- gpio_set_value(drv->gpios[GPIO_WD_ENAB], 1);
57
+ gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 1);
5858
5959 return 0;
6060 }
....@@ -63,7 +63,7 @@
6363 {
6464 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
6565
66
- gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0);
66
+ gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0);
6767
6868 return 0;
6969 }
....@@ -72,9 +72,9 @@
7272 {
7373 struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
7474
75
- gpio_set_value(drv->gpios[GPIO_WD_TRIG], 0);
75
+ gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 0);
7676 ndelay(10);
77
- gpio_set_value(drv->gpios[GPIO_WD_TRIG], 1);
77
+ gpiod_set_value(drv->gpios[GPIO_WD_TRIG], 1);
7878
7979 return 0;
8080 }
....@@ -96,9 +96,9 @@
9696 }
9797
9898 if (timeout == 1)
99
- gpio_set_value(drv->gpios[GPIO_WD_FAST], 1);
99
+ gpiod_set_value(drv->gpios[GPIO_WD_FAST], 1);
100100 else
101
- gpio_set_value(drv->gpios[GPIO_WD_FAST], 0);
101
+ gpiod_set_value(drv->gpios[GPIO_WD_FAST], 0);
102102
103103 wdt->timeout = timeout;
104104
....@@ -127,57 +127,54 @@
127127
128128 static int a21_wdt_probe(struct platform_device *pdev)
129129 {
130
- struct device_node *node;
130
+ struct device *dev = &pdev->dev;
131131 struct a21_wdt_drv *drv;
132132 unsigned int reset = 0;
133133 int num_gpios;
134134 int ret;
135135 int i;
136136
137
- drv = devm_kzalloc(&pdev->dev, sizeof(struct a21_wdt_drv), GFP_KERNEL);
137
+ drv = devm_kzalloc(dev, sizeof(struct a21_wdt_drv), GFP_KERNEL);
138138 if (!drv)
139139 return -ENOMEM;
140140
141
- /* Fill GPIO pin array */
142
- node = pdev->dev.of_node;
143
-
144
- num_gpios = of_gpio_count(node);
141
+ num_gpios = gpiod_count(dev, NULL);
145142 if (num_gpios != NUM_GPIOS) {
146
- dev_err(&pdev->dev, "gpios DT property wrong, got %d want %d",
143
+ dev_err(dev, "gpios DT property wrong, got %d want %d",
147144 num_gpios, NUM_GPIOS);
148145 return -ENODEV;
149146 }
150147
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
-
161148 /* Request the used GPIOs */
162149 for (i = 0; i < num_gpios; i++) {
163
- ret = devm_gpio_request(&pdev->dev, drv->gpios[i],
164
- "MEN A21 Watchdog");
165
- if (ret)
166
- return ret;
150
+ enum gpiod_flags gflags;
167151
168152 if (i < GPIO_WD_RST0)
169
- ret = gpio_direction_output(drv->gpios[i],
170
- gpio_get_value(drv->gpios[i]));
171
- else /* GPIO_WD_RST[0..2] are inputs */
172
- ret = gpio_direction_input(drv->gpios[i]);
173
- if (ret)
174
- return ret;
153
+ gflags = GPIOD_ASIS;
154
+ else
155
+ gflags = GPIOD_IN;
156
+ drv->gpios[i] = devm_gpiod_get_index(dev, NULL, i, gflags);
157
+ if (IS_ERR(drv->gpios[i]))
158
+ return PTR_ERR(drv->gpios[i]);
159
+
160
+ gpiod_set_consumer_name(drv->gpios[i], "MEN A21 Watchdog");
161
+
162
+ /*
163
+ * Retrieve the initial value from the GPIOs that should be
164
+ * output, then set up the line as output with that value.
165
+ */
166
+ if (i < GPIO_WD_RST0) {
167
+ int val;
168
+
169
+ val = gpiod_get_value(drv->gpios[i]);
170
+ gpiod_direction_output(drv->gpios[i], val);
171
+ }
175172 }
176173
177
- watchdog_init_timeout(&a21_wdt, 30, &pdev->dev);
174
+ watchdog_init_timeout(&a21_wdt, 30, dev);
178175 watchdog_set_nowayout(&a21_wdt, nowayout);
179176 watchdog_set_drvdata(&a21_wdt, drv);
180
- a21_wdt.parent = &pdev->dev;
177
+ a21_wdt.parent = dev;
181178
182179 reset = a21_wdt_get_bootstatus(drv);
183180 if (reset == 2)
....@@ -190,15 +187,13 @@
190187 a21_wdt.bootstatus |= WDIOF_EXTERN2;
191188
192189 drv->wdt = a21_wdt;
193
- dev_set_drvdata(&pdev->dev, drv);
190
+ dev_set_drvdata(dev, drv);
194191
195
- ret = devm_watchdog_register_device(&pdev->dev, &a21_wdt);
196
- if (ret) {
197
- dev_err(&pdev->dev, "Cannot register watchdog device\n");
192
+ ret = devm_watchdog_register_device(dev, &a21_wdt);
193
+ if (ret)
198194 return ret;
199
- }
200195
201
- dev_info(&pdev->dev, "MEN A21 watchdog timer driver enabled\n");
196
+ dev_info(dev, "MEN A21 watchdog timer driver enabled\n");
202197
203198 return 0;
204199 }
....@@ -207,7 +202,7 @@
207202 {
208203 struct a21_wdt_drv *drv = dev_get_drvdata(&pdev->dev);
209204
210
- gpio_set_value(drv->gpios[GPIO_WD_ENAB], 0);
205
+ gpiod_set_value(drv->gpios[GPIO_WD_ENAB], 0);
211206 }
212207
213208 static const struct of_device_id a21_wdt_ids[] = {