extcon: usb-gpio: Don't miss event during suspend/resume
PATCH 1/1 extcon: usb-gpio: Don't miss event during suspend/resume
Pin state might have changed during suspend/resume while our interrupts were disabled. Scan for change during resume.
--- drivers/extcon/extcon-usb-gpio.c | 1 + 1 file changed, 1 insertion(+)
drivers/extcon/extcon-usb-gpio.c +1 -0
@@ -192,6 +192,7 @@ static int usb_extcon_resume(struct device *dev) }enable_irq (info->id_irq); +usb_extcon_detect_cable (&info->wq_detcable.work);return ret; }
Signature · 1 line
2.5.0
Chanwoo Choi
maintainerQuoted 13 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled. Scan for change during resume.
Signed-off-by Roger Quadros <[email protected]>--- drivers/extcon/extcon-usb-gpio.c | 1 + 1 file changed, 1 insertion(+)drivers/extcon/extcon-usb-gpio.c +0
-0
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 195
Quoted 4 lines
drivers/extcon/extcon-usb-gpio.c +1
-0@@ -192,6 +192,7 @@ static int usb_extcon_resume(struct device *dev) }enable_irq (info->id_irq); +usb_extcon_detect_cable (&info->wq_detcable.work);
If interrupt is using as wakeup source/irq,
after wake-up from suspend state, the interrupt handler will be handled.
But, if interrupt is not used for wakeup source/irq, As your patch, we need to check the state on resume().
So, I think you need more condition to check the interrupt is whether wakeup source or not.
Thanks,
Chanwoo CHoi
PATCH v2 1/1 extcon: usb-gpio: Don't miss event during suspend/resume
In reply to Roger QuadrosPin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
---
v2:
- only check for state change during resume if device wakeup is not supported
drivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/extcon/extcon-usb-gpio.c +2 -0
@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);return ret; }
Signature · 1 line
2.5.0
Chanwoo Choi
maintainerHi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);
The device_may_wakeup() check the following two states:
- dev->power.can_wakeup - device_init_wakeup() function set the this field.
- dev->power.wakeup - device_wakeup_enable() function set the this field.
The probe function of extcon-usb-gpio.c always call the 'device_init_wakeup(dev,true). But, anywhere in extcon-usb-gpio.c don't handle the device_wakeup_enable() for dev->power.wakeup.
In the extcon-usb-gpio.c, device_may_wakeup(dev) return always 'false'. If you use the only device_may_wakeup(),device_may_wakeup() is not able to check whether interrupt is wakeup source or not.
Thanks,
Chanwoo Choi
Quoted 31 lines · Chanwoo Choi
Hi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);The
device_may_wakeup()check the following two states:
-dev->power.can_wakeup-device_init_wakeup()function set the this field.
-dev->power.wakeup-device_wakeup_enable()function set the this field.
Quoted 2 lines
The probe function of
extcon-usb-gpio.calways call the 'device_init_wakeup(dev,true). But, anywhere inextcon-usb-gpio.cdon't handle thedevice_wakeup_enable()fordev->power.wakeup.
device_init_wakeup()
|-> device_wakeup_enable()
Quoted 5 lines
In the
extcon-usb-gpio.c,device_may_wakeup(dev)return always 'false'. If you use the onlydevice_may_wakeup(),device_may_wakeup()is not able to check whether interrupt is wakeup source or not.
This check is correct and it also will take into account wake up settings changes which can be made through sysfs: /sys/.../devX/power/wakeup
Signature · 2 lines
regards, -grygorii
Chanwoo Choi
maintainerQuoted 40 lines · Grygorii Strashko
Quoted 31 lines · Chanwoo Choi
Hi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);The
device_may_wakeup()check the following two states:
-dev->power.can_wakeup-device_init_wakeup()function set the this field.
-dev->power.wakeup-device_wakeup_enable()function set the this field.Quoted 2 lines
The probe function of
extcon-usb-gpio.calways call the 'device_init_wakeup(dev,true). But, anywhere inextcon-usb-gpio.cdon't handle thedevice_wakeup_enable()fordev->power.wakeup.
device_init_wakeup()
|->device_wakeup_enable()Quoted 1 line
Quoted 8 lines
Quoted 4 lines
In the
extcon-usb-gpio.c,device_may_wakeup(dev)return always 'false'. If you use the onlydevice_may_wakeup(),device_may_wakeup()is not able to check whether interrupt is wakeup source or not.This check is correct and it also will take into account wake up settings changes which can be made through sysfs:
/sys/.../devX/power/wakeup
To Grygorii,
You're right. I was mistaken. Again, I analyzed the sequence about wakeup. Thanks for your reply.
1. Register device as wakeup_source.
device_init_wakeup(dev, true) on probe()
device_wakeup_enable(dev) device_source_register(const char *name) struct wakeup_source *ws; ws = wakeup_source_create(name) if (ws) wakeup_source_add(ws); ... list_add_rcu(&ws->entry, &wakeup_sources); ... return ws;
2. Register the interrupt as wake_irq dev_pm_set_wake_irq(struct device *dev, int irq) on probe()
struct wake_irq *wirq; wirq->dev = dev; wirq->irq = irq; dev_pm_attach_wake_irq(dev, irq, wirq); device_wakeup_attach_irq(*dev, *wakeirq) struct wakeup_source *ws; ws = dev->power.wakeup; ws->wakeirq = wakeirq;
3. Enable irq wake if device is already registed to wakeup_sources. dpm_suspend_noirq()
device_wakeup_arm_wake_irqs()
list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
if (ws->wakeirq)
dev_pm_arm_wake_irq(sw->wakeirq);
if (device_may_wakeup(wirq->dev))
enable_irq_wake(wirq->irq);To Roger,
How about using the queue_delayed_work() instead of direct call function? Because the spent time of wakeup from suspend state should be fast. So, I think that you better to use the queue_delayed_work().
drivers/extcon/extcon-usb-gpio.c +3 -1
@@ -186,7 +186,9 @@ static int usb_extcon_resume(struct device *dev)enable_irq (info->id_irq);if (!device_may_wakeup (dev)) -usb_extcon_detect_cable (&info->wq_detcable.work); +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable, + info->debounce_jiffies);return ret; }
Thanks,
Chanwoo Choi
Chanwoo,
Quoted 102 lines · Chanwoo Choi
Quoted 40 lines · Grygorii Strashko
Quoted 31 lines · Chanwoo Choi
Hi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);The
device_may_wakeup()check the following two states:
-dev->power.can_wakeup-device_init_wakeup()function set the this field.
-dev->power.wakeup-device_wakeup_enable()function set the this field.Quoted 2 lines
The probe function of
extcon-usb-gpio.calways call the 'device_init_wakeup(dev,true). But, anywhere inextcon-usb-gpio.cdon't handle thedevice_wakeup_enable()fordev->power.wakeup.
device_init_wakeup()
|->device_wakeup_enable()Quoted 1 line
Quoted 8 lines
Quoted 4 lines
In the
extcon-usb-gpio.c,device_may_wakeup(dev)return always 'false'. If you use the onlydevice_may_wakeup(),device_may_wakeup()is not able to check whether interrupt is wakeup source or not.This check is correct and it also will take into account wake up settings changes which can be made through sysfs:
/sys/.../devX/power/wakeupTo Grygorii,
You're right. I was mistaken. Again, I analyzed the sequence about wakeup. Thanks for your reply.
1. Register device as
wakeup_source.
device_init_wakeup(dev, true)onprobe()device_wakeup_enable(dev) device_source_register(const char *name) struct wakeup_source *ws; ws = wakeup_source_create(name) if (ws) wakeup_source_add(ws); ... list_add_rcu(&ws->entry, &wakeup_sources); ... return ws;2. Register the interrupt as
wake_irqdev_pm_set_wake_irq(struct device *dev, int irq)onprobe()struct wake_irq *wirq; wirq->dev = dev; wirq->irq = irq; dev_pm_attach_wake_irq(dev, irq, wirq); device_wakeup_attach_irq(*dev, *wakeirq) struct wakeup_source *ws; ws = dev->power.wakeup; ws->wakeirq = wakeirq;3. Enable irq wake if device is already registed to
wakeup_sources.dpm_suspend_noirq()device_wakeup_arm_wake_irqs() list_for_each_entry_rcu(ws, &wakeup_sources, entry) { if (ws->wakeirq) dev_pm_arm_wake_irq(sw->wakeirq); if (device_may_wakeup(wirq->dev)) enable_irq_wake(wirq->irq);To Roger,
How about using the
queue_delayed_work()instead of direct call function? Because the spent time of wakeup from suspend state should be fast. So, I think that you better to use thequeue_delayed_work().drivers/extcon/extcon-usb-gpio.c +0
-0
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 191
Quoted 7 lines
drivers/extcon/extcon-usb-gpio.c +3
-1@@ -186,7 +186,9 @@ static int usb_extcon_resume(struct device *dev)enable_irq (info->id_irq);if (!device_may_wakeup (dev)) -usb_extcon_detect_cable (&info->wq_detcable.work); +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable, + info->debounce_jiffies);
Why not to just use queue_work() instead of queue_delayed_work() as don't need to debounce the input?
cheers,
-roger
Quoted 3 lines
drivers/extcon/extcon-usb-gpio.c +0
-0return ret; }
Hi Roger,
Quoted 106 lines · Roger Quadros
Chanwoo,
Quoted 103 lines · Chanwoo Choi
Quoted 40 lines · Grygorii Strashko
Quoted 31 lines · Chanwoo Choi
Hi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);The
device_may_wakeup()check the following two states:
-dev->power.can_wakeup-device_init_wakeup()function set the this field.
-dev->power.wakeup-device_wakeup_enable()function set the this field.Quoted 2 lines
The probe function of
extcon-usb-gpio.calways call the 'device_init_wakeup(dev,true). But, anywhere inextcon-usb-gpio.cdon't handle thedevice_wakeup_enable()fordev->power.wakeup.
device_init_wakeup()
|->device_wakeup_enable()Quoted 1 line
Quoted 8 lines
Quoted 4 lines
In the
extcon-usb-gpio.c,device_may_wakeup(dev)return always 'false'. If you use the onlydevice_may_wakeup(),device_may_wakeup()is not able to check whether interrupt is wakeup source or not.This check is correct and it also will take into account wake up settings changes which can be made through sysfs:
/sys/.../devX/power/wakeupTo Grygorii,
You're right. I was mistaken. Again, I analyzed the sequence about wakeup. Thanks for your reply.
1. Register device as
wakeup_source.
device_init_wakeup(dev, true)onprobe()device_wakeup_enable(dev) device_source_register(const char *name) struct wakeup_source *ws; ws = wakeup_source_create(name) if (ws) wakeup_source_add(ws); ... list_add_rcu(&ws->entry, &wakeup_sources); ... return ws;2. Register the interrupt as
wake_irqdev_pm_set_wake_irq(struct device *dev, int irq)onprobe()struct wake_irq *wirq; wirq->dev = dev; wirq->irq = irq; dev_pm_attach_wake_irq(dev, irq, wirq); device_wakeup_attach_irq(*dev, *wakeirq) struct wakeup_source *ws; ws = dev->power.wakeup; ws->wakeirq = wakeirq;3. Enable irq wake if device is already registed to
wakeup_sources.dpm_suspend_noirq()device_wakeup_arm_wake_irqs() list_for_each_entry_rcu(ws, &wakeup_sources, entry) { if (ws->wakeirq) dev_pm_arm_wake_irq(sw->wakeirq); if (device_may_wakeup(wirq->dev)) enable_irq_wake(wirq->irq);To Roger,
How about using the
queue_delayed_work()instead of direct call function? Because the spent time of wakeup from suspend state should be fast. So, I think that you better to use thequeue_delayed_work().drivers/extcon/extcon-usb-gpio.c +0
-0@@ -186,7 +186,9 @@ static int usb_extcon_resume(struct device *dev)
Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 191
Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c +3
-1enable_irq (info->id_irq);if (!device_may_wakeup (dev)) -usb_extcon_detect_cable (&info->wq_detcable.work); +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable, + info->debounce_jiffies);Why not to just use
queue_work()instead ofqueue_delayed_work()as don't need to debounce the input?
The use of queue_work() is good.
Thanks,
Chanwoo Choi
Quoted 119 lines · Chanwoo Choi
Hi Roger,
Quoted 106 lines · Roger Quadros
Chanwoo,
Quoted 103 lines · Chanwoo Choi
Quoted 40 lines · Grygorii Strashko
Quoted 31 lines · Chanwoo Choi
Hi Roger,
Quoted 18 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v2:
- only check for state change during resume if device wakeup is not supporteddrivers/extcon/extcon-usb-gpio.c | 2 ++ 1 file changed, 2 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 189
Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c +2
-0@@ -185,6 +185,8 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +usb_extcon_detect_cable (&info->wq_detcable.work);The
device_may_wakeup()check the following two states:
-dev->power.can_wakeup-device_init_wakeup()function set the this field.
-dev->power.wakeup-device_wakeup_enable()function set the this field.Quoted 2 lines
The probe function of
extcon-usb-gpio.calways call the 'device_init_wakeup(dev,true). But, anywhere inextcon-usb-gpio.cdon't handle thedevice_wakeup_enable()fordev->power.wakeup.
device_init_wakeup()
|->device_wakeup_enable()Quoted 1 line
Quoted 8 lines
Quoted 4 lines
In the
extcon-usb-gpio.c,device_may_wakeup(dev)return always 'false'. If you use the onlydevice_may_wakeup(),device_may_wakeup()is not able to check whether interrupt is wakeup source or not.This check is correct and it also will take into account wake up settings changes which can be made through sysfs:
/sys/.../devX/power/wakeupTo Grygorii,
You're right. I was mistaken. Again, I analyzed the sequence about wakeup. Thanks for your reply.
1. Register device as
wakeup_source.
device_init_wakeup(dev, true)onprobe()device_wakeup_enable(dev) device_source_register(const char *name) struct wakeup_source *ws; ws = wakeup_source_create(name) if (ws) wakeup_source_add(ws); ... list_add_rcu(&ws->entry, &wakeup_sources); ... return ws;2. Register the interrupt as
wake_irqdev_pm_set_wake_irq(struct device *dev, int irq)onprobe()struct wake_irq *wirq; wirq->dev = dev; wirq->irq = irq; dev_pm_attach_wake_irq(dev, irq, wirq); device_wakeup_attach_irq(*dev, *wakeirq) struct wakeup_source *ws; ws = dev->power.wakeup; ws->wakeirq = wakeirq;3. Enable irq wake if device is already registed to
wakeup_sources.dpm_suspend_noirq()device_wakeup_arm_wake_irqs() list_for_each_entry_rcu(ws, &wakeup_sources, entry) { if (ws->wakeirq) dev_pm_arm_wake_irq(sw->wakeirq); if (device_may_wakeup(wirq->dev)) enable_irq_wake(wirq->irq);To Roger,
How about using the
queue_delayed_work()instead of direct call function? Because the spent time of wakeup from suspend state should be fast. So, I think that you better to use thequeue_delayed_work().drivers/extcon/extcon-usb-gpio.c +0
-0@@ -186,7 +186,9 @@ static int usb_extcon_resume(struct device *dev)Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 191
Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c +3
-1enable_irq (info->id_irq);if (!device_may_wakeup (dev)) -usb_extcon_detect_cable (&info->wq_detcable.work); +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable, + info->debounce_jiffies);Why not to just use
queue_work()instead ofqueue_delayed_work()as don't need to debounce the input?
Quoted 1 line
The use of
queue_work()is good.
Unfortunately we can't as info->wq_detcable type is 'struct delayed_work' but queue_work() expects 'struct work_struct'
I'll just call queue_delayed_work() with 0 delay :)
cheers,
-roger
PATCH v3 1/1 extcon: usb-gpio: Don't miss event during suspend/resume
In reply to Roger QuadrosPin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
---
v3:
- use queue_delayed_work() instead of directly calling usb_extcon_detect_cable()
v2:
- only check for state change during resume if device wakeup is
drivers/extcon/extcon-usb-gpio.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/extcon/extcon-usb-gpio.c +3 -0
@@ -185,6 +185,9 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable,0 );return ret; }
Signature · 1 line
2.5.0
Chanwoo Choi
maintainerHi Roger,
Quoted 22 lines · Roger Quadros
Pin state might have changed during suspend/resume while our interrupts were disabled and if device doesn't support wakeup.
Scan for change during resume for such case.
Signed-off-by Roger Quadros <[email protected]>---
v3:
- usequeue_delayed_work()instead of directly callingusb_extcon_detect_cable()v2:
- only check for state change during resume if device wakeup isdrivers/extcon/extcon-usb-gpio.c | 3 +++ 1 file changed, 3 insertions(+)drivers/extcon/extcon-usb-gpio.c +0
-0
drivers/extcon/extcon-usb-gpio.c static int usb_extcon_resume(struct device *dev) · line 193
Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c +3
-0@@ -185,6 +185,9 @@ static int usb_extcon_resume(struct device *dev)int ret =0 ;enable_irq (info->id_irq); +if (!device_may_wakeup (dev)) +queue_delayed_work (system_power_efficient_wq, + &info->wq_detcable,0 );return ret; }
Applied it.
Thanks,
Chanwoo Choi