Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

fbtft_device

notro edited this page May 2, 2013 · 17 revisions

Unlike PCI or USB devices, SPI and GPIO devices are not enumerated at the hardware level.
Instead, Linux must be told explicitly about these devices.

Typically the platform/board file contains this information.

This is an example from arch/arm/mach-bcm2708/bcm2708.c:

static struct spi_board_info bcm2708_spi_devices[] = {
    {
        .modalias = "spidev",
        .max_speed_hz = 500000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    }, {
        .modalias = "spidev",
        .max_speed_hz = 500000,
        .bus_num = 0,
        .chip_select = 1,
        .mode = SPI_MODE_0,
    }
};

This approach requires a kernel build to register this information.

Another approach is to use Device Tree, but this hasn't come to vanilla Raspian yet.

A third approach is to let a kernel module register the information.
fbtft_device was created for this purpose.

# List supported parameters
modinfo -p fbtft_device
name:Devicename (required). name=list lists supported devices. (charp)
busnum:SPI bus number (default=0) (uint)
cs:SPI chip select (default=0) (uint)
speed:SPI speed (used to override default) (uint)
mode:SPI mode (used to override default) (int)
gpios:List of gpios. Comma seperated with the form: reset:23,dc:24 (used to override default) (array of charp)
fps:Frames per second (used to override default) (uint)
txbuflen:txbuflen (used to override default) (int)
verbose:0=silent, 0< show gpios, 1< show devices, 2< show devices before (default) (uint)

Show supported devices

modprobe fbtft_device name=list
ERROR: could not insert 'fbtft_device': Operation canceled

# Show output
dmesg
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.0 500kHz 8 bits mode=0x00
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:  'fb' Platform devices registered:
fbtft_device:      bcm2708_fb id=-1 pdata? no
fbtft_device:  Supported drivers:
fbtft_device:      spidev
fbtft_device:      flexfb
fbtft_device:      ili9341fb
fbtft_device:      r61505ufb
fbtft_device:      adafruit22fb
fbtft_device:      adafruit18fb
fbtft_device:      adafruit18greenfb
fbtft_device:      sainsmart18fb
fbtft_device:      nokia3310fb
fbtft_device:      itdb28fb
fbtft_device:      flexpfb

Register adafruit22fb device with default values:

modprobe fbtft_device name=adafruit22fb
dmesg
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.0 500kHz 8 bits mode=0x00
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:  'fb' Platform devices registered:
fbtft_device:      bcm2708_fb id=-1 pdata? no
fbtft_device: Deleting spi0.0
fbtft_device:  GPIOS used by 'adafruit22fb':
fbtft_device:    'reset' = GPIO25
fbtft_device:    'led' = GPIO23
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:      adafruit22fb spi0.0 32000kHz 8 bits mode=0x00

Register sainsmart18fb with changes
SPI: spi0.1 at 16MHz
GPIOs: reset=18 (when overriding, all must be mentioned)

modprobe fbtft_device name=sainsmart18fb cs=1 speed=16000000 gpios=reset:18,dc:24
dmesg
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:  'fb' Platform devices registered:
fbtft_device:      bcm2708_fb id=-1 pdata? no
fbtft_device: Deleting spi0.1
fbtft_device:  GPIOS used by 'sainsmart18fb':
fbtft_device:    'reset' = GPIO18
fbtft_device:    'dc' = GPIO24
fbtft_device:  SPI devices registered:
fbtft_device:      sainsmart18fb spi0.1 16000kHz 8 bits mode=0x00

Tip: When using rmmod: just start writing the modulename and press TAB to get the full name.

A note on probe()

When loading a driver, it's init() function is called and the device(s) it supports is made known to the kernel.
If the device it supports is registered in the kernel, the drivers probe() function is called with the device as an argument.
So, loading a driver when the device is not present, will just sit there. It is loaded, but it won't do anything before the supported device is present.
A driver can support more than one device.

References

piwik

Clone this wiki locally