hdmi.c 24 KB

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