exynos_hdmi.c 62 KB

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