* [PATCH] hwmon class driver registration with a device number
@ 2011-10-05 17:13 Himanshu Chauhan
2011-10-05 19:33 ` Greg KH
[not found] ` <1317839407.3983.46.camel@groeck-laptop>
0 siblings, 2 replies; 9+ messages in thread
From: Himanshu Chauhan @ 2011-10-05 17:13 UTC (permalink / raw)
To: kernelnewbies
This patch adds a way to register a hwmon class driver
with a device number rather than the default MK_DEV(0,0).
This would help in creating required "dev" file under
sysfs which in turn can be used in populating /dev tree
during bootup (helpful to driver which want to show up
a char interface along with sysfs).
Signed-off-by: Himanshu Chauhan <hschauhan@nulltrace.org>
---
drivers/hwmon/hwmon.c | 28 ++++++++++++++++++++++------
include/linux/hwmon.h | 1 +
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index a61e781..36961c5 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -31,15 +31,17 @@ static DEFINE_IDR(hwmon_idr);
static DEFINE_SPINLOCK(idr_lock);
/**
- * hwmon_device_register - register w/ hwmon
- * @dev: the device to register
+ * hwmon_device_register_numbered - register hwmon class dev
+ * with specific device number.
+ * @dev: Device to register.
+ * @dev_id: device number to register.
*
- * hwmon_device_unregister() must be called when the device is no
- * longer needed.
+ * hwmon_device_unregister() must be called when the device
+ * is no longer needed.
*
* Returns the pointer to the new device.
*/
-struct device *hwmon_device_register(struct device *dev)
+struct device* hwmon_device_register_numbered(struct device *dev, dev_t dev_id)
{
struct device *hwdev;
int id, err;
@@ -58,7 +60,7 @@ again:
return ERR_PTR(err);
id = id & MAX_ID_MASK;
- hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
+ hwdev = device_create(hwmon_class, dev, dev_id, NULL,
HWMON_ID_FORMAT, id);
if (IS_ERR(hwdev)) {
@@ -71,6 +73,20 @@ again:
}
/**
+ * hwmon_device_register - register w/ hwmon
+ * @dev: the device to register
+ *
+ * hwmon_device_unregister() must be called when the device is no
+ * longer needed.
+ *
+ * Returns the pointer to the new device.
+ */
+struct device *hwmon_device_register(struct device *dev)
+{
+ return hwmon_device_register_numbered(dev, MK_DEV(0,0));
+}
+
+/**
* hwmon_device_unregister - removes the previously registered class device
*
* @dev: the class device to destroy
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 6b6ee70..d816cbe 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -16,6 +16,7 @@
#include <linux/device.h>
+struct device *hwmon_device_register_numbered(struct device *dev, dev_t dev_id);
struct device *hwmon_device_register(struct device *dev);
void hwmon_device_unregister(struct device *dev);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH] hwmon class driver registration with a device number
2011-10-05 17:13 [PATCH] hwmon class driver registration with a device number Himanshu Chauhan
@ 2011-10-05 19:33 ` Greg KH
2011-10-06 4:10 ` Himanshu Chauhan
[not found] ` <1317839407.3983.46.camel@groeck-laptop>
1 sibling, 1 reply; 9+ messages in thread
From: Greg KH @ 2011-10-05 19:33 UTC (permalink / raw)
To: kernelnewbies
On Wed, Oct 05, 2011 at 10:43:11PM +0530, Himanshu Chauhan wrote:
> This patch adds a way to register a hwmon class driver
> with a device number rather than the default MK_DEV(0,0).
> This would help in creating required "dev" file under
> sysfs which in turn can be used in populating /dev tree
> during bootup (helpful to driver which want to show up
> a char interface along with sysfs).
How do you later remove a device created with this new interface? As it
is, I think the existing calls will fail, right?
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH] hwmon class driver registration with a device number
2011-10-05 19:33 ` Greg KH
@ 2011-10-06 4:10 ` Himanshu Chauhan
2011-10-06 18:25 ` Greg KH
0 siblings, 1 reply; 9+ messages in thread
From: Himanshu Chauhan @ 2011-10-06 4:10 UTC (permalink / raw)
To: kernelnewbies
Hi Greg,
>
> How do you later remove a device created with this new interface? As it
> is, I think the existing calls will fail, right?
>
If I have not missed out anything from hwmon_device_unregister(), it shouldn't
fail. Why did you point that out?
-Himanshu
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] hwmon class driver registration with a device number
2011-10-06 4:10 ` Himanshu Chauhan
@ 2011-10-06 18:25 ` Greg KH
[not found] ` <20111006190752.GA28455@ericsson.com>
0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2011-10-06 18:25 UTC (permalink / raw)
To: kernelnewbies
On Thu, Oct 06, 2011 at 09:40:11AM +0530, Himanshu Chauhan wrote:
> Hi Greg,
>
> >
> > How do you later remove a device created with this new interface? As it
> > is, I think the existing calls will fail, right?
> >
> If I have not missed out anything from hwmon_device_unregister(), it shouldn't
> fail. Why did you point that out?
If you create a device with a call to device_create() with a dev_t set,
it is usually cleaned up with a call to device_destroy(), but you are
right, a simple call to device_unregister() will still work properly.
So nevermind, sorry for the noise.
What you do need to determine is if this is a device node you really
want to be creating in this manner, as it is a new user/kernel API,
right?
greg k-h
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <1317839407.3983.46.camel@groeck-laptop>]
* [PATCH] hwmon class driver registration with a device number
[not found] ` <1317839407.3983.46.camel@groeck-laptop>
@ 2011-10-06 4:06 ` Himanshu Chauhan
0 siblings, 0 replies; 9+ messages in thread
From: Himanshu Chauhan @ 2011-10-06 4:06 UTC (permalink / raw)
To: kernelnewbies
Hi,
> I can not comment on the merits of your patch. Unless I am missing
> something, which may well be since I only spent a couple of minutes on
> it, other device classes don't seem to provide a similar API, so I don't
> know if or why it would make sense for hwmon. Maybe a driver which wants
> to register a character device interface should do so independently of
> hwmon.
>
The idea here is to sit in the same class directory as of hwmon. Devices
registered with this interface will have "dev" under, for example,
/sys/class/hwmon/hwmon0/dev. To do the same inside the driver will be
a bit more involved than a call.
In my opinion other classes should also have similar interfaces.
> On the technical side, EXPORT_SYMBOL is missing.
>
I will take care of that.
Regards
Himanshu
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-10-07 15:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-05 17:13 [PATCH] hwmon class driver registration with a device number Himanshu Chauhan
2011-10-05 19:33 ` Greg KH
2011-10-06 4:10 ` Himanshu Chauhan
2011-10-06 18:25 ` Greg KH
[not found] ` <20111006190752.GA28455@ericsson.com>
2011-10-07 6:42 ` [lm-sensors] " Himanshu Chauhan
2011-10-07 6:52 ` Greg KH
2011-10-07 9:56 ` Himanshu Chauhan
2011-10-07 15:46 ` Greg KH
[not found] ` <1317839407.3983.46.camel@groeck-laptop>
2011-10-06 4:06 ` Himanshu Chauhan
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).