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
18Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com>18Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com>
19Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@intel.com>19Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@intel.com>
20Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@linaro.org>20Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@linaro.org>
21Alexandre Belloni <alexandre.belloni@bootlin.com> <alexandre.belloni@free-electrons.com>
21Alexei Starovoitov <ast@kernel.org> <ast@plumgrid.com>22Alexei Starovoitov <ast@kernel.org> <ast@plumgrid.com>
22Alexei Starovoitov <ast@kernel.org> <alexei.starovoitov@gmail.com>23Alexei Starovoitov <ast@kernel.org> <alexei.starovoitov@gmail.com>
23Alexei Starovoitov <ast@kernel.org> <ast@fb.com>24Alexei Starovoitov <ast@kernel.org> <ast@fb.com>
Documentation/ABI/testing/rtc-cdev+8−0
@@ -33,6 +33,14 @@ Description: · 32 unmodified lines
33 Requires a separate RTC_PIE_ON call to enable the periodic33 Requires a separate RTC_PIE_ON call to enable the periodic
34 interrupts.34 interrupts.
35 35
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
36 The ioctl() calls supported by the older /dev/rtc interface are44 The ioctl() calls supported by the older /dev/rtc interface are
37 also supported by the newer RTC class framework. However,45 also supported by the newer RTC class framework. However,
38 because the chips and systems are not standardized, some PC/AT46 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 @@
1Atmel AT91RM9200 Real Time Clock
2
3Required 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
10Example:
11
12rtc@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
7title: Atmel AT91 RTC Device Tree Bindings
8
9allOf:
10 - $ref: "rtc.yaml#"
11
12maintainers:
13 - Alexandre Belloni <alexandre.belloni@bootlin.com>
14
15properties:
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
33required:
34 - compatible
35 - reg
36 - interrupts
37 - clocks
38
39additionalProperties: false
40
41examples:
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
240 240
241config RTC_DRV_DS1307241config RTC_DRV_DS1307
242 tristate "Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057"242 tristate "Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057"
243 select REGMAP_I2C
243 help244 help
244 If you say yes here you get support for various compatible RTC245 If you say yes here you get support for various compatible RTC
245 chips (often with battery backup) connected with I2C. This driver246 chips (often with battery backup) connected with I2C. This driver
@@ -622,6 +623,7 @@ config RTC_DRV_RX8010 · 376 unmodified lines
622 623
623config RTC_DRV_RX8581624config RTC_DRV_RX8581
624 tristate "Epson RX-8571/RX-8581"625 tristate "Epson RX-8571/RX-8581"
626 select REGMAP_I2C
625 help627 help
626 If you say yes here you will get support for the Epson RX-8571/628 If you say yes here you will get support for the Epson RX-8571/
627 RX-8581.629 RX-8581.
@@ -649,6 +651,7 @@ config RTC_DRV_EM3027 · 21 unmodified lines
649 651
650config RTC_DRV_RV3028652config RTC_DRV_RV3028
651 tristate "Micro Crystal RV3028"653 tristate "Micro Crystal RV3028"
654 select REGMAP_I2C
652 help655 help
653 If you say yes here you get support for the Micro Crystal656 If you say yes here you get support for the Micro Crystal
654 RV3028.657 RV3028.
@@ -677,13 +680,14 @@ config RTC_DRV_S5M · 22 unmodified lines
677 will be called rtc-s5m.680 will be called rtc-s5m.
678 681
679config RTC_DRV_SD3078682config RTC_DRV_SD3078
680 tristate "ZXW Shenzhen whwave SD3078"683 tristate "ZXW Shenzhen whwave SD3078"
681 help684 select REGMAP_I2C
682 If you say yes here you get support for the ZXW Shenzhen whwave685 help
683 SD3078 RTC chips.686 If you say yes here you get support for the ZXW Shenzhen whwave
687 SD3078 RTC chips.
684 688
685 This driver can also be built as a module. If so, the module689 This driver can also be built as a module. If so, the module
686 will be called rtc-sd3078690 will be called rtc-sd3078
687 691
688endif # I2C692endif # I2C
689 693
@@ -849,14 +853,14 @@ config RTC_I2C_AND_SPI · 159 unmodified lines
849 default m if I2C=m853 default m if I2C=m
850 default y if I2C=y854 default y if I2C=y
851 default y if SPI_MASTER=y855 default y if SPI_MASTER=y
852 select REGMAP_I2C if I2C
853 select REGMAP_SPI if SPI_MASTER
854 856
855comment "SPI and I2C RTC drivers"857comment "SPI and I2C RTC drivers"
856 858
857config RTC_DRV_DS3232859config RTC_DRV_DS3232
858 tristate "Dallas/Maxim DS3232/DS3234"860 tristate "Dallas/Maxim DS3232/DS3234"
859 depends on RTC_I2C_AND_SPI861 depends on RTC_I2C_AND_SPI
862 select REGMAP_I2C if I2C
863 select REGMAP_SPI if SPI_MASTER
860 help864 help
861 If you say yes here you get support for Dallas Semiconductor865 If you say yes here you get support for Dallas Semiconductor
862 DS3232 and DS3234 real-time clock chips. If an interrupt is associated866 DS3232 and DS3234 real-time clock chips. If an interrupt is associated
@@ -876,6 +880,8 @@ config RTC_DRV_DS3232_HWMON · 13 unmodified lines
876config RTC_DRV_PCF2127880config RTC_DRV_PCF2127
877 tristate "NXP PCF2127"881 tristate "NXP PCF2127"
878 depends on RTC_I2C_AND_SPI882 depends on RTC_I2C_AND_SPI
883 select REGMAP_I2C if I2C
884 select REGMAP_SPI if SPI_MASTER
879 select WATCHDOG_CORE if WATCHDOG885 select WATCHDOG_CORE if WATCHDOG
880 help886 help
881 If you say yes here you get support for the NXP PCF2127/29 RTC887 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
892config RTC_DRV_RV3029C2898config RTC_DRV_RV3029C2
893 tristate "Micro Crystal RV3029/3049"899 tristate "Micro Crystal RV3029/3049"
894 depends on RTC_I2C_AND_SPI900 depends on RTC_I2C_AND_SPI
901 select REGMAP_I2C if I2C
902 select REGMAP_SPI if SPI_MASTER
895 help903 help
896 If you say yes here you get support for the Micro Crystal904 If you say yes here you get support for the Micro Crystal
897 RV3029 and RV3049 RTC chips.905 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
523 if (status < 0)523 if (status < 0)
524 return status;524 return status;
525 525
526 tmp = !!(status & ABX8XX_STATUS_BLF);526 tmp = status & ABX8XX_STATUS_BLF ? RTC_VL_BACKUP_LOW : 0;
527 527
528 if (copy_to_user((void __user *)arg, &tmp, sizeof(int)))528 return put_user(tmp, (unsigned int __user *)arg);
529 return -EFAULT;
530
531 return 0;
532 529
533 case RTC_VL_CLR:530 case RTC_VL_CLR:
534 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS);531 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
264 return PTR_ERR(priv->iobase);264 return PTR_ERR(priv->iobase);
265 265
266 priv->clk = devm_clk_get(dev, "ahb");266 priv->clk = devm_clk_get(dev, "ahb");
267 if (IS_ERR(priv->clk))
268 return PTR_ERR(priv->clk);
269
267 ret = clk_prepare_enable(priv->clk);270 ret = clk_prepare_enable(priv->clk);
268 if (ret) {271 if (ret) {
269 dev_err(dev, "Failed to enable clk!\n");272 dev_err(dev, "Failed to enable clk!\n");
drivers/rtc/rtc-at91rm9200.c+74−45
@@ -14,6 +14,7 @@ · 13 unmodified lines
14 */14 */
15 15
16#include <linux/bcd.h>16#include <linux/bcd.h>
17#include <linux/bitfield.h>
17#include <linux/clk.h>18#include <linux/clk.h>
18#include <linux/completion.h>19#include <linux/completion.h>
19#include <linux/interrupt.h>20#include <linux/interrupt.h>
@@ -30,7 +31,51 @@ · 10 unmodified lines
30#include <linux/time.h>31#include <linux/time.h>
31#include <linux/uaccess.h>32#include <linux/uaccess.h>
32 33
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 */
34 79
35#define at91_rtc_read(field) \80#define at91_rtc_read(field) \
36 readl_relaxed(at91_rtc_regs + field)81 readl_relaxed(at91_rtc_regs + field)
@@ -117,20 +162,20 @@ static void at91_rtc_decodetime(unsigned int timereg, unsigned int calreg, · 80 unmodified lines
117 } while ((time != at91_rtc_read(timereg)) ||162 } while ((time != at91_rtc_read(timereg)) ||
118 (date != at91_rtc_read(calreg)));163 (date != at91_rtc_read(calreg)));
119 164
120 tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0);165 tm->tm_sec = bcd2bin(FIELD_GET(AT91_RTC_SEC, time));
121 tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8);166 tm->tm_min = bcd2bin(FIELD_GET(AT91_RTC_MIN, time));
122 tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16);167 tm->tm_hour = bcd2bin(FIELD_GET(AT91_RTC_HOUR, time));
123 168
124 /*169 /*
125 * The Calendar Alarm register does not have a field for170 * The Calendar Alarm register does not have a field for
126 * the year - so these will return an invalid value.171 * the year - so these will return an invalid value.
127 */172 */
128 tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */173 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 */
130 175
131 tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */176 tm->tm_wday = bcd2bin(FIELD_GET(AT91_RTC_DAY, date)) - 1; /* day of the week [0-6], Sunday=0 */
132 tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1;177 tm->tm_mon = bcd2bin(FIELD_GET(AT91_RTC_MONTH, date)) - 1;
133 tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24);178 tm->tm_mday = bcd2bin(FIELD_GET(AT91_RTC_DATE, date));
134}179}
135 180
136/*181/*
@@ -167,16 +212,17 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm) · 30 unmodified lines
167 at91_rtc_write_idr(AT91_RTC_ACKUPD);212 at91_rtc_write_idr(AT91_RTC_ACKUPD);
168 213
169 at91_rtc_write(AT91_RTC_TIMR,214 at91_rtc_write(AT91_RTC_TIMR,
170 bin2bcd(tm->tm_sec) << 0215 FIELD_PREP(AT91_RTC_SEC, bin2bcd(tm->tm_sec))
171 | bin2bcd(tm->tm_min) << 8216 | FIELD_PREP(AT91_RTC_MIN, bin2bcd(tm->tm_min))
172 | bin2bcd(tm->tm_hour) << 16);217 | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(tm->tm_hour)));
173 218
174 at91_rtc_write(AT91_RTC_CALR,219 at91_rtc_write(AT91_RTC_CALR,
175 bin2bcd((tm->tm_year + 1900) / 100) /* century */220 FIELD_PREP(AT91_RTC_CENT,
176 | bin2bcd(tm->tm_year % 100) << 8 /* year */221 bin2bcd((tm->tm_year + 1900) / 100))
177 | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */222 | FIELD_PREP(AT91_RTC_YEAR, bin2bcd(tm->tm_year % 100))
178 | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */223 | FIELD_PREP(AT91_RTC_MONTH, bin2bcd(tm->tm_mon + 1))
179 | bin2bcd(tm->tm_mday) << 24);224 | FIELD_PREP(AT91_RTC_DAY, bin2bcd(tm->tm_wday + 1))
225 | FIELD_PREP(AT91_RTC_DATE, bin2bcd(tm->tm_mday)));
180 226
181 /* Restart Time/Calendar */227 /* Restart Time/Calendar */
182 cr = at91_rtc_read(AT91_RTC_CR);228 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
211 */257 */
212static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)258static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
213{259{
214 struct rtc_time tm;260 struct rtc_time tm = alrm->time;
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;
223 261
224 at91_rtc_write_idr(AT91_RTC_ALARM);262 at91_rtc_write_idr(AT91_RTC_ALARM);
225 at91_rtc_write(AT91_RTC_TIMALR,263 at91_rtc_write(AT91_RTC_TIMALR,
226 bin2bcd(tm.tm_sec) << 0264 FIELD_PREP(AT91_RTC_SEC, bin2bcd(alrm->time.tm_sec))
227 | bin2bcd(tm.tm_min) << 8265 | FIELD_PREP(AT91_RTC_MIN, bin2bcd(alrm->time.tm_min))
228 | bin2bcd(tm.tm_hour) << 16266 | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(alrm->time.tm_hour))
229 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);267 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);
230 at91_rtc_write(AT91_RTC_CALALR,268 at91_rtc_write(AT91_RTC_CALALR,
231 bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */269 FIELD_PREP(AT91_RTC_MONTH, bin2bcd(alrm->time.tm_mon + 1))
232 | bin2bcd(tm.tm_mday) << 24270 | FIELD_PREP(AT91_RTC_DATE, bin2bcd(alrm->time.tm_mday))
233 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);271 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
234 272
235 if (alrm->enabled) {273 if (alrm->enabled) {
@@ -254,20 +292,6 @@ static int at91_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 18 unmodified lines
254 292
255 return 0;293 return 0;
256}294}
257/*
258 * Provide additional RTC information in /proc/driver/rtc
259 */
260static 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}
271 295
272/*296/*
273 * IRQ handler for the RTC297 * IRQ handler for the RTC
@@ -326,6 +350,12 @@ static const struct of_device_id at91_rtc_dt_ids[] = { · 52 unmodified lines
326 }, {350 }, {
327 .compatible = "atmel,at91sam9x5-rtc",351 .compatible = "atmel,at91sam9x5-rtc",
328 .data = &at91sam9x5_config,352 .data = &at91sam9x5_config,
353 }, {
354 .compatible = "atmel,sama5d4-rtc",
355 .data = &at91rm9200_config,
356 }, {
357 .compatible = "atmel,sama5d2-rtc",
358 .data = &at91rm9200_config,
329 }, {359 }, {
330 /* sentinel */360 /* sentinel */
331 }361 }
@@ -337,7 +367,6 @@ static const struct rtc_class_ops at91_rtc_ops = { · 5 unmodified lines
337 .set_time = at91_rtc_settime,367 .set_time = at91_rtc_settime,
338 .read_alarm = at91_rtc_readalarm,368 .read_alarm = at91_rtc_readalarm,
339 .set_alarm = at91_rtc_setalarm,369 .set_alarm = at91_rtc_setalarm,
340 .proc = at91_rtc_proc,
341 .alarm_irq_enable = at91_rtc_alarm_irq_enable,370 .alarm_irq_enable = at91_rtc_alarm_irq_enable,
342};371};
343 372
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
850 rtc_cmos_int_handler = cmos_interrupt;850 rtc_cmos_int_handler = cmos_interrupt;
851 851
852 retval = request_irq(rtc_irq, rtc_cmos_int_handler,852 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),
854 cmos_rtc.rtc);854 cmos_rtc.rtc);
855 if (retval < 0) {855 if (retval < 0) {
856 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);856 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
1197/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */1197/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
1198static void use_acpi_alarm_quirks(void)1198static void use_acpi_alarm_quirks(void)
1199{1199{
1200 int year;
1201
1202 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)1200 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
1203 return;1201 return;
1204 1202
@@ -1208,8 +1206,10 @@ static void use_acpi_alarm_quirks(void) · 3 unmodified lines
1208 if (!is_hpet_enabled())1206 if (!is_hpet_enabled())
1209 return;1207 return;
1210 1208
1211 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015)1209 if (dmi_get_bios_year() < 2015)
1212 use_acpi_alarm = true;1210 return;
1211
1212 use_acpi_alarm = true;
1213}1213}
1214#else1214#else
1215static inline void use_acpi_alarm_quirks(void) { }1215static 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
1305 * hardcode it on systems with a legacy PIC.1305 * hardcode it on systems with a legacy PIC.
1306 */1306 */
1307 if (nr_legacy_irqs())1307 if (nr_legacy_irqs())
1308 irq = 8;1308 irq = RTC_IRQ;
1309#endif1309#endif
1310 return cmos_do_probe(&pnp->dev,1310 return cmos_do_probe(&pnp->dev,
1311 pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);1311 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
75MODULE_DEVICE_TABLE(spi, ds1343_id);75MODULE_DEVICE_TABLE(spi, ds1343_id);
76 76
77struct ds1343_priv {77struct ds1343_priv {
78 struct spi_device *spi;
79 struct rtc_device *rtc;78 struct rtc_device *rtc;
80 struct regmap *map;79 struct regmap *map;
81 int irq;80 int irq;
@@ -362,12 +361,13 @@ static int ds1343_probe(struct spi_device *spi) · 280 unmodified lines
362 if (!priv)361 if (!priv)
363 return -ENOMEM;362 return -ENOMEM;
364 363
365 priv->spi = spi;
366
367 /* RTC DS1347 works in spi mode 3 and364 /* RTC DS1347 works in spi mode 3 and
368 * its chip select is active high365 * 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.
369 */368 */
370 spi->mode = SPI_MODE_3 | SPI_CS_HIGH;369 spi->mode |= SPI_MODE_3;
370 spi->mode ^= SPI_CS_HIGH;
371 spi->bits_per_word = 8;371 spi->bits_per_word = 8;
372 res = spi_setup(spi);372 res = spi_setup(spi);
373 if (res)373 if (res)
drivers/rtc/rtc-hym8563.c+7−12
@@ -78,7 +78,6 @@ · 77 unmodified lines
78struct hym8563 {78struct hym8563 {
79 struct i2c_client *client;79 struct i2c_client *client;
80 struct rtc_device *rtc;80 struct rtc_device *rtc;
81 bool valid;
82#ifdef CONFIG_COMMON_CLK81#ifdef CONFIG_COMMON_CLK
83 struct clk_hw clkout_hw;82 struct clk_hw clkout_hw;
84#endif83#endif
@@ -91,19 +90,19 @@ struct hym8563 { · 6 unmodified lines
91static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)90static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
92{91{
93 struct i2c_client *client = to_i2c_client(dev);92 struct i2c_client *client = to_i2c_client(dev);
94 struct hym8563 *hym8563 = i2c_get_clientdata(client);
95 u8 buf[7];93 u8 buf[7];
96 int ret;94 int ret;
97 95
98 if (!hym8563->valid) {
99 dev_warn(&client->dev, "no valid clock/calendar values available\n");
100 return -EPERM;
101 }
102
103 ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);96 ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf);
104 if (ret < 0)97 if (ret < 0)
105 return ret;98 return ret;
106 99
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
107 tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);106 tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK);
108 tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);107 tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK);
109 tm->tm_hour = bcd2bin(buf[2] & HYM8563_HOUR_MASK);108 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
118static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)117static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
119{118{
120 struct i2c_client *client = to_i2c_client(dev);119 struct i2c_client *client = to_i2c_client(dev);
121 struct hym8563 *hym8563 = i2c_get_clientdata(client);
122 u8 buf[7];120 u8 buf[7];
123 int ret;121 int ret;
124 122
@@ -157,8 +155,6 @@ static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm) · 32 unmodified lines
157 if (ret < 0)155 if (ret < 0)
158 return ret;156 return ret;
159 157
160 hym8563->valid = true;
161
162 return 0;158 return 0;
163}159}
164 160
@@ -556,9 +552,8 @@ static int hym8563_probe(struct i2c_client *client, · 391 unmodified lines
556 if (ret < 0)552 if (ret < 0)
557 return ret;553 return ret;
558 554
559 hym8563->valid = !(ret & HYM8563_SEC_VL);
560 dev_dbg(&client->dev, "rtc information is %s\n",555 dev_dbg(&client->dev, "rtc information is %s\n",
561 hym8563->valid ? "valid" : "invalid");556 (ret & HYM8563_SEC_VL) ? "invalid" : "valid");
562 557
563 hym8563->rtc = devm_rtc_device_register(&client->dev, client->name,558 hym8563->rtc = devm_rtc_device_register(&client->dev, client->name,
564 &hym8563_rtc_ops, THIS_MODULE);559 &hym8563_rtc_ops, THIS_MODULE);
drivers/rtc/rtc-moxart.c+1−4
@@ -1,3 +1,4 @@
1// SPDX-License-Identifier: GPL-2.0
1/*2/*
2 * MOXA ART RTC driver.3 * MOXA ART RTC driver.
3 *4 *
@@ -7,10 +8,6 @@ · 3 unmodified lines
7 *8 *
8 * Based on code from9 * Based on code from
9 * Moxa Technology Co., Ltd. <www.moxa.com>10 * 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.
14 */11 */
15 12
16#include <linux/init.h>13#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
297 297
298 rtc->rtc_dev->ops = &mtk_rtc_ops;298 rtc->rtc_dev->ops = &mtk_rtc_ops;
299 299
300 ret = rtc_register_device(rtc->rtc_dev);300 return rtc_register_device(rtc->rtc_dev);
301 if (ret)
302 goto out_free_irq;
303
304 return 0;
305
306out_free_irq:
307 free_irq(rtc->irq, rtc);
308 return ret;
309}301}
310 302
311#ifdef CONFIG_PM_SLEEP303#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
616 break;616 break;
617 default:617 default:
618 return -ENOTSUPP;618 return -ENOTSUPP;
619 };619 }
620 620
621 *config = pinconf_to_config_packed(param, arg);621 *config = pinconf_to_config_packed(param, arg);
622 622
drivers/rtc/rtc-pcf2127.c+2−4
@@ -199,11 +199,9 @@ static int pcf2127_rtc_ioctl(struct device *dev, · 198 unmodified lines
199 if (ret)199 if (ret)
200 return ret;200 return ret;
201 201
202 touser = touser & PCF2127_BIT_CTRL3_BLF ? 1 : 0;202 touser = touser & PCF2127_BIT_CTRL3_BLF ? RTC_VL_BACKUP_LOW : 0;
203 203
204 if (copy_to_user((void __user *)arg, &touser, sizeof(int)))204 return put_user(touser, (unsigned int __user *)arg);
205 return -EFAULT;
206 return 0;
207 default:205 default:
208 return -ENOIOCTLCMD;206 return -ENOIOCTLCMD;
209 }207 }
drivers/rtc/rtc-pcf85063.c+2−14
@@ -289,21 +289,9 @@ static int pcf85063_ioctl(struct device *dev, unsigned int cmd, · 288 unmodified lines
289 if (ret < 0)289 if (ret < 0)
290 return ret;290 return ret;
291 291
292 if (status & PCF85063_REG_SC_OS)292 status = status & PCF85063_REG_SC_OS ? RTC_VL_DATA_INVALID : 0;
293 dev_warn(&pcf85063->rtc->dev, "Voltage low, data loss detected.\n");
294 293
295 status &= PCF85063_REG_SC_OS;294 return put_user(status, (unsigned int __user *)arg);
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;
307 295
308 default:296 default:
309 return -ENOIOCTLCMD;297 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
282 ret = pcf8523_voltage_low(client);282 ret = pcf8523_voltage_low(client);
283 if (ret < 0)283 if (ret < 0)
284 return ret;284 return ret;
285 if (ret)
286 ret = RTC_VL_BACKUP_LOW;
285 287
286 if (copy_to_user((void __user *)arg, &ret, sizeof(int)))288 return put_user(ret, (unsigned int __user *)arg);
287 return -EFAULT;
288 289
289 return 0;
290 default:290 default:
291 return -ENOIOCTLCMD;291 return -ENOIOCTLCMD;
292 }292 }
drivers/rtc/rtc-pcf8563.c+9−31
@@ -22,8 +22,8 @@ · 21 unmodified lines
22 22
23#define PCF8563_REG_ST1 0x00 /* status */23#define PCF8563_REG_ST1 0x00 /* status */
24#define PCF8563_REG_ST2 0x0124#define PCF8563_REG_ST2 0x01
25#define PCF8563_BIT_AIE (1 << 1)25#define PCF8563_BIT_AIE BIT(1)
26#define PCF8563_BIT_AF (1 << 3)26#define PCF8563_BIT_AF BIT(3)
27#define PCF8563_BITS_ST2_N (7 << 5)27#define PCF8563_BITS_ST2_N (7 << 5)
28 28
29#define PCF8563_REG_SC 0x02 /* datetime */29#define PCF8563_REG_SC 0x02 /* datetime */
@@ -76,7 +76,6 @@ struct pcf8563 { · 46 unmodified lines
76 * 1970...2069.76 * 1970...2069.
77 */77 */
78 int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */78 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 */
80 79
81 struct i2c_client *client;80 struct i2c_client *client;
82#ifdef CONFIG_COMMON_CLK81#ifdef CONFIG_COMMON_CLK
@@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) · 125 unmodified lines
208 return err;207 return err;
209 208
210 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {209 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) {
211 pcf8563->voltage_low = 1;
212 dev_err(&client->dev,210 dev_err(&client->dev,
213 "low voltage detected, date/time is not reliable.\n");211 "low voltage detected, date/time is not reliable.\n");
214 return -EINVAL;212 return -EINVAL;
@@ -276,43 +274,23 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm) · 61 unmodified lines
276 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);274 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC);
277}275}
278 276
279#ifdef CONFIG_RTC_INTF_DEV
280static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)277static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
281{278{
282 struct pcf8563 *pcf8563 = i2c_get_clientdata(to_i2c_client(dev));279 struct i2c_client *client = to_i2c_client(dev);
283 struct rtc_time tm;280 int ret;
284 281
285 switch (cmd) {282 switch (cmd) {
286 case RTC_VL_READ:283 case RTC_VL_READ:
287 if (pcf8563->voltage_low)284 ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC);
288 dev_info(dev, "low voltage detected, date/time is not reliable.\n");285 if (ret < 0)
289 286 return ret;
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;
307 287
308 return 0;288 return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0,
289 (unsigned int __user *)arg);
309 default:290 default:
310 return -ENOIOCTLCMD;291 return -ENOIOCTLCMD;
311 }292 }
312}293}
313#else
314#define pcf8563_rtc_ioctl NULL
315#endif
316 294
317static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)295static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
318{296{
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
428 if (ret < 0)428 if (ret < 0)
429 return ret;429 return ret;
430 430
431 if (status & RV3028_STATUS_PORF)431 status = status & RV3028_STATUS_PORF ? RTC_VL_DATA_INVALID : 0;
432 dev_warn(&rv3028->rtc->dev, "Voltage low, data loss detected.\n");432 return put_user(status, (unsigned int __user *)arg);
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;
446 433
447 default:434 default:
448 return -ENOIOCTLCMD;435 return -ENOIOCTLCMD;
drivers/rtc/rtc-rv3029c2.c+182−260
@@ -109,10 +109,8 @@ · 108 unmodified lines
109#define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */109#define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */
110 110
111/* user ram section */111/* user ram section */
112#define RV3029_USR1_RAM_PAGE 0x38112#define RV3029_RAM_PAGE 0x38
113#define RV3029_USR1_SECTION_LEN 0x04113#define RV3029_RAM_SECTION_LEN 8
114#define RV3029_USR2_RAM_PAGE 0x3C
115#define RV3029_USR2_SECTION_LEN 0x04
116 114
117struct rv3029_data {115struct rv3029_data {
118 struct device *dev;116 struct device *dev;
@@ -121,77 +119,13 @@ struct rv3029_data { · 2 unmodified lines
121 int irq;119 int irq;
122};120};
123 121
124static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf,122static int rv3029_eeprom_busywait(struct rv3029_data *rv3029)
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
136static 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
148static 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
165static 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
175static 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
188static int rv3029_eeprom_busywait(struct device *dev)
189{123{
124 unsigned int sr;
190 int i, ret;125 int i, ret;
191 u8 sr;
192 126
193 for (i = 100; i > 0; i--) {127 for (i = 100; i > 0; i--) {
194 ret = rv3029_get_sr(dev, &sr);128 ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
195 if (ret < 0)129 if (ret < 0)
196 break;130 break;
197 if (!(sr & RV3029_STATUS_EEBUSY))131 if (!(sr & RV3029_STATUS_EEBUSY))
@@ -199,126 +133,128 @@ static int rv3029_eeprom_busywait(struct device *dev) · 1 unmodified line
199 usleep_range(1000, 10000);133 usleep_range(1000, 10000);
200 }134 }
201 if (i <= 0) {135 if (i <= 0) {
202 dev_err(dev, "EEPROM busy wait timeout.\n");136 dev_err(rv3029->dev, "EEPROM busy wait timeout.\n");
203 return -ETIMEDOUT;137 return -ETIMEDOUT;
204 }138 }
205 139
206 return ret;140 return ret;
207}141}
208 142
209static int rv3029_eeprom_exit(struct device *dev)143static int rv3029_eeprom_exit(struct rv3029_data *rv3029)
210{144{
211 /* Re-enable eeprom refresh */145 /* Re-enable eeprom refresh */
212 return rv3029_update_bits(dev, RV3029_ONOFF_CTRL,146 return regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL,
213 RV3029_ONOFF_CTRL_EERE,147 RV3029_ONOFF_CTRL_EERE,
214 RV3029_ONOFF_CTRL_EERE);148 RV3029_ONOFF_CTRL_EERE);
215}149}
216 150
217static int rv3029_eeprom_enter(struct device *dev)151static int rv3029_eeprom_enter(struct rv3029_data *rv3029)
218{152{
153 unsigned int sr;
219 int ret;154 int ret;
220 u8 sr;
221 155
222 /* Check whether we are in the allowed voltage range. */156 /* 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);
224 if (ret < 0)158 if (ret < 0)
225 return ret;159 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) {
227 /* We clear the bits and retry once just in case163 /* We clear the bits and retry once just in case
228 * we had a brown out in early startup.164 * we had a brown out in early startup.
229 */165 */
230 sr &= ~RV3029_STATUS_VLOW1;166 ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS,
231 sr &= ~RV3029_STATUS_VLOW2;167 RV3029_STATUS_VLOW1, 0);
232 ret = rv3029_set_sr(dev, sr);
233 if (ret < 0)168 if (ret < 0)
234 return ret;169 return ret;
235 usleep_range(1000, 10000);170 usleep_range(1000, 10000);
236 ret = rv3029_get_sr(dev, &sr);171 ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
237 if (ret < 0)172 if (ret < 0)
238 return ret;173 return ret;
239 if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) {174 if (sr & RV3029_STATUS_VLOW1) {
240 dev_err(dev,175 dev_err(rv3029->dev,
241 "Supply voltage is too low to safely access the EEPROM.\n");176 "Supply voltage is too low to safely access the EEPROM.\n");
242 return -ENODEV;177 return -ENODEV;
243 }178 }
244 }179 }
245 180
246 /* Disable eeprom refresh. */181 /* Disable eeprom refresh. */
247 ret = rv3029_update_bits(dev, RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE,182 ret = regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL,
248 0);183 RV3029_ONOFF_CTRL_EERE, 0);
249 if (ret < 0)184 if (ret < 0)
250 return ret;185 return ret;
251 186
252 /* Wait for any previous eeprom accesses to finish. */187 /* Wait for any previous eeprom accesses to finish. */
253 ret = rv3029_eeprom_busywait(dev);188 ret = rv3029_eeprom_busywait(rv3029);
254 if (ret < 0)189 if (ret < 0)
255 rv3029_eeprom_exit(dev);190 rv3029_eeprom_exit(rv3029);
256 191
257 return ret;192 return ret;
258}193}
259 194
260static int rv3029_eeprom_read(struct device *dev, u8 reg,195static int rv3029_eeprom_read(struct rv3029_data *rv3029, u8 reg,
261 u8 buf[], size_t len)196 u8 buf[], size_t len)
262{197{
263 int ret, err;198 int ret, err;
264 199
265 err = rv3029_eeprom_enter(dev);200 err = rv3029_eeprom_enter(rv3029);
266 if (err < 0)201 if (err < 0)
267 return err;202 return err;
268 203
269 ret = rv3029_read_regs(dev, reg, buf, len);204 ret = regmap_bulk_read(rv3029->regmap, reg, buf, len);
270 205
271 err = rv3029_eeprom_exit(dev);206 err = rv3029_eeprom_exit(rv3029);
272 if (err < 0)207 if (err < 0)
273 return err;208 return err;
274 209
275 return ret;210 return ret;
276}211}
277 212
278static int rv3029_eeprom_write(struct device *dev, u8 reg,213static int rv3029_eeprom_write(struct rv3029_data *rv3029, u8 reg,
279 u8 const buf[], size_t len)214 u8 const buf[], size_t len)
280{215{
216 unsigned int tmp;
281 int ret, err;217 int ret, err;
282 size_t i;218 size_t i;
283 u8 tmp;
284 219
285 err = rv3029_eeprom_enter(dev);220 err = rv3029_eeprom_enter(rv3029);
286 if (err < 0)221 if (err < 0)
287 return err;222 return err;
288 223
289 for (i = 0; i < len; i++, reg++) {224 for (i = 0; i < len; i++, reg++) {
290 ret = rv3029_read_regs(dev, reg, &tmp, 1);225 ret = regmap_read(rv3029->regmap, reg, &tmp);
291 if (ret < 0)226 if (ret < 0)
292 break;227 break;
293 if (tmp != buf[i]) {228 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);
295 if (ret < 0)231 if (ret < 0)
296 break;232 break;
297 }233 }
298 ret = rv3029_eeprom_busywait(dev);234 ret = rv3029_eeprom_busywait(rv3029);
299 if (ret < 0)235 if (ret < 0)
300 break;236 break;
301 }237 }
302 238
303 err = rv3029_eeprom_exit(dev);239 err = rv3029_eeprom_exit(rv3029);
304 if (err < 0)240 if (err < 0)
305 return err;241 return err;
306 242
307 return ret;243 return ret;
308}244}
309 245
310static int rv3029_eeprom_update_bits(struct device *dev,246static int rv3029_eeprom_update_bits(struct rv3029_data *rv3029,
311 u8 reg, u8 mask, u8 set)247 u8 reg, u8 mask, u8 set)
312{248{
313 u8 buf;249 u8 buf;
314 int ret;250 int ret;
315 251
316 ret = rv3029_eeprom_read(dev, reg, &buf, 1);252 ret = rv3029_eeprom_read(rv3029, reg, &buf, 1);
317 if (ret < 0)253 if (ret < 0)
318 return ret;254 return ret;
319 buf &= ~mask;255 buf &= ~mask;
320 buf |= set & mask;256 buf |= set & mask;
321 ret = rv3029_eeprom_write(dev, reg, &buf, 1);257 ret = rv3029_eeprom_write(rv3029, reg, &buf, 1);
322 if (ret < 0)258 if (ret < 0)
323 return ret;259 return ret;
324 260
@@ -330,20 +266,20 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 5 unmodified lines
330 struct device *dev = dev_id;266 struct device *dev = dev_id;
331 struct rv3029_data *rv3029 = dev_get_drvdata(dev);267 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
332 struct mutex *lock = &rv3029->rtc->ops_lock;268 struct mutex *lock = &rv3029->rtc->ops_lock;
269 unsigned int flags, controls;
333 unsigned long events = 0;270 unsigned long events = 0;
334 u8 flags, controls;
335 int ret;271 int ret;
336 272
337 mutex_lock(lock);273 mutex_lock(lock);
338 274
339 ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);275 ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls);
340 if (ret) {276 if (ret) {
341 dev_warn(dev, "Read IRQ Control Register error %d\n", ret);277 dev_warn(dev, "Read IRQ Control Register error %d\n", ret);
342 mutex_unlock(lock);278 mutex_unlock(lock);
343 return IRQ_NONE;279 return IRQ_NONE;
344 }280 }
345 281
346 ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);282 ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags);
347 if (ret) {283 if (ret) {
348 dev_warn(dev, "Read IRQ Flags Register error %d\n", ret);284 dev_warn(dev, "Read IRQ Flags Register error %d\n", ret);
349 mutex_unlock(lock);285 mutex_unlock(lock);
@@ -358,8 +294,8 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 8 unmodified lines
358 294
359 if (events) {295 if (events) {
360 rtc_update_irq(rv3029->rtc, 1, events);296 rtc_update_irq(rv3029->rtc, 1, events);
361 rv3029_write_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);297 regmap_write(rv3029->regmap, RV3029_IRQ_FLAGS, flags);
362 rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1);298 regmap_write(rv3029->regmap, RV3029_IRQ_CTRL, controls);
363 }299 }
364 mutex_unlock(lock);300 mutex_unlock(lock);
365 301
@@ -368,22 +304,22 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 2 unmodified lines
368 304
369static int rv3029_read_time(struct device *dev, struct rtc_time *tm)305static int rv3029_read_time(struct device *dev, struct rtc_time *tm)
370{306{
371 u8 buf[1];307 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
308 unsigned int sr;
372 int ret;309 int ret;
373 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };310 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, };
374 311
375 ret = rv3029_get_sr(dev, buf);312 ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr);
376 if (ret < 0) {313 if (ret < 0)
377 dev_err(dev, "%s: reading SR failed\n", __func__);314 return ret;
378 return -EIO;315
379 }316 if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON))
317 return -EINVAL;
380 318
381 ret = rv3029_read_regs(dev, RV3029_W_SEC, regs,319 ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs,
382 RV3029_WATCH_SECTION_LEN);320 RV3029_WATCH_SECTION_LEN);
383 if (ret < 0) {321 if (ret < 0)
384 dev_err(dev, "%s: reading RTC section failed\n", __func__);
385 return ret;322 return ret;
386 }
387 323
388 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]);324 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]);
389 tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]);325 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
411 347
412static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)348static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
413{349{
350 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
414 struct rtc_time *const tm = &alarm->time;351 struct rtc_time *const tm = &alarm->time;
352 unsigned int controls, flags;
415 int ret;353 int ret;
416 u8 regs[8], controls, flags;354 u8 regs[8];
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 }
423 355
424 ret = rv3029_read_regs(dev, RV3029_A_SC, regs,356 ret = regmap_bulk_read(rv3029->regmap, RV3029_A_SC, regs,
425 RV3029_ALARM_SECTION_LEN);357 RV3029_ALARM_SECTION_LEN);
426 358 if (ret < 0)
427 if (ret < 0) {
428 dev_err(dev, "%s: reading alarm section failed\n", __func__);
429 return ret;359 return ret;
430 }
431 360
432 ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1);361 ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls);
433 if (ret) {362 if (ret)
434 dev_err(dev, "Read IRQ Control Register error %d\n", ret);
435 return ret;363 return ret;
436 }364
437 ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1);365 ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags);
438 if (ret < 0) {366 if (ret < 0)
439 dev_err(dev, "Read IRQ Flags Register error %d\n", ret);
440 return ret;367 return ret;
441 }
442 368
443 tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f);369 tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f);
444 tm->tm_min = bcd2bin(regs[RV3029_A_MN - RV3029_A_SC] & 0x7f);370 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
456 382
457static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable)383static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable)
458{384{
459 int ret;385 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
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 }
479 386
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);
481}390}
482 391
483static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)392static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
484{393{
394 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
485 struct rtc_time *const tm = &alarm->time;395 struct rtc_time *const tm = &alarm->time;
486 int ret;396 int ret;
487 u8 regs[8];397 u8 regs[8];
488 398
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
503 /* Activate all the alarms with AE_x bit */399 /* Activate all the alarms with AE_x bit */
504 regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X;400 regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X;
505 regs[RV3029_A_MN - RV3029_A_SC] = bin2bcd(tm->tm_min) | RV3029_A_AE_X;401 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
515 | RV3029_A_AE_X;411 | RV3029_A_AE_X;
516 412
517 /* Write the alarm */413 /* Write the alarm */
518 ret = rv3029_write_regs(dev, RV3029_A_SC, regs,414 ret = regmap_bulk_write(rv3029->regmap, RV3029_A_SC, regs,
519 RV3029_ALARM_SECTION_LEN);415 RV3029_ALARM_SECTION_LEN);
520 if (ret < 0)416 if (ret < 0)
521 return ret;417 return ret;
522 418
523 if (alarm->enabled) {419 return rv3029_alarm_irq_enable(dev, 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;
536}420}
537 421
538static int rv3029_set_time(struct device *dev, struct rtc_time *tm)422static int rv3029_set_time(struct device *dev, struct rtc_time *tm)
539{423{
424 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
540 u8 regs[8];425 u8 regs[8];
541 int ret;426 int ret;
542 427
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
551 regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec);428 regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec);
552 regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min);429 regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min);
553 regs[RV3029_W_HOURS - RV3029_W_SEC] = bin2bcd(tm->tm_hour);430 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
556 regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7;433 regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7;
557 regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100);434 regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100);
558 435
559 ret = rv3029_write_regs(dev, RV3029_W_SEC, regs,436 ret = regmap_bulk_write(rv3029->regmap, RV3029_W_SEC, regs,
560 RV3029_WATCH_SECTION_LEN);437 RV3029_WATCH_SECTION_LEN);
561 if (ret < 0)438 if (ret < 0)
562 return ret;439 return ret;
563 440
564 ret = rv3029_get_sr(dev, regs);441 /* clear PON and VLOW2 bits */
565 if (ret < 0) {442 return regmap_update_bits(rv3029->regmap, RV3029_STATUS,
566 dev_err(dev, "%s: reading SR failed\n", __func__);443 RV3029_STATUS_PON | RV3029_STATUS_VLOW2, 0);
567 return ret;444}
568 }445
569 /* clear PON bit */446static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
570 ret = rv3029_set_sr(dev, (regs[0] & ~RV3029_STATUS_PON));447{
571 if (ret < 0) {448 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
572 dev_err(dev, "%s: reading SR failed\n", __func__);449 unsigned long vl = 0;
573 return ret;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;
574 }472 }
473}
575 474
576 return 0;475static 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
481static 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);
577}485}
578 486
579static const struct rv3029_trickle_tab_elem {487static const struct rv3029_trickle_tab_elem {
@@ -635,6 +543,7 @@ static const struct rv3029_trickle_tab_elem { · 55 unmodified lines
635 543
636static void rv3029_trickle_config(struct device *dev)544static void rv3029_trickle_config(struct device *dev)
637{545{
546 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
638 struct device_node *of_node = dev->of_node;547 struct device_node *of_node = dev->of_node;
639 const struct rv3029_trickle_tab_elem *elem;548 const struct rv3029_trickle_tab_elem *elem;
640 int i, err;549 int i, err;
@@ -661,7 +570,7 @@ static void rv3029_trickle_config(struct device *dev) · 20 unmodified lines
661 "Trickle charger enabled at %d ohms resistance.\n",570 "Trickle charger enabled at %d ohms resistance.\n",
662 elem->r);571 elem->r);
663 }572 }
664 err = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,573 err = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL,
665 RV3029_TRICKLE_MASK,574 RV3029_TRICKLE_MASK,
666 trickle_set_bits);575 trickle_set_bits);
667 if (err < 0)576 if (err < 0)
@@ -670,12 +579,12 @@ static void rv3029_trickle_config(struct device *dev) · 2 unmodified lines
670 579
671#ifdef CONFIG_RTC_DRV_RV3029_HWMON580#ifdef CONFIG_RTC_DRV_RV3029_HWMON
672 581
673static int rv3029_read_temp(struct device *dev, int *temp_mC)582static int rv3029_read_temp(struct rv3029_data *rv3029, int *temp_mC)
674{583{
584 unsigned int temp;
675 int ret;585 int ret;
676 u8 temp;
677 586
678 ret = rv3029_read_regs(dev, RV3029_TEMP_PAGE, &temp, 1);587 ret = regmap_read(rv3029->regmap, RV3029_TEMP_PAGE, &temp);
679 if (ret < 0)588 if (ret < 0)
680 return ret;589 return ret;
681 590
@@ -688,9 +597,10 @@ static ssize_t rv3029_hwmon_show_temp(struct device *dev, · 6 unmodified lines
688 struct device_attribute *attr,597 struct device_attribute *attr,
689 char *buf)598 char *buf)
690{599{
600 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
691 int ret, temp_mC;601 int ret, temp_mC;
692 602
693 ret = rv3029_read_temp(dev, &temp_mC);603 ret = rv3029_read_temp(rv3029, &temp_mC);
694 if (ret < 0)604 if (ret < 0)
695 return ret;605 return ret;
696 606
@@ -702,9 +612,10 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 5 unmodified lines
702 const char *buf,612 const char *buf,
703 size_t count)613 size_t count)
704{614{
615 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
616 unsigned int th_set_bits = 0;
705 unsigned long interval_ms;617 unsigned long interval_ms;
706 int ret;618 int ret;
707 u8 th_set_bits = 0;
708 619
709 ret = kstrtoul(buf, 10, &interval_ms);620 ret = kstrtoul(buf, 10, &interval_ms);
710 if (ret < 0)621 if (ret < 0)
@@ -715,7 +626,7 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 4 unmodified lines
715 if (interval_ms >= 16000)626 if (interval_ms >= 16000)
716 th_set_bits |= RV3029_EECTRL_THP;627 th_set_bits |= RV3029_EECTRL_THP;
717 }628 }
718 ret = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL,629 ret = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL,
719 RV3029_EECTRL_THE | RV3029_EECTRL_THP,630 RV3029_EECTRL_THE | RV3029_EECTRL_THP,
720 th_set_bits);631 th_set_bits);
721 if (ret < 0)632 if (ret < 0)
@@ -728,10 +639,11 @@ static ssize_t rv3029_hwmon_show_update_interval(struct device *dev, · 6 unmodified lines
728 struct device_attribute *attr,639 struct device_attribute *attr,
729 char *buf)640 char *buf)
730{641{
642 struct rv3029_data *rv3029 = dev_get_drvdata(dev);
731 int ret, interval_ms;643 int ret, interval_ms;
732 u8 eectrl;644 u8 eectrl;
733 645
734 ret = rv3029_eeprom_read(dev, RV3029_CONTROL_E2P_EECTRL,646 ret = rv3029_eeprom_read(rv3029, RV3029_CONTROL_E2P_EECTRL,
735 &eectrl, 1);647 &eectrl, 1);
736 if (ret < 0)648 if (ret < 0)
737 return ret;649 return ret;
@@ -785,14 +697,23 @@ static void rv3029_hwmon_register(struct device *dev, const char *name) · 47 unmodified lines
785static struct rtc_class_ops rv3029_rtc_ops = {697static struct rtc_class_ops rv3029_rtc_ops = {
786 .read_time = rv3029_read_time,698 .read_time = rv3029_read_time,
787 .set_time = rv3029_set_time,699 .set_time = rv3029_set_time,
700 .ioctl = rv3029_ioctl,
788};701};
789 702
790static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,703static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq,
791 const char *name)704 const char *name)
792{705{
793 struct rv3029_data *rv3029;706 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 };
794 int rc = 0;716 int rc = 0;
795 u8 buf[1];
796 717
797 rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL);718 rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL);
798 if (!rv3029)719 if (!rv3029)
@@ -803,21 +724,12 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, · 4 unmodified lines
803 rv3029->dev = dev;724 rv3029->dev = dev;
804 dev_set_drvdata(dev, rv3029);725 dev_set_drvdata(dev, rv3029);
805 726
806 rc = rv3029_get_sr(dev, buf);
807 if (rc < 0) {
808 dev_err(dev, "reading status failed\n");
809 return rc;
810 }
811
812 rv3029_trickle_config(dev);727 rv3029_trickle_config(dev);
813 rv3029_hwmon_register(dev, name);728 rv3029_hwmon_register(dev, name);
814 729
815 rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops,730 rv3029->rtc = devm_rtc_allocate_device(dev);
816 THIS_MODULE);731 if (IS_ERR(rv3029->rtc))
817 if (IS_ERR(rv3029->rtc)) {
818 dev_err(dev, "unable to register the class device\n");
819 return PTR_ERR(rv3029->rtc);732 return PTR_ERR(rv3029->rtc);
820 }
821 733
822 if (rv3029->irq > 0) {734 if (rv3029->irq > 0) {
823 rc = devm_request_threaded_irq(dev, rv3029->irq,735 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
834 }746 }
835 }747 }
836 748
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
837 return 0;760 return 0;
838}761}
839 762
763static 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
772static const struct regmap_access_table rv3029_regs = {
773 .no_ranges = rv3029_holes_range,
774 .n_no_ranges = ARRAY_SIZE(rv3029_holes_range),
775};
776
777static 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
840#if IS_ENABLED(CONFIG_I2C)785#if IS_ENABLED(CONFIG_I2C)
841 786
842static int rv3029_i2c_probe(struct i2c_client *client,787static int rv3029_i2c_probe(struct i2c_client *client,
843 const struct i2c_device_id *id)788 const struct i2c_device_id *id)
844{789{
845 struct regmap *regmap;790 struct regmap *regmap;
846 static const struct regmap_config config = {
847 .reg_bits = 8,
848 .val_bits = 8,
849 };
850
851 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |791 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
852 I2C_FUNC_SMBUS_BYTE)) {792 I2C_FUNC_SMBUS_BYTE)) {
853 dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n");793 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
855 }795 }
856 796
857 regmap = devm_regmap_init_i2c(client, &config);797 regmap = devm_regmap_init_i2c(client, &config);
858 if (IS_ERR(regmap)) {798 if (IS_ERR(regmap))
859 dev_err(&client->dev, "%s: regmap allocation failed: %ld\n",
860 __func__, PTR_ERR(regmap));
861 return PTR_ERR(regmap);799 return PTR_ERR(regmap);
862 }
863 800
864 return rv3029_probe(&client->dev, regmap, client->irq, client->name);801 return rv3029_probe(&client->dev, regmap, client->irq, client->name);
865}802}
@@ -873,24 +810,20 @@ MODULE_DEVICE_TABLE(i2c, rv3029_id); · 7 unmodified lines
873 810
874static const struct of_device_id rv3029_of_match[] = {811static const struct of_device_id rv3029_of_match[] = {
875 { .compatible = "microcrystal,rv3029" },812 { .compatible = "microcrystal,rv3029" },
876 /* Backward compatibility only, do not use compatibles below: */
877 { .compatible = "rv3029" },
878 { .compatible = "rv3029c2" },
879 { .compatible = "mc,rv3029c2" },
880 { }813 { }
881};814};
882MODULE_DEVICE_TABLE(of, rv3029_of_match);815MODULE_DEVICE_TABLE(of, rv3029_of_match);
883 816
884static struct i2c_driver rv3029_driver = {817static struct i2c_driver rv3029_driver = {
885 .driver = {818 .driver = {
886 .name = "rtc-rv3029c2",819 .name = "rv3029",
887 .of_match_table = of_match_ptr(rv3029_of_match),820 .of_match_table = of_match_ptr(rv3029_of_match),
888 },821 },
889 .probe = rv3029_i2c_probe,822 .probe = rv3029_i2c_probe,
890 .id_table = rv3029_id,823 .id_table = rv3029_id,
891};824};
892 825
893static int rv3029_register_driver(void)826static int __init rv3029_register_driver(void)
894{827{
895 return i2c_add_driver(&rv3029_driver);828 return i2c_add_driver(&rv3029_driver);
896}829}
@@ -902,7 +835,7 @@ static void rv3029_unregister_driver(void) · 5 unmodified lines
902 835
903#else836#else
904 837
905static int rv3029_register_driver(void)838static int __init rv3029_register_driver(void)
906{839{
907 return 0;840 return 0;
908}841}
@@ -917,18 +850,11 @@ static void rv3029_unregister_driver(void) · 8 unmodified lines
917 850
918static int rv3049_probe(struct spi_device *spi)851static int rv3049_probe(struct spi_device *spi)
919{852{
920 static const struct regmap_config config = {
921 .reg_bits = 8,
922 .val_bits = 8,
923 };
924 struct regmap *regmap;853 struct regmap *regmap;
925 854
926 regmap = devm_regmap_init_spi(spi, &config);855 regmap = devm_regmap_init_spi(spi, &config);
927 if (IS_ERR(regmap)) {856 if (IS_ERR(regmap))
928 dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
929 __func__, PTR_ERR(regmap));
930 return PTR_ERR(regmap);857 return PTR_ERR(regmap);
931 }
932 858
933 return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049");859 return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049");
934}860}
@@ -940,24 +866,24 @@ static struct spi_driver rv3049_driver = { · 5 unmodified lines
940 .probe = rv3049_probe,866 .probe = rv3049_probe,
941};867};
942 868
943static int rv3049_register_driver(void)869static int __init rv3049_register_driver(void)
944{870{
945 return spi_register_driver(&rv3049_driver);871 return spi_register_driver(&rv3049_driver);
946}872}
947 873
948static void rv3049_unregister_driver(void)874static void __exit rv3049_unregister_driver(void)
949{875{
950 spi_unregister_driver(&rv3049_driver);876 spi_unregister_driver(&rv3049_driver);
951}877}
952 878
953#else879#else
954 880
955static int rv3049_register_driver(void)881static int __init rv3049_register_driver(void)
956{882{
957 return 0;883 return 0;
958}884}
959 885
960static void rv3049_unregister_driver(void)886static void __exit rv3049_unregister_driver(void)
961{887{
962}888}
963 889
@@ -968,16 +894,12 @@ static int __init rv30x9_init(void) · 4 unmodified lines
968 int ret;894 int ret;
969 895
970 ret = rv3029_register_driver();896 ret = rv3029_register_driver();
971 if (ret) {897 if (ret)
972 pr_err("Failed to register rv3029 driver: %d\n", ret);
973 return ret;898 return ret;
974 }
975 899
976 ret = rv3049_register_driver();900 ret = rv3049_register_driver();
977 if (ret) {901 if (ret)
978 pr_err("Failed to register rv3049 driver: %d\n", ret);
979 rv3029_unregister_driver();902 rv3029_unregister_driver();
980 }
981 903
982 return ret;904 return ret;
983}905}
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
411{411{
412 struct i2c_client *client = to_i2c_client(dev);412 struct i2c_client *client = to_i2c_client(dev);
413 struct rv8803_data *rv8803 = dev_get_drvdata(dev);413 struct rv8803_data *rv8803 = dev_get_drvdata(dev);
414 unsigned int vl = 0;
414 int flags, ret = 0;415 int flags, ret = 0;
415 416
416 switch (cmd) {417 switch (cmd) {
@@ -419,18 +420,15 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines
419 if (flags < 0)420 if (flags < 0)
420 return flags;421 return flags;
421 422
422 if (flags & RV8803_FLAG_V1F)423 if (flags & RV8803_FLAG_V1F) {
423 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");424 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n");
425 vl = RTC_VL_ACCURACY_LOW;
426 }
424 427
425 if (flags & RV8803_FLAG_V2F)428 if (flags & RV8803_FLAG_V2F)
426 dev_warn(&client->dev, "Voltage low, data loss detected.\n");429 vl |= RTC_VL_DATA_INVALID;
427
428 flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F;
429 430
430 if (copy_to_user((void __user *)arg, &flags, sizeof(int)))431 return put_user(vl, (unsigned int __user *)arg);
431 return -EFAULT;
432
433 return 0;
434 432
435 case RTC_VL_CLR:433 case RTC_VL_CLR:
436 mutex_lock(&rv8803->flags_lock);434 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
440 return flags;438 return flags;
441 }439 }
442 440
443 flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F);441 flags &= ~RV8803_FLAG_V1F;
444 ret = rv8803_write_reg(client, RV8803_FLAG, flags);442 ret = rv8803_write_reg(client, RV8803_FLAG, flags);
445 mutex_unlock(&rv8803->flags_lock);443 mutex_unlock(&rv8803->flags_lock);
446 if (ret)444 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
389 389
390static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)390static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
391{391{
392 struct i2c_client *client = to_i2c_client(dev);
393 struct rx8010_data *rx8010 = dev_get_drvdata(dev);392 struct rx8010_data *rx8010 = dev_get_drvdata(dev);
394 int ret, tmp;393 int tmp;
395 int flagreg;394 int flagreg;
396 395
397 switch (cmd) {396 switch (cmd) {
@@ -400,24 +399,8 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines
400 if (flagreg < 0)399 if (flagreg < 0)
401 return flagreg;400 return flagreg;
402 401
403 tmp = !!(flagreg & RX8010_FLAG_VLF);402 tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0;
404 if (copy_to_user((void __user *)arg, &tmp, sizeof(int)))403 return put_user(tmp, (unsigned int __user *)arg);
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;
421 404
422 default:405 default:
423 return -ENOIOCTLCMD;406 return -ENOIOCTLCMD;
@@ -482,7 +465,7 @@ static int rx8010_probe(struct i2c_client *client, · 58 unmodified lines
482 465
483 rx8010->rtc->max_user_freq = 1;466 rx8010->rtc->max_user_freq = 1;
484 467
485 return err;468 return 0;
486}469}
487 470
488static struct i2c_driver rx8010_driver = {471static 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
67MODULE_DEVICE_TABLE(i2c, rx8025_id);67MODULE_DEVICE_TABLE(i2c, rx8025_id);
68 68
69struct rx8025_data {69struct rx8025_data {
70 struct i2c_client *client;
71 struct rtc_device *rtc;70 struct rtc_device *rtc;
72 u8 ctrl1;71 u8 ctrl1;
73};72};
@@ -103,10 +102,10 @@ static s32 rx8025_write_regs(const struct i2c_client *client, · 29 unmodified lines
103 102
104static int rx8025_check_validity(struct device *dev)103static int rx8025_check_validity(struct device *dev)
105{104{
106 struct rx8025_data *rx8025 = dev_get_drvdata(dev);105 struct i2c_client *client = to_i2c_client(dev);
107 int ctrl2;106 int ctrl2;
108 107
109 ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);108 ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
110 if (ctrl2 < 0)109 if (ctrl2 < 0)
111 return ctrl2;110 return ctrl2;
112 111
@@ -178,6 +177,7 @@ out: · 65 unmodified lines
178 177
179static int rx8025_get_time(struct device *dev, struct rtc_time *dt)178static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
180{179{
180 struct i2c_client *client = to_i2c_client(dev);
181 struct rx8025_data *rx8025 = dev_get_drvdata(dev);181 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
182 u8 date[7];182 u8 date[7];
183 int err;183 int err;
@@ -186,7 +186,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 2 unmodified lines
186 if (err)186 if (err)
187 return err;187 return err;
188 188
189 err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);189 err = rx8025_read_regs(client, RX8025_REG_SEC, 7, date);
190 if (err)190 if (err)
191 return err;191 return err;
192 192
@@ -211,6 +211,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 18 unmodified lines
211 211
212static int rx8025_set_time(struct device *dev, struct rtc_time *dt)212static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
213{213{
214 struct i2c_client *client = to_i2c_client(dev);
214 struct rx8025_data *rx8025 = dev_get_drvdata(dev);215 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
215 u8 date[7];216 u8 date[7];
216 int ret;217 int ret;
@@ -237,11 +238,11 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) · 20 unmodified lines
237 238
238 dev_dbg(dev, "%s: write %7ph\n", __func__, date);239 dev_dbg(dev, "%s: write %7ph\n", __func__, date);
239 240
240 ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);241 ret = rx8025_write_regs(client, RX8025_REG_SEC, 7, date);
241 if (ret < 0)242 if (ret < 0)
242 return ret;243 return ret;
243 244
244 return rx8025_reset_validity(rx8025->client);245 return rx8025_reset_validity(client);
245}246}
246 247
247static int rx8025_init_client(struct i2c_client *client)248static int rx8025_init_client(struct i2c_client *client)
@@ -251,7 +252,7 @@ static int rx8025_init_client(struct i2c_client *client) · 3 unmodified lines
251 int need_clear = 0;252 int need_clear = 0;
252 int err;253 int err;
253 254
254 err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl);255 err = rx8025_read_regs(client, RX8025_REG_CTRL1, 2, ctrl);
255 if (err)256 if (err)
256 goto out;257 goto out;
257 258
@@ -280,8 +281,8 @@ out: · 22 unmodified lines
280/* Alarm support */281/* Alarm support */
281static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)282static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
282{283{
284 struct i2c_client *client = to_i2c_client(dev);
283 struct rx8025_data *rx8025 = dev_get_drvdata(dev);285 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
284 struct i2c_client *client = rx8025->client;
285 u8 ald[2];286 u8 ald[2];
286 int ctrl2, err;287 int ctrl2, err;
287 288
@@ -347,18 +348,18 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 59 unmodified lines
347 348
348 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {349 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) {
349 rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE;350 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,
351 rx8025->ctrl1);352 rx8025->ctrl1);
352 if (err)353 if (err)
353 return err;354 return err;
354 }355 }
355 err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald);356 err = rx8025_write_regs(client, RX8025_REG_ALDMIN, 2, ald);
356 if (err)357 if (err)
357 return err;358 return err;
358 359
359 if (t->enabled) {360 if (t->enabled) {
360 rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE;361 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,
362 rx8025->ctrl1);363 rx8025->ctrl1);
363 if (err)364 if (err)
364 return err;365 return err;
@@ -369,6 +370,7 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 4 unmodified lines
369 370
370static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)371static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
371{372{
373 struct i2c_client *client = to_i2c_client(dev);
372 struct rx8025_data *rx8025 = dev_get_drvdata(dev);374 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
373 u8 ctrl1;375 u8 ctrl1;
374 int err;376 int err;
@@ -381,7 +383,7 @@ static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled) · 6 unmodified lines
381 383
382 if (ctrl1 != rx8025->ctrl1) {384 if (ctrl1 != rx8025->ctrl1) {
383 rx8025->ctrl1 = ctrl1;385 rx8025->ctrl1 = ctrl1;
384 err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1,386 err = rx8025_write_reg(client, RX8025_REG_CTRL1,
385 rx8025->ctrl1);387 rx8025->ctrl1);
386 if (err)388 if (err)
387 return err;389 return err;
@@ -516,7 +518,6 @@ static int rx8025_probe(struct i2c_client *client, · 128 unmodified lines
516 if (!rx8025)518 if (!rx8025)
517 return -ENOMEM;519 return -ENOMEM;
518 520
519 rx8025->client = client;
520 i2c_set_clientdata(client, rx8025);521 i2c_set_clientdata(client, rx8025);
521 522
522 err = rx8025_init_client(client);523 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
897 }897 }
898 898
899 ret = stm32_rtc_wait_sync(rtc);899 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);
901 return ret;903 return ret;
904 }
902 905
903 if (device_may_wakeup(dev))906 if (device_may_wakeup(dev))
904 return disable_irq_wake(rtc->irq_alarm);907 return disable_irq_wake(rtc->irq_alarm);
drivers/rtc/rtc-tps6586x.c+3−1
@@ -23,6 +23,7 @@ · 22 unmodified lines
23#include <linux/device.h>23#include <linux/device.h>
24#include <linux/err.h>24#include <linux/err.h>
25#include <linux/init.h>25#include <linux/init.h>
26#include <linux/irq.h>
26#include <linux/kernel.h>27#include <linux/kernel.h>
27#include <linux/mfd/tps6586x.h>28#include <linux/mfd/tps6586x.h>
28#include <linux/module.h>29#include <linux/module.h>
@@ -267,6 +268,8 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 238 unmodified lines
267 rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0);268 rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0);
268 rtc->rtc->set_start_time = true;269 rtc->rtc->set_start_time = true;
269 270
271 irq_set_status_flags(rtc->irq, IRQ_NOAUTOEN);
272
270 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,273 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
271 tps6586x_rtc_irq,274 tps6586x_rtc_irq,
272 IRQF_ONESHOT,275 IRQF_ONESHOT,
@@ -276,7 +279,6 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 3 unmodified lines
276 rtc->irq, ret);279 rtc->irq, ret);
277 goto fail_rtc_register;280 goto fail_rtc_register;
278 }281 }
279 disable_irq(rtc->irq);
280 282
281 ret = rtc_register_device(rtc->rtc);283 ret = rtc_register_device(rtc->rtc);
282 if (ret)284 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
94 * RTC has updated the CURRENT_TIME with the time written into94 * RTC has updated the CURRENT_TIME with the time written into
95 * SET_TIME_WRITE register.95 * SET_TIME_WRITE register.
96 */96 */
97 rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm);97 read_time = readl(xrtcdev->reg_base + RTC_CUR_TM);
98 } else {98 } else {
99 /*99 /*
100 * Time written in SET_TIME_WRITE has not yet updated into100 * 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
104 * reading.104 * reading.
105 */105 */
106 read_time = readl(xrtcdev->reg_base + RTC_SET_TM_RD) - 1;106 read_time = readl(xrtcdev->reg_base + RTC_SET_TM_RD) - 1;
107 rtc_time64_to_tm(read_time, tm);
108 }107 }
108 rtc_time64_to_tm(read_time, tm);
109 109
110 return 0;110 return 0;
111}111}
include/linux/rtc.h+1−0
@@ -167,6 +167,7 @@ struct rtc_device { · 166 unmodified lines
167#define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */167#define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */
168#define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */168#define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */
169#define RTC_TIMESTAMP_END_2063 2966371199LL /* 2063-12-31 23:59:59 */169#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 */
170#define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */171#define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */
171#define RTC_TIMESTAMP_END_2199 7258118399LL /* 2199-12-31 23:59:59 */172#define RTC_TIMESTAMP_END_2199 7258118399LL /* 2199-12-31 23:59:59 */
172#define RTC_TIMESTAMP_END_9999 253402300799LL /* 9999-12-31 23:59:59 */173#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
92#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */92#define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */
93#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */93#define RTC_PLL_SET _IOW('p', 0x12, struct rtc_pll_info) /* Set PLL correction */
94 94
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 */
96#define RTC_VL_CLR _IO('p', 0x14) /* Clear voltage low information */101#define RTC_VL_CLR _IO('p', 0x14) /* Clear voltage low information */
97 102
98/* interrupt flags */103/* interrupt flags */