exynos_hdmi.c 67 KB

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