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  */
8 
9 #ifndef _DM_ROOT_H_
10 #define _DM_ROOT_H_
11 
12 struct udevice;
13 
14 /* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */
15 extern struct list_head uclass_head;
16 
17 /**
18  * dm_root() - Return pointer to the top of the driver tree
19  *
20  * This function returns pointer to the root node of the driver tree,
21  *
22  * @return pointer to root device, or NULL if not inited yet
23  */
24 struct udevice *dm_root(void);
25 
26 struct global_data;
27 /**
28  * dm_fixup_for_gd_move() - Handle global_data moving to a new place
29  *
30  * The uclass list is part of global_data. Due to the way lists work, moving
31  * the list will cause it to become invalid. This function fixes that up so
32  * that the uclass list will work correctly.
33  */
34 void dm_fixup_for_gd_move(struct global_data *new_gd);
35 
36 /**
37  * dm_scan_plat() - Scan all platform data and bind drivers
38  *
39  * This scans all available plat and creates drivers for each
40  *
41  * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
42  * flag. If false bind all drivers.
43  * @return 0 if OK, -ve on error
44  */
45 int dm_scan_plat(bool pre_reloc_only);
46 
47 /**
48  * dm_scan_fdt() - Scan the device tree and bind drivers
49  *
50  * This scans the device tree and creates a driver for each node. Only
51  * the top-level subnodes are examined.
52  *
53  * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
54  * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
55  * @return 0 if OK, -ve on error
56  */
57 int dm_scan_fdt(bool pre_reloc_only);
58 
59 /**
60  * dm_extended_scan() - Scan the device tree and bind drivers
61  *
62  * This calls dm_scna_dft() which scans the device tree and creates a driver
63  * for each node. the top-level subnodes are examined and also all sub-nodes
64  * of "clocks" node.
65  *
66  * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
67  * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
68  * @return 0 if OK, -ve on error
69  */
70 int dm_extended_scan(bool pre_reloc_only);
71 
72 /**
73  * dm_scan_other() - Scan for other devices
74  *
75  * Some devices may not be visible to Driver Model. This weak function can
76  * be provided by boards which wish to create their own devices
77  * programmaticaly. They should do this by calling device_bind() on each
78  * device.
79  *
80  * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
81  * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
82  * @return 0 if OK, -ve on error
83  */
84 int dm_scan_other(bool pre_reloc_only);
85 
86 /**
87  * dm_init_and_scan() - Initialise Driver Model structures and scan for devices
88  *
89  * This function initialises the roots of the driver tree and uclass trees,
90  * then scans and binds available devices from platform data and the FDT.
91  * This calls dm_init() to set up Driver Model structures.
92  *
93  * @pre_reloc_only: If true, bind only nodes with special devicetree properties,
94  * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers.
95  * @return 0 if OK, -ve on error
96  */
97 int dm_init_and_scan(bool pre_reloc_only);
98 
99 /**
100  * dm_init() - Initialise Driver Model structures
101  *
102  * This function will initialize roots of driver tree and class tree.
103  * This needs to be called before anything uses the DM
104  *
105  * @of_live:	Enable live device tree
106  * @return 0 if OK, -ve on error
107  */
108 int dm_init(bool of_live);
109 
110 /**
111  * dm_uninit - Uninitialise Driver Model structures
112  *
113  * All devices will be removed and unbound
114  * @return 0 if OK, -ve on error
115  */
116 int dm_uninit(void);
117 
118 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
119 /**
120  * dm_remove_devices_flags - Call remove function of all drivers with
121  *                           specific removal flags set to selectively
122  *                           remove drivers
123  *
124  * All devices with the matching flags set will be removed
125  *
126  * @flags: Flags for selective device removal
127  * @return 0 if OK, -ve on error
128  */
129 int dm_remove_devices_flags(uint flags);
130 #else
dm_remove_devices_flags(uint flags)131 static inline int dm_remove_devices_flags(uint flags) { return 0; }
132 #endif
133 
134 #endif
135