hdmi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * hdmi.c
  3. *
  4. * HDMI interface DSS driver setting for TI's OMAP4 family of processor.
  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. #define DSS_SUBSYS_NAME "HDMI"
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/io.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/mutex.h>
  28. #include <linux/delay.h>
  29. #include <linux/string.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/pm_runtime.h>
  32. #include <linux/clk.h>
  33. #include <video/omapdss.h>
  34. #include "ti_hdmi.h"
  35. #include "dss.h"
  36. #include "dss_features.h"
  37. #define HDMI_WP 0x0
  38. #define HDMI_CORE_SYS 0x400
  39. #define HDMI_CORE_AV 0x900
  40. #define HDMI_PLLCTRL 0x200
  41. #define HDMI_PHY 0x300
  42. /* HDMI EDID Length move this */
  43. #define HDMI_EDID_MAX_LENGTH 256
  44. #define EDID_TIMING_DESCRIPTOR_SIZE 0x12
  45. #define EDID_DESCRIPTOR_BLOCK0_ADDRESS 0x36
  46. #define EDID_DESCRIPTOR_BLOCK1_ADDRESS 0x80
  47. #define EDID_SIZE_BLOCK0_TIMING_DESCRIPTOR 4
  48. #define EDID_SIZE_BLOCK1_TIMING_DESCRIPTOR 4
  49. #define HDMI_DEFAULT_REGN 16
  50. #define HDMI_DEFAULT_REGM2 1
  51. static struct {
  52. struct mutex lock;
  53. struct platform_device *pdev;
  54. struct hdmi_ip_data ip_data;
  55. struct clk *sys_clk;
  56. } hdmi;
  57. /*
  58. * Logic for the below structure :
  59. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  60. * There is a correspondence between CEA/VESA timing and code, please
  61. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  62. *
  63. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  64. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  65. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  66. * with code_vesa. Code_index is used for back mapping, that is once EDID
  67. * is read from the TV, EDID is parsed to find the timing values and then
  68. * map it to corresponding CEA or VESA index.
  69. */
  70. static const struct hdmi_config cea_timings[] = {
  71. { {640, 480, 25200, 96, 16, 48, 2, 10, 33, 0, 0, 0}, {1, HDMI_HDMI} },
  72. { {720, 480, 27027, 62, 16, 60, 6, 9, 30, 0, 0, 0}, {2, HDMI_HDMI} },
  73. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20, 1, 1, 0}, {4, HDMI_HDMI} },
  74. { {1920, 540, 74250, 44, 88, 148, 5, 2, 15, 1, 1, 1}, {5, HDMI_HDMI} },
  75. { {1440, 240, 27027, 124, 38, 114, 3, 4, 15, 0, 0, 1}, {6, HDMI_HDMI} },
  76. { {1920, 1080, 148500, 44, 88, 148, 5, 4, 36, 1, 1, 0}, {16, HDMI_HDMI} },
  77. { {720, 576, 27000, 64, 12, 68, 5, 5, 39, 0, 0, 0}, {17, HDMI_HDMI} },
  78. { {1280, 720, 74250, 40, 440, 220, 5, 5, 20, 1, 1, 0}, {19, HDMI_HDMI} },
  79. { {1920, 540, 74250, 44, 528, 148, 5, 2, 15, 1, 1, 1}, {20, HDMI_HDMI} },
  80. { {1440, 288, 27000, 126, 24, 138, 3, 2, 19, 0, 0, 1}, {21, HDMI_HDMI} },
  81. { {1440, 576, 54000, 128, 24, 136, 5, 5, 39, 0, 0, 0}, {29, HDMI_HDMI} },
  82. { {1920, 1080, 148500, 44, 528, 148, 5, 4, 36, 1, 1, 0}, {31, HDMI_HDMI} },
  83. { {1920, 1080, 74250, 44, 638, 148, 5, 4, 36, 1, 1, 0}, {32, HDMI_HDMI} },
  84. { {2880, 480, 108108, 248, 64, 240, 6, 9, 30, 0, 0, 0}, {35, HDMI_HDMI} },
  85. { {2880, 576, 108000, 256, 48, 272, 5, 5, 39, 0, 0, 0}, {37, HDMI_HDMI} },
  86. };
  87. static const struct hdmi_config vesa_timings[] = {
  88. /* VESA From Here */
  89. { {640, 480, 25175, 96, 16, 48, 2 , 11, 31, 0, 0, 0}, {4, HDMI_DVI} },
  90. { {800, 600, 40000, 128, 40, 88, 4 , 1, 23, 1, 1, 0}, {9, HDMI_DVI} },
  91. { {848, 480, 33750, 112, 16, 112, 8 , 6, 23, 1, 1, 0}, {0xE, HDMI_DVI} },
  92. { {1280, 768, 79500, 128, 64, 192, 7 , 3, 20, 1, 0, 0}, {0x17, HDMI_DVI} },
  93. { {1280, 800, 83500, 128, 72, 200, 6 , 3, 22, 1, 0, 0}, {0x1C, HDMI_DVI} },
  94. { {1360, 768, 85500, 112, 64, 256, 6 , 3, 18, 1, 1, 0}, {0x27, HDMI_DVI} },
  95. { {1280, 960, 108000, 112, 96, 312, 3 , 1, 36, 1, 1, 0}, {0x20, HDMI_DVI} },
  96. { {1280, 1024, 108000, 112, 48, 248, 3 , 1, 38, 1, 1, 0}, {0x23, HDMI_DVI} },
  97. { {1024, 768, 65000, 136, 24, 160, 6, 3, 29, 0, 0, 0}, {0x10, HDMI_DVI} },
  98. { {1400, 1050, 121750, 144, 88, 232, 4, 3, 32, 1, 0, 0}, {0x2A, HDMI_DVI} },
  99. { {1440, 900, 106500, 152, 80, 232, 6, 3, 25, 1, 0, 0}, {0x2F, HDMI_DVI} },
  100. { {1680, 1050, 146250, 176 , 104, 280, 6, 3, 30, 1, 0, 0}, {0x3A, HDMI_DVI} },
  101. { {1366, 768, 85500, 143, 70, 213, 3, 3, 24, 1, 1, 0}, {0x51, HDMI_DVI} },
  102. { {1920, 1080, 148500, 44, 148, 80, 5, 4, 36, 1, 1, 0}, {0x52, HDMI_DVI} },
  103. { {1280, 768, 68250, 32, 48, 80, 7, 3, 12, 0, 1, 0}, {0x16, HDMI_DVI} },
  104. { {1400, 1050, 101000, 32, 48, 80, 4, 3, 23, 0, 1, 0}, {0x29, HDMI_DVI} },
  105. { {1680, 1050, 119000, 32, 48, 80, 6, 3, 21, 0, 1, 0}, {0x39, HDMI_DVI} },
  106. { {1280, 800, 79500, 32, 48, 80, 6, 3, 14, 0, 1, 0}, {0x1B, HDMI_DVI} },
  107. { {1280, 720, 74250, 40, 110, 220, 5, 5, 20, 1, 1, 0}, {0x55, HDMI_DVI} }
  108. };
  109. static int hdmi_runtime_get(void)
  110. {
  111. int r;
  112. DSSDBG("hdmi_runtime_get\n");
  113. r = pm_runtime_get_sync(&hdmi.pdev->dev);
  114. WARN_ON(r < 0);
  115. if (r < 0)
  116. return r;
  117. return 0;
  118. }
  119. static void hdmi_runtime_put(void)
  120. {
  121. int r;
  122. DSSDBG("hdmi_runtime_put\n");
  123. r = pm_runtime_put_sync(&hdmi.pdev->dev);
  124. WARN_ON(r < 0);
  125. }
  126. static int __init hdmi_init_display(struct omap_dss_device *dssdev)
  127. {
  128. DSSDBG("init_display\n");
  129. dss_init_hdmi_ip_ops(&hdmi.ip_data);
  130. return 0;
  131. }
  132. static const struct hdmi_config *hdmi_find_timing(
  133. const struct hdmi_config *timings_arr,
  134. int len)
  135. {
  136. int i;
  137. for (i = 0; i < len; i++) {
  138. if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
  139. return &timings_arr[i];
  140. }
  141. return NULL;
  142. }
  143. static const struct hdmi_config *hdmi_get_timings(void)
  144. {
  145. const struct hdmi_config *arr;
  146. int len;
  147. if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
  148. arr = vesa_timings;
  149. len = ARRAY_SIZE(vesa_timings);
  150. } else {
  151. arr = cea_timings;
  152. len = ARRAY_SIZE(cea_timings);
  153. }
  154. return hdmi_find_timing(arr, len);
  155. }
  156. static bool hdmi_timings_compare(struct omap_video_timings *timing1,
  157. const struct hdmi_video_timings *timing2)
  158. {
  159. int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
  160. if ((timing2->pixel_clock == timing1->pixel_clock) &&
  161. (timing2->x_res == timing1->x_res) &&
  162. (timing2->y_res == timing1->y_res)) {
  163. timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
  164. timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
  165. timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  166. timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  167. DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
  168. "timing2_hsync = %d timing2_vsync = %d\n",
  169. timing1_hsync, timing1_vsync,
  170. timing2_hsync, timing2_vsync);
  171. if ((timing1_hsync == timing2_hsync) &&
  172. (timing1_vsync == timing2_vsync)) {
  173. return true;
  174. }
  175. }
  176. return false;
  177. }
  178. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  179. {
  180. int i;
  181. struct hdmi_cm cm = {-1};
  182. DSSDBG("hdmi_get_code\n");
  183. for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
  184. if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
  185. cm = cea_timings[i].cm;
  186. goto end;
  187. }
  188. }
  189. for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
  190. if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
  191. cm = vesa_timings[i].cm;
  192. goto end;
  193. }
  194. }
  195. end: return cm;
  196. }
  197. unsigned long hdmi_get_pixel_clock(void)
  198. {
  199. /* HDMI Pixel Clock in Mhz */
  200. return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
  201. }
  202. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  203. struct hdmi_pll_info *pi)
  204. {
  205. unsigned long clkin, refclk;
  206. u32 mf;
  207. clkin = clk_get_rate(hdmi.sys_clk) / 10000;
  208. /*
  209. * Input clock is predivided by N + 1
  210. * out put of which is reference clk
  211. */
  212. if (dssdev->clocks.hdmi.regn == 0)
  213. pi->regn = HDMI_DEFAULT_REGN;
  214. else
  215. pi->regn = dssdev->clocks.hdmi.regn;
  216. refclk = clkin / pi->regn;
  217. if (dssdev->clocks.hdmi.regm2 == 0)
  218. pi->regm2 = HDMI_DEFAULT_REGM2;
  219. else
  220. pi->regm2 = dssdev->clocks.hdmi.regm2;
  221. /*
  222. * multiplier is pixel_clk/ref_clk
  223. * Multiplying by 100 to avoid fractional part removal
  224. */
  225. pi->regm = phy * pi->regm2 / refclk;
  226. /*
  227. * fractional multiplier is remainder of the difference between
  228. * multiplier and actual phy(required pixel clock thus should be
  229. * multiplied by 2^18(262144) divided by the reference clock
  230. */
  231. mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
  232. pi->regmf = pi->regm2 * mf / refclk;
  233. /*
  234. * Dcofreq should be set to 1 if required pixel clock
  235. * is greater than 1000MHz
  236. */
  237. pi->dcofreq = phy > 1000 * 100;
  238. pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
  239. /* Set the reference clock to sysclk reference */
  240. pi->refsel = HDMI_REFSEL_SYSCLK;
  241. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  242. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  243. }
  244. static int hdmi_power_on(struct omap_dss_device *dssdev)
  245. {
  246. int r;
  247. const struct hdmi_config *timing;
  248. struct omap_video_timings *p;
  249. unsigned long phy;
  250. r = hdmi_runtime_get();
  251. if (r)
  252. return r;
  253. dss_mgr_disable(dssdev->manager);
  254. p = &dssdev->panel.timings;
  255. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  256. dssdev->panel.timings.x_res,
  257. dssdev->panel.timings.y_res);
  258. timing = hdmi_get_timings();
  259. if (timing == NULL) {
  260. /* HDMI code 4 corresponds to 640 * 480 VGA */
  261. hdmi.ip_data.cfg.cm.code = 4;
  262. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  263. hdmi.ip_data.cfg.cm.mode = HDMI_DVI;
  264. hdmi.ip_data.cfg = vesa_timings[0];
  265. } else {
  266. hdmi.ip_data.cfg = *timing;
  267. }
  268. phy = p->pixel_clock;
  269. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  270. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  271. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  272. r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
  273. if (r) {
  274. DSSDBG("Failed to lock PLL\n");
  275. goto err;
  276. }
  277. r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
  278. if (r) {
  279. DSSDBG("Failed to start PHY\n");
  280. goto err;
  281. }
  282. hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
  283. /* Make selection of HDMI in DSS */
  284. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  285. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  286. * DSI PLL source as the clock selected by DSI PLL might not be
  287. * sufficient for the resolution selected / that can be changed
  288. * dynamically by user. This can be moved to single location , say
  289. * Boardfile.
  290. */
  291. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  292. /* bypass TV gamma table */
  293. dispc_enable_gamma_table(0);
  294. /* tv size */
  295. dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
  296. r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
  297. if (r)
  298. goto err_vid_enable;
  299. r = dss_mgr_enable(dssdev->manager);
  300. if (r)
  301. goto err_mgr_enable;
  302. return 0;
  303. err_mgr_enable:
  304. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  305. err_vid_enable:
  306. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  307. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  308. err:
  309. hdmi_runtime_put();
  310. return -EIO;
  311. }
  312. static void hdmi_power_off(struct omap_dss_device *dssdev)
  313. {
  314. dss_mgr_disable(dssdev->manager);
  315. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  316. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  317. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  318. hdmi_runtime_put();
  319. }
  320. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  321. struct omap_video_timings *timings)
  322. {
  323. struct hdmi_cm cm;
  324. cm = hdmi_get_code(timings);
  325. if (cm.code == -1) {
  326. return -EINVAL;
  327. }
  328. return 0;
  329. }
  330. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  331. {
  332. struct hdmi_cm cm;
  333. cm = hdmi_get_code(&dssdev->panel.timings);
  334. hdmi.ip_data.cfg.cm.code = cm.code;
  335. hdmi.ip_data.cfg.cm.mode = cm.mode;
  336. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  337. int r;
  338. hdmi_power_off(dssdev);
  339. r = hdmi_power_on(dssdev);
  340. if (r)
  341. DSSERR("failed to power on device\n");
  342. } else {
  343. dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
  344. }
  345. }
  346. static void hdmi_dump_regs(struct seq_file *s)
  347. {
  348. mutex_lock(&hdmi.lock);
  349. if (hdmi_runtime_get())
  350. return;
  351. hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
  352. hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
  353. hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
  354. hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
  355. hdmi_runtime_put();
  356. mutex_unlock(&hdmi.lock);
  357. }
  358. int omapdss_hdmi_read_edid(u8 *buf, int len)
  359. {
  360. int r;
  361. mutex_lock(&hdmi.lock);
  362. r = hdmi_runtime_get();
  363. BUG_ON(r);
  364. r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
  365. hdmi_runtime_put();
  366. mutex_unlock(&hdmi.lock);
  367. return r;
  368. }
  369. bool omapdss_hdmi_detect(void)
  370. {
  371. int r;
  372. mutex_lock(&hdmi.lock);
  373. r = hdmi_runtime_get();
  374. BUG_ON(r);
  375. r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
  376. hdmi_runtime_put();
  377. mutex_unlock(&hdmi.lock);
  378. return r == 1;
  379. }
  380. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  381. {
  382. struct omap_dss_hdmi_data *priv = dssdev->data;
  383. int r = 0;
  384. DSSDBG("ENTER hdmi_display_enable\n");
  385. mutex_lock(&hdmi.lock);
  386. if (dssdev->manager == NULL) {
  387. DSSERR("failed to enable display: no manager\n");
  388. r = -ENODEV;
  389. goto err0;
  390. }
  391. hdmi.ip_data.hpd_gpio = priv->hpd_gpio;
  392. r = omap_dss_start_device(dssdev);
  393. if (r) {
  394. DSSERR("failed to start device\n");
  395. goto err0;
  396. }
  397. if (dssdev->platform_enable) {
  398. r = dssdev->platform_enable(dssdev);
  399. if (r) {
  400. DSSERR("failed to enable GPIO's\n");
  401. goto err1;
  402. }
  403. }
  404. r = hdmi_power_on(dssdev);
  405. if (r) {
  406. DSSERR("failed to power on device\n");
  407. goto err2;
  408. }
  409. mutex_unlock(&hdmi.lock);
  410. return 0;
  411. err2:
  412. if (dssdev->platform_disable)
  413. dssdev->platform_disable(dssdev);
  414. err1:
  415. omap_dss_stop_device(dssdev);
  416. err0:
  417. mutex_unlock(&hdmi.lock);
  418. return r;
  419. }
  420. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  421. {
  422. DSSDBG("Enter hdmi_display_disable\n");
  423. mutex_lock(&hdmi.lock);
  424. hdmi_power_off(dssdev);
  425. if (dssdev->platform_disable)
  426. dssdev->platform_disable(dssdev);
  427. omap_dss_stop_device(dssdev);
  428. mutex_unlock(&hdmi.lock);
  429. }
  430. static int hdmi_get_clocks(struct platform_device *pdev)
  431. {
  432. struct clk *clk;
  433. clk = clk_get(&pdev->dev, "sys_clk");
  434. if (IS_ERR(clk)) {
  435. DSSERR("can't get sys_clk\n");
  436. return PTR_ERR(clk);
  437. }
  438. hdmi.sys_clk = clk;
  439. return 0;
  440. }
  441. static void hdmi_put_clocks(void)
  442. {
  443. if (hdmi.sys_clk)
  444. clk_put(hdmi.sys_clk);
  445. }
  446. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  447. int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
  448. {
  449. u32 deep_color;
  450. bool deep_color_correct = false;
  451. u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
  452. if (n == NULL || cts == NULL)
  453. return -EINVAL;
  454. /* TODO: When implemented, query deep color mode here. */
  455. deep_color = 100;
  456. /*
  457. * When using deep color, the default N value (as in the HDMI
  458. * specification) yields to an non-integer CTS. Hence, we
  459. * modify it while keeping the restrictions described in
  460. * section 7.2.1 of the HDMI 1.4a specification.
  461. */
  462. switch (sample_freq) {
  463. case 32000:
  464. case 48000:
  465. case 96000:
  466. case 192000:
  467. if (deep_color == 125)
  468. if (pclk == 27027 || pclk == 74250)
  469. deep_color_correct = true;
  470. if (deep_color == 150)
  471. if (pclk == 27027)
  472. deep_color_correct = true;
  473. break;
  474. case 44100:
  475. case 88200:
  476. case 176400:
  477. if (deep_color == 125)
  478. if (pclk == 27027)
  479. deep_color_correct = true;
  480. break;
  481. default:
  482. return -EINVAL;
  483. }
  484. if (deep_color_correct) {
  485. switch (sample_freq) {
  486. case 32000:
  487. *n = 8192;
  488. break;
  489. case 44100:
  490. *n = 12544;
  491. break;
  492. case 48000:
  493. *n = 8192;
  494. break;
  495. case 88200:
  496. *n = 25088;
  497. break;
  498. case 96000:
  499. *n = 16384;
  500. break;
  501. case 176400:
  502. *n = 50176;
  503. break;
  504. case 192000:
  505. *n = 32768;
  506. break;
  507. default:
  508. return -EINVAL;
  509. }
  510. } else {
  511. switch (sample_freq) {
  512. case 32000:
  513. *n = 4096;
  514. break;
  515. case 44100:
  516. *n = 6272;
  517. break;
  518. case 48000:
  519. *n = 6144;
  520. break;
  521. case 88200:
  522. *n = 12544;
  523. break;
  524. case 96000:
  525. *n = 12288;
  526. break;
  527. case 176400:
  528. *n = 25088;
  529. break;
  530. case 192000:
  531. *n = 24576;
  532. break;
  533. default:
  534. return -EINVAL;
  535. }
  536. }
  537. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  538. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  539. return 0;
  540. }
  541. int hdmi_audio_enable(void)
  542. {
  543. DSSDBG("audio_enable\n");
  544. return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
  545. }
  546. void hdmi_audio_disable(void)
  547. {
  548. DSSDBG("audio_disable\n");
  549. hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
  550. }
  551. int hdmi_audio_start(void)
  552. {
  553. DSSDBG("audio_start\n");
  554. return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
  555. }
  556. void hdmi_audio_stop(void)
  557. {
  558. DSSDBG("audio_stop\n");
  559. hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
  560. }
  561. bool hdmi_mode_has_audio(void)
  562. {
  563. if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
  564. return true;
  565. else
  566. return false;
  567. }
  568. int hdmi_audio_config(struct omap_dss_audio *audio)
  569. {
  570. return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
  571. }
  572. #endif
  573. static void __init hdmi_probe_pdata(struct platform_device *pdev)
  574. {
  575. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  576. int r, i;
  577. for (i = 0; i < pdata->num_devices; ++i) {
  578. struct omap_dss_device *dssdev = pdata->devices[i];
  579. if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
  580. continue;
  581. r = hdmi_init_display(dssdev);
  582. if (r) {
  583. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  584. continue;
  585. }
  586. r = omap_dss_register_device(dssdev, &pdev->dev, i);
  587. if (r)
  588. DSSERR("device %s register failed: %d\n",
  589. dssdev->name, r);
  590. }
  591. }
  592. /* HDMI HW IP initialisation */
  593. static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
  594. {
  595. struct resource *hdmi_mem;
  596. int r;
  597. hdmi.pdev = pdev;
  598. mutex_init(&hdmi.lock);
  599. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  600. if (!hdmi_mem) {
  601. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  602. return -EINVAL;
  603. }
  604. /* Base address taken from platform */
  605. hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
  606. resource_size(hdmi_mem));
  607. if (!hdmi.ip_data.base_wp) {
  608. DSSERR("can't ioremap WP\n");
  609. return -ENOMEM;
  610. }
  611. r = hdmi_get_clocks(pdev);
  612. if (r) {
  613. iounmap(hdmi.ip_data.base_wp);
  614. return r;
  615. }
  616. pm_runtime_enable(&pdev->dev);
  617. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  618. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  619. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  620. hdmi.ip_data.phy_offset = HDMI_PHY;
  621. hdmi_panel_init();
  622. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  623. hdmi_probe_pdata(pdev);
  624. return 0;
  625. }
  626. static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
  627. {
  628. omap_dss_unregister_child_devices(&pdev->dev);
  629. hdmi_panel_exit();
  630. pm_runtime_disable(&pdev->dev);
  631. hdmi_put_clocks();
  632. iounmap(hdmi.ip_data.base_wp);
  633. return 0;
  634. }
  635. static int hdmi_runtime_suspend(struct device *dev)
  636. {
  637. clk_disable(hdmi.sys_clk);
  638. dispc_runtime_put();
  639. return 0;
  640. }
  641. static int hdmi_runtime_resume(struct device *dev)
  642. {
  643. int r;
  644. r = dispc_runtime_get();
  645. if (r < 0)
  646. return r;
  647. clk_enable(hdmi.sys_clk);
  648. return 0;
  649. }
  650. static const struct dev_pm_ops hdmi_pm_ops = {
  651. .runtime_suspend = hdmi_runtime_suspend,
  652. .runtime_resume = hdmi_runtime_resume,
  653. };
  654. static struct platform_driver omapdss_hdmihw_driver = {
  655. .remove = __exit_p(omapdss_hdmihw_remove),
  656. .driver = {
  657. .name = "omapdss_hdmi",
  658. .owner = THIS_MODULE,
  659. .pm = &hdmi_pm_ops,
  660. },
  661. };
  662. int __init hdmi_init_platform_driver(void)
  663. {
  664. return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
  665. }
  666. void __exit hdmi_uninit_platform_driver(void)
  667. {
  668. platform_driver_unregister(&omapdss_hdmihw_driver);
  669. }