exynos_hdmi.c 56 KB

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