Putting it all together
The steps needed to write SPI client drivers are as follows:
- Declare device IDs supported by the driver. You can do that using
spi_device_id
. If the DT is supported, useof_device_id
too. You can make an exclusive use of the DT. - Call
MODULE_DEVICE_TABLE(spi, my_id_table);
in order to expose the driver along with its SPI device table IDs to userspace. If the DT is supported, you must callMODULE_DEVICE_TABLE(of, your_of_match_table);
in order to expose OF (device tree) related module aliases to user space. The preceding calls toMODULE_DEVICE_TABLE
will export informations that will be collected bydepmod
to update the modules.alias file, thus allowing the driver to be automatically found and loaded if it is build as module. - Write
probe
andremove
functions according to their respective prototypes. Theprobe
function must identify your device, configure it, define per-device (private) data, configure the bus if needed (SPI mode and so on) using thespi_setup
function...