Simon Glass | 6494d70 | 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 | /** |
| 14 | * uclass_find_device() - Return n-th child of uclass |
| 15 | * @id: Id number of the uclass |
| 16 | * @index: Position of the child in uclass's list |
| 17 | * #devp: Returns pointer to device, or NULL on error |
| 18 | * |
| 19 | * The device is not prepared for use - this is an internal function |
| 20 | * |
| 21 | * @return the uclass pointer of a child at the given index or |
| 22 | * return NULL on error. |
| 23 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 24 | int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 27 | * uclass_find_first_device() - Return the first device in a uclass |
| 28 | * @id: Id number of the uclass |
| 29 | * #devp: Returns pointer to device, or NULL on error |
| 30 | * |
| 31 | * The device is not prepared for use - this is an internal function |
| 32 | * |
| 33 | * @return 0 if OK (found or not found), -1 on error |
| 34 | */ |
| 35 | int uclass_find_first_device(enum uclass_id id, struct udevice **devp); |
| 36 | |
| 37 | /** |
| 38 | * uclass_find_next_device() - Return the next device in a uclass |
| 39 | * @devp: On entry, pointer to device to lookup. On exit, returns pointer |
| 40 | * to the next device in the same uclass, or NULL if none |
| 41 | * |
| 42 | * The device is not prepared for use - this is an internal function |
| 43 | * |
| 44 | * @return 0 if OK (found or not found), -1 on error |
| 45 | */ |
| 46 | int uclass_find_next_device(struct udevice **devp); |
| 47 | |
| 48 | /** |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame^] | 49 | * uclass_find_device_by_name() - Find uclass device based on ID and name |
| 50 | * |
| 51 | * This searches for a device with the given name. |
| 52 | * |
| 53 | * The device is NOT probed, it is merely returned. |
| 54 | * |
| 55 | * @id: ID to look up |
| 56 | * @name: name of a device to find |
| 57 | * @devp: Returns pointer to device (the first one with the name) |
| 58 | * @return 0 if OK, -ve on error |
| 59 | */ |
| 60 | int uclass_find_device_by_name(enum uclass_id id, const char *name, |
| 61 | struct udevice **devp); |
| 62 | |
| 63 | /** |
| 64 | * uclass_find_device_by_seq() - Find uclass device based on ID and sequence |
| 65 | * |
| 66 | * This searches for a device with the given seq or req_seq. |
| 67 | * |
| 68 | * For seq, if an active device has this sequence it will be returned. |
| 69 | * If there is no such device then this will return -ENODEV. |
| 70 | * |
| 71 | * For req_seq, if a device (whether activated or not) has this req_seq |
| 72 | * value, that device will be returned. This is a strong indication that |
| 73 | * the device will receive that sequence when activated. |
| 74 | * |
| 75 | * The device is NOT probed, it is merely returned. |
| 76 | * |
| 77 | * @id: ID to look up |
| 78 | * @seq_or_req_seq: Sequence number to find (0=first) |
| 79 | * @find_req_seq: true to find req_seq, false to find seq |
| 80 | * @devp: Returns pointer to device (there is only one per for each seq) |
| 81 | * @return 0 if OK, -ve on error |
| 82 | */ |
| 83 | int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, |
| 84 | bool find_req_seq, struct udevice **devp); |
| 85 | |
| 86 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 87 | * uclass_bind_device() - Associate device with a uclass |
| 88 | * |
| 89 | * Connect the device into uclass's list of devices. |
| 90 | * |
| 91 | * @dev: Pointer to the device |
| 92 | * #return 0 on success, -ve on error |
| 93 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 94 | int uclass_bind_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * uclass_unbind_device() - Deassociate device with a uclass |
| 98 | * |
| 99 | * Disconnect the device from uclass's list of devices. |
| 100 | * |
| 101 | * @dev: Pointer to the device |
| 102 | * #return 0 on success, -ve on error |
| 103 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 104 | int uclass_unbind_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 107 | * uclass_pre_probe_device() - Deal with a device that is about to be probed |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 108 | * |
| 109 | * Perform any pre-processing that is needed by the uclass before it can be |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 110 | * probed. This includes the uclass' pre-probe() method and the parent |
| 111 | * uclass' child_pre_probe() method. |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 112 | * |
| 113 | * @dev: Pointer to the device |
| 114 | * #return 0 on success, -ve on error |
| 115 | */ |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 116 | int uclass_pre_probe_device(struct udevice *dev); |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 119 | * uclass_post_probe_device() - Deal with a device that has just been probed |
| 120 | * |
| 121 | * Perform any post-processing of a probed device that is needed by the |
| 122 | * uclass. |
| 123 | * |
| 124 | * @dev: Pointer to the device |
| 125 | * #return 0 on success, -ve on error |
| 126 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 127 | int uclass_post_probe_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * uclass_pre_remove_device() - Handle a device which is about to be removed |
| 131 | * |
| 132 | * Perform any pre-processing of a device that is about to be removed. |
| 133 | * |
| 134 | * @dev: Pointer to the device |
| 135 | * #return 0 on success, -ve on error |
| 136 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 137 | int uclass_pre_remove_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * uclass_find() - Find uclass by its id |
| 141 | * |
| 142 | * @id: Id to serach for |
| 143 | * @return pointer to uclass, or NULL if not found |
| 144 | */ |
| 145 | struct uclass *uclass_find(enum uclass_id key); |
| 146 | |
| 147 | /** |
| 148 | * uclass_destroy() - Destroy a uclass |
| 149 | * |
| 150 | * Destroy a uclass and all its devices |
| 151 | * |
| 152 | * @uc: uclass to destroy |
| 153 | * @return 0 on success, -ve on error |
| 154 | */ |
| 155 | int uclass_destroy(struct uclass *uc); |
| 156 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 157 | #endif |