exynos_dp.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. *
  4. * Author: Donghwa Lee <dh09.lee@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. #include <config.h>
  22. #include <common.h>
  23. #include <malloc.h>
  24. #include <linux/err.h>
  25. #include <asm/arch/clk.h>
  26. #include <asm/arch/cpu.h>
  27. #include <asm/arch/dp_info.h>
  28. #include <asm/arch/dp.h>
  29. #include "exynos_dp_lowlevel.h"
  30. static struct exynos_dp_platform_data *dp_pd;
  31. static void exynos_dp_disp_info(struct edp_disp_info *disp_info)
  32. {
  33. disp_info->h_total = disp_info->h_res + disp_info->h_sync_width +
  34. disp_info->h_back_porch + disp_info->h_front_porch;
  35. disp_info->v_total = disp_info->v_res + disp_info->v_sync_width +
  36. disp_info->v_back_porch + disp_info->v_front_porch;
  37. return;
  38. }
  39. static int exynos_dp_init_dp(void)
  40. {
  41. int ret;
  42. exynos_dp_reset();
  43. /* SW defined function Normal operation */
  44. exynos_dp_enable_sw_func(DP_ENABLE);
  45. ret = exynos_dp_init_analog_func();
  46. if (ret != EXYNOS_DP_SUCCESS)
  47. return ret;
  48. exynos_dp_init_hpd();
  49. exynos_dp_init_aux();
  50. return ret;
  51. }
  52. static unsigned char exynos_dp_calc_edid_check_sum(unsigned char *edid_data)
  53. {
  54. int i;
  55. unsigned char sum = 0;
  56. for (i = 0; i < EDID_BLOCK_LENGTH; i++)
  57. sum = sum + edid_data[i];
  58. return sum;
  59. }
  60. static unsigned int exynos_dp_read_edid(void)
  61. {
  62. unsigned char edid[EDID_BLOCK_LENGTH * 2];
  63. unsigned int extend_block = 0;
  64. unsigned char sum;
  65. unsigned char test_vector;
  66. int retval;
  67. /*
  68. * EDID device address is 0x50.
  69. * However, if necessary, you must have set upper address
  70. * into E-EDID in I2C device, 0x30.
  71. */
  72. /* Read Extension Flag, Number of 128-byte EDID extension blocks */
  73. exynos_dp_read_byte_from_i2c(I2C_EDID_DEVICE_ADDR, EDID_EXTENSION_FLAG,
  74. &extend_block);
  75. if (extend_block > 0) {
  76. printf("DP EDID data includes a single extension!\n");
  77. /* Read EDID data */
  78. retval = exynos_dp_read_bytes_from_i2c(I2C_EDID_DEVICE_ADDR,
  79. EDID_HEADER_PATTERN,
  80. EDID_BLOCK_LENGTH,
  81. &edid[EDID_HEADER_PATTERN]);
  82. if (retval != 0) {
  83. printf("DP EDID Read failed!\n");
  84. return -1;
  85. }
  86. sum = exynos_dp_calc_edid_check_sum(edid);
  87. if (sum != 0) {
  88. printf("DP EDID bad checksum!\n");
  89. return -1;
  90. }
  91. /* Read additional EDID data */
  92. retval = exynos_dp_read_bytes_from_i2c(I2C_EDID_DEVICE_ADDR,
  93. EDID_BLOCK_LENGTH,
  94. EDID_BLOCK_LENGTH,
  95. &edid[EDID_BLOCK_LENGTH]);
  96. if (retval != 0) {
  97. printf("DP EDID Read failed!\n");
  98. return -1;
  99. }
  100. sum = exynos_dp_calc_edid_check_sum(&edid[EDID_BLOCK_LENGTH]);
  101. if (sum != 0) {
  102. printf("DP EDID bad checksum!\n");
  103. return -1;
  104. }
  105. exynos_dp_read_byte_from_dpcd(DPCD_TEST_REQUEST,
  106. &test_vector);
  107. if (test_vector & DPCD_TEST_EDID_READ) {
  108. exynos_dp_write_byte_to_dpcd(DPCD_TEST_EDID_CHECKSUM,
  109. edid[EDID_BLOCK_LENGTH + EDID_CHECKSUM]);
  110. exynos_dp_write_byte_to_dpcd(DPCD_TEST_RESPONSE,
  111. DPCD_TEST_EDID_CHECKSUM_WRITE);
  112. }
  113. } else {
  114. debug("DP EDID data does not include any extensions.\n");
  115. /* Read EDID data */
  116. retval = exynos_dp_read_bytes_from_i2c(I2C_EDID_DEVICE_ADDR,
  117. EDID_HEADER_PATTERN,
  118. EDID_BLOCK_LENGTH,
  119. &edid[EDID_HEADER_PATTERN]);
  120. if (retval != 0) {
  121. printf("DP EDID Read failed!\n");
  122. return -1;
  123. }
  124. sum = exynos_dp_calc_edid_check_sum(edid);
  125. if (sum != 0) {
  126. printf("DP EDID bad checksum!\n");
  127. return -1;
  128. }
  129. exynos_dp_read_byte_from_dpcd(DPCD_TEST_REQUEST,
  130. &test_vector);
  131. if (test_vector & DPCD_TEST_EDID_READ) {
  132. exynos_dp_write_byte_to_dpcd(DPCD_TEST_EDID_CHECKSUM,
  133. edid[EDID_CHECKSUM]);
  134. exynos_dp_write_byte_to_dpcd(DPCD_TEST_RESPONSE,
  135. DPCD_TEST_EDID_CHECKSUM_WRITE);
  136. }
  137. }
  138. debug("DP EDID Read success!\n");
  139. return 0;
  140. }
  141. static unsigned int exynos_dp_handle_edid(struct edp_device_info *edp_info)
  142. {
  143. unsigned char buf[12];
  144. unsigned int ret;
  145. unsigned char temp;
  146. unsigned char retry_cnt;
  147. unsigned char dpcd_rev[16];
  148. unsigned char lane_bw[16];
  149. unsigned char lane_cnt[16];
  150. memset(dpcd_rev, 0, 16);
  151. memset(lane_bw, 0, 16);
  152. memset(lane_cnt, 0, 16);
  153. memset(buf, 0, 12);
  154. retry_cnt = 5;
  155. while (retry_cnt) {
  156. /* Read DPCD 0x0000-0x000b */
  157. ret = exynos_dp_read_bytes_from_dpcd(DPCD_DPCD_REV, 12,
  158. buf);
  159. if (ret != EXYNOS_DP_SUCCESS) {
  160. if (retry_cnt == 0) {
  161. printf("DP read_byte_from_dpcd() failed\n");
  162. return ret;
  163. }
  164. retry_cnt--;
  165. } else
  166. break;
  167. }
  168. /* */
  169. temp = buf[DPCD_DPCD_REV];
  170. if (temp == DP_DPCD_REV_10 || temp == DP_DPCD_REV_11)
  171. edp_info->dpcd_rev = temp;
  172. else {
  173. printf("DP Wrong DPCD Rev : %x\n", temp);
  174. return -ENODEV;
  175. }
  176. temp = buf[DPCD_MAX_LINK_RATE];
  177. if (temp == DP_LANE_BW_1_62 || temp == DP_LANE_BW_2_70)
  178. edp_info->lane_bw = temp;
  179. else {
  180. printf("DP Wrong MAX LINK RATE : %x\n", temp);
  181. return -EINVAL;
  182. }
  183. /*Refer VESA Display Port Stnadard Ver1.1a Page 120 */
  184. if (edp_info->dpcd_rev == DP_DPCD_REV_11) {
  185. temp = buf[DPCD_MAX_LANE_COUNT] & 0x1f;
  186. if (buf[DPCD_MAX_LANE_COUNT] & 0x80)
  187. edp_info->dpcd_efc = 1;
  188. else
  189. edp_info->dpcd_efc = 0;
  190. } else {
  191. temp = buf[DPCD_MAX_LANE_COUNT];
  192. edp_info->dpcd_efc = 0;
  193. }
  194. if (temp == DP_LANE_CNT_1 || temp == DP_LANE_CNT_2 ||
  195. temp == DP_LANE_CNT_4) {
  196. edp_info->lane_cnt = temp;
  197. } else {
  198. printf("DP Wrong MAX LANE COUNT : %x\n", temp);
  199. return -EINVAL;
  200. }
  201. ret = exynos_dp_read_edid();
  202. if (ret != EXYNOS_DP_SUCCESS) {
  203. printf("DP exynos_dp_read_edid() failed\n");
  204. return -EINVAL;
  205. }
  206. return ret;
  207. }
  208. static void exynos_dp_init_training(void)
  209. {
  210. /*
  211. * MACRO_RST must be applied after the PLL_LOCK to avoid
  212. * the DP inter pair skew issue for at least 10 us
  213. */
  214. exynos_dp_reset_macro();
  215. /* All DP analog module power up */
  216. exynos_dp_set_analog_power_down(POWER_ALL, 0);
  217. }
  218. static unsigned int exynos_dp_link_start(struct edp_device_info *edp_info)
  219. {
  220. unsigned char buf[5];
  221. unsigned int ret = 0;
  222. debug("DP: %s was called\n", __func__);
  223. edp_info->lt_info.lt_status = DP_LT_CR;
  224. edp_info->lt_info.ep_loop = 0;
  225. edp_info->lt_info.cr_loop[0] = 0;
  226. edp_info->lt_info.cr_loop[1] = 0;
  227. edp_info->lt_info.cr_loop[2] = 0;
  228. edp_info->lt_info.cr_loop[3] = 0;
  229. /* Set sink to D0 (Sink Not Ready) mode. */
  230. ret = exynos_dp_write_byte_to_dpcd(DPCD_SINK_POWER_STATE,
  231. DPCD_SET_POWER_STATE_D0);
  232. if (ret != EXYNOS_DP_SUCCESS) {
  233. printf("DP write_dpcd_byte failed\n");
  234. return ret;
  235. }
  236. /* Set link rate and count as you want to establish*/
  237. exynos_dp_set_link_bandwidth(edp_info->lane_bw);
  238. exynos_dp_set_lane_count(edp_info->lane_cnt);
  239. /* Setup RX configuration */
  240. buf[0] = edp_info->lane_bw;
  241. buf[1] = edp_info->lane_cnt;
  242. ret = exynos_dp_write_bytes_to_dpcd(DPCD_LINK_BW_SET, 2,
  243. buf);
  244. if (ret != EXYNOS_DP_SUCCESS) {
  245. printf("DP write_dpcd_byte failed\n");
  246. return ret;
  247. }
  248. exynos_dp_set_lane_pre_emphasis(PRE_EMPHASIS_LEVEL_0,
  249. edp_info->lane_cnt);
  250. /* Set training pattern 1 */
  251. exynos_dp_set_training_pattern(TRAINING_PTN1);
  252. /* Set RX training pattern */
  253. buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_1;
  254. buf[1] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
  255. DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
  256. buf[2] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
  257. DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
  258. buf[3] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
  259. DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
  260. buf[4] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
  261. DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
  262. ret = exynos_dp_write_bytes_to_dpcd(DPCD_TRAINING_PATTERN_SET,
  263. 5, buf);
  264. if (ret != EXYNOS_DP_SUCCESS) {
  265. printf("DP write_dpcd_byte failed\n");
  266. return ret;
  267. }
  268. return ret;
  269. }
  270. static unsigned int exynos_dp_training_pattern_dis(void)
  271. {
  272. unsigned int ret = EXYNOS_DP_SUCCESS;
  273. exynos_dp_set_training_pattern(DP_NONE);
  274. ret = exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
  275. DPCD_TRAINING_PATTERN_DISABLED);
  276. if (ret != EXYNOS_DP_SUCCESS) {
  277. printf("DP requst_link_traninig_req failed\n");
  278. return -EAGAIN;
  279. }
  280. return ret;
  281. }
  282. static unsigned int exynos_dp_enable_rx_to_enhanced_mode(unsigned char enable)
  283. {
  284. unsigned char data;
  285. unsigned int ret = EXYNOS_DP_SUCCESS;
  286. ret = exynos_dp_read_byte_from_dpcd(DPCD_LANE_COUNT_SET,
  287. &data);
  288. if (ret != EXYNOS_DP_SUCCESS) {
  289. printf("DP read_from_dpcd failed\n");
  290. return -EAGAIN;
  291. }
  292. if (enable)
  293. data = DPCD_ENHANCED_FRAME_EN | DPCD_LN_COUNT_SET(data);
  294. else
  295. data = DPCD_LN_COUNT_SET(data);
  296. ret = exynos_dp_write_byte_to_dpcd(DPCD_LANE_COUNT_SET,
  297. data);
  298. if (ret != EXYNOS_DP_SUCCESS) {
  299. printf("DP write_to_dpcd failed\n");
  300. return -EAGAIN;
  301. }
  302. return ret;
  303. }
  304. static unsigned int exynos_dp_set_enhanced_mode(unsigned char enhance_mode)
  305. {
  306. unsigned int ret = EXYNOS_DP_SUCCESS;
  307. ret = exynos_dp_enable_rx_to_enhanced_mode(enhance_mode);
  308. if (ret != EXYNOS_DP_SUCCESS) {
  309. printf("DP rx_enhance_mode failed\n");
  310. return -EAGAIN;
  311. }
  312. exynos_dp_enable_enhanced_mode(enhance_mode);
  313. return ret;
  314. }
  315. static int exynos_dp_read_dpcd_lane_stat(struct edp_device_info *edp_info,
  316. unsigned char *status)
  317. {
  318. unsigned int ret, i;
  319. unsigned char buf[2];
  320. unsigned char lane_stat[DP_LANE_CNT_4] = {0,};
  321. unsigned char shift_val[DP_LANE_CNT_4] = {0,};
  322. shift_val[0] = 0;
  323. shift_val[1] = 4;
  324. shift_val[2] = 0;
  325. shift_val[3] = 4;
  326. ret = exynos_dp_read_bytes_from_dpcd(DPCD_LANE0_1_STATUS, 2, buf);
  327. if (ret != EXYNOS_DP_SUCCESS) {
  328. printf("DP read lane status failed\n");
  329. return ret;
  330. }
  331. for (i = 0; i < edp_info->lane_cnt; i++) {
  332. lane_stat[i] = (buf[(i / 2)] >> shift_val[i]) & 0x0f;
  333. if (lane_stat[0] != lane_stat[i]) {
  334. printf("Wrong lane status\n");
  335. return -EINVAL;
  336. }
  337. }
  338. *status = lane_stat[0];
  339. return ret;
  340. }
  341. static unsigned int exynos_dp_read_dpcd_adj_req(unsigned char lane_num,
  342. unsigned char *sw, unsigned char *em)
  343. {
  344. unsigned int ret = EXYNOS_DP_SUCCESS;
  345. unsigned char buf;
  346. unsigned int dpcd_addr;
  347. unsigned char shift_val[DP_LANE_CNT_4] = {0, 4, 0, 4};
  348. /*lane_num value is used as arry index, so this range 0 ~ 3 */
  349. dpcd_addr = DPCD_ADJUST_REQUEST_LANE0_1 + (lane_num / 2);
  350. ret = exynos_dp_read_byte_from_dpcd(dpcd_addr, &buf);
  351. if (ret != EXYNOS_DP_SUCCESS) {
  352. printf("DP read adjust request failed\n");
  353. return -EAGAIN;
  354. }
  355. *sw = ((buf >> shift_val[lane_num]) & 0x03);
  356. *em = ((buf >> shift_val[lane_num]) & 0x0c) >> 2;
  357. return ret;
  358. }
  359. static int exynos_dp_equalizer_err_link(struct edp_device_info *edp_info)
  360. {
  361. int ret;
  362. ret = exynos_dp_training_pattern_dis();
  363. if (ret != EXYNOS_DP_SUCCESS) {
  364. printf("DP training_patter_disable() failed\n");
  365. edp_info->lt_info.lt_status = DP_LT_FAIL;
  366. }
  367. ret = exynos_dp_set_enhanced_mode(edp_info->dpcd_efc);
  368. if (ret != EXYNOS_DP_SUCCESS) {
  369. printf("DP set_enhanced_mode() failed\n");
  370. edp_info->lt_info.lt_status = DP_LT_FAIL;
  371. }
  372. return ret;
  373. }
  374. static int exynos_dp_reduce_link_rate(struct edp_device_info *edp_info)
  375. {
  376. int ret;
  377. if (edp_info->lane_bw == DP_LANE_BW_2_70) {
  378. edp_info->lane_bw = DP_LANE_BW_1_62;
  379. printf("DP Change lane bw to 1.62Gbps\n");
  380. edp_info->lt_info.lt_status = DP_LT_START;
  381. ret = EXYNOS_DP_SUCCESS;
  382. } else {
  383. ret = exynos_dp_training_pattern_dis();
  384. if (ret != EXYNOS_DP_SUCCESS)
  385. printf("DP training_patter_disable() failed\n");
  386. ret = exynos_dp_set_enhanced_mode(edp_info->dpcd_efc);
  387. if (ret != EXYNOS_DP_SUCCESS)
  388. printf("DP set_enhanced_mode() failed\n");
  389. edp_info->lt_info.lt_status = DP_LT_FAIL;
  390. }
  391. return ret;
  392. }
  393. static unsigned int exynos_dp_process_clock_recovery(struct edp_device_info
  394. *edp_info)
  395. {
  396. unsigned int ret = EXYNOS_DP_SUCCESS;
  397. unsigned char lane_stat;
  398. unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0, };
  399. unsigned int i;
  400. unsigned char adj_req_sw;
  401. unsigned char adj_req_em;
  402. unsigned char buf[5];
  403. debug("DP: %s was called\n", __func__);
  404. mdelay(1);
  405. ret = exynos_dp_read_dpcd_lane_stat(edp_info, &lane_stat);
  406. if (ret != EXYNOS_DP_SUCCESS) {
  407. printf("DP read lane status failed\n");
  408. edp_info->lt_info.lt_status = DP_LT_FAIL;
  409. return ret;
  410. }
  411. if (lane_stat & DP_LANE_STAT_CR_DONE) {
  412. debug("DP clock Recovery training succeed\n");
  413. exynos_dp_set_training_pattern(TRAINING_PTN2);
  414. for (i = 0; i < edp_info->lane_cnt; i++) {
  415. ret = exynos_dp_read_dpcd_adj_req(i, &adj_req_sw,
  416. &adj_req_em);
  417. if (ret != EXYNOS_DP_SUCCESS) {
  418. edp_info->lt_info.lt_status = DP_LT_FAIL;
  419. return ret;
  420. }
  421. lt_ctl_val[i] = 0;
  422. lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
  423. if ((adj_req_sw == VOLTAGE_LEVEL_3)
  424. || (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
  425. lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
  426. MAX_PRE_EMPHASIS_REACH_3;
  427. }
  428. exynos_dp_set_lanex_pre_emphasis(lt_ctl_val[i], i);
  429. }
  430. buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_2;
  431. buf[1] = lt_ctl_val[0];
  432. buf[2] = lt_ctl_val[1];
  433. buf[3] = lt_ctl_val[2];
  434. buf[4] = lt_ctl_val[3];
  435. ret = exynos_dp_write_bytes_to_dpcd(
  436. DPCD_TRAINING_PATTERN_SET, 5, buf);
  437. if (ret != EXYNOS_DP_SUCCESS) {
  438. printf("DP write traning pattern1 failed\n");
  439. edp_info->lt_info.lt_status = DP_LT_FAIL;
  440. return ret;
  441. } else
  442. edp_info->lt_info.lt_status = DP_LT_ET;
  443. } else {
  444. for (i = 0; i < edp_info->lane_cnt; i++) {
  445. lt_ctl_val[i] = exynos_dp_get_lanex_pre_emphasis(i);
  446. ret = exynos_dp_read_dpcd_adj_req(i,
  447. &adj_req_sw, &adj_req_em);
  448. if (ret != EXYNOS_DP_SUCCESS) {
  449. printf("DP read adj req failed\n");
  450. edp_info->lt_info.lt_status = DP_LT_FAIL;
  451. return ret;
  452. }
  453. if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
  454. (adj_req_em == PRE_EMPHASIS_LEVEL_3))
  455. ret = exynos_dp_reduce_link_rate(edp_info);
  456. if ((DRIVE_CURRENT_SET_0_GET(lt_ctl_val[i]) ==
  457. adj_req_sw) &&
  458. (PRE_EMPHASIS_SET_0_GET(lt_ctl_val[i]) ==
  459. adj_req_em)) {
  460. edp_info->lt_info.cr_loop[i]++;
  461. if (edp_info->lt_info.cr_loop[i] == MAX_CR_LOOP)
  462. ret = exynos_dp_reduce_link_rate(
  463. edp_info);
  464. }
  465. lt_ctl_val[i] = 0;
  466. lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
  467. if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
  468. (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
  469. lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
  470. MAX_PRE_EMPHASIS_REACH_3;
  471. }
  472. exynos_dp_set_lanex_pre_emphasis(lt_ctl_val[i], i);
  473. }
  474. ret = exynos_dp_write_bytes_to_dpcd(
  475. DPCD_TRAINING_LANE0_SET, 4, lt_ctl_val);
  476. if (ret != EXYNOS_DP_SUCCESS) {
  477. printf("DP write traning pattern2 failed\n");
  478. edp_info->lt_info.lt_status = DP_LT_FAIL;
  479. return ret;
  480. }
  481. }
  482. return ret;
  483. }
  484. static unsigned int exynos_dp_process_equalizer_training(struct edp_device_info
  485. *edp_info)
  486. {
  487. unsigned int ret = EXYNOS_DP_SUCCESS;
  488. unsigned char lane_stat, adj_req_sw, adj_req_em, i;
  489. unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0,};
  490. unsigned char interlane_aligned = 0;
  491. unsigned char f_bw;
  492. unsigned char f_lane_cnt;
  493. unsigned char sink_stat;
  494. mdelay(1);
  495. ret = exynos_dp_read_dpcd_lane_stat(edp_info, &lane_stat);
  496. if (ret != EXYNOS_DP_SUCCESS) {
  497. printf("DP read lane status failed\n");
  498. edp_info->lt_info.lt_status = DP_LT_FAIL;
  499. return ret;
  500. }
  501. debug("DP lane stat : %x\n", lane_stat);
  502. if (lane_stat & DP_LANE_STAT_CR_DONE) {
  503. ret = exynos_dp_read_byte_from_dpcd(DPCD_LN_ALIGN_UPDATED,
  504. &sink_stat);
  505. if (ret != EXYNOS_DP_SUCCESS) {
  506. edp_info->lt_info.lt_status = DP_LT_FAIL;
  507. return ret;
  508. }
  509. interlane_aligned = (sink_stat & DPCD_INTERLANE_ALIGN_DONE);
  510. for (i = 0; i < edp_info->lane_cnt; i++) {
  511. ret = exynos_dp_read_dpcd_adj_req(i,
  512. &adj_req_sw, &adj_req_em);
  513. if (ret != EXYNOS_DP_SUCCESS) {
  514. printf("DP read adj req 1 failed\n");
  515. edp_info->lt_info.lt_status = DP_LT_FAIL;
  516. return ret;
  517. }
  518. lt_ctl_val[i] = 0;
  519. lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
  520. if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
  521. (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
  522. lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3;
  523. lt_ctl_val[i] |= MAX_PRE_EMPHASIS_REACH_3;
  524. }
  525. }
  526. if (((lane_stat&DP_LANE_STAT_CE_DONE) &&
  527. (lane_stat&DP_LANE_STAT_SYM_LOCK))
  528. && (interlane_aligned == DPCD_INTERLANE_ALIGN_DONE)) {
  529. debug("DP Equalizer training succeed\n");
  530. f_bw = exynos_dp_get_link_bandwidth();
  531. f_lane_cnt = exynos_dp_get_lane_count();
  532. debug("DP final BandWidth : %x\n", f_bw);
  533. debug("DP final Lane Count : %x\n", f_lane_cnt);
  534. edp_info->lt_info.lt_status = DP_LT_FINISHED;
  535. exynos_dp_equalizer_err_link(edp_info);
  536. } else {
  537. edp_info->lt_info.ep_loop++;
  538. if (edp_info->lt_info.ep_loop > MAX_EQ_LOOP) {
  539. if (edp_info->lane_bw == DP_LANE_BW_2_70) {
  540. ret = exynos_dp_reduce_link_rate(
  541. edp_info);
  542. } else {
  543. edp_info->lt_info.lt_status =
  544. DP_LT_FAIL;
  545. exynos_dp_equalizer_err_link(edp_info);
  546. }
  547. } else {
  548. for (i = 0; i < edp_info->lane_cnt; i++)
  549. exynos_dp_set_lanex_pre_emphasis(
  550. lt_ctl_val[i], i);
  551. ret = exynos_dp_write_bytes_to_dpcd(
  552. DPCD_TRAINING_LANE0_SET,
  553. 4, lt_ctl_val);
  554. if (ret != EXYNOS_DP_SUCCESS) {
  555. printf("DP set lt pattern failed\n");
  556. edp_info->lt_info.lt_status =
  557. DP_LT_FAIL;
  558. exynos_dp_equalizer_err_link(edp_info);
  559. }
  560. }
  561. }
  562. } else if (edp_info->lane_bw == DP_LANE_BW_2_70) {
  563. ret = exynos_dp_reduce_link_rate(edp_info);
  564. } else {
  565. edp_info->lt_info.lt_status = DP_LT_FAIL;
  566. exynos_dp_equalizer_err_link(edp_info);
  567. }
  568. return ret;
  569. }
  570. static unsigned int exynos_dp_sw_link_training(struct edp_device_info *edp_info)
  571. {
  572. unsigned int ret = 0;
  573. int training_finished;
  574. /* Turn off unnecessary lane */
  575. if (edp_info->lane_cnt == 1)
  576. exynos_dp_set_analog_power_down(CH1_BLOCK, 1);
  577. training_finished = 0;
  578. edp_info->lt_info.lt_status = DP_LT_START;
  579. /* Process here */
  580. while (!training_finished) {
  581. switch (edp_info->lt_info.lt_status) {
  582. case DP_LT_START:
  583. ret = exynos_dp_link_start(edp_info);
  584. if (ret != EXYNOS_DP_SUCCESS) {
  585. printf("DP LT:link start failed\n");
  586. return ret;
  587. }
  588. break;
  589. case DP_LT_CR:
  590. ret = exynos_dp_process_clock_recovery(edp_info);
  591. if (ret != EXYNOS_DP_SUCCESS) {
  592. printf("DP LT:clock recovery failed\n");
  593. return ret;
  594. }
  595. break;
  596. case DP_LT_ET:
  597. ret = exynos_dp_process_equalizer_training(edp_info);
  598. if (ret != EXYNOS_DP_SUCCESS) {
  599. printf("DP LT:equalizer training failed\n");
  600. return ret;
  601. }
  602. break;
  603. case DP_LT_FINISHED:
  604. training_finished = 1;
  605. break;
  606. case DP_LT_FAIL:
  607. return -1;
  608. }
  609. }
  610. return ret;
  611. }
  612. static unsigned int exynos_dp_set_link_train(struct edp_device_info *edp_info)
  613. {
  614. unsigned int ret;
  615. exynos_dp_init_training();
  616. ret = exynos_dp_sw_link_training(edp_info);
  617. if (ret != EXYNOS_DP_SUCCESS)
  618. printf("DP dp_sw_link_traning() failed\n");
  619. return ret;
  620. }
  621. static void exynos_dp_enable_scramble(unsigned int enable)
  622. {
  623. unsigned char data;
  624. if (enable) {
  625. exynos_dp_enable_scrambling(DP_ENABLE);
  626. exynos_dp_read_byte_from_dpcd(DPCD_TRAINING_PATTERN_SET,
  627. &data);
  628. exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
  629. (u8)(data & ~DPCD_SCRAMBLING_DISABLED));
  630. } else {
  631. exynos_dp_enable_scrambling(DP_DISABLE);
  632. exynos_dp_read_byte_from_dpcd(DPCD_TRAINING_PATTERN_SET,
  633. &data);
  634. exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
  635. (u8)(data | DPCD_SCRAMBLING_DISABLED));
  636. }
  637. }
  638. static unsigned int exynos_dp_config_video(struct edp_device_info *edp_info)
  639. {
  640. unsigned int ret = 0;
  641. unsigned int retry_cnt;
  642. mdelay(1);
  643. if (edp_info->video_info.master_mode) {
  644. printf("DP does not support master mode\n");
  645. return -ENODEV;
  646. } else {
  647. /* debug slave */
  648. exynos_dp_config_video_slave_mode(&edp_info->video_info);
  649. }
  650. exynos_dp_set_video_color_format(&edp_info->video_info);
  651. if (edp_info->video_info.bist_mode) {
  652. if (exynos_dp_config_video_bist(edp_info) != 0)
  653. return -1;
  654. }
  655. ret = exynos_dp_get_pll_lock_status();
  656. if (ret != PLL_LOCKED) {
  657. printf("DP PLL is not locked yet\n");
  658. return -EIO;
  659. }
  660. if (edp_info->video_info.master_mode == 0) {
  661. retry_cnt = 10;
  662. while (retry_cnt) {
  663. ret = exynos_dp_is_slave_video_stream_clock_on();
  664. if (ret != EXYNOS_DP_SUCCESS) {
  665. if (retry_cnt == 0) {
  666. printf("DP stream_clock_on failed\n");
  667. return ret;
  668. }
  669. retry_cnt--;
  670. mdelay(1);
  671. } else
  672. break;
  673. }
  674. }
  675. /* Set to use the register calculated M/N video */
  676. exynos_dp_set_video_cr_mn(CALCULATED_M, 0, 0);
  677. /* For video bist, Video timing must be generated by register */
  678. exynos_dp_set_video_timing_mode(VIDEO_TIMING_FROM_CAPTURE);
  679. /* Enable video bist */
  680. if (edp_info->video_info.bist_pattern != COLOR_RAMP &&
  681. edp_info->video_info.bist_pattern != BALCK_WHITE_V_LINES &&
  682. edp_info->video_info.bist_pattern != COLOR_SQUARE)
  683. exynos_dp_enable_video_bist(edp_info->video_info.bist_mode);
  684. else
  685. exynos_dp_enable_video_bist(DP_DISABLE);
  686. /* Disable video mute */
  687. exynos_dp_enable_video_mute(DP_DISABLE);
  688. /* Configure video Master or Slave mode */
  689. exynos_dp_enable_video_master(edp_info->video_info.master_mode);
  690. /* Enable video */
  691. exynos_dp_start_video();
  692. if (edp_info->video_info.master_mode == 0) {
  693. retry_cnt = 100;
  694. while (retry_cnt) {
  695. ret = exynos_dp_is_video_stream_on();
  696. if (ret != EXYNOS_DP_SUCCESS) {
  697. if (retry_cnt == 0) {
  698. printf("DP Timeout of video stream\n");
  699. return ret;
  700. }
  701. retry_cnt--;
  702. mdelay(5);
  703. } else
  704. break;
  705. }
  706. }
  707. return ret;
  708. }
  709. unsigned int exynos_init_dp(void)
  710. {
  711. unsigned int ret;
  712. struct edp_device_info *edp_info;
  713. struct edp_disp_info disp_info;
  714. edp_info = kzalloc(sizeof(struct edp_device_info), GFP_KERNEL);
  715. if (!edp_info) {
  716. debug("failed to allocate edp device object.\n");
  717. return -EFAULT;
  718. }
  719. edp_info = dp_pd->edp_dev_info;
  720. if (edp_info == NULL) {
  721. debug("failed to get edp_info data.\n");
  722. return -EFAULT;
  723. }
  724. disp_info = edp_info->disp_info;
  725. exynos_dp_disp_info(&edp_info->disp_info);
  726. if (dp_pd->phy_enable)
  727. dp_pd->phy_enable(1);
  728. ret = exynos_dp_init_dp();
  729. if (ret != EXYNOS_DP_SUCCESS) {
  730. printf("DP exynos_dp_init_dp() failed\n");
  731. return ret;
  732. }
  733. ret = exynos_dp_handle_edid(edp_info);
  734. if (ret != EXYNOS_DP_SUCCESS) {
  735. printf("EDP handle_edid fail\n");
  736. return ret;
  737. }
  738. ret = exynos_dp_set_link_train(edp_info);
  739. if (ret != EXYNOS_DP_SUCCESS) {
  740. printf("DP link training fail\n");
  741. return ret;
  742. }
  743. exynos_dp_enable_scramble(DP_ENABLE);
  744. exynos_dp_enable_rx_to_enhanced_mode(DP_ENABLE);
  745. exynos_dp_enable_enhanced_mode(DP_ENABLE);
  746. exynos_dp_set_link_bandwidth(edp_info->lane_bw);
  747. exynos_dp_set_lane_count(edp_info->lane_cnt);
  748. exynos_dp_init_video();
  749. ret = exynos_dp_config_video(edp_info);
  750. if (ret != EXYNOS_DP_SUCCESS) {
  751. printf("Exynos DP init failed\n");
  752. return ret;
  753. }
  754. printf("Exynos DP init done\n");
  755. return ret;
  756. }
  757. void exynos_set_dp_platform_data(struct exynos_dp_platform_data *pd)
  758. {
  759. if (pd == NULL) {
  760. debug("pd is NULL\n");
  761. return;
  762. }
  763. dp_pd = pd;
  764. }