hdmi.c 24 KB

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