* [PATCH v3 1/3] rtc: tps6594: Fix memleak in probe
2024-06-18 14:18 [PATCH v3 0/3] rtc: tps6594: Add power management support Richard Genoud
@ 2024-06-18 14:18 ` Richard Genoud
2024-06-18 14:18 ` [PATCH v3 2/3] rtc: tps6594: introduce private structure as drvdata Richard Genoud
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Richard Genoud @ 2024-06-18 14:18 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
struct rtc_device is allocated twice in probe(), once with
devm_kzalloc(), and then with devm_rtc_allocate_device().
The allocation with devm_kzalloc() is lost and superfluous.
Fixes: 9f67c1e63976 ("rtc: tps6594: Add driver for TPS6594 RTC")
Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
---
drivers/rtc/rtc-tps6594.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c
index 838ae8562a35..bc8dc735aa23 100644
--- a/drivers/rtc/rtc-tps6594.c
+++ b/drivers/rtc/rtc-tps6594.c
@@ -360,10 +360,6 @@ static int tps6594_rtc_probe(struct platform_device *pdev)
int irq;
int ret;
- rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
- if (!rtc)
- return -ENOMEM;
-
rtc = devm_rtc_allocate_device(dev);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 2/3] rtc: tps6594: introduce private structure as drvdata
2024-06-18 14:18 [PATCH v3 0/3] rtc: tps6594: Add power management support Richard Genoud
2024-06-18 14:18 ` [PATCH v3 1/3] rtc: tps6594: Fix memleak in probe Richard Genoud
@ 2024-06-18 14:18 ` Richard Genoud
2024-06-18 14:18 ` [PATCH v3 3/3] rtc: tps6594: Add power management support Richard Genoud
2024-06-27 22:22 ` [PATCH v3 0/3] " Alexandre Belloni
3 siblings, 0 replies; 5+ messages in thread
From: Richard Genoud @ 2024-06-18 14:18 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
This patch will prepare for the next one (power management support) by
introducing struct tps6594_rtc.
No functionnal change.
Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
---
drivers/rtc/rtc-tps6594.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c
index bc8dc735aa23..06af177b2d78 100644
--- a/drivers/rtc/rtc-tps6594.c
+++ b/drivers/rtc/rtc-tps6594.c
@@ -42,6 +42,10 @@
// Multiplier for ppb conversions
#define PPB_MULT NANO
+struct tps6594_rtc {
+ struct rtc_device *rtc_dev;
+};
+
static int tps6594_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
@@ -325,11 +329,11 @@ static int tps6594_rtc_set_offset(struct device *dev, long offset)
return tps6594_rtc_set_calibration(dev, calibration);
}
-static irqreturn_t tps6594_rtc_interrupt(int irq, void *rtc)
+static irqreturn_t tps6594_rtc_interrupt(int irq, void *data)
{
- struct device *dev = rtc;
+ struct device *dev = data;
struct tps6594 *tps = dev_get_drvdata(dev->parent);
- struct rtc_device *rtc_dev = dev_get_drvdata(dev);
+ struct tps6594_rtc *rtc = dev_get_drvdata(dev);
int ret;
u32 rtc_reg;
@@ -337,7 +341,7 @@ static irqreturn_t tps6594_rtc_interrupt(int irq, void *rtc)
if (ret)
return IRQ_NONE;
- rtc_update_irq(rtc_dev, 1, RTC_IRQF | RTC_AF);
+ rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
return IRQ_HANDLED;
}
@@ -356,13 +360,17 @@ static int tps6594_rtc_probe(struct platform_device *pdev)
{
struct tps6594 *tps = dev_get_drvdata(pdev->dev.parent);
struct device *dev = &pdev->dev;
- struct rtc_device *rtc;
+ struct tps6594_rtc *rtc;
int irq;
int ret;
- rtc = devm_rtc_allocate_device(dev);
- if (IS_ERR(rtc))
- return PTR_ERR(rtc);
+ rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
+ if (!rtc)
+ return -ENOMEM;
+
+ rtc->rtc_dev = devm_rtc_allocate_device(dev);
+ if (IS_ERR(rtc->rtc_dev))
+ return PTR_ERR(rtc->rtc_dev);
// Enable crystal oscillator.
ret = regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_2,
@@ -423,11 +431,11 @@ static int tps6594_rtc_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret,
"Failed to init rtc as wakeup source\n");
- rtc->ops = &tps6594_rtc_ops;
- rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
- rtc->range_max = RTC_TIMESTAMP_END_2099;
+ rtc->rtc_dev->ops = &tps6594_rtc_ops;
+ rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
+ rtc->rtc_dev->range_max = RTC_TIMESTAMP_END_2099;
- return devm_rtc_register_device(rtc);
+ return devm_rtc_register_device(rtc->rtc_dev);
}
static const struct platform_device_id tps6594_rtc_id_table[] = {
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v3 3/3] rtc: tps6594: Add power management support
2024-06-18 14:18 [PATCH v3 0/3] rtc: tps6594: Add power management support Richard Genoud
2024-06-18 14:18 ` [PATCH v3 1/3] rtc: tps6594: Fix memleak in probe Richard Genoud
2024-06-18 14:18 ` [PATCH v3 2/3] rtc: tps6594: introduce private structure as drvdata Richard Genoud
@ 2024-06-18 14:18 ` Richard Genoud
2024-06-27 22:22 ` [PATCH v3 0/3] " Alexandre Belloni
3 siblings, 0 replies; 5+ messages in thread
From: Richard Genoud @ 2024-06-18 14:18 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 | 47 +++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/drivers/rtc/rtc-tps6594.c b/drivers/rtc/rtc-tps6594.c
index 06af177b2d78..e69667634137 100644
--- a/drivers/rtc/rtc-tps6594.c
+++ b/drivers/rtc/rtc-tps6594.c
@@ -44,6 +44,7 @@
struct tps6594_rtc {
struct rtc_device *rtc_dev;
+ int irq;
};
static int tps6594_rtc_alarm_irq_enable(struct device *dev,
@@ -419,6 +420,8 @@ static int tps6594_rtc_probe(struct platform_device *pdev)
if (irq < 0)
return dev_err_probe(dev, irq, "Failed to get irq\n");
+ rtc->irq = irq;
+
ret = devm_request_threaded_irq(dev, irq, NULL, tps6594_rtc_interrupt,
IRQF_ONESHOT, TPS6594_IRQ_NAME_ALARM,
dev);
@@ -438,6 +441,49 @@ static int tps6594_rtc_probe(struct platform_device *pdev)
return devm_rtc_register_device(rtc->rtc_dev);
}
+static int tps6594_rtc_resume(struct device *dev)
+{
+ struct tps6594 *tps = dev_get_drvdata(dev->parent);
+ struct tps6594_rtc *rtc = 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->rtc_dev, 1, RTC_IRQF | RTC_AF);
+ }
+out:
+ disable_irq_wake(rtc->irq);
+
+ return 0;
+}
+
+static int tps6594_rtc_suspend(struct device *dev)
+{
+ struct tps6594_rtc *rtc = dev_get_drvdata(dev);
+
+ enable_irq_wake(rtc->irq);
+
+ 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", },
{}
@@ -448,6 +494,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,
};
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v3 0/3] rtc: tps6594: Add power management support
2024-06-18 14:18 [PATCH v3 0/3] rtc: tps6594: Add power management support Richard Genoud
` (2 preceding siblings ...)
2024-06-18 14:18 ` [PATCH v3 3/3] rtc: tps6594: Add power management support Richard Genoud
@ 2024-06-27 22:22 ` Alexandre Belloni
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2024-06-27 22:22 UTC (permalink / raw)
To: Richard Genoud
Cc: Thomas Petazzoni, Udit Kumar, Thomas Richard, Gregory CLEMENT,
Esteban Blanc, linux-rtc, Lee Jones, linux-kernel
On Tue, 18 Jun 2024 16:18:48 +0200, Richard Genoud wrote:
> This series add power management support for tps6594_rtc.
>
> The 1st patch fixes a memleak found in the probe()
> The 2nd patch simply introduce a private structure as drvdata that will
> be used in the 3rd patch. (no functionnal change)
> The 3rd patch introduce the power management support.
>
> [...]
Applied, thanks!
[1/3] rtc: tps6594: Fix memleak in probe
https://git.kernel.org/abelloni/c/94d4154792ab
[2/3] rtc: tps6594: introduce private structure as drvdata
https://git.kernel.org/abelloni/c/29bf97586f18
[3/3] rtc: tps6594: Add power management support
https://git.kernel.org/abelloni/c/c88014c7aa5c
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread