hdmi.c 47 KB

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