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 ...
Unified · Split
| @@ -18,6 +18,7 @@ Aleksey Gorelov <aleksey_gorelov@phoenix.com> · 17 unmodified lines | ||
| 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> |
| @@ -33,6 +33,14 @@ Description: · 32 unmodified lines | ||
| 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 |
| @@ -1,17 +0,0 @@ | ||
| 1 | −Atmel AT91RM9200 Real Time Clock | |
| 2 | − | |
| 3 | −Required properties: | |
| 4 | −- compatible: should be: "atmel,at91rm9200-rtc" or "atmel,at91sam9x5-rtc" | |
| 5 | −- reg: physical base address of the controller and length of memory mapped | |
| 6 | − region. | |
| 7 | −- interrupts: rtc alarm/event interrupt | |
| 8 | −- clocks: phandle to input clock. | |
| 9 | − | |
| 10 | −Example: | |
| 11 | − | |
| 12 | −rtc@fffffe00 { | |
| 13 | − compatible = "atmel,at91rm9200-rtc"; | |
| 14 | − reg = <0xfffffe00 0x100>; | |
| 15 | − interrupts = <1 4 7>; | |
| 16 | − clocks = <&clk32k>; | |
| 17 | −}; | |
| @@ -0,0 +1,49 @@ | ||
| 1 | +# SPDX-License-Identifier: GPL-2.0 | |
| 2 | +%YAML 1.2 | |
| 3 | +--- | |
| 4 | +$id: http://devicetree.org/schemas/rtc/atmel,at91rm9200-rtc.yaml# | |
| 5 | +$schema: http://devicetree.org/meta-schemas/core.yaml# | |
| 6 | + | |
| 7 | +title: Atmel AT91 RTC Device Tree Bindings | |
| 8 | + | |
| 9 | +allOf: | |
| 10 | + - $ref: "rtc.yaml#" | |
| 11 | + | |
| 12 | +maintainers: | |
| 13 | + - Alexandre Belloni <alexandre.belloni@bootlin.com> | |
| 14 | + | |
| 15 | +properties: | |
| 16 | + compatible: | |
| 17 | + enum: | |
| 18 | + - atmel,at91rm9200-rtc | |
| 19 | + - atmel,at91sam9x5-rtc | |
| 20 | + - atmel,sama5d4-rtc | |
| 21 | + - atmel,sama5d2-rtc | |
| 22 | + - microchip,sam9x60-rtc | |
| 23 | + | |
| 24 | + reg: | |
| 25 | + maxItems: 1 | |
| 26 | + | |
| 27 | + interrupts: | |
| 28 | + maxItems: 1 | |
| 29 | + | |
| 30 | + clocks: | |
| 31 | + maxItems: 1 | |
| 32 | + | |
| 33 | +required: | |
| 34 | + - compatible | |
| 35 | + - reg | |
| 36 | + - interrupts | |
| 37 | + - clocks | |
| 38 | + | |
| 39 | +additionalProperties: false | |
| 40 | + | |
| 41 | +examples: | |
| 42 | + - | | |
| 43 | + rtc@fffffe00 { | |
| 44 | + compatible = "atmel,at91rm9200-rtc"; | |
| 45 | + reg = <0xfffffe00 0x100>; | |
| 46 | + interrupts = <1 4 7>; | |
| 47 | + clocks = <&clk32k>; | |
| 48 | + }; | |
| 49 | +... | |
| @@ -240,6 +240,7 @@ config RTC_DRV_AS3722 · 239 unmodified lines | ||
| 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 |
| @@ -622,6 +623,7 @@ config RTC_DRV_RX8010 · 376 unmodified lines | ||
| 622 | 623 | |
| 623 | 624 | config RTC_DRV_RX8581 |
| 624 | 625 | tristate "Epson RX-8571/RX-8581" |
| 626 | + select REGMAP_I2C | |
| 625 | 627 | help |
| 626 | 628 | If you say yes here you will get support for the Epson RX-8571/ |
| 627 | 629 | RX-8581. |
| @@ -649,6 +651,7 @@ config RTC_DRV_EM3027 · 21 unmodified lines | ||
| 649 | 651 | |
| 650 | 652 | config RTC_DRV_RV3028 |
| 651 | 653 | tristate "Micro Crystal RV3028" |
| 654 | + select REGMAP_I2C | |
| 652 | 655 | help |
| 653 | 656 | If you say yes here you get support for the Micro Crystal |
| 654 | 657 | RV3028. |
| @@ -677,13 +680,14 @@ config RTC_DRV_S5M · 22 unmodified lines | ||
| 677 | 680 | will be called rtc-s5m. |
| 678 | 681 | |
| 679 | 682 | config RTC_DRV_SD3078 |
| 680 | − tristate "ZXW Shenzhen whwave SD3078" | |
| 681 | − help | |
| 682 | − If you say yes here you get support for the ZXW Shenzhen whwave | |
| 683 | − SD3078 RTC chips. | |
| 683 | + tristate "ZXW Shenzhen whwave SD3078" | |
| 684 | + select REGMAP_I2C | |
| 685 | + help | |
| 686 | + If you say yes here you get support for the ZXW Shenzhen whwave | |
| 687 | + SD3078 RTC chips. | |
| 684 | 688 | |
| 685 | − This driver can also be built as a module. If so, the module | |
| 686 | − will be called rtc-sd3078 | |
| 689 | + This driver can also be built as a module. If so, the module | |
| 690 | + will be called rtc-sd3078 | |
| 687 | 691 | |
| 688 | 692 | endif # I2C |
| 689 | 693 | |
| @@ -849,14 +853,14 @@ config RTC_I2C_AND_SPI · 159 unmodified lines | ||
| 849 | 853 | default m if I2C=m |
| 850 | 854 | default y if I2C=y |
| 851 | 855 | default y if SPI_MASTER=y |
| 852 | − select REGMAP_I2C if I2C | |
| 853 | − select REGMAP_SPI if SPI_MASTER | |
| 854 | 856 | |
| 855 | 857 | comment "SPI and I2C RTC drivers" |
| 856 | 858 | |
| 857 | 859 | config RTC_DRV_DS3232 |
| 858 | 860 | tristate "Dallas/Maxim DS3232/DS3234" |
| 859 | 861 | depends on RTC_I2C_AND_SPI |
| 862 | + select REGMAP_I2C if I2C | |
| 863 | + select REGMAP_SPI if SPI_MASTER | |
| 860 | 864 | help |
| 861 | 865 | If you say yes here you get support for Dallas Semiconductor |
| 862 | 866 | DS3232 and DS3234 real-time clock chips. If an interrupt is associated |
| @@ -876,6 +880,8 @@ config RTC_DRV_DS3232_HWMON · 13 unmodified lines | ||
| 876 | 880 | config RTC_DRV_PCF2127 |
| 877 | 881 | tristate "NXP PCF2127" |
| 878 | 882 | depends on RTC_I2C_AND_SPI |
| 883 | + select REGMAP_I2C if I2C | |
| 884 | + select REGMAP_SPI if SPI_MASTER | |
| 879 | 885 | select WATCHDOG_CORE if WATCHDOG |
| 880 | 886 | help |
| 881 | 887 | 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 | ||
| 892 | 898 | config RTC_DRV_RV3029C2 |
| 893 | 899 | tristate "Micro Crystal RV3029/3049" |
| 894 | 900 | depends on RTC_I2C_AND_SPI |
| 901 | + select REGMAP_I2C if I2C | |
| 902 | + select REGMAP_SPI if SPI_MASTER | |
| 895 | 903 | help |
| 896 | 904 | If you say yes here you get support for the Micro Crystal |
| 897 | 905 | RV3029 and RV3049 RTC chips. |
| @@ -523,12 +523,9 @@ static int abx80x_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 522 unmodified lines | ||
| 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); |
| @@ -264,6 +264,9 @@ static int asm9260_rtc_probe(struct platform_device *pdev) · 263 unmodified lines | ||
| 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"); |
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 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> |
| @@ -30,7 +31,51 @@ · 10 unmodified lines | ||
| 30 | 31 | #include <linux/time.h> |
| 31 | 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 | 80 | #define at91_rtc_read(field) \ |
| 36 | 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 | 162 | } while ((time != at91_rtc_read(timereg)) || |
| 118 | 163 | (date != at91_rtc_read(calreg))); |
| 119 | 164 | |
| 120 | − tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0); | |
| 121 | − tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8); | |
| 122 | − tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16); | |
| 165 | + tm->tm_sec = bcd2bin(FIELD_GET(AT91_RTC_SEC, time)); | |
| 166 | + tm->tm_min = bcd2bin(FIELD_GET(AT91_RTC_MIN, time)); | |
| 167 | + tm->tm_hour = bcd2bin(FIELD_GET(AT91_RTC_HOUR, time)); | |
| 123 | 168 | |
| 124 | 169 | /* |
| 125 | 170 | * The Calendar Alarm register does not have a field for |
| 126 | 171 | * the year - so these will return an invalid value. |
| 127 | 172 | */ |
| 128 | 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 */ | |
| 132 | − tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1; | |
| 133 | − tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24); | |
| 176 | + tm->tm_wday = bcd2bin(FIELD_GET(AT91_RTC_DAY, date)) - 1; /* day of the week [0-6], Sunday=0 */ | |
| 177 | + tm->tm_mon = bcd2bin(FIELD_GET(AT91_RTC_MONTH, date)) - 1; | |
| 178 | + tm->tm_mday = bcd2bin(FIELD_GET(AT91_RTC_DATE, date)); | |
| 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 | 212 | at91_rtc_write_idr(AT91_RTC_ACKUPD); |
| 168 | 213 | |
| 169 | 214 | at91_rtc_write(AT91_RTC_TIMR, |
| 170 | − bin2bcd(tm->tm_sec) << 0 | |
| 171 | − | bin2bcd(tm->tm_min) << 8 | |
| 172 | − | bin2bcd(tm->tm_hour) << 16); | |
| 215 | + FIELD_PREP(AT91_RTC_SEC, bin2bcd(tm->tm_sec)) | |
| 216 | + | FIELD_PREP(AT91_RTC_MIN, bin2bcd(tm->tm_min)) | |
| 217 | + | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(tm->tm_hour))); | |
| 173 | 218 | |
| 174 | 219 | at91_rtc_write(AT91_RTC_CALR, |
| 175 | − bin2bcd((tm->tm_year + 1900) / 100) /* century */ | |
| 176 | − | bin2bcd(tm->tm_year % 100) << 8 /* year */ | |
| 177 | − | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */ | |
| 178 | − | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */ | |
| 179 | − | bin2bcd(tm->tm_mday) << 24); | |
| 220 | + FIELD_PREP(AT91_RTC_CENT, | |
| 221 | + bin2bcd((tm->tm_year + 1900) / 100)) | |
| 222 | + | FIELD_PREP(AT91_RTC_YEAR, bin2bcd(tm->tm_year % 100)) | |
| 223 | + | FIELD_PREP(AT91_RTC_MONTH, bin2bcd(tm->tm_mon + 1)) | |
| 224 | + | FIELD_PREP(AT91_RTC_DAY, bin2bcd(tm->tm_wday + 1)) | |
| 225 | + | FIELD_PREP(AT91_RTC_DATE, bin2bcd(tm->tm_mday))); | |
| 180 | 226 | |
| 181 | 227 | /* Restart Time/Calendar */ |
| 182 | 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 | */ |
| 212 | 258 | static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) |
| 213 | 259 | { |
| 214 | − struct rtc_time tm; | |
| 215 | − | |
| 216 | − at91_rtc_decodetime(AT91_RTC_TIMR, AT91_RTC_CALR, &tm); | |
| 217 | − | |
| 218 | − tm.tm_mon = alrm->time.tm_mon; | |
| 219 | − tm.tm_mday = alrm->time.tm_mday; | |
| 220 | − tm.tm_hour = alrm->time.tm_hour; | |
| 221 | − tm.tm_min = alrm->time.tm_min; | |
| 222 | − tm.tm_sec = alrm->time.tm_sec; | |
| 260 | + struct rtc_time tm = alrm->time; | |
| 223 | 261 | |
| 224 | 262 | at91_rtc_write_idr(AT91_RTC_ALARM); |
| 225 | 263 | at91_rtc_write(AT91_RTC_TIMALR, |
| 226 | − bin2bcd(tm.tm_sec) << 0 | |
| 227 | − | bin2bcd(tm.tm_min) << 8 | |
| 228 | − | bin2bcd(tm.tm_hour) << 16 | |
| 264 | + FIELD_PREP(AT91_RTC_SEC, bin2bcd(alrm->time.tm_sec)) | |
| 265 | + | FIELD_PREP(AT91_RTC_MIN, bin2bcd(alrm->time.tm_min)) | |
| 266 | + | FIELD_PREP(AT91_RTC_HOUR, bin2bcd(alrm->time.tm_hour)) | |
| 229 | 267 | | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN); |
| 230 | 268 | at91_rtc_write(AT91_RTC_CALALR, |
| 231 | − bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */ | |
| 232 | − | bin2bcd(tm.tm_mday) << 24 | |
| 269 | + FIELD_PREP(AT91_RTC_MONTH, bin2bcd(alrm->time.tm_mon + 1)) | |
| 270 | + | FIELD_PREP(AT91_RTC_DATE, bin2bcd(alrm->time.tm_mday)) | |
| 233 | 271 | | AT91_RTC_DATEEN | AT91_RTC_MTHEN); |
| 234 | 272 | |
| 235 | 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 | 293 | return 0; |
| 256 | 294 | } |
| 257 | −/* | |
| 258 | − * Provide additional RTC information in /proc/driver/rtc | |
| 259 | − */ | |
| 260 | −static int at91_rtc_proc(struct device *dev, struct seq_file *seq) | |
| 261 | −{ | |
| 262 | − unsigned long imr = at91_rtc_read_imr(); | |
| 263 | − | |
| 264 | − seq_printf(seq, "update_IRQ\t: %s\n", | |
| 265 | − (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); | |
| 266 | − seq_printf(seq, "periodic_IRQ\t: %s\n", | |
| 267 | − (imr & AT91_RTC_SECEV) ? "yes" : "no"); | |
| 268 | − | |
| 269 | − return 0; | |
| 270 | −} | |
| 271 | 295 | |
| 272 | 296 | /* |
| 273 | 297 | * 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 | 351 | .compatible = "atmel,at91sam9x5-rtc", |
| 328 | 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 | 360 | /* sentinel */ |
| 331 | 361 | } |
| @@ -337,7 +367,6 @@ static const struct rtc_class_ops at91_rtc_ops = { · 5 unmodified lines | ||
| 337 | 367 | .set_time = at91_rtc_settime, |
| 338 | 368 | .read_alarm = at91_rtc_readalarm, |
| 339 | 369 | .set_alarm = at91_rtc_setalarm, |
| 340 | − .proc = at91_rtc_proc, | |
| 341 | 370 | .alarm_irq_enable = at91_rtc_alarm_irq_enable, |
| 342 | 371 | }; |
| 343 | 372 | |
| @@ -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 | |
| @@ -850,7 +850,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) · 849 unmodified lines | ||
| 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,8 +1197,6 @@ static void rtc_wake_off(struct device *dev) · 340 unmodified lines | ||
| 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 | |
| @@ -1208,8 +1206,10 @@ static void use_acpi_alarm_quirks(void) · 3 unmodified lines | ||
| 1208 | 1206 | if (!is_hpet_enabled()) |
| 1209 | 1207 | return; |
| 1210 | 1208 | |
| 1211 | − if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2015) | |
| 1212 | − use_acpi_alarm = true; | |
| 1209 | + if (dmi_get_bios_year() < 2015) | |
| 1210 | + return; | |
| 1211 | + | |
| 1212 | + use_acpi_alarm = true; | |
| 1213 | 1213 | } |
| 1214 | 1214 | #else |
| 1215 | 1215 | static inline void use_acpi_alarm_quirks(void) { } |
| @@ -1305,7 +1305,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) · 89 unmodified lines | ||
| 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); |
| @@ -75,7 +75,6 @@ static const struct spi_device_id ds1343_id[] = { · 74 unmodified lines | ||
| 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; |
| @@ -362,12 +361,13 @@ static int ds1343_probe(struct spi_device *spi) · 280 unmodified lines | ||
| 362 | 361 | if (!priv) |
| 363 | 362 | return -ENOMEM; |
| 364 | 363 | |
| 365 | − priv->spi = spi; | |
| 366 | − | |
| 367 | 364 | /* RTC DS1347 works in spi mode 3 and |
| 368 | − * its chip select is active high | |
| 365 | + * its chip select is active high. Active high should be defined as | |
| 366 | + * "inverse polarity" as GPIO-based chip selects can be logically | |
| 367 | + * active high but inverted by the GPIO library. | |
| 369 | 368 | */ |
| 370 | − spi->mode = SPI_MODE_3 | SPI_CS_HIGH; | |
| 369 | + spi->mode |= SPI_MODE_3; | |
| 370 | + spi->mode ^= SPI_CS_HIGH; | |
| 371 | 371 | spi->bits_per_word = 8; |
| 372 | 372 | res = spi_setup(spi); |
| 373 | 373 | if (res) |
| @@ -78,7 +78,6 @@ · 77 unmodified lines | ||
| 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 |
| @@ -91,19 +90,19 @@ struct hym8563 { · 6 unmodified lines | ||
| 91 | 90 | static int hym8563_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 92 | 91 | { |
| 93 | 92 | struct i2c_client *client = to_i2c_client(dev); |
| 94 | − struct hym8563 *hym8563 = i2c_get_clientdata(client); | |
| 95 | 93 | u8 buf[7]; |
| 96 | 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 | 96 | ret = i2c_smbus_read_i2c_block_data(client, HYM8563_SEC, 7, buf); |
| 104 | 97 | if (ret < 0) |
| 105 | 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 | 106 | tm->tm_sec = bcd2bin(buf[0] & HYM8563_SEC_MASK); |
| 108 | 107 | tm->tm_min = bcd2bin(buf[1] & HYM8563_MIN_MASK); |
| 109 | 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 | ||
| 118 | 117 | static int hym8563_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 119 | 118 | { |
| 120 | 119 | struct i2c_client *client = to_i2c_client(dev); |
| 121 | − struct hym8563 *hym8563 = i2c_get_clientdata(client); | |
| 122 | 120 | u8 buf[7]; |
| 123 | 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 | 155 | if (ret < 0) |
| 158 | 156 | return ret; |
| 159 | 157 | |
| 160 | − hym8563->valid = true; | |
| 161 | − | |
| 162 | 158 | return 0; |
| 163 | 159 | } |
| 164 | 160 | |
| @@ -556,9 +552,8 @@ static int hym8563_probe(struct i2c_client *client, · 391 unmodified lines | ||
| 556 | 552 | if (ret < 0) |
| 557 | 553 | return ret; |
| 558 | 554 | |
| 559 | − hym8563->valid = !(ret & HYM8563_SEC_VL); | |
| 560 | 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 | 558 | hym8563->rtc = devm_rtc_device_register(&client->dev, client->name, |
| 564 | 559 | &hym8563_rtc_ops, THIS_MODULE); |
| @@ -1,3 +1,4 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 1 | 2 | /* |
| 2 | 3 | * MOXA ART RTC driver. |
| 3 | 4 | * |
| @@ -7,10 +8,6 @@ · 3 unmodified lines | ||
| 7 | 8 | * |
| 8 | 9 | * Based on code from |
| 9 | 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 | 13 | #include <linux/init.h> |
| @@ -297,15 +297,7 @@ static int mtk_rtc_probe(struct platform_device *pdev) · 296 unmodified lines | ||
| 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 |
| @@ -616,7 +616,7 @@ static int rtc_pinconf_get(struct pinctrl_dev *pctldev, · 615 unmodified lines | ||
| 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 | |
| @@ -199,11 +199,9 @@ static int pcf2127_rtc_ioctl(struct device *dev, · 198 unmodified lines | ||
| 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 | } |
| @@ -289,21 +289,9 @@ static int pcf85063_ioctl(struct device *dev, unsigned int cmd, · 288 unmodified lines | ||
| 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; |
| @@ -282,11 +282,11 @@ static int pcf8523_rtc_ioctl(struct device *dev, unsigned int cmd, · 281 unmodified lines | ||
| 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 | } |
| @@ -22,8 +22,8 @@ · 21 unmodified lines | ||
| 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,7 +76,6 @@ struct pcf8563 { · 46 unmodified lines | ||
| 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 |
| @@ -208,7 +207,6 @@ static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) · 125 unmodified lines | ||
| 208 | 207 | return err; |
| 209 | 208 | |
| 210 | 209 | if (buf[PCF8563_REG_SC] & PCF8563_SC_LV) { |
| 211 | − pcf8563->voltage_low = 1; | |
| 212 | 210 | dev_err(&client->dev, |
| 213 | 211 | "low voltage detected, date/time is not reliable.\n"); |
| 214 | 212 | return -EINVAL; |
| @@ -276,43 +274,23 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm) · 61 unmodified lines | ||
| 276 | 274 | 9 - PCF8563_REG_SC, buf + PCF8563_REG_SC); |
| 277 | 275 | } |
| 278 | 276 | |
| 279 | −#ifdef CONFIG_RTC_INTF_DEV | |
| 280 | 277 | static 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)); | |
| 283 | − struct rtc_time tm; | |
| 279 | + struct i2c_client *client = to_i2c_client(dev); | |
| 280 | + int ret; | |
| 284 | 281 | |
| 285 | 282 | switch (cmd) { |
| 286 | 283 | case RTC_VL_READ: |
| 287 | − if (pcf8563->voltage_low) | |
| 288 | − dev_info(dev, "low voltage detected, date/time is not reliable.\n"); | |
| 289 | − | |
| 290 | − if (copy_to_user((void __user *)arg, &pcf8563->voltage_low, | |
| 291 | − sizeof(int))) | |
| 292 | − return -EFAULT; | |
| 293 | − return 0; | |
| 294 | − case RTC_VL_CLR: | |
| 295 | − /* | |
| 296 | − * Clear the VL bit in the seconds register in case | |
| 297 | − * the time has not been set already (which would | |
| 298 | − * have cleared it). This does not really matter | |
| 299 | − * because of the cached voltage_low value but do it | |
| 300 | − * anyway for consistency. | |
| 301 | − */ | |
| 302 | − if (pcf8563_rtc_read_time(dev, &tm)) | |
| 303 | − pcf8563_rtc_set_time(dev, &tm); | |
| 304 | − | |
| 305 | − /* Clear the cached value. */ | |
| 306 | − pcf8563->voltage_low = 0; | |
| 284 | + ret = i2c_smbus_read_byte_data(client, PCF8563_REG_SC); | |
| 285 | + if (ret < 0) | |
| 286 | + return ret; | |
| 307 | 287 | |
| 308 | − return 0; | |
| 288 | + return put_user(ret & PCF8563_SC_LV ? RTC_VL_DATA_INVALID : 0, | |
| 289 | + (unsigned int __user *)arg); | |
| 309 | 290 | default: |
| 310 | 291 | return -ENOIOCTLCMD; |
| 311 | 292 | } |
| 312 | 293 | } |
| 313 | −#else | |
| 314 | −#define pcf8563_rtc_ioctl NULL | |
| 315 | −#endif | |
| 316 | 294 | |
| 317 | 295 | static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm) |
| 318 | 296 | { |
| @@ -428,21 +428,8 @@ static int rv3028_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 427 unmodified lines | ||
| 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; |
| @@ -109,10 +109,8 @@ · 108 unmodified lines | ||
| 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; |
| @@ -121,77 +119,13 @@ struct rv3029_data { · 2 unmodified lines | ||
| 121 | 119 | int irq; |
| 122 | 120 | }; |
| 123 | 121 | |
| 124 | −static int rv3029_read_regs(struct device *dev, u8 reg, u8 *buf, | |
| 125 | − unsigned int len) | |
| 126 | −{ | |
| 127 | − struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 128 | − | |
| 129 | − if ((reg > RV3029_USR1_RAM_PAGE + 7) || | |
| 130 | − (reg + len > RV3029_USR1_RAM_PAGE + 8)) | |
| 131 | − return -EINVAL; | |
| 132 | − | |
| 133 | − return regmap_bulk_read(rv3029->regmap, reg, buf, len); | |
| 134 | −} | |
| 135 | − | |
| 136 | −static int rv3029_write_regs(struct device *dev, u8 reg, u8 const buf[], | |
| 137 | − unsigned int len) | |
| 138 | −{ | |
| 139 | − struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 140 | − | |
| 141 | − if ((reg > RV3029_USR1_RAM_PAGE + 7) || | |
| 142 | − (reg + len > RV3029_USR1_RAM_PAGE + 8)) | |
| 143 | − return -EINVAL; | |
| 144 | − | |
| 145 | − return regmap_bulk_write(rv3029->regmap, reg, buf, len); | |
| 146 | −} | |
| 147 | − | |
| 148 | −static int rv3029_update_bits(struct device *dev, u8 reg, u8 mask, u8 set) | |
| 149 | −{ | |
| 150 | − u8 buf; | |
| 151 | − int ret; | |
| 152 | − | |
| 153 | − ret = rv3029_read_regs(dev, reg, &buf, 1); | |
| 154 | − if (ret < 0) | |
| 155 | − return ret; | |
| 156 | − buf &= ~mask; | |
| 157 | − buf |= set & mask; | |
| 158 | − ret = rv3029_write_regs(dev, reg, &buf, 1); | |
| 159 | − if (ret < 0) | |
| 160 | − return ret; | |
| 161 | − | |
| 162 | − return 0; | |
| 163 | −} | |
| 164 | − | |
| 165 | −static int rv3029_get_sr(struct device *dev, u8 *buf) | |
| 166 | −{ | |
| 167 | − int ret = rv3029_read_regs(dev, RV3029_STATUS, buf, 1); | |
| 168 | − | |
| 169 | − if (ret < 0) | |
| 170 | − return -EIO; | |
| 171 | − dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); | |
| 172 | − return 0; | |
| 173 | −} | |
| 174 | − | |
| 175 | −static int rv3029_set_sr(struct device *dev, u8 val) | |
| 176 | −{ | |
| 177 | − u8 buf[1]; | |
| 178 | − int sr; | |
| 179 | − | |
| 180 | − buf[0] = val; | |
| 181 | − sr = rv3029_write_regs(dev, RV3029_STATUS, buf, 1); | |
| 182 | − dev_dbg(dev, "status = 0x%.2x (%d)\n", buf[0], buf[0]); | |
| 183 | − if (sr < 0) | |
| 184 | − return -EIO; | |
| 185 | − return 0; | |
| 186 | −} | |
| 187 | − | |
| 188 | −static int rv3029_eeprom_busywait(struct device *dev) | |
| 122 | +static int rv3029_eeprom_busywait(struct rv3029_data *rv3029) | |
| 189 | 123 | { |
| 124 | + unsigned int sr; | |
| 190 | 125 | int i, ret; |
| 191 | − u8 sr; | |
| 192 | 126 | |
| 193 | 127 | for (i = 100; i > 0; i--) { |
| 194 | − ret = rv3029_get_sr(dev, &sr); | |
| 128 | + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); | |
| 195 | 129 | if (ret < 0) |
| 196 | 130 | break; |
| 197 | 131 | if (!(sr & RV3029_STATUS_EEBUSY)) |
| @@ -199,126 +133,128 @@ static int rv3029_eeprom_busywait(struct device *dev) · 1 unmodified line | ||
| 199 | 133 | usleep_range(1000, 10000); |
| 200 | 134 | } |
| 201 | 135 | if (i <= 0) { |
| 202 | − dev_err(dev, "EEPROM busy wait timeout.\n"); | |
| 136 | + dev_err(rv3029->dev, "EEPROM busy wait timeout.\n"); | |
| 203 | 137 | return -ETIMEDOUT; |
| 204 | 138 | } |
| 205 | 139 | |
| 206 | 140 | return ret; |
| 207 | 141 | } |
| 208 | 142 | |
| 209 | −static int rv3029_eeprom_exit(struct device *dev) | |
| 143 | +static int rv3029_eeprom_exit(struct rv3029_data *rv3029) | |
| 210 | 144 | { |
| 211 | 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 | 147 | RV3029_ONOFF_CTRL_EERE, |
| 214 | 148 | RV3029_ONOFF_CTRL_EERE); |
| 215 | 149 | } |
| 216 | 150 | |
| 217 | −static int rv3029_eeprom_enter(struct device *dev) | |
| 151 | +static int rv3029_eeprom_enter(struct rv3029_data *rv3029) | |
| 218 | 152 | { |
| 153 | + unsigned int sr; | |
| 219 | 154 | int ret; |
| 220 | − u8 sr; | |
| 221 | 155 | |
| 222 | 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 | 158 | if (ret < 0) |
| 225 | 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 | 163 | /* We clear the bits and retry once just in case |
| 228 | 164 | * we had a brown out in early startup. |
| 229 | 165 | */ |
| 230 | − sr &= ~RV3029_STATUS_VLOW1; | |
| 231 | − sr &= ~RV3029_STATUS_VLOW2; | |
| 232 | − ret = rv3029_set_sr(dev, sr); | |
| 166 | + ret = regmap_update_bits(rv3029->regmap, RV3029_STATUS, | |
| 167 | + RV3029_STATUS_VLOW1, 0); | |
| 233 | 168 | if (ret < 0) |
| 234 | 169 | return ret; |
| 235 | 170 | usleep_range(1000, 10000); |
| 236 | − ret = rv3029_get_sr(dev, &sr); | |
| 171 | + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); | |
| 237 | 172 | if (ret < 0) |
| 238 | 173 | return ret; |
| 239 | − if (sr & (RV3029_STATUS_VLOW1 | RV3029_STATUS_VLOW2)) { | |
| 240 | − dev_err(dev, | |
| 174 | + if (sr & RV3029_STATUS_VLOW1) { | |
| 175 | + dev_err(rv3029->dev, | |
| 241 | 176 | "Supply voltage is too low to safely access the EEPROM.\n"); |
| 242 | 177 | return -ENODEV; |
| 243 | 178 | } |
| 244 | 179 | } |
| 245 | 180 | |
| 246 | 181 | /* Disable eeprom refresh. */ |
| 247 | − ret = rv3029_update_bits(dev, RV3029_ONOFF_CTRL, RV3029_ONOFF_CTRL_EERE, | |
| 248 | − 0); | |
| 182 | + ret = regmap_update_bits(rv3029->regmap, RV3029_ONOFF_CTRL, | |
| 183 | + RV3029_ONOFF_CTRL_EERE, 0); | |
| 249 | 184 | if (ret < 0) |
| 250 | 185 | return ret; |
| 251 | 186 | |
| 252 | 187 | /* Wait for any previous eeprom accesses to finish. */ |
| 253 | − ret = rv3029_eeprom_busywait(dev); | |
| 188 | + ret = rv3029_eeprom_busywait(rv3029); | |
| 254 | 189 | if (ret < 0) |
| 255 | − rv3029_eeprom_exit(dev); | |
| 190 | + rv3029_eeprom_exit(rv3029); | |
| 256 | 191 | |
| 257 | 192 | return ret; |
| 258 | 193 | } |
| 259 | 194 | |
| 260 | −static int rv3029_eeprom_read(struct device *dev, u8 reg, | |
| 195 | +static int rv3029_eeprom_read(struct rv3029_data *rv3029, u8 reg, | |
| 261 | 196 | u8 buf[], size_t len) |
| 262 | 197 | { |
| 263 | 198 | int ret, err; |
| 264 | 199 | |
| 265 | − err = rv3029_eeprom_enter(dev); | |
| 200 | + err = rv3029_eeprom_enter(rv3029); | |
| 266 | 201 | if (err < 0) |
| 267 | 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 | 207 | if (err < 0) |
| 273 | 208 | return err; |
| 274 | 209 | |
| 275 | 210 | return ret; |
| 276 | 211 | } |
| 277 | 212 | |
| 278 | −static int rv3029_eeprom_write(struct device *dev, u8 reg, | |
| 213 | +static int rv3029_eeprom_write(struct rv3029_data *rv3029, u8 reg, | |
| 279 | 214 | u8 const buf[], size_t len) |
| 280 | 215 | { |
| 216 | + unsigned int tmp; | |
| 281 | 217 | int ret, err; |
| 282 | 218 | size_t i; |
| 283 | − u8 tmp; | |
| 284 | 219 | |
| 285 | − err = rv3029_eeprom_enter(dev); | |
| 220 | + err = rv3029_eeprom_enter(rv3029); | |
| 286 | 221 | if (err < 0) |
| 287 | 222 | return err; |
| 288 | 223 | |
| 289 | 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 | 226 | if (ret < 0) |
| 292 | 227 | break; |
| 293 | 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 | 231 | if (ret < 0) |
| 296 | 232 | break; |
| 297 | 233 | } |
| 298 | − ret = rv3029_eeprom_busywait(dev); | |
| 234 | + ret = rv3029_eeprom_busywait(rv3029); | |
| 299 | 235 | if (ret < 0) |
| 300 | 236 | break; |
| 301 | 237 | } |
| 302 | 238 | |
| 303 | − err = rv3029_eeprom_exit(dev); | |
| 239 | + err = rv3029_eeprom_exit(rv3029); | |
| 304 | 240 | if (err < 0) |
| 305 | 241 | return err; |
| 306 | 242 | |
| 307 | 243 | return ret; |
| 308 | 244 | } |
| 309 | 245 | |
| 310 | −static int rv3029_eeprom_update_bits(struct device *dev, | |
| 246 | +static int rv3029_eeprom_update_bits(struct rv3029_data *rv3029, | |
| 311 | 247 | u8 reg, u8 mask, u8 set) |
| 312 | 248 | { |
| 313 | 249 | u8 buf; |
| 314 | 250 | int ret; |
| 315 | 251 | |
| 316 | − ret = rv3029_eeprom_read(dev, reg, &buf, 1); | |
| 252 | + ret = rv3029_eeprom_read(rv3029, reg, &buf, 1); | |
| 317 | 253 | if (ret < 0) |
| 318 | 254 | return ret; |
| 319 | 255 | buf &= ~mask; |
| 320 | 256 | buf |= set & mask; |
| 321 | − ret = rv3029_eeprom_write(dev, reg, &buf, 1); | |
| 257 | + ret = rv3029_eeprom_write(rv3029, reg, &buf, 1); | |
| 322 | 258 | if (ret < 0) |
| 323 | 259 | return ret; |
| 324 | 260 | |
| @@ -330,20 +266,20 @@ static irqreturn_t rv3029_handle_irq(int irq, void *dev_id) · 5 unmodified lines | ||
| 330 | 266 | struct device *dev = dev_id; |
| 331 | 267 | struct rv3029_data *rv3029 = dev_get_drvdata(dev); |
| 332 | 268 | struct mutex *lock = &rv3029->rtc->ops_lock; |
| 269 | + unsigned int flags, controls; | |
| 333 | 270 | unsigned long events = 0; |
| 334 | − u8 flags, controls; | |
| 335 | 271 | int ret; |
| 336 | 272 | |
| 337 | 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 | 276 | if (ret) { |
| 341 | 277 | dev_warn(dev, "Read IRQ Control Register error %d\n", ret); |
| 342 | 278 | mutex_unlock(lock); |
| 343 | 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 | 283 | if (ret) { |
| 348 | 284 | dev_warn(dev, "Read IRQ Flags Register error %d\n", ret); |
| 349 | 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 | 295 | if (events) { |
| 360 | 296 | rtc_update_irq(rv3029->rtc, 1, events); |
| 361 | − rv3029_write_regs(dev, RV3029_IRQ_FLAGS, &flags, 1); | |
| 362 | − rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1); | |
| 297 | + regmap_write(rv3029->regmap, RV3029_IRQ_FLAGS, flags); | |
| 298 | + regmap_write(rv3029->regmap, RV3029_IRQ_CTRL, controls); | |
| 363 | 299 | } |
| 364 | 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 | |
| 369 | 305 | static 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 | 309 | int ret; |
| 373 | 310 | u8 regs[RV3029_WATCH_SECTION_LEN] = { 0, }; |
| 374 | 311 | |
| 375 | − ret = rv3029_get_sr(dev, buf); | |
| 376 | − if (ret < 0) { | |
| 377 | − dev_err(dev, "%s: reading SR failed\n", __func__); | |
| 378 | − return -EIO; | |
| 379 | − } | |
| 312 | + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); | |
| 313 | + if (ret < 0) | |
| 314 | + return ret; | |
| 315 | + | |
| 316 | + if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON)) | |
| 317 | + return -EINVAL; | |
| 380 | 318 | |
| 381 | − ret = rv3029_read_regs(dev, RV3029_W_SEC, regs, | |
| 319 | + ret = regmap_bulk_read(rv3029->regmap, RV3029_W_SEC, regs, | |
| 382 | 320 | RV3029_WATCH_SECTION_LEN); |
| 383 | − if (ret < 0) { | |
| 384 | − dev_err(dev, "%s: reading RTC section failed\n", __func__); | |
| 321 | + if (ret < 0) | |
| 385 | 322 | return ret; |
| 386 | − } | |
| 387 | 323 | |
| 388 | 324 | tm->tm_sec = bcd2bin(regs[RV3029_W_SEC - RV3029_W_SEC]); |
| 389 | 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 | |
| 412 | 348 | static int rv3029_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 413 | 349 | { |
| 350 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 414 | 351 | struct rtc_time *const tm = &alarm->time; |
| 352 | + unsigned int controls, flags; | |
| 415 | 353 | int ret; |
| 416 | − u8 regs[8], controls, flags; | |
| 417 | − | |
| 418 | − ret = rv3029_get_sr(dev, regs); | |
| 419 | − if (ret < 0) { | |
| 420 | − dev_err(dev, "%s: reading SR failed\n", __func__); | |
| 421 | − return -EIO; | |
| 422 | − } | |
| 354 | + u8 regs[8]; | |
| 423 | 355 | |
| 424 | − ret = rv3029_read_regs(dev, RV3029_A_SC, regs, | |
| 356 | + ret = regmap_bulk_read(rv3029->regmap, RV3029_A_SC, regs, | |
| 425 | 357 | RV3029_ALARM_SECTION_LEN); |
| 426 | − | |
| 427 | − if (ret < 0) { | |
| 428 | − dev_err(dev, "%s: reading alarm section failed\n", __func__); | |
| 358 | + if (ret < 0) | |
| 429 | 359 | return ret; |
| 430 | − } | |
| 431 | 360 | |
| 432 | − ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1); | |
| 433 | − if (ret) { | |
| 434 | − dev_err(dev, "Read IRQ Control Register error %d\n", ret); | |
| 361 | + ret = regmap_read(rv3029->regmap, RV3029_IRQ_CTRL, &controls); | |
| 362 | + if (ret) | |
| 435 | 363 | return ret; |
| 436 | − } | |
| 437 | − ret = rv3029_read_regs(dev, RV3029_IRQ_FLAGS, &flags, 1); | |
| 438 | − if (ret < 0) { | |
| 439 | − dev_err(dev, "Read IRQ Flags Register error %d\n", ret); | |
| 364 | + | |
| 365 | + ret = regmap_read(rv3029->regmap, RV3029_IRQ_FLAGS, &flags); | |
| 366 | + if (ret < 0) | |
| 440 | 367 | return ret; |
| 441 | − } | |
| 442 | 368 | |
| 443 | 369 | tm->tm_sec = bcd2bin(regs[RV3029_A_SC - RV3029_A_SC] & 0x7f); |
| 444 | 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 | |
| 457 | 383 | static int rv3029_alarm_irq_enable(struct device *dev, unsigned int enable) |
| 458 | 384 | { |
| 459 | − int ret; | |
| 460 | − u8 controls; | |
| 461 | − | |
| 462 | − ret = rv3029_read_regs(dev, RV3029_IRQ_CTRL, &controls, 1); | |
| 463 | − if (ret < 0) { | |
| 464 | − dev_warn(dev, "Read IRQ Control Register error %d\n", ret); | |
| 465 | − return ret; | |
| 466 | − } | |
| 467 | − | |
| 468 | − /* enable/disable AIE irq */ | |
| 469 | − if (enable) | |
| 470 | − controls |= RV3029_IRQ_CTRL_AIE; | |
| 471 | − else | |
| 472 | − controls &= ~RV3029_IRQ_CTRL_AIE; | |
| 473 | − | |
| 474 | − ret = rv3029_write_regs(dev, RV3029_IRQ_CTRL, &controls, 1); | |
| 475 | − if (ret < 0) { | |
| 476 | − dev_err(dev, "can't update INT reg\n"); | |
| 477 | − return ret; | |
| 478 | − } | |
| 385 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 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 | |
| 483 | 392 | static int rv3029_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) |
| 484 | 393 | { |
| 394 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 485 | 395 | struct rtc_time *const tm = &alarm->time; |
| 486 | 396 | int ret; |
| 487 | 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 | 399 | /* Activate all the alarms with AE_x bit */ |
| 504 | 400 | regs[RV3029_A_SC - RV3029_A_SC] = bin2bcd(tm->tm_sec) | RV3029_A_AE_X; |
| 505 | 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 | 411 | | RV3029_A_AE_X; |
| 516 | 412 | |
| 517 | 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 | 415 | RV3029_ALARM_SECTION_LEN); |
| 520 | 416 | if (ret < 0) |
| 521 | 417 | return ret; |
| 522 | 418 | |
| 523 | − if (alarm->enabled) { | |
| 524 | − /* enable AIE irq */ | |
| 525 | − ret = rv3029_alarm_irq_enable(dev, 1); | |
| 526 | − if (ret) | |
| 527 | − return ret; | |
| 528 | − } else { | |
| 529 | − /* disable AIE irq */ | |
| 530 | − ret = rv3029_alarm_irq_enable(dev, 0); | |
| 531 | − if (ret) | |
| 532 | − return ret; | |
| 533 | − } | |
| 534 | − | |
| 535 | − return 0; | |
| 419 | + return rv3029_alarm_irq_enable(dev, alarm->enabled); | |
| 536 | 420 | } |
| 537 | 421 | |
| 538 | 422 | static int rv3029_set_time(struct device *dev, struct rtc_time *tm) |
| 539 | 423 | { |
| 424 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 540 | 425 | u8 regs[8]; |
| 541 | 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 | 428 | regs[RV3029_W_SEC - RV3029_W_SEC] = bin2bcd(tm->tm_sec); |
| 552 | 429 | regs[RV3029_W_MINUTES - RV3029_W_SEC] = bin2bcd(tm->tm_min); |
| 553 | 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 | 433 | regs[RV3029_W_DAYS - RV3029_W_SEC] = bin2bcd(tm->tm_wday + 1) & 0x7; |
| 557 | 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 | 437 | RV3029_WATCH_SECTION_LEN); |
| 561 | 438 | if (ret < 0) |
| 562 | 439 | return ret; |
| 563 | 440 | |
| 564 | − ret = rv3029_get_sr(dev, regs); | |
| 565 | − if (ret < 0) { | |
| 566 | − dev_err(dev, "%s: reading SR failed\n", __func__); | |
| 567 | − return ret; | |
| 568 | − } | |
| 569 | − /* clear PON bit */ | |
| 570 | − ret = rv3029_set_sr(dev, (regs[0] & ~RV3029_STATUS_PON)); | |
| 571 | − if (ret < 0) { | |
| 572 | − dev_err(dev, "%s: reading SR failed\n", __func__); | |
| 573 | − return ret; | |
| 441 | + /* clear PON and VLOW2 bits */ | |
| 442 | + return regmap_update_bits(rv3029->regmap, RV3029_STATUS, | |
| 443 | + RV3029_STATUS_PON | RV3029_STATUS_VLOW2, 0); | |
| 444 | +} | |
| 445 | + | |
| 446 | +static int rv3029_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) | |
| 447 | +{ | |
| 448 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 449 | + unsigned long vl = 0; | |
| 450 | + int sr, ret = 0; | |
| 451 | + | |
| 452 | + switch (cmd) { | |
| 453 | + case RTC_VL_READ: | |
| 454 | + ret = regmap_read(rv3029->regmap, RV3029_STATUS, &sr); | |
| 455 | + if (ret < 0) | |
| 456 | + return ret; | |
| 457 | + | |
| 458 | + if (sr & RV3029_STATUS_VLOW1) | |
| 459 | + vl = RTC_VL_ACCURACY_LOW; | |
| 460 | + | |
| 461 | + if (sr & (RV3029_STATUS_VLOW2 | RV3029_STATUS_PON)) | |
| 462 | + vl |= RTC_VL_DATA_INVALID; | |
| 463 | + | |
| 464 | + return put_user(vl, (unsigned int __user *)arg); | |
| 465 | + | |
| 466 | + case RTC_VL_CLR: | |
| 467 | + return regmap_update_bits(rv3029->regmap, RV3029_STATUS, | |
| 468 | + RV3029_STATUS_VLOW1, 0); | |
| 469 | + | |
| 470 | + default: | |
| 471 | + return -ENOIOCTLCMD; | |
| 574 | 472 | } |
| 473 | +} | |
| 575 | 474 | |
| 576 | − return 0; | |
| 475 | +static int rv3029_nvram_write(void *priv, unsigned int offset, void *val, | |
| 476 | + size_t bytes) | |
| 477 | +{ | |
| 478 | + return regmap_bulk_write(priv, RV3029_RAM_PAGE + offset, val, bytes); | |
| 479 | +} | |
| 480 | + | |
| 481 | +static int rv3029_nvram_read(void *priv, unsigned int offset, void *val, | |
| 482 | + size_t bytes) | |
| 483 | +{ | |
| 484 | + return regmap_bulk_read(priv, RV3029_RAM_PAGE + offset, val, bytes); | |
| 577 | 485 | } |
| 578 | 486 | |
| 579 | 487 | static const struct rv3029_trickle_tab_elem { |
| @@ -635,6 +543,7 @@ static const struct rv3029_trickle_tab_elem { · 55 unmodified lines | ||
| 635 | 543 | |
| 636 | 544 | static void rv3029_trickle_config(struct device *dev) |
| 637 | 545 | { |
| 546 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 638 | 547 | struct device_node *of_node = dev->of_node; |
| 639 | 548 | const struct rv3029_trickle_tab_elem *elem; |
| 640 | 549 | int i, err; |
| @@ -661,7 +570,7 @@ static void rv3029_trickle_config(struct device *dev) · 20 unmodified lines | ||
| 661 | 570 | "Trickle charger enabled at %d ohms resistance.\n", |
| 662 | 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 | 574 | RV3029_TRICKLE_MASK, |
| 666 | 575 | trickle_set_bits); |
| 667 | 576 | if (err < 0) |
| @@ -670,12 +579,12 @@ static void rv3029_trickle_config(struct device *dev) · 2 unmodified lines | ||
| 670 | 579 | |
| 671 | 580 | #ifdef CONFIG_RTC_DRV_RV3029_HWMON |
| 672 | 581 | |
| 673 | −static int rv3029_read_temp(struct device *dev, int *temp_mC) | |
| 582 | +static int rv3029_read_temp(struct rv3029_data *rv3029, int *temp_mC) | |
| 674 | 583 | { |
| 584 | + unsigned int temp; | |
| 675 | 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 | 588 | if (ret < 0) |
| 680 | 589 | return ret; |
| 681 | 590 | |
| @@ -688,9 +597,10 @@ static ssize_t rv3029_hwmon_show_temp(struct device *dev, · 6 unmodified lines | ||
| 688 | 597 | struct device_attribute *attr, |
| 689 | 598 | char *buf) |
| 690 | 599 | { |
| 600 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 691 | 601 | int ret, temp_mC; |
| 692 | 602 | |
| 693 | − ret = rv3029_read_temp(dev, &temp_mC); | |
| 603 | + ret = rv3029_read_temp(rv3029, &temp_mC); | |
| 694 | 604 | if (ret < 0) |
| 695 | 605 | return ret; |
| 696 | 606 | |
| @@ -702,9 +612,10 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 5 unmodified lines | ||
| 702 | 612 | const char *buf, |
| 703 | 613 | size_t count) |
| 704 | 614 | { |
| 615 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 616 | + unsigned int th_set_bits = 0; | |
| 705 | 617 | unsigned long interval_ms; |
| 706 | 618 | int ret; |
| 707 | − u8 th_set_bits = 0; | |
| 708 | 619 | |
| 709 | 620 | ret = kstrtoul(buf, 10, &interval_ms); |
| 710 | 621 | if (ret < 0) |
| @@ -715,7 +626,7 @@ static ssize_t rv3029_hwmon_set_update_interval(struct device *dev, · 4 unmodified lines | ||
| 715 | 626 | if (interval_ms >= 16000) |
| 716 | 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 | 630 | RV3029_EECTRL_THE | RV3029_EECTRL_THP, |
| 720 | 631 | th_set_bits); |
| 721 | 632 | if (ret < 0) |
| @@ -728,10 +639,11 @@ static ssize_t rv3029_hwmon_show_update_interval(struct device *dev, · 6 unmodified lines | ||
| 728 | 639 | struct device_attribute *attr, |
| 729 | 640 | char *buf) |
| 730 | 641 | { |
| 642 | + struct rv3029_data *rv3029 = dev_get_drvdata(dev); | |
| 731 | 643 | int ret, interval_ms; |
| 732 | 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 | 647 | &eectrl, 1); |
| 736 | 648 | if (ret < 0) |
| 737 | 649 | return ret; |
| @@ -785,14 +697,23 @@ static void rv3029_hwmon_register(struct device *dev, const char *name) · 47 unmodified lines | ||
| 785 | 697 | static struct rtc_class_ops rv3029_rtc_ops = { |
| 786 | 698 | .read_time = rv3029_read_time, |
| 787 | 699 | .set_time = rv3029_set_time, |
| 700 | + .ioctl = rv3029_ioctl, | |
| 788 | 701 | }; |
| 789 | 702 | |
| 790 | 703 | static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, |
| 791 | 704 | const char *name) |
| 792 | 705 | { |
| 793 | 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 | 716 | int rc = 0; |
| 795 | − u8 buf[1]; | |
| 796 | 717 | |
| 797 | 718 | rv3029 = devm_kzalloc(dev, sizeof(*rv3029), GFP_KERNEL); |
| 798 | 719 | if (!rv3029) |
| @@ -803,21 +724,12 @@ static int rv3029_probe(struct device *dev, struct regmap *regmap, int irq, · 4 unmodified lines | ||
| 803 | 724 | rv3029->dev = dev; |
| 804 | 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 | 727 | rv3029_trickle_config(dev); |
| 813 | 728 | rv3029_hwmon_register(dev, name); |
| 814 | 729 | |
| 815 | − rv3029->rtc = devm_rtc_device_register(dev, name, &rv3029_rtc_ops, | |
| 816 | − THIS_MODULE); | |
| 817 | − if (IS_ERR(rv3029->rtc)) { | |
| 818 | − dev_err(dev, "unable to register the class device\n"); | |
| 730 | + rv3029->rtc = devm_rtc_allocate_device(dev); | |
| 731 | + if (IS_ERR(rv3029->rtc)) | |
| 819 | 732 | return PTR_ERR(rv3029->rtc); |
| 820 | − } | |
| 821 | 733 | |
| 822 | 734 | if (rv3029->irq > 0) { |
| 823 | 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 | 760 | return 0; |
| 838 | 761 | } |
| 839 | 762 | |
| 763 | +static const struct regmap_range rv3029_holes_range[] = { | |
| 764 | + regmap_reg_range(0x05, 0x07), | |
| 765 | + regmap_reg_range(0x0f, 0x0f), | |
| 766 | + regmap_reg_range(0x17, 0x17), | |
| 767 | + regmap_reg_range(0x1a, 0x1f), | |
| 768 | + regmap_reg_range(0x21, 0x27), | |
| 769 | + regmap_reg_range(0x34, 0x37), | |
| 770 | +}; | |
| 771 | + | |
| 772 | +static const struct regmap_access_table rv3029_regs = { | |
| 773 | + .no_ranges = rv3029_holes_range, | |
| 774 | + .n_no_ranges = ARRAY_SIZE(rv3029_holes_range), | |
| 775 | +}; | |
| 776 | + | |
| 777 | +static const struct regmap_config config = { | |
| 778 | + .reg_bits = 8, | |
| 779 | + .val_bits = 8, | |
| 780 | + .rd_table = &rv3029_regs, | |
| 781 | + .wr_table = &rv3029_regs, | |
| 782 | + .max_register = 0x3f, | |
| 783 | +}; | |
| 784 | + | |
| 840 | 785 | #if IS_ENABLED(CONFIG_I2C) |
| 841 | 786 | |
| 842 | 787 | static int rv3029_i2c_probe(struct i2c_client *client, |
| 843 | 788 | const struct i2c_device_id *id) |
| 844 | 789 | { |
| 845 | 790 | struct regmap *regmap; |
| 846 | − static const struct regmap_config config = { | |
| 847 | − .reg_bits = 8, | |
| 848 | − .val_bits = 8, | |
| 849 | − }; | |
| 850 | − | |
| 851 | 791 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | |
| 852 | 792 | I2C_FUNC_SMBUS_BYTE)) { |
| 853 | 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 | 797 | regmap = devm_regmap_init_i2c(client, &config); |
| 858 | − if (IS_ERR(regmap)) { | |
| 859 | − dev_err(&client->dev, "%s: regmap allocation failed: %ld\n", | |
| 860 | − __func__, PTR_ERR(regmap)); | |
| 798 | + if (IS_ERR(regmap)) | |
| 861 | 799 | return PTR_ERR(regmap); |
| 862 | − } | |
| 863 | 800 | |
| 864 | 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 | |
| 874 | 811 | static const struct of_device_id rv3029_of_match[] = { |
| 875 | 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 | }; |
| 882 | 815 | MODULE_DEVICE_TABLE(of, rv3029_of_match); |
| 883 | 816 | |
| 884 | 817 | static struct i2c_driver rv3029_driver = { |
| 885 | 818 | .driver = { |
| 886 | − .name = "rtc-rv3029c2", | |
| 819 | + .name = "rv3029", | |
| 887 | 820 | .of_match_table = of_match_ptr(rv3029_of_match), |
| 888 | 821 | }, |
| 889 | 822 | .probe = rv3029_i2c_probe, |
| 890 | 823 | .id_table = rv3029_id, |
| 891 | 824 | }; |
| 892 | 825 | |
| 893 | −static int rv3029_register_driver(void) | |
| 826 | +static int __init rv3029_register_driver(void) | |
| 894 | 827 | { |
| 895 | 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 | 836 | #else |
| 904 | 837 | |
| 905 | −static int rv3029_register_driver(void) | |
| 838 | +static int __init rv3029_register_driver(void) | |
| 906 | 839 | { |
| 907 | 840 | return 0; |
| 908 | 841 | } |
| @@ -917,18 +850,11 @@ static void rv3029_unregister_driver(void) · 8 unmodified lines | ||
| 917 | 850 | |
| 918 | 851 | static 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 | 853 | struct regmap *regmap; |
| 925 | 854 | |
| 926 | 855 | regmap = devm_regmap_init_spi(spi, &config); |
| 927 | − if (IS_ERR(regmap)) { | |
| 928 | − dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n", | |
| 929 | − __func__, PTR_ERR(regmap)); | |
| 856 | + if (IS_ERR(regmap)) | |
| 930 | 857 | return PTR_ERR(regmap); |
| 931 | − } | |
| 932 | 858 | |
| 933 | 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 | 866 | .probe = rv3049_probe, |
| 941 | 867 | }; |
| 942 | 868 | |
| 943 | −static int rv3049_register_driver(void) | |
| 869 | +static int __init rv3049_register_driver(void) | |
| 944 | 870 | { |
| 945 | 871 | return spi_register_driver(&rv3049_driver); |
| 946 | 872 | } |
| 947 | 873 | |
| 948 | −static void rv3049_unregister_driver(void) | |
| 874 | +static void __exit rv3049_unregister_driver(void) | |
| 949 | 875 | { |
| 950 | 876 | spi_unregister_driver(&rv3049_driver); |
| 951 | 877 | } |
| 952 | 878 | |
| 953 | 879 | #else |
| 954 | 880 | |
| 955 | −static int rv3049_register_driver(void) | |
| 881 | +static int __init rv3049_register_driver(void) | |
| 956 | 882 | { |
| 957 | 883 | return 0; |
| 958 | 884 | } |
| 959 | 885 | |
| 960 | −static void rv3049_unregister_driver(void) | |
| 886 | +static 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 | 894 | int ret; |
| 969 | 895 | |
| 970 | 896 | ret = rv3029_register_driver(); |
| 971 | − if (ret) { | |
| 972 | − pr_err("Failed to register rv3029 driver: %d\n", ret); | |
| 897 | + if (ret) | |
| 973 | 898 | return ret; |
| 974 | − } | |
| 975 | 899 | |
| 976 | 900 | ret = rv3049_register_driver(); |
| 977 | − if (ret) { | |
| 978 | − pr_err("Failed to register rv3049 driver: %d\n", ret); | |
| 901 | + if (ret) | |
| 979 | 902 | rv3029_unregister_driver(); |
| 980 | − } | |
| 981 | 903 | |
| 982 | 904 | return ret; |
| 983 | 905 | } |
| @@ -411,6 +411,7 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 410 unmodified lines | ||
| 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) { |
| @@ -419,18 +420,15 @@ static int rv8803_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines | ||
| 419 | 420 | if (flags < 0) |
| 420 | 421 | return flags; |
| 421 | 422 | |
| 422 | − if (flags & RV8803_FLAG_V1F) | |
| 423 | + if (flags & RV8803_FLAG_V1F) { | |
| 423 | 424 | dev_warn(&client->dev, "Voltage low, temperature compensation stopped.\n"); |
| 425 | + vl = RTC_VL_ACCURACY_LOW; | |
| 426 | + } | |
| 424 | 427 | |
| 425 | 428 | if (flags & RV8803_FLAG_V2F) |
| 426 | − dev_warn(&client->dev, "Voltage low, data loss detected.\n"); | |
| 427 | − | |
| 428 | − flags &= RV8803_FLAG_V1F | RV8803_FLAG_V2F; | |
| 429 | + vl |= RTC_VL_DATA_INVALID; | |
| 429 | 430 | |
| 430 | − if (copy_to_user((void __user *)arg, &flags, sizeof(int))) | |
| 431 | − return -EFAULT; | |
| 432 | − | |
| 433 | − return 0; | |
| 431 | + return put_user(vl, (unsigned int __user *)arg); | |
| 434 | 432 | |
| 435 | 433 | case RTC_VL_CLR: |
| 436 | 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 | 438 | return flags; |
| 441 | 439 | } |
| 442 | 440 | |
| 443 | − flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F); | |
| 441 | + flags &= ~RV8803_FLAG_V1F; | |
| 444 | 442 | ret = rv8803_write_reg(client, RV8803_FLAG, flags); |
| 445 | 443 | mutex_unlock(&rv8803->flags_lock); |
| 446 | 444 | if (ret) |
| @@ -389,9 +389,8 @@ static int rx8010_alarm_irq_enable(struct device *dev, · 388 unmodified lines | ||
| 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) { |
| @@ -400,24 +399,8 @@ static int rx8010_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) · 2 unmodified lines | ||
| 400 | 399 | if (flagreg < 0) |
| 401 | 400 | return flagreg; |
| 402 | 401 | |
| 403 | − tmp = !!(flagreg & RX8010_FLAG_VLF); | |
| 404 | − if (copy_to_user((void __user *)arg, &tmp, sizeof(int))) | |
| 405 | − return -EFAULT; | |
| 406 | − | |
| 407 | − return 0; | |
| 408 | − | |
| 409 | − case RTC_VL_CLR: | |
| 410 | − flagreg = i2c_smbus_read_byte_data(rx8010->client, RX8010_FLAG); | |
| 411 | − if (flagreg < 0) { | |
| 412 | − return flagreg; | |
| 413 | − } | |
| 414 | − | |
| 415 | − flagreg &= ~RX8010_FLAG_VLF; | |
| 416 | − ret = i2c_smbus_write_byte_data(client, RX8010_FLAG, flagreg); | |
| 417 | − if (ret < 0) | |
| 418 | − return ret; | |
| 419 | − | |
| 420 | − return 0; | |
| 402 | + tmp = flagreg & RX8010_FLAG_VLF ? RTC_VL_DATA_INVALID : 0; | |
| 403 | + return put_user(tmp, (unsigned int __user *)arg); | |
| 421 | 404 | |
| 422 | 405 | default: |
| 423 | 406 | return -ENOIOCTLCMD; |
| @@ -482,7 +465,7 @@ static int rx8010_probe(struct i2c_client *client, · 58 unmodified lines | ||
| 482 | 465 | |
| 483 | 466 | rx8010->rtc->max_user_freq = 1; |
| 484 | 467 | |
| 485 | − return err; | |
| 468 | + return 0; | |
| 486 | 469 | } |
| 487 | 470 | |
| 488 | 471 | static struct i2c_driver rx8010_driver = { |
| @@ -67,7 +67,6 @@ static const struct i2c_device_id rx8025_id[] = { · 66 unmodified lines | ||
| 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 | }; |
| @@ -103,10 +102,10 @@ static s32 rx8025_write_regs(const struct i2c_client *client, · 29 unmodified lines | ||
| 103 | 102 | |
| 104 | 103 | static 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 | 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 | 109 | if (ctrl2 < 0) |
| 111 | 110 | return ctrl2; |
| 112 | 111 | |
| @@ -178,6 +177,7 @@ out: · 65 unmodified lines | ||
| 178 | 177 | |
| 179 | 178 | static int rx8025_get_time(struct device *dev, struct rtc_time *dt) |
| 180 | 179 | { |
| 180 | + struct i2c_client *client = to_i2c_client(dev); | |
| 181 | 181 | struct rx8025_data *rx8025 = dev_get_drvdata(dev); |
| 182 | 182 | u8 date[7]; |
| 183 | 183 | int err; |
| @@ -186,7 +186,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 2 unmodified lines | ||
| 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,6 +211,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 18 unmodified lines | ||
| 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; |
| @@ -237,11 +238,11 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) · 20 unmodified lines | ||
| 237 | 238 | |
| 238 | 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 | 242 | if (ret < 0) |
| 242 | 243 | return ret; |
| 243 | 244 | |
| 244 | − return rx8025_reset_validity(rx8025->client); | |
| 245 | + return rx8025_reset_validity(client); | |
| 245 | 246 | } |
| 246 | 247 | |
| 247 | 248 | static int rx8025_init_client(struct i2c_client *client) |
| @@ -251,7 +252,7 @@ static int rx8025_init_client(struct i2c_client *client) · 3 unmodified lines | ||
| 251 | 252 | int need_clear = 0; |
| 252 | 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 | 256 | if (err) |
| 256 | 257 | goto out; |
| 257 | 258 | |
| @@ -280,8 +281,8 @@ out: · 22 unmodified lines | ||
| 280 | 281 | /* Alarm support */ |
| 281 | 282 | static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) |
| 282 | 283 | { |
| 284 | + struct i2c_client *client = to_i2c_client(dev); | |
| 283 | 285 | struct rx8025_data *rx8025 = dev_get_drvdata(dev); |
| 284 | − struct i2c_client *client = rx8025->client; | |
| 285 | 286 | u8 ald[2]; |
| 286 | 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 | 349 | if (rx8025->ctrl1 & RX8025_BIT_CTRL1_DALE) { |
| 349 | 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 | 352 | rx8025->ctrl1); |
| 352 | 353 | if (err) |
| 353 | 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 | 357 | if (err) |
| 357 | 358 | return err; |
| 358 | 359 | |
| 359 | 360 | if (t->enabled) { |
| 360 | 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 | 363 | rx8025->ctrl1); |
| 363 | 364 | if (err) |
| 364 | 365 | return err; |
| @@ -369,6 +370,7 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 4 unmodified lines | ||
| 369 | 370 | |
| 370 | 371 | static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 371 | 372 | { |
| 373 | + struct i2c_client *client = to_i2c_client(dev); | |
| 372 | 374 | struct rx8025_data *rx8025 = dev_get_drvdata(dev); |
| 373 | 375 | u8 ctrl1; |
| 374 | 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 | 384 | if (ctrl1 != rx8025->ctrl1) { |
| 383 | 385 | rx8025->ctrl1 = ctrl1; |
| 384 | − err = rx8025_write_reg(rx8025->client, RX8025_REG_CTRL1, | |
| 386 | + err = rx8025_write_reg(client, RX8025_REG_CTRL1, | |
| 385 | 387 | rx8025->ctrl1); |
| 386 | 388 | if (err) |
| 387 | 389 | return err; |
| @@ -516,7 +518,6 @@ static int rx8025_probe(struct i2c_client *client, · 128 unmodified lines | ||
| 516 | 518 | if (!rx8025) |
| 517 | 519 | return -ENOMEM; |
| 518 | 520 | |
| 519 | − rx8025->client = client; | |
| 520 | 521 | i2c_set_clientdata(client, rx8025); |
| 521 | 522 | |
| 522 | 523 | err = rx8025_init_client(client); |
| @@ -897,8 +897,11 @@ static int stm32_rtc_resume(struct device *dev) · 896 unmodified lines | ||
| 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); |
| @@ -23,6 +23,7 @@ · 22 unmodified lines | ||
| 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> |
| @@ -267,6 +268,8 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 238 unmodified lines | ||
| 267 | 268 | rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0); |
| 268 | 269 | rtc->rtc->set_start_time = true; |
| 269 | 270 | |
| 271 | + irq_set_status_flags(rtc->irq, IRQ_NOAUTOEN); | |
| 272 | + | |
| 270 | 273 | ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, |
| 271 | 274 | tps6586x_rtc_irq, |
| 272 | 275 | IRQF_ONESHOT, |
| @@ -276,7 +279,6 @@ static int tps6586x_rtc_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 276 | 279 | rtc->irq, ret); |
| 277 | 280 | goto fail_rtc_register; |
| 278 | 281 | } |
| 279 | − disable_irq(rtc->irq); | |
| 280 | 282 | |
| 281 | 283 | ret = rtc_register_device(rtc->rtc); |
| 282 | 284 | if (ret) |
| @@ -94,7 +94,7 @@ static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 93 unmodified lines | ||
| 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,8 +104,8 @@ static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) · 3 unmodified lines | ||
| 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 | } |
| @@ -167,6 +167,7 @@ struct rtc_device { · 166 unmodified lines | ||
| 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 */ |
| @@ -92,7 +92,12 @@ struct rtc_pll_info { · 91 unmodified lines | ||
| 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 */ |