Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: acpi: Explain how to get GPIO descriptors in ACPI case

Documentation lacks of explanation how we actually use device properties
for GPIO resources.

Add a section to the documentation about that.

Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Andy Shevchenko and committed by
Linus Walleij
ed7fcf1e 6fe9da42

+65
+65
Documentation/acpi/gpio-properties.txt
··· 156 156 routine. On removal, the driver should unregister its GPIO mapping table by 157 157 calling acpi_dev_remove_driver_gpios() on the ACPI device object where that 158 158 table was previously registered. 159 + 160 + Using the _CRS fallback 161 + ----------------------- 162 + 163 + If a device does not have _DSD or the driver does not create ACPI GPIO 164 + mapping, the Linux GPIO framework refuses to return any GPIOs. This is 165 + because the driver does not know what it actually gets. For example if we 166 + have a device like below: 167 + 168 + Device (BTH) 169 + { 170 + Name (_HID, ...) 171 + 172 + Name (_CRS, ResourceTemplate () { 173 + GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone, 174 + "\\_SB.GPO0", 0, ResourceConsumer) {15} 175 + GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone, 176 + "\\_SB.GPO0", 0, ResourceConsumer) {27} 177 + }) 178 + } 179 + 180 + The driver might expect to get the right GPIO when it does: 181 + 182 + desc = gpiod_get(dev, "reset", GPIOD_OUT_LOW); 183 + 184 + but since there is no way to know the mapping between "reset" and 185 + the GpioIo() in _CRS desc will hold ERR_PTR(-ENOENT). 186 + 187 + The driver author can solve this by passing the mapping explictly 188 + (the recommended way and documented in the above chapter). 189 + 190 + The ACPI GPIO mapping tables should not contaminate drivers that are not 191 + knowing about which exact device they are servicing on. It implies that 192 + the ACPI GPIO mapping tables are hardly linked to ACPI ID and certain 193 + objects, as listed in the above chapter, of the device in question. 194 + 195 + Getting GPIO descriptor 196 + ----------------------- 197 + 198 + There are two main approaches to get GPIO resource from ACPI: 199 + desc = gpiod_get(dev, connection_id, flags); 200 + desc = gpiod_get_index(dev, connection_id, index, flags); 201 + 202 + We may consider two different cases here, i.e. when connection ID is 203 + provided and otherwise. 204 + 205 + Case 1: 206 + desc = gpiod_get(dev, "non-null-connection-id", flags); 207 + desc = gpiod_get_index(dev, "non-null-connection-id", index, flags); 208 + 209 + Case 2: 210 + desc = gpiod_get(dev, NULL, flags); 211 + desc = gpiod_get_index(dev, NULL, index, flags); 212 + 213 + Case 1 assumes that corresponding ACPI device description must have 214 + defined device properties and will prevent to getting any GPIO resources 215 + otherwise. 216 + 217 + Case 2 explicitly tells GPIO core to look for resources in _CRS. 218 + 219 + Be aware that gpiod_get_index() in cases 1 and 2, assuming that there 220 + are two versions of ACPI device description provided and no mapping is 221 + present in the driver, will return different resources. That's why a 222 + certain driver has to handle them carefully as explained in previous 223 + chapter.