Commit 2c4bf698 authored by Ikjoon Jang's avatar Ikjoon Jang Committed by Sebastian Reichel
Browse files

power: supply: sbs-battery: combine get_presence_and_health



This patch enables calling sbs_get_battery_presence_and_health()
without checking its chip type. No functional changes.

Signed-off-by: default avatarIkjoon Jang <ikjn@chromium.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 52bef41f
Loading
Loading
Loading
Loading
+36 −37
Original line number Diff line number Diff line
@@ -473,37 +473,6 @@ static bool sbs_bat_needs_calibration(struct i2c_client *client)
	return !!(ret & BIT(7));
}

static int sbs_get_battery_presence_and_health(
	struct i2c_client *client, enum power_supply_property psp,
	union power_supply_propval *val)
{
	int ret;

	/* Dummy command; if it succeeds, battery is present. */
	ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);

	if (ret < 0) { /* battery not present*/
		if (psp == POWER_SUPPLY_PROP_PRESENT) {
			val->intval = 0;
			return 0;
		}
		return ret;
	}

	if (psp == POWER_SUPPLY_PROP_PRESENT)
		val->intval = 1; /* battery present */
	else { /* POWER_SUPPLY_PROP_HEALTH */
		if (sbs_bat_needs_calibration(client)) {
			val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
		} else {
			/* SBS spec doesn't have a general health command. */
			val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
		}
	}

	return 0;
}

static int sbs_get_ti_battery_presence_and_health(
	struct i2c_client *client, enum power_supply_property psp,
	union power_supply_propval *val)
@@ -562,6 +531,41 @@ static int sbs_get_ti_battery_presence_and_health(
	return 0;
}

static int sbs_get_battery_presence_and_health(
	struct i2c_client *client, enum power_supply_property psp,
	union power_supply_propval *val)
{
	struct sbs_info *chip = i2c_get_clientdata(client);
	int ret;

	if (chip->flags & SBS_FLAGS_TI_BQ20ZX5)
		return sbs_get_ti_battery_presence_and_health(client, psp, val);

	/* Dummy command; if it succeeds, battery is present. */
	ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);

	if (ret < 0) { /* battery not present*/
		if (psp == POWER_SUPPLY_PROP_PRESENT) {
			val->intval = 0;
			return 0;
		}
		return ret;
	}

	if (psp == POWER_SUPPLY_PROP_PRESENT)
		val->intval = 1; /* battery present */
	else { /* POWER_SUPPLY_PROP_HEALTH */
		if (sbs_bat_needs_calibration(client)) {
			val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
		} else {
			/* SBS spec doesn't have a general health command. */
			val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
		}
	}

	return 0;
}

static int sbs_get_battery_property(struct i2c_client *client,
	int reg_offset, enum power_supply_property psp,
	union power_supply_propval *val)
@@ -864,12 +868,7 @@ static int sbs_get_property(struct power_supply *psy,
	switch (psp) {
	case POWER_SUPPLY_PROP_PRESENT:
	case POWER_SUPPLY_PROP_HEALTH:
		if (chip->flags & SBS_FLAGS_TI_BQ20ZX5)
			ret = sbs_get_ti_battery_presence_and_health(client,
								     psp, val);
		else
			ret = sbs_get_battery_presence_and_health(client, psp,
								  val);
		ret = sbs_get_battery_presence_and_health(client, psp, val);

		/* this can only be true if no gpio is used */
		if (psp == POWER_SUPPLY_PROP_PRESENT)