浏览代码

power_supply: Support serial number in olpc_battery

This adds serial number support to the OLPC battery driver.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andres Salomon <dilinger@debian.org>
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
David Woodhouse 17 年之前
父节点
当前提交
1ca5b9d218
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      drivers/power/olpc_battery.c

+ 12 - 0
drivers/power/olpc_battery.c

@@ -84,6 +84,8 @@ static struct power_supply olpc_ac = {
 	.get_property = olpc_ac_get_prop,
 	.get_property = olpc_ac_get_prop,
 };
 };
 
 
+static char bat_serial[17]; /* Ick */
+
 /*********************************************************************
 /*********************************************************************
  *		Battery properties
  *		Battery properties
  *********************************************************************/
  *********************************************************************/
@@ -94,6 +96,7 @@ static int olpc_bat_get_property(struct power_supply *psy,
 	int ret = 0;
 	int ret = 0;
 	int16_t ec_word;
 	int16_t ec_word;
 	uint8_t ec_byte;
 	uint8_t ec_byte;
+	uint64_t ser_buf;
 
 
 	ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &ec_byte, 1);
 	ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &ec_byte, 1);
 	if (ret)
 	if (ret)
@@ -241,6 +244,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
 		ec_word = be16_to_cpu(ec_word);
 		ec_word = be16_to_cpu(ec_word);
 		val->intval = ec_word * 100 / 256;
 		val->intval = ec_word * 100 / 256;
 		break;
 		break;
+	case POWER_SUPPLY_PROP_SERIAL_NUMBER:
+		ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
+		if (ret)
+			return ret;
+
+		sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
+		val->strval = bat_serial;
+		break;
 	default:
 	default:
 		ret = -EINVAL;
 		ret = -EINVAL;
 		break;
 		break;
@@ -260,6 +271,7 @@ static enum power_supply_property olpc_bat_props[] = {
 	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_TEMP,
 	POWER_SUPPLY_PROP_TEMP_AMBIENT,
 	POWER_SUPPLY_PROP_TEMP_AMBIENT,
 	POWER_SUPPLY_PROP_MANUFACTURER,
 	POWER_SUPPLY_PROP_MANUFACTURER,
+	POWER_SUPPLY_PROP_SERIAL_NUMBER,
 };
 };
 
 
 /*********************************************************************
 /*********************************************************************