uclass-internal.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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_bind_device() - Associate device with a uclass
  95. *
  96. * Connect the device into uclass's list of devices.
  97. *
  98. * @dev: Pointer to the device
  99. * #return 0 on success, -ve on error
  100. */
  101. int uclass_bind_device(struct udevice *dev);
  102. /**
  103. * uclass_unbind_device() - Deassociate device with a uclass
  104. *
  105. * Disconnect the device from uclass's list of devices.
  106. *
  107. * @dev: Pointer to the device
  108. * #return 0 on success, -ve on error
  109. */
  110. #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
  111. int uclass_unbind_device(struct udevice *dev);
  112. #else
  113. static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
  114. #endif
  115. /**
  116. * uclass_pre_probe_device() - Deal with a device that is about to be probed
  117. *
  118. * Perform any pre-processing that is needed by the uclass before it can be
  119. * probed. This includes the uclass' pre-probe() method and the parent
  120. * uclass' child_pre_probe() method.
  121. *
  122. * @dev: Pointer to the device
  123. * #return 0 on success, -ve on error
  124. */
  125. int uclass_pre_probe_device(struct udevice *dev);
  126. /**
  127. * uclass_post_probe_device() - Deal with a device that has just been probed
  128. *
  129. * Perform any post-processing of a probed device that is needed by the
  130. * uclass.
  131. *
  132. * @dev: Pointer to the device
  133. * #return 0 on success, -ve on error
  134. */
  135. int uclass_post_probe_device(struct udevice *dev);
  136. /**
  137. * uclass_pre_remove_device() - Handle a device which is about to be removed
  138. *
  139. * Perform any pre-processing of a device that is about to be removed.
  140. *
  141. * @dev: Pointer to the device
  142. * #return 0 on success, -ve on error
  143. */
  144. #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
  145. int uclass_pre_remove_device(struct udevice *dev);
  146. #else
  147. static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
  148. #endif
  149. /**
  150. * uclass_find() - Find uclass by its id
  151. *
  152. * @id: Id to serach for
  153. * @return pointer to uclass, or NULL if not found
  154. */
  155. struct uclass *uclass_find(enum uclass_id key);
  156. /**
  157. * uclass_destroy() - Destroy a uclass
  158. *
  159. * Destroy a uclass and all its devices
  160. *
  161. * @uc: uclass to destroy
  162. * @return 0 on success, -ve on error
  163. */
  164. int uclass_destroy(struct uclass *uc);
  165. #endif