hpm_lvb_drv.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_LVB_DRV_H
  8. #define HPM_LVB_DRV_H
  9. /**
  10. * @brief LVB APIs
  11. * @defgroup lvb_interface LVB driver APIs
  12. * @ingroup lvb_interfaces
  13. * @{
  14. */
  15. #include "hpm_common.h"
  16. #include "hpm_soc.h"
  17. #include "hpm_lvb_regs.h"
  18. /**
  19. * @brief LVB DI vsync polarity
  20. */
  21. typedef enum lvb_di_vsync_polarity {
  22. lvb_di_vsync_polarity_active_high = 0,
  23. lvb_di_vsync_polarity_active_low
  24. } lvb_di_vsync_polarity_t;
  25. /**
  26. * @brief Shift the LVDS TX PHY clock in relation to the data
  27. */
  28. typedef enum lvb_txclk_shift {
  29. lvb_txclk_shift_1100011 = 0,
  30. lvb_txclk_shift_1110001,
  31. lvb_txclk_shift_1111000,
  32. lvb_txclk_shift_1000111,
  33. lvb_txclk_shift_0001111,
  34. lvb_txclk_shift_0011110,
  35. lvb_txclk_shift_0111100,
  36. } lvb_txclk_shift_t;
  37. /**
  38. * @brief LVB config
  39. */
  40. typedef struct lvb_config {
  41. bool split_ch_is_reverse; /*!< Just for split mode, reverse two channel data */
  42. bool split_ch_data_is_unaligned; /*!< Just for split mode, two channel pixel data are aligned */
  43. bool split_hswhbp_width_is_even; /*!< Just for split mode, the sum of HSW and HBP width is even */
  44. bool split_mode_en; /*!< Note: when using split mode, ch0/1 should be enabled, and should select same DI */
  45. lvb_di_vsync_polarity_t di1_vsync_polarity; /*!< lvb di1 vsync polarity */
  46. lvb_di_vsync_polarity_t di0_vsync_polarity; /*!< lvb di0 vsync polarity */
  47. lvb_txclk_shift_t txclk_shift; /*!< Shift the LVDS TX PHY clock in relation to the data */
  48. } lvb_config_t;
  49. /**
  50. * @brief LVB channel pixel data mapping
  51. */
  52. typedef enum lvb_ch_mapping {
  53. lvb_ch_mapping_vesa = 0,
  54. lvb_ch_mapping_jeida,
  55. } lvb_ch_mapping_t;
  56. /**
  57. * @brief LVB channel pixel data source
  58. */
  59. typedef enum lvb_ch_data_source {
  60. lvb_ch_data_source_di0 = 0,
  61. lvb_ch_data_source_di1,
  62. } lv_ch_data_source_t;
  63. /**
  64. * @brief LVB channel number
  65. */
  66. typedef enum lvb_ch_num {
  67. lvb_ch_num_0 = 0,
  68. lvb_ch_num_1 = 1
  69. } lvb_ch_num_t;
  70. /**
  71. * @brief LVB channel config
  72. */
  73. typedef struct lvb_ch_config {
  74. lvb_ch_mapping_t map;
  75. lv_ch_data_source_t data_src;
  76. } lvb_ch_config_t;
  77. typedef enum lvb_lvds_lane_phase_sel {
  78. lvb_lvds_lane_phase_sel_0_ui = 0,
  79. lvb_lvds_lane_phase_sel_1_16_ui,
  80. lvb_lvds_lane_phase_sel_2_16_ui,
  81. lvb_lvds_lane_phase_sel_3_16_ui,
  82. lvb_lvds_lane_phase_sel_4_16_ui,
  83. lvb_lvds_lane_phase_sel_5_16_ui,
  84. lvb_lvds_lane_phase_sel_6_16_ui,
  85. lvb_lvds_lane_phase_sel_7_16_ui,
  86. lvb_lvds_lane_phase_sel_8_16_ui,
  87. lvb_lvds_lane_phase_sel_9_16_ui,
  88. lvb_lvds_lane_phase_sel_10_16_ui,
  89. lvb_lvds_lane_phase_sel_11_16_ui,
  90. lvb_lvds_lane_phase_sel_12_16_ui,
  91. lvb_lvds_lane_phase_sel_13_16_ui,
  92. lvb_lvds_lane_phase_sel_14_16_ui,
  93. lvb_lvds_lane_phase_sel_15_16_ui,
  94. } lvb_lvds_lane_phase_sel_t;
  95. typedef enum lvb_lvds_lane_amp {
  96. lvb_lvds_lane_amp_50_mv = 0,
  97. lvb_lvds_lane_amp_100_mv,
  98. lvb_lvds_lane_amp_150_mv,
  99. lvb_lvds_lane_amp_200_mv,
  100. lvb_lvds_lane_amp_250_mv,
  101. lvb_lvds_lane_amp_300_mv,
  102. lvb_lvds_lane_amp_350_mv,
  103. lvb_lvds_lane_amp_400_mv,
  104. lvb_lvds_lane_amp_450_mv,
  105. lvb_lvds_lane_amp_500_mv,
  106. lvb_lvds_lane_amp_550_mv,
  107. lvb_lvds_lane_amp_600_mv
  108. } lvb_lvds_lane_amp_t;
  109. typedef enum lvb_lvds_lane_vcom {
  110. lvb_lvds_lane_vcom_0_7_v = 0,
  111. lvb_lvds_lane_vcom_0_8_v,
  112. lvb_lvds_lane_vcom_0_9_v,
  113. lvb_lvds_lane_vcom_1_0_v,
  114. lvb_lvds_lane_vcom_1_1_v,
  115. lvb_lvds_lane_vcom_1_2_v,
  116. lvb_lvds_lane_vcom_1_3_v,
  117. lvb_lvds_lane_vcom_1_4_v,
  118. lvb_lvds_lane_vcom_1_5_v,
  119. } lvb_lvds_lane_vcom_t;
  120. typedef struct lvb_lvds_phy_lane_config {
  121. bool rterm_enable;
  122. bool tx_idle;
  123. lvb_lvds_lane_phase_sel_t phase_sel;
  124. lvb_lvds_lane_amp_t amp;
  125. lvb_lvds_lane_vcom_t vcom;
  126. bool fvco_div4;
  127. } lvb_lvds_phy_lane_config_t;
  128. typedef enum lvb_lvds_lane_idx {
  129. lvb_lvds_lane_idx_lvds0_tx0 = LVB_TX_PHY_LVDS0_TX0,
  130. lvb_lvds_lane_idx_lvds0_tx1 = LVB_TX_PHY_LVDS0_TX1,
  131. lvb_lvds_lane_idx_lvds0_tx2 = LVB_TX_PHY_LVDS0_TX2,
  132. lvb_lvds_lane_idx_lvds0_tx3 = LVB_TX_PHY_LVDS0_TX3,
  133. lvb_lvds_lane_idx_lvds0_txck = LVB_TX_PHY_LVDS0_TXCK,
  134. lvb_lvds_lane_idx_lvds1_tx0 = LVB_TX_PHY_LVDS1_TX0,
  135. lvb_lvds_lane_idx_lvds1_tx1 = LVB_TX_PHY_LVDS1_TX1,
  136. lvb_lvds_lane_idx_lvds1_tx2 = LVB_TX_PHY_LVDS1_TX2,
  137. lvb_lvds_lane_idx_lvds1_tx3 = LVB_TX_PHY_LVDS1_TX3,
  138. lvb_lvds_lane_idx_lvds1_txck = LVB_TX_PHY_LVDS1_TXCK,
  139. } lvb_lvds_lane_idx_t;
  140. #ifdef __cplusplus
  141. extern "C" {
  142. #endif
  143. /**
  144. * @brief get LVB of default config
  145. *
  146. * @param[out] cfg config of LVB
  147. */
  148. void lvb_get_default_config(lvb_config_t *cfg);
  149. /**
  150. * @brief LVB init
  151. *
  152. * @param[in] ptr LVB base address
  153. * @param[in] cfg config of LVB
  154. */
  155. void lvb_init(LVB_Type *ptr, lvb_config_t *cfg);
  156. /**
  157. * @brief get LVB channel of default config
  158. *
  159. * @param[out] ch_cfg config of LVB
  160. */
  161. void lvb_get_ch_default_config(lvb_ch_config_t *ch_cfg);
  162. /**
  163. * @brief LVB channel config
  164. *
  165. * @param[in] ptr LVB base address
  166. * @param[in] ch_num LVB channel number
  167. * @param[in] ch_cfg config of LVB channel
  168. */
  169. void lvb_ch_config(LVB_Type *ptr, lvb_ch_num_t ch_num, lvb_ch_config_t *ch_cfg);
  170. /**
  171. * @brief LVB channel enable
  172. *
  173. * @param[in] ptr LVB base address
  174. * @param[in] ch_num LVB channel number
  175. */
  176. void lvb_ch_enable(LVB_Type *ptr, lvb_ch_num_t ch_num);
  177. /**
  178. * @brief LVB channel disable
  179. *
  180. * @param[in] ptr LVB base address
  181. * @param[in] ch_num LVB channel number
  182. */
  183. void lvb_ch_disable(LVB_Type *ptr, lvb_ch_num_t ch_num);
  184. /**
  185. * @brief check LVB phy0 is lock
  186. *
  187. * @param[in] ptr LVB base address
  188. */
  189. static inline bool lvb_lvds_phy0_pll_is_lock(LVB_Type *ptr)
  190. {
  191. return !!LVB_PHY_STAT_LVDS0_TX_PHY_PLL_LOCK_GET(ptr->PHY_STAT);
  192. }
  193. /**
  194. * @brief check LVB phy1 is lock
  195. *
  196. * @param[in] ptr LVB base address
  197. */
  198. static inline bool lvb_lvds_phy1_pll_is_lock(LVB_Type *ptr)
  199. {
  200. return !!LVB_PHY_STAT_LVDS1_TX_PHY_PLL_LOCK_GET(ptr->PHY_STAT);
  201. }
  202. /**
  203. * @brief check LVB phy0 and phy1 is lock
  204. *
  205. * @param[in] ptr LVB base address
  206. */
  207. static inline bool lvb_lvds_phy_split_pll_is_lock(LVB_Type *ptr)
  208. {
  209. return !!LVB_PHY_STAT_LVDS0_TX_PHY_PLL_LOCK_GET(ptr->PHY_STAT) &&
  210. !!LVB_PHY_STAT_LVDS1_TX_PHY_PLL_LOCK_GET(ptr->PHY_STAT);
  211. }
  212. /**
  213. * @brief lvb lvds lane get default config
  214. *
  215. * @param[out] cfg lvds lane config @ref lvb_lvds_phy_lane_config_t
  216. */
  217. void lvb_lvds_phy_lane_get_default_config(lvb_lvds_phy_lane_config_t *cfg);
  218. /**
  219. * @brief lvb lvds lane init and config
  220. *
  221. * @param[in] ptr LVB base address
  222. * @param[in] tx_index lvds phy lane index @ref lvb_lvds_lane_idx_t
  223. * @param[in] cfg lvds lane config @ref lvb_lvds_phy_lane_config_t
  224. */
  225. void lvb_lvds_phy_lane_init(LVB_Type *ptr, lvb_lvds_lane_idx_t tx_index, lvb_lvds_phy_lane_config_t *cfg);
  226. /**
  227. * @brief power on LVB phy0
  228. *
  229. * @param[in] ptr LVB base address
  230. */
  231. void lvb_lvds_phy0_poweron(LVB_Type *ptr);
  232. /**
  233. * @brief power on LVB phy1
  234. *
  235. * @param[in] ptr LVB base address
  236. */
  237. void lvb_lvds_phy1_poweron(LVB_Type *ptr);
  238. /**
  239. * @brief power down LVB phy0
  240. *
  241. * @param[in] ptr LVB base address
  242. */
  243. void lvb_lvds_phy0_powerdown(LVB_Type *ptr);
  244. /**
  245. * @brief power down LVB phy0
  246. *
  247. * @param[in] ptr LVB base address
  248. */
  249. void lvb_lvds_phy1_powerdown(LVB_Type *ptr);
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. /**
  254. * @}
  255. */
  256. #endif /* HPM_LVB_DRV_H */