Re: How to create "dev" files in sysfs?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx/msg08461.html
> http://www.mail-archive.com/kernelnewbies@xxxxxxxxxxxx/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

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux