Search code examples
linuxlinux-device-driver

Linux Device Driver Registration procedure


I am a linux newbie, trying to understand Linux Device Model. I had been going through Linux 3.1.6 code base, particularly the driver part and found that

  1. some of the drivers were using (for example i2c-bus device : linux-3.1.6/drivers/i2c/i2c-dev.c) *register_chrdev()* and
  2. few others (for example pci bus : linux-3.1.6/drivers/pci/bus.c) were using *device_register()*.

My question is when to use register_chrdev (yes, I know its for a character device, but why not use device_register) and device_register ?

Does that depend on where does the driver developer wants his device/driver to be listed down, like devfs vs sysfs ? Or the interface exposed to the user space to access the device ?


Solution

  • One function registers a character device association (hooking up major:minors to your function), the other just creates an abstract device object (only), so to speak. The two are complementary. The device object is used for the generation of an event so that udev can, if there is also a cdev association registered, create a node in /dev. (Compare with, for example, drivers/char/misc.c.)