exynos_hdmi.c 70 KB

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