hdmi.c 21 KB

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