Skip to content

Commit 1bde8bd

Browse files
committed
Merge branch 'acpi-docs'
Make ACPI documentation updates for 5.18-rc1: - Update the ACPI device enumeration documentation and unify the ASL style in GPIO-related examples (Andy Shevchenko). * acpi-docs: ACPI: docs: gpio-properties: Unify ASL style for GPIO examples ACPI: docs: enumeration: Unify Package () for properties ACPI: docs: enumeration: Drop comma for terminator entry ACPI: docs: enumeration: Drop ugly ifdeffery from the examples ACPI: docs: enumeration: Amend PWM enumeration ASL example ACPI: docs: enumeration: Remove redundant .owner assignment ACPI: docs: enumeration: Update UART serial bus resource documentation ACPI: docs: enumeration: Discourage to use custom _DSM methods
2 parents 8a9bd50 + 830751d commit 1bde8bd

3 files changed

Lines changed: 67 additions & 91 deletions

File tree

Documentation/driver-api/gpio/board.rst

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ with the help of _DSD (Device Specific Data), introduced in ACPI 5.1::
7171

7272
Device (FOO) {
7373
Name (_CRS, ResourceTemplate () {
74-
GpioIo (Exclusive, ..., IoRestrictionOutputOnly,
75-
"\\_SB.GPI0") {15} // red
76-
GpioIo (Exclusive, ..., IoRestrictionOutputOnly,
77-
"\\_SB.GPI0") {16} // green
78-
GpioIo (Exclusive, ..., IoRestrictionOutputOnly,
79-
"\\_SB.GPI0") {17} // blue
80-
GpioIo (Exclusive, ..., IoRestrictionOutputOnly,
81-
"\\_SB.GPI0") {1} // power
74+
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
75+
"\\_SB.GPI0", 0, ResourceConsumer) { 15 } // red
76+
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
77+
"\\_SB.GPI0", 0, ResourceConsumer) { 16 } // green
78+
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
79+
"\\_SB.GPI0", 0, ResourceConsumer) { 17 } // blue
80+
GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionOutputOnly,
81+
"\\_SB.GPI0", 0, ResourceConsumer) { 1 } // power
8282
})
8383

8484
Name (_DSD, Package () {
@@ -92,10 +92,7 @@ with the help of _DSD (Device Specific Data), introduced in ACPI 5.1::
9292
^FOO, 2, 0, 1,
9393
}
9494
},
95-
Package () {
96-
"power-gpios",
97-
Package () {^FOO, 3, 0, 0},
98-
},
95+
Package () { "power-gpios", Package () { ^FOO, 3, 0, 0 } },
9996
}
10097
})
10198
}

Documentation/firmware-guide/acpi/enumeration.rst

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ possible we decided to do following:
1919
platform devices.
2020

2121
- Devices behind real busses where there is a connector resource
22-
are represented as struct spi_device or struct i2c_device
23-
(standard UARTs are not busses so there is no struct uart_device).
22+
are represented as struct spi_device or struct i2c_device. Note
23+
that standard UARTs are not busses so there is no struct uart_device,
24+
although some of them may be represented by sturct serdev_device.
2425

2526
As both ACPI and Device Tree represent a tree of devices (and their
2627
resources) this implementation follows the Device Tree way as much as
2728
possible.
2829

29-
The ACPI implementation enumerates devices behind busses (platform, SPI and
30-
I2C), creates the physical devices and binds them to their ACPI handle in
31-
the ACPI namespace.
30+
The ACPI implementation enumerates devices behind busses (platform, SPI,
31+
I2C, and in some cases UART), creates the physical devices and binds them
32+
to their ACPI handle in the ACPI namespace.
3233

3334
This means that when ACPI_HANDLE(dev) returns non-NULL the device was
3435
enumerated from ACPI namespace. This handle can be used to extract other
@@ -46,18 +47,16 @@ some minor changes.
4647
Adding ACPI support for an existing driver should be pretty
4748
straightforward. Here is the simplest example::
4849

49-
#ifdef CONFIG_ACPI
5050
static const struct acpi_device_id mydrv_acpi_match[] = {
5151
/* ACPI IDs here */
5252
{ }
5353
};
5454
MODULE_DEVICE_TABLE(acpi, mydrv_acpi_match);
55-
#endif
5655

5756
static struct platform_driver my_driver = {
5857
...
5958
.driver = {
60-
.acpi_match_table = ACPI_PTR(mydrv_acpi_match),
59+
.acpi_match_table = mydrv_acpi_match,
6160
},
6261
};
6362

@@ -155,7 +154,7 @@ Here is what the ACPI namespace for a SPI slave might look like::
155154
Device (EEP0)
156155
{
157156
Name (_ADR, 1)
158-
Name (_CID, Package() {
157+
Name (_CID, Package () {
159158
"ATML0025",
160159
"AT25",
161160
})
@@ -172,59 +171,51 @@ The SPI device drivers only need to add ACPI IDs in a similar way than with
172171
the platform device drivers. Below is an example where we add ACPI support
173172
to at25 SPI eeprom driver (this is meant for the above ACPI snippet)::
174173

175-
#ifdef CONFIG_ACPI
176174
static const struct acpi_device_id at25_acpi_match[] = {
177175
{ "AT25", 0 },
178-
{ },
176+
{ }
179177
};
180178
MODULE_DEVICE_TABLE(acpi, at25_acpi_match);
181-
#endif
182179

183180
static struct spi_driver at25_driver = {
184181
.driver = {
185182
...
186-
.acpi_match_table = ACPI_PTR(at25_acpi_match),
183+
.acpi_match_table = at25_acpi_match,
187184
},
188185
};
189186

190187
Note that this driver actually needs more information like page size of the
191-
eeprom etc. but at the time writing this there is no standard way of
192-
passing those. One idea is to return this in _DSM method like::
188+
eeprom, etc. This information can be passed via _DSD method like::
193189

194190
Device (EEP0)
195191
{
196192
...
197-
Method (_DSM, 4, NotSerialized)
193+
Name (_DSD, Package ()
198194
{
199-
Store (Package (6)
195+
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
196+
Package ()
200197
{
201-
"byte-len", 1024,
202-
"addr-mode", 2,
203-
"page-size, 32
204-
}, Local0)
205-
206-
// Check UUIDs etc.
207-
208-
Return (Local0)
209-
}
210-
211-
Then the at25 SPI driver can get this configuration by calling _DSM on its
212-
ACPI handle like::
213-
214-
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
215-
struct acpi_object_list input;
216-
acpi_status status;
198+
Package () { "size", 1024 },
199+
Package () { "pagesize", 32 },
200+
Package () { "address-width", 16 },
201+
}
202+
})
203+
}
217204

218-
/* Fill in the input buffer */
205+
Then the at25 SPI driver can get this configuration by calling device property
206+
APIs during ->probe() phase like::
219207

220-
status = acpi_evaluate_object(ACPI_HANDLE(&spi->dev), "_DSM",
221-
&input, &output);
222-
if (ACPI_FAILURE(status))
223-
/* Handle the error */
208+
err = device_property_read_u32(dev, "size", &size);
209+
if (err)
210+
...error handling...
224211

225-
/* Extract the data here */
212+
err = device_property_read_u32(dev, "pagesize", &page_size);
213+
if (err)
214+
...error handling...
226215

227-
kfree(output.pointer);
216+
err = device_property_read_u32(dev, "address-width", &addr_width);
217+
if (err)
218+
...error handling...
228219

229220
I2C serial bus support
230221
======================
@@ -237,26 +228,24 @@ registered.
237228
Below is an example of how to add ACPI support to the existing mpu3050
238229
input driver::
239230

240-
#ifdef CONFIG_ACPI
241231
static const struct acpi_device_id mpu3050_acpi_match[] = {
242232
{ "MPU3050", 0 },
243-
{ },
233+
{ }
244234
};
245235
MODULE_DEVICE_TABLE(acpi, mpu3050_acpi_match);
246-
#endif
247236

248237
static struct i2c_driver mpu3050_i2c_driver = {
249238
.driver = {
250239
.name = "mpu3050",
251-
.owner = THIS_MODULE,
252240
.pm = &mpu3050_pm,
253241
.of_match_table = mpu3050_of_match,
254-
.acpi_match_table = ACPI_PTR(mpu3050_acpi_match),
242+
.acpi_match_table = mpu3050_acpi_match,
255243
},
256244
.probe = mpu3050_probe,
257245
.remove = mpu3050_remove,
258246
.id_table = mpu3050_ids,
259247
};
248+
module_i2c_driver(mpu3050_i2c_driver);
260249

261250
Reference to PWM device
262251
=======================
@@ -282,9 +271,9 @@ introduced, i.e.::
282271
}
283272
}
284273
}
285-
286274
})
287275
...
276+
}
288277

289278
In the above example the PWM-based LED driver references to the PWM channel 0
290279
of \_SB.PCI0.PWM device with initial period setting equal to 600 ms (note that
@@ -306,26 +295,13 @@ For example::
306295
{
307296
Name (SBUF, ResourceTemplate()
308297
{
309-
...
310298
// Used to power on/off the device
311-
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
312-
IoRestrictionOutputOnly, "\\_SB.PCI0.GPI0",
313-
0x00, ResourceConsumer,,)
314-
{
315-
// Pin List
316-
0x0055
317-
}
299+
GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionOutputOnly,
300+
"\\_SB.PCI0.GPI0", 0, ResourceConsumer) { 85 }
318301

319302
// Interrupt for the device
320-
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone,
321-
0x0000, "\\_SB.PCI0.GPI0", 0x00, ResourceConsumer,,)
322-
{
323-
// Pin list
324-
0x0058
325-
}
326-
327-
...
328-
303+
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0,
304+
"\\_SB.PCI0.GPI0", 0, ResourceConsumer) { 88 }
329305
}
330306

331307
Return (SBUF)
@@ -337,11 +313,12 @@ For example::
337313
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
338314
Package ()
339315
{
340-
Package () {"power-gpios", Package() {^DEV, 0, 0, 0 }},
341-
Package () {"irq-gpios", Package() {^DEV, 1, 0, 0 }},
316+
Package () { "power-gpios", Package () { ^DEV, 0, 0, 0 } },
317+
Package () { "irq-gpios", Package () { ^DEV, 1, 0, 0 } },
342318
}
343319
})
344320
...
321+
}
345322

346323
These GPIO numbers are controller relative and path "\\_SB.PCI0.GPI0"
347324
specifies the path to the controller. In order to use these GPIOs in Linux
@@ -460,10 +437,10 @@ namespace link::
460437
Device (TMP0)
461438
{
462439
Name (_HID, "PRP0001")
463-
Name (_DSD, Package() {
440+
Name (_DSD, Package () {
464441
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
465442
Package () {
466-
Package (2) { "compatible", "ti,tmp75" },
443+
Package () { "compatible", "ti,tmp75" },
467444
}
468445
})
469446
Method (_CRS, 0, Serialized)

Documentation/firmware-guide/acpi/gpio-properties.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ index, like the ASL example below shows::
2121
Name (_CRS, ResourceTemplate ()
2222
{
2323
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
24-
"\\_SB.GPO0", 0, ResourceConsumer) {15}
24+
"\\_SB.GPO0", 0, ResourceConsumer) { 15 }
2525
GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionOutputOnly,
26-
"\\_SB.GPO0", 0, ResourceConsumer) {27, 31}
26+
"\\_SB.GPO0", 0, ResourceConsumer) { 27, 31 }
2727
})
2828

2929
Name (_DSD, Package ()
3030
{
3131
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
3232
Package ()
33-
{
34-
Package () {"reset-gpios", Package() {^BTH, 1, 1, 0 }},
35-
Package () {"shutdown-gpios", Package() {^BTH, 0, 0, 0 }},
33+
{
34+
Package () { "reset-gpios", Package () { ^BTH, 1, 1, 0 } },
35+
Package () { "shutdown-gpios", Package () { ^BTH, 0, 0, 0 } },
3636
}
3737
})
3838
}
@@ -123,17 +123,17 @@ Example::
123123
// _DSD Hierarchical Properties Extension UUID
124124
ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
125125
Package () {
126-
Package () {"hog-gpio8", "G8PU"}
126+
Package () { "hog-gpio8", "G8PU" }
127127
}
128128
})
129129

130130
Name (G8PU, Package () {
131131
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
132132
Package () {
133-
Package () {"gpio-hog", 1},
134-
Package () {"gpios", Package () {8, 0}},
135-
Package () {"output-high", 1},
136-
Package () {"line-name", "gpio8-pullup"},
133+
Package () { "gpio-hog", 1 },
134+
Package () { "gpios", Package () { 8, 0 } },
135+
Package () { "output-high", 1 },
136+
Package () { "line-name", "gpio8-pullup" },
137137
}
138138
})
139139

@@ -266,15 +266,17 @@ have a device like below::
266266

267267
Name (_CRS, ResourceTemplate () {
268268
GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
269-
"\\_SB.GPO0", 0, ResourceConsumer) {15}
269+
"\\_SB.GPO0", 0, ResourceConsumer) { 15 }
270270
GpioIo (Exclusive, PullNone, 0, 0, IoRestrictionNone,
271-
"\\_SB.GPO0", 0, ResourceConsumer) {27}
271+
"\\_SB.GPO0", 0, ResourceConsumer) { 27 }
272272
})
273273
}
274274

275275
The driver might expect to get the right GPIO when it does::
276276

277277
desc = gpiod_get(dev, "reset", GPIOD_OUT_LOW);
278+
if (IS_ERR(desc))
279+
...error handling...
278280

279281
but since there is no way to know the mapping between "reset" and
280282
the GpioIo() in _CRS desc will hold ERR_PTR(-ENOENT).

0 commit comments

Comments
 (0)