Re: [PATCH v1 6/7] power: bq24190_charger: Add power_supply_battery_info and devicetree support

Sebastian Reichel
2017-03-24T09:20:20Z

[-- Attachment #1: Type: text/plain, Size: 1897 bytes --]

Hi,

On Tue, Mar 21, 2017 at 03:09:20PM -0700, Liam Breck wrote:
> From: Liam Breck <kernel@networkimprov.net>
>
> Obtain pre-charge and end-charge current values from power_supply_battery_info.
> Obtain minimum system voltage level from devicetree.
>
> Cc: Mark Greer <mgreer@animalcreek.com>
> Signed-off-by: Liam Breck <kernel@networkimprov.net>
>
> [...]
>
> @@ -1314,6 +1358,39 @@ static int bq24190_hw_init(struct bq24190_dev_info *bdi)
> #ifdef CONFIG_OF
> static int bq24190_setup_dt(struct bq24190_dev_info *bdi)
> {
> + struct power_supply_battery_info info = {};
> + const char const* s = "ti,system-minimum-microvolt";
> + int v;
> +
> + if (!of_property_read_u32(bdi->dev->of_node, s, &v)) {
> + v /= 1000;
> + if (v >= BQ24190_REG_POC_SYS_MIN_MIN
> + && v <= BQ24190_REG_POC_SYS_MIN_MAX)
> + bdi->sys_min = v;
> + else
> + dev_err(bdi->dev, "invalid value for %s: %u\n", s, v);
> + }

Let's use device_property_read_u32 here. With that change
there is nothing DT specific, so the function can be named
bq24190_setup (or everything is done directly in probe, that's
also fine with me).

> + if (!power_supply_get_battery_info(bdi->battery, &info)) {
> + v = info.precharge_current_ua / 1000;
> + if (v >= BQ24190_REG_PCTCC_IPRECHG_MIN
> + && v <= BQ24190_REG_PCTCC_IPRECHG_MAX)
> + bdi->iprechg = v;
> + else
> + dev_err(bdi->dev,
> + "invalid value for battery:precharge-current-microamp: %d\n",
> + v);
> +
> + v = info.endcharge_current_ua / 1000;
> + if (v >= BQ24190_REG_PCTCC_ITERM_MIN
> + && v <= BQ24190_REG_PCTCC_ITERM_MAX)
> + bdi->iterm = v;
> + else
> + dev_err(bdi->dev,
> + "invalid value for battery:endcharge-current-microamp: %d\n",
> + v);
> + }
> +
> bdi->irq = irq_of_parse_and_map(bdi->dev->of_node, 0);
> if (bdi->irq <= 0)
> return -1;

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]