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

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

Pull RTC updates from Alexandre Belloni:
"Subsystem:

- Add a way for drivers to tell the core the supported alarm range is
smaller than the date range. This is not used yet but will be
useful for the alarmtimers in the next release.

- fix Wvoid-pointer-to-enum-cast warnings

- remove redundant of_match_ptr()

- stop warning for invalid alarms when the alarm is disabled

Drivers:

- isl12022: allow setting the trip level for battery level detection

- pcf2127: add support for PCF2131 and multiple timestamps

- stm32: time precision improvement, many fixes

- twl: NVRAM support"

* tag 'rtc-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (73 commits)
dt-bindings: rtc: ds3231: Remove text binding
rtc: wm8350: remove unnecessary messages
rtc: twl: remove unnecessary messages
rtc: sun6i: remove unnecessary message
rtc: stop warning for invalid alarms when the alarm is disabled
rtc: twl: add NVRAM support
rtc: pcf85363: Allow to wake up system without IRQ
rtc: m48t86: add DT support for m48t86
dt-bindings: rtc: Add ST M48T86
rtc: pcf2127: remove useless check
rtc: rzn1: Report maximum alarm limit to rtc core
rtc: ds1305: Report maximum alarm limit to rtc core
rtc: tps6586x: Report maximum alarm limit to rtc core
rtc: cmos: Report supported alarm limit to rtc infrastructure
rtc: cros-ec: Detect and report supported alarm window size
rtc: Add support for limited alarm timer offsets
rtc: isl1208: Fix incorrect logic in isl1208_set_xtoscb()
MAINTAINERS: remove obsolete pattern in RTC SUBSYSTEM section
rtc: tps65910: Remove redundant dev_warn() and do not check for 0 return after calling platform_get_irq()
rtc: omap: Do not check for 0 return after calling platform_get_irq()
...

+1337 -619
+11 -7
Documentation/devicetree/bindings/rtc/atmel,at91rm9200-rtc.yaml
··· 14 14 15 15 properties: 16 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 - - microchip,sama7g5-rtc 17 + oneOf: 18 + - enum: 19 + - atmel,at91rm9200-rtc 20 + - atmel,at91sam9x5-rtc 21 + - atmel,sama5d4-rtc 22 + - atmel,sama5d2-rtc 23 + - microchip,sam9x60-rtc 24 + - microchip,sama7g5-rtc 25 + - items: 26 + - const: microchip,sam9x7-rtc 27 + - const: microchip,sam9x60-rtc 24 28 25 29 reg: 26 30 maxItems: 1
+64
Documentation/devicetree/bindings/rtc/intersil,isl12022.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/rtc/intersil,isl12022.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Intersil ISL12022 Real-time Clock 8 + 9 + maintainers: 10 + - Alexandre Belloni <alexandre.belloni@bootlin.com> 11 + 12 + properties: 13 + compatible: 14 + const: isil,isl12022 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + maxItems: 1 21 + 22 + '#clock-cells': 23 + const: 0 24 + 25 + isil,battery-trip-levels-microvolt: 26 + description: 27 + The battery voltages at which the first alarm and second alarm 28 + should trigger (normally ~85% and ~75% of nominal V_BAT). 29 + items: 30 + - enum: [2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000] 31 + - enum: [1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000] 32 + 33 + required: 34 + - compatible 35 + - reg 36 + 37 + allOf: 38 + - $ref: rtc.yaml# 39 + # If #clock-cells is present, interrupts must not be present 40 + - if: 41 + required: 42 + - '#clock-cells' 43 + then: 44 + properties: 45 + interrupts: false 46 + 47 + unevaluatedProperties: false 48 + 49 + examples: 50 + - | 51 + #include <dt-bindings/interrupt-controller/irq.h> 52 + i2c { 53 + #address-cells = <1>; 54 + #size-cells = <0>; 55 + 56 + rtc@6f { 57 + compatible = "isil,isl12022"; 58 + reg = <0x6f>; 59 + interrupts-extended = <&gpio1 5 IRQ_TYPE_LEVEL_LOW>; 60 + isil,battery-trip-levels-microvolt = <2550000>, <2250000>; 61 + }; 62 + }; 63 + 64 + ...
-38
Documentation/devicetree/bindings/rtc/maxim,ds3231.txt
··· 1 - * Maxim DS3231 Real Time Clock 2 - 3 - Required properties: 4 - - compatible: Should contain "maxim,ds3231". 5 - - reg: I2C address for chip. 6 - 7 - Optional property: 8 - - #clock-cells: Should be 1. 9 - - clock-output-names: 10 - overwrite the default clock names "ds3231_clk_sqw" and "ds3231_clk_32khz". 11 - 12 - Each clock is assigned an identifier and client nodes can use this identifier 13 - to specify the clock which they consume. Following indices are allowed: 14 - - 0: square-wave output on the SQW pin 15 - - 1: square-wave output on the 32kHz pin 16 - 17 - - interrupts: rtc alarm/event interrupt. When this property is selected, 18 - clock on the SQW pin cannot be used. 19 - 20 - Example: 21 - 22 - ds3231: ds3231@51 { 23 - compatible = "maxim,ds3231"; 24 - reg = <0x68>; 25 - #clock-cells = <1>; 26 - }; 27 - 28 - device1 { 29 - ... 30 - clocks = <&ds3231 0>; 31 - ... 32 - }; 33 - 34 - device2 { 35 - ... 36 - clocks = <&ds3231 1>; 37 - ... 38 - };
+1
Documentation/devicetree/bindings/rtc/nxp,pcf2127.yaml
··· 18 18 - nxp,pca2129 19 19 - nxp,pcf2127 20 20 - nxp,pcf2129 21 + - nxp,pcf2131 21 22 22 23 reg: 23 24 maxItems: 1
+38
Documentation/devicetree/bindings/rtc/st,m48t86.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/rtc/st,m48t86.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ST M48T86 / Dallas DS12887 RTC with SRAM 8 + 9 + maintainers: 10 + - Alexandre Belloni <alexandre.belloni@bootlin.com> 11 + 12 + allOf: 13 + - $ref: rtc.yaml 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - st,m48t86 19 + 20 + reg: 21 + items: 22 + - description: index register 23 + - description: data register 24 + 25 + required: 26 + - compatible 27 + - reg 28 + 29 + unevaluatedProperties: false 30 + 31 + examples: 32 + - | 33 + rtc@10800000 { 34 + compatible = "st,m48t86"; 35 + reg = <0x10800000 0x1>, <0x11700000 0x1>; 36 + }; 37 + 38 + ...
-2
Documentation/devicetree/bindings/rtc/trivial-rtc.yaml
··· 45 45 - isil,isl1208 46 46 # Intersil ISL1218 Low Power RTC with Battery Backed SRAM 47 47 - isil,isl1218 48 - # Intersil ISL12022 Real-time Clock 49 - - isil,isl12022 50 48 # Real Time Clock Module with I2C-Bus 51 49 - microcrystal,rv3029 52 50 # Real Time Clock
-1
MAINTAINERS
··· 18084 18084 F: Documentation/admin-guide/rtc.rst 18085 18085 F: Documentation/devicetree/bindings/rtc/ 18086 18086 F: drivers/rtc/ 18087 - F: include/linux/platform_data/rtc-* 18088 18087 F: include/linux/rtc.h 18089 18088 F: include/linux/rtc/ 18090 18089 F: include/uapi/linux/rtc.h
+3 -2
drivers/rtc/Kconfig
··· 904 904 select REGMAP_SPI if SPI_MASTER 905 905 select WATCHDOG_CORE if WATCHDOG 906 906 help 907 - If you say yes here you get support for the NXP PCF2127/29 RTC 907 + If you say yes here you get support for the NXP PCF2127/29/31 RTC 908 908 chips with integrated quartz crystal for industrial applications. 909 - Both chips also have watchdog timer and tamper switch detection 909 + These chips also have watchdog timer and tamper switch detection 910 910 features. 911 911 912 912 PCF2127 has an additional feature of 512 bytes battery backed ··· 1196 1196 config RTC_DRV_BQ4802 1197 1197 tristate "TI BQ4802" 1198 1198 depends on HAS_IOMEM && HAS_IOPORT 1199 + depends on SPARC || COMPILE_TEST 1199 1200 help 1200 1201 If you say Y here you will get support for the TI 1201 1202 BQ4802 RTC chip.
+1 -1
drivers/rtc/interface.c
··· 376 376 err = rtc_valid_tm(&alarm->time); 377 377 378 378 done: 379 - if (err) 379 + if (err && alarm->enabled) 380 380 dev_warn(&rtc->dev, "invalid alarm value: %ptR\n", 381 381 &alarm->time); 382 382
+1 -1
drivers/rtc/rtc-abx80x.c
··· 15 15 #include <linux/i2c.h> 16 16 #include <linux/kstrtox.h> 17 17 #include <linux/module.h> 18 - #include <linux/of_device.h> 18 + #include <linux/of.h> 19 19 #include <linux/rtc.h> 20 20 #include <linux/watchdog.h> 21 21
+1 -4
drivers/rtc/rtc-armada38x.c
··· 11 11 #include <linux/io.h> 12 12 #include <linux/module.h> 13 13 #include <linux/of.h> 14 - #include <linux/of_device.h> 15 14 #include <linux/platform_device.h> 16 15 #include <linux/rtc.h> 17 16 ··· 473 474 .alarm = ALARM2, 474 475 }; 475 476 476 - #ifdef CONFIG_OF 477 477 static const struct of_device_id armada38x_rtc_of_match_table[] = { 478 478 { 479 479 .compatible = "marvell,armada-380-rtc", ··· 485 487 {} 486 488 }; 487 489 MODULE_DEVICE_TABLE(of, armada38x_rtc_of_match_table); 488 - #endif 489 490 490 491 static __init int armada38x_rtc_probe(struct platform_device *pdev) 491 492 { ··· 574 577 .driver = { 575 578 .name = "armada38x-rtc", 576 579 .pm = &armada38x_rtc_pm_ops, 577 - .of_match_table = of_match_ptr(armada38x_rtc_of_match_table), 580 + .of_match_table = armada38x_rtc_of_match_table, 578 581 }, 579 582 }; 580 583
+1 -1
drivers/rtc/rtc-aspeed.c
··· 118 118 static struct platform_driver aspeed_rtc_driver = { 119 119 .driver = { 120 120 .name = "aspeed-rtc", 121 - .of_match_table = of_match_ptr(aspeed_rtc_match), 121 + .of_match_table = aspeed_rtc_match, 122 122 }, 123 123 }; 124 124
+1 -2
drivers/rtc/rtc-at91rm9200.c
··· 22 22 #include <linux/io.h> 23 23 #include <linux/kernel.h> 24 24 #include <linux/module.h> 25 - #include <linux/of_device.h> 26 25 #include <linux/of.h> 27 26 #include <linux/platform_device.h> 28 27 #include <linux/rtc.h> ··· 641 642 .driver = { 642 643 .name = "at91_rtc", 643 644 .pm = &at91_rtc_pm_ops, 644 - .of_match_table = of_match_ptr(at91_rtc_dt_ids), 645 + .of_match_table = at91_rtc_dt_ids, 645 646 }, 646 647 }; 647 648
+1 -1
drivers/rtc/rtc-at91sam9.c
··· 534 534 .driver = { 535 535 .name = "rtc-at91sam9", 536 536 .pm = &at91_rtc_pm_ops, 537 - .of_match_table = of_match_ptr(at91_rtc_dt_ids), 537 + .of_match_table = at91_rtc_dt_ids, 538 538 }, 539 539 }; 540 540
+11
drivers/rtc/rtc-cmos.c
··· 913 913 #define INITSECTION __init 914 914 #endif 915 915 916 + #define SECS_PER_DAY (24 * 60 * 60) 917 + #define SECS_PER_MONTH (28 * SECS_PER_DAY) 918 + #define SECS_PER_YEAR (365 * SECS_PER_DAY) 919 + 916 920 static int INITSECTION 917 921 cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq) 918 922 { ··· 1022 1018 retval = PTR_ERR(cmos_rtc.rtc); 1023 1019 goto cleanup0; 1024 1020 } 1021 + 1022 + if (cmos_rtc.mon_alrm) 1023 + cmos_rtc.rtc->alarm_offset_max = SECS_PER_YEAR - 1; 1024 + else if (cmos_rtc.day_alrm) 1025 + cmos_rtc.rtc->alarm_offset_max = SECS_PER_MONTH - 1; 1026 + else 1027 + cmos_rtc.rtc->alarm_offset_max = SECS_PER_DAY - 1; 1025 1028 1026 1029 rename_region(ports, dev_name(&cmos_rtc.rtc->dev)); 1027 1030
+23 -15
drivers/rtc/rtc-cros-ec.c
··· 182 182 183 183 ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, alarm_offset); 184 184 if (ret < 0) { 185 - if (ret == -EINVAL && alarm_offset >= SECS_PER_DAY) { 186 - /* 187 - * RTC chips on some older Chromebooks can only handle 188 - * alarms up to 24h in the future. Try to set an alarm 189 - * below that limit to avoid suspend failures. 190 - */ 191 - ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, 192 - SECS_PER_DAY - 1); 193 - } 194 - 195 - if (ret < 0) { 196 - dev_err(dev, "error setting alarm in %u seconds: %d\n", 197 - alarm_offset, ret); 198 - return ret; 199 - } 185 + dev_err(dev, "error setting alarm in %u seconds: %d\n", 186 + alarm_offset, ret); 187 + /* 188 + * The EC code returns -EINVAL if the alarm time is too 189 + * far in the future. Convert it to the expected error code. 190 + */ 191 + if (ret == -EINVAL) 192 + ret = -ERANGE; 193 + return ret; 200 194 } 201 195 202 196 return 0; ··· 348 354 349 355 cros_ec_rtc->rtc->ops = &cros_ec_rtc_ops; 350 356 cros_ec_rtc->rtc->range_max = U32_MAX; 357 + 358 + /* 359 + * The RTC on some older Chromebooks can only handle alarms less than 360 + * 24 hours in the future. The only way to find out is to try to set an 361 + * alarm further in the future. If that fails, assume that the RTC 362 + * connected to the EC can only handle less than 24 hours of alarm 363 + * window. 364 + */ 365 + ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, SECS_PER_DAY * 2); 366 + if (ret == -EINVAL) 367 + cros_ec_rtc->rtc->alarm_offset_max = SECS_PER_DAY - 1; 368 + 369 + (void)cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_ALARM, 370 + EC_RTC_ALARM_CLEAR); 351 371 352 372 ret = devm_rtc_register_device(cros_ec_rtc->rtc); 353 373 if (ret)
+7
drivers/rtc/rtc-da9063.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/of.h> 13 13 #include <linux/platform_device.h> 14 + #include <linux/pm_wakeirq.h> 14 15 #include <linux/regmap.h> 15 16 #include <linux/rtc.h> 16 17 #include <linux/slab.h> ··· 496 495 if (ret) 497 496 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n", 498 497 irq_alarm, ret); 498 + 499 + ret = dev_pm_set_wake_irq(&pdev->dev, irq_alarm); 500 + if (ret) 501 + dev_warn(&pdev->dev, 502 + "Failed to set IRQ %d as a wake IRQ: %d\n", 503 + irq_alarm, ret); 499 504 500 505 device_init_wakeup(&pdev->dev, true); 501 506
+3 -2
drivers/rtc/rtc-ds1305.c
··· 336 336 /* make sure alarm fires within the next 24 hours */ 337 337 if (later <= now) 338 338 return -EINVAL; 339 - if ((later - now) > 24 * 60 * 60) 340 - return -EDOM; 339 + if ((later - now) > ds1305->rtc->alarm_offset_max) 340 + return -ERANGE; 341 341 342 342 /* disable alarm if needed */ 343 343 if (ds1305->ctrl[0] & DS1305_AEI0) { ··· 691 691 ds1305->rtc->ops = &ds1305_ops; 692 692 ds1305->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 693 693 ds1305->rtc->range_max = RTC_TIMESTAMP_END_2099; 694 + ds1305->rtc->alarm_offset_max = 24 * 60 * 60; 694 695 695 696 ds1305_nvmem_cfg.priv = ds1305; 696 697 status = devm_rtc_register_device(ds1305->rtc);
+1 -1
drivers/rtc/rtc-ds1307.c
··· 1744 1744 1745 1745 match = device_get_match_data(&client->dev); 1746 1746 if (match) { 1747 - ds1307->type = (enum ds_type)match; 1747 + ds1307->type = (uintptr_t)match; 1748 1748 chip = &chips[ds1307->type]; 1749 1749 } else if (id) { 1750 1750 chip = &chips[id->driver_data];
-1
drivers/rtc/rtc-ds1742.c
··· 16 16 #include <linux/jiffies.h> 17 17 #include <linux/rtc.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_device.h> 20 19 #include <linux/platform_device.h> 21 20 #include <linux/io.h> 22 21 #include <linux/module.h>
+69 -100
drivers/rtc/rtc-ds2404.c
··· 7 7 #include <linux/rtc.h> 8 8 #include <linux/types.h> 9 9 #include <linux/bcd.h> 10 - #include <linux/platform_data/rtc-ds2404.h> 11 10 #include <linux/delay.h> 12 - #include <linux/gpio.h> 11 + #include <linux/gpio/consumer.h> 13 12 #include <linux/slab.h> 14 13 15 14 #include <linux/io.h> ··· 26 27 #define DS2404_CLK 1 27 28 #define DS2404_DQ 2 28 29 29 - struct ds2404_gpio { 30 - const char *name; 31 - unsigned int gpio; 32 - }; 33 - 34 30 struct ds2404 { 35 - struct ds2404_gpio *gpio; 31 + struct device *dev; 32 + struct gpio_desc *rst_gpiod; 33 + struct gpio_desc *clk_gpiod; 34 + struct gpio_desc *dq_gpiod; 36 35 struct rtc_device *rtc; 37 36 }; 38 37 39 - static struct ds2404_gpio ds2404_gpio[] = { 40 - { "RTC RST", 0 }, 41 - { "RTC CLK", 0 }, 42 - { "RTC DQ", 0 }, 43 - }; 44 - 45 - static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev, 46 - struct ds2404_platform_data *pdata) 38 + static int ds2404_gpio_map(struct ds2404 *chip, struct platform_device *pdev) 47 39 { 48 - int i, err; 40 + struct device *dev = &pdev->dev; 49 41 50 - ds2404_gpio[DS2404_RST].gpio = pdata->gpio_rst; 51 - ds2404_gpio[DS2404_CLK].gpio = pdata->gpio_clk; 52 - ds2404_gpio[DS2404_DQ].gpio = pdata->gpio_dq; 42 + /* This will de-assert RESET, declare this GPIO as GPIOD_ACTIVE_LOW */ 43 + chip->rst_gpiod = devm_gpiod_get(dev, "rst", GPIOD_OUT_LOW); 44 + if (IS_ERR(chip->rst_gpiod)) 45 + return PTR_ERR(chip->rst_gpiod); 53 46 54 - for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++) { 55 - err = gpio_request(ds2404_gpio[i].gpio, ds2404_gpio[i].name); 56 - if (err) { 57 - dev_err(&pdev->dev, "error mapping gpio %s: %d\n", 58 - ds2404_gpio[i].name, err); 59 - goto err_request; 60 - } 61 - if (i != DS2404_DQ) 62 - gpio_direction_output(ds2404_gpio[i].gpio, 1); 63 - } 47 + chip->clk_gpiod = devm_gpiod_get(dev, "clk", GPIOD_OUT_HIGH); 48 + if (IS_ERR(chip->clk_gpiod)) 49 + return PTR_ERR(chip->clk_gpiod); 64 50 65 - chip->gpio = ds2404_gpio; 51 + chip->dq_gpiod = devm_gpiod_get(dev, "dq", GPIOD_ASIS); 52 + if (IS_ERR(chip->dq_gpiod)) 53 + return PTR_ERR(chip->dq_gpiod); 54 + 66 55 return 0; 67 - 68 - err_request: 69 - while (--i >= 0) 70 - gpio_free(ds2404_gpio[i].gpio); 71 - return err; 72 56 } 73 57 74 - static void ds2404_gpio_unmap(void *data) 58 + static void ds2404_reset(struct ds2404 *chip) 75 59 { 76 - int i; 77 - 78 - for (i = 0; i < ARRAY_SIZE(ds2404_gpio); i++) 79 - gpio_free(ds2404_gpio[i].gpio); 80 - } 81 - 82 - static void ds2404_reset(struct device *dev) 83 - { 84 - gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 0); 60 + gpiod_set_value(chip->rst_gpiod, 1); 85 61 udelay(1000); 86 - gpio_set_value(ds2404_gpio[DS2404_RST].gpio, 1); 87 - gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0); 88 - gpio_direction_output(ds2404_gpio[DS2404_DQ].gpio, 0); 62 + gpiod_set_value(chip->rst_gpiod, 0); 63 + gpiod_set_value(chip->clk_gpiod, 0); 64 + gpiod_direction_output(chip->dq_gpiod, 0); 89 65 udelay(10); 90 66 } 91 67 92 - static void ds2404_write_byte(struct device *dev, u8 byte) 68 + static void ds2404_write_byte(struct ds2404 *chip, u8 byte) 93 69 { 94 70 int i; 95 71 96 - gpio_direction_output(ds2404_gpio[DS2404_DQ].gpio, 1); 72 + gpiod_direction_output(chip->dq_gpiod, 1); 97 73 for (i = 0; i < 8; i++) { 98 - gpio_set_value(ds2404_gpio[DS2404_DQ].gpio, byte & (1 << i)); 74 + gpiod_set_value(chip->dq_gpiod, byte & (1 << i)); 99 75 udelay(10); 100 - gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 1); 76 + gpiod_set_value(chip->clk_gpiod, 1); 101 77 udelay(10); 102 - gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0); 78 + gpiod_set_value(chip->clk_gpiod, 0); 103 79 udelay(10); 104 80 } 105 81 } 106 82 107 - static u8 ds2404_read_byte(struct device *dev) 83 + static u8 ds2404_read_byte(struct ds2404 *chip) 108 84 { 109 85 int i; 110 86 u8 ret = 0; 111 87 112 - gpio_direction_input(ds2404_gpio[DS2404_DQ].gpio); 88 + gpiod_direction_input(chip->dq_gpiod); 113 89 114 90 for (i = 0; i < 8; i++) { 115 - gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 0); 91 + gpiod_set_value(chip->clk_gpiod, 0); 116 92 udelay(10); 117 - if (gpio_get_value(ds2404_gpio[DS2404_DQ].gpio)) 93 + if (gpiod_get_value(chip->dq_gpiod)) 118 94 ret |= 1 << i; 119 - gpio_set_value(ds2404_gpio[DS2404_CLK].gpio, 1); 95 + gpiod_set_value(chip->clk_gpiod, 1); 120 96 udelay(10); 121 97 } 122 98 return ret; 123 99 } 124 100 125 - static void ds2404_read_memory(struct device *dev, u16 offset, 101 + static void ds2404_read_memory(struct ds2404 *chip, u16 offset, 126 102 int length, u8 *out) 127 103 { 128 - ds2404_reset(dev); 129 - ds2404_write_byte(dev, DS2404_READ_MEMORY_CMD); 130 - ds2404_write_byte(dev, offset & 0xff); 131 - ds2404_write_byte(dev, (offset >> 8) & 0xff); 104 + ds2404_reset(chip); 105 + ds2404_write_byte(chip, DS2404_READ_MEMORY_CMD); 106 + ds2404_write_byte(chip, offset & 0xff); 107 + ds2404_write_byte(chip, (offset >> 8) & 0xff); 132 108 while (length--) 133 - *out++ = ds2404_read_byte(dev); 109 + *out++ = ds2404_read_byte(chip); 134 110 } 135 111 136 - static void ds2404_write_memory(struct device *dev, u16 offset, 112 + static void ds2404_write_memory(struct ds2404 *chip, u16 offset, 137 113 int length, u8 *out) 138 114 { 139 115 int i; 140 116 u8 ta01, ta02, es; 141 117 142 - ds2404_reset(dev); 143 - ds2404_write_byte(dev, DS2404_WRITE_SCRATCHPAD_CMD); 144 - ds2404_write_byte(dev, offset & 0xff); 145 - ds2404_write_byte(dev, (offset >> 8) & 0xff); 118 + ds2404_reset(chip); 119 + ds2404_write_byte(chip, DS2404_WRITE_SCRATCHPAD_CMD); 120 + ds2404_write_byte(chip, offset & 0xff); 121 + ds2404_write_byte(chip, (offset >> 8) & 0xff); 146 122 147 123 for (i = 0; i < length; i++) 148 - ds2404_write_byte(dev, out[i]); 124 + ds2404_write_byte(chip, out[i]); 149 125 150 - ds2404_reset(dev); 151 - ds2404_write_byte(dev, DS2404_READ_SCRATCHPAD_CMD); 126 + ds2404_reset(chip); 127 + ds2404_write_byte(chip, DS2404_READ_SCRATCHPAD_CMD); 152 128 153 - ta01 = ds2404_read_byte(dev); 154 - ta02 = ds2404_read_byte(dev); 155 - es = ds2404_read_byte(dev); 129 + ta01 = ds2404_read_byte(chip); 130 + ta02 = ds2404_read_byte(chip); 131 + es = ds2404_read_byte(chip); 156 132 157 133 for (i = 0; i < length; i++) { 158 - if (out[i] != ds2404_read_byte(dev)) { 159 - dev_err(dev, "read invalid data\n"); 134 + if (out[i] != ds2404_read_byte(chip)) { 135 + dev_err(chip->dev, "read invalid data\n"); 160 136 return; 161 137 } 162 138 } 163 139 164 - ds2404_reset(dev); 165 - ds2404_write_byte(dev, DS2404_COPY_SCRATCHPAD_CMD); 166 - ds2404_write_byte(dev, ta01); 167 - ds2404_write_byte(dev, ta02); 168 - ds2404_write_byte(dev, es); 140 + ds2404_reset(chip); 141 + ds2404_write_byte(chip, DS2404_COPY_SCRATCHPAD_CMD); 142 + ds2404_write_byte(chip, ta01); 143 + ds2404_write_byte(chip, ta02); 144 + ds2404_write_byte(chip, es); 169 145 170 - gpio_direction_input(ds2404_gpio[DS2404_DQ].gpio); 171 - while (gpio_get_value(ds2404_gpio[DS2404_DQ].gpio)) 146 + while (gpiod_get_value(chip->dq_gpiod)) 172 147 ; 173 148 } 174 149 175 - static void ds2404_enable_osc(struct device *dev) 150 + static void ds2404_enable_osc(struct ds2404 *chip) 176 151 { 177 152 u8 in[1] = { 0x10 }; /* enable oscillator */ 178 - ds2404_write_memory(dev, 0x201, 1, in); 153 + 154 + ds2404_write_memory(chip, 0x201, 1, in); 179 155 } 180 156 181 157 static int ds2404_read_time(struct device *dev, struct rtc_time *dt) 182 158 { 159 + struct ds2404 *chip = dev_get_drvdata(dev); 183 160 unsigned long time = 0; 184 161 __le32 hw_time = 0; 185 162 186 - ds2404_read_memory(dev, 0x203, 4, (u8 *)&hw_time); 163 + ds2404_read_memory(chip, 0x203, 4, (u8 *)&hw_time); 187 164 time = le32_to_cpu(hw_time); 188 165 189 166 rtc_time64_to_tm(time, dt); ··· 168 193 169 194 static int ds2404_set_time(struct device *dev, struct rtc_time *dt) 170 195 { 196 + struct ds2404 *chip = dev_get_drvdata(dev); 171 197 u32 time = cpu_to_le32(rtc_tm_to_time64(dt)); 172 - ds2404_write_memory(dev, 0x203, 4, (u8 *)&time); 198 + ds2404_write_memory(chip, 0x203, 4, (u8 *)&time); 173 199 return 0; 174 200 } 175 201 ··· 181 205 182 206 static int rtc_probe(struct platform_device *pdev) 183 207 { 184 - struct ds2404_platform_data *pdata = dev_get_platdata(&pdev->dev); 185 208 struct ds2404 *chip; 186 209 int retval = -EBUSY; 187 210 ··· 188 213 if (!chip) 189 214 return -ENOMEM; 190 215 216 + chip->dev = &pdev->dev; 217 + 191 218 chip->rtc = devm_rtc_allocate_device(&pdev->dev); 192 219 if (IS_ERR(chip->rtc)) 193 220 return PTR_ERR(chip->rtc); 194 221 195 - retval = ds2404_gpio_map(chip, pdev, pdata); 222 + retval = ds2404_gpio_map(chip, pdev); 196 223 if (retval) 197 224 return retval; 198 - 199 - retval = devm_add_action_or_reset(&pdev->dev, ds2404_gpio_unmap, chip); 200 - if (retval) 201 - return retval; 202 - 203 - dev_info(&pdev->dev, "using GPIOs RST:%d, CLK:%d, DQ:%d\n", 204 - chip->gpio[DS2404_RST].gpio, chip->gpio[DS2404_CLK].gpio, 205 - chip->gpio[DS2404_DQ].gpio); 206 225 207 226 platform_set_drvdata(pdev, chip); 208 227 ··· 207 238 if (retval) 208 239 return retval; 209 240 210 - ds2404_enable_osc(&pdev->dev); 241 + ds2404_enable_osc(chip); 211 242 return 0; 212 243 } 213 244
+1 -4
drivers/rtc/rtc-fsl-ftm-alarm.c
··· 11 11 #include <linux/err.h> 12 12 #include <linux/interrupt.h> 13 13 #include <linux/io.h> 14 - #include <linux/of_address.h> 15 - #include <linux/of_irq.h> 16 14 #include <linux/platform_device.h> 17 - #include <linux/of.h> 18 - #include <linux/of_device.h> 15 + #include <linux/mod_devicetable.h> 19 16 #include <linux/module.h> 20 17 #include <linux/fsl/ftm.h> 21 18 #include <linux/rtc.h>
+120 -6
drivers/rtc/rtc-isl12022.c
··· 9 9 */ 10 10 11 11 #include <linux/bcd.h> 12 + #include <linux/bitfield.h> 13 + #include <linux/clk-provider.h> 12 14 #include <linux/err.h> 13 15 #include <linux/hwmon.h> 14 16 #include <linux/i2c.h> ··· 33 31 #define ISL12022_REG_SR 0x07 34 32 #define ISL12022_REG_INT 0x08 35 33 34 + #define ISL12022_REG_PWR_VBAT 0x0a 35 + 36 36 #define ISL12022_REG_BETA 0x0d 37 37 #define ISL12022_REG_TEMP_L 0x28 38 38 ··· 45 41 #define ISL12022_SR_LBAT75 (1 << 1) 46 42 47 43 #define ISL12022_INT_WRTC (1 << 6) 44 + #define ISL12022_INT_FO_MASK GENMASK(3, 0) 45 + #define ISL12022_INT_FO_OFF 0x0 46 + #define ISL12022_INT_FO_32K 0x1 47 + 48 + #define ISL12022_REG_VB85_MASK GENMASK(5, 3) 49 + #define ISL12022_REG_VB75_MASK GENMASK(2, 0) 48 50 49 51 #define ISL12022_BETA_TSE (1 << 7) 50 52 ··· 151 141 if (ret) 152 142 return ret; 153 143 154 - if (buf[ISL12022_REG_SR] & (ISL12022_SR_LBAT85 | ISL12022_SR_LBAT75)) { 155 - dev_warn(dev, 156 - "voltage dropped below %u%%, date and time is not reliable.\n", 157 - buf[ISL12022_REG_SR] & ISL12022_SR_LBAT85 ? 85 : 75); 158 - } 159 - 160 144 dev_dbg(dev, 161 145 "raw data is sec=%02x, min=%02x, hr=%02x, mday=%02x, mon=%02x, year=%02x, wday=%02x, sr=%02x, int=%02x", 162 146 buf[ISL12022_REG_SC], ··· 208 204 return regmap_bulk_write(regmap, ISL12022_REG_SC, buf, sizeof(buf)); 209 205 } 210 206 207 + static int isl12022_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 208 + { 209 + struct regmap *regmap = dev_get_drvdata(dev); 210 + u32 user, val; 211 + int ret; 212 + 213 + switch (cmd) { 214 + case RTC_VL_READ: 215 + ret = regmap_read(regmap, ISL12022_REG_SR, &val); 216 + if (ret) 217 + return ret; 218 + 219 + user = 0; 220 + if (val & ISL12022_SR_LBAT85) 221 + user |= RTC_VL_BACKUP_LOW; 222 + 223 + if (val & ISL12022_SR_LBAT75) 224 + user |= RTC_VL_BACKUP_EMPTY; 225 + 226 + return put_user(user, (u32 __user *)arg); 227 + 228 + default: 229 + return -ENOIOCTLCMD; 230 + } 231 + } 232 + 211 233 static const struct rtc_class_ops isl12022_rtc_ops = { 234 + .ioctl = isl12022_rtc_ioctl, 212 235 .read_time = isl12022_rtc_read_time, 213 236 .set_time = isl12022_rtc_set_time, 214 237 }; ··· 246 215 .use_single_write = true, 247 216 }; 248 217 218 + static int isl12022_register_clock(struct device *dev) 219 + { 220 + struct regmap *regmap = dev_get_drvdata(dev); 221 + struct clk_hw *hw; 222 + int ret; 223 + 224 + if (!device_property_present(dev, "#clock-cells")) { 225 + /* 226 + * Disabling the F_OUT pin reduces the power 227 + * consumption in battery mode by ~25%. 228 + */ 229 + regmap_update_bits(regmap, ISL12022_REG_INT, ISL12022_INT_FO_MASK, 230 + ISL12022_INT_FO_OFF); 231 + 232 + return 0; 233 + } 234 + 235 + if (!IS_ENABLED(CONFIG_COMMON_CLK)) 236 + return 0; 237 + 238 + /* 239 + * For now, only support a fixed clock of 32768Hz (the reset default). 240 + */ 241 + ret = regmap_update_bits(regmap, ISL12022_REG_INT, 242 + ISL12022_INT_FO_MASK, ISL12022_INT_FO_32K); 243 + if (ret) 244 + return ret; 245 + 246 + hw = devm_clk_hw_register_fixed_rate(dev, "isl12022", NULL, 0, 32768); 247 + if (IS_ERR(hw)) 248 + return PTR_ERR(hw); 249 + 250 + return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw); 251 + } 252 + 253 + static const u32 trip_levels[2][7] = { 254 + { 2125000, 2295000, 2550000, 2805000, 3060000, 4250000, 4675000 }, 255 + { 1875000, 2025000, 2250000, 2475000, 2700000, 3750000, 4125000 }, 256 + }; 257 + 258 + static void isl12022_set_trip_levels(struct device *dev) 259 + { 260 + struct regmap *regmap = dev_get_drvdata(dev); 261 + u32 levels[2] = {0, 0}; 262 + int ret, i, j, x[2]; 263 + u8 val, mask; 264 + 265 + device_property_read_u32_array(dev, "isil,battery-trip-levels-microvolt", 266 + levels, 2); 267 + 268 + for (i = 0; i < 2; i++) { 269 + for (j = 0; j < ARRAY_SIZE(trip_levels[i]) - 1; j++) { 270 + if (levels[i] <= trip_levels[i][j]) 271 + break; 272 + } 273 + x[i] = j; 274 + } 275 + 276 + val = FIELD_PREP(ISL12022_REG_VB85_MASK, x[0]) | 277 + FIELD_PREP(ISL12022_REG_VB75_MASK, x[1]); 278 + mask = ISL12022_REG_VB85_MASK | ISL12022_REG_VB75_MASK; 279 + 280 + ret = regmap_update_bits(regmap, ISL12022_REG_PWR_VBAT, mask, val); 281 + if (ret) 282 + dev_warn(dev, "unable to set battery alarm levels: %d\n", ret); 283 + 284 + /* 285 + * Force a write of the TSE bit in the BETA register, in order 286 + * to trigger an update of the LBAT75 and LBAT85 bits in the 287 + * status register. In battery backup mode, those bits have 288 + * another meaning, so without this, they may contain stale 289 + * values for up to a minute after power-on. 290 + */ 291 + regmap_write_bits(regmap, ISL12022_REG_BETA, 292 + ISL12022_BETA_TSE, ISL12022_BETA_TSE); 293 + } 294 + 249 295 static int isl12022_probe(struct i2c_client *client) 250 296 { 251 297 struct rtc_device *rtc; 252 298 struct regmap *regmap; 299 + int ret; 253 300 254 301 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 255 302 return -ENODEV; ··· 340 231 341 232 dev_set_drvdata(&client->dev, regmap); 342 233 234 + ret = isl12022_register_clock(&client->dev); 235 + if (ret) 236 + return ret; 237 + 238 + isl12022_set_trip_levels(&client->dev); 343 239 isl12022_hwmon_register(&client->dev); 344 240 345 241 rtc = devm_rtc_allocate_device(&client->dev);
+2 -3
drivers/rtc/rtc-isl12026.c
··· 11 11 #include <linux/mutex.h> 12 12 #include <linux/nvmem-provider.h> 13 13 #include <linux/of.h> 14 - #include <linux/of_device.h> 15 14 #include <linux/rtc.h> 16 15 #include <linux/slab.h> 17 16 ··· 428 429 } 429 430 } 430 431 431 - static int isl12026_probe_new(struct i2c_client *client) 432 + static int isl12026_probe(struct i2c_client *client) 432 433 { 433 434 struct isl12026 *priv; 434 435 int ret; ··· 489 490 .name = "rtc-isl12026", 490 491 .of_match_table = isl12026_dt_match, 491 492 }, 492 - .probe = isl12026_probe_new, 493 + .probe = isl12026_probe, 493 494 .remove = isl12026_remove, 494 495 }; 495 496
+5 -14
drivers/rtc/rtc-isl1208.c
··· 9 9 #include <linux/clk.h> 10 10 #include <linux/i2c.h> 11 11 #include <linux/module.h> 12 - #include <linux/of_device.h> 12 + #include <linux/of.h> 13 13 #include <linux/of_irq.h> 14 14 #include <linux/rtc.h> 15 15 ··· 188 188 static int isl1208_set_xtoscb(struct i2c_client *client, int sr, int xtosb_val) 189 189 { 190 190 /* Do nothing if bit is already set to desired value */ 191 - if ((sr & ISL1208_REG_SR_XTOSCB) == xtosb_val) 191 + if (!!(sr & ISL1208_REG_SR_XTOSCB) == xtosb_val) 192 192 return 0; 193 193 194 194 if (xtosb_val) ··· 862 862 i2c_set_clientdata(client, isl1208); 863 863 864 864 /* Determine which chip we have */ 865 - if (client->dev.of_node) { 866 - isl1208->config = of_device_get_match_data(&client->dev); 867 - if (!isl1208->config) 868 - return -ENODEV; 869 - } else { 870 - const struct i2c_device_id *id = i2c_match_id(isl1208_id, client); 871 - 872 - if (!id) 873 - return -ENODEV; 874 - isl1208->config = (struct isl1208_config *)id->driver_data; 875 - } 865 + isl1208->config = i2c_get_match_data(client); 866 + if (!isl1208->config) 867 + return -ENODEV; 876 868 877 869 rc = isl1208_clk_present(client, "xin"); 878 870 if (rc < 0) ··· 944 952 rc = isl1208_setup_irq(client, client->irq); 945 953 if (rc) 946 954 return rc; 947 - 948 955 } else { 949 956 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, isl1208->rtc->features); 950 957 }
+2 -2
drivers/rtc/rtc-jz4740.c
··· 11 11 #include <linux/iopoll.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/module.h> 14 - #include <linux/of_device.h> 14 + #include <linux/of.h> 15 15 #include <linux/platform_device.h> 16 16 #include <linux/pm_wakeirq.h> 17 17 #include <linux/property.h> ··· 349 349 if (!rtc) 350 350 return -ENOMEM; 351 351 352 - rtc->type = (enum jz4740_rtc_type)device_get_match_data(dev); 352 + rtc->type = (uintptr_t)device_get_match_data(dev); 353 353 354 354 irq = platform_get_irq(pdev, 0); 355 355 if (irq < 0)
+1 -2
drivers/rtc/rtc-lpc24xx.c
··· 9 9 #include <linux/clk.h> 10 10 #include <linux/io.h> 11 11 #include <linux/kernel.h> 12 + #include <linux/mod_devicetable.h> 12 13 #include <linux/module.h> 13 - #include <linux/of.h> 14 - #include <linux/of_device.h> 15 14 #include <linux/platform_device.h> 16 15 #include <linux/rtc.h> 17 16
+1 -1
drivers/rtc/rtc-m41t80.c
··· 17 17 #include <linux/init.h> 18 18 #include <linux/kernel.h> 19 19 #include <linux/module.h> 20 - #include <linux/of_device.h> 20 + #include <linux/of.h> 21 21 #include <linux/rtc.h> 22 22 #include <linux/slab.h> 23 23 #include <linux/mutex.h>
+8
drivers/rtc/rtc-m48t86.c
··· 11 11 */ 12 12 13 13 #include <linux/module.h> 14 + #include <linux/mod_devicetable.h> 14 15 #include <linux/rtc.h> 15 16 #include <linux/platform_device.h> 16 17 #include <linux/bcd.h> ··· 270 269 return 0; 271 270 } 272 271 272 + static const struct of_device_id m48t86_rtc_of_ids[] = { 273 + { .compatible = "st,m48t86" }, 274 + { /* sentinel */ } 275 + }; 276 + MODULE_DEVICE_TABLE(of, m48t86_rtc_of_ids); 277 + 273 278 static struct platform_driver m48t86_rtc_platform_driver = { 274 279 .driver = { 275 280 .name = "rtc-m48t86", 281 + .of_match_table = m48t86_rtc_of_ids, 276 282 }, 277 283 .probe = m48t86_rtc_probe, 278 284 };
+1 -3
drivers/rtc/rtc-mpc5121.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/rtc.h> 13 13 #include <linux/of.h> 14 - #include <linux/of_address.h> 15 - #include <linux/of_device.h> 16 14 #include <linux/of_irq.h> 17 - #include <linux/of_platform.h> 15 + #include <linux/platform_device.h> 18 16 #include <linux/io.h> 19 17 #include <linux/slab.h> 20 18
+1 -1
drivers/rtc/rtc-mt6397.c
··· 9 9 #include <linux/mfd/mt6397/core.h> 10 10 #include <linux/module.h> 11 11 #include <linux/mutex.h> 12 - #include <linux/of_device.h> 12 + #include <linux/of.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/regmap.h> 15 15 #include <linux/rtc.h>
+2 -2
drivers/rtc/rtc-mt7622.c
··· 7 7 8 8 #include <linux/clk.h> 9 9 #include <linux/interrupt.h> 10 + #include <linux/io.h> 11 + #include <linux/mod_devicetable.h> 10 12 #include <linux/module.h> 11 - #include <linux/of_address.h> 12 - #include <linux/of_device.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/rtc.h> 15 15
-1
drivers/rtc/rtc-mxc.c
··· 11 11 #include <linux/pm_wakeirq.h> 12 12 #include <linux/clk.h> 13 13 #include <linux/of.h> 14 - #include <linux/of_device.h> 15 14 16 15 #define RTC_INPUT_CLK_32768HZ (0x00 << 5) 17 16 #define RTC_INPUT_CLK_32000HZ (0x01 << 5)
+1 -1
drivers/rtc/rtc-nct3018y.c
··· 538 538 static struct i2c_driver nct3018y_driver = { 539 539 .driver = { 540 540 .name = "rtc-nct3018y", 541 - .of_match_table = of_match_ptr(nct3018y_of_match), 541 + .of_match_table = nct3018y_of_match, 542 542 }, 543 543 .probe = nct3018y_probe, 544 544 .id_table = nct3018y_id,
+4 -4
drivers/rtc/rtc-omap.c
··· 747 747 } 748 748 749 749 rtc->irq_timer = platform_get_irq(pdev, 0); 750 - if (rtc->irq_timer <= 0) 751 - return -ENOENT; 750 + if (rtc->irq_timer < 0) 751 + return rtc->irq_timer; 752 752 753 753 rtc->irq_alarm = platform_get_irq(pdev, 1); 754 - if (rtc->irq_alarm <= 0) 755 - return -ENOENT; 754 + if (rtc->irq_alarm < 0) 755 + return rtc->irq_alarm; 756 756 757 757 rtc->clk = devm_clk_get(&pdev->dev, "ext-clk"); 758 758 if (!IS_ERR(rtc->clk))
+682 -190
drivers/rtc/rtc-pcf2127.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - * An I2C and SPI driver for the NXP PCF2127/29 RTC 3 + * An I2C and SPI driver for the NXP PCF2127/29/31 RTC 4 4 * Copyright 2013 Til-Technologies 5 5 * 6 6 * Author: Renaud Cerrato <r.cerrato@til-technologies.fr> ··· 8 8 * Watchdog and tamper functions 9 9 * Author: Bruno Thomsen <bruno.thomsen@gmail.com> 10 10 * 11 + * PCF2131 support 12 + * Author: Hugo Villeneuve <hvilleneuve@dimonoff.com> 13 + * 11 14 * based on the other drivers in this same directory. 12 15 * 13 - * Datasheet: https://www.nxp.com/docs/en/data-sheet/PCF2127.pdf 16 + * Datasheets: https://www.nxp.com/docs/en/data-sheet/PCF2127.pdf 17 + * https://www.nxp.com/docs/en/data-sheet/PCF2131DS.pdf 14 18 */ 15 19 16 20 #include <linux/i2c.h> ··· 25 21 #include <linux/module.h> 26 22 #include <linux/of.h> 27 23 #include <linux/of_irq.h> 24 + #include <linux/of_device.h> 28 25 #include <linux/regmap.h> 29 26 #include <linux/watchdog.h> 30 27 ··· 33 28 #define PCF2127_REG_CTRL1 0x00 34 29 #define PCF2127_BIT_CTRL1_POR_OVRD BIT(3) 35 30 #define PCF2127_BIT_CTRL1_TSF1 BIT(4) 31 + #define PCF2127_BIT_CTRL1_STOP BIT(5) 36 32 /* Control register 2 */ 37 33 #define PCF2127_REG_CTRL2 0x01 38 34 #define PCF2127_BIT_CTRL2_AIE BIT(1) ··· 49 43 #define PCF2127_BIT_CTRL3_BF BIT(3) 50 44 #define PCF2127_BIT_CTRL3_BTSE BIT(4) 51 45 /* Time and date registers */ 52 - #define PCF2127_REG_SC 0x03 46 + #define PCF2127_REG_TIME_BASE 0x03 53 47 #define PCF2127_BIT_SC_OSF BIT(7) 54 - #define PCF2127_REG_MN 0x04 55 - #define PCF2127_REG_HR 0x05 56 - #define PCF2127_REG_DM 0x06 57 - #define PCF2127_REG_DW 0x07 58 - #define PCF2127_REG_MO 0x08 59 - #define PCF2127_REG_YR 0x09 60 48 /* Alarm registers */ 61 - #define PCF2127_REG_ALARM_SC 0x0A 62 - #define PCF2127_REG_ALARM_MN 0x0B 63 - #define PCF2127_REG_ALARM_HR 0x0C 64 - #define PCF2127_REG_ALARM_DM 0x0D 65 - #define PCF2127_REG_ALARM_DW 0x0E 49 + #define PCF2127_REG_ALARM_BASE 0x0A 66 50 #define PCF2127_BIT_ALARM_AE BIT(7) 67 51 /* CLKOUT control register */ 68 52 #define PCF2127_REG_CLKOUT 0x0f ··· 64 68 #define PCF2127_BIT_WD_CTL_CD0 BIT(6) 65 69 #define PCF2127_BIT_WD_CTL_CD1 BIT(7) 66 70 #define PCF2127_REG_WD_VAL 0x11 67 - /* Tamper timestamp registers */ 68 - #define PCF2127_REG_TS_CTRL 0x12 71 + /* Tamper timestamp1 registers */ 72 + #define PCF2127_REG_TS1_BASE 0x12 69 73 #define PCF2127_BIT_TS_CTRL_TSOFF BIT(6) 70 74 #define PCF2127_BIT_TS_CTRL_TSM BIT(7) 71 - #define PCF2127_REG_TS_SC 0x13 72 - #define PCF2127_REG_TS_MN 0x14 73 - #define PCF2127_REG_TS_HR 0x15 74 - #define PCF2127_REG_TS_DM 0x16 75 - #define PCF2127_REG_TS_MO 0x17 76 - #define PCF2127_REG_TS_YR 0x18 77 75 /* 78 76 * RAM registers 79 77 * PCF2127 has 512 bytes general-purpose static RAM (SRAM) that is 80 78 * battery backed and can survive a power outage. 81 - * PCF2129 doesn't have this feature. 79 + * PCF2129/31 doesn't have this feature. 82 80 */ 83 81 #define PCF2127_REG_RAM_ADDR_MSB 0x1A 84 82 #define PCF2127_REG_RAM_WRT_CMD 0x1C ··· 80 90 81 91 /* Watchdog timer value constants */ 82 92 #define PCF2127_WD_VAL_STOP 0 83 - #define PCF2127_WD_VAL_MIN 2 84 - #define PCF2127_WD_VAL_MAX 255 85 - #define PCF2127_WD_VAL_DEFAULT 60 93 + /* PCF2127/29 watchdog timer value constants */ 94 + #define PCF2127_WD_CLOCK_HZ_X1000 1000 /* 1Hz */ 95 + #define PCF2127_WD_MIN_HW_HEARTBEAT_MS 500 96 + /* PCF2131 watchdog timer value constants */ 97 + #define PCF2131_WD_CLOCK_HZ_X1000 250 /* 1/4Hz */ 98 + #define PCF2131_WD_MIN_HW_HEARTBEAT_MS 4000 99 + 100 + #define PCF2127_WD_DEFAULT_TIMEOUT_S 60 86 101 87 102 /* Mask for currently enabled interrupts */ 88 103 #define PCF2127_CTRL1_IRQ_MASK (PCF2127_BIT_CTRL1_TSF1) ··· 96 101 PCF2127_BIT_CTRL2_WDTF | \ 97 102 PCF2127_BIT_CTRL2_TSF2) 98 103 104 + #define PCF2127_MAX_TS_SUPPORTED 4 105 + 106 + /* Control register 4 */ 107 + #define PCF2131_REG_CTRL4 0x03 108 + #define PCF2131_BIT_CTRL4_TSF4 BIT(4) 109 + #define PCF2131_BIT_CTRL4_TSF3 BIT(5) 110 + #define PCF2131_BIT_CTRL4_TSF2 BIT(6) 111 + #define PCF2131_BIT_CTRL4_TSF1 BIT(7) 112 + /* Control register 5 */ 113 + #define PCF2131_REG_CTRL5 0x04 114 + #define PCF2131_BIT_CTRL5_TSIE4 BIT(4) 115 + #define PCF2131_BIT_CTRL5_TSIE3 BIT(5) 116 + #define PCF2131_BIT_CTRL5_TSIE2 BIT(6) 117 + #define PCF2131_BIT_CTRL5_TSIE1 BIT(7) 118 + /* Software reset register */ 119 + #define PCF2131_REG_SR_RESET 0x05 120 + #define PCF2131_SR_RESET_READ_PATTERN (BIT(2) | BIT(5)) 121 + #define PCF2131_SR_RESET_CPR_CMD (PCF2131_SR_RESET_READ_PATTERN | BIT(7)) 122 + /* Time and date registers */ 123 + #define PCF2131_REG_TIME_BASE 0x07 124 + /* Alarm registers */ 125 + #define PCF2131_REG_ALARM_BASE 0x0E 126 + /* CLKOUT control register */ 127 + #define PCF2131_REG_CLKOUT 0x13 128 + /* Watchdog registers */ 129 + #define PCF2131_REG_WD_CTL 0x35 130 + #define PCF2131_REG_WD_VAL 0x36 131 + /* Tamper timestamp1 registers */ 132 + #define PCF2131_REG_TS1_BASE 0x14 133 + /* Tamper timestamp2 registers */ 134 + #define PCF2131_REG_TS2_BASE 0x1B 135 + /* Tamper timestamp3 registers */ 136 + #define PCF2131_REG_TS3_BASE 0x22 137 + /* Tamper timestamp4 registers */ 138 + #define PCF2131_REG_TS4_BASE 0x29 139 + /* Interrupt mask registers */ 140 + #define PCF2131_REG_INT_A_MASK1 0x31 141 + #define PCF2131_REG_INT_A_MASK2 0x32 142 + #define PCF2131_REG_INT_B_MASK1 0x33 143 + #define PCF2131_REG_INT_B_MASK2 0x34 144 + #define PCF2131_BIT_INT_BLIE BIT(0) 145 + #define PCF2131_BIT_INT_BIE BIT(1) 146 + #define PCF2131_BIT_INT_AIE BIT(2) 147 + #define PCF2131_BIT_INT_WD_CD BIT(3) 148 + #define PCF2131_BIT_INT_SI BIT(4) 149 + #define PCF2131_BIT_INT_MI BIT(5) 150 + #define PCF2131_CTRL2_IRQ_MASK ( \ 151 + PCF2127_BIT_CTRL2_AF | \ 152 + PCF2127_BIT_CTRL2_WDTF) 153 + #define PCF2131_CTRL4_IRQ_MASK ( \ 154 + PCF2131_BIT_CTRL4_TSF4 | \ 155 + PCF2131_BIT_CTRL4_TSF3 | \ 156 + PCF2131_BIT_CTRL4_TSF2 | \ 157 + PCF2131_BIT_CTRL4_TSF1) 158 + 159 + enum pcf21xx_type { 160 + PCF2127, 161 + PCF2129, 162 + PCF2131, 163 + PCF21XX_LAST_ID 164 + }; 165 + 166 + struct pcf21xx_ts_config { 167 + u8 reg_base; /* Base register to read timestamp values. */ 168 + 169 + /* 170 + * If the TS input pin is driven to GND, an interrupt can be generated 171 + * (supported by all variants). 172 + */ 173 + u8 gnd_detect_reg; /* Interrupt control register address. */ 174 + u8 gnd_detect_bit; /* Interrupt bit. */ 175 + 176 + /* 177 + * If the TS input pin is driven to an intermediate level between GND 178 + * and supply, an interrupt can be generated (optional feature depending 179 + * on variant). 180 + */ 181 + u8 inter_detect_reg; /* Interrupt control register address. */ 182 + u8 inter_detect_bit; /* Interrupt bit. */ 183 + 184 + u8 ie_reg; /* Interrupt enable control register. */ 185 + u8 ie_bit; /* Interrupt enable bit. */ 186 + }; 187 + 188 + struct pcf21xx_config { 189 + int type; /* IC variant */ 190 + int max_register; 191 + unsigned int has_nvmem:1; 192 + unsigned int has_bit_wd_ctl_cd0:1; 193 + unsigned int wd_val_reg_readable:1; /* If watchdog value register can be read. */ 194 + unsigned int has_int_a_b:1; /* PCF2131 supports two interrupt outputs. */ 195 + u8 reg_time_base; /* Time/date base register. */ 196 + u8 regs_alarm_base; /* Alarm function base registers. */ 197 + u8 reg_wd_ctl; /* Watchdog control register. */ 198 + u8 reg_wd_val; /* Watchdog value register. */ 199 + u8 reg_clkout; /* Clkout register. */ 200 + int wdd_clock_hz_x1000; /* Watchdog clock in Hz multiplicated by 1000 */ 201 + int wdd_min_hw_heartbeat_ms; 202 + unsigned int ts_count; 203 + struct pcf21xx_ts_config ts[PCF2127_MAX_TS_SUPPORTED]; 204 + struct attribute_group attribute_group; 205 + }; 206 + 99 207 struct pcf2127 { 100 208 struct rtc_device *rtc; 101 209 struct watchdog_device wdd; 102 210 struct regmap *regmap; 103 - time64_t ts; 104 - bool ts_valid; 211 + const struct pcf21xx_config *cfg; 105 212 bool irq_enabled; 213 + time64_t ts[PCF2127_MAX_TS_SUPPORTED]; /* Timestamp values. */ 214 + bool ts_valid[PCF2127_MAX_TS_SUPPORTED]; /* Timestamp valid indication. */ 106 215 }; 107 216 108 217 /* ··· 216 117 static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm) 217 118 { 218 119 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 219 - unsigned char buf[10]; 120 + unsigned char buf[7]; 220 121 int ret; 221 122 222 123 /* 223 124 * Avoid reading CTRL2 register as it causes WD_VAL register 224 125 * value to reset to 0 which means watchdog is stopped. 225 126 */ 226 - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL3, 227 - (buf + PCF2127_REG_CTRL3), 228 - ARRAY_SIZE(buf) - PCF2127_REG_CTRL3); 127 + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->reg_time_base, 128 + buf, sizeof(buf)); 229 129 if (ret) { 230 130 dev_err(dev, "%s: read error\n", __func__); 231 131 return ret; 232 132 } 233 133 234 - if (buf[PCF2127_REG_CTRL3] & PCF2127_BIT_CTRL3_BLF) 235 - dev_info(dev, 236 - "low voltage detected, check/replace RTC battery.\n"); 237 - 238 134 /* Clock integrity is not guaranteed when OSF flag is set. */ 239 - if (buf[PCF2127_REG_SC] & PCF2127_BIT_SC_OSF) { 135 + if (buf[0] & PCF2127_BIT_SC_OSF) { 240 136 /* 241 137 * no need clear the flag here, 242 138 * it will be cleared once the new date is saved ··· 242 148 } 243 149 244 150 dev_dbg(dev, 245 - "%s: raw data is cr3=%02x, sec=%02x, min=%02x, hr=%02x, " 151 + "%s: raw data is sec=%02x, min=%02x, hr=%02x, " 246 152 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n", 247 - __func__, buf[PCF2127_REG_CTRL3], buf[PCF2127_REG_SC], 248 - buf[PCF2127_REG_MN], buf[PCF2127_REG_HR], 249 - buf[PCF2127_REG_DM], buf[PCF2127_REG_DW], 250 - buf[PCF2127_REG_MO], buf[PCF2127_REG_YR]); 153 + __func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); 251 154 252 - tm->tm_sec = bcd2bin(buf[PCF2127_REG_SC] & 0x7F); 253 - tm->tm_min = bcd2bin(buf[PCF2127_REG_MN] & 0x7F); 254 - tm->tm_hour = bcd2bin(buf[PCF2127_REG_HR] & 0x3F); /* rtc hr 0-23 */ 255 - tm->tm_mday = bcd2bin(buf[PCF2127_REG_DM] & 0x3F); 256 - tm->tm_wday = buf[PCF2127_REG_DW] & 0x07; 257 - tm->tm_mon = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ 258 - tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]); 155 + tm->tm_sec = bcd2bin(buf[0] & 0x7F); 156 + tm->tm_min = bcd2bin(buf[1] & 0x7F); 157 + tm->tm_hour = bcd2bin(buf[2] & 0x3F); 158 + tm->tm_mday = bcd2bin(buf[3] & 0x3F); 159 + tm->tm_wday = buf[4] & 0x07; 160 + tm->tm_mon = bcd2bin(buf[5] & 0x1F) - 1; 161 + tm->tm_year = bcd2bin(buf[6]); 259 162 tm->tm_year += 100; 260 163 261 164 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " ··· 289 198 /* year */ 290 199 buf[i++] = bin2bcd(tm->tm_year - 100); 291 200 292 - /* write register's data */ 293 - err = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_SC, buf, i); 201 + /* Write access to time registers: 202 + * PCF2127/29: no special action required. 203 + * PCF2131: requires setting the STOP and CPR bits. STOP bit needs to 204 + * be cleared after time registers are updated. 205 + */ 206 + if (pcf2127->cfg->type == PCF2131) { 207 + err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, 208 + PCF2127_BIT_CTRL1_STOP, 209 + PCF2127_BIT_CTRL1_STOP); 210 + if (err) { 211 + dev_dbg(dev, "setting STOP bit failed\n"); 212 + return err; 213 + } 214 + 215 + err = regmap_write(pcf2127->regmap, PCF2131_REG_SR_RESET, 216 + PCF2131_SR_RESET_CPR_CMD); 217 + if (err) { 218 + dev_dbg(dev, "sending CPR cmd failed\n"); 219 + return err; 220 + } 221 + } 222 + 223 + /* write time register's data */ 224 + err = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->reg_time_base, buf, i); 294 225 if (err) { 295 - dev_err(dev, 296 - "%s: err=%d", __func__, err); 226 + dev_dbg(dev, "%s: err=%d", __func__, err); 297 227 return err; 228 + } 229 + 230 + if (pcf2127->cfg->type == PCF2131) { 231 + /* Clear STOP bit (PCF2131 only) after write is completed. */ 232 + err = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, 233 + PCF2127_BIT_CTRL1_STOP, 0); 234 + if (err) { 235 + dev_dbg(dev, "clearing STOP bit failed\n"); 236 + return err; 237 + } 298 238 } 299 239 300 240 return 0; ··· 397 275 398 276 static int pcf2127_wdt_ping(struct watchdog_device *wdd) 399 277 { 278 + int wd_val; 400 279 struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); 401 280 402 - return regmap_write(pcf2127->regmap, PCF2127_REG_WD_VAL, wdd->timeout); 281 + /* 282 + * Compute counter value of WATCHDG_TIM_VAL to obtain desired period 283 + * in seconds, depending on the source clock frequency. 284 + */ 285 + wd_val = ((wdd->timeout * pcf2127->cfg->wdd_clock_hz_x1000) / 1000) + 1; 286 + 287 + return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, wd_val); 403 288 } 404 289 405 290 /* ··· 440 311 { 441 312 struct pcf2127 *pcf2127 = watchdog_get_drvdata(wdd); 442 313 443 - return regmap_write(pcf2127->regmap, PCF2127_REG_WD_VAL, 314 + return regmap_write(pcf2127->regmap, pcf2127->cfg->reg_wd_val, 444 315 PCF2127_WD_VAL_STOP); 445 316 } 446 317 ··· 468 339 .set_timeout = pcf2127_wdt_set_timeout, 469 340 }; 470 341 342 + /* 343 + * Compute watchdog period, t, in seconds, from the WATCHDG_TIM_VAL register 344 + * value, n, and the clock frequency, f1000, in Hz x 1000. 345 + * 346 + * The PCF2127/29 datasheet gives t as: 347 + * t = n / f 348 + * The PCF2131 datasheet gives t as: 349 + * t = (n - 1) / f 350 + * For both variants, the watchdog is triggered when the WATCHDG_TIM_VAL reaches 351 + * the value 1, and not zero. Consequently, the equation from the PCF2131 352 + * datasheet seems to be the correct one for both variants. 353 + */ 354 + static int pcf2127_watchdog_get_period(int n, int f1000) 355 + { 356 + return (1000 * (n - 1)) / f1000; 357 + } 358 + 471 359 static int pcf2127_watchdog_init(struct device *dev, struct pcf2127 *pcf2127) 472 360 { 473 - u32 wdd_timeout; 474 361 int ret; 475 362 476 363 if (!IS_ENABLED(CONFIG_WATCHDOG) || ··· 496 351 pcf2127->wdd.parent = dev; 497 352 pcf2127->wdd.info = &pcf2127_wdt_info; 498 353 pcf2127->wdd.ops = &pcf2127_watchdog_ops; 499 - pcf2127->wdd.min_timeout = PCF2127_WD_VAL_MIN; 500 - pcf2127->wdd.max_timeout = PCF2127_WD_VAL_MAX; 501 - pcf2127->wdd.timeout = PCF2127_WD_VAL_DEFAULT; 502 - pcf2127->wdd.min_hw_heartbeat_ms = 500; 354 + 355 + pcf2127->wdd.min_timeout = 356 + pcf2127_watchdog_get_period( 357 + 2, pcf2127->cfg->wdd_clock_hz_x1000); 358 + pcf2127->wdd.max_timeout = 359 + pcf2127_watchdog_get_period( 360 + 255, pcf2127->cfg->wdd_clock_hz_x1000); 361 + pcf2127->wdd.timeout = PCF2127_WD_DEFAULT_TIMEOUT_S; 362 + 363 + dev_dbg(dev, "%s clock = %d Hz / 1000\n", __func__, 364 + pcf2127->cfg->wdd_clock_hz_x1000); 365 + 366 + pcf2127->wdd.min_hw_heartbeat_ms = pcf2127->cfg->wdd_min_hw_heartbeat_ms; 503 367 pcf2127->wdd.status = WATCHDOG_NOWAYOUT_INIT_STATUS; 504 368 505 369 watchdog_set_drvdata(&pcf2127->wdd, pcf2127); 506 370 507 371 /* Test if watchdog timer is started by bootloader */ 508 - ret = regmap_read(pcf2127->regmap, PCF2127_REG_WD_VAL, &wdd_timeout); 509 - if (ret) 510 - return ret; 372 + if (pcf2127->cfg->wd_val_reg_readable) { 373 + u32 wdd_timeout; 511 374 512 - if (wdd_timeout) 513 - set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); 375 + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_wd_val, 376 + &wdd_timeout); 377 + if (ret) 378 + return ret; 379 + 380 + if (wdd_timeout) 381 + set_bit(WDOG_HW_RUNNING, &pcf2127->wdd.status); 382 + } 514 383 515 384 return devm_watchdog_register_device(dev, &pcf2127->wdd); 516 385 } ··· 545 386 if (ret) 546 387 return ret; 547 388 548 - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_ALARM_SC, buf, 549 - sizeof(buf)); 389 + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, 390 + buf, sizeof(buf)); 550 391 if (ret) 551 392 return ret; 552 393 ··· 596 437 buf[3] = bin2bcd(alrm->time.tm_mday); 597 438 buf[4] = PCF2127_BIT_ALARM_AE; /* Do not match on week day */ 598 439 599 - ret = regmap_bulk_write(pcf2127->regmap, PCF2127_REG_ALARM_SC, buf, 600 - sizeof(buf)); 440 + ret = regmap_bulk_write(pcf2127->regmap, pcf2127->cfg->regs_alarm_base, 441 + buf, sizeof(buf)); 601 442 if (ret) 602 443 return ret; 603 444 ··· 605 446 } 606 447 607 448 /* 608 - * This function reads ctrl2 register, caller is responsible for calling 609 - * pcf2127_wdt_active_ping() 449 + * This function reads one timestamp function data, caller is responsible for 450 + * calling pcf2127_wdt_active_ping() 610 451 */ 611 - static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts) 452 + static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts, 453 + int ts_id) 612 454 { 613 455 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 614 456 struct rtc_time tm; 615 457 int ret; 616 - unsigned char data[25]; 458 + unsigned char data[7]; 617 459 618 - ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL1, data, 619 - sizeof(data)); 460 + ret = regmap_bulk_read(pcf2127->regmap, pcf2127->cfg->ts[ts_id].reg_base, 461 + data, sizeof(data)); 620 462 if (ret) { 621 463 dev_err(dev, "%s: read error ret=%d\n", __func__, ret); 622 464 return ret; 623 465 } 624 466 625 467 dev_dbg(dev, 626 - "%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n", 627 - __func__, data[PCF2127_REG_CTRL1], data[PCF2127_REG_CTRL2], 628 - data[PCF2127_REG_CTRL3], data[PCF2127_REG_TS_SC], 629 - data[PCF2127_REG_TS_MN], data[PCF2127_REG_TS_HR], 630 - data[PCF2127_REG_TS_DM], data[PCF2127_REG_TS_MO], 631 - data[PCF2127_REG_TS_YR]); 468 + "%s: raw data is ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n", 469 + __func__, data[1], data[2], data[3], data[4], data[5], data[6]); 632 470 633 - tm.tm_sec = bcd2bin(data[PCF2127_REG_TS_SC] & 0x7F); 634 - tm.tm_min = bcd2bin(data[PCF2127_REG_TS_MN] & 0x7F); 635 - tm.tm_hour = bcd2bin(data[PCF2127_REG_TS_HR] & 0x3F); 636 - tm.tm_mday = bcd2bin(data[PCF2127_REG_TS_DM] & 0x3F); 471 + tm.tm_sec = bcd2bin(data[1] & 0x7F); 472 + tm.tm_min = bcd2bin(data[2] & 0x7F); 473 + tm.tm_hour = bcd2bin(data[3] & 0x3F); 474 + tm.tm_mday = bcd2bin(data[4] & 0x3F); 637 475 /* TS_MO register (month) value range: 1-12 */ 638 - tm.tm_mon = bcd2bin(data[PCF2127_REG_TS_MO] & 0x1F) - 1; 639 - tm.tm_year = bcd2bin(data[PCF2127_REG_TS_YR]); 476 + tm.tm_mon = bcd2bin(data[5] & 0x1F) - 1; 477 + tm.tm_year = bcd2bin(data[6]); 640 478 if (tm.tm_year < 70) 641 479 tm.tm_year += 100; /* assume we are in 1970...2069 */ 642 480 ··· 647 491 return 0; 648 492 }; 649 493 650 - static void pcf2127_rtc_ts_snapshot(struct device *dev) 494 + static void pcf2127_rtc_ts_snapshot(struct device *dev, int ts_id) 651 495 { 652 496 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 653 497 int ret; 654 498 655 - /* Let userspace read the first timestamp */ 656 - if (pcf2127->ts_valid) 499 + if (ts_id >= pcf2127->cfg->ts_count) 657 500 return; 658 501 659 - ret = pcf2127_rtc_ts_read(dev, &pcf2127->ts); 502 + /* Let userspace read the first timestamp */ 503 + if (pcf2127->ts_valid[ts_id]) 504 + return; 505 + 506 + ret = pcf2127_rtc_ts_read(dev, &pcf2127->ts[ts_id], ts_id); 660 507 if (!ret) 661 - pcf2127->ts_valid = true; 508 + pcf2127->ts_valid[ts_id] = true; 662 509 } 663 510 664 511 static irqreturn_t pcf2127_rtc_irq(int irq, void *dev) 665 512 { 666 513 struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 667 - unsigned int ctrl1, ctrl2; 514 + unsigned int ctrl2; 668 515 int ret = 0; 669 - 670 - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); 671 - if (ret) 672 - return IRQ_NONE; 673 516 674 517 ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); 675 518 if (ret) 676 519 return IRQ_NONE; 677 520 678 - if (!(ctrl1 & PCF2127_CTRL1_IRQ_MASK || ctrl2 & PCF2127_CTRL2_IRQ_MASK)) 679 - return IRQ_NONE; 521 + if (pcf2127->cfg->ts_count == 1) { 522 + /* PCF2127/29 */ 523 + unsigned int ctrl1; 680 524 681 - if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) 682 - pcf2127_rtc_ts_snapshot(dev); 525 + ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); 526 + if (ret) 527 + return IRQ_NONE; 683 528 684 - if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) 685 - regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, 686 - ctrl1 & ~PCF2127_CTRL1_IRQ_MASK); 529 + if (!(ctrl1 & PCF2127_CTRL1_IRQ_MASK || ctrl2 & PCF2127_CTRL2_IRQ_MASK)) 530 + return IRQ_NONE; 687 531 688 - if (ctrl2 & PCF2127_CTRL2_IRQ_MASK) 689 - regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, 690 - ctrl2 & ~PCF2127_CTRL2_IRQ_MASK); 532 + if (ctrl1 & PCF2127_BIT_CTRL1_TSF1 || ctrl2 & PCF2127_BIT_CTRL2_TSF2) 533 + pcf2127_rtc_ts_snapshot(dev, 0); 534 + 535 + if (ctrl1 & PCF2127_CTRL1_IRQ_MASK) 536 + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL1, 537 + ctrl1 & ~PCF2127_CTRL1_IRQ_MASK); 538 + 539 + if (ctrl2 & PCF2127_CTRL2_IRQ_MASK) 540 + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, 541 + ctrl2 & ~PCF2127_CTRL2_IRQ_MASK); 542 + } else { 543 + /* PCF2131. */ 544 + unsigned int ctrl4; 545 + 546 + ret = regmap_read(pcf2127->regmap, PCF2131_REG_CTRL4, &ctrl4); 547 + if (ret) 548 + return IRQ_NONE; 549 + 550 + if (!(ctrl4 & PCF2131_CTRL4_IRQ_MASK || ctrl2 & PCF2131_CTRL2_IRQ_MASK)) 551 + return IRQ_NONE; 552 + 553 + if (ctrl4 & PCF2131_CTRL4_IRQ_MASK) { 554 + int i; 555 + int tsf_bit = PCF2131_BIT_CTRL4_TSF1; /* Start at bit 7. */ 556 + 557 + for (i = 0; i < pcf2127->cfg->ts_count; i++) { 558 + if (ctrl4 & tsf_bit) 559 + pcf2127_rtc_ts_snapshot(dev, i); 560 + 561 + tsf_bit = tsf_bit >> 1; 562 + } 563 + 564 + regmap_write(pcf2127->regmap, PCF2131_REG_CTRL4, 565 + ctrl4 & ~PCF2131_CTRL4_IRQ_MASK); 566 + } 567 + 568 + if (ctrl2 & PCF2131_CTRL2_IRQ_MASK) 569 + regmap_write(pcf2127->regmap, PCF2127_REG_CTRL2, 570 + ctrl2 & ~PCF2131_CTRL2_IRQ_MASK); 571 + } 691 572 692 573 if (ctrl2 & PCF2127_BIT_CTRL2_AF) 693 574 rtc_update_irq(pcf2127->rtc, 1, RTC_IRQF | RTC_AF); ··· 745 552 746 553 /* sysfs interface */ 747 554 748 - static ssize_t timestamp0_store(struct device *dev, 749 - struct device_attribute *attr, 750 - const char *buf, size_t count) 555 + static ssize_t timestamp_store(struct device *dev, 556 + struct device_attribute *attr, 557 + const char *buf, size_t count, int ts_id) 751 558 { 752 559 struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); 753 560 int ret; 754 561 562 + if (ts_id >= pcf2127->cfg->ts_count) 563 + return 0; 564 + 755 565 if (pcf2127->irq_enabled) { 756 - pcf2127->ts_valid = false; 566 + pcf2127->ts_valid[ts_id] = false; 757 567 } else { 758 - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL1, 759 - PCF2127_BIT_CTRL1_TSF1, 0); 568 + /* Always clear GND interrupt bit. */ 569 + ret = regmap_update_bits(pcf2127->regmap, 570 + pcf2127->cfg->ts[ts_id].gnd_detect_reg, 571 + pcf2127->cfg->ts[ts_id].gnd_detect_bit, 572 + 0); 573 + 760 574 if (ret) { 761 - dev_err(dev, "%s: update ctrl1 ret=%d\n", __func__, ret); 575 + dev_err(dev, "%s: update TS gnd detect ret=%d\n", __func__, ret); 762 576 return ret; 763 577 } 764 578 765 - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, 766 - PCF2127_BIT_CTRL2_TSF2, 0); 767 - if (ret) { 768 - dev_err(dev, "%s: update ctrl2 ret=%d\n", __func__, ret); 769 - return ret; 579 + if (pcf2127->cfg->ts[ts_id].inter_detect_bit) { 580 + /* Clear intermediate level interrupt bit if supported. */ 581 + ret = regmap_update_bits(pcf2127->regmap, 582 + pcf2127->cfg->ts[ts_id].inter_detect_reg, 583 + pcf2127->cfg->ts[ts_id].inter_detect_bit, 584 + 0); 585 + if (ret) { 586 + dev_err(dev, "%s: update TS intermediate level detect ret=%d\n", 587 + __func__, ret); 588 + return ret; 589 + } 770 590 } 771 591 772 592 ret = pcf2127_wdt_active_ping(&pcf2127->wdd); ··· 788 582 } 789 583 790 584 return count; 585 + } 586 + 587 + static ssize_t timestamp0_store(struct device *dev, 588 + struct device_attribute *attr, 589 + const char *buf, size_t count) 590 + { 591 + return timestamp_store(dev, attr, buf, count, 0); 791 592 }; 792 593 793 - static ssize_t timestamp0_show(struct device *dev, 794 - struct device_attribute *attr, char *buf) 594 + static ssize_t timestamp1_store(struct device *dev, 595 + struct device_attribute *attr, 596 + const char *buf, size_t count) 597 + { 598 + return timestamp_store(dev, attr, buf, count, 1); 599 + }; 600 + 601 + static ssize_t timestamp2_store(struct device *dev, 602 + struct device_attribute *attr, 603 + const char *buf, size_t count) 604 + { 605 + return timestamp_store(dev, attr, buf, count, 2); 606 + }; 607 + 608 + static ssize_t timestamp3_store(struct device *dev, 609 + struct device_attribute *attr, 610 + const char *buf, size_t count) 611 + { 612 + return timestamp_store(dev, attr, buf, count, 3); 613 + }; 614 + 615 + static ssize_t timestamp_show(struct device *dev, 616 + struct device_attribute *attr, char *buf, 617 + int ts_id) 795 618 { 796 619 struct pcf2127 *pcf2127 = dev_get_drvdata(dev->parent); 797 - unsigned int ctrl1, ctrl2; 798 620 int ret; 799 621 time64_t ts; 800 622 623 + if (ts_id >= pcf2127->cfg->ts_count) 624 + return 0; 625 + 801 626 if (pcf2127->irq_enabled) { 802 - if (!pcf2127->ts_valid) 627 + if (!pcf2127->ts_valid[ts_id]) 803 628 return 0; 804 - ts = pcf2127->ts; 629 + ts = pcf2127->ts[ts_id]; 805 630 } else { 806 - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL1, &ctrl1); 631 + u8 valid_low = 0; 632 + u8 valid_inter = 0; 633 + unsigned int ctrl; 634 + 635 + /* Check if TS input pin is driven to GND, supported by all 636 + * variants. 637 + */ 638 + ret = regmap_read(pcf2127->regmap, 639 + pcf2127->cfg->ts[ts_id].gnd_detect_reg, 640 + &ctrl); 807 641 if (ret) 808 642 return 0; 809 643 810 - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CTRL2, &ctrl2); 811 - if (ret) 644 + valid_low = ctrl & pcf2127->cfg->ts[ts_id].gnd_detect_bit; 645 + 646 + if (pcf2127->cfg->ts[ts_id].inter_detect_bit) { 647 + /* Check if TS input pin is driven to intermediate level 648 + * between GND and supply, if supported by variant. 649 + */ 650 + ret = regmap_read(pcf2127->regmap, 651 + pcf2127->cfg->ts[ts_id].inter_detect_reg, 652 + &ctrl); 653 + if (ret) 654 + return 0; 655 + 656 + valid_inter = ctrl & pcf2127->cfg->ts[ts_id].inter_detect_bit; 657 + } 658 + 659 + if (!valid_low && !valid_inter) 812 660 return 0; 813 661 814 - if (!(ctrl1 & PCF2127_BIT_CTRL1_TSF1) && 815 - !(ctrl2 & PCF2127_BIT_CTRL2_TSF2)) 816 - return 0; 817 - 818 - ret = pcf2127_rtc_ts_read(dev->parent, &ts); 662 + ret = pcf2127_rtc_ts_read(dev->parent, &ts, ts_id); 819 663 if (ret) 820 664 return 0; 821 665 ··· 874 618 return ret; 875 619 } 876 620 return sprintf(buf, "%llu\n", (unsigned long long)ts); 621 + } 622 + 623 + static ssize_t timestamp0_show(struct device *dev, 624 + struct device_attribute *attr, char *buf) 625 + { 626 + return timestamp_show(dev, attr, buf, 0); 627 + }; 628 + 629 + static ssize_t timestamp1_show(struct device *dev, 630 + struct device_attribute *attr, char *buf) 631 + { 632 + return timestamp_show(dev, attr, buf, 1); 633 + }; 634 + 635 + static ssize_t timestamp2_show(struct device *dev, 636 + struct device_attribute *attr, char *buf) 637 + { 638 + return timestamp_show(dev, attr, buf, 2); 639 + }; 640 + 641 + static ssize_t timestamp3_show(struct device *dev, 642 + struct device_attribute *attr, char *buf) 643 + { 644 + return timestamp_show(dev, attr, buf, 3); 877 645 }; 878 646 879 647 static DEVICE_ATTR_RW(timestamp0); 648 + static DEVICE_ATTR_RW(timestamp1); 649 + static DEVICE_ATTR_RW(timestamp2); 650 + static DEVICE_ATTR_RW(timestamp3); 880 651 881 652 static struct attribute *pcf2127_attrs[] = { 882 653 &dev_attr_timestamp0.attr, 883 654 NULL 884 655 }; 885 656 886 - static const struct attribute_group pcf2127_attr_group = { 887 - .attrs = pcf2127_attrs, 657 + static struct attribute *pcf2131_attrs[] = { 658 + &dev_attr_timestamp0.attr, 659 + &dev_attr_timestamp1.attr, 660 + &dev_attr_timestamp2.attr, 661 + &dev_attr_timestamp3.attr, 662 + NULL 888 663 }; 889 664 665 + static struct pcf21xx_config pcf21xx_cfg[] = { 666 + [PCF2127] = { 667 + .type = PCF2127, 668 + .max_register = 0x1d, 669 + .has_nvmem = 1, 670 + .has_bit_wd_ctl_cd0 = 1, 671 + .wd_val_reg_readable = 1, 672 + .has_int_a_b = 0, 673 + .reg_time_base = PCF2127_REG_TIME_BASE, 674 + .regs_alarm_base = PCF2127_REG_ALARM_BASE, 675 + .reg_wd_ctl = PCF2127_REG_WD_CTL, 676 + .reg_wd_val = PCF2127_REG_WD_VAL, 677 + .reg_clkout = PCF2127_REG_CLKOUT, 678 + .wdd_clock_hz_x1000 = PCF2127_WD_CLOCK_HZ_X1000, 679 + .wdd_min_hw_heartbeat_ms = PCF2127_WD_MIN_HW_HEARTBEAT_MS, 680 + .ts_count = 1, 681 + .ts[0] = { 682 + .reg_base = PCF2127_REG_TS1_BASE, 683 + .gnd_detect_reg = PCF2127_REG_CTRL1, 684 + .gnd_detect_bit = PCF2127_BIT_CTRL1_TSF1, 685 + .inter_detect_reg = PCF2127_REG_CTRL2, 686 + .inter_detect_bit = PCF2127_BIT_CTRL2_TSF2, 687 + .ie_reg = PCF2127_REG_CTRL2, 688 + .ie_bit = PCF2127_BIT_CTRL2_TSIE, 689 + }, 690 + .attribute_group = { 691 + .attrs = pcf2127_attrs, 692 + }, 693 + }, 694 + [PCF2129] = { 695 + .type = PCF2129, 696 + .max_register = 0x19, 697 + .has_nvmem = 0, 698 + .has_bit_wd_ctl_cd0 = 0, 699 + .wd_val_reg_readable = 1, 700 + .has_int_a_b = 0, 701 + .reg_time_base = PCF2127_REG_TIME_BASE, 702 + .regs_alarm_base = PCF2127_REG_ALARM_BASE, 703 + .reg_wd_ctl = PCF2127_REG_WD_CTL, 704 + .reg_wd_val = PCF2127_REG_WD_VAL, 705 + .reg_clkout = PCF2127_REG_CLKOUT, 706 + .wdd_clock_hz_x1000 = PCF2127_WD_CLOCK_HZ_X1000, 707 + .wdd_min_hw_heartbeat_ms = PCF2127_WD_MIN_HW_HEARTBEAT_MS, 708 + .ts_count = 1, 709 + .ts[0] = { 710 + .reg_base = PCF2127_REG_TS1_BASE, 711 + .gnd_detect_reg = PCF2127_REG_CTRL1, 712 + .gnd_detect_bit = PCF2127_BIT_CTRL1_TSF1, 713 + .inter_detect_reg = PCF2127_REG_CTRL2, 714 + .inter_detect_bit = PCF2127_BIT_CTRL2_TSF2, 715 + .ie_reg = PCF2127_REG_CTRL2, 716 + .ie_bit = PCF2127_BIT_CTRL2_TSIE, 717 + }, 718 + .attribute_group = { 719 + .attrs = pcf2127_attrs, 720 + }, 721 + }, 722 + [PCF2131] = { 723 + .type = PCF2131, 724 + .max_register = 0x36, 725 + .has_nvmem = 0, 726 + .has_bit_wd_ctl_cd0 = 0, 727 + .wd_val_reg_readable = 0, 728 + .has_int_a_b = 1, 729 + .reg_time_base = PCF2131_REG_TIME_BASE, 730 + .regs_alarm_base = PCF2131_REG_ALARM_BASE, 731 + .reg_wd_ctl = PCF2131_REG_WD_CTL, 732 + .reg_wd_val = PCF2131_REG_WD_VAL, 733 + .reg_clkout = PCF2131_REG_CLKOUT, 734 + .wdd_clock_hz_x1000 = PCF2131_WD_CLOCK_HZ_X1000, 735 + .wdd_min_hw_heartbeat_ms = PCF2131_WD_MIN_HW_HEARTBEAT_MS, 736 + .ts_count = 4, 737 + .ts[0] = { 738 + .reg_base = PCF2131_REG_TS1_BASE, 739 + .gnd_detect_reg = PCF2131_REG_CTRL4, 740 + .gnd_detect_bit = PCF2131_BIT_CTRL4_TSF1, 741 + .inter_detect_bit = 0, 742 + .ie_reg = PCF2131_REG_CTRL5, 743 + .ie_bit = PCF2131_BIT_CTRL5_TSIE1, 744 + }, 745 + .ts[1] = { 746 + .reg_base = PCF2131_REG_TS2_BASE, 747 + .gnd_detect_reg = PCF2131_REG_CTRL4, 748 + .gnd_detect_bit = PCF2131_BIT_CTRL4_TSF2, 749 + .inter_detect_bit = 0, 750 + .ie_reg = PCF2131_REG_CTRL5, 751 + .ie_bit = PCF2131_BIT_CTRL5_TSIE2, 752 + }, 753 + .ts[2] = { 754 + .reg_base = PCF2131_REG_TS3_BASE, 755 + .gnd_detect_reg = PCF2131_REG_CTRL4, 756 + .gnd_detect_bit = PCF2131_BIT_CTRL4_TSF3, 757 + .inter_detect_bit = 0, 758 + .ie_reg = PCF2131_REG_CTRL5, 759 + .ie_bit = PCF2131_BIT_CTRL5_TSIE3, 760 + }, 761 + .ts[3] = { 762 + .reg_base = PCF2131_REG_TS4_BASE, 763 + .gnd_detect_reg = PCF2131_REG_CTRL4, 764 + .gnd_detect_bit = PCF2131_BIT_CTRL4_TSF4, 765 + .inter_detect_bit = 0, 766 + .ie_reg = PCF2131_REG_CTRL5, 767 + .ie_bit = PCF2131_BIT_CTRL5_TSIE4, 768 + }, 769 + .attribute_group = { 770 + .attrs = pcf2131_attrs, 771 + }, 772 + }, 773 + }; 774 + 775 + /* 776 + * Enable timestamp function and corresponding interrupt(s). 777 + */ 778 + static int pcf2127_enable_ts(struct device *dev, int ts_id) 779 + { 780 + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 781 + int ret; 782 + 783 + if (ts_id >= pcf2127->cfg->ts_count) { 784 + dev_err(dev, "%s: invalid tamper detection ID (%d)\n", 785 + __func__, ts_id); 786 + return -EINVAL; 787 + } 788 + 789 + /* Enable timestamp function. */ 790 + ret = regmap_update_bits(pcf2127->regmap, 791 + pcf2127->cfg->ts[ts_id].reg_base, 792 + PCF2127_BIT_TS_CTRL_TSOFF | 793 + PCF2127_BIT_TS_CTRL_TSM, 794 + PCF2127_BIT_TS_CTRL_TSM); 795 + if (ret) { 796 + dev_err(dev, "%s: tamper detection config (ts%d_ctrl) failed\n", 797 + __func__, ts_id); 798 + return ret; 799 + } 800 + 801 + /* 802 + * Enable interrupt generation when TSF timestamp flag is set. 803 + * Interrupt signals are open-drain outputs and can be left floating if 804 + * unused. 805 + */ 806 + ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->ts[ts_id].ie_reg, 807 + pcf2127->cfg->ts[ts_id].ie_bit, 808 + pcf2127->cfg->ts[ts_id].ie_bit); 809 + if (ret) { 810 + dev_err(dev, "%s: tamper detection TSIE%d config failed\n", 811 + __func__, ts_id); 812 + return ret; 813 + } 814 + 815 + return ret; 816 + } 817 + 818 + /* Route all interrupt sources to INT A pin. */ 819 + static int pcf2127_configure_interrupt_pins(struct device *dev) 820 + { 821 + struct pcf2127 *pcf2127 = dev_get_drvdata(dev); 822 + int ret; 823 + 824 + /* Mask bits need to be cleared to enable corresponding 825 + * interrupt source. 826 + */ 827 + ret = regmap_write(pcf2127->regmap, 828 + PCF2131_REG_INT_A_MASK1, 0); 829 + if (ret) 830 + return ret; 831 + 832 + ret = regmap_write(pcf2127->regmap, 833 + PCF2131_REG_INT_A_MASK2, 0); 834 + if (ret) 835 + return ret; 836 + 837 + return ret; 838 + } 839 + 890 840 static int pcf2127_probe(struct device *dev, struct regmap *regmap, 891 - int alarm_irq, const char *name, bool is_pcf2127) 841 + int alarm_irq, const struct pcf21xx_config *config) 892 842 { 893 843 struct pcf2127 *pcf2127; 894 844 int ret = 0; ··· 1107 645 return -ENOMEM; 1108 646 1109 647 pcf2127->regmap = regmap; 648 + pcf2127->cfg = config; 1110 649 1111 650 dev_set_drvdata(dev, pcf2127); 1112 651 ··· 1119 656 pcf2127->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 1120 657 pcf2127->rtc->range_max = RTC_TIMESTAMP_END_2099; 1121 658 pcf2127->rtc->set_start_time = true; /* Sets actual start to 1970 */ 1122 - set_bit(RTC_FEATURE_ALARM_RES_2S, pcf2127->rtc->features); 1123 - clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf2127->rtc->features); 659 + 660 + /* 661 + * PCF2127/29 do not work correctly when setting alarms at 1s intervals. 662 + * PCF2131 is ok. 663 + */ 664 + if (pcf2127->cfg->type == PCF2127 || pcf2127->cfg->type == PCF2129) { 665 + set_bit(RTC_FEATURE_ALARM_RES_2S, pcf2127->rtc->features); 666 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, pcf2127->rtc->features); 667 + } 668 + 1124 669 clear_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); 1125 670 1126 671 if (alarm_irq > 0) { ··· 1159 688 set_bit(RTC_FEATURE_ALARM, pcf2127->rtc->features); 1160 689 } 1161 690 1162 - if (is_pcf2127) { 691 + if (pcf2127->cfg->has_int_a_b) { 692 + /* Configure int A/B pins, independently of alarm_irq. */ 693 + ret = pcf2127_configure_interrupt_pins(dev); 694 + if (ret) { 695 + dev_err(dev, "failed to configure interrupt pins\n"); 696 + return ret; 697 + } 698 + } 699 + 700 + if (pcf2127->cfg->has_nvmem) { 1163 701 struct nvmem_config nvmem_cfg = { 1164 702 .priv = pcf2127, 1165 703 .reg_read = pcf2127_nvmem_read, ··· 1183 703 * The "Power-On Reset Override" facility prevents the RTC to do a reset 1184 704 * after power on. For normal operation the PORO must be disabled. 1185 705 */ 1186 - regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1, 706 + ret = regmap_clear_bits(pcf2127->regmap, PCF2127_REG_CTRL1, 1187 707 PCF2127_BIT_CTRL1_POR_OVRD); 708 + if (ret < 0) 709 + return ret; 1188 710 1189 - ret = regmap_read(pcf2127->regmap, PCF2127_REG_CLKOUT, &val); 711 + ret = regmap_read(pcf2127->regmap, pcf2127->cfg->reg_clkout, &val); 1190 712 if (ret < 0) 1191 713 return ret; 1192 714 1193 715 if (!(val & PCF2127_BIT_CLKOUT_OTPR)) { 1194 - ret = regmap_set_bits(pcf2127->regmap, PCF2127_REG_CLKOUT, 716 + ret = regmap_set_bits(pcf2127->regmap, pcf2127->cfg->reg_clkout, 1195 717 PCF2127_BIT_CLKOUT_OTPR); 1196 718 if (ret < 0) 1197 719 return ret; ··· 1203 721 1204 722 /* 1205 723 * Watchdog timer enabled and reset pin /RST activated when timed out. 1206 - * Select 1Hz clock source for watchdog timer. 724 + * Select 1Hz clock source for watchdog timer (1/4Hz for PCF2131). 1207 725 * Note: Countdown timer disabled and not available. 1208 - * For pca2129, pcf2129, only bit[7] is for Symbol WD_CD 726 + * For pca2129, pcf2129 and pcf2131, only bit[7] is for Symbol WD_CD 1209 727 * of register watchdg_tim_ctl. The bit[6] is labeled 1210 728 * as T. Bits labeled as T must always be written with 1211 729 * logic 0. 1212 730 */ 1213 - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_WD_CTL, 731 + ret = regmap_update_bits(pcf2127->regmap, pcf2127->cfg->reg_wd_ctl, 1214 732 PCF2127_BIT_WD_CTL_CD1 | 1215 733 PCF2127_BIT_WD_CTL_CD0 | 1216 734 PCF2127_BIT_WD_CTL_TF1 | 1217 735 PCF2127_BIT_WD_CTL_TF0, 1218 736 PCF2127_BIT_WD_CTL_CD1 | 1219 - (is_pcf2127 ? PCF2127_BIT_WD_CTL_CD0 : 0) | 737 + (pcf2127->cfg->has_bit_wd_ctl_cd0 ? PCF2127_BIT_WD_CTL_CD0 : 0) | 1220 738 PCF2127_BIT_WD_CTL_TF1); 1221 739 if (ret) { 1222 740 dev_err(dev, "%s: watchdog config (wd_ctl) failed\n", __func__); ··· 1242 760 } 1243 761 1244 762 /* 1245 - * Enable timestamp function and store timestamp of first trigger 1246 - * event until TSF1 and TSF2 interrupt flags are cleared. 763 + * Enable timestamp functions 1 to 4. 1247 764 */ 1248 - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_TS_CTRL, 1249 - PCF2127_BIT_TS_CTRL_TSOFF | 1250 - PCF2127_BIT_TS_CTRL_TSM, 1251 - PCF2127_BIT_TS_CTRL_TSM); 1252 - if (ret) { 1253 - dev_err(dev, "%s: tamper detection config (ts_ctrl) failed\n", 1254 - __func__); 1255 - return ret; 765 + for (int i = 0; i < pcf2127->cfg->ts_count; i++) { 766 + ret = pcf2127_enable_ts(dev, i); 767 + if (ret) 768 + return ret; 1256 769 } 1257 770 1258 - /* 1259 - * Enable interrupt generation when TSF1 or TSF2 timestamp flags 1260 - * are set. Interrupt signal is an open-drain output and can be 1261 - * left floating if unused. 1262 - */ 1263 - ret = regmap_update_bits(pcf2127->regmap, PCF2127_REG_CTRL2, 1264 - PCF2127_BIT_CTRL2_TSIE, 1265 - PCF2127_BIT_CTRL2_TSIE); 1266 - if (ret) { 1267 - dev_err(dev, "%s: tamper detection config (ctrl2) failed\n", 1268 - __func__); 1269 - return ret; 1270 - } 1271 - 1272 - ret = rtc_add_group(pcf2127->rtc, &pcf2127_attr_group); 771 + ret = rtc_add_group(pcf2127->rtc, &pcf2127->cfg->attribute_group); 1273 772 if (ret) { 1274 773 dev_err(dev, "%s: tamper sysfs registering failed\n", 1275 774 __func__); ··· 1262 799 1263 800 #ifdef CONFIG_OF 1264 801 static const struct of_device_id pcf2127_of_match[] = { 1265 - { .compatible = "nxp,pcf2127" }, 1266 - { .compatible = "nxp,pcf2129" }, 1267 - { .compatible = "nxp,pca2129" }, 802 + { .compatible = "nxp,pcf2127", .data = &pcf21xx_cfg[PCF2127] }, 803 + { .compatible = "nxp,pcf2129", .data = &pcf21xx_cfg[PCF2129] }, 804 + { .compatible = "nxp,pca2129", .data = &pcf21xx_cfg[PCF2129] }, 805 + { .compatible = "nxp,pcf2131", .data = &pcf21xx_cfg[PCF2131] }, 1268 806 {} 1269 807 }; 1270 808 MODULE_DEVICE_TABLE(of, pcf2127_of_match); ··· 1350 886 static struct i2c_driver pcf2127_i2c_driver; 1351 887 1352 888 static const struct i2c_device_id pcf2127_i2c_id[] = { 1353 - { "pcf2127", 1 }, 1354 - { "pcf2129", 0 }, 1355 - { "pca2129", 0 }, 889 + { "pcf2127", PCF2127 }, 890 + { "pcf2129", PCF2129 }, 891 + { "pca2129", PCF2129 }, 892 + { "pcf2131", PCF2131 }, 1356 893 { } 1357 894 }; 1358 895 MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id); 1359 896 1360 897 static int pcf2127_i2c_probe(struct i2c_client *client) 1361 898 { 1362 - const struct i2c_device_id *id = i2c_match_id(pcf2127_i2c_id, client); 1363 899 struct regmap *regmap; 1364 - static const struct regmap_config config = { 900 + static struct regmap_config config = { 1365 901 .reg_bits = 8, 1366 902 .val_bits = 8, 1367 - .max_register = 0x1d, 1368 903 }; 904 + const struct pcf21xx_config *variant; 1369 905 1370 906 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 1371 907 return -ENODEV; 908 + 909 + if (client->dev.of_node) { 910 + variant = of_device_get_match_data(&client->dev); 911 + if (!variant) 912 + return -ENODEV; 913 + } else { 914 + enum pcf21xx_type type = 915 + i2c_match_id(pcf2127_i2c_id, client)->driver_data; 916 + 917 + if (type >= PCF21XX_LAST_ID) 918 + return -ENODEV; 919 + variant = &pcf21xx_cfg[type]; 920 + } 921 + 922 + config.max_register = variant->max_register, 1372 923 1373 924 regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap, 1374 925 &client->dev, &config); ··· 1393 914 return PTR_ERR(regmap); 1394 915 } 1395 916 1396 - return pcf2127_probe(&client->dev, regmap, client->irq, 1397 - pcf2127_i2c_driver.driver.name, id->driver_data); 917 + return pcf2127_probe(&client->dev, regmap, client->irq, variant); 1398 918 } 1399 919 1400 920 static struct i2c_driver pcf2127_i2c_driver = { ··· 1431 953 #if IS_ENABLED(CONFIG_SPI_MASTER) 1432 954 1433 955 static struct spi_driver pcf2127_spi_driver; 956 + static const struct spi_device_id pcf2127_spi_id[]; 1434 957 1435 958 static int pcf2127_spi_probe(struct spi_device *spi) 1436 959 { 1437 - static const struct regmap_config config = { 960 + static struct regmap_config config = { 1438 961 .reg_bits = 8, 1439 962 .val_bits = 8, 1440 963 .read_flag_mask = 0xa0, 1441 964 .write_flag_mask = 0x20, 1442 - .max_register = 0x1d, 1443 965 }; 1444 966 struct regmap *regmap; 967 + const struct pcf21xx_config *variant; 968 + 969 + if (spi->dev.of_node) { 970 + variant = of_device_get_match_data(&spi->dev); 971 + if (!variant) 972 + return -ENODEV; 973 + } else { 974 + enum pcf21xx_type type = spi_get_device_id(spi)->driver_data; 975 + 976 + if (type >= PCF21XX_LAST_ID) 977 + return -ENODEV; 978 + variant = &pcf21xx_cfg[type]; 979 + } 980 + 981 + config.max_register = variant->max_register, 1445 982 1446 983 regmap = devm_regmap_init_spi(spi, &config); 1447 984 if (IS_ERR(regmap)) { ··· 1465 972 return PTR_ERR(regmap); 1466 973 } 1467 974 1468 - return pcf2127_probe(&spi->dev, regmap, spi->irq, 1469 - pcf2127_spi_driver.driver.name, 1470 - spi_get_device_id(spi)->driver_data); 975 + return pcf2127_probe(&spi->dev, regmap, spi->irq, variant); 1471 976 } 1472 977 1473 978 static const struct spi_device_id pcf2127_spi_id[] = { 1474 - { "pcf2127", 1 }, 1475 - { "pcf2129", 0 }, 1476 - { "pca2129", 0 }, 979 + { "pcf2127", PCF2127 }, 980 + { "pcf2129", PCF2129 }, 981 + { "pca2129", PCF2129 }, 982 + { "pcf2131", PCF2131 }, 1477 983 { } 1478 984 }; 1479 985 MODULE_DEVICE_TABLE(spi, pcf2127_spi_id); ··· 1537 1045 module_exit(pcf2127_exit) 1538 1046 1539 1047 MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>"); 1540 - MODULE_DESCRIPTION("NXP PCF2127/29 RTC driver"); 1048 + MODULE_DESCRIPTION("NXP PCF2127/29/31 RTC driver"); 1541 1049 MODULE_LICENSE("GPL v2");
+45 -62
drivers/rtc/rtc-pcf85063.c
··· 14 14 #include <linux/bcd.h> 15 15 #include <linux/rtc.h> 16 16 #include <linux/module.h> 17 - #include <linux/of_device.h> 17 + #include <linux/of.h> 18 18 #include <linux/pm_wakeirq.h> 19 19 #include <linux/regmap.h> 20 20 ··· 514 514 } 515 515 #endif 516 516 517 - enum pcf85063_type { 518 - PCF85063, 519 - PCF85063TP, 520 - PCF85063A, 521 - RV8263, 522 - PCF85063_LAST_ID 523 - }; 524 - 525 - static struct pcf85063_config pcf85063_cfg[] = { 526 - [PCF85063] = { 527 - .regmap = { 528 - .reg_bits = 8, 529 - .val_bits = 8, 530 - .max_register = 0x0a, 531 - }, 532 - }, 533 - [PCF85063TP] = { 534 - .regmap = { 535 - .reg_bits = 8, 536 - .val_bits = 8, 537 - .max_register = 0x0a, 538 - }, 539 - }, 540 - [PCF85063A] = { 541 - .regmap = { 542 - .reg_bits = 8, 543 - .val_bits = 8, 544 - .max_register = 0x11, 545 - }, 546 - .has_alarms = 1, 547 - }, 548 - [RV8263] = { 549 - .regmap = { 550 - .reg_bits = 8, 551 - .val_bits = 8, 552 - .max_register = 0x11, 553 - }, 554 - .has_alarms = 1, 555 - .force_cap_7000 = 1, 517 + static const struct pcf85063_config config_pcf85063 = { 518 + .regmap = { 519 + .reg_bits = 8, 520 + .val_bits = 8, 521 + .max_register = 0x0a, 556 522 }, 557 523 }; 558 524 559 - static const struct i2c_device_id pcf85063_ids[]; 525 + static const struct pcf85063_config config_pcf85063tp = { 526 + .regmap = { 527 + .reg_bits = 8, 528 + .val_bits = 8, 529 + .max_register = 0x0a, 530 + }, 531 + }; 532 + 533 + static const struct pcf85063_config config_pcf85063a = { 534 + .regmap = { 535 + .reg_bits = 8, 536 + .val_bits = 8, 537 + .max_register = 0x11, 538 + }, 539 + .has_alarms = 1, 540 + }; 541 + 542 + static const struct pcf85063_config config_rv8263 = { 543 + .regmap = { 544 + .reg_bits = 8, 545 + .val_bits = 8, 546 + .max_register = 0x11, 547 + }, 548 + .has_alarms = 1, 549 + .force_cap_7000 = 1, 550 + }; 560 551 561 552 static int pcf85063_probe(struct i2c_client *client) 562 553 { ··· 570 579 if (!pcf85063) 571 580 return -ENOMEM; 572 581 573 - if (client->dev.of_node) { 574 - config = of_device_get_match_data(&client->dev); 575 - if (!config) 576 - return -ENODEV; 577 - } else { 578 - enum pcf85063_type type = 579 - i2c_match_id(pcf85063_ids, client)->driver_data; 580 - if (type >= PCF85063_LAST_ID) 581 - return -ENODEV; 582 - config = &pcf85063_cfg[type]; 583 - } 582 + config = i2c_get_match_data(client); 583 + if (!config) 584 + return -ENODEV; 584 585 585 586 pcf85063->regmap = devm_regmap_init_i2c(client, &config->regmap); 586 587 if (IS_ERR(pcf85063->regmap)) ··· 638 655 } 639 656 640 657 static const struct i2c_device_id pcf85063_ids[] = { 641 - { "pca85073a", PCF85063A }, 642 - { "pcf85063", PCF85063 }, 643 - { "pcf85063tp", PCF85063TP }, 644 - { "pcf85063a", PCF85063A }, 645 - { "rv8263", RV8263 }, 658 + { "pca85073a", .driver_data = (kernel_ulong_t)&config_pcf85063a }, 659 + { "pcf85063", .driver_data = (kernel_ulong_t)&config_pcf85063 }, 660 + { "pcf85063tp", .driver_data = (kernel_ulong_t)&config_pcf85063tp }, 661 + { "pcf85063a", .driver_data = (kernel_ulong_t)&config_pcf85063a }, 662 + { "rv8263", .driver_data = (kernel_ulong_t)&config_rv8263 }, 646 663 {} 647 664 }; 648 665 MODULE_DEVICE_TABLE(i2c, pcf85063_ids); 649 666 650 667 #ifdef CONFIG_OF 651 668 static const struct of_device_id pcf85063_of_match[] = { 652 - { .compatible = "nxp,pca85073a", .data = &pcf85063_cfg[PCF85063A] }, 653 - { .compatible = "nxp,pcf85063", .data = &pcf85063_cfg[PCF85063] }, 654 - { .compatible = "nxp,pcf85063tp", .data = &pcf85063_cfg[PCF85063TP] }, 655 - { .compatible = "nxp,pcf85063a", .data = &pcf85063_cfg[PCF85063A] }, 656 - { .compatible = "microcrystal,rv8263", .data = &pcf85063_cfg[RV8263] }, 669 + { .compatible = "nxp,pca85073a", .data = &config_pcf85063a }, 670 + { .compatible = "nxp,pcf85063", .data = &config_pcf85063 }, 671 + { .compatible = "nxp,pcf85063tp", .data = &config_pcf85063tp }, 672 + { .compatible = "nxp,pcf85063a", .data = &config_pcf85063a }, 673 + { .compatible = "microcrystal,rv8263", .data = &config_rv8263 }, 657 674 {} 658 675 }; 659 676 MODULE_DEVICE_TABLE(of, pcf85063_of_match);
+21 -10
drivers/rtc/rtc-pcf85363.c
··· 15 15 #include <linux/errno.h> 16 16 #include <linux/bcd.h> 17 17 #include <linux/of.h> 18 - #include <linux/of_device.h> 19 18 #include <linux/regmap.h> 20 19 21 20 /* ··· 402 403 }, 403 404 }; 404 405 int ret, i, err; 406 + bool wakeup_source; 405 407 406 408 if (data) 407 409 config = data; ··· 432 432 pcf85363->rtc->ops = &rtc_ops; 433 433 pcf85363->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 434 434 pcf85363->rtc->range_max = RTC_TIMESTAMP_END_2099; 435 - clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); 435 + 436 + wakeup_source = device_property_read_bool(&client->dev, 437 + "wakeup-source"); 438 + if (client->irq > 0 || wakeup_source) { 439 + regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); 440 + regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, 441 + PIN_IO_INTA_OUT, PIN_IO_INTAPM); 442 + } 436 443 437 444 if (client->irq > 0) { 438 445 unsigned long irqflags = IRQF_TRIGGER_LOW; 439 446 440 447 if (dev_fwnode(&client->dev)) 441 448 irqflags = 0; 442 - 443 - regmap_write(pcf85363->regmap, CTRL_FLAGS, 0); 444 - regmap_update_bits(pcf85363->regmap, CTRL_PIN_IO, 445 - PIN_IO_INTA_OUT, PIN_IO_INTAPM); 446 449 ret = devm_request_threaded_irq(&client->dev, client->irq, 447 450 NULL, pcf85363_rtc_handle_irq, 448 451 irqflags | IRQF_ONESHOT, 449 452 "pcf85363", client); 450 - if (ret) 451 - dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n"); 452 - else 453 - set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); 453 + if (ret) { 454 + dev_warn(&client->dev, 455 + "unable to request IRQ, alarms disabled\n"); 456 + client->irq = 0; 457 + } 458 + } 459 + 460 + if (client->irq > 0 || wakeup_source) { 461 + device_init_wakeup(&client->dev, true); 462 + set_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); 463 + } else { 464 + clear_bit(RTC_FEATURE_ALARM, pcf85363->rtc->features); 454 465 } 455 466 456 467 ret = devm_rtc_register_device(pcf85363->rtc);
-1
drivers/rtc/rtc-pxa.c
··· 14 14 #include <linux/io.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/of.h> 17 - #include <linux/of_device.h> 18 17 19 18 #include "rtc-sa1100.h" 20 19
+2 -3
drivers/rtc/rtc-rs5c372.c
··· 12 12 #include <linux/bcd.h> 13 13 #include <linux/slab.h> 14 14 #include <linux/module.h> 15 - #include <linux/of_device.h> 15 + #include <linux/of.h> 16 16 17 17 /* 18 18 * Ricoh has a family of I2C based RTCs, which differ only slightly from ··· 826 826 rs5c372->client = client; 827 827 i2c_set_clientdata(client, rs5c372); 828 828 if (client->dev.of_node) { 829 - rs5c372->type = (enum rtc_type) 830 - of_device_get_match_data(&client->dev); 829 + rs5c372->type = (uintptr_t)of_device_get_match_data(&client->dev); 831 830 } else { 832 831 const struct i2c_device_id *id = i2c_match_id(rs5c372_id, client); 833 832 rs5c372->type = id->driver_data;
+62 -20
drivers/rtc/rtc-rv3028.c
··· 17 17 #include <linux/kernel.h> 18 18 #include <linux/log2.h> 19 19 #include <linux/module.h> 20 - #include <linux/of_device.h> 20 + #include <linux/of.h> 21 21 #include <linux/regmap.h> 22 22 #include <linux/rtc.h> 23 23 ··· 855 855 .max_register = 0x37, 856 856 }; 857 857 858 + static u8 rv3028_set_trickle_charger(struct rv3028_data *rv3028, 859 + struct i2c_client *client) 860 + { 861 + int ret, val_old, val; 862 + u32 ohms, chargeable; 863 + 864 + ret = regmap_read(rv3028->regmap, RV3028_BACKUP, &val_old); 865 + if (ret < 0) 866 + return ret; 867 + 868 + /* mask out only trickle charger bits */ 869 + val_old = val_old & (RV3028_BACKUP_TCE | RV3028_BACKUP_TCR_MASK); 870 + val = val_old; 871 + 872 + /* setup trickle charger */ 873 + if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms", 874 + &ohms)) { 875 + int i; 876 + 877 + for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++) 878 + if (ohms == rv3028_trickle_resistors[i]) 879 + break; 880 + 881 + if (i < ARRAY_SIZE(rv3028_trickle_resistors)) { 882 + /* enable trickle charger and its resistor */ 883 + val = RV3028_BACKUP_TCE | i; 884 + } else { 885 + dev_warn(&client->dev, "invalid trickle resistor value\n"); 886 + } 887 + } 888 + 889 + if (!device_property_read_u32(&client->dev, "aux-voltage-chargeable", 890 + &chargeable)) { 891 + switch (chargeable) { 892 + case 0: 893 + val &= ~RV3028_BACKUP_TCE; 894 + break; 895 + case 1: 896 + val |= RV3028_BACKUP_TCE; 897 + break; 898 + default: 899 + dev_warn(&client->dev, 900 + "unsupported aux-voltage-chargeable value\n"); 901 + break; 902 + } 903 + } 904 + 905 + /* only update EEPROM if changes are necessary */ 906 + if (val_old != val) { 907 + ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE | 908 + RV3028_BACKUP_TCR_MASK, val); 909 + if (ret) 910 + return ret; 911 + } 912 + 913 + return ret; 914 + } 915 + 858 916 static int rv3028_probe(struct i2c_client *client) 859 917 { 860 918 struct rv3028_data *rv3028; 861 919 int ret, status; 862 - u32 ohms; 863 920 struct nvmem_config nvmem_cfg = { 864 921 .name = "rv3028_nvram", 865 922 .word_size = 1, ··· 994 937 if (ret) 995 938 return ret; 996 939 997 - /* setup trickle charger */ 998 - if (!device_property_read_u32(&client->dev, "trickle-resistor-ohms", 999 - &ohms)) { 1000 - int i; 1001 - 1002 - for (i = 0; i < ARRAY_SIZE(rv3028_trickle_resistors); i++) 1003 - if (ohms == rv3028_trickle_resistors[i]) 1004 - break; 1005 - 1006 - if (i < ARRAY_SIZE(rv3028_trickle_resistors)) { 1007 - ret = rv3028_update_cfg(rv3028, RV3028_BACKUP, RV3028_BACKUP_TCE | 1008 - RV3028_BACKUP_TCR_MASK, RV3028_BACKUP_TCE | i); 1009 - if (ret) 1010 - return ret; 1011 - } else { 1012 - dev_warn(&client->dev, "invalid trickle resistor value\n"); 1013 - } 1014 - } 940 + ret = rv3028_set_trickle_charger(rv3028, client); 941 + if (ret) 942 + return ret; 1015 943 1016 944 ret = rtc_add_group(rv3028->rtc, &rv3028_attr_group); 1017 945 if (ret)
+1 -1
drivers/rtc/rtc-rv3032.c
··· 19 19 #include <linux/kernel.h> 20 20 #include <linux/log2.h> 21 21 #include <linux/module.h> 22 - #include <linux/of_device.h> 22 + #include <linux/of.h> 23 23 #include <linux/regmap.h> 24 24 #include <linux/rtc.h> 25 25
+2 -3
drivers/rtc/rtc-rv8803.c
··· 15 15 #include <linux/interrupt.h> 16 16 #include <linux/kernel.h> 17 17 #include <linux/module.h> 18 - #include <linux/of_device.h> 18 + #include <linux/of.h> 19 19 #include <linux/rtc.h> 20 20 21 21 #define RV8803_I2C_TRY_COUNT 4 ··· 645 645 mutex_init(&rv8803->flags_lock); 646 646 rv8803->client = client; 647 647 if (client->dev.of_node) { 648 - rv8803->type = (enum rv8803_type) 649 - of_device_get_match_data(&client->dev); 648 + rv8803->type = (uintptr_t)of_device_get_match_data(&client->dev); 650 649 } else { 651 650 const struct i2c_device_id *id = i2c_match_id(rv8803_id, client); 652 651
-1
drivers/rtc/rtc-rx6110.c
··· 13 13 #include <linux/regmap.h> 14 14 #include <linux/rtc.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_device.h> 17 16 #include <linux/spi/spi.h> 18 17 #include <linux/i2c.h> 19 18
-1
drivers/rtc/rtc-rx8581.c
··· 13 13 #include <linux/i2c.h> 14 14 #include <linux/bcd.h> 15 15 #include <linux/of.h> 16 - #include <linux/of_device.h> 17 16 #include <linux/regmap.h> 18 17 #include <linux/rtc.h> 19 18 #include <linux/log2.h>
+3 -2
drivers/rtc/rtc-rzn1.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/iopoll.h> 17 17 #include <linux/module.h> 18 - #include <linux/of_device.h> 18 + #include <linux/mod_devicetable.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pm_runtime.h> 21 21 #include <linux/rtc.h> ··· 227 227 return ret; 228 228 229 229 /* We cannot set alarms more than one week ahead */ 230 - farest = rtc_tm_to_time64(&tm_now) + (7 * 86400); 230 + farest = rtc_tm_to_time64(&tm_now) + rtc->rtcdev->alarm_offset_max; 231 231 alarm = rtc_tm_to_time64(tm); 232 232 if (time_after(alarm, farest)) 233 233 return -ERANGE; ··· 351 351 352 352 rtc->rtcdev->range_min = RTC_TIMESTAMP_BEGIN_2000; 353 353 rtc->rtcdev->range_max = RTC_TIMESTAMP_END_2099; 354 + rtc->rtcdev->alarm_offset_max = 7 * 86400; 354 355 rtc->rtcdev->ops = &rzn1_rtc_ops; 355 356 set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->rtcdev->features); 356 357 clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->rtcdev->features);
-1
drivers/rtc/rtc-s3c.c
··· 23 23 #include <linux/log2.h> 24 24 #include <linux/slab.h> 25 25 #include <linux/of.h> 26 - #include <linux/of_device.h> 27 26 #include <linux/uaccess.h> 28 27 #include <linux/io.h> 29 28
+87 -56
drivers/rtc/rtc-stm32.c
··· 6 6 7 7 #include <linux/bcd.h> 8 8 #include <linux/clk.h> 9 + #include <linux/errno.h> 9 10 #include <linux/iopoll.h> 10 11 #include <linux/ioport.h> 11 12 #include <linux/mfd/syscon.h> 12 13 #include <linux/module.h> 13 - #include <linux/of_device.h> 14 + #include <linux/of.h> 15 + #include <linux/platform_device.h> 14 16 #include <linux/pm_wakeirq.h> 15 17 #include <linux/regmap.h> 16 18 #include <linux/rtc.h> ··· 91 89 /* Max STM32 RTC register offset is 0x3FC */ 92 90 #define UNDEF_REG 0xFFFF 93 91 92 + /* STM32 RTC driver time helpers */ 93 + #define SEC_PER_DAY (24 * 60 * 60) 94 + 94 95 struct stm32_rtc; 95 96 96 97 struct stm32_rtc_registers { ··· 119 114 void (*clear_events)(struct stm32_rtc *rtc, unsigned int flags); 120 115 bool has_pclk; 121 116 bool need_dbp; 117 + bool need_accuracy; 122 118 }; 123 119 124 120 struct stm32_rtc { ··· 164 158 * slowest rtc_ck frequency may be 32kHz and highest should be 165 159 * 1MHz, we poll every 10 us with a timeout of 100ms. 166 160 */ 167 - return readl_relaxed_poll_timeout_atomic( 168 - rtc->base + regs->isr, 169 - isr, (isr & STM32_RTC_ISR_INITF), 170 - 10, 100000); 161 + return readl_relaxed_poll_timeout_atomic(rtc->base + regs->isr, isr, 162 + (isr & STM32_RTC_ISR_INITF), 163 + 10, 100000); 171 164 } 172 165 173 166 return 0; ··· 430 425 return 0; 431 426 } 432 427 433 - static int stm32_rtc_valid_alrm(struct stm32_rtc *rtc, struct rtc_time *tm) 428 + static int stm32_rtc_valid_alrm(struct device *dev, struct rtc_time *tm) 434 429 { 435 - const struct stm32_rtc_registers *regs = &rtc->data->regs; 436 - int cur_day, cur_mon, cur_year, cur_hour, cur_min, cur_sec; 437 - unsigned int dr = readl_relaxed(rtc->base + regs->dr); 438 - unsigned int tr = readl_relaxed(rtc->base + regs->tr); 439 - 440 - cur_day = (dr & STM32_RTC_DR_DATE) >> STM32_RTC_DR_DATE_SHIFT; 441 - cur_mon = (dr & STM32_RTC_DR_MONTH) >> STM32_RTC_DR_MONTH_SHIFT; 442 - cur_year = (dr & STM32_RTC_DR_YEAR) >> STM32_RTC_DR_YEAR_SHIFT; 443 - cur_sec = (tr & STM32_RTC_TR_SEC) >> STM32_RTC_TR_SEC_SHIFT; 444 - cur_min = (tr & STM32_RTC_TR_MIN) >> STM32_RTC_TR_MIN_SHIFT; 445 - cur_hour = (tr & STM32_RTC_TR_HOUR) >> STM32_RTC_TR_HOUR_SHIFT; 430 + static struct rtc_time now; 431 + time64_t max_alarm_time64; 432 + int max_day_forward; 433 + int next_month; 434 + int next_year; 446 435 447 436 /* 448 437 * Assuming current date is M-D-Y H:M:S. 449 438 * RTC alarm can't be set on a specific month and year. 450 439 * So the valid alarm range is: 451 440 * M-D-Y H:M:S < alarm <= (M+1)-D-Y H:M:S 452 - * with a specific case for December... 453 441 */ 454 - if ((((tm->tm_year > cur_year) && 455 - (tm->tm_mon == 0x1) && (cur_mon == 0x12)) || 456 - ((tm->tm_year == cur_year) && 457 - (tm->tm_mon <= cur_mon + 1))) && 458 - ((tm->tm_mday > cur_day) || 459 - ((tm->tm_mday == cur_day) && 460 - ((tm->tm_hour > cur_hour) || 461 - ((tm->tm_hour == cur_hour) && (tm->tm_min > cur_min)) || 462 - ((tm->tm_hour == cur_hour) && (tm->tm_min == cur_min) && 463 - (tm->tm_sec >= cur_sec)))))) 464 - return 0; 442 + stm32_rtc_read_time(dev, &now); 465 443 466 - return -EINVAL; 444 + /* 445 + * Find the next month and the year of the next month. 446 + * Note: tm_mon and next_month are from 0 to 11 447 + */ 448 + next_month = now.tm_mon + 1; 449 + if (next_month == 12) { 450 + next_month = 0; 451 + next_year = now.tm_year + 1; 452 + } else { 453 + next_year = now.tm_year; 454 + } 455 + 456 + /* Find the maximum limit of alarm in days. */ 457 + max_day_forward = rtc_month_days(now.tm_mon, now.tm_year) 458 + - now.tm_mday 459 + + min(rtc_month_days(next_month, next_year), now.tm_mday); 460 + 461 + /* Convert to timestamp and compare the alarm time and its upper limit */ 462 + max_alarm_time64 = rtc_tm_to_time64(&now) + max_day_forward * SEC_PER_DAY; 463 + return rtc_tm_to_time64(tm) <= max_alarm_time64 ? 0 : -EINVAL; 467 464 } 468 465 469 466 static int stm32_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) ··· 476 469 unsigned int cr, isr, alrmar; 477 470 int ret = 0; 478 471 479 - tm2bcd(tm); 480 - 481 472 /* 482 473 * RTC alarm can't be set on a specific date, unless this date is 483 474 * up to the same day of month next month. 484 475 */ 485 - if (stm32_rtc_valid_alrm(rtc, tm) < 0) { 476 + if (stm32_rtc_valid_alrm(dev, tm) < 0) { 486 477 dev_err(dev, "Alarm can be set only on upcoming month.\n"); 487 478 return -EINVAL; 488 479 } 480 + 481 + tm2bcd(tm); 489 482 490 483 alrmar = 0; 491 484 /* tm_year and tm_mon are not used because not supported by RTC */ ··· 552 545 static const struct stm32_rtc_data stm32_rtc_data = { 553 546 .has_pclk = false, 554 547 .need_dbp = true, 548 + .need_accuracy = false, 555 549 .regs = { 556 550 .tr = 0x00, 557 551 .dr = 0x04, ··· 574 566 static const struct stm32_rtc_data stm32h7_rtc_data = { 575 567 .has_pclk = true, 576 568 .need_dbp = true, 569 + .need_accuracy = false, 577 570 .regs = { 578 571 .tr = 0x00, 579 572 .dr = 0x04, ··· 605 596 static const struct stm32_rtc_data stm32mp1_data = { 606 597 .has_pclk = true, 607 598 .need_dbp = false, 599 + .need_accuracy = true, 608 600 .regs = { 609 601 .tr = 0x00, 610 602 .dr = 0x04, ··· 638 628 const struct stm32_rtc_registers *regs = &rtc->data->regs; 639 629 unsigned int prer, pred_a, pred_s, pred_a_max, pred_s_max, cr; 640 630 unsigned int rate; 641 - int ret = 0; 631 + int ret; 642 632 643 633 rate = clk_get_rate(rtc->rtc_ck); 644 634 ··· 646 636 pred_a_max = STM32_RTC_PRER_PRED_A >> STM32_RTC_PRER_PRED_A_SHIFT; 647 637 pred_s_max = STM32_RTC_PRER_PRED_S >> STM32_RTC_PRER_PRED_S_SHIFT; 648 638 649 - for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { 650 - pred_s = (rate / (pred_a + 1)) - 1; 639 + if (rate > (pred_a_max + 1) * (pred_s_max + 1)) { 640 + dev_err(&pdev->dev, "rtc_ck rate is too high: %dHz\n", rate); 641 + return -EINVAL; 642 + } 651 643 652 - if (((pred_s + 1) * (pred_a + 1)) == rate) 653 - break; 644 + if (rtc->data->need_accuracy) { 645 + for (pred_a = 0; pred_a <= pred_a_max; pred_a++) { 646 + pred_s = (rate / (pred_a + 1)) - 1; 647 + 648 + if (pred_s <= pred_s_max && ((pred_s + 1) * (pred_a + 1)) == rate) 649 + break; 650 + } 651 + } else { 652 + for (pred_a = pred_a_max; pred_a + 1 > 0; pred_a--) { 653 + pred_s = (rate / (pred_a + 1)) - 1; 654 + 655 + if (((pred_s + 1) * (pred_a + 1)) == rate) 656 + break; 657 + } 654 658 } 655 659 656 660 /* 657 661 * Can't find a 1Hz, so give priority to RTC power consumption 658 662 * by choosing the higher possible value for prediv_a 659 663 */ 660 - if ((pred_s > pred_s_max) || (pred_a > pred_a_max)) { 664 + if (pred_s > pred_s_max || pred_a > pred_a_max) { 661 665 pred_a = pred_a_max; 662 666 pred_s = (rate / (pred_a + 1)) - 1; 663 667 ··· 679 655 (rate < ((pred_a + 1) * (pred_s + 1))) ? 680 656 "fast" : "slow"); 681 657 } 658 + 659 + cr = readl_relaxed(rtc->base + regs->cr); 660 + 661 + prer = readl_relaxed(rtc->base + regs->prer); 662 + prer &= STM32_RTC_PRER_PRED_S | STM32_RTC_PRER_PRED_A; 663 + 664 + pred_s = (pred_s << STM32_RTC_PRER_PRED_S_SHIFT) & 665 + STM32_RTC_PRER_PRED_S; 666 + pred_a = (pred_a << STM32_RTC_PRER_PRED_A_SHIFT) & 667 + STM32_RTC_PRER_PRED_A; 668 + 669 + /* quit if there is nothing to initialize */ 670 + if ((cr & STM32_RTC_CR_FMT) == 0 && prer == (pred_s | pred_a)) 671 + return 0; 682 672 683 673 stm32_rtc_wpr_unlock(rtc); 684 674 ··· 703 665 goto end; 704 666 } 705 667 706 - prer = (pred_s << STM32_RTC_PRER_PRED_S_SHIFT) & STM32_RTC_PRER_PRED_S; 707 - writel_relaxed(prer, rtc->base + regs->prer); 708 - prer |= (pred_a << STM32_RTC_PRER_PRED_A_SHIFT) & STM32_RTC_PRER_PRED_A; 709 - writel_relaxed(prer, rtc->base + regs->prer); 668 + writel_relaxed(pred_s, rtc->base + regs->prer); 669 + writel_relaxed(pred_a | pred_s, rtc->base + regs->prer); 710 670 711 671 /* Force 24h time format */ 712 - cr = readl_relaxed(rtc->base + regs->cr); 713 672 cr &= ~STM32_RTC_CR_FMT; 714 673 writel_relaxed(cr, rtc->base + regs->cr); 715 674 ··· 765 730 rtc->rtc_ck = devm_clk_get(&pdev->dev, NULL); 766 731 } else { 767 732 rtc->pclk = devm_clk_get(&pdev->dev, "pclk"); 768 - if (IS_ERR(rtc->pclk)) { 769 - dev_err(&pdev->dev, "no pclk clock"); 770 - return PTR_ERR(rtc->pclk); 771 - } 733 + if (IS_ERR(rtc->pclk)) 734 + return dev_err_probe(&pdev->dev, PTR_ERR(rtc->pclk), "no pclk clock"); 735 + 772 736 rtc->rtc_ck = devm_clk_get(&pdev->dev, "rtc_ck"); 773 737 } 774 - if (IS_ERR(rtc->rtc_ck)) { 775 - dev_err(&pdev->dev, "no rtc_ck clock"); 776 - return PTR_ERR(rtc->rtc_ck); 777 - } 738 + if (IS_ERR(rtc->rtc_ck)) 739 + return dev_err_probe(&pdev->dev, PTR_ERR(rtc->rtc_ck), "no rtc_ck clock"); 778 740 779 741 if (rtc->data->has_pclk) { 780 742 ret = clk_prepare_enable(rtc->pclk); ··· 891 859 device_init_wakeup(&pdev->dev, false); 892 860 } 893 861 894 - #ifdef CONFIG_PM_SLEEP 895 862 static int stm32_rtc_suspend(struct device *dev) 896 863 { 897 864 struct stm32_rtc *rtc = dev_get_drvdata(dev); ··· 921 890 922 891 return ret; 923 892 } 924 - #endif 925 893 926 - static SIMPLE_DEV_PM_OPS(stm32_rtc_pm_ops, 927 - stm32_rtc_suspend, stm32_rtc_resume); 894 + static const struct dev_pm_ops stm32_rtc_pm_ops = { 895 + NOIRQ_SYSTEM_SLEEP_PM_OPS(stm32_rtc_suspend, stm32_rtc_resume) 896 + }; 928 897 929 898 static struct platform_driver stm32_rtc_driver = { 930 899 .probe = stm32_rtc_probe,
-1
drivers/rtc/rtc-stmp3xxx.c
··· 18 18 #include <linux/delay.h> 19 19 #include <linux/rtc.h> 20 20 #include <linux/slab.h> 21 - #include <linux/of_device.h> 22 21 #include <linux/of.h> 23 22 #include <linux/stmp_device.h> 24 23 #include <linux/stmp3xxx_rtc_wdt.h>
-3
drivers/rtc/rtc-sun6i.c
··· 24 24 #include <linux/module.h> 25 25 #include <linux/of.h> 26 26 #include <linux/of_address.h> 27 - #include <linux/of_device.h> 28 27 #include <linux/platform_device.h> 29 28 #include <linux/rtc.h> 30 29 #include <linux/slab.h> ··· 845 846 ret = devm_rtc_nvmem_register(chip->rtc, &sun6i_rtc_nvmem_cfg); 846 847 if (ret) 847 848 return ret; 848 - 849 - dev_info(&pdev->dev, "RTC enabled\n"); 850 849 851 850 return 0; 852 851 }
+1 -1
drivers/rtc/rtc-sunplus.c
··· 244 244 245 245 sp_rtc->irq = platform_get_irq(plat_dev, 0); 246 246 if (sp_rtc->irq < 0) 247 - return dev_err_probe(&plat_dev->dev, sp_rtc->irq, "platform_get_irq failed\n"); 247 + return sp_rtc->irq; 248 248 249 249 ret = devm_request_irq(&plat_dev->dev, sp_rtc->irq, sp_rtc_irq_handler, 250 250 IRQF_TRIGGER_RISING, "rtc irq", plat_dev);
-2
drivers/rtc/rtc-sunxi.c
··· 14 14 #include <linux/kernel.h> 15 15 #include <linux/module.h> 16 16 #include <linux/of.h> 17 - #include <linux/of_address.h> 18 - #include <linux/of_device.h> 19 17 #include <linux/platform_device.h> 20 18 #include <linux/rtc.h> 21 19 #include <linux/types.h>
+1 -1
drivers/rtc/rtc-ti-k3.c
··· 9 9 #include <linux/delay.h> 10 10 #include <linux/mod_devicetable.h> 11 11 #include <linux/module.h> 12 - #include <linux/of_device.h> 12 + #include <linux/of.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/sys_soc.h> 15 15 #include <linux/property.h>
+1
drivers/rtc/rtc-tps6586x.c
··· 252 252 253 253 rtc->rtc->ops = &tps6586x_rtc_ops; 254 254 rtc->rtc->range_max = (1ULL << 30) - 1; /* 30-bit seconds */ 255 + rtc->rtc->alarm_offset_max = ALM1_VALID_RANGE_IN_SEC; 255 256 rtc->rtc->start_secs = mktime64(2009, 1, 1, 0, 0, 0); 256 257 rtc->rtc->set_start_time = true; 257 258
+2 -5
drivers/rtc/rtc-tps65910.c
··· 406 406 platform_set_drvdata(pdev, tps_rtc); 407 407 408 408 irq = platform_get_irq(pdev, 0); 409 - if (irq <= 0) { 410 - dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n", 411 - irq); 412 - return -ENXIO; 413 - } 409 + if (irq < 0) 410 + return irq; 414 411 415 412 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 416 413 tps65910_rtc_interrupt, IRQF_TRIGGER_LOW,
+38 -5
drivers/rtc/rtc-twl.c
··· 487 487 .alarm_irq_enable = twl_rtc_alarm_irq_enable, 488 488 }; 489 489 490 + static int twl_nvram_read(void *priv, unsigned int offset, void *val, 491 + size_t bytes) 492 + { 493 + return twl_i2c_read((long)priv, val, offset, bytes); 494 + } 495 + 496 + static int twl_nvram_write(void *priv, unsigned int offset, void *val, 497 + size_t bytes) 498 + { 499 + return twl_i2c_write((long)priv, val, offset, bytes); 500 + } 501 + 490 502 /*----------------------------------------------------------------------*/ 491 503 492 504 static int twl_rtc_probe(struct platform_device *pdev) 493 505 { 494 506 struct twl_rtc *twl_rtc; 507 + struct nvmem_config nvmem_cfg; 495 508 struct device_node *np = pdev->dev.of_node; 496 509 int ret = -EINVAL; 497 510 int irq = platform_get_irq(pdev, 0); ··· 555 542 REG_INT_MSK_STS_A); 556 543 } 557 544 558 - dev_info(&pdev->dev, "Enabling TWL-RTC\n"); 559 545 ret = twl_rtc_write_u8(twl_rtc, BIT_RTC_CTRL_REG_STOP_RTC_M, 560 546 REG_RTC_CTRL_REG); 561 547 if (ret < 0) ··· 576 564 577 565 twl_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 578 566 &twl_rtc_ops, THIS_MODULE); 579 - if (IS_ERR(twl_rtc->rtc)) { 580 - dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 581 - PTR_ERR(twl_rtc->rtc)); 567 + if (IS_ERR(twl_rtc->rtc)) 582 568 return PTR_ERR(twl_rtc->rtc); 583 - } 584 569 585 570 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 586 571 twl_rtc_interrupt, ··· 586 577 if (ret < 0) { 587 578 dev_err(&pdev->dev, "IRQ is not free.\n"); 588 579 return ret; 580 + } 581 + 582 + memset(&nvmem_cfg, 0, sizeof(nvmem_cfg)); 583 + nvmem_cfg.name = "twl-secured-"; 584 + nvmem_cfg.type = NVMEM_TYPE_BATTERY_BACKED; 585 + nvmem_cfg.reg_read = twl_nvram_read, 586 + nvmem_cfg.reg_write = twl_nvram_write, 587 + nvmem_cfg.word_size = 1; 588 + nvmem_cfg.stride = 1; 589 + if (twl_class_is_4030()) { 590 + /* 20 bytes SECURED_REG area */ 591 + nvmem_cfg.size = 20; 592 + nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG; 593 + devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg); 594 + /* 8 bytes BACKUP area */ 595 + nvmem_cfg.name = "twl-backup-"; 596 + nvmem_cfg.size = 8; 597 + nvmem_cfg.priv = (void *)TWL4030_MODULE_BACKUP; 598 + devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg); 599 + } else { 600 + /* 8 bytes SECURED_REG area */ 601 + nvmem_cfg.size = 8; 602 + nvmem_cfg.priv = (void *)TWL_MODULE_SECURED_REG; 603 + devm_rtc_nvmem_register(twl_rtc->rtc, &nvmem_cfg); 589 604 } 590 605 591 606 return 0;
+2 -7
drivers/rtc/rtc-wm8350.c
··· 386 386 /* enable the RTC if it's not already enabled */ 387 387 power5 = wm8350_reg_read(wm8350, WM8350_POWER_MGMT_5); 388 388 if (!(power5 & WM8350_RTC_TICK_ENA)) { 389 - dev_info(wm8350->dev, "Starting RTC\n"); 390 - 391 389 wm8350_reg_unlock(wm8350); 392 390 393 391 ret = wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, ··· 424 426 425 427 wm_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm8350", 426 428 &wm8350_rtc_ops, THIS_MODULE); 427 - if (IS_ERR(wm_rtc->rtc)) { 428 - ret = PTR_ERR(wm_rtc->rtc); 429 - dev_err(&pdev->dev, "failed to register RTC: %d\n", ret); 430 - return ret; 431 - } 429 + if (IS_ERR(wm_rtc->rtc)) 430 + return PTR_ERR(wm_rtc->rtc); 432 431 433 432 ret = wm8350_register_irq(wm8350, WM8350_IRQ_RTC_SEC, 434 433 wm8350_rtc_update_handler, 0,
-20
include/linux/platform_data/rtc-ds2404.h
··· 1 - /* 2 - * ds2404.h - platform data structure for the DS2404 RTC. 3 - * 4 - * This file is subject to the terms and conditions of the GNU General Public 5 - * License. See the file "COPYING" in the main directory of this archive 6 - * for more details. 7 - * 8 - * Copyright (C) 2012 Sven Schnelle <svens@stackframe.org> 9 - */ 10 - 11 - #ifndef __LINUX_DS2404_H 12 - #define __LINUX_DS2404_H 13 - 14 - struct ds2404_platform_data { 15 - 16 - unsigned int gpio_rst; 17 - unsigned int gpio_clk; 18 - unsigned int gpio_dq; 19 - }; 20 - #endif
+1
include/linux/rtc.h
··· 146 146 147 147 time64_t range_min; 148 148 timeu64_t range_max; 149 + timeu64_t alarm_offset_max; 149 150 time64_t start_secs; 150 151 time64_t offset_secs; 151 152 bool set_start_time;