hdmi4_core.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /*
  2. * ti_hdmi_4xxx_ip.c
  3. *
  4. * HDMI TI81xx, TI38xx, TI OMAP4 etc IP driver Library
  5. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  6. * Authors: Yong Zhi
  7. * Mythri pk <mythripk@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #define DSS_SUBSYS_NAME "HDMICORE"
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/io.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/mutex.h>
  28. #include <linux/delay.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/string.h>
  31. #include <linux/seq_file.h>
  32. #include <sound/asound.h>
  33. #include <sound/asoundef.h>
  34. #include "hdmi4_core.h"
  35. #include "dss_features.h"
  36. #define HDMI_CORE_AV 0x500
  37. static inline void __iomem *hdmi_av_base(struct hdmi_core_data *core)
  38. {
  39. return core->base + HDMI_CORE_AV;
  40. }
  41. static int hdmi_core_ddc_init(struct hdmi_core_data *core)
  42. {
  43. void __iomem *base = core->base;
  44. /* Turn on CLK for DDC */
  45. REG_FLD_MOD(base, HDMI_CORE_AV_DPD, 0x7, 2, 0);
  46. /* IN_PROG */
  47. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) {
  48. /* Abort transaction */
  49. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xf, 3, 0);
  50. /* IN_PROG */
  51. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  52. 4, 4, 0) != 0) {
  53. DSSERR("Timeout aborting DDC transaction\n");
  54. return -ETIMEDOUT;
  55. }
  56. }
  57. /* Clk SCL Devices */
  58. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  59. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  60. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  61. 4, 4, 0) != 0) {
  62. DSSERR("Timeout starting SCL clock\n");
  63. return -ETIMEDOUT;
  64. }
  65. /* Clear FIFO */
  66. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  67. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  68. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  69. 4, 4, 0) != 0) {
  70. DSSERR("Timeout clearing DDC fifo\n");
  71. return -ETIMEDOUT;
  72. }
  73. return 0;
  74. }
  75. static int hdmi_core_ddc_edid(struct hdmi_core_data *core,
  76. u8 *pedid, int ext)
  77. {
  78. void __iomem *base = core->base;
  79. u32 i;
  80. char checksum;
  81. u32 offset = 0;
  82. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  83. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  84. 4, 4, 0) != 0) {
  85. DSSERR("Timeout waiting DDC to be ready\n");
  86. return -ETIMEDOUT;
  87. }
  88. if (ext % 2 != 0)
  89. offset = 0x80;
  90. /* Load Segment Address Register */
  91. REG_FLD_MOD(base, HDMI_CORE_DDC_SEGM, ext / 2, 7, 0);
  92. /* Load Slave Address Register */
  93. REG_FLD_MOD(base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  94. /* Load Offset Address Register */
  95. REG_FLD_MOD(base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  96. /* Load Byte Count */
  97. REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  98. REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  99. /* Set DDC_CMD */
  100. if (ext)
  101. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  102. else
  103. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  104. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  105. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  106. DSSERR("I2C Bus Low?\n");
  107. return -EIO;
  108. }
  109. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  110. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  111. DSSERR("I2C No Ack\n");
  112. return -EIO;
  113. }
  114. for (i = 0; i < 0x80; ++i) {
  115. int t;
  116. /* IN_PROG */
  117. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 0) {
  118. DSSERR("operation stopped when reading edid\n");
  119. return -EIO;
  120. }
  121. t = 0;
  122. /* FIFO_EMPTY */
  123. while (REG_GET(base, HDMI_CORE_DDC_STATUS, 2, 2) == 1) {
  124. if (t++ > 10000) {
  125. DSSERR("timeout reading edid\n");
  126. return -ETIMEDOUT;
  127. }
  128. udelay(1);
  129. }
  130. pedid[i] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
  131. }
  132. checksum = 0;
  133. for (i = 0; i < 0x80; ++i)
  134. checksum += pedid[i];
  135. if (checksum != 0) {
  136. DSSERR("E-EDID checksum failed!!\n");
  137. return -EIO;
  138. }
  139. return 0;
  140. }
  141. int hdmi4_read_edid(struct hdmi_core_data *core, u8 *edid, int len)
  142. {
  143. int r, l;
  144. if (len < 128)
  145. return -EINVAL;
  146. r = hdmi_core_ddc_init(core);
  147. if (r)
  148. return r;
  149. r = hdmi_core_ddc_edid(core, edid, 0);
  150. if (r)
  151. return r;
  152. l = 128;
  153. if (len >= 128 * 2 && edid[0x7e] > 0) {
  154. r = hdmi_core_ddc_edid(core, edid + 0x80, 1);
  155. if (r)
  156. return r;
  157. l += 128;
  158. }
  159. return l;
  160. }
  161. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg)
  162. {
  163. DSSDBG("Enter hdmi_core_init\n");
  164. /* video core */
  165. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  166. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  167. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  168. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  169. video_cfg->hdmi_dvi = HDMI_DVI;
  170. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  171. }
  172. static void hdmi_core_powerdown_disable(struct hdmi_core_data *core)
  173. {
  174. DSSDBG("Enter hdmi_core_powerdown_disable\n");
  175. REG_FLD_MOD(core->base, HDMI_CORE_SYS_SYS_CTRL1, 0x0, 0, 0);
  176. }
  177. static void hdmi_core_swreset_release(struct hdmi_core_data *core)
  178. {
  179. DSSDBG("Enter hdmi_core_swreset_release\n");
  180. REG_FLD_MOD(core->base, HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  181. }
  182. static void hdmi_core_swreset_assert(struct hdmi_core_data *core)
  183. {
  184. DSSDBG("Enter hdmi_core_swreset_assert\n");
  185. REG_FLD_MOD(core->base, HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  186. }
  187. /* HDMI_CORE_VIDEO_CONFIG */
  188. static void hdmi_core_video_config(struct hdmi_core_data *core,
  189. struct hdmi_core_video_config *cfg)
  190. {
  191. u32 r = 0;
  192. void __iomem *core_sys_base = core->base;
  193. void __iomem *core_av_base = hdmi_av_base(core);
  194. /* sys_ctrl1 default configuration not tunable */
  195. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_SYS_CTRL1);
  196. r = FLD_MOD(r, HDMI_CORE_SYS_SYS_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  197. r = FLD_MOD(r, HDMI_CORE_SYS_SYS_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  198. r = FLD_MOD(r, HDMI_CORE_SYS_SYS_CTRL1_BSEL_24BITBUS, 2, 2);
  199. r = FLD_MOD(r, HDMI_CORE_SYS_SYS_CTRL1_EDGE_RISINGEDGE, 1, 1);
  200. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_SYS_CTRL1, r);
  201. REG_FLD_MOD(core_sys_base,
  202. HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  203. /* Vid_Mode */
  204. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
  205. /* dither truncation configuration */
  206. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  207. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  208. r = FLD_MOD(r, 1, 5, 5);
  209. } else {
  210. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  211. r = FLD_MOD(r, 0, 5, 5);
  212. }
  213. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
  214. /* HDMI_Ctrl */
  215. r = hdmi_read_reg(core_av_base, HDMI_CORE_AV_HDMI_CTRL);
  216. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  217. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  218. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  219. hdmi_write_reg(core_av_base, HDMI_CORE_AV_HDMI_CTRL, r);
  220. /* TMDS_CTRL */
  221. REG_FLD_MOD(core_sys_base,
  222. HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
  223. }
  224. static void hdmi_core_write_avi_infoframe(struct hdmi_core_data *core,
  225. struct hdmi_avi_infoframe *frame)
  226. {
  227. void __iomem *av_base = hdmi_av_base(core);
  228. u8 data[HDMI_INFOFRAME_SIZE(AVI)];
  229. int i;
  230. hdmi_avi_infoframe_pack(frame, data, sizeof(data));
  231. print_hex_dump_debug("AVI: ", DUMP_PREFIX_NONE, 16, 1, data,
  232. HDMI_INFOFRAME_SIZE(AVI), false);
  233. for (i = 0; i < sizeof(data); ++i) {
  234. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_BASE + i * 4,
  235. data[i]);
  236. }
  237. }
  238. static void hdmi_core_av_packet_config(struct hdmi_core_data *core,
  239. struct hdmi_core_packet_enable_repeat repeat_cfg)
  240. {
  241. /* enable/repeat the infoframe */
  242. hdmi_write_reg(hdmi_av_base(core), HDMI_CORE_AV_PB_CTRL1,
  243. (repeat_cfg.audio_pkt << 5) |
  244. (repeat_cfg.audio_pkt_repeat << 4) |
  245. (repeat_cfg.avi_infoframe << 1) |
  246. (repeat_cfg.avi_infoframe_repeat));
  247. /* enable/repeat the packet */
  248. hdmi_write_reg(hdmi_av_base(core), HDMI_CORE_AV_PB_CTRL2,
  249. (repeat_cfg.gen_cntrl_pkt << 3) |
  250. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  251. (repeat_cfg.generic_pkt << 1) |
  252. (repeat_cfg.generic_pkt_repeat));
  253. }
  254. void hdmi4_configure(struct hdmi_core_data *core,
  255. struct hdmi_wp_data *wp, struct hdmi_config *cfg)
  256. {
  257. /* HDMI */
  258. struct omap_video_timings video_timing;
  259. struct hdmi_video_format video_format;
  260. /* HDMI core */
  261. struct hdmi_core_video_config v_core_cfg;
  262. struct hdmi_core_packet_enable_repeat repeat_cfg = { 0 };
  263. hdmi_core_init(&v_core_cfg);
  264. hdmi_wp_init_vid_fmt_timings(&video_format, &video_timing, cfg);
  265. hdmi_wp_video_config_timing(wp, &video_timing);
  266. /* video config */
  267. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  268. hdmi_wp_video_config_format(wp, &video_format);
  269. hdmi_wp_video_config_interface(wp, &video_timing);
  270. /*
  271. * configure core video part
  272. * set software reset in the core
  273. */
  274. hdmi_core_swreset_assert(core);
  275. /* power down off */
  276. hdmi_core_powerdown_disable(core);
  277. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  278. v_core_cfg.hdmi_dvi = cfg->hdmi_dvi_mode;
  279. hdmi_core_video_config(core, &v_core_cfg);
  280. /* release software reset in the core */
  281. hdmi_core_swreset_release(core);
  282. if (cfg->hdmi_dvi_mode == HDMI_HDMI) {
  283. hdmi_core_write_avi_infoframe(core, &cfg->infoframe);
  284. /* enable/repeat the infoframe */
  285. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  286. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  287. /* wakeup */
  288. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  289. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  290. }
  291. hdmi_core_av_packet_config(core, repeat_cfg);
  292. }
  293. void hdmi4_core_dump(struct hdmi_core_data *core, struct seq_file *s)
  294. {
  295. int i;
  296. #define CORE_REG(i, name) name(i)
  297. #define DUMPCORE(r) seq_printf(s, "%-35s %08x\n", #r,\
  298. hdmi_read_reg(core->base, r))
  299. #define DUMPCOREAV(r) seq_printf(s, "%-35s %08x\n", #r,\
  300. hdmi_read_reg(hdmi_av_base(core), r))
  301. #define DUMPCOREAV2(i, r) seq_printf(s, "%s[%d]%*s %08x\n", #r, i, \
  302. (i < 10) ? 32 - (int)strlen(#r) : 31 - (int)strlen(#r), " ", \
  303. hdmi_read_reg(hdmi_av_base(core), CORE_REG(i, r)))
  304. DUMPCORE(HDMI_CORE_SYS_VND_IDL);
  305. DUMPCORE(HDMI_CORE_SYS_DEV_IDL);
  306. DUMPCORE(HDMI_CORE_SYS_DEV_IDH);
  307. DUMPCORE(HDMI_CORE_SYS_DEV_REV);
  308. DUMPCORE(HDMI_CORE_SYS_SRST);
  309. DUMPCORE(HDMI_CORE_SYS_SYS_CTRL1);
  310. DUMPCORE(HDMI_CORE_SYS_SYS_STAT);
  311. DUMPCORE(HDMI_CORE_SYS_SYS_CTRL3);
  312. DUMPCORE(HDMI_CORE_SYS_DE_DLY);
  313. DUMPCORE(HDMI_CORE_SYS_DE_CTRL);
  314. DUMPCORE(HDMI_CORE_SYS_DE_TOP);
  315. DUMPCORE(HDMI_CORE_SYS_DE_CNTL);
  316. DUMPCORE(HDMI_CORE_SYS_DE_CNTH);
  317. DUMPCORE(HDMI_CORE_SYS_DE_LINL);
  318. DUMPCORE(HDMI_CORE_SYS_DE_LINH_1);
  319. DUMPCORE(HDMI_CORE_SYS_HRES_L);
  320. DUMPCORE(HDMI_CORE_SYS_HRES_H);
  321. DUMPCORE(HDMI_CORE_SYS_VRES_L);
  322. DUMPCORE(HDMI_CORE_SYS_VRES_H);
  323. DUMPCORE(HDMI_CORE_SYS_IADJUST);
  324. DUMPCORE(HDMI_CORE_SYS_POLDETECT);
  325. DUMPCORE(HDMI_CORE_SYS_HWIDTH1);
  326. DUMPCORE(HDMI_CORE_SYS_HWIDTH2);
  327. DUMPCORE(HDMI_CORE_SYS_VWIDTH);
  328. DUMPCORE(HDMI_CORE_SYS_VID_CTRL);
  329. DUMPCORE(HDMI_CORE_SYS_VID_ACEN);
  330. DUMPCORE(HDMI_CORE_SYS_VID_MODE);
  331. DUMPCORE(HDMI_CORE_SYS_VID_BLANK1);
  332. DUMPCORE(HDMI_CORE_SYS_VID_BLANK3);
  333. DUMPCORE(HDMI_CORE_SYS_VID_BLANK1);
  334. DUMPCORE(HDMI_CORE_SYS_DC_HEADER);
  335. DUMPCORE(HDMI_CORE_SYS_VID_DITHER);
  336. DUMPCORE(HDMI_CORE_SYS_RGB2XVYCC_CT);
  337. DUMPCORE(HDMI_CORE_SYS_R2Y_COEFF_LOW);
  338. DUMPCORE(HDMI_CORE_SYS_R2Y_COEFF_UP);
  339. DUMPCORE(HDMI_CORE_SYS_G2Y_COEFF_LOW);
  340. DUMPCORE(HDMI_CORE_SYS_G2Y_COEFF_UP);
  341. DUMPCORE(HDMI_CORE_SYS_B2Y_COEFF_LOW);
  342. DUMPCORE(HDMI_CORE_SYS_B2Y_COEFF_UP);
  343. DUMPCORE(HDMI_CORE_SYS_R2CB_COEFF_LOW);
  344. DUMPCORE(HDMI_CORE_SYS_R2CB_COEFF_UP);
  345. DUMPCORE(HDMI_CORE_SYS_G2CB_COEFF_LOW);
  346. DUMPCORE(HDMI_CORE_SYS_G2CB_COEFF_UP);
  347. DUMPCORE(HDMI_CORE_SYS_B2CB_COEFF_LOW);
  348. DUMPCORE(HDMI_CORE_SYS_B2CB_COEFF_UP);
  349. DUMPCORE(HDMI_CORE_SYS_R2CR_COEFF_LOW);
  350. DUMPCORE(HDMI_CORE_SYS_R2CR_COEFF_UP);
  351. DUMPCORE(HDMI_CORE_SYS_G2CR_COEFF_LOW);
  352. DUMPCORE(HDMI_CORE_SYS_G2CR_COEFF_UP);
  353. DUMPCORE(HDMI_CORE_SYS_B2CR_COEFF_LOW);
  354. DUMPCORE(HDMI_CORE_SYS_B2CR_COEFF_UP);
  355. DUMPCORE(HDMI_CORE_SYS_RGB_OFFSET_LOW);
  356. DUMPCORE(HDMI_CORE_SYS_RGB_OFFSET_UP);
  357. DUMPCORE(HDMI_CORE_SYS_Y_OFFSET_LOW);
  358. DUMPCORE(HDMI_CORE_SYS_Y_OFFSET_UP);
  359. DUMPCORE(HDMI_CORE_SYS_CBCR_OFFSET_LOW);
  360. DUMPCORE(HDMI_CORE_SYS_CBCR_OFFSET_UP);
  361. DUMPCORE(HDMI_CORE_SYS_INTR_STATE);
  362. DUMPCORE(HDMI_CORE_SYS_INTR1);
  363. DUMPCORE(HDMI_CORE_SYS_INTR2);
  364. DUMPCORE(HDMI_CORE_SYS_INTR3);
  365. DUMPCORE(HDMI_CORE_SYS_INTR4);
  366. DUMPCORE(HDMI_CORE_SYS_INTR_UNMASK1);
  367. DUMPCORE(HDMI_CORE_SYS_INTR_UNMASK2);
  368. DUMPCORE(HDMI_CORE_SYS_INTR_UNMASK3);
  369. DUMPCORE(HDMI_CORE_SYS_INTR_UNMASK4);
  370. DUMPCORE(HDMI_CORE_SYS_INTR_CTRL);
  371. DUMPCORE(HDMI_CORE_SYS_TMDS_CTRL);
  372. DUMPCORE(HDMI_CORE_DDC_ADDR);
  373. DUMPCORE(HDMI_CORE_DDC_SEGM);
  374. DUMPCORE(HDMI_CORE_DDC_OFFSET);
  375. DUMPCORE(HDMI_CORE_DDC_COUNT1);
  376. DUMPCORE(HDMI_CORE_DDC_COUNT2);
  377. DUMPCORE(HDMI_CORE_DDC_STATUS);
  378. DUMPCORE(HDMI_CORE_DDC_CMD);
  379. DUMPCORE(HDMI_CORE_DDC_DATA);
  380. DUMPCOREAV(HDMI_CORE_AV_ACR_CTRL);
  381. DUMPCOREAV(HDMI_CORE_AV_FREQ_SVAL);
  382. DUMPCOREAV(HDMI_CORE_AV_N_SVAL1);
  383. DUMPCOREAV(HDMI_CORE_AV_N_SVAL2);
  384. DUMPCOREAV(HDMI_CORE_AV_N_SVAL3);
  385. DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL1);
  386. DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL2);
  387. DUMPCOREAV(HDMI_CORE_AV_CTS_SVAL3);
  388. DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL1);
  389. DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL2);
  390. DUMPCOREAV(HDMI_CORE_AV_CTS_HVAL3);
  391. DUMPCOREAV(HDMI_CORE_AV_AUD_MODE);
  392. DUMPCOREAV(HDMI_CORE_AV_SPDIF_CTRL);
  393. DUMPCOREAV(HDMI_CORE_AV_HW_SPDIF_FS);
  394. DUMPCOREAV(HDMI_CORE_AV_SWAP_I2S);
  395. DUMPCOREAV(HDMI_CORE_AV_SPDIF_ERTH);
  396. DUMPCOREAV(HDMI_CORE_AV_I2S_IN_MAP);
  397. DUMPCOREAV(HDMI_CORE_AV_I2S_IN_CTRL);
  398. DUMPCOREAV(HDMI_CORE_AV_I2S_CHST0);
  399. DUMPCOREAV(HDMI_CORE_AV_I2S_CHST1);
  400. DUMPCOREAV(HDMI_CORE_AV_I2S_CHST2);
  401. DUMPCOREAV(HDMI_CORE_AV_I2S_CHST4);
  402. DUMPCOREAV(HDMI_CORE_AV_I2S_CHST5);
  403. DUMPCOREAV(HDMI_CORE_AV_ASRC);
  404. DUMPCOREAV(HDMI_CORE_AV_I2S_IN_LEN);
  405. DUMPCOREAV(HDMI_CORE_AV_HDMI_CTRL);
  406. DUMPCOREAV(HDMI_CORE_AV_AUDO_TXSTAT);
  407. DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_1);
  408. DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_2);
  409. DUMPCOREAV(HDMI_CORE_AV_AUD_PAR_BUSCLK_3);
  410. DUMPCOREAV(HDMI_CORE_AV_TEST_TXCTRL);
  411. DUMPCOREAV(HDMI_CORE_AV_DPD);
  412. DUMPCOREAV(HDMI_CORE_AV_PB_CTRL1);
  413. DUMPCOREAV(HDMI_CORE_AV_PB_CTRL2);
  414. DUMPCOREAV(HDMI_CORE_AV_AVI_TYPE);
  415. DUMPCOREAV(HDMI_CORE_AV_AVI_VERS);
  416. DUMPCOREAV(HDMI_CORE_AV_AVI_LEN);
  417. DUMPCOREAV(HDMI_CORE_AV_AVI_CHSUM);
  418. for (i = 0; i < HDMI_CORE_AV_AVI_DBYTE_NELEMS; i++)
  419. DUMPCOREAV2(i, HDMI_CORE_AV_AVI_DBYTE);
  420. DUMPCOREAV(HDMI_CORE_AV_SPD_TYPE);
  421. DUMPCOREAV(HDMI_CORE_AV_SPD_VERS);
  422. DUMPCOREAV(HDMI_CORE_AV_SPD_LEN);
  423. DUMPCOREAV(HDMI_CORE_AV_SPD_CHSUM);
  424. for (i = 0; i < HDMI_CORE_AV_SPD_DBYTE_NELEMS; i++)
  425. DUMPCOREAV2(i, HDMI_CORE_AV_SPD_DBYTE);
  426. DUMPCOREAV(HDMI_CORE_AV_AUDIO_TYPE);
  427. DUMPCOREAV(HDMI_CORE_AV_AUDIO_VERS);
  428. DUMPCOREAV(HDMI_CORE_AV_AUDIO_LEN);
  429. DUMPCOREAV(HDMI_CORE_AV_AUDIO_CHSUM);
  430. for (i = 0; i < HDMI_CORE_AV_AUD_DBYTE_NELEMS; i++)
  431. DUMPCOREAV2(i, HDMI_CORE_AV_AUD_DBYTE);
  432. DUMPCOREAV(HDMI_CORE_AV_MPEG_TYPE);
  433. DUMPCOREAV(HDMI_CORE_AV_MPEG_VERS);
  434. DUMPCOREAV(HDMI_CORE_AV_MPEG_LEN);
  435. DUMPCOREAV(HDMI_CORE_AV_MPEG_CHSUM);
  436. for (i = 0; i < HDMI_CORE_AV_MPEG_DBYTE_NELEMS; i++)
  437. DUMPCOREAV2(i, HDMI_CORE_AV_MPEG_DBYTE);
  438. for (i = 0; i < HDMI_CORE_AV_GEN_DBYTE_NELEMS; i++)
  439. DUMPCOREAV2(i, HDMI_CORE_AV_GEN_DBYTE);
  440. DUMPCOREAV(HDMI_CORE_AV_CP_BYTE1);
  441. for (i = 0; i < HDMI_CORE_AV_GEN2_DBYTE_NELEMS; i++)
  442. DUMPCOREAV2(i, HDMI_CORE_AV_GEN2_DBYTE);
  443. DUMPCOREAV(HDMI_CORE_AV_CEC_ADDR_ID);
  444. }
  445. static void hdmi_core_audio_config(struct hdmi_core_data *core,
  446. struct hdmi_core_audio_config *cfg)
  447. {
  448. u32 r;
  449. void __iomem *av_base = hdmi_av_base(core);
  450. /*
  451. * Parameters for generation of Audio Clock Recovery packets
  452. */
  453. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  454. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  455. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  456. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  457. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  458. REG_FLD_MOD(av_base,
  459. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  460. REG_FLD_MOD(av_base,
  461. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  462. } else {
  463. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  464. cfg->aud_par_busclk, 7, 0);
  465. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  466. (cfg->aud_par_busclk >> 8), 7, 0);
  467. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  468. (cfg->aud_par_busclk >> 16), 7, 0);
  469. }
  470. /* Set ACR clock divisor */
  471. REG_FLD_MOD(av_base,
  472. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  473. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  474. /*
  475. * Use TMDS clock for ACR packets. For devices that use
  476. * the MCLK, this is the first part of the MCLK initialization.
  477. */
  478. r = FLD_MOD(r, 0, 2, 2);
  479. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  480. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  481. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  482. /* For devices using MCLK, this completes its initialization. */
  483. if (cfg->use_mclk)
  484. REG_FLD_MOD(av_base, HDMI_CORE_AV_ACR_CTRL, 1, 2, 2);
  485. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  486. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  487. cfg->fs_override, 1, 1);
  488. /*
  489. * Set IEC-60958-3 channel status word. It is passed to the IP
  490. * just as it is received. The user of the driver is responsible
  491. * for its contents.
  492. */
  493. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST0,
  494. cfg->iec60958_cfg->status[0]);
  495. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST1,
  496. cfg->iec60958_cfg->status[1]);
  497. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST2,
  498. cfg->iec60958_cfg->status[2]);
  499. /* yes, this is correct: status[3] goes to CHST4 register */
  500. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST4,
  501. cfg->iec60958_cfg->status[3]);
  502. /* yes, this is correct: status[4] goes to CHST5 register */
  503. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5,
  504. cfg->iec60958_cfg->status[4]);
  505. /* set I2S parameters */
  506. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  507. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  508. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  509. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  510. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  511. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  512. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  513. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  514. cfg->i2s_cfg.in_length_bits, 3, 0);
  515. /* Audio channels and mode parameters */
  516. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  517. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  518. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  519. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  520. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  521. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  522. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  523. /* Audio channel mappings */
  524. /* TODO: Make channel mapping dynamic. For now, map channels
  525. * in the ALSA order: FL/FR/RL/RR/C/LFE/SL/SR. Remapping is needed as
  526. * HDMI speaker order is different. See CEA-861 Section 6.6.2.
  527. */
  528. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_MAP, 0x78);
  529. REG_FLD_MOD(av_base, HDMI_CORE_AV_SWAP_I2S, 1, 5, 5);
  530. }
  531. static void hdmi_core_audio_infoframe_cfg(struct hdmi_core_data *core,
  532. struct snd_cea_861_aud_if *info_aud)
  533. {
  534. u8 sum = 0, checksum = 0;
  535. void __iomem *av_base = hdmi_av_base(core);
  536. /*
  537. * Set audio info frame type, version and length as
  538. * described in HDMI 1.4a Section 8.2.2 specification.
  539. * Checksum calculation is defined in Section 5.3.5.
  540. */
  541. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  542. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  543. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  544. sum += 0x84 + 0x001 + 0x00a;
  545. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0),
  546. info_aud->db1_ct_cc);
  547. sum += info_aud->db1_ct_cc;
  548. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1),
  549. info_aud->db2_sf_ss);
  550. sum += info_aud->db2_sf_ss;
  551. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), info_aud->db3);
  552. sum += info_aud->db3;
  553. /*
  554. * The OMAP HDMI IP requires to use the 8-channel channel code when
  555. * transmitting more than two channels.
  556. */
  557. if (info_aud->db4_ca != 0x00)
  558. info_aud->db4_ca = 0x13;
  559. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), info_aud->db4_ca);
  560. sum += info_aud->db4_ca;
  561. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4),
  562. info_aud->db5_dminh_lsv);
  563. sum += info_aud->db5_dminh_lsv;
  564. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  565. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  566. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  567. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  568. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  569. checksum = 0x100 - sum;
  570. hdmi_write_reg(av_base,
  571. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  572. /*
  573. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  574. * is available.
  575. */
  576. }
  577. int hdmi4_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
  578. struct omap_dss_audio *audio, u32 pclk)
  579. {
  580. struct hdmi_audio_format audio_format;
  581. struct hdmi_audio_dma audio_dma;
  582. struct hdmi_core_audio_config acore;
  583. int err, n, cts, channel_count;
  584. unsigned int fs_nr;
  585. bool word_length_16b = false;
  586. if (!audio || !audio->iec || !audio->cea || !core)
  587. return -EINVAL;
  588. acore.iec60958_cfg = audio->iec;
  589. /*
  590. * In the IEC-60958 status word, check if the audio sample word length
  591. * is 16-bit as several optimizations can be performed in such case.
  592. */
  593. if (!(audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24))
  594. if (audio->iec->status[4] & IEC958_AES4_CON_WORDLEN_20_16)
  595. word_length_16b = true;
  596. /* I2S configuration. See Phillips' specification */
  597. if (word_length_16b)
  598. acore.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_LEFT;
  599. else
  600. acore.i2s_cfg.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  601. /*
  602. * The I2S input word length is twice the lenght given in the IEC-60958
  603. * status word. If the word size is greater than
  604. * 20 bits, increment by one.
  605. */
  606. acore.i2s_cfg.in_length_bits = audio->iec->status[4]
  607. & IEC958_AES4_CON_WORDLEN;
  608. if (audio->iec->status[4] & IEC958_AES4_CON_MAX_WORDLEN_24)
  609. acore.i2s_cfg.in_length_bits++;
  610. acore.i2s_cfg.sck_edge_mode = HDMI_AUDIO_I2S_SCK_EDGE_RISING;
  611. acore.i2s_cfg.vbit = HDMI_AUDIO_I2S_VBIT_FOR_PCM;
  612. acore.i2s_cfg.direction = HDMI_AUDIO_I2S_MSB_SHIFTED_FIRST;
  613. acore.i2s_cfg.shift = HDMI_AUDIO_I2S_FIRST_BIT_SHIFT;
  614. /* convert sample frequency to a number */
  615. switch (audio->iec->status[3] & IEC958_AES3_CON_FS) {
  616. case IEC958_AES3_CON_FS_32000:
  617. fs_nr = 32000;
  618. break;
  619. case IEC958_AES3_CON_FS_44100:
  620. fs_nr = 44100;
  621. break;
  622. case IEC958_AES3_CON_FS_48000:
  623. fs_nr = 48000;
  624. break;
  625. case IEC958_AES3_CON_FS_88200:
  626. fs_nr = 88200;
  627. break;
  628. case IEC958_AES3_CON_FS_96000:
  629. fs_nr = 96000;
  630. break;
  631. case IEC958_AES3_CON_FS_176400:
  632. fs_nr = 176400;
  633. break;
  634. case IEC958_AES3_CON_FS_192000:
  635. fs_nr = 192000;
  636. break;
  637. default:
  638. return -EINVAL;
  639. }
  640. err = hdmi_compute_acr(pclk, fs_nr, &n, &cts);
  641. /* Audio clock regeneration settings */
  642. acore.n = n;
  643. acore.cts = cts;
  644. if (dss_has_feature(FEAT_HDMI_CTS_SWMODE)) {
  645. acore.aud_par_busclk = 0;
  646. acore.cts_mode = HDMI_AUDIO_CTS_MODE_SW;
  647. acore.use_mclk = dss_has_feature(FEAT_HDMI_AUDIO_USE_MCLK);
  648. } else {
  649. acore.aud_par_busclk = (((128 * 31) - 1) << 8);
  650. acore.cts_mode = HDMI_AUDIO_CTS_MODE_HW;
  651. acore.use_mclk = true;
  652. }
  653. if (acore.use_mclk)
  654. acore.mclk_mode = HDMI_AUDIO_MCLK_128FS;
  655. /* Audio channels settings */
  656. channel_count = (audio->cea->db1_ct_cc &
  657. CEA861_AUDIO_INFOFRAME_DB1CC) + 1;
  658. switch (channel_count) {
  659. case 2:
  660. audio_format.active_chnnls_msk = 0x03;
  661. break;
  662. case 3:
  663. audio_format.active_chnnls_msk = 0x07;
  664. break;
  665. case 4:
  666. audio_format.active_chnnls_msk = 0x0f;
  667. break;
  668. case 5:
  669. audio_format.active_chnnls_msk = 0x1f;
  670. break;
  671. case 6:
  672. audio_format.active_chnnls_msk = 0x3f;
  673. break;
  674. case 7:
  675. audio_format.active_chnnls_msk = 0x7f;
  676. break;
  677. case 8:
  678. audio_format.active_chnnls_msk = 0xff;
  679. break;
  680. default:
  681. return -EINVAL;
  682. }
  683. /*
  684. * the HDMI IP needs to enable four stereo channels when transmitting
  685. * more than 2 audio channels. Similarly, the channel count in the
  686. * Audio InfoFrame has to match the sample_present bits (some channels
  687. * are padded with zeroes)
  688. */
  689. if (channel_count == 2) {
  690. audio_format.stereo_channels = HDMI_AUDIO_STEREO_ONECHANNEL;
  691. acore.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN;
  692. acore.layout = HDMI_AUDIO_LAYOUT_2CH;
  693. } else {
  694. audio_format.stereo_channels = HDMI_AUDIO_STEREO_FOURCHANNELS;
  695. acore.i2s_cfg.active_sds = HDMI_AUDIO_I2S_SD0_EN |
  696. HDMI_AUDIO_I2S_SD1_EN | HDMI_AUDIO_I2S_SD2_EN |
  697. HDMI_AUDIO_I2S_SD3_EN;
  698. acore.layout = HDMI_AUDIO_LAYOUT_8CH;
  699. audio->cea->db1_ct_cc = 7;
  700. }
  701. acore.en_spdif = false;
  702. /* use sample frequency from channel status word */
  703. acore.fs_override = true;
  704. /* enable ACR packets */
  705. acore.en_acr_pkt = true;
  706. /* disable direct streaming digital audio */
  707. acore.en_dsd_audio = false;
  708. /* use parallel audio interface */
  709. acore.en_parallel_aud_input = true;
  710. /* DMA settings */
  711. if (word_length_16b)
  712. audio_dma.transfer_size = 0x10;
  713. else
  714. audio_dma.transfer_size = 0x20;
  715. audio_dma.block_size = 0xC0;
  716. audio_dma.mode = HDMI_AUDIO_TRANSF_DMA;
  717. audio_dma.fifo_threshold = 0x20; /* in number of samples */
  718. /* audio FIFO format settings */
  719. if (word_length_16b) {
  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. } else {
  724. audio_format.samples_per_word = HDMI_AUDIO_ONEWORD_ONESAMPLE;
  725. audio_format.sample_size = HDMI_AUDIO_SAMPLE_24BITS;
  726. audio_format.justification = HDMI_AUDIO_JUSTIFY_RIGHT;
  727. }
  728. audio_format.type = HDMI_AUDIO_TYPE_LPCM;
  729. audio_format.sample_order = HDMI_AUDIO_SAMPLE_LEFT_FIRST;
  730. /* disable start/stop signals of IEC 60958 blocks */
  731. audio_format.en_sig_blk_strt_end = HDMI_AUDIO_BLOCK_SIG_STARTEND_ON;
  732. /* configure DMA and audio FIFO format*/
  733. hdmi_wp_audio_config_dma(wp, &audio_dma);
  734. hdmi_wp_audio_config_format(wp, &audio_format);
  735. /* configure the core*/
  736. hdmi_core_audio_config(core, &acore);
  737. /* configure CEA 861 audio infoframe*/
  738. hdmi_core_audio_infoframe_cfg(core, audio->cea);
  739. return 0;
  740. }
  741. int hdmi4_audio_start(struct hdmi_core_data *core, struct hdmi_wp_data *wp)
  742. {
  743. REG_FLD_MOD(hdmi_av_base(core),
  744. HDMI_CORE_AV_AUD_MODE, true, 0, 0);
  745. hdmi_wp_audio_core_req_enable(wp, true);
  746. return 0;
  747. }
  748. void hdmi4_audio_stop(struct hdmi_core_data *core, struct hdmi_wp_data *wp)
  749. {
  750. REG_FLD_MOD(hdmi_av_base(core),
  751. HDMI_CORE_AV_AUD_MODE, false, 0, 0);
  752. hdmi_wp_audio_core_req_enable(wp, false);
  753. }
  754. int hdmi4_core_init(struct platform_device *pdev, struct hdmi_core_data *core)
  755. {
  756. struct resource *res;
  757. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
  758. if (!res) {
  759. DSSERR("can't get CORE mem resource\n");
  760. return -EINVAL;
  761. }
  762. core->base = devm_ioremap_resource(&pdev->dev, res);
  763. if (IS_ERR(core->base)) {
  764. DSSERR("can't ioremap CORE\n");
  765. return PTR_ERR(core->base);
  766. }
  767. return 0;
  768. }