Werner Zeh (werner.zeh@siemens.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17829
-gerrit
commit 4d2bcf8b331fda7196cdfb94603cced8ee230d4a Author: Werner Zeh werner.zeh@siemens.com Date: Tue Dec 13 08:03:10 2016 +0100
pcf8523: Fix wrong initialization of several registers
In the case where the RTC is initialized after the battery was completely drained the bits for power_mode and cof_selection were set up with wrongly applied masks. In the case where the RTC is re-initialized again with no power-loss after the last initialization the bits for cap_sel, power_mode and cof_selection were not shifted to the right position.
Both errors leads to a wrong initialization of the RTC and in turn to a way larger current consumption (instead of 120 nA the RTC current rises to over 2 µA).
This patch fixes both errors and the current consumption is in the right range again.
Change-Id: I8594f6ac121a175844393952db2169dbc5cbd2b2 Signed-off-by: Werner Zeh werner.zeh@siemens.com --- src/drivers/i2c/pcf8523/pcf8523.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/src/drivers/i2c/pcf8523/pcf8523.c b/src/drivers/i2c/pcf8523/pcf8523.c index eb0bf25..1f68042 100644 --- a/src/drivers/i2c/pcf8523/pcf8523.c +++ b/src/drivers/i2c/pcf8523/pcf8523.c @@ -63,15 +63,15 @@ static void pcf8523_init(struct device *dev) * corrupted and OS bit was not set. */ reg = smbus_read_byte(dev, CTRL_REG_1); reg &= ~(STOP_BIT | CAP_SEL); - reg |= config->cap_sel; + reg |= ((!!config->cap_sel) << 7); smbus_write_byte(dev, CTRL_REG_1, reg); reg = smbus_read_byte(dev, CTRL_REG_3); reg &= ~PM_MASK; - reg |= config->power_mode; + reg |= ((config->power_mode & 0x07) << 5); smbus_write_byte(dev, CTRL_REG_3, reg); reg = smbus_read_byte(dev, TMR_CLKOUT_REG); reg &= ~COF_MASK; - reg |= config->cof_selection; + reg |= ((config->cof_selection & 0x07) << 3); smbus_write_byte(dev, TMR_CLKOUT_REG, reg); return; } @@ -82,26 +82,20 @@ static void pcf8523_init(struct device *dev) ((!!config->second_int_en) << 2) | ((!!config->alarm_int_en) << 1) | (!!config->correction_int_en)); - smbus_write_byte(dev, CTRL_REG_2, ((!!config->wdt_int_en) << 2) | ((!!config->tmrA_int_en) << 1) | (!!config->tmrB_int_en)); - - smbus_write_byte(dev, CTRL_REG_3, ((config->power_mode & 0x03) << 5) | + smbus_write_byte(dev, CTRL_REG_3, ((config->power_mode & 0x07) << 5) | ((!!config->bat_switch_int_en) << 1) | (!!config->bat_low_int_en)); - smbus_write_byte(dev, OFFSET_REG, ((!!config->offset_mode) << 7) | (config->offset_val & 0x7f)); - smbus_write_byte(dev, TMR_CLKOUT_REG, ((!!config->tmrA_int_mode) << 7) | ((!!config->tmrB_int_mode) << 6) | - ((config->cof_selection & 0x38) << 3) | + ((config->cof_selection & 0x07) << 3) | ((config->tmrA_mode & 0x03) << 1) | (!!config->tmrB_mode)); - smbus_write_byte(dev, TMR_A_FREQ_REG, (config->tmrA_prescaler & 0x7)); - smbus_write_byte(dev, TMR_B_FREQ_REG, (config->tmrB_prescaler & 0x7) | ((config->tmrB_pulse_cfg & 0x7) << 4));