hdmi.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
  323. if (IS_ERR(reg))
  324. reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
  325. if (IS_ERR(reg)) {
  326. DSSERR("can't get VDDA_HDMI_DAC regulator\n");
  327. return PTR_ERR(reg);
  328. }
  329. hdmi.vdda_hdmi_dac_reg = reg;
  330. }
  331. r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
  332. if (r)
  333. return r;
  334. return 0;
  335. }
  336. static void hdmi_uninit_display(struct omap_dss_device *dssdev)
  337. {
  338. DSSDBG("uninit_display\n");
  339. gpio_free(hdmi.ct_cp_hpd_gpio);
  340. gpio_free(hdmi.ls_oe_gpio);
  341. gpio_free(hdmi.hpd_gpio);
  342. }
  343. static const struct hdmi_config *hdmi_find_timing(
  344. const struct hdmi_config *timings_arr,
  345. int len)
  346. {
  347. int i;
  348. for (i = 0; i < len; i++) {
  349. if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
  350. return &timings_arr[i];
  351. }
  352. return NULL;
  353. }
  354. static const struct hdmi_config *hdmi_get_timings(void)
  355. {
  356. const struct hdmi_config *arr;
  357. int len;
  358. if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
  359. arr = vesa_timings;
  360. len = ARRAY_SIZE(vesa_timings);
  361. } else {
  362. arr = cea_timings;
  363. len = ARRAY_SIZE(cea_timings);
  364. }
  365. return hdmi_find_timing(arr, len);
  366. }
  367. static bool hdmi_timings_compare(struct omap_video_timings *timing1,
  368. const struct omap_video_timings *timing2)
  369. {
  370. int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
  371. if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
  372. DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
  373. (timing2->x_res == timing1->x_res) &&
  374. (timing2->y_res == timing1->y_res)) {
  375. timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
  376. timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
  377. timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  378. timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  379. DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
  380. "timing2_hsync = %d timing2_vsync = %d\n",
  381. timing1_hsync, timing1_vsync,
  382. timing2_hsync, timing2_vsync);
  383. if ((timing1_hsync == timing2_hsync) &&
  384. (timing1_vsync == timing2_vsync)) {
  385. return true;
  386. }
  387. }
  388. return false;
  389. }
  390. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  391. {
  392. int i;
  393. struct hdmi_cm cm = {-1};
  394. DSSDBG("hdmi_get_code\n");
  395. for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
  396. if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
  397. cm = cea_timings[i].cm;
  398. goto end;
  399. }
  400. }
  401. for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
  402. if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
  403. cm = vesa_timings[i].cm;
  404. goto end;
  405. }
  406. }
  407. end: return cm;
  408. }
  409. unsigned long hdmi_get_pixel_clock(void)
  410. {
  411. /* HDMI Pixel Clock in Mhz */
  412. return hdmi.ip_data.cfg.timings.pixel_clock * 1000;
  413. }
  414. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  415. struct hdmi_pll_info *pi)
  416. {
  417. unsigned long clkin, refclk;
  418. u32 mf;
  419. clkin = clk_get_rate(hdmi.sys_clk) / 10000;
  420. /*
  421. * Input clock is predivided by N + 1
  422. * out put of which is reference clk
  423. */
  424. if (dssdev->clocks.hdmi.regn == 0)
  425. pi->regn = HDMI_DEFAULT_REGN;
  426. else
  427. pi->regn = dssdev->clocks.hdmi.regn;
  428. refclk = clkin / pi->regn;
  429. if (dssdev->clocks.hdmi.regm2 == 0)
  430. pi->regm2 = HDMI_DEFAULT_REGM2;
  431. else
  432. pi->regm2 = dssdev->clocks.hdmi.regm2;
  433. /*
  434. * multiplier is pixel_clk/ref_clk
  435. * Multiplying by 100 to avoid fractional part removal
  436. */
  437. pi->regm = phy * pi->regm2 / refclk;
  438. /*
  439. * fractional multiplier is remainder of the difference between
  440. * multiplier and actual phy(required pixel clock thus should be
  441. * multiplied by 2^18(262144) divided by the reference clock
  442. */
  443. mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
  444. pi->regmf = pi->regm2 * mf / refclk;
  445. /*
  446. * Dcofreq should be set to 1 if required pixel clock
  447. * is greater than 1000MHz
  448. */
  449. pi->dcofreq = phy > 1000 * 100;
  450. pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
  451. /* Set the reference clock to sysclk reference */
  452. pi->refsel = HDMI_REFSEL_SYSCLK;
  453. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  454. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  455. }
  456. static int hdmi_power_on_core(struct omap_dss_device *dssdev)
  457. {
  458. int r;
  459. gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
  460. gpio_set_value(hdmi.ls_oe_gpio, 1);
  461. /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
  462. udelay(300);
  463. r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
  464. if (r)
  465. goto err_vdac_enable;
  466. r = hdmi_runtime_get();
  467. if (r)
  468. goto err_runtime_get;
  469. /* Make selection of HDMI in DSS */
  470. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  471. return 0;
  472. err_runtime_get:
  473. regulator_disable(hdmi.vdda_hdmi_dac_reg);
  474. err_vdac_enable:
  475. gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
  476. gpio_set_value(hdmi.ls_oe_gpio, 0);
  477. return r;
  478. }
  479. static void hdmi_power_off_core(struct omap_dss_device *dssdev)
  480. {
  481. hdmi_runtime_put();
  482. regulator_disable(hdmi.vdda_hdmi_dac_reg);
  483. gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
  484. gpio_set_value(hdmi.ls_oe_gpio, 0);
  485. }
  486. static int hdmi_power_on_full(struct omap_dss_device *dssdev)
  487. {
  488. int r;
  489. struct omap_video_timings *p;
  490. struct omap_overlay_manager *mgr = dssdev->output->manager;
  491. unsigned long phy;
  492. r = hdmi_power_on_core(dssdev);
  493. if (r)
  494. return r;
  495. dss_mgr_disable(mgr);
  496. p = &hdmi.ip_data.cfg.timings;
  497. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
  498. phy = p->pixel_clock;
  499. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  500. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  501. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  502. r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
  503. if (r) {
  504. DSSDBG("Failed to lock PLL\n");
  505. goto err_pll_enable;
  506. }
  507. r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
  508. if (r) {
  509. DSSDBG("Failed to start PHY\n");
  510. goto err_phy_enable;
  511. }
  512. hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
  513. /* bypass TV gamma table */
  514. dispc_enable_gamma_table(0);
  515. /* tv size */
  516. dss_mgr_set_timings(mgr, p);
  517. r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
  518. if (r)
  519. goto err_vid_enable;
  520. r = dss_mgr_enable(mgr);
  521. if (r)
  522. goto err_mgr_enable;
  523. return 0;
  524. err_mgr_enable:
  525. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  526. err_vid_enable:
  527. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  528. err_phy_enable:
  529. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  530. err_pll_enable:
  531. hdmi_power_off_core(dssdev);
  532. return -EIO;
  533. }
  534. static void hdmi_power_off_full(struct omap_dss_device *dssdev)
  535. {
  536. struct omap_overlay_manager *mgr = dssdev->output->manager;
  537. dss_mgr_disable(mgr);
  538. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  539. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  540. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  541. hdmi_power_off_core(dssdev);
  542. }
  543. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  544. struct omap_video_timings *timings)
  545. {
  546. struct hdmi_cm cm;
  547. cm = hdmi_get_code(timings);
  548. if (cm.code == -1) {
  549. return -EINVAL;
  550. }
  551. return 0;
  552. }
  553. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
  554. struct omap_video_timings *timings)
  555. {
  556. struct hdmi_cm cm;
  557. const struct hdmi_config *t;
  558. mutex_lock(&hdmi.lock);
  559. cm = hdmi_get_code(timings);
  560. hdmi.ip_data.cfg.cm = cm;
  561. t = hdmi_get_timings();
  562. if (t != NULL)
  563. hdmi.ip_data.cfg = *t;
  564. mutex_unlock(&hdmi.lock);
  565. }
  566. static void hdmi_dump_regs(struct seq_file *s)
  567. {
  568. mutex_lock(&hdmi.lock);
  569. if (hdmi_runtime_get()) {
  570. mutex_unlock(&hdmi.lock);
  571. return;
  572. }
  573. hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
  574. hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
  575. hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
  576. hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
  577. hdmi_runtime_put();
  578. mutex_unlock(&hdmi.lock);
  579. }
  580. int omapdss_hdmi_read_edid(u8 *buf, int len)
  581. {
  582. int r;
  583. mutex_lock(&hdmi.lock);
  584. r = hdmi_runtime_get();
  585. BUG_ON(r);
  586. r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
  587. hdmi_runtime_put();
  588. mutex_unlock(&hdmi.lock);
  589. return r;
  590. }
  591. bool omapdss_hdmi_detect(void)
  592. {
  593. int r;
  594. mutex_lock(&hdmi.lock);
  595. r = hdmi_runtime_get();
  596. BUG_ON(r);
  597. r = hdmi.ip_data.ops->detect(&hdmi.ip_data);
  598. hdmi_runtime_put();
  599. mutex_unlock(&hdmi.lock);
  600. return r == 1;
  601. }
  602. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  603. {
  604. struct omap_dss_output *out = dssdev->output;
  605. int r = 0;
  606. DSSDBG("ENTER hdmi_display_enable\n");
  607. mutex_lock(&hdmi.lock);
  608. if (out == NULL || out->manager == NULL) {
  609. DSSERR("failed to enable display: no output/manager\n");
  610. r = -ENODEV;
  611. goto err0;
  612. }
  613. hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
  614. r = omap_dss_start_device(dssdev);
  615. if (r) {
  616. DSSERR("failed to start device\n");
  617. goto err0;
  618. }
  619. r = hdmi_power_on_full(dssdev);
  620. if (r) {
  621. DSSERR("failed to power on device\n");
  622. goto err1;
  623. }
  624. mutex_unlock(&hdmi.lock);
  625. return 0;
  626. err1:
  627. omap_dss_stop_device(dssdev);
  628. err0:
  629. mutex_unlock(&hdmi.lock);
  630. return r;
  631. }
  632. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  633. {
  634. DSSDBG("Enter hdmi_display_disable\n");
  635. mutex_lock(&hdmi.lock);
  636. hdmi_power_off_full(dssdev);
  637. omap_dss_stop_device(dssdev);
  638. mutex_unlock(&hdmi.lock);
  639. }
  640. int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
  641. {
  642. int r = 0;
  643. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  644. mutex_lock(&hdmi.lock);
  645. hdmi.ip_data.hpd_gpio = hdmi.hpd_gpio;
  646. r = hdmi_power_on_core(dssdev);
  647. if (r) {
  648. DSSERR("failed to power on device\n");
  649. goto err0;
  650. }
  651. mutex_unlock(&hdmi.lock);
  652. return 0;
  653. err0:
  654. mutex_unlock(&hdmi.lock);
  655. return r;
  656. }
  657. void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
  658. {
  659. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  660. mutex_lock(&hdmi.lock);
  661. hdmi_power_off_core(dssdev);
  662. mutex_unlock(&hdmi.lock);
  663. }
  664. static int hdmi_get_clocks(struct platform_device *pdev)
  665. {
  666. struct clk *clk;
  667. clk = clk_get(&pdev->dev, "sys_clk");
  668. if (IS_ERR(clk)) {
  669. DSSERR("can't get sys_clk\n");
  670. return PTR_ERR(clk);
  671. }
  672. hdmi.sys_clk = clk;
  673. return 0;
  674. }
  675. static void hdmi_put_clocks(void)
  676. {
  677. if (hdmi.sys_clk)
  678. clk_put(hdmi.sys_clk);
  679. }
  680. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  681. int hdmi_compute_acr(u32 sample_freq, u32 *n, u32 *cts)
  682. {
  683. u32 deep_color;
  684. bool deep_color_correct = false;
  685. u32 pclk = hdmi.ip_data.cfg.timings.pixel_clock;
  686. if (n == NULL || cts == NULL)
  687. return -EINVAL;
  688. /* TODO: When implemented, query deep color mode here. */
  689. deep_color = 100;
  690. /*
  691. * When using deep color, the default N value (as in the HDMI
  692. * specification) yields to an non-integer CTS. Hence, we
  693. * modify it while keeping the restrictions described in
  694. * section 7.2.1 of the HDMI 1.4a specification.
  695. */
  696. switch (sample_freq) {
  697. case 32000:
  698. case 48000:
  699. case 96000:
  700. case 192000:
  701. if (deep_color == 125)
  702. if (pclk == 27027 || pclk == 74250)
  703. deep_color_correct = true;
  704. if (deep_color == 150)
  705. if (pclk == 27027)
  706. deep_color_correct = true;
  707. break;
  708. case 44100:
  709. case 88200:
  710. case 176400:
  711. if (deep_color == 125)
  712. if (pclk == 27027)
  713. deep_color_correct = true;
  714. break;
  715. default:
  716. return -EINVAL;
  717. }
  718. if (deep_color_correct) {
  719. switch (sample_freq) {
  720. case 32000:
  721. *n = 8192;
  722. break;
  723. case 44100:
  724. *n = 12544;
  725. break;
  726. case 48000:
  727. *n = 8192;
  728. break;
  729. case 88200:
  730. *n = 25088;
  731. break;
  732. case 96000:
  733. *n = 16384;
  734. break;
  735. case 176400:
  736. *n = 50176;
  737. break;
  738. case 192000:
  739. *n = 32768;
  740. break;
  741. default:
  742. return -EINVAL;
  743. }
  744. } else {
  745. switch (sample_freq) {
  746. case 32000:
  747. *n = 4096;
  748. break;
  749. case 44100:
  750. *n = 6272;
  751. break;
  752. case 48000:
  753. *n = 6144;
  754. break;
  755. case 88200:
  756. *n = 12544;
  757. break;
  758. case 96000:
  759. *n = 12288;
  760. break;
  761. case 176400:
  762. *n = 25088;
  763. break;
  764. case 192000:
  765. *n = 24576;
  766. break;
  767. default:
  768. return -EINVAL;
  769. }
  770. }
  771. /* Calculate CTS. See HDMI 1.3a or 1.4a specifications */
  772. *cts = pclk * (*n / 128) * deep_color / (sample_freq / 10);
  773. return 0;
  774. }
  775. int hdmi_audio_enable(void)
  776. {
  777. DSSDBG("audio_enable\n");
  778. return hdmi.ip_data.ops->audio_enable(&hdmi.ip_data);
  779. }
  780. void hdmi_audio_disable(void)
  781. {
  782. DSSDBG("audio_disable\n");
  783. hdmi.ip_data.ops->audio_disable(&hdmi.ip_data);
  784. }
  785. int hdmi_audio_start(void)
  786. {
  787. DSSDBG("audio_start\n");
  788. return hdmi.ip_data.ops->audio_start(&hdmi.ip_data);
  789. }
  790. void hdmi_audio_stop(void)
  791. {
  792. DSSDBG("audio_stop\n");
  793. hdmi.ip_data.ops->audio_stop(&hdmi.ip_data);
  794. }
  795. bool hdmi_mode_has_audio(void)
  796. {
  797. if (hdmi.ip_data.cfg.cm.mode == HDMI_HDMI)
  798. return true;
  799. else
  800. return false;
  801. }
  802. int hdmi_audio_config(struct omap_dss_audio *audio)
  803. {
  804. return hdmi.ip_data.ops->audio_config(&hdmi.ip_data, audio);
  805. }
  806. #endif
  807. static struct omap_dss_device * __init hdmi_find_dssdev(struct platform_device *pdev)
  808. {
  809. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  810. const char *def_disp_name = omapdss_get_default_display_name();
  811. struct omap_dss_device *def_dssdev;
  812. int i;
  813. def_dssdev = NULL;
  814. for (i = 0; i < pdata->num_devices; ++i) {
  815. struct omap_dss_device *dssdev = pdata->devices[i];
  816. if (dssdev->type != OMAP_DISPLAY_TYPE_HDMI)
  817. continue;
  818. if (def_dssdev == NULL)
  819. def_dssdev = dssdev;
  820. if (def_disp_name != NULL &&
  821. strcmp(dssdev->name, def_disp_name) == 0) {
  822. def_dssdev = dssdev;
  823. break;
  824. }
  825. }
  826. return def_dssdev;
  827. }
  828. static void __init hdmi_probe_pdata(struct platform_device *pdev)
  829. {
  830. struct omap_dss_device *plat_dssdev;
  831. struct omap_dss_device *dssdev;
  832. struct omap_dss_hdmi_data *priv;
  833. int r;
  834. plat_dssdev = hdmi_find_dssdev(pdev);
  835. if (!plat_dssdev)
  836. return;
  837. dssdev = dss_alloc_and_init_device(&pdev->dev);
  838. if (!dssdev)
  839. return;
  840. dss_copy_device_pdata(dssdev, plat_dssdev);
  841. priv = dssdev->data;
  842. hdmi.ct_cp_hpd_gpio = priv->ct_cp_hpd_gpio;
  843. hdmi.ls_oe_gpio = priv->ls_oe_gpio;
  844. hdmi.hpd_gpio = priv->hpd_gpio;
  845. dssdev->channel = OMAP_DSS_CHANNEL_DIGIT;
  846. r = hdmi_init_display(dssdev);
  847. if (r) {
  848. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  849. dss_put_device(dssdev);
  850. return;
  851. }
  852. r = omapdss_output_set_device(&hdmi.output, dssdev);
  853. if (r) {
  854. DSSERR("failed to connect output to new device: %s\n",
  855. dssdev->name);
  856. dss_put_device(dssdev);
  857. return;
  858. }
  859. r = dss_add_device(dssdev);
  860. if (r) {
  861. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  862. omapdss_output_unset_device(&hdmi.output);
  863. hdmi_uninit_display(dssdev);
  864. dss_put_device(dssdev);
  865. return;
  866. }
  867. }
  868. static void __init hdmi_init_output(struct platform_device *pdev)
  869. {
  870. struct omap_dss_output *out = &hdmi.output;
  871. out->pdev = pdev;
  872. out->id = OMAP_DSS_OUTPUT_HDMI;
  873. out->type = OMAP_DISPLAY_TYPE_HDMI;
  874. dss_register_output(out);
  875. }
  876. static void __exit hdmi_uninit_output(struct platform_device *pdev)
  877. {
  878. struct omap_dss_output *out = &hdmi.output;
  879. dss_unregister_output(out);
  880. }
  881. /* HDMI HW IP initialisation */
  882. static int __init omapdss_hdmihw_probe(struct platform_device *pdev)
  883. {
  884. struct resource *res;
  885. int r;
  886. hdmi.pdev = pdev;
  887. mutex_init(&hdmi.lock);
  888. mutex_init(&hdmi.ip_data.lock);
  889. res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  890. if (!res) {
  891. DSSERR("can't get IORESOURCE_MEM HDMI\n");
  892. return -EINVAL;
  893. }
  894. /* Base address taken from platform */
  895. hdmi.ip_data.base_wp = devm_ioremap_resource(&pdev->dev, res);
  896. if (IS_ERR(hdmi.ip_data.base_wp))
  897. return PTR_ERR(hdmi.ip_data.base_wp);
  898. r = hdmi_get_clocks(pdev);
  899. if (r) {
  900. DSSERR("can't get clocks\n");
  901. return r;
  902. }
  903. pm_runtime_enable(&pdev->dev);
  904. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  905. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  906. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  907. hdmi.ip_data.phy_offset = HDMI_PHY;
  908. r = hdmi_panel_init();
  909. if (r) {
  910. DSSERR("can't init panel\n");
  911. goto err_panel_init;
  912. }
  913. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  914. hdmi_init_output(pdev);
  915. hdmi_probe_pdata(pdev);
  916. return 0;
  917. err_panel_init:
  918. hdmi_put_clocks();
  919. return r;
  920. }
  921. static int __exit hdmi_remove_child(struct device *dev, void *data)
  922. {
  923. struct omap_dss_device *dssdev = to_dss_device(dev);
  924. hdmi_uninit_display(dssdev);
  925. return 0;
  926. }
  927. static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
  928. {
  929. device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
  930. dss_unregister_child_devices(&pdev->dev);
  931. hdmi_panel_exit();
  932. hdmi_uninit_output(pdev);
  933. pm_runtime_disable(&pdev->dev);
  934. hdmi_put_clocks();
  935. return 0;
  936. }
  937. static int hdmi_runtime_suspend(struct device *dev)
  938. {
  939. clk_disable_unprepare(hdmi.sys_clk);
  940. dispc_runtime_put();
  941. return 0;
  942. }
  943. static int hdmi_runtime_resume(struct device *dev)
  944. {
  945. int r;
  946. r = dispc_runtime_get();
  947. if (r < 0)
  948. return r;
  949. clk_prepare_enable(hdmi.sys_clk);
  950. return 0;
  951. }
  952. static const struct dev_pm_ops hdmi_pm_ops = {
  953. .runtime_suspend = hdmi_runtime_suspend,
  954. .runtime_resume = hdmi_runtime_resume,
  955. };
  956. static struct platform_driver omapdss_hdmihw_driver = {
  957. .remove = __exit_p(omapdss_hdmihw_remove),
  958. .driver = {
  959. .name = "omapdss_hdmi",
  960. .owner = THIS_MODULE,
  961. .pm = &hdmi_pm_ops,
  962. },
  963. };
  964. int __init hdmi_init_platform_driver(void)
  965. {
  966. return platform_driver_probe(&omapdss_hdmihw_driver, omapdss_hdmihw_probe);
  967. }
  968. void __exit hdmi_uninit_platform_driver(void)
  969. {
  970. platform_driver_unregister(&omapdss_hdmihw_driver);
  971. }