exynos_hdmi.c 69 KB

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