Skip to content

Commit

Permalink
drivers/rtc/: use bcd2bin/bin2bcd
Browse files Browse the repository at this point in the history
Change drivers/rtc/ to use the new bcd2bin/bin2bcd functions instead of
the obsolete BCD_TO_BIN/BIN_TO_BCD/BCD2BIN/BIN2BCD macros.

Signed-off-by: Adrian Bunk <[email protected]>
Acked-by: Alessandro Zummo <[email protected]>
Cc: David Brownell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
AdrianBunk authored and torvalds committed Oct 20, 2008
1 parent 4110a0d commit fe20ba7
Show file tree
Hide file tree
Showing 30 changed files with 509 additions and 509 deletions.
42 changes: 21 additions & 21 deletions drivers/rtc/rtc-at91rm9200.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ static void at91_rtc_decodetime(unsigned int timereg, unsigned int calreg,
} while ((time != at91_sys_read(timereg)) ||
(date != at91_sys_read(calreg)));

tm->tm_sec = BCD2BIN((time & AT91_RTC_SEC) >> 0);
tm->tm_min = BCD2BIN((time & AT91_RTC_MIN) >> 8);
tm->tm_hour = BCD2BIN((time & AT91_RTC_HOUR) >> 16);
tm->tm_sec = bcd2bin((time & AT91_RTC_SEC) >> 0);
tm->tm_min = bcd2bin((time & AT91_RTC_MIN) >> 8);
tm->tm_hour = bcd2bin((time & AT91_RTC_HOUR) >> 16);

/*
* The Calendar Alarm register does not have a field for
* the year - so these will return an invalid value. When an
* alarm is set, at91_alarm_year wille store the current year.
*/
tm->tm_year = BCD2BIN(date & AT91_RTC_CENT) * 100; /* century */
tm->tm_year += BCD2BIN((date & AT91_RTC_YEAR) >> 8); /* year */
tm->tm_year = bcd2bin(date & AT91_RTC_CENT) * 100; /* century */
tm->tm_year += bcd2bin((date & AT91_RTC_YEAR) >> 8); /* year */

tm->tm_wday = BCD2BIN((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */
tm->tm_mon = BCD2BIN((date & AT91_RTC_MONTH) >> 16) - 1;
tm->tm_mday = BCD2BIN((date & AT91_RTC_DATE) >> 24);
tm->tm_wday = bcd2bin((date & AT91_RTC_DAY) >> 21) - 1; /* day of the week [0-6], Sunday=0 */
tm->tm_mon = bcd2bin((date & AT91_RTC_MONTH) >> 16) - 1;
tm->tm_mday = bcd2bin((date & AT91_RTC_DATE) >> 24);
}

/*
Expand Down Expand Up @@ -106,16 +106,16 @@ static int at91_rtc_settime(struct device *dev, struct rtc_time *tm)
at91_sys_write(AT91_RTC_IDR, AT91_RTC_ACKUPD);

at91_sys_write(AT91_RTC_TIMR,
BIN2BCD(tm->tm_sec) << 0
| BIN2BCD(tm->tm_min) << 8
| BIN2BCD(tm->tm_hour) << 16);
bin2bcd(tm->tm_sec) << 0
| bin2bcd(tm->tm_min) << 8
| bin2bcd(tm->tm_hour) << 16);

at91_sys_write(AT91_RTC_CALR,
BIN2BCD((tm->tm_year + 1900) / 100) /* century */
| BIN2BCD(tm->tm_year % 100) << 8 /* year */
| BIN2BCD(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */
| BIN2BCD(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */
| BIN2BCD(tm->tm_mday) << 24);
bin2bcd((tm->tm_year + 1900) / 100) /* century */
| bin2bcd(tm->tm_year % 100) << 8 /* year */
| bin2bcd(tm->tm_mon + 1) << 16 /* tm_mon starts at zero */
| bin2bcd(tm->tm_wday + 1) << 21 /* day of the week [0-6], Sunday=0 */
| bin2bcd(tm->tm_mday) << 24);

/* Restart Time/Calendar */
cr = at91_sys_read(AT91_RTC_CR);
Expand Down Expand Up @@ -162,13 +162,13 @@ static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)

at91_sys_write(AT91_RTC_IDR, AT91_RTC_ALARM);
at91_sys_write(AT91_RTC_TIMALR,
BIN2BCD(tm.tm_sec) << 0
| BIN2BCD(tm.tm_min) << 8
| BIN2BCD(tm.tm_hour) << 16
bin2bcd(tm.tm_sec) << 0
| bin2bcd(tm.tm_min) << 8
| bin2bcd(tm.tm_hour) << 16
| AT91_RTC_HOUREN | AT91_RTC_MINEN | AT91_RTC_SECEN);
at91_sys_write(AT91_RTC_CALALR,
BIN2BCD(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
| BIN2BCD(tm.tm_mday) << 24
bin2bcd(tm.tm_mon + 1) << 16 /* tm_mon starts at zero */
| bin2bcd(tm.tm_mday) << 24
| AT91_RTC_DATEEN | AT91_RTC_MTHEN);

if (alrm->enabled) {
Expand Down
20 changes: 10 additions & 10 deletions drivers/rtc/rtc-cmos.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,26 @@ static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
/* REVISIT this assumes PC style usage: always BCD */

if (((unsigned)t->time.tm_sec) < 0x60)
t->time.tm_sec = BCD2BIN(t->time.tm_sec);
t->time.tm_sec = bcd2bin(t->time.tm_sec);
else
t->time.tm_sec = -1;
if (((unsigned)t->time.tm_min) < 0x60)
t->time.tm_min = BCD2BIN(t->time.tm_min);
t->time.tm_min = bcd2bin(t->time.tm_min);
else
t->time.tm_min = -1;
if (((unsigned)t->time.tm_hour) < 0x24)
t->time.tm_hour = BCD2BIN(t->time.tm_hour);
t->time.tm_hour = bcd2bin(t->time.tm_hour);
else
t->time.tm_hour = -1;

if (cmos->day_alrm) {
if (((unsigned)t->time.tm_mday) <= 0x31)
t->time.tm_mday = BCD2BIN(t->time.tm_mday);
t->time.tm_mday = bcd2bin(t->time.tm_mday);
else
t->time.tm_mday = -1;
if (cmos->mon_alrm) {
if (((unsigned)t->time.tm_mon) <= 0x12)
t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1;
t->time.tm_mon = bcd2bin(t->time.tm_mon) - 1;
else
t->time.tm_mon = -1;
}
Expand Down Expand Up @@ -331,19 +331,19 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
/* Writing 0xff means "don't care" or "match all". */

mon = t->time.tm_mon + 1;
mon = (mon <= 12) ? BIN2BCD(mon) : 0xff;
mon = (mon <= 12) ? bin2bcd(mon) : 0xff;

mday = t->time.tm_mday;
mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff;
mday = (mday >= 1 && mday <= 31) ? bin2bcd(mday) : 0xff;

hrs = t->time.tm_hour;
hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff;
hrs = (hrs < 24) ? bin2bcd(hrs) : 0xff;

min = t->time.tm_min;
min = (min < 60) ? BIN2BCD(min) : 0xff;
min = (min < 60) ? bin2bcd(min) : 0xff;

sec = t->time.tm_sec;
sec = (sec < 60) ? BIN2BCD(sec) : 0xff;
sec = (sec < 60) ? bin2bcd(sec) : 0xff;

spin_lock_irq(&rtc_lock);

Expand Down
26 changes: 13 additions & 13 deletions drivers/rtc/rtc-ds1216.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
ds1216_switch_ds_to_clock(priv->ioaddr);
ds1216_read(priv->ioaddr, (u8 *)&regs);

tm->tm_sec = BCD2BIN(regs.sec);
tm->tm_min = BCD2BIN(regs.min);
tm->tm_sec = bcd2bin(regs.sec);
tm->tm_min = bcd2bin(regs.min);
if (regs.hour & DS1216_HOUR_1224) {
/* AM/PM mode */
tm->tm_hour = BCD2BIN(regs.hour & 0x1f);
tm->tm_hour = bcd2bin(regs.hour & 0x1f);
if (regs.hour & DS1216_HOUR_AMPM)
tm->tm_hour += 12;
} else
tm->tm_hour = BCD2BIN(regs.hour & 0x3f);
tm->tm_hour = bcd2bin(regs.hour & 0x3f);
tm->tm_wday = (regs.wday & 7) - 1;
tm->tm_mday = BCD2BIN(regs.mday & 0x3f);
tm->tm_mon = BCD2BIN(regs.month & 0x1f);
tm->tm_year = BCD2BIN(regs.year);
tm->tm_mday = bcd2bin(regs.mday & 0x3f);
tm->tm_mon = bcd2bin(regs.month & 0x1f);
tm->tm_year = bcd2bin(regs.year);
if (tm->tm_year < 70)
tm->tm_year += 100;
return 0;
Expand All @@ -114,19 +114,19 @@ static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
ds1216_read(priv->ioaddr, (u8 *)&regs);

regs.tsec = 0; /* clear 0.1 and 0.01 seconds */
regs.sec = BIN2BCD(tm->tm_sec);
regs.min = BIN2BCD(tm->tm_min);
regs.sec = bin2bcd(tm->tm_sec);
regs.min = bin2bcd(tm->tm_min);
regs.hour &= DS1216_HOUR_1224;
if (regs.hour && tm->tm_hour > 12) {
regs.hour |= DS1216_HOUR_AMPM;
tm->tm_hour -= 12;
}
regs.hour |= BIN2BCD(tm->tm_hour);
regs.hour |= bin2bcd(tm->tm_hour);
regs.wday &= ~7;
regs.wday |= tm->tm_wday;
regs.mday = BIN2BCD(tm->tm_mday);
regs.month = BIN2BCD(tm->tm_mon);
regs.year = BIN2BCD(tm->tm_year % 100);
regs.mday = bin2bcd(tm->tm_mday);
regs.month = bin2bcd(tm->tm_mon);
regs.year = bin2bcd(tm->tm_year % 100);

ds1216_switch_ds_to_clock(priv->ioaddr);
ds1216_write(priv->ioaddr, (u8 *)&regs);
Expand Down
28 changes: 14 additions & 14 deletions drivers/rtc/rtc-ds1302.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)

spin_lock_irq(&rtc->lock);

tm->tm_sec = BCD2BIN(ds1302_readbyte(RTC_ADDR_SEC));
tm->tm_min = BCD2BIN(ds1302_readbyte(RTC_ADDR_MIN));
tm->tm_hour = BCD2BIN(ds1302_readbyte(RTC_ADDR_HOUR));
tm->tm_wday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DAY));
tm->tm_mday = BCD2BIN(ds1302_readbyte(RTC_ADDR_DATE));
tm->tm_mon = BCD2BIN(ds1302_readbyte(RTC_ADDR_MON)) - 1;
tm->tm_year = BCD2BIN(ds1302_readbyte(RTC_ADDR_YEAR));
tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC));
tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN));
tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR));
tm->tm_wday = bcd2bin(ds1302_readbyte(RTC_ADDR_DAY));
tm->tm_mday = bcd2bin(ds1302_readbyte(RTC_ADDR_DATE));
tm->tm_mon = bcd2bin(ds1302_readbyte(RTC_ADDR_MON)) - 1;
tm->tm_year = bcd2bin(ds1302_readbyte(RTC_ADDR_YEAR));

if (tm->tm_year < 70)
tm->tm_year += 100;
Expand Down Expand Up @@ -141,13 +141,13 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
/* Stop RTC */
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);

ds1302_writebyte(RTC_ADDR_SEC, BIN2BCD(tm->tm_sec));
ds1302_writebyte(RTC_ADDR_MIN, BIN2BCD(tm->tm_min));
ds1302_writebyte(RTC_ADDR_HOUR, BIN2BCD(tm->tm_hour));
ds1302_writebyte(RTC_ADDR_DAY, BIN2BCD(tm->tm_wday));
ds1302_writebyte(RTC_ADDR_DATE, BIN2BCD(tm->tm_mday));
ds1302_writebyte(RTC_ADDR_MON, BIN2BCD(tm->tm_mon + 1));
ds1302_writebyte(RTC_ADDR_YEAR, BIN2BCD(tm->tm_year % 100));
ds1302_writebyte(RTC_ADDR_SEC, bin2bcd(tm->tm_sec));
ds1302_writebyte(RTC_ADDR_MIN, bin2bcd(tm->tm_min));
ds1302_writebyte(RTC_ADDR_HOUR, bin2bcd(tm->tm_hour));
ds1302_writebyte(RTC_ADDR_DAY, bin2bcd(tm->tm_wday));
ds1302_writebyte(RTC_ADDR_DATE, bin2bcd(tm->tm_mday));
ds1302_writebyte(RTC_ADDR_MON, bin2bcd(tm->tm_mon + 1));
ds1302_writebyte(RTC_ADDR_YEAR, bin2bcd(tm->tm_year % 100));

/* Start RTC */
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
Expand Down
38 changes: 19 additions & 19 deletions drivers/rtc/rtc-ds1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ static unsigned bcd2hour(u8 bcd)
hour = 12;
bcd &= ~DS1305_HR_PM;
}
hour += BCD2BIN(bcd);
hour += bcd2bin(bcd);
return hour - 1;
}
return BCD2BIN(bcd);
return bcd2bin(bcd);
}

static u8 hour2bcd(bool hr12, int hour)
{
if (hr12) {
hour++;
if (hour <= 12)
return DS1305_HR_12 | BIN2BCD(hour);
return DS1305_HR_12 | bin2bcd(hour);
hour -= 12;
return DS1305_HR_12 | DS1305_HR_PM | BIN2BCD(hour);
return DS1305_HR_12 | DS1305_HR_PM | bin2bcd(hour);
}
return BIN2BCD(hour);
return bin2bcd(hour);
}

/*----------------------------------------------------------------------*/
Expand Down Expand Up @@ -206,13 +206,13 @@ static int ds1305_get_time(struct device *dev, struct rtc_time *time)
buf[4], buf[5], buf[6]);

/* Decode the registers */
time->tm_sec = BCD2BIN(buf[DS1305_SEC]);
time->tm_min = BCD2BIN(buf[DS1305_MIN]);
time->tm_sec = bcd2bin(buf[DS1305_SEC]);
time->tm_min = bcd2bin(buf[DS1305_MIN]);
time->tm_hour = bcd2hour(buf[DS1305_HOUR]);
time->tm_wday = buf[DS1305_WDAY] - 1;
time->tm_mday = BCD2BIN(buf[DS1305_MDAY]);
time->tm_mon = BCD2BIN(buf[DS1305_MON]) - 1;
time->tm_year = BCD2BIN(buf[DS1305_YEAR]) + 100;
time->tm_mday = bcd2bin(buf[DS1305_MDAY]);
time->tm_mon = bcd2bin(buf[DS1305_MON]) - 1;
time->tm_year = bcd2bin(buf[DS1305_YEAR]) + 100;

dev_vdbg(dev, "%s secs=%d, mins=%d, "
"hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
Expand All @@ -239,13 +239,13 @@ static int ds1305_set_time(struct device *dev, struct rtc_time *time)
/* Write registers starting at the first time/date address. */
*bp++ = DS1305_WRITE | DS1305_SEC;

*bp++ = BIN2BCD(time->tm_sec);
*bp++ = BIN2BCD(time->tm_min);
*bp++ = bin2bcd(time->tm_sec);
*bp++ = bin2bcd(time->tm_min);
*bp++ = hour2bcd(ds1305->hr12, time->tm_hour);
*bp++ = (time->tm_wday < 7) ? (time->tm_wday + 1) : 1;
*bp++ = BIN2BCD(time->tm_mday);
*bp++ = BIN2BCD(time->tm_mon + 1);
*bp++ = BIN2BCD(time->tm_year - 100);
*bp++ = bin2bcd(time->tm_mday);
*bp++ = bin2bcd(time->tm_mon + 1);
*bp++ = bin2bcd(time->tm_year - 100);

dev_dbg(dev, "%s: %02x %02x %02x, %02x %02x %02x %02x\n",
"write", buf[1], buf[2], buf[3],
Expand Down Expand Up @@ -329,8 +329,8 @@ static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
* fill in the rest ... and also handle rollover to tomorrow when
* that's needed.
*/
alm->time.tm_sec = BCD2BIN(buf[DS1305_SEC]);
alm->time.tm_min = BCD2BIN(buf[DS1305_MIN]);
alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]);
alm->time.tm_min = bcd2bin(buf[DS1305_MIN]);
alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]);
alm->time.tm_mday = -1;
alm->time.tm_mon = -1;
Expand Down Expand Up @@ -387,8 +387,8 @@ static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)

/* write alarm */
buf[0] = DS1305_WRITE | DS1305_ALM0(DS1305_SEC);
buf[1 + DS1305_SEC] = BIN2BCD(alm->time.tm_sec);
buf[1 + DS1305_MIN] = BIN2BCD(alm->time.tm_min);
buf[1 + DS1305_SEC] = bin2bcd(alm->time.tm_sec);
buf[1 + DS1305_MIN] = bin2bcd(alm->time.tm_min);
buf[1 + DS1305_HOUR] = hour2bcd(ds1305->hr12, alm->time.tm_hour);
buf[1 + DS1305_WDAY] = DS1305_ALM_DISABLE;

Expand Down
Loading

0 comments on commit fe20ba7

Please sign in to comment.