From patchwork Fri Jun 17 14:49:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 891812 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 p5HEsZCm010597 for ; Fri, 17 Jun 2011 14:54:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759217Ab1FQOyf (ORCPT ); Fri, 17 Jun 2011 10:54:35 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:32907 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759229Ab1FQOuT (ORCPT ); Fri, 17 Jun 2011 10:50:19 -0400 Received: by fxm17 with SMTP id 17so1796125fxm.19 for ; Fri, 17 Jun 2011 07:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=oFKnUQjaCbBBPS5i807Bhhm8fuyuvrYSlAmiXLAHOxE=; b=L2Xv4sIZp6+BgKaAmz6c1z5OH63DKzCxCX9ko36ppznl/wALK693onRssqw6Nc1T8t tNE97YfUR69l0MOzhaUbIbnJSdJQB0aQ3tJTB9jZ5LozXb2xq5pqvaLQDAoroiGU074X K7cD1UusaYpv6qQSLEoGPJ8lL8L8aUxUmf/W0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=kurN7EmkIbAAt54auvCRtuxSWWhVmR+exO/C9xLaghUJBZS45x4TblGjAz5ZwkCWQU mlwZiPLN7YcQV/iMHGlvwylaHoC3TLfZfLCe85re5CSa6b/Cf9Z1p1Whj1QVX+Z90u2x WBRG6ntgv5n2107VkaLm0+zK0Gt2HRpdFAqUA= Received: by 10.223.57.5 with SMTP id a5mr2630202fah.90.1308322218206; Fri, 17 Jun 2011 07:50:18 -0700 (PDT) Received: from localhost.localdomain (stgt-4d039afc.pool.mediaWays.net [77.3.154.252]) by mx.google.com with ESMTPS id o10sm1378710fah.31.2011.06.17.07.50.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 07:50:17 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: padovan@profusion.mobi, jkosina@suse.cz, oliver@neukum.org, dh.herrmann@googlemail.com Subject: [PATCH 04/12 v2] HID: wiimote: Register input device in wiimote hid driver Date: Fri, 17 Jun 2011 16:49:14 +0200 Message-Id: <1308322162-13953-4-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308322162-13953-1-git-send-email-dh.herrmann@googlemail.com> References: <1308322162-13953-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]); Fri, 17 Jun 2011 14:54:37 +0000 (UTC) Register input device so the wiimote can report input events on it. We do not use HIDINPUT because the wiimote does not provide any descriptor table which might be used by HIDINPUT. So we avoid having HIDINPUT parse the wiimote descriptor and create unrelated or unknown event flags. Instead we register our own input device that we have full control of. Signed-off-by: David Herrmann --- drivers/hid/hid-wiimote.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/drivers/hid/hid-wiimote.c b/drivers/hid/hid-wiimote.c index ff7cf12..deaf232 100644 --- a/drivers/hid/hid-wiimote.c +++ b/drivers/hid/hid-wiimote.c @@ -10,7 +10,9 @@ * any later version. */ +#include #include +#include #include #include "hid-ids.h" @@ -19,8 +21,15 @@ struct wiimote_data { struct hid_device *hdev; + struct input_dev *input; }; +static int wiimote_input_event(struct input_dev *dev, unsigned int type, + unsigned int code, int value) +{ + return 0; +} + static int wiimote_hid_event(struct hid_device *hdev, struct hid_report *report, u8 *raw_data, int size) { @@ -38,9 +47,24 @@ static struct wiimote_data *wiimote_create(struct hid_device *hdev) if (!wdata) return NULL; + wdata->input = input_allocate_device(); + if (!wdata->input) { + kfree(wdata); + return NULL; + } + wdata->hdev = hdev; hid_set_drvdata(hdev, wdata); + input_set_drvdata(wdata->input, wdata); + wdata->input->event = wiimote_input_event; + wdata->input->dev.parent = &wdata->hdev->dev; + wdata->input->id.bustype = wdata->hdev->bus; + wdata->input->id.vendor = wdata->hdev->vendor; + wdata->input->id.product = wdata->hdev->product; + wdata->input->id.version = wdata->hdev->version; + wdata->input->name = WIIMOTE_NAME; + return wdata; } @@ -73,10 +97,19 @@ static int wiimote_hid_probe(struct hid_device *hdev, goto err; } + ret = input_register_device(wdata->input); + if (ret) { + hid_err(hdev, "Cannot register input device\n"); + goto err_stop; + } + hid_info(hdev, "New device registered\n"); return 0; +err_stop: + hid_hw_stop(hdev); err: + input_free_device(wdata->input); wiimote_destroy(wdata); return ret; } @@ -87,6 +120,7 @@ static void wiimote_hid_remove(struct hid_device *hdev) hid_info(hdev, "Device removed\n"); hid_hw_stop(hdev); + input_unregister_device(wdata->input); wiimote_destroy(wdata); }