Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Google, Inc |
| 3 | * |
| 4 | * (C) Copyright 2012 |
| 5 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #ifndef _DM_UCLASS_INTERNAL_H |
| 11 | #define _DM_UCLASS_INTERNAL_H |
| 12 | |
| 13 | /** |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 14 | * uclass_get_device_tail() - handle the end of a get_device call |
| 15 | * |
| 16 | * This handles returning an error or probing a device as needed. |
| 17 | * |
| 18 | * @dev: Device that needs to be probed |
| 19 | * @ret: Error to return. If non-zero then the device is not probed |
| 20 | * @devp: Returns the value of 'dev' if there is no error |
| 21 | * @return ret, if non-zero, else the result of the device_probe() call |
| 22 | */ |
| 23 | int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); |
| 24 | |
| 25 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 26 | * uclass_find_device() - Return n-th child of uclass |
| 27 | * @id: Id number of the uclass |
| 28 | * @index: Position of the child in uclass's list |
| 29 | * #devp: Returns pointer to device, or NULL on error |
| 30 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 31 | * The device is not prepared for use - this is an internal function. |
| 32 | * The function uclass_get_device_tail() can be used to probe the device. |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 33 | * |
| 34 | * @return the uclass pointer of a child at the given index or |
| 35 | * return NULL on error. |
| 36 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 37 | int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 40 | * uclass_find_first_device() - Return the first device in a uclass |
| 41 | * @id: Id number of the uclass |
| 42 | * #devp: Returns pointer to device, or NULL on error |
| 43 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 44 | * The device is not prepared for use - this is an internal function. |
| 45 | * The function uclass_get_device_tail() can be used to probe the device. |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 46 | * |
| 47 | * @return 0 if OK (found or not found), -1 on error |
| 48 | */ |
| 49 | int uclass_find_first_device(enum uclass_id id, struct udevice **devp); |
| 50 | |
| 51 | /** |
| 52 | * uclass_find_next_device() - Return the next device in a uclass |
| 53 | * @devp: On entry, pointer to device to lookup. On exit, returns pointer |
| 54 | * to the next device in the same uclass, or NULL if none |
| 55 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 56 | * The device is not prepared for use - this is an internal function. |
| 57 | * The function uclass_get_device_tail() can be used to probe the device. |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 58 | * |
| 59 | * @return 0 if OK (found or not found), -1 on error |
| 60 | */ |
| 61 | int uclass_find_next_device(struct udevice **devp); |
| 62 | |
| 63 | /** |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 64 | * uclass_find_device_by_name() - Find uclass device based on ID and name |
| 65 | * |
Przemyslaw Marczak | c917772 | 2015-04-20 13:32:34 +0200 | [diff] [blame] | 66 | * This searches for a device with the exactly given name. |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 67 | * |
| 68 | * The device is NOT probed, it is merely returned. |
| 69 | * |
| 70 | * @id: ID to look up |
| 71 | * @name: name of a device to find |
| 72 | * @devp: Returns pointer to device (the first one with the name) |
| 73 | * @return 0 if OK, -ve on error |
| 74 | */ |
| 75 | int uclass_find_device_by_name(enum uclass_id id, const char *name, |
| 76 | struct udevice **devp); |
| 77 | |
| 78 | /** |
| 79 | * uclass_find_device_by_seq() - Find uclass device based on ID and sequence |
| 80 | * |
| 81 | * This searches for a device with the given seq or req_seq. |
| 82 | * |
| 83 | * For seq, if an active device has this sequence it will be returned. |
| 84 | * If there is no such device then this will return -ENODEV. |
| 85 | * |
| 86 | * For req_seq, if a device (whether activated or not) has this req_seq |
| 87 | * value, that device will be returned. This is a strong indication that |
| 88 | * the device will receive that sequence when activated. |
| 89 | * |
| 90 | * The device is NOT probed, it is merely returned. |
| 91 | * |
| 92 | * @id: ID to look up |
| 93 | * @seq_or_req_seq: Sequence number to find (0=first) |
| 94 | * @find_req_seq: true to find req_seq, false to find seq |
| 95 | * @devp: Returns pointer to device (there is only one per for each seq) |
| 96 | * @return 0 if OK, -ve on error |
| 97 | */ |
| 98 | int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, |
| 99 | bool find_req_seq, struct udevice **devp); |
| 100 | |
| 101 | /** |
Simon Glass | 96f0444 | 2016-01-21 19:43:57 -0700 | [diff] [blame^] | 102 | * uclass_find_device_by_of_offset() - Find a uclass device by device tree node |
| 103 | * |
| 104 | * This searches the devices in the uclass for one attached to the given |
| 105 | * device tree node. |
| 106 | * |
| 107 | * The device is NOT probed, it is merely returned. |
| 108 | * |
| 109 | * @id: ID to look up |
| 110 | * @node: Device tree offset to search for (if -ve then -ENODEV is returned) |
| 111 | * @devp: Returns pointer to device (there is only one for each node) |
| 112 | * @return 0 if OK, -ve on error |
| 113 | */ |
| 114 | int uclass_find_device_by_of_offset(enum uclass_id id, int node, |
| 115 | struct udevice **devp); |
| 116 | |
| 117 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 118 | * uclass_bind_device() - Associate device with a uclass |
| 119 | * |
| 120 | * Connect the device into uclass's list of devices. |
| 121 | * |
| 122 | * @dev: Pointer to the device |
| 123 | * #return 0 on success, -ve on error |
| 124 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 125 | int uclass_bind_device(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * uclass_unbind_device() - Deassociate device with a uclass |
| 129 | * |
| 130 | * Disconnect the device from uclass's list of devices. |
| 131 | * |
| 132 | * @dev: Pointer to the device |
| 133 | * #return 0 on success, -ve on error |
| 134 | */ |
Masahiro Yamada | 04aa00d | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 135 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 136 | int uclass_unbind_device(struct udevice *dev); |
Simon Glass | 8914c8a | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 137 | #else |
| 138 | static inline int uclass_unbind_device(struct udevice *dev) { return 0; } |
| 139 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 142 | * uclass_pre_probe_device() - Deal with a device that is about to be probed |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 143 | * |
| 144 | * Perform any pre-processing that is needed by the uclass before it can be |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 145 | * probed. This includes the uclass' pre-probe() method and the parent |
| 146 | * uclass' child_pre_probe() method. |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 147 | * |
| 148 | * @dev: Pointer to the device |
| 149 | * #return 0 on success, -ve on error |
| 150 | */ |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 151 | int uclass_pre_probe_device(struct udevice *dev); |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 154 | * uclass_post_probe_device() - Deal with a device that has just been probed |
| 155 | * |
| 156 | * Perform any post-processing of a probed device that is needed by the |
| 157 | * uclass. |
| 158 | * |
| 159 | * @dev: Pointer to the device |
| 160 | * #return 0 on success, -ve on error |
| 161 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 162 | int uclass_post_probe_device(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 163 | |
| 164 | /** |
| 165 | * uclass_pre_remove_device() - Handle a device which is about to be removed |
| 166 | * |
| 167 | * Perform any pre-processing of a device that is about to be removed. |
| 168 | * |
| 169 | * @dev: Pointer to the device |
| 170 | * #return 0 on success, -ve on error |
| 171 | */ |
Masahiro Yamada | 04aa00d | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 172 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 173 | int uclass_pre_remove_device(struct udevice *dev); |
Simon Glass | 8914c8a | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 174 | #else |
| 175 | static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; } |
| 176 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * uclass_find() - Find uclass by its id |
| 180 | * |
| 181 | * @id: Id to serach for |
| 182 | * @return pointer to uclass, or NULL if not found |
| 183 | */ |
| 184 | struct uclass *uclass_find(enum uclass_id key); |
| 185 | |
| 186 | /** |
| 187 | * uclass_destroy() - Destroy a uclass |
| 188 | * |
| 189 | * Destroy a uclass and all its devices |
| 190 | * |
| 191 | * @uc: uclass to destroy |
| 192 | * @return 0 on success, -ve on error |
| 193 | */ |
| 194 | int uclass_destroy(struct uclass *uc); |
| 195 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 196 | #endif |