Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DM_ROOT_H_ |
| 10 | #define _DM_ROOT_H_ |
| 11 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 12 | struct udevice; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 13 | |
Simon Glass | 6f15653 | 2021-03-15 17:25:16 +1300 | [diff] [blame] | 14 | /* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */ |
| 15 | extern struct list_head uclass_head; |
| 16 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 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 | * |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 22 | * Return: pointer to root device, or NULL if not inited yet |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 23 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 24 | struct udevice *dm_root(void); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 25 | |
Simon Glass | 1b0deee | 2016-11-13 14:21:58 -0700 | [diff] [blame] | 26 | struct global_data; |
| 27 | /** |
| 28 | * dm_fixup_for_gd_move() - Handle global_data moving to a new place |
| 29 | * |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 30 | * @new_gd: Pointer to the new global data |
| 31 | * |
Simon Glass | 1b0deee | 2016-11-13 14:21:58 -0700 | [diff] [blame] | 32 | * The uclass list is part of global_data. Due to the way lists work, moving |
| 33 | * the list will cause it to become invalid. This function fixes that up so |
| 34 | * that the uclass list will work correctly. |
| 35 | */ |
| 36 | void dm_fixup_for_gd_move(struct global_data *new_gd); |
| 37 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 38 | /** |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 39 | * dm_scan_plat() - Scan all platform data and bind drivers |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 40 | * |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 41 | * This scans all available plat and creates drivers for each |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 42 | * |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 43 | * @pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC |
| 44 | * flag. If false bind all drivers. |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 45 | * Return: 0 if OK, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 46 | */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 47 | int dm_scan_plat(bool pre_reloc_only); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * dm_scan_fdt() - Scan the device tree and bind drivers |
| 51 | * |
Simon Glass | cebcebb | 2014-07-23 06:55:17 -0600 | [diff] [blame] | 52 | * This scans the device tree and creates a driver for each node. Only |
| 53 | * the top-level subnodes are examined. |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 54 | * |
Bin Meng | 004323a | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 55 | * @pre_reloc_only: If true, bind only nodes with special devicetree properties, |
| 56 | * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 57 | * Return: 0 if OK, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 58 | */ |
Simon Glass | 5039cab | 2020-11-28 17:50:09 -0700 | [diff] [blame] | 59 | int dm_scan_fdt(bool pre_reloc_only); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
Simon Glass | 4d71d60 | 2020-11-28 17:50:10 -0700 | [diff] [blame] | 62 | * dm_extended_scan() - Scan the device tree and bind drivers |
Patrice Chotard | bb3a45b | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 63 | * |
| 64 | * This calls dm_scna_dft() which scans the device tree and creates a driver |
| 65 | * for each node. the top-level subnodes are examined and also all sub-nodes |
| 66 | * of "clocks" node. |
| 67 | * |
Bin Meng | 004323a | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 68 | * @pre_reloc_only: If true, bind only nodes with special devicetree properties, |
| 69 | * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 70 | * Return: 0 if OK, -ve on error |
Patrice Chotard | bb3a45b | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 71 | */ |
Simon Glass | 4d71d60 | 2020-11-28 17:50:10 -0700 | [diff] [blame] | 72 | int dm_extended_scan(bool pre_reloc_only); |
Patrice Chotard | bb3a45b | 2017-09-04 14:55:56 +0200 | [diff] [blame] | 73 | |
| 74 | /** |
Simon Glass | 97e22e3 | 2014-07-23 06:55:23 -0600 | [diff] [blame] | 75 | * dm_scan_other() - Scan for other devices |
| 76 | * |
| 77 | * Some devices may not be visible to Driver Model. This weak function can |
| 78 | * be provided by boards which wish to create their own devices |
| 79 | * programmaticaly. They should do this by calling device_bind() on each |
| 80 | * device. |
| 81 | * |
Bin Meng | 004323a | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 82 | * @pre_reloc_only: If true, bind only nodes with special devicetree properties, |
| 83 | * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 84 | * Return: 0 if OK, -ve on error |
Simon Glass | 97e22e3 | 2014-07-23 06:55:23 -0600 | [diff] [blame] | 85 | */ |
| 86 | int dm_scan_other(bool pre_reloc_only); |
| 87 | |
| 88 | /** |
Simon Glass | a730c5d | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 89 | * dm_init_and_scan() - Initialise Driver Model structures and scan for devices |
| 90 | * |
| 91 | * This function initialises the roots of the driver tree and uclass trees, |
| 92 | * then scans and binds available devices from platform data and the FDT. |
| 93 | * This calls dm_init() to set up Driver Model structures. |
| 94 | * |
Bin Meng | 004323a | 2018-10-10 22:06:59 -0700 | [diff] [blame] | 95 | * @pre_reloc_only: If true, bind only nodes with special devicetree properties, |
| 96 | * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 97 | * Return: 0 if OK, -ve on error |
Simon Glass | a730c5d | 2014-07-23 06:55:04 -0600 | [diff] [blame] | 98 | */ |
| 99 | int dm_init_and_scan(bool pre_reloc_only); |
| 100 | |
| 101 | /** |
Simon Glass | 4dbb5cf | 2014-06-11 23:29:54 -0600 | [diff] [blame] | 102 | * dm_init() - Initialise Driver Model structures |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 103 | * |
| 104 | * This function will initialize roots of driver tree and class tree. |
| 105 | * This needs to be called before anything uses the DM |
| 106 | * |
Simon Glass | f19d9f2 | 2017-05-18 20:09:08 -0600 | [diff] [blame] | 107 | * @of_live: Enable live device tree |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 108 | * Return: 0 if OK, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 109 | */ |
Simon Glass | f19d9f2 | 2017-05-18 20:09:08 -0600 | [diff] [blame] | 110 | int dm_init(bool of_live); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 111 | |
Simon Glass | 0019758 | 2014-07-23 06:55:01 -0600 | [diff] [blame] | 112 | /** |
| 113 | * dm_uninit - Uninitialise Driver Model structures |
| 114 | * |
| 115 | * All devices will be removed and unbound |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 116 | * Return: 0 if OK, -ve on error |
Simon Glass | 0019758 | 2014-07-23 06:55:01 -0600 | [diff] [blame] | 117 | */ |
| 118 | int dm_uninit(void); |
| 119 | |
Stefan Roese | 505045d | 2017-03-27 10:58:53 +0200 | [diff] [blame] | 120 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
| 121 | /** |
| 122 | * dm_remove_devices_flags - Call remove function of all drivers with |
| 123 | * specific removal flags set to selectively |
| 124 | * remove drivers |
| 125 | * |
| 126 | * All devices with the matching flags set will be removed |
| 127 | * |
| 128 | * @flags: Flags for selective device removal |
Patrick Delaunay | 3df46be | 2022-01-12 10:53:43 +0100 | [diff] [blame] | 129 | * Return: 0 if OK, -ve on error |
Stefan Roese | 505045d | 2017-03-27 10:58:53 +0200 | [diff] [blame] | 130 | */ |
| 131 | int dm_remove_devices_flags(uint flags); |
| 132 | #else |
| 133 | static inline int dm_remove_devices_flags(uint flags) { return 0; } |
| 134 | #endif |
| 135 | |
Simon Glass | 51608c9 | 2021-12-16 20:59:32 -0700 | [diff] [blame] | 136 | /** |
| 137 | * dm_get_stats() - Get some stats for driver mode |
| 138 | * |
| 139 | * @device_countp: Returns total number of devices that are bound |
| 140 | * @uclass_countp: Returns total number of uclasses in use |
| 141 | */ |
| 142 | void dm_get_stats(int *device_countp, int *uclass_countp); |
| 143 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 144 | #endif |