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

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

Pull RTC updates from Alexandre Belloni:
"RTC for 4.8

Cleanups:
- huge cleanup of rtc-generic and char/genrtc this allowed to cleanup
rtc-cmos, rtc-sh, rtc-m68k, rtc-powerpc and rtc-parisc
- move mn10300 to rtc-cmos

Subsystem:
- fix wakealarms after hibernate
- multiples fixes for rctest
- simplify implementations of .read_alarm

New drivers:
- Maxim MAX6916

Drivers:
- ds1307: fix weekday
- m41t80: add wakeup support
- pcf85063: add support for PCF85063A variant
- rv8803: extend i2c fix and other fixes
- s35390a: fix alarm reading, this fixes instant reboot after
shutdown for QNAP TS-41x
- s3c: clock fixes"

* tag 'rtc-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (65 commits)
rtc: rv8803: Clear V1F when setting the time
rtc: rv8803: Stop the clock while setting the time
rtc: rv8803: Always apply the I²C workaround
rtc: rv8803: Fix read day of week
rtc: rv8803: Remove the check for valid time
rtc: rv8803: Kconfig: Indicate rx8900 support
rtc: asm9260: remove .owner field for driver
rtc: at91sam9: Fix missing spin_lock_init()
rtc: m41t80: add suspend handlers for alarm IRQ
rtc: m41t80: make it a real error message
rtc: pcf85063: Add support for the PCF85063A device
rtc: pcf85063: fix year range
rtc: hym8563: in .read_alarm set .tm_sec to 0 to signal minute accuracy
rtc: explicitly set tm_sec = 0 for drivers with minute accurancy
rtc: s3c: Add s3c_rtc_{enable/disable}_clk in s3c_rtc_setfreq()
rtc: s3c: Remove unnecessary call to disable already disabled clock
rtc: abx80x: use devm_add_action_or_reset()
rtc: m41t80: use devm_add_action_or_reset()
rtc: fix a typo and reduce three empty lines to one
rtc: s35390a: improve two comments in .set_alarm
...

+848 -1580
+4
MAINTAINERS
··· 9828 9828 Q: http://patchwork.ozlabs.org/project/rtc-linux/list/ 9829 9829 T: git git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git 9830 9830 S: Maintained 9831 + F: Documentation/devicetree/bindings/rtc/ 9831 9832 F: Documentation/rtc.txt 9832 9833 F: drivers/rtc/ 9833 9834 F: include/linux/rtc.h 9834 9835 F: include/uapi/linux/rtc.h 9836 + F: include/linux/rtc/ 9837 + F: include/linux/platform_data/rtc-* 9838 + F: tools/testing/selftests/timers/rtctest.c 9835 9839 9836 9840 REALTEK AUDIO CODECS 9837 9841 M: Bard Liao <bardliao@realtek.com>
-1
arch/alpha/include/asm/rtc.h
··· 1 - #include <asm-generic/rtc.h>
-1
arch/alpha/kernel/core_marvel.c
··· 24 24 #include <asm/gct.h> 25 25 #include <asm/pgalloc.h> 26 26 #include <asm/tlbflush.h> 27 - #include <asm/rtc.h> 28 27 #include <asm/vga.h> 29 28 30 29 #include "proto.h"
+2 -4
arch/alpha/kernel/rtc.c
··· 15 15 #include <linux/rtc.h> 16 16 #include <linux/platform_device.h> 17 17 18 - #include <asm/rtc.h> 19 - 20 18 #include "proto.h" 21 19 22 20 ··· 79 81 static int 80 82 alpha_rtc_read_time(struct device *dev, struct rtc_time *tm) 81 83 { 82 - __get_rtc_time(tm); 84 + mc146818_get_time(tm); 83 85 84 86 /* Adjust for non-default epochs. It's easier to depend on the 85 87 generic __get_rtc_time and adjust the epoch here than create ··· 110 112 tm = &xtm; 111 113 } 112 114 113 - return __set_rtc_time(tm); 115 + return mc146818_set_time(tm); 114 116 } 115 117 116 118 static int
+1 -1
arch/arm/mach-ep93xx/ts72xx.c
··· 16 16 #include <linux/init.h> 17 17 #include <linux/platform_device.h> 18 18 #include <linux/io.h> 19 - #include <linux/m48t86.h> 19 + #include <linux/platform_data/rtc-m48t86.h> 20 20 #include <linux/mtd/nand.h> 21 21 #include <linux/mtd/partitions.h> 22 22
+1 -1
arch/arm/mach-orion5x/ts78xx-setup.c
··· 16 16 #include <linux/platform_device.h> 17 17 #include <linux/mv643xx_eth.h> 18 18 #include <linux/ata_platform.h> 19 - #include <linux/m48t86.h> 19 + #include <linux/platform_data/rtc-m48t86.h> 20 20 #include <linux/mtd/nand.h> 21 21 #include <linux/mtd/partitions.h> 22 22 #include <linux/timeriomem-rng.h>
+1 -1
arch/arm/mach-pxa/cm-x270.c
··· 14 14 #include <linux/gpio.h> 15 15 #include <linux/delay.h> 16 16 17 - #include <linux/rtc-v3020.h> 17 + #include <linux/platform_data/rtc-v3020.h> 18 18 #include <video/mbxfb.h> 19 19 20 20 #include <linux/spi/spi.h>
+1 -1
arch/arm/mach-pxa/cm-x300.c
··· 25 25 #include <linux/gpio.h> 26 26 #include <linux/dm9000.h> 27 27 #include <linux/leds.h> 28 - #include <linux/rtc-v3020.h> 28 + #include <linux/platform_data/rtc-v3020.h> 29 29 #include <linux/pwm.h> 30 30 #include <linux/pwm_backlight.h> 31 31
+1 -1
arch/arm/mach-pxa/em-x270.c
··· 14 14 #include <linux/delay.h> 15 15 16 16 #include <linux/dm9000.h> 17 - #include <linux/rtc-v3020.h> 17 + #include <linux/platform_data/rtc-v3020.h> 18 18 #include <linux/mtd/nand.h> 19 19 #include <linux/mtd/partitions.h> 20 20 #include <linux/mtd/physmap.h>
-16
arch/frv/include/asm/mc146818rtc.h
··· 1 - /* mc146818rtc.h: RTC defs 2 - * 3 - * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved. 4 - * Written by David Howells (dhowells@redhat.com) 5 - * 6 - * This program is free software; you can redistribute it and/or 7 - * modify it under the terms of the GNU General Public License 8 - * as published by the Free Software Foundation; either version 9 - * 2 of the License, or (at your option) any later version. 10 - */ 11 - 12 - #ifndef _ASM_MC146818RTC_H 13 - #define _ASM_MC146818RTC_H 14 - 15 - 16 - #endif /* _ASM_MC146818RTC_H */
-9
arch/h8300/include/asm/mc146818rtc.h
··· 1 - /* 2 - * Machine dependent access functions for RTC registers. 3 - */ 4 - #ifndef _H8300_MC146818RTC_H 5 - #define _H8300_MC146818RTC_H 6 - 7 - /* empty include file to satisfy the include in genrtc.c/ide-geometry.c */ 8 - 9 - #endif /* _H8300_MC146818RTC_H */
-10
arch/ia64/include/asm/mc146818rtc.h
··· 1 - #ifndef _ASM_IA64_MC146818RTC_H 2 - #define _ASM_IA64_MC146818RTC_H 3 - 4 - /* 5 - * Machine dependent access functions for RTC registers. 6 - */ 7 - 8 - /* empty include file to satisfy the include in genrtc.c */ 9 - 10 - #endif /* _ASM_IA64_MC146818RTC_H */
-1
arch/m68k/amiga/config.c
··· 35 35 #include <asm/amigahw.h> 36 36 #include <asm/amigaints.h> 37 37 #include <asm/irq.h> 38 - #include <asm/rtc.h> 39 38 #include <asm/machdep.h> 40 39 #include <asm/io.h> 41 40
-1
arch/m68k/apollo/config.c
··· 15 15 #include <asm/pgtable.h> 16 16 #include <asm/apollohw.h> 17 17 #include <asm/irq.h> 18 - #include <asm/rtc.h> 19 18 #include <asm/machdep.h> 20 19 21 20 u_long sio01_physaddr;
-1
arch/m68k/bvme6000/config.c
··· 34 34 #include <asm/setup.h> 35 35 #include <asm/irq.h> 36 36 #include <asm/traps.h> 37 - #include <asm/rtc.h> 38 37 #include <asm/machdep.h> 39 38 #include <asm/bvme6000hw.h> 40 39
+1 -1
arch/m68k/hp300/config.c
··· 12 12 #include <linux/string.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/console.h> 15 + #include <linux/rtc.h> 15 16 16 17 #include <asm/bootinfo.h> 17 18 #include <asm/bootinfo-hp300.h> ··· 21 20 #include <asm/blinken.h> 22 21 #include <asm/io.h> /* readb() and writeb() */ 23 22 #include <asm/hp300hw.h> 24 - #include <asm/rtc.h> 25 23 26 24 #include "time.h" 27 25
-79
arch/m68k/include/asm/rtc.h
··· 1 - /* include/asm-m68k/rtc.h 2 - * 3 - * Copyright Richard Zidlicky 4 - * implementation details for genrtc/q40rtc driver 5 - */ 6 - /* permission is hereby granted to copy, modify and redistribute this code 7 - * in terms of the GNU Library General Public License, Version 2 or later, 8 - * at your option. 9 - */ 10 - 11 - #ifndef _ASM_RTC_H 12 - #define _ASM_RTC_H 13 - 14 - #ifdef __KERNEL__ 15 - 16 - #include <linux/rtc.h> 17 - #include <asm/errno.h> 18 - #include <asm/machdep.h> 19 - 20 - #define RTC_PIE 0x40 /* periodic interrupt enable */ 21 - #define RTC_AIE 0x20 /* alarm interrupt enable */ 22 - #define RTC_UIE 0x10 /* update-finished interrupt enable */ 23 - 24 - /* some dummy definitions */ 25 - #define RTC_BATT_BAD 0x100 /* battery bad */ 26 - #define RTC_SQWE 0x08 /* enable square-wave output */ 27 - #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ 28 - #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 29 - #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 30 - 31 - static inline unsigned int get_rtc_time(struct rtc_time *time) 32 - { 33 - /* 34 - * Only the values that we read from the RTC are set. We leave 35 - * tm_wday, tm_yday and tm_isdst untouched. Even though the 36 - * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated 37 - * by the RTC when initially set to a non-zero value. 38 - */ 39 - if (mach_hwclk) 40 - mach_hwclk(0, time); 41 - return RTC_24H; 42 - } 43 - 44 - static inline int set_rtc_time(struct rtc_time *time) 45 - { 46 - if (mach_hwclk) 47 - return mach_hwclk(1, time); 48 - return -EINVAL; 49 - } 50 - 51 - static inline unsigned int get_rtc_ss(void) 52 - { 53 - if (mach_get_ss) 54 - return mach_get_ss(); 55 - else{ 56 - struct rtc_time h; 57 - 58 - get_rtc_time(&h); 59 - return h.tm_sec; 60 - } 61 - } 62 - 63 - static inline int get_rtc_pll(struct rtc_pll_info *pll) 64 - { 65 - if (mach_get_rtc_pll) 66 - return mach_get_rtc_pll(pll); 67 - else 68 - return -EINVAL; 69 - } 70 - static inline int set_rtc_pll(struct rtc_pll_info *pll) 71 - { 72 - if (mach_set_rtc_pll) 73 - return mach_set_rtc_pll(pll); 74 - else 75 - return -EINVAL; 76 - } 77 - #endif /* __KERNEL__ */ 78 - 79 - #endif /* _ASM__RTC_H */
+46 -2
arch/m68k/kernel/time.c
··· 86 86 } 87 87 } 88 88 89 - #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET 89 + #if defined(CONFIG_ARCH_USES_GETTIMEOFFSET) && IS_ENABLED(CONFIG_RTC_DRV_GENERIC) 90 + static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm) 91 + { 92 + mach_hwclk(0, tm); 93 + return rtc_valid_tm(tm); 94 + } 95 + 96 + static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm) 97 + { 98 + if (mach_hwclk(1, tm) < 0) 99 + return -EOPNOTSUPP; 100 + return 0; 101 + } 102 + 103 + static int rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 104 + { 105 + struct rtc_pll_info pll; 106 + struct rtc_pll_info __user *argp = (void __user *)arg; 107 + 108 + switch (cmd) { 109 + case RTC_PLL_GET: 110 + if (!mach_get_rtc_pll || mach_get_rtc_pll(&pll)) 111 + return -EINVAL; 112 + return copy_to_user(argp, &pll, sizeof pll) ? -EFAULT : 0; 113 + 114 + case RTC_PLL_SET: 115 + if (!mach_set_rtc_pll) 116 + return -EINVAL; 117 + if (!capable(CAP_SYS_TIME)) 118 + return -EACCES; 119 + if (copy_from_user(&pll, argp, sizeof(pll))) 120 + return -EFAULT; 121 + return mach_set_rtc_pll(&pll); 122 + } 123 + 124 + return -ENOIOCTLCMD; 125 + } 126 + 127 + static const struct rtc_class_ops generic_rtc_ops = { 128 + .ioctl = rtc_ioctl, 129 + .read_time = rtc_generic_get_time, 130 + .set_time = rtc_generic_set_time, 131 + }; 90 132 91 133 static int __init rtc_init(void) 92 134 { ··· 137 95 if (!mach_hwclk) 138 96 return -ENODEV; 139 97 140 - pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); 98 + pdev = platform_device_register_data(NULL, "rtc-generic", -1, 99 + &generic_rtc_ops, 100 + sizeof(generic_rtc_ops)); 141 101 return PTR_ERR_OR_ZERO(pdev); 142 102 } 143 103
+2 -1
arch/m68k/mac/config.c
··· 10 10 * Miscellaneous linux stuff 11 11 */ 12 12 13 + #include <linux/errno.h> 13 14 #include <linux/module.h> 14 15 #include <linux/types.h> 15 16 #include <linux/mm.h> ··· 26 25 #include <linux/platform_device.h> 27 26 #include <linux/adb.h> 28 27 #include <linux/cuda.h> 28 + #include <linux/rtc.h> 29 29 30 30 #include <asm/setup.h> 31 31 #include <asm/bootinfo.h> ··· 36 34 #include <asm/io.h> 37 35 #include <asm/irq.h> 38 36 #include <asm/pgtable.h> 39 - #include <asm/rtc.h> 40 37 #include <asm/machdep.h> 41 38 42 39 #include <asm/macintosh.h>
-1
arch/m68k/mac/misc.c
··· 18 18 19 19 #include <asm/uaccess.h> 20 20 #include <asm/io.h> 21 - #include <asm/rtc.h> 22 21 #include <asm/segment.h> 23 22 #include <asm/setup.h> 24 23 #include <asm/macintosh.h>
-1
arch/m68k/mvme147/config.c
··· 32 32 #include <asm/setup.h> 33 33 #include <asm/irq.h> 34 34 #include <asm/traps.h> 35 - #include <asm/rtc.h> 36 35 #include <asm/machdep.h> 37 36 #include <asm/mvme147hw.h> 38 37
-1
arch/m68k/mvme16x/config.c
··· 35 35 #include <asm/setup.h> 36 36 #include <asm/irq.h> 37 37 #include <asm/traps.h> 38 - #include <asm/rtc.h> 39 38 #include <asm/machdep.h> 40 39 #include <asm/mvme16xhw.h> 41 40
+1 -1
arch/m68k/q40/config.c
··· 12 12 * for more details. 13 13 */ 14 14 15 + #include <linux/errno.h> 15 16 #include <linux/types.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/mm.h> ··· 28 27 #include <linux/platform_device.h> 29 28 30 29 #include <asm/io.h> 31 - #include <asm/rtc.h> 32 30 #include <asm/bootinfo.h> 33 31 #include <asm/pgtable.h> 34 32 #include <asm/setup.h>
-1
arch/m68k/sun3/config.c
··· 26 26 #include <asm/pgalloc.h> 27 27 #include <asm/sun3-head.h> 28 28 #include <asm/sun3mmu.h> 29 - #include <asm/rtc.h> 30 29 #include <asm/machdep.h> 31 30 #include <asm/machines.h> 32 31 #include <asm/idprom.h>
+1 -1
arch/m68k/sun3/intersil.c
··· 14 14 #include <linux/rtc.h> 15 15 16 16 #include <asm/errno.h> 17 - #include <asm/rtc.h> 18 17 #include <asm/intersil.h> 18 + #include <asm/machdep.h> 19 19 20 20 21 21 /* bits to set for start/run of the intersil */
+1 -1
arch/m68k/sun3x/time.c
··· 15 15 16 16 #include <asm/irq.h> 17 17 #include <asm/io.h> 18 + #include <asm/machdep.h> 18 19 #include <asm/traps.h> 19 20 #include <asm/sun3x.h> 20 21 #include <asm/sun3ints.h> 21 - #include <asm/rtc.h> 22 22 23 23 #include "time.h" 24 24
+1 -1
arch/mips/sgi-ip22/ip22-reset.c
··· 7 7 */ 8 8 #include <linux/linkage.h> 9 9 #include <linux/init.h> 10 - #include <linux/ds1286.h> 10 + #include <linux/rtc/ds1286.h> 11 11 #include <linux/module.h> 12 12 #include <linux/interrupt.h> 13 13 #include <linux/kernel.h>
-1
arch/mips/sni/time.c
··· 8 8 9 9 #include <asm/sni.h> 10 10 #include <asm/time.h> 11 - #include <asm-generic/rtc.h> 12 11 13 12 #define SNI_CLOCK_TICK_RATE 3686400 14 13 #define SNI_COUNTER2_DIV 64
+3 -1
arch/mn10300/Kconfig
··· 236 236 config MN10300_RTC 237 237 bool "Using MN10300 RTC" 238 238 depends on MN10300_PROC_MN103E010 || MN10300_PROC_MN2WS0050 239 - select GENERIC_CMOS_UPDATE 239 + select RTC_CLASS 240 + select RTC_DRV_CMOS 241 + select RTC_SYSTOHC 240 242 default n 241 243 help 242 244 This option enables support for the RTC, thus enabling time to be
+2 -2
arch/mn10300/include/asm/rtc-regs.h
··· 75 75 #define RTC_PORT(x) 0xd8600000 76 76 #define RTC_ALWAYS_BCD 1 /* RTC operates in binary mode */ 77 77 78 - #define CMOS_READ(addr) __SYSREG(0xd8600000 + (addr), u8) 78 + #define CMOS_READ(addr) __SYSREG(0xd8600000 + (u32)(addr), u8) 79 79 #define CMOS_WRITE(val, addr) \ 80 - do { __SYSREG(0xd8600000 + (addr), u8) = val; } while (0) 80 + do { __SYSREG(0xd8600000 + (u32)(addr), u8) = val; } while (0) 81 81 82 82 #define RTC_IRQ RTIRQ 83 83
-2
arch/mn10300/include/asm/rtc.h
··· 25 25 26 26 #endif /* !CONFIG_MN10300_RTC */ 27 27 28 - #include <asm-generic/rtc.h> 29 - 30 28 #endif /* _ASM_RTC_H */
+9 -95
arch/mn10300/kernel/rtc.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/init.h> 14 14 #include <linux/mc146818rtc.h> 15 - #include <linux/bcd.h> 16 - #include <linux/timex.h> 15 + #include <linux/ioport.h> 16 + #include <linux/platform_device.h> 17 + 17 18 #include <asm/rtc-regs.h> 18 19 #include <asm/rtc.h> 19 20 20 21 DEFINE_SPINLOCK(rtc_lock); 21 22 EXPORT_SYMBOL(rtc_lock); 22 23 23 - /* 24 - * Read the current RTC time 25 - */ 26 - void read_persistent_clock(struct timespec *ts) 27 - { 28 - struct rtc_time tm; 29 - 30 - get_rtc_time(&tm); 31 - 32 - ts->tv_nsec = 0; 33 - ts->tv_sec = mktime(tm.tm_year, tm.tm_mon, tm.tm_mday, 34 - tm.tm_hour, tm.tm_min, tm.tm_sec); 35 - 36 - /* if rtc is way off in the past, set something reasonable */ 37 - if (ts->tv_sec < 0) 38 - ts->tv_sec = mktime(2009, 1, 1, 12, 0, 0); 39 - } 40 - 41 - /* 42 - * In order to set the CMOS clock precisely, set_rtc_mmss has to be called 500 43 - * ms after the second nowtime has started, because when nowtime is written 44 - * into the registers of the CMOS clock, it will jump to the next second 45 - * precisely 500 ms later. Check the Motorola MC146818A or Dallas DS12887 data 46 - * sheet for details. 47 - * 48 - * BUG: This routine does not handle hour overflow properly; it just 49 - * sets the minutes. Usually you'll only notice that after reboot! 50 - */ 51 - static int set_rtc_mmss(unsigned long nowtime) 52 - { 53 - unsigned char save_control, save_freq_select; 54 - int retval = 0; 55 - int real_seconds, real_minutes, cmos_minutes; 56 - 57 - /* gets recalled with irq locally disabled */ 58 - spin_lock(&rtc_lock); 59 - save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being 60 - * set */ 61 - CMOS_WRITE(save_control | RTC_SET, RTC_CONTROL); 62 - 63 - save_freq_select = CMOS_READ(RTC_FREQ_SELECT); /* stop and reset 64 - * prescaler */ 65 - CMOS_WRITE(save_freq_select | RTC_DIV_RESET2, RTC_FREQ_SELECT); 66 - 67 - cmos_minutes = CMOS_READ(RTC_MINUTES); 68 - if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) 69 - cmos_minutes = bcd2bin(cmos_minutes); 70 - 71 - /* 72 - * since we're only adjusting minutes and seconds, 73 - * don't interfere with hour overflow. This avoids 74 - * messing with unknown time zones but requires your 75 - * RTC not to be off by more than 15 minutes 76 - */ 77 - real_seconds = nowtime % 60; 78 - real_minutes = nowtime / 60; 79 - if (((abs(real_minutes - cmos_minutes) + 15) / 30) & 1) 80 - /* correct for half hour time zone */ 81 - real_minutes += 30; 82 - real_minutes %= 60; 83 - 84 - if (abs(real_minutes - cmos_minutes) < 30) { 85 - if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { 86 - real_seconds = bin2bcd(real_seconds); 87 - real_minutes = bin2bcd(real_minutes); 88 - } 89 - CMOS_WRITE(real_seconds, RTC_SECONDS); 90 - CMOS_WRITE(real_minutes, RTC_MINUTES); 91 - } else { 92 - printk_once(KERN_NOTICE 93 - "set_rtc_mmss: can't update from %d to %d\n", 94 - cmos_minutes, real_minutes); 95 - retval = -1; 96 - } 97 - 98 - /* The following flags have to be released exactly in this order, 99 - * otherwise the DS12887 (popular MC146818A clone with integrated 100 - * battery and quartz) will not reset the oscillator and will not 101 - * update precisely 500 ms later. You won't find this mentioned in 102 - * the Dallas Semiconductor data sheets, but who believes data 103 - * sheets anyway ... -- Markus Kuhn 104 - */ 105 - CMOS_WRITE(save_control, RTC_CONTROL); 106 - CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); 107 - spin_unlock(&rtc_lock); 108 - 109 - return retval; 110 - } 111 - 112 - int update_persistent_clock(struct timespec now) 113 - { 114 - return set_rtc_mmss(now.tv_sec); 115 - } 24 + static const __initdata struct resource res[] = { 25 + DEFINE_RES_IO(RTC_PORT(0), RTC_IO_EXTENT), 26 + DEFINE_RES_IRQ(RTC_IRQ), 27 + }; 116 28 117 29 /* 118 30 * calibrate the TSC clock against the RTC ··· 41 129 RTCRA |= RTCRA_DVR; 42 130 RTCRA &= ~RTCRA_DVR; 43 131 RTCRB &= ~RTCRB_SET; 132 + 133 + platform_device_register_simple("rtc_cmos", -1, res, ARRAY_SIZE(res)); 44 134 }
+3
arch/mn10300/proc-mn103e010/proc-init.c
··· 9 9 * 2 of the Licence, or (at your option) any later version. 10 10 */ 11 11 #include <linux/kernel.h> 12 + #include <linux/irq.h> 13 + #include <asm/cacheflush.h> 12 14 #include <asm/fpu.h> 15 + #include <asm/irq.h> 13 16 #include <asm/rtc.h> 14 17 #include <asm/busctl-regs.h> 15 18
+1
arch/mn10300/proc-mn2ws0050/proc-init.c
··· 14 14 #include <linux/delay.h> 15 15 #include <linux/interrupt.h> 16 16 17 + #include <asm/cacheflush.h> 17 18 #include <asm/processor.h> 18 19 #include <asm/uaccess.h> 19 20 #include <asm/io.h>
-9
arch/parisc/include/asm/mc146818rtc.h
··· 1 - /* 2 - * Machine dependent access functions for RTC registers. 3 - */ 4 - #ifndef _ASM_MC146818RTC_H 5 - #define _ASM_MC146818RTC_H 6 - 7 - /* empty include file to satisfy the include in genrtc.c */ 8 - 9 - #endif /* _ASM_MC146818RTC_H */
-131
arch/parisc/include/asm/rtc.h
··· 1 - /* 2 - * include/asm-parisc/rtc.h 3 - * 4 - * Copyright 2002 Randolph CHung <tausq@debian.org> 5 - * 6 - * Based on: include/asm-ppc/rtc.h and the genrtc driver in the 7 - * 2.4 parisc linux tree 8 - */ 9 - 10 - #ifndef __ASM_RTC_H__ 11 - #define __ASM_RTC_H__ 12 - 13 - #ifdef __KERNEL__ 14 - 15 - #include <linux/rtc.h> 16 - 17 - #include <asm/pdc.h> 18 - 19 - #define SECS_PER_HOUR (60 * 60) 20 - #define SECS_PER_DAY (SECS_PER_HOUR * 24) 21 - 22 - 23 - #define RTC_PIE 0x40 /* periodic interrupt enable */ 24 - #define RTC_AIE 0x20 /* alarm interrupt enable */ 25 - #define RTC_UIE 0x10 /* update-finished interrupt enable */ 26 - 27 - #define RTC_BATT_BAD 0x100 /* battery bad */ 28 - 29 - /* some dummy definitions */ 30 - #define RTC_SQWE 0x08 /* enable square-wave output */ 31 - #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ 32 - #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 33 - #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 34 - 35 - # define __isleap(year) \ 36 - ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) 37 - 38 - /* How many days come before each month (0-12). */ 39 - static const unsigned short int __mon_yday[2][13] = 40 - { 41 - /* Normal years. */ 42 - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, 43 - /* Leap years. */ 44 - { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } 45 - }; 46 - 47 - static inline unsigned int get_rtc_time(struct rtc_time *wtime) 48 - { 49 - struct pdc_tod tod_data; 50 - long int days, rem, y; 51 - const unsigned short int *ip; 52 - 53 - memset(wtime, 0, sizeof(*wtime)); 54 - if (pdc_tod_read(&tod_data) < 0) 55 - return RTC_24H | RTC_BATT_BAD; 56 - 57 - // most of the remainder of this function is: 58 - // Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc. 59 - // This was originally a part of the GNU C Library. 60 - // It is distributed under the GPL, and was swiped from offtime.c 61 - 62 - 63 - days = tod_data.tod_sec / SECS_PER_DAY; 64 - rem = tod_data.tod_sec % SECS_PER_DAY; 65 - 66 - wtime->tm_hour = rem / SECS_PER_HOUR; 67 - rem %= SECS_PER_HOUR; 68 - wtime->tm_min = rem / 60; 69 - wtime->tm_sec = rem % 60; 70 - 71 - y = 1970; 72 - 73 - #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) 74 - #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) 75 - 76 - while (days < 0 || days >= (__isleap (y) ? 366 : 365)) 77 - { 78 - /* Guess a corrected year, assuming 365 days per year. */ 79 - long int yg = y + days / 365 - (days % 365 < 0); 80 - 81 - /* Adjust DAYS and Y to match the guessed year. */ 82 - days -= ((yg - y) * 365 83 - + LEAPS_THRU_END_OF (yg - 1) 84 - - LEAPS_THRU_END_OF (y - 1)); 85 - y = yg; 86 - } 87 - wtime->tm_year = y - 1900; 88 - 89 - ip = __mon_yday[__isleap(y)]; 90 - for (y = 11; days < (long int) ip[y]; --y) 91 - continue; 92 - days -= ip[y]; 93 - wtime->tm_mon = y; 94 - wtime->tm_mday = days + 1; 95 - 96 - return RTC_24H; 97 - } 98 - 99 - static int set_rtc_time(struct rtc_time *wtime) 100 - { 101 - u_int32_t secs; 102 - 103 - secs = mktime(wtime->tm_year + 1900, wtime->tm_mon + 1, wtime->tm_mday, 104 - wtime->tm_hour, wtime->tm_min, wtime->tm_sec); 105 - 106 - if(pdc_tod_set(secs, 0) < 0) 107 - return -1; 108 - else 109 - return 0; 110 - 111 - } 112 - 113 - static inline unsigned int get_rtc_ss(void) 114 - { 115 - struct rtc_time h; 116 - 117 - get_rtc_time(&h); 118 - return h.tm_sec; 119 - } 120 - 121 - static inline int get_rtc_pll(struct rtc_pll_info *pll) 122 - { 123 - return -EINVAL; 124 - } 125 - static inline int set_rtc_pll(struct rtc_pll_info *pll) 126 - { 127 - return -EINVAL; 128 - } 129 - 130 - #endif /* __KERNEL__ */ 131 - #endif /* __ASM_RTC_H__ */
+35 -1
arch/parisc/kernel/time.c
··· 12 12 */ 13 13 #include <linux/errno.h> 14 14 #include <linux/module.h> 15 + #include <linux/rtc.h> 15 16 #include <linux/sched.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/param.h> ··· 249 248 per_cpu(cpu_data, cpu).it_value = next_tick; 250 249 } 251 250 251 + #if IS_ENABLED(CONFIG_RTC_DRV_GENERIC) 252 + static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm) 253 + { 254 + struct pdc_tod tod_data; 255 + 256 + memset(tm, 0, sizeof(*tm)); 257 + if (pdc_tod_read(&tod_data) < 0) 258 + return -EOPNOTSUPP; 259 + 260 + /* we treat tod_sec as unsigned, so this can work until year 2106 */ 261 + rtc_time64_to_tm(tod_data.tod_sec, tm); 262 + return rtc_valid_tm(tm); 263 + } 264 + 265 + static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm) 266 + { 267 + time64_t secs = rtc_tm_to_time64(tm); 268 + 269 + if (pdc_tod_set(secs, 0) < 0) 270 + return -EOPNOTSUPP; 271 + 272 + return 0; 273 + } 274 + 275 + static const struct rtc_class_ops rtc_generic_ops = { 276 + .read_time = rtc_generic_get_time, 277 + .set_time = rtc_generic_set_time, 278 + }; 279 + 252 280 static int __init rtc_init(void) 253 281 { 254 282 struct platform_device *pdev; 255 283 256 - pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); 284 + pdev = platform_device_register_data(NULL, "rtc-generic", -1, 285 + &rtc_generic_ops, 286 + sizeof(rtc_generic_ops)); 287 + 257 288 return PTR_ERR_OR_ZERO(pdev); 258 289 } 259 290 device_initcall(rtc_init); 291 + #endif 260 292 261 293 void read_persistent_clock(struct timespec *ts) 262 294 {
-78
arch/powerpc/include/asm/rtc.h
··· 1 - /* 2 - * Real-time clock definitions and interfaces 3 - * 4 - * Author: Tom Rini <trini@mvista.com> 5 - * 6 - * 2002 (c) MontaVista, Software, Inc. This file is licensed under 7 - * the terms of the GNU General Public License version 2. This program 8 - * is licensed "as is" without any warranty of any kind, whether express 9 - * or implied. 10 - * 11 - * Based on: 12 - * include/asm-m68k/rtc.h 13 - * 14 - * Copyright Richard Zidlicky 15 - * implementation details for genrtc/q40rtc driver 16 - * 17 - * And the old drivers/macintosh/rtc.c which was heavily based on: 18 - * Linux/SPARC Real Time Clock Driver 19 - * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu) 20 - * 21 - * With additional work by Paul Mackerras and Franz Sirl. 22 - */ 23 - 24 - #ifndef __ASM_POWERPC_RTC_H__ 25 - #define __ASM_POWERPC_RTC_H__ 26 - 27 - #ifdef __KERNEL__ 28 - 29 - #include <linux/rtc.h> 30 - 31 - #include <asm/machdep.h> 32 - #include <asm/time.h> 33 - 34 - #define RTC_PIE 0x40 /* periodic interrupt enable */ 35 - #define RTC_AIE 0x20 /* alarm interrupt enable */ 36 - #define RTC_UIE 0x10 /* update-finished interrupt enable */ 37 - 38 - /* some dummy definitions */ 39 - #define RTC_BATT_BAD 0x100 /* battery bad */ 40 - #define RTC_SQWE 0x08 /* enable square-wave output */ 41 - #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ 42 - #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 43 - #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 44 - 45 - static inline unsigned int get_rtc_time(struct rtc_time *time) 46 - { 47 - if (ppc_md.get_rtc_time) 48 - ppc_md.get_rtc_time(time); 49 - return RTC_24H; 50 - } 51 - 52 - /* Set the current date and time in the real time clock. */ 53 - static inline int set_rtc_time(struct rtc_time *time) 54 - { 55 - if (ppc_md.set_rtc_time) 56 - return ppc_md.set_rtc_time(time); 57 - return -EINVAL; 58 - } 59 - 60 - static inline unsigned int get_rtc_ss(void) 61 - { 62 - struct rtc_time h; 63 - 64 - get_rtc_time(&h); 65 - return h.tm_sec; 66 - } 67 - 68 - static inline int get_rtc_pll(struct rtc_pll_info *pll) 69 - { 70 - return -EINVAL; 71 - } 72 - static inline int set_rtc_pll(struct rtc_pll_info *pll) 73 - { 74 - return -EINVAL; 75 - } 76 - 77 - #endif /* __KERNEL__ */ 78 - #endif /* __ASM_POWERPC_RTC_H__ */
+28 -1
arch/powerpc/kernel/time.c
··· 56 56 #include <linux/irq_work.h> 57 57 #include <linux/clk-provider.h> 58 58 #include <linux/suspend.h> 59 + #include <linux/rtc.h> 59 60 #include <asm/trace.h> 60 61 61 62 #include <asm/io.h> ··· 1160 1159 loops_per_jiffy = tb_ticks_per_jiffy; 1161 1160 } 1162 1161 1162 + #if IS_ENABLED(CONFIG_RTC_DRV_GENERIC) 1163 + static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm) 1164 + { 1165 + ppc_md.get_rtc_time(tm); 1166 + return rtc_valid_tm(tm); 1167 + } 1168 + 1169 + static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm) 1170 + { 1171 + if (!ppc_md.set_rtc_time) 1172 + return -EOPNOTSUPP; 1173 + 1174 + if (ppc_md.set_rtc_time(tm) < 0) 1175 + return -EOPNOTSUPP; 1176 + 1177 + return 0; 1178 + } 1179 + 1180 + static const struct rtc_class_ops rtc_generic_ops = { 1181 + .read_time = rtc_generic_get_time, 1182 + .set_time = rtc_generic_set_time, 1183 + }; 1184 + 1163 1185 static int __init rtc_init(void) 1164 1186 { 1165 1187 struct platform_device *pdev; ··· 1190 1166 if (!ppc_md.get_rtc_time) 1191 1167 return -ENODEV; 1192 1168 1193 - pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); 1169 + pdev = platform_device_register_data(NULL, "rtc-generic", -1, 1170 + &rtc_generic_ops, 1171 + sizeof(rtc_generic_ops)); 1194 1172 1195 1173 return PTR_ERR_OR_ZERO(pdev); 1196 1174 } 1197 1175 1198 1176 device_initcall(rtc_init); 1177 + #endif
+11
arch/powerpc/platforms/Kconfig
··· 321 321 Uses information from the OF or flattened device tree to instantiate 322 322 platform devices for direct mapped RTC chips like the DS1742 or DS1743. 323 323 324 + config GEN_RTC 325 + bool "Use the platform RTC operations from user space" 326 + select RTC_CLASS 327 + select RTC_DRV_GENERIC 328 + help 329 + This option provides backwards compatibility with the old gen_rtc.ko 330 + module that was traditionally used for old PowerPC machines. 331 + Platforms should migrate to enabling the RTC_DRV_GENERIC by hand 332 + replacing their get_rtc_time/set_rtc_time callbacks with 333 + a proper RTC device driver. 334 + 324 335 config SIMPLE_GPIO 325 336 bool "Support for simple, memory-mapped GPIO controllers" 326 337 depends on PPC
+1 -1
arch/powerpc/platforms/ps3/time.c
··· 20 20 21 21 #include <linux/kernel.h> 22 22 #include <linux/platform_device.h> 23 + #include <linux/rtc.h> 23 24 24 25 #include <asm/firmware.h> 25 - #include <asm/rtc.h> 26 26 #include <asm/lv1call.h> 27 27 #include <asm/ps3.h> 28 28
-7
arch/sh/include/asm/mc146818rtc.h
··· 1 - /* 2 - * Machine dependent access functions for RTC registers. 3 - */ 4 - #ifndef _ASM_MC146818RTC_H 5 - #define _ASM_MC146818RTC_H 6 - 7 - #endif /* _ASM_MC146818RTC_H */
-11
arch/sh/include/asm/rtc.h
··· 6 6 extern void (*rtc_sh_get_time)(struct timespec *); 7 7 extern int (*rtc_sh_set_time)(const time_t); 8 8 9 - /* some dummy definitions */ 10 - #define RTC_BATT_BAD 0x100 /* battery bad */ 11 - #define RTC_SQWE 0x08 /* enable square-wave output */ 12 - #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ 13 - #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 14 - #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 15 - 16 - struct rtc_time; 17 - unsigned int get_rtc_time(struct rtc_time *); 18 - int set_rtc_time(struct rtc_time *); 19 - 20 9 #define RTC_CAP_4_DIGIT_YEAR (1 << 0) 21 10 22 11 struct sh_rtc_platform_info {
+20 -13
arch/sh/kernel/time.c
··· 50 50 } 51 51 #endif 52 52 53 - unsigned int get_rtc_time(struct rtc_time *tm) 53 + static int rtc_generic_get_time(struct device *dev, struct rtc_time *tm) 54 54 { 55 - if (rtc_sh_get_time != null_rtc_get_time) { 56 - struct timespec tv; 55 + struct timespec tv; 57 56 58 - rtc_sh_get_time(&tv); 59 - rtc_time_to_tm(tv.tv_sec, tm); 60 - } 61 - 62 - return RTC_24H; 57 + rtc_sh_get_time(&tv); 58 + rtc_time_to_tm(tv.tv_sec, tm); 59 + return 0; 63 60 } 64 - EXPORT_SYMBOL(get_rtc_time); 65 61 66 - int set_rtc_time(struct rtc_time *tm) 62 + static int rtc_generic_set_time(struct device *dev, struct rtc_time *tm) 67 63 { 68 64 unsigned long secs; 69 65 70 66 rtc_tm_to_time(tm, &secs); 71 - return rtc_sh_set_time(secs); 67 + if ((rtc_sh_set_time == null_rtc_set_time) || 68 + (rtc_sh_set_time(secs) < 0)) 69 + return -EOPNOTSUPP; 70 + 71 + return 0; 72 72 } 73 - EXPORT_SYMBOL(set_rtc_time); 73 + 74 + static const struct rtc_class_ops rtc_generic_ops = { 75 + .read_time = rtc_generic_get_time, 76 + .set_time = rtc_generic_set_time, 77 + }; 74 78 75 79 static int __init rtc_generic_init(void) 76 80 { ··· 83 79 if (rtc_sh_get_time == null_rtc_get_time) 84 80 return -ENODEV; 85 81 86 - pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0); 82 + pdev = platform_device_register_data(NULL, "rtc-generic", -1, 83 + &rtc_generic_ops, 84 + sizeof(rtc_generic_ops)); 85 + 87 86 88 87 return PTR_ERR_OR_ZERO(pdev); 89 88 }
-10
arch/sparc/include/asm/io_32.h
··· 140 140 struct pci_dev; 141 141 void pci_iounmap(struct pci_dev *dev, void __iomem *); 142 142 143 - 144 - 145 - /* 146 - * At the moment, we do not use CMOS_READ anywhere outside of rtc.c, 147 - * so rtc_port is static in it. This should not change unless a new 148 - * hardware pops up. 149 - */ 150 - #define RTC_PORT(x) (rtc_port + (x)) 151 - #define RTC_ALWAYS_BCD 0 152 - 153 143 static inline int sbus_can_dma_64bit(void) 154 144 { 155 145 return 0; /* actually, sparc_cpu_model==sun4d */
+1
arch/x86/Kconfig
··· 152 152 select OLD_SIGSUSPEND3 if X86_32 || IA32_EMULATION 153 153 select PERF_EVENTS 154 154 select RTC_LIB 155 + select RTC_MC146818_LIB 155 156 select SPARSE_IRQ 156 157 select SRCU 157 158 select SYSCTL_EXCEPTION_TRACE
-1
arch/x86/include/asm/mc146818rtc.h
··· 6 6 7 7 #include <asm/io.h> 8 8 #include <asm/processor.h> 9 - #include <linux/mc146818rtc.h> 10 9 11 10 #ifndef RTC_PORT 12 11 #define RTC_PORT(x) (0x70 + (x))
-1
arch/x86/include/asm/rtc.h
··· 1 - #include <asm-generic/rtc.h>
+1 -2
arch/x86/kernel/hpet.c
··· 1019 1019 */ 1020 1020 #include <linux/mc146818rtc.h> 1021 1021 #include <linux/rtc.h> 1022 - #include <asm/rtc.h> 1023 1022 1024 1023 #define DEFAULT_RTC_INT_FREQ 64 1025 1024 #define DEFAULT_RTC_SHIFT 6 ··· 1242 1243 memset(&curr_time, 0, sizeof(struct rtc_time)); 1243 1244 1244 1245 if (hpet_rtc_flags & (RTC_UIE | RTC_AIE)) 1245 - get_rtc_time(&curr_time); 1246 + mc146818_set_time(&curr_time); 1246 1247 1247 1248 if (hpet_rtc_flags & RTC_UIE && 1248 1249 curr_time.tm_sec != hpet_prev_update_sec) {
+1
arch/x86/kernel/nmi.c
··· 17 17 #include <linux/debugfs.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/hardirq.h> 20 + #include <linux/ratelimit.h> 20 21 #include <linux/slab.h> 21 22 #include <linux/export.h> 22 23
+1 -2
arch/x86/kernel/rtc.c
··· 13 13 #include <asm/x86_init.h> 14 14 #include <asm/time.h> 15 15 #include <asm/intel-mid.h> 16 - #include <asm/rtc.h> 17 16 #include <asm/setup.h> 18 17 19 18 #ifdef CONFIG_X86_32 ··· 46 47 47 48 rtc_time_to_tm(nowtime, &tm); 48 49 if (!rtc_valid_tm(&tm)) { 49 - retval = set_rtc_time(&tm); 50 + retval = mc146818_set_time(&tm); 50 51 if (retval) 51 52 printk(KERN_ERR "%s: RTC write failed with error %d\n", 52 53 __func__, retval);
-1
arch/x86/platform/efi/efi.c
··· 51 51 #include <asm/cacheflush.h> 52 52 #include <asm/tlbflush.h> 53 53 #include <asm/x86_init.h> 54 - #include <asm/rtc.h> 55 54 #include <asm/uv/uv.h> 56 55 57 56 static struct efi efi_phys __initdata;
+1
arch/x86/platform/efi/efi_64.c
··· 25 25 #include <linux/bootmem.h> 26 26 #include <linux/ioport.h> 27 27 #include <linux/init.h> 28 + #include <linux/mc146818rtc.h> 28 29 #include <linux/efi.h> 29 30 #include <linux/uaccess.h> 30 31 #include <linux/io.h>
+1
arch/x86/platform/intel-mid/intel_mid_vrtc.c
··· 22 22 #include <linux/init.h> 23 23 #include <linux/sfi.h> 24 24 #include <linux/platform_device.h> 25 + #include <linux/mc146818rtc.h> 25 26 26 27 #include <asm/intel-mid.h> 27 28 #include <asm/intel_mid_vrtc.h>
+1 -1
drivers/acpi/acpi_cmos_rtc.c
··· 14 14 #include <linux/err.h> 15 15 #include <linux/kernel.h> 16 16 #include <linux/module.h> 17 - #include <asm-generic/rtc.h> 17 + #include <linux/mc146818rtc.h> 18 18 19 19 #include "internal.h" 20 20
+3 -3
drivers/base/power/trace.c
··· 11 11 #include <linux/export.h> 12 12 #include <linux/rtc.h> 13 13 14 - #include <asm/rtc.h> 14 + #include <linux/mc146818rtc.h> 15 15 16 16 #include "power.h" 17 17 ··· 103 103 n /= 24; 104 104 time.tm_min = (n % 20) * 3; 105 105 n /= 20; 106 - set_rtc_time(&time); 106 + mc146818_set_time(&time); 107 107 return n ? -1 : 0; 108 108 } 109 109 ··· 112 112 struct rtc_time time; 113 113 unsigned int val; 114 114 115 - get_rtc_time(&time); 115 + mc146818_get_time(&time); 116 116 pr_info("RTC time: %2d:%02d:%02d, date: %02d/%02d/%02d\n", 117 117 time.tm_hour, time.tm_min, time.tm_sec, 118 118 time.tm_mon + 1, time.tm_mday, time.tm_year % 100);
+1 -27
drivers/char/Kconfig
··· 293 293 294 294 config RTC 295 295 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)" 296 - depends on ALPHA || (MIPS && MACH_LOONGSON64) || MN10300 296 + depends on ALPHA || (MIPS && MACH_LOONGSON64) 297 297 ---help--- 298 298 If you say Y here and create a character special file /dev/rtc with 299 299 major number 10 and minor number 135 using mknod ("man mknod"), you ··· 338 338 339 339 To compile this driver as a module, choose M here: the 340 340 module will be called js-rtc. 341 - 342 - config GEN_RTC 343 - tristate "Generic /dev/rtc emulation" 344 - depends on RTC!=y 345 - depends on ALPHA || M68K || MN10300 || PARISC || PPC || X86 346 - ---help--- 347 - If you say Y here and create a character special file /dev/rtc with 348 - major number 10 and minor number 135 using mknod ("man mknod"), you 349 - will get access to the real time clock (or hardware clock) built 350 - into your computer. 351 - 352 - It reports status information via the file /proc/driver/rtc and its 353 - behaviour is set by various ioctls on /dev/rtc. If you enable the 354 - "extended RTC operation" below it will also provide an emulation 355 - for RTC_UIE which is required by some programs and may improve 356 - precision in some cases. 357 - 358 - To compile this driver as a module, choose M here: the 359 - module will be called genrtc. 360 - 361 - config GEN_RTC_X 362 - bool "Extended RTC operation" 363 - depends on GEN_RTC 364 - help 365 - Provides an emulation for RTC_UIE which is required by some programs 366 - and may improve precision of the generic RTC support in some cases. 367 341 368 342 config EFI_RTC 369 343 bool "EFI Real Time Clock Services"
-1
drivers/char/Makefile
··· 25 25 obj-$(CONFIG_SONYPI) += sonypi.o 26 26 obj-$(CONFIG_RTC) += rtc.o 27 27 obj-$(CONFIG_HPET) += hpet.o 28 - obj-$(CONFIG_GEN_RTC) += genrtc.o 29 28 obj-$(CONFIG_EFI_RTC) += efirtc.o 30 29 obj-$(CONFIG_DS1302) += ds1302.o 31 30 obj-$(CONFIG_XILINX_HWICAP) += xilinx_hwicap/
-539
drivers/char/genrtc.c
··· 1 - /* 2 - * Real Time Clock interface for 3 - * - q40 and other m68k machines, 4 - * - HP PARISC machines 5 - * - PowerPC machines 6 - * emulate some RTC irq capabilities in software 7 - * 8 - * Copyright (C) 1999 Richard Zidlicky 9 - * 10 - * based on Paul Gortmaker's rtc.c device and 11 - * Sam Creasey Generic rtc driver 12 - * 13 - * This driver allows use of the real time clock (built into 14 - * nearly all computers) from user space. It exports the /dev/rtc 15 - * interface supporting various ioctl() and also the /proc/driver/rtc 16 - * pseudo-file for status information. 17 - * 18 - * The ioctls can be used to set the interrupt behaviour where 19 - * supported. 20 - * 21 - * The /dev/rtc interface will block on reads until an interrupt 22 - * has been received. If a RTC interrupt has already happened, 23 - * it will output an unsigned long and then block. The output value 24 - * contains the interrupt status in the low byte and the number of 25 - * interrupts since the last read in the remaining high bytes. The 26 - * /dev/rtc interface can also be used with the select(2) call. 27 - * 28 - * This program is free software; you can redistribute it and/or 29 - * modify it under the terms of the GNU General Public License 30 - * as published by the Free Software Foundation; either version 31 - * 2 of the License, or (at your option) any later version. 32 - * 33 - 34 - * 1.01 fix for 2.3.X rz@linux-m68k.org 35 - * 1.02 merged with code from genrtc.c rz@linux-m68k.org 36 - * 1.03 make it more portable zippel@linux-m68k.org 37 - * 1.04 removed useless timer code rz@linux-m68k.org 38 - * 1.05 portable RTC_UIE emulation rz@linux-m68k.org 39 - * 1.06 set_rtc_time can return an error trini@kernel.crashing.org 40 - * 1.07 ported to HP PARISC (hppa) Helge Deller <deller@gmx.de> 41 - */ 42 - 43 - #define RTC_VERSION "1.07" 44 - 45 - #include <linux/module.h> 46 - #include <linux/sched.h> 47 - #include <linux/errno.h> 48 - #include <linux/miscdevice.h> 49 - #include <linux/fcntl.h> 50 - 51 - #include <linux/rtc.h> 52 - #include <linux/init.h> 53 - #include <linux/poll.h> 54 - #include <linux/proc_fs.h> 55 - #include <linux/seq_file.h> 56 - #include <linux/mutex.h> 57 - #include <linux/workqueue.h> 58 - 59 - #include <asm/uaccess.h> 60 - #include <asm/rtc.h> 61 - 62 - /* 63 - * We sponge a minor off of the misc major. No need slurping 64 - * up another valuable major dev number for this. If you add 65 - * an ioctl, make sure you don't conflict with SPARC's RTC 66 - * ioctls. 67 - */ 68 - 69 - static DEFINE_MUTEX(gen_rtc_mutex); 70 - static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); 71 - 72 - /* 73 - * Bits in gen_rtc_status. 74 - */ 75 - 76 - #define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */ 77 - 78 - static unsigned char gen_rtc_status; /* bitmapped status byte. */ 79 - static unsigned long gen_rtc_irq_data; /* our output to the world */ 80 - 81 - /* months start at 0 now */ 82 - static unsigned char days_in_mo[] = 83 - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 84 - 85 - static int irq_active; 86 - 87 - #ifdef CONFIG_GEN_RTC_X 88 - static struct work_struct genrtc_task; 89 - static struct timer_list timer_task; 90 - 91 - static unsigned int oldsecs; 92 - static int lostint; 93 - static unsigned long tt_exp; 94 - 95 - static void gen_rtc_timer(unsigned long data); 96 - 97 - static volatile int stask_active; /* schedule_work */ 98 - static volatile int ttask_active; /* timer_task */ 99 - static int stop_rtc_timers; /* don't requeue tasks */ 100 - static DEFINE_SPINLOCK(gen_rtc_lock); 101 - 102 - static void gen_rtc_interrupt(unsigned long arg); 103 - 104 - /* 105 - * Routine to poll RTC seconds field for change as often as possible, 106 - * after first RTC_UIE use timer to reduce polling 107 - */ 108 - static void genrtc_troutine(struct work_struct *work) 109 - { 110 - unsigned int tmp = get_rtc_ss(); 111 - 112 - if (stop_rtc_timers) { 113 - stask_active = 0; 114 - return; 115 - } 116 - 117 - if (oldsecs != tmp){ 118 - oldsecs = tmp; 119 - 120 - timer_task.function = gen_rtc_timer; 121 - timer_task.expires = jiffies + HZ - (HZ/10); 122 - tt_exp=timer_task.expires; 123 - ttask_active=1; 124 - stask_active=0; 125 - add_timer(&timer_task); 126 - 127 - gen_rtc_interrupt(0); 128 - } else if (schedule_work(&genrtc_task) == 0) 129 - stask_active = 0; 130 - } 131 - 132 - static void gen_rtc_timer(unsigned long data) 133 - { 134 - lostint = get_rtc_ss() - oldsecs ; 135 - if (lostint<0) 136 - lostint = 60 - lostint; 137 - if (time_after(jiffies, tt_exp)) 138 - printk(KERN_INFO "genrtc: timer task delayed by %ld jiffies\n", 139 - jiffies-tt_exp); 140 - ttask_active=0; 141 - stask_active=1; 142 - if ((schedule_work(&genrtc_task) == 0)) 143 - stask_active = 0; 144 - } 145 - 146 - /* 147 - * call gen_rtc_interrupt function to signal an RTC_UIE, 148 - * arg is unused. 149 - * Could be invoked either from a real interrupt handler or 150 - * from some routine that periodically (eg 100HZ) monitors 151 - * whether RTC_SECS changed 152 - */ 153 - static void gen_rtc_interrupt(unsigned long arg) 154 - { 155 - /* We store the status in the low byte and the number of 156 - * interrupts received since the last read in the remainder 157 - * of rtc_irq_data. */ 158 - 159 - gen_rtc_irq_data += 0x100; 160 - gen_rtc_irq_data &= ~0xff; 161 - gen_rtc_irq_data |= RTC_UIE; 162 - 163 - if (lostint){ 164 - printk("genrtc: system delaying clock ticks?\n"); 165 - /* increment count so that userspace knows something is wrong */ 166 - gen_rtc_irq_data += ((lostint-1)<<8); 167 - lostint = 0; 168 - } 169 - 170 - wake_up_interruptible(&gen_rtc_wait); 171 - } 172 - 173 - /* 174 - * Now all the various file operations that we export. 175 - */ 176 - static ssize_t gen_rtc_read(struct file *file, char __user *buf, 177 - size_t count, loff_t *ppos) 178 - { 179 - unsigned long data; 180 - ssize_t retval; 181 - 182 - if (count != sizeof (unsigned int) && count != sizeof (unsigned long)) 183 - return -EINVAL; 184 - 185 - if (file->f_flags & O_NONBLOCK && !gen_rtc_irq_data) 186 - return -EAGAIN; 187 - 188 - retval = wait_event_interruptible(gen_rtc_wait, 189 - (data = xchg(&gen_rtc_irq_data, 0))); 190 - if (retval) 191 - goto out; 192 - 193 - /* first test allows optimizer to nuke this case for 32-bit machines */ 194 - if (sizeof (int) != sizeof (long) && count == sizeof (unsigned int)) { 195 - unsigned int uidata = data; 196 - retval = put_user(uidata, (unsigned int __user *)buf) ?: 197 - sizeof(unsigned int); 198 - } 199 - else { 200 - retval = put_user(data, (unsigned long __user *)buf) ?: 201 - sizeof(unsigned long); 202 - } 203 - out: 204 - return retval; 205 - } 206 - 207 - static unsigned int gen_rtc_poll(struct file *file, 208 - struct poll_table_struct *wait) 209 - { 210 - poll_wait(file, &gen_rtc_wait, wait); 211 - if (gen_rtc_irq_data != 0) 212 - return POLLIN | POLLRDNORM; 213 - return 0; 214 - } 215 - 216 - #endif 217 - 218 - /* 219 - * Used to disable/enable interrupts, only RTC_UIE supported 220 - * We also clear out any old irq data after an ioctl() that 221 - * meddles with the interrupt enable/disable bits. 222 - */ 223 - 224 - static inline void gen_clear_rtc_irq_bit(unsigned char bit) 225 - { 226 - #ifdef CONFIG_GEN_RTC_X 227 - stop_rtc_timers = 1; 228 - if (ttask_active){ 229 - del_timer_sync(&timer_task); 230 - ttask_active = 0; 231 - } 232 - while (stask_active) 233 - schedule(); 234 - 235 - spin_lock(&gen_rtc_lock); 236 - irq_active = 0; 237 - spin_unlock(&gen_rtc_lock); 238 - #endif 239 - } 240 - 241 - static inline int gen_set_rtc_irq_bit(unsigned char bit) 242 - { 243 - #ifdef CONFIG_GEN_RTC_X 244 - spin_lock(&gen_rtc_lock); 245 - if ( !irq_active ) { 246 - irq_active = 1; 247 - stop_rtc_timers = 0; 248 - lostint = 0; 249 - INIT_WORK(&genrtc_task, genrtc_troutine); 250 - oldsecs = get_rtc_ss(); 251 - init_timer(&timer_task); 252 - 253 - stask_active = 1; 254 - if (schedule_work(&genrtc_task) == 0){ 255 - stask_active = 0; 256 - } 257 - } 258 - spin_unlock(&gen_rtc_lock); 259 - gen_rtc_irq_data = 0; 260 - return 0; 261 - #else 262 - return -EINVAL; 263 - #endif 264 - } 265 - 266 - static int gen_rtc_ioctl(struct file *file, 267 - unsigned int cmd, unsigned long arg) 268 - { 269 - struct rtc_time wtime; 270 - struct rtc_pll_info pll; 271 - void __user *argp = (void __user *)arg; 272 - 273 - switch (cmd) { 274 - 275 - case RTC_PLL_GET: 276 - if (get_rtc_pll(&pll)) 277 - return -EINVAL; 278 - else 279 - return copy_to_user(argp, &pll, sizeof pll) ? -EFAULT : 0; 280 - 281 - case RTC_PLL_SET: 282 - if (!capable(CAP_SYS_TIME)) 283 - return -EACCES; 284 - if (copy_from_user(&pll, argp, sizeof(pll))) 285 - return -EFAULT; 286 - return set_rtc_pll(&pll); 287 - 288 - case RTC_UIE_OFF: /* disable ints from RTC updates. */ 289 - gen_clear_rtc_irq_bit(RTC_UIE); 290 - return 0; 291 - 292 - case RTC_UIE_ON: /* enable ints for RTC updates. */ 293 - return gen_set_rtc_irq_bit(RTC_UIE); 294 - 295 - case RTC_RD_TIME: /* Read the time/date from RTC */ 296 - /* this doesn't get week-day, who cares */ 297 - memset(&wtime, 0, sizeof(wtime)); 298 - get_rtc_time(&wtime); 299 - 300 - return copy_to_user(argp, &wtime, sizeof(wtime)) ? -EFAULT : 0; 301 - 302 - case RTC_SET_TIME: /* Set the RTC */ 303 - { 304 - int year; 305 - unsigned char leap_yr; 306 - 307 - if (!capable(CAP_SYS_TIME)) 308 - return -EACCES; 309 - 310 - if (copy_from_user(&wtime, argp, sizeof(wtime))) 311 - return -EFAULT; 312 - 313 - year = wtime.tm_year + 1900; 314 - leap_yr = ((!(year % 4) && (year % 100)) || 315 - !(year % 400)); 316 - 317 - if ((wtime.tm_mon < 0 || wtime.tm_mon > 11) || (wtime.tm_mday < 1)) 318 - return -EINVAL; 319 - 320 - if (wtime.tm_mday < 0 || wtime.tm_mday > 321 - (days_in_mo[wtime.tm_mon] + ((wtime.tm_mon == 1) && leap_yr))) 322 - return -EINVAL; 323 - 324 - if (wtime.tm_hour < 0 || wtime.tm_hour >= 24 || 325 - wtime.tm_min < 0 || wtime.tm_min >= 60 || 326 - wtime.tm_sec < 0 || wtime.tm_sec >= 60) 327 - return -EINVAL; 328 - 329 - return set_rtc_time(&wtime); 330 - } 331 - } 332 - 333 - return -EINVAL; 334 - } 335 - 336 - static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd, 337 - unsigned long arg) 338 - { 339 - int ret; 340 - 341 - mutex_lock(&gen_rtc_mutex); 342 - ret = gen_rtc_ioctl(file, cmd, arg); 343 - mutex_unlock(&gen_rtc_mutex); 344 - 345 - return ret; 346 - } 347 - 348 - /* 349 - * We enforce only one user at a time here with the open/close. 350 - * Also clear the previous interrupt data on an open, and clean 351 - * up things on a close. 352 - */ 353 - 354 - static int gen_rtc_open(struct inode *inode, struct file *file) 355 - { 356 - mutex_lock(&gen_rtc_mutex); 357 - if (gen_rtc_status & RTC_IS_OPEN) { 358 - mutex_unlock(&gen_rtc_mutex); 359 - return -EBUSY; 360 - } 361 - 362 - gen_rtc_status |= RTC_IS_OPEN; 363 - gen_rtc_irq_data = 0; 364 - irq_active = 0; 365 - mutex_unlock(&gen_rtc_mutex); 366 - 367 - return 0; 368 - } 369 - 370 - static int gen_rtc_release(struct inode *inode, struct file *file) 371 - { 372 - /* 373 - * Turn off all interrupts once the device is no longer 374 - * in use and clear the data. 375 - */ 376 - 377 - gen_clear_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE); 378 - 379 - gen_rtc_status &= ~RTC_IS_OPEN; 380 - return 0; 381 - } 382 - 383 - 384 - #ifdef CONFIG_PROC_FS 385 - 386 - /* 387 - * Info exported via "/proc/driver/rtc". 388 - */ 389 - 390 - static int gen_rtc_proc_show(struct seq_file *m, void *v) 391 - { 392 - struct rtc_time tm; 393 - unsigned int flags; 394 - struct rtc_pll_info pll; 395 - 396 - flags = get_rtc_time(&tm); 397 - 398 - seq_printf(m, 399 - "rtc_time\t: %02d:%02d:%02d\n" 400 - "rtc_date\t: %04d-%02d-%02d\n" 401 - "rtc_epoch\t: %04u\n", 402 - tm.tm_hour, tm.tm_min, tm.tm_sec, 403 - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1900); 404 - 405 - tm.tm_hour = tm.tm_min = tm.tm_sec = 0; 406 - 407 - seq_puts(m, "alarm\t\t: "); 408 - if (tm.tm_hour <= 24) 409 - seq_printf(m, "%02d:", tm.tm_hour); 410 - else 411 - seq_puts(m, "**:"); 412 - 413 - if (tm.tm_min <= 59) 414 - seq_printf(m, "%02d:", tm.tm_min); 415 - else 416 - seq_puts(m, "**:"); 417 - 418 - if (tm.tm_sec <= 59) 419 - seq_printf(m, "%02d\n", tm.tm_sec); 420 - else 421 - seq_puts(m, "**\n"); 422 - 423 - seq_printf(m, 424 - "DST_enable\t: %s\n" 425 - "BCD\t\t: %s\n" 426 - "24hr\t\t: %s\n" 427 - "square_wave\t: %s\n" 428 - "alarm_IRQ\t: %s\n" 429 - "update_IRQ\t: %s\n" 430 - "periodic_IRQ\t: %s\n" 431 - "periodic_freq\t: %ld\n" 432 - "batt_status\t: %s\n", 433 - (flags & RTC_DST_EN) ? "yes" : "no", 434 - (flags & RTC_DM_BINARY) ? "no" : "yes", 435 - (flags & RTC_24H) ? "yes" : "no", 436 - (flags & RTC_SQWE) ? "yes" : "no", 437 - (flags & RTC_AIE) ? "yes" : "no", 438 - irq_active ? "yes" : "no", 439 - (flags & RTC_PIE) ? "yes" : "no", 440 - 0L /* freq */, 441 - (flags & RTC_BATT_BAD) ? "bad" : "okay"); 442 - if (!get_rtc_pll(&pll)) 443 - seq_printf(m, 444 - "PLL adjustment\t: %d\n" 445 - "PLL max +ve adjustment\t: %d\n" 446 - "PLL max -ve adjustment\t: %d\n" 447 - "PLL +ve adjustment factor\t: %d\n" 448 - "PLL -ve adjustment factor\t: %d\n" 449 - "PLL frequency\t: %ld\n", 450 - pll.pll_value, 451 - pll.pll_max, 452 - pll.pll_min, 453 - pll.pll_posmult, 454 - pll.pll_negmult, 455 - pll.pll_clock); 456 - return 0; 457 - } 458 - 459 - static int gen_rtc_proc_open(struct inode *inode, struct file *file) 460 - { 461 - return single_open(file, gen_rtc_proc_show, NULL); 462 - } 463 - 464 - static const struct file_operations gen_rtc_proc_fops = { 465 - .open = gen_rtc_proc_open, 466 - .read = seq_read, 467 - .llseek = seq_lseek, 468 - .release = single_release, 469 - }; 470 - 471 - static int __init gen_rtc_proc_init(void) 472 - { 473 - struct proc_dir_entry *r; 474 - 475 - r = proc_create("driver/rtc", 0, NULL, &gen_rtc_proc_fops); 476 - if (!r) 477 - return -ENOMEM; 478 - return 0; 479 - } 480 - #else 481 - static inline int gen_rtc_proc_init(void) { return 0; } 482 - #endif /* CONFIG_PROC_FS */ 483 - 484 - 485 - /* 486 - * The various file operations we support. 487 - */ 488 - 489 - static const struct file_operations gen_rtc_fops = { 490 - .owner = THIS_MODULE, 491 - #ifdef CONFIG_GEN_RTC_X 492 - .read = gen_rtc_read, 493 - .poll = gen_rtc_poll, 494 - #endif 495 - .unlocked_ioctl = gen_rtc_unlocked_ioctl, 496 - .open = gen_rtc_open, 497 - .release = gen_rtc_release, 498 - .llseek = noop_llseek, 499 - }; 500 - 501 - static struct miscdevice rtc_gen_dev = 502 - { 503 - .minor = RTC_MINOR, 504 - .name = "rtc", 505 - .fops = &gen_rtc_fops, 506 - }; 507 - 508 - static int __init rtc_generic_init(void) 509 - { 510 - int retval; 511 - 512 - printk(KERN_INFO "Generic RTC Driver v%s\n", RTC_VERSION); 513 - 514 - retval = misc_register(&rtc_gen_dev); 515 - if (retval < 0) 516 - return retval; 517 - 518 - retval = gen_rtc_proc_init(); 519 - if (retval) { 520 - misc_deregister(&rtc_gen_dev); 521 - return retval; 522 - } 523 - 524 - return 0; 525 - } 526 - 527 - static void __exit rtc_generic_exit(void) 528 - { 529 - remove_proc_entry ("driver/rtc", NULL); 530 - misc_deregister(&rtc_gen_dev); 531 - } 532 - 533 - 534 - module_init(rtc_generic_init); 535 - module_exit(rtc_generic_exit); 536 - 537 - MODULE_AUTHOR("Richard Zidlicky"); 538 - MODULE_LICENSE("GPL"); 539 - MODULE_ALIAS_MISCDEV(RTC_MINOR);
+22 -4
drivers/rtc/Kconfig
··· 5 5 config RTC_LIB 6 6 bool 7 7 8 + config RTC_MC146818_LIB 9 + bool 10 + select RTC_LIB 11 + 8 12 menuconfig RTC_CLASS 9 13 bool "Real Time Clock" 10 14 default n ··· 578 574 will be called rtc-em3027. 579 575 580 576 config RTC_DRV_RV8803 581 - tristate "Micro Crystal RV8803" 577 + tristate "Micro Crystal RV8803, Epson RX8900" 582 578 help 583 - If you say yes here you get support for the Micro Crystal 584 - RV8803 RTC chips. 579 + If you say yes here you get support for the Micro Crystal RV8803 and 580 + Epson RX8900 RTC chips. 585 581 586 582 This driver can also be built as a module. If so, the module 587 583 will be called rtc-rv8803. ··· 673 669 674 670 This driver can also be built as a module. If so, the module 675 671 will be called rtc-ds1390. 672 + 673 + config RTC_DRV_MAX6916 674 + tristate "Maxim MAX6916" 675 + help 676 + If you say yes here you will get support for the 677 + Maxim MAX6916 SPI RTC chip. 678 + 679 + This driver only supports the RTC feature, and not other chip 680 + features such as alarms. 681 + 682 + This driver can also be built as a module. If so, the module 683 + will be called rtc-max6916. 676 684 677 685 config RTC_DRV_R9701 678 686 tristate "Epson RTC-9701JE" ··· 811 795 812 796 config RTC_DRV_CMOS 813 797 tristate "PC-style 'CMOS'" 814 - depends on X86 || ARM || M32R || PPC || MIPS || SPARC64 798 + depends on X86 || ARM || M32R || PPC || MIPS || SPARC64 || MN10300 815 799 default y if X86 800 + select RTC_MC146818_LIB 816 801 help 817 802 Say "yes" here to get direct support for the real time clock 818 803 found in every PC or ACPI-based system, and some other boards. ··· 832 815 config RTC_DRV_ALPHA 833 816 bool "Alpha PC-style CMOS" 834 817 depends on ALPHA 818 + select RTC_MC146818_LIB 835 819 default y 836 820 help 837 821 Direct support for the real-time clock found on every Alpha
+2
drivers/rtc/Makefile
··· 8 8 obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 9 9 obj-$(CONFIG_RTC_SYSTOHC) += systohc.o 10 10 obj-$(CONFIG_RTC_CLASS) += rtc-core.o 11 + obj-$(CONFIG_RTC_MC146818_LIB) += rtc-mc146818-lib.o 11 12 rtc-core-y := class.o interface.o 12 13 13 14 ifdef CONFIG_RTC_DRV_EFI ··· 86 85 obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 87 86 obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o 88 87 obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 88 + obj-$(CONFIG_RTC_DRV_MAX6916) += rtc-max6916.o 89 89 obj-$(CONFIG_RTC_DRV_MAX77686) += rtc-max77686.o 90 90 obj-$(CONFIG_RTC_DRV_MAX8907) += rtc-max8907.o 91 91 obj-$(CONFIG_RTC_DRV_MAX8925) += rtc-max8925.o
+27 -5
drivers/rtc/interface.c
··· 104 104 else if (!rtc->ops->read_alarm) 105 105 err = -EINVAL; 106 106 else { 107 - memset(alarm, 0, sizeof(struct rtc_wkalrm)); 107 + alarm->enabled = 0; 108 + alarm->pending = 0; 109 + alarm->time.tm_sec = -1; 110 + alarm->time.tm_min = -1; 111 + alarm->time.tm_hour = -1; 112 + alarm->time.tm_mday = -1; 113 + alarm->time.tm_mon = -1; 114 + alarm->time.tm_year = -1; 115 + alarm->time.tm_wday = -1; 116 + alarm->time.tm_yday = -1; 117 + alarm->time.tm_isdst = -1; 108 118 err = rtc->ops->read_alarm(rtc->dev.parent, alarm); 109 119 } 110 120 ··· 393 383 rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); 394 384 rtc->aie_timer.period = ktime_set(0, 0); 395 385 396 - /* Alarm has to be enabled & in the futrure for us to enqueue it */ 386 + /* Alarm has to be enabled & in the future for us to enqueue it */ 397 387 if (alarm->enabled && (rtc_tm_to_ktime(now).tv64 < 398 388 rtc->aie_timer.node.expires.tv64)) { 399 389 ··· 404 394 return err; 405 395 } 406 396 EXPORT_SYMBOL_GPL(rtc_initialize_alarm); 407 - 408 - 409 397 410 398 int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) 411 399 { ··· 756 748 */ 757 749 static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) 758 750 { 751 + struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue); 752 + struct rtc_time tm; 753 + ktime_t now; 754 + 759 755 timer->enabled = 1; 756 + __rtc_read_time(rtc, &tm); 757 + now = rtc_tm_to_ktime(tm); 758 + 759 + /* Skip over expired timers */ 760 + while (next) { 761 + if (next->expires.tv64 >= now.tv64) 762 + break; 763 + next = timerqueue_iterate_next(next); 764 + } 765 + 760 766 timerqueue_add(&rtc->timerqueue, &timer->node); 761 - if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) { 767 + if (!next) { 762 768 struct rtc_wkalrm alarm; 763 769 int err; 764 770 alarm.time = rtc_ktime_to_tm(timer->node.expires);
+5 -7
drivers/rtc/rtc-abx80x.c
··· 643 643 return err; 644 644 } 645 645 646 - err = devm_add_action(&client->dev, rtc_calib_remove_sysfs_group, 647 - &client->dev); 648 - if (err) { 649 - rtc_calib_remove_sysfs_group(&client->dev); 646 + err = devm_add_action_or_reset(&client->dev, 647 + rtc_calib_remove_sysfs_group, 648 + &client->dev); 649 + if (err) 650 650 dev_err(&client->dev, 651 651 "Failed to add sysfs cleanup action: %d\n", 652 652 err); 653 - return err; 654 - } 655 653 656 - return 0; 654 + return err; 657 655 } 658 656 659 657 static int abx80x_remove(struct i2c_client *client)
-1
drivers/rtc/rtc-asm9260.c
··· 343 343 .remove = asm9260_rtc_remove, 344 344 .driver = { 345 345 .name = "asm9260-rtc", 346 - .owner = THIS_MODULE, 347 346 .of_match_table = asm9260_dt_ids, 348 347 }, 349 348 };
+1
drivers/rtc/rtc-at91sam9.c
··· 375 375 if (!rtc) 376 376 return -ENOMEM; 377 377 378 + spin_lock_init(&rtc->lock); 378 379 rtc->irq = irq; 379 380 380 381 /* platform setup code should have handled this; sigh */
+7 -10
drivers/rtc/rtc-cmos.c
··· 43 43 #include <linux/of_platform.h> 44 44 45 45 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */ 46 - #include <asm-generic/rtc.h> 46 + #include <linux/mc146818rtc.h> 47 47 48 48 struct cmos_rtc { 49 49 struct rtc_device *rtc; ··· 190 190 static int cmos_read_time(struct device *dev, struct rtc_time *t) 191 191 { 192 192 /* REVISIT: if the clock has a "century" register, use 193 - * that instead of the heuristic in get_rtc_time(). 193 + * that instead of the heuristic in mc146818_get_time(). 194 194 * That'll make Y3K compatility (year > 2070) easy! 195 195 */ 196 - get_rtc_time(t); 196 + mc146818_get_time(t); 197 197 return 0; 198 198 } 199 199 ··· 205 205 * takes effect exactly 500ms after we write the register. 206 206 * (Also queueing and other delays before we get this far.) 207 207 */ 208 - return set_rtc_time(t); 208 + return mc146818_set_time(t); 209 209 } 210 210 211 211 static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t) ··· 220 220 * Some also support day and month, for alarms up to a year in 221 221 * the future. 222 222 */ 223 - t->time.tm_mday = -1; 224 - t->time.tm_mon = -1; 225 223 226 224 spin_lock_irq(&rtc_lock); 227 225 t->time.tm_sec = CMOS_READ(RTC_SECONDS_ALARM); ··· 270 272 } 271 273 } 272 274 } 273 - t->time.tm_year = -1; 274 275 275 276 t->enabled = !!(rtc_control & RTC_AIE); 276 277 t->pending = 0; ··· 627 630 address_space = 64; 628 631 #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) \ 629 632 || defined(__sparc__) || defined(__mips__) \ 630 - || defined(__powerpc__) 633 + || defined(__powerpc__) || defined(CONFIG_MN10300) 631 634 address_space = 128; 632 635 #else 633 636 #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. ··· 1139 1142 if (val) 1140 1143 CMOS_WRITE(be32_to_cpup(val), RTC_FREQ_SELECT); 1141 1144 1142 - get_rtc_time(&time); 1145 + cmos_read_time(&pdev->dev, &time); 1143 1146 ret = rtc_valid_tm(&time); 1144 1147 if (ret) { 1145 1148 struct rtc_time def_time = { 1146 1149 .tm_year = 1, 1147 1150 .tm_mday = 1, 1148 1151 }; 1149 - set_rtc_time(&def_time); 1152 + cmos_set_time(&pdev->dev, &def_time); 1150 1153 } 1151 1154 } 1152 1155 #else
+1
drivers/rtc/rtc-da9052.c
··· 85 85 rtc_tm->tm_mday = v[0][2] & DA9052_RTC_DAY; 86 86 rtc_tm->tm_hour = v[0][1] & DA9052_RTC_HOUR; 87 87 rtc_tm->tm_min = v[0][0] & DA9052_RTC_MIN; 88 + rtc_tm->tm_sec = 0; 88 89 89 90 ret = rtc_valid_tm(rtc_tm); 90 91 return ret;
+1
drivers/rtc/rtc-da9055.c
··· 74 74 rtc_tm->tm_mday = v[2] & DA9055_RTC_ALM_DAY; 75 75 rtc_tm->tm_hour = v[1] & DA9055_RTC_ALM_HOUR; 76 76 rtc_tm->tm_min = v[0] & DA9055_RTC_ALM_MIN; 77 + rtc_tm->tm_sec = 0; 77 78 78 79 return rtc_valid_tm(rtc_tm); 79 80 }
+2
drivers/rtc/rtc-davinci.c
··· 388 388 u8 day0, day1; 389 389 unsigned long flags; 390 390 391 + alm->time.tm_sec = 0; 392 + 391 393 spin_lock_irqsave(&davinci_rtc_lock, flags); 392 394 393 395 davinci_rtcss_calendar_wait(davinci_rtc);
+1 -1
drivers/rtc/rtc-ds1286.c
··· 16 16 #include <linux/rtc.h> 17 17 #include <linux/platform_device.h> 18 18 #include <linux/bcd.h> 19 - #include <linux/ds1286.h> 19 + #include <linux/rtc/ds1286.h> 20 20 #include <linux/io.h> 21 21 #include <linux/slab.h> 22 22
-7
drivers/rtc/rtc-ds1305.c
··· 313 313 alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]); 314 314 alm->time.tm_min = bcd2bin(buf[DS1305_MIN]); 315 315 alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]); 316 - alm->time.tm_mday = -1; 317 - alm->time.tm_mon = -1; 318 - alm->time.tm_year = -1; 319 - /* next three fields are unused by Linux */ 320 - alm->time.tm_wday = -1; 321 - alm->time.tm_mday = -1; 322 - alm->time.tm_isdst = -1; 323 316 324 317 return 0; 325 318 }
+27 -6
drivers/rtc/rtc-ds1307.c
··· 482 482 t->time.tm_min = bcd2bin(ds1307->regs[1] & 0x7f); 483 483 t->time.tm_hour = bcd2bin(ds1307->regs[2] & 0x3f); 484 484 t->time.tm_mday = bcd2bin(ds1307->regs[3] & 0x3f); 485 - t->time.tm_mon = -1; 486 - t->time.tm_year = -1; 487 - t->time.tm_wday = -1; 488 - t->time.tm_yday = -1; 489 - t->time.tm_isdst = -1; 490 485 491 486 /* ... and status */ 492 487 t->enabled = !!(ds1307->regs[7] & DS1337_BIT_A1IE); ··· 597 602 * Alarm support for mcp794xx devices. 598 603 */ 599 604 605 + #define MCP794XX_REG_WEEKDAY 0x3 606 + #define MCP794XX_REG_WEEKDAY_WDAY_MASK 0x7 600 607 #define MCP794XX_REG_CONTROL 0x07 601 608 # define MCP794XX_BIT_ALM0_EN 0x10 602 609 # define MCP794XX_BIT_ALM1_EN 0x20 ··· 1228 1231 { 1229 1232 struct ds1307 *ds1307; 1230 1233 int err = -ENODEV; 1231 - int tmp; 1234 + int tmp, wday; 1232 1235 struct chip_desc *chip = &chips[id->driver_data]; 1233 1236 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1234 1237 bool want_irq = false; 1235 1238 bool ds1307_can_wakeup_device = false; 1236 1239 unsigned char *buf; 1237 1240 struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev); 1241 + struct rtc_time tm; 1242 + unsigned long timestamp; 1243 + 1238 1244 irq_handler_t irq_handler = ds1307_irq; 1239 1245 1240 1246 static const int bbsqi_bitpos[] = { ··· 1524 1524 i2c_smbus_write_byte_data(client, 1525 1525 ds1307->offset + DS1307_REG_HOUR, 1526 1526 bin2bcd(tmp)); 1527 + } 1528 + 1529 + /* 1530 + * Some IPs have weekday reset value = 0x1 which might not correct 1531 + * hence compute the wday using the current date/month/year values 1532 + */ 1533 + ds1307_get_time(&client->dev, &tm); 1534 + wday = tm.tm_wday; 1535 + timestamp = rtc_tm_to_time64(&tm); 1536 + rtc_time64_to_tm(timestamp, &tm); 1537 + 1538 + /* 1539 + * Check if reset wday is different from the computed wday 1540 + * If different then set the wday which we computed using 1541 + * timestamp 1542 + */ 1543 + if (wday != tm.tm_wday) { 1544 + wday = i2c_smbus_read_byte_data(client, MCP794XX_REG_WEEKDAY); 1545 + wday = wday & ~MCP794XX_REG_WEEKDAY_WDAY_MASK; 1546 + wday = wday | (tm.tm_wday + 1); 1547 + i2c_smbus_write_byte_data(client, MCP794XX_REG_WEEKDAY, wday); 1527 1548 } 1528 1549 1529 1550 if (want_irq) {
-6
drivers/rtc/rtc-ds1343.c
··· 504 504 alarm->time.tm_hour = priv->alarm_hour < 0 ? 0 : priv->alarm_hour; 505 505 alarm->time.tm_mday = priv->alarm_mday < 0 ? 0 : priv->alarm_mday; 506 506 507 - alarm->time.tm_mon = -1; 508 - alarm->time.tm_year = -1; 509 - alarm->time.tm_wday = -1; 510 - alarm->time.tm_yday = -1; 511 - alarm->time.tm_isdst = -1; 512 - 513 507 out: 514 508 mutex_unlock(&priv->mutex); 515 509 return res;
+33 -20
drivers/rtc/rtc-ds1685.c
··· 103 103 } 104 104 105 105 /** 106 + * s1685_rtc_check_mday - check validity of the day of month. 107 + * @rtc: pointer to the ds1685 rtc structure. 108 + * @mday: day of month. 109 + * 110 + * Returns -EDOM if the day of month is not within 1..31 range. 111 + */ 112 + static inline int 113 + ds1685_rtc_check_mday(struct ds1685_priv *rtc, u8 mday) 114 + { 115 + if (rtc->bcd_mode) { 116 + if (mday < 0x01 || mday > 0x31 || (mday & 0x0f) > 0x09) 117 + return -EDOM; 118 + } else { 119 + if (mday < 1 || mday > 31) 120 + return -EDOM; 121 + } 122 + return 0; 123 + } 124 + 125 + /** 106 126 * ds1685_rtc_switch_to_bank0 - switch the rtc to bank 0. 107 127 * @rtc: pointer to the ds1685 rtc structure. 108 128 */ ··· 397 377 struct platform_device *pdev = to_platform_device(dev); 398 378 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 399 379 u8 seconds, minutes, hours, mday, ctrlb, ctrlc; 380 + int ret; 400 381 401 382 /* Fetch the alarm info from the RTC alarm registers. */ 402 383 ds1685_rtc_begin_data_access(rtc); ··· 409 388 ctrlc = rtc->read(rtc, RTC_CTRL_C); 410 389 ds1685_rtc_end_data_access(rtc); 411 390 412 - /* Check month date. */ 413 - if (!(mday >= 1) && (mday <= 31)) 414 - return -EDOM; 391 + /* Check the month date for validity. */ 392 + ret = ds1685_rtc_check_mday(rtc, mday); 393 + if (ret) 394 + return ret; 415 395 416 396 /* 417 397 * Check the three alarm bytes. 418 398 * 419 399 * The Linux RTC system doesn't support the "don't care" capability 420 400 * of this RTC chip. We check for it anyways in case support is 421 - * added in the future. 401 + * added in the future and only assign when we care. 422 402 */ 423 - if (unlikely(seconds >= 0xc0)) 424 - alrm->time.tm_sec = -1; 425 - else 403 + if (likely(seconds < 0xc0)) 426 404 alrm->time.tm_sec = ds1685_rtc_bcd2bin(rtc, seconds, 427 405 RTC_SECS_BCD_MASK, 428 406 RTC_SECS_BIN_MASK); 429 407 430 - if (unlikely(minutes >= 0xc0)) 431 - alrm->time.tm_min = -1; 432 - else 408 + if (likely(minutes < 0xc0)) 433 409 alrm->time.tm_min = ds1685_rtc_bcd2bin(rtc, minutes, 434 410 RTC_MINS_BCD_MASK, 435 411 RTC_MINS_BIN_MASK); 436 412 437 - if (unlikely(hours >= 0xc0)) 438 - alrm->time.tm_hour = -1; 439 - else 413 + if (likely(hours < 0xc0)) 440 414 alrm->time.tm_hour = ds1685_rtc_bcd2bin(rtc, hours, 441 415 RTC_HRS_24_BCD_MASK, 442 416 RTC_HRS_24_BIN_MASK); ··· 439 423 /* Write the data to rtc_wkalrm. */ 440 424 alrm->time.tm_mday = ds1685_rtc_bcd2bin(rtc, mday, RTC_MDAY_BCD_MASK, 441 425 RTC_MDAY_BIN_MASK); 442 - alrm->time.tm_mon = -1; 443 - alrm->time.tm_year = -1; 444 - alrm->time.tm_wday = -1; 445 - alrm->time.tm_yday = -1; 446 - alrm->time.tm_isdst = -1; 447 426 alrm->enabled = !!(ctrlb & RTC_CTRL_B_AIE); 448 427 alrm->pending = !!(ctrlc & RTC_CTRL_C_AF); 449 428 ··· 456 445 struct platform_device *pdev = to_platform_device(dev); 457 446 struct ds1685_priv *rtc = platform_get_drvdata(pdev); 458 447 u8 ctrlb, seconds, minutes, hours, mday; 448 + int ret; 459 449 460 450 /* Fetch the alarm info and convert to BCD. */ 461 451 seconds = ds1685_rtc_bin2bcd(rtc, alrm->time.tm_sec, ··· 473 461 RTC_MDAY_BCD_MASK); 474 462 475 463 /* Check the month date for validity. */ 476 - if (!(mday >= 1) && (mday <= 31)) 477 - return -EDOM; 464 + ret = ds1685_rtc_check_mday(rtc, mday); 465 + if (ret) 466 + return ret; 478 467 479 468 /* 480 469 * Check the three alarm bytes.
+1 -1
drivers/rtc/rtc-ds2404.c
··· 13 13 #include <linux/rtc.h> 14 14 #include <linux/types.h> 15 15 #include <linux/bcd.h> 16 - #include <linux/rtc-ds2404.h> 16 + #include <linux/platform_data/rtc-ds2404.h> 17 17 #include <linux/delay.h> 18 18 #include <linux/gpio.h> 19 19 #include <linux/slab.h>
-6
drivers/rtc/rtc-ds3232.c
··· 197 197 alarm->time.tm_hour = bcd2bin(buf[2] & 0x7F); 198 198 alarm->time.tm_mday = bcd2bin(buf[3] & 0x7F); 199 199 200 - alarm->time.tm_mon = -1; 201 - alarm->time.tm_year = -1; 202 - alarm->time.tm_wday = -1; 203 - alarm->time.tm_yday = -1; 204 - alarm->time.tm_isdst = -1; 205 - 206 200 alarm->enabled = !!(control & DS3232_REG_CR_A1IE); 207 201 alarm->pending = !!(stat & DS3232_REG_SR_A1F); 208 202
+6
drivers/rtc/rtc-efi.c
··· 259 259 static int __init efi_rtc_probe(struct platform_device *dev) 260 260 { 261 261 struct rtc_device *rtc; 262 + efi_time_t eft; 263 + efi_time_cap_t cap; 264 + 265 + /* First check if the RTC is usable */ 266 + if (efi.get_time(&eft, &cap) != EFI_SUCCESS) 267 + return -ENODEV; 262 268 263 269 rtc = devm_rtc_device_register(&dev->dev, "rtc-efi", &efi_rtc_ops, 264 270 THIS_MODULE);
+1 -35
drivers/rtc/rtc-generic.c
··· 9 9 #include <linux/platform_device.h> 10 10 #include <linux/rtc.h> 11 11 12 - #if defined(CONFIG_M68K) || defined(CONFIG_PARISC) || \ 13 - defined(CONFIG_PPC) || defined(CONFIG_SUPERH32) 14 - #include <asm/rtc.h> 15 - 16 - static int generic_get_time(struct device *dev, struct rtc_time *tm) 17 - { 18 - unsigned int ret = get_rtc_time(tm); 19 - 20 - if (ret & RTC_BATT_BAD) 21 - return -EOPNOTSUPP; 22 - 23 - return rtc_valid_tm(tm); 24 - } 25 - 26 - static int generic_set_time(struct device *dev, struct rtc_time *tm) 27 - { 28 - if (set_rtc_time(tm) < 0) 29 - return -EOPNOTSUPP; 30 - 31 - return 0; 32 - } 33 - 34 - static const struct rtc_class_ops generic_rtc_ops = { 35 - .read_time = generic_get_time, 36 - .set_time = generic_set_time, 37 - }; 38 - #else 39 - #define generic_rtc_ops *(struct rtc_class_ops*)NULL 40 - #endif 41 - 42 12 static int __init generic_rtc_probe(struct platform_device *dev) 43 13 { 44 14 struct rtc_device *rtc; 45 - const struct rtc_class_ops *ops; 46 - 47 - ops = dev_get_platdata(&dev->dev); 48 - if (!ops) 49 - ops = &generic_rtc_ops; 15 + const struct rtc_class_ops *ops = dev_get_platdata(&dev->dev); 50 16 51 17 rtc = devm_rtc_device_register(&dev->dev, "rtc-generic", 52 18 ops, THIS_MODULE);
+1 -4
drivers/rtc/rtc-hym8563.c
··· 198 198 return ret; 199 199 200 200 /* The alarm only has a minute accuracy */ 201 - alm_tm->tm_sec = -1; 201 + alm_tm->tm_sec = 0; 202 202 203 203 alm_tm->tm_min = (buf[0] & HYM8563_ALM_BIT_DISABLE) ? 204 204 -1 : ··· 212 212 alm_tm->tm_wday = (buf[3] & HYM8563_ALM_BIT_DISABLE) ? 213 213 -1 : 214 214 bcd2bin(buf[3] & HYM8563_WEEKDAY_MASK); 215 - 216 - alm_tm->tm_mon = -1; 217 - alm_tm->tm_year = -1; 218 215 219 216 ret = i2c_smbus_read_byte_data(client, HYM8563_CTL2); 220 217 if (ret < 0)
+1 -32
drivers/rtc/rtc-isl12057.c
··· 245 245 static int isl12057_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm) 246 246 { 247 247 struct isl12057_rtc_data *data = dev_get_drvdata(dev); 248 - struct rtc_time rtc_tm, *alarm_tm = &alarm->time; 249 - unsigned long rtc_secs, alarm_secs; 248 + struct rtc_time *alarm_tm = &alarm->time; 250 249 u8 regs[ISL12057_A1_SEC_LEN]; 251 250 unsigned int ir; 252 251 int ret; ··· 263 264 alarm_tm->tm_min = bcd2bin(regs[1] & 0x7f); 264 265 alarm_tm->tm_hour = bcd2bin(regs[2] & 0x3f); 265 266 alarm_tm->tm_mday = bcd2bin(regs[3] & 0x3f); 266 - alarm_tm->tm_wday = -1; 267 - 268 - /* 269 - * The alarm section does not store year/month. We use the ones in rtc 270 - * section as a basis and increment month and then year if needed to get 271 - * alarm after current time. 272 - */ 273 - ret = _isl12057_rtc_read_time(dev, &rtc_tm); 274 - if (ret) 275 - goto err_unlock; 276 - 277 - alarm_tm->tm_year = rtc_tm.tm_year; 278 - alarm_tm->tm_mon = rtc_tm.tm_mon; 279 - 280 - ret = rtc_tm_to_time(&rtc_tm, &rtc_secs); 281 - if (ret) 282 - goto err_unlock; 283 - 284 - ret = rtc_tm_to_time(alarm_tm, &alarm_secs); 285 - if (ret) 286 - goto err_unlock; 287 - 288 - if (alarm_secs < rtc_secs) { 289 - if (alarm_tm->tm_mon == 11) { 290 - alarm_tm->tm_mon = 0; 291 - alarm_tm->tm_year += 1; 292 - } else { 293 - alarm_tm->tm_mon += 1; 294 - } 295 - } 296 267 297 268 ret = regmap_read(data->regmap, ISL12057_REG_INT, &ir); 298 269 if (ret) {
+28 -6
drivers/rtc/rtc-m41t80.c
··· 244 244 245 245 retval = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, flags); 246 246 if (retval < 0) { 247 - dev_info(dev, "Unable to enable alarm IRQ %d\n", retval); 247 + dev_err(dev, "Unable to enable alarm IRQ %d\n", retval); 248 248 return retval; 249 249 } 250 250 return 0; ··· 320 320 alrm->time.tm_sec = bcd2bin(alarmvals[4] & 0x7f); 321 321 alrm->time.tm_min = bcd2bin(alarmvals[3] & 0x7f); 322 322 alrm->time.tm_hour = bcd2bin(alarmvals[2] & 0x3f); 323 - alrm->time.tm_wday = -1; 324 323 alrm->time.tm_mday = bcd2bin(alarmvals[1] & 0x3f); 325 324 alrm->time.tm_mon = bcd2bin(alarmvals[0] & 0x3f); 326 - alrm->time.tm_year = -1; 327 325 328 326 alrm->enabled = !!(alarmvals[0] & M41T80_ALMON_AFE); 329 327 alrm->pending = (flags & M41T80_FLAGS_AF) && alrm->enabled; ··· 334 336 .set_time = m41t80_rtc_set_time, 335 337 .proc = m41t80_rtc_proc, 336 338 }; 339 + 340 + #ifdef CONFIG_PM_SLEEP 341 + static int m41t80_suspend(struct device *dev) 342 + { 343 + struct i2c_client *client = to_i2c_client(dev); 344 + 345 + if (client->irq >= 0 && device_may_wakeup(dev)) 346 + enable_irq_wake(client->irq); 347 + 348 + return 0; 349 + } 350 + 351 + static int m41t80_resume(struct device *dev) 352 + { 353 + struct i2c_client *client = to_i2c_client(dev); 354 + 355 + if (client->irq >= 0 && device_may_wakeup(dev)) 356 + disable_irq_wake(client->irq); 357 + 358 + return 0; 359 + } 360 + #endif 361 + 362 + static SIMPLE_DEV_PM_OPS(m41t80_pm, m41t80_suspend, m41t80_resume); 337 363 338 364 static ssize_t flags_show(struct device *dev, 339 365 struct device_attribute *attr, char *buf) ··· 853 831 return rc; 854 832 } 855 833 856 - rc = devm_add_action(&client->dev, m41t80_remove_sysfs_group, 857 - &client->dev); 834 + rc = devm_add_action_or_reset(&client->dev, m41t80_remove_sysfs_group, 835 + &client->dev); 858 836 if (rc) { 859 - m41t80_remove_sysfs_group(&client->dev); 860 837 dev_err(&client->dev, 861 838 "Failed to add sysfs cleanup action: %d\n", rc); 862 839 return rc; ··· 894 873 static struct i2c_driver m41t80_driver = { 895 874 .driver = { 896 875 .name = "rtc-m41t80", 876 + .pm = &m41t80_pm, 897 877 }, 898 878 .probe = m41t80_probe, 899 879 .remove = m41t80_remove,
+1 -1
drivers/rtc/rtc-m48t86.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/rtc.h> 18 18 #include <linux/platform_device.h> 19 - #include <linux/m48t86.h> 19 + #include <linux/platform_data/rtc-m48t86.h> 20 20 #include <linux/bcd.h> 21 21 22 22 #define M48T86_REG_SEC 0x00
+164
drivers/rtc/rtc-max6916.c
··· 1 + /* rtc-max6916.c 2 + * 3 + * Driver for MAXIM max6916 Low Current, SPI Compatible 4 + * Real Time Clock 5 + * 6 + * Author : Venkat Prashanth B U <venkat.prashanth2498@gmail.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License version 2 as 10 + * published by the Free Software Foundation. 11 + * 12 + */ 13 + 14 + #include <linux/init.h> 15 + #include <linux/module.h> 16 + #include <linux/device.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/rtc.h> 19 + #include <linux/spi/spi.h> 20 + #include <linux/bcd.h> 21 + 22 + /* Registers in max6916 rtc */ 23 + 24 + #define MAX6916_SECONDS_REG 0x01 25 + #define MAX6916_MINUTES_REG 0x02 26 + #define MAX6916_HOURS_REG 0x03 27 + #define MAX6916_DATE_REG 0x04 28 + #define MAX6916_MONTH_REG 0x05 29 + #define MAX6916_DAY_REG 0x06 30 + #define MAX6916_YEAR_REG 0x07 31 + #define MAX6916_CONTROL_REG 0x08 32 + #define MAX6916_STATUS_REG 0x0C 33 + #define MAX6916_CLOCK_BURST 0x3F 34 + 35 + static int max6916_read_reg(struct device *dev, unsigned char address, 36 + unsigned char *data) 37 + { 38 + struct spi_device *spi = to_spi_device(dev); 39 + 40 + *data = address | 0x80; 41 + 42 + return spi_write_then_read(spi, data, 1, data, 1); 43 + } 44 + 45 + static int max6916_write_reg(struct device *dev, unsigned char address, 46 + unsigned char data) 47 + { 48 + struct spi_device *spi = to_spi_device(dev); 49 + unsigned char buf[2]; 50 + 51 + buf[0] = address & 0x7F; 52 + buf[1] = data; 53 + 54 + return spi_write_then_read(spi, buf, 2, NULL, 0); 55 + } 56 + 57 + static int max6916_read_time(struct device *dev, struct rtc_time *dt) 58 + { 59 + struct spi_device *spi = to_spi_device(dev); 60 + int err; 61 + unsigned char buf[8]; 62 + 63 + buf[0] = MAX6916_CLOCK_BURST | 0x80; 64 + 65 + err = spi_write_then_read(spi, buf, 1, buf, 8); 66 + 67 + if (err) 68 + return err; 69 + 70 + dt->tm_sec = bcd2bin(buf[0]); 71 + dt->tm_min = bcd2bin(buf[1]); 72 + dt->tm_hour = bcd2bin(buf[2] & 0x3F); 73 + dt->tm_mday = bcd2bin(buf[3]); 74 + dt->tm_mon = bcd2bin(buf[4]) - 1; 75 + dt->tm_wday = bcd2bin(buf[5]) - 1; 76 + dt->tm_year = bcd2bin(buf[6]) + 100; 77 + 78 + return rtc_valid_tm(dt); 79 + } 80 + 81 + static int max6916_set_time(struct device *dev, struct rtc_time *dt) 82 + { 83 + struct spi_device *spi = to_spi_device(dev); 84 + unsigned char buf[9]; 85 + 86 + if (dt->tm_year < 100 || dt->tm_year > 199) { 87 + dev_err(&spi->dev, "Year must be between 2000 and 2099. It's %d.\n", 88 + dt->tm_year + 1900); 89 + return -EINVAL; 90 + } 91 + 92 + buf[0] = MAX6916_CLOCK_BURST & 0x7F; 93 + buf[1] = bin2bcd(dt->tm_sec); 94 + buf[2] = bin2bcd(dt->tm_min); 95 + buf[3] = (bin2bcd(dt->tm_hour) & 0X3F); 96 + buf[4] = bin2bcd(dt->tm_mday); 97 + buf[5] = bin2bcd(dt->tm_mon + 1); 98 + buf[6] = bin2bcd(dt->tm_wday + 1); 99 + buf[7] = bin2bcd(dt->tm_year % 100); 100 + buf[8] = bin2bcd(0x00); 101 + 102 + /* write the rtc settings */ 103 + return spi_write_then_read(spi, buf, 9, NULL, 0); 104 + } 105 + 106 + static const struct rtc_class_ops max6916_rtc_ops = { 107 + .read_time = max6916_read_time, 108 + .set_time = max6916_set_time, 109 + }; 110 + 111 + static int max6916_probe(struct spi_device *spi) 112 + { 113 + struct rtc_device *rtc; 114 + unsigned char data; 115 + int res; 116 + 117 + /* spi setup with max6916 in mode 3 and bits per word as 8 */ 118 + spi->mode = SPI_MODE_3; 119 + spi->bits_per_word = 8; 120 + spi_setup(spi); 121 + 122 + /* RTC Settings */ 123 + res = max6916_read_reg(&spi->dev, MAX6916_SECONDS_REG, &data); 124 + if (res) 125 + return res; 126 + 127 + /* Disable the write protect of rtc */ 128 + max6916_read_reg(&spi->dev, MAX6916_CONTROL_REG, &data); 129 + data = data & ~(1 << 7); 130 + max6916_write_reg(&spi->dev, MAX6916_CONTROL_REG, data); 131 + 132 + /*Enable oscillator,disable oscillator stop flag, glitch filter*/ 133 + max6916_read_reg(&spi->dev, MAX6916_STATUS_REG, &data); 134 + data = data & 0x1B; 135 + max6916_write_reg(&spi->dev, MAX6916_STATUS_REG, data); 136 + 137 + /* display the settings */ 138 + max6916_read_reg(&spi->dev, MAX6916_CONTROL_REG, &data); 139 + dev_info(&spi->dev, "MAX6916 RTC CTRL Reg = 0x%02x\n", data); 140 + 141 + max6916_read_reg(&spi->dev, MAX6916_STATUS_REG, &data); 142 + dev_info(&spi->dev, "MAX6916 RTC Status Reg = 0x%02x\n", data); 143 + 144 + rtc = devm_rtc_device_register(&spi->dev, "max6916", 145 + &max6916_rtc_ops, THIS_MODULE); 146 + if (IS_ERR(rtc)) 147 + return PTR_ERR(rtc); 148 + 149 + spi_set_drvdata(spi, rtc); 150 + 151 + return 0; 152 + } 153 + 154 + static struct spi_driver max6916_driver = { 155 + .driver = { 156 + .name = "max6916", 157 + }, 158 + .probe = max6916_probe, 159 + }; 160 + module_spi_driver(max6916_driver); 161 + 162 + MODULE_DESCRIPTION("MAX6916 SPI RTC DRIVER"); 163 + MODULE_AUTHOR("Venkat Prashanth B U <venkat.prashanth2498@gmail.com>"); 164 + MODULE_LICENSE("GPL v2");
+1 -9
drivers/rtc/rtc-mrst.c
··· 32 32 #include <linux/interrupt.h> 33 33 #include <linux/spinlock.h> 34 34 #include <linux/kernel.h> 35 + #include <linux/mc146818rtc.h> 35 36 #include <linux/module.h> 36 37 #include <linux/init.h> 37 38 #include <linux/sfi.h> 38 39 39 - #include <asm-generic/rtc.h> 40 40 #include <asm/intel_scu_ipc.h> 41 41 #include <asm/intel-mid.h> 42 42 #include <asm/intel_mid_vrtc.h> ··· 148 148 149 149 if (mrst->irq <= 0) 150 150 return -EIO; 151 - 152 - /* Basic alarms only support hour, minute, and seconds fields. 153 - * Some also support day and month, for alarms up to a year in 154 - * the future. 155 - */ 156 - t->time.tm_mday = -1; 157 - t->time.tm_mon = -1; 158 - t->time.tm_year = -1; 159 151 160 152 /* vRTC only supports binary mode */ 161 153 spin_lock_irq(&rtc_lock);
+2 -2
drivers/rtc/rtc-pcf2123.c
··· 96 96 #define CD_TMR_TE BIT(3) /* Countdown timer enable */ 97 97 98 98 /* PCF2123_REG_OFFSET BITS */ 99 - #define OFFSET_SIGN_BIT BIT(6) /* 2's complement sign bit */ 99 + #define OFFSET_SIGN_BIT 6 /* 2's complement sign bit */ 100 100 #define OFFSET_COARSE BIT(7) /* Coarse mode offset */ 101 101 #define OFFSET_STEP (2170) /* Offset step in parts per billion */ 102 102 ··· 217 217 if (reg & OFFSET_COARSE) 218 218 reg <<= 1; /* multiply by 2 and sign extend */ 219 219 else 220 - reg |= (reg & OFFSET_SIGN_BIT) << 1; /* sign extend only */ 220 + reg = sign_extend32(reg, OFFSET_SIGN_BIT); 221 221 222 222 *offset = ((long)reg) * OFFSET_STEP; 223 223
+43 -16
drivers/rtc/rtc-pcf85063.c
··· 16 16 #include <linux/rtc.h> 17 17 #include <linux/module.h> 18 18 19 + /* 20 + * Information for this driver was pulled from the following datasheets. 21 + * 22 + * http://www.nxp.com/documents/data_sheet/PCF85063A.pdf 23 + * http://www.nxp.com/documents/data_sheet/PCF85063TP.pdf 24 + * 25 + * PCF85063A -- Rev. 6 — 18 November 2015 26 + * PCF85063TP -- Rev. 4 — 6 May 2015 27 + */ 28 + 19 29 #define PCF85063_REG_CTRL1 0x00 /* status */ 20 30 #define PCF85063_REG_CTRL1_STOP BIT(5) 21 31 #define PCF85063_REG_CTRL2 0x01 ··· 65 55 return 0; 66 56 } 67 57 68 - /* 69 - * In the routines that deal directly with the pcf85063 hardware, we use 70 - * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch. 71 - */ 58 + static int pcf85063_start_clock(struct i2c_client *client, u8 ctrl1) 59 + { 60 + s32 ret; 61 + 62 + /* start the clock */ 63 + ctrl1 &= PCF85063_REG_CTRL1_STOP; 64 + 65 + ret = i2c_smbus_write_byte_data(client, PCF85063_REG_CTRL1, ctrl1); 66 + if (ret < 0) { 67 + dev_err(&client->dev, "Failing to start the clock\n"); 68 + return -EIO; 69 + } 70 + 71 + return 0; 72 + } 73 + 72 74 static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) 73 75 { 74 76 int rc; ··· 112 90 tm->tm_wday = regs[4] & 0x07; 113 91 tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ 114 92 tm->tm_year = bcd2bin(regs[6]); 115 - if (tm->tm_year < 70) 116 - tm->tm_year += 100; /* assume we are in 1970...2069 */ 93 + tm->tm_year += 100; 117 94 118 95 return rtc_valid_tm(tm); 119 96 } ··· 120 99 static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm) 121 100 { 122 101 int rc; 123 - u8 regs[8]; 102 + u8 regs[7]; 103 + u8 ctrl1; 104 + 105 + if ((tm->tm_year < 100) || (tm->tm_year > 199)) 106 + return -EINVAL; 124 107 125 108 /* 126 109 * to accurately set the time, reset the divider chain and keep it in 127 110 * reset state until all time/date registers are written 128 111 */ 129 - rc = pcf85063_stop_clock(client, &regs[7]); 112 + rc = pcf85063_stop_clock(client, &ctrl1); 130 113 if (rc != 0) 131 114 return rc; 132 115 ··· 150 125 regs[5] = bin2bcd(tm->tm_mon + 1); 151 126 152 127 /* year and century */ 153 - regs[6] = bin2bcd(tm->tm_year % 100); 154 - 155 - /* 156 - * after all time/date registers are written, let the 'address auto 157 - * increment' feature wrap around and write register CTRL1 to re-enable 158 - * the clock divider chain again 159 - */ 160 - regs[7] &= ~PCF85063_REG_CTRL1_STOP; 128 + regs[6] = bin2bcd(tm->tm_year - 100); 161 129 162 130 /* write all registers at once */ 163 131 rc = i2c_smbus_write_i2c_block_data(client, PCF85063_REG_SC, ··· 159 141 dev_err(&client->dev, "date/time register write error\n"); 160 142 return rc; 161 143 } 144 + 145 + /* 146 + * Write the control register as a separate action since the size of 147 + * the register space is different between the PCF85063TP and 148 + * PCF85063A devices. The rollover point can not be used. 149 + */ 150 + rc = pcf85063_start_clock(client, ctrl1); 151 + if (rc != 0) 152 + return rc; 162 153 163 154 return 0; 164 155 }
+1 -4
drivers/rtc/rtc-pcf8563.c
··· 341 341 "%s: raw data is min=%02x, hr=%02x, mday=%02x, wday=%02x\n", 342 342 __func__, buf[0], buf[1], buf[2], buf[3]); 343 343 344 + tm->time.tm_sec = 0; 344 345 tm->time.tm_min = bcd2bin(buf[0] & 0x7F); 345 346 tm->time.tm_hour = bcd2bin(buf[1] & 0x3F); 346 347 tm->time.tm_mday = bcd2bin(buf[2] & 0x3F); 347 348 tm->time.tm_wday = bcd2bin(buf[3] & 0x7); 348 - tm->time.tm_mon = -1; 349 - tm->time.tm_year = -1; 350 - tm->time.tm_yday = -1; 351 - tm->time.tm_isdst = -1; 352 349 353 350 err = pcf8563_get_alarm_mode(client, &tm->enabled, &tm->pending); 354 351 if (err < 0)
+1
drivers/rtc/rtc-rc5t583.c
··· 128 128 return ret; 129 129 } 130 130 131 + alm->time.tm_sec = 0; 131 132 alm->time.tm_min = bcd2bin(alarm_data[0]); 132 133 alm->time.tm_hour = bcd2bin(alarm_data[1]); 133 134 alm->time.tm_mday = bcd2bin(alarm_data[2]);
-6
drivers/rtc/rtc-rs5c372.c
··· 341 341 t->time.tm_sec = 0; 342 342 t->time.tm_min = bcd2bin(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f); 343 343 t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]); 344 - t->time.tm_mday = -1; 345 - t->time.tm_mon = -1; 346 - t->time.tm_year = -1; 347 - t->time.tm_wday = -1; 348 - t->time.tm_yday = -1; 349 - t->time.tm_isdst = -1; 350 344 351 345 /* ... and status */ 352 346 t->enabled = !!(rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE);
+133 -72
drivers/rtc/rtc-rv8803.c
··· 13 13 14 14 #include <linux/bcd.h> 15 15 #include <linux/bitops.h> 16 + #include <linux/log2.h> 16 17 #include <linux/i2c.h> 17 18 #include <linux/interrupt.h> 18 19 #include <linux/kernel.h> 19 20 #include <linux/module.h> 20 21 #include <linux/rtc.h> 22 + 23 + #define RV8803_I2C_TRY_COUNT 4 21 24 22 25 #define RV8803_SEC 0x00 23 26 #define RV8803_MIN 0x01 ··· 59 56 u8 ctrl; 60 57 }; 61 58 59 + static int rv8803_read_reg(const struct i2c_client *client, u8 reg) 60 + { 61 + int try = RV8803_I2C_TRY_COUNT; 62 + s32 ret; 63 + 64 + /* 65 + * There is a 61µs window during which the RTC does not acknowledge I2C 66 + * transfers. In that case, ensure that there are multiple attempts. 67 + */ 68 + do 69 + ret = i2c_smbus_read_byte_data(client, reg); 70 + while ((ret == -ENXIO || ret == -EIO) && --try); 71 + if (ret < 0) 72 + dev_err(&client->dev, "Unable to read register 0x%02x\n", reg); 73 + 74 + return ret; 75 + } 76 + 77 + static int rv8803_read_regs(const struct i2c_client *client, 78 + u8 reg, u8 count, u8 *values) 79 + { 80 + int try = RV8803_I2C_TRY_COUNT; 81 + s32 ret; 82 + 83 + do 84 + ret = i2c_smbus_read_i2c_block_data(client, reg, count, values); 85 + while ((ret == -ENXIO || ret == -EIO) && --try); 86 + if (ret != count) { 87 + dev_err(&client->dev, 88 + "Unable to read registers 0x%02x..0x%02x\n", 89 + reg, reg + count - 1); 90 + return ret < 0 ? ret : -EIO; 91 + } 92 + 93 + return 0; 94 + } 95 + 96 + static int rv8803_write_reg(const struct i2c_client *client, u8 reg, u8 value) 97 + { 98 + int try = RV8803_I2C_TRY_COUNT; 99 + s32 ret; 100 + 101 + do 102 + ret = i2c_smbus_write_byte_data(client, reg, value); 103 + while ((ret == -ENXIO || ret == -EIO) && --try); 104 + if (ret) 105 + dev_err(&client->dev, "Unable to write register 0x%02x\n", reg); 106 + 107 + return ret; 108 + } 109 + 110 + static int rv8803_write_regs(const struct i2c_client *client, 111 + u8 reg, u8 count, const u8 *values) 112 + { 113 + int try = RV8803_I2C_TRY_COUNT; 114 + s32 ret; 115 + 116 + do 117 + ret = i2c_smbus_write_i2c_block_data(client, reg, count, 118 + values); 119 + while ((ret == -ENXIO || ret == -EIO) && --try); 120 + if (ret) 121 + dev_err(&client->dev, 122 + "Unable to write registers 0x%02x..0x%02x\n", 123 + reg, reg + count - 1); 124 + 125 + return ret; 126 + } 127 + 62 128 static irqreturn_t rv8803_handle_irq(int irq, void *dev_id) 63 129 { 64 130 struct i2c_client *client = dev_id; 65 131 struct rv8803_data *rv8803 = i2c_get_clientdata(client); 66 132 unsigned long events = 0; 67 - int flags, try = 0; 133 + int flags; 68 134 69 135 mutex_lock(&rv8803->flags_lock); 70 136 71 - do { 72 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 73 - try++; 74 - } while ((flags == -ENXIO) && (try < 3)); 137 + flags = rv8803_read_reg(client, RV8803_FLAG); 75 138 if (flags <= 0) { 76 139 mutex_unlock(&rv8803->flags_lock); 77 140 return IRQ_NONE; ··· 169 100 170 101 if (events) { 171 102 rtc_update_irq(rv8803->rtc, 1, events); 172 - i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 173 - i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 174 - rv8803->ctrl); 103 + rv8803_write_reg(client, RV8803_FLAG, flags); 104 + rv8803_write_reg(rv8803->client, RV8803_CTRL, rv8803->ctrl); 175 105 } 176 106 177 107 mutex_unlock(&rv8803->flags_lock); ··· 186 118 u8 *date = date1; 187 119 int ret, flags; 188 120 189 - flags = i2c_smbus_read_byte_data(rv8803->client, RV8803_FLAG); 121 + flags = rv8803_read_reg(rv8803->client, RV8803_FLAG); 190 122 if (flags < 0) 191 123 return flags; 192 124 ··· 195 127 return -EINVAL; 196 128 } 197 129 198 - ret = i2c_smbus_read_i2c_block_data(rv8803->client, RV8803_SEC, 199 - 7, date); 200 - if (ret != 7) 201 - return ret < 0 ? ret : -EIO; 130 + ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date); 131 + if (ret) 132 + return ret; 202 133 203 134 if ((date1[RV8803_SEC] & 0x7f) == bin2bcd(59)) { 204 - ret = i2c_smbus_read_i2c_block_data(rv8803->client, RV8803_SEC, 205 - 7, date2); 206 - if (ret != 7) 207 - return ret < 0 ? ret : -EIO; 135 + ret = rv8803_read_regs(rv8803->client, RV8803_SEC, 7, date2); 136 + if (ret) 137 + return ret; 208 138 209 139 if ((date2[RV8803_SEC] & 0x7f) != bin2bcd(59)) 210 140 date = date2; ··· 211 145 tm->tm_sec = bcd2bin(date[RV8803_SEC] & 0x7f); 212 146 tm->tm_min = bcd2bin(date[RV8803_MIN] & 0x7f); 213 147 tm->tm_hour = bcd2bin(date[RV8803_HOUR] & 0x3f); 214 - tm->tm_wday = ffs(date[RV8803_WEEK] & 0x7f); 148 + tm->tm_wday = ilog2(date[RV8803_WEEK] & 0x7f); 215 149 tm->tm_mday = bcd2bin(date[RV8803_DAY] & 0x3f); 216 150 tm->tm_mon = bcd2bin(date[RV8803_MONTH] & 0x1f) - 1; 217 151 tm->tm_year = bcd2bin(date[RV8803_YEAR]) + 100; 218 152 219 - return rtc_valid_tm(tm); 153 + return 0; 220 154 } 221 155 222 156 static int rv8803_set_time(struct device *dev, struct rtc_time *tm) 223 157 { 224 158 struct rv8803_data *rv8803 = dev_get_drvdata(dev); 225 159 u8 date[7]; 226 - int flags, ret; 160 + int ctrl, flags, ret; 227 161 228 162 if ((tm->tm_year < 100) || (tm->tm_year > 199)) 229 163 return -EINVAL; 164 + 165 + ctrl = rv8803_read_reg(rv8803->client, RV8803_CTRL); 166 + if (ctrl < 0) 167 + return ctrl; 168 + 169 + /* Stop the clock */ 170 + ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, 171 + ctrl | RV8803_CTRL_RESET); 172 + if (ret) 173 + return ret; 230 174 231 175 date[RV8803_SEC] = bin2bcd(tm->tm_sec); 232 176 date[RV8803_MIN] = bin2bcd(tm->tm_min); ··· 246 170 date[RV8803_MONTH] = bin2bcd(tm->tm_mon + 1); 247 171 date[RV8803_YEAR] = bin2bcd(tm->tm_year - 100); 248 172 249 - ret = i2c_smbus_write_i2c_block_data(rv8803->client, RV8803_SEC, 250 - 7, date); 251 - if (ret < 0) 173 + ret = rv8803_write_regs(rv8803->client, RV8803_SEC, 7, date); 174 + if (ret) 175 + return ret; 176 + 177 + /* Restart the clock */ 178 + ret = rv8803_write_reg(rv8803->client, RV8803_CTRL, 179 + ctrl & ~RV8803_CTRL_RESET); 180 + if (ret) 252 181 return ret; 253 182 254 183 mutex_lock(&rv8803->flags_lock); 255 184 256 - flags = i2c_smbus_read_byte_data(rv8803->client, RV8803_FLAG); 185 + flags = rv8803_read_reg(rv8803->client, RV8803_FLAG); 257 186 if (flags < 0) { 258 187 mutex_unlock(&rv8803->flags_lock); 259 188 return flags; 260 189 } 261 190 262 - ret = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, 263 - flags & ~RV8803_FLAG_V2F); 191 + ret = rv8803_write_reg(rv8803->client, RV8803_FLAG, 192 + flags & ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F)); 264 193 265 194 mutex_unlock(&rv8803->flags_lock); 266 195 ··· 279 198 u8 alarmvals[3]; 280 199 int flags, ret; 281 200 282 - ret = i2c_smbus_read_i2c_block_data(client, RV8803_ALARM_MIN, 283 - 3, alarmvals); 284 - if (ret != 3) 285 - return ret < 0 ? ret : -EIO; 201 + ret = rv8803_read_regs(client, RV8803_ALARM_MIN, 3, alarmvals); 202 + if (ret) 203 + return ret; 286 204 287 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 205 + flags = rv8803_read_reg(client, RV8803_FLAG); 288 206 if (flags < 0) 289 207 return flags; 290 208 291 209 alrm->time.tm_sec = 0; 292 210 alrm->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); 293 211 alrm->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); 294 - alrm->time.tm_wday = -1; 295 212 alrm->time.tm_mday = bcd2bin(alarmvals[2] & 0x3f); 296 - alrm->time.tm_mon = -1; 297 - alrm->time.tm_year = -1; 298 213 299 214 alrm->enabled = !!(rv8803->ctrl & RV8803_CTRL_AIE); 300 215 alrm->pending = (flags & RV8803_FLAG_AF) && alrm->enabled; ··· 316 239 317 240 mutex_lock(&rv8803->flags_lock); 318 241 319 - ret = i2c_smbus_read_i2c_block_data(client, RV8803_FLAG, 2, ctrl); 320 - if (ret != 2) { 242 + ret = rv8803_read_regs(client, RV8803_FLAG, 2, ctrl); 243 + if (ret) { 321 244 mutex_unlock(&rv8803->flags_lock); 322 - return ret < 0 ? ret : -EIO; 245 + return ret; 323 246 } 324 247 325 248 alarmvals[0] = bin2bcd(alrm->time.tm_min); ··· 328 251 329 252 if (rv8803->ctrl & (RV8803_CTRL_AIE | RV8803_CTRL_UIE)) { 330 253 rv8803->ctrl &= ~(RV8803_CTRL_AIE | RV8803_CTRL_UIE); 331 - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 332 - rv8803->ctrl); 254 + err = rv8803_write_reg(rv8803->client, RV8803_CTRL, 255 + rv8803->ctrl); 333 256 if (err) { 334 257 mutex_unlock(&rv8803->flags_lock); 335 258 return err; ··· 337 260 } 338 261 339 262 ctrl[1] &= ~RV8803_FLAG_AF; 340 - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_FLAG, ctrl[1]); 263 + err = rv8803_write_reg(rv8803->client, RV8803_FLAG, ctrl[1]); 341 264 mutex_unlock(&rv8803->flags_lock); 342 265 if (err) 343 266 return err; 344 267 345 - err = i2c_smbus_write_i2c_block_data(rv8803->client, RV8803_ALARM_MIN, 346 - 3, alarmvals); 268 + err = rv8803_write_regs(rv8803->client, RV8803_ALARM_MIN, 3, alarmvals); 347 269 if (err) 348 270 return err; 349 271 ··· 352 276 if (rv8803->rtc->aie_timer.enabled) 353 277 rv8803->ctrl |= RV8803_CTRL_AIE; 354 278 355 - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_CTRL, 356 - rv8803->ctrl); 279 + err = rv8803_write_reg(rv8803->client, RV8803_CTRL, 280 + rv8803->ctrl); 357 281 if (err) 358 282 return err; 359 283 } ··· 382 306 } 383 307 384 308 mutex_lock(&rv8803->flags_lock); 385 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 309 + flags = rv8803_read_reg(client, RV8803_FLAG); 386 310 if (flags < 0) { 387 311 mutex_unlock(&rv8803->flags_lock); 388 312 return flags; 389 313 } 390 314 flags &= ~(RV8803_FLAG_AF | RV8803_FLAG_UF); 391 - err = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 315 + err = rv8803_write_reg(client, RV8803_FLAG, flags); 392 316 mutex_unlock(&rv8803->flags_lock); 393 317 if (err) 394 318 return err; 395 319 396 320 if (ctrl != rv8803->ctrl) { 397 321 rv8803->ctrl = ctrl; 398 - err = i2c_smbus_write_byte_data(client, RV8803_CTRL, 399 - rv8803->ctrl); 322 + err = rv8803_write_reg(client, RV8803_CTRL, rv8803->ctrl); 400 323 if (err) 401 324 return err; 402 325 } ··· 411 336 412 337 switch (cmd) { 413 338 case RTC_VL_READ: 414 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 339 + flags = rv8803_read_reg(client, RV8803_FLAG); 415 340 if (flags < 0) 416 341 return flags; 417 342 ··· 430 355 431 356 case RTC_VL_CLR: 432 357 mutex_lock(&rv8803->flags_lock); 433 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 358 + flags = rv8803_read_reg(client, RV8803_FLAG); 434 359 if (flags < 0) { 435 360 mutex_unlock(&rv8803->flags_lock); 436 361 return flags; 437 362 } 438 363 439 364 flags &= ~(RV8803_FLAG_V1F | RV8803_FLAG_V2F); 440 - ret = i2c_smbus_write_byte_data(client, RV8803_FLAG, flags); 365 + ret = rv8803_write_reg(client, RV8803_FLAG, flags); 441 366 mutex_unlock(&rv8803->flags_lock); 442 - if (ret < 0) 367 + if (ret) 443 368 return ret; 444 369 445 370 return 0; ··· 457 382 struct i2c_client *client = to_i2c_client(dev); 458 383 int ret; 459 384 460 - ret = i2c_smbus_write_byte_data(client, RV8803_RAM, buf[0]); 461 - if (ret < 0) 385 + ret = rv8803_write_reg(client, RV8803_RAM, buf[0]); 386 + if (ret) 462 387 return ret; 463 388 464 389 return 1; ··· 472 397 struct i2c_client *client = to_i2c_client(dev); 473 398 int ret; 474 399 475 - ret = i2c_smbus_read_byte_data(client, RV8803_RAM); 400 + ret = rv8803_read_reg(client, RV8803_RAM); 476 401 if (ret < 0) 477 402 return ret; 478 403 ··· 502 427 { 503 428 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 504 429 struct rv8803_data *rv8803; 505 - int err, flags, try = 0; 430 + int err, flags; 506 431 507 432 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 508 433 I2C_FUNC_SMBUS_I2C_BLOCK)) { ··· 519 444 rv8803->client = client; 520 445 i2c_set_clientdata(client, rv8803); 521 446 522 - /* 523 - * There is a 60µs window where the RTC may not reply on the i2c bus in 524 - * that case, the transfer is not ACKed. In that case, ensure there are 525 - * multiple attempts. 526 - */ 527 - do { 528 - flags = i2c_smbus_read_byte_data(client, RV8803_FLAG); 529 - try++; 530 - } while ((flags == -ENXIO) && (try < 3)); 531 - 447 + flags = rv8803_read_reg(client, RV8803_FLAG); 532 448 if (flags < 0) 533 449 return flags; 534 450 ··· 554 488 return PTR_ERR(rv8803->rtc); 555 489 } 556 490 557 - try = 0; 558 - do { 559 - err = i2c_smbus_write_byte_data(rv8803->client, RV8803_EXT, 560 - RV8803_EXT_WADA); 561 - try++; 562 - } while ((err == -ENXIO) && (try < 3)); 491 + err = rv8803_write_reg(rv8803->client, RV8803_EXT, RV8803_EXT_WADA); 563 492 if (err) 564 493 return err; 565 494
+1 -7
drivers/rtc/rtc-rx8010.c
··· 272 272 t->time.tm_min = bcd2bin(alarmvals[0] & 0x7f); 273 273 t->time.tm_hour = bcd2bin(alarmvals[1] & 0x3f); 274 274 275 - if (alarmvals[2] & RX8010_ALARM_AE) 276 - t->time.tm_mday = -1; 277 - else 275 + if (!(alarmvals[2] & RX8010_ALARM_AE)) 278 276 t->time.tm_mday = bcd2bin(alarmvals[2] & 0x7f); 279 - 280 - t->time.tm_wday = -1; 281 - t->time.tm_mon = -1; 282 - t->time.tm_year = -1; 283 277 284 278 t->enabled = !!(rx8010->ctrlreg & RX8010_CTRL_AIE); 285 279 t->pending = (flagreg & RX8010_FLAG_AF) && t->enabled;
-5
drivers/rtc/rtc-rx8025.c
··· 319 319 t->time.tm_hour = bcd2bin(ald[1] & 0x1f) % 12 320 320 + (ald[1] & 0x20 ? 12 : 0); 321 321 322 - t->time.tm_wday = -1; 323 - t->time.tm_mday = -1; 324 - t->time.tm_mon = -1; 325 - t->time.tm_year = -1; 326 - 327 322 dev_dbg(dev, "%s: date: %ds %dm %dh %dmd %dm %dy\n", 328 323 __func__, 329 324 t->time.tm_sec, t->time.tm_min, t->time.tm_hour,
+117 -36
drivers/rtc/rtc-s35390a.c
··· 15 15 #include <linux/bitrev.h> 16 16 #include <linux/bcd.h> 17 17 #include <linux/slab.h> 18 + #include <linux/delay.h> 18 19 19 20 #define S35390A_CMD_STATUS1 0 20 21 #define S35390A_CMD_STATUS2 1 ··· 35 34 #define S35390A_ALRM_BYTE_HOURS 1 36 35 #define S35390A_ALRM_BYTE_MINS 2 37 36 37 + /* flags for STATUS1 */ 38 38 #define S35390A_FLAG_POC 0x01 39 39 #define S35390A_FLAG_BLD 0x02 40 + #define S35390A_FLAG_INT2 0x04 40 41 #define S35390A_FLAG_24H 0x40 41 42 #define S35390A_FLAG_RESET 0x80 43 + 44 + /* flag for STATUS2 */ 42 45 #define S35390A_FLAG_TEST 0x01 43 46 44 47 #define S35390A_INT2_MODE_MASK 0xF0 ··· 99 94 return 0; 100 95 } 101 96 102 - static int s35390a_reset(struct s35390a *s35390a) 97 + /* 98 + * Returns <0 on error, 0 if rtc is setup fine and 1 if the chip was reset. 99 + * To keep the information if an irq is pending, pass the value read from 100 + * STATUS1 to the caller. 101 + */ 102 + static int s35390a_reset(struct s35390a *s35390a, char *status1) 103 103 { 104 - char buf[1]; 104 + char buf; 105 + int ret; 106 + unsigned initcount = 0; 105 107 106 - if (s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, buf, sizeof(buf)) < 0) 107 - return -EIO; 108 + ret = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, status1, 1); 109 + if (ret < 0) 110 + return ret; 108 111 109 - if (!(buf[0] & (S35390A_FLAG_POC | S35390A_FLAG_BLD))) 112 + if (*status1 & S35390A_FLAG_POC) 113 + /* 114 + * Do not communicate for 0.5 seconds since the power-on 115 + * detection circuit is in operation. 116 + */ 117 + msleep(500); 118 + else if (!(*status1 & S35390A_FLAG_BLD)) 119 + /* 120 + * If both POC and BLD are unset everything is fine. 121 + */ 110 122 return 0; 111 123 112 - buf[0] |= (S35390A_FLAG_RESET | S35390A_FLAG_24H); 113 - buf[0] &= 0xf0; 114 - return s35390a_set_reg(s35390a, S35390A_CMD_STATUS1, buf, sizeof(buf)); 124 + /* 125 + * At least one of POC and BLD are set, so reinitialise chip. Keeping 126 + * this information in the hardware to know later that the time isn't 127 + * valid is unfortunately not possible because POC and BLD are cleared 128 + * on read. So the reset is best done now. 129 + * 130 + * The 24H bit is kept over reset, so set it already here. 131 + */ 132 + initialize: 133 + *status1 = S35390A_FLAG_24H; 134 + buf = S35390A_FLAG_RESET | S35390A_FLAG_24H; 135 + ret = s35390a_set_reg(s35390a, S35390A_CMD_STATUS1, &buf, 1); 136 + 137 + if (ret < 0) 138 + return ret; 139 + 140 + ret = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, &buf, 1); 141 + if (ret < 0) 142 + return ret; 143 + 144 + if (buf & (S35390A_FLAG_POC | S35390A_FLAG_BLD)) { 145 + /* Try up to five times to reset the chip */ 146 + if (initcount < 5) { 147 + ++initcount; 148 + goto initialize; 149 + } else 150 + return -EIO; 151 + } 152 + 153 + return 1; 115 154 } 116 155 117 156 static int s35390a_disable_test_mode(struct s35390a *s35390a) ··· 266 217 alm->time.tm_min, alm->time.tm_hour, alm->time.tm_mday, 267 218 alm->time.tm_mon, alm->time.tm_year, alm->time.tm_wday); 268 219 269 - /* disable interrupt */ 220 + /* disable interrupt (which deasserts the irq line) */ 270 221 err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &sts, sizeof(sts)); 271 222 if (err < 0) 272 223 return err; 273 224 274 - /* clear pending interrupt, if any */ 225 + /* clear pending interrupt (in STATUS1 only), if any */ 275 226 err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, &sts, sizeof(sts)); 276 227 if (err < 0) 277 228 return err; ··· 291 242 292 243 if (alm->time.tm_wday != -1) 293 244 buf[S35390A_ALRM_BYTE_WDAY] = bin2bcd(alm->time.tm_wday) | 0x80; 245 + else 246 + buf[S35390A_ALRM_BYTE_WDAY] = 0; 294 247 295 248 buf[S35390A_ALRM_BYTE_HOURS] = s35390a_hr2reg(s35390a, 296 249 alm->time.tm_hour) | 0x80; ··· 320 269 if (err < 0) 321 270 return err; 322 271 323 - if (bitrev8(sts) != S35390A_INT2_MODE_ALARM) 324 - return -EINVAL; 272 + if ((bitrev8(sts) & S35390A_INT2_MODE_MASK) != S35390A_INT2_MODE_ALARM) { 273 + /* 274 + * When the alarm isn't enabled, the register to configure 275 + * the alarm time isn't accessible. 276 + */ 277 + alm->enabled = 0; 278 + return 0; 279 + } else { 280 + alm->enabled = 1; 281 + } 325 282 326 283 err = s35390a_get_reg(s35390a, S35390A_CMD_INT2_REG1, buf, sizeof(buf)); 327 284 if (err < 0) 328 285 return err; 329 286 330 287 /* This chip returns the bits of each byte in reverse order */ 331 - for (i = 0; i < 3; ++i) { 288 + for (i = 0; i < 3; ++i) 332 289 buf[i] = bitrev8(buf[i]); 333 - buf[i] &= ~0x80; 334 - } 335 290 336 - alm->time.tm_wday = bcd2bin(buf[S35390A_ALRM_BYTE_WDAY]); 337 - alm->time.tm_hour = s35390a_reg2hr(s35390a, 338 - buf[S35390A_ALRM_BYTE_HOURS]); 339 - alm->time.tm_min = bcd2bin(buf[S35390A_ALRM_BYTE_MINS]); 291 + /* 292 + * B0 of the three matching registers is an enable flag. Iff it is set 293 + * the configured value is used for matching. 294 + */ 295 + if (buf[S35390A_ALRM_BYTE_WDAY] & 0x80) 296 + alm->time.tm_wday = 297 + bcd2bin(buf[S35390A_ALRM_BYTE_WDAY] & ~0x80); 298 + 299 + if (buf[S35390A_ALRM_BYTE_HOURS] & 0x80) 300 + alm->time.tm_hour = 301 + s35390a_reg2hr(s35390a, 302 + buf[S35390A_ALRM_BYTE_HOURS] & ~0x80); 303 + 304 + if (buf[S35390A_ALRM_BYTE_MINS] & 0x80) 305 + alm->time.tm_min = bcd2bin(buf[S35390A_ALRM_BYTE_MINS] & ~0x80); 306 + 307 + /* alarm triggers always at s=0 */ 308 + alm->time.tm_sec = 0; 340 309 341 310 dev_dbg(&client->dev, "%s: alm is mins=%d, hours=%d, wday=%d\n", 342 311 __func__, alm->time.tm_min, alm->time.tm_hour, ··· 398 327 static int s35390a_probe(struct i2c_client *client, 399 328 const struct i2c_device_id *id) 400 329 { 401 - int err; 330 + int err, err_reset; 402 331 unsigned int i; 403 332 struct s35390a *s35390a; 404 333 struct rtc_time tm; 405 - char buf[1]; 334 + char buf, status1; 406 335 407 336 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 408 337 err = -ENODEV; ··· 431 360 } 432 361 } 433 362 434 - err = s35390a_reset(s35390a); 435 - if (err < 0) { 363 + err_reset = s35390a_reset(s35390a, &status1); 364 + if (err_reset < 0) { 365 + err = err_reset; 436 366 dev_err(&client->dev, "error resetting chip\n"); 437 367 goto exit_dummy; 438 368 } 439 369 440 - err = s35390a_disable_test_mode(s35390a); 441 - if (err < 0) { 442 - dev_err(&client->dev, "error disabling test mode\n"); 443 - goto exit_dummy; 444 - } 445 - 446 - err = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, buf, sizeof(buf)); 447 - if (err < 0) { 448 - dev_err(&client->dev, "error checking 12/24 hour mode\n"); 449 - goto exit_dummy; 450 - } 451 - if (buf[0] & S35390A_FLAG_24H) 370 + if (status1 & S35390A_FLAG_24H) 452 371 s35390a->twentyfourhour = 1; 453 372 else 454 373 s35390a->twentyfourhour = 0; 455 374 456 - if (s35390a_get_datetime(client, &tm) < 0) 375 + if (status1 & S35390A_FLAG_INT2) { 376 + /* disable alarm (and maybe test mode) */ 377 + buf = 0; 378 + err = s35390a_set_reg(s35390a, S35390A_CMD_STATUS2, &buf, 1); 379 + if (err < 0) { 380 + dev_err(&client->dev, "error disabling alarm"); 381 + goto exit_dummy; 382 + } 383 + } else { 384 + err = s35390a_disable_test_mode(s35390a); 385 + if (err < 0) { 386 + dev_err(&client->dev, "error disabling test mode\n"); 387 + goto exit_dummy; 388 + } 389 + } 390 + 391 + if (err_reset > 0 || s35390a_get_datetime(client, &tm) < 0) 457 392 dev_warn(&client->dev, "clock needs to be set\n"); 458 393 459 394 device_set_wakeup_capable(&client->dev, 1); ··· 472 395 err = PTR_ERR(s35390a->rtc); 473 396 goto exit_dummy; 474 397 } 398 + 399 + if (status1 & S35390A_FLAG_INT2) 400 + rtc_update_irq(s35390a->rtc, 1, RTC_AF); 401 + 475 402 return 0; 476 403 477 404 exit_dummy:
+2 -14
drivers/rtc/rtc-s3c.c
··· 149 149 if (!is_power_of_2(freq)) 150 150 return -EINVAL; 151 151 152 + s3c_rtc_enable_clk(info); 152 153 spin_lock_irq(&info->pie_lock); 153 154 154 155 if (info->data->set_freq) 155 156 info->data->set_freq(info, freq); 156 157 157 158 spin_unlock_irq(&info->pie_lock); 159 + s3c_rtc_disable_clk(info); 158 160 159 161 return 0; 160 162 } ··· 266 264 /* decode the alarm enable field */ 267 265 if (alm_en & S3C2410_RTCALM_SECEN) 268 266 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec); 269 - else 270 - alm_tm->tm_sec = -1; 271 267 272 268 if (alm_en & S3C2410_RTCALM_MINEN) 273 269 alm_tm->tm_min = bcd2bin(alm_tm->tm_min); 274 - else 275 - alm_tm->tm_min = -1; 276 270 277 271 if (alm_en & S3C2410_RTCALM_HOUREN) 278 272 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour); 279 - else 280 - alm_tm->tm_hour = -1; 281 273 282 274 if (alm_en & S3C2410_RTCALM_DAYEN) 283 275 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday); 284 - else 285 - alm_tm->tm_mday = -1; 286 276 287 277 if (alm_en & S3C2410_RTCALM_MONEN) { 288 278 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon); 289 279 alm_tm->tm_mon -= 1; 290 - } else { 291 - alm_tm->tm_mon = -1; 292 280 } 293 281 294 282 if (alm_en & S3C2410_RTCALM_YEAREN) 295 283 alm_tm->tm_year = bcd2bin(alm_tm->tm_year); 296 - else 297 - alm_tm->tm_year = -1; 298 284 299 285 return 0; 300 286 } ··· 566 576 info->data->select_tick_clk(info); 567 577 568 578 s3c_rtc_setfreq(info, 1); 569 - 570 - s3c_rtc_disable_clk(info); 571 579 572 580 return 0; 573 581
+1 -41
drivers/rtc/rtc-sh.c
··· 481 481 tm->tm_mon = sh_rtc_read_alarm_value(rtc, RMONAR); 482 482 if (tm->tm_mon > 0) 483 483 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ 484 - tm->tm_year = 0xffff; 485 484 486 485 wkalrm->enabled = (readb(rtc->regbase + RCR1) & RCR1_AIE) ? 1 : 0; 487 486 ··· 499 500 writeb(bin2bcd(value) | AR_ENB, rtc->regbase + reg_off); 500 501 } 501 502 502 - static int sh_rtc_check_alarm(struct rtc_time *tm) 503 - { 504 - /* 505 - * The original rtc says anything > 0xc0 is "don't care" or "match 506 - * all" - most users use 0xff but rtc-dev uses -1 for the same thing. 507 - * The original rtc doesn't support years - some things use -1 and 508 - * some 0xffff. We use -1 to make out tests easier. 509 - */ 510 - if (tm->tm_year == 0xffff) 511 - tm->tm_year = -1; 512 - if (tm->tm_mon >= 0xff) 513 - tm->tm_mon = -1; 514 - if (tm->tm_mday >= 0xff) 515 - tm->tm_mday = -1; 516 - if (tm->tm_wday >= 0xff) 517 - tm->tm_wday = -1; 518 - if (tm->tm_hour >= 0xff) 519 - tm->tm_hour = -1; 520 - if (tm->tm_min >= 0xff) 521 - tm->tm_min = -1; 522 - if (tm->tm_sec >= 0xff) 523 - tm->tm_sec = -1; 524 - 525 - if (tm->tm_year > 9999 || 526 - tm->tm_mon >= 12 || 527 - tm->tm_mday == 0 || tm->tm_mday >= 32 || 528 - tm->tm_wday >= 7 || 529 - tm->tm_hour >= 24 || 530 - tm->tm_min >= 60 || 531 - tm->tm_sec >= 60) 532 - return -EINVAL; 533 - 534 - return 0; 535 - } 536 - 537 503 static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm) 538 504 { 539 505 struct platform_device *pdev = to_platform_device(dev); 540 506 struct sh_rtc *rtc = platform_get_drvdata(pdev); 541 507 unsigned int rcr1; 542 508 struct rtc_time *tm = &wkalrm->time; 543 - int mon, err; 544 - 545 - err = sh_rtc_check_alarm(tm); 546 - if (unlikely(err < 0)) 547 - return err; 509 + int mon; 548 510 549 511 spin_lock_irq(&rtc->lock); 550 512
-6
drivers/rtc/rtc-tegra.c
··· 179 179 if (sec == 0) { 180 180 /* alarm is disabled. */ 181 181 alarm->enabled = 0; 182 - alarm->time.tm_mon = -1; 183 - alarm->time.tm_mday = -1; 184 - alarm->time.tm_year = -1; 185 - alarm->time.tm_hour = -1; 186 - alarm->time.tm_min = -1; 187 - alarm->time.tm_sec = -1; 188 182 } else { 189 183 /* alarm is enabled. */ 190 184 alarm->enabled = 1;
+1 -1
drivers/rtc/rtc-v3020.c
··· 25 25 #include <linux/rtc.h> 26 26 #include <linux/types.h> 27 27 #include <linux/bcd.h> 28 - #include <linux/rtc-v3020.h> 28 + #include <linux/platform_data/rtc-v3020.h> 29 29 #include <linux/delay.h> 30 30 #include <linux/gpio.h> 31 31 #include <linux/slab.h>
+10 -59
include/asm-generic/rtc.h drivers/rtc/rtc-mc146818-lib.c
··· 1 - /* 2 - * include/asm-generic/rtc.h 3 - * 4 - * Author: Tom Rini <trini@mvista.com> 5 - * 6 - * Based on: 7 - * drivers/char/rtc.c 8 - * 9 - * Please read the COPYING file for all license details. 10 - */ 11 - 12 - #ifndef __ASM_RTC_H__ 13 - #define __ASM_RTC_H__ 14 - 15 - #include <linux/mc146818rtc.h> 16 - #include <linux/rtc.h> 17 1 #include <linux/bcd.h> 18 2 #include <linux/delay.h> 3 + #include <linux/export.h> 4 + #include <linux/mc146818rtc.h> 5 + 19 6 #ifdef CONFIG_ACPI 20 7 #include <linux/acpi.h> 21 8 #endif 22 9 23 - #define RTC_PIE 0x40 /* periodic interrupt enable */ 24 - #define RTC_AIE 0x20 /* alarm interrupt enable */ 25 - #define RTC_UIE 0x10 /* update-finished interrupt enable */ 26 - 27 - /* some dummy definitions */ 28 - #define RTC_BATT_BAD 0x100 /* battery bad */ 29 - #define RTC_SQWE 0x08 /* enable square-wave output */ 30 - #define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ 31 - #define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ 32 - #define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ 33 - 34 10 /* 35 11 * Returns true if a clock update is in progress 36 12 */ 37 - static inline unsigned char rtc_is_updating(void) 13 + static inline unsigned char mc146818_is_updating(void) 38 14 { 39 15 unsigned char uip; 40 16 unsigned long flags; ··· 21 45 return uip; 22 46 } 23 47 24 - static inline unsigned int __get_rtc_time(struct rtc_time *time) 48 + unsigned int mc146818_get_time(struct rtc_time *time) 25 49 { 26 50 unsigned char ctrl; 27 51 unsigned long flags; ··· 36 60 * can take just over 2ms. We wait 20ms. There is no need to 37 61 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP. 38 62 * If you need to know *exactly* when a second has started, enable 39 - * periodic update complete interrupts, (via ioctl) and then 63 + * periodic update complete interrupts, (via ioctl) and then 40 64 * immediately read /dev/rtc which will block until you get the IRQ. 41 65 * Once the read clears, read the RTC time (again via ioctl). Easy. 42 66 */ 43 - if (rtc_is_updating()) 67 + if (mc146818_is_updating()) 44 68 mdelay(20); 45 69 46 70 /* ··· 96 120 97 121 return RTC_24H; 98 122 } 99 - 100 - #ifndef get_rtc_time 101 - #define get_rtc_time __get_rtc_time 102 - #endif 123 + EXPORT_SYMBOL_GPL(mc146818_get_time); 103 124 104 125 /* Set the current date and time in the real time clock. */ 105 - static inline int __set_rtc_time(struct rtc_time *time) 126 + int mc146818_set_time(struct rtc_time *time) 106 127 { 107 128 unsigned long flags; 108 129 unsigned char mon, day, hrs, min, sec; ··· 195 222 196 223 return 0; 197 224 } 198 - 199 - #ifndef set_rtc_time 200 - #define set_rtc_time __set_rtc_time 201 - #endif 202 - 203 - static inline unsigned int get_rtc_ss(void) 204 - { 205 - struct rtc_time h; 206 - 207 - get_rtc_time(&h); 208 - return h.tm_sec; 209 - } 210 - 211 - static inline int get_rtc_pll(struct rtc_pll_info *pll) 212 - { 213 - return -EINVAL; 214 - } 215 - static inline int set_rtc_pll(struct rtc_pll_info *pll) 216 - { 217 - return -EINVAL; 218 - } 219 - 220 - #endif /* __ASM_RTC_H__ */ 225 + EXPORT_SYMBOL_GPL(mc146818_set_time);
include/linux/ds1286.h include/linux/rtc/ds1286.h
-66
include/linux/ds17287rtc.h
··· 1 - /* 2 - * ds17287rtc.h - register definitions for the ds1728[57] RTC / CMOS RAM 3 - * 4 - * This file is subject to the terms and conditions of the GNU General Public 5 - * License. See the file "COPYING" in the main directory of this archive 6 - * for more details. 7 - * 8 - * (C) 2003 Guido Guenther <agx@sigxcpu.org> 9 - */ 10 - #ifndef __LINUX_DS17287RTC_H 11 - #define __LINUX_DS17287RTC_H 12 - 13 - #include <linux/rtc.h> /* get the user-level API */ 14 - #include <linux/mc146818rtc.h> 15 - 16 - /* Register A */ 17 - #define DS_REGA_DV2 0x40 /* countdown chain */ 18 - #define DS_REGA_DV1 0x20 /* oscillator enable */ 19 - #define DS_REGA_DV0 0x10 /* bank select */ 20 - 21 - /* bank 1 registers */ 22 - #define DS_B1_MODEL 0x40 /* model number byte */ 23 - #define DS_B1_SN1 0x41 /* serial number byte 1 */ 24 - #define DS_B1_SN2 0x42 /* serial number byte 2 */ 25 - #define DS_B1_SN3 0x43 /* serial number byte 3 */ 26 - #define DS_B1_SN4 0x44 /* serial number byte 4 */ 27 - #define DS_B1_SN5 0x45 /* serial number byte 5 */ 28 - #define DS_B1_SN6 0x46 /* serial number byte 6 */ 29 - #define DS_B1_CRC 0x47 /* CRC byte */ 30 - #define DS_B1_CENTURY 0x48 /* Century byte */ 31 - #define DS_B1_DALARM 0x49 /* date alarm */ 32 - #define DS_B1_XCTRL4A 0x4a /* extendec control register 4a */ 33 - #define DS_B1_XCTRL4B 0x4b /* extendec control register 4b */ 34 - #define DS_B1_RTCADDR2 0x4e /* rtc address 2 */ 35 - #define DS_B1_RTCADDR3 0x4f /* rtc address 3 */ 36 - #define DS_B1_RAMLSB 0x50 /* extended ram LSB */ 37 - #define DS_B1_RAMMSB 0x51 /* extended ram MSB */ 38 - #define DS_B1_RAMDPORT 0x53 /* extended ram data port */ 39 - 40 - /* register details */ 41 - /* extended control register 4a */ 42 - #define DS_XCTRL4A_VRT2 0x80 /* valid ram and time */ 43 - #define DS_XCTRL4A_INCR 0x40 /* increment progress status */ 44 - #define DS_XCTRL4A_BME 0x20 /* burst mode enable */ 45 - #define DS_XCTRL4A_PAB 0x08 /* power active bar ctrl */ 46 - #define DS_XCTRL4A_RF 0x04 /* ram clear flag */ 47 - #define DS_XCTRL4A_WF 0x02 /* wake up alarm flag */ 48 - #define DS_XCTRL4A_KF 0x01 /* kickstart flag */ 49 - 50 - /* interrupt causes */ 51 - #define DS_XCTRL4A_IFS (DS_XCTRL4A_RF|DS_XCTRL4A_WF|DS_XCTRL4A_KF) 52 - 53 - /* extended control register 4b */ 54 - #define DS_XCTRL4B_ABE 0x80 /* auxiliary battery enable */ 55 - #define DS_XCTRL4B_E32K 0x40 /* enable 32.768 kHz Output */ 56 - #define DS_XCTRL4B_CS 0x20 /* crystal select */ 57 - #define DS_XCTRL4B_RCE 0x10 /* ram clear enable */ 58 - #define DS_XCTRL4B_PRS 0x08 /* PAB resec select */ 59 - #define DS_XCTRL4B_RIE 0x04 /* ram clear interrupt enable */ 60 - #define DS_XCTRL4B_WFE 0x02 /* wake up alarm interrupt enable */ 61 - #define DS_XCTRL4B_KFE 0x01 /* kickstart interrupt enable */ 62 - 63 - /* interrupt enable bits */ 64 - #define DS_XCTRL4B_IFES (DS_XCTRL4B_RIE|DS_XCTRL4B_WFE|DS_XCTRL4B_KFE) 65 - 66 - #endif /* __LINUX_DS17287RTC_H */
include/linux/m48t86.h include/linux/platform_data/rtc-m48t86.h
+5
include/linux/mc146818rtc.h
··· 14 14 #include <asm/io.h> 15 15 #include <linux/rtc.h> /* get the user-level API */ 16 16 #include <asm/mc146818rtc.h> /* register access macros */ 17 + #include <linux/bcd.h> 18 + #include <linux/delay.h> 17 19 18 20 #ifdef __KERNEL__ 19 21 #include <linux/spinlock.h> /* spinlock_t */ ··· 121 119 #else 122 120 #define RTC_IO_EXTENT_USED RTC_IO_EXTENT 123 121 #endif /* ARCH_RTC_LOCATION */ 122 + 123 + unsigned int mc146818_get_time(struct rtc_time *time); 124 + int mc146818_set_time(struct rtc_time *time); 124 125 125 126 #endif /* _MC146818RTC_H */
include/linux/rtc-ds2404.h include/linux/platform_data/rtc-ds2404.h
include/linux/rtc-v3020.h include/linux/platform_data/rtc-v3020.h
+10 -3
tools/testing/selftests/timers/rtctest.c
··· 144 144 145 145 retval = ioctl(fd, RTC_ALM_SET, &rtc_tm); 146 146 if (retval == -1) { 147 - if (errno == ENOTTY) { 147 + if (errno == EINVAL) { 148 148 fprintf(stderr, 149 149 "\n...Alarm IRQs not supported.\n"); 150 150 goto test_PIE; 151 151 } 152 + 152 153 perror("RTC_ALM_SET ioctl"); 153 154 exit(errno); 154 155 } ··· 167 166 /* Enable alarm interrupts */ 168 167 retval = ioctl(fd, RTC_AIE_ON, 0); 169 168 if (retval == -1) { 169 + if (errno == EINVAL) { 170 + fprintf(stderr, 171 + "\n...Alarm IRQs not supported.\n"); 172 + goto test_PIE; 173 + } 174 + 170 175 perror("RTC_AIE_ON ioctl"); 171 176 exit(errno); 172 177 } ··· 200 193 retval = ioctl(fd, RTC_IRQP_READ, &tmp); 201 194 if (retval == -1) { 202 195 /* not all RTCs support periodic IRQs */ 203 - if (errno == ENOTTY) { 196 + if (errno == EINVAL) { 204 197 fprintf(stderr, "\nNo periodic IRQ support\n"); 205 198 goto done; 206 199 } ··· 218 211 retval = ioctl(fd, RTC_IRQP_SET, tmp); 219 212 if (retval == -1) { 220 213 /* not all RTCs can change their periodic IRQ rate */ 221 - if (errno == ENOTTY) { 214 + if (errno == EINVAL) { 222 215 fprintf(stderr, 223 216 "\n...Periodic IRQ rate is fixed\n"); 224 217 goto done;