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

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

Pull RTC updates from Alexandre Belloni:
"New drivers:
- Microchip PolarFire
- Nuvoton NCT3018Y
- TI K3 RTC

Subsystem:
- Replace flush_scheduled_work() with flush_work()
- Remove deprecated ida_simple_get()/ida_simple_remove() calls

Drivers:
- use simple i2c probe where possible
- sun6i: add R329 support
- zynqmp: add calibration support
- vr41xx: remove unused driver"

* tag 'rtc-6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (31 commits)
rtc: spear: set range max
rtc: rtc-cmos: Do not check ACPI_FADT_LOW_POWER_S0
rtc: zynqmp: initialize fract_tick
rtc: Add NCT3018Y real time clock driver
dt-bindings: rtc: nuvoton: add NCT3018Y Real Time Clock
dt-bindings: rtc: nxp,pcf85063: Convert to DT schema
dt-bindings: rtc: microcrystal,rv3032: Add missing type to 'trickle-voltage-millivolt'
rtc: rx8025: fix 12/24 hour mode detection on RX-8035
rtc: cros-ec: Only warn once in .remove() about notifier_chain problems
rtc: vr41xx: remove driver
rtc: mpfs: remove 'pending' variable from mpfs_rtc_wakeup_irq_handler()
rtc: rv8803: fix missing unlock on error in rv8803_set_time()
rtc: zynqmp: Add calibration set and get support
rtc: zynqmp: Updated calibration value
dt-bindings: rtc: zynqmp: Add clock information
rtc: sun6i: add support for R329 RTC
rtc: Directly use ida_alloc()/free()
rtc: Introduce ti-k3-rtc
dt-bindings: rtc: Add TI K3 RTC description
dt-bindings: rtc: qcom-pm8xxx-rtc: Update the maintainers section
...

+2063 -540
+1
Documentation/devicetree/bindings/rtc/microcrystal,rv3032.yaml
··· 32 32 - 11000 33 33 34 34 trickle-voltage-millivolt: 35 + $ref: /schemas/types.yaml#/definitions/uint32 35 36 enum: 36 37 - 1750 37 38 - 3000
+45
Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.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/nuvoton,nct3018y.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NUVOTON NCT3018Y Real Time Clock 8 + 9 + allOf: 10 + - $ref: "rtc.yaml#" 11 + 12 + maintainers: 13 + - Medad CChien <ctcchien@nuvoton.com> 14 + - Mia Lin <mimi05633@gmail.com> 15 + 16 + properties: 17 + compatible: 18 + const: nuvoton,nct3018y 19 + 20 + reg: 21 + maxItems: 1 22 + 23 + start-year: true 24 + 25 + reset-source: true 26 + 27 + required: 28 + - compatible 29 + - reg 30 + 31 + additionalProperties: false 32 + 33 + examples: 34 + - | 35 + i2c { 36 + #address-cells = <1>; 37 + #size-cells = <0>; 38 + 39 + rtc@6f { 40 + compatible = "nuvoton,nct3018y"; 41 + reg = <0x6f>; 42 + }; 43 + }; 44 + 45 + ...
-32
Documentation/devicetree/bindings/rtc/nxp,pcf85063.txt
··· 1 - * NXP PCF85063 Real Time Clock 2 - 3 - Required properties: 4 - - compatible: Should one of contain: 5 - "nxp,pca85073a", 6 - "nxp,pcf85063", 7 - "nxp,pcf85063a", 8 - "nxp,pcf85063tp", 9 - "microcrystal,rv8263" 10 - - reg: I2C address for chip. 11 - 12 - Optional property: 13 - - quartz-load-femtofarads: The capacitive load of the quartz(x-tal), 14 - expressed in femto Farad (fF). Valid values are 7000 and 12500. 15 - Default value (if no value is specified) is 7000fF. 16 - 17 - Optional child node: 18 - - clock: Provide this if the square wave pin is used as boot-enabled fixed clock. 19 - 20 - Example: 21 - 22 - pcf85063: rtc@51 { 23 - compatible = "nxp,pcf85063"; 24 - reg = <0x51>; 25 - quartz-load-femtofarads = <12500>; 26 - 27 - clock { 28 - compatible = "fixed-clock"; 29 - #clock-cells = <0>; 30 - clock-frequency = <32768>; 31 - }; 32 - };
+92
Documentation/devicetree/bindings/rtc/nxp,pcf85063.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/nxp,pcf85063.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP PCF85063 Real Time Clock 8 + 9 + maintainers: 10 + - Alexander Stein <alexander.stein@ew.tq-group.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - microcrystal,rv8263 16 + - nxp,pcf85063 17 + - nxp,pcf85063a 18 + - nxp,pcf85063tp 19 + - nxp,pca85073a 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + "#clock-cells": 25 + const: 0 26 + 27 + clock-output-names: 28 + maxItems: 1 29 + 30 + interrupts: 31 + maxItems: 1 32 + 33 + quartz-load-femtofarads: 34 + description: 35 + The capacitive load of the quartz(x-tal). 36 + enum: [7000, 12500] 37 + default: 7000 38 + 39 + clock: 40 + $ref: /schemas/clock/fixed-clock.yaml 41 + description: 42 + Provide this if the square wave pin is used as boot-enabled 43 + fixed clock. 44 + 45 + wakeup-source: true 46 + 47 + allOf: 48 + - $ref: rtc.yaml# 49 + - if: 50 + properties: 51 + compatible: 52 + contains: 53 + enum: 54 + - microcrystal,rv8263 55 + then: 56 + properties: 57 + quartz-load-femtofarads: false 58 + - if: 59 + properties: 60 + compatible: 61 + contains: 62 + enum: 63 + - nxp,pcf85063 64 + then: 65 + properties: 66 + quartz-load-femtofarads: 67 + const: 7000 68 + 69 + required: 70 + - compatible 71 + - reg 72 + 73 + additionalProperties: false 74 + 75 + examples: 76 + - | 77 + i2c { 78 + #address-cells = <1>; 79 + #size-cells = <0>; 80 + 81 + rtc@51 { 82 + compatible = "nxp,pcf85063a"; 83 + reg = <0x51>; 84 + quartz-load-femtofarads = <12500>; 85 + 86 + clock { 87 + compatible = "fixed-clock"; 88 + #clock-cells = <0>; 89 + clock-frequency = <32768>; 90 + }; 91 + }; 92 + };
+1 -1
Documentation/devicetree/bindings/rtc/qcom-pm8xxx-rtc.yaml
··· 7 7 title: Qualcomm PM8xxx PMIC RTC device 8 8 9 9 maintainers: 10 - - Satya Priya <skakit@codeaurora.org> 10 + - Satya Priya <quic_c_skakit@quicinc.com> 11 11 12 12 properties: 13 13 compatible:
+2
Documentation/devicetree/bindings/rtc/rtc-mt6397.txt
··· 14 14 Required properties: 15 15 - compatible: Should be one of follows 16 16 "mediatek,mt6323-rtc": for MT6323 PMIC 17 + "mediatek,mt6358-rtc": for MT6358 PMIC 18 + "mediatek,mt6366-rtc", "mediatek,mt6358-rtc": for MT6366 PMIC 17 19 "mediatek,mt6397-rtc": for MT6397 PMIC 18 20 19 21 Example:
+62
Documentation/devicetree/bindings/rtc/ti,k3-rtc.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/ti,k3-rtc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments K3 Real Time Clock 8 + 9 + maintainers: 10 + - Nishanth Menon <nm@ti.com> 11 + 12 + description: | 13 + This RTC appears in the AM62x family of SoCs. 14 + 15 + allOf: 16 + - $ref: "rtc.yaml#" 17 + 18 + properties: 19 + compatible: 20 + enum: 21 + - ti,am62-rtc 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + clocks: 30 + items: 31 + - description: VBUS Interface clock 32 + - description: 32k Clock source (external or internal). 33 + 34 + clock-names: 35 + items: 36 + - const: vbus 37 + - const: osc32k 38 + 39 + power-domains: 40 + maxItems: 1 41 + 42 + required: 43 + - compatible 44 + - reg 45 + - interrupts 46 + - clocks 47 + - clock-names 48 + 49 + unevaluatedProperties: false 50 + 51 + examples: 52 + - | 53 + #include <dt-bindings/interrupt-controller/arm-gic.h> 54 + rtc@2b1f0000 { 55 + compatible = "ti,am62-rtc"; 56 + reg = <0x2b1f0000 0x100>; 57 + interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>; 58 + power-domains = <&bar 0>; 59 + clocks = <&foo 0>, <&foo 1>; 60 + clock-names = "vbus", "osc32k"; 61 + wakeup-source; 62 + };
+11 -1
Documentation/devicetree/bindings/rtc/xlnx,zynqmp-rtc.yaml
··· 23 23 reg: 24 24 maxItems: 1 25 25 26 + clocks: 27 + maxItems: 1 28 + 29 + clock-names: 30 + items: 31 + - const: rtc 32 + 26 33 interrupts: 27 - minItems: 2 34 + maxItems: 2 28 35 29 36 interrupt-names: 30 37 items: ··· 46 39 minimum: 0x1 47 40 maximum: 0x1FFFFF 48 41 default: 0x198233 42 + deprecated: true 49 43 50 44 required: 51 45 - compatible ··· 69 61 interrupts = <0 26 4>, <0 27 4>; 70 62 interrupt-names = "alarm", "sec"; 71 63 calibration = <0x198233>; 64 + clock-names = "rtc"; 65 + clocks = <&rtc_clk>; 72 66 }; 73 67 };
+3
MAINTAINERS
··· 2486 2486 F: Documentation/devicetree/bindings/*/*/*npcm* 2487 2487 F: Documentation/devicetree/bindings/*/*npcm* 2488 2488 F: Documentation/devicetree/bindings/arm/npcm/* 2489 + F: Documentation/devicetree/bindings/rtc/nuvoton,nct3018y.yaml 2489 2490 F: arch/arm/boot/dts/nuvoton-npcm* 2490 2491 F: arch/arm/mach-npcm/ 2491 2492 F: arch/arm64/boot/dts/nuvoton/ 2492 2493 F: drivers/*/*npcm* 2493 2494 F: drivers/*/*/*npcm* 2495 + F: drivers/rtc/rtc-nct3018y.c 2494 2496 F: include/dt-bindings/clock/nuvoton,npcm7xx-clock.h 2495 2497 F: include/dt-bindings/clock/nuvoton,npcm845-clk.h 2496 2498 ··· 17531 17529 F: drivers/clk/microchip/clk-mpfs.c 17532 17530 F: drivers/mailbox/mailbox-mpfs.c 17533 17531 F: drivers/pci/controller/pcie-microchip-host.c 17532 + F: drivers/rtc/rtc-mpfs.c 17534 17533 F: drivers/soc/microchip/ 17535 17534 F: drivers/spi/spi-microchip-core.c 17536 17535 F: drivers/usb/musb/mpfs.c
+31 -10
drivers/rtc/Kconfig
··· 383 383 This driver can also be built as a module. If so, the module 384 384 will be called rtc-max77686. 385 385 386 + config RTC_DRV_NCT3018Y 387 + tristate "Nuvoton NCT3018Y" 388 + depends on OF 389 + help 390 + If you say yes here you get support for the Nuvoton NCT3018Y I2C RTC 391 + chip. 392 + 393 + This driver can also be built as a module, if so, the module will be 394 + called "rtc-nct3018y". 395 + 386 396 config RTC_DRV_RK808 387 397 tristate "Rockchip RK805/RK808/RK809/RK817/RK818 RTC" 388 398 depends on MFD_RK808 ··· 1488 1478 This driver can also be built as a module. If so, the module 1489 1479 will be called rtc-sunplus. 1490 1480 1491 - config RTC_DRV_VR41XX 1492 - tristate "NEC VR41XX" 1493 - depends on CPU_VR41XX || COMPILE_TEST 1494 - help 1495 - If you say Y here you will get access to the real time clock 1496 - built into your NEC VR41XX CPU. 1497 - 1498 - To compile this driver as a module, choose M here: the 1499 - module will be called rtc-vr41xx. 1500 - 1501 1481 config RTC_DRV_PL030 1502 1482 tristate "ARM AMBA PL030 RTC" 1503 1483 depends on ARM_AMBA ··· 1929 1929 This driver can also be built as a module, if so, the module 1930 1930 will be called "rtc-aspeed". 1931 1931 1932 + config RTC_DRV_TI_K3 1933 + tristate "TI K3 RTC" 1934 + depends on ARCH_K3 || COMPILE_TEST 1935 + select REGMAP_MMIO 1936 + help 1937 + If you say yes here you get support for the Texas Instruments's 1938 + Real Time Clock for K3 architecture. 1939 + 1940 + This driver can also be built as a module, if so, the module 1941 + will be called "rtc-ti-k3". 1942 + 1932 1943 comment "HID Sensor RTC drivers" 1933 1944 1934 1945 config RTC_DRV_HID_SENSOR_TIME ··· 1983 1972 1984 1973 This driver can also be built as a module, if so, the module 1985 1974 will be called "rtc-msc313". 1975 + 1976 + config RTC_DRV_POLARFIRE_SOC 1977 + tristate "Microchip PolarFire SoC built-in RTC" 1978 + depends on SOC_MICROCHIP_POLARFIRE 1979 + help 1980 + If you say yes here you will get support for the 1981 + built-in RTC on Polarfire SoC. 1982 + 1983 + This driver can also be built as a module, if so, the module 1984 + will be called "rtc-mpfs". 1986 1985 1987 1986 endif # RTC_CLASS
+3 -1
drivers/rtc/Makefile
··· 112 112 obj-$(CONFIG_RTC_DRV_MXC) += rtc-mxc.o 113 113 obj-$(CONFIG_RTC_DRV_MXC_V2) += rtc-mxc_v2.o 114 114 obj-$(CONFIG_RTC_DRV_GAMECUBE) += rtc-gamecube.o 115 + obj-$(CONFIG_RTC_DRV_NCT3018Y) += rtc-nct3018y.o 115 116 obj-$(CONFIG_RTC_DRV_NTXEC) += rtc-ntxec.o 116 117 obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 117 118 obj-$(CONFIG_RTC_DRV_OPAL) += rtc-opal.o ··· 131 130 obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o 132 131 obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 133 132 obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o 133 + obj-$(CONFIG_RTC_DRV_POLARFIRE_SOC) += rtc-mpfs.o 134 134 obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o 135 135 obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o 136 136 obj-$(CONFIG_RTC_DRV_R7301) += rtc-r7301.o ··· 174 172 obj-$(CONFIG_RTC_DRV_SUNXI) += rtc-sunxi.o 175 173 obj-$(CONFIG_RTC_DRV_TEGRA) += rtc-tegra.o 176 174 obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 175 + obj-$(CONFIG_RTC_DRV_TI_K3) += rtc-ti-k3.o 177 176 obj-$(CONFIG_RTC_DRV_TPS6586X) += rtc-tps6586x.o 178 177 obj-$(CONFIG_RTC_DRV_TPS65910) += rtc-tps65910.o 179 178 obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl.o 180 179 obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 181 - obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 182 180 obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o 183 181 obj-$(CONFIG_RTC_DRV_WILCO_EC) += rtc-wilco-ec.o 184 182 obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o
+3 -3
drivers/rtc/class.c
··· 36 36 37 37 cancel_work_sync(&rtc->irqwork); 38 38 39 - ida_simple_remove(&rtc_ida, rtc->id); 39 + ida_free(&rtc_ida, rtc->id); 40 40 mutex_destroy(&rtc->ops_lock); 41 41 kfree(rtc); 42 42 } ··· 262 262 } 263 263 264 264 if (id < 0) 265 - id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL); 265 + id = ida_alloc(&rtc_ida, GFP_KERNEL); 266 266 267 267 return id; 268 268 } ··· 368 368 369 369 rtc = rtc_allocate_device(); 370 370 if (!rtc) { 371 - ida_simple_remove(&rtc_ida, id); 371 + ida_free(&rtc_ida, id); 372 372 return ERR_PTR(-ENOMEM); 373 373 } 374 374
+1 -7
drivers/rtc/dev.c
··· 96 96 } 97 97 if (rtc->uie_task_active) { 98 98 spin_unlock_irq(&rtc->irq_lock); 99 - flush_scheduled_work(); 99 + flush_work(&rtc->uie_task); 100 100 spin_lock_irq(&rtc->irq_lock); 101 101 } 102 102 rtc->uie_irq_active = 0; ··· 565 565 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc"); 566 566 if (err < 0) 567 567 pr_err("failed to allocate char dev region\n"); 568 - } 569 - 570 - void __exit rtc_dev_exit(void) 571 - { 572 - if (rtc_devt) 573 - unregister_chrdev_region(rtc_devt, RTC_DEV_MAX); 574 568 }
+2 -3
drivers/rtc/rtc-ab-b5ze-s3.c
··· 817 817 .val_bits = 8, 818 818 }; 819 819 820 - static int abb5zes3_probe(struct i2c_client *client, 821 - const struct i2c_device_id *id) 820 + static int abb5zes3_probe(struct i2c_client *client) 822 821 { 823 822 struct abb5zes3_rtc_data *data = NULL; 824 823 struct device *dev = &client->dev; ··· 944 945 .pm = &abb5zes3_rtc_pm_ops, 945 946 .of_match_table = of_match_ptr(abb5zes3_dt_match), 946 947 }, 947 - .probe = abb5zes3_probe, 948 + .probe_new = abb5zes3_probe, 948 949 .id_table = abb5zes3_id, 949 950 }; 950 951 module_i2c_driver(abb5zes3_driver);
+2 -3
drivers/rtc/rtc-ab-eoz9.c
··· 495 495 496 496 #endif 497 497 498 - static int abeoz9_probe(struct i2c_client *client, 499 - const struct i2c_device_id *id) 498 + static int abeoz9_probe(struct i2c_client *client) 500 499 { 501 500 struct abeoz9_rtc_data *data = NULL; 502 501 struct device *dev = &client->dev; ··· 579 580 .name = "rtc-ab-eoz9", 580 581 .of_match_table = of_match_ptr(abeoz9_dt_match), 581 582 }, 582 - .probe = abeoz9_probe, 583 + .probe_new = abeoz9_probe, 583 584 .id_table = abeoz9_id, 584 585 }; 585 586
+2 -3
drivers/rtc/rtc-bq32k.c
··· 249 249 device_remove_file(dev, &dev_attr_trickle_charge_bypass); 250 250 } 251 251 252 - static int bq32k_probe(struct i2c_client *client, 253 - const struct i2c_device_id *id) 252 + static int bq32k_probe(struct i2c_client *client) 254 253 { 255 254 struct device *dev = &client->dev; 256 255 struct rtc_device *rtc; ··· 321 322 .name = "bq32k", 322 323 .of_match_table = of_match_ptr(bq32k_of_match), 323 324 }, 324 - .probe = bq32k_probe, 325 + .probe_new = bq32k_probe, 325 326 .remove = bq32k_remove, 326 327 .id_table = bq32k_id, 327 328 };
-3
drivers/rtc/rtc-cmos.c
··· 1260 1260 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) 1261 1261 return; 1262 1262 1263 - if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) 1264 - return; 1265 - 1266 1263 if (!is_hpet_enabled()) 1267 1264 return; 1268 1265
-5
drivers/rtc/rtc-core.h
··· 2 2 #ifdef CONFIG_RTC_INTF_DEV 3 3 4 4 extern void __init rtc_dev_init(void); 5 - extern void __exit rtc_dev_exit(void); 6 5 extern void rtc_dev_prepare(struct rtc_device *rtc); 7 6 8 7 #else 9 8 10 9 static inline void rtc_dev_init(void) 11 - { 12 - } 13 - 14 - static inline void rtc_dev_exit(void) 15 10 { 16 11 } 17 12
+1 -3
drivers/rtc/rtc-cros-ec.c
··· 375 375 ret = blocking_notifier_chain_unregister( 376 376 &cros_ec_rtc->cros_ec->event_notifier, 377 377 &cros_ec_rtc->notifier); 378 - if (ret) { 378 + if (ret) 379 379 dev_err(dev, "failed to unregister notifier\n"); 380 - return ret; 381 - } 382 380 383 381 return 0; 384 382 }
+2 -3
drivers/rtc/rtc-ds1374.c
··· 467 467 * 468 468 ***************************************************************************** 469 469 */ 470 - static int ds1374_probe(struct i2c_client *client, 471 - const struct i2c_device_id *id) 470 + static int ds1374_probe(struct i2c_client *client) 472 471 { 473 472 struct ds1374 *ds1374; 474 473 int ret; ··· 574 575 .of_match_table = of_match_ptr(ds1374_of_match), 575 576 .pm = &ds1374_pm, 576 577 }, 577 - .probe = ds1374_probe, 578 + .probe_new = ds1374_probe, 578 579 .remove = ds1374_remove, 579 580 .id_table = ds1374_id, 580 581 };
+2 -3
drivers/rtc/rtc-ds1672.c
··· 106 106 .set_time = ds1672_set_time, 107 107 }; 108 108 109 - static int ds1672_probe(struct i2c_client *client, 110 - const struct i2c_device_id *id) 109 + static int ds1672_probe(struct i2c_client *client) 111 110 { 112 111 int err = 0; 113 112 struct rtc_device *rtc; ··· 149 150 .name = "rtc-ds1672", 150 151 .of_match_table = of_match_ptr(ds1672_of_match), 151 152 }, 152 - .probe = &ds1672_probe, 153 + .probe_new = ds1672_probe, 153 154 .id_table = ds1672_id, 154 155 }; 155 156
+2 -3
drivers/rtc/rtc-ds3232.c
··· 566 566 567 567 #if IS_ENABLED(CONFIG_I2C) 568 568 569 - static int ds3232_i2c_probe(struct i2c_client *client, 570 - const struct i2c_device_id *id) 569 + static int ds3232_i2c_probe(struct i2c_client *client) 571 570 { 572 571 struct regmap *regmap; 573 572 static const struct regmap_config config = { ··· 603 604 .of_match_table = of_match_ptr(ds3232_of_match), 604 605 .pm = &ds3232_pm_ops, 605 606 }, 606 - .probe = ds3232_i2c_probe, 607 + .probe_new = ds3232_i2c_probe, 607 608 .id_table = ds3232_id, 608 609 }; 609 610
+2 -3
drivers/rtc/rtc-em3027.c
··· 111 111 .set_time = em3027_set_time, 112 112 }; 113 113 114 - static int em3027_probe(struct i2c_client *client, 115 - const struct i2c_device_id *id) 114 + static int em3027_probe(struct i2c_client *client) 116 115 { 117 116 struct rtc_device *rtc; 118 117 ··· 147 148 .name = "rtc-em3027", 148 149 .of_match_table = of_match_ptr(em3027_of_match), 149 150 }, 150 - .probe = &em3027_probe, 151 + .probe_new = em3027_probe, 151 152 .id_table = em3027_id, 152 153 }; 153 154
+2 -3
drivers/rtc/rtc-fm3130.c
··· 340 340 341 341 static struct i2c_driver fm3130_driver; 342 342 343 - static int fm3130_probe(struct i2c_client *client, 344 - const struct i2c_device_id *id) 343 + static int fm3130_probe(struct i2c_client *client) 345 344 { 346 345 struct fm3130 *fm3130; 347 346 int err = -ENODEV; ··· 517 518 .driver = { 518 519 .name = "rtc-fm3130", 519 520 }, 520 - .probe = fm3130_probe, 521 + .probe_new = fm3130_probe, 521 522 .id_table = fm3130_id, 522 523 }; 523 524
+2 -3
drivers/rtc/rtc-hym8563.c
··· 495 495 496 496 static SIMPLE_DEV_PM_OPS(hym8563_pm_ops, hym8563_suspend, hym8563_resume); 497 497 498 - static int hym8563_probe(struct i2c_client *client, 499 - const struct i2c_device_id *id) 498 + static int hym8563_probe(struct i2c_client *client) 500 499 { 501 500 struct hym8563 *hym8563; 502 501 int ret; ··· 571 572 .pm = &hym8563_pm_ops, 572 573 .of_match_table = hym8563_dt_idtable, 573 574 }, 574 - .probe = hym8563_probe, 575 + .probe_new = hym8563_probe, 575 576 .id_table = hym8563_id, 576 577 }; 577 578
+2 -3
drivers/rtc/rtc-isl12022.c
··· 232 232 .set_time = isl12022_rtc_set_time, 233 233 }; 234 234 235 - static int isl12022_probe(struct i2c_client *client, 236 - const struct i2c_device_id *id) 235 + static int isl12022_probe(struct i2c_client *client) 237 236 { 238 237 struct isl12022 *isl12022; 239 238 ··· 274 275 .of_match_table = of_match_ptr(isl12022_dt_match), 275 276 #endif 276 277 }, 277 - .probe = isl12022_probe, 278 + .probe_new = isl12022_probe, 278 279 .id_table = isl12022_id, 279 280 }; 280 281
+7 -3
drivers/rtc/rtc-isl1208.c
··· 880 880 if (rc) 881 881 return rc; 882 882 883 - if (client->irq > 0) 883 + if (client->irq > 0) { 884 884 rc = isl1208_setup_irq(client, client->irq); 885 - if (rc) 886 - return rc; 885 + if (rc) 886 + return rc; 887 + 888 + } else { 889 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, isl1208->rtc->features); 890 + } 887 891 888 892 if (evdet_irq > 0 && evdet_irq != client->irq) 889 893 rc = isl1208_setup_irq(client, evdet_irq);
+2 -3
drivers/rtc/rtc-max6900.c
··· 197 197 .set_time = max6900_rtc_set_time, 198 198 }; 199 199 200 - static int 201 - max6900_probe(struct i2c_client *client, const struct i2c_device_id *id) 200 + static int max6900_probe(struct i2c_client *client) 202 201 { 203 202 struct rtc_device *rtc; 204 203 ··· 224 225 .driver = { 225 226 .name = "rtc-max6900", 226 227 }, 227 - .probe = max6900_probe, 228 + .probe_new = max6900_probe, 228 229 .id_table = max6900_id, 229 230 }; 230 231
+4 -4
drivers/rtc/rtc-mc146818-lib.c
··· 21 21 unsigned long flags; 22 22 unsigned char seconds; 23 23 24 - for (i = 0; i < 10; i++) { 24 + for (i = 0; i < 100; i++) { 25 25 spin_lock_irqsave(&rtc_lock, flags); 26 26 27 27 /* 28 28 * Check whether there is an update in progress during which the 29 29 * readout is unspecified. The maximum update time is ~2ms. Poll 30 - * every msec for completion. 30 + * every 100 usec for completion. 31 31 * 32 32 * Store the second value before checking UIP so a long lasting 33 33 * NMI which happens to hit after the UIP check cannot make ··· 37 37 38 38 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { 39 39 spin_unlock_irqrestore(&rtc_lock, flags); 40 - mdelay(1); 40 + udelay(100); 41 41 continue; 42 42 } 43 43 ··· 56 56 */ 57 57 if (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP) { 58 58 spin_unlock_irqrestore(&rtc_lock, flags); 59 - mdelay(1); 59 + udelay(100); 60 60 continue; 61 61 } 62 62
+323
drivers/rtc/rtc-mpfs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Microchip MPFS RTC driver 4 + * 5 + * Copyright (c) 2021-2022 Microchip Corporation. All rights reserved. 6 + * 7 + * Author: Daire McNamara <daire.mcnamara@microchip.com> 8 + * & Conor Dooley <conor.dooley@microchip.com> 9 + */ 10 + #include "linux/bits.h" 11 + #include "linux/iopoll.h" 12 + #include <linux/clk.h> 13 + #include <linux/io.h> 14 + #include <linux/module.h> 15 + #include <linux/kernel.h> 16 + #include <linux/of.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/pm_wakeirq.h> 19 + #include <linux/slab.h> 20 + #include <linux/rtc.h> 21 + 22 + #define CONTROL_REG 0x00 23 + #define MODE_REG 0x04 24 + #define PRESCALER_REG 0x08 25 + #define ALARM_LOWER_REG 0x0c 26 + #define ALARM_UPPER_REG 0x10 27 + #define COMPARE_LOWER_REG 0x14 28 + #define COMPARE_UPPER_REG 0x18 29 + #define DATETIME_LOWER_REG 0x20 30 + #define DATETIME_UPPER_REG 0x24 31 + 32 + #define CONTROL_RUNNING_BIT BIT(0) 33 + #define CONTROL_START_BIT BIT(0) 34 + #define CONTROL_STOP_BIT BIT(1) 35 + #define CONTROL_ALARM_ON_BIT BIT(2) 36 + #define CONTROL_ALARM_OFF_BIT BIT(3) 37 + #define CONTROL_RESET_BIT BIT(4) 38 + #define CONTROL_UPLOAD_BIT BIT(5) 39 + #define CONTROL_DOWNLOAD_BIT BIT(6) 40 + #define CONTROL_MATCH_BIT BIT(7) 41 + #define CONTROL_WAKEUP_CLR_BIT BIT(8) 42 + #define CONTROL_WAKEUP_SET_BIT BIT(9) 43 + #define CONTROL_UPDATED_BIT BIT(10) 44 + 45 + #define MODE_CLOCK_CALENDAR BIT(0) 46 + #define MODE_WAKE_EN BIT(1) 47 + #define MODE_WAKE_RESET BIT(2) 48 + #define MODE_WAKE_CONTINUE BIT(3) 49 + 50 + #define MAX_PRESCALER_COUNT GENMASK(25, 0) 51 + #define DATETIME_UPPER_MASK GENMASK(29, 0) 52 + #define ALARM_UPPER_MASK GENMASK(10, 0) 53 + 54 + #define UPLOAD_TIMEOUT_US 50 55 + 56 + struct mpfs_rtc_dev { 57 + struct rtc_device *rtc; 58 + void __iomem *base; 59 + }; 60 + 61 + static void mpfs_rtc_start(struct mpfs_rtc_dev *rtcdev) 62 + { 63 + u32 ctrl; 64 + 65 + ctrl = readl(rtcdev->base + CONTROL_REG); 66 + ctrl &= ~CONTROL_STOP_BIT; 67 + ctrl |= CONTROL_START_BIT; 68 + writel(ctrl, rtcdev->base + CONTROL_REG); 69 + } 70 + 71 + static void mpfs_rtc_clear_irq(struct mpfs_rtc_dev *rtcdev) 72 + { 73 + u32 val = readl(rtcdev->base + CONTROL_REG); 74 + 75 + val &= ~(CONTROL_ALARM_ON_BIT | CONTROL_STOP_BIT); 76 + val |= CONTROL_ALARM_OFF_BIT; 77 + writel(val, rtcdev->base + CONTROL_REG); 78 + /* 79 + * Ensure that the posted write to the CONTROL_REG register completed before 80 + * returning from this function. Not doing this may result in the interrupt 81 + * only being cleared some time after this function returns. 82 + */ 83 + (void)readl(rtcdev->base + CONTROL_REG); 84 + } 85 + 86 + static int mpfs_rtc_readtime(struct device *dev, struct rtc_time *tm) 87 + { 88 + struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev); 89 + u64 time; 90 + 91 + time = readl(rtcdev->base + DATETIME_LOWER_REG); 92 + time |= ((u64)readl(rtcdev->base + DATETIME_UPPER_REG) & DATETIME_UPPER_MASK) << 32; 93 + rtc_time64_to_tm(time, tm); 94 + 95 + return 0; 96 + } 97 + 98 + static int mpfs_rtc_settime(struct device *dev, struct rtc_time *tm) 99 + { 100 + struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev); 101 + u32 ctrl, prog; 102 + u64 time; 103 + int ret; 104 + 105 + time = rtc_tm_to_time64(tm); 106 + 107 + writel((u32)time, rtcdev->base + DATETIME_LOWER_REG); 108 + writel((u32)(time >> 32) & DATETIME_UPPER_MASK, rtcdev->base + DATETIME_UPPER_REG); 109 + 110 + ctrl = readl(rtcdev->base + CONTROL_REG); 111 + ctrl &= ~CONTROL_STOP_BIT; 112 + ctrl |= CONTROL_UPLOAD_BIT; 113 + writel(ctrl, rtcdev->base + CONTROL_REG); 114 + 115 + ret = read_poll_timeout(readl, prog, prog & CONTROL_UPLOAD_BIT, 0, UPLOAD_TIMEOUT_US, 116 + false, rtcdev->base + CONTROL_REG); 117 + if (ret) { 118 + dev_err(dev, "timed out uploading time to rtc"); 119 + return ret; 120 + } 121 + mpfs_rtc_start(rtcdev); 122 + 123 + return 0; 124 + } 125 + 126 + static int mpfs_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm) 127 + { 128 + struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev); 129 + u32 mode = readl(rtcdev->base + MODE_REG); 130 + u64 time; 131 + 132 + alrm->enabled = mode & MODE_WAKE_EN; 133 + 134 + time = (u64)readl(rtcdev->base + ALARM_LOWER_REG) << 32; 135 + time |= (readl(rtcdev->base + ALARM_UPPER_REG) & ALARM_UPPER_MASK); 136 + rtc_time64_to_tm(time, &alrm->time); 137 + 138 + return 0; 139 + } 140 + 141 + static int mpfs_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm) 142 + { 143 + struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev); 144 + u32 mode, ctrl; 145 + u64 time; 146 + 147 + /* Disable the alarm before updating */ 148 + ctrl = readl(rtcdev->base + CONTROL_REG); 149 + ctrl |= CONTROL_ALARM_OFF_BIT; 150 + writel(ctrl, rtcdev->base + CONTROL_REG); 151 + 152 + time = rtc_tm_to_time64(&alrm->time); 153 + 154 + writel((u32)time, rtcdev->base + ALARM_LOWER_REG); 155 + writel((u32)(time >> 32) & ALARM_UPPER_MASK, rtcdev->base + ALARM_UPPER_REG); 156 + 157 + /* Bypass compare register in alarm mode */ 158 + writel(GENMASK(31, 0), rtcdev->base + COMPARE_LOWER_REG); 159 + writel(GENMASK(29, 0), rtcdev->base + COMPARE_UPPER_REG); 160 + 161 + /* Configure the RTC to enable the alarm. */ 162 + ctrl = readl(rtcdev->base + CONTROL_REG); 163 + mode = readl(rtcdev->base + MODE_REG); 164 + if (alrm->enabled) { 165 + mode = MODE_WAKE_EN | MODE_WAKE_CONTINUE; 166 + /* Enable the alarm */ 167 + ctrl &= ~CONTROL_ALARM_OFF_BIT; 168 + ctrl |= CONTROL_ALARM_ON_BIT; 169 + } 170 + ctrl &= ~CONTROL_STOP_BIT; 171 + ctrl |= CONTROL_START_BIT; 172 + writel(ctrl, rtcdev->base + CONTROL_REG); 173 + writel(mode, rtcdev->base + MODE_REG); 174 + 175 + return 0; 176 + } 177 + 178 + static int mpfs_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 179 + { 180 + struct mpfs_rtc_dev *rtcdev = dev_get_drvdata(dev); 181 + u32 ctrl; 182 + 183 + ctrl = readl(rtcdev->base + CONTROL_REG); 184 + ctrl &= ~(CONTROL_ALARM_ON_BIT | CONTROL_ALARM_OFF_BIT | CONTROL_STOP_BIT); 185 + 186 + if (enabled) 187 + ctrl |= CONTROL_ALARM_ON_BIT; 188 + else 189 + ctrl |= CONTROL_ALARM_OFF_BIT; 190 + 191 + writel(ctrl, rtcdev->base + CONTROL_REG); 192 + 193 + return 0; 194 + } 195 + 196 + static inline struct clk *mpfs_rtc_init_clk(struct device *dev) 197 + { 198 + struct clk *clk; 199 + int ret; 200 + 201 + clk = devm_clk_get(dev, "rtc"); 202 + if (IS_ERR(clk)) 203 + return clk; 204 + 205 + ret = clk_prepare_enable(clk); 206 + if (ret) 207 + return ERR_PTR(ret); 208 + 209 + devm_add_action_or_reset(dev, (void (*) (void *))clk_disable_unprepare, clk); 210 + return clk; 211 + } 212 + 213 + static irqreturn_t mpfs_rtc_wakeup_irq_handler(int irq, void *dev) 214 + { 215 + struct mpfs_rtc_dev *rtcdev = dev; 216 + 217 + mpfs_rtc_clear_irq(rtcdev); 218 + 219 + rtc_update_irq(rtcdev->rtc, 1, RTC_IRQF | RTC_AF); 220 + 221 + return IRQ_HANDLED; 222 + } 223 + 224 + static const struct rtc_class_ops mpfs_rtc_ops = { 225 + .read_time = mpfs_rtc_readtime, 226 + .set_time = mpfs_rtc_settime, 227 + .read_alarm = mpfs_rtc_readalarm, 228 + .set_alarm = mpfs_rtc_setalarm, 229 + .alarm_irq_enable = mpfs_rtc_alarm_irq_enable, 230 + }; 231 + 232 + static int mpfs_rtc_probe(struct platform_device *pdev) 233 + { 234 + struct mpfs_rtc_dev *rtcdev; 235 + struct clk *clk; 236 + u32 prescaler; 237 + int wakeup_irq, ret; 238 + 239 + rtcdev = devm_kzalloc(&pdev->dev, sizeof(struct mpfs_rtc_dev), GFP_KERNEL); 240 + if (!rtcdev) 241 + return -ENOMEM; 242 + 243 + platform_set_drvdata(pdev, rtcdev); 244 + 245 + rtcdev->rtc = devm_rtc_allocate_device(&pdev->dev); 246 + if (IS_ERR(rtcdev->rtc)) 247 + return PTR_ERR(rtcdev->rtc); 248 + 249 + rtcdev->rtc->ops = &mpfs_rtc_ops; 250 + 251 + /* range is capped by alarm max, lower reg is 31:0 & upper is 10:0 */ 252 + rtcdev->rtc->range_max = GENMASK_ULL(42, 0); 253 + 254 + clk = mpfs_rtc_init_clk(&pdev->dev); 255 + if (IS_ERR(clk)) 256 + return PTR_ERR(clk); 257 + 258 + rtcdev->base = devm_platform_ioremap_resource(pdev, 0); 259 + if (IS_ERR(rtcdev->base)) { 260 + dev_dbg(&pdev->dev, "invalid ioremap resources\n"); 261 + return PTR_ERR(rtcdev->base); 262 + } 263 + 264 + wakeup_irq = platform_get_irq(pdev, 0); 265 + if (wakeup_irq <= 0) { 266 + dev_dbg(&pdev->dev, "could not get wakeup irq\n"); 267 + return wakeup_irq; 268 + } 269 + ret = devm_request_irq(&pdev->dev, wakeup_irq, mpfs_rtc_wakeup_irq_handler, 0, 270 + dev_name(&pdev->dev), rtcdev); 271 + if (ret) { 272 + dev_dbg(&pdev->dev, "could not request wakeup irq\n"); 273 + return ret; 274 + } 275 + 276 + /* prescaler hardware adds 1 to reg value */ 277 + prescaler = clk_get_rate(devm_clk_get(&pdev->dev, "rtcref")) - 1; 278 + 279 + if (prescaler > MAX_PRESCALER_COUNT) { 280 + dev_dbg(&pdev->dev, "invalid prescaler %d\n", prescaler); 281 + return -EINVAL; 282 + } 283 + 284 + writel(prescaler, rtcdev->base + PRESCALER_REG); 285 + dev_info(&pdev->dev, "prescaler set to: 0x%X \r\n", prescaler); 286 + 287 + device_init_wakeup(&pdev->dev, true); 288 + ret = dev_pm_set_wake_irq(&pdev->dev, wakeup_irq); 289 + if (ret) 290 + dev_err(&pdev->dev, "failed to enable irq wake\n"); 291 + 292 + return devm_rtc_register_device(rtcdev->rtc); 293 + } 294 + 295 + static int mpfs_rtc_remove(struct platform_device *pdev) 296 + { 297 + dev_pm_clear_wake_irq(&pdev->dev); 298 + 299 + return 0; 300 + } 301 + 302 + static const struct of_device_id mpfs_rtc_of_match[] = { 303 + { .compatible = "microchip,mpfs-rtc" }, 304 + { } 305 + }; 306 + 307 + MODULE_DEVICE_TABLE(of, mpfs_rtc_of_match); 308 + 309 + static struct platform_driver mpfs_rtc_driver = { 310 + .probe = mpfs_rtc_probe, 311 + .remove = mpfs_rtc_remove, 312 + .driver = { 313 + .name = "mpfs_rtc", 314 + .of_match_table = mpfs_rtc_of_match, 315 + }, 316 + }; 317 + 318 + module_platform_driver(mpfs_rtc_driver); 319 + 320 + MODULE_DESCRIPTION("Real time clock for Microchip Polarfire SoC"); 321 + MODULE_AUTHOR("Daire McNamara <daire.mcnamara@microchip.com>"); 322 + MODULE_AUTHOR("Conor Dooley <conor.dooley@microchip.com>"); 323 + MODULE_LICENSE("GPL");
+553
drivers/rtc/rtc-nct3018y.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (c) 2022 Nuvoton Technology Corporation 3 + 4 + #include <linux/bcd.h> 5 + #include <linux/clk-provider.h> 6 + #include <linux/err.h> 7 + #include <linux/i2c.h> 8 + #include <linux/module.h> 9 + #include <linux/of.h> 10 + #include <linux/rtc.h> 11 + #include <linux/slab.h> 12 + 13 + #define NCT3018Y_REG_SC 0x00 /* seconds */ 14 + #define NCT3018Y_REG_SCA 0x01 /* alarm */ 15 + #define NCT3018Y_REG_MN 0x02 16 + #define NCT3018Y_REG_MNA 0x03 /* alarm */ 17 + #define NCT3018Y_REG_HR 0x04 18 + #define NCT3018Y_REG_HRA 0x05 /* alarm */ 19 + #define NCT3018Y_REG_DW 0x06 20 + #define NCT3018Y_REG_DM 0x07 21 + #define NCT3018Y_REG_MO 0x08 22 + #define NCT3018Y_REG_YR 0x09 23 + #define NCT3018Y_REG_CTRL 0x0A /* timer control */ 24 + #define NCT3018Y_REG_ST 0x0B /* status */ 25 + #define NCT3018Y_REG_CLKO 0x0C /* clock out */ 26 + 27 + #define NCT3018Y_BIT_AF BIT(7) 28 + #define NCT3018Y_BIT_ST BIT(7) 29 + #define NCT3018Y_BIT_DM BIT(6) 30 + #define NCT3018Y_BIT_HF BIT(5) 31 + #define NCT3018Y_BIT_DSM BIT(4) 32 + #define NCT3018Y_BIT_AIE BIT(3) 33 + #define NCT3018Y_BIT_OFIE BIT(2) 34 + #define NCT3018Y_BIT_CIE BIT(1) 35 + #define NCT3018Y_BIT_TWO BIT(0) 36 + 37 + #define NCT3018Y_REG_BAT_MASK 0x07 38 + #define NCT3018Y_REG_CLKO_F_MASK 0x03 /* frequenc mask */ 39 + #define NCT3018Y_REG_CLKO_CKE 0x80 /* clock out enabled */ 40 + 41 + struct nct3018y { 42 + struct rtc_device *rtc; 43 + struct i2c_client *client; 44 + #ifdef CONFIG_COMMON_CLK 45 + struct clk_hw clkout_hw; 46 + #endif 47 + }; 48 + 49 + static int nct3018y_set_alarm_mode(struct i2c_client *client, bool on) 50 + { 51 + int err, flags; 52 + 53 + dev_dbg(&client->dev, "%s:on:%d\n", __func__, on); 54 + 55 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); 56 + if (flags < 0) { 57 + dev_dbg(&client->dev, 58 + "Failed to read NCT3018Y_REG_CTRL\n"); 59 + return flags; 60 + } 61 + 62 + if (on) 63 + flags |= NCT3018Y_BIT_AIE; 64 + else 65 + flags &= ~NCT3018Y_BIT_AIE; 66 + 67 + flags |= NCT3018Y_BIT_CIE; 68 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); 69 + if (err < 0) { 70 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); 71 + return err; 72 + } 73 + 74 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST); 75 + if (flags < 0) { 76 + dev_dbg(&client->dev, 77 + "Failed to read NCT3018Y_REG_ST\n"); 78 + return flags; 79 + } 80 + 81 + flags &= ~(NCT3018Y_BIT_AF); 82 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_ST, flags); 83 + if (err < 0) { 84 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_ST\n"); 85 + return err; 86 + } 87 + 88 + return 0; 89 + } 90 + 91 + static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *alarm_enable, 92 + unsigned char *alarm_flag) 93 + { 94 + int flags; 95 + 96 + if (alarm_enable) { 97 + dev_dbg(&client->dev, "%s:NCT3018Y_REG_CTRL\n", __func__); 98 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); 99 + if (flags < 0) 100 + return flags; 101 + *alarm_enable = flags & NCT3018Y_BIT_AIE; 102 + } 103 + 104 + if (alarm_flag) { 105 + dev_dbg(&client->dev, "%s:NCT3018Y_REG_ST\n", __func__); 106 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST); 107 + if (flags < 0) 108 + return flags; 109 + *alarm_flag = flags & NCT3018Y_BIT_AF; 110 + } 111 + 112 + dev_dbg(&client->dev, "%s:alarm_enable:%x alarm_flag:%x\n", 113 + __func__, *alarm_enable, *alarm_flag); 114 + 115 + return 0; 116 + } 117 + 118 + static irqreturn_t nct3018y_irq(int irq, void *dev_id) 119 + { 120 + struct nct3018y *nct3018y = i2c_get_clientdata(dev_id); 121 + struct i2c_client *client = nct3018y->client; 122 + int err; 123 + unsigned char alarm_flag; 124 + unsigned char alarm_enable; 125 + 126 + dev_dbg(&client->dev, "%s:irq:%d\n", __func__, irq); 127 + err = nct3018y_get_alarm_mode(nct3018y->client, &alarm_enable, &alarm_flag); 128 + if (err) 129 + return IRQ_NONE; 130 + 131 + if (alarm_flag) { 132 + dev_dbg(&client->dev, "%s:alarm flag:%x\n", 133 + __func__, alarm_flag); 134 + rtc_update_irq(nct3018y->rtc, 1, RTC_IRQF | RTC_AF); 135 + nct3018y_set_alarm_mode(nct3018y->client, 0); 136 + dev_dbg(&client->dev, "%s:IRQ_HANDLED\n", __func__); 137 + return IRQ_HANDLED; 138 + } 139 + 140 + return IRQ_NONE; 141 + } 142 + 143 + /* 144 + * In the routines that deal directly with the nct3018y hardware, we use 145 + * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 146 + */ 147 + static int nct3018y_rtc_read_time(struct device *dev, struct rtc_time *tm) 148 + { 149 + struct i2c_client *client = to_i2c_client(dev); 150 + unsigned char buf[10]; 151 + int err; 152 + 153 + err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_ST, 1, buf); 154 + if (err < 0) 155 + return err; 156 + 157 + if (!buf[0]) { 158 + dev_dbg(&client->dev, " voltage <=1.7, date/time is not reliable.\n"); 159 + return -EINVAL; 160 + } 161 + 162 + err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SC, sizeof(buf), buf); 163 + if (err < 0) 164 + return err; 165 + 166 + tm->tm_sec = bcd2bin(buf[0] & 0x7F); 167 + tm->tm_min = bcd2bin(buf[2] & 0x7F); 168 + tm->tm_hour = bcd2bin(buf[4] & 0x3F); 169 + tm->tm_wday = buf[6] & 0x07; 170 + tm->tm_mday = bcd2bin(buf[7] & 0x3F); 171 + tm->tm_mon = bcd2bin(buf[8] & 0x1F) - 1; 172 + tm->tm_year = bcd2bin(buf[9]) + 100; 173 + 174 + return 0; 175 + } 176 + 177 + static int nct3018y_rtc_set_time(struct device *dev, struct rtc_time *tm) 178 + { 179 + struct i2c_client *client = to_i2c_client(dev); 180 + unsigned char buf[4] = {0}; 181 + int err; 182 + 183 + buf[0] = bin2bcd(tm->tm_sec); 184 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SC, buf[0]); 185 + if (err < 0) { 186 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_SC\n"); 187 + return err; 188 + } 189 + 190 + buf[0] = bin2bcd(tm->tm_min); 191 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_MN, buf[0]); 192 + if (err < 0) { 193 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_MN\n"); 194 + return err; 195 + } 196 + 197 + buf[0] = bin2bcd(tm->tm_hour); 198 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_HR, buf[0]); 199 + if (err < 0) { 200 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_HR\n"); 201 + return err; 202 + } 203 + 204 + buf[0] = tm->tm_wday & 0x07; 205 + buf[1] = bin2bcd(tm->tm_mday); 206 + buf[2] = bin2bcd(tm->tm_mon + 1); 207 + buf[3] = bin2bcd(tm->tm_year - 100); 208 + err = i2c_smbus_write_i2c_block_data(client, NCT3018Y_REG_DW, 209 + sizeof(buf), buf); 210 + if (err < 0) { 211 + dev_dbg(&client->dev, "Unable to write for day and mon and year\n"); 212 + return -EIO; 213 + } 214 + 215 + return err; 216 + } 217 + 218 + static int nct3018y_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm) 219 + { 220 + struct i2c_client *client = to_i2c_client(dev); 221 + unsigned char buf[5]; 222 + int err; 223 + 224 + err = i2c_smbus_read_i2c_block_data(client, NCT3018Y_REG_SCA, 225 + sizeof(buf), buf); 226 + if (err < 0) { 227 + dev_dbg(&client->dev, "Unable to read date\n"); 228 + return -EIO; 229 + } 230 + 231 + dev_dbg(&client->dev, "%s: raw data is sec=%02x, min=%02x hr=%02x\n", 232 + __func__, buf[0], buf[2], buf[4]); 233 + 234 + tm->time.tm_sec = bcd2bin(buf[0] & 0x7F); 235 + tm->time.tm_min = bcd2bin(buf[2] & 0x7F); 236 + tm->time.tm_hour = bcd2bin(buf[4] & 0x3F); 237 + 238 + err = nct3018y_get_alarm_mode(client, &tm->enabled, &tm->pending); 239 + if (err < 0) 240 + return err; 241 + 242 + dev_dbg(&client->dev, "%s:s=%d m=%d, hr=%d, enabled=%d, pending=%d\n", 243 + __func__, tm->time.tm_sec, tm->time.tm_min, 244 + tm->time.tm_hour, tm->enabled, tm->pending); 245 + 246 + return 0; 247 + } 248 + 249 + static int nct3018y_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *tm) 250 + { 251 + struct i2c_client *client = to_i2c_client(dev); 252 + int err; 253 + 254 + dev_dbg(dev, "%s, sec=%d, min=%d hour=%d tm->enabled:%d\n", 255 + __func__, tm->time.tm_sec, tm->time.tm_min, tm->time.tm_hour, 256 + tm->enabled); 257 + 258 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_SCA, bin2bcd(tm->time.tm_sec)); 259 + if (err < 0) { 260 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_SCA\n"); 261 + return err; 262 + } 263 + 264 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_MNA, bin2bcd(tm->time.tm_min)); 265 + if (err < 0) { 266 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_MNA\n"); 267 + return err; 268 + } 269 + 270 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_HRA, bin2bcd(tm->time.tm_hour)); 271 + if (err < 0) { 272 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_HRA\n"); 273 + return err; 274 + } 275 + 276 + return nct3018y_set_alarm_mode(client, tm->enabled); 277 + } 278 + 279 + static int nct3018y_irq_enable(struct device *dev, unsigned int enabled) 280 + { 281 + dev_dbg(dev, "%s: alarm enable=%d\n", __func__, enabled); 282 + 283 + return nct3018y_set_alarm_mode(to_i2c_client(dev), enabled); 284 + } 285 + 286 + static int nct3018y_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 287 + { 288 + struct i2c_client *client = to_i2c_client(dev); 289 + int status, flags = 0; 290 + 291 + switch (cmd) { 292 + case RTC_VL_READ: 293 + status = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST); 294 + if (status < 0) 295 + return status; 296 + 297 + if (!(status & NCT3018Y_REG_BAT_MASK)) 298 + flags |= RTC_VL_DATA_INVALID; 299 + 300 + return put_user(flags, (unsigned int __user *)arg); 301 + 302 + default: 303 + return -ENOIOCTLCMD; 304 + } 305 + } 306 + 307 + #ifdef CONFIG_COMMON_CLK 308 + /* 309 + * Handling of the clkout 310 + */ 311 + 312 + #define clkout_hw_to_nct3018y(_hw) container_of(_hw, struct nct3018y, clkout_hw) 313 + 314 + static const int clkout_rates[] = { 315 + 32768, 316 + 1024, 317 + 32, 318 + 1, 319 + }; 320 + 321 + static unsigned long nct3018y_clkout_recalc_rate(struct clk_hw *hw, 322 + unsigned long parent_rate) 323 + { 324 + struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw); 325 + struct i2c_client *client = nct3018y->client; 326 + int flags; 327 + 328 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO); 329 + if (flags < 0) 330 + return 0; 331 + 332 + flags &= NCT3018Y_REG_CLKO_F_MASK; 333 + return clkout_rates[flags]; 334 + } 335 + 336 + static long nct3018y_clkout_round_rate(struct clk_hw *hw, unsigned long rate, 337 + unsigned long *prate) 338 + { 339 + int i; 340 + 341 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 342 + if (clkout_rates[i] <= rate) 343 + return clkout_rates[i]; 344 + 345 + return 0; 346 + } 347 + 348 + static int nct3018y_clkout_set_rate(struct clk_hw *hw, unsigned long rate, 349 + unsigned long parent_rate) 350 + { 351 + struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw); 352 + struct i2c_client *client = nct3018y->client; 353 + int i, flags; 354 + 355 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO); 356 + if (flags < 0) 357 + return flags; 358 + 359 + for (i = 0; i < ARRAY_SIZE(clkout_rates); i++) 360 + if (clkout_rates[i] == rate) { 361 + flags &= ~NCT3018Y_REG_CLKO_F_MASK; 362 + flags |= i; 363 + return i2c_smbus_write_byte_data(client, NCT3018Y_REG_CLKO, flags); 364 + } 365 + 366 + return -EINVAL; 367 + } 368 + 369 + static int nct3018y_clkout_control(struct clk_hw *hw, bool enable) 370 + { 371 + struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw); 372 + struct i2c_client *client = nct3018y->client; 373 + int flags; 374 + 375 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO); 376 + if (flags < 0) 377 + return flags; 378 + 379 + if (enable) 380 + flags |= NCT3018Y_REG_CLKO_CKE; 381 + else 382 + flags &= ~NCT3018Y_REG_CLKO_CKE; 383 + 384 + return i2c_smbus_write_byte_data(client, NCT3018Y_REG_CLKO, flags); 385 + } 386 + 387 + static int nct3018y_clkout_prepare(struct clk_hw *hw) 388 + { 389 + return nct3018y_clkout_control(hw, 1); 390 + } 391 + 392 + static void nct3018y_clkout_unprepare(struct clk_hw *hw) 393 + { 394 + nct3018y_clkout_control(hw, 0); 395 + } 396 + 397 + static int nct3018y_clkout_is_prepared(struct clk_hw *hw) 398 + { 399 + struct nct3018y *nct3018y = clkout_hw_to_nct3018y(hw); 400 + struct i2c_client *client = nct3018y->client; 401 + int flags; 402 + 403 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CLKO); 404 + if (flags < 0) 405 + return flags; 406 + 407 + return flags & NCT3018Y_REG_CLKO_CKE; 408 + } 409 + 410 + static const struct clk_ops nct3018y_clkout_ops = { 411 + .prepare = nct3018y_clkout_prepare, 412 + .unprepare = nct3018y_clkout_unprepare, 413 + .is_prepared = nct3018y_clkout_is_prepared, 414 + .recalc_rate = nct3018y_clkout_recalc_rate, 415 + .round_rate = nct3018y_clkout_round_rate, 416 + .set_rate = nct3018y_clkout_set_rate, 417 + }; 418 + 419 + static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y) 420 + { 421 + struct i2c_client *client = nct3018y->client; 422 + struct device_node *node = client->dev.of_node; 423 + struct clk *clk; 424 + struct clk_init_data init; 425 + 426 + init.name = "nct3018y-clkout"; 427 + init.ops = &nct3018y_clkout_ops; 428 + init.flags = 0; 429 + init.parent_names = NULL; 430 + init.num_parents = 0; 431 + nct3018y->clkout_hw.init = &init; 432 + 433 + /* optional override of the clockname */ 434 + of_property_read_string(node, "clock-output-names", &init.name); 435 + 436 + /* register the clock */ 437 + clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw); 438 + 439 + if (!IS_ERR(clk)) 440 + of_clk_add_provider(node, of_clk_src_simple_get, clk); 441 + 442 + return clk; 443 + } 444 + #endif 445 + 446 + static const struct rtc_class_ops nct3018y_rtc_ops = { 447 + .read_time = nct3018y_rtc_read_time, 448 + .set_time = nct3018y_rtc_set_time, 449 + .read_alarm = nct3018y_rtc_read_alarm, 450 + .set_alarm = nct3018y_rtc_set_alarm, 451 + .alarm_irq_enable = nct3018y_irq_enable, 452 + .ioctl = nct3018y_ioctl, 453 + }; 454 + 455 + static int nct3018y_probe(struct i2c_client *client, 456 + const struct i2c_device_id *id) 457 + { 458 + struct nct3018y *nct3018y; 459 + int err, flags; 460 + 461 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 462 + I2C_FUNC_SMBUS_BYTE | 463 + I2C_FUNC_SMBUS_BLOCK_DATA)) 464 + return -ENODEV; 465 + 466 + nct3018y = devm_kzalloc(&client->dev, sizeof(struct nct3018y), 467 + GFP_KERNEL); 468 + if (!nct3018y) 469 + return -ENOMEM; 470 + 471 + i2c_set_clientdata(client, nct3018y); 472 + nct3018y->client = client; 473 + device_set_wakeup_capable(&client->dev, 1); 474 + 475 + flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL); 476 + if (flags < 0) { 477 + dev_dbg(&client->dev, "%s: read error\n", __func__); 478 + return flags; 479 + } else if (flags & NCT3018Y_BIT_TWO) { 480 + dev_dbg(&client->dev, "%s: NCT3018Y_BIT_TWO is set\n", __func__); 481 + } 482 + 483 + flags = NCT3018Y_BIT_TWO; 484 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags); 485 + if (err < 0) { 486 + dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n"); 487 + return err; 488 + } 489 + 490 + flags = 0; 491 + err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_ST, flags); 492 + if (err < 0) { 493 + dev_dbg(&client->dev, "%s: write error\n", __func__); 494 + return err; 495 + } 496 + 497 + nct3018y->rtc = devm_rtc_allocate_device(&client->dev); 498 + if (IS_ERR(nct3018y->rtc)) 499 + return PTR_ERR(nct3018y->rtc); 500 + 501 + nct3018y->rtc->ops = &nct3018y_rtc_ops; 502 + nct3018y->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; 503 + nct3018y->rtc->range_max = RTC_TIMESTAMP_END_2099; 504 + 505 + if (client->irq > 0) { 506 + err = devm_request_threaded_irq(&client->dev, client->irq, 507 + NULL, nct3018y_irq, 508 + IRQF_ONESHOT | IRQF_TRIGGER_FALLING, 509 + "nct3018y", client); 510 + if (err) { 511 + dev_dbg(&client->dev, "unable to request IRQ %d\n", client->irq); 512 + return err; 513 + } 514 + } else { 515 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, nct3018y->rtc->features); 516 + clear_bit(RTC_FEATURE_ALARM, nct3018y->rtc->features); 517 + } 518 + 519 + #ifdef CONFIG_COMMON_CLK 520 + /* register clk in common clk framework */ 521 + nct3018y_clkout_register_clk(nct3018y); 522 + #endif 523 + 524 + return devm_rtc_register_device(nct3018y->rtc); 525 + } 526 + 527 + static const struct i2c_device_id nct3018y_id[] = { 528 + { "nct3018y", 0 }, 529 + { } 530 + }; 531 + MODULE_DEVICE_TABLE(i2c, nct3018y_id); 532 + 533 + static const struct of_device_id nct3018y_of_match[] = { 534 + { .compatible = "nuvoton,nct3018y" }, 535 + {} 536 + }; 537 + MODULE_DEVICE_TABLE(of, nct3018y_of_match); 538 + 539 + static struct i2c_driver nct3018y_driver = { 540 + .driver = { 541 + .name = "rtc-nct3018y", 542 + .of_match_table = of_match_ptr(nct3018y_of_match), 543 + }, 544 + .probe = nct3018y_probe, 545 + .id_table = nct3018y_id, 546 + }; 547 + 548 + module_i2c_driver(nct3018y_driver); 549 + 550 + MODULE_AUTHOR("Medad CChien <ctcchien@nuvoton.com>"); 551 + MODULE_AUTHOR("Mia Lin <mimi05633@gmail.com>"); 552 + MODULE_DESCRIPTION("Nuvoton NCT3018Y RTC driver"); 553 + MODULE_LICENSE("GPL");
+2 -3
drivers/rtc/rtc-pcf8523.c
··· 390 390 .max_register = 0x13, 391 391 }; 392 392 393 - static int pcf8523_probe(struct i2c_client *client, 394 - const struct i2c_device_id *id) 393 + static int pcf8523_probe(struct i2c_client *client) 395 394 { 396 395 struct pcf8523 *pcf8523; 397 396 struct rtc_device *rtc; ··· 484 485 .name = "rtc-pcf8523", 485 486 .of_match_table = pcf8523_of_match, 486 487 }, 487 - .probe = pcf8523_probe, 488 + .probe_new = pcf8523_probe, 488 489 .id_table = pcf8523_id, 489 490 }; 490 491 module_i2c_driver(pcf8523_driver);
+2 -3
drivers/rtc/rtc-pcf85363.c
··· 350 350 .num_nvram = 2 351 351 }; 352 352 353 - static int pcf85363_probe(struct i2c_client *client, 354 - const struct i2c_device_id *id) 353 + static int pcf85363_probe(struct i2c_client *client) 355 354 { 356 355 struct pcf85363 *pcf85363; 357 356 const struct pcf85x63_config *config = &pcf_85363_config; ··· 435 436 .name = "pcf85363", 436 437 .of_match_table = of_match_ptr(dev_ids), 437 438 }, 438 - .probe = pcf85363_probe, 439 + .probe_new = pcf85363_probe, 439 440 }; 440 441 441 442 module_i2c_driver(pcf85363_driver);
+2 -3
drivers/rtc/rtc-pcf8563.c
··· 509 509 .alarm_irq_enable = pcf8563_irq_enable, 510 510 }; 511 511 512 - static int pcf8563_probe(struct i2c_client *client, 513 - const struct i2c_device_id *id) 512 + static int pcf8563_probe(struct i2c_client *client) 514 513 { 515 514 struct pcf8563 *pcf8563; 516 515 int err; ··· 605 606 .name = "rtc-pcf8563", 606 607 .of_match_table = of_match_ptr(pcf8563_of_match), 607 608 }, 608 - .probe = pcf8563_probe, 609 + .probe_new = pcf8563_probe, 609 610 .id_table = pcf8563_id, 610 611 }; 611 612
+2 -3
drivers/rtc/rtc-pcf8583.c
··· 275 275 .set_time = pcf8583_rtc_set_time, 276 276 }; 277 277 278 - static int pcf8583_probe(struct i2c_client *client, 279 - const struct i2c_device_id *id) 278 + static int pcf8583_probe(struct i2c_client *client) 280 279 { 281 280 struct pcf8583 *pcf8583; 282 281 ··· 306 307 .driver = { 307 308 .name = "pcf8583", 308 309 }, 309 - .probe = pcf8583_probe, 310 + .probe_new = pcf8583_probe, 310 311 .id_table = pcf8583_id, 311 312 }; 312 313
+2 -3
drivers/rtc/rtc-rv3029c2.c
··· 784 784 785 785 #if IS_ENABLED(CONFIG_I2C) 786 786 787 - static int rv3029_i2c_probe(struct i2c_client *client, 788 - const struct i2c_device_id *id) 787 + static int rv3029_i2c_probe(struct i2c_client *client) 789 788 { 790 789 struct regmap *regmap; 791 790 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | ··· 818 819 .name = "rv3029", 819 820 .of_match_table = of_match_ptr(rv3029_of_match), 820 821 }, 821 - .probe = rv3029_i2c_probe, 822 + .probe_new = rv3029_i2c_probe, 822 823 .id_table = rv3029_id, 823 824 }; 824 825
+82 -16
drivers/rtc/rtc-rv8803.c
··· 9 9 10 10 #include <linux/bcd.h> 11 11 #include <linux/bitops.h> 12 + #include <linux/bitfield.h> 12 13 #include <linux/log2.h> 13 14 #include <linux/i2c.h> 14 15 #include <linux/interrupt.h> ··· 34 33 #define RV8803_EXT 0x0D 35 34 #define RV8803_FLAG 0x0E 36 35 #define RV8803_CTRL 0x0F 36 + #define RV8803_OSC_OFFSET 0x2C 37 37 38 38 #define RV8803_EXT_WADA BIT(6) 39 39 ··· 51 49 #define RV8803_CTRL_TIE BIT(4) 52 50 #define RV8803_CTRL_UIE BIT(5) 53 51 52 + #define RX8803_CTRL_CSEL GENMASK(7, 6) 53 + 54 54 #define RX8900_BACKUP_CTRL 0x18 55 55 #define RX8900_FLAG_SWOFF BIT(2) 56 56 #define RX8900_FLAG_VDETOFF BIT(3) 57 57 58 58 enum rv8803_type { 59 59 rv_8803, 60 + rx_8803, 60 61 rx_8804, 61 62 rx_8900 62 63 }; ··· 69 64 struct rtc_device *rtc; 70 65 struct mutex flags_lock; 71 66 u8 ctrl; 67 + u8 backup; 72 68 enum rv8803_type type; 73 69 }; 74 70 ··· 140 134 reg, reg + count - 1); 141 135 142 136 return ret; 137 + } 138 + 139 + static int rv8803_regs_init(struct rv8803_data *rv8803) 140 + { 141 + int ret; 142 + 143 + ret = rv8803_write_reg(rv8803->client, RV8803_OSC_OFFSET, 0x00); 144 + if (ret) 145 + return ret; 146 + 147 + ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, 148 + FIELD_PREP(RX8803_CTRL_CSEL, 1)); /* 2s */ 149 + if (ret) 150 + return ret; 151 + 152 + ret = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3, 153 + (u8[]){ 0, 0, 0 }); 154 + if (ret) 155 + return ret; 156 + 157 + return rv8803_write_reg(rv8803->client, RV8803_RAM, 0x00); 158 + } 159 + 160 + static int rv8803_regs_configure(struct rv8803_data *rv8803); 161 + 162 + static int rv8803_regs_reset(struct rv8803_data *rv8803) 163 + { 164 + /* 165 + * The RV-8803 resets all registers to POR defaults after voltage-loss, 166 + * the Epson RTCs don't, so we manually reset the remainder here. 167 + */ 168 + if (rv8803->type == rx_8803 || rv8803->type == rx_8900) { 169 + int ret = rv8803_regs_init(rv8803); 170 + if (ret) 171 + return ret; 172 + } 173 + 174 + return rv8803_regs_configure(rv8803); 143 175 } 144 176 145 177 static irqreturn_t rv8803_handle_irq(int irq, void *dev_id) ··· 311 267 if (flags < 0) { 312 268 mutex_unlock(&rv8803->flags_lock); 313 269 return flags; 270 + } 271 + 272 + if (flags & RV8803_FLAG_V2F) { 273 + ret = rv8803_regs_reset(rv8803); 274 + if (ret) { 275 + mutex_unlock(&rv8803->flags_lock); 276 + return ret; 277 + } 314 278 } 315 279 316 280 ret = rv8803_write_reg(rv8803->client, RV8803_FLAG, ··· 550 498 if (err < 0) 551 499 return err; 552 500 553 - flags = ~(RX8900_FLAG_VDETOFF | RX8900_FLAG_SWOFF) & (u8)err; 554 - 555 - if (of_property_read_bool(node, "epson,vdet-disable")) 556 - flags |= RX8900_FLAG_VDETOFF; 557 - 558 - if (of_property_read_bool(node, "trickle-diode-disable")) 559 - flags |= RX8900_FLAG_SWOFF; 501 + flags = (u8)err; 502 + flags &= ~(RX8900_FLAG_VDETOFF | RX8900_FLAG_SWOFF); 503 + flags |= rv8803->backup; 560 504 561 505 return i2c_smbus_write_byte_data(rv8803->client, RX8900_BACKUP_CTRL, 562 506 flags); 507 + } 508 + 509 + /* configure registers with values different than the Power-On reset defaults */ 510 + static int rv8803_regs_configure(struct rv8803_data *rv8803) 511 + { 512 + int err; 513 + 514 + err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); 515 + if (err) 516 + return err; 517 + 518 + err = rx8900_trickle_charger_init(rv8803); 519 + if (err) { 520 + dev_err(&rv8803->client->dev, "failed to init charger\n"); 521 + return err; 522 + } 523 + 524 + return 0; 563 525 } 564 526 565 527 static int rv8803_probe(struct i2c_client *client, ··· 642 576 if (!client->irq) 643 577 clear_bit(RTC_FEATURE_ALARM, rv8803->rtc->features); 644 578 645 - err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); 579 + if (of_property_read_bool(client->dev.of_node, "epson,vdet-disable")) 580 + rv8803->backup |= RX8900_FLAG_VDETOFF; 581 + 582 + if (of_property_read_bool(client->dev.of_node, "trickle-diode-disable")) 583 + rv8803->backup |= RX8900_FLAG_SWOFF; 584 + 585 + err = rv8803_regs_configure(rv8803); 646 586 if (err) 647 587 return err; 648 - 649 - err = rx8900_trickle_charger_init(rv8803); 650 - if (err) { 651 - dev_err(&client->dev, "failed to init charger\n"); 652 - return err; 653 - } 654 588 655 589 rv8803->rtc->ops = &rv8803_rtc_ops; 656 590 rv8803->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; ··· 669 603 static const struct i2c_device_id rv8803_id[] = { 670 604 { "rv8803", rv_8803 }, 671 605 { "rv8804", rx_8804 }, 672 - { "rx8803", rv_8803 }, 606 + { "rx8803", rx_8803 }, 673 607 { "rx8900", rx_8900 }, 674 608 { } 675 609 }; ··· 682 616 }, 683 617 { 684 618 .compatible = "epson,rx8803", 685 - .data = (void *)rv_8803 619 + .data = (void *)rx_8803 686 620 }, 687 621 { 688 622 .compatible = "epson,rx8804",
+2 -3
drivers/rtc/rtc-rx6110.c
··· 419 419 .read_flag_mask = 0x80, 420 420 }; 421 421 422 - static int rx6110_i2c_probe(struct i2c_client *client, 423 - const struct i2c_device_id *id) 422 + static int rx6110_i2c_probe(struct i2c_client *client) 424 423 { 425 424 struct i2c_adapter *adapter = client->adapter; 426 425 struct rx6110_data *rx6110; ··· 463 464 .name = RX6110_DRIVER_NAME, 464 465 .acpi_match_table = rx6110_i2c_acpi_match, 465 466 }, 466 - .probe = rx6110_i2c_probe, 467 + .probe_new = rx6110_i2c_probe, 467 468 .id_table = rx6110_i2c_id, 468 469 }; 469 470
+18 -4
drivers/rtc/rtc-rx8025.c
··· 55 55 #define RX8025_BIT_CTRL2_XST BIT(5) 56 56 #define RX8025_BIT_CTRL2_VDET BIT(6) 57 57 58 + #define RX8035_BIT_HOUR_1224 BIT(7) 59 + 58 60 /* Clock precision adjustment */ 59 61 #define RX8025_ADJ_RESOLUTION 3050 /* in ppb */ 60 62 #define RX8025_ADJ_DATA_MAX 62 ··· 80 78 struct rtc_device *rtc; 81 79 enum rx_model model; 82 80 u8 ctrl1; 81 + int is_24; 83 82 }; 84 83 85 84 static s32 rx8025_read_reg(const struct i2c_client *client, u8 number) ··· 229 226 230 227 dt->tm_sec = bcd2bin(date[RX8025_REG_SEC] & 0x7f); 231 228 dt->tm_min = bcd2bin(date[RX8025_REG_MIN] & 0x7f); 232 - if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224) 229 + if (rx8025->is_24) 233 230 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x3f); 234 231 else 235 232 dt->tm_hour = bcd2bin(date[RX8025_REG_HOUR] & 0x1f) % 12 ··· 257 254 */ 258 255 date[RX8025_REG_SEC] = bin2bcd(dt->tm_sec); 259 256 date[RX8025_REG_MIN] = bin2bcd(dt->tm_min); 260 - if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224) 257 + if (rx8025->is_24) 261 258 date[RX8025_REG_HOUR] = bin2bcd(dt->tm_hour); 262 259 else 263 260 date[RX8025_REG_HOUR] = (dt->tm_hour >= 12 ? 0x20 : 0) ··· 282 279 struct rx8025_data *rx8025 = i2c_get_clientdata(client); 283 280 u8 ctrl[2], ctrl2; 284 281 int need_clear = 0; 282 + int hour_reg; 285 283 int err; 286 284 287 285 err = rx8025_read_regs(client, RX8025_REG_CTRL1, 2, ctrl); ··· 306 302 RX8025_BIT_CTRL2_DAFG); 307 303 308 304 err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2); 305 + } 306 + 307 + if (rx8025->model == model_rx_8035) { 308 + /* In RX-8035, 12/24 flag is in the hour register */ 309 + hour_reg = rx8025_read_reg(client, RX8025_REG_HOUR); 310 + if (hour_reg < 0) 311 + return hour_reg; 312 + rx8025->is_24 = (hour_reg & RX8035_BIT_HOUR_1224); 313 + } else { 314 + rx8025->is_24 = (ctrl[1] & RX8025_BIT_CTRL1_1224); 309 315 } 310 316 out: 311 317 return err; ··· 343 329 /* Hardware alarms precision is 1 minute! */ 344 330 t->time.tm_sec = 0; 345 331 t->time.tm_min = bcd2bin(ald[0] & 0x7f); 346 - if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224) 332 + if (rx8025->is_24) 347 333 t->time.tm_hour = bcd2bin(ald[1] & 0x3f); 348 334 else 349 335 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12 ··· 364 350 int err; 365 351 366 352 ald[0] = bin2bcd(t->time.tm_min); 367 - if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224) 353 + if (rx8025->is_24) 368 354 ald[1] = bin2bcd(t->time.tm_hour); 369 355 else 370 356 ald[1] = (t->time.tm_hour >= 12 ? 0x20 : 0)
+2 -3
drivers/rtc/rtc-rx8581.c
··· 248 248 .num_nvram = 2 249 249 }; 250 250 251 - static int rx8581_probe(struct i2c_client *client, 252 - const struct i2c_device_id *id) 251 + static int rx8581_probe(struct i2c_client *client) 253 252 { 254 253 struct rx8581 *rx8581; 255 254 const struct rx85x1_config *config = &rx8581_config; ··· 325 326 .name = "rtc-rx8581", 326 327 .of_match_table = of_match_ptr(rx8581_of_match), 327 328 }, 328 - .probe = rx8581_probe, 329 + .probe_new = rx8581_probe, 329 330 .id_table = rx8581_id, 330 331 }; 331 332
+2 -3
drivers/rtc/rtc-s35390a.c
··· 420 420 .ioctl = s35390a_rtc_ioctl, 421 421 }; 422 422 423 - static int s35390a_probe(struct i2c_client *client, 424 - const struct i2c_device_id *id) 423 + static int s35390a_probe(struct i2c_client *client) 425 424 { 426 425 int err, err_read; 427 426 unsigned int i; ··· 501 502 .name = "rtc-s35390a", 502 503 .of_match_table = of_match_ptr(s35390a_of_match), 503 504 }, 504 - .probe = s35390a_probe, 505 + .probe_new = s35390a_probe, 505 506 .id_table = s35390a_id, 506 507 }; 507 508
+2 -3
drivers/rtc/rtc-sd3078.c
··· 163 163 .max_register = 0x11, 164 164 }; 165 165 166 - static int sd3078_probe(struct i2c_client *client, 167 - const struct i2c_device_id *id) 166 + static int sd3078_probe(struct i2c_client *client) 168 167 { 169 168 int ret; 170 169 struct sd3078 *sd3078; ··· 217 218 .name = "sd3078", 218 219 .of_match_table = of_match_ptr(rtc_dt_match), 219 220 }, 220 - .probe = sd3078_probe, 221 + .probe_new = sd3078_probe, 221 222 .id_table = sd3078_id, 222 223 }; 223 224
+1 -1
drivers/rtc/rtc-spear.c
··· 388 388 389 389 config->rtc->ops = &spear_rtc_ops; 390 390 config->rtc->range_min = RTC_TIMESTAMP_BEGIN_0000; 391 - config->rtc->range_min = RTC_TIMESTAMP_END_9999; 391 + config->rtc->range_max = RTC_TIMESTAMP_END_9999; 392 392 393 393 status = devm_rtc_register_device(config->rtc); 394 394 if (status)
+2
drivers/rtc/rtc-sun6i.c
··· 875 875 { .compatible = "allwinner,sun50i-h6-rtc" }, 876 876 { .compatible = "allwinner,sun50i-h616-rtc", 877 877 .data = (void *)RTC_LINEAR_DAY }, 878 + { .compatible = "allwinner,sun50i-r329-rtc", 879 + .data = (void *)RTC_LINEAR_DAY }, 878 880 { /* sentinel */ }, 879 881 }; 880 882 MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);
+680
drivers/rtc/rtc-ti-k3.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Texas Instruments K3 RTC driver 4 + * 5 + * Copyright (C) 2021-2022 Texas Instruments Incorporated - https://www.ti.com/ 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/delay.h> 10 + #include <linux/mod_devicetable.h> 11 + #include <linux/module.h> 12 + #include <linux/of_device.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/property.h> 15 + #include <linux/regmap.h> 16 + #include <linux/rtc.h> 17 + 18 + /* Registers */ 19 + #define REG_K3RTC_S_CNT_LSW 0x08 20 + #define REG_K3RTC_S_CNT_MSW 0x0c 21 + #define REG_K3RTC_COMP 0x10 22 + #define REG_K3RTC_ON_OFF_S_CNT_LSW 0x20 23 + #define REG_K3RTC_ON_OFF_S_CNT_MSW 0x24 24 + #define REG_K3RTC_SCRATCH0 0x30 25 + #define REG_K3RTC_SCRATCH7 0x4c 26 + #define REG_K3RTC_GENERAL_CTL 0x50 27 + #define REG_K3RTC_IRQSTATUS_RAW_SYS 0x54 28 + #define REG_K3RTC_IRQSTATUS_SYS 0x58 29 + #define REG_K3RTC_IRQENABLE_SET_SYS 0x5c 30 + #define REG_K3RTC_IRQENABLE_CLR_SYS 0x60 31 + #define REG_K3RTC_SYNCPEND 0x68 32 + #define REG_K3RTC_KICK0 0x70 33 + #define REG_K3RTC_KICK1 0x74 34 + 35 + /* Freeze when lsw is read and unfreeze when msw is read */ 36 + #define K3RTC_CNT_FMODE_S_CNT_VALUE (0x2 << 24) 37 + 38 + /* Magic values for lock/unlock */ 39 + #define K3RTC_KICK0_UNLOCK_VALUE 0x83e70b13 40 + #define K3RTC_KICK1_UNLOCK_VALUE 0x95a4f1e0 41 + 42 + /* Multiplier for ppb conversions */ 43 + #define K3RTC_PPB_MULT (1000000000LL) 44 + /* Min and max values supported with 'offset' interface (swapped sign) */ 45 + #define K3RTC_MIN_OFFSET (-277761) 46 + #define K3RTC_MAX_OFFSET (277778) 47 + 48 + /** 49 + * struct ti_k3_rtc_soc_data - Private of compatible data for ti-k3-rtc 50 + * @unlock_irq_erratum: Has erratum for unlock infinite IRQs (erratum i2327) 51 + */ 52 + struct ti_k3_rtc_soc_data { 53 + const bool unlock_irq_erratum; 54 + }; 55 + 56 + static const struct regmap_config ti_k3_rtc_regmap_config = { 57 + .name = "peripheral-registers", 58 + .reg_bits = 32, 59 + .val_bits = 32, 60 + .reg_stride = 4, 61 + .max_register = REG_K3RTC_KICK1, 62 + }; 63 + 64 + enum ti_k3_rtc_fields { 65 + K3RTC_KICK0, 66 + K3RTC_KICK1, 67 + K3RTC_S_CNT_LSW, 68 + K3RTC_S_CNT_MSW, 69 + K3RTC_O32K_OSC_DEP_EN, 70 + K3RTC_UNLOCK, 71 + K3RTC_CNT_FMODE, 72 + K3RTC_PEND, 73 + K3RTC_RELOAD_FROM_BBD, 74 + K3RTC_COMP, 75 + 76 + K3RTC_ALM_S_CNT_LSW, 77 + K3RTC_ALM_S_CNT_MSW, 78 + K3RTC_IRQ_STATUS_RAW, 79 + K3RTC_IRQ_STATUS, 80 + K3RTC_IRQ_ENABLE_SET, 81 + K3RTC_IRQ_ENABLE_CLR, 82 + 83 + K3RTC_IRQ_STATUS_ALT, 84 + K3RTC_IRQ_ENABLE_CLR_ALT, 85 + 86 + K3_RTC_MAX_FIELDS 87 + }; 88 + 89 + static const struct reg_field ti_rtc_reg_fields[] = { 90 + [K3RTC_KICK0] = REG_FIELD(REG_K3RTC_KICK0, 0, 31), 91 + [K3RTC_KICK1] = REG_FIELD(REG_K3RTC_KICK1, 0, 31), 92 + [K3RTC_S_CNT_LSW] = REG_FIELD(REG_K3RTC_S_CNT_LSW, 0, 31), 93 + [K3RTC_S_CNT_MSW] = REG_FIELD(REG_K3RTC_S_CNT_MSW, 0, 15), 94 + [K3RTC_O32K_OSC_DEP_EN] = REG_FIELD(REG_K3RTC_GENERAL_CTL, 21, 21), 95 + [K3RTC_UNLOCK] = REG_FIELD(REG_K3RTC_GENERAL_CTL, 23, 23), 96 + [K3RTC_CNT_FMODE] = REG_FIELD(REG_K3RTC_GENERAL_CTL, 24, 25), 97 + [K3RTC_PEND] = REG_FIELD(REG_K3RTC_SYNCPEND, 0, 1), 98 + [K3RTC_RELOAD_FROM_BBD] = REG_FIELD(REG_K3RTC_SYNCPEND, 31, 31), 99 + [K3RTC_COMP] = REG_FIELD(REG_K3RTC_COMP, 0, 31), 100 + 101 + /* We use on to off as alarm trigger */ 102 + [K3RTC_ALM_S_CNT_LSW] = REG_FIELD(REG_K3RTC_ON_OFF_S_CNT_LSW, 0, 31), 103 + [K3RTC_ALM_S_CNT_MSW] = REG_FIELD(REG_K3RTC_ON_OFF_S_CNT_MSW, 0, 15), 104 + [K3RTC_IRQ_STATUS_RAW] = REG_FIELD(REG_K3RTC_IRQSTATUS_RAW_SYS, 0, 0), 105 + [K3RTC_IRQ_STATUS] = REG_FIELD(REG_K3RTC_IRQSTATUS_SYS, 0, 0), 106 + [K3RTC_IRQ_ENABLE_SET] = REG_FIELD(REG_K3RTC_IRQENABLE_SET_SYS, 0, 0), 107 + [K3RTC_IRQ_ENABLE_CLR] = REG_FIELD(REG_K3RTC_IRQENABLE_CLR_SYS, 0, 0), 108 + /* Off to on is alternate */ 109 + [K3RTC_IRQ_STATUS_ALT] = REG_FIELD(REG_K3RTC_IRQSTATUS_SYS, 1, 1), 110 + [K3RTC_IRQ_ENABLE_CLR_ALT] = REG_FIELD(REG_K3RTC_IRQENABLE_CLR_SYS, 1, 1), 111 + }; 112 + 113 + /** 114 + * struct ti_k3_rtc - Private data for ti-k3-rtc 115 + * @irq: IRQ 116 + * @sync_timeout_us: data sync timeout period in uSec 117 + * @rate_32k: 32k clock rate in Hz 118 + * @rtc_dev: rtc device 119 + * @regmap: rtc mmio regmap 120 + * @r_fields: rtc register fields 121 + * @soc: SoC compatible match data 122 + */ 123 + struct ti_k3_rtc { 124 + unsigned int irq; 125 + u32 sync_timeout_us; 126 + unsigned long rate_32k; 127 + struct rtc_device *rtc_dev; 128 + struct regmap *regmap; 129 + struct regmap_field *r_fields[K3_RTC_MAX_FIELDS]; 130 + const struct ti_k3_rtc_soc_data *soc; 131 + }; 132 + 133 + static int k3rtc_field_read(struct ti_k3_rtc *priv, enum ti_k3_rtc_fields f) 134 + { 135 + int ret; 136 + int val; 137 + 138 + ret = regmap_field_read(priv->r_fields[f], &val); 139 + /* 140 + * We shouldn't be seeing regmap fail on us for mmio reads 141 + * This is possible if clock context fails, but that isn't the case for us 142 + */ 143 + if (WARN_ON_ONCE(ret)) 144 + return ret; 145 + return val; 146 + } 147 + 148 + static void k3rtc_field_write(struct ti_k3_rtc *priv, enum ti_k3_rtc_fields f, u32 val) 149 + { 150 + regmap_field_write(priv->r_fields[f], val); 151 + } 152 + 153 + /** 154 + * k3rtc_fence - Ensure a register sync took place between the two domains 155 + * @priv: pointer to priv data 156 + * 157 + * Return: 0 if the sync took place, else returns -ETIMEDOUT 158 + */ 159 + static int k3rtc_fence(struct ti_k3_rtc *priv) 160 + { 161 + int ret; 162 + 163 + ret = regmap_field_read_poll_timeout(priv->r_fields[K3RTC_PEND], ret, 164 + !ret, 2, priv->sync_timeout_us); 165 + 166 + return ret; 167 + } 168 + 169 + static inline int k3rtc_check_unlocked(struct ti_k3_rtc *priv) 170 + { 171 + int ret; 172 + 173 + ret = k3rtc_field_read(priv, K3RTC_UNLOCK); 174 + if (ret < 0) 175 + return ret; 176 + 177 + return (ret) ? 0 : 1; 178 + } 179 + 180 + static int k3rtc_unlock_rtc(struct ti_k3_rtc *priv) 181 + { 182 + int ret; 183 + 184 + ret = k3rtc_check_unlocked(priv); 185 + if (!ret) 186 + return ret; 187 + 188 + k3rtc_field_write(priv, K3RTC_KICK0, K3RTC_KICK0_UNLOCK_VALUE); 189 + k3rtc_field_write(priv, K3RTC_KICK1, K3RTC_KICK1_UNLOCK_VALUE); 190 + 191 + /* Skip fence since we are going to check the unlock bit as fence */ 192 + ret = regmap_field_read_poll_timeout(priv->r_fields[K3RTC_UNLOCK], ret, 193 + !ret, 2, priv->sync_timeout_us); 194 + 195 + return ret; 196 + } 197 + 198 + static int k3rtc_configure(struct device *dev) 199 + { 200 + int ret; 201 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 202 + 203 + /* 204 + * HWBUG: The compare state machine is broken if the RTC module 205 + * is NOT unlocked in under one second of boot - which is pretty long 206 + * time from the perspective of Linux driver (module load, u-boot 207 + * shell all can take much longer than this. 208 + * 209 + * In such occurrence, it is assumed that the RTC module is unusable 210 + */ 211 + if (priv->soc->unlock_irq_erratum) { 212 + ret = k3rtc_check_unlocked(priv); 213 + /* If there is an error OR if we are locked, return error */ 214 + if (ret) { 215 + dev_err(dev, 216 + HW_ERR "Erratum i2327 unlock QUIRK! Cannot operate!!\n"); 217 + return -EFAULT; 218 + } 219 + } else { 220 + /* May need to explicitly unlock first time */ 221 + ret = k3rtc_unlock_rtc(priv); 222 + if (ret) { 223 + dev_err(dev, "Failed to unlock(%d)!\n", ret); 224 + return ret; 225 + } 226 + } 227 + 228 + /* Enable Shadow register sync on 32k clock boundary */ 229 + k3rtc_field_write(priv, K3RTC_O32K_OSC_DEP_EN, 0x1); 230 + 231 + /* 232 + * Wait at least clock sync time before proceeding further programming. 233 + * This ensures that the 32k based sync is active. 234 + */ 235 + usleep_range(priv->sync_timeout_us, priv->sync_timeout_us + 5); 236 + 237 + /* We need to ensure fence here to make sure sync here */ 238 + ret = k3rtc_fence(priv); 239 + if (ret) { 240 + dev_err(dev, 241 + "Failed fence osc_dep enable(%d) - is 32k clk working?!\n", ret); 242 + return ret; 243 + } 244 + 245 + /* 246 + * FMODE setting: Reading lower seconds will freeze value on higher 247 + * seconds. This also implies that we must *ALWAYS* read lower seconds 248 + * prior to reading higher seconds 249 + */ 250 + k3rtc_field_write(priv, K3RTC_CNT_FMODE, K3RTC_CNT_FMODE_S_CNT_VALUE); 251 + 252 + /* Clear any spurious IRQ sources if any */ 253 + k3rtc_field_write(priv, K3RTC_IRQ_STATUS_ALT, 0x1); 254 + k3rtc_field_write(priv, K3RTC_IRQ_STATUS, 0x1); 255 + /* Disable all IRQs */ 256 + k3rtc_field_write(priv, K3RTC_IRQ_ENABLE_CLR_ALT, 0x1); 257 + k3rtc_field_write(priv, K3RTC_IRQ_ENABLE_CLR, 0x1); 258 + 259 + /* And.. Let us Sync the writes in */ 260 + return k3rtc_fence(priv); 261 + } 262 + 263 + static int ti_k3_rtc_read_time(struct device *dev, struct rtc_time *tm) 264 + { 265 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 266 + u32 seconds_lo, seconds_hi; 267 + 268 + seconds_lo = k3rtc_field_read(priv, K3RTC_S_CNT_LSW); 269 + seconds_hi = k3rtc_field_read(priv, K3RTC_S_CNT_MSW); 270 + 271 + rtc_time64_to_tm((((time64_t)seconds_hi) << 32) | (time64_t)seconds_lo, tm); 272 + 273 + return 0; 274 + } 275 + 276 + static int ti_k3_rtc_set_time(struct device *dev, struct rtc_time *tm) 277 + { 278 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 279 + time64_t seconds; 280 + 281 + seconds = rtc_tm_to_time64(tm); 282 + 283 + /* 284 + * Read operation on LSW will freeze the RTC, so to update 285 + * the time, we cannot use field operations. Just write since the 286 + * reserved bits are ignored. 287 + */ 288 + regmap_write(priv->regmap, REG_K3RTC_S_CNT_LSW, seconds); 289 + regmap_write(priv->regmap, REG_K3RTC_S_CNT_MSW, seconds >> 32); 290 + 291 + return k3rtc_fence(priv); 292 + } 293 + 294 + static int ti_k3_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 295 + { 296 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 297 + u32 reg; 298 + u32 offset = enabled ? K3RTC_IRQ_ENABLE_SET : K3RTC_IRQ_ENABLE_CLR; 299 + 300 + reg = k3rtc_field_read(priv, K3RTC_IRQ_ENABLE_SET); 301 + if ((enabled && reg) || (!enabled && !reg)) 302 + return 0; 303 + 304 + k3rtc_field_write(priv, offset, 0x1); 305 + 306 + /* 307 + * Ensure the write sync is through - NOTE: it should be OK to have 308 + * ISR to fire as we are checking sync (which should be done in a 32k 309 + * cycle or so). 310 + */ 311 + return k3rtc_fence(priv); 312 + } 313 + 314 + static int ti_k3_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 315 + { 316 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 317 + u32 seconds_lo, seconds_hi; 318 + 319 + seconds_lo = k3rtc_field_read(priv, K3RTC_ALM_S_CNT_LSW); 320 + seconds_hi = k3rtc_field_read(priv, K3RTC_ALM_S_CNT_MSW); 321 + 322 + rtc_time64_to_tm((((time64_t)seconds_hi) << 32) | (time64_t)seconds_lo, &alarm->time); 323 + 324 + alarm->enabled = k3rtc_field_read(priv, K3RTC_IRQ_ENABLE_SET); 325 + 326 + return 0; 327 + } 328 + 329 + static int ti_k3_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm) 330 + { 331 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 332 + time64_t seconds; 333 + int ret; 334 + 335 + seconds = rtc_tm_to_time64(&alarm->time); 336 + 337 + k3rtc_field_write(priv, K3RTC_ALM_S_CNT_LSW, seconds); 338 + k3rtc_field_write(priv, K3RTC_ALM_S_CNT_MSW, (seconds >> 32)); 339 + 340 + /* Make sure the alarm time is synced in */ 341 + ret = k3rtc_fence(priv); 342 + if (ret) { 343 + dev_err(dev, "Failed to fence(%d)! Potential config issue?\n", ret); 344 + return ret; 345 + } 346 + 347 + /* Alarm IRQ enable will do a sync */ 348 + return ti_k3_rtc_alarm_irq_enable(dev, alarm->enabled); 349 + } 350 + 351 + static int ti_k3_rtc_read_offset(struct device *dev, long *offset) 352 + { 353 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 354 + u32 ticks_per_hr = priv->rate_32k * 3600; 355 + int comp; 356 + s64 tmp; 357 + 358 + comp = k3rtc_field_read(priv, K3RTC_COMP); 359 + 360 + /* Convert from RTC calibration register format to ppb format */ 361 + tmp = comp * (s64)K3RTC_PPB_MULT; 362 + if (tmp < 0) 363 + tmp -= ticks_per_hr / 2LL; 364 + else 365 + tmp += ticks_per_hr / 2LL; 366 + tmp = div_s64(tmp, ticks_per_hr); 367 + 368 + /* Offset value operates in negative way, so swap sign */ 369 + *offset = (long)-tmp; 370 + 371 + return 0; 372 + } 373 + 374 + static int ti_k3_rtc_set_offset(struct device *dev, long offset) 375 + { 376 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 377 + u32 ticks_per_hr = priv->rate_32k * 3600; 378 + int comp; 379 + s64 tmp; 380 + 381 + /* Make sure offset value is within supported range */ 382 + if (offset < K3RTC_MIN_OFFSET || offset > K3RTC_MAX_OFFSET) 383 + return -ERANGE; 384 + 385 + /* Convert from ppb format to RTC calibration register format */ 386 + tmp = offset * (s64)ticks_per_hr; 387 + if (tmp < 0) 388 + tmp -= K3RTC_PPB_MULT / 2LL; 389 + else 390 + tmp += K3RTC_PPB_MULT / 2LL; 391 + tmp = div_s64(tmp, K3RTC_PPB_MULT); 392 + 393 + /* Offset value operates in negative way, so swap sign */ 394 + comp = (int)-tmp; 395 + 396 + k3rtc_field_write(priv, K3RTC_COMP, comp); 397 + 398 + return k3rtc_fence(priv); 399 + } 400 + 401 + static irqreturn_t ti_k3_rtc_interrupt(s32 irq, void *dev_id) 402 + { 403 + struct device *dev = dev_id; 404 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 405 + u32 reg; 406 + int ret; 407 + 408 + /* 409 + * IRQ assertion can be very fast, however, the IRQ Status clear 410 + * de-assert depends on 32k clock edge in the 32k domain 411 + * If we clear the status prior to the first 32k clock edge, 412 + * the status bit is cleared, but the IRQ stays re-asserted. 413 + * 414 + * To prevent this condition, we need to wait for clock sync time. 415 + * We can either do that by polling the 32k observability signal for 416 + * a toggle OR we could just sleep and let the processor do other 417 + * stuff. 418 + */ 419 + usleep_range(priv->sync_timeout_us, priv->sync_timeout_us + 2); 420 + 421 + /* Lets make sure that this is a valid interrupt */ 422 + reg = k3rtc_field_read(priv, K3RTC_IRQ_STATUS); 423 + 424 + if (!reg) { 425 + u32 raw = k3rtc_field_read(priv, K3RTC_IRQ_STATUS_RAW); 426 + 427 + dev_err(dev, 428 + HW_ERR 429 + "Erratum i2327/IRQ trig: status: 0x%08x / 0x%08x\n", reg, raw); 430 + return IRQ_NONE; 431 + } 432 + 433 + /* 434 + * Write 1 to clear status reg 435 + * We cannot use a field operation here due to a potential race between 436 + * 32k domain and vbus domain. 437 + */ 438 + regmap_write(priv->regmap, REG_K3RTC_IRQSTATUS_SYS, 0x1); 439 + 440 + /* Sync the write in */ 441 + ret = k3rtc_fence(priv); 442 + if (ret) { 443 + dev_err(dev, "Failed to fence irq status clr(%d)!\n", ret); 444 + return IRQ_NONE; 445 + } 446 + 447 + /* 448 + * Force the 32k status to be reloaded back in to ensure status is 449 + * reflected back correctly. 450 + */ 451 + k3rtc_field_write(priv, K3RTC_RELOAD_FROM_BBD, 0x1); 452 + 453 + /* Ensure the write sync is through */ 454 + ret = k3rtc_fence(priv); 455 + if (ret) { 456 + dev_err(dev, "Failed to fence reload from bbd(%d)!\n", ret); 457 + return IRQ_NONE; 458 + } 459 + 460 + /* Now we ensure that the status bit is cleared */ 461 + ret = regmap_field_read_poll_timeout(priv->r_fields[K3RTC_IRQ_STATUS], 462 + ret, !ret, 2, priv->sync_timeout_us); 463 + if (ret) { 464 + dev_err(dev, "Time out waiting for status clear\n"); 465 + return IRQ_NONE; 466 + } 467 + 468 + /* Notify RTC core on event */ 469 + rtc_update_irq(priv->rtc_dev, 1, RTC_IRQF | RTC_AF); 470 + 471 + return IRQ_HANDLED; 472 + } 473 + 474 + static const struct rtc_class_ops ti_k3_rtc_ops = { 475 + .read_time = ti_k3_rtc_read_time, 476 + .set_time = ti_k3_rtc_set_time, 477 + .read_alarm = ti_k3_rtc_read_alarm, 478 + .set_alarm = ti_k3_rtc_set_alarm, 479 + .read_offset = ti_k3_rtc_read_offset, 480 + .set_offset = ti_k3_rtc_set_offset, 481 + .alarm_irq_enable = ti_k3_rtc_alarm_irq_enable, 482 + }; 483 + 484 + static int ti_k3_rtc_scratch_read(void *priv_data, unsigned int offset, 485 + void *val, size_t bytes) 486 + { 487 + struct ti_k3_rtc *priv = (struct ti_k3_rtc *)priv_data; 488 + 489 + return regmap_bulk_read(priv->regmap, REG_K3RTC_SCRATCH0 + offset, val, bytes / 4); 490 + } 491 + 492 + static int ti_k3_rtc_scratch_write(void *priv_data, unsigned int offset, 493 + void *val, size_t bytes) 494 + { 495 + struct ti_k3_rtc *priv = (struct ti_k3_rtc *)priv_data; 496 + int ret; 497 + 498 + ret = regmap_bulk_write(priv->regmap, REG_K3RTC_SCRATCH0 + offset, val, bytes / 4); 499 + if (ret) 500 + return ret; 501 + 502 + return k3rtc_fence(priv); 503 + } 504 + 505 + static struct nvmem_config ti_k3_rtc_nvmem_config = { 506 + .name = "ti_k3_rtc_scratch", 507 + .word_size = 4, 508 + .stride = 4, 509 + .size = REG_K3RTC_SCRATCH7 - REG_K3RTC_SCRATCH0 + 4, 510 + .reg_read = ti_k3_rtc_scratch_read, 511 + .reg_write = ti_k3_rtc_scratch_write, 512 + }; 513 + 514 + static int k3rtc_get_32kclk(struct device *dev, struct ti_k3_rtc *priv) 515 + { 516 + int ret; 517 + struct clk *clk; 518 + 519 + clk = devm_clk_get(dev, "osc32k"); 520 + if (IS_ERR(clk)) 521 + return PTR_ERR(clk); 522 + 523 + ret = clk_prepare_enable(clk); 524 + if (ret) 525 + return ret; 526 + 527 + ret = devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk); 528 + if (ret) 529 + return ret; 530 + 531 + priv->rate_32k = clk_get_rate(clk); 532 + 533 + /* Make sure we are exact 32k clock. Else, try to compensate delay */ 534 + if (priv->rate_32k != 32768) 535 + dev_warn(dev, "Clock rate %ld is not 32768! Could misbehave!\n", 536 + priv->rate_32k); 537 + 538 + /* 539 + * Sync timeout should be two 32k clk sync cycles = ~61uS. We double 540 + * it to comprehend intermediate bus segment and cpu frequency 541 + * deltas 542 + */ 543 + priv->sync_timeout_us = (u32)(DIV_ROUND_UP_ULL(1000000, priv->rate_32k) * 4); 544 + 545 + return ret; 546 + } 547 + 548 + static int k3rtc_get_vbusclk(struct device *dev, struct ti_k3_rtc *priv) 549 + { 550 + int ret; 551 + struct clk *clk; 552 + 553 + /* Note: VBUS isn't a context clock, it is needed for hardware operation */ 554 + clk = devm_clk_get(dev, "vbus"); 555 + if (IS_ERR(clk)) 556 + return PTR_ERR(clk); 557 + 558 + ret = clk_prepare_enable(clk); 559 + if (ret) 560 + return ret; 561 + 562 + return devm_add_action_or_reset(dev, (void (*)(void *))clk_disable_unprepare, clk); 563 + } 564 + 565 + static int ti_k3_rtc_probe(struct platform_device *pdev) 566 + { 567 + struct device *dev = &pdev->dev; 568 + struct ti_k3_rtc *priv; 569 + void __iomem *rtc_base; 570 + int ret; 571 + 572 + priv = devm_kzalloc(dev, sizeof(struct ti_k3_rtc), GFP_KERNEL); 573 + if (!priv) 574 + return -ENOMEM; 575 + 576 + rtc_base = devm_platform_ioremap_resource(pdev, 0); 577 + if (IS_ERR(rtc_base)) 578 + return PTR_ERR(rtc_base); 579 + 580 + priv->regmap = devm_regmap_init_mmio(dev, rtc_base, &ti_k3_rtc_regmap_config); 581 + if (IS_ERR(priv->regmap)) 582 + return PTR_ERR(priv->regmap); 583 + 584 + ret = devm_regmap_field_bulk_alloc(dev, priv->regmap, priv->r_fields, 585 + ti_rtc_reg_fields, K3_RTC_MAX_FIELDS); 586 + if (ret) 587 + return ret; 588 + 589 + ret = k3rtc_get_32kclk(dev, priv); 590 + if (ret) 591 + return ret; 592 + ret = k3rtc_get_vbusclk(dev, priv); 593 + if (ret) 594 + return ret; 595 + 596 + ret = platform_get_irq(pdev, 0); 597 + if (ret < 0) 598 + return ret; 599 + priv->irq = (unsigned int)ret; 600 + 601 + priv->rtc_dev = devm_rtc_allocate_device(dev); 602 + if (IS_ERR(priv->rtc_dev)) 603 + return PTR_ERR(priv->rtc_dev); 604 + 605 + priv->soc = of_device_get_match_data(dev); 606 + 607 + priv->rtc_dev->ops = &ti_k3_rtc_ops; 608 + priv->rtc_dev->range_max = (1ULL << 48) - 1; /* 48Bit seconds */ 609 + ti_k3_rtc_nvmem_config.priv = priv; 610 + 611 + ret = devm_request_threaded_irq(dev, priv->irq, NULL, 612 + ti_k3_rtc_interrupt, 613 + IRQF_TRIGGER_HIGH | IRQF_ONESHOT, 614 + dev_name(dev), dev); 615 + if (ret) { 616 + dev_err(dev, "Could not request IRQ: %d\n", ret); 617 + return ret; 618 + } 619 + 620 + platform_set_drvdata(pdev, priv); 621 + 622 + ret = k3rtc_configure(dev); 623 + if (ret) 624 + return ret; 625 + 626 + if (device_property_present(dev, "wakeup-source")) 627 + device_init_wakeup(dev, true); 628 + else 629 + device_set_wakeup_capable(dev, true); 630 + 631 + ret = devm_rtc_register_device(priv->rtc_dev); 632 + if (ret) 633 + return ret; 634 + 635 + return devm_rtc_nvmem_register(priv->rtc_dev, &ti_k3_rtc_nvmem_config); 636 + } 637 + 638 + static const struct ti_k3_rtc_soc_data ti_k3_am62_data = { 639 + .unlock_irq_erratum = true, 640 + }; 641 + 642 + static const struct of_device_id ti_k3_rtc_of_match_table[] = { 643 + {.compatible = "ti,am62-rtc", .data = &ti_k3_am62_data}, 644 + {} 645 + }; 646 + MODULE_DEVICE_TABLE(of, ti_k3_rtc_of_match_table); 647 + 648 + static int __maybe_unused ti_k3_rtc_suspend(struct device *dev) 649 + { 650 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 651 + 652 + if (device_may_wakeup(dev)) 653 + enable_irq_wake(priv->irq); 654 + return 0; 655 + } 656 + 657 + static int __maybe_unused ti_k3_rtc_resume(struct device *dev) 658 + { 659 + struct ti_k3_rtc *priv = dev_get_drvdata(dev); 660 + 661 + if (device_may_wakeup(dev)) 662 + disable_irq_wake(priv->irq); 663 + return 0; 664 + } 665 + 666 + static SIMPLE_DEV_PM_OPS(ti_k3_rtc_pm_ops, ti_k3_rtc_suspend, ti_k3_rtc_resume); 667 + 668 + static struct platform_driver ti_k3_rtc_driver = { 669 + .probe = ti_k3_rtc_probe, 670 + .driver = { 671 + .name = "rtc-ti-k3", 672 + .of_match_table = ti_k3_rtc_of_match_table, 673 + .pm = &ti_k3_rtc_pm_ops, 674 + }, 675 + }; 676 + module_platform_driver(ti_k3_rtc_driver); 677 + 678 + MODULE_LICENSE("GPL"); 679 + MODULE_DESCRIPTION("TI K3 RTC driver"); 680 + MODULE_AUTHOR("Nishanth Menon");
-363
drivers/rtc/rtc-vr41xx.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * Driver for NEC VR4100 series Real Time Clock unit. 4 - * 5 - * Copyright (C) 2003-2008 Yoichi Yuasa <yuasa@linux-mips.org> 6 - */ 7 - #include <linux/compat.h> 8 - #include <linux/err.h> 9 - #include <linux/fs.h> 10 - #include <linux/init.h> 11 - #include <linux/io.h> 12 - #include <linux/ioport.h> 13 - #include <linux/interrupt.h> 14 - #include <linux/module.h> 15 - #include <linux/platform_device.h> 16 - #include <linux/rtc.h> 17 - #include <linux/spinlock.h> 18 - #include <linux/types.h> 19 - #include <linux/uaccess.h> 20 - #include <linux/log2.h> 21 - 22 - #include <asm/div64.h> 23 - 24 - MODULE_AUTHOR("Yoichi Yuasa <yuasa@linux-mips.org>"); 25 - MODULE_DESCRIPTION("NEC VR4100 series RTC driver"); 26 - MODULE_LICENSE("GPL v2"); 27 - 28 - /* RTC 1 registers */ 29 - #define ETIMELREG 0x00 30 - #define ETIMEMREG 0x02 31 - #define ETIMEHREG 0x04 32 - /* RFU */ 33 - #define ECMPLREG 0x08 34 - #define ECMPMREG 0x0a 35 - #define ECMPHREG 0x0c 36 - /* RFU */ 37 - #define RTCL1LREG 0x10 38 - #define RTCL1HREG 0x12 39 - #define RTCL1CNTLREG 0x14 40 - #define RTCL1CNTHREG 0x16 41 - #define RTCL2LREG 0x18 42 - #define RTCL2HREG 0x1a 43 - #define RTCL2CNTLREG 0x1c 44 - #define RTCL2CNTHREG 0x1e 45 - 46 - /* RTC 2 registers */ 47 - #define TCLKLREG 0x00 48 - #define TCLKHREG 0x02 49 - #define TCLKCNTLREG 0x04 50 - #define TCLKCNTHREG 0x06 51 - /* RFU */ 52 - #define RTCINTREG 0x1e 53 - #define TCLOCK_INT 0x08 54 - #define RTCLONG2_INT 0x04 55 - #define RTCLONG1_INT 0x02 56 - #define ELAPSEDTIME_INT 0x01 57 - 58 - #define RTC_FREQUENCY 32768 59 - #define MAX_PERIODIC_RATE 6553 60 - 61 - static void __iomem *rtc1_base; 62 - static void __iomem *rtc2_base; 63 - 64 - #define rtc1_read(offset) readw(rtc1_base + (offset)) 65 - #define rtc1_write(offset, value) writew((value), rtc1_base + (offset)) 66 - 67 - #define rtc2_read(offset) readw(rtc2_base + (offset)) 68 - #define rtc2_write(offset, value) writew((value), rtc2_base + (offset)) 69 - 70 - /* 32-bit compat for ioctls that nobody else uses */ 71 - #define RTC_EPOCH_READ32 _IOR('p', 0x0d, __u32) 72 - 73 - static unsigned long epoch = 1970; /* Jan 1 1970 00:00:00 */ 74 - 75 - static DEFINE_SPINLOCK(rtc_lock); 76 - static char rtc_name[] = "RTC"; 77 - static unsigned long periodic_count; 78 - static unsigned int alarm_enabled; 79 - static int aie_irq; 80 - static int pie_irq; 81 - 82 - static inline time64_t read_elapsed_second(void) 83 - { 84 - 85 - unsigned long first_low, first_mid, first_high; 86 - 87 - unsigned long second_low, second_mid, second_high; 88 - 89 - do { 90 - first_low = rtc1_read(ETIMELREG); 91 - first_mid = rtc1_read(ETIMEMREG); 92 - first_high = rtc1_read(ETIMEHREG); 93 - second_low = rtc1_read(ETIMELREG); 94 - second_mid = rtc1_read(ETIMEMREG); 95 - second_high = rtc1_read(ETIMEHREG); 96 - } while (first_low != second_low || first_mid != second_mid || 97 - first_high != second_high); 98 - 99 - return ((u64)first_high << 17) | (first_mid << 1) | (first_low >> 15); 100 - } 101 - 102 - static inline void write_elapsed_second(time64_t sec) 103 - { 104 - spin_lock_irq(&rtc_lock); 105 - 106 - rtc1_write(ETIMELREG, (uint16_t)(sec << 15)); 107 - rtc1_write(ETIMEMREG, (uint16_t)(sec >> 1)); 108 - rtc1_write(ETIMEHREG, (uint16_t)(sec >> 17)); 109 - 110 - spin_unlock_irq(&rtc_lock); 111 - } 112 - 113 - static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time) 114 - { 115 - time64_t epoch_sec, elapsed_sec; 116 - 117 - epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); 118 - elapsed_sec = read_elapsed_second(); 119 - 120 - rtc_time64_to_tm(epoch_sec + elapsed_sec, time); 121 - 122 - return 0; 123 - } 124 - 125 - static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time) 126 - { 127 - time64_t epoch_sec, current_sec; 128 - 129 - epoch_sec = mktime64(epoch, 1, 1, 0, 0, 0); 130 - current_sec = rtc_tm_to_time64(time); 131 - 132 - write_elapsed_second(current_sec - epoch_sec); 133 - 134 - return 0; 135 - } 136 - 137 - static int vr41xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 138 - { 139 - unsigned long low, mid, high; 140 - struct rtc_time *time = &wkalrm->time; 141 - 142 - spin_lock_irq(&rtc_lock); 143 - 144 - low = rtc1_read(ECMPLREG); 145 - mid = rtc1_read(ECMPMREG); 146 - high = rtc1_read(ECMPHREG); 147 - wkalrm->enabled = alarm_enabled; 148 - 149 - spin_unlock_irq(&rtc_lock); 150 - 151 - rtc_time64_to_tm((high << 17) | (mid << 1) | (low >> 15), time); 152 - 153 - return 0; 154 - } 155 - 156 - static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 157 - { 158 - time64_t alarm_sec; 159 - 160 - alarm_sec = rtc_tm_to_time64(&wkalrm->time); 161 - 162 - spin_lock_irq(&rtc_lock); 163 - 164 - if (alarm_enabled) 165 - disable_irq(aie_irq); 166 - 167 - rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15)); 168 - rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1)); 169 - rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17)); 170 - 171 - if (wkalrm->enabled) 172 - enable_irq(aie_irq); 173 - 174 - alarm_enabled = wkalrm->enabled; 175 - 176 - spin_unlock_irq(&rtc_lock); 177 - 178 - return 0; 179 - } 180 - 181 - static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 182 - { 183 - switch (cmd) { 184 - case RTC_EPOCH_READ: 185 - return put_user(epoch, (unsigned long __user *)arg); 186 - #ifdef CONFIG_64BIT 187 - case RTC_EPOCH_READ32: 188 - return put_user(epoch, (unsigned int __user *)arg); 189 - #endif 190 - case RTC_EPOCH_SET: 191 - /* Doesn't support before 1900 */ 192 - if (arg < 1900) 193 - return -EINVAL; 194 - epoch = arg; 195 - break; 196 - default: 197 - return -ENOIOCTLCMD; 198 - } 199 - 200 - return 0; 201 - } 202 - 203 - static int vr41xx_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 204 - { 205 - spin_lock_irq(&rtc_lock); 206 - if (enabled) { 207 - if (!alarm_enabled) { 208 - enable_irq(aie_irq); 209 - alarm_enabled = 1; 210 - } 211 - } else { 212 - if (alarm_enabled) { 213 - disable_irq(aie_irq); 214 - alarm_enabled = 0; 215 - } 216 - } 217 - spin_unlock_irq(&rtc_lock); 218 - return 0; 219 - } 220 - 221 - static irqreturn_t elapsedtime_interrupt(int irq, void *dev_id) 222 - { 223 - struct platform_device *pdev = (struct platform_device *)dev_id; 224 - struct rtc_device *rtc = platform_get_drvdata(pdev); 225 - 226 - rtc2_write(RTCINTREG, ELAPSEDTIME_INT); 227 - 228 - rtc_update_irq(rtc, 1, RTC_AF); 229 - 230 - return IRQ_HANDLED; 231 - } 232 - 233 - static irqreturn_t rtclong1_interrupt(int irq, void *dev_id) 234 - { 235 - struct platform_device *pdev = (struct platform_device *)dev_id; 236 - struct rtc_device *rtc = platform_get_drvdata(pdev); 237 - unsigned long count = periodic_count; 238 - 239 - rtc2_write(RTCINTREG, RTCLONG1_INT); 240 - 241 - rtc1_write(RTCL1LREG, count); 242 - rtc1_write(RTCL1HREG, count >> 16); 243 - 244 - rtc_update_irq(rtc, 1, RTC_PF); 245 - 246 - return IRQ_HANDLED; 247 - } 248 - 249 - static const struct rtc_class_ops vr41xx_rtc_ops = { 250 - .ioctl = vr41xx_rtc_ioctl, 251 - .read_time = vr41xx_rtc_read_time, 252 - .set_time = vr41xx_rtc_set_time, 253 - .read_alarm = vr41xx_rtc_read_alarm, 254 - .set_alarm = vr41xx_rtc_set_alarm, 255 - .alarm_irq_enable = vr41xx_rtc_alarm_irq_enable, 256 - }; 257 - 258 - static int rtc_probe(struct platform_device *pdev) 259 - { 260 - struct resource *res; 261 - struct rtc_device *rtc; 262 - int retval; 263 - 264 - if (pdev->num_resources != 4) 265 - return -EBUSY; 266 - 267 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 268 - if (!res) 269 - return -EBUSY; 270 - 271 - rtc1_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 272 - if (!rtc1_base) 273 - return -EBUSY; 274 - 275 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 276 - if (!res) { 277 - retval = -EBUSY; 278 - goto err_rtc1_iounmap; 279 - } 280 - 281 - rtc2_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 282 - if (!rtc2_base) { 283 - retval = -EBUSY; 284 - goto err_rtc1_iounmap; 285 - } 286 - 287 - rtc = devm_rtc_allocate_device(&pdev->dev); 288 - if (IS_ERR(rtc)) { 289 - retval = PTR_ERR(rtc); 290 - goto err_iounmap_all; 291 - } 292 - 293 - rtc->ops = &vr41xx_rtc_ops; 294 - 295 - /* 48-bit counter at 32.768 kHz */ 296 - rtc->range_max = (1ULL << 33) - 1; 297 - rtc->max_user_freq = MAX_PERIODIC_RATE; 298 - 299 - spin_lock_irq(&rtc_lock); 300 - 301 - rtc1_write(ECMPLREG, 0); 302 - rtc1_write(ECMPMREG, 0); 303 - rtc1_write(ECMPHREG, 0); 304 - rtc1_write(RTCL1LREG, 0); 305 - rtc1_write(RTCL1HREG, 0); 306 - 307 - spin_unlock_irq(&rtc_lock); 308 - 309 - aie_irq = platform_get_irq(pdev, 0); 310 - if (aie_irq <= 0) { 311 - retval = -EBUSY; 312 - goto err_iounmap_all; 313 - } 314 - 315 - retval = devm_request_irq(&pdev->dev, aie_irq, elapsedtime_interrupt, 0, 316 - "elapsed_time", pdev); 317 - if (retval < 0) 318 - goto err_iounmap_all; 319 - 320 - pie_irq = platform_get_irq(pdev, 1); 321 - if (pie_irq <= 0) { 322 - retval = -EBUSY; 323 - goto err_iounmap_all; 324 - } 325 - 326 - retval = devm_request_irq(&pdev->dev, pie_irq, rtclong1_interrupt, 0, 327 - "rtclong1", pdev); 328 - if (retval < 0) 329 - goto err_iounmap_all; 330 - 331 - platform_set_drvdata(pdev, rtc); 332 - 333 - disable_irq(aie_irq); 334 - disable_irq(pie_irq); 335 - 336 - dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n"); 337 - 338 - retval = devm_rtc_register_device(rtc); 339 - if (retval) 340 - goto err_iounmap_all; 341 - 342 - return 0; 343 - 344 - err_iounmap_all: 345 - rtc2_base = NULL; 346 - 347 - err_rtc1_iounmap: 348 - rtc1_base = NULL; 349 - 350 - return retval; 351 - } 352 - 353 - /* work with hotplug and coldplug */ 354 - MODULE_ALIAS("platform:RTC"); 355 - 356 - static struct platform_driver rtc_platform_driver = { 357 - .probe = rtc_probe, 358 - .driver = { 359 - .name = rtc_name, 360 - }, 361 - }; 362 - 363 - module_platform_driver(rtc_platform_driver);
+2 -3
drivers/rtc/rtc-x1205.c
··· 614 614 } 615 615 616 616 617 - static int x1205_probe(struct i2c_client *client, 618 - const struct i2c_device_id *id) 617 + static int x1205_probe(struct i2c_client *client) 619 618 { 620 619 int err = 0; 621 620 unsigned char sr; ··· 680 681 .name = "rtc-x1205", 681 682 .of_match_table = x1205_dt_ids, 682 683 }, 683 - .probe = x1205_probe, 684 + .probe_new = x1205_probe, 684 685 .remove = x1205_remove, 685 686 .id_table = x1205_id, 686 687 };
+95 -20
drivers/rtc/rtc-zynqmp.c
··· 6 6 * 7 7 */ 8 8 9 + #include <linux/clk.h> 9 10 #include <linux/delay.h> 10 11 #include <linux/init.h> 11 12 #include <linux/io.h> ··· 37 36 #define RTC_OSC_EN BIT(24) 38 37 #define RTC_BATT_EN BIT(31) 39 38 40 - #define RTC_CALIB_DEF 0x198233 39 + #define RTC_CALIB_DEF 0x7FFF 41 40 #define RTC_CALIB_MASK 0x1FFFFF 42 41 #define RTC_ALRM_MASK BIT(1) 43 42 #define RTC_MSEC 1000 43 + #define RTC_FR_MASK 0xF0000 44 + #define RTC_FR_MAX_TICKS 16 45 + #define RTC_PPB 1000000000LL 46 + #define RTC_MIN_OFFSET -32768000 47 + #define RTC_MAX_OFFSET 32767000 44 48 45 49 struct xlnx_rtc_dev { 46 50 struct rtc_device *rtc; 47 51 void __iomem *reg_base; 48 52 int alarm_irq; 49 53 int sec_irq; 50 - unsigned int calibval; 54 + struct clk *rtc_clk; 55 + unsigned int freq; 51 56 }; 52 57 53 58 static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) ··· 67 60 * to get the correct time on read. 68 61 */ 69 62 new_time = rtc_tm_to_time64(tm) + 1; 70 - 71 - /* 72 - * Writing into calibration register will clear the Tick Counter and 73 - * force the next second to be signaled exactly in 1 second period 74 - */ 75 - xrtcdev->calibval &= RTC_CALIB_MASK; 76 - writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); 77 63 78 64 writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); 79 65 ··· 173 173 rtc_ctrl = readl(xrtcdev->reg_base + RTC_CTRL); 174 174 rtc_ctrl |= RTC_BATT_EN; 175 175 writel(rtc_ctrl, xrtcdev->reg_base + RTC_CTRL); 176 + } 176 177 177 - /* 178 - * Based on crystal freq of 33.330 KHz 179 - * set the seconds counter and enable, set fractions counter 180 - * to default value suggested as per design spec 181 - * to correct RTC delay in frequency over period of time. 178 + static int xlnx_rtc_read_offset(struct device *dev, long *offset) 179 + { 180 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 181 + unsigned long long rtc_ppb = RTC_PPB; 182 + unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq); 183 + unsigned int calibval; 184 + long offset_val; 185 + 186 + calibval = readl(xrtcdev->reg_base + RTC_CALIB_RD); 187 + /* Offset with seconds ticks */ 188 + offset_val = calibval & RTC_TICK_MASK; 189 + offset_val = offset_val - RTC_CALIB_DEF; 190 + offset_val = offset_val * tick_mult; 191 + 192 + /* Offset with fractional ticks */ 193 + if (calibval & RTC_FR_EN) 194 + offset_val += ((calibval & RTC_FR_MASK) >> RTC_FR_DATSHIFT) 195 + * (tick_mult / RTC_FR_MAX_TICKS); 196 + *offset = offset_val; 197 + 198 + return 0; 199 + } 200 + 201 + static int xlnx_rtc_set_offset(struct device *dev, long offset) 202 + { 203 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 204 + unsigned long long rtc_ppb = RTC_PPB; 205 + unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq); 206 + unsigned char fract_tick = 0; 207 + unsigned int calibval; 208 + short int max_tick; 209 + int fract_offset; 210 + 211 + if (offset < RTC_MIN_OFFSET || offset > RTC_MAX_OFFSET) 212 + return -ERANGE; 213 + 214 + /* Number ticks for given offset */ 215 + max_tick = div_s64_rem(offset, tick_mult, &fract_offset); 216 + 217 + /* Number fractional ticks for given offset */ 218 + if (fract_offset) { 219 + if (fract_offset < 0) { 220 + fract_offset = fract_offset + tick_mult; 221 + max_tick--; 222 + } 223 + if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) { 224 + for (fract_tick = 1; fract_tick < 16; fract_tick++) { 225 + if (fract_offset <= 226 + (fract_tick * 227 + (tick_mult / RTC_FR_MAX_TICKS))) 228 + break; 229 + } 230 + } 231 + } 232 + 233 + /* Zynqmp RTC uses second and fractional tick 234 + * counters for compensation 182 235 */ 183 - xrtcdev->calibval &= RTC_CALIB_MASK; 184 - writel(xrtcdev->calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); 236 + calibval = max_tick + RTC_CALIB_DEF; 237 + 238 + if (fract_tick) 239 + calibval |= RTC_FR_EN; 240 + 241 + calibval |= (fract_tick << RTC_FR_DATSHIFT); 242 + 243 + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); 244 + 245 + return 0; 185 246 } 186 247 187 248 static const struct rtc_class_ops xlnx_rtc_ops = { ··· 251 190 .read_alarm = xlnx_rtc_read_alarm, 252 191 .set_alarm = xlnx_rtc_set_alarm, 253 192 .alarm_irq_enable = xlnx_rtc_alarm_irq_enable, 193 + .read_offset = xlnx_rtc_read_offset, 194 + .set_offset = xlnx_rtc_set_offset, 254 195 }; 255 196 256 197 static irqreturn_t xlnx_rtc_interrupt(int irq, void *id) ··· 318 255 return ret; 319 256 } 320 257 321 - ret = of_property_read_u32(pdev->dev.of_node, "calibration", 322 - &xrtcdev->calibval); 323 - if (ret) 324 - xrtcdev->calibval = RTC_CALIB_DEF; 258 + /* Getting the rtc_clk info */ 259 + xrtcdev->rtc_clk = devm_clk_get_optional(&pdev->dev, "rtc_clk"); 260 + if (IS_ERR(xrtcdev->rtc_clk)) { 261 + if (PTR_ERR(xrtcdev->rtc_clk) != -EPROBE_DEFER) 262 + dev_warn(&pdev->dev, "Device clock not found.\n"); 263 + } 264 + xrtcdev->freq = clk_get_rate(xrtcdev->rtc_clk); 265 + if (!xrtcdev->freq) { 266 + ret = of_property_read_u32(pdev->dev.of_node, "calibration", 267 + &xrtcdev->freq); 268 + if (ret) 269 + xrtcdev->freq = RTC_CALIB_DEF; 270 + } 271 + ret = readl(xrtcdev->reg_base + RTC_CALIB_RD); 272 + if (!ret) 273 + writel(xrtcdev->freq, (xrtcdev->reg_base + RTC_CALIB_WR)); 325 274 326 275 xlnx_init_rtc(xrtcdev); 327 276