Implement Bluetooth Wacom tablet's mode change in the kernel
Subsystems (3)
PATCH 1/1 Implement Bluetooth Wacom tablet's mode change in the kernel
Heya,
Here's a patch to do the Bluetooth Wacom tablet's mode setting in the kernel. In the past, it was done in a patch in bluetootd.
The first patch is probably completely wrong. Right now, hid_output_raw_report is done on the intr socket, instead of the ctrl socket. If it's correct to do it on the intr socket, we'd need to add some API as a way to select the ctrl socket instead for use in that driver.
I still have the exact same problems as with the user-space patch in that an error occurs sending the second blob of data to the tablet, the first time the driver is initialised. Ping, any ideas about that?
Cheers
Quoted 1 line
From
024b4ebd722ddb18f5f455c4db4a3f5ff41caa38Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Mon, 18 Jan 2010 16:11:33 +0000
Subject: [PATCH 1/2] [hidp] Use the control socket for raw messages
In commit 2da31939a42f7a676a0bc5155d6a0a39ed8451f2, support for Bluetooth hid_output_raw_report was added, but it pushes the data to the intr socket instead of the ctrl one.
This patch makes hid_output_raw_report use the control socket instead.
--- net/bluetooth/hidp/core.c | 70 +++++++++++++++++++++++---------------------- 1 files changed, 36 insertions(+), 34 deletions(-)
net/bluetooth/hidp/core.c +36 -34
@@ -243,6 +243,39 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)input_sync (dev); } +static int __hidp_send_ctrl_message (struct hidp_session *session, +unsigned char hdr,unsigned char *data,int size) +{ +struct sk_buff *skb; + +BT_DBG ("session %p data %p size %d" , session, data, size); + +if (!(skb =alloc_skb (size +1 ,GFP_ATOMIC ))) { +BT_ERR ("Can't allocate memory for new frame" ); +return -ENOMEM ; + } + + *skb_put (skb,1 ) = hdr; +if (data && size >0 ) +memcpy (skb_put (skb, size), data, size); + +skb_queue_tail (&session->ctrl_transmit, skb); + +return 0 ; +} + +static inline int hidp_send_ctrl_message (struct hidp_session *session, +unsigned char hdr,unsigned char *data,int size) +{ +int err; + + err =__hidp_send_ctrl_message (session, hdr, data, size); + +hidp_schedule (session); + +return err; +} +static int hidp_queue_report (struct hidp_session *session,unsigned char *data,int size) {
@@ -282,7 +315,9 @@ static int hidp_send_report(struct hidp_session *session, struct hid_report *repstatic int hidp_output_raw_report (struct hid_device *hid,unsigned char *data,size_t count) { -if (hidp_queue_report (hid->driver_data, data, count)) +if (count <=1 ) +return -EINVAL ; +if (hidp_send_ctrl_message (hid->driver_data, data[0 ], data +1 , count -1 ))return -ENOMEM ;return count; }
@@ -307,39 +342,6 @@ static inline void hidp_del_timer(struct hidp_session *session)del_timer (&session->timer); } -static int __hidp_send_ctrl_message (struct hidp_session *session, -unsigned char hdr,unsigned char *data,int size) -{ -struct sk_buff *skb; - -BT_DBG ("session %p data %p size %d" , session, data, size); - -if (!(skb =alloc_skb (size +1 ,GFP_ATOMIC ))) { -BT_ERR ("Can't allocate memory for new frame" ); -return -ENOMEM ; - } - - *skb_put (skb,1 ) = hdr; -if (data && size >0 ) -memcpy (skb_put (skb, size), data, size); - -skb_queue_tail (&session->ctrl_transmit, skb); - -return 0 ; -} - -static inline int hidp_send_ctrl_message (struct hidp_session *session, -unsigned char hdr,unsigned char *data,int size) -{ -int err; - - err =__hidp_send_ctrl_message (session, hdr, data, size); - -hidp_schedule (session); - -return err; -} -static void hidp_process_handshake (struct hidp_session *session,unsigned char param) {
Signature · 1 line
1.6.5.2
Quoted 1 line
From
6f83c0d084631033db9cb9b9452f5cf2e2bf67c2Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Mon, 18 Jan 2010 16:13:41 +0000
Subject: [PATCH 2/2] [hid] Implement Wacom quirk in the kernel
The hid-wacom driver required user-space to poke at the tablet to make it send data about the cursor location.
This patch makes it do the same thing but in the kernel.
--- drivers/hid/hid-wacom.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/hid/hid-wacom.c +13 -0
@@ -155,6 +155,7 @@ static int wacom_probe(struct hid_device *hdev,struct hid_input *hidinput;struct input_dev *input;struct wacom_data *wdata; +char rep_data[3 ];int ret; wdata =kzalloc (sizeof (*wdata),GFP_KERNEL );
@@ -177,6 +178,18 @@ static int wacom_probe(struct hid_device *hdev, goto err_free; } + rep_data[0 ] =0x53 ;/* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */ + rep_data[1 ] =0x03 ; rep_data[2 ] =0x00 ; + ret = hdev->hid_output_raw_report (hdev, rep_data,3 ); +if (ret <0 ) +dev_err (&hdev->dev,"failed to poke device #1, %d\n" , ret); + + rep_data[0 ] =0x71 ;/* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */ +/* 0x06 - high reporting speed, 0x05 - low speed */ + rep_data[1 ] =0x06 ; rep_data[2 ] =0x00 ; + ret = hdev->hid_output_raw_report (hdev, rep_data,3 ); +dev_err (&hdev->dev,"failed to poke device #2, %d\n" , ret); + hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input;
Signature · 1 line
1.6.5.2
Quoted 17 lines · Ping Cheng
On Mon, Jan 18, 2010 at 8:49 AM, Bastien Nocera <[email protected]> wrote:
Heya,Here's a patch to do the Bluetooth Wacom tablet's mode setting in the
kernel. In the past, it was done in a patch in bluetootd.The first patch is probably completely wrong. Right now,
hid_output_raw_reportis done on the intr socket, instead of the ctrl
socket. If it's correct to do it on the intr socket, we'd need to add
some API as a way to select the ctrl socket instead for use in that
driver.
Quoted 2 lines
I can not make a comment on the above patch since I know nothing about Bluetooth.
I'll let Marcel and Jiri be the judges of the value of this patch. In the worst case, it'll need a change of API for hid-core.
Quoted 7 lines
I still have the exact same problems as with the user-space patch in
that an error occurs sending the second blob of data to the tablet, the
first time the driver is initialised. Ping, any ideas about that?
Quoted 7 lines
I am not sure if your issue is similar to what we see with USB devices or not. In order to properly set the device to Wacom mode, we had to call
usb_set_reportmore than once (up to 5 times for older kernels, and up to 3 times for newer kernels) to get it right. Please call:
hdev->hid_output_raw_reportagain when ret is less than 0. Try up to three times to see what you get.
That's pretty straight forward, I'll try and do that.
Quoted 2 lines
You need to check if (ret < 0) before calling
dev_err()with the secondhid_output_raw_report()call, right?
Copy/paste stupidness all around there (as you can see, it's indented properly already ;)
Cheers
Dnia 2010-01-18, pon o godzinie 16:49 +0000, Bastien Nocera pisze:
[..]
My tablet has a really big lag when I'm using hi speed (patch 0002*). Does it work fine for you?
My laptop is rather slow, but I'm not sure if that's the bottleneck.
[przemo@pldmachine Desktop]$ uname -a
Linux pldmachine 2.6.33-rc4-00209-gd63f9cd-dirty #7 Mon Jan 18 20:45:27 GMT 2010 i686 Intel(R)_Pentium(R)_M_processor_1.86GHz PLD Linux
--
Cheers,
Przemo
On Mon, 2010-01-18 at 21:35 +0000, Bastien Nocera wrote:
<snip>
Quoted 12 lines
Quoted 12 lines
I still have the exact same problems as with the user-space patch in
that an error occurs sending the second blob of data to the tablet, the
first time the driver is initialised. Ping, any ideas about that?I am not sure if your issue is similar to what we see with USB devices or not. In order to properly set the device to Wacom mode, we had to call
usb_set_reportmore than once (up to 5 times for older kernels, and up to 3 times for newer kernels) to get it right. Please call:
Quoted 4 lines
Quoted 2 lines
hdev->hid_output_raw_reportagain when ret is less than 0. Try up to three times to see what you get.That's pretty straight forward, I'll try and do that.
My brain must have started turning to mush.
It's hid_parse() failing, and calling it multiple times doesn't have any effects (unlike on USB where it would poke the device repeatedly).
Marcel, any ideas about that?
Adding a few loops for the mode2 switching fixed very unfrequent failures. All that's left is the hid_parse() failure the first time the device connects.
Quoted 5 lines
Quoted 2 lines
You need to check if (ret < 0) before calling
dev_err()with the secondhid_output_raw_report()call, right?Copy/paste stupidness all around there (as you can see, it's indented properly already ;)
Fixed in the attached patch. Obviously still requires the first patch to be reviewed.
Cheers
Quoted 1 line
From
15fd982367e4e8f5ceeec3b8f802fb0f43da4ef9Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Mon, 18 Jan 2010 16:13:41 +0000
Subject: [PATCH] [hid] Implement Wacom quirk in the kernel
The hid-wacom driver required user-space to poke at the tablet to make it send data about the cursor location.
This patch makes it do the same thing but in the kernel.
--- drivers/hid/hid-wacom.c | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
drivers/hid/hid-wacom.c +33 -0
@@ -155,7 +155,9 @@ static int wacom_probe(struct hid_device *hdev,struct hid_input *hidinput;struct input_dev *input;struct wacom_data *wdata; +char rep_data[3 ];int ret; +int limit; wdata =kzalloc (sizeof (*wdata),GFP_KERNEL );if (wdata ==NULL ) {
@@ -165,6 +167,7 @@ static int wacom_probe(struct hid_device *hdev,hid_set_drvdata (hdev, wdata); +/* Parse the HID report now */ ret =hid_parse (hdev);if (ret) {dev_err (&hdev->dev,"parse failed\n" );
@@ -177,6 +180,36 @@ static int wacom_probe(struct hid_device *hdev, goto err_free; } +/* Set Wacom mode2 */ + rep_data[0 ] =0x53 ;/* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */ + rep_data[1 ] =0x03 ; rep_data[2 ] =0x00 ; + limit =3 ; +do { + ret = hdev->hid_output_raw_report (hdev, rep_data,3 ); + }while (ret <0 && limit-- >0 ); +if (ret <0 ) { +dev_err (&hdev->dev,"failed to poke device #1, %d\n" , ret); + goto err_free; + } + + rep_data[0 ] =0x71 ;/* HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE */ +/* 0x06 - high reporting speed, 0x05 - low speed */ + rep_data[1 ] =0x06 ; rep_data[2 ] =0x00 ; + limit =3 ; +do { + ret = hdev->hid_output_raw_report (hdev, rep_data,3 ); + }while (ret <0 && limit-- >0 ); +if (ret <0 ) { +dev_err (&hdev->dev,"failed to poke device #2, %d\n" , ret); + goto err_free; + } + + ret =hid_parse (hdev); +if (ret) { +dev_err (&hdev->dev,"parse failed\n" ); + goto err_free; + } + hidinput = list_entry(hdev->inputs.next, struct hid_input, list); input = hidinput->input;
Signature · 1 line
1.6.5.2
Marcel Holtmann
maintainerHi Bastien,
Quoted 8 lines
Here's a patch to do the Bluetooth Wacom tablet's mode setting in the kernel. In the past, it was done in a patch in bluetootd.
The first patch is probably completely wrong. Right now,
hid_output_raw_reportis done on the intr socket, instead of the ctrl socket. If it's correct to do it on the intr socket, we'd need to add some API as a way to select the ctrl socket instead for use in that driver.
actually the interrupt should be incoming only. So moving the raw output to the control channel seems fine to. Any reason why it is on the interrupt channel in the first place?
Regards
Marcel
Quoted 11 lines · Marcel Holtmann
Hi Bastien,
Quoted 8 lines
Here's a patch to do the Bluetooth Wacom tablet's mode setting in the kernel. In the past, it was done in a patch in bluetootd.
The first patch is probably completely wrong. Right now,
hid_output_raw_reportis done on the intr socket, instead of the ctrl socket. If it's correct to do it on the intr socket, we'd need to add some API as a way to select the ctrl socket instead for use in that driver.
Quoted 3 lines
actually the interrupt should be incoming only. So moving the raw output to the control channel seems fine to. Any reason why it is on the interrupt channel in the first place?
The patch was written by Jiri and tested by Brian. Not sure what sort of device Brian tested this with...
Quoted 12 lines · Bastien Nocera
Quoted 11 lines · Marcel Holtmann
Hi Bastien,
Quoted 8 lines
Here's a patch to do the Bluetooth Wacom tablet's mode setting in the kernel. In the past, it was done in a patch in bluetootd.
The first patch is probably completely wrong. Right now,
hid_output_raw_reportis done on the intr socket, instead of the ctrl socket. If it's correct to do it on the intr socket, we'd need to add some API as a way to select the ctrl socket instead for use in that driver.
Quoted 6 lines
Quoted 3 lines
actually the interrupt should be incoming only. So moving the raw output to the control channel seems fine to. Any reason why it is on the interrupt channel in the first place?
The patch was written by Jiri and tested by Brian. Not sure what sort of device Brian tested this with...
Hmm, that's right, ctrl pipe would make much more sense (and this is what we do in USB driver as well). I used intr pipe by mistake, but it seems that it made things work for Brian anyway, which is quite puzzling.
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
I tested this with a Bluetooth remote control. As I understand, reports ca= n be written to either the interrupt or control sockets. I'm happy to test=
other changes to let this be selectable.
Brian
________________________________________
From: Bastien Nocera [[email protected]]
Sent: Tuesday, January 19, 2010 2:30 AM
To: Marcel Holtmann
Cc: Dmitry Torokhov; linux-input; BlueZ development; Gunn, Brian; Ping; Jir= i Kosina
Subject: Re: [PATCHes] Implement Bluetooth Wacom tablet's mode change in th= e kernel
Quoted 11 lines · Marcel Holtmann
Hi Bastien,
Quoted 8 lines
Here's a patch to do the Bluetooth Wacom tablet's mode setting in the kernel. In the past, it was done in a patch in bluetootd.
The first patch is probably completely wrong. Right now,
hid_output_raw_reportis done on the intr socket, instead of the ctrl socket. If it's correct to do it on the intr socket, we'd need to add some API as a way to select the ctrl socket instead for use in that driver.
Quoted 3 lines
actually the interrupt should be incoming only. So moving the raw output to the control channel seems fine to. Any reason why it is on the interrupt channel in the first place?
The patch was written by Jiri and tested by Brian. Not sure what sort of device Brian tested this with...
Quoted 3 lines · Brian
I tested this with a Bluetooth remote control. As I understand, reports can be written to either the interrupt or control sockets. I'm happy to test other changes to let this be selectable.
Could you expand slightly on that? What make/model? What sort of tests did you do on it?
Cheers
Quoted 8 lines
Bastien Nocera wrote:
Quoted 3 lines · Brian
I tested this with a Bluetooth remote control. As I understand, reports can be written to either the interrupt or control sockets. I'm happy to test other changes to let this be selectable.
Could you expand slightly on that? What make/model? What sort of tests did you do on it?
I used a custom remote control under development by the company I'm contrac= ted to. We have custom HID output reports that trigger actions on the remo= te. I was able to send the output reports and get the behavior I expected = on the remote. I have no faith that the company developing the remote impl= emented their side correctly and would like to try it with the control sock= et instead.
Brian
Quoted 5 lines · Brian Gunn
I used a custom remote control under development by the company I'm contracted to. We have custom HID output reports that trigger actions on the remote. I was able to send the output reports and get the behavior I expected on the remote. I have no faith that the company developing the remote implemented their side correctly and would like to try it with the control socket instead.
BTW: The Sony PS3 controller requires sending of HID reports as well. I just checked the one implementation of this I've seen (input/device.c in the BlueZ source) and I see that it uses the control socket.
Once we get implementation of sending HID reports to the control socket implemented elsewhere, this kludge can be removed from the BlueZ source.
Brian
Quoted 2 lines · Bastien Nocera
The patch was written by Jiri and tested by Brian. Not sure what sort of device Brian tested this with...
I just tested this patch with my device and it does work. I had to slightl= y alter the data I send (had to add 0xA2 to the front of it), but then it d= oes work.
In my initial attempts, it does seem to work a little worse, but that is pr= obably because of the device I'm using, which is still under development.
Brian
Quoted 11 lines · Brian
Quoted 2 lines · Bastien Nocera
The patch was written by Jiri and tested by Brian. Not sure what sort of device Brian tested this with...
I just tested this patch with my device and it does work. I had to slightly alter the data I send (had to add
0xA2to the front of it), but then it does work.In my initial attempts, it does seem to work a little worse, but that is probably because of the device I'm using, which is still under development.
I sent a new version of the patch, which uses "HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?
Quoted 6 lines
Quoted 3 lines
I just tested this patch with my device and it does work. I had to slightly alter the data I send (had to add
0xA2to the front of it), but then it does work.I sent a new version of the patch, which uses "
HIDP_TRANS_SET_REPORT|HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?
Actually for my application it doesn't. I use HIDP_TRANS_DATA | HIDP_DATA_= RTYPE_OUTPUT.
Perhaps allowing the user the choice of what do to here is more flexible.
Brian
Quoted 10 lines · Brian
Quoted 6 lines
Quoted 3 lines
I just tested this patch with my device and it does work. I had to slightly alter the data I send (had to add
0xA2to the front of it), but then it does work.I sent a new version of the patch, which uses "
HIDP_TRANS_SET_REPORT|HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?Actually for my application it doesn't. I use
HIDP_TRANS_DATA|HIDP_DATA_RTYPE_OUTPUT.Perhaps allowing the user the choice of what do to here is more flexible.
Except that it would mean different code for USB and Bluetooth versions...
Quoted 1 line
Quoted 1 line
Quoted 1 line
I sent a new version of the patch, which uses "
HIDP_TRANS_SET_REPORT=
|
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?Actually for my application it doesn't. I use
HIDP_TRANS_DATA|
HIDP_DATA_RTYPE_OUTPUT.Quoted 2 lines
Perhaps allowing the user the choice of what do to here is more flexibl=
e.
Quoted 3 lines
Except that it would mean different code for USB and Bluetooth versions...
So do we need a method of setting which device reports we're sending before=
writing them?
Brian
Quoted 4 lines · Brian
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
I sent a new version of the patch, which uses "
HIDP_TRANS_SET_REPORT|HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?Actually for my application it doesn't. I use
HIDP_TRANS_DATA|
Quoted 8 lines
Quoted 6 lines
HIDP_DATA_RTYPE_OUTPUT.Quoted 2 lines
Perhaps allowing the user the choice of what do to here is more flexible.
Except that it would mean different code for USB and Bluetooth versions...
So do we need a method of setting which device reports we're sending before writing them?
Having separate methods for feature and output reports should be sufficient and general enough, right?
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Quoted 10 lines · Jiri Kosina
Quoted 8 lines · Brian
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I sent a new version of the patch, which uses "
HIDP_TRANS_SET_REPORT|HIDP_DATA_RTYPE_FEATURE" for the first byte. Would that work?Actually for my application it doesn't. I use
HIDP_TRANS_DATA|
HIDP_DATA_RTYPE_OUTPUT.Quoted 2 lines
Perhaps allowing the user the choice of what do to here is more flexible.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Except that it would mean different code for USB and Bluetooth versions...
So do we need a method of setting which device reports we're sending before writing them?
Having separate methods for feature and output reports should be sufficient and general enough, right?
Most likely, yes. Feature is enough for the 2 devices I provided patches for. Could you please comment on what you'd like the implementation of this to look like? This simple bug fix is turning into a lot more to-and-fro than I would have anticipated.
Cheers
Quoted 6 lines · Bastien Nocera
Quoted 2 lines
Having separate methods for feature and output reports should be sufficient and general enough, right?
Most likely, yes. Feature is enough for the 2 devices I provided patches for. Could you please comment on what you'd like the implementation of this to look like?
I think that we should probably introduce flag parameter into hid_output_raw_report(), which would indicate whether OUTPUT or FEATURE report should be sent.
This makes sense both for Bluetooth and HID.
I will send out patches later today for you guys to test (and for Marcel to Ack the Bluetooth part).
Quoted 2 lines
This simple bug fix is turning into a lot more to-and-fro than I would have anticipated.
It's nice example of evolution, isn't it? :)
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.