0

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?

jackhab
  • 17,128
  • 37
  • 99
  • 136
  • Please, elaborate what the exact specification of board in use. – 0andriy Aug 24 '16 at 11:17
  • @Andy: added board spec – jackhab Aug 24 '16 at 12:38
  • Hmm... Didn't see anything except name. Shall we all google for it? – 0andriy Aug 24 '16 at 12:58
  • Okay, I checked the manuals and have questions. 1. Why do you use PCI enumeration enabled instead of ACPI? 2. Can you switch to ACPI (In LPSS & SCC menu), boot and gather acpidump, and then share it? – 0andriy Aug 24 '16 at 13:13
  • @AndyShevchenko Thanks a lot for the elaborate support! 1. I have no particular reason to prefer PCI enumeration over ACPI, it's what was enabled by default in the BIOS. 2. I'll be able to get acpidump next week. Two questions back. 1. Is ACPI considered to be superior to PCI enumeration? 2. I would expect Atom SoC to have out of the box driver support on such a universal OS as Linux is today. After all this platform is far from being esoteric or new. The Kontron board is new but all its peripherals come from the SoC. Am I missing something? – jackhab Aug 25 '16 at 04:44
  • 1. Yes, ACPI provides a lot of data that PCI doesn't have by design. Though you may still use PCI enumeration with ACPI tables. In that case you have to be sure that driver supports such a case. For BayTrail not all device drivers are supporting as you may notice. It was initially promoted as ACPI-enabled platform. 2. See answer to the first question. Drivers usually least problems when firmware provides all necessary information itself. – 0andriy Aug 25 '16 at 11:08
  • @AndyShevchenko here is the acpidump https://www.dropbox.com/s/rnbivhgbyrreun5/xbti-smarc-acmpidump.dat?dl=0 – jackhab Aug 29 '16 at 08:29

3 Answers3

2

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.

0andriy
  • 4,183
  • 1
  • 24
  • 37
  • As to "why?" - this is an embedded system board which is supposed to connect to IC devices which have not been finalized yet and may change in the future. ...and since I have zero-knowledge in ACPI - is this the only way to get spidev going? – jackhab Aug 24 '16 at 13:21
  • Great advertisment for ARM. – user1244932 Aug 24 '16 at 15:05
  • @jackhab, for ACPI enabled boards, the proper way, yes. Though, you may create an ugly hack as suggested in the other answer. – 0andriy Aug 24 '16 at 23:24
  • @user1244932, and how arm is different to x86 in SPI device node? Seems you quite out of topic. – 0andriy Aug 25 '16 at 01:24
  • @AndyShevchenko On arm you just edit DTS to point that this device should be handled by spidev, and that's all, you no need hack firmware. It seems that you quite out of topic – user1244932 Aug 25 '16 at 07:49
  • @user1244932, and how the mentioned excerpt and mechanism is different to DTS overlays? P.S. Read again the discussion with Mark Brown I pointed to. *spidev* is a hack and should not be used at all. – 0andriy Aug 25 '16 at 11:10
0

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.

fghj
  • 8,898
  • 4
  • 28
  • 56
0

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.

jackhab
  • 17,128
  • 37
  • 99
  • 136