Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+418 -561
+1
.mailmap
··· 18 18 Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com> 19 19 Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@intel.com> 20 20 Alex Shi <alex.shi@linux.alibaba.com> <alex.shi@linaro.org> 21 + Alexandre Belloni <alexandre.belloni@bootlin.com> <alexandre.belloni@free-electrons.com> 21 22 Alexei Starovoitov <ast@kernel.org> <ast@plumgrid.com> 22 23 Alexei Starovoitov <ast@kernel.org> <alexei.starovoitov@gmail.com> 23 24 Alexei Starovoitov <ast@kernel.org> <ast@fb.com>
+8
Documentation/ABI/testing/rtc-cdev
··· 33 33 Requires a separate RTC_PIE_ON call to enable the periodic 34 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 44 The ioctl() calls supported by the older /dev/rtc interface are 37 45 also supported by the newer RTC class framework. However, 38 46 because the chips and systems are not standardized, some PC/AT
-17
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.txt
··· 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 - };
+49
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.yaml
··· 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 + ...
+16 -8
drivers/rtc/Kconfig
··· 240 240 241 241 config RTC_DRV_DS1307 242 242 tristate "Dallas/Maxim DS1307/37/38/39/40/41, ST M41T00, EPSON RX-8025, ISL12057" 243 + select REGMAP_I2C 243 244 help 244 245 If you say yes here you get support for various compatible RTC 245 246 chips (often with battery backup) connected with I2C. This driver ··· 623 622 624 623 config RTC_DRV_RX8581 625 624 tristate "Epson RX-8571/RX-8581" 625 + select REGMAP_I2C 626 626 help 627 627 If you say yes here you will get support for the Epson RX-8571/ 628 628 RX-8581. ··· 651 649 652 650 config RTC_DRV_RV3028 653 651 tristate "Micro Crystal RV3028" 652 + select REGMAP_I2C 654 653 help 655 654 If you say yes here you get support for the Micro Crystal 656 655 RV3028. ··· 680 677 will be called rtc-s5m. 681 678 682 679 config RTC_DRV_SD3078 683 - tristate "ZXW Shenzhen whwave SD3078" 684 - help 685 - If you say yes here you get support for the ZXW Shenzhen whwave 686 - SD3078 RTC chips. 680 + tristate "ZXW Shenzhen whwave SD3078" 681 + select REGMAP_I2C 682 + help 683 + If you say yes here you get support for the ZXW Shenzhen whwave 684 + SD3078 RTC chips. 687 685 688 - This driver can also be built as a module. If so, the module 689 - will be called rtc-sd3078 686 + This driver can also be built as a module. If so, the module 687 + will be called rtc-sd3078 690 688 691 689 endif # I2C 692 690 ··· 853 849 default m if I2C=m 854 850 default y if I2C=y 855 851 default y if SPI_MASTER=y 856 - select REGMAP_I2C if I2C 857 - select REGMAP_SPI if SPI_MASTER 858 852 859 853 comment "SPI and I2C RTC drivers" 860 854 861 855 config RTC_DRV_DS3232 862 856 tristate "Dallas/Maxim DS3232/DS3234" 863 857 depends on RTC_I2C_AND_SPI 858 + select REGMAP_I2C if I2C 859 + select REGMAP_SPI if SPI_MASTER 864 860 help 865 861 If you say yes here you get support for Dallas Semiconductor 866 862 DS3232 and DS3234 real-time clock chips. If an interrupt is associated ··· 880 876 config RTC_DRV_PCF2127 881 877 tristate "NXP PCF2127" 882 878 depends on RTC_I2C_AND_SPI 879 + select REGMAP_I2C if I2C 880 + select REGMAP_SPI if SPI_MASTER 883 881 select WATCHDOG_CORE if WATCHDOG 884 882 help 885 883 If you say yes here you get support for the NXP PCF2127/29 RTC ··· 898 892 config RTC_DRV_RV3029C2 899 893 tristate "Micro Crystal RV3029/3049" 900 894 depends on RTC_I2C_AND_SPI 895 + select REGMAP_I2C if I2C 896 + select REGMAP_SPI if SPI_MASTER 901 897 help 902 898 If you say yes here you get support for the Micro Crystal 903 899 RV3029 and RV3049 RTC chips.
+2 -5
drivers/rtc/rtc-abx80x.c
··· 523 523 if (status < 0) 524 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))) 529 - return -EFAULT; 530 - 531 - return 0; 528 + return put_user(tmp, (unsigned int __user *)arg); 532 529 533 530 case RTC_VL_CLR: 534 531 status = i2c_smbus_read_byte_data(client, ABX8XX_REG_STATUS);
+3
drivers/rtc/rtc-asm9260.c
··· 264 264 return PTR_ERR(priv->iobase); 265 265 266 266 priv->clk = devm_clk_get(dev, "ahb"); 267 + if (IS_ERR(priv->clk)) 268 + return PTR_ERR(priv->clk); 269 + 267 270 ret = clk_prepare_enable(priv->clk); 268 271 if (ret) { 269 272 dev_err(dev, "Failed to enable clk!\n");
+74 -45
drivers/rtc/rtc-at91rm9200.c
··· 14 14 */ 15 15 16 16 #include <linux/bcd.h> 17 + #include <linux/bitfield.h> 17 18 #include <linux/clk.h> 18 19 #include <linux/completion.h> 19 20 #include <linux/interrupt.h> ··· 31 30 #include <linux/time.h> 32 31 #include <linux/uaccess.h> 33 32 34 - #include "rtc-at91rm9200.h" 33 + #define AT91_RTC_CR 0x00 /* Control Register */ 34 + #define AT91_RTC_UPDTIM BIT(0) /* Update Request Time Register */ 35 + #define AT91_RTC_UPDCAL BIT(1) /* Update Request Calendar Register */ 36 + 37 + #define AT91_RTC_MR 0x04 /* Mode Register */ 38 + 39 + #define AT91_RTC_TIMR 0x08 /* Time Register */ 40 + #define AT91_RTC_SEC GENMASK(6, 0) /* Current Second */ 41 + #define AT91_RTC_MIN GENMASK(14, 8) /* Current Minute */ 42 + #define AT91_RTC_HOUR GENMASK(21, 16) /* Current Hour */ 43 + #define AT91_RTC_AMPM BIT(22) /* Ante Meridiem Post Meridiem Indicator */ 44 + 45 + #define AT91_RTC_CALR 0x0c /* Calendar Register */ 46 + #define AT91_RTC_CENT GENMASK(6, 0) /* Current Century */ 47 + #define AT91_RTC_YEAR GENMASK(15, 8) /* Current Year */ 48 + #define AT91_RTC_MONTH GENMASK(20, 16) /* Current Month */ 49 + #define AT91_RTC_DAY GENMASK(23, 21) /* Current Day */ 50 + #define AT91_RTC_DATE GENMASK(29, 24) /* Current Date */ 51 + 52 + #define AT91_RTC_TIMALR 0x10 /* Time Alarm Register */ 53 + #define AT91_RTC_SECEN BIT(7) /* Second Alarm Enable */ 54 + #define AT91_RTC_MINEN BIT(15) /* Minute Alarm Enable */ 55 + #define AT91_RTC_HOUREN BIT(23) /* Hour Alarm Enable */ 56 + 57 + #define AT91_RTC_CALALR 0x14 /* Calendar Alarm Register */ 58 + #define AT91_RTC_MTHEN BIT(23) /* Month Alarm Enable */ 59 + #define AT91_RTC_DATEEN BIT(31) /* Date Alarm Enable */ 60 + 61 + #define AT91_RTC_SR 0x18 /* Status Register */ 62 + #define AT91_RTC_ACKUPD BIT(0) /* Acknowledge for Update */ 63 + #define AT91_RTC_ALARM BIT(1) /* Alarm Flag */ 64 + #define AT91_RTC_SECEV BIT(2) /* Second Event */ 65 + #define AT91_RTC_TIMEV BIT(3) /* Time Event */ 66 + #define AT91_RTC_CALEV BIT(4) /* Calendar Event */ 67 + 68 + #define AT91_RTC_SCCR 0x1c /* Status Clear Command Register */ 69 + #define AT91_RTC_IER 0x20 /* Interrupt Enable Register */ 70 + #define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */ 71 + #define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */ 72 + 73 + #define AT91_RTC_VER 0x2c /* Valid Entry Register */ 74 + #define AT91_RTC_NVTIM BIT(0) /* Non valid Time */ 75 + #define AT91_RTC_NVCAL BIT(1) /* Non valid Calendar */ 76 + #define AT91_RTC_NVTIMALR BIT(2) /* Non valid Time Alarm */ 77 + #define AT91_RTC_NVCALALR BIT(3) /* Non valid Calendar Alarm */ 35 78 36 79 #define at91_rtc_read(field) \ 37 80 readl_relaxed(at91_rtc_regs + field) ··· 162 117 } while ((time != at91_rtc_read(timereg)) || 163 118 (date != at91_rtc_read(calreg))); 164 119 165 - tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0); 166 - tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8); 167 - tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16); 120 + tm->tm_sec = bcd2bin(FIELD_GET(AT91_RTC_SEC, time)); 121 + tm->tm_min = bcd2bin(FIELD_GET(AT91_RTC_MIN, time)); 122 + tm->tm_hour = bcd2bin(FIELD_GET(AT91_RTC_HOUR, time)); 168 123 169 124 /* 170 125 * The Calendar Alarm register does not have a field for 171 126 * the year - so these will return an invalid value. 172 127 */ 173 128 tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */ 174 - tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */ 129 + tm->tm_year += bcd2bin(FIELD_GET(AT91_RTC_YEAR, date)); /* year */ 175 130 176 - tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */ 177 - tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1; 178 - tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24); 131 + tm->tm_wday = bcd2bin(FIELD_GET(AT91_RTC_DAY, date)) - 1; /* day of the week [0-6], Sunday=0 */ 132 + tm->tm_mon = bcd2bin(FIELD_GET(AT91_RTC_MONTH, date)) - 1; 133 + tm->tm_mday = bcd2bin(FIELD_GET(AT91_RTC_DATE, date)); 179 134 } 180 135 181 136 /* ··· 212 167 at91_rtc_write_idr(AT91_RTC_ACKUPD); 213 168 214 169 at91_rtc_write(AT91_RTC_TIMR, 215 - bin2bcd(tm->tm_sec) << 0 216 - | bin2bcd(tm->tm_min) << 8 217 - | bin2bcd(tm->tm_hour) << 16); 170 + FIELD_PREP(AT91_RTC_SEC, bin2bcd(tm->tm_sec)) 171 + | FIELD_PREP(AT91_RTC_MIN, bin2bcd(tm->tm_min)) 172 + | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(tm->tm_hour))); 218 173 219 174 at91_rtc_write(AT91_RTC_CALR, 220 - bin2bcd((tm->tm_year + 1900) / 100) /* century */ 221 - | bin2bcd(tm->tm_year % 100) << 8 /* year */ 222 - | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */ 223 - | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */ 224 - | bin2bcd(tm->tm_mday) << 24); 175 + FIELD_PREP(AT91_RTC_CENT, 176 + bin2bcd((tm->tm_year + 1900) / 100)) 177 + | FIELD_PREP(AT91_RTC_YEAR, bin2bcd(tm->tm_year % 100)) 178 + | FIELD_PREP(AT91_RTC_MONTH, bin2bcd(tm->tm_mon + 1)) 179 + | FIELD_PREP(AT91_RTC_DAY, bin2bcd(tm->tm_wday + 1)) 180 + | FIELD_PREP(AT91_RTC_DATE, bin2bcd(tm->tm_mday))); 225 181 226 182 /* Restart Time/Calendar */ 227 183 cr = at91_rtc_read(AT91_RTC_CR); ··· 257 211 */ 258 212 static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 259 213 { 260 - struct rtc_time tm; 261 - 262 - at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, &tm); 263 - 264 - tm.tm_mon = alrm->time.tm_mon; 265 - tm.tm_mday = alrm->time.tm_mday; 266 - tm.tm_hour = alrm->time.tm_hour; 267 - tm.tm_min = alrm->time.tm_min; 268 - tm.tm_sec = alrm->time.tm_sec; 214 + struct rtc_time tm = alrm->time; 269 215 270 216 at91_rtc_write_idr(AT91_RTC_ALARM); 271 217 at91_rtc_write(AT91_RTC_TIMALR, 272 - bin2bcd(tm.tm_sec) << 0 273 - | bin2bcd(tm.tm_min) << 8 274 - | bin2bcd(tm.tm_hour) << 16 218 + FIELD_PREP(AT91_RTC_SEC, bin2bcd(alrm->time.tm_sec)) 219 + | FIELD_PREP(AT91_RTC_MIN, bin2bcd(alrm->time.tm_min)) 220 + | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(alrm->time.tm_hour)) 275 221 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN); 276 222 at91_rtc_write(AT91_RTC_CALALR, 277 - bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */ 278 - | bin2bcd(tm.tm_mday) << 24 223 + FIELD_PREP(AT91_RTC_MONTH, bin2bcd(alrm->time.tm_mon + 1)) 224 + | FIELD_PREP(AT91_RTC_DATE, bin2bcd(alrm->time.tm_mday)) 279 225 | AT91_RTC_DATEEN | AT91_RTC_MTHEN); 280 226 281 227 if (alrm->enabled) { ··· 289 251 at91_rtc_write_ier(AT91_RTC_ALARM); 290 252 } else 291 253 at91_rtc_write_idr(AT91_RTC_ALARM); 292 - 293 - return 0; 294 - } 295 - /* 296 - * Provide additional RTC information in /proc/driver/rtc 297 - */ 298 - static int at91_rtc_proc(struct device *dev, struct seq_file *seq) 299 - { 300 - unsigned long imr = at91_rtc_read_imr(); 301 - 302 - seq_printf(seq, "update_IRQ\t: %s\n", 303 - (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); 304 - seq_printf(seq, "periodic_IRQ\t: %s\n", 305 - (imr & AT91_RTC_SECEV) ? "yes" : "no"); 306 254 307 255 return 0; 308 256 } ··· 351 327 .compatible = "atmel,at91sam9x5-rtc", 352 328 .data = &at91sam9x5_config, 353 329 }, { 330 + .compatible = "atmel,sama5d4-rtc", 331 + .data = &at91rm9200_config, 332 + }, { 333 + .compatible = "atmel,sama5d2-rtc", 334 + .data = &at91rm9200_config, 335 + }, { 354 336 /* sentinel */ 355 337 } 356 338 }; ··· 367 337 .set_time = at91_rtc_settime, 368 338 .read_alarm = at91_rtc_readalarm, 369 339 .set_alarm = at91_rtc_setalarm, 370 - .proc = at91_rtc_proc, 371 340 .alarm_irq_enable = at91_rtc_alarm_irq_enable, 372 341 }; 373 342
-71
drivers/rtc/rtc-at91rm9200.h
··· 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
+6 -6
drivers/rtc/rtc-cmos.c
··· 850 850 rtc_cmos_int_handler = cmos_interrupt; 851 851 852 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 854 cmos_rtc.rtc); 855 855 if (retval < 0) { 856 856 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq); ··· 1197 1197 /* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */ 1198 1198 static void use_acpi_alarm_quirks(void) 1199 1199 { 1200 - int year; 1201 - 1202 1200 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) 1203 1201 return; 1204 1202 ··· 1206 1208 if (!is_hpet_enabled()) 1207 1209 return; 1208 1210 1209 - if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015) 1210 - use_acpi_alarm = true; 1211 + if (dmi_get_bios_year() < 2015) 1212 + return; 1213 + 1214 + use_acpi_alarm = true; 1211 1215 } 1212 1216 #else 1213 1217 static inline void use_acpi_alarm_quirks(void) { } ··· 1305 1305 * hardcode it on systems with a legacy PIC. 1306 1306 */ 1307 1307 if (nr_legacy_irqs()) 1308 - irq = 8; 1308 + irq = RTC_IRQ; 1309 1309 #endif 1310 1310 return cmos_do_probe(&pnp->dev, 1311 1311 pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
+5 -5
drivers/rtc/rtc-ds1343.c
··· 75 75 MODULE_DEVICE_TABLE(spi, ds1343_id); 76 76 77 77 struct ds1343_priv { 78 - struct spi_device *spi; 79 78 struct rtc_device *rtc; 80 79 struct regmap *map; 81 80 int irq; ··· 361 362 if (!priv) 362 363 return -ENOMEM; 363 364 364 - priv->spi = spi; 365 - 366 365 /* RTC DS1347 works in spi mode 3 and 367 - * its chip select is active high 366 + * its chip select is active high. Active high should be defined as 367 + * "inverse polarity" as GPIO-based chip selects can be logically 368 + * active high but inverted by the GPIO library. 368 369 */ 369 - spi->mode = SPI_MODE_3 | SPI_CS_HIGH; 370 + spi->mode |= SPI_MODE_3; 371 + spi->mode ^= SPI_CS_HIGH; 370 372 spi->bits_per_word = 8; 371 373 res = spi_setup(spi); 372 374 if (res)
+7 -12
drivers/rtc/rtc-hym8563.c
··· 78 78 struct hym8563 { 79 79 struct i2c_client *client; 80 80 struct rtc_device *rtc; 81 - bool valid; 82 81 #ifdef CONFIG_COMMON_CLK 83 82 struct clk_hw clkout_hw; 84 83 #endif ··· 90 91 static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm) 91 92 { 92 93 struct i2c_client *client = to_i2c_client(dev); 93 - struct hym8563 *hym8563 = i2c_get_clientdata(client); 94 94 u8 buf[7]; 95 95 int ret; 96 - 97 - if (!hym8563->valid) { 98 - dev_warn(&client->dev, "no valid clock/calendar values available\n"); 99 - return -EPERM; 100 - } 101 96 102 97 ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf); 103 98 if (ret < 0) 104 99 return ret; 100 + 101 + if (buf[0] & HYM8563_SEC_VL) { 102 + dev_warn(&client->dev, 103 + "no valid clock/calendar values available\n"); 104 + return -EINVAL; 105 + } 105 106 106 107 tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK); 107 108 tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK); ··· 117 118 static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm) 118 119 { 119 120 struct i2c_client *client = to_i2c_client(dev); 120 - struct hym8563 *hym8563 = i2c_get_clientdata(client); 121 121 u8 buf[7]; 122 122 int ret; 123 123 ··· 154 156 ret = i2c_smbus_write_byte_data(client, HYM8563_CTL1, 0); 155 157 if (ret < 0) 156 158 return ret; 157 - 158 - hym8563->valid = true; 159 159 160 160 return 0; 161 161 } ··· 552 556 if (ret < 0) 553 557 return ret; 554 558 555 - hym8563->valid = !(ret & HYM8563_SEC_VL); 556 559 dev_dbg(&client->dev, "rtc information is %s\n", 557 - hym8563->valid ? "valid" : "invalid"); 560 + (ret & HYM8563_SEC_VL) ? "invalid" : "valid"); 558 561 559 562 hym8563->rtc = devm_rtc_device_register(&client->dev, client->name, 560 563 &hym8563_rtc_ops, THIS_MODULE);
+1 -4
drivers/rtc/rtc-moxart.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * MOXA ART RTC driver. 3 4 * ··· 8 7 * 9 8 * Based on code from 10 9 * Moxa Technology Co., Ltd. <www.moxa.com> 11 - * 12 - * This file is licensed under the terms of the GNU General Public 13 - * License version 2. This program is licensed "as is" without any 14 - * warranty of any kind, whether express or implied. 15 10 */ 16 11 17 12 #include <linux/init.h>
+1 -9
drivers/rtc/rtc-mt6397.c
··· 297 297 298 298 rtc->rtc_dev->ops = &mtk_rtc_ops; 299 299 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); 309 301 } 310 302 311 303 #ifdef CONFIG_PM_SLEEP
+1 -1
drivers/rtc/rtc-omap.c
··· 616 616 break; 617 617 default: 618 618 return -ENOTSUPP; 619 - }; 619 + } 620 620 621 621 *config = pinconf_to_config_packed(param, arg); 622 622
+2 -4
drivers/rtc/rtc-pcf2127.c
··· 199 199 if (ret) 200 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))) 205 - return -EFAULT; 206 - return 0; 204 + return put_user(touser, (unsigned int __user *)arg); 207 205 default: 208 206 return -ENOIOCTLCMD; 209 207 }
+2 -14
drivers/rtc/rtc-pcf85063.c
··· 289 289 if (ret < 0) 290 290 return ret; 291 291 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; 294 293 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); 307 295 308 296 default: 309 297 return -ENOIOCTLCMD;
+3 -3
drivers/rtc/rtc-pcf8523.c
··· 282 282 ret = pcf8523_voltage_low(client); 283 283 if (ret < 0) 284 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))) 287 - return -EFAULT; 288 + return put_user(ret, (unsigned int __user *)arg); 288 289 289 - return 0; 290 290 default: 291 291 return -ENOIOCTLCMD; 292 292 }
+9 -31
drivers/rtc/rtc-pcf8563.c
··· 22 22 23 23 #define PCF8563_REG_ST1 0x00 /* status */ 24 24 #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) 27 27 #define PCF8563_BITS_ST2_N (7 << 5) 28 28 29 29 #define PCF8563_REG_SC 0x02 /* datetime */ ··· 76 76 * 1970...2069. 77 77 */ 78 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 80 struct i2c_client *client; 82 81 #ifdef CONFIG_COMMON_CLK ··· 207 208 return err; 208 209 209 210 if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) { 210 - pcf8563->voltage_low = 1; 211 211 dev_err(&client->dev, 212 212 "low voltage detected, date/time is not reliable.\n"); 213 213 return -EINVAL; ··· 274 276 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); 275 277 } 276 278 277 - #ifdef CONFIG_RTC_INTF_DEV 278 279 static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 279 280 { 280 - struct pcf8563 *pcf8563 = i2c_get_clientdata(to_i2c_client(dev)); 281 - struct rtc_time tm; 281 + struct i2c_client *client = to_i2c_client(dev); 282 + int ret; 282 283 283 284 switch (cmd) { 284 285 case RTC_VL_READ: 285 - if (pcf8563->voltage_low) 286 - dev_info(dev, "low voltage detected, date/time is not reliable.\n"); 286 + ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC); 287 + if (ret < 0) 288 + return ret; 287 289 288 - if (copy_to_user((void __user *)arg, &pcf8563->voltage_low, 289 - sizeof(int))) 290 - return -EFAULT; 291 - return 0; 292 - case RTC_VL_CLR: 293 - /* 294 - * Clear the VL bit in the seconds register in case 295 - * the time has not been set already (which would 296 - * have cleared it). This does not really matter 297 - * because of the cached voltage_low value but do it 298 - * anyway for consistency. 299 - */ 300 - if (pcf8563_rtc_read_time(dev, &tm)) 301 - pcf8563_rtc_set_time(dev, &tm); 302 - 303 - /* Clear the cached value. */ 304 - pcf8563->voltage_low = 0; 305 - 306 - return 0; 290 + return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0, 291 + (unsigned int __user *)arg); 307 292 default: 308 293 return -ENOIOCTLCMD; 309 294 } 310 295 } 311 - #else 312 - #define pcf8563_rtc_ioctl NULL 313 - #endif 314 296 315 297 static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm) 316 298 {
+2 -15
drivers/rtc/rtc-rv3028.c
··· 428 428 if (ret < 0) 429 429 return ret; 430 430 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); 446 433 447 434 default: 448 435 return -ENOIOCTLCMD;
+185 -263
drivers/rtc/rtc-rv3029c2.c
··· 109 109 #define RV3029_CONTROL_E2P_TOV_MASK 0x3F /* XTAL turnover temp mask */ 110 110 111 111 /* 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 116 114 117 115 struct rv3029_data { 118 116 struct device *dev; ··· 119 121 int irq; 120 122 }; 121 123 122 - static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf, 123 - unsigned int len) 124 + static int rv3029_eeprom_busywait(struct rv3029_data *rv3029) 124 125 { 125 - struct rv3029_data *rv3029 = dev_get_drvdata(dev); 126 - 127 - if ((reg > RV3029_USR1_RAM_PAGE + 7) || 128 - (reg + len > RV3029_USR1_RAM_PAGE + 8)) 129 - return -EINVAL; 130 - 131 - return regmap_bulk_read(rv3029->regmap, reg, buf, len); 132 - } 133 - 134 - static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[], 135 - unsigned int len) 136 - { 137 - struct rv3029_data *rv3029 = dev_get_drvdata(dev); 138 - 139 - if ((reg > RV3029_USR1_RAM_PAGE + 7) || 140 - (reg + len > RV3029_USR1_RAM_PAGE + 8)) 141 - return -EINVAL; 142 - 143 - return regmap_bulk_write(rv3029->regmap, reg, buf, len); 144 - } 145 - 146 - static int rv3029_update_bits(struct device *dev, u8 reg, u8 mask, u8 set) 147 - { 148 - u8 buf; 149 - int ret; 150 - 151 - ret = rv3029_read_regs(dev, reg, &buf, 1); 152 - if (ret < 0) 153 - return ret; 154 - buf &= ~mask; 155 - buf |= set & mask; 156 - ret = rv3029_write_regs(dev, reg, &buf, 1); 157 - if (ret < 0) 158 - return ret; 159 - 160 - return 0; 161 - } 162 - 163 - static int rv3029_get_sr(struct device *dev, u8 *buf) 164 - { 165 - int ret = rv3029_read_regs(dev, RV3029_STATUS, buf, 1); 166 - 167 - if (ret < 0) 168 - return -EIO; 169 - dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 170 - return 0; 171 - } 172 - 173 - static int rv3029_set_sr(struct device *dev, u8 val) 174 - { 175 - u8 buf[1]; 176 - int sr; 177 - 178 - buf[0] = val; 179 - sr = rv3029_write_regs(dev, RV3029_STATUS, buf, 1); 180 - dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); 181 - if (sr < 0) 182 - return -EIO; 183 - return 0; 184 - } 185 - 186 - static int rv3029_eeprom_busywait(struct device *dev) 187 - { 126 + unsigned int sr; 188 127 int i, ret; 189 - u8 sr; 190 128 191 129 for (i = 100; i > 0; i--) { 192 - ret = rv3029_get_sr(dev, &sr); 130 + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); 193 131 if (ret < 0) 194 132 break; 195 133 if (!(sr & RV3029_STATUS_EEBUSY)) ··· 133 199 usleep_range(1000, 10000); 134 200 } 135 201 if (i <= 0) { 136 - dev_err(dev, "EEPROM busy wait timeout.\n"); 202 + dev_err(rv3029->dev, "EEPROM busy wait timeout.\n"); 137 203 return -ETIMEDOUT; 138 204 } 139 205 140 206 return ret; 141 207 } 142 208 143 - static int rv3029_eeprom_exit(struct device *dev) 209 + static int rv3029_eeprom_exit(struct rv3029_data *rv3029) 144 210 { 145 211 /* Re-enable eeprom refresh */ 146 - return rv3029_update_bits(dev, RV3029_ONOFF_CTRL, 212 + return regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL, 147 213 RV3029_ONOFF_CTRL_EERE, 148 214 RV3029_ONOFF_CTRL_EERE); 149 215 } 150 216 151 - static int rv3029_eeprom_enter(struct device *dev) 217 + static int rv3029_eeprom_enter(struct rv3029_data *rv3029) 152 218 { 219 + unsigned int sr; 153 220 int ret; 154 - u8 sr; 155 221 156 222 /* Check whether we are in the allowed voltage range. */ 157 - ret = rv3029_get_sr(dev, &sr); 223 + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); 158 224 if (ret < 0) 159 225 return ret; 160 - if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 226 + if (sr & RV3029_STATUS_VLOW2) 227 + return -ENODEV; 228 + if (sr & RV3029_STATUS_VLOW1) { 161 229 /* We clear the bits and retry once just in case 162 230 * we had a brown out in early startup. 163 231 */ 164 - sr &= ~RV3029_STATUS_VLOW1; 165 - sr &= ~RV3029_STATUS_VLOW2; 166 - ret = rv3029_set_sr(dev, sr); 232 + ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS, 233 + RV3029_STATUS_VLOW1, 0); 167 234 if (ret < 0) 168 235 return ret; 169 236 usleep_range(1000, 10000); 170 - ret = rv3029_get_sr(dev, &sr); 237 + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); 171 238 if (ret < 0) 172 239 return ret; 173 - if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { 174 - dev_err(dev, 240 + if (sr & RV3029_STATUS_VLOW1) { 241 + dev_err(rv3029->dev, 175 242 "Supply voltage is too low to safely access the EEPROM.\n"); 176 243 return -ENODEV; 177 244 } 178 245 } 179 246 180 247 /* Disable eeprom refresh. */ 181 - ret = rv3029_update_bits(dev, RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE, 182 - 0); 248 + ret = regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL, 249 + RV3029_ONOFF_CTRL_EERE, 0); 183 250 if (ret < 0) 184 251 return ret; 185 252 186 253 /* Wait for any previous eeprom accesses to finish. */ 187 - ret = rv3029_eeprom_busywait(dev); 254 + ret = rv3029_eeprom_busywait(rv3029); 188 255 if (ret < 0) 189 - rv3029_eeprom_exit(dev); 256 + rv3029_eeprom_exit(rv3029); 190 257 191 258 return ret; 192 259 } 193 260 194 - static int rv3029_eeprom_read(struct device *dev, u8 reg, 261 + static int rv3029_eeprom_read(struct rv3029_data *rv3029, u8 reg, 195 262 u8 buf[], size_t len) 196 263 { 197 264 int ret, err; 198 265 199 - err = rv3029_eeprom_enter(dev); 266 + err = rv3029_eeprom_enter(rv3029); 200 267 if (err < 0) 201 268 return err; 202 269 203 - ret = rv3029_read_regs(dev, reg, buf, len); 270 + ret = regmap_bulk_read(rv3029->regmap, reg, buf, len); 204 271 205 - err = rv3029_eeprom_exit(dev); 272 + err = rv3029_eeprom_exit(rv3029); 206 273 if (err < 0) 207 274 return err; 208 275 209 276 return ret; 210 277 } 211 278 212 - static int rv3029_eeprom_write(struct device *dev, u8 reg, 279 + static int rv3029_eeprom_write(struct rv3029_data *rv3029, u8 reg, 213 280 u8 const buf[], size_t len) 214 281 { 282 + unsigned int tmp; 215 283 int ret, err; 216 284 size_t i; 217 - u8 tmp; 218 285 219 - err = rv3029_eeprom_enter(dev); 286 + err = rv3029_eeprom_enter(rv3029); 220 287 if (err < 0) 221 288 return err; 222 289 223 290 for (i = 0; i < len; i++, reg++) { 224 - ret = rv3029_read_regs(dev, reg, &tmp, 1); 291 + ret = regmap_read(rv3029->regmap, reg, &tmp); 225 292 if (ret < 0) 226 293 break; 227 294 if (tmp != buf[i]) { 228 - ret = rv3029_write_regs(dev, reg, &buf[i], 1); 295 + tmp = buf[i]; 296 + ret = regmap_write(rv3029->regmap, reg, tmp); 229 297 if (ret < 0) 230 298 break; 231 299 } 232 - ret = rv3029_eeprom_busywait(dev); 300 + ret = rv3029_eeprom_busywait(rv3029); 233 301 if (ret < 0) 234 302 break; 235 303 } 236 304 237 - err = rv3029_eeprom_exit(dev); 305 + err = rv3029_eeprom_exit(rv3029); 238 306 if (err < 0) 239 307 return err; 240 308 241 309 return ret; 242 310 } 243 311 244 - static int rv3029_eeprom_update_bits(struct device *dev, 312 + static int rv3029_eeprom_update_bits(struct rv3029_data *rv3029, 245 313 u8 reg, u8 mask, u8 set) 246 314 { 247 315 u8 buf; 248 316 int ret; 249 317 250 - ret = rv3029_eeprom_read(dev, reg, &buf, 1); 318 + ret = rv3029_eeprom_read(rv3029, reg, &buf, 1); 251 319 if (ret < 0) 252 320 return ret; 253 321 buf &= ~mask; 254 322 buf |= set & mask; 255 - ret = rv3029_eeprom_write(dev, reg, &buf, 1); 323 + ret = rv3029_eeprom_write(rv3029, reg, &buf, 1); 256 324 if (ret < 0) 257 325 return ret; 258 326 ··· 266 330 struct device *dev = dev_id; 267 331 struct rv3029_data *rv3029 = dev_get_drvdata(dev); 268 332 struct mutex *lock = &rv3029->rtc->ops_lock; 333 + unsigned int flags, controls; 269 334 unsigned long events = 0; 270 - u8 flags, controls; 271 335 int ret; 272 336 273 337 mutex_lock(lock); 274 338 275 - ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1); 339 + ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls); 276 340 if (ret) { 277 341 dev_warn(dev, "Read IRQ Control Register error %d\n", ret); 278 342 mutex_unlock(lock); 279 343 return IRQ_NONE; 280 344 } 281 345 282 - ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1); 346 + ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags); 283 347 if (ret) { 284 348 dev_warn(dev, "Read IRQ Flags Register error %d\n", ret); 285 349 mutex_unlock(lock); ··· 294 358 295 359 if (events) { 296 360 rtc_update_irq(rv3029->rtc, 1, events); 297 - rv3029_write_regs(dev, RV3029_IRQ_FLAGS, &flags, 1); 298 - rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1); 361 + regmap_write(rv3029->regmap, RV3029_IRQ_FLAGS, flags); 362 + regmap_write(rv3029->regmap, RV3029_IRQ_CTRL, controls); 299 363 } 300 364 mutex_unlock(lock); 301 365 ··· 304 368 305 369 static int rv3029_read_time(struct device *dev, struct rtc_time *tm) 306 370 { 307 - u8 buf[1]; 371 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 372 + unsigned int sr; 308 373 int ret; 309 374 u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; 310 375 311 - ret = rv3029_get_sr(dev, buf); 312 - if (ret < 0) { 313 - dev_err(dev, "%s: reading SR failed\n", __func__); 314 - return -EIO; 315 - } 316 - 317 - ret = rv3029_read_regs(dev, RV3029_W_SEC, regs, 318 - RV3029_WATCH_SECTION_LEN); 319 - if (ret < 0) { 320 - dev_err(dev, "%s: reading RTC section failed\n", __func__); 376 + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); 377 + if (ret < 0) 321 378 return ret; 322 - } 379 + 380 + if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON)) 381 + return -EINVAL; 382 + 383 + ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs, 384 + RV3029_WATCH_SECTION_LEN); 385 + if (ret < 0) 386 + return ret; 323 387 324 388 tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]); 325 389 tm->tm_min = bcd2bin(regs[RV3029_W_MINUTES - RV3029_W_SEC]); ··· 347 411 348 412 static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 349 413 { 414 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 350 415 struct rtc_time *const tm = &alarm->time; 416 + unsigned int controls, flags; 351 417 int ret; 352 - u8 regs[8], controls, flags; 418 + u8 regs[8]; 353 419 354 - ret = rv3029_get_sr(dev, regs); 355 - if (ret < 0) { 356 - dev_err(dev, "%s: reading SR failed\n", __func__); 357 - return -EIO; 358 - } 359 - 360 - ret = rv3029_read_regs(dev, RV3029_A_SC, regs, 420 + ret = regmap_bulk_read(rv3029->regmap, RV3029_A_SC, regs, 361 421 RV3029_ALARM_SECTION_LEN); 422 + if (ret < 0) 423 + return ret; 362 424 363 - if (ret < 0) { 364 - dev_err(dev, "%s: reading alarm section failed\n", __func__); 425 + ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls); 426 + if (ret) 365 427 return ret; 366 - } 367 428 368 - ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1); 369 - if (ret) { 370 - dev_err(dev, "Read IRQ Control Register error %d\n", ret); 429 + ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags); 430 + if (ret < 0) 371 431 return ret; 372 - } 373 - ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1); 374 - if (ret < 0) { 375 - dev_err(dev, "Read IRQ Flags Register error %d\n", ret); 376 - return ret; 377 - } 378 432 379 433 tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f); 380 434 tm->tm_min = bcd2bin(regs[RV3029_A_MN - RV3029_A_SC] & 0x7f); ··· 382 456 383 457 static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable) 384 458 { 385 - int ret; 386 - u8 controls; 459 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 387 460 388 - ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1); 389 - if (ret < 0) { 390 - dev_warn(dev, "Read IRQ Control Register error %d\n", ret); 391 - return ret; 392 - } 393 - 394 - /* enable/disable AIE irq */ 395 - if (enable) 396 - controls |= RV3029_IRQ_CTRL_AIE; 397 - else 398 - controls &= ~RV3029_IRQ_CTRL_AIE; 399 - 400 - ret = rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1); 401 - if (ret < 0) { 402 - dev_err(dev, "can't update INT reg\n"); 403 - return ret; 404 - } 405 - 406 - return 0; 461 + return regmap_update_bits(rv3029->regmap, RV3029_IRQ_CTRL, 462 + RV3029_IRQ_CTRL_AIE, 463 + enable ? RV3029_IRQ_CTRL_AIE : 0); 407 464 } 408 465 409 466 static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 410 467 { 468 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 411 469 struct rtc_time *const tm = &alarm->time; 412 470 int ret; 413 471 u8 regs[8]; 414 - 415 - /* 416 - * The clock has an 8 bit wide bcd-coded register (they never learn) 417 - * for the year. tm_year is an offset from 1900 and we are interested 418 - * in the 2000-2099 range, so any value less than 100 is invalid. 419 - */ 420 - if (tm->tm_year < 100) 421 - return -EINVAL; 422 - 423 - ret = rv3029_get_sr(dev, regs); 424 - if (ret < 0) { 425 - dev_err(dev, "%s: reading SR failed\n", __func__); 426 - return -EIO; 427 - } 428 472 429 473 /* Activate all the alarms with AE_x bit */ 430 474 regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X; ··· 411 515 | RV3029_A_AE_X; 412 516 413 517 /* Write the alarm */ 414 - ret = rv3029_write_regs(dev, RV3029_A_SC, regs, 518 + ret = regmap_bulk_write(rv3029->regmap, RV3029_A_SC, regs, 415 519 RV3029_ALARM_SECTION_LEN); 416 520 if (ret < 0) 417 521 return ret; 418 522 419 - if (alarm->enabled) { 420 - /* enable AIE irq */ 421 - ret = rv3029_alarm_irq_enable(dev, 1); 422 - if (ret) 423 - return ret; 424 - } else { 425 - /* disable AIE irq */ 426 - ret = rv3029_alarm_irq_enable(dev, 0); 427 - if (ret) 428 - return ret; 429 - } 430 - 431 - return 0; 523 + return rv3029_alarm_irq_enable(dev, alarm->enabled); 432 524 } 433 525 434 526 static int rv3029_set_time(struct device *dev, struct rtc_time *tm) 435 527 { 528 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 436 529 u8 regs[8]; 437 530 int ret; 438 - 439 - /* 440 - * The clock has an 8 bit wide bcd-coded register (they never learn) 441 - * for the year. tm_year is an offset from 1900 and we are interested 442 - * in the 2000-2099 range, so any value less than 100 is invalid. 443 - */ 444 - if (tm->tm_year < 100) 445 - return -EINVAL; 446 531 447 532 regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec); 448 533 regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min); ··· 433 556 regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7; 434 557 regs[RV3029_W_YEARS - RV3029_W_SEC] = bin2bcd(tm->tm_year - 100); 435 558 436 - ret = rv3029_write_regs(dev, RV3029_W_SEC, regs, 559 + ret = regmap_bulk_write(rv3029->regmap, RV3029_W_SEC, regs, 437 560 RV3029_WATCH_SECTION_LEN); 438 561 if (ret < 0) 439 562 return ret; 440 563 441 - ret = rv3029_get_sr(dev, regs); 442 - if (ret < 0) { 443 - dev_err(dev, "%s: reading SR failed\n", __func__); 444 - return ret; 445 - } 446 - /* clear PON bit */ 447 - ret = rv3029_set_sr(dev, (regs[0] & ~RV3029_STATUS_PON)); 448 - if (ret < 0) { 449 - dev_err(dev, "%s: reading SR failed\n", __func__); 450 - return ret; 451 - } 564 + /* clear PON and VLOW2 bits */ 565 + return regmap_update_bits(rv3029->regmap, RV3029_STATUS, 566 + RV3029_STATUS_PON | RV3029_STATUS_VLOW2, 0); 567 + } 452 568 453 - return 0; 569 + static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 570 + { 571 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 572 + unsigned long vl = 0; 573 + int sr, ret = 0; 574 + 575 + switch (cmd) { 576 + case RTC_VL_READ: 577 + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); 578 + if (ret < 0) 579 + return ret; 580 + 581 + if (sr & RV3029_STATUS_VLOW1) 582 + vl = RTC_VL_ACCURACY_LOW; 583 + 584 + if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON)) 585 + vl |= RTC_VL_DATA_INVALID; 586 + 587 + return put_user(vl, (unsigned int __user *)arg); 588 + 589 + case RTC_VL_CLR: 590 + return regmap_update_bits(rv3029->regmap, RV3029_STATUS, 591 + RV3029_STATUS_VLOW1, 0); 592 + 593 + default: 594 + return -ENOIOCTLCMD; 595 + } 596 + } 597 + 598 + static int rv3029_nvram_write(void *priv, unsigned int offset, void *val, 599 + size_t bytes) 600 + { 601 + return regmap_bulk_write(priv, RV3029_RAM_PAGE + offset, val, bytes); 602 + } 603 + 604 + static int rv3029_nvram_read(void *priv, unsigned int offset, void *val, 605 + size_t bytes) 606 + { 607 + return regmap_bulk_read(priv, RV3029_RAM_PAGE + offset, val, bytes); 454 608 } 455 609 456 610 static const struct rv3029_trickle_tab_elem { ··· 543 635 544 636 static void rv3029_trickle_config(struct device *dev) 545 637 { 638 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 546 639 struct device_node *of_node = dev->of_node; 547 640 const struct rv3029_trickle_tab_elem *elem; 548 641 int i, err; ··· 570 661 "Trickle charger enabled at %d ohms resistance.\n", 571 662 elem->r); 572 663 } 573 - err = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL, 664 + err = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL, 574 665 RV3029_TRICKLE_MASK, 575 666 trickle_set_bits); 576 667 if (err < 0) ··· 579 670 580 671 #ifdef CONFIG_RTC_DRV_RV3029_HWMON 581 672 582 - static int rv3029_read_temp(struct device *dev, int *temp_mC) 673 + static int rv3029_read_temp(struct rv3029_data *rv3029, int *temp_mC) 583 674 { 675 + unsigned int temp; 584 676 int ret; 585 - u8 temp; 586 677 587 - ret = rv3029_read_regs(dev, RV3029_TEMP_PAGE, &temp, 1); 678 + ret = regmap_read(rv3029->regmap, RV3029_TEMP_PAGE, &temp); 588 679 if (ret < 0) 589 680 return ret; 590 681 ··· 597 688 struct device_attribute *attr, 598 689 char *buf) 599 690 { 691 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 600 692 int ret, temp_mC; 601 693 602 - ret = rv3029_read_temp(dev, &temp_mC); 694 + ret = rv3029_read_temp(rv3029, &temp_mC); 603 695 if (ret < 0) 604 696 return ret; 605 697 ··· 612 702 const char *buf, 613 703 size_t count) 614 704 { 705 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 706 + unsigned int th_set_bits = 0; 615 707 unsigned long interval_ms; 616 708 int ret; 617 - u8 th_set_bits = 0; 618 709 619 710 ret = kstrtoul(buf, 10, &interval_ms); 620 711 if (ret < 0) ··· 626 715 if (interval_ms >= 16000) 627 716 th_set_bits |= RV3029_EECTRL_THP; 628 717 } 629 - ret = rv3029_eeprom_update_bits(dev, RV3029_CONTROL_E2P_EECTRL, 718 + ret = rv3029_eeprom_update_bits(rv3029, RV3029_CONTROL_E2P_EECTRL, 630 719 RV3029_EECTRL_THE | RV3029_EECTRL_THP, 631 720 th_set_bits); 632 721 if (ret < 0) ··· 639 728 struct device_attribute *attr, 640 729 char *buf) 641 730 { 731 + struct rv3029_data *rv3029 = dev_get_drvdata(dev); 642 732 int ret, interval_ms; 643 733 u8 eectrl; 644 734 645 - ret = rv3029_eeprom_read(dev, RV3029_CONTROL_E2P_EECTRL, 735 + ret = rv3029_eeprom_read(rv3029, RV3029_CONTROL_E2P_EECTRL, 646 736 &eectrl, 1); 647 737 if (ret < 0) 648 738 return ret; ··· 697 785 static struct rtc_class_ops rv3029_rtc_ops = { 698 786 .read_time = rv3029_read_time, 699 787 .set_time = rv3029_set_time, 788 + .ioctl = rv3029_ioctl, 700 789 }; 701 790 702 791 static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, 703 792 const char *name) 704 793 { 705 794 struct rv3029_data *rv3029; 795 + struct nvmem_config nvmem_cfg = { 796 + .name = "rv3029_nvram", 797 + .word_size = 1, 798 + .stride = 1, 799 + .size = RV3029_RAM_SECTION_LEN, 800 + .type = NVMEM_TYPE_BATTERY_BACKED, 801 + .reg_read = rv3029_nvram_read, 802 + .reg_write = rv3029_nvram_write, 803 + }; 706 804 int rc = 0; 707 - u8 buf[1]; 708 805 709 806 rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL); 710 807 if (!rv3029) ··· 724 803 rv3029->dev = dev; 725 804 dev_set_drvdata(dev, rv3029); 726 805 727 - rc = rv3029_get_sr(dev, buf); 728 - if (rc < 0) { 729 - dev_err(dev, "reading status failed\n"); 730 - return rc; 731 - } 732 - 733 806 rv3029_trickle_config(dev); 734 807 rv3029_hwmon_register(dev, name); 735 808 736 - rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops, 737 - THIS_MODULE); 738 - if (IS_ERR(rv3029->rtc)) { 739 - dev_err(dev, "unable to register the class device\n"); 809 + rv3029->rtc = devm_rtc_allocate_device(dev); 810 + if (IS_ERR(rv3029->rtc)) 740 811 return PTR_ERR(rv3029->rtc); 741 - } 742 812 743 813 if (rv3029->irq > 0) { 744 814 rc = devm_request_threaded_irq(dev, rv3029->irq, ··· 746 834 } 747 835 } 748 836 837 + rv3029->rtc->ops = &rv3029_rtc_ops; 838 + rv3029->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 839 + rv3029->rtc->range_max = RTC_TIMESTAMP_END_2079; 840 + 841 + rc = rtc_register_device(rv3029->rtc); 842 + if (rc) 843 + return rc; 844 + 845 + nvmem_cfg.priv = rv3029->regmap; 846 + rtc_nvmem_register(rv3029->rtc, &nvmem_cfg); 847 + 749 848 return 0; 750 849 } 850 + 851 + static const struct regmap_range rv3029_holes_range[] = { 852 + regmap_reg_range(0x05, 0x07), 853 + regmap_reg_range(0x0f, 0x0f), 854 + regmap_reg_range(0x17, 0x17), 855 + regmap_reg_range(0x1a, 0x1f), 856 + regmap_reg_range(0x21, 0x27), 857 + regmap_reg_range(0x34, 0x37), 858 + }; 859 + 860 + static const struct regmap_access_table rv3029_regs = { 861 + .no_ranges = rv3029_holes_range, 862 + .n_no_ranges = ARRAY_SIZE(rv3029_holes_range), 863 + }; 864 + 865 + static const struct regmap_config config = { 866 + .reg_bits = 8, 867 + .val_bits = 8, 868 + .rd_table = &rv3029_regs, 869 + .wr_table = &rv3029_regs, 870 + .max_register = 0x3f, 871 + }; 751 872 752 873 #if IS_ENABLED(CONFIG_I2C) 753 874 ··· 788 843 const struct i2c_device_id *id) 789 844 { 790 845 struct regmap *regmap; 791 - static const struct regmap_config config = { 792 - .reg_bits = 8, 793 - .val_bits = 8, 794 - }; 795 - 796 846 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | 797 847 I2C_FUNC_SMBUS_BYTE)) { 798 848 dev_err(&client->dev, "Adapter does not support SMBUS_I2C_BLOCK or SMBUS_I2C_BYTE\n"); ··· 795 855 } 796 856 797 857 regmap = devm_regmap_init_i2c(client, &config); 798 - if (IS_ERR(regmap)) { 799 - dev_err(&client->dev, "%s: regmap allocation failed: %ld\n", 800 - __func__, PTR_ERR(regmap)); 858 + if (IS_ERR(regmap)) 801 859 return PTR_ERR(regmap); 802 - } 803 860 804 861 return rv3029_probe(&client->dev, regmap, client->irq, client->name); 805 862 } ··· 810 873 811 874 static const struct of_device_id rv3029_of_match[] = { 812 875 { .compatible = "microcrystal,rv3029" }, 813 - /* Backward compatibility only, do not use compatibles below: */ 814 - { .compatible = "rv3029" }, 815 - { .compatible = "rv3029c2" }, 816 - { .compatible = "mc,rv3029c2" }, 817 876 { } 818 877 }; 819 878 MODULE_DEVICE_TABLE(of, rv3029_of_match); 820 879 821 880 static struct i2c_driver rv3029_driver = { 822 881 .driver = { 823 - .name = "rtc-rv3029c2", 882 + .name = "rv3029", 824 883 .of_match_table = of_match_ptr(rv3029_of_match), 825 884 }, 826 885 .probe = rv3029_i2c_probe, 827 886 .id_table = rv3029_id, 828 887 }; 829 888 830 - static int rv3029_register_driver(void) 889 + static int __init rv3029_register_driver(void) 831 890 { 832 891 return i2c_add_driver(&rv3029_driver); 833 892 } ··· 835 902 836 903 #else 837 904 838 - static int rv3029_register_driver(void) 905 + static int __init rv3029_register_driver(void) 839 906 { 840 907 return 0; 841 908 } ··· 850 917 851 918 static int rv3049_probe(struct spi_device *spi) 852 919 { 853 - static const struct regmap_config config = { 854 - .reg_bits = 8, 855 - .val_bits = 8, 856 - }; 857 920 struct regmap *regmap; 858 921 859 922 regmap = devm_regmap_init_spi(spi, &config); 860 - if (IS_ERR(regmap)) { 861 - dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", 862 - __func__, PTR_ERR(regmap)); 923 + if (IS_ERR(regmap)) 863 924 return PTR_ERR(regmap); 864 - } 865 925 866 926 return rv3029_probe(&spi->dev, regmap, spi->irq, "rv3049"); 867 927 } ··· 866 940 .probe = rv3049_probe, 867 941 }; 868 942 869 - static int rv3049_register_driver(void) 943 + static int __init rv3049_register_driver(void) 870 944 { 871 945 return spi_register_driver(&rv3049_driver); 872 946 } 873 947 874 - static void rv3049_unregister_driver(void) 948 + static void __exit rv3049_unregister_driver(void) 875 949 { 876 950 spi_unregister_driver(&rv3049_driver); 877 951 } 878 952 879 953 #else 880 954 881 - static int rv3049_register_driver(void) 955 + static int __init rv3049_register_driver(void) 882 956 { 883 957 return 0; 884 958 } 885 959 886 - static void rv3049_unregister_driver(void) 960 + static void __exit rv3049_unregister_driver(void) 887 961 { 888 962 } 889 963 ··· 894 968 int ret; 895 969 896 970 ret = rv3029_register_driver(); 897 - if (ret) { 898 - pr_err("Failed to register rv3029 driver: %d\n", ret); 971 + if (ret) 899 972 return ret; 900 - } 901 973 902 974 ret = rv3049_register_driver(); 903 - if (ret) { 904 - pr_err("Failed to register rv3049 driver: %d\n", ret); 975 + if (ret) 905 976 rv3029_unregister_driver(); 906 - } 907 977 908 978 return ret; 909 979 }
+7 -9
drivers/rtc/rtc-rv8803.c
··· 411 411 { 412 412 struct i2c_client *client = to_i2c_client(dev); 413 413 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 414 + unsigned int vl = 0; 414 415 int flags, ret = 0; 415 416 416 417 switch (cmd) { ··· 420 419 if (flags < 0) 421 420 return flags; 422 421 423 - if (flags & RV8803_FLAG_V1F) 422 + if (flags & RV8803_FLAG_V1F) { 424 423 dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); 424 + vl = RTC_VL_ACCURACY_LOW; 425 + } 425 426 426 427 if (flags & RV8803_FLAG_V2F) 427 - dev_warn(&client->dev, "Voltage low, data loss detected.\n"); 428 + vl |= RTC_VL_DATA_INVALID; 428 429 429 - flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F; 430 - 431 - if (copy_to_user((void __user *)arg, &flags, sizeof(int))) 432 - return -EFAULT; 433 - 434 - return 0; 430 + return put_user(vl, (unsigned int __user *)arg); 435 431 436 432 case RTC_VL_CLR: 437 433 mutex_lock(&rv8803->flags_lock); ··· 438 440 return flags; 439 441 } 440 442 441 - flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F); 443 + flags &= ~RV8803_FLAG_V1F; 442 444 ret = rv8803_write_reg(client, RV8803_FLAG, flags); 443 445 mutex_unlock(&rv8803->flags_lock); 444 446 if (ret)
+4 -21
drivers/rtc/rtc-rx8010.c
··· 389 389 390 390 static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 391 391 { 392 - struct i2c_client *client = to_i2c_client(dev); 393 392 struct rx8010_data *rx8010 = dev_get_drvdata(dev); 394 - int ret, tmp; 393 + int tmp; 395 394 int flagreg; 396 395 397 396 switch (cmd) { ··· 399 400 if (flagreg < 0) 400 401 return flagreg; 401 402 402 - tmp = !!(flagreg & RX8010_FLAG_VLF); 403 - if (copy_to_user((void __user *)arg, &tmp, sizeof(int))) 404 - return -EFAULT; 405 - 406 - return 0; 407 - 408 - case RTC_VL_CLR: 409 - flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); 410 - if (flagreg < 0) { 411 - return flagreg; 412 - } 413 - 414 - flagreg &= ~RX8010_FLAG_VLF; 415 - ret = i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg); 416 - if (ret < 0) 417 - return ret; 418 - 419 - return 0; 403 + tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0; 404 + return put_user(tmp, (unsigned int __user *)arg); 420 405 421 406 default: 422 407 return -ENOIOCTLCMD; ··· 465 482 466 483 rx8010->rtc->max_user_freq = 1; 467 484 468 - return err; 485 + return 0; 469 486 } 470 487 471 488 static struct i2c_driver rx8010_driver = {
+14 -13
drivers/rtc/rtc-rx8025.c
··· 67 67 MODULE_DEVICE_TABLE(i2c, rx8025_id); 68 68 69 69 struct rx8025_data { 70 - struct i2c_client *client; 71 70 struct rtc_device *rtc; 72 71 u8 ctrl1; 73 72 }; ··· 102 103 103 104 static int rx8025_check_validity(struct device *dev) 104 105 { 105 - struct rx8025_data *rx8025 = dev_get_drvdata(dev); 106 + struct i2c_client *client = to_i2c_client(dev); 106 107 int ctrl2; 107 108 108 - ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2); 109 + ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); 109 110 if (ctrl2 < 0) 110 111 return ctrl2; 111 112 ··· 177 178 178 179 static int rx8025_get_time(struct device *dev, struct rtc_time *dt) 179 180 { 181 + struct i2c_client *client = to_i2c_client(dev); 180 182 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 181 183 u8 date[7]; 182 184 int err; ··· 186 186 if (err) 187 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 190 if (err) 191 191 return err; 192 192 ··· 211 211 212 212 static int rx8025_set_time(struct device *dev, struct rtc_time *dt) 213 213 { 214 + struct i2c_client *client = to_i2c_client(dev); 214 215 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 215 216 u8 date[7]; 216 217 int ret; ··· 238 237 239 238 dev_dbg(dev, "%s: write %7ph\n", __func__, date); 240 239 241 - ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date); 240 + ret = rx8025_write_regs(client, RX8025_REG_SEC, 7, date); 242 241 if (ret < 0) 243 242 return ret; 244 243 245 - return rx8025_reset_validity(rx8025->client); 244 + return rx8025_reset_validity(client); 246 245 } 247 246 248 247 static int rx8025_init_client(struct i2c_client *client) ··· 252 251 int need_clear = 0; 253 252 int err; 254 253 255 - err = rx8025_read_regs(rx8025->client, RX8025_REG_CTRL1, 2, ctrl); 254 + err = rx8025_read_regs(client, RX8025_REG_CTRL1, 2, ctrl); 256 255 if (err) 257 256 goto out; 258 257 ··· 281 280 /* Alarm support */ 282 281 static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) 283 282 { 283 + struct i2c_client *client = to_i2c_client(dev); 284 284 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 285 - struct i2c_client *client = rx8025->client; 286 285 u8 ald[2]; 287 286 int ctrl2, err; 288 287 ··· 348 347 349 348 if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) { 350 349 rx8025->ctrl1 &= ~RX8025_BIT_CTRL1_DALE; 351 - err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1, 350 + err = rx8025_write_reg(client, RX8025_REG_CTRL1, 352 351 rx8025->ctrl1); 353 352 if (err) 354 353 return err; 355 354 } 356 - err = rx8025_write_regs(rx8025->client, RX8025_REG_ALDMIN, 2, ald); 355 + err = rx8025_write_regs(client, RX8025_REG_ALDMIN, 2, ald); 357 356 if (err) 358 357 return err; 359 358 360 359 if (t->enabled) { 361 360 rx8025->ctrl1 |= RX8025_BIT_CTRL1_DALE; 362 - err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1, 361 + err = rx8025_write_reg(client, RX8025_REG_CTRL1, 363 362 rx8025->ctrl1); 364 363 if (err) 365 364 return err; ··· 370 369 371 370 static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled) 372 371 { 372 + struct i2c_client *client = to_i2c_client(dev); 373 373 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 374 374 u8 ctrl1; 375 375 int err; ··· 383 381 384 382 if (ctrl1 != rx8025->ctrl1) { 385 383 rx8025->ctrl1 = ctrl1; 386 - err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1, 384 + err = rx8025_write_reg(client, RX8025_REG_CTRL1, 387 385 rx8025->ctrl1); 388 386 if (err) 389 387 return err; ··· 518 516 if (!rx8025) 519 517 return -ENOMEM; 520 518 521 - rx8025->client = client; 522 519 i2c_set_clientdata(client, rx8025); 523 520 524 521 err = rx8025_init_client(client);
+4 -1
drivers/rtc/rtc-stm32.c
··· 897 897 } 898 898 899 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 903 return ret; 904 + } 902 905 903 906 if (device_may_wakeup(dev)) 904 907 return disable_irq_wake(rtc->irq_alarm);
+3 -1
drivers/rtc/rtc-tps6586x.c
··· 23 23 #include <linux/device.h> 24 24 #include <linux/err.h> 25 25 #include <linux/init.h> 26 + #include <linux/irq.h> 26 27 #include <linux/kernel.h> 27 28 #include <linux/mfd/tps6586x.h> 28 29 #include <linux/module.h> ··· 268 267 rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0); 269 268 rtc->rtc->set_start_time = true; 270 269 270 + irq_set_status_flags(rtc->irq, IRQ_NOAUTOEN); 271 + 271 272 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 272 273 tps6586x_rtc_irq, 273 274 IRQF_ONESHOT, ··· 279 276 rtc->irq, ret); 280 277 goto fail_rtc_register; 281 278 } 282 - disable_irq(rtc->irq); 283 279 284 280 ret = rtc_register_device(rtc->rtc); 285 281 if (ret)
+2 -2
drivers/rtc/rtc-zynqmp.c
··· 94 94 * RTC has updated the CURRENT_TIME with the time written into 95 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 98 } else { 99 99 /* 100 100 * Time written in SET_TIME_WRITE has not yet updated into ··· 104 104 * reading. 105 105 */ 106 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 110 return 0; 111 111 }
+1
include/linux/rtc.h
··· 167 167 #define RTC_TIMESTAMP_BEGIN_1900 -2208988800LL /* 1900-01-01 00:00:00 */ 168 168 #define RTC_TIMESTAMP_BEGIN_2000 946684800LL /* 2000-01-01 00:00:00 */ 169 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 171 #define RTC_TIMESTAMP_END_2099 4102444799LL /* 2099-12-31 23:59:59 */ 171 172 #define RTC_TIMESTAMP_END_2199 7258118399LL /* 2199-12-31 23:59:59 */ 172 173 #define RTC_TIMESTAMP_END_9999 253402300799LL /* 9999-12-31 23:59:59 */
+6 -1
include/uapi/linux/rtc.h
··· 92 92 #define RTC_PLL_GET _IOR('p', 0x11, struct rtc_pll_info) /* Get PLL correction */ 93 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 101 #define RTC_VL_CLR _IO('p', 0x14) /* Clear voltage low information */ 97 102 98 103 /* interrupt flags */