hdmi.c 48 KB

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