hdmi.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  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. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  32. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  33. #include <sound/soc.h>
  34. #include <sound/pcm_params.h>
  35. #endif
  36. #include "dss.h"
  37. #include "hdmi.h"
  38. #include "dss_features.h"
  39. static struct {
  40. struct mutex lock;
  41. struct omap_display_platform_data *pdata;
  42. struct platform_device *pdev;
  43. void __iomem *base_wp; /* HDMI wrapper */
  44. int code;
  45. int mode;
  46. u8 edid[HDMI_EDID_MAX_LENGTH];
  47. u8 edid_set;
  48. bool custom_set;
  49. struct hdmi_config cfg;
  50. } hdmi;
  51. /*
  52. * Logic for the below structure :
  53. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  54. * There is a correspondence between CEA/VESA timing and code, please
  55. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  56. *
  57. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  58. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  59. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  60. * with code_vesa. Code_index is used for back mapping, that is once EDID
  61. * is read from the TV, EDID is parsed to find the timing values and then
  62. * map it to corresponding CEA or VESA index.
  63. */
  64. static const struct hdmi_timings cea_vesa_timings[OMAP_HDMI_TIMINGS_NB] = {
  65. { {640, 480, 25200, 96, 16, 48, 2, 10, 33} , 0 , 0},
  66. { {1280, 720, 74250, 40, 440, 220, 5, 5, 20}, 1, 1},
  67. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1},
  68. { {720, 480, 27027, 62, 16, 60, 6, 9, 30}, 0, 0},
  69. { {2880, 576, 108000, 256, 48, 272, 5, 5, 39}, 0, 0},
  70. { {1440, 240, 27027, 124, 38, 114, 3, 4, 15}, 0, 0},
  71. { {1440, 288, 27000, 126, 24, 138, 3, 2, 19}, 0, 0},
  72. { {1920, 540, 74250, 44, 528, 148, 5, 2, 15}, 1, 1},
  73. { {1920, 540, 74250, 44, 88, 148, 5, 2, 15}, 1, 1},
  74. { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36}, 1, 1},
  75. { {720, 576, 27000, 64, 12, 68, 5, 5, 39}, 0, 0},
  76. { {1440, 576, 54000, 128, 24, 136, 5, 5, 39}, 0, 0},
  77. { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36}, 1, 1},
  78. { {2880, 480, 108108, 248, 64, 240, 6, 9, 30}, 0, 0},
  79. { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36}, 1, 1},
  80. /* VESA From Here */
  81. { {640, 480, 25175, 96, 16, 48, 2 , 11, 31}, 0, 0},
  82. { {800, 600, 40000, 128, 40, 88, 4 , 1, 23}, 1, 1},
  83. { {848, 480, 33750, 112, 16, 112, 8 , 6, 23}, 1, 1},
  84. { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20}, 1, 0},
  85. { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22}, 1, 0},
  86. { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18}, 1, 1},
  87. { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36}, 1, 1},
  88. { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38}, 1, 1},
  89. { {1024, 768, 65000, 136, 24, 160, 6, 3, 29}, 0, 0},
  90. { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32}, 1, 0},
  91. { {1440, 900, 106500, 152, 80, 232, 6, 3, 25}, 1, 0},
  92. { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30}, 1, 0},
  93. { {1366, 768, 85500, 143, 70, 213, 3, 3, 24}, 1, 1},
  94. { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36}, 1, 1},
  95. { {1280, 768, 68250, 32, 48, 80, 7, 3, 12}, 0, 1},
  96. { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23}, 0, 1},
  97. { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21}, 0, 1},
  98. { {1280, 800, 79500, 32, 48, 80, 6, 3, 14}, 0, 1},
  99. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20}, 1, 1}
  100. };
  101. /*
  102. * This is a static mapping array which maps the timing values
  103. * with corresponding CEA / VESA code
  104. */
  105. static const int code_index[OMAP_HDMI_TIMINGS_NB] = {
  106. 1, 19, 4, 2, 37, 6, 21, 20, 5, 16, 17, 29, 31, 35, 32,
  107. /* <--15 CEA 17--> vesa*/
  108. 4, 9, 0xE, 0x17, 0x1C, 0x27, 0x20, 0x23, 0x10, 0x2A,
  109. 0X2F, 0x3A, 0X51, 0X52, 0x16, 0x29, 0x39, 0x1B
  110. };
  111. /*
  112. * This is reverse static mapping which maps the CEA / VESA code
  113. * to the corresponding timing values
  114. */
  115. static const int code_cea[39] = {
  116. -1, 0, 3, 3, 2, 8, 5, 5, -1, -1,
  117. -1, -1, -1, -1, -1, -1, 9, 10, 10, 1,
  118. 7, 6, 6, -1, -1, -1, -1, -1, -1, 11,
  119. 11, 12, 14, -1, -1, 13, 13, 4, 4
  120. };
  121. static const int code_vesa[85] = {
  122. -1, -1, -1, -1, 15, -1, -1, -1, -1, 16,
  123. -1, -1, -1, -1, 17, -1, 23, -1, -1, -1,
  124. -1, -1, 29, 18, -1, -1, -1, 32, 19, -1,
  125. -1, -1, 21, -1, -1, 22, -1, -1, -1, 20,
  126. -1, 30, 24, -1, -1, -1, -1, 25, -1, -1,
  127. -1, -1, -1, -1, -1, -1, -1, 31, 26, -1,
  128. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  129. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  130. -1, 27, 28, -1, 33};
  131. static const u8 edid_header[8] = {0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0};
  132. static inline void hdmi_write_reg(const struct hdmi_reg idx, u32 val)
  133. {
  134. __raw_writel(val, hdmi.base_wp + idx.idx);
  135. }
  136. static inline u32 hdmi_read_reg(const struct hdmi_reg idx)
  137. {
  138. return __raw_readl(hdmi.base_wp + idx.idx);
  139. }
  140. static inline int hdmi_wait_for_bit_change(const struct hdmi_reg idx,
  141. int b2, int b1, u32 val)
  142. {
  143. u32 t = 0;
  144. while (val != REG_GET(idx, b2, b1)) {
  145. udelay(1);
  146. if (t++ > 10000)
  147. return !val;
  148. }
  149. return val;
  150. }
  151. int hdmi_init_display(struct omap_dss_device *dssdev)
  152. {
  153. DSSDBG("init_display\n");
  154. return 0;
  155. }
  156. static int hdmi_pll_init(enum hdmi_clk_refsel refsel, int dcofreq,
  157. struct hdmi_pll_info *fmt, u16 sd)
  158. {
  159. u32 r;
  160. /* PLL start always use manual mode */
  161. REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
  162. r = hdmi_read_reg(PLLCTRL_CFG1);
  163. r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
  164. r = FLD_MOD(r, fmt->regn, 8, 1); /* CFG1_PLL_REGN */
  165. hdmi_write_reg(PLLCTRL_CFG1, r);
  166. r = hdmi_read_reg(PLLCTRL_CFG2);
  167. r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
  168. r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
  169. r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
  170. if (dcofreq) {
  171. /* divider programming for frequency beyond 1000Mhz */
  172. REG_FLD_MOD(PLLCTRL_CFG3, sd, 17, 10);
  173. r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
  174. } else {
  175. r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
  176. }
  177. hdmi_write_reg(PLLCTRL_CFG2, r);
  178. r = hdmi_read_reg(PLLCTRL_CFG4);
  179. r = FLD_MOD(r, fmt->regm2, 24, 18);
  180. r = FLD_MOD(r, fmt->regmf, 17, 0);
  181. hdmi_write_reg(PLLCTRL_CFG4, r);
  182. /* go now */
  183. REG_FLD_MOD(PLLCTRL_PLL_GO, 0x1, 0, 0);
  184. /* wait for bit change */
  185. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_GO, 0, 0, 1) != 1) {
  186. DSSERR("PLL GO bit not set\n");
  187. return -ETIMEDOUT;
  188. }
  189. /* Wait till the lock bit is set in PLL status */
  190. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
  191. DSSWARN("cannot lock PLL\n");
  192. DSSWARN("CFG1 0x%x\n",
  193. hdmi_read_reg(PLLCTRL_CFG1));
  194. DSSWARN("CFG2 0x%x\n",
  195. hdmi_read_reg(PLLCTRL_CFG2));
  196. DSSWARN("CFG4 0x%x\n",
  197. hdmi_read_reg(PLLCTRL_CFG4));
  198. return -ETIMEDOUT;
  199. }
  200. DSSDBG("PLL locked!\n");
  201. return 0;
  202. }
  203. /* PHY_PWR_CMD */
  204. static int hdmi_set_phy_pwr(enum hdmi_phy_pwr val)
  205. {
  206. /* Command for power control of HDMI PHY */
  207. REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 7, 6);
  208. /* Status of the power control of HDMI PHY */
  209. if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
  210. DSSERR("Failed to set PHY power mode to %d\n", val);
  211. return -ETIMEDOUT;
  212. }
  213. return 0;
  214. }
  215. /* PLL_PWR_CMD */
  216. static int hdmi_set_pll_pwr(enum hdmi_pll_pwr val)
  217. {
  218. /* Command for power control of HDMI PLL */
  219. REG_FLD_MOD(HDMI_WP_PWR_CTRL, val, 3, 2);
  220. /* wait till PHY_PWR_STATUS is set */
  221. if (hdmi_wait_for_bit_change(HDMI_WP_PWR_CTRL, 1, 0, val) != val) {
  222. DSSERR("Failed to set PHY_PWR_STATUS\n");
  223. return -ETIMEDOUT;
  224. }
  225. return 0;
  226. }
  227. static int hdmi_pll_reset(void)
  228. {
  229. /* SYSRESET controlled by power FSM */
  230. REG_FLD_MOD(PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
  231. /* READ 0x0 reset is in progress */
  232. if (hdmi_wait_for_bit_change(PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
  233. DSSERR("Failed to sysreset PLL\n");
  234. return -ETIMEDOUT;
  235. }
  236. return 0;
  237. }
  238. static int hdmi_phy_init(void)
  239. {
  240. u16 r = 0;
  241. r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_LDOON);
  242. if (r)
  243. return r;
  244. r = hdmi_set_phy_pwr(HDMI_PHYPWRCMD_TXON);
  245. if (r)
  246. return r;
  247. /*
  248. * Read address 0 in order to get the SCP reset done completed
  249. * Dummy access performed to make sure reset is done
  250. */
  251. hdmi_read_reg(HDMI_TXPHY_TX_CTRL);
  252. /*
  253. * Write to phy address 0 to configure the clock
  254. * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
  255. */
  256. REG_FLD_MOD(HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
  257. /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
  258. hdmi_write_reg(HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
  259. /* Setup max LDO voltage */
  260. REG_FLD_MOD(HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
  261. /* Write to phy address 3 to change the polarity control */
  262. REG_FLD_MOD(HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
  263. return 0;
  264. }
  265. static int hdmi_wait_softreset(void)
  266. {
  267. /* reset W1 */
  268. REG_FLD_MOD(HDMI_WP_SYSCONFIG, 0x1, 0, 0);
  269. /* wait till SOFTRESET == 0 */
  270. if (hdmi_wait_for_bit_change(HDMI_WP_SYSCONFIG, 0, 0, 0) != 0) {
  271. DSSERR("sysconfig reset failed\n");
  272. return -ETIMEDOUT;
  273. }
  274. return 0;
  275. }
  276. static int hdmi_pll_program(struct hdmi_pll_info *fmt)
  277. {
  278. u16 r = 0;
  279. enum hdmi_clk_refsel refsel;
  280. /* wait for wrapper reset */
  281. r = hdmi_wait_softreset();
  282. if (r)
  283. return r;
  284. r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
  285. if (r)
  286. return r;
  287. r = hdmi_set_pll_pwr(HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
  288. if (r)
  289. return r;
  290. r = hdmi_pll_reset();
  291. if (r)
  292. return r;
  293. refsel = HDMI_REFSEL_SYSCLK;
  294. r = hdmi_pll_init(refsel, fmt->dcofreq, fmt, fmt->regsd);
  295. if (r)
  296. return r;
  297. return 0;
  298. }
  299. static void hdmi_phy_off(void)
  300. {
  301. hdmi_set_phy_pwr(HDMI_PHYPWRCMD_OFF);
  302. }
  303. static int hdmi_core_ddc_edid(u8 *pedid, int ext)
  304. {
  305. u32 i, j;
  306. char checksum = 0;
  307. u32 offset = 0;
  308. /* Turn on CLK for DDC */
  309. REG_FLD_MOD(HDMI_CORE_AV_DPD, 0x7, 2, 0);
  310. /*
  311. * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
  312. * right shifted values( The behavior is not consistent and seen only
  313. * with some TV's)
  314. */
  315. usleep_range(800, 1000);
  316. if (!ext) {
  317. /* Clk SCL Devices */
  318. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  319. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  320. if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
  321. 4, 4, 0) != 0) {
  322. DSSERR("Failed to program DDC\n");
  323. return -ETIMEDOUT;
  324. }
  325. /* Clear FIFO */
  326. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  327. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  328. if (hdmi_wait_for_bit_change(HDMI_CORE_DDC_STATUS,
  329. 4, 4, 0) != 0) {
  330. DSSERR("Failed to program DDC\n");
  331. return -ETIMEDOUT;
  332. }
  333. } else {
  334. if (ext % 2 != 0)
  335. offset = 0x80;
  336. }
  337. /* Load Segment Address Register */
  338. REG_FLD_MOD(HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
  339. /* Load Slave Address Register */
  340. REG_FLD_MOD(HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  341. /* Load Offset Address Register */
  342. REG_FLD_MOD(HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  343. /* Load Byte Count */
  344. REG_FLD_MOD(HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  345. REG_FLD_MOD(HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  346. /* Set DDC_CMD */
  347. if (ext)
  348. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  349. else
  350. REG_FLD_MOD(HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  351. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  352. if (REG_GET(HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  353. DSSWARN("I2C Bus Low?\n");
  354. return -EIO;
  355. }
  356. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  357. if (REG_GET(HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  358. DSSWARN("I2C No Ack\n");
  359. return -EIO;
  360. }
  361. i = ext * 128;
  362. j = 0;
  363. while (((REG_GET(HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
  364. (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0)) &&
  365. j < 128) {
  366. if (REG_GET(HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
  367. /* FIFO not empty */
  368. pedid[i++] = REG_GET(HDMI_CORE_DDC_DATA, 7, 0);
  369. j++;
  370. }
  371. }
  372. for (j = 0; j < 128; j++)
  373. checksum += pedid[j];
  374. if (checksum != 0) {
  375. DSSERR("E-EDID checksum failed!!\n");
  376. return -EIO;
  377. }
  378. return 0;
  379. }
  380. static int read_edid(u8 *pedid, u16 max_length)
  381. {
  382. int r = 0, n = 0, i = 0;
  383. int max_ext_blocks = (max_length / 128) - 1;
  384. r = hdmi_core_ddc_edid(pedid, 0);
  385. if (r) {
  386. return r;
  387. } else {
  388. n = pedid[0x7e];
  389. /*
  390. * README: need to comply with max_length set by the caller.
  391. * Better implementation should be to allocate necessary
  392. * memory to store EDID according to nb_block field found
  393. * in first block
  394. */
  395. if (n > max_ext_blocks)
  396. n = max_ext_blocks;
  397. for (i = 1; i <= n; i++) {
  398. r = hdmi_core_ddc_edid(pedid, i);
  399. if (r)
  400. return r;
  401. }
  402. }
  403. return 0;
  404. }
  405. static int get_timings_index(void)
  406. {
  407. int code;
  408. if (hdmi.mode == 0)
  409. code = code_vesa[hdmi.code];
  410. else
  411. code = code_cea[hdmi.code];
  412. if (code == -1) {
  413. /* HDMI code 4 corresponds to 640 * 480 VGA */
  414. hdmi.code = 4;
  415. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  416. hdmi.mode = HDMI_DVI;
  417. code = code_vesa[hdmi.code];
  418. }
  419. return code;
  420. }
  421. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  422. {
  423. int i = 0, code = -1, temp_vsync = 0, temp_hsync = 0;
  424. int timing_vsync = 0, timing_hsync = 0;
  425. struct omap_video_timings temp;
  426. struct hdmi_cm cm = {-1};
  427. DSSDBG("hdmi_get_code\n");
  428. for (i = 0; i < OMAP_HDMI_TIMINGS_NB; i++) {
  429. temp = cea_vesa_timings[i].timings;
  430. if ((temp.pixel_clock == timing->pixel_clock) &&
  431. (temp.x_res == timing->x_res) &&
  432. (temp.y_res == timing->y_res)) {
  433. temp_hsync = temp.hfp + temp.hsw + temp.hbp;
  434. timing_hsync = timing->hfp + timing->hsw + timing->hbp;
  435. temp_vsync = temp.vfp + temp.vsw + temp.vbp;
  436. timing_vsync = timing->vfp + timing->vsw + timing->vbp;
  437. DSSDBG("temp_hsync = %d , temp_vsync = %d"
  438. "timing_hsync = %d, timing_vsync = %d\n",
  439. temp_hsync, temp_hsync,
  440. timing_hsync, timing_vsync);
  441. if ((temp_hsync == timing_hsync) &&
  442. (temp_vsync == timing_vsync)) {
  443. code = i;
  444. cm.code = code_index[i];
  445. if (code < 14)
  446. cm.mode = HDMI_HDMI;
  447. else
  448. cm.mode = HDMI_DVI;
  449. DSSDBG("Hdmi_code = %d mode = %d\n",
  450. cm.code, cm.mode);
  451. break;
  452. }
  453. }
  454. }
  455. return cm;
  456. }
  457. static void get_horz_vert_timing_info(int current_descriptor_addrs, u8 *edid ,
  458. struct omap_video_timings *timings)
  459. {
  460. /* X and Y resolution */
  461. timings->x_res = (((edid[current_descriptor_addrs + 4] & 0xF0) << 4) |
  462. edid[current_descriptor_addrs + 2]);
  463. timings->y_res = (((edid[current_descriptor_addrs + 7] & 0xF0) << 4) |
  464. edid[current_descriptor_addrs + 5]);
  465. timings->pixel_clock = ((edid[current_descriptor_addrs + 1] << 8) |
  466. edid[current_descriptor_addrs]);
  467. timings->pixel_clock = 10 * timings->pixel_clock;
  468. /* HORIZONTAL FRONT PORCH */
  469. timings->hfp = edid[current_descriptor_addrs + 8] |
  470. ((edid[current_descriptor_addrs + 11] & 0xc0) << 2);
  471. /* HORIZONTAL SYNC WIDTH */
  472. timings->hsw = edid[current_descriptor_addrs + 9] |
  473. ((edid[current_descriptor_addrs + 11] & 0x30) << 4);
  474. /* HORIZONTAL BACK PORCH */
  475. timings->hbp = (((edid[current_descriptor_addrs + 4] & 0x0F) << 8) |
  476. edid[current_descriptor_addrs + 3]) -
  477. (timings->hfp + timings->hsw);
  478. /* VERTICAL FRONT PORCH */
  479. timings->vfp = ((edid[current_descriptor_addrs + 10] & 0xF0) >> 4) |
  480. ((edid[current_descriptor_addrs + 11] & 0x0f) << 2);
  481. /* VERTICAL SYNC WIDTH */
  482. timings->vsw = (edid[current_descriptor_addrs + 10] & 0x0F) |
  483. ((edid[current_descriptor_addrs + 11] & 0x03) << 4);
  484. /* VERTICAL BACK PORCH */
  485. timings->vbp = (((edid[current_descriptor_addrs + 7] & 0x0F) << 8) |
  486. edid[current_descriptor_addrs + 6]) -
  487. (timings->vfp + timings->vsw);
  488. }
  489. /* Description : This function gets the resolution information from EDID */
  490. static void get_edid_timing_data(u8 *edid)
  491. {
  492. u8 count;
  493. u16 current_descriptor_addrs;
  494. struct hdmi_cm cm;
  495. struct omap_video_timings edid_timings;
  496. /* search block 0, there are 4 DTDs arranged in priority order */
  497. for (count = 0; count < EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR; count++) {
  498. current_descriptor_addrs =
  499. EDID_DESCRIPTOR_BLOCK0_ADDRESS +
  500. count * EDID_TIMING_DESCRIPTOR_SIZE;
  501. get_horz_vert_timing_info(current_descriptor_addrs,
  502. edid, &edid_timings);
  503. cm = hdmi_get_code(&edid_timings);
  504. DSSDBG("Block0[%d] value matches code = %d , mode = %d\n",
  505. count, cm.code, cm.mode);
  506. if (cm.code == -1) {
  507. continue;
  508. } else {
  509. hdmi.code = cm.code;
  510. hdmi.mode = cm.mode;
  511. DSSDBG("code = %d , mode = %d\n",
  512. hdmi.code, hdmi.mode);
  513. return;
  514. }
  515. }
  516. if (edid[0x7e] != 0x00) {
  517. for (count = 0; count < EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR;
  518. count++) {
  519. current_descriptor_addrs =
  520. EDID_DESCRIPTOR_BLOCK1_ADDRESS +
  521. count * EDID_TIMING_DESCRIPTOR_SIZE;
  522. get_horz_vert_timing_info(current_descriptor_addrs,
  523. edid, &edid_timings);
  524. cm = hdmi_get_code(&edid_timings);
  525. DSSDBG("Block1[%d] value matches code = %d, mode = %d",
  526. count, cm.code, cm.mode);
  527. if (cm.code == -1) {
  528. continue;
  529. } else {
  530. hdmi.code = cm.code;
  531. hdmi.mode = cm.mode;
  532. DSSDBG("code = %d , mode = %d\n",
  533. hdmi.code, hdmi.mode);
  534. return;
  535. }
  536. }
  537. }
  538. DSSINFO("no valid timing found , falling back to VGA\n");
  539. hdmi.code = 4; /* setting default value of 640 480 VGA */
  540. hdmi.mode = HDMI_DVI;
  541. }
  542. static void hdmi_read_edid(struct omap_video_timings *dp)
  543. {
  544. int ret = 0, code;
  545. memset(hdmi.edid, 0, HDMI_EDID_MAX_LENGTH);
  546. if (!hdmi.edid_set)
  547. ret = read_edid(hdmi.edid, HDMI_EDID_MAX_LENGTH);
  548. if (!ret) {
  549. if (!memcmp(hdmi.edid, edid_header, sizeof(edid_header))) {
  550. /* search for timings of default resolution */
  551. get_edid_timing_data(hdmi.edid);
  552. hdmi.edid_set = true;
  553. }
  554. } else {
  555. DSSWARN("failed to read E-EDID\n");
  556. }
  557. if (!hdmi.edid_set) {
  558. DSSINFO("fallback to VGA\n");
  559. hdmi.code = 4; /* setting default value of 640 480 VGA */
  560. hdmi.mode = HDMI_DVI;
  561. }
  562. code = get_timings_index();
  563. *dp = cea_vesa_timings[code].timings;
  564. }
  565. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  566. struct hdmi_core_infoframe_avi *avi_cfg,
  567. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  568. {
  569. DSSDBG("Enter hdmi_core_init\n");
  570. /* video core */
  571. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  572. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  573. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  574. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  575. video_cfg->hdmi_dvi = HDMI_DVI;
  576. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  577. /* info frame */
  578. avi_cfg->db1_format = 0;
  579. avi_cfg->db1_active_info = 0;
  580. avi_cfg->db1_bar_info_dv = 0;
  581. avi_cfg->db1_scan_info = 0;
  582. avi_cfg->db2_colorimetry = 0;
  583. avi_cfg->db2_aspect_ratio = 0;
  584. avi_cfg->db2_active_fmt_ar = 0;
  585. avi_cfg->db3_itc = 0;
  586. avi_cfg->db3_ec = 0;
  587. avi_cfg->db3_q_range = 0;
  588. avi_cfg->db3_nup_scaling = 0;
  589. avi_cfg->db4_videocode = 0;
  590. avi_cfg->db5_pixel_repeat = 0;
  591. avi_cfg->db6_7_line_eoftop = 0 ;
  592. avi_cfg->db8_9_line_sofbottom = 0;
  593. avi_cfg->db10_11_pixel_eofleft = 0;
  594. avi_cfg->db12_13_pixel_sofright = 0;
  595. /* packet enable and repeat */
  596. repeat_cfg->audio_pkt = 0;
  597. repeat_cfg->audio_pkt_repeat = 0;
  598. repeat_cfg->avi_infoframe = 0;
  599. repeat_cfg->avi_infoframe_repeat = 0;
  600. repeat_cfg->gen_cntrl_pkt = 0;
  601. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  602. repeat_cfg->generic_pkt = 0;
  603. repeat_cfg->generic_pkt_repeat = 0;
  604. }
  605. static void hdmi_core_powerdown_disable(void)
  606. {
  607. DSSDBG("Enter hdmi_core_powerdown_disable\n");
  608. REG_FLD_MOD(HDMI_CORE_CTRL1, 0x0, 0, 0);
  609. }
  610. static void hdmi_core_swreset_release(void)
  611. {
  612. DSSDBG("Enter hdmi_core_swreset_release\n");
  613. REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  614. }
  615. static void hdmi_core_swreset_assert(void)
  616. {
  617. DSSDBG("Enter hdmi_core_swreset_assert\n");
  618. REG_FLD_MOD(HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  619. }
  620. /* DSS_HDMI_CORE_VIDEO_CONFIG */
  621. static void hdmi_core_video_config(struct hdmi_core_video_config *cfg)
  622. {
  623. u32 r = 0;
  624. /* sys_ctrl1 default configuration not tunable */
  625. r = hdmi_read_reg(HDMI_CORE_CTRL1);
  626. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  627. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  628. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  629. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  630. hdmi_write_reg(HDMI_CORE_CTRL1, r);
  631. REG_FLD_MOD(HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  632. /* Vid_Mode */
  633. r = hdmi_read_reg(HDMI_CORE_SYS_VID_MODE);
  634. /* dither truncation configuration */
  635. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  636. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  637. r = FLD_MOD(r, 1, 5, 5);
  638. } else {
  639. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  640. r = FLD_MOD(r, 0, 5, 5);
  641. }
  642. hdmi_write_reg(HDMI_CORE_SYS_VID_MODE, r);
  643. /* HDMI_Ctrl */
  644. r = hdmi_read_reg(HDMI_CORE_AV_HDMI_CTRL);
  645. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  646. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  647. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  648. hdmi_write_reg(HDMI_CORE_AV_HDMI_CTRL, r);
  649. /* TMDS_CTRL */
  650. REG_FLD_MOD(HDMI_CORE_SYS_TMDS_CTRL,
  651. cfg->tclk_sel_clkmult, 6, 5);
  652. }
  653. static void hdmi_core_aux_infoframe_avi_config(
  654. struct hdmi_core_infoframe_avi info_avi)
  655. {
  656. u32 val;
  657. char sum = 0, checksum = 0;
  658. sum += 0x82 + 0x002 + 0x00D;
  659. hdmi_write_reg(HDMI_CORE_AV_AVI_TYPE, 0x082);
  660. hdmi_write_reg(HDMI_CORE_AV_AVI_VERS, 0x002);
  661. hdmi_write_reg(HDMI_CORE_AV_AVI_LEN, 0x00D);
  662. val = (info_avi.db1_format << 5) |
  663. (info_avi.db1_active_info << 4) |
  664. (info_avi.db1_bar_info_dv << 2) |
  665. (info_avi.db1_scan_info);
  666. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(0), val);
  667. sum += val;
  668. val = (info_avi.db2_colorimetry << 6) |
  669. (info_avi.db2_aspect_ratio << 4) |
  670. (info_avi.db2_active_fmt_ar);
  671. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(1), val);
  672. sum += val;
  673. val = (info_avi.db3_itc << 7) |
  674. (info_avi.db3_ec << 4) |
  675. (info_avi.db3_q_range << 2) |
  676. (info_avi.db3_nup_scaling);
  677. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(2), val);
  678. sum += val;
  679. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(3), info_avi.db4_videocode);
  680. sum += info_avi.db4_videocode;
  681. val = info_avi.db5_pixel_repeat;
  682. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(4), val);
  683. sum += val;
  684. val = info_avi.db6_7_line_eoftop & 0x00FF;
  685. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(5), val);
  686. sum += val;
  687. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  688. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(6), val);
  689. sum += val;
  690. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  691. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(7), val);
  692. sum += val;
  693. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  694. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(8), val);
  695. sum += val;
  696. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  697. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(9), val);
  698. sum += val;
  699. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  700. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(10), val);
  701. sum += val;
  702. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  703. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(11), val);
  704. sum += val;
  705. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  706. hdmi_write_reg(HDMI_CORE_AV_AVI_DBYTE(12), val);
  707. sum += val;
  708. checksum = 0x100 - sum;
  709. hdmi_write_reg(HDMI_CORE_AV_AVI_CHSUM, checksum);
  710. }
  711. static void hdmi_core_av_packet_config(
  712. struct hdmi_core_packet_enable_repeat repeat_cfg)
  713. {
  714. /* enable/repeat the infoframe */
  715. hdmi_write_reg(HDMI_CORE_AV_PB_CTRL1,
  716. (repeat_cfg.audio_pkt << 5) |
  717. (repeat_cfg.audio_pkt_repeat << 4) |
  718. (repeat_cfg.avi_infoframe << 1) |
  719. (repeat_cfg.avi_infoframe_repeat));
  720. /* enable/repeat the packet */
  721. hdmi_write_reg(HDMI_CORE_AV_PB_CTRL2,
  722. (repeat_cfg.gen_cntrl_pkt << 3) |
  723. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  724. (repeat_cfg.generic_pkt << 1) |
  725. (repeat_cfg.generic_pkt_repeat));
  726. }
  727. static void hdmi_wp_init(struct omap_video_timings *timings,
  728. struct hdmi_video_format *video_fmt,
  729. struct hdmi_video_interface *video_int)
  730. {
  731. DSSDBG("Enter hdmi_wp_init\n");
  732. timings->hbp = 0;
  733. timings->hfp = 0;
  734. timings->hsw = 0;
  735. timings->vbp = 0;
  736. timings->vfp = 0;
  737. timings->vsw = 0;
  738. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  739. video_fmt->y_res = 0;
  740. video_fmt->x_res = 0;
  741. video_int->vsp = 0;
  742. video_int->hsp = 0;
  743. video_int->interlacing = 0;
  744. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  745. }
  746. static void hdmi_wp_video_start(bool start)
  747. {
  748. REG_FLD_MOD(HDMI_WP_VIDEO_CFG, start, 31, 31);
  749. }
  750. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  751. struct omap_video_timings *timings, struct hdmi_config *param)
  752. {
  753. DSSDBG("Enter hdmi_wp_video_init_format\n");
  754. video_fmt->y_res = param->timings.timings.y_res;
  755. video_fmt->x_res = param->timings.timings.x_res;
  756. timings->hbp = param->timings.timings.hbp;
  757. timings->hfp = param->timings.timings.hfp;
  758. timings->hsw = param->timings.timings.hsw;
  759. timings->vbp = param->timings.timings.vbp;
  760. timings->vfp = param->timings.timings.vfp;
  761. timings->vsw = param->timings.timings.vsw;
  762. }
  763. static void hdmi_wp_video_config_format(
  764. struct hdmi_video_format *video_fmt)
  765. {
  766. u32 l = 0;
  767. REG_FLD_MOD(HDMI_WP_VIDEO_CFG, video_fmt->packing_mode, 10, 8);
  768. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  769. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  770. hdmi_write_reg(HDMI_WP_VIDEO_SIZE, l);
  771. }
  772. static void hdmi_wp_video_config_interface(
  773. struct hdmi_video_interface *video_int)
  774. {
  775. u32 r;
  776. DSSDBG("Enter hdmi_wp_video_config_interface\n");
  777. r = hdmi_read_reg(HDMI_WP_VIDEO_CFG);
  778. r = FLD_MOD(r, video_int->vsp, 7, 7);
  779. r = FLD_MOD(r, video_int->hsp, 6, 6);
  780. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  781. r = FLD_MOD(r, video_int->tm, 1, 0);
  782. hdmi_write_reg(HDMI_WP_VIDEO_CFG, r);
  783. }
  784. static void hdmi_wp_video_config_timing(
  785. struct omap_video_timings *timings)
  786. {
  787. u32 timing_h = 0;
  788. u32 timing_v = 0;
  789. DSSDBG("Enter hdmi_wp_video_config_timing\n");
  790. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  791. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  792. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  793. hdmi_write_reg(HDMI_WP_VIDEO_TIMING_H, timing_h);
  794. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  795. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  796. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  797. hdmi_write_reg(HDMI_WP_VIDEO_TIMING_V, timing_v);
  798. }
  799. static void hdmi_basic_configure(struct hdmi_config *cfg)
  800. {
  801. /* HDMI */
  802. struct omap_video_timings video_timing;
  803. struct hdmi_video_format video_format;
  804. struct hdmi_video_interface video_interface;
  805. /* HDMI core */
  806. struct hdmi_core_infoframe_avi avi_cfg;
  807. struct hdmi_core_video_config v_core_cfg;
  808. struct hdmi_core_packet_enable_repeat repeat_cfg;
  809. hdmi_wp_init(&video_timing, &video_format,
  810. &video_interface);
  811. hdmi_core_init(&v_core_cfg,
  812. &avi_cfg,
  813. &repeat_cfg);
  814. hdmi_wp_video_init_format(&video_format,
  815. &video_timing, cfg);
  816. hdmi_wp_video_config_timing(&video_timing);
  817. /* video config */
  818. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  819. hdmi_wp_video_config_format(&video_format);
  820. video_interface.vsp = cfg->timings.vsync_pol;
  821. video_interface.hsp = cfg->timings.hsync_pol;
  822. video_interface.interlacing = cfg->interlace;
  823. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  824. hdmi_wp_video_config_interface(&video_interface);
  825. /*
  826. * configure core video part
  827. * set software reset in the core
  828. */
  829. hdmi_core_swreset_assert();
  830. /* power down off */
  831. hdmi_core_powerdown_disable();
  832. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  833. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  834. hdmi_core_video_config(&v_core_cfg);
  835. /* release software reset in the core */
  836. hdmi_core_swreset_release();
  837. /*
  838. * configure packet
  839. * info frame video see doc CEA861-D page 65
  840. */
  841. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  842. avi_cfg.db1_active_info =
  843. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  844. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  845. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  846. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  847. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  848. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  849. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  850. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  851. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  852. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  853. avi_cfg.db4_videocode = cfg->cm.code;
  854. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  855. avi_cfg.db6_7_line_eoftop = 0;
  856. avi_cfg.db8_9_line_sofbottom = 0;
  857. avi_cfg.db10_11_pixel_eofleft = 0;
  858. avi_cfg.db12_13_pixel_sofright = 0;
  859. hdmi_core_aux_infoframe_avi_config(avi_cfg);
  860. /* enable/repeat the infoframe */
  861. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  862. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  863. /* wakeup */
  864. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  865. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  866. hdmi_core_av_packet_config(repeat_cfg);
  867. }
  868. static void update_hdmi_timings(struct hdmi_config *cfg,
  869. struct omap_video_timings *timings, int code)
  870. {
  871. cfg->timings.timings.x_res = timings->x_res;
  872. cfg->timings.timings.y_res = timings->y_res;
  873. cfg->timings.timings.hbp = timings->hbp;
  874. cfg->timings.timings.hfp = timings->hfp;
  875. cfg->timings.timings.hsw = timings->hsw;
  876. cfg->timings.timings.vbp = timings->vbp;
  877. cfg->timings.timings.vfp = timings->vfp;
  878. cfg->timings.timings.vsw = timings->vsw;
  879. cfg->timings.timings.pixel_clock = timings->pixel_clock;
  880. cfg->timings.vsync_pol = cea_vesa_timings[code].vsync_pol;
  881. cfg->timings.hsync_pol = cea_vesa_timings[code].hsync_pol;
  882. }
  883. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  884. struct hdmi_pll_info *pi)
  885. {
  886. unsigned long clkin, refclk;
  887. u32 mf;
  888. clkin = dss_clk_get_rate(DSS_CLK_SYSCK) / 10000;
  889. /*
  890. * Input clock is predivided by N + 1
  891. * out put of which is reference clk
  892. */
  893. pi->regn = dssdev->clocks.hdmi.regn;
  894. refclk = clkin / (pi->regn + 1);
  895. /*
  896. * multiplier is pixel_clk/ref_clk
  897. * Multiplying by 100 to avoid fractional part removal
  898. */
  899. pi->regm = (phy * 100 / (refclk)) / 100;
  900. pi->regm2 = dssdev->clocks.hdmi.regm2;
  901. /*
  902. * fractional multiplier is remainder of the difference between
  903. * multiplier and actual phy(required pixel clock thus should be
  904. * multiplied by 2^18(262144) divided by the reference clock
  905. */
  906. mf = (phy - pi->regm * refclk) * 262144;
  907. pi->regmf = mf / (refclk);
  908. /*
  909. * Dcofreq should be set to 1 if required pixel clock
  910. * is greater than 1000MHz
  911. */
  912. pi->dcofreq = phy > 1000 * 100;
  913. pi->regsd = ((pi->regm * clkin / 10) / ((pi->regn + 1) * 250) + 5) / 10;
  914. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  915. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  916. }
  917. static void hdmi_enable_clocks(int enable)
  918. {
  919. if (enable)
  920. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK |
  921. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  922. else
  923. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK |
  924. DSS_CLK_SYSCK | DSS_CLK_VIDFCK);
  925. }
  926. static int hdmi_power_on(struct omap_dss_device *dssdev)
  927. {
  928. int r, code = 0;
  929. struct hdmi_pll_info pll_data;
  930. struct omap_video_timings *p;
  931. unsigned long phy;
  932. hdmi_enable_clocks(1);
  933. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  934. p = &dssdev->panel.timings;
  935. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  936. dssdev->panel.timings.x_res,
  937. dssdev->panel.timings.y_res);
  938. if (!hdmi.custom_set) {
  939. DSSDBG("Read EDID as no EDID is not set on poweron\n");
  940. hdmi_read_edid(p);
  941. }
  942. code = get_timings_index();
  943. dssdev->panel.timings = cea_vesa_timings[code].timings;
  944. update_hdmi_timings(&hdmi.cfg, p, code);
  945. phy = p->pixel_clock;
  946. hdmi_compute_pll(dssdev, phy, &pll_data);
  947. hdmi_wp_video_start(0);
  948. /* config the PLL and PHY first */
  949. r = hdmi_pll_program(&pll_data);
  950. if (r) {
  951. DSSDBG("Failed to lock PLL\n");
  952. goto err;
  953. }
  954. r = hdmi_phy_init();
  955. if (r) {
  956. DSSDBG("Failed to start PHY\n");
  957. goto err;
  958. }
  959. hdmi.cfg.cm.mode = hdmi.mode;
  960. hdmi.cfg.cm.code = hdmi.code;
  961. hdmi_basic_configure(&hdmi.cfg);
  962. /* Make selection of HDMI in DSS */
  963. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  964. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  965. * DSI PLL source as the clock selected by DSI PLL might not be
  966. * sufficient for the resolution selected / that can be changed
  967. * dynamically by user. This can be moved to single location , say
  968. * Boardfile.
  969. */
  970. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  971. /* bypass TV gamma table */
  972. dispc_enable_gamma_table(0);
  973. /* tv size */
  974. dispc_set_digit_size(dssdev->panel.timings.x_res,
  975. dssdev->panel.timings.y_res);
  976. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 1);
  977. hdmi_wp_video_start(1);
  978. return 0;
  979. err:
  980. hdmi_enable_clocks(0);
  981. return -EIO;
  982. }
  983. static void hdmi_power_off(struct omap_dss_device *dssdev)
  984. {
  985. dispc_enable_channel(OMAP_DSS_CHANNEL_DIGIT, 0);
  986. hdmi_wp_video_start(0);
  987. hdmi_phy_off();
  988. hdmi_set_pll_pwr(HDMI_PLLPWRCMD_ALLOFF);
  989. hdmi_enable_clocks(0);
  990. hdmi.edid_set = 0;
  991. }
  992. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  993. struct omap_video_timings *timings)
  994. {
  995. struct hdmi_cm cm;
  996. cm = hdmi_get_code(timings);
  997. if (cm.code == -1) {
  998. DSSERR("Invalid timing entered\n");
  999. return -EINVAL;
  1000. }
  1001. return 0;
  1002. }
  1003. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  1004. {
  1005. struct hdmi_cm cm;
  1006. hdmi.custom_set = 1;
  1007. cm = hdmi_get_code(&dssdev->panel.timings);
  1008. hdmi.code = cm.code;
  1009. hdmi.mode = cm.mode;
  1010. omapdss_hdmi_display_enable(dssdev);
  1011. hdmi.custom_set = 0;
  1012. }
  1013. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  1014. {
  1015. int r = 0;
  1016. DSSDBG("ENTER hdmi_display_enable\n");
  1017. mutex_lock(&hdmi.lock);
  1018. r = omap_dss_start_device(dssdev);
  1019. if (r) {
  1020. DSSERR("failed to start device\n");
  1021. goto err0;
  1022. }
  1023. if (dssdev->platform_enable) {
  1024. r = dssdev->platform_enable(dssdev);
  1025. if (r) {
  1026. DSSERR("failed to enable GPIO's\n");
  1027. goto err1;
  1028. }
  1029. }
  1030. r = hdmi_power_on(dssdev);
  1031. if (r) {
  1032. DSSERR("failed to power on device\n");
  1033. goto err2;
  1034. }
  1035. mutex_unlock(&hdmi.lock);
  1036. return 0;
  1037. err2:
  1038. if (dssdev->platform_disable)
  1039. dssdev->platform_disable(dssdev);
  1040. err1:
  1041. omap_dss_stop_device(dssdev);
  1042. err0:
  1043. mutex_unlock(&hdmi.lock);
  1044. return r;
  1045. }
  1046. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  1047. {
  1048. DSSDBG("Enter hdmi_display_disable\n");
  1049. mutex_lock(&hdmi.lock);
  1050. hdmi_power_off(dssdev);
  1051. if (dssdev->platform_disable)
  1052. dssdev->platform_disable(dssdev);
  1053. omap_dss_stop_device(dssdev);
  1054. mutex_unlock(&hdmi.lock);
  1055. }
  1056. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1057. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1058. static void hdmi_wp_audio_config_format(
  1059. struct hdmi_audio_format *aud_fmt)
  1060. {
  1061. u32 r;
  1062. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  1063. r = hdmi_read_reg(HDMI_WP_AUDIO_CFG);
  1064. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  1065. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  1066. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  1067. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  1068. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  1069. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  1070. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  1071. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  1072. hdmi_write_reg(HDMI_WP_AUDIO_CFG, r);
  1073. }
  1074. static void hdmi_wp_audio_config_dma(struct hdmi_audio_dma *aud_dma)
  1075. {
  1076. u32 r;
  1077. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  1078. r = hdmi_read_reg(HDMI_WP_AUDIO_CFG2);
  1079. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  1080. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  1081. hdmi_write_reg(HDMI_WP_AUDIO_CFG2, r);
  1082. r = hdmi_read_reg(HDMI_WP_AUDIO_CTRL);
  1083. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  1084. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  1085. hdmi_write_reg(HDMI_WP_AUDIO_CTRL, r);
  1086. }
  1087. static void hdmi_core_audio_config(struct hdmi_core_audio_config *cfg)
  1088. {
  1089. u32 r;
  1090. /* audio clock recovery parameters */
  1091. r = hdmi_read_reg(HDMI_CORE_AV_ACR_CTRL);
  1092. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  1093. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  1094. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  1095. hdmi_write_reg(HDMI_CORE_AV_ACR_CTRL, r);
  1096. REG_FLD_MOD(HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  1097. REG_FLD_MOD(HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  1098. REG_FLD_MOD(HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  1099. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  1100. REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  1101. REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  1102. REG_FLD_MOD(HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  1103. } else {
  1104. /*
  1105. * HDMI IP uses this configuration to divide the MCLK to
  1106. * update CTS value.
  1107. */
  1108. REG_FLD_MOD(HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  1109. /* Configure clock for audio packets */
  1110. REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  1111. cfg->aud_par_busclk, 7, 0);
  1112. REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  1113. (cfg->aud_par_busclk >> 8), 7, 0);
  1114. REG_FLD_MOD(HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  1115. (cfg->aud_par_busclk >> 16), 7, 0);
  1116. }
  1117. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  1118. REG_FLD_MOD(HDMI_CORE_AV_SPDIF_CTRL, cfg->fs_override, 1, 1);
  1119. /* I2S parameters */
  1120. REG_FLD_MOD(HDMI_CORE_AV_I2S_CHST4, cfg->freq_sample, 3, 0);
  1121. r = hdmi_read_reg(HDMI_CORE_AV_I2S_IN_CTRL);
  1122. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  1123. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  1124. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  1125. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  1126. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  1127. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  1128. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  1129. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  1130. hdmi_write_reg(HDMI_CORE_AV_I2S_IN_CTRL, r);
  1131. r = hdmi_read_reg(HDMI_CORE_AV_I2S_CHST5);
  1132. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  1133. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  1134. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  1135. hdmi_write_reg(HDMI_CORE_AV_I2S_CHST5, r);
  1136. REG_FLD_MOD(HDMI_CORE_AV_I2S_IN_LEN, cfg->i2s_cfg.in_length_bits, 3, 0);
  1137. /* Audio channels and mode parameters */
  1138. REG_FLD_MOD(HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  1139. r = hdmi_read_reg(HDMI_CORE_AV_AUD_MODE);
  1140. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  1141. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  1142. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  1143. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  1144. hdmi_write_reg(HDMI_CORE_AV_AUD_MODE, r);
  1145. }
  1146. static void hdmi_core_audio_infoframe_config(
  1147. struct hdmi_core_infoframe_audio *info_aud)
  1148. {
  1149. u8 val;
  1150. u8 sum = 0, checksum = 0;
  1151. /*
  1152. * Set audio info frame type, version and length as
  1153. * described in HDMI 1.4a Section 8.2.2 specification.
  1154. * Checksum calculation is defined in Section 5.3.5.
  1155. */
  1156. hdmi_write_reg(HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  1157. hdmi_write_reg(HDMI_CORE_AV_AUDIO_VERS, 0x01);
  1158. hdmi_write_reg(HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  1159. sum += 0x84 + 0x001 + 0x00a;
  1160. val = (info_aud->db1_coding_type << 4)
  1161. | (info_aud->db1_channel_count - 1);
  1162. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(0), val);
  1163. sum += val;
  1164. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  1165. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(1), val);
  1166. sum += val;
  1167. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  1168. val = info_aud->db4_channel_alloc;
  1169. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(3), val);
  1170. sum += val;
  1171. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  1172. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(4), val);
  1173. sum += val;
  1174. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  1175. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  1176. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  1177. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  1178. hdmi_write_reg(HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  1179. checksum = 0x100 - sum;
  1180. hdmi_write_reg(HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  1181. /*
  1182. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  1183. * is available.
  1184. */
  1185. }
  1186. static int hdmi_config_audio_acr(u32 sample_freq, u32 *n, u32 *cts)
  1187. {
  1188. u32 r;
  1189. u32 deep_color = 0;
  1190. u32 pclk = hdmi.cfg.timings.timings.pixel_clock;
  1191. if (n == NULL || cts == NULL)
  1192. return -EINVAL;
  1193. /*
  1194. * Obtain current deep color configuration. This needed
  1195. * to calculate the TMDS clock based on the pixel clock.
  1196. */
  1197. r = REG_GET(HDMI_WP_VIDEO_CFG, 1, 0);
  1198. switch (r) {
  1199. case 1: /* No deep color selected */
  1200. deep_color = 100;
  1201. break;
  1202. case 2: /* 10-bit deep color selected */
  1203. deep_color = 125;
  1204. break;
  1205. case 3: /* 12-bit deep color selected */
  1206. deep_color = 150;
  1207. break;
  1208. default:
  1209. return -EINVAL;
  1210. }
  1211. switch (sample_freq) {
  1212. case 32000:
  1213. if ((deep_color == 125) && ((pclk == 54054)
  1214. || (pclk == 74250)))
  1215. *n = 8192;
  1216. else
  1217. *n = 4096;
  1218. break;
  1219. case 44100:
  1220. *n = 6272;
  1221. break;
  1222. case 48000:
  1223. if ((deep_color == 125) && ((pclk == 54054)
  1224. || (pclk == 74250)))
  1225. *n = 8192;
  1226. else
  1227. *n = 6144;
  1228. break;
  1229. default:
  1230. *n = 0;
  1231. return -EINVAL;
  1232. }
  1233. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  1234. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  1235. return 0;
  1236. }
  1237. static int hdmi_audio_hw_params(struct snd_pcm_substream *substream,
  1238. struct snd_pcm_hw_params *params,
  1239. struct snd_soc_dai *dai)
  1240. {
  1241. struct hdmi_audio_format audio_format;
  1242. struct hdmi_audio_dma audio_dma;
  1243. struct hdmi_core_audio_config core_cfg;
  1244. struct hdmi_core_infoframe_audio aud_if_cfg;
  1245. int err, n, cts;
  1246. enum hdmi_core_audio_sample_freq sample_freq;
  1247. switch (params_format(params)) {
  1248. case SNDRV_PCM_FORMAT_S16_LE:
  1249. core_cfg.i2s_cfg.word_max_length =
  1250. HDMI_AUDIO_I2S_MAX_WORD_20BITS;
  1251. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_16_BITS;
  1252. core_cfg.i2s_cfg.in_length_bits =
  1253. HDMI_AUDIO_I2S_INPUT_LENGTH_16;
  1254. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  1255. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
  1256. audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
  1257. audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  1258. audio_dma.transfer_size = 0x10;
  1259. break;
  1260. case SNDRV_PCM_FORMAT_S24_LE:
  1261. core_cfg.i2s_cfg.word_max_length =
  1262. HDMI_AUDIO_I2S_MAX_WORD_24BITS;
  1263. core_cfg.i2s_cfg.word_length = HDMI_AUDIO_I2S_CHST_WORD_24_BITS;
  1264. core_cfg.i2s_cfg.in_length_bits =
  1265. HDMI_AUDIO_I2S_INPUT_LENGTH_24;
  1266. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
  1267. audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
  1268. audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  1269. core_cfg.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  1270. audio_dma.transfer_size = 0x20;
  1271. break;
  1272. default:
  1273. return -EINVAL;
  1274. }
  1275. switch (params_rate(params)) {
  1276. case 32000:
  1277. sample_freq = HDMI_AUDIO_FS_32000;
  1278. break;
  1279. case 44100:
  1280. sample_freq = HDMI_AUDIO_FS_44100;
  1281. break;
  1282. case 48000:
  1283. sample_freq = HDMI_AUDIO_FS_48000;
  1284. break;
  1285. default:
  1286. return -EINVAL;
  1287. }
  1288. err = hdmi_config_audio_acr(params_rate(params), &n, &cts);
  1289. if (err < 0)
  1290. return err;
  1291. /* Audio wrapper config */
  1292. audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
  1293. audio_format.active_chnnls_msk = 0x03;
  1294. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  1295. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  1296. /* Disable start/stop signals of IEC 60958 blocks */
  1297. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_OFF;
  1298. audio_dma.block_size = 0xC0;
  1299. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  1300. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  1301. hdmi_wp_audio_config_dma(&audio_dma);
  1302. hdmi_wp_audio_config_format(&audio_format);
  1303. /*
  1304. * I2S config
  1305. */
  1306. core_cfg.i2s_cfg.en_high_bitrate_aud = false;
  1307. /* Only used with high bitrate audio */
  1308. core_cfg.i2s_cfg.cbit_order = false;
  1309. /* Serial data and word select should change on sck rising edge */
  1310. core_cfg.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
  1311. core_cfg.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
  1312. /* Set I2S word select polarity */
  1313. core_cfg.i2s_cfg.ws_polarity = HDMI_AUDIO_I2S_WS_POLARITY_LOW_IS_LEFT;
  1314. core_cfg.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
  1315. /* Set serial data to word select shift. See Phillips spec. */
  1316. core_cfg.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
  1317. /* Enable one of the four available serial data channels */
  1318. core_cfg.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
  1319. /* Core audio config */
  1320. core_cfg.freq_sample = sample_freq;
  1321. core_cfg.n = n;
  1322. core_cfg.cts = cts;
  1323. if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
  1324. core_cfg.aud_par_busclk = 0;
  1325. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
  1326. core_cfg.use_mclk = false;
  1327. } else {
  1328. core_cfg.aud_par_busclk = (((128 * 31) - 1) << 8);
  1329. core_cfg.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
  1330. core_cfg.use_mclk = true;
  1331. core_cfg.mclk_mode = HDMI_AUDIO_MCLK_128FS;
  1332. }
  1333. core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
  1334. core_cfg.en_spdif = false;
  1335. /* Use sample frequency from channel status word */
  1336. core_cfg.fs_override = true;
  1337. /* Enable ACR packets */
  1338. core_cfg.en_acr_pkt = true;
  1339. /* Disable direct streaming digital audio */
  1340. core_cfg.en_dsd_audio = false;
  1341. /* Use parallel audio interface */
  1342. core_cfg.en_parallel_aud_input = true;
  1343. hdmi_core_audio_config(&core_cfg);
  1344. /*
  1345. * Configure packet
  1346. * info frame audio see doc CEA861-D page 74
  1347. */
  1348. aud_if_cfg.db1_coding_type = HDMI_INFOFRAME_AUDIO_DB1CT_FROM_STREAM;
  1349. aud_if_cfg.db1_channel_count = 2;
  1350. aud_if_cfg.db2_sample_freq = HDMI_INFOFRAME_AUDIO_DB2SF_FROM_STREAM;
  1351. aud_if_cfg.db2_sample_size = HDMI_INFOFRAME_AUDIO_DB2SS_FROM_STREAM;
  1352. aud_if_cfg.db4_channel_alloc = 0x00;
  1353. aud_if_cfg.db5_downmix_inh = false;
  1354. aud_if_cfg.db5_lsv = 0;
  1355. hdmi_core_audio_infoframe_config(&aud_if_cfg);
  1356. return 0;
  1357. }
  1358. static int hdmi_audio_trigger(struct snd_pcm_substream *substream, int cmd,
  1359. struct snd_soc_dai *dai)
  1360. {
  1361. int err = 0;
  1362. switch (cmd) {
  1363. case SNDRV_PCM_TRIGGER_START:
  1364. case SNDRV_PCM_TRIGGER_RESUME:
  1365. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1366. REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  1367. REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  1368. REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  1369. break;
  1370. case SNDRV_PCM_TRIGGER_STOP:
  1371. case SNDRV_PCM_TRIGGER_SUSPEND:
  1372. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1373. REG_FLD_MOD(HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  1374. REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  1375. REG_FLD_MOD(HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  1376. break;
  1377. default:
  1378. err = -EINVAL;
  1379. }
  1380. return err;
  1381. }
  1382. static int hdmi_audio_startup(struct snd_pcm_substream *substream,
  1383. struct snd_soc_dai *dai)
  1384. {
  1385. if (!hdmi.mode) {
  1386. pr_err("Current video settings do not support audio.\n");
  1387. return -EIO;
  1388. }
  1389. return 0;
  1390. }
  1391. static struct snd_soc_codec_driver hdmi_audio_codec_drv = {
  1392. };
  1393. static struct snd_soc_dai_ops hdmi_audio_codec_ops = {
  1394. .hw_params = hdmi_audio_hw_params,
  1395. .trigger = hdmi_audio_trigger,
  1396. .startup = hdmi_audio_startup,
  1397. };
  1398. static struct snd_soc_dai_driver hdmi_codec_dai_drv = {
  1399. .name = "hdmi-audio-codec",
  1400. .playback = {
  1401. .channels_min = 2,
  1402. .channels_max = 2,
  1403. .rates = SNDRV_PCM_RATE_32000 |
  1404. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  1405. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  1406. SNDRV_PCM_FMTBIT_S24_LE,
  1407. },
  1408. .ops = &hdmi_audio_codec_ops,
  1409. };
  1410. #endif
  1411. /* HDMI HW IP initialisation */
  1412. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  1413. {
  1414. struct resource *hdmi_mem;
  1415. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1416. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1417. int ret;
  1418. #endif
  1419. hdmi.pdata = pdev->dev.platform_data;
  1420. hdmi.pdev = pdev;
  1421. mutex_init(&hdmi.lock);
  1422. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  1423. if (!hdmi_mem) {
  1424. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  1425. return -EINVAL;
  1426. }
  1427. /* Base address taken from platform */
  1428. hdmi.base_wp = ioremap(hdmi_mem->start, resource_size(hdmi_mem));
  1429. if (!hdmi.base_wp) {
  1430. DSSERR("can't ioremap WP\n");
  1431. return -ENOMEM;
  1432. }
  1433. hdmi_panel_init();
  1434. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1435. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1436. /* Register ASoC codec DAI */
  1437. ret = snd_soc_register_codec(&pdev->dev, &hdmi_audio_codec_drv,
  1438. &hdmi_codec_dai_drv, 1);
  1439. if (ret) {
  1440. DSSERR("can't register ASoC HDMI audio codec\n");
  1441. return ret;
  1442. }
  1443. #endif
  1444. return 0;
  1445. }
  1446. static int omapdss_hdmihw_remove(struct platform_device *pdev)
  1447. {
  1448. hdmi_panel_exit();
  1449. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  1450. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  1451. snd_soc_unregister_codec(&pdev->dev);
  1452. #endif
  1453. iounmap(hdmi.base_wp);
  1454. return 0;
  1455. }
  1456. static struct platform_driver omapdss_hdmihw_driver = {
  1457. .probe = omapdss_hdmihw_probe,
  1458. .remove = omapdss_hdmihw_remove,
  1459. .driver = {
  1460. .name = "omapdss_hdmi",
  1461. .owner = THIS_MODULE,
  1462. },
  1463. };
  1464. int hdmi_init_platform_driver(void)
  1465. {
  1466. return platform_driver_register(&omapdss_hdmihw_driver);
  1467. }
  1468. void hdmi_uninit_platform_driver(void)
  1469. {
  1470. return platform_driver_unregister(&omapdss_hdmihw_driver);
  1471. }