Skip to contentSkip to conversation

extcon: gpio: queue work only if debounce is NZ

PATCH In review Venkat Reddy Talla 2 participants 2 messages Mar 8, 2016 External connector subsystem (extcon)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extcon: gpio: queue work only if debounce is NZ

Use queue_delayed_work only when debounce time is required to read gpio state properly, read the gpio state and set the extcon cable state in IRQ handler context if gpio settling time is not needed.

---
 drivers/extcon/extcon-gpio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +5 -1
index 279ff8f..1beb086 100644
@@ -56,8 +56,12 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 {
 	struct gpio_extcon_data *data = dev_id;
 
-	queue_delayed_work(system_power_efficient_wq, &data->work,
+	if (data->debounce_jiffies)
+		queue_delayed_work(system_power_efficient_wq, &data->work,
 			      data->debounce_jiffies);
+	else
+		gpio_extcon_work(&data->work.work);
+
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 15 lines · Venkat Reddy Talla

Use queue_delayed_work only when debounce time is required to read gpio state properly, read the gpio state and set the extcon cable state in IRQ handler context if gpio settling time is not needed.

---
 drivers/extcon/extcon-gpio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +0 -0
index 279ff8f..1beb086 100644

drivers/extcon/extcon-gpio.c static irqreturn_t gpio_irq_handler(int irq, void *dev_id) · line 64

Quoted 10 lines
drivers/extcon/extcon-gpio.c +5 -1
@@ -56,8 +56,12 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 {
 	struct gpio_extcon_data *data = dev_id;
 
-	queue_delayed_work(system_power_efficient_wq, &data->work,
+	if (data->debounce_jiffies)
+		queue_delayed_work(system_power_efficient_wq, &data->work,
 			      data->debounce_jiffies);
+	else
+		gpio_extcon_work(&data->work.work);
+

The interrupt is requested with devm_request_any_context_irq(), meaning the handler may run in hard interrupt context. gpio_extcon_work() calls gpiod_get_value_cansleep(), which may not be a good idea in hard interrupt context.

Guenter

Quoted 7 lines
drivers/extcon/extcon-gpio.c +0 -0
 	return IRQ_HANDLED;
 }
 
Signature · 1 line
2.1.4