ti_hdmi_4xxx_ip.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. }