Skip to content

Commit c46a9ee

Browse files
ChiYuan Huangsre
authored andcommitted
power: supply: rt9471: Use IC status regfield to report real charger status
Use IC status regfield to rewrite the 'get_staus' function. The original one cannot cover some special scenario like as charger OTG or JEITA case. Fixes: 4a1a5f6 ("power: supply: rt9471: Add Richtek RT9471 charger driver") Reported-by: Lucas Tsai <[email protected]> Signed-off-by: ChiYuan Huang <[email protected]> Link: https://lore.kernel.org/r/67ba92bb4a9c51d9cafadab30b788a3a2c3048e1.1727252762.git.cy_huang@richtek.com Signed-off-by: Sebastian Reichel <[email protected]>
1 parent d10ff07 commit c46a9ee

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

drivers/power/supply/rt9471.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ enum {
139139
RT9471_PORTSTAT_DCP,
140140
};
141141

142+
enum {
143+
RT9471_ICSTAT_SLEEP = 0,
144+
RT9471_ICSTAT_VBUSRDY,
145+
RT9471_ICSTAT_TRICKLECHG,
146+
RT9471_ICSTAT_PRECHG,
147+
RT9471_ICSTAT_FASTCHG,
148+
RT9471_ICSTAT_IEOC,
149+
RT9471_ICSTAT_BGCHG,
150+
RT9471_ICSTAT_CHGDONE,
151+
RT9471_ICSTAT_CHGFAULT,
152+
RT9471_ICSTAT_OTG = 15,
153+
};
154+
142155
struct rt9471_chip {
143156
struct device *dev;
144157
struct regmap *regmap;
@@ -255,31 +268,32 @@ static int rt9471_get_ieoc(struct rt9471_chip *chip, int *microamp)
255268

256269
static int rt9471_get_status(struct rt9471_chip *chip, int *status)
257270
{
258-
unsigned int chg_ready, chg_done, fault_stat;
271+
unsigned int ic_stat;
259272
int ret;
260273

261-
ret = regmap_field_read(chip->rm_fields[F_ST_CHG_RDY], &chg_ready);
262-
if (ret)
263-
return ret;
264-
265-
ret = regmap_field_read(chip->rm_fields[F_ST_CHG_DONE], &chg_done);
274+
ret = regmap_field_read(chip->rm_fields[F_IC_STAT], &ic_stat);
266275
if (ret)
267276
return ret;
268277

269-
ret = regmap_read(chip->regmap, RT9471_REG_STAT1, &fault_stat);
270-
if (ret)
271-
return ret;
272-
273-
fault_stat &= RT9471_CHGFAULT_MASK;
274-
275-
if (chg_ready && chg_done)
276-
*status = POWER_SUPPLY_STATUS_FULL;
277-
else if (chg_ready && fault_stat)
278+
switch (ic_stat) {
279+
case RT9471_ICSTAT_VBUSRDY:
280+
case RT9471_ICSTAT_CHGFAULT:
278281
*status = POWER_SUPPLY_STATUS_NOT_CHARGING;
279-
else if (chg_ready && !fault_stat)
282+
break;
283+
case RT9471_ICSTAT_TRICKLECHG ... RT9471_ICSTAT_BGCHG:
280284
*status = POWER_SUPPLY_STATUS_CHARGING;
281-
else
285+
break;
286+
case RT9471_ICSTAT_CHGDONE:
287+
*status = POWER_SUPPLY_STATUS_FULL;
288+
break;
289+
case RT9471_ICSTAT_SLEEP:
290+
case RT9471_ICSTAT_OTG:
282291
*status = POWER_SUPPLY_STATUS_DISCHARGING;
292+
break;
293+
default:
294+
*status = POWER_SUPPLY_STATUS_UNKNOWN;
295+
break;
296+
}
283297

284298
return 0;
285299
}

0 commit comments

Comments
 (0)