1
votes

I've been tasked to import the spi driver into an existing platform running Openwrt.
After "successfully" build the full Openwrt: packages and the kernel matching the one running into the platform, including the spidev kernel module I run into some trouble in make this module work.
**insmod** of the driver terminates without error, and I see that in the **/sys/class** the creation of the directory **spidev**, but it is empty.
Looking at the code of the spidev kernel module, the function **probe** has caught my eye. My feel is that this function is what actually allocates the minor device number an make the device available to be used. But it's not clear to me who, or what should call it.
Another doubt I have is about the architecture. The spi depends on the underlaying architecture, which in my case is the MT7620 soc which is a mipsel architecture have a specific spi code. In my understanding this SOC specific code is wrapped by the spidev kernel module and the link between these two entities should be
status = spi_register_driver(&spidev_spi_driver);

in the

static int __init spidev_init(void)

function.
Again, I'm far to be sure of what I'm writing and I'm here asking for directions.

1
spidev is a raw driver to SPI bus. What you need to look is some drivers that are using module_spi_driver() macro. - 0andriy
Issue is still open by my side. I want to thank you to have casted some light in my lack of knowledge. I suspected spidev was not exactly what I were looking for. googling around I found some other piece of code which contains code that seem to be more specific regarding my platform. So said, the code I found does not have any init function so I wonder how could it work. By the way, the module obtained by its compilation, can be insmod without error, but it doesn't seem to produce any visible effect. Is there any dependence among spi modules (eg. with spidev.ko) to get them work? - Alessandro

1 Answers

0
votes

First, you may want to read the Linux Device Driver - Chapter 14.

Generally speaking, in the Linux kernel you have devices and drivers on a bus (subsystem). You have to register them using the functions register_device() and register_driver() (the exact name depends on the subsystem). When a device or a driver get registered the subsystem will try to match devices with drivers. If they match, the subsystem calls the driver's function probe(). So, the execution of the probe() function can be triggered by the driver registration or the device registration. This also means that the device exists before the execution of probe()

Back to your specific case: SPI. To register a device instance you need to use spi_alloc_device and spi_add_device, or spi_new_device. Where to put this code? This depends on your need. Typically, the SPI devices are declared in some architecture file or device-tree description. Probably you can also do it in a module (not sure).

The spidev is a Linux device driver that exports the SPI raw interface to the user-space. This means that once you register an SPI device instance the driver spidev take control of it. Actually, the spidev does nothing: it waits for an user-space program to read/write data on the SPI bus. So, you will end up writing the driver for your device in userspace.