ti_hdmi_4xxx_ip.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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;
  254. char checksum;
  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. for (i = 0; i < 0x80; ++i) {
  289. int t;
  290. /* IN_PROG */
  291. if (REG_GET(base, HDMI_CORE_DDC_STATUS, 4, 4) == 0) {
  292. DSSERR("operation stopped when reading edid\n");
  293. return -EIO;
  294. }
  295. t = 0;
  296. /* FIFO_EMPTY */
  297. while (REG_GET(base, HDMI_CORE_DDC_STATUS, 2, 2) == 1) {
  298. if (t++ > 10000) {
  299. DSSERR("timeout reading edid\n");
  300. return -ETIMEDOUT;
  301. }
  302. udelay(1);
  303. }
  304. pedid[i] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
  305. }
  306. checksum = 0;
  307. for (i = 0; i < 0x80; ++i)
  308. checksum += pedid[i];
  309. if (checksum != 0) {
  310. pr_err("E-EDID checksum failed!!\n");
  311. return -EIO;
  312. }
  313. return 0;
  314. }
  315. int ti_hdmi_4xxx_read_edid(struct hdmi_ip_data *ip_data,
  316. u8 *edid, int len)
  317. {
  318. int r, l;
  319. if (len < 128)
  320. return -EINVAL;
  321. r = hdmi_core_ddc_init(ip_data);
  322. if (r)
  323. return r;
  324. r = hdmi_core_ddc_edid(ip_data, edid, 0);
  325. if (r)
  326. return r;
  327. l = 128;
  328. if (len >= 128 * 2 && edid[0x7e] > 0) {
  329. r = hdmi_core_ddc_edid(ip_data, edid + 0x80, 1);
  330. if (r)
  331. return r;
  332. l += 128;
  333. }
  334. return l;
  335. }
  336. static void hdmi_core_init(struct hdmi_core_video_config *video_cfg,
  337. struct hdmi_core_infoframe_avi *avi_cfg,
  338. struct hdmi_core_packet_enable_repeat *repeat_cfg)
  339. {
  340. pr_debug("Enter hdmi_core_init\n");
  341. /* video core */
  342. video_cfg->ip_bus_width = HDMI_INPUT_8BIT;
  343. video_cfg->op_dither_truc = HDMI_OUTPUTTRUNCATION_8BIT;
  344. video_cfg->deep_color_pkt = HDMI_DEEPCOLORPACKECTDISABLE;
  345. video_cfg->pkt_mode = HDMI_PACKETMODERESERVEDVALUE;
  346. video_cfg->hdmi_dvi = HDMI_DVI;
  347. video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
  348. /* info frame */
  349. avi_cfg->db1_format = 0;
  350. avi_cfg->db1_active_info = 0;
  351. avi_cfg->db1_bar_info_dv = 0;
  352. avi_cfg->db1_scan_info = 0;
  353. avi_cfg->db2_colorimetry = 0;
  354. avi_cfg->db2_aspect_ratio = 0;
  355. avi_cfg->db2_active_fmt_ar = 0;
  356. avi_cfg->db3_itc = 0;
  357. avi_cfg->db3_ec = 0;
  358. avi_cfg->db3_q_range = 0;
  359. avi_cfg->db3_nup_scaling = 0;
  360. avi_cfg->db4_videocode = 0;
  361. avi_cfg->db5_pixel_repeat = 0;
  362. avi_cfg->db6_7_line_eoftop = 0 ;
  363. avi_cfg->db8_9_line_sofbottom = 0;
  364. avi_cfg->db10_11_pixel_eofleft = 0;
  365. avi_cfg->db12_13_pixel_sofright = 0;
  366. /* packet enable and repeat */
  367. repeat_cfg->audio_pkt = 0;
  368. repeat_cfg->audio_pkt_repeat = 0;
  369. repeat_cfg->avi_infoframe = 0;
  370. repeat_cfg->avi_infoframe_repeat = 0;
  371. repeat_cfg->gen_cntrl_pkt = 0;
  372. repeat_cfg->gen_cntrl_pkt_repeat = 0;
  373. repeat_cfg->generic_pkt = 0;
  374. repeat_cfg->generic_pkt_repeat = 0;
  375. }
  376. static void hdmi_core_powerdown_disable(struct hdmi_ip_data *ip_data)
  377. {
  378. pr_debug("Enter hdmi_core_powerdown_disable\n");
  379. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_CTRL1, 0x0, 0, 0);
  380. }
  381. static void hdmi_core_swreset_release(struct hdmi_ip_data *ip_data)
  382. {
  383. pr_debug("Enter hdmi_core_swreset_release\n");
  384. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x0, 0, 0);
  385. }
  386. static void hdmi_core_swreset_assert(struct hdmi_ip_data *ip_data)
  387. {
  388. pr_debug("Enter hdmi_core_swreset_assert\n");
  389. REG_FLD_MOD(hdmi_core_sys_base(ip_data), HDMI_CORE_SYS_SRST, 0x1, 0, 0);
  390. }
  391. /* HDMI_CORE_VIDEO_CONFIG */
  392. static void hdmi_core_video_config(struct hdmi_ip_data *ip_data,
  393. struct hdmi_core_video_config *cfg)
  394. {
  395. u32 r = 0;
  396. void __iomem *core_sys_base = hdmi_core_sys_base(ip_data);
  397. /* sys_ctrl1 default configuration not tunable */
  398. r = hdmi_read_reg(core_sys_base, HDMI_CORE_CTRL1);
  399. r = FLD_MOD(r, HDMI_CORE_CTRL1_VEN_FOLLOWVSYNC, 5, 5);
  400. r = FLD_MOD(r, HDMI_CORE_CTRL1_HEN_FOLLOWHSYNC, 4, 4);
  401. r = FLD_MOD(r, HDMI_CORE_CTRL1_BSEL_24BITBUS, 2, 2);
  402. r = FLD_MOD(r, HDMI_CORE_CTRL1_EDGE_RISINGEDGE, 1, 1);
  403. hdmi_write_reg(core_sys_base, HDMI_CORE_CTRL1, r);
  404. REG_FLD_MOD(core_sys_base,
  405. HDMI_CORE_SYS_VID_ACEN, cfg->ip_bus_width, 7, 6);
  406. /* Vid_Mode */
  407. r = hdmi_read_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE);
  408. /* dither truncation configuration */
  409. if (cfg->op_dither_truc > HDMI_OUTPUTTRUNCATION_12BIT) {
  410. r = FLD_MOD(r, cfg->op_dither_truc - 3, 7, 6);
  411. r = FLD_MOD(r, 1, 5, 5);
  412. } else {
  413. r = FLD_MOD(r, cfg->op_dither_truc, 7, 6);
  414. r = FLD_MOD(r, 0, 5, 5);
  415. }
  416. hdmi_write_reg(core_sys_base, HDMI_CORE_SYS_VID_MODE, r);
  417. /* HDMI_Ctrl */
  418. r = hdmi_read_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL);
  419. r = FLD_MOD(r, cfg->deep_color_pkt, 6, 6);
  420. r = FLD_MOD(r, cfg->pkt_mode, 5, 3);
  421. r = FLD_MOD(r, cfg->hdmi_dvi, 0, 0);
  422. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_HDMI_CTRL, r);
  423. /* TMDS_CTRL */
  424. REG_FLD_MOD(core_sys_base,
  425. HDMI_CORE_SYS_TMDS_CTRL, cfg->tclk_sel_clkmult, 6, 5);
  426. }
  427. static void hdmi_core_aux_infoframe_avi_config(struct hdmi_ip_data *ip_data,
  428. struct hdmi_core_infoframe_avi info_avi)
  429. {
  430. u32 val;
  431. char sum = 0, checksum = 0;
  432. void __iomem *av_base = hdmi_av_base(ip_data);
  433. sum += 0x82 + 0x002 + 0x00D;
  434. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_TYPE, 0x082);
  435. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_VERS, 0x002);
  436. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_LEN, 0x00D);
  437. val = (info_avi.db1_format << 5) |
  438. (info_avi.db1_active_info << 4) |
  439. (info_avi.db1_bar_info_dv << 2) |
  440. (info_avi.db1_scan_info);
  441. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(0), val);
  442. sum += val;
  443. val = (info_avi.db2_colorimetry << 6) |
  444. (info_avi.db2_aspect_ratio << 4) |
  445. (info_avi.db2_active_fmt_ar);
  446. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(1), val);
  447. sum += val;
  448. val = (info_avi.db3_itc << 7) |
  449. (info_avi.db3_ec << 4) |
  450. (info_avi.db3_q_range << 2) |
  451. (info_avi.db3_nup_scaling);
  452. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(2), val);
  453. sum += val;
  454. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(3),
  455. info_avi.db4_videocode);
  456. sum += info_avi.db4_videocode;
  457. val = info_avi.db5_pixel_repeat;
  458. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(4), val);
  459. sum += val;
  460. val = info_avi.db6_7_line_eoftop & 0x00FF;
  461. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(5), val);
  462. sum += val;
  463. val = ((info_avi.db6_7_line_eoftop >> 8) & 0x00FF);
  464. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(6), val);
  465. sum += val;
  466. val = info_avi.db8_9_line_sofbottom & 0x00FF;
  467. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(7), val);
  468. sum += val;
  469. val = ((info_avi.db8_9_line_sofbottom >> 8) & 0x00FF);
  470. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(8), val);
  471. sum += val;
  472. val = info_avi.db10_11_pixel_eofleft & 0x00FF;
  473. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(9), val);
  474. sum += val;
  475. val = ((info_avi.db10_11_pixel_eofleft >> 8) & 0x00FF);
  476. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(10), val);
  477. sum += val;
  478. val = info_avi.db12_13_pixel_sofright & 0x00FF;
  479. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(11), val);
  480. sum += val;
  481. val = ((info_avi.db12_13_pixel_sofright >> 8) & 0x00FF);
  482. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_DBYTE(12), val);
  483. sum += val;
  484. checksum = 0x100 - sum;
  485. hdmi_write_reg(av_base, HDMI_CORE_AV_AVI_CHSUM, checksum);
  486. }
  487. static void hdmi_core_av_packet_config(struct hdmi_ip_data *ip_data,
  488. struct hdmi_core_packet_enable_repeat repeat_cfg)
  489. {
  490. /* enable/repeat the infoframe */
  491. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL1,
  492. (repeat_cfg.audio_pkt << 5) |
  493. (repeat_cfg.audio_pkt_repeat << 4) |
  494. (repeat_cfg.avi_infoframe << 1) |
  495. (repeat_cfg.avi_infoframe_repeat));
  496. /* enable/repeat the packet */
  497. hdmi_write_reg(hdmi_av_base(ip_data), HDMI_CORE_AV_PB_CTRL2,
  498. (repeat_cfg.gen_cntrl_pkt << 3) |
  499. (repeat_cfg.gen_cntrl_pkt_repeat << 2) |
  500. (repeat_cfg.generic_pkt << 1) |
  501. (repeat_cfg.generic_pkt_repeat));
  502. }
  503. static void hdmi_wp_init(struct omap_video_timings *timings,
  504. struct hdmi_video_format *video_fmt,
  505. struct hdmi_video_interface *video_int)
  506. {
  507. pr_debug("Enter hdmi_wp_init\n");
  508. timings->hbp = 0;
  509. timings->hfp = 0;
  510. timings->hsw = 0;
  511. timings->vbp = 0;
  512. timings->vfp = 0;
  513. timings->vsw = 0;
  514. video_fmt->packing_mode = HDMI_PACK_10b_RGB_YUV444;
  515. video_fmt->y_res = 0;
  516. video_fmt->x_res = 0;
  517. video_int->vsp = 0;
  518. video_int->hsp = 0;
  519. video_int->interlacing = 0;
  520. video_int->tm = 0; /* HDMI_TIMING_SLAVE */
  521. }
  522. void ti_hdmi_4xxx_wp_video_start(struct hdmi_ip_data *ip_data, bool start)
  523. {
  524. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, start, 31, 31);
  525. }
  526. static void hdmi_wp_video_init_format(struct hdmi_video_format *video_fmt,
  527. struct omap_video_timings *timings, struct hdmi_config *param)
  528. {
  529. pr_debug("Enter hdmi_wp_video_init_format\n");
  530. video_fmt->y_res = param->timings.timings.y_res;
  531. video_fmt->x_res = param->timings.timings.x_res;
  532. timings->hbp = param->timings.timings.hbp;
  533. timings->hfp = param->timings.timings.hfp;
  534. timings->hsw = param->timings.timings.hsw;
  535. timings->vbp = param->timings.timings.vbp;
  536. timings->vfp = param->timings.timings.vfp;
  537. timings->vsw = param->timings.timings.vsw;
  538. }
  539. static void hdmi_wp_video_config_format(struct hdmi_ip_data *ip_data,
  540. struct hdmi_video_format *video_fmt)
  541. {
  542. u32 l = 0;
  543. REG_FLD_MOD(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG,
  544. video_fmt->packing_mode, 10, 8);
  545. l |= FLD_VAL(video_fmt->y_res, 31, 16);
  546. l |= FLD_VAL(video_fmt->x_res, 15, 0);
  547. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_SIZE, l);
  548. }
  549. static void hdmi_wp_video_config_interface(struct hdmi_ip_data *ip_data,
  550. struct hdmi_video_interface *video_int)
  551. {
  552. u32 r;
  553. pr_debug("Enter hdmi_wp_video_config_interface\n");
  554. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG);
  555. r = FLD_MOD(r, video_int->vsp, 7, 7);
  556. r = FLD_MOD(r, video_int->hsp, 6, 6);
  557. r = FLD_MOD(r, video_int->interlacing, 3, 3);
  558. r = FLD_MOD(r, video_int->tm, 1, 0);
  559. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, r);
  560. }
  561. static void hdmi_wp_video_config_timing(struct hdmi_ip_data *ip_data,
  562. struct omap_video_timings *timings)
  563. {
  564. u32 timing_h = 0;
  565. u32 timing_v = 0;
  566. pr_debug("Enter hdmi_wp_video_config_timing\n");
  567. timing_h |= FLD_VAL(timings->hbp, 31, 20);
  568. timing_h |= FLD_VAL(timings->hfp, 19, 8);
  569. timing_h |= FLD_VAL(timings->hsw, 7, 0);
  570. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_H, timing_h);
  571. timing_v |= FLD_VAL(timings->vbp, 31, 20);
  572. timing_v |= FLD_VAL(timings->vfp, 19, 8);
  573. timing_v |= FLD_VAL(timings->vsw, 7, 0);
  574. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_TIMING_V, timing_v);
  575. }
  576. void ti_hdmi_4xxx_basic_configure(struct hdmi_ip_data *ip_data)
  577. {
  578. /* HDMI */
  579. struct omap_video_timings video_timing;
  580. struct hdmi_video_format video_format;
  581. struct hdmi_video_interface video_interface;
  582. /* HDMI core */
  583. struct hdmi_core_infoframe_avi avi_cfg;
  584. struct hdmi_core_video_config v_core_cfg;
  585. struct hdmi_core_packet_enable_repeat repeat_cfg;
  586. struct hdmi_config *cfg = &ip_data->cfg;
  587. hdmi_wp_init(&video_timing, &video_format,
  588. &video_interface);
  589. hdmi_core_init(&v_core_cfg,
  590. &avi_cfg,
  591. &repeat_cfg);
  592. hdmi_wp_video_init_format(&video_format, &video_timing, cfg);
  593. hdmi_wp_video_config_timing(ip_data, &video_timing);
  594. /* video config */
  595. video_format.packing_mode = HDMI_PACK_24b_RGB_YUV444_YUV422;
  596. hdmi_wp_video_config_format(ip_data, &video_format);
  597. video_interface.vsp = cfg->timings.vsync_pol;
  598. video_interface.hsp = cfg->timings.hsync_pol;
  599. video_interface.interlacing = cfg->interlace;
  600. video_interface.tm = 1 ; /* HDMI_TIMING_MASTER_24BIT */
  601. hdmi_wp_video_config_interface(ip_data, &video_interface);
  602. /*
  603. * configure core video part
  604. * set software reset in the core
  605. */
  606. hdmi_core_swreset_assert(ip_data);
  607. /* power down off */
  608. hdmi_core_powerdown_disable(ip_data);
  609. v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
  610. v_core_cfg.hdmi_dvi = cfg->cm.mode;
  611. hdmi_core_video_config(ip_data, &v_core_cfg);
  612. /* release software reset in the core */
  613. hdmi_core_swreset_release(ip_data);
  614. /*
  615. * configure packet
  616. * info frame video see doc CEA861-D page 65
  617. */
  618. avi_cfg.db1_format = HDMI_INFOFRAME_AVI_DB1Y_RGB;
  619. avi_cfg.db1_active_info =
  620. HDMI_INFOFRAME_AVI_DB1A_ACTIVE_FORMAT_OFF;
  621. avi_cfg.db1_bar_info_dv = HDMI_INFOFRAME_AVI_DB1B_NO;
  622. avi_cfg.db1_scan_info = HDMI_INFOFRAME_AVI_DB1S_0;
  623. avi_cfg.db2_colorimetry = HDMI_INFOFRAME_AVI_DB2C_NO;
  624. avi_cfg.db2_aspect_ratio = HDMI_INFOFRAME_AVI_DB2M_NO;
  625. avi_cfg.db2_active_fmt_ar = HDMI_INFOFRAME_AVI_DB2R_SAME;
  626. avi_cfg.db3_itc = HDMI_INFOFRAME_AVI_DB3ITC_NO;
  627. avi_cfg.db3_ec = HDMI_INFOFRAME_AVI_DB3EC_XVYUV601;
  628. avi_cfg.db3_q_range = HDMI_INFOFRAME_AVI_DB3Q_DEFAULT;
  629. avi_cfg.db3_nup_scaling = HDMI_INFOFRAME_AVI_DB3SC_NO;
  630. avi_cfg.db4_videocode = cfg->cm.code;
  631. avi_cfg.db5_pixel_repeat = HDMI_INFOFRAME_AVI_DB5PR_NO;
  632. avi_cfg.db6_7_line_eoftop = 0;
  633. avi_cfg.db8_9_line_sofbottom = 0;
  634. avi_cfg.db10_11_pixel_eofleft = 0;
  635. avi_cfg.db12_13_pixel_sofright = 0;
  636. hdmi_core_aux_infoframe_avi_config(ip_data, avi_cfg);
  637. /* enable/repeat the infoframe */
  638. repeat_cfg.avi_infoframe = HDMI_PACKETENABLE;
  639. repeat_cfg.avi_infoframe_repeat = HDMI_PACKETREPEATON;
  640. /* wakeup */
  641. repeat_cfg.audio_pkt = HDMI_PACKETENABLE;
  642. repeat_cfg.audio_pkt_repeat = HDMI_PACKETREPEATON;
  643. hdmi_core_av_packet_config(ip_data, repeat_cfg);
  644. }
  645. #if defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI) || \
  646. defined(CONFIG_SND_OMAP_SOC_OMAP4_HDMI_MODULE)
  647. void hdmi_wp_audio_config_format(struct hdmi_ip_data *ip_data,
  648. struct hdmi_audio_format *aud_fmt)
  649. {
  650. u32 r;
  651. DSSDBG("Enter hdmi_wp_audio_config_format\n");
  652. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG);
  653. r = FLD_MOD(r, aud_fmt->stereo_channels, 26, 24);
  654. r = FLD_MOD(r, aud_fmt->active_chnnls_msk, 23, 16);
  655. r = FLD_MOD(r, aud_fmt->en_sig_blk_strt_end, 5, 5);
  656. r = FLD_MOD(r, aud_fmt->type, 4, 4);
  657. r = FLD_MOD(r, aud_fmt->justification, 3, 3);
  658. r = FLD_MOD(r, aud_fmt->sample_order, 2, 2);
  659. r = FLD_MOD(r, aud_fmt->samples_per_word, 1, 1);
  660. r = FLD_MOD(r, aud_fmt->sample_size, 0, 0);
  661. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG, r);
  662. }
  663. void hdmi_wp_audio_config_dma(struct hdmi_ip_data *ip_data,
  664. struct hdmi_audio_dma *aud_dma)
  665. {
  666. u32 r;
  667. DSSDBG("Enter hdmi_wp_audio_config_dma\n");
  668. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2);
  669. r = FLD_MOD(r, aud_dma->transfer_size, 15, 8);
  670. r = FLD_MOD(r, aud_dma->block_size, 7, 0);
  671. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CFG2, r);
  672. r = hdmi_read_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL);
  673. r = FLD_MOD(r, aud_dma->mode, 9, 9);
  674. r = FLD_MOD(r, aud_dma->fifo_threshold, 8, 0);
  675. hdmi_write_reg(hdmi_wp_base(ip_data), HDMI_WP_AUDIO_CTRL, r);
  676. }
  677. void hdmi_core_audio_config(struct hdmi_ip_data *ip_data,
  678. struct hdmi_core_audio_config *cfg)
  679. {
  680. u32 r;
  681. void __iomem *av_base = hdmi_av_base(ip_data);
  682. /* audio clock recovery parameters */
  683. r = hdmi_read_reg(av_base, HDMI_CORE_AV_ACR_CTRL);
  684. r = FLD_MOD(r, cfg->use_mclk, 2, 2);
  685. r = FLD_MOD(r, cfg->en_acr_pkt, 1, 1);
  686. r = FLD_MOD(r, cfg->cts_mode, 0, 0);
  687. hdmi_write_reg(av_base, HDMI_CORE_AV_ACR_CTRL, r);
  688. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL1, cfg->n, 7, 0);
  689. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL2, cfg->n >> 8, 7, 0);
  690. REG_FLD_MOD(av_base, HDMI_CORE_AV_N_SVAL3, cfg->n >> 16, 7, 0);
  691. if (cfg->cts_mode == HDMI_AUDIO_CTS_MODE_SW) {
  692. REG_FLD_MOD(av_base, HDMI_CORE_AV_CTS_SVAL1, cfg->cts, 7, 0);
  693. REG_FLD_MOD(av_base,
  694. HDMI_CORE_AV_CTS_SVAL2, cfg->cts >> 8, 7, 0);
  695. REG_FLD_MOD(av_base,
  696. HDMI_CORE_AV_CTS_SVAL3, cfg->cts >> 16, 7, 0);
  697. } else {
  698. /*
  699. * HDMI IP uses this configuration to divide the MCLK to
  700. * update CTS value.
  701. */
  702. REG_FLD_MOD(av_base,
  703. HDMI_CORE_AV_FREQ_SVAL, cfg->mclk_mode, 2, 0);
  704. /* Configure clock for audio packets */
  705. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_1,
  706. cfg->aud_par_busclk, 7, 0);
  707. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_2,
  708. (cfg->aud_par_busclk >> 8), 7, 0);
  709. REG_FLD_MOD(av_base, HDMI_CORE_AV_AUD_PAR_BUSCLK_3,
  710. (cfg->aud_par_busclk >> 16), 7, 0);
  711. }
  712. /* Override of SPDIF sample frequency with value in I2S_CHST4 */
  713. REG_FLD_MOD(av_base, HDMI_CORE_AV_SPDIF_CTRL,
  714. cfg->fs_override, 1, 1);
  715. /* I2S parameters */
  716. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_CHST4,
  717. cfg->freq_sample, 3, 0);
  718. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL);
  719. r = FLD_MOD(r, cfg->i2s_cfg.en_high_bitrate_aud, 7, 7);
  720. r = FLD_MOD(r, cfg->i2s_cfg.sck_edge_mode, 6, 6);
  721. r = FLD_MOD(r, cfg->i2s_cfg.cbit_order, 5, 5);
  722. r = FLD_MOD(r, cfg->i2s_cfg.vbit, 4, 4);
  723. r = FLD_MOD(r, cfg->i2s_cfg.ws_polarity, 3, 3);
  724. r = FLD_MOD(r, cfg->i2s_cfg.justification, 2, 2);
  725. r = FLD_MOD(r, cfg->i2s_cfg.direction, 1, 1);
  726. r = FLD_MOD(r, cfg->i2s_cfg.shift, 0, 0);
  727. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_IN_CTRL, r);
  728. r = hdmi_read_reg(av_base, HDMI_CORE_AV_I2S_CHST5);
  729. r = FLD_MOD(r, cfg->freq_sample, 7, 4);
  730. r = FLD_MOD(r, cfg->i2s_cfg.word_length, 3, 1);
  731. r = FLD_MOD(r, cfg->i2s_cfg.word_max_length, 0, 0);
  732. hdmi_write_reg(av_base, HDMI_CORE_AV_I2S_CHST5, r);
  733. REG_FLD_MOD(av_base, HDMI_CORE_AV_I2S_IN_LEN,
  734. cfg->i2s_cfg.in_length_bits, 3, 0);
  735. /* Audio channels and mode parameters */
  736. REG_FLD_MOD(av_base, HDMI_CORE_AV_HDMI_CTRL, cfg->layout, 2, 1);
  737. r = hdmi_read_reg(av_base, HDMI_CORE_AV_AUD_MODE);
  738. r = FLD_MOD(r, cfg->i2s_cfg.active_sds, 7, 4);
  739. r = FLD_MOD(r, cfg->en_dsd_audio, 3, 3);
  740. r = FLD_MOD(r, cfg->en_parallel_aud_input, 2, 2);
  741. r = FLD_MOD(r, cfg->en_spdif, 1, 1);
  742. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_MODE, r);
  743. }
  744. void hdmi_core_audio_infoframe_config(struct hdmi_ip_data *ip_data,
  745. struct hdmi_core_infoframe_audio *info_aud)
  746. {
  747. u8 val;
  748. u8 sum = 0, checksum = 0;
  749. void __iomem *av_base = hdmi_av_base(ip_data);
  750. /*
  751. * Set audio info frame type, version and length as
  752. * described in HDMI 1.4a Section 8.2.2 specification.
  753. * Checksum calculation is defined in Section 5.3.5.
  754. */
  755. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_TYPE, 0x84);
  756. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_VERS, 0x01);
  757. hdmi_write_reg(av_base, HDMI_CORE_AV_AUDIO_LEN, 0x0a);
  758. sum += 0x84 + 0x001 + 0x00a;
  759. val = (info_aud->db1_coding_type << 4)
  760. | (info_aud->db1_channel_count - 1);
  761. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(0), val);
  762. sum += val;
  763. val = (info_aud->db2_sample_freq << 2) | info_aud->db2_sample_size;
  764. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(1), val);
  765. sum += val;
  766. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(2), 0x00);
  767. val = info_aud->db4_channel_alloc;
  768. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(3), val);
  769. sum += val;
  770. val = (info_aud->db5_downmix_inh << 7) | (info_aud->db5_lsv << 3);
  771. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(4), val);
  772. sum += val;
  773. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(5), 0x00);
  774. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(6), 0x00);
  775. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(7), 0x00);
  776. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(8), 0x00);
  777. hdmi_write_reg(av_base, HDMI_CORE_AV_AUD_DBYTE(9), 0x00);
  778. checksum = 0x100 - sum;
  779. hdmi_write_reg(av_base,
  780. HDMI_CORE_AV_AUDIO_CHSUM, checksum);
  781. /*
  782. * TODO: Add MPEG and SPD enable and repeat cfg when EDID parsing
  783. * is available.
  784. */
  785. }
  786. int hdmi_config_audio_acr(struct hdmi_ip_data *ip_data,
  787. u32 sample_freq, u32 *n, u32 *cts)
  788. {
  789. u32 r;
  790. u32 deep_color = 0;
  791. u32 pclk = ip_data->cfg.timings.timings.pixel_clock;
  792. if (n == NULL || cts == NULL)
  793. return -EINVAL;
  794. /*
  795. * Obtain current deep color configuration. This needed
  796. * to calculate the TMDS clock based on the pixel clock.
  797. */
  798. r = REG_GET(hdmi_wp_base(ip_data), HDMI_WP_VIDEO_CFG, 1, 0);
  799. switch (r) {
  800. case 1: /* No deep color selected */
  801. deep_color = 100;
  802. break;
  803. case 2: /* 10-bit deep color selected */
  804. deep_color = 125;
  805. break;
  806. case 3: /* 12-bit deep color selected */
  807. deep_color = 150;
  808. break;
  809. default:
  810. return -EINVAL;
  811. }
  812. switch (sample_freq) {
  813. case 32000:
  814. if ((deep_color == 125) && ((pclk == 54054)
  815. || (pclk == 74250)))
  816. *n = 8192;
  817. else
  818. *n = 4096;
  819. break;
  820. case 44100:
  821. *n = 6272;
  822. break;
  823. case 48000:
  824. if ((deep_color == 125) && ((pclk == 54054)
  825. || (pclk == 74250)))
  826. *n = 8192;
  827. else
  828. *n = 6144;
  829. break;
  830. default:
  831. *n = 0;
  832. return -EINVAL;
  833. }
  834. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  835. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  836. return 0;
  837. }
  838. int hdmi_audio_trigger(struct hdmi_ip_data *ip_data,
  839. struct snd_pcm_substream *substream, int cmd,
  840. struct snd_soc_dai *dai)
  841. {
  842. int err = 0;
  843. switch (cmd) {
  844. case SNDRV_PCM_TRIGGER_START:
  845. case SNDRV_PCM_TRIGGER_RESUME:
  846. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  847. REG_FLD_MOD(hdmi_av_base(ip_data),
  848. HDMI_CORE_AV_AUD_MODE, 1, 0, 0);
  849. REG_FLD_MOD(hdmi_wp_base(ip_data),
  850. HDMI_WP_AUDIO_CTRL, 1, 31, 31);
  851. REG_FLD_MOD(hdmi_wp_base(ip_data),
  852. HDMI_WP_AUDIO_CTRL, 1, 30, 30);
  853. break;
  854. case SNDRV_PCM_TRIGGER_STOP:
  855. case SNDRV_PCM_TRIGGER_SUSPEND:
  856. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  857. REG_FLD_MOD(hdmi_av_base(ip_data),
  858. HDMI_CORE_AV_AUD_MODE, 0, 0, 0);
  859. REG_FLD_MOD(hdmi_wp_base(ip_data),
  860. HDMI_WP_AUDIO_CTRL, 0, 30, 30);
  861. REG_FLD_MOD(hdmi_wp_base(ip_data),
  862. HDMI_WP_AUDIO_CTRL, 0, 31, 31);
  863. break;
  864. default:
  865. err = -EINVAL;
  866. }
  867. return err;
  868. }
  869. #endif