2020-04-20 03:43:50

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 0/4] 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(-)

--
2.17.1


2020-04-20 03:43:58

by Baolin Wang

[permalink] [raw]
Subject: [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.

Signed-off-by: Yuanjiang Yu <[email protected]>
Signed-off-by: Baolin Wang <[email protected]>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index a7c8a8453db1..9dcd55f1d9f3 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -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)
--
2.17.1

2020-04-20 03:44:07

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 2/4] power: supply: sc27xx: Allow to change the battery full capacity

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.

Signed-off-by: Yuanjiang Yu <[email protected]>
Signed-off-by: Baolin Wang <[email protected]>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index 9dcd55f1d9f3..5970d4a78016 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -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[] = {
--
2.17.1

2020-04-20 03:45:29

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 3/4] power: supply: sc27xx: Add CURRENT_NOW/VOLTAGE_NOW properties support

From: Yuanjiang Yu <[email protected]>

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

Signed-off-by: Yuanjiang Yu <[email protected]>
Signed-off-by: Baolin Wang <[email protected]>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 60 +++++++++++++++++++++++-
1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index 5970d4a78016..82d0c64ef269 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -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,
--
2.17.1

2020-04-20 03:47:39

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 4/4] power: supply: sc27xx: Add boot voltage support

From: Yuanjiang Yu <[email protected]>

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

Signed-off-by: Yuanjiang Yu <[email protected]>
Signed-off-by: Baolin Wang <[email protected]>
---
drivers/power/supply/sc27xx_fuel_gauge.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index 82d0c64ef269..be42e814ea34 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -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,
--
2.17.1

2020-04-28 19:28:42

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH 0/4] Add some new properties for the SC27XX fuel gauge

Hi,

On Mon, Apr 20, 2020 at 11:42:03AM +0800, Baolin Wang wrote:
> 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(-)

Thanks, queued.

-- Sebastian


Attachments:
(No filename) (692.00 B)
signature.asc (849.00 B)
Download all attachments