1

I am looking for how to use the SPI bitbang driver provided in Linux kernel, commonly known as spi-gpio.c.

I have compiled it to a valid *.ko file, first inserted the spi-bitbang driver and now I have inserted the spidriv.c driver that I made and compiled from spi-gpio.c. All goes without a hitch, no errors in dmesg | tail however I cannot find any record of the SPI device I just added existing aside from an entry of my SPI driver in /sys/modules.

Frankly, this is ridiculous because every article I read says to use this and that it is "easy" however with the amount of time I have so far invested I could have written my own driver for an SPI device.

To elaborate how do I use this driver to get an entry in /dev aside from the obvious and simple instructions given in the kernel driver itself because they apparently do not register any kind of device.

What I've tried: Using spi-bitbang driver

My custom SPI driver:

// led  sck  sda  rst   a0   cs    w    h
// 332, 329, 330, 335, 336, 338, 128, 160

#define DRIVER_NAME     "spidriv"

#define SPI_MISO_GPIO   334
#define SPI_MOSI_GPIO   330
#define SPI_SCK_GPIO    329
#define SPI_N_CHIPSEL   338

#include "spi-gpio.c"

My install process:

$ sudo rmmod spi_bitbang 
$ sudo modprobe spi_bitbang
$ sudo insmod spidriv.ko
# No (recent) errors in dmesg
$ lsmod | grep spi
spidriv                16384  0  # My driver
spi_bitbang            16384  1 spidriv
spi_pxa2xx_platform    28672  0

Nothing is in /sys/class/spi* or /dev* after install the kernel module.

I have heard rumors of having to create a device tree entry, if I need to do this please help me step-by-step as I have never interfaced with the device tree system in Linux (despite being a long time Linux user and even writing my own basic kernel modules) and documentation seems non-existent or so overly complicated that it is incomprehensible!

This project has took me weeks (literally just connecting a ST7735 display to my homemade WiFi router) and this is driving me nuts, I wrote my own bit-banged SPI C library but it is simply not fast enough and I need a kernel level SPI interface to really get the bandwidth up.

artless noise
  • 21,212
  • 6
  • 68
  • 105
Jeremiah
  • 99
  • 1
  • 9
  • If there is no device file, then your driver module failed to create one in its entry routine. Without any code it's hard to offer advice. – stark Mar 30 '23 at 12:30
  • The code is all there, It all comes from spi-gpio.c which is part of the linux kernel: https://github.com/torvalds/linux/blob/master/drivers/spi/spi-gpio.c – Jeremiah Mar 30 '23 at 12:34
  • Try the two `echo` commands listed here: https://www.kernel.org/doc/html/latest/spi/spidev.html – stark Mar 30 '23 at 13:11
  • None of the other files exist, except for ` /sys/bus/spi/drivers/spidev/bind` (obviously since this does not rely on having an SPI device to work), and I tried all of the mentioned echo commands on it and nothing but IO errors. – Jeremiah Mar 30 '23 at 18:26
  • I ended up just writing my own SPI bitbang driver instead, frankly it was easier and quicker then getting the "built-in" one to work. I was also able to add in some key performance optimizations specifically for the SPI device I am working with. I will leave this open and continue to test the solutions so then there will be a guide in case anyone else tries to do this. – Jeremiah Mar 30 '23 at 18:31
  • 1
    @Jeremiah, it's good you have a progress, but bad that you may not upstream it :-( And no-one will benefit, because upstream already has a driver (as you have noticed) and the idea is to improve existing code (in most cases) rather than duplicate. – 0andriy Apr 02 '23 at 19:42
  • 1
    The use of the bitbang GPIO driver with the hardcoded values is well outdated. It's not supported anymore and that documentation should be amended. What you are suppose to have is properly formed device tree. – 0andriy Apr 02 '23 at 19:47
  • 1
    That aid, it seems you didn't get what has to be done, because you used outdated documentation most likely without looking into the implementation. – 0andriy Apr 02 '23 at 19:48
  • @0andriy I get that, and I would love to use the device tree to do what as I need, but unlike a kernel module with a simple character device file and some module options the device tree is completely undocumented and the only sources on how to use it are just "use the device tree" without providing any examples or any information on how I can work with and experiment with the device tree. – Jeremiah Apr 05 '23 at 10:10
  • 1
    I'm a bit puzzled. Does your system **not** utilising Device Tree already?! Ah, with the `lsmod` output and GPIO numbers it seems you are using some of x86 based platform. Am I right? Can you provide more details about platform you are using and I perhaps can suggest you a solution. – 0andriy Apr 07 '23 at 12:07
  • Gladly, it is Atomic Pi - Intel Atom(TM) x5-Z8350 development board I got off eBay for dirt cheap. – Jeremiah Apr 24 '23 at 04:15

0 Answers0