exynos_hdmi.c 53 KB

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