All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] sbs-battery: Add missing power class sysfs files
@ 2014-08-04 11:47 Javier Martinez Canillas
  2014-08-04 11:47 ` [PATCH 1/2] sbs-battery: export manufacturer and model name to sysfs Javier Martinez Canillas
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2014-08-04 11:47 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Dmitry Eremin-Solenikov, Doug Anderson, Olof Johansson,
	Simon Que, cychiang, linux-pm, linux-samsung-soc,
	Javier Martinez Canillas

This series add the model_name, manufacturer and voltage_min_design
files from the power supply monitor class sysfs interface that were
missing for the sbs-battery driver. The commits were taken from the
Chrome OS 3.8 downstream kernel and patches were squashed when they
just fixed bugs introduced on previous commits that do the export.

The patch-set was tested on a Exynos5420 based Peach Pit machine by
confirming that the sysfs files existed and provide the right data:

# cat /sys/class/power_supply/sbs-20-000b/{voltage_min_design,manufacturer,model_name}
7500000
SANYO
4302A40

Simon Que (1):
  sbs-battery: add min design voltage to sbs-battery

cychiang (1):
  sbs-battery: export manufacturer and model name to sysfs

 drivers/power/sbs-battery.c | 125 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 2 deletions(-)

Best regards,
Javier

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

* [PATCH 1/2] sbs-battery: export manufacturer and model name to sysfs
  2014-08-04 11:47 [PATCH 0/2] sbs-battery: Add missing power class sysfs files Javier Martinez Canillas
@ 2014-08-04 11:47 ` Javier Martinez Canillas
  2014-08-04 11:47 ` [PATCH 2/2] sbs-battery: add min design voltage to sbs-battery Javier Martinez Canillas
  2014-08-06  0:40 ` [PATCH 0/2] sbs-battery: Add missing power class sysfs files Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2014-08-04 11:47 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Dmitry Eremin-Solenikov, Doug Anderson, Olof Johansson,
	Simon Que, cychiang, linux-pm, linux-samsung-soc,
	Javier Martinez Canillas

From: cychiang <cychiang@chromium.org>

This CL supports two power_supply_property items for smart battery:
POWER_SUPPLY_PROP_MANUFACTURER and POWER_SUPPLY_PROP_MODEL_NAME such
that battery information 'manufacturer' and 'model_name' can be exported
to sysfs.

Signed-off-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
---
 drivers/power/sbs-battery.c | 115 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index b5f2a76..08feb38 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -49,6 +49,8 @@ enum {
 	REG_DESIGN_CAPACITY,
 	REG_DESIGN_CAPACITY_CHARGE,
 	REG_DESIGN_VOLTAGE,
+	REG_MANUFACTURER,
+	REG_MODEL_NAME,
 };
 
 /* Battery Mode defines */
@@ -68,6 +70,7 @@ enum sbs_battery_mode {
 #define BATTERY_FULL_CHARGED		0x20
 #define BATTERY_FULL_DISCHARGED		0x10
 
+/* min_value and max_value are only valid for numerical data */
 #define SBS_DATA(_psp, _addr, _min_value, _max_value) { \
 	.psp = _psp, \
 	.addr = _addr, \
@@ -115,6 +118,11 @@ static const struct chip_data {
 		SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535),
 	[REG_SERIAL_NUMBER] =
 		SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535),
+	/* Properties of type `const char *' */
+	[REG_MANUFACTURER] =
+		SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535),
+	[REG_MODEL_NAME] =
+		SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535)
 };
 
 static enum power_supply_property sbs_properties[] = {
@@ -137,6 +145,9 @@ static enum power_supply_property sbs_properties[] = {
 	POWER_SUPPLY_PROP_CHARGE_NOW,
 	POWER_SUPPLY_PROP_CHARGE_FULL,
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
+	/* Properties of type `const char *' */
+	POWER_SUPPLY_PROP_MANUFACTURER,
+	POWER_SUPPLY_PROP_MODEL_NAME
 };
 
 struct sbs_info {
@@ -153,6 +164,9 @@ struct sbs_info {
 	int				ignore_changes;
 };
 
+static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
+static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
+
 static int sbs_read_word_data(struct i2c_client *client, u8 address)
 {
 	struct sbs_info *chip = i2c_get_clientdata(client);
@@ -179,6 +193,74 @@ static int sbs_read_word_data(struct i2c_client *client, u8 address)
 	return le16_to_cpu(ret);
 }
 
+static int sbs_read_string_data(struct i2c_client *client, u8 address,
+				char *values)
+{
+	struct sbs_info *chip = i2c_get_clientdata(client);
+	s32 ret = 0, block_length = 0;
+	int retries_length = 1, retries_block = 1;
+	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
+
+	if (chip->pdata) {
+		retries_length = max(chip->pdata->i2c_retry_count + 1, 1);
+		retries_block = max(chip->pdata->i2c_retry_count + 1, 1);
+	}
+
+	/* Adapter needs to support these two functions */
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_BYTE_DATA |
+				     I2C_FUNC_SMBUS_I2C_BLOCK)){
+		return -ENODEV;
+	}
+
+	/* Get the length of block data */
+	while (retries_length > 0) {
+		ret = i2c_smbus_read_byte_data(client, address);
+		if (ret >= 0)
+			break;
+		retries_length--;
+	}
+
+	if (ret < 0) {
+		dev_dbg(&client->dev,
+			"%s: i2c read at address 0x%x failed\n",
+			__func__, address);
+		return ret;
+	}
+
+	/* block_length does not include NULL terminator */
+	block_length = ret;
+	if (block_length > I2C_SMBUS_BLOCK_MAX) {
+		dev_err(&client->dev,
+			"%s: Returned block_length is longer than 0x%x\n",
+			__func__, I2C_SMBUS_BLOCK_MAX);
+		return -EINVAL;
+	}
+
+	/* Get the block data */
+	while (retries_block > 0) {
+		ret = i2c_smbus_read_i2c_block_data(
+				client, address,
+				block_length + 1, block_buffer);
+		if (ret >= 0)
+			break;
+		retries_block--;
+	}
+
+	if (ret < 0) {
+		dev_dbg(&client->dev,
+			"%s: i2c read at address 0x%x failed\n",
+			__func__, address);
+		return ret;
+	}
+
+	/* block_buffer[0] == block_length */
+	memcpy(values, block_buffer + 1, block_length);
+	values[block_length] = '\0';
+
+	return le16_to_cpu(ret);
+}
+
 static int sbs_write_word_data(struct i2c_client *client, u8 address,
 	u16 value)
 {
@@ -318,6 +400,19 @@ 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)
+{
+	s32 ret;
+
+	ret = sbs_read_string_data(client, sbs_data[reg_offset].addr, val);
+
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static void  sbs_unit_adjustment(struct i2c_client *client,
 	enum power_supply_property psp, union power_supply_propval *val)
 {
@@ -505,6 +600,26 @@ static int sbs_get_property(struct power_supply *psy,
 		ret = sbs_get_battery_property(client, ret, psp, val);
 		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;
+		break;
+
 	default:
 		dev_err(&client->dev,
 			"%s: INVALID property\n", __func__);
-- 
2.0.0.rc2

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

* [PATCH 2/2] sbs-battery: add min design voltage to sbs-battery
  2014-08-04 11:47 [PATCH 0/2] sbs-battery: Add missing power class sysfs files Javier Martinez Canillas
  2014-08-04 11:47 ` [PATCH 1/2] sbs-battery: export manufacturer and model name to sysfs Javier Martinez Canillas
@ 2014-08-04 11:47 ` Javier Martinez Canillas
  2014-08-06  0:40 ` [PATCH 0/2] sbs-battery: Add missing power class sysfs files Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2014-08-04 11:47 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Dmitry Eremin-Solenikov, Doug Anderson, Olof Johansson,
	Simon Que, cychiang, linux-pm, linux-samsung-soc,
	Javier Martinez Canillas

From: Simon Que <sque@chromium.org>

sbs-battery has a max design voltage but not a min design voltage field.
The SBS spec only has one design voltage:
http://www.sbs-forum.org/specs/sbdat110.pdf

Currently this is being used for max design voltage.  This patch uses it
for min design voltage as well.

Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
---
 drivers/power/sbs-battery.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 08feb38..c7b7b40 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -48,7 +48,8 @@ enum {
 	REG_FULL_CHARGE_CAPACITY_CHARGE,
 	REG_DESIGN_CAPACITY,
 	REG_DESIGN_CAPACITY_CHARGE,
-	REG_DESIGN_VOLTAGE,
+	REG_DESIGN_VOLTAGE_MIN,
+	REG_DESIGN_VOLTAGE_MAX,
 	REG_MANUFACTURER,
 	REG_MODEL_NAME,
 };
@@ -114,7 +115,9 @@ static const struct chip_data {
 		SBS_DATA(POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 0x18, 0, 65535),
 	[REG_DESIGN_CAPACITY_CHARGE] =
 		SBS_DATA(POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, 0x18, 0, 65535),
-	[REG_DESIGN_VOLTAGE] =
+	[REG_DESIGN_VOLTAGE_MIN] =
+		SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 0x19, 0, 65535),
+	[REG_DESIGN_VOLTAGE_MAX] =
 		SBS_DATA(POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, 0x19, 0, 65535),
 	[REG_SERIAL_NUMBER] =
 		SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535),
@@ -138,6 +141,7 @@ static enum power_supply_property sbs_properties[] = {
 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
 	POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
 	POWER_SUPPLY_PROP_SERIAL_NUMBER,
+	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
 	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 	POWER_SUPPLY_PROP_ENERGY_NOW,
 	POWER_SUPPLY_PROP_ENERGY_FULL,
@@ -431,6 +435,7 @@ static void  sbs_unit_adjustment(struct i2c_client *client,
 		break;
 
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
 	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 	case POWER_SUPPLY_PROP_CHARGE_NOW:
@@ -592,6 +597,7 @@ static int sbs_get_property(struct power_supply *psy,
 	case POWER_SUPPLY_PROP_TEMP:
 	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
 	case POWER_SUPPLY_PROP_TIME_TO_FULL_AVG:
+	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
 	case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
 		ret = sbs_get_property_index(client, psp);
 		if (ret < 0)
-- 
2.0.0.rc2


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

* Re: [PATCH 0/2] sbs-battery: Add missing power class sysfs files
  2014-08-04 11:47 [PATCH 0/2] sbs-battery: Add missing power class sysfs files Javier Martinez Canillas
  2014-08-04 11:47 ` [PATCH 1/2] sbs-battery: export manufacturer and model name to sysfs Javier Martinez Canillas
  2014-08-04 11:47 ` [PATCH 2/2] sbs-battery: add min design voltage to sbs-battery Javier Martinez Canillas
@ 2014-08-06  0:40 ` Sebastian Reichel
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2014-08-06  0:40 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: Dmitry Eremin-Solenikov, Doug Anderson, Olof Johansson,
	Simon Que, cychiang, linux-pm, linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 1268 bytes --]

On Mon, Aug 04, 2014 at 01:47:44PM +0200, Javier Martinez Canillas wrote:
> This series add the model_name, manufacturer and voltage_min_design
> files from the power supply monitor class sysfs interface that were
> missing for the sbs-battery driver. The commits were taken from the
> Chrome OS 3.8 downstream kernel and patches were squashed when they
> just fixed bugs introduced on previous commits that do the export.
> 
> The patch-set was tested on a Exynos5420 based Peach Pit machine by
> confirming that the sysfs files existed and provide the right data:
> 
> # cat /sys/class/power_supply/sbs-20-000b/{voltage_min_design,manufacturer,model_name}
> 7500000
> SANYO
> 4302A40
> 
> Simon Que (1):
>   sbs-battery: add min design voltage to sbs-battery
> 
> cychiang (1):
>   sbs-battery: export manufacturer and model name to sysfs
> 
>  drivers/power/sbs-battery.c | 125 +++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 123 insertions(+), 2 deletions(-)
> 
> Best regards,
> Javier

Both applied to battery.git's next-next branch. I modified the
author from the first commit (cychiang <cychiang@chromium.org>),
so that it's equal to the signed-off line (Cheng-Yi Chiang
<cychiang@chromium.org>).

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2014-08-06  0:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04 11:47 [PATCH 0/2] sbs-battery: Add missing power class sysfs files Javier Martinez Canillas
2014-08-04 11:47 ` [PATCH 1/2] sbs-battery: export manufacturer and model name to sysfs Javier Martinez Canillas
2014-08-04 11:47 ` [PATCH 2/2] sbs-battery: add min design voltage to sbs-battery Javier Martinez Canillas
2014-08-06  0:40 ` [PATCH 0/2] sbs-battery: Add missing power class sysfs files Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.