public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* led and hid class - hid_device vs led_classdev
@ 2008-11-04  7:51 Adam Nielsen
  2008-11-04 21:48 ` Jiri Slaby
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Nielsen @ 2008-11-04  7:51 UTC (permalink / raw)
  To: LKML Mailinglist

Hi all,

I'm writing a driver for a USB HID device (using the new hid class), but 
I'm a bit confused about how the hid_device structure relates to the 
other driver-information structures.

One of the functions the device implements is a LED.  This is pretty 
simple to control (basic on/off), so I'd like to implement a device in 
the "led" class that controls this led.

In my hid driver's probe function I'm given a struct hid_device* which 
is used with functions like hid_hw_start().

I then need to call led_classdev_register() to register my led device. 
At the moment I pass this function hid_device.dev

Then I set my custom driver data with hid_set_drvdata().

Later on, when the user wants to switch the LED on or off, a function in 
my driver gets called, with a struct led_classdev* parameter.

I'm stuck trying to figure out how to convert this led_classdev 
parameter back into a hid_device, so that I can extract the custom data 
I set with hid_set_drvdata().

Some of the led drivers use platform_set_drvdata() in their probe 
functions to get their custom data instead, but I'm afraid if I do this 
I'll overwrite any hid-related data that hid_set_drvdata() might tack on 
to my custom data.

Some pseudocode to help illustrate:

static int my_probe(struct hid_device *hid,
   const struct hid_device_id *id)
{
   hid_parse(hid);
   hid_hw_start(hid, HID_CONNECT_DEFAULT);

   led_classdev_register(&hid->dev, &my_led);

   hid_set_drvdata(hid, my_data);

   /* Don't want to use this, in case it overwrites something that
      hid_set_drvdata() includes. */
   /*platform_set_drvdata(&hid->dev, my_data);*/
}

/* Callback function when user wants to change LED state */
static void my_led_set(struct led_classdev *led_cdev,
   enum led_brightness value)
{
   /* How do I get my_data back? */
}

Hopefully this explains what I'm after - if you need me to clarify 
anything please let me know.

Many thanks,
Adam.

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

end of thread, other threads:[~2008-11-08 22:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04  7:51 led and hid class - hid_device vs led_classdev Adam Nielsen
2008-11-04 21:48 ` Jiri Slaby
2008-11-08  6:18   ` hid class and sysfs/hwmon (was: led and hid class - hid_device vs led_classdev) Adam Nielsen
2008-11-08 14:16     ` hid class and sysfs/hwmon Jiri Slaby
2008-11-08 21:45       ` Adam Nielsen
2008-11-08 21:51         ` Jiri Slaby
2008-11-08 22:02           ` Adam Nielsen

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