<br><br><div class="gmail_quote">On Thu, Jan 20, 2011 at 5:48 AM, Mulyadi Santosa <span dir="ltr"><<a href="mailto:mulyadi.santosa@gmail.com">mulyadi.santosa@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Guys...<br>
<br>
I believe it's one of the sample of a question that is well structured.<br>
<br></blockquote><div>Thanks Mulyadi,<br>I guess this can be put on newbies page, it its not already there.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
---------- Forwarded message ----------<br>
From: Arvid Brodin <<a href="mailto:arvid.brodin@enea.com">arvid.brodin@enea.com</a>><br>
Date: Wed, Jan 19, 2011 at 20:23<br>
Subject: How to create "dev" files in sysfs?<br>
To: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
<br>
<br>
Hello,<br>
<br>
How do I make my platform device a character device that<br>
can be handled by udev?<br>
<br>
Background:<br>
<br>
I've written a driver for a very simple platform device (a jumper<br>
connected to an input pin on the processor). Today I can read the status<br>
of the pin through a driver attribute file in sysfs at:<br>
<br>
/sys/devices/platform/msel/<br>
<br>
As a learning experience I want to get udev to detect this device and<br>
create a character device file under /dev for it, that I could read to<br>
get the pin status. If I understand correctly, udev looks for files<br>
named "dev" in sysfs, which contains the major and minor device numbers<br>
which udev use to create the device node.<br>
<br>
From the kernel code it seems that ((struct platform_device *)<br>
my_platform_device)->dev->devt would have to be set to contain the major<br>
& minor device numbers when the device is created for a "dev" file to<br>
appear, which is not possible in this case since the device is<br>
registered in board setup code where it seems wrong to get device<br>
numbers by calling call alloc_chrdev_region() (right?).<br>
<br>
I found a few previous questions about this same problem in these<br>
kernelnewbies threads:<br>
<br>
<a href="http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg08461.html" target="_blank">http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg08461.html</a><br>
<a href="http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg06807.html" target="_blank">http://www.mail-archive.com/kernelnewbies@nl.linux.org/msg06807.html</a><br>
<br>
Using that info, and looking at the hpet driver code, I initialised a<br>
struct miscdevice and called misc_register(). This gives me a<br>
/sys/class/misc/msel_chrdev/ folder with the required dev and<br>
uevent files. udev also picks up this and creates the corresponding file<br>
in /dev.<br>
<br>
<br>
Is this the correct way to do this? One "device" for the hardware and<br>
one or more "devices" for the userland interface(s)? Also, looking at my<br>
desktop system, there's one device under /sys/devices/platform that also<br>
has "dev" files:<br>
<br>
/sys/devices/platform/serial8250/tty/ttyS1/dev<br>
/sys/devices/platform/serial8250/tty/ttyS2/dev<br>
/sys/devices/platform/serial8250/tty/ttyS3/dev<br>
<br>
I notice that these "dev" files appear as subfolders under the platform<br>
device's own folder, and not under /sys/class/. Perhaps this is more<br>
correct? The source for 8250 is ~223K in 14 different files so I have<br>
not been able to decode how they do this.<br>
<br>
(Please CC me directly if you respond!)<br>
<br>
Thanks for reading all this,<br>
Arvid Brodin<br>
Enea Services Stockholm AB<br>
<br>
<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br>
<br>
<br>
--<br>
regards,<br>
<br>
Mulyadi Santosa<br>
Freelance Linux trainer and consultant<br>
<br>
blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>
training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a><br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br>