diff options
author | Shunqing Chen <csq@rock-chips.com> | 2017-12-11 11:28:20 +0800 |
---|---|---|
committer | Tao Huang <huangtao@rock-chips.com> | 2018-02-25 19:33:19 +0800 |
commit | c800d4456eaa23654094a72b80bf58972858754b (patch) | |
tree | 720a10ecfd726f7b19b3171335e145eaa7113128 /drivers/power | |
parent | 810497ff787f9a01f59a993cda4308f3785d8f6a (diff) |
power_supply: cw201x: add hw_id check for android things SOM
Change-Id: Ic51abf5ccf89d3106858d029812ba6450422f1f5
Signed-off-by: Shunqing Chen <csq@rock-chips.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/cw2015_battery.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/drivers/power/cw2015_battery.c b/drivers/power/cw2015_battery.c index 283367953e6b..6594b5989ade 100644 --- a/drivers/power/cw2015_battery.c +++ b/drivers/power/cw2015_battery.c @@ -16,6 +16,7 @@ #include <linux/i2c.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/of_gpio.h> #include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/slab.h> @@ -456,6 +457,8 @@ static int cw_get_voltage(struct cw_battery *cw_bat) res1 = cw_bat->plat_data.divider_res1; res2 = cw_bat->plat_data.divider_res2; voltage = voltage * (res1 + res2) / res2; + } else if (cw_bat->dual_battery) { + voltage = voltage * 2; } dev_dbg(&cw_bat->client->dev, "the cw201x voltage=%d,reg_val=%x %x\n", @@ -677,12 +680,49 @@ static int cw2015_parse_dt(struct cw_battery *cw_bat) u32 value; int ret; struct cw_bat_platform_data *data = &cw_bat->plat_data; + struct gpio_desc *hw_id0_io; + struct gpio_desc *hw_id1_io; + int hw_id0_val; + int hw_id1_val; if (!node) return -ENODEV; memset(data, 0, sizeof(*data)); + ret = of_property_read_u32(node, "hw_id_check", &value); + if (!ret && value) { + hw_id0_io = gpiod_get_optional(dev, "hw-id0", GPIOD_IN); + if (!hw_id0_io) + return -EINVAL; + if (IS_ERR(hw_id0_io)) + return PTR_ERR(hw_id0_io); + + hw_id0_val = gpiod_get_value(hw_id0_io); + gpiod_put(hw_id0_io); + + hw_id1_io = gpiod_get_optional(dev, "hw-id1", GPIOD_IN); + if (!hw_id1_io) + return -EINVAL; + if (IS_ERR(hw_id1_io)) + return PTR_ERR(hw_id1_io); + + hw_id1_val = gpiod_get_value(hw_id1_io); + gpiod_put(hw_id1_io); + + /* + * ID1 = 0, ID0 = 1 : Battery + * ID1 = 1, ID0 = 0 : Dual Battery + * ID1 = 0, ID0 = 0 : Adapter + */ + if (hw_id0_val == 1 && hw_id1_val == 0) + cw_bat->dual_battery = false; + else if (hw_id0_val == 0 && hw_id1_val == 1) + cw_bat->dual_battery = true; + else + return -EINVAL; + } + /* determine the number of config info */ prop = of_find_property(node, "bat_config_info", &length); if (!prop) |