~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/firmware-guide/acpi/gpio-properties.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/firmware-guide/acpi/gpio-properties.rst (Version linux-6.12-rc7) and /Documentation/firmware-guide/acpi/gpio-properties.rst (Version linux-5.2.21)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 ======================================              3 ======================================
  4 _DSD Device Properties Related to GPIO              4 _DSD Device Properties Related to GPIO
  5 ======================================              5 ======================================
  6                                                     6 
  7 With the release of ACPI 5.1, the _DSD configu      7 With the release of ACPI 5.1, the _DSD configuration object finally
  8 allows names to be given to GPIOs (and other t      8 allows names to be given to GPIOs (and other things as well) returned
  9 by _CRS.  Previously, we were only able to use      9 by _CRS.  Previously, we were only able to use an integer index to find
 10 the corresponding GPIO, which is pretty error      10 the corresponding GPIO, which is pretty error prone (it depends on
 11 the _CRS output ordering, for example).            11 the _CRS output ordering, for example).
 12                                                    12 
 13 With _DSD we can now query GPIOs using a name      13 With _DSD we can now query GPIOs using a name instead of an integer
 14 index, like the ASL example below shows::          14 index, like the ASL example below shows::
 15                                                    15 
 16   // Bluetooth device with reset and shutdown      16   // Bluetooth device with reset and shutdown GPIOs
 17   Device (BTH)                                     17   Device (BTH)
 18   {                                                18   {
 19       Name (_HID, ...)                             19       Name (_HID, ...)
 20                                                    20 
 21       Name (_CRS, ResourceTemplate ()              21       Name (_CRS, ResourceTemplate ()
 22       {                                            22       {
 23           GpioIo (Exclusive, PullUp, 0, 0, IoR !!  23           GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
 24                   "\\_SB.GPO0", 0, ResourceCon !!  24                   "\\_SB.GPO0", 0, ResourceConsumer) {15}
 25           GpioIo (Exclusive, PullUp, 0, 0, IoR !!  25           GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly,
 26                   "\\_SB.GPO0", 0, ResourceCon !!  26                   "\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
 27       })                                           27       })
 28                                                    28 
 29       Name (_DSD, Package ()                       29       Name (_DSD, Package ()
 30       {                                            30       {
 31           ToUUID("daffd814-6eba-4d8c-8a91-bc9b     31           ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
 32           Package ()                               32           Package ()
 33           {                                    !!  33           {
 34               Package () { "reset-gpios", Pack !!  34               Package () {"reset-gpios", Package() {^BTH, 1, 1, 0 }},
 35               Package () { "shutdown-gpios", P !!  35               Package () {"shutdown-gpios", Package() {^BTH, 0, 0, 0 }},
 36           }                                        36           }
 37       })                                           37       })
 38   }                                                38   }
 39                                                    39 
 40 The format of the supported GPIO property is::     40 The format of the supported GPIO property is::
 41                                                    41 
 42   Package () { "name", Package () { ref, index     42   Package () { "name", Package () { ref, index, pin, active_low }}
 43                                                    43 
 44 ref                                                44 ref
 45   The device that has _CRS containing GpioIo()     45   The device that has _CRS containing GpioIo()/GpioInt() resources,
 46   typically this is the device itself (BTH in      46   typically this is the device itself (BTH in our case).
 47 index                                              47 index
 48   Index of the GpioIo()/GpioInt() resource in      48   Index of the GpioIo()/GpioInt() resource in _CRS starting from zero.
 49 pin                                                49 pin
 50   Pin in the GpioIo()/GpioInt() resource. Typi     50   Pin in the GpioIo()/GpioInt() resource. Typically this is zero.
 51 active_low                                         51 active_low
 52   If 1, the GPIO is marked as active_low.      !!  52   If 1 the GPIO is marked as active_low.
 53                                                    53 
 54 Since ACPI GpioIo() resource does not have a f     54 Since ACPI GpioIo() resource does not have a field saying whether it is
 55 active low or high, the "active_low" argument      55 active low or high, the "active_low" argument can be used here.  Setting
 56 it to 1 marks the GPIO as active low.              56 it to 1 marks the GPIO as active low.
 57                                                    57 
 58 Note, active_low in _DSD does not make sense f << 
 59 must be 0. GpioInt() resource has its own mean << 
 60                                                << 
 61 In our Bluetooth example the "reset-gpios" ref     58 In our Bluetooth example the "reset-gpios" refers to the second GpioIo()
 62 resource, second pin in that resource with the     59 resource, second pin in that resource with the GPIO number of 31.
 63                                                    60 
 64 The GpioIo() resource unfortunately doesn't ex << 
 65 state of the output pin which driver should us << 
 66                                                << 
 67 Linux tries to use common sense here and deriv << 
 68 and polarity settings. The table below shows t << 
 69                                                << 
 70 +-------------+-------------+----------------- << 
 71 | Pull Bias   | Polarity    | Requested...     << 
 72 +=============+=============+================= << 
 73 | Implicit                                     << 
 74 +-------------+-------------+----------------- << 
 75 | **Default** | x           | AS IS (assumed f << 
 76 +-------------+-------------+----------------- << 
 77 | Explicit                                     << 
 78 +-------------+-------------+----------------- << 
 79 | **None**    | x           | AS IS (assumed f << 
 80 |             |             | with no Pull Bia << 
 81 +-------------+-------------+----------------- << 
 82 | **Up**      | x (no _DSD) |                  << 
 83 |             +-------------+ as high, assumin << 
 84 |             | Low         |                  << 
 85 |             +-------------+----------------- << 
 86 |             | High        | as high, assumin << 
 87 +-------------+-------------+----------------- << 
 88 | **Down**    | x (no _DSD) |                  << 
 89 |             +-------------+ as low, assuming << 
 90 |             | High        |                  << 
 91 |             +-------------+----------------- << 
 92 |             | Low         | as low, assuming << 
 93 +-------------+-------------+----------------- << 
 94                                                << 
 95 That said, for our above example the both GPIO << 
 96 is explicit and _DSD is present, will be treat << 
 97 polarity and Linux will configure the pins in  << 
 98 reprograms them differently.                   << 
 99                                                << 
100 It is possible to leave holes in the array of      61 It is possible to leave holes in the array of GPIOs. This is useful in
101 cases like with SPI host controllers where som     62 cases like with SPI host controllers where some chip selects may be
102 implemented as GPIOs and some as native signal     63 implemented as GPIOs and some as native signals. For example a SPI host
103 controller can have chip selects 0 and 2 imple     64 controller can have chip selects 0 and 2 implemented as GPIOs and 1 as
104 native::                                           65 native::
105                                                    66 
106   Package () {                                     67   Package () {
107       "cs-gpios",                                  68       "cs-gpios",
108       Package () {                                 69       Package () {
109           ^GPIO, 19, 0, 0, // chip select 0: G     70           ^GPIO, 19, 0, 0, // chip select 0: GPIO
110           0,               // chip select 1: n     71           0,               // chip select 1: native signal
111           ^GPIO, 20, 0, 0, // chip select 2: G     72           ^GPIO, 20, 0, 0, // chip select 2: GPIO
112       }                                            73       }
113   }                                                74   }
114                                                    75 
115 Note, that historically ACPI has no means of t << 
116 the SPISerialBus() resource defines it on the  << 
117 to avoid a chain of negations, the GPIO polari << 
118 Active High. Even for the cases when _DSD() is << 
119 above) the GPIO CS polarity must be defined Ac << 
120                                                << 
121 Other supported properties                         76 Other supported properties
122 ==========================                         77 ==========================
123                                                    78 
124 Following Device Tree compatible device proper     79 Following Device Tree compatible device properties are also supported by
125 _DSD device properties for GPIO controllers:       80 _DSD device properties for GPIO controllers:
126                                                    81 
127 - gpio-hog                                         82 - gpio-hog
128 - output-high                                      83 - output-high
129 - output-low                                       84 - output-low
130 - input                                            85 - input
131 - line-name                                        86 - line-name
132                                                    87 
133 Example::                                          88 Example::
134                                                    89 
135   Name (_DSD, Package () {                         90   Name (_DSD, Package () {
136       // _DSD Hierarchical Properties Extensio     91       // _DSD Hierarchical Properties Extension UUID
137       ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a     92       ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
138       Package () {                                 93       Package () {
139           Package () { "hog-gpio8", "G8PU" }   !!  94           Package () {"hog-gpio8", "G8PU"}
140       }                                            95       }
141   })                                               96   })
142                                                    97 
143   Name (G8PU, Package () {                         98   Name (G8PU, Package () {
144       ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4a     99       ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
145       Package () {                                100       Package () {
146           Package () { "gpio-hog", 1 },        !! 101           Package () {"gpio-hog", 1},
147           Package () { "gpios", Package () { 8 !! 102           Package () {"gpios", Package () {8, 0}},
148           Package () { "output-high", 1 },     !! 103           Package () {"output-high", 1},
149           Package () { "line-name", "gpio8-pul !! 104           Package () {"line-name", "gpio8-pullup"},
150       }                                           105       }
151   })                                              106   })
152                                                   107 
153 - gpio-line-names                                 108 - gpio-line-names
154                                                   109 
155 The ``gpio-line-names`` declaration is a list  !! 110 Example::
156 describes each line/pin of a GPIO controller/e << 
157 a package, must be inserted inside the GPIO co << 
158 table (typically inside the DSDT). The ``gpio- << 
159 following rules (see also the examples):       << 
160                                                << 
161   - the first name in the list corresponds wit << 
162     controller/expander                        << 
163   - the names inside the list must be consecut << 
164   - the list can be incomplete and can end bef << 
165     other words, it is not mandatory to fill a << 
166   - empty names are allowed (two quotation mar << 
167     name)                                      << 
168   - names inside one GPIO controller/expander  << 
169                                                << 
170 Example of a GPIO controller of 16 lines, with << 
171 empty names::                                  << 
172                                                << 
173   Package () {                                 << 
174       "gpio-line-names",                       << 
175       Package () {                             << 
176           "pin_0",                             << 
177           "pin_1",                             << 
178           "",                                  << 
179           "",                                  << 
180           "pin_3",                             << 
181           "pin_4_push_button",                 << 
182       }                                        << 
183   }                                            << 
184                                                << 
185 At runtime, the above declaration produces the << 
186 "libgpiod" tools)::                            << 
187                                                << 
188   root@debian:~# gpioinfo gpiochip4            << 
189   gpiochip4 - 16 lines:                        << 
190           line   0:      "pin_0"       unused  << 
191           line   1:      "pin_1"       unused  << 
192           line   2:      unnamed       unused  << 
193           line   3:      unnamed       unused  << 
194           line   4:      "pin_3"       unused  << 
195           line   5: "pin_4_push_button" unused << 
196           line   6:      unnamed       unused  << 
197           line   7       unnamed       unused  << 
198           line   8:      unnamed       unused  << 
199           line   9:      unnamed       unused  << 
200           line  10:      unnamed       unused  << 
201           line  11:      unnamed       unused  << 
202           line  12:      unnamed       unused  << 
203           line  13:      unnamed       unused  << 
204           line  14:      unnamed       unused  << 
205           line  15:      unnamed       unused  << 
206   root@debian:~# gpiofind pin_4_push_button    << 
207   gpiochip4 5                                  << 
208   root@debian:~#                               << 
209                                                << 
210 Another example::                              << 
211                                                   111 
212   Package () {                                    112   Package () {
213       "gpio-line-names",                          113       "gpio-line-names",
214       Package () {                                114       Package () {
215           "SPI0_CS_N", "EXP2_INT", "MUX6_IO",  !! 115           "SPI0_CS_N", "EXP2_INT", "MUX6_IO", "UART0_RXD", "MUX7_IO",
216           "MUX7_IO", "LVL_C_A1", "MUX0_IO", "S !! 116           "LVL_C_A1", "MUX0_IO", "SPI1_MISO"
217       }                                           117       }
218   }                                               118   }
219                                                   119 
220 See Documentation/devicetree/bindings/gpio/gpi    120 See Documentation/devicetree/bindings/gpio/gpio.txt for more information
221 about these properties.                           121 about these properties.
222                                                   122 
223 ACPI GPIO Mappings Provided by Drivers            123 ACPI GPIO Mappings Provided by Drivers
224 ======================================            124 ======================================
225                                                   125 
226 There are systems in which the ACPI tables do     126 There are systems in which the ACPI tables do not contain _DSD but provide _CRS
227 with GpioIo()/GpioInt() resources and device d    127 with GpioIo()/GpioInt() resources and device drivers still need to work with
228 them.                                             128 them.
229                                                   129 
230 In those cases ACPI device identification obje    130 In those cases ACPI device identification objects, _HID, _CID, _CLS, _SUB, _HRV,
231 available to the driver can be used to identif    131 available to the driver can be used to identify the device and that is supposed
232 to be sufficient to determine the meaning and     132 to be sufficient to determine the meaning and purpose of all of the GPIO lines
233 listed by the GpioIo()/GpioInt() resources ret    133 listed by the GpioIo()/GpioInt() resources returned by _CRS.  In other words,
234 the driver is supposed to know what to use the    134 the driver is supposed to know what to use the GpioIo()/GpioInt() resources for
235 once it has identified the device.  Having don    135 once it has identified the device.  Having done that, it can simply assign names
236 to the GPIO lines it is going to use and provi    136 to the GPIO lines it is going to use and provide the GPIO subsystem with a
237 mapping between those names and the ACPI GPIO     137 mapping between those names and the ACPI GPIO resources corresponding to them.
238                                                   138 
239 To do that, the driver needs to define a mappi    139 To do that, the driver needs to define a mapping table as a NULL-terminated
240 array of struct acpi_gpio_mapping objects that !! 140 array of struct acpi_gpio_mapping objects that each contain a name, a pointer
241 to an array of line data (struct acpi_gpio_par    141 to an array of line data (struct acpi_gpio_params) objects and the size of that
242 array.  Each struct acpi_gpio_params object co    142 array.  Each struct acpi_gpio_params object consists of three fields,
243 crs_entry_index, line_index, active_low, repre    143 crs_entry_index, line_index, active_low, representing the index of the target
244 GpioIo()/GpioInt() resource in _CRS starting f    144 GpioIo()/GpioInt() resource in _CRS starting from zero, the index of the target
245 line in that resource starting from zero, and     145 line in that resource starting from zero, and the active-low flag for that line,
246 respectively, in analogy with the _DSD GPIO pr    146 respectively, in analogy with the _DSD GPIO property format specified above.
247                                                   147 
248 For the example Bluetooth device discussed pre    148 For the example Bluetooth device discussed previously the data structures in
249 question would look like this::                   149 question would look like this::
250                                                   150 
251   static const struct acpi_gpio_params reset_g    151   static const struct acpi_gpio_params reset_gpio = { 1, 1, false };
252   static const struct acpi_gpio_params shutdow    152   static const struct acpi_gpio_params shutdown_gpio = { 0, 0, false };
253                                                   153 
254   static const struct acpi_gpio_mapping blueto    154   static const struct acpi_gpio_mapping bluetooth_acpi_gpios[] = {
255     { "reset-gpios", &reset_gpio, 1 },            155     { "reset-gpios", &reset_gpio, 1 },
256     { "shutdown-gpios", &shutdown_gpio, 1 },      156     { "shutdown-gpios", &shutdown_gpio, 1 },
257     { }                                        !! 157     { },
258   };                                              158   };
259                                                   159 
260 Next, the mapping table needs to be passed as     160 Next, the mapping table needs to be passed as the second argument to
261 acpi_dev_add_driver_gpios() or its managed ana !! 161 acpi_dev_add_driver_gpios() that will register it with the ACPI device object
262 register it with the ACPI device object pointe !! 162 pointed to by its first argument.  That should be done in the driver's .probe()
263 argument. That should be done in the driver's  !! 163 routine.  On removal, the driver should unregister its GPIO mapping table by
264 On removal, the driver should unregister its G << 
265 calling acpi_dev_remove_driver_gpios() on the     164 calling acpi_dev_remove_driver_gpios() on the ACPI device object where that
266 table was previously registered.                  165 table was previously registered.
267                                                   166 
268 Using the _CRS fallback                           167 Using the _CRS fallback
269 =======================                           168 =======================
270                                                   169 
271 If a device does not have _DSD or the driver d    170 If a device does not have _DSD or the driver does not create ACPI GPIO
272 mapping, the Linux GPIO framework refuses to r    171 mapping, the Linux GPIO framework refuses to return any GPIOs. This is
273 because the driver does not know what it actua    172 because the driver does not know what it actually gets. For example if we
274 have a device like below::                        173 have a device like below::
275                                                   174 
276   Device (BTH)                                    175   Device (BTH)
277   {                                               176   {
278       Name (_HID, ...)                            177       Name (_HID, ...)
279                                                   178 
280       Name (_CRS, ResourceTemplate () {           179       Name (_CRS, ResourceTemplate () {
281           GpioIo (Exclusive, PullNone, 0, 0, I    180           GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
282                   "\\_SB.GPO0", 0, ResourceCon !! 181                   "\\_SB.GPO0", 0, ResourceConsumer) {15}
283           GpioIo (Exclusive, PullNone, 0, 0, I    182           GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
284                   "\\_SB.GPO0", 0, ResourceCon !! 183                   "\\_SB.GPO0", 0, ResourceConsumer) {27}
285       })                                          184       })
286   }                                               185   }
287                                                   186 
288 The driver might expect to get the right GPIO     187 The driver might expect to get the right GPIO when it does::
289                                                   188 
290   desc = gpiod_get(dev, "reset", GPIOD_OUT_LOW    189   desc = gpiod_get(dev, "reset", GPIOD_OUT_LOW);
291   if (IS_ERR(desc))                            << 
292         ...error handling...                   << 
293                                                   190 
294 but since there is no way to know the mapping     191 but since there is no way to know the mapping between "reset" and
295 the GpioIo() in _CRS desc will hold ERR_PTR(-E    192 the GpioIo() in _CRS desc will hold ERR_PTR(-ENOENT).
296                                                   193 
297 The driver author can solve this by passing th !! 194 The driver author can solve this by passing the mapping explictly
298 (this is the recommended way and it's document !! 195 (the recommended way and documented in the above chapter).
299                                                   196 
300 The ACPI GPIO mapping tables should not contam    197 The ACPI GPIO mapping tables should not contaminate drivers that are not
301 knowing about which exact device they are serv    198 knowing about which exact device they are servicing on. It implies that
302 the ACPI GPIO mapping tables are hardly linked !! 199 the ACPI GPIO mapping tables are hardly linked to ACPI ID and certain
303 objects, as listed in the above chapter, of th    200 objects, as listed in the above chapter, of the device in question.
304                                                   201 
305 Getting GPIO descriptor                           202 Getting GPIO descriptor
306 =======================                           203 =======================
307                                                   204 
308 There are two main approaches to get GPIO reso    205 There are two main approaches to get GPIO resource from ACPI::
309                                                   206 
310   desc = gpiod_get(dev, connection_id, flags);    207   desc = gpiod_get(dev, connection_id, flags);
311   desc = gpiod_get_index(dev, connection_id, i    208   desc = gpiod_get_index(dev, connection_id, index, flags);
312                                                   209 
313 We may consider two different cases here, i.e.    210 We may consider two different cases here, i.e. when connection ID is
314 provided and otherwise.                           211 provided and otherwise.
315                                                   212 
316 Case 1::                                          213 Case 1::
317                                                   214 
318   desc = gpiod_get(dev, "non-null-connection-i    215   desc = gpiod_get(dev, "non-null-connection-id", flags);
319   desc = gpiod_get_index(dev, "non-null-connec    216   desc = gpiod_get_index(dev, "non-null-connection-id", index, flags);
320                                                   217 
321 Case 2::                                          218 Case 2::
322                                                   219 
323   desc = gpiod_get(dev, NULL, flags);             220   desc = gpiod_get(dev, NULL, flags);
324   desc = gpiod_get_index(dev, NULL, index, fla    221   desc = gpiod_get_index(dev, NULL, index, flags);
325                                                   222 
326 Case 1 assumes that corresponding ACPI device     223 Case 1 assumes that corresponding ACPI device description must have
327 defined device properties and will prevent to     224 defined device properties and will prevent to getting any GPIO resources
328 otherwise.                                        225 otherwise.
329                                                   226 
330 Case 2 explicitly tells GPIO core to look for     227 Case 2 explicitly tells GPIO core to look for resources in _CRS.
331                                                   228 
332 Be aware that gpiod_get_index() in cases 1 and    229 Be aware that gpiod_get_index() in cases 1 and 2, assuming that there
333 are two versions of ACPI device description pr    230 are two versions of ACPI device description provided and no mapping is
334 present in the driver, will return different r    231 present in the driver, will return different resources. That's why a
335 certain driver has to handle them carefully as !! 232 certain driver has to handle them carefully as explained in previous
336 chapter.                                          233 chapter.
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php