.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for the Diolan DLN-2 USB-GPIO adapter |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
9 | 6 | */ |
---|
10 | 7 | |
---|
11 | 8 | #include <linux/kernel.h> |
---|
.. | .. |
---|
49 | 46 | struct dln2_gpio { |
---|
50 | 47 | struct platform_device *pdev; |
---|
51 | 48 | struct gpio_chip gpio; |
---|
| 49 | + struct irq_chip irqchip; |
---|
52 | 50 | |
---|
53 | 51 | /* |
---|
54 | 52 | * Cache pin direction to save us one transfer, since the hardware has |
---|
.. | .. |
---|
203 | 201 | struct dln2_gpio *dln2 = gpiochip_get_data(chip); |
---|
204 | 202 | |
---|
205 | 203 | if (test_bit(offset, dln2->output_enabled)) |
---|
206 | | - return 0; |
---|
| 204 | + return GPIO_LINE_DIRECTION_OUT; |
---|
207 | 205 | |
---|
208 | | - return 1; |
---|
| 206 | + return GPIO_LINE_DIRECTION_IN; |
---|
209 | 207 | } |
---|
210 | 208 | |
---|
211 | 209 | static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset) |
---|
.. | .. |
---|
217 | 215 | if (dir < 0) |
---|
218 | 216 | return dir; |
---|
219 | 217 | |
---|
220 | | - if (dir == 1) |
---|
| 218 | + if (dir == GPIO_LINE_DIRECTION_IN) |
---|
221 | 219 | return dln2_gpio_pin_get_in_val(dln2, offset); |
---|
222 | 220 | |
---|
223 | 221 | return dln2_gpio_pin_get_out_val(dln2, offset); |
---|
.. | .. |
---|
386 | 384 | mutex_unlock(&dln2->irq_lock); |
---|
387 | 385 | } |
---|
388 | 386 | |
---|
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 | | - |
---|
398 | 387 | static void dln2_gpio_event(struct platform_device *pdev, u16 echo, |
---|
399 | 388 | const void *data, int len) |
---|
400 | 389 | { |
---|
.. | .. |
---|
443 | 432 | { |
---|
444 | 433 | struct dln2_gpio *dln2; |
---|
445 | 434 | struct device *dev = &pdev->dev; |
---|
| 435 | + struct gpio_irq_chip *girq; |
---|
446 | 436 | int pins; |
---|
447 | 437 | int ret; |
---|
448 | 438 | |
---|
.. | .. |
---|
479 | 469 | dln2->gpio.direction_output = dln2_gpio_direction_output; |
---|
480 | 470 | dln2->gpio.set_config = dln2_gpio_set_config; |
---|
481 | 471 | |
---|
| 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 | + |
---|
482 | 488 | platform_set_drvdata(pdev, dln2); |
---|
483 | 489 | |
---|
484 | 490 | ret = devm_gpiochip_add_data(dev, &dln2->gpio, dln2); |
---|
485 | 491 | if (ret < 0) { |
---|
486 | 492 | 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); |
---|
494 | 493 | return ret; |
---|
495 | 494 | } |
---|
496 | 495 | |
---|