summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--common/cmd_nvedit.c2
-rw-r--r--drivers/rtc/rv3029.c87
-rw-r--r--drivers/spi/bfin_spi.c32
-rw-r--r--include/configs/digsy_mtc.h2
-rw-r--r--include/spi.h8
6 files changed, 119 insertions, 14 deletions
diff --git a/README b/README
index beb1cbb..cdbb9de 100644
--- a/README
+++ b/README
@@ -748,6 +748,8 @@ The following options need to be configured:
CONFIG_RTC_ISL1208 - use Intersil ISL1208 RTC
CONFIG_RTC_MAX6900 - use Maxim, Inc. MAX6900 RTC
CONFIG_SYS_RTC_DS1337_NOOSC - Turn off the OSC output for DS1337
+ CONFIG_SYS_RV3029_TCR - enable trickle charger on
+ RV3029 RTC.
Note that if the RTC uses I2C, then the I2C interface
must also be configured. See I2C Support, below.
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 204a094..df0e6db 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -65,7 +65,7 @@ DECLARE_GLOBAL_DATA_PTR;
!defined(CONFIG_ENV_IS_IN_SPI_FLASH) && \
!defined(CONFIG_ENV_IS_NOWHERE)
# error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|MG_DISK|NVRAM|MMC|NOWHERE}
+SPI_FLASH|MG_DISK|NVRAM|MMC} or CONFIG_ENV_IS_NOWHERE
#endif
#define XMK_STR(x) #x
diff --git a/drivers/rtc/rv3029.c b/drivers/rtc/rv3029.c
index 3ebc768..e012168 100644
--- a/drivers/rtc/rv3029.c
+++ b/drivers/rtc/rv3029.c
@@ -25,6 +25,12 @@
#include <i2c.h>
#include <rtc.h>
+#define RTC_RV3029_CTRL1 0x00
+#define RTC_RV3029_CTRL1_EERE (1 << 3)
+
+#define RTC_RV3029_CTRL_STATUS 0x03
+#define RTC_RV3029_CTRLS_EEBUSY (1 << 7)
+
#define RTC_RV3029_CTRL_RESET 0x04
#define RTC_RV3029_CTRL_SYS_R (1 << 4)
@@ -42,6 +48,12 @@
#define RV3029C2_REG_HR_12_24 (1 << 6) /* 24h/12h mode */
#define RV3029C2_REG_HR_PM (1 << 5) /* PM/AM bit in 12h mode */
+#define RTC_RV3029_EEPROM_CTRL 0x30
+#define RTC_RV3029_TRICKLE_1K (1 << 4)
+#define RTC_RV3029_TRICKLE_5K (1 << 5)
+#define RTC_RV3029_TRICKLE_20K (1 << 6)
+#define RTC_RV3029_TRICKLE_80K (1 << 7)
+
int rtc_get( struct rtc_time *tmp )
{
int ret;
@@ -113,6 +125,41 @@ int rtc_set( struct rtc_time *tmp )
return 0;
}
+/* sets EERE-Bit (automatic EEPROM refresh) */
+static void set_eere_bit(int state)
+{
+ int ret;
+ unsigned char reg_ctrl1;
+
+ ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CTRL1, 1,
+ &reg_ctrl1, 1);
+
+ if (state)
+ reg_ctrl1 |= RTC_RV3029_CTRL1_EERE;
+ else
+ reg_ctrl1 &= (~RTC_RV3029_CTRL1_EERE);
+
+ ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CTRL1, 1,
+ &reg_ctrl1, 1);
+}
+
+/* waits until EEPROM page is no longer busy (times out after 10ms*loops) */
+static int wait_eebusy(int loops)
+{
+ int i, ret;
+ unsigned char ctrl_status;
+
+ for (i = 0; i < loops; i++) {
+ ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CTRL_STATUS,
+ 1, &ctrl_status, 1);
+
+ if ((ctrl_status & RTC_RV3029_CTRLS_EEBUSY) == 0)
+ break;
+ udelay(10000);
+ }
+ return i;
+}
+
void rtc_reset (void)
{
int ret;
@@ -121,4 +168,44 @@ void rtc_reset (void)
buf[0] = RTC_RV3029_CTRL_SYS_R;
ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_CTRL_RESET, 1,
buf, 1);
+
+#if defined(CONFIG_SYS_RV3029_TCR)
+ /*
+ * because EEPROM_CTRL register is in EEPROM page it is necessary to
+ * disable automatic EEPROM refresh and check if EEPROM is busy
+ * before EEPORM_CTRL register may be accessed
+ */
+ set_eere_bit(0);
+ wait_eebusy(100);
+ /* read current trickle charger setting */
+ ret = i2c_read(CONFIG_SYS_I2C_RTC_ADDR, RTC_RV3029_EEPROM_CTRL,
+ 1, buf, 1);
+ /* enable automatic EEPROM refresh again */
+ set_eere_bit(1);
+
+ /*
+ * to minimize EEPROM access write trickle charger setting only if it
+ * differs from current value
+ */
+ if ((buf[0] & 0xF0) != CONFIG_SYS_RV3029_TCR) {
+ buf[0] = (buf[0] & 0x0F) | CONFIG_SYS_RV3029_TCR;
+ /*
+ * write trickle charger setting (disable autom. EEPROM
+ * refresh and wait until EEPROM is idle)
+ */
+ set_eere_bit(0);
+ wait_eebusy(100);
+ ret = i2c_write(CONFIG_SYS_I2C_RTC_ADDR,
+ RTC_RV3029_EEPROM_CTRL, 1, buf, 1);
+ /*
+ * it is necessary to wait 10ms before EEBUSY-Bit may be read
+ * (this is not documented in the data sheet yet, but the
+ * manufacturer recommends it)
+ */
+ udelay(10000);
+ /* wait until EEPROM write access is finished */
+ wait_eebusy(100);
+ set_eere_bit(1);
+ }
+#endif
}
diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index e8a4de5..213e792 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -138,13 +138,29 @@ static const unsigned short cs_pins[][7] = {
#endif
};
+void spi_set_speed(struct spi_slave *slave, uint hz)
+{
+ struct bfin_spi_slave *bss = to_bfin_spi_slave(slave);
+ ulong sclk;
+ u32 baud;
+
+ sclk = get_sclk();
+ baud = sclk / (2 * hz);
+ /* baud should be rounded up */
+ if (sclk % (2 * hz))
+ baud += 1;
+ if (baud < 2)
+ baud = 2;
+ else if (baud > (u16)-1)
+ baud = -1;
+ bss->baud = baud;
+}
+
struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
unsigned int max_hz, unsigned int mode)
{
struct bfin_spi_slave *bss;
- ulong sclk;
u32 mmr_base;
- u32 baud;
if (!spi_cs_is_valid(bus, cs))
return NULL;
@@ -166,16 +182,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
default: return NULL;
}
- sclk = get_sclk();
- baud = sclk / (2 * max_hz);
- /* baud should be rounded up */
- if (sclk % (2 * max_hz))
- baud += 1;
- if (baud < 2)
- baud = 2;
- else if (baud > (u16)-1)
- baud = -1;
-
bss = malloc(sizeof(*bss));
if (!bss)
return NULL;
@@ -187,8 +193,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
if (mode & SPI_CPHA) bss->ctl |= CPHA;
if (mode & SPI_CPOL) bss->ctl |= CPOL;
if (mode & SPI_LSB_FIRST) bss->ctl |= LSBF;
- bss->baud = baud;
bss->flg = mode & SPI_CS_HIGH ? 1 : 0;
+ spi_set_speed(&bss->slave, max_hz);
debug("%s: bus:%i cs:%i mmr:%x ctl:%x baud:%i flg:%i\n", __func__,
bus, cs, mmr_base, bss->ctl, baud, bss->flg);
diff --git a/include/configs/digsy_mtc.h b/include/configs/digsy_mtc.h
index e7fd0f7..f1613c7 100644
--- a/include/configs/digsy_mtc.h
+++ b/include/configs/digsy_mtc.h
@@ -252,6 +252,8 @@
#if defined(CONFIG_DIGSY_REV5)
#define CONFIG_SYS_I2C_RTC_ADDR 0x56
#define CONFIG_RTC_RV3029
+/* Enable 5k Ohm trickle charge resistor */
+#define CONFIG_SYS_RV3029_TCR 0x20
#else
#define CONFIG_RTC_DS1337
#define CONFIG_SYS_I2C_RTC_ADDR 0x68
diff --git a/include/spi.h b/include/spi.h
index 320e50e..7887d0f 100644
--- a/include/spi.h
+++ b/include/spi.h
@@ -176,6 +176,14 @@ void spi_cs_activate(struct spi_slave *slave);
void spi_cs_deactivate(struct spi_slave *slave);
/*-----------------------------------------------------------------------
+ * Set transfer speed.
+ * This sets a new speed to be applied for next spi_xfer().
+ * slave: The SPI slave
+ * hz: The transfer speed
+ */
+void spi_set_speed(struct spi_slave *slave, uint hz);
+
+/*-----------------------------------------------------------------------
* Write 8 bits, then read 8 bits.
* slave: The SPI slave we're communicating with
* byte: Byte to be written