I’ve made my first foray into the kernel, by writing a kernel module for the TSIC 306 temperature sensor. After overcoming the difficulties in setting up the tools, the actual driver development was much easier than expected. The source code is up on Google Code and is basically working, but needs a little more development.
This maps the sensor to the file-system, so you can load the module and read the temperature like this:
$ sudo insmod tsic.ko $ cat /sys/kernel/tsic/temp 14680
In the example above, the temperature is 14.68°C and all the values are scaled by 1000 to avoid floating point maths in the module, and to match the behaviour of existing sensors such as:
$ cat /sys/class/thermal/thermal_zone0/temp 40084
Writing the module turned out to be easier than expected, and there are some great libraries such as gpiolib and kobject which simplify development. Documentation is a bit scarce, but there are some useful resources:
Eventually I plan to add support for multiple sensors on configurable GPIO pins, make it more robust and clean up a few issues such as the lack of time-outs in the I/O.