exynos_hdmi.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  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 (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 = 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(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(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. 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. hdata->regs = devm_ioremap_resource(dev, res);
  1761. if (IS_ERR(hdata->regs))
  1762. return PTR_ERR(hdata->regs);
  1763. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  1764. if (ret) {
  1765. DRM_ERROR("failed to request HPD gpio\n");
  1766. return ret;
  1767. }
  1768. /* DDC i2c driver */
  1769. if (i2c_add_driver(&ddc_driver)) {
  1770. DRM_ERROR("failed to register ddc i2c driver\n");
  1771. return -ENOENT;
  1772. }
  1773. hdata->ddc_port = hdmi_ddc;
  1774. /* hdmiphy i2c driver */
  1775. if (i2c_add_driver(&hdmiphy_driver)) {
  1776. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  1777. ret = -ENOENT;
  1778. goto err_ddc;
  1779. }
  1780. hdata->hdmiphy_port = hdmi_hdmiphy;
  1781. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  1782. if (hdata->irq < 0) {
  1783. DRM_ERROR("failed to get GPIO irq\n");
  1784. ret = hdata->irq;
  1785. goto err_hdmiphy;
  1786. }
  1787. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1788. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1789. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1790. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1791. "hdmi", drm_hdmi_ctx);
  1792. if (ret) {
  1793. DRM_ERROR("failed to register hdmi interrupt\n");
  1794. goto err_hdmiphy;
  1795. }
  1796. /* Attach HDMI Driver to common hdmi. */
  1797. exynos_hdmi_drv_attach(drm_hdmi_ctx);
  1798. /* register specific callbacks to common hdmi. */
  1799. exynos_hdmi_ops_register(&hdmi_ops);
  1800. pm_runtime_enable(dev);
  1801. return 0;
  1802. err_hdmiphy:
  1803. i2c_del_driver(&hdmiphy_driver);
  1804. err_ddc:
  1805. i2c_del_driver(&ddc_driver);
  1806. return ret;
  1807. }
  1808. static int hdmi_remove(struct platform_device *pdev)
  1809. {
  1810. struct device *dev = &pdev->dev;
  1811. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1812. pm_runtime_disable(dev);
  1813. /* hdmiphy i2c driver */
  1814. i2c_del_driver(&hdmiphy_driver);
  1815. /* DDC i2c driver */
  1816. i2c_del_driver(&ddc_driver);
  1817. return 0;
  1818. }
  1819. #ifdef CONFIG_PM_SLEEP
  1820. static int hdmi_suspend(struct device *dev)
  1821. {
  1822. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1823. struct hdmi_context *hdata = ctx->ctx;
  1824. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1825. disable_irq(hdata->irq);
  1826. hdata->hpd = false;
  1827. if (ctx->drm_dev)
  1828. drm_helper_hpd_irq_event(ctx->drm_dev);
  1829. if (pm_runtime_suspended(dev)) {
  1830. DRM_DEBUG_KMS("%s : Already suspended\n", __func__);
  1831. return 0;
  1832. }
  1833. hdmi_poweroff(hdata);
  1834. return 0;
  1835. }
  1836. static int hdmi_resume(struct device *dev)
  1837. {
  1838. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1839. struct hdmi_context *hdata = ctx->ctx;
  1840. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1841. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1842. enable_irq(hdata->irq);
  1843. if (!pm_runtime_suspended(dev)) {
  1844. DRM_DEBUG_KMS("%s : Already resumed\n", __func__);
  1845. return 0;
  1846. }
  1847. hdmi_poweron(hdata);
  1848. return 0;
  1849. }
  1850. #endif
  1851. #ifdef CONFIG_PM_RUNTIME
  1852. static int hdmi_runtime_suspend(struct device *dev)
  1853. {
  1854. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1855. struct hdmi_context *hdata = ctx->ctx;
  1856. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1857. hdmi_poweroff(hdata);
  1858. return 0;
  1859. }
  1860. static int hdmi_runtime_resume(struct device *dev)
  1861. {
  1862. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1863. struct hdmi_context *hdata = ctx->ctx;
  1864. DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
  1865. hdmi_poweron(hdata);
  1866. return 0;
  1867. }
  1868. #endif
  1869. static const struct dev_pm_ops hdmi_pm_ops = {
  1870. SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
  1871. SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
  1872. };
  1873. struct platform_driver hdmi_driver = {
  1874. .probe = hdmi_probe,
  1875. .remove = hdmi_remove,
  1876. .id_table = hdmi_driver_types,
  1877. .driver = {
  1878. .name = "exynos-hdmi",
  1879. .owner = THIS_MODULE,
  1880. .pm = &hdmi_pm_ops,
  1881. .of_match_table = of_match_ptr(hdmi_match_types),
  1882. },
  1883. };