xref: /optee_os/core/include/kernel/dt_driver.h (revision 8c0c44c9d2f768a95beacd4605776cfe29c9bff6)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2021, Linaro Limited
4  * Copyright (c) 2021, Bootlin
5  */
6 
7 #ifndef __DT_DRIVER_H
8 #define __DT_DRIVER_H
9 
10 #include <kernel/dt.h>
11 #include <stdint.h>
12 #include <sys/queue.h>
13 
14 /**
15  * struct dt_driver_phandle_args - Devicetree phandle arguments
16  * @args_count: Count of cells for the device
17  * @args: Device consumer specifiers
18  */
19 struct dt_driver_phandle_args {
20 	int args_count;
21 	uint32_t args[];
22 };
23 
24 /*
25  * get_of_device_func - Callback function for returning a driver private
26  *	instance based on a FDT phandle with possible arguments and the
27  *	registered dt_driver private data reference.
28  *
29  * @parg: phandle argument(s) referencing the device in the FDT.
30  * @data: driver private data registered in struct dt_driver.
31  *
32  * Return a device opaque reference, e.g. a struct clk pointer for a clock
33  * driver, or NULL if not found.
34  */
35 typedef void *(*get_of_device_func)(struct dt_driver_phandle_args *parg,
36 				    void *data);
37 
38 /*
39  * struct dt_driver_provider - DT related info on probed device
40  *
41  * Saves information on the probed device so that device
42  * drivers can get resources from DT phandle and related arguments.
43  *
44  * @nodeoffset: Node offset of device referenced in the FDT
45  * @type: One of DT_DRIVER_* or DT_DRIVER_NOTYPE.
46  * @provider_cells: Cells count in the FDT used by the driver's references
47  * @get_of_device: Function to get driver's device ref from phandle data
48  * @priv_data: Driver private data passed as @get_of_device argument
49  * @link: Reference in DT driver providers list
50  */
51 struct dt_driver_provider {
52 	int nodeoffset;
53 	enum dt_driver_type type;
54 	unsigned int provider_cells;
55 	uint32_t phandle;
56 	get_of_device_func get_of_device;
57 	void *priv_data;
58 	SLIST_ENTRY(dt_driver_provider) link;
59 };
60 
61 SLIST_HEAD(dt_driver_prov_list, dt_driver_provider);
62 extern struct dt_driver_prov_list dt_driver_provider_list;
63 #endif /* __DT_DRIVER_H */
64