ti_hdmi_4xxx_ip.c 35 KB

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