hdmi.c 48 KB

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