aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-05-05 17:12:49 -0400
committerJiri Kosina <jkosina@suse.cz>2013-06-03 05:07:00 -0400
commit6b80bb94dc61a7f702df13c6c7e8edee331d0a9a (patch)
treedd1802ca633f492420d9b8cfc2b161b35079208b
parentc57ff761be8365599ff9ccdbb205ead4912b2067 (diff)
HID: wiimote: use cached battery values on I/O failure
Battery reports are sent along every status report of the Wii Remote. So chances are pretty high that we have an up-to-date battery cache at any time. Therefore, initialize the battery-cache to 100% and then return battery values from the cache if the query fails. This works around a power_supply limitation in that it requires us to be able to query the device during power_supply registration and removal. Otherwise, "add" or "remove" udev events are not sent. If we answer these requests from our cache instead, we avoid dropping these events and no longer cause warnings printed. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-wiimote-core.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c
index 76d2c73eb696..00a9b6fa5189 100644
--- a/drivers/hid/hid-wiimote-core.c
+++ b/drivers/hid/hid-wiimote-core.c
@@ -461,12 +461,12 @@ static int wiimote_battery_get_property(struct power_supply *psy,
461 wiiproto_req_status(wdata); 461 wiiproto_req_status(wdata);
462 spin_unlock_irqrestore(&wdata->state.lock, flags); 462 spin_unlock_irqrestore(&wdata->state.lock, flags);
463 463
464 ret = wiimote_cmd_wait(wdata); 464 wiimote_cmd_wait(wdata);
465 state = wdata->state.cmd_battery;
466 wiimote_cmd_release(wdata); 465 wiimote_cmd_release(wdata);
467 466
468 if (ret) 467 spin_lock_irqsave(&wdata->state.lock, flags);
469 return ret; 468 state = wdata->state.cmd_battery;
469 spin_unlock_irqrestore(&wdata->state.lock, flags);
470 470
471 switch (psp) { 471 switch (psp) {
472 case POWER_SUPPLY_PROP_CAPACITY: 472 case POWER_SUPPLY_PROP_CAPACITY:
@@ -923,10 +923,9 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload)
923 wiiext_event(wdata, false); 923 wiiext_event(wdata, false);
924 } 924 }
925 925
926 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { 926 wdata->state.cmd_battery = payload[5];
927 wdata->state.cmd_battery = payload[5]; 927 if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0))
928 wiimote_cmd_complete(wdata); 928 wiimote_cmd_complete(wdata);
929 }
930} 929}
931 930
932/* reduced generic report with "BB BB" key data only */ 931/* reduced generic report with "BB BB" key data only */
@@ -1279,6 +1278,7 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
1279 init_completion(&wdata->state.ready); 1278 init_completion(&wdata->state.ready);
1280 mutex_init(&wdata->state.sync); 1279 mutex_init(&wdata->state.sync);
1281 wdata->state.drm = WIIPROTO_REQ_DRM_K; 1280 wdata->state.drm = WIIPROTO_REQ_DRM_K;
1281 wdata->state.cmd_battery = 0xff;
1282 1282
1283 INIT_WORK(&wdata->init_worker, wiimote_init_worker); 1283 INIT_WORK(&wdata->init_worker, wiimote_init_worker);
1284 1284