hdmi.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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 <video/omapdss.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. /* search 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(struct omap_dss_device *dssdev, int phy,
  878. struct hdmi_pll_info *pi)
  879. {
  880. unsigned long clkin, refclk;
  881. u32 mf;
  882. clkin = dss_clk_get_rate(DSS_CLK_SYSCK) / 10000;
  883. /*
  884. * Input clock is predivided by N + 1
  885. * out put of which is reference clk
  886. */
  887. pi->regn = dssdev->clocks.hdmi.regn;
  888. refclk = clkin / (pi->regn + 1);
  889. /*
  890. * multiplier is pixel_clk/ref_clk
  891. * Multiplying by 100 to avoid fractional part removal
  892. */
  893. pi->regm = (phy * 100 / (refclk)) / 100;
  894. pi->regm2 = dssdev->clocks.hdmi.regm2;
  895. /*
  896. * fractional multiplier is remainder of the difference between
  897. * multiplier and actual phy(required pixel clock thus should be
  898. * multiplied by 2^18(262144) divided by the reference clock
  899. */
  900. mf = (phy - pi->regm * refclk) * 262144;
  901. pi->regmf = mf / (refclk);
  902. /*
  903. * Dcofreq should be set to 1 if required pixel clock
  904. * is greater than 1000MHz
  905. */
  906. pi->dcofreq = phy > 1000 * 100;
  907. pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
  908. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  909. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  910. }
  911. static void hdmi_enable_clocks(int enable)
  912. {
  913. if (enable)
  914. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK |
  915. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  916. else
  917. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK |
  918. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  919. }
  920. static int hdmi_power_on(struct omap_dss_device *dssdev)
  921. {
  922. int r, code = 0;
  923. struct hdmi_pll_info pll_data;
  924. struct omap_video_timings *p;
  925. unsigned long phy;
  926. hdmi_enable_clocks(1);
  927. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  928. p = &dssdev->panel.timings;
  929. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  930. dssdev->panel.timings.x_res,
  931. dssdev->panel.timings.y_res);
  932. if (!hdmi.custom_set) {
  933. DSSDBG("Read EDID as no EDID is not set on poweron\n");
  934. hdmi_read_edid(p);
  935. }
  936. code = get_timings_index();
  937. dssdev->panel.timings = cea_vesa_timings[code].timings;
  938. update_hdmi_timings(&hdmi.cfg, p, code);
  939. phy = p->pixel_clock;
  940. hdmi_compute_pll(dssdev, phy, &pll_data);
  941. hdmi_wp_video_start(0);
  942. /* config the PLL and PHY first */
  943. r = hdmi_pll_program(&pll_data);
  944. if (r) {
  945. DSSDBG("Failed to lock PLL\n");
  946. goto err;
  947. }
  948. r = hdmi_phy_init();
  949. if (r) {
  950. DSSDBG("Failed to start PHY\n");
  951. goto err;
  952. }
  953. hdmi.cfg.cm.mode = hdmi.mode;
  954. hdmi.cfg.cm.code = hdmi.code;
  955. hdmi_basic_configure(&hdmi.cfg);
  956. /* Make selection of HDMI in DSS */
  957. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  958. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  959. * DSI PLL source as the clock selected by DSI PLL might not be
  960. * sufficient for the resolution selected / that can be changed
  961. * dynamically by user. This can be moved to single location , say
  962. * Boardfile.
  963. */
  964. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  965. /* bypass TV gamma table */
  966. dispc_enable_gamma_table(0);
  967. /* tv size */
  968. dispc_set_digit_size(dssdev->panel.timings.x_res,
  969. dssdev->panel.timings.y_res);
  970. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 1);
  971. hdmi_wp_video_start(1);
  972. return 0;
  973. err:
  974. hdmi_enable_clocks(0);
  975. return -EIO;
  976. }
  977. static void hdmi_power_off(struct omap_dss_device *dssdev)
  978. {
  979. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  980. hdmi_wp_video_start(0);
  981. hdmi_phy_off();
  982. hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
  983. hdmi_enable_clocks(0);
  984. hdmi.edid_set = 0;
  985. }
  986. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  987. struct omap_video_timings *timings)
  988. {
  989. struct hdmi_cm cm;
  990. cm = hdmi_get_code(timings);
  991. if (cm.code == -1) {
  992. DSSERR("Invalid timing entered\n");
  993. return -EINVAL;
  994. }
  995. return 0;
  996. }
  997. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  998. {
  999. struct hdmi_cm cm;
  1000. hdmi.custom_set = 1;
  1001. cm = hdmi_get_code(&dssdev->panel.timings);
  1002. hdmi.code = cm.code;
  1003. hdmi.mode = cm.mode;
  1004. omapdss_hdmi_display_enable(dssdev);
  1005. hdmi.custom_set = 0;
  1006. }
  1007. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  1008. {
  1009. int r = 0;
  1010. DSSDBG("ENTER hdmi_display_enable\n");
  1011. mutex_lock(&hdmi.lock);
  1012. r = omap_dss_start_device(dssdev);
  1013. if (r) {
  1014. DSSERR("failed to start device\n");
  1015. goto err0;
  1016. }
  1017. if (dssdev->platform_enable) {
  1018. r = dssdev->platform_enable(dssdev);
  1019. if (r) {
  1020. DSSERR("failed to enable GPIO's\n");
  1021. goto err1;
  1022. }
  1023. }
  1024. r = hdmi_power_on(dssdev);
  1025. if (r) {
  1026. DSSERR("failed to power on device\n");
  1027. goto err2;
  1028. }
  1029. mutex_unlock(&hdmi.lock);
  1030. return 0;
  1031. err2:
  1032. if (dssdev->platform_disable)
  1033. dssdev->platform_disable(dssdev);
  1034. err1:
  1035. omap_dss_stop_device(dssdev);
  1036. err0:
  1037. mutex_unlock(&hdmi.lock);
  1038. return r;
  1039. }
  1040. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  1041. {
  1042. DSSDBG("Enter hdmi_display_disable\n");
  1043. mutex_lock(&hdmi.lock);
  1044. hdmi_power_off(dssdev);
  1045. if (dssdev->platform_disable)
  1046. dssdev->platform_disable(dssdev);
  1047. omap_dss_stop_device(dssdev);
  1048. mutex_unlock(&hdmi.lock);
  1049. }
  1050. /* HDMI HW IP initialisation */
  1051. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  1052. {
  1053. struct resource *hdmi_mem;
  1054. hdmi.pdata = pdev->dev.platform_data;
  1055. hdmi.pdev = pdev;
  1056. mutex_init(&hdmi.lock);
  1057. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  1058. if (!hdmi_mem) {
  1059. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  1060. return -EINVAL;
  1061. }
  1062. /* Base address taken from platform */
  1063. hdmi.base_wp = ioremap(hdmi_mem->start, resource_size(hdmi_mem));
  1064. if (!hdmi.base_wp) {
  1065. DSSERR("can't ioremap WP\n");
  1066. return -ENOMEM;
  1067. }
  1068. hdmi_panel_init();
  1069. return 0;
  1070. }
  1071. static int omapdss_hdmihw_remove(struct platform_device *pdev)
  1072. {
  1073. hdmi_panel_exit();
  1074. iounmap(hdmi.base_wp);
  1075. return 0;
  1076. }
  1077. static struct platform_driver omapdss_hdmihw_driver = {
  1078. .probe = omapdss_hdmihw_probe,
  1079. .remove = omapdss_hdmihw_remove,
  1080. .driver = {
  1081. .name = "omapdss_hdmi",
  1082. .owner = THIS_MODULE,
  1083. },
  1084. };
  1085. int hdmi_init_platform_driver(void)
  1086. {
  1087. return platform_driver_register(&omapdss_hdmihw_driver);
  1088. }
  1089. void hdmi_uninit_platform_driver(void)
  1090. {
  1091. return platform_driver_unregister(&omapdss_hdmihw_driver);
  1092. }