* [rtc-linux] [PATCH 2/3] tools: timer: add test to check y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-16 14:03 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org>
The goal of this test is to check if a RTC device correctly support
dates after years 2038 or 2106.
It set a date (1-1-2200) on RTC and read it back to be sure that the
driver is working well.
The same thing is done on alarm.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
tools/testing/selftests/timers/Makefile | 4 +-
tools/testing/selftests/timers/rtctest-2038.c | 135 ++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/timers/rtctest-2038.c
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 54481f1..7791f79 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -9,7 +9,8 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
skew_consistency clocksource-switch leap-a-day \
- leapcrash set-tai set-2038 set-tz rtctest_setdate
+ leapcrash set-tai set-2038 set-tz rtctest_setdate \
+ rtctest-2038
include ../lib.mk
@@ -29,4 +30,5 @@ run_destructive_tests: run_tests
./set-tz
./set-tai
./set-2038
+ ./rtctest-2038
diff --git a/tools/testing/selftests/timers/rtctest-2038.c b/tools/testing/selftests/timers/rtctest-2038.c
new file mode 100644
index 0000000..213b7ee
--- /dev/null
+++ b/tools/testing/selftests/timers/rtctest-2038.c
@@ -0,0 +1,135 @@
+/* Real Time Clock Driver Test
+ * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
+ *
+ * To build
+ * gcc rtctest-2038.c -o rtctest-2038
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+static const char default_rtc[] = "/dev/rtc0";
+
+int main(int argc, char **argv)
+{
+ int fd, retval;
+ struct rtc_time new, current;
+ const char *rtc = default_rtc;
+
+ switch (argc) {
+ case 2:
+ rtc = argv[1];
+ /* FALLTHROUGH */
+ case 1:
+ break;
+ default:
+ fprintf(stderr, "usage: rtctest-2038 [rtcdev]\n");
+ return 1;
+ }
+
+ fprintf(stderr, "\nTest if RTC is robust for date after y2038/2106\n\n");
+
+ fd = open(rtc, O_RDONLY);
+ if (fd == -1) {
+ perror(rtc);
+ exit(errno);
+ }
+
+ new.tm_year = 300; /* 2200 - 1900 */
+ new.tm_mon = 0;
+ new.tm_mday = 1;
+ new.tm_hour = 0;
+ new.tm_min = 0;
+ new.tm_sec = 0;
+
+ fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new date in RTC */
+ retval = ioctl(fd, RTC_SET_TIME, &new);
+ if (retval == -1) {
+ perror("RTC_SET_TIME ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_RD_TIME, ¤t);
+ if (retval == -1) {
+ perror("RTC_RD_TIME ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ if (new.tm_year != current.tm_year ||
+ new.tm_mon != current.tm_mon ||
+ new.tm_mday != current.tm_mday ||
+ new.tm_hour != current.tm_hour ||
+ new.tm_min != current.tm_min ||
+ new.tm_sec != current.tm_sec) {
+ fprintf(stderr, "\n\nSet Time test failed\n");
+ close(fd);
+ return 1;
+ }
+
+ new.tm_sec += 5;
+
+ fprintf(stderr, "\nTest will set RTC alarm to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new alarm in RTC */
+ retval = ioctl(fd, RTC_ALM_SET, &new);
+ if (retval == -1) {
+ perror("RTC_ALM_SET ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_ALM_READ, ¤t);
+ if (retval == -1) {
+ perror("RTC_ALM_READ ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "RTC alarm is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ if (new.tm_year != current.tm_year ||
+ new.tm_mon != current.tm_mon ||
+ new.tm_mday != current.tm_mday ||
+ new.tm_hour != current.tm_hour ||
+ new.tm_min != current.tm_min ||
+ new.tm_sec != current.tm_sec) {
+ fprintf(stderr, "\n\nSet alarm test failed\n");
+ close(fd);
+ return 1;
+ }
+
+ fprintf(stderr, "\nTest complete\n");
+ close(fd);
+ return 0;
+}
--
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related
* [rtc-linux] [PATCH 3/3] rtc: st-lpc: make it robust against y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-16 14:03 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org>
Make driver use u64 variables and functions to be sure that
it will support dates after year 2038.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
drivers/rtc/rtc-st-lpc.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index 74c0a33..82b0af1 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
do_div(lpt, rtc->clkrate);
- rtc_time_to_tm(lpt, tm);
+ rtc_time64_to_tm(lpt, tm);
return 0;
}
@@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
- unsigned long long lpt;
- unsigned long secs, flags;
- int ret;
+ unsigned long long lpt, secs;
+ unsigned long flags;
- ret = rtc_tm_to_time(tm, &secs);
- if (ret)
- return ret;
+ secs = rtc_tm_to_time64(tm);
lpt = (unsigned long long)secs * rtc->clkrate;
@@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
struct rtc_time now;
- unsigned long now_secs;
- unsigned long alarm_secs;
+ unsigned long long now_secs;
+ unsigned long long alarm_secs;
unsigned long long lpa;
st_rtc_read_time(dev, &now);
- rtc_tm_to_time(&now, &now_secs);
- rtc_tm_to_time(&t->time, &alarm_secs);
+ now_secs = rtc_tm_to_time64(&now);
+ alarm_secs = rtc_tm_to_time64(&t->time);
/* Invalid alarm time */
if (now_secs > alarm_secs)
--
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related
* [rtc-linux] Re: [PATCH 0/3] rtc: make st-lpc robust against y2038/2106 bug
From: Shuah Khan @ 2017-06-16 15:19 UTC (permalink / raw)
To: Benjamin Gaignard, john.stultz, tglx, sboyd, linux-kernel,
linux-kselftest, patrice.chotard, a.zummo, alexandre.belloni,
linux-arm-kernel, rtc-linux
Cc: linaro-kernel, Shuah Khan
In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org>
On 06/16/2017 08:03 AM, Benjamin Gaignard wrote:
> On 32bits platforms "struct timeval" or "time_t" are using u32 to code the
> date, this cause tools like "date" or "hwclock" failed even before setting
> the RTC device if the date is superior to year 2038 (or 2106).
>
> To avoid this problem I add two RTC tests files which directly use RTC ioctl
> to set and read RTC time and alarm values.
> rtctest_setdate allow to set any date/time given in the command line.
> rtctest-2038 perform a basic test by writing 1-1-2200 in RTC time and alarm
> and checking that the read back values are correct.
>
> Finally that had allowed me to test and fix rtc-st-lpc driver.
>
> Benjamin Gaignard (3):
> tools: timer: add rtctest_setdate
> tools: timer: add test to check y2038/2106 bug
> rtc: st-lpc: make it robust against y2038/2106 bug
>
> drivers/rtc/rtc-st-lpc.c | 19 ++--
> tools/testing/selftests/timers/Makefile | 4 +-
> tools/testing/selftests/timers/rtctest-2038.c | 135 +++++++++++++++++++++++
> tools/testing/selftests/timers/rtctest_setdate.c | 86 +++++++++++++++
> 4 files changed, 232 insertions(+), 12 deletions(-)
> create mode 100644 tools/testing/selftests/timers/rtctest-2038.c
> create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
>
Hi John/Thomas,
Please review them and let me know. Looks to me these will make good
additions to 4.13-rc1 kselftest content.
thanks,
-- Shuah
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [rtc-linux] Re: [PATCH 1/3] tools: timer: add rtctest_setdate
From: Alexandre Belloni @ 2017-06-16 15:34 UTC (permalink / raw)
To: Benjamin Gaignard
Cc: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, linux-arm-kernel, rtc-linux,
linaro-kernel
In-Reply-To: <1497621833-9942-2-git-send-email-benjamin.gaignard@linaro.org>
Hi,
On 16/06/2017 at 16:03:51 +0200, Benjamin Gaignard wrote:
> This tool allow to set directly the time and date to a RTC device.
>
> Unlike other tools isn't doens't use "strut timeval" or "time_t"
A small typo here-----^
> so it is safe for 32bits platforms when testing for y2038/2106 bug.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> ---
> tools/testing/selftests/timers/Makefile | 2 +-
> tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++++++++++
> 2 files changed, 87 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
>
> diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
> index 5fa1d7e9..54481f1 100644
> --- a/tools/testing/selftests/timers/Makefile
> +++ b/tools/testing/selftests/timers/Makefile
> @@ -9,7 +9,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
>
> TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
> skew_consistency clocksource-switch leap-a-day \
> - leapcrash set-tai set-2038 set-tz
> + leapcrash set-tai set-2038 set-tz rtctest_setdate
>
>
> include ../lib.mk
> diff --git a/tools/testing/selftests/timers/rtctest_setdate.c b/tools/testing/selftests/timers/rtctest_setdate.c
> new file mode 100644
> index 0000000..2cb7848
> --- /dev/null
> +++ b/tools/testing/selftests/timers/rtctest_setdate.c
> @@ -0,0 +1,86 @@
> +/* Real Time Clock Driver Test
> + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
> + *
> + * To build
> + * gcc rtctest_setdate.c -o rtctest_setdate
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <stdio.h>
> +#include <linux/rtc.h>
> +#include <sys/ioctl.h>
> +#include <sys/time.h>
> +#include <sys/types.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <errno.h>
> +
> +static const char default_time[] = "00:00:00";
> +
> +int main(int argc, char **argv)
> +{
> + int fd, retval;
> + struct rtc_time new, current;
> + const char *rtc, *date;
> + const char *time = default_time;
> +
> + switch (argc) {
> + case 4:
> + time = argv[3];
> + /* FALLTHROUGH */
> + case 3:
> + date = argv[2];
> + rtc = argv[1];
> + break;
> + default:
> + fprintf(stderr, "usage: rtctest_setdate <rtcdev> <DD-MM-YYYY> [HH:MM:SS]\n");
> + return 1;
> + }
> +
> + fd = open(rtc, O_RDONLY);
> + if (fd == -1) {
> + perror(rtc);
> + exit(errno);
> + }
> +
> + sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year);
> + new.tm_mon -= 1;
> + new.tm_year -= 1900;
> + sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec);
> +
> + fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
> + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
> + new.tm_hour, new.tm_min, new.tm_sec);
> +
> + /* Write the new date in RTC */
> + retval = ioctl(fd, RTC_SET_TIME, &new);
> + if (retval == -1) {
> + perror("RTC_SET_TIME ioctl");
> + close(fd);
> + exit(errno);
> + }
> +
> + /* Read back */
> + retval = ioctl(fd, RTC_RD_TIME, ¤t);
> + if (retval == -1) {
> + perror("RTC_RD_TIME ioctl");
> + exit(errno);
> + }
> +
> + fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
> + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
> + current.tm_hour, current.tm_min, current.tm_sec);
> +
> + close(fd);
> + return 0;
> +}
> --
> 1.9.1
>
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [PATCH 2/3] tools: timer: add test to check y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-16 14:03 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org>
The goal of this test is to check if a RTC device correctly support
dates after years 2038 or 2106.
It set a date (1-1-2200) on RTC and read it back to be sure that the
driver is working well.
The same thing is done on alarm.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
tools/testing/selftests/timers/Makefile | 4 +-
tools/testing/selftests/timers/rtctest-2038.c | 135 ++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/timers/rtctest-2038.c
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 54481f1..7791f79 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -9,7 +9,8 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
skew_consistency clocksource-switch leap-a-day \
- leapcrash set-tai set-2038 set-tz rtctest_setdate
+ leapcrash set-tai set-2038 set-tz rtctest_setdate \
+ rtctest-2038
include ../lib.mk
@@ -29,4 +30,5 @@ run_destructive_tests: run_tests
./set-tz
./set-tai
./set-2038
+ ./rtctest-2038
diff --git a/tools/testing/selftests/timers/rtctest-2038.c b/tools/testing/selftests/timers/rtctest-2038.c
new file mode 100644
index 0000000..213b7ee
--- /dev/null
+++ b/tools/testing/selftests/timers/rtctest-2038.c
@@ -0,0 +1,135 @@
+/* Real Time Clock Driver Test
+ * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
+ *
+ * To build
+ * gcc rtctest-2038.c -o rtctest-2038
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+static const char default_rtc[] = "/dev/rtc0";
+
+int main(int argc, char **argv)
+{
+ int fd, retval;
+ struct rtc_time new, current;
+ const char *rtc = default_rtc;
+
+ switch (argc) {
+ case 2:
+ rtc = argv[1];
+ /* FALLTHROUGH */
+ case 1:
+ break;
+ default:
+ fprintf(stderr, "usage: rtctest-2038 [rtcdev]\n");
+ return 1;
+ }
+
+ fprintf(stderr, "\nTest if RTC is robust for date after y2038/2106\n\n");
+
+ fd = open(rtc, O_RDONLY);
+ if (fd == -1) {
+ perror(rtc);
+ exit(errno);
+ }
+
+ new.tm_year = 300; /* 2200 - 1900 */
+ new.tm_mon = 0;
+ new.tm_mday = 1;
+ new.tm_hour = 0;
+ new.tm_min = 0;
+ new.tm_sec = 0;
+
+ fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new date in RTC */
+ retval = ioctl(fd, RTC_SET_TIME, &new);
+ if (retval == -1) {
+ perror("RTC_SET_TIME ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_RD_TIME, ¤t);
+ if (retval == -1) {
+ perror("RTC_RD_TIME ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ if (new.tm_year != current.tm_year ||
+ new.tm_mon != current.tm_mon ||
+ new.tm_mday != current.tm_mday ||
+ new.tm_hour != current.tm_hour ||
+ new.tm_min != current.tm_min ||
+ new.tm_sec != current.tm_sec) {
+ fprintf(stderr, "\n\nSet Time test failed\n");
+ close(fd);
+ return 1;
+ }
+
+ new.tm_sec += 5;
+
+ fprintf(stderr, "\nTest will set RTC alarm to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new alarm in RTC */
+ retval = ioctl(fd, RTC_ALM_SET, &new);
+ if (retval == -1) {
+ perror("RTC_ALM_SET ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_ALM_READ, ¤t);
+ if (retval == -1) {
+ perror("RTC_ALM_READ ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "RTC alarm is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ if (new.tm_year != current.tm_year ||
+ new.tm_mon != current.tm_mon ||
+ new.tm_mday != current.tm_mday ||
+ new.tm_hour != current.tm_hour ||
+ new.tm_min != current.tm_min ||
+ new.tm_sec != current.tm_sec) {
+ fprintf(stderr, "\n\nSet alarm test failed\n");
+ close(fd);
+ return 1;
+ }
+
+ fprintf(stderr, "\nTest complete\n");
+ close(fd);
+ return 0;
+}
--
1.9.1
^ permalink raw reply related
* [PATCH 3/3] rtc: st-lpc: make it robust against y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-16 14:03 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497621833-9942-1-git-send-email-benjamin.gaignard@linaro.org>
Make driver use u64 variables and functions to be sure that
it will support dates after year 2038.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
drivers/rtc/rtc-st-lpc.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index 74c0a33..82b0af1 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
do_div(lpt, rtc->clkrate);
- rtc_time_to_tm(lpt, tm);
+ rtc_time64_to_tm(lpt, tm);
return 0;
}
@@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
- unsigned long long lpt;
- unsigned long secs, flags;
- int ret;
+ unsigned long long lpt, secs;
+ unsigned long flags;
- ret = rtc_tm_to_time(tm, &secs);
- if (ret)
- return ret;
+ secs = rtc_tm_to_time64(tm);
lpt = (unsigned long long)secs * rtc->clkrate;
@@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
struct rtc_time now;
- unsigned long now_secs;
- unsigned long alarm_secs;
+ unsigned long long now_secs;
+ unsigned long long alarm_secs;
unsigned long long lpa;
st_rtc_read_time(dev, &now);
- rtc_tm_to_time(&now, &now_secs);
- rtc_tm_to_time(&t->time, &alarm_secs);
+ now_secs = rtc_tm_to_time64(&now);
+ alarm_secs = rtc_tm_to_time64(&t->time);
/* Invalid alarm time */
if (now_secs > alarm_secs)
--
1.9.1
^ permalink raw reply related
* Re: [PATCH 2/3] tools: timer: add test to check y2038/2106 bug
From: Alexandre Belloni @ 2017-06-16 15:52 UTC (permalink / raw)
To: Benjamin Gaignard
Cc: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, linux-arm-kernel, rtc-linux,
linaro-kernel
In-Reply-To: <1497621833-9942-3-git-send-email-benjamin.gaignard@linaro.org>
On 16/06/2017 at 16:03:52 +0200, Benjamin Gaignard wrote:
> The goal of this test is to check if a RTC device correctly support
> dates after years 2038 or 2106.
> It set a date (1-1-2200) on RTC and read it back to be sure that the
> driver is working well.
> The same thing is done on alarm.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> ---
> tools/testing/selftests/timers/Makefile | 4 +-
> tools/testing/selftests/timers/rtctest-2038.c | 135 ++++++++++++++++++++++++++
> 2 files changed, 138 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/timers/rtctest-2038.c
>
> diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
> index 54481f1..7791f79 100644
> --- a/tools/testing/selftests/timers/Makefile
> +++ b/tools/testing/selftests/timers/Makefile
> @@ -9,7 +9,8 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
>
> TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
> skew_consistency clocksource-switch leap-a-day \
> - leapcrash set-tai set-2038 set-tz rtctest_setdate
> + leapcrash set-tai set-2038 set-tz rtctest_setdate \
> + rtctest-2038
>
>
> include ../lib.mk
> @@ -29,4 +30,5 @@ run_destructive_tests: run_tests
> ./set-tz
> ./set-tai
> ./set-2038
> + ./rtctest-2038
>
> diff --git a/tools/testing/selftests/timers/rtctest-2038.c b/tools/testing/selftests/timers/rtctest-2038.c
> new file mode 100644
> index 0000000..213b7ee
> --- /dev/null
> +++ b/tools/testing/selftests/timers/rtctest-2038.c
> @@ -0,0 +1,135 @@
> +/* Real Time Clock Driver Test
> + * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
> + *
> + * To build
> + * gcc rtctest-2038.c -o rtctest-2038
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <stdio.h>
> +#include <linux/rtc.h>
> +#include <sys/ioctl.h>
> +#include <sys/time.h>
> +#include <sys/types.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <errno.h>
> +
> +static const char default_rtc[] = "/dev/rtc0";
> +
> +int main(int argc, char **argv)
> +{
> + int fd, retval;
> + struct rtc_time new, current;
> + const char *rtc = default_rtc;
> +
> + switch (argc) {
> + case 2:
> + rtc = argv[1];
> + /* FALLTHROUGH */
> + case 1:
> + break;
> + default:
> + fprintf(stderr, "usage: rtctest-2038 [rtcdev]\n");
> + return 1;
> + }
> +
> + fprintf(stderr, "\nTest if RTC is robust for date after y2038/2106\n\n");
> +
> + fd = open(rtc, O_RDONLY);
> + if (fd == -1) {
> + perror(rtc);
> + exit(errno);
> + }
> +
> + new.tm_year = 300; /* 2200 - 1900 */
It would be nice to have tests for 1900, 1901, 1969, 1970, 2037,
2038, 2099, 2100, 2105, 2106, 2261 and 2262.
Those are the various cutoff dates that exist and RTC supporting up to
2099 are certainly more common that RTC handling dates after 2200 else,
most RTC will fail the test.
> + new.tm_mon = 0;
> + new.tm_mday = 1;
> + new.tm_hour = 0;
> + new.tm_min = 0;
> + new.tm_sec = 0;
> +
> + fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
> + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
> + new.tm_hour, new.tm_min, new.tm_sec);
> +
> + /* Write the new date in RTC */
> + retval = ioctl(fd, RTC_SET_TIME, &new);
> + if (retval == -1) {
> + perror("RTC_SET_TIME ioctl");
> + close(fd);
> + exit(errno);
> + }
> +
> + /* Read back */
> + retval = ioctl(fd, RTC_RD_TIME, ¤t);
> + if (retval == -1) {
> + perror("RTC_RD_TIME ioctl");
> + exit(errno);
> + }
> +
> + fprintf(stderr, "RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
> + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
> + current.tm_hour, current.tm_min, current.tm_sec);
> +
> + if (new.tm_year != current.tm_year ||
> + new.tm_mon != current.tm_mon ||
> + new.tm_mday != current.tm_mday ||
> + new.tm_hour != current.tm_hour ||
> + new.tm_min != current.tm_min ||
> + new.tm_sec != current.tm_sec) {
This may fail because nothing guarantees that the RTC will reset its
sub seconds counter to 0 when setting the time so new.tm_sec could be
current.tm_sec + 1.
Maybe you could factorize the comparison in a function.
Finally, I won't insist on that but it could be interesting to integrate
it in rtctest.c, hidden behind a option warning that it is "destructive"
(i.e. the current time and date will be lost).
> + fprintf(stderr, "\n\nSet Time test failed\n");
> + close(fd);
> + return 1;
> + }
> +
> + new.tm_sec += 5;
> +
> + fprintf(stderr, "\nTest will set RTC alarm to %d-%d-%d, %02d:%02d:%02d.\n",
> + new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
> + new.tm_hour, new.tm_min, new.tm_sec);
> +
> + /* Write the new alarm in RTC */
> + retval = ioctl(fd, RTC_ALM_SET, &new);
> + if (retval == -1) {
> + perror("RTC_ALM_SET ioctl");
> + close(fd);
> + exit(errno);
> + }
> +
> + /* Read back */
> + retval = ioctl(fd, RTC_ALM_READ, ¤t);
> + if (retval == -1) {
> + perror("RTC_ALM_READ ioctl");
> + exit(errno);
> + }
> +
> + fprintf(stderr, "RTC alarm is %d-%d-%d, %02d:%02d:%02d.\n",
> + current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
> + current.tm_hour, current.tm_min, current.tm_sec);
> +
> + if (new.tm_year != current.tm_year ||
> + new.tm_mon != current.tm_mon ||
> + new.tm_mday != current.tm_mday ||
> + new.tm_hour != current.tm_hour ||
> + new.tm_min != current.tm_min ||
> + new.tm_sec != current.tm_sec) {
> + fprintf(stderr, "\n\nSet alarm test failed\n");
> + close(fd);
> + return 1;
> + }
> +
> + fprintf(stderr, "\nTest complete\n");
> + close(fd);
> + return 0;
> +}
> --
> 1.9.1
>
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply
* [PATCH 2/2] rtc: brcmstb-waketimer: Add Broadcom STB wake-timer
From: Florian Fainelli @ 2017-06-15 19:59 UTC (permalink / raw)
To: linux-kernel
Cc: Brian Norris, Markus Mayer, Florian Fainelli, Alessandro Zummo,
Alexandre Belloni, Rob Herring, Mark Rutland, Gregory Fong,
maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE,
open list:REAL TIME CLOCK (RTC) SUBSYSTEM,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
moderated list:BROADCOM BCM7XXX ARM ARCHITECTURE
In-Reply-To: <20170615195904.12653-1-f.fainelli@gmail.com>
From: Brian Norris <computersforpeace@gmail.com>
This adds support for the Broadcom STB wake-timer which is a timer in
the chip's 27Mhz clock domain that offers the ability to wake the system
(wake-up source) from suspend states (S2, S3, S5). It is supported using
the rtc framework allowing us to configure alarms for system wake-up.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/rtc/Kconfig | 11 ++
drivers/rtc/Makefile | 1 +
drivers/rtc/rtc-brcmstb-waketimer.c | 345 ++++++++++++++++++++++++++++++++++++
3 files changed, 357 insertions(+)
create mode 100644 drivers/rtc/rtc-brcmstb-waketimer.c
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8d3b95728326..8e1aa67fe533 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -197,6 +197,17 @@ config RTC_DRV_AC100
This driver can also be built as a module. If so, the module
will be called rtc-ac100.
+config RTC_DRV_BRCMSTB
+ tristate "Broadcom STB wake-timer"
+ depends on ARCH_BRCMSTB || BMIPS_GENERIC || COMPILE_TEST
+ default ARCH_BRCMSTB || BMIPS_GENERIC
+ help
+ If you say yes here you get support for the wake-timer found on
+ Broadcom STB SoCs (BCM7xxx).
+
+ This driver can also be built as a module. If so, the module will
+ be called rtc-brcmstb-waketimer.
+
config RTC_DRV_AS3722
tristate "ams AS3722 RTC driver"
depends on MFD_AS3722
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 13857d2fce09..df89cac1f9ae 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
obj-$(CONFIG_RTC_DRV_AU1XXX) += rtc-au1xxx.o
obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
+obj-$(CONFIG_RTC_DRV_BRCMSTB) += rtc-brcmstb-waketimer.o
obj-$(CONFIG_RTC_DRV_BQ32K) += rtc-bq32k.o
obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o
obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
diff --git a/drivers/rtc/rtc-brcmstb-waketimer.c b/drivers/rtc/rtc-brcmstb-waketimer.c
new file mode 100644
index 000000000000..c7f166e39f5e
--- /dev/null
+++ b/drivers/rtc/rtc-brcmstb-waketimer.c
@@ -0,0 +1,345 @@
+/*
+ * Copyright © 2014-2017 Broadcom
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irqreturn.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm.h>
+#include <linux/pm_wakeup.h>
+#include <linux/reboot.h>
+#include <linux/rtc.h>
+#include <linux/stat.h>
+#include <linux/suspend.h>
+
+struct brcmstb_waketmr {
+ struct rtc_device *rtc;
+ struct device *dev;
+ void __iomem *base;
+ int irq;
+ struct notifier_block reboot_notifier;
+ struct clk *clk;
+ u32 rate;
+};
+
+#define BRCMSTB_WKTMR_EVENT 0x00
+#define BRCMSTB_WKTMR_COUNTER 0x04
+#define BRCMSTB_WKTMR_ALARM 0x08
+#define BRCMSTB_WKTMR_PRESCALER 0x0C
+#define BRCMSTB_WKTMR_PRESCALER_VAL 0x10
+
+#define BRCMSTB_WKTMR_DEFAULT_FREQ 27000000
+
+static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer)
+{
+ writel_relaxed(1, timer->base + BRCMSTB_WKTMR_EVENT);
+ (void)readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT);
+}
+
+static void brcmstb_waketmr_set_alarm(struct brcmstb_waketmr *timer,
+ unsigned int secs)
+{
+ brcmstb_waketmr_clear_alarm(timer);
+
+ writel_relaxed(secs + 1, timer->base + BRCMSTB_WKTMR_ALARM);
+}
+
+static irqreturn_t brcmstb_waketmr_irq(int irq, void *data)
+{
+ struct brcmstb_waketmr *timer = data;
+
+ pm_wakeup_event(timer->dev, 0);
+
+ return IRQ_HANDLED;
+}
+
+struct wktmr_time {
+ u32 sec;
+ u32 pre;
+};
+
+static void wktmr_read(struct brcmstb_waketmr *timer,
+ struct wktmr_time *t)
+{
+ u32 tmp;
+
+ do {
+ t->sec = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER);
+ tmp = readl_relaxed(timer->base + BRCMSTB_WKTMR_PRESCALER_VAL);
+ } while (tmp >= timer->rate);
+
+ t->pre = timer->rate - tmp;
+}
+
+static int brcmstb_waketmr_prepare_suspend(struct brcmstb_waketmr *timer)
+{
+ struct device *dev = timer->dev;
+ int ret = 0;
+
+ if (device_may_wakeup(dev)) {
+ dev_dbg(dev, "enable wake IRQ\n");
+ ret = enable_irq_wake(timer->irq);
+ if (ret) {
+ dev_err(dev, "failed to enable wake-up interrupt\n");
+ return ret;
+ }
+ }
+
+ return ret;
+}
+
+/* If enabled as a wakeup-source, arm the timer when powering off */
+static int brcmstb_waketmr_reboot(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct brcmstb_waketmr *timer;
+
+ timer = container_of(nb, struct brcmstb_waketmr, reboot_notifier);
+
+ /* Set timer for cold boot */
+ if (action == SYS_POWER_OFF)
+ brcmstb_waketmr_prepare_suspend(timer);
+
+ return NOTIFY_DONE;
+}
+
+static int brcmstb_waketmr_gettime(struct device *dev,
+ struct rtc_time *tm)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+ struct wktmr_time now;
+
+ wktmr_read(timer, &now);
+
+ rtc_time_to_tm(now.sec, tm);
+
+ return 0;
+}
+
+static int brcmstb_waketmr_settime(struct device *dev,
+ struct rtc_time *tm)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+ unsigned long sec;
+ int ret;
+
+ ret = rtc_valid_tm(tm);
+ if (ret)
+ return ret;
+
+ rtc_tm_to_time(tm, &sec);
+
+ dev_dbg(dev, "%s: sec=%ld\n", __func__, sec);
+ writel_relaxed(sec, timer->base + BRCMSTB_WKTMR_COUNTER);
+
+ return 0;
+}
+
+static int brcmstb_waketmr_getalarm(struct device *dev,
+ struct rtc_wkalrm *alarm)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+ unsigned long sec;
+ u32 reg;
+
+ sec = readl_relaxed(timer->base + BRCMSTB_WKTMR_ALARM);
+ if (sec == 0) {
+ /* Alarm is disabled */
+ alarm->enabled = 0;
+ alarm->time.tm_mon = -1;
+ alarm->time.tm_mday = -1;
+ alarm->time.tm_year = -1;
+ alarm->time.tm_hour = -1;
+ alarm->time.tm_min = -1;
+ alarm->time.tm_sec = -1;
+ dev_dbg(dev, "%s: alarm is disabled\n", __func__);
+ } else {
+ /* Alarm is enabled */
+ alarm->enabled = 1;
+ rtc_time_to_tm(sec, &alarm->time);
+ dev_dbg(dev, "%s: alarm is enabled\n", __func__);
+ }
+
+ reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT);
+ alarm->pending = !!(reg & 1);
+ dev_dbg(dev, "%s: alarm pending=%d\n", __func__, alarm->pending);
+
+ return 0;
+}
+
+static int brcmstb_waketmr_setalarm(struct device *dev,
+ struct rtc_wkalrm *alarm)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+ unsigned long sec;
+
+ if (alarm->enabled)
+ rtc_tm_to_time(&alarm->time, &sec);
+ else
+ sec = 0;
+
+ dev_dbg(dev, "%s: timeout=%ld\n", __func__, sec);
+ brcmstb_waketmr_set_alarm(timer, sec);
+
+ return 0;
+}
+
+/*
+ * Does not do much but keep the RTC class happy. We always support
+ * alarms.
+ */
+static int brcmstb_waketmr_alarm_enable(struct device *dev,
+ unsigned int enabled)
+{
+ dev_dbg(dev, "%s: enabled=%d\n", __func__, enabled);
+ return 0;
+}
+
+static const struct rtc_class_ops brcmstb_waketmr_ops = {
+ .read_time = brcmstb_waketmr_gettime,
+ .set_time = brcmstb_waketmr_settime,
+ .read_alarm = brcmstb_waketmr_getalarm,
+ .set_alarm = brcmstb_waketmr_setalarm,
+ .alarm_irq_enable = brcmstb_waketmr_alarm_enable,
+};
+
+static int brcmstb_waketmr_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct brcmstb_waketmr *timer;
+ struct resource *res;
+ int ret;
+
+ timer = devm_kzalloc(dev, sizeof(*timer), GFP_KERNEL);
+ if (!timer)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, timer);
+ timer->dev = dev;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ timer->base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(timer->base))
+ return PTR_ERR(timer->base);
+
+ /*
+ * Set wakeup capability before requesting wakeup interrupt, so we can
+ * process boot-time "wakeups" (e.g., from S5 soft-off)
+ */
+ device_set_wakeup_capable(dev, true);
+ device_wakeup_enable(dev);
+
+ timer->irq = platform_get_irq(pdev, 0);
+ if (timer->irq < 0)
+ return -ENODEV;
+
+ timer->clk = devm_clk_get(dev, NULL);
+ if (!IS_ERR(timer->clk)) {
+ ret = clk_prepare_enable(timer->clk);
+ if (ret)
+ return ret;
+ timer->rate = clk_get_rate(timer->clk);
+ if (!timer->rate)
+ timer->rate = BRCMSTB_WKTMR_DEFAULT_FREQ;
+ } else {
+ timer->rate = BRCMSTB_WKTMR_DEFAULT_FREQ;
+ timer->clk = NULL;
+ }
+
+ ret = devm_request_irq(dev, timer->irq, brcmstb_waketmr_irq, 0,
+ "brcmstb-waketimer", timer);
+ if (ret < 0)
+ return ret;
+
+ timer->reboot_notifier.notifier_call = brcmstb_waketmr_reboot;
+ register_reboot_notifier(&timer->reboot_notifier);
+
+ timer->rtc = rtc_device_register("brcmstb-waketmr", dev,
+ &brcmstb_waketmr_ops, THIS_MODULE);
+ if (IS_ERR(timer->rtc)) {
+ dev_err(dev, "unable to register device\n");
+ unregister_reboot_notifier(&timer->reboot_notifier);
+ return PTR_ERR(timer->rtc);
+ }
+
+ dev_info(dev, "registered, with irq %d\n", timer->irq);
+
+ return ret;
+}
+
+static int brcmstb_waketmr_remove(struct platform_device *pdev)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(&pdev->dev);
+
+ unregister_reboot_notifier(&timer->reboot_notifier);
+ rtc_device_unregister(timer->rtc);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int brcmstb_waketmr_suspend(struct device *dev)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+
+ return brcmstb_waketmr_prepare_suspend(timer);
+}
+
+static int brcmstb_waketmr_resume(struct device *dev)
+{
+ struct brcmstb_waketmr *timer = dev_get_drvdata(dev);
+ int ret;
+
+ if (!device_may_wakeup(dev))
+ return 0;
+
+ ret = disable_irq_wake(timer->irq);
+
+ brcmstb_waketmr_clear_alarm(timer);
+
+ return ret;
+}
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(brcmstb_waketmr_pm_ops,
+ brcmstb_waketmr_suspend, brcmstb_waketmr_resume);
+
+static const struct of_device_id brcmstb_waketmr_of_match[] = {
+ { .compatible = "brcm,brcmstb-waketimer" },
+ { /* sentinel */ },
+};
+
+static struct platform_driver brcmstb_waketmr_driver = {
+ .probe = brcmstb_waketmr_probe,
+ .remove = brcmstb_waketmr_remove,
+ .driver = {
+ .name = "brcmstb-waketimer",
+ .pm = &brcmstb_waketmr_pm_ops,
+ .of_match_table = of_match_ptr(brcmstb_waketmr_of_match),
+ }
+};
+module_platform_driver(brcmstb_waketmr_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Brian Norris");
+MODULE_AUTHOR("Markus Mayer");
+MODULE_DESCRIPTION("Wake-up timer driver for STB chips");
--
2.9.3
^ permalink raw reply related
* [PATCH 1/6] rtc: s3c: Jump to central exit point on getting src clock error
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In other error paths in probe, centralized exit point was used so make
this consistent.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index d44fb34df8fe..c5aa7a35d07f 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -510,8 +510,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
else
dev_dbg(&pdev->dev,
"probe deferred due to missing rtc src clk\n");
- clk_disable_unprepare(info->rtc_clk);
- return ret;
+ goto err_src_clk;
}
clk_prepare_enable(info->rtc_src_clk);
}
@@ -575,6 +574,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
if (info->data->needs_src_clk)
clk_disable_unprepare(info->rtc_src_clk);
+err_src_clk:
clk_disable_unprepare(info->rtc_clk);
return ret;
--
2.9.3
^ permalink raw reply related
* [PATCH 2/6] rtc: s3c: Minor white-space cleanups
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In-Reply-To: <20170616192807.10347-1-krzk@kernel.org>
Minor cleanups to make the code easier to read. No functional changes.
1. Remove one space before labels as this is nowadays mostly preferred.
2. Fix indentation of arguments in function calls.
3. Split structure member declaration.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 47 +++++++++++++++++++++++------------------------
1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index c5aa7a35d07f..2b503dab7957 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -49,7 +49,8 @@ struct s3c_rtc {
spinlock_t pie_lock;
spinlock_t alarm_clk_lock;
- int ticnt_save, ticnt_en_save;
+ int ticnt_save;
+ int ticnt_en_save;
bool wake_en;
};
@@ -169,7 +170,7 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
s3c_rtc_enable_clk(info);
- retry_get_time:
+retry_get_time:
rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN);
rtc_tm->tm_hour = readb(info->base + S3C2410_RTCHOUR);
rtc_tm->tm_mday = readb(info->base + S3C2410_RTCDATE);
@@ -199,8 +200,8 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
rtc_tm->tm_year += 100;
dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
- 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
- rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
+ 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
+ rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
rtc_tm->tm_mon -= 1;
@@ -213,8 +214,8 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
int year = tm->tm_year - 100;
dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
- 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
/* we get around y2k by simply not supporting it */
@@ -259,9 +260,9 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n",
- alm_en,
- 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
- alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
+ alm_en,
+ 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
+ alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
/* decode the alarm enable field */
if (alm_en & S3C2410_RTCALM_SECEN)
@@ -295,9 +296,9 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
int year = tm->tm_year - 100;
dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
- alrm->enabled,
- 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ alrm->enabled,
+ 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
s3c_rtc_enable_clk(info);
@@ -378,8 +379,7 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info)
dev_info(info->dev, "rtc disabled, re-enabling\n");
tmp = readw(info->base + S3C2410_RTCCON);
- writew(tmp | S3C2410_RTCCON_RTCEN,
- info->base + S3C2410_RTCCON);
+ writew(tmp | S3C2410_RTCCON_RTCEN, info->base + S3C2410_RTCCON);
}
if (con & S3C2410_RTCCON_CNTSEL) {
@@ -387,7 +387,7 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info)
tmp = readw(info->base + S3C2410_RTCCON);
writew(tmp & ~S3C2410_RTCCON_CNTSEL,
- info->base + S3C2410_RTCCON);
+ info->base + S3C2410_RTCCON);
}
if (con & S3C2410_RTCCON_CLKRST) {
@@ -395,7 +395,7 @@ static void s3c24xx_rtc_enable(struct s3c_rtc *info)
tmp = readw(info->base + S3C2410_RTCCON);
writew(tmp & ~S3C2410_RTCCON_CLKRST,
- info->base + S3C2410_RTCCON);
+ info->base + S3C2410_RTCCON);
}
}
@@ -481,7 +481,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
}
dev_dbg(&pdev->dev, "s3c2410_rtc: tick irq %d, alarm irq %d\n",
- info->irq_tick, info->irq_alarm);
+ info->irq_tick, info->irq_alarm);
/* get the memory region */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -520,7 +520,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
info->data->enable(info);
dev_dbg(&pdev->dev, "s3c2410_rtc: RTCCON=%02x\n",
- readw(info->base + S3C2410_RTCCON));
+ readw(info->base + S3C2410_RTCCON));
device_init_wakeup(&pdev->dev, 1);
@@ -540,7 +540,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
/* register RTC and exit */
info->rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
- THIS_MODULE);
+ THIS_MODULE);
if (IS_ERR(info->rtc)) {
dev_err(&pdev->dev, "cannot attach rtc\n");
ret = PTR_ERR(info->rtc);
@@ -548,14 +548,14 @@ static int s3c_rtc_probe(struct platform_device *pdev)
}
ret = devm_request_irq(&pdev->dev, info->irq_alarm, s3c_rtc_alarmirq,
- 0, "s3c2410-rtc alarm", info);
+ 0, "s3c2410-rtc alarm", info);
if (ret) {
dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_alarm, ret);
goto err_nortc;
}
ret = devm_request_irq(&pdev->dev, info->irq_tick, s3c_rtc_tickirq,
- 0, "s3c2410-rtc tick", info);
+ 0, "s3c2410-rtc tick", info);
if (ret) {
dev_err(&pdev->dev, "IRQ%d error %d\n", info->irq_tick, ret);
goto err_nortc;
@@ -568,7 +568,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
return 0;
- err_nortc:
+err_nortc:
if (info->data->disable)
info->data->disable(info);
@@ -747,8 +747,7 @@ static void s3c6410_rtc_restore_tick_cnt(struct s3c_rtc *info)
writel(info->ticnt_save, info->base + S3C2410_TICNT);
if (info->ticnt_en_save) {
con = readw(info->base + S3C2410_RTCCON);
- writew(con | info->ticnt_en_save,
- info->base + S3C2410_RTCCON);
+ writew(con | info->ticnt_en_save, info->base + S3C2410_RTCCON);
}
}
--
2.9.3
^ permalink raw reply related
* [PATCH 4/6] rtc: s3c: Do not remove const from rodata memory
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In-Reply-To: <20170616192807.10347-1-krzk@kernel.org>
All instances of struct s3c_rtc_data are in fact static const thus
put in rodata so we should not drop the const while getting the pointer
to them.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index bfc8660ff1e7..c666b95fb8d7 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -41,7 +41,7 @@ struct s3c_rtc {
struct clk *rtc_src_clk;
bool clk_disabled;
- struct s3c_rtc_data *data;
+ const struct s3c_rtc_data *data;
int irq_alarm;
int irq_tick;
@@ -437,12 +437,12 @@ static int s3c_rtc_remove(struct platform_device *pdev)
static const struct of_device_id s3c_rtc_dt_match[];
-static struct s3c_rtc_data *s3c_rtc_get_data(struct platform_device *pdev)
+static const struct s3c_rtc_data *s3c_rtc_get_data(struct platform_device *pdev)
{
const struct of_device_id *match;
match = of_match_node(s3c_rtc_dt_match, pdev->dev.of_node);
- return (struct s3c_rtc_data *)match->data;
+ return match->data;
}
static int s3c_rtc_probe(struct platform_device *pdev)
--
2.9.3
^ permalink raw reply related
* [PATCH 5/6] rtc: s3c: Handle clock prepare failures in probe
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In-Reply-To: <20170616192807.10347-1-krzk@kernel.org>
clk_prepare_enable() can fail so handle such case.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index c666b95fb8d7..0cb2f27a30b4 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -498,7 +498,9 @@ static int s3c_rtc_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "probe deferred due to missing rtc clk\n");
return ret;
}
- clk_prepare_enable(info->rtc_clk);
+ ret = clk_prepare_enable(info->rtc_clk);
+ if (ret)
+ return ret;
if (info->data->needs_src_clk) {
info->rtc_src_clk = devm_clk_get(&pdev->dev, "rtc_src");
@@ -512,7 +514,9 @@ static int s3c_rtc_probe(struct platform_device *pdev)
"probe deferred due to missing rtc src clk\n");
goto err_src_clk;
}
- clk_prepare_enable(info->rtc_src_clk);
+ ret = clk_prepare_enable(info->rtc_src_clk);
+ if (ret)
+ goto err_src_clk;
}
/* check to see if everything is setup correctly */
--
2.9.3
^ permalink raw reply related
* [PATCH 6/6] rtc: s3c: Handle clock enable failures
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In-Reply-To: <20170616192807.10347-1-krzk@kernel.org>
clk_enable() can fail so handle such case.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 72 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 57 insertions(+), 15 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 0cb2f27a30b4..a8992c227f61 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -68,18 +68,32 @@ struct s3c_rtc_data {
void (*disable) (struct s3c_rtc *info);
};
-static void s3c_rtc_enable_clk(struct s3c_rtc *info)
+static int s3c_rtc_enable_clk(struct s3c_rtc *info)
{
unsigned long irq_flags;
+ int ret = 0;
spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
+
if (info->clk_disabled) {
- clk_enable(info->rtc_clk);
- if (info->data->needs_src_clk)
- clk_enable(info->rtc_src_clk);
+ ret = clk_enable(info->rtc_clk);
+ if (ret)
+ goto out;
+
+ if (info->data->needs_src_clk) {
+ ret = clk_enable(info->rtc_src_clk);
+ if (ret) {
+ clk_disable(info->rtc_clk);
+ goto out;
+ }
+ }
info->clk_disabled = false;
}
+
+out:
spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
+
+ return ret;
}
static void s3c_rtc_disable_clk(struct s3c_rtc *info)
@@ -122,10 +136,13 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
unsigned int tmp;
+ int ret;
dev_dbg(info->dev, "%s: aie=%d\n", __func__, enabled);
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
tmp = readb(info->base + S3C2410_RTCALM) & ~S3C2410_RTCALM_ALMEN;
@@ -136,10 +153,13 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
s3c_rtc_disable_clk(info);
- if (enabled)
- s3c_rtc_enable_clk(info);
- else
+ if (enabled) {
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
+ } else {
s3c_rtc_disable_clk(info);
+ }
return 0;
}
@@ -147,10 +167,14 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled)
/* Set RTC frequency */
static int s3c_rtc_setfreq(struct s3c_rtc *info, int freq)
{
+ int ret;
+
if (!is_power_of_2(freq))
return -EINVAL;
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
spin_lock_irq(&info->pie_lock);
if (info->data->set_freq)
@@ -167,8 +191,11 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
unsigned int have_retried = 0;
+ int ret;
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
retry_get_time:
rtc_tm->tm_min = readb(info->base + S3C2410_RTCMIN);
@@ -212,6 +239,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
int year = tm->tm_year - 100;
+ int ret;
dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n",
1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
@@ -224,7 +252,9 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
return -EINVAL;
}
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
writeb(bin2bcd(tm->tm_sec), info->base + S3C2410_RTCSEC);
writeb(bin2bcd(tm->tm_min), info->base + S3C2410_RTCMIN);
@@ -243,8 +273,11 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
struct s3c_rtc *info = dev_get_drvdata(dev);
struct rtc_time *alm_tm = &alrm->time;
unsigned int alm_en;
+ int ret;
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
alm_tm->tm_sec = readb(info->base + S3C2410_ALMSEC);
alm_tm->tm_min = readb(info->base + S3C2410_ALMMIN);
@@ -293,6 +326,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 ret;
int year = tm->tm_year - 100;
dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n",
@@ -300,7 +334,9 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
alrm_en = readb(info->base + S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;
writeb(0x00, info->base + S3C2410_RTCALM);
@@ -349,8 +385,11 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
static int s3c_rtc_proc(struct device *dev, struct seq_file *seq)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
+ int ret;
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
if (info->data->enable_tick)
info->data->enable_tick(info, seq);
@@ -589,8 +628,11 @@ static int s3c_rtc_probe(struct platform_device *pdev)
static int s3c_rtc_suspend(struct device *dev)
{
struct s3c_rtc *info = dev_get_drvdata(dev);
+ int ret;
- s3c_rtc_enable_clk(info);
+ ret = s3c_rtc_enable_clk(info);
+ if (ret)
+ return ret;
/* save TICNT for anyone using periodic interrupts */
if (info->data->save_tick_cnt)
--
2.9.3
^ permalink raw reply related
* [PATCH 3/6] rtc: s3c: Drop unneeded cast to void pointer
From: Krzysztof Kozlowski @ 2017-06-16 19:28 UTC (permalink / raw)
To: Alessandro Zummo, Alexandre Belloni, linux-rtc, linux-kernel
Cc: Krzysztof Kozlowski
In-Reply-To: <20170616192807.10347-1-krzk@kernel.org>
There is no need for casting to void pointer for of_device_id data.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
drivers/rtc/rtc-s3c.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 2b503dab7957..bfc8660ff1e7 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -801,19 +801,19 @@ static struct s3c_rtc_data const s3c6410_rtc_data = {
static const struct of_device_id s3c_rtc_dt_match[] = {
{
.compatible = "samsung,s3c2410-rtc",
- .data = (void *)&s3c2410_rtc_data,
+ .data = &s3c2410_rtc_data,
}, {
.compatible = "samsung,s3c2416-rtc",
- .data = (void *)&s3c2416_rtc_data,
+ .data = &s3c2416_rtc_data,
}, {
.compatible = "samsung,s3c2443-rtc",
- .data = (void *)&s3c2443_rtc_data,
+ .data = &s3c2443_rtc_data,
}, {
.compatible = "samsung,s3c6410-rtc",
- .data = (void *)&s3c6410_rtc_data,
+ .data = &s3c6410_rtc_data,
}, {
.compatible = "samsung,exynos3250-rtc",
- .data = (void *)&s3c6410_rtc_data,
+ .data = &s3c6410_rtc_data,
},
{ /* sentinel */ },
};
--
2.9.3
^ permalink raw reply related
* [rtc-linux] Re: [PATCH] rtc: ds1307: Add support for Epson RX8130CE
From: Marek Vasut @ 2017-06-18 20:52 UTC (permalink / raw)
To: Alexandre Belloni
Cc: rtc-linux, Arnd Bergmann, Felipe Balbi, Nishanth Menon,
Tony Lindgren
In-Reply-To: <20170531014515.4a7yebud7qssyjok@piout.net>
On 05/31/2017 03:45 AM, Alexandre Belloni wrote:
> Hi Marek,
Hi,
> On 04/05/2017 at 12:33:46 +0200, Marek Vasut wrote:
>> Add support for yet another RTC chip, Epson RX8130CE. This time around,
>> the chip has slightly permutated registers and also the register starts
>> at 0x10 instead of 0x0 .
>>
>
> Do you mind rebasing on top of rtc-next or linux-next because this
> driver now uses regmap for the register accesses.
Sure ... I don't have the hardware anymore, so it'll be compile-tested
only, but the conversion seems trivial enough.
--
Best regards,
Marek Vasut
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [PATCH V2] rtc: ds1307: Add support for Epson RX8130CE
From: Marek Vasut @ 2017-06-18 20:55 UTC (permalink / raw)
To: rtc-linux
Cc: Marek Vasut, Alexandre Belloni, Arnd Bergmann, Felipe Balbi,
Nishanth Menon, Tony Lindgren
Add support for yet another RTC chip, Epson RX8130CE. This time around,
the chip has slightly permutated registers and also the register starts
at 0x10 instead of 0x0 .
So far, we only support the RTC and NVRAM parts of the chip, Alarm and
Timer is not supported.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Tony Lindgren <tony@atomide.com>
---
V2: Convert to regmap
---
drivers/rtc/rtc-ds1307.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 175 insertions(+)
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 16ace2fb0c0a..3cbb7636b405 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -44,6 +44,7 @@ enum ds_type {
m41t00,
mcp794xx,
rx_8025,
+ rx_8130,
last_ds_type /* always last */
/* rs5c372 too? different address... */
};
@@ -169,6 +170,12 @@ static struct chip_desc chips[last_ds_type] = {
[ds_3231] = {
.alarm = 1,
},
+ [rx_8130] = {
+ .alarm = 1,
+ /* this is battery backed SRAM */
+ .nvram_offset = 0x20,
+ .nvram_size = 4, /* 32bit (4 word x 8 bit) */
+ },
[mcp794xx] = {
.alarm = 1,
/* this is battery backed SRAM */
@@ -192,6 +199,7 @@ static const struct i2c_device_id ds1307_id[] = {
{ "pt7c4338", ds_1307 },
{ "rx8025", rx_8025 },
{ "isl12057", ds_1337 },
+ { "rx8130", rx_8130 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ds1307_id);
@@ -587,6 +595,165 @@ static const struct rtc_class_ops ds13xx_rtc_ops = {
/*----------------------------------------------------------------------*/
/*
+ * Alarm support for rx8130 devices.
+ */
+
+#define RX8130_REG_ALARM_MIN 0x07
+#define RX8130_REG_ALARM_HOUR 0x08
+#define RX8130_REG_ALARM_WEEK_OR_DAY 0x09
+#define RX8130_REG_EXTENSION 0x0c
+#define RX8130_REG_EXTENSION_WADA (1 << 3)
+#define RX8130_REG_FLAG 0x0d
+#define RX8130_REG_FLAG_AF (1 << 3)
+#define RX8130_REG_CONTROL0 0x0e
+#define RX8130_REG_CONTROL0_AIE (1 << 3)
+
+static irqreturn_t rx8130_irq(int irq, void *dev_id)
+{
+ struct ds1307 *ds1307 = dev_id;
+ struct mutex *lock = &ds1307->rtc->ops_lock;
+ u8 ctl[3];
+ int ret;
+
+ mutex_lock(lock);
+
+ /* Read control registers. */
+ ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+ if (ret < 0)
+ goto out;
+ if (!(ctl[1] & RX8130_REG_FLAG_AF))
+ goto out;
+ ctl[1] &= ~RX8130_REG_FLAG_AF;
+ ctl[2] &= ~RX8130_REG_CONTROL0_AIE;
+
+ ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+ if (ret < 0)
+ goto out;
+
+ rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
+
+out:
+ mutex_unlock(lock);
+
+ return IRQ_HANDLED;
+}
+
+static int rx8130_read_alarm(struct device *dev, struct rtc_wkalrm *t)
+{
+ struct ds1307 *ds1307 = dev_get_drvdata(dev);
+ u8 ald[3], ctl[3];
+ int ret;
+
+ if (!test_bit(HAS_ALARM, &ds1307->flags))
+ return -EINVAL;
+
+ /* Read alarm registers. */
+ ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, 3);
+ if (ret < 0)
+ return ret;
+
+ /* Read control registers. */
+ ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+ if (ret < 0)
+ return ret;
+
+ t->enabled = !!(ctl[2] & RX8130_REG_CONTROL0_AIE);
+ t->pending = !!(ctl[1] & RX8130_REG_FLAG_AF);
+
+ /* Report alarm 0 time assuming 24-hour and day-of-month modes. */
+ t->time.tm_sec = -1;
+ t->time.tm_min = bcd2bin(ald[0] & 0x7f);
+ t->time.tm_hour = bcd2bin(ald[1] & 0x7f);
+ t->time.tm_wday = -1;
+ t->time.tm_mday = bcd2bin(ald[2] & 0x7f);
+ t->time.tm_mon = -1;
+ t->time.tm_year = -1;
+ t->time.tm_yday = -1;
+ t->time.tm_isdst = -1;
+
+ dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d enabled=%d\n",
+ __func__, t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
+ t->time.tm_wday, t->time.tm_mday, t->time.tm_mon, t->enabled);
+
+ return 0;
+}
+
+static int rx8130_set_alarm(struct device *dev, struct rtc_wkalrm *t)
+{
+ struct ds1307 *ds1307 = dev_get_drvdata(dev);
+ u8 ald[3], ctl[3];
+ int ret;
+
+ if (!test_bit(HAS_ALARM, &ds1307->flags))
+ return -EINVAL;
+
+ dev_dbg(dev, "%s, sec=%d min=%d hour=%d wday=%d mday=%d mon=%d "
+ "enabled=%d pending=%d\n", __func__,
+ t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
+ t->time.tm_wday, t->time.tm_mday, t->time.tm_mon,
+ t->enabled, t->pending);
+
+ /* Read control registers. */
+ ret = regmap_bulk_read(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+ if (ret < 0)
+ return ret;
+
+ ctl[0] &= ~RX8130_REG_EXTENSION_WADA;
+ ctl[1] |= RX8130_REG_FLAG_AF;
+ ctl[2] &= ~RX8130_REG_CONTROL0_AIE;
+
+ ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+ if (ret < 0)
+ return ret;
+
+ /* Hardware alarm precision is 1 minute! */
+ ald[0] = bin2bcd(t->time.tm_min);
+ ald[1] = bin2bcd(t->time.tm_hour);
+ ald[2] = bin2bcd(t->time.tm_mday);
+
+ ret = regmap_bulk_write(ds1307->regmap, RX8130_REG_ALARM_MIN, ald, 3);
+ if (ret < 0)
+ return ret;
+
+ if (!t->enabled)
+ return 0;
+
+ ctl[2] |= RX8130_REG_CONTROL0_AIE;
+
+ return regmap_bulk_write(ds1307->regmap, RX8130_REG_EXTENSION, ctl, 3);
+}
+
+static int rx8130_alarm_irq_enable(struct device *dev, unsigned int enabled)
+{
+ struct ds1307 *ds1307 = dev_get_drvdata(dev);
+ int ret, reg;
+
+ if (!test_bit(HAS_ALARM, &ds1307->flags))
+ return -EINVAL;
+
+ ret = regmap_read(ds1307->regmap, RX8130_REG_CONTROL0, ®);
+ if (ret < 0)
+ return ret;
+
+ if (enabled)
+ reg |= RX8130_REG_CONTROL0_AIE;
+ else
+ reg &= ~RX8130_REG_CONTROL0_AIE;
+
+ return regmap_write(ds1307->regmap, RX8130_REG_CONTROL0, reg);
+}
+
+static const struct rtc_class_ops rx8130_rtc_ops = {
+ .read_time = ds1307_get_time,
+ .set_time = ds1307_set_time,
+ .read_alarm = rx8130_read_alarm,
+ .set_alarm = rx8130_set_alarm,
+ .alarm_irq_enable = rx8130_alarm_irq_enable,
+};
+
+/*----------------------------------------------------------------------*/
+
+/*
* Alarm support for mcp794xx devices.
*/
@@ -1402,6 +1569,14 @@ static int ds1307_probe(struct i2c_client *client,
DS1307_REG_HOUR << 4 | 0x08, hour);
}
break;
+ case rx_8130:
+ ds1307->offset = 0x10; /* Seconds starts at 0x10 */
+ rtc_ops = &rx8130_rtc_ops;
+ if (chip->alarm && ds1307->irq > 0) {
+ irq_handler = rx8130_irq;
+ want_irq = true;
+ }
+ break;
case ds_1388:
ds1307->offset = 1; /* Seconds starts at 1 */
break;
--
2.11.0
^ permalink raw reply related
* [rtc-linux] Re: [PATCH 3/3] rtc: st-lpc: make it robust against y2038/2106 bug
From: Patrice CHOTARD @ 2017-06-19 7:57 UTC (permalink / raw)
To: Benjamin Gaignard, john.stultz@linaro.org, tglx@linutronix.de,
sboyd@codeaurora.org, shuah@kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
a.zummo@towertech.it, alexandre.belloni@free-electrons.com,
linux-arm-kernel@lists.infradead.org, rtc-linux@googlegroups.com
Cc: linaro-kernel@lists.linaro.org
In-Reply-To: <1497621833-9942-4-git-send-email-benjamin.gaignard@linaro.org>
Hi Benjamin
On 06/16/2017 04:03 PM, Benjamin Gaignard wrote:
> Make driver use u64 variables and functions to be sure that
> it will support dates after year 2038.
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
> ---
> drivers/rtc/rtc-st-lpc.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
> index 74c0a33..82b0af1 100644
> --- a/drivers/rtc/rtc-st-lpc.c
> +++ b/drivers/rtc/rtc-st-lpc.c
> @@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
>
> lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
> do_div(lpt, rtc->clkrate);
> - rtc_time_to_tm(lpt, tm);
> + rtc_time64_to_tm(lpt, tm);
>
> return 0;
> }
> @@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
> static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
> {
> struct st_rtc *rtc = dev_get_drvdata(dev);
> - unsigned long long lpt;
> - unsigned long secs, flags;
> - int ret;
> + unsigned long long lpt, secs;
> + unsigned long flags;
>
> - ret = rtc_tm_to_time(tm, &secs);
> - if (ret)
> - return ret;
> + secs = rtc_tm_to_time64(tm);
>
> lpt = (unsigned long long)secs * rtc->clkrate;
>
> @@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
> {
> struct st_rtc *rtc = dev_get_drvdata(dev);
> struct rtc_time now;
> - unsigned long now_secs;
> - unsigned long alarm_secs;
> + unsigned long long now_secs;
> + unsigned long long alarm_secs;
> unsigned long long lpa;
>
> st_rtc_read_time(dev, &now);
> - rtc_tm_to_time(&now, &now_secs);
> - rtc_tm_to_time(&t->time, &alarm_secs);
> + now_secs = rtc_tm_to_time64(&now);
> + alarm_secs = rtc_tm_to_time64(&t->time);
>
> /* Invalid alarm time */
> if (now_secs > alarm_secs)
>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
Thanks
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [PATCH v2 2/3] tool: timer: rtctest add check for problematic dates
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org>
Some dates could be problematic because they reach the limits of
RTC hardware capabilities.
This patch add various of them but since it will change RTC date
it will be activated only when 'd' args is set.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
tools/testing/selftests/timers/rtctest.c | 121 ++++++++++++++++++++++++++++++-
1 file changed, 117 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/timers/rtctest.c b/tools/testing/selftests/timers/rtctest.c
index 4230d30..715a016 100644
--- a/tools/testing/selftests/timers/rtctest.c
+++ b/tools/testing/selftests/timers/rtctest.c
@@ -21,6 +21,9 @@
#include <stdlib.h>
#include <errno.h>
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
/*
* This expects the new RTC class driver framework, working with
@@ -29,23 +32,77 @@
*/
static const char default_rtc[] = "/dev/rtc0";
+static struct rtc_time cutoff_dates[] = {
+ {
+ .tm_year = 70, /* 1970 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 137, /* 2037 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 138, /* 2038 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 199, /* 2099 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 200, /* 2100 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 205, /* 2105 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 206, /* 2106 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 361, /* 2261 -1900 */
+ .tm_mday = 1,
+ },
+ {
+ .tm_year = 362, /* 2262 -1900 */
+ .tm_mday = 1,
+ },
+};
+
+static int compare_dates(struct rtc_time *a, struct rtc_time *b)
+{
+ if (a->tm_year != b->tm_year ||
+ a->tm_mon != b->tm_mon ||
+ a->tm_mday != b->tm_mday ||
+ a->tm_hour != b->tm_hour ||
+ a->tm_min != b->tm_min ||
+ ((b->tm_sec - a->tm_sec) > 1))
+ return 1;
+
+ return 0;
+}
int main(int argc, char **argv)
{
- int i, fd, retval, irqcount = 0;
+ int i, fd, retval, irqcount = 0, dangerous = 0;
unsigned long tmp, data;
struct rtc_time rtc_tm;
const char *rtc = default_rtc;
struct timeval start, end, diff;
switch (argc) {
+ case 3:
+ if (*argv[2] == 'd')
+ dangerous = 1;
case 2:
rtc = argv[1];
/* FALLTHROUGH */
case 1:
break;
default:
- fprintf(stderr, "usage: rtctest [rtcdev]\n");
+ fprintf(stderr, "usage: rtctest [rtcdev] [d]\n");
return 1;
}
@@ -202,7 +259,7 @@ int main(int argc, char **argv)
/* not all RTCs support periodic IRQs */
if (errno == EINVAL) {
fprintf(stderr, "\nNo periodic IRQ support\n");
- goto done;
+ goto test_DATE;
}
perror("RTC_IRQP_READ ioctl");
exit(errno);
@@ -221,7 +278,7 @@ int main(int argc, char **argv)
if (errno == EINVAL) {
fprintf(stderr,
"\n...Periodic IRQ rate is fixed\n");
- goto done;
+ goto test_DATE;
}
perror("RTC_IRQP_SET ioctl");
exit(errno);
@@ -269,6 +326,62 @@ int main(int argc, char **argv)
}
}
+test_DATE:
+ if (!dangerous)
+ goto done;
+
+ fprintf(stderr, "\nTesting problematic dates\n");
+
+ for (i = 0; i < ARRAY_SIZE(cutoff_dates); i++) {
+ struct rtc_time current;
+
+ /* Write the new date in RTC */
+ retval = ioctl(fd, RTC_SET_TIME, &cutoff_dates[i]);
+ if (retval == -1) {
+ perror("RTC_SET_TIME ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_RD_TIME, ¤t);
+ if (retval == -1) {
+ perror("RTC_RD_TIME ioctl");
+ exit(errno);
+ }
+
+ if(compare_dates(&cutoff_dates[i], ¤t)) {
+ fprintf(stderr,"Setting date %d failed\n",
+ cutoff_dates[i].tm_year + 1900);
+ goto done;
+ }
+
+ cutoff_dates[i].tm_sec += 5;
+
+ /* Write the new alarm in RTC */
+ retval = ioctl(fd, RTC_ALM_SET, &cutoff_dates[i]);
+ if (retval == -1) {
+ perror("RTC_ALM_SET ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_ALM_READ, ¤t);
+ if (retval == -1) {
+ perror("RTC_ALM_READ ioctl");
+ exit(errno);
+ }
+
+ if(compare_dates(&cutoff_dates[i], ¤t)) {
+ fprintf(stderr,"Setting alarm %d failed\n",
+ cutoff_dates[i].tm_year + 1900);
+ goto done;
+ }
+
+ fprintf(stderr, "Setting year %d is OK \n",
+ cutoff_dates[i].tm_year + 1900);
+ }
done:
fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n");
--
1.9.1
^ permalink raw reply related
* [PATCH v2 3/3] rtc: st-lpc: make it robust against y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org>
Make driver use u64 variables and functions to be sure that
it will support dates after year 2038.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
---
drivers/rtc/rtc-st-lpc.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index 74c0a33..82b0af1 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -99,7 +99,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
do_div(lpt, rtc->clkrate);
- rtc_time_to_tm(lpt, tm);
+ rtc_time64_to_tm(lpt, tm);
return 0;
}
@@ -107,13 +107,10 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
- unsigned long long lpt;
- unsigned long secs, flags;
- int ret;
+ unsigned long long lpt, secs;
+ unsigned long flags;
- ret = rtc_tm_to_time(tm, &secs);
- if (ret)
- return ret;
+ secs = rtc_tm_to_time64(tm);
lpt = (unsigned long long)secs * rtc->clkrate;
@@ -161,13 +158,13 @@ static int st_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
struct rtc_time now;
- unsigned long now_secs;
- unsigned long alarm_secs;
+ unsigned long long now_secs;
+ unsigned long long alarm_secs;
unsigned long long lpa;
st_rtc_read_time(dev, &now);
- rtc_tm_to_time(&now, &now_secs);
- rtc_tm_to_time(&t->time, &alarm_secs);
+ now_secs = rtc_tm_to_time64(&now);
+ alarm_secs = rtc_tm_to_time64(&t->time);
/* Invalid alarm time */
if (now_secs > alarm_secs)
--
1.9.1
^ permalink raw reply related
* [rtc-linux] [PATCH v2 0/3] rtc: make st-lpc robust against y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
On 32bits platforms "struct timeval" or "time_t" are using u32 to code the
date, this cause tools like "date" or "hwclock" failed even before setting
the RTC device if the date is superior to year 2038 (or 2106).
To avoid this problem I add one RTC test file which directly use RTC ioctl
to set and read RTC time and alarm values.
rtctest_setdate allow to set any date/time given in the command line.
On this version 2 I add check of problematics years in rtctest like suggest
by Alexandre.
Finally that had allowed me to test and fix rtc-st-lpc driver.
Benjamin Gaignard (3):
tools: timer: add rtctest_setdate
tool: timer: rtctest add check for problematic dates
rtc: st-lpc: make it robust against y2038/2106 bug
drivers/rtc/rtc-st-lpc.c | 19 ++--
tools/testing/selftests/timers/Makefile | 2 +-
tools/testing/selftests/timers/rtctest.c | 121 ++++++++++++++++++++++-
tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++
4 files changed, 212 insertions(+), 16 deletions(-)
create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
--
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [rtc-linux] [PATCH v2 1/3] tools: timer: add rtctest_setdate
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org>
This tool allow to set directly the time and date to a RTC device.
Unlike other tools isn't doens't use "struct timeval" or "time_t"
so it is safe for 32bits platforms when testing for y2038/2106 bug.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
tools/testing/selftests/timers/Makefile | 2 +-
tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++++++++++
2 files changed, 87 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 5fa1d7e9..54481f1 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -9,7 +9,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
skew_consistency clocksource-switch leap-a-day \
- leapcrash set-tai set-2038 set-tz
+ leapcrash set-tai set-2038 set-tz rtctest_setdate
include ../lib.mk
diff --git a/tools/testing/selftests/timers/rtctest_setdate.c b/tools/testing/selftests/timers/rtctest_setdate.c
new file mode 100644
index 0000000..2cb7848
--- /dev/null
+++ b/tools/testing/selftests/timers/rtctest_setdate.c
@@ -0,0 +1,86 @@
+/* Real Time Clock Driver Test
+ * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
+ *
+ * To build
+ * gcc rtctest_setdate.c -o rtctest_setdate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+static const char default_time[] = "00:00:00";
+
+int main(int argc, char **argv)
+{
+ int fd, retval;
+ struct rtc_time new, current;
+ const char *rtc, *date;
+ const char *time = default_time;
+
+ switch (argc) {
+ case 4:
+ time = argv[3];
+ /* FALLTHROUGH */
+ case 3:
+ date = argv[2];
+ rtc = argv[1];
+ break;
+ default:
+ fprintf(stderr, "usage: rtctest_setdate <rtcdev> <DD-MM-YYYY> [HH:MM:SS]\n");
+ return 1;
+ }
+
+ fd = open(rtc, O_RDONLY);
+ if (fd == -1) {
+ perror(rtc);
+ exit(errno);
+ }
+
+ sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year);
+ new.tm_mon -= 1;
+ new.tm_year -= 1900;
+ sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec);
+
+ fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new date in RTC */
+ retval = ioctl(fd, RTC_SET_TIME, &new);
+ if (retval == -1) {
+ perror("RTC_SET_TIME ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_RD_TIME, ¤t);
+ if (retval == -1) {
+ perror("RTC_RD_TIME ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ close(fd);
+ return 0;
+}
--
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related
* [PATCH v2 0/3] rtc: make st-lpc robust against y2038/2106 bug
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
On 32bits platforms "struct timeval" or "time_t" are using u32 to code the
date, this cause tools like "date" or "hwclock" failed even before setting
the RTC device if the date is superior to year 2038 (or 2106).
To avoid this problem I add one RTC test file which directly use RTC ioctl
to set and read RTC time and alarm values.
rtctest_setdate allow to set any date/time given in the command line.
On this version 2 I add check of problematics years in rtctest like suggest
by Alexandre.
Finally that had allowed me to test and fix rtc-st-lpc driver.
Benjamin Gaignard (3):
tools: timer: add rtctest_setdate
tool: timer: rtctest add check for problematic dates
rtc: st-lpc: make it robust against y2038/2106 bug
drivers/rtc/rtc-st-lpc.c | 19 ++--
tools/testing/selftests/timers/Makefile | 2 +-
tools/testing/selftests/timers/rtctest.c | 121 ++++++++++++++++++++++-
tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++
4 files changed, 212 insertions(+), 16 deletions(-)
create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
--
1.9.1
^ permalink raw reply
* [PATCH v2 1/3] tools: timer: add rtctest_setdate
From: Benjamin Gaignard @ 2017-06-19 9:36 UTC (permalink / raw)
To: john.stultz, tglx, sboyd, shuah, linux-kernel, linux-kselftest,
patrice.chotard, a.zummo, alexandre.belloni, linux-arm-kernel,
rtc-linux
Cc: linaro-kernel, Benjamin Gaignard
In-Reply-To: <1497864982-29284-1-git-send-email-benjamin.gaignard@linaro.org>
This tool allow to set directly the time and date to a RTC device.
Unlike other tools isn't doens't use "struct timeval" or "time_t"
so it is safe for 32bits platforms when testing for y2038/2106 bug.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
tools/testing/selftests/timers/Makefile | 2 +-
tools/testing/selftests/timers/rtctest_setdate.c | 86 ++++++++++++++++++++++++
2 files changed, 87 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/timers/rtctest_setdate.c
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile
index 5fa1d7e9..54481f1 100644
--- a/tools/testing/selftests/timers/Makefile
+++ b/tools/testing/selftests/timers/Makefile
@@ -9,7 +9,7 @@ TEST_GEN_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \
TEST_GEN_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \
skew_consistency clocksource-switch leap-a-day \
- leapcrash set-tai set-2038 set-tz
+ leapcrash set-tai set-2038 set-tz rtctest_setdate
include ../lib.mk
diff --git a/tools/testing/selftests/timers/rtctest_setdate.c b/tools/testing/selftests/timers/rtctest_setdate.c
new file mode 100644
index 0000000..2cb7848
--- /dev/null
+++ b/tools/testing/selftests/timers/rtctest_setdate.c
@@ -0,0 +1,86 @@
+/* Real Time Clock Driver Test
+ * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
+ *
+ * To build
+ * gcc rtctest_setdate.c -o rtctest_setdate
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdio.h>
+#include <linux/rtc.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+
+static const char default_time[] = "00:00:00";
+
+int main(int argc, char **argv)
+{
+ int fd, retval;
+ struct rtc_time new, current;
+ const char *rtc, *date;
+ const char *time = default_time;
+
+ switch (argc) {
+ case 4:
+ time = argv[3];
+ /* FALLTHROUGH */
+ case 3:
+ date = argv[2];
+ rtc = argv[1];
+ break;
+ default:
+ fprintf(stderr, "usage: rtctest_setdate <rtcdev> <DD-MM-YYYY> [HH:MM:SS]\n");
+ return 1;
+ }
+
+ fd = open(rtc, O_RDONLY);
+ if (fd == -1) {
+ perror(rtc);
+ exit(errno);
+ }
+
+ sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year);
+ new.tm_mon -= 1;
+ new.tm_year -= 1900;
+ sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec);
+
+ fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
+ new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
+ new.tm_hour, new.tm_min, new.tm_sec);
+
+ /* Write the new date in RTC */
+ retval = ioctl(fd, RTC_SET_TIME, &new);
+ if (retval == -1) {
+ perror("RTC_SET_TIME ioctl");
+ close(fd);
+ exit(errno);
+ }
+
+ /* Read back */
+ retval = ioctl(fd, RTC_RD_TIME, ¤t);
+ if (retval == -1) {
+ perror("RTC_RD_TIME ioctl");
+ exit(errno);
+ }
+
+ fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
+ current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
+ current.tm_hour, current.tm_min, current.tm_sec);
+
+ close(fd);
+ return 0;
+}
--
1.9.1
^ permalink raw reply related
* [rtc-linux] [PATCH 00/51] rtc: stop using rtc deprecated functions
From: Benjamin Gaignard @ 2017-06-20 9:35 UTC (permalink / raw)
To: benjamin.gaignard
Cc: linaro-kernel, adi-buildroot-devel, Alessandro Zummo,
Alexandre Belloni, Gregory Clement, Ingo Molnar, Jason Cooper,
John Stultz, linux-arm-kernel, linux-kernel, Linus Walleij,
Michael Chan, netdev, rtc-linux, Sebastian Hesselbarth,
Support Opensource, Thomas Gleixner, x86, Baruch Siach,
Hans Ulli Kroll, Vladimir Zapolskiy, Sylvain Lemieux, Barry Song,
Maxime Ripard, Chen-Yu Tsai, Thierry Reding, Jonathan Hunter,
linux-tegra, patches, Rafael J. Wysocki, Pavel Machek, Len Brown,
linux-pm
rtc_time_to_tm() and rtc_tm_to_time() are deprecated because they
rely on 32bits variables and that will make rtc break in y2038/2016.
The goal of this series of patches is ti stop using those two functions
and use instead to safer 64bits ones.
It also remove change .set_mmss to set_mmss64 callback for the same reasons.
Those 51 patches almost clean all the drivers except the few that I haven't
been able to compile because of cross-toolchains issues (au1xxx, mpc5121, ps3,
puv3, sun4v, tx4939, starfire, ls1x ...)
Obviously I don't have all those hardwares in my hands so I have only check
that the patches compile without warnings but it up to each maintainer to
valid them on real hardware.
Benjamin Gaignard (51):
x86: rtc: stop using rtc deprecated functions
x86: intel-mid: vrtc: stop using rtc deprecated functions
net: broadcom: stop using rtc deprecated functions
rtc: 88pm80x: stop using rtc deprecated functions
rtc: 88pm860x: stop using rtc deprecated functions
rtc: ab-b5ze-s3: stop using rtc deprecated functions
rtc: ab8500: stop using rtc deprecated functions
rtc: armada38x: stop using rtc deprecated functions
rtc: at32ap700x: stop using rtc deprecated functions
rtc: at91sam9: stop using rtc deprecated functions
rtc: bfin: stop using rtc deprecated functions
rtc: coh901331: stop using rtc deprecated functions
rtc: cpcap: stop using rtc deprecated functions
rtc: da9063: stop using rtc deprecated functions
rtc: da9063: stop using rtc deprecated functions
rtc: davinci: stop using rtc deprecated functions
rtc: digicolor: stop using rtc deprecated functions
rtc: dm355evm: stop using rtc deprecated functions
rtc: ds1305: stop using rtc deprecated functions
rtc: ds1374: stop using rtc deprecated functions
rtc: ds1511: stop using rtc deprecated functions
rtc: ds1553: stop using rtc deprecated functions
rtc: ds1672: stop using rtc deprecated functions
rtc: ds2404: stop using rtc deprecated functions
rtc: ep93xx: stop using rtc deprecated functions
rtc: gemini: stop using rtc deprecated functions
rtc: imxdi: stop using rtc deprecated functions
rtc: jz4740: stop using rtc deprecated functions
rtc: lpc32xx: stop using rtc deprecated functions
rtc: mv: stop using rtc deprecated functions
rtc: omap: stop using rtc deprecated functions
rtc: pcap: stop using rtc deprecated functions
rtc: pl030: stop using rtc deprecated functions
rtc: pl031: stop using rtc deprecated functions
rtc: pm8xxx: stop using rtc deprecated functions
rtc: rs5c348: stop using rtc deprecated functions
rtc: sa1100: stop using rtc deprecated functions
rtc: sh: stop using rtc deprecated functions
rtc: sirfsoc: stop using rtc deprecated functions
rtc: snvs: stop using rtc deprecated functions
rtc: stk17ta8: stop using rtc deprecated functions
rtc: stmp3xxx: stop using rtc deprecated functions
rtc: sun6i: stop using rtc deprecated functions
rtc: sysfs: stop using rtc deprecated functions
rtc: tegra stop using rtc deprecated functions
rtc: test: stop using rtc deprecated functions
rtc: tps6586: stop using rtc deprecated functions
rtc: vr41xx: stop using rtc deprecated functions
rtc: wm831x: stop using rtc deprecated functions
rtc: xgene stop using rtc deprecated functions
power: suspend test: stop using rtc deprecated functions
arch/x86/kernel/rtc.c | 6 ++--
arch/x86/platform/intel-mid/intel_mid_vrtc.c | 2 +-
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +-
drivers/rtc/rtc-88pm80x.c | 44 +++++++++++++--------------
drivers/rtc/rtc-88pm860x.c | 40 ++++++++++++-------------
drivers/rtc/rtc-ab-b5ze-s3.c | 45 ++++++++--------------------
drivers/rtc/rtc-ab8500.c | 26 ++++++++--------
drivers/rtc/rtc-armada38x.c | 34 +++++++++------------
drivers/rtc/rtc-at32ap700x.c | 29 ++++++++----------
drivers/rtc/rtc-at91sam9.c | 18 ++++-------
drivers/rtc/rtc-bfin.c | 24 +++++++--------
drivers/rtc/rtc-coh901331.c | 14 +++++----
drivers/rtc/rtc-cpcap.c | 8 ++---
drivers/rtc/rtc-da9052.c | 8 ++---
drivers/rtc/rtc-da9063.c | 8 ++---
drivers/rtc/rtc-davinci.c | 8 ++---
drivers/rtc/rtc-digicolor.c | 4 +--
drivers/rtc/rtc-dm355evm.c | 6 ++--
drivers/rtc/rtc-ds1305.c | 11 +++----
drivers/rtc/rtc-ds1374.c | 6 ++--
drivers/rtc/rtc-ds1511.c | 2 +-
drivers/rtc/rtc-ds1553.c | 2 +-
drivers/rtc/rtc-ds1672.c | 8 ++---
drivers/rtc/rtc-ds2404.c | 8 ++---
drivers/rtc/rtc-ep93xx.c | 10 +++----
drivers/rtc/rtc-gemini.c | 8 ++---
drivers/rtc/rtc-imxdi.c | 16 +++++-----
drivers/rtc/rtc-jz4740.c | 12 ++++----
drivers/rtc/rtc-lpc32xx.c | 19 +++++-------
drivers/rtc/rtc-mv.c | 2 +-
drivers/rtc/rtc-omap.c | 6 ++--
drivers/rtc/rtc-pcap.c | 16 +++++-----
drivers/rtc/rtc-pl030.c | 24 +++++++--------
drivers/rtc/rtc-pl031.c | 31 ++++++++-----------
drivers/rtc/rtc-pm8xxx.c | 22 +++++++-------
drivers/rtc/rtc-rs5c348.c | 4 +--
drivers/rtc/rtc-sa1100.c | 25 +++++++---------
drivers/rtc/rtc-sh.c | 2 +-
drivers/rtc/rtc-sirfsoc.c | 18 +++++------
drivers/rtc/rtc-snvs.c | 14 ++++-----
drivers/rtc/rtc-stk17ta8.c | 2 +-
drivers/rtc/rtc-stmp3xxx.c | 12 ++++----
drivers/rtc/rtc-sun6i.c | 14 ++++-----
drivers/rtc/rtc-sysfs.c | 25 ++++++++--------
drivers/rtc/rtc-tegra.c | 22 +++++++-------
drivers/rtc/rtc-test.c | 17 +----------
drivers/rtc/rtc-tps6586x.c | 26 ++++++++--------
drivers/rtc/rtc-vr41xx.c | 6 ++--
drivers/rtc/rtc-wm831x.c | 28 +++++++----------
drivers/rtc/rtc-xgene.c | 12 ++++----
kernel/power/suspend_test.c | 6 ++--
51 files changed, 342 insertions(+), 420 deletions(-)
--
CC: adi-buildroot-devel@lists.sourceforge.net
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Alexandre Belloni <alexandre.belloni@free-electrons.com>
CC: Gregory Clement <gregory.clement@free-electrons.com>
CC: Ingo Molnar <mingo@redhat.com>
CC: Jason Cooper <jason@lakedaemon.net>
CC: John Stultz <john.stultz@linaro.org>
CC: linux-arm-kernel@lists.infradead.org
CC: linux-kernel@vger.kernel.org
CC: Linus Walleij <linus.walleij@linaro.org>
CC: Michael Chan <michael.chan@broadcom.com>
CC: netdev@vger.kernel.org
CC: rtc-linux@googlegroups.com
CC: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
CC: Support Opensource <support.opensource@diasemi.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: x86@kernel.org
CC: Baruch Siach <baruch@tkos.co.il>
CC: Hans Ulli Kroll <ulli.kroll@googlemail.com>
CC: Vladimir Zapolskiy <vz@mleia.com>
CC: Sylvain Lemieux <slemieux.tyco@gmail.com>
CC: Barry Song <baohua@kernel.org>
CC: Maxime Ripard <maxime.ripard@free-electrons.com>
CC: Chen-Yu Tsai <wens@csie.org>
CC: Thierry Reding <thierry.reding@gmail.com>
CC: Jonathan Hunter <jonathanh@nvidia.com>
CC: linux-tegra@vger.kernel.org
CC: patches@opensource.wolfsonmicro.com
CC: "Rafael J. Wysocki" <rjw@rjwysocki.net>
CC: Pavel Machek <pavel@ucw.cz>
CC: Len Brown <len.brown@intel.com>
CC: linux-pm@vger.kernel.org
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply
* [rtc-linux] [PATCH 04/51] rtc: 88pm80x: stop using rtc deprecated functions
From: Benjamin Gaignard @ 2017-06-20 9:35 UTC (permalink / raw)
To: benjamin.gaignard
Cc: linaro-kernel, Alessandro Zummo, Alexandre Belloni, rtc-linux,
linux-kernel
In-Reply-To: <1497951359-13334-1-git-send-email-benjamin.gaignard@linaro.org>
rtc_time_to_tm() and rtc_tm_to_time() are deprecated because they
rely on 32bits variables and that will make rtc break in y2038/2016.
Stop using those two functions to safer 64bits ones.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
CC: Alessandro Zummo <a.zummo@towertech.it>
CC: Alexandre Belloni <alexandre.belloni@free-electrons.com>
CC: rtc-linux@googlegroups.com
CC: linux-kernel@vger.kernel.org
---
drivers/rtc/rtc-88pm80x.c | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 466bf7f..1898e9b 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -90,8 +90,8 @@ static int pm80x_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
struct rtc_time *alrm)
{
- unsigned long next_time;
- unsigned long now_time;
+ unsigned long long next_time;
+ unsigned long long now_time;
next->tm_year = now->tm_year;
next->tm_mon = now->tm_mon;
@@ -100,13 +100,13 @@ static void rtc_next_alarm_time(struct rtc_time *next, struct rtc_time *now,
next->tm_min = alrm->tm_min;
next->tm_sec = alrm->tm_sec;
- rtc_tm_to_time(now, &now_time);
- rtc_tm_to_time(next, &next_time);
+ now_time = rtc_tm_to_time64(now);
+ next_time = rtc_tm_to_time64(next);
if (next_time < now_time) {
/* Advance one day */
next_time += 60 * 60 * 24;
- rtc_time_to_tm(next_time, next);
+ rtc_time64_to_tm(next_time, next);
}
}
@@ -114,7 +114,7 @@ static int pm80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct pm80x_rtc_info *info = dev_get_drvdata(dev);
unsigned char buf[4];
- unsigned long ticks, base, data;
+ unsigned long long ticks, base, data;
regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4);
base = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
dev_dbg(info->dev, "%x-%x-%x-%x\n", buf[0], buf[1], buf[2], buf[3]);
@@ -123,9 +123,9 @@ static int pm80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4);
data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
ticks = base + data;
- dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ dev_dbg(info->dev, "get base:0x%llx, RO count:0x%llx, ticks:0x%llx\n",
base, data, ticks);
- rtc_time_to_tm(ticks, tm);
+ rtc_time64_to_tm(ticks, tm);
return 0;
}
@@ -133,20 +133,20 @@ static int pm80x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct pm80x_rtc_info *info = dev_get_drvdata(dev);
unsigned char buf[4];
- unsigned long ticks, base, data;
+ unsigned long long ticks, base, data;
if ((tm->tm_year < 70) || (tm->tm_year > 138)) {
dev_dbg(info->dev,
"Set time %d out of range. Please set time between 1970 to 2038.\n",
1900 + tm->tm_year);
return -EINVAL;
}
- rtc_tm_to_time(tm, &ticks);
+ ticks = rtc_tm_to_time64(tm);
/* load 32-bit read-only counter */
regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4);
data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
base = ticks - data;
- dev_dbg(info->dev, "set base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ dev_dbg(info->dev, "set base:0x%llx, RO count:0x%llx, ticks:0x%llx\n",
base, data, ticks);
buf[0] = base & 0xFF;
buf[1] = (base >> 8) & 0xFF;
@@ -161,7 +161,7 @@ static int pm80x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pm80x_rtc_info *info = dev_get_drvdata(dev);
unsigned char buf[4];
- unsigned long ticks, base, data;
+ unsigned long long ticks, base, data;
int ret;
regmap_raw_read(info->map, PM800_RTC_EXPIRE2_1, buf, 4);
@@ -171,10 +171,10 @@ static int pm80x_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
regmap_raw_read(info->map, PM800_RTC_EXPIRE1_1, buf, 4);
data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
ticks = base + data;
- dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ dev_dbg(info->dev, "get base:0x%llx, RO count:0x%llx, ticks:0x%llx\n",
base, data, ticks);
- rtc_time_to_tm(ticks, &alrm->time);
+ rtc_time64_to_tm(ticks, &alrm->time);
regmap_read(info->map, PM800_RTC_CONTROL, &ret);
alrm->enabled = (ret & PM800_ALARM1_EN) ? 1 : 0;
alrm->pending = (ret & (PM800_ALARM | PM800_ALARM_WAKEUP)) ? 1 : 0;
@@ -185,7 +185,7 @@ static int pm80x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pm80x_rtc_info *info = dev_get_drvdata(dev);
struct rtc_time now_tm, alarm_tm;
- unsigned long ticks, base, data;
+ unsigned long long ticks, base, data;
unsigned char buf[4];
int mask;
@@ -199,15 +199,15 @@ static int pm80x_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
regmap_raw_read(info->map, PM800_RTC_COUNTER1, buf, 4);
data = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
ticks = base + data;
- dev_dbg(info->dev, "get base:0x%lx, RO count:0x%lx, ticks:0x%lx\n",
+ dev_dbg(info->dev, "get base:0x%llx, RO count:0x%llx, ticks:0x%llx\n",
base, data, ticks);
- rtc_time_to_tm(ticks, &now_tm);
- dev_dbg(info->dev, "%s, now time : %lu\n", __func__, ticks);
+ rtc_time64_to_tm(ticks, &now_tm);
+ dev_dbg(info->dev, "%s, now time : %llu\n", __func__, ticks);
rtc_next_alarm_time(&alarm_tm, &now_tm, &alrm->time);
/* get new ticks for alarm in 24 hours */
- rtc_tm_to_time(&alarm_tm, &ticks);
- dev_dbg(info->dev, "%s, alarm time: %lu\n", __func__, ticks);
+ ticks = rtc_tm_to_time64(&alarm_tm);
+ dev_dbg(info->dev, "%s, alarm time: %llu\n", __func__, ticks);
data = ticks - base;
buf[0] = data & 0xff;
@@ -255,7 +255,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
struct pm80x_rtc_info *info;
struct device_node *node = pdev->dev.of_node;
struct rtc_time tm;
- unsigned long ticks = 0;
+ unsigned long long ticks = 0;
int ret;
if (!pdata && !node) {
@@ -320,7 +320,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
goto out_rtc;
}
}
- rtc_tm_to_time(&tm, &ticks);
+ ticks = rtc_tm_to_time64(&tm);
info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm80x-rtc",
&pm80x_rtc_ops, THIS_MODULE);
--
1.9.1
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox