exynos_dp.c 23 KB

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