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

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

Pull RTC updates from Alexandre Belloni:
"Core:
- use is_visible() to control sysfs attributes
- switch wakealarm attribute to DEVICE_ATTR_RW
- make rtc_does_wakealarm() return boolean
- properly manage lifetime of dev and cdev in rtc device
- remove unnecessary device_get() in rtc_device_unregister
- fix double free in rtc_register_device() error path

New drivers:
- NXP LPC24xx
- Xilinx Zynq MP
- Dialog DA9062

Subsystem wide cleanups:
- fix drivers that consider 0 as a valid IRQ in client->irq
- Drop (un)likely before IS_ERR(_OR_NULL)
- drop the remaining owner assignment for i2c_driver and
platform_driver
- module autoload fixes

Drivers:
- 88pm80x: add device tree support
- abx80x: fix RTC write bit
- ab8500: Add a sentinel to ab85xx_rtc_ids[]
- armada38x: Align RTC set time procedure with the official errata
- as3722: correct month value
- at91sam9: cleanups
- at91rm9200: get and use slow clock and cleanups
- bq32k: remove redundant check
- cmos: century support, proper fix for the spurious wakeup
- ds1307: cleanups and wakeup irq support
- ds1374: Remove unused variable
- ds1685: Use module_platform_driver
- ds3232: fix WARNING trace in resume function
- gemini: fix ptr_ret.cocci warnings
- mt6397: implement suspend/resume
- omap: support internal and external clock enabling
- opal: Enable alarms only when opal supports tpo
- pcf2127: use OFS flag to detect unreliable date and warn the user
- pl031: fix typo for author email
- rx8025: huge cleanup and fixes
- sa1100/pxa: share common code
- s5m: fix to update ctrl register
- s3c: fix clocks and wakeup, cleanup
- sirfsoc: use regmap
- nvram_read()/nvram_write() functions for cmos, ds1305, ds1307,
ds1343, ds1511, ds1553, ds1742, m48t59, rp5c01, stk17ta8, tx4939
- use rtc_valid_tm() error code when reading date/time instead of 0
for isl12022, pcf2123, pcf2127"

* tag 'rtc-v4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (90 commits)
rtc: abx80x: fix RTC write bit
rtc: ab8500: Add a sentinel to ab85xx_rtc_ids[]
rtc: ds1374: Remove unused variable
rtc: Fix module autoload for OF platform drivers
rtc: Fix module autoload for rtc-{ab8500,max8997,s5m} drivers
rtc: omap: Add external clock enabling support
rtc: omap: Add internal clock enabling support
ARM: dts: AM437x: Add the internal and external clock nodes for rtc
rtc: s5m: fix to update ctrl register
rtc: add xilinx zynqmp rtc driver
devicetree: bindings: rtc: add bindings for xilinx zynqmp rtc
rtc: as3722: correct month value
ARM: config: Switch PXA27x platforms to use PXA RTC driver
ARM: mmp: remove unused RTC register definitions
ARM: sa1100: remove unused RTC register definitions
rtc: sa1100/pxa: convert to run-time register mapping
ARM: pxa: add memory resource to SA1100 RTC device
rtc: pxa: convert to use shared sa1100 functions
rtc: sa1100: prepare to share sa1100_rtc_ops
rtc: ds3232: fix WARNING trace in resume function
...

+1763 -940
+21
Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt
··· 1 + NXP LPC1788 real-time clock 2 + 3 + The LPC1788 RTC provides calendar and clock functionality 4 + together with periodic tick and alarm interrupt support. 5 + 6 + Required properties: 7 + - compatible : must contain "nxp,lpc1788-rtc" 8 + - reg : Specifies base physical address and size of the registers. 9 + - interrupts : A single interrupt specifier. 10 + - clocks : Must contain clock specifiers for rtc and register clock 11 + - clock-names : Must contain "rtc" and "reg" 12 + See ../clocks/clock-bindings.txt for details. 13 + 14 + Example: 15 + rtc: rtc@40046000 { 16 + compatible = "nxp,lpc1788-rtc"; 17 + reg = <0x40046000 0x1000>; 18 + interrupts = <47>; 19 + clocks = <&creg_clk 0>, <&ccu1 CLK_CPU_BUS>; 20 + clock-names = "rtc", "reg"; 21 + };
+4
Documentation/devicetree/bindings/rtc/rtc-omap.txt
··· 16 16 Optional properties: 17 17 - system-power-controller: whether the rtc is controlling the system power 18 18 through pmic_power_en 19 + - clocks: Any internal or external clocks feeding in to rtc 20 + - clock-names: Corresponding names of the clocks 19 21 20 22 Example: 21 23 ··· 28 26 19>; 29 27 interrupt-parent = <&intc>; 30 28 system-power-controller; 29 + clocks = <&clk_32k_rtc>, <&clk_32768_ck>; 30 + clock-names = "ext-clk", "int-clk"; 31 31 };
+25
Documentation/devicetree/bindings/rtc/xlnx-rtc.txt
··· 1 + * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock 2 + 3 + RTC controller for the Xilinx Zynq MPSoC Real Time Clock 4 + Separate IRQ lines for seconds and alarm 5 + 6 + Required properties: 7 + - compatible: Should be "xlnx,zynqmp-rtc" 8 + - reg: Physical base address of the controller and length 9 + of memory mapped region. 10 + - interrupts: IRQ lines for the RTC. 11 + - interrupt-names: interrupt line names eg. "sec" "alarm" 12 + 13 + Optional: 14 + - calibration: calibration value for 1 sec period which will 15 + be programmed directly to calibration register 16 + 17 + Example: 18 + rtc: rtc@ffa60000 { 19 + compatible = "xlnx,zynqmp-rtc"; 20 + reg = <0x0 0xffa60000 0x100>; 21 + interrupt-parent = <&gic>; 22 + interrupts = <0 26 4>, <0 27 4>; 23 + interrupt-names = "alarm", "sec"; 24 + calibration = <0x198233>; 25 + };
+2
arch/arm/boot/dts/am4372.dtsi
··· 358 358 interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH 359 359 GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>; 360 360 ti,hwmods = "rtc"; 361 + clocks = <&clk_32768_ck>; 362 + clock-names = "int-clk"; 361 363 status = "disabled"; 362 364 }; 363 365
+13
arch/arm/boot/dts/am437x-gp-evm.dts
··· 112 112 clock-frequency = <12000000>; 113 113 }; 114 114 115 + /* fixed 32k external oscillator clock */ 116 + clk_32k_rtc: clk_32k_rtc { 117 + #clock-cells = <0>; 118 + compatible = "fixed-clock"; 119 + clock-frequency = <32768>; 120 + }; 121 + 115 122 sound0: sound@0 { 116 123 compatible = "simple-audio-card"; 117 124 simple-audio-card,name = "AM437x-GP-EVM"; ··· 947 940 >; 948 941 tx-num-evt = <32>; 949 942 rx-num-evt = <32>; 943 + }; 944 + 945 + &rtc { 946 + clocks = <&clk_32k_rtc>, <&clk_32768_ck>; 947 + clock-names = "ext-clk", "int-clk"; 948 + status = "okay"; 950 949 };
+9
arch/arm/boot/dts/am437x-idk-evm.dts
··· 110 110 gpios = <&gpio4 2 GPIO_ACTIVE_LOW>; 111 111 }; 112 112 }; 113 + 114 + /* fixed 32k external oscillator clock */ 115 + clk_32k_rtc: clk_32k_rtc { 116 + #clock-cells = <0>; 117 + compatible = "fixed-clock"; 118 + clock-frequency = <32768>; 119 + }; 113 120 }; 114 121 115 122 &am43xx_pinmux { ··· 401 394 }; 402 395 403 396 &rtc { 397 + clocks = <&clk_32k_rtc>, <&clk_32768_ck>; 398 + clock-names = "ext-clk", "int-clk"; 404 399 status = "okay"; 405 400 }; 406 401
+9
arch/arm/boot/dts/am437x-sk-evm.dts
··· 24 24 display0 = &lcd0; 25 25 }; 26 26 27 + /* fixed 32k external oscillator clock */ 28 + clk_32k_rtc: clk_32k_rtc { 29 + #clock-cells = <0>; 30 + compatible = "fixed-clock"; 31 + clock-frequency = <32768>; 32 + }; 33 + 27 34 backlight { 28 35 compatible = "pwm-backlight"; 29 36 pwms = <&ecap0 0 50000 PWM_POLARITY_INVERTED>; ··· 704 697 }; 705 698 706 699 &rtc { 700 + clocks = <&clk_32k_rtc>, <&clk_32768_ck>; 701 + clock-names = "ext-clk", "int-clk"; 707 702 status = "okay"; 708 703 }; 709 704
+1 -1
arch/arm/configs/cm_x2xx_defconfig
··· 157 157 CONFIG_LEDS_TRIGGER_HEARTBEAT=y 158 158 CONFIG_RTC_CLASS=y 159 159 CONFIG_RTC_DRV_V3020=y 160 - CONFIG_RTC_DRV_SA1100=y 160 + CONFIG_RTC_DRV_PXA=y 161 161 CONFIG_EXT2_FS=y 162 162 CONFIG_EXT3_FS=y 163 163 CONFIG_INOTIFY=y
+1 -1
arch/arm/configs/em_x270_defconfig
··· 157 157 CONFIG_LEDS_TRIGGER_HEARTBEAT=y 158 158 CONFIG_RTC_CLASS=y 159 159 CONFIG_RTC_DRV_V3020=y 160 - CONFIG_RTC_DRV_SA1100=y 160 + CONFIG_RTC_DRV_PXA=y 161 161 CONFIG_EXT2_FS=y 162 162 CONFIG_EXT3_FS=y 163 163 CONFIG_INOTIFY=y
+1 -1
arch/arm/configs/magician_defconfig
··· 150 150 CONFIG_LEDS_TRIGGER_BACKLIGHT=y 151 151 CONFIG_RTC_CLASS=y 152 152 CONFIG_RTC_DEBUG=y 153 - CONFIG_RTC_DRV_SA1100=y 153 + CONFIG_RTC_DRV_PXA=y 154 154 CONFIG_EXT2_FS=y 155 155 CONFIG_INOTIFY=y 156 156 CONFIG_MSDOS_FS=m
+1 -1
arch/arm/configs/palmz72_defconfig
··· 67 67 CONFIG_MMC_DEBUG=y 68 68 CONFIG_MMC_PXA=y 69 69 CONFIG_RTC_CLASS=y 70 - CONFIG_RTC_DRV_SA1100=y 70 + CONFIG_RTC_DRV_PXA=y 71 71 CONFIG_EXT2_FS=y 72 72 CONFIG_EXT3_FS=y 73 73 # CONFIG_DNOTIFY is not set
+1 -1
arch/arm/configs/pcm027_defconfig
··· 82 82 CONFIG_MMC_PXA=y 83 83 CONFIG_RTC_CLASS=y 84 84 CONFIG_RTC_DRV_PCF8563=m 85 - CONFIG_RTC_DRV_SA1100=m 85 + CONFIG_RTC_DRV_PXA=m 86 86 CONFIG_EXT2_FS=m 87 87 CONFIG_EXT3_FS=m 88 88 # CONFIG_DNOTIFY is not set
+1 -1
arch/arm/configs/trizeps4_defconfig
··· 177 177 CONFIG_RTC_CLASS=y 178 178 # CONFIG_RTC_HCTOSYS is not set 179 179 CONFIG_RTC_DRV_PCF8583=m 180 - CONFIG_RTC_DRV_SA1100=y 180 + CONFIG_RTC_DRV_PXA=y 181 181 CONFIG_EXT2_FS=y 182 182 CONFIG_EXT2_FS_XATTR=y 183 183 CONFIG_EXT2_FS_POSIX_ACL=y
-23
arch/arm/mach-mmp/include/mach/regs-rtc.h
··· 1 - #ifndef __ASM_MACH_REGS_RTC_H 2 - #define __ASM_MACH_REGS_RTC_H 3 - 4 - #include <mach/addr-map.h> 5 - 6 - #define RTC_VIRT_BASE (APB_VIRT_BASE + 0x10000) 7 - #define RTC_REG(x) (*((volatile u32 __iomem *)(RTC_VIRT_BASE + (x)))) 8 - 9 - /* 10 - * Real Time Clock 11 - */ 12 - 13 - #define RCNR RTC_REG(0x00) /* RTC Count Register */ 14 - #define RTAR RTC_REG(0x04) /* RTC Alarm Register */ 15 - #define RTSR RTC_REG(0x08) /* RTC Status Register */ 16 - #define RTTR RTC_REG(0x0C) /* RTC Timer Trim Register */ 17 - 18 - #define RTSR_HZE (1 << 3) /* HZ interrupt enable */ 19 - #define RTSR_ALE (1 << 2) /* RTC alarm interrupt enable */ 20 - #define RTSR_HZ (1 << 1) /* HZ rising-edge detected */ 21 - #define RTSR_AL (1 << 0) /* RTC alarm detected */ 22 - 23 - #endif /* __ASM_MACH_REGS_RTC_H */
+2 -16
arch/arm/mach-pxa/devices.c
··· 440 440 .resource = pxa_rtc_resources, 441 441 }; 442 442 443 - static struct resource sa1100_rtc_resources[] = { 444 - { 445 - .start = IRQ_RTC1Hz, 446 - .end = IRQ_RTC1Hz, 447 - .name = "rtc 1Hz", 448 - .flags = IORESOURCE_IRQ, 449 - }, { 450 - .start = IRQ_RTCAlrm, 451 - .end = IRQ_RTCAlrm, 452 - .name = "rtc alarm", 453 - .flags = IORESOURCE_IRQ, 454 - }, 455 - }; 456 - 457 443 struct platform_device sa1100_device_rtc = { 458 444 .name = "sa1100-rtc", 459 445 .id = -1, 460 - .num_resources = ARRAY_SIZE(sa1100_rtc_resources), 461 - .resource = sa1100_rtc_resources, 446 + .num_resources = ARRAY_SIZE(pxa_rtc_resources), 447 + .resource = pxa_rtc_resources, 462 448 }; 463 449 464 450 static struct resource pxa_ac97_resources[] = {
-1
arch/arm/mach-pxa/pxa27x.c
··· 282 282 &pxa_device_asoc_ssp2, 283 283 &pxa_device_asoc_ssp3, 284 284 &pxa_device_asoc_platform, 285 - &sa1100_device_rtc, 286 285 &pxa_device_rtc, 287 286 &pxa27x_device_ssp1, 288 287 &pxa27x_device_ssp2,
-1
arch/arm/mach-pxa/pxa3xx.c
··· 394 394 &pxa_device_asoc_ssp3, 395 395 &pxa_device_asoc_ssp4, 396 396 &pxa_device_asoc_platform, 397 - &sa1100_device_rtc, 398 397 &pxa_device_rtc, 399 398 &pxa3xx_device_ssp1, 400 399 &pxa3xx_device_ssp2,
-34
arch/arm/mach-sa1100/include/mach/SA-1100.h
··· 858 858 859 859 860 860 /* 861 - * Real-Time Clock (RTC) control registers 862 - * 863 - * Registers 864 - * RTAR Real-Time Clock (RTC) Alarm Register (read/write). 865 - * RCNR Real-Time Clock (RTC) CouNt Register (read/write). 866 - * RTTR Real-Time Clock (RTC) Trim Register (read/write). 867 - * RTSR Real-Time Clock (RTC) Status Register (read/write). 868 - * 869 - * Clocks 870 - * frtx, Trtx Frequency, period of the real-time clock crystal 871 - * (32.768 kHz nominal). 872 - * frtc, Trtc Frequency, period of the real-time clock counter 873 - * (1 Hz nominal). 874 - */ 875 - 876 - #define RTAR __REG(0x90010000) /* RTC Alarm Reg. */ 877 - #define RCNR __REG(0x90010004) /* RTC CouNt Reg. */ 878 - #define RTTR __REG(0x90010008) /* RTC Trim Reg. */ 879 - #define RTSR __REG(0x90010010) /* RTC Status Reg. */ 880 - 881 - #define RTTR_C Fld (16, 0) /* clock divider Count - 1 */ 882 - #define RTTR_D Fld (10, 16) /* trim Delete count */ 883 - /* frtc = (1023*(C + 1) - D)*frtx/ */ 884 - /* (1023*(C + 1)^2) */ 885 - /* Trtc = (1023*(C + 1)^2)*Trtx/ */ 886 - /* (1023*(C + 1) - D) */ 887 - 888 - #define RTSR_AL 0x00000001 /* ALarm detected */ 889 - #define RTSR_HZ 0x00000002 /* 1 Hz clock detected */ 890 - #define RTSR_ALE 0x00000004 /* ALarm interrupt Enable */ 891 - #define RTSR_HZE 0x00000008 /* 1 Hz clock interrupt Enable */ 892 - 893 - 894 - /* 895 861 * Power Manager (PM) control registers 896 862 * 897 863 * Registers
+29 -8
drivers/rtc/Kconfig
··· 945 945 will be called rtc-da9055 946 946 947 947 config RTC_DRV_DA9063 948 - tristate "Dialog Semiconductor DA9063 RTC" 949 - depends on MFD_DA9063 948 + tristate "Dialog Semiconductor DA9063/DA9062 RTC" 949 + depends on MFD_DA9063 || MFD_DA9062 950 950 help 951 951 If you say yes here you will get support for the RTC subsystem 952 - of the Dialog Semiconductor DA9063. 952 + for the Dialog Semiconductor PMIC chips DA9063 and DA9062. 953 953 954 954 This driver can also be built as a module. If so, the module 955 955 will be called "rtc-da9063". ··· 1115 1115 1116 1116 This driver can also be built as a module. If so, the module 1117 1117 will be called rtc-opal. 1118 + 1119 + config RTC_DRV_ZYNQMP 1120 + tristate "Xilinx Zynq Ultrascale+ MPSoC RTC" 1121 + depends on OF 1122 + help 1123 + If you say yes here you get support for the RTC controller found on 1124 + Xilinx Zynq Ultrascale+ MPSoC. 1118 1125 1119 1126 comment "on-CPU RTC drivers" 1120 1127 ··· 1313 1306 just say Y. 1314 1307 1315 1308 config RTC_DRV_PXA 1316 - tristate "PXA27x/PXA3xx" 1317 - depends on ARCH_PXA 1318 - help 1319 - If you say Y here you will get access to the real time clock 1320 - built into your PXA27x or PXA3xx CPU. 1309 + tristate "PXA27x/PXA3xx" 1310 + depends on ARCH_PXA 1311 + select RTC_DRV_SA1100 1312 + help 1313 + If you say Y here you will get access to the real time clock 1314 + built into your PXA27x or PXA3xx CPU. This RTC is actually 2 RTCs 1315 + consisting of an SA1100 compatible RTC and the extended PXA RTC. 1321 1316 1322 1317 This RTC driver uses PXA RTC registers available since pxa27x 1323 1318 series (RDxR, RYxR) instead of legacy RCNR, RTAR. ··· 1464 1455 1465 1456 This driver can also be buillt as a module. If so, the module 1466 1457 will be called rtc-jz4740. 1458 + 1459 + config RTC_DRV_LPC24XX 1460 + tristate "NXP RTC for LPC178x/18xx/408x/43xx" 1461 + depends on ARCH_LPC18XX || COMPILE_TEST 1462 + depends on OF && HAS_IOMEM 1463 + help 1464 + This enables support for the NXP RTC found which can be found on 1465 + NXP LPC178x/18xx/408x/43xx devices. 1466 + 1467 + If you have one of the devices above enable this driver to use 1468 + the hardware RTC. This driver can also be buillt as a module. If 1469 + so, the module will be called rtc-lpc24xx. 1467 1470 1468 1471 config RTC_DRV_LPC32XX 1469 1472 depends on ARCH_LPC32XX
+2
drivers/rtc/Makefile
··· 74 74 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 75 75 obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o 76 76 obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o 77 + obj-$(CONFIG_RTC_DRV_LPC24XX) += rtc-lpc24xx.o 77 78 obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o 78 79 obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o 79 80 obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o ··· 159 158 obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o 160 159 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 161 160 obj-$(CONFIG_RTC_DRV_XGENE) += rtc-xgene.o 161 + obj-$(CONFIG_RTC_DRV_ZYNQMP) += rtc-zynqmp.o
+14 -19
drivers/rtc/class.c
··· 202 202 rtc->max_user_freq = 64; 203 203 rtc->dev.parent = dev; 204 204 rtc->dev.class = rtc_class; 205 + rtc->dev.groups = rtc_get_dev_attribute_groups(); 205 206 rtc->dev.release = rtc_device_release; 206 207 207 208 mutex_init(&rtc->ops_lock); ··· 235 234 236 235 err = device_register(&rtc->dev); 237 236 if (err) { 237 + /* This will free both memory and the ID */ 238 238 put_device(&rtc->dev); 239 - goto exit_kfree; 239 + goto exit; 240 240 } 241 241 242 242 rtc_dev_add_device(rtc); 243 - rtc_sysfs_add_device(rtc); 244 243 rtc_proc_add_device(rtc); 245 244 246 245 dev_info(dev, "rtc core: registered %s as %s\n", 247 246 rtc->name, dev_name(&rtc->dev)); 248 247 249 248 return rtc; 250 - 251 - exit_kfree: 252 - kfree(rtc); 253 249 254 250 exit_ida: 255 251 ida_simple_remove(&rtc_ida, id); ··· 266 268 */ 267 269 void rtc_device_unregister(struct rtc_device *rtc) 268 270 { 269 - if (get_device(&rtc->dev) != NULL) { 270 - mutex_lock(&rtc->ops_lock); 271 - /* remove innards of this RTC, then disable it, before 272 - * letting any rtc_class_open() users access it again 273 - */ 274 - rtc_sysfs_del_device(rtc); 275 - rtc_dev_del_device(rtc); 276 - rtc_proc_del_device(rtc); 277 - device_unregister(&rtc->dev); 278 - rtc->ops = NULL; 279 - mutex_unlock(&rtc->ops_lock); 280 - put_device(&rtc->dev); 281 - } 271 + mutex_lock(&rtc->ops_lock); 272 + /* 273 + * Remove innards of this RTC, then disable it, before 274 + * letting any rtc_class_open() users access it again 275 + */ 276 + rtc_dev_del_device(rtc); 277 + rtc_proc_del_device(rtc); 278 + device_del(&rtc->dev); 279 + rtc->ops = NULL; 280 + mutex_unlock(&rtc->ops_lock); 281 + put_device(&rtc->dev); 282 282 } 283 283 EXPORT_SYMBOL_GPL(rtc_device_unregister); 284 284 ··· 359 363 } 360 364 rtc_class->pm = RTC_CLASS_DEV_PM_OPS; 361 365 rtc_dev_init(); 362 - rtc_sysfs_init(rtc_class); 363 366 return 0; 364 367 } 365 368
+1 -1
drivers/rtc/interface.c
··· 564 564 void rtc_update_irq(struct rtc_device *rtc, 565 565 unsigned long num, unsigned long events) 566 566 { 567 - if (unlikely(IS_ERR_OR_NULL(rtc))) 567 + if (IS_ERR_OR_NULL(rtc)) 568 568 return; 569 569 570 570 pm_stay_awake(rtc->dev.parent);
+17 -11
drivers/rtc/rtc-88pm80x.c
··· 251 251 static int pm80x_rtc_probe(struct platform_device *pdev) 252 252 { 253 253 struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent); 254 - struct pm80x_platform_data *pm80x_pdata = 255 - dev_get_platdata(pdev->dev.parent); 256 - struct pm80x_rtc_pdata *pdata = NULL; 254 + struct pm80x_rtc_pdata *pdata = dev_get_platdata(&pdev->dev); 257 255 struct pm80x_rtc_info *info; 256 + struct device_node *node = pdev->dev.of_node; 258 257 struct rtc_time tm; 259 258 unsigned long ticks = 0; 260 259 int ret; 261 260 262 - pdata = dev_get_platdata(&pdev->dev); 263 - if (pdata == NULL) 264 - dev_warn(&pdev->dev, "No platform data!\n"); 261 + if (!pdata && !node) { 262 + dev_err(&pdev->dev, 263 + "pm80x-rtc requires platform data or of_node\n"); 264 + return -EINVAL; 265 + } 266 + 267 + if (!pdata) { 268 + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 269 + if (!pdata) { 270 + dev_err(&pdev->dev, "failed to allocate memory\n"); 271 + return -ENOMEM; 272 + } 273 + } 265 274 266 275 info = 267 276 devm_kzalloc(&pdev->dev, sizeof(struct pm80x_rtc_info), GFP_KERNEL); ··· 336 327 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_RTC1_USE_XO, 337 328 PM800_RTC1_USE_XO); 338 329 339 - if (pm80x_pdata) { 340 - pdata = pm80x_pdata->rtc; 341 - if (pdata) 342 - info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup; 343 - } 330 + /* remember whether this power up is caused by PMIC RTC or not */ 331 + info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup; 344 332 345 333 device_init_wakeup(&pdev->dev, 1); 346 334
+1 -1
drivers/rtc/rtc-ab-b5ze-s3.c
··· 1009 1009 { .compatible = "abracon,abb5zes3" }, 1010 1010 { }, 1011 1011 }; 1012 + MODULE_DEVICE_TABLE(of, abb5zes3_dt_match); 1012 1013 #endif 1013 1014 1014 1015 static const struct i2c_device_id abb5zes3_id[] = { ··· 1021 1020 static struct i2c_driver abb5zes3_driver = { 1022 1021 .driver = { 1023 1022 .name = DRV_NAME, 1024 - .owner = THIS_MODULE, 1025 1023 .pm = &abb5zes3_rtc_pm_ops, 1026 1024 .of_match_table = of_match_ptr(abb5zes3_dt_match), 1027 1025 },
+2
drivers/rtc/rtc-ab8500.c
··· 445 445 static const struct platform_device_id ab85xx_rtc_ids[] = { 446 446 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, }, 447 447 { "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, }, 448 + { /* sentinel */ } 448 449 }; 450 + MODULE_DEVICE_TABLE(platform, ab85xx_rtc_ids); 449 451 450 452 static int ab8500_rtc_probe(struct platform_device *pdev) 451 453 {
+1 -1
drivers/rtc/rtc-abx80x.c
··· 28 28 #define ABX8XX_REG_WD 0x07 29 29 30 30 #define ABX8XX_REG_CTRL1 0x10 31 - #define ABX8XX_CTRL_WRITE BIT(1) 31 + #define ABX8XX_CTRL_WRITE BIT(0) 32 32 #define ABX8XX_CTRL_12_24 BIT(6) 33 33 34 34 #define ABX8XX_REG_CFG_KEY 0x1f
+13 -20
drivers/rtc/rtc-armada38x.c
··· 40 40 void __iomem *regs; 41 41 void __iomem *regs_soc; 42 42 spinlock_t lock; 43 - /* 44 - * While setting the time, the RTC TIME register should not be 45 - * accessed. Setting the RTC time involves sleeping during 46 - * 100ms, so a mutex instead of a spinlock is used to protect 47 - * it 48 - */ 49 - struct mutex mutex_time; 50 43 int irq; 51 44 }; 52 45 ··· 57 64 static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm) 58 65 { 59 66 struct armada38x_rtc *rtc = dev_get_drvdata(dev); 60 - unsigned long time, time_check; 67 + unsigned long time, time_check, flags; 61 68 62 - mutex_lock(&rtc->mutex_time); 69 + spin_lock_irqsave(&rtc->lock, flags); 63 70 time = readl(rtc->regs + RTC_TIME); 64 71 /* 65 72 * WA for failing time set attempts. As stated in HW ERRATA if ··· 70 77 if ((time_check - time) > 1) 71 78 time_check = readl(rtc->regs + RTC_TIME); 72 79 73 - mutex_unlock(&rtc->mutex_time); 80 + spin_unlock_irqrestore(&rtc->lock, flags); 74 81 75 82 rtc_time_to_tm(time_check, tm); 76 83 ··· 81 88 { 82 89 struct armada38x_rtc *rtc = dev_get_drvdata(dev); 83 90 int ret = 0; 84 - unsigned long time; 91 + unsigned long time, flags; 85 92 86 93 ret = rtc_tm_to_time(tm, &time); 87 94 88 95 if (ret) 89 96 goto out; 90 97 /* 91 - * Setting the RTC time not always succeeds. According to the 92 - * errata we need to first write on the status register and 93 - * then wait for 100ms before writing to the time register to be 94 - * sure that the data will be taken into account. 98 + * According to errata FE-3124064, Write to RTC TIME register 99 + * may fail. As a workaround, after writing to RTC TIME 100 + * register, issue a dummy write of 0x0 twice to RTC Status 101 + * register. 95 102 */ 96 - mutex_lock(&rtc->mutex_time); 97 - rtc_delayed_write(0, rtc, RTC_STATUS); 98 - msleep(100); 103 + spin_lock_irqsave(&rtc->lock, flags); 99 104 rtc_delayed_write(time, rtc, RTC_TIME); 100 - mutex_unlock(&rtc->mutex_time); 105 + rtc_delayed_write(0, rtc, RTC_STATUS); 106 + rtc_delayed_write(0, rtc, RTC_STATUS); 107 + spin_unlock_irqrestore(&rtc->lock, flags); 101 108 102 109 out: 103 110 return ret; ··· 222 229 return -ENOMEM; 223 230 224 231 spin_lock_init(&rtc->lock); 225 - mutex_init(&rtc->mutex_time); 226 232 227 233 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc"); 228 234 rtc->regs = devm_ioremap_resource(&pdev->dev, res); ··· 295 303 { .compatible = "marvell,armada-380-rtc", }, 296 304 {} 297 305 }; 306 + MODULE_DEVICE_TABLE(of, armada38x_rtc_of_match_table); 298 307 #endif 299 308 300 309 static struct platform_driver armada38x_rtc_driver = {
+2 -2
drivers/rtc/rtc-as3722.c
··· 45 45 rbuff[1] = bin2bcd(tm->tm_min); 46 46 rbuff[2] = bin2bcd(tm->tm_hour); 47 47 rbuff[3] = bin2bcd(tm->tm_mday); 48 - rbuff[4] = bin2bcd(tm->tm_mon); 48 + rbuff[4] = bin2bcd(tm->tm_mon + 1); 49 49 rbuff[5] = bin2bcd(tm->tm_year - (AS3722_RTC_START_YEAR - 1900)); 50 50 } 51 51 ··· 55 55 tm->tm_min = bcd2bin(rbuff[1] & 0x7F); 56 56 tm->tm_hour = bcd2bin(rbuff[2] & 0x3F); 57 57 tm->tm_mday = bcd2bin(rbuff[3] & 0x3F); 58 - tm->tm_mon = bcd2bin(rbuff[4] & 0x1F); 58 + tm->tm_mon = bcd2bin(rbuff[4] & 0x1F) - 1; 59 59 tm->tm_year = (AS3722_RTC_START_YEAR - 1900) + bcd2bin(rbuff[5] & 0x7F); 60 60 return; 61 61 }
+33 -12
drivers/rtc/rtc-at91rm9200.c
··· 18 18 * 19 19 */ 20 20 21 - #include <linux/module.h> 22 - #include <linux/kernel.h> 23 - #include <linux/platform_device.h> 24 - #include <linux/time.h> 25 - #include <linux/rtc.h> 26 21 #include <linux/bcd.h> 27 - #include <linux/interrupt.h> 28 - #include <linux/spinlock.h> 29 - #include <linux/ioctl.h> 22 + #include <linux/clk.h> 30 23 #include <linux/completion.h> 24 + #include <linux/interrupt.h> 25 + #include <linux/ioctl.h> 31 26 #include <linux/io.h> 32 - #include <linux/of.h> 27 + #include <linux/kernel.h> 28 + #include <linux/module.h> 33 29 #include <linux/of_device.h> 30 + #include <linux/of.h> 31 + #include <linux/platform_device.h> 32 + #include <linux/rtc.h> 33 + #include <linux/spinlock.h> 34 34 #include <linux/suspend.h> 35 + #include <linux/time.h> 35 36 #include <linux/uaccess.h> 36 37 37 38 #include "rtc-at91rm9200.h" ··· 60 59 static DEFINE_SPINLOCK(suspended_lock); 61 60 static unsigned long cached_events; 62 61 static u32 at91_rtc_imr; 62 + static struct clk *sclk; 63 63 64 64 static void at91_rtc_write_ier(u32 mask) 65 65 { ··· 409 407 return -ENOMEM; 410 408 } 411 409 410 + sclk = devm_clk_get(&pdev->dev, NULL); 411 + if (IS_ERR(sclk)) 412 + return PTR_ERR(sclk); 413 + 414 + ret = clk_prepare_enable(sclk); 415 + if (ret) { 416 + dev_err(&pdev->dev, "Could not enable slow clock\n"); 417 + return ret; 418 + } 419 + 412 420 at91_rtc_write(AT91_RTC_CR, 0); 413 421 at91_rtc_write(AT91_RTC_MR, 0); /* 24 hour mode */ 414 422 ··· 432 420 "at91_rtc", pdev); 433 421 if (ret) { 434 422 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); 435 - return ret; 423 + goto err_clk; 436 424 } 437 425 438 426 /* cpu init code should really have flagged this device as ··· 443 431 444 432 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 445 433 &at91_rtc_ops, THIS_MODULE); 446 - if (IS_ERR(rtc)) 447 - return PTR_ERR(rtc); 434 + if (IS_ERR(rtc)) { 435 + ret = PTR_ERR(rtc); 436 + goto err_clk; 437 + } 448 438 platform_set_drvdata(pdev, rtc); 449 439 450 440 /* enable SECEV interrupt in order to initialize at91_rtc_upd_rdy ··· 456 442 457 443 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n"); 458 444 return 0; 445 + 446 + err_clk: 447 + clk_disable_unprepare(sclk); 448 + 449 + return ret; 459 450 } 460 451 461 452 /* ··· 472 453 at91_rtc_write_idr(AT91_RTC_ACKUPD | AT91_RTC_ALARM | 473 454 AT91_RTC_SECEV | AT91_RTC_TIMEV | 474 455 AT91_RTC_CALEV); 456 + 457 + clk_disable_unprepare(sclk); 475 458 476 459 return 0; 477 460 }
+26 -19
drivers/rtc/rtc-at91sam9.c
··· 11 11 * 2 of the License, or (at your option) any later version. 12 12 */ 13 13 14 - #include <linux/module.h> 15 - #include <linux/kernel.h> 16 - #include <linux/platform_device.h> 17 - #include <linux/time.h> 18 - #include <linux/rtc.h> 14 + #include <linux/clk.h> 19 15 #include <linux/interrupt.h> 20 16 #include <linux/ioctl.h> 21 - #include <linux/slab.h> 22 - #include <linux/platform_data/atmel.h> 23 17 #include <linux/io.h> 18 + #include <linux/kernel.h> 24 19 #include <linux/mfd/syscon.h> 20 + #include <linux/module.h> 21 + #include <linux/of.h> 22 + #include <linux/platform_device.h> 25 23 #include <linux/regmap.h> 24 + #include <linux/rtc.h> 25 + #include <linux/slab.h> 26 26 #include <linux/suspend.h> 27 - #include <linux/clk.h> 27 + #include <linux/time.h> 28 28 29 29 /* 30 30 * This driver uses two configurable hardware resources that live in the ··· 425 425 if (IS_ERR(rtc->sclk)) 426 426 return PTR_ERR(rtc->sclk); 427 427 428 - sclk_rate = clk_get_rate(rtc->sclk); 429 - if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) { 430 - dev_err(&pdev->dev, "Invalid slow clock rate\n"); 431 - return -EINVAL; 432 - } 433 - 434 428 ret = clk_prepare_enable(rtc->sclk); 435 429 if (ret) { 436 430 dev_err(&pdev->dev, "Could not enable slow clock\n"); 437 431 return ret; 432 + } 433 + 434 + sclk_rate = clk_get_rate(rtc->sclk); 435 + if (!sclk_rate || sclk_rate > AT91_RTT_RTPRES) { 436 + dev_err(&pdev->dev, "Invalid slow clock rate\n"); 437 + ret = -EINVAL; 438 + goto err_clk; 438 439 } 439 440 440 441 mr = rtt_readl(rtc, MR); ··· 452 451 453 452 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, 454 453 &at91_rtc_ops, THIS_MODULE); 455 - if (IS_ERR(rtc->rtcdev)) 456 - return PTR_ERR(rtc->rtcdev); 454 + if (IS_ERR(rtc->rtcdev)) { 455 + ret = PTR_ERR(rtc->rtcdev); 456 + goto err_clk; 457 + } 457 458 458 459 /* register irq handler after we know what name we'll use */ 459 460 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, ··· 463 460 dev_name(&rtc->rtcdev->dev), rtc); 464 461 if (ret) { 465 462 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); 466 - return ret; 463 + goto err_clk; 467 464 } 468 465 469 466 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the ··· 477 474 dev_name(&rtc->rtcdev->dev)); 478 475 479 476 return 0; 477 + 478 + err_clk: 479 + clk_disable_unprepare(rtc->sclk); 480 + 481 + return ret; 480 482 } 481 483 482 484 /* ··· 495 487 /* disable all interrupts */ 496 488 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); 497 489 498 - if (!IS_ERR(rtc->sclk)) 499 - clk_disable_unprepare(rtc->sclk); 490 + clk_disable_unprepare(rtc->sclk); 500 491 501 492 return 0; 502 493 }
+1 -1
drivers/rtc/rtc-bfin.c
··· 361 361 /* Register our RTC with the RTC framework */ 362 362 rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops, 363 363 THIS_MODULE); 364 - if (unlikely(IS_ERR(rtc->rtc_dev))) 364 + if (IS_ERR(rtc->rtc_dev)) 365 365 return PTR_ERR(rtc->rtc_dev); 366 366 367 367 /* Grab the IRQ and init the hardware */
+1 -2
drivers/rtc/rtc-bq32k.c
··· 212 212 if (error) 213 213 return error; 214 214 215 - if (client && client->dev.of_node) 215 + if (client->dev.of_node) 216 216 trickle_charger_of_init(dev, client->dev.of_node); 217 217 218 218 rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name, ··· 234 234 static struct i2c_driver bq32k_driver = { 235 235 .driver = { 236 236 .name = "bq32k", 237 - .owner = THIS_MODULE, 238 237 }, 239 238 .probe = bq32k_probe, 240 239 .id_table = bq32k_id,
+60 -67
drivers/rtc/rtc-cmos.c
··· 41 41 #include <linux/pm.h> 42 42 #include <linux/of.h> 43 43 #include <linux/of_platform.h> 44 - #include <linux/dmi.h> 45 44 46 45 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ 47 46 #include <asm-generic/rtc.h> ··· 50 51 struct device *dev; 51 52 int irq; 52 53 struct resource *iomem; 54 + time64_t alarm_expires; 53 55 54 56 void (*wake_on)(struct device *); 55 57 void (*wake_off)(struct device *); ··· 377 377 378 378 spin_unlock_irq(&rtc_lock); 379 379 380 + cmos->alarm_expires = rtc_tm_to_time64(&t->time); 381 + 380 382 return 0; 381 383 } 382 - 383 - /* 384 - * Do not disable RTC alarm on shutdown - workaround for b0rked BIOSes. 385 - */ 386 - static bool alarm_disable_quirk; 387 - 388 - static int __init set_alarm_disable_quirk(const struct dmi_system_id *id) 389 - { 390 - alarm_disable_quirk = true; 391 - pr_info("BIOS has alarm-disable quirk - RTC alarms disabled\n"); 392 - return 0; 393 - } 394 - 395 - static const struct dmi_system_id rtc_quirks[] __initconst = { 396 - /* https://bugzilla.novell.com/show_bug.cgi?id=805740 */ 397 - { 398 - .callback = set_alarm_disable_quirk, 399 - .ident = "IBM Truman", 400 - .matches = { 401 - DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 402 - DMI_MATCH(DMI_PRODUCT_NAME, "4852570"), 403 - }, 404 - }, 405 - /* https://bugzilla.novell.com/show_bug.cgi?id=812592 */ 406 - { 407 - .callback = set_alarm_disable_quirk, 408 - .ident = "Gigabyte GA-990XA-UD3", 409 - .matches = { 410 - DMI_MATCH(DMI_SYS_VENDOR, 411 - "Gigabyte Technology Co., Ltd."), 412 - DMI_MATCH(DMI_PRODUCT_NAME, "GA-990XA-UD3"), 413 - }, 414 - }, 415 - /* http://permalink.gmane.org/gmane.linux.kernel/1604474 */ 416 - { 417 - .callback = set_alarm_disable_quirk, 418 - .ident = "Toshiba Satellite L300", 419 - .matches = { 420 - DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 421 - DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L300"), 422 - }, 423 - }, 424 - {} 425 - }; 426 384 427 385 static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled) 428 386 { ··· 389 431 390 432 if (!is_valid_irq(cmos->irq)) 391 433 return -EINVAL; 392 - 393 - if (alarm_disable_quirk) 394 - return 0; 395 434 396 435 spin_lock_irqsave(&rtc_lock, flags); 397 436 ··· 467 512 { 468 513 int retval; 469 514 470 - if (unlikely(off >= attr->size)) 471 - return 0; 472 - if (unlikely(off < 0)) 473 - return -EINVAL; 474 - if ((off + count) > attr->size) 475 - count = attr->size - off; 476 - 477 515 off += NVRAM_OFFSET; 478 516 spin_lock_irq(&rtc_lock); 479 517 for (retval = 0; count; count--, off++, retval++) { ··· 491 543 int retval; 492 544 493 545 cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); 494 - if (unlikely(off >= attr->size)) 495 - return -EFBIG; 496 - if (unlikely(off < 0)) 497 - return -EINVAL; 498 - if ((off + count) > attr->size) 499 - count = attr->size - off; 500 546 501 547 /* NOTE: on at least PCs and Ataris, the boot firmware uses a 502 548 * checksum on part of the NVRAM data. That's currently ignored ··· 802 860 cmos->dev = NULL; 803 861 } 804 862 863 + static int cmos_aie_poweroff(struct device *dev) 864 + { 865 + struct cmos_rtc *cmos = dev_get_drvdata(dev); 866 + struct rtc_time now; 867 + time64_t t_now; 868 + int retval = 0; 869 + unsigned char rtc_control; 870 + 871 + if (!cmos->alarm_expires) 872 + return -EINVAL; 873 + 874 + spin_lock_irq(&rtc_lock); 875 + rtc_control = CMOS_READ(RTC_CONTROL); 876 + spin_unlock_irq(&rtc_lock); 877 + 878 + /* We only care about the situation where AIE is disabled. */ 879 + if (rtc_control & RTC_AIE) 880 + return -EBUSY; 881 + 882 + cmos_read_time(dev, &now); 883 + t_now = rtc_tm_to_time64(&now); 884 + 885 + /* 886 + * When enabling "RTC wake-up" in BIOS setup, the machine reboots 887 + * automatically right after shutdown on some buggy boxes. 888 + * This automatic rebooting issue won't happen when the alarm 889 + * time is larger than now+1 seconds. 890 + * 891 + * If the alarm time is equal to now+1 seconds, the issue can be 892 + * prevented by cancelling the alarm. 893 + */ 894 + if (cmos->alarm_expires == t_now + 1) { 895 + struct rtc_wkalrm alarm; 896 + 897 + /* Cancel the AIE timer by configuring the past time. */ 898 + rtc_time64_to_tm(t_now - 1, &alarm.time); 899 + alarm.enabled = 0; 900 + retval = cmos_set_alarm(dev, &alarm); 901 + } else if (cmos->alarm_expires > t_now + 1) { 902 + retval = -EBUSY; 903 + } 904 + 905 + return retval; 906 + } 907 + 805 908 #ifdef CONFIG_PM 806 909 807 910 static int cmos_suspend(struct device *dev) ··· 1081 1094 struct device *dev = &pnp->dev; 1082 1095 struct cmos_rtc *cmos = dev_get_drvdata(dev); 1083 1096 1084 - if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(dev)) 1085 - return; 1097 + if (system_state == SYSTEM_POWER_OFF) { 1098 + int retval = cmos_poweroff(dev); 1099 + 1100 + if (cmos_aie_poweroff(dev) < 0 && !retval) 1101 + return; 1102 + } 1086 1103 1087 1104 cmos_do_shutdown(cmos->irq); 1088 1105 } ··· 1191 1200 struct device *dev = &pdev->dev; 1192 1201 struct cmos_rtc *cmos = dev_get_drvdata(dev); 1193 1202 1194 - if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(dev)) 1195 - return; 1203 + if (system_state == SYSTEM_POWER_OFF) { 1204 + int retval = cmos_poweroff(dev); 1205 + 1206 + if (cmos_aie_poweroff(dev) < 0 && !retval) 1207 + return; 1208 + } 1196 1209 1197 1210 cmos_do_shutdown(cmos->irq); 1198 1211 } ··· 1237 1242 if (retval == 0) 1238 1243 platform_driver_registered = true; 1239 1244 } 1240 - 1241 - dmi_check_system(rtc_quirks); 1242 1245 1243 1246 if (retval == 0) 1244 1247 return 0;
+1
drivers/rtc/rtc-coh901331.c
··· 263 263 { .compatible = "stericsson,coh901331" }, 264 264 {}, 265 265 }; 266 + MODULE_DEVICE_TABLE(of, coh901331_dt_match); 266 267 267 268 static struct platform_driver coh901331_driver = { 268 269 .driver = {
+3 -16
drivers/rtc/rtc-core.h
··· 48 48 #endif 49 49 50 50 #ifdef CONFIG_RTC_INTF_SYSFS 51 - 52 - extern void __init rtc_sysfs_init(struct class *); 53 - extern void rtc_sysfs_add_device(struct rtc_device *rtc); 54 - extern void rtc_sysfs_del_device(struct rtc_device *rtc); 55 - 51 + const struct attribute_group **rtc_get_dev_attribute_groups(void); 56 52 #else 57 - 58 - static inline void rtc_sysfs_init(struct class *rtc) 53 + static inline const struct attribute_group **rtc_get_dev_attribute_groups(void) 59 54 { 55 + return NULL; 60 56 } 61 - 62 - static inline void rtc_sysfs_add_device(struct rtc_device *rtc) 63 - { 64 - } 65 - 66 - static inline void rtc_sysfs_del_device(struct rtc_device *rtc) 67 - { 68 - } 69 - 70 57 #endif
+280 -112
drivers/rtc/rtc-da9063.c
··· 12 12 * Library General Public License for more details. 13 13 */ 14 14 15 + #include <linux/delay.h> 16 + #include <linux/init.h> 17 + #include <linux/interrupt.h> 15 18 #include <linux/kernel.h> 16 19 #include <linux/module.h> 17 - #include <linux/init.h> 20 + #include <linux/of.h> 18 21 #include <linux/platform_device.h> 19 - #include <linux/interrupt.h> 22 + #include <linux/regmap.h> 20 23 #include <linux/rtc.h> 21 24 #include <linux/slab.h> 22 - #include <linux/delay.h> 23 - #include <linux/regmap.h> 25 + 26 + #include <linux/mfd/da9062/registers.h> 24 27 #include <linux/mfd/da9063/registers.h> 25 28 #include <linux/mfd/da9063/core.h> 26 29 ··· 32 29 #define YEARS_FROM_DA9063(year) ((year) + 100) 33 30 #define MONTHS_FROM_DA9063(month) ((month) - 1) 34 31 35 - #define RTC_ALARM_DATA_LEN (DA9063_AD_REG_ALARM_Y - DA9063_AD_REG_ALARM_MI + 1) 36 - 37 - #define RTC_DATA_LEN (DA9063_REG_COUNT_Y - DA9063_REG_COUNT_S + 1) 38 - #define RTC_SEC 0 39 - #define RTC_MIN 1 40 - #define RTC_HOUR 2 41 - #define RTC_DAY 3 42 - #define RTC_MONTH 4 43 - #define RTC_YEAR 5 44 - 45 - struct da9063_rtc { 46 - struct rtc_device *rtc_dev; 47 - struct da9063 *hw; 48 - struct rtc_time alarm_time; 49 - bool rtc_sync; 50 - int alarm_year; 51 - int alarm_start; 52 - int alarm_len; 53 - int data_start; 32 + enum { 33 + RTC_SEC = 0, 34 + RTC_MIN = 1, 35 + RTC_HOUR = 2, 36 + RTC_DAY = 3, 37 + RTC_MONTH = 4, 38 + RTC_YEAR = 5, 39 + RTC_DATA_LEN 54 40 }; 55 41 56 - static void da9063_data_to_tm(u8 *data, struct rtc_time *tm) 42 + struct da9063_compatible_rtc_regmap { 43 + /* REGS */ 44 + int rtc_enable_reg; 45 + int rtc_enable_32k_crystal_reg; 46 + int rtc_alarm_secs_reg; 47 + int rtc_alarm_year_reg; 48 + int rtc_count_secs_reg; 49 + int rtc_count_year_reg; 50 + int rtc_event_reg; 51 + /* MASKS */ 52 + int rtc_enable_mask; 53 + int rtc_crystal_mask; 54 + int rtc_event_alarm_mask; 55 + int rtc_alarm_on_mask; 56 + int rtc_alarm_status_mask; 57 + int rtc_tick_on_mask; 58 + int rtc_ready_to_read_mask; 59 + int rtc_count_sec_mask; 60 + int rtc_count_min_mask; 61 + int rtc_count_hour_mask; 62 + int rtc_count_day_mask; 63 + int rtc_count_month_mask; 64 + int rtc_count_year_mask; 65 + /* ALARM CONFIG */ 66 + int rtc_data_start; 67 + int rtc_alarm_len; 68 + }; 69 + 70 + struct da9063_compatible_rtc { 71 + struct rtc_device *rtc_dev; 72 + struct rtc_time alarm_time; 73 + struct regmap *regmap; 74 + const struct da9063_compatible_rtc_regmap *config; 75 + bool rtc_sync; 76 + }; 77 + 78 + static const struct da9063_compatible_rtc_regmap da9063_ad_regs = { 79 + /* REGS */ 80 + .rtc_enable_reg = DA9063_REG_CONTROL_E, 81 + .rtc_alarm_secs_reg = DA9063_AD_REG_ALARM_MI, 82 + .rtc_alarm_year_reg = DA9063_AD_REG_ALARM_Y, 83 + .rtc_count_secs_reg = DA9063_REG_COUNT_S, 84 + .rtc_count_year_reg = DA9063_REG_COUNT_Y, 85 + .rtc_event_reg = DA9063_REG_EVENT_A, 86 + /* MASKS */ 87 + .rtc_enable_mask = DA9063_RTC_EN, 88 + .rtc_crystal_mask = DA9063_CRYSTAL, 89 + .rtc_enable_32k_crystal_reg = DA9063_REG_EN_32K, 90 + .rtc_event_alarm_mask = DA9063_E_ALARM, 91 + .rtc_alarm_on_mask = DA9063_ALARM_ON, 92 + .rtc_alarm_status_mask = DA9063_ALARM_STATUS_ALARM | 93 + DA9063_ALARM_STATUS_TICK, 94 + .rtc_tick_on_mask = DA9063_TICK_ON, 95 + .rtc_ready_to_read_mask = DA9063_RTC_READ, 96 + .rtc_count_sec_mask = DA9063_COUNT_SEC_MASK, 97 + .rtc_count_min_mask = DA9063_COUNT_MIN_MASK, 98 + .rtc_count_hour_mask = DA9063_COUNT_HOUR_MASK, 99 + .rtc_count_day_mask = DA9063_COUNT_DAY_MASK, 100 + .rtc_count_month_mask = DA9063_COUNT_MONTH_MASK, 101 + .rtc_count_year_mask = DA9063_COUNT_YEAR_MASK, 102 + /* ALARM CONFIG */ 103 + .rtc_data_start = RTC_MIN, 104 + .rtc_alarm_len = RTC_DATA_LEN - 1, 105 + }; 106 + 107 + static const struct da9063_compatible_rtc_regmap da9063_bb_regs = { 108 + /* REGS */ 109 + .rtc_enable_reg = DA9063_REG_CONTROL_E, 110 + .rtc_alarm_secs_reg = DA9063_BB_REG_ALARM_S, 111 + .rtc_alarm_year_reg = DA9063_BB_REG_ALARM_Y, 112 + .rtc_count_secs_reg = DA9063_REG_COUNT_S, 113 + .rtc_count_year_reg = DA9063_REG_COUNT_Y, 114 + .rtc_event_reg = DA9063_REG_EVENT_A, 115 + /* MASKS */ 116 + .rtc_enable_mask = DA9063_RTC_EN, 117 + .rtc_crystal_mask = DA9063_CRYSTAL, 118 + .rtc_enable_32k_crystal_reg = DA9063_REG_EN_32K, 119 + .rtc_event_alarm_mask = DA9063_E_ALARM, 120 + .rtc_alarm_on_mask = DA9063_ALARM_ON, 121 + .rtc_alarm_status_mask = DA9063_ALARM_STATUS_ALARM | 122 + DA9063_ALARM_STATUS_TICK, 123 + .rtc_tick_on_mask = DA9063_TICK_ON, 124 + .rtc_ready_to_read_mask = DA9063_RTC_READ, 125 + .rtc_count_sec_mask = DA9063_COUNT_SEC_MASK, 126 + .rtc_count_min_mask = DA9063_COUNT_MIN_MASK, 127 + .rtc_count_hour_mask = DA9063_COUNT_HOUR_MASK, 128 + .rtc_count_day_mask = DA9063_COUNT_DAY_MASK, 129 + .rtc_count_month_mask = DA9063_COUNT_MONTH_MASK, 130 + .rtc_count_year_mask = DA9063_COUNT_YEAR_MASK, 131 + /* ALARM CONFIG */ 132 + .rtc_data_start = RTC_SEC, 133 + .rtc_alarm_len = RTC_DATA_LEN, 134 + }; 135 + 136 + static const struct da9063_compatible_rtc_regmap da9062_aa_regs = { 137 + /* REGS */ 138 + .rtc_enable_reg = DA9062AA_CONTROL_E, 139 + .rtc_alarm_secs_reg = DA9062AA_ALARM_S, 140 + .rtc_alarm_year_reg = DA9062AA_ALARM_Y, 141 + .rtc_count_secs_reg = DA9062AA_COUNT_S, 142 + .rtc_count_year_reg = DA9062AA_COUNT_Y, 143 + .rtc_event_reg = DA9062AA_EVENT_A, 144 + /* MASKS */ 145 + .rtc_enable_mask = DA9062AA_RTC_EN_MASK, 146 + .rtc_crystal_mask = DA9062AA_CRYSTAL_MASK, 147 + .rtc_enable_32k_crystal_reg = DA9062AA_EN_32K, 148 + .rtc_event_alarm_mask = DA9062AA_M_ALARM_MASK, 149 + .rtc_alarm_on_mask = DA9062AA_ALARM_ON_MASK, 150 + .rtc_alarm_status_mask = (0x02 << 6), 151 + .rtc_tick_on_mask = DA9062AA_TICK_ON_MASK, 152 + .rtc_ready_to_read_mask = DA9062AA_RTC_READ_MASK, 153 + .rtc_count_sec_mask = DA9062AA_COUNT_SEC_MASK, 154 + .rtc_count_min_mask = DA9062AA_COUNT_MIN_MASK, 155 + .rtc_count_hour_mask = DA9062AA_COUNT_HOUR_MASK, 156 + .rtc_count_day_mask = DA9062AA_COUNT_DAY_MASK, 157 + .rtc_count_month_mask = DA9062AA_COUNT_MONTH_MASK, 158 + .rtc_count_year_mask = DA9062AA_COUNT_YEAR_MASK, 159 + /* ALARM CONFIG */ 160 + .rtc_data_start = RTC_SEC, 161 + .rtc_alarm_len = RTC_DATA_LEN, 162 + }; 163 + 164 + static const struct of_device_id da9063_compatible_reg_id_table[] = { 165 + { .compatible = "dlg,da9063-rtc", .data = &da9063_bb_regs }, 166 + { .compatible = "dlg,da9062-rtc", .data = &da9062_aa_regs }, 167 + { }, 168 + }; 169 + MODULE_DEVICE_TABLE(of, da9063_compatible_reg_id_table); 170 + 171 + static void da9063_data_to_tm(u8 *data, struct rtc_time *tm, 172 + struct da9063_compatible_rtc *rtc) 57 173 { 58 - tm->tm_sec = data[RTC_SEC] & DA9063_COUNT_SEC_MASK; 59 - tm->tm_min = data[RTC_MIN] & DA9063_COUNT_MIN_MASK; 60 - tm->tm_hour = data[RTC_HOUR] & DA9063_COUNT_HOUR_MASK; 61 - tm->tm_mday = data[RTC_DAY] & DA9063_COUNT_DAY_MASK; 174 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 175 + 176 + tm->tm_sec = data[RTC_SEC] & config->rtc_count_sec_mask; 177 + tm->tm_min = data[RTC_MIN] & config->rtc_count_min_mask; 178 + tm->tm_hour = data[RTC_HOUR] & config->rtc_count_hour_mask; 179 + tm->tm_mday = data[RTC_DAY] & config->rtc_count_day_mask; 62 180 tm->tm_mon = MONTHS_FROM_DA9063(data[RTC_MONTH] & 63 - DA9063_COUNT_MONTH_MASK); 181 + config->rtc_count_month_mask); 64 182 tm->tm_year = YEARS_FROM_DA9063(data[RTC_YEAR] & 65 - DA9063_COUNT_YEAR_MASK); 183 + config->rtc_count_year_mask); 66 184 } 67 185 68 - static void da9063_tm_to_data(struct rtc_time *tm, u8 *data) 186 + static void da9063_tm_to_data(struct rtc_time *tm, u8 *data, 187 + struct da9063_compatible_rtc *rtc) 69 188 { 70 - data[RTC_SEC] &= ~DA9063_COUNT_SEC_MASK; 71 - data[RTC_SEC] |= tm->tm_sec & DA9063_COUNT_SEC_MASK; 189 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 72 190 73 - data[RTC_MIN] &= ~DA9063_COUNT_MIN_MASK; 74 - data[RTC_MIN] |= tm->tm_min & DA9063_COUNT_MIN_MASK; 191 + data[RTC_SEC] &= ~config->rtc_count_sec_mask; 192 + data[RTC_SEC] |= tm->tm_sec & config->rtc_count_sec_mask; 75 193 76 - data[RTC_HOUR] &= ~DA9063_COUNT_HOUR_MASK; 77 - data[RTC_HOUR] |= tm->tm_hour & DA9063_COUNT_HOUR_MASK; 194 + data[RTC_MIN] &= ~config->rtc_count_min_mask; 195 + data[RTC_MIN] |= tm->tm_min & config->rtc_count_min_mask; 78 196 79 - data[RTC_DAY] &= ~DA9063_COUNT_DAY_MASK; 80 - data[RTC_DAY] |= tm->tm_mday & DA9063_COUNT_DAY_MASK; 197 + data[RTC_HOUR] &= ~config->rtc_count_hour_mask; 198 + data[RTC_HOUR] |= tm->tm_hour & config->rtc_count_hour_mask; 81 199 82 - data[RTC_MONTH] &= ~DA9063_COUNT_MONTH_MASK; 200 + data[RTC_DAY] &= ~config->rtc_count_day_mask; 201 + data[RTC_DAY] |= tm->tm_mday & config->rtc_count_day_mask; 202 + 203 + data[RTC_MONTH] &= ~config->rtc_count_month_mask; 83 204 data[RTC_MONTH] |= MONTHS_TO_DA9063(tm->tm_mon) & 84 - DA9063_COUNT_MONTH_MASK; 205 + config->rtc_count_month_mask; 85 206 86 - data[RTC_YEAR] &= ~DA9063_COUNT_YEAR_MASK; 207 + data[RTC_YEAR] &= ~config->rtc_count_year_mask; 87 208 data[RTC_YEAR] |= YEARS_TO_DA9063(tm->tm_year) & 88 - DA9063_COUNT_YEAR_MASK; 209 + config->rtc_count_year_mask; 89 210 } 90 211 91 212 static int da9063_rtc_stop_alarm(struct device *dev) 92 213 { 93 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 214 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 215 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 94 216 95 - return regmap_update_bits(rtc->hw->regmap, rtc->alarm_year, 96 - DA9063_ALARM_ON, 0); 217 + return regmap_update_bits(rtc->regmap, 218 + config->rtc_alarm_year_reg, 219 + config->rtc_alarm_on_mask, 220 + 0); 97 221 } 98 222 99 223 static int da9063_rtc_start_alarm(struct device *dev) 100 224 { 101 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 225 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 226 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 102 227 103 - return regmap_update_bits(rtc->hw->regmap, rtc->alarm_year, 104 - DA9063_ALARM_ON, DA9063_ALARM_ON); 228 + return regmap_update_bits(rtc->regmap, 229 + config->rtc_alarm_year_reg, 230 + config->rtc_alarm_on_mask, 231 + config->rtc_alarm_on_mask); 105 232 } 106 233 107 234 static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm) 108 235 { 109 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 236 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 237 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 110 238 unsigned long tm_secs; 111 239 unsigned long al_secs; 112 240 u8 data[RTC_DATA_LEN]; 113 241 int ret; 114 242 115 - ret = regmap_bulk_read(rtc->hw->regmap, DA9063_REG_COUNT_S, 243 + ret = regmap_bulk_read(rtc->regmap, 244 + config->rtc_count_secs_reg, 116 245 data, RTC_DATA_LEN); 117 246 if (ret < 0) { 118 247 dev_err(dev, "Failed to read RTC time data: %d\n", ret); 119 248 return ret; 120 249 } 121 250 122 - if (!(data[RTC_SEC] & DA9063_RTC_READ)) { 251 + if (!(data[RTC_SEC] & config->rtc_ready_to_read_mask)) { 123 252 dev_dbg(dev, "RTC not yet ready to be read by the host\n"); 124 253 return -EINVAL; 125 254 } 126 255 127 - da9063_data_to_tm(data, tm); 256 + da9063_data_to_tm(data, tm, rtc); 128 257 129 258 rtc_tm_to_time(tm, &tm_secs); 130 259 rtc_tm_to_time(&rtc->alarm_time, &al_secs); ··· 272 137 273 138 static int da9063_rtc_set_time(struct device *dev, struct rtc_time *tm) 274 139 { 275 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 140 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 141 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 276 142 u8 data[RTC_DATA_LEN]; 277 143 int ret; 278 144 279 - da9063_tm_to_data(tm, data); 280 - ret = regmap_bulk_write(rtc->hw->regmap, DA9063_REG_COUNT_S, 145 + da9063_tm_to_data(tm, data, rtc); 146 + ret = regmap_bulk_write(rtc->regmap, 147 + config->rtc_count_secs_reg, 281 148 data, RTC_DATA_LEN); 282 149 if (ret < 0) 283 150 dev_err(dev, "Failed to set RTC time data: %d\n", ret); ··· 289 152 290 153 static int da9063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 291 154 { 292 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 155 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 156 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 293 157 u8 data[RTC_DATA_LEN]; 294 158 int ret; 295 159 unsigned int val; 296 160 297 161 data[RTC_SEC] = 0; 298 - ret = regmap_bulk_read(rtc->hw->regmap, rtc->alarm_start, 299 - &data[rtc->data_start], rtc->alarm_len); 162 + ret = regmap_bulk_read(rtc->regmap, 163 + config->rtc_alarm_secs_reg, 164 + &data[config->rtc_data_start], 165 + config->rtc_alarm_len); 300 166 if (ret < 0) 301 167 return ret; 302 168 303 - da9063_data_to_tm(data, &alrm->time); 169 + da9063_data_to_tm(data, &alrm->time, rtc); 304 170 305 - alrm->enabled = !!(data[RTC_YEAR] & DA9063_ALARM_ON); 171 + alrm->enabled = !!(data[RTC_YEAR] & config->rtc_alarm_on_mask); 306 172 307 - ret = regmap_read(rtc->hw->regmap, DA9063_REG_EVENT_A, &val); 173 + ret = regmap_read(rtc->regmap, 174 + config->rtc_event_reg, 175 + &val); 308 176 if (ret < 0) 309 177 return ret; 310 178 311 - if (val & (DA9063_E_ALARM)) 179 + if (val & config->rtc_event_alarm_mask) 312 180 alrm->pending = 1; 313 181 else 314 182 alrm->pending = 0; ··· 323 181 324 182 static int da9063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 325 183 { 326 - struct da9063_rtc *rtc = dev_get_drvdata(dev); 184 + struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev); 185 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 327 186 u8 data[RTC_DATA_LEN]; 328 187 int ret; 329 188 330 - da9063_tm_to_data(&alrm->time, data); 189 + da9063_tm_to_data(&alrm->time, data, rtc); 331 190 332 191 ret = da9063_rtc_stop_alarm(dev); 333 192 if (ret < 0) { ··· 336 193 return ret; 337 194 } 338 195 339 - ret = regmap_bulk_write(rtc->hw->regmap, rtc->alarm_start, 340 - &data[rtc->data_start], rtc->alarm_len); 196 + ret = regmap_bulk_write(rtc->regmap, 197 + config->rtc_alarm_secs_reg, 198 + &data[config->rtc_data_start], 199 + config->rtc_alarm_len); 341 200 if (ret < 0) { 342 201 dev_err(dev, "Failed to write alarm: %d\n", ret); 343 202 return ret; 344 203 } 345 204 346 - da9063_data_to_tm(data, &rtc->alarm_time); 205 + da9063_data_to_tm(data, &rtc->alarm_time, rtc); 347 206 348 207 if (alrm->enabled) { 349 208 ret = da9063_rtc_start_alarm(dev); ··· 358 213 return ret; 359 214 } 360 215 361 - static int da9063_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 216 + static int da9063_rtc_alarm_irq_enable(struct device *dev, 217 + unsigned int enabled) 362 218 { 363 219 if (enabled) 364 220 return da9063_rtc_start_alarm(dev); ··· 369 223 370 224 static irqreturn_t da9063_alarm_event(int irq, void *data) 371 225 { 372 - struct da9063_rtc *rtc = data; 226 + struct da9063_compatible_rtc *rtc = data; 227 + const struct da9063_compatible_rtc_regmap *config = rtc->config; 373 228 374 - regmap_update_bits(rtc->hw->regmap, rtc->alarm_year, 375 - DA9063_ALARM_ON, 0); 229 + regmap_update_bits(rtc->regmap, 230 + config->rtc_alarm_year_reg, 231 + config->rtc_alarm_on_mask, 232 + 0); 376 233 377 234 rtc->rtc_sync = true; 378 235 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF); ··· 393 244 394 245 static int da9063_rtc_probe(struct platform_device *pdev) 395 246 { 396 - struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); 397 - struct da9063_rtc *rtc; 247 + struct da9063_compatible_rtc *rtc; 248 + const struct da9063_compatible_rtc_regmap *config; 249 + const struct of_device_id *match; 398 250 int irq_alarm; 399 251 u8 data[RTC_DATA_LEN]; 400 252 int ret; 401 253 402 - ret = regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_E, 403 - DA9063_RTC_EN, DA9063_RTC_EN); 404 - if (ret < 0) { 405 - dev_err(&pdev->dev, "Failed to enable RTC\n"); 406 - goto err; 407 - } 254 + if (!pdev->dev.of_node) 255 + return -ENXIO; 408 256 409 - ret = regmap_update_bits(da9063->regmap, DA9063_REG_EN_32K, 410 - DA9063_CRYSTAL, DA9063_CRYSTAL); 411 - if (ret < 0) { 412 - dev_err(&pdev->dev, "Failed to run 32kHz oscillator\n"); 413 - goto err; 414 - } 257 + match = of_match_node(da9063_compatible_reg_id_table, 258 + pdev->dev.of_node); 415 259 416 260 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); 417 261 if (!rtc) 418 262 return -ENOMEM; 419 263 420 - if (da9063->variant_code == PMIC_DA9063_AD) { 421 - rtc->alarm_year = DA9063_AD_REG_ALARM_Y; 422 - rtc->alarm_start = DA9063_AD_REG_ALARM_MI; 423 - rtc->alarm_len = RTC_ALARM_DATA_LEN; 424 - rtc->data_start = RTC_MIN; 425 - } else { 426 - rtc->alarm_year = DA9063_BB_REG_ALARM_Y; 427 - rtc->alarm_start = DA9063_BB_REG_ALARM_S; 428 - rtc->alarm_len = RTC_DATA_LEN; 429 - rtc->data_start = RTC_SEC; 264 + rtc->config = match->data; 265 + if (of_device_is_compatible(pdev->dev.of_node, "dlg,da9063-rtc")) { 266 + struct da9063 *chip = dev_get_drvdata(pdev->dev.parent); 267 + 268 + if (chip->variant_code == PMIC_DA9063_AD) 269 + rtc->config = &da9063_ad_regs; 430 270 } 431 271 432 - ret = regmap_update_bits(da9063->regmap, rtc->alarm_start, 433 - DA9063_ALARM_STATUS_TICK | DA9063_ALARM_STATUS_ALARM, 434 - 0); 272 + rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL); 273 + if (!rtc->regmap) { 274 + dev_warn(&pdev->dev, "Parent regmap unavailable.\n"); 275 + return -ENXIO; 276 + } 277 + 278 + config = rtc->config; 279 + ret = regmap_update_bits(rtc->regmap, 280 + config->rtc_enable_reg, 281 + config->rtc_enable_mask, 282 + config->rtc_enable_mask); 283 + if (ret < 0) { 284 + dev_err(&pdev->dev, "Failed to enable RTC\n"); 285 + return ret; 286 + } 287 + 288 + ret = regmap_update_bits(rtc->regmap, 289 + config->rtc_enable_32k_crystal_reg, 290 + config->rtc_crystal_mask, 291 + config->rtc_crystal_mask); 292 + if (ret < 0) { 293 + dev_err(&pdev->dev, "Failed to run 32kHz oscillator\n"); 294 + return ret; 295 + } 296 + 297 + ret = regmap_update_bits(rtc->regmap, 298 + config->rtc_alarm_secs_reg, 299 + config->rtc_alarm_status_mask, 300 + 0); 435 301 if (ret < 0) { 436 302 dev_err(&pdev->dev, "Failed to access RTC alarm register\n"); 437 - goto err; 303 + return ret; 438 304 } 439 305 440 - ret = regmap_update_bits(da9063->regmap, rtc->alarm_start, 306 + ret = regmap_update_bits(rtc->regmap, 307 + config->rtc_alarm_secs_reg, 441 308 DA9063_ALARM_STATUS_ALARM, 442 309 DA9063_ALARM_STATUS_ALARM); 443 310 if (ret < 0) { 444 311 dev_err(&pdev->dev, "Failed to access RTC alarm register\n"); 445 - goto err; 312 + return ret; 446 313 } 447 314 448 - ret = regmap_update_bits(da9063->regmap, rtc->alarm_year, 449 - DA9063_TICK_ON, 0); 315 + ret = regmap_update_bits(rtc->regmap, 316 + config->rtc_alarm_year_reg, 317 + config->rtc_tick_on_mask, 318 + 0); 450 319 if (ret < 0) { 451 320 dev_err(&pdev->dev, "Failed to disable TICKs\n"); 452 - goto err; 321 + return ret; 453 322 } 454 323 455 324 data[RTC_SEC] = 0; 456 - ret = regmap_bulk_read(da9063->regmap, rtc->alarm_start, 457 - &data[rtc->data_start], rtc->alarm_len); 325 + ret = regmap_bulk_read(rtc->regmap, 326 + config->rtc_alarm_secs_reg, 327 + &data[config->rtc_data_start], 328 + config->rtc_alarm_len); 458 329 if (ret < 0) { 459 330 dev_err(&pdev->dev, "Failed to read initial alarm data: %d\n", 460 331 ret); 461 - goto err; 332 + return ret; 462 333 } 463 334 464 335 platform_set_drvdata(pdev, rtc); ··· 491 322 if (ret) { 492 323 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n", 493 324 irq_alarm, ret); 494 - goto err; 325 + return ret; 495 326 } 496 327 497 - rtc->hw = da9063; 498 328 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC, 499 329 &da9063_rtc_ops, THIS_MODULE); 500 330 if (IS_ERR(rtc->rtc_dev)) 501 331 return PTR_ERR(rtc->rtc_dev); 502 332 503 - da9063_data_to_tm(data, &rtc->alarm_time); 333 + da9063_data_to_tm(data, &rtc->alarm_time, rtc); 504 334 rtc->rtc_sync = false; 505 - err: 506 335 return ret; 507 336 } 508 337 ··· 508 341 .probe = da9063_rtc_probe, 509 342 .driver = { 510 343 .name = DA9063_DRVNAME_RTC, 344 + .of_match_table = da9063_compatible_reg_id_table, 511 345 }, 512 346 }; 513 347
+1
drivers/rtc/rtc-dev.c
··· 477 477 478 478 cdev_init(&rtc->char_dev, &rtc_dev_fops); 479 479 rtc->char_dev.owner = rtc->owner; 480 + rtc->char_dev.kobj.parent = &rtc->dev.kobj; 480 481 } 481 482 482 483 void rtc_dev_add_device(struct rtc_device *rtc)
-18
drivers/rtc/rtc-ds1305.c
··· 538 538 539 539 spi = container_of(kobj, struct spi_device, dev.kobj); 540 540 541 - if (unlikely(off >= DS1305_NVRAM_LEN)) 542 - return 0; 543 - if (count >= DS1305_NVRAM_LEN) 544 - count = DS1305_NVRAM_LEN; 545 - if ((off + count) > DS1305_NVRAM_LEN) 546 - count = DS1305_NVRAM_LEN - off; 547 - if (unlikely(!count)) 548 - return count; 549 - 550 541 addr = DS1305_NVRAM + off; 551 542 msg_init(&m, x, &addr, count, NULL, buf); 552 543 ··· 559 568 int status; 560 569 561 570 spi = container_of(kobj, struct spi_device, dev.kobj); 562 - 563 - if (unlikely(off >= DS1305_NVRAM_LEN)) 564 - return -EFBIG; 565 - if (count >= DS1305_NVRAM_LEN) 566 - count = DS1305_NVRAM_LEN; 567 - if ((off + count) > DS1305_NVRAM_LEN) 568 - count = DS1305_NVRAM_LEN - off; 569 - if (unlikely(!count)) 570 - return count; 571 571 572 572 addr = (DS1305_WRITE | DS1305_NVRAM) + off; 573 573 msg_init(&m, x, &addr, count, buf, NULL);
+57 -65
drivers/rtc/rtc-ds1307.c
··· 11 11 * published by the Free Software Foundation. 12 12 */ 13 13 14 - #include <linux/module.h> 15 - #include <linux/init.h> 16 - #include <linux/slab.h> 17 - #include <linux/i2c.h> 18 - #include <linux/string.h> 19 - #include <linux/rtc.h> 20 14 #include <linux/bcd.h> 15 + #include <linux/i2c.h> 16 + #include <linux/init.h> 17 + #include <linux/module.h> 18 + #include <linux/of_device.h> 19 + #include <linux/of_irq.h> 20 + #include <linux/pm_wakeirq.h> 21 21 #include <linux/rtc/ds1307.h> 22 + #include <linux/rtc.h> 23 + #include <linux/slab.h> 24 + #include <linux/string.h> 22 25 23 26 /* 24 27 * We can't determine type by probing, but if we expect pre-Linux code ··· 117 114 #define HAS_ALARM 1 /* bit 1 == irq claimed */ 118 115 struct i2c_client *client; 119 116 struct rtc_device *rtc; 120 - struct work_struct work; 117 + int wakeirq; 121 118 s32 (*read_block_data)(const struct i2c_client *client, u8 command, 122 119 u8 length, u8 *values); 123 120 s32 (*write_block_data)(const struct i2c_client *client, u8 command, ··· 314 311 /*----------------------------------------------------------------------*/ 315 312 316 313 /* 317 - * The IRQ logic includes a "real" handler running in IRQ context just 318 - * long enough to schedule this workqueue entry. We need a task context 319 - * to talk to the RTC, since I2C I/O calls require that; and disable the 320 - * IRQ until we clear its status on the chip, so that this handler can 321 - * work with any type of triggering (not just falling edge). 322 - * 323 314 * The ds1337 and ds1339 both have two alarms, but we only use the first 324 315 * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm 325 316 * signal; ds1339 chips have only one alarm signal. 326 317 */ 327 - static void ds1307_work(struct work_struct *work) 318 + static irqreturn_t ds1307_irq(int irq, void *dev_id) 328 319 { 329 - struct ds1307 *ds1307; 330 - struct i2c_client *client; 331 - struct mutex *lock; 320 + struct i2c_client *client = dev_id; 321 + struct ds1307 *ds1307 = i2c_get_clientdata(client); 322 + struct mutex *lock = &ds1307->rtc->ops_lock; 332 323 int stat, control; 333 - 334 - ds1307 = container_of(work, struct ds1307, work); 335 - client = ds1307->client; 336 - lock = &ds1307->rtc->ops_lock; 337 324 338 325 mutex_lock(lock); 339 326 stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS); ··· 345 352 } 346 353 347 354 out: 348 - if (test_bit(HAS_ALARM, &ds1307->flags)) 349 - enable_irq(client->irq); 350 355 mutex_unlock(lock); 351 - } 352 356 353 - static irqreturn_t ds1307_irq(int irq, void *dev_id) 354 - { 355 - struct i2c_client *client = dev_id; 356 - struct ds1307 *ds1307 = i2c_get_clientdata(client); 357 - 358 - disable_irq_nosync(irq); 359 - schedule_work(&ds1307->work); 360 357 return IRQ_HANDLED; 361 358 } 362 359 ··· 617 634 MCP794XX_BIT_ALMX_C1 | \ 618 635 MCP794XX_BIT_ALMX_C2) 619 636 620 - static void mcp794xx_work(struct work_struct *work) 637 + static irqreturn_t mcp794xx_irq(int irq, void *dev_id) 621 638 { 622 - struct ds1307 *ds1307 = container_of(work, struct ds1307, work); 623 - struct i2c_client *client = ds1307->client; 639 + struct i2c_client *client = dev_id; 640 + struct ds1307 *ds1307 = i2c_get_clientdata(client); 641 + struct mutex *lock = &ds1307->rtc->ops_lock; 624 642 int reg, ret; 625 643 626 - mutex_lock(&ds1307->rtc->ops_lock); 644 + mutex_lock(lock); 627 645 628 646 /* Check and clear alarm 0 interrupt flag. */ 629 647 reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_ALARM0_CTRL); ··· 649 665 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF); 650 666 651 667 out: 652 - if (test_bit(HAS_ALARM, &ds1307->flags)) 653 - enable_irq(client->irq); 654 - mutex_unlock(&ds1307->rtc->ops_lock); 668 + mutex_unlock(lock); 669 + 670 + return IRQ_HANDLED; 655 671 } 656 672 657 673 static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t) ··· 782 798 client = kobj_to_i2c_client(kobj); 783 799 ds1307 = i2c_get_clientdata(client); 784 800 785 - if (unlikely(off >= ds1307->nvram->size)) 786 - return 0; 787 - if ((off + count) > ds1307->nvram->size) 788 - count = ds1307->nvram->size - off; 789 - if (unlikely(!count)) 790 - return count; 791 - 792 801 result = ds1307->read_block_data(client, ds1307->nvram_offset + off, 793 802 count, buf); 794 803 if (result < 0) ··· 800 823 801 824 client = kobj_to_i2c_client(kobj); 802 825 ds1307 = i2c_get_clientdata(client); 803 - 804 - if (unlikely(off >= ds1307->nvram->size)) 805 - return -EFBIG; 806 - if ((off + count) > ds1307->nvram->size) 807 - count = ds1307->nvram->size - off; 808 - if (unlikely(!count)) 809 - return count; 810 826 811 827 result = ds1307->write_block_data(client, ds1307->nvram_offset + off, 812 828 count, buf); ··· 866 896 bool want_irq = false; 867 897 unsigned char *buf; 868 898 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); 899 + irq_handler_t irq_handler = ds1307_irq; 900 + 869 901 static const int bbsqi_bitpos[] = { 870 902 [ds_1337] = 0, 871 903 [ds_1339] = DS1339_BIT_BBSQI, ··· 934 962 * running on Vbackup (BBSQI/BBSQW) 935 963 */ 936 964 if (ds1307->client->irq > 0 && chip->alarm) { 937 - INIT_WORK(&ds1307->work, ds1307_work); 938 - 939 965 ds1307->regs[0] |= DS1337_BIT_INTCN 940 966 | bbsqi_bitpos[ds1307->type]; 941 967 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE); ··· 1023 1053 case mcp794xx: 1024 1054 rtc_ops = &mcp794xx_rtc_ops; 1025 1055 if (ds1307->client->irq > 0 && chip->alarm) { 1026 - INIT_WORK(&ds1307->work, mcp794xx_work); 1056 + irq_handler = mcp794xx_irq; 1027 1057 want_irq = true; 1028 1058 } 1029 1059 break; ··· 1146 1176 } 1147 1177 1148 1178 if (want_irq) { 1149 - err = request_irq(client->irq, ds1307_irq, IRQF_SHARED, 1150 - ds1307->rtc->name, client); 1179 + struct device_node *node = client->dev.of_node; 1180 + 1181 + err = devm_request_threaded_irq(&client->dev, 1182 + client->irq, NULL, irq_handler, 1183 + IRQF_SHARED | IRQF_ONESHOT, 1184 + ds1307->rtc->name, client); 1151 1185 if (err) { 1152 1186 client->irq = 0; 1153 1187 dev_err(&client->dev, "unable to request IRQ!\n"); 1154 - } else { 1188 + goto no_irq; 1189 + } 1155 1190 1156 - set_bit(HAS_ALARM, &ds1307->flags); 1157 - dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 1191 + set_bit(HAS_ALARM, &ds1307->flags); 1192 + dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 1193 + 1194 + /* Currently supported by OF code only! */ 1195 + if (!node) 1196 + goto no_irq; 1197 + 1198 + err = of_irq_get(node, 1); 1199 + if (err <= 0) { 1200 + if (err == -EPROBE_DEFER) 1201 + goto exit; 1202 + goto no_irq; 1203 + } 1204 + ds1307->wakeirq = err; 1205 + 1206 + err = dev_pm_set_dedicated_wake_irq(&client->dev, 1207 + ds1307->wakeirq); 1208 + if (err) { 1209 + dev_err(&client->dev, "unable to setup wakeIRQ %d!\n", 1210 + err); 1211 + goto exit; 1158 1212 } 1159 1213 } 1160 1214 1215 + no_irq: 1161 1216 if (chip->nvram_size) { 1162 1217 1163 1218 ds1307->nvram = devm_kzalloc(&client->dev, ··· 1226 1231 { 1227 1232 struct ds1307 *ds1307 = i2c_get_clientdata(client); 1228 1233 1229 - if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) { 1230 - free_irq(client->irq, client); 1231 - cancel_work_sync(&ds1307->work); 1232 - } 1234 + if (ds1307->wakeirq) 1235 + dev_pm_clear_wake_irq(&client->dev); 1233 1236 1234 1237 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) 1235 1238 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); ··· 1238 1245 static struct i2c_driver ds1307_driver = { 1239 1246 .driver = { 1240 1247 .name = "rtc-ds1307", 1241 - .owner = THIS_MODULE, 1242 1248 }, 1243 1249 .probe = ds1307_probe, 1244 1250 .remove = ds1307_remove,
-12
drivers/rtc/rtc-ds1343.c
··· 162 162 struct device *dev = kobj_to_dev(kobj); 163 163 struct ds1343_priv *priv = dev_get_drvdata(dev); 164 164 165 - if (unlikely(!count)) 166 - return count; 167 - 168 - if ((count + off) > DS1343_NVRAM_LEN) 169 - count = DS1343_NVRAM_LEN - off; 170 - 171 165 address = DS1343_NVRAM + off; 172 166 173 167 ret = regmap_bulk_write(priv->map, address, buf, count); ··· 180 186 unsigned char address; 181 187 struct device *dev = kobj_to_dev(kobj); 182 188 struct ds1343_priv *priv = dev_get_drvdata(dev); 183 - 184 - if (unlikely(!count)) 185 - return count; 186 - 187 - if ((count + off) > DS1343_NVRAM_LEN) 188 - count = DS1343_NVRAM_LEN - off; 189 189 190 190 address = DS1343_NVRAM + off; 191 191
+2 -5
drivers/rtc/rtc-ds1374.c
··· 664 664 { 665 665 struct ds1374 *ds1374 = i2c_get_clientdata(client); 666 666 #ifdef CONFIG_RTC_DRV_DS1374_WDT 667 - int res; 668 - 669 667 misc_deregister(&ds1374_miscdev); 670 668 ds1374_miscdev.parent = NULL; 671 669 unregister_reboot_notifier(&ds1374_wdt_notifier); ··· 686 688 { 687 689 struct i2c_client *client = to_i2c_client(dev); 688 690 689 - if (client->irq >= 0 && device_may_wakeup(&client->dev)) 691 + if (client->irq > 0 && device_may_wakeup(&client->dev)) 690 692 enable_irq_wake(client->irq); 691 693 return 0; 692 694 } ··· 695 697 { 696 698 struct i2c_client *client = to_i2c_client(dev); 697 699 698 - if (client->irq >= 0 && device_may_wakeup(&client->dev)) 700 + if (client->irq > 0 && device_may_wakeup(&client->dev)) 699 701 disable_irq_wake(client->irq); 700 702 return 0; 701 703 } ··· 706 708 static struct i2c_driver ds1374_driver = { 707 709 .driver = { 708 710 .name = "rtc-ds1374", 709 - .owner = THIS_MODULE, 710 711 .pm = &ds1374_pm, 711 712 }, 712 713 .probe = ds1374_probe,
+5 -37
drivers/rtc/rtc-ds1511.c
··· 64 64 #define DS1511_KIE 0x04 65 65 #define DS1511_WDE 0x02 66 66 #define DS1511_WDS 0x01 67 - #define DS1511_RAM_MAX 0xff 67 + #define DS1511_RAM_MAX 0x100 68 68 69 69 #define RTC_CMD DS1511_CONTROL_B 70 70 #define RTC_CMD1 DS1511_CONTROL_A ··· 159 159 /* 160 160 * set wdog enable and wdog 'steering' bit to issue a reset 161 161 */ 162 - rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD); 162 + rtc_write(rtc_read(RTC_CMD) | DS1511_WDE | DS1511_WDS, RTC_CMD); 163 163 } 164 164 165 165 void ··· 407 407 { 408 408 ssize_t count; 409 409 410 - /* 411 - * if count is more than one, turn on "burst" mode 412 - * turn it off when you're done 413 - */ 414 - if (size > 1) 415 - rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); 416 - 417 - if (pos > DS1511_RAM_MAX) 418 - pos = DS1511_RAM_MAX; 419 - 420 - if (size + pos > DS1511_RAM_MAX + 1) 421 - size = DS1511_RAM_MAX - pos + 1; 422 - 423 410 rtc_write(pos, DS1511_RAMADDR_LSB); 424 - for (count = 0; size > 0; count++, size--) 411 + for (count = 0; count < size; count++) 425 412 *buf++ = rtc_read(DS1511_RAMDATA); 426 - 427 - if (count > 1) 428 - rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); 429 413 430 414 return count; 431 415 } ··· 421 437 { 422 438 ssize_t count; 423 439 424 - /* 425 - * if count is more than one, turn on "burst" mode 426 - * turn it off when you're done 427 - */ 428 - if (size > 1) 429 - rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); 430 - 431 - if (pos > DS1511_RAM_MAX) 432 - pos = DS1511_RAM_MAX; 433 - 434 - if (size + pos > DS1511_RAM_MAX + 1) 435 - size = DS1511_RAM_MAX - pos + 1; 436 - 437 440 rtc_write(pos, DS1511_RAMADDR_LSB); 438 - for (count = 0; size > 0; count++, size--) 441 + for (count = 0; count < size; count++) 439 442 rtc_write(*buf++, DS1511_RAMDATA); 440 - 441 - if (count > 1) 442 - rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); 443 443 444 444 return count; 445 445 } ··· 458 490 /* 459 491 * turn on the clock and the crystal, etc. 460 492 */ 461 - rtc_write(0, RTC_CMD); 493 + rtc_write(DS1511_BME, RTC_CMD); 462 494 rtc_write(0, RTC_CMD1); 463 495 /* 464 496 * clear the wdog counter
+2 -2
drivers/rtc/rtc-ds1553.c
··· 245 245 void __iomem *ioaddr = pdata->ioaddr; 246 246 ssize_t count; 247 247 248 - for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) 248 + for (count = 0; count < size; count++) 249 249 *buf++ = readb(ioaddr + pos++); 250 250 return count; 251 251 } ··· 260 260 void __iomem *ioaddr = pdata->ioaddr; 261 261 ssize_t count; 262 262 263 - for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) 263 + for (count = 0; count < size; count++) 264 264 writeb(*buf++, ioaddr + pos++); 265 265 return count; 266 266 }
+1 -21
drivers/rtc/rtc-ds1685.c
··· 2145 2145 .probe = ds1685_rtc_probe, 2146 2146 .remove = ds1685_rtc_remove, 2147 2147 }; 2148 - 2149 - /** 2150 - * ds1685_rtc_init - rtc module init. 2151 - */ 2152 - static int __init 2153 - ds1685_rtc_init(void) 2154 - { 2155 - return platform_driver_register(&ds1685_rtc_driver); 2156 - } 2157 - 2158 - /** 2159 - * ds1685_rtc_exit - rtc module exit. 2160 - */ 2161 - static void __exit 2162 - ds1685_rtc_exit(void) 2163 - { 2164 - platform_driver_unregister(&ds1685_rtc_driver); 2165 - } 2166 - 2167 - module_init(ds1685_rtc_init); 2168 - module_exit(ds1685_rtc_exit); 2148 + module_platform_driver(ds1685_rtc_driver); 2169 2149 /* ----------------------------------------------------------------------- */ 2170 2150 2171 2151
+2 -2
drivers/rtc/rtc-ds1742.c
··· 134 134 void __iomem *ioaddr = pdata->ioaddr_nvram; 135 135 ssize_t count; 136 136 137 - for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--) 137 + for (count = 0; count < size; count++) 138 138 *buf++ = readb(ioaddr + pos++); 139 139 return count; 140 140 } ··· 149 149 void __iomem *ioaddr = pdata->ioaddr_nvram; 150 150 ssize_t count; 151 151 152 - for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--) 152 + for (count = 0; count < size; count++) 153 153 writeb(*buf++, ioaddr + pos++); 154 154 return count; 155 155 }
+5 -3
drivers/rtc/rtc-ds3232.c
··· 443 443 { 444 444 struct ds3232 *ds3232 = i2c_get_clientdata(client); 445 445 446 - if (client->irq >= 0) { 446 + if (client->irq > 0) { 447 447 mutex_lock(&ds3232->mutex); 448 448 ds3232->exiting = 1; 449 449 mutex_unlock(&ds3232->mutex); ··· 463 463 464 464 if (device_can_wakeup(dev)) { 465 465 ds3232->suspended = true; 466 - irq_set_irq_wake(client->irq, 1); 466 + if (irq_set_irq_wake(client->irq, 1)) { 467 + dev_warn_once(dev, "Cannot set wakeup source\n"); 468 + ds3232->suspended = false; 469 + } 467 470 } 468 471 469 472 return 0; ··· 503 500 static struct i2c_driver ds3232_driver = { 504 501 .driver = { 505 502 .name = "rtc-ds3232", 506 - .owner = THIS_MODULE, 507 503 .pm = &ds3232_pm_ops, 508 504 }, 509 505 .probe = ds3232_probe,
-1
drivers/rtc/rtc-fm3130.c
··· 523 523 static struct i2c_driver fm3130_driver = { 524 524 .driver = { 525 525 .name = "rtc-fm3130", 526 - .owner = THIS_MODULE, 527 526 }, 528 527 .probe = fm3130_probe, 529 528 .id_table = fm3130_id,
+1 -4
drivers/rtc/rtc-gemini.c
··· 148 148 149 149 rtc->rtc_dev = rtc_device_register(pdev->name, dev, 150 150 &gemini_rtc_ops, THIS_MODULE); 151 - if (likely(IS_ERR(rtc->rtc_dev))) 152 - return PTR_ERR(rtc->rtc_dev); 153 - 154 - return 0; 151 + return PTR_ERR_OR_ZERO(rtc->rtc_dev); 155 152 } 156 153 157 154 static int gemini_rtc_remove(struct platform_device *pdev)
-1
drivers/rtc/rtc-hym8563.c
··· 599 599 static struct i2c_driver hym8563_driver = { 600 600 .driver = { 601 601 .name = "rtc-hym8563", 602 - .owner = THIS_MODULE, 603 602 .pm = &hym8563_pm_ops, 604 603 .of_match_table = hym8563_dt_idtable, 605 604 },
+2 -6
drivers/rtc/rtc-isl12022.c
··· 151 151 tm->tm_sec, tm->tm_min, tm->tm_hour, 152 152 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 153 153 154 - /* The clock can give out invalid datetime, but we cannot return 155 - * -EINVAL otherwise hwclock will refuse to set the time on bootup. */ 156 - if (rtc_valid_tm(tm) < 0) 157 - dev_err(&client->dev, "retrieved date and time is invalid.\n"); 158 - 159 - return 0; 154 + return rtc_valid_tm(tm); 160 155 } 161 156 162 157 static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm) ··· 274 279 { .compatible = "isil,isl12022" }, 275 280 { }, 276 281 }; 282 + MODULE_DEVICE_TABLE(of, isl12022_dt_match); 277 283 #endif 278 284 279 285 static const struct i2c_device_id isl12022_id[] = {
+1 -1
drivers/rtc/rtc-isl12057.c
··· 648 648 { .compatible = "isil,isl12057" }, 649 649 { }, 650 650 }; 651 + MODULE_DEVICE_TABLE(of, isl12057_dt_match); 651 652 #endif 652 653 653 654 static const struct i2c_device_id isl12057_id[] = { ··· 660 659 static struct i2c_driver isl12057_driver = { 661 660 .driver = { 662 661 .name = DRV_NAME, 663 - .owner = THIS_MODULE, 664 662 .pm = &isl12057_rtc_pm_ops, 665 663 .of_match_table = of_match_ptr(isl12057_dt_match), 666 664 },
+310
drivers/rtc/rtc-lpc24xx.c
··· 1 + /* 2 + * RTC driver for NXP LPC178x/18xx/43xx Real-Time Clock (RTC) 3 + * 4 + * Copyright (C) 2011 NXP Semiconductors 5 + * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2 of the License, or 10 + * (at your option) any later version. 11 + * 12 + */ 13 + 14 + #include <linux/clk.h> 15 + #include <linux/io.h> 16 + #include <linux/kernel.h> 17 + #include <linux/module.h> 18 + #include <linux/of.h> 19 + #include <linux/of_device.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/rtc.h> 22 + 23 + /* LPC24xx RTC register offsets and bits */ 24 + #define LPC24XX_ILR 0x00 25 + #define LPC24XX_RTCCIF BIT(0) 26 + #define LPC24XX_RTCALF BIT(1) 27 + #define LPC24XX_CTC 0x04 28 + #define LPC24XX_CCR 0x08 29 + #define LPC24XX_CLKEN BIT(0) 30 + #define LPC178X_CCALEN BIT(4) 31 + #define LPC24XX_CIIR 0x0c 32 + #define LPC24XX_AMR 0x10 33 + #define LPC24XX_ALARM_DISABLE 0xff 34 + #define LPC24XX_CTIME0 0x14 35 + #define LPC24XX_CTIME1 0x18 36 + #define LPC24XX_CTIME2 0x1c 37 + #define LPC24XX_SEC 0x20 38 + #define LPC24XX_MIN 0x24 39 + #define LPC24XX_HOUR 0x28 40 + #define LPC24XX_DOM 0x2c 41 + #define LPC24XX_DOW 0x30 42 + #define LPC24XX_DOY 0x34 43 + #define LPC24XX_MONTH 0x38 44 + #define LPC24XX_YEAR 0x3c 45 + #define LPC24XX_ALSEC 0x60 46 + #define LPC24XX_ALMIN 0x64 47 + #define LPC24XX_ALHOUR 0x68 48 + #define LPC24XX_ALDOM 0x6c 49 + #define LPC24XX_ALDOW 0x70 50 + #define LPC24XX_ALDOY 0x74 51 + #define LPC24XX_ALMON 0x78 52 + #define LPC24XX_ALYEAR 0x7c 53 + 54 + /* Macros to read fields in consolidated time (CT) registers */ 55 + #define CT0_SECS(x) (((x) >> 0) & 0x3f) 56 + #define CT0_MINS(x) (((x) >> 8) & 0x3f) 57 + #define CT0_HOURS(x) (((x) >> 16) & 0x1f) 58 + #define CT0_DOW(x) (((x) >> 24) & 0x07) 59 + #define CT1_DOM(x) (((x) >> 0) & 0x1f) 60 + #define CT1_MONTH(x) (((x) >> 8) & 0x0f) 61 + #define CT1_YEAR(x) (((x) >> 16) & 0xfff) 62 + #define CT2_DOY(x) (((x) >> 0) & 0xfff) 63 + 64 + #define rtc_readl(dev, reg) readl((dev)->rtc_base + (reg)) 65 + #define rtc_writel(dev, reg, val) writel((val), (dev)->rtc_base + (reg)) 66 + 67 + struct lpc24xx_rtc { 68 + void __iomem *rtc_base; 69 + struct rtc_device *rtc; 70 + struct clk *clk_rtc; 71 + struct clk *clk_reg; 72 + }; 73 + 74 + static int lpc24xx_rtc_set_time(struct device *dev, struct rtc_time *tm) 75 + { 76 + struct lpc24xx_rtc *rtc = dev_get_drvdata(dev); 77 + 78 + /* Disable RTC during update */ 79 + rtc_writel(rtc, LPC24XX_CCR, LPC178X_CCALEN); 80 + 81 + rtc_writel(rtc, LPC24XX_SEC, tm->tm_sec); 82 + rtc_writel(rtc, LPC24XX_MIN, tm->tm_min); 83 + rtc_writel(rtc, LPC24XX_HOUR, tm->tm_hour); 84 + rtc_writel(rtc, LPC24XX_DOW, tm->tm_wday); 85 + rtc_writel(rtc, LPC24XX_DOM, tm->tm_mday); 86 + rtc_writel(rtc, LPC24XX_DOY, tm->tm_yday); 87 + rtc_writel(rtc, LPC24XX_MONTH, tm->tm_mon); 88 + rtc_writel(rtc, LPC24XX_YEAR, tm->tm_year); 89 + 90 + rtc_writel(rtc, LPC24XX_CCR, LPC24XX_CLKEN | LPC178X_CCALEN); 91 + 92 + return 0; 93 + } 94 + 95 + static int lpc24xx_rtc_read_time(struct device *dev, struct rtc_time *tm) 96 + { 97 + struct lpc24xx_rtc *rtc = dev_get_drvdata(dev); 98 + u32 ct0, ct1, ct2; 99 + 100 + ct0 = rtc_readl(rtc, LPC24XX_CTIME0); 101 + ct1 = rtc_readl(rtc, LPC24XX_CTIME1); 102 + ct2 = rtc_readl(rtc, LPC24XX_CTIME2); 103 + 104 + tm->tm_sec = CT0_SECS(ct0); 105 + tm->tm_min = CT0_MINS(ct0); 106 + tm->tm_hour = CT0_HOURS(ct0); 107 + tm->tm_wday = CT0_DOW(ct0); 108 + tm->tm_mon = CT1_MONTH(ct1); 109 + tm->tm_mday = CT1_DOM(ct1); 110 + tm->tm_year = CT1_YEAR(ct1); 111 + tm->tm_yday = CT2_DOY(ct2); 112 + 113 + return rtc_valid_tm(tm); 114 + } 115 + 116 + static int lpc24xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 117 + { 118 + struct lpc24xx_rtc *rtc = dev_get_drvdata(dev); 119 + struct rtc_time *tm = &wkalrm->time; 120 + 121 + tm->tm_sec = rtc_readl(rtc, LPC24XX_ALSEC); 122 + tm->tm_min = rtc_readl(rtc, LPC24XX_ALMIN); 123 + tm->tm_hour = rtc_readl(rtc, LPC24XX_ALHOUR); 124 + tm->tm_mday = rtc_readl(rtc, LPC24XX_ALDOM); 125 + tm->tm_wday = rtc_readl(rtc, LPC24XX_ALDOW); 126 + tm->tm_yday = rtc_readl(rtc, LPC24XX_ALDOY); 127 + tm->tm_mon = rtc_readl(rtc, LPC24XX_ALMON); 128 + tm->tm_year = rtc_readl(rtc, LPC24XX_ALYEAR); 129 + 130 + wkalrm->enabled = rtc_readl(rtc, LPC24XX_AMR) == 0; 131 + wkalrm->pending = !!(rtc_readl(rtc, LPC24XX_ILR) & LPC24XX_RTCCIF); 132 + 133 + return rtc_valid_tm(&wkalrm->time); 134 + } 135 + 136 + static int lpc24xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 137 + { 138 + struct lpc24xx_rtc *rtc = dev_get_drvdata(dev); 139 + struct rtc_time *tm = &wkalrm->time; 140 + 141 + /* Disable alarm irq during update */ 142 + rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE); 143 + 144 + rtc_writel(rtc, LPC24XX_ALSEC, tm->tm_sec); 145 + rtc_writel(rtc, LPC24XX_ALMIN, tm->tm_min); 146 + rtc_writel(rtc, LPC24XX_ALHOUR, tm->tm_hour); 147 + rtc_writel(rtc, LPC24XX_ALDOM, tm->tm_mday); 148 + rtc_writel(rtc, LPC24XX_ALDOW, tm->tm_wday); 149 + rtc_writel(rtc, LPC24XX_ALDOY, tm->tm_yday); 150 + rtc_writel(rtc, LPC24XX_ALMON, tm->tm_mon); 151 + rtc_writel(rtc, LPC24XX_ALYEAR, tm->tm_year); 152 + 153 + if (wkalrm->enabled) 154 + rtc_writel(rtc, LPC24XX_AMR, 0); 155 + 156 + return 0; 157 + } 158 + 159 + static int lpc24xx_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) 160 + { 161 + struct lpc24xx_rtc *rtc = dev_get_drvdata(dev); 162 + 163 + if (enable) 164 + rtc_writel(rtc, LPC24XX_AMR, 0); 165 + else 166 + rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE); 167 + 168 + return 0; 169 + } 170 + 171 + static irqreturn_t lpc24xx_rtc_interrupt(int irq, void *data) 172 + { 173 + unsigned long events = RTC_IRQF; 174 + struct lpc24xx_rtc *rtc = data; 175 + u32 rtc_iir; 176 + 177 + /* Check interrupt cause */ 178 + rtc_iir = rtc_readl(rtc, LPC24XX_ILR); 179 + if (rtc_iir & LPC24XX_RTCALF) { 180 + events |= RTC_AF; 181 + rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE); 182 + } 183 + 184 + /* Clear interrupt status and report event */ 185 + rtc_writel(rtc, LPC24XX_ILR, rtc_iir); 186 + rtc_update_irq(rtc->rtc, 1, events); 187 + 188 + return IRQ_HANDLED; 189 + } 190 + 191 + static const struct rtc_class_ops lpc24xx_rtc_ops = { 192 + .read_time = lpc24xx_rtc_read_time, 193 + .set_time = lpc24xx_rtc_set_time, 194 + .read_alarm = lpc24xx_rtc_read_alarm, 195 + .set_alarm = lpc24xx_rtc_set_alarm, 196 + .alarm_irq_enable = lpc24xx_rtc_alarm_irq_enable, 197 + }; 198 + 199 + static int lpc24xx_rtc_probe(struct platform_device *pdev) 200 + { 201 + struct lpc24xx_rtc *rtc; 202 + struct resource *res; 203 + int irq, ret; 204 + 205 + rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); 206 + if (!rtc) 207 + return -ENOMEM; 208 + 209 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 210 + rtc->rtc_base = devm_ioremap_resource(&pdev->dev, res); 211 + if (IS_ERR(rtc->rtc_base)) 212 + return PTR_ERR(rtc->rtc_base); 213 + 214 + irq = platform_get_irq(pdev, 0); 215 + if (irq < 0) { 216 + dev_warn(&pdev->dev, "can't get interrupt resource\n"); 217 + return irq; 218 + } 219 + 220 + rtc->clk_rtc = devm_clk_get(&pdev->dev, "rtc"); 221 + if (IS_ERR(rtc->clk_rtc)) { 222 + dev_err(&pdev->dev, "error getting rtc clock\n"); 223 + return PTR_ERR(rtc->clk_rtc); 224 + } 225 + 226 + rtc->clk_reg = devm_clk_get(&pdev->dev, "reg"); 227 + if (IS_ERR(rtc->clk_reg)) { 228 + dev_err(&pdev->dev, "error getting reg clock\n"); 229 + return PTR_ERR(rtc->clk_reg); 230 + } 231 + 232 + ret = clk_prepare_enable(rtc->clk_rtc); 233 + if (ret) { 234 + dev_err(&pdev->dev, "unable to enable rtc clock\n"); 235 + return ret; 236 + } 237 + 238 + ret = clk_prepare_enable(rtc->clk_reg); 239 + if (ret) { 240 + dev_err(&pdev->dev, "unable to enable reg clock\n"); 241 + goto disable_rtc_clk; 242 + } 243 + 244 + platform_set_drvdata(pdev, rtc); 245 + 246 + /* Clear any pending interrupts */ 247 + rtc_writel(rtc, LPC24XX_ILR, LPC24XX_RTCCIF | LPC24XX_RTCALF); 248 + 249 + /* Enable RTC count */ 250 + rtc_writel(rtc, LPC24XX_CCR, LPC24XX_CLKEN | LPC178X_CCALEN); 251 + 252 + ret = devm_request_irq(&pdev->dev, irq, lpc24xx_rtc_interrupt, 0, 253 + pdev->name, rtc); 254 + if (ret < 0) { 255 + dev_warn(&pdev->dev, "can't request interrupt\n"); 256 + goto disable_clks; 257 + } 258 + 259 + rtc->rtc = devm_rtc_device_register(&pdev->dev, "lpc24xx-rtc", 260 + &lpc24xx_rtc_ops, THIS_MODULE); 261 + if (IS_ERR(rtc->rtc)) { 262 + dev_err(&pdev->dev, "can't register rtc device\n"); 263 + ret = PTR_ERR(rtc->rtc); 264 + goto disable_clks; 265 + } 266 + 267 + return 0; 268 + 269 + disable_clks: 270 + clk_disable_unprepare(rtc->clk_reg); 271 + disable_rtc_clk: 272 + clk_disable_unprepare(rtc->clk_rtc); 273 + return ret; 274 + } 275 + 276 + static int lpc24xx_rtc_remove(struct platform_device *pdev) 277 + { 278 + struct lpc24xx_rtc *rtc = platform_get_drvdata(pdev); 279 + 280 + /* Ensure all interrupt sources are masked */ 281 + rtc_writel(rtc, LPC24XX_AMR, LPC24XX_ALARM_DISABLE); 282 + rtc_writel(rtc, LPC24XX_CIIR, 0); 283 + 284 + rtc_writel(rtc, LPC24XX_CCR, LPC178X_CCALEN); 285 + 286 + clk_disable_unprepare(rtc->clk_rtc); 287 + clk_disable_unprepare(rtc->clk_reg); 288 + 289 + return 0; 290 + } 291 + 292 + static const struct of_device_id lpc24xx_rtc_match[] = { 293 + { .compatible = "nxp,lpc1788-rtc" }, 294 + { } 295 + }; 296 + MODULE_DEVICE_TABLE(of, lpc24xx_rtc_match); 297 + 298 + static struct platform_driver lpc24xx_rtc_driver = { 299 + .probe = lpc24xx_rtc_probe, 300 + .remove = lpc24xx_rtc_remove, 301 + .driver = { 302 + .name = "lpc24xx-rtc", 303 + .of_match_table = lpc24xx_rtc_match, 304 + }, 305 + }; 306 + module_platform_driver(lpc24xx_rtc_driver); 307 + 308 + MODULE_AUTHOR("Kevin Wells <wellsk40@gmail.com>"); 309 + MODULE_DESCRIPTION("RTC driver for the LPC178x/18xx/408x/43xx SoCs"); 310 + MODULE_LICENSE("GPL");
+10 -8
drivers/rtc/rtc-m48t59.c
··· 345 345 ssize_t cnt = 0; 346 346 unsigned long flags; 347 347 348 - for (; size > 0 && pos < pdata->offset; cnt++, size--) { 349 - spin_lock_irqsave(&m48t59->lock, flags); 348 + spin_lock_irqsave(&m48t59->lock, flags); 349 + 350 + for (; cnt < size; cnt++) 350 351 *buf++ = M48T59_READ(cnt); 351 - spin_unlock_irqrestore(&m48t59->lock, flags); 352 - } 352 + 353 + spin_unlock_irqrestore(&m48t59->lock, flags); 353 354 354 355 return cnt; 355 356 } ··· 366 365 ssize_t cnt = 0; 367 366 unsigned long flags; 368 367 369 - for (; size > 0 && pos < pdata->offset; cnt++, size--) { 370 - spin_lock_irqsave(&m48t59->lock, flags); 368 + spin_lock_irqsave(&m48t59->lock, flags); 369 + 370 + for (; cnt < size; cnt++) 371 371 M48T59_WRITE(*buf++, cnt); 372 - spin_unlock_irqrestore(&m48t59->lock, flags); 373 - } 372 + 373 + spin_unlock_irqrestore(&m48t59->lock, flags); 374 374 375 375 return cnt; 376 376 }
+1
drivers/rtc/rtc-max8997.c
··· 521 521 { "max8997-rtc", 0 }, 522 522 {}, 523 523 }; 524 + MODULE_DEVICE_TABLE(platform, rtc_id); 524 525 525 526 static struct platform_driver max8997_rtc_driver = { 526 527 .driver = {
+1
drivers/rtc/rtc-moxart.c
··· 312 312 { .compatible = "moxa,moxart-rtc" }, 313 313 { }, 314 314 }; 315 + MODULE_DEVICE_TABLE(of, moxart_rtc_match); 315 316 316 317 static struct platform_driver moxart_rtc_driver = { 317 318 .probe = moxart_rtc_probe,
+1
drivers/rtc/rtc-mpc5121.c
··· 406 406 { .compatible = "fsl,mpc5200-rtc", }, 407 407 {}, 408 408 }; 409 + MODULE_DEVICE_TABLE(of, mpc5121_rtc_match); 409 410 #endif 410 411 411 412 static struct platform_driver mpc5121_rtc_driver = {
+27
drivers/rtc/rtc-mt6397.c
··· 373 373 return 0; 374 374 } 375 375 376 + #ifdef CONFIG_PM_SLEEP 377 + static int mt6397_rtc_suspend(struct device *dev) 378 + { 379 + struct mt6397_rtc *rtc = dev_get_drvdata(dev); 380 + 381 + if (device_may_wakeup(dev)) 382 + enable_irq_wake(rtc->irq); 383 + 384 + return 0; 385 + } 386 + 387 + static int mt6397_rtc_resume(struct device *dev) 388 + { 389 + struct mt6397_rtc *rtc = dev_get_drvdata(dev); 390 + 391 + if (device_may_wakeup(dev)) 392 + disable_irq_wake(rtc->irq); 393 + 394 + return 0; 395 + } 396 + #endif 397 + 398 + static SIMPLE_DEV_PM_OPS(mt6397_pm_ops, mt6397_rtc_suspend, 399 + mt6397_rtc_resume); 400 + 376 401 static const struct of_device_id mt6397_rtc_of_match[] = { 377 402 { .compatible = "mediatek,mt6397-rtc", }, 378 403 { } 379 404 }; 405 + MODULE_DEVICE_TABLE(of, mt6397_rtc_of_match); 380 406 381 407 static struct platform_driver mtk_rtc_driver = { 382 408 .driver = { 383 409 .name = "mt6397-rtc", 384 410 .of_match_table = mt6397_rtc_of_match, 411 + .pm = &mt6397_pm_ops, 385 412 }, 386 413 .probe = mtk_rtc_probe, 387 414 .remove = mtk_rtc_remove,
+1
drivers/rtc/rtc-mv.c
··· 324 324 { .compatible = "marvell,orion-rtc", }, 325 325 {} 326 326 }; 327 + MODULE_DEVICE_TABLE(of, rtc_mv_of_match_table); 327 328 #endif 328 329 329 330 static struct platform_driver mv_rtc_driver = {
+33
drivers/rtc/rtc-omap.c
··· 25 25 #include <linux/of_device.h> 26 26 #include <linux/pm_runtime.h> 27 27 #include <linux/io.h> 28 + #include <linux/clk.h> 28 29 29 30 /* 30 31 * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock ··· 108 107 109 108 /* OMAP_RTC_OSC_REG bit fields: */ 110 109 #define OMAP_RTC_OSC_32KCLK_EN BIT(6) 110 + #define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3) 111 111 112 112 /* OMAP_RTC_IRQWAKEEN bit fields: */ 113 113 #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1) ··· 134 132 struct omap_rtc { 135 133 struct rtc_device *rtc; 136 134 void __iomem *base; 135 + struct clk *clk; 137 136 int irq_alarm; 138 137 int irq_timer; 139 138 u8 interrupts_reg; 140 139 bool is_pmic_controller; 140 + bool has_ext_clk; 141 141 const struct omap_rtc_device_type *type; 142 142 }; 143 143 ··· 557 553 if (rtc->irq_alarm <= 0) 558 554 return -ENOENT; 559 555 556 + rtc->clk = devm_clk_get(&pdev->dev, "ext-clk"); 557 + if (!IS_ERR(rtc->clk)) 558 + rtc->has_ext_clk = true; 559 + else 560 + rtc->clk = devm_clk_get(&pdev->dev, "int-clk"); 561 + 562 + if (!IS_ERR(rtc->clk)) 563 + clk_prepare_enable(rtc->clk); 564 + 560 565 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 561 566 rtc->base = devm_ioremap_resource(&pdev->dev, res); 562 567 if (IS_ERR(rtc->base)) ··· 640 627 if (reg != new_ctrl) 641 628 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); 642 629 630 + /* 631 + * If we have the external clock then switch to it so we can keep 632 + * ticking across suspend. 633 + */ 634 + if (rtc->has_ext_clk) { 635 + reg = rtc_read(rtc, OMAP_RTC_OSC_REG); 636 + rtc_write(rtc, OMAP_RTC_OSC_REG, 637 + reg | OMAP_RTC_OSC_SEL_32KCLK_SRC); 638 + } 639 + 643 640 rtc->type->lock(rtc); 644 641 645 642 device_init_wakeup(&pdev->dev, true); ··· 695 672 static int __exit omap_rtc_remove(struct platform_device *pdev) 696 673 { 697 674 struct omap_rtc *rtc = platform_get_drvdata(pdev); 675 + u8 reg; 698 676 699 677 if (pm_power_off == omap_rtc_power_off && 700 678 omap_rtc_power_off_rtc == rtc) { ··· 705 681 706 682 device_init_wakeup(&pdev->dev, 0); 707 683 684 + if (!IS_ERR(rtc->clk)) 685 + clk_disable_unprepare(rtc->clk); 686 + 708 687 rtc->type->unlock(rtc); 709 688 /* leave rtc running, but disable irqs */ 710 689 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); 690 + 691 + if (rtc->has_ext_clk) { 692 + reg = rtc_read(rtc, OMAP_RTC_OSC_REG); 693 + reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC; 694 + rtc_write(rtc, OMAP_RTC_OSC_REG, reg); 695 + } 711 696 712 697 rtc->type->lock(rtc); 713 698
+5 -5
drivers/rtc/rtc-opal.c
··· 190 190 return rc; 191 191 } 192 192 193 - static const struct rtc_class_ops opal_rtc_ops = { 193 + static struct rtc_class_ops opal_rtc_ops = { 194 194 .read_time = opal_get_rtc_time, 195 195 .set_time = opal_set_rtc_time, 196 - .read_alarm = opal_get_tpo_time, 197 - .set_alarm = opal_set_tpo_time, 198 196 }; 199 197 200 198 static int opal_rtc_probe(struct platform_device *pdev) ··· 200 202 struct rtc_device *rtc; 201 203 202 204 if (pdev->dev.of_node && of_get_property(pdev->dev.of_node, "has-tpo", 203 - NULL)) 205 + NULL)) { 204 206 device_set_wakeup_capable(&pdev->dev, true); 207 + opal_rtc_ops.read_alarm = opal_get_tpo_time; 208 + opal_rtc_ops.set_alarm = opal_set_tpo_time; 209 + } 205 210 206 211 rtc = devm_rtc_device_register(&pdev->dev, DRVNAME, &opal_rtc_ops, 207 212 THIS_MODULE); ··· 237 236 .id_table = opal_rtc_driver_ids, 238 237 .driver = { 239 238 .name = DRVNAME, 240 - .owner = THIS_MODULE, 241 239 .of_match_table = opal_rtc_match, 242 240 }, 243 241 };
+1 -7
drivers/rtc/rtc-pcf2123.c
··· 165 165 tm->tm_sec, tm->tm_min, tm->tm_hour, 166 166 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 167 167 168 - /* the clock can give out invalid datetime, but we cannot return 169 - * -EINVAL otherwise hwclock will refuse to set the time on bootup. 170 - */ 171 - if (rtc_valid_tm(tm) < 0) 172 - dev_err(dev, "retrieved date/time is not valid.\n"); 173 - 174 - return 0; 168 + return rtc_valid_tm(tm); 175 169 } 176 170 177 171 static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
+24 -11
drivers/rtc/rtc-pcf2127.c
··· 33 33 #define PCF2127_REG_MO (0x08) 34 34 #define PCF2127_REG_YR (0x09) 35 35 36 + #define PCF2127_OSF BIT(7) /* Oscillator Fail flag */ 37 + 36 38 static struct i2c_driver pcf2127_driver; 37 39 38 40 struct pcf2127 { 39 41 struct rtc_device *rtc; 40 42 int voltage_low; /* indicates if a low_voltage was detected */ 43 + int oscillator_failed; /* OSF was detected and date is unreliable */ 41 44 }; 42 45 43 46 /* ··· 62 59 if (buf[PCF2127_REG_CTRL3] & 0x04) { 63 60 pcf2127->voltage_low = 1; 64 61 dev_info(&client->dev, 65 - "low voltage detected, date/time is not reliable.\n"); 62 + "low voltage detected, check/replace RTC battery.\n"); 63 + } 64 + 65 + if (buf[PCF2127_REG_SC] & PCF2127_OSF) { 66 + /* 67 + * no need clear the flag here, 68 + * it will be cleared once the new date is saved 69 + */ 70 + pcf2127->oscillator_failed = 1; 71 + dev_warn(&client->dev, 72 + "oscillator stop detected, date/time is not reliable\n"); 73 + return -EINVAL; 66 74 } 67 75 68 76 dev_dbg(&client->dev, ··· 102 88 tm->tm_sec, tm->tm_min, tm->tm_hour, 103 89 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 104 90 105 - /* the clock can give out invalid datetime, but we cannot return 106 - * -EINVAL otherwise hwclock will refuse to set the time on bootup. 107 - */ 108 - if (rtc_valid_tm(tm) < 0) 109 - dev_err(&client->dev, "retrieved date/time is not valid.\n"); 110 - 111 - return 0; 91 + return rtc_valid_tm(tm); 112 92 } 113 93 114 94 static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) 115 95 { 96 + struct pcf2127 *pcf2127 = i2c_get_clientdata(client); 116 97 unsigned char buf[8]; 117 98 int i = 0, err; 118 99 ··· 121 112 buf[i++] = PCF2127_REG_SC; 122 113 123 114 /* hours, minutes and seconds */ 124 - buf[i++] = bin2bcd(tm->tm_sec); 115 + buf[i++] = bin2bcd(tm->tm_sec); /* this will also clear OSF flag */ 125 116 buf[i++] = bin2bcd(tm->tm_min); 126 117 buf[i++] = bin2bcd(tm->tm_hour); 127 118 buf[i++] = bin2bcd(tm->tm_mday); ··· 141 132 return -EIO; 142 133 } 143 134 135 + /* clear OSF flag in client data */ 136 + pcf2127->oscillator_failed = 0; 137 + 144 138 return 0; 145 139 } 146 140 ··· 156 144 switch (cmd) { 157 145 case RTC_VL_READ: 158 146 if (pcf2127->voltage_low) 159 - dev_info(dev, "low voltage detected, date/time is not reliable.\n"); 147 + dev_info(dev, "low voltage detected, check/replace battery\n"); 148 + if (pcf2127->oscillator_failed) 149 + dev_info(dev, "oscillator stop detected, date/time is not reliable\n"); 160 150 161 151 if (copy_to_user((void __user *)arg, &pcf2127->voltage_low, 162 152 sizeof(int))) ··· 231 217 static struct i2c_driver pcf2127_driver = { 232 218 .driver = { 233 219 .name = "rtc-pcf2127", 234 - .owner = THIS_MODULE, 235 220 .of_match_table = of_match_ptr(pcf2127_of_match), 236 221 }, 237 222 .probe = pcf2127_probe,
-1
drivers/rtc/rtc-pcf85063.c
··· 189 189 static struct i2c_driver pcf85063_driver = { 190 190 .driver = { 191 191 .name = "rtc-pcf85063", 192 - .owner = THIS_MODULE, 193 192 .of_match_table = of_match_ptr(pcf85063_of_match), 194 193 }, 195 194 .probe = pcf85063_probe,
-1
drivers/rtc/rtc-pcf8523.c
··· 334 334 static struct i2c_driver pcf8523_driver = { 335 335 .driver = { 336 336 .name = DRIVER_NAME, 337 - .owner = THIS_MODULE, 338 337 .of_match_table = of_match_ptr(pcf8523_of_match), 339 338 }, 340 339 .probe = pcf8523_probe,
-1
drivers/rtc/rtc-pcf8563.c
··· 483 483 static struct i2c_driver pcf8563_driver = { 484 484 .driver = { 485 485 .name = "rtc-pcf8563", 486 - .owner = THIS_MODULE, 487 486 .of_match_table = of_match_ptr(pcf8563_of_match), 488 487 }, 489 488 .probe = pcf8563_probe,
-1
drivers/rtc/rtc-pcf8583.c
··· 309 309 static struct i2c_driver pcf8583_driver = { 310 310 .driver = { 311 311 .name = "pcf8583", 312 - .owner = THIS_MODULE, 313 312 }, 314 313 .probe = pcf8583_probe, 315 314 .id_table = pcf8583_id,
+1 -1
drivers/rtc/rtc-pl031.c
··· 476 476 477 477 module_amba_driver(pl031_driver); 478 478 479 - MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net"); 479 + MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); 480 480 MODULE_DESCRIPTION("ARM AMBA PL031 RTC Driver"); 481 481 MODULE_LICENSE("GPL");
+28 -27
drivers/rtc/rtc-pxa.c
··· 32 32 33 33 #include <mach/hardware.h> 34 34 35 + #include "rtc-sa1100.h" 36 + 35 37 #define RTC_DEF_DIVIDER (32768 - 1) 36 38 #define RTC_DEF_TRIM 0 37 39 #define MAXFREQ_PERIODIC 1000 ··· 88 86 __raw_writel((value), (pxa_rtc)->base + (reg)) 89 87 90 88 struct pxa_rtc { 89 + struct sa1100_rtc sa1100_rtc; 91 90 struct resource *ress; 92 91 void __iomem *base; 93 - int irq_1Hz; 94 - int irq_Alrm; 95 92 struct rtc_device *rtc; 96 93 spinlock_t lock; /* Protects this structure */ 97 94 }; ··· 185 184 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 186 185 int ret; 187 186 188 - ret = request_irq(pxa_rtc->irq_1Hz, pxa_rtc_irq, 0, 187 + ret = request_irq(pxa_rtc->sa1100_rtc.irq_1hz, pxa_rtc_irq, 0, 189 188 "rtc 1Hz", dev); 190 189 if (ret < 0) { 191 - dev_err(dev, "can't get irq %i, err %d\n", pxa_rtc->irq_1Hz, 192 - ret); 190 + dev_err(dev, "can't get irq %i, err %d\n", 191 + pxa_rtc->sa1100_rtc.irq_1hz, ret); 193 192 goto err_irq_1Hz; 194 193 } 195 - ret = request_irq(pxa_rtc->irq_Alrm, pxa_rtc_irq, 0, 194 + ret = request_irq(pxa_rtc->sa1100_rtc.irq_alarm, pxa_rtc_irq, 0, 196 195 "rtc Alrm", dev); 197 196 if (ret < 0) { 198 - dev_err(dev, "can't get irq %i, err %d\n", pxa_rtc->irq_Alrm, 199 - ret); 197 + dev_err(dev, "can't get irq %i, err %d\n", 198 + pxa_rtc->sa1100_rtc.irq_alarm, ret); 200 199 goto err_irq_Alrm; 201 200 } 202 201 203 202 return 0; 204 203 205 204 err_irq_Alrm: 206 - free_irq(pxa_rtc->irq_1Hz, dev); 205 + free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev); 207 206 err_irq_1Hz: 208 207 return ret; 209 208 } ··· 216 215 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE); 217 216 spin_unlock_irq(&pxa_rtc->lock); 218 217 219 - free_irq(pxa_rtc->irq_Alrm, dev); 220 - free_irq(pxa_rtc->irq_1Hz, dev); 218 + free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev); 219 + free_irq(pxa_rtc->sa1100_rtc.irq_alarm, dev); 221 220 } 222 221 223 222 static int pxa_alarm_irq_enable(struct device *dev, unsigned int enabled) ··· 321 320 { 322 321 struct device *dev = &pdev->dev; 323 322 struct pxa_rtc *pxa_rtc; 323 + struct sa1100_rtc *sa1100_rtc; 324 324 int ret; 325 - u32 rttr; 326 325 327 326 pxa_rtc = devm_kzalloc(dev, sizeof(*pxa_rtc), GFP_KERNEL); 328 327 if (!pxa_rtc) 329 328 return -ENOMEM; 329 + sa1100_rtc = &pxa_rtc->sa1100_rtc; 330 330 331 331 spin_lock_init(&pxa_rtc->lock); 332 332 platform_set_drvdata(pdev, pxa_rtc); ··· 338 336 return -ENXIO; 339 337 } 340 338 341 - pxa_rtc->irq_1Hz = platform_get_irq(pdev, 0); 342 - if (pxa_rtc->irq_1Hz < 0) { 339 + sa1100_rtc->irq_1hz = platform_get_irq(pdev, 0); 340 + if (sa1100_rtc->irq_1hz < 0) { 343 341 dev_err(dev, "No 1Hz IRQ resource defined\n"); 344 342 return -ENXIO; 345 343 } 346 - pxa_rtc->irq_Alrm = platform_get_irq(pdev, 1); 347 - if (pxa_rtc->irq_Alrm < 0) { 344 + sa1100_rtc->irq_alarm = platform_get_irq(pdev, 1); 345 + if (sa1100_rtc->irq_alarm < 0) { 348 346 dev_err(dev, "No alarm IRQ resource defined\n"); 349 347 return -ENXIO; 350 348 } ··· 356 354 return -ENOMEM; 357 355 } 358 356 359 - /* 360 - * If the clock divider is uninitialized then reset it to the 361 - * default value to get the 1Hz clock. 362 - */ 363 - if (rtc_readl(pxa_rtc, RTTR) == 0) { 364 - rttr = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); 365 - rtc_writel(pxa_rtc, RTTR, rttr); 366 - dev_warn(dev, "warning: initializing default clock" 367 - " divider/trim value\n"); 357 + sa1100_rtc->rcnr = pxa_rtc->base + 0x0; 358 + sa1100_rtc->rtsr = pxa_rtc->base + 0x8; 359 + sa1100_rtc->rtar = pxa_rtc->base + 0x4; 360 + sa1100_rtc->rttr = pxa_rtc->base + 0xc; 361 + ret = sa1100_rtc_init(pdev, sa1100_rtc); 362 + if (!ret) { 363 + dev_err(dev, "Unable to init SA1100 RTC sub-device\n"); 364 + return ret; 368 365 } 369 366 370 367 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE); ··· 403 402 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 404 403 405 404 if (device_may_wakeup(dev)) 406 - enable_irq_wake(pxa_rtc->irq_Alrm); 405 + enable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm); 407 406 return 0; 408 407 } 409 408 ··· 412 411 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 413 412 414 413 if (device_may_wakeup(dev)) 415 - disable_irq_wake(pxa_rtc->irq_Alrm); 414 + disable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm); 416 415 return 0; 417 416 } 418 417 #endif
+2 -2
drivers/rtc/rtc-rp5c01.c
··· 170 170 171 171 spin_lock_irq(&priv->lock); 172 172 173 - for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) { 173 + for (count = 0; count < size; count++) { 174 174 u8 data; 175 175 176 176 rp5c01_write(priv, ··· 200 200 201 201 spin_lock_irq(&priv->lock); 202 202 203 - for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) { 203 + for (count = 0; count < size; count++) { 204 204 u8 data = *buf++; 205 205 206 206 rp5c01_write(priv,
+109 -176
drivers/rtc/rtc-rx8025.c
··· 18 18 * modify it under the terms of the GNU General Public License 19 19 * version 2 as published by the Free Software Foundation. 20 20 */ 21 + #include <linux/bcd.h> 22 + #include <linux/bitops.h> 23 + #include <linux/i2c.h> 21 24 #include <linux/kernel.h> 22 25 #include <linux/module.h> 23 - #include <linux/slab.h> 24 - #include <linux/init.h> 25 - #include <linux/bcd.h> 26 - #include <linux/i2c.h> 27 - #include <linux/list.h> 28 26 #include <linux/rtc.h> 29 27 30 28 /* Register definitions */ ··· 46 48 #define RX8025_BIT_CTRL1_CT (7 << 0) 47 49 /* 1 Hz periodic level irq */ 48 50 #define RX8025_BIT_CTRL1_CT_1HZ 4 49 - #define RX8025_BIT_CTRL1_TEST (1 << 3) 50 - #define RX8025_BIT_CTRL1_1224 (1 << 5) 51 - #define RX8025_BIT_CTRL1_DALE (1 << 6) 52 - #define RX8025_BIT_CTRL1_WALE (1 << 7) 51 + #define RX8025_BIT_CTRL1_TEST BIT(3) 52 + #define RX8025_BIT_CTRL1_1224 BIT(5) 53 + #define RX8025_BIT_CTRL1_DALE BIT(6) 54 + #define RX8025_BIT_CTRL1_WALE BIT(7) 53 55 54 - #define RX8025_BIT_CTRL2_DAFG (1 << 0) 55 - #define RX8025_BIT_CTRL2_WAFG (1 << 1) 56 - #define RX8025_BIT_CTRL2_CTFG (1 << 2) 57 - #define RX8025_BIT_CTRL2_PON (1 << 4) 58 - #define RX8025_BIT_CTRL2_XST (1 << 5) 59 - #define RX8025_BIT_CTRL2_VDET (1 << 6) 56 + #define RX8025_BIT_CTRL2_DAFG BIT(0) 57 + #define RX8025_BIT_CTRL2_WAFG BIT(1) 58 + #define RX8025_BIT_CTRL2_CTFG BIT(2) 59 + #define RX8025_BIT_CTRL2_PON BIT(4) 60 + #define RX8025_BIT_CTRL2_XST BIT(5) 61 + #define RX8025_BIT_CTRL2_VDET BIT(6) 60 62 61 63 /* Clock precision adjustment */ 62 64 #define RX8025_ADJ_RESOLUTION 3050 /* in ppb */ ··· 72 74 struct rx8025_data { 73 75 struct i2c_client *client; 74 76 struct rtc_device *rtc; 75 - struct work_struct work; 76 77 u8 ctrl1; 77 - unsigned exiting:1; 78 78 }; 79 79 80 - static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value) 80 + static s32 rx8025_read_reg(const struct i2c_client *client, u8 number) 81 81 { 82 - int ret = i2c_smbus_read_byte_data(client, (number << 4) | 0x08); 83 - 84 - if (ret < 0) { 85 - dev_err(&client->dev, "Unable to read register #%d\n", number); 86 - return ret; 87 - } 88 - 89 - *value = ret; 90 - return 0; 82 + return i2c_smbus_read_byte_data(client, number << 4); 91 83 } 92 84 93 - static int rx8025_read_regs(struct i2c_client *client, 94 - int number, u8 length, u8 *values) 85 + static int rx8025_read_regs(const struct i2c_client *client, 86 + u8 number, u8 length, u8 *values) 95 87 { 96 - int ret = i2c_smbus_read_i2c_block_data(client, (number << 4) | 0x08, 97 - length, values); 98 - 99 - if (ret != length) { 100 - dev_err(&client->dev, "Unable to read registers #%d..#%d\n", 101 - number, number + length - 1); 88 + int ret = i2c_smbus_read_i2c_block_data(client, number << 4, length, 89 + values); 90 + if (ret != length) 102 91 return ret < 0 ? ret : -EIO; 92 + 93 + return 0; 94 + } 95 + 96 + static s32 rx8025_write_reg(const struct i2c_client *client, u8 number, 97 + u8 value) 98 + { 99 + return i2c_smbus_write_byte_data(client, number << 4, value); 100 + } 101 + 102 + static s32 rx8025_write_regs(const struct i2c_client *client, 103 + u8 number, u8 length, const u8 *values) 104 + { 105 + return i2c_smbus_write_i2c_block_data(client, number << 4, 106 + length, values); 107 + } 108 + 109 + static int rx8025_check_validity(struct device *dev) 110 + { 111 + struct rx8025_data *rx8025 = dev_get_drvdata(dev); 112 + int ctrl2; 113 + 114 + ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2); 115 + if (ctrl2 < 0) 116 + return ctrl2; 117 + 118 + if (ctrl2 & RX8025_BIT_CTRL2_VDET) 119 + dev_warn(dev, "power voltage drop detected\n"); 120 + 121 + if (ctrl2 & RX8025_BIT_CTRL2_PON) { 122 + dev_warn(dev, "power-on reset detected, date is invalid\n"); 123 + return -EINVAL; 124 + } 125 + 126 + if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) { 127 + dev_warn(dev, "crystal stopped, date is invalid\n"); 128 + return -EINVAL; 103 129 } 104 130 105 131 return 0; 106 132 } 107 133 108 - static int rx8025_write_reg(struct i2c_client *client, int number, u8 value) 134 + static int rx8025_reset_validity(struct i2c_client *client) 109 135 { 110 - int ret = i2c_smbus_write_byte_data(client, number << 4, value); 136 + int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); 111 137 112 - if (ret) 113 - dev_err(&client->dev, "Unable to write register #%d\n", 114 - number); 138 + if (ctrl2 < 0) 139 + return ctrl2; 115 140 116 - return ret; 141 + ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET); 142 + 143 + return rx8025_write_reg(client, RX8025_REG_CTRL2, 144 + ctrl2 | RX8025_BIT_CTRL2_XST); 117 145 } 118 146 119 - static int rx8025_write_regs(struct i2c_client *client, 120 - int number, u8 length, u8 *values) 121 - { 122 - int ret = i2c_smbus_write_i2c_block_data(client, (number << 4) | 0x08, 123 - length, values); 124 - 125 - if (ret) 126 - dev_err(&client->dev, "Unable to write registers #%d..#%d\n", 127 - number, number + length - 1); 128 - 129 - return ret; 130 - } 131 - 132 - static irqreturn_t rx8025_irq(int irq, void *dev_id) 147 + static irqreturn_t rx8025_handle_irq(int irq, void *dev_id) 133 148 { 134 149 struct i2c_client *client = dev_id; 135 150 struct rx8025_data *rx8025 = i2c_get_clientdata(client); 151 + int status; 136 152 137 - disable_irq_nosync(irq); 138 - schedule_work(&rx8025->work); 139 - return IRQ_HANDLED; 140 - } 141 - 142 - static void rx8025_work(struct work_struct *work) 143 - { 144 - struct rx8025_data *rx8025 = container_of(work, struct rx8025_data, 145 - work); 146 - struct i2c_client *client = rx8025->client; 147 - struct mutex *lock = &rx8025->rtc->ops_lock; 148 - u8 status; 149 - 150 - mutex_lock(lock); 151 - 152 - if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status)) 153 + status = rx8025_read_reg(client, RX8025_REG_CTRL2); 154 + if (status < 0) 153 155 goto out; 154 156 155 157 if (!(status & RX8025_BIT_CTRL2_XST)) ··· 159 161 if (status & RX8025_BIT_CTRL2_CTFG) { 160 162 /* periodic */ 161 163 status &= ~RX8025_BIT_CTRL2_CTFG; 162 - local_irq_disable(); 163 164 rtc_update_irq(rx8025->rtc, 1, RTC_PF | RTC_IRQF); 164 - local_irq_enable(); 165 165 } 166 166 167 167 if (status & RX8025_BIT_CTRL2_DAFG) { ··· 168 172 if (rx8025_write_reg(client, RX8025_REG_CTRL1, 169 173 rx8025->ctrl1 & ~RX8025_BIT_CTRL1_DALE)) 170 174 goto out; 171 - local_irq_disable(); 172 175 rtc_update_irq(rx8025->rtc, 1, RTC_AF | RTC_IRQF); 173 - local_irq_enable(); 174 176 } 175 177 176 - /* acknowledge IRQ */ 177 - rx8025_write_reg(client, RX8025_REG_CTRL2, 178 - status | RX8025_BIT_CTRL2_XST); 179 - 180 178 out: 181 - if (!rx8025->exiting) 182 - enable_irq(client->irq); 183 - 184 - mutex_unlock(lock); 179 + return IRQ_HANDLED; 185 180 } 186 181 187 182 static int rx8025_get_time(struct device *dev, struct rtc_time *dt) ··· 180 193 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 181 194 u8 date[7]; 182 195 int err; 196 + 197 + err = rx8025_check_validity(dev); 198 + if (err) 199 + return err; 183 200 184 201 err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date); 185 202 if (err) ··· 204 213 205 214 dt->tm_mday = bcd2bin(date[RX8025_REG_MDAY] & 0x3f); 206 215 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1; 207 - dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]); 208 - 209 - if (dt->tm_year < 70) 210 - dt->tm_year += 100; 216 + dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]) + 100; 211 217 212 218 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__, 213 219 dt->tm_sec, dt->tm_min, dt->tm_hour, ··· 217 229 { 218 230 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 219 231 u8 date[7]; 232 + int ret; 220 233 221 - /* 222 - * BUG: The HW assumes every year that is a multiple of 4 to be a leap 223 - * year. Next time this is wrong is 2100, which will not be a leap 224 - * year. 225 - */ 234 + if ((dt->tm_year < 100) || (dt->tm_year > 199)) 235 + return -EINVAL; 226 236 227 237 /* 228 238 * Here the read-only bits are written as "0". I'm not sure if that ··· 237 251 date[RX8025_REG_WDAY] = bin2bcd(dt->tm_wday); 238 252 date[RX8025_REG_MDAY] = bin2bcd(dt->tm_mday); 239 253 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1); 240 - date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year % 100); 254 + date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year - 100); 241 255 242 256 dev_dbg(dev, 243 257 "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", 244 258 __func__, 245 259 date[0], date[1], date[2], date[3], date[4], date[5], date[6]); 246 260 247 - return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date); 261 + ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date); 262 + if (ret < 0) 263 + return ret; 264 + 265 + return rx8025_reset_validity(rx8025->client); 248 266 } 249 267 250 - static int rx8025_init_client(struct i2c_client *client, int *need_reset) 268 + static int rx8025_init_client(struct i2c_client *client) 251 269 { 252 270 struct rx8025_data *rx8025 = i2c_get_clientdata(client); 253 271 u8 ctrl[2], ctrl2; ··· 265 275 /* Keep test bit zero ! */ 266 276 rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST; 267 277 268 - if (ctrl[1] & RX8025_BIT_CTRL2_PON) { 269 - dev_warn(&client->dev, "power-on reset was detected, " 270 - "you may have to readjust the clock\n"); 271 - *need_reset = 1; 272 - } 273 - 274 - if (ctrl[1] & RX8025_BIT_CTRL2_VDET) { 275 - dev_warn(&client->dev, "a power voltage drop was detected, " 276 - "you may have to readjust the clock\n"); 277 - *need_reset = 1; 278 - } 279 - 280 - if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) { 281 - dev_warn(&client->dev, "Oscillation stop was detected," 282 - "you may have to readjust the clock\n"); 283 - *need_reset = 1; 284 - } 285 - 286 278 if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) { 287 279 dev_warn(&client->dev, "Alarm was detected\n"); 288 280 need_clear = 1; 289 281 } 290 282 291 - if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG)) 283 + if (ctrl[1] & RX8025_BIT_CTRL2_CTFG) 292 284 need_clear = 1; 293 285 294 - if (*need_reset || need_clear) { 295 - ctrl2 = ctrl[0]; 296 - ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET | 297 - RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG | 286 + if (need_clear) { 287 + ctrl2 = ctrl[1]; 288 + ctrl2 &= ~(RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG | 298 289 RX8025_BIT_CTRL2_DAFG); 299 - ctrl2 |= RX8025_BIT_CTRL2_XST; 300 290 301 291 err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2); 302 292 } ··· 289 319 { 290 320 struct rx8025_data *rx8025 = dev_get_drvdata(dev); 291 321 struct i2c_client *client = rx8025->client; 292 - u8 ctrl2, ald[2]; 293 - int err; 322 + u8 ald[2]; 323 + int ctrl2, err; 294 324 295 325 if (client->irq <= 0) 296 326 return -EINVAL; ··· 299 329 if (err) 300 330 return err; 301 331 302 - err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2); 303 - if (err) 304 - return err; 332 + ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2); 333 + if (ctrl2 < 0) 334 + return ctrl2; 305 335 306 336 dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n", 307 337 __func__, ald[0], ald[1], ctrl2); ··· 422 452 static int rx8025_get_clock_adjust(struct device *dev, int *adj) 423 453 { 424 454 struct i2c_client *client = to_i2c_client(dev); 425 - u8 digoff; 426 - int err; 455 + int digoff; 427 456 428 - err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff); 429 - if (err) 430 - return err; 457 + digoff = rx8025_read_reg(client, RX8025_REG_DIGOFF); 458 + if (digoff < 0) 459 + return digoff; 431 460 432 461 *adj = digoff >= 64 ? digoff - 128 : digoff; 433 462 if (*adj > 0) ··· 508 539 { 509 540 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 510 541 struct rx8025_data *rx8025; 511 - int err, need_reset = 0; 542 + int err = 0; 512 543 513 544 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 514 545 | I2C_FUNC_SMBUS_I2C_BLOCK)) { 515 546 dev_err(&adapter->dev, 516 547 "doesn't support required functionality\n"); 517 - err = -EIO; 518 - goto errout; 548 + return -EIO; 519 549 } 520 550 521 551 rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL); 522 552 if (!rx8025) { 523 - err = -ENOMEM; 524 - goto errout; 553 + return -ENOMEM; 525 554 } 526 555 527 556 rx8025->client = client; 528 557 i2c_set_clientdata(client, rx8025); 529 - INIT_WORK(&rx8025->work, rx8025_work); 530 558 531 - err = rx8025_init_client(client, &need_reset); 559 + err = rx8025_init_client(client); 532 560 if (err) 533 - goto errout; 534 - 535 - if (need_reset) { 536 - struct rtc_time tm; 537 - dev_info(&client->dev, 538 - "bad conditions detected, resetting date\n"); 539 - rtc_time_to_tm(0, &tm); /* 1970/1/1 */ 540 - rx8025_set_time(&client->dev, &tm); 541 - } 561 + return err; 542 562 543 563 rx8025->rtc = devm_rtc_device_register(&client->dev, client->name, 544 564 &rx8025_rtc_ops, THIS_MODULE); 545 565 if (IS_ERR(rx8025->rtc)) { 546 - err = PTR_ERR(rx8025->rtc); 547 566 dev_err(&client->dev, "unable to register the class device\n"); 548 - goto errout; 567 + return PTR_ERR(rx8025->rtc); 549 568 } 550 569 551 570 if (client->irq > 0) { 552 571 dev_info(&client->dev, "IRQ %d supplied\n", client->irq); 553 - err = request_irq(client->irq, rx8025_irq, 554 - 0, "rx8025", client); 572 + err = devm_request_threaded_irq(&client->dev, client->irq, NULL, 573 + rx8025_handle_irq, 0, "rx8025", 574 + client); 555 575 if (err) { 556 - dev_err(&client->dev, "unable to request IRQ\n"); 557 - goto errout; 576 + dev_err(&client->dev, "unable to request IRQ, alarms disabled\n"); 577 + client->irq = 0; 558 578 } 559 579 } 560 580 561 - rx8025->rtc->irq_freq = 1; 562 581 rx8025->rtc->max_user_freq = 1; 563 582 564 583 err = rx8025_sysfs_register(&client->dev); 565 - if (err) 566 - goto errout_irq; 567 - 568 - return 0; 569 - 570 - errout_irq: 571 - if (client->irq > 0) 572 - free_irq(client->irq, client); 573 - 574 - errout: 575 - dev_err(&adapter->dev, "probing for rx8025 failed\n"); 576 584 return err; 577 585 } 578 586 579 587 static int rx8025_remove(struct i2c_client *client) 580 588 { 581 - struct rx8025_data *rx8025 = i2c_get_clientdata(client); 582 - struct mutex *lock = &rx8025->rtc->ops_lock; 583 - 584 - if (client->irq > 0) { 585 - mutex_lock(lock); 586 - rx8025->exiting = 1; 587 - mutex_unlock(lock); 588 - 589 - free_irq(client->irq, client); 590 - cancel_work_sync(&rx8025->work); 591 - } 592 - 593 589 rx8025_sysfs_unregister(&client->dev); 594 590 return 0; 595 591 } ··· 562 628 static struct i2c_driver rx8025_driver = { 563 629 .driver = { 564 630 .name = "rtc-rx8025", 565 - .owner = THIS_MODULE, 566 631 }, 567 632 .probe = rx8025_probe, 568 633 .remove = rx8025_remove,
-1
drivers/rtc/rtc-rx8581.c
··· 315 315 static struct i2c_driver rx8581_driver = { 316 316 .driver = { 317 317 .name = "rtc-rx8581", 318 - .owner = THIS_MODULE, 319 318 }, 320 319 .probe = rx8581_probe, 321 320 .id_table = rx8581_id,
+21 -7
drivers/rtc/rtc-s3c.c
··· 39 39 void __iomem *base; 40 40 struct clk *rtc_clk; 41 41 struct clk *rtc_src_clk; 42 + bool clk_disabled; 42 43 43 44 struct s3c_rtc_data *data; 44 45 ··· 72 71 unsigned long irq_flags; 73 72 74 73 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 75 - clk_enable(info->rtc_clk); 76 - if (info->data->needs_src_clk) 77 - clk_enable(info->rtc_src_clk); 74 + if (info->clk_disabled) { 75 + clk_enable(info->rtc_clk); 76 + if (info->data->needs_src_clk) 77 + clk_enable(info->rtc_src_clk); 78 + info->clk_disabled = false; 79 + } 78 80 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 79 81 } 80 82 ··· 86 82 unsigned long irq_flags; 87 83 88 84 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags); 89 - if (info->data->needs_src_clk) 90 - clk_disable(info->rtc_src_clk); 91 - clk_disable(info->rtc_clk); 85 + if (!info->clk_disabled) { 86 + if (info->data->needs_src_clk) 87 + clk_disable(info->rtc_src_clk); 88 + clk_disable(info->rtc_clk); 89 + info->clk_disabled = true; 90 + } 92 91 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags); 93 92 } 94 93 ··· 134 127 writeb(tmp, info->base + S3C2410_RTCALM); 135 128 136 129 s3c_rtc_disable_clk(info); 130 + 131 + if (enabled) 132 + s3c_rtc_enable_clk(info); 133 + else 134 + s3c_rtc_disable_clk(info); 137 135 138 136 return 0; 139 137 } ··· 422 410 423 411 s3c_rtc_setaie(info->dev, 0); 424 412 413 + if (info->data->needs_src_clk) 414 + clk_unprepare(info->rtc_src_clk); 425 415 clk_unprepare(info->rtc_clk); 426 - info->rtc_clk = NULL; 427 416 428 417 return 0; 429 418 } ··· 495 482 if (IS_ERR(info->rtc_src_clk)) { 496 483 dev_err(&pdev->dev, 497 484 "failed to find rtc source clock\n"); 485 + clk_disable_unprepare(info->rtc_clk); 498 486 return PTR_ERR(info->rtc_src_clk); 499 487 } 500 488 clk_prepare_enable(info->rtc_src_clk);
+11
drivers/rtc/rtc-s5m.c
··· 635 635 case S2MPS13X: 636 636 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT); 637 637 ret = regmap_write(info->regmap, info->regs->ctrl, data[0]); 638 + if (ret < 0) 639 + break; 640 + 641 + /* 642 + * Should set WUDR & (RUDR or AUDR) bits to high after writing 643 + * RTC_CTRL register like writing Alarm registers. We can't find 644 + * the description from datasheet but vendor code does that 645 + * really. 646 + */ 647 + ret = s5m8767_rtc_set_alarm_reg(info); 638 648 break; 639 649 640 650 default: ··· 807 797 { "s2mps14-rtc", S2MPS14X }, 808 798 { }, 809 799 }; 800 + MODULE_DEVICE_TABLE(platform, s5m_rtc_id); 810 801 811 802 static struct platform_driver s5m_rtc_driver = { 812 803 .driver = {
+84 -55
drivers/rtc/rtc-sa1100.c
··· 35 35 #include <linux/bitops.h> 36 36 #include <linux/io.h> 37 37 38 - #include <mach/hardware.h> 39 - #include <mach/irqs.h> 38 + #define RTSR_HZE BIT(3) /* HZ interrupt enable */ 39 + #define RTSR_ALE BIT(2) /* RTC alarm interrupt enable */ 40 + #define RTSR_HZ BIT(1) /* HZ rising-edge detected */ 41 + #define RTSR_AL BIT(0) /* RTC alarm detected */ 40 42 41 - #if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP) 42 - #include <mach/regs-rtc.h> 43 - #endif 43 + #include "rtc-sa1100.h" 44 44 45 45 #define RTC_DEF_DIVIDER (32768 - 1) 46 46 #define RTC_DEF_TRIM 0 47 47 #define RTC_FREQ 1024 48 48 49 - struct sa1100_rtc { 50 - spinlock_t lock; 51 - int irq_1hz; 52 - int irq_alarm; 53 - struct rtc_device *rtc; 54 - struct clk *clk; 55 - }; 56 49 57 50 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) 58 51 { ··· 56 63 57 64 spin_lock(&info->lock); 58 65 59 - rtsr = RTSR; 66 + rtsr = readl_relaxed(info->rtsr); 60 67 /* clear interrupt sources */ 61 - RTSR = 0; 68 + writel_relaxed(0, info->rtsr); 62 69 /* Fix for a nasty initialization problem the in SA11xx RTSR register. 63 70 * See also the comments in sa1100_rtc_probe(). */ 64 71 if (rtsr & (RTSR_ALE | RTSR_HZE)) { 65 72 /* This is the original code, before there was the if test 66 73 * above. This code does not clear interrupts that were not 67 74 * enabled. */ 68 - RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2); 75 + writel_relaxed((RTSR_AL | RTSR_HZ) & (rtsr >> 2), info->rtsr); 69 76 } else { 70 77 /* For some reason, it is possible to enter this routine 71 78 * without interruptions enabled, it has been tested with ··· 74 81 * This situation leads to an infinite "loop" of interrupt 75 82 * routine calling and as a result the processor seems to 76 83 * lock on its first call to open(). */ 77 - RTSR = RTSR_AL | RTSR_HZ; 84 + writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr); 78 85 } 79 86 80 87 /* clear alarm interrupt if it has occurred */ 81 88 if (rtsr & RTSR_AL) 82 89 rtsr &= ~RTSR_ALE; 83 - RTSR = rtsr & (RTSR_ALE | RTSR_HZE); 90 + writel_relaxed(rtsr & (RTSR_ALE | RTSR_HZE), info->rtsr); 84 91 85 92 /* update irq data & counter */ 86 93 if (rtsr & RTSR_AL) ··· 128 135 struct sa1100_rtc *info = dev_get_drvdata(dev); 129 136 130 137 spin_lock_irq(&info->lock); 131 - RTSR = 0; 138 + writel_relaxed(0, info->rtsr); 132 139 spin_unlock_irq(&info->lock); 133 140 134 141 free_irq(info->irq_alarm, dev); ··· 137 144 138 145 static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 139 146 { 147 + u32 rtsr; 140 148 struct sa1100_rtc *info = dev_get_drvdata(dev); 141 149 142 150 spin_lock_irq(&info->lock); 151 + rtsr = readl_relaxed(info->rtsr); 143 152 if (enabled) 144 - RTSR |= RTSR_ALE; 153 + rtsr |= RTSR_ALE; 145 154 else 146 - RTSR &= ~RTSR_ALE; 155 + rtsr &= ~RTSR_ALE; 156 + writel_relaxed(rtsr, info->rtsr); 147 157 spin_unlock_irq(&info->lock); 148 158 return 0; 149 159 } 150 160 151 161 static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm) 152 162 { 153 - rtc_time_to_tm(RCNR, tm); 163 + struct sa1100_rtc *info = dev_get_drvdata(dev); 164 + 165 + rtc_time_to_tm(readl_relaxed(info->rcnr), tm); 154 166 return 0; 155 167 } 156 168 157 169 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm) 158 170 { 171 + struct sa1100_rtc *info = dev_get_drvdata(dev); 159 172 unsigned long time; 160 173 int ret; 161 174 162 175 ret = rtc_tm_to_time(tm, &time); 163 176 if (ret == 0) 164 - RCNR = time; 177 + writel_relaxed(time, info->rcnr); 165 178 return ret; 166 179 } 167 180 168 181 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 169 182 { 170 183 u32 rtsr; 184 + struct sa1100_rtc *info = dev_get_drvdata(dev); 171 185 172 - rtsr = RTSR; 186 + rtsr = readl_relaxed(info->rtsr); 173 187 alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0; 174 188 alrm->pending = (rtsr & RTSR_AL) ? 1 : 0; 175 189 return 0; ··· 192 192 ret = rtc_tm_to_time(&alrm->time, &time); 193 193 if (ret != 0) 194 194 goto out; 195 - RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL); 196 - RTAR = time; 195 + writel_relaxed(readl_relaxed(info->rtsr) & 196 + (RTSR_HZE | RTSR_ALE | RTSR_AL), info->rtsr); 197 + writel_relaxed(time, info->rtar); 197 198 if (alrm->enabled) 198 - RTSR |= RTSR_ALE; 199 + writel_relaxed(readl_relaxed(info->rtsr) | RTSR_ALE, info->rtsr); 199 200 else 200 - RTSR &= ~RTSR_ALE; 201 + writel_relaxed(readl_relaxed(info->rtsr) & ~RTSR_ALE, info->rtsr); 201 202 out: 202 203 spin_unlock_irq(&info->lock); 203 204 ··· 207 206 208 207 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) 209 208 { 210 - seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32) RTTR); 211 - seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)RTSR); 209 + struct sa1100_rtc *info = dev_get_drvdata(dev); 210 + 211 + seq_printf(seq, "trim/divider\t\t: 0x%08x\n", readl_relaxed(info->rttr)); 212 + seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", readl_relaxed(info->rtsr)); 212 213 213 214 return 0; 214 215 } ··· 226 223 .alarm_irq_enable = sa1100_rtc_alarm_irq_enable, 227 224 }; 228 225 229 - static int sa1100_rtc_probe(struct platform_device *pdev) 226 + int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info) 230 227 { 231 228 struct rtc_device *rtc; 232 - struct sa1100_rtc *info; 233 - int irq_1hz, irq_alarm, ret = 0; 229 + int ret; 234 230 235 - irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); 236 - irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); 237 - if (irq_1hz < 0 || irq_alarm < 0) 238 - return -ENODEV; 231 + spin_lock_init(&info->lock); 239 232 240 - info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); 241 - if (!info) 242 - return -ENOMEM; 243 233 info->clk = devm_clk_get(&pdev->dev, NULL); 244 234 if (IS_ERR(info->clk)) { 245 235 dev_err(&pdev->dev, "failed to find rtc clock source\n"); 246 236 return PTR_ERR(info->clk); 247 237 } 248 - info->irq_1hz = irq_1hz; 249 - info->irq_alarm = irq_alarm; 250 - spin_lock_init(&info->lock); 251 - platform_set_drvdata(pdev, info); 252 238 253 239 ret = clk_prepare_enable(info->clk); 254 240 if (ret) ··· 249 257 * If the clock divider is uninitialized then reset it to the 250 258 * default value to get the 1Hz clock. 251 259 */ 252 - if (RTTR == 0) { 253 - RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); 260 + if (readl_relaxed(info->rttr) == 0) { 261 + writel_relaxed(RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16), info->rttr); 254 262 dev_warn(&pdev->dev, "warning: " 255 263 "initializing default clock divider/trim value\n"); 256 264 /* The current RTC value probably doesn't make sense either */ 257 - RCNR = 0; 265 + writel_relaxed(0, info->rcnr); 258 266 } 259 - 260 - device_init_wakeup(&pdev->dev, 1); 261 267 262 268 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, 263 269 THIS_MODULE); 264 - 265 270 if (IS_ERR(rtc)) { 266 - ret = PTR_ERR(rtc); 267 - goto err_dev; 271 + clk_disable_unprepare(info->clk); 272 + return PTR_ERR(rtc); 268 273 } 269 274 info->rtc = rtc; 270 275 ··· 287 298 * 288 299 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to 289 300 * the corresponding bits in RTSR. */ 290 - RTSR = RTSR_AL | RTSR_HZ; 301 + writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr); 291 302 292 303 return 0; 293 - err_dev: 294 - clk_disable_unprepare(info->clk); 295 - return ret; 304 + } 305 + EXPORT_SYMBOL_GPL(sa1100_rtc_init); 306 + 307 + static int sa1100_rtc_probe(struct platform_device *pdev) 308 + { 309 + struct sa1100_rtc *info; 310 + struct resource *iores; 311 + void __iomem *base; 312 + int irq_1hz, irq_alarm; 313 + 314 + irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); 315 + irq_alarm = platform_get_irq_byname(pdev, "rtc alarm"); 316 + if (irq_1hz < 0 || irq_alarm < 0) 317 + return -ENODEV; 318 + 319 + info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL); 320 + if (!info) 321 + return -ENOMEM; 322 + info->irq_1hz = irq_1hz; 323 + info->irq_alarm = irq_alarm; 324 + 325 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 326 + base = devm_ioremap_resource(&pdev->dev, iores); 327 + if (IS_ERR(base)) 328 + return PTR_ERR(base); 329 + 330 + if (IS_ENABLED(CONFIG_ARCH_SA1100) || 331 + of_device_is_compatible(pdev->dev.of_node, "mrvl,sa1100-rtc")) { 332 + info->rcnr = base + 0x04; 333 + info->rtsr = base + 0x10; 334 + info->rtar = base + 0x00; 335 + info->rttr = base + 0x08; 336 + } else { 337 + info->rcnr = base + 0x0; 338 + info->rtsr = base + 0x8; 339 + info->rtar = base + 0x4; 340 + info->rttr = base + 0xc; 341 + } 342 + 343 + platform_set_drvdata(pdev, info); 344 + device_init_wakeup(&pdev->dev, 1); 345 + 346 + return sa1100_rtc_init(pdev, info); 296 347 } 297 348 298 349 static int sa1100_rtc_remove(struct platform_device *pdev)
+23
drivers/rtc/rtc-sa1100.h
··· 1 + #ifndef __RTC_SA1100_H__ 2 + #define __RTC_SA1100_H__ 3 + 4 + #include <linux/kernel.h> 5 + 6 + struct clk; 7 + struct platform_device; 8 + 9 + struct sa1100_rtc { 10 + spinlock_t lock; 11 + void __iomem *rcnr; 12 + void __iomem *rtar; 13 + void __iomem *rtsr; 14 + void __iomem *rttr; 15 + int irq_1hz; 16 + int irq_alarm; 17 + struct rtc_device *rtc; 18 + struct clk *clk; 19 + }; 20 + 21 + int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info); 22 + 23 + #endif
+64 -43
drivers/rtc/rtc-sirfsoc.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/io.h> 15 15 #include <linux/of.h> 16 + #include <linux/regmap.h> 16 17 #include <linux/rtc/sirfsoc_rtciobrg.h> 17 18 18 19 ··· 49 48 /* Overflow for every 8 years extra time */ 50 49 u32 overflow_rtc; 51 50 spinlock_t lock; 51 + struct regmap *regmap; 52 52 #ifdef CONFIG_PM 53 53 u32 saved_counter; 54 54 u32 saved_overflow_rtc; 55 55 #endif 56 56 }; 57 + 58 + static u32 sirfsoc_rtc_readl(struct sirfsoc_rtc_drv *rtcdrv, u32 offset) 59 + { 60 + u32 val; 61 + 62 + regmap_read(rtcdrv->regmap, rtcdrv->rtc_base + offset, &val); 63 + return val; 64 + } 65 + 66 + static void sirfsoc_rtc_writel(struct sirfsoc_rtc_drv *rtcdrv, 67 + u32 offset, u32 val) 68 + { 69 + regmap_write(rtcdrv->regmap, rtcdrv->rtc_base + offset, val); 70 + } 57 71 58 72 static int sirfsoc_rtc_read_alarm(struct device *dev, 59 73 struct rtc_wkalrm *alrm) ··· 80 64 81 65 spin_lock_irq(&rtcdrv->lock); 82 66 83 - rtc_count = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN); 67 + rtc_count = sirfsoc_rtc_readl(rtcdrv, RTC_CN); 84 68 85 - rtc_alarm = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_ALARM0); 69 + rtc_alarm = sirfsoc_rtc_readl(rtcdrv, RTC_ALARM0); 86 70 memset(alrm, 0, sizeof(struct rtc_wkalrm)); 87 71 88 72 /* ··· 98 82 rtc_time_to_tm(rtcdrv->overflow_rtc 99 83 << (BITS_PER_LONG - RTC_SHIFT) 100 84 | rtc_alarm >> RTC_SHIFT, &(alrm->time)); 101 - if (sirfsoc_rtc_iobrg_readl( 102 - rtcdrv->rtc_base + RTC_STATUS) & SIRFSOC_RTC_AL0E) 85 + if (sirfsoc_rtc_readl(rtcdrv, RTC_STATUS) & SIRFSOC_RTC_AL0E) 103 86 alrm->enabled = 1; 104 87 105 88 spin_unlock_irq(&rtcdrv->lock); ··· 118 103 119 104 spin_lock_irq(&rtcdrv->lock); 120 105 121 - rtc_status_reg = sirfsoc_rtc_iobrg_readl( 122 - rtcdrv->rtc_base + RTC_STATUS); 106 + rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS); 123 107 if (rtc_status_reg & SIRFSOC_RTC_AL0E) { 124 108 /* 125 109 * An ongoing alarm in progress - ingore it and not ··· 127 113 dev_info(dev, "An old alarm was set, will be replaced by a new one\n"); 128 114 } 129 115 130 - sirfsoc_rtc_iobrg_writel( 131 - rtc_alarm << RTC_SHIFT, rtcdrv->rtc_base + RTC_ALARM0); 116 + sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, rtc_alarm << RTC_SHIFT); 132 117 rtc_status_reg &= ~0x07; /* mask out the lower status bits */ 133 118 /* 134 119 * This bit RTC_AL sets it as a wake-up source for Sleep Mode ··· 136 123 rtc_status_reg |= SIRFSOC_RTC_AL0; 137 124 /* enable the RTC alarm interrupt */ 138 125 rtc_status_reg |= SIRFSOC_RTC_AL0E; 139 - sirfsoc_rtc_iobrg_writel( 140 - rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS); 126 + sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg); 141 127 142 128 spin_unlock_irq(&rtcdrv->lock); 143 129 } else { ··· 147 135 */ 148 136 spin_lock_irq(&rtcdrv->lock); 149 137 150 - rtc_status_reg = sirfsoc_rtc_iobrg_readl( 151 - rtcdrv->rtc_base + RTC_STATUS); 138 + rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS); 152 139 if (rtc_status_reg & SIRFSOC_RTC_AL0E) { 153 140 /* clear the RTC status register's alarm bit */ 154 141 rtc_status_reg &= ~0x07; ··· 156 145 /* Clear the Alarm enable bit */ 157 146 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E); 158 147 159 - sirfsoc_rtc_iobrg_writel(rtc_status_reg, 160 - rtcdrv->rtc_base + RTC_STATUS); 148 + sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, 149 + rtc_status_reg); 161 150 } 162 151 163 152 spin_unlock_irq(&rtcdrv->lock); ··· 178 167 * fail, read several times to make sure get stable value. 179 168 */ 180 169 do { 181 - tmp_rtc = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN); 170 + tmp_rtc = sirfsoc_rtc_readl(rtcdrv, RTC_CN); 182 171 cpu_relax(); 183 - } while (tmp_rtc != sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN)); 172 + } while (tmp_rtc != sirfsoc_rtc_readl(rtcdrv, RTC_CN)); 184 173 185 174 rtc_time_to_tm(rtcdrv->overflow_rtc << (BITS_PER_LONG - RTC_SHIFT) | 186 175 tmp_rtc >> RTC_SHIFT, tm); ··· 198 187 199 188 rtcdrv->overflow_rtc = rtc_time >> (BITS_PER_LONG - RTC_SHIFT); 200 189 201 - sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc, 202 - rtcdrv->rtc_base + RTC_SW_VALUE); 203 - sirfsoc_rtc_iobrg_writel( 204 - rtc_time << RTC_SHIFT, rtcdrv->rtc_base + RTC_CN); 190 + sirfsoc_rtc_writel(rtcdrv, RTC_SW_VALUE, rtcdrv->overflow_rtc); 191 + sirfsoc_rtc_writel(rtcdrv, RTC_CN, rtc_time << RTC_SHIFT); 205 192 206 193 return 0; 207 194 } ··· 231 222 232 223 spin_lock_irq(&rtcdrv->lock); 233 224 234 - rtc_status_reg = sirfsoc_rtc_iobrg_readl( 235 - rtcdrv->rtc_base + RTC_STATUS); 225 + rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS); 236 226 if (enabled) 237 227 rtc_status_reg |= SIRFSOC_RTC_AL0E; 238 228 else 239 229 rtc_status_reg &= ~SIRFSOC_RTC_AL0E; 240 230 241 - sirfsoc_rtc_iobrg_writel(rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS); 231 + sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg); 242 232 243 233 spin_unlock_irq(&rtcdrv->lock); 244 234 ··· 262 254 263 255 spin_lock(&rtcdrv->lock); 264 256 265 - rtc_status_reg = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_STATUS); 257 + rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS); 266 258 /* this bit will be set ONLY if an alarm was active 267 259 * and it expired NOW 268 260 * So this is being used as an ASSERT ··· 278 270 /* Clear the Alarm enable bit */ 279 271 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E); 280 272 } 281 - sirfsoc_rtc_iobrg_writel(rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS); 273 + 274 + sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg); 282 275 283 276 spin_unlock(&rtcdrv->lock); 284 277 ··· 296 287 { .compatible = "sirf,prima2-sysrtc"}, 297 288 {}, 298 289 }; 290 + 291 + const struct regmap_config sysrtc_regmap_config = { 292 + .reg_bits = 32, 293 + .val_bits = 32, 294 + .fast_io = true, 295 + }; 296 + 299 297 MODULE_DEVICE_TABLE(of, sirfsoc_rtc_of_match); 300 298 301 299 static int sirfsoc_rtc_probe(struct platform_device *pdev) ··· 330 314 /* Register rtc alarm as a wakeup source */ 331 315 device_init_wakeup(&pdev->dev, 1); 332 316 317 + rtcdrv->regmap = devm_regmap_init_iobg(&pdev->dev, 318 + &sysrtc_regmap_config); 319 + if (IS_ERR(rtcdrv->regmap)) { 320 + err = PTR_ERR(rtcdrv->regmap); 321 + dev_err(&pdev->dev, "Failed to allocate register map: %d\n", 322 + err); 323 + return err; 324 + } 325 + 333 326 /* 334 327 * Set SYS_RTC counter in RTC_HZ HZ Units 335 328 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1 336 329 * If 16HZ, therefore RTC_DIV = 1023; 337 330 */ 338 331 rtc_div = ((32768 / RTC_HZ) / 2) - 1; 339 - sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV); 332 + sirfsoc_rtc_writel(rtcdrv, RTC_DIV, rtc_div); 340 333 341 334 /* 0x3 -> RTC_CLK */ 342 - sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK, 343 - rtcdrv->rtc_base + RTC_CLOCK_SWITCH); 335 + sirfsoc_rtc_writel(rtcdrv, RTC_CLOCK_SWITCH, SIRFSOC_RTC_CLK); 344 336 345 337 /* reset SYS RTC ALARM0 */ 346 - sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0); 338 + sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, 0x0); 347 339 348 340 /* reset SYS RTC ALARM1 */ 349 - sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1); 341 + sirfsoc_rtc_writel(rtcdrv, RTC_ALARM1, 0x0); 350 342 351 343 /* Restore RTC Overflow From Register After Command Reboot */ 352 344 rtcdrv->overflow_rtc = 353 - sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE); 345 + sirfsoc_rtc_readl(rtcdrv, RTC_SW_VALUE); 354 346 355 347 rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 356 348 &sirfsoc_rtc_ops, THIS_MODULE); ··· 396 372 { 397 373 struct sirfsoc_rtc_drv *rtcdrv = dev_get_drvdata(dev); 398 374 rtcdrv->overflow_rtc = 399 - sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE); 375 + sirfsoc_rtc_readl(rtcdrv, RTC_SW_VALUE); 400 376 401 377 rtcdrv->saved_counter = 402 - sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN); 378 + sirfsoc_rtc_readl(rtcdrv, RTC_CN); 403 379 rtcdrv->saved_overflow_rtc = rtcdrv->overflow_rtc; 404 380 if (device_may_wakeup(dev) && !enable_irq_wake(rtcdrv->irq)) 405 381 rtcdrv->irq_wake = 1; ··· 416 392 * if resume from snapshot and the rtc power is lost, 417 393 * restroe the rtc settings 418 394 */ 419 - if (SIRFSOC_RTC_CLK != sirfsoc_rtc_iobrg_readl( 420 - rtcdrv->rtc_base + RTC_CLOCK_SWITCH)) { 395 + if (SIRFSOC_RTC_CLK != sirfsoc_rtc_readl(rtcdrv, RTC_CLOCK_SWITCH)) { 421 396 u32 rtc_div; 422 397 /* 0x3 -> RTC_CLK */ 423 - sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK, 424 - rtcdrv->rtc_base + RTC_CLOCK_SWITCH); 398 + sirfsoc_rtc_writel(rtcdrv, RTC_CLOCK_SWITCH, SIRFSOC_RTC_CLK); 425 399 /* 426 400 * Set SYS_RTC counter in RTC_HZ HZ Units 427 401 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1 ··· 427 405 */ 428 406 rtc_div = ((32768 / RTC_HZ) / 2) - 1; 429 407 430 - sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV); 408 + sirfsoc_rtc_writel(rtcdrv, RTC_DIV, rtc_div); 431 409 432 410 /* reset SYS RTC ALARM0 */ 433 - sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0); 411 + sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, 0x0); 434 412 435 413 /* reset SYS RTC ALARM1 */ 436 - sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1); 414 + sirfsoc_rtc_writel(rtcdrv, RTC_ALARM1, 0x0); 437 415 } 438 416 rtcdrv->overflow_rtc = rtcdrv->saved_overflow_rtc; 439 417 ··· 441 419 * if current counter is small than previous, 442 420 * it means overflow in sleep 443 421 */ 444 - tmp = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN); 422 + tmp = sirfsoc_rtc_readl(rtcdrv, RTC_CN); 445 423 if (tmp <= rtcdrv->saved_counter) 446 424 rtcdrv->overflow_rtc++; 447 425 /* 448 426 *PWRC Value Be Changed When Suspend, Restore Overflow 449 427 * In Memory To Register 450 428 */ 451 - sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc, 452 - rtcdrv->rtc_base + RTC_SW_VALUE); 429 + sirfsoc_rtc_writel(rtcdrv, RTC_SW_VALUE, rtcdrv->overflow_rtc); 453 430 454 431 if (device_may_wakeup(dev) && rtcdrv->irq_wake) { 455 432 disable_irq_wake(rtcdrv->irq);
+2 -2
drivers/rtc/rtc-stk17ta8.c
··· 254 254 void __iomem *ioaddr = pdata->ioaddr; 255 255 ssize_t count; 256 256 257 - for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) 257 + for (count = 0; count < size; count++) 258 258 *buf++ = readb(ioaddr + pos++); 259 259 return count; 260 260 } ··· 269 269 void __iomem *ioaddr = pdata->ioaddr; 270 270 ssize_t count; 271 271 272 - for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--) 272 + for (count = 0; count < size; count++) 273 273 writeb(*buf++, ioaddr + pos++); 274 274 return count; 275 275 }
+36 -36
drivers/rtc/rtc-sysfs.c
··· 122 122 } 123 123 static DEVICE_ATTR_RO(hctosys); 124 124 125 - static struct attribute *rtc_attrs[] = { 126 - &dev_attr_name.attr, 127 - &dev_attr_date.attr, 128 - &dev_attr_time.attr, 129 - &dev_attr_since_epoch.attr, 130 - &dev_attr_max_user_freq.attr, 131 - &dev_attr_hctosys.attr, 132 - NULL, 133 - }; 134 - ATTRIBUTE_GROUPS(rtc); 135 - 136 125 static ssize_t 137 - rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr, 138 - char *buf) 126 + wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) 139 127 { 140 128 ssize_t retval; 141 129 unsigned long alarm; ··· 147 159 } 148 160 149 161 static ssize_t 150 - rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr, 162 + wakealarm_store(struct device *dev, struct device_attribute *attr, 151 163 const char *buf, size_t n) 152 164 { 153 165 ssize_t retval; ··· 209 221 retval = rtc_set_alarm(rtc, &alm); 210 222 return (retval < 0) ? retval : n; 211 223 } 212 - static DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR, 213 - rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm); 224 + static DEVICE_ATTR_RW(wakealarm); 214 225 226 + static struct attribute *rtc_attrs[] = { 227 + &dev_attr_name.attr, 228 + &dev_attr_date.attr, 229 + &dev_attr_time.attr, 230 + &dev_attr_since_epoch.attr, 231 + &dev_attr_max_user_freq.attr, 232 + &dev_attr_hctosys.attr, 233 + &dev_attr_wakealarm.attr, 234 + NULL, 235 + }; 215 236 216 237 /* The reason to trigger an alarm with no process watching it (via sysfs) 217 238 * is its side effect: waking from a system state like suspend-to-RAM or 218 239 * suspend-to-disk. So: no attribute unless that side effect is possible. 219 240 * (Userspace may disable that mechanism later.) 220 241 */ 221 - static inline int rtc_does_wakealarm(struct rtc_device *rtc) 242 + static bool rtc_does_wakealarm(struct rtc_device *rtc) 222 243 { 223 244 if (!device_can_wakeup(rtc->dev.parent)) 224 - return 0; 245 + return false; 246 + 225 247 return rtc->ops->set_alarm != NULL; 226 248 } 227 249 228 - 229 - void rtc_sysfs_add_device(struct rtc_device *rtc) 250 + static umode_t rtc_attr_is_visible(struct kobject *kobj, 251 + struct attribute *attr, int n) 230 252 { 231 - int err; 253 + struct device *dev = container_of(kobj, struct device, kobj); 254 + struct rtc_device *rtc = to_rtc_device(dev); 255 + umode_t mode = attr->mode; 232 256 233 - /* not all RTCs support both alarms and wakeup */ 234 - if (!rtc_does_wakealarm(rtc)) 235 - return; 257 + if (attr == &dev_attr_wakealarm.attr) 258 + if (!rtc_does_wakealarm(rtc)) 259 + mode = 0; 236 260 237 - err = device_create_file(&rtc->dev, &dev_attr_wakealarm); 238 - if (err) 239 - dev_err(rtc->dev.parent, 240 - "failed to create alarm attribute, %d\n", err); 261 + return mode; 241 262 } 242 263 243 - void rtc_sysfs_del_device(struct rtc_device *rtc) 244 - { 245 - /* REVISIT did we add it successfully? */ 246 - if (rtc_does_wakealarm(rtc)) 247 - device_remove_file(&rtc->dev, &dev_attr_wakealarm); 248 - } 264 + static struct attribute_group rtc_attr_group = { 265 + .is_visible = rtc_attr_is_visible, 266 + .attrs = rtc_attrs, 267 + }; 249 268 250 - void __init rtc_sysfs_init(struct class *rtc_class) 269 + static const struct attribute_group *rtc_attr_groups[] = { 270 + &rtc_attr_group, 271 + NULL 272 + }; 273 + 274 + const struct attribute_group **rtc_get_dev_attribute_groups(void) 251 275 { 252 - rtc_class->dev_groups = rtc_groups; 276 + return rtc_attr_groups; 253 277 }
+2 -4
drivers/rtc/rtc-tx4939.c
··· 199 199 ssize_t count; 200 200 201 201 spin_lock_irq(&pdata->lock); 202 - for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; 203 - count++, size--) { 202 + for (count = 0; count < size; count++) { 204 203 __raw_writel(pos++, &rtcreg->adr); 205 204 *buf++ = __raw_readl(&rtcreg->dat); 206 205 } ··· 217 218 ssize_t count; 218 219 219 220 spin_lock_irq(&pdata->lock); 220 - for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE; 221 - count++, size--) { 221 + for (count = 0; count < size; count++) { 222 222 __raw_writel(pos++, &rtcreg->adr); 223 223 __raw_writel(*buf++, &rtcreg->dat); 224 224 }
+1
drivers/rtc/rtc-vt8500.c
··· 271 271 { .compatible = "via,vt8500-rtc", }, 272 272 {} 273 273 }; 274 + MODULE_DEVICE_TABLE(of, wmt_dt_ids); 274 275 275 276 static struct platform_driver vt8500_rtc_driver = { 276 277 .probe = vt8500_rtc_probe,
+279
drivers/rtc/rtc-zynqmp.c
··· 1 + /* 2 + * Xilinx Zynq Ultrascale+ MPSoC Real Time Clock Driver 3 + * 4 + * Copyright (C) 2015 Xilinx, Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms and conditions of the GNU General Public License, 8 + * version 2, as published by the Free Software Foundation. 9 + * 10 + * This program is distributed in the hope it will be useful, but WITHOUT 11 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + * more details. 14 + * 15 + * You should have received a copy of the GNU General Public License along with 16 + * this program. If not, see <http://www.gnu.org/licenses/>. 17 + * 18 + */ 19 + 20 + #include <linux/delay.h> 21 + #include <linux/init.h> 22 + #include <linux/io.h> 23 + #include <linux/module.h> 24 + #include <linux/of.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/rtc.h> 27 + 28 + /* RTC Registers */ 29 + #define RTC_SET_TM_WR 0x00 30 + #define RTC_SET_TM_RD 0x04 31 + #define RTC_CALIB_WR 0x08 32 + #define RTC_CALIB_RD 0x0C 33 + #define RTC_CUR_TM 0x10 34 + #define RTC_CUR_TICK 0x14 35 + #define RTC_ALRM 0x18 36 + #define RTC_INT_STS 0x20 37 + #define RTC_INT_MASK 0x24 38 + #define RTC_INT_EN 0x28 39 + #define RTC_INT_DIS 0x2C 40 + #define RTC_CTRL 0x40 41 + 42 + #define RTC_FR_EN BIT(20) 43 + #define RTC_FR_DATSHIFT 16 44 + #define RTC_TICK_MASK 0xFFFF 45 + #define RTC_INT_SEC BIT(0) 46 + #define RTC_INT_ALRM BIT(1) 47 + #define RTC_OSC_EN BIT(24) 48 + 49 + #define RTC_CALIB_DEF 0x198233 50 + #define RTC_CALIB_MASK 0x1FFFFF 51 + #define RTC_SEC_MAX_VAL 0xFFFFFFFF 52 + 53 + struct xlnx_rtc_dev { 54 + struct rtc_device *rtc; 55 + void __iomem *reg_base; 56 + int alarm_irq; 57 + int sec_irq; 58 + }; 59 + 60 + static int xlnx_rtc_set_time(struct device *dev, struct rtc_time *tm) 61 + { 62 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 63 + unsigned long new_time; 64 + 65 + new_time = rtc_tm_to_time64(tm); 66 + 67 + if (new_time > RTC_SEC_MAX_VAL) 68 + return -EINVAL; 69 + 70 + writel(new_time, xrtcdev->reg_base + RTC_SET_TM_WR); 71 + 72 + return 0; 73 + } 74 + 75 + static int xlnx_rtc_read_time(struct device *dev, struct rtc_time *tm) 76 + { 77 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 78 + 79 + rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_CUR_TM), tm); 80 + 81 + return rtc_valid_tm(tm); 82 + } 83 + 84 + static int xlnx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 85 + { 86 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 87 + 88 + rtc_time64_to_tm(readl(xrtcdev->reg_base + RTC_ALRM), &alrm->time); 89 + alrm->enabled = readl(xrtcdev->reg_base + RTC_INT_MASK) & RTC_INT_ALRM; 90 + 91 + return 0; 92 + } 93 + 94 + static int xlnx_rtc_alarm_irq_enable(struct device *dev, u32 enabled) 95 + { 96 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 97 + 98 + if (enabled) 99 + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_EN); 100 + else 101 + writel(RTC_INT_ALRM, xrtcdev->reg_base + RTC_INT_DIS); 102 + 103 + return 0; 104 + } 105 + 106 + static int xlnx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 107 + { 108 + struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev); 109 + unsigned long alarm_time; 110 + 111 + alarm_time = rtc_tm_to_time64(&alrm->time); 112 + 113 + if (alarm_time > RTC_SEC_MAX_VAL) 114 + return -EINVAL; 115 + 116 + writel((u32)alarm_time, (xrtcdev->reg_base + RTC_ALRM)); 117 + 118 + xlnx_rtc_alarm_irq_enable(dev, alrm->enabled); 119 + 120 + return 0; 121 + } 122 + 123 + static void xlnx_init_rtc(struct xlnx_rtc_dev *xrtcdev, u32 calibval) 124 + { 125 + /* 126 + * Based on crystal freq of 33.330 KHz 127 + * set the seconds counter and enable, set fractions counter 128 + * to default value suggested as per design spec 129 + * to correct RTC delay in frequency over period of time. 130 + */ 131 + calibval &= RTC_CALIB_MASK; 132 + writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR)); 133 + } 134 + 135 + static const struct rtc_class_ops xlnx_rtc_ops = { 136 + .set_time = xlnx_rtc_set_time, 137 + .read_time = xlnx_rtc_read_time, 138 + .read_alarm = xlnx_rtc_read_alarm, 139 + .set_alarm = xlnx_rtc_set_alarm, 140 + .alarm_irq_enable = xlnx_rtc_alarm_irq_enable, 141 + }; 142 + 143 + static irqreturn_t xlnx_rtc_interrupt(int irq, void *id) 144 + { 145 + struct xlnx_rtc_dev *xrtcdev = (struct xlnx_rtc_dev *)id; 146 + unsigned int status; 147 + 148 + status = readl(xrtcdev->reg_base + RTC_INT_STS); 149 + /* Check if interrupt asserted */ 150 + if (!(status & (RTC_INT_SEC | RTC_INT_ALRM))) 151 + return IRQ_NONE; 152 + 153 + /* Clear interrupt */ 154 + writel(status, xrtcdev->reg_base + RTC_INT_STS); 155 + 156 + if (status & RTC_INT_SEC) 157 + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_UF); 158 + if (status & RTC_INT_ALRM) 159 + rtc_update_irq(xrtcdev->rtc, 1, RTC_IRQF | RTC_AF); 160 + 161 + return IRQ_HANDLED; 162 + } 163 + 164 + static int xlnx_rtc_probe(struct platform_device *pdev) 165 + { 166 + struct xlnx_rtc_dev *xrtcdev; 167 + struct resource *res; 168 + int ret; 169 + unsigned int calibvalue; 170 + 171 + xrtcdev = devm_kzalloc(&pdev->dev, sizeof(*xrtcdev), GFP_KERNEL); 172 + if (!xrtcdev) 173 + return -ENOMEM; 174 + 175 + platform_set_drvdata(pdev, xrtcdev); 176 + 177 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 178 + 179 + xrtcdev->reg_base = devm_ioremap_resource(&pdev->dev, res); 180 + if (IS_ERR(xrtcdev->reg_base)) 181 + return PTR_ERR(xrtcdev->reg_base); 182 + 183 + xrtcdev->alarm_irq = platform_get_irq_byname(pdev, "alarm"); 184 + if (xrtcdev->alarm_irq < 0) { 185 + dev_err(&pdev->dev, "no irq resource\n"); 186 + return xrtcdev->alarm_irq; 187 + } 188 + ret = devm_request_irq(&pdev->dev, xrtcdev->alarm_irq, 189 + xlnx_rtc_interrupt, 0, 190 + dev_name(&pdev->dev), xrtcdev); 191 + if (ret) { 192 + dev_err(&pdev->dev, "request irq failed\n"); 193 + return ret; 194 + } 195 + 196 + xrtcdev->sec_irq = platform_get_irq_byname(pdev, "sec"); 197 + if (xrtcdev->sec_irq < 0) { 198 + dev_err(&pdev->dev, "no irq resource\n"); 199 + return xrtcdev->sec_irq; 200 + } 201 + ret = devm_request_irq(&pdev->dev, xrtcdev->sec_irq, 202 + xlnx_rtc_interrupt, 0, 203 + dev_name(&pdev->dev), xrtcdev); 204 + if (ret) { 205 + dev_err(&pdev->dev, "request irq failed\n"); 206 + return ret; 207 + } 208 + 209 + ret = of_property_read_u32(pdev->dev.of_node, "calibration", 210 + &calibvalue); 211 + if (ret) 212 + calibvalue = RTC_CALIB_DEF; 213 + 214 + xlnx_init_rtc(xrtcdev, calibvalue); 215 + 216 + device_init_wakeup(&pdev->dev, 1); 217 + 218 + xrtcdev->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 219 + &xlnx_rtc_ops, THIS_MODULE); 220 + return PTR_ERR_OR_ZERO(xrtcdev->rtc); 221 + } 222 + 223 + static int xlnx_rtc_remove(struct platform_device *pdev) 224 + { 225 + xlnx_rtc_alarm_irq_enable(&pdev->dev, 0); 226 + device_init_wakeup(&pdev->dev, 0); 227 + 228 + return 0; 229 + } 230 + 231 + static int __maybe_unused xlnx_rtc_suspend(struct device *dev) 232 + { 233 + struct platform_device *pdev = to_platform_device(dev); 234 + struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); 235 + 236 + if (device_may_wakeup(&pdev->dev)) 237 + enable_irq_wake(xrtcdev->alarm_irq); 238 + else 239 + xlnx_rtc_alarm_irq_enable(dev, 0); 240 + 241 + return 0; 242 + } 243 + 244 + static int __maybe_unused xlnx_rtc_resume(struct device *dev) 245 + { 246 + struct platform_device *pdev = to_platform_device(dev); 247 + struct xlnx_rtc_dev *xrtcdev = platform_get_drvdata(pdev); 248 + 249 + if (device_may_wakeup(&pdev->dev)) 250 + disable_irq_wake(xrtcdev->alarm_irq); 251 + else 252 + xlnx_rtc_alarm_irq_enable(dev, 1); 253 + 254 + return 0; 255 + } 256 + 257 + static SIMPLE_DEV_PM_OPS(xlnx_rtc_pm_ops, xlnx_rtc_suspend, xlnx_rtc_resume); 258 + 259 + static const struct of_device_id xlnx_rtc_of_match[] = { 260 + {.compatible = "xlnx,zynqmp-rtc" }, 261 + { } 262 + }; 263 + MODULE_DEVICE_TABLE(of, xlnx_rtc_of_match); 264 + 265 + static struct platform_driver xlnx_rtc_driver = { 266 + .probe = xlnx_rtc_probe, 267 + .remove = xlnx_rtc_remove, 268 + .driver = { 269 + .name = KBUILD_MODNAME, 270 + .pm = &xlnx_rtc_pm_ops, 271 + .of_match_table = xlnx_rtc_of_match, 272 + }, 273 + }; 274 + 275 + module_platform_driver(xlnx_rtc_driver); 276 + 277 + MODULE_DESCRIPTION("Xilinx Zynq MPSoC RTC driver"); 278 + MODULE_AUTHOR("Xilinx Inc."); 279 + MODULE_LICENSE("GPL v2");
+29
include/asm-generic/rtc.h
··· 16 16 #include <linux/rtc.h> 17 17 #include <linux/bcd.h> 18 18 #include <linux/delay.h> 19 + #ifdef CONFIG_ACPI 20 + #include <linux/acpi.h> 21 + #endif 19 22 20 23 #define RTC_PIE 0x40 /* periodic interrupt enable */ 21 24 #define RTC_AIE 0x20 /* alarm interrupt enable */ ··· 49 46 { 50 47 unsigned char ctrl; 51 48 unsigned long flags; 49 + unsigned char century = 0; 52 50 53 51 #ifdef CONFIG_MACH_DECSTATION 54 52 unsigned int real_year; ··· 83 79 #ifdef CONFIG_MACH_DECSTATION 84 80 real_year = CMOS_READ(RTC_DEC_YEAR); 85 81 #endif 82 + #ifdef CONFIG_ACPI 83 + if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID && 84 + acpi_gbl_FADT.century) 85 + century = CMOS_READ(acpi_gbl_FADT.century); 86 + #endif 86 87 ctrl = CMOS_READ(RTC_CONTROL); 87 88 spin_unlock_irqrestore(&rtc_lock, flags); 88 89 ··· 99 90 time->tm_mday = bcd2bin(time->tm_mday); 100 91 time->tm_mon = bcd2bin(time->tm_mon); 101 92 time->tm_year = bcd2bin(time->tm_year); 93 + century = bcd2bin(century); 102 94 } 103 95 104 96 #ifdef CONFIG_MACH_DECSTATION 105 97 time->tm_year += real_year - 72; 106 98 #endif 99 + 100 + if (century) 101 + time->tm_year += (century - 19) * 100; 107 102 108 103 /* 109 104 * Account for differences between how the RTC uses the values ··· 135 122 #ifdef CONFIG_MACH_DECSTATION 136 123 unsigned int real_yrs, leap_yr; 137 124 #endif 125 + unsigned char century = 0; 138 126 139 127 yrs = time->tm_year; 140 128 mon = time->tm_mon + 1; /* tm_mon starts at zero */ ··· 164 150 yrs = 73; 165 151 } 166 152 #endif 153 + 154 + #ifdef CONFIG_ACPI 155 + if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID && 156 + acpi_gbl_FADT.century) { 157 + century = (yrs + 1900) / 100; 158 + yrs %= 100; 159 + } 160 + #endif 161 + 167 162 /* These limits and adjustments are independent of 168 163 * whether the chip is in binary mode or not. 169 164 */ ··· 192 169 day = bin2bcd(day); 193 170 mon = bin2bcd(mon); 194 171 yrs = bin2bcd(yrs); 172 + century = bin2bcd(century); 195 173 } 196 174 197 175 save_control = CMOS_READ(RTC_CONTROL); ··· 209 185 CMOS_WRITE(hrs, RTC_HOURS); 210 186 CMOS_WRITE(min, RTC_MINUTES); 211 187 CMOS_WRITE(sec, RTC_SECONDS); 188 + #ifdef CONFIG_ACPI 189 + if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID && 190 + acpi_gbl_FADT.century) 191 + CMOS_WRITE(century, acpi_gbl_FADT.century); 192 + #endif 212 193 213 194 CMOS_WRITE(save_control, RTC_CONTROL); 214 195 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);