All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Nielsen <a.nielsen@shikadi.net>
To: LKML Mailinglist <linux-kernel@vger.kernel.org>
Subject: led and hid class - hid_device vs led_classdev
Date: Tue, 04 Nov 2008 17:51:55 +1000	[thread overview]
Message-ID: <490FFF1B.6050300@shikadi.net> (raw)

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.

             reply	other threads:[~2008-11-04  7:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  7:51 Adam Nielsen [this message]
2008-11-04 21:48 ` led and hid class - hid_device vs led_classdev 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

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=490FFF1B.6050300@shikadi.net \
    --to=a.nielsen@shikadi.net \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.