aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig22
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/interface.c2
-rw-r--r--drivers/rtc/rtc-at91rm9200.c42
-rw-r--r--drivers/rtc/rtc-bq4802.c30
-rw-r--r--drivers/rtc/rtc-cmos.c23
-rw-r--r--drivers/rtc/rtc-dev.c3
-rw-r--r--drivers/rtc/rtc-ds1216.c26
-rw-r--r--drivers/rtc/rtc-ds1302.c30
-rw-r--r--drivers/rtc/rtc-ds1305.c39
-rw-r--r--drivers/rtc/rtc-ds1307.c41
-rw-r--r--drivers/rtc/rtc-ds1511.c43
-rw-r--r--drivers/rtc/rtc-ds1553.c38
-rw-r--r--drivers/rtc/rtc-ds1742.c30
-rw-r--r--drivers/rtc/rtc-ds3234.c4
-rw-r--r--drivers/rtc/rtc-fm3130.c56
-rw-r--r--drivers/rtc/rtc-isl1208.c42
-rw-r--r--drivers/rtc/rtc-m41t80.c44
-rw-r--r--drivers/rtc/rtc-m41t94.c28
-rw-r--r--drivers/rtc/rtc-m48t59.c81
-rw-r--r--drivers/rtc/rtc-m48t86.c28
-rw-r--r--drivers/rtc/rtc-max6900.c32
-rw-r--r--drivers/rtc/rtc-max6902.c32
-rw-r--r--drivers/rtc/rtc-omap.c24
-rw-r--r--drivers/rtc/rtc-parisc.c111
-rw-r--r--drivers/rtc/rtc-pcf8563.c24
-rw-r--r--drivers/rtc/rtc-pcf8583.c20
-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.c42
-rw-r--r--drivers/rtc/rtc-s35390a.c34
-rw-r--r--drivers/rtc/rtc-s3c.c50
-rw-r--r--drivers/rtc/rtc-sh.c61
-rw-r--r--drivers/rtc/rtc-stk17ta8.c39
-rw-r--r--drivers/rtc/rtc-twl4030.c564
-rw-r--r--drivers/rtc/rtc-v3020.c28
-rw-r--r--drivers/rtc/rtc-vr41xx.c4
-rw-r--r--drivers/rtc/rtc-x1205.c30
39 files changed, 1276 insertions, 555 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index f660ef3e5b2..8abbb2020af 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -171,10 +171,10 @@ config RTC_DRV_MAX6900
171 will be called rtc-max6900. 171 will be called rtc-max6900.
172 172
173config RTC_DRV_RS5C372 173config RTC_DRV_RS5C372
174 tristate "Ricoh RS5C372A/B, RV5C386, RV5C387A" 174 tristate "Ricoh R2025S/D, RS5C372A/B, RV5C386, RV5C387A"
175 help 175 help
176 If you say yes here you get support for the 176 If you say yes here you get support for the
177 Ricoh RS5C372A, RS5C372B, RV5C386, and RV5C387A RTC chips. 177 Ricoh R2025S/D, RS5C372A, RS5C372B, RV5C386, and RV5C387A RTC chips.
178 178
179 This driver can also be built as a module. If so, the module 179 This driver can also be built as a module. If so, the module
180 will be called rtc-rs5c372. 180 will be called rtc-rs5c372.
@@ -246,6 +246,16 @@ config RTC_DRV_TWL92330
246 platforms. The support is integrated with the rest of 246 platforms. The support is integrated with the rest of
247 the Menelaus driver; it's not separate module. 247 the Menelaus driver; it's not separate module.
248 248
249config RTC_DRV_TWL4030
250 tristate "TI TWL4030/TWL5030/TPS659x0"
251 depends on RTC_CLASS && TWL4030_CORE
252 help
253 If you say yes here you get support for the RTC on the
254 TWL4030 family chips, used mostly with OMAP3 platforms.
255
256 This driver can also be built as a module. If so, the module
257 will be called rtc-twl4030.
258
249config RTC_DRV_S35390A 259config RTC_DRV_S35390A
250 tristate "Seiko Instruments S-35390A" 260 tristate "Seiko Instruments S-35390A"
251 select BITREVERSE 261 select BITREVERSE
@@ -610,6 +620,14 @@ config RTC_DRV_RS5C313
610 help 620 help
611 If you say yes here you get support for the Ricoh RS5C313 RTC chips. 621 If you say yes here you get support for the Ricoh RS5C313 RTC chips.
612 622
623config RTC_DRV_PARISC
624 tristate "PA-RISC firmware RTC support"
625 depends on PARISC
626 help
627 Say Y or M here to enable RTC support on PA-RISC systems using
628 firmware calls. If you do not know what you are doing, you should
629 just say Y.
630
613config RTC_DRV_PPC 631config RTC_DRV_PPC
614 tristate "PowerPC machine dependent RTC support" 632 tristate "PowerPC machine dependent RTC support"
615 depends on PPC 633 depends on PPC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index d05928b3ca9..e9e8474cc8f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
51obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 51obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
52obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o 52obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o
53obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 53obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
54obj-$(CONFIG_RTC_DRV_PARISC) += rtc-parisc.o
54obj-$(CONFIG_RTC_DRV_PPC) += rtc-ppc.o 55obj-$(CONFIG_RTC_DRV_PPC) += rtc-ppc.o
55obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o 56obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
56obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o 57obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
@@ -62,6 +63,7 @@ obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
62obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 63obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
63obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o 64obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
64obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 65obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
66obj-$(CONFIG_RTC_DRV_TWL4030) += rtc-twl4030.o
65obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 67obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
66obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 68obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
67obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 69obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 7af60b98d8a..a04c1b6b157 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -271,7 +271,7 @@ int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
271 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year"); 271 dev_dbg(&rtc->dev, "alarm rollover: %s\n", "year");
272 do { 272 do {
273 alarm->time.tm_year++; 273 alarm->time.tm_year++;
274 } while (!rtc_valid_tm(&alarm->time)); 274 } while (rtc_valid_tm(&alarm->time) != 0);
275 break; 275 break;
276 276
277 default: 277 default:
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 37082616482..b5bf9370691 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -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) {
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index 189a018bdf3..d00a274df8f 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 f1695d7fa0f..6cf8e282338 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -240,26 +240,26 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
240 /* REVISIT this assumes PC style usage: always BCD */ 240 /* REVISIT this assumes PC style usage: always BCD */
241 241
242 if (((unsigned)t->time.tm_sec) < 0x60) 242 if (((unsigned)t->time.tm_sec) < 0x60)
243 t->time.tm_sec = BCD2BIN(t->time.tm_sec); 243 t->time.tm_sec = bcd2bin(t->time.tm_sec);
244 else 244 else
245 t->time.tm_sec = -1; 245 t->time.tm_sec = -1;
246 if (((unsigned)t->time.tm_min) < 0x60) 246 if (((unsigned)t->time.tm_min) < 0x60)
247 t->time.tm_min = BCD2BIN(t->time.tm_min); 247 t->time.tm_min = bcd2bin(t->time.tm_min);
248 else 248 else
249 t->time.tm_min = -1; 249 t->time.tm_min = -1;
250 if (((unsigned)t->time.tm_hour) < 0x24) 250 if (((unsigned)t->time.tm_hour) < 0x24)
251 t->time.tm_hour = BCD2BIN(t->time.tm_hour); 251 t->time.tm_hour = bcd2bin(t->time.tm_hour);
252 else 252 else
253 t->time.tm_hour = -1; 253 t->time.tm_hour = -1;
254 254
255 if (cmos->day_alrm) { 255 if (cmos->day_alrm) {
256 if (((unsigned)t->time.tm_mday) <= 0x31) 256 if (((unsigned)t->time.tm_mday) <= 0x31)
257 t->time.tm_mday = BCD2BIN(t->time.tm_mday); 257 t->time.tm_mday = bcd2bin(t->time.tm_mday);
258 else 258 else
259 t->time.tm_mday = -1; 259 t->time.tm_mday = -1;
260 if (cmos->mon_alrm) { 260 if (cmos->mon_alrm) {
261 if (((unsigned)t->time.tm_mon) <= 0x12) 261 if (((unsigned)t->time.tm_mon) <= 0x12)
262 t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1; 262 t->time.tm_mon = bcd2bin(t->time.tm_mon) - 1;
263 else 263 else
264 t->time.tm_mon = -1; 264 t->time.tm_mon = -1;
265 } 265 }
@@ -331,19 +331,19 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
331 /* Writing 0xff means "don't care" or "match all". */ 331 /* Writing 0xff means "don't care" or "match all". */
332 332
333 mon = t->time.tm_mon + 1; 333 mon = t->time.tm_mon + 1;
334 mon = (mon <= 12) ? BIN2BCD(mon) : 0xff; 334 mon = (mon <= 12) ? bin2bcd(mon) : 0xff;
335 335
336 mday = t->time.tm_mday; 336 mday = t->time.tm_mday;
337 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; 337 mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
338 338
339 hrs = t->time.tm_hour; 339 hrs = t->time.tm_hour;
340 hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff; 340 hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff;
341 341
342 min = t->time.tm_min; 342 min = t->time.tm_min;
343 min = (min < 60) ? BIN2BCD(min) : 0xff; 343 min = (min < 60) ? bin2bcd(min) : 0xff;
344 344
345 sec = t->time.tm_sec; 345 sec = t->time.tm_sec;
346 sec = (sec < 60) ? BIN2BCD(sec) : 0xff; 346 sec = (sec < 60) ? bin2bcd(sec) : 0xff;
347 347
348 spin_lock_irq(&rtc_lock); 348 spin_lock_irq(&rtc_lock);
349 349
@@ -592,7 +592,6 @@ static struct bin_attribute nvram = {
592 .attr = { 592 .attr = {
593 .name = "nvram", 593 .name = "nvram",
594 .mode = S_IRUGO | S_IWUSR, 594 .mode = S_IRUGO | S_IWUSR,
595 .owner = THIS_MODULE,
596 }, 595 },
597 596
598 .read = cmos_nvram_read, 597 .read = cmos_nvram_read,
@@ -795,7 +794,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
795 goto cleanup2; 794 goto cleanup2;
796 } 795 }
797 796
798 pr_info("%s: alarms up to one %s%s, %zd bytes nvram, %s irqs\n", 797 pr_info("%s: alarms up to one %s%s, %zd bytes nvram%s\n",
799 cmos_rtc.rtc->dev.bus_id, 798 cmos_rtc.rtc->dev.bus_id,
800 is_valid_irq(rtc_irq) 799 is_valid_irq(rtc_irq)
801 ? (cmos_rtc.mon_alrm 800 ? (cmos_rtc.mon_alrm
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 079e9ed907e..ecdea44ae4e 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -446,9 +446,6 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
446 if (rtc->ops->release) 446 if (rtc->ops->release)
447 rtc->ops->release(rtc->dev.parent); 447 rtc->ops->release(rtc->dev.parent);
448 448
449 if (file->f_flags & FASYNC)
450 rtc_dev_fasync(-1, file, 0);
451
452 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); 449 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
453 return 0; 450 return 0;
454} 451}
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 0b17770b032..9a234a4ec06 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-ds1302.c b/drivers/rtc/rtc-ds1302.c
index b9397818f73..18455662077 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 b91d02a3ace..fc372df6534 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 4fcf0734a6e..162330b9d1d 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -222,17 +222,17 @@ static int ds1307_get_time(struct device *dev, struct rtc_time *t)
222 ds1307->regs[4], ds1307->regs[5], 222 ds1307->regs[4], ds1307->regs[5],
223 ds1307->regs[6]); 223 ds1307->regs[6]);
224 224
225 t->tm_sec = BCD2BIN(ds1307->regs[DS1307_REG_SECS] & 0x7f); 225 t->tm_sec = bcd2bin(ds1307->regs[DS1307_REG_SECS] & 0x7f);
226 t->tm_min = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); 226 t->tm_min = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f);
227 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f; 227 tmp = ds1307->regs[DS1307_REG_HOUR] & 0x3f;
228 t->tm_hour = BCD2BIN(tmp); 228 t->tm_hour = bcd2bin(tmp);
229 t->tm_wday = BCD2BIN(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1; 229 t->tm_wday = bcd2bin(ds1307->regs[DS1307_REG_WDAY] & 0x07) - 1;
230 t->tm_mday = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); 230 t->tm_mday = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
231 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f; 231 tmp = ds1307->regs[DS1307_REG_MONTH] & 0x1f;
232 t->tm_mon = BCD2BIN(tmp) - 1; 232 t->tm_mon = bcd2bin(tmp) - 1;
233 233
234 /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */ 234 /* assume 20YY not 19YY, and ignore DS1337_BIT_CENTURY */
235 t->tm_year = BCD2BIN(ds1307->regs[DS1307_REG_YEAR]) + 100; 235 t->tm_year = bcd2bin(ds1307->regs[DS1307_REG_YEAR]) + 100;
236 236
237 dev_dbg(dev, "%s secs=%d, mins=%d, " 237 dev_dbg(dev, "%s secs=%d, mins=%d, "
238 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 238 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -258,16 +258,16 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
258 t->tm_mon, t->tm_year, t->tm_wday); 258 t->tm_mon, t->tm_year, t->tm_wday);
259 259
260 *buf++ = 0; /* first register addr */ 260 *buf++ = 0; /* first register addr */
261 buf[DS1307_REG_SECS] = BIN2BCD(t->tm_sec); 261 buf[DS1307_REG_SECS] = bin2bcd(t->tm_sec);
262 buf[DS1307_REG_MIN] = BIN2BCD(t->tm_min); 262 buf[DS1307_REG_MIN] = bin2bcd(t->tm_min);
263 buf[DS1307_REG_HOUR] = BIN2BCD(t->tm_hour); 263 buf[DS1307_REG_HOUR] = bin2bcd(t->tm_hour);
264 buf[DS1307_REG_WDAY] = BIN2BCD(t->tm_wday + 1); 264 buf[DS1307_REG_WDAY] = bin2bcd(t->tm_wday + 1);
265 buf[DS1307_REG_MDAY] = BIN2BCD(t->tm_mday); 265 buf[DS1307_REG_MDAY] = bin2bcd(t->tm_mday);
266 buf[DS1307_REG_MONTH] = BIN2BCD(t->tm_mon + 1); 266 buf[DS1307_REG_MONTH] = bin2bcd(t->tm_mon + 1);
267 267
268 /* assume 20YY not 19YY */ 268 /* assume 20YY not 19YY */
269 tmp = t->tm_year - 100; 269 tmp = t->tm_year - 100;
270 buf[DS1307_REG_YEAR] = BIN2BCD(tmp); 270 buf[DS1307_REG_YEAR] = bin2bcd(tmp);
271 271
272 switch (ds1307->type) { 272 switch (ds1307->type) {
273 case ds_1337: 273 case ds_1337:
@@ -551,7 +551,6 @@ static struct bin_attribute nvram = {
551 .attr = { 551 .attr = {
552 .name = "nvram", 552 .name = "nvram",
553 .mode = S_IRUGO | S_IWUSR, 553 .mode = S_IRUGO | S_IWUSR,
554 .owner = THIS_MODULE,
555 }, 554 },
556 555
557 .read = ds1307_nvram_read, 556 .read = ds1307_nvram_read,
@@ -709,18 +708,18 @@ read_rtc:
709 } 708 }
710 709
711 tmp = ds1307->regs[DS1307_REG_SECS]; 710 tmp = ds1307->regs[DS1307_REG_SECS];
712 tmp = BCD2BIN(tmp & 0x7f); 711 tmp = bcd2bin(tmp & 0x7f);
713 if (tmp > 60) 712 if (tmp > 60)
714 goto exit_bad; 713 goto exit_bad;
715 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MIN] & 0x7f); 714 tmp = bcd2bin(ds1307->regs[DS1307_REG_MIN] & 0x7f);
716 if (tmp > 60) 715 if (tmp > 60)
717 goto exit_bad; 716 goto exit_bad;
718 717
719 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MDAY] & 0x3f); 718 tmp = bcd2bin(ds1307->regs[DS1307_REG_MDAY] & 0x3f);
720 if (tmp == 0 || tmp > 31) 719 if (tmp == 0 || tmp > 31)
721 goto exit_bad; 720 goto exit_bad;
722 721
723 tmp = BCD2BIN(ds1307->regs[DS1307_REG_MONTH] & 0x1f); 722 tmp = bcd2bin(ds1307->regs[DS1307_REG_MONTH] & 0x1f);
724 if (tmp == 0 || tmp > 12) 723 if (tmp == 0 || tmp > 12)
725 goto exit_bad; 724 goto exit_bad;
726 725
@@ -739,14 +738,14 @@ read_rtc:
739 /* Be sure we're in 24 hour mode. Multi-master systems 738 /* Be sure we're in 24 hour mode. Multi-master systems
740 * take note... 739 * take note...
741 */ 740 */
742 tmp = BCD2BIN(tmp & 0x1f); 741 tmp = bcd2bin(tmp & 0x1f);
743 if (tmp == 12) 742 if (tmp == 12)
744 tmp = 0; 743 tmp = 0;
745 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM) 744 if (ds1307->regs[DS1307_REG_HOUR] & DS1307_BIT_PM)
746 tmp += 12; 745 tmp += 12;
747 i2c_smbus_write_byte_data(client, 746 i2c_smbus_write_byte_data(client,
748 DS1307_REG_HOUR, 747 DS1307_REG_HOUR,
749 BIN2BCD(tmp)); 748 bin2bcd(tmp));
750 } 749 }
751 750
752 ds1307->rtc = rtc_device_register(client->name, &client->dev, 751 ds1307->rtc = rtc_device_register(client->name, &client->dev,
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 86981d34fbb..25caada7839 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 */
@@ -481,7 +481,6 @@ static struct bin_attribute ds1511_nvram_attr = {
481 .attr = { 481 .attr = {
482 .name = "nvram", 482 .name = "nvram",
483 .mode = S_IRUGO | S_IWUGO, 483 .mode = S_IRUGO | S_IWUGO,
484 .owner = THIS_MODULE,
485 }, 484 },
486 .size = DS1511_RAM_MAX, 485 .size = DS1511_RAM_MAX,
487 .read = ds1511_nvram_read, 486 .read = ds1511_nvram_read,
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 4ef59285b48..b9475cd2021 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 */
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 24d35ede2db..8bc8501bffc 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
index 37d131d03f3..45e5b106af7 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -189,7 +189,7 @@ static const struct rtc_class_ops ds3234_rtc_ops = {
189 .set_time = ds3234_set_time, 189 .set_time = ds3234_set_time,
190}; 190};
191 191
192static int ds3234_probe(struct spi_device *spi) 192static int __devinit ds3234_probe(struct spi_device *spi)
193{ 193{
194 struct rtc_device *rtc; 194 struct rtc_device *rtc;
195 unsigned char tmp; 195 unsigned char tmp;
@@ -249,7 +249,7 @@ static int ds3234_probe(struct spi_device *spi)
249 return 0; 249 return 0;
250} 250}
251 251
252static int __exit ds3234_remove(struct spi_device *spi) 252static int __devexit ds3234_remove(struct spi_device *spi)
253{ 253{
254 struct ds3234 *chip = platform_get_drvdata(spi); 254 struct ds3234 *chip = platform_get_drvdata(spi);
255 struct rtc_device *rtc = chip->rtc; 255 struct rtc_device *rtc = chip->rtc;
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index abfdfcbaa05..3a7be11cc6b 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 a81adab6e51..2cd77ab8fc6 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 470fb2d2954..893f7dece23 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -110,15 +110,15 @@ static int m41t80_get_datetime(struct i2c_client *client,
110 return -EIO; 110 return -EIO;
111 } 111 }
112 112
113 tm->tm_sec = BCD2BIN(buf[M41T80_REG_SEC] & 0x7f); 113 tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f);
114 tm->tm_min = BCD2BIN(buf[M41T80_REG_MIN] & 0x7f); 114 tm->tm_min = bcd2bin(buf[M41T80_REG_MIN] & 0x7f);
115 tm->tm_hour = BCD2BIN(buf[M41T80_REG_HOUR] & 0x3f); 115 tm->tm_hour = bcd2bin(buf[M41T80_REG_HOUR] & 0x3f);
116 tm->tm_mday = BCD2BIN(buf[M41T80_REG_DAY] & 0x3f); 116 tm->tm_mday = bcd2bin(buf[M41T80_REG_DAY] & 0x3f);
117 tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07; 117 tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07;
118 tm->tm_mon = BCD2BIN(buf[M41T80_REG_MON] & 0x1f) - 1; 118 tm->tm_mon = bcd2bin(buf[M41T80_REG_MON] & 0x1f) - 1;
119 119
120 /* assume 20YY not 19YY, and ignore the Century Bit */ 120 /* assume 20YY not 19YY, and ignore the Century Bit */
121 tm->tm_year = BCD2BIN(buf[M41T80_REG_YEAR]) + 100; 121 tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100;
122 return 0; 122 return 0;
123} 123}
124 124
@@ -161,19 +161,19 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
161 /* Merge time-data and register flags into buf[0..7] */ 161 /* Merge time-data and register flags into buf[0..7] */
162 buf[M41T80_REG_SSEC] = 0; 162 buf[M41T80_REG_SSEC] = 0;
163 buf[M41T80_REG_SEC] = 163 buf[M41T80_REG_SEC] =
164 BIN2BCD(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f); 164 bin2bcd(tm->tm_sec) | (buf[M41T80_REG_SEC] & ~0x7f);
165 buf[M41T80_REG_MIN] = 165 buf[M41T80_REG_MIN] =
166 BIN2BCD(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); 166 bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f);
167 buf[M41T80_REG_HOUR] = 167 buf[M41T80_REG_HOUR] =
168 BIN2BCD(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ; 168 bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ;
169 buf[M41T80_REG_WDAY] = 169 buf[M41T80_REG_WDAY] =
170 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); 170 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07);
171 buf[M41T80_REG_DAY] = 171 buf[M41T80_REG_DAY] =
172 BIN2BCD(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); 172 bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f);
173 buf[M41T80_REG_MON] = 173 buf[M41T80_REG_MON] =
174 BIN2BCD(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); 174 bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f);
175 /* assume 20YY not 19YY */ 175 /* assume 20YY not 19YY */
176 buf[M41T80_REG_YEAR] = BIN2BCD(tm->tm_year % 100); 176 buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100);
177 177
178 if (i2c_transfer(client->adapter, msgs, 1) != 1) { 178 if (i2c_transfer(client->adapter, msgs, 1) != 1) {
179 dev_err(&client->dev, "write error\n"); 179 dev_err(&client->dev, "write error\n");
@@ -288,15 +288,15 @@ static int m41t80_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *t)
288 288
289 wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */ 289 wbuf[0] = M41T80_REG_ALARM_MON; /* offset into rtc's regs */
290 reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ? 290 reg[M41T80_REG_ALARM_SEC] |= t->time.tm_sec >= 0 ?
291 BIN2BCD(t->time.tm_sec) : 0x80; 291 bin2bcd(t->time.tm_sec) : 0x80;
292 reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ? 292 reg[M41T80_REG_ALARM_MIN] |= t->time.tm_min >= 0 ?
293 BIN2BCD(t->time.tm_min) : 0x80; 293 bin2bcd(t->time.tm_min) : 0x80;
294 reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ? 294 reg[M41T80_REG_ALARM_HOUR] |= t->time.tm_hour >= 0 ?
295 BIN2BCD(t->time.tm_hour) : 0x80; 295 bin2bcd(t->time.tm_hour) : 0x80;
296 reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ? 296 reg[M41T80_REG_ALARM_DAY] |= t->time.tm_mday >= 0 ?
297 BIN2BCD(t->time.tm_mday) : 0x80; 297 bin2bcd(t->time.tm_mday) : 0x80;
298 if (t->time.tm_mon >= 0) 298 if (t->time.tm_mon >= 0)
299 reg[M41T80_REG_ALARM_MON] |= BIN2BCD(t->time.tm_mon + 1); 299 reg[M41T80_REG_ALARM_MON] |= bin2bcd(t->time.tm_mon + 1);
300 else 300 else
301 reg[M41T80_REG_ALARM_DAY] |= 0x40; 301 reg[M41T80_REG_ALARM_DAY] |= 0x40;
302 302
@@ -347,15 +347,15 @@ static int m41t80_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *t)
347 t->time.tm_mday = -1; 347 t->time.tm_mday = -1;
348 t->time.tm_mon = -1; 348 t->time.tm_mon = -1;
349 if (!(reg[M41T80_REG_ALARM_SEC] & 0x80)) 349 if (!(reg[M41T80_REG_ALARM_SEC] & 0x80))
350 t->time.tm_sec = BCD2BIN(reg[M41T80_REG_ALARM_SEC] & 0x7f); 350 t->time.tm_sec = bcd2bin(reg[M41T80_REG_ALARM_SEC] & 0x7f);
351 if (!(reg[M41T80_REG_ALARM_MIN] & 0x80)) 351 if (!(reg[M41T80_REG_ALARM_MIN] & 0x80))
352 t->time.tm_min = BCD2BIN(reg[M41T80_REG_ALARM_MIN] & 0x7f); 352 t->time.tm_min = bcd2bin(reg[M41T80_REG_ALARM_MIN] & 0x7f);
353 if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80)) 353 if (!(reg[M41T80_REG_ALARM_HOUR] & 0x80))
354 t->time.tm_hour = BCD2BIN(reg[M41T80_REG_ALARM_HOUR] & 0x3f); 354 t->time.tm_hour = bcd2bin(reg[M41T80_REG_ALARM_HOUR] & 0x3f);
355 if (!(reg[M41T80_REG_ALARM_DAY] & 0x80)) 355 if (!(reg[M41T80_REG_ALARM_DAY] & 0x80))
356 t->time.tm_mday = BCD2BIN(reg[M41T80_REG_ALARM_DAY] & 0x3f); 356 t->time.tm_mday = bcd2bin(reg[M41T80_REG_ALARM_DAY] & 0x3f);
357 if (!(reg[M41T80_REG_ALARM_DAY] & 0x40)) 357 if (!(reg[M41T80_REG_ALARM_DAY] & 0x40))
358 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;
359 t->time.tm_year = -1; 359 t->time.tm_year = -1;
360 t->time.tm_wday = -1; 360 t->time.tm_wday = -1;
361 t->time.tm_yday = -1; 361 t->time.tm_yday = -1;
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 9b19499c829..c3a18c58daf 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-m48t59.c b/drivers/rtc/rtc-m48t59.c
index ce4eff6a8d5..43afb7ab528 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) &&
@@ -87,11 +87,15 @@ static int m48t59_rtc_read_time(struct device *dev, struct rtc_time *tm)
87 dev_dbg(dev, "Century bit is enabled\n"); 87 dev_dbg(dev, "Century bit is enabled\n");
88 tm->tm_year += 100; /* one century */ 88 tm->tm_year += 100; /* one century */
89 } 89 }
90#ifdef CONFIG_SPARC
91 /* Sun SPARC machines count years since 1968 */
92 tm->tm_year += 68;
93#endif
90 94
91 tm->tm_wday = BCD2BIN(val & 0x07); 95 tm->tm_wday = bcd2bin(val & 0x07);
92 tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_HOUR) & 0x3F); 96 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_HOUR) & 0x3F);
93 tm->tm_min = BCD2BIN(M48T59_READ(M48T59_MIN) & 0x7F); 97 tm->tm_min = bcd2bin(M48T59_READ(M48T59_MIN) & 0x7F);
94 tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_SEC) & 0x7F); 98 tm->tm_sec = bcd2bin(M48T59_READ(M48T59_SEC) & 0x7F);
95 99
96 /* Clear the READ bit */ 100 /* Clear the READ bit */
97 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 101 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
@@ -110,26 +114,35 @@ static int m48t59_rtc_set_time(struct device *dev, struct rtc_time *tm)
110 struct m48t59_private *m48t59 = platform_get_drvdata(pdev); 114 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
111 unsigned long flags; 115 unsigned long flags;
112 u8 val = 0; 116 u8 val = 0;
117 int year = tm->tm_year;
118
119#ifdef CONFIG_SPARC
120 /* Sun SPARC machines count years since 1968 */
121 year -= 68;
122#endif
113 123
114 dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n", 124 dev_dbg(dev, "RTC set time %04d-%02d-%02d %02d/%02d/%02d\n",
115 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 125 year + 1900, tm->tm_mon, tm->tm_mday,
116 tm->tm_hour, tm->tm_min, tm->tm_sec); 126 tm->tm_hour, tm->tm_min, tm->tm_sec);
117 127
128 if (year < 0)
129 return -EINVAL;
130
118 spin_lock_irqsave(&m48t59->lock, flags); 131 spin_lock_irqsave(&m48t59->lock, flags);
119 /* Issue the WRITE command */ 132 /* Issue the WRITE command */
120 M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL); 133 M48T59_SET_BITS(M48T59_CNTL_WRITE, M48T59_CNTL);
121 134
122 M48T59_WRITE((BIN2BCD(tm->tm_sec) & 0x7F), M48T59_SEC); 135 M48T59_WRITE((bin2bcd(tm->tm_sec) & 0x7F), M48T59_SEC);
123 M48T59_WRITE((BIN2BCD(tm->tm_min) & 0x7F), M48T59_MIN); 136 M48T59_WRITE((bin2bcd(tm->tm_min) & 0x7F), M48T59_MIN);
124 M48T59_WRITE((BIN2BCD(tm->tm_hour) & 0x3F), M48T59_HOUR); 137 M48T59_WRITE((bin2bcd(tm->tm_hour) & 0x3F), M48T59_HOUR);
125 M48T59_WRITE((BIN2BCD(tm->tm_mday) & 0x3F), M48T59_MDAY); 138 M48T59_WRITE((bin2bcd(tm->tm_mday) & 0x3F), M48T59_MDAY);
126 /* tm_mon is 0-11 */ 139 /* tm_mon is 0-11 */
127 M48T59_WRITE((BIN2BCD(tm->tm_mon + 1) & 0x1F), M48T59_MONTH); 140 M48T59_WRITE((bin2bcd(tm->tm_mon + 1) & 0x1F), M48T59_MONTH);
128 M48T59_WRITE(BIN2BCD(tm->tm_year % 100), M48T59_YEAR); 141 M48T59_WRITE(bin2bcd(year % 100), M48T59_YEAR);
129 142
130 if (pdata->type == M48T59RTC_TYPE_M48T59 && (tm->tm_year / 100)) 143 if (pdata->type == M48T59RTC_TYPE_M48T59 && (year / 100))
131 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB); 144 val = (M48T59_WDAY_CEB | M48T59_WDAY_CB);
132 val |= (BIN2BCD(tm->tm_wday) & 0x07); 145 val |= (bin2bcd(tm->tm_wday) & 0x07);
133 M48T59_WRITE(val, M48T59_WDAY); 146 M48T59_WRITE(val, M48T59_WDAY);
134 147
135 /* Clear the WRITE bit */ 148 /* Clear the WRITE bit */
@@ -158,18 +171,22 @@ static int m48t59_rtc_readalarm(struct device *dev, struct rtc_wkalrm *alrm)
158 /* Issue the READ command */ 171 /* Issue the READ command */
159 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL); 172 M48T59_SET_BITS(M48T59_CNTL_READ, M48T59_CNTL);
160 173
161 tm->tm_year = BCD2BIN(M48T59_READ(M48T59_YEAR)); 174 tm->tm_year = bcd2bin(M48T59_READ(M48T59_YEAR));
175#ifdef CONFIG_SPARC
176 /* Sun SPARC machines count years since 1968 */
177 tm->tm_year += 68;
178#endif
162 /* tm_mon is 0-11 */ 179 /* tm_mon is 0-11 */
163 tm->tm_mon = BCD2BIN(M48T59_READ(M48T59_MONTH)) - 1; 180 tm->tm_mon = bcd2bin(M48T59_READ(M48T59_MONTH)) - 1;
164 181
165 val = M48T59_READ(M48T59_WDAY); 182 val = M48T59_READ(M48T59_WDAY);
166 if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB)) 183 if ((val & M48T59_WDAY_CEB) && (val & M48T59_WDAY_CB))
167 tm->tm_year += 100; /* one century */ 184 tm->tm_year += 100; /* one century */
168 185
169 tm->tm_mday = BCD2BIN(M48T59_READ(M48T59_ALARM_DATE)); 186 tm->tm_mday = bcd2bin(M48T59_READ(M48T59_ALARM_DATE));
170 tm->tm_hour = BCD2BIN(M48T59_READ(M48T59_ALARM_HOUR)); 187 tm->tm_hour = bcd2bin(M48T59_READ(M48T59_ALARM_HOUR));
171 tm->tm_min = BCD2BIN(M48T59_READ(M48T59_ALARM_MIN)); 188 tm->tm_min = bcd2bin(M48T59_READ(M48T59_ALARM_MIN));
172 tm->tm_sec = BCD2BIN(M48T59_READ(M48T59_ALARM_SEC)); 189 tm->tm_sec = bcd2bin(M48T59_READ(M48T59_ALARM_SEC));
173 190
174 /* Clear the READ bit */ 191 /* Clear the READ bit */
175 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL); 192 M48T59_CLEAR_BITS(M48T59_CNTL_READ, M48T59_CNTL);
@@ -192,27 +209,36 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
192 struct rtc_time *tm = &alrm->time; 209 struct rtc_time *tm = &alrm->time;
193 u8 mday, hour, min, sec; 210 u8 mday, hour, min, sec;
194 unsigned long flags; 211 unsigned long flags;
212 int year = tm->tm_year;
213
214#ifdef CONFIG_SPARC
215 /* Sun SPARC machines count years since 1968 */
216 year -= 68;
217#endif
195 218
196 /* If no irq, we don't support ALARM */ 219 /* If no irq, we don't support ALARM */
197 if (m48t59->irq == NO_IRQ) 220 if (m48t59->irq == NO_IRQ)
198 return -EIO; 221 return -EIO;
199 222
223 if (year < 0)
224 return -EINVAL;
225
200 /* 226 /*
201 * 0xff means "always match" 227 * 0xff means "always match"
202 */ 228 */
203 mday = tm->tm_mday; 229 mday = tm->tm_mday;
204 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff; 230 mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;
205 if (mday == 0xff) 231 if (mday == 0xff)
206 mday = M48T59_READ(M48T59_MDAY); 232 mday = M48T59_READ(M48T59_MDAY);
207 233
208 hour = tm->tm_hour; 234 hour = tm->tm_hour;
209 hour = (hour < 24) ? BIN2BCD(hour) : 0x00; 235 hour = (hour < 24) ? bin2bcd(hour) : 0x00;
210 236
211 min = tm->tm_min; 237 min = tm->tm_min;
212 min = (min < 60) ? BIN2BCD(min) : 0x00; 238 min = (min < 60) ? bin2bcd(min) : 0x00;
213 239
214 sec = tm->tm_sec; 240 sec = tm->tm_sec;
215 sec = (sec < 60) ? BIN2BCD(sec) : 0x00; 241 sec = (sec < 60) ? bin2bcd(sec) : 0x00;
216 242
217 spin_lock_irqsave(&m48t59->lock, flags); 243 spin_lock_irqsave(&m48t59->lock, flags);
218 /* Issue the WRITE command */ 244 /* Issue the WRITE command */
@@ -228,7 +254,7 @@ static int m48t59_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
228 spin_unlock_irqrestore(&m48t59->lock, flags); 254 spin_unlock_irqrestore(&m48t59->lock, flags);
229 255
230 dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n", 256 dev_dbg(dev, "RTC set alarm time %04d-%02d-%02d %02d/%02d/%02d\n",
231 tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, 257 year + 1900, tm->tm_mon, tm->tm_mday,
232 tm->tm_hour, tm->tm_min, tm->tm_sec); 258 tm->tm_hour, tm->tm_min, tm->tm_sec);
233 return 0; 259 return 0;
234} 260}
@@ -360,7 +386,6 @@ static struct bin_attribute m48t59_nvram_attr = {
360 .attr = { 386 .attr = {
361 .name = "nvram", 387 .name = "nvram",
362 .mode = S_IRUGO | S_IWUSR, 388 .mode = S_IRUGO | S_IWUSR,
363 .owner = THIS_MODULE,
364 }, 389 },
365 .read = m48t59_nvram_read, 390 .read = m48t59_nvram_read,
366 .write = m48t59_nvram_write, 391 .write = m48t59_nvram_write,
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 3f7f99a5d96..7c045cffa9f 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 12c9cd25cad..80782798763 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -150,14 +150,14 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
150 if (rc < 0) 150 if (rc < 0)
151 return rc; 151 return rc;
152 152
153 tm->tm_sec = BCD2BIN(regs[MAX6900_REG_SC]); 153 tm->tm_sec = bcd2bin(regs[MAX6900_REG_SC]);
154 tm->tm_min = BCD2BIN(regs[MAX6900_REG_MN]); 154 tm->tm_min = bcd2bin(regs[MAX6900_REG_MN]);
155 tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f); 155 tm->tm_hour = bcd2bin(regs[MAX6900_REG_HR] & 0x3f);
156 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]); 156 tm->tm_mday = bcd2bin(regs[MAX6900_REG_DT]);
157 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1; 157 tm->tm_mon = bcd2bin(regs[MAX6900_REG_MO]) - 1;
158 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + 158 tm->tm_year = bcd2bin(regs[MAX6900_REG_YR]) +
159 BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
160 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]); 160 tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]);
161 161
162 return 0; 162 return 0;
163} 163}
@@ -184,14 +184,14 @@ max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
184 if (rc < 0) 184 if (rc < 0)
185 return rc; 185 return rc;
186 186
187 regs[MAX6900_REG_SC] = BIN2BCD(tm->tm_sec); 187 regs[MAX6900_REG_SC] = bin2bcd(tm->tm_sec);
188 regs[MAX6900_REG_MN] = BIN2BCD(tm->tm_min); 188 regs[MAX6900_REG_MN] = bin2bcd(tm->tm_min);
189 regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour); 189 regs[MAX6900_REG_HR] = bin2bcd(tm->tm_hour);
190 regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday); 190 regs[MAX6900_REG_DT] = bin2bcd(tm->tm_mday);
191 regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1); 191 regs[MAX6900_REG_MO] = bin2bcd(tm->tm_mon + 1);
192 regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday); 192 regs[MAX6900_REG_DW] = bin2bcd(tm->tm_wday);
193 regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year % 100); 193 regs[MAX6900_REG_YR] = bin2bcd(tm->tm_year % 100);
194 regs[MAX6900_REG_CENTURY] = BIN2BCD((tm->tm_year + 1900) / 100); 194 regs[MAX6900_REG_CENTURY] = bin2bcd((tm->tm_year + 1900) / 100);
195 /* set write protect */ 195 /* set write protect */
196 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; 196 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP;
197 197
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 78b2551fb19..2f6507df7b4 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 8876605d4d4..2cbeb0794f1 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-parisc.c b/drivers/rtc/rtc-parisc.c
new file mode 100644
index 00000000000..346d633655e
--- /dev/null
+++ b/drivers/rtc/rtc-parisc.c
@@ -0,0 +1,111 @@
1/* rtc-parisc: RTC for HP PA-RISC firmware
2 *
3 * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/time.h>
9#include <linux/platform_device.h>
10
11#include <asm/rtc.h>
12
13/* as simple as can be, and no simpler. */
14struct parisc_rtc {
15 struct rtc_device *rtc;
16 spinlock_t lock;
17};
18
19static int parisc_get_time(struct device *dev, struct rtc_time *tm)
20{
21 struct parisc_rtc *p = dev_get_drvdata(dev);
22 unsigned long flags, ret;
23
24 spin_lock_irqsave(&p->lock, flags);
25 ret = get_rtc_time(tm);
26 spin_unlock_irqrestore(&p->lock, flags);
27
28 if (ret & RTC_BATT_BAD)
29 return -EOPNOTSUPP;
30
31 return 0;
32}
33
34static int parisc_set_time(struct device *dev, struct rtc_time *tm)
35{
36 struct parisc_rtc *p = dev_get_drvdata(dev);
37 unsigned long flags, ret;
38
39 spin_lock_irqsave(&p->lock, flags);
40 ret = set_rtc_time(tm);
41 spin_unlock_irqrestore(&p->lock, flags);
42
43 if (ret < 0)
44 return -EOPNOTSUPP;
45
46 return 0;
47}
48
49static const struct rtc_class_ops parisc_rtc_ops = {
50 .read_time = parisc_get_time,
51 .set_time = parisc_set_time,
52};
53
54static int __devinit parisc_rtc_probe(struct platform_device *dev)
55{
56 struct parisc_rtc *p;
57
58 p = kzalloc(sizeof (*p), GFP_KERNEL);
59 if (!p)
60 return -ENOMEM;
61
62 spin_lock_init(&p->lock);
63
64 p->rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops,
65 THIS_MODULE);
66 if (IS_ERR(p->rtc)) {
67 int err = PTR_ERR(p->rtc);
68 kfree(p);
69 return err;
70 }
71
72 platform_set_drvdata(dev, p);
73
74 return 0;
75}
76
77static int __devexit parisc_rtc_remove(struct platform_device *dev)
78{
79 struct parisc_rtc *p = platform_get_drvdata(dev);
80
81 rtc_device_unregister(p->rtc);
82 kfree(p);
83
84 return 0;
85}
86
87static struct platform_driver parisc_rtc_driver = {
88 .driver = {
89 .name = "rtc-parisc",
90 .owner = THIS_MODULE,
91 },
92 .probe = parisc_rtc_probe,
93 .remove = __devexit_p(parisc_rtc_remove),
94};
95
96static int __init parisc_rtc_init(void)
97{
98 return platform_driver_register(&parisc_rtc_driver);
99}
100
101static void __exit parisc_rtc_fini(void)
102{
103 platform_driver_unregister(&parisc_rtc_driver);
104}
105
106module_init(parisc_rtc_init);
107module_exit(parisc_rtc_fini);
108
109MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
110MODULE_LICENSE("GPL");
111MODULE_DESCRIPTION("HP PA-RISC RTC driver");
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index a829f20ad6d..b725913ccbe 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
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index d388c662bf4..7d33cda3f8f 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-r9701.c b/drivers/rtc/rtc-r9701.c
index 395985b339c..42028f233be 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 1c14d4497c4..e6ea3f5ee1e 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 839462659af..dd1e2bc7a47 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 8b561958fb1..2f2c68d476d 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -148,9 +148,9 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
148 unsigned hour; 148 unsigned hour;
149 149
150 if (rs5c->time24) 150 if (rs5c->time24)
151 return BCD2BIN(reg & 0x3f); 151 return bcd2bin(reg & 0x3f);
152 152
153 hour = BCD2BIN(reg & 0x1f); 153 hour = bcd2bin(reg & 0x1f);
154 if (hour == 12) 154 if (hour == 12)
155 hour = 0; 155 hour = 0;
156 if (reg & 0x20) 156 if (reg & 0x20)
@@ -161,15 +161,15 @@ static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
161static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour) 161static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour)
162{ 162{
163 if (rs5c->time24) 163 if (rs5c->time24)
164 return BIN2BCD(hour); 164 return bin2bcd(hour);
165 165
166 if (hour > 12) 166 if (hour > 12)
167 return 0x20 | BIN2BCD(hour - 12); 167 return 0x20 | bin2bcd(hour - 12);
168 if (hour == 12) 168 if (hour == 12)
169 return 0x20 | BIN2BCD(12); 169 return 0x20 | bin2bcd(12);
170 if (hour == 0) 170 if (hour == 0)
171 return BIN2BCD(12); 171 return bin2bcd(12);
172 return BIN2BCD(hour); 172 return bin2bcd(hour);
173} 173}
174 174
175static 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)
@@ -180,18 +180,18 @@ static int rs5c372_get_datetime(struct i2c_client *client, struct rtc_time *tm)
180 if (status < 0) 180 if (status < 0)
181 return status; 181 return status;
182 182
183 tm->tm_sec = BCD2BIN(rs5c->regs[RS5C372_REG_SECS] & 0x7f); 183 tm->tm_sec = bcd2bin(rs5c->regs[RS5C372_REG_SECS] & 0x7f);
184 tm->tm_min = BCD2BIN(rs5c->regs[RS5C372_REG_MINS] & 0x7f); 184 tm->tm_min = bcd2bin(rs5c->regs[RS5C372_REG_MINS] & 0x7f);
185 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]); 185 tm->tm_hour = rs5c_reg2hr(rs5c, rs5c->regs[RS5C372_REG_HOURS]);
186 186
187 tm->tm_wday = BCD2BIN(rs5c->regs[RS5C372_REG_WDAY] & 0x07); 187 tm->tm_wday = bcd2bin(rs5c->regs[RS5C372_REG_WDAY] & 0x07);
188 tm->tm_mday = BCD2BIN(rs5c->regs[RS5C372_REG_DAY] & 0x3f); 188 tm->tm_mday = bcd2bin(rs5c->regs[RS5C372_REG_DAY] & 0x3f);
189 189
190 /* tm->tm_mon is zero-based */ 190 /* tm->tm_mon is zero-based */
191 tm->tm_mon = BCD2BIN(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1; 191 tm->tm_mon = bcd2bin(rs5c->regs[RS5C372_REG_MONTH] & 0x1f) - 1;
192 192
193 /* year is 1900 + tm->tm_year */ 193 /* year is 1900 + tm->tm_year */
194 tm->tm_year = BCD2BIN(rs5c->regs[RS5C372_REG_YEAR]) + 100; 194 tm->tm_year = bcd2bin(rs5c->regs[RS5C372_REG_YEAR]) + 100;
195 195
196 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, "
197 "mday=%d, mon=%d, year=%d, wday=%d\n", 197 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -216,13 +216,13 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
216 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);
217 217
218 addr = RS5C_ADDR(RS5C372_REG_SECS); 218 addr = RS5C_ADDR(RS5C372_REG_SECS);
219 buf[0] = BIN2BCD(tm->tm_sec); 219 buf[0] = bin2bcd(tm->tm_sec);
220 buf[1] = BIN2BCD(tm->tm_min); 220 buf[1] = bin2bcd(tm->tm_min);
221 buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour); 221 buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour);
222 buf[3] = BIN2BCD(tm->tm_wday); 222 buf[3] = bin2bcd(tm->tm_wday);
223 buf[4] = BIN2BCD(tm->tm_mday); 223 buf[4] = bin2bcd(tm->tm_mday);
224 buf[5] = BIN2BCD(tm->tm_mon + 1); 224 buf[5] = bin2bcd(tm->tm_mon + 1);
225 buf[6] = BIN2BCD(tm->tm_year - 100); 225 buf[6] = bin2bcd(tm->tm_year - 100);
226 226
227 if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) { 227 if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) {
228 dev_err(&client->dev, "%s: write error\n", __func__); 228 dev_err(&client->dev, "%s: write error\n", __func__);
@@ -367,7 +367,7 @@ static int rs5c_read_alarm(struct device *dev, struct rtc_wkalrm *t)
367 367
368 /* report alarm time */ 368 /* report alarm time */
369 t->time.tm_sec = 0; 369 t->time.tm_sec = 0;
370 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);
371 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]);
372 t->time.tm_mday = -1; 372 t->time.tm_mday = -1;
373 t->time.tm_mon = -1; 373 t->time.tm_mon = -1;
@@ -413,7 +413,7 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
413 } 413 }
414 414
415 /* set alarm */ 415 /* set alarm */
416 buf[0] = BIN2BCD(t->time.tm_min); 416 buf[0] = bin2bcd(t->time.tm_min);
417 buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour); 417 buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour);
418 buf[2] = 0x7f; /* any/all days */ 418 buf[2] = 0x7f; /* any/all days */
419 419
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index a6fa1f2f2ca..def4d396d0b 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 e7d19b6c265..f59277bbeda 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);
@@ -455,6 +455,8 @@ static int __devinit s3c_rtc_probe(struct platform_device *pdev)
455 455
456 s3c_rtc_setfreq(&pdev->dev, 1); 456 s3c_rtc_setfreq(&pdev->dev, 1);
457 457
458 device_init_wakeup(&pdev->dev, 1);
459
458 /* register RTC and exit */ 460 /* register RTC and exit */
459 461
460 rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops, 462 rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops,
@@ -507,7 +509,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
507#define s3c_rtc_resume NULL 509#define s3c_rtc_resume NULL
508#endif 510#endif
509 511
510static struct platform_driver s3c2410_rtcdrv = { 512static struct platform_driver s3c2410_rtc_driver = {
511 .probe = s3c_rtc_probe, 513 .probe = s3c_rtc_probe,
512 .remove = __devexit_p(s3c_rtc_remove), 514 .remove = __devexit_p(s3c_rtc_remove),
513 .suspend = s3c_rtc_suspend, 515 .suspend = s3c_rtc_suspend,
@@ -523,12 +525,12 @@ static char __initdata banner[] = "S3C24XX RTC, (c) 2004,2006 Simtec Electronics
523static int __init s3c_rtc_init(void) 525static int __init s3c_rtc_init(void)
524{ 526{
525 printk(banner); 527 printk(banner);
526 return platform_driver_register(&s3c2410_rtcdrv); 528 return platform_driver_register(&s3c2410_rtc_driver);
527} 529}
528 530
529static void __exit s3c_rtc_exit(void) 531static void __exit s3c_rtc_exit(void)
530{ 532{
531 platform_driver_unregister(&s3c2410_rtcdrv); 533 platform_driver_unregister(&s3c2410_rtc_driver);
532} 534}
533 535
534module_init(s3c_rtc_init); 536module_init(s3c_rtc_init);
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index fcead4c4cd1..aaf9d6a337c 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -324,23 +324,23 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
324 324
325 sec128 = readb(rtc->regbase + R64CNT); 325 sec128 = readb(rtc->regbase + R64CNT);
326 326
327 tm->tm_sec = BCD2BIN(readb(rtc->regbase + RSECCNT)); 327 tm->tm_sec = bcd2bin(readb(rtc->regbase + RSECCNT));
328 tm->tm_min = BCD2BIN(readb(rtc->regbase + RMINCNT)); 328 tm->tm_min = bcd2bin(readb(rtc->regbase + RMINCNT));
329 tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); 329 tm->tm_hour = bcd2bin(readb(rtc->regbase + RHRCNT));
330 tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); 330 tm->tm_wday = bcd2bin(readb(rtc->regbase + RWKCNT));
331 tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); 331 tm->tm_mday = bcd2bin(readb(rtc->regbase + RDAYCNT));
332 tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)) - 1; 332 tm->tm_mon = bcd2bin(readb(rtc->regbase + RMONCNT)) - 1;
333 333
334 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { 334 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
335 yr = readw(rtc->regbase + RYRCNT); 335 yr = readw(rtc->regbase + RYRCNT);
336 yr100 = BCD2BIN(yr >> 8); 336 yr100 = bcd2bin(yr >> 8);
337 yr &= 0xff; 337 yr &= 0xff;
338 } else { 338 } else {
339 yr = readb(rtc->regbase + RYRCNT); 339 yr = readb(rtc->regbase + RYRCNT);
340 yr100 = BCD2BIN((yr == 0x99) ? 0x19 : 0x20); 340 yr100 = bcd2bin((yr == 0x99) ? 0x19 : 0x20);
341 } 341 }
342 342
343 tm->tm_year = (yr100 * 100 + BCD2BIN(yr)) - 1900; 343 tm->tm_year = (yr100 * 100 + bcd2bin(yr)) - 1900;
344 344
345 sec2 = readb(rtc->regbase + R64CNT); 345 sec2 = readb(rtc->regbase + R64CNT);
346 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF; 346 cf_bit = readb(rtc->regbase + RCR1) & RCR1_CF;
@@ -382,20 +382,20 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
382 tmp &= ~RCR2_START; 382 tmp &= ~RCR2_START;
383 writeb(tmp, rtc->regbase + RCR2); 383 writeb(tmp, rtc->regbase + RCR2);
384 384
385 writeb(BIN2BCD(tm->tm_sec), rtc->regbase + RSECCNT); 385 writeb(bin2bcd(tm->tm_sec), rtc->regbase + RSECCNT);
386 writeb(BIN2BCD(tm->tm_min), rtc->regbase + RMINCNT); 386 writeb(bin2bcd(tm->tm_min), rtc->regbase + RMINCNT);
387 writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); 387 writeb(bin2bcd(tm->tm_hour), rtc->regbase + RHRCNT);
388 writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); 388 writeb(bin2bcd(tm->tm_wday), rtc->regbase + RWKCNT);
389 writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); 389 writeb(bin2bcd(tm->tm_mday), rtc->regbase + RDAYCNT);
390 writeb(BIN2BCD(tm->tm_mon + 1), rtc->regbase + RMONCNT); 390 writeb(bin2bcd(tm->tm_mon + 1), rtc->regbase + RMONCNT);
391 391
392 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) { 392 if (rtc->capabilities & RTC_CAP_4_DIGIT_YEAR) {
393 year = (BIN2BCD((tm->tm_year + 1900) / 100) << 8) | 393 year = (bin2bcd((tm->tm_year + 1900) / 100) << 8) |
394 BIN2BCD(tm->tm_year % 100); 394 bin2bcd(tm->tm_year % 100);
395 writew(year, rtc->regbase + RYRCNT); 395 writew(year, rtc->regbase + RYRCNT);
396 } else { 396 } else {
397 year = tm->tm_year % 100; 397 year = tm->tm_year % 100;
398 writeb(BIN2BCD(year), rtc->regbase + RYRCNT); 398 writeb(bin2bcd(year), rtc->regbase + RYRCNT);
399 } 399 }
400 400
401 /* Start RTC */ 401 /* Start RTC */
@@ -417,7 +417,7 @@ static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off)
417 byte = readb(rtc->regbase + reg_off); 417 byte = readb(rtc->regbase + reg_off);
418 if (byte & AR_ENB) { 418 if (byte & AR_ENB) {
419 byte &= ~AR_ENB; /* strip the enable bit */ 419 byte &= ~AR_ENB; /* strip the enable bit */
420 value = BCD2BIN(byte); 420 value = bcd2bin(byte);
421 } 421 }
422 422
423 return value; 423 return value;
@@ -455,7 +455,7 @@ static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc,
455 if (value < 0) 455 if (value < 0)
456 writeb(0, rtc->regbase + reg_off); 456 writeb(0, rtc->regbase + reg_off);
457 else 457 else
458 writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off); 458 writeb(bin2bcd(value) | AR_ENB, rtc->regbase + reg_off);
459} 459}
460 460
461static int sh_rtc_check_alarm(struct rtc_time *tm) 461static int sh_rtc_check_alarm(struct rtc_time *tm)
@@ -568,7 +568,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
568 struct sh_rtc *rtc; 568 struct sh_rtc *rtc;
569 struct resource *res; 569 struct resource *res;
570 unsigned int tmp; 570 unsigned int tmp;
571 int ret = -ENOENT; 571 int ret;
572 572
573 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); 573 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL);
574 if (unlikely(!rtc)) 574 if (unlikely(!rtc))
@@ -577,26 +577,33 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
577 spin_lock_init(&rtc->lock); 577 spin_lock_init(&rtc->lock);
578 578
579 /* get periodic/carry/alarm irqs */ 579 /* get periodic/carry/alarm irqs */
580 rtc->periodic_irq = platform_get_irq(pdev, 0); 580 ret = platform_get_irq(pdev, 0);
581 if (unlikely(rtc->periodic_irq < 0)) { 581 if (unlikely(ret < 0)) {
582 ret = -ENOENT;
582 dev_err(&pdev->dev, "No IRQ for period\n"); 583 dev_err(&pdev->dev, "No IRQ for period\n");
583 goto err_badres; 584 goto err_badres;
584 } 585 }
586 rtc->periodic_irq = ret;
585 587
586 rtc->carry_irq = platform_get_irq(pdev, 1); 588 ret = platform_get_irq(pdev, 1);
587 if (unlikely(rtc->carry_irq < 0)) { 589 if (unlikely(ret < 0)) {
590 ret = -ENOENT;
588 dev_err(&pdev->dev, "No IRQ for carry\n"); 591 dev_err(&pdev->dev, "No IRQ for carry\n");
589 goto err_badres; 592 goto err_badres;
590 } 593 }
594 rtc->carry_irq = ret;
591 595
592 rtc->alarm_irq = platform_get_irq(pdev, 2); 596 ret = platform_get_irq(pdev, 2);
593 if (unlikely(rtc->alarm_irq < 0)) { 597 if (unlikely(ret < 0)) {
598 ret = -ENOENT;
594 dev_err(&pdev->dev, "No IRQ for alarm\n"); 599 dev_err(&pdev->dev, "No IRQ for alarm\n");
595 goto err_badres; 600 goto err_badres;
596 } 601 }
602 rtc->alarm_irq = ret;
597 603
598 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 604 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
599 if (unlikely(res == NULL)) { 605 if (unlikely(res == NULL)) {
606 ret = -ENOENT;
600 dev_err(&pdev->dev, "No IO resource\n"); 607 dev_err(&pdev->dev, "No IO resource\n");
601 goto err_badres; 608 goto err_badres;
602 } 609 }
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 9a7e920315f..f4cd46e15af 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 */
@@ -280,7 +280,6 @@ static struct bin_attribute stk17ta8_nvram_attr = {
280 .attr = { 280 .attr = {
281 .name = "nvram", 281 .name = "nvram",
282 .mode = S_IRUGO | S_IWUSR, 282 .mode = S_IRUGO | S_IWUSR,
283 .owner = THIS_MODULE,
284 }, 283 },
285 .size = RTC_OFFSET, 284 .size = RTC_OFFSET,
286 .read = stk17ta8_nvram_read, 285 .read = stk17ta8_nvram_read,
diff --git a/drivers/rtc/rtc-twl4030.c b/drivers/rtc/rtc-twl4030.c
new file mode 100644
index 00000000000..abe87a4d266
--- /dev/null
+++ b/drivers/rtc/rtc-twl4030.c
@@ -0,0 +1,564 @@
1/*
2 * rtc-twl4030.c -- TWL4030 Real Time Clock interface
3 *
4 * Copyright (C) 2007 MontaVista Software, Inc
5 * Author: Alexandre Rusev <source@mvista.com>
6 *
7 * Based on original TI driver twl4030-rtc.c
8 * Copyright (C) 2006 Texas Instruments, Inc.
9 *
10 * Based on rtc-omap.c
11 * Copyright (C) 2003 MontaVista Software, Inc.
12 * Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com>
13 * Copyright (C) 2006 David Brownell
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/types.h>
25#include <linux/rtc.h>
26#include <linux/bcd.h>
27#include <linux/platform_device.h>
28#include <linux/interrupt.h>
29
30#include <linux/i2c/twl4030.h>
31
32
33/*
34 * RTC block register offsets (use TWL_MODULE_RTC)
35 */
36#define REG_SECONDS_REG 0x00
37#define REG_MINUTES_REG 0x01
38#define REG_HOURS_REG 0x02
39#define REG_DAYS_REG 0x03
40#define REG_MONTHS_REG 0x04
41#define REG_YEARS_REG 0x05
42#define REG_WEEKS_REG 0x06
43
44#define REG_ALARM_SECONDS_REG 0x07
45#define REG_ALARM_MINUTES_REG 0x08
46#define REG_ALARM_HOURS_REG 0x09
47#define REG_ALARM_DAYS_REG 0x0A
48#define REG_ALARM_MONTHS_REG 0x0B
49#define REG_ALARM_YEARS_REG 0x0C
50
51#define REG_RTC_CTRL_REG 0x0D
52#define REG_RTC_STATUS_REG 0x0E
53#define REG_RTC_INTERRUPTS_REG 0x0F
54
55#define REG_RTC_COMP_LSB_REG 0x10
56#define REG_RTC_COMP_MSB_REG 0x11
57
58/* RTC_CTRL_REG bitfields */
59#define BIT_RTC_CTRL_REG_STOP_RTC_M 0x01
60#define BIT_RTC_CTRL_REG_ROUND_30S_M 0x02
61#define BIT_RTC_CTRL_REG_AUTO_COMP_M 0x04
62#define BIT_RTC_CTRL_REG_MODE_12_24_M 0x08
63#define BIT_RTC_CTRL_REG_TEST_MODE_M 0x10
64#define BIT_RTC_CTRL_REG_SET_32_COUNTER_M 0x20
65#define BIT_RTC_CTRL_REG_GET_TIME_M 0x40
66
67/* RTC_STATUS_REG bitfields */
68#define BIT_RTC_STATUS_REG_RUN_M 0x02
69#define BIT_RTC_STATUS_REG_1S_EVENT_M 0x04
70#define BIT_RTC_STATUS_REG_1M_EVENT_M 0x08
71#define BIT_RTC_STATUS_REG_1H_EVENT_M 0x10
72#define BIT_RTC_STATUS_REG_1D_EVENT_M 0x20
73#define BIT_RTC_STATUS_REG_ALARM_M 0x40
74#define BIT_RTC_STATUS_REG_POWER_UP_M 0x80
75
76/* RTC_INTERRUPTS_REG bitfields */
77#define BIT_RTC_INTERRUPTS_REG_EVERY_M 0x03
78#define BIT_RTC_INTERRUPTS_REG_IT_TIMER_M 0x04
79#define BIT_RTC_INTERRUPTS_REG_IT_ALARM_M 0x08
80
81
82/* REG_SECONDS_REG through REG_YEARS_REG is how many registers? */
83#define ALL_TIME_REGS 6
84
85/*----------------------------------------------------------------------*/
86
87/*
88 * Supports 1 byte read from TWL4030 RTC register.
89 */
90static int twl4030_rtc_read_u8(u8 *data, u8 reg)
91{
92 int ret;
93
94 ret = twl4030_i2c_read_u8(TWL4030_MODULE_RTC, data, reg);
95 if (ret < 0)
96 pr_err("twl4030_rtc: Could not read TWL4030"
97 "register %X - error %d\n", reg, ret);
98 return ret;
99}
100
101/*
102 * Supports 1 byte write to TWL4030 RTC registers.
103 */
104static int twl4030_rtc_write_u8(u8 data, u8 reg)
105{
106 int ret;
107
108 ret = twl4030_i2c_write_u8(TWL4030_MODULE_RTC, data, reg);
109 if (ret < 0)
110 pr_err("twl4030_rtc: Could not write TWL4030"
111 "register %X - error %d\n", reg, ret);
112 return ret;
113}
114
115/*
116 * Cache the value for timer/alarm interrupts register; this is
117 * only changed by callers holding rtc ops lock (or resume).
118 */
119static unsigned char rtc_irq_bits;
120
121/*
122 * Enable timer and/or alarm interrupts.
123 */
124static int set_rtc_irq_bit(unsigned char bit)
125{
126 unsigned char val;
127 int ret;
128
129 val = rtc_irq_bits | bit;
130 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
131 if (ret == 0)
132 rtc_irq_bits = val;
133
134 return ret;
135}
136
137/*
138 * Disable timer and/or alarm interrupts.
139 */
140static int mask_rtc_irq_bit(unsigned char bit)
141{
142 unsigned char val;
143 int ret;
144
145 val = rtc_irq_bits & ~bit;
146 ret = twl4030_rtc_write_u8(val, REG_RTC_INTERRUPTS_REG);
147 if (ret == 0)
148 rtc_irq_bits = val;
149
150 return ret;
151}
152
153static inline int twl4030_rtc_alarm_irq_set_state(int enabled)
154{
155 int ret;
156
157 if (enabled)
158 ret = set_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
159 else
160 ret = mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
161
162 return ret;
163}
164
165static inline int twl4030_rtc_irq_set_state(int enabled)
166{
167 int ret;
168
169 if (enabled)
170 ret = set_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
171 else
172 ret = mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
173
174 return ret;
175}
176
177/*
178 * Gets current TWL4030 RTC time and date parameters.
179 *
180 * The RTC's time/alarm representation is not what gmtime(3) requires
181 * Linux to use:
182 *
183 * - Months are 1..12 vs Linux 0-11
184 * - Years are 0..99 vs Linux 1900..N (we assume 21st century)
185 */
186static int twl4030_rtc_read_time(struct device *dev, struct rtc_time *tm)
187{
188 unsigned char rtc_data[ALL_TIME_REGS + 1];
189 int ret;
190 u8 save_control;
191
192 ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
193 if (ret < 0)
194 return ret;
195
196 save_control |= BIT_RTC_CTRL_REG_GET_TIME_M;
197
198 ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
199 if (ret < 0)
200 return ret;
201
202 ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
203 REG_SECONDS_REG, ALL_TIME_REGS);
204
205 if (ret < 0) {
206 dev_err(dev, "rtc_read_time error %d\n", ret);
207 return ret;
208 }
209
210 tm->tm_sec = bcd2bin(rtc_data[0]);
211 tm->tm_min = bcd2bin(rtc_data[1]);
212 tm->tm_hour = bcd2bin(rtc_data[2]);
213 tm->tm_mday = bcd2bin(rtc_data[3]);
214 tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
215 tm->tm_year = bcd2bin(rtc_data[5]) + 100;
216
217 return ret;
218}
219
220static int twl4030_rtc_set_time(struct device *dev, struct rtc_time *tm)
221{
222 unsigned char save_control;
223 unsigned char rtc_data[ALL_TIME_REGS + 1];
224 int ret;
225
226 rtc_data[1] = bin2bcd(tm->tm_sec);
227 rtc_data[2] = bin2bcd(tm->tm_min);
228 rtc_data[3] = bin2bcd(tm->tm_hour);
229 rtc_data[4] = bin2bcd(tm->tm_mday);
230 rtc_data[5] = bin2bcd(tm->tm_mon + 1);
231 rtc_data[6] = bin2bcd(tm->tm_year - 100);
232
233 /* Stop RTC while updating the TC registers */
234 ret = twl4030_rtc_read_u8(&save_control, REG_RTC_CTRL_REG);
235 if (ret < 0)
236 goto out;
237
238 save_control &= ~BIT_RTC_CTRL_REG_STOP_RTC_M;
239 twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
240 if (ret < 0)
241 goto out;
242
243 /* update all the time registers in one shot */
244 ret = twl4030_i2c_write(TWL4030_MODULE_RTC, rtc_data,
245 REG_SECONDS_REG, ALL_TIME_REGS);
246 if (ret < 0) {
247 dev_err(dev, "rtc_set_time error %d\n", ret);
248 goto out;
249 }
250
251 /* Start back RTC */
252 save_control |= BIT_RTC_CTRL_REG_STOP_RTC_M;
253 ret = twl4030_rtc_write_u8(save_control, REG_RTC_CTRL_REG);
254
255out:
256 return ret;
257}
258
259/*
260 * Gets current TWL4030 RTC alarm time.
261 */
262static int twl4030_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
263{
264 unsigned char rtc_data[ALL_TIME_REGS + 1];
265 int ret;
266
267 ret = twl4030_i2c_read(TWL4030_MODULE_RTC, rtc_data,
268 REG_ALARM_SECONDS_REG, ALL_TIME_REGS);
269 if (ret < 0) {
270 dev_err(dev, "rtc_read_alarm error %d\n", ret);
271 return ret;
272 }
273
274 /* some of these fields may be wildcard/"match all" */
275 alm->time.tm_sec = bcd2bin(rtc_data[0]);
276 alm->time.tm_min = bcd2bin(rtc_data[1]);
277 alm->time.tm_hour = bcd2bin(rtc_data[2]);
278 alm->time.tm_mday = bcd2bin(rtc_data[3]);
279 alm->time.tm_mon = bcd2bin(rtc_data[4]) - 1;
280 alm->time.tm_year = bcd2bin(rtc_data[5]) + 100;
281
282 /* report cached alarm enable state */
283 if (rtc_irq_bits & BIT_RTC_INTERRUPTS_REG_IT_ALARM_M)
284 alm->enabled = 1;
285
286 return ret;
287}
288
289static int twl4030_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
290{
291 unsigned char alarm_data[ALL_TIME_REGS + 1];
292 int ret;
293
294 ret = twl4030_rtc_alarm_irq_set_state(0);
295 if (ret)
296 goto out;
297
298 alarm_data[1] = bin2bcd(alm->time.tm_sec);
299 alarm_data[2] = bin2bcd(alm->time.tm_min);
300 alarm_data[3] = bin2bcd(alm->time.tm_hour);
301 alarm_data[4] = bin2bcd(alm->time.tm_mday);
302 alarm_data[5] = bin2bcd(alm->time.tm_mon + 1);
303 alarm_data[6] = bin2bcd(alm->time.tm_year - 100);
304
305 /* update all the alarm registers in one shot */
306 ret = twl4030_i2c_write(TWL4030_MODULE_RTC, alarm_data,
307 REG_ALARM_SECONDS_REG, ALL_TIME_REGS);
308 if (ret) {
309 dev_err(dev, "rtc_set_alarm error %d\n", ret);
310 goto out;
311 }
312
313 if (alm->enabled)
314 ret = twl4030_rtc_alarm_irq_set_state(1);
315out:
316 return ret;
317}
318
319#ifdef CONFIG_RTC_INTF_DEV
320
321static int twl4030_rtc_ioctl(struct device *dev, unsigned int cmd,
322 unsigned long arg)
323{
324 switch (cmd) {
325 case RTC_AIE_OFF:
326 return twl4030_rtc_alarm_irq_set_state(0);
327 case RTC_AIE_ON:
328 return twl4030_rtc_alarm_irq_set_state(1);
329 case RTC_UIE_OFF:
330 return twl4030_rtc_irq_set_state(0);
331 case RTC_UIE_ON:
332 return twl4030_rtc_irq_set_state(1);
333
334 default:
335 return -ENOIOCTLCMD;
336 }
337}
338
339#else
340#define omap_rtc_ioctl NULL
341#endif
342
343static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc)
344{
345 unsigned long events = 0;
346 int ret = IRQ_NONE;
347 int res;
348 u8 rd_reg;
349
350#ifdef CONFIG_LOCKDEP
351 /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which
352 * we don't want and can't tolerate. Although it might be
353 * friendlier not to borrow this thread context...
354 */
355 local_irq_enable();
356#endif
357
358 res = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
359 if (res)
360 goto out;
361 /*
362 * Figure out source of interrupt: ALARM or TIMER in RTC_STATUS_REG.
363 * only one (ALARM or RTC) interrupt source may be enabled
364 * at time, we also could check our results
365 * by reading RTS_INTERRUPTS_REGISTER[IT_TIMER,IT_ALARM]
366 */
367 if (rd_reg & BIT_RTC_STATUS_REG_ALARM_M)
368 events |= RTC_IRQF | RTC_AF;
369 else
370 events |= RTC_IRQF | RTC_UF;
371
372 res = twl4030_rtc_write_u8(rd_reg | BIT_RTC_STATUS_REG_ALARM_M,
373 REG_RTC_STATUS_REG);
374 if (res)
375 goto out;
376
377 /* Clear on Read enabled. RTC_IT bit of TWL4030_INT_PWR_ISR1
378 * needs 2 reads to clear the interrupt. One read is done in
379 * do_twl4030_pwrirq(). Doing the second read, to clear
380 * the bit.
381 *
382 * FIXME the reason PWR_ISR1 needs an extra read is that
383 * RTC_IF retriggered until we cleared REG_ALARM_M above.
384 * But re-reading like this is a bad hack; by doing so we
385 * risk wrongly clearing status for some other IRQ (losing
386 * the interrupt). Be smarter about handling RTC_UF ...
387 */
388 res = twl4030_i2c_read_u8(TWL4030_MODULE_INT,
389 &rd_reg, TWL4030_INT_PWR_ISR1);
390 if (res)
391 goto out;
392
393 /* Notify RTC core on event */
394 rtc_update_irq(rtc, 1, events);
395
396 ret = IRQ_HANDLED;
397out:
398 return ret;
399}
400
401static struct rtc_class_ops twl4030_rtc_ops = {
402 .ioctl = twl4030_rtc_ioctl,
403 .read_time = twl4030_rtc_read_time,
404 .set_time = twl4030_rtc_set_time,
405 .read_alarm = twl4030_rtc_read_alarm,
406 .set_alarm = twl4030_rtc_set_alarm,
407};
408
409/*----------------------------------------------------------------------*/
410
411static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
412{
413 struct rtc_device *rtc;
414 int ret = 0;
415 int irq = platform_get_irq(pdev, 0);
416 u8 rd_reg;
417
418 if (irq < 0)
419 return irq;
420
421 rtc = rtc_device_register(pdev->name,
422 &pdev->dev, &twl4030_rtc_ops, THIS_MODULE);
423 if (IS_ERR(rtc)) {
424 ret = -EINVAL;
425 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
426 PTR_ERR(rtc));
427 goto out0;
428
429 }
430
431 platform_set_drvdata(pdev, rtc);
432
433 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
434
435 if (ret < 0)
436 goto out1;
437
438 if (rd_reg & BIT_RTC_STATUS_REG_POWER_UP_M)
439 dev_warn(&pdev->dev, "Power up reset detected.\n");
440
441 if (rd_reg & BIT_RTC_STATUS_REG_ALARM_M)
442 dev_warn(&pdev->dev, "Pending Alarm interrupt detected.\n");
443
444 /* Clear RTC Power up reset and pending alarm interrupts */
445 ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_STATUS_REG);
446 if (ret < 0)
447 goto out1;
448
449 ret = request_irq(irq, twl4030_rtc_interrupt,
450 IRQF_TRIGGER_RISING,
451 rtc->dev.bus_id, rtc);
452 if (ret < 0) {
453 dev_err(&pdev->dev, "IRQ is not free.\n");
454 goto out1;
455 }
456
457 /* Check RTC module status, Enable if it is off */
458 ret = twl4030_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG);
459 if (ret < 0)
460 goto out2;
461
462 if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) {
463 dev_info(&pdev->dev, "Enabling TWL4030-RTC.\n");
464 rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M;
465 ret = twl4030_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG);
466 if (ret < 0)
467 goto out2;
468 }
469
470 /* init cached IRQ enable bits */
471 ret = twl4030_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
472 if (ret < 0)
473 goto out2;
474
475 return ret;
476
477
478out2:
479 free_irq(irq, rtc);
480out1:
481 rtc_device_unregister(rtc);
482out0:
483 return ret;
484}
485
486/*
487 * Disable all TWL4030 RTC module interrupts.
488 * Sets status flag to free.
489 */
490static int __devexit twl4030_rtc_remove(struct platform_device *pdev)
491{
492 /* leave rtc running, but disable irqs */
493 struct rtc_device *rtc = platform_get_drvdata(pdev);
494 int irq = platform_get_irq(pdev, 0);
495
496 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
497 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
498
499 free_irq(irq, rtc);
500
501 rtc_device_unregister(rtc);
502 platform_set_drvdata(pdev, NULL);
503 return 0;
504}
505
506static void twl4030_rtc_shutdown(struct platform_device *pdev)
507{
508 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M |
509 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
510}
511
512#ifdef CONFIG_PM
513
514static unsigned char irqstat;
515
516static int twl4030_rtc_suspend(struct platform_device *pdev, pm_message_t state)
517{
518 irqstat = rtc_irq_bits;
519
520 /* REVISIT alarm may need to wake us from sleep */
521 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M |
522 BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
523 return 0;
524}
525
526static int twl4030_rtc_resume(struct platform_device *pdev)
527{
528 set_rtc_irq_bit(irqstat);
529 return 0;
530}
531
532#else
533#define twl4030_rtc_suspend NULL
534#define twl4030_rtc_resume NULL
535#endif
536
537MODULE_ALIAS("platform:twl4030_rtc");
538
539static struct platform_driver twl4030rtc_driver = {
540 .probe = twl4030_rtc_probe,
541 .remove = __devexit_p(twl4030_rtc_remove),
542 .shutdown = twl4030_rtc_shutdown,
543 .suspend = twl4030_rtc_suspend,
544 .resume = twl4030_rtc_resume,
545 .driver = {
546 .owner = THIS_MODULE,
547 .name = "twl4030_rtc",
548 },
549};
550
551static int __init twl4030_rtc_init(void)
552{
553 return platform_driver_register(&twl4030rtc_driver);
554}
555module_init(twl4030_rtc_init);
556
557static void __exit twl4030_rtc_exit(void)
558{
559 platform_driver_unregister(&twl4030rtc_driver);
560}
561module_exit(twl4030_rtc_exit);
562
563MODULE_AUTHOR("Texas Instruments, MontaVista Software");
564MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index 10025d84026..14d4f036a76 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-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index 884b635f028..834dcc6d785 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -360,7 +360,7 @@ static int __devinit rtc_probe(struct platform_device *pdev)
360 spin_unlock_irq(&rtc_lock); 360 spin_unlock_irq(&rtc_lock);
361 361
362 aie_irq = platform_get_irq(pdev, 0); 362 aie_irq = platform_get_irq(pdev, 0);
363 if (aie_irq < 0 || aie_irq >= NR_IRQS) { 363 if (aie_irq < 0 || aie_irq >= nr_irqs) {
364 retval = -EBUSY; 364 retval = -EBUSY;
365 goto err_device_unregister; 365 goto err_device_unregister;
366 } 366 }
@@ -371,7 +371,7 @@ static int __devinit rtc_probe(struct platform_device *pdev)
371 goto err_device_unregister; 371 goto err_device_unregister;
372 372
373 pie_irq = platform_get_irq(pdev, 1); 373 pie_irq = platform_get_irq(pdev, 1);
374 if (pie_irq < 0 || pie_irq >= NR_IRQS) 374 if (pie_irq < 0 || pie_irq >= nr_irqs)
375 goto err_free_irq; 375 goto err_free_irq;
376 376
377 retval = request_irq(pie_irq, rtclong1_interrupt, IRQF_DISABLED, 377 retval = request_irq(pie_irq, rtclong1_interrupt, IRQF_DISABLED,
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 7dcfba1bbfe..310c10795e9 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) {