exynos_hdmi.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  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/regulator/consumer.h>
  31. #include <linux/io.h>
  32. #include <linux/of_address.h>
  33. #include <linux/of_device.h>
  34. #include <linux/of_gpio.h>
  35. #include <linux/hdmi.h>
  36. #include <linux/component.h>
  37. #include <linux/mfd/syscon.h>
  38. #include <linux/regmap.h>
  39. #include <drm/exynos_drm.h>
  40. #include "exynos_drm_drv.h"
  41. #include "exynos_drm_crtc.h"
  42. #include "exynos_mixer.h"
  43. #include <linux/gpio.h>
  44. #define ctx_from_connector(c) container_of(c, struct hdmi_context, connector)
  45. #define HOTPLUG_DEBOUNCE_MS 1100
  46. /* AVI header and aspect ratio */
  47. #define HDMI_AVI_VERSION 0x02
  48. #define HDMI_AVI_LENGTH 0x0D
  49. /* AUI header info */
  50. #define HDMI_AUI_VERSION 0x01
  51. #define HDMI_AUI_LENGTH 0x0A
  52. #define AVI_SAME_AS_PIC_ASPECT_RATIO 0x8
  53. #define AVI_4_3_CENTER_RATIO 0x9
  54. #define AVI_16_9_CENTER_RATIO 0xa
  55. enum hdmi_type {
  56. HDMI_TYPE13,
  57. HDMI_TYPE14,
  58. };
  59. struct hdmi_driver_data {
  60. unsigned int type;
  61. const struct hdmiphy_config *phy_confs;
  62. unsigned int phy_conf_count;
  63. unsigned int is_apb_phy:1;
  64. };
  65. struct hdmi_resources {
  66. struct clk *hdmi;
  67. struct clk *sclk_hdmi;
  68. struct clk *sclk_pixel;
  69. struct clk *sclk_hdmiphy;
  70. struct clk *mout_hdmi;
  71. struct regulator_bulk_data *regul_bulk;
  72. struct regulator *reg_hdmi_en;
  73. int regul_count;
  74. };
  75. struct hdmi_context {
  76. struct drm_encoder encoder;
  77. struct device *dev;
  78. struct drm_device *drm_dev;
  79. struct drm_connector connector;
  80. bool hpd;
  81. bool powered;
  82. bool dvi_mode;
  83. void __iomem *regs;
  84. int irq;
  85. struct delayed_work hotplug_work;
  86. struct i2c_adapter *ddc_adpt;
  87. struct i2c_client *hdmiphy_port;
  88. /* current hdmiphy conf regs */
  89. struct drm_display_mode current_mode;
  90. u8 cea_video_id;
  91. struct hdmi_resources res;
  92. const struct hdmi_driver_data *drv_data;
  93. int hpd_gpio;
  94. void __iomem *regs_hdmiphy;
  95. struct regmap *pmureg;
  96. };
  97. static inline struct hdmi_context *encoder_to_hdmi(struct drm_encoder *e)
  98. {
  99. return container_of(e, struct hdmi_context, encoder);
  100. }
  101. struct hdmiphy_config {
  102. int pixel_clock;
  103. u8 conf[32];
  104. };
  105. /* list of phy config settings */
  106. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  107. {
  108. .pixel_clock = 27000000,
  109. .conf = {
  110. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  111. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  112. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  113. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  114. },
  115. },
  116. {
  117. .pixel_clock = 27027000,
  118. .conf = {
  119. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  120. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  121. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  122. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  123. },
  124. },
  125. {
  126. .pixel_clock = 74176000,
  127. .conf = {
  128. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  129. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  130. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  131. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  132. },
  133. },
  134. {
  135. .pixel_clock = 74250000,
  136. .conf = {
  137. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  138. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  139. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  140. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  141. },
  142. },
  143. {
  144. .pixel_clock = 148500000,
  145. .conf = {
  146. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  147. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  148. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  149. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  150. },
  151. },
  152. };
  153. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  154. {
  155. .pixel_clock = 25200000,
  156. .conf = {
  157. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  158. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  159. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  160. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  161. },
  162. },
  163. {
  164. .pixel_clock = 27000000,
  165. .conf = {
  166. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  167. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  168. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  169. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  170. },
  171. },
  172. {
  173. .pixel_clock = 27027000,
  174. .conf = {
  175. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  176. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  177. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  178. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  179. },
  180. },
  181. {
  182. .pixel_clock = 36000000,
  183. .conf = {
  184. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  185. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  186. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  187. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  188. },
  189. },
  190. {
  191. .pixel_clock = 40000000,
  192. .conf = {
  193. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  194. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  195. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  196. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  197. },
  198. },
  199. {
  200. .pixel_clock = 65000000,
  201. .conf = {
  202. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  203. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  204. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  205. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  206. },
  207. },
  208. {
  209. .pixel_clock = 71000000,
  210. .conf = {
  211. 0x01, 0xd1, 0x3b, 0x35, 0x40, 0x0c, 0x04, 0x08,
  212. 0x85, 0xa0, 0x63, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  213. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  214. 0x54, 0xad, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  215. },
  216. },
  217. {
  218. .pixel_clock = 73250000,
  219. .conf = {
  220. 0x01, 0xd1, 0x3d, 0x35, 0x40, 0x18, 0x02, 0x08,
  221. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  222. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  223. 0x54, 0xa8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  224. },
  225. },
  226. {
  227. .pixel_clock = 74176000,
  228. .conf = {
  229. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  230. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  231. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  232. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  233. },
  234. },
  235. {
  236. .pixel_clock = 74250000,
  237. .conf = {
  238. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  239. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  240. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  241. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  242. },
  243. },
  244. {
  245. .pixel_clock = 83500000,
  246. .conf = {
  247. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  248. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  249. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  250. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  251. },
  252. },
  253. {
  254. .pixel_clock = 106500000,
  255. .conf = {
  256. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  257. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  258. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  259. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  260. },
  261. },
  262. {
  263. .pixel_clock = 108000000,
  264. .conf = {
  265. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  266. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  267. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  268. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  269. },
  270. },
  271. {
  272. .pixel_clock = 115500000,
  273. .conf = {
  274. 0x01, 0xd1, 0x30, 0x12, 0x40, 0x40, 0x10, 0x08,
  275. 0x80, 0x80, 0x21, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  276. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  277. 0x54, 0xaa, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  278. },
  279. },
  280. {
  281. .pixel_clock = 119000000,
  282. .conf = {
  283. 0x01, 0xd1, 0x32, 0x1a, 0x40, 0x30, 0xd8, 0x08,
  284. 0x04, 0xa0, 0x2a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  285. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  286. 0x54, 0x9d, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  287. },
  288. },
  289. {
  290. .pixel_clock = 146250000,
  291. .conf = {
  292. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  293. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  294. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  295. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  296. },
  297. },
  298. {
  299. .pixel_clock = 148500000,
  300. .conf = {
  301. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  302. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  303. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  304. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  305. },
  306. },
  307. };
  308. static const struct hdmiphy_config hdmiphy_5420_configs[] = {
  309. {
  310. .pixel_clock = 25200000,
  311. .conf = {
  312. 0x01, 0x52, 0x3F, 0x55, 0x40, 0x01, 0x00, 0xC8,
  313. 0x82, 0xC8, 0xBD, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  314. 0x06, 0x80, 0x01, 0x84, 0x05, 0x02, 0x24, 0x66,
  315. 0x54, 0xF4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  316. },
  317. },
  318. {
  319. .pixel_clock = 27000000,
  320. .conf = {
  321. 0x01, 0xD1, 0x22, 0x51, 0x40, 0x08, 0xFC, 0xE0,
  322. 0x98, 0xE8, 0xCB, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  323. 0x06, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  324. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  325. },
  326. },
  327. {
  328. .pixel_clock = 27027000,
  329. .conf = {
  330. 0x01, 0xD1, 0x2D, 0x72, 0x40, 0x64, 0x12, 0xC8,
  331. 0x43, 0xE8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  332. 0x26, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  333. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  334. },
  335. },
  336. {
  337. .pixel_clock = 36000000,
  338. .conf = {
  339. 0x01, 0x51, 0x2D, 0x55, 0x40, 0x40, 0x00, 0xC8,
  340. 0x02, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  341. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  342. 0x54, 0xAB, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  343. },
  344. },
  345. {
  346. .pixel_clock = 40000000,
  347. .conf = {
  348. 0x01, 0xD1, 0x21, 0x31, 0x40, 0x3C, 0x28, 0xC8,
  349. 0x87, 0xE8, 0xC8, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  350. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  351. 0x54, 0x9A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  352. },
  353. },
  354. {
  355. .pixel_clock = 65000000,
  356. .conf = {
  357. 0x01, 0xD1, 0x36, 0x34, 0x40, 0x0C, 0x04, 0xC8,
  358. 0x82, 0xE8, 0x45, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  359. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  360. 0x54, 0xBD, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  361. },
  362. },
  363. {
  364. .pixel_clock = 71000000,
  365. .conf = {
  366. 0x01, 0xD1, 0x3B, 0x35, 0x40, 0x0C, 0x04, 0xC8,
  367. 0x85, 0xE8, 0x63, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  368. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  369. 0x54, 0x57, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  370. },
  371. },
  372. {
  373. .pixel_clock = 73250000,
  374. .conf = {
  375. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x78, 0x8D, 0xC8,
  376. 0x81, 0xE8, 0xB7, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  377. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  378. 0x54, 0xA8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  379. },
  380. },
  381. {
  382. .pixel_clock = 74176000,
  383. .conf = {
  384. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0xC8,
  385. 0x81, 0xE8, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  386. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  387. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  388. },
  389. },
  390. {
  391. .pixel_clock = 74250000,
  392. .conf = {
  393. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  394. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  395. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  396. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  397. },
  398. },
  399. {
  400. .pixel_clock = 83500000,
  401. .conf = {
  402. 0x01, 0xD1, 0x23, 0x11, 0x40, 0x0C, 0xFB, 0xC8,
  403. 0x85, 0xE8, 0xD1, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  404. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  405. 0x54, 0x4A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  406. },
  407. },
  408. {
  409. .pixel_clock = 88750000,
  410. .conf = {
  411. 0x01, 0xD1, 0x25, 0x11, 0x40, 0x18, 0xFF, 0xC8,
  412. 0x83, 0xE8, 0xDE, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  413. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  414. 0x54, 0x45, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  415. },
  416. },
  417. {
  418. .pixel_clock = 106500000,
  419. .conf = {
  420. 0x01, 0xD1, 0x2C, 0x12, 0x40, 0x0C, 0x09, 0xC8,
  421. 0x84, 0xE8, 0x0A, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  422. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  423. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  424. },
  425. },
  426. {
  427. .pixel_clock = 108000000,
  428. .conf = {
  429. 0x01, 0x51, 0x2D, 0x15, 0x40, 0x01, 0x00, 0xC8,
  430. 0x82, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  431. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  432. 0x54, 0xC7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  433. },
  434. },
  435. {
  436. .pixel_clock = 115500000,
  437. .conf = {
  438. 0x01, 0xD1, 0x30, 0x14, 0x40, 0x0C, 0x03, 0xC8,
  439. 0x88, 0xE8, 0x21, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  440. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  441. 0x54, 0x6A, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  442. },
  443. },
  444. {
  445. .pixel_clock = 146250000,
  446. .conf = {
  447. 0x01, 0xD1, 0x3D, 0x15, 0x40, 0x18, 0xFD, 0xC8,
  448. 0x83, 0xE8, 0x6E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  449. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  450. 0x54, 0x54, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  451. },
  452. },
  453. {
  454. .pixel_clock = 148500000,
  455. .conf = {
  456. 0x01, 0xD1, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  457. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  458. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  459. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x80, 0x01, 0x80,
  460. },
  461. },
  462. };
  463. static struct hdmi_driver_data exynos5420_hdmi_driver_data = {
  464. .type = HDMI_TYPE14,
  465. .phy_confs = hdmiphy_5420_configs,
  466. .phy_conf_count = ARRAY_SIZE(hdmiphy_5420_configs),
  467. .is_apb_phy = 1,
  468. };
  469. static struct hdmi_driver_data exynos4212_hdmi_driver_data = {
  470. .type = HDMI_TYPE14,
  471. .phy_confs = hdmiphy_v14_configs,
  472. .phy_conf_count = ARRAY_SIZE(hdmiphy_v14_configs),
  473. .is_apb_phy = 0,
  474. };
  475. static struct hdmi_driver_data exynos4210_hdmi_driver_data = {
  476. .type = HDMI_TYPE13,
  477. .phy_confs = hdmiphy_v13_configs,
  478. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  479. .is_apb_phy = 0,
  480. };
  481. static struct hdmi_driver_data exynos5_hdmi_driver_data = {
  482. .type = HDMI_TYPE14,
  483. .phy_confs = hdmiphy_v13_configs,
  484. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  485. .is_apb_phy = 0,
  486. };
  487. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  488. {
  489. return readl(hdata->regs + reg_id);
  490. }
  491. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  492. u32 reg_id, u8 value)
  493. {
  494. writeb(value, hdata->regs + reg_id);
  495. }
  496. static inline void hdmi_reg_writev(struct hdmi_context *hdata, u32 reg_id,
  497. int bytes, u32 val)
  498. {
  499. while (--bytes >= 0) {
  500. writeb(val & 0xff, hdata->regs + reg_id);
  501. val >>= 8;
  502. reg_id += 4;
  503. }
  504. }
  505. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  506. u32 reg_id, u32 value, u32 mask)
  507. {
  508. u32 old = readl(hdata->regs + reg_id);
  509. value = (value & mask) | (old & ~mask);
  510. writel(value, hdata->regs + reg_id);
  511. }
  512. static int hdmiphy_reg_writeb(struct hdmi_context *hdata,
  513. u32 reg_offset, u8 value)
  514. {
  515. if (hdata->hdmiphy_port) {
  516. u8 buffer[2];
  517. int ret;
  518. buffer[0] = reg_offset;
  519. buffer[1] = value;
  520. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  521. if (ret == 2)
  522. return 0;
  523. return ret;
  524. } else {
  525. writeb(value, hdata->regs_hdmiphy + (reg_offset<<2));
  526. return 0;
  527. }
  528. }
  529. static int hdmiphy_reg_write_buf(struct hdmi_context *hdata,
  530. u32 reg_offset, const u8 *buf, u32 len)
  531. {
  532. if ((reg_offset + len) > 32)
  533. return -EINVAL;
  534. if (hdata->hdmiphy_port) {
  535. int ret;
  536. ret = i2c_master_send(hdata->hdmiphy_port, buf, len);
  537. if (ret == len)
  538. return 0;
  539. return ret;
  540. } else {
  541. int i;
  542. for (i = 0; i < len; i++)
  543. writeb(buf[i], hdata->regs_hdmiphy +
  544. ((reg_offset + i)<<2));
  545. return 0;
  546. }
  547. }
  548. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  549. {
  550. #define DUMPREG(reg_id) \
  551. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  552. readl(hdata->regs + reg_id))
  553. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  554. DUMPREG(HDMI_INTC_FLAG);
  555. DUMPREG(HDMI_INTC_CON);
  556. DUMPREG(HDMI_HPD_STATUS);
  557. DUMPREG(HDMI_V13_PHY_RSTOUT);
  558. DUMPREG(HDMI_V13_PHY_VPLL);
  559. DUMPREG(HDMI_V13_PHY_CMU);
  560. DUMPREG(HDMI_V13_CORE_RSTOUT);
  561. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  562. DUMPREG(HDMI_CON_0);
  563. DUMPREG(HDMI_CON_1);
  564. DUMPREG(HDMI_CON_2);
  565. DUMPREG(HDMI_SYS_STATUS);
  566. DUMPREG(HDMI_V13_PHY_STATUS);
  567. DUMPREG(HDMI_STATUS_EN);
  568. DUMPREG(HDMI_HPD);
  569. DUMPREG(HDMI_MODE_SEL);
  570. DUMPREG(HDMI_V13_HPD_GEN);
  571. DUMPREG(HDMI_V13_DC_CONTROL);
  572. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  573. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  574. DUMPREG(HDMI_H_BLANK_0);
  575. DUMPREG(HDMI_H_BLANK_1);
  576. DUMPREG(HDMI_V13_V_BLANK_0);
  577. DUMPREG(HDMI_V13_V_BLANK_1);
  578. DUMPREG(HDMI_V13_V_BLANK_2);
  579. DUMPREG(HDMI_V13_H_V_LINE_0);
  580. DUMPREG(HDMI_V13_H_V_LINE_1);
  581. DUMPREG(HDMI_V13_H_V_LINE_2);
  582. DUMPREG(HDMI_VSYNC_POL);
  583. DUMPREG(HDMI_INT_PRO_MODE);
  584. DUMPREG(HDMI_V13_V_BLANK_F_0);
  585. DUMPREG(HDMI_V13_V_BLANK_F_1);
  586. DUMPREG(HDMI_V13_V_BLANK_F_2);
  587. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  588. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  589. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  590. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  591. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  592. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  593. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  594. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  595. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  596. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  597. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  598. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  599. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  600. DUMPREG(HDMI_TG_CMD);
  601. DUMPREG(HDMI_TG_H_FSZ_L);
  602. DUMPREG(HDMI_TG_H_FSZ_H);
  603. DUMPREG(HDMI_TG_HACT_ST_L);
  604. DUMPREG(HDMI_TG_HACT_ST_H);
  605. DUMPREG(HDMI_TG_HACT_SZ_L);
  606. DUMPREG(HDMI_TG_HACT_SZ_H);
  607. DUMPREG(HDMI_TG_V_FSZ_L);
  608. DUMPREG(HDMI_TG_V_FSZ_H);
  609. DUMPREG(HDMI_TG_VSYNC_L);
  610. DUMPREG(HDMI_TG_VSYNC_H);
  611. DUMPREG(HDMI_TG_VSYNC2_L);
  612. DUMPREG(HDMI_TG_VSYNC2_H);
  613. DUMPREG(HDMI_TG_VACT_ST_L);
  614. DUMPREG(HDMI_TG_VACT_ST_H);
  615. DUMPREG(HDMI_TG_VACT_SZ_L);
  616. DUMPREG(HDMI_TG_VACT_SZ_H);
  617. DUMPREG(HDMI_TG_FIELD_CHG_L);
  618. DUMPREG(HDMI_TG_FIELD_CHG_H);
  619. DUMPREG(HDMI_TG_VACT_ST2_L);
  620. DUMPREG(HDMI_TG_VACT_ST2_H);
  621. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  622. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  623. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  624. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  625. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  626. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  627. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  628. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  629. #undef DUMPREG
  630. }
  631. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  632. {
  633. int i;
  634. #define DUMPREG(reg_id) \
  635. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  636. readl(hdata->regs + reg_id))
  637. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  638. DUMPREG(HDMI_INTC_CON);
  639. DUMPREG(HDMI_INTC_FLAG);
  640. DUMPREG(HDMI_HPD_STATUS);
  641. DUMPREG(HDMI_INTC_CON_1);
  642. DUMPREG(HDMI_INTC_FLAG_1);
  643. DUMPREG(HDMI_PHY_STATUS_0);
  644. DUMPREG(HDMI_PHY_STATUS_PLL);
  645. DUMPREG(HDMI_PHY_CON_0);
  646. DUMPREG(HDMI_PHY_RSTOUT);
  647. DUMPREG(HDMI_PHY_VPLL);
  648. DUMPREG(HDMI_PHY_CMU);
  649. DUMPREG(HDMI_CORE_RSTOUT);
  650. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  651. DUMPREG(HDMI_CON_0);
  652. DUMPREG(HDMI_CON_1);
  653. DUMPREG(HDMI_CON_2);
  654. DUMPREG(HDMI_SYS_STATUS);
  655. DUMPREG(HDMI_PHY_STATUS_0);
  656. DUMPREG(HDMI_STATUS_EN);
  657. DUMPREG(HDMI_HPD);
  658. DUMPREG(HDMI_MODE_SEL);
  659. DUMPREG(HDMI_ENC_EN);
  660. DUMPREG(HDMI_DC_CONTROL);
  661. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  662. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  663. DUMPREG(HDMI_H_BLANK_0);
  664. DUMPREG(HDMI_H_BLANK_1);
  665. DUMPREG(HDMI_V2_BLANK_0);
  666. DUMPREG(HDMI_V2_BLANK_1);
  667. DUMPREG(HDMI_V1_BLANK_0);
  668. DUMPREG(HDMI_V1_BLANK_1);
  669. DUMPREG(HDMI_V_LINE_0);
  670. DUMPREG(HDMI_V_LINE_1);
  671. DUMPREG(HDMI_H_LINE_0);
  672. DUMPREG(HDMI_H_LINE_1);
  673. DUMPREG(HDMI_HSYNC_POL);
  674. DUMPREG(HDMI_VSYNC_POL);
  675. DUMPREG(HDMI_INT_PRO_MODE);
  676. DUMPREG(HDMI_V_BLANK_F0_0);
  677. DUMPREG(HDMI_V_BLANK_F0_1);
  678. DUMPREG(HDMI_V_BLANK_F1_0);
  679. DUMPREG(HDMI_V_BLANK_F1_1);
  680. DUMPREG(HDMI_H_SYNC_START_0);
  681. DUMPREG(HDMI_H_SYNC_START_1);
  682. DUMPREG(HDMI_H_SYNC_END_0);
  683. DUMPREG(HDMI_H_SYNC_END_1);
  684. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  685. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  686. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  687. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  688. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  689. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  690. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  691. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  692. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  693. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  694. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  695. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  696. DUMPREG(HDMI_V_BLANK_F2_0);
  697. DUMPREG(HDMI_V_BLANK_F2_1);
  698. DUMPREG(HDMI_V_BLANK_F3_0);
  699. DUMPREG(HDMI_V_BLANK_F3_1);
  700. DUMPREG(HDMI_V_BLANK_F4_0);
  701. DUMPREG(HDMI_V_BLANK_F4_1);
  702. DUMPREG(HDMI_V_BLANK_F5_0);
  703. DUMPREG(HDMI_V_BLANK_F5_1);
  704. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  705. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  706. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  707. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  708. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  709. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  710. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  711. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  712. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  713. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  714. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  715. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  716. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  717. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  718. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  719. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  720. DUMPREG(HDMI_VACT_SPACE_1_0);
  721. DUMPREG(HDMI_VACT_SPACE_1_1);
  722. DUMPREG(HDMI_VACT_SPACE_2_0);
  723. DUMPREG(HDMI_VACT_SPACE_2_1);
  724. DUMPREG(HDMI_VACT_SPACE_3_0);
  725. DUMPREG(HDMI_VACT_SPACE_3_1);
  726. DUMPREG(HDMI_VACT_SPACE_4_0);
  727. DUMPREG(HDMI_VACT_SPACE_4_1);
  728. DUMPREG(HDMI_VACT_SPACE_5_0);
  729. DUMPREG(HDMI_VACT_SPACE_5_1);
  730. DUMPREG(HDMI_VACT_SPACE_6_0);
  731. DUMPREG(HDMI_VACT_SPACE_6_1);
  732. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  733. DUMPREG(HDMI_TG_CMD);
  734. DUMPREG(HDMI_TG_H_FSZ_L);
  735. DUMPREG(HDMI_TG_H_FSZ_H);
  736. DUMPREG(HDMI_TG_HACT_ST_L);
  737. DUMPREG(HDMI_TG_HACT_ST_H);
  738. DUMPREG(HDMI_TG_HACT_SZ_L);
  739. DUMPREG(HDMI_TG_HACT_SZ_H);
  740. DUMPREG(HDMI_TG_V_FSZ_L);
  741. DUMPREG(HDMI_TG_V_FSZ_H);
  742. DUMPREG(HDMI_TG_VSYNC_L);
  743. DUMPREG(HDMI_TG_VSYNC_H);
  744. DUMPREG(HDMI_TG_VSYNC2_L);
  745. DUMPREG(HDMI_TG_VSYNC2_H);
  746. DUMPREG(HDMI_TG_VACT_ST_L);
  747. DUMPREG(HDMI_TG_VACT_ST_H);
  748. DUMPREG(HDMI_TG_VACT_SZ_L);
  749. DUMPREG(HDMI_TG_VACT_SZ_H);
  750. DUMPREG(HDMI_TG_FIELD_CHG_L);
  751. DUMPREG(HDMI_TG_FIELD_CHG_H);
  752. DUMPREG(HDMI_TG_VACT_ST2_L);
  753. DUMPREG(HDMI_TG_VACT_ST2_H);
  754. DUMPREG(HDMI_TG_VACT_ST3_L);
  755. DUMPREG(HDMI_TG_VACT_ST3_H);
  756. DUMPREG(HDMI_TG_VACT_ST4_L);
  757. DUMPREG(HDMI_TG_VACT_ST4_H);
  758. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  759. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  760. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  761. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  762. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  763. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  764. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  765. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  766. DUMPREG(HDMI_TG_3D);
  767. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  768. DUMPREG(HDMI_AVI_CON);
  769. DUMPREG(HDMI_AVI_HEADER0);
  770. DUMPREG(HDMI_AVI_HEADER1);
  771. DUMPREG(HDMI_AVI_HEADER2);
  772. DUMPREG(HDMI_AVI_CHECK_SUM);
  773. DUMPREG(HDMI_VSI_CON);
  774. DUMPREG(HDMI_VSI_HEADER0);
  775. DUMPREG(HDMI_VSI_HEADER1);
  776. DUMPREG(HDMI_VSI_HEADER2);
  777. for (i = 0; i < 7; ++i)
  778. DUMPREG(HDMI_VSI_DATA(i));
  779. #undef DUMPREG
  780. }
  781. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  782. {
  783. if (hdata->drv_data->type == HDMI_TYPE13)
  784. hdmi_v13_regs_dump(hdata, prefix);
  785. else
  786. hdmi_v14_regs_dump(hdata, prefix);
  787. }
  788. static u8 hdmi_chksum(struct hdmi_context *hdata,
  789. u32 start, u8 len, u32 hdr_sum)
  790. {
  791. int i;
  792. /* hdr_sum : header0 + header1 + header2
  793. * start : start address of packet byte1
  794. * len : packet bytes - 1 */
  795. for (i = 0; i < len; ++i)
  796. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  797. /* return 2's complement of 8 bit hdr_sum */
  798. return (u8)(~(hdr_sum & 0xff) + 1);
  799. }
  800. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  801. union hdmi_infoframe *infoframe)
  802. {
  803. u32 hdr_sum;
  804. u8 chksum;
  805. u32 mod;
  806. u8 ar;
  807. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  808. if (hdata->dvi_mode) {
  809. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  810. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  811. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  812. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  813. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  814. return;
  815. }
  816. switch (infoframe->any.type) {
  817. case HDMI_INFOFRAME_TYPE_AVI:
  818. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  819. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
  820. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
  821. infoframe->any.version);
  822. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
  823. hdr_sum = infoframe->any.type + infoframe->any.version +
  824. infoframe->any.length;
  825. /* Output format zero hardcoded ,RGB YBCR selection */
  826. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  827. AVI_ACTIVE_FORMAT_VALID |
  828. AVI_UNDERSCANNED_DISPLAY_VALID);
  829. /*
  830. * Set the aspect ratio as per the mode, mentioned in
  831. * Table 9 AVI InfoFrame Data Byte 2 of CEA-861-D Standard
  832. */
  833. ar = hdata->current_mode.picture_aspect_ratio;
  834. switch (ar) {
  835. case HDMI_PICTURE_ASPECT_4_3:
  836. ar |= AVI_4_3_CENTER_RATIO;
  837. break;
  838. case HDMI_PICTURE_ASPECT_16_9:
  839. ar |= AVI_16_9_CENTER_RATIO;
  840. break;
  841. case HDMI_PICTURE_ASPECT_NONE:
  842. default:
  843. ar |= AVI_SAME_AS_PIC_ASPECT_RATIO;
  844. break;
  845. }
  846. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), ar);
  847. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), hdata->cea_video_id);
  848. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  849. infoframe->any.length, hdr_sum);
  850. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  851. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  852. break;
  853. case HDMI_INFOFRAME_TYPE_AUDIO:
  854. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  855. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
  856. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
  857. infoframe->any.version);
  858. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
  859. hdr_sum = infoframe->any.type + infoframe->any.version +
  860. infoframe->any.length;
  861. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  862. infoframe->any.length, hdr_sum);
  863. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  864. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  865. break;
  866. default:
  867. break;
  868. }
  869. }
  870. static enum drm_connector_status hdmi_detect(struct drm_connector *connector,
  871. bool force)
  872. {
  873. struct hdmi_context *hdata = ctx_from_connector(connector);
  874. if (gpio_get_value(hdata->hpd_gpio))
  875. return connector_status_connected;
  876. return connector_status_disconnected;
  877. }
  878. static void hdmi_connector_destroy(struct drm_connector *connector)
  879. {
  880. drm_connector_unregister(connector);
  881. drm_connector_cleanup(connector);
  882. }
  883. static struct drm_connector_funcs hdmi_connector_funcs = {
  884. .dpms = drm_atomic_helper_connector_dpms,
  885. .fill_modes = drm_helper_probe_single_connector_modes,
  886. .detect = hdmi_detect,
  887. .destroy = hdmi_connector_destroy,
  888. .reset = drm_atomic_helper_connector_reset,
  889. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  890. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  891. };
  892. static int hdmi_get_modes(struct drm_connector *connector)
  893. {
  894. struct hdmi_context *hdata = ctx_from_connector(connector);
  895. struct edid *edid;
  896. int ret;
  897. if (!hdata->ddc_adpt)
  898. return -ENODEV;
  899. edid = drm_get_edid(connector, hdata->ddc_adpt);
  900. if (!edid)
  901. return -ENODEV;
  902. hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
  903. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  904. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  905. edid->width_cm, edid->height_cm);
  906. drm_mode_connector_update_edid_property(connector, edid);
  907. ret = drm_add_edid_modes(connector, edid);
  908. kfree(edid);
  909. return ret;
  910. }
  911. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  912. {
  913. int i;
  914. for (i = 0; i < hdata->drv_data->phy_conf_count; i++)
  915. if (hdata->drv_data->phy_confs[i].pixel_clock == pixel_clock)
  916. return i;
  917. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  918. return -EINVAL;
  919. }
  920. static int hdmi_mode_valid(struct drm_connector *connector,
  921. struct drm_display_mode *mode)
  922. {
  923. struct hdmi_context *hdata = ctx_from_connector(connector);
  924. int ret;
  925. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  926. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  927. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  928. false, mode->clock * 1000);
  929. ret = mixer_check_mode(mode);
  930. if (ret)
  931. return MODE_BAD;
  932. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  933. if (ret < 0)
  934. return MODE_BAD;
  935. return MODE_OK;
  936. }
  937. static struct drm_encoder *hdmi_best_encoder(struct drm_connector *connector)
  938. {
  939. struct hdmi_context *hdata = ctx_from_connector(connector);
  940. return &hdata->encoder;
  941. }
  942. static struct drm_connector_helper_funcs hdmi_connector_helper_funcs = {
  943. .get_modes = hdmi_get_modes,
  944. .mode_valid = hdmi_mode_valid,
  945. .best_encoder = hdmi_best_encoder,
  946. };
  947. static int hdmi_create_connector(struct drm_encoder *encoder)
  948. {
  949. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  950. struct drm_connector *connector = &hdata->connector;
  951. int ret;
  952. connector->interlace_allowed = true;
  953. connector->polled = DRM_CONNECTOR_POLL_HPD;
  954. ret = drm_connector_init(hdata->drm_dev, connector,
  955. &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
  956. if (ret) {
  957. DRM_ERROR("Failed to initialize connector with drm\n");
  958. return ret;
  959. }
  960. drm_connector_helper_add(connector, &hdmi_connector_helper_funcs);
  961. drm_connector_register(connector);
  962. drm_mode_connector_attach_encoder(connector, encoder);
  963. return 0;
  964. }
  965. static bool hdmi_mode_fixup(struct drm_encoder *encoder,
  966. const struct drm_display_mode *mode,
  967. struct drm_display_mode *adjusted_mode)
  968. {
  969. struct drm_device *dev = encoder->dev;
  970. struct drm_connector *connector;
  971. struct drm_display_mode *m;
  972. int mode_ok;
  973. drm_mode_set_crtcinfo(adjusted_mode, 0);
  974. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  975. if (connector->encoder == encoder)
  976. break;
  977. }
  978. if (connector->encoder != encoder)
  979. return true;
  980. mode_ok = hdmi_mode_valid(connector, adjusted_mode);
  981. /* just return if user desired mode exists. */
  982. if (mode_ok == MODE_OK)
  983. return true;
  984. /*
  985. * otherwise, find the most suitable mode among modes and change it
  986. * to adjusted_mode.
  987. */
  988. list_for_each_entry(m, &connector->modes, head) {
  989. mode_ok = hdmi_mode_valid(connector, m);
  990. if (mode_ok == MODE_OK) {
  991. DRM_INFO("desired mode doesn't exist so\n");
  992. DRM_INFO("use the most suitable mode among modes.\n");
  993. DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
  994. m->hdisplay, m->vdisplay, m->vrefresh);
  995. drm_mode_copy(adjusted_mode, m);
  996. break;
  997. }
  998. }
  999. return true;
  1000. }
  1001. static void hdmi_set_acr(u32 freq, u8 *acr)
  1002. {
  1003. u32 n, cts;
  1004. switch (freq) {
  1005. case 32000:
  1006. n = 4096;
  1007. cts = 27000;
  1008. break;
  1009. case 44100:
  1010. n = 6272;
  1011. cts = 30000;
  1012. break;
  1013. case 88200:
  1014. n = 12544;
  1015. cts = 30000;
  1016. break;
  1017. case 176400:
  1018. n = 25088;
  1019. cts = 30000;
  1020. break;
  1021. case 48000:
  1022. n = 6144;
  1023. cts = 27000;
  1024. break;
  1025. case 96000:
  1026. n = 12288;
  1027. cts = 27000;
  1028. break;
  1029. case 192000:
  1030. n = 24576;
  1031. cts = 27000;
  1032. break;
  1033. default:
  1034. n = 0;
  1035. cts = 0;
  1036. break;
  1037. }
  1038. acr[1] = cts >> 16;
  1039. acr[2] = cts >> 8 & 0xff;
  1040. acr[3] = cts & 0xff;
  1041. acr[4] = n >> 16;
  1042. acr[5] = n >> 8 & 0xff;
  1043. acr[6] = n & 0xff;
  1044. }
  1045. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  1046. {
  1047. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  1048. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  1049. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  1050. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  1051. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  1052. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  1053. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  1054. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  1055. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  1056. if (hdata->drv_data->type == HDMI_TYPE13)
  1057. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  1058. else
  1059. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  1060. }
  1061. static void hdmi_audio_init(struct hdmi_context *hdata)
  1062. {
  1063. u32 sample_rate, bits_per_sample;
  1064. u32 data_num, bit_ch, sample_frq;
  1065. u32 val;
  1066. u8 acr[7];
  1067. sample_rate = 44100;
  1068. bits_per_sample = 16;
  1069. switch (bits_per_sample) {
  1070. case 20:
  1071. data_num = 2;
  1072. bit_ch = 1;
  1073. break;
  1074. case 24:
  1075. data_num = 3;
  1076. bit_ch = 1;
  1077. break;
  1078. default:
  1079. data_num = 1;
  1080. bit_ch = 0;
  1081. break;
  1082. }
  1083. hdmi_set_acr(sample_rate, acr);
  1084. hdmi_reg_acr(hdata, acr);
  1085. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  1086. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  1087. | HDMI_I2S_MUX_ENABLE);
  1088. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  1089. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  1090. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  1091. sample_frq = (sample_rate == 44100) ? 0 :
  1092. (sample_rate == 48000) ? 2 :
  1093. (sample_rate == 32000) ? 3 :
  1094. (sample_rate == 96000) ? 0xa : 0x0;
  1095. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  1096. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  1097. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  1098. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  1099. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  1100. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  1101. | HDMI_I2S_SEL_LRCK(6));
  1102. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  1103. | HDMI_I2S_SEL_SDATA2(4));
  1104. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  1105. | HDMI_I2S_SEL_SDATA2(2));
  1106. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  1107. /* I2S_CON_1 & 2 */
  1108. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  1109. | HDMI_I2S_L_CH_LOW_POL);
  1110. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  1111. | HDMI_I2S_SET_BIT_CH(bit_ch)
  1112. | HDMI_I2S_SET_SDATA_BIT(data_num)
  1113. | HDMI_I2S_BASIC_FORMAT);
  1114. /* Configure register related to CUV information */
  1115. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  1116. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  1117. | HDMI_I2S_COPYRIGHT
  1118. | HDMI_I2S_LINEAR_PCM
  1119. | HDMI_I2S_CONSUMER_FORMAT);
  1120. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  1121. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  1122. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  1123. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  1124. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  1125. HDMI_I2S_ORG_SMP_FREQ_44_1
  1126. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  1127. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  1128. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  1129. }
  1130. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  1131. {
  1132. if (hdata->dvi_mode)
  1133. return;
  1134. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  1135. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  1136. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  1137. }
  1138. static void hdmi_start(struct hdmi_context *hdata, bool start)
  1139. {
  1140. u32 val = start ? HDMI_TG_EN : 0;
  1141. if (hdata->current_mode.flags & DRM_MODE_FLAG_INTERLACE)
  1142. val |= HDMI_FIELD_EN;
  1143. hdmi_reg_writemask(hdata, HDMI_CON_0, val, HDMI_EN);
  1144. hdmi_reg_writemask(hdata, HDMI_TG_CMD, val, HDMI_TG_EN | HDMI_FIELD_EN);
  1145. }
  1146. static void hdmi_conf_init(struct hdmi_context *hdata)
  1147. {
  1148. union hdmi_infoframe infoframe;
  1149. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  1150. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  1151. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  1152. /* choose HDMI mode */
  1153. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1154. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  1155. /* Apply Video preable and Guard band in HDMI mode only */
  1156. hdmi_reg_writeb(hdata, HDMI_CON_2, 0);
  1157. /* disable bluescreen */
  1158. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  1159. if (hdata->dvi_mode) {
  1160. /* choose DVI mode */
  1161. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1162. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  1163. hdmi_reg_writeb(hdata, HDMI_CON_2,
  1164. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  1165. }
  1166. if (hdata->drv_data->type == HDMI_TYPE13) {
  1167. /* choose bluescreen (fecal) color */
  1168. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  1169. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1170. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1171. /* enable AVI packet every vsync, fixes purple line problem */
  1172. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1173. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1174. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1175. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1176. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1177. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1178. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1179. } else {
  1180. infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
  1181. infoframe.any.version = HDMI_AVI_VERSION;
  1182. infoframe.any.length = HDMI_AVI_LENGTH;
  1183. hdmi_reg_infoframe(hdata, &infoframe);
  1184. infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
  1185. infoframe.any.version = HDMI_AUI_VERSION;
  1186. infoframe.any.length = HDMI_AUI_LENGTH;
  1187. hdmi_reg_infoframe(hdata, &infoframe);
  1188. /* enable AVI packet every vsync, fixes purple line problem */
  1189. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1190. }
  1191. }
  1192. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  1193. {
  1194. struct drm_display_mode *m = &hdata->current_mode;
  1195. unsigned int val;
  1196. int tries;
  1197. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1198. hdmi_reg_writev(hdata, HDMI_V13_H_V_LINE_0, 3,
  1199. (m->htotal << 12) | m->vtotal);
  1200. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1201. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1, val);
  1202. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1203. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1, val);
  1204. val = (m->hsync_start - m->hdisplay - 2);
  1205. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1206. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1207. hdmi_reg_writev(hdata, HDMI_V13_H_SYNC_GEN_0, 3, val);
  1208. /*
  1209. * Quirk requirement for exynos HDMI IP design,
  1210. * 2 pixels less than the actual calculation for hsync_start
  1211. * and end.
  1212. */
  1213. /* Following values & calculations differ for different type of modes */
  1214. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1215. /* Interlaced Mode */
  1216. val = ((m->vsync_end - m->vdisplay) / 2);
  1217. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1218. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1219. val = m->vtotal / 2;
  1220. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1221. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1222. val = (m->vtotal +
  1223. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1224. val |= m->vtotal << 11;
  1225. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, val);
  1226. val = ((m->vtotal / 2) + 7);
  1227. val |= ((m->vtotal / 2) + 2) << 12;
  1228. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, val);
  1229. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1230. val |= ((m->htotal / 2) +
  1231. (m->hsync_start - m->hdisplay)) << 12;
  1232. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, val);
  1233. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1234. (m->vtotal - m->vdisplay) / 2);
  1235. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1236. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x249);
  1237. } else {
  1238. /* Progressive Mode */
  1239. val = m->vtotal;
  1240. val |= (m->vtotal - m->vdisplay) << 11;
  1241. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1242. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, 0);
  1243. val = (m->vsync_end - m->vdisplay);
  1244. val |= ((m->vsync_start - m->vdisplay) << 12);
  1245. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1246. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, 0x1001);
  1247. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, 0x1001);
  1248. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1249. m->vtotal - m->vdisplay);
  1250. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1251. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x248);
  1252. }
  1253. /* Timing generator registers */
  1254. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1255. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1256. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1257. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1258. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_L, 2, 0x1);
  1259. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2, 0x233);
  1260. hdmi_reg_writev(hdata, HDMI_TG_FIELD_CHG_L, 2, 0x233);
  1261. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, 2, 0x1);
  1262. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2, 0x233);
  1263. hdmi_reg_writev(hdata, HDMI_TG_FIELD_TOP_HDMI_L, 2, 0x1);
  1264. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2, 0x233);
  1265. /* waiting for HDMIPHY's PLL to get to steady state */
  1266. for (tries = 100; tries; --tries) {
  1267. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  1268. if (val & HDMI_PHY_STATUS_READY)
  1269. break;
  1270. usleep_range(1000, 2000);
  1271. }
  1272. /* steady state not achieved */
  1273. if (tries == 0) {
  1274. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1275. hdmi_regs_dump(hdata, "timing apply");
  1276. }
  1277. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1278. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1279. clk_prepare_enable(hdata->res.sclk_hdmi);
  1280. /* enable HDMI and timing generator */
  1281. hdmi_start(hdata, true);
  1282. }
  1283. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1284. {
  1285. struct drm_display_mode *m = &hdata->current_mode;
  1286. int tries;
  1287. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1288. hdmi_reg_writev(hdata, HDMI_V_LINE_0, 2, m->vtotal);
  1289. hdmi_reg_writev(hdata, HDMI_H_LINE_0, 2, m->htotal);
  1290. hdmi_reg_writev(hdata, HDMI_HSYNC_POL, 1,
  1291. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1292. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1,
  1293. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1294. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1,
  1295. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1296. /*
  1297. * Quirk requirement for exynos 5 HDMI IP design,
  1298. * 2 pixels less than the actual calculation for hsync_start
  1299. * and end.
  1300. */
  1301. /* Following values & calculations differ for different type of modes */
  1302. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1303. /* Interlaced Mode */
  1304. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1305. (m->vsync_end - m->vdisplay) / 2);
  1306. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1307. (m->vsync_start - m->vdisplay) / 2);
  1308. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal / 2);
  1309. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1310. (m->vtotal - m->vdisplay) / 2);
  1311. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2,
  1312. m->vtotal - m->vdisplay / 2);
  1313. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, m->vtotal);
  1314. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2,
  1315. (m->vtotal / 2) + 7);
  1316. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2,
  1317. (m->vtotal / 2) + 2);
  1318. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2,
  1319. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1320. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2,
  1321. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1322. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1323. (m->vtotal - m->vdisplay) / 2);
  1324. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1325. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2,
  1326. m->vtotal - m->vdisplay / 2);
  1327. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2,
  1328. (m->vtotal / 2) + 1);
  1329. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2,
  1330. (m->vtotal / 2) + 1);
  1331. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2,
  1332. (m->vtotal / 2) + 1);
  1333. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST3_L, 2, 0x0);
  1334. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST4_L, 2, 0x0);
  1335. } else {
  1336. /* Progressive Mode */
  1337. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1338. m->vsync_end - m->vdisplay);
  1339. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1340. m->vsync_start - m->vdisplay);
  1341. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal);
  1342. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1343. m->vtotal - m->vdisplay);
  1344. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2, 0xffff);
  1345. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, 0xffff);
  1346. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2, 0xffff);
  1347. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2, 0xffff);
  1348. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2, 0xffff);
  1349. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2, 0xffff);
  1350. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1351. m->vtotal - m->vdisplay);
  1352. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1353. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x248);
  1354. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST3_L, 2, 0x47b);
  1355. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST4_L, 2, 0x6ae);
  1356. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2, 0x233);
  1357. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2, 0x233);
  1358. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2, 0x233);
  1359. }
  1360. /* Following values & calculations are same irrespective of mode type */
  1361. hdmi_reg_writev(hdata, HDMI_H_SYNC_START_0, 2,
  1362. m->hsync_start - m->hdisplay - 2);
  1363. hdmi_reg_writev(hdata, HDMI_H_SYNC_END_0, 2,
  1364. m->hsync_end - m->hdisplay - 2);
  1365. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_1_0, 2, 0xffff);
  1366. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_2_0, 2, 0xffff);
  1367. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_3_0, 2, 0xffff);
  1368. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_4_0, 2, 0xffff);
  1369. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_5_0, 2, 0xffff);
  1370. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_6_0, 2, 0xffff);
  1371. hdmi_reg_writev(hdata, HDMI_V_BLANK_F2_0, 2, 0xffff);
  1372. hdmi_reg_writev(hdata, HDMI_V_BLANK_F3_0, 2, 0xffff);
  1373. hdmi_reg_writev(hdata, HDMI_V_BLANK_F4_0, 2, 0xffff);
  1374. hdmi_reg_writev(hdata, HDMI_V_BLANK_F5_0, 2, 0xffff);
  1375. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_3_0, 2, 0xffff);
  1376. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_4_0, 2, 0xffff);
  1377. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_5_0, 2, 0xffff);
  1378. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_6_0, 2, 0xffff);
  1379. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0, 2, 0xffff);
  1380. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0, 2, 0xffff);
  1381. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0, 2, 0xffff);
  1382. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0, 2, 0xffff);
  1383. /* Timing generator registers */
  1384. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1385. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1386. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1387. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1388. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_L, 2, 0x1);
  1389. hdmi_reg_writev(hdata, HDMI_TG_FIELD_CHG_L, 2, 0x233);
  1390. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, 2, 0x1);
  1391. hdmi_reg_writev(hdata, HDMI_TG_FIELD_TOP_HDMI_L, 2, 0x1);
  1392. hdmi_reg_writev(hdata, HDMI_TG_3D, 1, 0x0);
  1393. /* waiting for HDMIPHY's PLL to get to steady state */
  1394. for (tries = 100; tries; --tries) {
  1395. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1396. if (val & HDMI_PHY_STATUS_READY)
  1397. break;
  1398. usleep_range(1000, 2000);
  1399. }
  1400. /* steady state not achieved */
  1401. if (tries == 0) {
  1402. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1403. hdmi_regs_dump(hdata, "timing apply");
  1404. }
  1405. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1406. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1407. clk_prepare_enable(hdata->res.sclk_hdmi);
  1408. /* enable HDMI and timing generator */
  1409. hdmi_start(hdata, true);
  1410. }
  1411. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1412. {
  1413. if (hdata->drv_data->type == HDMI_TYPE13)
  1414. hdmi_v13_mode_apply(hdata);
  1415. else
  1416. hdmi_v14_mode_apply(hdata);
  1417. }
  1418. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1419. {
  1420. u32 reg;
  1421. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1422. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1423. clk_prepare_enable(hdata->res.sclk_hdmi);
  1424. /* operation mode */
  1425. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1426. HDMI_PHY_ENABLE_MODE_SET);
  1427. if (hdata->drv_data->type == HDMI_TYPE13)
  1428. reg = HDMI_V13_PHY_RSTOUT;
  1429. else
  1430. reg = HDMI_PHY_RSTOUT;
  1431. /* reset hdmiphy */
  1432. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1433. usleep_range(10000, 12000);
  1434. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1435. usleep_range(10000, 12000);
  1436. }
  1437. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1438. {
  1439. if (hdata->drv_data->type != HDMI_TYPE14)
  1440. return;
  1441. DRM_DEBUG_KMS("\n");
  1442. /* For PHY Mode Setting */
  1443. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1444. HDMI_PHY_ENABLE_MODE_SET);
  1445. /* Phy Power On */
  1446. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1447. HDMI_PHY_POWER_ON);
  1448. /* For PHY Mode Setting */
  1449. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1450. HDMI_PHY_DISABLE_MODE_SET);
  1451. /* PHY SW Reset */
  1452. hdmiphy_conf_reset(hdata);
  1453. }
  1454. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1455. {
  1456. if (hdata->drv_data->type != HDMI_TYPE14)
  1457. return;
  1458. DRM_DEBUG_KMS("\n");
  1459. /* PHY SW Reset */
  1460. hdmiphy_conf_reset(hdata);
  1461. /* For PHY Mode Setting */
  1462. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1463. HDMI_PHY_ENABLE_MODE_SET);
  1464. /* PHY Power Off */
  1465. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1466. HDMI_PHY_POWER_OFF);
  1467. /* For PHY Mode Setting */
  1468. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1469. HDMI_PHY_DISABLE_MODE_SET);
  1470. }
  1471. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1472. {
  1473. int ret;
  1474. int i;
  1475. /* pixel clock */
  1476. i = hdmi_find_phy_conf(hdata, hdata->current_mode.clock * 1000);
  1477. if (i < 0) {
  1478. DRM_ERROR("failed to find hdmiphy conf\n");
  1479. return;
  1480. }
  1481. ret = hdmiphy_reg_write_buf(hdata, 0,
  1482. hdata->drv_data->phy_confs[i].conf, 32);
  1483. if (ret) {
  1484. DRM_ERROR("failed to configure hdmiphy\n");
  1485. return;
  1486. }
  1487. usleep_range(10000, 12000);
  1488. ret = hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1489. HDMI_PHY_DISABLE_MODE_SET);
  1490. if (ret) {
  1491. DRM_ERROR("failed to enable hdmiphy\n");
  1492. return;
  1493. }
  1494. }
  1495. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1496. {
  1497. hdmiphy_conf_reset(hdata);
  1498. hdmiphy_conf_apply(hdata);
  1499. hdmi_start(hdata, false);
  1500. hdmi_conf_init(hdata);
  1501. hdmi_audio_init(hdata);
  1502. /* setting core registers */
  1503. hdmi_mode_apply(hdata);
  1504. hdmi_audio_control(hdata, true);
  1505. hdmi_regs_dump(hdata, "start");
  1506. }
  1507. static void hdmi_mode_set(struct drm_encoder *encoder,
  1508. struct drm_display_mode *mode,
  1509. struct drm_display_mode *adjusted_mode)
  1510. {
  1511. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1512. struct drm_display_mode *m = adjusted_mode;
  1513. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1514. m->hdisplay, m->vdisplay,
  1515. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1516. "INTERLACED" : "PROGRESSIVE");
  1517. drm_mode_copy(&hdata->current_mode, m);
  1518. hdata->cea_video_id = drm_match_cea_mode(mode);
  1519. }
  1520. static void hdmi_enable(struct drm_encoder *encoder)
  1521. {
  1522. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1523. struct hdmi_resources *res = &hdata->res;
  1524. if (hdata->powered)
  1525. return;
  1526. hdata->powered = true;
  1527. pm_runtime_get_sync(hdata->dev);
  1528. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1529. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1530. /* set pmu hdmiphy control bit to enable hdmiphy */
  1531. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1532. PMU_HDMI_PHY_ENABLE_BIT, 1);
  1533. clk_prepare_enable(res->hdmi);
  1534. clk_prepare_enable(res->sclk_hdmi);
  1535. hdmiphy_poweron(hdata);
  1536. hdmi_conf_apply(hdata);
  1537. }
  1538. static void hdmi_disable(struct drm_encoder *encoder)
  1539. {
  1540. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1541. struct hdmi_resources *res = &hdata->res;
  1542. struct drm_crtc *crtc = encoder->crtc;
  1543. const struct drm_crtc_helper_funcs *funcs = NULL;
  1544. if (!hdata->powered)
  1545. return;
  1546. /*
  1547. * The SFRs of VP and Mixer are updated by Vertical Sync of
  1548. * Timing generator which is a part of HDMI so the sequence
  1549. * to disable TV Subsystem should be as following,
  1550. * VP -> Mixer -> HDMI
  1551. *
  1552. * Below codes will try to disable Mixer and VP(if used)
  1553. * prior to disabling HDMI.
  1554. */
  1555. if (crtc)
  1556. funcs = crtc->helper_private;
  1557. if (funcs && funcs->disable)
  1558. (*funcs->disable)(crtc);
  1559. /* HDMI System Disable */
  1560. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_EN);
  1561. hdmiphy_poweroff(hdata);
  1562. cancel_delayed_work(&hdata->hotplug_work);
  1563. clk_disable_unprepare(res->sclk_hdmi);
  1564. clk_disable_unprepare(res->hdmi);
  1565. /* reset pmu hdmiphy control bit to disable hdmiphy */
  1566. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1567. PMU_HDMI_PHY_ENABLE_BIT, 0);
  1568. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1569. pm_runtime_put_sync(hdata->dev);
  1570. hdata->powered = false;
  1571. }
  1572. static struct drm_encoder_helper_funcs exynos_hdmi_encoder_helper_funcs = {
  1573. .mode_fixup = hdmi_mode_fixup,
  1574. .mode_set = hdmi_mode_set,
  1575. .enable = hdmi_enable,
  1576. .disable = hdmi_disable,
  1577. };
  1578. static struct drm_encoder_funcs exynos_hdmi_encoder_funcs = {
  1579. .destroy = drm_encoder_cleanup,
  1580. };
  1581. static void hdmi_hotplug_work_func(struct work_struct *work)
  1582. {
  1583. struct hdmi_context *hdata;
  1584. hdata = container_of(work, struct hdmi_context, hotplug_work.work);
  1585. if (hdata->drm_dev)
  1586. drm_helper_hpd_irq_event(hdata->drm_dev);
  1587. }
  1588. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1589. {
  1590. struct hdmi_context *hdata = arg;
  1591. mod_delayed_work(system_wq, &hdata->hotplug_work,
  1592. msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
  1593. return IRQ_HANDLED;
  1594. }
  1595. static int hdmi_resources_init(struct hdmi_context *hdata)
  1596. {
  1597. struct device *dev = hdata->dev;
  1598. struct hdmi_resources *res = &hdata->res;
  1599. static char *supply[] = {
  1600. "vdd",
  1601. "vdd_osc",
  1602. "vdd_pll",
  1603. };
  1604. int i, ret;
  1605. DRM_DEBUG_KMS("HDMI resource init\n");
  1606. /* get clocks, power */
  1607. res->hdmi = devm_clk_get(dev, "hdmi");
  1608. if (IS_ERR(res->hdmi)) {
  1609. DRM_ERROR("failed to get clock 'hdmi'\n");
  1610. ret = PTR_ERR(res->hdmi);
  1611. goto fail;
  1612. }
  1613. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1614. if (IS_ERR(res->sclk_hdmi)) {
  1615. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1616. ret = PTR_ERR(res->sclk_hdmi);
  1617. goto fail;
  1618. }
  1619. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1620. if (IS_ERR(res->sclk_pixel)) {
  1621. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1622. ret = PTR_ERR(res->sclk_pixel);
  1623. goto fail;
  1624. }
  1625. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1626. if (IS_ERR(res->sclk_hdmiphy)) {
  1627. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1628. ret = PTR_ERR(res->sclk_hdmiphy);
  1629. goto fail;
  1630. }
  1631. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1632. if (IS_ERR(res->mout_hdmi)) {
  1633. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1634. ret = PTR_ERR(res->mout_hdmi);
  1635. goto fail;
  1636. }
  1637. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1638. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1639. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1640. if (!res->regul_bulk) {
  1641. ret = -ENOMEM;
  1642. goto fail;
  1643. }
  1644. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1645. res->regul_bulk[i].supply = supply[i];
  1646. res->regul_bulk[i].consumer = NULL;
  1647. }
  1648. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1649. if (ret) {
  1650. DRM_ERROR("failed to get regulators\n");
  1651. return ret;
  1652. }
  1653. res->regul_count = ARRAY_SIZE(supply);
  1654. res->reg_hdmi_en = devm_regulator_get(dev, "hdmi-en");
  1655. if (IS_ERR(res->reg_hdmi_en) && PTR_ERR(res->reg_hdmi_en) != -ENOENT) {
  1656. DRM_ERROR("failed to get hdmi-en regulator\n");
  1657. return PTR_ERR(res->reg_hdmi_en);
  1658. }
  1659. if (!IS_ERR(res->reg_hdmi_en)) {
  1660. ret = regulator_enable(res->reg_hdmi_en);
  1661. if (ret) {
  1662. DRM_ERROR("failed to enable hdmi-en regulator\n");
  1663. return ret;
  1664. }
  1665. } else
  1666. res->reg_hdmi_en = NULL;
  1667. return ret;
  1668. fail:
  1669. DRM_ERROR("HDMI resource init - failed\n");
  1670. return ret;
  1671. }
  1672. static struct of_device_id hdmi_match_types[] = {
  1673. {
  1674. .compatible = "samsung,exynos5-hdmi",
  1675. .data = &exynos5_hdmi_driver_data,
  1676. }, {
  1677. .compatible = "samsung,exynos4210-hdmi",
  1678. .data = &exynos4210_hdmi_driver_data,
  1679. }, {
  1680. .compatible = "samsung,exynos4212-hdmi",
  1681. .data = &exynos4212_hdmi_driver_data,
  1682. }, {
  1683. .compatible = "samsung,exynos5420-hdmi",
  1684. .data = &exynos5420_hdmi_driver_data,
  1685. }, {
  1686. /* end node */
  1687. }
  1688. };
  1689. MODULE_DEVICE_TABLE (of, hdmi_match_types);
  1690. static int hdmi_bind(struct device *dev, struct device *master, void *data)
  1691. {
  1692. struct drm_device *drm_dev = data;
  1693. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1694. struct drm_encoder *encoder = &hdata->encoder;
  1695. int ret, pipe;
  1696. hdata->drm_dev = drm_dev;
  1697. pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
  1698. EXYNOS_DISPLAY_TYPE_HDMI);
  1699. if (pipe < 0)
  1700. return pipe;
  1701. encoder->possible_crtcs = 1 << pipe;
  1702. DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
  1703. drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs,
  1704. DRM_MODE_ENCODER_TMDS);
  1705. drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs);
  1706. ret = hdmi_create_connector(encoder);
  1707. if (ret) {
  1708. DRM_ERROR("failed to create connector ret = %d\n", ret);
  1709. drm_encoder_cleanup(encoder);
  1710. return ret;
  1711. }
  1712. return 0;
  1713. }
  1714. static void hdmi_unbind(struct device *dev, struct device *master, void *data)
  1715. {
  1716. }
  1717. static const struct component_ops hdmi_component_ops = {
  1718. .bind = hdmi_bind,
  1719. .unbind = hdmi_unbind,
  1720. };
  1721. static struct device_node *hdmi_legacy_ddc_dt_binding(struct device *dev)
  1722. {
  1723. const char *compatible_str = "samsung,exynos4210-hdmiddc";
  1724. struct device_node *np;
  1725. np = of_find_compatible_node(NULL, NULL, compatible_str);
  1726. if (np)
  1727. return of_get_next_parent(np);
  1728. return NULL;
  1729. }
  1730. static struct device_node *hdmi_legacy_phy_dt_binding(struct device *dev)
  1731. {
  1732. const char *compatible_str = "samsung,exynos4212-hdmiphy";
  1733. return of_find_compatible_node(NULL, NULL, compatible_str);
  1734. }
  1735. static int hdmi_probe(struct platform_device *pdev)
  1736. {
  1737. struct device_node *ddc_node, *phy_node;
  1738. const struct of_device_id *match;
  1739. struct device *dev = &pdev->dev;
  1740. struct hdmi_context *hdata;
  1741. struct resource *res;
  1742. int ret;
  1743. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  1744. if (!hdata)
  1745. return -ENOMEM;
  1746. match = of_match_device(hdmi_match_types, dev);
  1747. if (!match)
  1748. return -ENODEV;
  1749. hdata->drv_data = match->data;
  1750. platform_set_drvdata(pdev, hdata);
  1751. hdata->dev = dev;
  1752. hdata->hpd_gpio = of_get_named_gpio(dev->of_node, "hpd-gpio", 0);
  1753. if (hdata->hpd_gpio < 0) {
  1754. DRM_ERROR("cannot get hpd gpio property\n");
  1755. return hdata->hpd_gpio;
  1756. }
  1757. ret = hdmi_resources_init(hdata);
  1758. if (ret) {
  1759. DRM_ERROR("hdmi_resources_init failed\n");
  1760. return ret;
  1761. }
  1762. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1763. hdata->regs = devm_ioremap_resource(dev, res);
  1764. if (IS_ERR(hdata->regs)) {
  1765. ret = PTR_ERR(hdata->regs);
  1766. return ret;
  1767. }
  1768. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  1769. if (ret) {
  1770. DRM_ERROR("failed to request HPD gpio\n");
  1771. return ret;
  1772. }
  1773. ddc_node = hdmi_legacy_ddc_dt_binding(dev);
  1774. if (ddc_node)
  1775. goto out_get_ddc_adpt;
  1776. /* DDC i2c driver */
  1777. ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
  1778. if (!ddc_node) {
  1779. DRM_ERROR("Failed to find ddc node in device tree\n");
  1780. return -ENODEV;
  1781. }
  1782. out_get_ddc_adpt:
  1783. hdata->ddc_adpt = of_find_i2c_adapter_by_node(ddc_node);
  1784. if (!hdata->ddc_adpt) {
  1785. DRM_ERROR("Failed to get ddc i2c adapter by node\n");
  1786. return -EPROBE_DEFER;
  1787. }
  1788. phy_node = hdmi_legacy_phy_dt_binding(dev);
  1789. if (phy_node)
  1790. goto out_get_phy_port;
  1791. /* hdmiphy i2c driver */
  1792. phy_node = of_parse_phandle(dev->of_node, "phy", 0);
  1793. if (!phy_node) {
  1794. DRM_ERROR("Failed to find hdmiphy node in device tree\n");
  1795. ret = -ENODEV;
  1796. goto err_ddc;
  1797. }
  1798. out_get_phy_port:
  1799. if (hdata->drv_data->is_apb_phy) {
  1800. hdata->regs_hdmiphy = of_iomap(phy_node, 0);
  1801. if (!hdata->regs_hdmiphy) {
  1802. DRM_ERROR("failed to ioremap hdmi phy\n");
  1803. ret = -ENOMEM;
  1804. goto err_ddc;
  1805. }
  1806. } else {
  1807. hdata->hdmiphy_port = of_find_i2c_device_by_node(phy_node);
  1808. if (!hdata->hdmiphy_port) {
  1809. DRM_ERROR("Failed to get hdmi phy i2c client\n");
  1810. ret = -EPROBE_DEFER;
  1811. goto err_ddc;
  1812. }
  1813. }
  1814. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  1815. if (hdata->irq < 0) {
  1816. DRM_ERROR("failed to get GPIO irq\n");
  1817. ret = hdata->irq;
  1818. goto err_hdmiphy;
  1819. }
  1820. INIT_DELAYED_WORK(&hdata->hotplug_work, hdmi_hotplug_work_func);
  1821. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1822. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1823. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1824. "hdmi", hdata);
  1825. if (ret) {
  1826. DRM_ERROR("failed to register hdmi interrupt\n");
  1827. goto err_hdmiphy;
  1828. }
  1829. hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  1830. "samsung,syscon-phandle");
  1831. if (IS_ERR(hdata->pmureg)) {
  1832. DRM_ERROR("syscon regmap lookup failed.\n");
  1833. ret = -EPROBE_DEFER;
  1834. goto err_hdmiphy;
  1835. }
  1836. pm_runtime_enable(dev);
  1837. ret = component_add(&pdev->dev, &hdmi_component_ops);
  1838. if (ret)
  1839. goto err_disable_pm_runtime;
  1840. return ret;
  1841. err_disable_pm_runtime:
  1842. pm_runtime_disable(dev);
  1843. err_hdmiphy:
  1844. if (hdata->hdmiphy_port)
  1845. put_device(&hdata->hdmiphy_port->dev);
  1846. err_ddc:
  1847. put_device(&hdata->ddc_adpt->dev);
  1848. return ret;
  1849. }
  1850. static int hdmi_remove(struct platform_device *pdev)
  1851. {
  1852. struct hdmi_context *hdata = platform_get_drvdata(pdev);
  1853. cancel_delayed_work_sync(&hdata->hotplug_work);
  1854. if (hdata->res.reg_hdmi_en)
  1855. regulator_disable(hdata->res.reg_hdmi_en);
  1856. if (hdata->hdmiphy_port)
  1857. put_device(&hdata->hdmiphy_port->dev);
  1858. put_device(&hdata->ddc_adpt->dev);
  1859. pm_runtime_disable(&pdev->dev);
  1860. component_del(&pdev->dev, &hdmi_component_ops);
  1861. return 0;
  1862. }
  1863. struct platform_driver hdmi_driver = {
  1864. .probe = hdmi_probe,
  1865. .remove = hdmi_remove,
  1866. .driver = {
  1867. .name = "exynos-hdmi",
  1868. .owner = THIS_MODULE,
  1869. .of_match_table = hdmi_match_types,
  1870. },
  1871. };