Uncategorized

Driver module and kernel module

-2

I want to load my kernel module which communicates with my device over spi interface. I have tried loading my modules but it’s showing spidev is already installed.

I see 2 modules named spidev and spi_bcm2835 already installed. Can I know what does these modules do and help me in running my use case?

Also, I have tried removing spidev module but only driver is getting registered but probe is not getting called.

 New contributor
  • 1
    I am confused. Raspbian stretch has built in SPI, IC, UART. So it is not necessary to load the kernel modules yourself. – tlfong01 May 31 at 13:33   
  • I am also confused of your use of the term “use case”. Are you talking “UseCase Analysis” using the “UML/SysML” language? I also don’t understand “probe not getting called”. All sounds scary to a SPI newbie like me. BTW the SPI newbie, ie, me is now learning how to build a SPI touch LCD kernel module. He finds building a SPI kernel module very very hardt, not to mention developing one! 🙂 raspberrypi.stackexchange.com/questions/98549/… – tlfong01 Jun 1 at 1:33   
  • My above link to SPI kernel module building tutorial by developer uju on GitHub is very newbie friendly, with detailed instruction and explanation on how to remove unwanted old SPI touch LCD kernel module and build your own new SPI touch LCD kernel module. Perhaps you can let us know more about your SPI kernel module, if it is also on GitHub. – tlfong01 Jun 1 at 3:26   
  • Newbie True or False Qustions: (1) A kernel module is a compiled code that can be inserted into the kernel at run-time. (2) A driver is a compiled code that runs in the kernel to talk to hardware device. (3) A large part of a running kernel is driver code. (4) A driver may be built statically into the kernel file on Rpi SD card. (4) A driver may also be built as a kernel module so that it can be dynamically loaded later. (5) Not all kernel modules are drivers. (6) Some drivers are kernel modules. (7) A device tree is a kernel tree. (8) A kernel tree is a device tree.– tlfong01 yesterday    
  • “I want to load my kernel module which communicates with my device over spi interface.” – I am very confused. Can you tell us what is your “device”? Is it an SPI ADC such as MCP3008, or a SPI IO thing, such as MCP23S17? – tlfong01 yesterday   

2 Answers

0

Congratulations on writing a kernel module. That is quite hard.

The only thing which loads SPI on a modern Linux system will be device tree. You need to search /boot/config.txt and comment out or remove all SPI related lines. I believe most such lines will contain spi. You then need to reboot.

  • “only thing” … for many drivers, you can bind devices to drivers via sysfs. – domen yesterday
  • @domen I didn’t know that. If you want edit my reply to add that information or post a link and I will add it. – joan yesterday
  • I read that to run/launch a kernel module, eg, the ili9341 SPI touch LCD kernel module, the “only thing” you need to do is edit the file /etc/rc.local, adding the following line: sudo /path/to/fbcp-ili9341/build/fbcp-ili9341 &– tlfong01 18 hours ago    

0

Question

  1. I want to load my kernel module which communicates with my device over spi interface. I have tried loading my modules but it’s showing spidev is already installed.
  2. I see 2 modules named spidev and spi_bcm2835 already installed. Can I know what does these modules do and help me in running my use case?
  3. Also, I have tried removing spidev module but only driver is getting registered but probe is not getting called.
  4. I’m very new to work on SPI as well as Raspberry. What do you mean by conflicting? Is there anything that I have to change in my driver?

Answer

Brief description of the OP’s question.

He has developed a kernel module and wishes to run in Rpi Raspbian with SPI interface. He found that Raspboian already has two drivers installed:

(1) spidev,

(2) spi_bcm2835.

He was wondering if he should

(a) remove those two SPI drivers, or

(b) interface with those two drivers.

/ to continue, …

References

/ to add later, …

Appendices

Appendix A – What is the difference between kernel drivers and kernel modules?

Reading notes

A kernel module is a bit of compiled code that can be inserted into the kernel at run-time, such as with insmod or modprobe.

A driver is a bit of code that runs in the kernel to talk to some hardware device. It “drives” the hardware. Most every bit of hardware in your computer has an associated driver. A large part of a running kernel is driver code.

A driver may be built statically into the kernel file on disk. A driver may also be built as a kernel module so that it can be dynamically loaded later. (And then maybe unloaded.)

Standard practice is to build drivers as kernel modules where possible, rather than link them statically to the kernel, since that gives more flexibility. There are good reasons not to, however:

Sometimes a given driver is absolutely necessary to help the system boot up. That doesn’t happen as often as you might imagine, due to the initrd feature.

Statically built drivers may be exactly what you want in a system that is statically scoped, such as an embedded system. That is to say, if you know in advance exactly which drivers will always be needed and that this will never change, you have a good reason not to bother with dynamic kernel modules.

If you build your kernel statically and disable Linux’s dynamic module loading feature, you prevent run-time modification of the kernel code. This provides additional security and stability at the expense of flexibility.

Not all kernel modules are drivers. For example, a relatively recent feature in the Linux kernel is that you can load a different process scheduler. Another example is that the more complex types of hardware often have multiple generic layers that sit between the low-level hardware driver and userland, such as the USB HID driver, which implements a particular element of the USB stack, independent of the underlying hardware

Appendix B – Example of a statically bound driver module

Reading Notes

To add the DS18B20 One Wire Temperature Sensor driver module to the device tree, add the following line in /boot/config.txt

dtoverlay=w1-gpio,gpiopin=14

Appendix C – Example of a dynamically bound kernel module

Reading notes

To launch the ILI9342 touch LCD kernel module at startup, add a line in the file /etc/rc.local

sudo /path/to/fbcp-ili9341/build/fbcp-ili9341 &

/ to continue, …

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: