I'm reading about misc drivers in Linux, and I'm a little confused about the differences between them and char drivers. One source, the Linux journal, writes:
Alessandro tells us how to register a small device needing a single entry point with the misc driver.
Sometimes people need to write “small” device drivers, to support custom hacks—either hardware or software ones. To this end, as well as to host some real drivers, the Linux kernel exports an interface to allow modules to register their own small drivers. The misc driver was designed for this purpose.
Ok, so from this I get that there's a simple driver (in this case with a single entry point), that's a misc driver. Then another source, Essential Linux Device Drivers, states:
Misc (or miscellaneous) drivers are simple char drivers that share certain common characteristics. Because misc drivers are char drivers, the earlier discussion on char driver entry points hold for misc drivers, too.
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)
So, what, in Linux C coding terms, are the differences between a char and misc device driver? (Besides the obvious major number assignment (10) for all misc drivers). Is there a difference in supported entry points? Is my assumption correct that misc device drivers only have a subset of what you can get in a full char device driver?
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.