History

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

Linus Torvalds committed 11 years ago

Commit c1917612 parents 12f03ee 5f1b2f782 files · +1756 −933Browse files

Unified · Split

82 files
  1. Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt +21 −0
  2. Documentation/devicetree/bindings/rtc/rtc-omap.txt +4 −0
  3. Documentation/devicetree/bindings/rtc/xlnx-rtc.txt +25 −0
  4. arch/arm/boot/dts/am4372.dtsi +2 −0
  5. arch/arm/boot/dts/am437x-gp-evm.dts +13 −0
  6. arch/arm/boot/dts/am437x-idk-evm.dts +9 −0
  7. arch/arm/boot/dts/am437x-sk-evm.dts +9 −0
  8. arch/arm/configs/cm_x2xx_defconfig +1 −1
  9. arch/arm/configs/em_x270_defconfig +1 −1
  10. arch/arm/configs/magician_defconfig +1 −1
  11. arch/arm/configs/palmz72_defconfig +1 −1
  12. arch/arm/configs/pcm027_defconfig +1 −1
  13. arch/arm/configs/trizeps4_defconfig +1 −1
  14. arch/arm/mach-mmp/include/mach/regs-rtc.h +0 −23
  15. arch/arm/mach-pxa/devices.c +2 −16
  16. arch/arm/mach-pxa/pxa27x.c +0 −1
  17. arch/arm/mach-pxa/pxa3xx.c +0 −1
  18. arch/arm/mach-sa1100/include/mach/SA-1100.h +0 −34
  19. drivers/rtc/Kconfig +29 −8
  20. drivers/rtc/Makefile +2 −0
  21. drivers/rtc/class.c +14 −19
  22. drivers/rtc/interface.c +1 −1
  23. drivers/rtc/rtc-88pm80x.c +17 −11
  24. drivers/rtc/rtc-ab-b5ze-s3.c +1 −1
  25. drivers/rtc/rtc-ab8500.c +2 −0
  26. drivers/rtc/rtc-abx80x.c +1 −1
  27. drivers/rtc/rtc-armada38x.c +13 −20
  28. drivers/rtc/rtc-as3722.c +2 −2
  29. drivers/rtc/rtc-at91rm9200.c +32 −11
  30. drivers/rtc/rtc-at91sam9.c +26 −19
  31. drivers/rtc/rtc-bfin.c +1 −1
  32. drivers/rtc/rtc-bq32k.c +1 −2
  33. drivers/rtc/rtc-cmos.c +59 −66
  34. drivers/rtc/rtc-coh901331.c +1 −0
  35. drivers/rtc/rtc-core.h +3 −16
  36. drivers/rtc/rtc-da9063.c +280 −112
  37. drivers/rtc/rtc-dev.c +1 −0
  38. drivers/rtc/rtc-ds1305.c +0 −18
  39. drivers/rtc/rtc-ds1307.c +56 −64
  40. drivers/rtc/rtc-ds1343.c +0 −12
  41. drivers/rtc/rtc-ds1374.c +2 −5
  42. drivers/rtc/rtc-ds1511.c +5 −37
  43. drivers/rtc/rtc-ds1553.c +2 −2
  44. drivers/rtc/rtc-ds1685.c +1 −21
  45. drivers/rtc/rtc-ds1742.c +2 −2
  46. drivers/rtc/rtc-ds3232.c +5 −3
  47. drivers/rtc/rtc-fm3130.c +0 −1
  48. drivers/rtc/rtc-gemini.c +1 −4
  49. drivers/rtc/rtc-hym8563.c +0 −1
  50. drivers/rtc/rtc-isl12022.c +2 −6
  51. drivers/rtc/rtc-isl12057.c +1 −1
  52. drivers/rtc/rtc-lpc24xx.c +310 −0
  53. drivers/rtc/rtc-m48t59.c +10 −8
  54. drivers/rtc/rtc-max8997.c +1 −0
  55. drivers/rtc/rtc-moxart.c +1 −0
  56. drivers/rtc/rtc-mpc5121.c +1 −0
  57. drivers/rtc/rtc-mt6397.c +27 −0
  58. drivers/rtc/rtc-mv.c +1 −0
  59. drivers/rtc/rtc-omap.c +33 −0
  60. drivers/rtc/rtc-opal.c +5 −5
  61. drivers/rtc/rtc-pcf2123.c +1 −7
  62. drivers/rtc/rtc-pcf2127.c +24 −11
  63. drivers/rtc/rtc-pcf85063.c +0 −1
  64. drivers/rtc/rtc-pcf8523.c +0 −1
  65. drivers/rtc/rtc-pcf8563.c +0 −1
  66. drivers/rtc/rtc-pcf8583.c +0 −1
  67. drivers/rtc/rtc-pl031.c +1 −1
  68. drivers/rtc/rtc-pxa.c +28 −27
  69. drivers/rtc/rtc-rp5c01.c +2 −2
  70. drivers/rtc/rtc-rx8025.c +105 −172
  71. drivers/rtc/rtc-rx8581.c +0 −1
  72. drivers/rtc/rtc-s3c.c +21 −7
  73. drivers/rtc/rtc-s5m.c +11 −0
  74. drivers/rtc/rtc-sa1100.c +84 −55
  75. drivers/rtc/rtc-sa1100.h +23 −0
  76. drivers/rtc/rtc-sirfsoc.c +64 −43
  77. drivers/rtc/rtc-stk17ta8.c +2 −2
  78. drivers/rtc/rtc-sysfs.c +36 −36
  79. drivers/rtc/rtc-tx4939.c +2 −4
  80. drivers/rtc/rtc-vt8500.c +1 −0
  81. drivers/rtc/rtc-zynqmp.c +279 −0
  82. include/asm-generic/rtc.h +29 −0
Documentation/devicetree/bindings/rtc/nxp,lpc1788-rtc.txt+21−0
@@ -0,0 +1,21 @@
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+};
Documentation/devicetree/bindings/rtc/rtc-omap.txt+4−0
@@ -16,6 +16,8 @@ Required properties: · 15 unmodified lines
1616 Optional properties:
1717 - system-power-controller: whether the rtc is controlling the system power
1818 through pmic_power_en
19+- clocks: Any internal or external clocks feeding in to rtc
20+- clock-names: Corresponding names of the clocks
1921
2022 Example:
2123
@@ -26,4 +28,6 @@ rtc@1c23000 { · 4 unmodified lines
2628 19>;
2729 interrupt-parent = <&intc>;
2830 system-power-controller;
31+ clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
32+ clock-names = "ext-clk", "int-clk";
2933 };
Documentation/devicetree/bindings/rtc/xlnx-rtc.txt+25−0
@@ -0,0 +1,25 @@
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+};
arch/arm/boot/dts/am4372.dtsi+2−0
@@ -358,6 +358,8 @@ · 357 unmodified lines
358358 interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH
359359 GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>;
360360 ti,hwmods = "rtc";
361+ clocks = <&clk_32768_ck>;
362+ clock-names = "int-clk";
361363 status = "disabled";
362364 };
363365
arch/arm/boot/dts/am437x-gp-evm.dts+13−0
@@ -112,6 +112,13 @@ · 111 unmodified lines
112112 clock-frequency = <12000000>;
113113 };
114114
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+
115122 sound0: sound@0 {
116123 compatible = "simple-audio-card";
117124 simple-audio-card,name = "AM437x-GP-EVM";
@@ -941,3 +948,9 @@ · 823 unmodified lines
941948 tx-num-evt = <32>;
942949 rx-num-evt = <32>;
943950 };
951+
952+&rtc {
953+ clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
954+ clock-names = "ext-clk", "int-clk";
955+ status = "okay";
956+};
arch/arm/boot/dts/am437x-idk-evm.dts+9−0
@@ -110,6 +110,13 @@ · 109 unmodified lines
110110 gpios = <&gpio4 2 GPIO_ACTIVE_LOW>;
111111 };
112112 };
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+ };
113120 };
114121
115122 &am43xx_pinmux {
@@ -394,6 +401,8 @@ · 278 unmodified lines
394401 };
395402
396403 &rtc {
404+ clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
405+ clock-names = "ext-clk", "int-clk";
397406 status = "okay";
398407 };
399408
arch/arm/boot/dts/am437x-sk-evm.dts+9−0
@@ -24,6 +24,13 @@ · 23 unmodified lines
2424 display0 = &lcd0;
2525 };
2626
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+
2734 backlight {
2835 compatible = "pwm-backlight";
2936 pwms = <&ecap0 0 50000 PWM_POLARITY_INVERTED>;
@@ -697,6 +704,8 @@ · 667 unmodified lines
697704 };
698705
699706 &rtc {
707+ clocks = <&clk_32k_rtc>, <&clk_32768_ck>;
708+ clock-names = "ext-clk", "int-clk";
700709 status = "okay";
701710 };
702711
arch/arm/configs/cm_x2xx_defconfig+1−1
@@ -157,7 +157,7 @@ CONFIG_LEDS_TRIGGERS=y · 156 unmodified lines
157157 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
158158 CONFIG_RTC_CLASS=y
159159 CONFIG_RTC_DRV_V3020=y
160−CONFIG_RTC_DRV_SA1100=y
160+CONFIG_RTC_DRV_PXA=y
161161 CONFIG_EXT2_FS=y
162162 CONFIG_EXT3_FS=y
163163 CONFIG_INOTIFY=y
arch/arm/configs/em_x270_defconfig+1−1
@@ -157,7 +157,7 @@ CONFIG_LEDS_TRIGGERS=y · 156 unmodified lines
157157 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
158158 CONFIG_RTC_CLASS=y
159159 CONFIG_RTC_DRV_V3020=y
160−CONFIG_RTC_DRV_SA1100=y
160+CONFIG_RTC_DRV_PXA=y
161161 CONFIG_EXT2_FS=y
162162 CONFIG_EXT3_FS=y
163163 CONFIG_INOTIFY=y
arch/arm/configs/magician_defconfig+1−1
@@ -150,7 +150,7 @@ CONFIG_LEDS_TRIGGERS=y · 149 unmodified lines
150150 CONFIG_LEDS_TRIGGER_BACKLIGHT=y
151151 CONFIG_RTC_CLASS=y
152152 CONFIG_RTC_DEBUG=y
153−CONFIG_RTC_DRV_SA1100=y
153+CONFIG_RTC_DRV_PXA=y
154154 CONFIG_EXT2_FS=y
155155 CONFIG_INOTIFY=y
156156 CONFIG_MSDOS_FS=m
arch/arm/configs/palmz72_defconfig+1−1
@@ -67,7 +67,7 @@ CONFIG_MMC=y · 66 unmodified lines
6767 CONFIG_MMC_DEBUG=y
6868 CONFIG_MMC_PXA=y
6969 CONFIG_RTC_CLASS=y
70−CONFIG_RTC_DRV_SA1100=y
70+CONFIG_RTC_DRV_PXA=y
7171 CONFIG_EXT2_FS=y
7272 CONFIG_EXT3_FS=y
7373 # CONFIG_DNOTIFY is not set
arch/arm/configs/pcm027_defconfig+1−1
@@ -82,7 +82,7 @@ CONFIG_MMC=y · 81 unmodified lines
8282 CONFIG_MMC_PXA=y
8383 CONFIG_RTC_CLASS=y
8484 CONFIG_RTC_DRV_PCF8563=m
85−CONFIG_RTC_DRV_SA1100=m
85+CONFIG_RTC_DRV_PXA=m
8686 CONFIG_EXT2_FS=m
8787 CONFIG_EXT3_FS=m
8888 # CONFIG_DNOTIFY is not set
arch/arm/configs/trizeps4_defconfig+1−1
@@ -177,7 +177,7 @@ CONFIG_NEW_LEDS=y · 176 unmodified lines
177177 CONFIG_RTC_CLASS=y
178178 # CONFIG_RTC_HCTOSYS is not set
179179 CONFIG_RTC_DRV_PCF8583=m
180−CONFIG_RTC_DRV_SA1100=y
180+CONFIG_RTC_DRV_PXA=y
181181 CONFIG_EXT2_FS=y
182182 CONFIG_EXT2_FS_XATTR=y
183183 CONFIG_EXT2_FS_POSIX_ACL=y
arch/arm/mach-mmp/include/mach/regs-rtc.h+0−23
@@ -1,23 +0,0 @@
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 */
arch/arm/mach-pxa/devices.c+2−16
@@ -440,25 +440,11 @@ struct platform_device pxa_device_rtc = { · 439 unmodified lines
440440 .resource = pxa_rtc_resources,
441441 };
442442
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−
457443 struct platform_device sa1100_device_rtc = {
458444 .name = "sa1100-rtc",
459445 .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,
462448 };
463449
464450 static struct resource pxa_ac97_resources[] = {
arch/arm/mach-pxa/pxa27x.c+0−1
@@ -282,7 +282,6 @@ static struct platform_device *devices[] __initdata = { · 281 unmodified lines
282282 &pxa_device_asoc_ssp2,
283283 &pxa_device_asoc_ssp3,
284284 &pxa_device_asoc_platform,
285− &sa1100_device_rtc,
286285 &pxa_device_rtc,
287286 &pxa27x_device_ssp1,
288287 &pxa27x_device_ssp2,
arch/arm/mach-pxa/pxa3xx.c+0−1
@@ -394,7 +394,6 @@ static struct platform_device *devices[] __initdata = { · 393 unmodified lines
394394 &pxa_device_asoc_ssp3,
395395 &pxa_device_asoc_ssp4,
396396 &pxa_device_asoc_platform,
397− &sa1100_device_rtc,
398397 &pxa_device_rtc,
399398 &pxa3xx_device_ssp1,
400399 &pxa3xx_device_ssp2,
arch/arm/mach-sa1100/include/mach/SA-1100.h+0−34
@@ -857,40 +857,6 @@ · 856 unmodified lines
857857 #define OIER_E3 OIER_E (3) /* match interrupt Enable 3 */
858858
859859
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−
894860 /*
895861 * Power Manager (PM) control registers
896862 *
drivers/rtc/Kconfig+29−8
@@ -945,11 +945,11 @@ config RTC_DRV_DA9055 · 944 unmodified lines
945945 will be called rtc-da9055
946946
947947 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
950950 help
951951 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.
953953
954954 This driver can also be built as a module. If so, the module
955955 will be called "rtc-da9063".
@@ -1116,6 +1116,13 @@ config RTC_DRV_OPAL · 160 unmodified lines
11161116 This driver can also be built as a module. If so, the module
11171117 will be called rtc-opal.
11181118
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.
1125+
11191126 comment "on-CPU RTC drivers"
11201127
11211128 config RTC_DRV_DAVINCI
@@ -1306,11 +1313,13 @@ config RTC_DRV_GENERIC · 184 unmodified lines
13061313 just say Y.
13071314
13081315 config RTC_DRV_PXA
1309− tristate "PXA27x/PXA3xx"
1310− depends on ARCH_PXA
1311− help
1312− If you say Y here you will get access to the real time clock
1313− built into your PXA27x or PXA3xx CPU.
1316+ tristate "PXA27x/PXA3xx"
1317+ depends on ARCH_PXA
1318+ select RTC_DRV_SA1100
1319+ help
1320+ If you say Y here you will get access to the real time clock
1321+ built into your PXA27x or PXA3xx CPU. This RTC is actually 2 RTCs
1322+ consisting of an SA1100 compatible RTC and the extended PXA RTC.
13141323
13151324 This RTC driver uses PXA RTC registers available since pxa27x
13161325 series (RDxR, RYxR) instead of legacy RCNR, RTAR.
@@ -1456,6 +1465,18 @@ config RTC_DRV_JZ4740 · 139 unmodified lines
14561465 This driver can also be buillt as a module. If so, the module
14571466 will be called rtc-jz4740.
14581467
1468+config RTC_DRV_LPC24XX
1469+ tristate "NXP RTC for LPC178x/18xx/408x/43xx"
1470+ depends on ARCH_LPC18XX || COMPILE_TEST
1471+ depends on OF && HAS_IOMEM
1472+ help
1473+ This enables support for the NXP RTC found which can be found on
1474+ NXP LPC178x/18xx/408x/43xx devices.
1475+
1476+ If you have one of the devices above enable this driver to use
1477+ the hardware RTC. This driver can also be buillt as a module. If
1478+ so, the module will be called rtc-lpc24xx.
1479+
14591480 config RTC_DRV_LPC32XX
14601481 depends on ARCH_LPC32XX
14611482 tristate "NXP LPC32XX RTC"
drivers/rtc/Makefile+2−0
@@ -74,6 +74,7 @@ obj-$(CONFIG_RTC_DRV_ISL12057) += rtc-isl12057.o · 73 unmodified lines
7474 obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
7575 obj-$(CONFIG_RTC_DRV_JZ4740) += rtc-jz4740.o
7676 obj-$(CONFIG_RTC_DRV_LP8788) += rtc-lp8788.o
77+obj-$(CONFIG_RTC_DRV_LPC24XX) += rtc-lpc24xx.o
7778 obj-$(CONFIG_RTC_DRV_LPC32XX) += rtc-lpc32xx.o
7879 obj-$(CONFIG_RTC_DRV_LOONGSON1) += rtc-ls1x.o
7980 obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
@@ -158,3 +159,4 @@ obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o · 78 unmodified lines
158159 obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o
159160 obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
160161 obj-$(CONFIG_RTC_DRV_XGENE) += rtc-xgene.o
162+obj-$(CONFIG_RTC_DRV_ZYNQMP) += rtc-zynqmp.o
drivers/rtc/class.c+14−19
@@ -202,6 +202,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, · 201 unmodified lines
202202 rtc->max_user_freq = 64;
203203 rtc->dev.parent = dev;
204204 rtc->dev.class = rtc_class;
205+ rtc->dev.groups = rtc_get_dev_attribute_groups();
205206 rtc->dev.release = rtc_device_release;
206207
207208 mutex_init(&rtc->ops_lock);
@@ -234,12 +235,12 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, · 26 unmodified lines
234235
235236 err = device_register(&rtc->dev);
236237 if (err) {
238+ /* This will free both memory and the ID */
237239 put_device(&rtc->dev);
238− goto exit_kfree;
240+ goto exit;
239241 }
240242
241243 rtc_dev_add_device(rtc);
242− rtc_sysfs_add_device(rtc);
243244 rtc_proc_add_device(rtc);
244245
245246 dev_info(dev, "rtc core: registered %s as %s\n",
@@ -247,9 +248,6 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, · 1 unmodified line
247248
248249 return rtc;
249250
250−exit_kfree:
251− kfree(rtc);
252−
253251 exit_ida:
254252 ida_simple_remove(&rtc_ida, id);
255253
@@ -268,19 +266,17 @@ EXPORT_SYMBOL_GPL(rtc_device_register); · 12 unmodified lines
268266 */
269267 void rtc_device_unregister(struct rtc_device *rtc)
270268 {
271− if (get_device(&rtc->dev) != NULL) {
272− mutex_lock(&rtc->ops_lock);
273− /* remove innards of this RTC, then disable it, before
274− * letting any rtc_class_open() users access it again
275− */
276− rtc_sysfs_del_device(rtc);
277− rtc_dev_del_device(rtc);
278− rtc_proc_del_device(rtc);
279− device_unregister(&rtc->dev);
280− rtc->ops = NULL;
281− mutex_unlock(&rtc->ops_lock);
282− put_device(&rtc->dev);
283− }
269+ mutex_lock(&rtc->ops_lock);
270+ /*
271+ * Remove innards of this RTC, then disable it, before
272+ * letting any rtc_class_open() users access it again
273+ */
274+ rtc_dev_del_device(rtc);
275+ rtc_proc_del_device(rtc);
276+ device_del(&rtc->dev);
277+ rtc->ops = NULL;
278+ mutex_unlock(&rtc->ops_lock);
279+ put_device(&rtc->dev);
284280 }
285281 EXPORT_SYMBOL_GPL(rtc_device_unregister);
286282
@@ -363,7 +359,6 @@ static int __init rtc_init(void) · 76 unmodified lines
363359 }
364360 rtc_class->pm = RTC_CLASS_DEV_PM_OPS;
365361 rtc_dev_init();
366− rtc_sysfs_init(rtc_class);
367362 return 0;
368363 }
369364
drivers/rtc/interface.c+1−1
@@ -564,7 +564,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer) · 563 unmodified lines
564564 void rtc_update_irq(struct rtc_device *rtc,
565565 unsigned long num, unsigned long events)
566566 {
567− if (unlikely(IS_ERR_OR_NULL(rtc)))
567+ if (IS_ERR_OR_NULL(rtc))
568568 return;
569569
570570 pm_stay_awake(rtc->dev.parent);
drivers/rtc/rtc-88pm80x.c+17−11
@@ -251,17 +251,26 @@ static SIMPLE_DEV_PM_OPS(pm80x_rtc_pm_ops, pm80x_rtc_suspend, pm80x_rtc_resume); · 250 unmodified lines
251251 static int pm80x_rtc_probe(struct platform_device *pdev)
252252 {
253253 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);
257255 struct pm80x_rtc_info *info;
256+ struct device_node *node = pdev->dev.of_node;
258257 struct rtc_time tm;
259258 unsigned long ticks = 0;
260259 int ret;
261260
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+ }
265274
266275 info =
267276 devm_kzalloc(&pdev->dev, sizeof(struct pm80x_rtc_info), GFP_KERNEL);
@@ -327,11 +336,8 @@ static int pm80x_rtc_probe(struct platform_device *pdev) · 59 unmodified lines
327336 regmap_update_bits(info->map, PM800_RTC_CONTROL, PM800_RTC1_USE_XO,
328337 PM800_RTC1_USE_XO);
329338
330− if (pm80x_pdata) {
331− pdata = pm80x_pdata->rtc;
332− if (pdata)
333− info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup;
334− }
339+ /* remember whether this power up is caused by PMIC RTC or not */
340+ info->rtc_dev->dev.platform_data = &pdata->rtc_wakeup;
335341
336342 device_init_wakeup(&pdev->dev, 1);
337343
drivers/rtc/rtc-ab-b5ze-s3.c+1−1
@@ -1009,6 +1009,7 @@ static const struct of_device_id abb5zes3_dt_match[] = { · 1008 unmodified lines
10091009 { .compatible = "abracon,abb5zes3" },
10101010 { },
10111011 };
1012+MODULE_DEVICE_TABLE(of, abb5zes3_dt_match);
10121013 #endif
10131014
10141015 static const struct i2c_device_id abb5zes3_id[] = {
@@ -1020,7 +1021,6 @@ MODULE_DEVICE_TABLE(i2c, abb5zes3_id); · 5 unmodified lines
10201021 static struct i2c_driver abb5zes3_driver = {
10211022 .driver = {
10221023 .name = DRV_NAME,
1023− .owner = THIS_MODULE,
10241024 .pm = &abb5zes3_rtc_pm_ops,
10251025 .of_match_table = of_match_ptr(abb5zes3_dt_match),
10261026 },
drivers/rtc/rtc-ab8500.c+2−0
@@ -445,7 +445,9 @@ static const struct rtc_class_ops ab8540_rtc_ops = { · 444 unmodified lines
445445 static const struct platform_device_id ab85xx_rtc_ids[] = {
446446 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
447447 { "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, },
448+ { /* sentinel */ }
448449 };
450+MODULE_DEVICE_TABLE(platform, ab85xx_rtc_ids);
449451
450452 static int ab8500_rtc_probe(struct platform_device *pdev)
451453 {
drivers/rtc/rtc-abx80x.c+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #define ABX8XX_REG_WD 0x07
2929
3030 #define ABX8XX_REG_CTRL1 0x10
31−#define ABX8XX_CTRL_WRITE BIT(1)
31+#define ABX8XX_CTRL_WRITE BIT(0)
3232 #define ABX8XX_CTRL_12_24 BIT(6)
3333
3434 #define ABX8XX_REG_CFG_KEY 0x1f
drivers/rtc/rtc-armada38x.c+13−20
@@ -40,13 +40,6 @@ struct armada38x_rtc { · 39 unmodified lines
4040 void __iomem *regs;
4141 void __iomem *regs_soc;
4242 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;
5043 int irq;
5144 };
5245
@@ -64,9 +57,9 @@ static void rtc_delayed_write(u32 val, struct armada38x_rtc *rtc, int offset) · 11 unmodified lines
6457 static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm)
6558 {
6659 struct armada38x_rtc *rtc = dev_get_drvdata(dev);
67− unsigned long time, time_check;
60+ unsigned long time, time_check, flags;
6861
69− mutex_lock(&rtc->mutex_time);
62+ spin_lock_irqsave(&rtc->lock, flags);
7063 time = readl(rtc->regs + RTC_TIME);
7164 /*
7265 * WA for failing time set attempts. As stated in HW ERRATA if
@@ -77,7 +70,7 @@ static int armada38x_rtc_read_time(struct device *dev, struct rtc_time *tm) · 4 unmodified lines
7770 if ((time_check - time) > 1)
7871 time_check = readl(rtc->regs + RTC_TIME);
7972
80− mutex_unlock(&rtc->mutex_time);
73+ spin_unlock_irqrestore(&rtc->lock, flags);
8174
8275 rtc_time_to_tm(time_check, tm);
8376
@@ -88,23 +81,23 @@ static int armada38x_rtc_set_time(struct device *dev, struct rtc_time *tm) · 4 unmodified lines
8881 {
8982 struct armada38x_rtc *rtc = dev_get_drvdata(dev);
9083 int ret = 0;
91− unsigned long time;
84+ unsigned long time, flags;
9285
9386 ret = rtc_tm_to_time(tm, &time);
9487
9588 if (ret)
9689 goto out;
9790 /*
98− * Setting the RTC time not always succeeds. According to the
99− * errata we need to first write on the status register and
100− * then wait for 100ms before writing to the time register to be
101− * sure that the data will be taken into account.
91+ * According to errata FE-3124064, Write to RTC TIME register
92+ * may fail. As a workaround, after writing to RTC TIME
93+ * register, issue a dummy write of 0x0 twice to RTC Status
94+ * register.
10295 */
103− mutex_lock(&rtc->mutex_time);
104− rtc_delayed_write(0, rtc, RTC_STATUS);
105− msleep(100);
96+ spin_lock_irqsave(&rtc->lock, flags);
10697 rtc_delayed_write(time, rtc, RTC_TIME);
107− mutex_unlock(&rtc->mutex_time);
98+ rtc_delayed_write(0, rtc, RTC_STATUS);
99+ rtc_delayed_write(0, rtc, RTC_STATUS);
100+ spin_unlock_irqrestore(&rtc->lock, flags);
108101
109102 out:
110103 return ret;
@@ -229,7 +222,6 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev) · 118 unmodified lines
229222 return -ENOMEM;
230223
231224 spin_lock_init(&rtc->lock);
232− mutex_init(&rtc->mutex_time);
233225
234226 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc");
235227 rtc->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -303,6 +295,7 @@ static const struct of_device_id armada38x_rtc_of_match_table[] = { · 67 unmodified lines
303295 { .compatible = "marvell,armada-380-rtc", },
304296 {}
305297 };
298+MODULE_DEVICE_TABLE(of, armada38x_rtc_of_match_table);
306299 #endif
307300
308301 static struct platform_driver armada38x_rtc_driver = {
drivers/rtc/rtc-as3722.c+2−2
@@ -45,7 +45,7 @@ static void as3722_time_to_reg(u8 *rbuff, struct rtc_time *tm) · 44 unmodified lines
4545 rbuff[1] = bin2bcd(tm->tm_min);
4646 rbuff[2] = bin2bcd(tm->tm_hour);
4747 rbuff[3] = bin2bcd(tm->tm_mday);
48− rbuff[4] = bin2bcd(tm->tm_mon);
48+ rbuff[4] = bin2bcd(tm->tm_mon + 1);
4949 rbuff[5] = bin2bcd(tm->tm_year - (AS3722_RTC_START_YEAR - 1900));
5050 }
5151
@@ -55,7 +55,7 @@ static void as3722_reg_to_time(u8 *rbuff, struct rtc_time *tm) · 3 unmodified lines
5555 tm->tm_min = bcd2bin(rbuff[1] & 0x7F);
5656 tm->tm_hour = bcd2bin(rbuff[2] & 0x3F);
5757 tm->tm_mday = bcd2bin(rbuff[3] & 0x3F);
58− tm->tm_mon = bcd2bin(rbuff[4] & 0x1F);
58+ tm->tm_mon = bcd2bin(rbuff[4] & 0x1F) - 1;
5959 tm->tm_year = (AS3722_RTC_START_YEAR - 1900) + bcd2bin(rbuff[5] & 0x7F);
6060 return;
6161 }
drivers/rtc/rtc-at91rm9200.c+32−11
@@ -18,20 +18,21 @@ · 17 unmodified lines
1818 *
1919 */
2020
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>
2621 #include <linux/bcd.h>
22+#include <linux/clk.h>
23+#include <linux/completion.h>
2724 #include <linux/interrupt.h>
28−#include <linux/spinlock.h>
2925 #include <linux/ioctl.h>
30−#include <linux/completion.h>
3126 #include <linux/io.h>
32−#include <linux/of.h>
27+#include <linux/kernel.h>
28+#include <linux/module.h>
3329 #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>
3434 #include <linux/suspend.h>
35+#include <linux/time.h>
3536 #include <linux/uaccess.h>
3637
3738 #include "rtc-at91rm9200.h"
@@ -59,6 +60,7 @@ static bool suspended; · 21 unmodified lines
5960 static DEFINE_SPINLOCK(suspended_lock);
6061 static unsigned long cached_events;
6162 static u32 at91_rtc_imr;
63+static struct clk *sclk;
6264
6365 static void at91_rtc_write_ier(u32 mask)
6466 {
@@ -407,6 +409,16 @@ static int __init at91_rtc_probe(struct platform_device *pdev) · 342 unmodified lines
407409 return -ENOMEM;
408410 }
409411
412+ sclk = devm_clk_get(&pdev->dev, NULL);
413+ if (IS_ERR(sclk))
414+ return PTR_ERR(sclk);
415+
416+ ret = clk_prepare_enable(sclk);
417+ if (ret) {
418+ dev_err(&pdev->dev, "Could not enable slow clock\n");
419+ return ret;
420+ }
421+
410422 at91_rtc_write(AT91_RTC_CR, 0);
411423 at91_rtc_write(AT91_RTC_MR, 0); /* 24 hour mode */
412424
@@ -420,7 +432,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev) · 7 unmodified lines
420432 "at91_rtc", pdev);
421433 if (ret) {
422434 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq);
423− return ret;
435+ goto err_clk;
424436 }
425437
426438 /* cpu init code should really have flagged this device as
@@ -431,8 +443,10 @@ static int __init at91_rtc_probe(struct platform_device *pdev) · 4 unmodified lines
431443
432444 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
433445 &at91_rtc_ops, THIS_MODULE);
434− if (IS_ERR(rtc))
435− return PTR_ERR(rtc);
446+ if (IS_ERR(rtc)) {
447+ ret = PTR_ERR(rtc);
448+ goto err_clk;
449+ }
436450 platform_set_drvdata(pdev, rtc);
437451
438452 /* enable SECEV interrupt in order to initialize at91_rtc_upd_rdy
@@ -442,6 +456,11 @@ static int __init at91_rtc_probe(struct platform_device *pdev) · 3 unmodified lines
442456
443457 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n");
444458 return 0;
459+
460+err_clk:
461+ clk_disable_unprepare(sclk);
462+
463+ return ret;
445464 }
446465
447466 /*
@@ -454,6 +473,8 @@ static int __exit at91_rtc_remove(struct platform_device *pdev) · 6 unmodified lines
454473 AT91_RTC_SECEV | AT91_RTC_TIMEV |
455474 AT91_RTC_CALEV);
456475
476+ clk_disable_unprepare(sclk);
477+
457478 return 0;
458479 }
459480
drivers/rtc/rtc-at91sam9.c+26−19
@@ -11,20 +11,20 @@ · 10 unmodified lines
1111 * 2 of the License, or (at your option) any later version.
1212 */
1313
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>
1915 #include <linux/interrupt.h>
2016 #include <linux/ioctl.h>
21−#include <linux/slab.h>
22−#include <linux/platform_data/atmel.h>
2317 #include <linux/io.h>
18+#include <linux/kernel.h>
2419 #include <linux/mfd/syscon.h>
20+#include <linux/module.h>
21+#include <linux/of.h>
22+#include <linux/platform_device.h>
2523 #include <linux/regmap.h>
24+#include <linux/rtc.h>
25+#include <linux/slab.h>
2626 #include <linux/suspend.h>
27−#include <linux/clk.h>
27+#include <linux/time.h>
2828
2929 /*
3030 * This driver uses two configurable hardware resources that live in the
@@ -425,18 +425,19 @@ static int at91_rtc_probe(struct platform_device *pdev) · 394 unmodified lines
425425 if (IS_ERR(rtc->sclk))
426426 return PTR_ERR(rtc->sclk);
427427
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−
434428 ret = clk_prepare_enable(rtc->sclk);
435429 if (ret) {
436430 dev_err(&pdev->dev, "Could not enable slow clock\n");
437431 return ret;
438432 }
439433
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;
439+ }
440+
440441 mr = rtt_readl(rtc, MR);
441442
442443 /* unless RTT is counting at 1 Hz, re-initialize it */
@@ -451,8 +452,10 @@ static int at91_rtc_probe(struct platform_device *pdev) · 8 unmodified lines
451452
452453 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
453454 &at91_rtc_ops, THIS_MODULE);
454− if (IS_ERR(rtc->rtcdev))
455− return PTR_ERR(rtc->rtcdev);
455+ if (IS_ERR(rtc->rtcdev)) {
456+ ret = PTR_ERR(rtc->rtcdev);
457+ goto err_clk;
458+ }
456459
457460 /* register irq handler after we know what name we'll use */
458461 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
@@ -460,7 +463,7 @@ static int at91_rtc_probe(struct platform_device *pdev) · 1 unmodified line
460463 dev_name(&rtc->rtcdev->dev), rtc);
461464 if (ret) {
462465 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
463− return ret;
466+ goto err_clk;
464467 }
465468
466469 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the
@@ -474,6 +477,11 @@ static int at91_rtc_probe(struct platform_device *pdev) · 7 unmodified lines
474477 dev_name(&rtc->rtcdev->dev));
475478
476479 return 0;
480+
481+err_clk:
482+ clk_disable_unprepare(rtc->sclk);
483+
484+ return ret;
477485 }
478486
479487 /*
@@ -487,8 +495,7 @@ static int at91_rtc_remove(struct platform_device *pdev) · 7 unmodified lines
487495 /* disable all interrupts */
488496 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
489497
490− if (!IS_ERR(rtc->sclk))
491− clk_disable_unprepare(rtc->sclk);
498+ clk_disable_unprepare(rtc->sclk);
492499
493500 return 0;
494501 }
drivers/rtc/rtc-bfin.c+1−1
@@ -361,7 +361,7 @@ static int bfin_rtc_probe(struct platform_device *pdev) · 360 unmodified lines
361361 /* Register our RTC with the RTC framework */
362362 rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
363363 THIS_MODULE);
364− if (unlikely(IS_ERR(rtc->rtc_dev)))
364+ if (IS_ERR(rtc->rtc_dev))
365365 return PTR_ERR(rtc->rtc_dev);
366366
367367 /* Grab the IRQ and init the hardware */
drivers/rtc/rtc-bq32k.c+1−2
@@ -212,7 +212,7 @@ static int bq32k_probe(struct i2c_client *client, · 211 unmodified lines
212212 if (error)
213213 return error;
214214
215− if (client && client->dev.of_node)
215+ if (client->dev.of_node)
216216 trickle_charger_of_init(dev, client->dev.of_node);
217217
218218 rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
@@ -234,7 +234,6 @@ MODULE_DEVICE_TABLE(i2c, bq32k_id); · 15 unmodified lines
234234 static struct i2c_driver bq32k_driver = {
235235 .driver = {
236236 .name = "bq32k",
237− .owner = THIS_MODULE,
238237 },
239238 .probe = bq32k_probe,
240239 .id_table = bq32k_id,
drivers/rtc/rtc-cmos.c+59−66
@@ -41,7 +41,6 @@ · 40 unmodified lines
4141 #include <linux/pm.h>
4242 #include <linux/of.h>
4343 #include <linux/of_platform.h>
44−#include <linux/dmi.h>
4544
4645 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
4746 #include <asm-generic/rtc.h>
@@ -51,6 +50,7 @@ struct cmos_rtc { · 3 unmodified lines
5150 struct device *dev;
5251 int irq;
5352 struct resource *iomem;
53+ time64_t alarm_expires;
5454
5555 void (*wake_on)(struct device *);
5656 void (*wake_off)(struct device *);
@@ -377,53 +377,11 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) · 320 unmodified lines
377377
378378 spin_unlock_irq(&rtc_lock);
379379
380− return 0;
381−}
382−
383−/*
384− * Do not disable RTC alarm on shutdown - workaround for b0rked BIOSes.
385− */
386−static bool alarm_disable_quirk;
380+ cmos->alarm_expires = rtc_tm_to_time64(&t->time);
387381
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");
392382 return 0;
393383 }
394384
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−
427385 static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled)
428386 {
429387 struct cmos_rtc *cmos = dev_get_drvdata(dev);
@@ -432,9 +390,6 @@ static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled) · 2 unmodified lines
432390 if (!is_valid_irq(cmos->irq))
433391 return -EINVAL;
434392
435− if (alarm_disable_quirk)
436− return 0;
437−
438393 spin_lock_irqsave(&rtc_lock, flags);
439394
440395 if (enabled)
@@ -512,13 +467,6 @@ cmos_nvram_read(struct file *filp, struct kobject *kobj, · 71 unmodified lines
512467 {
513468 int retval;
514469
515− if (unlikely(off >= attr->size))
516− return 0;
517− if (unlikely(off < 0))
518− return -EINVAL;
519− if ((off + count) > attr->size)
520− count = attr->size - off;
521−
522470 off += NVRAM_OFFSET;
523471 spin_lock_irq(&rtc_lock);
524472 for (retval = 0; count; count--, off++, retval++) {
@@ -543,12 +491,6 @@ cmos_nvram_write(struct file *filp, struct kobject *kobj, · 18 unmodified lines
543491 int retval;
544492
545493 cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
546− if (unlikely(off >= attr->size))
547− return -EFBIG;
548− if (unlikely(off < 0))
549− return -EINVAL;
550− if ((off + count) > attr->size)
551− count = attr->size - off;
552494
553495 /* NOTE: on at least PCs and Ataris, the boot firmware uses a
554496 * checksum on part of the NVRAM data. That's currently ignored
@@ -860,6 +802,51 @@ static void __exit cmos_do_remove(struct device *dev) · 305 unmodified lines
860802 cmos->dev = NULL;
861803 }
862804
805+static int cmos_aie_poweroff(struct device *dev)
806+{
807+ struct cmos_rtc *cmos = dev_get_drvdata(dev);
808+ struct rtc_time now;
809+ time64_t t_now;
810+ int retval = 0;
811+ unsigned char rtc_control;
812+
813+ if (!cmos->alarm_expires)
814+ return -EINVAL;
815+
816+ spin_lock_irq(&rtc_lock);
817+ rtc_control = CMOS_READ(RTC_CONTROL);
818+ spin_unlock_irq(&rtc_lock);
819+
820+ /* We only care about the situation where AIE is disabled. */
821+ if (rtc_control & RTC_AIE)
822+ return -EBUSY;
823+
824+ cmos_read_time(dev, &now);
825+ t_now = rtc_tm_to_time64(&now);
826+
827+ /*
828+ * When enabling "RTC wake-up" in BIOS setup, the machine reboots
829+ * automatically right after shutdown on some buggy boxes.
830+ * This automatic rebooting issue won't happen when the alarm
831+ * time is larger than now+1 seconds.
832+ *
833+ * If the alarm time is equal to now+1 seconds, the issue can be
834+ * prevented by cancelling the alarm.
835+ */
836+ if (cmos->alarm_expires == t_now + 1) {
837+ struct rtc_wkalrm alarm;
838+
839+ /* Cancel the AIE timer by configuring the past time. */
840+ rtc_time64_to_tm(t_now - 1, &alarm.time);
841+ alarm.enabled = 0;
842+ retval = cmos_set_alarm(dev, &alarm);
843+ } else if (cmos->alarm_expires > t_now + 1) {
844+ retval = -EBUSY;
845+ }
846+
847+ return retval;
848+}
849+
863850 #ifdef CONFIG_PM
864851
865852 static int cmos_suspend(struct device *dev)
@@ -1094,8 +1081,12 @@ static void cmos_pnp_shutdown(struct pnp_dev *pnp) · 228 unmodified lines
10941081 struct device *dev = &pnp->dev;
10951082 struct cmos_rtc *cmos = dev_get_drvdata(dev);
10961083
1097− if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(dev))
1098− return;
1084+ if (system_state == SYSTEM_POWER_OFF) {
1085+ int retval = cmos_poweroff(dev);
1086+
1087+ if (cmos_aie_poweroff(dev) < 0 && !retval)
1088+ return;
1089+ }
10991090
11001091 cmos_do_shutdown(cmos->irq);
11011092 }
@@ -1200,8 +1191,12 @@ static void cmos_platform_shutdown(struct platform_device *pdev) · 98 unmodified lines
12001191 struct device *dev = &pdev->dev;
12011192 struct cmos_rtc *cmos = dev_get_drvdata(dev);
12021193
1203− if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(dev))
1204− return;
1194+ if (system_state == SYSTEM_POWER_OFF) {
1195+ int retval = cmos_poweroff(dev);
1196+
1197+ if (cmos_aie_poweroff(dev) < 0 && !retval)
1198+ return;
1199+ }
12051200
12061201 cmos_do_shutdown(cmos->irq);
12071202 }
@@ -1243,8 +1238,6 @@ static int __init cmos_init(void) · 35 unmodified lines
12431238 platform_driver_registered = true;
12441239 }
12451240
1246− dmi_check_system(rtc_quirks);
1247−
12481241 if (retval == 0)
12491242 return 0;
12501243
drivers/rtc/rtc-coh901331.c+1−0
@@ -263,6 +263,7 @@ static const struct of_device_id coh901331_dt_match[] = { · 262 unmodified lines
263263 { .compatible = "stericsson,coh901331" },
264264 {},
265265 };
266+MODULE_DEVICE_TABLE(of, coh901331_dt_match);
266267
267268 static struct platform_driver coh901331_driver = {
268269 .driver = {
drivers/rtc/rtc-core.h+3−16
@@ -48,23 +48,10 @@ static inline void rtc_proc_del_device(struct rtc_device *rtc) · 47 unmodified lines
4848 #endif
4949
5050 #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);
5652 #else
57−
58−static inline void rtc_sysfs_init(struct class *rtc)
59−{
60−}
61−
62−static inline void rtc_sysfs_add_device(struct rtc_device *rtc)
53+static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)
6354 {
55+ return NULL;
6456 }
65−
66−static inline void rtc_sysfs_del_device(struct rtc_device *rtc)
67−{
68−}
69−
7057 #endif
drivers/rtc/rtc-da9063.c+280−112
@@ -12,15 +12,18 @@ · 11 unmodified lines
1212 * Library General Public License for more details.
1313 */
1414
15+#include <linux/delay.h>
16+#include <linux/init.h>
17+#include <linux/interrupt.h>
1518 #include <linux/kernel.h>
1619 #include <linux/module.h>
17−#include <linux/init.h>
20+#include <linux/of.h>
1821 #include <linux/platform_device.h>
19−#include <linux/interrupt.h>
22+#include <linux/regmap.h>
2023 #include <linux/rtc.h>
2124 #include <linux/slab.h>
22−#include <linux/delay.h>
23−#include <linux/regmap.h>
25+
26+#include <linux/mfd/da9062/registers.h>
2427 #include <linux/mfd/da9063/registers.h>
2528 #include <linux/mfd/da9063/core.h>
2629
@@ -29,99 +32,231 @@ · 2 unmodified lines
2932 #define YEARS_FROM_DA9063(year) ((year) + 100)
3033 #define MONTHS_FROM_DA9063(month) ((month) - 1)
3134
32−#define RTC_ALARM_DATA_LEN (DA9063_AD_REG_ALARM_Y - DA9063_AD_REG_ALARM_MI + 1)
33−
34−#define RTC_DATA_LEN (DA9063_REG_COUNT_Y - DA9063_REG_COUNT_S + 1)
35−#define RTC_SEC 0
36−#define RTC_MIN 1
37−#define RTC_HOUR 2
38−#define RTC_DAY 3
39−#define RTC_MONTH 4
40−#define RTC_YEAR 5
41−
42−struct da9063_rtc {
43− struct rtc_device *rtc_dev;
44− struct da9063 *hw;
45− struct rtc_time alarm_time;
46− bool rtc_sync;
47− int alarm_year;
48− int alarm_start;
49− int alarm_len;
50− int data_start;
35+enum {
36+ RTC_SEC = 0,
37+ RTC_MIN = 1,
38+ RTC_HOUR = 2,
39+ RTC_DAY = 3,
40+ RTC_MONTH = 4,
41+ RTC_YEAR = 5,
42+ RTC_DATA_LEN
43+};
44+
45+struct da9063_compatible_rtc_regmap {
46+ /* REGS */
47+ int rtc_enable_reg;
48+ int rtc_enable_32k_crystal_reg;
49+ int rtc_alarm_secs_reg;
50+ int rtc_alarm_year_reg;
51+ int rtc_count_secs_reg;
52+ int rtc_count_year_reg;
53+ int rtc_event_reg;
54+ /* MASKS */
55+ int rtc_enable_mask;
56+ int rtc_crystal_mask;
57+ int rtc_event_alarm_mask;
58+ int rtc_alarm_on_mask;
59+ int rtc_alarm_status_mask;
60+ int rtc_tick_on_mask;
61+ int rtc_ready_to_read_mask;
62+ int rtc_count_sec_mask;
63+ int rtc_count_min_mask;
64+ int rtc_count_hour_mask;
65+ int rtc_count_day_mask;
66+ int rtc_count_month_mask;
67+ int rtc_count_year_mask;
68+ /* ALARM CONFIG */
69+ int rtc_data_start;
70+ int rtc_alarm_len;
71+};
72+
73+struct da9063_compatible_rtc {
74+ struct rtc_device *rtc_dev;
75+ struct rtc_time alarm_time;
76+ struct regmap *regmap;
77+ const struct da9063_compatible_rtc_regmap *config;
78+ bool rtc_sync;
79+};
80+
81+static const struct da9063_compatible_rtc_regmap da9063_ad_regs = {
82+ /* REGS */
83+ .rtc_enable_reg = DA9063_REG_CONTROL_E,
84+ .rtc_alarm_secs_reg = DA9063_AD_REG_ALARM_MI,
85+ .rtc_alarm_year_reg = DA9063_AD_REG_ALARM_Y,
86+ .rtc_count_secs_reg = DA9063_REG_COUNT_S,
87+ .rtc_count_year_reg = DA9063_REG_COUNT_Y,
88+ .rtc_event_reg = DA9063_REG_EVENT_A,
89+ /* MASKS */
90+ .rtc_enable_mask = DA9063_RTC_EN,
91+ .rtc_crystal_mask = DA9063_CRYSTAL,
92+ .rtc_enable_32k_crystal_reg = DA9063_REG_EN_32K,
93+ .rtc_event_alarm_mask = DA9063_E_ALARM,
94+ .rtc_alarm_on_mask = DA9063_ALARM_ON,
95+ .rtc_alarm_status_mask = DA9063_ALARM_STATUS_ALARM |
96+ DA9063_ALARM_STATUS_TICK,
97+ .rtc_tick_on_mask = DA9063_TICK_ON,
98+ .rtc_ready_to_read_mask = DA9063_RTC_READ,
99+ .rtc_count_sec_mask = DA9063_COUNT_SEC_MASK,
100+ .rtc_count_min_mask = DA9063_COUNT_MIN_MASK,
101+ .rtc_count_hour_mask = DA9063_COUNT_HOUR_MASK,
102+ .rtc_count_day_mask = DA9063_COUNT_DAY_MASK,
103+ .rtc_count_month_mask = DA9063_COUNT_MONTH_MASK,
104+ .rtc_count_year_mask = DA9063_COUNT_YEAR_MASK,
105+ /* ALARM CONFIG */
106+ .rtc_data_start = RTC_MIN,
107+ .rtc_alarm_len = RTC_DATA_LEN - 1,
108+};
109+
110+static const struct da9063_compatible_rtc_regmap da9063_bb_regs = {
111+ /* REGS */
112+ .rtc_enable_reg = DA9063_REG_CONTROL_E,
113+ .rtc_alarm_secs_reg = DA9063_BB_REG_ALARM_S,
114+ .rtc_alarm_year_reg = DA9063_BB_REG_ALARM_Y,
115+ .rtc_count_secs_reg = DA9063_REG_COUNT_S,
116+ .rtc_count_year_reg = DA9063_REG_COUNT_Y,
117+ .rtc_event_reg = DA9063_REG_EVENT_A,
118+ /* MASKS */
119+ .rtc_enable_mask = DA9063_RTC_EN,
120+ .rtc_crystal_mask = DA9063_CRYSTAL,
121+ .rtc_enable_32k_crystal_reg = DA9063_REG_EN_32K,
122+ .rtc_event_alarm_mask = DA9063_E_ALARM,
123+ .rtc_alarm_on_mask = DA9063_ALARM_ON,
124+ .rtc_alarm_status_mask = DA9063_ALARM_STATUS_ALARM |
125+ DA9063_ALARM_STATUS_TICK,
126+ .rtc_tick_on_mask = DA9063_TICK_ON,
127+ .rtc_ready_to_read_mask = DA9063_RTC_READ,
128+ .rtc_count_sec_mask = DA9063_COUNT_SEC_MASK,
129+ .rtc_count_min_mask = DA9063_COUNT_MIN_MASK,
130+ .rtc_count_hour_mask = DA9063_COUNT_HOUR_MASK,
131+ .rtc_count_day_mask = DA9063_COUNT_DAY_MASK,
132+ .rtc_count_month_mask = DA9063_COUNT_MONTH_MASK,
133+ .rtc_count_year_mask = DA9063_COUNT_YEAR_MASK,
134+ /* ALARM CONFIG */
135+ .rtc_data_start = RTC_SEC,
136+ .rtc_alarm_len = RTC_DATA_LEN,
137+};
138+
139+static const struct da9063_compatible_rtc_regmap da9062_aa_regs = {
140+ /* REGS */
141+ .rtc_enable_reg = DA9062AA_CONTROL_E,
142+ .rtc_alarm_secs_reg = DA9062AA_ALARM_S,
143+ .rtc_alarm_year_reg = DA9062AA_ALARM_Y,
144+ .rtc_count_secs_reg = DA9062AA_COUNT_S,
145+ .rtc_count_year_reg = DA9062AA_COUNT_Y,
146+ .rtc_event_reg = DA9062AA_EVENT_A,
147+ /* MASKS */
148+ .rtc_enable_mask = DA9062AA_RTC_EN_MASK,
149+ .rtc_crystal_mask = DA9062AA_CRYSTAL_MASK,
150+ .rtc_enable_32k_crystal_reg = DA9062AA_EN_32K,
151+ .rtc_event_alarm_mask = DA9062AA_M_ALARM_MASK,
152+ .rtc_alarm_on_mask = DA9062AA_ALARM_ON_MASK,
153+ .rtc_alarm_status_mask = (0x02 << 6),
154+ .rtc_tick_on_mask = DA9062AA_TICK_ON_MASK,
155+ .rtc_ready_to_read_mask = DA9062AA_RTC_READ_MASK,
156+ .rtc_count_sec_mask = DA9062AA_COUNT_SEC_MASK,
157+ .rtc_count_min_mask = DA9062AA_COUNT_MIN_MASK,
158+ .rtc_count_hour_mask = DA9062AA_COUNT_HOUR_MASK,
159+ .rtc_count_day_mask = DA9062AA_COUNT_DAY_MASK,
160+ .rtc_count_month_mask = DA9062AA_COUNT_MONTH_MASK,
161+ .rtc_count_year_mask = DA9062AA_COUNT_YEAR_MASK,
162+ /* ALARM CONFIG */
163+ .rtc_data_start = RTC_SEC,
164+ .rtc_alarm_len = RTC_DATA_LEN,
165+};
166+
167+static const struct of_device_id da9063_compatible_reg_id_table[] = {
168+ { .compatible = "dlg,da9063-rtc", .data = &da9063_bb_regs },
169+ { .compatible = "dlg,da9062-rtc", .data = &da9062_aa_regs },
170+ { },
51171 };
172+MODULE_DEVICE_TABLE(of, da9063_compatible_reg_id_table);
52173
53−static void da9063_data_to_tm(u8 *data, struct rtc_time *tm)
174+static void da9063_data_to_tm(u8 *data, struct rtc_time *tm,
175+ struct da9063_compatible_rtc *rtc)
54176 {
55− tm->tm_sec = data[RTC_SEC] & DA9063_COUNT_SEC_MASK;
56− tm->tm_min = data[RTC_MIN] & DA9063_COUNT_MIN_MASK;
57− tm->tm_hour = data[RTC_HOUR] & DA9063_COUNT_HOUR_MASK;
58− tm->tm_mday = data[RTC_DAY] & DA9063_COUNT_DAY_MASK;
177+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
178+
179+ tm->tm_sec = data[RTC_SEC] & config->rtc_count_sec_mask;
180+ tm->tm_min = data[RTC_MIN] & config->rtc_count_min_mask;
181+ tm->tm_hour = data[RTC_HOUR] & config->rtc_count_hour_mask;
182+ tm->tm_mday = data[RTC_DAY] & config->rtc_count_day_mask;
59183 tm->tm_mon = MONTHS_FROM_DA9063(data[RTC_MONTH] &
60− DA9063_COUNT_MONTH_MASK);
184+ config->rtc_count_month_mask);
61185 tm->tm_year = YEARS_FROM_DA9063(data[RTC_YEAR] &
62− DA9063_COUNT_YEAR_MASK);
186+ config->rtc_count_year_mask);
63187 }
64188
65−static void da9063_tm_to_data(struct rtc_time *tm, u8 *data)
189+static void da9063_tm_to_data(struct rtc_time *tm, u8 *data,
190+ struct da9063_compatible_rtc *rtc)
66191 {
67− data[RTC_SEC] &= ~DA9063_COUNT_SEC_MASK;
68− data[RTC_SEC] |= tm->tm_sec & DA9063_COUNT_SEC_MASK;
192+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
193+
194+ data[RTC_SEC] &= ~config->rtc_count_sec_mask;
195+ data[RTC_SEC] |= tm->tm_sec & config->rtc_count_sec_mask;
69196
70− data[RTC_MIN] &= ~DA9063_COUNT_MIN_MASK;
71− data[RTC_MIN] |= tm->tm_min & DA9063_COUNT_MIN_MASK;
197+ data[RTC_MIN] &= ~config->rtc_count_min_mask;
198+ data[RTC_MIN] |= tm->tm_min & config->rtc_count_min_mask;
72199
73− data[RTC_HOUR] &= ~DA9063_COUNT_HOUR_MASK;
74− data[RTC_HOUR] |= tm->tm_hour & DA9063_COUNT_HOUR_MASK;
200+ data[RTC_HOUR] &= ~config->rtc_count_hour_mask;
201+ data[RTC_HOUR] |= tm->tm_hour & config->rtc_count_hour_mask;
75202
76− data[RTC_DAY] &= ~DA9063_COUNT_DAY_MASK;
77− data[RTC_DAY] |= tm->tm_mday & DA9063_COUNT_DAY_MASK;
203+ data[RTC_DAY] &= ~config->rtc_count_day_mask;
204+ data[RTC_DAY] |= tm->tm_mday & config->rtc_count_day_mask;
78205
79− data[RTC_MONTH] &= ~DA9063_COUNT_MONTH_MASK;
206+ data[RTC_MONTH] &= ~config->rtc_count_month_mask;
80207 data[RTC_MONTH] |= MONTHS_TO_DA9063(tm->tm_mon) &
81− DA9063_COUNT_MONTH_MASK;
208+ config->rtc_count_month_mask;
82209
83− data[RTC_YEAR] &= ~DA9063_COUNT_YEAR_MASK;
210+ data[RTC_YEAR] &= ~config->rtc_count_year_mask;
84211 data[RTC_YEAR] |= YEARS_TO_DA9063(tm->tm_year) &
85− DA9063_COUNT_YEAR_MASK;
212+ config->rtc_count_year_mask;
86213 }
87214
88215 static int da9063_rtc_stop_alarm(struct device *dev)
89216 {
90− struct da9063_rtc *rtc = dev_get_drvdata(dev);
217+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
218+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
91219
92− return regmap_update_bits(rtc->hw->regmap, rtc->alarm_year,
93− DA9063_ALARM_ON, 0);
220+ return regmap_update_bits(rtc->regmap,
221+ config->rtc_alarm_year_reg,
222+ config->rtc_alarm_on_mask,
223+ 0);
94224 }
95225
96226 static int da9063_rtc_start_alarm(struct device *dev)
97227 {
98− struct da9063_rtc *rtc = dev_get_drvdata(dev);
228+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
229+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
99230
100− return regmap_update_bits(rtc->hw->regmap, rtc->alarm_year,
101− DA9063_ALARM_ON, DA9063_ALARM_ON);
231+ return regmap_update_bits(rtc->regmap,
232+ config->rtc_alarm_year_reg,
233+ config->rtc_alarm_on_mask,
234+ config->rtc_alarm_on_mask);
102235 }
103236
104237 static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm)
105238 {
106− struct da9063_rtc *rtc = dev_get_drvdata(dev);
239+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
240+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
107241 unsigned long tm_secs;
108242 unsigned long al_secs;
109243 u8 data[RTC_DATA_LEN];
110244 int ret;
111245
112− ret = regmap_bulk_read(rtc->hw->regmap, DA9063_REG_COUNT_S,
246+ ret = regmap_bulk_read(rtc->regmap,
247+ config->rtc_count_secs_reg,
113248 data, RTC_DATA_LEN);
114249 if (ret < 0) {
115250 dev_err(dev, "Failed to read RTC time data: %d\n", ret);
116251 return ret;
117252 }
118253
119− if (!(data[RTC_SEC] & DA9063_RTC_READ)) {
254+ if (!(data[RTC_SEC] & config->rtc_ready_to_read_mask)) {
120255 dev_dbg(dev, "RTC not yet ready to be read by the host\n");
121256 return -EINVAL;
122257 }
123258
124− da9063_data_to_tm(data, tm);
259+ da9063_data_to_tm(data, tm, rtc);
125260
126261 rtc_tm_to_time(tm, &tm_secs);
127262 rtc_tm_to_time(&rtc->alarm_time, &al_secs);
@@ -137,12 +272,14 @@ static int da9063_rtc_read_time(struct device *dev, struct rtc_time *tm) · 9 unmodified lines
137272
138273 static int da9063_rtc_set_time(struct device *dev, struct rtc_time *tm)
139274 {
140− struct da9063_rtc *rtc = dev_get_drvdata(dev);
275+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
276+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
141277 u8 data[RTC_DATA_LEN];
142278 int ret;
143279
144− da9063_tm_to_data(tm, data);
145− ret = regmap_bulk_write(rtc->hw->regmap, DA9063_REG_COUNT_S,
280+ da9063_tm_to_data(tm, data, rtc);
281+ ret = regmap_bulk_write(rtc->regmap,
282+ config->rtc_count_secs_reg,
146283 data, RTC_DATA_LEN);
147284 if (ret < 0)
148285 dev_err(dev, "Failed to set RTC time data: %d\n", ret);
@@ -152,26 +289,31 @@ static int da9063_rtc_set_time(struct device *dev, struct rtc_time *tm) · 3 unmodified lines
152289
153290 static int da9063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
154291 {
155− struct da9063_rtc *rtc = dev_get_drvdata(dev);
292+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
293+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
156294 u8 data[RTC_DATA_LEN];
157295 int ret;
158296 unsigned int val;
159297
160298 data[RTC_SEC] = 0;
161− ret = regmap_bulk_read(rtc->hw->regmap, rtc->alarm_start,
162− &data[rtc->data_start], rtc->alarm_len);
299+ ret = regmap_bulk_read(rtc->regmap,
300+ config->rtc_alarm_secs_reg,
301+ &data[config->rtc_data_start],
302+ config->rtc_alarm_len);
163303 if (ret < 0)
164304 return ret;
165305
166− da9063_data_to_tm(data, &alrm->time);
306+ da9063_data_to_tm(data, &alrm->time, rtc);
167307
168− alrm->enabled = !!(data[RTC_YEAR] & DA9063_ALARM_ON);
308+ alrm->enabled = !!(data[RTC_YEAR] & config->rtc_alarm_on_mask);
169309
170− ret = regmap_read(rtc->hw->regmap, DA9063_REG_EVENT_A, &val);
310+ ret = regmap_read(rtc->regmap,
311+ config->rtc_event_reg,
312+ &val);
171313 if (ret < 0)
172314 return ret;
173315
174− if (val & (DA9063_E_ALARM))
316+ if (val & config->rtc_event_alarm_mask)
175317 alrm->pending = 1;
176318 else
177319 alrm->pending = 0;
@@ -181,11 +323,12 @@ static int da9063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 3 unmodified lines
181323
182324 static int da9063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
183325 {
184− struct da9063_rtc *rtc = dev_get_drvdata(dev);
326+ struct da9063_compatible_rtc *rtc = dev_get_drvdata(dev);
327+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
185328 u8 data[RTC_DATA_LEN];
186329 int ret;
187330
188− da9063_tm_to_data(&alrm->time, data);
331+ da9063_tm_to_data(&alrm->time, data, rtc);
189332
190333 ret = da9063_rtc_stop_alarm(dev);
191334 if (ret < 0) {
@@ -193,14 +336,16 @@ static int da9063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 1 unmodified line
193336 return ret;
194337 }
195338
196− ret = regmap_bulk_write(rtc->hw->regmap, rtc->alarm_start,
197− &data[rtc->data_start], rtc->alarm_len);
339+ ret = regmap_bulk_write(rtc->regmap,
340+ config->rtc_alarm_secs_reg,
341+ &data[config->rtc_data_start],
342+ config->rtc_alarm_len);
198343 if (ret < 0) {
199344 dev_err(dev, "Failed to write alarm: %d\n", ret);
200345 return ret;
201346 }
202347
203− da9063_data_to_tm(data, &rtc->alarm_time);
348+ da9063_data_to_tm(data, &rtc->alarm_time, rtc);
204349
205350 if (alrm->enabled) {
206351 ret = da9063_rtc_start_alarm(dev);
@@ -213,7 +358,8 @@ static int da9063_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 6 unmodified lines
213358 return ret;
214359 }
215360
216−static int da9063_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
361+static int da9063_rtc_alarm_irq_enable(struct device *dev,
362+ unsigned int enabled)
217363 {
218364 if (enabled)
219365 return da9063_rtc_start_alarm(dev);
@@ -223,10 +369,13 @@ static int da9063_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) · 3 unmodified lines
223369
224370 static irqreturn_t da9063_alarm_event(int irq, void *data)
225371 {
226− struct da9063_rtc *rtc = data;
372+ struct da9063_compatible_rtc *rtc = data;
373+ const struct da9063_compatible_rtc_regmap *config = rtc->config;
227374
228− regmap_update_bits(rtc->hw->regmap, rtc->alarm_year,
229− DA9063_ALARM_ON, 0);
375+ regmap_update_bits(rtc->regmap,
376+ config->rtc_alarm_year_reg,
377+ config->rtc_alarm_on_mask,
378+ 0);
230379
231380 rtc->rtc_sync = true;
232381 rtc_update_irq(rtc->rtc_dev, 1, RTC_IRQF | RTC_AF);
@@ -244,72 +393,92 @@ static const struct rtc_class_ops da9063_rtc_ops = { · 11 unmodified lines
244393
245394 static int da9063_rtc_probe(struct platform_device *pdev)
246395 {
247− struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
248− struct da9063_rtc *rtc;
396+ struct da9063_compatible_rtc *rtc;
397+ const struct da9063_compatible_rtc_regmap *config;
398+ const struct of_device_id *match;
249399 int irq_alarm;
250400 u8 data[RTC_DATA_LEN];
251401 int ret;
252402
253− ret = regmap_update_bits(da9063->regmap, DA9063_REG_CONTROL_E,
254− DA9063_RTC_EN, DA9063_RTC_EN);
255− if (ret < 0) {
256− dev_err(&pdev->dev, "Failed to enable RTC\n");
257− goto err;
258− }
403+ if (!pdev->dev.of_node)
404+ return -ENXIO;
259405
260− ret = regmap_update_bits(da9063->regmap, DA9063_REG_EN_32K,
261− DA9063_CRYSTAL, DA9063_CRYSTAL);
262− if (ret < 0) {
263− dev_err(&pdev->dev, "Failed to run 32kHz oscillator\n");
264− goto err;
265− }
406+ match = of_match_node(da9063_compatible_reg_id_table,
407+ pdev->dev.of_node);
266408
267409 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
268410 if (!rtc)
269411 return -ENOMEM;
270412
271− if (da9063->variant_code == PMIC_DA9063_AD) {
272− rtc->alarm_year = DA9063_AD_REG_ALARM_Y;
273− rtc->alarm_start = DA9063_AD_REG_ALARM_MI;
274− rtc->alarm_len = RTC_ALARM_DATA_LEN;
275− rtc->data_start = RTC_MIN;
276− } else {
277− rtc->alarm_year = DA9063_BB_REG_ALARM_Y;
278− rtc->alarm_start = DA9063_BB_REG_ALARM_S;
279− rtc->alarm_len = RTC_DATA_LEN;
280− rtc->data_start = RTC_SEC;
413+ rtc->config = match->data;
414+ if (of_device_is_compatible(pdev->dev.of_node, "dlg,da9063-rtc")) {
415+ struct da9063 *chip = dev_get_drvdata(pdev->dev.parent);
416+
417+ if (chip->variant_code == PMIC_DA9063_AD)
418+ rtc->config = &da9063_ad_regs;
281419 }
282420
283− ret = regmap_update_bits(da9063->regmap, rtc->alarm_start,
284− DA9063_ALARM_STATUS_TICK | DA9063_ALARM_STATUS_ALARM,
285− 0);
421+ rtc->regmap = dev_get_regmap(pdev->dev.parent, NULL);
422+ if (!rtc->regmap) {
423+ dev_warn(&pdev->dev, "Parent regmap unavailable.\n");
424+ return -ENXIO;
425+ }
426+
427+ config = rtc->config;
428+ ret = regmap_update_bits(rtc->regmap,
429+ config->rtc_enable_reg,
430+ config->rtc_enable_mask,
431+ config->rtc_enable_mask);
432+ if (ret < 0) {
433+ dev_err(&pdev->dev, "Failed to enable RTC\n");
434+ return ret;
435+ }
436+
437+ ret = regmap_update_bits(rtc->regmap,
438+ config->rtc_enable_32k_crystal_reg,
439+ config->rtc_crystal_mask,
440+ config->rtc_crystal_mask);
441+ if (ret < 0) {
442+ dev_err(&pdev->dev, "Failed to run 32kHz oscillator\n");
443+ return ret;
444+ }
445+
446+ ret = regmap_update_bits(rtc->regmap,
447+ config->rtc_alarm_secs_reg,
448+ config->rtc_alarm_status_mask,
449+ 0);
286450 if (ret < 0) {
287451 dev_err(&pdev->dev, "Failed to access RTC alarm register\n");
288− goto err;
452+ return ret;
289453 }
290454
291− ret = regmap_update_bits(da9063->regmap, rtc->alarm_start,
455+ ret = regmap_update_bits(rtc->regmap,
456+ config->rtc_alarm_secs_reg,
292457 DA9063_ALARM_STATUS_ALARM,
293458 DA9063_ALARM_STATUS_ALARM);
294459 if (ret < 0) {
295460 dev_err(&pdev->dev, "Failed to access RTC alarm register\n");
296− goto err;
461+ return ret;
297462 }
298463
299− ret = regmap_update_bits(da9063->regmap, rtc->alarm_year,
300− DA9063_TICK_ON, 0);
464+ ret = regmap_update_bits(rtc->regmap,
465+ config->rtc_alarm_year_reg,
466+ config->rtc_tick_on_mask,
467+ 0);
301468 if (ret < 0) {
302469 dev_err(&pdev->dev, "Failed to disable TICKs\n");
303− goto err;
470+ return ret;
304471 }
305472
306473 data[RTC_SEC] = 0;
307− ret = regmap_bulk_read(da9063->regmap, rtc->alarm_start,
308− &data[rtc->data_start], rtc->alarm_len);
474+ ret = regmap_bulk_read(rtc->regmap,
475+ config->rtc_alarm_secs_reg,
476+ &data[config->rtc_data_start],
477+ config->rtc_alarm_len);
309478 if (ret < 0) {
310479 dev_err(&pdev->dev, "Failed to read initial alarm data: %d\n",
311480 ret);
312− goto err;
481+ return ret;
313482 }
314483
315484 platform_set_drvdata(pdev, rtc);
@@ -322,18 +491,16 @@ static int da9063_rtc_probe(struct platform_device *pdev) · 6 unmodified lines
322491 if (ret) {
323492 dev_err(&pdev->dev, "Failed to request ALARM IRQ %d: %d\n",
324493 irq_alarm, ret);
325− goto err;
494+ return ret;
326495 }
327496
328− rtc->hw = da9063;
329497 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, DA9063_DRVNAME_RTC,
330498 &da9063_rtc_ops, THIS_MODULE);
331499 if (IS_ERR(rtc->rtc_dev))
332500 return PTR_ERR(rtc->rtc_dev);
333501
334− da9063_data_to_tm(data, &rtc->alarm_time);
502+ da9063_data_to_tm(data, &rtc->alarm_time, rtc);
335503 rtc->rtc_sync = false;
336−err:
337504 return ret;
338505 }
339506
@@ -341,6 +508,7 @@ static struct platform_driver da9063_rtc_driver = { · 1 unmodified line
341508 .probe = da9063_rtc_probe,
342509 .driver = {
343510 .name = DA9063_DRVNAME_RTC,
511+ .of_match_table = da9063_compatible_reg_id_table,
344512 },
345513 };
346514
drivers/rtc/rtc-dev.c+1−0
@@ -477,6 +477,7 @@ void rtc_dev_prepare(struct rtc_device *rtc) · 476 unmodified lines
477477
478478 cdev_init(&rtc->char_dev, &rtc_dev_fops);
479479 rtc->char_dev.owner = rtc->owner;
480+ rtc->char_dev.kobj.parent = &rtc->dev.kobj;
480481 }
481482
482483 void rtc_dev_add_device(struct rtc_device *rtc)
drivers/rtc/rtc-ds1305.c+0−18
@@ -538,15 +538,6 @@ ds1305_nvram_read(struct file *filp, struct kobject *kobj, · 537 unmodified lines
538538
539539 spi = container_of(kobj, struct spi_device, dev.kobj);
540540
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−
550541 addr = DS1305_NVRAM + off;
551542 msg_init(&m, x, &addr, count, NULL, buf);
552543
@@ -569,15 +560,6 @@ ds1305_nvram_write(struct file *filp, struct kobject *kobj, · 16 unmodified lines
569560
570561 spi = container_of(kobj, struct spi_device, dev.kobj);
571562
572− if (unlikely(off >= DS1305_NVRAM_LEN))
573− return -EFBIG;
574− if (count >= DS1305_NVRAM_LEN)
575− count = DS1305_NVRAM_LEN;
576− if ((off + count) > DS1305_NVRAM_LEN)
577− count = DS1305_NVRAM_LEN - off;
578− if (unlikely(!count))
579− return count;
580−
581563 addr = (DS1305_WRITE | DS1305_NVRAM) + off;
582564 msg_init(&m, x, &addr, count, buf, NULL);
583565
drivers/rtc/rtc-ds1307.c+56−64
@@ -11,14 +11,17 @@ · 10 unmodified lines
1111 * published by the Free Software Foundation.
1212 */
1313
14−#include <linux/module.h>
14+#include <linux/bcd.h>
15+#include <linux/i2c.h>
1516 #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+#include <linux/rtc/ds1307.h>
22+#include <linux/rtc.h>
1623 #include <linux/slab.h>
17−#include <linux/i2c.h>
1824 #include <linux/string.h>
19−#include <linux/rtc.h>
20−#include <linux/bcd.h>
21−#include <linux/rtc/ds1307.h>
2225
2326 /*
2427 * We can't determine type by probing, but if we expect pre-Linux code
@@ -114,7 +117,7 @@ struct ds1307 { · 89 unmodified lines
114117 #define HAS_ALARM 1 /* bit 1 == irq claimed */
115118 struct i2c_client *client;
116119 struct rtc_device *rtc;
117− struct work_struct work;
120+ int wakeirq;
118121 s32 (*read_block_data)(const struct i2c_client *client, u8 command,
119122 u8 length, u8 *values);
120123 s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -311,27 +314,17 @@ static s32 ds1307_native_smbus_read_block_data(const struct i2c_client *client, · 190 unmodified lines
311314 /*----------------------------------------------------------------------*/
312315
313316 /*
314− * The IRQ logic includes a "real" handler running in IRQ context just
315− * long enough to schedule this workqueue entry. We need a task context
316− * to talk to the RTC, since I2C I/O calls require that; and disable the
317− * IRQ until we clear its status on the chip, so that this handler can
318− * work with any type of triggering (not just falling edge).
319− *
320317 * The ds1337 and ds1339 both have two alarms, but we only use the first
321318 * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm
322319 * signal; ds1339 chips have only one alarm signal.
323320 */
324−static void ds1307_work(struct work_struct *work)
321+static irqreturn_t ds1307_irq(int irq, void *dev_id)
325322 {
326− struct ds1307 *ds1307;
327− struct i2c_client *client;
328− struct mutex *lock;
323+ struct i2c_client *client = dev_id;
324+ struct ds1307 *ds1307 = i2c_get_clientdata(client);
325+ struct mutex *lock = &ds1307->rtc->ops_lock;
329326 int stat, control;
330327
331− ds1307 = container_of(work, struct ds1307, work);
332− client = ds1307->client;
333− lock = &ds1307->rtc->ops_lock;
334−
335328 mutex_lock(lock);
336329 stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
337330 if (stat < 0)
@@ -352,18 +345,8 @@ static void ds1307_work(struct work_struct *work) · 14 unmodified lines
352345 }
353346
354347 out:
355− if (test_bit(HAS_ALARM, &ds1307->flags))
356− enable_irq(client->irq);
357348 mutex_unlock(lock);
358−}
359349
360−static irqreturn_t ds1307_irq(int irq, void *dev_id)
361−{
362− struct i2c_client *client = dev_id;
363− struct ds1307 *ds1307 = i2c_get_clientdata(client);
364−
365− disable_irq_nosync(irq);
366− schedule_work(&ds1307->work);
367350 return IRQ_HANDLED;
368351 }
369352
@@ -634,13 +617,14 @@ static const struct rtc_class_ops ds13xx_rtc_ops = { · 264 unmodified lines
634617 MCP794XX_BIT_ALMX_C1 | \
635618 MCP794XX_BIT_ALMX_C2)
636619
637−static void mcp794xx_work(struct work_struct *work)
620+static irqreturn_t mcp794xx_irq(int irq, void *dev_id)
638621 {
639− struct ds1307 *ds1307 = container_of(work, struct ds1307, work);
640− struct i2c_client *client = ds1307->client;
622+ struct i2c_client *client = dev_id;
623+ struct ds1307 *ds1307 = i2c_get_clientdata(client);
624+ struct mutex *lock = &ds1307->rtc->ops_lock;
641625 int reg, ret;
642626
643− mutex_lock(&ds1307->rtc->ops_lock);
627+ mutex_lock(lock);
644628
645629 /* Check and clear alarm 0 interrupt flag. */
646630 reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_ALARM0_CTRL);
@@ -665,9 +649,9 @@ static void mcp794xx_work(struct work_struct *work) · 18 unmodified lines
665649 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
666650
667651 out:
668− if (test_bit(HAS_ALARM, &ds1307->flags))
669− enable_irq(client->irq);
670− mutex_unlock(&ds1307->rtc->ops_lock);
652+ mutex_unlock(lock);
653+
654+ return IRQ_HANDLED;
671655 }
672656
673657 static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t)
@@ -798,13 +782,6 @@ ds1307_nvram_read(struct file *filp, struct kobject *kobj, · 124 unmodified lines
798782 client = kobj_to_i2c_client(kobj);
799783 ds1307 = i2c_get_clientdata(client);
800784
801− if (unlikely(off >= ds1307->nvram->size))
802− return 0;
803− if ((off + count) > ds1307->nvram->size)
804− count = ds1307->nvram->size - off;
805− if (unlikely(!count))
806− return count;
807−
808785 result = ds1307->read_block_data(client, ds1307->nvram_offset + off,
809786 count, buf);
810787 if (result < 0)
@@ -824,13 +801,6 @@ ds1307_nvram_write(struct file *filp, struct kobject *kobj, · 13 unmodified lines
824801 client = kobj_to_i2c_client(kobj);
825802 ds1307 = i2c_get_clientdata(client);
826803
827− if (unlikely(off >= ds1307->nvram->size))
828− return -EFBIG;
829− if ((off + count) > ds1307->nvram->size)
830− count = ds1307->nvram->size - off;
831− if (unlikely(!count))
832− return count;
833−
834804 result = ds1307->write_block_data(client, ds1307->nvram_offset + off,
835805 count, buf);
836806 if (result < 0) {
@@ -896,6 +866,8 @@ static int ds1307_probe(struct i2c_client *client, · 59 unmodified lines
896866 bool want_irq = false;
897867 unsigned char *buf;
898868 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
869+ irq_handler_t irq_handler = ds1307_irq;
870+
899871 static const int bbsqi_bitpos[] = {
900872 [ds_1337] = 0,
901873 [ds_1339] = DS1339_BIT_BBSQI,
@@ -962,8 +934,6 @@ static int ds1307_probe(struct i2c_client *client, · 60 unmodified lines
962934 * running on Vbackup (BBSQI/BBSQW)
963935 */
964936 if (ds1307->client->irq > 0 && chip->alarm) {
965− INIT_WORK(&ds1307->work, ds1307_work);
966−
967937 ds1307->regs[0] |= DS1337_BIT_INTCN
968938 | bbsqi_bitpos[ds1307->type];
969939 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
@@ -1053,7 +1023,7 @@ static int ds1307_probe(struct i2c_client *client, · 83 unmodified lines
10531023 case mcp794xx:
10541024 rtc_ops = &mcp794xx_rtc_ops;
10551025 if (ds1307->client->irq > 0 && chip->alarm) {
1056− INIT_WORK(&ds1307->work, mcp794xx_work);
1026+ irq_handler = mcp794xx_irq;
10571027 want_irq = true;
10581028 }
10591029 break;
@@ -1176,18 +1146,43 @@ read_rtc: · 116 unmodified lines
11761146 }
11771147
11781148 if (want_irq) {
1179− err = request_irq(client->irq, ds1307_irq, IRQF_SHARED,
1180− ds1307->rtc->name, client);
1149+ struct device_node *node = client->dev.of_node;
1150+
1151+ err = devm_request_threaded_irq(&client->dev,
1152+ client->irq, NULL, irq_handler,
1153+ IRQF_SHARED | IRQF_ONESHOT,
1154+ ds1307->rtc->name, client);
11811155 if (err) {
11821156 client->irq = 0;
11831157 dev_err(&client->dev, "unable to request IRQ!\n");
1184− } else {
1158+ goto no_irq;
1159+ }
1160+
1161+ set_bit(HAS_ALARM, &ds1307->flags);
1162+ dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
1163+
1164+ /* Currently supported by OF code only! */
1165+ if (!node)
1166+ goto no_irq;
1167+
1168+ err = of_irq_get(node, 1);
1169+ if (err <= 0) {
1170+ if (err == -EPROBE_DEFER)
1171+ goto exit;
1172+ goto no_irq;
1173+ }
1174+ ds1307->wakeirq = err;
11851175
1186− set_bit(HAS_ALARM, &ds1307->flags);
1187− dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
1176+ err = dev_pm_set_dedicated_wake_irq(&client->dev,
1177+ ds1307->wakeirq);
1178+ if (err) {
1179+ dev_err(&client->dev, "unable to setup wakeIRQ %d!\n",
1180+ err);
1181+ goto exit;
11881182 }
11891183 }
11901184
1185+no_irq:
11911186 if (chip->nvram_size) {
11921187
11931188 ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1231,10 +1226,8 @@ static int ds1307_remove(struct i2c_client *client) · 37 unmodified lines
12311226 {
12321227 struct ds1307 *ds1307 = i2c_get_clientdata(client);
12331228
1234− if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) {
1235− free_irq(client->irq, client);
1236− cancel_work_sync(&ds1307->work);
1237− }
1229+ if (ds1307->wakeirq)
1230+ dev_pm_clear_wake_irq(&client->dev);
12381231
12391232 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
12401233 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
@@ -1245,7 +1238,6 @@ static int ds1307_remove(struct i2c_client *client) · 4 unmodified lines
12451238 static struct i2c_driver ds1307_driver = {
12461239 .driver = {
12471240 .name = "rtc-ds1307",
1248− .owner = THIS_MODULE,
12491241 },
12501242 .probe = ds1307_probe,
12511243 .remove = ds1307_remove,
drivers/rtc/rtc-ds1343.c+0−12
@@ -162,12 +162,6 @@ static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj, · 161 unmodified lines
162162 struct device *dev = kobj_to_dev(kobj);
163163 struct ds1343_priv *priv = dev_get_drvdata(dev);
164164
165− if (unlikely(!count))
166− return count;
167−
168− if ((count + off) > DS1343_NVRAM_LEN)
169− count = DS1343_NVRAM_LEN - off;
170−
171165 address = DS1343_NVRAM + off;
172166
173167 ret = regmap_bulk_write(priv->map, address, buf, count);
@@ -187,12 +181,6 @@ static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj, · 13 unmodified lines
187181 struct device *dev = kobj_to_dev(kobj);
188182 struct ds1343_priv *priv = dev_get_drvdata(dev);
189183
190− if (unlikely(!count))
191− return count;
192−
193− if ((count + off) > DS1343_NVRAM_LEN)
194− count = DS1343_NVRAM_LEN - off;
195−
196184 address = DS1343_NVRAM + off;
197185
198186 ret = regmap_bulk_read(priv->map, address, buf, count);
drivers/rtc/rtc-ds1374.c+2−5
@@ -664,8 +664,6 @@ static int ds1374_remove(struct i2c_client *client) · 663 unmodified lines
664664 {
665665 struct ds1374 *ds1374 = i2c_get_clientdata(client);
666666 #ifdef CONFIG_RTC_DRV_DS1374_WDT
667− int res;
668−
669667 misc_deregister(&ds1374_miscdev);
670668 ds1374_miscdev.parent = NULL;
671669 unregister_reboot_notifier(&ds1374_wdt_notifier);
@@ -688,7 +686,7 @@ static int ds1374_suspend(struct device *dev) · 16 unmodified lines
688686 {
689687 struct i2c_client *client = to_i2c_client(dev);
690688
691− if (client->irq >= 0 && device_may_wakeup(&client->dev))
689+ if (client->irq > 0 && device_may_wakeup(&client->dev))
692690 enable_irq_wake(client->irq);
693691 return 0;
694692 }
@@ -697,7 +695,7 @@ static int ds1374_resume(struct device *dev) · 2 unmodified lines
697695 {
698696 struct i2c_client *client = to_i2c_client(dev);
699697
700− if (client->irq >= 0 && device_may_wakeup(&client->dev))
698+ if (client->irq > 0 && device_may_wakeup(&client->dev))
701699 disable_irq_wake(client->irq);
702700 return 0;
703701 }
@@ -708,7 +706,6 @@ static SIMPLE_DEV_PM_OPS(ds1374_pm, ds1374_suspend, ds1374_resume); · 4 unmodified lines
708706 static struct i2c_driver ds1374_driver = {
709707 .driver = {
710708 .name = "rtc-ds1374",
711− .owner = THIS_MODULE,
712709 .pm = &ds1374_pm,
713710 },
714711 .probe = ds1374_probe,
drivers/rtc/rtc-ds1511.c+5−37
@@ -64,7 +64,7 @@ enum ds1511reg { · 63 unmodified lines
6464 #define DS1511_KIE 0x04
6565 #define DS1511_WDE 0x02
6666 #define DS1511_WDS 0x01
67−#define DS1511_RAM_MAX 0xff
67+#define DS1511_RAM_MAX 0x100
6868
6969 #define RTC_CMD DS1511_CONTROL_B
7070 #define RTC_CMD1 DS1511_CONTROL_A
@@ -159,7 +159,7 @@ ds1511_wdog_set(unsigned long deciseconds) · 88 unmodified lines
159159 /*
160160 * set wdog enable and wdog 'steering' bit to issue a reset
161161 */
162− rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD);
162+ rtc_write(rtc_read(RTC_CMD) | DS1511_WDE | DS1511_WDS, RTC_CMD);
163163 }
164164
165165 void
@@ -407,26 +407,10 @@ ds1511_nvram_read(struct file *filp, struct kobject *kobj, · 241 unmodified lines
407407 {
408408 ssize_t count;
409409
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−
423410 rtc_write(pos, DS1511_RAMADDR_LSB);
424− for (count = 0; size > 0; count++, size--)
411+ for (count = 0; count < size; count++)
425412 *buf++ = rtc_read(DS1511_RAMDATA);
426413
427− if (count > 1)
428− rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
429−
430414 return count;
431415 }
432416
@@ -437,26 +421,10 @@ ds1511_nvram_write(struct file *filp, struct kobject *kobj, · 4 unmodified lines
437421 {
438422 ssize_t count;
439423
440− /*
441− * if count is more than one, turn on "burst" mode
442− * turn it off when you're done
443− */
444− if (size > 1)
445− rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD);
446−
447− if (pos > DS1511_RAM_MAX)
448− pos = DS1511_RAM_MAX;
449−
450− if (size + pos > DS1511_RAM_MAX + 1)
451− size = DS1511_RAM_MAX - pos + 1;
452−
453424 rtc_write(pos, DS1511_RAMADDR_LSB);
454− for (count = 0; size > 0; count++, size--)
425+ for (count = 0; count < size; count++)
455426 rtc_write(*buf++, DS1511_RAMDATA);
456427
457− if (count > 1)
458− rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
459−
460428 return count;
461429 }
462430
@@ -490,7 +458,7 @@ static int ds1511_rtc_probe(struct platform_device *pdev) · 27 unmodified lines
490458 /*
491459 * turn on the clock and the crystal, etc.
492460 */
493− rtc_write(0, RTC_CMD);
461+ rtc_write(DS1511_BME, RTC_CMD);
494462 rtc_write(0, RTC_CMD1);
495463 /*
496464 * clear the wdog counter
drivers/rtc/rtc-ds1553.c+2−2
@@ -245,7 +245,7 @@ static ssize_t ds1553_nvram_read(struct file *filp, struct kobject *kobj, · 244 unmodified lines
245245 void __iomem *ioaddr = pdata->ioaddr;
246246 ssize_t count;
247247
248− for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
248+ for (count = 0; count < size; count++)
249249 *buf++ = readb(ioaddr + pos++);
250250 return count;
251251 }
@@ -260,7 +260,7 @@ static ssize_t ds1553_nvram_write(struct file *filp, struct kobject *kobj, · 8 unmodified lines
260260 void __iomem *ioaddr = pdata->ioaddr;
261261 ssize_t count;
262262
263− for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
263+ for (count = 0; count < size; count++)
264264 writeb(*buf++, ioaddr + pos++);
265265 return count;
266266 }
drivers/rtc/rtc-ds1685.c+1−21
@@ -2145,27 +2145,7 @@ static struct platform_driver ds1685_rtc_driver = { · 2144 unmodified lines
21452145 .probe = ds1685_rtc_probe,
21462146 .remove = ds1685_rtc_remove,
21472147 };
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);
21692149 /* ----------------------------------------------------------------------- */
21702150
21712151
drivers/rtc/rtc-ds1742.c+2−2
@@ -134,7 +134,7 @@ static ssize_t ds1742_nvram_read(struct file *filp, struct kobject *kobj, · 133 unmodified lines
134134 void __iomem *ioaddr = pdata->ioaddr_nvram;
135135 ssize_t count;
136136
137− for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--)
137+ for (count = 0; count < size; count++)
138138 *buf++ = readb(ioaddr + pos++);
139139 return count;
140140 }
@@ -149,7 +149,7 @@ static ssize_t ds1742_nvram_write(struct file *filp, struct kobject *kobj, · 8 unmodified lines
149149 void __iomem *ioaddr = pdata->ioaddr_nvram;
150150 ssize_t count;
151151
152− for (count = 0; size > 0 && pos < pdata->size_nvram; count++, size--)
152+ for (count = 0; count < size; count++)
153153 writeb(*buf++, ioaddr + pos++);
154154 return count;
155155 }
drivers/rtc/rtc-ds3232.c+5−3
@@ -443,7 +443,7 @@ static int ds3232_remove(struct i2c_client *client) · 442 unmodified lines
443443 {
444444 struct ds3232 *ds3232 = i2c_get_clientdata(client);
445445
446− if (client->irq >= 0) {
446+ if (client->irq > 0) {
447447 mutex_lock(&ds3232->mutex);
448448 ds3232->exiting = 1;
449449 mutex_unlock(&ds3232->mutex);
@@ -463,7 +463,10 @@ static int ds3232_suspend(struct device *dev) · 13 unmodified lines
463463
464464 if (device_can_wakeup(dev)) {
465465 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+ }
467470 }
468471
469472 return 0;
@@ -500,7 +503,6 @@ MODULE_DEVICE_TABLE(i2c, ds3232_id); · 30 unmodified lines
500503 static struct i2c_driver ds3232_driver = {
501504 .driver = {
502505 .name = "rtc-ds3232",
503− .owner = THIS_MODULE,
504506 .pm = &ds3232_pm_ops,
505507 },
506508 .probe = ds3232_probe,
drivers/rtc/rtc-fm3130.c+0−1
@@ -523,7 +523,6 @@ exit_free: · 522 unmodified lines
523523 static struct i2c_driver fm3130_driver = {
524524 .driver = {
525525 .name = "rtc-fm3130",
526− .owner = THIS_MODULE,
527526 },
528527 .probe = fm3130_probe,
529528 .id_table = fm3130_id,
drivers/rtc/rtc-gemini.c+1−4
@@ -148,10 +148,7 @@ static int gemini_rtc_probe(struct platform_device *pdev) · 147 unmodified lines
148148
149149 rtc->rtc_dev = rtc_device_register(pdev->name, dev,
150150 &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);
155152 }
156153
157154 static int gemini_rtc_remove(struct platform_device *pdev)
drivers/rtc/rtc-hym8563.c+0−1
@@ -599,7 +599,6 @@ MODULE_DEVICE_TABLE(of, hym8563_dt_idtable); · 598 unmodified lines
599599 static struct i2c_driver hym8563_driver = {
600600 .driver = {
601601 .name = "rtc-hym8563",
602− .owner = THIS_MODULE,
603602 .pm = &hym8563_pm_ops,
604603 .of_match_table = hym8563_dt_idtable,
605604 },
drivers/rtc/rtc-isl12022.c+2−6
@@ -151,12 +151,7 @@ static int isl12022_get_datetime(struct i2c_client *client, struct rtc_time *tm) · 150 unmodified lines
151151 tm->tm_sec, tm->tm_min, tm->tm_hour,
152152 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
153153
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);
160155 }
161156
162157 static int isl12022_set_datetime(struct i2c_client *client, struct rtc_time *tm)
@@ -279,6 +274,7 @@ static const struct of_device_id isl12022_dt_match[] = { · 116 unmodified lines
279274 { .compatible = "isil,isl12022" },
280275 { },
281276 };
277+MODULE_DEVICE_TABLE(of, isl12022_dt_match);
282278 #endif
283279
284280 static const struct i2c_device_id isl12022_id[] = {
drivers/rtc/rtc-isl12057.c+1−1
@@ -648,6 +648,7 @@ static const struct of_device_id isl12057_dt_match[] = { · 647 unmodified lines
648648 { .compatible = "isil,isl12057" },
649649 { },
650650 };
651+MODULE_DEVICE_TABLE(of, isl12057_dt_match);
651652 #endif
652653
653654 static const struct i2c_device_id isl12057_id[] = {
@@ -659,7 +660,6 @@ MODULE_DEVICE_TABLE(i2c, isl12057_id); · 5 unmodified lines
659660 static struct i2c_driver isl12057_driver = {
660661 .driver = {
661662 .name = DRV_NAME,
662− .owner = THIS_MODULE,
663663 .pm = &isl12057_rtc_pm_ops,
664664 .of_match_table = of_match_ptr(isl12057_dt_match),
665665 },
drivers/rtc/rtc-lpc24xx.c+310−0
@@ -0,0 +1,310 @@
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");
drivers/rtc/rtc-m48t59.c+10−8
@@ -345,11 +345,12 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj, · 344 unmodified lines
345345 ssize_t cnt = 0;
346346 unsigned long flags;
347347
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++)
350351 *buf++ = M48T59_READ(cnt);
351− spin_unlock_irqrestore(&m48t59->lock, flags);
352− }
352+
353+ spin_unlock_irqrestore(&m48t59->lock, flags);
353354
354355 return cnt;
355356 }
@@ -365,11 +366,12 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj, · 9 unmodified lines
365366 ssize_t cnt = 0;
366367 unsigned long flags;
367368
368− for (; size > 0 && pos < pdata->offset; cnt++, size--) {
369− spin_lock_irqsave(&m48t59->lock, flags);
369+ spin_lock_irqsave(&m48t59->lock, flags);
370+
371+ for (; cnt < size; cnt++)
370372 M48T59_WRITE(*buf++, cnt);
371− spin_unlock_irqrestore(&m48t59->lock, flags);
372− }
373+
374+ spin_unlock_irqrestore(&m48t59->lock, flags);
373375
374376 return cnt;
375377 }
drivers/rtc/rtc-max8997.c+1−0
@@ -521,6 +521,7 @@ static const struct platform_device_id rtc_id[] = { · 520 unmodified lines
521521 { "max8997-rtc", 0 },
522522 {},
523523 };
524+MODULE_DEVICE_TABLE(platform, rtc_id);
524525
525526 static struct platform_driver max8997_rtc_driver = {
526527 .driver = {
drivers/rtc/rtc-moxart.c+1−0
@@ -312,6 +312,7 @@ static const struct of_device_id moxart_rtc_match[] = { · 311 unmodified lines
312312 { .compatible = "moxa,moxart-rtc" },
313313 { },
314314 };
315+MODULE_DEVICE_TABLE(of, moxart_rtc_match);
315316
316317 static struct platform_driver moxart_rtc_driver = {
317318 .probe = moxart_rtc_probe,
drivers/rtc/rtc-mpc5121.c+1−0
@@ -406,6 +406,7 @@ static const struct of_device_id mpc5121_rtc_match[] = { · 405 unmodified lines
406406 { .compatible = "fsl,mpc5200-rtc", },
407407 {},
408408 };
409+MODULE_DEVICE_TABLE(of, mpc5121_rtc_match);
409410 #endif
410411
411412 static struct platform_driver mpc5121_rtc_driver = {
drivers/rtc/rtc-mt6397.c+27−0
@@ -373,15 +373,42 @@ static int mtk_rtc_remove(struct platform_device *pdev) · 372 unmodified lines
373373 return 0;
374374 }
375375
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+
376401 static const struct of_device_id mt6397_rtc_of_match[] = {
377402 { .compatible = "mediatek,mt6397-rtc", },
378403 { }
379404 };
405+MODULE_DEVICE_TABLE(of, mt6397_rtc_of_match);
380406
381407 static struct platform_driver mtk_rtc_driver = {
382408 .driver = {
383409 .name = "mt6397-rtc",
384410 .of_match_table = mt6397_rtc_of_match,
411+ .pm = &mt6397_pm_ops,
385412 },
386413 .probe = mtk_rtc_probe,
387414 .remove = mtk_rtc_remove,
drivers/rtc/rtc-mv.c+1−0
@@ -324,6 +324,7 @@ static const struct of_device_id rtc_mv_of_match_table[] = { · 323 unmodified lines
324324 { .compatible = "marvell,orion-rtc", },
325325 {}
326326 };
327+MODULE_DEVICE_TABLE(of, rtc_mv_of_match_table);
327328 #endif
328329
329330 static struct platform_driver mv_rtc_driver = {
drivers/rtc/rtc-omap.c+33−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <linux/of_device.h>
2626 #include <linux/pm_runtime.h>
2727 #include <linux/io.h>
28+#include <linux/clk.h>
2829
2930 /*
3031 * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
@@ -107,6 +108,7 @@ · 76 unmodified lines
107108
108109 /* OMAP_RTC_OSC_REG bit fields: */
109110 #define OMAP_RTC_OSC_32KCLK_EN BIT(6)
111+#define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3)
110112
111113 /* OMAP_RTC_IRQWAKEEN bit fields: */
112114 #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1)
@@ -132,10 +134,12 @@ struct omap_rtc_device_type { · 19 unmodified lines
132134 struct omap_rtc {
133135 struct rtc_device *rtc;
134136 void __iomem *base;
137+ struct clk *clk;
135138 int irq_alarm;
136139 int irq_timer;
137140 u8 interrupts_reg;
138141 bool is_pmic_controller;
142+ bool has_ext_clk;
139143 const struct omap_rtc_device_type *type;
140144 };
141145
@@ -553,6 +557,15 @@ static int omap_rtc_probe(struct platform_device *pdev) · 411 unmodified lines
553557 if (rtc->irq_alarm <= 0)
554558 return -ENOENT;
555559
560+ rtc->clk = devm_clk_get(&pdev->dev, "ext-clk");
561+ if (!IS_ERR(rtc->clk))
562+ rtc->has_ext_clk = true;
563+ else
564+ rtc->clk = devm_clk_get(&pdev->dev, "int-clk");
565+
566+ if (!IS_ERR(rtc->clk))
567+ clk_prepare_enable(rtc->clk);
568+
556569 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
557570 rtc->base = devm_ioremap_resource(&pdev->dev, res);
558571 if (IS_ERR(rtc->base))
@@ -627,6 +640,16 @@ static int omap_rtc_probe(struct platform_device *pdev) · 68 unmodified lines
627640 if (reg != new_ctrl)
628641 rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
629642
643+ /*
644+ * If we have the external clock then switch to it so we can keep
645+ * ticking across suspend.
646+ */
647+ if (rtc->has_ext_clk) {
648+ reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
649+ rtc_write(rtc, OMAP_RTC_OSC_REG,
650+ reg | OMAP_RTC_OSC_SEL_32KCLK_SRC);
651+ }
652+
630653 rtc->type->lock(rtc);
631654
632655 device_init_wakeup(&pdev->dev, true);
@@ -672,6 +695,7 @@ err: · 39 unmodified lines
672695 static int __exit omap_rtc_remove(struct platform_device *pdev)
673696 {
674697 struct omap_rtc *rtc = platform_get_drvdata(pdev);
698+ u8 reg;
675699
676700 if (pm_power_off == omap_rtc_power_off &&
677701 omap_rtc_power_off_rtc == rtc) {
@@ -681,10 +705,19 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) · 3 unmodified lines
681705
682706 device_init_wakeup(&pdev->dev, 0);
683707
708+ if (!IS_ERR(rtc->clk))
709+ clk_disable_unprepare(rtc->clk);
710+
684711 rtc->type->unlock(rtc);
685712 /* leave rtc running, but disable irqs */
686713 rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
687714
715+ if (rtc->has_ext_clk) {
716+ reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
717+ reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC;
718+ rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
719+ }
720+
688721 rtc->type->lock(rtc);
689722
690723 /* Disable the clock/module */
drivers/rtc/rtc-opal.c+5−5
@@ -190,11 +190,9 @@ exit: · 189 unmodified lines
190190 return rc;
191191 }
192192
193−static const struct rtc_class_ops opal_rtc_ops = {
193+static struct rtc_class_ops opal_rtc_ops = {
194194 .read_time = opal_get_rtc_time,
195195 .set_time = opal_set_rtc_time,
196− .read_alarm = opal_get_tpo_time,
197− .set_alarm = opal_set_tpo_time,
198196 };
199197
200198 static int opal_rtc_probe(struct platform_device *pdev)
@@ -202,8 +200,11 @@ static int opal_rtc_probe(struct platform_device *pdev) · 1 unmodified line
202200 struct rtc_device *rtc;
203201
204202 if (pdev->dev.of_node && of_get_property(pdev->dev.of_node, "has-tpo",
205− NULL))
203+ NULL)) {
206204 device_set_wakeup_capable(&pdev->dev, true);
205+ opal_rtc_ops.read_alarm = opal_get_tpo_time;
206+ opal_rtc_ops.set_alarm = opal_set_tpo_time;
207+ }
207208
208209 rtc = devm_rtc_device_register(&pdev->dev, DRVNAME, &opal_rtc_ops,
209210 THIS_MODULE);
@@ -236,7 +237,6 @@ static struct platform_driver opal_rtc_driver = { · 26 unmodified lines
236237 .id_table = opal_rtc_driver_ids,
237238 .driver = {
238239 .name = DRVNAME,
239− .owner = THIS_MODULE,
240240 .of_match_table = opal_rtc_match,
241241 },
242242 };
drivers/rtc/rtc-pcf2123.c+1−7
@@ -165,13 +165,7 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm) · 164 unmodified lines
165165 tm->tm_sec, tm->tm_min, tm->tm_hour,
166166 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
167167
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);
175169 }
176170
177171 static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
drivers/rtc/rtc-pcf2127.c+24−11
@@ -33,11 +33,14 @@ · 32 unmodified lines
3333 #define PCF2127_REG_MO (0x08)
3434 #define PCF2127_REG_YR (0x09)
3535
36+#define PCF2127_OSF BIT(7) /* Oscillator Fail flag */
37+
3638 static struct i2c_driver pcf2127_driver;
3739
3840 struct pcf2127 {
3941 struct rtc_device *rtc;
4042 int voltage_low; /* indicates if a low_voltage was detected */
43+ int oscillator_failed; /* OSF was detected and date is unreliable */
4144 };
4245
4346 /*
@@ -59,7 +62,18 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm) · 15 unmodified lines
5962 if (buf[PCF2127_REG_CTRL3] & 0x04) {
6063 pcf2127->voltage_low = 1;
6164 dev_info(&client->dev,
62− "low voltage detected, date/time is not reliable.\n");
65+ "low voltage detected, check/replace RTC battery.\n");
66+ }
67+
68+ if (buf[PCF2127_REG_SC] & PCF2127_OSF) {
69+ /*
70+ * no need clear the flag here,
71+ * it will be cleared once the new date is saved
72+ */
73+ pcf2127->oscillator_failed = 1;
74+ dev_warn(&client->dev,
75+ "oscillator stop detected, date/time is not reliable\n");
76+ return -EINVAL;
6377 }
6478
6579 dev_dbg(&client->dev,
@@ -88,17 +102,12 @@ static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm) · 22 unmodified lines
88102 tm->tm_sec, tm->tm_min, tm->tm_hour,
89103 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
90104
91− /* the clock can give out invalid datetime, but we cannot return
92− * -EINVAL otherwise hwclock will refuse to set the time on bootup.
93− */
94− if (rtc_valid_tm(tm) < 0)
95− dev_err(&client->dev, "retrieved date/time is not valid.\n");
96−
97− return 0;
105+ return rtc_valid_tm(tm);
98106 }
99107
100108 static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm)
101109 {
110+ struct pcf2127 *pcf2127 = i2c_get_clientdata(client);
102111 unsigned char buf[8];
103112 int i = 0, err;
104113
@@ -112,7 +121,7 @@ static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) · 7 unmodified lines
112121 buf[i++] = PCF2127_REG_SC;
113122
114123 /* hours, minutes and seconds */
115− buf[i++] = bin2bcd(tm->tm_sec);
124+ buf[i++] = bin2bcd(tm->tm_sec); /* this will also clear OSF flag */
116125 buf[i++] = bin2bcd(tm->tm_min);
117126 buf[i++] = bin2bcd(tm->tm_hour);
118127 buf[i++] = bin2bcd(tm->tm_mday);
@@ -132,6 +141,9 @@ static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm) · 13 unmodified lines
132141 return -EIO;
133142 }
134143
144+ /* clear OSF flag in client data */
145+ pcf2127->oscillator_failed = 0;
146+
135147 return 0;
136148 }
137149
@@ -144,7 +156,9 @@ static int pcf2127_rtc_ioctl(struct device *dev, · 6 unmodified lines
144156 switch (cmd) {
145157 case RTC_VL_READ:
146158 if (pcf2127->voltage_low)
147− dev_info(dev, "low voltage detected, date/time is not reliable.\n");
159+ dev_info(dev, "low voltage detected, check/replace battery\n");
160+ if (pcf2127->oscillator_failed)
161+ dev_info(dev, "oscillator stop detected, date/time is not reliable\n");
148162
149163 if (copy_to_user((void __user *)arg, &pcf2127->voltage_low,
150164 sizeof(int)))
@@ -217,7 +231,6 @@ MODULE_DEVICE_TABLE(of, pcf2127_of_match); · 66 unmodified lines
217231 static struct i2c_driver pcf2127_driver = {
218232 .driver = {
219233 .name = "rtc-pcf2127",
220− .owner = THIS_MODULE,
221234 .of_match_table = of_match_ptr(pcf2127_of_match),
222235 },
223236 .probe = pcf2127_probe,
drivers/rtc/rtc-pcf85063.c+0−1
@@ -189,7 +189,6 @@ MODULE_DEVICE_TABLE(of, pcf85063_of_match); · 188 unmodified lines
189189 static struct i2c_driver pcf85063_driver = {
190190 .driver = {
191191 .name = "rtc-pcf85063",
192− .owner = THIS_MODULE,
193192 .of_match_table = of_match_ptr(pcf85063_of_match),
194193 },
195194 .probe = pcf85063_probe,
drivers/rtc/rtc-pcf8523.c+0−1
@@ -334,7 +334,6 @@ MODULE_DEVICE_TABLE(of, pcf8523_of_match); · 333 unmodified lines
334334 static struct i2c_driver pcf8523_driver = {
335335 .driver = {
336336 .name = DRIVER_NAME,
337− .owner = THIS_MODULE,
338337 .of_match_table = of_match_ptr(pcf8523_of_match),
339338 },
340339 .probe = pcf8523_probe,
drivers/rtc/rtc-pcf8563.c+0−1
@@ -483,7 +483,6 @@ MODULE_DEVICE_TABLE(of, pcf8563_of_match); · 482 unmodified lines
483483 static struct i2c_driver pcf8563_driver = {
484484 .driver = {
485485 .name = "rtc-pcf8563",
486− .owner = THIS_MODULE,
487486 .of_match_table = of_match_ptr(pcf8563_of_match),
488487 },
489488 .probe = pcf8563_probe,
drivers/rtc/rtc-pcf8583.c+0−1
@@ -309,7 +309,6 @@ MODULE_DEVICE_TABLE(i2c, pcf8583_id); · 308 unmodified lines
309309 static struct i2c_driver pcf8583_driver = {
310310 .driver = {
311311 .name = "pcf8583",
312− .owner = THIS_MODULE,
313312 },
314313 .probe = pcf8583_probe,
315314 .id_table = pcf8583_id,
drivers/rtc/rtc-pl031.c+1−1
@@ -476,6 +476,6 @@ static struct amba_driver pl031_driver = { · 475 unmodified lines
476476
477477 module_amba_driver(pl031_driver);
478478
479−MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net");
479+MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
480480 MODULE_DESCRIPTION("ARM AMBA PL031 RTC Driver");
481481 MODULE_LICENSE("GPL");
drivers/rtc/rtc-pxa.c+28−27
@@ -32,6 +32,8 @@ · 31 unmodified lines
3232
3333 #include <mach/hardware.h>
3434
35+#include "rtc-sa1100.h"
36+
3537 #define RTC_DEF_DIVIDER (32768 - 1)
3638 #define RTC_DEF_TRIM 0
3739 #define MAXFREQ_PERIODIC 1000
@@ -86,10 +88,9 @@ · 48 unmodified lines
8688 __raw_writel((value), (pxa_rtc)->base + (reg))
8789
8890 struct pxa_rtc {
91+ struct sa1100_rtc sa1100_rtc;
8992 struct resource *ress;
9093 void __iomem *base;
91− int irq_1Hz;
92− int irq_Alrm;
9394 struct rtc_device *rtc;
9495 spinlock_t lock; /* Protects this structure */
9596 };
@@ -184,25 +185,25 @@ static int pxa_rtc_open(struct device *dev) · 88 unmodified lines
184185 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
185186 int ret;
186187
187− ret = request_irq(pxa_rtc->irq_1Hz, pxa_rtc_irq, 0,
188+ ret = request_irq(pxa_rtc->sa1100_rtc.irq_1hz, pxa_rtc_irq, 0,
188189 "rtc 1Hz", dev);
189190 if (ret < 0) {
190− dev_err(dev, "can't get irq %i, err %d\n", pxa_rtc->irq_1Hz,
191− ret);
191+ dev_err(dev, "can't get irq %i, err %d\n",
192+ pxa_rtc->sa1100_rtc.irq_1hz, ret);
192193 goto err_irq_1Hz;
193194 }
194− ret = request_irq(pxa_rtc->irq_Alrm, pxa_rtc_irq, 0,
195+ ret = request_irq(pxa_rtc->sa1100_rtc.irq_alarm, pxa_rtc_irq, 0,
195196 "rtc Alrm", dev);
196197 if (ret < 0) {
197− dev_err(dev, "can't get irq %i, err %d\n", pxa_rtc->irq_Alrm,
198− ret);
198+ dev_err(dev, "can't get irq %i, err %d\n",
199+ pxa_rtc->sa1100_rtc.irq_alarm, ret);
199200 goto err_irq_Alrm;
200201 }
201202
202203 return 0;
203204
204205 err_irq_Alrm:
205− free_irq(pxa_rtc->irq_1Hz, dev);
206+ free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev);
206207 err_irq_1Hz:
207208 return ret;
208209 }
@@ -215,8 +216,8 @@ static void pxa_rtc_release(struct device *dev) · 6 unmodified lines
215216 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE);
216217 spin_unlock_irq(&pxa_rtc->lock);
217218
218− free_irq(pxa_rtc->irq_Alrm, dev);
219− free_irq(pxa_rtc->irq_1Hz, dev);
219+ free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev);
220+ free_irq(pxa_rtc->sa1100_rtc.irq_alarm, dev);
220221 }
221222
222223 static int pxa_alarm_irq_enable(struct device *dev, unsigned int enabled)
@@ -320,12 +321,13 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) · 97 unmodified lines
320321 {
321322 struct device *dev = &pdev->dev;
322323 struct pxa_rtc *pxa_rtc;
324+ struct sa1100_rtc *sa1100_rtc;
323325 int ret;
324− u32 rttr;
325326
326327 pxa_rtc = devm_kzalloc(dev, sizeof(*pxa_rtc), GFP_KERNEL);
327328 if (!pxa_rtc)
328329 return -ENOMEM;
330+ sa1100_rtc = &pxa_rtc->sa1100_rtc;
329331
330332 spin_lock_init(&pxa_rtc->lock);
331333 platform_set_drvdata(pdev, pxa_rtc);
@@ -336,13 +338,13 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) · 4 unmodified lines
336338 return -ENXIO;
337339 }
338340
339− pxa_rtc->irq_1Hz = platform_get_irq(pdev, 0);
340− if (pxa_rtc->irq_1Hz < 0) {
341+ sa1100_rtc->irq_1hz = platform_get_irq(pdev, 0);
342+ if (sa1100_rtc->irq_1hz < 0) {
341343 dev_err(dev, "No 1Hz IRQ resource defined\n");
342344 return -ENXIO;
343345 }
344− pxa_rtc->irq_Alrm = platform_get_irq(pdev, 1);
345− if (pxa_rtc->irq_Alrm < 0) {
346+ sa1100_rtc->irq_alarm = platform_get_irq(pdev, 1);
347+ if (sa1100_rtc->irq_alarm < 0) {
346348 dev_err(dev, "No alarm IRQ resource defined\n");
347349 return -ENXIO;
348350 }
@@ -354,15 +356,14 @@ static int __init pxa_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
354356 return -ENOMEM;
355357 }
356358
357− /*
358− * If the clock divider is uninitialized then reset it to the
359− * default value to get the 1Hz clock.
360− */
361− if (rtc_readl(pxa_rtc, RTTR) == 0) {
362− rttr = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
363− rtc_writel(pxa_rtc, RTTR, rttr);
364− dev_warn(dev, "warning: initializing default clock"
365− " divider/trim value\n");
359+ sa1100_rtc->rcnr = pxa_rtc->base + 0x0;
360+ sa1100_rtc->rtsr = pxa_rtc->base + 0x8;
361+ sa1100_rtc->rtar = pxa_rtc->base + 0x4;
362+ sa1100_rtc->rttr = pxa_rtc->base + 0xc;
363+ ret = sa1100_rtc_init(pdev, sa1100_rtc);
364+ if (!ret) {
365+ dev_err(dev, "Unable to init SA1100 RTC sub-device\n");
366+ return ret;
366367 }
367368
368369 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE);
@@ -402,7 +403,7 @@ static int pxa_rtc_suspend(struct device *dev) · 33 unmodified lines
402403 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
403404
404405 if (device_may_wakeup(dev))
405− enable_irq_wake(pxa_rtc->irq_Alrm);
406+ enable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm);
406407 return 0;
407408 }
408409
@@ -411,7 +412,7 @@ static int pxa_rtc_resume(struct device *dev) · 2 unmodified lines
411412 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
412413
413414 if (device_may_wakeup(dev))
414− disable_irq_wake(pxa_rtc->irq_Alrm);
415+ disable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm);
415416 return 0;
416417 }
417418 #endif
drivers/rtc/rtc-rp5c01.c+2−2
@@ -170,7 +170,7 @@ static ssize_t rp5c01_nvram_read(struct file *filp, struct kobject *kobj, · 169 unmodified lines
170170
171171 spin_lock_irq(&priv->lock);
172172
173− for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
173+ for (count = 0; count < size; count++) {
174174 u8 data;
175175
176176 rp5c01_write(priv,
@@ -200,7 +200,7 @@ static ssize_t rp5c01_nvram_write(struct file *filp, struct kobject *kobj, · 23 unmodified lines
200200
201201 spin_lock_irq(&priv->lock);
202202
203− for (count = 0; size > 0 && pos < RP5C01_MODE; count++, size--) {
203+ for (count = 0; count < size; count++) {
204204 u8 data = *buf++;
205205
206206 rp5c01_write(priv,
drivers/rtc/rtc-rx8025.c+105−172
@@ -18,13 +18,11 @@ · 17 unmodified lines
1818 * modify it under the terms of the GNU General Public License
1919 * version 2 as published by the Free Software Foundation.
2020 */
21−#include <linux/kernel.h>
22−#include <linux/module.h>
23−#include <linux/slab.h>
24−#include <linux/init.h>
2521 #include <linux/bcd.h>
22+#include <linux/bitops.h>
2623 #include <linux/i2c.h>
27−#include <linux/list.h>
24+#include <linux/kernel.h>
25+#include <linux/module.h>
2826 #include <linux/rtc.h>
2927
3028 /* Register definitions */
@@ -48,17 +46,17 @@ · 17 unmodified lines
4846 #define RX8025_BIT_CTRL1_CT (7 << 0)
4947 /* 1 Hz periodic level irq */
5048 #define RX8025_BIT_CTRL1_CT_1HZ 4
51−#define RX8025_BIT_CTRL1_TEST (1 << 3)
52−#define RX8025_BIT_CTRL1_1224 (1 << 5)
53−#define RX8025_BIT_CTRL1_DALE (1 << 6)
54−#define RX8025_BIT_CTRL1_WALE (1 << 7)
55−
56−#define RX8025_BIT_CTRL2_DAFG (1 << 0)
57−#define RX8025_BIT_CTRL2_WAFG (1 << 1)
58−#define RX8025_BIT_CTRL2_CTFG (1 << 2)
59−#define RX8025_BIT_CTRL2_PON (1 << 4)
60−#define RX8025_BIT_CTRL2_XST (1 << 5)
61−#define RX8025_BIT_CTRL2_VDET (1 << 6)
49+#define RX8025_BIT_CTRL1_TEST BIT(3)
50+#define RX8025_BIT_CTRL1_1224 BIT(5)
51+#define RX8025_BIT_CTRL1_DALE BIT(6)
52+#define RX8025_BIT_CTRL1_WALE BIT(7)
53+
54+#define RX8025_BIT_CTRL2_DAFG BIT(0)
55+#define RX8025_BIT_CTRL2_WAFG BIT(1)
56+#define RX8025_BIT_CTRL2_CTFG BIT(2)
57+#define RX8025_BIT_CTRL2_PON BIT(4)
58+#define RX8025_BIT_CTRL2_XST BIT(5)
59+#define RX8025_BIT_CTRL2_VDET BIT(6)
6260
6361 /* Clock precision adjustment */
6462 #define RX8025_ADJ_RESOLUTION 3050 /* in ppb */
@@ -74,84 +72,84 @@ MODULE_DEVICE_TABLE(i2c, rx8025_id); · 9 unmodified lines
7472 struct rx8025_data {
7573 struct i2c_client *client;
7674 struct rtc_device *rtc;
77− struct work_struct work;
7875 u8 ctrl1;
79− unsigned exiting:1;
8076 };
8177
82−static int rx8025_read_reg(struct i2c_client *client, int number, u8 *value)
78+static s32 rx8025_read_reg(const struct i2c_client *client, u8 number)
8379 {
84− int ret = i2c_smbus_read_byte_data(client, (number << 4) | 0x08);
85−
86− if (ret < 0) {
87− dev_err(&client->dev, "Unable to read register #%d\n", number);
88− return ret;
89− }
90−
91− *value = ret;
92− return 0;
80+ return i2c_smbus_read_byte_data(client, number << 4);
9381 }
9482
95−static int rx8025_read_regs(struct i2c_client *client,
96− int number, u8 length, u8 *values)
83+static int rx8025_read_regs(const struct i2c_client *client,
84+ u8 number, u8 length, u8 *values)
9785 {
98− int ret = i2c_smbus_read_i2c_block_data(client, (number << 4) | 0x08,
99− length, values);
100−
101− if (ret != length) {
102− dev_err(&client->dev, "Unable to read registers #%d..#%d\n",
103− number, number + length - 1);
86+ int ret = i2c_smbus_read_i2c_block_data(client, number << 4, length,
87+ values);
88+ if (ret != length)
10489 return ret < 0 ? ret : -EIO;
105− }
10690
10791 return 0;
10892 }
10993
110−static int rx8025_write_reg(struct i2c_client *client, int number, u8 value)
94+static s32 rx8025_write_reg(const struct i2c_client *client, u8 number,
95+ u8 value)
11196 {
112− int ret = i2c_smbus_write_byte_data(client, number << 4, value);
113−
114− if (ret)
115− dev_err(&client->dev, "Unable to write register #%d\n",
116− number);
97+ return i2c_smbus_write_byte_data(client, number << 4, value);
98+}
11799
118− return ret;
100+static s32 rx8025_write_regs(const struct i2c_client *client,
101+ u8 number, u8 length, const u8 *values)
102+{
103+ return i2c_smbus_write_i2c_block_data(client, number << 4,
104+ length, values);
119105 }
120106
121−static int rx8025_write_regs(struct i2c_client *client,
122− int number, u8 length, u8 *values)
107+static int rx8025_check_validity(struct device *dev)
123108 {
124− int ret = i2c_smbus_write_i2c_block_data(client, (number << 4) | 0x08,
125− length, values);
109+ struct rx8025_data *rx8025 = dev_get_drvdata(dev);
110+ int ctrl2;
111+
112+ ctrl2 = rx8025_read_reg(rx8025->client, RX8025_REG_CTRL2);
113+ if (ctrl2 < 0)
114+ return ctrl2;
115+
116+ if (ctrl2 & RX8025_BIT_CTRL2_VDET)
117+ dev_warn(dev, "power voltage drop detected\n");
118+
119+ if (ctrl2 & RX8025_BIT_CTRL2_PON) {
120+ dev_warn(dev, "power-on reset detected, date is invalid\n");
121+ return -EINVAL;
122+ }
126123
127− if (ret)
128− dev_err(&client->dev, "Unable to write registers #%d..#%d\n",
129− number, number + length - 1);
124+ if (!(ctrl2 & RX8025_BIT_CTRL2_XST)) {
125+ dev_warn(dev, "crystal stopped, date is invalid\n");
126+ return -EINVAL;
127+ }
130128
131− return ret;
129+ return 0;
132130 }
133131
134−static irqreturn_t rx8025_irq(int irq, void *dev_id)
132+static int rx8025_reset_validity(struct i2c_client *client)
135133 {
136− struct i2c_client *client = dev_id;
137− struct rx8025_data *rx8025 = i2c_get_clientdata(client);
134+ int ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
138135
139− disable_irq_nosync(irq);
140− schedule_work(&rx8025->work);
141− return IRQ_HANDLED;
136+ if (ctrl2 < 0)
137+ return ctrl2;
138+
139+ ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET);
140+
141+ return rx8025_write_reg(client, RX8025_REG_CTRL2,
142+ ctrl2 | RX8025_BIT_CTRL2_XST);
142143 }
143144
144−static void rx8025_work(struct work_struct *work)
145+static irqreturn_t rx8025_handle_irq(int irq, void *dev_id)
145146 {
146− struct rx8025_data *rx8025 = container_of(work, struct rx8025_data,
147− work);
148− struct i2c_client *client = rx8025->client;
149− struct mutex *lock = &rx8025->rtc->ops_lock;
150− u8 status;
151−
152− mutex_lock(lock);
147+ struct i2c_client *client = dev_id;
148+ struct rx8025_data *rx8025 = i2c_get_clientdata(client);
149+ int status;
153150
154− if (rx8025_read_reg(client, RX8025_REG_CTRL2, &status))
151+ status = rx8025_read_reg(client, RX8025_REG_CTRL2);
152+ if (status < 0)
155153 goto out;
156154
157155 if (!(status & RX8025_BIT_CTRL2_XST))
@@ -161,9 +159,7 @@ static void rx8025_work(struct work_struct *work) · 3 unmodified lines
161159 if (status & RX8025_BIT_CTRL2_CTFG) {
162160 /* periodic */
163161 status &= ~RX8025_BIT_CTRL2_CTFG;
164− local_irq_disable();
165162 rtc_update_irq(rx8025->rtc, 1, RTC_PF | RTC_IRQF);
166− local_irq_enable();
167163 }
168164
169165 if (status & RX8025_BIT_CTRL2_DAFG) {
@@ -172,20 +168,11 @@ static void rx8025_work(struct work_struct *work) · 2 unmodified lines
172168 if (rx8025_write_reg(client, RX8025_REG_CTRL1,
173169 rx8025->ctrl1 & ~RX8025_BIT_CTRL1_DALE))
174170 goto out;
175− local_irq_disable();
176171 rtc_update_irq(rx8025->rtc, 1, RTC_AF | RTC_IRQF);
177− local_irq_enable();
178172 }
179173
180− /* acknowledge IRQ */
181− rx8025_write_reg(client, RX8025_REG_CTRL2,
182− status | RX8025_BIT_CTRL2_XST);
183−
184174 out:
185− if (!rx8025->exiting)
186− enable_irq(client->irq);
187−
188− mutex_unlock(lock);
175+ return IRQ_HANDLED;
189176 }
190177
191178 static int rx8025_get_time(struct device *dev, struct rtc_time *dt)
@@ -194,6 +181,10 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 2 unmodified lines
194181 u8 date[7];
195182 int err;
196183
184+ err = rx8025_check_validity(dev);
185+ if (err)
186+ return err;
187+
197188 err = rx8025_read_regs(rx8025->client, RX8025_REG_SEC, 7, date);
198189 if (err)
199190 return err;
@@ -213,10 +204,7 @@ static int rx8025_get_time(struct device *dev, struct rtc_time *dt) · 13 unmodified lines
213204
214205 dt->tm_mday = bcd2bin(date[RX8025_REG_MDAY] & 0x3f);
215206 dt->tm_mon = bcd2bin(date[RX8025_REG_MONTH] & 0x1f) - 1;
216− dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]);
217−
218− if (dt->tm_year < 70)
219− dt->tm_year += 100;
207+ dt->tm_year = bcd2bin(date[RX8025_REG_YEAR]) + 100;
220208
221209 dev_dbg(dev, "%s: date %ds %dm %dh %dmd %dm %dy\n", __func__,
222210 dt->tm_sec, dt->tm_min, dt->tm_hour,
@@ -229,12 +217,10 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) · 6 unmodified lines
229217 {
230218 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
231219 u8 date[7];
220+ int ret;
232221
233− /*
234− * BUG: The HW assumes every year that is a multiple of 4 to be a leap
235− * year. Next time this is wrong is 2100, which will not be a leap
236− * year.
237− */
222+ if ((dt->tm_year < 100) || (dt->tm_year > 199))
223+ return -EINVAL;
238224
239225 /*
240226 * Here the read-only bits are written as "0". I'm not sure if that
@@ -251,17 +237,21 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt) · 10 unmodified lines
251237 date[RX8025_REG_WDAY] = bin2bcd(dt->tm_wday);
252238 date[RX8025_REG_MDAY] = bin2bcd(dt->tm_mday);
253239 date[RX8025_REG_MONTH] = bin2bcd(dt->tm_mon + 1);
254− date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year % 100);
240+ date[RX8025_REG_YEAR] = bin2bcd(dt->tm_year - 100);
255241
256242 dev_dbg(dev,
257243 "%s: write 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",
258244 __func__,
259245 date[0], date[1], date[2], date[3], date[4], date[5], date[6]);
260246
261− return rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
247+ ret = rx8025_write_regs(rx8025->client, RX8025_REG_SEC, 7, date);
248+ if (ret < 0)
249+ return ret;
250+
251+ return rx8025_reset_validity(rx8025->client);
262252 }
263253
264−static int rx8025_init_client(struct i2c_client *client, int *need_reset)
254+static int rx8025_init_client(struct i2c_client *client)
265255 {
266256 struct rx8025_data *rx8025 = i2c_get_clientdata(client);
267257 u8 ctrl[2], ctrl2;
@@ -275,38 +265,18 @@ static int rx8025_init_client(struct i2c_client *client, int *need_reset) · 7 unmodified lines
275265 /* Keep test bit zero ! */
276266 rx8025->ctrl1 = ctrl[0] & ~RX8025_BIT_CTRL1_TEST;
277267
278− if (ctrl[1] & RX8025_BIT_CTRL2_PON) {
279− dev_warn(&client->dev, "power-on reset was detected, "
280− "you may have to readjust the clock\n");
281− *need_reset = 1;
282− }
283−
284− if (ctrl[1] & RX8025_BIT_CTRL2_VDET) {
285− dev_warn(&client->dev, "a power voltage drop was detected, "
286− "you may have to readjust the clock\n");
287− *need_reset = 1;
288− }
289−
290− if (!(ctrl[1] & RX8025_BIT_CTRL2_XST)) {
291− dev_warn(&client->dev, "Oscillation stop was detected,"
292− "you may have to readjust the clock\n");
293− *need_reset = 1;
294− }
295−
296268 if (ctrl[1] & (RX8025_BIT_CTRL2_DAFG | RX8025_BIT_CTRL2_WAFG)) {
297269 dev_warn(&client->dev, "Alarm was detected\n");
298270 need_clear = 1;
299271 }
300272
301− if (!(ctrl[1] & RX8025_BIT_CTRL2_CTFG))
273+ if (ctrl[1] & RX8025_BIT_CTRL2_CTFG)
302274 need_clear = 1;
303275
304− if (*need_reset || need_clear) {
305− ctrl2 = ctrl[0];
306− ctrl2 &= ~(RX8025_BIT_CTRL2_PON | RX8025_BIT_CTRL2_VDET |
307− RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG |
276+ if (need_clear) {
277+ ctrl2 = ctrl[1];
278+ ctrl2 &= ~(RX8025_BIT_CTRL2_CTFG | RX8025_BIT_CTRL2_WAFG |
308279 RX8025_BIT_CTRL2_DAFG);
309− ctrl2 |= RX8025_BIT_CTRL2_XST;
310280
311281 err = rx8025_write_reg(client, RX8025_REG_CTRL2, ctrl2);
312282 }
@@ -319,8 +289,8 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) · 6 unmodified lines
319289 {
320290 struct rx8025_data *rx8025 = dev_get_drvdata(dev);
321291 struct i2c_client *client = rx8025->client;
322− u8 ctrl2, ald[2];
323− int err;
292+ u8 ald[2];
293+ int ctrl2, err;
324294
325295 if (client->irq <= 0)
326296 return -EINVAL;
@@ -329,9 +299,9 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t) · 2 unmodified lines
329299 if (err)
330300 return err;
331301
332− err = rx8025_read_reg(client, RX8025_REG_CTRL2, &ctrl2);
333− if (err)
334− return err;
302+ ctrl2 = rx8025_read_reg(client, RX8025_REG_CTRL2);
303+ if (ctrl2 < 0)
304+ return ctrl2;
335305
336306 dev_dbg(dev, "%s: read alarm 0x%02x 0x%02x ctrl2 %02x\n",
337307 __func__, ald[0], ald[1], ctrl2);
@@ -452,12 +422,11 @@ static struct rtc_class_ops rx8025_rtc_ops = { · 114 unmodified lines
452422 static int rx8025_get_clock_adjust(struct device *dev, int *adj)
453423 {
454424 struct i2c_client *client = to_i2c_client(dev);
455− u8 digoff;
456− int err;
425+ int digoff;
457426
458− err = rx8025_read_reg(client, RX8025_REG_DIGOFF, &digoff);
459− if (err)
460− return err;
427+ digoff = rx8025_read_reg(client, RX8025_REG_DIGOFF);
428+ if (digoff < 0)
429+ return digoff;
461430
462431 *adj = digoff >= 64 ? digoff - 128 : digoff;
463432 if (*adj > 0)
@@ -539,88 +508,53 @@ static int rx8025_probe(struct i2c_client *client, · 75 unmodified lines
539508 {
540509 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
541510 struct rx8025_data *rx8025;
542− int err, need_reset = 0;
511+ int err = 0;
543512
544513 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
545514 | I2C_FUNC_SMBUS_I2C_BLOCK)) {
546515 dev_err(&adapter->dev,
547516 "doesn't support required functionality\n");
548− err = -EIO;
549− goto errout;
517+ return -EIO;
550518 }
551519
552520 rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL);
553521 if (!rx8025) {
554− err = -ENOMEM;
555− goto errout;
522+ return -ENOMEM;
556523 }
557524
558525 rx8025->client = client;
559526 i2c_set_clientdata(client, rx8025);
560− INIT_WORK(&rx8025->work, rx8025_work);
561527
562− err = rx8025_init_client(client, &need_reset);
528+ err = rx8025_init_client(client);
563529 if (err)
564− goto errout;
565−
566− if (need_reset) {
567− struct rtc_time tm;
568− dev_info(&client->dev,
569− "bad conditions detected, resetting date\n");
570− rtc_time_to_tm(0, &tm); /* 1970/1/1 */
571− rx8025_set_time(&client->dev, &tm);
572− }
530+ return err;
573531
574532 rx8025->rtc = devm_rtc_device_register(&client->dev, client->name,
575533 &rx8025_rtc_ops, THIS_MODULE);
576534 if (IS_ERR(rx8025->rtc)) {
577− err = PTR_ERR(rx8025->rtc);
578535 dev_err(&client->dev, "unable to register the class device\n");
579− goto errout;
536+ return PTR_ERR(rx8025->rtc);
580537 }
581538
582539 if (client->irq > 0) {
583540 dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
584− err = request_irq(client->irq, rx8025_irq,
585− 0, "rx8025", client);
541+ err = devm_request_threaded_irq(&client->dev, client->irq, NULL,
542+ rx8025_handle_irq, 0, "rx8025",
543+ client);
586544 if (err) {
587− dev_err(&client->dev, "unable to request IRQ\n");
588− goto errout;
545+ dev_err(&client->dev, "unable to request IRQ, alarms disabled\n");
546+ client->irq = 0;
589547 }
590548 }
591549
592− rx8025->rtc->irq_freq = 1;
593550 rx8025->rtc->max_user_freq = 1;
594551
595552 err = rx8025_sysfs_register(&client->dev);
596− if (err)
597− goto errout_irq;
598−
599− return 0;
600−
601−errout_irq:
602− if (client->irq > 0)
603− free_irq(client->irq, client);
604−
605−errout:
606− dev_err(&adapter->dev, "probing for rx8025 failed\n");
607553 return err;
608554 }
609555
610556 static int rx8025_remove(struct i2c_client *client)
611557 {
612− struct rx8025_data *rx8025 = i2c_get_clientdata(client);
613− struct mutex *lock = &rx8025->rtc->ops_lock;
614−
615− if (client->irq > 0) {
616− mutex_lock(lock);
617− rx8025->exiting = 1;
618− mutex_unlock(lock);
619−
620− free_irq(client->irq, client);
621− cancel_work_sync(&rx8025->work);
622− }
623−
624558 rx8025_sysfs_unregister(&client->dev);
625559 return 0;
626560 }
@@ -628,7 +562,6 @@ static int rx8025_remove(struct i2c_client *client) · 1 unmodified line
628562 static struct i2c_driver rx8025_driver = {
629563 .driver = {
630564 .name = "rtc-rx8025",
631− .owner = THIS_MODULE,
632565 },
633566 .probe = rx8025_probe,
634567 .remove = rx8025_remove,
drivers/rtc/rtc-rx8581.c+0−1
@@ -315,7 +315,6 @@ MODULE_DEVICE_TABLE(i2c, rx8581_id); · 314 unmodified lines
315315 static struct i2c_driver rx8581_driver = {
316316 .driver = {
317317 .name = "rtc-rx8581",
318− .owner = THIS_MODULE,
319318 },
320319 .probe = rx8581_probe,
321320 .id_table = rx8581_id,
drivers/rtc/rtc-s3c.c+21−7
@@ -39,6 +39,7 @@ struct s3c_rtc { · 38 unmodified lines
3939 void __iomem *base;
4040 struct clk *rtc_clk;
4141 struct clk *rtc_src_clk;
42+ bool clk_disabled;
4243
4344 struct s3c_rtc_data *data;
4445
@@ -71,9 +72,12 @@ static void s3c_rtc_enable_clk(struct s3c_rtc *info) · 26 unmodified lines
7172 unsigned long irq_flags;
7273
7374 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
74− clk_enable(info->rtc_clk);
75− if (info->data->needs_src_clk)
76− clk_enable(info->rtc_src_clk);
75+ if (info->clk_disabled) {
76+ clk_enable(info->rtc_clk);
77+ if (info->data->needs_src_clk)
78+ clk_enable(info->rtc_src_clk);
79+ info->clk_disabled = false;
80+ }
7781 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
7882 }
7983
@@ -82,9 +86,12 @@ static void s3c_rtc_disable_clk(struct s3c_rtc *info) · 2 unmodified lines
8286 unsigned long irq_flags;
8387
8488 spin_lock_irqsave(&info->alarm_clk_lock, irq_flags);
85− if (info->data->needs_src_clk)
86− clk_disable(info->rtc_src_clk);
87− clk_disable(info->rtc_clk);
89+ if (!info->clk_disabled) {
90+ if (info->data->needs_src_clk)
91+ clk_disable(info->rtc_src_clk);
92+ clk_disable(info->rtc_clk);
93+ info->clk_disabled = true;
94+ }
8895 spin_unlock_irqrestore(&info->alarm_clk_lock, irq_flags);
8996 }
9097
@@ -128,6 +135,11 @@ static int s3c_rtc_setaie(struct device *dev, unsigned int enabled) · 37 unmodified lines
128135
129136 s3c_rtc_disable_clk(info);
130137
138+ if (enabled)
139+ s3c_rtc_enable_clk(info);
140+ else
141+ s3c_rtc_disable_clk(info);
142+
131143 return 0;
132144 }
133145
@@ -410,8 +422,9 @@ static int s3c_rtc_remove(struct platform_device *pdev) · 276 unmodified lines
410422
411423 s3c_rtc_setaie(info->dev, 0);
412424
425+ if (info->data->needs_src_clk)
426+ clk_unprepare(info->rtc_src_clk);
413427 clk_unprepare(info->rtc_clk);
414− info->rtc_clk = NULL;
415428
416429 return 0;
417430 }
@@ -482,6 +495,7 @@ static int s3c_rtc_probe(struct platform_device *pdev) · 64 unmodified lines
482495 if (IS_ERR(info->rtc_src_clk)) {
483496 dev_err(&pdev->dev,
484497 "failed to find rtc source clock\n");
498+ clk_disable_unprepare(info->rtc_clk);
485499 return PTR_ERR(info->rtc_src_clk);
486500 }
487501 clk_prepare_enable(info->rtc_src_clk);
drivers/rtc/rtc-s5m.c+11−0
@@ -635,6 +635,16 @@ static int s5m8767_rtc_init_reg(struct s5m_rtc_info *info) · 634 unmodified lines
635635 case S2MPS13X:
636636 data[0] = (0 << BCD_EN_SHIFT) | (1 << MODEL24_SHIFT);
637637 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);
638648 break;
639649
640650 default:
@@ -797,6 +807,7 @@ static const struct platform_device_id s5m_rtc_id[] = { · 156 unmodified lines
797807 { "s2mps14-rtc", S2MPS14X },
798808 { },
799809 };
810+MODULE_DEVICE_TABLE(platform, s5m_rtc_id);
800811
801812 static struct platform_driver s5m_rtc_driver = {
802813 .driver = {
drivers/rtc/rtc-sa1100.c+84−55
@@ -35,24 +35,17 @@ · 34 unmodified lines
3535 #include <linux/bitops.h>
3636 #include <linux/io.h>
3737
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 */
4042
41−#if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP)
42−#include <mach/regs-rtc.h>
43−#endif
43+#include "rtc-sa1100.h"
4444
4545 #define RTC_DEF_DIVIDER (32768 - 1)
4646 #define RTC_DEF_TRIM 0
4747 #define RTC_FREQ 1024
4848
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−};
5649
5750 static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
5851 {
@@ -63,16 +56,16 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) · 4 unmodified lines
6356
6457 spin_lock(&info->lock);
6558
66− rtsr = RTSR;
59+ rtsr = readl_relaxed(info->rtsr);
6760 /* clear interrupt sources */
68− RTSR = 0;
61+ writel_relaxed(0, info->rtsr);
6962 /* Fix for a nasty initialization problem the in SA11xx RTSR register.
7063 * See also the comments in sa1100_rtc_probe(). */
7164 if (rtsr & (RTSR_ALE | RTSR_HZE)) {
7265 /* This is the original code, before there was the if test
7366 * above. This code does not clear interrupts that were not
7467 * enabled. */
75− RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2);
68+ writel_relaxed((RTSR_AL | RTSR_HZ) & (rtsr >> 2), info->rtsr);
7669 } else {
7770 /* For some reason, it is possible to enter this routine
7871 * without interruptions enabled, it has been tested with
@@ -81,13 +74,13 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id) · 2 unmodified lines
8174 * This situation leads to an infinite "loop" of interrupt
8275 * routine calling and as a result the processor seems to
8376 * lock on its first call to open(). */
84− RTSR = RTSR_AL | RTSR_HZ;
77+ writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr);
8578 }
8679
8780 /* clear alarm interrupt if it has occurred */
8881 if (rtsr & RTSR_AL)
8982 rtsr &= ~RTSR_ALE;
90− RTSR = rtsr & (RTSR_ALE | RTSR_HZE);
83+ writel_relaxed(rtsr & (RTSR_ALE | RTSR_HZE), info->rtsr);
9184
9285 /* update irq data & counter */
9386 if (rtsr & RTSR_AL)
@@ -135,7 +128,7 @@ static void sa1100_rtc_release(struct device *dev) · 41 unmodified lines
135128 struct sa1100_rtc *info = dev_get_drvdata(dev);
136129
137130 spin_lock_irq(&info->lock);
138− RTSR = 0;
131+ writel_relaxed(0, info->rtsr);
139132 spin_unlock_irq(&info->lock);
140133
141134 free_irq(info->irq_alarm, dev);
@@ -144,39 +137,46 @@ static void sa1100_rtc_release(struct device *dev) · 2 unmodified lines
144137
145138 static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
146139 {
140+ u32 rtsr;
147141 struct sa1100_rtc *info = dev_get_drvdata(dev);
148142
149143 spin_lock_irq(&info->lock);
144+ rtsr = readl_relaxed(info->rtsr);
150145 if (enabled)
151− RTSR |= RTSR_ALE;
146+ rtsr |= RTSR_ALE;
152147 else
153− RTSR &= ~RTSR_ALE;
148+ rtsr &= ~RTSR_ALE;
149+ writel_relaxed(rtsr, info->rtsr);
154150 spin_unlock_irq(&info->lock);
155151 return 0;
156152 }
157153
158154 static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm)
159155 {
160− rtc_time_to_tm(RCNR, tm);
156+ struct sa1100_rtc *info = dev_get_drvdata(dev);
157+
158+ rtc_time_to_tm(readl_relaxed(info->rcnr), tm);
161159 return 0;
162160 }
163161
164162 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm)
165163 {
164+ struct sa1100_rtc *info = dev_get_drvdata(dev);
166165 unsigned long time;
167166 int ret;
168167
169168 ret = rtc_tm_to_time(tm, &time);
170169 if (ret == 0)
171− RCNR = time;
170+ writel_relaxed(time, info->rcnr);
172171 return ret;
173172 }
174173
175174 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
176175 {
177176 u32 rtsr;
177+ struct sa1100_rtc *info = dev_get_drvdata(dev);
178178
179− rtsr = RTSR;
179+ rtsr = readl_relaxed(info->rtsr);
180180 alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0;
181181 alrm->pending = (rtsr & RTSR_AL) ? 1 : 0;
182182 return 0;
@@ -192,12 +192,13 @@ static int sa1100_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) · 9 unmodified lines
192192 ret = rtc_tm_to_time(&alrm->time, &time);
193193 if (ret != 0)
194194 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);
197198 if (alrm->enabled)
198− RTSR |= RTSR_ALE;
199+ writel_relaxed(readl_relaxed(info->rtsr) | RTSR_ALE, info->rtsr);
199200 else
200− RTSR &= ~RTSR_ALE;
201+ writel_relaxed(readl_relaxed(info->rtsr) & ~RTSR_ALE, info->rtsr);
201202 out:
202203 spin_unlock_irq(&info->lock);
203204
@@ -206,8 +207,10 @@ out: · 2 unmodified lines
206207
207208 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq)
208209 {
209− seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32) RTTR);
210− seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)RTSR);
210+ struct sa1100_rtc *info = dev_get_drvdata(dev);
211+
212+ seq_printf(seq, "trim/divider\t\t: 0x%08x\n", readl_relaxed(info->rttr));
213+ seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", readl_relaxed(info->rtsr));
211214
212215 return 0;
213216 }
@@ -223,29 +226,18 @@ static const struct rtc_class_ops sa1100_rtc_ops = { · 9 unmodified lines
223226 .alarm_irq_enable = sa1100_rtc_alarm_irq_enable,
224227 };
225228
226−static int sa1100_rtc_probe(struct platform_device *pdev)
229+int sa1100_rtc_init(struct platform_device *pdev, struct sa1100_rtc *info)
227230 {
228231 struct rtc_device *rtc;
229− struct sa1100_rtc *info;
230− int irq_1hz, irq_alarm, ret = 0;
232+ int ret;
231233
232− irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
233− irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
234− if (irq_1hz < 0 || irq_alarm < 0)
235− return -ENODEV;
234+ spin_lock_init(&info->lock);
236235
237− info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL);
238− if (!info)
239− return -ENOMEM;
240236 info->clk = devm_clk_get(&pdev->dev, NULL);
241237 if (IS_ERR(info->clk)) {
242238 dev_err(&pdev->dev, "failed to find rtc clock source\n");
243239 return PTR_ERR(info->clk);
244240 }
245− info->irq_1hz = irq_1hz;
246− info->irq_alarm = irq_alarm;
247− spin_lock_init(&info->lock);
248− platform_set_drvdata(pdev, info);
249241
250242 ret = clk_prepare_enable(info->clk);
251243 if (ret)
@@ -257,22 +249,19 @@ static int sa1100_rtc_probe(struct platform_device *pdev) · 5 unmodified lines
257249 * If the clock divider is uninitialized then reset it to the
258250 * default value to get the 1Hz clock.
259251 */
260− if (RTTR == 0) {
261− RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
252+ if (readl_relaxed(info->rttr) == 0) {
253+ writel_relaxed(RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16), info->rttr);
262254 dev_warn(&pdev->dev, "warning: "
263255 "initializing default clock divider/trim value\n");
264256 /* The current RTC value probably doesn't make sense either */
265− RCNR = 0;
257+ writel_relaxed(0, info->rcnr);
266258 }
267259
268− device_init_wakeup(&pdev->dev, 1);
269−
270260 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops,
271261 THIS_MODULE);
272−
273262 if (IS_ERR(rtc)) {
274− ret = PTR_ERR(rtc);
275− goto err_dev;
263+ clk_disable_unprepare(info->clk);
264+ return PTR_ERR(rtc);
276265 }
277266 info->rtc = rtc;
278267
@@ -298,12 +287,52 @@ static int sa1100_rtc_probe(struct platform_device *pdev) · 19 unmodified lines
298287 *
299288 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to
300289 * the corresponding bits in RTSR. */
301− RTSR = RTSR_AL | RTSR_HZ;
290+ writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr);
302291
303292 return 0;
304−err_dev:
305− clk_disable_unprepare(info->clk);
306− return ret;
293+}
294+EXPORT_SYMBOL_GPL(sa1100_rtc_init);
295+
296+static int sa1100_rtc_probe(struct platform_device *pdev)
297+{
298+ struct sa1100_rtc *info;
299+ struct resource *iores;
300+ void __iomem *base;
301+ int irq_1hz, irq_alarm;
302+
303+ irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz");
304+ irq_alarm = platform_get_irq_byname(pdev, "rtc alarm");
305+ if (irq_1hz < 0 || irq_alarm < 0)
306+ return -ENODEV;
307+
308+ info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL);
309+ if (!info)
310+ return -ENOMEM;
311+ info->irq_1hz = irq_1hz;
312+ info->irq_alarm = irq_alarm;
313+
314+ iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
315+ base = devm_ioremap_resource(&pdev->dev, iores);
316+ if (IS_ERR(base))
317+ return PTR_ERR(base);
318+
319+ if (IS_ENABLED(CONFIG_ARCH_SA1100) ||
320+ of_device_is_compatible(pdev->dev.of_node, "mrvl,sa1100-rtc")) {
321+ info->rcnr = base + 0x04;
322+ info->rtsr = base + 0x10;
323+ info->rtar = base + 0x00;
324+ info->rttr = base + 0x08;
325+ } else {
326+ info->rcnr = base + 0x0;
327+ info->rtsr = base + 0x8;
328+ info->rtar = base + 0x4;
329+ info->rttr = base + 0xc;
330+ }
331+
332+ platform_set_drvdata(pdev, info);
333+ device_init_wakeup(&pdev->dev, 1);
334+
335+ return sa1100_rtc_init(pdev, info);
307336 }
308337
309338 static int sa1100_rtc_remove(struct platform_device *pdev)
drivers/rtc/rtc-sa1100.h+23−0
@@ -0,0 +1,23 @@
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
drivers/rtc/rtc-sirfsoc.c+64−43
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/slab.h>
1414 #include <linux/io.h>
1515 #include <linux/of.h>
16+#include <linux/regmap.h>
1617 #include <linux/rtc/sirfsoc_rtciobrg.h>
1718
1819
@@ -48,12 +49,27 @@ struct sirfsoc_rtc_drv { · 29 unmodified lines
4849 /* Overflow for every 8 years extra time */
4950 u32 overflow_rtc;
5051 spinlock_t lock;
52+ struct regmap *regmap;
5153 #ifdef CONFIG_PM
5254 u32 saved_counter;
5355 u32 saved_overflow_rtc;
5456 #endif
5557 };
5658
59+static u32 sirfsoc_rtc_readl(struct sirfsoc_rtc_drv *rtcdrv, u32 offset)
60+{
61+ u32 val;
62+
63+ regmap_read(rtcdrv->regmap, rtcdrv->rtc_base + offset, &val);
64+ return val;
65+}
66+
67+static void sirfsoc_rtc_writel(struct sirfsoc_rtc_drv *rtcdrv,
68+ u32 offset, u32 val)
69+{
70+ regmap_write(rtcdrv->regmap, rtcdrv->rtc_base + offset, val);
71+}
72+
5773 static int sirfsoc_rtc_read_alarm(struct device *dev,
5874 struct rtc_wkalrm *alrm)
5975 {
@@ -64,9 +80,9 @@ static int sirfsoc_rtc_read_alarm(struct device *dev, · 4 unmodified lines
6480
6581 spin_lock_irq(&rtcdrv->lock);
6682
67− rtc_count = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
83+ rtc_count = sirfsoc_rtc_readl(rtcdrv, RTC_CN);
6884
69− rtc_alarm = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_ALARM0);
85+ rtc_alarm = sirfsoc_rtc_readl(rtcdrv, RTC_ALARM0);
7086 memset(alrm, 0, sizeof(struct rtc_wkalrm));
7187
7288 /*
@@ -82,8 +98,7 @@ static int sirfsoc_rtc_read_alarm(struct device *dev, · 9 unmodified lines
8298 rtc_time_to_tm(rtcdrv->overflow_rtc
8399 << (BITS_PER_LONG - RTC_SHIFT)
84100 | rtc_alarm >> RTC_SHIFT, &(alrm->time));
85− if (sirfsoc_rtc_iobrg_readl(
86− rtcdrv->rtc_base + RTC_STATUS) & SIRFSOC_RTC_AL0E)
101+ if (sirfsoc_rtc_readl(rtcdrv, RTC_STATUS) & SIRFSOC_RTC_AL0E)
87102 alrm->enabled = 1;
88103
89104 spin_unlock_irq(&rtcdrv->lock);
@@ -103,8 +118,7 @@ static int sirfsoc_rtc_set_alarm(struct device *dev, · 13 unmodified lines
103118
104119 spin_lock_irq(&rtcdrv->lock);
105120
106− rtc_status_reg = sirfsoc_rtc_iobrg_readl(
107− rtcdrv->rtc_base + RTC_STATUS);
121+ rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS);
108122 if (rtc_status_reg & SIRFSOC_RTC_AL0E) {
109123 /*
110124 * An ongoing alarm in progress - ingore it and not
@@ -113,8 +127,7 @@ static int sirfsoc_rtc_set_alarm(struct device *dev, · 2 unmodified lines
113127 dev_info(dev, "An old alarm was set, will be replaced by a new one\n");
114128 }
115129
116− sirfsoc_rtc_iobrg_writel(
117− rtc_alarm << RTC_SHIFT, rtcdrv->rtc_base + RTC_ALARM0);
130+ sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, rtc_alarm << RTC_SHIFT);
118131 rtc_status_reg &= ~0x07; /* mask out the lower status bits */
119132 /*
120133 * This bit RTC_AL sets it as a wake-up source for Sleep Mode
@@ -123,8 +136,7 @@ static int sirfsoc_rtc_set_alarm(struct device *dev, · 2 unmodified lines
123136 rtc_status_reg |= SIRFSOC_RTC_AL0;
124137 /* enable the RTC alarm interrupt */
125138 rtc_status_reg |= SIRFSOC_RTC_AL0E;
126− sirfsoc_rtc_iobrg_writel(
127− rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS);
139+ sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg);
128140
129141 spin_unlock_irq(&rtcdrv->lock);
130142 } else {
@@ -135,8 +147,7 @@ static int sirfsoc_rtc_set_alarm(struct device *dev, · 4 unmodified lines
135147 */
136148 spin_lock_irq(&rtcdrv->lock);
137149
138− rtc_status_reg = sirfsoc_rtc_iobrg_readl(
139− rtcdrv->rtc_base + RTC_STATUS);
150+ rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS);
140151 if (rtc_status_reg & SIRFSOC_RTC_AL0E) {
141152 /* clear the RTC status register's alarm bit */
142153 rtc_status_reg &= ~0x07;
@@ -145,8 +156,8 @@ static int sirfsoc_rtc_set_alarm(struct device *dev, · 2 unmodified lines
145156 /* Clear the Alarm enable bit */
146157 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E);
147158
148− sirfsoc_rtc_iobrg_writel(rtc_status_reg,
149− rtcdrv->rtc_base + RTC_STATUS);
159+ sirfsoc_rtc_writel(rtcdrv, RTC_STATUS,
160+ rtc_status_reg);
150161 }
151162
152163 spin_unlock_irq(&rtcdrv->lock);
@@ -167,9 +178,9 @@ static int sirfsoc_rtc_read_time(struct device *dev, · 14 unmodified lines
167178 * fail, read several times to make sure get stable value.
168179 */
169180 do {
170− tmp_rtc = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
181+ tmp_rtc = sirfsoc_rtc_readl(rtcdrv, RTC_CN);
171182 cpu_relax();
172− } while (tmp_rtc != sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN));
183+ } while (tmp_rtc != sirfsoc_rtc_readl(rtcdrv, RTC_CN));
173184
174185 rtc_time_to_tm(rtcdrv->overflow_rtc << (BITS_PER_LONG - RTC_SHIFT) |
175186 tmp_rtc >> RTC_SHIFT, tm);
@@ -187,10 +198,8 @@ static int sirfsoc_rtc_set_time(struct device *dev, · 11 unmodified lines
187198
188199 rtcdrv->overflow_rtc = rtc_time >> (BITS_PER_LONG - RTC_SHIFT);
189200
190− sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc,
191− rtcdrv->rtc_base + RTC_SW_VALUE);
192− sirfsoc_rtc_iobrg_writel(
193− rtc_time << RTC_SHIFT, rtcdrv->rtc_base + RTC_CN);
201+ sirfsoc_rtc_writel(rtcdrv, RTC_SW_VALUE, rtcdrv->overflow_rtc);
202+ sirfsoc_rtc_writel(rtcdrv, RTC_CN, rtc_time << RTC_SHIFT);
194203
195204 return 0;
196205 }
@@ -222,14 +231,13 @@ static int sirfsoc_rtc_alarm_irq_enable(struct device *dev, · 25 unmodified lines
222231
223232 spin_lock_irq(&rtcdrv->lock);
224233
225− rtc_status_reg = sirfsoc_rtc_iobrg_readl(
226− rtcdrv->rtc_base + RTC_STATUS);
234+ rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS);
227235 if (enabled)
228236 rtc_status_reg |= SIRFSOC_RTC_AL0E;
229237 else
230238 rtc_status_reg &= ~SIRFSOC_RTC_AL0E;
231239
232− sirfsoc_rtc_iobrg_writel(rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS);
240+ sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg);
233241
234242 spin_unlock_irq(&rtcdrv->lock);
235243
@@ -254,7 +262,7 @@ static irqreturn_t sirfsoc_rtc_irq_handler(int irq, void *pdata) · 18 unmodified lines
254262
255263 spin_lock(&rtcdrv->lock);
256264
257− rtc_status_reg = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_STATUS);
265+ rtc_status_reg = sirfsoc_rtc_readl(rtcdrv, RTC_STATUS);
258266 /* this bit will be set ONLY if an alarm was active
259267 * and it expired NOW
260268 * So this is being used as an ASSERT
@@ -270,7 +278,8 @@ static irqreturn_t sirfsoc_rtc_irq_handler(int irq, void *pdata) · 9 unmodified lines
270278 /* Clear the Alarm enable bit */
271279 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E);
272280 }
273− sirfsoc_rtc_iobrg_writel(rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS);
281+
282+ sirfsoc_rtc_writel(rtcdrv, RTC_STATUS, rtc_status_reg);
274283
275284 spin_unlock(&rtcdrv->lock);
276285
@@ -287,6 +296,13 @@ static const struct of_device_id sirfsoc_rtc_of_match[] = { · 10 unmodified lines
287296 { .compatible = "sirf,prima2-sysrtc"},
288297 {},
289298 };
299+
300+const struct regmap_config sysrtc_regmap_config = {
301+ .reg_bits = 32,
302+ .val_bits = 32,
303+ .fast_io = true,
304+};
305+
290306 MODULE_DEVICE_TABLE(of, sirfsoc_rtc_of_match);
291307
292308 static int sirfsoc_rtc_probe(struct platform_device *pdev)
@@ -314,27 +330,35 @@ static int sirfsoc_rtc_probe(struct platform_device *pdev) · 21 unmodified lines
314330 /* Register rtc alarm as a wakeup source */
315331 device_init_wakeup(&pdev->dev, 1);
316332
333+ rtcdrv->regmap = devm_regmap_init_iobg(&pdev->dev,
334+ &sysrtc_regmap_config);
335+ if (IS_ERR(rtcdrv->regmap)) {
336+ err = PTR_ERR(rtcdrv->regmap);
337+ dev_err(&pdev->dev, "Failed to allocate register map: %d\n",
338+ err);
339+ return err;
340+ }
341+
317342 /*
318343 * Set SYS_RTC counter in RTC_HZ HZ Units
319344 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1
320345 * If 16HZ, therefore RTC_DIV = 1023;
321346 */
322347 rtc_div = ((32768 / RTC_HZ) / 2) - 1;
323− sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
348+ sirfsoc_rtc_writel(rtcdrv, RTC_DIV, rtc_div);
324349
325350 /* 0x3 -> RTC_CLK */
326− sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK,
327− rtcdrv->rtc_base + RTC_CLOCK_SWITCH);
351+ sirfsoc_rtc_writel(rtcdrv, RTC_CLOCK_SWITCH, SIRFSOC_RTC_CLK);
328352
329353 /* reset SYS RTC ALARM0 */
330− sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0);
354+ sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, 0x0);
331355
332356 /* reset SYS RTC ALARM1 */
333− sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1);
357+ sirfsoc_rtc_writel(rtcdrv, RTC_ALARM1, 0x0);
334358
335359 /* Restore RTC Overflow From Register After Command Reboot */
336360 rtcdrv->overflow_rtc =
337− sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE);
361+ sirfsoc_rtc_readl(rtcdrv, RTC_SW_VALUE);
338362
339363 rtcdrv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
340364 &sirfsoc_rtc_ops, THIS_MODULE);
@@ -372,10 +396,10 @@ static int sirfsoc_rtc_suspend(struct device *dev) · 31 unmodified lines
372396 {
373397 struct sirfsoc_rtc_drv *rtcdrv = dev_get_drvdata(dev);
374398 rtcdrv->overflow_rtc =
375− sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE);
399+ sirfsoc_rtc_readl(rtcdrv, RTC_SW_VALUE);
376400
377401 rtcdrv->saved_counter =
378− sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
402+ sirfsoc_rtc_readl(rtcdrv, RTC_CN);
379403 rtcdrv->saved_overflow_rtc = rtcdrv->overflow_rtc;
380404 if (device_may_wakeup(dev) && !enable_irq_wake(rtcdrv->irq))
381405 rtcdrv->irq_wake = 1;
@@ -392,12 +416,10 @@ static int sirfsoc_rtc_resume(struct device *dev) · 10 unmodified lines
392416 * if resume from snapshot and the rtc power is lost,
393417 * restroe the rtc settings
394418 */
395− if (SIRFSOC_RTC_CLK != sirfsoc_rtc_iobrg_readl(
396− rtcdrv->rtc_base + RTC_CLOCK_SWITCH)) {
419+ if (SIRFSOC_RTC_CLK != sirfsoc_rtc_readl(rtcdrv, RTC_CLOCK_SWITCH)) {
397420 u32 rtc_div;
398421 /* 0x3 -> RTC_CLK */
399− sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK,
400− rtcdrv->rtc_base + RTC_CLOCK_SWITCH);
422+ sirfsoc_rtc_writel(rtcdrv, RTC_CLOCK_SWITCH, SIRFSOC_RTC_CLK);
401423 /*
402424 * Set SYS_RTC counter in RTC_HZ HZ Units
403425 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1
@@ -405,13 +427,13 @@ static int sirfsoc_rtc_resume(struct device *dev) · 1 unmodified line
405427 */
406428 rtc_div = ((32768 / RTC_HZ) / 2) - 1;
407429
408− sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
430+ sirfsoc_rtc_writel(rtcdrv, RTC_DIV, rtc_div);
409431
410432 /* reset SYS RTC ALARM0 */
411− sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0);
433+ sirfsoc_rtc_writel(rtcdrv, RTC_ALARM0, 0x0);
412434
413435 /* reset SYS RTC ALARM1 */
414− sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1);
436+ sirfsoc_rtc_writel(rtcdrv, RTC_ALARM1, 0x0);
415437 }
416438 rtcdrv->overflow_rtc = rtcdrv->saved_overflow_rtc;
417439
@@ -419,15 +441,14 @@ static int sirfsoc_rtc_resume(struct device *dev) · 1 unmodified line
419441 * if current counter is small than previous,
420442 * it means overflow in sleep
421443 */
422− tmp = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
444+ tmp = sirfsoc_rtc_readl(rtcdrv, RTC_CN);
423445 if (tmp <= rtcdrv->saved_counter)
424446 rtcdrv->overflow_rtc++;
425447 /*
426448 *PWRC Value Be Changed When Suspend, Restore Overflow
427449 * In Memory To Register
428450 */
429− sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc,
430− rtcdrv->rtc_base + RTC_SW_VALUE);
451+ sirfsoc_rtc_writel(rtcdrv, RTC_SW_VALUE, rtcdrv->overflow_rtc);
431452
432453 if (device_may_wakeup(dev) && rtcdrv->irq_wake) {
433454 disable_irq_wake(rtcdrv->irq);
drivers/rtc/rtc-stk17ta8.c+2−2
@@ -254,7 +254,7 @@ static ssize_t stk17ta8_nvram_read(struct file *filp, struct kobject *kobj, · 253 unmodified lines
254254 void __iomem *ioaddr = pdata->ioaddr;
255255 ssize_t count;
256256
257− for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
257+ for (count = 0; count < size; count++)
258258 *buf++ = readb(ioaddr + pos++);
259259 return count;
260260 }
@@ -269,7 +269,7 @@ static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj, · 8 unmodified lines
269269 void __iomem *ioaddr = pdata->ioaddr;
270270 ssize_t count;
271271
272− for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
272+ for (count = 0; count < size; count++)
273273 writeb(*buf++, ioaddr + pos++);
274274 return count;
275275 }
drivers/rtc/rtc-sysfs.c+36−36
@@ -122,20 +122,8 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf) · 121 unmodified lines
122122 }
123123 static DEVICE_ATTR_RO(hctosys);
124124
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−
136125 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)
139127 {
140128 ssize_t retval;
141129 unsigned long alarm;
@@ -159,7 +147,7 @@ rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr, · 17 unmodified lines
159147 }
160148
161149 static ssize_t
162−rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
150+wakealarm_store(struct device *dev, struct device_attribute *attr,
163151 const char *buf, size_t n)
164152 {
165153 ssize_t retval;
@@ -221,45 +209,57 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr, · 55 unmodified lines
221209 retval = rtc_set_alarm(rtc, &alm);
222210 return (retval < 0) ? retval : n;
223211 }
224−static DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
225− rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm);
212+static DEVICE_ATTR_RW(wakealarm);
226213
214+static struct attribute *rtc_attrs[] = {
215+ &dev_attr_name.attr,
216+ &dev_attr_date.attr,
217+ &dev_attr_time.attr,
218+ &dev_attr_since_epoch.attr,
219+ &dev_attr_max_user_freq.attr,
220+ &dev_attr_hctosys.attr,
221+ &dev_attr_wakealarm.attr,
222+ NULL,
223+};
227224
228225 /* The reason to trigger an alarm with no process watching it (via sysfs)
229226 * is its side effect: waking from a system state like suspend-to-RAM or
230227 * suspend-to-disk. So: no attribute unless that side effect is possible.
231228 * (Userspace may disable that mechanism later.)
232229 */
233−static inline int rtc_does_wakealarm(struct rtc_device *rtc)
230+static bool rtc_does_wakealarm(struct rtc_device *rtc)
234231 {
235232 if (!device_can_wakeup(rtc->dev.parent))
236− return 0;
233+ return false;
234+
237235 return rtc->ops->set_alarm != NULL;
238236 }
239237
240−
241−void rtc_sysfs_add_device(struct rtc_device *rtc)
238+static umode_t rtc_attr_is_visible(struct kobject *kobj,
239+ struct attribute *attr, int n)
242240 {
243− int err;
241+ struct device *dev = container_of(kobj, struct device, kobj);
242+ struct rtc_device *rtc = to_rtc_device(dev);
243+ umode_t mode = attr->mode;
244244
245− /* not all RTCs support both alarms and wakeup */
246− if (!rtc_does_wakealarm(rtc))
247− return;
245+ if (attr == &dev_attr_wakealarm.attr)
246+ if (!rtc_does_wakealarm(rtc))
247+ mode = 0;
248248
249− err = device_create_file(&rtc->dev, &dev_attr_wakealarm);
250− if (err)
251− dev_err(rtc->dev.parent,
252− "failed to create alarm attribute, %d\n", err);
249+ return mode;
253250 }
254251
255−void rtc_sysfs_del_device(struct rtc_device *rtc)
256−{
257− /* REVISIT did we add it successfully? */
258− if (rtc_does_wakealarm(rtc))
259− device_remove_file(&rtc->dev, &dev_attr_wakealarm);
260−}
252+static struct attribute_group rtc_attr_group = {
253+ .is_visible = rtc_attr_is_visible,
254+ .attrs = rtc_attrs,
255+};
256+
257+static const struct attribute_group *rtc_attr_groups[] = {
258+ &rtc_attr_group,
259+ NULL
260+};
261261
262−void __init rtc_sysfs_init(struct class *rtc_class)
262+const struct attribute_group **rtc_get_dev_attribute_groups(void)
263263 {
264− rtc_class->dev_groups = rtc_groups;
264+ return rtc_attr_groups;
265265 }
drivers/rtc/rtc-tx4939.c+2−4
@@ -199,8 +199,7 @@ static ssize_t tx4939_rtc_nvram_read(struct file *filp, struct kobject *kobj, · 198 unmodified lines
199199 ssize_t count;
200200
201201 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++) {
204203 __raw_writel(pos++, &rtcreg->adr);
205204 *buf++ = __raw_readl(&rtcreg->dat);
206205 }
@@ -218,8 +217,7 @@ static ssize_t tx4939_rtc_nvram_write(struct file *filp, struct kobject *kobj, · 11 unmodified lines
218217 ssize_t count;
219218
220219 spin_lock_irq(&pdata->lock);
221− for (count = 0; size > 0 && pos < TX4939_RTC_REG_RAMSIZE;
222− count++, size--) {
220+ for (count = 0; count < size; count++) {
223221 __raw_writel(pos++, &rtcreg->adr);
224222 __raw_writel(*buf++, &rtcreg->dat);
225223 }
drivers/rtc/rtc-vt8500.c+1−0
@@ -271,6 +271,7 @@ static const struct of_device_id wmt_dt_ids[] = { · 270 unmodified lines
271271 { .compatible = "via,vt8500-rtc", },
272272 {}
273273 };
274+MODULE_DEVICE_TABLE(of, wmt_dt_ids);
274275
275276 static struct platform_driver vt8500_rtc_driver = {
276277 .probe = vt8500_rtc_probe,
drivers/rtc/rtc-zynqmp.c+279−0
@@ -0,0 +1,279 @@
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");
include/asm-generic/rtc.h+29−0
@@ -16,6 +16,9 @@ · 15 unmodified lines
1616 #include <linux/rtc.h>
1717 #include <linux/bcd.h>
1818 #include <linux/delay.h>
19+#ifdef CONFIG_ACPI
20+#include <linux/acpi.h>
21+#endif
1922
2023 #define RTC_PIE 0x40 /* periodic interrupt enable */
2124 #define RTC_AIE 0x20 /* alarm interrupt enable */
@@ -46,6 +49,7 @@ static inline unsigned int __get_rtc_time(struct rtc_time *time) · 24 unmodified lines
4649 {
4750 unsigned char ctrl;
4851 unsigned long flags;
52+ unsigned char century = 0;
4953
5054 #ifdef CONFIG_MACH_DECSTATION
5155 unsigned int real_year;
@@ -78,6 +82,11 @@ static inline unsigned int __get_rtc_time(struct rtc_time *time) · 26 unmodified lines
7882 time->tm_year = CMOS_READ(RTC_YEAR);
7983 #ifdef CONFIG_MACH_DECSTATION
8084 real_year = CMOS_READ(RTC_DEC_YEAR);
85+#endif
86+#ifdef CONFIG_ACPI
87+ if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
88+ acpi_gbl_FADT.century)
89+ century = CMOS_READ(acpi_gbl_FADT.century);
8190 #endif
8291 ctrl = CMOS_READ(RTC_CONTROL);
8392 spin_unlock_irqrestore(&rtc_lock, flags);
@@ -90,12 +99,16 @@ static inline unsigned int __get_rtc_time(struct rtc_time *time) · 6 unmodified lines
9099 time->tm_mday = bcd2bin(time->tm_mday);
91100 time->tm_mon = bcd2bin(time->tm_mon);
92101 time->tm_year = bcd2bin(time->tm_year);
102+ century = bcd2bin(century);
93103 }
94104
95105 #ifdef CONFIG_MACH_DECSTATION
96106 time->tm_year += real_year - 72;
97107 #endif
98108
109+ if (century)
110+ time->tm_year += (century - 19) * 100;
111+
99112 /*
100113 * Account for differences between how the RTC uses the values
101114 * and how they are defined in a struct rtc_time;
@@ -122,6 +135,7 @@ static inline int __set_rtc_time(struct rtc_time *time) · 20 unmodified lines
122135 #ifdef CONFIG_MACH_DECSTATION
123136 unsigned int real_yrs, leap_yr;
124137 #endif
138+ unsigned char century = 0;
125139
126140 yrs = time->tm_year;
127141 mon = time->tm_mon + 1; /* tm_mon starts at zero */
@@ -150,6 +164,15 @@ static inline int __set_rtc_time(struct rtc_time *time) · 22 unmodified lines
150164 yrs = 73;
151165 }
152166 #endif
167+
168+#ifdef CONFIG_ACPI
169+ if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
170+ acpi_gbl_FADT.century) {
171+ century = (yrs + 1900) / 100;
172+ yrs %= 100;
173+ }
174+#endif
175+
153176 /* These limits and adjustments are independent of
154177 * whether the chip is in binary mode or not.
155178 */
@@ -169,6 +192,7 @@ static inline int __set_rtc_time(struct rtc_time *time) · 13 unmodified lines
169192 day = bin2bcd(day);
170193 mon = bin2bcd(mon);
171194 yrs = bin2bcd(yrs);
195+ century = bin2bcd(century);
172196 }
173197
174198 save_control = CMOS_READ(RTC_CONTROL);
@@ -185,6 +209,11 @@ static inline int __set_rtc_time(struct rtc_time *time) · 10 unmodified lines
185209 CMOS_WRITE(hrs, RTC_HOURS);
186210 CMOS_WRITE(min, RTC_MINUTES);
187211 CMOS_WRITE(sec, RTC_SECONDS);
212+#ifdef CONFIG_ACPI
213+ if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID &&
214+ acpi_gbl_FADT.century)
215+ CMOS_WRITE(century, acpi_gbl_FADT.century);
216+#endif
188217
189218 CMOS_WRITE(save_control, RTC_CONTROL);
190219 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);