From patchwork Tue Sep 6 11:50:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 1126122 X-Patchwork-Delegate: jikos@jikos.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p86BpCg5020984 for ; Tue, 6 Sep 2011 11:51:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754287Ab1IFLvX (ORCPT ); Tue, 6 Sep 2011 07:51:23 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:44212 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754248Ab1IFLvX (ORCPT ); Tue, 6 Sep 2011 07:51:23 -0400 Received: by mail-fx0-f46.google.com with SMTP id 19so4508571fxh.19 for ; Tue, 06 Sep 2011 04:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=mXXfBVHKhCWHGni6CCOACsGIFAQuSpnPMf91TTvDjWE=; b=LyHJtSPRZm4OCKxrrfJyFOdxkzM7xkkYkgFBfP20RY6yQLfIPXqmQ1Z5rnwQKk8HmC CoR8sRh/uyfa+c96oWkVlz7nQ9od7QsjYD4IcXF7sd8R1pXyI++zmrWz/rvvcVrZuJ7X A3d9JQFLpkiiYneE7nY/10X8AvBuYXe24m8jA= Received: by 10.223.97.136 with SMTP id l8mr2700806fan.101.1315309882807; Tue, 06 Sep 2011 04:51:22 -0700 (PDT) Received: from localhost.localdomain (stgt-5f708ff4.pool.mediaWays.net [95.112.143.244]) by mx.google.com with ESMTPS id q23sm5071202fae.1.2011.09.06.04.51.21 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Sep 2011 04:51:22 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, David Herrmann Subject: [PATCH v2 10/15] HID: wiimote: Add write-register helpers Date: Tue, 6 Sep 2011 13:50:35 +0200 Message-Id: <1315309840-4664-11-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1315309840-4664-1-git-send-email-dh.herrmann@googlemail.com> References: <1315309840-4664-1-git-send-email-dh.herrmann@googlemail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 06 Sep 2011 11:51:24 +0000 (UTC) Add helpers to synchronously write registers of the wiimote. This is heavily used by initialization functions for wiimote peripherals. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index 0a5e458..59a0893 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -39,6 +39,9 @@ struct wiimote_state { struct completion ready; int cmd; __u32 opt; + + /* results of synchronous requests */ + __u8 cmd_err; }; struct wiimote_data { @@ -394,6 +397,25 @@ static void wiiproto_req_wmem(struct wiimote_data *wdata, bool eeprom, wiimote_queue(wdata, cmd, sizeof(cmd)); } +/* requries the cmd-mutex to be held */ +static int wiimote_cmd_write(struct wiimote_data *wdata, __u32 offset, + const __u8 *wmem, __u8 size) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&wdata->state.lock, flags); + wiimote_cmd_set(wdata, WIIPROTO_REQ_WMEM, 0); + wiiproto_req_wreg(wdata, offset, wmem, size); + spin_unlock_irqrestore(&wdata->state.lock, flags); + + ret = wiimote_cmd_wait(wdata); + if (!ret && wdata->state.cmd_err) + ret = -EIO; + + return ret; +} + static enum led_brightness wiimote_leds_get(struct led_classdev *led_dev) { struct wiimote_data *wdata; @@ -635,9 +657,13 @@ static void handler_return(struct wiimote_data *wdata, const __u8 *payload) handler_keys(wdata, payload); - if (err) + if (wiimote_cmd_pending(wdata, cmd, 0)) { + wdata->state.cmd_err = err; + wiimote_cmd_complete(wdata); + } else if (err) { hid_warn(wdata->hdev, "Remote error %hhu on req %hhu\n", err, cmd); + } } static void handler_drm_KA(struct wiimote_data *wdata, const __u8 *payload)