exynos_hdmi.c 53 KB

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