summaryrefslogtreecommitdiff
path: root/src/drivers/i2c/rx6110sa/rx6110sa.c
diff options
context:
space:
mode:
authorWerner Zeh <werner.zeh@siemens.com>2017-06-07 09:51:06 +0200
committerWerner Zeh <werner.zeh@siemens.com>2017-06-09 06:31:21 +0200
commit0dc405de980a22721e9faba9127321f4849d10ab (patch)
treecc5fe375be0a67d74fc816328f5d25bbeeac37d3 /src/drivers/i2c/rx6110sa/rx6110sa.c
parent37afb270b461314978ce741cffa3b896673eb829 (diff)
downloadcoreboot-0dc405de980a22721e9faba9127321f4849d10ab.tar.xz
rx6110sa: Add more chip configuration options to chip
The RTC RX6110SA has several configuration options which might be interesting to set. To make this setup independent of the driver itself but let it still be configurable on mainboard level, add more configuration options to the chip driver. Change-Id: I7f8b2aa7cd001a887f271be36f655e10e60e778b Signed-off-by: Werner Zeh <werner.zeh@siemens.com> Reviewed-on: https://review.coreboot.org/20084 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Mario Scheithauer <mario.scheithauer@siemens.com>
Diffstat (limited to 'src/drivers/i2c/rx6110sa/rx6110sa.c')
-rw-r--r--src/drivers/i2c/rx6110sa/rx6110sa.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/drivers/i2c/rx6110sa/rx6110sa.c b/src/drivers/i2c/rx6110sa/rx6110sa.c
index 9d60bdb7e1..06735a7868 100644
--- a/src/drivers/i2c/rx6110sa/rx6110sa.c
+++ b/src/drivers/i2c/rx6110sa/rx6110sa.c
@@ -88,33 +88,54 @@ static void rx6110sa_init(struct device *dev)
struct drivers_i2c_rx6110sa_config *config = dev->chip_info;
uint8_t reg;
- /* Do a dummy read first. */
- reg = rx6110sa_read(dev, SECOND_REG);
-
+ /* Do a dummy read first as requested in the datasheet. */
+ rx6110sa_read(dev, SECOND_REG);
+ /*
+ * Set battery backup mode and power monitor sampling time even if there
+ * was no power loss to make sure that the right mode is used as it
+ * directly influences the backup current consumption and therefore the
+ * backup time.
+ */
+ reg = (config->pmon_sampling & PMON_SAMPL_MASK) |
+ (!!config->bks_off << 2) | (!!config->bks_on << 3) |
+ (!!config->iocut_en << 4);
+ rx6110sa_write(dev, BATTERY_BACKUP_REG, reg);
/*
* Check VLF-bit which indicates the RTC data loss, such as due to a
* supply voltage drop.
*/
reg = rx6110sa_read(dev, FLAG_REGISTER);
-
if (!(reg & VLF_BIT))
/* No voltage low detected, everything is well. */
return;
-
/*
* Voltage low detected, initialize RX6110 SA again.
* Set first some registers to known state.
*/
- rx6110sa_write(dev, BATTERY_BACKUP_REG, 0x00);
rx6110sa_write(dev, RESERVED_BIT_REG, RTC_INIT_VALUE);
rx6110sa_write(dev, DIGITAL_REG, 0x00);
- rx6110sa_write(dev, IRQ_CONTROL_REG, 0x00);
+ reg = (!!config->enable_1hz_out << 4) |
+ (!!config->irq_output_pin << 2) |
+ (config->fout_output_pin & FOUT_OUTPUT_PIN_MASK);
+ rx6110sa_write(dev, IRQ_CONTROL_REG, reg);
/* Clear timer enable bit and set frequency of clock output. */
-
reg = rx6110sa_read(dev, EXTENSION_REG);
reg &= ~(FSEL_MASK | TE_BIT);
reg |= (config->cof_selection << 6);
+ if (config->timer_preset) {
+ /* Timer needs to be in stop mode prior to programming it. */
+ rx6110sa_write(dev, EXTENSION_REG, reg);
+ reg &= ~TSEL_MASK;
+ /* Program the timer preset value. */
+ rx6110sa_write(dev, TMR_COUNTER_0_REG,
+ config->timer_preset & 0xff);
+ rx6110sa_write(dev, TMR_COUNTER_1_REG,
+ (config->timer_preset >> 8) & 0xff);
+ /* Set Timer Enable bit and the timer clock value. */
+ reg |= ((!!config->timer_en << 4) |
+ (config->timer_clk & TSEL_MASK));
+ }
rx6110sa_write(dev, EXTENSION_REG, reg);
/* Clear voltage low detect bit. */
@@ -140,7 +161,9 @@ static void rx6110sa_init(struct device *dev)
rx6110sa_write(dev, MINUTE_REG, 0);
rx6110sa_write(dev, SECOND_REG, 0);
/* Start oscillator again as the RTC is set up now. */
- rx6110sa_write(dev, CTRL_REG, 0x00);
+ reg = (!!config->timer_irq_en << 4) |
+ (config->timer_mode & TMR_MODE_MASK);
+ rx6110sa_write(dev, CTRL_REG, reg);
}
static struct device_operations rx6110sa_ops = {