6
votes

I am currently reading the Linux Module Programming Guide and I have stumbled onto two terms that have confused a bit - device files and device driver. Upon goggling these terms I have come across the following-

A device driver is a piece of software that operates or controls a particular type of device.

A device file is an interface for a device driver that appears in a file system as if it were an ordinary file. In Unix-like operating systems, these are usually found under the /dev directory and are also called device nodes.

What I would like to know is -

1) Are device files an interface between user space programs and the device driver? 2) Does the program access the driver in the kernel via the appropriate device special file?

eg, when using say spidev char dev file, does that allow my userspace program to interact with spi.c and omap2_mcspi.c etc using simple read, write and ioctl calls?

3

3 Answers

7
votes

One of the primary abstractions in Unix is the file (source):

Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.

This lets users treat a variety of entities with a uniform set of operations, even through the implementation of those operations may be wildly different.

As you were getting at with your question, device files are the user facing side of the abstraction. This is what the user sees; a file that they can write to, read from, open, close, etc. The device drivers are the implementation of those operations.

So the user will make a call to a file operation such as write, and then the kernel will then use the device driver to carry out the operation.

0
votes

Device File like /dev/spidevX.Y is a SW abstraction of a SPI device which exposes Linux low level SPI API to the userspace with syscalls (in Linux driver world known as "file operations"):

That is read(), write(), ioctl()...

spidev.c is a special kind of driver which is registered for generic SPI client(chip) devices, and it's main goal is to export Kernel low level SPI API to userspace.

There is a whole Linux SPI layer in between defined in spi.c

Device driver representing real HW SPI controller is where callbacks (hooks) are implemented and registered to the kernel as a part of spi_master (spi_controller)structure. Here is a callback initialization for SPI message transfer:

master->transfer_one_message = atmel_spi_transfer_one_message;
-2
votes

everything in linux is a file. device driver is a software used by operating system to communicate with device. device driver makes use of device files.