hdmi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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. const struct hdmi_config *timing;
  418. struct omap_video_timings *p;
  419. unsigned long phy;
  420. r = hdmi_runtime_get();
  421. if (r)
  422. return r;
  423. dss_mgr_disable(dssdev->manager);
  424. p = &dssdev->panel.timings;
  425. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n",
  426. dssdev->panel.timings.x_res,
  427. dssdev->panel.timings.y_res);
  428. timing = hdmi_get_timings();
  429. if (timing == NULL) {
  430. /* HDMI code 4 corresponds to 640 * 480 VGA */
  431. hdmi.ip_data.cfg.cm.code = 4;
  432. /* DVI mode 1 corresponds to HDMI 0 to DVI */
  433. hdmi.ip_data.cfg.cm.mode = HDMI_DVI;
  434. hdmi.ip_data.cfg = vesa_timings[0];
  435. } else {
  436. hdmi.ip_data.cfg = *timing;
  437. }
  438. phy = p->pixel_clock;
  439. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  440. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  441. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  442. r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
  443. if (r) {
  444. DSSDBG("Failed to lock PLL\n");
  445. goto err;
  446. }
  447. r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
  448. if (r) {
  449. DSSDBG("Failed to start PHY\n");
  450. goto err;
  451. }
  452. hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
  453. /* Make selection of HDMI in DSS */
  454. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  455. /* Select the dispc clock source as PRCM clock, to ensure that it is not
  456. * DSI PLL source as the clock selected by DSI PLL might not be
  457. * sufficient for the resolution selected / that can be changed
  458. * dynamically by user. This can be moved to single location , say
  459. * Boardfile.
  460. */
  461. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  462. /* bypass TV gamma table */
  463. dispc_enable_gamma_table(0);
  464. /* tv size */
  465. dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
  466. r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
  467. if (r)
  468. goto err_vid_enable;
  469. r = dss_mgr_enable(dssdev->manager);
  470. if (r)
  471. goto err_mgr_enable;
  472. return 0;
  473. err_mgr_enable:
  474. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  475. err_vid_enable:
  476. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  477. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  478. err:
  479. hdmi_runtime_put();
  480. return -EIO;
  481. }
  482. static void hdmi_power_off(struct omap_dss_device *dssdev)
  483. {
  484. dss_mgr_disable(dssdev->manager);
  485. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  486. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  487. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  488. hdmi_runtime_put();
  489. }
  490. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  491. struct omap_video_timings *timings)
  492. {
  493. struct hdmi_cm cm;
  494. cm = hdmi_get_code(timings);
  495. if (cm.code == -1) {
  496. return -EINVAL;
  497. }
  498. return 0;
  499. }
  500. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev)
  501. {
  502. struct hdmi_cm cm;
  503. cm = hdmi_get_code(&dssdev->panel.timings);
  504. hdmi.ip_data.cfg.cm.code = cm.code;
  505. hdmi.ip_data.cfg.cm.mode = cm.mode;
  506. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  507. int r;
  508. hdmi_power_off(dssdev);
  509. r = hdmi_power_on(dssdev);
  510. if (r)
  511. DSSERR("failed to power on device\n");
  512. } else {
  513. dss_mgr_set_timings(dssdev->manager, &dssdev->panel.timings);
  514. }
  515. }
  516. static void hdmi_dump_regs(struct seq_file *s)
  517. {
  518. mutex_lock(&hdmi.lock);
  519. if (hdmi_runtime_get())
  520. return;
  521. hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
  522. hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
  523. hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
  524. hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
  525. hdmi_runtime_put();
  526. mutex_unlock(&hdmi.lock);
  527. }
  528. int omapdss_hdmi_read_edid(u8 *buf, int len)
  529. {
  530. int r;
  531. mutex_lock(&hdmi.lock);
  532. r = hdmi_runtime_get();
  533. BUG_ON(r);
  534. r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
  535. hdmi_runtime_put();
  536. mutex_unlock(&hdmi.lock);
  537. return r;
  538. }
  539. bool omapdss_hdmi_detect(void)
  540. {
  541. int r;
  542. mutex_lock(&hdmi.lock);
  543. r = hdmi_runtime_get();
  544. BUG_ON(r);
  545. r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
  546. hdmi_runtime_put();
  547. mutex_unlock(&hdmi.lock);
  548. return r == 1;
  549. }
  550. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  551. {
  552. struct omap_dss_hdmi_data *priv = dssdev->data;
  553. int r = 0;
  554. DSSDBG("ENTER hdmi_display_enable\n");
  555. mutex_lock(&hdmi.lock);
  556. if (dssdev->manager == NULL) {
  557. DSSERR("failed to enable display: no manager\n");
  558. r = -ENODEV;
  559. goto err0;
  560. }
  561. hdmi.ip_data.hpd_gpio = priv->hpd_gpio;
  562. r = omap_dss_start_device(dssdev);
  563. if (r) {
  564. DSSERR("failed to start device\n");
  565. goto err0;
  566. }
  567. if (dssdev->platform_enable) {
  568. r = dssdev->platform_enable(dssdev);
  569. if (r) {
  570. DSSERR("failed to enable GPIO's\n");
  571. goto err1;
  572. }
  573. }
  574. r = hdmi_power_on(dssdev);
  575. if (r) {
  576. DSSERR("failed to power on device\n");
  577. goto err2;
  578. }
  579. mutex_unlock(&hdmi.lock);
  580. return 0;
  581. err2:
  582. if (dssdev->platform_disable)
  583. dssdev->platform_disable(dssdev);
  584. err1:
  585. omap_dss_stop_device(dssdev);
  586. err0:
  587. mutex_unlock(&hdmi.lock);
  588. return r;
  589. }
  590. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  591. {
  592. DSSDBG("Enter hdmi_display_disable\n");
  593. mutex_lock(&hdmi.lock);
  594. hdmi_power_off(dssdev);
  595. if (dssdev->platform_disable)
  596. dssdev->platform_disable(dssdev);
  597. omap_dss_stop_device(dssdev);
  598. mutex_unlock(&hdmi.lock);
  599. }
  600. static int hdmi_get_clocks(struct platform_device *pdev)
  601. {
  602. struct clk *clk;
  603. clk = clk_get(&pdev->dev, "sys_clk");
  604. if (IS_ERR(clk)) {
  605. DSSERR("can't get sys_clk\n");
  606. return PTR_ERR(clk);
  607. }
  608. hdmi.sys_clk = clk;
  609. return 0;
  610. }
  611. static void hdmi_put_clocks(void)
  612. {
  613. if (hdmi.sys_clk)
  614. clk_put(hdmi.sys_clk);
  615. }
  616. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  617. int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
  618. {
  619. u32 deep_color;
  620. bool deep_color_correct = false;
  621. u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
  622. if (n == NULL || cts == NULL)
  623. return -EINVAL;
  624. /* TODO: When implemented, query deep color mode here. */
  625. deep_color = 100;
  626. /*
  627. * When using deep color, the default N value (as in the HDMI
  628. * specification) yields to an non-integer CTS. Hence, we
  629. * modify it while keeping the restrictions described in
  630. * section 7.2.1 of the HDMI 1.4a specification.
  631. */
  632. switch (sample_freq) {
  633. case 32000:
  634. case 48000:
  635. case 96000:
  636. case 192000:
  637. if (deep_color == 125)
  638. if (pclk == 27027 || pclk == 74250)
  639. deep_color_correct = true;
  640. if (deep_color == 150)
  641. if (pclk == 27027)
  642. deep_color_correct = true;
  643. break;
  644. case 44100:
  645. case 88200:
  646. case 176400:
  647. if (deep_color == 125)
  648. if (pclk == 27027)
  649. deep_color_correct = true;
  650. break;
  651. default:
  652. return -EINVAL;
  653. }
  654. if (deep_color_correct) {
  655. switch (sample_freq) {
  656. case 32000:
  657. *n = 8192;
  658. break;
  659. case 44100:
  660. *n = 12544;
  661. break;
  662. case 48000:
  663. *n = 8192;
  664. break;
  665. case 88200:
  666. *n = 25088;
  667. break;
  668. case 96000:
  669. *n = 16384;
  670. break;
  671. case 176400:
  672. *n = 50176;
  673. break;
  674. case 192000:
  675. *n = 32768;
  676. break;
  677. default:
  678. return -EINVAL;
  679. }
  680. } else {
  681. switch (sample_freq) {
  682. case 32000:
  683. *n = 4096;
  684. break;
  685. case 44100:
  686. *n = 6272;
  687. break;
  688. case 48000:
  689. *n = 6144;
  690. break;
  691. case 88200:
  692. *n = 12544;
  693. break;
  694. case 96000:
  695. *n = 12288;
  696. break;
  697. case 176400:
  698. *n = 25088;
  699. break;
  700. case 192000:
  701. *n = 24576;
  702. break;
  703. default:
  704. return -EINVAL;
  705. }
  706. }
  707. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  708. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  709. return 0;
  710. }
  711. int hdmi_audio_enable(void)
  712. {
  713. DSSDBG("audio_enable\n");
  714. return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
  715. }
  716. void hdmi_audio_disable(void)
  717. {
  718. DSSDBG("audio_disable\n");
  719. hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
  720. }
  721. int hdmi_audio_start(void)
  722. {
  723. DSSDBG("audio_start\n");
  724. return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
  725. }
  726. void hdmi_audio_stop(void)
  727. {
  728. DSSDBG("audio_stop\n");
  729. hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
  730. }
  731. bool hdmi_mode_has_audio(void)
  732. {
  733. if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
  734. return true;
  735. else
  736. return false;
  737. }
  738. int hdmi_audio_config(struct omap_dss_audio *audio)
  739. {
  740. return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
  741. }
  742. #endif
  743. static void __init hdmi_probe_pdata(struct platform_device *pdev)
  744. {
  745. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  746. int r, i;
  747. for (i = 0; i < pdata->num_devices; ++i) {
  748. struct omap_dss_device *dssdev = pdata->devices[i];
  749. if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
  750. continue;
  751. r = hdmi_init_display(dssdev);
  752. if (r) {
  753. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  754. continue;
  755. }
  756. r = omap_dss_register_device(dssdev, &pdev->dev, i);
  757. if (r)
  758. DSSERR("device %s register failed: %d\n",
  759. dssdev->name, r);
  760. }
  761. }
  762. /* HDMI HW IP initialisation */
  763. static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
  764. {
  765. struct resource *hdmi_mem;
  766. int r;
  767. hdmi.pdev = pdev;
  768. mutex_init(&hdmi.lock);
  769. hdmi_mem = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  770. if (!hdmi_mem) {
  771. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  772. return -EINVAL;
  773. }
  774. /* Base address taken from platform */
  775. hdmi.ip_data.base_wp = ioremap(hdmi_mem->start,
  776. resource_size(hdmi_mem));
  777. if (!hdmi.ip_data.base_wp) {
  778. DSSERR("can't ioremap WP\n");
  779. return -ENOMEM;
  780. }
  781. r = hdmi_get_clocks(pdev);
  782. if (r) {
  783. iounmap(hdmi.ip_data.base_wp);
  784. return r;
  785. }
  786. pm_runtime_enable(&pdev->dev);
  787. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  788. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  789. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  790. hdmi.ip_data.phy_offset = HDMI_PHY;
  791. mutex_init(&hdmi.ip_data.lock);
  792. hdmi_panel_init();
  793. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  794. hdmi_probe_pdata(pdev);
  795. return 0;
  796. }
  797. static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
  798. {
  799. omap_dss_unregister_child_devices(&pdev->dev);
  800. hdmi_panel_exit();
  801. pm_runtime_disable(&pdev->dev);
  802. hdmi_put_clocks();
  803. iounmap(hdmi.ip_data.base_wp);
  804. return 0;
  805. }
  806. static int hdmi_runtime_suspend(struct device *dev)
  807. {
  808. clk_disable_unprepare(hdmi.sys_clk);
  809. dispc_runtime_put();
  810. return 0;
  811. }
  812. static int hdmi_runtime_resume(struct device *dev)
  813. {
  814. int r;
  815. r = dispc_runtime_get();
  816. if (r < 0)
  817. return r;
  818. clk_prepare_enable(hdmi.sys_clk);
  819. return 0;
  820. }
  821. static const struct dev_pm_ops hdmi_pm_ops = {
  822. .runtime_suspend = hdmi_runtime_suspend,
  823. .runtime_resume = hdmi_runtime_resume,
  824. };
  825. static struct platform_driver omapdss_hdmihw_driver = {
  826. .remove = __exit_p(omapdss_hdmihw_remove),
  827. .driver = {
  828. .name = "omapdss_hdmi",
  829. .owner = THIS_MODULE,
  830. .pm = &hdmi_pm_ops,
  831. },
  832. };
  833. int __init hdmi_init_platform_driver(void)
  834. {
  835. return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
  836. }
  837. void __exit hdmi_uninit_platform_driver(void)
  838. {
  839. platform_driver_unregister(&omapdss_hdmihw_driver);
  840. }