public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* usbhid: How to wait for response after submitting report
@ 2010-03-13  3:10 Adam Nielsen
  2010-03-15 16:07 ` Jiri Kosina
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Nielsen @ 2010-03-13  3:10 UTC (permalink / raw)
  To: LKML Mailinglist

Hi all,

I'm working on a USB HID driver, but my driver seems to be receiving bad data.
 I think it's because usbhid_submit_report is non-blocking and I'm not
correctly waiting for a response.  I'm not sure though, because none of the
existing usbhid drivers seem to work in this way.

Could someone please let me know if I'm going about this the right way?

  odin_psu->report->field[0]->value[0] = msg;
  odin_psu->report->field[0]->value[1] = 0x01;

  usbhid_submit_report(odin_psu->hdev, odin_psu->report, USB_DIR_OUT);
  usbhid_wait_io(odin_psu->hdev);

  usbhid_submit_report(odin_psu->hdev, odin_psu->report_in, USB_DIR_IN);
  usbhid_wait_io(odin_psu->hdev);

Many thanks,
Adam.

(Please CC)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: usbhid: How to wait for response after submitting report
  2010-03-13  3:10 usbhid: How to wait for response after submitting report Adam Nielsen
@ 2010-03-15 16:07 ` Jiri Kosina
  2010-03-27 11:52   ` Adam Nielsen
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Kosina @ 2010-03-15 16:07 UTC (permalink / raw)
  To: Adam Nielsen; +Cc: LKML Mailinglist

On Sat, 13 Mar 2010, Adam Nielsen wrote:

> I'm working on a USB HID driver, but my driver seems to be receiving bad data.
>  I think it's because usbhid_submit_report is non-blocking and I'm not
> correctly waiting for a response.  I'm not sure though, because none of the
> existing usbhid drivers seem to work in this way.
> 
> Could someone please let me know if I'm going about this the right way?
> 
>   odin_psu->report->field[0]->value[0] = msg;
>   odin_psu->report->field[0]->value[1] = 0x01;
> 
>   usbhid_submit_report(odin_psu->hdev, odin_psu->report, USB_DIR_OUT);
>   usbhid_wait_io(odin_psu->hdev);
> 
>   usbhid_submit_report(odin_psu->hdev, odin_psu->report_in, USB_DIR_IN);
>   usbhid_wait_io(odin_psu->hdev);

Hi Adam,

I am afraid you'll have to explain in more detail what exactly you are 
tying to achieve, and why the way the current HID code does it (i.e. URB 
gets submitted, completion handler is called when completed) doesn't work 
for you.

Thanks,

-- 
Jiri Kosina
SUSE Labs, Novell Inc.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: usbhid: How to wait for response after submitting report
  2010-03-15 16:07 ` Jiri Kosina
@ 2010-03-27 11:52   ` Adam Nielsen
  2010-03-30 12:10     ` Jiri Kosina
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Nielsen @ 2010-03-27 11:52 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: LKML Mailinglist

>> I'm working on a USB HID driver, but my driver seems to be receiving bad data.
>>  I think it's because usbhid_submit_report is non-blocking and I'm not
>> correctly waiting for a response.  I'm not sure though, because none of the
>> existing usbhid drivers seem to work in this way.
>>
>> Could someone please let me know if I'm going about this the right way?
> 
> I am afraid you'll have to explain in more detail what exactly you are 
> tying to achieve, and why the way the current HID code does it (i.e. URB 
> gets submitted, completion handler is called when completed) doesn't work 
> for you.

Thanks Jiri, it's probably because I still don't know what I'm doing :-)  Can
you point me at any HID examples that show how to use a completion handler?
I'm afraid after hours of staring at HID code I'm still none the wiser as to
how this part of the system works.

Basically I have a USB HID device, and it works by submitting a HID report,
then waiting until it replies with (I assume) another HID report.  The
messages are all proprietary.  I can send the reports fine, but half the time
I get garbage coming back, which I assume is because I'm not getting the
message quickly enough and processing whatever was in the buffer instead.

If you're able to point me in the direction of an example showing how to set
up and use a completion handler, hopefully I can change my code to work like
that instead.

Many thanks,
Adam.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: usbhid: How to wait for response after submitting report
  2010-03-27 11:52   ` Adam Nielsen
@ 2010-03-30 12:10     ` Jiri Kosina
  2010-03-30 12:21       ` Adam Nielsen
  0 siblings, 1 reply; 5+ messages in thread
From: Jiri Kosina @ 2010-03-30 12:10 UTC (permalink / raw)
  To: Adam Nielsen; +Cc: LKML Mailinglist

On Sat, 27 Mar 2010, Adam Nielsen wrote:

> Thanks Jiri, it's probably because I still don't know what I'm doing :-)  Can
> you point me at any HID examples that show how to use a completion handler?
> I'm afraid after hours of staring at HID code I'm still none the wiser as to
> how this part of the system works.
> 
> Basically I have a USB HID device, and it works by submitting a HID report,
> then waiting until it replies with (I assume) another HID report.  The
> messages are all proprietary.  I can send the reports fine, but half the time
> I get garbage coming back, which I assume is because I'm not getting the
> message quickly enough and processing whatever was in the buffer instead.
> 
> If you're able to point me in the direction of an example showing how to set
> up and use a completion handler, hopefully I can change my code to work like
> that instead.

Well this is rather more USB-related question than HID related question, 
I'd say.

Basically you prepare URB, along with specifying which routine should be 
called by USB core as completion handler, and then submit the URB.

USB HID implementation is working like this (and zillions of other USB 
drivers which are in kernel do as well) -- just look at initialization of 
control URB in usbhid_start(), and the completion handler (for control 
URBs) in hid_ctrl().

-- 
Jiri Kosina
SUSE Labs, Novell Inc.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: usbhid: How to wait for response after submitting report
  2010-03-30 12:10     ` Jiri Kosina
@ 2010-03-30 12:21       ` Adam Nielsen
  0 siblings, 0 replies; 5+ messages in thread
From: Adam Nielsen @ 2010-03-30 12:21 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: LKML Mailinglist

>> Basically I have a USB HID device, and it works by submitting a HID report,
>> then waiting until it replies with (I assume) another HID report.  The
>> messages are all proprietary.  I can send the reports fine, but half the time
>> I get garbage coming back, which I assume is because I'm not getting the
>> message quickly enough and processing whatever was in the buffer instead.
>>
>> If you're able to point me in the direction of an example showing how to set
>> up and use a completion handler, hopefully I can change my code to work like
>> that instead.
> 
> Well this is rather more USB-related question than HID related question, 
> I'd say.

Well originally I was going to write a USB driver, but as it's a HID device
and there's a HID class in the kernel, I thought it would be better to use the
functions provided by the USB HID device class.

> Basically you prepare URB, along with specifying which routine should be 
> called by USB core as completion handler, and then submit the URB.

Can I do this without conflicting with the HID "layer"?  I assumed that
drivers appearing in the HID class should only use HID functions, and those
functions would take care of the USB side of things.  I don't really want to
reimplement all the standard HID communication code when it has already been
implemented in the USB HID driver/class.

> USB HID implementation is working like this (and zillions of other USB 
> drivers which are in kernel do as well) -- just look at initialization of 
> control URB in usbhid_start(), and the completion handler (for control 
> URBs) in hid_ctrl().

At the moment I am calling functions like hid_hw_start and
usbhid_submit_report, which (I think) take care of all this for me.  There's
not a lot of documentation about how the HID class works, and only a handful
of drivers unfortunately, since it's a standard USB device class - you only
need to write a driver for nonstandard hardware, which means all the existing
HID drivers are all very different!

Because usbhid_submit_report takes the raw data to be packaged up inside a USB
HID message, I don't have an opportunity to set any sort of completion
handler.  I imagine the HID class takes care of it, but I don't know how to
figure out whether the completion handler has been called and there's data to
read.

Thanks,
Adam.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-03-30 12:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-13  3:10 usbhid: How to wait for response after submitting report Adam Nielsen
2010-03-15 16:07 ` Jiri Kosina
2010-03-27 11:52   ` Adam Nielsen
2010-03-30 12:10     ` Jiri Kosina
2010-03-30 12:21       ` Adam Nielsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox