summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-01-01 16:24:31 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2019-01-01 16:24:31 -0500
commit28e8c4bc8eb483c22d977e147a0b98fc63efadf7 (patch)
tree8006dd759601c70d4dd1fc644ed817e9597cec55
parentc9bef4a651769927445900564781a9c99fdf6258 (diff)
parent36e14f5fdfdf7cec8887b7ff69cd9bb5051ecf62 (diff)
Merge tag 'rtc-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux
Pull RTC updates from Alexandre Belloni: "Subsystem: - new %ptR printk format - rename core files - allow registration of multiple nvmem devices New driver: - i.MX system controller RTC Driver updates: - abx80x: handle voltage ioctls, correct binding doc - m41t80: correct month in alarm reads - pcf85363: add pcf85263 support - pcf8523: properly handle battery low flag - s3c: limit alarm to one year in the future as ALMYEAR is broken - sun6i: rework clock output binding" * tag 'rtc-4.21' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (54 commits) rtc: rename core files rtc: nvmem: fix possible use after free rtc: add i.MX system controller RTC support dt-bindings: fsl: scu: add rtc binding rtc: pcf2123: Add Microcrystal rv2123 rtc: class: reimplement devm_rtc_device_register rtc: enforce rtc_timer_init private_data type rtc: abx80x: Implement RTC_VL_READ,CLR ioctls rtc: pcf85363: Add support for NXP pcf85263 rtc dt-bindings: rtc: pcf85363: Document pcf85263 real-time clock rtc: pcf8523: don't return invalid date when battery is low dt-bindings: rtc: use a generic node name for ds1307 PM: Switch to use %ptR m68k/mac: Switch to use %ptR Input: hp_sdc_rtc - Switch to use %ptR rtc: tegra: Switch to use %ptR rtc: s5m: Switch to use %ptR rtc: s3c: Switch to use %ptR rtc: rx8025: Switch to use %ptR rtc: rx6110: Switch to use %ptR ...
-rw-r--r--Documentation/core-api/printk-formats.rst18
-rw-r--r--Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt10
-rw-r--r--Documentation/devicetree/bindings/rtc/abracon,abx80x.txt2
-rw-r--r--Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt1
-rw-r--r--Documentation/devicetree/bindings/rtc/pcf85363.txt4
-rw-r--r--Documentation/devicetree/bindings/rtc/rtc-ds1307.txt2
-rw-r--r--Documentation/devicetree/bindings/rtc/sun6i-rtc.txt33
-rw-r--r--arch/m68k/mac/misc.c8
-rw-r--r--drivers/base/power/trace.c4
-rw-r--r--drivers/char/rtc.c7
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c8
-rw-r--r--drivers/rtc/Kconfig7
-rw-r--r--drivers/rtc/Makefile9
-rw-r--r--drivers/rtc/class.c187
-rw-r--r--drivers/rtc/dev.c (renamed from drivers/rtc/rtc-dev.c)0
-rw-r--r--drivers/rtc/hctosys.c8
-rw-r--r--drivers/rtc/interface.c27
-rw-r--r--drivers/rtc/lib.c (renamed from drivers/rtc/rtc-lib.c)0
-rw-r--r--drivers/rtc/nvmem.c38
-rw-r--r--drivers/rtc/proc.c (renamed from drivers/rtc/rtc-proc.c)36
-rw-r--r--drivers/rtc/rtc-abx80x.c38
-rw-r--r--drivers/rtc/rtc-at91rm9200.c15
-rw-r--r--drivers/rtc/rtc-at91sam9.c16
-rw-r--r--drivers/rtc/rtc-ep93xx.c2
-rw-r--r--drivers/rtc/rtc-imx-sc.c91
-rw-r--r--drivers/rtc/rtc-isl1208.c37
-rw-r--r--drivers/rtc/rtc-m41t80.c21
-rw-r--r--drivers/rtc/rtc-m48t59.c8
-rw-r--r--drivers/rtc/rtc-max6916.c2
-rw-r--r--drivers/rtc/rtc-max77686.c2
-rw-r--r--drivers/rtc/rtc-max8997.c2
-rw-r--r--drivers/rtc/rtc-mcp795.c18
-rw-r--r--drivers/rtc/rtc-omap.c4
-rw-r--r--drivers/rtc/rtc-pcf2123.c1
-rw-r--r--drivers/rtc/rtc-pcf50633.c8
-rw-r--r--drivers/rtc/rtc-pcf8523.c32
-rw-r--r--drivers/rtc/rtc-pcf85363.c94
-rw-r--r--drivers/rtc/rtc-pic32.c18
-rw-r--r--drivers/rtc/rtc-pm8xxx.c16
-rw-r--r--drivers/rtc/rtc-puv3.c18
-rw-r--r--drivers/rtc/rtc-rk808.c22
-rw-r--r--drivers/rtc/rtc-rx6110.c12
-rw-r--r--drivers/rtc/rtc-rx8025.c19
-rw-r--r--drivers/rtc/rtc-s3c.c26
-rw-r--r--drivers/rtc/rtc-s5m.c27
-rw-r--r--drivers/rtc/rtc-sh.c7
-rw-r--r--drivers/rtc/rtc-sun6i.c121
-rw-r--r--drivers/rtc/rtc-tegra.c30
-rw-r--r--drivers/rtc/sysfs.c (renamed from drivers/rtc/rtc-sysfs.c)16
-rw-r--r--include/linux/rtc.h17
-rw-r--r--lib/test_printf.c61
-rw-r--r--lib/vsprintf.c100
52 files changed, 744 insertions, 566 deletions
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index ff48b55040ef..a7fae4538946 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -412,6 +412,24 @@ Examples::
412 412
413Passed by reference. 413Passed by reference.
414 414
415Time and date (struct rtc_time)
416-------------------------------
417
418::
419
420 %ptR YYYY-mm-ddTHH:MM:SS
421 %ptRd YYYY-mm-dd
422 %ptRt HH:MM:SS
423 %ptR[dt][r]
424
425For printing date and time as represented by struct rtc_time structure in
426human readable format.
427
428By default year will be incremented by 1900 and month by 1. Use %ptRr (raw)
429to suppress this behaviour.
430
431Passed by reference.
432
415struct clk 433struct clk
416---------- 434----------
417 435
diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
index 0af618b6a448..27784b6edfed 100644
--- a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
+++ b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
@@ -109,6 +109,12 @@ Required properties for Pinctrl sub nodes:
109[2] Documentation/devicetree/bindings/power/power_domain.txt 109[2] Documentation/devicetree/bindings/power/power_domain.txt
110[3] Documentation/devicetree/bindings/pinctrl/fsl,imx-pinctrl.txt 110[3] Documentation/devicetree/bindings/pinctrl/fsl,imx-pinctrl.txt
111 111
112RTC bindings based on SCU Message Protocol
113------------------------------------------------------------
114
115Required properties:
116- compatible: should be "fsl,imx8qxp-sc-rtc";
117
112Example (imx8qxp): 118Example (imx8qxp):
113------------- 119-------------
114lsio_mu1: mailbox@5d1c0000 { 120lsio_mu1: mailbox@5d1c0000 {
@@ -151,6 +157,10 @@ firmware {
151 compatible = "fsl,imx8qxp-scu-pd"; 157 compatible = "fsl,imx8qxp-scu-pd";
152 #power-domain-cells = <1>; 158 #power-domain-cells = <1>;
153 }; 159 };
160
161 rtc: rtc {
162 compatible = "fsl,imx8qxp-sc-rtc";
163 };
154 }; 164 };
155}; 165};
156 166
diff --git a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
index be789685a1c2..18b892d010d8 100644
--- a/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
+++ b/Documentation/devicetree/bindings/rtc/abracon,abx80x.txt
@@ -27,4 +27,4 @@ and valid to enable charging:
27 27
28 - "abracon,tc-diode": should be "standard" (0.6V) or "schottky" (0.3V) 28 - "abracon,tc-diode": should be "standard" (0.6V) or "schottky" (0.3V)
29 - "abracon,tc-resistor": should be <0>, <3>, <6> or <11>. 0 disables the output 29 - "abracon,tc-resistor": should be <0>, <3>, <6> or <11>. 0 disables the output
30 resistor, the other values are in ohm. 30 resistor, the other values are in kOhm.
diff --git a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
index 811124a36d16..1994f601800a 100644
--- a/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
+++ b/Documentation/devicetree/bindings/rtc/nxp,rtc-2123.txt
@@ -2,6 +2,7 @@ NXP PCF2123 SPI Real Time Clock
2 2
3Required properties: 3Required properties:
4- compatible: should be: "nxp,rtc-pcf2123" 4- compatible: should be: "nxp,rtc-pcf2123"
5 or "microcrystal,rv2123"
5- reg: should be the SPI slave chipselect address 6- reg: should be the SPI slave chipselect address
6 7
7Optional properties: 8Optional properties:
diff --git a/Documentation/devicetree/bindings/rtc/pcf85363.txt b/Documentation/devicetree/bindings/rtc/pcf85363.txt
index 76fdabc59742..94adc1cf93d9 100644
--- a/Documentation/devicetree/bindings/rtc/pcf85363.txt
+++ b/Documentation/devicetree/bindings/rtc/pcf85363.txt
@@ -1,8 +1,8 @@
1NXP PCF85363 Real Time Clock 1NXP PCF85263/PCF85363 Real Time Clock
2============================ 2============================
3 3
4Required properties: 4Required properties:
5- compatible: Should contain "nxp,pcf85363". 5- compatible: Should contain "nxp,pcf85263" or "nxp,pcf85363".
6- reg: I2C address for chip. 6- reg: I2C address for chip.
7 7
8Optional properties: 8Optional properties:
diff --git a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
index eebfbe04207a..eaee19b60960 100644
--- a/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
+++ b/Documentation/devicetree/bindings/rtc/rtc-ds1307.txt
@@ -35,7 +35,7 @@ Optional properties:
35 Should be given if internal trickle charger diode should be disabled 35 Should be given if internal trickle charger diode should be disabled
36 36
37Example: 37Example:
38 rtc1: ds1339@68 { 38 ds1339: rtc@68 {
39 compatible = "dallas,ds1339"; 39 compatible = "dallas,ds1339";
40 reg = <0x68>; 40 reg = <0x68>;
41 interrupt-parent = <&gpio4>; 41 interrupt-parent = <&gpio4>;
diff --git a/Documentation/devicetree/bindings/rtc/sun6i-rtc.txt b/Documentation/devicetree/bindings/rtc/sun6i-rtc.txt
index 12c083c1140a..6b732c41392b 100644
--- a/Documentation/devicetree/bindings/rtc/sun6i-rtc.txt
+++ b/Documentation/devicetree/bindings/rtc/sun6i-rtc.txt
@@ -3,25 +3,44 @@
3RTC controller for the Allwinner A31 3RTC controller for the Allwinner A31
4 4
5Required properties: 5Required properties:
6- compatible : Should be "allwinner,sun6i-a31-rtc" 6- compatible : Should be one of the following combinations:
7 - "allwinner,sun6i-a31-rtc"
8 - "allwinner,sun8i-a23-rtc"
9 - "allwinner,sun8i-h3-rtc"
10 - "allwinner,sun8i-r40-rtc", "allwinner,sun8i-h3-rtc"
11 - "allwinner,sun8i-v3-rtc"
12 - "allwinner,sun50i-a64-rtc", "allwinner,sun8i-h3-rtc"
13 - "allwinner,sun50i-h5-rtc"
14
15 Where there are two or more compatible strings, this
16 denotes the hardware covered by the most specific one
17 is backward-compatible with the latter ones, and the
18 implementation for the latter ones can be used, albeit
19 with reduced functionality.
20
7- reg : physical base address of the controller and length of 21- reg : physical base address of the controller and length of
8 memory mapped region. 22 memory mapped region.
9- interrupts : IRQ lines for the RTC alarm 0 and alarm 1, in that order. 23- interrupts : IRQ lines for the RTC alarm 0 and alarm 1, in that order.
10 24
11Required properties for new device trees 25Required properties for new device trees
12- clocks : phandle to the 32kHz external oscillator 26- clocks : phandle to the 32kHz external oscillator
13- clock-output-names : names of the LOSC and its external output clocks created 27- clock-output-names : names of up to three clock outputs. See below.
14- #clock-cells : must be equals to 1. The RTC provides two clocks: the 28- #clock-cells : must be equal to 1.
15 LOSC and its external output, with index 0 and 1 29
16 respectively. 30The RTC provides the following clocks at the given indices:
31- 0: LOSC
32- 1: LOSC external output, known as X32KFOUT in the datasheet.
33 This clock is not available on the A31 and is deprecated for old
34 device trees still using the "allwinner,sun6i-a31-rtc" compatible.
35- 2: InternalOSC, or internal RC oscillator (A64/H3/H5 only)
17 36
18Example: 37Example:
19 38
20rtc: rtc@1f00000 { 39rtc: rtc@1f00000 {
21 compatible = "allwinner,sun6i-a31-rtc"; 40 compatible = "allwinner,sun6i-a31-rtc";
22 reg = <0x01f00000 0x54>; 41 reg = <0x01f00000 0x400>;
23 interrupts = <0 40 4>, <0 41 4>; 42 interrupts = <0 40 4>, <0 41 4>;
24 clock-output-names = "osc32k", "osc32k-out"; 43 clock-output-names = "osc32k";
25 clocks = <&ext_osc32k>; 44 clocks = <&ext_osc32k>;
26 #clock-cells = <1>; 45 #clock-cells = <1>;
27}; 46};
diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index ebb3b6d169ea..71c4735a31ee 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -605,13 +605,9 @@ int mac_hwclk(int op, struct rtc_time *t)
605 unmktime(now, 0, 605 unmktime(now, 0,
606 &t->tm_year, &t->tm_mon, &t->tm_mday, 606 &t->tm_year, &t->tm_mon, &t->tm_mday,
607 &t->tm_hour, &t->tm_min, &t->tm_sec); 607 &t->tm_hour, &t->tm_min, &t->tm_sec);
608 pr_debug("%s: read %04d-%02d-%-2d %02d:%02d:%02d\n", 608 pr_debug("%s: read %ptR\n", __func__, t);
609 __func__, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
610 t->tm_hour, t->tm_min, t->tm_sec);
611 } else { /* write */ 609 } else { /* write */
612 pr_debug("%s: tried to write %04d-%02d-%-2d %02d:%02d:%02d\n", 610 pr_debug("%s: tried to write %ptR\n", __func__, t);
613 __func__, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
614 t->tm_hour, t->tm_min, t->tm_sec);
615 611
616 switch (macintosh_config->adb_type) { 612 switch (macintosh_config->adb_type) {
617 case MAC_ADB_IOP: 613 case MAC_ADB_IOP:
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index 1cda505d6a85..b11f47a1e819 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -118,9 +118,7 @@ static unsigned int read_magic_time(void)
118 unsigned int val; 118 unsigned int val;
119 119
120 mc146818_get_time(&time); 120 mc146818_get_time(&time);
121 pr_info("RTC time: %2d:%02d:%02d, date: %02d/%02d/%02d\n", 121 pr_info("RTC time: %ptRt, date: %ptRd\n", &time, &time);
122 time.tm_hour, time.tm_min, time.tm_sec,
123 time.tm_mon + 1, time.tm_mday, time.tm_year % 100);
124 val = time.tm_year; /* 100 years */ 122 val = time.tm_year; /* 100 years */
125 if (val > 100) 123 if (val > 100)
126 val -= 100; 124 val -= 100;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 62b7c721c732..c862d0b6b118 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -1125,11 +1125,10 @@ static int rtc_proc_show(struct seq_file *seq, void *v)
1125 * time or for Universal Standard Time (GMT). Probably local though. 1125 * time or for Universal Standard Time (GMT). Probably local though.
1126 */ 1126 */
1127 seq_printf(seq, 1127 seq_printf(seq,
1128 "rtc_time\t: %02d:%02d:%02d\n" 1128 "rtc_time\t: %ptRt\n"
1129 "rtc_date\t: %04d-%02d-%02d\n" 1129 "rtc_date\t: %ptRd\n"
1130 "rtc_epoch\t: %04lu\n", 1130 "rtc_epoch\t: %04lu\n",
1131 tm.tm_hour, tm.tm_min, tm.tm_sec, 1131 &tm, &tm, epoch);
1132 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, epoch);
1133 1132
1134 get_rtc_alm_time(&tm); 1133 get_rtc_alm_time(&tm);
1135 1134
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index 47eb8ca729fe..abca895a6156 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -441,12 +441,10 @@ static int hp_sdc_rtc_proc_show(struct seq_file *m, void *v)
441 seq_puts(m, "BBRTC\t\t: READ FAILED!\n"); 441 seq_puts(m, "BBRTC\t\t: READ FAILED!\n");
442 } else { 442 } else {
443 seq_printf(m, 443 seq_printf(m,
444 "rtc_time\t: %02d:%02d:%02d\n" 444 "rtc_time\t: %ptRt\n"
445 "rtc_date\t: %04d-%02d-%02d\n" 445 "rtc_date\t: %ptRd\n"
446 "rtc_epoch\t: %04lu\n", 446 "rtc_epoch\t: %04lu\n",
447 tm.tm_hour, tm.tm_min, tm.tm_sec, 447 &tm, &tm, epoch);
448 tm.tm_year + 1900, tm.tm_mon + 1,
449 tm.tm_mday, epoch);
450 } 448 }
451 449
452 if (hp_sdc_rtc_read_rt(&tv)) { 450 if (hp_sdc_rtc_read_rt(&tv)) {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a819ef07b7ec..225b0b8516f3 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1677,6 +1677,13 @@ config RTC_DRV_SNVS
1677 This driver can also be built as a module, if so, the module 1677 This driver can also be built as a module, if so, the module
1678 will be called "rtc-snvs". 1678 will be called "rtc-snvs".
1679 1679
1680config RTC_DRV_IMX_SC
1681 depends on IMX_SCU
1682 tristate "NXP i.MX System Controller RTC support"
1683 help
1684 If you say yes here you get support for the NXP i.MX System
1685 Controller RTC module.
1686
1680config RTC_DRV_SIRFSOC 1687config RTC_DRV_SIRFSOC
1681 tristate "SiRFSOC RTC" 1688 tristate "SiRFSOC RTC"
1682 depends on ARCH_SIRF 1689 depends on ARCH_SIRF
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 290c1730fb0a..df022d820bee 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -5,7 +5,7 @@
5 5
6ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG 6ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG
7 7
8obj-$(CONFIG_RTC_LIB) += rtc-lib.o 8obj-$(CONFIG_RTC_LIB) += lib.o
9obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 9obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
10obj-$(CONFIG_RTC_SYSTOHC) += systohc.o 10obj-$(CONFIG_RTC_SYSTOHC) += systohc.o
11obj-$(CONFIG_RTC_CLASS) += rtc-core.o 11obj-$(CONFIG_RTC_CLASS) += rtc-core.o
@@ -17,9 +17,9 @@ rtc-core-y += rtc-efi-platform.o
17endif 17endif
18 18
19rtc-core-$(CONFIG_RTC_NVMEM) += nvmem.o 19rtc-core-$(CONFIG_RTC_NVMEM) += nvmem.o
20rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 20rtc-core-$(CONFIG_RTC_INTF_DEV) += dev.o
21rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 21rtc-core-$(CONFIG_RTC_INTF_PROC) += proc.o
22rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o 22rtc-core-$(CONFIG_RTC_INTF_SYSFS) += sysfs.o
23 23
24# Keep the list ordered. 24# Keep the list ordered.
25 25
@@ -75,6 +75,7 @@ obj-$(CONFIG_RTC_DRV_GOLDFISH) += rtc-goldfish.o
75obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o 75obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
76obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o 76obj-$(CONFIG_RTC_DRV_HYM8563) += rtc-hym8563.o
77obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o 77obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
78obj-$(CONFIG_RTC_DRV_IMX_SC) += rtc-imx-sc.o
78obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o 79obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
79obj-$(CONFIG_RTC_DRV_ISL12026) += rtc-isl12026.o 80obj-$(CONFIG_RTC_DRV_ISL12026) += rtc-isl12026.o
80obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 81obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 3b43787f154b..ac93b76f2b11 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -178,9 +178,9 @@ static struct rtc_device *rtc_allocate_device(void)
178 timerqueue_init_head(&rtc->timerqueue); 178 timerqueue_init_head(&rtc->timerqueue);
179 INIT_WORK(&rtc->irqwork, rtc_timer_do_work); 179 INIT_WORK(&rtc->irqwork, rtc_timer_do_work);
180 /* Init aie timer */ 180 /* Init aie timer */
181 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc); 181 rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, rtc);
182 /* Init uie timer */ 182 /* Init uie timer */
183 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc); 183 rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, rtc);
184 /* Init pie timer */ 184 /* Init pie timer */
185 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 185 hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
186 rtc->pie_timer.function = rtc_pie_update_irq; 186 rtc->pie_timer.function = rtc_pie_update_irq;
@@ -278,82 +278,6 @@ static void rtc_device_get_offset(struct rtc_device *rtc)
278} 278}
279 279
280/** 280/**
281 * rtc_device_register - register w/ RTC class
282 * @dev: the device to register
283 *
284 * rtc_device_unregister() must be called when the class device is no
285 * longer needed.
286 *
287 * Returns the pointer to the new struct class device.
288 */
289static struct rtc_device *rtc_device_register(const char *name,
290 struct device *dev,
291 const struct rtc_class_ops *ops,
292 struct module *owner)
293{
294 struct rtc_device *rtc;
295 struct rtc_wkalrm alrm;
296 int id, err;
297
298 id = rtc_device_get_id(dev);
299 if (id < 0) {
300 err = id;
301 goto exit;
302 }
303
304 rtc = rtc_allocate_device();
305 if (!rtc) {
306 err = -ENOMEM;
307 goto exit_ida;
308 }
309
310 rtc->id = id;
311 rtc->ops = ops;
312 rtc->owner = owner;
313 rtc->dev.parent = dev;
314
315 dev_set_name(&rtc->dev, "rtc%d", id);
316
317 rtc_device_get_offset(rtc);
318
319 /* Check to see if there is an ALARM already set in hw */
320 err = __rtc_read_alarm(rtc, &alrm);
321
322 if (!err && !rtc_valid_tm(&alrm.time))
323 rtc_initialize_alarm(rtc, &alrm);
324
325 rtc_dev_prepare(rtc);
326
327 err = cdev_device_add(&rtc->char_dev, &rtc->dev);
328 if (err) {
329 dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n",
330 name, MAJOR(rtc->dev.devt), rtc->id);
331
332 /* This will free both memory and the ID */
333 put_device(&rtc->dev);
334 goto exit;
335 } else {
336 dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", name,
337 MAJOR(rtc->dev.devt), rtc->id);
338 }
339
340 rtc_proc_add_device(rtc);
341
342 dev_info(dev, "rtc core: registered %s as %s\n",
343 name, dev_name(&rtc->dev));
344
345 return rtc;
346
347exit_ida:
348 ida_simple_remove(&rtc_ida, id);
349
350exit:
351 dev_err(dev, "rtc core: unable to register %s, err = %d\n",
352 name, err);
353 return ERR_PTR(err);
354}
355
356/**
357 * rtc_device_unregister - removes the previously registered RTC class device 281 * rtc_device_unregister - removes the previously registered RTC class device
358 * 282 *
359 * @rtc: the RTC class device to destroy 283 * @rtc: the RTC class device to destroy
@@ -372,77 +296,6 @@ static void rtc_device_unregister(struct rtc_device *rtc)
372 put_device(&rtc->dev); 296 put_device(&rtc->dev);
373} 297}
374 298
375static void devm_rtc_device_release(struct device *dev, void *res)
376{
377 struct rtc_device *rtc = *(struct rtc_device **)res;
378
379 rtc_nvmem_unregister(rtc);
380 rtc_device_unregister(rtc);
381}
382
383static int devm_rtc_device_match(struct device *dev, void *res, void *data)
384{
385 struct rtc **r = res;
386
387 return *r == data;
388}
389
390/**
391 * devm_rtc_device_register - resource managed rtc_device_register()
392 * @dev: the device to register
393 * @name: the name of the device
394 * @ops: the rtc operations structure
395 * @owner: the module owner
396 *
397 * @return a struct rtc on success, or an ERR_PTR on error
398 *
399 * Managed rtc_device_register(). The rtc_device returned from this function
400 * are automatically freed on driver detach. See rtc_device_register()
401 * for more information.
402 */
403
404struct rtc_device *devm_rtc_device_register(struct device *dev,
405 const char *name,
406 const struct rtc_class_ops *ops,
407 struct module *owner)
408{
409 struct rtc_device **ptr, *rtc;
410
411 ptr = devres_alloc(devm_rtc_device_release, sizeof(*ptr), GFP_KERNEL);
412 if (!ptr)
413 return ERR_PTR(-ENOMEM);
414
415 rtc = rtc_device_register(name, dev, ops, owner);
416 if (!IS_ERR(rtc)) {
417 *ptr = rtc;
418 devres_add(dev, ptr);
419 } else {
420 devres_free(ptr);
421 }
422
423 return rtc;
424}
425EXPORT_SYMBOL_GPL(devm_rtc_device_register);
426
427/**
428 * devm_rtc_device_unregister - resource managed devm_rtc_device_unregister()
429 * @dev: the device to unregister
430 * @rtc: the RTC class device to unregister
431 *
432 * Deallocated a rtc allocated with devm_rtc_device_register(). Normally this
433 * function will not need to be called and the resource management code will
434 * ensure that the resource is freed.
435 */
436void devm_rtc_device_unregister(struct device *dev, struct rtc_device *rtc)
437{
438 int rc;
439
440 rc = devres_release(dev, devm_rtc_device_release,
441 devm_rtc_device_match, rtc);
442 WARN_ON(rc);
443}
444EXPORT_SYMBOL_GPL(devm_rtc_device_unregister);
445
446static void devm_rtc_release_device(struct device *dev, void *res) 299static void devm_rtc_release_device(struct device *dev, void *res)
447{ 300{
448 struct rtc_device *rtc = *(struct rtc_device **)res; 301 struct rtc_device *rtc = *(struct rtc_device **)res;
@@ -529,6 +382,42 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
529} 382}
530EXPORT_SYMBOL_GPL(__rtc_register_device); 383EXPORT_SYMBOL_GPL(__rtc_register_device);
531 384
385/**
386 * devm_rtc_device_register - resource managed rtc_device_register()
387 * @dev: the device to register
388 * @name: the name of the device (unused)
389 * @ops: the rtc operations structure
390 * @owner: the module owner
391 *
392 * @return a struct rtc on success, or an ERR_PTR on error
393 *
394 * Managed rtc_device_register(). The rtc_device returned from this function
395 * are automatically freed on driver detach.
396 * This function is deprecated, use devm_rtc_allocate_device and
397 * rtc_register_device instead
398 */
399struct rtc_device *devm_rtc_device_register(struct device *dev,
400 const char *name,
401 const struct rtc_class_ops *ops,
402 struct module *owner)
403{
404 struct rtc_device *rtc;
405 int err;
406
407 rtc = devm_rtc_allocate_device(dev);
408 if (IS_ERR(rtc))
409 return rtc;
410
411 rtc->ops = ops;
412
413 err = __rtc_register_device(owner, rtc);
414 if (err)
415 return ERR_PTR(err);
416
417 return rtc;
418}
419EXPORT_SYMBOL_GPL(devm_rtc_device_register);
420
532static int __init rtc_init(void) 421static int __init rtc_init(void)
533{ 422{
534 rtc_class = class_create(THIS_MODULE, "rtc"); 423 rtc_class = class_create(THIS_MODULE, "rtc");
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/dev.c
index 43d962a9c210..43d962a9c210 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/dev.c
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index b9ec4a16db1f..ff2092a0d38c 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -58,12 +58,8 @@ static int __init rtc_hctosys(void)
58 58
59 err = do_settimeofday64(&tv64); 59 err = do_settimeofday64(&tv64);
60 60
61 dev_info(rtc->dev.parent, 61 dev_info(rtc->dev.parent, "setting system clock to %ptR UTC (%lld)\n",
62 "setting system clock to " 62 &tm, (long long)tv64.tv_sec);
63 "%d-%02d-%02d %02d:%02d:%02d UTC (%lld)\n",
64 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
65 tm.tm_hour, tm.tm_min, tm.tm_sec,
66 (long long) tv64.tv_sec);
67 63
68err_read: 64err_read:
69 rtc_class_close(rtc); 65 rtc_class_close(rtc);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 612a83d3ddcc..98d9c87b0d1b 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -368,12 +368,8 @@ int __rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
368 err = rtc_valid_tm(&alarm->time); 368 err = rtc_valid_tm(&alarm->time);
369 369
370done: 370done:
371 if (err) { 371 if (err)
372 dev_warn(&rtc->dev, "invalid alarm value: %d-%d-%d %d:%d:%d\n", 372 dev_warn(&rtc->dev, "invalid alarm value: %ptR\n", &alarm->time);
373 alarm->time.tm_year + 1900, alarm->time.tm_mon + 1,
374 alarm->time.tm_mday, alarm->time.tm_hour, alarm->time.tm_min,
375 alarm->time.tm_sec);
376 }
377 373
378 return err; 374 return err;
379} 375}
@@ -613,26 +609,24 @@ void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode)
613 609
614/** 610/**
615 * rtc_aie_update_irq - AIE mode rtctimer hook 611 * rtc_aie_update_irq - AIE mode rtctimer hook
616 * @private: pointer to the rtc_device 612 * @rtc: pointer to the rtc_device
617 * 613 *
618 * This functions is called when the aie_timer expires. 614 * This functions is called when the aie_timer expires.
619 */ 615 */
620void rtc_aie_update_irq(void *private) 616void rtc_aie_update_irq(struct rtc_device *rtc)
621{ 617{
622 struct rtc_device *rtc = (struct rtc_device *)private;
623 rtc_handle_legacy_irq(rtc, 1, RTC_AF); 618 rtc_handle_legacy_irq(rtc, 1, RTC_AF);
624} 619}
625 620
626 621
627/** 622/**
628 * rtc_uie_update_irq - UIE mode rtctimer hook 623 * rtc_uie_update_irq - UIE mode rtctimer hook
629 * @private: pointer to the rtc_device 624 * @rtc: pointer to the rtc_device
630 * 625 *
631 * This functions is called when the uie_timer expires. 626 * This functions is called when the uie_timer expires.
632 */ 627 */
633void rtc_uie_update_irq(void *private) 628void rtc_uie_update_irq(struct rtc_device *rtc)
634{ 629{
635 struct rtc_device *rtc = (struct rtc_device *)private;
636 rtc_handle_legacy_irq(rtc, 1, RTC_UF); 630 rtc_handle_legacy_irq(rtc, 1, RTC_UF);
637} 631}
638 632
@@ -912,7 +906,7 @@ again:
912 trace_rtc_timer_dequeue(timer); 906 trace_rtc_timer_dequeue(timer);
913 timer->enabled = 0; 907 timer->enabled = 0;
914 if (timer->func) 908 if (timer->func)
915 timer->func(timer->private_data); 909 timer->func(timer->rtc);
916 910
917 trace_rtc_timer_fired(timer); 911 trace_rtc_timer_fired(timer);
918 /* Re-add/fwd periodic timers */ 912 /* Re-add/fwd periodic timers */
@@ -959,16 +953,17 @@ reprogram:
959/* rtc_timer_init - Initializes an rtc_timer 953/* rtc_timer_init - Initializes an rtc_timer
960 * @timer: timer to be intiialized 954 * @timer: timer to be intiialized
961 * @f: function pointer to be called when timer fires 955 * @f: function pointer to be called when timer fires
962 * @data: private data passed to function pointer 956 * @rtc: pointer to the rtc_device
963 * 957 *
964 * Kernel interface to initializing an rtc_timer. 958 * Kernel interface to initializing an rtc_timer.
965 */ 959 */
966void rtc_timer_init(struct rtc_timer *timer, void (*f)(void *p), void *data) 960void rtc_timer_init(struct rtc_timer *timer, void (*f)(struct rtc_device *r),
961 struct rtc_device *rtc)
967{ 962{
968 timerqueue_init(&timer->node); 963 timerqueue_init(&timer->node);
969 timer->enabled = 0; 964 timer->enabled = 0;
970 timer->func = f; 965 timer->func = f;
971 timer->private_data = data; 966 timer->rtc = rtc;
972} 967}
973 968
974/* rtc_timer_start - Sets an rtc_timer to fire in the future 969/* rtc_timer_start - Sets an rtc_timer to fire in the future
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/lib.c
index ef160da84220..ef160da84220 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/lib.c
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 36ab183c42f1..dce518d5e50e 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -12,6 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/nvmem-consumer.h> 13#include <linux/nvmem-consumer.h>
14#include <linux/rtc.h> 14#include <linux/rtc.h>
15#include <linux/slab.h>
15#include <linux/sysfs.h> 16#include <linux/sysfs.h>
16 17
17/* 18/*
@@ -25,11 +26,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj,
25 struct bin_attribute *attr, 26 struct bin_attribute *attr,
26 char *buf, loff_t off, size_t count) 27 char *buf, loff_t off, size_t count)
27{ 28{
28 struct rtc_device *rtc = attr->private;
29
30 dev_warn_once(kobj_to_dev(kobj), nvram_warning); 29 dev_warn_once(kobj_to_dev(kobj), nvram_warning);
31 30
32 return nvmem_device_read(rtc->nvmem, off, count, buf); 31 return nvmem_device_read(attr->private, off, count, buf);
33} 32}
34 33
35static ssize_t 34static ssize_t
@@ -37,26 +36,23 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
37 struct bin_attribute *attr, 36 struct bin_attribute *attr,
38 char *buf, loff_t off, size_t count) 37 char *buf, loff_t off, size_t count)
39{ 38{
40 struct rtc_device *rtc = attr->private;
41
42 dev_warn_once(kobj_to_dev(kobj), nvram_warning); 39 dev_warn_once(kobj_to_dev(kobj), nvram_warning);
43 40
44 return nvmem_device_write(rtc->nvmem, off, count, buf); 41 return nvmem_device_write(attr->private, off, count, buf);
45} 42}
46 43
47static int rtc_nvram_register(struct rtc_device *rtc, size_t size) 44static int rtc_nvram_register(struct rtc_device *rtc,
45 struct nvmem_device *nvmem, size_t size)
48{ 46{
49 int err; 47 int err;
50 48
51 rtc->nvram = devm_kzalloc(rtc->dev.parent, 49 rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL);
52 sizeof(struct bin_attribute),
53 GFP_KERNEL);
54 if (!rtc->nvram) 50 if (!rtc->nvram)
55 return -ENOMEM; 51 return -ENOMEM;
56 52
57 rtc->nvram->attr.name = "nvram"; 53 rtc->nvram->attr.name = "nvram";
58 rtc->nvram->attr.mode = 0644; 54 rtc->nvram->attr.mode = 0644;
59 rtc->nvram->private = rtc; 55 rtc->nvram->private = nvmem;
60 56
61 sysfs_bin_attr_init(rtc->nvram); 57 sysfs_bin_attr_init(rtc->nvram);
62 58
@@ -67,7 +63,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
67 err = sysfs_create_bin_file(&rtc->dev.parent->kobj, 63 err = sysfs_create_bin_file(&rtc->dev.parent->kobj,
68 rtc->nvram); 64 rtc->nvram);
69 if (err) { 65 if (err) {
70 devm_kfree(rtc->dev.parent, rtc->nvram); 66 kfree(rtc->nvram);
71 rtc->nvram = NULL; 67 rtc->nvram = NULL;
72 } 68 }
73 69
@@ -77,6 +73,8 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
77static void rtc_nvram_unregister(struct rtc_device *rtc) 73static void rtc_nvram_unregister(struct rtc_device *rtc)
78{ 74{
79 sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram); 75 sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram);
76 kfree(rtc->nvram);
77 rtc->nvram = NULL;
80} 78}
81 79
82/* 80/*
@@ -85,21 +83,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
85int rtc_nvmem_register(struct rtc_device *rtc, 83int rtc_nvmem_register(struct rtc_device *rtc,
86 struct nvmem_config *nvmem_config) 84 struct nvmem_config *nvmem_config)
87{ 85{
88 if (!IS_ERR_OR_NULL(rtc->nvmem)) 86 struct nvmem_device *nvmem;
89 return -EBUSY;
90 87
91 if (!nvmem_config) 88 if (!nvmem_config)
92 return -ENODEV; 89 return -ENODEV;
93 90
94 nvmem_config->dev = rtc->dev.parent; 91 nvmem_config->dev = rtc->dev.parent;
95 nvmem_config->owner = rtc->owner; 92 nvmem_config->owner = rtc->owner;
96 rtc->nvmem = nvmem_register(nvmem_config); 93 nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
97 if (IS_ERR(rtc->nvmem)) 94 if (IS_ERR(nvmem))
98 return PTR_ERR(rtc->nvmem); 95 return PTR_ERR(nvmem);
99 96
100 /* Register the old ABI */ 97 /* Register the old ABI */
101 if (rtc->nvram_old_abi) 98 if (rtc->nvram_old_abi)
102 rtc_nvram_register(rtc, nvmem_config->size); 99 rtc_nvram_register(rtc, nvmem, nvmem_config->size);
103 100
104 return 0; 101 return 0;
105} 102}
@@ -107,12 +104,7 @@ EXPORT_SYMBOL_GPL(rtc_nvmem_register);
107 104
108void rtc_nvmem_unregister(struct rtc_device *rtc) 105void rtc_nvmem_unregister(struct rtc_device *rtc)
109{ 106{
110 if (IS_ERR_OR_NULL(rtc->nvmem))
111 return;
112
113 /* unregister the old ABI */ 107 /* unregister the old ABI */
114 if (rtc->nvram) 108 if (rtc->nvram)
115 rtc_nvram_unregister(rtc); 109 rtc_nvram_unregister(rtc);
116
117 nvmem_unregister(rtc->nvmem);
118} 110}
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/proc.c
index a9dd9218fae2..4d74e4f4ff30 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/proc.c
@@ -50,41 +50,15 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
50 err = rtc_read_time(rtc, &tm); 50 err = rtc_read_time(rtc, &tm);
51 if (err == 0) { 51 if (err == 0) {
52 seq_printf(seq, 52 seq_printf(seq,
53 "rtc_time\t: %02d:%02d:%02d\n" 53 "rtc_time\t: %ptRt\n"
54 "rtc_date\t: %04d-%02d-%02d\n", 54 "rtc_date\t: %ptRd\n",
55 tm.tm_hour, tm.tm_min, tm.tm_sec, 55 &tm, &tm);
56 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
57 } 56 }
58 57
59 err = rtc_read_alarm(rtc, &alrm); 58 err = rtc_read_alarm(rtc, &alrm);
60 if (err == 0) { 59 if (err == 0) {
61 seq_printf(seq, "alrm_time\t: "); 60 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
62 if ((unsigned int)alrm.time.tm_hour <= 24) 61 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
63 seq_printf(seq, "%02d:", alrm.time.tm_hour);
64 else
65 seq_printf(seq, "**:");
66 if ((unsigned int)alrm.time.tm_min <= 59)
67 seq_printf(seq, "%02d:", alrm.time.tm_min);
68 else
69 seq_printf(seq, "**:");
70 if ((unsigned int)alrm.time.tm_sec <= 59)
71 seq_printf(seq, "%02d\n", alrm.time.tm_sec);
72 else
73 seq_printf(seq, "**\n");
74
75 seq_printf(seq, "alrm_date\t: ");
76 if ((unsigned int)alrm.time.tm_year <= 200)
77 seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
78 else
79 seq_printf(seq, "****-");
80 if ((unsigned int)alrm.time.tm_mon <= 11)
81 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
82 else
83 seq_printf(seq, "**-");
84 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
85 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
86 else
87 seq_printf(seq, "**\n");
88 seq_printf(seq, "alarm_IRQ\t: %s\n", 62 seq_printf(seq, "alarm_IRQ\t: %s\n",
89 alrm.enabled ? "yes" : "no"); 63 alrm.enabled ? "yes" : "no");
90 seq_printf(seq, "alrm_pending\t: %s\n", 64 seq_printf(seq, "alrm_pending\t: %s\n",
diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c
index d8e94edcb0ba..4d24f7288ad7 100644
--- a/drivers/rtc/rtc-abx80x.c
+++ b/drivers/rtc/rtc-abx80x.c
@@ -38,6 +38,7 @@
38 38
39#define ABX8XX_REG_STATUS 0x0f 39#define ABX8XX_REG_STATUS 0x0f
40#define ABX8XX_STATUS_AF BIT(2) 40#define ABX8XX_STATUS_AF BIT(2)
41#define ABX8XX_STATUS_BLF BIT(4)
41#define ABX8XX_STATUS_WDT BIT(6) 42#define ABX8XX_STATUS_WDT BIT(6)
42 43
43#define ABX8XX_REG_CTRL1 0x10 44#define ABX8XX_REG_CTRL1 0x10
@@ -507,12 +508,49 @@ static int abx80x_alarm_irq_enable(struct device *dev, unsigned int enabled)
507 return err; 508 return err;
508} 509}
509 510
511static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
512{
513 struct i2c_client *client = to_i2c_client(dev);
514 int status, tmp;
515
516 switch (cmd) {
517 case RTC_VL_READ:
518 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS);
519 if (status < 0)
520 return status;
521
522 tmp = !!(status & ABX8XX_STATUS_BLF);
523
524 if (copy_to_user((void __user *)arg, &tmp, sizeof(int)))
525 return -EFAULT;
526
527 return 0;
528
529 case RTC_VL_CLR:
530 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS);
531 if (status < 0)
532 return status;
533
534 status &= ~ABX8XX_STATUS_BLF;
535
536 tmp = i2c_smbus_write_byte_data(client, ABX8XX_REG_STATUS, 0);
537 if (tmp < 0)
538 return tmp;
539
540 return 0;
541
542 default:
543 return -ENOIOCTLCMD;
544 }
545}
546
510static const struct rtc_class_ops abx80x_rtc_ops = { 547static const struct rtc_class_ops abx80x_rtc_ops = {
511 .read_time = abx80x_rtc_read_time, 548 .read_time = abx80x_rtc_read_time,
512 .set_time = abx80x_rtc_set_time, 549 .set_time = abx80x_rtc_set_time,
513 .read_alarm = abx80x_read_alarm, 550 .read_alarm = abx80x_read_alarm,
514 .set_alarm = abx80x_set_alarm, 551 .set_alarm = abx80x_set_alarm,
515 .alarm_irq_enable = abx80x_alarm_irq_enable, 552 .alarm_irq_enable = abx80x_alarm_irq_enable,
553 .ioctl = abx80x_ioctl,
516}; 554};
517 555
518static int abx80x_dt_trickle_cfg(struct device_node *np) 556static int abx80x_dt_trickle_cfg(struct device_node *np)
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index caa71d04e989..862b993c3142 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -147,9 +147,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
147 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year); 147 tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
148 tm->tm_year = tm->tm_year - 1900; 148 tm->tm_year = tm->tm_year - 1900;
149 149
150 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 150 dev_dbg(dev, "%s(): %ptR\n", __func__, tm);
151 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
152 tm->tm_hour, tm->tm_min, tm->tm_sec);
153 151
154 return 0; 152 return 0;
155} 153}
@@ -161,9 +159,7 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
161{ 159{
162 unsigned long cr; 160 unsigned long cr;
163 161
164 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 162 dev_dbg(dev, "%s(): %ptR\n", __func__, tm);
165 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
166 tm->tm_hour, tm->tm_min, tm->tm_sec);
167 163
168 wait_for_completion(&at91_rtc_upd_rdy); 164 wait_for_completion(&at91_rtc_upd_rdy);
169 165
@@ -209,8 +205,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
209 alrm->enabled = (at91_rtc_read_imr() & AT91_RTC_ALARM) 205 alrm->enabled = (at91_rtc_read_imr() & AT91_RTC_ALARM)
210 ? 1 : 0; 206 ? 1 : 0;
211 207
212 dev_dbg(dev, "%s(): %02d-%02d %02d:%02d:%02d %sabled\n", __func__, 208 dev_dbg(dev, "%s(): %ptR %sabled\n", __func__, tm,
213 tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,
214 alrm->enabled ? "en" : "dis"); 209 alrm->enabled ? "en" : "dis");
215 210
216 return 0; 211 return 0;
@@ -247,9 +242,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
247 at91_rtc_write_ier(AT91_RTC_ALARM); 242 at91_rtc_write_ier(AT91_RTC_ALARM);
248 } 243 }
249 244
250 dev_dbg(dev, "%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __func__, 245 dev_dbg(dev, "%s(): %ptR\n", __func__, &tm);
251 tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
252 tm.tm_min, tm.tm_sec);
253 246
254 return 0; 247 return 0;
255} 248}
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index ee71e647fd43..1d31c0ae6334 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -124,9 +124,7 @@ static int at91_rtc_readtime(struct device *dev, struct rtc_time *tm)
124 124
125 rtc_time_to_tm(offset + secs, tm); 125 rtc_time_to_tm(offset + secs, tm);
126 126
127 dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readtime", 127 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
128 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
129 tm->tm_hour, tm->tm_min, tm->tm_sec);
130 128
131 return 0; 129 return 0;
132} 130}
@@ -141,9 +139,7 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
141 u32 offset, alarm, mr; 139 u32 offset, alarm, mr;
142 unsigned long secs; 140 unsigned long secs;
143 141
144 dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "settime", 142 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
145 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
146 tm->tm_hour, tm->tm_min, tm->tm_sec);
147 143
148 err = rtc_tm_to_time(tm, &secs); 144 err = rtc_tm_to_time(tm, &secs);
149 if (err != 0) 145 if (err != 0)
@@ -199,9 +195,7 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
199 if (alarm != ALARM_DISABLED && offset != 0) { 195 if (alarm != ALARM_DISABLED && offset != 0) {
200 rtc_time_to_tm(offset + alarm, tm); 196 rtc_time_to_tm(offset + alarm, tm);
201 197
202 dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "readalarm", 198 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
203 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
204 tm->tm_hour, tm->tm_min, tm->tm_sec);
205 199
206 if (rtt_readl(rtc, MR) & AT91_RTT_ALMIEN) 200 if (rtt_readl(rtc, MR) & AT91_RTT_ALMIEN)
207 alrm->enabled = 1; 201 alrm->enabled = 1;
@@ -242,9 +236,7 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
242 if (alrm->enabled) 236 if (alrm->enabled)
243 rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN); 237 rtt_writel(rtc, MR, mr | AT91_RTT_ALMIEN);
244 238
245 dev_dbg(dev, "%s: %4d-%02d-%02d %02d:%02d:%02d\n", "setalarm", 239 dev_dbg(dev, "%s: %ptR\n", __func__, tm);
246 tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour,
247 tm->tm_min, tm->tm_sec);
248 240
249 return 0; 241 return 0;
250} 242}
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 694038208745..1932a4f861d1 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -61,7 +61,7 @@ static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
61 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev); 61 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
62 unsigned long time; 62 unsigned long time;
63 63
64 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA); 64 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
65 65
66 rtc_time_to_tm(time, tm); 66 rtc_time_to_tm(time, tm);
67 return 0; 67 return 0;
diff --git a/drivers/rtc/rtc-imx-sc.c b/drivers/rtc/rtc-imx-sc.c
new file mode 100644
index 000000000000..7ff08544532a
--- /dev/null
+++ b/drivers/rtc/rtc-imx-sc.c
@@ -0,0 +1,91 @@
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP.
4 */
5
6#include <linux/firmware/imx/sci.h>
7#include <linux/module.h>
8#include <linux/of.h>
9#include <linux/platform_device.h>
10#include <linux/rtc.h>
11
12#define IMX_SC_TIMER_FUNC_GET_RTC_SEC1970 9
13#define IMX_SC_TIMER_FUNC_SET_RTC_TIME 6
14
15static struct imx_sc_ipc *rtc_ipc_handle;
16static struct rtc_device *imx_sc_rtc;
17
18struct imx_sc_msg_timer_get_rtc_time {
19 struct imx_sc_rpc_msg hdr;
20 u32 time;
21} __packed;
22
23static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm)
24{
25 struct imx_sc_msg_timer_get_rtc_time msg;
26 struct imx_sc_rpc_msg *hdr = &msg.hdr;
27 int ret;
28
29 hdr->ver = IMX_SC_RPC_VERSION;
30 hdr->svc = IMX_SC_RPC_SVC_TIMER;
31 hdr->func = IMX_SC_TIMER_FUNC_GET_RTC_SEC1970;
32 hdr->size = 1;
33
34 ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
35 if (ret) {
36 dev_err(dev, "read rtc time failed, ret %d\n", ret);
37 return ret;
38 }
39
40 rtc_time_to_tm(msg.time, tm);
41
42 return 0;
43}
44
45static const struct rtc_class_ops imx_sc_rtc_ops = {
46 .read_time = imx_sc_rtc_read_time,
47};
48
49static int imx_sc_rtc_probe(struct platform_device *pdev)
50{
51 int ret;
52
53 ret = imx_scu_get_handle(&rtc_ipc_handle);
54 if (ret)
55 return ret;
56
57 imx_sc_rtc = devm_rtc_allocate_device(&pdev->dev);
58 if (IS_ERR(imx_sc_rtc))
59 return PTR_ERR(imx_sc_rtc);
60
61 imx_sc_rtc->ops = &imx_sc_rtc_ops;
62 imx_sc_rtc->range_min = 0;
63 imx_sc_rtc->range_max = U32_MAX;
64
65 ret = rtc_register_device(imx_sc_rtc);
66 if (ret) {
67 dev_err(&pdev->dev, "failed to register rtc: %d\n", ret);
68 return ret;
69 }
70
71 return 0;
72}
73
74static const struct of_device_id imx_sc_dt_ids[] = {
75 { .compatible = "fsl,imx8qxp-sc-rtc", },
76 {}
77};
78MODULE_DEVICE_TABLE(of, imx_sc_dt_ids);
79
80static struct platform_driver imx_sc_rtc_driver = {
81 .driver = {
82 .name = "imx-sc-rtc",
83 .of_match_table = imx_sc_dt_ids,
84 },
85 .probe = imx_sc_rtc_probe,
86};
87module_platform_driver(imx_sc_rtc_driver);
88
89MODULE_AUTHOR("Anson Huang <Anson.Huang@nxp.com>");
90MODULE_DESCRIPTION("NXP i.MX System Controller RTC Driver");
91MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index ec5ef518a09b..37ab3e1d25f5 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -84,29 +84,13 @@ static int
84isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[], 84isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
85 unsigned len) 85 unsigned len)
86{ 86{
87 u8 reg_addr[1] = { reg };
88 struct i2c_msg msgs[2] = {
89 {
90 .addr = client->addr,
91 .len = sizeof(reg_addr),
92 .buf = reg_addr
93 },
94 {
95 .addr = client->addr,
96 .flags = I2C_M_RD,
97 .len = len,
98 .buf = buf
99 }
100 };
101 int ret; 87 int ret;
102 88
103 WARN_ON(reg > ISL1219_REG_YRT); 89 WARN_ON(reg > ISL1219_REG_YRT);
104 WARN_ON(reg + len > ISL1219_REG_YRT + 1); 90 WARN_ON(reg + len > ISL1219_REG_YRT + 1);
105 91
106 ret = i2c_transfer(client->adapter, msgs, 2); 92 ret = i2c_smbus_read_i2c_block_data(client, reg, len, buf);
107 if (ret > 0) 93 return (ret < 0) ? ret : 0;
108 ret = 0;
109 return ret;
110} 94}
111 95
112/* block write */ 96/* block write */
@@ -114,26 +98,13 @@ static int
114isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], 98isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
115 unsigned len) 99 unsigned len)
116{ 100{
117 u8 i2c_buf[ISL1208_REG_USR2 + 2];
118 struct i2c_msg msgs[1] = {
119 {
120 .addr = client->addr,
121 .len = len + 1,
122 .buf = i2c_buf
123 }
124 };
125 int ret; 101 int ret;
126 102
127 WARN_ON(reg > ISL1219_REG_YRT); 103 WARN_ON(reg > ISL1219_REG_YRT);
128 WARN_ON(reg + len > ISL1219_REG_YRT + 1); 104 WARN_ON(reg + len > ISL1219_REG_YRT + 1);
129 105
130 i2c_buf[0] = reg; 106 ret = i2c_smbus_write_i2c_block_data(client, reg, len, buf);
131 memcpy(&i2c_buf[1], &buf[0], len); 107 return (ret < 0) ? ret : 0;
132
133 ret = i2c_transfer(client->adapter, msgs, 1);
134 if (ret > 0)
135 ret = 0;
136 return ret;
137} 108}
138 109
139/* simple check to see whether we have a isl1208 */ 110/* simple check to see whether we have a isl1208 */
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index a3fb235fea0d..ebf50b1540f2 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -217,7 +217,7 @@ static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm)
217 sizeof(buf), buf); 217 sizeof(buf), buf);
218 if (err < 0) { 218 if (err < 0) {
219 dev_err(&client->dev, "Unable to read date\n"); 219 dev_err(&client->dev, "Unable to read date\n");
220 return -EIO; 220 return err;
221 } 221 }
222 222
223 tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f); 223 tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f);
@@ -274,10 +274,11 @@ static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm)
274 if (flags < 0) 274 if (flags < 0)
275 return flags; 275 return flags;
276 276
277 if (i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS, 277 err = i2c_smbus_write_byte_data(client, M41T80_REG_FLAGS,
278 flags & ~M41T80_FLAGS_OF)) { 278 flags & ~M41T80_FLAGS_OF);
279 if (err < 0) {
279 dev_err(&client->dev, "Unable to write flags register\n"); 280 dev_err(&client->dev, "Unable to write flags register\n");
280 return -EIO; 281 return err;
281 } 282 }
282 283
283 return err; 284 return err;
@@ -287,10 +288,12 @@ static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq)
287{ 288{
288 struct i2c_client *client = to_i2c_client(dev); 289 struct i2c_client *client = to_i2c_client(dev);
289 struct m41t80_data *clientdata = i2c_get_clientdata(client); 290 struct m41t80_data *clientdata = i2c_get_clientdata(client);
290 u8 reg; 291 int reg;
291 292
292 if (clientdata->features & M41T80_FEATURE_BL) { 293 if (clientdata->features & M41T80_FEATURE_BL) {
293 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); 294 reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS);
295 if (reg < 0)
296 return reg;
294 seq_printf(seq, "battery\t\t: %s\n", 297 seq_printf(seq, "battery\t\t: %s\n",
295 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); 298 (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok");
296 } 299 }
@@ -393,7 +396,7 @@ static int m41t80_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
393 alrm->time.tm_min = bcd2bin(alarmvals[3] & 0x7f); 396 alrm->time.tm_min = bcd2bin(alarmvals[3] & 0x7f);
394 alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f); 397 alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f);
395 alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f); 398 alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f);
396 alrm->time.tm_mon = bcd2bin(alarmvals[0] & 0x3f); 399 alrm->time.tm_mon = bcd2bin(alarmvals[0] & 0x3f) - 1;
397 400
398 alrm->enabled = !!(alarmvals[0] & M41T80_ALMON_AFE); 401 alrm->enabled = !!(alarmvals[0] & M41T80_ALMON_AFE);
399 alrm->pending = (flags & M41T80_FLAGS_AF) && alrm->enabled; 402 alrm->pending = (flags & M41T80_FLAGS_AF) && alrm->enabled;
@@ -939,11 +942,7 @@ static int m41t80_probe(struct i2c_client *client,
939 if (m41t80_data->features & M41T80_FEATURE_HT) { 942 if (m41t80_data->features & M41T80_FEATURE_HT) {
940 m41t80_rtc_read_time(&client->dev, &tm); 943 m41t80_rtc_read_time(&client->dev, &tm);
941 dev_info(&client->dev, "HT bit was set!\n"); 944 dev_info(&client->dev, "HT bit was set!\n");
942 dev_info(&client->dev, 945 dev_info(&client->dev, "Power Down at %ptR\n", &tm);
943 "Power Down at %04i-%02i-%02i %02i:%02i:%02i\n",
944 tm.tm_year + 1900,
945 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
946 tm.tm_min, tm.tm_sec);
947 } 946 }
948 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR, 947 rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR,
949 rc & ~M41T80_ALHOUR_HT); 948 rc & ~M41T80_ALHOUR_HT);
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index ac9ca1042889..3c8ad1cdfd7c 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -99,9 +99,7 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
99 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 99 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
100 spin_unlock_irqrestore(&m48t59->lock, flags); 100 spin_unlock_irqrestore(&m48t59->lock, flags);
101 101
102 dev_dbg(dev, "RTC read time %04d-%02d-%02d %02d/%02d/%02d\n", 102 dev_dbg(dev, "RTC read time %ptR\n", tm);
103 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
104 tm->tm_hour, tm->tm_min, tm->tm_sec);
105 return 0; 103 return 0;
106} 104}
107 105
@@ -188,9 +186,7 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
188 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 186 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
189 spin_unlock_irqrestore(&m48t59->lock, flags); 187 spin_unlock_irqrestore(&m48t59->lock, flags);
190 188
191 dev_dbg(dev, "RTC read alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 189 dev_dbg(dev, "RTC read alarm time %ptR\n", tm);
192 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday,
193 tm->tm_hour, tm->tm_min, tm->tm_sec);
194 return rtc_valid_tm(tm); 190 return rtc_valid_tm(tm);
195} 191}
196 192
diff --git a/drivers/rtc/rtc-max6916.c b/drivers/rtc/rtc-max6916.c
index 7e908a490cf6..9d4b407cc4b8 100644
--- a/drivers/rtc/rtc-max6916.c
+++ b/drivers/rtc/rtc-max6916.c
@@ -86,7 +86,7 @@ static int max6916_set_time(struct device *dev, struct rtc_time *dt)
86 if (dt->tm_year < 100 || dt->tm_year > 199) { 86 if (dt->tm_year < 100 || dt->tm_year > 199) {
87 dev_err(&spi->dev, "Year must be between 2000 and 2099. It's %d.\n", 87 dev_err(&spi->dev, "Year must be between 2000 and 2099. It's %d.\n",
88 dt->tm_year + 1900); 88 dt->tm_year + 1900);
89 return -EINVAL; 89 return -EINVAL;
90 } 90 }
91 91
92 buf[0] = MAX6916_CLOCK_BURST & 0x7F; 92 buf[0] = MAX6916_CLOCK_BURST & 0x7F;
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 8a60900d6b8b..4aff349ae301 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -360,7 +360,7 @@ static int max77686_rtc_read_time(struct device *dev, struct rtc_time *tm)
360 360
361out: 361out:
362 mutex_unlock(&info->lock); 362 mutex_unlock(&info->lock);
363 return 0; 363 return ret;
364} 364}
365 365
366static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm) 366static int max77686_rtc_set_time(struct device *dev, struct rtc_time *tm)
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index 08c661a332ec..20e50d9fdf88 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -215,7 +215,7 @@ static int max8997_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
215 215
216out: 216out:
217 mutex_unlock(&info->lock); 217 mutex_unlock(&info->lock);
218 return 0; 218 return ret;
219} 219}
220 220
221static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info) 221static int max8997_rtc_stop_alarm(struct max8997_rtc_info *info)
diff --git a/drivers/rtc/rtc-mcp795.c b/drivers/rtc/rtc-mcp795.c
index 00e11c1b2186..f22a945a3794 100644
--- a/drivers/rtc/rtc-mcp795.c
+++ b/drivers/rtc/rtc-mcp795.c
@@ -233,9 +233,7 @@ static int mcp795_set_time(struct device *dev, struct rtc_time *tim)
233 if (ret) 233 if (ret)
234 return ret; 234 return ret;
235 235
236 dev_dbg(dev, "Set mcp795: %04d-%02d-%02d(%d) %02d:%02d:%02d\n", 236 dev_dbg(dev, "Set mcp795: %ptR\n", tim);
237 tim->tm_year + 1900, tim->tm_mon, tim->tm_mday,
238 tim->tm_wday, tim->tm_hour, tim->tm_min, tim->tm_sec);
239 237
240 return 0; 238 return 0;
241} 239}
@@ -258,9 +256,7 @@ static int mcp795_read_time(struct device *dev, struct rtc_time *tim)
258 tim->tm_mon = bcd2bin(data[5] & 0x1F) - 1; 256 tim->tm_mon = bcd2bin(data[5] & 0x1F) - 1;
259 tim->tm_year = bcd2bin(data[6]) + 100; /* Assume we are in 20xx */ 257 tim->tm_year = bcd2bin(data[6]) + 100; /* Assume we are in 20xx */
260 258
261 dev_dbg(dev, "Read from mcp795: %04d-%02d-%02d(%d) %02d:%02d:%02d\n", 259 dev_dbg(dev, "Read from mcp795: %ptR\n", tim);
262 tim->tm_year + 1900, tim->tm_mon, tim->tm_mday,
263 tim->tm_wday, tim->tm_hour, tim->tm_min, tim->tm_sec);
264 260
265 return 0; 261 return 0;
266} 262}
@@ -319,9 +315,8 @@ static int mcp795_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
319 return ret; 315 return ret;
320 dev_dbg(dev, "Alarm IRQ armed\n"); 316 dev_dbg(dev, "Alarm IRQ armed\n");
321 } 317 }
322 dev_dbg(dev, "Set alarm: %02d-%02d(%d) %02d:%02d:%02d\n", 318 dev_dbg(dev, "Set alarm: %ptRdr(%d) %ptRt\n",
323 alm->time.tm_mon, alm->time.tm_mday, alm->time.tm_wday, 319 &alm->time, alm->time.tm_wday, &alm->time);
324 alm->time.tm_hour, alm->time.tm_min, alm->time.tm_sec);
325 return 0; 320 return 0;
326} 321}
327 322
@@ -345,9 +340,8 @@ static int mcp795_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
345 alm->time.tm_isdst = -1; 340 alm->time.tm_isdst = -1;
346 alm->time.tm_yday = -1; 341 alm->time.tm_yday = -1;
347 342
348 dev_dbg(dev, "Read alarm: %02d-%02d(%d) %02d:%02d:%02d\n", 343 dev_dbg(dev, "Read alarm: %ptRdr(%d) %ptRt\n",
349 alm->time.tm_mon, alm->time.tm_mday, alm->time.tm_wday, 344 &alm->time, alm->time.tm_wday, &alm->time);
350 alm->time.tm_hour, alm->time.tm_min, alm->time.tm_sec);
351 return 0; 345 return 0;
352} 346}
353 347
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 320b4a520eb3..bbff0e2deb84 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -566,9 +566,7 @@ static const struct pinctrl_ops rtc_pinctrl_ops = {
566 .dt_free_map = pinconf_generic_dt_free_map, 566 .dt_free_map = pinconf_generic_dt_free_map,
567}; 567};
568 568
569enum rtc_pin_config_param { 569#define PIN_CONFIG_ACTIVE_HIGH (PIN_CONFIG_END + 1)
570 PIN_CONFIG_ACTIVE_HIGH = PIN_CONFIG_END + 1,
571};
572 570
573static const struct pinconf_generic_params rtc_params[] = { 571static const struct pinconf_generic_params rtc_params[] = {
574 {"ti,active-high", PIN_CONFIG_ACTIVE_HIGH, 0}, 572 {"ti,active-high", PIN_CONFIG_ACTIVE_HIGH, 0},
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index e5222c5d8223..39da8b214275 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -453,6 +453,7 @@ static int pcf2123_remove(struct spi_device *spi)
453#ifdef CONFIG_OF 453#ifdef CONFIG_OF
454static const struct of_device_id pcf2123_dt_ids[] = { 454static const struct of_device_id pcf2123_dt_ids[] = {
455 { .compatible = "nxp,rtc-pcf2123", }, 455 { .compatible = "nxp,rtc-pcf2123", },
456 { .compatible = "microcrystal,rv2123", },
456 { /* sentinel */ } 457 { /* sentinel */ }
457}; 458};
458MODULE_DEVICE_TABLE(of, pcf2123_dt_ids); 459MODULE_DEVICE_TABLE(of, pcf2123_dt_ids);
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index ef72b0c389d7..0eb05b1d0b94 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -131,9 +131,7 @@ static int pcf50633_rtc_read_time(struct device *dev, struct rtc_time *tm)
131 131
132 pcf2rtc_time(tm, &pcf_tm); 132 pcf2rtc_time(tm, &pcf_tm);
133 133
134 dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n", 134 dev_dbg(dev, "RTC_TIME: %ptRr\n", tm);
135 tm->tm_mday, tm->tm_mon, tm->tm_year,
136 tm->tm_hour, tm->tm_min, tm->tm_sec);
137 135
138 return 0; 136 return 0;
139} 137}
@@ -146,9 +144,7 @@ static int pcf50633_rtc_set_time(struct device *dev, struct rtc_time *tm)
146 144
147 rtc = dev_get_drvdata(dev); 145 rtc = dev_get_drvdata(dev);
148 146
149 dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n", 147 dev_dbg(dev, "RTC_TIME: %ptRr\n", tm);
150 tm->tm_mday, tm->tm_mon, tm->tm_year,
151 tm->tm_hour, tm->tm_min, tm->tm_sec);
152 148
153 rtc2pcf_time(&pcf_tm, tm); 149 rtc2pcf_time(&pcf_tm, tm);
154 150
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 453615f8ac9a..3fcd2cbafc84 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -85,6 +85,18 @@ static int pcf8523_write(struct i2c_client *client, u8 reg, u8 value)
85 return 0; 85 return 0;
86} 86}
87 87
88static int pcf8523_voltage_low(struct i2c_client *client)
89{
90 u8 value;
91 int err;
92
93 err = pcf8523_read(client, REG_CONTROL3, &value);
94 if (err < 0)
95 return err;
96
97 return !!(value & REG_CONTROL3_BLF);
98}
99
88static int pcf8523_select_capacitance(struct i2c_client *client, bool high) 100static int pcf8523_select_capacitance(struct i2c_client *client, bool high)
89{ 101{
90 u8 value; 102 u8 value;
@@ -167,6 +179,14 @@ static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
167 struct i2c_msg msgs[2]; 179 struct i2c_msg msgs[2];
168 int err; 180 int err;
169 181
182 err = pcf8523_voltage_low(client);
183 if (err < 0) {
184 return err;
185 } else if (err > 0) {
186 dev_err(dev, "low voltage detected, time is unreliable\n");
187 return -EINVAL;
188 }
189
170 msgs[0].addr = client->addr; 190 msgs[0].addr = client->addr;
171 msgs[0].flags = 0; 191 msgs[0].flags = 0;
172 msgs[0].len = 1; 192 msgs[0].len = 1;
@@ -251,17 +271,13 @@ static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd,
251 unsigned long arg) 271 unsigned long arg)
252{ 272{
253 struct i2c_client *client = to_i2c_client(dev); 273 struct i2c_client *client = to_i2c_client(dev);
254 u8 value; 274 int ret;
255 int ret = 0, err;
256 275
257 switch (cmd) { 276 switch (cmd) {
258 case RTC_VL_READ: 277 case RTC_VL_READ:
259 err = pcf8523_read(client, REG_CONTROL3, &value); 278 ret = pcf8523_voltage_low(client);
260 if (err < 0) 279 if (ret < 0)
261 return err; 280 return ret;
262
263 if (value & REG_CONTROL3_BLF)
264 ret = 1;
265 281
266 if (copy_to_user((void __user *)arg, &ret, sizeof(int))) 282 if (copy_to_user((void __user *)arg, &ret, sizeof(int)))
267 return -EFAULT; 283 return -EFAULT;
diff --git a/drivers/rtc/rtc-pcf85363.c b/drivers/rtc/rtc-pcf85363.c
index c04a1edcd571..a3988079f60a 100644
--- a/drivers/rtc/rtc-pcf85363.c
+++ b/drivers/rtc/rtc-pcf85363.c
@@ -120,6 +120,11 @@ struct pcf85363 {
120 struct regmap *regmap; 120 struct regmap *regmap;
121}; 121};
122 122
123struct pcf85x63_config {
124 struct regmap_config regmap;
125 unsigned int num_nvram;
126};
127
123static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm) 128static int pcf85363_rtc_read_time(struct device *dev, struct rtc_time *tm)
124{ 129{
125 struct pcf85363 *pcf85363 = dev_get_drvdata(dev); 130 struct pcf85363 *pcf85363 = dev_get_drvdata(dev);
@@ -311,25 +316,75 @@ static int pcf85363_nvram_write(void *priv, unsigned int offset, void *val,
311 val, bytes); 316 val, bytes);
312} 317}
313 318
314static const struct regmap_config regmap_config = { 319static int pcf85x63_nvram_read(void *priv, unsigned int offset, void *val,
315 .reg_bits = 8, 320 size_t bytes)
316 .val_bits = 8, 321{
317 .max_register = 0x7f, 322 struct pcf85363 *pcf85363 = priv;
323 unsigned int tmp_val;
324 int ret;
325
326 ret = regmap_read(pcf85363->regmap, CTRL_RAMBYTE, &tmp_val);
327 (*(unsigned char *) val) = (unsigned char) tmp_val;
328
329 return ret;
330}
331
332static int pcf85x63_nvram_write(void *priv, unsigned int offset, void *val,
333 size_t bytes)
334{
335 struct pcf85363 *pcf85363 = priv;
336 unsigned char tmp_val;
337
338 tmp_val = *((unsigned char *)val);
339 return regmap_write(pcf85363->regmap, CTRL_RAMBYTE,
340 (unsigned int)tmp_val);
341}
342
343static const struct pcf85x63_config pcf_85263_config = {
344 .regmap = {
345 .reg_bits = 8,
346 .val_bits = 8,
347 .max_register = 0x2f,
348 },
349 .num_nvram = 1
350};
351
352static const struct pcf85x63_config pcf_85363_config = {
353 .regmap = {
354 .reg_bits = 8,
355 .val_bits = 8,
356 .max_register = 0x7f,
357 },
358 .num_nvram = 2
318}; 359};
319 360
320static int pcf85363_probe(struct i2c_client *client, 361static int pcf85363_probe(struct i2c_client *client,
321 const struct i2c_device_id *id) 362 const struct i2c_device_id *id)
322{ 363{
323 struct pcf85363 *pcf85363; 364 struct pcf85363 *pcf85363;
324 struct nvmem_config nvmem_cfg = { 365 const struct pcf85x63_config *config = &pcf_85363_config;
325 .name = "pcf85363-", 366 const void *data = of_device_get_match_data(&client->dev);
326 .word_size = 1, 367 static struct nvmem_config nvmem_cfg[] = {
327 .stride = 1, 368 {
328 .size = NVRAM_SIZE, 369 .name = "pcf85x63-",
329 .reg_read = pcf85363_nvram_read, 370 .word_size = 1,
330 .reg_write = pcf85363_nvram_write, 371 .stride = 1,
372 .size = 1,
373 .reg_read = pcf85x63_nvram_read,
374 .reg_write = pcf85x63_nvram_write,
375 }, {
376 .name = "pcf85363-",
377 .word_size = 1,
378 .stride = 1,
379 .size = NVRAM_SIZE,
380 .reg_read = pcf85363_nvram_read,
381 .reg_write = pcf85363_nvram_write,
382 },
331 }; 383 };
332 int ret; 384 int ret, i;
385
386 if (data)
387 config = data;
333 388
334 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 389 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
335 return -ENODEV; 390 return -ENODEV;
@@ -339,7 +394,7 @@ static int pcf85363_probe(struct i2c_client *client,
339 if (!pcf85363) 394 if (!pcf85363)
340 return -ENOMEM; 395 return -ENOMEM;
341 396
342 pcf85363->regmap = devm_regmap_init_i2c(client, &regmap_config); 397 pcf85363->regmap = devm_regmap_init_i2c(client, &config->regmap);
343 if (IS_ERR(pcf85363->regmap)) { 398 if (IS_ERR(pcf85363->regmap)) {
344 dev_err(&client->dev, "regmap allocation failed\n"); 399 dev_err(&client->dev, "regmap allocation failed\n");
345 return PTR_ERR(pcf85363->regmap); 400 return PTR_ERR(pcf85363->regmap);
@@ -370,15 +425,18 @@ static int pcf85363_probe(struct i2c_client *client,
370 425
371 ret = rtc_register_device(pcf85363->rtc); 426 ret = rtc_register_device(pcf85363->rtc);
372 427
373 nvmem_cfg.priv = pcf85363; 428 for (i = 0; i < config->num_nvram; i++) {
374 rtc_nvmem_register(pcf85363->rtc, &nvmem_cfg); 429 nvmem_cfg[i].priv = pcf85363;
430 rtc_nvmem_register(pcf85363->rtc, &nvmem_cfg[i]);
431 }
375 432
376 return ret; 433 return ret;
377} 434}
378 435
379static const struct of_device_id dev_ids[] = { 436static const struct of_device_id dev_ids[] = {
380 { .compatible = "nxp,pcf85363" }, 437 { .compatible = "nxp,pcf85263", .data = &pcf_85263_config },
381 {} 438 { .compatible = "nxp,pcf85363", .data = &pcf_85363_config },
439 { /* sentinel */ }
382}; 440};
383MODULE_DEVICE_TABLE(of, dev_ids); 441MODULE_DEVICE_TABLE(of, dev_ids);
384 442
@@ -393,5 +451,5 @@ static struct i2c_driver pcf85363_driver = {
393module_i2c_driver(pcf85363_driver); 451module_i2c_driver(pcf85363_driver);
394 452
395MODULE_AUTHOR("Eric Nelson"); 453MODULE_AUTHOR("Eric Nelson");
396MODULE_DESCRIPTION("pcf85363 I2C RTC driver"); 454MODULE_DESCRIPTION("pcf85263/pcf85363 I2C RTC driver");
397MODULE_LICENSE("GPL"); 455MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c
index 3c08eab4f1a8..d7ef0a6f8931 100644
--- a/drivers/rtc/rtc-pic32.c
+++ b/drivers/rtc/rtc-pic32.c
@@ -170,9 +170,7 @@ static int pic32_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
170 170
171 rtc_tm->tm_year += 100; 171 rtc_tm->tm_year += 100;
172 172
173 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n", 173 dev_dbg(dev, "read time %ptR\n", rtc_tm);
174 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
175 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
176 174
177 clk_disable(pdata->clk); 175 clk_disable(pdata->clk);
178 return 0; 176 return 0;
@@ -184,9 +182,7 @@ static int pic32_rtc_settime(struct device *dev, struct rtc_time *tm)
184 void __iomem *base = pdata->reg_base; 182 void __iomem *base = pdata->reg_base;
185 int year = tm->tm_year - 100; 183 int year = tm->tm_year - 100;
186 184
187 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n", 185 dev_dbg(dev, "set time %ptR\n", tm);
188 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
189 tm->tm_hour, tm->tm_min, tm->tm_sec);
190 186
191 if (year < 0 || year >= 100) { 187 if (year < 0 || year >= 100) {
192 dev_err(dev, "rtc only supports 100 years\n"); 188 dev_err(dev, "rtc only supports 100 years\n");
@@ -224,10 +220,7 @@ static int pic32_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
224 220
225 alrm->enabled = (alm_en & PIC32_RTCALRM_ALRMEN) ? 1 : 0; 221 alrm->enabled = (alm_en & PIC32_RTCALRM_ALRMEN) ? 1 : 0;
226 222
227 dev_dbg(dev, "getalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 223 dev_dbg(dev, "getalarm: %d, %ptR\n", alm_en, alm_tm);
228 alm_en,
229 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
230 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
231 224
232 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 225 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
233 alm_tm->tm_min = bcd2bin(alm_tm->tm_min); 226 alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
@@ -247,10 +240,7 @@ static int pic32_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
247 void __iomem *base = pdata->reg_base; 240 void __iomem *base = pdata->reg_base;
248 241
249 clk_enable(pdata->clk); 242 clk_enable(pdata->clk);
250 dev_dbg(dev, "setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 243 dev_dbg(dev, "setalarm: %d, %ptR\n", alrm->enabled, tm);
251 alrm->enabled,
252 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
253 tm->tm_hour, tm->tm_min, tm->tm_sec);
254 244
255 writel(0x00, base + PIC32_ALRMTIME); 245 writel(0x00, base + PIC32_ALRMTIME);
256 writel(0x00, base + PIC32_ALRMDATE); 246 writel(0x00, base + PIC32_ALRMDATE);
diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
index 29358a045925..1074e3dbfc1d 100644
--- a/drivers/rtc/rtc-pm8xxx.c
+++ b/drivers/rtc/rtc-pm8xxx.c
@@ -217,9 +217,7 @@ static int pm8xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
217 217
218 rtc_time_to_tm(secs, tm); 218 rtc_time_to_tm(secs, tm);
219 219
220 dev_dbg(dev, "secs = %lu, h:m:s == %d:%d:%d, d/m/y = %d/%d/%d\n", 220 dev_dbg(dev, "secs = %lu, h:m:s == %ptRt, y-m-d = %ptRdr\n", secs, tm, tm);
221 secs, tm->tm_hour, tm->tm_min, tm->tm_sec,
222 tm->tm_mday, tm->tm_mon, tm->tm_year);
223 221
224 return 0; 222 return 0;
225} 223}
@@ -264,10 +262,8 @@ static int pm8xxx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
264 goto rtc_rw_fail; 262 goto rtc_rw_fail;
265 } 263 }
266 264
267 dev_dbg(dev, "Alarm Set for h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n", 265 dev_dbg(dev, "Alarm Set for h:m:s=%ptRt, y-m-d=%ptRdr\n",
268 alarm->time.tm_hour, alarm->time.tm_min, 266 &alarm->time, &alarm->time);
269 alarm->time.tm_sec, alarm->time.tm_mday,
270 alarm->time.tm_mon, alarm->time.tm_year);
271rtc_rw_fail: 267rtc_rw_fail:
272 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags); 268 spin_unlock_irqrestore(&rtc_dd->ctrl_reg_lock, irq_flags);
273 return rc; 269 return rc;
@@ -298,10 +294,8 @@ static int pm8xxx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
298 return rc; 294 return rc;
299 } 295 }
300 296
301 dev_dbg(dev, "Alarm set for - h:r:s=%d:%d:%d, d/m/y=%d/%d/%d\n", 297 dev_dbg(dev, "Alarm set for - h:m:s=%ptRt, y-m-d=%ptRdr\n",
302 alarm->time.tm_hour, alarm->time.tm_min, 298 &alarm->time, &alarm->time);
303 alarm->time.tm_sec, alarm->time.tm_mday,
304 alarm->time.tm_mon, alarm->time.tm_year);
305 299
306 return 0; 300 return 0;
307} 301}
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 9e83be32ff43..f77ef282f013 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -90,9 +90,7 @@ static int puv3_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
90{ 90{
91 rtc_time_to_tm(readl(RTC_RCNR), rtc_tm); 91 rtc_time_to_tm(readl(RTC_RCNR), rtc_tm);
92 92
93 dev_dbg(dev, "read time %02x.%02x.%02x %02x/%02x/%02x\n", 93 dev_dbg(dev, "read time %ptRr\n", rtc_tm);
94 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
95 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
96 94
97 return 0; 95 return 0;
98} 96}
@@ -101,9 +99,7 @@ static int puv3_rtc_settime(struct device *dev, struct rtc_time *tm)
101{ 99{
102 unsigned long rtc_count = 0; 100 unsigned long rtc_count = 0;
103 101
104 dev_dbg(dev, "set time %02d.%02d.%02d %02d/%02d/%02d\n", 102 dev_dbg(dev, "set time %ptRr\n", tm);
105 tm->tm_year, tm->tm_mon, tm->tm_mday,
106 tm->tm_hour, tm->tm_min, tm->tm_sec);
107 103
108 rtc_tm_to_time(tm, &rtc_count); 104 rtc_tm_to_time(tm, &rtc_count);
109 writel(rtc_count, RTC_RCNR); 105 writel(rtc_count, RTC_RCNR);
@@ -119,10 +115,7 @@ static int puv3_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
119 115
120 alrm->enabled = readl(RTC_RTSR) & RTC_RTSR_ALE; 116 alrm->enabled = readl(RTC_RTSR) & RTC_RTSR_ALE;
121 117
122 dev_dbg(dev, "read alarm %02x %02x.%02x.%02x %02x/%02x/%02x\n", 118 dev_dbg(dev, "read alarm: %d, %ptRr\n", alrm->enabled, alm_tm);
123 alrm->enabled,
124 alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
125 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
126 119
127 return 0; 120 return 0;
128} 121}
@@ -132,10 +125,7 @@ static int puv3_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
132 struct rtc_time *tm = &alrm->time; 125 struct rtc_time *tm = &alrm->time;
133 unsigned long rtcalarm_count = 0; 126 unsigned long rtcalarm_count = 0;
134 127
135 dev_dbg(dev, "puv3_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02x\n", 128 dev_dbg(dev, "set alarm: %d, %ptRr\n", alrm->enabled, tm);
136 alrm->enabled,
137 tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff,
138 tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);
139 129
140 rtc_tm_to_time(tm, &rtcalarm_count); 130 rtc_tm_to_time(tm, &rtcalarm_count);
141 writel(rtcalarm_count, RTC_RTAR); 131 writel(rtcalarm_count, RTC_RTAR);
diff --git a/drivers/rtc/rtc-rk808.c b/drivers/rtc/rtc-rk808.c
index 739c0d42e835..1fb864d4ef83 100644
--- a/drivers/rtc/rtc-rk808.c
+++ b/drivers/rtc/rtc-rk808.c
@@ -138,9 +138,7 @@ static int rk808_rtc_readtime(struct device *dev, struct rtc_time *tm)
138 tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 100; 138 tm->tm_year = (bcd2bin(rtc_data[5] & YEARS_REG_MSK)) + 100;
139 tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK); 139 tm->tm_wday = bcd2bin(rtc_data[6] & WEEKS_REG_MSK);
140 rockchip_to_gregorian(tm); 140 rockchip_to_gregorian(tm);
141 dev_dbg(dev, "RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", 141 dev_dbg(dev, "RTC date/time %ptRd(%d) %ptRt\n", tm, tm->tm_wday, tm);
142 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
143 tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
144 142
145 return ret; 143 return ret;
146} 144}
@@ -153,9 +151,7 @@ static int rk808_rtc_set_time(struct device *dev, struct rtc_time *tm)
153 u8 rtc_data[NUM_TIME_REGS]; 151 u8 rtc_data[NUM_TIME_REGS];
154 int ret; 152 int ret;
155 153
156 dev_dbg(dev, "set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", 154 dev_dbg(dev, "set RTC date/time %ptRd(%d) %ptRt\n", tm, tm->tm_wday, tm);
157 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
158 tm->tm_wday, tm->tm_hour, tm->tm_min, tm->tm_sec);
159 gregorian_to_rockchip(tm); 155 gregorian_to_rockchip(tm);
160 rtc_data[0] = bin2bcd(tm->tm_sec); 156 rtc_data[0] = bin2bcd(tm->tm_sec);
161 rtc_data[1] = bin2bcd(tm->tm_min); 157 rtc_data[1] = bin2bcd(tm->tm_min);
@@ -216,10 +212,8 @@ static int rk808_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
216 return ret; 212 return ret;
217 } 213 }
218 214
219 dev_dbg(dev, "alrm read RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", 215 dev_dbg(dev, "alrm read RTC date/time %ptRd(%d) %ptRt\n",
220 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, 216 &alrm->time, alrm->time.tm_wday, &alrm->time);
221 alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour,
222 alrm->time.tm_min, alrm->time.tm_sec);
223 217
224 alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0; 218 alrm->enabled = (int_reg & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M) ? 1 : 0;
225 219
@@ -261,10 +255,8 @@ static int rk808_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
261 dev_err(dev, "Failed to stop alarm: %d\n", ret); 255 dev_err(dev, "Failed to stop alarm: %d\n", ret);
262 return ret; 256 return ret;
263 } 257 }
264 dev_dbg(dev, "alrm set RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n", 258 dev_dbg(dev, "alrm set RTC date/time %ptRd(%d) %ptRt\n",
265 1900 + alrm->time.tm_year, alrm->time.tm_mon + 1, 259 &alrm->time, alrm->time.tm_wday, &alrm->time);
266 alrm->time.tm_mday, alrm->time.tm_wday, alrm->time.tm_hour,
267 alrm->time.tm_min, alrm->time.tm_sec);
268 260
269 gregorian_to_rockchip(&alrm->time); 261 gregorian_to_rockchip(&alrm->time);
270 alrm_data[0] = bin2bcd(alrm->time.tm_sec); 262 alrm_data[0] = bin2bcd(alrm->time.tm_sec);
@@ -400,7 +392,7 @@ static int rk808_rtc_probe(struct platform_device *pdev)
400 if (ret) { 392 if (ret) {
401 dev_err(&pdev->dev, 393 dev_err(&pdev->dev,
402 "Failed to write RTC status: %d\n", ret); 394 "Failed to write RTC status: %d\n", ret);
403 return ret; 395 return ret;
404 } 396 }
405 397
406 device_init_wakeup(&pdev->dev, 1); 398 device_init_wakeup(&pdev->dev, 1);
diff --git a/drivers/rtc/rtc-rx6110.c b/drivers/rtc/rtc-rx6110.c
index 8e322d884cc2..5899ca368d59 100644
--- a/drivers/rtc/rtc-rx6110.c
+++ b/drivers/rtc/rtc-rx6110.c
@@ -114,9 +114,7 @@ struct rx6110_data {
114 */ 114 */
115static int rx6110_rtc_tm_to_data(struct rtc_time *tm, u8 *data) 115static int rx6110_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
116{ 116{
117 pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 117 pr_debug("%s: date %ptRr\n", __func__, tm);
118 tm->tm_sec, tm->tm_min, tm->tm_hour,
119 tm->tm_mday, tm->tm_mon, tm->tm_year);
120 118
121 /* 119 /*
122 * The year in the RTC is a value between 0 and 99. 120 * The year in the RTC is a value between 0 and 99.
@@ -154,9 +152,7 @@ static int rx6110_data_to_rtc_tm(u8 *data, struct rtc_time *tm)
154 tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1; 152 tm->tm_mon = bcd2bin(data[RTC_MONTH] & 0x1f) - 1;
155 tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100; 153 tm->tm_year = bcd2bin(data[RTC_YEAR]) + 100;
156 154
157 pr_debug("%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 155 pr_debug("%s: date %ptRr\n", __func__, tm);
158 tm->tm_sec, tm->tm_min, tm->tm_hour,
159 tm->tm_mday, tm->tm_mon, tm->tm_year);
160 156
161 /* 157 /*
162 * The year in the RTC is a value between 0 and 99. 158 * The year in the RTC is a value between 0 and 99.
@@ -248,9 +244,7 @@ static int rx6110_get_time(struct device *dev, struct rtc_time *tm)
248 if (ret) 244 if (ret)
249 return ret; 245 return ret;
250 246
251 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 247 dev_dbg(dev, "%s: date %ptRr\n", __func__, tm);
252 tm->tm_sec, tm->tm_min, tm->tm_hour,
253 tm->tm_mday, tm->tm_mon, tm->tm_year);
254 248
255 return 0; 249 return 0;
256} 250}
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index 41127adf5765..41de38acc570 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -193,10 +193,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
193 if (err) 193 if (err)
194 return err; 194 return err;
195 195
196 dev_dbg(dev, "%s: read 0x%02x 0x%02x " 196 dev_dbg(dev, "%s: read %7ph\n", __func__, date);
197 "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", __func__,
198 date[0], date[1], date[2], date[3], date[4],
199 date[5], date[6]);
200 197
201 dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f); 198 dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f);
202 dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f); 199 dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f);
@@ -210,9 +207,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
210 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1; 207 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1;
211 dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]) + 100; 208 dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]) + 100;
212 209
213 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 210 dev_dbg(dev, "%s: date %ptRr\n", __func__, dt);
214 dt->tm_sec, dt->tm_min, dt->tm_hour,
215 dt->tm_mday, dt->tm_mon, dt->tm_year);
216 211
217 return 0; 212 return 0;
218} 213}
@@ -243,10 +238,7 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
243 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1); 238 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1);
244 date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year - 100); 239 date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year - 100);
245 240
246 dev_dbg(dev, 241 dev_dbg(dev, "%s: write %7ph\n", __func__, date);
247 "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
248 __func__,
249 date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
250 242
251 ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date); 243 ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
252 if (ret < 0) 244 if (ret < 0)
@@ -319,10 +311,7 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
319 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12 311 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12
320 + (ald[1] & 0x20 ? 12 : 0); 312 + (ald[1] & 0x20 ? 12 : 0);
321 313
322 dev_dbg(dev, "%s: date: %ds %dm %dh %dmd %dm %dy\n", 314 dev_dbg(dev, "%s: date: %ptRr\n", __func__, t);
323 __func__,
324 t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
325 t->time.tm_mday, t->time.tm_mon, t->time.tm_year);
326 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE); 315 t->enabled = !!(rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE);
327 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled; 316 t->pending = (ctrl2 & RX8025_BIT_CTRL2_DAFG) && t->enabled;
328 317
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 75c8c5033e08..04c68178c42d 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -225,13 +225,9 @@ retry_get_time:
225 s3c_rtc_disable_clk(info); 225 s3c_rtc_disable_clk(info);
226 226
227 rtc_tm->tm_year += 100; 227 rtc_tm->tm_year += 100;
228
229 dev_dbg(dev, "read time %04d.%02d.%02d %02d:%02d:%02d\n",
230 1900 + rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
231 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
232
233 rtc_tm->tm_mon -= 1; 228 rtc_tm->tm_mon -= 1;
234 229
230 dev_dbg(dev, "read time %ptR\n", rtc_tm);
235 return 0; 231 return 0;
236} 232}
237 233
@@ -241,9 +237,7 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
241 int year = tm->tm_year - 100; 237 int year = tm->tm_year - 100;
242 int ret; 238 int ret;
243 239
244 dev_dbg(dev, "set time %04d.%02d.%02d %02d:%02d:%02d\n", 240 dev_dbg(dev, "set time %ptR\n", tm);
245 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
246 tm->tm_hour, tm->tm_min, tm->tm_sec);
247 241
248 /* we get around y2k by simply not supporting it */ 242 /* we get around y2k by simply not supporting it */
249 243
@@ -292,10 +286,7 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
292 286
293 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0; 287 alrm->enabled = (alm_en & S3C2410_RTCALM_ALMEN) ? 1 : 0;
294 288
295 dev_dbg(dev, "read alarm %d, %04d.%02d.%02d %02d:%02d:%02d\n", 289 dev_dbg(dev, "read alarm %d, %ptR\n", alm_en, alm_tm);
296 alm_en,
297 1900 + alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday,
298 alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);
299 290
300 /* decode the alarm enable field */ 291 /* decode the alarm enable field */
301 if (alm_en & S3C2410_RTCALM_SECEN) 292 if (alm_en & S3C2410_RTCALM_SECEN)
@@ -327,12 +318,8 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
327 struct rtc_time *tm = &alrm->time; 318 struct rtc_time *tm = &alrm->time;
328 unsigned int alrm_en; 319 unsigned int alrm_en;
329 int ret; 320 int ret;
330 int year = tm->tm_year - 100;
331 321
332 dev_dbg(dev, "s3c_rtc_setalarm: %d, %04d.%02d.%02d %02d:%02d:%02d\n", 322 dev_dbg(dev, "s3c_rtc_setalarm: %d, %ptR\n", alrm->enabled, tm);
333 alrm->enabled,
334 1900 + tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
335 tm->tm_hour, tm->tm_min, tm->tm_sec);
336 323
337 ret = s3c_rtc_enable_clk(info); 324 ret = s3c_rtc_enable_clk(info);
338 if (ret) 325 if (ret)
@@ -356,11 +343,6 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
356 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR); 343 writeb(bin2bcd(tm->tm_hour), info->base + S3C2410_ALMHOUR);
357 } 344 }
358 345
359 if (year < 100 && year >= 0) {
360 alrm_en |= S3C2410_RTCALM_YEAREN;
361 writeb(bin2bcd(year), info->base + S3C2410_ALMYEAR);
362 }
363
364 if (tm->tm_mon < 12 && tm->tm_mon >= 0) { 346 if (tm->tm_mon < 12 && tm->tm_mon >= 0) {
365 alrm_en |= S3C2410_RTCALM_MONEN; 347 alrm_en |= S3C2410_RTCALM_MONEN;
366 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON); 348 writeb(bin2bcd(tm->tm_mon + 1), info->base + S3C2410_ALMMON);
diff --git a/drivers/rtc/rtc-s5m.c b/drivers/rtc/rtc-s5m.c
index 6495f84f7428..c7f1bf823ea0 100644
--- a/drivers/rtc/rtc-s5m.c
+++ b/drivers/rtc/rtc-s5m.c
@@ -406,9 +406,7 @@ static int s5m_rtc_read_time(struct device *dev, struct rtc_time *tm)
406 return -EINVAL; 406 return -EINVAL;
407 } 407 }
408 408
409 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 409 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, tm, tm->tm_wday);
410 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
411 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
412 410
413 return 0; 411 return 0;
414} 412}
@@ -436,9 +434,7 @@ static int s5m_rtc_set_time(struct device *dev, struct rtc_time *tm)
436 if (ret < 0) 434 if (ret < 0)
437 return ret; 435 return ret;
438 436
439 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 437 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, tm, tm->tm_wday);
440 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday,
441 tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_wday);
442 438
443 ret = regmap_raw_write(info->regmap, info->regs->time, data, 439 ret = regmap_raw_write(info->regmap, info->regs->time, data,
444 info->regs->regs_count); 440 info->regs->regs_count);
@@ -490,11 +486,7 @@ static int s5m_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
490 return -EINVAL; 486 return -EINVAL;
491 } 487 }
492 488
493 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 489 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, &alrm->time, alrm->time.tm_wday);
494 1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
495 alrm->time.tm_mday, alrm->time.tm_hour,
496 alrm->time.tm_min, alrm->time.tm_sec,
497 alrm->time.tm_wday);
498 490
499 ret = s5m_check_peding_alarm_interrupt(info, alrm); 491 ret = s5m_check_peding_alarm_interrupt(info, alrm);
500 492
@@ -513,9 +505,7 @@ static int s5m_rtc_stop_alarm(struct s5m_rtc_info *info)
513 return ret; 505 return ret;
514 506
515 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode); 507 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
516 dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 508 dev_dbg(info->dev, "%s: %ptR(%d)\n", __func__, &tm, tm.tm_wday);
517 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
518 tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
519 509
520 switch (info->device_type) { 510 switch (info->device_type) {
521 case S5M8763X: 511 case S5M8763X:
@@ -558,9 +548,7 @@ static int s5m_rtc_start_alarm(struct s5m_rtc_info *info)
558 return ret; 548 return ret;
559 549
560 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode); 550 s5m8767_data_to_tm(data, &tm, info->rtc_24hr_mode);
561 dev_dbg(info->dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 551 dev_dbg(info->dev, "%s: %ptR(%d)\n", __func__, &tm, tm.tm_wday);
562 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday,
563 tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_wday);
564 552
565 switch (info->device_type) { 553 switch (info->device_type) {
566 case S5M8763X: 554 case S5M8763X:
@@ -620,10 +608,7 @@ static int s5m_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
620 return -EINVAL; 608 return -EINVAL;
621 } 609 }
622 610
623 dev_dbg(dev, "%s: %d/%d/%d %d:%d:%d(%d)\n", __func__, 611 dev_dbg(dev, "%s: %ptR(%d)\n", __func__, &alrm->time, alrm->time.tm_wday);
624 1900 + alrm->time.tm_year, 1 + alrm->time.tm_mon,
625 alrm->time.tm_mday, alrm->time.tm_hour, alrm->time.tm_min,
626 alrm->time.tm_sec, alrm->time.tm_wday);
627 612
628 ret = s5m_rtc_stop_alarm(info); 613 ret = s5m_rtc_stop_alarm(info);
629 if (ret < 0) 614 if (ret < 0)
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 51ba414798a8..d417b203cbc5 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/* 2/*
2 * SuperH On-Chip RTC Support 3 * SuperH On-Chip RTC Support
3 * 4 *
@@ -9,10 +10,6 @@
9 * 10 *
10 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> 11 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
11 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka 12 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */ 13 */
17#include <linux/module.h> 14#include <linux/module.h>
18#include <linux/mod_devicetable.h> 15#include <linux/mod_devicetable.h>
@@ -681,5 +678,5 @@ MODULE_DESCRIPTION("SuperH on-chip RTC driver");
681MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, " 678MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, "
682 "Jamie Lenehan <lenehan@twibble.org>, " 679 "Jamie Lenehan <lenehan@twibble.org>, "
683 "Angelo Castello <angelo.castello@st.com>"); 680 "Angelo Castello <angelo.castello@st.com>");
684MODULE_LICENSE("GPL"); 681MODULE_LICENSE("GPL v2");
685MODULE_ALIAS("platform:" DRV_NAME); 682MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
index fe07310952df..11f56de52179 100644
--- a/drivers/rtc/rtc-sun6i.c
+++ b/drivers/rtc/rtc-sun6i.c
@@ -118,9 +118,31 @@
118#define SUN6I_YEAR_MAX 2033 118#define SUN6I_YEAR_MAX 2033
119#define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900) 119#define SUN6I_YEAR_OFF (SUN6I_YEAR_MIN - 1900)
120 120
121/*
122 * There are other differences between models, including:
123 *
124 * - number of GPIO pins that can be configured to hold a certain level
125 * - crypto-key related registers (H5, H6)
126 * - boot process related (super standby, secondary processor entry address)
127 * registers (R40, H6)
128 * - SYS power domain controls (R40)
129 * - DCXO controls (H6)
130 * - RC oscillator calibration (H6)
131 *
132 * These functions are not covered by this driver.
133 */
134struct sun6i_rtc_clk_data {
135 unsigned long rc_osc_rate;
136 unsigned int fixed_prescaler : 16;
137 unsigned int has_prescaler : 1;
138 unsigned int has_out_clk : 1;
139 unsigned int export_iosc : 1;
140};
141
121struct sun6i_rtc_dev { 142struct sun6i_rtc_dev {
122 struct rtc_device *rtc; 143 struct rtc_device *rtc;
123 struct device *dev; 144 struct device *dev;
145 const struct sun6i_rtc_clk_data *data;
124 void __iomem *base; 146 void __iomem *base;
125 int irq; 147 int irq;
126 unsigned long alarm; 148 unsigned long alarm;
@@ -139,14 +161,19 @@ static unsigned long sun6i_rtc_osc_recalc_rate(struct clk_hw *hw,
139 unsigned long parent_rate) 161 unsigned long parent_rate)
140{ 162{
141 struct sun6i_rtc_dev *rtc = container_of(hw, struct sun6i_rtc_dev, hw); 163 struct sun6i_rtc_dev *rtc = container_of(hw, struct sun6i_rtc_dev, hw);
142 u32 val; 164 u32 val = 0;
143 165
144 val = readl(rtc->base + SUN6I_LOSC_CTRL); 166 val = readl(rtc->base + SUN6I_LOSC_CTRL);
145 if (val & SUN6I_LOSC_CTRL_EXT_OSC) 167 if (val & SUN6I_LOSC_CTRL_EXT_OSC)
146 return parent_rate; 168 return parent_rate;
147 169
148 val = readl(rtc->base + SUN6I_LOSC_CLK_PRESCAL); 170 if (rtc->data->fixed_prescaler)
149 val &= GENMASK(4, 0); 171 parent_rate /= rtc->data->fixed_prescaler;
172
173 if (rtc->data->has_prescaler) {
174 val = readl(rtc->base + SUN6I_LOSC_CLK_PRESCAL);
175 val &= GENMASK(4, 0);
176 }
150 177
151 return parent_rate / (val + 1); 178 return parent_rate / (val + 1);
152} 179}
@@ -185,13 +212,16 @@ static const struct clk_ops sun6i_rtc_osc_ops = {
185 .set_parent = sun6i_rtc_osc_set_parent, 212 .set_parent = sun6i_rtc_osc_set_parent,
186}; 213};
187 214
188static void __init sun6i_rtc_clk_init(struct device_node *node) 215static void __init sun6i_rtc_clk_init(struct device_node *node,
216 const struct sun6i_rtc_clk_data *data)
189{ 217{
190 struct clk_hw_onecell_data *clk_data; 218 struct clk_hw_onecell_data *clk_data;
191 struct sun6i_rtc_dev *rtc; 219 struct sun6i_rtc_dev *rtc;
192 struct clk_init_data init = { 220 struct clk_init_data init = {
193 .ops = &sun6i_rtc_osc_ops, 221 .ops = &sun6i_rtc_osc_ops,
222 .name = "losc",
194 }; 223 };
224 const char *iosc_name = "rtc-int-osc";
195 const char *clkout_name = "osc32k-out"; 225 const char *clkout_name = "osc32k-out";
196 const char *parents[2]; 226 const char *parents[2];
197 227
@@ -199,7 +229,8 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
199 if (!rtc) 229 if (!rtc)
200 return; 230 return;
201 231
202 clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL); 232 rtc->data = data;
233 clk_data = kzalloc(struct_size(clk_data, hws, 3), GFP_KERNEL);
203 if (!clk_data) { 234 if (!clk_data) {
204 kfree(rtc); 235 kfree(rtc);
205 return; 236 return;
@@ -224,10 +255,15 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
224 if (!of_get_property(node, "clocks", NULL)) 255 if (!of_get_property(node, "clocks", NULL))
225 goto err; 256 goto err;
226 257
258 /* Only read IOSC name from device tree if it is exported */
259 if (rtc->data->export_iosc)
260 of_property_read_string_index(node, "clock-output-names", 2,
261 &iosc_name);
262
227 rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL, 263 rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL,
228 "rtc-int-osc", 264 iosc_name,
229 NULL, 0, 265 NULL, 0,
230 667000, 266 rtc->data->rc_osc_rate,
231 300000000); 267 300000000);
232 if (IS_ERR(rtc->int_osc)) { 268 if (IS_ERR(rtc->int_osc)) {
233 pr_crit("Couldn't register the internal oscillator\n"); 269 pr_crit("Couldn't register the internal oscillator\n");
@@ -264,14 +300,71 @@ static void __init sun6i_rtc_clk_init(struct device_node *node)
264 clk_data->num = 2; 300 clk_data->num = 2;
265 clk_data->hws[0] = &rtc->hw; 301 clk_data->hws[0] = &rtc->hw;
266 clk_data->hws[1] = __clk_get_hw(rtc->ext_losc); 302 clk_data->hws[1] = __clk_get_hw(rtc->ext_losc);
303 if (rtc->data->export_iosc) {
304 clk_data->hws[2] = rtc->int_osc;
305 clk_data->num = 3;
306 }
267 of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); 307 of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
268 return; 308 return;
269 309
270err: 310err:
271 kfree(clk_data); 311 kfree(clk_data);
272} 312}
273CLK_OF_DECLARE_DRIVER(sun6i_rtc_clk, "allwinner,sun6i-a31-rtc", 313
274 sun6i_rtc_clk_init); 314static const struct sun6i_rtc_clk_data sun6i_a31_rtc_data = {
315 .rc_osc_rate = 667000, /* datasheet says 600 ~ 700 KHz */
316 .has_prescaler = 1,
317};
318
319static void __init sun6i_a31_rtc_clk_init(struct device_node *node)
320{
321 sun6i_rtc_clk_init(node, &sun6i_a31_rtc_data);
322}
323CLK_OF_DECLARE_DRIVER(sun6i_a31_rtc_clk, "allwinner,sun6i-a31-rtc",
324 sun6i_a31_rtc_clk_init);
325
326static const struct sun6i_rtc_clk_data sun8i_a23_rtc_data = {
327 .rc_osc_rate = 667000, /* datasheet says 600 ~ 700 KHz */
328 .has_prescaler = 1,
329 .has_out_clk = 1,
330};
331
332static void __init sun8i_a23_rtc_clk_init(struct device_node *node)
333{
334 sun6i_rtc_clk_init(node, &sun8i_a23_rtc_data);
335}
336CLK_OF_DECLARE_DRIVER(sun8i_a23_rtc_clk, "allwinner,sun8i-a23-rtc",
337 sun8i_a23_rtc_clk_init);
338
339static const struct sun6i_rtc_clk_data sun8i_h3_rtc_data = {
340 .rc_osc_rate = 16000000,
341 .fixed_prescaler = 32,
342 .has_prescaler = 1,
343 .has_out_clk = 1,
344 .export_iosc = 1,
345};
346
347static void __init sun8i_h3_rtc_clk_init(struct device_node *node)
348{
349 sun6i_rtc_clk_init(node, &sun8i_h3_rtc_data);
350}
351CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk, "allwinner,sun8i-h3-rtc",
352 sun8i_h3_rtc_clk_init);
353/* As far as we are concerned, clocks for H5 are the same as H3 */
354CLK_OF_DECLARE_DRIVER(sun50i_h5_rtc_clk, "allwinner,sun50i-h5-rtc",
355 sun8i_h3_rtc_clk_init);
356
357static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = {
358 .rc_osc_rate = 32000,
359 .has_out_clk = 1,
360};
361
362static void __init sun8i_v3_rtc_clk_init(struct device_node *node)
363{
364 sun6i_rtc_clk_init(node, &sun8i_v3_rtc_data);
365}
366CLK_OF_DECLARE_DRIVER(sun8i_v3_rtc_clk, "allwinner,sun8i-v3-rtc",
367 sun8i_v3_rtc_clk_init);
275 368
276static irqreturn_t sun6i_rtc_alarmirq(int irq, void *id) 369static irqreturn_t sun6i_rtc_alarmirq(int irq, void *id)
277{ 370{
@@ -578,8 +671,18 @@ static int sun6i_rtc_probe(struct platform_device *pdev)
578 return 0; 671 return 0;
579} 672}
580 673
674/*
675 * As far as RTC functionality goes, all models are the same. The
676 * datasheets claim that different models have different number of
677 * registers available for non-volatile storage, but experiments show
678 * that all SoCs have 16 registers available for this purpose.
679 */
581static const struct of_device_id sun6i_rtc_dt_ids[] = { 680static const struct of_device_id sun6i_rtc_dt_ids[] = {
582 { .compatible = "allwinner,sun6i-a31-rtc" }, 681 { .compatible = "allwinner,sun6i-a31-rtc" },
682 { .compatible = "allwinner,sun8i-a23-rtc" },
683 { .compatible = "allwinner,sun8i-h3-rtc" },
684 { .compatible = "allwinner,sun8i-v3-rtc" },
685 { .compatible = "allwinner,sun50i-h5-rtc" },
583 { /* sentinel */ }, 686 { /* sentinel */ },
584}; 687};
585MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids); 688MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index c9e77a83cd1b..c6b0a99aa3a9 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -125,15 +125,7 @@ static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
125 125
126 rtc_time_to_tm(sec, tm); 126 rtc_time_to_tm(sec, tm);
127 127
128 dev_vdbg(dev, "time read as %lu. %d/%d/%d %d:%02u:%02u\n", 128 dev_vdbg(dev, "time read as %lu. %ptR\n", sec, tm);
129 sec,
130 tm->tm_mon + 1,
131 tm->tm_mday,
132 tm->tm_year + 1900,
133 tm->tm_hour,
134 tm->tm_min,
135 tm->tm_sec
136 );
137 129
138 return 0; 130 return 0;
139} 131}
@@ -147,15 +139,7 @@ static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
147 /* convert tm to seconds. */ 139 /* convert tm to seconds. */
148 rtc_tm_to_time(tm, &sec); 140 rtc_tm_to_time(tm, &sec);
149 141
150 dev_vdbg(dev, "time set to %lu. %d/%d/%d %d:%02u:%02u\n", 142 dev_vdbg(dev, "time set to %lu. %ptR\n", sec, tm);
151 sec,
152 tm->tm_mon+1,
153 tm->tm_mday,
154 tm->tm_year+1900,
155 tm->tm_hour,
156 tm->tm_min,
157 tm->tm_sec
158 );
159 143
160 /* seconds only written if wait succeeded. */ 144 /* seconds only written if wait succeeded. */
161 ret = tegra_rtc_wait_while_busy(dev); 145 ret = tegra_rtc_wait_while_busy(dev);
@@ -232,15 +216,7 @@ static int tegra_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
232 /* if successfully written and alarm is enabled ... */ 216 /* if successfully written and alarm is enabled ... */
233 if (sec) { 217 if (sec) {
234 tegra_rtc_alarm_irq_enable(dev, 1); 218 tegra_rtc_alarm_irq_enable(dev, 1);
235 219 dev_vdbg(dev, "alarm set as %lu. %ptR\n", sec, &alarm->time);
236 dev_vdbg(dev, "alarm set as %lu. %d/%d/%d %d:%02u:%02u\n",
237 sec,
238 alarm->time.tm_mon+1,
239 alarm->time.tm_mday,
240 alarm->time.tm_year+1900,
241 alarm->time.tm_hour,
242 alarm->time.tm_min,
243 alarm->time.tm_sec);
244 } else { 220 } else {
245 /* disable alarm if 0 or write error. */ 221 /* disable alarm if 0 or write error. */
246 dev_vdbg(dev, "alarm disabled\n"); 222 dev_vdbg(dev, "alarm disabled\n");
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/sysfs.c
index 9746c32eee2e..a8f22ee726bb 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -39,12 +39,10 @@ date_show(struct device *dev, struct device_attribute *attr, char *buf)
39 struct rtc_time tm; 39 struct rtc_time tm;
40 40
41 retval = rtc_read_time(to_rtc_device(dev), &tm); 41 retval = rtc_read_time(to_rtc_device(dev), &tm);
42 if (retval == 0) { 42 if (retval)
43 retval = sprintf(buf, "%04d-%02d-%02d\n", 43 return retval;
44 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
45 }
46 44
47 return retval; 45 return sprintf(buf, "%ptRd\n", &tm);
48} 46}
49static DEVICE_ATTR_RO(date); 47static DEVICE_ATTR_RO(date);
50 48
@@ -55,12 +53,10 @@ time_show(struct device *dev, struct device_attribute *attr, char *buf)
55 struct rtc_time tm; 53 struct rtc_time tm;
56 54
57 retval = rtc_read_time(to_rtc_device(dev), &tm); 55 retval = rtc_read_time(to_rtc_device(dev), &tm);
58 if (retval == 0) { 56 if (retval)
59 retval = sprintf(buf, "%02d:%02d:%02d\n", 57 return retval;
60 tm.tm_hour, tm.tm_min, tm.tm_sec);
61 }
62 58
63 return retval; 59 return sprintf(buf, "%ptRt\n", &tm);
64} 60}
65static DEVICE_ATTR_RO(time); 61static DEVICE_ATTR_RO(time);
66 62
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index c8bb4a2b48c3..c1089fe5344a 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -87,15 +87,16 @@ struct rtc_class_ops {
87 int (*set_offset)(struct device *, long offset); 87 int (*set_offset)(struct device *, long offset);
88}; 88};
89 89
90struct rtc_device;
91
90struct rtc_timer { 92struct rtc_timer {
91 struct timerqueue_node node; 93 struct timerqueue_node node;
92 ktime_t period; 94 ktime_t period;
93 void (*func)(void *private_data); 95 void (*func)(struct rtc_device *rtc);
94 void *private_data; 96 struct rtc_device *rtc;
95 int enabled; 97 int enabled;
96}; 98};
97 99
98
99/* flags */ 100/* flags */
100#define RTC_DEV_BUSY 0 101#define RTC_DEV_BUSY 0
101 102
@@ -138,7 +139,6 @@ struct rtc_device {
138 139
139 bool registered; 140 bool registered;
140 141
141 struct nvmem_device *nvmem;
142 /* Old ABI support */ 142 /* Old ABI support */
143 bool nvram_old_abi; 143 bool nvram_old_abi;
144 struct bin_attribute *nvram; 144 struct bin_attribute *nvram;
@@ -173,8 +173,6 @@ extern struct rtc_device *devm_rtc_device_register(struct device *dev,
173 struct module *owner); 173 struct module *owner);
174struct rtc_device *devm_rtc_allocate_device(struct device *dev); 174struct rtc_device *devm_rtc_allocate_device(struct device *dev);
175int __rtc_register_device(struct module *owner, struct rtc_device *rtc); 175int __rtc_register_device(struct module *owner, struct rtc_device *rtc);
176extern void devm_rtc_device_unregister(struct device *dev,
177 struct rtc_device *rtc);
178 176
179extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm); 177extern int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm);
180extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm); 178extern int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm);
@@ -200,11 +198,12 @@ extern int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc,
200 unsigned int enabled); 198 unsigned int enabled);
201 199
202void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode); 200void rtc_handle_legacy_irq(struct rtc_device *rtc, int num, int mode);
203void rtc_aie_update_irq(void *private); 201void rtc_aie_update_irq(struct rtc_device *rtc);
204void rtc_uie_update_irq(void *private); 202void rtc_uie_update_irq(struct rtc_device *rtc);
205enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer); 203enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer);
206 204
207void rtc_timer_init(struct rtc_timer *timer, void (*f)(void *p), void *data); 205void rtc_timer_init(struct rtc_timer *timer, void (*f)(struct rtc_device *r),
206 struct rtc_device *rtc);
208int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, 207int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer,
209 ktime_t expires, ktime_t period); 208 ktime_t expires, ktime_t period);
210void rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer *timer); 209void rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer *timer);
diff --git a/lib/test_printf.c b/lib/test_printf.c
index 53527ea822b5..659b6cc0d483 100644
--- a/lib/test_printf.c
+++ b/lib/test_printf.c
@@ -9,6 +9,7 @@
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/printk.h> 10#include <linux/printk.h>
11#include <linux/random.h> 11#include <linux/random.h>
12#include <linux/rtc.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/string.h> 14#include <linux/string.h>
14 15
@@ -249,12 +250,11 @@ plain_format(void)
249#endif /* BITS_PER_LONG == 64 */ 250#endif /* BITS_PER_LONG == 64 */
250 251
251static int __init 252static int __init
252plain_hash(void) 253plain_hash_to_buffer(const void *p, char *buf, size_t len)
253{ 254{
254 char buf[PLAIN_BUF_SIZE];
255 int nchars; 255 int nchars;
256 256
257 nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR); 257 nchars = snprintf(buf, len, "%p", p);
258 258
259 if (nchars != PTR_WIDTH) 259 if (nchars != PTR_WIDTH)
260 return -1; 260 return -1;
@@ -265,6 +265,20 @@ plain_hash(void)
265 return 0; 265 return 0;
266 } 266 }
267 267
268 return 0;
269}
270
271
272static int __init
273plain_hash(void)
274{
275 char buf[PLAIN_BUF_SIZE];
276 int ret;
277
278 ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE);
279 if (ret)
280 return ret;
281
268 if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0) 282 if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
269 return -1; 283 return -1;
270 284
@@ -295,6 +309,23 @@ plain(void)
295} 309}
296 310
297static void __init 311static void __init
312test_hashed(const char *fmt, const void *p)
313{
314 char buf[PLAIN_BUF_SIZE];
315 int ret;
316
317 /*
318 * No need to increase failed test counter since this is assumed
319 * to be called after plain().
320 */
321 ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE);
322 if (ret)
323 return;
324
325 test(buf, fmt, p);
326}
327
328static void __init
298symbol_ptr(void) 329symbol_ptr(void)
299{ 330{
300} 331}
@@ -419,6 +450,29 @@ struct_va_format(void)
419} 450}
420 451
421static void __init 452static void __init
453struct_rtc_time(void)
454{
455 /* 1543210543 */
456 const struct rtc_time tm = {
457 .tm_sec = 43,
458 .tm_min = 35,
459 .tm_hour = 5,
460 .tm_mday = 26,
461 .tm_mon = 10,
462 .tm_year = 118,
463 };
464
465 test_hashed("%pt", &tm);
466
467 test("2018-11-26T05:35:43", "%ptR", &tm);
468 test("0118-10-26T05:35:43", "%ptRr", &tm);
469 test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
470 test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm);
471 test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm);
472 test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm);
473}
474
475static void __init
422struct_clk(void) 476struct_clk(void)
423{ 477{
424} 478}
@@ -529,6 +583,7 @@ test_pointer(void)
529 uuid(); 583 uuid();
530 dentry(); 584 dentry();
531 struct_va_format(); 585 struct_va_format();
586 struct_rtc_time();
532 struct_clk(); 587 struct_clk();
533 bitmap(); 588 bitmap();
534 netdev_features(); 589 netdev_features();
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 37a54a6dd594..3add92329bae 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -30,6 +30,7 @@
30#include <linux/ioport.h> 30#include <linux/ioport.h>
31#include <linux/dcache.h> 31#include <linux/dcache.h>
32#include <linux/cred.h> 32#include <linux/cred.h>
33#include <linux/rtc.h>
33#include <linux/uuid.h> 34#include <linux/uuid.h>
34#include <linux/of.h> 35#include <linux/of.h>
35#include <net/addrconf.h> 36#include <net/addrconf.h>
@@ -822,6 +823,20 @@ static const struct printf_spec default_dec_spec = {
822 .precision = -1, 823 .precision = -1,
823}; 824};
824 825
826static const struct printf_spec default_dec02_spec = {
827 .base = 10,
828 .field_width = 2,
829 .precision = -1,
830 .flags = ZEROPAD,
831};
832
833static const struct printf_spec default_dec04_spec = {
834 .base = 10,
835 .field_width = 4,
836 .precision = -1,
837 .flags = ZEROPAD,
838};
839
825static noinline_for_stack 840static noinline_for_stack
826char *resource_string(char *buf, char *end, struct resource *res, 841char *resource_string(char *buf, char *end, struct resource *res,
827 struct printf_spec spec, const char *fmt) 842 struct printf_spec spec, const char *fmt)
@@ -1550,6 +1565,87 @@ char *address_val(char *buf, char *end, const void *addr, const char *fmt)
1550} 1565}
1551 1566
1552static noinline_for_stack 1567static noinline_for_stack
1568char *date_str(char *buf, char *end, const struct rtc_time *tm, bool r)
1569{
1570 int year = tm->tm_year + (r ? 0 : 1900);
1571 int mon = tm->tm_mon + (r ? 0 : 1);
1572
1573 buf = number(buf, end, year, default_dec04_spec);
1574 if (buf < end)
1575 *buf = '-';
1576 buf++;
1577
1578 buf = number(buf, end, mon, default_dec02_spec);
1579 if (buf < end)
1580 *buf = '-';
1581 buf++;
1582
1583 return number(buf, end, tm->tm_mday, default_dec02_spec);
1584}
1585
1586static noinline_for_stack
1587char *time_str(char *buf, char *end, const struct rtc_time *tm, bool r)
1588{
1589 buf = number(buf, end, tm->tm_hour, default_dec02_spec);
1590 if (buf < end)
1591 *buf = ':';
1592 buf++;
1593
1594 buf = number(buf, end, tm->tm_min, default_dec02_spec);
1595 if (buf < end)
1596 *buf = ':';
1597 buf++;
1598
1599 return number(buf, end, tm->tm_sec, default_dec02_spec);
1600}
1601
1602static noinline_for_stack
1603char *rtc_str(char *buf, char *end, const struct rtc_time *tm, const char *fmt)
1604{
1605 bool have_t = true, have_d = true;
1606 bool raw = false;
1607 int count = 2;
1608
1609 switch (fmt[count]) {
1610 case 'd':
1611 have_t = false;
1612 count++;
1613 break;
1614 case 't':
1615 have_d = false;
1616 count++;
1617 break;
1618 }
1619
1620 raw = fmt[count] == 'r';
1621
1622 if (have_d)
1623 buf = date_str(buf, end, tm, raw);
1624 if (have_d && have_t) {
1625 /* Respect ISO 8601 */
1626 if (buf < end)
1627 *buf = 'T';
1628 buf++;
1629 }
1630 if (have_t)
1631 buf = time_str(buf, end, tm, raw);
1632
1633 return buf;
1634}
1635
1636static noinline_for_stack
1637char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
1638 const char *fmt)
1639{
1640 switch (fmt[1]) {
1641 case 'R':
1642 return rtc_str(buf, end, (const struct rtc_time *)ptr, fmt);
1643 default:
1644 return ptr_to_id(buf, end, ptr, spec);
1645 }
1646}
1647
1648static noinline_for_stack
1553char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec, 1649char *clock(char *buf, char *end, struct clk *clk, struct printf_spec spec,
1554 const char *fmt) 1650 const char *fmt)
1555{ 1651{
@@ -1828,6 +1924,8 @@ char *device_node_string(char *buf, char *end, struct device_node *dn,
1828 * - 'd[234]' For a dentry name (optionally 2-4 last components) 1924 * - 'd[234]' For a dentry name (optionally 2-4 last components)
1829 * - 'D[234]' Same as 'd' but for a struct file 1925 * - 'D[234]' Same as 'd' but for a struct file
1830 * - 'g' For block_device name (gendisk + partition number) 1926 * - 'g' For block_device name (gendisk + partition number)
1927 * - 't[R][dt][r]' For time and date as represented:
1928 * R struct rtc_time
1831 * - 'C' For a clock, it prints the name (Common Clock Framework) or address 1929 * - 'C' For a clock, it prints the name (Common Clock Framework) or address
1832 * (legacy clock framework) of the clock 1930 * (legacy clock framework) of the clock
1833 * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address 1931 * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
@@ -1952,6 +2050,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
1952 return address_val(buf, end, ptr, fmt); 2050 return address_val(buf, end, ptr, fmt);
1953 case 'd': 2051 case 'd':
1954 return dentry_name(buf, end, ptr, spec, fmt); 2052 return dentry_name(buf, end, ptr, spec, fmt);
2053 case 't':
2054 return time_and_date(buf, end, ptr, spec, fmt);
1955 case 'C': 2055 case 'C':
1956 return clock(buf, end, ptr, spec, fmt); 2056 return clock(buf, end, ptr, spec, fmt);
1957 case 'D': 2057 case 'D':