dm: Support parent devices with of-platdata
[platform/kernel/u-boot.git] / include / dm / platdata.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2013 Google, Inc
4  *
5  * (C) Copyright 2012
6  * Pavel Herrmann <morpheus.ibis@gmail.com>
7  * Marek Vasut <marex@denx.de>
8  */
9
10 #ifndef _DM_PLATDATA_H
11 #define _DM_PLATDATA_H
12
13 #include <linker_lists.h>
14
15 /**
16  * struct driver_info - Information required to instantiate a device
17  *
18  * NOTE: Avoid using this except in extreme circumstances, where device tree
19  * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
20  * available). U-Boot's driver model uses device tree for configuration.
21  *
22  * @name:       Driver name
23  * @platdata:   Driver-specific platform data
24  * @platdata_size: Size of platform data structure
25  * @parent_idx: Index of the parent driver_info structure
26  */
27 struct driver_info {
28         const char *name;
29         const void *platdata;
30 #if CONFIG_IS_ENABLED(OF_PLATDATA)
31         unsigned short platdata_size;
32         short parent_idx;
33 #endif
34 };
35
36 #if CONFIG_IS_ENABLED(OF_PLATDATA)
37 #define driver_info_parent_id(driver_info)      driver_info->parent_idx
38 #else
39 #define driver_info_parent_id(driver_info)      (-1)
40 #endif
41
42 /**
43  * driver_rt - runtime information set up by U-Boot
44  *
45  * There is one of these for every driver_info in the linker list, indexed by
46  * the driver_info idx value.
47  *
48  * @dev: Device created from this idx
49  */
50 struct driver_rt {
51         struct udevice *dev;
52 };
53
54 /**
55  * NOTE: Avoid using these except in extreme circumstances, where device tree
56  * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
57  * available). U-Boot's driver model uses device tree for configuration.
58  */
59 #define U_BOOT_DEVICE(__name)                                           \
60         ll_entry_declare(struct driver_info, __name, driver_info)
61
62 /* Declare a list of devices. The argument is a driver_info[] array */
63 #define U_BOOT_DEVICES(__name)                                          \
64         ll_entry_declare_list(struct driver_info, __name, driver_info)
65
66 /**
67  * Get a pointer to a given device info given its name
68  *
69  * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a
70  * pointer to the struct driver_info created by that declaration.
71  *
72  * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of
73  * struct driver_info to find the device pointer itself.
74  *
75  * TODO(sjg@chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so
76  * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it
77  * finds the driver_info record, not the device.
78  *
79  * @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000)
80  * @return struct driver_info * to the driver that created the device
81  */
82 #define DM_GET_DEVICE(__name)                                           \
83         ll_entry_get(struct driver_info, __name, driver_info)
84
85 /**
86  * dm_populate_phandle_data() - Populates phandle data in platda
87  *
88  * This populates phandle data with an U_BOOT_DEVICE entry get by
89  * DM_GET_DEVICE. The implementation of this function will be done
90  * by dtoc when parsing dtb.
91  */
92 void dm_populate_phandle_data(void);
93 #endif