ti_hdmi_4xxx_ip.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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, 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. 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 hdmi_pll_program(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. int hdmi_phy_init(struct hdmi_ip_data *ip_data)
  180. {
  181. u16 r = 0;
  182. void __iomem *phy_base = hdmi_phy_base(ip_data);
  183. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_LDOON);
  184. if (r)
  185. return r;
  186. r = hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_TXON);
  187. if (r)
  188. return r;
  189. /*
  190. * Read address 0 in order to get the SCP reset done completed
  191. * Dummy access performed to make sure reset is done
  192. */
  193. hdmi_read_reg(phy_base, HDMI_TXPHY_TX_CTRL);
  194. /*
  195. * Write to phy address 0 to configure the clock
  196. * use HFBITCLK write HDMI_TXPHY_TX_CONTROL_FREQOUT field
  197. */
  198. REG_FLD_MOD(phy_base, HDMI_TXPHY_TX_CTRL, 0x1, 31, 30);
  199. /* Write to phy address 1 to start HDMI line (TXVALID and TMDSCLKEN) */
  200. hdmi_write_reg(phy_base, HDMI_TXPHY_DIGITAL_CTRL, 0xF0000000);
  201. /* Setup max LDO voltage */
  202. REG_FLD_MOD(phy_base, HDMI_TXPHY_POWER_CTRL, 0xB, 3, 0);
  203. /* Write to phy address 3 to change the polarity control */
  204. REG_FLD_MOD(phy_base, HDMI_TXPHY_PAD_CFG_CTRL, 0x1, 27, 27);
  205. return 0;
  206. }
  207. void hdmi_phy_off(struct hdmi_ip_data *ip_data)
  208. {
  209. hdmi_set_phy_pwr(ip_data, HDMI_PHYPWRCMD_OFF);
  210. }
  211. static int hdmi_core_ddc_edid(struct hdmi_ip_data *ip_data,
  212. u8 *pedid, int ext)
  213. {
  214. u32 i, j;
  215. char checksum = 0;
  216. u32 offset = 0;
  217. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  218. /* Turn on CLK for DDC */
  219. REG_FLD_MOD(hdmi_av_base(ip_data), HDMI_CORE_AV_DPD, 0x7, 2, 0);
  220. /*
  221. * SW HACK : Without the Delay DDC(i2c bus) reads 0 values /
  222. * right shifted values( The behavior is not consistent and seen only
  223. * with some TV's)
  224. */
  225. usleep_range(800, 1000);
  226. if (!ext) {
  227. /* Clk SCL Devices */
  228. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0xA, 3, 0);
  229. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  230. if (hdmi_wait_for_bit_change(core_sys_base,
  231. HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
  232. pr_err("Failed to program DDC\n");
  233. return -ETIMEDOUT;
  234. }
  235. /* Clear FIFO */
  236. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x9, 3, 0);
  237. /* HDMI_CORE_DDC_STATUS_IN_PROG */
  238. if (hdmi_wait_for_bit_change(core_sys_base,
  239. HDMI_CORE_DDC_STATUS, 4, 4, 0) != 0) {
  240. pr_err("Failed to program DDC\n");
  241. return -ETIMEDOUT;
  242. }
  243. } else {
  244. if (ext % 2 != 0)
  245. offset = 0x80;
  246. }
  247. /* Load Segment Address Register */
  248. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_SEGM, ext/2, 7, 0);
  249. /* Load Slave Address Register */
  250. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
  251. /* Load Offset Address Register */
  252. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
  253. /* Load Byte Count */
  254. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
  255. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
  256. /* Set DDC_CMD */
  257. if (ext)
  258. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
  259. else
  260. REG_FLD_MOD(core_sys_base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
  261. /* HDMI_CORE_DDC_STATUS_BUS_LOW */
  262. if (REG_GET(core_sys_base,
  263. HDMI_CORE_DDC_STATUS, 6, 6) == 1) {
  264. pr_err("I2C Bus Low?\n");
  265. return -EIO;
  266. }
  267. /* HDMI_CORE_DDC_STATUS_NO_ACK */
  268. if (REG_GET(core_sys_base,
  269. HDMI_CORE_DDC_STATUS, 5, 5) == 1) {
  270. pr_err("I2C No Ack\n");
  271. return -EIO;
  272. }
  273. i = ext * 128;
  274. j = 0;
  275. while (((REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 4, 4) == 1) ||
  276. (REG_GET(core_sys_base,
  277. HDMI_CORE_DDC_STATUS, 2, 2) == 0)) && j < 128) {
  278. if (REG_GET(core_sys_base, HDMI_CORE_DDC_STATUS, 2, 2) == 0) {
  279. /* FIFO not empty */
  280. pedid[i++] = REG_GET(core_sys_base,
  281. HDMI_CORE_DDC_DATA, 7, 0);
  282. j++;
  283. }
  284. }
  285. for (j = 0; j < 128; j++)
  286. checksum += pedid[j];
  287. if (checksum != 0) {
  288. pr_err("E-EDID checksum failed!!\n");
  289. return -EIO;
  290. }
  291. return 0;
  292. }
  293. int read_edid(struct hdmi_ip_data *ip_data, u8 *pedid, u16 max_length)
  294. {
  295. int r = 0, n = 0, i = 0;
  296. int max_ext_blocks = (max_length / 128) - 1;
  297. r = hdmi_core_ddc_edid(ip_data, pedid, 0);
  298. if (r) {
  299. return r;
  300. } else {
  301. n = pedid[0x7e];
  302. /*
  303. * README: need to comply with max_length set by the caller.
  304. * Better implementation should be to allocate necessary
  305. * memory to store EDID according to nb_block field found
  306. * in first block
  307. */
  308. if (n > max_ext_blocks)
  309. n = max_ext_blocks;
  310. for (i = 1; i <= n; i++) {
  311. r = hdmi_core_ddc_edid(ip_data, pedid, i);
  312. if (r)
  313. return r;
  314. }
  315. }
  316. return 0;
  317. }
  318. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  319. struct hdmi_core_infoframe_avi *avi_cfg,
  320. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  321. {
  322. pr_debug("Enter hdmi_core_init\n");
  323. /* video core */
  324. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  325. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  326. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  327. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  328. video_cfg->hdmi_dvi = HDMI_DVI;
  329. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  330. /* info frame */
  331. avi_cfg->db1_format = 0;
  332. avi_cfg->db1_active_info = 0;
  333. avi_cfg->db1_bar_info_dv = 0;
  334. avi_cfg->db1_scan_info = 0;
  335. avi_cfg->db2_colorimetry = 0;
  336. avi_cfg->db2_aspect_ratio = 0;
  337. avi_cfg->db2_active_fmt_ar = 0;
  338. avi_cfg->db3_itc = 0;
  339. avi_cfg->db3_ec = 0;
  340. avi_cfg->db3_q_range = 0;
  341. avi_cfg->db3_nup_scaling = 0;
  342. avi_cfg->db4_videocode = 0;
  343. avi_cfg->db5_pixel_repeat = 0;
  344. avi_cfg->db6_7_line_eoftop = 0 ;
  345. avi_cfg->db8_9_line_sofbottom = 0;
  346. avi_cfg->db10_11_pixel_eofleft = 0;
  347. avi_cfg->db12_13_pixel_sofright = 0;
  348. /* packet enable and repeat */
  349. repeat_cfg->audio_pkt = 0;
  350. repeat_cfg->audio_pkt_repeat = 0;
  351. repeat_cfg->avi_infoframe = 0;
  352. repeat_cfg->avi_infoframe_repeat = 0;
  353. repeat_cfg->gen_cntrl_pkt = 0;
  354. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  355. repeat_cfg->generic_pkt = 0;
  356. repeat_cfg->generic_pkt_repeat = 0;
  357. }
  358. static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
  359. {
  360. pr_debug("Enter hdmi_core_powerdown_disable\n");
  361. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
  362. }
  363. static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
  364. {
  365. pr_debug("Enter hdmi_core_swreset_release\n");
  366. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  367. }
  368. static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
  369. {
  370. pr_debug("Enter hdmi_core_swreset_assert\n");
  371. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  372. }
  373. /* HDMI_CORE_VIDEO_CONFIG */
  374. static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
  375. struct hdmi_core_video_config *cfg)
  376. {
  377. u32 r = 0;
  378. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  379. /* sys_ctrl1 default configuration not tunable */
  380. r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
  381. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  382. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  383. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  384. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  385. hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
  386. REG_FLD_MOD(core_sys_base,
  387. HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  388. /* Vid_Mode */
  389. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
  390. /* dither truncation configuration */
  391. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  392. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  393. r = FLD_MOD(r, 1, 5, 5);
  394. } else {
  395. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  396. r = FLD_MOD(r, 0, 5, 5);
  397. }
  398. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
  399. /* HDMI_Ctrl */
  400. r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
  401. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  402. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  403. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  404. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
  405. /* TMDS_CTRL */
  406. REG_FLD_MOD(core_sys_base,
  407. HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
  408. }
  409. static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
  410. struct hdmi_core_infoframe_avi info_avi)
  411. {
  412. u32 val;
  413. char sum = 0, checksum = 0;
  414. void __iomem *av_base = hdmi_av_base(ip_data);
  415. sum += 0x82 + 0x002 + 0x00D;
  416. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
  417. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
  418. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
  419. val = (info_avi.db1_format << 5) |
  420. (info_avi.db1_active_info << 4) |
  421. (info_avi.db1_bar_info_dv << 2) |
  422. (info_avi.db1_scan_info);
  423. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
  424. sum += val;
  425. val = (info_avi.db2_colorimetry << 6) |
  426. (info_avi.db2_aspect_ratio << 4) |
  427. (info_avi.db2_active_fmt_ar);
  428. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
  429. sum += val;
  430. val = (info_avi.db3_itc << 7) |
  431. (info_avi.db3_ec << 4) |
  432. (info_avi.db3_q_range << 2) |
  433. (info_avi.db3_nup_scaling);
  434. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
  435. sum += val;
  436. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
  437. info_avi.db4_videocode);
  438. sum += info_avi.db4_videocode;
  439. val = info_avi.db5_pixel_repeat;
  440. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
  441. sum += val;
  442. val = info_avi.db6_7_line_eoftop & 0x00FF;
  443. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
  444. sum += val;
  445. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  446. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
  447. sum += val;
  448. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  449. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
  450. sum += val;
  451. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  452. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
  453. sum += val;
  454. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  455. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
  456. sum += val;
  457. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  458. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
  459. sum += val;
  460. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  461. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
  462. sum += val;
  463. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  464. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
  465. sum += val;
  466. checksum = 0x100 - sum;
  467. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
  468. }
  469. static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
  470. struct hdmi_core_packet_enable_repeat repeat_cfg)
  471. {
  472. /* enable/repeat the infoframe */
  473. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
  474. (repeat_cfg.audio_pkt << 5) |
  475. (repeat_cfg.audio_pkt_repeat << 4) |
  476. (repeat_cfg.avi_infoframe << 1) |
  477. (repeat_cfg.avi_infoframe_repeat));
  478. /* enable/repeat the packet */
  479. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
  480. (repeat_cfg.gen_cntrl_pkt << 3) |
  481. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  482. (repeat_cfg.generic_pkt << 1) |
  483. (repeat_cfg.generic_pkt_repeat));
  484. }
  485. static void hdmi_wp_init(struct omap_video_timings *timings,
  486. struct hdmi_video_format *video_fmt,
  487. struct hdmi_video_interface *video_int)
  488. {
  489. pr_debug("Enter hdmi_wp_init\n");
  490. timings->hbp = 0;
  491. timings->hfp = 0;
  492. timings->hsw = 0;
  493. timings->vbp = 0;
  494. timings->vfp = 0;
  495. timings->vsw = 0;
  496. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  497. video_fmt->y_res = 0;
  498. video_fmt->x_res = 0;
  499. video_int->vsp = 0;
  500. video_int->hsp = 0;
  501. video_int->interlacing = 0;
  502. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  503. }
  504. void hdmi_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
  505. {
  506. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
  507. }
  508. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  509. struct omap_video_timings *timings, struct hdmi_config *param)
  510. {
  511. pr_debug("Enter hdmi_wp_video_init_format\n");
  512. video_fmt->y_res = param->timings.timings.y_res;
  513. video_fmt->x_res = param->timings.timings.x_res;
  514. timings->hbp = param->timings.timings.hbp;
  515. timings->hfp = param->timings.timings.hfp;
  516. timings->hsw = param->timings.timings.hsw;
  517. timings->vbp = param->timings.timings.vbp;
  518. timings->vfp = param->timings.timings.vfp;
  519. timings->vsw = param->timings.timings.vsw;
  520. }
  521. static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
  522. struct hdmi_video_format *video_fmt)
  523. {
  524. u32 l = 0;
  525. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
  526. video_fmt->packing_mode, 10, 8);
  527. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  528. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  529. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
  530. }
  531. static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
  532. struct hdmi_video_interface *video_int)
  533. {
  534. u32 r;
  535. pr_debug("Enter hdmi_wp_video_config_interface\n");
  536. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
  537. r = FLD_MOD(r, video_int->vsp, 7, 7);
  538. r = FLD_MOD(r, video_int->hsp, 6, 6);
  539. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  540. r = FLD_MOD(r, video_int->tm, 1, 0);
  541. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
  542. }
  543. static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
  544. struct omap_video_timings *timings)
  545. {
  546. u32 timing_h = 0;
  547. u32 timing_v = 0;
  548. pr_debug("Enter hdmi_wp_video_config_timing\n");
  549. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  550. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  551. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  552. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
  553. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  554. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  555. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  556. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
  557. }
  558. void hdmi_basic_configure(struct hdmi_ip_data *ip_data)
  559. {
  560. /* HDMI */
  561. struct omap_video_timings video_timing;
  562. struct hdmi_video_format video_format;
  563. struct hdmi_video_interface video_interface;
  564. /* HDMI core */
  565. struct hdmi_core_infoframe_avi avi_cfg;
  566. struct hdmi_core_video_config v_core_cfg;
  567. struct hdmi_core_packet_enable_repeat repeat_cfg;
  568. struct hdmi_config *cfg = &ip_data->cfg;
  569. hdmi_wp_init(&video_timing, &video_format,
  570. &video_interface);
  571. hdmi_core_init(&v_core_cfg,
  572. &avi_cfg,
  573. &repeat_cfg);
  574. hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
  575. hdmi_wp_video_config_timing(ip_data, &video_timing);
  576. /* video config */
  577. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  578. hdmi_wp_video_config_format(ip_data, &video_format);
  579. video_interface.vsp = cfg->timings.vsync_pol;
  580. video_interface.hsp = cfg->timings.hsync_pol;
  581. video_interface.interlacing = cfg->interlace;
  582. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  583. hdmi_wp_video_config_interface(ip_data, &video_interface);
  584. /*
  585. * configure core video part
  586. * set software reset in the core
  587. */
  588. hdmi_core_swreset_assert(ip_data);
  589. /* power down off */
  590. hdmi_core_powerdown_disable(ip_data);
  591. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  592. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  593. hdmi_core_video_config(ip_data, &v_core_cfg);
  594. /* release software reset in the core */
  595. hdmi_core_swreset_release(ip_data);
  596. /*
  597. * configure packet
  598. * info frame video see doc CEA861-D page 65
  599. */
  600. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  601. avi_cfg.db1_active_info =
  602. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  603. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  604. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  605. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  606. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  607. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  608. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  609. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  610. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  611. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  612. avi_cfg.db4_videocode = cfg->cm.code;
  613. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  614. avi_cfg.db6_7_line_eoftop = 0;
  615. avi_cfg.db8_9_line_sofbottom = 0;
  616. avi_cfg.db10_11_pixel_eofleft = 0;
  617. avi_cfg.db12_13_pixel_sofright = 0;
  618. hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
  619. /* enable/repeat the infoframe */
  620. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  621. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  622. /* wakeup */
  623. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  624. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  625. hdmi_core_av_packet_config(ip_data, repeat_cfg);
  626. }
  627. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  628. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  629. void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
  630. struct hdmi_audio_format *aud_fmt)
  631. {
  632. u32 r;
  633. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  634. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
  635. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  636. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  637. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  638. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  639. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  640. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  641. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  642. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  643. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
  644. }
  645. void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
  646. struct hdmi_audio_dma *aud_dma)
  647. {
  648. u32 r;
  649. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  650. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
  651. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  652. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  653. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
  654. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
  655. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  656. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  657. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
  658. }
  659. void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
  660. struct hdmi_core_audio_config *cfg)
  661. {
  662. u32 r;
  663. void __iomem *av_base = hdmi_av_base(ip_data);
  664. /* audio clock recovery parameters */
  665. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  666. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  667. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  668. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  669. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  670. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  671. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  672. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  673. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  674. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  675. REG_FLD_MOD(av_base,
  676. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  677. REG_FLD_MOD(av_base,
  678. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  679. } else {
  680. /*
  681. * HDMI IP uses this configuration to divide the MCLK to
  682. * update CTS value.
  683. */
  684. REG_FLD_MOD(av_base,
  685. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  686. /* Configure clock for audio packets */
  687. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  688. cfg->aud_par_busclk, 7, 0);
  689. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  690. (cfg->aud_par_busclk >> 8), 7, 0);
  691. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  692. (cfg->aud_par_busclk >> 16), 7, 0);
  693. }
  694. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  695. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  696. cfg->fs_override, 1, 1);
  697. /* I2S parameters */
  698. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
  699. cfg->freq_sample, 3, 0);
  700. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  701. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  702. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  703. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  704. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  705. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  706. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  707. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  708. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  709. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  710. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
  711. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  712. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  713. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  714. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
  715. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  716. cfg->i2s_cfg.in_length_bits, 3, 0);
  717. /* Audio channels and mode parameters */
  718. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  719. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  720. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  721. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  722. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  723. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  724. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  725. }
  726. void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
  727. struct hdmi_core_infoframe_audio *info_aud)
  728. {
  729. u8 val;
  730. u8 sum = 0, checksum = 0;
  731. void __iomem *av_base = hdmi_av_base(ip_data);
  732. /*
  733. * Set audio info frame type, version and length as
  734. * described in HDMI 1.4a Section 8.2.2 specification.
  735. * Checksum calculation is defined in Section 5.3.5.
  736. */
  737. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  738. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  739. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  740. sum += 0x84 + 0x001 + 0x00a;
  741. val = (info_aud->db1_coding_type << 4)
  742. | (info_aud->db1_channel_count - 1);
  743. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
  744. sum += val;
  745. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  746. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
  747. sum += val;
  748. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  749. val = info_aud->db4_channel_alloc;
  750. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
  751. sum += val;
  752. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  753. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
  754. sum += val;
  755. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  756. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  757. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  758. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  759. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  760. checksum = 0x100 - sum;
  761. hdmi_write_reg(av_base,
  762. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  763. /*
  764. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  765. * is available.
  766. */
  767. }
  768. int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
  769. u32 sample_freq, u32 *n, u32 *cts)
  770. {
  771. u32 r;
  772. u32 deep_color = 0;
  773. u32 pclk = ip_data->cfg.timings.timings.pixel_clock;
  774. if (n == NULL || cts == NULL)
  775. return -EINVAL;
  776. /*
  777. * Obtain current deep color configuration. This needed
  778. * to calculate the TMDS clock based on the pixel clock.
  779. */
  780. r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
  781. switch (r) {
  782. case 1: /* No deep color selected */
  783. deep_color = 100;
  784. break;
  785. case 2: /* 10-bit deep color selected */
  786. deep_color = 125;
  787. break;
  788. case 3: /* 12-bit deep color selected */
  789. deep_color = 150;
  790. break;
  791. default:
  792. return -EINVAL;
  793. }
  794. switch (sample_freq) {
  795. case 32000:
  796. if ((deep_color == 125) && ((pclk == 54054)
  797. || (pclk == 74250)))
  798. *n = 8192;
  799. else
  800. *n = 4096;
  801. break;
  802. case 44100:
  803. *n = 6272;
  804. break;
  805. case 48000:
  806. if ((deep_color == 125) && ((pclk == 54054)
  807. || (pclk == 74250)))
  808. *n = 8192;
  809. else
  810. *n = 6144;
  811. break;
  812. default:
  813. *n = 0;
  814. return -EINVAL;
  815. }
  816. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  817. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  818. return 0;
  819. }
  820. int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
  821. struct snd_pcm_substream *substream, int cmd,
  822. struct snd_soc_dai *dai)
  823. {
  824. int err = 0;
  825. switch (cmd) {
  826. case SNDRV_PCM_TRIGGER_START:
  827. case SNDRV_PCM_TRIGGER_RESUME:
  828. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  829. REG_FLD_MOD(hdmi_av_base(ip_data),
  830. HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  831. REG_FLD_MOD(hdmi_wp_base(ip_data),
  832. HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  833. REG_FLD_MOD(hdmi_wp_base(ip_data),
  834. HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  835. break;
  836. case SNDRV_PCM_TRIGGER_STOP:
  837. case SNDRV_PCM_TRIGGER_SUSPEND:
  838. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  839. REG_FLD_MOD(hdmi_av_base(ip_data),
  840. HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  841. REG_FLD_MOD(hdmi_wp_base(ip_data),
  842. HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  843. REG_FLD_MOD(hdmi_wp_base(ip_data),
  844. HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  845. break;
  846. default:
  847. err = -EINVAL;
  848. }
  849. return err;
  850. }
  851. #endif