exynos_hdmi.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  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 <drm/drmP.h>
  17. #include <drm/drm_edid.h>
  18. #include <drm/drm_crtc_helper.h>
  19. #include <drm/drm_atomic_helper.h>
  20. #include "regs-hdmi.h"
  21. #include <linux/kernel.h>
  22. #include <linux/wait.h>
  23. #include <linux/i2c.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/clk.h>
  30. #include <linux/gpio/consumer.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/io.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_device.h>
  35. #include <linux/of_graph.h>
  36. #include <linux/hdmi.h>
  37. #include <linux/component.h>
  38. #include <linux/mfd/syscon.h>
  39. #include <linux/regmap.h>
  40. #include <drm/exynos_drm.h>
  41. #include "exynos_drm_drv.h"
  42. #include "exynos_drm_crtc.h"
  43. #define HOTPLUG_DEBOUNCE_MS 1100
  44. enum hdmi_type {
  45. HDMI_TYPE13,
  46. HDMI_TYPE14,
  47. HDMI_TYPE_COUNT
  48. };
  49. #define HDMI_MAPPED_BASE 0xffff0000
  50. enum hdmi_mapped_regs {
  51. HDMI_PHY_STATUS = HDMI_MAPPED_BASE,
  52. HDMI_PHY_RSTOUT,
  53. HDMI_ACR_CON,
  54. HDMI_ACR_MCTS0,
  55. HDMI_ACR_CTS0,
  56. HDMI_ACR_N0
  57. };
  58. static const u32 hdmi_reg_map[][HDMI_TYPE_COUNT] = {
  59. { HDMI_V13_PHY_STATUS, HDMI_PHY_STATUS_0 },
  60. { HDMI_V13_PHY_RSTOUT, HDMI_V14_PHY_RSTOUT },
  61. { HDMI_V13_ACR_CON, HDMI_V14_ACR_CON },
  62. { HDMI_V13_ACR_MCTS0, HDMI_V14_ACR_MCTS0 },
  63. { HDMI_V13_ACR_CTS0, HDMI_V14_ACR_CTS0 },
  64. { HDMI_V13_ACR_N0, HDMI_V14_ACR_N0 },
  65. };
  66. static const char * const supply[] = {
  67. "vdd",
  68. "vdd_osc",
  69. "vdd_pll",
  70. };
  71. struct hdmiphy_config {
  72. int pixel_clock;
  73. u8 conf[32];
  74. };
  75. struct hdmiphy_configs {
  76. int count;
  77. const struct hdmiphy_config *data;
  78. };
  79. struct string_array_spec {
  80. int count;
  81. const char * const *data;
  82. };
  83. #define INIT_ARRAY_SPEC(a) { .count = ARRAY_SIZE(a), .data = a }
  84. struct hdmi_driver_data {
  85. unsigned int type;
  86. unsigned int is_apb_phy:1;
  87. unsigned int has_sysreg:1;
  88. struct hdmiphy_configs phy_confs;
  89. struct string_array_spec clk_gates;
  90. /*
  91. * Array of triplets (p_off, p_on, clock), where p_off and p_on are
  92. * required parents of clock when HDMI-PHY is respectively off or on.
  93. */
  94. struct string_array_spec clk_muxes;
  95. };
  96. struct hdmi_context {
  97. struct drm_encoder encoder;
  98. struct device *dev;
  99. struct drm_device *drm_dev;
  100. struct drm_connector connector;
  101. bool powered;
  102. bool dvi_mode;
  103. struct delayed_work hotplug_work;
  104. struct drm_display_mode current_mode;
  105. const struct hdmi_driver_data *drv_data;
  106. void __iomem *regs;
  107. void __iomem *regs_hdmiphy;
  108. struct i2c_client *hdmiphy_port;
  109. struct i2c_adapter *ddc_adpt;
  110. struct gpio_desc *hpd_gpio;
  111. int irq;
  112. struct regmap *pmureg;
  113. struct regmap *sysreg;
  114. struct clk **clk_gates;
  115. struct clk **clk_muxes;
  116. struct regulator_bulk_data regul_bulk[ARRAY_SIZE(supply)];
  117. struct regulator *reg_hdmi_en;
  118. struct exynos_drm_clk phy_clk;
  119. struct drm_bridge *bridge;
  120. };
  121. static inline struct hdmi_context *encoder_to_hdmi(struct drm_encoder *e)
  122. {
  123. return container_of(e, struct hdmi_context, encoder);
  124. }
  125. static inline struct hdmi_context *connector_to_hdmi(struct drm_connector *c)
  126. {
  127. return container_of(c, struct hdmi_context, connector);
  128. }
  129. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  130. {
  131. .pixel_clock = 27000000,
  132. .conf = {
  133. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  134. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  135. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  136. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x80,
  137. },
  138. },
  139. {
  140. .pixel_clock = 27027000,
  141. .conf = {
  142. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  143. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  144. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  145. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x80,
  146. },
  147. },
  148. {
  149. .pixel_clock = 74176000,
  150. .conf = {
  151. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  152. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  153. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  154. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x80,
  155. },
  156. },
  157. {
  158. .pixel_clock = 74250000,
  159. .conf = {
  160. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  161. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  162. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  163. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x80,
  164. },
  165. },
  166. {
  167. .pixel_clock = 148500000,
  168. .conf = {
  169. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  170. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  171. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  172. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x80,
  173. },
  174. },
  175. };
  176. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  177. {
  178. .pixel_clock = 25200000,
  179. .conf = {
  180. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  181. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  182. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  183. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  184. },
  185. },
  186. {
  187. .pixel_clock = 27000000,
  188. .conf = {
  189. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  190. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  191. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  192. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  193. },
  194. },
  195. {
  196. .pixel_clock = 27027000,
  197. .conf = {
  198. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  199. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  200. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  201. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  202. },
  203. },
  204. {
  205. .pixel_clock = 36000000,
  206. .conf = {
  207. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  208. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  209. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  210. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  211. },
  212. },
  213. {
  214. .pixel_clock = 40000000,
  215. .conf = {
  216. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  217. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  218. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  219. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  220. },
  221. },
  222. {
  223. .pixel_clock = 65000000,
  224. .conf = {
  225. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  226. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  227. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  228. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  229. },
  230. },
  231. {
  232. .pixel_clock = 71000000,
  233. .conf = {
  234. 0x01, 0xd1, 0x3b, 0x35, 0x40, 0x0c, 0x04, 0x08,
  235. 0x85, 0xa0, 0x63, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  236. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  237. 0x54, 0xad, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  238. },
  239. },
  240. {
  241. .pixel_clock = 73250000,
  242. .conf = {
  243. 0x01, 0xd1, 0x3d, 0x35, 0x40, 0x18, 0x02, 0x08,
  244. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  245. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  246. 0x54, 0xa8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  247. },
  248. },
  249. {
  250. .pixel_clock = 74176000,
  251. .conf = {
  252. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  253. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  254. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  255. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  256. },
  257. },
  258. {
  259. .pixel_clock = 74250000,
  260. .conf = {
  261. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  262. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  263. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  264. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  265. },
  266. },
  267. {
  268. .pixel_clock = 83500000,
  269. .conf = {
  270. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  271. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  272. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  273. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  274. },
  275. },
  276. {
  277. .pixel_clock = 106500000,
  278. .conf = {
  279. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  280. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  281. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  282. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  283. },
  284. },
  285. {
  286. .pixel_clock = 108000000,
  287. .conf = {
  288. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  289. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  290. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  291. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  292. },
  293. },
  294. {
  295. .pixel_clock = 115500000,
  296. .conf = {
  297. 0x01, 0xd1, 0x30, 0x12, 0x40, 0x40, 0x10, 0x08,
  298. 0x80, 0x80, 0x21, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  299. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  300. 0x54, 0xaa, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  301. },
  302. },
  303. {
  304. .pixel_clock = 119000000,
  305. .conf = {
  306. 0x01, 0xd1, 0x32, 0x1a, 0x40, 0x30, 0xd8, 0x08,
  307. 0x04, 0xa0, 0x2a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  308. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  309. 0x54, 0x9d, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  310. },
  311. },
  312. {
  313. .pixel_clock = 146250000,
  314. .conf = {
  315. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  316. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  317. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  318. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  319. },
  320. },
  321. {
  322. .pixel_clock = 148500000,
  323. .conf = {
  324. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  325. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  326. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  327. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  328. },
  329. },
  330. };
  331. static const struct hdmiphy_config hdmiphy_5420_configs[] = {
  332. {
  333. .pixel_clock = 25200000,
  334. .conf = {
  335. 0x01, 0x52, 0x3F, 0x55, 0x40, 0x01, 0x00, 0xC8,
  336. 0x82, 0xC8, 0xBD, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  337. 0x06, 0x80, 0x01, 0x84, 0x05, 0x02, 0x24, 0x66,
  338. 0x54, 0xF4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  339. },
  340. },
  341. {
  342. .pixel_clock = 27000000,
  343. .conf = {
  344. 0x01, 0xD1, 0x22, 0x51, 0x40, 0x08, 0xFC, 0xE0,
  345. 0x98, 0xE8, 0xCB, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  346. 0x06, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  347. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  348. },
  349. },
  350. {
  351. .pixel_clock = 27027000,
  352. .conf = {
  353. 0x01, 0xD1, 0x2D, 0x72, 0x40, 0x64, 0x12, 0xC8,
  354. 0x43, 0xE8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  355. 0x26, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  356. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  357. },
  358. },
  359. {
  360. .pixel_clock = 36000000,
  361. .conf = {
  362. 0x01, 0x51, 0x2D, 0x55, 0x40, 0x40, 0x00, 0xC8,
  363. 0x02, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  364. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  365. 0x54, 0xAB, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  366. },
  367. },
  368. {
  369. .pixel_clock = 40000000,
  370. .conf = {
  371. 0x01, 0xD1, 0x21, 0x31, 0x40, 0x3C, 0x28, 0xC8,
  372. 0x87, 0xE8, 0xC8, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  373. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  374. 0x54, 0x9A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  375. },
  376. },
  377. {
  378. .pixel_clock = 65000000,
  379. .conf = {
  380. 0x01, 0xD1, 0x36, 0x34, 0x40, 0x0C, 0x04, 0xC8,
  381. 0x82, 0xE8, 0x45, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  382. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  383. 0x54, 0xBD, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  384. },
  385. },
  386. {
  387. .pixel_clock = 71000000,
  388. .conf = {
  389. 0x01, 0xD1, 0x3B, 0x35, 0x40, 0x0C, 0x04, 0xC8,
  390. 0x85, 0xE8, 0x63, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  391. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  392. 0x54, 0x57, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  393. },
  394. },
  395. {
  396. .pixel_clock = 73250000,
  397. .conf = {
  398. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x78, 0x8D, 0xC8,
  399. 0x81, 0xE8, 0xB7, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  400. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  401. 0x54, 0xA8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  402. },
  403. },
  404. {
  405. .pixel_clock = 74176000,
  406. .conf = {
  407. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0xC8,
  408. 0x81, 0xE8, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  409. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  410. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  411. },
  412. },
  413. {
  414. .pixel_clock = 74250000,
  415. .conf = {
  416. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  417. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  418. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  419. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  420. },
  421. },
  422. {
  423. .pixel_clock = 83500000,
  424. .conf = {
  425. 0x01, 0xD1, 0x23, 0x11, 0x40, 0x0C, 0xFB, 0xC8,
  426. 0x85, 0xE8, 0xD1, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  427. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  428. 0x54, 0x4A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  429. },
  430. },
  431. {
  432. .pixel_clock = 88750000,
  433. .conf = {
  434. 0x01, 0xD1, 0x25, 0x11, 0x40, 0x18, 0xFF, 0xC8,
  435. 0x83, 0xE8, 0xDE, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  436. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  437. 0x54, 0x45, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  438. },
  439. },
  440. {
  441. .pixel_clock = 106500000,
  442. .conf = {
  443. 0x01, 0xD1, 0x2C, 0x12, 0x40, 0x0C, 0x09, 0xC8,
  444. 0x84, 0xE8, 0x0A, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  445. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  446. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  447. },
  448. },
  449. {
  450. .pixel_clock = 108000000,
  451. .conf = {
  452. 0x01, 0x51, 0x2D, 0x15, 0x40, 0x01, 0x00, 0xC8,
  453. 0x82, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  454. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  455. 0x54, 0xC7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  456. },
  457. },
  458. {
  459. .pixel_clock = 115500000,
  460. .conf = {
  461. 0x01, 0xD1, 0x30, 0x14, 0x40, 0x0C, 0x03, 0xC8,
  462. 0x88, 0xE8, 0x21, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  463. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  464. 0x54, 0x6A, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  465. },
  466. },
  467. {
  468. .pixel_clock = 146250000,
  469. .conf = {
  470. 0x01, 0xD1, 0x3D, 0x15, 0x40, 0x18, 0xFD, 0xC8,
  471. 0x83, 0xE8, 0x6E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  472. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  473. 0x54, 0x54, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  474. },
  475. },
  476. {
  477. .pixel_clock = 148500000,
  478. .conf = {
  479. 0x01, 0xD1, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  480. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  481. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  482. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x80, 0x01, 0x80,
  483. },
  484. },
  485. };
  486. static const struct hdmiphy_config hdmiphy_5433_configs[] = {
  487. {
  488. .pixel_clock = 27000000,
  489. .conf = {
  490. 0x01, 0x51, 0x2d, 0x75, 0x01, 0x00, 0x88, 0x02,
  491. 0x72, 0x50, 0x44, 0x8c, 0x27, 0x00, 0x7c, 0xac,
  492. 0xd6, 0x2b, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  493. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  494. },
  495. },
  496. {
  497. .pixel_clock = 27027000,
  498. .conf = {
  499. 0x01, 0x51, 0x2d, 0x72, 0x64, 0x09, 0x88, 0xc3,
  500. 0x71, 0x50, 0x44, 0x8c, 0x27, 0x00, 0x7c, 0xac,
  501. 0xd6, 0x2b, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  502. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  503. },
  504. },
  505. {
  506. .pixel_clock = 40000000,
  507. .conf = {
  508. 0x01, 0x51, 0x32, 0x55, 0x01, 0x00, 0x88, 0x02,
  509. 0x4d, 0x50, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  510. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  511. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  512. },
  513. },
  514. {
  515. .pixel_clock = 50000000,
  516. .conf = {
  517. 0x01, 0x51, 0x34, 0x40, 0x64, 0x09, 0x88, 0xc3,
  518. 0x3d, 0x50, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  519. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  520. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  521. },
  522. },
  523. {
  524. .pixel_clock = 65000000,
  525. .conf = {
  526. 0x01, 0x51, 0x36, 0x31, 0x40, 0x10, 0x04, 0xc6,
  527. 0x2e, 0xe8, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  528. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  529. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  530. },
  531. },
  532. {
  533. .pixel_clock = 74176000,
  534. .conf = {
  535. 0x01, 0x51, 0x3E, 0x35, 0x5B, 0xDE, 0x88, 0x42,
  536. 0x53, 0x51, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  537. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  538. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  539. },
  540. },
  541. {
  542. .pixel_clock = 74250000,
  543. .conf = {
  544. 0x01, 0x51, 0x3E, 0x35, 0x40, 0xF0, 0x88, 0xC2,
  545. 0x52, 0x51, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  546. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  547. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  548. },
  549. },
  550. {
  551. .pixel_clock = 108000000,
  552. .conf = {
  553. 0x01, 0x51, 0x2d, 0x15, 0x01, 0x00, 0x88, 0x02,
  554. 0x72, 0x52, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  555. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  556. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  557. },
  558. },
  559. {
  560. .pixel_clock = 148500000,
  561. .conf = {
  562. 0x01, 0x51, 0x1f, 0x00, 0x40, 0xf8, 0x88, 0xc1,
  563. 0x52, 0x52, 0x24, 0x0c, 0x24, 0x0f, 0x7c, 0xa5,
  564. 0xd4, 0x2b, 0x87, 0x00, 0x00, 0x04, 0x00, 0x30,
  565. 0x08, 0x10, 0x01, 0x01, 0x48, 0x4a, 0x00, 0x40,
  566. },
  567. },
  568. {
  569. .pixel_clock = 297000000,
  570. .conf = {
  571. 0x01, 0x51, 0x3E, 0x05, 0x40, 0xF0, 0x88, 0xC2,
  572. 0x52, 0x53, 0x44, 0x8C, 0x27, 0x00, 0x7C, 0xAC,
  573. 0xD6, 0x2B, 0x67, 0x00, 0x00, 0x04, 0x00, 0x30,
  574. 0x08, 0x10, 0x01, 0x01, 0x48, 0x40, 0x00, 0x40,
  575. },
  576. },
  577. };
  578. static const char * const hdmi_clk_gates4[] = {
  579. "hdmi", "sclk_hdmi"
  580. };
  581. static const char * const hdmi_clk_muxes4[] = {
  582. "sclk_pixel", "sclk_hdmiphy", "mout_hdmi"
  583. };
  584. static const char * const hdmi_clk_gates5433[] = {
  585. "hdmi_pclk", "hdmi_i_pclk", "i_tmds_clk", "i_pixel_clk", "i_spdif_clk"
  586. };
  587. static const char * const hdmi_clk_muxes5433[] = {
  588. "oscclk", "tmds_clko", "tmds_clko_user",
  589. "oscclk", "pixel_clko", "pixel_clko_user"
  590. };
  591. static const struct hdmi_driver_data exynos4210_hdmi_driver_data = {
  592. .type = HDMI_TYPE13,
  593. .phy_confs = INIT_ARRAY_SPEC(hdmiphy_v13_configs),
  594. .clk_gates = INIT_ARRAY_SPEC(hdmi_clk_gates4),
  595. .clk_muxes = INIT_ARRAY_SPEC(hdmi_clk_muxes4),
  596. };
  597. static const struct hdmi_driver_data exynos4212_hdmi_driver_data = {
  598. .type = HDMI_TYPE14,
  599. .phy_confs = INIT_ARRAY_SPEC(hdmiphy_v14_configs),
  600. .clk_gates = INIT_ARRAY_SPEC(hdmi_clk_gates4),
  601. .clk_muxes = INIT_ARRAY_SPEC(hdmi_clk_muxes4),
  602. };
  603. static const struct hdmi_driver_data exynos5420_hdmi_driver_data = {
  604. .type = HDMI_TYPE14,
  605. .is_apb_phy = 1,
  606. .phy_confs = INIT_ARRAY_SPEC(hdmiphy_5420_configs),
  607. .clk_gates = INIT_ARRAY_SPEC(hdmi_clk_gates4),
  608. .clk_muxes = INIT_ARRAY_SPEC(hdmi_clk_muxes4),
  609. };
  610. static const struct hdmi_driver_data exynos5433_hdmi_driver_data = {
  611. .type = HDMI_TYPE14,
  612. .is_apb_phy = 1,
  613. .has_sysreg = 1,
  614. .phy_confs = INIT_ARRAY_SPEC(hdmiphy_5433_configs),
  615. .clk_gates = INIT_ARRAY_SPEC(hdmi_clk_gates5433),
  616. .clk_muxes = INIT_ARRAY_SPEC(hdmi_clk_muxes5433),
  617. };
  618. static inline u32 hdmi_map_reg(struct hdmi_context *hdata, u32 reg_id)
  619. {
  620. if ((reg_id & 0xffff0000) == HDMI_MAPPED_BASE)
  621. return hdmi_reg_map[reg_id & 0xffff][hdata->drv_data->type];
  622. return reg_id;
  623. }
  624. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  625. {
  626. return readl(hdata->regs + hdmi_map_reg(hdata, reg_id));
  627. }
  628. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  629. u32 reg_id, u8 value)
  630. {
  631. writel(value, hdata->regs + hdmi_map_reg(hdata, reg_id));
  632. }
  633. static inline void hdmi_reg_writev(struct hdmi_context *hdata, u32 reg_id,
  634. int bytes, u32 val)
  635. {
  636. reg_id = hdmi_map_reg(hdata, reg_id);
  637. while (--bytes >= 0) {
  638. writel(val & 0xff, hdata->regs + reg_id);
  639. val >>= 8;
  640. reg_id += 4;
  641. }
  642. }
  643. static inline void hdmi_reg_write_buf(struct hdmi_context *hdata, u32 reg_id,
  644. u8 *buf, int size)
  645. {
  646. for (reg_id = hdmi_map_reg(hdata, reg_id); size; --size, reg_id += 4)
  647. writel(*buf++, hdata->regs + reg_id);
  648. }
  649. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  650. u32 reg_id, u32 value, u32 mask)
  651. {
  652. u32 old;
  653. reg_id = hdmi_map_reg(hdata, reg_id);
  654. old = readl(hdata->regs + reg_id);
  655. value = (value & mask) | (old & ~mask);
  656. writel(value, hdata->regs + reg_id);
  657. }
  658. static int hdmiphy_reg_write_buf(struct hdmi_context *hdata,
  659. u32 reg_offset, const u8 *buf, u32 len)
  660. {
  661. if ((reg_offset + len) > 32)
  662. return -EINVAL;
  663. if (hdata->hdmiphy_port) {
  664. int ret;
  665. ret = i2c_master_send(hdata->hdmiphy_port, buf, len);
  666. if (ret == len)
  667. return 0;
  668. return ret;
  669. } else {
  670. int i;
  671. for (i = 0; i < len; i++)
  672. writel(buf[i], hdata->regs_hdmiphy +
  673. ((reg_offset + i)<<2));
  674. return 0;
  675. }
  676. }
  677. static int hdmi_clk_enable_gates(struct hdmi_context *hdata)
  678. {
  679. int i, ret;
  680. for (i = 0; i < hdata->drv_data->clk_gates.count; ++i) {
  681. ret = clk_prepare_enable(hdata->clk_gates[i]);
  682. if (!ret)
  683. continue;
  684. dev_err(hdata->dev, "Cannot enable clock '%s', %d\n",
  685. hdata->drv_data->clk_gates.data[i], ret);
  686. while (i--)
  687. clk_disable_unprepare(hdata->clk_gates[i]);
  688. return ret;
  689. }
  690. return 0;
  691. }
  692. static void hdmi_clk_disable_gates(struct hdmi_context *hdata)
  693. {
  694. int i = hdata->drv_data->clk_gates.count;
  695. while (i--)
  696. clk_disable_unprepare(hdata->clk_gates[i]);
  697. }
  698. static int hdmi_clk_set_parents(struct hdmi_context *hdata, bool to_phy)
  699. {
  700. struct device *dev = hdata->dev;
  701. int ret = 0;
  702. int i;
  703. for (i = 0; i < hdata->drv_data->clk_muxes.count; i += 3) {
  704. struct clk **c = &hdata->clk_muxes[i];
  705. ret = clk_set_parent(c[2], c[to_phy]);
  706. if (!ret)
  707. continue;
  708. dev_err(dev, "Cannot set clock parent of '%s' to '%s', %d\n",
  709. hdata->drv_data->clk_muxes.data[i + 2],
  710. hdata->drv_data->clk_muxes.data[i + to_phy], ret);
  711. }
  712. return ret;
  713. }
  714. static void hdmi_reg_infoframes(struct hdmi_context *hdata)
  715. {
  716. union hdmi_infoframe frm;
  717. u8 buf[25];
  718. int ret;
  719. if (hdata->dvi_mode) {
  720. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  721. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  722. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  723. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  724. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  725. return;
  726. }
  727. ret = drm_hdmi_avi_infoframe_from_display_mode(&frm.avi,
  728. &hdata->current_mode);
  729. if (!ret)
  730. ret = hdmi_avi_infoframe_pack(&frm.avi, buf, sizeof(buf));
  731. if (ret > 0) {
  732. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  733. hdmi_reg_write_buf(hdata, HDMI_AVI_HEADER0, buf, ret);
  734. } else {
  735. DRM_INFO("%s: invalid AVI infoframe (%d)\n", __func__, ret);
  736. }
  737. ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
  738. &hdata->current_mode);
  739. if (!ret)
  740. ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
  741. sizeof(buf));
  742. if (ret > 0) {
  743. hdmi_reg_writeb(hdata, HDMI_VSI_CON, HDMI_VSI_CON_EVERY_VSYNC);
  744. hdmi_reg_write_buf(hdata, HDMI_VSI_HEADER0, buf, 3);
  745. hdmi_reg_write_buf(hdata, HDMI_VSI_DATA(0), buf + 3, ret - 3);
  746. }
  747. ret = hdmi_audio_infoframe_init(&frm.audio);
  748. if (!ret) {
  749. frm.audio.channels = 2;
  750. ret = hdmi_audio_infoframe_pack(&frm.audio, buf, sizeof(buf));
  751. }
  752. if (ret > 0) {
  753. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_EVERY_VSYNC);
  754. hdmi_reg_write_buf(hdata, HDMI_AUI_HEADER0, buf, ret);
  755. }
  756. }
  757. static enum drm_connector_status hdmi_detect(struct drm_connector *connector,
  758. bool force)
  759. {
  760. struct hdmi_context *hdata = connector_to_hdmi(connector);
  761. if (gpiod_get_value(hdata->hpd_gpio))
  762. return connector_status_connected;
  763. return connector_status_disconnected;
  764. }
  765. static void hdmi_connector_destroy(struct drm_connector *connector)
  766. {
  767. drm_connector_unregister(connector);
  768. drm_connector_cleanup(connector);
  769. }
  770. static const struct drm_connector_funcs hdmi_connector_funcs = {
  771. .dpms = drm_atomic_helper_connector_dpms,
  772. .fill_modes = drm_helper_probe_single_connector_modes,
  773. .detect = hdmi_detect,
  774. .destroy = hdmi_connector_destroy,
  775. .reset = drm_atomic_helper_connector_reset,
  776. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  777. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  778. };
  779. static int hdmi_get_modes(struct drm_connector *connector)
  780. {
  781. struct hdmi_context *hdata = connector_to_hdmi(connector);
  782. struct edid *edid;
  783. int ret;
  784. if (!hdata->ddc_adpt)
  785. return -ENODEV;
  786. edid = drm_get_edid(connector, hdata->ddc_adpt);
  787. if (!edid)
  788. return -ENODEV;
  789. hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
  790. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  791. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  792. edid->width_cm, edid->height_cm);
  793. drm_mode_connector_update_edid_property(connector, edid);
  794. ret = drm_add_edid_modes(connector, edid);
  795. kfree(edid);
  796. return ret;
  797. }
  798. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  799. {
  800. const struct hdmiphy_configs *confs = &hdata->drv_data->phy_confs;
  801. int i;
  802. for (i = 0; i < confs->count; i++)
  803. if (confs->data[i].pixel_clock == pixel_clock)
  804. return i;
  805. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  806. return -EINVAL;
  807. }
  808. static int hdmi_mode_valid(struct drm_connector *connector,
  809. struct drm_display_mode *mode)
  810. {
  811. struct hdmi_context *hdata = connector_to_hdmi(connector);
  812. int ret;
  813. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  814. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  815. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  816. false, mode->clock * 1000);
  817. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  818. if (ret < 0)
  819. return MODE_BAD;
  820. return MODE_OK;
  821. }
  822. static const struct drm_connector_helper_funcs hdmi_connector_helper_funcs = {
  823. .get_modes = hdmi_get_modes,
  824. .mode_valid = hdmi_mode_valid,
  825. };
  826. static int hdmi_create_connector(struct drm_encoder *encoder)
  827. {
  828. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  829. struct drm_connector *connector = &hdata->connector;
  830. int ret;
  831. connector->interlace_allowed = true;
  832. connector->polled = DRM_CONNECTOR_POLL_HPD;
  833. ret = drm_connector_init(hdata->drm_dev, connector,
  834. &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
  835. if (ret) {
  836. DRM_ERROR("Failed to initialize connector with drm\n");
  837. return ret;
  838. }
  839. drm_connector_helper_add(connector, &hdmi_connector_helper_funcs);
  840. drm_connector_register(connector);
  841. drm_mode_connector_attach_encoder(connector, encoder);
  842. if (hdata->bridge) {
  843. encoder->bridge = hdata->bridge;
  844. hdata->bridge->encoder = encoder;
  845. ret = drm_bridge_attach(encoder, hdata->bridge, NULL);
  846. if (ret)
  847. DRM_ERROR("Failed to attach bridge\n");
  848. }
  849. return ret;
  850. }
  851. static bool hdmi_mode_fixup(struct drm_encoder *encoder,
  852. const struct drm_display_mode *mode,
  853. struct drm_display_mode *adjusted_mode)
  854. {
  855. struct drm_device *dev = encoder->dev;
  856. struct drm_connector *connector;
  857. struct drm_display_mode *m;
  858. int mode_ok;
  859. drm_mode_set_crtcinfo(adjusted_mode, 0);
  860. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  861. if (connector->encoder == encoder)
  862. break;
  863. }
  864. if (connector->encoder != encoder)
  865. return true;
  866. mode_ok = hdmi_mode_valid(connector, adjusted_mode);
  867. if (mode_ok == MODE_OK)
  868. return true;
  869. /*
  870. * Find the most suitable mode and copy it to adjusted_mode.
  871. */
  872. list_for_each_entry(m, &connector->modes, head) {
  873. mode_ok = hdmi_mode_valid(connector, m);
  874. if (mode_ok == MODE_OK) {
  875. DRM_INFO("desired mode doesn't exist so\n");
  876. DRM_INFO("use the most suitable mode among modes.\n");
  877. DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
  878. m->hdisplay, m->vdisplay, m->vrefresh);
  879. drm_mode_copy(adjusted_mode, m);
  880. break;
  881. }
  882. }
  883. return true;
  884. }
  885. static void hdmi_reg_acr(struct hdmi_context *hdata, u32 freq)
  886. {
  887. u32 n, cts;
  888. cts = (freq % 9) ? 27000 : 30000;
  889. n = 128 * freq / (27000000 / cts);
  890. hdmi_reg_writev(hdata, HDMI_ACR_N0, 3, n);
  891. hdmi_reg_writev(hdata, HDMI_ACR_MCTS0, 3, cts);
  892. hdmi_reg_writev(hdata, HDMI_ACR_CTS0, 3, cts);
  893. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  894. }
  895. static void hdmi_audio_init(struct hdmi_context *hdata)
  896. {
  897. u32 sample_rate, bits_per_sample;
  898. u32 data_num, bit_ch, sample_frq;
  899. u32 val;
  900. sample_rate = 44100;
  901. bits_per_sample = 16;
  902. switch (bits_per_sample) {
  903. case 20:
  904. data_num = 2;
  905. bit_ch = 1;
  906. break;
  907. case 24:
  908. data_num = 3;
  909. bit_ch = 1;
  910. break;
  911. default:
  912. data_num = 1;
  913. bit_ch = 0;
  914. break;
  915. }
  916. hdmi_reg_acr(hdata, sample_rate);
  917. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  918. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  919. | HDMI_I2S_MUX_ENABLE);
  920. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  921. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  922. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  923. sample_frq = (sample_rate == 44100) ? 0 :
  924. (sample_rate == 48000) ? 2 :
  925. (sample_rate == 32000) ? 3 :
  926. (sample_rate == 96000) ? 0xa : 0x0;
  927. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  928. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  929. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  930. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  931. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  932. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  933. | HDMI_I2S_SEL_LRCK(6));
  934. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  935. | HDMI_I2S_SEL_SDATA2(4));
  936. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  937. | HDMI_I2S_SEL_SDATA2(2));
  938. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  939. /* I2S_CON_1 & 2 */
  940. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  941. | HDMI_I2S_L_CH_LOW_POL);
  942. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  943. | HDMI_I2S_SET_BIT_CH(bit_ch)
  944. | HDMI_I2S_SET_SDATA_BIT(data_num)
  945. | HDMI_I2S_BASIC_FORMAT);
  946. /* Configure register related to CUV information */
  947. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  948. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  949. | HDMI_I2S_COPYRIGHT
  950. | HDMI_I2S_LINEAR_PCM
  951. | HDMI_I2S_CONSUMER_FORMAT);
  952. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  953. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  954. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  955. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  956. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  957. HDMI_I2S_ORG_SMP_FREQ_44_1
  958. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  959. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  960. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  961. }
  962. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  963. {
  964. if (hdata->dvi_mode)
  965. return;
  966. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  967. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  968. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  969. }
  970. static void hdmi_start(struct hdmi_context *hdata, bool start)
  971. {
  972. u32 val = start ? HDMI_TG_EN : 0;
  973. if (hdata->current_mode.flags & DRM_MODE_FLAG_INTERLACE)
  974. val |= HDMI_FIELD_EN;
  975. hdmi_reg_writemask(hdata, HDMI_CON_0, val, HDMI_EN);
  976. hdmi_reg_writemask(hdata, HDMI_TG_CMD, val, HDMI_TG_EN | HDMI_FIELD_EN);
  977. }
  978. static void hdmi_conf_init(struct hdmi_context *hdata)
  979. {
  980. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  981. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  982. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  983. /* choose HDMI mode */
  984. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  985. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  986. /* apply video pre-amble and guard band in HDMI mode only */
  987. hdmi_reg_writeb(hdata, HDMI_CON_2, 0);
  988. /* disable bluescreen */
  989. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  990. if (hdata->dvi_mode) {
  991. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  992. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  993. hdmi_reg_writeb(hdata, HDMI_CON_2,
  994. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  995. }
  996. if (hdata->drv_data->type == HDMI_TYPE13) {
  997. /* choose bluescreen (fecal) color */
  998. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  999. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1000. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1001. /* enable AVI packet every vsync, fixes purple line problem */
  1002. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1003. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1004. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1005. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1006. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1007. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1008. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1009. } else {
  1010. hdmi_reg_infoframes(hdata);
  1011. /* enable AVI packet every vsync, fixes purple line problem */
  1012. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1013. }
  1014. }
  1015. static void hdmiphy_wait_for_pll(struct hdmi_context *hdata)
  1016. {
  1017. int tries;
  1018. for (tries = 0; tries < 10; ++tries) {
  1019. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS);
  1020. if (val & HDMI_PHY_STATUS_READY) {
  1021. DRM_DEBUG_KMS("PLL stabilized after %d tries\n", tries);
  1022. return;
  1023. }
  1024. usleep_range(10, 20);
  1025. }
  1026. DRM_ERROR("PLL could not reach steady state\n");
  1027. }
  1028. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  1029. {
  1030. struct drm_display_mode *m = &hdata->current_mode;
  1031. unsigned int val;
  1032. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1033. hdmi_reg_writev(hdata, HDMI_V13_H_V_LINE_0, 3,
  1034. (m->htotal << 12) | m->vtotal);
  1035. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1036. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1, val);
  1037. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1038. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1, val);
  1039. val = (m->hsync_start - m->hdisplay - 2);
  1040. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1041. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1042. hdmi_reg_writev(hdata, HDMI_V13_H_SYNC_GEN_0, 3, val);
  1043. /*
  1044. * Quirk requirement for exynos HDMI IP design,
  1045. * 2 pixels less than the actual calculation for hsync_start
  1046. * and end.
  1047. */
  1048. /* Following values & calculations differ for different type of modes */
  1049. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1050. val = ((m->vsync_end - m->vdisplay) / 2);
  1051. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1052. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1053. val = m->vtotal / 2;
  1054. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1055. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1056. val = (m->vtotal +
  1057. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1058. val |= m->vtotal << 11;
  1059. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, val);
  1060. val = ((m->vtotal / 2) + 7);
  1061. val |= ((m->vtotal / 2) + 2) << 12;
  1062. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, val);
  1063. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1064. val |= ((m->htotal / 2) +
  1065. (m->hsync_start - m->hdisplay)) << 12;
  1066. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, val);
  1067. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1068. (m->vtotal - m->vdisplay) / 2);
  1069. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1070. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x249);
  1071. } else {
  1072. val = m->vtotal;
  1073. val |= (m->vtotal - m->vdisplay) << 11;
  1074. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1075. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, 0);
  1076. val = (m->vsync_end - m->vdisplay);
  1077. val |= ((m->vsync_start - m->vdisplay) << 12);
  1078. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1079. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, 0x1001);
  1080. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, 0x1001);
  1081. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1082. m->vtotal - m->vdisplay);
  1083. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1084. }
  1085. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1086. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1087. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1088. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1089. }
  1090. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1091. {
  1092. struct drm_display_mode *m = &hdata->current_mode;
  1093. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1094. hdmi_reg_writev(hdata, HDMI_V_LINE_0, 2, m->vtotal);
  1095. hdmi_reg_writev(hdata, HDMI_H_LINE_0, 2, m->htotal);
  1096. hdmi_reg_writev(hdata, HDMI_HSYNC_POL, 1,
  1097. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1098. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1,
  1099. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1100. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1,
  1101. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1102. /*
  1103. * Quirk requirement for exynos 5 HDMI IP design,
  1104. * 2 pixels less than the actual calculation for hsync_start
  1105. * and end.
  1106. */
  1107. /* Following values & calculations differ for different type of modes */
  1108. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1109. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1110. (m->vsync_end - m->vdisplay) / 2);
  1111. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1112. (m->vsync_start - m->vdisplay) / 2);
  1113. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal / 2);
  1114. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1115. (m->vtotal - m->vdisplay) / 2);
  1116. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2,
  1117. m->vtotal - m->vdisplay / 2);
  1118. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, m->vtotal);
  1119. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2,
  1120. (m->vtotal / 2) + 7);
  1121. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2,
  1122. (m->vtotal / 2) + 2);
  1123. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2,
  1124. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1125. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2,
  1126. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1127. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1128. (m->vtotal - m->vdisplay) / 2);
  1129. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1130. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2,
  1131. m->vtotal - m->vdisplay / 2);
  1132. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2,
  1133. (m->vtotal / 2) + 1);
  1134. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2,
  1135. (m->vtotal / 2) + 1);
  1136. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2,
  1137. (m->vtotal / 2) + 1);
  1138. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST3_L, 2, 0x0);
  1139. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST4_L, 2, 0x0);
  1140. } else {
  1141. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1142. m->vsync_end - m->vdisplay);
  1143. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1144. m->vsync_start - m->vdisplay);
  1145. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal);
  1146. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1147. m->vtotal - m->vdisplay);
  1148. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2, 0xffff);
  1149. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, 0xffff);
  1150. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2, 0xffff);
  1151. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2, 0xffff);
  1152. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2, 0xffff);
  1153. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2, 0xffff);
  1154. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1155. m->vtotal - m->vdisplay);
  1156. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1157. }
  1158. hdmi_reg_writev(hdata, HDMI_H_SYNC_START_0, 2,
  1159. m->hsync_start - m->hdisplay - 2);
  1160. hdmi_reg_writev(hdata, HDMI_H_SYNC_END_0, 2,
  1161. m->hsync_end - m->hdisplay - 2);
  1162. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_1_0, 2, 0xffff);
  1163. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_2_0, 2, 0xffff);
  1164. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_3_0, 2, 0xffff);
  1165. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_4_0, 2, 0xffff);
  1166. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_5_0, 2, 0xffff);
  1167. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_6_0, 2, 0xffff);
  1168. hdmi_reg_writev(hdata, HDMI_V_BLANK_F2_0, 2, 0xffff);
  1169. hdmi_reg_writev(hdata, HDMI_V_BLANK_F3_0, 2, 0xffff);
  1170. hdmi_reg_writev(hdata, HDMI_V_BLANK_F4_0, 2, 0xffff);
  1171. hdmi_reg_writev(hdata, HDMI_V_BLANK_F5_0, 2, 0xffff);
  1172. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_3_0, 2, 0xffff);
  1173. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_4_0, 2, 0xffff);
  1174. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_5_0, 2, 0xffff);
  1175. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_6_0, 2, 0xffff);
  1176. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0, 2, 0xffff);
  1177. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0, 2, 0xffff);
  1178. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0, 2, 0xffff);
  1179. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0, 2, 0xffff);
  1180. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1181. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1182. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1183. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1184. if (hdata->drv_data == &exynos5433_hdmi_driver_data)
  1185. hdmi_reg_writeb(hdata, HDMI_TG_DECON_EN, 1);
  1186. }
  1187. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1188. {
  1189. if (hdata->drv_data->type == HDMI_TYPE13)
  1190. hdmi_v13_mode_apply(hdata);
  1191. else
  1192. hdmi_v14_mode_apply(hdata);
  1193. hdmi_start(hdata, true);
  1194. }
  1195. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1196. {
  1197. hdmi_reg_writemask(hdata, HDMI_CORE_RSTOUT, 0, 1);
  1198. usleep_range(10000, 12000);
  1199. hdmi_reg_writemask(hdata, HDMI_CORE_RSTOUT, ~0, 1);
  1200. usleep_range(10000, 12000);
  1201. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, ~0, HDMI_PHY_SW_RSTOUT);
  1202. usleep_range(10000, 12000);
  1203. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, 0, HDMI_PHY_SW_RSTOUT);
  1204. usleep_range(10000, 12000);
  1205. }
  1206. static void hdmiphy_enable_mode_set(struct hdmi_context *hdata, bool enable)
  1207. {
  1208. u8 v = enable ? HDMI_PHY_ENABLE_MODE_SET : HDMI_PHY_DISABLE_MODE_SET;
  1209. if (hdata->drv_data == &exynos5433_hdmi_driver_data)
  1210. writel(v, hdata->regs_hdmiphy + HDMIPHY5433_MODE_SET_DONE);
  1211. }
  1212. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1213. {
  1214. int ret;
  1215. const u8 *phy_conf;
  1216. ret = hdmi_find_phy_conf(hdata, hdata->current_mode.clock * 1000);
  1217. if (ret < 0) {
  1218. DRM_ERROR("failed to find hdmiphy conf\n");
  1219. return;
  1220. }
  1221. phy_conf = hdata->drv_data->phy_confs.data[ret].conf;
  1222. hdmi_clk_set_parents(hdata, false);
  1223. hdmiphy_conf_reset(hdata);
  1224. hdmiphy_enable_mode_set(hdata, true);
  1225. ret = hdmiphy_reg_write_buf(hdata, 0, phy_conf, 32);
  1226. if (ret) {
  1227. DRM_ERROR("failed to configure hdmiphy\n");
  1228. return;
  1229. }
  1230. hdmiphy_enable_mode_set(hdata, false);
  1231. hdmi_clk_set_parents(hdata, true);
  1232. usleep_range(10000, 12000);
  1233. hdmiphy_wait_for_pll(hdata);
  1234. }
  1235. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1236. {
  1237. hdmi_start(hdata, false);
  1238. hdmi_conf_init(hdata);
  1239. hdmi_audio_init(hdata);
  1240. hdmi_mode_apply(hdata);
  1241. hdmi_audio_control(hdata, true);
  1242. }
  1243. static void hdmi_mode_set(struct drm_encoder *encoder,
  1244. struct drm_display_mode *mode,
  1245. struct drm_display_mode *adjusted_mode)
  1246. {
  1247. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1248. struct drm_display_mode *m = adjusted_mode;
  1249. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1250. m->hdisplay, m->vdisplay,
  1251. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1252. "INTERLACED" : "PROGRESSIVE");
  1253. drm_mode_copy(&hdata->current_mode, m);
  1254. }
  1255. static void hdmi_set_refclk(struct hdmi_context *hdata, bool on)
  1256. {
  1257. if (!hdata->sysreg)
  1258. return;
  1259. regmap_update_bits(hdata->sysreg, EXYNOS5433_SYSREG_DISP_HDMI_PHY,
  1260. SYSREG_HDMI_REFCLK_INT_CLK, on ? ~0 : 0);
  1261. }
  1262. static void hdmiphy_enable(struct hdmi_context *hdata)
  1263. {
  1264. if (hdata->powered)
  1265. return;
  1266. pm_runtime_get_sync(hdata->dev);
  1267. if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk))
  1268. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1269. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1270. PMU_HDMI_PHY_ENABLE_BIT, 1);
  1271. hdmi_set_refclk(hdata, true);
  1272. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, 0, HDMI_PHY_POWER_OFF_EN);
  1273. hdmiphy_conf_apply(hdata);
  1274. hdata->powered = true;
  1275. }
  1276. static void hdmiphy_disable(struct hdmi_context *hdata)
  1277. {
  1278. if (!hdata->powered)
  1279. return;
  1280. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_EN);
  1281. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, ~0, HDMI_PHY_POWER_OFF_EN);
  1282. hdmi_set_refclk(hdata, false);
  1283. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1284. PMU_HDMI_PHY_ENABLE_BIT, 0);
  1285. regulator_bulk_disable(ARRAY_SIZE(supply), hdata->regul_bulk);
  1286. pm_runtime_put_sync(hdata->dev);
  1287. hdata->powered = false;
  1288. }
  1289. static void hdmi_enable(struct drm_encoder *encoder)
  1290. {
  1291. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1292. hdmiphy_enable(hdata);
  1293. hdmi_conf_apply(hdata);
  1294. }
  1295. static void hdmi_disable(struct drm_encoder *encoder)
  1296. {
  1297. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1298. struct drm_crtc *crtc = encoder->crtc;
  1299. const struct drm_crtc_helper_funcs *funcs = NULL;
  1300. if (!hdata->powered)
  1301. return;
  1302. /*
  1303. * The SFRs of VP and Mixer are updated by Vertical Sync of
  1304. * Timing generator which is a part of HDMI so the sequence
  1305. * to disable TV Subsystem should be as following,
  1306. * VP -> Mixer -> HDMI
  1307. *
  1308. * Below codes will try to disable Mixer and VP(if used)
  1309. * prior to disabling HDMI.
  1310. */
  1311. if (crtc)
  1312. funcs = crtc->helper_private;
  1313. if (funcs && funcs->disable)
  1314. (*funcs->disable)(crtc);
  1315. cancel_delayed_work(&hdata->hotplug_work);
  1316. hdmiphy_disable(hdata);
  1317. }
  1318. static const struct drm_encoder_helper_funcs exynos_hdmi_encoder_helper_funcs = {
  1319. .mode_fixup = hdmi_mode_fixup,
  1320. .mode_set = hdmi_mode_set,
  1321. .enable = hdmi_enable,
  1322. .disable = hdmi_disable,
  1323. };
  1324. static const struct drm_encoder_funcs exynos_hdmi_encoder_funcs = {
  1325. .destroy = drm_encoder_cleanup,
  1326. };
  1327. static void hdmi_hotplug_work_func(struct work_struct *work)
  1328. {
  1329. struct hdmi_context *hdata;
  1330. hdata = container_of(work, struct hdmi_context, hotplug_work.work);
  1331. if (hdata->drm_dev)
  1332. drm_helper_hpd_irq_event(hdata->drm_dev);
  1333. }
  1334. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1335. {
  1336. struct hdmi_context *hdata = arg;
  1337. mod_delayed_work(system_wq, &hdata->hotplug_work,
  1338. msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
  1339. return IRQ_HANDLED;
  1340. }
  1341. static int hdmi_clks_get(struct hdmi_context *hdata,
  1342. const struct string_array_spec *names,
  1343. struct clk **clks)
  1344. {
  1345. struct device *dev = hdata->dev;
  1346. int i;
  1347. for (i = 0; i < names->count; ++i) {
  1348. struct clk *clk = devm_clk_get(dev, names->data[i]);
  1349. if (IS_ERR(clk)) {
  1350. int ret = PTR_ERR(clk);
  1351. dev_err(dev, "Cannot get clock %s, %d\n",
  1352. names->data[i], ret);
  1353. return ret;
  1354. }
  1355. clks[i] = clk;
  1356. }
  1357. return 0;
  1358. }
  1359. static int hdmi_clk_init(struct hdmi_context *hdata)
  1360. {
  1361. const struct hdmi_driver_data *drv_data = hdata->drv_data;
  1362. int count = drv_data->clk_gates.count + drv_data->clk_muxes.count;
  1363. struct device *dev = hdata->dev;
  1364. struct clk **clks;
  1365. int ret;
  1366. if (!count)
  1367. return 0;
  1368. clks = devm_kzalloc(dev, sizeof(*clks) * count, GFP_KERNEL);
  1369. if (!clks)
  1370. return -ENOMEM;
  1371. hdata->clk_gates = clks;
  1372. hdata->clk_muxes = clks + drv_data->clk_gates.count;
  1373. ret = hdmi_clks_get(hdata, &drv_data->clk_gates, hdata->clk_gates);
  1374. if (ret)
  1375. return ret;
  1376. return hdmi_clks_get(hdata, &drv_data->clk_muxes, hdata->clk_muxes);
  1377. }
  1378. static void hdmiphy_clk_enable(struct exynos_drm_clk *clk, bool enable)
  1379. {
  1380. struct hdmi_context *hdata = container_of(clk, struct hdmi_context,
  1381. phy_clk);
  1382. if (enable)
  1383. hdmiphy_enable(hdata);
  1384. else
  1385. hdmiphy_disable(hdata);
  1386. }
  1387. static int hdmi_bridge_init(struct hdmi_context *hdata)
  1388. {
  1389. struct device *dev = hdata->dev;
  1390. struct device_node *ep, *np;
  1391. ep = of_graph_get_endpoint_by_regs(dev->of_node, 1, -1);
  1392. if (!ep)
  1393. return 0;
  1394. np = of_graph_get_remote_port_parent(ep);
  1395. of_node_put(ep);
  1396. if (!np) {
  1397. DRM_ERROR("failed to get remote port parent");
  1398. return -EINVAL;
  1399. }
  1400. hdata->bridge = of_drm_find_bridge(np);
  1401. of_node_put(np);
  1402. if (!hdata->bridge)
  1403. return -EPROBE_DEFER;
  1404. return 0;
  1405. }
  1406. static int hdmi_resources_init(struct hdmi_context *hdata)
  1407. {
  1408. struct device *dev = hdata->dev;
  1409. int i, ret;
  1410. DRM_DEBUG_KMS("HDMI resource init\n");
  1411. hdata->hpd_gpio = devm_gpiod_get(dev, "hpd", GPIOD_IN);
  1412. if (IS_ERR(hdata->hpd_gpio)) {
  1413. DRM_ERROR("cannot get hpd gpio property\n");
  1414. return PTR_ERR(hdata->hpd_gpio);
  1415. }
  1416. hdata->irq = gpiod_to_irq(hdata->hpd_gpio);
  1417. if (hdata->irq < 0) {
  1418. DRM_ERROR("failed to get GPIO irq\n");
  1419. return hdata->irq;
  1420. }
  1421. ret = hdmi_clk_init(hdata);
  1422. if (ret)
  1423. return ret;
  1424. ret = hdmi_clk_set_parents(hdata, false);
  1425. if (ret)
  1426. return ret;
  1427. for (i = 0; i < ARRAY_SIZE(supply); ++i)
  1428. hdata->regul_bulk[i].supply = supply[i];
  1429. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), hdata->regul_bulk);
  1430. if (ret) {
  1431. if (ret != -EPROBE_DEFER)
  1432. DRM_ERROR("failed to get regulators\n");
  1433. return ret;
  1434. }
  1435. hdata->reg_hdmi_en = devm_regulator_get_optional(dev, "hdmi-en");
  1436. if (PTR_ERR(hdata->reg_hdmi_en) != -ENODEV) {
  1437. if (IS_ERR(hdata->reg_hdmi_en))
  1438. return PTR_ERR(hdata->reg_hdmi_en);
  1439. ret = regulator_enable(hdata->reg_hdmi_en);
  1440. if (ret) {
  1441. DRM_ERROR("failed to enable hdmi-en regulator\n");
  1442. return ret;
  1443. }
  1444. }
  1445. return hdmi_bridge_init(hdata);
  1446. }
  1447. static struct of_device_id hdmi_match_types[] = {
  1448. {
  1449. .compatible = "samsung,exynos4210-hdmi",
  1450. .data = &exynos4210_hdmi_driver_data,
  1451. }, {
  1452. .compatible = "samsung,exynos4212-hdmi",
  1453. .data = &exynos4212_hdmi_driver_data,
  1454. }, {
  1455. .compatible = "samsung,exynos5420-hdmi",
  1456. .data = &exynos5420_hdmi_driver_data,
  1457. }, {
  1458. .compatible = "samsung,exynos5433-hdmi",
  1459. .data = &exynos5433_hdmi_driver_data,
  1460. }, {
  1461. /* end node */
  1462. }
  1463. };
  1464. MODULE_DEVICE_TABLE (of, hdmi_match_types);
  1465. static int hdmi_bind(struct device *dev, struct device *master, void *data)
  1466. {
  1467. struct drm_device *drm_dev = data;
  1468. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1469. struct drm_encoder *encoder = &hdata->encoder;
  1470. int ret, pipe;
  1471. hdata->drm_dev = drm_dev;
  1472. pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
  1473. EXYNOS_DISPLAY_TYPE_HDMI);
  1474. if (pipe < 0)
  1475. return pipe;
  1476. hdata->phy_clk.enable = hdmiphy_clk_enable;
  1477. exynos_drm_crtc_from_pipe(drm_dev, pipe)->pipe_clk = &hdata->phy_clk;
  1478. encoder->possible_crtcs = 1 << pipe;
  1479. DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
  1480. drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs,
  1481. DRM_MODE_ENCODER_TMDS, NULL);
  1482. drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs);
  1483. ret = hdmi_create_connector(encoder);
  1484. if (ret) {
  1485. DRM_ERROR("failed to create connector ret = %d\n", ret);
  1486. drm_encoder_cleanup(encoder);
  1487. return ret;
  1488. }
  1489. return 0;
  1490. }
  1491. static void hdmi_unbind(struct device *dev, struct device *master, void *data)
  1492. {
  1493. }
  1494. static const struct component_ops hdmi_component_ops = {
  1495. .bind = hdmi_bind,
  1496. .unbind = hdmi_unbind,
  1497. };
  1498. static int hdmi_get_ddc_adapter(struct hdmi_context *hdata)
  1499. {
  1500. const char *compatible_str = "samsung,exynos4210-hdmiddc";
  1501. struct device_node *np;
  1502. struct i2c_adapter *adpt;
  1503. np = of_find_compatible_node(NULL, NULL, compatible_str);
  1504. if (np)
  1505. np = of_get_next_parent(np);
  1506. else
  1507. np = of_parse_phandle(hdata->dev->of_node, "ddc", 0);
  1508. if (!np) {
  1509. DRM_ERROR("Failed to find ddc node in device tree\n");
  1510. return -ENODEV;
  1511. }
  1512. adpt = of_find_i2c_adapter_by_node(np);
  1513. of_node_put(np);
  1514. if (!adpt) {
  1515. DRM_INFO("Failed to get ddc i2c adapter by node\n");
  1516. return -EPROBE_DEFER;
  1517. }
  1518. hdata->ddc_adpt = adpt;
  1519. return 0;
  1520. }
  1521. static int hdmi_get_phy_io(struct hdmi_context *hdata)
  1522. {
  1523. const char *compatible_str = "samsung,exynos4212-hdmiphy";
  1524. struct device_node *np;
  1525. int ret = 0;
  1526. np = of_find_compatible_node(NULL, NULL, compatible_str);
  1527. if (!np) {
  1528. np = of_parse_phandle(hdata->dev->of_node, "phy", 0);
  1529. if (!np) {
  1530. DRM_ERROR("Failed to find hdmiphy node in device tree\n");
  1531. return -ENODEV;
  1532. }
  1533. }
  1534. if (hdata->drv_data->is_apb_phy) {
  1535. hdata->regs_hdmiphy = of_iomap(np, 0);
  1536. if (!hdata->regs_hdmiphy) {
  1537. DRM_ERROR("failed to ioremap hdmi phy\n");
  1538. ret = -ENOMEM;
  1539. goto out;
  1540. }
  1541. } else {
  1542. hdata->hdmiphy_port = of_find_i2c_device_by_node(np);
  1543. if (!hdata->hdmiphy_port) {
  1544. DRM_INFO("Failed to get hdmi phy i2c client\n");
  1545. ret = -EPROBE_DEFER;
  1546. goto out;
  1547. }
  1548. }
  1549. out:
  1550. of_node_put(np);
  1551. return ret;
  1552. }
  1553. static int hdmi_probe(struct platform_device *pdev)
  1554. {
  1555. struct device *dev = &pdev->dev;
  1556. struct hdmi_context *hdata;
  1557. struct resource *res;
  1558. int ret;
  1559. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  1560. if (!hdata)
  1561. return -ENOMEM;
  1562. hdata->drv_data = of_device_get_match_data(dev);
  1563. platform_set_drvdata(pdev, hdata);
  1564. hdata->dev = dev;
  1565. ret = hdmi_resources_init(hdata);
  1566. if (ret) {
  1567. if (ret != -EPROBE_DEFER)
  1568. DRM_ERROR("hdmi_resources_init failed\n");
  1569. return ret;
  1570. }
  1571. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1572. hdata->regs = devm_ioremap_resource(dev, res);
  1573. if (IS_ERR(hdata->regs)) {
  1574. ret = PTR_ERR(hdata->regs);
  1575. return ret;
  1576. }
  1577. ret = hdmi_get_ddc_adapter(hdata);
  1578. if (ret)
  1579. return ret;
  1580. ret = hdmi_get_phy_io(hdata);
  1581. if (ret)
  1582. goto err_ddc;
  1583. INIT_DELAYED_WORK(&hdata->hotplug_work, hdmi_hotplug_work_func);
  1584. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1585. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1586. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1587. "hdmi", hdata);
  1588. if (ret) {
  1589. DRM_ERROR("failed to register hdmi interrupt\n");
  1590. goto err_hdmiphy;
  1591. }
  1592. hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  1593. "samsung,syscon-phandle");
  1594. if (IS_ERR(hdata->pmureg)) {
  1595. DRM_ERROR("syscon regmap lookup failed.\n");
  1596. ret = -EPROBE_DEFER;
  1597. goto err_hdmiphy;
  1598. }
  1599. if (hdata->drv_data->has_sysreg) {
  1600. hdata->sysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
  1601. "samsung,sysreg-phandle");
  1602. if (IS_ERR(hdata->sysreg)) {
  1603. DRM_ERROR("sysreg regmap lookup failed.\n");
  1604. ret = -EPROBE_DEFER;
  1605. goto err_hdmiphy;
  1606. }
  1607. }
  1608. pm_runtime_enable(dev);
  1609. ret = component_add(&pdev->dev, &hdmi_component_ops);
  1610. if (ret)
  1611. goto err_disable_pm_runtime;
  1612. return ret;
  1613. err_disable_pm_runtime:
  1614. pm_runtime_disable(dev);
  1615. err_hdmiphy:
  1616. if (hdata->hdmiphy_port)
  1617. put_device(&hdata->hdmiphy_port->dev);
  1618. if (hdata->regs_hdmiphy)
  1619. iounmap(hdata->regs_hdmiphy);
  1620. err_ddc:
  1621. put_device(&hdata->ddc_adpt->dev);
  1622. return ret;
  1623. }
  1624. static int hdmi_remove(struct platform_device *pdev)
  1625. {
  1626. struct hdmi_context *hdata = platform_get_drvdata(pdev);
  1627. cancel_delayed_work_sync(&hdata->hotplug_work);
  1628. component_del(&pdev->dev, &hdmi_component_ops);
  1629. pm_runtime_disable(&pdev->dev);
  1630. if (!IS_ERR(hdata->reg_hdmi_en))
  1631. regulator_disable(hdata->reg_hdmi_en);
  1632. if (hdata->hdmiphy_port)
  1633. put_device(&hdata->hdmiphy_port->dev);
  1634. if (hdata->regs_hdmiphy)
  1635. iounmap(hdata->regs_hdmiphy);
  1636. put_device(&hdata->ddc_adpt->dev);
  1637. return 0;
  1638. }
  1639. #ifdef CONFIG_PM
  1640. static int exynos_hdmi_suspend(struct device *dev)
  1641. {
  1642. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1643. hdmi_clk_disable_gates(hdata);
  1644. return 0;
  1645. }
  1646. static int exynos_hdmi_resume(struct device *dev)
  1647. {
  1648. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1649. int ret;
  1650. ret = hdmi_clk_enable_gates(hdata);
  1651. if (ret < 0)
  1652. return ret;
  1653. return 0;
  1654. }
  1655. #endif
  1656. static const struct dev_pm_ops exynos_hdmi_pm_ops = {
  1657. SET_RUNTIME_PM_OPS(exynos_hdmi_suspend, exynos_hdmi_resume, NULL)
  1658. };
  1659. struct platform_driver hdmi_driver = {
  1660. .probe = hdmi_probe,
  1661. .remove = hdmi_remove,
  1662. .driver = {
  1663. .name = "exynos-hdmi",
  1664. .owner = THIS_MODULE,
  1665. .pm = &exynos_hdmi_pm_ops,
  1666. .of_match_table = hdmi_match_types,
  1667. },
  1668. };