From patchwork Mon Aug 29 13:38:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 1108032 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 p7TDclf2003316 for ; Mon, 29 Aug 2011 13:38:47 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753759Ab1H2Niq (ORCPT ); Mon, 29 Aug 2011 09:38:46 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:57851 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753760Ab1H2Nip (ORCPT ); Mon, 29 Aug 2011 09:38:45 -0400 Received: by mail-fx0-f46.google.com with SMTP id 19so4422164fxh.19 for ; Mon, 29 Aug 2011 06:38:44 -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=YDPu6DGQqnSvCuMG6GblNfsWVWYk/Jy8ftAYC/KIgqiwalwSoIphxeHrNjdc/OfHfD j0vbWHkmKkF+mXOCWT0ih5Ng4h2eX9AENGgCr4/+0MwEDrVbWdx2qKPQ1841n5LgCaDS j0AjE+/Cmy/Uxg4uKJsCCUaL+hY935YRYIYC4= Received: by 10.223.4.133 with SMTP id 5mr7216610far.81.1314625124853; Mon, 29 Aug 2011 06:38:44 -0700 (PDT) Received: from localhost.localdomain (stgt-5f70ad61.pool.mediaWays.net [95.112.173.97]) by mx.google.com with ESMTPS id b14sm3767290fak.29.2011.08.29.06.38.43 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Aug 2011 06:38:44 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, oliver@neukum.org, David Herrmann Subject: [PATCH 10/14] HID: wiimote: Add write-register helpers Date: Mon, 29 Aug 2011 15:38:07 +0200 Message-Id: <1314625091-1405-11-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.6.1 In-Reply-To: <1314625091-1405-1-git-send-email-dh.herrmann@googlemail.com> References: <1314625091-1405-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]); Mon, 29 Aug 2011 13:38:47 +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)