.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * |
---|
7 | 8 | * Modified by MyungJoo Ham <myungjoo.ham@samsung.com> to support extcon |
---|
8 | 9 | * (originally switch class is supported) |
---|
9 | | - * |
---|
10 | | - * This software is licensed under the terms of the GNU General Public |
---|
11 | | - * License version 2, as published by the Free Software Foundation, and |
---|
12 | | - * may be copied, distributed, and modified under those terms. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, |
---|
15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | | - * GNU General Public License for more details. |
---|
18 | 10 | */ |
---|
19 | 11 | |
---|
20 | 12 | #include <linux/extcon-provider.h> |
---|
.. | .. |
---|
30 | 22 | /** |
---|
31 | 23 | * struct gpio_extcon_data - A simple GPIO-controlled extcon device state container. |
---|
32 | 24 | * @edev: Extcon device. |
---|
33 | | - * @irq: Interrupt line for the external connector. |
---|
34 | 25 | * @work: Work fired by the interrupt. |
---|
35 | 26 | * @debounce_jiffies: Number of jiffies to wait for the GPIO to stabilize, from the debounce |
---|
36 | 27 | * value. |
---|
37 | 28 | * @gpiod: GPIO descriptor for this external connector. |
---|
38 | 29 | * @extcon_id: The unique id of specific external connector. |
---|
39 | 30 | * @debounce: Debounce time for GPIO IRQ in ms. |
---|
40 | | - * @irq_flags: IRQ Flags (e.g., IRQF_TRIGGER_LOW). |
---|
41 | 31 | * @check_on_resume: Boolean describing whether to check the state of gpio |
---|
42 | 32 | * while resuming from sleep. |
---|
43 | 33 | */ |
---|
44 | 34 | struct gpio_extcon_data { |
---|
45 | 35 | struct extcon_dev *edev; |
---|
46 | | - int irq; |
---|
47 | 36 | struct delayed_work work; |
---|
48 | 37 | unsigned long debounce_jiffies; |
---|
49 | 38 | struct gpio_desc *gpiod; |
---|
50 | 39 | unsigned int extcon_id; |
---|
51 | 40 | unsigned long debounce; |
---|
52 | | - unsigned long irq_flags; |
---|
53 | 41 | bool check_on_resume; |
---|
54 | 42 | }; |
---|
55 | 43 | |
---|
.. | .. |
---|
77 | 65 | { |
---|
78 | 66 | struct gpio_extcon_data *data; |
---|
79 | 67 | struct device *dev = &pdev->dev; |
---|
| 68 | + unsigned long irq_flags; |
---|
| 69 | + int irq; |
---|
80 | 70 | int ret; |
---|
81 | 71 | |
---|
82 | 72 | data = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL); |
---|
.. | .. |
---|
90 | 80 | * developed to get the extcon id from device-tree or others. |
---|
91 | 81 | * On later, it have to be solved. |
---|
92 | 82 | */ |
---|
93 | | - if (!data->irq_flags || data->extcon_id > EXTCON_NONE) |
---|
| 83 | + if (data->extcon_id > EXTCON_NONE) |
---|
94 | 84 | return -EINVAL; |
---|
95 | 85 | |
---|
96 | 86 | data->gpiod = devm_gpiod_get(dev, "extcon", GPIOD_IN); |
---|
97 | 87 | if (IS_ERR(data->gpiod)) |
---|
98 | 88 | return PTR_ERR(data->gpiod); |
---|
99 | | - data->irq = gpiod_to_irq(data->gpiod); |
---|
100 | | - if (data->irq <= 0) |
---|
101 | | - return data->irq; |
---|
| 89 | + irq = gpiod_to_irq(data->gpiod); |
---|
| 90 | + if (irq <= 0) |
---|
| 91 | + return irq; |
---|
| 92 | + |
---|
| 93 | + /* |
---|
| 94 | + * It is unlikely that this is an acknowledged interrupt that goes |
---|
| 95 | + * away after handling, what we are looking for are falling edges |
---|
| 96 | + * if the signal is active low, and rising edges if the signal is |
---|
| 97 | + * active high. |
---|
| 98 | + */ |
---|
| 99 | + if (gpiod_is_active_low(data->gpiod)) |
---|
| 100 | + irq_flags = IRQF_TRIGGER_FALLING; |
---|
| 101 | + else |
---|
| 102 | + irq_flags = IRQF_TRIGGER_RISING; |
---|
102 | 103 | |
---|
103 | 104 | /* Allocate the memory of extcon devie and register extcon device */ |
---|
104 | 105 | data->edev = devm_extcon_dev_allocate(dev, &data->extcon_id); |
---|
.. | .. |
---|
117 | 118 | * Request the interrupt of gpio to detect whether external connector |
---|
118 | 119 | * is attached or detached. |
---|
119 | 120 | */ |
---|
120 | | - ret = devm_request_any_context_irq(dev, data->irq, |
---|
121 | | - gpio_irq_handler, data->irq_flags, |
---|
| 121 | + ret = devm_request_any_context_irq(dev, irq, |
---|
| 122 | + gpio_irq_handler, irq_flags, |
---|
122 | 123 | pdev->name, data); |
---|
123 | 124 | if (ret < 0) |
---|
124 | 125 | return ret; |
---|