All of lore.kernel.org
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: How to create "dev" files in sysfs?
Date: Wed, 19 Jan 2011 07:34:45 -0800	[thread overview]
Message-ID: <20110119153445.GA30975@kroah.com> (raw)
In-Reply-To: <4D36E5DD.2000903@enea.com>

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 at nl.linux.org/msg08461.html
> http://www.mail-archive.com/kernelnewbies at 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

      reply	other threads:[~2011-01-19 15:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 13:23 How to create "dev" files in sysfs? Arvid Brodin
2011-01-19 15:34 ` Greg KH [this message]

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=20110119153445.GA30975@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.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.