forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f9004dbfff8a3fbbd7e2a88c8a4327c7f2f8e5b2
kernel/drivers/extcon/extcon-gpio.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
34 *
....@@ -6,15 +7,6 @@
67 *
78 * Modified by MyungJoo Ham <myungjoo.ham@samsung.com> to support extcon
89 * (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.
1810 */
1911
2012 #include <linux/extcon-provider.h>
....@@ -30,26 +22,22 @@
3022 /**
3123 * struct gpio_extcon_data - A simple GPIO-controlled extcon device state container.
3224 * @edev: Extcon device.
33
- * @irq: Interrupt line for the external connector.
3425 * @work: Work fired by the interrupt.
3526 * @debounce_jiffies: Number of jiffies to wait for the GPIO to stabilize, from the debounce
3627 * value.
3728 * @gpiod: GPIO descriptor for this external connector.
3829 * @extcon_id: The unique id of specific external connector.
3930 * @debounce: Debounce time for GPIO IRQ in ms.
40
- * @irq_flags: IRQ Flags (e.g., IRQF_TRIGGER_LOW).
4131 * @check_on_resume: Boolean describing whether to check the state of gpio
4232 * while resuming from sleep.
4333 */
4434 struct gpio_extcon_data {
4535 struct extcon_dev *edev;
46
- int irq;
4736 struct delayed_work work;
4837 unsigned long debounce_jiffies;
4938 struct gpio_desc *gpiod;
5039 unsigned int extcon_id;
5140 unsigned long debounce;
52
- unsigned long irq_flags;
5341 bool check_on_resume;
5442 };
5543
....@@ -77,6 +65,8 @@
7765 {
7866 struct gpio_extcon_data *data;
7967 struct device *dev = &pdev->dev;
68
+ unsigned long irq_flags;
69
+ int irq;
8070 int ret;
8171
8272 data = devm_kzalloc(dev, sizeof(struct gpio_extcon_data), GFP_KERNEL);
....@@ -90,15 +80,26 @@
9080 * developed to get the extcon id from device-tree or others.
9181 * On later, it have to be solved.
9282 */
93
- if (!data->irq_flags || data->extcon_id > EXTCON_NONE)
83
+ if (data->extcon_id > EXTCON_NONE)
9484 return -EINVAL;
9585
9686 data->gpiod = devm_gpiod_get(dev, "extcon", GPIOD_IN);
9787 if (IS_ERR(data->gpiod))
9888 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;
102103
103104 /* Allocate the memory of extcon devie and register extcon device */
104105 data->edev = devm_extcon_dev_allocate(dev, &data->extcon_id);
....@@ -117,8 +118,8 @@
117118 * Request the interrupt of gpio to detect whether external connector
118119 * is attached or detached.
119120 */
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,
122123 pdev->name, data);
123124 if (ret < 0)
124125 return ret;