Skip to contentSkip to conversation

Add some new properties for the SC27XX fuel gauge

PATCH In review Baolin Wang 2 participants 6 messages Apr 20, 2020 – Apr 28, 2020

Subsystems (2)
lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

cover Add some new properties for the SC27XX fuel gauge

Hi,

This patch set adds some new properties for the SC27XX fuel gauge, as well as changing the 'POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN' as writeable. Thanks.

Yuanjiang Yu (4):
power: supply: sc27xx: Set 'no_thermal' flag for SC27xx fuel gauge
power: supply: sc27xx: Allow to change the battery full capacity
power: supply: sc27xx: Add CURRENT_NOW/VOLTAGE_NOW properties support
power: supply: sc27xx: Add boot voltage support

 drivers/power/supply/sc27xx_fuel_gauge.c | 77 +++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/4 power: supply: sc27xx: Set 'no_thermal' flag for SC27xx fuel gauge

From: Yuanjiang Yu <[email protected]>

There is no thermal zone should be created for the SC27XX FGU power supply, thus set the 'no_thermal' flag as true.

---
 drivers/power/supply/sc27xx_fuel_gauge.c | 1 +
 1 file changed, 1 insertion(+)
drivers/power/supply/sc27xx_fuel_gauge.c +1 -0
index a7c8a8453db1..9dcd55f1d9f3 100644
@@ -705,6 +705,7 @@ static const struct power_supply_desc sc27xx_fgu_desc = {
 	.set_property		= sc27xx_fgu_set_property,
 	.external_power_changed	= sc27xx_fgu_external_power_changed,
 	.property_is_writeable	= sc27xx_fgu_property_is_writeable,
+	.no_thermal		= true,
 };
 
 static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap)
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH 2/4 power: supply: sc27xx: Allow to change the battery full capacity

In reply to Baolin Wang

From: Yuanjiang Yu <[email protected]>

The battery full capacity can be affected by the temperature or the servicing time or other factors, so some platforms will track the real battery full capacity in charger manager service. Thus we should allow to change the battery full capacity by setting the 'POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN' property as writeable.

---
 drivers/power/supply/sc27xx_fuel_gauge.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/power/supply/sc27xx_fuel_gauge.c +7 -1
index 9dcd55f1d9f3..5970d4a78016 100644
@@ -656,6 +656,11 @@ static int sc27xx_fgu_set_property(struct power_supply *psy,
 		ret = 0;
 		break;
 
+	case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
+		data->total_cap = val->intval / 1000;
+		ret = 0;
+		break;
+
 	default:
 		ret = -EINVAL;
 	}
@@ -676,7 +681,8 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
 					    enum power_supply_property psp)
 {
 	return psp == POWER_SUPPLY_PROP_CAPACITY ||
-		psp == POWER_SUPPLY_PROP_CALIBRATE;
+		psp == POWER_SUPPLY_PROP_CALIBRATE ||
+		psp == POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
 }
 
 static enum power_supply_property sc27xx_fgu_props[] = {
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

PATCH 3/4 power: supply: sc27xx: Add CURRENT_NOW/VOLTAGE_NOW properties support

In reply to Baolin Wang

From: Yuanjiang Yu <[email protected]>

Add new properties to get present current and voltage of the fuel gauge.

---
 drivers/power/supply/sc27xx_fuel_gauge.c | 60 +++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 2 deletions(-)
drivers/power/supply/sc27xx_fuel_gauge.c +58 -2
index 5970d4a78016..82d0c64ef269 100644
@@ -42,6 +42,8 @@
 #define SC27XX_FGU_USER_AREA_SET	0xa0
 #define SC27XX_FGU_USER_AREA_CLEAR	0xa4
 #define SC27XX_FGU_USER_AREA_STATUS	0xa8
+#define SC27XX_FGU_VOLTAGE_BUF		0xd0
+#define SC27XX_FGU_CURRENT_BUF		0xf0
 
 #define SC27XX_WRITE_SELCLB_EN		BIT(0)
 #define SC27XX_FGU_CLBCNT_MASK		GENMASK(15, 0)
@@ -376,6 +378,44 @@ static int sc27xx_fgu_get_clbcnt(struct sc27xx_fgu_data *data, int *clb_cnt)
 	return 0;
 }
 
+static int sc27xx_fgu_get_vol_now(struct sc27xx_fgu_data *data, int *val)
+{
+	int ret;
+	u32 vol;
+
+	ret = regmap_read(data->regmap, data->base + SC27XX_FGU_VOLTAGE_BUF,
+			  &vol);
+	if (ret)
+		return ret;
+
+	/*
+	 * It is ADC values reading from registers which need to convert to
+	 * corresponding voltage values.
+	 */
+	*val = sc27xx_fgu_adc_to_voltage(data, vol);
+
+	return 0;
+}
+
+static int sc27xx_fgu_get_cur_now(struct sc27xx_fgu_data *data, int *val)
+{
+	int ret;
+	u32 cur;
+
+	ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CURRENT_BUF,
+			  &cur);
+	if (ret)
+		return ret;
+
+	/*
+	 * It is ADC values reading from registers which need to convert to
+	 * corresponding current values.
+	 */
+	*val = sc27xx_fgu_adc_to_current(data, cur - SC27XX_FGU_CUR_BASIC_ADC);
+
+	return 0;
+}
+
 static int sc27xx_fgu_get_capacity(struct sc27xx_fgu_data *data, int *cap)
 {
 	int ret, cur_clbcnt, delta_clbcnt, delta_cap, temp;
@@ -577,7 +617,7 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 		val->intval = value;
 		break;
 
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+	case POWER_SUPPLY_PROP_VOLTAGE_AVG:
 		ret = sc27xx_fgu_get_vbat_vol(data, &value);
 		if (ret)
 			goto error;
@@ -601,7 +641,6 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 		val->intval = value;
 		break;
 
-	case POWER_SUPPLY_PROP_CURRENT_NOW:
 	case POWER_SUPPLY_PROP_CURRENT_AVG:
 		ret = sc27xx_fgu_get_current(data, &value);
 		if (ret)
@@ -625,6 +664,22 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 
 		break;
 
+	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+		ret = sc27xx_fgu_get_vol_now(data, &value);
+		if (ret)
+			goto error;
+
+		val->intval = value * 1000;
+		break;
+
+	case POWER_SUPPLY_PROP_CURRENT_NOW:
+		ret = sc27xx_fgu_get_cur_now(data, &value);
+		if (ret)
+			goto error;
+
+		val->intval = value * 1000;
+		break;
+
 	default:
 		ret = -EINVAL;
 		break;
@@ -694,6 +749,7 @@ static enum power_supply_property sc27xx_fgu_props[] = {
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_OCV,
+	POWER_SUPPLY_PROP_VOLTAGE_AVG,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_CURRENT_AVG,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH 4/4 power: supply: sc27xx: Add boot voltage support

In reply to Baolin Wang

From: Yuanjiang Yu <[email protected]>

Add new property to allow to get the voltage measured during boot time.

---
 drivers/power/supply/sc27xx_fuel_gauge.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/power/supply/sc27xx_fuel_gauge.c +8 -0
index 82d0c64ef269..be42e814ea34 100644
@@ -84,6 +84,7 @@
  * @init_clbcnt: the initial coulomb counter
  * @max_volt: the maximum constant input voltage in millivolt
  * @min_volt: the minimum drained battery voltage in microvolt
+ * @boot_volt: the voltage measured during boot in microvolt
  * @table_len: the capacity table length
  * @resist_table_len: the resistance table length
  * @cur_1000ma_adc: ADC value corresponding to 1000 mA
@@ -109,6 +110,7 @@ struct sc27xx_fgu_data {
 	int init_clbcnt;
 	int max_volt;
 	int min_volt;
+	int boot_volt;
 	int table_len;
 	int resist_table_len;
 	int cur_1000ma_adc;
@@ -321,6 +323,7 @@ static int sc27xx_fgu_get_boot_capacity(struct sc27xx_fgu_data *data, int *cap)
 
 	volt = sc27xx_fgu_adc_to_voltage(data, volt);
 	ocv = volt * 1000 - oci * data->internal_resist;
+	data->boot_volt = ocv;
 
 	/*
 	 * Parse the capacity table to look up the correct capacity percent
@@ -680,6 +683,10 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 		val->intval = value * 1000;
 		break;
 
+	case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
+		val->intval = data->boot_volt;
+		break;
+
 	default:
 		ret = -EINVAL;
 		break;
@@ -750,6 +757,7 @@ static enum power_supply_property sc27xx_fgu_props[] = {
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_OCV,
 	POWER_SUPPLY_PROP_VOLTAGE_AVG,
+	POWER_SUPPLY_PROP_VOLTAGE_BOOT,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_CURRENT_AVG,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
Signature · 1 line
2.17.1
#5 lore raw
In reply to Baolin Wang

Hi,

Quoted 4 lines · Baolin Wang

This patch set adds some new properties for the SC27XX fuel gauge, as well as changing the 'POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN' as writeable. Thanks.

Quoted 8 lines

Yuanjiang Yu (4):
power: supply: sc27xx: Set 'no_thermal' flag for SC27xx fuel gauge
power: supply: sc27xx: Allow to change the battery full capacity
power: supply: sc27xx: Add CURRENT_NOW/VOLTAGE_NOW properties support
power: supply: sc27xx: Add boot voltage support

 drivers/power/supply/sc27xx_fuel_gauge.c | 77 +++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 3 deletions(-)

Thanks, queued.

-- Sebastian