aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig39
-rw-r--r--drivers/rtc/Makefile3
-rw-r--r--drivers/rtc/rtc-at91rm9200.c46
-rw-r--r--drivers/rtc/rtc-bq4802.c30
-rw-r--r--drivers/rtc/rtc-cmos.c91
-rw-r--r--drivers/rtc/rtc-dev.c12
-rw-r--r--drivers/rtc/rtc-ds1216.c26
-rw-r--r--drivers/rtc/rtc-ds1286.c410
-rw-r--r--drivers/rtc/rtc-ds1302.c30
-rw-r--r--drivers/rtc/rtc-ds1305.c39
-rw-r--r--drivers/rtc/rtc-ds1307.c349
-rw-r--r--drivers/rtc/rtc-ds1374.c21
-rw-r--r--drivers/rtc/rtc-ds1511.c56
-rw-r--r--drivers/rtc/rtc-ds1553.c50
-rw-r--r--drivers/rtc/rtc-ds1672.c114
-rw-r--r--drivers/rtc/rtc-ds1742.c30
-rw-r--r--drivers/rtc/rtc-ds3234.c290
-rw-r--r--drivers/rtc/rtc-fm3130.c56
-rw-r--r--drivers/rtc/rtc-isl1208.c42
-rw-r--r--drivers/rtc/rtc-m41t80.c87
-rw-r--r--drivers/rtc/rtc-m41t94.c28
-rw-r--r--drivers/rtc/rtc-m48t35.c235
-rw-r--r--drivers/rtc/rtc-m48t59.c49
-rw-r--r--drivers/rtc/rtc-m48t86.c28
-rw-r--r--drivers/rtc/rtc-max6900.c253
-rw-r--r--drivers/rtc/rtc-max6902.c32
-rw-r--r--drivers/rtc/rtc-omap.c24
-rw-r--r--drivers/rtc/rtc-pcf8563.c82
-rw-r--r--drivers/rtc/rtc-pcf8583.c20
-rw-r--r--drivers/rtc/rtc-pl030.c11
-rw-r--r--drivers/rtc/rtc-pl031.c14
-rw-r--r--drivers/rtc/rtc-r9701.c24
-rw-r--r--drivers/rtc/rtc-rs5c313.c28
-rw-r--r--drivers/rtc/rtc-rs5c348.c30
-rw-r--r--drivers/rtc/rtc-rs5c372.c256
-rw-r--r--drivers/rtc/rtc-s35390a.c34
-rw-r--r--drivers/rtc/rtc-s3c.c42
-rw-r--r--drivers/rtc/rtc-sh.c68
-rw-r--r--drivers/rtc/rtc-stk17ta8.c51
-rw-r--r--drivers/rtc/rtc-v3020.c28
-rw-r--r--drivers/rtc/rtc-x1205.c30
41 files changed, 2173 insertions, 1015 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b57fba5c6d02..f660ef3e5b29 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -220,22 +220,22 @@ config RTC_DRV_PCF8583
220 will be called rtc-pcf8583. 220 will be called rtc-pcf8583.
221 221
222config RTC_DRV_M41T80 222config RTC_DRV_M41T80
223 tristate "ST M41T80/81/82/83/84/85/87" 223 tristate "ST M41T65/M41T80/81/82/83/84/85/87"
224 help 224 help
225 If you say Y here you will get support for the 225 If you say Y here you will get support for the ST M41T60
226 ST M41T80 RTC chips series. Currently following chips are 226 and M41T80 RTC chips series. Currently, the following chips are
227 supported: M41T80, M41T81, M41T82, M41T83, M41ST84, M41ST85 227 supported: M41T65, M41T80, M41T81, M41T82, M41T83, M41ST84,
228 and M41ST87. 228 M41ST85, and M41ST87.
229 229
230 This driver can also be built as a module. If so, the module 230 This driver can also be built as a module. If so, the module
231 will be called rtc-m41t80. 231 will be called rtc-m41t80.
232 232
233config RTC_DRV_M41T80_WDT 233config RTC_DRV_M41T80_WDT
234 bool "ST M41T80 series RTC watchdog timer" 234 bool "ST M41T65/M41T80 series RTC watchdog timer"
235 depends on RTC_DRV_M41T80 235 depends on RTC_DRV_M41T80
236 help 236 help
237 If you say Y here you will get support for the 237 If you say Y here you will get support for the
238 watchdog timer in ST M41T80 RTC chips series. 238 watchdog timer in the ST M41T60 and M41T80 RTC chips series.
239 239
240config RTC_DRV_TWL92330 240config RTC_DRV_TWL92330
241 boolean "TI TWL92330/Menelaus" 241 boolean "TI TWL92330/Menelaus"
@@ -319,6 +319,15 @@ config RTC_DRV_RS5C348
319 This driver can also be built as a module. If so, the module 319 This driver can also be built as a module. If so, the module
320 will be called rtc-rs5c348. 320 will be called rtc-rs5c348.
321 321
322config RTC_DRV_DS3234
323 tristate "Maxim/Dallas DS3234"
324 help
325 If you say yes here you get support for the
326 Maxim/Dallas DS3234 SPI RTC chip.
327
328 This driver can also be built as a module. If so, the module
329 will be called rtc-ds3234.
330
322endif # SPI_MASTER 331endif # SPI_MASTER
323 332
324comment "Platform RTC drivers" 333comment "Platform RTC drivers"
@@ -352,6 +361,11 @@ config RTC_DRV_DS1216
352 help 361 help
353 If you say yes here you get support for the Dallas DS1216 RTC chips. 362 If you say yes here you get support for the Dallas DS1216 RTC chips.
354 363
364config RTC_DRV_DS1286
365 tristate "Dallas DS1286"
366 help
367 If you say yes here you get support for the Dallas DS1286 RTC chips.
368
355config RTC_DRV_DS1302 369config RTC_DRV_DS1302
356 tristate "Dallas DS1302" 370 tristate "Dallas DS1302"
357 depends on SH_SECUREEDGE5410 371 depends on SH_SECUREEDGE5410
@@ -405,6 +419,15 @@ config RTC_DRV_M48T86
405 This driver can also be built as a module. If so, the module 419 This driver can also be built as a module. If so, the module
406 will be called rtc-m48t86. 420 will be called rtc-m48t86.
407 421
422config RTC_DRV_M48T35
423 tristate "ST M48T35"
424 help
425 If you say Y here you will get support for the
426 ST M48T35 RTC chip.
427
428 This driver can also be built as a module, if so, the module
429 will be called "rtc-m48t35".
430
408config RTC_DRV_M48T59 431config RTC_DRV_M48T59
409 tristate "ST M48T59/M48T08/M48T02" 432 tristate "ST M48T59/M48T08/M48T02"
410 help 433 help
@@ -589,7 +612,7 @@ config RTC_DRV_RS5C313
589 612
590config RTC_DRV_PPC 613config RTC_DRV_PPC
591 tristate "PowerPC machine dependent RTC support" 614 tristate "PowerPC machine dependent RTC support"
592 depends on PPC_MERGE 615 depends on PPC
593 help 616 help
594 The PowerPC kernel has machine-specific functions for accessing 617 The PowerPC kernel has machine-specific functions for accessing
595 the RTC. This exposes that functionality through the generic RTC 618 the RTC. This exposes that functionality through the generic RTC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 10f41f85c38a..d05928b3ca94 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
23obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o 23obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o 25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
26obj-$(CONFIG_RTC_DRV_DS1286) += rtc-ds1286.o
26obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o 27obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o
27obj-$(CONFIG_RTC_DRV_DS1305) += rtc-ds1305.o 28obj-$(CONFIG_RTC_DRV_DS1305) += rtc-ds1305.o
28obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o 29obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
@@ -31,11 +32,13 @@ obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
31obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 32obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
32obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 33obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
33obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 34obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
35obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o
34obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 36obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
35obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 37obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
36obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 38obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
37obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 39obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
38obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o 40obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
41obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o
39obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o 42obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o
40obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 43obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
41obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o 44obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 4e888cc8be5b..b5bf93706913 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -29,10 +29,10 @@
29#include <linux/completion.h> 29#include <linux/completion.h>
30 30
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32
32#include <mach/at91_rtc.h> 33#include <mach/at91_rtc.h>
33 34
34 35
35#define AT91_RTC_FREQ 1
36#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 36#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */
37 37
38static DECLARE_COMPLETION(at91_rtc_updated); 38static DECLARE_COMPLETION(at91_rtc_updated);
@@ -53,21 +53,21 @@ static void at91_rtc_decodetime(unsigned int timereg, unsigned int calreg,
53 } while ((time != at91_sys_read(timereg)) || 53 } while ((time != at91_sys_read(timereg)) ||
54 (date != at91_sys_read(calreg))); 54 (date != at91_sys_read(calreg)));
55 55
56 tm->tm_sec = BCD2BIN((time & AT91_RTC_SEC) >> 0); 56 tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0);
57 tm->tm_min = BCD2BIN((time & AT91_RTC_MIN) >> 8); 57 tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8);
58 tm->tm_hour = BCD2BIN((time & AT91_RTC_HOUR) >> 16); 58 tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16);
59 59
60 /* 60 /*
61 * The Calendar Alarm register does not have a field for 61 * The Calendar Alarm register does not have a field for
62 * the year - so these will return an invalid value. When an 62 * the year - so these will return an invalid value. When an
63 * alarm is set, at91_alarm_year wille store the current year. 63 * alarm is set, at91_alarm_year wille store the current year.
64 */ 64 */
65 tm->tm_year = BCD2BIN(date & AT91_RTC_CENT) * 100; /* century */ 65 tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */
66 tm->tm_year += BCD2BIN((date & AT91_RTC_YEAR) >> 8); /* year */ 66 tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */
67 67
68 tm->tm_wday = BCD2BIN((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */ 68 tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */
69 tm->tm_mon = BCD2BIN((date & AT91_RTC_MONTH) >> 16) - 1; 69 tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1;
70 tm->tm_mday = BCD2BIN((date & AT91_RTC_DATE) >> 24); 70 tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24);
71} 71}
72 72
73/* 73/*
@@ -106,16 +106,16 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
106 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ACKUPD); 106 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ACKUPD);
107 107
108 at91_sys_write(AT91_RTC_TIMR, 108 at91_sys_write(AT91_RTC_TIMR,
109 BIN2BCD(tm->tm_sec) << 0 109 bin2bcd(tm->tm_sec) << 0
110 | BIN2BCD(tm->tm_min) << 8 110 | bin2bcd(tm->tm_min) << 8
111 | BIN2BCD(tm->tm_hour) << 16); 111 | bin2bcd(tm->tm_hour) << 16);
112 112
113 at91_sys_write(AT91_RTC_CALR, 113 at91_sys_write(AT91_RTC_CALR,
114 BIN2BCD((tm->tm_year + 1900) / 100) /* century */ 114 bin2bcd((tm->tm_year + 1900) / 100) /* century */
115 | BIN2BCD(tm->tm_year % 100) << 8 /* year */ 115 | bin2bcd(tm->tm_year % 100) << 8 /* year */
116 | BIN2BCD(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */ 116 | bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */
117 | BIN2BCD(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */ 117 | bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */
118 | BIN2BCD(tm->tm_mday) << 24); 118 | bin2bcd(tm->tm_mday) << 24);
119 119
120 /* Restart Time/Calendar */ 120 /* Restart Time/Calendar */
121 cr = at91_sys_read(AT91_RTC_CR); 121 cr = at91_sys_read(AT91_RTC_CR);
@@ -162,13 +162,13 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
162 162
163 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM); 163 at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
164 at91_sys_write(AT91_RTC_TIMALR, 164 at91_sys_write(AT91_RTC_TIMALR,
165 BIN2BCD(tm.tm_sec) << 0 165 bin2bcd(tm.tm_sec) << 0
166 | BIN2BCD(tm.tm_min) << 8 166 | bin2bcd(tm.tm_min) << 8
167 | BIN2BCD(tm.tm_hour) << 16 167 | bin2bcd(tm.tm_hour) << 16
168 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN); 168 | AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);
169 at91_sys_write(AT91_RTC_CALALR, 169 at91_sys_write(AT91_RTC_CALALR,
170 BIN2BCD(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */ 170 bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
171 | BIN2BCD(tm.tm_mday) << 24 171 | bin2bcd(tm.tm_mday) << 24
172 | AT91_RTC_DATEEN | AT91_RTC_MTHEN); 172 | AT91_RTC_DATEEN | AT91_RTC_MTHEN);
173 173
174 if (alrm->enabled) { 174 if (alrm->enabled) {
@@ -228,8 +228,6 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
228 (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); 228 (imr & AT91_RTC_ACKUPD) ? "yes" : "no");
229 seq_printf(seq, "periodic_IRQ\t: %s\n", 229 seq_printf(seq, "periodic_IRQ\t: %s\n",
230 (imr & AT91_RTC_SECEV) ? "yes" : "no"); 230 (imr & AT91_RTC_SECEV) ? "yes" : "no");
231 seq_printf(seq, "periodic_freq\t: %ld\n",
232 (unsigned long) AT91_RTC_FREQ);
233 231
234 return 0; 232 return 0;
235} 233}
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index 189a018bdf34..d00a274df8fc 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -71,14 +71,14 @@ static int bq4802_read_time(struct device *dev, struct rtc_time *tm)
71 71
72 spin_unlock_irqrestore(&p->lock, flags); 72 spin_unlock_irqrestore(&p->lock, flags);
73 73
74 BCD_TO_BIN(tm->tm_sec); 74 tm->tm_sec = bcd2bin(tm->tm_sec);
75 BCD_TO_BIN(tm->tm_min); 75 tm->tm_min = bcd2bin(tm->tm_min);
76 BCD_TO_BIN(tm->tm_hour); 76 tm->tm_hour = bcd2bin(tm->tm_hour);
77 BCD_TO_BIN(tm->tm_mday); 77 tm->tm_mday = bcd2bin(tm->tm_mday);
78 BCD_TO_BIN(tm->tm_mon); 78 tm->tm_mon = bcd2bin(tm->tm_mon);
79 BCD_TO_BIN(tm->tm_year); 79 tm->tm_year = bcd2bin(tm->tm_year);
80 BCD_TO_BIN(tm->tm_wday); 80 tm->tm_wday = bcd2bin(tm->tm_wday);
81 BCD_TO_BIN(century); 81 century = bcd2bin(century);
82 82
83 tm->tm_year += (century * 100); 83 tm->tm_year += (century * 100);
84 tm->tm_year -= 1900; 84 tm->tm_year -= 1900;
@@ -106,13 +106,13 @@ static int bq4802_set_time(struct device *dev, struct rtc_time *tm)
106 min = tm->tm_min; 106 min = tm->tm_min;
107 sec = tm->tm_sec; 107 sec = tm->tm_sec;
108 108
109 BIN_TO_BCD(sec); 109 sec = bin2bcd(sec);
110 BIN_TO_BCD(min); 110 min = bin2bcd(min);
111 BIN_TO_BCD(hrs); 111 hrs = bin2bcd(hrs);
112 BIN_TO_BCD(day); 112 day = bin2bcd(day);
113 BIN_TO_BCD(mon); 113 mon = bin2bcd(mon);
114 BIN_TO_BCD(yrs); 114 yrs = bin2bcd(yrs);
115 BIN_TO_BCD(century); 115 century = bin2bcd(century);
116 116
117 spin_lock_irqsave(&p->lock, flags); 117 spin_lock_irqsave(&p->lock, flags);
118 118
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 963ad0b6a4e9..5549231179a2 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -143,6 +143,43 @@ static inline int hpet_unregister_irq_handler(irq_handler_t handler)
143 143
144/*----------------------------------------------------------------*/ 144/*----------------------------------------------------------------*/
145 145
146#ifdef RTC_PORT
147
148/* Most newer x86 systems have two register banks, the first used
149 * for RTC and NVRAM and the second only for NVRAM. Caller must
150 * own rtc_lock ... and we won't worry about access during NMI.
151 */
152#define can_bank2 true
153
154static inline unsigned char cmos_read_bank2(unsigned char addr)
155{
156 outb(addr, RTC_PORT(2));
157 return inb(RTC_PORT(3));
158}
159
160static inline void cmos_write_bank2(unsigned char val, unsigned char addr)
161{
162 outb(addr, RTC_PORT(2));
163 outb(val, RTC_PORT(2));
164}
165
166#else
167
168#define can_bank2 false
169
170static inline unsigned char cmos_read_bank2(unsigned char addr)
171{
172 return 0;
173}
174
175static inline void cmos_write_bank2(unsigned char val, unsigned char addr)
176{
177}
178
179#endif
180
181/*----------------------------------------------------------------*/
182
146static int cmos_read_time(struct device *dev, struct rtc_time *t) 183static int cmos_read_time(struct device *dev, struct rtc_time *t)
147{ 184{
148 /* REVISIT: if the clock has a "century" register, use 185 /* REVISIT: if the clock has a "century" register, use
@@ -203,26 +240,26 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
203 /* REVISIT this assumes PC style usage: always BCD */ 240 /* REVISIT this assumes PC style usage: always BCD */
204 241
205 if (((unsigned)t->time.tm_sec) < 0x60) 242 if (((unsigned)t->time.tm_sec) < 0x60)
206 t->time.tm_sec = BCD2BIN(t->time.tm_sec); 243 t->time.tm_sec = bcd2bin(t->time.tm_sec);
207 else 244 else
208 t->time.tm_sec = -1; 245 t->time.tm_sec = -1;
209 if (((unsigned)t->time.tm_min) < 0x60) 246 if (((unsigned)t->time.tm_min) < 0x60)
210 t->time.tm_min = BCD2BIN(t->time.tm_min); 247 t->time.tm_min = bcd2bin(t->time.tm_min);
211 else 248 else
212 t->time.tm_min = -1; 249 t->time.tm_min = -1;
213 if (((unsigned)t->time.tm_hour) < 0x24) 250 if (((unsigned)t->time.tm_hour) < 0x24)
214 t->time.tm_hour = BCD2BIN(t->time.tm_hour); 251 t->time.tm_hour = bcd2bin(t->time.tm_hour);
215 else 252 else
216 t->time.tm_hour = -1; 253 t->time.tm_hour = -1;
217 254
218 if (cmos->day_alrm) { 255 if (cmos->day_alrm) {
219 if (((unsigned)t->time.tm_mday) <= 0x31) 256 if (((unsigned)t->time.tm_mday) <= 0x31)
220 t->time.tm_mday = BCD2BIN(t->time.tm_mday); 257 t->time.tm_mday = bcd2bin(t->time.tm_mday);
221 else 258 else
222 t->time.tm_mday = -1; 259 t->time.tm_mday = -1;
223 if (cmos->mon_alrm) { 260 if (cmos->mon_alrm) {
224 if (((unsigned)t->time.tm_mon) <= 0x12) 261 if (((unsigned)t->time.tm_mon) <= 0x12)
225 t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1; 262 t->time.tm_mon = bcd2bin(t->time.tm_mon) - 1;
226 else 263 else
227 t->time.tm_mon = -1; 264 t->time.tm_mon = -1;
228 } 265 }
@@ -294,19 +331,19 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
294 /* Writing 0xff means "don't care" or "match all". */ 331 /* Writing 0xff means "don't care" or "match all". */
295 332
296 mon = t->time.tm_mon + 1; 333 mon = t->time.tm_mon + 1;
297 mon = (mon <= 12) ? BIN2BCD(mon) : 0xff; 334 mon = (mon <= 12) ? bin2bcd(mon) : 0xff;
298 335
299 mday = t->time.tm_mday; 336 mday = t->time.tm_mday;
300 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; 337 mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
301 338
302 hrs = t->time.tm_hour; 339 hrs = t->time.tm_hour;
303 hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff; 340 hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff;
304 341
305 min = t->time.tm_min; 342 min = t->time.tm_min;
306 min = (min < 60) ? BIN2BCD(min) : 0xff; 343 min = (min < 60) ? bin2bcd(min) : 0xff;
307 344
308 sec = t->time.tm_sec; 345 sec = t->time.tm_sec;
309 sec = (sec < 60) ? BIN2BCD(sec) : 0xff; 346 sec = (sec < 60) ? bin2bcd(sec) : 0xff;
310 347
311 spin_lock_irq(&rtc_lock); 348 spin_lock_irq(&rtc_lock);
312 349
@@ -491,12 +528,21 @@ cmos_nvram_read(struct kobject *kobj, struct bin_attribute *attr,
491 528
492 if (unlikely(off >= attr->size)) 529 if (unlikely(off >= attr->size))
493 return 0; 530 return 0;
531 if (unlikely(off < 0))
532 return -EINVAL;
494 if ((off + count) > attr->size) 533 if ((off + count) > attr->size)
495 count = attr->size - off; 534 count = attr->size - off;
496 535
536 off += NVRAM_OFFSET;
497 spin_lock_irq(&rtc_lock); 537 spin_lock_irq(&rtc_lock);
498 for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) 538 for (retval = 0; count; count--, off++, retval++) {
499 *buf++ = CMOS_READ(off); 539 if (off < 128)
540 *buf++ = CMOS_READ(off);
541 else if (can_bank2)
542 *buf++ = cmos_read_bank2(off);
543 else
544 break;
545 }
500 spin_unlock_irq(&rtc_lock); 546 spin_unlock_irq(&rtc_lock);
501 547
502 return retval; 548 return retval;
@@ -512,6 +558,8 @@ cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
512 cmos = dev_get_drvdata(container_of(kobj, struct device, kobj)); 558 cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
513 if (unlikely(off >= attr->size)) 559 if (unlikely(off >= attr->size))
514 return -EFBIG; 560 return -EFBIG;
561 if (unlikely(off < 0))
562 return -EINVAL;
515 if ((off + count) > attr->size) 563 if ((off + count) > attr->size)
516 count = attr->size - off; 564 count = attr->size - off;
517 565
@@ -520,15 +568,20 @@ cmos_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
520 * here. If userspace is smart enough to know what fields of 568 * here. If userspace is smart enough to know what fields of
521 * NVRAM to update, updating checksums is also part of its job. 569 * NVRAM to update, updating checksums is also part of its job.
522 */ 570 */
571 off += NVRAM_OFFSET;
523 spin_lock_irq(&rtc_lock); 572 spin_lock_irq(&rtc_lock);
524 for (retval = 0, off += NVRAM_OFFSET; count--; retval++, off++) { 573 for (retval = 0; count; count--, off++, retval++) {
525 /* don't trash RTC registers */ 574 /* don't trash RTC registers */
526 if (off == cmos->day_alrm 575 if (off == cmos->day_alrm
527 || off == cmos->mon_alrm 576 || off == cmos->mon_alrm
528 || off == cmos->century) 577 || off == cmos->century)
529 buf++; 578 buf++;
530 else 579 else if (off < 128)
531 CMOS_WRITE(*buf++, off); 580 CMOS_WRITE(*buf++, off);
581 else if (can_bank2)
582 cmos_write_bank2(*buf++, off);
583 else
584 break;
532 } 585 }
533 spin_unlock_irq(&rtc_lock); 586 spin_unlock_irq(&rtc_lock);
534 587
@@ -539,7 +592,6 @@ static struct bin_attribute nvram = {
539 .attr = { 592 .attr = {
540 .name = "nvram", 593 .name = "nvram",
541 .mode = S_IRUGO | S_IWUSR, 594 .mode = S_IRUGO | S_IWUSR,
542 .owner = THIS_MODULE,
543 }, 595 },
544 596
545 .read = cmos_nvram_read, 597 .read = cmos_nvram_read,
@@ -631,8 +683,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
631 683
632 /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM 684 /* Heuristic to deduce NVRAM size ... do what the legacy NVRAM
633 * driver did, but don't reject unknown configs. Old hardware 685 * driver did, but don't reject unknown configs. Old hardware
634 * won't address 128 bytes, and for now we ignore the way newer 686 * won't address 128 bytes. Newer chips have multiple banks,
635 * chips can address 256 bytes (using two more i/o ports). 687 * though they may not be listed in one I/O resource.
636 */ 688 */
637#if defined(CONFIG_ATARI) 689#if defined(CONFIG_ATARI)
638 address_space = 64; 690 address_space = 64;
@@ -642,6 +694,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
642#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes. 694#warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
643 address_space = 128; 695 address_space = 128;
644#endif 696#endif
697 if (can_bank2 && ports->end > (ports->start + 1))
698 address_space = 256;
645 699
646 /* For ACPI systems extension info comes from the FADT. On others, 700 /* For ACPI systems extension info comes from the FADT. On others,
647 * board specific setup provides it as appropriate. Systems where 701 * board specific setup provides it as appropriate. Systems where
@@ -740,7 +794,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
740 goto cleanup2; 794 goto cleanup2;
741 } 795 }
742 796
743 pr_info("%s: alarms up to one %s%s%s\n", 797 pr_info("%s: alarms up to one %s%s, %zd bytes nvram, %s irqs\n",
744 cmos_rtc.rtc->dev.bus_id, 798 cmos_rtc.rtc->dev.bus_id,
745 is_valid_irq(rtc_irq) 799 is_valid_irq(rtc_irq)
746 ? (cmos_rtc.mon_alrm 800 ? (cmos_rtc.mon_alrm
@@ -749,6 +803,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
749 ? "month" : "day")) 803 ? "month" : "day"))
750 : "no", 804 : "no",
751 cmos_rtc.century ? ", y3k" : "", 805 cmos_rtc.century ? ", y3k" : "",
806 nvram.size,
752 is_hpet_enabled() ? ", hpet irqs" : ""); 807 is_hpet_enabled() ? ", hpet irqs" : "");
753 808
754 return 0; 809 return 0;
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 52e2743b04ec..079e9ed907e0 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -432,9 +432,15 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
432{ 432{
433 struct rtc_device *rtc = file->private_data; 433 struct rtc_device *rtc = file->private_data;
434 434
435#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 435 /* We shut down the repeating IRQs that userspace enabled,
436 clear_uie(rtc); 436 * since nothing is listening to them.
437#endif 437 * - Update (UIE) ... currently only managed through ioctls
438 * - Periodic (PIE) ... also used through rtc_*() interface calls
439 *
440 * Leave the alarm alone; it may be set to trigger a system wakeup
441 * later, or be used by kernel code, and is a one-shot event anyway.
442 */
443 rtc_dev_ioctl(file, RTC_UIE_OFF, 0);
438 rtc_irq_set_state(rtc, NULL, 0); 444 rtc_irq_set_state(rtc, NULL, 0);
439 445
440 if (rtc->ops->release) 446 if (rtc->ops->release)
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 0b17770b032b..9a234a4ec06d 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -86,19 +86,19 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
86 ds1216_switch_ds_to_clock(priv->ioaddr); 86 ds1216_switch_ds_to_clock(priv->ioaddr);
87 ds1216_read(priv->ioaddr, (u8 *)&regs); 87 ds1216_read(priv->ioaddr, (u8 *)&regs);
88 88
89 tm->tm_sec = BCD2BIN(regs.sec); 89 tm->tm_sec = bcd2bin(regs.sec);
90 tm->tm_min = BCD2BIN(regs.min); 90 tm->tm_min = bcd2bin(regs.min);
91 if (regs.hour & DS1216_HOUR_1224) { 91 if (regs.hour & DS1216_HOUR_1224) {
92 /* AM/PM mode */ 92 /* AM/PM mode */
93 tm->tm_hour = BCD2BIN(regs.hour & 0x1f); 93 tm->tm_hour = bcd2bin(regs.hour & 0x1f);
94 if (regs.hour & DS1216_HOUR_AMPM) 94 if (regs.hour & DS1216_HOUR_AMPM)
95 tm->tm_hour += 12; 95 tm->tm_hour += 12;
96 } else 96 } else
97 tm->tm_hour = BCD2BIN(regs.hour & 0x3f); 97 tm->tm_hour = bcd2bin(regs.hour & 0x3f);
98 tm->tm_wday = (regs.wday & 7) - 1; 98 tm->tm_wday = (regs.wday & 7) - 1;
99 tm->tm_mday = BCD2BIN(regs.mday & 0x3f); 99 tm->tm_mday = bcd2bin(regs.mday & 0x3f);
100 tm->tm_mon = BCD2BIN(regs.month & 0x1f); 100 tm->tm_mon = bcd2bin(regs.month & 0x1f);
101 tm->tm_year = BCD2BIN(regs.year); 101 tm->tm_year = bcd2bin(regs.year);
102 if (tm->tm_year < 70) 102 if (tm->tm_year < 70)
103 tm->tm_year += 100; 103 tm->tm_year += 100;
104 return 0; 104 return 0;
@@ -114,19 +114,19 @@ static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
114 ds1216_read(priv->ioaddr, (u8 *)&regs); 114 ds1216_read(priv->ioaddr, (u8 *)&regs);
115 115
116 regs.tsec = 0; /* clear 0.1 and 0.01 seconds */ 116 regs.tsec = 0; /* clear 0.1 and 0.01 seconds */
117 regs.sec = BIN2BCD(tm->tm_sec); 117 regs.sec = bin2bcd(tm->tm_sec);
118 regs.min = BIN2BCD(tm->tm_min); 118 regs.min = bin2bcd(tm->tm_min);
119 regs.hour &= DS1216_HOUR_1224; 119 regs.hour &= DS1216_HOUR_1224;
120 if (regs.hour && tm->tm_hour > 12) { 120 if (regs.hour && tm->tm_hour > 12) {
121 regs.hour |= DS1216_HOUR_AMPM; 121 regs.hour |= DS1216_HOUR_AMPM;
122 tm->tm_hour -= 12; 122 tm->tm_hour -= 12;
123 } 123 }
124 regs.hour |= BIN2BCD(tm->tm_hour); 124 regs.hour |= bin2bcd(tm->tm_hour);
125 regs.wday &= ~7; 125 regs.wday &= ~7;
126 regs.wday |= tm->tm_wday; 126 regs.wday |= tm->tm_wday;
127 regs.mday = BIN2BCD(tm->tm_mday); 127 regs.mday = bin2bcd(tm->tm_mday);
128 regs.month = BIN2BCD(tm->tm_mon); 128 regs.month = bin2bcd(tm->tm_mon);
129 regs.year = BIN2BCD(tm->tm_year % 100); 129 regs.year = bin2bcd(tm->tm_year % 100);
130 130
131 ds1216_switch_ds_to_clock(priv->ioaddr); 131 ds1216_switch_ds_to_clock(priv->ioaddr);
132 ds1216_write(priv->ioaddr, (u8 *)&regs); 132 ds1216_write(priv->ioaddr, (u8 *)&regs);
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
new file mode 100644
index 000000000000..4fcb16bbff4a
--- /dev/null
+++ b/drivers/rtc/rtc-ds1286.c
@@ -0,0 +1,410 @@
1/*
2 * DS1286 Real Time Clock interface for Linux
3 *
4 * Copyright (C) 1998, 1999, 2000 Ralf Baechle
5 * Copyright (C) 2008 Thomas Bogendoerfer
6 *
7 * Based on code written by Paul Gortmaker.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/module.h>
16#include <linux/rtc.h>
17#include <linux/platform_device.h>
18#include <linux/bcd.h>
19#include <linux/ds1286.h>
20#include <linux/io.h>
21
22#define DRV_VERSION "1.0"
23
24struct ds1286_priv {
25 struct rtc_device *rtc;
26 u32 __iomem *rtcregs;
27 size_t size;
28 unsigned long baseaddr;
29 spinlock_t lock;
30};
31
32static inline u8 ds1286_rtc_read(struct ds1286_priv *priv, int reg)
33{
34 return __raw_readl(&priv->rtcregs[reg]) & 0xff;
35}
36
37static inline void ds1286_rtc_write(struct ds1286_priv *priv, u8 data, int reg)
38{
39 __raw_writel(data, &priv->rtcregs[reg]);
40}
41
42#ifdef CONFIG_RTC_INTF_DEV
43
44static int ds1286_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
45{
46 struct ds1286_priv *priv = dev_get_drvdata(dev);
47 unsigned long flags;
48 unsigned char val;
49
50 switch (cmd) {
51 case RTC_AIE_OFF:
52 /* Mask alarm int. enab. bit */
53 spin_lock_irqsave(&priv->lock, flags);
54 val = ds1286_rtc_read(priv, RTC_CMD);
55 val |= RTC_TDM;
56 ds1286_rtc_write(priv, val, RTC_CMD);
57 spin_unlock_irqrestore(&priv->lock, flags);
58 break;
59 case RTC_AIE_ON:
60 /* Allow alarm interrupts. */
61 spin_lock_irqsave(&priv->lock, flags);
62 val = ds1286_rtc_read(priv, RTC_CMD);
63 val &= ~RTC_TDM;
64 ds1286_rtc_write(priv, val, RTC_CMD);
65 spin_unlock_irqrestore(&priv->lock, flags);
66 break;
67 case RTC_WIE_OFF:
68 /* Mask watchdog int. enab. bit */
69 spin_lock_irqsave(&priv->lock, flags);
70 val = ds1286_rtc_read(priv, RTC_CMD);
71 val |= RTC_WAM;
72 ds1286_rtc_write(priv, val, RTC_CMD);
73 spin_unlock_irqrestore(&priv->lock, flags);
74 break;
75 case RTC_WIE_ON:
76 /* Allow watchdog interrupts. */
77 spin_lock_irqsave(&priv->lock, flags);
78 val = ds1286_rtc_read(priv, RTC_CMD);
79 val &= ~RTC_WAM;
80 ds1286_rtc_write(priv, val, RTC_CMD);
81 spin_unlock_irqrestore(&priv->lock, flags);
82 break;
83 default:
84 return -ENOIOCTLCMD;
85 }
86 return 0;
87}
88
89#else
90#define ds1286_ioctl NULL
91#endif
92
93#ifdef CONFIG_PROC_FS
94
95static int ds1286_proc(struct device *dev, struct seq_file *seq)
96{
97 struct ds1286_priv *priv = dev_get_drvdata(dev);
98 unsigned char month, cmd, amode;
99 const char *s;
100
101 month = ds1286_rtc_read(priv, RTC_MONTH);
102 seq_printf(seq,
103 "oscillator\t: %s\n"
104 "square_wave\t: %s\n",
105 (month & RTC_EOSC) ? "disabled" : "enabled",
106 (month & RTC_ESQW) ? "disabled" : "enabled");
107
108 amode = ((ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x80) >> 5) |
109 ((ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x80) >> 6) |
110 ((ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x80) >> 7);
111 switch (amode) {
112 case 7:
113 s = "each minute";
114 break;
115 case 3:
116 s = "minutes match";
117 break;
118 case 1:
119 s = "hours and minutes match";
120 break;
121 case 0:
122 s = "days, hours and minutes match";
123 break;
124 default:
125 s = "invalid";
126 break;
127 }
128 seq_printf(seq, "alarm_mode\t: %s\n", s);
129
130 cmd = ds1286_rtc_read(priv, RTC_CMD);
131 seq_printf(seq,
132 "alarm_enable\t: %s\n"
133 "wdog_alarm\t: %s\n"
134 "alarm_mask\t: %s\n"
135 "wdog_alarm_mask\t: %s\n"
136 "interrupt_mode\t: %s\n"
137 "INTB_mode\t: %s_active\n"
138 "interrupt_pins\t: %s\n",
139 (cmd & RTC_TDF) ? "yes" : "no",
140 (cmd & RTC_WAF) ? "yes" : "no",
141 (cmd & RTC_TDM) ? "disabled" : "enabled",
142 (cmd & RTC_WAM) ? "disabled" : "enabled",
143 (cmd & RTC_PU_LVL) ? "pulse" : "level",
144 (cmd & RTC_IBH_LO) ? "low" : "high",
145 (cmd & RTC_IPSW) ? "unswapped" : "swapped");
146 return 0;
147}
148
149#else
150#define ds1286_proc NULL
151#endif
152
153static int ds1286_read_time(struct device *dev, struct rtc_time *tm)
154{
155 struct ds1286_priv *priv = dev_get_drvdata(dev);
156 unsigned char save_control;
157 unsigned long flags;
158 unsigned long uip_watchdog = jiffies;
159
160 /*
161 * read RTC once any update in progress is done. The update
162 * can take just over 2ms. We wait 10 to 20ms. There is no need to
163 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
164 * If you need to know *exactly* when a second has started, enable
165 * periodic update complete interrupts, (via ioctl) and then
166 * immediately read /dev/rtc which will block until you get the IRQ.
167 * Once the read clears, read the RTC time (again via ioctl). Easy.
168 */
169
170 if (ds1286_rtc_read(priv, RTC_CMD) & RTC_TE)
171 while (time_before(jiffies, uip_watchdog + 2*HZ/100))
172 barrier();
173
174 /*
175 * Only the values that we read from the RTC are set. We leave
176 * tm_wday, tm_yday and tm_isdst untouched. Even though the
177 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
178 * by the RTC when initially set to a non-zero value.
179 */
180 spin_lock_irqsave(&priv->lock, flags);
181 save_control = ds1286_rtc_read(priv, RTC_CMD);
182 ds1286_rtc_write(priv, (save_control|RTC_TE), RTC_CMD);
183
184 tm->tm_sec = ds1286_rtc_read(priv, RTC_SECONDS);
185 tm->tm_min = ds1286_rtc_read(priv, RTC_MINUTES);
186 tm->tm_hour = ds1286_rtc_read(priv, RTC_HOURS) & 0x3f;
187 tm->tm_mday = ds1286_rtc_read(priv, RTC_DATE);
188 tm->tm_mon = ds1286_rtc_read(priv, RTC_MONTH) & 0x1f;
189 tm->tm_year = ds1286_rtc_read(priv, RTC_YEAR);
190
191 ds1286_rtc_write(priv, save_control, RTC_CMD);
192 spin_unlock_irqrestore(&priv->lock, flags);
193
194 tm->tm_sec = bcd2bin(tm->tm_sec);
195 tm->tm_min = bcd2bin(tm->tm_min);
196 tm->tm_hour = bcd2bin(tm->tm_hour);
197 tm->tm_mday = bcd2bin(tm->tm_mday);
198 tm->tm_mon = bcd2bin(tm->tm_mon);
199 tm->tm_year = bcd2bin(tm->tm_year);
200
201 /*
202 * Account for differences between how the RTC uses the values
203 * and how they are defined in a struct rtc_time;
204 */
205 if (tm->tm_year < 45)
206 tm->tm_year += 30;
207 tm->tm_year += 40;
208 if (tm->tm_year < 70)
209 tm->tm_year += 100;
210
211 tm->tm_mon--;
212
213 return rtc_valid_tm(tm);
214}
215
216static int ds1286_set_time(struct device *dev, struct rtc_time *tm)
217{
218 struct ds1286_priv *priv = dev_get_drvdata(dev);
219 unsigned char mon, day, hrs, min, sec;
220 unsigned char save_control;
221 unsigned int yrs;
222 unsigned long flags;
223
224 yrs = tm->tm_year + 1900;
225 mon = tm->tm_mon + 1; /* tm_mon starts at zero */
226 day = tm->tm_mday;
227 hrs = tm->tm_hour;
228 min = tm->tm_min;
229 sec = tm->tm_sec;
230
231 if (yrs < 1970)
232 return -EINVAL;
233
234 yrs -= 1940;
235 if (yrs > 255) /* They are unsigned */
236 return -EINVAL;
237
238 if (yrs >= 100)
239 yrs -= 100;
240
241 sec = bin2bcd(sec);
242 min = bin2bcd(min);
243 hrs = bin2bcd(hrs);
244 day = bin2bcd(day);
245 mon = bin2bcd(mon);
246 yrs = bin2bcd(yrs);
247
248 spin_lock_irqsave(&priv->lock, flags);
249 save_control = ds1286_rtc_read(priv, RTC_CMD);
250 ds1286_rtc_write(priv, (save_control|RTC_TE), RTC_CMD);
251
252 ds1286_rtc_write(priv, yrs, RTC_YEAR);
253 ds1286_rtc_write(priv, mon, RTC_MONTH);
254 ds1286_rtc_write(priv, day, RTC_DATE);
255 ds1286_rtc_write(priv, hrs, RTC_HOURS);
256 ds1286_rtc_write(priv, min, RTC_MINUTES);
257 ds1286_rtc_write(priv, sec, RTC_SECONDS);
258 ds1286_rtc_write(priv, 0, RTC_HUNDREDTH_SECOND);
259
260 ds1286_rtc_write(priv, save_control, RTC_CMD);
261 spin_unlock_irqrestore(&priv->lock, flags);
262 return 0;
263}
264
265static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
266{
267 struct ds1286_priv *priv = dev_get_drvdata(dev);
268 unsigned char cmd;
269 unsigned long flags;
270
271 /*
272 * Only the values that we read from the RTC are set. That
273 * means only tm_wday, tm_hour, tm_min.
274 */
275 spin_lock_irqsave(&priv->lock, flags);
276 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f;
277 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f;
278 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07;
279 cmd = ds1286_rtc_read(priv, RTC_CMD);
280 spin_unlock_irqrestore(&priv->lock, flags);
281
282 alm->time.tm_min = bcd2bin(alm->time.tm_min);
283 alm->time.tm_hour = bcd2bin(alm->time.tm_hour);
284 alm->time.tm_sec = 0;
285 return 0;
286}
287
288static int ds1286_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
289{
290 struct ds1286_priv *priv = dev_get_drvdata(dev);
291 unsigned char hrs, min, sec;
292
293 hrs = alm->time.tm_hour;
294 min = alm->time.tm_min;
295 sec = alm->time.tm_sec;
296
297 if (hrs >= 24)
298 hrs = 0xff;
299
300 if (min >= 60)
301 min = 0xff;
302
303 if (sec != 0)
304 return -EINVAL;
305
306 min = bin2bcd(min);
307 hrs = bin2bcd(hrs);
308
309 spin_lock(&priv->lock);
310 ds1286_rtc_write(priv, hrs, RTC_HOURS_ALARM);
311 ds1286_rtc_write(priv, min, RTC_MINUTES_ALARM);
312 spin_unlock(&priv->lock);
313
314 return 0;
315}
316
317static const struct rtc_class_ops ds1286_ops = {
318 .ioctl = ds1286_ioctl,
319 .proc = ds1286_proc,
320 .read_time = ds1286_read_time,
321 .set_time = ds1286_set_time,
322 .read_alarm = ds1286_read_alarm,
323 .set_alarm = ds1286_set_alarm,
324};
325
326static int __devinit ds1286_probe(struct platform_device *pdev)
327{
328 struct rtc_device *rtc;
329 struct resource *res;
330 struct ds1286_priv *priv;
331 int ret = 0;
332
333 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
334 if (!res)
335 return -ENODEV;
336 priv = kzalloc(sizeof(struct ds1286_priv), GFP_KERNEL);
337 if (!priv)
338 return -ENOMEM;
339
340 priv->size = res->end - res->start + 1;
341 if (!request_mem_region(res->start, priv->size, pdev->name)) {
342 ret = -EBUSY;
343 goto out;
344 }
345 priv->baseaddr = res->start;
346 priv->rtcregs = ioremap(priv->baseaddr, priv->size);
347 if (!priv->rtcregs) {
348 ret = -ENOMEM;
349 goto out;
350 }
351 spin_lock_init(&priv->lock);
352 rtc = rtc_device_register("ds1286", &pdev->dev,
353 &ds1286_ops, THIS_MODULE);
354 if (IS_ERR(rtc)) {
355 ret = PTR_ERR(rtc);
356 goto out;
357 }
358 priv->rtc = rtc;
359 platform_set_drvdata(pdev, priv);
360 return 0;
361
362out:
363 if (priv->rtc)
364 rtc_device_unregister(priv->rtc);
365 if (priv->rtcregs)
366 iounmap(priv->rtcregs);
367 if (priv->baseaddr)
368 release_mem_region(priv->baseaddr, priv->size);
369 kfree(priv);
370 return ret;
371}
372
373static int __devexit ds1286_remove(struct platform_device *pdev)
374{
375 struct ds1286_priv *priv = platform_get_drvdata(pdev);
376
377 rtc_device_unregister(priv->rtc);
378 iounmap(priv->rtcregs);
379 release_mem_region(priv->baseaddr, priv->size);
380 kfree(priv);
381 return 0;
382}
383
384static struct platform_driver ds1286_platform_driver = {
385 .driver = {
386 .name = "rtc-ds1286",
387 .owner = THIS_MODULE,
388 },
389 .probe = ds1286_probe,
390 .remove = __devexit_p(ds1286_remove),
391};
392
393static int __init ds1286_init(void)
394{
395 return platform_driver_register(&ds1286_platform_driver);
396}
397
398static void __exit ds1286_exit(void)
399{
400 platform_driver_unregister(&ds1286_platform_driver);
401}
402
403MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
404MODULE_DESCRIPTION("DS1286 RTC driver");
405MODULE_LICENSE("GPL");
406MODULE_VERSION(DRV_VERSION);
407MODULE_ALIAS("platform:rtc-ds1286");
408
409module_init(ds1286_init);
410module_exit(ds1286_exit);
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index b9397818f73a..184556620778 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -40,7 +40,7 @@
40#define RTC_SCLK 0x0400 40#define RTC_SCLK 0x0400
41 41
42#ifdef CONFIG_SH_SECUREEDGE5410 42#ifdef CONFIG_SH_SECUREEDGE5410
43#include <asm/snapgear.h> 43#include <mach/snapgear.h>
44#define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00) 44#define set_dp(x) SECUREEDGE_WRITE_IOPORT(x, 0x1c00)
45#define get_dp() SECUREEDGE_READ_IOPORT() 45#define get_dp() SECUREEDGE_READ_IOPORT()
46#else 46#else
@@ -107,13 +107,13 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
107 107
108 spin_lock_irq(&rtc->lock); 108 spin_lock_irq(&rtc->lock);
109 109
110 tm->tm_sec = BCD2BIN(ds1302_readbyte(RTC_ADDR_SEC)); 110 tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC));
111 tm->tm_min = BCD2BIN(ds1302_readbyte(RTC_ADDR_MIN)); 111 tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN));
112 tm->tm_hour = BCD2BIN(ds1302_readbyte(RTC_ADDR_HOUR)); 112 tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR));
113 tm->tm_wday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DAY)); 113 tm->tm_wday = bcd2bin(ds1302_readbyte(RTC_ADDR_DAY));
114 tm->tm_mday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DATE)); 114 tm->tm_mday = bcd2bin(ds1302_readbyte(RTC_ADDR_DATE));
115 tm->tm_mon = BCD2BIN(ds1302_readbyte(RTC_ADDR_MON)) - 1; 115 tm->tm_mon = bcd2bin(ds1302_readbyte(RTC_ADDR_MON)) - 1;
116 tm->tm_year = BCD2BIN(ds1302_readbyte(RTC_ADDR_YEAR)); 116 tm->tm_year = bcd2bin(ds1302_readbyte(RTC_ADDR_YEAR));
117 117
118 if (tm->tm_year < 70) 118 if (tm->tm_year < 70)
119 tm->tm_year += 100; 119 tm->tm_year += 100;
@@ -141,13 +141,13 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
141 /* Stop RTC */ 141 /* Stop RTC */
142 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); 142 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
143 143
144 ds1302_writebyte(RTC_ADDR_SEC, BIN2BCD(tm->tm_sec)); 144 ds1302_writebyte(RTC_ADDR_SEC, bin2bcd(tm->tm_sec));
145 ds1302_writebyte(RTC_ADDR_MIN, BIN2BCD(tm->tm_min)); 145 ds1302_writebyte(RTC_ADDR_MIN, bin2bcd(tm->tm_min));
146 ds1302_writebyte(RTC_ADDR_HOUR, BIN2BCD(tm->tm_hour)); 146 ds1302_writebyte(RTC_ADDR_HOUR, bin2bcd(tm->tm_hour));
147 ds1302_writebyte(RTC_ADDR_DAY, BIN2BCD(tm->tm_wday)); 147 ds1302_writebyte(RTC_ADDR_DAY, bin2bcd(tm->tm_wday));
148 ds1302_writebyte(RTC_ADDR_DATE, BIN2BCD(tm->tm_mday)); 148 ds1302_writebyte(RTC_ADDR_DATE, bin2bcd(tm->tm_mday));
149 ds1302_writebyte(RTC_ADDR_MON, BIN2BCD(tm->tm_mon + 1)); 149 ds1302_writebyte(RTC_ADDR_MON, bin2bcd(tm->tm_mon + 1));
150 ds1302_writebyte(RTC_ADDR_YEAR, BIN2BCD(tm->tm_year % 100)); 150 ds1302_writebyte(RTC_ADDR_YEAR, bin2bcd(tm->tm_year % 100));
151 151
152 /* Start RTC */ 152 /* Start RTC */
153 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); 153 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index b91d02a3ace9..fc372df6534b 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -114,10 +114,10 @@ static unsigned bcd2hour(u8 bcd)
114 hour = 12; 114 hour = 12;
115 bcd &= ~DS1305_HR_PM; 115 bcd &= ~DS1305_HR_PM;
116 } 116 }
117 hour += BCD2BIN(bcd); 117 hour += bcd2bin(bcd);
118 return hour - 1; 118 return hour - 1;
119 } 119 }
120 return BCD2BIN(bcd); 120 return bcd2bin(bcd);
121} 121}
122 122
123static u8 hour2bcd(bool hr12, int hour) 123static u8 hour2bcd(bool hr12, int hour)
@@ -125,11 +125,11 @@ static u8 hour2bcd(bool hr12, int hour)
125 if (hr12) { 125 if (hr12) {
126 hour++; 126 hour++;
127 if (hour <= 12) 127 if (hour <= 12)
128 return DS1305_HR_12 | BIN2BCD(hour); 128 return DS1305_HR_12 | bin2bcd(hour);
129 hour -= 12; 129 hour -= 12;
130 return DS1305_HR_12 | DS1305_HR_PM | BIN2BCD(hour); 130 return DS1305_HR_12 | DS1305_HR_PM | bin2bcd(hour);
131 } 131 }
132 return BIN2BCD(hour); 132 return bin2bcd(hour);
133} 133}
134 134
135/*----------------------------------------------------------------------*/ 135/*----------------------------------------------------------------------*/
@@ -206,13 +206,13 @@ static int ds1305_get_time(struct device *dev, struct rtc_time *time)
206 buf[4], buf[5], buf[6]); 206 buf[4], buf[5], buf[6]);
207 207
208 /* Decode the registers */ 208 /* Decode the registers */
209 time->tm_sec = BCD2BIN(buf[DS1305_SEC]); 209 time->tm_sec = bcd2bin(buf[DS1305_SEC]);
210 time->tm_min = BCD2BIN(buf[DS1305_MIN]); 210 time->tm_min = bcd2bin(buf[DS1305_MIN]);
211 time->tm_hour = bcd2hour(buf[DS1305_HOUR]); 211 time->tm_hour = bcd2hour(buf[DS1305_HOUR]);
212 time->tm_wday = buf[DS1305_WDAY] - 1; 212 time->tm_wday = buf[DS1305_WDAY] - 1;
213 time->tm_mday = BCD2BIN(buf[DS1305_MDAY]); 213 time->tm_mday = bcd2bin(buf[DS1305_MDAY]);
214 time->tm_mon = BCD2BIN(buf[DS1305_MON]) - 1; 214 time->tm_mon = bcd2bin(buf[DS1305_MON]) - 1;
215 time->tm_year = BCD2BIN(buf[DS1305_YEAR]) + 100; 215 time->tm_year = bcd2bin(buf[DS1305_YEAR]) + 100;
216 216
217 dev_vdbg(dev, "%s secs=%d, mins=%d, " 217 dev_vdbg(dev, "%s secs=%d, mins=%d, "
218 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 218 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -239,13 +239,13 @@ static int ds1305_set_time(struct device *dev, struct rtc_time *time)
239 /* Write registers starting at the first time/date address. */ 239 /* Write registers starting at the first time/date address. */
240 *bp++ = DS1305_WRITE | DS1305_SEC; 240 *bp++ = DS1305_WRITE | DS1305_SEC;
241 241
242 *bp++ = BIN2BCD(time->tm_sec); 242 *bp++ = bin2bcd(time->tm_sec);
243 *bp++ = BIN2BCD(time->tm_min); 243 *bp++ = bin2bcd(time->tm_min);
244 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour); 244 *bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
245 *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1; 245 *bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1;
246 *bp++ = BIN2BCD(time->tm_mday); 246 *bp++ = bin2bcd(time->tm_mday);
247 *bp++ = BIN2BCD(time->tm_mon + 1); 247 *bp++ = bin2bcd(time->tm_mon + 1);
248 *bp++ = BIN2BCD(time->tm_year - 100); 248 *bp++ = bin2bcd(time->tm_year - 100);
249 249
250 dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n", 250 dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
251 "write", buf[1], buf[2], buf[3], 251 "write", buf[1], buf[2], buf[3],
@@ -329,8 +329,8 @@ static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
329 * fill in the rest ... and also handle rollover to tomorrow when 329 * fill in the rest ... and also handle rollover to tomorrow when
330 * that's needed. 330 * that's needed.
331 */ 331 */
332 alm->time.tm_sec = BCD2BIN(buf[DS1305_SEC]); 332 alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]);
333 alm->time.tm_min = BCD2BIN(buf[DS1305_MIN]); 333 alm->time.tm_min = bcd2bin(buf[DS1305_MIN]);
334 alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]); 334 alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]);
335 alm->time.tm_mday = -1; 335 alm->time.tm_mday = -1;
336 alm->time.tm_mon = -1; 336 alm->time.tm_mon = -1;
@@ -387,8 +387,8 @@ static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
387 387
388 /* write alarm */ 388 /* write alarm */
389 buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC); 389 buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC);
390 buf[1 + DS1305_SEC] = BIN2BCD(alm->time.tm_sec); 390 buf[1 + DS1305_SEC] = bin2bcd(alm->time.tm_sec);
391 buf[1 + DS1305_MIN] = BIN2BCD(alm->time.tm_min); 391 buf[1 + DS1305_MIN] = bin2bcd(alm->time.tm_min);
392 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour); 392 buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
393 buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE; 393 buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE;
394 394
@@ -606,7 +606,6 @@ ds1305_nvram_write(struct kobject *kobj, struct bin_attribute *attr,
606static struct bin_attribute nvram = { 606static struct bin_attribute nvram = {
607 .attr.name = "nvram", 607 .attr.name = "nvram",
608 .attr.mode = S_IRUGO | S_IWUSR, 608 .attr.mode = S_IRUGO | S_IWUSR,
609 .attr.owner = THIS_MODULE,
610 .read = ds1305_nvram_read, 609 .read = ds1305_nvram_read,
611 .write = ds1305_nvram_write, 610 .write = ds1305_nvram_write,
612 .size = DS1305_NVRAM_LEN, 611 .size = DS1305_NVRAM_LEN,
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bbf97e65202a..162330b9d1dc 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -23,10 +23,6 @@
23 * to have set the chip up as a clock (turning on the oscillator and 23 * to have set the chip up as a clock (turning on the oscillator and
24 * setting the date and time), Linux can ignore the non-clock features. 24 * setting the date and time), Linux can ignore the non-clock features.
25 * That's a natural job for a factory or repair bench. 25 * That's a natural job for a factory or repair bench.
26 *
27 * This is currently a simple no-alarms driver. If your board has the
28 * alarm irq wired up on a ds1337 or ds1339, and you want to use that,
29 * then look at the rtc-rs5c372 driver for code to steal...
30 */ 26 */
31enum ds_type { 27enum ds_type {
32 ds_1307, 28 ds_1307,
@@ -67,6 +63,7 @@ enum ds_type {
67# define DS1307_BIT_RS0 0x01 63# define DS1307_BIT_RS0 0x01
68#define DS1337_REG_CONTROL 0x0e 64#define DS1337_REG_CONTROL 0x0e
69# define DS1337_BIT_nEOSC 0x80 65# define DS1337_BIT_nEOSC 0x80
66# define DS1339_BIT_BBSQI 0x20
70# define DS1337_BIT_RS2 0x10 67# define DS1337_BIT_RS2 0x10
71# define DS1337_BIT_RS1 0x08 68# define DS1337_BIT_RS1 0x08
72# define DS1337_BIT_INTCN 0x04 69# define DS1337_BIT_INTCN 0x04
@@ -83,19 +80,22 @@ enum ds_type {
83# define DS1337_BIT_OSF 0x80 80# define DS1337_BIT_OSF 0x80
84# define DS1337_BIT_A2I 0x02 81# define DS1337_BIT_A2I 0x02
85# define DS1337_BIT_A1I 0x01 82# define DS1337_BIT_A1I 0x01
83#define DS1339_REG_ALARM1_SECS 0x07
86#define DS1339_REG_TRICKLE 0x10 84#define DS1339_REG_TRICKLE 0x10
87 85
88 86
89 87
90struct ds1307 { 88struct ds1307 {
91 u8 reg_addr; 89 u8 reg_addr;
92 bool has_nvram; 90 u8 regs[11];
93 u8 regs[8];
94 enum ds_type type; 91 enum ds_type type;
92 unsigned long flags;
93#define HAS_NVRAM 0 /* bit 0 == sysfs file active */
94#define HAS_ALARM 1 /* bit 1 == irq claimed */
95 struct i2c_msg msg[2]; 95 struct i2c_msg msg[2];
96 struct i2c_client *client; 96 struct i2c_client *client;
97 struct i2c_client dev;
98 struct rtc_device *rtc; 97 struct rtc_device *rtc;
98 struct work_struct work;
99}; 99};
100 100
101struct chip_desc { 101struct chip_desc {
@@ -132,12 +132,79 @@ static const struct i2c_device_id ds1307_id[] = {
132}; 132};
133MODULE_DEVICE_TABLE(i2c, ds1307_id); 133MODULE_DEVICE_TABLE(i2c, ds1307_id);
134 134
135/*----------------------------------------------------------------------*/
136
137/*
138 * The IRQ logic includes a "real" handler running in IRQ context just
139 * long enough to schedule this workqueue entry. We need a task context
140 * to talk to the RTC, since I2C I/O calls require that; and disable the
141 * IRQ until we clear its status on the chip, so that this handler can
142 * work with any type of triggering (not just falling edge).
143 *
144 * The ds1337 and ds1339 both have two alarms, but we only use the first
145 * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm
146 * signal; ds1339 chips have only one alarm signal.
147 */
148static void ds1307_work(struct work_struct *work)
149{
150 struct ds1307 *ds1307;
151 struct i2c_client *client;
152 struct mutex *lock;
153 int stat, control;
154
155 ds1307 = container_of(work, struct ds1307, work);
156 client = ds1307->client;
157 lock = &ds1307->rtc->ops_lock;
158
159 mutex_lock(lock);
160 stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
161 if (stat < 0)
162 goto out;
163
164 if (stat & DS1337_BIT_A1I) {
165 stat &= ~DS1337_BIT_A1I;
166 i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, stat);
167
168 control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
169 if (control < 0)
170 goto out;
171
172 control &= ~DS1337_BIT_A1IE;
173 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control);
174
175 /* rtc_update_irq() assumes that it is called
176 * from IRQ-disabled context.
177 */
178 local_irq_disable();
179 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
180 local_irq_enable();
181 }
182
183out:
184 if (test_bit(HAS_ALARM, &ds1307->flags))
185 enable_irq(client->irq);
186 mutex_unlock(lock);
187}
188
189static irqreturn_t ds1307_irq(int irq, void *dev_id)
190{
191 struct i2c_client *client = dev_id;
192 struct ds1307 *ds1307 = i2c_get_clientdata(client);
193
194 disable_irq_nosync(irq);
195 schedule_work(&ds1307->work);
196 return IRQ_HANDLED;
197}
198
199/*----------------------------------------------------------------------*/
200
135static int ds1307_get_time(struct device *dev, struct rtc_time *t) 201static int ds1307_get_time(struct device *dev, struct rtc_time *t)
136{ 202{
137 struct ds1307 *ds1307 = dev_get_drvdata(dev); 203 struct ds1307 *ds1307 = dev_get_drvdata(dev);
138 int tmp; 204 int tmp;
139 205
140 /* read the RTC date and time registers all at once */ 206 /* read the RTC date and time registers all at once */
207 ds1307->reg_addr = 0;
141 ds1307->msg[1].flags = I2C_M_RD; 208 ds1307->msg[1].flags = I2C_M_RD;
142 ds1307->msg[1].len = 7; 209 ds1307->msg[1].len = 7;
143 210
@@ -155,17 +222,17 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
155 ds1307->regs[4], ds1307->regs[5], 222 ds1307->regs[4], ds1307->regs[5],
156 ds1307->regs[6]); 223 ds1307->regs[6]);
157 224
158 t->tm_sec = BCD2BIN(ds1307->regs[DS1307_REG_SECS] & 0x7f); 225 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f);
159 t->tm_min = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); 226 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f);
160 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; 227 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f;
161 t->tm_hour = BCD2BIN(tmp); 228 t->tm_hour = bcd2bin(tmp);
162 t->tm_wday = BCD2BIN(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; 229 t->tm_wday = bcd2bin(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1;
163 t->tm_mday = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); 230 t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
164 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; 231 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f;
165 t->tm_mon = BCD2BIN(tmp) - 1; 232 t->tm_mon = bcd2bin(tmp) - 1;
166 233
167 /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */ 234 /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */
168 t->tm_year = BCD2BIN(ds1307->regs[DS1307_REG_YEAR]) + 100; 235 t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100;
169 236
170 dev_dbg(dev, "%s secs=%d, mins=%d, " 237 dev_dbg(dev, "%s secs=%d, mins=%d, "
171 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 238 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -191,16 +258,16 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
191 t->tm_mon, t->tm_year, t->tm_wday); 258 t->tm_mon, t->tm_year, t->tm_wday);
192 259
193 *buf++ = 0; /* first register addr */ 260 *buf++ = 0; /* first register addr */
194 buf[DS1307_REG_SECS] = BIN2BCD(t->tm_sec); 261 buf[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
195 buf[DS1307_REG_MIN] = BIN2BCD(t->tm_min); 262 buf[DS1307_REG_MIN] = bin2bcd(t->tm_min);
196 buf[DS1307_REG_HOUR] = BIN2BCD(t->tm_hour); 263 buf[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
197 buf[DS1307_REG_WDAY] = BIN2BCD(t->tm_wday + 1); 264 buf[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
198 buf[DS1307_REG_MDAY] = BIN2BCD(t->tm_mday); 265 buf[DS1307_REG_MDAY] = bin2bcd(t->tm_mday);
199 buf[DS1307_REG_MONTH] = BIN2BCD(t->tm_mon + 1); 266 buf[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);
200 267
201 /* assume 20YY not 19YY */ 268 /* assume 20YY not 19YY */
202 tmp = t->tm_year - 100; 269 tmp = t->tm_year - 100;
203 buf[DS1307_REG_YEAR] = BIN2BCD(tmp); 270 buf[DS1307_REG_YEAR] = bin2bcd(tmp);
204 271
205 switch (ds1307->type) { 272 switch (ds1307->type) {
206 case ds_1337: 273 case ds_1337:
@@ -231,9 +298,186 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
231 return 0; 298 return 0;
232} 299}
233 300
301static int ds1307_read_alarm(struct device *dev, struct rtc_wkalrm *t)
302{
303 struct i2c_client *client = to_i2c_client(dev);
304 struct ds1307 *ds1307 = i2c_get_clientdata(client);
305 int ret;
306
307 if (!test_bit(HAS_ALARM, &ds1307->flags))
308 return -EINVAL;
309
310 /* read all ALARM1, ALARM2, and status registers at once */
311 ds1307->reg_addr = DS1339_REG_ALARM1_SECS;
312 ds1307->msg[1].flags = I2C_M_RD;
313 ds1307->msg[1].len = 9;
314
315 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
316 ds1307->msg, 2);
317 if (ret != 2) {
318 dev_err(dev, "%s error %d\n", "alarm read", ret);
319 return -EIO;
320 }
321
322 dev_dbg(dev, "%s: %02x %02x %02x %02x, %02x %02x %02x, %02x %02x\n",
323 "alarm read",
324 ds1307->regs[0], ds1307->regs[1],
325 ds1307->regs[2], ds1307->regs[3],
326 ds1307->regs[4], ds1307->regs[5],
327 ds1307->regs[6], ds1307->regs[7],
328 ds1307->regs[8]);
329
330 /* report alarm time (ALARM1); assume 24 hour and day-of-month modes,
331 * and that all four fields are checked matches
332 */
333 t->time.tm_sec = bcd2bin(ds1307->regs[0] & 0x7f);
334 t->time.tm_min = bcd2bin(ds1307->regs[1] & 0x7f);
335 t->time.tm_hour = bcd2bin(ds1307->regs[2] & 0x3f);
336 t->time.tm_mday = bcd2bin(ds1307->regs[3] & 0x3f);
337 t->time.tm_mon = -1;
338 t->time.tm_year = -1;
339 t->time.tm_wday = -1;
340 t->time.tm_yday = -1;
341 t->time.tm_isdst = -1;
342
343 /* ... and status */
344 t->enabled = !!(ds1307->regs[7] & DS1337_BIT_A1IE);
345 t->pending = !!(ds1307->regs[8] & DS1337_BIT_A1I);
346
347 dev_dbg(dev, "%s secs=%d, mins=%d, "
348 "hours=%d, mday=%d, enabled=%d, pending=%d\n",
349 "alarm read", t->time.tm_sec, t->time.tm_min,
350 t->time.tm_hour, t->time.tm_mday,
351 t->enabled, t->pending);
352
353 return 0;
354}
355
356static int ds1307_set_alarm(struct device *dev, struct rtc_wkalrm *t)
357{
358 struct i2c_client *client = to_i2c_client(dev);
359 struct ds1307 *ds1307 = i2c_get_clientdata(client);
360 unsigned char *buf = ds1307->regs;
361 u8 control, status;
362 int ret;
363
364 if (!test_bit(HAS_ALARM, &ds1307->flags))
365 return -EINVAL;
366
367 dev_dbg(dev, "%s secs=%d, mins=%d, "
368 "hours=%d, mday=%d, enabled=%d, pending=%d\n",
369 "alarm set", t->time.tm_sec, t->time.tm_min,
370 t->time.tm_hour, t->time.tm_mday,
371 t->enabled, t->pending);
372
373 /* read current status of both alarms and the chip */
374 ds1307->reg_addr = DS1339_REG_ALARM1_SECS;
375 ds1307->msg[1].flags = I2C_M_RD;
376 ds1307->msg[1].len = 9;
377
378 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
379 ds1307->msg, 2);
380 if (ret != 2) {
381 dev_err(dev, "%s error %d\n", "alarm write", ret);
382 return -EIO;
383 }
384 control = ds1307->regs[7];
385 status = ds1307->regs[8];
386
387 dev_dbg(dev, "%s: %02x %02x %02x %02x, %02x %02x %02x, %02x %02x\n",
388 "alarm set (old status)",
389 ds1307->regs[0], ds1307->regs[1],
390 ds1307->regs[2], ds1307->regs[3],
391 ds1307->regs[4], ds1307->regs[5],
392 ds1307->regs[6], control, status);
393
394 /* set ALARM1, using 24 hour and day-of-month modes */
395 *buf++ = DS1339_REG_ALARM1_SECS; /* first register addr */
396 buf[0] = bin2bcd(t->time.tm_sec);
397 buf[1] = bin2bcd(t->time.tm_min);
398 buf[2] = bin2bcd(t->time.tm_hour);
399 buf[3] = bin2bcd(t->time.tm_mday);
400
401 /* set ALARM2 to non-garbage */
402 buf[4] = 0;
403 buf[5] = 0;
404 buf[6] = 0;
405
406 /* optionally enable ALARM1 */
407 buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE);
408 if (t->enabled) {
409 dev_dbg(dev, "alarm IRQ armed\n");
410 buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
411 }
412 buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I);
413
414 ds1307->msg[1].flags = 0;
415 ds1307->msg[1].len = 10;
416
417 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
418 &ds1307->msg[1], 1);
419 if (ret != 1) {
420 dev_err(dev, "can't set alarm time\n");
421 return -EIO;
422 }
423
424 return 0;
425}
426
427static int ds1307_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
428{
429 struct i2c_client *client = to_i2c_client(dev);
430 struct ds1307 *ds1307 = i2c_get_clientdata(client);
431 int ret;
432
433 switch (cmd) {
434 case RTC_AIE_OFF:
435 if (!test_bit(HAS_ALARM, &ds1307->flags))
436 return -ENOTTY;
437
438 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
439 if (ret < 0)
440 return ret;
441
442 ret &= ~DS1337_BIT_A1IE;
443
444 ret = i2c_smbus_write_byte_data(client,
445 DS1337_REG_CONTROL, ret);
446 if (ret < 0)
447 return ret;
448
449 break;
450
451 case RTC_AIE_ON:
452 if (!test_bit(HAS_ALARM, &ds1307->flags))
453 return -ENOTTY;
454
455 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
456 if (ret < 0)
457 return ret;
458
459 ret |= DS1337_BIT_A1IE;
460
461 ret = i2c_smbus_write_byte_data(client,
462 DS1337_REG_CONTROL, ret);
463 if (ret < 0)
464 return ret;
465
466 break;
467
468 default:
469 return -ENOIOCTLCMD;
470 }
471
472 return 0;
473}
474
234static const struct rtc_class_ops ds13xx_rtc_ops = { 475static const struct rtc_class_ops ds13xx_rtc_ops = {
235 .read_time = ds1307_get_time, 476 .read_time = ds1307_get_time,
236 .set_time = ds1307_set_time, 477 .set_time = ds1307_set_time,
478 .read_alarm = ds1307_read_alarm,
479 .set_alarm = ds1307_set_alarm,
480 .ioctl = ds1307_ioctl,
237}; 481};
238 482
239/*----------------------------------------------------------------------*/ 483/*----------------------------------------------------------------------*/
@@ -307,7 +551,6 @@ static struct bin_attribute nvram = {
307 .attr = { 551 .attr = {
308 .name = "nvram", 552 .name = "nvram",
309 .mode = S_IRUGO | S_IWUSR, 553 .mode = S_IRUGO | S_IWUSR,
310 .owner = THIS_MODULE,
311 }, 554 },
312 555
313 .read = ds1307_nvram_read, 556 .read = ds1307_nvram_read,
@@ -327,6 +570,7 @@ static int __devinit ds1307_probe(struct i2c_client *client,
327 int tmp; 570 int tmp;
328 const struct chip_desc *chip = &chips[id->driver_data]; 571 const struct chip_desc *chip = &chips[id->driver_data];
329 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 572 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
573 int want_irq = false;
330 574
331 if (!i2c_check_functionality(adapter, 575 if (!i2c_check_functionality(adapter,
332 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 576 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
@@ -353,6 +597,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
353 switch (ds1307->type) { 597 switch (ds1307->type) {
354 case ds_1337: 598 case ds_1337:
355 case ds_1339: 599 case ds_1339:
600 /* has IRQ? */
601 if (ds1307->client->irq > 0 && chip->alarm) {
602 INIT_WORK(&ds1307->work, ds1307_work);
603 want_irq = true;
604 }
605
356 ds1307->reg_addr = DS1337_REG_CONTROL; 606 ds1307->reg_addr = DS1337_REG_CONTROL;
357 ds1307->msg[1].len = 2; 607 ds1307->msg[1].len = 2;
358 608
@@ -369,8 +619,20 @@ static int __devinit ds1307_probe(struct i2c_client *client,
369 619
370 /* oscillator off? turn it on, so clock can tick. */ 620 /* oscillator off? turn it on, so clock can tick. */
371 if (ds1307->regs[0] & DS1337_BIT_nEOSC) 621 if (ds1307->regs[0] & DS1337_BIT_nEOSC)
372 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, 622 ds1307->regs[0] &= ~DS1337_BIT_nEOSC;
373 ds1307->regs[0] & ~DS1337_BIT_nEOSC); 623
624 /* Using IRQ? Disable the square wave and both alarms.
625 * For ds1339, be sure alarms can trigger when we're
626 * running on Vbackup (BBSQI); we assume ds1337 will
627 * ignore that bit
628 */
629 if (want_irq) {
630 ds1307->regs[0] |= DS1337_BIT_INTCN | DS1339_BIT_BBSQI;
631 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
632 }
633
634 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL,
635 ds1307->regs[0]);
374 636
375 /* oscillator fault? clear flag, and warn */ 637 /* oscillator fault? clear flag, and warn */
376 if (ds1307->regs[1] & DS1337_BIT_OSF) { 638 if (ds1307->regs[1] & DS1337_BIT_OSF) {
@@ -446,18 +708,18 @@ read_rtc:
446 } 708 }
447 709
448 tmp = ds1307->regs[DS1307_REG_SECS]; 710 tmp = ds1307->regs[DS1307_REG_SECS];
449 tmp = BCD2BIN(tmp & 0x7f); 711 tmp = bcd2bin(tmp & 0x7f);
450 if (tmp > 60) 712 if (tmp > 60)
451 goto exit_bad; 713 goto exit_bad;
452 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); 714 tmp = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f);
453 if (tmp > 60) 715 if (tmp > 60)
454 goto exit_bad; 716 goto exit_bad;
455 717
456 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); 718 tmp = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
457 if (tmp == 0 || tmp > 31) 719 if (tmp == 0 || tmp > 31)
458 goto exit_bad; 720 goto exit_bad;
459 721
460 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MONTH] & 0x1f); 722 tmp = bcd2bin(ds1307->regs[DS1307_REG_MONTH] & 0x1f);
461 if (tmp == 0 || tmp > 12) 723 if (tmp == 0 || tmp > 12)
462 goto exit_bad; 724 goto exit_bad;
463 725
@@ -476,14 +738,14 @@ read_rtc:
476 /* Be sure we're in 24 hour mode. Multi-master systems 738 /* Be sure we're in 24 hour mode. Multi-master systems
477 * take note... 739 * take note...
478 */ 740 */
479 tmp = BCD2BIN(tmp & 0x1f); 741 tmp = bcd2bin(tmp & 0x1f);
480 if (tmp == 12) 742 if (tmp == 12)
481 tmp = 0; 743 tmp = 0;
482 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) 744 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM)
483 tmp += 12; 745 tmp += 12;
484 i2c_smbus_write_byte_data(client, 746 i2c_smbus_write_byte_data(client,
485 DS1307_REG_HOUR, 747 DS1307_REG_HOUR,
486 BIN2BCD(tmp)); 748 bin2bcd(tmp));
487 } 749 }
488 750
489 ds1307->rtc = rtc_device_register(client->name, &client->dev, 751 ds1307->rtc = rtc_device_register(client->name, &client->dev,
@@ -495,10 +757,22 @@ read_rtc:
495 goto exit_free; 757 goto exit_free;
496 } 758 }
497 759
760 if (want_irq) {
761 err = request_irq(client->irq, ds1307_irq, 0,
762 ds1307->rtc->name, client);
763 if (err) {
764 dev_err(&client->dev,
765 "unable to request IRQ!\n");
766 goto exit_irq;
767 }
768 set_bit(HAS_ALARM, &ds1307->flags);
769 dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
770 }
771
498 if (chip->nvram56) { 772 if (chip->nvram56) {
499 err = sysfs_create_bin_file(&client->dev.kobj, &nvram); 773 err = sysfs_create_bin_file(&client->dev.kobj, &nvram);
500 if (err == 0) { 774 if (err == 0) {
501 ds1307->has_nvram = true; 775 set_bit(HAS_NVRAM, &ds1307->flags);
502 dev_info(&client->dev, "56 bytes nvram\n"); 776 dev_info(&client->dev, "56 bytes nvram\n");
503 } 777 }
504 } 778 }
@@ -512,7 +786,9 @@ exit_bad:
512 ds1307->regs[2], ds1307->regs[3], 786 ds1307->regs[2], ds1307->regs[3],
513 ds1307->regs[4], ds1307->regs[5], 787 ds1307->regs[4], ds1307->regs[5],
514 ds1307->regs[6]); 788 ds1307->regs[6]);
515 789exit_irq:
790 if (ds1307->rtc)
791 rtc_device_unregister(ds1307->rtc);
516exit_free: 792exit_free:
517 kfree(ds1307); 793 kfree(ds1307);
518 return err; 794 return err;
@@ -520,9 +796,14 @@ exit_free:
520 796
521static int __devexit ds1307_remove(struct i2c_client *client) 797static int __devexit ds1307_remove(struct i2c_client *client)
522{ 798{
523 struct ds1307 *ds1307 = i2c_get_clientdata(client); 799 struct ds1307 *ds1307 = i2c_get_clientdata(client);
800
801 if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) {
802 free_irq(client->irq, client);
803 cancel_work_sync(&ds1307->work);
804 }
524 805
525 if (ds1307->has_nvram) 806 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
526 sysfs_remove_bin_file(&client->dev.kobj, &nvram); 807 sysfs_remove_bin_file(&client->dev.kobj, &nvram);
527 808
528 rtc_device_unregister(ds1307->rtc); 809 rtc_device_unregister(ds1307->rtc);
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index a150418fba76..a5b0fc09f0c6 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -429,12 +429,33 @@ static int __devexit ds1374_remove(struct i2c_client *client)
429 return 0; 429 return 0;
430} 430}
431 431
432#ifdef CONFIG_PM
433static int ds1374_suspend(struct i2c_client *client, pm_message_t state)
434{
435 if (client->irq >= 0 && device_may_wakeup(&client->dev))
436 enable_irq_wake(client->irq);
437 return 0;
438}
439
440static int ds1374_resume(struct i2c_client *client)
441{
442 if (client->irq >= 0 && device_may_wakeup(&client->dev))
443 disable_irq_wake(client->irq);
444 return 0;
445}
446#else
447#define ds1374_suspend NULL
448#define ds1374_resume NULL
449#endif
450
432static struct i2c_driver ds1374_driver = { 451static struct i2c_driver ds1374_driver = {
433 .driver = { 452 .driver = {
434 .name = "rtc-ds1374", 453 .name = "rtc-ds1374",
435 .owner = THIS_MODULE, 454 .owner = THIS_MODULE,
436 }, 455 },
437 .probe = ds1374_probe, 456 .probe = ds1374_probe,
457 .suspend = ds1374_suspend,
458 .resume = ds1374_resume,
438 .remove = __devexit_p(ds1374_remove), 459 .remove = __devexit_p(ds1374_remove),
439 .id_table = ds1374_id, 460 .id_table = ds1374_id,
440}; 461};
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 0f0d27d1c4ca..25caada78398 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -153,8 +153,8 @@ ds1511_wdog_set(unsigned long deciseconds)
153 /* 153 /*
154 * set the wdog values in the wdog registers 154 * set the wdog values in the wdog registers
155 */ 155 */
156 rtc_write(BIN2BCD(deciseconds % 100), DS1511_WD_MSEC); 156 rtc_write(bin2bcd(deciseconds % 100), DS1511_WD_MSEC);
157 rtc_write(BIN2BCD(deciseconds / 100), DS1511_WD_SEC); 157 rtc_write(bin2bcd(deciseconds / 100), DS1511_WD_SEC);
158 /* 158 /*
159 * set wdog enable and wdog 'steering' bit to issue a reset 159 * set wdog enable and wdog 'steering' bit to issue a reset
160 */ 160 */
@@ -220,13 +220,13 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
220 /* 220 /*
221 * each register is a different number of valid bits 221 * each register is a different number of valid bits
222 */ 222 */
223 sec = BIN2BCD(sec) & 0x7f; 223 sec = bin2bcd(sec) & 0x7f;
224 min = BIN2BCD(min) & 0x7f; 224 min = bin2bcd(min) & 0x7f;
225 hrs = BIN2BCD(hrs) & 0x3f; 225 hrs = bin2bcd(hrs) & 0x3f;
226 day = BIN2BCD(day) & 0x3f; 226 day = bin2bcd(day) & 0x3f;
227 mon = BIN2BCD(mon) & 0x1f; 227 mon = bin2bcd(mon) & 0x1f;
228 yrs = BIN2BCD(yrs) & 0xff; 228 yrs = bin2bcd(yrs) & 0xff;
229 cen = BIN2BCD(cen) & 0xff; 229 cen = bin2bcd(cen) & 0xff;
230 230
231 spin_lock_irqsave(&ds1511_lock, flags); 231 spin_lock_irqsave(&ds1511_lock, flags);
232 rtc_disable_update(); 232 rtc_disable_update();
@@ -264,14 +264,14 @@ static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
264 rtc_enable_update(); 264 rtc_enable_update();
265 spin_unlock_irqrestore(&ds1511_lock, flags); 265 spin_unlock_irqrestore(&ds1511_lock, flags);
266 266
267 rtc_tm->tm_sec = BCD2BIN(rtc_tm->tm_sec); 267 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
268 rtc_tm->tm_min = BCD2BIN(rtc_tm->tm_min); 268 rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
269 rtc_tm->tm_hour = BCD2BIN(rtc_tm->tm_hour); 269 rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
270 rtc_tm->tm_mday = BCD2BIN(rtc_tm->tm_mday); 270 rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
271 rtc_tm->tm_wday = BCD2BIN(rtc_tm->tm_wday); 271 rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday);
272 rtc_tm->tm_mon = BCD2BIN(rtc_tm->tm_mon); 272 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
273 rtc_tm->tm_year = BCD2BIN(rtc_tm->tm_year); 273 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
274 century = BCD2BIN(century) * 100; 274 century = bcd2bin(century) * 100;
275 275
276 /* 276 /*
277 * Account for differences between how the RTC uses the values 277 * Account for differences between how the RTC uses the values
@@ -304,16 +304,16 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
304 304
305 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); 305 spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
306 rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 306 rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
307 0x80 : BIN2BCD(pdata->alrm_mday) & 0x3f, 307 0x80 : bin2bcd(pdata->alrm_mday) & 0x3f,
308 RTC_ALARM_DATE); 308 RTC_ALARM_DATE);
309 rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? 309 rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
310 0x80 : BIN2BCD(pdata->alrm_hour) & 0x3f, 310 0x80 : bin2bcd(pdata->alrm_hour) & 0x3f,
311 RTC_ALARM_HOUR); 311 RTC_ALARM_HOUR);
312 rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? 312 rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
313 0x80 : BIN2BCD(pdata->alrm_min) & 0x7f, 313 0x80 : bin2bcd(pdata->alrm_min) & 0x7f,
314 RTC_ALARM_MIN); 314 RTC_ALARM_MIN);
315 rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? 315 rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
316 0x80 : BIN2BCD(pdata->alrm_sec) & 0x7f, 316 0x80 : bin2bcd(pdata->alrm_sec) & 0x7f,
317 RTC_ALARM_SEC); 317 RTC_ALARM_SEC);
318 rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD); 318 rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD);
319 rtc_read(RTC_CMD1); /* clear interrupts */ 319 rtc_read(RTC_CMD1); /* clear interrupts */
@@ -379,18 +379,6 @@ ds1511_interrupt(int irq, void *dev_id)
379 return IRQ_HANDLED; 379 return IRQ_HANDLED;
380} 380}
381 381
382 static void
383ds1511_rtc_release(struct device *dev)
384{
385 struct platform_device *pdev = to_platform_device(dev);
386 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
387
388 if (pdata->irq >= 0) {
389 pdata->irqen = 0;
390 ds1511_rtc_update_alarm(pdata);
391 }
392}
393
394 static int 382 static int
395ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 383ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
396{ 384{
@@ -428,7 +416,6 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
428 .set_time = ds1511_rtc_set_time, 416 .set_time = ds1511_rtc_set_time,
429 .read_alarm = ds1511_rtc_read_alarm, 417 .read_alarm = ds1511_rtc_read_alarm,
430 .set_alarm = ds1511_rtc_set_alarm, 418 .set_alarm = ds1511_rtc_set_alarm,
431 .release = ds1511_rtc_release,
432 .ioctl = ds1511_rtc_ioctl, 419 .ioctl = ds1511_rtc_ioctl,
433}; 420};
434 421
@@ -494,7 +481,6 @@ static struct bin_attribute ds1511_nvram_attr = {
494 .attr = { 481 .attr = {
495 .name = "nvram", 482 .name = "nvram",
496 .mode = S_IRUGO | S_IWUGO, 483 .mode = S_IRUGO | S_IWUGO,
497 .owner = THIS_MODULE,
498 }, 484 },
499 .size = DS1511_RAM_MAX, 485 .size = DS1511_RAM_MAX,
500 .read = ds1511_nvram_read, 486 .read = ds1511_nvram_read,
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index a19f11415540..b9475cd20210 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -78,17 +78,17 @@ static int ds1553_rtc_set_time(struct device *dev, struct rtc_time *tm)
78 void __iomem *ioaddr = pdata->ioaddr; 78 void __iomem *ioaddr = pdata->ioaddr;
79 u8 century; 79 u8 century;
80 80
81 century = BIN2BCD((tm->tm_year + 1900) / 100); 81 century = bin2bcd((tm->tm_year + 1900) / 100);
82 82
83 writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL); 83 writeb(RTC_WRITE, pdata->ioaddr + RTC_CONTROL);
84 84
85 writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); 85 writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR);
86 writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); 86 writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH);
87 writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); 87 writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY);
88 writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); 88 writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE);
89 writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); 89 writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS);
90 writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); 90 writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES);
91 writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); 91 writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS);
92 92
93 /* RTC_CENTURY and RTC_CONTROL share same register */ 93 /* RTC_CENTURY and RTC_CONTROL share same register */
94 writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); 94 writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY);
@@ -118,14 +118,14 @@ static int ds1553_rtc_read_time(struct device *dev, struct rtc_time *tm)
118 year = readb(ioaddr + RTC_YEAR); 118 year = readb(ioaddr + RTC_YEAR);
119 century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; 119 century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK;
120 writeb(0, ioaddr + RTC_CONTROL); 120 writeb(0, ioaddr + RTC_CONTROL);
121 tm->tm_sec = BCD2BIN(second); 121 tm->tm_sec = bcd2bin(second);
122 tm->tm_min = BCD2BIN(minute); 122 tm->tm_min = bcd2bin(minute);
123 tm->tm_hour = BCD2BIN(hour); 123 tm->tm_hour = bcd2bin(hour);
124 tm->tm_mday = BCD2BIN(day); 124 tm->tm_mday = bcd2bin(day);
125 tm->tm_wday = BCD2BIN(week); 125 tm->tm_wday = bcd2bin(week);
126 tm->tm_mon = BCD2BIN(month) - 1; 126 tm->tm_mon = bcd2bin(month) - 1;
127 /* year is 1900 + tm->tm_year */ 127 /* year is 1900 + tm->tm_year */
128 tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; 128 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900;
129 129
130 if (rtc_valid_tm(tm) < 0) { 130 if (rtc_valid_tm(tm) < 0) {
131 dev_err(dev, "retrieved date/time is not valid.\n"); 131 dev_err(dev, "retrieved date/time is not valid.\n");
@@ -141,16 +141,16 @@ static void ds1553_rtc_update_alarm(struct rtc_plat_data *pdata)
141 141
142 spin_lock_irqsave(&pdata->rtc->irq_lock, flags); 142 spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
143 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 143 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
144 0x80 : BIN2BCD(pdata->alrm_mday), 144 0x80 : bin2bcd(pdata->alrm_mday),
145 ioaddr + RTC_DATE_ALARM); 145 ioaddr + RTC_DATE_ALARM);
146 writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? 146 writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
147 0x80 : BIN2BCD(pdata->alrm_hour), 147 0x80 : bin2bcd(pdata->alrm_hour),
148 ioaddr + RTC_HOURS_ALARM); 148 ioaddr + RTC_HOURS_ALARM);
149 writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? 149 writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
150 0x80 : BIN2BCD(pdata->alrm_min), 150 0x80 : bin2bcd(pdata->alrm_min),
151 ioaddr + RTC_MINUTES_ALARM); 151 ioaddr + RTC_MINUTES_ALARM);
152 writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? 152 writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
153 0x80 : BIN2BCD(pdata->alrm_sec), 153 0x80 : bin2bcd(pdata->alrm_sec),
154 ioaddr + RTC_SECONDS_ALARM); 154 ioaddr + RTC_SECONDS_ALARM);
155 writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS); 155 writeb(pdata->irqen ? RTC_INTS_AE : 0, ioaddr + RTC_INTERRUPTS);
156 readb(ioaddr + RTC_FLAGS); /* clear interrupts */ 156 readb(ioaddr + RTC_FLAGS); /* clear interrupts */
@@ -207,17 +207,6 @@ static irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id)
207 return IRQ_HANDLED; 207 return IRQ_HANDLED;
208} 208}
209 209
210static void ds1553_rtc_release(struct device *dev)
211{
212 struct platform_device *pdev = to_platform_device(dev);
213 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
214
215 if (pdata->irq >= 0) {
216 pdata->irqen = 0;
217 ds1553_rtc_update_alarm(pdata);
218 }
219}
220
221static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd, 210static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd,
222 unsigned long arg) 211 unsigned long arg)
223{ 212{
@@ -254,7 +243,6 @@ static const struct rtc_class_ops ds1553_rtc_ops = {
254 .set_time = ds1553_rtc_set_time, 243 .set_time = ds1553_rtc_set_time,
255 .read_alarm = ds1553_rtc_read_alarm, 244 .read_alarm = ds1553_rtc_read_alarm,
256 .set_alarm = ds1553_rtc_set_alarm, 245 .set_alarm = ds1553_rtc_set_alarm,
257 .release = ds1553_rtc_release,
258 .ioctl = ds1553_rtc_ioctl, 246 .ioctl = ds1553_rtc_ioctl,
259}; 247};
260 248
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 6fa4556f5f5c..341d7a5b45a2 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -9,17 +9,10 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/i2c.h> 12#include <linux/i2c.h>
14#include <linux/rtc.h> 13#include <linux/rtc.h>
15 14
16#define DRV_VERSION "0.3" 15#define DRV_VERSION "0.4"
17
18/* Addresses to scan: none. This chip cannot be detected. */
19static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
20
21/* Insmod parameters */
22I2C_CLIENT_INSMOD;
23 16
24/* Registers */ 17/* Registers */
25 18
@@ -29,8 +22,7 @@ I2C_CLIENT_INSMOD;
29 22
30#define DS1672_REG_CONTROL_EOSC 0x80 23#define DS1672_REG_CONTROL_EOSC 0x80
31 24
32/* Prototypes */ 25static struct i2c_driver ds1672_driver;
33static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
34 26
35/* 27/*
36 * In the routines that deal directly with the ds1672 hardware, we use 28 * In the routines that deal directly with the ds1672 hardware, we use
@@ -44,8 +36,8 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
44 unsigned char buf[4]; 36 unsigned char buf[4];
45 37
46 struct i2c_msg msgs[] = { 38 struct i2c_msg msgs[] = {
47 { client->addr, 0, 1, &addr }, /* setup read ptr */ 39 {client->addr, 0, 1, &addr}, /* setup read ptr */
48 { client->addr, I2C_M_RD, 4, buf }, /* read date */ 40 {client->addr, I2C_M_RD, 4, buf}, /* read date */
49 }; 41 };
50 42
51 /* read date registers */ 43 /* read date registers */
@@ -80,7 +72,7 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
80 buf[2] = (secs & 0x0000FF00) >> 8; 72 buf[2] = (secs & 0x0000FF00) >> 8;
81 buf[3] = (secs & 0x00FF0000) >> 16; 73 buf[3] = (secs & 0x00FF0000) >> 16;
82 buf[4] = (secs & 0xFF000000) >> 24; 74 buf[4] = (secs & 0xFF000000) >> 24;
83 buf[5] = 0; /* set control reg to enable counting */ 75 buf[5] = 0; /* set control reg to enable counting */
84 76
85 xfer = i2c_master_send(client, buf, 6); 77 xfer = i2c_master_send(client, buf, 6);
86 if (xfer != 6) { 78 if (xfer != 6) {
@@ -127,8 +119,8 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
127 unsigned char addr = DS1672_REG_CONTROL; 119 unsigned char addr = DS1672_REG_CONTROL;
128 120
129 struct i2c_msg msgs[] = { 121 struct i2c_msg msgs[] = {
130 { client->addr, 0, 1, &addr }, /* setup read ptr */ 122 {client->addr, 0, 1, &addr}, /* setup read ptr */
131 { client->addr, I2C_M_RD, 1, status }, /* read control */ 123 {client->addr, I2C_M_RD, 1, status}, /* read control */
132 }; 124 };
133 125
134 /* read control register */ 126 /* read control register */
@@ -141,7 +133,8 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
141} 133}
142 134
143/* following are the sysfs callback functions */ 135/* following are the sysfs callback functions */
144static ssize_t show_control(struct device *dev, struct device_attribute *attr, char *buf) 136static ssize_t show_control(struct device *dev, struct device_attribute *attr,
137 char *buf)
145{ 138{
146 struct i2c_client *client = to_i2c_client(dev); 139 struct i2c_client *client = to_i2c_client(dev);
147 u8 control; 140 u8 control;
@@ -152,85 +145,46 @@ static ssize_t show_control(struct device *dev, struct device_attribute *attr, c
152 return err; 145 return err;
153 146
154 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC) 147 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
155 ? "disabled" : "enabled"); 148 ? "disabled" : "enabled");
156} 149}
150
157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL); 151static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
158 152
159static const struct rtc_class_ops ds1672_rtc_ops = { 153static const struct rtc_class_ops ds1672_rtc_ops = {
160 .read_time = ds1672_rtc_read_time, 154 .read_time = ds1672_rtc_read_time,
161 .set_time = ds1672_rtc_set_time, 155 .set_time = ds1672_rtc_set_time,
162 .set_mmss = ds1672_rtc_set_mmss, 156 .set_mmss = ds1672_rtc_set_mmss,
163}; 157};
164 158
165static int ds1672_attach(struct i2c_adapter *adapter) 159static int ds1672_remove(struct i2c_client *client)
166{ 160{
167 return i2c_probe(adapter, &addr_data, ds1672_probe);
168}
169
170static int ds1672_detach(struct i2c_client *client)
171{
172 int err;
173 struct rtc_device *rtc = i2c_get_clientdata(client); 161 struct rtc_device *rtc = i2c_get_clientdata(client);
174 162
175 if (rtc) 163 if (rtc)
176 rtc_device_unregister(rtc); 164 rtc_device_unregister(rtc);
177 165
178 if ((err = i2c_detach_client(client)))
179 return err;
180
181 kfree(client);
182
183 return 0; 166 return 0;
184} 167}
185 168
186static struct i2c_driver ds1672_driver = { 169static int ds1672_probe(struct i2c_client *client,
187 .driver = { 170 const struct i2c_device_id *id)
188 .name = "ds1672",
189 },
190 .id = I2C_DRIVERID_DS1672,
191 .attach_adapter = &ds1672_attach,
192 .detach_client = &ds1672_detach,
193};
194
195static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
196{ 171{
197 int err = 0; 172 int err = 0;
198 u8 control; 173 u8 control;
199 struct i2c_client *client;
200 struct rtc_device *rtc; 174 struct rtc_device *rtc;
201 175
202 dev_dbg(&adapter->dev, "%s\n", __func__); 176 dev_dbg(&client->dev, "%s\n", __func__);
203 177
204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 178 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
205 err = -ENODEV; 179 return -ENODEV;
206 goto exit;
207 }
208
209 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
210 err = -ENOMEM;
211 goto exit;
212 }
213
214 /* I2C client */
215 client->addr = address;
216 client->driver = &ds1672_driver;
217 client->adapter = adapter;
218
219 strlcpy(client->name, ds1672_driver.driver.name, I2C_NAME_SIZE);
220
221 /* Inform the i2c layer */
222 if ((err = i2c_attach_client(client)))
223 goto exit_kfree;
224 180
225 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 181 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
226 182
227 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev, 183 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev,
228 &ds1672_rtc_ops, THIS_MODULE); 184 &ds1672_rtc_ops, THIS_MODULE);
229 185
230 if (IS_ERR(rtc)) { 186 if (IS_ERR(rtc))
231 err = PTR_ERR(rtc); 187 return PTR_ERR(rtc);
232 goto exit_detach;
233 }
234 188
235 i2c_set_clientdata(client, rtc); 189 i2c_set_clientdata(client, rtc);
236 190
@@ -241,7 +195,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
241 195
242 if (control & DS1672_REG_CONTROL_EOSC) 196 if (control & DS1672_REG_CONTROL_EOSC)
243 dev_warn(&client->dev, "Oscillator not enabled. " 197 dev_warn(&client->dev, "Oscillator not enabled. "
244 "Set time to enable.\n"); 198 "Set time to enable.\n");
245 199
246 /* Register sysfs hooks */ 200 /* Register sysfs hooks */
247 err = device_create_file(&client->dev, &dev_attr_control); 201 err = device_create_file(&client->dev, &dev_attr_control);
@@ -250,19 +204,19 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
250 204
251 return 0; 205 return 0;
252 206
253exit_devreg: 207 exit_devreg:
254 rtc_device_unregister(rtc); 208 rtc_device_unregister(rtc);
255
256exit_detach:
257 i2c_detach_client(client);
258
259exit_kfree:
260 kfree(client);
261
262exit:
263 return err; 209 return err;
264} 210}
265 211
212static struct i2c_driver ds1672_driver = {
213 .driver = {
214 .name = "rtc-ds1672",
215 },
216 .probe = &ds1672_probe,
217 .remove = &ds1672_remove,
218};
219
266static int __init ds1672_init(void) 220static int __init ds1672_init(void)
267{ 221{
268 return i2c_add_driver(&ds1672_driver); 222 return i2c_add_driver(&ds1672_driver);
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 24d35ede2dbf..8bc8501bffc8 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -66,17 +66,17 @@ static int ds1742_rtc_set_time(struct device *dev, struct rtc_time *tm)
66 void __iomem *ioaddr = pdata->ioaddr_rtc; 66 void __iomem *ioaddr = pdata->ioaddr_rtc;
67 u8 century; 67 u8 century;
68 68
69 century = BIN2BCD((tm->tm_year + 1900) / 100); 69 century = bin2bcd((tm->tm_year + 1900) / 100);
70 70
71 writeb(RTC_WRITE, ioaddr + RTC_CONTROL); 71 writeb(RTC_WRITE, ioaddr + RTC_CONTROL);
72 72
73 writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); 73 writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR);
74 writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); 74 writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH);
75 writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); 75 writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY);
76 writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); 76 writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE);
77 writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); 77 writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS);
78 writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); 78 writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES);
79 writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); 79 writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS);
80 80
81 /* RTC_CENTURY and RTC_CONTROL share same register */ 81 /* RTC_CENTURY and RTC_CONTROL share same register */
82 writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY); 82 writeb(RTC_WRITE | (century & RTC_CENTURY_MASK), ioaddr + RTC_CENTURY);
@@ -106,14 +106,14 @@ static int ds1742_rtc_read_time(struct device *dev, struct rtc_time *tm)
106 year = readb(ioaddr + RTC_YEAR); 106 year = readb(ioaddr + RTC_YEAR);
107 century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK; 107 century = readb(ioaddr + RTC_CENTURY) & RTC_CENTURY_MASK;
108 writeb(0, ioaddr + RTC_CONTROL); 108 writeb(0, ioaddr + RTC_CONTROL);
109 tm->tm_sec = BCD2BIN(second); 109 tm->tm_sec = bcd2bin(second);
110 tm->tm_min = BCD2BIN(minute); 110 tm->tm_min = bcd2bin(minute);
111 tm->tm_hour = BCD2BIN(hour); 111 tm->tm_hour = bcd2bin(hour);
112 tm->tm_mday = BCD2BIN(day); 112 tm->tm_mday = bcd2bin(day);
113 tm->tm_wday = BCD2BIN(week); 113 tm->tm_wday = bcd2bin(week);
114 tm->tm_mon = BCD2BIN(month) - 1; 114 tm->tm_mon = bcd2bin(month) - 1;
115 /* year is 1900 + tm->tm_year */ 115 /* year is 1900 + tm->tm_year */
116 tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; 116 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900;
117 117
118 if (rtc_valid_tm(tm) < 0) { 118 if (rtc_valid_tm(tm) < 0) {
119 dev_err(dev, "retrieved date/time is not valid.\n"); 119 dev_err(dev, "retrieved date/time is not valid.\n");
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
new file mode 100644
index 000000000000..37d131d03f33
--- /dev/null
+++ b/drivers/rtc/rtc-ds3234.c
@@ -0,0 +1,290 @@
1/* drivers/rtc/rtc-ds3234.c
2 *
3 * Driver for Dallas Semiconductor (DS3234) SPI RTC with Integrated Crystal
4 * and SRAM.
5 *
6 * Copyright (C) 2008 MIMOMax Wireless Ltd.
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 * Changelog:
13 *
14 * 07-May-2008: Dennis Aberilla <denzzzhome@yahoo.com>
15 * - Created based on the max6902 code. Only implements the
16 * date/time keeping functions; no SRAM yet.
17 */
18
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/rtc.h>
22#include <linux/spi/spi.h>
23#include <linux/bcd.h>
24
25#define DS3234_REG_SECONDS 0x00
26#define DS3234_REG_MINUTES 0x01
27#define DS3234_REG_HOURS 0x02
28#define DS3234_REG_DAY 0x03
29#define DS3234_REG_DATE 0x04
30#define DS3234_REG_MONTH 0x05
31#define DS3234_REG_YEAR 0x06
32#define DS3234_REG_CENTURY (1 << 7) /* Bit 7 of the Month register */
33
34#define DS3234_REG_CONTROL 0x0E
35#define DS3234_REG_CONT_STAT 0x0F
36
37#undef DS3234_DEBUG
38
39struct ds3234 {
40 struct rtc_device *rtc;
41 u8 buf[8]; /* Burst read: addr + 7 regs */
42 u8 tx_buf[2];
43 u8 rx_buf[2];
44};
45
46static void ds3234_set_reg(struct device *dev, unsigned char address,
47 unsigned char data)
48{
49 struct spi_device *spi = to_spi_device(dev);
50 unsigned char buf[2];
51
52 /* MSB must be '1' to indicate write */
53 buf[0] = address | 0x80;
54 buf[1] = data;
55
56 spi_write(spi, buf, 2);
57}
58
59static int ds3234_get_reg(struct device *dev, unsigned char address,
60 unsigned char *data)
61{
62 struct spi_device *spi = to_spi_device(dev);
63 struct ds3234 *chip = dev_get_drvdata(dev);
64 struct spi_message message;
65 struct spi_transfer xfer;
66 int status;
67
68 if (!data)
69 return -EINVAL;
70
71 /* Build our spi message */
72 spi_message_init(&message);
73 memset(&xfer, 0, sizeof(xfer));
74
75 /* Address + dummy tx byte */
76 xfer.len = 2;
77 xfer.tx_buf = chip->tx_buf;
78 xfer.rx_buf = chip->rx_buf;
79
80 chip->tx_buf[0] = address;
81 chip->tx_buf[1] = 0xff;
82
83 spi_message_add_tail(&xfer, &message);
84
85 /* do the i/o */
86 status = spi_sync(spi, &message);
87 if (status == 0)
88 status = message.status;
89 else
90 return status;
91
92 *data = chip->rx_buf[1];
93
94 return status;
95}
96
97static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt)
98{
99 struct spi_device *spi = to_spi_device(dev);
100 struct ds3234 *chip = dev_get_drvdata(dev);
101 struct spi_message message;
102 struct spi_transfer xfer;
103 int status;
104
105 /* build the message */
106 spi_message_init(&message);
107 memset(&xfer, 0, sizeof(xfer));
108 xfer.len = 1 + 7; /* Addr + 7 registers */
109 xfer.tx_buf = chip->buf;
110 xfer.rx_buf = chip->buf;
111 chip->buf[0] = 0x00; /* Start address */
112 spi_message_add_tail(&xfer, &message);
113
114 /* do the i/o */
115 status = spi_sync(spi, &message);
116 if (status == 0)
117 status = message.status;
118 else
119 return status;
120
121 /* Seconds, Minutes, Hours, Day, Date, Month, Year */
122 dt->tm_sec = bcd2bin(chip->buf[1]);
123 dt->tm_min = bcd2bin(chip->buf[2]);
124 dt->tm_hour = bcd2bin(chip->buf[3] & 0x3f);
125 dt->tm_wday = bcd2bin(chip->buf[4]) - 1; /* 0 = Sun */
126 dt->tm_mday = bcd2bin(chip->buf[5]);
127 dt->tm_mon = bcd2bin(chip->buf[6] & 0x1f) - 1; /* 0 = Jan */
128 dt->tm_year = bcd2bin(chip->buf[7] & 0xff) + 100; /* Assume 20YY */
129
130#ifdef DS3234_DEBUG
131 dev_dbg(dev, "\n%s : Read RTC values\n", __func__);
132 dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour);
133 dev_dbg(dev, "tm_min : %i\n", dt->tm_min);
134 dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec);
135 dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday);
136 dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday);
137 dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon);
138 dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
139#endif
140
141 return 0;
142}
143
144static int ds3234_set_datetime(struct device *dev, struct rtc_time *dt)
145{
146#ifdef DS3234_DEBUG
147 dev_dbg(dev, "\n%s : Setting RTC values\n", __func__);
148 dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec);
149 dev_dbg(dev, "tm_min : %i\n", dt->tm_min);
150 dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour);
151 dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday);
152 dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday);
153 dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon);
154 dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
155#endif
156
157 ds3234_set_reg(dev, DS3234_REG_SECONDS, bin2bcd(dt->tm_sec));
158 ds3234_set_reg(dev, DS3234_REG_MINUTES, bin2bcd(dt->tm_min));
159 ds3234_set_reg(dev, DS3234_REG_HOURS, bin2bcd(dt->tm_hour) & 0x3f);
160
161 /* 0 = Sun */
162 ds3234_set_reg(dev, DS3234_REG_DAY, bin2bcd(dt->tm_wday + 1));
163 ds3234_set_reg(dev, DS3234_REG_DATE, bin2bcd(dt->tm_mday));
164
165 /* 0 = Jan */
166 ds3234_set_reg(dev, DS3234_REG_MONTH, bin2bcd(dt->tm_mon + 1));
167
168 /* Assume 20YY although we just want to make sure not to go negative. */
169 if (dt->tm_year > 100)
170 dt->tm_year -= 100;
171
172 ds3234_set_reg(dev, DS3234_REG_YEAR, bin2bcd(dt->tm_year));
173
174 return 0;
175}
176
177static int ds3234_read_time(struct device *dev, struct rtc_time *tm)
178{
179 return ds3234_get_datetime(dev, tm);
180}
181
182static int ds3234_set_time(struct device *dev, struct rtc_time *tm)
183{
184 return ds3234_set_datetime(dev, tm);
185}
186
187static const struct rtc_class_ops ds3234_rtc_ops = {
188 .read_time = ds3234_read_time,
189 .set_time = ds3234_set_time,
190};
191
192static int ds3234_probe(struct spi_device *spi)
193{
194 struct rtc_device *rtc;
195 unsigned char tmp;
196 struct ds3234 *chip;
197 int res;
198
199 rtc = rtc_device_register("ds3234",
200 &spi->dev, &ds3234_rtc_ops, THIS_MODULE);
201 if (IS_ERR(rtc))
202 return PTR_ERR(rtc);
203
204 spi->mode = SPI_MODE_3;
205 spi->bits_per_word = 8;
206 spi_setup(spi);
207
208 chip = kzalloc(sizeof(struct ds3234), GFP_KERNEL);
209 if (!chip) {
210 rtc_device_unregister(rtc);
211 return -ENOMEM;
212 }
213 chip->rtc = rtc;
214 dev_set_drvdata(&spi->dev, chip);
215
216 res = ds3234_get_reg(&spi->dev, DS3234_REG_SECONDS, &tmp);
217 if (res) {
218 rtc_device_unregister(rtc);
219 return res;
220 }
221
222 /* Control settings
223 *
224 * CONTROL_REG
225 * BIT 7 6 5 4 3 2 1 0
226 * EOSC BBSQW CONV RS2 RS1 INTCN A2IE A1IE
227 *
228 * 0 0 0 1 1 1 0 0
229 *
230 * CONTROL_STAT_REG
231 * BIT 7 6 5 4 3 2 1 0
232 * OSF BB32kHz CRATE1 CRATE0 EN32kHz BSY A2F A1F
233 *
234 * 1 0 0 0 1 0 0 0
235 */
236 ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp);
237 ds3234_set_reg(&spi->dev, DS3234_REG_CONTROL, tmp & 0x1c);
238
239 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
240 ds3234_set_reg(&spi->dev, DS3234_REG_CONT_STAT, tmp & 0x88);
241
242 /* Print our settings */
243 ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp);
244 dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp);
245
246 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
247 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);
248
249 return 0;
250}
251
252static int __exit ds3234_remove(struct spi_device *spi)
253{
254 struct ds3234 *chip = platform_get_drvdata(spi);
255 struct rtc_device *rtc = chip->rtc;
256
257 if (rtc)
258 rtc_device_unregister(rtc);
259
260 kfree(chip);
261
262 return 0;
263}
264
265static struct spi_driver ds3234_driver = {
266 .driver = {
267 .name = "ds3234",
268 .bus = &spi_bus_type,
269 .owner = THIS_MODULE,
270 },
271 .probe = ds3234_probe,
272 .remove = __devexit_p(ds3234_remove),
273};
274
275static __init int ds3234_init(void)
276{
277 printk(KERN_INFO "DS3234 SPI RTC Driver\n");
278 return spi_register_driver(&ds3234_driver);
279}
280module_init(ds3234_init);
281
282static __exit void ds3234_exit(void)
283{
284 spi_unregister_driver(&ds3234_driver);
285}
286module_exit(ds3234_exit);
287
288MODULE_DESCRIPTION("DS3234 SPI RTC driver");
289MODULE_AUTHOR("Dennis Aberilla <denzzzhome@yahoo.com>");
290MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index abfdfcbaa059..3a7be11cc6b9 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -131,17 +131,17 @@ static int fm3130_get_time(struct device *dev, struct rtc_time *t)
131 fm3130->regs[0xc], fm3130->regs[0xd], 131 fm3130->regs[0xc], fm3130->regs[0xd],
132 fm3130->regs[0xe]); 132 fm3130->regs[0xe]);
133 133
134 t->tm_sec = BCD2BIN(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f); 134 t->tm_sec = bcd2bin(fm3130->regs[FM3130_RTC_SECONDS] & 0x7f);
135 t->tm_min = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); 135 t->tm_min = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
136 tmp = fm3130->regs[FM3130_RTC_HOURS] & 0x3f; 136 tmp = fm3130->regs[FM3130_RTC_HOURS] & 0x3f;
137 t->tm_hour = BCD2BIN(tmp); 137 t->tm_hour = bcd2bin(tmp);
138 t->tm_wday = BCD2BIN(fm3130->regs[FM3130_RTC_DAY] & 0x07) - 1; 138 t->tm_wday = bcd2bin(fm3130->regs[FM3130_RTC_DAY] & 0x07) - 1;
139 t->tm_mday = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); 139 t->tm_mday = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
140 tmp = fm3130->regs[FM3130_RTC_MONTHS] & 0x1f; 140 tmp = fm3130->regs[FM3130_RTC_MONTHS] & 0x1f;
141 t->tm_mon = BCD2BIN(tmp) - 1; 141 t->tm_mon = bcd2bin(tmp) - 1;
142 142
143 /* assume 20YY not 19YY, and ignore CF bit */ 143 /* assume 20YY not 19YY, and ignore CF bit */
144 t->tm_year = BCD2BIN(fm3130->regs[FM3130_RTC_YEARS]) + 100; 144 t->tm_year = bcd2bin(fm3130->regs[FM3130_RTC_YEARS]) + 100;
145 145
146 dev_dbg(dev, "%s secs=%d, mins=%d, " 146 dev_dbg(dev, "%s secs=%d, mins=%d, "
147 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 147 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -167,16 +167,16 @@ static int fm3130_set_time(struct device *dev, struct rtc_time *t)
167 t->tm_mon, t->tm_year, t->tm_wday); 167 t->tm_mon, t->tm_year, t->tm_wday);
168 168
169 /* first register addr */ 169 /* first register addr */
170 buf[FM3130_RTC_SECONDS] = BIN2BCD(t->tm_sec); 170 buf[FM3130_RTC_SECONDS] = bin2bcd(t->tm_sec);
171 buf[FM3130_RTC_MINUTES] = BIN2BCD(t->tm_min); 171 buf[FM3130_RTC_MINUTES] = bin2bcd(t->tm_min);
172 buf[FM3130_RTC_HOURS] = BIN2BCD(t->tm_hour); 172 buf[FM3130_RTC_HOURS] = bin2bcd(t->tm_hour);
173 buf[FM3130_RTC_DAY] = BIN2BCD(t->tm_wday + 1); 173 buf[FM3130_RTC_DAY] = bin2bcd(t->tm_wday + 1);
174 buf[FM3130_RTC_DATE] = BIN2BCD(t->tm_mday); 174 buf[FM3130_RTC_DATE] = bin2bcd(t->tm_mday);
175 buf[FM3130_RTC_MONTHS] = BIN2BCD(t->tm_mon + 1); 175 buf[FM3130_RTC_MONTHS] = bin2bcd(t->tm_mon + 1);
176 176
177 /* assume 20YY not 19YY */ 177 /* assume 20YY not 19YY */
178 tmp = t->tm_year - 100; 178 tmp = t->tm_year - 100;
179 buf[FM3130_RTC_YEARS] = BIN2BCD(tmp); 179 buf[FM3130_RTC_YEARS] = bin2bcd(tmp);
180 180
181 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x" 181 dev_dbg(dev, "%s: %02x %02x %02x %02x %02x %02x %02x"
182 "%02x %02x %02x %02x %02x %02x %02x %02x\n", 182 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
@@ -222,11 +222,11 @@ static int fm3130_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
222 fm3130->regs[FM3130_ALARM_MONTHS]); 222 fm3130->regs[FM3130_ALARM_MONTHS]);
223 223
224 224
225 tm->tm_sec = BCD2BIN(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F); 225 tm->tm_sec = bcd2bin(fm3130->regs[FM3130_ALARM_SECONDS] & 0x7F);
226 tm->tm_min = BCD2BIN(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F); 226 tm->tm_min = bcd2bin(fm3130->regs[FM3130_ALARM_MINUTES] & 0x7F);
227 tm->tm_hour = BCD2BIN(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F); 227 tm->tm_hour = bcd2bin(fm3130->regs[FM3130_ALARM_HOURS] & 0x3F);
228 tm->tm_mday = BCD2BIN(fm3130->regs[FM3130_ALARM_DATE] & 0x3F); 228 tm->tm_mday = bcd2bin(fm3130->regs[FM3130_ALARM_DATE] & 0x3F);
229 tm->tm_mon = BCD2BIN(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F); 229 tm->tm_mon = bcd2bin(fm3130->regs[FM3130_ALARM_MONTHS] & 0x1F);
230 if (tm->tm_mon > 0) 230 if (tm->tm_mon > 0)
231 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */ 231 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */
232 dev_dbg(dev, "%s secs=%d, mins=%d, " 232 dev_dbg(dev, "%s secs=%d, mins=%d, "
@@ -252,23 +252,23 @@ static int fm3130_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
252 252
253 if (tm->tm_sec != -1) 253 if (tm->tm_sec != -1)
254 fm3130->regs[FM3130_ALARM_SECONDS] = 254 fm3130->regs[FM3130_ALARM_SECONDS] =
255 BIN2BCD(tm->tm_sec) | 0x80; 255 bin2bcd(tm->tm_sec) | 0x80;
256 256
257 if (tm->tm_min != -1) 257 if (tm->tm_min != -1)
258 fm3130->regs[FM3130_ALARM_MINUTES] = 258 fm3130->regs[FM3130_ALARM_MINUTES] =
259 BIN2BCD(tm->tm_min) | 0x80; 259 bin2bcd(tm->tm_min) | 0x80;
260 260
261 if (tm->tm_hour != -1) 261 if (tm->tm_hour != -1)
262 fm3130->regs[FM3130_ALARM_HOURS] = 262 fm3130->regs[FM3130_ALARM_HOURS] =
263 BIN2BCD(tm->tm_hour) | 0x80; 263 bin2bcd(tm->tm_hour) | 0x80;
264 264
265 if (tm->tm_mday != -1) 265 if (tm->tm_mday != -1)
266 fm3130->regs[FM3130_ALARM_DATE] = 266 fm3130->regs[FM3130_ALARM_DATE] =
267 BIN2BCD(tm->tm_mday) | 0x80; 267 bin2bcd(tm->tm_mday) | 0x80;
268 268
269 if (tm->tm_mon != -1) 269 if (tm->tm_mon != -1)
270 fm3130->regs[FM3130_ALARM_MONTHS] = 270 fm3130->regs[FM3130_ALARM_MONTHS] =
271 BIN2BCD(tm->tm_mon + 1) | 0x80; 271 bin2bcd(tm->tm_mon + 1) | 0x80;
272 272
273 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n", 273 dev_dbg(dev, "alarm write %02x %02x %02x %02x %02x\n",
274 fm3130->regs[FM3130_ALARM_SECONDS], 274 fm3130->regs[FM3130_ALARM_SECONDS],
@@ -414,18 +414,18 @@ static int __devinit fm3130_probe(struct i2c_client *client,
414 /* TODO */ 414 /* TODO */
415 /* TODO need to sanity check alarm */ 415 /* TODO need to sanity check alarm */
416 tmp = fm3130->regs[FM3130_RTC_SECONDS]; 416 tmp = fm3130->regs[FM3130_RTC_SECONDS];
417 tmp = BCD2BIN(tmp & 0x7f); 417 tmp = bcd2bin(tmp & 0x7f);
418 if (tmp > 60) 418 if (tmp > 60)
419 goto exit_bad; 419 goto exit_bad;
420 tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f); 420 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MINUTES] & 0x7f);
421 if (tmp > 60) 421 if (tmp > 60)
422 goto exit_bad; 422 goto exit_bad;
423 423
424 tmp = BCD2BIN(fm3130->regs[FM3130_RTC_DATE] & 0x3f); 424 tmp = bcd2bin(fm3130->regs[FM3130_RTC_DATE] & 0x3f);
425 if (tmp == 0 || tmp > 31) 425 if (tmp == 0 || tmp > 31)
426 goto exit_bad; 426 goto exit_bad;
427 427
428 tmp = BCD2BIN(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f); 428 tmp = bcd2bin(fm3130->regs[FM3130_RTC_MONTHS] & 0x1f);
429 if (tmp == 0 || tmp > 12) 429 if (tmp == 0 || tmp > 12)
430 goto exit_bad; 430 goto exit_bad;
431 431
diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index a81adab6e515..2cd77ab8fc66 100644
--- a/drivers/rtc/rtc-isl1208.c
+++ b/drivers/rtc/rtc-isl1208.c
@@ -259,26 +259,26 @@ isl1208_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
259 return sr; 259 return sr;
260 } 260 }
261 261
262 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SC]); 262 tm->tm_sec = bcd2bin(regs[ISL1208_REG_SC]);
263 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MN]); 263 tm->tm_min = bcd2bin(regs[ISL1208_REG_MN]);
264 264
265 /* HR field has a more complex interpretation */ 265 /* HR field has a more complex interpretation */
266 { 266 {
267 const u8 _hr = regs[ISL1208_REG_HR]; 267 const u8 _hr = regs[ISL1208_REG_HR];
268 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */ 268 if (_hr & ISL1208_REG_HR_MIL) /* 24h format */
269 tm->tm_hour = BCD2BIN(_hr & 0x3f); 269 tm->tm_hour = bcd2bin(_hr & 0x3f);
270 else { 270 else {
271 /* 12h format */ 271 /* 12h format */
272 tm->tm_hour = BCD2BIN(_hr & 0x1f); 272 tm->tm_hour = bcd2bin(_hr & 0x1f);
273 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */ 273 if (_hr & ISL1208_REG_HR_PM) /* PM flag set */
274 tm->tm_hour += 12; 274 tm->tm_hour += 12;
275 } 275 }
276 } 276 }
277 277
278 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DT]); 278 tm->tm_mday = bcd2bin(regs[ISL1208_REG_DT]);
279 tm->tm_mon = BCD2BIN(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */ 279 tm->tm_mon = bcd2bin(regs[ISL1208_REG_MO]) - 1; /* rtc starts at 1 */
280 tm->tm_year = BCD2BIN(regs[ISL1208_REG_YR]) + 100; 280 tm->tm_year = bcd2bin(regs[ISL1208_REG_YR]) + 100;
281 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DW]); 281 tm->tm_wday = bcd2bin(regs[ISL1208_REG_DW]);
282 282
283 return 0; 283 return 0;
284} 284}
@@ -305,13 +305,13 @@ isl1208_i2c_read_alarm(struct i2c_client *client, struct rtc_wkalrm *alarm)
305 } 305 }
306 306
307 /* MSB of each alarm register is an enable bit */ 307 /* MSB of each alarm register is an enable bit */
308 tm->tm_sec = BCD2BIN(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f); 308 tm->tm_sec = bcd2bin(regs[ISL1208_REG_SCA - ISL1208_REG_SCA] & 0x7f);
309 tm->tm_min = BCD2BIN(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f); 309 tm->tm_min = bcd2bin(regs[ISL1208_REG_MNA - ISL1208_REG_SCA] & 0x7f);
310 tm->tm_hour = BCD2BIN(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f); 310 tm->tm_hour = bcd2bin(regs[ISL1208_REG_HRA - ISL1208_REG_SCA] & 0x3f);
311 tm->tm_mday = BCD2BIN(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f); 311 tm->tm_mday = bcd2bin(regs[ISL1208_REG_DTA - ISL1208_REG_SCA] & 0x3f);
312 tm->tm_mon = 312 tm->tm_mon =
313 BCD2BIN(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1; 313 bcd2bin(regs[ISL1208_REG_MOA - ISL1208_REG_SCA] & 0x1f) - 1;
314 tm->tm_wday = BCD2BIN(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03); 314 tm->tm_wday = bcd2bin(regs[ISL1208_REG_DWA - ISL1208_REG_SCA] & 0x03);
315 315
316 return 0; 316 return 0;
317} 317}
@@ -328,15 +328,15 @@ isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
328 int sr; 328 int sr;
329 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; 329 u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, };
330 330
331 regs[ISL1208_REG_SC] = BIN2BCD(tm->tm_sec); 331 regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec);
332 regs[ISL1208_REG_MN] = BIN2BCD(tm->tm_min); 332 regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min);
333 regs[ISL1208_REG_HR] = BIN2BCD(tm->tm_hour) | ISL1208_REG_HR_MIL; 333 regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL;
334 334
335 regs[ISL1208_REG_DT] = BIN2BCD(tm->tm_mday); 335 regs[ISL1208_REG_DT] = bin2bcd(tm->tm_mday);
336 regs[ISL1208_REG_MO] = BIN2BCD(tm->tm_mon + 1); 336 regs[ISL1208_REG_MO] = bin2bcd(tm->tm_mon + 1);
337 regs[ISL1208_REG_YR] = BIN2BCD(tm->tm_year - 100); 337 regs[ISL1208_REG_YR] = bin2bcd(tm->tm_year - 100);
338 338
339 regs[ISL1208_REG_DW] = BIN2BCD(tm->tm_wday & 7); 339 regs[ISL1208_REG_DW] = bin2bcd(tm->tm_wday & 7);
340 340
341 sr = isl1208_i2c_get_sr(client); 341 sr = isl1208_i2c_get_sr(client);
342 if (sr < 0) { 342 if (sr < 0) {
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 24bc1689fc74..893f7dece239 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -56,21 +56,27 @@
56#define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ 56#define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */
57#define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ 57#define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */
58#define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ 58#define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */
59#define M41T80_WATCHDOG_RB2 (1 << 7) /* RB: Watchdog resolution */
60#define M41T80_WATCHDOG_RB1 (1 << 1) /* RB: Watchdog resolution */
61#define M41T80_WATCHDOG_RB0 (1 << 0) /* RB: Watchdog resolution */
59 62
60#define M41T80_FEATURE_HT (1 << 0) 63#define M41T80_FEATURE_HT (1 << 0) /* Halt feature */
61#define M41T80_FEATURE_BL (1 << 1) 64#define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */
65#define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */
66#define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */
62 67
63#define DRV_VERSION "0.05" 68#define DRV_VERSION "0.05"
64 69
65static const struct i2c_device_id m41t80_id[] = { 70static const struct i2c_device_id m41t80_id[] = {
66 { "m41t80", 0 }, 71 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD },
67 { "m41t81", M41T80_FEATURE_HT }, 72 { "m41t80", M41T80_FEATURE_SQ },
68 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 73 { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ},
69 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 74 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
70 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 75 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
71 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 76 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
72 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 77 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
73 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 78 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
79 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
74 { } 80 { }
75}; 81};
76MODULE_DEVICE_TABLE(i2c, m41t80_id); 82MODULE_DEVICE_TABLE(i2c, m41t80_id);
@@ -104,15 +110,15 @@ static int m41t80_get_datetime(struct i2c_client *client,
104 return -EIO; 110 return -EIO;
105 } 111 }
106 112
107 tm->tm_sec = BCD2BIN(buf[M41T80_REG_SEC] & 0x7f); 113 tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f);
108 tm->tm_min = BCD2BIN(buf[M41T80_REG_MIN] & 0x7f); 114 tm->tm_min = bcd2bin(buf[M41T80_REG_MIN] & 0x7f);
109 tm->tm_hour = BCD2BIN(buf[M41T80_REG_HOUR] & 0x3f); 115 tm->tm_hour = bcd2bin(buf[M41T80_REG_HOUR] & 0x3f);
110 tm->tm_mday = BCD2BIN(buf[M41T80_REG_DAY] & 0x3f); 116 tm->tm_mday = bcd2bin(buf[M41T80_REG_DAY] & 0x3f);
111 tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07; 117 tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07;
112 tm->tm_mon = BCD2BIN(buf[M41T80_REG_MON] & 0x1f) - 1; 118 tm->tm_mon = bcd2bin(buf[M41T80_REG_MON] & 0x1f) - 1;
113 119
114 /* assume 20YY not 19YY, and ignore the Century Bit */ 120 /* assume 20YY not 19YY, and ignore the Century Bit */
115 tm->tm_year = BCD2BIN(buf[M41T80_REG_YEAR]) + 100; 121 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100;
116 return 0; 122 return 0;
117} 123}
118 124
@@ -155,19 +161,19 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
155 /* Merge time-data and register flags into buf[0..7] */ 161 /* Merge time-data and register flags into buf[0..7] */
156 buf[M41T80_REG_SSEC] = 0; 162 buf[M41T80_REG_SSEC] = 0;
157 buf[M41T80_REG_SEC] = 163 buf[M41T80_REG_SEC] =
158 BIN2BCD(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f); 164 bin2bcd(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f);
159 buf[M41T80_REG_MIN] = 165 buf[M41T80_REG_MIN] =
160 BIN2BCD(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); 166 bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f);
161 buf[M41T80_REG_HOUR] = 167 buf[M41T80_REG_HOUR] =
162 BIN2BCD(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ; 168 bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ;
163 buf[M41T80_REG_WDAY] = 169 buf[M41T80_REG_WDAY] =
164 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); 170 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07);
165 buf[M41T80_REG_DAY] = 171 buf[M41T80_REG_DAY] =
166 BIN2BCD(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); 172 bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f);
167 buf[M41T80_REG_MON] = 173 buf[M41T80_REG_MON] =
168 BIN2BCD(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); 174 bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f);
169 /* assume 20YY not 19YY */ 175 /* assume 20YY not 19YY */
170 buf[M41T80_REG_YEAR] = BIN2BCD(tm->tm_year % 100); 176 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100);
171 177
172 if (i2c_transfer(client->adapter, msgs, 1) != 1) { 178 if (i2c_transfer(client->adapter, msgs, 1) != 1) {
173 dev_err(&client->dev, "write error\n"); 179 dev_err(&client->dev, "write error\n");
@@ -282,15 +288,15 @@ static int m41t80_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
282 288
283 wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */ 289 wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */
284 reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ? 290 reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ?
285 BIN2BCD(t->time.tm_sec) : 0x80; 291 bin2bcd(t->time.tm_sec) : 0x80;
286 reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ? 292 reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ?
287 BIN2BCD(t->time.tm_min) : 0x80; 293 bin2bcd(t->time.tm_min) : 0x80;
288 reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ? 294 reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ?
289 BIN2BCD(t->time.tm_hour) : 0x80; 295 bin2bcd(t->time.tm_hour) : 0x80;
290 reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ? 296 reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ?
291 BIN2BCD(t->time.tm_mday) : 0x80; 297 bin2bcd(t->time.tm_mday) : 0x80;
292 if (t->time.tm_mon >= 0) 298 if (t->time.tm_mon >= 0)
293 reg[M41T80_REG_ALARM_MON] |= BIN2BCD(t->time.tm_mon + 1); 299 reg[M41T80_REG_ALARM_MON] |= bin2bcd(t->time.tm_mon + 1);
294 else 300 else
295 reg[M41T80_REG_ALARM_DAY] |= 0x40; 301 reg[M41T80_REG_ALARM_DAY] |= 0x40;
296 302
@@ -341,15 +347,15 @@ static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t)
341 t->time.tm_mday = -1; 347 t->time.tm_mday = -1;
342 t->time.tm_mon = -1; 348 t->time.tm_mon = -1;
343 if (!(reg[M41T80_REG_ALARM_SEC] & 0x80)) 349 if (!(reg[M41T80_REG_ALARM_SEC] & 0x80))
344 t->time.tm_sec = BCD2BIN(reg[M41T80_REG_ALARM_SEC] & 0x7f); 350 t->time.tm_sec = bcd2bin(reg[M41T80_REG_ALARM_SEC] & 0x7f);
345 if (!(reg[M41T80_REG_ALARM_MIN] & 0x80)) 351 if (!(reg[M41T80_REG_ALARM_MIN] & 0x80))
346 t->time.tm_min = BCD2BIN(reg[M41T80_REG_ALARM_MIN] & 0x7f); 352 t->time.tm_min = bcd2bin(reg[M41T80_REG_ALARM_MIN] & 0x7f);
347 if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80)) 353 if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80))
348 t->time.tm_hour = BCD2BIN(reg[M41T80_REG_ALARM_HOUR] & 0x3f); 354 t->time.tm_hour = bcd2bin(reg[M41T80_REG_ALARM_HOUR] & 0x3f);
349 if (!(reg[M41T80_REG_ALARM_DAY] & 0x80)) 355 if (!(reg[M41T80_REG_ALARM_DAY] & 0x80))
350 t->time.tm_mday = BCD2BIN(reg[M41T80_REG_ALARM_DAY] & 0x3f); 356 t->time.tm_mday = bcd2bin(reg[M41T80_REG_ALARM_DAY] & 0x3f);
351 if (!(reg[M41T80_REG_ALARM_DAY] & 0x40)) 357 if (!(reg[M41T80_REG_ALARM_DAY] & 0x40))
352 t->time.tm_mon = BCD2BIN(reg[M41T80_REG_ALARM_MON] & 0x1f) - 1; 358 t->time.tm_mon = bcd2bin(reg[M41T80_REG_ALARM_MON] & 0x1f) - 1;
353 t->time.tm_year = -1; 359 t->time.tm_year = -1;
354 t->time.tm_wday = -1; 360 t->time.tm_wday = -1;
355 t->time.tm_yday = -1; 361 t->time.tm_yday = -1;
@@ -386,8 +392,12 @@ static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev,
386 struct device_attribute *attr, char *buf) 392 struct device_attribute *attr, char *buf)
387{ 393{
388 struct i2c_client *client = to_i2c_client(dev); 394 struct i2c_client *client = to_i2c_client(dev);
395 struct m41t80_data *clientdata = i2c_get_clientdata(client);
389 int val; 396 int val;
390 397
398 if (!(clientdata->features & M41T80_FEATURE_SQ))
399 return -EINVAL;
400
391 val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); 401 val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW);
392 if (val < 0) 402 if (val < 0)
393 return -EIO; 403 return -EIO;
@@ -408,9 +418,13 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev,
408 const char *buf, size_t count) 418 const char *buf, size_t count)
409{ 419{
410 struct i2c_client *client = to_i2c_client(dev); 420 struct i2c_client *client = to_i2c_client(dev);
421 struct m41t80_data *clientdata = i2c_get_clientdata(client);
411 int almon, sqw; 422 int almon, sqw;
412 int val = simple_strtoul(buf, NULL, 0); 423 int val = simple_strtoul(buf, NULL, 0);
413 424
425 if (!(clientdata->features & M41T80_FEATURE_SQ))
426 return -EINVAL;
427
414 if (val) { 428 if (val) {
415 if (!is_power_of_2(val)) 429 if (!is_power_of_2(val))
416 return -EINVAL; 430 return -EINVAL;
@@ -499,6 +513,8 @@ static void wdt_ping(void)
499 .buf = i2c_data, 513 .buf = i2c_data,
500 }, 514 },
501 }; 515 };
516 struct m41t80_data *clientdata = i2c_get_clientdata(save_client);
517
502 i2c_data[0] = 0x09; /* watchdog register */ 518 i2c_data[0] = 0x09; /* watchdog register */
503 519
504 if (wdt_margin > 31) 520 if (wdt_margin > 31)
@@ -509,6 +525,13 @@ static void wdt_ping(void)
509 */ 525 */
510 i2c_data[1] = wdt_margin<<2 | 0x82; 526 i2c_data[1] = wdt_margin<<2 | 0x82;
511 527
528 /*
529 * M41T65 has three bits for watchdog resolution. Don't set bit 7, as
530 * that would be an invalid resolution.
531 */
532 if (clientdata->features & M41T80_FEATURE_WD)
533 i2c_data[1] &= ~M41T80_WATCHDOG_RB2;
534
512 i2c_transfer(save_client->adapter, msgs1, 1); 535 i2c_transfer(save_client->adapter, msgs1, 1);
513} 536}
514 537
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 9b19499c829e..c3a18c58daf6 100644
--- a/drivers/rtc/rtc-m41t94.c
+++ b/drivers/rtc/rtc-m41t94.c
@@ -41,17 +41,17 @@ static int m41t94_set_time(struct device *dev, struct rtc_time *tm)
41 tm->tm_mon, tm->tm_year, tm->tm_wday); 41 tm->tm_mon, tm->tm_year, tm->tm_wday);
42 42
43 buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */ 43 buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */
44 buf[M41T94_REG_SECONDS] = BIN2BCD(tm->tm_sec); 44 buf[M41T94_REG_SECONDS] = bin2bcd(tm->tm_sec);
45 buf[M41T94_REG_MINUTES] = BIN2BCD(tm->tm_min); 45 buf[M41T94_REG_MINUTES] = bin2bcd(tm->tm_min);
46 buf[M41T94_REG_HOURS] = BIN2BCD(tm->tm_hour); 46 buf[M41T94_REG_HOURS] = bin2bcd(tm->tm_hour);
47 buf[M41T94_REG_WDAY] = BIN2BCD(tm->tm_wday + 1); 47 buf[M41T94_REG_WDAY] = bin2bcd(tm->tm_wday + 1);
48 buf[M41T94_REG_DAY] = BIN2BCD(tm->tm_mday); 48 buf[M41T94_REG_DAY] = bin2bcd(tm->tm_mday);
49 buf[M41T94_REG_MONTH] = BIN2BCD(tm->tm_mon + 1); 49 buf[M41T94_REG_MONTH] = bin2bcd(tm->tm_mon + 1);
50 50
51 buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB; 51 buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB;
52 if (tm->tm_year >= 100) 52 if (tm->tm_year >= 100)
53 buf[M41T94_REG_HOURS] |= M41T94_BIT_CB; 53 buf[M41T94_REG_HOURS] |= M41T94_BIT_CB;
54 buf[M41T94_REG_YEAR] = BIN2BCD(tm->tm_year % 100); 54 buf[M41T94_REG_YEAR] = bin2bcd(tm->tm_year % 100);
55 55
56 return spi_write(spi, buf, 8); 56 return spi_write(spi, buf, 8);
57} 57}
@@ -82,14 +82,14 @@ static int m41t94_read_time(struct device *dev, struct rtc_time *tm)
82 spi_write(spi, buf, 2); 82 spi_write(spi, buf, 2);
83 } 83 }
84 84
85 tm->tm_sec = BCD2BIN(spi_w8r8(spi, M41T94_REG_SECONDS)); 85 tm->tm_sec = bcd2bin(spi_w8r8(spi, M41T94_REG_SECONDS));
86 tm->tm_min = BCD2BIN(spi_w8r8(spi, M41T94_REG_MINUTES)); 86 tm->tm_min = bcd2bin(spi_w8r8(spi, M41T94_REG_MINUTES));
87 hour = spi_w8r8(spi, M41T94_REG_HOURS); 87 hour = spi_w8r8(spi, M41T94_REG_HOURS);
88 tm->tm_hour = BCD2BIN(hour & 0x3f); 88 tm->tm_hour = bcd2bin(hour & 0x3f);
89 tm->tm_wday = BCD2BIN(spi_w8r8(spi, M41T94_REG_WDAY)) - 1; 89 tm->tm_wday = bcd2bin(spi_w8r8(spi, M41T94_REG_WDAY)) - 1;
90 tm->tm_mday = BCD2BIN(spi_w8r8(spi, M41T94_REG_DAY)); 90 tm->tm_mday = bcd2bin(spi_w8r8(spi, M41T94_REG_DAY));
91 tm->tm_mon = BCD2BIN(spi_w8r8(spi, M41T94_REG_MONTH)) - 1; 91 tm->tm_mon = bcd2bin(spi_w8r8(spi, M41T94_REG_MONTH)) - 1;
92 tm->tm_year = BCD2BIN(spi_w8r8(spi, M41T94_REG_YEAR)); 92 tm->tm_year = bcd2bin(spi_w8r8(spi, M41T94_REG_YEAR));
93 if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB)) 93 if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB))
94 tm->tm_year += 100; 94 tm->tm_year += 100;
95 95
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
new file mode 100644
index 000000000000..0b2197559940
--- /dev/null
+++ b/drivers/rtc/rtc-m48t35.c
@@ -0,0 +1,235 @@
1/*
2 * Driver for the SGS-Thomson M48T35 Timekeeper RAM chip
3 *
4 * Copyright (C) 2000 Silicon Graphics, Inc.
5 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
6 *
7 * Copyright (C) 2008 Thomas Bogendoerfer
8 *
9 * Based on code written by Paul Gortmaker.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
17#include <linux/module.h>
18#include <linux/rtc.h>
19#include <linux/platform_device.h>
20#include <linux/bcd.h>
21#include <linux/io.h>
22
23#define DRV_VERSION "1.0"
24
25struct m48t35_rtc {
26 u8 pad[0x7ff8]; /* starts at 0x7ff8 */
27 u8 control;
28 u8 sec;
29 u8 min;
30 u8 hour;
31 u8 day;
32 u8 date;
33 u8 month;
34 u8 year;
35};
36
37#define M48T35_RTC_SET 0x80
38#define M48T35_RTC_READ 0x40
39
40struct m48t35_priv {
41 struct rtc_device *rtc;
42 struct m48t35_rtc __iomem *reg;
43 size_t size;
44 unsigned long baseaddr;
45 spinlock_t lock;
46};
47
48static int m48t35_read_time(struct device *dev, struct rtc_time *tm)
49{
50 struct m48t35_priv *priv = dev_get_drvdata(dev);
51 u8 control;
52
53 /*
54 * Only the values that we read from the RTC are set. We leave
55 * tm_wday, tm_yday and tm_isdst untouched. Even though the
56 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
57 * by the RTC when initially set to a non-zero value.
58 */
59 spin_lock_irq(&priv->lock);
60 control = readb(&priv->reg->control);
61 writeb(control | M48T35_RTC_READ, &priv->reg->control);
62 tm->tm_sec = readb(&priv->reg->sec);
63 tm->tm_min = readb(&priv->reg->min);
64 tm->tm_hour = readb(&priv->reg->hour);
65 tm->tm_mday = readb(&priv->reg->date);
66 tm->tm_mon = readb(&priv->reg->month);
67 tm->tm_year = readb(&priv->reg->year);
68 writeb(control, &priv->reg->control);
69 spin_unlock_irq(&priv->lock);
70
71 tm->tm_sec = bcd2bin(tm->tm_sec);
72 tm->tm_min = bcd2bin(tm->tm_min);
73 tm->tm_hour = bcd2bin(tm->tm_hour);
74 tm->tm_mday = bcd2bin(tm->tm_mday);
75 tm->tm_mon = bcd2bin(tm->tm_mon);
76 tm->tm_year = bcd2bin(tm->tm_year);
77
78 /*
79 * Account for differences between how the RTC uses the values
80 * and how they are defined in a struct rtc_time;
81 */
82 tm->tm_year += 70;
83 if (tm->tm_year <= 69)
84 tm->tm_year += 100;
85
86 tm->tm_mon--;
87 return rtc_valid_tm(tm);
88}
89
90static int m48t35_set_time(struct device *dev, struct rtc_time *tm)
91{
92 struct m48t35_priv *priv = dev_get_drvdata(dev);
93 unsigned char mon, day, hrs, min, sec;
94 unsigned int yrs;
95 u8 control;
96
97 yrs = tm->tm_year + 1900;
98 mon = tm->tm_mon + 1; /* tm_mon starts at zero */
99 day = tm->tm_mday;
100 hrs = tm->tm_hour;
101 min = tm->tm_min;
102 sec = tm->tm_sec;
103
104 if (yrs < 1970)
105 return -EINVAL;
106
107 yrs -= 1970;
108 if (yrs > 255) /* They are unsigned */
109 return -EINVAL;
110
111 if (yrs > 169)
112 return -EINVAL;
113
114 if (yrs >= 100)
115 yrs -= 100;
116
117 sec = bin2bcd(sec);
118 min = bin2bcd(min);
119 hrs = bin2bcd(hrs);
120 day = bin2bcd(day);
121 mon = bin2bcd(mon);
122 yrs = bin2bcd(yrs);
123
124 spin_lock_irq(&priv->lock);
125 control = readb(&priv->reg->control);
126 writeb(control | M48T35_RTC_SET, &priv->reg->control);
127 writeb(yrs, &priv->reg->year);
128 writeb(mon, &priv->reg->month);
129 writeb(day, &priv->reg->date);
130 writeb(hrs, &priv->reg->hour);
131 writeb(min, &priv->reg->min);
132 writeb(sec, &priv->reg->sec);
133 writeb(control, &priv->reg->control);
134 spin_unlock_irq(&priv->lock);
135 return 0;
136}
137
138static const struct rtc_class_ops m48t35_ops = {
139 .read_time = m48t35_read_time,
140 .set_time = m48t35_set_time,
141};
142
143static int __devinit m48t35_probe(struct platform_device *pdev)
144{
145 struct rtc_device *rtc;
146 struct resource *res;
147 struct m48t35_priv *priv;
148 int ret = 0;
149
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res)
152 return -ENODEV;
153 priv = kzalloc(sizeof(struct m48t35_priv), GFP_KERNEL);
154 if (!priv)
155 return -ENOMEM;
156
157 priv->size = res->end - res->start + 1;
158 /*
159 * kludge: remove the #ifndef after ioc3 resource
160 * conflicts are resolved
161 */
162#ifndef CONFIG_SGI_IP27
163 if (!request_mem_region(res->start, priv->size, pdev->name)) {
164 ret = -EBUSY;
165 goto out;
166 }
167#endif
168 priv->baseaddr = res->start;
169 priv->reg = ioremap(priv->baseaddr, priv->size);
170 if (!priv->reg) {
171 ret = -ENOMEM;
172 goto out;
173 }
174 spin_lock_init(&priv->lock);
175 rtc = rtc_device_register("m48t35", &pdev->dev,
176 &m48t35_ops, THIS_MODULE);
177 if (IS_ERR(rtc)) {
178 ret = PTR_ERR(rtc);
179 goto out;
180 }
181 priv->rtc = rtc;
182 platform_set_drvdata(pdev, priv);
183 return 0;
184
185out:
186 if (priv->rtc)
187 rtc_device_unregister(priv->rtc);
188 if (priv->reg)
189 iounmap(priv->reg);
190 if (priv->baseaddr)
191 release_mem_region(priv->baseaddr, priv->size);
192 kfree(priv);
193 return ret;
194}
195
196static int __devexit m48t35_remove(struct platform_device *pdev)
197{
198 struct m48t35_priv *priv = platform_get_drvdata(pdev);
199
200 rtc_device_unregister(priv->rtc);
201 iounmap(priv->reg);
202#ifndef CONFIG_SGI_IP27
203 release_mem_region(priv->baseaddr, priv->size);
204#endif
205 kfree(priv);
206 return 0;
207}
208
209static struct platform_driver m48t35_platform_driver = {
210 .driver = {
211 .name = "rtc-m48t35",
212 .owner = THIS_MODULE,
213 },
214 .probe = m48t35_probe,
215 .remove = __devexit_p(m48t35_remove),
216};
217
218static int __init m48t35_init(void)
219{
220 return platform_driver_register(&m48t35_platform_driver);
221}
222
223static void __exit m48t35_exit(void)
224{
225 platform_driver_unregister(&m48t35_platform_driver);
226}
227
228MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
229MODULE_DESCRIPTION("M48T35 RTC driver");
230MODULE_LICENSE("GPL");
231MODULE_VERSION(DRV_VERSION);
232MODULE_ALIAS("platform:rtc-m48t35");
233
234module_init(m48t35_init);
235module_exit(m48t35_exit);
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index ce4eff6a8d51..04b63dab6932 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -76,10 +76,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
76 /* Issue the READ command */ 76 /* Issue the READ command */
77 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 77 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
78 78
79 tm->tm_year = BCD2BIN(M48T59_READ(M48T59_YEAR)); 79 tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
80 /* tm_mon is 0-11 */ 80 /* tm_mon is 0-11 */
81 tm->tm_mon = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1; 81 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
82 tm->tm_mday = BCD2BIN(M48T59_READ(M48T59_MDAY)); 82 tm->tm_mday = bcd2bin(M48T59_READ(M48T59_MDAY));
83 83
84 val = M48T59_READ(M48T59_WDAY); 84 val = M48T59_READ(M48T59_WDAY);
85 if ((pdata->type == M48T59RTC_TYPE_M48T59) && 85 if ((pdata->type == M48T59RTC_TYPE_M48T59) &&
@@ -88,10 +88,10 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
88 tm->tm_year += 100; /* one century */ 88 tm->tm_year += 100; /* one century */
89 } 89 }
90 90
91 tm->tm_wday = BCD2BIN(val & 0x07); 91 tm->tm_wday = bcd2bin(val & 0x07);
92 tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_HOUR) & 0x3F); 92 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F);
93 tm->tm_min = BCD2BIN(M48T59_READ(M48T59_MIN) & 0x7F); 93 tm->tm_min = bcd2bin(M48T59_READ(M48T59_MIN) & 0x7F);
94 tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_SEC) & 0x7F); 94 tm->tm_sec = bcd2bin(M48T59_READ(M48T59_SEC) & 0x7F);
95 95
96 /* Clear the READ bit */ 96 /* Clear the READ bit */
97 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 97 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
@@ -119,17 +119,17 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
119 /* Issue the WRITE command */ 119 /* Issue the WRITE command */
120 M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); 120 M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
121 121
122 M48T59_WRITE((BIN2BCD(tm->tm_sec) & 0x7F), M48T59_SEC); 122 M48T59_WRITE((bin2bcd(tm->tm_sec) & 0x7F), M48T59_SEC);
123 M48T59_WRITE((BIN2BCD(tm->tm_min) & 0x7F), M48T59_MIN); 123 M48T59_WRITE((bin2bcd(tm->tm_min) & 0x7F), M48T59_MIN);
124 M48T59_WRITE((BIN2BCD(tm->tm_hour) & 0x3F), M48T59_HOUR); 124 M48T59_WRITE((bin2bcd(tm->tm_hour) & 0x3F), M48T59_HOUR);
125 M48T59_WRITE((BIN2BCD(tm->tm_mday) & 0x3F), M48T59_MDAY); 125 M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY);
126 /* tm_mon is 0-11 */ 126 /* tm_mon is 0-11 */
127 M48T59_WRITE((BIN2BCD(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); 127 M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH);
128 M48T59_WRITE(BIN2BCD(tm->tm_year % 100), M48T59_YEAR); 128 M48T59_WRITE(bin2bcd(tm->tm_year % 100), M48T59_YEAR);
129 129
130 if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) 130 if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100))
131 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); 131 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB);
132 val |= (BIN2BCD(tm->tm_wday) & 0x07); 132 val |= (bin2bcd(tm->tm_wday) & 0x07);
133 M48T59_WRITE(val, M48T59_WDAY); 133 M48T59_WRITE(val, M48T59_WDAY);
134 134
135 /* Clear the WRITE bit */ 135 /* Clear the WRITE bit */
@@ -158,18 +158,18 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
158 /* Issue the READ command */ 158 /* Issue the READ command */
159 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 159 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
160 160
161 tm->tm_year = BCD2BIN(M48T59_READ(M48T59_YEAR)); 161 tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
162 /* tm_mon is 0-11 */ 162 /* tm_mon is 0-11 */
163 tm->tm_mon = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1; 163 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
164 164
165 val = M48T59_READ(M48T59_WDAY); 165 val = M48T59_READ(M48T59_WDAY);
166 if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) 166 if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB))
167 tm->tm_year += 100; /* one century */ 167 tm->tm_year += 100; /* one century */
168 168
169 tm->tm_mday = BCD2BIN(M48T59_READ(M48T59_ALARM_DATE)); 169 tm->tm_mday = bcd2bin(M48T59_READ(M48T59_ALARM_DATE));
170 tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_ALARM_HOUR)); 170 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_ALARM_HOUR));
171 tm->tm_min = BCD2BIN(M48T59_READ(M48T59_ALARM_MIN)); 171 tm->tm_min = bcd2bin(M48T59_READ(M48T59_ALARM_MIN));
172 tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_ALARM_SEC)); 172 tm->tm_sec = bcd2bin(M48T59_READ(M48T59_ALARM_SEC));
173 173
174 /* Clear the READ bit */ 174 /* Clear the READ bit */
175 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 175 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
@@ -201,18 +201,18 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
201 * 0xff means "always match" 201 * 0xff means "always match"
202 */ 202 */
203 mday = tm->tm_mday; 203 mday = tm->tm_mday;
204 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; 204 mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
205 if (mday == 0xff) 205 if (mday == 0xff)
206 mday = M48T59_READ(M48T59_MDAY); 206 mday = M48T59_READ(M48T59_MDAY);
207 207
208 hour = tm->tm_hour; 208 hour = tm->tm_hour;
209 hour = (hour < 24) ? BIN2BCD(hour) : 0x00; 209 hour = (hour < 24) ? bin2bcd(hour) : 0x00;
210 210
211 min = tm->tm_min; 211 min = tm->tm_min;
212 min = (min < 60) ? BIN2BCD(min) : 0x00; 212 min = (min < 60) ? bin2bcd(min) : 0x00;
213 213
214 sec = tm->tm_sec; 214 sec = tm->tm_sec;
215 sec = (sec < 60) ? BIN2BCD(sec) : 0x00; 215 sec = (sec < 60) ? bin2bcd(sec) : 0x00;
216 216
217 spin_lock_irqsave(&m48t59->lock, flags); 217 spin_lock_irqsave(&m48t59->lock, flags);
218 /* Issue the WRITE command */ 218 /* Issue the WRITE command */
@@ -360,7 +360,6 @@ static struct bin_attribute m48t59_nvram_attr = {
360 .attr = { 360 .attr = {
361 .name = "nvram", 361 .name = "nvram",
362 .mode = S_IRUGO | S_IWUSR, 362 .mode = S_IRUGO | S_IWUSR,
363 .owner = THIS_MODULE,
364 }, 363 },
365 .read = m48t59_nvram_read, 364 .read = m48t59_nvram_read,
366 .write = m48t59_nvram_write, 365 .write = m48t59_nvram_write,
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 3f7f99a5d96a..7c045cffa9ff 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -62,14 +62,14 @@ static int m48t86_rtc_read_time(struct device *dev, struct rtc_time *tm)
62 tm->tm_wday = ops->readbyte(M48T86_REG_DOW); 62 tm->tm_wday = ops->readbyte(M48T86_REG_DOW);
63 } else { 63 } else {
64 /* bcd mode */ 64 /* bcd mode */
65 tm->tm_sec = BCD2BIN(ops->readbyte(M48T86_REG_SEC)); 65 tm->tm_sec = bcd2bin(ops->readbyte(M48T86_REG_SEC));
66 tm->tm_min = BCD2BIN(ops->readbyte(M48T86_REG_MIN)); 66 tm->tm_min = bcd2bin(ops->readbyte(M48T86_REG_MIN));
67 tm->tm_hour = BCD2BIN(ops->readbyte(M48T86_REG_HOUR) & 0x3F); 67 tm->tm_hour = bcd2bin(ops->readbyte(M48T86_REG_HOUR) & 0x3F);
68 tm->tm_mday = BCD2BIN(ops->readbyte(M48T86_REG_DOM)); 68 tm->tm_mday = bcd2bin(ops->readbyte(M48T86_REG_DOM));
69 /* tm_mon is 0-11 */ 69 /* tm_mon is 0-11 */
70 tm->tm_mon = BCD2BIN(ops->readbyte(M48T86_REG_MONTH)) - 1; 70 tm->tm_mon = bcd2bin(ops->readbyte(M48T86_REG_MONTH)) - 1;
71 tm->tm_year = BCD2BIN(ops->readbyte(M48T86_REG_YEAR)) + 100; 71 tm->tm_year = bcd2bin(ops->readbyte(M48T86_REG_YEAR)) + 100;
72 tm->tm_wday = BCD2BIN(ops->readbyte(M48T86_REG_DOW)); 72 tm->tm_wday = bcd2bin(ops->readbyte(M48T86_REG_DOW));
73 } 73 }
74 74
75 /* correct the hour if the clock is in 12h mode */ 75 /* correct the hour if the clock is in 12h mode */
@@ -103,13 +103,13 @@ static int m48t86_rtc_set_time(struct device *dev, struct rtc_time *tm)
103 ops->writebyte(tm->tm_wday, M48T86_REG_DOW); 103 ops->writebyte(tm->tm_wday, M48T86_REG_DOW);
104 } else { 104 } else {
105 /* bcd mode */ 105 /* bcd mode */
106 ops->writebyte(BIN2BCD(tm->tm_sec), M48T86_REG_SEC); 106 ops->writebyte(bin2bcd(tm->tm_sec), M48T86_REG_SEC);
107 ops->writebyte(BIN2BCD(tm->tm_min), M48T86_REG_MIN); 107 ops->writebyte(bin2bcd(tm->tm_min), M48T86_REG_MIN);
108 ops->writebyte(BIN2BCD(tm->tm_hour), M48T86_REG_HOUR); 108 ops->writebyte(bin2bcd(tm->tm_hour), M48T86_REG_HOUR);
109 ops->writebyte(BIN2BCD(tm->tm_mday), M48T86_REG_DOM); 109 ops->writebyte(bin2bcd(tm->tm_mday), M48T86_REG_DOM);
110 ops->writebyte(BIN2BCD(tm->tm_mon + 1), M48T86_REG_MONTH); 110 ops->writebyte(bin2bcd(tm->tm_mon + 1), M48T86_REG_MONTH);
111 ops->writebyte(BIN2BCD(tm->tm_year % 100), M48T86_REG_YEAR); 111 ops->writebyte(bin2bcd(tm->tm_year % 100), M48T86_REG_YEAR);
112 ops->writebyte(BIN2BCD(tm->tm_wday), M48T86_REG_DOW); 112 ops->writebyte(bin2bcd(tm->tm_wday), M48T86_REG_DOW);
113 } 113 }
114 114
115 /* update ended */ 115 /* update ended */
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index ded3c0abad83..80782798763f 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -17,19 +17,18 @@
17#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19 19
20#define DRV_NAME "max6900" 20#define DRV_VERSION "0.2"
21#define DRV_VERSION "0.1"
22 21
23/* 22/*
24 * register indices 23 * register indices
25 */ 24 */
26#define MAX6900_REG_SC 0 /* seconds 00-59 */ 25#define MAX6900_REG_SC 0 /* seconds 00-59 */
27#define MAX6900_REG_MN 1 /* minutes 00-59 */ 26#define MAX6900_REG_MN 1 /* minutes 00-59 */
28#define MAX6900_REG_HR 2 /* hours 00-23 */ 27#define MAX6900_REG_HR 2 /* hours 00-23 */
29#define MAX6900_REG_DT 3 /* day of month 00-31 */ 28#define MAX6900_REG_DT 3 /* day of month 00-31 */
30#define MAX6900_REG_MO 4 /* month 01-12 */ 29#define MAX6900_REG_MO 4 /* month 01-12 */
31#define MAX6900_REG_DW 5 /* day of week 1-7 */ 30#define MAX6900_REG_DW 5 /* day of week 1-7 */
32#define MAX6900_REG_YR 6 /* year 00-99 */ 31#define MAX6900_REG_YR 6 /* year 00-99 */
33#define MAX6900_REG_CT 7 /* control */ 32#define MAX6900_REG_CT 7 /* control */
34 /* register 8 is undocumented */ 33 /* register 8 is undocumented */
35#define MAX6900_REG_CENTURY 9 /* century */ 34#define MAX6900_REG_CENTURY 9 /* century */
@@ -39,7 +38,6 @@
39 38
40#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */ 39#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
41 40
42
43/* 41/*
44 * register read/write commands 42 * register read/write commands
45 */ 43 */
@@ -52,16 +50,7 @@
52 50
53#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */ 51#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
54 52
55#define MAX6900_I2C_ADDR 0xa0 53static struct i2c_driver max6900_driver;
56
57static const unsigned short normal_i2c[] = {
58 MAX6900_I2C_ADDR >> 1,
59 I2C_CLIENT_END
60};
61
62I2C_CLIENT_INSMOD; /* defines addr_data */
63
64static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind);
65 54
66static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf) 55static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
67{ 56{
@@ -69,36 +58,35 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
69 u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ }; 58 u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ };
70 struct i2c_msg msgs[4] = { 59 struct i2c_msg msgs[4] = {
71 { 60 {
72 .addr = client->addr, 61 .addr = client->addr,
73 .flags = 0, /* write */ 62 .flags = 0, /* write */
74 .len = sizeof(reg_burst_read), 63 .len = sizeof(reg_burst_read),
75 .buf = reg_burst_read 64 .buf = reg_burst_read}
76 }, 65 ,
77 { 66 {
78 .addr = client->addr, 67 .addr = client->addr,
79 .flags = I2C_M_RD, 68 .flags = I2C_M_RD,
80 .len = MAX6900_BURST_LEN, 69 .len = MAX6900_BURST_LEN,
81 .buf = buf 70 .buf = buf}
82 }, 71 ,
83 { 72 {
84 .addr = client->addr, 73 .addr = client->addr,
85 .flags = 0, /* write */ 74 .flags = 0, /* write */
86 .len = sizeof(reg_century_read), 75 .len = sizeof(reg_century_read),
87 .buf = reg_century_read 76 .buf = reg_century_read}
88 }, 77 ,
89 { 78 {
90 .addr = client->addr, 79 .addr = client->addr,
91 .flags = I2C_M_RD, 80 .flags = I2C_M_RD,
92 .len = sizeof(buf[MAX6900_REG_CENTURY]), 81 .len = sizeof(buf[MAX6900_REG_CENTURY]),
93 .buf = &buf[MAX6900_REG_CENTURY] 82 .buf = &buf[MAX6900_REG_CENTURY]
94 } 83 }
95 }; 84 };
96 int rc; 85 int rc;
97 86
98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 87 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
99 if (rc != ARRAY_SIZE(msgs)) { 88 if (rc != ARRAY_SIZE(msgs)) {
100 dev_err(&client->dev, "%s: register read failed\n", 89 dev_err(&client->dev, "%s: register read failed\n", __func__);
101 __func__);
102 return -EIO; 90 return -EIO;
103 } 91 }
104 return 0; 92 return 0;
@@ -109,20 +97,18 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
109 u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE }; 97 u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE };
110 struct i2c_msg century_msgs[1] = { 98 struct i2c_msg century_msgs[1] = {
111 { 99 {
112 .addr = client->addr, 100 .addr = client->addr,
113 .flags = 0, /* write */ 101 .flags = 0, /* write */
114 .len = sizeof(i2c_century_buf), 102 .len = sizeof(i2c_century_buf),
115 .buf = i2c_century_buf 103 .buf = i2c_century_buf}
116 }
117 }; 104 };
118 u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE }; 105 u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
119 struct i2c_msg burst_msgs[1] = { 106 struct i2c_msg burst_msgs[1] = {
120 { 107 {
121 .addr = client->addr, 108 .addr = client->addr,
122 .flags = 0, /* write */ 109 .flags = 0, /* write */
123 .len = sizeof(i2c_burst_buf), 110 .len = sizeof(i2c_burst_buf),
124 .buf = i2c_burst_buf 111 .buf = i2c_burst_buf}
125 }
126 }; 112 };
127 int rc; 113 int rc;
128 114
@@ -133,10 +119,12 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
133 * bit as part of the burst write. 119 * bit as part of the burst write.
134 */ 120 */
135 i2c_century_buf[1] = buf[MAX6900_REG_CENTURY]; 121 i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
122
136 rc = i2c_transfer(client->adapter, century_msgs, 123 rc = i2c_transfer(client->adapter, century_msgs,
137 ARRAY_SIZE(century_msgs)); 124 ARRAY_SIZE(century_msgs));
138 if (rc != ARRAY_SIZE(century_msgs)) 125 if (rc != ARRAY_SIZE(century_msgs))
139 goto write_failed; 126 goto write_failed;
127
140 msleep(MAX6900_IDLE_TIME_AFTER_WRITE); 128 msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
141 129
142 memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN); 130 memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
@@ -148,45 +136,11 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
148 136
149 return 0; 137 return 0;
150 138
151write_failed: 139 write_failed:
152 dev_err(&client->dev, "%s: register write failed\n", 140 dev_err(&client->dev, "%s: register write failed\n", __func__);
153 __func__);
154 return -EIO; 141 return -EIO;
155} 142}
156 143
157static int max6900_i2c_validate_client(struct i2c_client *client)
158{
159 u8 regs[MAX6900_REG_LEN];
160 u8 zero_mask[] = {
161 0x80, /* seconds */
162 0x80, /* minutes */
163 0x40, /* hours */
164 0xc0, /* day of month */
165 0xe0, /* month */
166 0xf8, /* day of week */
167 0x00, /* year */
168 0x7f, /* control */
169 };
170 int i;
171 int rc;
172 int reserved;
173
174 reserved = i2c_smbus_read_byte_data(client, MAX6900_REG_RESERVED_READ);
175 if (reserved != 0x07)
176 return -ENODEV;
177
178 rc = max6900_i2c_read_regs(client, regs);
179 if (rc < 0)
180 return rc;
181
182 for (i = 0; i < ARRAY_SIZE(zero_mask); ++i) {
183 if (regs[i] & zero_mask[i])
184 return -ENODEV;
185 }
186
187 return 0;
188}
189
190static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 144static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
191{ 145{
192 int rc; 146 int rc;
@@ -196,14 +150,14 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
196 if (rc < 0) 150 if (rc < 0)
197 return rc; 151 return rc;
198 152
199 tm->tm_sec = BCD2BIN(regs[MAX6900_REG_SC]); 153 tm->tm_sec = bcd2bin(regs[MAX6900_REG_SC]);
200 tm->tm_min = BCD2BIN(regs[MAX6900_REG_MN]); 154 tm->tm_min = bcd2bin(regs[MAX6900_REG_MN]);
201 tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f); 155 tm->tm_hour = bcd2bin(regs[MAX6900_REG_HR] & 0x3f);
202 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]); 156 tm->tm_mday = bcd2bin(regs[MAX6900_REG_DT]);
203 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1; 157 tm->tm_mon = bcd2bin(regs[MAX6900_REG_MO]) - 1;
204 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + 158 tm->tm_year = bcd2bin(regs[MAX6900_REG_YR]) +
205 BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
206 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]); 160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]);
207 161
208 return 0; 162 return 0;
209} 163}
@@ -211,7 +165,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
211static int max6900_i2c_clear_write_protect(struct i2c_client *client) 165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
212{ 166{
213 int rc; 167 int rc;
214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0); 168 rc = i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0);
215 if (rc < 0) { 169 if (rc < 0) {
216 dev_err(&client->dev, "%s: control register write failed\n", 170 dev_err(&client->dev, "%s: control register write failed\n",
217 __func__); 171 __func__);
@@ -220,8 +174,8 @@ static int max6900_i2c_clear_write_protect(struct i2c_client *client)
220 return 0; 174 return 0;
221} 175}
222 176
223static int max6900_i2c_set_time(struct i2c_client *client, 177static int
224 struct rtc_time const *tm) 178max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
225{ 179{
226 u8 regs[MAX6900_REG_LEN]; 180 u8 regs[MAX6900_REG_LEN];
227 int rc; 181 int rc;
@@ -230,14 +184,14 @@ static int max6900_i2c_set_time(struct i2c_client *client,
230 if (rc < 0) 184 if (rc < 0)
231 return rc; 185 return rc;
232 186
233 regs[MAX6900_REG_SC] = BIN2BCD(tm->tm_sec); 187 regs[MAX6900_REG_SC] = bin2bcd(tm->tm_sec);
234 regs[MAX6900_REG_MN] = BIN2BCD(tm->tm_min); 188 regs[MAX6900_REG_MN] = bin2bcd(tm->tm_min);
235 regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour); 189 regs[MAX6900_REG_HR] = bin2bcd(tm->tm_hour);
236 regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday); 190 regs[MAX6900_REG_DT] = bin2bcd(tm->tm_mday);
237 regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1); 191 regs[MAX6900_REG_MO] = bin2bcd(tm->tm_mon + 1);
238 regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday); 192 regs[MAX6900_REG_DW] = bin2bcd(tm->tm_wday);
239 regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year % 100); 193 regs[MAX6900_REG_YR] = bin2bcd(tm->tm_year % 100);
240 regs[MAX6900_REG_CENTURY] = BIN2BCD((tm->tm_year + 1900) / 100); 194 regs[MAX6900_REG_CENTURY] = bin2bcd((tm->tm_year + 1900) / 100);
241 /* set write protect */ 195 /* set write protect */
242 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; 196 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP;
243 197
@@ -258,89 +212,49 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
258 return max6900_i2c_set_time(to_i2c_client(dev), tm); 212 return max6900_i2c_set_time(to_i2c_client(dev), tm);
259} 213}
260 214
261static int max6900_attach_adapter(struct i2c_adapter *adapter) 215static int max6900_remove(struct i2c_client *client)
262{
263 return i2c_probe(adapter, &addr_data, max6900_probe);
264}
265
266static int max6900_detach_client(struct i2c_client *client)
267{ 216{
268 struct rtc_device *const rtc = i2c_get_clientdata(client); 217 struct rtc_device *rtc = i2c_get_clientdata(client);
269 218
270 if (rtc) 219 if (rtc)
271 rtc_device_unregister(rtc); 220 rtc_device_unregister(rtc);
272 221
273 return i2c_detach_client(client); 222 return 0;
274} 223}
275 224
276static struct i2c_driver max6900_driver = {
277 .driver = {
278 .name = DRV_NAME,
279 },
280 .id = I2C_DRIVERID_MAX6900,
281 .attach_adapter = max6900_attach_adapter,
282 .detach_client = max6900_detach_client,
283};
284
285static const struct rtc_class_ops max6900_rtc_ops = { 225static const struct rtc_class_ops max6900_rtc_ops = {
286 .read_time = max6900_rtc_read_time, 226 .read_time = max6900_rtc_read_time,
287 .set_time = max6900_rtc_set_time, 227 .set_time = max6900_rtc_set_time,
288}; 228};
289 229
290static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind) 230static int
231max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
291{ 232{
292 int rc = 0; 233 struct rtc_device *rtc;
293 struct i2c_client *client = NULL;
294 struct rtc_device *rtc = NULL;
295
296 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
297 rc = -ENODEV;
298 goto failout;
299 }
300
301 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
302 if (client == NULL) {
303 rc = -ENOMEM;
304 goto failout;
305 }
306
307 client->addr = addr;
308 client->adapter = adapter;
309 client->driver = &max6900_driver;
310 strlcpy(client->name, DRV_NAME, I2C_NAME_SIZE);
311
312 if (kind < 0) {
313 rc = max6900_i2c_validate_client(client);
314 if (rc < 0)
315 goto failout;
316 }
317 234
318 rc = i2c_attach_client(client); 235 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
319 if (rc < 0) 236 return -ENODEV;
320 goto failout;
321 237
322 dev_info(&client->dev, 238 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
323 "chip found, driver version " DRV_VERSION "\n");
324 239
325 rtc = rtc_device_register(max6900_driver.driver.name, 240 rtc = rtc_device_register(max6900_driver.driver.name,
326 &client->dev, 241 &client->dev, &max6900_rtc_ops, THIS_MODULE);
327 &max6900_rtc_ops, THIS_MODULE); 242 if (IS_ERR(rtc))
328 if (IS_ERR(rtc)) { 243 return PTR_ERR(rtc);
329 rc = PTR_ERR(rtc);
330 goto failout_detach;
331 }
332 244
333 i2c_set_clientdata(client, rtc); 245 i2c_set_clientdata(client, rtc);
334 246
335 return 0; 247 return 0;
336
337failout_detach:
338 i2c_detach_client(client);
339failout:
340 kfree(client);
341 return rc;
342} 248}
343 249
250static struct i2c_driver max6900_driver = {
251 .driver = {
252 .name = "rtc-max6900",
253 },
254 .probe = max6900_probe,
255 .remove = max6900_remove,
256};
257
344static int __init max6900_init(void) 258static int __init max6900_init(void)
345{ 259{
346 return i2c_add_driver(&max6900_driver); 260 return i2c_add_driver(&max6900_driver);
@@ -352,6 +266,7 @@ static void __exit max6900_exit(void)
352} 266}
353 267
354MODULE_DESCRIPTION("Maxim MAX6900 RTC driver"); 268MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
269MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>");
355MODULE_LICENSE("GPL"); 270MODULE_LICENSE("GPL");
356MODULE_VERSION(DRV_VERSION); 271MODULE_VERSION(DRV_VERSION);
357 272
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 78b2551fb19d..2f6507df7b49 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -124,15 +124,15 @@ static int max6902_get_datetime(struct device *dev, struct rtc_time *dt)
124 124
125 /* The chip sends data in this order: 125 /* The chip sends data in this order:
126 * Seconds, Minutes, Hours, Date, Month, Day, Year */ 126 * Seconds, Minutes, Hours, Date, Month, Day, Year */
127 dt->tm_sec = BCD2BIN(chip->buf[1]); 127 dt->tm_sec = bcd2bin(chip->buf[1]);
128 dt->tm_min = BCD2BIN(chip->buf[2]); 128 dt->tm_min = bcd2bin(chip->buf[2]);
129 dt->tm_hour = BCD2BIN(chip->buf[3]); 129 dt->tm_hour = bcd2bin(chip->buf[3]);
130 dt->tm_mday = BCD2BIN(chip->buf[4]); 130 dt->tm_mday = bcd2bin(chip->buf[4]);
131 dt->tm_mon = BCD2BIN(chip->buf[5]) - 1; 131 dt->tm_mon = bcd2bin(chip->buf[5]) - 1;
132 dt->tm_wday = BCD2BIN(chip->buf[6]); 132 dt->tm_wday = bcd2bin(chip->buf[6]);
133 dt->tm_year = BCD2BIN(chip->buf[7]); 133 dt->tm_year = bcd2bin(chip->buf[7]);
134 134
135 century = BCD2BIN(tmp) * 100; 135 century = bcd2bin(tmp) * 100;
136 136
137 dt->tm_year += century; 137 dt->tm_year += century;
138 dt->tm_year -= 1900; 138 dt->tm_year -= 1900;
@@ -168,15 +168,15 @@ static int max6902_set_datetime(struct device *dev, struct rtc_time *dt)
168 /* Remove write protection */ 168 /* Remove write protection */
169 max6902_set_reg(dev, 0xF, 0); 169 max6902_set_reg(dev, 0xF, 0);
170 170
171 max6902_set_reg(dev, 0x01, BIN2BCD(dt->tm_sec)); 171 max6902_set_reg(dev, 0x01, bin2bcd(dt->tm_sec));
172 max6902_set_reg(dev, 0x03, BIN2BCD(dt->tm_min)); 172 max6902_set_reg(dev, 0x03, bin2bcd(dt->tm_min));
173 max6902_set_reg(dev, 0x05, BIN2BCD(dt->tm_hour)); 173 max6902_set_reg(dev, 0x05, bin2bcd(dt->tm_hour));
174 174
175 max6902_set_reg(dev, 0x07, BIN2BCD(dt->tm_mday)); 175 max6902_set_reg(dev, 0x07, bin2bcd(dt->tm_mday));
176 max6902_set_reg(dev, 0x09, BIN2BCD(dt->tm_mon+1)); 176 max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon+1));
177 max6902_set_reg(dev, 0x0B, BIN2BCD(dt->tm_wday)); 177 max6902_set_reg(dev, 0x0B, bin2bcd(dt->tm_wday));
178 max6902_set_reg(dev, 0x0D, BIN2BCD(dt->tm_year%100)); 178 max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year%100));
179 max6902_set_reg(dev, 0x13, BIN2BCD(dt->tm_year/100)); 179 max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year/100));
180 180
181 /* Compulab used a delay here. However, the datasheet 181 /* Compulab used a delay here. However, the datasheet
182 * does not mention a delay being required anywhere... */ 182 * does not mention a delay being required anywhere... */
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 8876605d4d4b..2cbeb0794f14 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -186,30 +186,30 @@ static int tm2bcd(struct rtc_time *tm)
186 if (rtc_valid_tm(tm) != 0) 186 if (rtc_valid_tm(tm) != 0)
187 return -EINVAL; 187 return -EINVAL;
188 188
189 tm->tm_sec = BIN2BCD(tm->tm_sec); 189 tm->tm_sec = bin2bcd(tm->tm_sec);
190 tm->tm_min = BIN2BCD(tm->tm_min); 190 tm->tm_min = bin2bcd(tm->tm_min);
191 tm->tm_hour = BIN2BCD(tm->tm_hour); 191 tm->tm_hour = bin2bcd(tm->tm_hour);
192 tm->tm_mday = BIN2BCD(tm->tm_mday); 192 tm->tm_mday = bin2bcd(tm->tm_mday);
193 193
194 tm->tm_mon = BIN2BCD(tm->tm_mon + 1); 194 tm->tm_mon = bin2bcd(tm->tm_mon + 1);
195 195
196 /* epoch == 1900 */ 196 /* epoch == 1900 */
197 if (tm->tm_year < 100 || tm->tm_year > 199) 197 if (tm->tm_year < 100 || tm->tm_year > 199)
198 return -EINVAL; 198 return -EINVAL;
199 tm->tm_year = BIN2BCD(tm->tm_year - 100); 199 tm->tm_year = bin2bcd(tm->tm_year - 100);
200 200
201 return 0; 201 return 0;
202} 202}
203 203
204static void bcd2tm(struct rtc_time *tm) 204static void bcd2tm(struct rtc_time *tm)
205{ 205{
206 tm->tm_sec = BCD2BIN(tm->tm_sec); 206 tm->tm_sec = bcd2bin(tm->tm_sec);
207 tm->tm_min = BCD2BIN(tm->tm_min); 207 tm->tm_min = bcd2bin(tm->tm_min);
208 tm->tm_hour = BCD2BIN(tm->tm_hour); 208 tm->tm_hour = bcd2bin(tm->tm_hour);
209 tm->tm_mday = BCD2BIN(tm->tm_mday); 209 tm->tm_mday = bcd2bin(tm->tm_mday);
210 tm->tm_mon = BCD2BIN(tm->tm_mon) - 1; 210 tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
211 /* epoch == 1900 */ 211 /* epoch == 1900 */
212 tm->tm_year = BCD2BIN(tm->tm_year) + 100; 212 tm->tm_year = bcd2bin(tm->tm_year) + 100;
213} 213}
214 214
215 215
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 748a502a6355..b725913ccbe8 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -97,13 +97,13 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
97 buf[8]); 97 buf[8]);
98 98
99 99
100 tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F); 100 tm->tm_sec = bcd2bin(buf[PCF8563_REG_SC] & 0x7F);
101 tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F); 101 tm->tm_min = bcd2bin(buf[PCF8563_REG_MN] & 0x7F);
102 tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */ 102 tm->tm_hour = bcd2bin(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */
103 tm->tm_mday = BCD2BIN(buf[PCF8563_REG_DM] & 0x3F); 103 tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F);
104 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07; 104 tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
105 tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */ 105 tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
106 tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR]); 106 tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]);
107 if (tm->tm_year < 70) 107 if (tm->tm_year < 70)
108 tm->tm_year += 100; /* assume we are in 1970...2069 */ 108 tm->tm_year += 100; /* assume we are in 1970...2069 */
109 /* detect the polarity heuristically. see note above. */ 109 /* detect the polarity heuristically. see note above. */
@@ -138,17 +138,17 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 138 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
139 139
140 /* hours, minutes and seconds */ 140 /* hours, minutes and seconds */
141 buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec); 141 buf[PCF8563_REG_SC] = bin2bcd(tm->tm_sec);
142 buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min); 142 buf[PCF8563_REG_MN] = bin2bcd(tm->tm_min);
143 buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour); 143 buf[PCF8563_REG_HR] = bin2bcd(tm->tm_hour);
144 144
145 buf[PCF8563_REG_DM] = BIN2BCD(tm->tm_mday); 145 buf[PCF8563_REG_DM] = bin2bcd(tm->tm_mday);
146 146
147 /* month, 1 - 12 */ 147 /* month, 1 - 12 */
148 buf[PCF8563_REG_MO] = BIN2BCD(tm->tm_mon + 1); 148 buf[PCF8563_REG_MO] = bin2bcd(tm->tm_mon + 1);
149 149
150 /* year and century */ 150 /* year and century */
151 buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100); 151 buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year % 100);
152 if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100)) 152 if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100))
153 buf[PCF8563_REG_MO] |= PCF8563_MO_C; 153 buf[PCF8563_REG_MO] |= PCF8563_MO_C;
154 154
@@ -179,58 +179,6 @@ struct pcf8563_limit
179 unsigned char max; 179 unsigned char max;
180}; 180};
181 181
182static int pcf8563_validate_client(struct i2c_client *client)
183{
184 int i;
185
186 static const struct pcf8563_limit pattern[] = {
187 /* register, mask, min, max */
188 { PCF8563_REG_SC, 0x7F, 0, 59 },
189 { PCF8563_REG_MN, 0x7F, 0, 59 },
190 { PCF8563_REG_HR, 0x3F, 0, 23 },
191 { PCF8563_REG_DM, 0x3F, 0, 31 },
192 { PCF8563_REG_MO, 0x1F, 0, 12 },
193 };
194
195 /* check limits (only registers with bcd values) */
196 for (i = 0; i < ARRAY_SIZE(pattern); i++) {
197 int xfer;
198 unsigned char value;
199 unsigned char buf = pattern[i].reg;
200
201 struct i2c_msg msgs[] = {
202 { client->addr, 0, 1, &buf },
203 { client->addr, I2C_M_RD, 1, &buf },
204 };
205
206 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
207
208 if (xfer != ARRAY_SIZE(msgs)) {
209 dev_err(&client->dev,
210 "%s: could not read register 0x%02X\n",
211 __func__, pattern[i].reg);
212
213 return -EIO;
214 }
215
216 value = BCD2BIN(buf & pattern[i].mask);
217
218 if (value > pattern[i].max ||
219 value < pattern[i].min) {
220 dev_dbg(&client->dev,
221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
222 "max=%d, value=%d, raw=0x%02X\n",
223 __func__, i, pattern[i].reg, pattern[i].mask,
224 pattern[i].min, pattern[i].max,
225 value, buf);
226
227 return -ENODEV;
228 }
229 }
230
231 return 0;
232}
233
234static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) 182static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
235{ 183{
236 return pcf8563_get_datetime(to_i2c_client(dev), tm); 184 return pcf8563_get_datetime(to_i2c_client(dev), tm);
@@ -262,12 +210,6 @@ static int pcf8563_probe(struct i2c_client *client,
262 if (!pcf8563) 210 if (!pcf8563)
263 return -ENOMEM; 211 return -ENOMEM;
264 212
265 /* Verify the chip is really an PCF8563 */
266 if (pcf8563_validate_client(client) < 0) {
267 err = -ENODEV;
268 goto exit_kfree;
269 }
270
271 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 213 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
272 214
273 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 215 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index d388c662bf4b..7d33cda3f8f6 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -76,11 +76,11 @@ static int pcf8583_get_datetime(struct i2c_client *client, struct rtc_time *dt)
76 buf[4] &= 0x3f; 76 buf[4] &= 0x3f;
77 buf[5] &= 0x1f; 77 buf[5] &= 0x1f;
78 78
79 dt->tm_sec = BCD2BIN(buf[1]); 79 dt->tm_sec = bcd2bin(buf[1]);
80 dt->tm_min = BCD2BIN(buf[2]); 80 dt->tm_min = bcd2bin(buf[2]);
81 dt->tm_hour = BCD2BIN(buf[3]); 81 dt->tm_hour = bcd2bin(buf[3]);
82 dt->tm_mday = BCD2BIN(buf[4]); 82 dt->tm_mday = bcd2bin(buf[4]);
83 dt->tm_mon = BCD2BIN(buf[5]) - 1; 83 dt->tm_mon = bcd2bin(buf[5]) - 1;
84 } 84 }
85 85
86 return ret == 2 ? 0 : -EIO; 86 return ret == 2 ? 0 : -EIO;
@@ -94,14 +94,14 @@ static int pcf8583_set_datetime(struct i2c_client *client, struct rtc_time *dt,
94 buf[0] = 0; 94 buf[0] = 0;
95 buf[1] = get_ctrl(client) | 0x80; 95 buf[1] = get_ctrl(client) | 0x80;
96 buf[2] = 0; 96 buf[2] = 0;
97 buf[3] = BIN2BCD(dt->tm_sec); 97 buf[3] = bin2bcd(dt->tm_sec);
98 buf[4] = BIN2BCD(dt->tm_min); 98 buf[4] = bin2bcd(dt->tm_min);
99 buf[5] = BIN2BCD(dt->tm_hour); 99 buf[5] = bin2bcd(dt->tm_hour);
100 100
101 if (datetoo) { 101 if (datetoo) {
102 len = 8; 102 len = 8;
103 buf[6] = BIN2BCD(dt->tm_mday) | (dt->tm_year << 6); 103 buf[6] = bin2bcd(dt->tm_mday) | (dt->tm_year << 6);
104 buf[7] = BIN2BCD(dt->tm_mon + 1) | (dt->tm_wday << 5); 104 buf[7] = bin2bcd(dt->tm_mon + 1) | (dt->tm_wday << 5);
105 } 105 }
106 106
107 ret = i2c_master_send(client, (char *)buf, len); 107 ret = i2c_master_send(client, (char *)buf, len);
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
index 8448eeb9d675..826153552157 100644
--- a/drivers/rtc/rtc-pl030.c
+++ b/drivers/rtc/rtc-pl030.c
@@ -34,15 +34,6 @@ static irqreturn_t pl030_interrupt(int irq, void *dev_id)
34 return IRQ_HANDLED; 34 return IRQ_HANDLED;
35} 35}
36 36
37static int pl030_open(struct device *dev)
38{
39 return 0;
40}
41
42static void pl030_release(struct device *dev)
43{
44}
45
46static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 37static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
47{ 38{
48 return -ENOIOCTLCMD; 39 return -ENOIOCTLCMD;
@@ -104,8 +95,6 @@ static int pl030_set_time(struct device *dev, struct rtc_time *tm)
104} 95}
105 96
106static const struct rtc_class_ops pl030_ops = { 97static const struct rtc_class_ops pl030_ops = {
107 .open = pl030_open,
108 .release = pl030_release,
109 .ioctl = pl030_ioctl, 98 .ioctl = pl030_ioctl,
110 .read_time = pl030_read_time, 99 .read_time = pl030_read_time,
111 .set_time = pl030_set_time, 100 .set_time = pl030_set_time,
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 08b4610ec5a6..333eec689d2f 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -45,18 +45,6 @@ static irqreturn_t pl031_interrupt(int irq, void *dev_id)
45 return IRQ_HANDLED; 45 return IRQ_HANDLED;
46} 46}
47 47
48static int pl031_open(struct device *dev)
49{
50 /*
51 * We request IRQ in pl031_probe, so nothing to do here...
52 */
53 return 0;
54}
55
56static void pl031_release(struct device *dev)
57{
58}
59
60static int pl031_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 48static int pl031_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
61{ 49{
62 struct pl031_local *ldata = dev_get_drvdata(dev); 50 struct pl031_local *ldata = dev_get_drvdata(dev);
@@ -118,8 +106,6 @@ static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
118} 106}
119 107
120static const struct rtc_class_ops pl031_ops = { 108static const struct rtc_class_ops pl031_ops = {
121 .open = pl031_open,
122 .release = pl031_release,
123 .ioctl = pl031_ioctl, 109 .ioctl = pl031_ioctl,
124 .read_time = pl031_read_time, 110 .read_time = pl031_read_time,
125 .set_time = pl031_set_time, 111 .set_time = pl031_set_time,
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 395985b339c9..42028f233bef 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -80,13 +80,13 @@ static int r9701_get_datetime(struct device *dev, struct rtc_time *dt)
80 80
81 memset(dt, 0, sizeof(*dt)); 81 memset(dt, 0, sizeof(*dt));
82 82
83 dt->tm_sec = BCD2BIN(buf[0]); /* RSECCNT */ 83 dt->tm_sec = bcd2bin(buf[0]); /* RSECCNT */
84 dt->tm_min = BCD2BIN(buf[1]); /* RMINCNT */ 84 dt->tm_min = bcd2bin(buf[1]); /* RMINCNT */
85 dt->tm_hour = BCD2BIN(buf[2]); /* RHRCNT */ 85 dt->tm_hour = bcd2bin(buf[2]); /* RHRCNT */
86 86
87 dt->tm_mday = BCD2BIN(buf[3]); /* RDAYCNT */ 87 dt->tm_mday = bcd2bin(buf[3]); /* RDAYCNT */
88 dt->tm_mon = BCD2BIN(buf[4]) - 1; /* RMONCNT */ 88 dt->tm_mon = bcd2bin(buf[4]) - 1; /* RMONCNT */
89 dt->tm_year = BCD2BIN(buf[5]) + 100; /* RYRCNT */ 89 dt->tm_year = bcd2bin(buf[5]) + 100; /* RYRCNT */
90 90
91 /* the rtc device may contain illegal values on power up 91 /* the rtc device may contain illegal values on power up
92 * according to the data sheet. make sure they are valid. 92 * according to the data sheet. make sure they are valid.
@@ -103,12 +103,12 @@ static int r9701_set_datetime(struct device *dev, struct rtc_time *dt)
103 if (year >= 2100 || year < 2000) 103 if (year >= 2100 || year < 2000)
104 return -EINVAL; 104 return -EINVAL;
105 105
106 ret = write_reg(dev, RHRCNT, BIN2BCD(dt->tm_hour)); 106 ret = write_reg(dev, RHRCNT, bin2bcd(dt->tm_hour));
107 ret = ret ? ret : write_reg(dev, RMINCNT, BIN2BCD(dt->tm_min)); 107 ret = ret ? ret : write_reg(dev, RMINCNT, bin2bcd(dt->tm_min));
108 ret = ret ? ret : write_reg(dev, RSECCNT, BIN2BCD(dt->tm_sec)); 108 ret = ret ? ret : write_reg(dev, RSECCNT, bin2bcd(dt->tm_sec));
109 ret = ret ? ret : write_reg(dev, RDAYCNT, BIN2BCD(dt->tm_mday)); 109 ret = ret ? ret : write_reg(dev, RDAYCNT, bin2bcd(dt->tm_mday));
110 ret = ret ? ret : write_reg(dev, RMONCNT, BIN2BCD(dt->tm_mon + 1)); 110 ret = ret ? ret : write_reg(dev, RMONCNT, bin2bcd(dt->tm_mon + 1));
111 ret = ret ? ret : write_reg(dev, RYRCNT, BIN2BCD(dt->tm_year - 100)); 111 ret = ret ? ret : write_reg(dev, RYRCNT, bin2bcd(dt->tm_year - 100));
112 ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday); 112 ret = ret ? ret : write_reg(dev, RWKCNT, 1 << dt->tm_wday);
113 113
114 return ret; 114 return ret;
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 1c14d4497c4d..e6ea3f5ee1eb 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -235,33 +235,33 @@ static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
235 235
236 data = rs5c313_read_reg(RS5C313_ADDR_SEC); 236 data = rs5c313_read_reg(RS5C313_ADDR_SEC);
237 data |= (rs5c313_read_reg(RS5C313_ADDR_SEC10) << 4); 237 data |= (rs5c313_read_reg(RS5C313_ADDR_SEC10) << 4);
238 tm->tm_sec = BCD2BIN(data); 238 tm->tm_sec = bcd2bin(data);
239 239
240 data = rs5c313_read_reg(RS5C313_ADDR_MIN); 240 data = rs5c313_read_reg(RS5C313_ADDR_MIN);
241 data |= (rs5c313_read_reg(RS5C313_ADDR_MIN10) << 4); 241 data |= (rs5c313_read_reg(RS5C313_ADDR_MIN10) << 4);
242 tm->tm_min = BCD2BIN(data); 242 tm->tm_min = bcd2bin(data);
243 243
244 data = rs5c313_read_reg(RS5C313_ADDR_HOUR); 244 data = rs5c313_read_reg(RS5C313_ADDR_HOUR);
245 data |= (rs5c313_read_reg(RS5C313_ADDR_HOUR10) << 4); 245 data |= (rs5c313_read_reg(RS5C313_ADDR_HOUR10) << 4);
246 tm->tm_hour = BCD2BIN(data); 246 tm->tm_hour = bcd2bin(data);
247 247
248 data = rs5c313_read_reg(RS5C313_ADDR_DAY); 248 data = rs5c313_read_reg(RS5C313_ADDR_DAY);
249 data |= (rs5c313_read_reg(RS5C313_ADDR_DAY10) << 4); 249 data |= (rs5c313_read_reg(RS5C313_ADDR_DAY10) << 4);
250 tm->tm_mday = BCD2BIN(data); 250 tm->tm_mday = bcd2bin(data);
251 251
252 data = rs5c313_read_reg(RS5C313_ADDR_MON); 252 data = rs5c313_read_reg(RS5C313_ADDR_MON);
253 data |= (rs5c313_read_reg(RS5C313_ADDR_MON10) << 4); 253 data |= (rs5c313_read_reg(RS5C313_ADDR_MON10) << 4);
254 tm->tm_mon = BCD2BIN(data) - 1; 254 tm->tm_mon = bcd2bin(data) - 1;
255 255
256 data = rs5c313_read_reg(RS5C313_ADDR_YEAR); 256 data = rs5c313_read_reg(RS5C313_ADDR_YEAR);
257 data |= (rs5c313_read_reg(RS5C313_ADDR_YEAR10) << 4); 257 data |= (rs5c313_read_reg(RS5C313_ADDR_YEAR10) << 4);
258 tm->tm_year = BCD2BIN(data); 258 tm->tm_year = bcd2bin(data);
259 259
260 if (tm->tm_year < 70) 260 if (tm->tm_year < 70)
261 tm->tm_year += 100; 261 tm->tm_year += 100;
262 262
263 data = rs5c313_read_reg(RS5C313_ADDR_WEEK); 263 data = rs5c313_read_reg(RS5C313_ADDR_WEEK);
264 tm->tm_wday = BCD2BIN(data); 264 tm->tm_wday = bcd2bin(data);
265 265
266 RS5C313_CEDISABLE; 266 RS5C313_CEDISABLE;
267 ndelay(700); /* CE:L */ 267 ndelay(700); /* CE:L */
@@ -294,31 +294,31 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
294 } 294 }
295 } 295 }
296 296
297 data = BIN2BCD(tm->tm_sec); 297 data = bin2bcd(tm->tm_sec);
298 rs5c313_write_reg(RS5C313_ADDR_SEC, data); 298 rs5c313_write_reg(RS5C313_ADDR_SEC, data);
299 rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4)); 299 rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4));
300 300
301 data = BIN2BCD(tm->tm_min); 301 data = bin2bcd(tm->tm_min);
302 rs5c313_write_reg(RS5C313_ADDR_MIN, data ); 302 rs5c313_write_reg(RS5C313_ADDR_MIN, data );
303 rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4)); 303 rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4));
304 304
305 data = BIN2BCD(tm->tm_hour); 305 data = bin2bcd(tm->tm_hour);
306 rs5c313_write_reg(RS5C313_ADDR_HOUR, data); 306 rs5c313_write_reg(RS5C313_ADDR_HOUR, data);
307 rs5c313_write_reg(RS5C313_ADDR_HOUR10, (data >> 4)); 307 rs5c313_write_reg(RS5C313_ADDR_HOUR10, (data >> 4));
308 308
309 data = BIN2BCD(tm->tm_mday); 309 data = bin2bcd(tm->tm_mday);
310 rs5c313_write_reg(RS5C313_ADDR_DAY, data); 310 rs5c313_write_reg(RS5C313_ADDR_DAY, data);
311 rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4)); 311 rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4));
312 312
313 data = BIN2BCD(tm->tm_mon + 1); 313 data = bin2bcd(tm->tm_mon + 1);
314 rs5c313_write_reg(RS5C313_ADDR_MON, data); 314 rs5c313_write_reg(RS5C313_ADDR_MON, data);
315 rs5c313_write_reg(RS5C313_ADDR_MON10, (data >> 4)); 315 rs5c313_write_reg(RS5C313_ADDR_MON10, (data >> 4));
316 316
317 data = BIN2BCD(tm->tm_year % 100); 317 data = bin2bcd(tm->tm_year % 100);
318 rs5c313_write_reg(RS5C313_ADDR_YEAR, data); 318 rs5c313_write_reg(RS5C313_ADDR_YEAR, data);
319 rs5c313_write_reg(RS5C313_ADDR_YEAR10, (data >> 4)); 319 rs5c313_write_reg(RS5C313_ADDR_YEAR10, (data >> 4));
320 320
321 data = BIN2BCD(tm->tm_wday); 321 data = bin2bcd(tm->tm_wday);
322 rs5c313_write_reg(RS5C313_ADDR_WEEK, data); 322 rs5c313_write_reg(RS5C313_ADDR_WEEK, data);
323 323
324 RS5C313_CEDISABLE; /* CE:H */ 324 RS5C313_CEDISABLE; /* CE:H */
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 839462659afa..dd1e2bc7a472 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -74,20 +74,20 @@ rs5c348_rtc_set_time(struct device *dev, struct rtc_time *tm)
74 txbuf[3] = 0; /* dummy */ 74 txbuf[3] = 0; /* dummy */
75 txbuf[4] = RS5C348_CMD_MW(RS5C348_REG_SECS); /* cmd, sec, ... */ 75 txbuf[4] = RS5C348_CMD_MW(RS5C348_REG_SECS); /* cmd, sec, ... */
76 txp = &txbuf[5]; 76 txp = &txbuf[5];
77 txp[RS5C348_REG_SECS] = BIN2BCD(tm->tm_sec); 77 txp[RS5C348_REG_SECS] = bin2bcd(tm->tm_sec);
78 txp[RS5C348_REG_MINS] = BIN2BCD(tm->tm_min); 78 txp[RS5C348_REG_MINS] = bin2bcd(tm->tm_min);
79 if (pdata->rtc_24h) { 79 if (pdata->rtc_24h) {
80 txp[RS5C348_REG_HOURS] = BIN2BCD(tm->tm_hour); 80 txp[RS5C348_REG_HOURS] = bin2bcd(tm->tm_hour);
81 } else { 81 } else {
82 /* hour 0 is AM12, noon is PM12 */ 82 /* hour 0 is AM12, noon is PM12 */
83 txp[RS5C348_REG_HOURS] = BIN2BCD((tm->tm_hour + 11) % 12 + 1) | 83 txp[RS5C348_REG_HOURS] = bin2bcd((tm->tm_hour + 11) % 12 + 1) |
84 (tm->tm_hour >= 12 ? RS5C348_BIT_PM : 0); 84 (tm->tm_hour >= 12 ? RS5C348_BIT_PM : 0);
85 } 85 }
86 txp[RS5C348_REG_WDAY] = BIN2BCD(tm->tm_wday); 86 txp[RS5C348_REG_WDAY] = bin2bcd(tm->tm_wday);
87 txp[RS5C348_REG_DAY] = BIN2BCD(tm->tm_mday); 87 txp[RS5C348_REG_DAY] = bin2bcd(tm->tm_mday);
88 txp[RS5C348_REG_MONTH] = BIN2BCD(tm->tm_mon + 1) | 88 txp[RS5C348_REG_MONTH] = bin2bcd(tm->tm_mon + 1) |
89 (tm->tm_year >= 100 ? RS5C348_BIT_Y2K : 0); 89 (tm->tm_year >= 100 ? RS5C348_BIT_Y2K : 0);
90 txp[RS5C348_REG_YEAR] = BIN2BCD(tm->tm_year % 100); 90 txp[RS5C348_REG_YEAR] = bin2bcd(tm->tm_year % 100);
91 /* write in one transfer to avoid data inconsistency */ 91 /* write in one transfer to avoid data inconsistency */
92 ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), NULL, 0); 92 ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), NULL, 0);
93 udelay(62); /* Tcsr 62us */ 93 udelay(62); /* Tcsr 62us */
@@ -116,20 +116,20 @@ rs5c348_rtc_read_time(struct device *dev, struct rtc_time *tm)
116 if (ret < 0) 116 if (ret < 0)
117 return ret; 117 return ret;
118 118
119 tm->tm_sec = BCD2BIN(rxbuf[RS5C348_REG_SECS] & RS5C348_SECS_MASK); 119 tm->tm_sec = bcd2bin(rxbuf[RS5C348_REG_SECS] & RS5C348_SECS_MASK);
120 tm->tm_min = BCD2BIN(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK); 120 tm->tm_min = bcd2bin(rxbuf[RS5C348_REG_MINS] & RS5C348_MINS_MASK);
121 tm->tm_hour = BCD2BIN(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK); 121 tm->tm_hour = bcd2bin(rxbuf[RS5C348_REG_HOURS] & RS5C348_HOURS_MASK);
122 if (!pdata->rtc_24h) { 122 if (!pdata->rtc_24h) {
123 tm->tm_hour %= 12; 123 tm->tm_hour %= 12;
124 if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM) 124 if (rxbuf[RS5C348_REG_HOURS] & RS5C348_BIT_PM)
125 tm->tm_hour += 12; 125 tm->tm_hour += 12;
126 } 126 }
127 tm->tm_wday = BCD2BIN(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK); 127 tm->tm_wday = bcd2bin(rxbuf[RS5C348_REG_WDAY] & RS5C348_WDAY_MASK);
128 tm->tm_mday = BCD2BIN(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK); 128 tm->tm_mday = bcd2bin(rxbuf[RS5C348_REG_DAY] & RS5C348_DAY_MASK);
129 tm->tm_mon = 129 tm->tm_mon =
130 BCD2BIN(rxbuf[RS5C348_REG_MONTH] & RS5C348_MONTH_MASK) - 1; 130 bcd2bin(rxbuf[RS5C348_REG_MONTH] & RS5C348_MONTH_MASK) - 1;
131 /* year is 1900 + tm->tm_year */ 131 /* year is 1900 + tm->tm_year */
132 tm->tm_year = BCD2BIN(rxbuf[RS5C348_REG_YEAR]) + 132 tm->tm_year = bcd2bin(rxbuf[RS5C348_REG_YEAR]) +
133 ((rxbuf[RS5C348_REG_MONTH] & RS5C348_BIT_Y2K) ? 100 : 0); 133 ((rxbuf[RS5C348_REG_MONTH] & RS5C348_BIT_Y2K) ? 100 : 0);
134 134
135 if (rtc_valid_tm(tm) < 0) { 135 if (rtc_valid_tm(tm) < 0) {
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 56caf6b2c3e5..2f2c68d476da 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * An I2C driver for Ricoh RS5C372 and RV5C38[67] RTCs 2 * An I2C driver for Ricoh RS5C372, R2025S/D and RV5C38[67] RTCs
3 * 3 *
4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net> 4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net>
5 * Copyright (C) 2006 Tower Technologies 5 * Copyright (C) 2006 Tower Technologies
6 * Copyright (C) 2008 Paul Mundt
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
@@ -13,7 +14,7 @@
13#include <linux/rtc.h> 14#include <linux/rtc.h>
14#include <linux/bcd.h> 15#include <linux/bcd.h>
15 16
16#define DRV_VERSION "0.5" 17#define DRV_VERSION "0.6"
17 18
18 19
19/* 20/*
@@ -51,7 +52,8 @@
51# define RS5C_CTRL1_CT4 (4 << 0) /* 1 Hz level irq */ 52# define RS5C_CTRL1_CT4 (4 << 0) /* 1 Hz level irq */
52#define RS5C_REG_CTRL2 15 53#define RS5C_REG_CTRL2 15
53# define RS5C372_CTRL2_24 (1 << 5) 54# define RS5C372_CTRL2_24 (1 << 5)
54# define RS5C_CTRL2_XSTP (1 << 4) 55# define R2025_CTRL2_XST (1 << 5)
56# define RS5C_CTRL2_XSTP (1 << 4) /* only if !R2025S/D */
55# define RS5C_CTRL2_CTFG (1 << 2) 57# define RS5C_CTRL2_CTFG (1 << 2)
56# define RS5C_CTRL2_AAFG (1 << 1) /* or WAFG */ 58# define RS5C_CTRL2_AAFG (1 << 1) /* or WAFG */
57# define RS5C_CTRL2_BAFG (1 << 0) /* or DAFG */ 59# define RS5C_CTRL2_BAFG (1 << 0) /* or DAFG */
@@ -63,6 +65,7 @@
63 65
64enum rtc_type { 66enum rtc_type {
65 rtc_undef = 0, 67 rtc_undef = 0,
68 rtc_r2025sd,
66 rtc_rs5c372a, 69 rtc_rs5c372a,
67 rtc_rs5c372b, 70 rtc_rs5c372b,
68 rtc_rv5c386, 71 rtc_rv5c386,
@@ -70,6 +73,7 @@ enum rtc_type {
70}; 73};
71 74
72static const struct i2c_device_id rs5c372_id[] = { 75static const struct i2c_device_id rs5c372_id[] = {
76 { "r2025sd", rtc_r2025sd },
73 { "rs5c372a", rtc_rs5c372a }, 77 { "rs5c372a", rtc_rs5c372a },
74 { "rs5c372b", rtc_rs5c372b }, 78 { "rs5c372b", rtc_rs5c372b },
75 { "rv5c386", rtc_rv5c386 }, 79 { "rv5c386", rtc_rv5c386 },
@@ -89,6 +93,7 @@ struct rs5c372 {
89 enum rtc_type type; 93 enum rtc_type type;
90 unsigned time24:1; 94 unsigned time24:1;
91 unsigned has_irq:1; 95 unsigned has_irq:1;
96 unsigned smbus:1;
92 char buf[17]; 97 char buf[17];
93 char *regs; 98 char *regs;
94}; 99};
@@ -106,10 +111,25 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
106 * 111 *
107 * The first method doesn't work with the iop3xx adapter driver, on at 112 * The first method doesn't work with the iop3xx adapter driver, on at
108 * least 80219 chips; this works around that bug. 113 * least 80219 chips; this works around that bug.
114 *
115 * The third method on the other hand doesn't work for the SMBus-only
116 * configurations, so we use the the first method there, stripping off
117 * the extra register in the process.
109 */ 118 */
110 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) { 119 if (rs5c->smbus) {
111 dev_warn(&client->dev, "can't read registers\n"); 120 int addr = RS5C_ADDR(RS5C372_REG_SECS);
112 return -EIO; 121 int size = sizeof(rs5c->buf) - 1;
122
123 if (i2c_smbus_read_i2c_block_data(client, addr, size,
124 rs5c->buf + 1) != size) {
125 dev_warn(&client->dev, "can't read registers\n");
126 return -EIO;
127 }
128 } else {
129 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
130 dev_warn(&client->dev, "can't read registers\n");
131 return -EIO;
132 }
113 } 133 }
114 134
115 dev_dbg(&client->dev, 135 dev_dbg(&client->dev,
@@ -128,9 +148,9 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
128 unsigned hour; 148 unsigned hour;
129 149
130 if (rs5c->time24) 150 if (rs5c->time24)
131 return BCD2BIN(reg & 0x3f); 151 return bcd2bin(reg & 0x3f);
132 152
133 hour = BCD2BIN(reg & 0x1f); 153 hour = bcd2bin(reg & 0x1f);
134 if (hour == 12) 154 if (hour == 12)
135 hour = 0; 155 hour = 0;
136 if (reg & 0x20) 156 if (reg & 0x20)
@@ -141,15 +161,15 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
141static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour) 161static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour)
142{ 162{
143 if (rs5c->time24) 163 if (rs5c->time24)
144 return BIN2BCD(hour); 164 return bin2bcd(hour);
145 165
146 if (hour > 12) 166 if (hour > 12)
147 return 0x20 | BIN2BCD(hour - 12); 167 return 0x20 | bin2bcd(hour - 12);
148 if (hour == 12) 168 if (hour == 12)
149 return 0x20 | BIN2BCD(12); 169 return 0x20 | bin2bcd(12);
150 if (hour == 0) 170 if (hour == 0)
151 return BIN2BCD(12); 171 return bin2bcd(12);
152 return BIN2BCD(hour); 172 return bin2bcd(hour);
153} 173}
154 174
155static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm) 175static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
@@ -160,18 +180,18 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
160 if (status < 0) 180 if (status < 0)
161 return status; 181 return status;
162 182
163 tm->tm_sec = BCD2BIN(rs5c->regs[RS5C372_REG_SECS] & 0x7f); 183 tm->tm_sec = bcd2bin(rs5c->regs[RS5C372_REG_SECS] & 0x7f);
164 tm->tm_min = BCD2BIN(rs5c->regs[RS5C372_REG_MINS] & 0x7f); 184 tm->tm_min = bcd2bin(rs5c->regs[RS5C372_REG_MINS] & 0x7f);
165 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); 185 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]);
166 186
167 tm->tm_wday = BCD2BIN(rs5c->regs[RS5C372_REG_WDAY] & 0x07); 187 tm->tm_wday = bcd2bin(rs5c->regs[RS5C372_REG_WDAY] & 0x07);
168 tm->tm_mday = BCD2BIN(rs5c->regs[RS5C372_REG_DAY] & 0x3f); 188 tm->tm_mday = bcd2bin(rs5c->regs[RS5C372_REG_DAY] & 0x3f);
169 189
170 /* tm->tm_mon is zero-based */ 190 /* tm->tm_mon is zero-based */
171 tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; 191 tm->tm_mon = bcd2bin(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1;
172 192
173 /* year is 1900 + tm->tm_year */ 193 /* year is 1900 + tm->tm_year */
174 tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100; 194 tm->tm_year = bcd2bin(rs5c->regs[RS5C372_REG_YEAR]) + 100;
175 195
176 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 196 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
177 "mday=%d, mon=%d, year=%d, wday=%d\n", 197 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -187,6 +207,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
187{ 207{
188 struct rs5c372 *rs5c = i2c_get_clientdata(client); 208 struct rs5c372 *rs5c = i2c_get_clientdata(client);
189 unsigned char buf[8]; 209 unsigned char buf[8];
210 int addr;
190 211
191 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 212 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d "
192 "mday=%d, mon=%d, year=%d, wday=%d\n", 213 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -194,16 +215,16 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
194 tm->tm_sec, tm->tm_min, tm->tm_hour, 215 tm->tm_sec, tm->tm_min, tm->tm_hour,
195 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 216 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
196 217
197 buf[0] = RS5C_ADDR(RS5C372_REG_SECS); 218 addr = RS5C_ADDR(RS5C372_REG_SECS);
198 buf[1] = BIN2BCD(tm->tm_sec); 219 buf[0] = bin2bcd(tm->tm_sec);
199 buf[2] = BIN2BCD(tm->tm_min); 220 buf[1] = bin2bcd(tm->tm_min);
200 buf[3] = rs5c_hr2reg(rs5c, tm->tm_hour); 221 buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour);
201 buf[4] = BIN2BCD(tm->tm_wday); 222 buf[3] = bin2bcd(tm->tm_wday);
202 buf[5] = BIN2BCD(tm->tm_mday); 223 buf[4] = bin2bcd(tm->tm_mday);
203 buf[6] = BIN2BCD(tm->tm_mon + 1); 224 buf[5] = bin2bcd(tm->tm_mon + 1);
204 buf[7] = BIN2BCD(tm->tm_year - 100); 225 buf[6] = bin2bcd(tm->tm_year - 100);
205 226
206 if ((i2c_master_send(client, buf, 8)) != 8) { 227 if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) {
207 dev_err(&client->dev, "%s: write error\n", __func__); 228 dev_err(&client->dev, "%s: write error\n", __func__);
208 return -EIO; 229 return -EIO;
209 } 230 }
@@ -266,16 +287,16 @@ rs5c_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
266{ 287{
267 struct i2c_client *client = to_i2c_client(dev); 288 struct i2c_client *client = to_i2c_client(dev);
268 struct rs5c372 *rs5c = i2c_get_clientdata(client); 289 struct rs5c372 *rs5c = i2c_get_clientdata(client);
269 unsigned char buf[2]; 290 unsigned char buf;
270 int status; 291 int status, addr;
271 292
272 buf[1] = rs5c->regs[RS5C_REG_CTRL1]; 293 buf = rs5c->regs[RS5C_REG_CTRL1];
273 switch (cmd) { 294 switch (cmd) {
274 case RTC_UIE_OFF: 295 case RTC_UIE_OFF:
275 case RTC_UIE_ON: 296 case RTC_UIE_ON:
276 /* some 327a modes use a different IRQ pin for 1Hz irqs */ 297 /* some 327a modes use a different IRQ pin for 1Hz irqs */
277 if (rs5c->type == rtc_rs5c372a 298 if (rs5c->type == rtc_rs5c372a
278 && (buf[1] & RS5C372A_CTRL1_SL1)) 299 && (buf & RS5C372A_CTRL1_SL1))
279 return -ENOIOCTLCMD; 300 return -ENOIOCTLCMD;
280 case RTC_AIE_OFF: 301 case RTC_AIE_OFF:
281 case RTC_AIE_ON: 302 case RTC_AIE_ON:
@@ -293,28 +314,30 @@ rs5c_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
293 if (status < 0) 314 if (status < 0)
294 return status; 315 return status;
295 316
296 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 317 addr = RS5C_ADDR(RS5C_REG_CTRL1);
297 switch (cmd) { 318 switch (cmd) {
298 case RTC_AIE_OFF: /* alarm off */ 319 case RTC_AIE_OFF: /* alarm off */
299 buf[1] &= ~RS5C_CTRL1_AALE; 320 buf &= ~RS5C_CTRL1_AALE;
300 break; 321 break;
301 case RTC_AIE_ON: /* alarm on */ 322 case RTC_AIE_ON: /* alarm on */
302 buf[1] |= RS5C_CTRL1_AALE; 323 buf |= RS5C_CTRL1_AALE;
303 break; 324 break;
304 case RTC_UIE_OFF: /* update off */ 325 case RTC_UIE_OFF: /* update off */
305 buf[1] &= ~RS5C_CTRL1_CT_MASK; 326 buf &= ~RS5C_CTRL1_CT_MASK;
306 break; 327 break;
307 case RTC_UIE_ON: /* update on */ 328 case RTC_UIE_ON: /* update on */
308 buf[1] &= ~RS5C_CTRL1_CT_MASK; 329 buf &= ~RS5C_CTRL1_CT_MASK;
309 buf[1] |= RS5C_CTRL1_CT4; 330 buf |= RS5C_CTRL1_CT4;
310 break; 331 break;
311 } 332 }
312 if ((i2c_master_send(client, buf, 2)) != 2) { 333
334 if (i2c_smbus_write_byte_data(client, addr, buf) < 0) {
313 printk(KERN_WARNING "%s: can't update alarm\n", 335 printk(KERN_WARNING "%s: can't update alarm\n",
314 rs5c->rtc->name); 336 rs5c->rtc->name);
315 status = -EIO; 337 status = -EIO;
316 } else 338 } else
317 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 339 rs5c->regs[RS5C_REG_CTRL1] = buf;
340
318 return status; 341 return status;
319} 342}
320 343
@@ -344,7 +367,7 @@ static int rs5c_read_alarm(struct device *dev, struct rtc_wkalrm *t)
344 367
345 /* report alarm time */ 368 /* report alarm time */
346 t->time.tm_sec = 0; 369 t->time.tm_sec = 0;
347 t->time.tm_min = BCD2BIN(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f); 370 t->time.tm_min = bcd2bin(rs5c->regs[RS5C_REG_ALARM_A_MIN] & 0x7f);
348 t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]); 371 t->time.tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C_REG_ALARM_A_HOURS]);
349 t->time.tm_mday = -1; 372 t->time.tm_mday = -1;
350 t->time.tm_mon = -1; 373 t->time.tm_mon = -1;
@@ -364,8 +387,8 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
364{ 387{
365 struct i2c_client *client = to_i2c_client(dev); 388 struct i2c_client *client = to_i2c_client(dev);
366 struct rs5c372 *rs5c = i2c_get_clientdata(client); 389 struct rs5c372 *rs5c = i2c_get_clientdata(client);
367 int status; 390 int status, addr, i;
368 unsigned char buf[4]; 391 unsigned char buf[3];
369 392
370 /* only handle up to 24 hours in the future, like RTC_ALM_SET */ 393 /* only handle up to 24 hours in the future, like RTC_ALM_SET */
371 if (t->time.tm_mday != -1 394 if (t->time.tm_mday != -1
@@ -380,33 +403,36 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
380 if (status < 0) 403 if (status < 0)
381 return status; 404 return status;
382 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) { 405 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) {
383 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 406 addr = RS5C_ADDR(RS5C_REG_CTRL1);
384 buf[1] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE; 407 buf[0] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE;
385 if (i2c_master_send(client, buf, 2) != 2) { 408 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0) {
386 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name); 409 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name);
387 return -EIO; 410 return -EIO;
388 } 411 }
389 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 412 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
390 } 413 }
391 414
392 /* set alarm */ 415 /* set alarm */
393 buf[0] = RS5C_ADDR(RS5C_REG_ALARM_A_MIN); 416 buf[0] = bin2bcd(t->time.tm_min);
394 buf[1] = BIN2BCD(t->time.tm_min); 417 buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour);
395 buf[2] = rs5c_hr2reg(rs5c, t->time.tm_hour); 418 buf[2] = 0x7f; /* any/all days */
396 buf[3] = 0x7f; /* any/all days */ 419
397 if ((i2c_master_send(client, buf, 4)) != 4) { 420 for (i = 0; i < sizeof(buf); i++) {
398 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name); 421 addr = RS5C_ADDR(RS5C_REG_ALARM_A_MIN + i);
399 return -EIO; 422 if (i2c_smbus_write_byte_data(client, addr, buf[i]) < 0) {
423 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name);
424 return -EIO;
425 }
400 } 426 }
401 427
402 /* ... and maybe enable its irq */ 428 /* ... and maybe enable its irq */
403 if (t->enabled) { 429 if (t->enabled) {
404 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 430 addr = RS5C_ADDR(RS5C_REG_CTRL1);
405 buf[1] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE; 431 buf[0] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE;
406 if ((i2c_master_send(client, buf, 2)) != 2) 432 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0)
407 printk(KERN_WARNING "%s: can't enable alarm\n", 433 printk(KERN_WARNING "%s: can't enable alarm\n",
408 rs5c->rtc->name); 434 rs5c->rtc->name);
409 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 435 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
410 } 436 }
411 437
412 return 0; 438 return 0;
@@ -503,18 +529,81 @@ static void rs5c_sysfs_unregister(struct device *dev)
503 529
504static struct i2c_driver rs5c372_driver; 530static struct i2c_driver rs5c372_driver;
505 531
532static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
533{
534 unsigned char buf[2];
535 int addr, i, ret = 0;
536
537 if (rs5c372->type == rtc_r2025sd) {
538 if (!(rs5c372->regs[RS5C_REG_CTRL2] & R2025_CTRL2_XST))
539 return ret;
540 rs5c372->regs[RS5C_REG_CTRL2] &= ~R2025_CTRL2_XST;
541 } else {
542 if (!(rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP))
543 return ret;
544 rs5c372->regs[RS5C_REG_CTRL2] &= ~RS5C_CTRL2_XSTP;
545 }
546
547 addr = RS5C_ADDR(RS5C_REG_CTRL1);
548 buf[0] = rs5c372->regs[RS5C_REG_CTRL1];
549 buf[1] = rs5c372->regs[RS5C_REG_CTRL2];
550
551 /* use 24hr mode */
552 switch (rs5c372->type) {
553 case rtc_rs5c372a:
554 case rtc_rs5c372b:
555 buf[1] |= RS5C372_CTRL2_24;
556 rs5c372->time24 = 1;
557 break;
558 case rtc_r2025sd:
559 case rtc_rv5c386:
560 case rtc_rv5c387a:
561 buf[0] |= RV5C387_CTRL1_24;
562 rs5c372->time24 = 1;
563 break;
564 default:
565 /* impossible */
566 break;
567 }
568
569 for (i = 0; i < sizeof(buf); i++) {
570 addr = RS5C_ADDR(RS5C_REG_CTRL1 + i);
571 ret = i2c_smbus_write_byte_data(rs5c372->client, addr, buf[i]);
572 if (unlikely(ret < 0))
573 return ret;
574 }
575
576 rs5c372->regs[RS5C_REG_CTRL1] = buf[0];
577 rs5c372->regs[RS5C_REG_CTRL2] = buf[1];
578
579 return 0;
580}
581
506static int rs5c372_probe(struct i2c_client *client, 582static int rs5c372_probe(struct i2c_client *client,
507 const struct i2c_device_id *id) 583 const struct i2c_device_id *id)
508{ 584{
509 int err = 0; 585 int err = 0;
586 int smbus_mode = 0;
510 struct rs5c372 *rs5c372; 587 struct rs5c372 *rs5c372;
511 struct rtc_time tm; 588 struct rtc_time tm;
512 589
513 dev_dbg(&client->dev, "%s\n", __func__); 590 dev_dbg(&client->dev, "%s\n", __func__);
514 591
515 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 592 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
516 err = -ENODEV; 593 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) {
517 goto exit; 594 /*
595 * If we don't have any master mode adapter, try breaking
596 * it down in to the barest of capabilities.
597 */
598 if (i2c_check_functionality(client->adapter,
599 I2C_FUNC_SMBUS_BYTE_DATA |
600 I2C_FUNC_SMBUS_I2C_BLOCK))
601 smbus_mode = 1;
602 else {
603 /* Still no good, give up */
604 err = -ENODEV;
605 goto exit;
606 }
518 } 607 }
519 608
520 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 609 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) {
@@ -528,6 +617,7 @@ static int rs5c372_probe(struct i2c_client *client,
528 617
529 /* we read registers 0x0f then 0x00-0x0f; skip the first one */ 618 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
530 rs5c372->regs = &rs5c372->buf[1]; 619 rs5c372->regs = &rs5c372->buf[1];
620 rs5c372->smbus = smbus_mode;
531 621
532 err = rs5c_get_regs(rs5c372); 622 err = rs5c_get_regs(rs5c372);
533 if (err < 0) 623 if (err < 0)
@@ -543,6 +633,7 @@ static int rs5c372_probe(struct i2c_client *client,
543 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24) 633 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24)
544 rs5c372->time24 = 1; 634 rs5c372->time24 = 1;
545 break; 635 break;
636 case rtc_r2025sd:
546 case rtc_rv5c386: 637 case rtc_rv5c386:
547 case rtc_rv5c387a: 638 case rtc_rv5c387a:
548 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24) 639 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24)
@@ -558,39 +649,14 @@ static int rs5c372_probe(struct i2c_client *client,
558 649
559 /* if the oscillator lost power and no other software (like 650 /* if the oscillator lost power and no other software (like
560 * the bootloader) set it up, do it here. 651 * the bootloader) set it up, do it here.
652 *
653 * The R2025S/D does this a little differently than the other
654 * parts, so we special case that..
561 */ 655 */
562 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP) { 656 err = rs5c_oscillator_setup(rs5c372);
563 unsigned char buf[3]; 657 if (unlikely(err < 0)) {
564 658 dev_err(&client->dev, "setup error\n");
565 rs5c372->regs[RS5C_REG_CTRL2] &= ~RS5C_CTRL2_XSTP; 659 goto exit_kfree;
566
567 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
568 buf[1] = rs5c372->regs[RS5C_REG_CTRL1];
569 buf[2] = rs5c372->regs[RS5C_REG_CTRL2];
570
571 /* use 24hr mode */
572 switch (rs5c372->type) {
573 case rtc_rs5c372a:
574 case rtc_rs5c372b:
575 buf[2] |= RS5C372_CTRL2_24;
576 rs5c372->time24 = 1;
577 break;
578 case rtc_rv5c386:
579 case rtc_rv5c387a:
580 buf[1] |= RV5C387_CTRL1_24;
581 rs5c372->time24 = 1;
582 break;
583 default:
584 /* impossible */
585 break;
586 }
587
588 if ((i2c_master_send(client, buf, 3)) != 3) {
589 dev_err(&client->dev, "setup error\n");
590 goto exit_kfree;
591 }
592 rs5c372->regs[RS5C_REG_CTRL1] = buf[1];
593 rs5c372->regs[RS5C_REG_CTRL2] = buf[2];
594 } 660 }
595 661
596 if (rs5c372_get_datetime(client, &tm) < 0) 662 if (rs5c372_get_datetime(client, &tm) < 0)
@@ -598,6 +664,7 @@ static int rs5c372_probe(struct i2c_client *client,
598 664
599 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n", 665 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n",
600 ({ char *s; switch (rs5c372->type) { 666 ({ char *s; switch (rs5c372->type) {
667 case rtc_r2025sd: s = "r2025sd"; break;
601 case rtc_rs5c372a: s = "rs5c372a"; break; 668 case rtc_rs5c372a: s = "rs5c372a"; break;
602 case rtc_rs5c372b: s = "rs5c372b"; break; 669 case rtc_rs5c372b: s = "rs5c372b"; break;
603 case rtc_rv5c386: s = "rv5c386"; break; 670 case rtc_rv5c386: s = "rv5c386"; break;
@@ -667,7 +734,8 @@ module_exit(rs5c372_exit);
667 734
668MODULE_AUTHOR( 735MODULE_AUTHOR(
669 "Pavel Mironchik <pmironchik@optifacio.net>, " 736 "Pavel Mironchik <pmironchik@optifacio.net>, "
670 "Alessandro Zummo <a.zummo@towertech.it>"); 737 "Alessandro Zummo <a.zummo@towertech.it>, "
738 "Paul Mundt <lethal@linux-sh.org>");
671MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver"); 739MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver");
672MODULE_LICENSE("GPL"); 740MODULE_LICENSE("GPL");
673MODULE_VERSION(DRV_VERSION); 741MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index a6fa1f2f2ca6..def4d396d0b0 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -104,12 +104,12 @@ static int s35390a_disable_test_mode(struct s35390a *s35390a)
104static char s35390a_hr2reg(struct s35390a *s35390a, int hour) 104static char s35390a_hr2reg(struct s35390a *s35390a, int hour)
105{ 105{
106 if (s35390a->twentyfourhour) 106 if (s35390a->twentyfourhour)
107 return BIN2BCD(hour); 107 return bin2bcd(hour);
108 108
109 if (hour < 12) 109 if (hour < 12)
110 return BIN2BCD(hour); 110 return bin2bcd(hour);
111 111
112 return 0x40 | BIN2BCD(hour - 12); 112 return 0x40 | bin2bcd(hour - 12);
113} 113}
114 114
115static int s35390a_reg2hr(struct s35390a *s35390a, char reg) 115static int s35390a_reg2hr(struct s35390a *s35390a, char reg)
@@ -117,9 +117,9 @@ static int s35390a_reg2hr(struct s35390a *s35390a, char reg)
117 unsigned hour; 117 unsigned hour;
118 118
119 if (s35390a->twentyfourhour) 119 if (s35390a->twentyfourhour)
120 return BCD2BIN(reg & 0x3f); 120 return bcd2bin(reg & 0x3f);
121 121
122 hour = BCD2BIN(reg & 0x3f); 122 hour = bcd2bin(reg & 0x3f);
123 if (reg & 0x40) 123 if (reg & 0x40)
124 hour += 12; 124 hour += 12;
125 125
@@ -137,13 +137,13 @@ static int s35390a_set_datetime(struct i2c_client *client, struct rtc_time *tm)
137 tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, 137 tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year,
138 tm->tm_wday); 138 tm->tm_wday);
139 139
140 buf[S35390A_BYTE_YEAR] = BIN2BCD(tm->tm_year - 100); 140 buf[S35390A_BYTE_YEAR] = bin2bcd(tm->tm_year - 100);
141 buf[S35390A_BYTE_MONTH] = BIN2BCD(tm->tm_mon + 1); 141 buf[S35390A_BYTE_MONTH] = bin2bcd(tm->tm_mon + 1);
142 buf[S35390A_BYTE_DAY] = BIN2BCD(tm->tm_mday); 142 buf[S35390A_BYTE_DAY] = bin2bcd(tm->tm_mday);
143 buf[S35390A_BYTE_WDAY] = BIN2BCD(tm->tm_wday); 143 buf[S35390A_BYTE_WDAY] = bin2bcd(tm->tm_wday);
144 buf[S35390A_BYTE_HOURS] = s35390a_hr2reg(s35390a, tm->tm_hour); 144 buf[S35390A_BYTE_HOURS] = s35390a_hr2reg(s35390a, tm->tm_hour);
145 buf[S35390A_BYTE_MINS] = BIN2BCD(tm->tm_min); 145 buf[S35390A_BYTE_MINS] = bin2bcd(tm->tm_min);
146 buf[S35390A_BYTE_SECS] = BIN2BCD(tm->tm_sec); 146 buf[S35390A_BYTE_SECS] = bin2bcd(tm->tm_sec);
147 147
148 /* This chip expects the bits of each byte to be in reverse order */ 148 /* This chip expects the bits of each byte to be in reverse order */
149 for (i = 0; i < 7; ++i) 149 for (i = 0; i < 7; ++i)
@@ -168,13 +168,13 @@ static int s35390a_get_datetime(struct i2c_client *client, struct rtc_time *tm)
168 for (i = 0; i < 7; ++i) 168 for (i = 0; i < 7; ++i)
169 buf[i] = bitrev8(buf[i]); 169 buf[i] = bitrev8(buf[i]);
170 170
171 tm->tm_sec = BCD2BIN(buf[S35390A_BYTE_SECS]); 171 tm->tm_sec = bcd2bin(buf[S35390A_BYTE_SECS]);
172 tm->tm_min = BCD2BIN(buf[S35390A_BYTE_MINS]); 172 tm->tm_min = bcd2bin(buf[S35390A_BYTE_MINS]);
173 tm->tm_hour = s35390a_reg2hr(s35390a, buf[S35390A_BYTE_HOURS]); 173 tm->tm_hour = s35390a_reg2hr(s35390a, buf[S35390A_BYTE_HOURS]);
174 tm->tm_wday = BCD2BIN(buf[S35390A_BYTE_WDAY]); 174 tm->tm_wday = bcd2bin(buf[S35390A_BYTE_WDAY]);
175 tm->tm_mday = BCD2BIN(buf[S35390A_BYTE_DAY]); 175 tm->tm_mday = bcd2bin(buf[S35390A_BYTE_DAY]);
176 tm->tm_mon = BCD2BIN(buf[S35390A_BYTE_MONTH]) - 1; 176 tm->tm_mon = bcd2bin(buf[S35390A_BYTE_MONTH]) - 1;
177 tm->tm_year = BCD2BIN(buf[S35390A_BYTE_YEAR]) + 100; 177 tm->tm_year = bcd2bin(buf[S35390A_BYTE_YEAR]) + 100;
178 178
179 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, mday=%d, " 179 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, mday=%d, "
180 "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec, 180 "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec,
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index e7d19b6c265a..910bc704939c 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -134,12 +134,12 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
134 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday, 134 rtc_tm->tm_year, rtc_tm->tm_mon, rtc_tm->tm_mday,
135 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec); 135 rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
136 136
137 BCD_TO_BIN(rtc_tm->tm_sec); 137 rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
138 BCD_TO_BIN(rtc_tm->tm_min); 138 rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
139 BCD_TO_BIN(rtc_tm->tm_hour); 139 rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
140 BCD_TO_BIN(rtc_tm->tm_mday); 140 rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
141 BCD_TO_BIN(rtc_tm->tm_mon); 141 rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
142 BCD_TO_BIN(rtc_tm->tm_year); 142 rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
143 143
144 rtc_tm->tm_year += 100; 144 rtc_tm->tm_year += 100;
145 rtc_tm->tm_mon -= 1; 145 rtc_tm->tm_mon -= 1;
@@ -163,12 +163,12 @@ static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
163 return -EINVAL; 163 return -EINVAL;
164 } 164 }
165 165
166 writeb(BIN2BCD(tm->tm_sec), base + S3C2410_RTCSEC); 166 writeb(bin2bcd(tm->tm_sec), base + S3C2410_RTCSEC);
167 writeb(BIN2BCD(tm->tm_min), base + S3C2410_RTCMIN); 167 writeb(bin2bcd(tm->tm_min), base + S3C2410_RTCMIN);
168 writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR); 168 writeb(bin2bcd(tm->tm_hour), base + S3C2410_RTCHOUR);
169 writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE); 169 writeb(bin2bcd(tm->tm_mday), base + S3C2410_RTCDATE);
170 writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON); 170 writeb(bin2bcd(tm->tm_mon + 1), base + S3C2410_RTCMON);
171 writeb(BIN2BCD(year), base + S3C2410_RTCYEAR); 171 writeb(bin2bcd(year), base + S3C2410_RTCYEAR);
172 172
173 return 0; 173 return 0;
174} 174}
@@ -199,34 +199,34 @@ static int s3c_rtc_getalarm(struct device *dev, struct rtc_wkalrm *alrm)
199 /* decode the alarm enable field */ 199 /* decode the alarm enable field */
200 200
201 if (alm_en & S3C2410_RTCALM_SECEN) 201 if (alm_en & S3C2410_RTCALM_SECEN)
202 BCD_TO_BIN(alm_tm->tm_sec); 202 alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
203 else 203 else
204 alm_tm->tm_sec = 0xff; 204 alm_tm->tm_sec = 0xff;
205 205
206 if (alm_en & S3C2410_RTCALM_MINEN) 206 if (alm_en & S3C2410_RTCALM_MINEN)
207 BCD_TO_BIN(alm_tm->tm_min); 207 alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
208 else 208 else
209 alm_tm->tm_min = 0xff; 209 alm_tm->tm_min = 0xff;
210 210
211 if (alm_en & S3C2410_RTCALM_HOUREN) 211 if (alm_en & S3C2410_RTCALM_HOUREN)
212 BCD_TO_BIN(alm_tm->tm_hour); 212 alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
213 else 213 else
214 alm_tm->tm_hour = 0xff; 214 alm_tm->tm_hour = 0xff;
215 215
216 if (alm_en & S3C2410_RTCALM_DAYEN) 216 if (alm_en & S3C2410_RTCALM_DAYEN)
217 BCD_TO_BIN(alm_tm->tm_mday); 217 alm_tm->tm_mday = bcd2bin(alm_tm->tm_mday);
218 else 218 else
219 alm_tm->tm_mday = 0xff; 219 alm_tm->tm_mday = 0xff;
220 220
221 if (alm_en & S3C2410_RTCALM_MONEN) { 221 if (alm_en & S3C2410_RTCALM_MONEN) {
222 BCD_TO_BIN(alm_tm->tm_mon); 222 alm_tm->tm_mon = bcd2bin(alm_tm->tm_mon);
223 alm_tm->tm_mon -= 1; 223 alm_tm->tm_mon -= 1;
224 } else { 224 } else {
225 alm_tm->tm_mon = 0xff; 225 alm_tm->tm_mon = 0xff;
226 } 226 }
227 227
228 if (alm_en & S3C2410_RTCALM_YEAREN) 228 if (alm_en & S3C2410_RTCALM_YEAREN)
229 BCD_TO_BIN(alm_tm->tm_year); 229 alm_tm->tm_year = bcd2bin(alm_tm->tm_year);
230 else 230 else
231 alm_tm->tm_year = 0xffff; 231 alm_tm->tm_year = 0xffff;
232 232
@@ -250,17 +250,17 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
250 250
251 if (tm->tm_sec < 60 && tm->tm_sec >= 0) { 251 if (tm->tm_sec < 60 && tm->tm_sec >= 0) {
252 alrm_en |= S3C2410_RTCALM_SECEN; 252 alrm_en |= S3C2410_RTCALM_SECEN;
253 writeb(BIN2BCD(tm->tm_sec), base + S3C2410_ALMSEC); 253 writeb(bin2bcd(tm->tm_sec), base + S3C2410_ALMSEC);
254 } 254 }
255 255
256 if (tm->tm_min < 60 && tm->tm_min >= 0) { 256 if (tm->tm_min < 60 && tm->tm_min >= 0) {
257 alrm_en |= S3C2410_RTCALM_MINEN; 257 alrm_en |= S3C2410_RTCALM_MINEN;
258 writeb(BIN2BCD(tm->tm_min), base + S3C2410_ALMMIN); 258 writeb(bin2bcd(tm->tm_min), base + S3C2410_ALMMIN);
259 } 259 }
260 260
261 if (tm->tm_hour < 24 && tm->tm_hour >= 0) { 261 if (tm->tm_hour < 24 && tm->tm_hour >= 0) {
262 alrm_en |= S3C2410_RTCALM_HOUREN; 262 alrm_en |= S3C2410_RTCALM_HOUREN;
263 writeb(BIN2BCD(tm->tm_hour), base + S3C2410_ALMHOUR); 263 writeb(bin2bcd(tm->tm_hour), base + S3C2410_ALMHOUR);
264 } 264 }
265 265
266 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en); 266 pr_debug("setting S3C2410_RTCALM to %08x\n", alrm_en);
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 1f88e9e914ec..aaf9d6a337cc 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -257,12 +257,6 @@ static inline void sh_rtc_setaie(struct device *dev, unsigned int enable)
257 spin_unlock_irq(&rtc->lock); 257 spin_unlock_irq(&rtc->lock);
258} 258}
259 259
260static void sh_rtc_release(struct device *dev)
261{
262 sh_rtc_setpie(dev, 0);
263 sh_rtc_setaie(dev, 0);
264}
265
266static int sh_rtc_proc(struct device *dev, struct seq_file *seq) 260static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
267{ 261{
268 struct sh_rtc *rtc = dev_get_drvdata(dev); 262 struct sh_rtc *rtc = dev_get_drvdata(dev);
@@ -330,23 +324,23 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
330 324
331 sec128 = readb(rtc->regbase + R64CNT); 325 sec128 = readb(rtc->regbase + R64CNT);
332 326
333 tm->tm_sec = BCD2BIN(readb(rtc->regbase + RSECCNT)); 327 tm->tm_sec = bcd2bin(readb(rtc->regbase + RSECCNT));
334 tm->tm_min = BCD2BIN(readb(rtc->regbase + RMINCNT)); 328 tm->tm_min = bcd2bin(readb(rtc->regbase + RMINCNT));
335 tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); 329 tm->tm_hour = bcd2bin(readb(rtc->regbase + RHRCNT));
336 tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); 330 tm->tm_wday = bcd2bin(readb(rtc->regbase + RWKCNT));
337 tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); 331 tm->tm_mday = bcd2bin(readb(rtc->regbase + RDAYCNT));
338 tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)) - 1; 332 tm->tm_mon = bcd2bin(readb(rtc->regbase + RMONCNT)) - 1;
339 333
340 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { 334 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
341 yr = readw(rtc->regbase + RYRCNT); 335 yr = readw(rtc->regbase + RYRCNT);
342 yr100 = BCD2BIN(yr >> 8); 336 yr100 = bcd2bin(yr >> 8);
343 yr &= 0xff; 337 yr &= 0xff;
344 } else { 338 } else {
345 yr = readb(rtc->regbase + RYRCNT); 339 yr = readb(rtc->regbase + RYRCNT);
346 yr100 = BCD2BIN((yr == 0x99) ? 0x19 : 0x20); 340 yr100 = bcd2bin((yr == 0x99) ? 0x19 : 0x20);
347 } 341 }
348 342
349 tm->tm_year = (yr100 * 100 + BCD2BIN(yr)) - 1900; 343 tm->tm_year = (yr100 * 100 + bcd2bin(yr)) - 1900;
350 344
351 sec2 = readb(rtc->regbase + R64CNT); 345 sec2 = readb(rtc->regbase + R64CNT);
352 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF; 346 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF;
@@ -388,20 +382,20 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
388 tmp &= ~RCR2_START; 382 tmp &= ~RCR2_START;
389 writeb(tmp, rtc->regbase + RCR2); 383 writeb(tmp, rtc->regbase + RCR2);
390 384
391 writeb(BIN2BCD(tm->tm_sec), rtc->regbase + RSECCNT); 385 writeb(bin2bcd(tm->tm_sec), rtc->regbase + RSECCNT);
392 writeb(BIN2BCD(tm->tm_min), rtc->regbase + RMINCNT); 386 writeb(bin2bcd(tm->tm_min), rtc->regbase + RMINCNT);
393 writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); 387 writeb(bin2bcd(tm->tm_hour), rtc->regbase + RHRCNT);
394 writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); 388 writeb(bin2bcd(tm->tm_wday), rtc->regbase + RWKCNT);
395 writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); 389 writeb(bin2bcd(tm->tm_mday), rtc->regbase + RDAYCNT);
396 writeb(BIN2BCD(tm->tm_mon + 1), rtc->regbase + RMONCNT); 390 writeb(bin2bcd(tm->tm_mon + 1), rtc->regbase + RMONCNT);
397 391
398 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { 392 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
399 year = (BIN2BCD((tm->tm_year + 1900) / 100) << 8) | 393 year = (bin2bcd((tm->tm_year + 1900) / 100) << 8) |
400 BIN2BCD(tm->tm_year % 100); 394 bin2bcd(tm->tm_year % 100);
401 writew(year, rtc->regbase + RYRCNT); 395 writew(year, rtc->regbase + RYRCNT);
402 } else { 396 } else {
403 year = tm->tm_year % 100; 397 year = tm->tm_year % 100;
404 writeb(BIN2BCD(year), rtc->regbase + RYRCNT); 398 writeb(bin2bcd(year), rtc->regbase + RYRCNT);
405 } 399 }
406 400
407 /* Start RTC */ 401 /* Start RTC */
@@ -423,7 +417,7 @@ static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off)
423 byte = readb(rtc->regbase + reg_off); 417 byte = readb(rtc->regbase + reg_off);
424 if (byte & AR_ENB) { 418 if (byte & AR_ENB) {
425 byte &= ~AR_ENB; /* strip the enable bit */ 419 byte &= ~AR_ENB; /* strip the enable bit */
426 value = BCD2BIN(byte); 420 value = bcd2bin(byte);
427 } 421 }
428 422
429 return value; 423 return value;
@@ -461,7 +455,7 @@ static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc,
461 if (value < 0) 455 if (value < 0)
462 writeb(0, rtc->regbase + reg_off); 456 writeb(0, rtc->regbase + reg_off);
463 else 457 else
464 writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off); 458 writeb(bin2bcd(value) | AR_ENB, rtc->regbase + reg_off);
465} 459}
466 460
467static int sh_rtc_check_alarm(struct rtc_time *tm) 461static int sh_rtc_check_alarm(struct rtc_time *tm)
@@ -559,7 +553,6 @@ static int sh_rtc_irq_set_freq(struct device *dev, int freq)
559} 553}
560 554
561static struct rtc_class_ops sh_rtc_ops = { 555static struct rtc_class_ops sh_rtc_ops = {
562 .release = sh_rtc_release,
563 .ioctl = sh_rtc_ioctl, 556 .ioctl = sh_rtc_ioctl,
564 .read_time = sh_rtc_read_time, 557 .read_time = sh_rtc_read_time,
565 .set_time = sh_rtc_set_time, 558 .set_time = sh_rtc_set_time,
@@ -575,7 +568,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
575 struct sh_rtc *rtc; 568 struct sh_rtc *rtc;
576 struct resource *res; 569 struct resource *res;
577 unsigned int tmp; 570 unsigned int tmp;
578 int ret = -ENOENT; 571 int ret;
579 572
580 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); 573 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL);
581 if (unlikely(!rtc)) 574 if (unlikely(!rtc))
@@ -584,26 +577,33 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
584 spin_lock_init(&rtc->lock); 577 spin_lock_init(&rtc->lock);
585 578
586 /* get periodic/carry/alarm irqs */ 579 /* get periodic/carry/alarm irqs */
587 rtc->periodic_irq = platform_get_irq(pdev, 0); 580 ret = platform_get_irq(pdev, 0);
588 if (unlikely(rtc->periodic_irq < 0)) { 581 if (unlikely(ret < 0)) {
582 ret = -ENOENT;
589 dev_err(&pdev->dev, "No IRQ for period\n"); 583 dev_err(&pdev->dev, "No IRQ for period\n");
590 goto err_badres; 584 goto err_badres;
591 } 585 }
586 rtc->periodic_irq = ret;
592 587
593 rtc->carry_irq = platform_get_irq(pdev, 1); 588 ret = platform_get_irq(pdev, 1);
594 if (unlikely(rtc->carry_irq < 0)) { 589 if (unlikely(ret < 0)) {
590 ret = -ENOENT;
595 dev_err(&pdev->dev, "No IRQ for carry\n"); 591 dev_err(&pdev->dev, "No IRQ for carry\n");
596 goto err_badres; 592 goto err_badres;
597 } 593 }
594 rtc->carry_irq = ret;
598 595
599 rtc->alarm_irq = platform_get_irq(pdev, 2); 596 ret = platform_get_irq(pdev, 2);
600 if (unlikely(rtc->alarm_irq < 0)) { 597 if (unlikely(ret < 0)) {
598 ret = -ENOENT;
601 dev_err(&pdev->dev, "No IRQ for alarm\n"); 599 dev_err(&pdev->dev, "No IRQ for alarm\n");
602 goto err_badres; 600 goto err_badres;
603 } 601 }
602 rtc->alarm_irq = ret;
604 603
605 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 604 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
606 if (unlikely(res == NULL)) { 605 if (unlikely(res == NULL)) {
606 ret = -ENOENT;
607 dev_err(&pdev->dev, "No IO resource\n"); 607 dev_err(&pdev->dev, "No IO resource\n");
608 goto err_badres; 608 goto err_badres;
609 } 609 }
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 31d3c8c28588..f4cd46e15af9 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -82,14 +82,14 @@ static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm)
82 flags = readb(pdata->ioaddr + RTC_FLAGS); 82 flags = readb(pdata->ioaddr + RTC_FLAGS);
83 writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS); 83 writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
84 84
85 writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR); 85 writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR);
86 writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH); 86 writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH);
87 writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY); 87 writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY);
88 writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE); 88 writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE);
89 writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS); 89 writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS);
90 writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES); 90 writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES);
91 writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS); 91 writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS);
92 writeb(BIN2BCD((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY); 92 writeb(bin2bcd((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY);
93 93
94 writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS); 94 writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
95 return 0; 95 return 0;
@@ -120,14 +120,14 @@ static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm)
120 year = readb(ioaddr + RTC_YEAR); 120 year = readb(ioaddr + RTC_YEAR);
121 century = readb(ioaddr + RTC_CENTURY); 121 century = readb(ioaddr + RTC_CENTURY);
122 writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS); 122 writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS);
123 tm->tm_sec = BCD2BIN(second); 123 tm->tm_sec = bcd2bin(second);
124 tm->tm_min = BCD2BIN(minute); 124 tm->tm_min = bcd2bin(minute);
125 tm->tm_hour = BCD2BIN(hour); 125 tm->tm_hour = bcd2bin(hour);
126 tm->tm_mday = BCD2BIN(day); 126 tm->tm_mday = bcd2bin(day);
127 tm->tm_wday = BCD2BIN(week); 127 tm->tm_wday = bcd2bin(week);
128 tm->tm_mon = BCD2BIN(month) - 1; 128 tm->tm_mon = bcd2bin(month) - 1;
129 /* year is 1900 + tm->tm_year */ 129 /* year is 1900 + tm->tm_year */
130 tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900; 130 tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900;
131 131
132 if (rtc_valid_tm(tm) < 0) { 132 if (rtc_valid_tm(tm) < 0) {
133 dev_err(dev, "retrieved date/time is not valid.\n"); 133 dev_err(dev, "retrieved date/time is not valid.\n");
@@ -148,16 +148,16 @@ static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata)
148 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS); 148 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
149 149
150 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ? 150 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
151 0x80 : BIN2BCD(pdata->alrm_mday), 151 0x80 : bin2bcd(pdata->alrm_mday),
152 ioaddr + RTC_DATE_ALARM); 152 ioaddr + RTC_DATE_ALARM);
153 writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ? 153 writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
154 0x80 : BIN2BCD(pdata->alrm_hour), 154 0x80 : bin2bcd(pdata->alrm_hour),
155 ioaddr + RTC_HOURS_ALARM); 155 ioaddr + RTC_HOURS_ALARM);
156 writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ? 156 writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
157 0x80 : BIN2BCD(pdata->alrm_min), 157 0x80 : bin2bcd(pdata->alrm_min),
158 ioaddr + RTC_MINUTES_ALARM); 158 ioaddr + RTC_MINUTES_ALARM);
159 writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ? 159 writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
160 0x80 : BIN2BCD(pdata->alrm_sec), 160 0x80 : bin2bcd(pdata->alrm_sec),
161 ioaddr + RTC_SECONDS_ALARM); 161 ioaddr + RTC_SECONDS_ALARM);
162 writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS); 162 writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS);
163 readb(ioaddr + RTC_FLAGS); /* clear interrupts */ 163 readb(ioaddr + RTC_FLAGS); /* clear interrupts */
@@ -215,17 +215,6 @@ static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id)
215 return IRQ_HANDLED; 215 return IRQ_HANDLED;
216} 216}
217 217
218static void stk17ta8_rtc_release(struct device *dev)
219{
220 struct platform_device *pdev = to_platform_device(dev);
221 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
222
223 if (pdata->irq >= 0) {
224 pdata->irqen = 0;
225 stk17ta8_rtc_update_alarm(pdata);
226 }
227}
228
229static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd, 218static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd,
230 unsigned long arg) 219 unsigned long arg)
231{ 220{
@@ -254,7 +243,6 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = {
254 .set_time = stk17ta8_rtc_set_time, 243 .set_time = stk17ta8_rtc_set_time,
255 .read_alarm = stk17ta8_rtc_read_alarm, 244 .read_alarm = stk17ta8_rtc_read_alarm,
256 .set_alarm = stk17ta8_rtc_set_alarm, 245 .set_alarm = stk17ta8_rtc_set_alarm,
257 .release = stk17ta8_rtc_release,
258 .ioctl = stk17ta8_rtc_ioctl, 246 .ioctl = stk17ta8_rtc_ioctl,
259}; 247};
260 248
@@ -292,7 +280,6 @@ static struct bin_attribute stk17ta8_nvram_attr = {
292 .attr = { 280 .attr = {
293 .name = "nvram", 281 .name = "nvram",
294 .mode = S_IRUGO | S_IWUSR, 282 .mode = S_IRUGO | S_IWUSR,
295 .owner = THIS_MODULE,
296 }, 283 },
297 .size = RTC_OFFSET, 284 .size = RTC_OFFSET,
298 .read = stk17ta8_nvram_read, 285 .read = stk17ta8_nvram_read,
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index 10025d840268..14d4f036a768 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -92,19 +92,19 @@ static int v3020_read_time(struct device *dev, struct rtc_time *dt)
92 92
93 /* ...and then read constant values. */ 93 /* ...and then read constant values. */
94 tmp = v3020_get_reg(chip, V3020_SECONDS); 94 tmp = v3020_get_reg(chip, V3020_SECONDS);
95 dt->tm_sec = BCD2BIN(tmp); 95 dt->tm_sec = bcd2bin(tmp);
96 tmp = v3020_get_reg(chip, V3020_MINUTES); 96 tmp = v3020_get_reg(chip, V3020_MINUTES);
97 dt->tm_min = BCD2BIN(tmp); 97 dt->tm_min = bcd2bin(tmp);
98 tmp = v3020_get_reg(chip, V3020_HOURS); 98 tmp = v3020_get_reg(chip, V3020_HOURS);
99 dt->tm_hour = BCD2BIN(tmp); 99 dt->tm_hour = bcd2bin(tmp);
100 tmp = v3020_get_reg(chip, V3020_MONTH_DAY); 100 tmp = v3020_get_reg(chip, V3020_MONTH_DAY);
101 dt->tm_mday = BCD2BIN(tmp); 101 dt->tm_mday = bcd2bin(tmp);
102 tmp = v3020_get_reg(chip, V3020_MONTH); 102 tmp = v3020_get_reg(chip, V3020_MONTH);
103 dt->tm_mon = BCD2BIN(tmp) - 1; 103 dt->tm_mon = bcd2bin(tmp) - 1;
104 tmp = v3020_get_reg(chip, V3020_WEEK_DAY); 104 tmp = v3020_get_reg(chip, V3020_WEEK_DAY);
105 dt->tm_wday = BCD2BIN(tmp); 105 dt->tm_wday = bcd2bin(tmp);
106 tmp = v3020_get_reg(chip, V3020_YEAR); 106 tmp = v3020_get_reg(chip, V3020_YEAR);
107 dt->tm_year = BCD2BIN(tmp)+100; 107 dt->tm_year = bcd2bin(tmp)+100;
108 108
109#ifdef DEBUG 109#ifdef DEBUG
110 printk("\n%s : Read RTC values\n",__func__); 110 printk("\n%s : Read RTC values\n",__func__);
@@ -136,13 +136,13 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)
136#endif 136#endif
137 137
138 /* Write all the values to ram... */ 138 /* Write all the values to ram... */
139 v3020_set_reg(chip, V3020_SECONDS, BIN2BCD(dt->tm_sec)); 139 v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec));
140 v3020_set_reg(chip, V3020_MINUTES, BIN2BCD(dt->tm_min)); 140 v3020_set_reg(chip, V3020_MINUTES, bin2bcd(dt->tm_min));
141 v3020_set_reg(chip, V3020_HOURS, BIN2BCD(dt->tm_hour)); 141 v3020_set_reg(chip, V3020_HOURS, bin2bcd(dt->tm_hour));
142 v3020_set_reg(chip, V3020_MONTH_DAY, BIN2BCD(dt->tm_mday)); 142 v3020_set_reg(chip, V3020_MONTH_DAY, bin2bcd(dt->tm_mday));
143 v3020_set_reg(chip, V3020_MONTH, BIN2BCD(dt->tm_mon + 1)); 143 v3020_set_reg(chip, V3020_MONTH, bin2bcd(dt->tm_mon + 1));
144 v3020_set_reg(chip, V3020_WEEK_DAY, BIN2BCD(dt->tm_wday)); 144 v3020_set_reg(chip, V3020_WEEK_DAY, bin2bcd(dt->tm_wday));
145 v3020_set_reg(chip, V3020_YEAR, BIN2BCD(dt->tm_year % 100)); 145 v3020_set_reg(chip, V3020_YEAR, bin2bcd(dt->tm_year % 100));
146 146
147 /* ...and set the clock. */ 147 /* ...and set the clock. */
148 v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0); 148 v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0);
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 7dcfba1bbfe1..310c10795e9a 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -118,13 +118,13 @@ static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
118 for (i = 0; i <= 4; i++) 118 for (i = 0; i <= 4; i++)
119 buf[i] &= 0x7F; 119 buf[i] &= 0x7F;
120 120
121 tm->tm_sec = BCD2BIN(buf[CCR_SEC]); 121 tm->tm_sec = bcd2bin(buf[CCR_SEC]);
122 tm->tm_min = BCD2BIN(buf[CCR_MIN]); 122 tm->tm_min = bcd2bin(buf[CCR_MIN]);
123 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */ 123 tm->tm_hour = bcd2bin(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
124 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]); 124 tm->tm_mday = bcd2bin(buf[CCR_MDAY]);
125 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]) - 1; /* mon is 0-11 */ 125 tm->tm_mon = bcd2bin(buf[CCR_MONTH]) - 1; /* mon is 0-11 */
126 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) 126 tm->tm_year = bcd2bin(buf[CCR_YEAR])
127 + (BCD2BIN(buf[CCR_Y2K]) * 100) - 1900; 127 + (bcd2bin(buf[CCR_Y2K]) * 100) - 1900;
128 tm->tm_wday = buf[CCR_WDAY]; 128 tm->tm_wday = buf[CCR_WDAY];
129 129
130 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 130 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
@@ -174,11 +174,11 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
174 __func__, 174 __func__,
175 tm->tm_sec, tm->tm_min, tm->tm_hour); 175 tm->tm_sec, tm->tm_min, tm->tm_hour);
176 176
177 buf[CCR_SEC] = BIN2BCD(tm->tm_sec); 177 buf[CCR_SEC] = bin2bcd(tm->tm_sec);
178 buf[CCR_MIN] = BIN2BCD(tm->tm_min); 178 buf[CCR_MIN] = bin2bcd(tm->tm_min);
179 179
180 /* set hour and 24hr bit */ 180 /* set hour and 24hr bit */
181 buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL; 181 buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL;
182 182
183 /* should we also set the date? */ 183 /* should we also set the date? */
184 if (datetoo) { 184 if (datetoo) {
@@ -187,15 +187,15 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
187 __func__, 187 __func__,
188 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 188 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
189 189
190 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday); 190 buf[CCR_MDAY] = bin2bcd(tm->tm_mday);
191 191
192 /* month, 1 - 12 */ 192 /* month, 1 - 12 */
193 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon + 1); 193 buf[CCR_MONTH] = bin2bcd(tm->tm_mon + 1);
194 194
195 /* year, since the rtc epoch*/ 195 /* year, since the rtc epoch*/
196 buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100); 196 buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100);
197 buf[CCR_WDAY] = tm->tm_wday & 0x07; 197 buf[CCR_WDAY] = tm->tm_wday & 0x07;
198 buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100); 198 buf[CCR_Y2K] = bin2bcd(tm->tm_year / 100);
199 } 199 }
200 200
201 /* If writing alarm registers, set compare bits on registers 0-4 */ 201 /* If writing alarm registers, set compare bits on registers 0-4 */
@@ -437,7 +437,7 @@ static int x1205_validate_client(struct i2c_client *client)
437 return -EIO; 437 return -EIO;
438 } 438 }
439 439
440 value = BCD2BIN(reg & probe_limits_pattern[i].mask); 440 value = bcd2bin(reg & probe_limits_pattern[i].mask);
441 441
442 if (value > probe_limits_pattern[i].max || 442 if (value > probe_limits_pattern[i].max ||
443 value < probe_limits_pattern[i].min) { 443 value < probe_limits_pattern[i].min) {