From 3b33621d2f64d86f86770a3f2b7bc3ed92087784 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Wed, 7 Feb 2018 10:57:24 +0800 Subject: driver/led/lm3630a: Disable Bank B, avoid race setting brightness It is not necessary to enable Bank B, as we do not use it. Also, we have seen a race between enabling the banks and writing the brightness register to 0xFF, where the chip would reset the value after it has been set by EC. Adding a short 100us sleep fixes the issue. BRANCH=none BUG=b:69379749 TEST=Flash whiskers, pwm 0 50 works, even after a cold reset. Change-Id: Ic523a2475c3874c8433eb1b39e927793dd893e8f Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/906165 Reviewed-by: Aseda Aboagye Reviewed-by: Edward Hill Reviewed-by: Benjamin Gordon --- driver/led/lm3630a.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/driver/led/lm3630a.c b/driver/led/lm3630a.c index 932afcf644..b65294c543 100644 --- a/driver/led/lm3630a.c +++ b/driver/led/lm3630a.c @@ -7,6 +7,8 @@ #include "i2c.h" #include "lm3630a.h" +#include "timer.h" + /* 8-bit I2C address */ #define LM3630A_I2C_ADDR (0x36 << 1) @@ -28,12 +30,10 @@ int lm3630a_poweron(void) /* Sample PWM every 8 periods. */ ret |= lm3630a_write(LM3630A_REG_FILTER_STRENGTH, 0x3); - /* Enable feedback and PWM for banks A & B. */ + /* Enable feedback and PWM for banks A. */ ret |= lm3630a_write(LM3630A_REG_CONFIG, LM3630A_CFG_BIT_FB_EN_A | - LM3630A_CFG_BIT_FB_EN_B | - LM3630A_CFG_BIT_PWM_EN_A | - LM3630A_CFG_BIT_PWM_EN_B); + LM3630A_CFG_BIT_PWM_EN_A); /* 24V, 800mA overcurrent protection, 500kHz boost frequency. */ ret |= lm3630a_write(LM3630A_REG_BOOST_CONTROL, @@ -43,21 +43,20 @@ int lm3630a_poweron(void) /* Limit current to 24.5mA */ ret |= lm3630a_write(LM3630A_REG_A_CURRENT, 0x1a); - ret |= lm3630a_write(LM3630A_REG_B_CURRENT, 0x1a); - /* Enable both banks, put in linear mode, and connect LED2 to bank A. */ + /* Enable bank A, put in linear mode, and connect LED2 to bank A. */ ret |= lm3630a_write(LM3630A_REG_CONTROL, LM3630A_CTRL_BIT_LINEAR_A | - LM3630A_CTRL_BIT_LINEAR_B | LM3630A_CTRL_BIT_LED_EN_A | - LM3630A_CTRL_BIT_LED_EN_B | LM3630A_CTRL_BIT_LED2_ON_A); /* * Set full brightness so that PWM will control. This needs to happen * after setting the control register, because enabling the banks - * resets the value to 0. + * resets the value to 0 (the short sleep prevents a race between the + * chip resetting the value to 0 and our command). */ + usleep(100); ret |= lm3630a_write(LM3630A_REG_A_BRIGHTNESS, 0xff); return ret; -- cgit v1.2.1