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