简体   繁体   中英

How to configure ACPI *.asl for a virtual mdio-gpio device connected to a I2C gpio expander

I'm working with a Q7 Module (x86) and try to configure our peripherals with ACPI SSDT Overlay on Linux. But I strugle with it. I think I missunderstand some of the core concept of ACPI.

Problem

CPU -> I2C -> PCA9575 GPIO Expander -> virtual,mdio-gpio -> Ethernet Phy

What works

DefinitionBlock ("abc.asl", "SSDT", 2, "test", "HAL", 2)
{
    External (\_SB_.PCI0.D01D, DeviceObj)

    Scope (\_SB.PCI0.D01D)
    {
        Device (ABC0)
        {
            Name (_HID, "PRP0001")                      // must be PRP0001 that linux searches for compatible driver
            Name (_CRS, ResourceTemplate () {
                        I2cSerialBusV2 (
                                0x20,                  // SlaveAddress    : I2C Address
                                ControllerInitiated,   // SlaveMode       : ControllerInitiated
                                100000,                // ConnectionSpeed : max Bus Speed for this device
                                AddressingMode7Bit,    // AddressingMode  : Adress Mode
                                "\\_SB.PCI0.D01D",     // ResourceSource  : I2C host controller
                                0x00,                  // ResourceSourceIndex : must be 0
                                ResourceConsumer,      // ResourceUsage   : must be ResourceConsumer
                                ,                      // DescriptorName  : optional name for integer value which is an offset to a buffer field...
                                Exclusive              // Shared          : Shared or Exclusive
                                ,)                     // VendorData      : optional field                                
            })

            Name (_DSD, Package() {
                    ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
                    Package () {
                            Package (2) { "compatible", "nxp,pca9575"  },
                            Package ()  { "gpio-line-names", Package ()
                                                        {       "LED_Red",
                                                                "",
                                                                "MDC",
                                                                "MDIO",
                                                        }
                                        },
                        },
                    ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
                    Package () {
                        Package () { "led-red",   "LED0" },
                        Package () { "mdc-gpios",  "MDC0" },
                        Package () { "mdio-gpios", "MDIO" },
                    }
            })

            Name (LED0, Package () {
            ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
            Package () {
                Package () {"gpio-hog", 1},
                Package () {"gpios", Package () {0, 1}},
                Package () {"output-low", 1},
              }
            })

... <placeholder for virtual,mdio-gpiocode here> ...

        }
    }
}

It recognises the PCA9575 GPIO expander and registering it as gpiochip in Linux. The LED is fixed to low and "hogged". It seems that this part is not totally wrong.

What not works

I inserted this code into the placeholder

Device (MD00)
        {
            Name (_HID, "PRP0001")                      // must be PRP0001 that linux searches for compatible driver

            Name (_DSD, Package() {
                    ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
                    Package () {
                            Package (2) { "compatible", "virtual,mdio-gpio" },
                            Package () {"gpios", Package () {^MDC0, 2, 0, 
                                                             ^MDIO, 3, 0,}},
                            }
            })
        }

But when I try to load this file via configfs I can see an error message in dmesg that the compatible field for the defined resource in _CRS field is missing. But I don't even defined a _CRS field.

I'm also not sure if my GPIO's are defined correctly. I'm not able to set the Pull-Modes with the Package () {"gpios", Package () {0, 1}}, command.

I question myself, shall the GPIO Expander Ports again defined as GgioIo Structures in the MDO Device?

Name (_CRS, ResourceTemplate () {
        GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
                "\\_SB.PCI0.D01D.ABC0", 0, ResourceConsumer) {2}
        GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
                "\\_SB.PCI0.D01D.ABC0", 0, ResourceConsumer) {3}
    })

It doesn't seem to work either and I'm confused. I'm not sure if I use the GPIO PCA9575 driver correctly. Where could I configure the pull bias in ACPI? The driver load the config from of_ but I don't know where to define it in ACPI. I hope somebody here got an idea.

First of all let's see the main architecture of the design:

+-------------------+
|  HOST             |       +------+
|              MDIO <------>+ MDIO |
|              Intf |       | Phy  |
|                   |       +--^---+
| +------+          |          |       +-----+
| | I²C  |          |          |       | LED |
| | host |          |          |       +--^--+
| +--^---+          |          |          |
|    |              |       +--+---+      |
+-------------------+       | I²C  |      |
     +----------------------> GPIO +------+
                            +------+

From this schematic we see how devices are related to each other. Now let's move to ACPI representation. At the beginning we need to define I²C GPIO expander. From the examples in meta-acpi project we can find how PCA9535 can be described. Assuming we found the I²C host controller device ( \_SB_.PCI0.D01D as per your post) and the fact that you have expander without latching IRQ events, the following is the mix between original ASL excerpt and how to match it with proper configuration in the driver:

Device (ABC0)
{

    Name (_HID, "PRP0001")
    Name (_DDN, "NXP PCA9575 GPIO expander")

    Name (RBUF, ResourceTemplate()
    {
        I2cSerialBusV2(0x0020, ControllerInitiated, 400000,
            AddressingMode7Bit, "\\_SB.PCI0.D01D",
            0x00, ResourceConsumer, , Exclusive, )
    })

    Name (_DSD, Package () {
        ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
        Package () {
            Package () {"compatible", "nxp,pca9575"},
            Package () {"gpio-line-names", Package () {
                "LED_Red",
                "",
                "MDC",
                "MDIO",
            }},
        }
    })

    Method (_CRS, 0, NotSerialized)
    {
        Return (RBUF)
    }

    Method (_STA, 0, NotSerialized)
    {
        Return (0x0F)
    }
}

This excerpt provides us a new GPIO chip in the system, resources of which can be consumed by others.

For example, in your Virtual MDIO Phy case (see _DSD Device Properties Related to GPIO as well)

Device (MD00)
{
    Name (_HID, "PRP0001")

    Name (_CRS, ResourceTemplate () {
        GpioIo (Exclusive, PullDown, 0, 0, IoRestrictionOutputOnly,
            "\\_SB.PCI0.D01D.ABC0", 0, ResourceConsumer) {2} // pin 2
        GpioIo (Exclusive, PullDown, 0, 0, IoRestrictionOutputOnly,
            "\\_SB.PCI0.D01D.ABC0", 0, ResourceConsumer) {3} // pin 3
    })

    Name (_DSD, Package() {
        ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
        Package () {
            Package () { "compatible", "virtual,mdio-gpio" },
            Package () {
                "gpios", Package () {
                    ^MD00, 0, 0, 0, // index 0 in _CRS -> pin 2
                    ^MD00, 1, 0, 0, // index 1 in _CRS -> pin 3
                }
            },
        }
    })
}

Now it is a time to look at the LED binding code. For the sake of clarification hogging is when you want a GPIO provider to consume a resource itself. And it is quite likely not your case. Better is to connect this with the LED GPIO driver:

Device (LEDS)
{
    Name (_HID, "PRP0001")
    Name (_DDN, "GPIO LEDs device")

    Name (_CRS, ResourceTemplate () {
        GpioIo (
            Exclusive,                  // Not shared
            PullUp,                     // Default off
            0,                          // Debounce timeout
            0,                          // Drive strength
            IoRestrictionOutputOnly,    // Only used as output
            "\\_SB.PCI0.D01D.ABC0",     // GPIO controller
            0)                          // Must be 0
        {
            0,                          // LED_Red
        }
    })

    Name (_DSD, Package () {
        ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
        Package () {
            Package () { "compatible", Package() { "gpio-leds" } },
        },
        ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
        Package () {
            Package () { "led-0", "LED0" },
        }
    })

    /*
     * For more information about these bindings see:
     * Documentation/devicetree/bindings/leds/common.yaml,
     * Documentation/devicetree/bindings/leds/leds-gpio.yaml and
     * Documentation/firmware-guide/acpi/gpio-properties.rst.
     */
    Name (LED0, Package () {
        ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
        Package () {
            Package () { "label", "red" },
            Package () { "default-state", "on" },
            Package () { "gpios", Package () { ^LEDS, 0, 0, 1 } }, // active low
        }
    })
}

Also you may look into similar questions (starting from the given link and there are references to the rest) on StackOverflow site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM