summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2017-12-15 18:09:10 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-12-18 17:55:00 -0800
commit6aa967e4bbbdf28e0d9f5e537ccf4cbd76665b68 (patch)
tree28b5c7adecd5a3441ea5f5dcebcc6f28390f233a /driver
parent34788758ac86de3587d7ba75848c59199aa49622 (diff)
downloadchrome-ec-6aa967e4bbbdf28e0d9f5e537ccf4cbd76665b68.tar.gz
charger/rt946X: Set boost current threshold correctly
rt946x_closest_reg_via_tbl() is buggy and doesn't return the right reg value because of misuse of ARRAY_SIZE(). We should fix it. Meanwhile, since rt946x_closest_reg_via_tbl() is only called in rt946x_set_boost_current(), let's just delete rt946x_closest_reg_via_tbl() and move its code to rt946x_set_boost_current(). BUG=b:70524967 BRANCH=none TEST=Confirm reg 0x0a is set correctly Change-Id: Ie9c90ebf63596a52f864ff5809488731edc41fff Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/830895 Commit-Ready: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/rt946x.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c
index 60322f08e6..84be7e18f3 100644
--- a/driver/charger/rt946x.c
+++ b/driver/charger/rt946x.c
@@ -92,8 +92,9 @@ static const uint8_t rt946x_irq_maskall[RT946X_IRQ_COUNT] = {
#endif
};
+/* Must be in ascending order */
static const uint16_t rt946x_boost_current[] = {
- 500, 700, 1100, 1300, 1800, 2100, 2400, 3000,
+ 500, 700, 1100, 1300, 1800, 2100, 2400,
};
static int rt946x_read8(int reg, int *val)
@@ -163,19 +164,6 @@ static inline uint8_t rt946x_closest_reg(uint16_t min, uint16_t max,
return (target - min) / step;
}
-static uint8_t rt946x_closest_reg_via_tbl(const uint16_t *tbl, uint16_t target)
-{
- int i = 0;
-
- if (target < tbl[0])
- return 0;
- for (i = 0; i < ARRAY_SIZE(tbl) - 1; i++) {
- if (target >= tbl[i] && target < tbl[i + 1])
- return i;
- }
- return ARRAY_SIZE(tbl) - 1;
-}
-
static int rt946x_chip_rev(int *chip_rev)
{
int rv;
@@ -276,15 +264,23 @@ static int rt946x_set_boost_voltage(unsigned int voltage)
static int rt946x_set_boost_current(unsigned int current)
{
- uint8_t reg_current = 0;
+ int i;
- reg_current = rt946x_closest_reg_via_tbl(rt946x_boost_current, current);
+ /*
+ * Find the smallest output current threshold which can support
+ * our requested output current. Use the greatest achievable
+ * boost current (2.4A) if requested current is too large.
+ */
+ for (i = 0; i < ARRAY_SIZE(rt946x_boost_current) - 1; i++) {
+ if (current < rt946x_boost_current[i])
+ break;
+ }
- CPRINTF("%s current = %d(0x%02X)\n", __func__, current, reg_current);
+ CPRINTF("%s current = %d(0x%02X)\n", __func__, current, i);
return rt946x_update_bits(RT946X_REG_CHGCTRL10,
RT946X_MASK_BOOST_CURRENT,
- reg_current << RT946X_SHIFT_BOOST_CURRENT);
+ i << RT946X_SHIFT_BOOST_CURRENT);
}
static int rt946x_set_ircmp_vclamp(unsigned int vclamp)