hdmi5_core.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /*
  2. * OMAP5 HDMI CORE IP driver library
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated
  5. *
  6. * Authors:
  7. * Yong Zhi
  8. * Mythri pk
  9. * Archit Taneja <archit@ti.com>
  10. * Tomi Valkeinen <tomi.valkeinen@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published by
  14. * the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  19. * more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along with
  22. * this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/err.h>
  27. #include <linux/io.h>
  28. #include <linux/delay.h>
  29. #include <linux/string.h>
  30. #include <linux/seq_file.h>
  31. #include <drm/drm_edid.h>
  32. #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
  33. #include <sound/asound.h>
  34. #include <sound/asoundef.h>
  35. #endif
  36. #include "hdmi5_core.h"
  37. /* only 24 bit color depth used for now */
  38. static const struct csc_table csc_table_deepcolor[] = {
  39. /* HDMI_DEEP_COLOR_24BIT */
  40. [0] = { 7036, 0, 0, 32, 0, 7036, 0, 32, 0, 0, 7036, 32, },
  41. /* HDMI_DEEP_COLOR_30BIT */
  42. [1] = { 7015, 0, 0, 128, 0, 7015, 0, 128, 0, 0, 7015, 128, },
  43. /* HDMI_DEEP_COLOR_36BIT */
  44. [2] = { 7010, 0, 0, 512, 0, 7010, 0, 512, 0, 0, 7010, 512, },
  45. /* FULL RANGE */
  46. [3] = { 8192, 0, 0, 0, 0, 8192, 0, 0, 0, 0, 8192, 0, },
  47. };
  48. static void hdmi_core_ddc_init(struct hdmi_core_data *core)
  49. {
  50. void __iomem *base = core->base;
  51. const unsigned long long iclk = 266000000; /* DSS L3 ICLK */
  52. const unsigned ss_scl_high = 4000; /* ns */
  53. const unsigned ss_scl_low = 4700; /* ns */
  54. const unsigned fs_scl_high = 600; /* ns */
  55. const unsigned fs_scl_low = 1300; /* ns */
  56. const unsigned sda_hold = 300; /* ns */
  57. const unsigned sfr_div = 10;
  58. unsigned long long sfr;
  59. unsigned v;
  60. sfr = iclk / sfr_div; /* SFR_DIV */
  61. sfr /= 1000; /* SFR clock in kHz */
  62. /* Reset */
  63. REG_FLD_MOD(base, HDMI_CORE_I2CM_SOFTRSTZ, 0, 0, 0);
  64. if (hdmi_wait_for_bit_change(base, HDMI_CORE_I2CM_SOFTRSTZ,
  65. 0, 0, 1) != 1)
  66. DSSERR("HDMI I2CM reset failed\n");
  67. /* Standard (0) or Fast (1) Mode */
  68. REG_FLD_MOD(base, HDMI_CORE_I2CM_DIV, 0, 3, 3);
  69. /* Standard Mode SCL High counter */
  70. v = DIV_ROUND_UP_ULL(ss_scl_high * sfr, 1000000);
  71. REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_HCNT_1_ADDR,
  72. (v >> 8) & 0xff, 7, 0);
  73. REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_HCNT_0_ADDR,
  74. v & 0xff, 7, 0);
  75. /* Standard Mode SCL Low counter */
  76. v = DIV_ROUND_UP_ULL(ss_scl_low * sfr, 1000000);
  77. REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_LCNT_1_ADDR,
  78. (v >> 8) & 0xff, 7, 0);
  79. REG_FLD_MOD(base, HDMI_CORE_I2CM_SS_SCL_LCNT_0_ADDR,
  80. v & 0xff, 7, 0);
  81. /* Fast Mode SCL High Counter */
  82. v = DIV_ROUND_UP_ULL(fs_scl_high * sfr, 1000000);
  83. REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_HCNT_1_ADDR,
  84. (v >> 8) & 0xff, 7, 0);
  85. REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_HCNT_0_ADDR,
  86. v & 0xff, 7, 0);
  87. /* Fast Mode SCL Low Counter */
  88. v = DIV_ROUND_UP_ULL(fs_scl_low * sfr, 1000000);
  89. REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_LCNT_1_ADDR,
  90. (v >> 8) & 0xff, 7, 0);
  91. REG_FLD_MOD(base, HDMI_CORE_I2CM_FS_SCL_LCNT_0_ADDR,
  92. v & 0xff, 7, 0);
  93. /* SDA Hold Time */
  94. v = DIV_ROUND_UP_ULL(sda_hold * sfr, 1000000);
  95. REG_FLD_MOD(base, HDMI_CORE_I2CM_SDA_HOLD_ADDR, v & 0xff, 7, 0);
  96. REG_FLD_MOD(base, HDMI_CORE_I2CM_SLAVE, 0x50, 6, 0);
  97. REG_FLD_MOD(base, HDMI_CORE_I2CM_SEGADDR, 0x30, 6, 0);
  98. /* NACK_POL to high */
  99. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 7, 7);
  100. /* NACK_MASK to unmasked */
  101. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x0, 6, 6);
  102. /* ARBITRATION_POL to high */
  103. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 3, 3);
  104. /* ARBITRATION_MASK to unmasked */
  105. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x0, 2, 2);
  106. /* DONE_POL to high */
  107. REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 3, 3);
  108. /* DONE_MASK to unmasked */
  109. REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x0, 2, 2);
  110. }
  111. static void hdmi_core_ddc_uninit(struct hdmi_core_data *core)
  112. {
  113. void __iomem *base = core->base;
  114. /* Mask I2C interrupts */
  115. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 6, 6);
  116. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 2, 2);
  117. REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2);
  118. }
  119. static int hdmi_core_ddc_edid(struct hdmi_core_data *core, u8 *pedid, u8 ext)
  120. {
  121. void __iomem *base = core->base;
  122. u8 cur_addr;
  123. char checksum = 0;
  124. const int retries = 1000;
  125. u8 seg_ptr = ext / 2;
  126. u8 edidbase = ((ext % 2) * 0x80);
  127. REG_FLD_MOD(base, HDMI_CORE_I2CM_SEGPTR, seg_ptr, 7, 0);
  128. /*
  129. * TODO: We use polling here, although we probably should use proper
  130. * interrupts.
  131. */
  132. for (cur_addr = 0; cur_addr < 128; ++cur_addr) {
  133. int i;
  134. /* clear ERROR and DONE */
  135. REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0x3, 1, 0);
  136. REG_FLD_MOD(base, HDMI_CORE_I2CM_ADDRESS,
  137. edidbase + cur_addr, 7, 0);
  138. if (seg_ptr)
  139. REG_FLD_MOD(base, HDMI_CORE_I2CM_OPERATION, 1, 1, 1);
  140. else
  141. REG_FLD_MOD(base, HDMI_CORE_I2CM_OPERATION, 1, 0, 0);
  142. for (i = 0; i < retries; ++i) {
  143. u32 stat;
  144. stat = REG_GET(base, HDMI_CORE_IH_I2CM_STAT0, 1, 0);
  145. /* I2CM_ERROR */
  146. if (stat & 1) {
  147. DSSERR("HDMI I2C Master Error\n");
  148. return -EIO;
  149. }
  150. /* I2CM_DONE */
  151. if (stat & (1 << 1))
  152. break;
  153. usleep_range(250, 1000);
  154. }
  155. if (i == retries) {
  156. DSSERR("HDMI I2C timeout reading EDID\n");
  157. return -EIO;
  158. }
  159. pedid[cur_addr] = REG_GET(base, HDMI_CORE_I2CM_DATAI, 7, 0);
  160. checksum += pedid[cur_addr];
  161. }
  162. return 0;
  163. }
  164. int hdmi5_read_edid(struct hdmi_core_data *core, u8 *edid, int len)
  165. {
  166. int r, n, i;
  167. int max_ext_blocks = (len / 128) - 1;
  168. if (len < 128)
  169. return -EINVAL;
  170. hdmi_core_ddc_init(core);
  171. r = hdmi_core_ddc_edid(core, edid, 0);
  172. if (r)
  173. goto out;
  174. n = edid[0x7e];
  175. if (n > max_ext_blocks)
  176. n = max_ext_blocks;
  177. for (i = 1; i <= n; i++) {
  178. r = hdmi_core_ddc_edid(core, edid + i * EDID_LENGTH, i);
  179. if (r)
  180. goto out;
  181. }
  182. out:
  183. hdmi_core_ddc_uninit(core);
  184. return r ? r : len;
  185. }
  186. void hdmi5_core_dump(struct hdmi_core_data *core, struct seq_file *s)
  187. {
  188. #define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\
  189. hdmi_read_reg(core->base, r))
  190. DUMPCORE(HDMI_CORE_FC_INVIDCONF);
  191. DUMPCORE(HDMI_CORE_FC_INHACTIV0);
  192. DUMPCORE(HDMI_CORE_FC_INHACTIV1);
  193. DUMPCORE(HDMI_CORE_FC_INHBLANK0);
  194. DUMPCORE(HDMI_CORE_FC_INHBLANK1);
  195. DUMPCORE(HDMI_CORE_FC_INVACTIV0);
  196. DUMPCORE(HDMI_CORE_FC_INVACTIV1);
  197. DUMPCORE(HDMI_CORE_FC_INVBLANK);
  198. DUMPCORE(HDMI_CORE_FC_HSYNCINDELAY0);
  199. DUMPCORE(HDMI_CORE_FC_HSYNCINDELAY1);
  200. DUMPCORE(HDMI_CORE_FC_HSYNCINWIDTH0);
  201. DUMPCORE(HDMI_CORE_FC_HSYNCINWIDTH1);
  202. DUMPCORE(HDMI_CORE_FC_VSYNCINDELAY);
  203. DUMPCORE(HDMI_CORE_FC_VSYNCINWIDTH);
  204. DUMPCORE(HDMI_CORE_FC_CTRLDUR);
  205. DUMPCORE(HDMI_CORE_FC_EXCTRLDUR);
  206. DUMPCORE(HDMI_CORE_FC_EXCTRLSPAC);
  207. DUMPCORE(HDMI_CORE_FC_CH0PREAM);
  208. DUMPCORE(HDMI_CORE_FC_CH1PREAM);
  209. DUMPCORE(HDMI_CORE_FC_CH2PREAM);
  210. DUMPCORE(HDMI_CORE_FC_AVICONF0);
  211. DUMPCORE(HDMI_CORE_FC_AVICONF1);
  212. DUMPCORE(HDMI_CORE_FC_AVICONF2);
  213. DUMPCORE(HDMI_CORE_FC_AVIVID);
  214. DUMPCORE(HDMI_CORE_FC_PRCONF);
  215. DUMPCORE(HDMI_CORE_MC_CLKDIS);
  216. DUMPCORE(HDMI_CORE_MC_SWRSTZREQ);
  217. DUMPCORE(HDMI_CORE_MC_FLOWCTRL);
  218. DUMPCORE(HDMI_CORE_MC_PHYRSTZ);
  219. DUMPCORE(HDMI_CORE_MC_LOCKONCLOCK);
  220. DUMPCORE(HDMI_CORE_I2CM_SLAVE);
  221. DUMPCORE(HDMI_CORE_I2CM_ADDRESS);
  222. DUMPCORE(HDMI_CORE_I2CM_DATAO);
  223. DUMPCORE(HDMI_CORE_I2CM_DATAI);
  224. DUMPCORE(HDMI_CORE_I2CM_OPERATION);
  225. DUMPCORE(HDMI_CORE_I2CM_INT);
  226. DUMPCORE(HDMI_CORE_I2CM_CTLINT);
  227. DUMPCORE(HDMI_CORE_I2CM_DIV);
  228. DUMPCORE(HDMI_CORE_I2CM_SEGADDR);
  229. DUMPCORE(HDMI_CORE_I2CM_SOFTRSTZ);
  230. DUMPCORE(HDMI_CORE_I2CM_SEGPTR);
  231. DUMPCORE(HDMI_CORE_I2CM_SS_SCL_HCNT_1_ADDR);
  232. DUMPCORE(HDMI_CORE_I2CM_SS_SCL_HCNT_0_ADDR);
  233. DUMPCORE(HDMI_CORE_I2CM_SS_SCL_LCNT_1_ADDR);
  234. DUMPCORE(HDMI_CORE_I2CM_SS_SCL_LCNT_0_ADDR);
  235. DUMPCORE(HDMI_CORE_I2CM_FS_SCL_HCNT_1_ADDR);
  236. DUMPCORE(HDMI_CORE_I2CM_FS_SCL_HCNT_0_ADDR);
  237. DUMPCORE(HDMI_CORE_I2CM_FS_SCL_LCNT_1_ADDR);
  238. DUMPCORE(HDMI_CORE_I2CM_FS_SCL_LCNT_0_ADDR);
  239. DUMPCORE(HDMI_CORE_I2CM_SDA_HOLD_ADDR);
  240. }
  241. static void hdmi_core_init(struct hdmi_core_vid_config *video_cfg,
  242. struct hdmi_config *cfg)
  243. {
  244. DSSDBG("hdmi_core_init\n");
  245. /* video core */
  246. video_cfg->data_enable_pol = 1; /* It is always 1*/
  247. video_cfg->v_fc_config.timings.hsync_level = cfg->timings.hsync_level;
  248. video_cfg->v_fc_config.timings.x_res = cfg->timings.x_res;
  249. video_cfg->v_fc_config.timings.hsw = cfg->timings.hsw - 1;
  250. video_cfg->v_fc_config.timings.hbp = cfg->timings.hbp;
  251. video_cfg->v_fc_config.timings.hfp = cfg->timings.hfp;
  252. video_cfg->hblank = cfg->timings.hfp +
  253. cfg->timings.hbp + cfg->timings.hsw - 1;
  254. video_cfg->v_fc_config.timings.vsync_level = cfg->timings.vsync_level;
  255. video_cfg->v_fc_config.timings.y_res = cfg->timings.y_res;
  256. video_cfg->v_fc_config.timings.vsw = cfg->timings.vsw;
  257. video_cfg->v_fc_config.timings.vfp = cfg->timings.vfp;
  258. video_cfg->v_fc_config.timings.vbp = cfg->timings.vbp;
  259. video_cfg->vblank_osc = 0; /* Always 0 - need to confirm */
  260. video_cfg->vblank = cfg->timings.vsw +
  261. cfg->timings.vfp + cfg->timings.vbp;
  262. video_cfg->v_fc_config.hdmi_dvi_mode = cfg->hdmi_dvi_mode;
  263. video_cfg->v_fc_config.timings.interlace = cfg->timings.interlace;
  264. }
  265. /* DSS_HDMI_CORE_VIDEO_CONFIG */
  266. static void hdmi_core_video_config(struct hdmi_core_data *core,
  267. struct hdmi_core_vid_config *cfg)
  268. {
  269. void __iomem *base = core->base;
  270. unsigned char r = 0;
  271. bool vsync_pol, hsync_pol;
  272. vsync_pol =
  273. cfg->v_fc_config.timings.vsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  274. hsync_pol =
  275. cfg->v_fc_config.timings.hsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  276. /* Set hsync, vsync and data-enable polarity */
  277. r = hdmi_read_reg(base, HDMI_CORE_FC_INVIDCONF);
  278. r = FLD_MOD(r, vsync_pol, 6, 6);
  279. r = FLD_MOD(r, hsync_pol, 5, 5);
  280. r = FLD_MOD(r, cfg->data_enable_pol, 4, 4);
  281. r = FLD_MOD(r, cfg->vblank_osc, 1, 1);
  282. r = FLD_MOD(r, cfg->v_fc_config.timings.interlace, 0, 0);
  283. hdmi_write_reg(base, HDMI_CORE_FC_INVIDCONF, r);
  284. /* set x resolution */
  285. REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV1,
  286. cfg->v_fc_config.timings.x_res >> 8, 4, 0);
  287. REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV0,
  288. cfg->v_fc_config.timings.x_res & 0xFF, 7, 0);
  289. /* set y resolution */
  290. REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV1,
  291. cfg->v_fc_config.timings.y_res >> 8, 4, 0);
  292. REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV0,
  293. cfg->v_fc_config.timings.y_res & 0xFF, 7, 0);
  294. /* set horizontal blanking pixels */
  295. REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK1, cfg->hblank >> 8, 4, 0);
  296. REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK0, cfg->hblank & 0xFF, 7, 0);
  297. /* set vertial blanking pixels */
  298. REG_FLD_MOD(base, HDMI_CORE_FC_INVBLANK, cfg->vblank, 7, 0);
  299. /* set horizontal sync offset */
  300. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY1,
  301. cfg->v_fc_config.timings.hfp >> 8, 4, 0);
  302. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY0,
  303. cfg->v_fc_config.timings.hfp & 0xFF, 7, 0);
  304. /* set vertical sync offset */
  305. REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINDELAY,
  306. cfg->v_fc_config.timings.vfp, 7, 0);
  307. /* set horizontal sync pulse width */
  308. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH1,
  309. (cfg->v_fc_config.timings.hsw >> 8), 1, 0);
  310. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH0,
  311. cfg->v_fc_config.timings.hsw & 0xFF, 7, 0);
  312. /* set vertical sync pulse width */
  313. REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINWIDTH,
  314. cfg->v_fc_config.timings.vsw, 5, 0);
  315. /* select DVI mode */
  316. REG_FLD_MOD(base, HDMI_CORE_FC_INVIDCONF,
  317. cfg->v_fc_config.hdmi_dvi_mode, 3, 3);
  318. }
  319. static void hdmi_core_config_video_packetizer(struct hdmi_core_data *core)
  320. {
  321. void __iomem *base = core->base;
  322. int clr_depth = 0; /* 24 bit color depth */
  323. /* COLOR_DEPTH */
  324. REG_FLD_MOD(base, HDMI_CORE_VP_PR_CD, clr_depth, 7, 4);
  325. /* BYPASS_EN */
  326. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 1, 6, 6);
  327. /* PP_EN */
  328. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 1 : 0, 5, 5);
  329. /* YCC422_EN */
  330. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, 0, 3, 3);
  331. /* PP_STUFFING */
  332. REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, clr_depth ? 1 : 0, 1, 1);
  333. /* YCC422_STUFFING */
  334. REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, 1, 2, 2);
  335. /* OUTPUT_SELECTOR */
  336. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 2, 1, 0);
  337. }
  338. static void hdmi_core_config_csc(struct hdmi_core_data *core)
  339. {
  340. int clr_depth = 0; /* 24 bit color depth */
  341. /* CSC_COLORDEPTH */
  342. REG_FLD_MOD(core->base, HDMI_CORE_CSC_SCALE, clr_depth, 7, 4);
  343. }
  344. static void hdmi_core_config_video_sampler(struct hdmi_core_data *core)
  345. {
  346. int video_mapping = 1; /* for 24 bit color depth */
  347. /* VIDEO_MAPPING */
  348. REG_FLD_MOD(core->base, HDMI_CORE_TX_INVID0, video_mapping, 4, 0);
  349. }
  350. static void hdmi_core_write_avi_infoframe(struct hdmi_core_data *core,
  351. struct hdmi_avi_infoframe *frame)
  352. {
  353. void __iomem *base = core->base;
  354. u8 data[HDMI_INFOFRAME_SIZE(AVI)];
  355. u8 *ptr;
  356. unsigned y, a, b, s;
  357. unsigned c, m, r;
  358. unsigned itc, ec, q, sc;
  359. unsigned vic;
  360. unsigned yq, cn, pr;
  361. hdmi_avi_infoframe_pack(frame, data, sizeof(data));
  362. print_hex_dump_debug("AVI: ", DUMP_PREFIX_NONE, 16, 1, data,
  363. HDMI_INFOFRAME_SIZE(AVI), false);
  364. ptr = data + HDMI_INFOFRAME_HEADER_SIZE;
  365. y = (ptr[0] >> 5) & 0x3;
  366. a = (ptr[0] >> 4) & 0x1;
  367. b = (ptr[0] >> 2) & 0x3;
  368. s = (ptr[0] >> 0) & 0x3;
  369. c = (ptr[1] >> 6) & 0x3;
  370. m = (ptr[1] >> 4) & 0x3;
  371. r = (ptr[1] >> 0) & 0x3;
  372. itc = (ptr[2] >> 7) & 0x1;
  373. ec = (ptr[2] >> 4) & 0x7;
  374. q = (ptr[2] >> 2) & 0x3;
  375. sc = (ptr[2] >> 0) & 0x3;
  376. vic = ptr[3];
  377. yq = (ptr[4] >> 6) & 0x3;
  378. cn = (ptr[4] >> 4) & 0x3;
  379. pr = (ptr[4] >> 0) & 0xf;
  380. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF0,
  381. (a << 6) | (s << 4) | (b << 2) | (y << 0));
  382. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF1,
  383. (c << 6) | (m << 4) | (r << 0));
  384. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF2,
  385. (itc << 7) | (ec << 4) | (q << 2) | (sc << 0));
  386. hdmi_write_reg(base, HDMI_CORE_FC_AVIVID, vic);
  387. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF3,
  388. (yq << 2) | (cn << 0));
  389. REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, pr, 3, 0);
  390. }
  391. static void hdmi_core_csc_config(struct hdmi_core_data *core,
  392. struct csc_table csc_coeff)
  393. {
  394. void __iomem *base = core->base;
  395. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_MSB, csc_coeff.a1 >> 8 , 6, 0);
  396. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_LSB, csc_coeff.a1, 7, 0);
  397. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_MSB, csc_coeff.a2 >> 8, 6, 0);
  398. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_LSB, csc_coeff.a2, 7, 0);
  399. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_MSB, csc_coeff.a3 >> 8, 6, 0);
  400. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_LSB, csc_coeff.a3, 7, 0);
  401. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_MSB, csc_coeff.a4 >> 8, 6, 0);
  402. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_LSB, csc_coeff.a4, 7, 0);
  403. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_MSB, csc_coeff.b1 >> 8, 6, 0);
  404. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_LSB, csc_coeff.b1, 7, 0);
  405. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_MSB, csc_coeff.b2 >> 8, 6, 0);
  406. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_LSB, csc_coeff.b2, 7, 0);
  407. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_MSB, csc_coeff.b3 >> 8, 6, 0);
  408. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_LSB, csc_coeff.b3, 7, 0);
  409. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_MSB, csc_coeff.b4 >> 8, 6, 0);
  410. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_LSB, csc_coeff.b4, 7, 0);
  411. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_MSB, csc_coeff.c1 >> 8, 6, 0);
  412. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_LSB, csc_coeff.c1, 7, 0);
  413. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_MSB, csc_coeff.c2 >> 8, 6, 0);
  414. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_LSB, csc_coeff.c2, 7, 0);
  415. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_MSB, csc_coeff.c3 >> 8, 6, 0);
  416. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_LSB, csc_coeff.c3, 7, 0);
  417. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_MSB, csc_coeff.c4 >> 8, 6, 0);
  418. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_LSB, csc_coeff.c4, 7, 0);
  419. REG_FLD_MOD(base, HDMI_CORE_MC_FLOWCTRL, 0x1, 0, 0);
  420. }
  421. static void hdmi_core_configure_range(struct hdmi_core_data *core)
  422. {
  423. struct csc_table csc_coeff = { 0 };
  424. /* support limited range with 24 bit color depth for now */
  425. csc_coeff = csc_table_deepcolor[0];
  426. hdmi_core_csc_config(core, csc_coeff);
  427. }
  428. static void hdmi_core_enable_video_path(struct hdmi_core_data *core)
  429. {
  430. void __iomem *base = core->base;
  431. DSSDBG("hdmi_core_enable_video_path\n");
  432. REG_FLD_MOD(base, HDMI_CORE_FC_CTRLDUR, 0x0C, 7, 0);
  433. REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLDUR, 0x20, 7, 0);
  434. REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLSPAC, 0x01, 7, 0);
  435. REG_FLD_MOD(base, HDMI_CORE_FC_CH0PREAM, 0x0B, 7, 0);
  436. REG_FLD_MOD(base, HDMI_CORE_FC_CH1PREAM, 0x16, 5, 0);
  437. REG_FLD_MOD(base, HDMI_CORE_FC_CH2PREAM, 0x21, 5, 0);
  438. REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 0, 0);
  439. REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 1, 1);
  440. }
  441. static void hdmi_core_mask_interrupts(struct hdmi_core_data *core)
  442. {
  443. void __iomem *base = core->base;
  444. /* Master IRQ mask */
  445. REG_FLD_MOD(base, HDMI_CORE_IH_MUTE, 0x3, 1, 0);
  446. /* Mask all the interrupts in HDMI core */
  447. REG_FLD_MOD(base, HDMI_CORE_VP_MASK, 0xff, 7, 0);
  448. REG_FLD_MOD(base, HDMI_CORE_FC_MASK0, 0xe7, 7, 0);
  449. REG_FLD_MOD(base, HDMI_CORE_FC_MASK1, 0xfb, 7, 0);
  450. REG_FLD_MOD(base, HDMI_CORE_FC_MASK2, 0x3, 1, 0);
  451. REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 0x3, 3, 2);
  452. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 0x3, 1, 0);
  453. REG_FLD_MOD(base, HDMI_CORE_CEC_MASK, 0x7f, 6, 0);
  454. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 6, 6);
  455. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 2, 2);
  456. REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2);
  457. REG_FLD_MOD(base, HDMI_CORE_PHY_MASK0, 0xf3, 7, 0);
  458. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  459. /* Clear all the current interrupt bits */
  460. REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0);
  461. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xe7, 7, 0);
  462. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xfb, 7, 0);
  463. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0x3, 1, 0);
  464. REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0x7, 2, 0);
  465. REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0x7f, 6, 0);
  466. REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0x3, 1, 0);
  467. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  468. }
  469. static void hdmi_core_enable_interrupts(struct hdmi_core_data *core)
  470. {
  471. /* Unmute interrupts */
  472. REG_FLD_MOD(core->base, HDMI_CORE_IH_MUTE, 0x0, 1, 0);
  473. }
  474. int hdmi5_core_handle_irqs(struct hdmi_core_data *core)
  475. {
  476. void __iomem *base = core->base;
  477. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xff, 7, 0);
  478. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xff, 7, 0);
  479. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0xff, 7, 0);
  480. REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0xff, 7, 0);
  481. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  482. REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0xff, 7, 0);
  483. REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0xff, 7, 0);
  484. REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0);
  485. REG_FLD_MOD(base, HDMI_CORE_IH_I2CMPHY_STAT0, 0xff, 7, 0);
  486. return 0;
  487. }
  488. void hdmi5_configure(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
  489. struct hdmi_config *cfg)
  490. {
  491. struct omap_video_timings video_timing;
  492. struct hdmi_video_format video_format;
  493. struct hdmi_core_vid_config v_core_cfg;
  494. hdmi_core_mask_interrupts(core);
  495. hdmi_core_init(&v_core_cfg, cfg);
  496. hdmi_wp_init_vid_fmt_timings(&video_format, &video_timing, cfg);
  497. hdmi_wp_video_config_timing(wp, &video_timing);
  498. /* video config */
  499. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  500. hdmi_wp_video_config_format(wp, &video_format);
  501. hdmi_wp_video_config_interface(wp, &video_timing);
  502. /* support limited range with 24 bit color depth for now */
  503. hdmi_core_configure_range(core);
  504. cfg->infoframe.quantization_range = HDMI_QUANTIZATION_RANGE_LIMITED;
  505. /*
  506. * configure core video part, set software reset in the core
  507. */
  508. v_core_cfg.packet_mode = HDMI_PACKETMODE24BITPERPIXEL;
  509. hdmi_core_video_config(core, &v_core_cfg);
  510. hdmi_core_config_video_packetizer(core);
  511. hdmi_core_config_csc(core);
  512. hdmi_core_config_video_sampler(core);
  513. if (cfg->hdmi_dvi_mode == HDMI_HDMI)
  514. hdmi_core_write_avi_infoframe(core, &cfg->infoframe);
  515. hdmi_core_enable_video_path(core);
  516. hdmi_core_enable_interrupts(core);
  517. }
  518. #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
  519. static void hdmi5_core_audio_config(struct hdmi_core_data *core,
  520. struct hdmi_core_audio_config *cfg)
  521. {
  522. void __iomem *base = core->base;
  523. u8 val;
  524. /* Mute audio before configuring */
  525. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0xf, 7, 4);
  526. /* Set the N parameter */
  527. REG_FLD_MOD(base, HDMI_CORE_AUD_N1, cfg->n, 7, 0);
  528. REG_FLD_MOD(base, HDMI_CORE_AUD_N2, cfg->n >> 8, 7, 0);
  529. REG_FLD_MOD(base, HDMI_CORE_AUD_N3, cfg->n >> 16, 3, 0);
  530. /*
  531. * CTS manual mode. Automatic mode is not supported when using audio
  532. * parallel interface.
  533. */
  534. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, 1, 4, 4);
  535. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS1, cfg->cts, 7, 0);
  536. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS2, cfg->cts >> 8, 7, 0);
  537. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, cfg->cts >> 16, 3, 0);
  538. /* Layout of Audio Sample Packets: 2-channel or multichannels */
  539. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH)
  540. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0, 0, 0);
  541. else
  542. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 1, 0, 0);
  543. /* Configure IEC-609580 Validity bits */
  544. /* Channel 0 is valid */
  545. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 0, 0);
  546. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 4, 4);
  547. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH)
  548. val = 1;
  549. else
  550. val = 0;
  551. /* Channels 1, 2 setting */
  552. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 1, 1);
  553. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 5, 5);
  554. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 2, 2);
  555. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 6, 6);
  556. /* Channel 3 setting */
  557. if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH)
  558. val = 1;
  559. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 3, 3);
  560. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 7, 7);
  561. /* Configure IEC-60958 User bits */
  562. /* TODO: should be set by user. */
  563. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSU, 0, 7, 0);
  564. /* Configure IEC-60958 Channel Status word */
  565. /* CGMSA */
  566. val = cfg->iec60958_cfg->status[5] & IEC958_AES5_CON_CGMSA;
  567. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 5, 4);
  568. /* Copyright */
  569. val = (cfg->iec60958_cfg->status[0] &
  570. IEC958_AES0_CON_NOT_COPYRIGHT) >> 2;
  571. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 0, 0);
  572. /* Category */
  573. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(1),
  574. cfg->iec60958_cfg->status[1]);
  575. /* PCM audio mode */
  576. val = (cfg->iec60958_cfg->status[0] & IEC958_AES0_CON_MODE) >> 6;
  577. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 6, 4);
  578. /* Source number */
  579. val = cfg->iec60958_cfg->status[2] & IEC958_AES2_CON_SOURCE;
  580. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 3, 4);
  581. /* Channel number right 0 */
  582. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 2, 3, 0);
  583. /* Channel number right 1*/
  584. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 4, 7, 4);
  585. /* Channel number right 2 */
  586. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 6, 3, 0);
  587. /* Channel number right 3*/
  588. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 8, 7, 4);
  589. /* Channel number left 0 */
  590. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 1, 3, 0);
  591. /* Channel number left 1*/
  592. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 3, 7, 4);
  593. /* Channel number left 2 */
  594. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 5, 3, 0);
  595. /* Channel number left 3*/
  596. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 7, 7, 4);
  597. /* Clock accuracy and sample rate */
  598. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(7),
  599. cfg->iec60958_cfg->status[3]);
  600. /* Original sample rate and word length */
  601. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(8),
  602. cfg->iec60958_cfg->status[4]);
  603. /* Enable FIFO empty and full interrupts */
  604. REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 3, 3, 2);
  605. /* Configure GPA */
  606. /* select HBR/SPDIF interfaces */
  607. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH) {
  608. /* select HBR/SPDIF interfaces */
  609. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  610. /* enable two channels in GPA */
  611. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 3, 7, 0);
  612. } else if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH) {
  613. /* select HBR/SPDIF interfaces */
  614. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  615. /* enable six channels in GPA */
  616. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0x3F, 7, 0);
  617. } else {
  618. /* select HBR/SPDIF interfaces */
  619. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  620. /* enable eight channels in GPA */
  621. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0xFF, 7, 0);
  622. }
  623. /* disable HBR */
  624. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 0, 0, 0);
  625. /* enable PCUV */
  626. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 1, 1, 1);
  627. /* enable GPA FIFO full and empty mask */
  628. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 3, 1, 0);
  629. /* set polarity of GPA FIFO empty interrupts */
  630. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_POL, 1, 0, 0);
  631. /* unmute audio */
  632. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0, 7, 4);
  633. }
  634. static void hdmi5_core_audio_infoframe_cfg(struct hdmi_core_data *core,
  635. struct snd_cea_861_aud_if *info_aud)
  636. {
  637. void __iomem *base = core->base;
  638. /* channel count and coding type fields in AUDICONF0 are swapped */
  639. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF0,
  640. (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC) << 4 |
  641. (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CT) >> 4);
  642. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF1, info_aud->db2_sf_ss);
  643. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF2, info_aud->db4_ca);
  644. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF3, info_aud->db5_dminh_lsv);
  645. }
  646. int hdmi5_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
  647. struct omap_dss_audio *audio, u32 pclk)
  648. {
  649. struct hdmi_audio_format audio_format;
  650. struct hdmi_audio_dma audio_dma;
  651. struct hdmi_core_audio_config core_cfg;
  652. int err, n, cts, channel_count;
  653. unsigned int fs_nr;
  654. bool word_length_16b = false;
  655. if (!audio || !audio->iec || !audio->cea || !core)
  656. return -EINVAL;
  657. core_cfg.iec60958_cfg = audio->iec;
  658. if (!(audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24) &&
  659. (audio->iec->status[4] & IEC958_AES4_CON_WORDLEN_20_16))
  660. word_length_16b = true;
  661. /* only 16-bit word length supported atm */
  662. if (!word_length_16b)
  663. return -EINVAL;
  664. switch (audio->iec->status[3] & IEC958_AES3_CON_FS) {
  665. case IEC958_AES3_CON_FS_32000:
  666. fs_nr = 32000;
  667. break;
  668. case IEC958_AES3_CON_FS_44100:
  669. fs_nr = 44100;
  670. break;
  671. case IEC958_AES3_CON_FS_48000:
  672. fs_nr = 48000;
  673. break;
  674. case IEC958_AES3_CON_FS_88200:
  675. fs_nr = 88200;
  676. break;
  677. case IEC958_AES3_CON_FS_96000:
  678. fs_nr = 96000;
  679. break;
  680. case IEC958_AES3_CON_FS_176400:
  681. fs_nr = 176400;
  682. break;
  683. case IEC958_AES3_CON_FS_192000:
  684. fs_nr = 192000;
  685. break;
  686. default:
  687. return -EINVAL;
  688. }
  689. err = hdmi_compute_acr(pclk, fs_nr, &n, &cts);
  690. core_cfg.n = n;
  691. core_cfg.cts = cts;
  692. /* Audio channels settings */
  693. channel_count = (audio->cea->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC)
  694. + 1;
  695. if (channel_count == 2)
  696. core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
  697. else if (channel_count == 6)
  698. core_cfg.layout = HDMI_AUDIO_LAYOUT_6CH;
  699. else
  700. core_cfg.layout = HDMI_AUDIO_LAYOUT_8CH;
  701. /* DMA settings */
  702. if (word_length_16b)
  703. audio_dma.transfer_size = 0x10;
  704. else
  705. audio_dma.transfer_size = 0x20;
  706. audio_dma.block_size = 0xC0;
  707. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  708. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  709. /* audio FIFO format settings for 16-bit samples*/
  710. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
  711. audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
  712. audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  713. /* only LPCM atm */
  714. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  715. /* disable start/stop signals of IEC 60958 blocks */
  716. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_ON;
  717. /* configure DMA and audio FIFO format*/
  718. hdmi_wp_audio_config_dma(wp, &audio_dma);
  719. hdmi_wp_audio_config_format(wp, &audio_format);
  720. /* configure the core */
  721. hdmi5_core_audio_config(core, &core_cfg);
  722. /* configure CEA 861 audio infoframe */
  723. hdmi5_core_audio_infoframe_cfg(core, audio->cea);
  724. return 0;
  725. }
  726. #endif
  727. int hdmi5_core_init(struct platform_device *pdev, struct hdmi_core_data *core)
  728. {
  729. struct resource *res;
  730. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
  731. if (!res) {
  732. DSSERR("can't get CORE IORESOURCE_MEM HDMI\n");
  733. return -EINVAL;
  734. }
  735. core->base = devm_ioremap_resource(&pdev->dev, res);
  736. if (IS_ERR(core->base)) {
  737. DSSERR("can't ioremap HDMI core\n");
  738. return PTR_ERR(core->base);
  739. }
  740. return 0;
  741. }