Message ID | 20250103-wake_irq-v2-1-e3aeff5e9966@nxp.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | pm: Introduce devm_pm_set_wake_irq | expand |
On Fri, Jan 3, 2025 at 9:42 AM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote: > > From: Peng Fan <peng.fan@nxp.com> > > Add device-managed variant of dev_pm_set_wake_irq which automatically > clear the wake irq on device destruction to simplify error handling > and resource management in drivers. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- > drivers/base/power/wakeirq.c | 26 ++++++++++++++++++++++++++ > include/linux/pm_wakeirq.h | 6 ++++++ > 2 files changed, 32 insertions(+) > > diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c > index 5a5a9e978e85f3fc9d89cb7d43527dc1dd42a9b1..8aa28c08b2891f3af490175362cc1a759069bd50 100644 > --- a/drivers/base/power/wakeirq.c > +++ b/drivers/base/power/wakeirq.c > @@ -103,6 +103,32 @@ void dev_pm_clear_wake_irq(struct device *dev) > } > EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq); > > +static void devm_pm_clear_wake_irq(void *dev) > +{ > + dev_pm_clear_wake_irq(dev); > +} > + > +/** > + * devm_pm_set_wake_irq - device-managed variant of dev_pm_set_wake_irq > + * @dev: Device entry > + * @irq: Device IO interrupt > + * > + * > + * Attach a device IO interrupt as a wake IRQ, same with dev_pm_set_wake_irq, > + * but the device will be auto clear wake capability on driver detach. > + */ > +int devm_pm_set_wake_irq(struct device *dev, int irq) > +{ > + int ret; > + > + ret = dev_pm_set_wake_irq(dev, irq); > + if (ret) > + return ret; > + > + return devm_add_action_or_reset(dev, devm_pm_clear_wake_irq, dev); > +} > +EXPORT_SYMBOL_GPL(devm_pm_set_wake_irq); > + > /** > * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts > * @irq: Device specific dedicated wake-up interrupt > diff --git a/include/linux/pm_wakeirq.h b/include/linux/pm_wakeirq.h > index d9642c6cf85211af603ce39e280a5b4de6617ee5..25b63ed51b765c2c6919f259668a12675330835e 100644 > --- a/include/linux/pm_wakeirq.h > +++ b/include/linux/pm_wakeirq.h > @@ -10,6 +10,7 @@ extern int dev_pm_set_wake_irq(struct device *dev, int irq); > extern int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq); > extern int dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq); > extern void dev_pm_clear_wake_irq(struct device *dev); > +extern int devm_pm_set_wake_irq(struct device *dev, int irq); > > #else /* !CONFIG_PM */ > > @@ -32,5 +33,10 @@ static inline void dev_pm_clear_wake_irq(struct device *dev) > { > } > > +static inline int devm_pm_set_wake_irq(struct device *dev, int irq) > +{ > + return 0; > +} > + > #endif /* CONFIG_PM */ > #endif /* _LINUX_PM_WAKEIRQ_H */ > > -- I can apply this patch for 6.14, but the rest of the series will need to be picked up by the respective driver maintainers. I hope this works for you?
> Subject: Re: [PATCH v2 01/12] PM: sleep: wakeirq: Introduce device- > managed variant of dev_pm_set_wake_irq > > On Fri, Jan 3, 2025 at 9:42 AM Peng Fan (OSS) <peng.fan@oss.nxp.com> > wrote: > > > > From: Peng Fan <peng.fan@nxp.com> > > > > Add device-managed variant of dev_pm_set_wake_irq which > automatically > > clear the wake irq on device destruction to simplify error handling > > and resource management in drivers. > > > > Signed-off-by: Peng Fan <peng.fan@nxp.com> > > --- > > drivers/base/power/wakeirq.c | 26 ++++++++++++++++++++++++++ > > include/linux/pm_wakeirq.h | 6 ++++++ > > 2 files changed, 32 insertions(+) > > > > diff --git a/drivers/base/power/wakeirq.c > > b/drivers/base/power/wakeirq.c index > > > 5a5a9e978e85f3fc9d89cb7d43527dc1dd42a9b1..8aa28c08b2891f3af > 490175362cc > > 1a759069bd50 100644 > > --- a/drivers/base/power/wakeirq.c > > +++ b/drivers/base/power/wakeirq.c > > @@ -103,6 +103,32 @@ void dev_pm_clear_wake_irq(struct device > *dev) } > > EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq); > > > > +static void devm_pm_clear_wake_irq(void *dev) { > > + dev_pm_clear_wake_irq(dev); > > +} > > + > > +/** > > + * devm_pm_set_wake_irq - device-managed variant of > > +dev_pm_set_wake_irq > > + * @dev: Device entry > > + * @irq: Device IO interrupt > > + * > > + * > > + * Attach a device IO interrupt as a wake IRQ, same with > > +dev_pm_set_wake_irq, > > + * but the device will be auto clear wake capability on driver detach. > > + */ > > +int devm_pm_set_wake_irq(struct device *dev, int irq) { > > + int ret; > > + > > + ret = dev_pm_set_wake_irq(dev, irq); > > + if (ret) > > + return ret; > > + > > + return devm_add_action_or_reset(dev, > devm_pm_clear_wake_irq, > > +dev); } EXPORT_SYMBOL_GPL(devm_pm_set_wake_irq); > > + > > /** > > * handle_threaded_wake_irq - Handler for dedicated wake-up > interrupts > > * @irq: Device specific dedicated wake-up interrupt diff --git > > a/include/linux/pm_wakeirq.h b/include/linux/pm_wakeirq.h index > > > d9642c6cf85211af603ce39e280a5b4de6617ee5..25b63ed51b765c2c6 > 919f259668a > > 12675330835e 100644 > > --- a/include/linux/pm_wakeirq.h > > +++ b/include/linux/pm_wakeirq.h > > @@ -10,6 +10,7 @@ extern int dev_pm_set_wake_irq(struct device > *dev, > > int irq); extern int dev_pm_set_dedicated_wake_irq(struct device > > *dev, int irq); extern int > > dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq); > > extern void dev_pm_clear_wake_irq(struct device *dev); > > +extern int devm_pm_set_wake_irq(struct device *dev, int irq); > > > > #else /* !CONFIG_PM */ > > > > @@ -32,5 +33,10 @@ static inline void > dev_pm_clear_wake_irq(struct > > device *dev) { } > > > > +static inline int devm_pm_set_wake_irq(struct device *dev, int irq) { > > + return 0; > > +} > > + > > #endif /* CONFIG_PM */ > > #endif /* _LINUX_PM_WAKEIRQ_H */ > > > > -- > > I can apply this patch for 6.14, but the rest of the series will need to be > picked up by the respective driver maintainers. > > I hope this works for you? Yes. please just pick up patch 1. Patch [2-12]/12 should go through RTC and INPUT maintainer's tree Thanks, Peng.
diff --git a/drivers/base/power/wakeirq.c b/drivers/base/power/wakeirq.c index 5a5a9e978e85f3fc9d89cb7d43527dc1dd42a9b1..8aa28c08b2891f3af490175362cc1a759069bd50 100644 --- a/drivers/base/power/wakeirq.c +++ b/drivers/base/power/wakeirq.c @@ -103,6 +103,32 @@ void dev_pm_clear_wake_irq(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq); +static void devm_pm_clear_wake_irq(void *dev) +{ + dev_pm_clear_wake_irq(dev); +} + +/** + * devm_pm_set_wake_irq - device-managed variant of dev_pm_set_wake_irq + * @dev: Device entry + * @irq: Device IO interrupt + * + * + * Attach a device IO interrupt as a wake IRQ, same with dev_pm_set_wake_irq, + * but the device will be auto clear wake capability on driver detach. + */ +int devm_pm_set_wake_irq(struct device *dev, int irq) +{ + int ret; + + ret = dev_pm_set_wake_irq(dev, irq); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, devm_pm_clear_wake_irq, dev); +} +EXPORT_SYMBOL_GPL(devm_pm_set_wake_irq); + /** * handle_threaded_wake_irq - Handler for dedicated wake-up interrupts * @irq: Device specific dedicated wake-up interrupt diff --git a/include/linux/pm_wakeirq.h b/include/linux/pm_wakeirq.h index d9642c6cf85211af603ce39e280a5b4de6617ee5..25b63ed51b765c2c6919f259668a12675330835e 100644 --- a/include/linux/pm_wakeirq.h +++ b/include/linux/pm_wakeirq.h @@ -10,6 +10,7 @@ extern int dev_pm_set_wake_irq(struct device *dev, int irq); extern int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq); extern int dev_pm_set_dedicated_wake_irq_reverse(struct device *dev, int irq); extern void dev_pm_clear_wake_irq(struct device *dev); +extern int devm_pm_set_wake_irq(struct device *dev, int irq); #else /* !CONFIG_PM */ @@ -32,5 +33,10 @@ static inline void dev_pm_clear_wake_irq(struct device *dev) { } +static inline int devm_pm_set_wake_irq(struct device *dev, int irq) +{ + return 0; +} + #endif /* CONFIG_PM */ #endif /* _LINUX_PM_WAKEIRQ_H */