uclass-internal.h 6.5 KB

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