* [PATCH v2 0/1] rtc: tps6594: Add power management support @ 2024-05-15 15:28 Richard Genoud 2024-05-15 15:28 ` [PATCH v2 1/1] " Richard Genoud 0 siblings, 1 reply; 7+ messages in thread From: Richard Genoud @ 2024-05-15 15:28 UTC (permalink / raw) To: Alexandre Belloni Cc: Thomas Petazzoni, Udit Kumar, Thomas Richard, Gregory CLEMENT, Esteban Blanc, linux-rtc, Lee Jones, linux-kernel, Richard Genoud Changes in v2: - use DEFINE_SIMPLE_DEV_PM_OPS instead of deprecated SIMPLE_DEV_PM_OPS (This fixes the defined but unsed warning when CONFIG_PM is unset) Richard Genoud (1): rtc: tps6594: Add power management support drivers/rtc/rtc-tps6594.c | 46 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/tps6594.h | 1 + 2 files changed, 47 insertions(+) ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-05-15 15:28 [PATCH v2 0/1] rtc: tps6594: Add power management support Richard Genoud @ 2024-05-15 15:28 ` Richard Genoud 2024-05-15 16:11 ` Esteban Blanc ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Richard Genoud @ 2024-05-15 15:28 UTC (permalink / raw) To: Alexandre Belloni Cc: Thomas Petazzoni, Udit Kumar, Thomas Richard, Gregory CLEMENT, Esteban Blanc, linux-rtc, Lee Jones, linux-kernel, Richard Genoud Add power management support to the driver. This allows a SoC to wake from suspend using the nINT provided by the RTC. It takes care of the case when the interrupt has not been caught because the kernel has not yet woke up. (This is the case when only edges interrupt are caught) Signed-off-by: Richard Genoud <richard.genoud@bootlin.com> --- drivers/rtc/rtc-tps6594.c | 46 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/tps6594.h | 1 + 2 files changed, 47 insertions(+) diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c index 838ae8562a35..d221dc560682 100644 --- a/drivers/rtc/rtc-tps6594.c +++ b/drivers/rtc/rtc-tps6594.c @@ -415,6 +415,8 @@ static int tps6594_rtc_probe(struct platform_device *pdev) if (irq < 0) return dev_err_probe(dev, irq, "Failed to get irq\n"); + tps->irq_rtc = irq; + ret = devm_request_threaded_irq(dev, irq, NULL, tps6594_rtc_interrupt, IRQF_ONESHOT, TPS6594_IRQ_NAME_ALARM, dev); @@ -434,6 +436,49 @@ static int tps6594_rtc_probe(struct platform_device *pdev) return devm_rtc_register_device(rtc); } +static int tps6594_rtc_resume(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + struct rtc_device *rtc_dev = dev_get_drvdata(dev); + int ret; + + ret = regmap_test_bits(tps->regmap, TPS6594_REG_INT_STARTUP, + TPS6594_BIT_RTC_INT); + if (ret < 0) { + dev_err(dev, "failed to read REG_INT_STARTUP: %d\n", ret); + goto out; + } + + if (ret > 0) { + /* + * If the alarm bit is set, it means that the IRQ has been + * fired. But, the kernel may not have woke up yet when it + * happened. So, we have to clear it. + */ + ret = regmap_write(tps->regmap, TPS6594_REG_RTC_STATUS, + TPS6594_BIT_ALARM); + if (ret < 0) + dev_err(dev, "error clearing alarm bit: %d", ret); + + rtc_update_irq(rtc_dev, 1, RTC_IRQF | RTC_AF); + } +out: + disable_irq_wake(tps->irq_rtc); + + return 0; +} + +static int tps6594_rtc_suspend(struct device *dev) +{ + struct tps6594 *tps = dev_get_drvdata(dev->parent); + + enable_irq_wake(tps->irq_rtc); + + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(tps6594_rtc_pm_ops, tps6594_rtc_suspend, tps6594_rtc_resume); + static const struct platform_device_id tps6594_rtc_id_table[] = { { "tps6594-rtc", }, {} @@ -444,6 +489,7 @@ static struct platform_driver tps6594_rtc_driver = { .probe = tps6594_rtc_probe, .driver = { .name = "tps6594-rtc", + .pm = pm_sleep_ptr(&tps6594_rtc_pm_ops), }, .id_table = tps6594_rtc_id_table, }; diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h index 3f7c5e23cd4c..85933f1519c4 100644 --- a/include/linux/mfd/tps6594.h +++ b/include/linux/mfd/tps6594.h @@ -1011,6 +1011,7 @@ struct tps6594 { bool use_crc; struct regmap *regmap; int irq; + int irq_rtc; struct regmap_irq_chip_data *irq_data; }; ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-05-15 15:28 ` [PATCH v2 1/1] " Richard Genoud @ 2024-05-15 16:11 ` Esteban Blanc 2024-05-31 13:36 ` Lee Jones 2024-06-14 13:21 ` Thomas Richard 2 siblings, 0 replies; 7+ messages in thread From: Esteban Blanc @ 2024-05-15 16:11 UTC (permalink / raw) To: Richard Genoud, Alexandre Belloni Cc: Thomas Petazzoni, Udit Kumar, Thomas Richard, Gregory CLEMENT, linux-rtc, Lee Jones, linux-kernel Hi Richard, This looks good to me. Reviewed-by: Esteban Blanc <eblanc@baylibre.com> Best regards, -- Esteban "Skallwar" Blanc BayLibre ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-05-15 15:28 ` [PATCH v2 1/1] " Richard Genoud 2024-05-15 16:11 ` Esteban Blanc @ 2024-05-31 13:36 ` Lee Jones 2024-06-14 13:21 ` Thomas Richard 2 siblings, 0 replies; 7+ messages in thread From: Lee Jones @ 2024-05-31 13:36 UTC (permalink / raw) To: Richard Genoud Cc: Alexandre Belloni, Thomas Petazzoni, Udit Kumar, Thomas Richard, Gregory CLEMENT, Esteban Blanc, linux-rtc, linux-kernel On Wed, 15 May 2024, Richard Genoud wrote: > Add power management support to the driver. This allows a SoC to wake > from suspend using the nINT provided by the RTC. > It takes care of the case when the interrupt has not been caught because > the kernel has not yet woke up. > (This is the case when only edges interrupt are caught) > > Signed-off-by: Richard Genoud <richard.genoud@bootlin.com> > --- > drivers/rtc/rtc-tps6594.c | 46 +++++++++++++++++++++++++++++++++++++ > include/linux/mfd/tps6594.h | 1 + Acked-by: Lee Jones <lee@kernel.org> > 2 files changed, 47 insertions(+) -- Lee Jones [李琼斯] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-05-15 15:28 ` [PATCH v2 1/1] " Richard Genoud 2024-05-15 16:11 ` Esteban Blanc 2024-05-31 13:36 ` Lee Jones @ 2024-06-14 13:21 ` Thomas Richard 2024-06-18 9:48 ` Richard GENOUD 2 siblings, 1 reply; 7+ messages in thread From: Thomas Richard @ 2024-06-14 13:21 UTC (permalink / raw) To: Richard Genoud, Alexandre Belloni Cc: Thomas Petazzoni, Udit Kumar, Gregory CLEMENT, Esteban Blanc, linux-rtc, Lee Jones, linux-kernel > diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h > index 3f7c5e23cd4c..85933f1519c4 100644 > --- a/include/linux/mfd/tps6594.h > +++ b/include/linux/mfd/tps6594.h > @@ -1011,6 +1011,7 @@ struct tps6594 { > bool use_crc; > struct regmap *regmap; > int irq; > + int irq_rtc; irq_rtc should be stored in driver data. > struct regmap_irq_chip_data *irq_data; > }; > Thomas ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-06-14 13:21 ` Thomas Richard @ 2024-06-18 9:48 ` Richard GENOUD 2024-06-18 15:17 ` Alexandre Belloni 0 siblings, 1 reply; 7+ messages in thread From: Richard GENOUD @ 2024-06-18 9:48 UTC (permalink / raw) To: Thomas Richard, Alexandre Belloni Cc: Thomas Petazzoni, Udit Kumar, Gregory CLEMENT, Esteban Blanc, linux-rtc, Lee Jones, linux-kernel Le 14/06/2024 à 15:21, Thomas Richard a écrit : >> diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h >> index 3f7c5e23cd4c..85933f1519c4 100644 >> --- a/include/linux/mfd/tps6594.h >> +++ b/include/linux/mfd/tps6594.h >> @@ -1011,6 +1011,7 @@ struct tps6594 { >> bool use_crc; >> struct regmap *regmap; >> int irq; >> + int irq_rtc; > > irq_rtc should be stored in driver data. I understand your point. It may indeed be cleaner to separate the rtc-specific data into a private struct. I'll send a v3 with this modification, and I'll let Alexandre decide which he prefers. > >> struct regmap_irq_chip_data *irq_data; >> }; >> > > Thomas Thanks ! -- Richard Genoud, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/1] rtc: tps6594: Add power management support 2024-06-18 9:48 ` Richard GENOUD @ 2024-06-18 15:17 ` Alexandre Belloni 0 siblings, 0 replies; 7+ messages in thread From: Alexandre Belloni @ 2024-06-18 15:17 UTC (permalink / raw) To: Richard GENOUD Cc: Thomas Richard, Thomas Petazzoni, Udit Kumar, Gregory CLEMENT, Esteban Blanc, linux-rtc, Lee Jones, linux-kernel On 18/06/2024 11:48:33+0200, Richard GENOUD wrote: > Le 14/06/2024 à 15:21, Thomas Richard a écrit : > > > diff --git a/include/linux/mfd/tps6594.h b/include/linux/mfd/tps6594.h > > > index 3f7c5e23cd4c..85933f1519c4 100644 > > > --- a/include/linux/mfd/tps6594.h > > > +++ b/include/linux/mfd/tps6594.h > > > @@ -1011,6 +1011,7 @@ struct tps6594 { > > > bool use_crc; > > > struct regmap *regmap; > > > int irq; > > > + int irq_rtc; > > > > irq_rtc should be stored in driver data. > I understand your point. > It may indeed be cleaner to separate the rtc-specific data into a private > struct. > > I'll send a v3 with this modification, and I'll let Alexandre decide which > he prefers. My plan is to take v2 as-is -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-06-18 15:17 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-05-15 15:28 [PATCH v2 0/1] rtc: tps6594: Add power management support Richard Genoud 2024-05-15 15:28 ` [PATCH v2 1/1] " Richard Genoud 2024-05-15 16:11 ` Esteban Blanc 2024-05-31 13:36 ` Lee Jones 2024-06-14 13:21 ` Thomas Richard 2024-06-18 9:48 ` Richard GENOUD 2024-06-18 15:17 ` Alexandre Belloni
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).