From c2cb19bf1eb390b98423e61367ea1508af35d7c2 Mon Sep 17 00:00:00 2001 From: Zain Wang Date: Tue, 14 Jun 2022 15:17:54 +0800 Subject: [PATCH] power: supply: sc8886: fixed otg_voltage formula OTG voltage is Reg0x07/0x06 bit<2-13> by 8mV per step, are 0 for reserved. OTG voltage = 1.28V + (Reg0x07/0x06 bit<2-13>) * 8mV. And OTG voltage would be ignored if it's not in 4.28V-20.8V. In order to keep same to bq25703, it can be expressed as 1280000uV + (Reg0x07/0x06 bit<6-13>) * 128mV Signed-off-by: Zain Wang Change-Id: I0275eeded4cf86a208bf46d7a3f1dbd6d0e37b63 --- drivers/power/supply/bq25700_charger.c | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/bq25700_charger.c b/drivers/power/supply/bq25700_charger.c index 33106746a4c4..710961307882 100644 --- a/drivers/power/supply/bq25700_charger.c +++ b/drivers/power/supply/bq25700_charger.c @@ -47,6 +47,7 @@ module_param_named(dbg_level, dbg_enable, int, 0644); #define MAX_CHARGEVOLTAGE 16800000 #define MAX_CHARGECURRETNT 8128000 #define MAX_OTGVOLTAGE 20800000 +#define MIN_OTGVOLTAGE 4280000 #define MAX_OTGCURRENT 6350000 enum bq25700_fields { @@ -506,7 +507,13 @@ struct bq25700_lookup { u32 size; }; -static const union { +static const struct bq25700_range sc8886_otg_range = { + .min = 1280000, + .max = 20800000, + .step = 128000, +}; + +static union { struct bq25700_range rt; struct bq25700_lookup lt; } bq25700_tables[] = { @@ -935,12 +942,25 @@ static int bq25700_fw_read_u32_props(struct bq25700_device *charger) dev_err(charger->dev, "ti,input-current is error\n"); return -ENODEV; } - if ((props[i].tbl_id == TBL_OTGVOL) && - (property > MAX_OTGVOLTAGE)) { - dev_err(charger->dev, "ti,ti,otg-voltage is error\n"); - return -ENODEV; + if (props[i].tbl_id == TBL_OTGVOL) { + if (of_device_is_compatible(charger->dev->of_node, + "southchip,sc8886")) { + bq25700_tables[TBL_OTGVOL].rt = sc8886_otg_range; + + if (property < MIN_OTGVOLTAGE) { + dev_err(charger->dev, + "ti,otg-voltage is error"); + return -ENODEV; + } + } + + if (property > MAX_OTGVOLTAGE) { + dev_err(charger->dev, "ti,otg-voltage is error\n"); + return -ENODEV; + }; } - if ((props[i].tbl_id == TBL_OTGVOL) && + + if ((props[i].tbl_id == TBL_OTGCUR) && (property > MAX_OTGCURRENT)) { dev_err(charger->dev, "ti,otg-current is error\n"); return -ENODEV;