usb: typec: tcpci: add wakeup support
PATCH 1/1 usb: typec: tcpci: add wakeup support
Add wakeup support for tcpci, so if the user has enabled wakeup file, it will call enable_irq_wake() when do system suspend and call disable_irq_wake() when do system resume. Due to this driver supports shared interrupt, if the wakeup is disabled, it will mask the chip interrupt by default to avoid affecting other IRQ users.
--- drivers/usb/typec/tcpm/tcpci.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/usb/typec/tcpm/tcpci.c +33 -0
@@ -949,6 +949,8 @@ static int tcpci_probe(struct i2c_client *client)if (err <0 ) goto unregister_port; +device_set_wakeup_capable (chip->tcpci->dev, true); +return 0 ; unregister_port:
@@ -969,6 +971,36 @@ static void tcpci_remove(struct i2c_client *client)tcpci_unregister_port (chip->tcpci); } +static int tcpci_suspend (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =enable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK ,0 ); + +return ret; +} + +static int tcpci_resume (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =disable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK , chip->tcpci->alert_mask); + +return ret; +} + +DEFINE_SIMPLE_DEV_PM_OPS (tcpci_pm_ops, tcpci_suspend, tcpci_resume); +static const struct i2c_device_id tcpci_id[] = { {"tcpci" }, { }
@@ -987,6 +1019,7 @@ MODULE_DEVICE_TABLE(of, tcpci_of_match);static struct i2c_driver tcpci_i2c_driver = { .driver = { .name ="tcpci" , + .pm =pm_sleep_ptr (&tcpci_pm_ops), .of_match_table =of_match_ptr (tcpci_of_match), }, .probe = tcpci_probe,
Signature · 1 line
2.34.1
Quoted 5 lines · Xu Yang
Add wakeup support for tcpci, so if the user has enabled wakeup file, it will call
enable_irq_wake()when do system suspend and calldisable_irq_wake()when do system resume. Due to this driver supports shared interrupt, if the wakeup is disabled, it will mask the chip interrupt by default to avoid affecting other IRQ users.
Is below look better?
Add wakeup support for tcpci. If the user enables the wakeup file, call enable_irq_wake() during system suspend and disable_irq_wake() during system resume. Since this driver supports shared interrupts, mask the chip interrupt by default when wakeup is disabled to avoid affecting other IRQ users.
Quoted 67 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/typec/tcpm/tcpci.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/usb/typec/tcpm/tcpci.c +33
-1@@ -949,6 +949,8 @@ static int tcpci_probe(struct i2c_client *client)if (err <0 ) goto unregister_port; +device_set_wakeup_capable (chip->tcpci->dev, true); +return 0 ; unregister_port:@@ -969,6 +971,36 @@ static void tcpci_remove(struct i2c_client *client)tcpci_unregister_port (chip->tcpci); } +static int tcpci_suspend (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =enable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK ,0 ); + +return ret; +} + +static int tcpci_resume (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =disable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK , chip->tcpci->alert_mask); + +return ret; +} + +DEFINE_SIMPLE_DEV_PM_OPS (tcpci_pm_ops, tcpci_suspend, tcpci_resume); +static const struct i2c_device_id tcpci_id[] = { {"tcpci" }, { }@@ -987,6 +1019,7 @@ MODULE_DEVICE_TABLE(of, tcpci_of_match);static struct i2c_driver tcpci_i2c_driver = { .driver = { .name ="tcpci" , + .pm =pm_sleep_ptr (&tcpci_pm_ops), .of_match_table =of_match_ptr (tcpci_of_match), }, .probe = tcpci_probe, --2.34.1
Quoted 8 lines · Frank Li
Quoted 5 lines · Xu Yang
Add wakeup support for tcpci, so if the user has enabled wakeup file, it will call
enable_irq_wake()when do system suspend and calldisable_irq_wake()when do system resume. Due to this driver supports shared interrupt, if the wakeup is disabled, it will mask the chip interrupt by default to avoid affecting other IRQ users.
Quoted 7 lines
Is below look better?
Add wakeup support for tcpci. If the user enables the wakeup file, call
enable_irq_wake()during system suspend anddisable_irq_wake()during system resume. Since this driver supports shared interrupts, mask the chip interrupt by default when wakeup is disabled to avoid affecting other IRQ users.
+1, The above description looks more cleaner to me, otherwise LGTM
Quoted 69 lines
Reviewed-by Frank Li <[email protected]>Quoted 67 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/typec/tcpm/tcpci.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/usb/typec/tcpm/tcpci.c +33
-1@@ -949,6 +949,8 @@ static int tcpci_probe(struct i2c_client *client)if (err <0 ) goto unregister_port; +device_set_wakeup_capable (chip->tcpci->dev, true); +return 0 ; unregister_port:@@ -969,6 +971,36 @@ static void tcpci_remove(struct i2c_client *client)tcpci_unregister_port (chip->tcpci); } +static int tcpci_suspend (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =enable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK ,0 ); + +return ret; +} + +static int tcpci_resume (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =disable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK , chip->tcpci->alert_mask); + +return ret; +} + +DEFINE_SIMPLE_DEV_PM_OPS (tcpci_pm_ops, tcpci_suspend, tcpci_resume); +static const struct i2c_device_id tcpci_id[] = { {"tcpci" }, { }@@ -987,6 +1019,7 @@ MODULE_DEVICE_TABLE(of, tcpci_of_match);static struct i2c_driver tcpci_i2c_driver = { .driver = { .name ="tcpci" , + .pm =pm_sleep_ptr (&tcpci_pm_ops), .of_match_table =of_match_ptr (tcpci_of_match), }, .probe = tcpci_probe, --2.34.1
Quoted 8 lines · Frank Li
Quoted 5 lines · Xu Yang
Add wakeup support for tcpci, so if the user has enabled wakeup file, it will call
enable_irq_wake()when do system suspend and calldisable_irq_wake()when do system resume. Due to this driver supports shared interrupt, if the wakeup is disabled, it will mask the chip interrupt by default to avoid affecting other IRQ users.Is below look better?
Sure. Thank you!
Quoted 75 lines
Add wakeup support for tcpci. If the user enables the wakeup file, call
enable_irq_wake()during system suspend anddisable_irq_wake()during system resume. Since this driver supports shared interrupts, mask the chip interrupt by default when wakeup is disabled to avoid affecting other IRQ users.Reviewed-by Frank Li <[email protected]>Quoted 67 lines
Signed-off-by Xu Yang <[email protected]>--- drivers/usb/typec/tcpm/tcpci.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/usb/typec/tcpm/tcpci.c +33
-1@@ -949,6 +949,8 @@ static int tcpci_probe(struct i2c_client *client)if (err <0 ) goto unregister_port; +device_set_wakeup_capable (chip->tcpci->dev, true); +return 0 ; unregister_port:@@ -969,6 +971,36 @@ static void tcpci_remove(struct i2c_client *client)tcpci_unregister_port (chip->tcpci); } +static int tcpci_suspend (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =enable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK ,0 ); + +return ret; +} + +static int tcpci_resume (struct device *dev) +{ +struct i2c_client *i2c =to_i2c_client (dev); +struct tcpci_chip *chip =i2c_get_clientdata (i2c); +int ret; + +if (device_may_wakeup (dev)) + ret =disable_irq_wake (i2c->irq); +else + ret =tcpci_write16 (chip->tcpci,TCPC_ALERT_MASK , chip->tcpci->alert_mask); + +return ret; +} + +DEFINE_SIMPLE_DEV_PM_OPS (tcpci_pm_ops, tcpci_suspend, tcpci_resume); +static const struct i2c_device_id tcpci_id[] = { {"tcpci" }, { }@@ -987,6 +1019,7 @@ MODULE_DEVICE_TABLE(of, tcpci_of_match);static struct i2c_driver tcpci_i2c_driver = { .driver = { .name ="tcpci" , + .pm =pm_sleep_ptr (&tcpci_pm_ops), .of_match_table =of_match_ptr (tcpci_of_match), }, .probe = tcpci_probe, --2.34.1