History

Merge tag 'rtc-5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux

Pull RTC updates from Alexandre Belloni: "The VL_READ and VL_CLR ioctls have been reworked to be more useful. This will not break userspace as there are very few users and they are using the integer value as a boolean. Apart from that, two drivers were reworked and a few fixes here and there for a net reduction of number of lines. Summary: Subsystem: - the VL_READ and VL_CLR ioctls are now documented and their behavior is unified across all the drivers. - RTC_I2C_AND_SPI Kconfig option rework to avoid selecting both REGMAP_I2C and REGMAP_SPI unecessarily. Drivers: - at91rm9200: remove deprecated procfs, add sam9x60, sama5d4 and sama5d2 compatibles. - cmos: solve lost interrupts issue on MS Surface 3 - hym8563: return proper errno when time is invalid - rv3029: many fixes, nvram support" * tag 'rtc-5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (63 commits) dt-bindings: rtc: at91rm9200: document clocks property rtc: i2c/spi: Avoid inclusion of REGMAP support when not needed rtc: Kconfig: select REGMAP_I2C when necessary rtc: Kconfig: properly indent sd3078 entry rtc: cmos: Refactor code by using the new dmi_get_bios_year() helper rtc: cmos: Use predefined value for RTC IRQ on legacy x86 rtc: cmos: Stop using shared IRQ rtc: tps6586x: Use IRQ_NOAUTOEN flag rtc: at91rm9200: use FIELD_PREP/FIELD_GET rtc: at91rm9200: avoid time readout in at91_rtc_setalarm rtc: at91rm9200: move register definitions to C file rtc: at91rm9200: add sama5d4 and sama5d2 compatibles dt-bindings: rtc: at91rm9200: convert bindings to json-schema rtc: at91rm9200: remove procfs information dt-bindings: atmel, at91rm9200-rtc: add microchip, sam9x60-rtc rtc: pcf8563: Use BIT rtc: moxart: Convert to SPDX identifier rtc: ds1343: Remove unused struct spi_device in struct ds1343_priv rtc: rx8025: Remove struct i2c_client from struct rx8025_data rtc: hym8563: Read the valid flag directly instead of caching it ...

Linus Torvalds committed 6 years ago

Commit eadc4e42 parents 322bf2d f45719229 files · +415 −558Browse files

Unified · Split

29 files
  1. .mailmap +1 −0
  2. Documentation/ABI/testing/rtc-cdev +8 −0
  3. Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.txt +0 −17
  4. Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.yaml +49 −0
  5. drivers/rtc/Kconfig +16 −8
  6. drivers/rtc/rtc-abx80x.c +2 −5
  7. drivers/rtc/rtc-asm9260.c +3 −0
  8. drivers/rtc/rtc-at91rm9200.c +74 −45
  9. drivers/rtc/rtc-at91rm9200.h +0 −71
  10. drivers/rtc/rtc-cmos.c +6 −6
  11. drivers/rtc/rtc-ds1343.c +5 −5
  12. drivers/rtc/rtc-hym8563.c +7 −12
  13. drivers/rtc/rtc-moxart.c +1 −4
  14. drivers/rtc/rtc-mt6397.c +1 −9
  15. drivers/rtc/rtc-omap.c +1 −1
  16. drivers/rtc/rtc-pcf2127.c +2 −4
  17. drivers/rtc/rtc-pcf85063.c +2 −14
  18. drivers/rtc/rtc-pcf8523.c +3 −3
  19. drivers/rtc/rtc-pcf8563.c +9 −31
  20. drivers/rtc/rtc-rv3028.c +2 −15
  21. drivers/rtc/rtc-rv3029c2.c +182 −260
  22. drivers/rtc/rtc-rv8803.c +7 −9
  23. drivers/rtc/rtc-rx8010.c +4 −21
  24. drivers/rtc/rtc-rx8025.c +14 −13
  25. drivers/rtc/rtc-stm32.c +4 −1
  26. drivers/rtc/rtc-tps6586x.c +3 −1
  27. drivers/rtc/rtc-zynqmp.c +2 −2
  28. include/linux/rtc.h +1 −0
  29. include/uapi/linux/rtc.h +6 −1
.mailmap+1−0
@@ -18,6 +18,7 @@ Aleksey Gorelov <aleksey_gorelov@phoenix.com> · 17 unmodified lines
1818 Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com>
1919 Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@intel.com>
2020 Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@linaro.org>
21+Alexandre Belloni <alexandre.belloni@bootlin.com> <alexandre.belloni@free-electrons.com>
2122 Alexei Starovoitov <ast@kernel.org> <ast@plumgrid.com>
2223 Alexei Starovoitov <ast@kernel.org> <alexei.starovoitov@gmail.com>
2324 Alexei Starovoitov <ast@kernel.org> <ast@fb.com>
Documentation/ABI/testing/rtc-cdev+8−0
@@ -33,6 +33,14 @@ Description: · 32 unmodified lines
3333 Requires a separate RTC_PIE_ON call to enable the periodic
3434 interrupts.
3535
36+ * RTC_VL_READ: Read the voltage inputs status of the RTC when
37+ supported. The value is a bit field of RTC_VL_*, giving the
38+ status of the main and backup voltages.
39+
40+ * RTC_VL_CLEAR: Clear the voltage status of the RTC. Some RTCs
41+ need user interaction when the backup power provider is
42+ replaced or charged to be able to clear the status.
43+
3644 The ioctl() calls supported by the older /dev/rtc interface are
3745 also supported by the newer RTC class framework. However,
3846 because the chips and systems are not standardized, some PC/AT
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.txt+0−17
@@ -1,17 +0,0 @@
1−Atmel AT91RM9200 Real Time Clock
2−
3−Required properties:
4−- compatible: should be: "atmel,at91rm9200-rtc" or "atmel,at91sam9x5-rtc"
5−- reg: physical base address of the controller and length of memory mapped
6− region.
7−- interrupts: rtc alarm/event interrupt
8−- clocks: phandle to input clock.
9−
10−Example:
11−
12−rtc@fffffe00 {
13− compatible = "atmel,at91rm9200-rtc";
14− reg = <0xfffffe00 0x100>;
15− interrupts = <1 4 7>;
16− clocks = <&clk32k>;
17−};
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.yaml+49−0
@@ -0,0 +1,49 @@
1+# SPDX-License-Identifier: GPL-2.0
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/rtc/atmel,at91rm9200-rtc.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Atmel AT91 RTC Device Tree Bindings
8+
9+allOf:
10+ - $ref: "rtc.yaml#"
11+
12+maintainers:
13+ - Alexandre Belloni <alexandre.belloni@bootlin.com>
14+
15+properties:
16+ compatible:
17+ enum:
18+ - atmel,at91rm9200-rtc
19+ - atmel,at91sam9x5-rtc
20+ - atmel,sama5d4-rtc
21+ - atmel,sama5d2-rtc
22+ - microchip,sam9x60-rtc
23+
24+ reg:
25+ maxItems: 1
26+
27+ interrupts:
28+ maxItems: 1
29+
30+ clocks:
31+ maxItems: 1
32+
33+required:
34+ - compatible
35+ - reg
36+ - interrupts
37+ - clocks
38+
39+additionalProperties: false
40+
41+examples:
42+ - |
43+ rtc@fffffe00 {
44+ compatible = "atmel,at91rm9200-rtc";
45+ reg = <0xfffffe00 0x100>;
46+ interrupts = <1 4 7>;
47+ clocks = <&clk32k>;
48+ };
49+...
drivers/rtc/Kconfig+16−8
@@ -240,6 +240,7 @@ config RTC_DRV_AS3722 · 239 unmodified lines
240240
241241 config RTC_DRV_DS1307
242242 tristate "Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057"
243+ select REGMAP_I2C
243244 help
244245 If you say yes here you get support for various compatible RTC
245246 chips (often with battery backup) connected with I2C. This driver
@@ -622,6 +623,7 @@ config RTC_DRV_RX8010 · 376 unmodified lines
622623
623624 config RTC_DRV_RX8581
624625 tristate "Epson RX-8571/RX-8581"
626+ select REGMAP_I2C
625627 help
626628 If you say yes here you will get support for the Epson RX-8571/
627629 RX-8581.
@@ -649,6 +651,7 @@ config RTC_DRV_EM3027 · 21 unmodified lines
649651
650652 config RTC_DRV_RV3028
651653 tristate "Micro Crystal RV3028"
654+ select REGMAP_I2C
652655 help
653656 If you say yes here you get support for the Micro Crystal
654657 RV3028.
@@ -677,13 +680,14 @@ config RTC_DRV_S5M · 22 unmodified lines
677680 will be called rtc-s5m.
678681
679682 config RTC_DRV_SD3078
680− tristate "ZXW Shenzhen whwave SD3078"
681− help
682− If you say yes here you get support for the ZXW Shenzhen whwave
683− SD3078 RTC chips.
683+ tristate "ZXW Shenzhen whwave SD3078"
684+ select REGMAP_I2C
685+ help
686+ If you say yes here you get support for the ZXW Shenzhen whwave
687+ SD3078 RTC chips.
684688
685− This driver can also be built as a module. If so, the module
686− will be called rtc-sd3078
689+ This driver can also be built as a module. If so, the module
690+ will be called rtc-sd3078
687691
688692 endif # I2C
689693
@@ -849,14 +853,14 @@ config RTC_I2C_AND_SPI · 159 unmodified lines
849853 default m if I2C=m
850854 default y if I2C=y
851855 default y if SPI_MASTER=y
852− select REGMAP_I2C if I2C
853− select REGMAP_SPI if SPI_MASTER
854856
855857 comment "SPI and I2C RTC drivers"
856858
857859 config RTC_DRV_DS3232
858860 tristate "Dallas/Maxim DS3232/DS3234"
859861 depends on RTC_I2C_AND_SPI
862+ select REGMAP_I2C if I2C
863+ select REGMAP_SPI if SPI_MASTER
860864 help
861865 If you say yes here you get support for Dallas Semiconductor
862866 DS3232 and DS3234 real-time clock chips. If an interrupt is associated
@@ -876,6 +880,8 @@ config RTC_DRV_DS3232_HWMON · 13 unmodified lines
876880 config RTC_DRV_PCF2127
877881 tristate "NXP PCF2127"
878882 depends on RTC_I2C_AND_SPI
883+ select REGMAP_I2C if I2C
884+ select REGMAP_SPI if SPI_MASTER
879885 select WATCHDOG_CORE if WATCHDOG
880886 help
881887 If you say yes here you get support for the NXP PCF2127/29 RTC
@@ -892,6 +898,8 @@ config RTC_DRV_PCF2127 · 10 unmodified lines
892898 config RTC_DRV_RV3029C2
893899 tristate "Micro Crystal RV3029/3049"
894900 depends on RTC_I2C_AND_SPI
901+ select REGMAP_I2C if I2C
902+ select REGMAP_SPI if SPI_MASTER
895903 help
896904 If you say yes here you get support for the Micro Crystal
897905 RV3029 and RV3049 RTC chips.
drivers/rtc/rtc-abx80x.c+2−5
@@ -523,12 +523,9 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 522 unmodified lines
523523 if (status < 0)
524524 return status;
525525
526− tmp = !!(status & ABX8XX_STATUS_BLF);
526+ tmp = status & ABX8XX_STATUS_BLF ? RTC_VL_BACKUP_LOW : 0;
527527
528− if (copy_to_user((void __user *)arg, &tmp, sizeof(int)))
529− return -EFAULT;
530−
531− return 0;
528+ return put_user(tmp, (unsigned int __user *)arg);
532529
533530 case RTC_VL_CLR:
534531 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS);
drivers/rtc/rtc-asm9260.c+3−0
@@ -264,6 +264,9 @@ static int asm9260_rtc_probe(struct platform_device *pdev) · 263 unmodified lines
264264 return PTR_ERR(priv->iobase);
265265
266266 priv->clk = devm_clk_get(dev, "ahb");
267+ if (IS_ERR(priv->clk))
268+ return PTR_ERR(priv->clk);
269+
267270 ret = clk_prepare_enable(priv->clk);
268271 if (ret) {
269272 dev_err(dev, "Failed to enable clk!\n");
drivers/rtc/rtc-at91rm9200.c+74−45
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 */
1515
1616 #include <linux/bcd.h>
17+#include <linux/bitfield.h>
1718 #include <linux/clk.h>
1819 #include <linux/completion.h>
1920 #include <linux/interrupt.h>
@@ -30,7 +31,51 @@ · 10 unmodified lines
3031 #include <linux/time.h>
3132 #include <linux/uaccess.h>
3233
33−#include "rtc-at91rm9200.h"
34+#define AT91_RTC_CR 0x00 /* Control Register */
35+#define AT91_RTC_UPDTIM BIT(0) /* Update Request Time Register */
36+#define AT91_RTC_UPDCAL BIT(1) /* Update Request Calendar Register */
37+
38+#define AT91_RTC_MR 0x04 /* Mode Register */
39+
40+#define AT91_RTC_TIMR 0x08 /* Time Register */
41+#define AT91_RTC_SEC GENMASK(6, 0) /* Current Second */
42+#define AT91_RTC_MIN GENMASK(14, 8) /* Current Minute */
43+#define AT91_RTC_HOUR GENMASK(21, 16) /* Current Hour */
44+#define AT91_RTC_AMPM BIT(22) /* Ante Meridiem Post Meridiem Indicator */
45+
46+#define AT91_RTC_CALR 0x0c /* Calendar Register */
47+#define AT91_RTC_CENT GENMASK(6, 0) /* Current Century */
48+#define AT91_RTC_YEAR GENMASK(15, 8) /* Current Year */
49+#define AT91_RTC_MONTH GENMASK(20, 16) /* Current Month */
50+#define AT91_RTC_DAY GENMASK(23, 21) /* Current Day */
51+#define AT91_RTC_DATE GENMASK(29, 24) /* Current Date */
52+
53+#define AT91_RTC_TIMALR 0x10 /* Time Alarm Register */
54+#define AT91_RTC_SECEN BIT(7) /* Second Alarm Enable */
55+#define AT91_RTC_MINEN BIT(15) /* Minute Alarm Enable */
56+#define AT91_RTC_HOUREN BIT(23) /* Hour Alarm Enable */
57+
58+#define AT91_RTC_CALALR 0x14 /* Calendar Alarm Register */
59+#define AT91_RTC_MTHEN BIT(23) /* Month Alarm Enable */
60+#define AT91_RTC_DATEEN BIT(31) /* Date Alarm Enable */
61+
62+#define AT91_RTC_SR 0x18 /* Status Register */
63+#define AT91_RTC_ACKUPD BIT(0) /* Acknowledge for Update */
64+#define AT91_RTC_ALARM BIT(1) /* Alarm Flag */
65+#define AT91_RTC_SECEV BIT(2) /* Second Event */
66+#define AT91_RTC_TIMEV BIT(3) /* Time Event */
67+#define AT91_RTC_CALEV BIT(4) /* Calendar Event */
68+
69+#define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */
70+#define AT91_RTC_IER 0x20 /* Interrupt Enable Register */
71+#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */
72+#define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */
73+
74+#define AT91_RTC_VER 0x2c /* Valid Entry Register */
75+#define AT91_RTC_NVTIM BIT(0) /* Non valid Time */
76+#define AT91_RTC_NVCAL BIT(1) /* Non valid Calendar */
77+#define AT91_RTC_NVTIMALR BIT(2) /* Non valid Time Alarm */
78+#define AT91_RTC_NVCALALR BIT(3) /* Non valid Calendar Alarm */
3479
3580 #define at91_rtc_read(field) \
3681 readl_relaxed(at91_rtc_regs + field)
@@ -117,20 +162,20 @@ static void at91_rtc_decodetime(unsigned int timereg, unsigned int calreg, · 80 unmodified lines
117162 } while ((time != at91_rtc_read(timereg)) ||
118163 (date != at91_rtc_read(calreg)));
119164
120− tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0);
121− tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8);
122− tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16);
165+ tm->tm_sec = bcd2bin(FIELD_GET(AT91_RTC_SEC, time));
166+ tm->tm_min = bcd2bin(FIELD_GET(AT91_RTC_MIN, time));
167+ tm->tm_hour = bcd2bin(FIELD_GET(AT91_RTC_HOUR, time));
123168
124169 /*
125170 * The Calendar Alarm register does not have a field for
126171 * the year - so these will return an invalid value.
127172 */
128173 tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */
129− tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */
174+ tm->tm_year += bcd2bin(FIELD_GET(AT91_RTC_YEAR, date)); /* year */
130175
131− tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */
132− tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1;
133− tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24);
176+ tm->tm_wday = bcd2bin(FIELD_GET(AT91_RTC_DAY, date)) - 1; /* day of the week [0-6], Sunday=0 */
177+ tm->tm_mon = bcd2bin(FIELD_GET(AT91_RTC_MONTH, date)) - 1;
178+ tm->tm_mday = bcd2bin(FIELD_GET(AT91_RTC_DATE, date));
134179 }
135180
136181 /*
@@ -167,16 +212,17 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm) · 30 unmodified lines
167212 at91_rtc_write_idr(AT91_RTC_ACKUPD);
168213
169214 at91_rtc_write(AT91_RTC_TIMR,
170− bin2bcd(tm->tm_sec) << 0
171− | bin2bcd(tm->tm_min) << 8
172− | bin2bcd(tm->tm_hour) << 16);
215+ FIELD_PREP(AT91_RTC_SEC, bin2bcd(tm->tm_sec))
216+ | FIELD_PREP(AT91_RTC_MIN, bin2bcd(tm->tm_min))
217+ | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(tm->tm_hour)));
173218
174219 at91_rtc_write(AT91_RTC_CALR,
175− bin2bcd((tm->tm_year + 1900) / 100) /* century */
176− | bin2bcd(tm->tm_year % 100) << 8 /* year */
177− | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */
178− | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */
179− | bin2bcd(tm->tm_mday) << 24);
220+ FIELD_PREP(AT91_RTC_CENT,
221+ bin2bcd((tm->tm_year + 1900) / 100))
222+ | FIELD_PREP(AT91_RTC_YEAR, bin2bcd(tm->tm_year % 100))
223+ | FIELD_PREP(AT91_RTC_MONTH, bin2bcd(tm->tm_mon + 1))
224+ | FIELD_PREP(AT91_RTC_DAY, bin2bcd(tm->tm_wday + 1))
225+ | FIELD_PREP(AT91_RTC_DATE, bin2bcd(tm->tm_mday)));
180226
181227 /* Restart Time/Calendar */
182228 cr = at91_rtc_read(AT91_RTC_CR);
@@ -211,25 +257,17 @@ static int at91_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) · 28 unmodified lines
211257 */
212258 static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
213259 {
214− struct rtc_time tm;
215−
216− at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, &tm);
217−
218− tm.tm_mon = alrm->time.tm_mon;
219− tm.tm_mday = alrm->time.tm_mday;
220− tm.tm_hour = alrm->time.tm_hour;
221− tm.tm_min = alrm->time.tm_min;
222− tm.tm_sec = alrm->time.tm_sec;
260+ struct rtc_time tm = alrm->time;
223261
224262 at91_rtc_write_idr(AT91_RTC_ALARM);
225263 at91_rtc_write(AT91_RTC_TIMALR,
226− bin2bcd(tm.tm_sec) << 0
227− | bin2bcd(tm.tm_min) << 8
228− | bin2bcd(tm.tm_hour) << 16
264+ FIELD_PREP(AT91_RTC_SEC, bin2bcd(alrm->time.tm_sec))
265+ | FIELD_PREP(AT91_RTC_MIN, bin2bcd(alrm->time.tm_min))
266+ | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(alrm->time.tm_hour))
229267 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);
230268 at91_rtc_write(AT91_RTC_CALALR,
231− bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
232− | bin2bcd(tm.tm_mday) << 24
269+ FIELD_PREP(AT91_RTC_MONTH, bin2bcd(alrm->time.tm_mon + 1))
270+ | FIELD_PREP(AT91_RTC_DATE, bin2bcd(alrm->time.tm_mday))
233271 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
234272
235273 if (alrm->enabled) {
@@ -254,20 +292,6 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 18 unmodified lines
254292
255293 return 0;
256294 }
257−/*
258− * Provide additional RTC information in /proc/driver/rtc
259− */
260−static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
261−{
262− unsigned long imr = at91_rtc_read_imr();
263−
264− seq_printf(seq, "update_IRQ\t: %s\n",
265− (imr & AT91_RTC_ACKUPD) ? "yes" : "no");
266− seq_printf(seq, "periodic_IRQ\t: %s\n",
267− (imr & AT91_RTC_SECEV) ? "yes" : "no");
268−
269− return 0;
270−}
271295
272296 /*
273297 * IRQ handler for the RTC
@@ -326,6 +350,12 @@ static const struct of_device_id at91_rtc_dt_ids[] = { · 52 unmodified lines
326350 }, {
327351 .compatible = "atmel,at91sam9x5-rtc",
328352 .data = &at91sam9x5_config,
353+ }, {
354+ .compatible = "atmel,sama5d4-rtc",
355+ .data = &at91rm9200_config,
356+ }, {
357+ .compatible = "atmel,sama5d2-rtc",
358+ .data = &at91rm9200_config,
329359 }, {
330360 /* sentinel */
331361 }
@@ -337,7 +367,6 @@ static const struct rtc_class_ops at91_rtc_ops = { · 5 unmodified lines
337367 .set_time = at91_rtc_settime,
338368 .read_alarm = at91_rtc_readalarm,
339369 .set_alarm = at91_rtc_setalarm,
340− .proc = at91_rtc_proc,
341370 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
342371 };
343372
drivers/rtc/rtc-at91rm9200.h+0−71
@@ -1,71 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-or-later */
2−/*
3− * arch/arm/mach-at91/include/mach/at91_rtc.h
4− *
5− * Copyright (C) 2005 Ivan Kokshaysky
6− * Copyright (C) SAN People
7− *
8− * Real Time Clock (RTC) - System peripheral registers.
9− * Based on AT91RM9200 datasheet revision E.
10− */
11−
12−#ifndef AT91_RTC_H
13−#define AT91_RTC_H
14−
15−#define AT91_RTC_CR 0x00 /* Control Register */
16−#define AT91_RTC_UPDTIM (1 << 0) /* Update Request Time Register */
17−#define AT91_RTC_UPDCAL (1 << 1) /* Update Request Calendar Register */
18−#define AT91_RTC_TIMEVSEL (3 << 8) /* Time Event Selection */
19−#define AT91_RTC_TIMEVSEL_MINUTE (0 << 8)
20−#define AT91_RTC_TIMEVSEL_HOUR (1 << 8)
21−#define AT91_RTC_TIMEVSEL_DAY24 (2 << 8)
22−#define AT91_RTC_TIMEVSEL_DAY12 (3 << 8)
23−#define AT91_RTC_CALEVSEL (3 << 16) /* Calendar Event Selection */
24−#define AT91_RTC_CALEVSEL_WEEK (0 << 16)
25−#define AT91_RTC_CALEVSEL_MONTH (1 << 16)
26−#define AT91_RTC_CALEVSEL_YEAR (2 << 16)
27−
28−#define AT91_RTC_MR 0x04 /* Mode Register */
29−#define AT91_RTC_HRMOD (1 << 0) /* 12/24 Hour Mode */
30−
31−#define AT91_RTC_TIMR 0x08 /* Time Register */
32−#define AT91_RTC_SEC (0x7f << 0) /* Current Second */
33−#define AT91_RTC_MIN (0x7f << 8) /* Current Minute */
34−#define AT91_RTC_HOUR (0x3f << 16) /* Current Hour */
35−#define AT91_RTC_AMPM (1 << 22) /* Ante Meridiem Post Meridiem Indicator */
36−
37−#define AT91_RTC_CALR 0x0c /* Calendar Register */
38−#define AT91_RTC_CENT (0x7f << 0) /* Current Century */
39−#define AT91_RTC_YEAR (0xff << 8) /* Current Year */
40−#define AT91_RTC_MONTH (0x1f << 16) /* Current Month */
41−#define AT91_RTC_DAY (7 << 21) /* Current Day */
42−#define AT91_RTC_DATE (0x3f << 24) /* Current Date */
43−
44−#define AT91_RTC_TIMALR 0x10 /* Time Alarm Register */
45−#define AT91_RTC_SECEN (1 << 7) /* Second Alarm Enable */
46−#define AT91_RTC_MINEN (1 << 15) /* Minute Alarm Enable */
47−#define AT91_RTC_HOUREN (1 << 23) /* Hour Alarm Enable */
48−
49−#define AT91_RTC_CALALR 0x14 /* Calendar Alarm Register */
50−#define AT91_RTC_MTHEN (1 << 23) /* Month Alarm Enable */
51−#define AT91_RTC_DATEEN (1 << 31) /* Date Alarm Enable */
52−
53−#define AT91_RTC_SR 0x18 /* Status Register */
54−#define AT91_RTC_ACKUPD (1 << 0) /* Acknowledge for Update */
55−#define AT91_RTC_ALARM (1 << 1) /* Alarm Flag */
56−#define AT91_RTC_SECEV (1 << 2) /* Second Event */
57−#define AT91_RTC_TIMEV (1 << 3) /* Time Event */
58−#define AT91_RTC_CALEV (1 << 4) /* Calendar Event */
59−
60−#define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */
61−#define AT91_RTC_IER 0x20 /* Interrupt Enable Register */
62−#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */
63−#define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */
64−
65−#define AT91_RTC_VER 0x2c /* Valid Entry Register */
66−#define AT91_RTC_NVTIM (1 << 0) /* Non valid Time */
67−#define AT91_RTC_NVCAL (1 << 1) /* Non valid Calendar */
68−#define AT91_RTC_NVTIMALR (1 << 2) /* Non valid Time Alarm */
69−#define AT91_RTC_NVCALALR (1 << 3) /* Non valid Calendar Alarm */
70−
71−#endif
drivers/rtc/rtc-cmos.c+6−6
@@ -850,7 +850,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) · 849 unmodified lines
850850 rtc_cmos_int_handler = cmos_interrupt;
851851
852852 retval = request_irq(rtc_irq, rtc_cmos_int_handler,
853− IRQF_SHARED, dev_name(&cmos_rtc.rtc->dev),
853+ 0, dev_name(&cmos_rtc.rtc->dev),
854854 cmos_rtc.rtc);
855855 if (retval < 0) {
856856 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
@@ -1197,8 +1197,6 @@ static void rtc_wake_off(struct device *dev) · 340 unmodified lines
11971197 /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
11981198 static void use_acpi_alarm_quirks(void)
11991199 {
1200− int year;
1201−
12021200 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
12031201 return;
12041202
@@ -1208,8 +1206,10 @@ static void use_acpi_alarm_quirks(void) · 3 unmodified lines
12081206 if (!is_hpet_enabled())
12091207 return;
12101208
1211− if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015)
1212− use_acpi_alarm = true;
1209+ if (dmi_get_bios_year() < 2015)
1210+ return;
1211+
1212+ use_acpi_alarm = true;
12131213 }
12141214 #else
12151215 static inline void use_acpi_alarm_quirks(void) { }
@@ -1305,7 +1305,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) · 89 unmodified lines
13051305 * hardcode it on systems with a legacy PIC.
13061306 */
13071307 if (nr_legacy_irqs())
1308− irq = 8;
1308+ irq = RTC_IRQ;
13091309 #endif
13101310 return cmos_do_probe(&pnp->dev,
13111311 pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
drivers/rtc/rtc-ds1343.c+5−5
@@ -75,7 +75,6 @@ static const struct spi_device_id ds1343_id[] = { · 74 unmodified lines
7575 MODULE_DEVICE_TABLE(spi, ds1343_id);
7676
7777 struct ds1343_priv {
78− struct spi_device *spi;
7978 struct rtc_device *rtc;
8079 struct regmap *map;
8180 int irq;
@@ -362,12 +361,13 @@ static int ds1343_probe(struct spi_device *spi) · 280 unmodified lines
362361 if (!priv)
363362 return -ENOMEM;
364363
365− priv->spi = spi;
366−
367364 /* RTC DS1347 works in spi mode 3 and
368− * its chip select is active high
365+ * its chip select is active high. Active high should be defined as
366+ * "inverse polarity" as GPIO-based chip selects can be logically
367+ * active high but inverted by the GPIO library.
369368 */
370− spi->mode = SPI_MODE_3 | SPI_CS_HIGH;
369+ spi->mode |= SPI_MODE_3;
370+ spi->mode ^= SPI_CS_HIGH;
371371 spi->bits_per_word = 8;
372372 res = spi_setup(spi);
373373 if (res)
drivers/rtc/rtc-hym8563.c+7−12
@@ -78,7 +78,6 @@ · 77 unmodified lines
7878 struct hym8563 {
7979 struct i2c_client *client;
8080 struct rtc_device *rtc;
81− bool valid;
8281 #ifdef CONFIG_COMMON_CLK
8382 struct clk_hw clkout_hw;
8483 #endif
@@ -91,19 +90,19 @@ struct hym8563 { · 6 unmodified lines
9190 static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
9291 {
9392 struct i2c_client *client = to_i2c_client(dev);
94− struct hym8563 *hym8563 = i2c_get_clientdata(client);
9593 u8 buf[7];
9694 int ret;
9795
98− if (!hym8563->valid) {
99− dev_warn(&client->dev, "no valid clock/calendar values available\n");
100− return -EPERM;
101− }
102−
10396 ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
10497 if (ret < 0)
10598 return ret;
10699
100+ if (buf[0] & HYM8563_SEC_VL) {
101+ dev_warn(&client->dev,
102+ "no valid clock/calendar values available\n");
103+ return -EINVAL;
104+ }
105+
107106 tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);
108107 tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);
109108 tm->tm_hour = bcd2bin(buf[2] & HYM8563_HOUR_MASK);
@@ -118,7 +117,6 @@ static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm) · 8 unmodified lines
118117 static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
119118 {
120119 struct i2c_client *client = to_i2c_client(dev);
121− struct hym8563 *hym8563 = i2c_get_clientdata(client);
122120 u8 buf[7];
123121 int ret;
124122
@@ -157,8 +155,6 @@ static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm) · 32 unmodified lines
157155 if (ret < 0)
158156 return ret;
159157
160− hym8563->valid = true;
161−
162158 return 0;
163159 }
164160
@@ -556,9 +552,8 @@ static int hym8563_probe(struct i2c_client *client, · 391 unmodified lines
556552 if (ret < 0)
557553 return ret;
558554
559− hym8563->valid = !(ret & HYM8563_SEC_VL);
560555 dev_dbg(&client->dev, "rtc information is %s\n",
561− hym8563->valid ? "valid" : "invalid");
556+ (ret & HYM8563_SEC_VL) ? "invalid" : "valid");
562557
563558 hym8563->rtc = devm_rtc_device_register(&client->dev, client->name,
564559 &hym8563_rtc_ops, THIS_MODULE);
drivers/rtc/rtc-moxart.c+1−4
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * MOXA ART RTC driver.
34 *
@@ -7,10 +8,6 @@ · 3 unmodified lines
78 *
89 * Based on code from
910 * Moxa Technology Co., Ltd. <www.moxa.com>
10− *
11− * This file is licensed under the terms of the GNU General Public
12− * License version 2. This program is licensed "as is" without any
13− * warranty of any kind, whether express or implied.
1411 */
1512
1613 #include <linux/init.h>
drivers/rtc/rtc-mt6397.c+1−9
@@ -297,15 +297,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) · 296 unmodified lines
297297
298298 rtc->rtc_dev->ops = &mtk_rtc_ops;
299299
300− ret = rtc_register_device(rtc->rtc_dev);
301− if (ret)
302− goto out_free_irq;
303−
304− return 0;
305−
306−out_free_irq:
307− free_irq(rtc->irq, rtc);
308− return ret;
300+ return rtc_register_device(rtc->rtc_dev);
309301 }
310302
311303 #ifdef CONFIG_PM_SLEEP
drivers/rtc/rtc-omap.c+1−1
@@ -616,7 +616,7 @@ static int rtc_pinconf_get(struct pinctrl_dev *pctldev, · 615 unmodified lines
616616 break;
617617 default:
618618 return -ENOTSUPP;
619− };
619+ }
620620
621621 *config = pinconf_to_config_packed(param, arg);
622622
drivers/rtc/rtc-pcf2127.c+2−4
@@ -199,11 +199,9 @@ static int pcf2127_rtc_ioctl(struct device *dev, · 198 unmodified lines
199199 if (ret)
200200 return ret;
201201
202− touser = touser & PCF2127_BIT_CTRL3_BLF ? 1 : 0;
202+ touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0;
203203
204− if (copy_to_user((void __user *)arg, &touser, sizeof(int)))
205− return -EFAULT;
206− return 0;
204+ return put_user(touser, (unsigned int __user *)arg);
207205 default:
208206 return -ENOIOCTLCMD;
209207 }
drivers/rtc/rtc-pcf85063.c+2−14
@@ -289,21 +289,9 @@ static int pcf85063_ioctl(struct device *dev, unsigned int cmd, · 288 unmodified lines
289289 if (ret < 0)
290290 return ret;
291291
292− if (status & PCF85063_REG_SC_OS)
293− dev_warn(&pcf85063->rtc->dev, "Voltage low, data loss detected.\n");
292+ status = status & PCF85063_REG_SC_OS ? RTC_VL_DATA_INVALID : 0;
294293
295− status &= PCF85063_REG_SC_OS;
296−
297− if (copy_to_user((void __user *)arg, &status, sizeof(int)))
298− return -EFAULT;
299−
300− return 0;
301−
302− case RTC_VL_CLR:
303− ret = regmap_update_bits(pcf85063->regmap, PCF85063_REG_SC,
304− PCF85063_REG_SC_OS, 0);
305−
306− return ret;
294+ return put_user(status, (unsigned int __user *)arg);
307295
308296 default:
309297 return -ENOIOCTLCMD;
drivers/rtc/rtc-pcf8523.c+3−3
@@ -282,11 +282,11 @@ static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd, · 281 unmodified lines
282282 ret = pcf8523_voltage_low(client);
283283 if (ret < 0)
284284 return ret;
285+ if (ret)
286+ ret = RTC_VL_BACKUP_LOW;
285287
286− if (copy_to_user((void __user *)arg, &ret, sizeof(int)))
287− return -EFAULT;
288+ return put_user(ret, (unsigned int __user *)arg);
288289
289− return 0;
290290 default:
291291 return -ENOIOCTLCMD;
292292 }
drivers/rtc/rtc-pcf8563.c+9−31
@@ -22,8 +22,8 @@ · 21 unmodified lines
2222
2323 #define PCF8563_REG_ST1 0x00 /* status */
2424 #define PCF8563_REG_ST2 0x01
25−#define PCF8563_BIT_AIE (1 << 1)
26−#define PCF8563_BIT_AF (1 << 3)
25+#define PCF8563_BIT_AIE BIT(1)
26+#define PCF8563_BIT_AF BIT(3)
2727 #define PCF8563_BITS_ST2_N (7 << 5)
2828
2929 #define PCF8563_REG_SC 0x02 /* datetime */
@@ -76,7 +76,6 @@ struct pcf8563 { · 46 unmodified lines
7676 * 1970...2069.
7777 */
7878 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
79− int voltage_low; /* incicates if a low_voltage was detected */
8079
8180 struct i2c_client *client;
8281 #ifdef CONFIG_COMMON_CLK
@@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) · 125 unmodified lines
208207 return err;
209208
210209 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
211− pcf8563->voltage_low = 1;
212210 dev_err(&client->dev,
213211 "low voltage detected, date/time is not reliable.\n");
214212 return -EINVAL;
@@ -276,43 +274,23 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm) · 61 unmodified lines
276274 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);
277275 }
278276
279−#ifdef CONFIG_RTC_INTF_DEV
280277 static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
281278 {
282− struct pcf8563 *pcf8563 = i2c_get_clientdata(to_i2c_client(dev));
283− struct rtc_time tm;
279+ struct i2c_client *client = to_i2c_client(dev);
280+ int ret;
284281
285282 switch (cmd) {
286283 case RTC_VL_READ:
287− if (pcf8563->voltage_low)
288− dev_info(dev, "low voltage detected, date/time is not reliable.\n");
289−
290− if (copy_to_user((void __user *)arg, &pcf8563->voltage_low,
291− sizeof(int)))
292− return -EFAULT;
293− return 0;
294− case RTC_VL_CLR:
295− /*
296− * Clear the VL bit in the seconds register in case
297− * the time has not been set already (which would
298− * have cleared it). This does not really matter
299− * because of the cached voltage_low value but do it
300− * anyway for consistency.
301− */
302− if (pcf8563_rtc_read_time(dev, &tm))
303− pcf8563_rtc_set_time(dev, &tm);
304−
305− /* Clear the cached value. */
306− pcf8563->voltage_low = 0;
284+ ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC);
285+ if (ret < 0)
286+ return ret;
307287
308− return 0;
288+ return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0,
289+ (unsigned int __user *)arg);
309290 default:
310291 return -ENOIOCTLCMD;
311292 }
312293 }
313−#else
314−#define pcf8563_rtc_ioctl NULL
315−#endif
316294
317295 static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
318296 {
drivers/rtc/rtc-rv3028.c+2−15
@@ -428,21 +428,8 @@ static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 427 unmodified lines
428428 if (ret < 0)
429429 return ret;
430430
431− if (status & RV3028_STATUS_PORF)
432− dev_warn(&rv3028->rtc->dev, "Voltage low, data loss detected.\n");
433−
434− status &= RV3028_STATUS_PORF;
435−
436− if (copy_to_user((void __user *)arg, &status, sizeof(int)))
437− return -EFAULT;
438−
439− return 0;
440−
441− case RTC_VL_CLR:
442− ret = regmap_update_bits(rv3028->regmap, RV3028_STATUS,
443− RV3028_STATUS_PORF, 0);
444−
445− return ret;
431+ status = status & RV3028_STATUS_PORF ? RTC_VL_DATA_INVALID : 0;
432+ return put_user(status, (unsigned int __user *)arg);
446433
447434 default:
448435 return -ENOIOCTLCMD;
drivers/rtc/rtc-rv3029c2.c+182−260
@@ -109,10 +109,8 @@ · 108 unmodified lines
109109 #define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */
110110
111111 /* user ram section */
112−#define RV3029_USR1_RAM_PAGE 0x38
113−#define RV3029_USR1_SECTION_LEN 0x04
114−#define RV3029_USR2_RAM_PAGE 0x3C
115−#define RV3029_USR2_SECTION_LEN 0x04
112+#define RV3029_RAM_PAGE 0x38
113+#define RV3029_RAM_SECTION_LEN 8
116114
117115 struct rv3029_data {
118116 struct device *dev;
@@ -121,77 +119,13 @@ struct rv3029_data { · 2 unmodified lines
121119 int irq;
122120 };
123121
124−static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf,
125− unsigned int len)
126−{
127− struct rv3029_data *rv3029 = dev_get_drvdata(dev);
128−
129− if ((reg > RV3029_USR1_RAM_PAGE + 7) ||
130− (reg + len > RV3029_USR1_RAM_PAGE + 8))
131− return -EINVAL;
132−
133− return regmap_bulk_read(rv3029->regmap, reg, buf, len);
134−}
135−
136−static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[],
137− unsigned int len)
138−{
139− struct rv3029_data *rv3029 = dev_get_drvdata(dev);
140−
141− if ((reg > RV3029_USR1_RAM_PAGE + 7) ||
142− (reg + len > RV3029_USR1_RAM_PAGE + 8))
143− return -EINVAL;
144−
145− return regmap_bulk_write(rv3029->regmap, reg, buf, len);
146−}
147−
148−static int rv3029_update_bits(struct device *dev, u8 reg, u8 mask, u8 set)
149−{
150− u8 buf;
151− int ret;
152−
153− ret = rv3029_read_regs(dev, reg, &buf, 1);
154− if (ret < 0)
155− return ret;
156− buf &= ~mask;
157− buf |= set & mask;
158− ret = rv3029_write_regs(dev, reg, &buf, 1);
159− if (ret < 0)
160− return ret;
161−
162− return 0;
163−}
164−
165−static int rv3029_get_sr(struct device *dev, u8 *buf)
166−{
167− int ret = rv3029_read_regs(dev, RV3029_STATUS, buf, 1);
168−
169− if (ret < 0)
170− return -EIO;
171− dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
172− return 0;
173−}
174−
175−static int rv3029_set_sr(struct device *dev, u8 val)
176−{
177− u8 buf[1];
178− int sr;
179−
180− buf[0] = val;
181− sr = rv3029_write_regs(dev, RV3029_STATUS, buf, 1);
182− dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]);
183− if (sr < 0)
184− return -EIO;
185− return 0;
186−}
187−
188−static int rv3029_eeprom_busywait(struct device *dev)
122+static int rv3029_eeprom_busywait(struct rv3029_data *rv3029)
189123 {
124+ unsigned int sr;
190125 int i, ret;
191− u8 sr;
192126
193127 for (i = 100; i > 0; i--) {
194− ret = rv3029_get_sr(dev, &sr);
128+ ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
195129 if (ret < 0)
196130 break;
197131 if (!(sr & RV3029_STATUS_EEBUSY))
@@ -199,126 +133,128 @@ static int rv3029_eeprom_busywait(struct device *dev) · 1 unmodified line
199133 usleep_range(1000, 10000);
200134 }
201135 if (i <= 0) {
202− dev_err(dev, "EEPROM busy wait timeout.\n");
136+ dev_err(rv3029->dev, "EEPROM busy wait timeout.\n");
203137 return -ETIMEDOUT;
204138 }
205139
206140 return ret;
207141 }
208142
209−static int rv3029_eeprom_exit(struct device *dev)
143+static int rv3029_eeprom_exit(struct rv3029_data *rv3029)
210144 {
211145 /* Re-enable eeprom refresh */
212− return rv3029_update_bits(dev, RV3029_ONOFF_CTRL,
146+ return regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL,
213147 RV3029_ONOFF_CTRL_EERE,
214148 RV3029_ONOFF_CTRL_EERE);
215149 }
216150
217−static int rv3029_eeprom_enter(struct device *dev)
151+static int rv3029_eeprom_enter(struct rv3029_data *rv3029)
218152 {
153+ unsigned int sr;
219154 int ret;
220− u8 sr;
221155
222156 /* Check whether we are in the allowed voltage range. */
223− ret = rv3029_get_sr(dev, &sr);
157+ ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
224158 if (ret < 0)
225159 return ret;
226− if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
160+ if (sr & RV3029_STATUS_VLOW2)
161+ return -ENODEV;
162+ if (sr & RV3029_STATUS_VLOW1) {
227163 /* We clear the bits and retry once just in case
228164 * we had a brown out in early startup.
229165 */
230− sr &= ~RV3029_STATUS_VLOW1;
231− sr &= ~RV3029_STATUS_VLOW2;
232− ret = rv3029_set_sr(dev, sr);
166+ ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS,
167+ RV3029_STATUS_VLOW1, 0);
233168 if (ret < 0)
234169 return ret;
235170 usleep_range(1000, 10000);
236− ret = rv3029_get_sr(dev, &sr);
171+ ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
237172 if (ret < 0)
238173 return ret;
239− if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {
240− dev_err(dev,
174+ if (sr & RV3029_STATUS_VLOW1) {
175+ dev_err(rv3029->dev,
241176 "Supply voltage is too low to safely access the EEPROM.\n");
242177 return -ENODEV;
243178 }
244179 }
245180
246181 /* Disable eeprom refresh. */
247− ret = rv3029_update_bits(dev, RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE,
248− 0);
182+ ret = regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL,
183+ RV3029_ONOFF_CTRL_EERE, 0);
249184 if (ret < 0)
250185 return ret;
251186
252187 /* Wait for any previous eeprom accesses to finish. */
253− ret = rv3029_eeprom_busywait(dev);
188+ ret = rv3029_eeprom_busywait(rv3029);
254189 if (ret < 0)
255− rv3029_eeprom_exit(dev);
190+ rv3029_eeprom_exit(rv3029);
256191
257192 return ret;
258193 }
259194
260−static int rv3029_eeprom_read(struct device *dev, u8 reg,
195+static int rv3029_eeprom_read(struct rv3029_data *rv3029, u8 reg,
261196 u8 buf[], size_t len)
262197 {
263198 int ret, err;
264199
265− err = rv3029_eeprom_enter(dev);
200+ err = rv3029_eeprom_enter(rv3029);
266201 if (err < 0)
267202 return err;
268203
269− ret = rv3029_read_regs(dev, reg, buf, len);
204+ ret = regmap_bulk_read(rv3029->regmap, reg, buf, len);
270205
271− err = rv3029_eeprom_exit(dev);
206+ err = rv3029_eeprom_exit(rv3029);
272207 if (err < 0)
273208 return err;
274209
275210 return ret;
276211 }
277212
278−static int rv3029_eeprom_write(struct device *dev, u8 reg,
213+static int rv3029_eeprom_write(struct rv3029_data *rv3029, u8 reg,
279214 u8 const buf[], size_t len)
280215 {
216+ unsigned int tmp;
281217 int ret, err;
282218 size_t i;
283− u8 tmp;
284219
285− err = rv3029_eeprom_enter(dev);
220+ err = rv3029_eeprom_enter(rv3029);
286221 if (err < 0)
287222 return err;
288223
289224 for (i = 0; i < len; i++, reg++) {
290− ret = rv3029_read_regs(dev, reg, &tmp, 1);
225+ ret = regmap_read(rv3029->regmap, reg, &tmp);
291226 if (ret < 0)
292227 break;
293228 if (tmp != buf[i]) {
294− ret = rv3029_write_regs(dev, reg, &buf[i], 1);
229+ tmp = buf[i];
230+ ret = regmap_write(rv3029->regmap, reg, tmp);
295231 if (ret < 0)
296232 break;
297233 }
298− ret = rv3029_eeprom_busywait(dev);
234+ ret = rv3029_eeprom_busywait(rv3029);
299235 if (ret < 0)
300236 break;
301237 }
302238
303− err = rv3029_eeprom_exit(dev);
239+ err = rv3029_eeprom_exit(rv3029);
304240 if (err < 0)
305241 return err;
306242
307243 return ret;
308244 }
309245
310−static int rv3029_eeprom_update_bits(struct device *dev,
246+static int rv3029_eeprom_update_bits(struct rv3029_data *rv3029,
311247 u8 reg, u8 mask, u8 set)
312248 {
313249 u8 buf;
314250 int ret;
315251
316− ret = rv3029_eeprom_read(dev, reg, &buf, 1);
252+ ret = rv3029_eeprom_read(rv3029, reg, &buf, 1);
317253 if (ret < 0)
318254 return ret;
319255 buf &= ~mask;
320256 buf |= set & mask;
321− ret = rv3029_eeprom_write(dev, reg, &buf, 1);
257+ ret = rv3029_eeprom_write(rv3029, reg, &buf, 1);
322258 if (ret < 0)
323259 return ret;
324260
@@ -330,20 +266,20 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 5 unmodified lines
330266 struct device *dev = dev_id;
331267 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
332268 struct mutex *lock = &rv3029->rtc->ops_lock;
269+ unsigned int flags, controls;
333270 unsigned long events = 0;
334− u8 flags, controls;
335271 int ret;
336272
337273 mutex_lock(lock);
338274
339− ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
275+ ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls);
340276 if (ret) {
341277 dev_warn(dev, "Read IRQ Control Register error %d\n", ret);
342278 mutex_unlock(lock);
343279 return IRQ_NONE;
344280 }
345281
346− ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
282+ ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags);
347283 if (ret) {
348284 dev_warn(dev, "Read IRQ Flags Register error %d\n", ret);
349285 mutex_unlock(lock);
@@ -358,8 +294,8 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 8 unmodified lines
358294
359295 if (events) {
360296 rtc_update_irq(rv3029->rtc, 1, events);
361− rv3029_write_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
362− rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
297+ regmap_write(rv3029->regmap, RV3029_IRQ_FLAGS, flags);
298+ regmap_write(rv3029->regmap, RV3029_IRQ_CTRL, controls);
363299 }
364300 mutex_unlock(lock);
365301
@@ -368,22 +304,22 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 2 unmodified lines
368304
369305 static int rv3029_read_time(struct device *dev, struct rtc_time *tm)
370306 {
371− u8 buf[1];
307+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
308+ unsigned int sr;
372309 int ret;
373310 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };
374311
375− ret = rv3029_get_sr(dev, buf);
376− if (ret < 0) {
377− dev_err(dev, "%s: reading SR failed\n", __func__);
378− return -EIO;
379− }
312+ ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
313+ if (ret < 0)
314+ return ret;
315+
316+ if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON))
317+ return -EINVAL;
380318
381− ret = rv3029_read_regs(dev, RV3029_W_SEC, regs,
319+ ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs,
382320 RV3029_WATCH_SECTION_LEN);
383− if (ret < 0) {
384− dev_err(dev, "%s: reading RTC section failed\n", __func__);
321+ if (ret < 0)
385322 return ret;
386− }
387323
388324 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]);
389325 tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]);
@@ -411,34 +347,24 @@ static int rv3029_read_time(struct device *dev, struct rtc_time *tm) · 21 unmodified lines
411347
412348 static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
413349 {
350+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
414351 struct rtc_time *const tm = &alarm->time;
352+ unsigned int controls, flags;
415353 int ret;
416− u8 regs[8], controls, flags;
417−
418− ret = rv3029_get_sr(dev, regs);
419− if (ret < 0) {
420− dev_err(dev, "%s: reading SR failed\n", __func__);
421− return -EIO;
422− }
354+ u8 regs[8];
423355
424− ret = rv3029_read_regs(dev, RV3029_A_SC, regs,
356+ ret = regmap_bulk_read(rv3029->regmap, RV3029_A_SC, regs,
425357 RV3029_ALARM_SECTION_LEN);
426−
427− if (ret < 0) {
428− dev_err(dev, "%s: reading alarm section failed\n", __func__);
358+ if (ret < 0)
429359 return ret;
430− }
431360
432− ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
433− if (ret) {
434− dev_err(dev, "Read IRQ Control Register error %d\n", ret);
361+ ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls);
362+ if (ret)
435363 return ret;
436− }
437− ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);
438− if (ret < 0) {
439− dev_err(dev, "Read IRQ Flags Register error %d\n", ret);
364+
365+ ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags);
366+ if (ret < 0)
440367 return ret;
441− }
442368
443369 tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f);
444370 tm->tm_min = bcd2bin(regs[RV3029_A_MN - RV3029_A_SC] & 0x7f);
@@ -456,50 +382,20 @@ static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 11 unmodified lines
456382
457383 static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable)
458384 {
459− int ret;
460− u8 controls;
461−
462− ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
463− if (ret < 0) {
464− dev_warn(dev, "Read IRQ Control Register error %d\n", ret);
465− return ret;
466− }
467−
468− /* enable/disable AIE irq */
469− if (enable)
470− controls |= RV3029_IRQ_CTRL_AIE;
471− else
472− controls &= ~RV3029_IRQ_CTRL_AIE;
473−
474− ret = rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1);
475− if (ret < 0) {
476− dev_err(dev, "can't update INT reg\n");
477− return ret;
478− }
385+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
479386
480− return 0;
387+ return regmap_update_bits(rv3029->regmap, RV3029_IRQ_CTRL,
388+ RV3029_IRQ_CTRL_AIE,
389+ enable ? RV3029_IRQ_CTRL_AIE : 0);
481390 }
482391
483392 static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
484393 {
394+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
485395 struct rtc_time *const tm = &alarm->time;
486396 int ret;
487397 u8 regs[8];
488398
489− /*
490− * The clock has an 8 bit wide bcd-coded register (they never learn)
491− * for the year. tm_year is an offset from 1900 and we are interested
492− * in the 2000-2099 range, so any value less than 100 is invalid.
493− */
494− if (tm->tm_year < 100)
495− return -EINVAL;
496−
497− ret = rv3029_get_sr(dev, regs);
498− if (ret < 0) {
499− dev_err(dev, "%s: reading SR failed\n", __func__);
500− return -EIO;
501− }
502−
503399 /* Activate all the alarms with AE_x bit */
504400 regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X;
505401 regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min) | RV3029_A_AE_X;
@@ -515,39 +411,20 @@ static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) · 9 unmodified lines
515411 | RV3029_A_AE_X;
516412
517413 /* Write the alarm */
518− ret = rv3029_write_regs(dev, RV3029_A_SC, regs,
414+ ret = regmap_bulk_write(rv3029->regmap, RV3029_A_SC, regs,
519415 RV3029_ALARM_SECTION_LEN);
520416 if (ret < 0)
521417 return ret;
522418
523− if (alarm->enabled) {
524− /* enable AIE irq */
525− ret = rv3029_alarm_irq_enable(dev, 1);
526− if (ret)
527− return ret;
528− } else {
529− /* disable AIE irq */
530− ret = rv3029_alarm_irq_enable(dev, 0);
531− if (ret)
532− return ret;
533− }
534−
535− return 0;
419+ return rv3029_alarm_irq_enable(dev, alarm->enabled);
536420 }
537421
538422 static int rv3029_set_time(struct device *dev, struct rtc_time *tm)
539423 {
424+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
540425 u8 regs[8];
541426 int ret;
542427
543− /*
544− * The clock has an 8 bit wide bcd-coded register (they never learn)
545− * for the year. tm_year is an offset from 1900 and we are interested
546− * in the 2000-2099 range, so any value less than 100 is invalid.
547− */
548− if (tm->tm_year < 100)
549− return -EINVAL;
550−
551428 regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec);
552429 regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min);
553430 regs[RV3029_W_HOURS - RV3029_W_SEC] = bin2bcd(tm->tm_hour);
@@ -556,24 +433,55 @@ static int rv3029_set_time(struct device *dev, struct rtc_time *tm) · 2 unmodified lines
556433 regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7;
557434 regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100);
558435
559− ret = rv3029_write_regs(dev, RV3029_W_SEC, regs,
436+ ret = regmap_bulk_write(rv3029->regmap, RV3029_W_SEC, regs,
560437 RV3029_WATCH_SECTION_LEN);
561438 if (ret < 0)
562439 return ret;
563440
564− ret = rv3029_get_sr(dev, regs);
565− if (ret < 0) {
566− dev_err(dev, "%s: reading SR failed\n", __func__);
567− return ret;
568− }
569− /* clear PON bit */
570− ret = rv3029_set_sr(dev, (regs[0] & ~RV3029_STATUS_PON));
571− if (ret < 0) {
572− dev_err(dev, "%s: reading SR failed\n", __func__);
573− return ret;
441+ /* clear PON and VLOW2 bits */
442+ return regmap_update_bits(rv3029->regmap, RV3029_STATUS,
443+ RV3029_STATUS_PON | RV3029_STATUS_VLOW2, 0);
444+}
445+
446+static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
447+{
448+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
449+ unsigned long vl = 0;
450+ int sr, ret = 0;
451+
452+ switch (cmd) {
453+ case RTC_VL_READ:
454+ ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
455+ if (ret < 0)
456+ return ret;
457+
458+ if (sr & RV3029_STATUS_VLOW1)
459+ vl = RTC_VL_ACCURACY_LOW;
460+
461+ if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON))
462+ vl |= RTC_VL_DATA_INVALID;
463+
464+ return put_user(vl, (unsigned int __user *)arg);
465+
466+ case RTC_VL_CLR:
467+ return regmap_update_bits(rv3029->regmap, RV3029_STATUS,
468+ RV3029_STATUS_VLOW1, 0);
469+
470+ default:
471+ return -ENOIOCTLCMD;
574472 }
473+}
575474
576− return 0;
475+static int rv3029_nvram_write(void *priv, unsigned int offset, void *val,
476+ size_t bytes)
477+{
478+ return regmap_bulk_write(priv, RV3029_RAM_PAGE + offset, val, bytes);
479+}
480+
481+static int rv3029_nvram_read(void *priv, unsigned int offset, void *val,
482+ size_t bytes)
483+{
484+ return regmap_bulk_read(priv, RV3029_RAM_PAGE + offset, val, bytes);
577485 }
578486
579487 static const struct rv3029_trickle_tab_elem {
@@ -635,6 +543,7 @@ static const struct rv3029_trickle_tab_elem { · 55 unmodified lines
635543
636544 static void rv3029_trickle_config(struct device *dev)
637545 {
546+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
638547 struct device_node *of_node = dev->of_node;
639548 const struct rv3029_trickle_tab_elem *elem;
640549 int i, err;
@@ -661,7 +570,7 @@ static void rv3029_trickle_config(struct device *dev) · 20 unmodified lines
661570 "Trickle charger enabled at %d ohms resistance.\n",
662571 elem->r);
663572 }
664− err = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,
573+ err = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL,
665574 RV3029_TRICKLE_MASK,
666575 trickle_set_bits);
667576 if (err < 0)
@@ -670,12 +579,12 @@ static void rv3029_trickle_config(struct device *dev) · 2 unmodified lines
670579
671580 #ifdef CONFIG_RTC_DRV_RV3029_HWMON
672581
673−static int rv3029_read_temp(struct device *dev, int *temp_mC)
582+static int rv3029_read_temp(struct rv3029_data *rv3029, int *temp_mC)
674583 {
584+ unsigned int temp;
675585 int ret;
676− u8 temp;
677586
678− ret = rv3029_read_regs(dev, RV3029_TEMP_PAGE, &temp, 1);
587+ ret = regmap_read(rv3029->regmap, RV3029_TEMP_PAGE, &temp);
679588 if (ret < 0)
680589 return ret;
681590
@@ -688,9 +597,10 @@ static ssize_t rv3029_hwmon_show_temp(struct device *dev, · 6 unmodified lines
688597 struct device_attribute *attr,
689598 char *buf)
690599 {
600+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
691601 int ret, temp_mC;
692602
693− ret = rv3029_read_temp(dev, &temp_mC);
603+ ret = rv3029_read_temp(rv3029, &temp_mC);
694604 if (ret < 0)
695605 return ret;
696606
@@ -702,9 +612,10 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 5 unmodified lines
702612 const char *buf,
703613 size_t count)
704614 {
615+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
616+ unsigned int th_set_bits = 0;
705617 unsigned long interval_ms;
706618 int ret;
707− u8 th_set_bits = 0;
708619
709620 ret = kstrtoul(buf, 10, &interval_ms);
710621 if (ret < 0)
@@ -715,7 +626,7 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 4 unmodified lines
715626 if (interval_ms >= 16000)
716627 th_set_bits |= RV3029_EECTRL_THP;
717628 }
718− ret = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,
629+ ret = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL,
719630 RV3029_EECTRL_THE | RV3029_EECTRL_THP,
720631 th_set_bits);
721632 if (ret < 0)
@@ -728,10 +639,11 @@ static ssize_t rv3029_hwmon_show_update_interval(struct device *dev, · 6 unmodified lines
728639 struct device_attribute *attr,
729640 char *buf)
730641 {
642+ struct rv3029_data *rv3029 = dev_get_drvdata(dev);
731643 int ret, interval_ms;
732644 u8 eectrl;
733645
734− ret = rv3029_eeprom_read(dev, RV3029_CONTROL_E2P_EECTRL,
646+ ret = rv3029_eeprom_read(rv3029, RV3029_CONTROL_E2P_EECTRL,
735647 &eectrl, 1);
736648 if (ret < 0)
737649 return ret;
@@ -785,14 +697,23 @@ static void rv3029_hwmon_register(struct device *dev, const char *name) · 47 unmodified lines
785697 static struct rtc_class_ops rv3029_rtc_ops = {
786698 .read_time = rv3029_read_time,
787699 .set_time = rv3029_set_time,
700+ .ioctl = rv3029_ioctl,
788701 };
789702
790703 static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
791704 const char *name)
792705 {
793706 struct rv3029_data *rv3029;
707+ struct nvmem_config nvmem_cfg = {
708+ .name = "rv3029_nvram",
709+ .word_size = 1,
710+ .stride = 1,
711+ .size = RV3029_RAM_SECTION_LEN,
712+ .type = NVMEM_TYPE_BATTERY_BACKED,
713+ .reg_read = rv3029_nvram_read,
714+ .reg_write = rv3029_nvram_write,
715+ };
794716 int rc = 0;
795− u8 buf[1];
796717
797718 rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL);
798719 if (!rv3029)
@@ -803,21 +724,12 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, · 4 unmodified lines
803724 rv3029->dev = dev;
804725 dev_set_drvdata(dev, rv3029);
805726
806− rc = rv3029_get_sr(dev, buf);
807− if (rc < 0) {
808− dev_err(dev, "reading status failed\n");
809− return rc;
810− }
811−
812727 rv3029_trickle_config(dev);
813728 rv3029_hwmon_register(dev, name);
814729
815− rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops,
816− THIS_MODULE);
817− if (IS_ERR(rv3029->rtc)) {
818− dev_err(dev, "unable to register the class device\n");
730+ rv3029->rtc = devm_rtc_allocate_device(dev);
731+ if (IS_ERR(rv3029->rtc))
819732 return PTR_ERR(rv3029->rtc);
820− }
821733
822734 if (rv3029->irq > 0) {
823735 rc = devm_request_threaded_irq(dev, rv3029->irq,
@@ -834,20 +746,48 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, · 10 unmodified lines
834746 }
835747 }
836748
749+ rv3029->rtc->ops = &rv3029_rtc_ops;
750+ rv3029->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
751+ rv3029->rtc->range_max = RTC_TIMESTAMP_END_2079;
752+
753+ rc = rtc_register_device(rv3029->rtc);
754+ if (rc)
755+ return rc;
756+
757+ nvmem_cfg.priv = rv3029->regmap;
758+ rtc_nvmem_register(rv3029->rtc, &nvmem_cfg);
759+
837760 return 0;
838761 }
839762
763+static const struct regmap_range rv3029_holes_range[] = {
764+ regmap_reg_range(0x05, 0x07),
765+ regmap_reg_range(0x0f, 0x0f),
766+ regmap_reg_range(0x17, 0x17),
767+ regmap_reg_range(0x1a, 0x1f),
768+ regmap_reg_range(0x21, 0x27),
769+ regmap_reg_range(0x34, 0x37),
770+};
771+
772+static const struct regmap_access_table rv3029_regs = {
773+ .no_ranges = rv3029_holes_range,
774+ .n_no_ranges = ARRAY_SIZE(rv3029_holes_range),
775+};
776+
777+static const struct regmap_config config = {
778+ .reg_bits = 8,
779+ .val_bits = 8,
780+ .rd_table = &rv3029_regs,
781+ .wr_table = &rv3029_regs,
782+ .max_register = 0x3f,
783+};
784+
840785 #if IS_ENABLED(CONFIG_I2C)
841786
842787 static int rv3029_i2c_probe(struct i2c_client *client,
843788 const struct i2c_device_id *id)
844789 {
845790 struct regmap *regmap;
846− static const struct regmap_config config = {
847− .reg_bits = 8,
848− .val_bits = 8,
849− };
850−
851791 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
852792 I2C_FUNC_SMBUS_BYTE)) {
853793 dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n");
@@ -855,11 +795,8 @@ static int rv3029_i2c_probe(struct i2c_client *client, · 1 unmodified line
855795 }
856796
857797 regmap = devm_regmap_init_i2c(client, &config);
858− if (IS_ERR(regmap)) {
859− dev_err(&client->dev, "%s: regmap allocation failed: %ld\n",
860− __func__, PTR_ERR(regmap));
798+ if (IS_ERR(regmap))
861799 return PTR_ERR(regmap);
862− }
863800
864801 return rv3029_probe(&client->dev, regmap, client->irq, client->name);
865802 }
@@ -873,24 +810,20 @@ MODULE_DEVICE_TABLE(i2c, rv3029_id); · 7 unmodified lines
873810
874811 static const struct of_device_id rv3029_of_match[] = {
875812 { .compatible = "microcrystal,rv3029" },
876− /* Backward compatibility only, do not use compatibles below: */
877− { .compatible = "rv3029" },
878− { .compatible = "rv3029c2" },
879− { .compatible = "mc,rv3029c2" },
880813 { }
881814 };
882815 MODULE_DEVICE_TABLE(of, rv3029_of_match);
883816
884817 static struct i2c_driver rv3029_driver = {
885818 .driver = {
886− .name = "rtc-rv3029c2",
819+ .name = "rv3029",
887820 .of_match_table = of_match_ptr(rv3029_of_match),
888821 },
889822 .probe = rv3029_i2c_probe,
890823 .id_table = rv3029_id,
891824 };
892825
893−static int rv3029_register_driver(void)
826+static int __init rv3029_register_driver(void)
894827 {
895828 return i2c_add_driver(&rv3029_driver);
896829 }
@@ -902,7 +835,7 @@ static void rv3029_unregister_driver(void) · 5 unmodified lines
902835
903836 #else
904837
905−static int rv3029_register_driver(void)
838+static int __init rv3029_register_driver(void)
906839 {
907840 return 0;
908841 }
@@ -917,18 +850,11 @@ static void rv3029_unregister_driver(void) · 8 unmodified lines
917850
918851 static int rv3049_probe(struct spi_device *spi)
919852 {
920− static const struct regmap_config config = {
921− .reg_bits = 8,
922− .val_bits = 8,
923− };
924853 struct regmap *regmap;
925854
926855 regmap = devm_regmap_init_spi(spi, &config);
927− if (IS_ERR(regmap)) {
928− dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
929− __func__, PTR_ERR(regmap));
856+ if (IS_ERR(regmap))
930857 return PTR_ERR(regmap);
931− }
932858
933859 return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049");
934860 }
@@ -940,24 +866,24 @@ static struct spi_driver rv3049_driver = { · 5 unmodified lines
940866 .probe = rv3049_probe,
941867 };
942868
943−static int rv3049_register_driver(void)
869+static int __init rv3049_register_driver(void)
944870 {
945871 return spi_register_driver(&rv3049_driver);
946872 }
947873
948−static void rv3049_unregister_driver(void)
874+static void __exit rv3049_unregister_driver(void)
949875 {
950876 spi_unregister_driver(&rv3049_driver);
951877 }
952878
953879 #else
954880
955−static int rv3049_register_driver(void)
881+static int __init rv3049_register_driver(void)
956882 {
957883 return 0;
958884 }
959885
960−static void rv3049_unregister_driver(void)
886+static void __exit rv3049_unregister_driver(void)
961887 {
962888 }
963889
@@ -968,16 +894,12 @@ static int __init rv30x9_init(void) · 4 unmodified lines
968894 int ret;
969895
970896 ret = rv3029_register_driver();
971− if (ret) {
972− pr_err("Failed to register rv3029 driver: %d\n", ret);
897+ if (ret)
973898 return ret;
974− }
975899
976900 ret = rv3049_register_driver();
977− if (ret) {
978− pr_err("Failed to register rv3049 driver: %d\n", ret);
901+ if (ret)
979902 rv3029_unregister_driver();
980− }
981903
982904 return ret;
983905 }
drivers/rtc/rtc-rv8803.c+7−9
@@ -411,6 +411,7 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 410 unmodified lines
411411 {
412412 struct i2c_client *client = to_i2c_client(dev);
413413 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
414+ unsigned int vl = 0;
414415 int flags, ret = 0;
415416
416417 switch (cmd) {
@@ -419,18 +420,15 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines
419420 if (flags < 0)
420421 return flags;
421422
422− if (flags & RV8803_FLAG_V1F)
423+ if (flags & RV8803_FLAG_V1F) {
423424 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
425+ vl = RTC_VL_ACCURACY_LOW;
426+ }
424427
425428 if (flags & RV8803_FLAG_V2F)
426− dev_warn(&client->dev, "Voltage low, data loss detected.\n");
427−
428− flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F;
429+ vl |= RTC_VL_DATA_INVALID;
429430
430− if (copy_to_user((void __user *)arg, &flags, sizeof(int)))
431− return -EFAULT;
432−
433− return 0;
431+ return put_user(vl, (unsigned int __user *)arg);
434432
435433 case RTC_VL_CLR:
436434 mutex_lock(&rv8803->flags_lock);
@@ -440,7 +438,7 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 3 unmodified lines
440438 return flags;
441439 }
442440
443− flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F);
441+ flags &= ~RV8803_FLAG_V1F;
444442 ret = rv8803_write_reg(client, RV8803_FLAG, flags);
445443 mutex_unlock(&rv8803->flags_lock);
446444 if (ret)
drivers/rtc/rtc-rx8010.c+4−21
@@ -389,9 +389,8 @@ static int rx8010_alarm_irq_enable(struct device *dev, · 388 unmodified lines
389389
390390 static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
391391 {
392− struct i2c_client *client = to_i2c_client(dev);
393392 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
394− int ret, tmp;
393+ int tmp;
395394 int flagreg;
396395
397396 switch (cmd) {
@@ -400,24 +399,8 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines
400399 if (flagreg < 0)
401400 return flagreg;
402401
403− tmp = !!(flagreg & RX8010_FLAG_VLF);
404− if (copy_to_user((void __user *)arg, &tmp, sizeof(int)))
405− return -EFAULT;
406−
407− return 0;
408−
409− case RTC_VL_CLR:
410− flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG);
411− if (flagreg < 0) {
412− return flagreg;
413− }
414−
415− flagreg &= ~RX8010_FLAG_VLF;
416− ret = i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg);
417− if (ret < 0)
418− return ret;
419−
420− return 0;
402+ tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0;
403+ return put_user(tmp, (unsigned int __user *)arg);
421404
422405 default:
423406 return -ENOIOCTLCMD;
@@ -482,7 +465,7 @@ static int rx8010_probe(struct i2c_client *client, · 58 unmodified lines
482465
483466 rx8010->rtc->max_user_freq = 1;
484467
485− return err;
468+ return 0;
486469 }
487470
488471 static struct i2c_driver rx8010_driver = {
drivers/rtc/rtc-rx8025.c+14−13
@@ -67,7 +67,6 @@ static const struct i2c_device_id rx8025_id[] = { · 66 unmodified lines
6767 MODULE_DEVICE_TABLE(i2c, rx8025_id);
6868
6969 struct rx8025_data {
70− struct i2c_client *client;
7170 struct rtc_device *rtc;
7271 u8 ctrl1;
7372 };
@@ -103,10 +102,10 @@ static s32 rx8025_write_regs(const struct i2c_client *client, · 29 unmodified lines
103102
104103 static int rx8025_check_validity(struct device *dev)
105104 {
106− struct rx8025_data *rx8025 = dev_get_drvdata(dev);
105+ struct i2c_client *client = to_i2c_client(dev);
107106 int ctrl2;
108107
109− ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
108+ ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
110109 if (ctrl2 < 0)
111110 return ctrl2;
112111
@@ -178,6 +177,7 @@ out: · 65 unmodified lines
178177
179178 static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
180179 {
180+ struct i2c_client *client = to_i2c_client(dev);
181181 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
182182 u8 date[7];
183183 int err;
@@ -186,7 +186,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 2 unmodified lines
186186 if (err)
187187 return err;
188188
189− err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
189+ err = rx8025_read_regs(client, RX8025_REG_SEC, 7, date);
190190 if (err)
191191 return err;
192192
@@ -211,6 +211,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 18 unmodified lines
211211
212212 static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
213213 {
214+ struct i2c_client *client = to_i2c_client(dev);
214215 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
215216 u8 date[7];
216217 int ret;
@@ -237,11 +238,11 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) · 20 unmodified lines
237238
238239 dev_dbg(dev, "%s: write %7ph\n", __func__, date);
239240
240− ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
241+ ret = rx8025_write_regs(client, RX8025_REG_SEC, 7, date);
241242 if (ret < 0)
242243 return ret;
243244
244− return rx8025_reset_validity(rx8025->client);
245+ return rx8025_reset_validity(client);
245246 }
246247
247248 static int rx8025_init_client(struct i2c_client *client)
@@ -251,7 +252,7 @@ static int rx8025_init_client(struct i2c_client *client) · 3 unmodified lines
251252 int need_clear = 0;
252253 int err;
253254
254− err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl);
255+ err = rx8025_read_regs(client, RX8025_REG_CTRL1, 2, ctrl);
255256 if (err)
256257 goto out;
257258
@@ -280,8 +281,8 @@ out: · 22 unmodified lines
280281 /* Alarm support */
281282 static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
282283 {
284+ struct i2c_client *client = to_i2c_client(dev);
283285 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
284− struct i2c_client *client = rx8025->client;
285286 u8 ald[2];
286287 int ctrl2, err;
287288
@@ -347,18 +348,18 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 59 unmodified lines
347348
348349 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {
349350 rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE;
350− err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
351+ err = rx8025_write_reg(client, RX8025_REG_CTRL1,
351352 rx8025->ctrl1);
352353 if (err)
353354 return err;
354355 }
355− err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald);
356+ err = rx8025_write_regs(client, RX8025_REG_ALDMIN, 2, ald);
356357 if (err)
357358 return err;
358359
359360 if (t->enabled) {
360361 rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE;
361− err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
362+ err = rx8025_write_reg(client, RX8025_REG_CTRL1,
362363 rx8025->ctrl1);
363364 if (err)
364365 return err;
@@ -369,6 +370,7 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 4 unmodified lines
369370
370371 static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
371372 {
373+ struct i2c_client *client = to_i2c_client(dev);
372374 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
373375 u8 ctrl1;
374376 int err;
@@ -381,7 +383,7 @@ static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled) · 6 unmodified lines
381383
382384 if (ctrl1 != rx8025->ctrl1) {
383385 rx8025->ctrl1 = ctrl1;
384− err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,
386+ err = rx8025_write_reg(client, RX8025_REG_CTRL1,
385387 rx8025->ctrl1);
386388 if (err)
387389 return err;
@@ -516,7 +518,6 @@ static int rx8025_probe(struct i2c_client *client, · 128 unmodified lines
516518 if (!rx8025)
517519 return -ENOMEM;
518520
519− rx8025->client = client;
520521 i2c_set_clientdata(client, rx8025);
521522
522523 err = rx8025_init_client(client);
drivers/rtc/rtc-stm32.c+4−1
@@ -897,8 +897,11 @@ static int stm32_rtc_resume(struct device *dev) · 896 unmodified lines
897897 }
898898
899899 ret = stm32_rtc_wait_sync(rtc);
900− if (ret < 0)
900+ if (ret < 0) {
901+ if (rtc->data->has_pclk)
902+ clk_disable_unprepare(rtc->pclk);
901903 return ret;
904+ }
902905
903906 if (device_may_wakeup(dev))
904907 return disable_irq_wake(rtc->irq_alarm);
drivers/rtc/rtc-tps6586x.c+3−1
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #include <linux/device.h>
2424 #include <linux/err.h>
2525 #include <linux/init.h>
26+#include <linux/irq.h>
2627 #include <linux/kernel.h>
2728 #include <linux/mfd/tps6586x.h>
2829 #include <linux/module.h>
@@ -267,6 +268,8 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 238 unmodified lines
267268 rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0);
268269 rtc->rtc->set_start_time = true;
269270
271+ irq_set_status_flags(rtc->irq, IRQ_NOAUTOEN);
272+
270273 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
271274 tps6586x_rtc_irq,
272275 IRQF_ONESHOT,
@@ -276,7 +279,6 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 3 unmodified lines
276279 rtc->irq, ret);
277280 goto fail_rtc_register;
278281 }
279− disable_irq(rtc->irq);
280282
281283 ret = rtc_register_device(rtc->rtc);
282284 if (ret)
drivers/rtc/rtc-zynqmp.c+2−2
@@ -94,7 +94,7 @@ static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 93 unmodified lines
9494 * RTC has updated the CURRENT_TIME with the time written into
9595 * SET_TIME_WRITE register.
9696 */
97− rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm);
97+ read_time = readl(xrtcdev->reg_base + RTC_CUR_TM);
9898 } else {
9999 /*
100100 * Time written in SET_TIME_WRITE has not yet updated into
@@ -104,8 +104,8 @@ static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 3 unmodified lines
104104 * reading.
105105 */
106106 read_time = readl(xrtcdev->reg_base + RTC_SET_TM_RD) - 1;
107− rtc_time64_to_tm(read_time, tm);
108107 }
108+ rtc_time64_to_tm(read_time, tm);
109109
110110 return 0;
111111 }
include/linux/rtc.h+1−0
@@ -167,6 +167,7 @@ struct rtc_device { · 166 unmodified lines
167167 #define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */
168168 #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */
169169 #define RTC_TIMESTAMP_END_2063 2966371199LL /* 2063-12-31 23:59:59 */
170+#define RTC_TIMESTAMP_END_2079 3471292799LL /* 2079-12-31 23:59:59 */
170171 #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */
171172 #define RTC_TIMESTAMP_END_2199 7258118399LL /* 2199-12-31 23:59:59 */
172173 #define RTC_TIMESTAMP_END_9999 253402300799LL /* 9999-12-31 23:59:59 */
include/uapi/linux/rtc.h+6−1
@@ -92,7 +92,12 @@ struct rtc_pll_info { · 91 unmodified lines
9292 #define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */
9393 #define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */
9494
95−#define RTC_VL_READ _IOR('p', 0x13, int) /* Voltage low detector */
95+#define RTC_VL_DATA_INVALID BIT(0) /* Voltage too low, RTC data is invalid */
96+#define RTC_VL_BACKUP_LOW BIT(1) /* Backup voltage is low */
97+#define RTC_VL_BACKUP_EMPTY BIT(2) /* Backup empty or not present */
98+#define RTC_VL_ACCURACY_LOW BIT(3) /* Voltage is low, RTC accuracy is reduced */
99+
100+#define RTC_VL_READ _IOR('p', 0x13, unsigned int) /* Voltage low detection */
96101 #define RTC_VL_CLR _IO('p', 0x14) /* Clear voltage low information */
97102
98103 /* interrupt flags */