hpm_lcb_drv.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_LCB_DRV_H
  8. #define HPM_LCB_DRV_H
  9. /**
  10. * @brief LCB APIs
  11. * @defgroup lcb_interface LCB driver APIs
  12. * @ingroup lcb_interfaces
  13. * @{
  14. */
  15. #include "hpm_common.h"
  16. #include "hpm_soc.h"
  17. #include "hpm_lcb_regs.h"
  18. typedef enum lcb_rxclk_sel {
  19. lcb_rxclk_sel_phy0 = 0,
  20. lcb_rxclk_sel_phy1 = 1,
  21. } lcb_rxclk_sel_t;
  22. typedef enum lcb_mode {
  23. lcb_mode_display = 0,
  24. lcb_mode_cam_link = 1,
  25. } lcb_mode_t;
  26. typedef enum lcb_display_mode_mapping {
  27. lcb_display_mode_mapping_vesa = 0,
  28. lcb_display_mode_mapping_jeida = 1,
  29. } lcb_display_mode_mapping_t;
  30. typedef enum lcb_display_mode_data_width {
  31. lcb_display_mode_data_width_18bit = 0,
  32. lcb_display_mode_data_width_24bit = 1,
  33. } lcb_display_mode_data_width_t;
  34. typedef struct lcb_display_mode_config {
  35. lcb_display_mode_mapping_t map;
  36. lcb_display_mode_data_width_t data_width;
  37. } lcb_display_mode_config_t;
  38. typedef enum lcb_cam_link_mode_data_width {
  39. lcb_cam_link_mode_data_width_24bit = 0,
  40. lcb_cam_link_mode_data_width_30bit = 1,
  41. lcb_cam_link_mode_data_width_36bit = 1,
  42. } lcb_cam_link_mode_data_width_t;
  43. typedef struct lcb_cam_link_mode_config {
  44. lcb_cam_link_mode_data_width_t data_width;
  45. } lcb_cam_link_mode_config_t;
  46. typedef struct lcb_config {
  47. lcb_rxclk_sel_t rxclk_sel;
  48. lcb_mode_t mode;
  49. union {
  50. lcb_display_mode_config_t display;
  51. lcb_cam_link_mode_config_t cam_link;
  52. };
  53. } lcb_config_t;
  54. /**
  55. * @brief Terminal impedance regulation
  56. */
  57. typedef enum lcb_lvds_phy_rterm {
  58. lcb_lvds_phy_rterm_hi_z = 0,
  59. lcb_lvds_phy_rterm_150_ohm = 1,
  60. lcb_lvds_phy_rterm_100_ohm = 8,
  61. lcb_lvds_phy_rterm_75_ohm = 15,
  62. } lcb_lvds_phy_rterm_t;
  63. typedef struct lcb_lvds_phy_data_lane_config {
  64. uint8_t dline_adj; /*!< Lane N skew adjustment value between data and clock. 0000000: max; 1111111: min */
  65. lcb_lvds_phy_rterm_t rterm; /*!< Terminal impedance regulation */
  66. } lcb_lvds_phy_data_lane_config_t;
  67. /**
  68. * @brief DLL loop delay adjustment minimum frequency
  69. */
  70. typedef enum lcb_lvds_phy_dll_delay_adj_min_freq {
  71. lcb_lvds_phy_dll_delay_adj_min_freq_40_70mhz = 0,
  72. lcb_lvds_phy_dll_delay_adj_min_freq_70_110mhz = 0,
  73. } lcb_lvds_phy_dll_delay_adj_min_freq_t;
  74. typedef struct lcb_lvds_phy_clk_lane_config {
  75. lcb_lvds_phy_dll_delay_adj_min_freq_t min_adj;
  76. uint16_t dll_tuning_int; /*!< DLL loop delay coarse adjustment initial value. 00000000: min ; 11111111: max */
  77. lcb_lvds_phy_rterm_t rterm; /*!< Terminal impedance regulation */
  78. } lcb_lvds_phy_clk_lane_config_t;
  79. typedef enum lcb_lvds_phy_data_lane_id {
  80. lcb_lvds_phy_data_lane_id_0 = 0,
  81. lcb_lvds_phy_data_lane_id_1 = 1,
  82. } lcb_lvds_phy_data_lane_id_t;
  83. #ifdef __cplusplus
  84. extern "C" {
  85. #endif
  86. /**
  87. * @brief get LCB of default config
  88. *
  89. * @param[out] cfg config of LCB
  90. */
  91. void lcb_get_default_config(lcb_config_t *cfg);
  92. /**
  93. * @brief LCB init
  94. *
  95. * @param[in] ptr LCB base address
  96. * @param[in] cfg config of LCB
  97. */
  98. void lcb_init(LCB_Type *ptr, lcb_config_t *cfg);
  99. /**
  100. * @brief get LCB clk_lane of default config
  101. *
  102. * @param[out] cfg config of clk_lane
  103. */
  104. void lcb_get_phy_clk_lane_default_config(lcb_lvds_phy_clk_lane_config_t *cfg);
  105. /**
  106. * @brief get LCB data_lane of default config
  107. *
  108. * @param[out] cfg config of data_lane
  109. */
  110. void lcb_get_phy_data_lane_default_config(lcb_lvds_phy_data_lane_config_t *cfg);
  111. /**
  112. * @brief LCB phy0 data lane config
  113. *
  114. * @param[in] ptr LCB base address
  115. * @param[in] cfg config of phy0 data lane
  116. * @param[in] lane_id data lane id
  117. */
  118. void lcb_lvds_phy0_data_lane_config(LCB_Type *ptr, lcb_lvds_phy_data_lane_config_t *cfg, lcb_lvds_phy_data_lane_id_t lane_id);
  119. /**
  120. * @brief LCB phy0 clk lane config
  121. *
  122. * @param[in] ptr LCB base address
  123. * @param[in] cfg config of phy0 clk lane
  124. */
  125. void lcb_lvds_phy0_clk_lane_config(LCB_Type *ptr, lcb_lvds_phy_clk_lane_config_t *cfg);
  126. /**
  127. * @brief LCB phy1 data lane config
  128. *
  129. * @param[in] ptr LCB base address
  130. * @param[in] cfg config of phy1 data lane
  131. * @param[in] lane_id data lane id
  132. */
  133. void lcb_lvds_phy1_data_lane_config(LCB_Type *ptr, lcb_lvds_phy_data_lane_config_t *cfg, lcb_lvds_phy_data_lane_id_t lane_id);
  134. /**
  135. * @brief LCB phy1 clk lane config
  136. *
  137. * @param[in] ptr LCB base address
  138. * @param[in] cfg config of phy1 clk lane
  139. */
  140. void lcb_lvds_phy1_clk_lane_config(LCB_Type *ptr, lcb_lvds_phy_clk_lane_config_t *cfg);
  141. /**
  142. * @brief power on LCB phy0
  143. *
  144. * @param[in] ptr LCB base address
  145. */
  146. void lcb_lvds_phy0_poweron(LCB_Type *ptr);
  147. /**
  148. * @brief power on LCB phy1
  149. *
  150. * @param[in] ptr LCB base address
  151. */
  152. void lcb_lvds_phy1_poweron(LCB_Type *ptr);
  153. /**
  154. * @brief power down LCB phy0
  155. *
  156. * @param[in] ptr LCB base address
  157. */
  158. void lcb_lvds_phy0_powerdown(LCB_Type *ptr);
  159. /**
  160. * @brief power on LCB phy1
  161. *
  162. * @param[in] ptr LCB base address
  163. */
  164. void lcb_lvds_phy1_powerdown(LCB_Type *ptr);
  165. /**
  166. * @brief check LCB phy0 is lock
  167. *
  168. * @param[in] ptr LCB base address
  169. */
  170. static inline bool lcb_lvds_phy0_dll_is_lock(LCB_Type *ptr)
  171. {
  172. return !!LCB_PHY_STAT_LVDS0_RX_PHY_DLL_LOCK_GET(ptr->PHY_STAT);
  173. }
  174. /**
  175. * @brief check LCB phy1 is lock
  176. *
  177. * @param[in] ptr LCB base address
  178. */
  179. static inline bool lcb_lvds_phy1_dll_is_lock(LCB_Type *ptr)
  180. {
  181. return !!LCB_PHY_STAT_LVDS1_RX_PHY_DLL_LOCK_GET(ptr->PHY_STAT);
  182. }
  183. /**
  184. * @brief check LCB display phy is lock
  185. *
  186. * @param[in] ptr LCB base address
  187. */
  188. static inline bool lcb_lvds_display_phy_dll_is_lock(LCB_Type *ptr)
  189. {
  190. return !!LCB_PHY_STAT_LVDS0_RX_PHY_DLL_LOCK_GET(ptr->PHY_STAT) &&
  191. !!LCB_PHY_STAT_LVDS1_RX_PHY_DLL_LOCK_GET(ptr->PHY_STAT);
  192. }
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. /**
  197. * @}
  198. */
  199. #endif /* HPM_LCB_DRV_H */