dp_catalog_v420.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include "dp_catalog.h"
  7. #include "dp_reg.h"
  8. #include "dp_debug.h"
  9. #define MMSS_DP_PIXEL_BASE_V130 (0x1A8)
  10. #define MMSS_DP_PIXEL1_BASE_V130 (0x1C0)
  11. #define MMSS_DP_PIXEL_BASE_V140 (0x1BC)
  12. #define MMSS_DP_PIXEL1_BASE_V140 (0x1D4)
  13. #define MMSS_DP_M_OFF (0x8)
  14. #define MMSS_DP_N_OFF (0xC)
  15. #define dp_catalog_get_priv_v420(x) ({ \
  16. struct dp_catalog *catalog; \
  17. catalog = container_of(x, struct dp_catalog, x); \
  18. container_of(catalog->sub, \
  19. struct dp_catalog_private_v420, sub); \
  20. })
  21. #define dp_read(x) ({ \
  22. catalog->sub.read(catalog->dpc, io_data, x); \
  23. })
  24. #define dp_write(x, y) ({ \
  25. catalog->sub.write(catalog->dpc, io_data, x, y); \
  26. })
  27. #define MAX_VOLTAGE_LEVELS 4
  28. #define MAX_PRE_EMP_LEVELS 4
  29. static u8 const vm_pre_emphasis[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  30. {0x00, 0x0E, 0x16, 0xFF}, /* pe0, 0 db */
  31. {0x00, 0x0E, 0x16, 0xFF}, /* pe1, 3.5 db */
  32. {0x00, 0x0E, 0xFF, 0xFF}, /* pe2, 6.0 db */
  33. {0xFF, 0xFF, 0xFF, 0xFF} /* pe3, 9.5 db */
  34. };
  35. /* voltage swing, 0.2v and 1.0v are not support */
  36. static u8 const vm_voltage_swing[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  37. {0x07, 0x0F, 0x16, 0xFF}, /* sw0, 0.4v */
  38. {0x11, 0x1E, 0x1F, 0xFF}, /* sw1, 0.6 v */
  39. {0x1A, 0x1F, 0xFF, 0xFF}, /* sw1, 0.8 v */
  40. {0xFF, 0xFF, 0xFF, 0xFF} /* sw1, 1.2 v, optional */
  41. };
  42. static u8 const dp_pre_emp_hbr2_hbr3[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  43. {0x00, 0x0C, 0x15, 0x1B}, /* pe0, 0 db */
  44. {0x02, 0x0E, 0x16, 0xFF}, /* pe1, 3.5 db */
  45. {0x02, 0x11, 0xFF, 0xFF}, /* pe2, 6.0 db */
  46. {0x04, 0xFF, 0xFF, 0xFF} /* pe3, 9.5 db */
  47. };
  48. static u8 const dp_swing_hbr2_hbr3[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  49. {0x02, 0x12, 0x16, 0x1A}, /* sw0, 0.4v */
  50. {0x09, 0x19, 0x1F, 0xFF}, /* sw1, 0.6v */
  51. {0x10, 0x1F, 0xFF, 0xFF}, /* sw1, 0.8v */
  52. {0x1F, 0xFF, 0xFF, 0xFF} /* sw1, 1.2v */
  53. };
  54. static u8 const dp_pre_emp_hbr_rbr[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  55. {0x00, 0x0D, 0x14, 0x1A}, /* pe0, 0 db */
  56. {0x00, 0x0E, 0x15, 0xFF}, /* pe1, 3.5 db */
  57. {0x00, 0x0E, 0xFF, 0xFF}, /* pe2, 6.0 db */
  58. {0x03, 0xFF, 0xFF, 0xFF} /* pe3, 9.5 db */
  59. };
  60. static u8 const dp_swing_hbr_rbr[MAX_VOLTAGE_LEVELS][MAX_PRE_EMP_LEVELS] = {
  61. {0x08, 0x0F, 0x16, 0x1F}, /* sw0, 0.4v */
  62. {0x11, 0x1E, 0x1F, 0xFF}, /* sw1, 0.6v */
  63. {0x16, 0x1F, 0xFF, 0xFF}, /* sw1, 0.8v */
  64. {0x1F, 0xFF, 0xFF, 0xFF} /* sw1, 1.2v */
  65. };
  66. struct dp_catalog_private_v420 {
  67. struct device *dev;
  68. struct dp_catalog_sub sub;
  69. struct dp_catalog_io *io;
  70. struct dp_catalog *dpc;
  71. };
  72. static void dp_catalog_aux_setup_v420(struct dp_catalog_aux *aux,
  73. struct dp_aux_cfg *cfg)
  74. {
  75. struct dp_catalog_private_v420 *catalog;
  76. struct dp_io_data *io_data;
  77. int i = 0;
  78. u32 phy_version;
  79. if (!aux || !cfg) {
  80. DP_ERR("invalid input\n");
  81. return;
  82. }
  83. catalog = dp_catalog_get_priv_v420(aux);
  84. io_data = catalog->io->dp_phy;
  85. dp_write(DP_PHY_PD_CTL, 0x67);
  86. wmb(); /* make sure PD programming happened */
  87. phy_version = dp_catalog_get_dp_phy_version(catalog->dpc);
  88. if (phy_version >= 0x60000000) {
  89. /* Turn on BIAS current for PHY/PLL */
  90. io_data = catalog->io->dp_pll;
  91. dp_write(QSERDES_COM_BIAS_EN_CLKBUFLR_EN_V600, 0x17);
  92. wmb(); /* make sure BIAS programming happened */
  93. } else {
  94. /* Turn on BIAS current for PHY/PLL */
  95. io_data = catalog->io->dp_pll;
  96. dp_write(QSERDES_COM_BIAS_EN_CLKBUFLR_EN, 0x17);
  97. wmb(); /* make sure BIAS programming happened */
  98. }
  99. io_data = catalog->io->dp_phy;
  100. /* DP AUX CFG register programming */
  101. for (i = 0; i < PHY_AUX_CFG_MAX; i++) {
  102. DP_DEBUG("%s: offset=0x%08x, value=0x%08x\n",
  103. dp_phy_aux_config_type_to_string(i),
  104. cfg[i].offset, cfg[i].lut[cfg[i].current_index]);
  105. dp_write(cfg[i].offset, cfg[i].lut[cfg[i].current_index]);
  106. }
  107. wmb(); /* make sure DP AUX CFG programming happened */
  108. dp_write(DP_PHY_AUX_INTERRUPT_MASK_V420, 0x1F);
  109. }
  110. static void dp_catalog_aux_clear_hw_int_v420(struct dp_catalog_aux *aux)
  111. {
  112. struct dp_catalog_private_v420 *catalog;
  113. struct dp_io_data *io_data;
  114. u32 data = 0;
  115. u32 phy_version;
  116. if (!aux) {
  117. DP_ERR("invalid input\n");
  118. return;
  119. }
  120. catalog = dp_catalog_get_priv_v420(aux);
  121. phy_version = dp_catalog_get_dp_phy_version(catalog->dpc);
  122. io_data = catalog->io->dp_phy;
  123. if (phy_version >= 0x60000000)
  124. data = dp_read(DP_PHY_AUX_INTERRUPT_STATUS_V600);
  125. else
  126. data = dp_read(DP_PHY_AUX_INTERRUPT_STATUS_V420);
  127. dp_write(DP_PHY_AUX_INTERRUPT_CLEAR_V420, 0x1f);
  128. wmb(); /* make sure 0x1f is written before next write */
  129. dp_write(DP_PHY_AUX_INTERRUPT_CLEAR_V420, 0x9f);
  130. wmb(); /* make sure 0x9f is written before next write */
  131. dp_write(DP_PHY_AUX_INTERRUPT_CLEAR_V420, 0);
  132. wmb(); /* make sure register is cleared */
  133. }
  134. static void dp_catalog_panel_config_msa_v420(struct dp_catalog_panel *panel,
  135. u32 rate, u32 stream_rate_khz)
  136. {
  137. u32 pixel_m, pixel_n;
  138. u32 mvid, nvid, reg_off = 0, mvid_off = 0, nvid_off = 0;
  139. u32 const nvid_fixed = 0x8000;
  140. u32 const link_rate_hbr2 = 540000;
  141. u32 const link_rate_hbr3 = 810000;
  142. struct dp_catalog *dp_catalog;
  143. struct dp_catalog_private_v420 *catalog;
  144. struct dp_io_data *io_data;
  145. u32 version;
  146. if (!panel || !rate) {
  147. DP_ERR("invalid input\n");
  148. return;
  149. }
  150. if (panel->stream_id >= DP_STREAM_MAX) {
  151. DP_ERR("invalid stream id:%d\n", panel->stream_id);
  152. return;
  153. }
  154. dp_catalog = container_of(panel, struct dp_catalog, panel);
  155. catalog = container_of(dp_catalog->sub, struct dp_catalog_private_v420, sub);
  156. version = dp_catalog_get_dp_core_version(dp_catalog);
  157. io_data = catalog->io->dp_mmss_cc;
  158. if (version >= 0x10040000) {
  159. if (panel->stream_id == DP_STREAM_1)
  160. reg_off = MMSS_DP_PIXEL1_BASE_V140;
  161. else
  162. reg_off = MMSS_DP_PIXEL_BASE_V140;
  163. } else {
  164. if (panel->stream_id == DP_STREAM_1)
  165. reg_off = MMSS_DP_PIXEL1_BASE_V130;
  166. else
  167. reg_off = MMSS_DP_PIXEL_BASE_V130;
  168. }
  169. pixel_m = dp_read(reg_off + MMSS_DP_M_OFF);
  170. pixel_n = dp_read(reg_off + MMSS_DP_N_OFF);
  171. DP_DEBUG("pixel_m=0x%x, pixel_n=0x%x\n", pixel_m, pixel_n);
  172. mvid = (pixel_m & 0xFFFF) * 5;
  173. nvid = (0xFFFF & (~pixel_n)) + (pixel_m & 0xFFFF);
  174. if (nvid < nvid_fixed) {
  175. u32 temp;
  176. temp = (nvid_fixed / nvid) * nvid;
  177. mvid = (nvid_fixed / nvid) * mvid;
  178. nvid = temp;
  179. }
  180. DP_DEBUG("rate = %d\n", rate);
  181. if (panel->widebus_en)
  182. mvid <<= 1;
  183. if (link_rate_hbr2 == rate)
  184. nvid *= 2;
  185. if (link_rate_hbr3 == rate)
  186. nvid *= 3;
  187. io_data = catalog->io->dp_link;
  188. if (panel->stream_id == DP_STREAM_1) {
  189. mvid_off = DP1_SOFTWARE_MVID - DP_SOFTWARE_MVID;
  190. nvid_off = DP1_SOFTWARE_NVID - DP_SOFTWARE_NVID;
  191. }
  192. DP_DEBUG("mvid=0x%x, nvid=0x%x\n", mvid, nvid);
  193. dp_write(DP_SOFTWARE_MVID + mvid_off, mvid);
  194. dp_write(DP_SOFTWARE_NVID + nvid_off, nvid);
  195. }
  196. static void dp_catalog_ctrl_phy_lane_cfg_v420(struct dp_catalog_ctrl *ctrl,
  197. bool flipped, u8 ln_cnt)
  198. {
  199. u32 info = 0x0;
  200. struct dp_catalog_private_v420 *catalog;
  201. struct dp_io_data *io_data;
  202. u8 orientation = BIT(!!flipped);
  203. if (!ctrl) {
  204. DP_ERR("invalid input\n");
  205. return;
  206. }
  207. catalog = dp_catalog_get_priv_v420(ctrl);
  208. io_data = catalog->io->dp_phy;
  209. info |= (ln_cnt & 0x0F);
  210. info |= ((orientation & 0x0F) << 4);
  211. DP_DEBUG("Shared Info = 0x%x\n", info);
  212. dp_write(DP_PHY_SPARE0_V420, info);
  213. }
  214. static void dp_catalog_ctrl_update_vx_px_v420(struct dp_catalog_ctrl *ctrl,
  215. u8 v_level, u8 p_level, bool high)
  216. {
  217. struct dp_catalog_private_v420 *catalog;
  218. struct dp_io_data *io_data;
  219. u8 value0, value1;
  220. u32 version;
  221. if (!ctrl || !((v_level < MAX_VOLTAGE_LEVELS)
  222. && (p_level < MAX_PRE_EMP_LEVELS))) {
  223. DP_ERR("invalid input\n");
  224. return;
  225. }
  226. DP_DEBUG("hw: v=%d p=%d, high=%d\n", v_level, p_level, high);
  227. catalog = dp_catalog_get_priv_v420(ctrl);
  228. io_data = catalog->io->dp_ahb;
  229. version = dp_read(DP_HW_VERSION);
  230. DP_DEBUG("version: 0x%x\n", version);
  231. /*
  232. * For DP controller versions >= 1.2.3
  233. */
  234. if (version >= 0x10020003) {
  235. if (high) {
  236. value0 = dp_swing_hbr2_hbr3[v_level][p_level];
  237. value1 = dp_pre_emp_hbr2_hbr3[v_level][p_level];
  238. } else {
  239. value0 = dp_swing_hbr_rbr[v_level][p_level];
  240. value1 = dp_pre_emp_hbr_rbr[v_level][p_level];
  241. }
  242. } else {
  243. value0 = vm_voltage_swing[v_level][p_level];
  244. value1 = vm_pre_emphasis[v_level][p_level];
  245. }
  246. /* program default setting first */
  247. io_data = catalog->io->dp_ln_tx0;
  248. dp_write(TXn_TX_DRV_LVL_V420, 0x2A);
  249. dp_write(TXn_TX_EMP_POST1_LVL, 0x20);
  250. io_data = catalog->io->dp_ln_tx1;
  251. dp_write(TXn_TX_DRV_LVL_V420, 0x2A);
  252. dp_write(TXn_TX_EMP_POST1_LVL, 0x20);
  253. /* Enable MUX to use Cursor values from these registers */
  254. value0 |= BIT(5);
  255. value1 |= BIT(5);
  256. /* Configure host and panel only if both values are allowed */
  257. if (value0 != 0xFF && value1 != 0xFF) {
  258. io_data = catalog->io->dp_ln_tx0;
  259. dp_write(TXn_TX_DRV_LVL_V420, value0);
  260. dp_write(TXn_TX_EMP_POST1_LVL, value1);
  261. io_data = catalog->io->dp_ln_tx1;
  262. dp_write(TXn_TX_DRV_LVL_V420, value0);
  263. dp_write(TXn_TX_EMP_POST1_LVL, value1);
  264. DP_DEBUG("hw: vx_value=0x%x px_value=0x%x\n",
  265. value0, value1);
  266. } else {
  267. DP_ERR("invalid vx (0x%x=0x%x), px (0x%x=0x%x\n",
  268. v_level, value0, p_level, value1);
  269. }
  270. }
  271. static void dp_catalog_ctrl_lane_pnswap_v420(struct dp_catalog_ctrl *ctrl,
  272. u8 ln_pnswap)
  273. {
  274. struct dp_catalog_private_v420 *catalog;
  275. struct dp_io_data *io_data;
  276. u32 cfg0, cfg1;
  277. catalog = dp_catalog_get_priv_v420(ctrl);
  278. cfg0 = 0x0a;
  279. cfg1 = 0x0a;
  280. cfg0 |= ((ln_pnswap >> 0) & 0x1) << 0;
  281. cfg0 |= ((ln_pnswap >> 1) & 0x1) << 2;
  282. cfg1 |= ((ln_pnswap >> 2) & 0x1) << 0;
  283. cfg1 |= ((ln_pnswap >> 3) & 0x1) << 2;
  284. io_data = catalog->io->dp_ln_tx0;
  285. dp_write(TXn_TX_POL_INV_V420, cfg0);
  286. io_data = catalog->io->dp_ln_tx1;
  287. dp_write(TXn_TX_POL_INV_V420, cfg1);
  288. }
  289. static void dp_catalog_put_v420(struct dp_catalog *catalog)
  290. {
  291. struct dp_catalog_private_v420 *catalog_priv;
  292. if (!catalog)
  293. return;
  294. catalog_priv = container_of(catalog->sub,
  295. struct dp_catalog_private_v420, sub);
  296. devm_kfree(catalog_priv->dev, catalog_priv);
  297. }
  298. struct dp_catalog_sub *dp_catalog_get_v420(struct device *dev,
  299. struct dp_catalog *catalog, struct dp_catalog_io *io)
  300. {
  301. struct dp_catalog_private_v420 *catalog_priv;
  302. if (!dev || !catalog) {
  303. DP_ERR("invalid input\n");
  304. return ERR_PTR(-EINVAL);
  305. }
  306. catalog_priv = devm_kzalloc(dev, sizeof(*catalog_priv), GFP_KERNEL);
  307. if (!catalog_priv)
  308. return ERR_PTR(-ENOMEM);
  309. catalog_priv->dev = dev;
  310. catalog_priv->io = io;
  311. catalog_priv->dpc = catalog;
  312. catalog_priv->sub.put = dp_catalog_put_v420;
  313. catalog->aux.setup = dp_catalog_aux_setup_v420;
  314. catalog->aux.clear_hw_interrupts = dp_catalog_aux_clear_hw_int_v420;
  315. catalog->panel.config_msa = dp_catalog_panel_config_msa_v420;
  316. catalog->ctrl.phy_lane_cfg = dp_catalog_ctrl_phy_lane_cfg_v420;
  317. catalog->ctrl.update_vx_px = dp_catalog_ctrl_update_vx_px_v420;
  318. catalog->ctrl.lane_pnswap = dp_catalog_ctrl_lane_pnswap_v420;
  319. return &catalog_priv->sub;
  320. }