Skip to content

Commit eab4e6d

Browse files
IMbackKsre
authored andcommitted
power: supply: cpcap-charger: get the battery inserted infomation from cpcap-battery
This avoids reimplementing the detection logic twice and removes the possibility of activating charging with 500mA even if a battery is not detected. Signed-off-by: Carl Philipp Klemm <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent aecd127 commit eab4e6d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

drivers/power/supply/cpcap-charger.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,6 @@ static enum power_supply_property cpcap_charger_props[] = {
173173
POWER_SUPPLY_PROP_CURRENT_NOW,
174174
};
175175

176-
/* No battery always shows temperature of -40000 */
177-
static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
178-
{
179-
struct iio_channel *channel;
180-
int error, temperature;
181-
182-
channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
183-
error = iio_read_channel_processed(channel, &temperature);
184-
if (error < 0) {
185-
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
186-
187-
return false;
188-
}
189-
190-
return temperature > -20000 && temperature < 60000;
191-
}
192-
193176
static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
194177
{
195178
struct iio_channel *channel;
@@ -700,11 +683,29 @@ static void cpcap_usb_detect(struct work_struct *work)
700683

701684
if (!ddata->feeding_vbus && cpcap_charger_vbus_valid(ddata) &&
702685
s.chrgcurr1) {
703-
int max_current = 532000;
686+
int max_current;
704687
int vchrg, ichrg;
688+
union power_supply_propval val;
689+
struct power_supply *battery;
705690

706-
if (cpcap_charger_battery_found(ddata))
691+
battery = power_supply_get_by_name("battery");
692+
if (IS_ERR_OR_NULL(battery)) {
693+
dev_err(ddata->dev, "battery power_supply not available %li\n",
694+
PTR_ERR(battery));
695+
return;
696+
}
697+
698+
error = power_supply_get_property(battery, POWER_SUPPLY_PROP_PRESENT, &val);
699+
power_supply_put(battery);
700+
if (error)
701+
goto out_err;
702+
703+
if (val.intval) {
707704
max_current = 1596000;
705+
} else {
706+
dev_info(ddata->dev, "battery not inserted, charging disabled\n");
707+
max_current = 0;
708+
}
708709

709710
if (max_current > ddata->limit_current)
710711
max_current = ddata->limit_current;

0 commit comments

Comments
 (0)