hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/gpio/gpio-ath79.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Atheros AR71XX/AR724X/AR913X GPIO API support
34 *
....@@ -5,10 +6,6 @@
56 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
67 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
78 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8
- *
9
- * This program is free software; you can redistribute it and/or modify it
10
- * under the terms of the GNU General Public License version 2 as published
11
- * by the Free Software Foundation.
129 */
1310
1411 #include <linux/gpio/driver.h>
....@@ -132,7 +129,7 @@
132129
133130 case IRQ_TYPE_LEVEL_HIGH:
134131 polarity |= mask;
135
- /* fall through */
132
+ fallthrough;
136133 case IRQ_TYPE_LEVEL_LOW:
137134 type |= mask;
138135 break;
....@@ -225,14 +222,15 @@
225222 static int ath79_gpio_probe(struct platform_device *pdev)
226223 {
227224 struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
228
- struct device_node *np = pdev->dev.of_node;
225
+ struct device *dev = &pdev->dev;
226
+ struct device_node *np = dev->of_node;
229227 struct ath79_gpio_ctrl *ctrl;
230
- struct resource *res;
228
+ struct gpio_irq_chip *girq;
231229 u32 ath79_gpio_count;
232230 bool oe_inverted;
233231 int err;
234232
235
- ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL);
233
+ ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL);
236234 if (!ctrl)
237235 return -ENOMEM;
238236 platform_set_drvdata(pdev, ctrl);
....@@ -240,7 +238,7 @@
240238 if (np) {
241239 err = of_property_read_u32(np, "ngpios", &ath79_gpio_count);
242240 if (err) {
243
- dev_err(&pdev->dev, "ngpios property is not valid\n");
241
+ dev_err(dev, "ngpios property is not valid\n");
244242 return err;
245243 }
246244 oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio");
....@@ -248,25 +246,21 @@
248246 ath79_gpio_count = pdata->ngpios;
249247 oe_inverted = pdata->oe_inverted;
250248 } else {
251
- dev_err(&pdev->dev, "No DT node or platform data found\n");
249
+ dev_err(dev, "No DT node or platform data found\n");
252250 return -EINVAL;
253251 }
254252
255253 if (ath79_gpio_count >= 32) {
256
- dev_err(&pdev->dev, "ngpios must be less than 32\n");
254
+ dev_err(dev, "ngpios must be less than 32\n");
257255 return -EINVAL;
258256 }
259257
260
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
261
- if (!res)
262
- return -EINVAL;
263
- ctrl->base = devm_ioremap_nocache(
264
- &pdev->dev, res->start, resource_size(res));
265
- if (!ctrl->base)
266
- return -ENOMEM;
258
+ ctrl->base = devm_platform_ioremap_resource(pdev, 0);
259
+ if (IS_ERR(ctrl->base))
260
+ return PTR_ERR(ctrl->base);
267261
268262 raw_spin_lock_init(&ctrl->lock);
269
- err = bgpio_init(&ctrl->gc, &pdev->dev, 4,
263
+ err = bgpio_init(&ctrl->gc, dev, 4,
270264 ctrl->base + AR71XX_GPIO_REG_IN,
271265 ctrl->base + AR71XX_GPIO_REG_SET,
272266 ctrl->base + AR71XX_GPIO_REG_CLEAR,
....@@ -274,45 +268,33 @@
274268 oe_inverted ? ctrl->base + AR71XX_GPIO_REG_OE : NULL,
275269 0);
276270 if (err) {
277
- dev_err(&pdev->dev, "bgpio_init failed\n");
271
+ dev_err(dev, "bgpio_init failed\n");
278272 return err;
279273 }
280274 /* Use base 0 to stay compatible with legacy platforms */
281275 ctrl->gc.base = 0;
282276
283
- err = gpiochip_add_data(&ctrl->gc, ctrl);
277
+ /* Optional interrupt setup */
278
+ if (!np || of_property_read_bool(np, "interrupt-controller")) {
279
+ girq = &ctrl->gc.irq;
280
+ girq->chip = &ath79_gpio_irqchip;
281
+ girq->parent_handler = ath79_gpio_irq_handler;
282
+ girq->num_parents = 1;
283
+ girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents),
284
+ GFP_KERNEL);
285
+ if (!girq->parents)
286
+ return -ENOMEM;
287
+ girq->parents[0] = platform_get_irq(pdev, 0);
288
+ girq->default_type = IRQ_TYPE_NONE;
289
+ girq->handler = handle_simple_irq;
290
+ }
291
+
292
+ err = devm_gpiochip_add_data(dev, &ctrl->gc, ctrl);
284293 if (err) {
285
- dev_err(&pdev->dev,
294
+ dev_err(dev,
286295 "cannot add AR71xx GPIO chip, error=%d", err);
287296 return err;
288297 }
289
-
290
- if (np && !of_property_read_bool(np, "interrupt-controller"))
291
- return 0;
292
-
293
- err = gpiochip_irqchip_add(&ctrl->gc, &ath79_gpio_irqchip, 0,
294
- handle_simple_irq, IRQ_TYPE_NONE);
295
- if (err) {
296
- dev_err(&pdev->dev, "failed to add gpiochip_irqchip\n");
297
- goto gpiochip_remove;
298
- }
299
-
300
- gpiochip_set_chained_irqchip(&ctrl->gc, &ath79_gpio_irqchip,
301
- platform_get_irq(pdev, 0),
302
- ath79_gpio_irq_handler);
303
-
304
- return 0;
305
-
306
-gpiochip_remove:
307
- gpiochip_remove(&ctrl->gc);
308
- return err;
309
-}
310
-
311
-static int ath79_gpio_remove(struct platform_device *pdev)
312
-{
313
- struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev);
314
-
315
- gpiochip_remove(&ctrl->gc);
316298 return 0;
317299 }
318300
....@@ -322,7 +304,6 @@
322304 .of_match_table = ath79_gpio_of_match,
323305 },
324306 .probe = ath79_gpio_probe,
325
- .remove = ath79_gpio_remove,
326307 };
327308
328309 module_platform_driver(ath79_gpio_driver);