hdmi.c 25 KB

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