uclass-internal.h 6.0 KB

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