spidev Linux driver on Intel Atom board

烈酒焚心 提交于 2019-12-08 12:30:24

问题


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?


回答1:


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.




回答2:


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

In times when the device tree were not working, I used the following code (example based on beagle board, you should fix for your board accordingly):

arch/arm/mach-omap2/board-omap3beagle.c:

static struct spi_board_info my_spi_board_info[] = {
...
        {
                .modalias       = "spidev",
                .max_speed_hz   = 3000000, //48 Mbps
                .bus_num        = 3,
                .chip_select    = 1,
                .mode = 0,
        },
...
};

static void __init omap3_beagle_init(void)
{
...
   spi_register_board_info(my_spi_board_info,
                           ARRAY_SIZE(my_spi_board_info));
...
}

As you can see I specify "bus_num" omap CPU have several SPI, also I specify chipselect, and speed, after that I call spi_register_board_info, and after rebuild of kernel and reboot something like /dev/spidev3.1 appear.




回答3:


I found that Valley Island (Baytrail) BSP provides much better hardware support for Kontron SMARC than Kontron BSP. It comes with spidev and other drivers necessary to access Atom peripherals.

Not directly related to the question (just to inform those developing on SXBTI SMARC platform): there are couple of things required which are not part of this BSP: Ethernet and eMMC flash. The former can be added by enabling Intel IGB driver in kernel, the latter... I'm still trying to figure it out.



来源:https://stackoverflow.com/questions/39118721/spidev-linux-driver-on-intel-atom-board

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!