xref: /OK3568_Linux_fs/kernel/Documentation/firmware-guide/acpi/enumeration.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=============================
4*4882a593SmuzhiyunACPI Based Device Enumeration
5*4882a593Smuzhiyun=============================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunACPI 5 introduced a set of new resources (UartTSerialBus, I2cSerialBus,
8*4882a593SmuzhiyunSpiSerialBus, GpioIo and GpioInt) which can be used in enumerating slave
9*4882a593Smuzhiyundevices behind serial bus controllers.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIn addition we are starting to see peripherals integrated in the
12*4882a593SmuzhiyunSoC/Chipset to appear only in ACPI namespace. These are typically devices
13*4882a593Smuzhiyunthat are accessed through memory-mapped registers.
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunIn order to support this and re-use the existing drivers as much as
16*4882a593Smuzhiyunpossible we decided to do following:
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun  - Devices that have no bus connector resource are represented as
19*4882a593Smuzhiyun    platform devices.
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun  - Devices behind real busses where there is a connector resource
22*4882a593Smuzhiyun    are represented as struct spi_device or struct i2c_device
23*4882a593Smuzhiyun    (standard UARTs are not busses so there is no struct uart_device).
24*4882a593Smuzhiyun
25*4882a593SmuzhiyunAs both ACPI and Device Tree represent a tree of devices (and their
26*4882a593Smuzhiyunresources) this implementation follows the Device Tree way as much as
27*4882a593Smuzhiyunpossible.
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunThe ACPI implementation enumerates devices behind busses (platform, SPI and
30*4882a593SmuzhiyunI2C), creates the physical devices and binds them to their ACPI handle in
31*4882a593Smuzhiyunthe ACPI namespace.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunThis means that when ACPI_HANDLE(dev) returns non-NULL the device was
34*4882a593Smuzhiyunenumerated from ACPI namespace. This handle can be used to extract other
35*4882a593Smuzhiyundevice-specific configuration. There is an example of this below.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunPlatform bus support
38*4882a593Smuzhiyun====================
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunSince we are using platform devices to represent devices that are not
41*4882a593Smuzhiyunconnected to any physical bus we only need to implement a platform driver
42*4882a593Smuzhiyunfor the device and add supported ACPI IDs. If this same IP-block is used on
43*4882a593Smuzhiyunsome other non-ACPI platform, the driver might work out of the box or needs
44*4882a593Smuzhiyunsome minor changes.
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunAdding ACPI support for an existing driver should be pretty
47*4882a593Smuzhiyunstraightforward. Here is the simplest example::
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun	#ifdef CONFIG_ACPI
50*4882a593Smuzhiyun	static const struct acpi_device_id mydrv_acpi_match[] = {
51*4882a593Smuzhiyun		/* ACPI IDs here */
52*4882a593Smuzhiyun		{ }
53*4882a593Smuzhiyun	};
54*4882a593Smuzhiyun	MODULE_DEVICE_TABLE(acpi, mydrv_acpi_match);
55*4882a593Smuzhiyun	#endif
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun	static struct platform_driver my_driver = {
58*4882a593Smuzhiyun		...
59*4882a593Smuzhiyun		.driver = {
60*4882a593Smuzhiyun			.acpi_match_table = ACPI_PTR(mydrv_acpi_match),
61*4882a593Smuzhiyun		},
62*4882a593Smuzhiyun	};
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunIf the driver needs to perform more complex initialization like getting and
65*4882a593Smuzhiyunconfiguring GPIOs it can get its ACPI handle and extract this information
66*4882a593Smuzhiyunfrom ACPI tables.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunDMA support
69*4882a593Smuzhiyun===========
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunDMA controllers enumerated via ACPI should be registered in the system to
72*4882a593Smuzhiyunprovide generic access to their resources. For example, a driver that would
73*4882a593Smuzhiyunlike to be accessible to slave devices via generic API call
74*4882a593Smuzhiyundma_request_chan() must register itself at the end of the probe function like
75*4882a593Smuzhiyunthis::
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun	err = devm_acpi_dma_controller_register(dev, xlate_func, dw);
78*4882a593Smuzhiyun	/* Handle the error if it's not a case of !CONFIG_ACPI */
79*4882a593Smuzhiyun
80*4882a593Smuzhiyunand implement custom xlate function if needed (usually acpi_dma_simple_xlate()
81*4882a593Smuzhiyunis enough) which converts the FixedDMA resource provided by struct
82*4882a593Smuzhiyunacpi_dma_spec into the corresponding DMA channel. A piece of code for that case
83*4882a593Smuzhiyuncould look like::
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun	#ifdef CONFIG_ACPI
86*4882a593Smuzhiyun	struct filter_args {
87*4882a593Smuzhiyun		/* Provide necessary information for the filter_func */
88*4882a593Smuzhiyun		...
89*4882a593Smuzhiyun	};
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun	static bool filter_func(struct dma_chan *chan, void *param)
92*4882a593Smuzhiyun	{
93*4882a593Smuzhiyun		/* Choose the proper channel */
94*4882a593Smuzhiyun		...
95*4882a593Smuzhiyun	}
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun	static struct dma_chan *xlate_func(struct acpi_dma_spec *dma_spec,
98*4882a593Smuzhiyun			struct acpi_dma *adma)
99*4882a593Smuzhiyun	{
100*4882a593Smuzhiyun		dma_cap_mask_t cap;
101*4882a593Smuzhiyun		struct filter_args args;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun		/* Prepare arguments for filter_func */
104*4882a593Smuzhiyun		...
105*4882a593Smuzhiyun		return dma_request_channel(cap, filter_func, &args);
106*4882a593Smuzhiyun	}
107*4882a593Smuzhiyun	#else
108*4882a593Smuzhiyun	static struct dma_chan *xlate_func(struct acpi_dma_spec *dma_spec,
109*4882a593Smuzhiyun			struct acpi_dma *adma)
110*4882a593Smuzhiyun	{
111*4882a593Smuzhiyun		return NULL;
112*4882a593Smuzhiyun	}
113*4882a593Smuzhiyun	#endif
114*4882a593Smuzhiyun
115*4882a593Smuzhiyundma_request_chan() will call xlate_func() for each registered DMA controller.
116*4882a593SmuzhiyunIn the xlate function the proper channel must be chosen based on
117*4882a593Smuzhiyuninformation in struct acpi_dma_spec and the properties of the controller
118*4882a593Smuzhiyunprovided by struct acpi_dma.
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunClients must call dma_request_chan() with the string parameter that corresponds
121*4882a593Smuzhiyunto a specific FixedDMA resource. By default "tx" means the first entry of the
122*4882a593SmuzhiyunFixedDMA resource array, "rx" means the second entry. The table below shows a
123*4882a593Smuzhiyunlayout::
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun	Device (I2C0)
126*4882a593Smuzhiyun	{
127*4882a593Smuzhiyun		...
128*4882a593Smuzhiyun		Method (_CRS, 0, NotSerialized)
129*4882a593Smuzhiyun		{
130*4882a593Smuzhiyun			Name (DBUF, ResourceTemplate ()
131*4882a593Smuzhiyun			{
132*4882a593Smuzhiyun				FixedDMA (0x0018, 0x0004, Width32bit, _Y48)
133*4882a593Smuzhiyun				FixedDMA (0x0019, 0x0005, Width32bit, )
134*4882a593Smuzhiyun			})
135*4882a593Smuzhiyun		...
136*4882a593Smuzhiyun		}
137*4882a593Smuzhiyun	}
138*4882a593Smuzhiyun
139*4882a593SmuzhiyunSo, the FixedDMA with request line 0x0018 is "tx" and next one is "rx" in
140*4882a593Smuzhiyunthis example.
141*4882a593Smuzhiyun
142*4882a593SmuzhiyunIn robust cases the client unfortunately needs to call
143*4882a593Smuzhiyunacpi_dma_request_slave_chan_by_index() directly and therefore choose the
144*4882a593Smuzhiyunspecific FixedDMA resource by its index.
145*4882a593Smuzhiyun
146*4882a593SmuzhiyunSPI serial bus support
147*4882a593Smuzhiyun======================
148*4882a593Smuzhiyun
149*4882a593SmuzhiyunSlave devices behind SPI bus have SpiSerialBus resource attached to them.
150*4882a593SmuzhiyunThis is extracted automatically by the SPI core and the slave devices are
151*4882a593Smuzhiyunenumerated once spi_register_master() is called by the bus driver.
152*4882a593Smuzhiyun
153*4882a593SmuzhiyunHere is what the ACPI namespace for a SPI slave might look like::
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun	Device (EEP0)
156*4882a593Smuzhiyun	{
157*4882a593Smuzhiyun		Name (_ADR, 1)
158*4882a593Smuzhiyun		Name (_CID, Package() {
159*4882a593Smuzhiyun			"ATML0025",
160*4882a593Smuzhiyun			"AT25",
161*4882a593Smuzhiyun		})
162*4882a593Smuzhiyun		...
163*4882a593Smuzhiyun		Method (_CRS, 0, NotSerialized)
164*4882a593Smuzhiyun		{
165*4882a593Smuzhiyun			SPISerialBus(1, PolarityLow, FourWireMode, 8,
166*4882a593Smuzhiyun				ControllerInitiated, 1000000, ClockPolarityLow,
167*4882a593Smuzhiyun				ClockPhaseFirst, "\\_SB.PCI0.SPI1",)
168*4882a593Smuzhiyun		}
169*4882a593Smuzhiyun		...
170*4882a593Smuzhiyun
171*4882a593SmuzhiyunThe SPI device drivers only need to add ACPI IDs in a similar way than with
172*4882a593Smuzhiyunthe platform device drivers. Below is an example where we add ACPI support
173*4882a593Smuzhiyunto at25 SPI eeprom driver (this is meant for the above ACPI snippet)::
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun	#ifdef CONFIG_ACPI
176*4882a593Smuzhiyun	static const struct acpi_device_id at25_acpi_match[] = {
177*4882a593Smuzhiyun		{ "AT25", 0 },
178*4882a593Smuzhiyun		{ },
179*4882a593Smuzhiyun	};
180*4882a593Smuzhiyun	MODULE_DEVICE_TABLE(acpi, at25_acpi_match);
181*4882a593Smuzhiyun	#endif
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun	static struct spi_driver at25_driver = {
184*4882a593Smuzhiyun		.driver = {
185*4882a593Smuzhiyun			...
186*4882a593Smuzhiyun			.acpi_match_table = ACPI_PTR(at25_acpi_match),
187*4882a593Smuzhiyun		},
188*4882a593Smuzhiyun	};
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunNote that this driver actually needs more information like page size of the
191*4882a593Smuzhiyuneeprom etc. but at the time writing this there is no standard way of
192*4882a593Smuzhiyunpassing those. One idea is to return this in _DSM method like::
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun	Device (EEP0)
195*4882a593Smuzhiyun	{
196*4882a593Smuzhiyun		...
197*4882a593Smuzhiyun		Method (_DSM, 4, NotSerialized)
198*4882a593Smuzhiyun		{
199*4882a593Smuzhiyun			Store (Package (6)
200*4882a593Smuzhiyun			{
201*4882a593Smuzhiyun				"byte-len", 1024,
202*4882a593Smuzhiyun				"addr-mode", 2,
203*4882a593Smuzhiyun				"page-size, 32
204*4882a593Smuzhiyun			}, Local0)
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun			// Check UUIDs etc.
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun			Return (Local0)
209*4882a593Smuzhiyun		}
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunThen the at25 SPI driver can get this configuration by calling _DSM on its
212*4882a593SmuzhiyunACPI handle like::
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
215*4882a593Smuzhiyun	struct acpi_object_list input;
216*4882a593Smuzhiyun	acpi_status status;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun	/* Fill in the input buffer */
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun	status = acpi_evaluate_object(ACPI_HANDLE(&spi->dev), "_DSM",
221*4882a593Smuzhiyun				      &input, &output);
222*4882a593Smuzhiyun	if (ACPI_FAILURE(status))
223*4882a593Smuzhiyun		/* Handle the error */
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun	/* Extract the data here */
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun	kfree(output.pointer);
228*4882a593Smuzhiyun
229*4882a593SmuzhiyunI2C serial bus support
230*4882a593Smuzhiyun======================
231*4882a593Smuzhiyun
232*4882a593SmuzhiyunThe slaves behind I2C bus controller only need to add the ACPI IDs like
233*4882a593Smuzhiyunwith the platform and SPI drivers. The I2C core automatically enumerates
234*4882a593Smuzhiyunany slave devices behind the controller device once the adapter is
235*4882a593Smuzhiyunregistered.
236*4882a593Smuzhiyun
237*4882a593SmuzhiyunBelow is an example of how to add ACPI support to the existing mpu3050
238*4882a593Smuzhiyuninput driver::
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun	#ifdef CONFIG_ACPI
241*4882a593Smuzhiyun	static const struct acpi_device_id mpu3050_acpi_match[] = {
242*4882a593Smuzhiyun		{ "MPU3050", 0 },
243*4882a593Smuzhiyun		{ },
244*4882a593Smuzhiyun	};
245*4882a593Smuzhiyun	MODULE_DEVICE_TABLE(acpi, mpu3050_acpi_match);
246*4882a593Smuzhiyun	#endif
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun	static struct i2c_driver mpu3050_i2c_driver = {
249*4882a593Smuzhiyun		.driver	= {
250*4882a593Smuzhiyun			.name	= "mpu3050",
251*4882a593Smuzhiyun			.owner	= THIS_MODULE,
252*4882a593Smuzhiyun			.pm	= &mpu3050_pm,
253*4882a593Smuzhiyun			.of_match_table = mpu3050_of_match,
254*4882a593Smuzhiyun			.acpi_match_table = ACPI_PTR(mpu3050_acpi_match),
255*4882a593Smuzhiyun		},
256*4882a593Smuzhiyun		.probe		= mpu3050_probe,
257*4882a593Smuzhiyun		.remove		= mpu3050_remove,
258*4882a593Smuzhiyun		.id_table	= mpu3050_ids,
259*4882a593Smuzhiyun	};
260*4882a593Smuzhiyun
261*4882a593SmuzhiyunGPIO support
262*4882a593Smuzhiyun============
263*4882a593Smuzhiyun
264*4882a593SmuzhiyunACPI 5 introduced two new resources to describe GPIO connections: GpioIo
265*4882a593Smuzhiyunand GpioInt. These resources can be used to pass GPIO numbers used by
266*4882a593Smuzhiyunthe device to the driver. ACPI 5.1 extended this with _DSD (Device
267*4882a593SmuzhiyunSpecific Data) which made it possible to name the GPIOs among other things.
268*4882a593Smuzhiyun
269*4882a593SmuzhiyunFor example::
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun	Device (DEV)
272*4882a593Smuzhiyun	{
273*4882a593Smuzhiyun		Method (_CRS, 0, NotSerialized)
274*4882a593Smuzhiyun		{
275*4882a593Smuzhiyun			Name (SBUF, ResourceTemplate()
276*4882a593Smuzhiyun			{
277*4882a593Smuzhiyun				...
278*4882a593Smuzhiyun				// Used to power on/off the device
279*4882a593Smuzhiyun				GpioIo (Exclusive, PullDefault, 0x0000, 0x0000,
280*4882a593Smuzhiyun					IoRestrictionOutputOnly, "\\_SB.PCI0.GPI0",
281*4882a593Smuzhiyun					0x00, ResourceConsumer,,)
282*4882a593Smuzhiyun				{
283*4882a593Smuzhiyun					// Pin List
284*4882a593Smuzhiyun					0x0055
285*4882a593Smuzhiyun				}
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun				// Interrupt for the device
288*4882a593Smuzhiyun				GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone,
289*4882a593Smuzhiyun					0x0000, "\\_SB.PCI0.GPI0", 0x00, ResourceConsumer,,)
290*4882a593Smuzhiyun				{
291*4882a593Smuzhiyun					// Pin list
292*4882a593Smuzhiyun					0x0058
293*4882a593Smuzhiyun				}
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun				...
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun			}
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun			Return (SBUF)
300*4882a593Smuzhiyun		}
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun		// ACPI 5.1 _DSD used for naming the GPIOs
303*4882a593Smuzhiyun		Name (_DSD, Package ()
304*4882a593Smuzhiyun		{
305*4882a593Smuzhiyun			ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
306*4882a593Smuzhiyun			Package ()
307*4882a593Smuzhiyun			{
308*4882a593Smuzhiyun				Package () {"power-gpios", Package() {^DEV, 0, 0, 0 }},
309*4882a593Smuzhiyun				Package () {"irq-gpios", Package() {^DEV, 1, 0, 0 }},
310*4882a593Smuzhiyun			}
311*4882a593Smuzhiyun		})
312*4882a593Smuzhiyun		...
313*4882a593Smuzhiyun
314*4882a593SmuzhiyunThese GPIO numbers are controller relative and path "\\_SB.PCI0.GPI0"
315*4882a593Smuzhiyunspecifies the path to the controller. In order to use these GPIOs in Linux
316*4882a593Smuzhiyunwe need to translate them to the corresponding Linux GPIO descriptors.
317*4882a593Smuzhiyun
318*4882a593SmuzhiyunThere is a standard GPIO API for that and is documented in
319*4882a593SmuzhiyunDocumentation/admin-guide/gpio/.
320*4882a593Smuzhiyun
321*4882a593SmuzhiyunIn the above example we can get the corresponding two GPIO descriptors with
322*4882a593Smuzhiyuna code like this::
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun	#include <linux/gpio/consumer.h>
325*4882a593Smuzhiyun	...
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun	struct gpio_desc *irq_desc, *power_desc;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun	irq_desc = gpiod_get(dev, "irq");
330*4882a593Smuzhiyun	if (IS_ERR(irq_desc))
331*4882a593Smuzhiyun		/* handle error */
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun	power_desc = gpiod_get(dev, "power");
334*4882a593Smuzhiyun	if (IS_ERR(power_desc))
335*4882a593Smuzhiyun		/* handle error */
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun	/* Now we can use the GPIO descriptors */
338*4882a593Smuzhiyun
339*4882a593SmuzhiyunThere are also devm_* versions of these functions which release the
340*4882a593Smuzhiyundescriptors once the device is released.
341*4882a593Smuzhiyun
342*4882a593SmuzhiyunSee Documentation/firmware-guide/acpi/gpio-properties.rst for more information about the
343*4882a593Smuzhiyun_DSD binding related to GPIOs.
344*4882a593Smuzhiyun
345*4882a593SmuzhiyunMFD devices
346*4882a593Smuzhiyun===========
347*4882a593Smuzhiyun
348*4882a593SmuzhiyunThe MFD devices register their children as platform devices. For the child
349*4882a593Smuzhiyundevices there needs to be an ACPI handle that they can use to reference
350*4882a593Smuzhiyunparts of the ACPI namespace that relate to them. In the Linux MFD subsystem
351*4882a593Smuzhiyunwe provide two ways:
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun  - The children share the parent ACPI handle.
354*4882a593Smuzhiyun  - The MFD cell can specify the ACPI id of the device.
355*4882a593Smuzhiyun
356*4882a593SmuzhiyunFor the first case, the MFD drivers do not need to do anything. The
357*4882a593Smuzhiyunresulting child platform device will have its ACPI_COMPANION() set to point
358*4882a593Smuzhiyunto the parent device.
359*4882a593Smuzhiyun
360*4882a593SmuzhiyunIf the ACPI namespace has a device that we can match using an ACPI id or ACPI
361*4882a593Smuzhiyunadr, the cell should be set like::
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun	static struct mfd_cell_acpi_match my_subdevice_cell_acpi_match = {
364*4882a593Smuzhiyun		.pnpid = "XYZ0001",
365*4882a593Smuzhiyun		.adr = 0,
366*4882a593Smuzhiyun	};
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun	static struct mfd_cell my_subdevice_cell = {
369*4882a593Smuzhiyun		.name = "my_subdevice",
370*4882a593Smuzhiyun		/* set the resources relative to the parent */
371*4882a593Smuzhiyun		.acpi_match = &my_subdevice_cell_acpi_match,
372*4882a593Smuzhiyun	};
373*4882a593Smuzhiyun
374*4882a593SmuzhiyunThe ACPI id "XYZ0001" is then used to lookup an ACPI device directly under
375*4882a593Smuzhiyunthe MFD device and if found, that ACPI companion device is bound to the
376*4882a593Smuzhiyunresulting child platform device.
377*4882a593Smuzhiyun
378*4882a593SmuzhiyunDevice Tree namespace link device ID
379*4882a593Smuzhiyun====================================
380*4882a593Smuzhiyun
381*4882a593SmuzhiyunThe Device Tree protocol uses device identification based on the "compatible"
382*4882a593Smuzhiyunproperty whose value is a string or an array of strings recognized as device
383*4882a593Smuzhiyunidentifiers by drivers and the driver core.  The set of all those strings may be
384*4882a593Smuzhiyunregarded as a device identification namespace analogous to the ACPI/PNP device
385*4882a593SmuzhiyunID namespace.  Consequently, in principle it should not be necessary to allocate
386*4882a593Smuzhiyuna new (and arguably redundant) ACPI/PNP device ID for a devices with an existing
387*4882a593Smuzhiyunidentification string in the Device Tree (DT) namespace, especially if that ID
388*4882a593Smuzhiyunis only needed to indicate that a given device is compatible with another one,
389*4882a593Smuzhiyunpresumably having a matching driver in the kernel already.
390*4882a593Smuzhiyun
391*4882a593SmuzhiyunIn ACPI, the device identification object called _CID (Compatible ID) is used to
392*4882a593Smuzhiyunlist the IDs of devices the given one is compatible with, but those IDs must
393*4882a593Smuzhiyunbelong to one of the namespaces prescribed by the ACPI specification (see
394*4882a593SmuzhiyunSection 6.1.2 of ACPI 6.0 for details) and the DT namespace is not one of them.
395*4882a593SmuzhiyunMoreover, the specification mandates that either a _HID or an _ADR identification
396*4882a593Smuzhiyunobject be present for all ACPI objects representing devices (Section 6.1 of ACPI
397*4882a593Smuzhiyun6.0).  For non-enumerable bus types that object must be _HID and its value must
398*4882a593Smuzhiyunbe a device ID from one of the namespaces prescribed by the specification too.
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunThe special DT namespace link device ID, PRP0001, provides a means to use the
401*4882a593Smuzhiyunexisting DT-compatible device identification in ACPI and to satisfy the above
402*4882a593Smuzhiyunrequirements following from the ACPI specification at the same time.  Namely,
403*4882a593Smuzhiyunif PRP0001 is returned by _HID, the ACPI subsystem will look for the
404*4882a593Smuzhiyun"compatible" property in the device object's _DSD and will use the value of that
405*4882a593Smuzhiyunproperty to identify the corresponding device in analogy with the original DT
406*4882a593Smuzhiyundevice identification algorithm.  If the "compatible" property is not present
407*4882a593Smuzhiyunor its value is not valid, the device will not be enumerated by the ACPI
408*4882a593Smuzhiyunsubsystem.  Otherwise, it will be enumerated automatically as a platform device
409*4882a593Smuzhiyun(except when an I2C or SPI link from the device to its parent is present, in
410*4882a593Smuzhiyunwhich case the ACPI core will leave the device enumeration to the parent's
411*4882a593Smuzhiyundriver) and the identification strings from the "compatible" property value will
412*4882a593Smuzhiyunbe used to find a driver for the device along with the device IDs listed by _CID
413*4882a593Smuzhiyun(if present).
414*4882a593Smuzhiyun
415*4882a593SmuzhiyunAnalogously, if PRP0001 is present in the list of device IDs returned by _CID,
416*4882a593Smuzhiyunthe identification strings listed by the "compatible" property value (if present
417*4882a593Smuzhiyunand valid) will be used to look for a driver matching the device, but in that
418*4882a593Smuzhiyuncase their relative priority with respect to the other device IDs listed by
419*4882a593Smuzhiyun_HID and _CID depends on the position of PRP0001 in the _CID return package.
420*4882a593SmuzhiyunSpecifically, the device IDs returned by _HID and preceding PRP0001 in the _CID
421*4882a593Smuzhiyunreturn package will be checked first.  Also in that case the bus type the device
422*4882a593Smuzhiyunwill be enumerated to depends on the device ID returned by _HID.
423*4882a593Smuzhiyun
424*4882a593SmuzhiyunFor example, the following ACPI sample might be used to enumerate an lm75-type
425*4882a593SmuzhiyunI2C temperature sensor and match it to the driver using the Device Tree
426*4882a593Smuzhiyunnamespace link::
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun	Device (TMP0)
429*4882a593Smuzhiyun	{
430*4882a593Smuzhiyun		Name (_HID, "PRP0001")
431*4882a593Smuzhiyun		Name (_DSD, Package() {
432*4882a593Smuzhiyun			ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
433*4882a593Smuzhiyun			Package () {
434*4882a593Smuzhiyun				Package (2) { "compatible", "ti,tmp75" },
435*4882a593Smuzhiyun			}
436*4882a593Smuzhiyun		})
437*4882a593Smuzhiyun		Method (_CRS, 0, Serialized)
438*4882a593Smuzhiyun		{
439*4882a593Smuzhiyun			Name (SBUF, ResourceTemplate ()
440*4882a593Smuzhiyun			{
441*4882a593Smuzhiyun				I2cSerialBusV2 (0x48, ControllerInitiated,
442*4882a593Smuzhiyun					400000, AddressingMode7Bit,
443*4882a593Smuzhiyun					"\\_SB.PCI0.I2C1", 0x00,
444*4882a593Smuzhiyun					ResourceConsumer, , Exclusive,)
445*4882a593Smuzhiyun			})
446*4882a593Smuzhiyun			Return (SBUF)
447*4882a593Smuzhiyun		}
448*4882a593Smuzhiyun	}
449*4882a593Smuzhiyun
450*4882a593SmuzhiyunIt is valid to define device objects with a _HID returning PRP0001 and without
451*4882a593Smuzhiyunthe "compatible" property in the _DSD or a _CID as long as one of their
452*4882a593Smuzhiyunancestors provides a _DSD with a valid "compatible" property.  Such device
453*4882a593Smuzhiyunobjects are then simply regarded as additional "blocks" providing hierarchical
454*4882a593Smuzhiyunconfiguration information to the driver of the composite ancestor device.
455*4882a593Smuzhiyun
456*4882a593SmuzhiyunHowever, PRP0001 can only be returned from either _HID or _CID of a device
457*4882a593Smuzhiyunobject if all of the properties returned by the _DSD associated with it (either
458*4882a593Smuzhiyunthe _DSD of the device object itself or the _DSD of its ancestor in the
459*4882a593Smuzhiyun"composite device" case described above) can be used in the ACPI environment.
460*4882a593SmuzhiyunOtherwise, the _DSD itself is regarded as invalid and therefore the "compatible"
461*4882a593Smuzhiyunproperty returned by it is meaningless.
462*4882a593Smuzhiyun
463*4882a593SmuzhiyunRefer to :doc:`DSD-properties-rules` for more information.
464