hdmi.c 22 KB

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