From patchwork Sun May 5 21:12:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 2521381 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A08513FD4E for ; Sun, 5 May 2013 21:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752066Ab3EEVNw (ORCPT ); Sun, 5 May 2013 17:13:52 -0400 Received: from mail-bk0-f43.google.com ([209.85.214.43]:63484 "EHLO mail-bk0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752117Ab3EEVNu (ORCPT ); Sun, 5 May 2013 17:13:50 -0400 Received: by mail-bk0-f43.google.com with SMTP id jm19so1355419bkc.30 for ; Sun, 05 May 2013 14:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=hrK3fkSeyF1D7GVVBhH+HTtmkNygGHC/Jzrm6/j4CeY=; b=zq3auTgEiibL814Bw75FXXZ4iiusH9b5Sp+ml+oLJoKcI0GnhvMv6bCVG2zj7dhrjC qiuvqc4hKI9JWXs6EuakUvk5eXPORH+0xmzS8tXqp9b/RPoWmxIkkui2bKnuUZrGIj47 MtTFdCYp53ocTfdokG9H95DDOiFyOZyr8tLEXLrs7MumwEj7bdog6t6k+utRp6oW8MSV hqqd5Ag4FABJsUYABTkFT/fNyvWvErMvxx/hJ5OAvFRx3UY9XnZNRgmpIupUsBD5FWho vGplpMoq7xtJe/9YG+BsWFGzgxSG333ci23rvdBzUS9N3KKFWr8M7etcVCWoHgNM8lpS Nf9A== X-Received: by 10.205.42.194 with SMTP id tz2mr7371811bkb.129.1367788429270; Sun, 05 May 2013 14:13:49 -0700 (PDT) Received: from localhost.localdomain (stgt-5f71a35b.pool.mediaWays.net. [95.113.163.91]) by mx.google.com with ESMTPSA id cv9sm4667233bkb.5.2013.05.05.14.13.47 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 05 May 2013 14:13:48 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: Jiri Kosina , David Herrmann Subject: [PATCH 05/26] HID: wiimote: use cached battery values on I/O failure Date: Sun, 5 May 2013 23:12:49 +0200 Message-Id: <1367788390-29835-6-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1367788390-29835-1-git-send-email-dh.herrmann@gmail.com> References: <1367788390-29835-1-git-send-email-dh.herrmann@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 --- drivers/hid/hid-wiimote-core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-wiimote-core.c b/drivers/hid/hid-wiimote-core.c index 76d2c73..00a9b6f 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, wiiproto_req_status(wdata); spin_unlock_irqrestore(&wdata->state.lock, flags); - ret = wiimote_cmd_wait(wdata); - state = wdata->state.cmd_battery; + wiimote_cmd_wait(wdata); wiimote_cmd_release(wdata); - if (ret) - return ret; + spin_lock_irqsave(&wdata->state.lock, flags); + state = wdata->state.cmd_battery; + spin_unlock_irqrestore(&wdata->state.lock, flags); switch (psp) { case POWER_SUPPLY_PROP_CAPACITY: @@ -923,10 +923,9 @@ static void handler_status(struct wiimote_data *wdata, const __u8 *payload) 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); - } } /* reduced generic report with "BB BB" key data only */ @@ -1279,6 +1278,7 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) init_completion(&wdata->state.ready); mutex_init(&wdata->state.sync); wdata->state.drm = WIIPROTO_REQ_DRM_K; + wdata->state.cmd_battery = 0xff; INIT_WORK(&wdata->init_worker, wiimote_init_worker);