hdmi.c 24 KB

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