hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-dln2.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for the Diolan DLN-2 USB-GPIO adapter
34 *
45 * Copyright (c) 2014 Intel Corporation
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License as
8
- * published by the Free Software Foundation, version 2.
96 */
107
118 #include <linux/kernel.h>
....@@ -49,6 +46,7 @@
4946 struct dln2_gpio {
5047 struct platform_device *pdev;
5148 struct gpio_chip gpio;
49
+ struct irq_chip irqchip;
5250
5351 /*
5452 * Cache pin direction to save us one transfer, since the hardware has
....@@ -203,9 +201,9 @@
203201 struct dln2_gpio *dln2 = gpiochip_get_data(chip);
204202
205203 if (test_bit(offset, dln2->output_enabled))
206
- return 0;
204
+ return GPIO_LINE_DIRECTION_OUT;
207205
208
- return 1;
206
+ return GPIO_LINE_DIRECTION_IN;
209207 }
210208
211209 static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
....@@ -217,7 +215,7 @@
217215 if (dir < 0)
218216 return dir;
219217
220
- if (dir == 1)
218
+ if (dir == GPIO_LINE_DIRECTION_IN)
221219 return dln2_gpio_pin_get_in_val(dln2, offset);
222220
223221 return dln2_gpio_pin_get_out_val(dln2, offset);
....@@ -386,15 +384,6 @@
386384 mutex_unlock(&dln2->irq_lock);
387385 }
388386
389
-static struct irq_chip dln2_gpio_irqchip = {
390
- .name = "dln2-irq",
391
- .irq_mask = dln2_irq_mask,
392
- .irq_unmask = dln2_irq_unmask,
393
- .irq_set_type = dln2_irq_set_type,
394
- .irq_bus_lock = dln2_irq_bus_lock,
395
- .irq_bus_sync_unlock = dln2_irq_bus_unlock,
396
-};
397
-
398387 static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
399388 const void *data, int len)
400389 {
....@@ -443,6 +432,7 @@
443432 {
444433 struct dln2_gpio *dln2;
445434 struct device *dev = &pdev->dev;
435
+ struct gpio_irq_chip *girq;
446436 int pins;
447437 int ret;
448438
....@@ -479,18 +469,27 @@
479469 dln2->gpio.direction_output = dln2_gpio_direction_output;
480470 dln2->gpio.set_config = dln2_gpio_set_config;
481471
472
+ dln2->irqchip.name = "dln2-irq",
473
+ dln2->irqchip.irq_mask = dln2_irq_mask,
474
+ dln2->irqchip.irq_unmask = dln2_irq_unmask,
475
+ dln2->irqchip.irq_set_type = dln2_irq_set_type,
476
+ dln2->irqchip.irq_bus_lock = dln2_irq_bus_lock,
477
+ dln2->irqchip.irq_bus_sync_unlock = dln2_irq_bus_unlock,
478
+
479
+ girq = &dln2->gpio.irq;
480
+ girq->chip = &dln2->irqchip;
481
+ /* The event comes from the outside so no parent handler */
482
+ girq->parent_handler = NULL;
483
+ girq->num_parents = 0;
484
+ girq->parents = NULL;
485
+ girq->default_type = IRQ_TYPE_NONE;
486
+ girq->handler = handle_simple_irq;
487
+
482488 platform_set_drvdata(pdev, dln2);
483489
484490 ret = devm_gpiochip_add_data(dev, &dln2->gpio, dln2);
485491 if (ret < 0) {
486492 dev_err(dev, "failed to add gpio chip: %d\n", ret);
487
- return ret;
488
- }
489
-
490
- ret = gpiochip_irqchip_add(&dln2->gpio, &dln2_gpio_irqchip, 0,
491
- handle_simple_irq, IRQ_TYPE_NONE);
492
- if (ret < 0) {
493
- dev_err(dev, "failed to add irq chip: %d\n", ret);
494493 return ret;
495494 }
496495