What is the difference between misc drivers and char drivers?
Edit: I thought you were talking about drivers/misc
drivers, but I see you're refering to character drivers using misc_register
(and all the API in drivers/char/misc.c
). You should specify this in your question.
In this case, the misc
API seems to make your life easier when you're writing a small character driver and do not want to need to allocate a new major number only to use one minor number, for example. It simplifies things, but all the file operations are still available using the fops
member of struct miscdevice
. The basic difference is you only get one minor number per misc
device.
My previous, unrelated answer was, for the record:
Have a quick look at drivers/misc
: you won't find any "misc
core" out there. This means: misc
is not a device class; it's just a bunch of drivers that don't fit in any other category. Things like barometers, DACs, test suites and other strange things.
Look at the top of drivers/misc/Kconfig
:
## Misc strange devices#menu "Misc devices"
All the items in this Kconfig do not depend on any "misc
core", but on other cores (i2c
, pci
, tty
, etc.). Usually, when a driver is really using a driver core, you will see it in its Kconfig. For instance, pretty much all leds
drivers (drivers/leds
) depend on the leds
class core and have this in their Kconfig node:
depends on LEDS_CLASS
Maybe misc
drivers are all character drivers (I didn't check all of them), but something else would still work there, although it would probably be at the wrong place. I believe that lots of misc
drivers could be moved to better places now... a veteran kernel hacker could confirm this.
So, to answer your question: misc
drivers do not have to be character drivers, so the two categories are completely unrelated. A misc
driver brings nothing more than a character driver because a misc
driver is, again, nothing special.
Update: the Honeywell compass driver is a great example. It is small and straightforward.
It communicates with the actual compass using I²C. This device won't show up as a character device, so forget about major number 10. It will, however, appear somewhere in Sysfs, under /sys/bus/i2c/devices
, like all I²C devices do. And you will see the Sysfs attributes it adds to its group, like heading0_input
that will show the current compass direction when read.
So here you have it: a misc
driver that's not a character driver.
Now this seems to say that misc drivers are just char drivers, but perhaps a subset of functions, and char drivers can have more than one entry point (such as an ioctl() or an open() or a read() call)
Yes,it just Charater driver, and Misc driver also have multiple entry point read(), write(), ioctl() (because in miscdevice 's structure already have filefile_operations structure)
in my understanding, when we need to write a small driver (only have one entry point or some more (2,3,... entry points) <<< mean small driver) we should use misc driver. it will prevent waste of RAM if we register new Major Number.
Now Since the kernel keeps a static table of device drivers, frivolous allocation of major numbers is rather wasteful of RAM. The Linux kernel, therefore, offers a simplified interface for simple drivers—those that will register a single entry point. Note that, in general, allocating the whole name space of a major number to every device is beneficial. This allows the handling of multiple terminals, multiple serial ports and several disk partitions without any overhead in the kernel proper: a single driver takes care of all of them, and uses the minor number to differentiate.