exynos_hdmi.c 67 KB

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