linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device
@ 2021-08-04 10:41 Alexandre Belloni
  2021-08-04 10:41 ` [PATCH 2/4] rtc: s5m: signal the core when alarm are not available Alexandre Belloni
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Alexandre Belloni @ 2021-08-04 10:41 UTC (permalink / raw)
  To: Alessandro Zummo, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
	Alexandre Belloni
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

Switch to devm_rtc_allocate_device/devm_rtc_register_device, this allows
for further improvement of the driver.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-s5m.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 6b56f8eacba6..4c1596c55de8 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -788,12 +788,16 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 
 	device_init_wakeup(&pdev->dev, 1);
 
-	info->rtc_dev = devm_rtc_device_register(&pdev->dev, "s5m-rtc",
-						 &s5m_rtc_ops, THIS_MODULE);
-
+	info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(info->rtc_dev))
 		return PTR_ERR(info->rtc_dev);
 
+	info->rtc_dev->ops = &s5m_rtc_ops;
+
+	err = devm_rtc_register_device(info->rtc_dev);
+	if (err)
+		return err;
+
 	if (!info->irq) {
 		dev_info(&pdev->dev, "Alarm IRQ not available\n");
 		return 0;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] rtc: s5m: signal the core when alarm are not available
  2021-08-04 10:41 [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Alexandre Belloni
@ 2021-08-04 10:41 ` Alexandre Belloni
  2021-08-04 11:48   ` Krzysztof Kozlowski
  2021-08-04 10:41 ` [PATCH 3/4] rtc: s5m: enable wakeup only when available Alexandre Belloni
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Alexandre Belloni @ 2021-08-04 10:41 UTC (permalink / raw)
  To: Alessandro Zummo, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
	Alexandre Belloni
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

Clear the RTC_FEATURE_ALARM bit to signal to the core when alarms are not
available to ensure the alarm callbacks are never called and userspace is
aware alarms are not supported.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-s5m.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 4c1596c55de8..ee195697e6c6 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -794,25 +794,20 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 
 	info->rtc_dev->ops = &s5m_rtc_ops;
 
-	err = devm_rtc_register_device(info->rtc_dev);
-	if (err)
-		return err;
-
 	if (!info->irq) {
-		dev_info(&pdev->dev, "Alarm IRQ not available\n");
-		return 0;
-	}
-
-	ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
-					s5m_rtc_alarm_irq, 0, "rtc-alarm0",
-					info);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
-			info->irq, ret);
-		return ret;
+		clear_bit(RTC_FEATURE_ALARM, info->rtc_dev->features);
+	} else {
+		ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
+						s5m_rtc_alarm_irq, 0, "rtc-alarm0",
+						info);
+		if (ret < 0) {
+			dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
+				info->irq, ret);
+			return ret;
+		}
 	}
 
-	return 0;
+	return devm_rtc_register_device(info->rtc_dev);
 }
 
 #ifdef CONFIG_PM_SLEEP
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] rtc: s5m: enable wakeup only when available
  2021-08-04 10:41 [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Alexandre Belloni
  2021-08-04 10:41 ` [PATCH 2/4] rtc: s5m: signal the core when alarm are not available Alexandre Belloni
@ 2021-08-04 10:41 ` Alexandre Belloni
  2021-08-04 11:48   ` Krzysztof Kozlowski
  2021-08-04 10:41 ` [PATCH 4/4] rtc: s5m: set range Alexandre Belloni
  2021-08-04 11:43 ` [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Krzysztof Kozlowski
  3 siblings, 1 reply; 8+ messages in thread
From: Alexandre Belloni @ 2021-08-04 10:41 UTC (permalink / raw)
  To: Alessandro Zummo, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
	Alexandre Belloni
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

Call device_init_wakeup() only when alarms are available and the RTC is
actually able to wake up the system.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-s5m.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index ee195697e6c6..87df797758fc 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -786,8 +786,6 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	device_init_wakeup(&pdev->dev, 1);
-
 	info->rtc_dev = devm_rtc_allocate_device(&pdev->dev);
 	if (IS_ERR(info->rtc_dev))
 		return PTR_ERR(info->rtc_dev);
@@ -805,6 +803,7 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 				info->irq, ret);
 			return ret;
 		}
+		device_init_wakeup(&pdev->dev, 1);
 	}
 
 	return devm_rtc_register_device(info->rtc_dev);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] rtc: s5m: set range
  2021-08-04 10:41 [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Alexandre Belloni
  2021-08-04 10:41 ` [PATCH 2/4] rtc: s5m: signal the core when alarm are not available Alexandre Belloni
  2021-08-04 10:41 ` [PATCH 3/4] rtc: s5m: enable wakeup only when available Alexandre Belloni
@ 2021-08-04 10:41 ` Alexandre Belloni
  2021-08-04 12:01   ` Krzysztof Kozlowski
  2021-08-04 11:43 ` [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Krzysztof Kozlowski
  3 siblings, 1 reply; 8+ messages in thread
From: Alexandre Belloni @ 2021-08-04 10:41 UTC (permalink / raw)
  To: Alessandro Zummo, Krzysztof Kozlowski, Bartlomiej Zolnierkiewicz,
	Alexandre Belloni
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

The S5M8763X type seems to handles dates from year 0000 to 9999, there is
no info on leap year handling after 2099. The other models handles dates
from 2000 to 2099.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/rtc/rtc-s5m.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 87df797758fc..fb9c6b709e13 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -204,15 +204,9 @@ static int s5m8767_tm_to_data(struct rtc_time *tm, u8 *data)
 	data[RTC_WEEKDAY] = 1 << tm->tm_wday;
 	data[RTC_DATE] = tm->tm_mday;
 	data[RTC_MONTH] = tm->tm_mon + 1;
-	data[RTC_YEAR1] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
+	data[RTC_YEAR1] = tm->tm_year - 100;
 
-	if (tm->tm_year < 100) {
-		pr_err("RTC cannot handle the year %d\n",
-		       1900 + tm->tm_year);
-		return -EINVAL;
-	} else {
-		return 0;
-	}
+	return 0;
 }
 
 /*
@@ -792,6 +786,14 @@ static int s5m_rtc_probe(struct platform_device *pdev)
 
 	info->rtc_dev->ops = &s5m_rtc_ops;
 
+	if (info->device_type == S5M8763X) {
+		info->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_0000;
+		info->rtc_dev->range_max = RTC_TIMESTAMP_END_9999;
+	} else {
+		info->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_2000;
+		info->rtc_dev->range_max = RTC_TIMESTAMP_END_2099;
+	}
+
 	if (!info->irq) {
 		clear_bit(RTC_FEATURE_ALARM, info->rtc_dev->features);
 	} else {
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device
  2021-08-04 10:41 [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Alexandre Belloni
                   ` (2 preceding siblings ...)
  2021-08-04 10:41 ` [PATCH 4/4] rtc: s5m: set range Alexandre Belloni
@ 2021-08-04 11:43 ` Krzysztof Kozlowski
  3 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-08-04 11:43 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo, Bartlomiej Zolnierkiewicz
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

On 04/08/2021 12:41, Alexandre Belloni wrote:
> Switch to devm_rtc_allocate_device/devm_rtc_register_device, this allows
> for further improvement of the driver.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-s5m.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] rtc: s5m: signal the core when alarm are not available
  2021-08-04 10:41 ` [PATCH 2/4] rtc: s5m: signal the core when alarm are not available Alexandre Belloni
@ 2021-08-04 11:48   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-08-04 11:48 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo, Bartlomiej Zolnierkiewicz
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

On 04/08/2021 12:41, Alexandre Belloni wrote:
> Clear the RTC_FEATURE_ALARM bit to signal to the core when alarms are not
> available to ensure the alarm callbacks are never called and userspace is
> aware alarms are not supported.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-s5m.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
> 


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] rtc: s5m: enable wakeup only when available
  2021-08-04 10:41 ` [PATCH 3/4] rtc: s5m: enable wakeup only when available Alexandre Belloni
@ 2021-08-04 11:48   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-08-04 11:48 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo, Bartlomiej Zolnierkiewicz
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

On 04/08/2021 12:41, Alexandre Belloni wrote:
> Call device_init_wakeup() only when alarms are available and the RTC is
> actually able to wake up the system.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-s5m.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] rtc: s5m: set range
  2021-08-04 10:41 ` [PATCH 4/4] rtc: s5m: set range Alexandre Belloni
@ 2021-08-04 12:01   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2021-08-04 12:01 UTC (permalink / raw)
  To: Alexandre Belloni, Alessandro Zummo, Bartlomiej Zolnierkiewicz
  Cc: linux-rtc, linux-kernel, linux-samsung-soc

On 04/08/2021 12:41, Alexandre Belloni wrote:
> The S5M8763X type seems to handles dates from year 0000 to 9999, there is
> no info on leap year handling after 2099. The other models handles dates
> from 2000 to 2099.
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
> ---
>  drivers/rtc/rtc-s5m.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 

Seems correct:


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-08-04 12:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-04 10:41 [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Alexandre Belloni
2021-08-04 10:41 ` [PATCH 2/4] rtc: s5m: signal the core when alarm are not available Alexandre Belloni
2021-08-04 11:48   ` Krzysztof Kozlowski
2021-08-04 10:41 ` [PATCH 3/4] rtc: s5m: enable wakeup only when available Alexandre Belloni
2021-08-04 11:48   ` Krzysztof Kozlowski
2021-08-04 10:41 ` [PATCH 4/4] rtc: s5m: set range Alexandre Belloni
2021-08-04 12:01   ` Krzysztof Kozlowski
2021-08-04 11:43 ` [PATCH 1/4] rtc: s5m: switch to devm_rtc_allocate_device Krzysztof Kozlowski

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).