2015-11-01 11:40:40

by Krzysztof Kozłowski

[permalink] [raw]
Subject: [PATCH v2] rtc: rtc-s3c: Set year, month, day value for setting alarm

From: Donggeun Kim <[email protected]>

This patch sets year, month, day value for set_alarm function.
The current driver omits to set the values.

This fixes setting wake alarm for dates different than current day.
Without the patch the alarm scheduled for tomorrow would fire today on
chosen time.

Signed-off-by: Donggeun Kim <[email protected]>
Signed-off-by: MyungJoo Ham <[email protected]>
Signed-off-by: KyungMin Park <[email protected]>
[k.kozlowski: Rebase and test the patch, update commit message]
Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/rtc/rtc-s3c.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 7cc8f73a3fe8..5604ebbef222 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -149,6 +149,7 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
if (!is_power_of_2(freq))
return -EINVAL;

+ WARN_ON(1);
spin_lock_irq(&info->pie_lock);

if (info->data->set_freq)
@@ -302,6 +303,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
struct s3c_rtc *info = dev_get_drvdata(dev);
struct rtc_time *tm = &alrm->time;
unsigned int alrm_en;
+ int year = tm->tm_year - 100;

dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
alrm->enabled,
@@ -328,6 +330,21 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR);
}

+ if (year < 100 && year >= 0) {
+ alrm_en |= S3C2410_RTCALM_YEAREN;
+ writeb(bin2bcd(year), info->base + S3C2410_ALMYEAR);
+ }
+
+ if (tm->tm_mon < 12 && tm->tm_mon >= 0) {
+ alrm_en |= S3C2410_RTCALM_MONEN;
+ writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON);
+ }
+
+ if (tm->tm_mday <= 31 && tm->tm_mday >= 1) {
+ alrm_en |= S3C2410_RTCALM_DAYEN;
+ writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_ALMDATE);
+ }
+
dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);

writeb(alrm_en, info->base + S3C2410_RTCALM);
--
2.1.4


2015-11-01 11:42:29

by Krzysztof Kozłowski

[permalink] [raw]
Subject: Re: [PATCH v2] rtc: rtc-s3c: Set year, month, day value for setting alarm

W dniu 01.11.2015 o 20:40, Krzysztof Kozlowski pisze:
> From: Donggeun Kim <[email protected]>
>
> This patch sets year, month, day value for set_alarm function.
> The current driver omits to set the values.
>
> This fixes setting wake alarm for dates different than current day.
> Without the patch the alarm scheduled for tomorrow would fire today on
> chosen time.
>
> Signed-off-by: Donggeun Kim <[email protected]>
> Signed-off-by: MyungJoo Ham <[email protected]>
> Signed-off-by: KyungMin Park <[email protected]>
> [k.kozlowski: Rebase and test the patch, update commit message]
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
> drivers/rtc/rtc-s3c.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
> index 7cc8f73a3fe8..5604ebbef222 100644
> --- a/drivers/rtc/rtc-s3c.c
> +++ b/drivers/rtc/rtc-s3c.c
> @@ -149,6 +149,7 @@ static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
> if (!is_power_of_2(freq))
> return -EINVAL;
>
> + WARN_ON(1);

Ehhh, this is debug. Sorry for the noise.

These emails: [email protected] and [email protected] do not
exist anymore. I'll replace the author with myself in that case.

Best regards,
Krzysztof

> spin_lock_irq(&info->pie_lock);
>
> if (info->data->set_freq)
> @@ -302,6 +303,7 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
> struct s3c_rtc *info = dev_get_drvdata(dev);
> struct rtc_time *tm = &alrm->time;
> unsigned int alrm_en;
> + int year = tm->tm_year - 100;
>
> dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
> alrm->enabled,
> @@ -328,6 +330,21 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
> writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR);
> }
>
> + if (year < 100 && year >= 0) {
> + alrm_en |= S3C2410_RTCALM_YEAREN;
> + writeb(bin2bcd(year), info->base + S3C2410_ALMYEAR);
> + }
> +
> + if (tm->tm_mon < 12 && tm->tm_mon >= 0) {
> + alrm_en |= S3C2410_RTCALM_MONEN;
> + writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON);
> + }
> +
> + if (tm->tm_mday <= 31 && tm->tm_mday >= 1) {
> + alrm_en |= S3C2410_RTCALM_DAYEN;
> + writeb(bin2bcd(tm->tm_mday), info->base + S3C2410_ALMDATE);
> + }
> +
> dev_dbg(dev, "setting S3C2410_RTCALM to %08x\n", alrm_en);
>
> writeb(alrm_en, info->base + S3C2410_RTCALM);
>