Commit 6b80bb94 authored by David Herrmann's avatar David Herrmann Committed by Jiri Kosina

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: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent c57ff761
...@@ -461,12 +461,12 @@ static int wiimote_battery_get_property(struct power_supply *psy, ...@@ -461,12 +461,12 @@ static int wiimote_battery_get_property(struct power_supply *psy,
wiiproto_req_status(wdata); wiiproto_req_status(wdata);
spin_unlock_irqrestore(&wdata->state.lock, flags); spin_unlock_irqrestore(&wdata->state.lock, flags);
ret = wiimote_cmd_wait(wdata); wiimote_cmd_wait(wdata);
state = wdata->state.cmd_battery;
wiimote_cmd_release(wdata); wiimote_cmd_release(wdata);
if (ret) spin_lock_irqsave(&wdata->state.lock, flags);
return ret; state = wdata->state.cmd_battery;
spin_unlock_irqrestore(&wdata->state.lock, flags);
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_CAPACITY: case POWER_SUPPLY_PROP_CAPACITY:
...@@ -923,10 +923,9 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload) ...@@ -923,10 +923,9 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload)
wiiext_event(wdata, false); wiiext_event(wdata, false);
} }
if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0)) { wdata->state.cmd_battery = payload[5];
wdata->state.cmd_battery = payload[5]; if (wiimote_cmd_pending(wdata, WIIPROTO_REQ_SREQ, 0))
wiimote_cmd_complete(wdata); wiimote_cmd_complete(wdata);
}
} }
/* reduced generic report with "BB BB" key data only */ /* reduced generic report with "BB BB" key data only */
...@@ -1279,6 +1278,7 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) ...@@ -1279,6 +1278,7 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev)
init_completion(&wdata->state.ready); init_completion(&wdata->state.ready);
mutex_init(&wdata->state.sync); mutex_init(&wdata->state.sync);
wdata->state.drm = WIIPROTO_REQ_DRM_K; wdata->state.drm = WIIPROTO_REQ_DRM_K;
wdata->state.cmd_battery = 0xff;
INIT_WORK(&wdata->init_worker, wiimote_init_worker); INIT_WORK(&wdata->init_worker, wiimote_init_worker);
......
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