hdmi.c 22 KB

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