exynos_hdmi.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151
  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/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/clk.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/io.h>
  32. #include <linux/of_gpio.h>
  33. #include <drm/exynos_drm.h>
  34. #include "exynos_drm_drv.h"
  35. #include "exynos_drm_hdmi.h"
  36. #include "exynos_hdmi.h"
  37. #include <linux/gpio.h>
  38. #include <media/s5p_hdmi.h>
  39. #define MAX_WIDTH 1920
  40. #define MAX_HEIGHT 1080
  41. #define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
  42. /* AVI header and aspect ratio */
  43. #define HDMI_AVI_VERSION 0x02
  44. #define HDMI_AVI_LENGTH 0x0D
  45. #define AVI_PIC_ASPECT_RATIO_16_9 (2 << 4)
  46. #define AVI_SAME_AS_PIC_ASPECT_RATIO 8
  47. /* AUI header info */
  48. #define HDMI_AUI_VERSION 0x01
  49. #define HDMI_AUI_LENGTH 0x0A
  50. /* HDMI infoframe to configure HDMI out packet header, AUI and AVI */
  51. enum HDMI_PACKET_TYPE {
  52. /* refer to Table 5-8 Packet Type in HDMI specification v1.4a */
  53. /* InfoFrame packet type */
  54. HDMI_PACKET_TYPE_INFOFRAME = 0x80,
  55. /* Vendor-Specific InfoFrame */
  56. HDMI_PACKET_TYPE_VSI = HDMI_PACKET_TYPE_INFOFRAME + 1,
  57. /* Auxiliary Video information InfoFrame */
  58. HDMI_PACKET_TYPE_AVI = HDMI_PACKET_TYPE_INFOFRAME + 2,
  59. /* Audio information InfoFrame */
  60. HDMI_PACKET_TYPE_AUI = HDMI_PACKET_TYPE_INFOFRAME + 4
  61. };
  62. enum hdmi_type {
  63. HDMI_TYPE13,
  64. HDMI_TYPE14,
  65. };
  66. struct hdmi_resources {
  67. struct clk *hdmi;
  68. struct clk *sclk_hdmi;
  69. struct clk *sclk_pixel;
  70. struct clk *sclk_hdmiphy;
  71. struct clk *hdmiphy;
  72. struct clk *mout_hdmi;
  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. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  633. if (hdata->dvi_mode) {
  634. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  635. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  636. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  637. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  638. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  639. return;
  640. }
  641. switch (infoframe->type) {
  642. case HDMI_PACKET_TYPE_AVI:
  643. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  644. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->type);
  645. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1, infoframe->ver);
  646. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->len);
  647. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  648. /* Output format zero hardcoded ,RGB YBCR selection */
  649. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  650. AVI_ACTIVE_FORMAT_VALID |
  651. AVI_UNDERSCANNED_DISPLAY_VALID);
  652. aspect_ratio = AVI_PIC_ASPECT_RATIO_16_9;
  653. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), aspect_ratio |
  654. AVI_SAME_AS_PIC_ASPECT_RATIO);
  655. vic = hdata->mode_conf.cea_video_id;
  656. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  657. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  658. infoframe->len, hdr_sum);
  659. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  660. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  661. break;
  662. case HDMI_PACKET_TYPE_AUI:
  663. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  664. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->type);
  665. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1, infoframe->ver);
  666. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->len);
  667. hdr_sum = infoframe->type + infoframe->ver + infoframe->len;
  668. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  669. infoframe->len, hdr_sum);
  670. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  671. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  672. break;
  673. default:
  674. break;
  675. }
  676. }
  677. static bool hdmi_is_connected(void *ctx)
  678. {
  679. struct hdmi_context *hdata = ctx;
  680. return hdata->hpd;
  681. }
  682. static struct edid *hdmi_get_edid(void *ctx, struct drm_connector *connector)
  683. {
  684. struct edid *raw_edid;
  685. struct hdmi_context *hdata = ctx;
  686. if (!hdata->ddc_port)
  687. return ERR_PTR(-ENODEV);
  688. raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
  689. if (!raw_edid)
  690. return ERR_PTR(-ENODEV);
  691. hdata->dvi_mode = !drm_detect_hdmi_monitor(raw_edid);
  692. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  693. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  694. raw_edid->width_cm, raw_edid->height_cm);
  695. return raw_edid;
  696. }
  697. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  698. {
  699. const struct hdmiphy_config *confs;
  700. int count, i;
  701. if (hdata->type == HDMI_TYPE13) {
  702. confs = hdmiphy_v13_configs;
  703. count = ARRAY_SIZE(hdmiphy_v13_configs);
  704. } else if (hdata->type == HDMI_TYPE14) {
  705. confs = hdmiphy_v14_configs;
  706. count = ARRAY_SIZE(hdmiphy_v14_configs);
  707. } else
  708. return -EINVAL;
  709. for (i = 0; i < count; i++)
  710. if (confs[i].pixel_clock == pixel_clock)
  711. return i;
  712. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  713. return -EINVAL;
  714. }
  715. static int hdmi_check_mode(void *ctx, struct drm_display_mode *mode)
  716. {
  717. struct hdmi_context *hdata = ctx;
  718. int ret;
  719. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  720. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  721. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  722. false, mode->clock * 1000);
  723. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  724. if (ret < 0)
  725. return ret;
  726. return 0;
  727. }
  728. static void hdmi_set_acr(u32 freq, u8 *acr)
  729. {
  730. u32 n, cts;
  731. switch (freq) {
  732. case 32000:
  733. n = 4096;
  734. cts = 27000;
  735. break;
  736. case 44100:
  737. n = 6272;
  738. cts = 30000;
  739. break;
  740. case 88200:
  741. n = 12544;
  742. cts = 30000;
  743. break;
  744. case 176400:
  745. n = 25088;
  746. cts = 30000;
  747. break;
  748. case 48000:
  749. n = 6144;
  750. cts = 27000;
  751. break;
  752. case 96000:
  753. n = 12288;
  754. cts = 27000;
  755. break;
  756. case 192000:
  757. n = 24576;
  758. cts = 27000;
  759. break;
  760. default:
  761. n = 0;
  762. cts = 0;
  763. break;
  764. }
  765. acr[1] = cts >> 16;
  766. acr[2] = cts >> 8 & 0xff;
  767. acr[3] = cts & 0xff;
  768. acr[4] = n >> 16;
  769. acr[5] = n >> 8 & 0xff;
  770. acr[6] = n & 0xff;
  771. }
  772. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  773. {
  774. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  775. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  776. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  777. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  778. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  779. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  780. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  781. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  782. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  783. if (hdata->type == HDMI_TYPE13)
  784. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  785. else
  786. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  787. }
  788. static void hdmi_audio_init(struct hdmi_context *hdata)
  789. {
  790. u32 sample_rate, bits_per_sample, frame_size_code;
  791. u32 data_num, bit_ch, sample_frq;
  792. u32 val;
  793. u8 acr[7];
  794. sample_rate = 44100;
  795. bits_per_sample = 16;
  796. frame_size_code = 0;
  797. switch (bits_per_sample) {
  798. case 20:
  799. data_num = 2;
  800. bit_ch = 1;
  801. break;
  802. case 24:
  803. data_num = 3;
  804. bit_ch = 1;
  805. break;
  806. default:
  807. data_num = 1;
  808. bit_ch = 0;
  809. break;
  810. }
  811. hdmi_set_acr(sample_rate, acr);
  812. hdmi_reg_acr(hdata, acr);
  813. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  814. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  815. | HDMI_I2S_MUX_ENABLE);
  816. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  817. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  818. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  819. sample_frq = (sample_rate == 44100) ? 0 :
  820. (sample_rate == 48000) ? 2 :
  821. (sample_rate == 32000) ? 3 :
  822. (sample_rate == 96000) ? 0xa : 0x0;
  823. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  824. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  825. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  826. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  827. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  828. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  829. | HDMI_I2S_SEL_LRCK(6));
  830. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  831. | HDMI_I2S_SEL_SDATA2(4));
  832. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  833. | HDMI_I2S_SEL_SDATA2(2));
  834. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  835. /* I2S_CON_1 & 2 */
  836. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  837. | HDMI_I2S_L_CH_LOW_POL);
  838. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  839. | HDMI_I2S_SET_BIT_CH(bit_ch)
  840. | HDMI_I2S_SET_SDATA_BIT(data_num)
  841. | HDMI_I2S_BASIC_FORMAT);
  842. /* Configure register related to CUV information */
  843. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  844. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  845. | HDMI_I2S_COPYRIGHT
  846. | HDMI_I2S_LINEAR_PCM
  847. | HDMI_I2S_CONSUMER_FORMAT);
  848. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  849. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  850. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  851. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  852. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  853. HDMI_I2S_ORG_SMP_FREQ_44_1
  854. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  855. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  856. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  857. }
  858. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  859. {
  860. if (hdata->dvi_mode)
  861. return;
  862. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  863. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  864. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  865. }
  866. static void hdmi_conf_reset(struct hdmi_context *hdata)
  867. {
  868. u32 reg;
  869. if (hdata->type == HDMI_TYPE13)
  870. reg = HDMI_V13_CORE_RSTOUT;
  871. else
  872. reg = HDMI_CORE_RSTOUT;
  873. /* resetting HDMI core */
  874. hdmi_reg_writemask(hdata, reg, 0, HDMI_CORE_SW_RSTOUT);
  875. usleep_range(10000, 12000);
  876. hdmi_reg_writemask(hdata, reg, ~0, HDMI_CORE_SW_RSTOUT);
  877. usleep_range(10000, 12000);
  878. }
  879. static void hdmi_conf_init(struct hdmi_context *hdata)
  880. {
  881. struct hdmi_infoframe infoframe;
  882. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  883. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  884. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  885. /* choose HDMI mode */
  886. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  887. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  888. /* disable bluescreen */
  889. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  890. if (hdata->dvi_mode) {
  891. /* choose DVI mode */
  892. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  893. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  894. hdmi_reg_writeb(hdata, HDMI_CON_2,
  895. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  896. }
  897. if (hdata->type == HDMI_TYPE13) {
  898. /* choose bluescreen (fecal) color */
  899. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  900. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  901. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  902. /* enable AVI packet every vsync, fixes purple line problem */
  903. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  904. /* force RGB, look to CEA-861-D, table 7 for more detail */
  905. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  906. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  907. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  908. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  909. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  910. } else {
  911. infoframe.type = HDMI_PACKET_TYPE_AVI;
  912. infoframe.ver = HDMI_AVI_VERSION;
  913. infoframe.len = HDMI_AVI_LENGTH;
  914. hdmi_reg_infoframe(hdata, &infoframe);
  915. infoframe.type = HDMI_PACKET_TYPE_AUI;
  916. infoframe.ver = HDMI_AUI_VERSION;
  917. infoframe.len = HDMI_AUI_LENGTH;
  918. hdmi_reg_infoframe(hdata, &infoframe);
  919. /* enable AVI packet every vsync, fixes purple line problem */
  920. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  921. }
  922. }
  923. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  924. {
  925. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  926. const struct hdmi_v13_core_regs *core =
  927. &hdata->mode_conf.conf.v13_conf.core;
  928. int tries;
  929. /* setting core registers */
  930. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  931. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  932. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  933. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  934. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  935. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  936. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  937. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  938. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  939. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  940. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  941. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  942. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  943. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  944. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  945. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  946. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  947. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  948. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  949. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  950. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  951. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  952. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  953. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  954. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  955. /* Timing generator registers */
  956. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  957. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  958. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  959. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  960. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  961. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  962. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  963. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  964. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  965. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  966. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  967. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  968. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  969. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  970. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  971. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  972. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  973. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  974. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  975. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  976. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  977. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  978. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  979. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  980. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  981. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  982. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  983. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  984. /* waiting for HDMIPHY's PLL to get to steady state */
  985. for (tries = 100; tries; --tries) {
  986. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  987. if (val & HDMI_PHY_STATUS_READY)
  988. break;
  989. usleep_range(1000, 2000);
  990. }
  991. /* steady state not achieved */
  992. if (tries == 0) {
  993. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  994. hdmi_regs_dump(hdata, "timing apply");
  995. }
  996. clk_disable_unprepare(hdata->res.sclk_hdmi);
  997. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  998. clk_prepare_enable(hdata->res.sclk_hdmi);
  999. /* enable HDMI and timing generator */
  1000. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1001. if (core->int_pro_mode[0])
  1002. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1003. HDMI_FIELD_EN);
  1004. else
  1005. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1006. }
  1007. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1008. {
  1009. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1010. const struct hdmi_v14_core_regs *core =
  1011. &hdata->mode_conf.conf.v14_conf.core;
  1012. int tries;
  1013. /* setting core registers */
  1014. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1015. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1016. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1017. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1018. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1019. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1020. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1021. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1022. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1023. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1024. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1025. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1026. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1027. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1028. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1029. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1030. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1031. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1032. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1033. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1034. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1035. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1036. core->v_sync_line_bef_2[0]);
  1037. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1038. core->v_sync_line_bef_2[1]);
  1039. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1040. core->v_sync_line_bef_1[0]);
  1041. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1042. core->v_sync_line_bef_1[1]);
  1043. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1044. core->v_sync_line_aft_2[0]);
  1045. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1046. core->v_sync_line_aft_2[1]);
  1047. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1048. core->v_sync_line_aft_1[0]);
  1049. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1050. core->v_sync_line_aft_1[1]);
  1051. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1052. core->v_sync_line_aft_pxl_2[0]);
  1053. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1054. core->v_sync_line_aft_pxl_2[1]);
  1055. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1056. core->v_sync_line_aft_pxl_1[0]);
  1057. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1058. core->v_sync_line_aft_pxl_1[1]);
  1059. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1060. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1061. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1062. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1063. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1064. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1065. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1066. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1067. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1068. core->v_sync_line_aft_3[0]);
  1069. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1070. core->v_sync_line_aft_3[1]);
  1071. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1072. core->v_sync_line_aft_4[0]);
  1073. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1074. core->v_sync_line_aft_4[1]);
  1075. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1076. core->v_sync_line_aft_5[0]);
  1077. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1078. core->v_sync_line_aft_5[1]);
  1079. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1080. core->v_sync_line_aft_6[0]);
  1081. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1082. core->v_sync_line_aft_6[1]);
  1083. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1084. core->v_sync_line_aft_pxl_3[0]);
  1085. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1086. core->v_sync_line_aft_pxl_3[1]);
  1087. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1088. core->v_sync_line_aft_pxl_4[0]);
  1089. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1090. core->v_sync_line_aft_pxl_4[1]);
  1091. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1092. core->v_sync_line_aft_pxl_5[0]);
  1093. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1094. core->v_sync_line_aft_pxl_5[1]);
  1095. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1096. core->v_sync_line_aft_pxl_6[0]);
  1097. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1098. core->v_sync_line_aft_pxl_6[1]);
  1099. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1100. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1101. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1102. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1103. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1104. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1105. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1106. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1107. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1108. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1109. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1110. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1111. /* Timing generator registers */
  1112. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1113. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1114. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1115. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1116. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1117. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1118. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1119. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1120. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1121. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1122. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1123. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1124. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1125. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1126. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1127. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1128. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1129. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1130. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1131. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1132. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3[0]);
  1133. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3[1]);
  1134. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4[0]);
  1135. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4[1]);
  1136. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1137. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1138. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1139. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1140. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1141. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1142. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1143. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1144. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d[0]);
  1145. /* waiting for HDMIPHY's PLL to get to steady state */
  1146. for (tries = 100; tries; --tries) {
  1147. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1148. if (val & HDMI_PHY_STATUS_READY)
  1149. break;
  1150. usleep_range(1000, 2000);
  1151. }
  1152. /* steady state not achieved */
  1153. if (tries == 0) {
  1154. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1155. hdmi_regs_dump(hdata, "timing apply");
  1156. }
  1157. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1158. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1159. clk_prepare_enable(hdata->res.sclk_hdmi);
  1160. /* enable HDMI and timing generator */
  1161. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1162. if (core->int_pro_mode[0])
  1163. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1164. HDMI_FIELD_EN);
  1165. else
  1166. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1167. }
  1168. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1169. {
  1170. if (hdata->type == HDMI_TYPE13)
  1171. hdmi_v13_mode_apply(hdata);
  1172. else
  1173. hdmi_v14_mode_apply(hdata);
  1174. }
  1175. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1176. {
  1177. u8 buffer[2];
  1178. u32 reg;
  1179. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1180. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1181. clk_prepare_enable(hdata->res.sclk_hdmi);
  1182. /* operation mode */
  1183. buffer[0] = 0x1f;
  1184. buffer[1] = 0x00;
  1185. if (hdata->hdmiphy_port)
  1186. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1187. if (hdata->type == HDMI_TYPE13)
  1188. reg = HDMI_V13_PHY_RSTOUT;
  1189. else
  1190. reg = HDMI_PHY_RSTOUT;
  1191. /* reset hdmiphy */
  1192. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1193. usleep_range(10000, 12000);
  1194. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1195. usleep_range(10000, 12000);
  1196. }
  1197. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1198. {
  1199. if (hdata->type == HDMI_TYPE14)
  1200. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, 0,
  1201. HDMI_PHY_POWER_OFF_EN);
  1202. }
  1203. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1204. {
  1205. if (hdata->type == HDMI_TYPE14)
  1206. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, ~0,
  1207. HDMI_PHY_POWER_OFF_EN);
  1208. }
  1209. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1210. {
  1211. const u8 *hdmiphy_data;
  1212. u8 buffer[32];
  1213. u8 operation[2];
  1214. u8 read_buffer[32] = {0, };
  1215. int ret;
  1216. int i;
  1217. if (!hdata->hdmiphy_port) {
  1218. DRM_ERROR("hdmiphy is not attached\n");
  1219. return;
  1220. }
  1221. /* pixel clock */
  1222. i = hdmi_find_phy_conf(hdata, hdata->mode_conf.pixel_clock);
  1223. if (i < 0) {
  1224. DRM_ERROR("failed to find hdmiphy conf\n");
  1225. return;
  1226. }
  1227. if (hdata->type == HDMI_TYPE13)
  1228. hdmiphy_data = hdmiphy_v13_configs[i].conf;
  1229. else
  1230. hdmiphy_data = hdmiphy_v14_configs[i].conf;
  1231. memcpy(buffer, hdmiphy_data, 32);
  1232. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 32);
  1233. if (ret != 32) {
  1234. DRM_ERROR("failed to configure HDMIPHY via I2C\n");
  1235. return;
  1236. }
  1237. usleep_range(10000, 12000);
  1238. /* operation mode */
  1239. operation[0] = 0x1f;
  1240. operation[1] = 0x80;
  1241. ret = i2c_master_send(hdata->hdmiphy_port, operation, 2);
  1242. if (ret != 2) {
  1243. DRM_ERROR("failed to enable hdmiphy\n");
  1244. return;
  1245. }
  1246. ret = i2c_master_recv(hdata->hdmiphy_port, read_buffer, 32);
  1247. if (ret < 0) {
  1248. DRM_ERROR("failed to read hdmiphy config\n");
  1249. return;
  1250. }
  1251. for (i = 0; i < ret; i++)
  1252. DRM_DEBUG_KMS("hdmiphy[0x%02x] write[0x%02x] - "
  1253. "recv [0x%02x]\n", i, buffer[i], read_buffer[i]);
  1254. }
  1255. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1256. {
  1257. hdmiphy_conf_reset(hdata);
  1258. hdmiphy_conf_apply(hdata);
  1259. mutex_lock(&hdata->hdmi_mutex);
  1260. hdmi_conf_reset(hdata);
  1261. hdmi_conf_init(hdata);
  1262. mutex_unlock(&hdata->hdmi_mutex);
  1263. hdmi_audio_init(hdata);
  1264. /* setting core registers */
  1265. hdmi_mode_apply(hdata);
  1266. hdmi_audio_control(hdata, true);
  1267. hdmi_regs_dump(hdata, "start");
  1268. }
  1269. static void hdmi_set_reg(u8 *reg_pair, int num_bytes, u32 value)
  1270. {
  1271. int i;
  1272. BUG_ON(num_bytes > 4);
  1273. for (i = 0; i < num_bytes; i++)
  1274. reg_pair[i] = (value >> (8 * i)) & 0xff;
  1275. }
  1276. static void hdmi_v13_mode_set(struct hdmi_context *hdata,
  1277. struct drm_display_mode *m)
  1278. {
  1279. struct hdmi_v13_core_regs *core = &hdata->mode_conf.conf.v13_conf.core;
  1280. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1281. unsigned int val;
  1282. hdata->mode_conf.cea_video_id =
  1283. drm_match_cea_mode((struct drm_display_mode *)m);
  1284. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1285. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1286. hdmi_set_reg(core->h_v_line, 3, (m->htotal << 12) | m->vtotal);
  1287. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1288. hdmi_set_reg(core->vsync_pol, 1, val);
  1289. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1290. hdmi_set_reg(core->int_pro_mode, 1, val);
  1291. val = (m->hsync_start - m->hdisplay - 2);
  1292. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1293. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1294. hdmi_set_reg(core->h_sync_gen, 3, val);
  1295. /*
  1296. * Quirk requirement for exynos HDMI IP design,
  1297. * 2 pixels less than the actual calculation for hsync_start
  1298. * and end.
  1299. */
  1300. /* Following values & calculations differ for different type of modes */
  1301. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1302. /* Interlaced Mode */
  1303. val = ((m->vsync_end - m->vdisplay) / 2);
  1304. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1305. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1306. val = m->vtotal / 2;
  1307. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1308. hdmi_set_reg(core->v_blank, 3, val);
  1309. val = (m->vtotal +
  1310. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1311. val |= m->vtotal << 11;
  1312. hdmi_set_reg(core->v_blank_f, 3, val);
  1313. val = ((m->vtotal / 2) + 7);
  1314. val |= ((m->vtotal / 2) + 2) << 12;
  1315. hdmi_set_reg(core->v_sync_gen2, 3, val);
  1316. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1317. val |= ((m->htotal / 2) +
  1318. (m->hsync_start - m->hdisplay)) << 12;
  1319. hdmi_set_reg(core->v_sync_gen3, 3, val);
  1320. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1321. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1322. hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
  1323. } else {
  1324. /* Progressive Mode */
  1325. val = m->vtotal;
  1326. val |= (m->vtotal - m->vdisplay) << 11;
  1327. hdmi_set_reg(core->v_blank, 3, val);
  1328. hdmi_set_reg(core->v_blank_f, 3, 0);
  1329. val = (m->vsync_end - m->vdisplay);
  1330. val |= ((m->vsync_start - m->vdisplay) << 12);
  1331. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1332. hdmi_set_reg(core->v_sync_gen2, 3, 0x1001);/* Reset value */
  1333. hdmi_set_reg(core->v_sync_gen3, 3, 0x1001);/* Reset value */
  1334. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1335. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1336. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1337. }
  1338. /* Timing generator registers */
  1339. hdmi_set_reg(tg->cmd, 1, 0x0);
  1340. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1341. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1342. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1343. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1344. hdmi_set_reg(tg->vsync, 2, 0x1);
  1345. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1346. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1347. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1348. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1349. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1350. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1351. hdmi_set_reg(tg->tg_3d, 1, 0x0); /* Not used */
  1352. }
  1353. static void hdmi_v14_mode_set(struct hdmi_context *hdata,
  1354. struct drm_display_mode *m)
  1355. {
  1356. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1357. struct hdmi_v14_core_regs *core =
  1358. &hdata->mode_conf.conf.v14_conf.core;
  1359. hdata->mode_conf.cea_video_id =
  1360. drm_match_cea_mode((struct drm_display_mode *)m);
  1361. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1362. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1363. hdmi_set_reg(core->v_line, 2, m->vtotal);
  1364. hdmi_set_reg(core->h_line, 2, m->htotal);
  1365. hdmi_set_reg(core->hsync_pol, 1,
  1366. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1367. hdmi_set_reg(core->vsync_pol, 1,
  1368. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1369. hdmi_set_reg(core->int_pro_mode, 1,
  1370. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1371. /*
  1372. * Quirk requirement for exynos 5 HDMI IP design,
  1373. * 2 pixels less than the actual calculation for hsync_start
  1374. * and end.
  1375. */
  1376. /* Following values & calculations differ for different type of modes */
  1377. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1378. /* Interlaced Mode */
  1379. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1380. (m->vsync_end - m->vdisplay) / 2);
  1381. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1382. (m->vsync_start - m->vdisplay) / 2);
  1383. hdmi_set_reg(core->v2_blank, 2, m->vtotal / 2);
  1384. hdmi_set_reg(core->v1_blank, 2, (m->vtotal - m->vdisplay) / 2);
  1385. hdmi_set_reg(core->v_blank_f0, 2, m->vtotal - m->vdisplay / 2);
  1386. hdmi_set_reg(core->v_blank_f1, 2, m->vtotal);
  1387. hdmi_set_reg(core->v_sync_line_aft_2, 2, (m->vtotal / 2) + 7);
  1388. hdmi_set_reg(core->v_sync_line_aft_1, 2, (m->vtotal / 2) + 2);
  1389. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
  1390. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1391. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
  1392. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1393. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1394. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1395. hdmi_set_reg(tg->vact_st2, 2, m->vtotal - m->vdisplay / 2);
  1396. hdmi_set_reg(tg->vsync2, 2, (m->vtotal / 2) + 1);
  1397. hdmi_set_reg(tg->vsync_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1398. hdmi_set_reg(tg->field_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1399. hdmi_set_reg(tg->vact_st3, 2, 0x0);
  1400. hdmi_set_reg(tg->vact_st4, 2, 0x0);
  1401. } else {
  1402. /* Progressive Mode */
  1403. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1404. m->vsync_end - m->vdisplay);
  1405. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1406. m->vsync_start - m->vdisplay);
  1407. hdmi_set_reg(core->v2_blank, 2, m->vtotal);
  1408. hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
  1409. hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
  1410. hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
  1411. hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
  1412. hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
  1413. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
  1414. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
  1415. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1416. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1417. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1418. hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
  1419. hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
  1420. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1421. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1422. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1423. }
  1424. /* Following values & calculations are same irrespective of mode type */
  1425. hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
  1426. hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
  1427. hdmi_set_reg(core->vact_space_1, 2, 0xffff);
  1428. hdmi_set_reg(core->vact_space_2, 2, 0xffff);
  1429. hdmi_set_reg(core->vact_space_3, 2, 0xffff);
  1430. hdmi_set_reg(core->vact_space_4, 2, 0xffff);
  1431. hdmi_set_reg(core->vact_space_5, 2, 0xffff);
  1432. hdmi_set_reg(core->vact_space_6, 2, 0xffff);
  1433. hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
  1434. hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
  1435. hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
  1436. hdmi_set_reg(core->v_blank_f5, 2, 0xffff);
  1437. hdmi_set_reg(core->v_sync_line_aft_3, 2, 0xffff);
  1438. hdmi_set_reg(core->v_sync_line_aft_4, 2, 0xffff);
  1439. hdmi_set_reg(core->v_sync_line_aft_5, 2, 0xffff);
  1440. hdmi_set_reg(core->v_sync_line_aft_6, 2, 0xffff);
  1441. hdmi_set_reg(core->v_sync_line_aft_pxl_3, 2, 0xffff);
  1442. hdmi_set_reg(core->v_sync_line_aft_pxl_4, 2, 0xffff);
  1443. hdmi_set_reg(core->v_sync_line_aft_pxl_5, 2, 0xffff);
  1444. hdmi_set_reg(core->v_sync_line_aft_pxl_6, 2, 0xffff);
  1445. /* Timing generator registers */
  1446. hdmi_set_reg(tg->cmd, 1, 0x0);
  1447. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1448. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1449. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1450. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1451. hdmi_set_reg(tg->vsync, 2, 0x1);
  1452. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1453. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1454. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1455. hdmi_set_reg(tg->tg_3d, 1, 0x0);
  1456. }
  1457. static void hdmi_mode_set(void *ctx, struct drm_display_mode *mode)
  1458. {
  1459. struct hdmi_context *hdata = ctx;
  1460. struct drm_display_mode *m = mode;
  1461. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1462. m->hdisplay, m->vdisplay,
  1463. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1464. "INTERLACED" : "PROGERESSIVE");
  1465. if (hdata->type == HDMI_TYPE13)
  1466. hdmi_v13_mode_set(hdata, mode);
  1467. else
  1468. hdmi_v14_mode_set(hdata, mode);
  1469. }
  1470. static void hdmi_get_max_resol(void *ctx, unsigned int *width,
  1471. unsigned int *height)
  1472. {
  1473. *width = MAX_WIDTH;
  1474. *height = MAX_HEIGHT;
  1475. }
  1476. static void hdmi_commit(void *ctx)
  1477. {
  1478. struct hdmi_context *hdata = ctx;
  1479. mutex_lock(&hdata->hdmi_mutex);
  1480. if (!hdata->powered) {
  1481. mutex_unlock(&hdata->hdmi_mutex);
  1482. return;
  1483. }
  1484. mutex_unlock(&hdata->hdmi_mutex);
  1485. hdmi_conf_apply(hdata);
  1486. }
  1487. static void hdmi_poweron(struct hdmi_context *hdata)
  1488. {
  1489. struct hdmi_resources *res = &hdata->res;
  1490. mutex_lock(&hdata->hdmi_mutex);
  1491. if (hdata->powered) {
  1492. mutex_unlock(&hdata->hdmi_mutex);
  1493. return;
  1494. }
  1495. hdata->powered = true;
  1496. mutex_unlock(&hdata->hdmi_mutex);
  1497. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1498. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1499. clk_prepare_enable(res->hdmiphy);
  1500. clk_prepare_enable(res->hdmi);
  1501. clk_prepare_enable(res->sclk_hdmi);
  1502. hdmiphy_poweron(hdata);
  1503. }
  1504. static void hdmi_poweroff(struct hdmi_context *hdata)
  1505. {
  1506. struct hdmi_resources *res = &hdata->res;
  1507. mutex_lock(&hdata->hdmi_mutex);
  1508. if (!hdata->powered)
  1509. goto out;
  1510. mutex_unlock(&hdata->hdmi_mutex);
  1511. /*
  1512. * The TV power domain needs any condition of hdmiphy to turn off and
  1513. * its reset state seems to meet the condition.
  1514. */
  1515. hdmiphy_conf_reset(hdata);
  1516. hdmiphy_poweroff(hdata);
  1517. clk_disable_unprepare(res->sclk_hdmi);
  1518. clk_disable_unprepare(res->hdmi);
  1519. clk_disable_unprepare(res->hdmiphy);
  1520. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1521. mutex_lock(&hdata->hdmi_mutex);
  1522. hdata->powered = false;
  1523. out:
  1524. mutex_unlock(&hdata->hdmi_mutex);
  1525. }
  1526. static void hdmi_dpms(void *ctx, int mode)
  1527. {
  1528. struct hdmi_context *hdata = ctx;
  1529. DRM_DEBUG_KMS("mode %d\n", mode);
  1530. switch (mode) {
  1531. case DRM_MODE_DPMS_ON:
  1532. if (pm_runtime_suspended(hdata->dev))
  1533. pm_runtime_get_sync(hdata->dev);
  1534. break;
  1535. case DRM_MODE_DPMS_STANDBY:
  1536. case DRM_MODE_DPMS_SUSPEND:
  1537. case DRM_MODE_DPMS_OFF:
  1538. if (!pm_runtime_suspended(hdata->dev))
  1539. pm_runtime_put_sync(hdata->dev);
  1540. break;
  1541. default:
  1542. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  1543. break;
  1544. }
  1545. }
  1546. static struct exynos_hdmi_ops hdmi_ops = {
  1547. /* display */
  1548. .is_connected = hdmi_is_connected,
  1549. .get_edid = hdmi_get_edid,
  1550. .check_mode = hdmi_check_mode,
  1551. /* manager */
  1552. .mode_set = hdmi_mode_set,
  1553. .get_max_resol = hdmi_get_max_resol,
  1554. .commit = hdmi_commit,
  1555. .dpms = hdmi_dpms,
  1556. };
  1557. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1558. {
  1559. struct exynos_drm_hdmi_context *ctx = arg;
  1560. struct hdmi_context *hdata = ctx->ctx;
  1561. mutex_lock(&hdata->hdmi_mutex);
  1562. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1563. mutex_unlock(&hdata->hdmi_mutex);
  1564. if (ctx->drm_dev)
  1565. drm_helper_hpd_irq_event(ctx->drm_dev);
  1566. return IRQ_HANDLED;
  1567. }
  1568. static int hdmi_resources_init(struct hdmi_context *hdata)
  1569. {
  1570. struct device *dev = hdata->dev;
  1571. struct hdmi_resources *res = &hdata->res;
  1572. static char *supply[] = {
  1573. "hdmi-en",
  1574. "vdd",
  1575. "vdd_osc",
  1576. "vdd_pll",
  1577. };
  1578. int i, ret;
  1579. DRM_DEBUG_KMS("HDMI resource init\n");
  1580. memset(res, 0, sizeof(*res));
  1581. /* get clocks, power */
  1582. res->hdmi = devm_clk_get(dev, "hdmi");
  1583. if (IS_ERR(res->hdmi)) {
  1584. DRM_ERROR("failed to get clock 'hdmi'\n");
  1585. goto fail;
  1586. }
  1587. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1588. if (IS_ERR(res->sclk_hdmi)) {
  1589. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1590. goto fail;
  1591. }
  1592. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1593. if (IS_ERR(res->sclk_pixel)) {
  1594. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1595. goto fail;
  1596. }
  1597. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1598. if (IS_ERR(res->sclk_hdmiphy)) {
  1599. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1600. goto fail;
  1601. }
  1602. res->hdmiphy = devm_clk_get(dev, "hdmiphy");
  1603. if (IS_ERR(res->hdmiphy)) {
  1604. DRM_ERROR("failed to get clock 'hdmiphy'\n");
  1605. goto fail;
  1606. }
  1607. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1608. if (IS_ERR(res->mout_hdmi)) {
  1609. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1610. goto fail;
  1611. }
  1612. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1613. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1614. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1615. if (!res->regul_bulk) {
  1616. DRM_ERROR("failed to get memory for regulators\n");
  1617. goto fail;
  1618. }
  1619. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1620. res->regul_bulk[i].supply = supply[i];
  1621. res->regul_bulk[i].consumer = NULL;
  1622. }
  1623. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1624. if (ret) {
  1625. DRM_ERROR("failed to get regulators\n");
  1626. goto fail;
  1627. }
  1628. res->regul_count = ARRAY_SIZE(supply);
  1629. return 0;
  1630. fail:
  1631. DRM_ERROR("HDMI resource init - failed\n");
  1632. return -ENODEV;
  1633. }
  1634. static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
  1635. void hdmi_attach_ddc_client(struct i2c_client *ddc)
  1636. {
  1637. if (ddc)
  1638. hdmi_ddc = ddc;
  1639. }
  1640. void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
  1641. {
  1642. if (hdmiphy)
  1643. hdmi_hdmiphy = hdmiphy;
  1644. }
  1645. #ifdef CONFIG_OF
  1646. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  1647. (struct device *dev)
  1648. {
  1649. struct device_node *np = dev->of_node;
  1650. struct s5p_hdmi_platform_data *pd;
  1651. u32 value;
  1652. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  1653. if (!pd) {
  1654. DRM_ERROR("memory allocation for pdata failed\n");
  1655. goto err_data;
  1656. }
  1657. if (!of_find_property(np, "hpd-gpio", &value)) {
  1658. DRM_ERROR("no hpd gpio property found\n");
  1659. goto err_data;
  1660. }
  1661. pd->hpd_gpio = of_get_named_gpio(np, "hpd-gpio", 0);
  1662. return pd;
  1663. err_data:
  1664. return NULL;
  1665. }
  1666. #else
  1667. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  1668. (struct device *dev)
  1669. {
  1670. return NULL;
  1671. }
  1672. #endif
  1673. static struct platform_device_id hdmi_driver_types[] = {
  1674. {
  1675. .name = "s5pv210-hdmi",
  1676. .driver_data = HDMI_TYPE13,
  1677. }, {
  1678. .name = "exynos4-hdmi",
  1679. .driver_data = HDMI_TYPE13,
  1680. }, {
  1681. .name = "exynos4-hdmi14",
  1682. .driver_data = HDMI_TYPE14,
  1683. }, {
  1684. .name = "exynos5-hdmi",
  1685. .driver_data = HDMI_TYPE14,
  1686. }, {
  1687. /* end node */
  1688. }
  1689. };
  1690. #ifdef CONFIG_OF
  1691. static struct of_device_id hdmi_match_types[] = {
  1692. {
  1693. .compatible = "samsung,exynos5-hdmi",
  1694. .data = (void *)HDMI_TYPE14,
  1695. }, {
  1696. .compatible = "samsung,exynos4212-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. if (dev->of_node) {
  1712. pdata = drm_hdmi_dt_parse_pdata(dev);
  1713. if (IS_ERR(pdata)) {
  1714. DRM_ERROR("failed to parse dt\n");
  1715. return PTR_ERR(pdata);
  1716. }
  1717. } else {
  1718. pdata = dev->platform_data;
  1719. }
  1720. if (!pdata) {
  1721. DRM_ERROR("no platform data specified\n");
  1722. return -EINVAL;
  1723. }
  1724. drm_hdmi_ctx = devm_kzalloc(dev, sizeof(*drm_hdmi_ctx),
  1725. GFP_KERNEL);
  1726. if (!drm_hdmi_ctx) {
  1727. DRM_ERROR("failed to allocate common hdmi context.\n");
  1728. return -ENOMEM;
  1729. }
  1730. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context),
  1731. GFP_KERNEL);
  1732. if (!hdata) {
  1733. DRM_ERROR("out of memory\n");
  1734. return -ENOMEM;
  1735. }
  1736. mutex_init(&hdata->hdmi_mutex);
  1737. drm_hdmi_ctx->ctx = (void *)hdata;
  1738. hdata->parent_ctx = (void *)drm_hdmi_ctx;
  1739. platform_set_drvdata(pdev, drm_hdmi_ctx);
  1740. if (dev->of_node) {
  1741. const struct of_device_id *match;
  1742. match = of_match_node(of_match_ptr(hdmi_match_types),
  1743. dev->of_node);
  1744. if (match == NULL)
  1745. return -ENODEV;
  1746. hdata->type = (enum hdmi_type)match->data;
  1747. } else {
  1748. hdata->type = (enum hdmi_type)platform_get_device_id
  1749. (pdev)->driver_data;
  1750. }
  1751. hdata->hpd_gpio = pdata->hpd_gpio;
  1752. hdata->dev = dev;
  1753. ret = hdmi_resources_init(hdata);
  1754. if (ret) {
  1755. DRM_ERROR("hdmi_resources_init failed\n");
  1756. return -EINVAL;
  1757. }
  1758. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1759. hdata->regs = devm_ioremap_resource(dev, res);
  1760. if (IS_ERR(hdata->regs))
  1761. return PTR_ERR(hdata->regs);
  1762. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  1763. if (ret) {
  1764. DRM_ERROR("failed to request HPD gpio\n");
  1765. return ret;
  1766. }
  1767. /* DDC i2c driver */
  1768. if (i2c_add_driver(&ddc_driver)) {
  1769. DRM_ERROR("failed to register ddc i2c driver\n");
  1770. return -ENOENT;
  1771. }
  1772. hdata->ddc_port = hdmi_ddc;
  1773. /* hdmiphy i2c driver */
  1774. if (i2c_add_driver(&hdmiphy_driver)) {
  1775. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  1776. ret = -ENOENT;
  1777. goto err_ddc;
  1778. }
  1779. hdata->hdmiphy_port = hdmi_hdmiphy;
  1780. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  1781. if (hdata->irq < 0) {
  1782. DRM_ERROR("failed to get GPIO irq\n");
  1783. ret = hdata->irq;
  1784. goto err_hdmiphy;
  1785. }
  1786. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1787. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1788. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1789. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1790. "hdmi", drm_hdmi_ctx);
  1791. if (ret) {
  1792. DRM_ERROR("failed to register hdmi interrupt\n");
  1793. goto err_hdmiphy;
  1794. }
  1795. /* Attach HDMI Driver to common hdmi. */
  1796. exynos_hdmi_drv_attach(drm_hdmi_ctx);
  1797. /* register specific callbacks to common hdmi. */
  1798. exynos_hdmi_ops_register(&hdmi_ops);
  1799. pm_runtime_enable(dev);
  1800. return 0;
  1801. err_hdmiphy:
  1802. i2c_del_driver(&hdmiphy_driver);
  1803. err_ddc:
  1804. i2c_del_driver(&ddc_driver);
  1805. return ret;
  1806. }
  1807. static int hdmi_remove(struct platform_device *pdev)
  1808. {
  1809. struct device *dev = &pdev->dev;
  1810. pm_runtime_disable(dev);
  1811. /* hdmiphy i2c driver */
  1812. i2c_del_driver(&hdmiphy_driver);
  1813. /* DDC i2c driver */
  1814. i2c_del_driver(&ddc_driver);
  1815. return 0;
  1816. }
  1817. #ifdef CONFIG_PM_SLEEP
  1818. static int hdmi_suspend(struct device *dev)
  1819. {
  1820. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1821. struct hdmi_context *hdata = ctx->ctx;
  1822. disable_irq(hdata->irq);
  1823. hdata->hpd = false;
  1824. if (ctx->drm_dev)
  1825. drm_helper_hpd_irq_event(ctx->drm_dev);
  1826. if (pm_runtime_suspended(dev)) {
  1827. DRM_DEBUG_KMS("Already suspended\n");
  1828. return 0;
  1829. }
  1830. hdmi_poweroff(hdata);
  1831. return 0;
  1832. }
  1833. static int hdmi_resume(struct device *dev)
  1834. {
  1835. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1836. struct hdmi_context *hdata = ctx->ctx;
  1837. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1838. enable_irq(hdata->irq);
  1839. if (!pm_runtime_suspended(dev)) {
  1840. DRM_DEBUG_KMS("Already resumed\n");
  1841. return 0;
  1842. }
  1843. hdmi_poweron(hdata);
  1844. return 0;
  1845. }
  1846. #endif
  1847. #ifdef CONFIG_PM_RUNTIME
  1848. static int hdmi_runtime_suspend(struct device *dev)
  1849. {
  1850. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1851. struct hdmi_context *hdata = ctx->ctx;
  1852. hdmi_poweroff(hdata);
  1853. return 0;
  1854. }
  1855. static int hdmi_runtime_resume(struct device *dev)
  1856. {
  1857. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1858. struct hdmi_context *hdata = ctx->ctx;
  1859. hdmi_poweron(hdata);
  1860. return 0;
  1861. }
  1862. #endif
  1863. static const struct dev_pm_ops hdmi_pm_ops = {
  1864. SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
  1865. SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
  1866. };
  1867. struct platform_driver hdmi_driver = {
  1868. .probe = hdmi_probe,
  1869. .remove = hdmi_remove,
  1870. .id_table = hdmi_driver_types,
  1871. .driver = {
  1872. .name = "exynos-hdmi",
  1873. .owner = THIS_MODULE,
  1874. .pm = &hdmi_pm_ops,
  1875. .of_match_table = of_match_ptr(hdmi_match_types),
  1876. },
  1877. };