ti_hdmi_4xxx_ip.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/err.h>
  24. #include <linux/io.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/mutex.h>
  27. #include <linux/delay.h>
  28. #include <linux/string.h>
  29. #include "ti_hdmi_4xxx_ip.h"
  30. #include "dss.h"
  31. static inline void hdmi_write_reg(void __iomem *base_addr,
  32. const struct hdmi_reg idx, u32 val)
  33. {
  34. __raw_writel(val, base_addr + idx.idx);
  35. }
  36. static inline u32 hdmi_read_reg(void __iomem *base_addr,
  37. const struct hdmi_reg idx)
  38. {
  39. return __raw_readl(base_addr + idx.idx);
  40. }
  41. static inline void __iomem *hdmi_wp_base(struct hdmi_ip_data *ip_data)
  42. {
  43. return ip_data->base_wp;
  44. }
  45. static inline void __iomem *hdmi_phy_base(struct hdmi_ip_data *ip_data)
  46. {
  47. return ip_data->base_wp + ip_data->phy_offset;
  48. }
  49. static inline void __iomem *hdmi_pll_base(struct hdmi_ip_data *ip_data)
  50. {
  51. return ip_data->base_wp + ip_data->pll_offset;
  52. }
  53. static inline void __iomem *hdmi_av_base(struct hdmi_ip_data *ip_data)
  54. {
  55. return ip_data->base_wp + ip_data->core_av_offset;
  56. }
  57. static inline void __iomem *hdmi_core_sys_base(struct hdmi_ip_data *ip_data)
  58. {
  59. return ip_data->base_wp + ip_data->core_sys_offset;
  60. }
  61. static inline int hdmi_wait_for_bit_change(void __iomem *base_addr,
  62. const struct hdmi_reg idx,
  63. int b2, int b1, u32 val)
  64. {
  65. u32 t = 0;
  66. while (val != REG_GET(base_addr, idx, b2, b1)) {
  67. udelay(1);
  68. if (t++ > 10000)
  69. return !val;
  70. }
  71. return val;
  72. }
  73. static int hdmi_pll_init(struct hdmi_ip_data *ip_data)
  74. {
  75. u32 r;
  76. void __iomem *pll_base = hdmi_pll_base(ip_data);
  77. struct hdmi_pll_info *fmt = &ip_data->pll_data;
  78. /* PLL start always use manual mode */
  79. REG_FLD_MOD(pll_base, PLLCTRL_PLL_CONTROL, 0x0, 0, 0);
  80. r = hdmi_read_reg(pll_base, PLLCTRL_CFG1);
  81. r = FLD_MOD(r, fmt->regm, 20, 9); /* CFG1_PLL_REGM */
  82. r = FLD_MOD(r, fmt->regn - 1, 8, 1); /* CFG1_PLL_REGN */
  83. hdmi_write_reg(pll_base, PLLCTRL_CFG1, r);
  84. r = hdmi_read_reg(pll_base, PLLCTRL_CFG2);
  85. r = FLD_MOD(r, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */
  86. r = FLD_MOD(r, 0x1, 13, 13); /* PLL_REFEN */
  87. r = FLD_MOD(r, 0x0, 14, 14); /* PHY_CLKINEN de-assert during locking */
  88. r = FLD_MOD(r, fmt->refsel, 22, 21); /* REFSEL */
  89. if (fmt->dcofreq) {
  90. /* divider programming for frequency beyond 1000Mhz */
  91. REG_FLD_MOD(pll_base, PLLCTRL_CFG3, fmt->regsd, 17, 10);
  92. r = FLD_MOD(r, 0x4, 3, 1); /* 1000MHz and 2000MHz */
  93. } else {
  94. r = FLD_MOD(r, 0x2, 3, 1); /* 500MHz and 1000MHz */
  95. }
  96. hdmi_write_reg(pll_base, PLLCTRL_CFG2, r);
  97. r = hdmi_read_reg(pll_base, PLLCTRL_CFG4);
  98. r = FLD_MOD(r, fmt->regm2, 24, 18);
  99. r = FLD_MOD(r, fmt->regmf, 17, 0);
  100. hdmi_write_reg(pll_base, PLLCTRL_CFG4, r);
  101. /* go now */
  102. REG_FLD_MOD(pll_base, PLLCTRL_PLL_GO, 0x1, 0, 0);
  103. /* wait for bit change */
  104. if (hdmi_wait_for_bit_change(pll_base, PLLCTRL_PLL_GO,
  105. 0, 0, 1) != 1) {
  106. pr_err("PLL GO bit not set\n");
  107. return -ETIMEDOUT;
  108. }
  109. /* Wait till the lock bit is set in PLL status */
  110. if (hdmi_wait_for_bit_change(pll_base,
  111. PLLCTRL_PLL_STATUS, 1, 1, 1) != 1) {
  112. pr_err("cannot lock PLL\n");
  113. pr_err("CFG1 0x%x\n",
  114. hdmi_read_reg(pll_base, PLLCTRL_CFG1));
  115. pr_err("CFG2 0x%x\n",
  116. hdmi_read_reg(pll_base, PLLCTRL_CFG2));
  117. pr_err("CFG4 0x%x\n",
  118. hdmi_read_reg(pll_base, PLLCTRL_CFG4));
  119. return -ETIMEDOUT;
  120. }
  121. pr_debug("PLL locked!\n");
  122. return 0;
  123. }
  124. /* PHY_PWR_CMD */
  125. static int hdmi_set_phy_pwr(struct hdmi_ip_data *ip_data, enum hdmi_phy_pwr val)
  126. {
  127. /* Command for power control of HDMI PHY */
  128. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 7, 6);
  129. /* Status of the power control of HDMI PHY */
  130. if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data),
  131. HDMI_WP_PWR_CTRL, 5, 4, val) != val) {
  132. pr_err("Failed to set PHY power mode to %d\n", val);
  133. return -ETIMEDOUT;
  134. }
  135. return 0;
  136. }
  137. /* PLL_PWR_CMD */
  138. static int hdmi_set_pll_pwr(struct hdmi_ip_data *ip_data, enum hdmi_pll_pwr val)
  139. {
  140. /* Command for power control of HDMI PLL */
  141. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL, val, 3, 2);
  142. /* wait till PHY_PWR_STATUS is set */
  143. if (hdmi_wait_for_bit_change(hdmi_wp_base(ip_data), HDMI_WP_PWR_CTRL,
  144. 1, 0, val) != val) {
  145. pr_err("Failed to set PLL_PWR_STATUS\n");
  146. return -ETIMEDOUT;
  147. }
  148. return 0;
  149. }
  150. static int hdmi_pll_reset(struct hdmi_ip_data *ip_data)
  151. {
  152. /* SYSRESET controlled by power FSM */
  153. REG_FLD_MOD(hdmi_pll_base(ip_data), PLLCTRL_PLL_CONTROL, 0x0, 3, 3);
  154. /* READ 0x0 reset is in progress */
  155. if (hdmi_wait_for_bit_change(hdmi_pll_base(ip_data),
  156. PLLCTRL_PLL_STATUS, 0, 0, 1) != 1) {
  157. pr_err("Failed to sysreset PLL\n");
  158. return -ETIMEDOUT;
  159. }
  160. return 0;
  161. }
  162. int ti_hdmi_4xxx_pll_enable(struct hdmi_ip_data *ip_data)
  163. {
  164. u16 r = 0;
  165. r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
  166. if (r)
  167. return r;
  168. r = hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
  169. if (r)
  170. return r;
  171. r = hdmi_pll_reset(ip_data);
  172. if (r)
  173. return r;
  174. r = hdmi_pll_init(ip_data);
  175. if (r)
  176. return r;
  177. return 0;
  178. }
  179. void ti_hdmi_4xxx_pll_disable(struct hdmi_ip_data *ip_data)
  180. {
  181. hdmi_set_pll_pwr(ip_data, HDMI_PLLPWRCMD_ALLOFF);
  182. }
  183. int ti_hdmi_4xxx_phy_enable(struct hdmi_ip_data *ip_data)
  184. {
  185. u16 r = 0;
  186. void __iomem *phy_base = hdmi_phy_base(ip_data);
  187. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
  188. if (r)
  189. return r;
  190. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
  191. if (r)
  192. return r;
  193. /*
  194. * Read address 0 in order to get the SCP reset done completed
  195. * Dummy access performed to make sure reset is done
  196. */
  197. hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
  198. /*
  199. * Write to phy address 0 to configure the clock
  200. * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
  201. */
  202. REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
  203. /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
  204. hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
  205. /* Setup max LDO voltage */
  206. REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
  207. /* Write to phy address 3 to change the polarity control */
  208. REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
  209. return 0;
  210. }
  211. void ti_hdmi_4xxx_phy_disable(struct hdmi_ip_data *ip_data)
  212. {
  213. hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
  214. }
  215. static int hdmi_core_ddc_init(struct hdmi_ip_data *ip_data)
  216. {
  217. void __iomem *base = hdmi_core_sys_base(ip_data);
  218. /* Turn on CLK for DDC */
  219. REG_FLD_MOD(base, HDMI_CORE_AV_DPD, 0x7, 2, 0);
  220. /* IN_PROG */
  221. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) {
  222. /* Abort transaction */
  223. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xf, 3, 0);
  224. /* IN_PROG */
  225. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  226. 4, 4, 0) != 0) {
  227. DSSERR("Timeout aborting DDC transaction\n");
  228. return -ETIMEDOUT;
  229. }
  230. }
  231. /* Clk SCL Devices */
  232. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  233. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  234. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  235. 4, 4, 0) != 0) {
  236. DSSERR("Timeout starting SCL clock\n");
  237. return -ETIMEDOUT;
  238. }
  239. /* Clear FIFO */
  240. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  241. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  242. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  243. 4, 4, 0) != 0) {
  244. DSSERR("Timeout clearing DDC fifo\n");
  245. return -ETIMEDOUT;
  246. }
  247. return 0;
  248. }
  249. static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
  250. u8 *pedid, int ext)
  251. {
  252. void __iomem *base = hdmi_core_sys_base(ip_data);
  253. u32 i, j;
  254. char checksum = 0;
  255. u32 offset = 0;
  256. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  257. if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
  258. 4, 4, 0) != 0) {
  259. DSSERR("Timeout waiting DDC to be ready\n");
  260. return -ETIMEDOUT;
  261. }
  262. if (ext % 2 != 0)
  263. offset = 0x80;
  264. /* Load Segment Address Register */
  265. REG_FLD_MOD(base, HDMI_CORE_DDC_SEGM, ext / 2, 7, 0);
  266. /* Load Slave Address Register */
  267. REG_FLD_MOD(base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  268. /* Load Offset Address Register */
  269. REG_FLD_MOD(base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  270. /* Load Byte Count */
  271. REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  272. REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  273. /* Set DDC_CMD */
  274. if (ext)
  275. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  276. else
  277. REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  278. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  279. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  280. pr_err("I2C Bus Low?\n");
  281. return -EIO;
  282. }
  283. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  284. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  285. pr_err("I2C No Ack\n");
  286. return -EIO;
  287. }
  288. i = ext * 128;
  289. j = 0;
  290. while (((REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
  291. (REG_GET(base, HDMI_CORE_DDC_STATUS, 2, 2) == 0)) &&
  292. j < 128) {
  293. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
  294. /* FIFO not empty */
  295. pedid[i++] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
  296. j++;
  297. }
  298. }
  299. for (j = 0; j < 128; j++)
  300. checksum += pedid[j];
  301. if (checksum != 0) {
  302. pr_err("E-EDID checksum failed!!\n");
  303. return -EIO;
  304. }
  305. return 0;
  306. }
  307. int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data,
  308. u8 *pedid, u16 max_length)
  309. {
  310. int r = 0, n = 0, i = 0;
  311. int max_ext_blocks = (max_length / 128) - 1;
  312. int len;
  313. r = hdmi_core_ddc_init(ip_data);
  314. if (r)
  315. return r;
  316. r = hdmi_core_ddc_edid(ip_data, pedid, 0);
  317. if (r)
  318. return r;
  319. len = 128;
  320. n = pedid[0x7e];
  321. /*
  322. * README: need to comply with max_length set by the caller.
  323. * Better implementation should be to allocate necessary
  324. * memory to store EDID according to nb_block field found
  325. * in first block
  326. */
  327. if (n > max_ext_blocks)
  328. n = max_ext_blocks;
  329. for (i = 1; i <= n; i++) {
  330. r = hdmi_core_ddc_edid(ip_data, pedid, i);
  331. if (r)
  332. return r;
  333. len += 128;
  334. }
  335. return len;
  336. }
  337. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  338. struct hdmi_core_infoframe_avi *avi_cfg,
  339. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  340. {
  341. pr_debug("Enter hdmi_core_init\n");
  342. /* video core */
  343. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  344. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  345. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  346. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  347. video_cfg->hdmi_dvi = HDMI_DVI;
  348. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  349. /* info frame */
  350. avi_cfg->db1_format = 0;
  351. avi_cfg->db1_active_info = 0;
  352. avi_cfg->db1_bar_info_dv = 0;
  353. avi_cfg->db1_scan_info = 0;
  354. avi_cfg->db2_colorimetry = 0;
  355. avi_cfg->db2_aspect_ratio = 0;
  356. avi_cfg->db2_active_fmt_ar = 0;
  357. avi_cfg->db3_itc = 0;
  358. avi_cfg->db3_ec = 0;
  359. avi_cfg->db3_q_range = 0;
  360. avi_cfg->db3_nup_scaling = 0;
  361. avi_cfg->db4_videocode = 0;
  362. avi_cfg->db5_pixel_repeat = 0;
  363. avi_cfg->db6_7_line_eoftop = 0 ;
  364. avi_cfg->db8_9_line_sofbottom = 0;
  365. avi_cfg->db10_11_pixel_eofleft = 0;
  366. avi_cfg->db12_13_pixel_sofright = 0;
  367. /* packet enable and repeat */
  368. repeat_cfg->audio_pkt = 0;
  369. repeat_cfg->audio_pkt_repeat = 0;
  370. repeat_cfg->avi_infoframe = 0;
  371. repeat_cfg->avi_infoframe_repeat = 0;
  372. repeat_cfg->gen_cntrl_pkt = 0;
  373. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  374. repeat_cfg->generic_pkt = 0;
  375. repeat_cfg->generic_pkt_repeat = 0;
  376. }
  377. static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
  378. {
  379. pr_debug("Enter hdmi_core_powerdown_disable\n");
  380. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
  381. }
  382. static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
  383. {
  384. pr_debug("Enter hdmi_core_swreset_release\n");
  385. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  386. }
  387. static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
  388. {
  389. pr_debug("Enter hdmi_core_swreset_assert\n");
  390. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  391. }
  392. /* HDMI_CORE_VIDEO_CONFIG */
  393. static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
  394. struct hdmi_core_video_config *cfg)
  395. {
  396. u32 r = 0;
  397. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  398. /* sys_ctrl1 default configuration not tunable */
  399. r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
  400. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  401. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  402. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  403. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  404. hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
  405. REG_FLD_MOD(core_sys_base,
  406. HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  407. /* Vid_Mode */
  408. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
  409. /* dither truncation configuration */
  410. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  411. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  412. r = FLD_MOD(r, 1, 5, 5);
  413. } else {
  414. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  415. r = FLD_MOD(r, 0, 5, 5);
  416. }
  417. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
  418. /* HDMI_Ctrl */
  419. r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
  420. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  421. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  422. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  423. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
  424. /* TMDS_CTRL */
  425. REG_FLD_MOD(core_sys_base,
  426. HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
  427. }
  428. static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
  429. struct hdmi_core_infoframe_avi info_avi)
  430. {
  431. u32 val;
  432. char sum = 0, checksum = 0;
  433. void __iomem *av_base = hdmi_av_base(ip_data);
  434. sum += 0x82 + 0x002 + 0x00D;
  435. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
  436. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
  437. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
  438. val = (info_avi.db1_format << 5) |
  439. (info_avi.db1_active_info << 4) |
  440. (info_avi.db1_bar_info_dv << 2) |
  441. (info_avi.db1_scan_info);
  442. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
  443. sum += val;
  444. val = (info_avi.db2_colorimetry << 6) |
  445. (info_avi.db2_aspect_ratio << 4) |
  446. (info_avi.db2_active_fmt_ar);
  447. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
  448. sum += val;
  449. val = (info_avi.db3_itc << 7) |
  450. (info_avi.db3_ec << 4) |
  451. (info_avi.db3_q_range << 2) |
  452. (info_avi.db3_nup_scaling);
  453. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
  454. sum += val;
  455. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
  456. info_avi.db4_videocode);
  457. sum += info_avi.db4_videocode;
  458. val = info_avi.db5_pixel_repeat;
  459. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
  460. sum += val;
  461. val = info_avi.db6_7_line_eoftop & 0x00FF;
  462. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
  463. sum += val;
  464. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  465. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
  466. sum += val;
  467. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  468. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
  469. sum += val;
  470. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  471. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
  472. sum += val;
  473. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  474. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
  475. sum += val;
  476. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  477. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
  478. sum += val;
  479. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  480. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
  481. sum += val;
  482. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  483. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
  484. sum += val;
  485. checksum = 0x100 - sum;
  486. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
  487. }
  488. static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
  489. struct hdmi_core_packet_enable_repeat repeat_cfg)
  490. {
  491. /* enable/repeat the infoframe */
  492. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
  493. (repeat_cfg.audio_pkt << 5) |
  494. (repeat_cfg.audio_pkt_repeat << 4) |
  495. (repeat_cfg.avi_infoframe << 1) |
  496. (repeat_cfg.avi_infoframe_repeat));
  497. /* enable/repeat the packet */
  498. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
  499. (repeat_cfg.gen_cntrl_pkt << 3) |
  500. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  501. (repeat_cfg.generic_pkt << 1) |
  502. (repeat_cfg.generic_pkt_repeat));
  503. }
  504. static void hdmi_wp_init(struct omap_video_timings *timings,
  505. struct hdmi_video_format *video_fmt,
  506. struct hdmi_video_interface *video_int)
  507. {
  508. pr_debug("Enter hdmi_wp_init\n");
  509. timings->hbp = 0;
  510. timings->hfp = 0;
  511. timings->hsw = 0;
  512. timings->vbp = 0;
  513. timings->vfp = 0;
  514. timings->vsw = 0;
  515. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  516. video_fmt->y_res = 0;
  517. video_fmt->x_res = 0;
  518. video_int->vsp = 0;
  519. video_int->hsp = 0;
  520. video_int->interlacing = 0;
  521. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  522. }
  523. void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
  524. {
  525. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
  526. }
  527. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  528. struct omap_video_timings *timings, struct hdmi_config *param)
  529. {
  530. pr_debug("Enter hdmi_wp_video_init_format\n");
  531. video_fmt->y_res = param->timings.timings.y_res;
  532. video_fmt->x_res = param->timings.timings.x_res;
  533. timings->hbp = param->timings.timings.hbp;
  534. timings->hfp = param->timings.timings.hfp;
  535. timings->hsw = param->timings.timings.hsw;
  536. timings->vbp = param->timings.timings.vbp;
  537. timings->vfp = param->timings.timings.vfp;
  538. timings->vsw = param->timings.timings.vsw;
  539. }
  540. static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
  541. struct hdmi_video_format *video_fmt)
  542. {
  543. u32 l = 0;
  544. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
  545. video_fmt->packing_mode, 10, 8);
  546. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  547. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  548. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
  549. }
  550. static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
  551. struct hdmi_video_interface *video_int)
  552. {
  553. u32 r;
  554. pr_debug("Enter hdmi_wp_video_config_interface\n");
  555. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
  556. r = FLD_MOD(r, video_int->vsp, 7, 7);
  557. r = FLD_MOD(r, video_int->hsp, 6, 6);
  558. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  559. r = FLD_MOD(r, video_int->tm, 1, 0);
  560. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
  561. }
  562. static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
  563. struct omap_video_timings *timings)
  564. {
  565. u32 timing_h = 0;
  566. u32 timing_v = 0;
  567. pr_debug("Enter hdmi_wp_video_config_timing\n");
  568. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  569. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  570. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  571. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
  572. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  573. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  574. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  575. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
  576. }
  577. void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data)
  578. {
  579. /* HDMI */
  580. struct omap_video_timings video_timing;
  581. struct hdmi_video_format video_format;
  582. struct hdmi_video_interface video_interface;
  583. /* HDMI core */
  584. struct hdmi_core_infoframe_avi avi_cfg;
  585. struct hdmi_core_video_config v_core_cfg;
  586. struct hdmi_core_packet_enable_repeat repeat_cfg;
  587. struct hdmi_config *cfg = &ip_data->cfg;
  588. hdmi_wp_init(&video_timing, &video_format,
  589. &video_interface);
  590. hdmi_core_init(&v_core_cfg,
  591. &avi_cfg,
  592. &repeat_cfg);
  593. hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
  594. hdmi_wp_video_config_timing(ip_data, &video_timing);
  595. /* video config */
  596. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  597. hdmi_wp_video_config_format(ip_data, &video_format);
  598. video_interface.vsp = cfg->timings.vsync_pol;
  599. video_interface.hsp = cfg->timings.hsync_pol;
  600. video_interface.interlacing = cfg->interlace;
  601. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  602. hdmi_wp_video_config_interface(ip_data, &video_interface);
  603. /*
  604. * configure core video part
  605. * set software reset in the core
  606. */
  607. hdmi_core_swreset_assert(ip_data);
  608. /* power down off */
  609. hdmi_core_powerdown_disable(ip_data);
  610. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  611. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  612. hdmi_core_video_config(ip_data, &v_core_cfg);
  613. /* release software reset in the core */
  614. hdmi_core_swreset_release(ip_data);
  615. /*
  616. * configure packet
  617. * info frame video see doc CEA861-D page 65
  618. */
  619. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  620. avi_cfg.db1_active_info =
  621. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  622. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  623. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  624. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  625. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  626. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  627. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  628. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  629. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  630. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  631. avi_cfg.db4_videocode = cfg->cm.code;
  632. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  633. avi_cfg.db6_7_line_eoftop = 0;
  634. avi_cfg.db8_9_line_sofbottom = 0;
  635. avi_cfg.db10_11_pixel_eofleft = 0;
  636. avi_cfg.db12_13_pixel_sofright = 0;
  637. hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
  638. /* enable/repeat the infoframe */
  639. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  640. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  641. /* wakeup */
  642. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  643. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  644. hdmi_core_av_packet_config(ip_data, repeat_cfg);
  645. }
  646. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  647. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  648. void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
  649. struct hdmi_audio_format *aud_fmt)
  650. {
  651. u32 r;
  652. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  653. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
  654. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  655. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  656. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  657. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  658. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  659. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  660. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  661. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  662. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
  663. }
  664. void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
  665. struct hdmi_audio_dma *aud_dma)
  666. {
  667. u32 r;
  668. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  669. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
  670. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  671. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  672. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
  673. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
  674. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  675. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  676. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
  677. }
  678. void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
  679. struct hdmi_core_audio_config *cfg)
  680. {
  681. u32 r;
  682. void __iomem *av_base = hdmi_av_base(ip_data);
  683. /* audio clock recovery parameters */
  684. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  685. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  686. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  687. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  688. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  689. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  690. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  691. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  692. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  693. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  694. REG_FLD_MOD(av_base,
  695. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  696. REG_FLD_MOD(av_base,
  697. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  698. } else {
  699. /*
  700. * HDMI IP uses this configuration to divide the MCLK to
  701. * update CTS value.
  702. */
  703. REG_FLD_MOD(av_base,
  704. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  705. /* Configure clock for audio packets */
  706. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  707. cfg->aud_par_busclk, 7, 0);
  708. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  709. (cfg->aud_par_busclk >> 8), 7, 0);
  710. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  711. (cfg->aud_par_busclk >> 16), 7, 0);
  712. }
  713. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  714. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  715. cfg->fs_override, 1, 1);
  716. /* I2S parameters */
  717. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
  718. cfg->freq_sample, 3, 0);
  719. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  720. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  721. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  722. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  723. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  724. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  725. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  726. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  727. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  728. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  729. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
  730. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  731. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  732. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  733. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
  734. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  735. cfg->i2s_cfg.in_length_bits, 3, 0);
  736. /* Audio channels and mode parameters */
  737. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  738. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  739. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  740. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  741. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  742. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  743. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  744. }
  745. void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
  746. struct hdmi_core_infoframe_audio *info_aud)
  747. {
  748. u8 val;
  749. u8 sum = 0, checksum = 0;
  750. void __iomem *av_base = hdmi_av_base(ip_data);
  751. /*
  752. * Set audio info frame type, version and length as
  753. * described in HDMI 1.4a Section 8.2.2 specification.
  754. * Checksum calculation is defined in Section 5.3.5.
  755. */
  756. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  757. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  758. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  759. sum += 0x84 + 0x001 + 0x00a;
  760. val = (info_aud->db1_coding_type << 4)
  761. | (info_aud->db1_channel_count - 1);
  762. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
  763. sum += val;
  764. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  765. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
  766. sum += val;
  767. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  768. val = info_aud->db4_channel_alloc;
  769. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
  770. sum += val;
  771. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  772. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
  773. sum += val;
  774. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  775. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  776. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  777. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  778. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  779. checksum = 0x100 - sum;
  780. hdmi_write_reg(av_base,
  781. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  782. /*
  783. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  784. * is available.
  785. */
  786. }
  787. int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
  788. u32 sample_freq, u32 *n, u32 *cts)
  789. {
  790. u32 r;
  791. u32 deep_color = 0;
  792. u32 pclk = ip_data->cfg.timings.timings.pixel_clock;
  793. if (n == NULL || cts == NULL)
  794. return -EINVAL;
  795. /*
  796. * Obtain current deep color configuration. This needed
  797. * to calculate the TMDS clock based on the pixel clock.
  798. */
  799. r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
  800. switch (r) {
  801. case 1: /* No deep color selected */
  802. deep_color = 100;
  803. break;
  804. case 2: /* 10-bit deep color selected */
  805. deep_color = 125;
  806. break;
  807. case 3: /* 12-bit deep color selected */
  808. deep_color = 150;
  809. break;
  810. default:
  811. return -EINVAL;
  812. }
  813. switch (sample_freq) {
  814. case 32000:
  815. if ((deep_color == 125) && ((pclk == 54054)
  816. || (pclk == 74250)))
  817. *n = 8192;
  818. else
  819. *n = 4096;
  820. break;
  821. case 44100:
  822. *n = 6272;
  823. break;
  824. case 48000:
  825. if ((deep_color == 125) && ((pclk == 54054)
  826. || (pclk == 74250)))
  827. *n = 8192;
  828. else
  829. *n = 6144;
  830. break;
  831. default:
  832. *n = 0;
  833. return -EINVAL;
  834. }
  835. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  836. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  837. return 0;
  838. }
  839. int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
  840. struct snd_pcm_substream *substream, int cmd,
  841. struct snd_soc_dai *dai)
  842. {
  843. int err = 0;
  844. switch (cmd) {
  845. case SNDRV_PCM_TRIGGER_START:
  846. case SNDRV_PCM_TRIGGER_RESUME:
  847. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  848. REG_FLD_MOD(hdmi_av_base(ip_data),
  849. HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  850. REG_FLD_MOD(hdmi_wp_base(ip_data),
  851. HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  852. REG_FLD_MOD(hdmi_wp_base(ip_data),
  853. HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  854. break;
  855. case SNDRV_PCM_TRIGGER_STOP:
  856. case SNDRV_PCM_TRIGGER_SUSPEND:
  857. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  858. REG_FLD_MOD(hdmi_av_base(ip_data),
  859. HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  860. REG_FLD_MOD(hdmi_wp_base(ip_data),
  861. HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  862. REG_FLD_MOD(hdmi_wp_base(ip_data),
  863. HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  864. break;
  865. default:
  866. err = -EINVAL;
  867. }
  868. return err;
  869. }
  870. #endif