mtk_dp_hal.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (c) 2020 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __DRTX_HAL_H__
  14. #define __DRTX_HAL_H__
  15. #include "mtk_dp_common.h"
  16. #define AUX_CMD_I2C_R_MOT0 0x01
  17. #define AUX_CMD_I2C_R 0x05
  18. #define AUX_CMD_NATIVE_R 0x09
  19. #define AuxWaitReplyLpCntNum 20000
  20. #define MASKBIT(a) (BIT((1 ? a) + 1) - BIT((0 ? a)))
  21. #define _BITMASK(loc_msb, loc_lsb) \
  22. ((1U << (loc_msb)) - (1U << (loc_lsb)) + (1U << (loc_msb)))
  23. #define BITMASK(x) _BITMASK(1 ? x, 0 ? x)
  24. enum DPTx_LANE_NUM {
  25. DPTx_LANE0 = 0x0,
  26. DPTx_LANE1 = 0x1,
  27. DPTx_LANE2 = 0x2,
  28. DPTx_LANE3 = 0x3,
  29. DPTx_LANE_MAX,
  30. };
  31. enum DPTx_LANE_Count {
  32. DPTx_LANE_0 = 0x0,
  33. DPTx_LANE_2 = 0x01,
  34. DPTx_LANE_4 = 0x02,
  35. };
  36. enum DPTx_LINK_Rate {
  37. DPTx_RATE_RBR = 0x06,
  38. DPTx_RATE_HBR = 0x0A,
  39. DPTx_RATE_HBR2 = 0x14,
  40. DPTx_RATE_HBR3 = 0x1E,
  41. };
  42. enum DPTx_SDP_PKG_TYPE {
  43. DPTx_SDPTYP_NONE = 0x00,
  44. DPTx_SDPTYP_ACM = 0x01,
  45. DPTx_SDPTYP_ISRC = 0x02,
  46. DPTx_SDPTYP_AVI = 0x03,
  47. DPTx_SDPTYP_AUI = 0x04,
  48. DPTx_SDPTYP_SPD = 0x05,
  49. DPTx_SDPTYP_MPEG = 0x06,
  50. DPTx_SDPTYP_NTSC = 0x07,
  51. DPTx_SDPTYP_VSP = 0x08,
  52. DPTx_SDPTYP_VSC = 0x09,
  53. DPTx_SDPTYP_EXT = 0x0A,
  54. DPTx_SDPTYP_PPS0 = 0x0B,
  55. DPTx_SDPTYP_PPS1 = 0x0C,
  56. DPTx_SDPTYP_PPS2 = 0x0D,
  57. DPTx_SDPTYP_PPS3 = 0x0E,
  58. DPTx_SDPTYP_DRM = 0x10,
  59. DPTx_SDPTYP_MAX_NUM
  60. };
  61. enum DPTx_SDP_HB1_PKG_TYPE {
  62. DP_SPEC_SDPTYP_RESERVE = 0x00,
  63. DP_SPEC_SDPTYP_AUDIO_TS = 0x01,
  64. DP_SPEC_SDPTYP_AUDIO = 0x02,
  65. DP_SPEC_SDPTYP_EXT = 0x04,
  66. DP_SPEC_SDPTYP_ACM = 0x05,
  67. DP_SPEC_SDPTYP_ISRC = 0x06,
  68. DP_SPEC_SDPTYP_VSC = 0x07,
  69. DP_SPEC_SDPTYP_CAMERA = 0x08,
  70. DP_SPEC_SDPTYP_PPS = 0x10,
  71. DP_SPEC_SDPTYP_EXT_VESA = 0x20,
  72. DP_SPEC_SDPTYP_EXT_CEA = 0x21,
  73. DP_SPEC_SDPTYP_NON_AINFO = 0x80,
  74. DP_SPEC_SDPTYP_VS_INFO = 0x81,
  75. DP_SPEC_SDPTYP_AVI_INFO = 0x82,
  76. DP_SPEC_SDPTYP_SPD_INFO = 0x83,
  77. DP_SPEC_SDPTYP_AINFO = 0x84,
  78. DP_SPEC_SDPTYP_MPG_INFO = 0x85,
  79. DP_SPEC_SDPTYP_NTSC_INFO = 0x86,
  80. DP_SPEC_SDPTYP_DRM_INFO = 0x87,
  81. DP_SPEC_SDPTYP_MAX_NUM
  82. };
  83. enum DP_COLOR_FORMAT_TYPE {
  84. DP_COLOR_FORMAT_RGB_444 = 0,
  85. DP_COLOR_FORMAT_YUV_422 = 1,
  86. DP_COLOR_FORMAT_YUV_444 = 2,
  87. DP_COLOR_FORMAT_YUV_420 = 3,
  88. DP_COLOR_FORMAT_YONLY = 4,
  89. DP_COLOR_FORMAT_RAW = 5,
  90. DP_COLOR_FORMAT_RESERVED = 6,
  91. DP_COLOR_FORMAT_DEFAULT = DP_COLOR_FORMAT_RGB_444,
  92. DP_COLOR_FORMAT_UNKNOWN = 15,
  93. };
  94. enum DP_COLOR_DEPTH_TYPE {
  95. DP_COLOR_DEPTH_6BIT = 0,
  96. DP_COLOR_DEPTH_8BIT = 1,
  97. DP_COLOR_DEPTH_10BIT = 2,
  98. DP_COLOR_DEPTH_12BIT = 3,
  99. DP_COLOR_DEPTH_16BIT = 4,
  100. DP_COLOR_DEPTH_UNKNOWN = 5,
  101. };
  102. enum AUDIO_FS {
  103. FS_22K = 0x0,
  104. FS_32K = 0x1,
  105. FS_44K = 0x2,
  106. FS_48K = 0x3,
  107. FS_88K = 0x4,
  108. FS_96K = 0x5,
  109. FS_176K = 0x6,
  110. FS_192K = 0x7,
  111. FS_MAX,
  112. };
  113. enum AUDIO_WORD_LEN {
  114. WL_16bit = 1,
  115. WL_20bit = 2,
  116. WL_24bit = 3,
  117. WL_MAX,
  118. };
  119. #define IEC_CH_STATUS_LEN 5
  120. union DPRX_AUDIO_CHSTS {
  121. struct{
  122. BYTE rev : 1;
  123. BYTE ISLPCM : 1;
  124. BYTE CopyRight : 1;
  125. BYTE AdditionFormatInfo : 3;
  126. BYTE ChannelStatusMode : 2;
  127. BYTE CategoryCode;
  128. BYTE SourceNumber : 4;
  129. BYTE ChannelNumber : 4;
  130. BYTE SamplingFreq : 4;
  131. BYTE ClockAccuary : 2;
  132. BYTE rev2 : 2;
  133. BYTE WordLen : 4;
  134. BYTE OriginalSamplingFreq : 4;
  135. } iec_ch_sts;
  136. BYTE AUD_CH_STS[IEC_CH_STATUS_LEN];
  137. };
  138. enum DPTx_PG_PURECOLOR {
  139. DPTX_PG_PURECOLOR_NONE = 0x0,
  140. DPTX_PG_PURECOLOR_BLUE = 0x1,
  141. DPTX_PG_PURECOLOR_GREEN = 0x2,
  142. DPTX_PG_PURECOLOR_RED = 0x3,
  143. DPTX_PG_PURECOLOR_MAX,
  144. };
  145. enum DPTx_PG_LOCATION {
  146. DPTX_PG_LOCATION_NONE = 0x0,
  147. DPTX_PG_LOCATION_ALL = 0x1,
  148. DPTX_PG_LOCATION_TOP = 0x2,
  149. DPTX_PG_LOCATION_BOTTOM = 0x3,
  150. DPTX_PG_LOCATION_LEFT_OF_TOP = 0x4,
  151. DPTX_PG_LOCATION_LEFT_OF_BOTTOM = 0x5,
  152. DPTX_PG_LOCATION_LEFT = 0x6,
  153. DPTX_PG_LOCATION_RIGHT = 0x7,
  154. DPTX_PG_LOCATION_LEFT_OF_LEFT = 0x8,
  155. DPTX_PG_LOCATION_RIGHT_OF_LEFT = 0x9,
  156. DPTX_PG_LOCATION_LEFT_OF_RIGHT = 0xA,
  157. DPTX_PG_LOCATION_RIGHT_OF_RIGHT = 0xB,
  158. DPTX_PG_LOCATION_MAX,
  159. };
  160. enum DPTx_PG_PIXEL_MASK {
  161. DPTX_PG_PIXEL_MASK_NONE = 0x0,
  162. DPTX_PG_PIXEL_ODD_MASK = 0x1,
  163. DPTX_PG_PIXEL_EVEN_MASK = 0x2,
  164. DPTX_PG_PIXEL_MASK_MAX,
  165. };
  166. enum DPTx_PG_TYPESEL {
  167. DPTX_PG_NONE = 0x0,
  168. DPTX_PG_PURE_COLOR = 0x1,
  169. DPTX_PG_VERTICAL_RAMPING = 0x2,
  170. DPTX_PG_HORIZONTAL_RAMPING = 0x3,
  171. DPTX_PG_VERTICAL_COLOR_BAR = 0x4,
  172. DPTX_PG_HORIZONTAL_COLOR_BAR = 0x5,
  173. DPTX_PG_CHESSBOARD_PATTERN = 0x6,
  174. DPTX_PG_SUB_PIXEL_PATTERN = 0x7,
  175. DPTX_PG_FRAME_PATTERN = 0x8,
  176. DPTX_PG_MAX,
  177. };
  178. u32 mtk_dp_read(struct mtk_dp *mtk_dp, u32 offset);
  179. void mtk_dp_write_byte(struct mtk_dp *mtk_dp, u32 addr, u8 val, u32 mask);
  180. void mtk_dp_mask(struct mtk_dp *mtk_dp, u32 offset, u32 val, u32 mask);
  181. void mtk_dp_write(struct mtk_dp *mtk_dp, u32 offset, u32 val);
  182. #define msReadByte(mtk_dp, u32Reg) mtk_dp_read(mtk_dp, u32Reg)
  183. #define msRead2Byte(mtk_dp, u32Reg) mtk_dp_read(mtk_dp, u32Reg)
  184. #define msRead4Byte(mtk_dp, u32Reg) mtk_dp_read(mtk_dp, u32Reg)
  185. #define msWriteByte(mtk_dp, u32Reg, u8Val) \
  186. mtk_dp_write_byte(mtk_dp, u32Reg, u8Val, 0xFF)
  187. #define msWrite2Byte(mtk_dp, u32Reg, u16Val) \
  188. mtk_dp_mask(mtk_dp, u32Reg, u16Val, 0xFFFF)
  189. #define msWrite4Byte(mtk_dp, u32Reg, u32Val) \
  190. mtk_dp_write(mtk_dp, u32Reg, u32Val)
  191. #define msWriteByteMask(mtk_dp, addr, val, mask) \
  192. mtk_dp_write_byte(mtk_dp, addr, val, mask)
  193. #define msWrite2ByteMask(mtk_dp, addr, val, mask) \
  194. mtk_dp_mask(mtk_dp, addr, val, mask)
  195. #define msWrite4ByteMask(mtk_dp, addr, val, mask) \
  196. mtk_dp_mask(mtk_dp, addr, val, mask)
  197. extern void mdrv_DPTx_HPD_ISREvent(struct mtk_dp *mtk_dp);
  198. void mhal_DPTx_USBC_HPD(struct mtk_dp *mtk_dp, bool conn);
  199. void mhal_DPTx_Fake_Plugin(struct mtk_dp *mtk_dp, bool conn);
  200. void mhal_dump_reg(struct mtk_dp *mtk_dp);
  201. void mhal_DPTx_Verify_Clock(struct mtk_dp *mtk_dp);
  202. void mhal_DPTx_ISR(struct mtk_dp *mtk_dp);
  203. BYTE mhal_DPTx_GetColorBpp(struct mtk_dp *mtk_dp);
  204. bool mhal_DPTx_AuxRead_Bytes(struct mtk_dp *mtk_dp,
  205. BYTE ubCmd, DWORD usDPCDADDR, size_t ubLength, BYTE *pRxBuf);
  206. bool mhal_DPTx_AuxWrite_Bytes(struct mtk_dp *mtk_dp,
  207. BYTE ubCmd, DWORD usDPCDADDR, size_t ubLength, BYTE *pData);
  208. bool mhal_DPTx_SetSwingtPreEmphasis(struct mtk_dp *mtk_dp, int lane_num,
  209. int swingValue, int preEmphasis);
  210. bool mhal_DPTx_ResetSwingtPreEmphasis(struct mtk_dp *mtk_dp);
  211. void mhal_DPTx_DigitalSwReset(struct mtk_dp *mtk_dp);
  212. bool mhal_DPTx_GetHPDPinLevel(struct mtk_dp *mtk_dp);
  213. void mhal_DPTx_SSCOnOffSetting(struct mtk_dp *mtk_dp, bool bENABLE);
  214. void mhal_DPTx_SWInterruptSet(struct mtk_dp *mtk_dp, WORD bstatus);
  215. void mhal_DPTx_SWInterruptClr(struct mtk_dp *mtk_dp, WORD bstatus);
  216. void mhal_DPTx_SWInterruptEnable(struct mtk_dp *mtk_dp, bool enable);
  217. void mhal_DPTx_HPDInterruptClr(struct mtk_dp *mtk_dp, BYTE bstatus);
  218. void mhal_DPTx_HPDInterruptEnable(struct mtk_dp *mtk_dp, bool enable);
  219. void mhal_DPTx_HPDDetectSetting(struct mtk_dp *mtk_dp);
  220. void mhal_DPTx_PHYSetting(struct mtk_dp *mtk_dp);
  221. void mhal_DPTx_AuxSetting(struct mtk_dp *mtk_dp);
  222. void mhal_DPTx_AdjustPHYSetting(struct mtk_dp *mtk_dp, BYTE c0, BYTE cp1);
  223. void mhal_DPTx_DigitalSetting(struct mtk_dp *mtk_dp);
  224. void mhal_DPTx_PSCTRL(bool AUXNHighEnable);
  225. void mhal_DPTx_SetTxLane(struct mtk_dp *mtk_dp, int Value);
  226. void mhal_DPTx_SetTxLaneToLane(struct mtk_dp *mtk_dp,
  227. BYTE ucLaneNum, BYTE ucSetLaneNum);
  228. void mhal_DPTx_SetPGMSA(struct mtk_dp *mtk_dp, BYTE Address, WORD Data);
  229. void mhal_DPTx_PHY_ResetPattern(struct mtk_dp *mtk_dp);
  230. void mhal_DPTx_PHY_SetIdlePattern(struct mtk_dp *mtk_dp, bool bENABLE);
  231. void mhal_DPTx_PHYD_Reset(struct mtk_dp *mtk_dp);
  232. void mhal_DPTx_PRBSEnable(struct mtk_dp *mtk_dp, bool bENABLE);
  233. void mhal_DPTx_PatternSelect(struct mtk_dp *mtk_dp, int Value);
  234. void mhal_DPTx_ComplianceEyeEnSetting(struct mtk_dp *mtk_dp, bool bENABLE);
  235. void mhal_DPTx_SetProgramPattern(struct mtk_dp *mtk_dp,
  236. BYTE Value, BYTE *usData);
  237. void mhal_DPTx_ProgramPatternEnable(struct mtk_dp *mtk_dp, bool bENABLE);
  238. void mhal_DPTx_SetTxTrainingPattern(struct mtk_dp *mtk_dp, int Value);
  239. void mhal_DPTx_SetEF_Mode(struct mtk_dp *mtk_dp, bool bENABLE);
  240. void mhal_DPTx_SetScramble(struct mtk_dp *mtk_dp, bool bENABLE);
  241. void mhal_DPTx_SetScramble_Type(struct mtk_dp *mtk_dp, bool bSelType);
  242. void mhal_DPTx_ShutDownDPTxPort(struct mtk_dp *mtk_dp);
  243. void mhal_DPTx_EnableFEC(struct mtk_dp *mtk_dp, bool bENABLE);
  244. void mhal_DPTx_EnableDSC(struct mtk_dp *mtk_dp, bool bENABLE);
  245. void mhal_DPTx_SetChunkSize(struct mtk_dp *mtk_dp,
  246. BYTE slice_num, WORD chunk_num,
  247. BYTE remainder, BYTE lane_count,
  248. BYTE hde_last_num, BYTE hde_num_even);
  249. void mhal_DPTx_InitialSetting(struct mtk_dp *mtk_dp);
  250. void mhal_DPTx_Set_Efuse_Value(struct mtk_dp *mtk_dp);
  251. void mhal_DPTx_VideoMuteSW(struct mtk_dp *mtk_dp, bool bENABLE);
  252. void mhal_DPTx_VideoMute(struct mtk_dp *mtk_dp, bool bENABLE);
  253. void mhal_DPTx_AudioMute(struct mtk_dp *mtk_dp, bool bENABLE);
  254. void mhal_DPTx_SetFreeSync(struct mtk_dp *mtk_dp, bool bENABLE);
  255. void mhal_DPTx_Set_VideoInterlance(struct mtk_dp *mtk_dp, bool bENABLE);
  256. void mhal_DPTx_EnableBypassMSA(struct mtk_dp *mtk_dp, bool bENABLE);
  257. void mhal_DPTx_PGEnable(struct mtk_dp *mtk_dp, bool bENABLE);
  258. void mhal_DPTx_PG_Pure_Color(struct mtk_dp *mtk_dp, BYTE BGR, DWORD ColorDepth);
  259. void mhal_DPTx_PG_VerticalRamping(struct mtk_dp *mtk_dp, BYTE BGR,
  260. DWORD ColorDepth, BYTE Location);
  261. void mhal_DPTx_PG_HorizontalRamping(struct mtk_dp *mtk_dp, BYTE BGR,
  262. DWORD ColorDepth, BYTE Location);
  263. void mhal_DPTx_PG_VerticalColorBar(struct mtk_dp *mtk_dp, BYTE Location);
  264. void mhal_DPTx_PG_HorizontalColorBar(struct mtk_dp *mtk_dp, BYTE Location);
  265. void mhal_DPTx_PG_Chessboard(struct mtk_dp *mtk_dp, BYTE Location,
  266. WORD Hde, WORD Vde);
  267. void mhal_DPTx_PG_SubPixel(struct mtk_dp *mtk_dp, BYTE Location);
  268. void mhal_DPTx_PG_Frame(struct mtk_dp *mtk_dp, BYTE Location,
  269. WORD Hde, WORD Vde);
  270. void mhal_DPTx_Set_MVIDx2(struct mtk_dp *mtk_dp, bool bEnable);
  271. bool mhal_DPTx_OverWrite_MN(struct mtk_dp *mtk_dp,
  272. bool bEnable, DWORD ulVideo_M, DWORD ulVideo_N);
  273. void mhal_DPTx_SetTU_SramRdStart(struct mtk_dp *mtk_dp, WORD uwValue);
  274. void mhal_DPTx_SetSDP_DownCntinitInHblanking(struct mtk_dp *mtk_dp,
  275. WORD uwValue);
  276. void mhal_DPTx_SetSDP_DownCntinit(struct mtk_dp *mtk_dp, WORD uwValue);
  277. void mhal_DPTx_SetTU_SetEncoder(struct mtk_dp *mtk_dp);
  278. void mhal_DPTx_SetMSA(struct mtk_dp *mtk_dp);
  279. void mhal_DPTx_SetMISC(struct mtk_dp *mtk_dp, BYTE ucMISC[2]);
  280. void mhal_DPTx_SetColorDepth(struct mtk_dp *mtk_dp, BYTE coloer_depth);
  281. void mhal_DPTx_SetColorFormat(struct mtk_dp *mtk_dp, BYTE enOutColorFormat);
  282. void mhal_DPTx_SPKG_SDP(struct mtk_dp *mtk_dp, bool bEnable, BYTE ucSDPType,
  283. BYTE *pHB, BYTE *pDB);
  284. void mhal_DPTx_SPKG_VSC_EXT_VESA(struct mtk_dp *mtk_dp, bool bEnable,
  285. BYTE ucHDR_NUM, BYTE *pDB);
  286. void mhal_DPTx_SPKG_VSC_EXT_CEA(struct mtk_dp *mtk_dp, bool bEnable,
  287. BYTE ucHDR_NUM, BYTE *pDB);
  288. BYTE mhal_DPTx_GetHPDIRQStatus(struct mtk_dp *mtk_dp);
  289. void mhal_DPTx_Audio_PG_EN(struct mtk_dp *mtk_dp, BYTE Channel, BYTE Fs,
  290. BYTE bEnable);
  291. void mhal_DPTx_Audio_PG_EN(struct mtk_dp *mtk_dp, BYTE Channel, BYTE Fs,
  292. BYTE bEnable);
  293. WORD mhal_DPTx_GetSWIRQStatus(struct mtk_dp *mtk_dp);
  294. void mhal_DPTx_Audio_Ch_Status_Set(struct mtk_dp *mtk_dp, BYTE Channel,
  295. BYTE Fs, BYTE Wordlength);
  296. void mhal_DPTx_Audio_SDP_Setting(struct mtk_dp *mtk_dp, BYTE Channel);
  297. void mhal_DPTx_Audio_M_Divider_Setting(struct mtk_dp *mtk_dp, BYTE Div);
  298. void mhal_DPTx_SetTxRate(struct mtk_dp *mtk_dp, int Value);
  299. void mhal_DPTx_AnalogPowerOnOff(struct mtk_dp *mtk_dp, bool enable);
  300. void mhal_DPTx_DataLanePNSwap(struct mtk_dp *mtk_dp, bool bENABLE);
  301. #endif //__DRTX_HAL_H__