Commit 2724be03 authored by Rui Miguel Silva's avatar Rui Miguel Silva Committed by Greg Kroah-Hartman

greybus: battery: move implementation to power_supply

Rename protocol to POWER_SUPPLY and implementation details from battery
to power_supply.

Also fix some tabs between define and macro name.
Signed-off-by: default avatarRui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 46488841
...@@ -30,7 +30,7 @@ enum greybus_protocol { ...@@ -30,7 +30,7 @@ enum greybus_protocol {
GREYBUS_PROTOCOL_HID = 0x05, GREYBUS_PROTOCOL_HID = 0x05,
GREYBUS_PROTOCOL_USB = 0x06, GREYBUS_PROTOCOL_USB = 0x06,
GREYBUS_PROTOCOL_SDIO = 0x07, GREYBUS_PROTOCOL_SDIO = 0x07,
GREYBUS_PROTOCOL_BATTERY = 0x08, GREYBUS_PROTOCOL_POWER_SUPPLY = 0x08,
GREYBUS_PROTOCOL_PWM = 0x09, GREYBUS_PROTOCOL_PWM = 0x09,
/* 0x0a is unused */ /* 0x0a is unused */
GREYBUS_PROTOCOL_SPI = 0x0b, GREYBUS_PROTOCOL_SPI = 0x0b,
...@@ -58,7 +58,7 @@ enum greybus_class_type { ...@@ -58,7 +58,7 @@ enum greybus_class_type {
GREYBUS_CLASS_HID = 0x05, GREYBUS_CLASS_HID = 0x05,
GREYBUS_CLASS_USB = 0x06, GREYBUS_CLASS_USB = 0x06,
GREYBUS_CLASS_SDIO = 0x07, GREYBUS_CLASS_SDIO = 0x07,
GREYBUS_CLASS_BATTERY = 0x08, GREYBUS_CLASS_POWER_SUPPLY = 0x08,
GREYBUS_CLASS_PWM = 0x09, GREYBUS_CLASS_PWM = 0x09,
/* 0x0a is unused */ /* 0x0a is unused */
GREYBUS_CLASS_SPI = 0x0b, GREYBUS_CLASS_SPI = 0x0b,
......
...@@ -198,60 +198,60 @@ struct gb_firmware_ready_to_boot_request { ...@@ -198,60 +198,60 @@ struct gb_firmware_ready_to_boot_request {
/* Firmware protocol Ready to boot response has no payload */ /* Firmware protocol Ready to boot response has no payload */
/* BATTERY */ /* Power Supply */
/* Version of the Greybus battery protocol we support */ /* Version of the Greybus power supply protocol we support */
#define GB_BATTERY_VERSION_MAJOR 0x00 #define GB_POWER_SUPPLY_VERSION_MAJOR 0x00
#define GB_BATTERY_VERSION_MINOR 0x01 #define GB_POWER_SUPPLY_VERSION_MINOR 0x01
/* Greybus battery request types */ /* Greybus power supply request types */
#define GB_BATTERY_TYPE_TECHNOLOGY 0x02 #define GB_POWER_SUPPLY_TYPE_TECHNOLOGY 0x02
#define GB_BATTERY_TYPE_STATUS 0x03 #define GB_POWER_SUPPLY_TYPE_STATUS 0x03
#define GB_BATTERY_TYPE_MAX_VOLTAGE 0x04 #define GB_POWER_SUPPLY_TYPE_MAX_VOLTAGE 0x04
#define GB_BATTERY_TYPE_PERCENT_CAPACITY 0x05 #define GB_POWER_SUPPLY_TYPE_PERCENT_CAPACITY 0x05
#define GB_BATTERY_TYPE_TEMPERATURE 0x06 #define GB_POWER_SUPPLY_TYPE_TEMPERATURE 0x06
#define GB_BATTERY_TYPE_VOLTAGE 0x07 #define GB_POWER_SUPPLY_TYPE_VOLTAGE 0x07
#define GB_BATTERY_TYPE_CURRENT 0x08 #define GB_POWER_SUPPLY_TYPE_CURRENT 0x08
#define GB_BATTERY_TYPE_CAPACITY 0x09 // TODO - POWER_SUPPLY_PROP_CURRENT_MAX #define GB_POWER_SUPPLY_TYPE_CAPACITY 0x09 // TODO - POWER_SUPPLY_PROP_CURRENT_MAX
#define GB_BATTERY_TYPE_SHUTDOWN_TEMP 0x0a // TODO - POWER_SUPPLY_PROP_TEMP_ALERT_MAX #define GB_POWER_SUPPLY_TYPE_SHUTDOWN_TEMP 0x0a // TODO - POWER_SUPPLY_PROP_TEMP_ALERT_MAX
/* Should match up with battery types in linux/power_supply.h */ /* Should match up with battery technology types in linux/power_supply.h */
#define GB_BATTERY_TECH_UNKNOWN 0x0000 #define GB_POWER_SUPPLY_TECH_UNKNOWN 0x0000
#define GB_BATTERY_TECH_NiMH 0x0001 #define GB_POWER_SUPPLY_TECH_NiMH 0x0001
#define GB_BATTERY_TECH_LION 0x0002 #define GB_POWER_SUPPLY_TECH_LION 0x0002
#define GB_BATTERY_TECH_LIPO 0x0003 #define GB_POWER_SUPPLY_TECH_LIPO 0x0003
#define GB_BATTERY_TECH_LiFe 0x0004 #define GB_POWER_SUPPLY_TECH_LiFe 0x0004
#define GB_BATTERY_TECH_NiCd 0x0005 #define GB_POWER_SUPPLY_TECH_NiCd 0x0005
#define GB_BATTERY_TECH_LiMn 0x0006 #define GB_POWER_SUPPLY_TECH_LiMn 0x0006
struct gb_battery_technology_response { struct gb_power_supply_technology_response {
__le32 technology; __le32 technology;
} __packed; } __packed;
/* Should match up with battery status in linux/power_supply.h */ /* Should match up with power supply status in linux/power_supply.h */
#define GB_BATTERY_STATUS_UNKNOWN 0x0000 #define GB_POWER_SUPPLY_STATUS_UNKNOWN 0x0000
#define GB_BATTERY_STATUS_CHARGING 0x0001 #define GB_POWER_SUPPLY_STATUS_CHARGING 0x0001
#define GB_BATTERY_STATUS_DISCHARGING 0x0002 #define GB_POWER_SUPPLY_STATUS_DISCHARGING 0x0002
#define GB_BATTERY_STATUS_NOT_CHARGING 0x0003 #define GB_POWER_SUPPLY_STATUS_NOT_CHARGING 0x0003
#define GB_BATTERY_STATUS_FULL 0x0004 #define GB_POWER_SUPPLY_STATUS_FULL 0x0004
struct gb_battery_status_response { struct gb_power_supply_status_response {
__le16 battery_status; __le16 psy_status;
} __packed; } __packed;
struct gb_battery_max_voltage_response { struct gb_power_supply_max_voltage_response {
__le32 max_voltage; __le32 max_voltage;
} __packed; } __packed;
struct gb_battery_capacity_response { struct gb_power_supply_capacity_response {
__le32 capacity; __le32 capacity;
} __packed; } __packed;
struct gb_battery_temperature_response { struct gb_power_supply_temperature_response {
__le32 temperature; __le32 temperature;
} __packed; } __packed;
struct gb_battery_voltage_response { struct gb_power_supply_voltage_response {
__le32 voltage; __le32 voltage;
} __packed; } __packed;
......
/* /*
* Battery driver for a Greybus module. * Power Supply driver for a Greybus module.
* *
* Copyright 2014 Google Inc. * Copyright 2014 Google Inc.
* Copyright 2014 Linaro Ltd. * Copyright 2014 Linaro Ltd.
...@@ -13,35 +13,36 @@ ...@@ -13,35 +13,36 @@
#include <linux/power_supply.h> #include <linux/power_supply.h>
#include "greybus.h" #include "greybus.h"
struct gb_battery { struct gb_power_supply {
/* /*
* The power supply api changed in 4.1, so handle both the old * The power supply api changed in 4.1, so handle both the old
* and new apis in the same driver for now, until this is merged * and new apis in the same driver for now, until this is merged
* upstream, when all of these version checks can be removed. * upstream, when all of these version checks can be removed.
*/ */
#ifdef DRIVER_OWNS_PSY_STRUCT #ifdef DRIVER_OWNS_PSY_STRUCT
struct power_supply bat; struct power_supply psy;
#define to_gb_battery(x) container_of(x, struct gb_battery, bat) #define to_gb_power_supply(x) container_of(x, struct gb_power_supply, psy)
#else #else
struct power_supply *bat; struct power_supply *psy;
struct power_supply_desc desc; struct power_supply_desc desc;
#define to_gb_battery(x) power_supply_get_drvdata(x) #define to_gb_power_supply(x) power_supply_get_drvdata(x)
#endif #endif
// FIXME // FIXME
// we will want to keep the battery stats in here as we will be getting // we will want to keep the power supply stats in here as we will be
// updates from the SVC "on the fly" so we don't have to always go ask // getting updates from the SVC "on the fly" so we don't have to always
// the battery for some information. Hopefully... // go ask the power supply for some information. Hopefully...
struct gb_connection *connection; struct gb_connection *connection;
}; };
static int get_tech(struct gb_battery *gb) static int get_tech(struct gb_power_supply *gb)
{ {
struct gb_battery_technology_response tech_response; struct gb_power_supply_technology_response tech_response;
u32 technology; u32 technology;
int retval; int retval;
retval = gb_operation_sync(gb->connection, GB_BATTERY_TYPE_TECHNOLOGY, retval = gb_operation_sync(gb->connection,
GB_POWER_SUPPLY_TYPE_TECHNOLOGY,
NULL, 0, NULL, 0,
&tech_response, sizeof(tech_response)); &tech_response, sizeof(tech_response));
if (retval) if (retval)
...@@ -54,25 +55,25 @@ static int get_tech(struct gb_battery *gb) ...@@ -54,25 +55,25 @@ static int get_tech(struct gb_battery *gb)
*/ */
technology = le32_to_cpu(tech_response.technology); technology = le32_to_cpu(tech_response.technology);
switch (technology) { switch (technology) {
case GB_BATTERY_TECH_NiMH: case GB_POWER_SUPPLY_TECH_NiMH:
technology = POWER_SUPPLY_TECHNOLOGY_NiMH; technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
break; break;
case GB_BATTERY_TECH_LION: case GB_POWER_SUPPLY_TECH_LION:
technology = POWER_SUPPLY_TECHNOLOGY_LION; technology = POWER_SUPPLY_TECHNOLOGY_LION;
break; break;
case GB_BATTERY_TECH_LIPO: case GB_POWER_SUPPLY_TECH_LIPO:
technology = POWER_SUPPLY_TECHNOLOGY_LIPO; technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
break; break;
case GB_BATTERY_TECH_LiFe: case GB_POWER_SUPPLY_TECH_LiFe:
technology = POWER_SUPPLY_TECHNOLOGY_LiFe; technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
break; break;
case GB_BATTERY_TECH_NiCd: case GB_POWER_SUPPLY_TECH_NiCd:
technology = POWER_SUPPLY_TECHNOLOGY_NiCd; technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
break; break;
case GB_BATTERY_TECH_LiMn: case GB_POWER_SUPPLY_TECH_LiMn:
technology = POWER_SUPPLY_TECHNOLOGY_LiMn; technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
break; break;
case GB_BATTERY_TECH_UNKNOWN: case GB_POWER_SUPPLY_TECH_UNKNOWN:
default: default:
technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
break; break;
...@@ -80,13 +81,13 @@ static int get_tech(struct gb_battery *gb) ...@@ -80,13 +81,13 @@ static int get_tech(struct gb_battery *gb)
return technology; return technology;
} }
static int get_status(struct gb_battery *gb) static int get_status(struct gb_power_supply *gb)
{ {
struct gb_battery_status_response status_response; struct gb_power_supply_status_response status_response;
u16 battery_status; u16 psy_status;
int retval; int retval;
retval = gb_operation_sync(gb->connection, GB_BATTERY_TYPE_STATUS, retval = gb_operation_sync(gb->connection, GB_POWER_SUPPLY_TYPE_STATUS,
NULL, 0, NULL, 0,
&status_response, sizeof(status_response)); &status_response, sizeof(status_response));
if (retval) if (retval)
...@@ -97,35 +98,36 @@ static int get_status(struct gb_battery *gb) ...@@ -97,35 +98,36 @@ static int get_status(struct gb_battery *gb)
* "identical" which should allow gcc to optimize the code away to * "identical" which should allow gcc to optimize the code away to
* nothing. * nothing.
*/ */
battery_status = le16_to_cpu(status_response.battery_status); psy_status = le16_to_cpu(status_response.psy_status);
switch (battery_status) { switch (psy_status) {
case GB_BATTERY_STATUS_CHARGING: case GB_POWER_SUPPLY_STATUS_CHARGING:
battery_status = POWER_SUPPLY_STATUS_CHARGING; psy_status = POWER_SUPPLY_STATUS_CHARGING;
break; break;
case GB_BATTERY_STATUS_DISCHARGING: case GB_POWER_SUPPLY_STATUS_DISCHARGING:
battery_status = POWER_SUPPLY_STATUS_DISCHARGING; psy_status = POWER_SUPPLY_STATUS_DISCHARGING;
break; break;
case GB_BATTERY_STATUS_NOT_CHARGING: case GB_POWER_SUPPLY_STATUS_NOT_CHARGING:
battery_status = POWER_SUPPLY_STATUS_NOT_CHARGING; psy_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
break; break;
case GB_BATTERY_STATUS_FULL: case GB_POWER_SUPPLY_STATUS_FULL:
battery_status = POWER_SUPPLY_STATUS_FULL; psy_status = POWER_SUPPLY_STATUS_FULL;
break; break;
case GB_BATTERY_STATUS_UNKNOWN: case GB_POWER_SUPPLY_STATUS_UNKNOWN:
default: default:
battery_status = POWER_SUPPLY_STATUS_UNKNOWN; psy_status = POWER_SUPPLY_STATUS_UNKNOWN;
break; break;
} }
return battery_status; return psy_status;
} }
static int get_max_voltage(struct gb_battery *gb) static int get_max_voltage(struct gb_power_supply *gb)
{ {
struct gb_battery_max_voltage_response volt_response; struct gb_power_supply_max_voltage_response volt_response;
u32 max_voltage; u32 max_voltage;
int retval; int retval;
retval = gb_operation_sync(gb->connection, GB_BATTERY_TYPE_MAX_VOLTAGE, retval = gb_operation_sync(gb->connection,
GB_POWER_SUPPLY_TYPE_MAX_VOLTAGE,
NULL, 0, NULL, 0,
&volt_response, sizeof(volt_response)); &volt_response, sizeof(volt_response));
if (retval) if (retval)
...@@ -135,14 +137,14 @@ static int get_max_voltage(struct gb_battery *gb) ...@@ -135,14 +137,14 @@ static int get_max_voltage(struct gb_battery *gb)
return max_voltage; return max_voltage;
} }
static int get_percent_capacity(struct gb_battery *gb) static int get_percent_capacity(struct gb_power_supply *gb)
{ {
struct gb_battery_capacity_response capacity_response; struct gb_power_supply_capacity_response capacity_response;
u32 capacity; u32 capacity;
int retval; int retval;
retval = gb_operation_sync(gb->connection, retval = gb_operation_sync(gb->connection,
GB_BATTERY_TYPE_PERCENT_CAPACITY, GB_POWER_SUPPLY_TYPE_PERCENT_CAPACITY,
NULL, 0, &capacity_response, NULL, 0, &capacity_response,
sizeof(capacity_response)); sizeof(capacity_response));
if (retval) if (retval)
...@@ -152,13 +154,14 @@ static int get_percent_capacity(struct gb_battery *gb) ...@@ -152,13 +154,14 @@ static int get_percent_capacity(struct gb_battery *gb)
return capacity; return capacity;
} }
static int get_temp(struct gb_battery *gb) static int get_temp(struct gb_power_supply *gb)
{ {
struct gb_battery_temperature_response temp_response; struct gb_power_supply_temperature_response temp_response;
u32 temperature; u32 temperature;
int retval; int retval;
retval = gb_operation_sync(gb->connection, GB_BATTERY_TYPE_TEMPERATURE, retval = gb_operation_sync(gb->connection,
GB_POWER_SUPPLY_TYPE_TEMPERATURE,
NULL, 0, NULL, 0,
&temp_response, sizeof(temp_response)); &temp_response, sizeof(temp_response));
if (retval) if (retval)
...@@ -168,13 +171,13 @@ static int get_temp(struct gb_battery *gb) ...@@ -168,13 +171,13 @@ static int get_temp(struct gb_battery *gb)
return temperature; return temperature;
} }
static int get_voltage(struct gb_battery *gb) static int get_voltage(struct gb_power_supply *gb)
{ {
struct gb_battery_voltage_response voltage_response; struct gb_power_supply_voltage_response voltage_response;
u32 voltage; u32 voltage;
int retval; int retval;
retval = gb_operation_sync(gb->connection, GB_BATTERY_TYPE_VOLTAGE, retval = gb_operation_sync(gb->connection, GB_POWER_SUPPLY_TYPE_VOLTAGE,
NULL, 0, NULL, 0,
&voltage_response, sizeof(voltage_response)); &voltage_response, sizeof(voltage_response));
if (retval) if (retval)
...@@ -188,7 +191,7 @@ static int get_property(struct power_supply *b, ...@@ -188,7 +191,7 @@ static int get_property(struct power_supply *b,
enum power_supply_property psp, enum power_supply_property psp,
union power_supply_propval *val) union power_supply_propval *val)
{ {
struct gb_battery *gb = to_gb_battery(b); struct gb_power_supply *gb = to_gb_power_supply(b);
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_TECHNOLOGY: case POWER_SUPPLY_PROP_TECHNOLOGY:
...@@ -223,7 +226,7 @@ static int get_property(struct power_supply *b, ...@@ -223,7 +226,7 @@ static int get_property(struct power_supply *b,
} }
// FIXME - verify this list, odds are some can be removed and others added. // FIXME - verify this list, odds are some can be removed and others added.
static enum power_supply_property battery_props[] = { static enum power_supply_property psy_props[] = {
POWER_SUPPLY_PROP_TECHNOLOGY, POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
...@@ -238,17 +241,17 @@ static int init_and_register(struct gb_connection *connection, ...@@ -238,17 +241,17 @@ static int init_and_register(struct gb_connection *connection,
{ {
// FIXME - get a better (i.e. unique) name // FIXME - get a better (i.e. unique) name
// FIXME - anything else needs to be set? // FIXME - anything else needs to be set?
gb->bat.name = "gb_battery"; gb->psy.name = "gb_battery";
gb->bat.type = POWER_SUPPLY_TYPE_BATTERY; gb->psy.type = POWER_SUPPLY_TYPE_BATTERY;
gb->bat.properties = battery_props; gb->psy.properties = psy_props;
gb->bat.num_properties = ARRAY_SIZE(battery_props); gb->psy.num_properties = ARRAY_SIZE(psy_props);
gb->bat.get_property = get_property; gb->psy.get_property = get_property;
return power_supply_register(&connection->bundle->dev, &gb->bat); return power_supply_register(&connection->bundle->dev, &gb->psy);
} }
#else #else
static int init_and_register(struct gb_connection *connection, static int init_and_register(struct gb_connection *connection,
struct gb_battery *gb) struct gb_power_supply *gb)
{ {
struct power_supply_config cfg = {}; struct power_supply_config cfg = {};
...@@ -258,22 +261,22 @@ static int init_and_register(struct gb_connection *connection, ...@@ -258,22 +261,22 @@ static int init_and_register(struct gb_connection *connection,
// FIXME - anything else needs to be set? // FIXME - anything else needs to be set?
gb->desc.name = "gb_battery"; gb->desc.name = "gb_battery";
gb->desc.type = POWER_SUPPLY_TYPE_BATTERY; gb->desc.type = POWER_SUPPLY_TYPE_BATTERY;
gb->desc.properties = battery_props; gb->desc.properties = psy_props;
gb->desc.num_properties = ARRAY_SIZE(battery_props); gb->desc.num_properties = ARRAY_SIZE(psy_props);
gb->desc.get_property = get_property; gb->desc.get_property = get_property;
gb->bat = power_supply_register(&connection->bundle->dev, gb->psy = power_supply_register(&connection->bundle->dev,
&gb->desc, &cfg); &gb->desc, &cfg);
if (IS_ERR(gb->bat)) if (IS_ERR(gb->psy))
return PTR_ERR(gb->bat); return PTR_ERR(gb->psy);
return 0; return 0;
} }
#endif #endif
static int gb_battery_connection_init(struct gb_connection *connection) static int gb_power_supply_connection_init(struct gb_connection *connection)
{ {
struct gb_battery *gb; struct gb_power_supply *gb;
int retval; int retval;
gb = kzalloc(sizeof(*gb), GFP_KERNEL); gb = kzalloc(sizeof(*gb), GFP_KERNEL);
...@@ -290,28 +293,28 @@ static int gb_battery_connection_init(struct gb_connection *connection) ...@@ -290,28 +293,28 @@ static int gb_battery_connection_init(struct gb_connection *connection)
return retval; return retval;
} }
static void gb_battery_connection_exit(struct gb_connection *connection) static void gb_power_supply_connection_exit(struct gb_connection *connection)
{ {
struct gb_battery *gb = connection->private; struct gb_power_supply *gb = connection->private;
#ifdef DRIVER_OWNS_PSY_STRUCT #ifdef DRIVER_OWNS_PSY_STRUCT
power_supply_unregister(&gb->bat); power_supply_unregister(&gb->psy);
#else #else
power_supply_unregister(gb->bat); power_supply_unregister(gb->psy);
#endif #endif
kfree(gb); kfree(gb);
} }
static struct gb_protocol battery_protocol = { static struct gb_protocol power_supply_protocol = {
.name = "battery", .name = "power_supply",
.id = GREYBUS_PROTOCOL_BATTERY, .id = GREYBUS_PROTOCOL_POWER_SUPPLY,
.major = GB_BATTERY_VERSION_MAJOR, .major = GB_POWER_SUPPLY_VERSION_MAJOR,
.minor = GB_BATTERY_VERSION_MINOR, .minor = GB_POWER_SUPPLY_VERSION_MINOR,
.connection_init = gb_battery_connection_init, .connection_init = gb_power_supply_connection_init,
.connection_exit = gb_battery_connection_exit, .connection_exit = gb_power_supply_connection_exit,
.request_recv = NULL, /* no incoming requests */ .request_recv = NULL, /* no incoming requests */
}; };
gb_protocol_driver(&battery_protocol); gb_protocol_driver(&power_supply_protocol);
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment