hotplug_manager.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2018 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file hotplug manager interface
  8. * @brief manager all hotplug devive, include hotplug detected,
  9. * state report , and get hotplug state.
  10. */
  11. #ifndef __HOTPLUG_MANAGER_H__
  12. #define __HOTPLUG_MANAGER_H__
  13. //#include <hotplug.h>
  14. /**
  15. * @defgroup hotplug_manager_apis App hot plug Manager APIs
  16. * @ingroup system_apis
  17. * @{
  18. */
  19. /** hotplug state enum */
  20. typedef enum
  21. {
  22. /** hotplug state not changed */
  23. HOTPLUG_NONE,
  24. /** hotplug state plug in*/
  25. HOTPLUG_IN,
  26. /** hotplug state plug out*/
  27. HOTPLUG_OUT,
  28. }hotplug_state_e;
  29. /** hotplug device type enum */
  30. typedef enum
  31. {
  32. /** hotplug type linein*/
  33. HOTPLUG_LINEIN = 1,
  34. /** hotplug type sdcard*/
  35. HOTPLUG_SDCARD,
  36. /** hotplug type usb device*/
  37. HOTPLUG_USB_DEVICE,
  38. /** hotplug type usb host*/
  39. HOTPLUG_USB_HOST,
  40. /** hotplug type usb stub*/
  41. HOTPLUG_USB_STUB,
  42. /** hotplug type charger*/
  43. HOTPLUG_CHARGER,
  44. }hotplug_type_e;
  45. /**
  46. * @brief hotplug manager init function
  47. * @details init hotplug manager struct and init hotplug device
  48. * add monitor work to system monitor
  49. *
  50. * @return 0 success
  51. * @return others failed
  52. */
  53. int hotplug_manager_init(void);
  54. /**
  55. * @brief hotplug manager get device state
  56. *
  57. * @param hotplug_device_type hotplug type of device.
  58. *
  59. * @return hotplug state of target device
  60. */
  61. int hotplug_manager_get_state(int hotplug_device_type);
  62. /**
  63. * @cond INTERNAL_HIDDEN
  64. */
  65. /** @def MAX_HOTPLUG_DEVICE_NUM
  66. *
  67. * @brief support max hotplug device number
  68. *
  69. * @details max hotplug device number , if user want support much more devices
  70. * must modify this macros
  71. */
  72. #define MAX_HOTPLUG_DEVICE_NUM 5
  73. typedef int (*hotplug_device_get_type)(void);
  74. /** @def hotplug_device_get_state
  75. *
  76. * @brief type of function pointer of device get state
  77. *
  78. * @details this function return device state
  79. * @return hotplug_state_e
  80. */
  81. typedef int (*hotplug_device_get_state)(void);
  82. /** @def hotplug_device_hotplug_detect
  83. *
  84. * @brief type of function pointer of device hotplug detect
  85. *
  86. * @details this function return device hotplug state changed
  87. * @return hotplug_state_e
  88. */
  89. typedef int (*hotplug_device_hotplug_detect)(void);
  90. /** @def hotplug_device_hotplug_fs_process
  91. *
  92. * @brief type of function pointer of device hot plug fs process
  93. *
  94. * @details this function do fs process accodrding device state
  95. * such as: mount fs when storage plugin and unmount fs when storage plug out
  96. * @return 0 int success
  97. * @others failed
  98. *
  99. */
  100. typedef int (*hotplug_device_hotplug_fs_process)(int device_state);
  101. /** hotpulg device structure */
  102. struct hotplug_device_t {
  103. /**type of device type @hotplug_type_e */
  104. uint8_t type;
  105. hotplug_device_get_type get_type;
  106. /**function pointer of get state ,plug in or plug out*/
  107. hotplug_device_get_state get_state;
  108. /**function pointer of detect */
  109. hotplug_device_hotplug_detect hotplug_detect;
  110. /**function pointer of fs prorss when device hotplug in/ hotplug out */
  111. hotplug_device_hotplug_fs_process fs_process;
  112. };
  113. struct hotplug_manager_context_t {
  114. uint8_t device_num;
  115. const struct hotplug_device_t *device[MAX_HOTPLUG_DEVICE_NUM];
  116. };
  117. int hotplug_linein_init(void);
  118. int hotplug_sdcard_init(void);
  119. int hotplug_usb_init(void);
  120. uint8_t usb_hotplug_get_otgstate(void);
  121. bool usb_hotplug_device_mode(void);
  122. int hotplug_charger_init(void);
  123. /**
  124. * @brief register hotplug device
  125. *
  126. * @param device register device
  127. *
  128. * @return 0 success
  129. * @return others failed
  130. */
  131. int hotplug_device_register(const struct hotplug_device_t *device);
  132. /**
  133. * @brief unregister hotplug device
  134. *
  135. * @param device unregister device
  136. *
  137. * @return 0 success
  138. * @return others failed
  139. */
  140. int hotplug_device_unregister(const struct hotplug_device_t *device);
  141. /**
  142. * INTERNAL_HIDDEN @endcond
  143. */
  144. /**
  145. * @} end defgroup hotplug_manager_apis
  146. */
  147. #endif