4
votes

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 ?

2

2 Answers

3
votes

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.)

0
votes

See when you register a device as a character device specifically then following thing happens:

Major Number is given in accordance. If you use any device depending on functionality whose registration is based on character device (like tty, input etc), then those will have their respective major number. Thats why its said that dont assign major number statically if not sure.

And

There are certain file operations which correspond to operations that could be performed on char devices only.

Do ask if any query.