summaryrefslogtreecommitdiff
path: root/drivers/rtc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/ds12887.c12
-rw-r--r--drivers/rtc/ds1306.c18
-rw-r--r--drivers/rtc/ds1307.c13
-rw-r--r--drivers/rtc/ds1337.c13
-rw-r--r--drivers/rtc/ds1556.c12
-rw-r--r--drivers/rtc/ds164x.c12
-rw-r--r--drivers/rtc/ds174x.c12
-rw-r--r--drivers/rtc/ds3231.c12
-rw-r--r--drivers/rtc/isl1208.c12
-rw-r--r--drivers/rtc/m41t11.c11
-rw-r--r--drivers/rtc/m41t60.c10
-rw-r--r--drivers/rtc/m41t62.c25
-rw-r--r--drivers/rtc/m41t94.c124
-rw-r--r--drivers/rtc/m48t35ax.c12
-rw-r--r--drivers/rtc/max6900.c10
-rw-r--r--drivers/rtc/mc146818.c12
-rw-r--r--drivers/rtc/mk48t59.c10
-rw-r--r--drivers/rtc/pcf8563.c12
-rw-r--r--drivers/rtc/rs5c372.c14
-rw-r--r--drivers/rtc/rtc4543.c29
-rw-r--r--drivers/rtc/rx8025.c12
-rw-r--r--drivers/rtc/s3c24x0_rtc.c10
-rw-r--r--drivers/rtc/s3c44b0_rtc.c43
-rw-r--r--drivers/rtc/x1205.c29
25 files changed, 186 insertions, 294 deletions
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 822dc1a..ea7d899 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -44,6 +44,7 @@ COBJS-$(CONFIG_RTC_ISL1208) += isl1208.o
COBJS-$(CONFIG_RTC_M41T11) += m41t11.o
COBJS-$(CONFIG_RTC_M41T60) += m41t60.o
COBJS-$(CONFIG_RTC_M41T62) += m41t62.o
+COBJS-$(CONFIG_RTC_M41T94) += m41t94.o
COBJS-$(CONFIG_RTC_M48T35A) += m48t35ax.o
COBJS-$(CONFIG_RTC_MAX6900) += max6900.o
COBJS-$(CONFIG_RTC_MC13783) += mc13783-rtc.o
diff --git a/drivers/rtc/ds12887.c b/drivers/rtc/ds12887.c
index 25ca133..486105f 100644
--- a/drivers/rtc/ds12887.c
+++ b/drivers/rtc/ds12887.c
@@ -76,18 +76,6 @@ static void rtc_write (uchar reg, uchar val)
# error Board specific rtc access functions should be supplied
#endif
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
-/* ------------------------------------------------------------------------- */
-
int rtc_get (struct rtc_time *tmp)
{
uchar sec, min, hour, mday, wday, mon, year;
diff --git a/drivers/rtc/ds1306.c b/drivers/rtc/ds1306.c
index 75f88a9..288c5f8 100644
--- a/drivers/rtc/ds1306.c
+++ b/drivers/rtc/ds1306.c
@@ -62,9 +62,6 @@
#define RTC_USER_RAM_BASE 0x20
-static unsigned int bin2bcd (unsigned int n);
-static unsigned char bcd2bin (unsigned char c);
-
/* ************************************************************************* */
#ifdef CONFIG_SXNI855T /* !!! SHOULD BE CHANGED TO NEW CODE !!! */
@@ -459,19 +456,4 @@ static void rtc_write (unsigned char reg, unsigned char val)
#endif /* end of code exclusion (see #ifdef CONFIG_SXNI855T above) */
-/* ------------------------------------------------------------------------- */
-
-static unsigned char bcd2bin (unsigned char n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-/* ------------------------------------------------------------------------- */
-
-static unsigned int bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-/* ------------------------------------------------------------------------- */
-
#endif
diff --git a/drivers/rtc/ds1307.c b/drivers/rtc/ds1307.c
index 0650d91..079aa99 100644
--- a/drivers/rtc/ds1307.c
+++ b/drivers/rtc/ds1307.c
@@ -76,8 +76,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
@@ -195,15 +193,4 @@ static void rtc_write (uchar reg, uchar val)
{
i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
}
-
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/ds1337.c b/drivers/rtc/ds1337.c
index 58e3966..a71ab5d 100644
--- a/drivers/rtc/ds1337.c
+++ b/drivers/rtc/ds1337.c
@@ -77,9 +77,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
-
/*
* Get the current time from the RTC
@@ -191,14 +188,4 @@ static void rtc_write (uchar reg, uchar val)
i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/ds1556.c b/drivers/rtc/ds1556.c
index 763d22a..25a0b64 100644
--- a/drivers/rtc/ds1556.c
+++ b/drivers/rtc/ds1556.c
@@ -40,8 +40,6 @@
static uchar rtc_read( unsigned int addr );
static void rtc_write( unsigned int addr, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin(uchar c);
#define RTC_BASE ( CONFIG_SYS_NVRAM_SIZE + CONFIG_SYS_NVRAM_BASE_ADDR )
@@ -195,14 +193,4 @@ static void rtc_write( unsigned int addr, uchar val )
*(volatile unsigned char*)(addr) = val;
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/ds164x.c b/drivers/rtc/ds164x.c
index 1e96679..9f306d1 100644
--- a/drivers/rtc/ds164x.c
+++ b/drivers/rtc/ds164x.c
@@ -41,8 +41,6 @@
static uchar rtc_read(unsigned int addr );
static void rtc_write(unsigned int addr, uchar val);
-static uchar bin2bcd(unsigned int n);
-static unsigned bcd2bin(uchar c);
#define RTC_EPOCH 2000 /* century */
@@ -191,14 +189,4 @@ static void rtc_write( unsigned int addr, uchar val )
*(volatile unsigned char*)(addr) = val;
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/ds174x.c b/drivers/rtc/ds174x.c
index 738d118..5a55dc8 100644
--- a/drivers/rtc/ds174x.c
+++ b/drivers/rtc/ds174x.c
@@ -37,8 +37,6 @@
static uchar rtc_read( unsigned int addr );
static void rtc_write( unsigned int addr, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin(uchar c);
#define RTC_BASE ( CONFIG_SYS_NVRAM_SIZE + CONFIG_SYS_NVRAM_BASE_ADDR )
@@ -192,14 +190,4 @@ static void rtc_write( unsigned int addr, uchar val )
out8( addr, val );
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/ds3231.c b/drivers/rtc/ds3231.c
index ef03358..134a0e4 100644
--- a/drivers/rtc/ds3231.c
+++ b/drivers/rtc/ds3231.c
@@ -79,8 +79,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
/*
@@ -186,14 +184,4 @@ static void rtc_write (uchar reg, uchar val)
i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/isl1208.c b/drivers/rtc/isl1208.c
index 71f63d5..07591b7 100644
--- a/drivers/rtc/isl1208.c
+++ b/drivers/rtc/isl1208.c
@@ -66,8 +66,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
@@ -160,13 +158,3 @@ static void rtc_write (uchar reg, uchar val)
{
i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
}
-
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
diff --git a/drivers/rtc/m41t11.c b/drivers/rtc/m41t11.c
index 3a77c1b..e0c27e1 100644
--- a/drivers/rtc/m41t11.c
+++ b/drivers/rtc/m41t11.c
@@ -45,17 +45,6 @@
#if defined(CONFIG_SYS_I2C_RTC_ADDR) && defined(CONFIG_CMD_DATE)
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
-
/* ------------------------------------------------------------------------- */
/*
these are simple defines for the chip local to here so they aren't too
diff --git a/drivers/rtc/m41t60.c b/drivers/rtc/m41t60.c
index e34a5f4..632fe4b 100644
--- a/drivers/rtc/m41t60.c
+++ b/drivers/rtc/m41t60.c
@@ -36,16 +36,6 @@
#if defined(CONFIG_SYS_I2C_RTC_ADDR) && defined(CONFIG_CMD_DATE)
-static unsigned bcd2bin(uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd(unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
/*
* Convert between century and "century bits" (CB1 and CB0). These routines
* assume years are in the range 1900 - 2299.
diff --git a/drivers/rtc/m41t62.c b/drivers/rtc/m41t62.c
index cfe84f9..62c2446 100644
--- a/drivers/rtc/m41t62.c
+++ b/drivers/rtc/m41t62.c
@@ -31,7 +31,6 @@
#include <command.h>
#include <rtc.h>
#include <i2c.h>
-#include <bcd.h>
#if defined(CONFIG_CMD_DATE)
@@ -76,16 +75,16 @@ int rtc_get(struct rtc_time *tm)
buf[0], buf[1], buf[2], buf[3],
buf[4], buf[5], buf[6], buf[7]);
- tm->tm_sec = BCD2BIN(buf[M41T62_REG_SEC] & 0x7f);
- tm->tm_min = BCD2BIN(buf[M41T62_REG_MIN] & 0x7f);
- tm->tm_hour = BCD2BIN(buf[M41T62_REG_HOUR] & 0x3f);
- tm->tm_mday = BCD2BIN(buf[M41T62_REG_DAY] & 0x3f);
+ tm->tm_sec = bcd2bin(buf[M41T62_REG_SEC] & 0x7f);
+ tm->tm_min = bcd2bin(buf[M41T62_REG_MIN] & 0x7f);
+ tm->tm_hour = bcd2bin(buf[M41T62_REG_HOUR] & 0x3f);
+ tm->tm_mday = bcd2bin(buf[M41T62_REG_DAY] & 0x3f);
tm->tm_wday = buf[M41T62_REG_WDAY] & 0x07;
- tm->tm_mon = BCD2BIN(buf[M41T62_REG_MON] & 0x1f);
+ tm->tm_mon = bcd2bin(buf[M41T62_REG_MON] & 0x1f);
/* assume 20YY not 19YY, and ignore the Century Bit */
/* U-Boot needs to add 1900 here */
- tm->tm_year = BCD2BIN(buf[M41T62_REG_YEAR]) + 100 + 1900;
+ tm->tm_year = bcd2bin(buf[M41T62_REG_YEAR]) + 100 + 1900;
debug("%s: tm is secs=%d, mins=%d, hours=%d, "
"mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -109,19 +108,19 @@ int rtc_set(struct rtc_time *tm)
/* Merge time-data and register flags into buf[0..7] */
buf[M41T62_REG_SSEC] = 0;
buf[M41T62_REG_SEC] =
- BIN2BCD(tm->tm_sec) | (buf[M41T62_REG_SEC] & ~0x7f);
+ bin2bcd(tm->tm_sec) | (buf[M41T62_REG_SEC] & ~0x7f);
buf[M41T62_REG_MIN] =
- BIN2BCD(tm->tm_min) | (buf[M41T62_REG_MIN] & ~0x7f);
+ bin2bcd(tm->tm_min) | (buf[M41T62_REG_MIN] & ~0x7f);
buf[M41T62_REG_HOUR] =
- BIN2BCD(tm->tm_hour) | (buf[M41T62_REG_HOUR] & ~0x3f) ;
+ bin2bcd(tm->tm_hour) | (buf[M41T62_REG_HOUR] & ~0x3f) ;
buf[M41T62_REG_WDAY] =
(tm->tm_wday & 0x07) | (buf[M41T62_REG_WDAY] & ~0x07);
buf[M41T62_REG_DAY] =
- BIN2BCD(tm->tm_mday) | (buf[M41T62_REG_DAY] & ~0x3f);
+ bin2bcd(tm->tm_mday) | (buf[M41T62_REG_DAY] & ~0x3f);
buf[M41T62_REG_MON] =
- BIN2BCD(tm->tm_mon) | (buf[M41T62_REG_MON] & ~0x1f);
+ bin2bcd(tm->tm_mon) | (buf[M41T62_REG_MON] & ~0x1f);
/* assume 20YY not 19YY */
- buf[M41T62_REG_YEAR] = BIN2BCD(tm->tm_year % 100);
+ buf[M41T62_REG_YEAR] = bin2bcd(tm->tm_year % 100);
if (i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, buf, M41T62_DATETIME_REG_SIZE)) {
printf("I2C write failed in %s()\n", __func__);
diff --git a/drivers/rtc/m41t94.c b/drivers/rtc/m41t94.c
new file mode 100644
index 0000000..02b41d9
--- /dev/null
+++ b/drivers/rtc/m41t94.c
@@ -0,0 +1,124 @@
+/*
+ * Driver for ST M41T94 SPI RTC
+ *
+ * Taken from the Linux kernel drivier:
+ * Copyright (C) 2008 Kim B. Heino
+ *
+ * Adaptation for U-Boot:
+ * Copyright (C) 2009
+ * Albin Tonnerre, Free Electrons <albin.tonnerre@free-electrons.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <rtc.h>
+#include <spi.h>
+
+static struct spi_slave *slave;
+
+#define M41T94_REG_SECONDS 0x01
+#define M41T94_REG_MINUTES 0x02
+#define M41T94_REG_HOURS 0x03
+#define M41T94_REG_WDAY 0x04
+#define M41T94_REG_DAY 0x05
+#define M41T94_REG_MONTH 0x06
+#define M41T94_REG_YEAR 0x07
+#define M41T94_REG_HT 0x0c
+
+#define M41T94_BIT_HALT 0x40
+#define M41T94_BIT_STOP 0x80
+#define M41T94_BIT_CB 0x40
+#define M41T94_BIT_CEB 0x80
+
+int rtc_set(struct rtc_time *tm)
+{
+ u8 buf[8]; /* write cmd + 7 registers */
+ int ret;
+
+ if (!slave) {
+ slave = spi_setup_slave(CONFIG_M41T94_SPI_BUS,
+ CONFIG_M41T94_SPI_CS, 1000000,
+ SPI_MODE_3);
+ if (!slave)
+ return -1;
+ }
+ spi_claim_bus(slave);
+
+ buf[0] = 0x80 | M41T94_REG_SECONDS; /* write time + date */
+ buf[M41T94_REG_SECONDS] = bin2bcd(tm->tm_sec);
+ buf[M41T94_REG_MINUTES] = bin2bcd(tm->tm_min);
+ buf[M41T94_REG_HOURS] = bin2bcd(tm->tm_hour);
+ buf[M41T94_REG_WDAY] = bin2bcd(tm->tm_wday + 1);
+ buf[M41T94_REG_DAY] = bin2bcd(tm->tm_mday);
+ buf[M41T94_REG_MONTH] = bin2bcd(tm->tm_mon + 1);
+
+ buf[M41T94_REG_HOURS] |= M41T94_BIT_CEB;
+ if (tm->tm_year >= 100)
+ buf[M41T94_REG_HOURS] |= M41T94_BIT_CB;
+ buf[M41T94_REG_YEAR] = bin2bcd(tm->tm_year % 100);
+
+ ret = spi_xfer(slave, 64, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ spi_release_bus(slave);
+ return ret;
+}
+
+int rtc_get(struct rtc_time *tm)
+{
+ u8 buf[2];
+ int ret, hour;
+
+ if (!slave) {
+ slave = spi_setup_slave(CONFIG_M41T94_SPI_BUS,
+ CONFIG_M41T94_SPI_CS, 1000000,
+ SPI_MODE_3);
+ if (!slave)
+ return -1;
+ }
+ spi_claim_bus(slave);
+
+ /* clear halt update bit */
+ ret = spi_w8r8(slave, M41T94_REG_HT);
+ if (ret < 0)
+ return ret;
+ if (ret & M41T94_BIT_HALT) {
+ buf[0] = 0x80 | M41T94_REG_HT;
+ buf[1] = ret & ~M41T94_BIT_HALT;
+ spi_xfer(slave, 16, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ }
+
+ /* clear stop bit */
+ ret = spi_w8r8(slave, M41T94_REG_SECONDS);
+ if (ret < 0)
+ return ret;
+ if (ret & M41T94_BIT_STOP) {
+ buf[0] = 0x80 | M41T94_REG_SECONDS;
+ buf[1] = ret & ~M41T94_BIT_STOP;
+ spi_xfer(slave, 16, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END);
+ }
+
+ tm->tm_sec = bcd2bin(spi_w8r8(slave, M41T94_REG_SECONDS));
+ tm->tm_min = bcd2bin(spi_w8r8(slave, M41T94_REG_MINUTES));
+ hour = spi_w8r8(slave, M41T94_REG_HOURS);
+ tm->tm_hour = bcd2bin(hour & 0x3f);
+ tm->tm_wday = bcd2bin(spi_w8r8(slave, M41T94_REG_WDAY)) - 1;
+ tm->tm_mday = bcd2bin(spi_w8r8(slave, M41T94_REG_DAY));
+ tm->tm_mon = bcd2bin(spi_w8r8(slave, M41T94_REG_MONTH)) - 1;
+ tm->tm_year = bcd2bin(spi_w8r8(slave, M41T94_REG_YEAR));
+ if ((hour & M41T94_BIT_CB) || !(hour & M41T94_BIT_CEB))
+ tm->tm_year += 100;
+
+ spi_release_bus(slave);
+ return 0;
+}
+
+void rtc_reset(void)
+{
+ /*
+ * Could not be tested as the reset pin is not wired on
+ * the sbc35-ag20 board
+ */
+ return 0;
+}
diff --git a/drivers/rtc/m48t35ax.c b/drivers/rtc/m48t35ax.c
index 1482edd..29b36c1 100644
--- a/drivers/rtc/m48t35ax.c
+++ b/drivers/rtc/m48t35ax.c
@@ -37,8 +37,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
@@ -157,14 +155,4 @@ static void rtc_write (uchar reg, uchar val)
((CONFIG_SYS_NVRAM_BASE_ADDR + CONFIG_SYS_NVRAM_SIZE - 8) + reg) = val;
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/max6900.c b/drivers/rtc/max6900.c
index 7c99c5e..74637d1 100644
--- a/drivers/rtc/max6900.c
+++ b/drivers/rtc/max6900.c
@@ -51,16 +51,6 @@ static void rtc_write (uchar reg, uchar val)
udelay(2500);
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
/* ------------------------------------------------------------------------- */
int rtc_get (struct rtc_time *tmp)
diff --git a/drivers/rtc/mc146818.c b/drivers/rtc/mc146818.c
index 38484ce..d68b438 100644
--- a/drivers/rtc/mc146818.c
+++ b/drivers/rtc/mc146818.c
@@ -35,8 +35,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin(uchar c);
#define RTC_PORT_MC146818 CONFIG_SYS_ISA_IO_BASE_ADDRESS + 0x70
#define RTC_SECONDS 0x00
@@ -168,14 +166,4 @@ static void rtc_write (uchar reg, uchar val)
}
#endif
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/mk48t59.c b/drivers/rtc/mk48t59.c
index dabf322..b176882 100644
--- a/drivers/rtc/mk48t59.c
+++ b/drivers/rtc/mk48t59.c
@@ -97,16 +97,6 @@ static void rtc_write (short reg, uchar val)
# error Board specific rtc access functions should be supplied
#endif
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
/* ------------------------------------------------------------------------- */
void *nvram_read(void *dest, const short src, size_t count)
diff --git a/drivers/rtc/pcf8563.c b/drivers/rtc/pcf8563.c
index cd9fb65..339e5f6 100644
--- a/drivers/rtc/pcf8563.c
+++ b/drivers/rtc/pcf8563.c
@@ -36,8 +36,6 @@
static uchar rtc_read (uchar reg);
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin(uchar c);
/* ------------------------------------------------------------------------- */
@@ -137,14 +135,4 @@ static void rtc_write (uchar reg, uchar val)
i2c_reg_write (CONFIG_SYS_I2C_RTC_ADDR, reg, val);
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif
diff --git a/drivers/rtc/rs5c372.c b/drivers/rtc/rs5c372.c
index d6cd7c8..90bbb4e 100644
--- a/drivers/rtc/rs5c372.c
+++ b/drivers/rtc/rs5c372.c
@@ -67,9 +67,6 @@ static unsigned int rtc_debug = DEBUG;
#define HOURS_24(n) bcd2bin((n) & 0x3F)
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
-
static int setup_done = 0;
static int
@@ -291,15 +288,4 @@ rtc_reset (void)
return;
}
-static unsigned int
-bcd2bin (unsigned char n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char
-bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
#endif
diff --git a/drivers/rtc/rtc4543.c b/drivers/rtc/rtc4543.c
index 242d9bc..046aa67 100644
--- a/drivers/rtc/rtc4543.c
+++ b/drivers/rtc/rtc4543.c
@@ -25,7 +25,6 @@
#include <common.h>
#include <command.h>
#include <config.h>
-#include <bcd.h>
#include <rtc.h>
#include <tws.h>
@@ -49,13 +48,13 @@ int rtc_get(struct rtc_time *tm)
/* Read 52 bits into our buffer */
tws_read(buffer, 52);
- tm->tm_sec = BCD2BIN( buffer[0] & 0x7F);
- tm->tm_min = BCD2BIN( buffer[1] & 0x7F);
- tm->tm_hour = BCD2BIN( buffer[2] & 0x3F);
- tm->tm_wday = BCD2BIN( buffer[3] & 0x07);
- tm->tm_mday = BCD2BIN((buffer[3] & 0xF0) >> 4 | (buffer[4] & 0x0F) << 4);
- tm->tm_mon = BCD2BIN((buffer[4] & 0x30) >> 4 | (buffer[5] & 0x0F) << 4);
- tm->tm_year = BCD2BIN((buffer[5] & 0xF0) >> 4 | (buffer[6] & 0x0F) << 4) + 2000;
+ tm->tm_sec = bcd2bin( buffer[0] & 0x7F);
+ tm->tm_min = bcd2bin( buffer[1] & 0x7F);
+ tm->tm_hour = bcd2bin( buffer[2] & 0x3F);
+ tm->tm_wday = bcd2bin( buffer[3] & 0x07);
+ tm->tm_mday = bcd2bin((buffer[3] & 0xF0) >> 4 | (buffer[4] & 0x0F) << 4);
+ tm->tm_mon = bcd2bin((buffer[4] & 0x30) >> 4 | (buffer[5] & 0x0F) << 4);
+ tm->tm_year = bcd2bin((buffer[5] & 0xF0) >> 4 | (buffer[6] & 0x0F) << 4) + 2000;
tm->tm_yday = 0;
tm->tm_isdst = 0;
@@ -81,17 +80,17 @@ int rtc_set(struct rtc_time *tm)
tm->tm_hour, tm->tm_min, tm->tm_sec);
memset(buffer, 0, 7);
- buffer[0] = BIN2BCD(tm->tm_sec);
- buffer[1] = BIN2BCD(tm->tm_min);
- buffer[2] = BIN2BCD(tm->tm_hour);
- buffer[3] = BIN2BCD(tm->tm_wday);
- tmp = BIN2BCD(tm->tm_mday);
+ buffer[0] = bin2bcd(tm->tm_sec);
+ buffer[1] = bin2bcd(tm->tm_min);
+ buffer[2] = bin2bcd(tm->tm_hour);
+ buffer[3] = bin2bcd(tm->tm_wday);
+ tmp = bin2bcd(tm->tm_mday);
buffer[3] |= (tmp & 0x0F) << 4;
buffer[4] = (tmp & 0xF0) >> 4;
- tmp = BIN2BCD(tm->tm_mon);
+ tmp = bin2bcd(tm->tm_mon);
buffer[4] |= (tmp & 0x0F) << 4;
buffer[5] = (tmp & 0xF0) >> 4;
- tmp = BIN2BCD(tm->tm_year % 100);
+ tmp = bin2bcd(tm->tm_year % 100);
buffer[5] |= (tmp & 0x0F) << 4;
buffer[6] = (tmp & 0xF0) >> 4;
diff --git a/drivers/rtc/rx8025.c b/drivers/rtc/rx8025.c
index da87394..64eb1cd 100644
--- a/drivers/rtc/rx8025.c
+++ b/drivers/rtc/rx8025.c
@@ -90,8 +90,6 @@
#define rtc_read(reg) buf[((reg) + 1) & 0xf]
static void rtc_write (uchar reg, uchar val);
-static uchar bin2bcd (unsigned int n);
-static unsigned bcd2bin (uchar c);
/*
* Get the current time from the RTC
@@ -226,14 +224,4 @@ static void rtc_write (uchar reg, uchar val)
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
#endif /* CONFIG_RTC_RX8025 && CONFIG_CMD_DATE */
diff --git a/drivers/rtc/s3c24x0_rtc.c b/drivers/rtc/s3c24x0_rtc.c
index 0d3372f..e10db9a 100644
--- a/drivers/rtc/s3c24x0_rtc.c
+++ b/drivers/rtc/s3c24x0_rtc.c
@@ -58,16 +58,6 @@ static inline void SetRTC_Access(RTC_ACCESS a)
}
}
-static unsigned bcd2bin (uchar n)
-{
- return ((((n >> 4) & 0x0F) * 10) + (n & 0x0F));
-}
-
-static unsigned char bin2bcd (unsigned int n)
-{
- return (((n / 10) << 4) | (n % 10));
-}
-
/* ------------------------------------------------------------------------- */
int rtc_get (struct rtc_time *tmp)
diff --git a/drivers/rtc/s3c44b0_rtc.c b/drivers/rtc/s3c44b0_rtc.c
index bfb744a..d087d8a 100644
--- a/drivers/rtc/s3c44b0_rtc.c
+++ b/drivers/rtc/s3c44b0_rtc.c
@@ -32,29 +32,28 @@
#include <command.h>
#include <asm/hardware.h>
#include <rtc.h>
-#include <bcd.h>
int rtc_get (struct rtc_time* tm)
{
RTCCON |= 1;
- tm->tm_year = BCD2BIN(BCDYEAR);
- tm->tm_mon = BCD2BIN(BCDMON);
- tm->tm_wday = BCD2BIN(BCDDATE);
- tm->tm_mday = BCD2BIN(BCDDAY);
- tm->tm_hour = BCD2BIN(BCDHOUR);
- tm->tm_min = BCD2BIN(BCDMIN);
- tm->tm_sec = BCD2BIN(BCDSEC);
+ tm->tm_year = bcd2bin(BCDYEAR);
+ tm->tm_mon = bcd2bin(BCDMON);
+ tm->tm_wday = bcd2bin(BCDDATE);
+ tm->tm_mday = bcd2bin(BCDDAY);
+ tm->tm_hour = bcd2bin(BCDHOUR);
+ tm->tm_min = bcd2bin(BCDMIN);
+ tm->tm_sec = bcd2bin(BCDSEC);
if (tm->tm_sec==0) {
/* we have to re-read the rtc data because of the "one second deviation" problem */
/* see RTC datasheet for more info about it */
- tm->tm_year = BCD2BIN(BCDYEAR);
- tm->tm_mon = BCD2BIN(BCDMON);
- tm->tm_mday = BCD2BIN(BCDDAY);
- tm->tm_wday = BCD2BIN(BCDDATE);
- tm->tm_hour = BCD2BIN(BCDHOUR);
- tm->tm_min = BCD2BIN(BCDMIN);
- tm->tm_sec = BCD2BIN(BCDSEC);
+ tm->tm_year = bcd2bin(BCDYEAR);
+ tm->tm_mon = bcd2bin(BCDMON);
+ tm->tm_mday = bcd2bin(BCDDAY);
+ tm->tm_wday = bcd2bin(BCDDATE);
+ tm->tm_hour = bcd2bin(BCDHOUR);
+ tm->tm_min = bcd2bin(BCDMIN);
+ tm->tm_sec = bcd2bin(BCDSEC);
}
RTCCON &= ~1;
@@ -75,13 +74,13 @@ int rtc_set (struct rtc_time* tm)
tm->tm_year -= 2000;
RTCCON |= 1;
- BCDYEAR = BIN2BCD(tm->tm_year);
- BCDMON = BIN2BCD(tm->tm_mon);
- BCDDAY = BIN2BCD(tm->tm_mday);
- BCDDATE = BIN2BCD(tm->tm_wday);
- BCDHOUR = BIN2BCD(tm->tm_hour);
- BCDMIN = BIN2BCD(tm->tm_min);
- BCDSEC = BIN2BCD(tm->tm_sec);
+ BCDYEAR = bin2bcd(tm->tm_year);
+ BCDMON = bin2bcd(tm->tm_mon);
+ BCDDAY = bin2bcd(tm->tm_mday);
+ BCDDATE = bin2bcd(tm->tm_wday);
+ BCDHOUR = bin2bcd(tm->tm_hour);
+ BCDMIN = bin2bcd(tm->tm_min);
+ BCDSEC = bin2bcd(tm->tm_sec);
RTCCON &= 1;
return 0;
diff --git a/drivers/rtc/x1205.c b/drivers/rtc/x1205.c
index 56115b0..7adf377 100644
--- a/drivers/rtc/x1205.c
+++ b/drivers/rtc/x1205.c
@@ -38,7 +38,6 @@
#include <command.h>
#include <rtc.h>
#include <i2c.h>
-#include <bcd.h>
#if defined(CONFIG_CMD_DATE)
@@ -116,13 +115,13 @@ int rtc_get(struct rtc_time *tm)
buf[0], buf[1], buf[2], buf[3],
buf[4], buf[5], buf[6], buf[7]);
- tm->tm_sec = BCD2BIN(buf[CCR_SEC]);
- tm->tm_min = BCD2BIN(buf[CCR_MIN]);
- tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
- tm->tm_mday = BCD2BIN(buf[CCR_MDAY]);
- tm->tm_mon = BCD2BIN(buf[CCR_MONTH]); /* mon is 0-11 */
- tm->tm_year = BCD2BIN(buf[CCR_YEAR])
- + (BCD2BIN(buf[CCR_Y2K]) * 100);
+ tm->tm_sec = bcd2bin(buf[CCR_SEC]);
+ tm->tm_min = bcd2bin(buf[CCR_MIN]);
+ tm->tm_hour = bcd2bin(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
+ tm->tm_mday = bcd2bin(buf[CCR_MDAY]);
+ tm->tm_mon = bcd2bin(buf[CCR_MONTH]); /* mon is 0-11 */
+ tm->tm_year = bcd2bin(buf[CCR_YEAR])
+ + (bcd2bin(buf[CCR_Y2K]) * 100);
tm->tm_wday = buf[CCR_WDAY];
debug("%s: tm is secs=%d, mins=%d, hours=%d, "
@@ -143,21 +142,21 @@ int rtc_set(struct rtc_time *tm)
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
- buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
- buf[CCR_MIN] = BIN2BCD(tm->tm_min);
+ buf[CCR_SEC] = bin2bcd(tm->tm_sec);
+ buf[CCR_MIN] = bin2bcd(tm->tm_min);
/* set hour and 24hr bit */
- buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL;
+ buf[CCR_HOUR] = bin2bcd(tm->tm_hour) | X1205_HR_MIL;
- buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
+ buf[CCR_MDAY] = bin2bcd(tm->tm_mday);
/* month, 1 - 12 */
- buf[CCR_MONTH] = BIN2BCD(tm->tm_mon);
+ buf[CCR_MONTH] = bin2bcd(tm->tm_mon);
/* year, since the rtc epoch*/
- buf[CCR_YEAR] = BIN2BCD(tm->tm_year % 100);
+ buf[CCR_YEAR] = bin2bcd(tm->tm_year % 100);
buf[CCR_WDAY] = tm->tm_wday & 0x07;
- buf[CCR_Y2K] = BIN2BCD(tm->tm_year / 100);
+ buf[CCR_Y2K] = bin2bcd(tm->tm_year / 100);
/* this sequence is required to unlock the chip */
rtc_write(X1205_REG_SR, X1205_SR_WEL);