How to create "dev" files in sysfs?
Greg KH
greg at kroah.com
Wed Jan 19 10:34:45 EST 2011
On Wed, Jan 19, 2011 at 02:23:41PM +0100, Arvid Brodin wrote:
> Hello,
>
> How do I make my platform device a character device that
> can be handled by udev?
Have you read the Linux Device Drivers book about this very topic? If
not, I suggest you do so.
> Background:
>
> I've written a driver for a very simple platform device (a jumper
> connected to an input pin on the processor). Today I can read the status
> of the pin through a driver attribute file in sysfs at:
>
> /sys/devices/platform/msel/
>
> As a learning experience I want to get udev to detect this device and
> create a character device file under /dev for it, that I could read to
> get the pin status. If I understand correctly, udev looks for files
> named "dev" in sysfs, which contains the major and minor device numbers
> which udev use to create the device node.
>
> From the kernel code it seems that ((struct platform_device *)
> my_platform_device)->dev->devt would have to be set to contain the major
> & minor device numbers when the device is created for a "dev" file to
> appear, which is not possible in this case since the device is
> registered in board setup code where it seems wrong to get device
> numbers by calling call alloc_chrdev_region() (right?).
>
> I found a few previous questions about this same problem in these
> kernelnewbies threads:
>
> http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg08461.html
> http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg06807.html
>
> Using that info, and looking at the hpet driver code, I initialised a
> struct miscdevice and called misc_register(). This gives me a
> /sys/class/misc/msel_chrdev/ folder with the required dev and
> uevent files. udev also picks up this and creates the corresponding file
> in /dev.
Great.
> Is this the correct way to do this? One "device" for the hardware and
> one or more "devices" for the userland interface(s)?
Yes.
But you might want to rethink a char device for your user interface, as
it doesn't sound like it fits very well. What about the GPIO interface
instead?
thanks,
greg k-h
More information about the Kernelnewbies
mailing list