* [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture
@ 2020-06-09 19:22 Tim Wawrzynczak
2020-06-09 19:22 ` [PATCH 2/2] power: supply: sbs_battery: Support Manufacture Date field Tim Wawrzynczak
2020-06-09 23:29 ` [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Sebastian Reichel
0 siblings, 2 replies; 3+ messages in thread
From: Tim Wawrzynczak @ 2020-06-09 19:22 UTC (permalink / raw)
Cc: Sebastian Reichel, linux-pm, linux-kernel, Tim Wawrzynczak
The Smart Battery Specification v1.1 defines Manufacture Date as one of
its availabe registers. This patch adds this as a property so that
power_supply drivers can support the property and report it in syfs.
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Change-Id: I90bf8c67b0cd531f2155404424a98302a1c931d6
---
drivers/power/supply/power_supply_sysfs.c | 3 ++-
include/linux/power_supply.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index f37ad4eae60b9..ac6d9992a8675 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -171,7 +171,7 @@ static ssize_t power_supply_show_property(struct device *dev,
ret = sprintf(buf, "%s\n",
power_supply_scope_text[value.intval]);
break;
- case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
+ case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_MANUFACTURE_DATE:
ret = sprintf(buf, "%s\n", value.strval);
break;
default:
@@ -310,6 +310,7 @@ static struct device_attribute power_supply_attrs[] = {
POWER_SUPPLY_ATTR(model_name),
POWER_SUPPLY_ATTR(manufacturer),
POWER_SUPPLY_ATTR(serial_number),
+ POWER_SUPPLY_ATTR(manufacture_date),
};
static struct attribute *
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 28413f737e7d0..67839bb0a46b6 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -162,6 +162,7 @@ enum power_supply_property {
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_SERIAL_NUMBER,
+ POWER_SUPPLY_PROP_MANUFACTURE_DATE,
};
enum power_supply_type {
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] power: supply: sbs_battery: Support Manufacture Date field
2020-06-09 19:22 [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Tim Wawrzynczak
@ 2020-06-09 19:22 ` Tim Wawrzynczak
2020-06-09 23:29 ` [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Sebastian Reichel
1 sibling, 0 replies; 3+ messages in thread
From: Tim Wawrzynczak @ 2020-06-09 19:22 UTC (permalink / raw)
Cc: Sebastian Reichel, linux-pm, linux-kernel, Tim Wawrzynczak
This patch adds support for the sbs-battery driver to export a battery's
manufacture date as a field in sysfs. It is exported as a simple Y/M/D
format for ease of consumption.
Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Change-Id: Ia952624f33700587f4d71ad09ad68c0940c7f508
---
drivers/power/supply/sbs-battery.c | 31 +++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index f8d74e9f79317..989625be80743 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -42,6 +42,7 @@ enum {
REG_DESIGN_VOLTAGE_MAX,
REG_MANUFACTURER,
REG_MODEL_NAME,
+ REG_MANUFACTURE_DATE,
};
/* Battery Mode defines */
@@ -112,6 +113,10 @@ static const struct chip_data {
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),
+ /* Manufacture Date is encoded as a 16-bit register, but is exported
+ * from here as a string */
+ [REG_MANUFACTURE_DATE] =
+ SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURE_DATE, 0x1B, 0, 65535),
[REG_SERIAL_NUMBER] =
SBS_DATA(POWER_SUPPLY_PROP_SERIAL_NUMBER, 0x1C, 0, 65535),
/* Properties of type `const char *' */
@@ -145,7 +150,8 @@ static enum power_supply_property sbs_properties[] = {
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
/* Properties of type `const char *' */
POWER_SUPPLY_PROP_MANUFACTURER,
- POWER_SUPPLY_PROP_MODEL_NAME
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_MANUFACTURE_DATE,
};
/* Supports special manufacturer commands from TI BQ20Z75 IC. */
@@ -170,6 +176,10 @@ static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
static bool force_load;
+/* manufacture_date is returned as a 16-bit word in the smart battery itself.
+ * It is decoded here and displayed as "%4d/%2d/%2d", Y/m/d format. */
+static char manufacture_date[11];
+
static int sbs_read_word_data(struct i2c_client *client, u8 address)
{
struct sbs_info *chip = i2c_get_clientdata(client);
@@ -682,6 +692,25 @@ static int sbs_get_property(struct power_supply *psy,
ret = sbs_get_battery_property(client, ret, psp, val);
break;
+ case POWER_SUPPLY_PROP_MANUFACTURE_DATE:
+ ret = sbs_get_property_index(client, psp);
+ if (ret < 0)
+ break;
+
+ ret = sbs_get_battery_property(client, ret, psp, val);
+
+ /* Convert encoded data (from the SBS 1.1 spec) into a string:
+ * bits 9-15 are the year, encoded as years since 1980
+ * bits 5-8 are the month, encoded as 1-12
+ * bits 0-4 are the day of the month, encoded as 1-31 */
+ snprintf(manufacture_date, sizeof(manufacture_date),
+ "%4d/%2d/%2d",
+ ((val->intval >> 9) & 0x7f) + 1980,
+ (val->intval >> 5) & 0xf,
+ val->intval & 0x1f);
+ val->strval = manufacture_date;
+ break;
+
case POWER_SUPPLY_PROP_MODEL_NAME:
ret = sbs_get_property_index(client, psp);
if (ret < 0)
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture
2020-06-09 19:22 [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Tim Wawrzynczak
2020-06-09 19:22 ` [PATCH 2/2] power: supply: sbs_battery: Support Manufacture Date field Tim Wawrzynczak
@ 2020-06-09 23:29 ` Sebastian Reichel
1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2020-06-09 23:29 UTC (permalink / raw)
To: Tim Wawrzynczak; +Cc: linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2455 bytes --]
Hi,
Support for SBS battery manufacturer date is part of power-supply's
pull request for v5.8 with a different API allowing other batteries
to expose less precise information:
https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git/commit/?h=for-next&id=feabe49e46bb556b8d43e28d4a0d459940f7a5cb
https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git/commit/?h=for-next&id=7721c2fd2668c751f9ba33b35db08b86293869e5
-- Sebastian
On Tue, Jun 09, 2020 at 01:22:36PM -0600, Tim Wawrzynczak wrote:
> The Smart Battery Specification v1.1 defines Manufacture Date as one of
> its availabe registers. This patch adds this as a property so that
> power_supply drivers can support the property and report it in syfs.
>
> Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
> Change-Id: I90bf8c67b0cd531f2155404424a98302a1c931d6
> ---
> drivers/power/supply/power_supply_sysfs.c | 3 ++-
> include/linux/power_supply.h | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> index f37ad4eae60b9..ac6d9992a8675 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -171,7 +171,7 @@ static ssize_t power_supply_show_property(struct device *dev,
> ret = sprintf(buf, "%s\n",
> power_supply_scope_text[value.intval]);
> break;
> - case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
> + case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_MANUFACTURE_DATE:
> ret = sprintf(buf, "%s\n", value.strval);
> break;
> default:
> @@ -310,6 +310,7 @@ static struct device_attribute power_supply_attrs[] = {
> POWER_SUPPLY_ATTR(model_name),
> POWER_SUPPLY_ATTR(manufacturer),
> POWER_SUPPLY_ATTR(serial_number),
> + POWER_SUPPLY_ATTR(manufacture_date),
> };
>
> static struct attribute *
> diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
> index 28413f737e7d0..67839bb0a46b6 100644
> --- a/include/linux/power_supply.h
> +++ b/include/linux/power_supply.h
> @@ -162,6 +162,7 @@ enum power_supply_property {
> POWER_SUPPLY_PROP_MODEL_NAME,
> POWER_SUPPLY_PROP_MANUFACTURER,
> POWER_SUPPLY_PROP_SERIAL_NUMBER,
> + POWER_SUPPLY_PROP_MANUFACTURE_DATE,
> };
>
> enum power_supply_type {
> --
> 2.26.2
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-09 23:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-09 19:22 [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Tim Wawrzynczak
2020-06-09 19:22 ` [PATCH 2/2] power: supply: sbs_battery: Support Manufacture Date field Tim Wawrzynczak
2020-06-09 23:29 ` [PATCH 1/2] power: supply: Add new power supply prop for date of manufacture Sebastian Reichel
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).