mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-18 17:54:13 +08:00
power: supply: sbs-battery: add MANUFACTURE_DATE support
Expose the battery's manufacture date to userspace. Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
787fdbcf5b
commit
7721c2fd26
@ -58,6 +58,8 @@ enum {
|
||||
#define SBS_VERSION_1_1 2
|
||||
#define SBS_VERSION_1_1_WITH_PEC 3
|
||||
|
||||
#define REG_ADDR_MANUFACTURE_DATE 0x1B
|
||||
|
||||
/* Battery Mode defines */
|
||||
#define BATTERY_MODE_OFFSET 0x03
|
||||
#define BATTERY_MODE_CAPACITY_MASK BIT(15)
|
||||
@ -171,6 +173,9 @@ static enum power_supply_property sbs_properties[] = {
|
||||
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
|
||||
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
|
||||
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
|
||||
POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
|
||||
POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
|
||||
POWER_SUPPLY_PROP_MANUFACTURE_DAY,
|
||||
/* Properties of type `const char *' */
|
||||
POWER_SUPPLY_PROP_MANUFACTURER,
|
||||
POWER_SUPPLY_PROP_MODEL_NAME
|
||||
@ -682,6 +687,38 @@ static int sbs_get_chemistry(struct i2c_client *client,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sbs_get_battery_manufacture_date(struct i2c_client *client,
|
||||
enum power_supply_property psp,
|
||||
union power_supply_propval *val)
|
||||
{
|
||||
int ret;
|
||||
u16 day, month, year;
|
||||
|
||||
ret = sbs_read_word_data(client, REG_ADDR_MANUFACTURE_DATE);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
day = ret & GENMASK(4, 0);
|
||||
month = (ret & GENMASK(8, 5)) >> 5;
|
||||
year = ((ret & GENMASK(15, 9)) >> 9) + 1980;
|
||||
|
||||
switch (psp) {
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
|
||||
val->intval = year;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_MONTH:
|
||||
val->intval = month;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_DAY:
|
||||
val->intval = day;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sbs_get_property(struct power_supply *psy,
|
||||
enum power_supply_property psp,
|
||||
union power_supply_propval *val)
|
||||
@ -790,6 +827,12 @@ static int sbs_get_property(struct power_supply *psy,
|
||||
val->strval = manufacturer;
|
||||
break;
|
||||
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_YEAR:
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_MONTH:
|
||||
case POWER_SUPPLY_PROP_MANUFACTURE_DAY:
|
||||
ret = sbs_get_battery_manufacture_date(client, psp, val);
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(&client->dev,
|
||||
"%s: INVALID property\n", __func__);
|
||||
|
Loading…
Reference in New Issue
Block a user