Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

spidev Linux driver on Intel Atom board

I am working on bringing up SPI on Kontron's Atom-based SMARC-sXBTi board under Linux.

Kontron provided Yocto BSP but it does not include SPI driver.

I rebuilt Linux with SPI support. I can see the SPI controller in lspci and in sysfs the SPI PCI device is bound to pca2xx_spi_pci driver.

As I understand this is a platform driver which does not expose user mode API and I need spidev to be able to work via /dev/spidev but when I modeprobe spidev I don't see anything happening: no file added to /dev, nothing in dmesg.

Do I need to configure spidev? The BSP does not include device tree. How can spidev find and talk to its PCI SPI controller?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First of all why do you need SPI device node to be exposed to user space?

I could imagine two possibilities:

  1. You are creating IoT software that will use user-space driver
  2. You are experimenting with different devices (that apparently have no kernel space drivers yet)

In any case:

  • according to Mark Brown (maintainer of SPI subsystem in the kernel):

    spidev should never appear directly in ACPI or DT since our ideas about the best way to control the hardware may change.

    See full discussion for the details.

  • Nevertheless Mark applied support for special SPI node in ACPI to expose spidev which you may use

  • Since the firmware is hardly to be changed for existing boards on market, you need to upgrade ACPI tables in OS. Some of engineers currently are working on a mechanism how to make this stuff easier for people. For now you may try latest vanilla kernel, let's say v4.8-rc3 as for this writing, and take an excerpt to enable SPI device (this is just an example, you need to adjust it regarding to the hardware in use):

   /*
    * Intel Joule
    *
    * This adds an SPI test device to the SPI host controller available on
    * Intel Joule breakout #1 header:
    *
    *   pin name           pin number
    *   -----------------------------
    *   SPI_1_MISO_LS      2
    *   SPI_1_MOSI_LS      4
    *   SPI_1_FS2_LS       8
    *   SPI_1_CLK_LS       10
    *
    * In Linux you need to set CONFIG_SPI_SPIDEV=y (or m) to be able to use
    * this device.
    */
DefinitionBlock ("spidev.aml", "SSDT", 5, "INTEL", "SPIDEV", 1)
{
  External (_SB_.PCI0.SPI2, DeviceObj)

  Scope (\_SB.PCI0.SPI2)
    {
        Device (TP0) {
            Name (_HID, "SPT0001")
            Name (_DDN, "SPI test device connected to CS2")
            Name (_CRS, ResourceTemplate () {
                SpiSerialBus (
                    2,                      // Chip select
                    PolarityLow,            // Chip select is active low
                    FourWireMode,           // Full duplex
                    8,                      // Bits per word is 8 (byte)
                    ControllerInitiated,    // Don't care
                    1000000,                // 1 MHz
                    ClockPolarityLow,       // SPI mode 0
                    ClockPhaseFirst,        // SPI mode 0
                    "\_SB.PCI0.SPI2",      // SPI host controller
                    0                       // Must be 0
                )
            })
        }
    }
}

Since you didn't point to the exact specifications you might need to do an additional work. For older Atoms the vanilla Linux kernel lacks of one patch to propagate ACPI handle to the platform driver.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...