exynos_dp_lowlevel.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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 <linux/err.h>
  24. #include <asm/arch/cpu.h>
  25. #include <asm/arch/dp_info.h>
  26. #include <asm/arch/dp.h>
  27. static void exynos_dp_enable_video_input(unsigned int enable)
  28. {
  29. unsigned int reg;
  30. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  31. reg = readl(&dp_regs->video_ctl1);
  32. reg &= ~VIDEO_EN_MASK;
  33. /* enable video input*/
  34. if (enable)
  35. reg |= VIDEO_EN_MASK;
  36. writel(reg, &dp_regs->video_ctl1);
  37. return;
  38. }
  39. void exynos_dp_enable_video_bist(unsigned int enable)
  40. {
  41. /*enable video bist*/
  42. unsigned int reg;
  43. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  44. reg = readl(&dp_regs->video_ctl4);
  45. reg &= ~VIDEO_BIST_MASK;
  46. /*enable video bist*/
  47. if (enable)
  48. reg |= VIDEO_BIST_MASK;
  49. writel(reg, &dp_regs->video_ctl4);
  50. return;
  51. }
  52. void exynos_dp_enable_video_mute(unsigned int enable)
  53. {
  54. unsigned int reg;
  55. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  56. reg = readl(&dp_regs->video_ctl1);
  57. reg &= ~(VIDEO_MUTE_MASK);
  58. if (enable)
  59. reg |= VIDEO_MUTE_MASK;
  60. writel(reg, &dp_regs->video_ctl1);
  61. return;
  62. }
  63. static void exynos_dp_init_analog_param(void)
  64. {
  65. unsigned int reg;
  66. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  67. /*
  68. * Set termination
  69. * Normal bandgap, Normal swing, Tx terminal registor 61 ohm
  70. * 24M Phy clock, TX digital logic power is 100:1.0625V
  71. */
  72. reg = SEL_BG_NEW_BANDGAP | TX_TERMINAL_CTRL_61_OHM |
  73. SWING_A_30PER_G_NORMAL;
  74. writel(reg, &dp_regs->analog_ctl1);
  75. reg = SEL_24M | TX_DVDD_BIT_1_0625V;
  76. writel(reg, &dp_regs->analog_ctl2);
  77. /*
  78. * Set power source for internal clk driver to 1.0625v.
  79. * Select current reference of TX driver current to 00:Ipp/2+Ic/2.
  80. * Set VCO range of PLL +- 0uA
  81. */
  82. reg = DRIVE_DVDD_BIT_1_0625V | SEL_CURRENT_DEFAULT | VCO_BIT_000_MICRO;
  83. writel(reg, &dp_regs->analog_ctl3);
  84. /*
  85. * Set AUX TX terminal resistor to 102 ohm
  86. * Set AUX channel amplitude control
  87. */
  88. reg = PD_RING_OSC | AUX_TERMINAL_CTRL_52_OHM | TX_CUR1_2X | TX_CUR_4_MA;
  89. writel(reg, &dp_regs->pll_filter_ctl1);
  90. /*
  91. * PLL loop filter bandwidth
  92. * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
  93. * PLL digital power select: 1.2500V
  94. */
  95. reg = CH3_AMP_0_MV | CH2_AMP_0_MV | CH1_AMP_0_MV | CH0_AMP_0_MV;
  96. writel(reg, &dp_regs->amp_tuning_ctl);
  97. /*
  98. * PLL loop filter bandwidth
  99. * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
  100. * PLL digital power select: 1.1250V
  101. */
  102. reg = DP_PLL_LOOP_BIT_DEFAULT | DP_PLL_REF_BIT_1_1250V;
  103. writel(reg, &dp_regs->pll_ctl);
  104. }
  105. static void exynos_dp_init_interrupt(void)
  106. {
  107. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  108. /* Set interrupt registers to initial states */
  109. /*
  110. * Disable interrupt
  111. * INT pin assertion polarity. It must be configured
  112. * correctly according to ICU setting.
  113. * 1 = assert high, 0 = assert low
  114. */
  115. writel(INT_POL, &dp_regs->int_ctl);
  116. /* Clear pending regisers */
  117. writel(0xff, &dp_regs->common_int_sta1);
  118. writel(0xff, &dp_regs->common_int_sta2);
  119. writel(0xff, &dp_regs->common_int_sta3);
  120. writel(0xff, &dp_regs->common_int_sta4);
  121. writel(0xff, &dp_regs->int_sta);
  122. /* 0:mask,1: unmask */
  123. writel(0x00, &dp_regs->int_sta_mask1);
  124. writel(0x00, &dp_regs->int_sta_mask2);
  125. writel(0x00, &dp_regs->int_sta_mask3);
  126. writel(0x00, &dp_regs->int_sta_mask4);
  127. writel(0x00, &dp_regs->int_sta_mask);
  128. }
  129. void exynos_dp_reset(void)
  130. {
  131. unsigned int reg_func_1;
  132. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  133. /*dp tx sw reset*/
  134. writel(RESET_DP_TX, &dp_regs->tx_sw_reset);
  135. exynos_dp_enable_video_input(DP_DISABLE);
  136. exynos_dp_enable_video_bist(DP_DISABLE);
  137. exynos_dp_enable_video_mute(DP_DISABLE);
  138. /* software reset */
  139. reg_func_1 = MASTER_VID_FUNC_EN_N | SLAVE_VID_FUNC_EN_N |
  140. AUD_FIFO_FUNC_EN_N | AUD_FUNC_EN_N |
  141. HDCP_FUNC_EN_N | SW_FUNC_EN_N;
  142. writel(reg_func_1, &dp_regs->func_en1);
  143. writel(reg_func_1, &dp_regs->func_en2);
  144. mdelay(1);
  145. exynos_dp_init_analog_param();
  146. exynos_dp_init_interrupt();
  147. return;
  148. }
  149. void exynos_dp_enable_sw_func(unsigned int enable)
  150. {
  151. unsigned int reg;
  152. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  153. reg = readl(&dp_regs->func_en1);
  154. reg &= ~(SW_FUNC_EN_N);
  155. if (!enable)
  156. reg |= SW_FUNC_EN_N;
  157. writel(reg, &dp_regs->func_en1);
  158. return;
  159. }
  160. unsigned int exynos_dp_set_analog_power_down(unsigned int block, u32 enable)
  161. {
  162. unsigned int reg;
  163. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  164. reg = readl(&dp_regs->phy_pd);
  165. switch (block) {
  166. case AUX_BLOCK:
  167. reg &= ~(AUX_PD);
  168. if (enable)
  169. reg |= AUX_PD;
  170. break;
  171. case CH0_BLOCK:
  172. reg &= ~(CH0_PD);
  173. if (enable)
  174. reg |= CH0_PD;
  175. break;
  176. case CH1_BLOCK:
  177. reg &= ~(CH1_PD);
  178. if (enable)
  179. reg |= CH1_PD;
  180. break;
  181. case CH2_BLOCK:
  182. reg &= ~(CH2_PD);
  183. if (enable)
  184. reg |= CH2_PD;
  185. break;
  186. case CH3_BLOCK:
  187. reg &= ~(CH3_PD);
  188. if (enable)
  189. reg |= CH3_PD;
  190. break;
  191. case ANALOG_TOTAL:
  192. reg &= ~PHY_PD;
  193. if (enable)
  194. reg |= PHY_PD;
  195. break;
  196. case POWER_ALL:
  197. reg &= ~(PHY_PD | AUX_PD | CH0_PD | CH1_PD | CH2_PD |
  198. CH3_PD);
  199. if (enable)
  200. reg |= (PHY_PD | AUX_PD | CH0_PD | CH1_PD |
  201. CH2_PD | CH3_PD);
  202. break;
  203. default:
  204. printf("DP undefined block number : %d\n", block);
  205. return -1;
  206. }
  207. writel(reg, &dp_regs->phy_pd);
  208. return 0;
  209. }
  210. unsigned int exynos_dp_get_pll_lock_status(void)
  211. {
  212. unsigned int reg;
  213. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  214. reg = readl(&dp_regs->debug_ctl);
  215. if (reg & PLL_LOCK)
  216. return PLL_LOCKED;
  217. else
  218. return PLL_UNLOCKED;
  219. }
  220. static void exynos_dp_set_pll_power(unsigned int enable)
  221. {
  222. unsigned int reg;
  223. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  224. reg = readl(&dp_regs->pll_ctl);
  225. reg &= ~(DP_PLL_PD);
  226. if (!enable)
  227. reg |= DP_PLL_PD;
  228. writel(reg, &dp_regs->pll_ctl);
  229. }
  230. int exynos_dp_init_analog_func(void)
  231. {
  232. int ret = EXYNOS_DP_SUCCESS;
  233. unsigned int retry_cnt = 10;
  234. unsigned int reg;
  235. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  236. /*Power On All Analog block */
  237. exynos_dp_set_analog_power_down(POWER_ALL, DP_DISABLE);
  238. reg = PLL_LOCK_CHG;
  239. writel(reg, &dp_regs->common_int_sta1);
  240. reg = readl(&dp_regs->debug_ctl);
  241. reg &= ~(F_PLL_LOCK | PLL_LOCK_CTRL);
  242. writel(reg, &dp_regs->debug_ctl);
  243. /*Assert DP PLL Reset*/
  244. reg = readl(&dp_regs->pll_ctl);
  245. reg |= DP_PLL_RESET;
  246. writel(reg, &dp_regs->pll_ctl);
  247. mdelay(1);
  248. /*Deassert DP PLL Reset*/
  249. reg = readl(&dp_regs->pll_ctl);
  250. reg &= ~(DP_PLL_RESET);
  251. writel(reg, &dp_regs->pll_ctl);
  252. exynos_dp_set_pll_power(DP_ENABLE);
  253. while (exynos_dp_get_pll_lock_status() == PLL_UNLOCKED) {
  254. mdelay(1);
  255. retry_cnt--;
  256. if (retry_cnt == 0) {
  257. printf("DP dp's pll lock failed : retry : %d\n",
  258. retry_cnt);
  259. return -EINVAL;
  260. }
  261. }
  262. debug("dp's pll lock success(%d)\n", retry_cnt);
  263. /* Enable Serdes FIFO function and Link symbol clock domain module */
  264. reg = readl(&dp_regs->func_en2);
  265. reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
  266. | AUX_FUNC_EN_N);
  267. writel(reg, &dp_regs->func_en2);
  268. return ret;
  269. }
  270. void exynos_dp_init_hpd(void)
  271. {
  272. unsigned int reg;
  273. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  274. /* Clear interrupts releated to Hot Plug Dectect */
  275. reg = HOTPLUG_CHG | HPD_LOST | PLUG;
  276. writel(reg, &dp_regs->common_int_sta4);
  277. reg = INT_HPD;
  278. writel(reg, &dp_regs->int_sta);
  279. reg = readl(&dp_regs->sys_ctl3);
  280. reg &= ~(F_HPD | HPD_CTRL);
  281. writel(reg, &dp_regs->sys_ctl3);
  282. return;
  283. }
  284. static inline void exynos_dp_reset_aux(void)
  285. {
  286. unsigned int reg;
  287. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  288. /* Disable AUX channel module */
  289. reg = readl(&dp_regs->func_en2);
  290. reg |= AUX_FUNC_EN_N;
  291. writel(reg, &dp_regs->func_en2);
  292. return;
  293. }
  294. void exynos_dp_init_aux(void)
  295. {
  296. unsigned int reg;
  297. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  298. /* Clear inerrupts related to AUX channel */
  299. reg = RPLY_RECEIV | AUX_ERR;
  300. writel(reg, &dp_regs->int_sta);
  301. exynos_dp_reset_aux();
  302. /* Disable AUX transaction H/W retry */
  303. reg = AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(3)|
  304. AUX_HW_RETRY_INTERVAL_600_MICROSECONDS;
  305. writel(reg, &dp_regs->aux_hw_retry_ctl);
  306. /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
  307. reg = DEFER_CTRL_EN | DEFER_COUNT(1);
  308. writel(reg, &dp_regs->aux_ch_defer_ctl);
  309. /* Enable AUX channel module */
  310. reg = readl(&dp_regs->func_en2);
  311. reg &= ~AUX_FUNC_EN_N;
  312. writel(reg, &dp_regs->func_en2);
  313. return;
  314. }
  315. void exynos_dp_config_interrupt(void)
  316. {
  317. unsigned int reg;
  318. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  319. /* 0: mask, 1: unmask */
  320. reg = COMMON_INT_MASK_1;
  321. writel(reg, &dp_regs->common_int_mask1);
  322. reg = COMMON_INT_MASK_2;
  323. writel(reg, &dp_regs->common_int_mask2);
  324. reg = COMMON_INT_MASK_3;
  325. writel(reg, &dp_regs->common_int_mask3);
  326. reg = COMMON_INT_MASK_4;
  327. writel(reg, &dp_regs->common_int_mask4);
  328. reg = INT_STA_MASK;
  329. writel(reg, &dp_regs->int_sta_mask);
  330. return;
  331. }
  332. unsigned int exynos_dp_get_plug_in_status(void)
  333. {
  334. unsigned int reg;
  335. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  336. reg = readl(&dp_regs->sys_ctl3);
  337. if (reg & HPD_STATUS)
  338. return 0;
  339. return -1;
  340. }
  341. unsigned int exynos_dp_detect_hpd(void)
  342. {
  343. int timeout_loop = DP_TIMEOUT_LOOP_COUNT;
  344. mdelay(2);
  345. while (exynos_dp_get_plug_in_status() != 0) {
  346. if (timeout_loop == 0)
  347. return -EINVAL;
  348. mdelay(10);
  349. timeout_loop--;
  350. }
  351. return EXYNOS_DP_SUCCESS;
  352. }
  353. unsigned int exynos_dp_start_aux_transaction(void)
  354. {
  355. unsigned int reg;
  356. unsigned int ret = 0;
  357. unsigned int retry_cnt;
  358. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  359. /* Enable AUX CH operation */
  360. reg = readl(&dp_regs->aux_ch_ctl2);
  361. reg |= AUX_EN;
  362. writel(reg, &dp_regs->aux_ch_ctl2);
  363. retry_cnt = 10;
  364. while (retry_cnt) {
  365. reg = readl(&dp_regs->int_sta);
  366. if (!(reg & RPLY_RECEIV)) {
  367. if (retry_cnt == 0) {
  368. printf("DP Reply Timeout!!\n");
  369. ret = -EAGAIN;
  370. return ret;
  371. }
  372. mdelay(1);
  373. retry_cnt--;
  374. } else
  375. break;
  376. }
  377. /* Clear interrupt source for AUX CH command reply */
  378. writel(reg, &dp_regs->int_sta);
  379. /* Clear interrupt source for AUX CH access error */
  380. reg = readl(&dp_regs->int_sta);
  381. if (reg & AUX_ERR) {
  382. printf("DP Aux Access Error\n");
  383. writel(AUX_ERR, &dp_regs->int_sta);
  384. ret = -EAGAIN;
  385. return ret;
  386. }
  387. /* Check AUX CH error access status */
  388. reg = readl(&dp_regs->aux_ch_sta);
  389. if ((reg & AUX_STATUS_MASK) != 0) {
  390. debug("DP AUX CH error happens: %x\n", reg & AUX_STATUS_MASK);
  391. ret = -EAGAIN;
  392. return ret;
  393. }
  394. return EXYNOS_DP_SUCCESS;
  395. }
  396. unsigned int exynos_dp_write_byte_to_dpcd(unsigned int reg_addr,
  397. unsigned char data)
  398. {
  399. unsigned int reg, ret;
  400. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  401. /* Clear AUX CH data buffer */
  402. reg = BUF_CLR;
  403. writel(reg, &dp_regs->buffer_data_ctl);
  404. /* Select DPCD device address */
  405. reg = AUX_ADDR_7_0(reg_addr);
  406. writel(reg, &dp_regs->aux_addr_7_0);
  407. reg = AUX_ADDR_15_8(reg_addr);
  408. writel(reg, &dp_regs->aux_addr_15_8);
  409. reg = AUX_ADDR_19_16(reg_addr);
  410. writel(reg, &dp_regs->aux_addr_19_16);
  411. /* Write data buffer */
  412. reg = (unsigned int)data;
  413. writel(reg, &dp_regs->buf_data0);
  414. /*
  415. * Set DisplayPort transaction and write 1 byte
  416. * If bit 3 is 1, DisplayPort transaction.
  417. * If Bit 3 is 0, I2C transaction.
  418. */
  419. reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
  420. writel(reg, &dp_regs->aux_ch_ctl1);
  421. /* Start AUX transaction */
  422. ret = exynos_dp_start_aux_transaction();
  423. if (ret != EXYNOS_DP_SUCCESS) {
  424. printf("DP Aux transaction failed\n");
  425. return ret;
  426. }
  427. return ret;
  428. }
  429. unsigned int exynos_dp_read_byte_from_dpcd(unsigned int reg_addr,
  430. unsigned char *data)
  431. {
  432. unsigned int reg;
  433. int retval;
  434. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  435. /* Clear AUX CH data buffer */
  436. reg = BUF_CLR;
  437. writel(reg, &dp_regs->buffer_data_ctl);
  438. /* Select DPCD device address */
  439. reg = AUX_ADDR_7_0(reg_addr);
  440. writel(reg, &dp_regs->aux_addr_7_0);
  441. reg = AUX_ADDR_15_8(reg_addr);
  442. writel(reg, &dp_regs->aux_addr_15_8);
  443. reg = AUX_ADDR_19_16(reg_addr);
  444. writel(reg, &dp_regs->aux_addr_19_16);
  445. /*
  446. * Set DisplayPort transaction and read 1 byte
  447. * If bit 3 is 1, DisplayPort transaction.
  448. * If Bit 3 is 0, I2C transaction.
  449. */
  450. reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
  451. writel(reg, &dp_regs->aux_ch_ctl1);
  452. /* Start AUX transaction */
  453. retval = exynos_dp_start_aux_transaction();
  454. if (!retval)
  455. debug("DP Aux Transaction fail!\n");
  456. /* Read data buffer */
  457. reg = readl(&dp_regs->buf_data0);
  458. *data = (unsigned char)(reg & 0xff);
  459. return retval;
  460. }
  461. unsigned int exynos_dp_write_bytes_to_dpcd(unsigned int reg_addr,
  462. unsigned int count,
  463. unsigned char data[])
  464. {
  465. unsigned int reg;
  466. unsigned int start_offset;
  467. unsigned int cur_data_count;
  468. unsigned int cur_data_idx;
  469. unsigned int retry_cnt;
  470. unsigned int ret = 0;
  471. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  472. /* Clear AUX CH data buffer */
  473. reg = BUF_CLR;
  474. writel(reg, &dp_regs->buffer_data_ctl);
  475. start_offset = 0;
  476. while (start_offset < count) {
  477. /* Buffer size of AUX CH is 16 * 4bytes */
  478. if ((count - start_offset) > 16)
  479. cur_data_count = 16;
  480. else
  481. cur_data_count = count - start_offset;
  482. retry_cnt = 5;
  483. while (retry_cnt) {
  484. /* Select DPCD device address */
  485. reg = AUX_ADDR_7_0(reg_addr + start_offset);
  486. writel(reg, &dp_regs->aux_addr_7_0);
  487. reg = AUX_ADDR_15_8(reg_addr + start_offset);
  488. writel(reg, &dp_regs->aux_addr_15_8);
  489. reg = AUX_ADDR_19_16(reg_addr + start_offset);
  490. writel(reg, &dp_regs->aux_addr_19_16);
  491. for (cur_data_idx = 0; cur_data_idx < cur_data_count;
  492. cur_data_idx++) {
  493. reg = data[start_offset + cur_data_idx];
  494. writel(reg, (unsigned int)&dp_regs->buf_data0 +
  495. (4 * cur_data_idx));
  496. }
  497. /*
  498. * Set DisplayPort transaction and write
  499. * If bit 3 is 1, DisplayPort transaction.
  500. * If Bit 3 is 0, I2C transaction.
  501. */
  502. reg = AUX_LENGTH(cur_data_count) |
  503. AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
  504. writel(reg, &dp_regs->aux_ch_ctl1);
  505. /* Start AUX transaction */
  506. ret = exynos_dp_start_aux_transaction();
  507. if (ret != EXYNOS_DP_SUCCESS) {
  508. if (retry_cnt == 0) {
  509. printf("DP Aux Transaction failed\n");
  510. return ret;
  511. }
  512. retry_cnt--;
  513. } else
  514. break;
  515. }
  516. start_offset += cur_data_count;
  517. }
  518. return ret;
  519. }
  520. unsigned int exynos_dp_read_bytes_from_dpcd(unsigned int reg_addr,
  521. unsigned int count,
  522. unsigned char data[])
  523. {
  524. unsigned int reg;
  525. unsigned int start_offset;
  526. unsigned int cur_data_count;
  527. unsigned int cur_data_idx;
  528. unsigned int retry_cnt;
  529. unsigned int ret = 0;
  530. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  531. /* Clear AUX CH data buffer */
  532. reg = BUF_CLR;
  533. writel(reg, &dp_regs->buffer_data_ctl);
  534. start_offset = 0;
  535. while (start_offset < count) {
  536. /* Buffer size of AUX CH is 16 * 4bytes */
  537. if ((count - start_offset) > 16)
  538. cur_data_count = 16;
  539. else
  540. cur_data_count = count - start_offset;
  541. retry_cnt = 5;
  542. while (retry_cnt) {
  543. /* Select DPCD device address */
  544. reg = AUX_ADDR_7_0(reg_addr + start_offset);
  545. writel(reg, &dp_regs->aux_addr_7_0);
  546. reg = AUX_ADDR_15_8(reg_addr + start_offset);
  547. writel(reg, &dp_regs->aux_addr_15_8);
  548. reg = AUX_ADDR_19_16(reg_addr + start_offset);
  549. writel(reg, &dp_regs->aux_addr_19_16);
  550. /*
  551. * Set DisplayPort transaction and read
  552. * If bit 3 is 1, DisplayPort transaction.
  553. * If Bit 3 is 0, I2C transaction.
  554. */
  555. reg = AUX_LENGTH(cur_data_count) |
  556. AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
  557. writel(reg, &dp_regs->aux_ch_ctl1);
  558. /* Start AUX transaction */
  559. ret = exynos_dp_start_aux_transaction();
  560. if (ret != EXYNOS_DP_SUCCESS) {
  561. if (retry_cnt == 0) {
  562. printf("DP Aux Transaction failed\n");
  563. return ret;
  564. }
  565. retry_cnt--;
  566. } else
  567. break;
  568. }
  569. for (cur_data_idx = 0; cur_data_idx < cur_data_count;
  570. cur_data_idx++) {
  571. reg = readl((unsigned int)&dp_regs->buf_data0 +
  572. 4 * cur_data_idx);
  573. data[start_offset + cur_data_idx] = (unsigned char)reg;
  574. }
  575. start_offset += cur_data_count;
  576. }
  577. return ret;
  578. }
  579. int exynos_dp_select_i2c_device(unsigned int device_addr,
  580. unsigned int reg_addr)
  581. {
  582. unsigned int reg;
  583. int retval;
  584. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  585. /* Set EDID device address */
  586. reg = device_addr;
  587. writel(reg, &dp_regs->aux_addr_7_0);
  588. writel(0x0, &dp_regs->aux_addr_15_8);
  589. writel(0x0, &dp_regs->aux_addr_19_16);
  590. /* Set offset from base address of EDID device */
  591. writel(reg_addr, &dp_regs->buf_data0);
  592. /*
  593. * Set I2C transaction and write address
  594. * If bit 3 is 1, DisplayPort transaction.
  595. * If Bit 3 is 0, I2C transaction.
  596. */
  597. reg = AUX_TX_COMM_I2C_TRANSACTION | AUX_TX_COMM_MOT |
  598. AUX_TX_COMM_WRITE;
  599. writel(reg, &dp_regs->aux_ch_ctl1);
  600. /* Start AUX transaction */
  601. retval = exynos_dp_start_aux_transaction();
  602. if (retval != 0)
  603. printf("%s: DP Aux Transaction fail!\n", __func__);
  604. return retval;
  605. }
  606. int exynos_dp_read_byte_from_i2c(unsigned int device_addr,
  607. unsigned int reg_addr,
  608. unsigned int *data)
  609. {
  610. unsigned int reg;
  611. int i;
  612. int retval;
  613. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  614. for (i = 0; i < 10; i++) {
  615. /* Clear AUX CH data buffer */
  616. reg = BUF_CLR;
  617. writel(reg, &dp_regs->buffer_data_ctl);
  618. /* Select EDID device */
  619. retval = exynos_dp_select_i2c_device(device_addr, reg_addr);
  620. if (retval != 0) {
  621. printf("DP Select EDID device fail. retry !\n");
  622. continue;
  623. }
  624. /*
  625. * Set I2C transaction and read data
  626. * If bit 3 is 1, DisplayPort transaction.
  627. * If Bit 3 is 0, I2C transaction.
  628. */
  629. reg = AUX_TX_COMM_I2C_TRANSACTION |
  630. AUX_TX_COMM_READ;
  631. writel(reg, &dp_regs->aux_ch_ctl1);
  632. /* Start AUX transaction */
  633. retval = exynos_dp_start_aux_transaction();
  634. if (retval != EXYNOS_DP_SUCCESS)
  635. printf("%s: DP Aux Transaction fail!\n", __func__);
  636. }
  637. /* Read data */
  638. if (retval == 0)
  639. *data = readl(&dp_regs->buf_data0);
  640. return retval;
  641. }
  642. int exynos_dp_read_bytes_from_i2c(unsigned int device_addr,
  643. unsigned int reg_addr, unsigned int count, unsigned char edid[])
  644. {
  645. unsigned int reg;
  646. unsigned int i, j;
  647. unsigned int cur_data_idx;
  648. unsigned int defer = 0;
  649. int retval = 0;
  650. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  651. for (i = 0; i < count; i += 16) { /* use 16 burst */
  652. for (j = 0; j < 100; j++) {
  653. /* Clear AUX CH data buffer */
  654. reg = BUF_CLR;
  655. writel(reg, &dp_regs->buffer_data_ctl);
  656. /* Set normal AUX CH command */
  657. reg = readl(&dp_regs->aux_ch_ctl2);
  658. reg &= ~ADDR_ONLY;
  659. writel(reg, &dp_regs->aux_ch_ctl2);
  660. /*
  661. * If Rx sends defer, Tx sends only reads
  662. * request without sending addres
  663. */
  664. if (!defer)
  665. retval =
  666. exynos_dp_select_i2c_device(device_addr,
  667. reg_addr + i);
  668. else
  669. defer = 0;
  670. if (retval == EXYNOS_DP_SUCCESS) {
  671. /*
  672. * Set I2C transaction and write data
  673. * If bit 3 is 1, DisplayPort transaction.
  674. * If Bit 3 is 0, I2C transaction.
  675. */
  676. reg = AUX_LENGTH(16) |
  677. AUX_TX_COMM_I2C_TRANSACTION |
  678. AUX_TX_COMM_READ;
  679. writel(reg, &dp_regs->aux_ch_ctl1);
  680. /* Start AUX transaction */
  681. retval = exynos_dp_start_aux_transaction();
  682. if (retval == 0)
  683. break;
  684. else
  685. printf("DP Aux Transaction fail!\n");
  686. }
  687. /* Check if Rx sends defer */
  688. reg = readl(&dp_regs->aux_rx_comm);
  689. if (reg == AUX_RX_COMM_AUX_DEFER ||
  690. reg == AUX_RX_COMM_I2C_DEFER) {
  691. printf("DP Defer: %d\n\n", reg);
  692. defer = 1;
  693. }
  694. }
  695. for (cur_data_idx = 0; cur_data_idx < 16; cur_data_idx++) {
  696. reg = readl((unsigned int)&dp_regs->buf_data0
  697. + 4 * cur_data_idx);
  698. edid[i + cur_data_idx] = (unsigned char)reg;
  699. }
  700. }
  701. return retval;
  702. }
  703. void exynos_dp_reset_macro(void)
  704. {
  705. unsigned int reg;
  706. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  707. reg = readl(&dp_regs->phy_test);
  708. reg |= MACRO_RST;
  709. writel(reg, &dp_regs->phy_test);
  710. /* 10 us is the minimum Macro reset time. */
  711. mdelay(1);
  712. reg &= ~MACRO_RST;
  713. writel(reg, &dp_regs->phy_test);
  714. }
  715. void exynos_dp_set_link_bandwidth(unsigned char bwtype)
  716. {
  717. unsigned int reg;
  718. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  719. reg = (unsigned int)bwtype;
  720. /* Set bandwidth to 2.7G or 1.62G */
  721. if ((bwtype == DP_LANE_BW_1_62) || (bwtype == DP_LANE_BW_2_70))
  722. writel(reg, &dp_regs->link_bw_set);
  723. }
  724. unsigned char exynos_dp_get_link_bandwidth(void)
  725. {
  726. unsigned char ret;
  727. unsigned int reg;
  728. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  729. reg = readl(&dp_regs->link_bw_set);
  730. ret = (unsigned char)reg;
  731. return ret;
  732. }
  733. void exynos_dp_set_lane_count(unsigned char count)
  734. {
  735. unsigned int reg;
  736. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  737. reg = (unsigned int)count;
  738. if ((count == DP_LANE_CNT_1) || (count == DP_LANE_CNT_2) ||
  739. (count == DP_LANE_CNT_4))
  740. writel(reg, &dp_regs->lane_count_set);
  741. }
  742. unsigned int exynos_dp_get_lane_count(void)
  743. {
  744. unsigned int reg;
  745. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  746. reg = readl(&dp_regs->lane_count_set);
  747. return reg;
  748. }
  749. unsigned char exynos_dp_get_lanex_pre_emphasis(unsigned char lanecnt)
  750. {
  751. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  752. unsigned int reg_list[DP_LANE_CNT_4] = {
  753. (unsigned int)&dp_regs->ln0_link_training_ctl,
  754. (unsigned int)&dp_regs->ln1_link_training_ctl,
  755. (unsigned int)&dp_regs->ln2_link_training_ctl,
  756. (unsigned int)&dp_regs->ln3_link_training_ctl,
  757. };
  758. return readl(reg_list[lanecnt]);
  759. }
  760. void exynos_dp_set_lanex_pre_emphasis(unsigned char request_val,
  761. unsigned char lanecnt)
  762. {
  763. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  764. unsigned int reg_list[DP_LANE_CNT_4] = {
  765. (unsigned int)&dp_regs->ln0_link_training_ctl,
  766. (unsigned int)&dp_regs->ln1_link_training_ctl,
  767. (unsigned int)&dp_regs->ln2_link_training_ctl,
  768. (unsigned int)&dp_regs->ln3_link_training_ctl,
  769. };
  770. writel(request_val, reg_list[lanecnt]);
  771. }
  772. void exynos_dp_set_lane_pre_emphasis(unsigned int level, unsigned char lanecnt)
  773. {
  774. unsigned char i;
  775. unsigned int reg;
  776. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  777. unsigned int reg_list[DP_LANE_CNT_4] = {
  778. (unsigned int)&dp_regs->ln0_link_training_ctl,
  779. (unsigned int)&dp_regs->ln1_link_training_ctl,
  780. (unsigned int)&dp_regs->ln2_link_training_ctl,
  781. (unsigned int)&dp_regs->ln3_link_training_ctl,
  782. };
  783. unsigned int reg_shift[DP_LANE_CNT_4] = {
  784. PRE_EMPHASIS_SET_0_SHIFT,
  785. PRE_EMPHASIS_SET_1_SHIFT,
  786. PRE_EMPHASIS_SET_2_SHIFT,
  787. PRE_EMPHASIS_SET_3_SHIFT
  788. };
  789. for (i = 0; i < lanecnt; i++) {
  790. reg = level << reg_shift[i];
  791. writel(reg, reg_list[i]);
  792. }
  793. }
  794. void exynos_dp_set_training_pattern(unsigned int pattern)
  795. {
  796. unsigned int reg = 0;
  797. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  798. switch (pattern) {
  799. case PRBS7:
  800. reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_PRBS7;
  801. break;
  802. case D10_2:
  803. reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_D10_2;
  804. break;
  805. case TRAINING_PTN1:
  806. reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN1;
  807. break;
  808. case TRAINING_PTN2:
  809. reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN2;
  810. break;
  811. case DP_NONE:
  812. reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_DISABLE |
  813. SW_TRAINING_PATTERN_SET_NORMAL;
  814. break;
  815. default:
  816. break;
  817. }
  818. writel(reg, &dp_regs->training_ptn_set);
  819. }
  820. void exynos_dp_enable_enhanced_mode(unsigned char enable)
  821. {
  822. unsigned int reg;
  823. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  824. reg = readl(&dp_regs->sys_ctl4);
  825. reg &= ~ENHANCED;
  826. if (enable)
  827. reg |= ENHANCED;
  828. writel(reg, &dp_regs->sys_ctl4);
  829. }
  830. void exynos_dp_enable_scrambling(unsigned int enable)
  831. {
  832. unsigned int reg;
  833. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  834. reg = readl(&dp_regs->training_ptn_set);
  835. reg &= ~(SCRAMBLING_DISABLE);
  836. if (!enable)
  837. reg |= SCRAMBLING_DISABLE;
  838. writel(reg, &dp_regs->training_ptn_set);
  839. }
  840. int exynos_dp_init_video(void)
  841. {
  842. unsigned int reg;
  843. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  844. /* Clear VID_CLK_CHG[1] and VID_FORMAT_CHG[3] and VSYNC_DET[7] */
  845. reg = VSYNC_DET | VID_FORMAT_CHG | VID_CLK_CHG;
  846. writel(reg, &dp_regs->common_int_sta1);
  847. /* I_STRM__CLK detect : DE_CTL : Auto detect */
  848. reg &= ~DET_CTRL;
  849. writel(reg, &dp_regs->sys_ctl1);
  850. return 0;
  851. }
  852. void exynos_dp_config_video_slave_mode(struct edp_video_info *video_info)
  853. {
  854. unsigned int reg;
  855. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  856. /* Video Slave mode setting */
  857. reg = readl(&dp_regs->func_en1);
  858. reg &= ~(MASTER_VID_FUNC_EN_N|SLAVE_VID_FUNC_EN_N);
  859. reg |= MASTER_VID_FUNC_EN_N;
  860. writel(reg, &dp_regs->func_en1);
  861. /* Configure Interlaced for slave mode video */
  862. reg = readl(&dp_regs->video_ctl10);
  863. reg &= ~INTERACE_SCAN_CFG;
  864. reg |= (video_info->interlaced << INTERACE_SCAN_CFG_SHIFT);
  865. writel(reg, &dp_regs->video_ctl10);
  866. /* Configure V sync polarity for slave mode video */
  867. reg = readl(&dp_regs->video_ctl10);
  868. reg &= ~VSYNC_POLARITY_CFG;
  869. reg |= (video_info->v_sync_polarity << V_S_POLARITY_CFG_SHIFT);
  870. writel(reg, &dp_regs->video_ctl10);
  871. /* Configure H sync polarity for slave mode video */
  872. reg = readl(&dp_regs->video_ctl10);
  873. reg &= ~HSYNC_POLARITY_CFG;
  874. reg |= (video_info->h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
  875. writel(reg, &dp_regs->video_ctl10);
  876. /*Set video mode to slave mode */
  877. reg = AUDIO_MODE_SPDIF_MODE | VIDEO_MODE_SLAVE_MODE;
  878. writel(reg, &dp_regs->soc_general_ctl);
  879. }
  880. void exynos_dp_set_video_color_format(struct edp_video_info *video_info)
  881. {
  882. unsigned int reg;
  883. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  884. /* Configure the input color depth, color space, dynamic range */
  885. reg = (video_info->dynamic_range << IN_D_RANGE_SHIFT) |
  886. (video_info->color_depth << IN_BPC_SHIFT) |
  887. (video_info->color_space << IN_COLOR_F_SHIFT);
  888. writel(reg, &dp_regs->video_ctl2);
  889. /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
  890. reg = readl(&dp_regs->video_ctl3);
  891. reg &= ~IN_YC_COEFFI_MASK;
  892. if (video_info->ycbcr_coeff)
  893. reg |= IN_YC_COEFFI_ITU709;
  894. else
  895. reg |= IN_YC_COEFFI_ITU601;
  896. writel(reg, &dp_regs->video_ctl3);
  897. }
  898. int exynos_dp_config_video_bist(struct edp_device_info *edp_info)
  899. {
  900. unsigned int reg;
  901. unsigned int bist_type = 0;
  902. struct edp_video_info video_info = edp_info->video_info;
  903. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  904. /* For master mode, you don't need to set the video format */
  905. if (video_info.master_mode == 0) {
  906. writel(TOTAL_LINE_CFG_L(edp_info->disp_info.v_total),
  907. &dp_regs->total_ln_cfg_l);
  908. writel(TOTAL_LINE_CFG_H(edp_info->disp_info.v_total),
  909. &dp_regs->total_ln_cfg_h);
  910. writel(ACTIVE_LINE_CFG_L(edp_info->disp_info.v_res),
  911. &dp_regs->active_ln_cfg_l);
  912. writel(ACTIVE_LINE_CFG_H(edp_info->disp_info.v_res),
  913. &dp_regs->active_ln_cfg_h);
  914. writel(edp_info->disp_info.v_sync_width,
  915. &dp_regs->vsw_cfg);
  916. writel(edp_info->disp_info.v_back_porch,
  917. &dp_regs->vbp_cfg);
  918. writel(edp_info->disp_info.v_front_porch,
  919. &dp_regs->vfp_cfg);
  920. writel(TOTAL_PIXEL_CFG_L(edp_info->disp_info.h_total),
  921. &dp_regs->total_pix_cfg_l);
  922. writel(TOTAL_PIXEL_CFG_H(edp_info->disp_info.h_total),
  923. &dp_regs->total_pix_cfg_h);
  924. writel(ACTIVE_PIXEL_CFG_L(edp_info->disp_info.h_res),
  925. &dp_regs->active_pix_cfg_l);
  926. writel(ACTIVE_PIXEL_CFG_H(edp_info->disp_info.h_res),
  927. &dp_regs->active_pix_cfg_h);
  928. writel(H_F_PORCH_CFG_L(edp_info->disp_info.h_front_porch),
  929. &dp_regs->hfp_cfg_l);
  930. writel(H_F_PORCH_CFG_H(edp_info->disp_info.h_front_porch),
  931. &dp_regs->hfp_cfg_h);
  932. writel(H_SYNC_PORCH_CFG_L(edp_info->disp_info.h_sync_width),
  933. &dp_regs->hsw_cfg_l);
  934. writel(H_SYNC_PORCH_CFG_H(edp_info->disp_info.h_sync_width),
  935. &dp_regs->hsw_cfg_h);
  936. writel(H_B_PORCH_CFG_L(edp_info->disp_info.h_back_porch),
  937. &dp_regs->hbp_cfg_l);
  938. writel(H_B_PORCH_CFG_H(edp_info->disp_info.h_back_porch),
  939. &dp_regs->hbp_cfg_h);
  940. /*
  941. * Set SLAVE_I_SCAN_CFG[2], VSYNC_P_CFG[1],
  942. * HSYNC_P_CFG[0] properly
  943. */
  944. reg = (video_info.interlaced << INTERACE_SCAN_CFG_SHIFT |
  945. video_info.v_sync_polarity << V_S_POLARITY_CFG_SHIFT |
  946. video_info.h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
  947. writel(reg, &dp_regs->video_ctl10);
  948. }
  949. /* BIST color bar width set--set to each bar is 32 pixel width */
  950. switch (video_info.bist_pattern) {
  951. case COLORBAR_32:
  952. bist_type = BIST_WIDTH_BAR_32_PIXEL |
  953. BIST_TYPE_COLOR_BAR;
  954. break;
  955. case COLORBAR_64:
  956. bist_type = BIST_WIDTH_BAR_64_PIXEL |
  957. BIST_TYPE_COLOR_BAR;
  958. break;
  959. case WHITE_GRAY_BALCKBAR_32:
  960. bist_type = BIST_WIDTH_BAR_32_PIXEL |
  961. BIST_TYPE_WHITE_GRAY_BLACK_BAR;
  962. break;
  963. case WHITE_GRAY_BALCKBAR_64:
  964. bist_type = BIST_WIDTH_BAR_64_PIXEL |
  965. BIST_TYPE_WHITE_GRAY_BLACK_BAR;
  966. break;
  967. case MOBILE_WHITEBAR_32:
  968. bist_type = BIST_WIDTH_BAR_32_PIXEL |
  969. BIST_TYPE_MOBILE_WHITE_BAR;
  970. break;
  971. case MOBILE_WHITEBAR_64:
  972. bist_type = BIST_WIDTH_BAR_64_PIXEL |
  973. BIST_TYPE_MOBILE_WHITE_BAR;
  974. break;
  975. default:
  976. return -1;
  977. }
  978. reg = bist_type;
  979. writel(reg, &dp_regs->video_ctl4);
  980. return 0;
  981. }
  982. unsigned int exynos_dp_is_slave_video_stream_clock_on(void)
  983. {
  984. unsigned int reg;
  985. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  986. /* Update Video stream clk detect status */
  987. reg = readl(&dp_regs->sys_ctl1);
  988. writel(reg, &dp_regs->sys_ctl1);
  989. reg = readl(&dp_regs->sys_ctl1);
  990. if (!(reg & DET_STA)) {
  991. debug("DP Input stream clock not detected.\n");
  992. return -EIO;
  993. }
  994. return EXYNOS_DP_SUCCESS;
  995. }
  996. void exynos_dp_set_video_cr_mn(unsigned int type, unsigned int m_value,
  997. unsigned int n_value)
  998. {
  999. unsigned int reg;
  1000. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  1001. if (type == REGISTER_M) {
  1002. reg = readl(&dp_regs->sys_ctl4);
  1003. reg |= FIX_M_VID;
  1004. writel(reg, &dp_regs->sys_ctl4);
  1005. reg = M_VID0_CFG(m_value);
  1006. writel(reg, &dp_regs->m_vid0);
  1007. reg = M_VID1_CFG(m_value);
  1008. writel(reg, &dp_regs->m_vid1);
  1009. reg = M_VID2_CFG(m_value);
  1010. writel(reg, &dp_regs->m_vid2);
  1011. reg = N_VID0_CFG(n_value);
  1012. writel(reg, &dp_regs->n_vid0);
  1013. reg = N_VID1_CFG(n_value);
  1014. writel(reg, &dp_regs->n_vid1);
  1015. reg = N_VID2_CFG(n_value);
  1016. writel(reg, &dp_regs->n_vid2);
  1017. } else {
  1018. reg = readl(&dp_regs->sys_ctl4);
  1019. reg &= ~FIX_M_VID;
  1020. writel(reg, &dp_regs->sys_ctl4);
  1021. }
  1022. }
  1023. void exynos_dp_set_video_timing_mode(unsigned int type)
  1024. {
  1025. unsigned int reg;
  1026. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  1027. reg = readl(&dp_regs->video_ctl10);
  1028. reg &= ~FORMAT_SEL;
  1029. if (type != VIDEO_TIMING_FROM_CAPTURE)
  1030. reg |= FORMAT_SEL;
  1031. writel(reg, &dp_regs->video_ctl10);
  1032. }
  1033. void exynos_dp_enable_video_master(unsigned int enable)
  1034. {
  1035. unsigned int reg;
  1036. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  1037. reg = readl(&dp_regs->soc_general_ctl);
  1038. if (enable) {
  1039. reg &= ~VIDEO_MODE_MASK;
  1040. reg |= VIDEO_MASTER_MODE_EN | VIDEO_MODE_MASTER_MODE;
  1041. } else {
  1042. reg &= ~VIDEO_MODE_MASK;
  1043. reg |= VIDEO_MODE_SLAVE_MODE;
  1044. }
  1045. writel(reg, &dp_regs->soc_general_ctl);
  1046. }
  1047. void exynos_dp_start_video(void)
  1048. {
  1049. unsigned int reg;
  1050. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  1051. /* Enable Video input and disable Mute */
  1052. reg = readl(&dp_regs->video_ctl1);
  1053. reg |= VIDEO_EN;
  1054. writel(reg, &dp_regs->video_ctl1);
  1055. }
  1056. unsigned int exynos_dp_is_video_stream_on(void)
  1057. {
  1058. unsigned int reg;
  1059. struct exynos_dp *dp_regs = (struct exynos_dp *)samsung_get_base_dp();
  1060. /* Update STRM_VALID */
  1061. reg = readl(&dp_regs->sys_ctl3);
  1062. writel(reg, &dp_regs->sys_ctl3);
  1063. reg = readl(&dp_regs->sys_ctl3);
  1064. if (!(reg & STRM_VALID))
  1065. return -EIO;
  1066. return EXYNOS_DP_SUCCESS;
  1067. }