hdmi.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. /*
  2. * hdmi.c
  3. *
  4. * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  6. * Authors: Yong Zhi
  7. * Mythri pk <mythripk@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define DSS_SUBSYS_NAME "HDMI"
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/io.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/mutex.h>
  28. #include <linux/delay.h>
  29. #include <linux/string.h>
  30. #include <plat/display.h>
  31. #include "dss.h"
  32. #include "hdmi.h"
  33. static struct {
  34. struct mutex lock;
  35. struct omap_display_platform_data *pdata;
  36. struct platform_device *pdev;
  37. void __iomem *base_wp; /* HDMI wrapper */
  38. int code;
  39. int mode;
  40. u8 edid[HDMI_EDID_MAX_LENGTH];
  41. u8 edid_set;
  42. bool custom_set;
  43. struct hdmi_config cfg;
  44. } hdmi;
  45. /*
  46. * Logic for the below structure :
  47. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  48. * There is a correspondence between CEA/VESA timing and code, please
  49. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  50. *
  51. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  52. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  53. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  54. * with code_vesa. Code_index is used for back mapping, that is once EDID
  55. * is read from the TV, EDID is parsed to find the timing values and then
  56. * map it to corresponding CEA or VESA index.
  57. */
  58. static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
  59. { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
  60. { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
  61. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
  62. { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
  63. { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
  64. { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
  65. { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
  66. { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
  67. { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
  68. { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
  69. { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
  70. { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
  71. { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
  72. { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
  73. { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
  74. /* VESA From Here */
  75. { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
  76. { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
  77. { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
  78. { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
  79. { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
  80. { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
  81. { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
  82. { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
  83. { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
  84. { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
  85. { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
  86. { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
  87. { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
  88. { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
  89. { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
  90. { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
  91. { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
  92. { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
  93. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
  94. };
  95. /*
  96. * This is a static mapping array which maps the timing values
  97. * with corresponding CEA / VESA code
  98. */
  99. static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
  100. 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
  101. /* <--15 CEA 17--> vesa*/
  102. 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
  103. 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
  104. };
  105. /*
  106. * This is reverse static mapping which maps the CEA / VESA code
  107. * to the corresponding timing values
  108. */
  109. static const int code_cea[39] = {
  110. -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
  111. -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
  112. 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
  113. 11, 12, 14, -1, -1, 13, 13, 4, 4
  114. };
  115. static const int code_vesa[85] = {
  116. -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
  117. -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
  118. -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
  119. -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
  120. -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
  121. -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
  122. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  123. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  124. -1, 27, 28, -1, 33};
  125. static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
  126. static inline void hdmi_write_reg(const struct hdmi_reg idx, u32 val)
  127. {
  128. __raw_writel(val, hdmi.base_wp + idx.idx);
  129. }
  130. static inline u32 hdmi_read_reg(const struct hdmi_reg idx)
  131. {
  132. return __raw_readl(hdmi.base_wp + idx.idx);
  133. }
  134. static inline int hdmi_wait_for_bit_change(const struct hdmi_reg idx,
  135. int b2, int b1, u32 val)
  136. {
  137. u32 t = 0;
  138. while (val != REG_GET(idx, b2, b1)) {
  139. udelay(1);
  140. if (t++ > 10000)
  141. return !val;
  142. }
  143. return val;
  144. }
  145. int hdmi_init_display(struct omap_dss_device *dssdev)
  146. {
  147. DSSDBG("init_display\n");
  148. return 0;
  149. }
  150. static int hdmi_pll_init(enum hdmi_clk_refsel refsel, int dcofreq,
  151. struct hdmi_pll_info *fmt, u16 sd)
  152. {
  153. u32 r;
  154. /* PLL start always use manual mode */
  155. REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
  156. r = hdmi_read_reg(PLLCTRL_CFG1);
  157. r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
  158. r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */
  159. hdmi_write_reg(PLLCTRL_CFG1, r);
  160. r = hdmi_read_reg(PLLCTRL_CFG2);
  161. r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
  162. r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
  163. r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
  164. if (dcofreq) {
  165. /* divider programming for frequency beyond 1000Mhz */
  166. REG_FLD_MOD(PLLCTRL_CFG3, sd, 17, 10);
  167. r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
  168. } else {
  169. r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
  170. }
  171. hdmi_write_reg(PLLCTRL_CFG2, r);
  172. r = hdmi_read_reg(PLLCTRL_CFG4);
  173. r = FLD_MOD(r, fmt->regm2, 24, 18);
  174. r = FLD_MOD(r, fmt->regmf, 17, 0);
  175. hdmi_write_reg(PLLCTRL_CFG4, r);
  176. /* go now */
  177. REG_FLD_MOD(PLLCTRL_PLL_GO, 0x1, 0, 0);
  178. /* wait for bit change */
  179. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_GO, 0, 0, 1) != 1) {
  180. DSSERR("PLL GO bit not set\n");
  181. return -ETIMEDOUT;
  182. }
  183. /* Wait till the lock bit is set in PLL status */
  184. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
  185. DSSWARN("cannot lock PLL\n");
  186. DSSWARN("CFG1 0x%x\n",
  187. hdmi_read_reg(PLLCTRL_CFG1));
  188. DSSWARN("CFG2 0x%x\n",
  189. hdmi_read_reg(PLLCTRL_CFG2));
  190. DSSWARN("CFG4 0x%x\n",
  191. hdmi_read_reg(PLLCTRL_CFG4));
  192. return -ETIMEDOUT;
  193. }
  194. DSSDBG("PLL locked!\n");
  195. return 0;
  196. }
  197. /* PHY_PWR_CMD */
  198. static int hdmi_set_phy_pwr(enum hdmi_phy_pwr val)
  199. {
  200. /* Command for power control of HDMI PHY */
  201. REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 7, 6);
  202. /* Status of the power control of HDMI PHY */
  203. if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
  204. DSSERR("Failed to set PHY power mode to %d\n", val);
  205. return -ETIMEDOUT;
  206. }
  207. return 0;
  208. }
  209. /* PLL_PWR_CMD */
  210. static int hdmi_set_pll_pwr(enum hdmi_pll_pwr val)
  211. {
  212. /* Command for power control of HDMI PLL */
  213. REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 3, 2);
  214. /* wait till PHY_PWR_STATUS is set */
  215. if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 1, 0, val) != val) {
  216. DSSERR("Failed to set PHY_PWR_STATUS\n");
  217. return -ETIMEDOUT;
  218. }
  219. return 0;
  220. }
  221. static int hdmi_pll_reset(void)
  222. {
  223. /* SYSRESET controlled by power FSM */
  224. REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
  225. /* READ 0x0 reset is in progress */
  226. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
  227. DSSERR("Failed to sysreset PLL\n");
  228. return -ETIMEDOUT;
  229. }
  230. return 0;
  231. }
  232. static int hdmi_phy_init(void)
  233. {
  234. u16 r = 0;
  235. r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_LDOON);
  236. if (r)
  237. return r;
  238. r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_TXON);
  239. if (r)
  240. return r;
  241. /*
  242. * Read address 0 in order to get the SCP reset done completed
  243. * Dummy access performed to make sure reset is done
  244. */
  245. hdmi_read_reg(HDMI_TXPHY_TX_CTRL);
  246. /*
  247. * Write to phy address 0 to configure the clock
  248. * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
  249. */
  250. REG_FLD_MOD(HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
  251. /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
  252. hdmi_write_reg(HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
  253. /* Setup max LDO voltage */
  254. REG_FLD_MOD(HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
  255. /* Write to phy address 3 to change the polarity control */
  256. REG_FLD_MOD(HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
  257. return 0;
  258. }
  259. static int hdmi_wait_softreset(void)
  260. {
  261. /* reset W1 */
  262. REG_FLD_MOD(HDMI_WP_SYSCONFIG, 0x1, 0, 0);
  263. /* wait till SOFTRESET == 0 */
  264. if (hdmi_wait_for_bit_change(HDMI_WP_SYSCONFIG, 0, 0, 0) != 0) {
  265. DSSERR("sysconfig reset failed\n");
  266. return -ETIMEDOUT;
  267. }
  268. return 0;
  269. }
  270. static int hdmi_pll_program(struct hdmi_pll_info *fmt)
  271. {
  272. u16 r = 0;
  273. enum hdmi_clk_refsel refsel;
  274. /* wait for wrapper reset */
  275. r = hdmi_wait_softreset();
  276. if (r)
  277. return r;
  278. r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
  279. if (r)
  280. return r;
  281. r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
  282. if (r)
  283. return r;
  284. r = hdmi_pll_reset();
  285. if (r)
  286. return r;
  287. refsel = HDMI_REFSEL_SYSCLK;
  288. r = hdmi_pll_init(refsel, fmt->dcofreq, fmt, fmt->regsd);
  289. if (r)
  290. return r;
  291. return 0;
  292. }
  293. static void hdmi_phy_off(void)
  294. {
  295. hdmi_set_phy_pwr(HDMI_PHYPWRCMD_OFF);
  296. }
  297. static int hdmi_core_ddc_edid(u8 *pedid, int ext)
  298. {
  299. u32 i, j;
  300. char checksum = 0;
  301. u32 offset = 0;
  302. /* Turn on CLK for DDC */
  303. REG_FLD_MOD(HDMI_CORE_AV_DPD, 0x7, 2, 0);
  304. /*
  305. * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
  306. * right shifted values( The behavior is not consistent and seen only
  307. * with some TV's)
  308. */
  309. usleep_range(800, 1000);
  310. if (!ext) {
  311. /* Clk SCL Devices */
  312. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  313. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  314. if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
  315. 4, 4, 0) != 0) {
  316. DSSERR("Failed to program DDC\n");
  317. return -ETIMEDOUT;
  318. }
  319. /* Clear FIFO */
  320. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  321. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  322. if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
  323. 4, 4, 0) != 0) {
  324. DSSERR("Failed to program DDC\n");
  325. return -ETIMEDOUT;
  326. }
  327. } else {
  328. if (ext % 2 != 0)
  329. offset = 0x80;
  330. }
  331. /* Load Segment Address Register */
  332. REG_FLD_MOD(HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
  333. /* Load Slave Address Register */
  334. REG_FLD_MOD(HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  335. /* Load Offset Address Register */
  336. REG_FLD_MOD(HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  337. /* Load Byte Count */
  338. REG_FLD_MOD(HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  339. REG_FLD_MOD(HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  340. /* Set DDC_CMD */
  341. if (ext)
  342. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  343. else
  344. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  345. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  346. if (REG_GET(HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  347. DSSWARN("I2C Bus Low?\n");
  348. return -EIO;
  349. }
  350. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  351. if (REG_GET(HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  352. DSSWARN("I2C No Ack\n");
  353. return -EIO;
  354. }
  355. i = ext * 128;
  356. j = 0;
  357. while (((REG_GET(HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
  358. (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0)) &&
  359. j < 128) {
  360. if (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
  361. /* FIFO not empty */
  362. pedid[i++] = REG_GET(HDMI_CORE_DDC_DATA, 7, 0);
  363. j++;
  364. }
  365. }
  366. for (j = 0; j < 128; j++)
  367. checksum += pedid[j];
  368. if (checksum != 0) {
  369. DSSERR("E-EDID checksum failed!!\n");
  370. return -EIO;
  371. }
  372. return 0;
  373. }
  374. static int read_edid(u8 *pedid, u16 max_length)
  375. {
  376. int r = 0, n = 0, i = 0;
  377. int max_ext_blocks = (max_length / 128) - 1;
  378. r = hdmi_core_ddc_edid(pedid, 0);
  379. if (r) {
  380. return r;
  381. } else {
  382. n = pedid[0x7e];
  383. /*
  384. * README: need to comply with max_length set by the caller.
  385. * Better implementation should be to allocate necessary
  386. * memory to store EDID according to nb_block field found
  387. * in first block
  388. */
  389. if (n > max_ext_blocks)
  390. n = max_ext_blocks;
  391. for (i = 1; i <= n; i++) {
  392. r = hdmi_core_ddc_edid(pedid, i);
  393. if (r)
  394. return r;
  395. }
  396. }
  397. return 0;
  398. }
  399. static int get_timings_index(void)
  400. {
  401. int code;
  402. if (hdmi.mode == 0)
  403. code = code_vesa[hdmi.code];
  404. else
  405. code = code_cea[hdmi.code];
  406. if (code == -1) {
  407. /* HDMI code 4 corresponds to 640 * 480 VGA */
  408. hdmi.code = 4;
  409. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  410. hdmi.mode = HDMI_DVI;
  411. code = code_vesa[hdmi.code];
  412. }
  413. return code;
  414. }
  415. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  416. {
  417. int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
  418. int timing_vsync = 0, timing_hsync = 0;
  419. struct omap_video_timings temp;
  420. struct hdmi_cm cm = {-1};
  421. DSSDBG("hdmi_get_code\n");
  422. for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
  423. temp = cea_vesa_timings[i].timings;
  424. if ((temp.pixel_clock == timing->pixel_clock) &&
  425. (temp.x_res == timing->x_res) &&
  426. (temp.y_res == timing->y_res)) {
  427. temp_hsync = temp.hfp + temp.hsw + temp.hbp;
  428. timing_hsync = timing->hfp + timing->hsw + timing->hbp;
  429. temp_vsync = temp.vfp + temp.vsw + temp.vbp;
  430. timing_vsync = timing->vfp + timing->vsw + timing->vbp;
  431. DSSDBG("temp_hsync = %d , temp_vsync = %d"
  432. "timing_hsync = %d, timing_vsync = %d\n",
  433. temp_hsync, temp_hsync,
  434. timing_hsync, timing_vsync);
  435. if ((temp_hsync == timing_hsync) &&
  436. (temp_vsync == timing_vsync)) {
  437. code = i;
  438. cm.code = code_index[i];
  439. if (code < 14)
  440. cm.mode = HDMI_HDMI;
  441. else
  442. cm.mode = HDMI_DVI;
  443. DSSDBG("Hdmi_code = %d mode = %d\n",
  444. cm.code, cm.mode);
  445. break;
  446. }
  447. }
  448. }
  449. return cm;
  450. }
  451. static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
  452. struct omap_video_timings *timings)
  453. {
  454. /* X and Y resolution */
  455. timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
  456. edid[current_descriptor_addrs + 2]);
  457. timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
  458. edid[current_descriptor_addrs + 5]);
  459. timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
  460. edid[current_descriptor_addrs]);
  461. timings->pixel_clock = 10 * timings->pixel_clock;
  462. /* HORIZONTAL FRONT PORCH */
  463. timings->hfp = edid[current_descriptor_addrs + 8] |
  464. ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
  465. /* HORIZONTAL SYNC WIDTH */
  466. timings->hsw = edid[current_descriptor_addrs + 9] |
  467. ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
  468. /* HORIZONTAL BACK PORCH */
  469. timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
  470. edid[current_descriptor_addrs + 3]) -
  471. (timings->hfp + timings->hsw);
  472. /* VERTICAL FRONT PORCH */
  473. timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
  474. ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
  475. /* VERTICAL SYNC WIDTH */
  476. timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
  477. ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
  478. /* VERTICAL BACK PORCH */
  479. timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
  480. edid[current_descriptor_addrs + 6]) -
  481. (timings->vfp + timings->vsw);
  482. }
  483. /* Description : This function gets the resolution information from EDID */
  484. static void get_edid_timing_data(u8 *edid)
  485. {
  486. u8 count;
  487. u16 current_descriptor_addrs;
  488. struct hdmi_cm cm;
  489. struct omap_video_timings edid_timings;
  490. /* seach block 0, there are 4 DTDs arranged in priority order */
  491. for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
  492. current_descriptor_addrs =
  493. EDID_DESCRIPTOR_BLOCK0_ADDRESS +
  494. count * EDID_TIMING_DESCRIPTOR_SIZE;
  495. get_horz_vert_timing_info(current_descriptor_addrs,
  496. edid, &edid_timings);
  497. cm = hdmi_get_code(&edid_timings);
  498. DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
  499. count, cm.code, cm.mode);
  500. if (cm.code == -1) {
  501. continue;
  502. } else {
  503. hdmi.code = cm.code;
  504. hdmi.mode = cm.mode;
  505. DSSDBG("code = %d , mode = %d\n",
  506. hdmi.code, hdmi.mode);
  507. return;
  508. }
  509. }
  510. if (edid[0x7e] != 0x00) {
  511. for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
  512. count++) {
  513. current_descriptor_addrs =
  514. EDID_DESCRIPTOR_BLOCK1_ADDRESS +
  515. count * EDID_TIMING_DESCRIPTOR_SIZE;
  516. get_horz_vert_timing_info(current_descriptor_addrs,
  517. edid, &edid_timings);
  518. cm = hdmi_get_code(&edid_timings);
  519. DSSDBG("Block1[%d] value matches code = %d, mode = %d",
  520. count, cm.code, cm.mode);
  521. if (cm.code == -1) {
  522. continue;
  523. } else {
  524. hdmi.code = cm.code;
  525. hdmi.mode = cm.mode;
  526. DSSDBG("code = %d , mode = %d\n",
  527. hdmi.code, hdmi.mode);
  528. return;
  529. }
  530. }
  531. }
  532. DSSINFO("no valid timing found , falling back to VGA\n");
  533. hdmi.code = 4; /* setting default value of 640 480 VGA */
  534. hdmi.mode = HDMI_DVI;
  535. }
  536. static void hdmi_read_edid(struct omap_video_timings *dp)
  537. {
  538. int ret = 0, code;
  539. memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
  540. if (!hdmi.edid_set)
  541. ret = read_edid(hdmi.edid, HDMI_EDID_MAX_LENGTH);
  542. if (!ret) {
  543. if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
  544. /* search for timings of default resolution */
  545. get_edid_timing_data(hdmi.edid);
  546. hdmi.edid_set = true;
  547. }
  548. } else {
  549. DSSWARN("failed to read E-EDID\n");
  550. }
  551. if (!hdmi.edid_set) {
  552. DSSINFO("fallback to VGA\n");
  553. hdmi.code = 4; /* setting default value of 640 480 VGA */
  554. hdmi.mode = HDMI_DVI;
  555. }
  556. code = get_timings_index();
  557. *dp = cea_vesa_timings[code].timings;
  558. }
  559. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  560. struct hdmi_core_infoframe_avi *avi_cfg,
  561. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  562. {
  563. DSSDBG("Enter hdmi_core_init\n");
  564. /* video core */
  565. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  566. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  567. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  568. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  569. video_cfg->hdmi_dvi = HDMI_DVI;
  570. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  571. /* info frame */
  572. avi_cfg->db1_format = 0;
  573. avi_cfg->db1_active_info = 0;
  574. avi_cfg->db1_bar_info_dv = 0;
  575. avi_cfg->db1_scan_info = 0;
  576. avi_cfg->db2_colorimetry = 0;
  577. avi_cfg->db2_aspect_ratio = 0;
  578. avi_cfg->db2_active_fmt_ar = 0;
  579. avi_cfg->db3_itc = 0;
  580. avi_cfg->db3_ec = 0;
  581. avi_cfg->db3_q_range = 0;
  582. avi_cfg->db3_nup_scaling = 0;
  583. avi_cfg->db4_videocode = 0;
  584. avi_cfg->db5_pixel_repeat = 0;
  585. avi_cfg->db6_7_line_eoftop = 0 ;
  586. avi_cfg->db8_9_line_sofbottom = 0;
  587. avi_cfg->db10_11_pixel_eofleft = 0;
  588. avi_cfg->db12_13_pixel_sofright = 0;
  589. /* packet enable and repeat */
  590. repeat_cfg->audio_pkt = 0;
  591. repeat_cfg->audio_pkt_repeat = 0;
  592. repeat_cfg->avi_infoframe = 0;
  593. repeat_cfg->avi_infoframe_repeat = 0;
  594. repeat_cfg->gen_cntrl_pkt = 0;
  595. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  596. repeat_cfg->generic_pkt = 0;
  597. repeat_cfg->generic_pkt_repeat = 0;
  598. }
  599. static void hdmi_core_powerdown_disable(void)
  600. {
  601. DSSDBG("Enter hdmi_core_powerdown_disable\n");
  602. REG_FLD_MOD(HDMI_CORE_CTRL1, 0x0, 0, 0);
  603. }
  604. static void hdmi_core_swreset_release(void)
  605. {
  606. DSSDBG("Enter hdmi_core_swreset_release\n");
  607. REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  608. }
  609. static void hdmi_core_swreset_assert(void)
  610. {
  611. DSSDBG("Enter hdmi_core_swreset_assert\n");
  612. REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  613. }
  614. /* DSS_HDMI_CORE_VIDEO_CONFIG */
  615. static void hdmi_core_video_config(struct hdmi_core_video_config *cfg)
  616. {
  617. u32 r = 0;
  618. /* sys_ctrl1 default configuration not tunable */
  619. r = hdmi_read_reg(HDMI_CORE_CTRL1);
  620. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  621. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  622. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  623. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  624. hdmi_write_reg(HDMI_CORE_CTRL1, r);
  625. REG_FLD_MOD(HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  626. /* Vid_Mode */
  627. r = hdmi_read_reg(HDMI_CORE_SYS_VID_MODE);
  628. /* dither truncation configuration */
  629. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  630. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  631. r = FLD_MOD(r, 1, 5, 5);
  632. } else {
  633. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  634. r = FLD_MOD(r, 0, 5, 5);
  635. }
  636. hdmi_write_reg(HDMI_CORE_SYS_VID_MODE, r);
  637. /* HDMI_Ctrl */
  638. r = hdmi_read_reg(HDMI_CORE_AV_HDMI_CTRL);
  639. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  640. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  641. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  642. hdmi_write_reg(HDMI_CORE_AV_HDMI_CTRL, r);
  643. /* TMDS_CTRL */
  644. REG_FLD_MOD(HDMI_CORE_SYS_TMDS_CTRL,
  645. cfg->tclk_sel_clkmult, 6, 5);
  646. }
  647. static void hdmi_core_aux_infoframe_avi_config(
  648. struct hdmi_core_infoframe_avi info_avi)
  649. {
  650. u32 val;
  651. char sum = 0, checksum = 0;
  652. sum += 0x82 + 0x002 + 0x00D;
  653. hdmi_write_reg(HDMI_CORE_AV_AVI_TYPE, 0x082);
  654. hdmi_write_reg(HDMI_CORE_AV_AVI_VERS, 0x002);
  655. hdmi_write_reg(HDMI_CORE_AV_AVI_LEN, 0x00D);
  656. val = (info_avi.db1_format << 5) |
  657. (info_avi.db1_active_info << 4) |
  658. (info_avi.db1_bar_info_dv << 2) |
  659. (info_avi.db1_scan_info);
  660. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(0), val);
  661. sum += val;
  662. val = (info_avi.db2_colorimetry << 6) |
  663. (info_avi.db2_aspect_ratio << 4) |
  664. (info_avi.db2_active_fmt_ar);
  665. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(1), val);
  666. sum += val;
  667. val = (info_avi.db3_itc << 7) |
  668. (info_avi.db3_ec << 4) |
  669. (info_avi.db3_q_range << 2) |
  670. (info_avi.db3_nup_scaling);
  671. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(2), val);
  672. sum += val;
  673. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(3), info_avi.db4_videocode);
  674. sum += info_avi.db4_videocode;
  675. val = info_avi.db5_pixel_repeat;
  676. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(4), val);
  677. sum += val;
  678. val = info_avi.db6_7_line_eoftop & 0x00FF;
  679. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(5), val);
  680. sum += val;
  681. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  682. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(6), val);
  683. sum += val;
  684. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  685. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(7), val);
  686. sum += val;
  687. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  688. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(8), val);
  689. sum += val;
  690. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  691. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(9), val);
  692. sum += val;
  693. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  694. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(10), val);
  695. sum += val;
  696. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  697. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(11), val);
  698. sum += val;
  699. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  700. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(12), val);
  701. sum += val;
  702. checksum = 0x100 - sum;
  703. hdmi_write_reg(HDMI_CORE_AV_AVI_CHSUM, checksum);
  704. }
  705. static void hdmi_core_av_packet_config(
  706. struct hdmi_core_packet_enable_repeat repeat_cfg)
  707. {
  708. /* enable/repeat the infoframe */
  709. hdmi_write_reg(HDMI_CORE_AV_PB_CTRL1,
  710. (repeat_cfg.audio_pkt << 5) |
  711. (repeat_cfg.audio_pkt_repeat << 4) |
  712. (repeat_cfg.avi_infoframe << 1) |
  713. (repeat_cfg.avi_infoframe_repeat));
  714. /* enable/repeat the packet */
  715. hdmi_write_reg(HDMI_CORE_AV_PB_CTRL2,
  716. (repeat_cfg.gen_cntrl_pkt << 3) |
  717. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  718. (repeat_cfg.generic_pkt << 1) |
  719. (repeat_cfg.generic_pkt_repeat));
  720. }
  721. static void hdmi_wp_init(struct omap_video_timings *timings,
  722. struct hdmi_video_format *video_fmt,
  723. struct hdmi_video_interface *video_int)
  724. {
  725. DSSDBG("Enter hdmi_wp_init\n");
  726. timings->hbp = 0;
  727. timings->hfp = 0;
  728. timings->hsw = 0;
  729. timings->vbp = 0;
  730. timings->vfp = 0;
  731. timings->vsw = 0;
  732. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  733. video_fmt->y_res = 0;
  734. video_fmt->x_res = 0;
  735. video_int->vsp = 0;
  736. video_int->hsp = 0;
  737. video_int->interlacing = 0;
  738. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  739. }
  740. static void hdmi_wp_video_start(bool start)
  741. {
  742. REG_FLD_MOD(HDMI_WP_VIDEO_CFG, start, 31, 31);
  743. }
  744. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  745. struct omap_video_timings *timings, struct hdmi_config *param)
  746. {
  747. DSSDBG("Enter hdmi_wp_video_init_format\n");
  748. video_fmt->y_res = param->timings.timings.y_res;
  749. video_fmt->x_res = param->timings.timings.x_res;
  750. timings->hbp = param->timings.timings.hbp;
  751. timings->hfp = param->timings.timings.hfp;
  752. timings->hsw = param->timings.timings.hsw;
  753. timings->vbp = param->timings.timings.vbp;
  754. timings->vfp = param->timings.timings.vfp;
  755. timings->vsw = param->timings.timings.vsw;
  756. }
  757. static void hdmi_wp_video_config_format(
  758. struct hdmi_video_format *video_fmt)
  759. {
  760. u32 l = 0;
  761. REG_FLD_MOD(HDMI_WP_VIDEO_CFG, video_fmt->packing_mode, 10, 8);
  762. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  763. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  764. hdmi_write_reg(HDMI_WP_VIDEO_SIZE, l);
  765. }
  766. static void hdmi_wp_video_config_interface(
  767. struct hdmi_video_interface *video_int)
  768. {
  769. u32 r;
  770. DSSDBG("Enter hdmi_wp_video_config_interface\n");
  771. r = hdmi_read_reg(HDMI_WP_VIDEO_CFG);
  772. r = FLD_MOD(r, video_int->vsp, 7, 7);
  773. r = FLD_MOD(r, video_int->hsp, 6, 6);
  774. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  775. r = FLD_MOD(r, video_int->tm, 1, 0);
  776. hdmi_write_reg(HDMI_WP_VIDEO_CFG, r);
  777. }
  778. static void hdmi_wp_video_config_timing(
  779. struct omap_video_timings *timings)
  780. {
  781. u32 timing_h = 0;
  782. u32 timing_v = 0;
  783. DSSDBG("Enter hdmi_wp_video_config_timing\n");
  784. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  785. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  786. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  787. hdmi_write_reg(HDMI_WP_VIDEO_TIMING_H, timing_h);
  788. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  789. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  790. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  791. hdmi_write_reg(HDMI_WP_VIDEO_TIMING_V, timing_v);
  792. }
  793. static void hdmi_basic_configure(struct hdmi_config *cfg)
  794. {
  795. /* HDMI */
  796. struct omap_video_timings video_timing;
  797. struct hdmi_video_format video_format;
  798. struct hdmi_video_interface video_interface;
  799. /* HDMI core */
  800. struct hdmi_core_infoframe_avi avi_cfg;
  801. struct hdmi_core_video_config v_core_cfg;
  802. struct hdmi_core_packet_enable_repeat repeat_cfg;
  803. hdmi_wp_init(&video_timing, &video_format,
  804. &video_interface);
  805. hdmi_core_init(&v_core_cfg,
  806. &avi_cfg,
  807. &repeat_cfg);
  808. hdmi_wp_video_init_format(&video_format,
  809. &video_timing, cfg);
  810. hdmi_wp_video_config_timing(&video_timing);
  811. /* video config */
  812. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  813. hdmi_wp_video_config_format(&video_format);
  814. video_interface.vsp = cfg->timings.vsync_pol;
  815. video_interface.hsp = cfg->timings.hsync_pol;
  816. video_interface.interlacing = cfg->interlace;
  817. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  818. hdmi_wp_video_config_interface(&video_interface);
  819. /*
  820. * configure core video part
  821. * set software reset in the core
  822. */
  823. hdmi_core_swreset_assert();
  824. /* power down off */
  825. hdmi_core_powerdown_disable();
  826. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  827. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  828. hdmi_core_video_config(&v_core_cfg);
  829. /* release software reset in the core */
  830. hdmi_core_swreset_release();
  831. /*
  832. * configure packet
  833. * info frame video see doc CEA861-D page 65
  834. */
  835. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  836. avi_cfg.db1_active_info =
  837. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  838. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  839. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  840. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  841. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  842. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  843. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  844. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  845. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  846. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  847. avi_cfg.db4_videocode = cfg->cm.code;
  848. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  849. avi_cfg.db6_7_line_eoftop = 0;
  850. avi_cfg.db8_9_line_sofbottom = 0;
  851. avi_cfg.db10_11_pixel_eofleft = 0;
  852. avi_cfg.db12_13_pixel_sofright = 0;
  853. hdmi_core_aux_infoframe_avi_config(avi_cfg);
  854. /* enable/repeat the infoframe */
  855. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  856. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  857. /* wakeup */
  858. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  859. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  860. hdmi_core_av_packet_config(repeat_cfg);
  861. }
  862. static void update_hdmi_timings(struct hdmi_config *cfg,
  863. struct omap_video_timings *timings, int code)
  864. {
  865. cfg->timings.timings.x_res = timings->x_res;
  866. cfg->timings.timings.y_res = timings->y_res;
  867. cfg->timings.timings.hbp = timings->hbp;
  868. cfg->timings.timings.hfp = timings->hfp;
  869. cfg->timings.timings.hsw = timings->hsw;
  870. cfg->timings.timings.vbp = timings->vbp;
  871. cfg->timings.timings.vfp = timings->vfp;
  872. cfg->timings.timings.vsw = timings->vsw;
  873. cfg->timings.timings.pixel_clock = timings->pixel_clock;
  874. cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
  875. cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
  876. }
  877. static void hdmi_compute_pll(unsigned long clkin, int phy,
  878. int n, struct hdmi_pll_info *pi)
  879. {
  880. unsigned long refclk;
  881. u32 mf;
  882. /*
  883. * Input clock is predivided by N + 1
  884. * out put of which is reference clk
  885. */
  886. refclk = clkin / (n + 1);
  887. pi->regn = n;
  888. /*
  889. * multiplier is pixel_clk/ref_clk
  890. * Multiplying by 100 to avoid fractional part removal
  891. */
  892. pi->regm = (phy * 100/(refclk))/100;
  893. pi->regm2 = 1;
  894. /*
  895. * fractional multiplier is remainder of the difference between
  896. * multiplier and actual phy(required pixel clock thus should be
  897. * multiplied by 2^18(262144) divided by the reference clock
  898. */
  899. mf = (phy - pi->regm * refclk) * 262144;
  900. pi->regmf = mf/(refclk);
  901. /*
  902. * Dcofreq should be set to 1 if required pixel clock
  903. * is greater than 1000MHz
  904. */
  905. pi->dcofreq = phy > 1000 * 100;
  906. pi->regsd = ((pi->regm * clkin / 10) / ((n + 1) * 250) + 5) / 10;
  907. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  908. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  909. }
  910. static void hdmi_enable_clocks(int enable)
  911. {
  912. if (enable)
  913. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK |
  914. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  915. else
  916. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK |
  917. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  918. }
  919. static int hdmi_power_on(struct omap_dss_device *dssdev)
  920. {
  921. int r, code = 0;
  922. struct hdmi_pll_info pll_data;
  923. struct omap_video_timings *p;
  924. int clkin, n, phy;
  925. hdmi_enable_clocks(1);
  926. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  927. p = &dssdev->panel.timings;
  928. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  929. dssdev->panel.timings.x_res,
  930. dssdev->panel.timings.y_res);
  931. if (!hdmi.custom_set) {
  932. DSSDBG("Read EDID as no EDID is not set on poweron\n");
  933. hdmi_read_edid(p);
  934. }
  935. code = get_timings_index();
  936. dssdev->panel.timings = cea_vesa_timings[code].timings;
  937. update_hdmi_timings(&hdmi.cfg, p, code);
  938. clkin = 3840; /* 38.4 MHz */
  939. n = 15; /* this is a constant for our math */
  940. phy = p->pixel_clock;
  941. hdmi_compute_pll(clkin, phy, n, &pll_data);
  942. hdmi_wp_video_start(0);
  943. /* config the PLL and PHY first */
  944. r = hdmi_pll_program(&pll_data);
  945. if (r) {
  946. DSSDBG("Failed to lock PLL\n");
  947. goto err;
  948. }
  949. r = hdmi_phy_init();
  950. if (r) {
  951. DSSDBG("Failed to start PHY\n");
  952. goto err;
  953. }
  954. hdmi.cfg.cm.mode = hdmi.mode;
  955. hdmi.cfg.cm.code = hdmi.code;
  956. hdmi_basic_configure(&hdmi.cfg);
  957. /* Make selection of HDMI in DSS */
  958. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  959. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  960. * DSI PLL source as the clock selected by DSI PLL might not be
  961. * sufficient for the resolution selected / that can be changed
  962. * dynamically by user. This can be moved to single location , say
  963. * Boardfile.
  964. */
  965. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  966. /* bypass TV gamma table */
  967. dispc_enable_gamma_table(0);
  968. /* tv size */
  969. dispc_set_digit_size(dssdev->panel.timings.x_res,
  970. dssdev->panel.timings.y_res);
  971. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 1);
  972. hdmi_wp_video_start(1);
  973. return 0;
  974. err:
  975. hdmi_enable_clocks(0);
  976. return -EIO;
  977. }
  978. static void hdmi_power_off(struct omap_dss_device *dssdev)
  979. {
  980. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  981. hdmi_wp_video_start(0);
  982. hdmi_phy_off();
  983. hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
  984. hdmi_enable_clocks(0);
  985. hdmi.edid_set = 0;
  986. }
  987. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  988. struct omap_video_timings *timings)
  989. {
  990. struct hdmi_cm cm;
  991. cm = hdmi_get_code(timings);
  992. if (cm.code == -1) {
  993. DSSERR("Invalid timing entered\n");
  994. return -EINVAL;
  995. }
  996. return 0;
  997. }
  998. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  999. {
  1000. struct hdmi_cm cm;
  1001. hdmi.custom_set = 1;
  1002. cm = hdmi_get_code(&dssdev->panel.timings);
  1003. hdmi.code = cm.code;
  1004. hdmi.mode = cm.mode;
  1005. omapdss_hdmi_display_enable(dssdev);
  1006. hdmi.custom_set = 0;
  1007. }
  1008. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  1009. {
  1010. int r = 0;
  1011. DSSDBG("ENTER hdmi_display_enable\n");
  1012. mutex_lock(&hdmi.lock);
  1013. r = omap_dss_start_device(dssdev);
  1014. if (r) {
  1015. DSSERR("failed to start device\n");
  1016. goto err0;
  1017. }
  1018. if (dssdev->platform_enable) {
  1019. r = dssdev->platform_enable(dssdev);
  1020. if (r) {
  1021. DSSERR("failed to enable GPIO's\n");
  1022. goto err1;
  1023. }
  1024. }
  1025. r = hdmi_power_on(dssdev);
  1026. if (r) {
  1027. DSSERR("failed to power on device\n");
  1028. goto err2;
  1029. }
  1030. mutex_unlock(&hdmi.lock);
  1031. return 0;
  1032. err2:
  1033. if (dssdev->platform_disable)
  1034. dssdev->platform_disable(dssdev);
  1035. err1:
  1036. omap_dss_stop_device(dssdev);
  1037. err0:
  1038. mutex_unlock(&hdmi.lock);
  1039. return r;
  1040. }
  1041. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  1042. {
  1043. DSSDBG("Enter hdmi_display_disable\n");
  1044. mutex_lock(&hdmi.lock);
  1045. hdmi_power_off(dssdev);
  1046. if (dssdev->platform_disable)
  1047. dssdev->platform_disable(dssdev);
  1048. omap_dss_stop_device(dssdev);
  1049. mutex_unlock(&hdmi.lock);
  1050. }
  1051. /* HDMI HW IP initialisation */
  1052. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  1053. {
  1054. struct resource *hdmi_mem;
  1055. hdmi.pdata = pdev->dev.platform_data;
  1056. hdmi.pdev = pdev;
  1057. mutex_init(&hdmi.lock);
  1058. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  1059. if (!hdmi_mem) {
  1060. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  1061. return -EINVAL;
  1062. }
  1063. /* Base address taken from platform */
  1064. hdmi.base_wp = ioremap(hdmi_mem->start, resource_size(hdmi_mem));
  1065. if (!hdmi.base_wp) {
  1066. DSSERR("can't ioremap WP\n");
  1067. return -ENOMEM;
  1068. }
  1069. hdmi_panel_init();
  1070. return 0;
  1071. }
  1072. static int omapdss_hdmihw_remove(struct platform_device *pdev)
  1073. {
  1074. hdmi_panel_exit();
  1075. iounmap(hdmi.base_wp);
  1076. return 0;
  1077. }
  1078. static struct platform_driver omapdss_hdmihw_driver = {
  1079. .probe = omapdss_hdmihw_probe,
  1080. .remove = omapdss_hdmihw_remove,
  1081. .driver = {
  1082. .name = "omapdss_hdmi",
  1083. .owner = THIS_MODULE,
  1084. },
  1085. };
  1086. int hdmi_init_platform_driver(void)
  1087. {
  1088. return platform_driver_register(&omapdss_hdmihw_driver);
  1089. }
  1090. void hdmi_uninit_platform_driver(void)
  1091. {
  1092. return platform_driver_unregister(&omapdss_hdmihw_driver);
  1093. }