uclass-internal.h 6.9 KB

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