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