aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorPrzemo Firszt <przemo@firszt.eu>2012-03-22 14:54:07 -0400
committerJiri Kosina <jkosina@suse.cz>2012-03-28 04:23:35 -0400
commite31e3832927f5ee2d788120826e73d120dd39ea9 (patch)
treec45f2efe19cb4d148661ea2a1894454001b70251 /drivers/hid
parent7e551abbc85703355dcc041434b4962697cdf628 (diff)
HID: wacom: Refactor battery/ac reporting for Graphire
This patch doesn't change the way battery/ac is reported, but the changes are required to facilitate battery reporting for Intuos4 WL. wdata->battery_capacity now stores actual battery capacity as opposed to raw value reported by wacom graphire previously. Power supply state is now stored in a separate variable - it used to be calculated on-the-fly in wacom_ac_get_property function. The raw value has to be stored as well to be able to determine if it has changed. Signed-off-by: Przemo Firszt <przemo@firszt.eu> Reviewed-by: Chris Bagwell <chris@cnpbagwell.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-wacom.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 46de2acada46..edf6cba6037a 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -39,13 +39,16 @@ struct wacom_data {
39 __u32 id; 39 __u32 id;
40 __u32 serial; 40 __u32 serial;
41 unsigned char high_speed; 41 unsigned char high_speed;
42 int battery_capacity; 42 __u8 battery_capacity;
43 __u8 power_raw;
44 __u8 ps_connected;
43 struct power_supply battery; 45 struct power_supply battery;
44 struct power_supply ac; 46 struct power_supply ac;
45}; 47};
46 48
47/*percent of battery capacity, 0 means AC online*/ 49/*percent of battery capacity for Graphire
48static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; 50 8th value means AC online and show 100% capacity */
51static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
49 52
50static enum power_supply_property wacom_battery_props[] = { 53static enum power_supply_property wacom_battery_props[] = {
51 POWER_SUPPLY_PROP_PRESENT, 54 POWER_SUPPLY_PROP_PRESENT,
@@ -65,7 +68,6 @@ static int wacom_battery_get_property(struct power_supply *psy,
65{ 68{
66 struct wacom_data *wdata = container_of(psy, 69 struct wacom_data *wdata = container_of(psy,
67 struct wacom_data, battery); 70 struct wacom_data, battery);
68 int power_state = batcap[wdata->battery_capacity];
69 int ret = 0; 71 int ret = 0;
70 72
71 switch (psp) { 73 switch (psp) {
@@ -76,11 +78,7 @@ static int wacom_battery_get_property(struct power_supply *psy,
76 val->intval = POWER_SUPPLY_SCOPE_DEVICE; 78 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
77 break; 79 break;
78 case POWER_SUPPLY_PROP_CAPACITY: 80 case POWER_SUPPLY_PROP_CAPACITY:
79 /* show 100% battery capacity when charging */ 81 val->intval = wdata->battery_capacity;
80 if (power_state == 0)
81 val->intval = 100;
82 else
83 val->intval = power_state;
84 break; 82 break;
85 default: 83 default:
86 ret = -EINVAL; 84 ret = -EINVAL;
@@ -94,17 +92,13 @@ static int wacom_ac_get_property(struct power_supply *psy,
94 union power_supply_propval *val) 92 union power_supply_propval *val)
95{ 93{
96 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); 94 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
97 int power_state = batcap[wdata->battery_capacity];
98 int ret = 0; 95 int ret = 0;
99 96
100 switch (psp) { 97 switch (psp) {
101 case POWER_SUPPLY_PROP_PRESENT: 98 case POWER_SUPPLY_PROP_PRESENT:
102 /* fall through */ 99 /* fall through */
103 case POWER_SUPPLY_PROP_ONLINE: 100 case POWER_SUPPLY_PROP_ONLINE:
104 if (power_state == 0) 101 val->intval = wdata->ps_connected;
105 val->intval = 1;
106 else
107 val->intval = 0;
108 break; 102 break;
109 case POWER_SUPPLY_PROP_SCOPE: 103 case POWER_SUPPLY_PROP_SCOPE:
110 val->intval = POWER_SUPPLY_SCOPE_DEVICE; 104 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
@@ -304,10 +298,16 @@ static int wacom_gr_parse_report(struct hid_device *hdev,
304 input_sync(input); 298 input_sync(input);
305 } 299 }
306 300
307 /* Store current battery capacity */ 301 /* Store current battery capacity and power supply state*/
308 rw = (data[7] >> 2 & 0x07); 302 rw = (data[7] >> 2 & 0x07);
309 if (rw != wdata->battery_capacity) 303 if (rw != wdata->power_raw) {
310 wdata->battery_capacity = rw; 304 wdata->power_raw = rw;
305 wdata->battery_capacity = batcap_gr[rw];
306 if (rw == 7)
307 wdata->ps_connected = 1;
308 else
309 wdata->ps_connected = 0;
310 }
311 return 1; 311 return 1;
312} 312}
313 313