uclass-internal.h 8.0 KB

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