From patchwork Tue Jun 14 23:45:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 880532 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 p5ENjw6K019029 for ; Tue, 14 Jun 2011 23:46:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753000Ab1FNXqT (ORCPT ); Tue, 14 Jun 2011 19:46:19 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:36667 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752089Ab1FNXqT (ORCPT ); Tue, 14 Jun 2011 19:46:19 -0400 Received: by mail-fx0-f46.google.com with SMTP id 17so41764fxm.19 for ; Tue, 14 Jun 2011 16:46: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=NF4quKSymUelYmcbQe2lasmemS1b+AjN5bn9ecraUW0=; b=aLc2lT/QSYppE/zAKtgz+DsOamr0qcwT+qujZ6/xL9LawiAW64i075Ew9Z8N8UpMBf HZxPEBrBkq+xx0g0OEYTmBIZ6EmefvbORBWUfCRa/ds56b9cyjQV3qY7y7t4xN87Y28P CcxmZ0CHx50gv/2ZndvDP7KJMrf5lrbngO9us= 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=VbygiTqArBl8RybQrdnAzaDBxxi5c0pwRsJo6QGJL+R8pw/GgLKyOGyDAQdKmUycae SVpsWtWYEqqHB668bQak1uQ5j8hOUJTaenC76PJmz1AWlqIJjngpP82llThKcMt0h5N3 5zADNrErJXDDCFCcGvmO1yyEcZeqywA+cvhLw= Received: by 10.223.96.130 with SMTP id h2mr1959679fan.142.1308095178644; Tue, 14 Jun 2011 16:46:18 -0700 (PDT) Received: from localhost.localdomain (stgt-4d0383f8.pool.mediaWays.net [77.3.131.248]) by mx.google.com with ESMTPS id g7sm2963789fac.39.2011.06.14.16.46.17 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2011 16:46:18 -0700 (PDT) From: David Herrmann To: linux-input@vger.kernel.org Cc: jkosina@suse.cz, padovan@profusion.mobi, dh.herrmann@googlemail.com Subject: [RFC 04/12] HID: wiimote: Register input device in wiimote hid driver Date: Wed, 15 Jun 2011 01:45:49 +0200 Message-Id: <1308095157-4699-5-git-send-email-dh.herrmann@googlemail.com> X-Mailer: git-send-email 1.7.5.2 In-Reply-To: <1308095157-4699-1-git-send-email-dh.herrmann@googlemail.com> References: <1308095157-4699-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, 14 Jun 2011 23:46:35 +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 27a4261..9fa4fe1 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; } @@ -68,10 +92,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); kfree(wdata); return ret; } @@ -82,6 +115,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); kfree(wdata); }