User Tools

Site Tools





Getting started with Linux Device Drivers

I spent a lot of time, but still not enough, on understanding how to write device drivers for Linux. This subject is niche, it's hard to find a reliable knowledge source. Fortunately I've managed to understand enough to create basic driver, and it's time to write down everything what I've learned. It's not everything what should be known, but it's a good starting point.


Device drivers are specialized Linux modules, so if you know how to write Loadable Kernel Modules (LKM), you just need to learn driver specific rules, follow them, and you can start writing drivers soon. As you probably suppose, the trickiest part are these rules.

Before you start, learn how to browse through Kernel repository. A I said earlier: a reliable knowledge source doesn't exist, you have to rely on what others did, bot don't rely too much, some drivers are old and uses deprecated techniques. Raspbian repository might be even better place to browse, because I saw more new school drivers there.

Old school vs new school

Many years ago, nobody thought that majority of future embedded devices will be driven by Linux. We didn't have Raspberries, Beagleboards, HiKeys etc. The choice was quite limited, thus every platform had its special description file in Kernel repository. For example, take a quick look at this platform.c file. All these structures are board configurations read by system during boot. This approach is sufficient provided that your hardware configuration doesn't change. If you attach a new peripheral to your board, for example GPIO controller on SPI, you have to update this file and recompile the kernel. What if your board is very flexible, or some vendor produces 100 variants of the same board? It sound like a lot of unnecessary work.

This article is in progress

software/linux/drivers/getting_started.txt · Last modified: 2019/11/13 02:55 by itachi