up-board / up-community

92 stars 11 forks source link

ACPI overlays tutorial #11

Open fvillml opened 2 years ago

fvillml commented 2 years ago

Hello, I would like to set some GPIOs as CS for SPI. I managed to do this on Raspberry pi by using Device Tree overlays. As far as I know, this is a feature for arm platforms and as up boards are intel x86 platforms you use ACPI which is the equivalent. I have followed this instructions to enable spi devices using ACPI overlays (which you can find in this repository however I cannot find a way to add more cs by using gpios with acpi overlays. Do you have any tutorial on this or some information about how to do that?

fvillml commented 2 years ago

So I managed to create a new spidev device with ACPI overlays as follows:

/*
 * This ASL can be used to declare a spidev device on SPI0 CS2
 */
DefinitionBlock ("", "SSDT", 5, "INTEL", "SPIDEV2", 1)
{
    External (_SB_.PCI0.SPI1, DeviceObj)
    External (_SB_.PCI0.GIP0.GPO, DeviceObj)

    Scope (\_SB.PCI0.SPI1)
    {

        Name (_CRS, ResourceTemplate () {
            GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
                "\\_SB.PCI0.GIP0.GPO", 0) {
                    22 // pin 22 is BCM25 or 402 in linux
                } 
        })

        Name (_DSD, Package() {
            ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
            Package () {
                Package () { "compatible", "spidev" }, // not sure if this is needed
                Package () {
                    "cs-gpios", Package () {
                        0,
                        0,
                        ^SPI1, 0, 0, 0, // index 0 in _CRS -> pin 22
                    }
                },
            }
        })

        Device (TP2) {
            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,                // 10 MHz
                    ClockPolarityLow,       // SPI mode 0
                    ClockPhaseFirst,        // SPI mode 0
                    "\\_SB.PCI0.SPI1",      // SPI host controller
                    0                       // Must be 0
                )
            })
        }
    }
}

However, the CS on pin 22 is low all the time which shouldn't be the case. Perhaps I need to enable the GPIO somehow? is the number of the pin correct? I'm using pin numbering from here