hdmi.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  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. bool core_enabled;
  63. struct omap_dss_device output;
  64. } hdmi;
  65. /*
  66. * Logic for the below structure :
  67. * user enters the CEA or VESA timings by specifying the HDMI/DVI code.
  68. * There is a correspondence between CEA/VESA timing and code, please
  69. * refer to section 6.3 in HDMI 1.3 specification for timing code.
  70. *
  71. * In the below structure, cea_vesa_timings corresponds to all OMAP4
  72. * supported CEA and VESA timing values.code_cea corresponds to the CEA
  73. * code, It is used to get the timing from cea_vesa_timing array.Similarly
  74. * with code_vesa. Code_index is used for back mapping, that is once EDID
  75. * is read from the TV, EDID is parsed to find the timing values and then
  76. * map it to corresponding CEA or VESA index.
  77. */
  78. static const struct hdmi_config cea_timings[] = {
  79. {
  80. { 640, 480, 25200, 96, 16, 48, 2, 10, 33,
  81. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  82. false, },
  83. { 1, HDMI_HDMI },
  84. },
  85. {
  86. { 720, 480, 27027, 62, 16, 60, 6, 9, 30,
  87. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  88. false, },
  89. { 2, HDMI_HDMI },
  90. },
  91. {
  92. { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
  93. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  94. false, },
  95. { 4, HDMI_HDMI },
  96. },
  97. {
  98. { 1920, 540, 74250, 44, 88, 148, 5, 2, 15,
  99. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  100. true, },
  101. { 5, HDMI_HDMI },
  102. },
  103. {
  104. { 1440, 240, 27027, 124, 38, 114, 3, 4, 15,
  105. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  106. true, },
  107. { 6, HDMI_HDMI },
  108. },
  109. {
  110. { 1920, 1080, 148500, 44, 88, 148, 5, 4, 36,
  111. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  112. false, },
  113. { 16, HDMI_HDMI },
  114. },
  115. {
  116. { 720, 576, 27000, 64, 12, 68, 5, 5, 39,
  117. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  118. false, },
  119. { 17, HDMI_HDMI },
  120. },
  121. {
  122. { 1280, 720, 74250, 40, 440, 220, 5, 5, 20,
  123. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  124. false, },
  125. { 19, HDMI_HDMI },
  126. },
  127. {
  128. { 1920, 540, 74250, 44, 528, 148, 5, 2, 15,
  129. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  130. true, },
  131. { 20, HDMI_HDMI },
  132. },
  133. {
  134. { 1440, 288, 27000, 126, 24, 138, 3, 2, 19,
  135. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  136. true, },
  137. { 21, HDMI_HDMI },
  138. },
  139. {
  140. { 1440, 576, 54000, 128, 24, 136, 5, 5, 39,
  141. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  142. false, },
  143. { 29, HDMI_HDMI },
  144. },
  145. {
  146. { 1920, 1080, 148500, 44, 528, 148, 5, 4, 36,
  147. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  148. false, },
  149. { 31, HDMI_HDMI },
  150. },
  151. {
  152. { 1920, 1080, 74250, 44, 638, 148, 5, 4, 36,
  153. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  154. false, },
  155. { 32, HDMI_HDMI },
  156. },
  157. {
  158. { 2880, 480, 108108, 248, 64, 240, 6, 9, 30,
  159. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  160. false, },
  161. { 35, HDMI_HDMI },
  162. },
  163. {
  164. { 2880, 576, 108000, 256, 48, 272, 5, 5, 39,
  165. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  166. false, },
  167. { 37, HDMI_HDMI },
  168. },
  169. };
  170. static const struct hdmi_config vesa_timings[] = {
  171. /* VESA From Here */
  172. {
  173. { 640, 480, 25175, 96, 16, 48, 2, 11, 31,
  174. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  175. false, },
  176. { 4, HDMI_DVI },
  177. },
  178. {
  179. { 800, 600, 40000, 128, 40, 88, 4, 1, 23,
  180. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  181. false, },
  182. { 9, HDMI_DVI },
  183. },
  184. {
  185. { 848, 480, 33750, 112, 16, 112, 8, 6, 23,
  186. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  187. false, },
  188. { 0xE, HDMI_DVI },
  189. },
  190. {
  191. { 1280, 768, 79500, 128, 64, 192, 7, 3, 20,
  192. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
  193. false, },
  194. { 0x17, HDMI_DVI },
  195. },
  196. {
  197. { 1280, 800, 83500, 128, 72, 200, 6, 3, 22,
  198. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
  199. false, },
  200. { 0x1C, HDMI_DVI },
  201. },
  202. {
  203. { 1360, 768, 85500, 112, 64, 256, 6, 3, 18,
  204. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  205. false, },
  206. { 0x27, HDMI_DVI },
  207. },
  208. {
  209. { 1280, 960, 108000, 112, 96, 312, 3, 1, 36,
  210. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  211. false, },
  212. { 0x20, HDMI_DVI },
  213. },
  214. {
  215. { 1280, 1024, 108000, 112, 48, 248, 3, 1, 38,
  216. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  217. false, },
  218. { 0x23, HDMI_DVI },
  219. },
  220. {
  221. { 1024, 768, 65000, 136, 24, 160, 6, 3, 29,
  222. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_LOW,
  223. false, },
  224. { 0x10, HDMI_DVI },
  225. },
  226. {
  227. { 1400, 1050, 121750, 144, 88, 232, 4, 3, 32,
  228. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
  229. false, },
  230. { 0x2A, HDMI_DVI },
  231. },
  232. {
  233. { 1440, 900, 106500, 152, 80, 232, 6, 3, 25,
  234. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
  235. false, },
  236. { 0x2F, HDMI_DVI },
  237. },
  238. {
  239. { 1680, 1050, 146250, 176 , 104, 280, 6, 3, 30,
  240. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_LOW,
  241. false, },
  242. { 0x3A, HDMI_DVI },
  243. },
  244. {
  245. { 1366, 768, 85500, 143, 70, 213, 3, 3, 24,
  246. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  247. false, },
  248. { 0x51, HDMI_DVI },
  249. },
  250. {
  251. { 1920, 1080, 148500, 44, 148, 80, 5, 4, 36,
  252. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  253. false, },
  254. { 0x52, HDMI_DVI },
  255. },
  256. {
  257. { 1280, 768, 68250, 32, 48, 80, 7, 3, 12,
  258. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
  259. false, },
  260. { 0x16, HDMI_DVI },
  261. },
  262. {
  263. { 1400, 1050, 101000, 32, 48, 80, 4, 3, 23,
  264. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
  265. false, },
  266. { 0x29, HDMI_DVI },
  267. },
  268. {
  269. { 1680, 1050, 119000, 32, 48, 80, 6, 3, 21,
  270. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
  271. false, },
  272. { 0x39, HDMI_DVI },
  273. },
  274. {
  275. { 1280, 800, 79500, 32, 48, 80, 6, 3, 14,
  276. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
  277. false, },
  278. { 0x1B, HDMI_DVI },
  279. },
  280. {
  281. { 1280, 720, 74250, 40, 110, 220, 5, 5, 20,
  282. OMAPDSS_SIG_ACTIVE_HIGH, OMAPDSS_SIG_ACTIVE_HIGH,
  283. false, },
  284. { 0x55, HDMI_DVI },
  285. },
  286. {
  287. { 1920, 1200, 154000, 32, 48, 80, 6, 3, 26,
  288. OMAPDSS_SIG_ACTIVE_LOW, OMAPDSS_SIG_ACTIVE_HIGH,
  289. false, },
  290. { 0x44, HDMI_DVI },
  291. },
  292. };
  293. static int hdmi_runtime_get(void)
  294. {
  295. int r;
  296. DSSDBG("hdmi_runtime_get\n");
  297. r = pm_runtime_get_sync(&hdmi.pdev->dev);
  298. WARN_ON(r < 0);
  299. if (r < 0)
  300. return r;
  301. return 0;
  302. }
  303. static void hdmi_runtime_put(void)
  304. {
  305. int r;
  306. DSSDBG("hdmi_runtime_put\n");
  307. r = pm_runtime_put_sync(&hdmi.pdev->dev);
  308. WARN_ON(r < 0 && r != -ENOSYS);
  309. }
  310. static int hdmi_init_regulator(void)
  311. {
  312. struct regulator *reg;
  313. if (hdmi.vdda_hdmi_dac_reg != NULL)
  314. return 0;
  315. reg = devm_regulator_get(&hdmi.pdev->dev, "vdda_hdmi_dac");
  316. /* DT HACK: try VDAC to make omapdss work for o4 sdp/panda */
  317. if (IS_ERR(reg))
  318. reg = devm_regulator_get(&hdmi.pdev->dev, "VDAC");
  319. if (IS_ERR(reg)) {
  320. DSSERR("can't get VDDA_HDMI_DAC regulator\n");
  321. return PTR_ERR(reg);
  322. }
  323. hdmi.vdda_hdmi_dac_reg = reg;
  324. return 0;
  325. }
  326. static int hdmi_init_display(struct omap_dss_device *dssdev)
  327. {
  328. int r;
  329. struct gpio gpios[] = {
  330. { hdmi.ct_cp_hpd_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ct_cp_hpd" },
  331. { hdmi.ls_oe_gpio, GPIOF_OUT_INIT_LOW, "hdmi_ls_oe" },
  332. { hdmi.hpd_gpio, GPIOF_DIR_IN, "hdmi_hpd" },
  333. };
  334. DSSDBG("init_display\n");
  335. dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
  336. r = hdmi_init_regulator();
  337. if (r)
  338. return r;
  339. r = gpio_request_array(gpios, ARRAY_SIZE(gpios));
  340. if (r)
  341. return r;
  342. return 0;
  343. }
  344. static void hdmi_uninit_display(struct omap_dss_device *dssdev)
  345. {
  346. DSSDBG("uninit_display\n");
  347. gpio_free(hdmi.ct_cp_hpd_gpio);
  348. gpio_free(hdmi.ls_oe_gpio);
  349. gpio_free(hdmi.hpd_gpio);
  350. }
  351. static const struct hdmi_config *hdmi_find_timing(
  352. const struct hdmi_config *timings_arr,
  353. int len)
  354. {
  355. int i;
  356. for (i = 0; i < len; i++) {
  357. if (timings_arr[i].cm.code == hdmi.ip_data.cfg.cm.code)
  358. return &timings_arr[i];
  359. }
  360. return NULL;
  361. }
  362. static const struct hdmi_config *hdmi_get_timings(void)
  363. {
  364. const struct hdmi_config *arr;
  365. int len;
  366. if (hdmi.ip_data.cfg.cm.mode == HDMI_DVI) {
  367. arr = vesa_timings;
  368. len = ARRAY_SIZE(vesa_timings);
  369. } else {
  370. arr = cea_timings;
  371. len = ARRAY_SIZE(cea_timings);
  372. }
  373. return hdmi_find_timing(arr, len);
  374. }
  375. static bool hdmi_timings_compare(struct omap_video_timings *timing1,
  376. const struct omap_video_timings *timing2)
  377. {
  378. int timing1_vsync, timing1_hsync, timing2_vsync, timing2_hsync;
  379. if ((DIV_ROUND_CLOSEST(timing2->pixel_clock, 1000) ==
  380. DIV_ROUND_CLOSEST(timing1->pixel_clock, 1000)) &&
  381. (timing2->x_res == timing1->x_res) &&
  382. (timing2->y_res == timing1->y_res)) {
  383. timing2_hsync = timing2->hfp + timing2->hsw + timing2->hbp;
  384. timing1_hsync = timing1->hfp + timing1->hsw + timing1->hbp;
  385. timing2_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  386. timing1_vsync = timing2->vfp + timing2->vsw + timing2->vbp;
  387. DSSDBG("timing1_hsync = %d timing1_vsync = %d"\
  388. "timing2_hsync = %d timing2_vsync = %d\n",
  389. timing1_hsync, timing1_vsync,
  390. timing2_hsync, timing2_vsync);
  391. if ((timing1_hsync == timing2_hsync) &&
  392. (timing1_vsync == timing2_vsync)) {
  393. return true;
  394. }
  395. }
  396. return false;
  397. }
  398. static struct hdmi_cm hdmi_get_code(struct omap_video_timings *timing)
  399. {
  400. int i;
  401. struct hdmi_cm cm = {-1};
  402. DSSDBG("hdmi_get_code\n");
  403. for (i = 0; i < ARRAY_SIZE(cea_timings); i++) {
  404. if (hdmi_timings_compare(timing, &cea_timings[i].timings)) {
  405. cm = cea_timings[i].cm;
  406. goto end;
  407. }
  408. }
  409. for (i = 0; i < ARRAY_SIZE(vesa_timings); i++) {
  410. if (hdmi_timings_compare(timing, &vesa_timings[i].timings)) {
  411. cm = vesa_timings[i].cm;
  412. goto end;
  413. }
  414. }
  415. end: return cm;
  416. }
  417. static void hdmi_compute_pll(struct omap_dss_device *dssdev, int phy,
  418. struct hdmi_pll_info *pi)
  419. {
  420. unsigned long clkin, refclk;
  421. u32 mf;
  422. clkin = clk_get_rate(hdmi.sys_clk) / 10000;
  423. /*
  424. * Input clock is predivided by N + 1
  425. * out put of which is reference clk
  426. */
  427. pi->regn = HDMI_DEFAULT_REGN;
  428. refclk = clkin / pi->regn;
  429. pi->regm2 = HDMI_DEFAULT_REGM2;
  430. /*
  431. * multiplier is pixel_clk/ref_clk
  432. * Multiplying by 100 to avoid fractional part removal
  433. */
  434. pi->regm = phy * pi->regm2 / refclk;
  435. /*
  436. * fractional multiplier is remainder of the difference between
  437. * multiplier and actual phy(required pixel clock thus should be
  438. * multiplied by 2^18(262144) divided by the reference clock
  439. */
  440. mf = (phy - pi->regm / pi->regm2 * refclk) * 262144;
  441. pi->regmf = pi->regm2 * mf / refclk;
  442. /*
  443. * Dcofreq should be set to 1 if required pixel clock
  444. * is greater than 1000MHz
  445. */
  446. pi->dcofreq = phy > 1000 * 100;
  447. pi->regsd = ((pi->regm * clkin / 10) / (pi->regn * 250) + 5) / 10;
  448. /* Set the reference clock to sysclk reference */
  449. pi->refsel = HDMI_REFSEL_SYSCLK;
  450. DSSDBG("M = %d Mf = %d\n", pi->regm, pi->regmf);
  451. DSSDBG("range = %d sd = %d\n", pi->dcofreq, pi->regsd);
  452. }
  453. static int hdmi_power_on_core(struct omap_dss_device *dssdev)
  454. {
  455. int r;
  456. if (gpio_is_valid(hdmi.ct_cp_hpd_gpio))
  457. gpio_set_value(hdmi.ct_cp_hpd_gpio, 1);
  458. if (gpio_is_valid(hdmi.ls_oe_gpio))
  459. gpio_set_value(hdmi.ls_oe_gpio, 1);
  460. /* wait 300us after CT_CP_HPD for the 5V power output to reach 90% */
  461. udelay(300);
  462. r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
  463. if (r)
  464. goto err_vdac_enable;
  465. r = hdmi_runtime_get();
  466. if (r)
  467. goto err_runtime_get;
  468. /* Make selection of HDMI in DSS */
  469. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  470. hdmi.core_enabled = true;
  471. return 0;
  472. err_runtime_get:
  473. regulator_disable(hdmi.vdda_hdmi_dac_reg);
  474. err_vdac_enable:
  475. if (gpio_is_valid(hdmi.ct_cp_hpd_gpio))
  476. gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
  477. if (gpio_is_valid(hdmi.ls_oe_gpio))
  478. gpio_set_value(hdmi.ls_oe_gpio, 0);
  479. return r;
  480. }
  481. static void hdmi_power_off_core(struct omap_dss_device *dssdev)
  482. {
  483. hdmi.core_enabled = false;
  484. hdmi_runtime_put();
  485. regulator_disable(hdmi.vdda_hdmi_dac_reg);
  486. if (gpio_is_valid(hdmi.ct_cp_hpd_gpio))
  487. gpio_set_value(hdmi.ct_cp_hpd_gpio, 0);
  488. if (gpio_is_valid(hdmi.ls_oe_gpio))
  489. gpio_set_value(hdmi.ls_oe_gpio, 0);
  490. }
  491. static int hdmi_power_on_full(struct omap_dss_device *dssdev)
  492. {
  493. int r;
  494. struct omap_video_timings *p;
  495. struct omap_overlay_manager *mgr = hdmi.output.manager;
  496. unsigned long phy;
  497. r = hdmi_power_on_core(dssdev);
  498. if (r)
  499. return r;
  500. dss_mgr_disable(mgr);
  501. p = &hdmi.ip_data.cfg.timings;
  502. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
  503. phy = p->pixel_clock;
  504. hdmi_compute_pll(dssdev, phy, &hdmi.ip_data.pll_data);
  505. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  506. /* config the PLL and PHY hdmi_set_pll_pwrfirst */
  507. r = hdmi.ip_data.ops->pll_enable(&hdmi.ip_data);
  508. if (r) {
  509. DSSDBG("Failed to lock PLL\n");
  510. goto err_pll_enable;
  511. }
  512. r = hdmi.ip_data.ops->phy_enable(&hdmi.ip_data);
  513. if (r) {
  514. DSSDBG("Failed to start PHY\n");
  515. goto err_phy_enable;
  516. }
  517. hdmi.ip_data.ops->video_configure(&hdmi.ip_data);
  518. /* bypass TV gamma table */
  519. dispc_enable_gamma_table(0);
  520. /* tv size */
  521. dss_mgr_set_timings(mgr, p);
  522. r = hdmi.ip_data.ops->video_enable(&hdmi.ip_data);
  523. if (r)
  524. goto err_vid_enable;
  525. r = dss_mgr_enable(mgr);
  526. if (r)
  527. goto err_mgr_enable;
  528. return 0;
  529. err_mgr_enable:
  530. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  531. err_vid_enable:
  532. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  533. err_phy_enable:
  534. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  535. err_pll_enable:
  536. hdmi_power_off_core(dssdev);
  537. return -EIO;
  538. }
  539. static void hdmi_power_off_full(struct omap_dss_device *dssdev)
  540. {
  541. struct omap_overlay_manager *mgr = hdmi.output.manager;
  542. dss_mgr_disable(mgr);
  543. hdmi.ip_data.ops->video_disable(&hdmi.ip_data);
  544. hdmi.ip_data.ops->phy_disable(&hdmi.ip_data);
  545. hdmi.ip_data.ops->pll_disable(&hdmi.ip_data);
  546. hdmi_power_off_core(dssdev);
  547. }
  548. int omapdss_hdmi_display_check_timing(struct omap_dss_device *dssdev,
  549. struct omap_video_timings *timings)
  550. {
  551. struct hdmi_cm cm;
  552. cm = hdmi_get_code(timings);
  553. if (cm.code == -1) {
  554. return -EINVAL;
  555. }
  556. return 0;
  557. }
  558. void omapdss_hdmi_display_set_timing(struct omap_dss_device *dssdev,
  559. struct omap_video_timings *timings)
  560. {
  561. struct hdmi_cm cm;
  562. const struct hdmi_config *t;
  563. mutex_lock(&hdmi.lock);
  564. cm = hdmi_get_code(timings);
  565. hdmi.ip_data.cfg.cm = cm;
  566. t = hdmi_get_timings();
  567. if (t != NULL)
  568. hdmi.ip_data.cfg = *t;
  569. dispc_set_tv_pclk(t->timings.pixel_clock * 1000);
  570. mutex_unlock(&hdmi.lock);
  571. }
  572. static void omapdss_hdmi_display_get_timings(struct omap_dss_device *dssdev,
  573. struct omap_video_timings *timings)
  574. {
  575. const struct hdmi_config *cfg;
  576. cfg = hdmi_get_timings();
  577. if (cfg == NULL)
  578. cfg = &vesa_timings[0];
  579. memcpy(timings, &cfg->timings, sizeof(cfg->timings));
  580. }
  581. static void hdmi_dump_regs(struct seq_file *s)
  582. {
  583. mutex_lock(&hdmi.lock);
  584. if (hdmi_runtime_get()) {
  585. mutex_unlock(&hdmi.lock);
  586. return;
  587. }
  588. hdmi.ip_data.ops->dump_wrapper(&hdmi.ip_data, s);
  589. hdmi.ip_data.ops->dump_pll(&hdmi.ip_data, s);
  590. hdmi.ip_data.ops->dump_phy(&hdmi.ip_data, s);
  591. hdmi.ip_data.ops->dump_core(&hdmi.ip_data, s);
  592. hdmi_runtime_put();
  593. mutex_unlock(&hdmi.lock);
  594. }
  595. int omapdss_hdmi_read_edid(u8 *buf, int len)
  596. {
  597. int r;
  598. mutex_lock(&hdmi.lock);
  599. r = hdmi_runtime_get();
  600. BUG_ON(r);
  601. r = hdmi.ip_data.ops->read_edid(&hdmi.ip_data, buf, len);
  602. hdmi_runtime_put();
  603. mutex_unlock(&hdmi.lock);
  604. return r;
  605. }
  606. bool omapdss_hdmi_detect(void)
  607. {
  608. int r;
  609. mutex_lock(&hdmi.lock);
  610. r = hdmi_runtime_get();
  611. BUG_ON(r);
  612. r = gpio_get_value(hdmi.hpd_gpio);
  613. hdmi_runtime_put();
  614. mutex_unlock(&hdmi.lock);
  615. return r == 1;
  616. }
  617. int omapdss_hdmi_display_enable(struct omap_dss_device *dssdev)
  618. {
  619. struct omap_dss_device *out = &hdmi.output;
  620. int r = 0;
  621. DSSDBG("ENTER hdmi_display_enable\n");
  622. mutex_lock(&hdmi.lock);
  623. if (out == NULL || out->manager == NULL) {
  624. DSSERR("failed to enable display: no output/manager\n");
  625. r = -ENODEV;
  626. goto err0;
  627. }
  628. r = hdmi_power_on_full(dssdev);
  629. if (r) {
  630. DSSERR("failed to power on device\n");
  631. goto err0;
  632. }
  633. mutex_unlock(&hdmi.lock);
  634. return 0;
  635. err0:
  636. mutex_unlock(&hdmi.lock);
  637. return r;
  638. }
  639. void omapdss_hdmi_display_disable(struct omap_dss_device *dssdev)
  640. {
  641. DSSDBG("Enter hdmi_display_disable\n");
  642. mutex_lock(&hdmi.lock);
  643. hdmi_power_off_full(dssdev);
  644. mutex_unlock(&hdmi.lock);
  645. }
  646. int omapdss_hdmi_core_enable(struct omap_dss_device *dssdev)
  647. {
  648. int r = 0;
  649. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  650. mutex_lock(&hdmi.lock);
  651. r = hdmi_power_on_core(dssdev);
  652. if (r) {
  653. DSSERR("failed to power on device\n");
  654. goto err0;
  655. }
  656. mutex_unlock(&hdmi.lock);
  657. return 0;
  658. err0:
  659. mutex_unlock(&hdmi.lock);
  660. return r;
  661. }
  662. void omapdss_hdmi_core_disable(struct omap_dss_device *dssdev)
  663. {
  664. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  665. mutex_lock(&hdmi.lock);
  666. hdmi_power_off_core(dssdev);
  667. mutex_unlock(&hdmi.lock);
  668. }
  669. static int hdmi_get_clocks(struct platform_device *pdev)
  670. {
  671. struct clk *clk;
  672. clk = devm_clk_get(&pdev->dev, "sys_clk");
  673. if (IS_ERR(clk)) {
  674. DSSERR("can't get sys_clk\n");
  675. return PTR_ERR(clk);
  676. }
  677. hdmi.sys_clk = clk;
  678. return 0;
  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 *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 int 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 0;
  837. dssdev = dss_alloc_and_init_device(&pdev->dev);
  838. if (!dssdev)
  839. return -ENOMEM;
  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. r = hdmi_init_display(dssdev);
  846. if (r) {
  847. DSSERR("device %s init failed: %d\n", dssdev->name, r);
  848. dss_put_device(dssdev);
  849. return r;
  850. }
  851. r = omapdss_output_set_device(&hdmi.output, dssdev);
  852. if (r) {
  853. DSSERR("failed to connect output to new device: %s\n",
  854. dssdev->name);
  855. dss_put_device(dssdev);
  856. return r;
  857. }
  858. r = dss_add_device(dssdev);
  859. if (r) {
  860. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  861. omapdss_output_unset_device(&hdmi.output);
  862. hdmi_uninit_display(dssdev);
  863. dss_put_device(dssdev);
  864. return r;
  865. }
  866. return 0;
  867. }
  868. static int hdmi_connect(struct omap_dss_device *dssdev,
  869. struct omap_dss_device *dst)
  870. {
  871. struct omap_overlay_manager *mgr;
  872. int r;
  873. dss_init_hdmi_ip_ops(&hdmi.ip_data, omapdss_get_version());
  874. r = hdmi_init_regulator();
  875. if (r)
  876. return r;
  877. mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
  878. if (!mgr)
  879. return -ENODEV;
  880. r = dss_mgr_connect(mgr, dssdev);
  881. if (r)
  882. return r;
  883. r = omapdss_output_set_device(dssdev, dst);
  884. if (r) {
  885. DSSERR("failed to connect output to new device: %s\n",
  886. dst->name);
  887. dss_mgr_disconnect(mgr, dssdev);
  888. return r;
  889. }
  890. return 0;
  891. }
  892. static void hdmi_disconnect(struct omap_dss_device *dssdev,
  893. struct omap_dss_device *dst)
  894. {
  895. WARN_ON(dst != dssdev->device);
  896. if (dst != dssdev->device)
  897. return;
  898. omapdss_output_unset_device(dssdev);
  899. if (dssdev->manager)
  900. dss_mgr_disconnect(dssdev->manager, dssdev);
  901. }
  902. static int hdmi_read_edid(struct omap_dss_device *dssdev,
  903. u8 *edid, int len)
  904. {
  905. bool need_enable;
  906. int r;
  907. need_enable = hdmi.core_enabled == false;
  908. if (need_enable) {
  909. r = omapdss_hdmi_core_enable(dssdev);
  910. if (r)
  911. return r;
  912. }
  913. r = omapdss_hdmi_read_edid(edid, len);
  914. if (need_enable)
  915. omapdss_hdmi_core_disable(dssdev);
  916. return r;
  917. }
  918. #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
  919. static int omapdss_hdmi_audio_enable(struct omap_dss_device *dssdev)
  920. {
  921. int r;
  922. mutex_lock(&hdmi.lock);
  923. if (!hdmi_mode_has_audio()) {
  924. r = -EPERM;
  925. goto err;
  926. }
  927. r = hdmi_audio_enable();
  928. if (r)
  929. goto err;
  930. mutex_unlock(&hdmi.lock);
  931. return 0;
  932. err:
  933. mutex_unlock(&hdmi.lock);
  934. return r;
  935. }
  936. static void omapdss_hdmi_audio_disable(struct omap_dss_device *dssdev)
  937. {
  938. hdmi_audio_disable();
  939. }
  940. static int omapdss_hdmi_audio_start(struct omap_dss_device *dssdev)
  941. {
  942. return hdmi_audio_start();
  943. }
  944. static void omapdss_hdmi_audio_stop(struct omap_dss_device *dssdev)
  945. {
  946. hdmi_audio_stop();
  947. }
  948. static bool omapdss_hdmi_audio_supported(struct omap_dss_device *dssdev)
  949. {
  950. bool r;
  951. mutex_lock(&hdmi.lock);
  952. r = hdmi_mode_has_audio();
  953. mutex_unlock(&hdmi.lock);
  954. return r;
  955. }
  956. static int omapdss_hdmi_audio_config(struct omap_dss_device *dssdev,
  957. struct omap_dss_audio *audio)
  958. {
  959. int r;
  960. mutex_lock(&hdmi.lock);
  961. if (!hdmi_mode_has_audio()) {
  962. r = -EPERM;
  963. goto err;
  964. }
  965. r = hdmi_audio_config(audio);
  966. if (r)
  967. goto err;
  968. mutex_unlock(&hdmi.lock);
  969. return 0;
  970. err:
  971. mutex_unlock(&hdmi.lock);
  972. return r;
  973. }
  974. #else
  975. static int omapdss_hdmi_audio_enable(struct omap_dss_device *dssdev)
  976. {
  977. return -EPERM;
  978. }
  979. static void omapdss_hdmi_audio_disable(struct omap_dss_device *dssdev)
  980. {
  981. }
  982. static int omapdss_hdmi_audio_start(struct omap_dss_device *dssdev)
  983. {
  984. return -EPERM;
  985. }
  986. static void omapdss_hdmi_audio_stop(struct omap_dss_device *dssdev)
  987. {
  988. }
  989. static bool omapdss_hdmi_audio_supported(struct omap_dss_device *dssdev)
  990. {
  991. return false;
  992. }
  993. static int omapdss_hdmi_audio_config(struct omap_dss_device *dssdev,
  994. struct omap_dss_audio *audio)
  995. {
  996. return -EPERM;
  997. }
  998. #endif
  999. static const struct omapdss_hdmi_ops hdmi_ops = {
  1000. .connect = hdmi_connect,
  1001. .disconnect = hdmi_disconnect,
  1002. .enable = omapdss_hdmi_display_enable,
  1003. .disable = omapdss_hdmi_display_disable,
  1004. .check_timings = omapdss_hdmi_display_check_timing,
  1005. .set_timings = omapdss_hdmi_display_set_timing,
  1006. .get_timings = omapdss_hdmi_display_get_timings,
  1007. .read_edid = hdmi_read_edid,
  1008. .audio_enable = omapdss_hdmi_audio_enable,
  1009. .audio_disable = omapdss_hdmi_audio_disable,
  1010. .audio_start = omapdss_hdmi_audio_start,
  1011. .audio_stop = omapdss_hdmi_audio_stop,
  1012. .audio_supported = omapdss_hdmi_audio_supported,
  1013. .audio_config = omapdss_hdmi_audio_config,
  1014. };
  1015. static void hdmi_init_output(struct platform_device *pdev)
  1016. {
  1017. struct omap_dss_device *out = &hdmi.output;
  1018. out->dev = &pdev->dev;
  1019. out->id = OMAP_DSS_OUTPUT_HDMI;
  1020. out->output_type = OMAP_DISPLAY_TYPE_HDMI;
  1021. out->name = "hdmi.0";
  1022. out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
  1023. out->ops.hdmi = &hdmi_ops;
  1024. out->owner = THIS_MODULE;
  1025. omapdss_register_output(out);
  1026. }
  1027. static void __exit hdmi_uninit_output(struct platform_device *pdev)
  1028. {
  1029. struct omap_dss_device *out = &hdmi.output;
  1030. omapdss_unregister_output(out);
  1031. }
  1032. /* HDMI HW IP initialisation */
  1033. static int omapdss_hdmihw_probe(struct platform_device *pdev)
  1034. {
  1035. struct resource *res;
  1036. int r;
  1037. hdmi.pdev = pdev;
  1038. mutex_init(&hdmi.lock);
  1039. mutex_init(&hdmi.ip_data.lock);
  1040. res = platform_get_resource(hdmi.pdev, IORESOURCE_MEM, 0);
  1041. /* Base address taken from platform */
  1042. hdmi.ip_data.base_wp = devm_ioremap_resource(&pdev->dev, res);
  1043. if (IS_ERR(hdmi.ip_data.base_wp))
  1044. return PTR_ERR(hdmi.ip_data.base_wp);
  1045. hdmi.ip_data.irq = platform_get_irq(pdev, 0);
  1046. if (hdmi.ip_data.irq < 0) {
  1047. DSSERR("platform_get_irq failed\n");
  1048. return -ENODEV;
  1049. }
  1050. r = hdmi_get_clocks(pdev);
  1051. if (r) {
  1052. DSSERR("can't get clocks\n");
  1053. return r;
  1054. }
  1055. pm_runtime_enable(&pdev->dev);
  1056. hdmi.ip_data.core_sys_offset = HDMI_CORE_SYS;
  1057. hdmi.ip_data.core_av_offset = HDMI_CORE_AV;
  1058. hdmi.ip_data.pll_offset = HDMI_PLLCTRL;
  1059. hdmi.ip_data.phy_offset = HDMI_PHY;
  1060. hdmi.ct_cp_hpd_gpio = -1;
  1061. hdmi.ls_oe_gpio = -1;
  1062. hdmi.hpd_gpio = -1;
  1063. hdmi_init_output(pdev);
  1064. r = hdmi_panel_init();
  1065. if (r) {
  1066. DSSERR("can't init panel\n");
  1067. return r;
  1068. }
  1069. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  1070. if (pdev->dev.platform_data) {
  1071. r = hdmi_probe_pdata(pdev);
  1072. if (r)
  1073. goto err_probe;
  1074. }
  1075. return 0;
  1076. err_probe:
  1077. hdmi_panel_exit();
  1078. hdmi_uninit_output(pdev);
  1079. pm_runtime_disable(&pdev->dev);
  1080. return r;
  1081. }
  1082. static int __exit hdmi_remove_child(struct device *dev, void *data)
  1083. {
  1084. struct omap_dss_device *dssdev = to_dss_device(dev);
  1085. hdmi_uninit_display(dssdev);
  1086. return 0;
  1087. }
  1088. static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
  1089. {
  1090. device_for_each_child(&pdev->dev, NULL, hdmi_remove_child);
  1091. dss_unregister_child_devices(&pdev->dev);
  1092. hdmi_panel_exit();
  1093. hdmi_uninit_output(pdev);
  1094. pm_runtime_disable(&pdev->dev);
  1095. return 0;
  1096. }
  1097. static int hdmi_runtime_suspend(struct device *dev)
  1098. {
  1099. clk_disable_unprepare(hdmi.sys_clk);
  1100. dispc_runtime_put();
  1101. return 0;
  1102. }
  1103. static int hdmi_runtime_resume(struct device *dev)
  1104. {
  1105. int r;
  1106. r = dispc_runtime_get();
  1107. if (r < 0)
  1108. return r;
  1109. clk_prepare_enable(hdmi.sys_clk);
  1110. return 0;
  1111. }
  1112. static const struct dev_pm_ops hdmi_pm_ops = {
  1113. .runtime_suspend = hdmi_runtime_suspend,
  1114. .runtime_resume = hdmi_runtime_resume,
  1115. };
  1116. static struct platform_driver omapdss_hdmihw_driver = {
  1117. .probe = omapdss_hdmihw_probe,
  1118. .remove = __exit_p(omapdss_hdmihw_remove),
  1119. .driver = {
  1120. .name = "omapdss_hdmi",
  1121. .owner = THIS_MODULE,
  1122. .pm = &hdmi_pm_ops,
  1123. },
  1124. };
  1125. int __init hdmi_init_platform_driver(void)
  1126. {
  1127. return platform_driver_register(&omapdss_hdmihw_driver);
  1128. }
  1129. void __exit hdmi_uninit_platform_driver(void)
  1130. {
  1131. platform_driver_unregister(&omapdss_hdmihw_driver);
  1132. }