exynos_hdmi.c 67 KB

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