exynos_hdmi.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Seung-Woo Kim <sw0312.kim@samsung.com>
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * Based on drivers/media/video/s5p-tv/hdmi_drv.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include "drmP.h"
  17. #include "drm_edid.h"
  18. #include "drm_crtc_helper.h"
  19. #include "regs-hdmi.h"
  20. #include <linux/kernel.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/wait.h>
  23. #include <linux/i2c.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/irq.h>
  28. #include <linux/delay.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/clk.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <drm/exynos_drm.h>
  33. #include "exynos_drm_drv.h"
  34. #include "exynos_drm_hdmi.h"
  35. #include "exynos_hdmi.h"
  36. #define HDMI_OVERLAY_NUMBER 3
  37. #define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
  38. static const u8 hdmiphy_conf27[32] = {
  39. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  40. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  41. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  42. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  43. };
  44. static const u8 hdmiphy_conf27_027[32] = {
  45. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  46. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  47. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  48. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  49. };
  50. static const u8 hdmiphy_conf74_175[32] = {
  51. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  52. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  53. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  54. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  55. };
  56. static const u8 hdmiphy_conf74_25[32] = {
  57. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  58. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  59. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  60. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  61. };
  62. static const u8 hdmiphy_conf148_5[32] = {
  63. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  64. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  65. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  66. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  67. };
  68. struct hdmi_tg_regs {
  69. u8 cmd;
  70. u8 h_fsz_l;
  71. u8 h_fsz_h;
  72. u8 hact_st_l;
  73. u8 hact_st_h;
  74. u8 hact_sz_l;
  75. u8 hact_sz_h;
  76. u8 v_fsz_l;
  77. u8 v_fsz_h;
  78. u8 vsync_l;
  79. u8 vsync_h;
  80. u8 vsync2_l;
  81. u8 vsync2_h;
  82. u8 vact_st_l;
  83. u8 vact_st_h;
  84. u8 vact_sz_l;
  85. u8 vact_sz_h;
  86. u8 field_chg_l;
  87. u8 field_chg_h;
  88. u8 vact_st2_l;
  89. u8 vact_st2_h;
  90. u8 vsync_top_hdmi_l;
  91. u8 vsync_top_hdmi_h;
  92. u8 vsync_bot_hdmi_l;
  93. u8 vsync_bot_hdmi_h;
  94. u8 field_top_hdmi_l;
  95. u8 field_top_hdmi_h;
  96. u8 field_bot_hdmi_l;
  97. u8 field_bot_hdmi_h;
  98. };
  99. struct hdmi_core_regs {
  100. u8 h_blank[2];
  101. u8 v_blank[3];
  102. u8 h_v_line[3];
  103. u8 vsync_pol[1];
  104. u8 int_pro_mode[1];
  105. u8 v_blank_f[3];
  106. u8 h_sync_gen[3];
  107. u8 v_sync_gen1[3];
  108. u8 v_sync_gen2[3];
  109. u8 v_sync_gen3[3];
  110. };
  111. struct hdmi_preset_conf {
  112. struct hdmi_core_regs core;
  113. struct hdmi_tg_regs tg;
  114. };
  115. static const struct hdmi_preset_conf hdmi_conf_480p = {
  116. .core = {
  117. .h_blank = {0x8a, 0x00},
  118. .v_blank = {0x0d, 0x6a, 0x01},
  119. .h_v_line = {0x0d, 0xa2, 0x35},
  120. .vsync_pol = {0x01},
  121. .int_pro_mode = {0x00},
  122. .v_blank_f = {0x00, 0x00, 0x00},
  123. .h_sync_gen = {0x0e, 0x30, 0x11},
  124. .v_sync_gen1 = {0x0f, 0x90, 0x00},
  125. /* other don't care */
  126. },
  127. .tg = {
  128. 0x00, /* cmd */
  129. 0x5a, 0x03, /* h_fsz */
  130. 0x8a, 0x00, 0xd0, 0x02, /* hact */
  131. 0x0d, 0x02, /* v_fsz */
  132. 0x01, 0x00, 0x33, 0x02, /* vsync */
  133. 0x2d, 0x00, 0xe0, 0x01, /* vact */
  134. 0x33, 0x02, /* field_chg */
  135. 0x49, 0x02, /* vact_st2 */
  136. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  137. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  138. },
  139. };
  140. static const struct hdmi_preset_conf hdmi_conf_720p60 = {
  141. .core = {
  142. .h_blank = {0x72, 0x01},
  143. .v_blank = {0xee, 0xf2, 0x00},
  144. .h_v_line = {0xee, 0x22, 0x67},
  145. .vsync_pol = {0x00},
  146. .int_pro_mode = {0x00},
  147. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  148. .h_sync_gen = {0x6c, 0x50, 0x02},
  149. .v_sync_gen1 = {0x0a, 0x50, 0x00},
  150. .v_sync_gen2 = {0x01, 0x10, 0x00},
  151. .v_sync_gen3 = {0x01, 0x10, 0x00},
  152. /* other don't care */
  153. },
  154. .tg = {
  155. 0x00, /* cmd */
  156. 0x72, 0x06, /* h_fsz */
  157. 0x71, 0x01, 0x01, 0x05, /* hact */
  158. 0xee, 0x02, /* v_fsz */
  159. 0x01, 0x00, 0x33, 0x02, /* vsync */
  160. 0x1e, 0x00, 0xd0, 0x02, /* vact */
  161. 0x33, 0x02, /* field_chg */
  162. 0x49, 0x02, /* vact_st2 */
  163. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  164. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  165. },
  166. };
  167. static const struct hdmi_preset_conf hdmi_conf_1080i50 = {
  168. .core = {
  169. .h_blank = {0xd0, 0x02},
  170. .v_blank = {0x32, 0xB2, 0x00},
  171. .h_v_line = {0x65, 0x04, 0xa5},
  172. .vsync_pol = {0x00},
  173. .int_pro_mode = {0x01},
  174. .v_blank_f = {0x49, 0x2A, 0x23},
  175. .h_sync_gen = {0x0E, 0xEA, 0x08},
  176. .v_sync_gen1 = {0x07, 0x20, 0x00},
  177. .v_sync_gen2 = {0x39, 0x42, 0x23},
  178. .v_sync_gen3 = {0x38, 0x87, 0x73},
  179. /* other don't care */
  180. },
  181. .tg = {
  182. 0x00, /* cmd */
  183. 0x50, 0x0A, /* h_fsz */
  184. 0xCF, 0x02, 0x81, 0x07, /* hact */
  185. 0x65, 0x04, /* v_fsz */
  186. 0x01, 0x00, 0x33, 0x02, /* vsync */
  187. 0x16, 0x00, 0x1c, 0x02, /* vact */
  188. 0x33, 0x02, /* field_chg */
  189. 0x49, 0x02, /* vact_st2 */
  190. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  191. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  192. },
  193. };
  194. static const struct hdmi_preset_conf hdmi_conf_1080p50 = {
  195. .core = {
  196. .h_blank = {0xd0, 0x02},
  197. .v_blank = {0x65, 0x6c, 0x01},
  198. .h_v_line = {0x65, 0x04, 0xa5},
  199. .vsync_pol = {0x00},
  200. .int_pro_mode = {0x00},
  201. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  202. .h_sync_gen = {0x0e, 0xea, 0x08},
  203. .v_sync_gen1 = {0x09, 0x40, 0x00},
  204. .v_sync_gen2 = {0x01, 0x10, 0x00},
  205. .v_sync_gen3 = {0x01, 0x10, 0x00},
  206. /* other don't care */
  207. },
  208. .tg = {
  209. 0x00, /* cmd */
  210. 0x50, 0x0A, /* h_fsz */
  211. 0xCF, 0x02, 0x81, 0x07, /* hact */
  212. 0x65, 0x04, /* v_fsz */
  213. 0x01, 0x00, 0x33, 0x02, /* vsync */
  214. 0x2d, 0x00, 0x38, 0x04, /* vact */
  215. 0x33, 0x02, /* field_chg */
  216. 0x48, 0x02, /* vact_st2 */
  217. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  218. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  219. },
  220. };
  221. static const struct hdmi_preset_conf hdmi_conf_1080i60 = {
  222. .core = {
  223. .h_blank = {0x18, 0x01},
  224. .v_blank = {0x32, 0xB2, 0x00},
  225. .h_v_line = {0x65, 0x84, 0x89},
  226. .vsync_pol = {0x00},
  227. .int_pro_mode = {0x01},
  228. .v_blank_f = {0x49, 0x2A, 0x23},
  229. .h_sync_gen = {0x56, 0x08, 0x02},
  230. .v_sync_gen1 = {0x07, 0x20, 0x00},
  231. .v_sync_gen2 = {0x39, 0x42, 0x23},
  232. .v_sync_gen3 = {0xa4, 0x44, 0x4a},
  233. /* other don't care */
  234. },
  235. .tg = {
  236. 0x00, /* cmd */
  237. 0x98, 0x08, /* h_fsz */
  238. 0x17, 0x01, 0x81, 0x07, /* hact */
  239. 0x65, 0x04, /* v_fsz */
  240. 0x01, 0x00, 0x33, 0x02, /* vsync */
  241. 0x16, 0x00, 0x1c, 0x02, /* vact */
  242. 0x33, 0x02, /* field_chg */
  243. 0x49, 0x02, /* vact_st2 */
  244. 0x01, 0x00, 0x33, 0x02, /* vsync top/bot */
  245. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  246. },
  247. };
  248. static const struct hdmi_preset_conf hdmi_conf_1080p60 = {
  249. .core = {
  250. .h_blank = {0x18, 0x01},
  251. .v_blank = {0x65, 0x6c, 0x01},
  252. .h_v_line = {0x65, 0x84, 0x89},
  253. .vsync_pol = {0x00},
  254. .int_pro_mode = {0x00},
  255. .v_blank_f = {0x00, 0x00, 0x00}, /* don't care */
  256. .h_sync_gen = {0x56, 0x08, 0x02},
  257. .v_sync_gen1 = {0x09, 0x40, 0x00},
  258. .v_sync_gen2 = {0x01, 0x10, 0x00},
  259. .v_sync_gen3 = {0x01, 0x10, 0x00},
  260. /* other don't care */
  261. },
  262. .tg = {
  263. 0x00, /* cmd */
  264. 0x98, 0x08, /* h_fsz */
  265. 0x17, 0x01, 0x81, 0x07, /* hact */
  266. 0x65, 0x04, /* v_fsz */
  267. 0x01, 0x00, 0x33, 0x02, /* vsync */
  268. 0x2d, 0x00, 0x38, 0x04, /* vact */
  269. 0x33, 0x02, /* field_chg */
  270. 0x48, 0x02, /* vact_st2 */
  271. 0x01, 0x00, 0x01, 0x00, /* vsync top/bot */
  272. 0x01, 0x00, 0x33, 0x02, /* field top/bot */
  273. },
  274. };
  275. static const struct hdmi_conf hdmi_confs[] = {
  276. { 1280, 720, 60, false, hdmiphy_conf74_25, &hdmi_conf_720p60 },
  277. { 1280, 720, 50, false, hdmiphy_conf74_25, &hdmi_conf_720p60 },
  278. { 720, 480, 60, false, hdmiphy_conf27_027, &hdmi_conf_480p },
  279. { 1920, 1080, 50, true, hdmiphy_conf74_25, &hdmi_conf_1080i50 },
  280. { 1920, 1080, 50, false, hdmiphy_conf148_5, &hdmi_conf_1080p50 },
  281. { 1920, 1080, 60, true, hdmiphy_conf74_25, &hdmi_conf_1080i60 },
  282. { 1920, 1080, 60, false, hdmiphy_conf148_5, &hdmi_conf_1080p60 },
  283. };
  284. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  285. {
  286. return readl(hdata->regs + reg_id);
  287. }
  288. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  289. u32 reg_id, u8 value)
  290. {
  291. writeb(value, hdata->regs + reg_id);
  292. }
  293. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  294. u32 reg_id, u32 value, u32 mask)
  295. {
  296. u32 old = readl(hdata->regs + reg_id);
  297. value = (value & mask) | (old & ~mask);
  298. writel(value, hdata->regs + reg_id);
  299. }
  300. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  301. {
  302. #define DUMPREG(reg_id) \
  303. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  304. readl(hdata->regs + reg_id))
  305. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  306. DUMPREG(HDMI_INTC_FLAG);
  307. DUMPREG(HDMI_INTC_CON);
  308. DUMPREG(HDMI_HPD_STATUS);
  309. DUMPREG(HDMI_PHY_RSTOUT);
  310. DUMPREG(HDMI_PHY_VPLL);
  311. DUMPREG(HDMI_PHY_CMU);
  312. DUMPREG(HDMI_CORE_RSTOUT);
  313. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  314. DUMPREG(HDMI_CON_0);
  315. DUMPREG(HDMI_CON_1);
  316. DUMPREG(HDMI_CON_2);
  317. DUMPREG(HDMI_SYS_STATUS);
  318. DUMPREG(HDMI_PHY_STATUS);
  319. DUMPREG(HDMI_STATUS_EN);
  320. DUMPREG(HDMI_HPD);
  321. DUMPREG(HDMI_MODE_SEL);
  322. DUMPREG(HDMI_HPD_GEN);
  323. DUMPREG(HDMI_DC_CONTROL);
  324. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  325. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  326. DUMPREG(HDMI_H_BLANK_0);
  327. DUMPREG(HDMI_H_BLANK_1);
  328. DUMPREG(HDMI_V_BLANK_0);
  329. DUMPREG(HDMI_V_BLANK_1);
  330. DUMPREG(HDMI_V_BLANK_2);
  331. DUMPREG(HDMI_H_V_LINE_0);
  332. DUMPREG(HDMI_H_V_LINE_1);
  333. DUMPREG(HDMI_H_V_LINE_2);
  334. DUMPREG(HDMI_VSYNC_POL);
  335. DUMPREG(HDMI_INT_PRO_MODE);
  336. DUMPREG(HDMI_V_BLANK_F_0);
  337. DUMPREG(HDMI_V_BLANK_F_1);
  338. DUMPREG(HDMI_V_BLANK_F_2);
  339. DUMPREG(HDMI_H_SYNC_GEN_0);
  340. DUMPREG(HDMI_H_SYNC_GEN_1);
  341. DUMPREG(HDMI_H_SYNC_GEN_2);
  342. DUMPREG(HDMI_V_SYNC_GEN_1_0);
  343. DUMPREG(HDMI_V_SYNC_GEN_1_1);
  344. DUMPREG(HDMI_V_SYNC_GEN_1_2);
  345. DUMPREG(HDMI_V_SYNC_GEN_2_0);
  346. DUMPREG(HDMI_V_SYNC_GEN_2_1);
  347. DUMPREG(HDMI_V_SYNC_GEN_2_2);
  348. DUMPREG(HDMI_V_SYNC_GEN_3_0);
  349. DUMPREG(HDMI_V_SYNC_GEN_3_1);
  350. DUMPREG(HDMI_V_SYNC_GEN_3_2);
  351. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  352. DUMPREG(HDMI_TG_CMD);
  353. DUMPREG(HDMI_TG_H_FSZ_L);
  354. DUMPREG(HDMI_TG_H_FSZ_H);
  355. DUMPREG(HDMI_TG_HACT_ST_L);
  356. DUMPREG(HDMI_TG_HACT_ST_H);
  357. DUMPREG(HDMI_TG_HACT_SZ_L);
  358. DUMPREG(HDMI_TG_HACT_SZ_H);
  359. DUMPREG(HDMI_TG_V_FSZ_L);
  360. DUMPREG(HDMI_TG_V_FSZ_H);
  361. DUMPREG(HDMI_TG_VSYNC_L);
  362. DUMPREG(HDMI_TG_VSYNC_H);
  363. DUMPREG(HDMI_TG_VSYNC2_L);
  364. DUMPREG(HDMI_TG_VSYNC2_H);
  365. DUMPREG(HDMI_TG_VACT_ST_L);
  366. DUMPREG(HDMI_TG_VACT_ST_H);
  367. DUMPREG(HDMI_TG_VACT_SZ_L);
  368. DUMPREG(HDMI_TG_VACT_SZ_H);
  369. DUMPREG(HDMI_TG_FIELD_CHG_L);
  370. DUMPREG(HDMI_TG_FIELD_CHG_H);
  371. DUMPREG(HDMI_TG_VACT_ST2_L);
  372. DUMPREG(HDMI_TG_VACT_ST2_H);
  373. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  374. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  375. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  376. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  377. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  378. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  379. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  380. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  381. #undef DUMPREG
  382. }
  383. static int hdmi_conf_index(struct drm_display_mode *mode)
  384. {
  385. int i;
  386. for (i = 0; i < ARRAY_SIZE(hdmi_confs); ++i)
  387. if (hdmi_confs[i].width == mode->hdisplay &&
  388. hdmi_confs[i].height == mode->vdisplay &&
  389. hdmi_confs[i].vrefresh == mode->vrefresh &&
  390. hdmi_confs[i].interlace ==
  391. ((mode->flags & DRM_MODE_FLAG_INTERLACE) ?
  392. true : false))
  393. return i;
  394. return -1;
  395. }
  396. static bool hdmi_is_connected(void *ctx)
  397. {
  398. struct hdmi_context *hdata = (struct hdmi_context *)ctx;
  399. u32 val = hdmi_reg_read(hdata, HDMI_HPD_STATUS);
  400. if (val)
  401. return true;
  402. return false;
  403. }
  404. static int hdmi_get_edid(void *ctx, struct drm_connector *connector,
  405. u8 *edid, int len)
  406. {
  407. struct edid *raw_edid;
  408. struct hdmi_context *hdata = (struct hdmi_context *)ctx;
  409. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  410. if (!hdata->ddc_port)
  411. return -ENODEV;
  412. raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
  413. if (raw_edid) {
  414. memcpy(edid, raw_edid, min((1 + raw_edid->extensions)
  415. * EDID_LENGTH, len));
  416. DRM_DEBUG_KMS("width[%d] x height[%d]\n",
  417. raw_edid->width_cm, raw_edid->height_cm);
  418. } else {
  419. return -ENODEV;
  420. }
  421. return 0;
  422. }
  423. static int hdmi_check_timing(void *ctx, void *timing)
  424. {
  425. struct fb_videomode *check_timing = timing;
  426. int i;
  427. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  428. DRM_DEBUG_KMS("[%d]x[%d] [%d]Hz [%x]\n", check_timing->xres,
  429. check_timing->yres, check_timing->refresh,
  430. check_timing->vmode);
  431. for (i = 0; i < ARRAY_SIZE(hdmi_confs); ++i)
  432. if (hdmi_confs[i].width == check_timing->xres &&
  433. hdmi_confs[i].height == check_timing->yres &&
  434. hdmi_confs[i].vrefresh == check_timing->refresh &&
  435. hdmi_confs[i].interlace ==
  436. ((check_timing->vmode & FB_VMODE_INTERLACED) ?
  437. true : false))
  438. return 0;
  439. return -EINVAL;
  440. }
  441. static int hdmi_display_power_on(void *ctx, int mode)
  442. {
  443. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  444. switch (mode) {
  445. case DRM_MODE_DPMS_ON:
  446. DRM_DEBUG_KMS("hdmi [on]\n");
  447. break;
  448. case DRM_MODE_DPMS_STANDBY:
  449. break;
  450. case DRM_MODE_DPMS_SUSPEND:
  451. break;
  452. case DRM_MODE_DPMS_OFF:
  453. DRM_DEBUG_KMS("hdmi [off]\n");
  454. break;
  455. default:
  456. break;
  457. }
  458. return 0;
  459. }
  460. static struct exynos_hdmi_display_ops display_ops = {
  461. .is_connected = hdmi_is_connected,
  462. .get_edid = hdmi_get_edid,
  463. .check_timing = hdmi_check_timing,
  464. .power_on = hdmi_display_power_on,
  465. };
  466. static void hdmi_conf_reset(struct hdmi_context *hdata)
  467. {
  468. /* disable hpd handle for drm */
  469. hdata->hpd_handle = false;
  470. /* resetting HDMI core */
  471. hdmi_reg_writemask(hdata, HDMI_CORE_RSTOUT, 0, HDMI_CORE_SW_RSTOUT);
  472. mdelay(10);
  473. hdmi_reg_writemask(hdata, HDMI_CORE_RSTOUT, ~0, HDMI_CORE_SW_RSTOUT);
  474. mdelay(10);
  475. /* enable hpd handle for drm */
  476. hdata->hpd_handle = true;
  477. }
  478. static void hdmi_conf_init(struct hdmi_context *hdata)
  479. {
  480. /* disable hpd handle for drm */
  481. hdata->hpd_handle = false;
  482. /* enable HPD interrupts */
  483. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  484. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  485. mdelay(10);
  486. hdmi_reg_writemask(hdata, HDMI_INTC_CON, ~0, HDMI_INTC_EN_GLOBAL |
  487. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  488. /* choose HDMI mode */
  489. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  490. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  491. /* disable bluescreen */
  492. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  493. /* choose bluescreen (fecal) color */
  494. hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_0, 0x12);
  495. hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_1, 0x34);
  496. hdmi_reg_writeb(hdata, HDMI_BLUE_SCREEN_2, 0x56);
  497. /* enable AVI packet every vsync, fixes purple line problem */
  498. hdmi_reg_writeb(hdata, HDMI_AVI_CON, 0x02);
  499. /* force RGB, look to CEA-861-D, table 7 for more detail */
  500. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(0), 0 << 5);
  501. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  502. hdmi_reg_writeb(hdata, HDMI_SPD_CON, 0x02);
  503. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  504. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 0x04);
  505. /* enable hpd handle for drm */
  506. hdata->hpd_handle = true;
  507. }
  508. static void hdmi_timing_apply(struct hdmi_context *hdata,
  509. const struct hdmi_preset_conf *conf)
  510. {
  511. const struct hdmi_core_regs *core = &conf->core;
  512. const struct hdmi_tg_regs *tg = &conf->tg;
  513. int tries;
  514. /* setting core registers */
  515. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  516. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  517. hdmi_reg_writeb(hdata, HDMI_V_BLANK_0, core->v_blank[0]);
  518. hdmi_reg_writeb(hdata, HDMI_V_BLANK_1, core->v_blank[1]);
  519. hdmi_reg_writeb(hdata, HDMI_V_BLANK_2, core->v_blank[2]);
  520. hdmi_reg_writeb(hdata, HDMI_H_V_LINE_0, core->h_v_line[0]);
  521. hdmi_reg_writeb(hdata, HDMI_H_V_LINE_1, core->h_v_line[1]);
  522. hdmi_reg_writeb(hdata, HDMI_H_V_LINE_2, core->h_v_line[2]);
  523. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  524. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  525. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F_0, core->v_blank_f[0]);
  526. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F_1, core->v_blank_f[1]);
  527. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F_2, core->v_blank_f[2]);
  528. hdmi_reg_writeb(hdata, HDMI_H_SYNC_GEN_0, core->h_sync_gen[0]);
  529. hdmi_reg_writeb(hdata, HDMI_H_SYNC_GEN_1, core->h_sync_gen[1]);
  530. hdmi_reg_writeb(hdata, HDMI_H_SYNC_GEN_2, core->h_sync_gen[2]);
  531. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  532. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  533. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  534. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  535. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  536. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  537. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  538. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  539. hdmi_reg_writeb(hdata, HDMI_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  540. /* Timing generator registers */
  541. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz_l);
  542. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz_h);
  543. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st_l);
  544. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st_h);
  545. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz_l);
  546. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz_h);
  547. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz_l);
  548. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz_h);
  549. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync_l);
  550. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync_h);
  551. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2_l);
  552. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2_h);
  553. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st_l);
  554. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st_h);
  555. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz_l);
  556. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz_h);
  557. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg_l);
  558. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg_h);
  559. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2_l);
  560. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2_h);
  561. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi_l);
  562. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi_h);
  563. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi_l);
  564. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi_h);
  565. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi_l);
  566. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi_h);
  567. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi_l);
  568. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi_h);
  569. /* waiting for HDMIPHY's PLL to get to steady state */
  570. for (tries = 100; tries; --tries) {
  571. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS);
  572. if (val & HDMI_PHY_STATUS_READY)
  573. break;
  574. mdelay(1);
  575. }
  576. /* steady state not achieved */
  577. if (tries == 0) {
  578. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  579. hdmi_regs_dump(hdata, "timing apply");
  580. }
  581. clk_disable(hdata->res.sclk_hdmi);
  582. clk_set_parent(hdata->res.sclk_hdmi, hdata->res.sclk_hdmiphy);
  583. clk_enable(hdata->res.sclk_hdmi);
  584. /* enable HDMI and timing generator */
  585. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  586. if (core->int_pro_mode[0])
  587. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  588. HDMI_FIELD_EN);
  589. else
  590. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  591. }
  592. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  593. {
  594. u8 buffer[2];
  595. clk_disable(hdata->res.sclk_hdmi);
  596. clk_set_parent(hdata->res.sclk_hdmi, hdata->res.sclk_pixel);
  597. clk_enable(hdata->res.sclk_hdmi);
  598. /* operation mode */
  599. buffer[0] = 0x1f;
  600. buffer[1] = 0x00;
  601. if (hdata->hdmiphy_port)
  602. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  603. /* reset hdmiphy */
  604. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, ~0, HDMI_PHY_SW_RSTOUT);
  605. mdelay(10);
  606. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, 0, HDMI_PHY_SW_RSTOUT);
  607. mdelay(10);
  608. }
  609. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  610. {
  611. u8 buffer[32];
  612. u8 operation[2];
  613. u8 read_buffer[32] = {0, };
  614. int ret;
  615. int i;
  616. if (!hdata->hdmiphy_port) {
  617. DRM_ERROR("hdmiphy is not attached\n");
  618. return;
  619. }
  620. /* pixel clock */
  621. memcpy(buffer, hdmi_confs[hdata->cur_conf].hdmiphy_data, 32);
  622. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 32);
  623. if (ret != 32) {
  624. DRM_ERROR("failed to configure HDMIPHY via I2C\n");
  625. return;
  626. }
  627. mdelay(10);
  628. /* operation mode */
  629. operation[0] = 0x1f;
  630. operation[1] = 0x80;
  631. ret = i2c_master_send(hdata->hdmiphy_port, operation, 2);
  632. if (ret != 2) {
  633. DRM_ERROR("failed to enable hdmiphy\n");
  634. return;
  635. }
  636. ret = i2c_master_recv(hdata->hdmiphy_port, read_buffer, 32);
  637. if (ret < 0) {
  638. DRM_ERROR("failed to read hdmiphy config\n");
  639. return;
  640. }
  641. for (i = 0; i < ret; i++)
  642. DRM_DEBUG_KMS("hdmiphy[0x%02x] write[0x%02x] - "
  643. "recv [0x%02x]\n", i, buffer[i], read_buffer[i]);
  644. }
  645. static void hdmi_conf_apply(struct hdmi_context *hdata)
  646. {
  647. const struct hdmi_preset_conf *conf =
  648. hdmi_confs[hdata->cur_conf].conf;
  649. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  650. hdmiphy_conf_reset(hdata);
  651. hdmiphy_conf_apply(hdata);
  652. hdmi_conf_reset(hdata);
  653. hdmi_conf_init(hdata);
  654. /* setting core registers */
  655. hdmi_timing_apply(hdata, conf);
  656. hdmi_regs_dump(hdata, "start");
  657. }
  658. static void hdmi_mode_set(void *ctx, void *mode)
  659. {
  660. struct hdmi_context *hdata = (struct hdmi_context *)ctx;
  661. int conf_idx;
  662. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  663. conf_idx = hdmi_conf_index(mode);
  664. if (conf_idx >= 0 && conf_idx < ARRAY_SIZE(hdmi_confs))
  665. hdata->cur_conf = conf_idx;
  666. else
  667. DRM_DEBUG_KMS("not supported mode\n");
  668. }
  669. static void hdmi_commit(void *ctx)
  670. {
  671. struct hdmi_context *hdata = (struct hdmi_context *)ctx;
  672. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  673. hdmi_conf_apply(hdata);
  674. hdata->enabled = true;
  675. }
  676. static void hdmi_disable(void *ctx)
  677. {
  678. struct hdmi_context *hdata = (struct hdmi_context *)ctx;
  679. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  680. if (hdata->enabled) {
  681. hdmiphy_conf_reset(hdata);
  682. hdmi_conf_reset(hdata);
  683. }
  684. }
  685. static struct exynos_hdmi_manager_ops manager_ops = {
  686. .mode_set = hdmi_mode_set,
  687. .commit = hdmi_commit,
  688. .disable = hdmi_disable,
  689. };
  690. /*
  691. * Handle hotplug events outside the interrupt handler proper.
  692. */
  693. static void hdmi_hotplug_func(struct work_struct *work)
  694. {
  695. struct hdmi_context *hdata =
  696. container_of(work, struct hdmi_context, hotplug_work);
  697. struct exynos_drm_hdmi_context *ctx =
  698. (struct exynos_drm_hdmi_context *)hdata->parent_ctx;
  699. drm_helper_hpd_irq_event(ctx->drm_dev);
  700. }
  701. static irqreturn_t hdmi_irq_handler(int irq, void *arg)
  702. {
  703. struct exynos_drm_hdmi_context *ctx = arg;
  704. struct hdmi_context *hdata = (struct hdmi_context *)ctx->ctx;
  705. u32 intc_flag;
  706. intc_flag = hdmi_reg_read(hdata, HDMI_INTC_FLAG);
  707. /* clearing flags for HPD plug/unplug */
  708. if (intc_flag & HDMI_INTC_FLAG_HPD_UNPLUG) {
  709. DRM_DEBUG_KMS("unplugged, handling:%d\n", hdata->hpd_handle);
  710. hdmi_reg_writemask(hdata, HDMI_INTC_FLAG, ~0,
  711. HDMI_INTC_FLAG_HPD_UNPLUG);
  712. }
  713. if (intc_flag & HDMI_INTC_FLAG_HPD_PLUG) {
  714. DRM_DEBUG_KMS("plugged, handling:%d\n", hdata->hpd_handle);
  715. hdmi_reg_writemask(hdata, HDMI_INTC_FLAG, ~0,
  716. HDMI_INTC_FLAG_HPD_PLUG);
  717. }
  718. if (ctx->drm_dev && hdata->hpd_handle)
  719. queue_work(hdata->wq, &hdata->hotplug_work);
  720. return IRQ_HANDLED;
  721. }
  722. static int __devinit hdmi_resources_init(struct hdmi_context *hdata)
  723. {
  724. struct device *dev = hdata->dev;
  725. struct hdmi_resources *res = &hdata->res;
  726. static char *supply[] = {
  727. "hdmi-en",
  728. "vdd",
  729. "vdd_osc",
  730. "vdd_pll",
  731. };
  732. int i, ret;
  733. DRM_DEBUG_KMS("HDMI resource init\n");
  734. memset(res, 0, sizeof *res);
  735. /* get clocks, power */
  736. res->hdmi = clk_get(dev, "hdmi");
  737. if (IS_ERR_OR_NULL(res->hdmi)) {
  738. DRM_ERROR("failed to get clock 'hdmi'\n");
  739. goto fail;
  740. }
  741. res->sclk_hdmi = clk_get(dev, "sclk_hdmi");
  742. if (IS_ERR_OR_NULL(res->sclk_hdmi)) {
  743. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  744. goto fail;
  745. }
  746. res->sclk_pixel = clk_get(dev, "sclk_pixel");
  747. if (IS_ERR_OR_NULL(res->sclk_pixel)) {
  748. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  749. goto fail;
  750. }
  751. res->sclk_hdmiphy = clk_get(dev, "sclk_hdmiphy");
  752. if (IS_ERR_OR_NULL(res->sclk_hdmiphy)) {
  753. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  754. goto fail;
  755. }
  756. res->hdmiphy = clk_get(dev, "hdmiphy");
  757. if (IS_ERR_OR_NULL(res->hdmiphy)) {
  758. DRM_ERROR("failed to get clock 'hdmiphy'\n");
  759. goto fail;
  760. }
  761. clk_set_parent(res->sclk_hdmi, res->sclk_pixel);
  762. res->regul_bulk = kzalloc(ARRAY_SIZE(supply) *
  763. sizeof res->regul_bulk[0], GFP_KERNEL);
  764. if (!res->regul_bulk) {
  765. DRM_ERROR("failed to get memory for regulators\n");
  766. goto fail;
  767. }
  768. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  769. res->regul_bulk[i].supply = supply[i];
  770. res->regul_bulk[i].consumer = NULL;
  771. }
  772. ret = regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  773. if (ret) {
  774. DRM_ERROR("failed to get regulators\n");
  775. goto fail;
  776. }
  777. res->regul_count = ARRAY_SIZE(supply);
  778. return 0;
  779. fail:
  780. DRM_ERROR("HDMI resource init - failed\n");
  781. return -ENODEV;
  782. }
  783. static int hdmi_resources_cleanup(struct hdmi_context *hdata)
  784. {
  785. struct hdmi_resources *res = &hdata->res;
  786. regulator_bulk_free(res->regul_count, res->regul_bulk);
  787. /* kfree is NULL-safe */
  788. kfree(res->regul_bulk);
  789. if (!IS_ERR_OR_NULL(res->hdmiphy))
  790. clk_put(res->hdmiphy);
  791. if (!IS_ERR_OR_NULL(res->sclk_hdmiphy))
  792. clk_put(res->sclk_hdmiphy);
  793. if (!IS_ERR_OR_NULL(res->sclk_pixel))
  794. clk_put(res->sclk_pixel);
  795. if (!IS_ERR_OR_NULL(res->sclk_hdmi))
  796. clk_put(res->sclk_hdmi);
  797. if (!IS_ERR_OR_NULL(res->hdmi))
  798. clk_put(res->hdmi);
  799. memset(res, 0, sizeof *res);
  800. return 0;
  801. }
  802. static void hdmi_resource_poweron(struct hdmi_context *hdata)
  803. {
  804. struct hdmi_resources *res = &hdata->res;
  805. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  806. /* turn HDMI power on */
  807. regulator_bulk_enable(res->regul_count, res->regul_bulk);
  808. /* power-on hdmi physical interface */
  809. clk_enable(res->hdmiphy);
  810. /* turn clocks on */
  811. clk_enable(res->hdmi);
  812. clk_enable(res->sclk_hdmi);
  813. hdmiphy_conf_reset(hdata);
  814. hdmi_conf_reset(hdata);
  815. hdmi_conf_init(hdata);
  816. }
  817. static void hdmi_resource_poweroff(struct hdmi_context *hdata)
  818. {
  819. struct hdmi_resources *res = &hdata->res;
  820. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  821. /* turn clocks off */
  822. clk_disable(res->sclk_hdmi);
  823. clk_disable(res->hdmi);
  824. /* power-off hdmiphy */
  825. clk_disable(res->hdmiphy);
  826. /* turn HDMI power off */
  827. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  828. }
  829. static int hdmi_runtime_suspend(struct device *dev)
  830. {
  831. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  832. DRM_DEBUG_KMS("%s\n", __func__);
  833. hdmi_resource_poweroff((struct hdmi_context *)ctx->ctx);
  834. return 0;
  835. }
  836. static int hdmi_runtime_resume(struct device *dev)
  837. {
  838. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  839. DRM_DEBUG_KMS("%s\n", __func__);
  840. hdmi_resource_poweron((struct hdmi_context *)ctx->ctx);
  841. return 0;
  842. }
  843. static const struct dev_pm_ops hdmi_pm_ops = {
  844. .runtime_suspend = hdmi_runtime_suspend,
  845. .runtime_resume = hdmi_runtime_resume,
  846. };
  847. static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
  848. void hdmi_attach_ddc_client(struct i2c_client *ddc)
  849. {
  850. if (ddc)
  851. hdmi_ddc = ddc;
  852. }
  853. EXPORT_SYMBOL(hdmi_attach_ddc_client);
  854. void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
  855. {
  856. if (hdmiphy)
  857. hdmi_hdmiphy = hdmiphy;
  858. }
  859. EXPORT_SYMBOL(hdmi_attach_hdmiphy_client);
  860. static int __devinit hdmi_probe(struct platform_device *pdev)
  861. {
  862. struct device *dev = &pdev->dev;
  863. struct exynos_drm_hdmi_context *drm_hdmi_ctx;
  864. struct hdmi_context *hdata;
  865. struct exynos_drm_hdmi_pdata *pdata;
  866. struct resource *res;
  867. int ret;
  868. DRM_DEBUG_KMS("[%d]\n", __LINE__);
  869. pdata = pdev->dev.platform_data;
  870. if (!pdata) {
  871. DRM_ERROR("no platform data specified\n");
  872. return -EINVAL;
  873. }
  874. drm_hdmi_ctx = kzalloc(sizeof(*drm_hdmi_ctx), GFP_KERNEL);
  875. if (!drm_hdmi_ctx) {
  876. DRM_ERROR("failed to allocate common hdmi context.\n");
  877. return -ENOMEM;
  878. }
  879. hdata = kzalloc(sizeof(struct hdmi_context), GFP_KERNEL);
  880. if (!hdata) {
  881. DRM_ERROR("out of memory\n");
  882. kfree(drm_hdmi_ctx);
  883. return -ENOMEM;
  884. }
  885. drm_hdmi_ctx->ctx = (void *)hdata;
  886. hdata->parent_ctx = (void *)drm_hdmi_ctx;
  887. platform_set_drvdata(pdev, drm_hdmi_ctx);
  888. hdata->default_win = pdata->default_win;
  889. hdata->default_timing = &pdata->timing;
  890. hdata->default_bpp = pdata->bpp;
  891. hdata->dev = dev;
  892. ret = hdmi_resources_init(hdata);
  893. if (ret) {
  894. ret = -EINVAL;
  895. goto err_data;
  896. }
  897. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  898. if (!res) {
  899. DRM_ERROR("failed to find registers\n");
  900. ret = -ENOENT;
  901. goto err_resource;
  902. }
  903. hdata->regs_res = request_mem_region(res->start, resource_size(res),
  904. dev_name(dev));
  905. if (!hdata->regs_res) {
  906. DRM_ERROR("failed to claim register region\n");
  907. ret = -ENOENT;
  908. goto err_resource;
  909. }
  910. hdata->regs = ioremap(res->start, resource_size(res));
  911. if (!hdata->regs) {
  912. DRM_ERROR("failed to map registers\n");
  913. ret = -ENXIO;
  914. goto err_req_region;
  915. }
  916. /* DDC i2c driver */
  917. if (i2c_add_driver(&ddc_driver)) {
  918. DRM_ERROR("failed to register ddc i2c driver\n");
  919. ret = -ENOENT;
  920. goto err_iomap;
  921. }
  922. hdata->ddc_port = hdmi_ddc;
  923. /* hdmiphy i2c driver */
  924. if (i2c_add_driver(&hdmiphy_driver)) {
  925. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  926. ret = -ENOENT;
  927. goto err_ddc;
  928. }
  929. hdata->hdmiphy_port = hdmi_hdmiphy;
  930. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  931. if (res == NULL) {
  932. DRM_ERROR("get interrupt resource failed.\n");
  933. ret = -ENXIO;
  934. goto err_hdmiphy;
  935. }
  936. /* create workqueue and hotplug work */
  937. hdata->wq = alloc_workqueue("exynos-drm-hdmi",
  938. WQ_UNBOUND | WQ_NON_REENTRANT, 1);
  939. if (hdata->wq == NULL) {
  940. DRM_ERROR("Failed to create workqueue.\n");
  941. ret = -ENOMEM;
  942. goto err_hdmiphy;
  943. }
  944. INIT_WORK(&hdata->hotplug_work, hdmi_hotplug_func);
  945. /* register hpd interrupt */
  946. ret = request_irq(res->start, hdmi_irq_handler, 0, "drm_hdmi",
  947. drm_hdmi_ctx);
  948. if (ret) {
  949. DRM_ERROR("request interrupt failed.\n");
  950. goto err_workqueue;
  951. }
  952. hdata->irq = res->start;
  953. /* register specific callbacks to common hdmi. */
  954. exynos_drm_display_ops_register(&display_ops);
  955. exynos_drm_manager_ops_register(&manager_ops);
  956. hdmi_resource_poweron(hdata);
  957. return 0;
  958. err_workqueue:
  959. destroy_workqueue(hdata->wq);
  960. err_hdmiphy:
  961. i2c_del_driver(&hdmiphy_driver);
  962. err_ddc:
  963. i2c_del_driver(&ddc_driver);
  964. err_iomap:
  965. iounmap(hdata->regs);
  966. err_req_region:
  967. release_mem_region(hdata->regs_res->start,
  968. resource_size(hdata->regs_res));
  969. err_resource:
  970. hdmi_resources_cleanup(hdata);
  971. err_data:
  972. kfree(hdata);
  973. kfree(drm_hdmi_ctx);
  974. return ret;
  975. }
  976. static int __devexit hdmi_remove(struct platform_device *pdev)
  977. {
  978. struct exynos_drm_hdmi_context *ctx = platform_get_drvdata(pdev);
  979. struct hdmi_context *hdata = (struct hdmi_context *)ctx->ctx;
  980. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  981. hdmi_resource_poweroff(hdata);
  982. disable_irq(hdata->irq);
  983. free_irq(hdata->irq, hdata);
  984. cancel_work_sync(&hdata->hotplug_work);
  985. destroy_workqueue(hdata->wq);
  986. hdmi_resources_cleanup(hdata);
  987. iounmap(hdata->regs);
  988. release_mem_region(hdata->regs_res->start,
  989. resource_size(hdata->regs_res));
  990. /* hdmiphy i2c driver */
  991. i2c_del_driver(&hdmiphy_driver);
  992. /* DDC i2c driver */
  993. i2c_del_driver(&ddc_driver);
  994. kfree(hdata);
  995. return 0;
  996. }
  997. struct platform_driver hdmi_driver = {
  998. .probe = hdmi_probe,
  999. .remove = __devexit_p(hdmi_remove),
  1000. .driver = {
  1001. .name = "exynos4-hdmi",
  1002. .owner = THIS_MODULE,
  1003. .pm = &hdmi_pm_ops,
  1004. },
  1005. };
  1006. EXPORT_SYMBOL(hdmi_driver);
  1007. MODULE_AUTHOR("Seung-Woo Kim, <sw0312.kim@samsung.com>");
  1008. MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
  1009. MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
  1010. MODULE_DESCRIPTION("Samsung DRM HDMI core Driver");
  1011. MODULE_LICENSE("GPL");