exynos_hdmi.c 72 KB

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