exynos_dp_reg.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /*
  2. * Samsung DP (Display port) register interface driver.
  3. *
  4. * Copyright (C) 2012 Samsung Electronics Co., Ltd.
  5. * Author: Jingoo Han <jg1.han@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/io.h>
  14. #include <linux/delay.h>
  15. #include <linux/gpio.h>
  16. #include "exynos_dp_core.h"
  17. #include "exynos_dp_reg.h"
  18. #define COMMON_INT_MASK_1 0
  19. #define COMMON_INT_MASK_2 0
  20. #define COMMON_INT_MASK_3 0
  21. #define COMMON_INT_MASK_4 (HOTPLUG_CHG | HPD_LOST | PLUG)
  22. #define INT_STA_MASK INT_HPD
  23. void exynos_dp_enable_video_mute(struct exynos_dp_device *dp, bool enable)
  24. {
  25. u32 reg;
  26. if (enable) {
  27. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  28. reg |= HDCP_VIDEO_MUTE;
  29. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  30. } else {
  31. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  32. reg &= ~HDCP_VIDEO_MUTE;
  33. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  34. }
  35. }
  36. void exynos_dp_stop_video(struct exynos_dp_device *dp)
  37. {
  38. u32 reg;
  39. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  40. reg &= ~VIDEO_EN;
  41. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  42. }
  43. void exynos_dp_lane_swap(struct exynos_dp_device *dp, bool enable)
  44. {
  45. u32 reg;
  46. if (enable)
  47. reg = LANE3_MAP_LOGIC_LANE_0 | LANE2_MAP_LOGIC_LANE_1 |
  48. LANE1_MAP_LOGIC_LANE_2 | LANE0_MAP_LOGIC_LANE_3;
  49. else
  50. reg = LANE3_MAP_LOGIC_LANE_3 | LANE2_MAP_LOGIC_LANE_2 |
  51. LANE1_MAP_LOGIC_LANE_1 | LANE0_MAP_LOGIC_LANE_0;
  52. writel(reg, dp->reg_base + EXYNOS_DP_LANE_MAP);
  53. }
  54. void exynos_dp_init_analog_param(struct exynos_dp_device *dp)
  55. {
  56. u32 reg;
  57. reg = TX_TERMINAL_CTRL_50_OHM;
  58. writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_1);
  59. reg = SEL_24M | TX_DVDD_BIT_1_0625V;
  60. writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_2);
  61. reg = DRIVE_DVDD_BIT_1_0625V | VCO_BIT_600_MICRO;
  62. writel(reg, dp->reg_base + EXYNOS_DP_ANALOG_CTL_3);
  63. reg = PD_RING_OSC | AUX_TERMINAL_CTRL_50_OHM |
  64. TX_CUR1_2X | TX_CUR_16_MA;
  65. writel(reg, dp->reg_base + EXYNOS_DP_PLL_FILTER_CTL_1);
  66. reg = CH3_AMP_400_MV | CH2_AMP_400_MV |
  67. CH1_AMP_400_MV | CH0_AMP_400_MV;
  68. writel(reg, dp->reg_base + EXYNOS_DP_TX_AMP_TUNING_CTL);
  69. }
  70. void exynos_dp_init_interrupt(struct exynos_dp_device *dp)
  71. {
  72. /* Set interrupt pin assertion polarity as high */
  73. writel(INT_POL1 | INT_POL0, dp->reg_base + EXYNOS_DP_INT_CTL);
  74. /* Clear pending regisers */
  75. writel(0xff, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_1);
  76. writel(0x4f, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_2);
  77. writel(0xe0, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_3);
  78. writel(0xe7, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_4);
  79. writel(0x63, dp->reg_base + EXYNOS_DP_INT_STA);
  80. /* 0:mask,1: unmask */
  81. writel(0x00, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_1);
  82. writel(0x00, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_2);
  83. writel(0x00, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_3);
  84. writel(0x00, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_4);
  85. writel(0x00, dp->reg_base + EXYNOS_DP_INT_STA_MASK);
  86. }
  87. void exynos_dp_reset(struct exynos_dp_device *dp)
  88. {
  89. u32 reg;
  90. exynos_dp_stop_video(dp);
  91. exynos_dp_enable_video_mute(dp, 0);
  92. reg = MASTER_VID_FUNC_EN_N | SLAVE_VID_FUNC_EN_N |
  93. AUD_FIFO_FUNC_EN_N | AUD_FUNC_EN_N |
  94. HDCP_FUNC_EN_N | SW_FUNC_EN_N;
  95. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_1);
  96. reg = SSC_FUNC_EN_N | AUX_FUNC_EN_N |
  97. SERDES_FIFO_FUNC_EN_N |
  98. LS_CLK_DOMAIN_FUNC_EN_N;
  99. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  100. usleep_range(20, 30);
  101. exynos_dp_lane_swap(dp, 0);
  102. writel(0x0, dp->reg_base + EXYNOS_DP_SYS_CTL_1);
  103. writel(0x40, dp->reg_base + EXYNOS_DP_SYS_CTL_2);
  104. writel(0x0, dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  105. writel(0x0, dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  106. writel(0x0, dp->reg_base + EXYNOS_DP_PKT_SEND_CTL);
  107. writel(0x0, dp->reg_base + EXYNOS_DP_HDCP_CTL);
  108. writel(0x5e, dp->reg_base + EXYNOS_DP_HPD_DEGLITCH_L);
  109. writel(0x1a, dp->reg_base + EXYNOS_DP_HPD_DEGLITCH_H);
  110. writel(0x10, dp->reg_base + EXYNOS_DP_LINK_DEBUG_CTL);
  111. writel(0x0, dp->reg_base + EXYNOS_DP_PHY_TEST);
  112. writel(0x0, dp->reg_base + EXYNOS_DP_VIDEO_FIFO_THRD);
  113. writel(0x20, dp->reg_base + EXYNOS_DP_AUDIO_MARGIN);
  114. writel(0x4, dp->reg_base + EXYNOS_DP_M_VID_GEN_FILTER_TH);
  115. writel(0x2, dp->reg_base + EXYNOS_DP_M_AUD_GEN_FILTER_TH);
  116. writel(0x00000101, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  117. }
  118. void exynos_dp_swreset(struct exynos_dp_device *dp)
  119. {
  120. writel(RESET_DP_TX, dp->reg_base + EXYNOS_DP_TX_SW_RESET);
  121. }
  122. void exynos_dp_config_interrupt(struct exynos_dp_device *dp)
  123. {
  124. u32 reg;
  125. /* 0: mask, 1: unmask */
  126. reg = COMMON_INT_MASK_1;
  127. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_1);
  128. reg = COMMON_INT_MASK_2;
  129. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_2);
  130. reg = COMMON_INT_MASK_3;
  131. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_3);
  132. reg = COMMON_INT_MASK_4;
  133. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_MASK_4);
  134. reg = INT_STA_MASK;
  135. writel(reg, dp->reg_base + EXYNOS_DP_INT_STA_MASK);
  136. }
  137. enum pll_status exynos_dp_get_pll_lock_status(struct exynos_dp_device *dp)
  138. {
  139. u32 reg;
  140. reg = readl(dp->reg_base + EXYNOS_DP_DEBUG_CTL);
  141. if (reg & PLL_LOCK)
  142. return PLL_LOCKED;
  143. else
  144. return PLL_UNLOCKED;
  145. }
  146. void exynos_dp_set_pll_power_down(struct exynos_dp_device *dp, bool enable)
  147. {
  148. u32 reg;
  149. if (enable) {
  150. reg = readl(dp->reg_base + EXYNOS_DP_PLL_CTL);
  151. reg |= DP_PLL_PD;
  152. writel(reg, dp->reg_base + EXYNOS_DP_PLL_CTL);
  153. } else {
  154. reg = readl(dp->reg_base + EXYNOS_DP_PLL_CTL);
  155. reg &= ~DP_PLL_PD;
  156. writel(reg, dp->reg_base + EXYNOS_DP_PLL_CTL);
  157. }
  158. }
  159. void exynos_dp_set_analog_power_down(struct exynos_dp_device *dp,
  160. enum analog_power_block block,
  161. bool enable)
  162. {
  163. u32 reg;
  164. switch (block) {
  165. case AUX_BLOCK:
  166. if (enable) {
  167. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  168. reg |= AUX_PD;
  169. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  170. } else {
  171. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  172. reg &= ~AUX_PD;
  173. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  174. }
  175. break;
  176. case CH0_BLOCK:
  177. if (enable) {
  178. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  179. reg |= CH0_PD;
  180. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  181. } else {
  182. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  183. reg &= ~CH0_PD;
  184. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  185. }
  186. break;
  187. case CH1_BLOCK:
  188. if (enable) {
  189. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  190. reg |= CH1_PD;
  191. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  192. } else {
  193. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  194. reg &= ~CH1_PD;
  195. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  196. }
  197. break;
  198. case CH2_BLOCK:
  199. if (enable) {
  200. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  201. reg |= CH2_PD;
  202. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  203. } else {
  204. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  205. reg &= ~CH2_PD;
  206. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  207. }
  208. break;
  209. case CH3_BLOCK:
  210. if (enable) {
  211. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  212. reg |= CH3_PD;
  213. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  214. } else {
  215. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  216. reg &= ~CH3_PD;
  217. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  218. }
  219. break;
  220. case ANALOG_TOTAL:
  221. if (enable) {
  222. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  223. reg |= DP_PHY_PD;
  224. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  225. } else {
  226. reg = readl(dp->reg_base + EXYNOS_DP_PHY_PD);
  227. reg &= ~DP_PHY_PD;
  228. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  229. }
  230. break;
  231. case POWER_ALL:
  232. if (enable) {
  233. reg = DP_PHY_PD | AUX_PD | CH3_PD | CH2_PD |
  234. CH1_PD | CH0_PD;
  235. writel(reg, dp->reg_base + EXYNOS_DP_PHY_PD);
  236. } else {
  237. writel(0x00, dp->reg_base + EXYNOS_DP_PHY_PD);
  238. }
  239. break;
  240. default:
  241. break;
  242. }
  243. }
  244. void exynos_dp_init_analog_func(struct exynos_dp_device *dp)
  245. {
  246. u32 reg;
  247. int timeout_loop = 0;
  248. exynos_dp_set_analog_power_down(dp, POWER_ALL, 0);
  249. reg = PLL_LOCK_CHG;
  250. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_1);
  251. reg = readl(dp->reg_base + EXYNOS_DP_DEBUG_CTL);
  252. reg &= ~(F_PLL_LOCK | PLL_LOCK_CTRL);
  253. writel(reg, dp->reg_base + EXYNOS_DP_DEBUG_CTL);
  254. /* Power up PLL */
  255. if (exynos_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) {
  256. exynos_dp_set_pll_power_down(dp, 0);
  257. while (exynos_dp_get_pll_lock_status(dp) == PLL_UNLOCKED) {
  258. timeout_loop++;
  259. if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
  260. dev_err(dp->dev, "failed to get pll lock status\n");
  261. return;
  262. }
  263. usleep_range(10, 20);
  264. }
  265. }
  266. /* Enable Serdes FIFO function and Link symbol clock domain module */
  267. reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  268. reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
  269. | AUX_FUNC_EN_N);
  270. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  271. }
  272. void exynos_dp_clear_hotplug_interrupts(struct exynos_dp_device *dp)
  273. {
  274. u32 reg;
  275. if (gpio_is_valid(dp->hpd_gpio))
  276. return;
  277. reg = HOTPLUG_CHG | HPD_LOST | PLUG;
  278. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_4);
  279. reg = INT_HPD;
  280. writel(reg, dp->reg_base + EXYNOS_DP_INT_STA);
  281. }
  282. void exynos_dp_init_hpd(struct exynos_dp_device *dp)
  283. {
  284. u32 reg;
  285. if (gpio_is_valid(dp->hpd_gpio))
  286. return;
  287. exynos_dp_clear_hotplug_interrupts(dp);
  288. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  289. reg &= ~(F_HPD | HPD_CTRL);
  290. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  291. }
  292. enum dp_irq_type exynos_dp_get_irq_type(struct exynos_dp_device *dp)
  293. {
  294. u32 reg;
  295. if (gpio_is_valid(dp->hpd_gpio)) {
  296. reg = gpio_get_value(dp->hpd_gpio);
  297. if (reg)
  298. return DP_IRQ_TYPE_HP_CABLE_IN;
  299. else
  300. return DP_IRQ_TYPE_HP_CABLE_OUT;
  301. } else {
  302. /* Parse hotplug interrupt status register */
  303. reg = readl(dp->reg_base + EXYNOS_DP_COMMON_INT_STA_4);
  304. if (reg & PLUG)
  305. return DP_IRQ_TYPE_HP_CABLE_IN;
  306. if (reg & HPD_LOST)
  307. return DP_IRQ_TYPE_HP_CABLE_OUT;
  308. if (reg & HOTPLUG_CHG)
  309. return DP_IRQ_TYPE_HP_CHANGE;
  310. return DP_IRQ_TYPE_UNKNOWN;
  311. }
  312. }
  313. void exynos_dp_reset_aux(struct exynos_dp_device *dp)
  314. {
  315. u32 reg;
  316. /* Disable AUX channel module */
  317. reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  318. reg |= AUX_FUNC_EN_N;
  319. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  320. }
  321. void exynos_dp_init_aux(struct exynos_dp_device *dp)
  322. {
  323. u32 reg;
  324. /* Clear inerrupts related to AUX channel */
  325. reg = RPLY_RECEIV | AUX_ERR;
  326. writel(reg, dp->reg_base + EXYNOS_DP_INT_STA);
  327. exynos_dp_reset_aux(dp);
  328. /* Disable AUX transaction H/W retry */
  329. reg = AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(0)|
  330. AUX_HW_RETRY_INTERVAL_600_MICROSECONDS;
  331. writel(reg, dp->reg_base + EXYNOS_DP_AUX_HW_RETRY_CTL);
  332. /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
  333. reg = DEFER_CTRL_EN | DEFER_COUNT(1);
  334. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_DEFER_CTL);
  335. /* Enable AUX channel module */
  336. reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  337. reg &= ~AUX_FUNC_EN_N;
  338. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_2);
  339. }
  340. int exynos_dp_get_plug_in_status(struct exynos_dp_device *dp)
  341. {
  342. u32 reg;
  343. if (gpio_is_valid(dp->hpd_gpio)) {
  344. if (gpio_get_value(dp->hpd_gpio))
  345. return 0;
  346. } else {
  347. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  348. if (reg & HPD_STATUS)
  349. return 0;
  350. }
  351. return -EINVAL;
  352. }
  353. void exynos_dp_enable_sw_function(struct exynos_dp_device *dp)
  354. {
  355. u32 reg;
  356. reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_1);
  357. reg &= ~SW_FUNC_EN_N;
  358. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_1);
  359. }
  360. int exynos_dp_start_aux_transaction(struct exynos_dp_device *dp)
  361. {
  362. int reg;
  363. int retval = 0;
  364. int timeout_loop = 0;
  365. /* Enable AUX CH operation */
  366. reg = readl(dp->reg_base + EXYNOS_DP_AUX_CH_CTL_2);
  367. reg |= AUX_EN;
  368. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_2);
  369. /* Is AUX CH command reply received? */
  370. reg = readl(dp->reg_base + EXYNOS_DP_INT_STA);
  371. while (!(reg & RPLY_RECEIV)) {
  372. timeout_loop++;
  373. if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
  374. dev_err(dp->dev, "AUX CH command reply failed!\n");
  375. return -ETIMEDOUT;
  376. }
  377. reg = readl(dp->reg_base + EXYNOS_DP_INT_STA);
  378. usleep_range(10, 11);
  379. }
  380. /* Clear interrupt source for AUX CH command reply */
  381. writel(RPLY_RECEIV, dp->reg_base + EXYNOS_DP_INT_STA);
  382. /* Clear interrupt source for AUX CH access error */
  383. reg = readl(dp->reg_base + EXYNOS_DP_INT_STA);
  384. if (reg & AUX_ERR) {
  385. writel(AUX_ERR, dp->reg_base + EXYNOS_DP_INT_STA);
  386. return -EREMOTEIO;
  387. }
  388. /* Check AUX CH error access status */
  389. reg = readl(dp->reg_base + EXYNOS_DP_AUX_CH_STA);
  390. if ((reg & AUX_STATUS_MASK) != 0) {
  391. dev_err(dp->dev, "AUX CH error happens: %d\n\n",
  392. reg & AUX_STATUS_MASK);
  393. return -EREMOTEIO;
  394. }
  395. return retval;
  396. }
  397. int exynos_dp_write_byte_to_dpcd(struct exynos_dp_device *dp,
  398. unsigned int reg_addr,
  399. unsigned char data)
  400. {
  401. u32 reg;
  402. int i;
  403. int retval;
  404. for (i = 0; i < 3; i++) {
  405. /* Clear AUX CH data buffer */
  406. reg = BUF_CLR;
  407. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  408. /* Select DPCD device address */
  409. reg = AUX_ADDR_7_0(reg_addr);
  410. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_7_0);
  411. reg = AUX_ADDR_15_8(reg_addr);
  412. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_15_8);
  413. reg = AUX_ADDR_19_16(reg_addr);
  414. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_19_16);
  415. /* Write data buffer */
  416. reg = (unsigned int)data;
  417. writel(reg, dp->reg_base + EXYNOS_DP_BUF_DATA_0);
  418. /*
  419. * Set DisplayPort transaction and write 1 byte
  420. * If bit 3 is 1, DisplayPort transaction.
  421. * If Bit 3 is 0, I2C transaction.
  422. */
  423. reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
  424. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  425. /* Start AUX transaction */
  426. retval = exynos_dp_start_aux_transaction(dp);
  427. if (retval == 0)
  428. break;
  429. else
  430. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n",
  431. __func__);
  432. }
  433. return retval;
  434. }
  435. int exynos_dp_read_byte_from_dpcd(struct exynos_dp_device *dp,
  436. unsigned int reg_addr,
  437. unsigned char *data)
  438. {
  439. u32 reg;
  440. int i;
  441. int retval;
  442. for (i = 0; i < 3; i++) {
  443. /* Clear AUX CH data buffer */
  444. reg = BUF_CLR;
  445. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  446. /* Select DPCD device address */
  447. reg = AUX_ADDR_7_0(reg_addr);
  448. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_7_0);
  449. reg = AUX_ADDR_15_8(reg_addr);
  450. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_15_8);
  451. reg = AUX_ADDR_19_16(reg_addr);
  452. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_19_16);
  453. /*
  454. * Set DisplayPort transaction and read 1 byte
  455. * If bit 3 is 1, DisplayPort transaction.
  456. * If Bit 3 is 0, I2C transaction.
  457. */
  458. reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
  459. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  460. /* Start AUX transaction */
  461. retval = exynos_dp_start_aux_transaction(dp);
  462. if (retval == 0)
  463. break;
  464. else
  465. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n",
  466. __func__);
  467. }
  468. /* Read data buffer */
  469. reg = readl(dp->reg_base + EXYNOS_DP_BUF_DATA_0);
  470. *data = (unsigned char)(reg & 0xff);
  471. return retval;
  472. }
  473. int exynos_dp_write_bytes_to_dpcd(struct exynos_dp_device *dp,
  474. unsigned int reg_addr,
  475. unsigned int count,
  476. unsigned char data[])
  477. {
  478. u32 reg;
  479. unsigned int start_offset;
  480. unsigned int cur_data_count;
  481. unsigned int cur_data_idx;
  482. int i;
  483. int retval = 0;
  484. /* Clear AUX CH data buffer */
  485. reg = BUF_CLR;
  486. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  487. start_offset = 0;
  488. while (start_offset < count) {
  489. /* Buffer size of AUX CH is 16 * 4bytes */
  490. if ((count - start_offset) > 16)
  491. cur_data_count = 16;
  492. else
  493. cur_data_count = count - start_offset;
  494. for (i = 0; i < 3; i++) {
  495. /* Select DPCD device address */
  496. reg = AUX_ADDR_7_0(reg_addr + start_offset);
  497. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_7_0);
  498. reg = AUX_ADDR_15_8(reg_addr + start_offset);
  499. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_15_8);
  500. reg = AUX_ADDR_19_16(reg_addr + start_offset);
  501. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_19_16);
  502. for (cur_data_idx = 0; cur_data_idx < cur_data_count;
  503. cur_data_idx++) {
  504. reg = data[start_offset + cur_data_idx];
  505. writel(reg, dp->reg_base + EXYNOS_DP_BUF_DATA_0
  506. + 4 * cur_data_idx);
  507. }
  508. /*
  509. * Set DisplayPort transaction and write
  510. * If bit 3 is 1, DisplayPort transaction.
  511. * If Bit 3 is 0, I2C transaction.
  512. */
  513. reg = AUX_LENGTH(cur_data_count) |
  514. AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
  515. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  516. /* Start AUX transaction */
  517. retval = exynos_dp_start_aux_transaction(dp);
  518. if (retval == 0)
  519. break;
  520. else
  521. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n",
  522. __func__);
  523. }
  524. start_offset += cur_data_count;
  525. }
  526. return retval;
  527. }
  528. int exynos_dp_read_bytes_from_dpcd(struct exynos_dp_device *dp,
  529. unsigned int reg_addr,
  530. unsigned int count,
  531. unsigned char data[])
  532. {
  533. u32 reg;
  534. unsigned int start_offset;
  535. unsigned int cur_data_count;
  536. unsigned int cur_data_idx;
  537. int i;
  538. int retval = 0;
  539. /* Clear AUX CH data buffer */
  540. reg = BUF_CLR;
  541. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  542. start_offset = 0;
  543. while (start_offset < count) {
  544. /* Buffer size of AUX CH is 16 * 4bytes */
  545. if ((count - start_offset) > 16)
  546. cur_data_count = 16;
  547. else
  548. cur_data_count = count - start_offset;
  549. /* AUX CH Request Transaction process */
  550. for (i = 0; i < 3; i++) {
  551. /* Select DPCD device address */
  552. reg = AUX_ADDR_7_0(reg_addr + start_offset);
  553. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_7_0);
  554. reg = AUX_ADDR_15_8(reg_addr + start_offset);
  555. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_15_8);
  556. reg = AUX_ADDR_19_16(reg_addr + start_offset);
  557. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_19_16);
  558. /*
  559. * Set DisplayPort transaction and read
  560. * If bit 3 is 1, DisplayPort transaction.
  561. * If Bit 3 is 0, I2C transaction.
  562. */
  563. reg = AUX_LENGTH(cur_data_count) |
  564. AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
  565. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  566. /* Start AUX transaction */
  567. retval = exynos_dp_start_aux_transaction(dp);
  568. if (retval == 0)
  569. break;
  570. else
  571. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n",
  572. __func__);
  573. }
  574. for (cur_data_idx = 0; cur_data_idx < cur_data_count;
  575. cur_data_idx++) {
  576. reg = readl(dp->reg_base + EXYNOS_DP_BUF_DATA_0
  577. + 4 * cur_data_idx);
  578. data[start_offset + cur_data_idx] =
  579. (unsigned char)reg;
  580. }
  581. start_offset += cur_data_count;
  582. }
  583. return retval;
  584. }
  585. int exynos_dp_select_i2c_device(struct exynos_dp_device *dp,
  586. unsigned int device_addr,
  587. unsigned int reg_addr)
  588. {
  589. u32 reg;
  590. int retval;
  591. /* Set EDID device address */
  592. reg = device_addr;
  593. writel(reg, dp->reg_base + EXYNOS_DP_AUX_ADDR_7_0);
  594. writel(0x0, dp->reg_base + EXYNOS_DP_AUX_ADDR_15_8);
  595. writel(0x0, dp->reg_base + EXYNOS_DP_AUX_ADDR_19_16);
  596. /* Set offset from base address of EDID device */
  597. writel(reg_addr, dp->reg_base + EXYNOS_DP_BUF_DATA_0);
  598. /*
  599. * Set I2C transaction and write address
  600. * If bit 3 is 1, DisplayPort transaction.
  601. * If Bit 3 is 0, I2C transaction.
  602. */
  603. reg = AUX_TX_COMM_I2C_TRANSACTION | AUX_TX_COMM_MOT |
  604. AUX_TX_COMM_WRITE;
  605. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  606. /* Start AUX transaction */
  607. retval = exynos_dp_start_aux_transaction(dp);
  608. if (retval != 0)
  609. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n", __func__);
  610. return retval;
  611. }
  612. int exynos_dp_read_byte_from_i2c(struct exynos_dp_device *dp,
  613. unsigned int device_addr,
  614. unsigned int reg_addr,
  615. unsigned int *data)
  616. {
  617. u32 reg;
  618. int i;
  619. int retval;
  620. for (i = 0; i < 3; i++) {
  621. /* Clear AUX CH data buffer */
  622. reg = BUF_CLR;
  623. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  624. /* Select EDID device */
  625. retval = exynos_dp_select_i2c_device(dp, device_addr, reg_addr);
  626. if (retval != 0)
  627. continue;
  628. /*
  629. * Set I2C transaction and read data
  630. * If bit 3 is 1, DisplayPort transaction.
  631. * If Bit 3 is 0, I2C transaction.
  632. */
  633. reg = AUX_TX_COMM_I2C_TRANSACTION |
  634. AUX_TX_COMM_READ;
  635. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_1);
  636. /* Start AUX transaction */
  637. retval = exynos_dp_start_aux_transaction(dp);
  638. if (retval == 0)
  639. break;
  640. else
  641. dev_dbg(dp->dev, "%s: Aux Transaction fail!\n",
  642. __func__);
  643. }
  644. /* Read data */
  645. if (retval == 0)
  646. *data = readl(dp->reg_base + EXYNOS_DP_BUF_DATA_0);
  647. return retval;
  648. }
  649. int exynos_dp_read_bytes_from_i2c(struct exynos_dp_device *dp,
  650. unsigned int device_addr,
  651. unsigned int reg_addr,
  652. unsigned int count,
  653. unsigned char edid[])
  654. {
  655. u32 reg;
  656. unsigned int i, j;
  657. unsigned int cur_data_idx;
  658. unsigned int defer = 0;
  659. int retval = 0;
  660. for (i = 0; i < count; i += 16) {
  661. for (j = 0; j < 3; j++) {
  662. /* Clear AUX CH data buffer */
  663. reg = BUF_CLR;
  664. writel(reg, dp->reg_base + EXYNOS_DP_BUFFER_DATA_CTL);
  665. /* Set normal AUX CH command */
  666. reg = readl(dp->reg_base + EXYNOS_DP_AUX_CH_CTL_2);
  667. reg &= ~ADDR_ONLY;
  668. writel(reg, dp->reg_base + EXYNOS_DP_AUX_CH_CTL_2);
  669. /*
  670. * If Rx sends defer, Tx sends only reads
  671. * request without sending address
  672. */
  673. if (!defer)
  674. retval = exynos_dp_select_i2c_device(dp,
  675. device_addr, reg_addr + i);
  676. else
  677. defer = 0;
  678. if (retval == 0) {
  679. /*
  680. * Set I2C transaction and write data
  681. * If bit 3 is 1, DisplayPort transaction.
  682. * If Bit 3 is 0, I2C transaction.
  683. */
  684. reg = AUX_LENGTH(16) |
  685. AUX_TX_COMM_I2C_TRANSACTION |
  686. AUX_TX_COMM_READ;
  687. writel(reg, dp->reg_base +
  688. EXYNOS_DP_AUX_CH_CTL_1);
  689. /* Start AUX transaction */
  690. retval = exynos_dp_start_aux_transaction(dp);
  691. if (retval == 0)
  692. break;
  693. else
  694. dev_dbg(dp->dev,
  695. "%s: Aux Transaction fail!\n",
  696. __func__);
  697. }
  698. /* Check if Rx sends defer */
  699. reg = readl(dp->reg_base + EXYNOS_DP_AUX_RX_COMM);
  700. if (reg == AUX_RX_COMM_AUX_DEFER ||
  701. reg == AUX_RX_COMM_I2C_DEFER) {
  702. dev_err(dp->dev, "Defer: %d\n\n", reg);
  703. defer = 1;
  704. }
  705. }
  706. for (cur_data_idx = 0; cur_data_idx < 16; cur_data_idx++) {
  707. reg = readl(dp->reg_base + EXYNOS_DP_BUF_DATA_0
  708. + 4 * cur_data_idx);
  709. edid[i + cur_data_idx] = (unsigned char)reg;
  710. }
  711. }
  712. return retval;
  713. }
  714. void exynos_dp_set_link_bandwidth(struct exynos_dp_device *dp, u32 bwtype)
  715. {
  716. u32 reg;
  717. reg = bwtype;
  718. if ((bwtype == LINK_RATE_2_70GBPS) || (bwtype == LINK_RATE_1_62GBPS))
  719. writel(reg, dp->reg_base + EXYNOS_DP_LINK_BW_SET);
  720. }
  721. void exynos_dp_get_link_bandwidth(struct exynos_dp_device *dp, u32 *bwtype)
  722. {
  723. u32 reg;
  724. reg = readl(dp->reg_base + EXYNOS_DP_LINK_BW_SET);
  725. *bwtype = reg;
  726. }
  727. void exynos_dp_set_lane_count(struct exynos_dp_device *dp, u32 count)
  728. {
  729. u32 reg;
  730. reg = count;
  731. writel(reg, dp->reg_base + EXYNOS_DP_LANE_COUNT_SET);
  732. }
  733. void exynos_dp_get_lane_count(struct exynos_dp_device *dp, u32 *count)
  734. {
  735. u32 reg;
  736. reg = readl(dp->reg_base + EXYNOS_DP_LANE_COUNT_SET);
  737. *count = reg;
  738. }
  739. void exynos_dp_enable_enhanced_mode(struct exynos_dp_device *dp, bool enable)
  740. {
  741. u32 reg;
  742. if (enable) {
  743. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  744. reg |= ENHANCED;
  745. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  746. } else {
  747. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  748. reg &= ~ENHANCED;
  749. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  750. }
  751. }
  752. void exynos_dp_set_training_pattern(struct exynos_dp_device *dp,
  753. enum pattern_set pattern)
  754. {
  755. u32 reg;
  756. switch (pattern) {
  757. case PRBS7:
  758. reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_PRBS7;
  759. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  760. break;
  761. case D10_2:
  762. reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_D10_2;
  763. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  764. break;
  765. case TRAINING_PTN1:
  766. reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN1;
  767. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  768. break;
  769. case TRAINING_PTN2:
  770. reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN2;
  771. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  772. break;
  773. case DP_NONE:
  774. reg = SCRAMBLING_ENABLE |
  775. LINK_QUAL_PATTERN_SET_DISABLE |
  776. SW_TRAINING_PATTERN_SET_NORMAL;
  777. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  778. break;
  779. default:
  780. break;
  781. }
  782. }
  783. void exynos_dp_set_lane0_pre_emphasis(struct exynos_dp_device *dp, u32 level)
  784. {
  785. u32 reg;
  786. reg = readl(dp->reg_base + EXYNOS_DP_LN0_LINK_TRAINING_CTL);
  787. reg &= ~PRE_EMPHASIS_SET_MASK;
  788. reg |= level << PRE_EMPHASIS_SET_SHIFT;
  789. writel(reg, dp->reg_base + EXYNOS_DP_LN0_LINK_TRAINING_CTL);
  790. }
  791. void exynos_dp_set_lane1_pre_emphasis(struct exynos_dp_device *dp, u32 level)
  792. {
  793. u32 reg;
  794. reg = readl(dp->reg_base + EXYNOS_DP_LN1_LINK_TRAINING_CTL);
  795. reg &= ~PRE_EMPHASIS_SET_MASK;
  796. reg |= level << PRE_EMPHASIS_SET_SHIFT;
  797. writel(reg, dp->reg_base + EXYNOS_DP_LN1_LINK_TRAINING_CTL);
  798. }
  799. void exynos_dp_set_lane2_pre_emphasis(struct exynos_dp_device *dp, u32 level)
  800. {
  801. u32 reg;
  802. reg = readl(dp->reg_base + EXYNOS_DP_LN2_LINK_TRAINING_CTL);
  803. reg &= ~PRE_EMPHASIS_SET_MASK;
  804. reg |= level << PRE_EMPHASIS_SET_SHIFT;
  805. writel(reg, dp->reg_base + EXYNOS_DP_LN2_LINK_TRAINING_CTL);
  806. }
  807. void exynos_dp_set_lane3_pre_emphasis(struct exynos_dp_device *dp, u32 level)
  808. {
  809. u32 reg;
  810. reg = readl(dp->reg_base + EXYNOS_DP_LN3_LINK_TRAINING_CTL);
  811. reg &= ~PRE_EMPHASIS_SET_MASK;
  812. reg |= level << PRE_EMPHASIS_SET_SHIFT;
  813. writel(reg, dp->reg_base + EXYNOS_DP_LN3_LINK_TRAINING_CTL);
  814. }
  815. void exynos_dp_set_lane0_link_training(struct exynos_dp_device *dp,
  816. u32 training_lane)
  817. {
  818. u32 reg;
  819. reg = training_lane;
  820. writel(reg, dp->reg_base + EXYNOS_DP_LN0_LINK_TRAINING_CTL);
  821. }
  822. void exynos_dp_set_lane1_link_training(struct exynos_dp_device *dp,
  823. u32 training_lane)
  824. {
  825. u32 reg;
  826. reg = training_lane;
  827. writel(reg, dp->reg_base + EXYNOS_DP_LN1_LINK_TRAINING_CTL);
  828. }
  829. void exynos_dp_set_lane2_link_training(struct exynos_dp_device *dp,
  830. u32 training_lane)
  831. {
  832. u32 reg;
  833. reg = training_lane;
  834. writel(reg, dp->reg_base + EXYNOS_DP_LN2_LINK_TRAINING_CTL);
  835. }
  836. void exynos_dp_set_lane3_link_training(struct exynos_dp_device *dp,
  837. u32 training_lane)
  838. {
  839. u32 reg;
  840. reg = training_lane;
  841. writel(reg, dp->reg_base + EXYNOS_DP_LN3_LINK_TRAINING_CTL);
  842. }
  843. u32 exynos_dp_get_lane0_link_training(struct exynos_dp_device *dp)
  844. {
  845. u32 reg;
  846. reg = readl(dp->reg_base + EXYNOS_DP_LN0_LINK_TRAINING_CTL);
  847. return reg;
  848. }
  849. u32 exynos_dp_get_lane1_link_training(struct exynos_dp_device *dp)
  850. {
  851. u32 reg;
  852. reg = readl(dp->reg_base + EXYNOS_DP_LN1_LINK_TRAINING_CTL);
  853. return reg;
  854. }
  855. u32 exynos_dp_get_lane2_link_training(struct exynos_dp_device *dp)
  856. {
  857. u32 reg;
  858. reg = readl(dp->reg_base + EXYNOS_DP_LN2_LINK_TRAINING_CTL);
  859. return reg;
  860. }
  861. u32 exynos_dp_get_lane3_link_training(struct exynos_dp_device *dp)
  862. {
  863. u32 reg;
  864. reg = readl(dp->reg_base + EXYNOS_DP_LN3_LINK_TRAINING_CTL);
  865. return reg;
  866. }
  867. void exynos_dp_reset_macro(struct exynos_dp_device *dp)
  868. {
  869. u32 reg;
  870. reg = readl(dp->reg_base + EXYNOS_DP_PHY_TEST);
  871. reg |= MACRO_RST;
  872. writel(reg, dp->reg_base + EXYNOS_DP_PHY_TEST);
  873. /* 10 us is the minimum reset time. */
  874. usleep_range(10, 20);
  875. reg &= ~MACRO_RST;
  876. writel(reg, dp->reg_base + EXYNOS_DP_PHY_TEST);
  877. }
  878. void exynos_dp_init_video(struct exynos_dp_device *dp)
  879. {
  880. u32 reg;
  881. reg = VSYNC_DET | VID_FORMAT_CHG | VID_CLK_CHG;
  882. writel(reg, dp->reg_base + EXYNOS_DP_COMMON_INT_STA_1);
  883. reg = 0x0;
  884. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_1);
  885. reg = CHA_CRI(4) | CHA_CTRL;
  886. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_2);
  887. reg = 0x0;
  888. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  889. reg = VID_HRES_TH(2) | VID_VRES_TH(0);
  890. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_8);
  891. }
  892. void exynos_dp_set_video_color_format(struct exynos_dp_device *dp)
  893. {
  894. u32 reg;
  895. /* Configure the input color depth, color space, dynamic range */
  896. reg = (dp->video_info->dynamic_range << IN_D_RANGE_SHIFT) |
  897. (dp->video_info->color_depth << IN_BPC_SHIFT) |
  898. (dp->video_info->color_space << IN_COLOR_F_SHIFT);
  899. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_2);
  900. /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
  901. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_3);
  902. reg &= ~IN_YC_COEFFI_MASK;
  903. if (dp->video_info->ycbcr_coeff)
  904. reg |= IN_YC_COEFFI_ITU709;
  905. else
  906. reg |= IN_YC_COEFFI_ITU601;
  907. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_3);
  908. }
  909. int exynos_dp_is_slave_video_stream_clock_on(struct exynos_dp_device *dp)
  910. {
  911. u32 reg;
  912. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_1);
  913. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_1);
  914. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_1);
  915. if (!(reg & DET_STA)) {
  916. dev_dbg(dp->dev, "Input stream clock not detected.\n");
  917. return -EINVAL;
  918. }
  919. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_2);
  920. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_2);
  921. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_2);
  922. dev_dbg(dp->dev, "wait SYS_CTL_2.\n");
  923. if (reg & CHA_STA) {
  924. dev_dbg(dp->dev, "Input stream clk is changing\n");
  925. return -EINVAL;
  926. }
  927. return 0;
  928. }
  929. void exynos_dp_set_video_cr_mn(struct exynos_dp_device *dp,
  930. enum clock_recovery_m_value_type type,
  931. u32 m_value,
  932. u32 n_value)
  933. {
  934. u32 reg;
  935. if (type == REGISTER_M) {
  936. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  937. reg |= FIX_M_VID;
  938. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  939. reg = m_value & 0xff;
  940. writel(reg, dp->reg_base + EXYNOS_DP_M_VID_0);
  941. reg = (m_value >> 8) & 0xff;
  942. writel(reg, dp->reg_base + EXYNOS_DP_M_VID_1);
  943. reg = (m_value >> 16) & 0xff;
  944. writel(reg, dp->reg_base + EXYNOS_DP_M_VID_2);
  945. reg = n_value & 0xff;
  946. writel(reg, dp->reg_base + EXYNOS_DP_N_VID_0);
  947. reg = (n_value >> 8) & 0xff;
  948. writel(reg, dp->reg_base + EXYNOS_DP_N_VID_1);
  949. reg = (n_value >> 16) & 0xff;
  950. writel(reg, dp->reg_base + EXYNOS_DP_N_VID_2);
  951. } else {
  952. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  953. reg &= ~FIX_M_VID;
  954. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_4);
  955. writel(0x00, dp->reg_base + EXYNOS_DP_N_VID_0);
  956. writel(0x80, dp->reg_base + EXYNOS_DP_N_VID_1);
  957. writel(0x00, dp->reg_base + EXYNOS_DP_N_VID_2);
  958. }
  959. }
  960. void exynos_dp_set_video_timing_mode(struct exynos_dp_device *dp, u32 type)
  961. {
  962. u32 reg;
  963. if (type == VIDEO_TIMING_FROM_CAPTURE) {
  964. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  965. reg &= ~FORMAT_SEL;
  966. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  967. } else {
  968. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  969. reg |= FORMAT_SEL;
  970. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  971. }
  972. }
  973. void exynos_dp_enable_video_master(struct exynos_dp_device *dp, bool enable)
  974. {
  975. u32 reg;
  976. if (enable) {
  977. reg = readl(dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  978. reg &= ~VIDEO_MODE_MASK;
  979. reg |= VIDEO_MASTER_MODE_EN | VIDEO_MODE_MASTER_MODE;
  980. writel(reg, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  981. } else {
  982. reg = readl(dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  983. reg &= ~VIDEO_MODE_MASK;
  984. reg |= VIDEO_MODE_SLAVE_MODE;
  985. writel(reg, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  986. }
  987. }
  988. void exynos_dp_start_video(struct exynos_dp_device *dp)
  989. {
  990. u32 reg;
  991. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  992. reg |= VIDEO_EN;
  993. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_1);
  994. }
  995. int exynos_dp_is_video_stream_on(struct exynos_dp_device *dp)
  996. {
  997. u32 reg;
  998. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  999. writel(reg, dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  1000. reg = readl(dp->reg_base + EXYNOS_DP_SYS_CTL_3);
  1001. if (!(reg & STRM_VALID)) {
  1002. dev_dbg(dp->dev, "Input video stream is not detected.\n");
  1003. return -EINVAL;
  1004. }
  1005. return 0;
  1006. }
  1007. void exynos_dp_config_video_slave_mode(struct exynos_dp_device *dp)
  1008. {
  1009. u32 reg;
  1010. reg = readl(dp->reg_base + EXYNOS_DP_FUNC_EN_1);
  1011. reg &= ~(MASTER_VID_FUNC_EN_N|SLAVE_VID_FUNC_EN_N);
  1012. reg |= MASTER_VID_FUNC_EN_N;
  1013. writel(reg, dp->reg_base + EXYNOS_DP_FUNC_EN_1);
  1014. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1015. reg &= ~INTERACE_SCAN_CFG;
  1016. reg |= (dp->video_info->interlaced << 2);
  1017. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1018. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1019. reg &= ~VSYNC_POLARITY_CFG;
  1020. reg |= (dp->video_info->v_sync_polarity << 1);
  1021. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1022. reg = readl(dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1023. reg &= ~HSYNC_POLARITY_CFG;
  1024. reg |= (dp->video_info->h_sync_polarity << 0);
  1025. writel(reg, dp->reg_base + EXYNOS_DP_VIDEO_CTL_10);
  1026. reg = AUDIO_MODE_SPDIF_MODE | VIDEO_MODE_SLAVE_MODE;
  1027. writel(reg, dp->reg_base + EXYNOS_DP_SOC_GENERAL_CTL);
  1028. }
  1029. void exynos_dp_enable_scrambling(struct exynos_dp_device *dp)
  1030. {
  1031. u32 reg;
  1032. reg = readl(dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  1033. reg &= ~SCRAMBLING_DISABLE;
  1034. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  1035. }
  1036. void exynos_dp_disable_scrambling(struct exynos_dp_device *dp)
  1037. {
  1038. u32 reg;
  1039. reg = readl(dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  1040. reg |= SCRAMBLING_DISABLE;
  1041. writel(reg, dp->reg_base + EXYNOS_DP_TRAINING_PTN_SET);
  1042. }