exynos_hdmi.c 72 KB

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