hdmi5_core.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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 = 4600; /* ns */
  51. const unsigned ss_scl_low = 5400; /* 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_cfg->v_fc_config.timings = cfg->timings;
  244. /* video core */
  245. video_cfg->data_enable_pol = 1; /* It is always 1*/
  246. video_cfg->hblank = cfg->timings.hfp +
  247. cfg->timings.hbp + cfg->timings.hsw;
  248. video_cfg->vblank_osc = 0;
  249. video_cfg->vblank = cfg->timings.vsw +
  250. cfg->timings.vfp + cfg->timings.vbp;
  251. video_cfg->v_fc_config.hdmi_dvi_mode = cfg->hdmi_dvi_mode;
  252. if (cfg->timings.interlace) {
  253. /* set vblank_osc if vblank is fractional */
  254. if (video_cfg->vblank % 2 != 0)
  255. video_cfg->vblank_osc = 1;
  256. video_cfg->v_fc_config.timings.y_res /= 2;
  257. video_cfg->vblank /= 2;
  258. video_cfg->v_fc_config.timings.vfp /= 2;
  259. video_cfg->v_fc_config.timings.vsw /= 2;
  260. video_cfg->v_fc_config.timings.vbp /= 2;
  261. }
  262. if (cfg->timings.double_pixel) {
  263. video_cfg->v_fc_config.timings.x_res *= 2;
  264. video_cfg->hblank *= 2;
  265. video_cfg->v_fc_config.timings.hfp *= 2;
  266. video_cfg->v_fc_config.timings.hsw *= 2;
  267. video_cfg->v_fc_config.timings.hbp *= 2;
  268. }
  269. }
  270. /* DSS_HDMI_CORE_VIDEO_CONFIG */
  271. static void hdmi_core_video_config(struct hdmi_core_data *core,
  272. struct hdmi_core_vid_config *cfg)
  273. {
  274. void __iomem *base = core->base;
  275. unsigned char r = 0;
  276. bool vsync_pol, hsync_pol;
  277. vsync_pol =
  278. cfg->v_fc_config.timings.vsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  279. hsync_pol =
  280. cfg->v_fc_config.timings.hsync_level == OMAPDSS_SIG_ACTIVE_HIGH;
  281. /* Set hsync, vsync and data-enable polarity */
  282. r = hdmi_read_reg(base, HDMI_CORE_FC_INVIDCONF);
  283. r = FLD_MOD(r, vsync_pol, 6, 6);
  284. r = FLD_MOD(r, hsync_pol, 5, 5);
  285. r = FLD_MOD(r, cfg->data_enable_pol, 4, 4);
  286. r = FLD_MOD(r, cfg->vblank_osc, 1, 1);
  287. r = FLD_MOD(r, cfg->v_fc_config.timings.interlace, 0, 0);
  288. hdmi_write_reg(base, HDMI_CORE_FC_INVIDCONF, r);
  289. /* set x resolution */
  290. REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV1,
  291. cfg->v_fc_config.timings.x_res >> 8, 4, 0);
  292. REG_FLD_MOD(base, HDMI_CORE_FC_INHACTIV0,
  293. cfg->v_fc_config.timings.x_res & 0xFF, 7, 0);
  294. /* set y resolution */
  295. REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV1,
  296. cfg->v_fc_config.timings.y_res >> 8, 4, 0);
  297. REG_FLD_MOD(base, HDMI_CORE_FC_INVACTIV0,
  298. cfg->v_fc_config.timings.y_res & 0xFF, 7, 0);
  299. /* set horizontal blanking pixels */
  300. REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK1, cfg->hblank >> 8, 4, 0);
  301. REG_FLD_MOD(base, HDMI_CORE_FC_INHBLANK0, cfg->hblank & 0xFF, 7, 0);
  302. /* set vertial blanking pixels */
  303. REG_FLD_MOD(base, HDMI_CORE_FC_INVBLANK, cfg->vblank, 7, 0);
  304. /* set horizontal sync offset */
  305. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY1,
  306. cfg->v_fc_config.timings.hfp >> 8, 4, 0);
  307. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINDELAY0,
  308. cfg->v_fc_config.timings.hfp & 0xFF, 7, 0);
  309. /* set vertical sync offset */
  310. REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINDELAY,
  311. cfg->v_fc_config.timings.vfp, 7, 0);
  312. /* set horizontal sync pulse width */
  313. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH1,
  314. (cfg->v_fc_config.timings.hsw >> 8), 1, 0);
  315. REG_FLD_MOD(base, HDMI_CORE_FC_HSYNCINWIDTH0,
  316. cfg->v_fc_config.timings.hsw & 0xFF, 7, 0);
  317. /* set vertical sync pulse width */
  318. REG_FLD_MOD(base, HDMI_CORE_FC_VSYNCINWIDTH,
  319. cfg->v_fc_config.timings.vsw, 5, 0);
  320. /* select DVI mode */
  321. REG_FLD_MOD(base, HDMI_CORE_FC_INVIDCONF,
  322. cfg->v_fc_config.hdmi_dvi_mode, 3, 3);
  323. if (cfg->v_fc_config.timings.double_pixel)
  324. REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, 2, 7, 4);
  325. else
  326. REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, 1, 7, 4);
  327. }
  328. static void hdmi_core_config_video_packetizer(struct hdmi_core_data *core)
  329. {
  330. void __iomem *base = core->base;
  331. int clr_depth = 0; /* 24 bit color depth */
  332. /* COLOR_DEPTH */
  333. REG_FLD_MOD(base, HDMI_CORE_VP_PR_CD, clr_depth, 7, 4);
  334. /* BYPASS_EN */
  335. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 1, 6, 6);
  336. /* PP_EN */
  337. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 1 : 0, 5, 5);
  338. /* YCC422_EN */
  339. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, 0, 3, 3);
  340. /* PP_STUFFING */
  341. REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, clr_depth ? 1 : 0, 1, 1);
  342. /* YCC422_STUFFING */
  343. REG_FLD_MOD(base, HDMI_CORE_VP_STUFF, 1, 2, 2);
  344. /* OUTPUT_SELECTOR */
  345. REG_FLD_MOD(base, HDMI_CORE_VP_CONF, clr_depth ? 0 : 2, 1, 0);
  346. }
  347. static void hdmi_core_config_csc(struct hdmi_core_data *core)
  348. {
  349. int clr_depth = 0; /* 24 bit color depth */
  350. /* CSC_COLORDEPTH */
  351. REG_FLD_MOD(core->base, HDMI_CORE_CSC_SCALE, clr_depth, 7, 4);
  352. }
  353. static void hdmi_core_config_video_sampler(struct hdmi_core_data *core)
  354. {
  355. int video_mapping = 1; /* for 24 bit color depth */
  356. /* VIDEO_MAPPING */
  357. REG_FLD_MOD(core->base, HDMI_CORE_TX_INVID0, video_mapping, 4, 0);
  358. }
  359. static void hdmi_core_write_avi_infoframe(struct hdmi_core_data *core,
  360. struct hdmi_avi_infoframe *frame)
  361. {
  362. void __iomem *base = core->base;
  363. u8 data[HDMI_INFOFRAME_SIZE(AVI)];
  364. u8 *ptr;
  365. unsigned y, a, b, s;
  366. unsigned c, m, r;
  367. unsigned itc, ec, q, sc;
  368. unsigned vic;
  369. unsigned yq, cn, pr;
  370. hdmi_avi_infoframe_pack(frame, data, sizeof(data));
  371. print_hex_dump_debug("AVI: ", DUMP_PREFIX_NONE, 16, 1, data,
  372. HDMI_INFOFRAME_SIZE(AVI), false);
  373. ptr = data + HDMI_INFOFRAME_HEADER_SIZE;
  374. y = (ptr[0] >> 5) & 0x3;
  375. a = (ptr[0] >> 4) & 0x1;
  376. b = (ptr[0] >> 2) & 0x3;
  377. s = (ptr[0] >> 0) & 0x3;
  378. c = (ptr[1] >> 6) & 0x3;
  379. m = (ptr[1] >> 4) & 0x3;
  380. r = (ptr[1] >> 0) & 0xf;
  381. itc = (ptr[2] >> 7) & 0x1;
  382. ec = (ptr[2] >> 4) & 0x7;
  383. q = (ptr[2] >> 2) & 0x3;
  384. sc = (ptr[2] >> 0) & 0x3;
  385. vic = ptr[3];
  386. yq = (ptr[4] >> 6) & 0x3;
  387. cn = (ptr[4] >> 4) & 0x3;
  388. pr = (ptr[4] >> 0) & 0xf;
  389. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF0,
  390. (a << 6) | (s << 4) | (b << 2) | (y << 0));
  391. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF1,
  392. (c << 6) | (m << 4) | (r << 0));
  393. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF2,
  394. (itc << 7) | (ec << 4) | (q << 2) | (sc << 0));
  395. hdmi_write_reg(base, HDMI_CORE_FC_AVIVID, vic);
  396. hdmi_write_reg(base, HDMI_CORE_FC_AVICONF3,
  397. (yq << 2) | (cn << 0));
  398. REG_FLD_MOD(base, HDMI_CORE_FC_PRCONF, pr, 3, 0);
  399. }
  400. static void hdmi_core_csc_config(struct hdmi_core_data *core,
  401. struct csc_table csc_coeff)
  402. {
  403. void __iomem *base = core->base;
  404. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_MSB, csc_coeff.a1 >> 8 , 6, 0);
  405. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A1_LSB, csc_coeff.a1, 7, 0);
  406. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_MSB, csc_coeff.a2 >> 8, 6, 0);
  407. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A2_LSB, csc_coeff.a2, 7, 0);
  408. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_MSB, csc_coeff.a3 >> 8, 6, 0);
  409. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A3_LSB, csc_coeff.a3, 7, 0);
  410. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_MSB, csc_coeff.a4 >> 8, 6, 0);
  411. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_A4_LSB, csc_coeff.a4, 7, 0);
  412. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_MSB, csc_coeff.b1 >> 8, 6, 0);
  413. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B1_LSB, csc_coeff.b1, 7, 0);
  414. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_MSB, csc_coeff.b2 >> 8, 6, 0);
  415. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B2_LSB, csc_coeff.b2, 7, 0);
  416. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_MSB, csc_coeff.b3 >> 8, 6, 0);
  417. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B3_LSB, csc_coeff.b3, 7, 0);
  418. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_MSB, csc_coeff.b4 >> 8, 6, 0);
  419. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_B4_LSB, csc_coeff.b4, 7, 0);
  420. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_MSB, csc_coeff.c1 >> 8, 6, 0);
  421. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C1_LSB, csc_coeff.c1, 7, 0);
  422. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_MSB, csc_coeff.c2 >> 8, 6, 0);
  423. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C2_LSB, csc_coeff.c2, 7, 0);
  424. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_MSB, csc_coeff.c3 >> 8, 6, 0);
  425. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C3_LSB, csc_coeff.c3, 7, 0);
  426. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_MSB, csc_coeff.c4 >> 8, 6, 0);
  427. REG_FLD_MOD(base, HDMI_CORE_CSC_COEF_C4_LSB, csc_coeff.c4, 7, 0);
  428. REG_FLD_MOD(base, HDMI_CORE_MC_FLOWCTRL, 0x1, 0, 0);
  429. }
  430. static void hdmi_core_configure_range(struct hdmi_core_data *core)
  431. {
  432. struct csc_table csc_coeff = { 0 };
  433. /* support limited range with 24 bit color depth for now */
  434. csc_coeff = csc_table_deepcolor[0];
  435. hdmi_core_csc_config(core, csc_coeff);
  436. }
  437. static void hdmi_core_enable_video_path(struct hdmi_core_data *core)
  438. {
  439. void __iomem *base = core->base;
  440. DSSDBG("hdmi_core_enable_video_path\n");
  441. REG_FLD_MOD(base, HDMI_CORE_FC_CTRLDUR, 0x0C, 7, 0);
  442. REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLDUR, 0x20, 7, 0);
  443. REG_FLD_MOD(base, HDMI_CORE_FC_EXCTRLSPAC, 0x01, 7, 0);
  444. REG_FLD_MOD(base, HDMI_CORE_FC_CH0PREAM, 0x0B, 7, 0);
  445. REG_FLD_MOD(base, HDMI_CORE_FC_CH1PREAM, 0x16, 5, 0);
  446. REG_FLD_MOD(base, HDMI_CORE_FC_CH2PREAM, 0x21, 5, 0);
  447. REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 0, 0);
  448. REG_FLD_MOD(base, HDMI_CORE_MC_CLKDIS, 0x00, 1, 1);
  449. }
  450. static void hdmi_core_mask_interrupts(struct hdmi_core_data *core)
  451. {
  452. void __iomem *base = core->base;
  453. /* Master IRQ mask */
  454. REG_FLD_MOD(base, HDMI_CORE_IH_MUTE, 0x3, 1, 0);
  455. /* Mask all the interrupts in HDMI core */
  456. REG_FLD_MOD(base, HDMI_CORE_VP_MASK, 0xff, 7, 0);
  457. REG_FLD_MOD(base, HDMI_CORE_FC_MASK0, 0xe7, 7, 0);
  458. REG_FLD_MOD(base, HDMI_CORE_FC_MASK1, 0xfb, 7, 0);
  459. REG_FLD_MOD(base, HDMI_CORE_FC_MASK2, 0x3, 1, 0);
  460. REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 0x3, 3, 2);
  461. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 0x3, 1, 0);
  462. REG_FLD_MOD(base, HDMI_CORE_CEC_MASK, 0x7f, 6, 0);
  463. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 6, 6);
  464. REG_FLD_MOD(base, HDMI_CORE_I2CM_CTLINT, 0x1, 2, 2);
  465. REG_FLD_MOD(base, HDMI_CORE_I2CM_INT, 0x1, 2, 2);
  466. REG_FLD_MOD(base, HDMI_CORE_PHY_MASK0, 0xf3, 7, 0);
  467. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  468. /* Clear all the current interrupt bits */
  469. REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0);
  470. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xe7, 7, 0);
  471. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xfb, 7, 0);
  472. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0x3, 1, 0);
  473. REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0x7, 2, 0);
  474. REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0x7f, 6, 0);
  475. REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0x3, 1, 0);
  476. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  477. }
  478. static void hdmi_core_enable_interrupts(struct hdmi_core_data *core)
  479. {
  480. /* Unmute interrupts */
  481. REG_FLD_MOD(core->base, HDMI_CORE_IH_MUTE, 0x0, 1, 0);
  482. }
  483. int hdmi5_core_handle_irqs(struct hdmi_core_data *core)
  484. {
  485. void __iomem *base = core->base;
  486. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT0, 0xff, 7, 0);
  487. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT1, 0xff, 7, 0);
  488. REG_FLD_MOD(base, HDMI_CORE_IH_FC_STAT2, 0xff, 7, 0);
  489. REG_FLD_MOD(base, HDMI_CORE_IH_AS_STAT0, 0xff, 7, 0);
  490. REG_FLD_MOD(base, HDMI_CORE_IH_PHY_STAT0, 0xff, 7, 0);
  491. REG_FLD_MOD(base, HDMI_CORE_IH_I2CM_STAT0, 0xff, 7, 0);
  492. REG_FLD_MOD(base, HDMI_CORE_IH_CEC_STAT0, 0xff, 7, 0);
  493. REG_FLD_MOD(base, HDMI_CORE_IH_VP_STAT0, 0xff, 7, 0);
  494. REG_FLD_MOD(base, HDMI_CORE_IH_I2CMPHY_STAT0, 0xff, 7, 0);
  495. return 0;
  496. }
  497. void hdmi5_configure(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
  498. struct hdmi_config *cfg)
  499. {
  500. struct omap_video_timings video_timing;
  501. struct hdmi_video_format video_format;
  502. struct hdmi_core_vid_config v_core_cfg;
  503. hdmi_core_mask_interrupts(core);
  504. hdmi_core_init(&v_core_cfg, cfg);
  505. hdmi_wp_init_vid_fmt_timings(&video_format, &video_timing, cfg);
  506. hdmi_wp_video_config_timing(wp, &video_timing);
  507. /* video config */
  508. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  509. hdmi_wp_video_config_format(wp, &video_format);
  510. hdmi_wp_video_config_interface(wp, &video_timing);
  511. /* support limited range with 24 bit color depth for now */
  512. hdmi_core_configure_range(core);
  513. cfg->infoframe.quantization_range = HDMI_QUANTIZATION_RANGE_LIMITED;
  514. /*
  515. * configure core video part, set software reset in the core
  516. */
  517. v_core_cfg.packet_mode = HDMI_PACKETMODE24BITPERPIXEL;
  518. hdmi_core_video_config(core, &v_core_cfg);
  519. hdmi_core_config_video_packetizer(core);
  520. hdmi_core_config_csc(core);
  521. hdmi_core_config_video_sampler(core);
  522. if (cfg->hdmi_dvi_mode == HDMI_HDMI)
  523. hdmi_core_write_avi_infoframe(core, &cfg->infoframe);
  524. hdmi_core_enable_video_path(core);
  525. hdmi_core_enable_interrupts(core);
  526. }
  527. static void hdmi5_core_audio_config(struct hdmi_core_data *core,
  528. struct hdmi_core_audio_config *cfg)
  529. {
  530. void __iomem *base = core->base;
  531. u8 val;
  532. /* Mute audio before configuring */
  533. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0xf, 7, 4);
  534. /* Set the N parameter */
  535. REG_FLD_MOD(base, HDMI_CORE_AUD_N1, cfg->n, 7, 0);
  536. REG_FLD_MOD(base, HDMI_CORE_AUD_N2, cfg->n >> 8, 7, 0);
  537. REG_FLD_MOD(base, HDMI_CORE_AUD_N3, cfg->n >> 16, 3, 0);
  538. /*
  539. * CTS manual mode. Automatic mode is not supported when using audio
  540. * parallel interface.
  541. */
  542. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, 1, 4, 4);
  543. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS1, cfg->cts, 7, 0);
  544. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS2, cfg->cts >> 8, 7, 0);
  545. REG_FLD_MOD(base, HDMI_CORE_AUD_CTS3, cfg->cts >> 16, 3, 0);
  546. /* Layout of Audio Sample Packets: 2-channel or multichannels */
  547. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH)
  548. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0, 0, 0);
  549. else
  550. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 1, 0, 0);
  551. /* Configure IEC-609580 Validity bits */
  552. /* Channel 0 is valid */
  553. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 0, 0);
  554. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, 0, 4, 4);
  555. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH)
  556. val = 1;
  557. else
  558. val = 0;
  559. /* Channels 1, 2 setting */
  560. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 1, 1);
  561. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 5, 5);
  562. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 2, 2);
  563. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 6, 6);
  564. /* Channel 3 setting */
  565. if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH)
  566. val = 1;
  567. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 3, 3);
  568. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSV, val, 7, 7);
  569. /* Configure IEC-60958 User bits */
  570. /* TODO: should be set by user. */
  571. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSU, 0, 7, 0);
  572. /* Configure IEC-60958 Channel Status word */
  573. /* CGMSA */
  574. val = cfg->iec60958_cfg->status[5] & IEC958_AES5_CON_CGMSA;
  575. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 5, 4);
  576. /* Copyright */
  577. val = (cfg->iec60958_cfg->status[0] &
  578. IEC958_AES0_CON_NOT_COPYRIGHT) >> 2;
  579. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(0), val, 0, 0);
  580. /* Category */
  581. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(1),
  582. cfg->iec60958_cfg->status[1]);
  583. /* PCM audio mode */
  584. val = (cfg->iec60958_cfg->status[0] & IEC958_AES0_CON_MODE) >> 6;
  585. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 6, 4);
  586. /* Source number */
  587. val = cfg->iec60958_cfg->status[2] & IEC958_AES2_CON_SOURCE;
  588. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(2), val, 3, 0);
  589. /* Channel number right 0 */
  590. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 2, 3, 0);
  591. /* Channel number right 1*/
  592. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(3), 4, 7, 4);
  593. /* Channel number right 2 */
  594. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 6, 3, 0);
  595. /* Channel number right 3*/
  596. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(4), 8, 7, 4);
  597. /* Channel number left 0 */
  598. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 1, 3, 0);
  599. /* Channel number left 1*/
  600. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(5), 3, 7, 4);
  601. /* Channel number left 2 */
  602. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 5, 3, 0);
  603. /* Channel number left 3*/
  604. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCHNLS(6), 7, 7, 4);
  605. /* Clock accuracy and sample rate */
  606. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(7),
  607. cfg->iec60958_cfg->status[3]);
  608. /* Original sample rate and word length */
  609. hdmi_write_reg(base, HDMI_CORE_FC_AUDSCHNLS(8),
  610. cfg->iec60958_cfg->status[4]);
  611. /* Enable FIFO empty and full interrupts */
  612. REG_FLD_MOD(base, HDMI_CORE_AUD_INT, 3, 3, 2);
  613. /* Configure GPA */
  614. /* select HBR/SPDIF interfaces */
  615. if (cfg->layout == HDMI_AUDIO_LAYOUT_2CH) {
  616. /* select HBR/SPDIF interfaces */
  617. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  618. /* enable two channels in GPA */
  619. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 3, 7, 0);
  620. } else if (cfg->layout == HDMI_AUDIO_LAYOUT_6CH) {
  621. /* select HBR/SPDIF interfaces */
  622. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  623. /* enable six channels in GPA */
  624. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0x3F, 7, 0);
  625. } else {
  626. /* select HBR/SPDIF interfaces */
  627. REG_FLD_MOD(base, HDMI_CORE_AUD_CONF0, 0, 5, 5);
  628. /* enable eight channels in GPA */
  629. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF1, 0xFF, 7, 0);
  630. }
  631. /* disable HBR */
  632. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 0, 0, 0);
  633. /* enable PCUV */
  634. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_CONF2, 1, 1, 1);
  635. /* enable GPA FIFO full and empty mask */
  636. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_MASK, 3, 1, 0);
  637. /* set polarity of GPA FIFO empty interrupts */
  638. REG_FLD_MOD(base, HDMI_CORE_AUD_GP_POL, 1, 0, 0);
  639. /* unmute audio */
  640. REG_FLD_MOD(base, HDMI_CORE_FC_AUDSCONF, 0, 7, 4);
  641. }
  642. static void hdmi5_core_audio_infoframe_cfg(struct hdmi_core_data *core,
  643. struct snd_cea_861_aud_if *info_aud)
  644. {
  645. void __iomem *base = core->base;
  646. /* channel count and coding type fields in AUDICONF0 are swapped */
  647. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF0,
  648. (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC) << 4 |
  649. (info_aud->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CT) >> 4);
  650. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF1, info_aud->db2_sf_ss);
  651. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF2, info_aud->db4_ca);
  652. hdmi_write_reg(base, HDMI_CORE_FC_AUDICONF3,
  653. (info_aud->db5_dminh_lsv & CEA861_AUDIO_INFOFRAME_DB5_DM_INH) >> 3 |
  654. (info_aud->db5_dminh_lsv & CEA861_AUDIO_INFOFRAME_DB5_LSV));
  655. }
  656. int hdmi5_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
  657. struct omap_dss_audio *audio, u32 pclk)
  658. {
  659. struct hdmi_audio_format audio_format;
  660. struct hdmi_audio_dma audio_dma;
  661. struct hdmi_core_audio_config core_cfg;
  662. int err, n, cts, channel_count;
  663. unsigned int fs_nr;
  664. bool word_length_16b = false;
  665. if (!audio || !audio->iec || !audio->cea || !core)
  666. return -EINVAL;
  667. core_cfg.iec60958_cfg = audio->iec;
  668. if (!(audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24) &&
  669. (audio->iec->status[4] & IEC958_AES4_CON_WORDLEN_20_16))
  670. word_length_16b = true;
  671. /* only 16-bit word length supported atm */
  672. if (!word_length_16b)
  673. return -EINVAL;
  674. switch (audio->iec->status[3] & IEC958_AES3_CON_FS) {
  675. case IEC958_AES3_CON_FS_32000:
  676. fs_nr = 32000;
  677. break;
  678. case IEC958_AES3_CON_FS_44100:
  679. fs_nr = 44100;
  680. break;
  681. case IEC958_AES3_CON_FS_48000:
  682. fs_nr = 48000;
  683. break;
  684. case IEC958_AES3_CON_FS_88200:
  685. fs_nr = 88200;
  686. break;
  687. case IEC958_AES3_CON_FS_96000:
  688. fs_nr = 96000;
  689. break;
  690. case IEC958_AES3_CON_FS_176400:
  691. fs_nr = 176400;
  692. break;
  693. case IEC958_AES3_CON_FS_192000:
  694. fs_nr = 192000;
  695. break;
  696. default:
  697. return -EINVAL;
  698. }
  699. err = hdmi_compute_acr(pclk, fs_nr, &n, &cts);
  700. core_cfg.n = n;
  701. core_cfg.cts = cts;
  702. /* Audio channels settings */
  703. channel_count = (audio->cea->db1_ct_cc & CEA861_AUDIO_INFOFRAME_DB1CC)
  704. + 1;
  705. if (channel_count == 2)
  706. core_cfg.layout = HDMI_AUDIO_LAYOUT_2CH;
  707. else if (channel_count == 6)
  708. core_cfg.layout = HDMI_AUDIO_LAYOUT_6CH;
  709. else
  710. core_cfg.layout = HDMI_AUDIO_LAYOUT_8CH;
  711. /* DMA settings */
  712. if (word_length_16b)
  713. audio_dma.transfer_size = 0x10;
  714. else
  715. audio_dma.transfer_size = 0x20;
  716. audio_dma.block_size = 0xC0;
  717. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  718. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  719. /* audio FIFO format settings for 16-bit samples*/
  720. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_TWOSAMPLES;
  721. audio_format.sample_size = HDMI_AUDIO_SAMPLE_16BITS;
  722. audio_format.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  723. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  724. /* only LPCM atm */
  725. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  726. /* only allowed option */
  727. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  728. /* disable start/stop signals of IEC 60958 blocks */
  729. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_ON;
  730. /* configure DMA and audio FIFO format*/
  731. hdmi_wp_audio_config_dma(wp, &audio_dma);
  732. hdmi_wp_audio_config_format(wp, &audio_format);
  733. /* configure the core */
  734. hdmi5_core_audio_config(core, &core_cfg);
  735. /* configure CEA 861 audio infoframe */
  736. hdmi5_core_audio_infoframe_cfg(core, audio->cea);
  737. return 0;
  738. }
  739. int hdmi5_core_init(struct platform_device *pdev, struct hdmi_core_data *core)
  740. {
  741. struct resource *res;
  742. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
  743. if (!res) {
  744. DSSERR("can't get CORE IORESOURCE_MEM HDMI\n");
  745. return -EINVAL;
  746. }
  747. core->base = devm_ioremap_resource(&pdev->dev, res);
  748. if (IS_ERR(core->base)) {
  749. DSSERR("can't ioremap HDMI core\n");
  750. return PTR_ERR(core->base);
  751. }
  752. return 0;
  753. }