exynos_hdmi.c 75 KB

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