cdns-mhdp.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Cadence MHDP DP MST bridge driver.
  4. *
  5. * Copyright: 2018 Cadence Design Systems, Inc.
  6. *
  7. * Author: Quentin Schulz <quentin.schulz@free-electrons.com>
  8. */
  9. #ifndef CDNS_MHDP_H
  10. #define CDNS_MHDP_H
  11. #include <drm/drm_bridge.h>
  12. #include <drm/drm_connector.h>
  13. #include <drm/drm_dp_helper.h>
  14. #define CDNS_APB_CFG 0x00000
  15. #define CDNS_APB_CTRL (CDNS_APB_CFG + 0x00)
  16. #define CDNS_CPU_STALL BIT(3)
  17. #define CDNS_MAILBOX_FULL (CDNS_APB_CFG + 0x08)
  18. #define CDNS_MAILBOX_EMPTY (CDNS_APB_CFG + 0x0c)
  19. #define CDNS_MAILBOX_TX_DATA (CDNS_APB_CFG + 0x10)
  20. #define CDNS_MAILBOX_RX_DATA (CDNS_APB_CFG + 0x14)
  21. #define CDNS_KEEP_ALIVE (CDNS_APB_CFG + 0x18)
  22. #define CDNS_KEEP_ALIVE_MASK GENMASK(7, 0)
  23. #define CDNS_MB_INT_MASK (CDNS_APB_CFG + 0x34)
  24. #define CDNS_MB_INT_STATUS (CDNS_APB_CFG + 0x38)
  25. #define CDNS_SW_CLK_L (CDNS_APB_CFG + 0x3c)
  26. #define CDNS_SW_CLK_H (CDNS_APB_CFG + 0x40)
  27. #define CDNS_SW_EVENT0 (CDNS_APB_CFG + 0x44)
  28. #define CDNS_DPTX_HPD BIT(0)
  29. #define CDNS_SW_EVENT1 (CDNS_APB_CFG + 0x48)
  30. #define CDNS_SW_EVENT2 (CDNS_APB_CFG + 0x4c)
  31. #define CDNS_SW_EVENT3 (CDNS_APB_CFG + 0x50)
  32. #define CDNS_APB_INT_MASK (CDNS_APB_CFG + 0x6C)
  33. #define CDNS_APB_INT_MASK_MAILBOX_INT BIT(0)
  34. #define CDNS_APB_INT_MASK_SW_EVENT_INT BIT(1)
  35. #define CDNS_APB_INT_STATUS (CDNS_APB_CFG + 0x70)
  36. #define CDNS_DPTX_CAR (CDNS_APB_CFG + 0x904)
  37. #define CDNS_VIF_CLK_EN BIT(0)
  38. #define CDNS_VIF_CLK_RSTN BIT(1)
  39. #define CDNS_SOURCE_VIDEO_IF(s) (0x00b00 + (s * 0x20))
  40. #define CDNS_BND_HSYNC2VSYNC(s) (CDNS_SOURCE_VIDEO_IF(s) + \
  41. 0x00)
  42. #define CDNS_IP_DTCT_WIN GENMASK(11, 0)
  43. #define CDNS_IP_DET_INTERLACE_FORMAT BIT(12)
  44. #define CDNS_IP_BYPASS_V_INTERFACE BIT(13)
  45. #define CDNS_HSYNC2VSYNC_POL_CTRL(s) (CDNS_SOURCE_VIDEO_IF(s) + \
  46. 0x10)
  47. #define CDNS_H2V_HSYNC_POL_ACTIVE_LOW BIT(1)
  48. #define CDNS_H2V_VSYNC_POL_ACTIVE_LOW BIT(2)
  49. #define CDNS_DPTX_PHY_CONFIG 0x02000
  50. #define CDNS_PHY_TRAINING_EN BIT(0)
  51. #define CDNS_PHY_TRAINING_TYPE(x) (((x) & GENMASK(3, 0)) << 1)
  52. #define CDNS_PHY_SCRAMBLER_BYPASS BIT(5)
  53. #define CDNS_PHY_ENCODER_BYPASS BIT(6)
  54. #define CDNS_PHY_SKEW_BYPASS BIT(7)
  55. #define CDNS_PHY_TRAINING_AUTO BIT(8)
  56. #define CDNS_PHY_LANE0_SKEW(x) (((x) & GENMASK(2, 0)) << 9)
  57. #define CDNS_PHY_LANE1_SKEW(x) (((x) & GENMASK(2, 0)) << 12)
  58. #define CDNS_PHY_LANE2_SKEW(x) (((x) & GENMASK(2, 0)) << 15)
  59. #define CDNS_PHY_LANE3_SKEW(x) (((x) & GENMASK(2, 0)) << 18)
  60. #define CDNS_PHY_COMMON_CONFIG (CDNS_PHY_LANE1_SKEW(1) | \
  61. CDNS_PHY_LANE2_SKEW(2) | \
  62. CDNS_PHY_LANE3_SKEW(3))
  63. #define CDNS_PHY_10BIT_EN BIT(21)
  64. #define CDNS_DPTX_FRAMER 0x02200
  65. #define CDNS_DP_FRAMER_GLOBAL_CONFIG (CDNS_DPTX_FRAMER + 0x00)
  66. #define CDNS_DP_NUM_LANES(x) (x - 1)
  67. #define CDNS_DP_MST_EN BIT(2)
  68. #define CDNS_DP_FRAMER_EN BIT(3)
  69. #define CDNS_DP_RATE_GOVERNOR_EN BIT(4)
  70. #define CDNS_DP_NO_VIDEO_MODE BIT(5)
  71. #define CDNS_DP_DISABLE_PHY_RST BIT(6)
  72. #define CDNS_DP_WR_FAILING_EDGE_VSYNC BIT(7)
  73. #define CDNS_DP_FRAMER_TU (CDNS_DPTX_FRAMER + 0x08)
  74. #define CDNS_DP_FRAMER_TU_SIZE(x) (((x) & GENMASK(6, 0)) << 8)
  75. #define CDNS_DP_FRAMER_TU_VS(x) ((x) & GENMASK(5, 0))
  76. #define CDNS_DP_FRAMER_TU_CNT_RST_EN BIT(15)
  77. #define CDNS_DPTX_STREAM(s) (0x03000 + s * 0x80)
  78. #define CDNS_DP_MSA_HORIZONTAL_0(s) (CDNS_DPTX_STREAM(s) + 0x00)
  79. #define CDNS_DP_MSAH0_H_TOTAL(x) (x)
  80. #define CDNS_DP_MSAH0_HSYNC_START(x) ((x) << 16)
  81. #define CDNS_DP_MSA_HORIZONTAL_1(s) (CDNS_DPTX_STREAM(s) + 0x04)
  82. #define CDNS_DP_MSAH1_HSYNC_WIDTH(x) (x)
  83. #define CDNS_DP_MSAH1_HSYNC_POL_LOW BIT(15)
  84. #define CDNS_DP_MSAH1_HDISP_WIDTH(x) ((x) << 16)
  85. #define CDNS_DP_MSA_VERTICAL_0(s) (CDNS_DPTX_STREAM(s) + 0x08)
  86. #define CDNS_DP_MSAV0_V_TOTAL(x) (x)
  87. #define CDNS_DP_MSAV0_VSYNC_START(x) ((x) << 16)
  88. #define CDNS_DP_MSA_VERTICAL_1(s) (CDNS_DPTX_STREAM(s) + 0x0c)
  89. #define CDNS_DP_MSAV1_VSYNC_WIDTH(x) (x)
  90. #define CDNS_DP_MSAV1_VSYNC_POL_LOW BIT(15)
  91. #define CDNS_DP_MSAV1_VDISP_WIDTH(x) ((x) << 16)
  92. #define CDNS_DP_MSA_MISC(s) (CDNS_DPTX_STREAM(s) + 0x10)
  93. #define CDNS_DP_STREAM_CONFIGs(s) (CDNS_DPTX_STREAM(s) + 0x14)
  94. #define CDNS_DP_STREAM_CONFIG_2(s) (CDNS_DPTX_STREAM(s) + 0x2c)
  95. #define CDNS_DP_SC2_TU_VS_DIFF(x) ((x) << 8)
  96. #define CDNS_DP_HORIZONTAL(s) (CDNS_DPTX_STREAM(s) + 0x30)
  97. #define CDNS_DP_H_HSYNC_WIDTH(x) (x)
  98. #define CDNS_DP_H_H_TOTAL(x) ((x) << 16)
  99. #define CDNS_DP_VERTICAL_0(s) (CDNS_DPTX_STREAM(s) + 0x34)
  100. #define CDNS_DP_V0_VHEIGHT(x) (x)
  101. #define CDNS_DP_V0_VSTART(x) ((x) << 16)
  102. #define CDNS_DP_VERTICAL_1(s) (CDNS_DPTX_STREAM(s) + 0x38)
  103. #define CDNS_DP_V1_VTOTAL(x) (x)
  104. #define CDNS_DP_V1_VTOTAL_EVEN BIT(16)
  105. #define CDNS_DP_FRAMER_PXL_REPR(s) (CDNS_DPTX_STREAM(s) + 0x4c)
  106. #define CDNS_DP_FRAMER_6_BPC BIT(0)
  107. #define CDNS_DP_FRAMER_8_BPC BIT(1)
  108. #define CDNS_DP_FRAMER_10_BPC BIT(2)
  109. #define CDNS_DP_FRAMER_12_BPC BIT(3)
  110. #define CDNS_DP_FRAMER_16_BPC BIT(4)
  111. #define CDNS_DP_FRAMER_PXL_FORMAT 0x8
  112. #define CDNS_DP_FRAMER_RGB BIT(0)
  113. #define CDNS_DP_FRAMER_YCBCR444 BIT(1)
  114. #define CDNS_DP_FRAMER_YCBCR422 BIT(2)
  115. #define CDNS_DP_FRAMER_YCBCR420 BIT(3)
  116. #define CDNS_DP_FRAMER_Y_ONLY BIT(4)
  117. #define CDNS_DP_FRAMER_SP(s) (CDNS_DPTX_STREAM(s) + 0x50)
  118. #define CDNS_DP_FRAMER_VSYNC_POL_LOW BIT(0)
  119. #define CDNS_DP_FRAMER_HSYNC_POL_LOW BIT(1)
  120. #define CDNS_DP_FRAMER_INTERLACE BIT(2)
  121. #define CDNS_DP_LINE_THRESH(s) (CDNS_DPTX_STREAM(s) + 0x64)
  122. #define CDNS_DP_ACTIVE_LINE_THRESH(x) (x)
  123. #define CDNS_DP_VB_ID(s) (CDNS_DPTX_STREAM(s) + 0x68)
  124. #define CDNS_DP_VB_ID_INTERLACED BIT(2)
  125. #define CDNS_DP_VB_ID_COMPRESSED BIT(6)
  126. #define CDNS_DP_FRONT_BACK_PORCH(s) (CDNS_DPTX_STREAM(s) + 0x78)
  127. #define CDNS_DP_BACK_PORCH(x) (x)
  128. #define CDNS_DP_FRONT_PORCH(x) ((x) << 16)
  129. #define CDNS_DP_BYTE_COUNT(s) (CDNS_DPTX_STREAM(s) + 0x7c)
  130. #define CDNS_DP_BYTE_COUNT_BYTES_IN_CHUNK_SHIFT 16
  131. #define CDNS_DP_MST_STREAM_CONFIG(s) (CDNS_DPTX_STREAM(s) + 0x14)
  132. #define CDNS_DP_MST_STRM_CFG_STREAM_EN BIT(0)
  133. #define CDNS_DP_MST_STRM_CFG_NO_VIDEO BIT(1)
  134. #define CDNS_DP_MST_SLOT_ALLOCATE(s) (CDNS_DPTX_STREAM(s) + 0x44)
  135. #define CDNS_DP_S_ALLOC_START_SLOT(x) (x)
  136. #define CDNS_DP_S_ALLOC_END_SLOT(x) ((x) << 8)
  137. #define CDNS_DP_RATE_GOVERNING(s) (CDNS_DPTX_STREAM(s) + 0x48)
  138. #define CDNS_DP_RG_TARG_AV_SLOTS_Y(x) (x)
  139. #define CDNS_DP_RG_TARG_AV_SLOTS_X(x) (x << 4)
  140. #define CDNS_DP_RG_ENABLE BIT(10)
  141. #define CDNS_DP_MTPH_CONTROL 0x2264
  142. #define CDNS_DP_MTPH_ECF_EN BIT(0)
  143. #define CDNS_DP_MTPH_ACT_EN BIT(1)
  144. #define CDNS_DP_MTPH_LVP_EN BIT(2)
  145. #define CDNS_DP_MTPH_STATUS 0x226C
  146. #define CDNS_DP_MTPH_ACT_STATUS BIT(0)
  147. #define CDNS_DPTX_GLOBAL 0x02300
  148. #define CDNS_DP_LANE_EN (CDNS_DPTX_GLOBAL + 0x00)
  149. #define CDNS_DP_LANE_EN_LANES(x) GENMASK(x - 1, 0)
  150. #define CDNS_DP_ENHNCD (CDNS_DPTX_GLOBAL + 0x04)
  151. struct cdns_mhdp_host {
  152. unsigned int link_rate;
  153. u8 lanes_cnt;
  154. u8 volt_swing;
  155. u8 pre_emphasis;
  156. u8 pattern_supp;
  157. u8 lane_mapping;
  158. u8 fast_link : 1;
  159. u8 enhanced : 1;
  160. u8 scrambler : 1;
  161. u8 ssc : 1;
  162. };
  163. struct cdns_mhdp_sink {
  164. unsigned int link_rate;
  165. u8 lanes_cnt;
  166. u8 pattern_supp;
  167. u8 fast_link : 1;
  168. u8 enhanced : 1;
  169. u8 ssc : 1;
  170. };
  171. struct cdns_mhdp_display_fmt {
  172. u32 color_format;
  173. u32 bpc;
  174. u8 y_only : 1;
  175. };
  176. /*
  177. * These enums present MHDP hw initialization state
  178. * Legal state transitions are:
  179. * MHDP_HW_INACTIVE <-> MHDP_HW_LOADING -> MHDP_HW_READY
  180. * | |
  181. * '----------> MHDP_HW_STOPPED <--------'
  182. */
  183. enum mhdp_hw_state { MHDP_HW_INACTIVE = 0, /* HW not initialized */
  184. MHDP_HW_LOADING, /* HW initialization in progress */
  185. MHDP_HW_READY, /* HW ready, FW active*/
  186. MHDP_HW_STOPPED }; /* Driver removal FW to be stopped */
  187. struct cdns_mhdp_device;
  188. struct mhdp_platform_ops {
  189. int (*init)(struct cdns_mhdp_device *mhdp);
  190. void (*exit)(struct cdns_mhdp_device *mhdp);
  191. void (*enable)(struct cdns_mhdp_device *mhdp);
  192. void (*disable)(struct cdns_mhdp_device *mhdp);
  193. };
  194. struct cdns_mhdp_device {
  195. void __iomem *regs;
  196. void __iomem *j721e_regs;
  197. struct device *dev;
  198. struct clk *clk;
  199. struct phy *phy;
  200. const struct mhdp_platform_ops *ops;
  201. /* This is to protect mailbox communications with the firmware */
  202. struct mutex mbox_mutex;
  203. struct drm_connector connector;
  204. struct drm_bridge bridge;
  205. struct drm_dp_link link;
  206. struct drm_dp_aux aux;
  207. struct cdns_mhdp_host host;
  208. struct cdns_mhdp_sink sink;
  209. struct cdns_mhdp_display_fmt display_fmt;
  210. s8 stream_id;
  211. u8 link_up : 1;
  212. u8 plugged : 1;
  213. /*
  214. * "start_lock" protects the access to bridge_attached and
  215. * hw_state data members that control the delayed firmware
  216. * loading and attaching the bridge. They are accessed from
  217. * both the DRM core and mhdp_fw_cb(). In most cases just
  218. * protecting the data members is enough, but the irq mask
  219. * setting needs to be protected when enabling the FW.
  220. */
  221. spinlock_t start_lock;
  222. u8 bridge_attached : 1;
  223. enum mhdp_hw_state hw_state;
  224. };
  225. #define connector_to_mhdp(x) container_of(x, struct cdns_mhdp_device, connector)
  226. #define bridge_to_mhdp(x) container_of(x, struct cdns_mhdp_device, bridge)
  227. #define CDNS_MHDP_MAX_STREAMS 4
  228. u32 cdns_mhdp_get_bpp(struct cdns_mhdp_display_fmt *fmt);
  229. void cdns_mhdp_configure_video(struct drm_bridge *bridge);
  230. void cdns_mhdp_enable(struct drm_bridge *bridge);
  231. #endif