porting driver 2.4 -> 2.6, confused by device model

Greg KH greg at kroah.com
Sat Feb 24 00:34:57 CST 2007


On Fri, Feb 23, 2007 at 11:03:04PM -0700, Sebastian Kuzminsky wrote:
> Greg KH <greg at kroah.com> wrote:
> > If you really want to do this on your own, see the chapter about the
> > driver model in the book, Linux Device Drivers, third edition, online
> > for free, that talks about how to hook up your code to let udev work
> > properly.
> > 
> > Note that the book is a bit out of date, and the functions that it tells
> > you to use there are no longer present.  Instead use the device_create()
> > functions.
> 
> Ok, that helps thanks!
> 
> Now in my driver, I detect the cards, request their IO ports and IRQs,
> then do this:
> 
>     alloc_chrdev_region();
> 
>     cdev_init();
>     cdev.owner = THIS_MODULE;
>     cdev_add();
> 
>     class_create();
> 
>     for each card:
>         for each feature of card:
>             device_create();
> 
> 
> Seem reasonable?

Yes.

> One thing I'm not sure how to do, I'd like to group the device files
> in directories.  Something like /dev/dmm/cardX/adcY.  How do I create
> the directories?

Create a udev rule that adds them in a subdirectory.  See the rule that
creates the /dev/bus/usb/BUS_NUM/DEVICE_NUM directories for an example
of one way to do this.

Hope this helps,

greg k-h


More information about the Kernel-mentors mailing list