linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: sbs-battery: do not use global variables
@ 2021-04-27  9:37 Ikjoon Jang
  2021-04-28  4:08 ` [PATCH v2] power: supply: sbs-battery: cache constant string properties Ikjoon Jang
  0 siblings, 1 reply; 3+ messages in thread
From: Ikjoon Jang @ 2021-04-27  9:37 UTC (permalink / raw)
  To: linux-pm; +Cc: hsinyi, Ikjoon Jang, Sebastian Reichel, linux-kernel

Currently sbs-battery driver declares three string buffers as global
variables for manufacturer, model_name, and chemistry. This patch
moves them into struct sbs_info.

Additionally, for 'chemistry' string property, suppress dev_warn() into
dev_warn_once() for some ChromeOS devices exposing chemistry property
as a non-standard string.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>

---

 drivers/power/supply/sbs-battery.c | 118 ++++++++++++++++-------------
 1 file changed, 66 insertions(+), 52 deletions(-)

diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index 4bf92831cb06..f51ff1d7b12f 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -188,6 +188,14 @@ static const enum power_supply_property sbs_properties[] = {
 /* Supports special manufacturer commands from TI BQ20Z65 and BQ20Z75 IC. */
 #define SBS_FLAGS_TI_BQ20ZX5		BIT(0)
 
+const enum power_supply_property string_properties[] = {
+	POWER_SUPPLY_PROP_TECHNOLOGY,
+	POWER_SUPPLY_PROP_MANUFACTURER,
+	POWER_SUPPLY_PROP_MODEL_NAME,
+};
+
+#define NR_STRING_BUFFERS	ARRAY_SIZE(string_properties)
+
 struct sbs_info {
 	struct i2c_client		*client;
 	struct power_supply		*power_supply;
@@ -201,11 +209,21 @@ struct sbs_info {
 	struct delayed_work		work;
 	struct mutex			mode_lock;
 	u32				flags;
+	char				strings[NR_STRING_BUFFERS][I2C_SMBUS_BLOCK_MAX + 1];
 };
 
-static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
-static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
-static char chemistry[I2C_SMBUS_BLOCK_MAX + 1];
+static char *sbs_get_string_buf(struct sbs_info *chip,
+				enum power_supply_property psp)
+{
+	int i = 0;
+
+	for (i = 0; i < NR_STRING_BUFFERS; i++)
+		if (string_properties[i] == psp)
+			return chip->strings[i];
+
+	return ERR_PTR(-EINVAL);
+}
+
 static bool force_load;
 
 static int sbs_read_word_data(struct i2c_client *client, u8 address);
@@ -639,17 +657,43 @@ static int sbs_get_battery_property(struct i2c_client *client,
 	return 0;
 }
 
-static int sbs_get_battery_string_property(struct i2c_client *client,
-	int reg_offset, enum power_supply_property psp, char *val)
+static int sbs_get_property_index(struct i2c_client *client,
+	enum power_supply_property psp)
 {
-	s32 ret;
+	int count;
+
+	for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
+		if (psp == sbs_data[count].psp)
+			return count;
+
+	dev_warn(&client->dev,
+		"%s: Invalid Property - %d\n", __func__, psp);
+
+	return -EINVAL;
+}
 
-	ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val);
+static const char *sbs_get_battery_string_property(struct sbs_info *chip,
+			enum power_supply_property psp)
+{
+	int ret;
+	char *buf;
+	u8 addr;
 
+	ret = sbs_get_property_index(chip->client, psp);
 	if (ret < 0)
-		return ret;
+		return ERR_PTR(ret);
 
-	return 0;
+	addr = sbs_data[ret].addr;
+
+	buf = sbs_get_string_buf(chip, psp);
+	if (IS_ERR(buf))
+		return buf;
+
+	ret = sbs_read_string_data(chip->client, addr, buf);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	return buf;
 }
 
 static void  sbs_unit_adjustment(struct i2c_client *client,
@@ -772,34 +816,14 @@ static int sbs_get_battery_serial_number(struct i2c_client *client,
 	return 0;
 }
 
-static int sbs_get_property_index(struct i2c_client *client,
-	enum power_supply_property psp)
-{
-	int count;
-	for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
-		if (psp == sbs_data[count].psp)
-			return count;
-
-	dev_warn(&client->dev,
-		"%s: Invalid Property - %d\n", __func__, psp);
-
-	return -EINVAL;
-}
-
-static int sbs_get_chemistry(struct i2c_client *client,
+static int sbs_get_chemistry(struct sbs_info *chip,
 		union power_supply_propval *val)
 {
-	enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY;
-	int ret;
+	const char *chemistry = sbs_get_battery_string_property(chip,
+					POWER_SUPPLY_PROP_TECHNOLOGY);
 
-	ret = sbs_get_property_index(client, psp);
-	if (ret < 0)
-		return ret;
-
-	ret = sbs_get_battery_string_property(client, ret, psp,
-					      chemistry);
-	if (ret < 0)
-		return ret;
+	if (IS_ERR(chemistry))
+		return PTR_ERR(chemistry);
 
 	if (!strncasecmp(chemistry, "LION", 4))
 		val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
@@ -813,7 +837,7 @@ static int sbs_get_chemistry(struct i2c_client *client,
 		val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
 
 	if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
-		dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry);
+		dev_warn_once(&chip->client->dev, "Unknown chemistry: %s\n", chemistry);
 
 	return 0;
 }
@@ -857,6 +881,7 @@ static int sbs_get_property(struct power_supply *psy,
 	int ret = 0;
 	struct sbs_info *chip = power_supply_get_drvdata(psy);
 	struct i2c_client *client = chip->client;
+	const char *str;
 
 	if (chip->gpio_detect) {
 		ret = gpiod_get_value_cansleep(chip->gpio_detect);
@@ -882,7 +907,7 @@ static int sbs_get_property(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_TECHNOLOGY:
-		ret = sbs_get_chemistry(client, val);
+		ret = sbs_get_chemistry(chip, val);
 		if (ret < 0)
 			break;
 
@@ -934,23 +959,12 @@ static int sbs_get_property(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_MODEL_NAME:
-		ret = sbs_get_property_index(client, psp);
-		if (ret < 0)
-			break;
-
-		ret = sbs_get_battery_string_property(client, ret, psp,
-						      model_name);
-		val->strval = model_name;
-		break;
-
 	case POWER_SUPPLY_PROP_MANUFACTURER:
-		ret = sbs_get_property_index(client, psp);
-		if (ret < 0)
-			break;
-
-		ret = sbs_get_battery_string_property(client, ret, psp,
-						      manufacturer);
-		val->strval = manufacturer;
+		str = sbs_get_battery_string_property(chip, psp);
+		if (IS_ERR(str))
+			ret = PTR_ERR(str);
+		else
+			val->strval = str;
 		break;
 
 	case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] power: supply: sbs-battery: cache constant string properties
  2021-04-27  9:37 [PATCH] power: supply: sbs-battery: do not use global variables Ikjoon Jang
@ 2021-04-28  4:08 ` Ikjoon Jang
  2021-05-03 10:04   ` Hsin-Yi Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Ikjoon Jang @ 2021-04-28  4:08 UTC (permalink / raw)
  To: linux-pm, Sebastian Reichel; +Cc: Hsinyi Wang, Ikjoon Jang, linux-kernel

Currently sbs-battery supports three string properties -
manufacturer, model_name, and chemistry. Buffers for those
properties are currently defined as global variables.

This patch moves those global variables into struct sbs_info
and cache/reuse them as they are all constant values.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>

---

Changes in v2:
- change function name of sbs_get_battery_string_property()
  to sbs_get_constant_string()
- use cached string properties
- use cached technology integer value in sbs_get_chemistry()

 drivers/power/supply/sbs-battery.c | 140 +++++++++++++++++------------
 1 file changed, 82 insertions(+), 58 deletions(-)

diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index 4bf92831cb06..414de9bc47bf 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -188,6 +188,14 @@ static const enum power_supply_property sbs_properties[] = {
 /* Supports special manufacturer commands from TI BQ20Z65 and BQ20Z75 IC. */
 #define SBS_FLAGS_TI_BQ20ZX5		BIT(0)
 
+static const enum power_supply_property string_properties[] = {
+	POWER_SUPPLY_PROP_TECHNOLOGY,
+	POWER_SUPPLY_PROP_MANUFACTURER,
+	POWER_SUPPLY_PROP_MODEL_NAME,
+};
+
+#define NR_STRING_BUFFERS	ARRAY_SIZE(string_properties)
+
 struct sbs_info {
 	struct i2c_client		*client;
 	struct power_supply		*power_supply;
@@ -201,11 +209,22 @@ struct sbs_info {
 	struct delayed_work		work;
 	struct mutex			mode_lock;
 	u32				flags;
+	int				technology;
+	char				strings[NR_STRING_BUFFERS][I2C_SMBUS_BLOCK_MAX + 1];
 };
 
-static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
-static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
-static char chemistry[I2C_SMBUS_BLOCK_MAX + 1];
+static char *sbs_get_string_buf(struct sbs_info *chip,
+				enum power_supply_property psp)
+{
+	int i = 0;
+
+	for (i = 0; i < NR_STRING_BUFFERS; i++)
+		if (string_properties[i] == psp)
+			return chip->strings[i];
+
+	return ERR_PTR(-EINVAL);
+}
+
 static bool force_load;
 
 static int sbs_read_word_data(struct i2c_client *client, u8 address);
@@ -639,17 +658,45 @@ static int sbs_get_battery_property(struct i2c_client *client,
 	return 0;
 }
 
-static int sbs_get_battery_string_property(struct i2c_client *client,
-	int reg_offset, enum power_supply_property psp, char *val)
+static int sbs_get_property_index(struct i2c_client *client,
+	enum power_supply_property psp)
 {
-	s32 ret;
+	int count;
+
+	for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
+		if (psp == sbs_data[count].psp)
+			return count;
 
-	ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val);
+	dev_warn(&client->dev,
+		"%s: Invalid Property - %d\n", __func__, psp);
 
-	if (ret < 0)
-		return ret;
+	return -EINVAL;
+}
 
-	return 0;
+static const char *sbs_get_constant_string(struct sbs_info *chip,
+			enum power_supply_property psp)
+{
+	int ret;
+	char *buf;
+	u8 addr;
+
+	buf = sbs_get_string_buf(chip, psp);
+	if (IS_ERR(buf))
+		return buf;
+
+	if (!buf[0]) {
+		ret = sbs_get_property_index(chip->client, psp);
+		if (ret < 0)
+			return ERR_PTR(ret);
+
+		addr = sbs_data[ret].addr;
+
+		ret = sbs_read_string_data(chip->client, addr, buf);
+		if (ret < 0)
+			return ERR_PTR(ret);
+	}
+
+	return buf;
 }
 
 static void  sbs_unit_adjustment(struct i2c_client *client,
@@ -772,48 +819,34 @@ static int sbs_get_battery_serial_number(struct i2c_client *client,
 	return 0;
 }
 
-static int sbs_get_property_index(struct i2c_client *client,
-	enum power_supply_property psp)
-{
-	int count;
-	for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
-		if (psp == sbs_data[count].psp)
-			return count;
-
-	dev_warn(&client->dev,
-		"%s: Invalid Property - %d\n", __func__, psp);
-
-	return -EINVAL;
-}
-
-static int sbs_get_chemistry(struct i2c_client *client,
+static int sbs_get_chemistry(struct sbs_info *chip,
 		union power_supply_propval *val)
 {
-	enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY;
-	int ret;
+	const char *chemistry;
 
-	ret = sbs_get_property_index(client, psp);
-	if (ret < 0)
-		return ret;
+	if (chip->technology >= POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
+		return chip->technology;
 
-	ret = sbs_get_battery_string_property(client, ret, psp,
-					      chemistry);
-	if (ret < 0)
-		return ret;
+	chemistry = sbs_get_constant_string(chip, POWER_SUPPLY_PROP_TECHNOLOGY);
+
+	if (IS_ERR(chemistry))
+		return PTR_ERR(chemistry);
 
 	if (!strncasecmp(chemistry, "LION", 4))
-		val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
+		chip->technology = POWER_SUPPLY_TECHNOLOGY_LION;
 	else if (!strncasecmp(chemistry, "LiP", 3))
-		val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
+		chip->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
 	else if (!strncasecmp(chemistry, "NiCd", 4))
-		val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd;
+		chip->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
 	else if (!strncasecmp(chemistry, "NiMH", 4))
-		val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH;
+		chip->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
 	else
-		val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
+		chip->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
 
-	if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
-		dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry);
+	if (chip->technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
+		dev_warn(&chip->client->dev, "Unknown chemistry: %s\n", chemistry);
+
+	val->intval = chip->technology;
 
 	return 0;
 }
@@ -857,6 +890,7 @@ static int sbs_get_property(struct power_supply *psy,
 	int ret = 0;
 	struct sbs_info *chip = power_supply_get_drvdata(psy);
 	struct i2c_client *client = chip->client;
+	const char *str;
 
 	if (chip->gpio_detect) {
 		ret = gpiod_get_value_cansleep(chip->gpio_detect);
@@ -882,7 +916,7 @@ static int sbs_get_property(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_TECHNOLOGY:
-		ret = sbs_get_chemistry(client, val);
+		ret = sbs_get_chemistry(chip, val);
 		if (ret < 0)
 			break;
 
@@ -934,23 +968,12 @@ static int sbs_get_property(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_MODEL_NAME:
-		ret = sbs_get_property_index(client, psp);
-		if (ret < 0)
-			break;
-
-		ret = sbs_get_battery_string_property(client, ret, psp,
-						      model_name);
-		val->strval = model_name;
-		break;
-
 	case POWER_SUPPLY_PROP_MANUFACTURER:
-		ret = sbs_get_property_index(client, psp);
-		if (ret < 0)
-			break;
-
-		ret = sbs_get_battery_string_property(client, ret, psp,
-						      manufacturer);
-		val->strval = manufacturer;
+		str = sbs_get_constant_string(chip, psp);
+		if (IS_ERR(str))
+			ret = PTR_ERR(str);
+		else
+			val->strval = str;
 		break;
 
 	case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
@@ -1097,6 +1120,7 @@ static int sbs_probe(struct i2c_client *client)
 	psy_cfg.of_node = client->dev.of_node;
 	psy_cfg.drv_data = chip;
 	chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
+	chip->technology = -1;
 	mutex_init(&chip->mode_lock);
 
 	/* use pdata if available, fall back to DT properties,
-- 
2.31.1.498.g6c1eba8ee3d-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] power: supply: sbs-battery: cache constant string properties
  2021-04-28  4:08 ` [PATCH v2] power: supply: sbs-battery: cache constant string properties Ikjoon Jang
@ 2021-05-03 10:04   ` Hsin-Yi Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Hsin-Yi Wang @ 2021-05-03 10:04 UTC (permalink / raw)
  To: Ikjoon Jang; +Cc: Linux PM, Sebastian Reichel, lkml

On Wed, Apr 28, 2021 at 12:08 PM Ikjoon Jang <ikjn@chromium.org> wrote:
>
> Currently sbs-battery supports three string properties -
> manufacturer, model_name, and chemistry. Buffers for those
> properties are currently defined as global variables.
>
> This patch moves those global variables into struct sbs_info
> and cache/reuse them as they are all constant values.
>
> Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
>

Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>

Test on a mt8183 krane device which uses sbs battery.

> ---
>
> Changes in v2:
> - change function name of sbs_get_battery_string_property()
>   to sbs_get_constant_string()
> - use cached string properties
> - use cached technology integer value in sbs_get_chemistry()
>
>  drivers/power/supply/sbs-battery.c | 140 +++++++++++++++++------------
>  1 file changed, 82 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
> index 4bf92831cb06..414de9bc47bf 100644
> --- a/drivers/power/supply/sbs-battery.c
> +++ b/drivers/power/supply/sbs-battery.c
> @@ -188,6 +188,14 @@ static const enum power_supply_property sbs_properties[] = {
>  /* Supports special manufacturer commands from TI BQ20Z65 and BQ20Z75 IC. */
>  #define SBS_FLAGS_TI_BQ20ZX5           BIT(0)
>
> +static const enum power_supply_property string_properties[] = {
> +       POWER_SUPPLY_PROP_TECHNOLOGY,
> +       POWER_SUPPLY_PROP_MANUFACTURER,
> +       POWER_SUPPLY_PROP_MODEL_NAME,
> +};
> +
> +#define NR_STRING_BUFFERS      ARRAY_SIZE(string_properties)
> +
>  struct sbs_info {
>         struct i2c_client               *client;
>         struct power_supply             *power_supply;
> @@ -201,11 +209,22 @@ struct sbs_info {
>         struct delayed_work             work;
>         struct mutex                    mode_lock;
>         u32                             flags;
> +       int                             technology;
> +       char                            strings[NR_STRING_BUFFERS][I2C_SMBUS_BLOCK_MAX + 1];
>  };
>
> -static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
> -static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
> -static char chemistry[I2C_SMBUS_BLOCK_MAX + 1];
> +static char *sbs_get_string_buf(struct sbs_info *chip,
> +                               enum power_supply_property psp)
> +{
> +       int i = 0;
> +
> +       for (i = 0; i < NR_STRING_BUFFERS; i++)
> +               if (string_properties[i] == psp)
> +                       return chip->strings[i];
> +
> +       return ERR_PTR(-EINVAL);
> +}
> +
>  static bool force_load;
>
>  static int sbs_read_word_data(struct i2c_client *client, u8 address);
> @@ -639,17 +658,45 @@ static int sbs_get_battery_property(struct i2c_client *client,
>         return 0;
>  }
>
> -static int sbs_get_battery_string_property(struct i2c_client *client,
> -       int reg_offset, enum power_supply_property psp, char *val)
> +static int sbs_get_property_index(struct i2c_client *client,
> +       enum power_supply_property psp)
>  {
> -       s32 ret;
> +       int count;
> +
> +       for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
> +               if (psp == sbs_data[count].psp)
> +                       return count;
>
> -       ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val);
> +       dev_warn(&client->dev,
> +               "%s: Invalid Property - %d\n", __func__, psp);
>
> -       if (ret < 0)
> -               return ret;
> +       return -EINVAL;
> +}
>
> -       return 0;
> +static const char *sbs_get_constant_string(struct sbs_info *chip,
> +                       enum power_supply_property psp)
> +{
> +       int ret;
> +       char *buf;
> +       u8 addr;
> +
> +       buf = sbs_get_string_buf(chip, psp);
> +       if (IS_ERR(buf))
> +               return buf;
> +
> +       if (!buf[0]) {
> +               ret = sbs_get_property_index(chip->client, psp);
> +               if (ret < 0)
> +                       return ERR_PTR(ret);
> +
> +               addr = sbs_data[ret].addr;
> +
> +               ret = sbs_read_string_data(chip->client, addr, buf);
> +               if (ret < 0)
> +                       return ERR_PTR(ret);
> +       }
> +
> +       return buf;
>  }
>
>  static void  sbs_unit_adjustment(struct i2c_client *client,
> @@ -772,48 +819,34 @@ static int sbs_get_battery_serial_number(struct i2c_client *client,
>         return 0;
>  }
>
> -static int sbs_get_property_index(struct i2c_client *client,
> -       enum power_supply_property psp)
> -{
> -       int count;
> -       for (count = 0; count < ARRAY_SIZE(sbs_data); count++)
> -               if (psp == sbs_data[count].psp)
> -                       return count;
> -
> -       dev_warn(&client->dev,
> -               "%s: Invalid Property - %d\n", __func__, psp);
> -
> -       return -EINVAL;
> -}
> -
> -static int sbs_get_chemistry(struct i2c_client *client,
> +static int sbs_get_chemistry(struct sbs_info *chip,
>                 union power_supply_propval *val)
>  {
> -       enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY;
> -       int ret;
> +       const char *chemistry;
>
> -       ret = sbs_get_property_index(client, psp);
> -       if (ret < 0)
> -               return ret;
> +       if (chip->technology >= POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
> +               return chip->technology;
>
> -       ret = sbs_get_battery_string_property(client, ret, psp,
> -                                             chemistry);
> -       if (ret < 0)
> -               return ret;
> +       chemistry = sbs_get_constant_string(chip, POWER_SUPPLY_PROP_TECHNOLOGY);
> +
> +       if (IS_ERR(chemistry))
> +               return PTR_ERR(chemistry);
>
>         if (!strncasecmp(chemistry, "LION", 4))
> -               val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
> +               chip->technology = POWER_SUPPLY_TECHNOLOGY_LION;
>         else if (!strncasecmp(chemistry, "LiP", 3))
> -               val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
> +               chip->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
>         else if (!strncasecmp(chemistry, "NiCd", 4))
> -               val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd;
> +               chip->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
>         else if (!strncasecmp(chemistry, "NiMH", 4))
> -               val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH;
> +               chip->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
>         else
> -               val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
> +               chip->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
>
> -       if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
> -               dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry);
> +       if (chip->technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
> +               dev_warn(&chip->client->dev, "Unknown chemistry: %s\n", chemistry);
> +
> +       val->intval = chip->technology;
>
>         return 0;
>  }
> @@ -857,6 +890,7 @@ static int sbs_get_property(struct power_supply *psy,
>         int ret = 0;
>         struct sbs_info *chip = power_supply_get_drvdata(psy);
>         struct i2c_client *client = chip->client;
> +       const char *str;
>
>         if (chip->gpio_detect) {
>                 ret = gpiod_get_value_cansleep(chip->gpio_detect);
> @@ -882,7 +916,7 @@ static int sbs_get_property(struct power_supply *psy,
>                 break;
>
>         case POWER_SUPPLY_PROP_TECHNOLOGY:
> -               ret = sbs_get_chemistry(client, val);
> +               ret = sbs_get_chemistry(chip, val);
>                 if (ret < 0)
>                         break;
>
> @@ -934,23 +968,12 @@ static int sbs_get_property(struct power_supply *psy,
>                 break;
>
>         case POWER_SUPPLY_PROP_MODEL_NAME:
> -               ret = sbs_get_property_index(client, psp);
> -               if (ret < 0)
> -                       break;
> -
> -               ret = sbs_get_battery_string_property(client, ret, psp,
> -                                                     model_name);
> -               val->strval = model_name;
> -               break;
> -
>         case POWER_SUPPLY_PROP_MANUFACTURER:
> -               ret = sbs_get_property_index(client, psp);
> -               if (ret < 0)
> -                       break;
> -
> -               ret = sbs_get_battery_string_property(client, ret, psp,
> -                                                     manufacturer);
> -               val->strval = manufacturer;
> +               str = sbs_get_constant_string(chip, psp);
> +               if (IS_ERR(str))
> +                       ret = PTR_ERR(str);
> +               else
> +                       val->strval = str;
>                 break;
>
>         case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
> @@ -1097,6 +1120,7 @@ static int sbs_probe(struct i2c_client *client)
>         psy_cfg.of_node = client->dev.of_node;
>         psy_cfg.drv_data = chip;
>         chip->last_state = POWER_SUPPLY_STATUS_UNKNOWN;
> +       chip->technology = -1;
>         mutex_init(&chip->mode_lock);
>
>         /* use pdata if available, fall back to DT properties,
> --
> 2.31.1.498.g6c1eba8ee3d-goog
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-03 10:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-27  9:37 [PATCH] power: supply: sbs-battery: do not use global variables Ikjoon Jang
2021-04-28  4:08 ` [PATCH v2] power: supply: sbs-battery: cache constant string properties Ikjoon Jang
2021-05-03 10:04   ` Hsin-Yi Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).