exynos_hdmi.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Authors:
  4. * Seung-Woo Kim <sw0312.kim@samsung.com>
  5. * Inki Dae <inki.dae@samsung.com>
  6. * Joonyoung Shim <jy0922.shim@samsung.com>
  7. *
  8. * Based on drivers/media/video/s5p-tv/hdmi_drv.c
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <drm/drmP.h>
  17. #include <drm/drm_edid.h>
  18. #include <drm/drm_crtc_helper.h>
  19. #include "regs-hdmi.h"
  20. #include <linux/kernel.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/wait.h>
  23. #include <linux/i2c.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm_runtime.h>
  29. #include <linux/clk.h>
  30. #include <linux/regulator/consumer.h>
  31. #include <linux/io.h>
  32. #include <linux/of.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_gpio.h>
  35. #include <linux/hdmi.h>
  36. #include <linux/component.h>
  37. #include <linux/mfd/syscon.h>
  38. #include <linux/regmap.h>
  39. #include <drm/exynos_drm.h>
  40. #include "exynos_drm_drv.h"
  41. #include "exynos_drm_crtc.h"
  42. #include "exynos_mixer.h"
  43. #include <linux/gpio.h>
  44. #include <media/s5p_hdmi.h>
  45. #define get_hdmi_display(dev) platform_get_drvdata(to_platform_device(dev))
  46. #define ctx_from_connector(c) container_of(c, struct hdmi_context, connector)
  47. #define HOTPLUG_DEBOUNCE_MS 1100
  48. /* AVI header and aspect ratio */
  49. #define HDMI_AVI_VERSION 0x02
  50. #define HDMI_AVI_LENGTH 0x0D
  51. /* AUI header info */
  52. #define HDMI_AUI_VERSION 0x01
  53. #define HDMI_AUI_LENGTH 0x0A
  54. #define AVI_SAME_AS_PIC_ASPECT_RATIO 0x8
  55. #define AVI_4_3_CENTER_RATIO 0x9
  56. #define AVI_16_9_CENTER_RATIO 0xa
  57. enum hdmi_type {
  58. HDMI_TYPE13,
  59. HDMI_TYPE14,
  60. };
  61. struct hdmi_driver_data {
  62. unsigned int type;
  63. const struct hdmiphy_config *phy_confs;
  64. unsigned int phy_conf_count;
  65. unsigned int is_apb_phy:1;
  66. };
  67. struct hdmi_resources {
  68. struct clk *hdmi;
  69. struct clk *sclk_hdmi;
  70. struct clk *sclk_pixel;
  71. struct clk *sclk_hdmiphy;
  72. struct clk *mout_hdmi;
  73. struct regulator_bulk_data *regul_bulk;
  74. struct regulator *reg_hdmi_en;
  75. int regul_count;
  76. };
  77. struct hdmi_tg_regs {
  78. u8 cmd[1];
  79. u8 h_fsz[2];
  80. u8 hact_st[2];
  81. u8 hact_sz[2];
  82. u8 v_fsz[2];
  83. u8 vsync[2];
  84. u8 vsync2[2];
  85. u8 vact_st[2];
  86. u8 vact_sz[2];
  87. u8 field_chg[2];
  88. u8 vact_st2[2];
  89. u8 vact_st3[2];
  90. u8 vact_st4[2];
  91. u8 vsync_top_hdmi[2];
  92. u8 vsync_bot_hdmi[2];
  93. u8 field_top_hdmi[2];
  94. u8 field_bot_hdmi[2];
  95. u8 tg_3d[1];
  96. };
  97. struct hdmi_v13_core_regs {
  98. u8 h_blank[2];
  99. u8 v_blank[3];
  100. u8 h_v_line[3];
  101. u8 vsync_pol[1];
  102. u8 int_pro_mode[1];
  103. u8 v_blank_f[3];
  104. u8 h_sync_gen[3];
  105. u8 v_sync_gen1[3];
  106. u8 v_sync_gen2[3];
  107. u8 v_sync_gen3[3];
  108. };
  109. struct hdmi_v14_core_regs {
  110. u8 h_blank[2];
  111. u8 v2_blank[2];
  112. u8 v1_blank[2];
  113. u8 v_line[2];
  114. u8 h_line[2];
  115. u8 hsync_pol[1];
  116. u8 vsync_pol[1];
  117. u8 int_pro_mode[1];
  118. u8 v_blank_f0[2];
  119. u8 v_blank_f1[2];
  120. u8 h_sync_start[2];
  121. u8 h_sync_end[2];
  122. u8 v_sync_line_bef_2[2];
  123. u8 v_sync_line_bef_1[2];
  124. u8 v_sync_line_aft_2[2];
  125. u8 v_sync_line_aft_1[2];
  126. u8 v_sync_line_aft_pxl_2[2];
  127. u8 v_sync_line_aft_pxl_1[2];
  128. u8 v_blank_f2[2]; /* for 3D mode */
  129. u8 v_blank_f3[2]; /* for 3D mode */
  130. u8 v_blank_f4[2]; /* for 3D mode */
  131. u8 v_blank_f5[2]; /* for 3D mode */
  132. u8 v_sync_line_aft_3[2];
  133. u8 v_sync_line_aft_4[2];
  134. u8 v_sync_line_aft_5[2];
  135. u8 v_sync_line_aft_6[2];
  136. u8 v_sync_line_aft_pxl_3[2];
  137. u8 v_sync_line_aft_pxl_4[2];
  138. u8 v_sync_line_aft_pxl_5[2];
  139. u8 v_sync_line_aft_pxl_6[2];
  140. u8 vact_space_1[2];
  141. u8 vact_space_2[2];
  142. u8 vact_space_3[2];
  143. u8 vact_space_4[2];
  144. u8 vact_space_5[2];
  145. u8 vact_space_6[2];
  146. };
  147. struct hdmi_v13_conf {
  148. struct hdmi_v13_core_regs core;
  149. struct hdmi_tg_regs tg;
  150. };
  151. struct hdmi_v14_conf {
  152. struct hdmi_v14_core_regs core;
  153. struct hdmi_tg_regs tg;
  154. };
  155. struct hdmi_conf_regs {
  156. int pixel_clock;
  157. int cea_video_id;
  158. enum hdmi_picture_aspect aspect_ratio;
  159. union {
  160. struct hdmi_v13_conf v13_conf;
  161. struct hdmi_v14_conf v14_conf;
  162. } conf;
  163. };
  164. struct hdmi_context {
  165. struct device *dev;
  166. struct drm_device *drm_dev;
  167. struct drm_connector connector;
  168. struct drm_encoder *encoder;
  169. bool hpd;
  170. bool powered;
  171. bool dvi_mode;
  172. struct mutex hdmi_mutex;
  173. void __iomem *regs;
  174. int irq;
  175. struct delayed_work hotplug_work;
  176. struct i2c_adapter *ddc_adpt;
  177. struct i2c_client *hdmiphy_port;
  178. /* current hdmiphy conf regs */
  179. struct drm_display_mode current_mode;
  180. struct hdmi_conf_regs mode_conf;
  181. struct hdmi_resources res;
  182. int hpd_gpio;
  183. void __iomem *regs_hdmiphy;
  184. const struct hdmiphy_config *phy_confs;
  185. unsigned int phy_conf_count;
  186. struct regmap *pmureg;
  187. enum hdmi_type type;
  188. };
  189. struct hdmiphy_config {
  190. int pixel_clock;
  191. u8 conf[32];
  192. };
  193. /* list of phy config settings */
  194. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  195. {
  196. .pixel_clock = 27000000,
  197. .conf = {
  198. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  199. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  200. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  201. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  202. },
  203. },
  204. {
  205. .pixel_clock = 27027000,
  206. .conf = {
  207. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  208. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  209. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  210. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  211. },
  212. },
  213. {
  214. .pixel_clock = 74176000,
  215. .conf = {
  216. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  217. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  218. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  219. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  220. },
  221. },
  222. {
  223. .pixel_clock = 74250000,
  224. .conf = {
  225. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  226. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  227. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  228. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  229. },
  230. },
  231. {
  232. .pixel_clock = 148500000,
  233. .conf = {
  234. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  235. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  236. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  237. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  238. },
  239. },
  240. };
  241. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  242. {
  243. .pixel_clock = 25200000,
  244. .conf = {
  245. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  246. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  247. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  248. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  249. },
  250. },
  251. {
  252. .pixel_clock = 27000000,
  253. .conf = {
  254. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  255. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  256. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  257. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  258. },
  259. },
  260. {
  261. .pixel_clock = 27027000,
  262. .conf = {
  263. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  264. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  265. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  266. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  267. },
  268. },
  269. {
  270. .pixel_clock = 36000000,
  271. .conf = {
  272. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  273. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  274. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  275. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  276. },
  277. },
  278. {
  279. .pixel_clock = 40000000,
  280. .conf = {
  281. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  282. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  283. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  284. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  285. },
  286. },
  287. {
  288. .pixel_clock = 65000000,
  289. .conf = {
  290. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  291. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  292. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  293. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  294. },
  295. },
  296. {
  297. .pixel_clock = 71000000,
  298. .conf = {
  299. 0x01, 0xd1, 0x3b, 0x35, 0x40, 0x0c, 0x04, 0x08,
  300. 0x85, 0xa0, 0x63, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  301. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  302. 0x54, 0xad, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  303. },
  304. },
  305. {
  306. .pixel_clock = 73250000,
  307. .conf = {
  308. 0x01, 0xd1, 0x3d, 0x35, 0x40, 0x18, 0x02, 0x08,
  309. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  310. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  311. 0x54, 0xa8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  312. },
  313. },
  314. {
  315. .pixel_clock = 74176000,
  316. .conf = {
  317. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  318. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  319. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  320. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  321. },
  322. },
  323. {
  324. .pixel_clock = 74250000,
  325. .conf = {
  326. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  327. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  328. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  329. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  330. },
  331. },
  332. {
  333. .pixel_clock = 83500000,
  334. .conf = {
  335. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  336. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  337. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  338. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  339. },
  340. },
  341. {
  342. .pixel_clock = 106500000,
  343. .conf = {
  344. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  345. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  346. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  347. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  348. },
  349. },
  350. {
  351. .pixel_clock = 108000000,
  352. .conf = {
  353. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  354. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  355. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  356. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  357. },
  358. },
  359. {
  360. .pixel_clock = 115500000,
  361. .conf = {
  362. 0x01, 0xd1, 0x30, 0x12, 0x40, 0x40, 0x10, 0x08,
  363. 0x80, 0x80, 0x21, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  364. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  365. 0x54, 0xaa, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  366. },
  367. },
  368. {
  369. .pixel_clock = 119000000,
  370. .conf = {
  371. 0x01, 0xd1, 0x32, 0x1a, 0x40, 0x30, 0xd8, 0x08,
  372. 0x04, 0xa0, 0x2a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  373. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  374. 0x54, 0x9d, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  375. },
  376. },
  377. {
  378. .pixel_clock = 146250000,
  379. .conf = {
  380. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  381. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  382. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  383. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  384. },
  385. },
  386. {
  387. .pixel_clock = 148500000,
  388. .conf = {
  389. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  390. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  391. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  392. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  393. },
  394. },
  395. };
  396. static const struct hdmiphy_config hdmiphy_5420_configs[] = {
  397. {
  398. .pixel_clock = 25200000,
  399. .conf = {
  400. 0x01, 0x52, 0x3F, 0x55, 0x40, 0x01, 0x00, 0xC8,
  401. 0x82, 0xC8, 0xBD, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  402. 0x06, 0x80, 0x01, 0x84, 0x05, 0x02, 0x24, 0x66,
  403. 0x54, 0xF4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  404. },
  405. },
  406. {
  407. .pixel_clock = 27000000,
  408. .conf = {
  409. 0x01, 0xD1, 0x22, 0x51, 0x40, 0x08, 0xFC, 0xE0,
  410. 0x98, 0xE8, 0xCB, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  411. 0x06, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  412. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  413. },
  414. },
  415. {
  416. .pixel_clock = 27027000,
  417. .conf = {
  418. 0x01, 0xD1, 0x2D, 0x72, 0x40, 0x64, 0x12, 0xC8,
  419. 0x43, 0xE8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  420. 0x26, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  421. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  422. },
  423. },
  424. {
  425. .pixel_clock = 36000000,
  426. .conf = {
  427. 0x01, 0x51, 0x2D, 0x55, 0x40, 0x40, 0x00, 0xC8,
  428. 0x02, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  429. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  430. 0x54, 0xAB, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  431. },
  432. },
  433. {
  434. .pixel_clock = 40000000,
  435. .conf = {
  436. 0x01, 0xD1, 0x21, 0x31, 0x40, 0x3C, 0x28, 0xC8,
  437. 0x87, 0xE8, 0xC8, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  438. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  439. 0x54, 0x9A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  440. },
  441. },
  442. {
  443. .pixel_clock = 65000000,
  444. .conf = {
  445. 0x01, 0xD1, 0x36, 0x34, 0x40, 0x0C, 0x04, 0xC8,
  446. 0x82, 0xE8, 0x45, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  447. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  448. 0x54, 0xBD, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  449. },
  450. },
  451. {
  452. .pixel_clock = 71000000,
  453. .conf = {
  454. 0x01, 0xD1, 0x3B, 0x35, 0x40, 0x0C, 0x04, 0xC8,
  455. 0x85, 0xE8, 0x63, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  456. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  457. 0x54, 0x57, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  458. },
  459. },
  460. {
  461. .pixel_clock = 73250000,
  462. .conf = {
  463. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x78, 0x8D, 0xC8,
  464. 0x81, 0xE8, 0xB7, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  465. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  466. 0x54, 0xA8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  467. },
  468. },
  469. {
  470. .pixel_clock = 74176000,
  471. .conf = {
  472. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0xC8,
  473. 0x81, 0xE8, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  474. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  475. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  476. },
  477. },
  478. {
  479. .pixel_clock = 74250000,
  480. .conf = {
  481. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  482. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  483. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  484. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  485. },
  486. },
  487. {
  488. .pixel_clock = 83500000,
  489. .conf = {
  490. 0x01, 0xD1, 0x23, 0x11, 0x40, 0x0C, 0xFB, 0xC8,
  491. 0x85, 0xE8, 0xD1, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  492. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  493. 0x54, 0x4A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  494. },
  495. },
  496. {
  497. .pixel_clock = 88750000,
  498. .conf = {
  499. 0x01, 0xD1, 0x25, 0x11, 0x40, 0x18, 0xFF, 0xC8,
  500. 0x83, 0xE8, 0xDE, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  501. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  502. 0x54, 0x45, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  503. },
  504. },
  505. {
  506. .pixel_clock = 106500000,
  507. .conf = {
  508. 0x01, 0xD1, 0x2C, 0x12, 0x40, 0x0C, 0x09, 0xC8,
  509. 0x84, 0xE8, 0x0A, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  510. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  511. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  512. },
  513. },
  514. {
  515. .pixel_clock = 108000000,
  516. .conf = {
  517. 0x01, 0x51, 0x2D, 0x15, 0x40, 0x01, 0x00, 0xC8,
  518. 0x82, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  519. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  520. 0x54, 0xC7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  521. },
  522. },
  523. {
  524. .pixel_clock = 115500000,
  525. .conf = {
  526. 0x01, 0xD1, 0x30, 0x14, 0x40, 0x0C, 0x03, 0xC8,
  527. 0x88, 0xE8, 0x21, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  528. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  529. 0x54, 0x6A, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  530. },
  531. },
  532. {
  533. .pixel_clock = 146250000,
  534. .conf = {
  535. 0x01, 0xD1, 0x3D, 0x15, 0x40, 0x18, 0xFD, 0xC8,
  536. 0x83, 0xE8, 0x6E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  537. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  538. 0x54, 0x54, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  539. },
  540. },
  541. {
  542. .pixel_clock = 148500000,
  543. .conf = {
  544. 0x01, 0xD1, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  545. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  546. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  547. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x80, 0x01, 0x80,
  548. },
  549. },
  550. };
  551. static struct hdmi_driver_data exynos5420_hdmi_driver_data = {
  552. .type = HDMI_TYPE14,
  553. .phy_confs = hdmiphy_5420_configs,
  554. .phy_conf_count = ARRAY_SIZE(hdmiphy_5420_configs),
  555. .is_apb_phy = 1,
  556. };
  557. static struct hdmi_driver_data exynos4212_hdmi_driver_data = {
  558. .type = HDMI_TYPE14,
  559. .phy_confs = hdmiphy_v14_configs,
  560. .phy_conf_count = ARRAY_SIZE(hdmiphy_v14_configs),
  561. .is_apb_phy = 0,
  562. };
  563. static struct hdmi_driver_data exynos4210_hdmi_driver_data = {
  564. .type = HDMI_TYPE13,
  565. .phy_confs = hdmiphy_v13_configs,
  566. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  567. .is_apb_phy = 0,
  568. };
  569. static struct hdmi_driver_data exynos5_hdmi_driver_data = {
  570. .type = HDMI_TYPE14,
  571. .phy_confs = hdmiphy_v13_configs,
  572. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  573. .is_apb_phy = 0,
  574. };
  575. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  576. {
  577. return readl(hdata->regs + reg_id);
  578. }
  579. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  580. u32 reg_id, u8 value)
  581. {
  582. writeb(value, hdata->regs + reg_id);
  583. }
  584. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  585. u32 reg_id, u32 value, u32 mask)
  586. {
  587. u32 old = readl(hdata->regs + reg_id);
  588. value = (value & mask) | (old & ~mask);
  589. writel(value, hdata->regs + reg_id);
  590. }
  591. static int hdmiphy_reg_writeb(struct hdmi_context *hdata,
  592. u32 reg_offset, u8 value)
  593. {
  594. if (hdata->hdmiphy_port) {
  595. u8 buffer[2];
  596. int ret;
  597. buffer[0] = reg_offset;
  598. buffer[1] = value;
  599. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  600. if (ret == 2)
  601. return 0;
  602. return ret;
  603. } else {
  604. writeb(value, hdata->regs_hdmiphy + (reg_offset<<2));
  605. return 0;
  606. }
  607. }
  608. static int hdmiphy_reg_write_buf(struct hdmi_context *hdata,
  609. u32 reg_offset, const u8 *buf, u32 len)
  610. {
  611. if ((reg_offset + len) > 32)
  612. return -EINVAL;
  613. if (hdata->hdmiphy_port) {
  614. int ret;
  615. ret = i2c_master_send(hdata->hdmiphy_port, buf, len);
  616. if (ret == len)
  617. return 0;
  618. return ret;
  619. } else {
  620. int i;
  621. for (i = 0; i < len; i++)
  622. writeb(buf[i], hdata->regs_hdmiphy +
  623. ((reg_offset + i)<<2));
  624. return 0;
  625. }
  626. }
  627. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  628. {
  629. #define DUMPREG(reg_id) \
  630. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  631. readl(hdata->regs + reg_id))
  632. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  633. DUMPREG(HDMI_INTC_FLAG);
  634. DUMPREG(HDMI_INTC_CON);
  635. DUMPREG(HDMI_HPD_STATUS);
  636. DUMPREG(HDMI_V13_PHY_RSTOUT);
  637. DUMPREG(HDMI_V13_PHY_VPLL);
  638. DUMPREG(HDMI_V13_PHY_CMU);
  639. DUMPREG(HDMI_V13_CORE_RSTOUT);
  640. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  641. DUMPREG(HDMI_CON_0);
  642. DUMPREG(HDMI_CON_1);
  643. DUMPREG(HDMI_CON_2);
  644. DUMPREG(HDMI_SYS_STATUS);
  645. DUMPREG(HDMI_V13_PHY_STATUS);
  646. DUMPREG(HDMI_STATUS_EN);
  647. DUMPREG(HDMI_HPD);
  648. DUMPREG(HDMI_MODE_SEL);
  649. DUMPREG(HDMI_V13_HPD_GEN);
  650. DUMPREG(HDMI_V13_DC_CONTROL);
  651. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  652. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  653. DUMPREG(HDMI_H_BLANK_0);
  654. DUMPREG(HDMI_H_BLANK_1);
  655. DUMPREG(HDMI_V13_V_BLANK_0);
  656. DUMPREG(HDMI_V13_V_BLANK_1);
  657. DUMPREG(HDMI_V13_V_BLANK_2);
  658. DUMPREG(HDMI_V13_H_V_LINE_0);
  659. DUMPREG(HDMI_V13_H_V_LINE_1);
  660. DUMPREG(HDMI_V13_H_V_LINE_2);
  661. DUMPREG(HDMI_VSYNC_POL);
  662. DUMPREG(HDMI_INT_PRO_MODE);
  663. DUMPREG(HDMI_V13_V_BLANK_F_0);
  664. DUMPREG(HDMI_V13_V_BLANK_F_1);
  665. DUMPREG(HDMI_V13_V_BLANK_F_2);
  666. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  667. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  668. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  669. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  670. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  671. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  672. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  673. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  674. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  675. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  676. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  677. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  678. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  679. DUMPREG(HDMI_TG_CMD);
  680. DUMPREG(HDMI_TG_H_FSZ_L);
  681. DUMPREG(HDMI_TG_H_FSZ_H);
  682. DUMPREG(HDMI_TG_HACT_ST_L);
  683. DUMPREG(HDMI_TG_HACT_ST_H);
  684. DUMPREG(HDMI_TG_HACT_SZ_L);
  685. DUMPREG(HDMI_TG_HACT_SZ_H);
  686. DUMPREG(HDMI_TG_V_FSZ_L);
  687. DUMPREG(HDMI_TG_V_FSZ_H);
  688. DUMPREG(HDMI_TG_VSYNC_L);
  689. DUMPREG(HDMI_TG_VSYNC_H);
  690. DUMPREG(HDMI_TG_VSYNC2_L);
  691. DUMPREG(HDMI_TG_VSYNC2_H);
  692. DUMPREG(HDMI_TG_VACT_ST_L);
  693. DUMPREG(HDMI_TG_VACT_ST_H);
  694. DUMPREG(HDMI_TG_VACT_SZ_L);
  695. DUMPREG(HDMI_TG_VACT_SZ_H);
  696. DUMPREG(HDMI_TG_FIELD_CHG_L);
  697. DUMPREG(HDMI_TG_FIELD_CHG_H);
  698. DUMPREG(HDMI_TG_VACT_ST2_L);
  699. DUMPREG(HDMI_TG_VACT_ST2_H);
  700. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  701. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  702. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  703. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  704. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  705. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  706. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  707. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  708. #undef DUMPREG
  709. }
  710. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  711. {
  712. int i;
  713. #define DUMPREG(reg_id) \
  714. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  715. readl(hdata->regs + reg_id))
  716. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  717. DUMPREG(HDMI_INTC_CON);
  718. DUMPREG(HDMI_INTC_FLAG);
  719. DUMPREG(HDMI_HPD_STATUS);
  720. DUMPREG(HDMI_INTC_CON_1);
  721. DUMPREG(HDMI_INTC_FLAG_1);
  722. DUMPREG(HDMI_PHY_STATUS_0);
  723. DUMPREG(HDMI_PHY_STATUS_PLL);
  724. DUMPREG(HDMI_PHY_CON_0);
  725. DUMPREG(HDMI_PHY_RSTOUT);
  726. DUMPREG(HDMI_PHY_VPLL);
  727. DUMPREG(HDMI_PHY_CMU);
  728. DUMPREG(HDMI_CORE_RSTOUT);
  729. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  730. DUMPREG(HDMI_CON_0);
  731. DUMPREG(HDMI_CON_1);
  732. DUMPREG(HDMI_CON_2);
  733. DUMPREG(HDMI_SYS_STATUS);
  734. DUMPREG(HDMI_PHY_STATUS_0);
  735. DUMPREG(HDMI_STATUS_EN);
  736. DUMPREG(HDMI_HPD);
  737. DUMPREG(HDMI_MODE_SEL);
  738. DUMPREG(HDMI_ENC_EN);
  739. DUMPREG(HDMI_DC_CONTROL);
  740. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  741. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  742. DUMPREG(HDMI_H_BLANK_0);
  743. DUMPREG(HDMI_H_BLANK_1);
  744. DUMPREG(HDMI_V2_BLANK_0);
  745. DUMPREG(HDMI_V2_BLANK_1);
  746. DUMPREG(HDMI_V1_BLANK_0);
  747. DUMPREG(HDMI_V1_BLANK_1);
  748. DUMPREG(HDMI_V_LINE_0);
  749. DUMPREG(HDMI_V_LINE_1);
  750. DUMPREG(HDMI_H_LINE_0);
  751. DUMPREG(HDMI_H_LINE_1);
  752. DUMPREG(HDMI_HSYNC_POL);
  753. DUMPREG(HDMI_VSYNC_POL);
  754. DUMPREG(HDMI_INT_PRO_MODE);
  755. DUMPREG(HDMI_V_BLANK_F0_0);
  756. DUMPREG(HDMI_V_BLANK_F0_1);
  757. DUMPREG(HDMI_V_BLANK_F1_0);
  758. DUMPREG(HDMI_V_BLANK_F1_1);
  759. DUMPREG(HDMI_H_SYNC_START_0);
  760. DUMPREG(HDMI_H_SYNC_START_1);
  761. DUMPREG(HDMI_H_SYNC_END_0);
  762. DUMPREG(HDMI_H_SYNC_END_1);
  763. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  764. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  765. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  766. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  767. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  768. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  769. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  770. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  771. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  772. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  773. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  774. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  775. DUMPREG(HDMI_V_BLANK_F2_0);
  776. DUMPREG(HDMI_V_BLANK_F2_1);
  777. DUMPREG(HDMI_V_BLANK_F3_0);
  778. DUMPREG(HDMI_V_BLANK_F3_1);
  779. DUMPREG(HDMI_V_BLANK_F4_0);
  780. DUMPREG(HDMI_V_BLANK_F4_1);
  781. DUMPREG(HDMI_V_BLANK_F5_0);
  782. DUMPREG(HDMI_V_BLANK_F5_1);
  783. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  784. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  785. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  786. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  787. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  788. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  789. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  790. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  791. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  792. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  793. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  794. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  795. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  796. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  797. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  798. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  799. DUMPREG(HDMI_VACT_SPACE_1_0);
  800. DUMPREG(HDMI_VACT_SPACE_1_1);
  801. DUMPREG(HDMI_VACT_SPACE_2_0);
  802. DUMPREG(HDMI_VACT_SPACE_2_1);
  803. DUMPREG(HDMI_VACT_SPACE_3_0);
  804. DUMPREG(HDMI_VACT_SPACE_3_1);
  805. DUMPREG(HDMI_VACT_SPACE_4_0);
  806. DUMPREG(HDMI_VACT_SPACE_4_1);
  807. DUMPREG(HDMI_VACT_SPACE_5_0);
  808. DUMPREG(HDMI_VACT_SPACE_5_1);
  809. DUMPREG(HDMI_VACT_SPACE_6_0);
  810. DUMPREG(HDMI_VACT_SPACE_6_1);
  811. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  812. DUMPREG(HDMI_TG_CMD);
  813. DUMPREG(HDMI_TG_H_FSZ_L);
  814. DUMPREG(HDMI_TG_H_FSZ_H);
  815. DUMPREG(HDMI_TG_HACT_ST_L);
  816. DUMPREG(HDMI_TG_HACT_ST_H);
  817. DUMPREG(HDMI_TG_HACT_SZ_L);
  818. DUMPREG(HDMI_TG_HACT_SZ_H);
  819. DUMPREG(HDMI_TG_V_FSZ_L);
  820. DUMPREG(HDMI_TG_V_FSZ_H);
  821. DUMPREG(HDMI_TG_VSYNC_L);
  822. DUMPREG(HDMI_TG_VSYNC_H);
  823. DUMPREG(HDMI_TG_VSYNC2_L);
  824. DUMPREG(HDMI_TG_VSYNC2_H);
  825. DUMPREG(HDMI_TG_VACT_ST_L);
  826. DUMPREG(HDMI_TG_VACT_ST_H);
  827. DUMPREG(HDMI_TG_VACT_SZ_L);
  828. DUMPREG(HDMI_TG_VACT_SZ_H);
  829. DUMPREG(HDMI_TG_FIELD_CHG_L);
  830. DUMPREG(HDMI_TG_FIELD_CHG_H);
  831. DUMPREG(HDMI_TG_VACT_ST2_L);
  832. DUMPREG(HDMI_TG_VACT_ST2_H);
  833. DUMPREG(HDMI_TG_VACT_ST3_L);
  834. DUMPREG(HDMI_TG_VACT_ST3_H);
  835. DUMPREG(HDMI_TG_VACT_ST4_L);
  836. DUMPREG(HDMI_TG_VACT_ST4_H);
  837. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  838. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  839. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  840. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  841. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  842. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  843. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  844. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  845. DUMPREG(HDMI_TG_3D);
  846. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  847. DUMPREG(HDMI_AVI_CON);
  848. DUMPREG(HDMI_AVI_HEADER0);
  849. DUMPREG(HDMI_AVI_HEADER1);
  850. DUMPREG(HDMI_AVI_HEADER2);
  851. DUMPREG(HDMI_AVI_CHECK_SUM);
  852. DUMPREG(HDMI_VSI_CON);
  853. DUMPREG(HDMI_VSI_HEADER0);
  854. DUMPREG(HDMI_VSI_HEADER1);
  855. DUMPREG(HDMI_VSI_HEADER2);
  856. for (i = 0; i < 7; ++i)
  857. DUMPREG(HDMI_VSI_DATA(i));
  858. #undef DUMPREG
  859. }
  860. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  861. {
  862. if (hdata->type == HDMI_TYPE13)
  863. hdmi_v13_regs_dump(hdata, prefix);
  864. else
  865. hdmi_v14_regs_dump(hdata, prefix);
  866. }
  867. static u8 hdmi_chksum(struct hdmi_context *hdata,
  868. u32 start, u8 len, u32 hdr_sum)
  869. {
  870. int i;
  871. /* hdr_sum : header0 + header1 + header2
  872. * start : start address of packet byte1
  873. * len : packet bytes - 1 */
  874. for (i = 0; i < len; ++i)
  875. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  876. /* return 2's complement of 8 bit hdr_sum */
  877. return (u8)(~(hdr_sum & 0xff) + 1);
  878. }
  879. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  880. union hdmi_infoframe *infoframe)
  881. {
  882. u32 hdr_sum;
  883. u8 chksum;
  884. u32 mod;
  885. u32 vic;
  886. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  887. if (hdata->dvi_mode) {
  888. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  889. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  890. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  891. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  892. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  893. return;
  894. }
  895. switch (infoframe->any.type) {
  896. case HDMI_INFOFRAME_TYPE_AVI:
  897. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  898. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
  899. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
  900. infoframe->any.version);
  901. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
  902. hdr_sum = infoframe->any.type + infoframe->any.version +
  903. infoframe->any.length;
  904. /* Output format zero hardcoded ,RGB YBCR selection */
  905. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  906. AVI_ACTIVE_FORMAT_VALID |
  907. AVI_UNDERSCANNED_DISPLAY_VALID);
  908. /*
  909. * Set the aspect ratio as per the mode, mentioned in
  910. * Table 9 AVI InfoFrame Data Byte 2 of CEA-861-D Standard
  911. */
  912. switch (hdata->mode_conf.aspect_ratio) {
  913. case HDMI_PICTURE_ASPECT_4_3:
  914. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  915. hdata->mode_conf.aspect_ratio |
  916. AVI_4_3_CENTER_RATIO);
  917. break;
  918. case HDMI_PICTURE_ASPECT_16_9:
  919. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  920. hdata->mode_conf.aspect_ratio |
  921. AVI_16_9_CENTER_RATIO);
  922. break;
  923. case HDMI_PICTURE_ASPECT_NONE:
  924. default:
  925. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2),
  926. hdata->mode_conf.aspect_ratio |
  927. AVI_SAME_AS_PIC_ASPECT_RATIO);
  928. break;
  929. }
  930. vic = hdata->mode_conf.cea_video_id;
  931. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  932. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  933. infoframe->any.length, hdr_sum);
  934. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  935. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  936. break;
  937. case HDMI_INFOFRAME_TYPE_AUDIO:
  938. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  939. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
  940. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
  941. infoframe->any.version);
  942. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
  943. hdr_sum = infoframe->any.type + infoframe->any.version +
  944. infoframe->any.length;
  945. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  946. infoframe->any.length, hdr_sum);
  947. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  948. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  949. break;
  950. default:
  951. break;
  952. }
  953. }
  954. static enum drm_connector_status hdmi_detect(struct drm_connector *connector,
  955. bool force)
  956. {
  957. struct hdmi_context *hdata = ctx_from_connector(connector);
  958. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  959. return hdata->hpd ? connector_status_connected :
  960. connector_status_disconnected;
  961. }
  962. static void hdmi_connector_destroy(struct drm_connector *connector)
  963. {
  964. }
  965. static struct drm_connector_funcs hdmi_connector_funcs = {
  966. .dpms = drm_helper_connector_dpms,
  967. .fill_modes = drm_helper_probe_single_connector_modes,
  968. .detect = hdmi_detect,
  969. .destroy = hdmi_connector_destroy,
  970. };
  971. static int hdmi_get_modes(struct drm_connector *connector)
  972. {
  973. struct hdmi_context *hdata = ctx_from_connector(connector);
  974. struct edid *edid;
  975. if (!hdata->ddc_adpt)
  976. return -ENODEV;
  977. edid = drm_get_edid(connector, hdata->ddc_adpt);
  978. if (!edid)
  979. return -ENODEV;
  980. hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
  981. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  982. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  983. edid->width_cm, edid->height_cm);
  984. drm_mode_connector_update_edid_property(connector, edid);
  985. return drm_add_edid_modes(connector, edid);
  986. }
  987. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  988. {
  989. int i;
  990. for (i = 0; i < hdata->phy_conf_count; i++)
  991. if (hdata->phy_confs[i].pixel_clock == pixel_clock)
  992. return i;
  993. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  994. return -EINVAL;
  995. }
  996. static int hdmi_mode_valid(struct drm_connector *connector,
  997. struct drm_display_mode *mode)
  998. {
  999. struct hdmi_context *hdata = ctx_from_connector(connector);
  1000. int ret;
  1001. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  1002. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  1003. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  1004. false, mode->clock * 1000);
  1005. ret = mixer_check_mode(mode);
  1006. if (ret)
  1007. return MODE_BAD;
  1008. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  1009. if (ret < 0)
  1010. return MODE_BAD;
  1011. return MODE_OK;
  1012. }
  1013. static struct drm_encoder *hdmi_best_encoder(struct drm_connector *connector)
  1014. {
  1015. struct hdmi_context *hdata = ctx_from_connector(connector);
  1016. return hdata->encoder;
  1017. }
  1018. static struct drm_connector_helper_funcs hdmi_connector_helper_funcs = {
  1019. .get_modes = hdmi_get_modes,
  1020. .mode_valid = hdmi_mode_valid,
  1021. .best_encoder = hdmi_best_encoder,
  1022. };
  1023. static int hdmi_create_connector(struct exynos_drm_display *display,
  1024. struct drm_encoder *encoder)
  1025. {
  1026. struct hdmi_context *hdata = display->ctx;
  1027. struct drm_connector *connector = &hdata->connector;
  1028. int ret;
  1029. hdata->encoder = encoder;
  1030. connector->interlace_allowed = true;
  1031. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1032. ret = drm_connector_init(hdata->drm_dev, connector,
  1033. &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
  1034. if (ret) {
  1035. DRM_ERROR("Failed to initialize connector with drm\n");
  1036. return ret;
  1037. }
  1038. drm_connector_helper_add(connector, &hdmi_connector_helper_funcs);
  1039. drm_connector_register(connector);
  1040. drm_mode_connector_attach_encoder(connector, encoder);
  1041. return 0;
  1042. }
  1043. static void hdmi_mode_fixup(struct exynos_drm_display *display,
  1044. struct drm_connector *connector,
  1045. const struct drm_display_mode *mode,
  1046. struct drm_display_mode *adjusted_mode)
  1047. {
  1048. struct drm_display_mode *m;
  1049. int mode_ok;
  1050. DRM_DEBUG_KMS("%s\n", __FILE__);
  1051. drm_mode_set_crtcinfo(adjusted_mode, 0);
  1052. mode_ok = hdmi_mode_valid(connector, adjusted_mode);
  1053. /* just return if user desired mode exists. */
  1054. if (mode_ok == MODE_OK)
  1055. return;
  1056. /*
  1057. * otherwise, find the most suitable mode among modes and change it
  1058. * to adjusted_mode.
  1059. */
  1060. list_for_each_entry(m, &connector->modes, head) {
  1061. mode_ok = hdmi_mode_valid(connector, m);
  1062. if (mode_ok == MODE_OK) {
  1063. DRM_INFO("desired mode doesn't exist so\n");
  1064. DRM_INFO("use the most suitable mode among modes.\n");
  1065. DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
  1066. m->hdisplay, m->vdisplay, m->vrefresh);
  1067. drm_mode_copy(adjusted_mode, m);
  1068. break;
  1069. }
  1070. }
  1071. }
  1072. static void hdmi_set_acr(u32 freq, u8 *acr)
  1073. {
  1074. u32 n, cts;
  1075. switch (freq) {
  1076. case 32000:
  1077. n = 4096;
  1078. cts = 27000;
  1079. break;
  1080. case 44100:
  1081. n = 6272;
  1082. cts = 30000;
  1083. break;
  1084. case 88200:
  1085. n = 12544;
  1086. cts = 30000;
  1087. break;
  1088. case 176400:
  1089. n = 25088;
  1090. cts = 30000;
  1091. break;
  1092. case 48000:
  1093. n = 6144;
  1094. cts = 27000;
  1095. break;
  1096. case 96000:
  1097. n = 12288;
  1098. cts = 27000;
  1099. break;
  1100. case 192000:
  1101. n = 24576;
  1102. cts = 27000;
  1103. break;
  1104. default:
  1105. n = 0;
  1106. cts = 0;
  1107. break;
  1108. }
  1109. acr[1] = cts >> 16;
  1110. acr[2] = cts >> 8 & 0xff;
  1111. acr[3] = cts & 0xff;
  1112. acr[4] = n >> 16;
  1113. acr[5] = n >> 8 & 0xff;
  1114. acr[6] = n & 0xff;
  1115. }
  1116. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  1117. {
  1118. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  1119. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  1120. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  1121. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  1122. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  1123. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  1124. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  1125. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  1126. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  1127. if (hdata->type == HDMI_TYPE13)
  1128. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  1129. else
  1130. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  1131. }
  1132. static void hdmi_audio_init(struct hdmi_context *hdata)
  1133. {
  1134. u32 sample_rate, bits_per_sample;
  1135. u32 data_num, bit_ch, sample_frq;
  1136. u32 val;
  1137. u8 acr[7];
  1138. sample_rate = 44100;
  1139. bits_per_sample = 16;
  1140. switch (bits_per_sample) {
  1141. case 20:
  1142. data_num = 2;
  1143. bit_ch = 1;
  1144. break;
  1145. case 24:
  1146. data_num = 3;
  1147. bit_ch = 1;
  1148. break;
  1149. default:
  1150. data_num = 1;
  1151. bit_ch = 0;
  1152. break;
  1153. }
  1154. hdmi_set_acr(sample_rate, acr);
  1155. hdmi_reg_acr(hdata, acr);
  1156. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  1157. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  1158. | HDMI_I2S_MUX_ENABLE);
  1159. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  1160. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  1161. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  1162. sample_frq = (sample_rate == 44100) ? 0 :
  1163. (sample_rate == 48000) ? 2 :
  1164. (sample_rate == 32000) ? 3 :
  1165. (sample_rate == 96000) ? 0xa : 0x0;
  1166. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  1167. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  1168. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  1169. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  1170. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  1171. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  1172. | HDMI_I2S_SEL_LRCK(6));
  1173. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  1174. | HDMI_I2S_SEL_SDATA2(4));
  1175. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  1176. | HDMI_I2S_SEL_SDATA2(2));
  1177. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  1178. /* I2S_CON_1 & 2 */
  1179. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  1180. | HDMI_I2S_L_CH_LOW_POL);
  1181. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  1182. | HDMI_I2S_SET_BIT_CH(bit_ch)
  1183. | HDMI_I2S_SET_SDATA_BIT(data_num)
  1184. | HDMI_I2S_BASIC_FORMAT);
  1185. /* Configure register related to CUV information */
  1186. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  1187. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  1188. | HDMI_I2S_COPYRIGHT
  1189. | HDMI_I2S_LINEAR_PCM
  1190. | HDMI_I2S_CONSUMER_FORMAT);
  1191. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  1192. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  1193. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  1194. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  1195. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  1196. HDMI_I2S_ORG_SMP_FREQ_44_1
  1197. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  1198. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  1199. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  1200. }
  1201. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  1202. {
  1203. if (hdata->dvi_mode)
  1204. return;
  1205. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  1206. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  1207. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  1208. }
  1209. static void hdmi_start(struct hdmi_context *hdata, bool start)
  1210. {
  1211. u32 val = start ? HDMI_TG_EN : 0;
  1212. if (hdata->current_mode.flags & DRM_MODE_FLAG_INTERLACE)
  1213. val |= HDMI_FIELD_EN;
  1214. hdmi_reg_writemask(hdata, HDMI_CON_0, val, HDMI_EN);
  1215. hdmi_reg_writemask(hdata, HDMI_TG_CMD, val, HDMI_TG_EN | HDMI_FIELD_EN);
  1216. }
  1217. static void hdmi_conf_init(struct hdmi_context *hdata)
  1218. {
  1219. union hdmi_infoframe infoframe;
  1220. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  1221. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  1222. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  1223. /* choose HDMI mode */
  1224. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1225. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  1226. /* Apply Video preable and Guard band in HDMI mode only */
  1227. hdmi_reg_writeb(hdata, HDMI_CON_2, 0);
  1228. /* disable bluescreen */
  1229. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  1230. if (hdata->dvi_mode) {
  1231. /* choose DVI mode */
  1232. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1233. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  1234. hdmi_reg_writeb(hdata, HDMI_CON_2,
  1235. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  1236. }
  1237. if (hdata->type == HDMI_TYPE13) {
  1238. /* choose bluescreen (fecal) color */
  1239. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  1240. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1241. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1242. /* enable AVI packet every vsync, fixes purple line problem */
  1243. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1244. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1245. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1246. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1247. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1248. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1249. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1250. } else {
  1251. infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
  1252. infoframe.any.version = HDMI_AVI_VERSION;
  1253. infoframe.any.length = HDMI_AVI_LENGTH;
  1254. hdmi_reg_infoframe(hdata, &infoframe);
  1255. infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
  1256. infoframe.any.version = HDMI_AUI_VERSION;
  1257. infoframe.any.length = HDMI_AUI_LENGTH;
  1258. hdmi_reg_infoframe(hdata, &infoframe);
  1259. /* enable AVI packet every vsync, fixes purple line problem */
  1260. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1261. }
  1262. }
  1263. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  1264. {
  1265. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1266. const struct hdmi_v13_core_regs *core =
  1267. &hdata->mode_conf.conf.v13_conf.core;
  1268. int tries;
  1269. /* setting core registers */
  1270. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1271. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1272. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  1273. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  1274. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  1275. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  1276. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  1277. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  1278. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1279. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1280. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  1281. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  1282. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  1283. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  1284. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  1285. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  1286. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  1287. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  1288. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  1289. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  1290. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  1291. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  1292. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  1293. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  1294. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  1295. /* Timing generator registers */
  1296. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1297. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1298. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1299. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1300. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1301. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1302. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1303. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1304. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1305. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1306. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1307. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1308. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1309. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1310. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1311. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1312. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1313. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1314. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1315. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1316. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1317. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1318. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1319. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1320. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1321. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1322. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1323. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1324. /* waiting for HDMIPHY's PLL to get to steady state */
  1325. for (tries = 100; tries; --tries) {
  1326. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  1327. if (val & HDMI_PHY_STATUS_READY)
  1328. break;
  1329. usleep_range(1000, 2000);
  1330. }
  1331. /* steady state not achieved */
  1332. if (tries == 0) {
  1333. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1334. hdmi_regs_dump(hdata, "timing apply");
  1335. }
  1336. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1337. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1338. clk_prepare_enable(hdata->res.sclk_hdmi);
  1339. /* enable HDMI and timing generator */
  1340. hdmi_start(hdata, true);
  1341. }
  1342. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1343. {
  1344. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1345. const struct hdmi_v14_core_regs *core =
  1346. &hdata->mode_conf.conf.v14_conf.core;
  1347. int tries;
  1348. /* setting core registers */
  1349. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1350. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1351. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1352. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1353. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1354. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1355. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1356. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1357. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1358. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1359. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1360. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1361. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1362. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1363. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1364. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1365. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1366. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1367. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1368. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1369. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1370. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1371. core->v_sync_line_bef_2[0]);
  1372. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1373. core->v_sync_line_bef_2[1]);
  1374. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1375. core->v_sync_line_bef_1[0]);
  1376. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1377. core->v_sync_line_bef_1[1]);
  1378. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1379. core->v_sync_line_aft_2[0]);
  1380. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1381. core->v_sync_line_aft_2[1]);
  1382. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1383. core->v_sync_line_aft_1[0]);
  1384. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1385. core->v_sync_line_aft_1[1]);
  1386. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1387. core->v_sync_line_aft_pxl_2[0]);
  1388. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1389. core->v_sync_line_aft_pxl_2[1]);
  1390. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1391. core->v_sync_line_aft_pxl_1[0]);
  1392. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1393. core->v_sync_line_aft_pxl_1[1]);
  1394. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1395. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1396. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1397. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1398. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1399. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1400. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1401. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1402. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1403. core->v_sync_line_aft_3[0]);
  1404. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1405. core->v_sync_line_aft_3[1]);
  1406. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1407. core->v_sync_line_aft_4[0]);
  1408. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1409. core->v_sync_line_aft_4[1]);
  1410. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1411. core->v_sync_line_aft_5[0]);
  1412. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1413. core->v_sync_line_aft_5[1]);
  1414. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1415. core->v_sync_line_aft_6[0]);
  1416. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1417. core->v_sync_line_aft_6[1]);
  1418. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1419. core->v_sync_line_aft_pxl_3[0]);
  1420. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1421. core->v_sync_line_aft_pxl_3[1]);
  1422. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1423. core->v_sync_line_aft_pxl_4[0]);
  1424. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1425. core->v_sync_line_aft_pxl_4[1]);
  1426. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1427. core->v_sync_line_aft_pxl_5[0]);
  1428. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1429. core->v_sync_line_aft_pxl_5[1]);
  1430. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1431. core->v_sync_line_aft_pxl_6[0]);
  1432. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1433. core->v_sync_line_aft_pxl_6[1]);
  1434. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1435. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1436. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1437. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1438. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1439. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1440. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1441. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1442. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1443. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1444. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1445. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1446. /* Timing generator registers */
  1447. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1448. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1449. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1450. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1451. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1452. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1453. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1454. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1455. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1456. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1457. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1458. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1459. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1460. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1461. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1462. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1463. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1464. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1465. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1466. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1467. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3[0]);
  1468. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3[1]);
  1469. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4[0]);
  1470. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4[1]);
  1471. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1472. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1473. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1474. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1475. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1476. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1477. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1478. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1479. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d[0]);
  1480. /* waiting for HDMIPHY's PLL to get to steady state */
  1481. for (tries = 100; tries; --tries) {
  1482. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1483. if (val & HDMI_PHY_STATUS_READY)
  1484. break;
  1485. usleep_range(1000, 2000);
  1486. }
  1487. /* steady state not achieved */
  1488. if (tries == 0) {
  1489. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1490. hdmi_regs_dump(hdata, "timing apply");
  1491. }
  1492. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1493. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1494. clk_prepare_enable(hdata->res.sclk_hdmi);
  1495. /* enable HDMI and timing generator */
  1496. hdmi_start(hdata, true);
  1497. }
  1498. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1499. {
  1500. if (hdata->type == HDMI_TYPE13)
  1501. hdmi_v13_mode_apply(hdata);
  1502. else
  1503. hdmi_v14_mode_apply(hdata);
  1504. }
  1505. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1506. {
  1507. u8 buffer[2];
  1508. u32 reg;
  1509. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1510. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1511. clk_prepare_enable(hdata->res.sclk_hdmi);
  1512. /* operation mode */
  1513. buffer[0] = 0x1f;
  1514. buffer[1] = 0x00;
  1515. if (hdata->hdmiphy_port)
  1516. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1517. if (hdata->type == HDMI_TYPE13)
  1518. reg = HDMI_V13_PHY_RSTOUT;
  1519. else
  1520. reg = HDMI_PHY_RSTOUT;
  1521. /* reset hdmiphy */
  1522. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1523. usleep_range(10000, 12000);
  1524. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1525. usleep_range(10000, 12000);
  1526. }
  1527. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1528. {
  1529. if (hdata->type != HDMI_TYPE14)
  1530. return;
  1531. DRM_DEBUG_KMS("\n");
  1532. /* For PHY Mode Setting */
  1533. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1534. HDMI_PHY_ENABLE_MODE_SET);
  1535. /* Phy Power On */
  1536. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1537. HDMI_PHY_POWER_ON);
  1538. /* For PHY Mode Setting */
  1539. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1540. HDMI_PHY_DISABLE_MODE_SET);
  1541. /* PHY SW Reset */
  1542. hdmiphy_conf_reset(hdata);
  1543. }
  1544. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1545. {
  1546. if (hdata->type != HDMI_TYPE14)
  1547. return;
  1548. DRM_DEBUG_KMS("\n");
  1549. /* PHY SW Reset */
  1550. hdmiphy_conf_reset(hdata);
  1551. /* For PHY Mode Setting */
  1552. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1553. HDMI_PHY_ENABLE_MODE_SET);
  1554. /* PHY Power Off */
  1555. hdmiphy_reg_writeb(hdata, HDMIPHY_POWER,
  1556. HDMI_PHY_POWER_OFF);
  1557. /* For PHY Mode Setting */
  1558. hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1559. HDMI_PHY_DISABLE_MODE_SET);
  1560. }
  1561. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1562. {
  1563. int ret;
  1564. int i;
  1565. /* pixel clock */
  1566. i = hdmi_find_phy_conf(hdata, hdata->mode_conf.pixel_clock);
  1567. if (i < 0) {
  1568. DRM_ERROR("failed to find hdmiphy conf\n");
  1569. return;
  1570. }
  1571. ret = hdmiphy_reg_write_buf(hdata, 0, hdata->phy_confs[i].conf, 32);
  1572. if (ret) {
  1573. DRM_ERROR("failed to configure hdmiphy\n");
  1574. return;
  1575. }
  1576. usleep_range(10000, 12000);
  1577. ret = hdmiphy_reg_writeb(hdata, HDMIPHY_MODE_SET_DONE,
  1578. HDMI_PHY_DISABLE_MODE_SET);
  1579. if (ret) {
  1580. DRM_ERROR("failed to enable hdmiphy\n");
  1581. return;
  1582. }
  1583. }
  1584. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1585. {
  1586. hdmiphy_conf_reset(hdata);
  1587. hdmiphy_conf_apply(hdata);
  1588. mutex_lock(&hdata->hdmi_mutex);
  1589. hdmi_start(hdata, false);
  1590. hdmi_conf_init(hdata);
  1591. mutex_unlock(&hdata->hdmi_mutex);
  1592. hdmi_audio_init(hdata);
  1593. /* setting core registers */
  1594. hdmi_mode_apply(hdata);
  1595. hdmi_audio_control(hdata, true);
  1596. hdmi_regs_dump(hdata, "start");
  1597. }
  1598. static void hdmi_set_reg(u8 *reg_pair, int num_bytes, u32 value)
  1599. {
  1600. int i;
  1601. BUG_ON(num_bytes > 4);
  1602. for (i = 0; i < num_bytes; i++)
  1603. reg_pair[i] = (value >> (8 * i)) & 0xff;
  1604. }
  1605. static void hdmi_v13_mode_set(struct hdmi_context *hdata,
  1606. struct drm_display_mode *m)
  1607. {
  1608. struct hdmi_v13_core_regs *core = &hdata->mode_conf.conf.v13_conf.core;
  1609. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1610. unsigned int val;
  1611. hdata->mode_conf.cea_video_id =
  1612. drm_match_cea_mode((struct drm_display_mode *)m);
  1613. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1614. hdata->mode_conf.aspect_ratio = m->picture_aspect_ratio;
  1615. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1616. hdmi_set_reg(core->h_v_line, 3, (m->htotal << 12) | m->vtotal);
  1617. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1618. hdmi_set_reg(core->vsync_pol, 1, val);
  1619. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1620. hdmi_set_reg(core->int_pro_mode, 1, val);
  1621. val = (m->hsync_start - m->hdisplay - 2);
  1622. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1623. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1624. hdmi_set_reg(core->h_sync_gen, 3, val);
  1625. /*
  1626. * Quirk requirement for exynos HDMI IP design,
  1627. * 2 pixels less than the actual calculation for hsync_start
  1628. * and end.
  1629. */
  1630. /* Following values & calculations differ for different type of modes */
  1631. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1632. /* Interlaced Mode */
  1633. val = ((m->vsync_end - m->vdisplay) / 2);
  1634. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1635. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1636. val = m->vtotal / 2;
  1637. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1638. hdmi_set_reg(core->v_blank, 3, val);
  1639. val = (m->vtotal +
  1640. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1641. val |= m->vtotal << 11;
  1642. hdmi_set_reg(core->v_blank_f, 3, val);
  1643. val = ((m->vtotal / 2) + 7);
  1644. val |= ((m->vtotal / 2) + 2) << 12;
  1645. hdmi_set_reg(core->v_sync_gen2, 3, val);
  1646. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1647. val |= ((m->htotal / 2) +
  1648. (m->hsync_start - m->hdisplay)) << 12;
  1649. hdmi_set_reg(core->v_sync_gen3, 3, val);
  1650. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1651. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1652. hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
  1653. } else {
  1654. /* Progressive Mode */
  1655. val = m->vtotal;
  1656. val |= (m->vtotal - m->vdisplay) << 11;
  1657. hdmi_set_reg(core->v_blank, 3, val);
  1658. hdmi_set_reg(core->v_blank_f, 3, 0);
  1659. val = (m->vsync_end - m->vdisplay);
  1660. val |= ((m->vsync_start - m->vdisplay) << 12);
  1661. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1662. hdmi_set_reg(core->v_sync_gen2, 3, 0x1001);/* Reset value */
  1663. hdmi_set_reg(core->v_sync_gen3, 3, 0x1001);/* Reset value */
  1664. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1665. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1666. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1667. }
  1668. /* Timing generator registers */
  1669. hdmi_set_reg(tg->cmd, 1, 0x0);
  1670. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1671. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1672. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1673. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1674. hdmi_set_reg(tg->vsync, 2, 0x1);
  1675. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1676. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1677. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1678. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1679. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1680. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1681. hdmi_set_reg(tg->tg_3d, 1, 0x0); /* Not used */
  1682. }
  1683. static void hdmi_v14_mode_set(struct hdmi_context *hdata,
  1684. struct drm_display_mode *m)
  1685. {
  1686. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1687. struct hdmi_v14_core_regs *core =
  1688. &hdata->mode_conf.conf.v14_conf.core;
  1689. hdata->mode_conf.cea_video_id =
  1690. drm_match_cea_mode((struct drm_display_mode *)m);
  1691. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1692. hdata->mode_conf.aspect_ratio = m->picture_aspect_ratio;
  1693. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1694. hdmi_set_reg(core->v_line, 2, m->vtotal);
  1695. hdmi_set_reg(core->h_line, 2, m->htotal);
  1696. hdmi_set_reg(core->hsync_pol, 1,
  1697. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1698. hdmi_set_reg(core->vsync_pol, 1,
  1699. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1700. hdmi_set_reg(core->int_pro_mode, 1,
  1701. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1702. /*
  1703. * Quirk requirement for exynos 5 HDMI IP design,
  1704. * 2 pixels less than the actual calculation for hsync_start
  1705. * and end.
  1706. */
  1707. /* Following values & calculations differ for different type of modes */
  1708. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1709. /* Interlaced Mode */
  1710. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1711. (m->vsync_end - m->vdisplay) / 2);
  1712. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1713. (m->vsync_start - m->vdisplay) / 2);
  1714. hdmi_set_reg(core->v2_blank, 2, m->vtotal / 2);
  1715. hdmi_set_reg(core->v1_blank, 2, (m->vtotal - m->vdisplay) / 2);
  1716. hdmi_set_reg(core->v_blank_f0, 2, m->vtotal - m->vdisplay / 2);
  1717. hdmi_set_reg(core->v_blank_f1, 2, m->vtotal);
  1718. hdmi_set_reg(core->v_sync_line_aft_2, 2, (m->vtotal / 2) + 7);
  1719. hdmi_set_reg(core->v_sync_line_aft_1, 2, (m->vtotal / 2) + 2);
  1720. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
  1721. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1722. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
  1723. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1724. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1725. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1726. hdmi_set_reg(tg->vact_st2, 2, m->vtotal - m->vdisplay / 2);
  1727. hdmi_set_reg(tg->vsync2, 2, (m->vtotal / 2) + 1);
  1728. hdmi_set_reg(tg->vsync_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1729. hdmi_set_reg(tg->field_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1730. hdmi_set_reg(tg->vact_st3, 2, 0x0);
  1731. hdmi_set_reg(tg->vact_st4, 2, 0x0);
  1732. } else {
  1733. /* Progressive Mode */
  1734. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1735. m->vsync_end - m->vdisplay);
  1736. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1737. m->vsync_start - m->vdisplay);
  1738. hdmi_set_reg(core->v2_blank, 2, m->vtotal);
  1739. hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
  1740. hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
  1741. hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
  1742. hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
  1743. hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
  1744. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
  1745. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
  1746. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1747. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1748. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1749. hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
  1750. hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
  1751. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1752. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1753. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1754. }
  1755. /* Following values & calculations are same irrespective of mode type */
  1756. hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
  1757. hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
  1758. hdmi_set_reg(core->vact_space_1, 2, 0xffff);
  1759. hdmi_set_reg(core->vact_space_2, 2, 0xffff);
  1760. hdmi_set_reg(core->vact_space_3, 2, 0xffff);
  1761. hdmi_set_reg(core->vact_space_4, 2, 0xffff);
  1762. hdmi_set_reg(core->vact_space_5, 2, 0xffff);
  1763. hdmi_set_reg(core->vact_space_6, 2, 0xffff);
  1764. hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
  1765. hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
  1766. hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
  1767. hdmi_set_reg(core->v_blank_f5, 2, 0xffff);
  1768. hdmi_set_reg(core->v_sync_line_aft_3, 2, 0xffff);
  1769. hdmi_set_reg(core->v_sync_line_aft_4, 2, 0xffff);
  1770. hdmi_set_reg(core->v_sync_line_aft_5, 2, 0xffff);
  1771. hdmi_set_reg(core->v_sync_line_aft_6, 2, 0xffff);
  1772. hdmi_set_reg(core->v_sync_line_aft_pxl_3, 2, 0xffff);
  1773. hdmi_set_reg(core->v_sync_line_aft_pxl_4, 2, 0xffff);
  1774. hdmi_set_reg(core->v_sync_line_aft_pxl_5, 2, 0xffff);
  1775. hdmi_set_reg(core->v_sync_line_aft_pxl_6, 2, 0xffff);
  1776. /* Timing generator registers */
  1777. hdmi_set_reg(tg->cmd, 1, 0x0);
  1778. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1779. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1780. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1781. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1782. hdmi_set_reg(tg->vsync, 2, 0x1);
  1783. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1784. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1785. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1786. hdmi_set_reg(tg->tg_3d, 1, 0x0);
  1787. }
  1788. static void hdmi_mode_set(struct exynos_drm_display *display,
  1789. struct drm_display_mode *mode)
  1790. {
  1791. struct hdmi_context *hdata = display->ctx;
  1792. struct drm_display_mode *m = mode;
  1793. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1794. m->hdisplay, m->vdisplay,
  1795. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1796. "INTERLACED" : "PROGERESSIVE");
  1797. /* preserve mode information for later use. */
  1798. drm_mode_copy(&hdata->current_mode, mode);
  1799. if (hdata->type == HDMI_TYPE13)
  1800. hdmi_v13_mode_set(hdata, mode);
  1801. else
  1802. hdmi_v14_mode_set(hdata, mode);
  1803. }
  1804. static void hdmi_commit(struct exynos_drm_display *display)
  1805. {
  1806. struct hdmi_context *hdata = display->ctx;
  1807. mutex_lock(&hdata->hdmi_mutex);
  1808. if (!hdata->powered) {
  1809. mutex_unlock(&hdata->hdmi_mutex);
  1810. return;
  1811. }
  1812. mutex_unlock(&hdata->hdmi_mutex);
  1813. hdmi_conf_apply(hdata);
  1814. }
  1815. static void hdmi_poweron(struct exynos_drm_display *display)
  1816. {
  1817. struct hdmi_context *hdata = display->ctx;
  1818. struct hdmi_resources *res = &hdata->res;
  1819. mutex_lock(&hdata->hdmi_mutex);
  1820. if (hdata->powered) {
  1821. mutex_unlock(&hdata->hdmi_mutex);
  1822. return;
  1823. }
  1824. hdata->powered = true;
  1825. mutex_unlock(&hdata->hdmi_mutex);
  1826. pm_runtime_get_sync(hdata->dev);
  1827. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1828. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1829. /* set pmu hdmiphy control bit to enable hdmiphy */
  1830. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1831. PMU_HDMI_PHY_ENABLE_BIT, 1);
  1832. clk_prepare_enable(res->hdmi);
  1833. clk_prepare_enable(res->sclk_hdmi);
  1834. hdmiphy_poweron(hdata);
  1835. hdmi_commit(display);
  1836. }
  1837. static void hdmi_poweroff(struct exynos_drm_display *display)
  1838. {
  1839. struct hdmi_context *hdata = display->ctx;
  1840. struct hdmi_resources *res = &hdata->res;
  1841. mutex_lock(&hdata->hdmi_mutex);
  1842. if (!hdata->powered)
  1843. goto out;
  1844. mutex_unlock(&hdata->hdmi_mutex);
  1845. /* HDMI System Disable */
  1846. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_EN);
  1847. hdmiphy_poweroff(hdata);
  1848. cancel_delayed_work(&hdata->hotplug_work);
  1849. clk_disable_unprepare(res->sclk_hdmi);
  1850. clk_disable_unprepare(res->hdmi);
  1851. /* reset pmu hdmiphy control bit to disable hdmiphy */
  1852. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1853. PMU_HDMI_PHY_ENABLE_BIT, 0);
  1854. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1855. pm_runtime_put_sync(hdata->dev);
  1856. mutex_lock(&hdata->hdmi_mutex);
  1857. hdata->powered = false;
  1858. out:
  1859. mutex_unlock(&hdata->hdmi_mutex);
  1860. }
  1861. static void hdmi_dpms(struct exynos_drm_display *display, int mode)
  1862. {
  1863. struct hdmi_context *hdata = display->ctx;
  1864. struct drm_encoder *encoder = hdata->encoder;
  1865. struct drm_crtc *crtc = encoder->crtc;
  1866. struct drm_crtc_helper_funcs *funcs = NULL;
  1867. DRM_DEBUG_KMS("mode %d\n", mode);
  1868. switch (mode) {
  1869. case DRM_MODE_DPMS_ON:
  1870. hdmi_poweron(display);
  1871. break;
  1872. case DRM_MODE_DPMS_STANDBY:
  1873. case DRM_MODE_DPMS_SUSPEND:
  1874. case DRM_MODE_DPMS_OFF:
  1875. /*
  1876. * The SFRs of VP and Mixer are updated by Vertical Sync of
  1877. * Timing generator which is a part of HDMI so the sequence
  1878. * to disable TV Subsystem should be as following,
  1879. * VP -> Mixer -> HDMI
  1880. *
  1881. * Below codes will try to disable Mixer and VP(if used)
  1882. * prior to disabling HDMI.
  1883. */
  1884. if (crtc)
  1885. funcs = crtc->helper_private;
  1886. if (funcs && funcs->dpms)
  1887. (*funcs->dpms)(crtc, mode);
  1888. hdmi_poweroff(display);
  1889. break;
  1890. default:
  1891. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  1892. break;
  1893. }
  1894. }
  1895. static struct exynos_drm_display_ops hdmi_display_ops = {
  1896. .create_connector = hdmi_create_connector,
  1897. .mode_fixup = hdmi_mode_fixup,
  1898. .mode_set = hdmi_mode_set,
  1899. .dpms = hdmi_dpms,
  1900. .commit = hdmi_commit,
  1901. };
  1902. static struct exynos_drm_display hdmi_display = {
  1903. .type = EXYNOS_DISPLAY_TYPE_HDMI,
  1904. .ops = &hdmi_display_ops,
  1905. };
  1906. static void hdmi_hotplug_work_func(struct work_struct *work)
  1907. {
  1908. struct hdmi_context *hdata;
  1909. hdata = container_of(work, struct hdmi_context, hotplug_work.work);
  1910. mutex_lock(&hdata->hdmi_mutex);
  1911. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1912. mutex_unlock(&hdata->hdmi_mutex);
  1913. if (hdata->drm_dev)
  1914. drm_helper_hpd_irq_event(hdata->drm_dev);
  1915. }
  1916. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1917. {
  1918. struct hdmi_context *hdata = arg;
  1919. mod_delayed_work(system_wq, &hdata->hotplug_work,
  1920. msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
  1921. return IRQ_HANDLED;
  1922. }
  1923. static int hdmi_resources_init(struct hdmi_context *hdata)
  1924. {
  1925. struct device *dev = hdata->dev;
  1926. struct hdmi_resources *res = &hdata->res;
  1927. static char *supply[] = {
  1928. "vdd",
  1929. "vdd_osc",
  1930. "vdd_pll",
  1931. };
  1932. int i, ret;
  1933. DRM_DEBUG_KMS("HDMI resource init\n");
  1934. /* get clocks, power */
  1935. res->hdmi = devm_clk_get(dev, "hdmi");
  1936. if (IS_ERR(res->hdmi)) {
  1937. DRM_ERROR("failed to get clock 'hdmi'\n");
  1938. ret = PTR_ERR(res->hdmi);
  1939. goto fail;
  1940. }
  1941. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1942. if (IS_ERR(res->sclk_hdmi)) {
  1943. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1944. ret = PTR_ERR(res->sclk_hdmi);
  1945. goto fail;
  1946. }
  1947. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1948. if (IS_ERR(res->sclk_pixel)) {
  1949. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1950. ret = PTR_ERR(res->sclk_pixel);
  1951. goto fail;
  1952. }
  1953. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1954. if (IS_ERR(res->sclk_hdmiphy)) {
  1955. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1956. ret = PTR_ERR(res->sclk_hdmiphy);
  1957. goto fail;
  1958. }
  1959. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1960. if (IS_ERR(res->mout_hdmi)) {
  1961. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1962. ret = PTR_ERR(res->mout_hdmi);
  1963. goto fail;
  1964. }
  1965. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1966. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1967. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1968. if (!res->regul_bulk) {
  1969. ret = -ENOMEM;
  1970. goto fail;
  1971. }
  1972. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1973. res->regul_bulk[i].supply = supply[i];
  1974. res->regul_bulk[i].consumer = NULL;
  1975. }
  1976. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1977. if (ret) {
  1978. DRM_ERROR("failed to get regulators\n");
  1979. return ret;
  1980. }
  1981. res->regul_count = ARRAY_SIZE(supply);
  1982. res->reg_hdmi_en = devm_regulator_get(dev, "hdmi-en");
  1983. if (IS_ERR(res->reg_hdmi_en) && PTR_ERR(res->reg_hdmi_en) != -ENOENT) {
  1984. DRM_ERROR("failed to get hdmi-en regulator\n");
  1985. return PTR_ERR(res->reg_hdmi_en);
  1986. }
  1987. if (!IS_ERR(res->reg_hdmi_en)) {
  1988. ret = regulator_enable(res->reg_hdmi_en);
  1989. if (ret) {
  1990. DRM_ERROR("failed to enable hdmi-en regulator\n");
  1991. return ret;
  1992. }
  1993. } else
  1994. res->reg_hdmi_en = NULL;
  1995. return ret;
  1996. fail:
  1997. DRM_ERROR("HDMI resource init - failed\n");
  1998. return ret;
  1999. }
  2000. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  2001. (struct device *dev)
  2002. {
  2003. struct device_node *np = dev->of_node;
  2004. struct s5p_hdmi_platform_data *pd;
  2005. u32 value;
  2006. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  2007. if (!pd)
  2008. goto err_data;
  2009. if (!of_find_property(np, "hpd-gpio", &value)) {
  2010. DRM_ERROR("no hpd gpio property found\n");
  2011. goto err_data;
  2012. }
  2013. pd->hpd_gpio = of_get_named_gpio(np, "hpd-gpio", 0);
  2014. return pd;
  2015. err_data:
  2016. return NULL;
  2017. }
  2018. static struct of_device_id hdmi_match_types[] = {
  2019. {
  2020. .compatible = "samsung,exynos5-hdmi",
  2021. .data = &exynos5_hdmi_driver_data,
  2022. }, {
  2023. .compatible = "samsung,exynos4210-hdmi",
  2024. .data = &exynos4210_hdmi_driver_data,
  2025. }, {
  2026. .compatible = "samsung,exynos4212-hdmi",
  2027. .data = &exynos4212_hdmi_driver_data,
  2028. }, {
  2029. .compatible = "samsung,exynos5420-hdmi",
  2030. .data = &exynos5420_hdmi_driver_data,
  2031. }, {
  2032. /* end node */
  2033. }
  2034. };
  2035. MODULE_DEVICE_TABLE (of, hdmi_match_types);
  2036. static int hdmi_bind(struct device *dev, struct device *master, void *data)
  2037. {
  2038. struct drm_device *drm_dev = data;
  2039. struct hdmi_context *hdata;
  2040. hdata = hdmi_display.ctx;
  2041. hdata->drm_dev = drm_dev;
  2042. return exynos_drm_create_enc_conn(drm_dev, &hdmi_display);
  2043. }
  2044. static void hdmi_unbind(struct device *dev, struct device *master, void *data)
  2045. {
  2046. struct exynos_drm_display *display = get_hdmi_display(dev);
  2047. struct drm_encoder *encoder = display->encoder;
  2048. struct hdmi_context *hdata = display->ctx;
  2049. encoder->funcs->destroy(encoder);
  2050. drm_connector_cleanup(&hdata->connector);
  2051. }
  2052. static const struct component_ops hdmi_component_ops = {
  2053. .bind = hdmi_bind,
  2054. .unbind = hdmi_unbind,
  2055. };
  2056. static struct device_node *hdmi_legacy_ddc_dt_binding(struct device *dev)
  2057. {
  2058. const char *compatible_str = "samsung,exynos4210-hdmiddc";
  2059. struct device_node *np;
  2060. np = of_find_compatible_node(NULL, NULL, compatible_str);
  2061. if (np)
  2062. return of_get_next_parent(np);
  2063. return NULL;
  2064. }
  2065. static struct device_node *hdmi_legacy_phy_dt_binding(struct device *dev)
  2066. {
  2067. const char *compatible_str = "samsung,exynos4212-hdmiphy";
  2068. return of_find_compatible_node(NULL, NULL, compatible_str);
  2069. }
  2070. static int hdmi_probe(struct platform_device *pdev)
  2071. {
  2072. struct device_node *ddc_node, *phy_node;
  2073. struct s5p_hdmi_platform_data *pdata;
  2074. struct hdmi_driver_data *drv_data;
  2075. const struct of_device_id *match;
  2076. struct device *dev = &pdev->dev;
  2077. struct hdmi_context *hdata;
  2078. struct resource *res;
  2079. int ret;
  2080. ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
  2081. hdmi_display.type);
  2082. if (ret)
  2083. return ret;
  2084. if (!dev->of_node) {
  2085. ret = -ENODEV;
  2086. goto err_del_component;
  2087. }
  2088. pdata = drm_hdmi_dt_parse_pdata(dev);
  2089. if (!pdata) {
  2090. ret = -EINVAL;
  2091. goto err_del_component;
  2092. }
  2093. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  2094. if (!hdata) {
  2095. ret = -ENOMEM;
  2096. goto err_del_component;
  2097. }
  2098. mutex_init(&hdata->hdmi_mutex);
  2099. platform_set_drvdata(pdev, &hdmi_display);
  2100. match = of_match_node(hdmi_match_types, dev->of_node);
  2101. if (!match) {
  2102. ret = -ENODEV;
  2103. goto err_del_component;
  2104. }
  2105. drv_data = (struct hdmi_driver_data *)match->data;
  2106. hdata->type = drv_data->type;
  2107. hdata->phy_confs = drv_data->phy_confs;
  2108. hdata->phy_conf_count = drv_data->phy_conf_count;
  2109. hdata->hpd_gpio = pdata->hpd_gpio;
  2110. hdata->dev = dev;
  2111. ret = hdmi_resources_init(hdata);
  2112. if (ret) {
  2113. DRM_ERROR("hdmi_resources_init failed\n");
  2114. return ret;
  2115. }
  2116. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2117. hdata->regs = devm_ioremap_resource(dev, res);
  2118. if (IS_ERR(hdata->regs)) {
  2119. ret = PTR_ERR(hdata->regs);
  2120. goto err_del_component;
  2121. }
  2122. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  2123. if (ret) {
  2124. DRM_ERROR("failed to request HPD gpio\n");
  2125. goto err_del_component;
  2126. }
  2127. ddc_node = hdmi_legacy_ddc_dt_binding(dev);
  2128. if (ddc_node)
  2129. goto out_get_ddc_adpt;
  2130. /* DDC i2c driver */
  2131. ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
  2132. if (!ddc_node) {
  2133. DRM_ERROR("Failed to find ddc node in device tree\n");
  2134. ret = -ENODEV;
  2135. goto err_del_component;
  2136. }
  2137. out_get_ddc_adpt:
  2138. hdata->ddc_adpt = of_find_i2c_adapter_by_node(ddc_node);
  2139. if (!hdata->ddc_adpt) {
  2140. DRM_ERROR("Failed to get ddc i2c adapter by node\n");
  2141. return -EPROBE_DEFER;
  2142. }
  2143. phy_node = hdmi_legacy_phy_dt_binding(dev);
  2144. if (phy_node)
  2145. goto out_get_phy_port;
  2146. /* hdmiphy i2c driver */
  2147. phy_node = of_parse_phandle(dev->of_node, "phy", 0);
  2148. if (!phy_node) {
  2149. DRM_ERROR("Failed to find hdmiphy node in device tree\n");
  2150. ret = -ENODEV;
  2151. goto err_ddc;
  2152. }
  2153. out_get_phy_port:
  2154. if (drv_data->is_apb_phy) {
  2155. hdata->regs_hdmiphy = of_iomap(phy_node, 0);
  2156. if (!hdata->regs_hdmiphy) {
  2157. DRM_ERROR("failed to ioremap hdmi phy\n");
  2158. ret = -ENOMEM;
  2159. goto err_ddc;
  2160. }
  2161. } else {
  2162. hdata->hdmiphy_port = of_find_i2c_device_by_node(phy_node);
  2163. if (!hdata->hdmiphy_port) {
  2164. DRM_ERROR("Failed to get hdmi phy i2c client\n");
  2165. ret = -EPROBE_DEFER;
  2166. goto err_ddc;
  2167. }
  2168. }
  2169. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  2170. if (hdata->irq < 0) {
  2171. DRM_ERROR("failed to get GPIO irq\n");
  2172. ret = hdata->irq;
  2173. goto err_hdmiphy;
  2174. }
  2175. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  2176. INIT_DELAYED_WORK(&hdata->hotplug_work, hdmi_hotplug_work_func);
  2177. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  2178. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  2179. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  2180. "hdmi", hdata);
  2181. if (ret) {
  2182. DRM_ERROR("failed to register hdmi interrupt\n");
  2183. goto err_hdmiphy;
  2184. }
  2185. hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  2186. "samsung,syscon-phandle");
  2187. if (IS_ERR(hdata->pmureg)) {
  2188. DRM_ERROR("syscon regmap lookup failed.\n");
  2189. ret = -EPROBE_DEFER;
  2190. goto err_hdmiphy;
  2191. }
  2192. pm_runtime_enable(dev);
  2193. hdmi_display.ctx = hdata;
  2194. ret = component_add(&pdev->dev, &hdmi_component_ops);
  2195. if (ret)
  2196. goto err_disable_pm_runtime;
  2197. return ret;
  2198. err_disable_pm_runtime:
  2199. pm_runtime_disable(dev);
  2200. err_hdmiphy:
  2201. if (hdata->hdmiphy_port)
  2202. put_device(&hdata->hdmiphy_port->dev);
  2203. err_ddc:
  2204. put_device(&hdata->ddc_adpt->dev);
  2205. err_del_component:
  2206. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  2207. return ret;
  2208. }
  2209. static int hdmi_remove(struct platform_device *pdev)
  2210. {
  2211. struct hdmi_context *hdata = hdmi_display.ctx;
  2212. cancel_delayed_work_sync(&hdata->hotplug_work);
  2213. if (hdata->res.reg_hdmi_en)
  2214. regulator_disable(hdata->res.reg_hdmi_en);
  2215. if (hdata->hdmiphy_port)
  2216. put_device(&hdata->hdmiphy_port->dev);
  2217. put_device(&hdata->ddc_adpt->dev);
  2218. pm_runtime_disable(&pdev->dev);
  2219. component_del(&pdev->dev, &hdmi_component_ops);
  2220. exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
  2221. return 0;
  2222. }
  2223. struct platform_driver hdmi_driver = {
  2224. .probe = hdmi_probe,
  2225. .remove = hdmi_remove,
  2226. .driver = {
  2227. .name = "exynos-hdmi",
  2228. .owner = THIS_MODULE,
  2229. .of_match_table = hdmi_match_types,
  2230. },
  2231. };