From: Chase Douglas <chase.douglas@canonical.com>
To: Michael Poole <mdpoole@troilus.org>
Cc: Jiri Slaby <jirislaby@gmail.com>, Jiri Kosina <jkosina@suse.cz>,
Henrik Rydberg <rydberg@euromail.se>, Tejun Heo <tj@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] hid-magicmouse: Map inputs rather than munging input devices
Date: Sat, 18 Sep 2010 14:50:32 +0200 [thread overview]
Message-ID: <1284814232.2257.6.camel@mini> (raw)
In-Reply-To: <1283699801.26830.4.camel@graviton>
On Sun, 2010-09-05 at 11:16 -0400, Michael Poole wrote:
> Let the HID core handle input device setup and HID-compliant reports.
> This driver then only has to worry about the non-standard reports.
>
> Signed-off-by: Michael Poole <mdpoole@troilus.org>
I have tested this patch and it does prevent the magic trackpad from
panicking the machine on device removal. I am acking this patch because
it resolves the issue and the changes are reasonable when looking at the
driver. I do not know much about the internal HID layer, so I have no
comment on the overall approach taken.
Acked-by: Chase Douglas <chase.douglas@canonical.com>
When pushing to the input tree, I suggest rebasing the magic trackpad
enablement patch after this patch so someone bisecting commits won't hit
the panic.
Thanks Michael!
> ---
> Jiri (Slaby), is this the kind of change you had in mind for getting rid
> of the input device setup for hid-magicmouse?
>
> (This applies on top of commit a462230e16 from the magicmouse branch at
> git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid.git.)
>
> drivers/hid/hid-magicmouse.c | 87
> +++++++++++------------------------------
> 1 files changed, 24 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index 8791a08..3778f9b 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -278,14 +278,12 @@ static int magicmouse_raw_event(struct hid_device
> *hdev,
> struct input_dev *input = msc->input;
> int x = 0, y = 0, ii, clicks = 0, npoints;
>
> + /* Slightly paranoid, but "input" only gets set when our
> + * input_mapping sees the right field. */
> + if (!input)
> + return 0;
> +
> switch (data[0]) {
> - case 0x10:
> - if (size != 6)
> - return 0;
> - x = (__s16)(data[2] | data[3] << 8);
> - y = (__s16)(data[4] | data[5] << 8);
> - clicks = data[1];
> - break;
> case TRACKPAD_REPORT_ID:
> /* Expect four bytes of prefix, and N*9 bytes of touch data. */
> if (size < 4 || ((size - 4) % 9) != 0)
> @@ -343,13 +341,6 @@ static int magicmouse_raw_event(struct hid_device
> *hdev,
> magicmouse_raw_event(hdev, report, data + 2 + data[1],
> size - 2 - data[1]);
> break;
> - case 0x20: /* Theoretically battery status (0-100), but I have
> - * never seen it -- maybe it is only upon request.
> - */
> - case 0x60: /* Unknown, maybe laser on/off. */
> - case 0x61: /* Laser reflection status change.
> - * data[1]: 0 = spotted, 1 = lost
> - */
> default:
> return 0;
> }
> @@ -377,36 +368,8 @@ static int magicmouse_raw_event(struct hid_device
> *hdev,
> return 1;
> }
>
> -static int magicmouse_input_open(struct input_dev *dev)
> -{
> - struct hid_device *hid = input_get_drvdata(dev);
> -
> - return hid->ll_driver->open(hid);
> -}
> -
> -static void magicmouse_input_close(struct input_dev *dev)
> -{
> - struct hid_device *hid = input_get_drvdata(dev);
> -
> - hid->ll_driver->close(hid);
> -}
> -
> static void magicmouse_setup_input(struct input_dev *input, struct
> hid_device *hdev)
> {
> - input_set_drvdata(input, hdev);
> - input->event = hdev->ll_driver->hidinput_input_event;
> - input->open = magicmouse_input_open;
> - input->close = magicmouse_input_close;
> -
> - input->name = hdev->name;
> - input->phys = hdev->phys;
> - input->uniq = hdev->uniq;
> - input->id.bustype = hdev->bus;
> - input->id.vendor = hdev->vendor;
> - input->id.product = hdev->product;
> - input->id.version = hdev->version;
> - input->dev.parent = hdev->dev.parent;
> -
> __set_bit(EV_KEY, input->evbit);
>
> if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
> @@ -466,11 +429,22 @@ static void magicmouse_setup_input(struct
> input_dev *input, struct hid_device *h
> }
> }
>
> +static int magicmouse_input_mapping(struct hid_device *hdev,
> + struct hid_input *hi, struct hid_field *field,
> + struct hid_usage *usage, unsigned long **bit, int *max)
> +{
> + struct magicmouse_sc *msc = hid_get_drvdata(hdev);
> +
> + if (!msc->input)
> + msc->input = hi->input;
> +
> + return 0;
> +}
> +
> static int magicmouse_probe(struct hid_device *hdev,
> const struct hid_device_id *id)
> {
> __u8 feature[] = { 0xd7, 0x01 };
> - struct input_dev *input;
> struct magicmouse_sc *msc;
> struct hid_report *report;
> int ret;
> @@ -500,8 +474,12 @@ static int magicmouse_probe(struct hid_device
> *hdev,
> goto err_free;
> }
>
> - /* we are handling the input ourselves */
> - hidinput_disconnect(hdev);
> + /* We do this after HID maps its inputs so that the
> + * Magic Mouse's HID-compliant report gets the right
> + * button and axis IDs.
> + */
> + if (msc->input)
> + magicmouse_setup_input(msc->input, hdev);
>
> if (id->product == USB_DEVICE_ID_APPLE_MAGICMOUSE)
> report = hid_register_report(hdev, HID_INPUT_REPORT,
> @@ -528,24 +506,7 @@ static int magicmouse_probe(struct hid_device
> *hdev,
> goto err_stop_hw;
> }
>
> - input = input_allocate_device();
> - if (!input) {
> - dev_err(&hdev->dev, "can't alloc input device\n");
> - ret = -ENOMEM;
> - goto err_stop_hw;
> - }
> - magicmouse_setup_input(input, hdev);
> -
> - ret = input_register_device(input);
> - if (ret) {
> - dev_err(&hdev->dev, "input device registration failed\n");
> - goto err_input;
> - }
> - msc->input = input;
> -
> return 0;
> -err_input:
> - input_free_device(input);
> err_stop_hw:
> hid_hw_stop(hdev);
> err_free:
> @@ -558,7 +519,6 @@ static void magicmouse_remove(struct hid_device
> *hdev)
> struct magicmouse_sc *msc = hid_get_drvdata(hdev);
>
> hid_hw_stop(hdev);
> - input_unregister_device(msc->input);
> kfree(msc);
> }
>
> @@ -577,6 +537,7 @@ static struct hid_driver magicmouse_driver = {
> .probe = magicmouse_probe,
> .remove = magicmouse_remove,
> .raw_event = magicmouse_raw_event,
> + .input_mapping = magicmouse_input_mapping,
> };
>
> static int __init magicmouse_init(void)
next prev parent reply other threads:[~2010-09-18 12:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-01 1:56 [PATCH 0/7 v3] HID: magicmouse: fixes and support for the Magic Trackpad (v3) Chase Douglas
2010-09-01 1:56 ` [PATCH 1/7 v3] HID: magicmouse: don't allow hidinput to initialize the device Chase Douglas
2010-09-01 18:01 ` Jiri Slaby
2010-09-01 23:57 ` Michael Poole
2010-09-02 9:28 ` Jiri Slaby
2010-09-02 12:06 ` Michael Poole
2010-09-03 11:25 ` Jiri Slaby
2010-09-04 1:10 ` Michael Poole
2010-09-05 15:16 ` [RFC PATCH] hid-magicmouse: Map inputs rather than munging input devices Michael Poole
2010-09-18 12:50 ` Chase Douglas [this message]
2010-09-01 1:56 ` [PATCH 2/7 v3] HID: magicmouse: simplify multitouch feature request Chase Douglas
2010-09-01 7:43 ` Henrik Rydberg
2010-09-01 12:34 ` Chase Douglas
2010-09-01 13:14 ` Henrik Rydberg
2010-09-01 13:50 ` Chase Douglas
2010-09-03 13:57 ` Jiri Kosina
2010-09-01 1:56 ` [PATCH 3/7 v3] HID: magicmouse: simplify touch data bit manipulation Chase Douglas
2010-09-03 14:07 ` Jiri Kosina
2010-09-01 1:56 ` [PATCH 4/7 v3] HID: magicmouse: simplify touch down logic Chase Douglas
2010-09-01 2:23 ` Michael Poole
2010-09-02 14:50 ` Jiri Kosina
2010-09-01 1:56 ` [PATCH 5/7 v3] HID: magicmouse: remove timestamp logic Chase Douglas
2010-09-01 2:24 ` Michael Poole
2010-09-02 14:52 ` Jiri Kosina
2010-09-01 1:56 ` [PATCH 6/7 v3] HID: magicmouse: enable Magic Trackpad support Chase Douglas
2010-09-03 14:05 ` Jiri Kosina
2010-09-01 1:56 ` [PATCH 7/7 v3] HID: magicmouse: Adjust major / minor axes to scale Chase Douglas
2010-09-02 14:55 ` Jiri Kosina
2010-09-07 13:50 ` Chase Douglas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1284814232.2257.6.camel@mini \
--to=chase.douglas@canonical.com \
--cc=jirislaby@gmail.com \
--cc=jkosina@suse.cz \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdpoole@troilus.org \
--cc=rydberg@euromail.se \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).