exynos_hdmi.c 52 KB

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