exynos_hdmi.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084
  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_gpio.h>
  34. #include <linux/hdmi.h>
  35. #include <drm/exynos_drm.h>
  36. #include "exynos_drm_drv.h"
  37. #include "exynos_drm_hdmi.h"
  38. #include "exynos_hdmi.h"
  39. #include <linux/gpio.h>
  40. #include <media/s5p_hdmi.h>
  41. #define MAX_WIDTH 1920
  42. #define MAX_HEIGHT 1080
  43. #define get_hdmi_context(dev) platform_get_drvdata(to_platform_device(dev))
  44. /* AVI header and aspect ratio */
  45. #define HDMI_AVI_VERSION 0x02
  46. #define HDMI_AVI_LENGTH 0x0D
  47. #define AVI_PIC_ASPECT_RATIO_16_9 (2 << 4)
  48. #define AVI_SAME_AS_PIC_ASPECT_RATIO 8
  49. /* AUI header info */
  50. #define HDMI_AUI_VERSION 0x01
  51. #define HDMI_AUI_LENGTH 0x0A
  52. enum hdmi_type {
  53. HDMI_TYPE13,
  54. HDMI_TYPE14,
  55. };
  56. struct hdmi_resources {
  57. struct clk *hdmi;
  58. struct clk *sclk_hdmi;
  59. struct clk *sclk_pixel;
  60. struct clk *sclk_hdmiphy;
  61. struct clk *hdmiphy;
  62. struct clk *mout_hdmi;
  63. struct regulator_bulk_data *regul_bulk;
  64. int regul_count;
  65. };
  66. struct hdmi_tg_regs {
  67. u8 cmd[1];
  68. u8 h_fsz[2];
  69. u8 hact_st[2];
  70. u8 hact_sz[2];
  71. u8 v_fsz[2];
  72. u8 vsync[2];
  73. u8 vsync2[2];
  74. u8 vact_st[2];
  75. u8 vact_sz[2];
  76. u8 field_chg[2];
  77. u8 vact_st2[2];
  78. u8 vact_st3[2];
  79. u8 vact_st4[2];
  80. u8 vsync_top_hdmi[2];
  81. u8 vsync_bot_hdmi[2];
  82. u8 field_top_hdmi[2];
  83. u8 field_bot_hdmi[2];
  84. u8 tg_3d[1];
  85. };
  86. struct hdmi_v13_core_regs {
  87. u8 h_blank[2];
  88. u8 v_blank[3];
  89. u8 h_v_line[3];
  90. u8 vsync_pol[1];
  91. u8 int_pro_mode[1];
  92. u8 v_blank_f[3];
  93. u8 h_sync_gen[3];
  94. u8 v_sync_gen1[3];
  95. u8 v_sync_gen2[3];
  96. u8 v_sync_gen3[3];
  97. };
  98. struct hdmi_v14_core_regs {
  99. u8 h_blank[2];
  100. u8 v2_blank[2];
  101. u8 v1_blank[2];
  102. u8 v_line[2];
  103. u8 h_line[2];
  104. u8 hsync_pol[1];
  105. u8 vsync_pol[1];
  106. u8 int_pro_mode[1];
  107. u8 v_blank_f0[2];
  108. u8 v_blank_f1[2];
  109. u8 h_sync_start[2];
  110. u8 h_sync_end[2];
  111. u8 v_sync_line_bef_2[2];
  112. u8 v_sync_line_bef_1[2];
  113. u8 v_sync_line_aft_2[2];
  114. u8 v_sync_line_aft_1[2];
  115. u8 v_sync_line_aft_pxl_2[2];
  116. u8 v_sync_line_aft_pxl_1[2];
  117. u8 v_blank_f2[2]; /* for 3D mode */
  118. u8 v_blank_f3[2]; /* for 3D mode */
  119. u8 v_blank_f4[2]; /* for 3D mode */
  120. u8 v_blank_f5[2]; /* for 3D mode */
  121. u8 v_sync_line_aft_3[2];
  122. u8 v_sync_line_aft_4[2];
  123. u8 v_sync_line_aft_5[2];
  124. u8 v_sync_line_aft_6[2];
  125. u8 v_sync_line_aft_pxl_3[2];
  126. u8 v_sync_line_aft_pxl_4[2];
  127. u8 v_sync_line_aft_pxl_5[2];
  128. u8 v_sync_line_aft_pxl_6[2];
  129. u8 vact_space_1[2];
  130. u8 vact_space_2[2];
  131. u8 vact_space_3[2];
  132. u8 vact_space_4[2];
  133. u8 vact_space_5[2];
  134. u8 vact_space_6[2];
  135. };
  136. struct hdmi_v13_conf {
  137. struct hdmi_v13_core_regs core;
  138. struct hdmi_tg_regs tg;
  139. };
  140. struct hdmi_v14_conf {
  141. struct hdmi_v14_core_regs core;
  142. struct hdmi_tg_regs tg;
  143. };
  144. struct hdmi_conf_regs {
  145. int pixel_clock;
  146. int cea_video_id;
  147. union {
  148. struct hdmi_v13_conf v13_conf;
  149. struct hdmi_v14_conf v14_conf;
  150. } conf;
  151. };
  152. struct hdmi_context {
  153. struct device *dev;
  154. struct drm_device *drm_dev;
  155. bool hpd;
  156. bool powered;
  157. bool dvi_mode;
  158. struct mutex hdmi_mutex;
  159. void __iomem *regs;
  160. void *parent_ctx;
  161. int irq;
  162. struct i2c_client *ddc_port;
  163. struct i2c_client *hdmiphy_port;
  164. /* current hdmiphy conf regs */
  165. struct hdmi_conf_regs mode_conf;
  166. struct hdmi_resources res;
  167. int hpd_gpio;
  168. enum hdmi_type type;
  169. };
  170. struct hdmiphy_config {
  171. int pixel_clock;
  172. u8 conf[32];
  173. };
  174. /* list of phy config settings */
  175. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  176. {
  177. .pixel_clock = 27000000,
  178. .conf = {
  179. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  180. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  181. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  182. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  183. },
  184. },
  185. {
  186. .pixel_clock = 27027000,
  187. .conf = {
  188. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  189. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  190. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  191. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x00,
  192. },
  193. },
  194. {
  195. .pixel_clock = 74176000,
  196. .conf = {
  197. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  198. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  199. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  200. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x00,
  201. },
  202. },
  203. {
  204. .pixel_clock = 74250000,
  205. .conf = {
  206. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  207. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  208. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  209. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x00,
  210. },
  211. },
  212. {
  213. .pixel_clock = 148500000,
  214. .conf = {
  215. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  216. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  217. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  218. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x00,
  219. },
  220. },
  221. };
  222. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  223. {
  224. .pixel_clock = 25200000,
  225. .conf = {
  226. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  227. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  228. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  229. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  230. },
  231. },
  232. {
  233. .pixel_clock = 27000000,
  234. .conf = {
  235. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  236. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  237. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  238. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  239. },
  240. },
  241. {
  242. .pixel_clock = 27027000,
  243. .conf = {
  244. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  245. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  246. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  247. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00,
  248. },
  249. },
  250. {
  251. .pixel_clock = 36000000,
  252. .conf = {
  253. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  254. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  255. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  256. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  257. },
  258. },
  259. {
  260. .pixel_clock = 40000000,
  261. .conf = {
  262. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  263. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  264. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  265. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  266. },
  267. },
  268. {
  269. .pixel_clock = 65000000,
  270. .conf = {
  271. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  272. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  273. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  274. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  275. },
  276. },
  277. {
  278. .pixel_clock = 74176000,
  279. .conf = {
  280. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  281. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  282. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  283. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  284. },
  285. },
  286. {
  287. .pixel_clock = 74250000,
  288. .conf = {
  289. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  290. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  291. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  292. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x00,
  293. },
  294. },
  295. {
  296. .pixel_clock = 83500000,
  297. .conf = {
  298. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  299. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  300. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  301. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  302. },
  303. },
  304. {
  305. .pixel_clock = 106500000,
  306. .conf = {
  307. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  308. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  309. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  310. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  311. },
  312. },
  313. {
  314. .pixel_clock = 108000000,
  315. .conf = {
  316. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  317. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  318. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  319. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  320. },
  321. },
  322. {
  323. .pixel_clock = 146250000,
  324. .conf = {
  325. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  326. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  327. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  328. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  329. },
  330. },
  331. {
  332. .pixel_clock = 148500000,
  333. .conf = {
  334. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  335. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  336. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  337. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x00,
  338. },
  339. },
  340. };
  341. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  342. {
  343. return readl(hdata->regs + reg_id);
  344. }
  345. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  346. u32 reg_id, u8 value)
  347. {
  348. writeb(value, hdata->regs + reg_id);
  349. }
  350. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  351. u32 reg_id, u32 value, u32 mask)
  352. {
  353. u32 old = readl(hdata->regs + reg_id);
  354. value = (value & mask) | (old & ~mask);
  355. writel(value, hdata->regs + reg_id);
  356. }
  357. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  358. {
  359. #define DUMPREG(reg_id) \
  360. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  361. readl(hdata->regs + reg_id))
  362. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  363. DUMPREG(HDMI_INTC_FLAG);
  364. DUMPREG(HDMI_INTC_CON);
  365. DUMPREG(HDMI_HPD_STATUS);
  366. DUMPREG(HDMI_V13_PHY_RSTOUT);
  367. DUMPREG(HDMI_V13_PHY_VPLL);
  368. DUMPREG(HDMI_V13_PHY_CMU);
  369. DUMPREG(HDMI_V13_CORE_RSTOUT);
  370. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  371. DUMPREG(HDMI_CON_0);
  372. DUMPREG(HDMI_CON_1);
  373. DUMPREG(HDMI_CON_2);
  374. DUMPREG(HDMI_SYS_STATUS);
  375. DUMPREG(HDMI_V13_PHY_STATUS);
  376. DUMPREG(HDMI_STATUS_EN);
  377. DUMPREG(HDMI_HPD);
  378. DUMPREG(HDMI_MODE_SEL);
  379. DUMPREG(HDMI_V13_HPD_GEN);
  380. DUMPREG(HDMI_V13_DC_CONTROL);
  381. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  382. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  383. DUMPREG(HDMI_H_BLANK_0);
  384. DUMPREG(HDMI_H_BLANK_1);
  385. DUMPREG(HDMI_V13_V_BLANK_0);
  386. DUMPREG(HDMI_V13_V_BLANK_1);
  387. DUMPREG(HDMI_V13_V_BLANK_2);
  388. DUMPREG(HDMI_V13_H_V_LINE_0);
  389. DUMPREG(HDMI_V13_H_V_LINE_1);
  390. DUMPREG(HDMI_V13_H_V_LINE_2);
  391. DUMPREG(HDMI_VSYNC_POL);
  392. DUMPREG(HDMI_INT_PRO_MODE);
  393. DUMPREG(HDMI_V13_V_BLANK_F_0);
  394. DUMPREG(HDMI_V13_V_BLANK_F_1);
  395. DUMPREG(HDMI_V13_V_BLANK_F_2);
  396. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  397. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  398. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  399. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  400. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  401. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  402. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  403. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  404. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  405. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  406. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  407. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  408. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  409. DUMPREG(HDMI_TG_CMD);
  410. DUMPREG(HDMI_TG_H_FSZ_L);
  411. DUMPREG(HDMI_TG_H_FSZ_H);
  412. DUMPREG(HDMI_TG_HACT_ST_L);
  413. DUMPREG(HDMI_TG_HACT_ST_H);
  414. DUMPREG(HDMI_TG_HACT_SZ_L);
  415. DUMPREG(HDMI_TG_HACT_SZ_H);
  416. DUMPREG(HDMI_TG_V_FSZ_L);
  417. DUMPREG(HDMI_TG_V_FSZ_H);
  418. DUMPREG(HDMI_TG_VSYNC_L);
  419. DUMPREG(HDMI_TG_VSYNC_H);
  420. DUMPREG(HDMI_TG_VSYNC2_L);
  421. DUMPREG(HDMI_TG_VSYNC2_H);
  422. DUMPREG(HDMI_TG_VACT_ST_L);
  423. DUMPREG(HDMI_TG_VACT_ST_H);
  424. DUMPREG(HDMI_TG_VACT_SZ_L);
  425. DUMPREG(HDMI_TG_VACT_SZ_H);
  426. DUMPREG(HDMI_TG_FIELD_CHG_L);
  427. DUMPREG(HDMI_TG_FIELD_CHG_H);
  428. DUMPREG(HDMI_TG_VACT_ST2_L);
  429. DUMPREG(HDMI_TG_VACT_ST2_H);
  430. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  431. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  432. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  433. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  434. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  435. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  436. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  437. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  438. #undef DUMPREG
  439. }
  440. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  441. {
  442. int i;
  443. #define DUMPREG(reg_id) \
  444. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  445. readl(hdata->regs + reg_id))
  446. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  447. DUMPREG(HDMI_INTC_CON);
  448. DUMPREG(HDMI_INTC_FLAG);
  449. DUMPREG(HDMI_HPD_STATUS);
  450. DUMPREG(HDMI_INTC_CON_1);
  451. DUMPREG(HDMI_INTC_FLAG_1);
  452. DUMPREG(HDMI_PHY_STATUS_0);
  453. DUMPREG(HDMI_PHY_STATUS_PLL);
  454. DUMPREG(HDMI_PHY_CON_0);
  455. DUMPREG(HDMI_PHY_RSTOUT);
  456. DUMPREG(HDMI_PHY_VPLL);
  457. DUMPREG(HDMI_PHY_CMU);
  458. DUMPREG(HDMI_CORE_RSTOUT);
  459. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  460. DUMPREG(HDMI_CON_0);
  461. DUMPREG(HDMI_CON_1);
  462. DUMPREG(HDMI_CON_2);
  463. DUMPREG(HDMI_SYS_STATUS);
  464. DUMPREG(HDMI_PHY_STATUS_0);
  465. DUMPREG(HDMI_STATUS_EN);
  466. DUMPREG(HDMI_HPD);
  467. DUMPREG(HDMI_MODE_SEL);
  468. DUMPREG(HDMI_ENC_EN);
  469. DUMPREG(HDMI_DC_CONTROL);
  470. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  471. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  472. DUMPREG(HDMI_H_BLANK_0);
  473. DUMPREG(HDMI_H_BLANK_1);
  474. DUMPREG(HDMI_V2_BLANK_0);
  475. DUMPREG(HDMI_V2_BLANK_1);
  476. DUMPREG(HDMI_V1_BLANK_0);
  477. DUMPREG(HDMI_V1_BLANK_1);
  478. DUMPREG(HDMI_V_LINE_0);
  479. DUMPREG(HDMI_V_LINE_1);
  480. DUMPREG(HDMI_H_LINE_0);
  481. DUMPREG(HDMI_H_LINE_1);
  482. DUMPREG(HDMI_HSYNC_POL);
  483. DUMPREG(HDMI_VSYNC_POL);
  484. DUMPREG(HDMI_INT_PRO_MODE);
  485. DUMPREG(HDMI_V_BLANK_F0_0);
  486. DUMPREG(HDMI_V_BLANK_F0_1);
  487. DUMPREG(HDMI_V_BLANK_F1_0);
  488. DUMPREG(HDMI_V_BLANK_F1_1);
  489. DUMPREG(HDMI_H_SYNC_START_0);
  490. DUMPREG(HDMI_H_SYNC_START_1);
  491. DUMPREG(HDMI_H_SYNC_END_0);
  492. DUMPREG(HDMI_H_SYNC_END_1);
  493. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  494. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  495. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  496. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  497. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  498. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  499. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  500. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  501. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  502. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  503. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  504. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  505. DUMPREG(HDMI_V_BLANK_F2_0);
  506. DUMPREG(HDMI_V_BLANK_F2_1);
  507. DUMPREG(HDMI_V_BLANK_F3_0);
  508. DUMPREG(HDMI_V_BLANK_F3_1);
  509. DUMPREG(HDMI_V_BLANK_F4_0);
  510. DUMPREG(HDMI_V_BLANK_F4_1);
  511. DUMPREG(HDMI_V_BLANK_F5_0);
  512. DUMPREG(HDMI_V_BLANK_F5_1);
  513. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  514. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  515. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  516. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  517. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  518. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  519. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  520. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  521. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  522. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  523. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  524. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  525. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  526. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  527. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  528. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  529. DUMPREG(HDMI_VACT_SPACE_1_0);
  530. DUMPREG(HDMI_VACT_SPACE_1_1);
  531. DUMPREG(HDMI_VACT_SPACE_2_0);
  532. DUMPREG(HDMI_VACT_SPACE_2_1);
  533. DUMPREG(HDMI_VACT_SPACE_3_0);
  534. DUMPREG(HDMI_VACT_SPACE_3_1);
  535. DUMPREG(HDMI_VACT_SPACE_4_0);
  536. DUMPREG(HDMI_VACT_SPACE_4_1);
  537. DUMPREG(HDMI_VACT_SPACE_5_0);
  538. DUMPREG(HDMI_VACT_SPACE_5_1);
  539. DUMPREG(HDMI_VACT_SPACE_6_0);
  540. DUMPREG(HDMI_VACT_SPACE_6_1);
  541. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  542. DUMPREG(HDMI_TG_CMD);
  543. DUMPREG(HDMI_TG_H_FSZ_L);
  544. DUMPREG(HDMI_TG_H_FSZ_H);
  545. DUMPREG(HDMI_TG_HACT_ST_L);
  546. DUMPREG(HDMI_TG_HACT_ST_H);
  547. DUMPREG(HDMI_TG_HACT_SZ_L);
  548. DUMPREG(HDMI_TG_HACT_SZ_H);
  549. DUMPREG(HDMI_TG_V_FSZ_L);
  550. DUMPREG(HDMI_TG_V_FSZ_H);
  551. DUMPREG(HDMI_TG_VSYNC_L);
  552. DUMPREG(HDMI_TG_VSYNC_H);
  553. DUMPREG(HDMI_TG_VSYNC2_L);
  554. DUMPREG(HDMI_TG_VSYNC2_H);
  555. DUMPREG(HDMI_TG_VACT_ST_L);
  556. DUMPREG(HDMI_TG_VACT_ST_H);
  557. DUMPREG(HDMI_TG_VACT_SZ_L);
  558. DUMPREG(HDMI_TG_VACT_SZ_H);
  559. DUMPREG(HDMI_TG_FIELD_CHG_L);
  560. DUMPREG(HDMI_TG_FIELD_CHG_H);
  561. DUMPREG(HDMI_TG_VACT_ST2_L);
  562. DUMPREG(HDMI_TG_VACT_ST2_H);
  563. DUMPREG(HDMI_TG_VACT_ST3_L);
  564. DUMPREG(HDMI_TG_VACT_ST3_H);
  565. DUMPREG(HDMI_TG_VACT_ST4_L);
  566. DUMPREG(HDMI_TG_VACT_ST4_H);
  567. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  568. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  569. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  570. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  571. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  572. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  573. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  574. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  575. DUMPREG(HDMI_TG_3D);
  576. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  577. DUMPREG(HDMI_AVI_CON);
  578. DUMPREG(HDMI_AVI_HEADER0);
  579. DUMPREG(HDMI_AVI_HEADER1);
  580. DUMPREG(HDMI_AVI_HEADER2);
  581. DUMPREG(HDMI_AVI_CHECK_SUM);
  582. DUMPREG(HDMI_VSI_CON);
  583. DUMPREG(HDMI_VSI_HEADER0);
  584. DUMPREG(HDMI_VSI_HEADER1);
  585. DUMPREG(HDMI_VSI_HEADER2);
  586. for (i = 0; i < 7; ++i)
  587. DUMPREG(HDMI_VSI_DATA(i));
  588. #undef DUMPREG
  589. }
  590. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  591. {
  592. if (hdata->type == HDMI_TYPE13)
  593. hdmi_v13_regs_dump(hdata, prefix);
  594. else
  595. hdmi_v14_regs_dump(hdata, prefix);
  596. }
  597. static u8 hdmi_chksum(struct hdmi_context *hdata,
  598. u32 start, u8 len, u32 hdr_sum)
  599. {
  600. int i;
  601. /* hdr_sum : header0 + header1 + header2
  602. * start : start address of packet byte1
  603. * len : packet bytes - 1 */
  604. for (i = 0; i < len; ++i)
  605. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  606. /* return 2's complement of 8 bit hdr_sum */
  607. return (u8)(~(hdr_sum & 0xff) + 1);
  608. }
  609. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  610. union hdmi_infoframe *infoframe)
  611. {
  612. u32 hdr_sum;
  613. u8 chksum;
  614. u32 aspect_ratio;
  615. u32 mod;
  616. u32 vic;
  617. mod = hdmi_reg_read(hdata, HDMI_MODE_SEL);
  618. if (hdata->dvi_mode) {
  619. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  620. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  621. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  622. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  623. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  624. return;
  625. }
  626. switch (infoframe->any.type) {
  627. case HDMI_INFOFRAME_TYPE_AVI:
  628. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  629. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
  630. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
  631. infoframe->any.version);
  632. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
  633. hdr_sum = infoframe->any.type + infoframe->any.version +
  634. infoframe->any.length;
  635. /* Output format zero hardcoded ,RGB YBCR selection */
  636. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  637. AVI_ACTIVE_FORMAT_VALID |
  638. AVI_UNDERSCANNED_DISPLAY_VALID);
  639. aspect_ratio = AVI_PIC_ASPECT_RATIO_16_9;
  640. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), aspect_ratio |
  641. AVI_SAME_AS_PIC_ASPECT_RATIO);
  642. vic = hdata->mode_conf.cea_video_id;
  643. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), vic);
  644. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  645. infoframe->any.length, hdr_sum);
  646. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  647. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  648. break;
  649. case HDMI_INFOFRAME_TYPE_AUDIO:
  650. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  651. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
  652. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
  653. infoframe->any.version);
  654. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
  655. hdr_sum = infoframe->any.type + infoframe->any.version +
  656. infoframe->any.length;
  657. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  658. infoframe->any.length, hdr_sum);
  659. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  660. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  661. break;
  662. default:
  663. break;
  664. }
  665. }
  666. static bool hdmi_is_connected(void *ctx)
  667. {
  668. struct hdmi_context *hdata = ctx;
  669. return hdata->hpd;
  670. }
  671. static struct edid *hdmi_get_edid(void *ctx, struct drm_connector *connector)
  672. {
  673. struct edid *raw_edid;
  674. struct hdmi_context *hdata = ctx;
  675. if (!hdata->ddc_port)
  676. return ERR_PTR(-ENODEV);
  677. raw_edid = drm_get_edid(connector, hdata->ddc_port->adapter);
  678. if (!raw_edid)
  679. return ERR_PTR(-ENODEV);
  680. hdata->dvi_mode = !drm_detect_hdmi_monitor(raw_edid);
  681. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  682. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  683. raw_edid->width_cm, raw_edid->height_cm);
  684. return raw_edid;
  685. }
  686. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  687. {
  688. const struct hdmiphy_config *confs;
  689. int count, i;
  690. if (hdata->type == HDMI_TYPE13) {
  691. confs = hdmiphy_v13_configs;
  692. count = ARRAY_SIZE(hdmiphy_v13_configs);
  693. } else if (hdata->type == HDMI_TYPE14) {
  694. confs = hdmiphy_v14_configs;
  695. count = ARRAY_SIZE(hdmiphy_v14_configs);
  696. } else
  697. return -EINVAL;
  698. for (i = 0; i < count; i++)
  699. if (confs[i].pixel_clock == pixel_clock)
  700. return i;
  701. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  702. return -EINVAL;
  703. }
  704. static int hdmi_check_mode(void *ctx, struct drm_display_mode *mode)
  705. {
  706. struct hdmi_context *hdata = ctx;
  707. int ret;
  708. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  709. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  710. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  711. false, mode->clock * 1000);
  712. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  713. if (ret < 0)
  714. return ret;
  715. return 0;
  716. }
  717. static void hdmi_set_acr(u32 freq, u8 *acr)
  718. {
  719. u32 n, cts;
  720. switch (freq) {
  721. case 32000:
  722. n = 4096;
  723. cts = 27000;
  724. break;
  725. case 44100:
  726. n = 6272;
  727. cts = 30000;
  728. break;
  729. case 88200:
  730. n = 12544;
  731. cts = 30000;
  732. break;
  733. case 176400:
  734. n = 25088;
  735. cts = 30000;
  736. break;
  737. case 48000:
  738. n = 6144;
  739. cts = 27000;
  740. break;
  741. case 96000:
  742. n = 12288;
  743. cts = 27000;
  744. break;
  745. case 192000:
  746. n = 24576;
  747. cts = 27000;
  748. break;
  749. default:
  750. n = 0;
  751. cts = 0;
  752. break;
  753. }
  754. acr[1] = cts >> 16;
  755. acr[2] = cts >> 8 & 0xff;
  756. acr[3] = cts & 0xff;
  757. acr[4] = n >> 16;
  758. acr[5] = n >> 8 & 0xff;
  759. acr[6] = n & 0xff;
  760. }
  761. static void hdmi_reg_acr(struct hdmi_context *hdata, u8 *acr)
  762. {
  763. hdmi_reg_writeb(hdata, HDMI_ACR_N0, acr[6]);
  764. hdmi_reg_writeb(hdata, HDMI_ACR_N1, acr[5]);
  765. hdmi_reg_writeb(hdata, HDMI_ACR_N2, acr[4]);
  766. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS0, acr[3]);
  767. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS1, acr[2]);
  768. hdmi_reg_writeb(hdata, HDMI_ACR_MCTS2, acr[1]);
  769. hdmi_reg_writeb(hdata, HDMI_ACR_CTS0, acr[3]);
  770. hdmi_reg_writeb(hdata, HDMI_ACR_CTS1, acr[2]);
  771. hdmi_reg_writeb(hdata, HDMI_ACR_CTS2, acr[1]);
  772. if (hdata->type == HDMI_TYPE13)
  773. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 4);
  774. else
  775. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  776. }
  777. static void hdmi_audio_init(struct hdmi_context *hdata)
  778. {
  779. u32 sample_rate, bits_per_sample, frame_size_code;
  780. u32 data_num, bit_ch, sample_frq;
  781. u32 val;
  782. u8 acr[7];
  783. sample_rate = 44100;
  784. bits_per_sample = 16;
  785. frame_size_code = 0;
  786. switch (bits_per_sample) {
  787. case 20:
  788. data_num = 2;
  789. bit_ch = 1;
  790. break;
  791. case 24:
  792. data_num = 3;
  793. bit_ch = 1;
  794. break;
  795. default:
  796. data_num = 1;
  797. bit_ch = 0;
  798. break;
  799. }
  800. hdmi_set_acr(sample_rate, acr);
  801. hdmi_reg_acr(hdata, acr);
  802. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  803. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  804. | HDMI_I2S_MUX_ENABLE);
  805. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  806. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  807. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  808. sample_frq = (sample_rate == 44100) ? 0 :
  809. (sample_rate == 48000) ? 2 :
  810. (sample_rate == 32000) ? 3 :
  811. (sample_rate == 96000) ? 0xa : 0x0;
  812. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  813. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  814. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  815. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  816. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  817. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  818. | HDMI_I2S_SEL_LRCK(6));
  819. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  820. | HDMI_I2S_SEL_SDATA2(4));
  821. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  822. | HDMI_I2S_SEL_SDATA2(2));
  823. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  824. /* I2S_CON_1 & 2 */
  825. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  826. | HDMI_I2S_L_CH_LOW_POL);
  827. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  828. | HDMI_I2S_SET_BIT_CH(bit_ch)
  829. | HDMI_I2S_SET_SDATA_BIT(data_num)
  830. | HDMI_I2S_BASIC_FORMAT);
  831. /* Configure register related to CUV information */
  832. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  833. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  834. | HDMI_I2S_COPYRIGHT
  835. | HDMI_I2S_LINEAR_PCM
  836. | HDMI_I2S_CONSUMER_FORMAT);
  837. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  838. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  839. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  840. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  841. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  842. HDMI_I2S_ORG_SMP_FREQ_44_1
  843. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  844. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  845. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  846. }
  847. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  848. {
  849. if (hdata->dvi_mode)
  850. return;
  851. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  852. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  853. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  854. }
  855. static void hdmi_conf_reset(struct hdmi_context *hdata)
  856. {
  857. u32 reg;
  858. if (hdata->type == HDMI_TYPE13)
  859. reg = HDMI_V13_CORE_RSTOUT;
  860. else
  861. reg = HDMI_CORE_RSTOUT;
  862. /* resetting HDMI core */
  863. hdmi_reg_writemask(hdata, reg, 0, HDMI_CORE_SW_RSTOUT);
  864. usleep_range(10000, 12000);
  865. hdmi_reg_writemask(hdata, reg, ~0, HDMI_CORE_SW_RSTOUT);
  866. usleep_range(10000, 12000);
  867. }
  868. static void hdmi_conf_init(struct hdmi_context *hdata)
  869. {
  870. union hdmi_infoframe infoframe;
  871. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  872. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  873. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  874. /* choose HDMI mode */
  875. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  876. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  877. /* disable bluescreen */
  878. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  879. if (hdata->dvi_mode) {
  880. /* choose DVI mode */
  881. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  882. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  883. hdmi_reg_writeb(hdata, HDMI_CON_2,
  884. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  885. }
  886. if (hdata->type == HDMI_TYPE13) {
  887. /* choose bluescreen (fecal) color */
  888. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  889. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  890. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  891. /* enable AVI packet every vsync, fixes purple line problem */
  892. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  893. /* force RGB, look to CEA-861-D, table 7 for more detail */
  894. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  895. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  896. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  897. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  898. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  899. } else {
  900. infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
  901. infoframe.any.version = HDMI_AVI_VERSION;
  902. infoframe.any.length = HDMI_AVI_LENGTH;
  903. hdmi_reg_infoframe(hdata, &infoframe);
  904. infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
  905. infoframe.any.version = HDMI_AUI_VERSION;
  906. infoframe.any.length = HDMI_AUI_LENGTH;
  907. hdmi_reg_infoframe(hdata, &infoframe);
  908. /* enable AVI packet every vsync, fixes purple line problem */
  909. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  910. }
  911. }
  912. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  913. {
  914. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  915. const struct hdmi_v13_core_regs *core =
  916. &hdata->mode_conf.conf.v13_conf.core;
  917. int tries;
  918. /* setting core registers */
  919. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  920. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  921. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_0, core->v_blank[0]);
  922. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_1, core->v_blank[1]);
  923. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_2, core->v_blank[2]);
  924. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_0, core->h_v_line[0]);
  925. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_1, core->h_v_line[1]);
  926. hdmi_reg_writeb(hdata, HDMI_V13_H_V_LINE_2, core->h_v_line[2]);
  927. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  928. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  929. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_0, core->v_blank_f[0]);
  930. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_1, core->v_blank_f[1]);
  931. hdmi_reg_writeb(hdata, HDMI_V13_V_BLANK_F_2, core->v_blank_f[2]);
  932. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_0, core->h_sync_gen[0]);
  933. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_1, core->h_sync_gen[1]);
  934. hdmi_reg_writeb(hdata, HDMI_V13_H_SYNC_GEN_2, core->h_sync_gen[2]);
  935. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_0, core->v_sync_gen1[0]);
  936. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_1, core->v_sync_gen1[1]);
  937. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_1_2, core->v_sync_gen1[2]);
  938. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_0, core->v_sync_gen2[0]);
  939. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_1, core->v_sync_gen2[1]);
  940. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_2_2, core->v_sync_gen2[2]);
  941. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_0, core->v_sync_gen3[0]);
  942. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_1, core->v_sync_gen3[1]);
  943. hdmi_reg_writeb(hdata, HDMI_V13_V_SYNC_GEN_3_2, core->v_sync_gen3[2]);
  944. /* Timing generator registers */
  945. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  946. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  947. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  948. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  949. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  950. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  951. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  952. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  953. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  954. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  955. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  956. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  957. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  958. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  959. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  960. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  961. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  962. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  963. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  964. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  965. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  966. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  967. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  968. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  969. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  970. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  971. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  972. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  973. /* waiting for HDMIPHY's PLL to get to steady state */
  974. for (tries = 100; tries; --tries) {
  975. u32 val = hdmi_reg_read(hdata, HDMI_V13_PHY_STATUS);
  976. if (val & HDMI_PHY_STATUS_READY)
  977. break;
  978. usleep_range(1000, 2000);
  979. }
  980. /* steady state not achieved */
  981. if (tries == 0) {
  982. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  983. hdmi_regs_dump(hdata, "timing apply");
  984. }
  985. clk_disable_unprepare(hdata->res.sclk_hdmi);
  986. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  987. clk_prepare_enable(hdata->res.sclk_hdmi);
  988. /* enable HDMI and timing generator */
  989. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  990. if (core->int_pro_mode[0])
  991. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  992. HDMI_FIELD_EN);
  993. else
  994. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  995. }
  996. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  997. {
  998. const struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  999. const struct hdmi_v14_core_regs *core =
  1000. &hdata->mode_conf.conf.v14_conf.core;
  1001. int tries;
  1002. /* setting core registers */
  1003. hdmi_reg_writeb(hdata, HDMI_H_BLANK_0, core->h_blank[0]);
  1004. hdmi_reg_writeb(hdata, HDMI_H_BLANK_1, core->h_blank[1]);
  1005. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_0, core->v2_blank[0]);
  1006. hdmi_reg_writeb(hdata, HDMI_V2_BLANK_1, core->v2_blank[1]);
  1007. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_0, core->v1_blank[0]);
  1008. hdmi_reg_writeb(hdata, HDMI_V1_BLANK_1, core->v1_blank[1]);
  1009. hdmi_reg_writeb(hdata, HDMI_V_LINE_0, core->v_line[0]);
  1010. hdmi_reg_writeb(hdata, HDMI_V_LINE_1, core->v_line[1]);
  1011. hdmi_reg_writeb(hdata, HDMI_H_LINE_0, core->h_line[0]);
  1012. hdmi_reg_writeb(hdata, HDMI_H_LINE_1, core->h_line[1]);
  1013. hdmi_reg_writeb(hdata, HDMI_HSYNC_POL, core->hsync_pol[0]);
  1014. hdmi_reg_writeb(hdata, HDMI_VSYNC_POL, core->vsync_pol[0]);
  1015. hdmi_reg_writeb(hdata, HDMI_INT_PRO_MODE, core->int_pro_mode[0]);
  1016. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_0, core->v_blank_f0[0]);
  1017. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F0_1, core->v_blank_f0[1]);
  1018. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_0, core->v_blank_f1[0]);
  1019. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F1_1, core->v_blank_f1[1]);
  1020. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_0, core->h_sync_start[0]);
  1021. hdmi_reg_writeb(hdata, HDMI_H_SYNC_START_1, core->h_sync_start[1]);
  1022. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_0, core->h_sync_end[0]);
  1023. hdmi_reg_writeb(hdata, HDMI_H_SYNC_END_1, core->h_sync_end[1]);
  1024. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_0,
  1025. core->v_sync_line_bef_2[0]);
  1026. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_2_1,
  1027. core->v_sync_line_bef_2[1]);
  1028. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_0,
  1029. core->v_sync_line_bef_1[0]);
  1030. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_BEF_1_1,
  1031. core->v_sync_line_bef_1[1]);
  1032. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_0,
  1033. core->v_sync_line_aft_2[0]);
  1034. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_2_1,
  1035. core->v_sync_line_aft_2[1]);
  1036. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_0,
  1037. core->v_sync_line_aft_1[0]);
  1038. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_1_1,
  1039. core->v_sync_line_aft_1[1]);
  1040. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0,
  1041. core->v_sync_line_aft_pxl_2[0]);
  1042. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_1,
  1043. core->v_sync_line_aft_pxl_2[1]);
  1044. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0,
  1045. core->v_sync_line_aft_pxl_1[0]);
  1046. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_1,
  1047. core->v_sync_line_aft_pxl_1[1]);
  1048. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_0, core->v_blank_f2[0]);
  1049. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F2_1, core->v_blank_f2[1]);
  1050. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_0, core->v_blank_f3[0]);
  1051. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F3_1, core->v_blank_f3[1]);
  1052. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_0, core->v_blank_f4[0]);
  1053. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F4_1, core->v_blank_f4[1]);
  1054. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_0, core->v_blank_f5[0]);
  1055. hdmi_reg_writeb(hdata, HDMI_V_BLANK_F5_1, core->v_blank_f5[1]);
  1056. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_0,
  1057. core->v_sync_line_aft_3[0]);
  1058. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_3_1,
  1059. core->v_sync_line_aft_3[1]);
  1060. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_0,
  1061. core->v_sync_line_aft_4[0]);
  1062. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_4_1,
  1063. core->v_sync_line_aft_4[1]);
  1064. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_0,
  1065. core->v_sync_line_aft_5[0]);
  1066. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_5_1,
  1067. core->v_sync_line_aft_5[1]);
  1068. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_0,
  1069. core->v_sync_line_aft_6[0]);
  1070. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_6_1,
  1071. core->v_sync_line_aft_6[1]);
  1072. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0,
  1073. core->v_sync_line_aft_pxl_3[0]);
  1074. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_1,
  1075. core->v_sync_line_aft_pxl_3[1]);
  1076. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0,
  1077. core->v_sync_line_aft_pxl_4[0]);
  1078. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_1,
  1079. core->v_sync_line_aft_pxl_4[1]);
  1080. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0,
  1081. core->v_sync_line_aft_pxl_5[0]);
  1082. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_1,
  1083. core->v_sync_line_aft_pxl_5[1]);
  1084. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0,
  1085. core->v_sync_line_aft_pxl_6[0]);
  1086. hdmi_reg_writeb(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_1,
  1087. core->v_sync_line_aft_pxl_6[1]);
  1088. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_0, core->vact_space_1[0]);
  1089. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_1_1, core->vact_space_1[1]);
  1090. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_0, core->vact_space_2[0]);
  1091. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_2_1, core->vact_space_2[1]);
  1092. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_0, core->vact_space_3[0]);
  1093. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_3_1, core->vact_space_3[1]);
  1094. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_0, core->vact_space_4[0]);
  1095. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_4_1, core->vact_space_4[1]);
  1096. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_0, core->vact_space_5[0]);
  1097. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_5_1, core->vact_space_5[1]);
  1098. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_0, core->vact_space_6[0]);
  1099. hdmi_reg_writeb(hdata, HDMI_VACT_SPACE_6_1, core->vact_space_6[1]);
  1100. /* Timing generator registers */
  1101. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_L, tg->h_fsz[0]);
  1102. hdmi_reg_writeb(hdata, HDMI_TG_H_FSZ_H, tg->h_fsz[1]);
  1103. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_L, tg->hact_st[0]);
  1104. hdmi_reg_writeb(hdata, HDMI_TG_HACT_ST_H, tg->hact_st[1]);
  1105. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_L, tg->hact_sz[0]);
  1106. hdmi_reg_writeb(hdata, HDMI_TG_HACT_SZ_H, tg->hact_sz[1]);
  1107. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_L, tg->v_fsz[0]);
  1108. hdmi_reg_writeb(hdata, HDMI_TG_V_FSZ_H, tg->v_fsz[1]);
  1109. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_L, tg->vsync[0]);
  1110. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_H, tg->vsync[1]);
  1111. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_L, tg->vsync2[0]);
  1112. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC2_H, tg->vsync2[1]);
  1113. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_L, tg->vact_st[0]);
  1114. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST_H, tg->vact_st[1]);
  1115. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_L, tg->vact_sz[0]);
  1116. hdmi_reg_writeb(hdata, HDMI_TG_VACT_SZ_H, tg->vact_sz[1]);
  1117. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_L, tg->field_chg[0]);
  1118. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_CHG_H, tg->field_chg[1]);
  1119. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_L, tg->vact_st2[0]);
  1120. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST2_H, tg->vact_st2[1]);
  1121. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_L, tg->vact_st3[0]);
  1122. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST3_H, tg->vact_st3[1]);
  1123. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_L, tg->vact_st4[0]);
  1124. hdmi_reg_writeb(hdata, HDMI_TG_VACT_ST4_H, tg->vact_st4[1]);
  1125. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, tg->vsync_top_hdmi[0]);
  1126. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_TOP_HDMI_H, tg->vsync_top_hdmi[1]);
  1127. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, tg->vsync_bot_hdmi[0]);
  1128. hdmi_reg_writeb(hdata, HDMI_TG_VSYNC_BOT_HDMI_H, tg->vsync_bot_hdmi[1]);
  1129. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_L, tg->field_top_hdmi[0]);
  1130. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_TOP_HDMI_H, tg->field_top_hdmi[1]);
  1131. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_L, tg->field_bot_hdmi[0]);
  1132. hdmi_reg_writeb(hdata, HDMI_TG_FIELD_BOT_HDMI_H, tg->field_bot_hdmi[1]);
  1133. hdmi_reg_writeb(hdata, HDMI_TG_3D, tg->tg_3d[0]);
  1134. /* waiting for HDMIPHY's PLL to get to steady state */
  1135. for (tries = 100; tries; --tries) {
  1136. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS_0);
  1137. if (val & HDMI_PHY_STATUS_READY)
  1138. break;
  1139. usleep_range(1000, 2000);
  1140. }
  1141. /* steady state not achieved */
  1142. if (tries == 0) {
  1143. DRM_ERROR("hdmiphy's pll could not reach steady state.\n");
  1144. hdmi_regs_dump(hdata, "timing apply");
  1145. }
  1146. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1147. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_hdmiphy);
  1148. clk_prepare_enable(hdata->res.sclk_hdmi);
  1149. /* enable HDMI and timing generator */
  1150. hdmi_reg_writemask(hdata, HDMI_CON_0, ~0, HDMI_EN);
  1151. if (core->int_pro_mode[0])
  1152. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN |
  1153. HDMI_FIELD_EN);
  1154. else
  1155. hdmi_reg_writemask(hdata, HDMI_TG_CMD, ~0, HDMI_TG_EN);
  1156. }
  1157. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1158. {
  1159. if (hdata->type == HDMI_TYPE13)
  1160. hdmi_v13_mode_apply(hdata);
  1161. else
  1162. hdmi_v14_mode_apply(hdata);
  1163. }
  1164. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1165. {
  1166. u8 buffer[2];
  1167. u32 reg;
  1168. clk_disable_unprepare(hdata->res.sclk_hdmi);
  1169. clk_set_parent(hdata->res.mout_hdmi, hdata->res.sclk_pixel);
  1170. clk_prepare_enable(hdata->res.sclk_hdmi);
  1171. /* operation mode */
  1172. buffer[0] = 0x1f;
  1173. buffer[1] = 0x00;
  1174. if (hdata->hdmiphy_port)
  1175. i2c_master_send(hdata->hdmiphy_port, buffer, 2);
  1176. if (hdata->type == HDMI_TYPE13)
  1177. reg = HDMI_V13_PHY_RSTOUT;
  1178. else
  1179. reg = HDMI_PHY_RSTOUT;
  1180. /* reset hdmiphy */
  1181. hdmi_reg_writemask(hdata, reg, ~0, HDMI_PHY_SW_RSTOUT);
  1182. usleep_range(10000, 12000);
  1183. hdmi_reg_writemask(hdata, reg, 0, HDMI_PHY_SW_RSTOUT);
  1184. usleep_range(10000, 12000);
  1185. }
  1186. static void hdmiphy_poweron(struct hdmi_context *hdata)
  1187. {
  1188. if (hdata->type == HDMI_TYPE14)
  1189. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, 0,
  1190. HDMI_PHY_POWER_OFF_EN);
  1191. }
  1192. static void hdmiphy_poweroff(struct hdmi_context *hdata)
  1193. {
  1194. if (hdata->type == HDMI_TYPE14)
  1195. hdmi_reg_writemask(hdata, HDMI_PHY_CON_0, ~0,
  1196. HDMI_PHY_POWER_OFF_EN);
  1197. }
  1198. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1199. {
  1200. const u8 *hdmiphy_data;
  1201. u8 buffer[32];
  1202. u8 operation[2];
  1203. u8 read_buffer[32] = {0, };
  1204. int ret;
  1205. int i;
  1206. if (!hdata->hdmiphy_port) {
  1207. DRM_ERROR("hdmiphy is not attached\n");
  1208. return;
  1209. }
  1210. /* pixel clock */
  1211. i = hdmi_find_phy_conf(hdata, hdata->mode_conf.pixel_clock);
  1212. if (i < 0) {
  1213. DRM_ERROR("failed to find hdmiphy conf\n");
  1214. return;
  1215. }
  1216. if (hdata->type == HDMI_TYPE13)
  1217. hdmiphy_data = hdmiphy_v13_configs[i].conf;
  1218. else
  1219. hdmiphy_data = hdmiphy_v14_configs[i].conf;
  1220. memcpy(buffer, hdmiphy_data, 32);
  1221. ret = i2c_master_send(hdata->hdmiphy_port, buffer, 32);
  1222. if (ret != 32) {
  1223. DRM_ERROR("failed to configure HDMIPHY via I2C\n");
  1224. return;
  1225. }
  1226. usleep_range(10000, 12000);
  1227. /* operation mode */
  1228. operation[0] = 0x1f;
  1229. operation[1] = 0x80;
  1230. ret = i2c_master_send(hdata->hdmiphy_port, operation, 2);
  1231. if (ret != 2) {
  1232. DRM_ERROR("failed to enable hdmiphy\n");
  1233. return;
  1234. }
  1235. ret = i2c_master_recv(hdata->hdmiphy_port, read_buffer, 32);
  1236. if (ret < 0) {
  1237. DRM_ERROR("failed to read hdmiphy config\n");
  1238. return;
  1239. }
  1240. for (i = 0; i < ret; i++)
  1241. DRM_DEBUG_KMS("hdmiphy[0x%02x] write[0x%02x] - "
  1242. "recv [0x%02x]\n", i, buffer[i], read_buffer[i]);
  1243. }
  1244. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1245. {
  1246. hdmiphy_conf_reset(hdata);
  1247. hdmiphy_conf_apply(hdata);
  1248. mutex_lock(&hdata->hdmi_mutex);
  1249. hdmi_conf_reset(hdata);
  1250. hdmi_conf_init(hdata);
  1251. mutex_unlock(&hdata->hdmi_mutex);
  1252. hdmi_audio_init(hdata);
  1253. /* setting core registers */
  1254. hdmi_mode_apply(hdata);
  1255. hdmi_audio_control(hdata, true);
  1256. hdmi_regs_dump(hdata, "start");
  1257. }
  1258. static void hdmi_set_reg(u8 *reg_pair, int num_bytes, u32 value)
  1259. {
  1260. int i;
  1261. BUG_ON(num_bytes > 4);
  1262. for (i = 0; i < num_bytes; i++)
  1263. reg_pair[i] = (value >> (8 * i)) & 0xff;
  1264. }
  1265. static void hdmi_v13_mode_set(struct hdmi_context *hdata,
  1266. struct drm_display_mode *m)
  1267. {
  1268. struct hdmi_v13_core_regs *core = &hdata->mode_conf.conf.v13_conf.core;
  1269. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v13_conf.tg;
  1270. unsigned int val;
  1271. hdata->mode_conf.cea_video_id =
  1272. drm_match_cea_mode((struct drm_display_mode *)m);
  1273. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1274. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1275. hdmi_set_reg(core->h_v_line, 3, (m->htotal << 12) | m->vtotal);
  1276. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1277. hdmi_set_reg(core->vsync_pol, 1, val);
  1278. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1279. hdmi_set_reg(core->int_pro_mode, 1, val);
  1280. val = (m->hsync_start - m->hdisplay - 2);
  1281. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1282. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1283. hdmi_set_reg(core->h_sync_gen, 3, val);
  1284. /*
  1285. * Quirk requirement for exynos HDMI IP design,
  1286. * 2 pixels less than the actual calculation for hsync_start
  1287. * and end.
  1288. */
  1289. /* Following values & calculations differ for different type of modes */
  1290. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1291. /* Interlaced Mode */
  1292. val = ((m->vsync_end - m->vdisplay) / 2);
  1293. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1294. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1295. val = m->vtotal / 2;
  1296. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1297. hdmi_set_reg(core->v_blank, 3, val);
  1298. val = (m->vtotal +
  1299. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1300. val |= m->vtotal << 11;
  1301. hdmi_set_reg(core->v_blank_f, 3, val);
  1302. val = ((m->vtotal / 2) + 7);
  1303. val |= ((m->vtotal / 2) + 2) << 12;
  1304. hdmi_set_reg(core->v_sync_gen2, 3, val);
  1305. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1306. val |= ((m->htotal / 2) +
  1307. (m->hsync_start - m->hdisplay)) << 12;
  1308. hdmi_set_reg(core->v_sync_gen3, 3, val);
  1309. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1310. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1311. hdmi_set_reg(tg->vact_st2, 2, 0x249);/* Reset value + 1*/
  1312. } else {
  1313. /* Progressive Mode */
  1314. val = m->vtotal;
  1315. val |= (m->vtotal - m->vdisplay) << 11;
  1316. hdmi_set_reg(core->v_blank, 3, val);
  1317. hdmi_set_reg(core->v_blank_f, 3, 0);
  1318. val = (m->vsync_end - m->vdisplay);
  1319. val |= ((m->vsync_start - m->vdisplay) << 12);
  1320. hdmi_set_reg(core->v_sync_gen1, 3, val);
  1321. hdmi_set_reg(core->v_sync_gen2, 3, 0x1001);/* Reset value */
  1322. hdmi_set_reg(core->v_sync_gen3, 3, 0x1001);/* Reset value */
  1323. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1324. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1325. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1326. }
  1327. /* Timing generator registers */
  1328. hdmi_set_reg(tg->cmd, 1, 0x0);
  1329. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1330. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1331. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1332. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1333. hdmi_set_reg(tg->vsync, 2, 0x1);
  1334. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1335. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1336. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1337. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1338. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1339. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1340. hdmi_set_reg(tg->tg_3d, 1, 0x0); /* Not used */
  1341. }
  1342. static void hdmi_v14_mode_set(struct hdmi_context *hdata,
  1343. struct drm_display_mode *m)
  1344. {
  1345. struct hdmi_tg_regs *tg = &hdata->mode_conf.conf.v14_conf.tg;
  1346. struct hdmi_v14_core_regs *core =
  1347. &hdata->mode_conf.conf.v14_conf.core;
  1348. hdata->mode_conf.cea_video_id =
  1349. drm_match_cea_mode((struct drm_display_mode *)m);
  1350. hdata->mode_conf.pixel_clock = m->clock * 1000;
  1351. hdmi_set_reg(core->h_blank, 2, m->htotal - m->hdisplay);
  1352. hdmi_set_reg(core->v_line, 2, m->vtotal);
  1353. hdmi_set_reg(core->h_line, 2, m->htotal);
  1354. hdmi_set_reg(core->hsync_pol, 1,
  1355. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1356. hdmi_set_reg(core->vsync_pol, 1,
  1357. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1358. hdmi_set_reg(core->int_pro_mode, 1,
  1359. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1360. /*
  1361. * Quirk requirement for exynos 5 HDMI IP design,
  1362. * 2 pixels less than the actual calculation for hsync_start
  1363. * and end.
  1364. */
  1365. /* Following values & calculations differ for different type of modes */
  1366. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1367. /* Interlaced Mode */
  1368. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1369. (m->vsync_end - m->vdisplay) / 2);
  1370. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1371. (m->vsync_start - m->vdisplay) / 2);
  1372. hdmi_set_reg(core->v2_blank, 2, m->vtotal / 2);
  1373. hdmi_set_reg(core->v1_blank, 2, (m->vtotal - m->vdisplay) / 2);
  1374. hdmi_set_reg(core->v_blank_f0, 2, m->vtotal - m->vdisplay / 2);
  1375. hdmi_set_reg(core->v_blank_f1, 2, m->vtotal);
  1376. hdmi_set_reg(core->v_sync_line_aft_2, 2, (m->vtotal / 2) + 7);
  1377. hdmi_set_reg(core->v_sync_line_aft_1, 2, (m->vtotal / 2) + 2);
  1378. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2,
  1379. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1380. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2,
  1381. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1382. hdmi_set_reg(tg->vact_st, 2, (m->vtotal - m->vdisplay) / 2);
  1383. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay / 2);
  1384. hdmi_set_reg(tg->vact_st2, 2, m->vtotal - m->vdisplay / 2);
  1385. hdmi_set_reg(tg->vsync2, 2, (m->vtotal / 2) + 1);
  1386. hdmi_set_reg(tg->vsync_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1387. hdmi_set_reg(tg->field_bot_hdmi, 2, (m->vtotal / 2) + 1);
  1388. hdmi_set_reg(tg->vact_st3, 2, 0x0);
  1389. hdmi_set_reg(tg->vact_st4, 2, 0x0);
  1390. } else {
  1391. /* Progressive Mode */
  1392. hdmi_set_reg(core->v_sync_line_bef_2, 2,
  1393. m->vsync_end - m->vdisplay);
  1394. hdmi_set_reg(core->v_sync_line_bef_1, 2,
  1395. m->vsync_start - m->vdisplay);
  1396. hdmi_set_reg(core->v2_blank, 2, m->vtotal);
  1397. hdmi_set_reg(core->v1_blank, 2, m->vtotal - m->vdisplay);
  1398. hdmi_set_reg(core->v_blank_f0, 2, 0xffff);
  1399. hdmi_set_reg(core->v_blank_f1, 2, 0xffff);
  1400. hdmi_set_reg(core->v_sync_line_aft_2, 2, 0xffff);
  1401. hdmi_set_reg(core->v_sync_line_aft_1, 2, 0xffff);
  1402. hdmi_set_reg(core->v_sync_line_aft_pxl_2, 2, 0xffff);
  1403. hdmi_set_reg(core->v_sync_line_aft_pxl_1, 2, 0xffff);
  1404. hdmi_set_reg(tg->vact_st, 2, m->vtotal - m->vdisplay);
  1405. hdmi_set_reg(tg->vact_sz, 2, m->vdisplay);
  1406. hdmi_set_reg(tg->vact_st2, 2, 0x248); /* Reset value */
  1407. hdmi_set_reg(tg->vact_st3, 2, 0x47b); /* Reset value */
  1408. hdmi_set_reg(tg->vact_st4, 2, 0x6ae); /* Reset value */
  1409. hdmi_set_reg(tg->vsync2, 2, 0x233); /* Reset value */
  1410. hdmi_set_reg(tg->vsync_bot_hdmi, 2, 0x233); /* Reset value */
  1411. hdmi_set_reg(tg->field_bot_hdmi, 2, 0x233); /* Reset value */
  1412. }
  1413. /* Following values & calculations are same irrespective of mode type */
  1414. hdmi_set_reg(core->h_sync_start, 2, m->hsync_start - m->hdisplay - 2);
  1415. hdmi_set_reg(core->h_sync_end, 2, m->hsync_end - m->hdisplay - 2);
  1416. hdmi_set_reg(core->vact_space_1, 2, 0xffff);
  1417. hdmi_set_reg(core->vact_space_2, 2, 0xffff);
  1418. hdmi_set_reg(core->vact_space_3, 2, 0xffff);
  1419. hdmi_set_reg(core->vact_space_4, 2, 0xffff);
  1420. hdmi_set_reg(core->vact_space_5, 2, 0xffff);
  1421. hdmi_set_reg(core->vact_space_6, 2, 0xffff);
  1422. hdmi_set_reg(core->v_blank_f2, 2, 0xffff);
  1423. hdmi_set_reg(core->v_blank_f3, 2, 0xffff);
  1424. hdmi_set_reg(core->v_blank_f4, 2, 0xffff);
  1425. hdmi_set_reg(core->v_blank_f5, 2, 0xffff);
  1426. hdmi_set_reg(core->v_sync_line_aft_3, 2, 0xffff);
  1427. hdmi_set_reg(core->v_sync_line_aft_4, 2, 0xffff);
  1428. hdmi_set_reg(core->v_sync_line_aft_5, 2, 0xffff);
  1429. hdmi_set_reg(core->v_sync_line_aft_6, 2, 0xffff);
  1430. hdmi_set_reg(core->v_sync_line_aft_pxl_3, 2, 0xffff);
  1431. hdmi_set_reg(core->v_sync_line_aft_pxl_4, 2, 0xffff);
  1432. hdmi_set_reg(core->v_sync_line_aft_pxl_5, 2, 0xffff);
  1433. hdmi_set_reg(core->v_sync_line_aft_pxl_6, 2, 0xffff);
  1434. /* Timing generator registers */
  1435. hdmi_set_reg(tg->cmd, 1, 0x0);
  1436. hdmi_set_reg(tg->h_fsz, 2, m->htotal);
  1437. hdmi_set_reg(tg->hact_st, 2, m->htotal - m->hdisplay);
  1438. hdmi_set_reg(tg->hact_sz, 2, m->hdisplay);
  1439. hdmi_set_reg(tg->v_fsz, 2, m->vtotal);
  1440. hdmi_set_reg(tg->vsync, 2, 0x1);
  1441. hdmi_set_reg(tg->field_chg, 2, 0x233); /* Reset value */
  1442. hdmi_set_reg(tg->vsync_top_hdmi, 2, 0x1); /* Reset value */
  1443. hdmi_set_reg(tg->field_top_hdmi, 2, 0x1); /* Reset value */
  1444. hdmi_set_reg(tg->tg_3d, 1, 0x0);
  1445. }
  1446. static void hdmi_mode_set(void *ctx, struct drm_display_mode *mode)
  1447. {
  1448. struct hdmi_context *hdata = ctx;
  1449. struct drm_display_mode *m = mode;
  1450. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1451. m->hdisplay, m->vdisplay,
  1452. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1453. "INTERLACED" : "PROGERESSIVE");
  1454. if (hdata->type == HDMI_TYPE13)
  1455. hdmi_v13_mode_set(hdata, mode);
  1456. else
  1457. hdmi_v14_mode_set(hdata, mode);
  1458. }
  1459. static void hdmi_get_max_resol(void *ctx, unsigned int *width,
  1460. unsigned int *height)
  1461. {
  1462. *width = MAX_WIDTH;
  1463. *height = MAX_HEIGHT;
  1464. }
  1465. static void hdmi_commit(void *ctx)
  1466. {
  1467. struct hdmi_context *hdata = ctx;
  1468. mutex_lock(&hdata->hdmi_mutex);
  1469. if (!hdata->powered) {
  1470. mutex_unlock(&hdata->hdmi_mutex);
  1471. return;
  1472. }
  1473. mutex_unlock(&hdata->hdmi_mutex);
  1474. hdmi_conf_apply(hdata);
  1475. }
  1476. static void hdmi_poweron(struct hdmi_context *hdata)
  1477. {
  1478. struct hdmi_resources *res = &hdata->res;
  1479. mutex_lock(&hdata->hdmi_mutex);
  1480. if (hdata->powered) {
  1481. mutex_unlock(&hdata->hdmi_mutex);
  1482. return;
  1483. }
  1484. hdata->powered = true;
  1485. mutex_unlock(&hdata->hdmi_mutex);
  1486. if (regulator_bulk_enable(res->regul_count, res->regul_bulk))
  1487. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1488. clk_prepare_enable(res->hdmiphy);
  1489. clk_prepare_enable(res->hdmi);
  1490. clk_prepare_enable(res->sclk_hdmi);
  1491. hdmiphy_poweron(hdata);
  1492. }
  1493. static void hdmi_poweroff(struct hdmi_context *hdata)
  1494. {
  1495. struct hdmi_resources *res = &hdata->res;
  1496. mutex_lock(&hdata->hdmi_mutex);
  1497. if (!hdata->powered)
  1498. goto out;
  1499. mutex_unlock(&hdata->hdmi_mutex);
  1500. /*
  1501. * The TV power domain needs any condition of hdmiphy to turn off and
  1502. * its reset state seems to meet the condition.
  1503. */
  1504. hdmiphy_conf_reset(hdata);
  1505. hdmiphy_poweroff(hdata);
  1506. clk_disable_unprepare(res->sclk_hdmi);
  1507. clk_disable_unprepare(res->hdmi);
  1508. clk_disable_unprepare(res->hdmiphy);
  1509. regulator_bulk_disable(res->regul_count, res->regul_bulk);
  1510. mutex_lock(&hdata->hdmi_mutex);
  1511. hdata->powered = false;
  1512. out:
  1513. mutex_unlock(&hdata->hdmi_mutex);
  1514. }
  1515. static void hdmi_dpms(void *ctx, int mode)
  1516. {
  1517. struct hdmi_context *hdata = ctx;
  1518. DRM_DEBUG_KMS("mode %d\n", mode);
  1519. switch (mode) {
  1520. case DRM_MODE_DPMS_ON:
  1521. if (pm_runtime_suspended(hdata->dev))
  1522. pm_runtime_get_sync(hdata->dev);
  1523. break;
  1524. case DRM_MODE_DPMS_STANDBY:
  1525. case DRM_MODE_DPMS_SUSPEND:
  1526. case DRM_MODE_DPMS_OFF:
  1527. if (!pm_runtime_suspended(hdata->dev))
  1528. pm_runtime_put_sync(hdata->dev);
  1529. break;
  1530. default:
  1531. DRM_DEBUG_KMS("unknown dpms mode: %d\n", mode);
  1532. break;
  1533. }
  1534. }
  1535. static struct exynos_hdmi_ops hdmi_ops = {
  1536. /* display */
  1537. .is_connected = hdmi_is_connected,
  1538. .get_edid = hdmi_get_edid,
  1539. .check_mode = hdmi_check_mode,
  1540. /* manager */
  1541. .mode_set = hdmi_mode_set,
  1542. .get_max_resol = hdmi_get_max_resol,
  1543. .commit = hdmi_commit,
  1544. .dpms = hdmi_dpms,
  1545. };
  1546. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1547. {
  1548. struct exynos_drm_hdmi_context *ctx = arg;
  1549. struct hdmi_context *hdata = ctx->ctx;
  1550. mutex_lock(&hdata->hdmi_mutex);
  1551. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1552. mutex_unlock(&hdata->hdmi_mutex);
  1553. if (ctx->drm_dev)
  1554. drm_helper_hpd_irq_event(ctx->drm_dev);
  1555. return IRQ_HANDLED;
  1556. }
  1557. static int hdmi_resources_init(struct hdmi_context *hdata)
  1558. {
  1559. struct device *dev = hdata->dev;
  1560. struct hdmi_resources *res = &hdata->res;
  1561. static char *supply[] = {
  1562. "hdmi-en",
  1563. "vdd",
  1564. "vdd_osc",
  1565. "vdd_pll",
  1566. };
  1567. int i, ret;
  1568. DRM_DEBUG_KMS("HDMI resource init\n");
  1569. memset(res, 0, sizeof(*res));
  1570. /* get clocks, power */
  1571. res->hdmi = devm_clk_get(dev, "hdmi");
  1572. if (IS_ERR(res->hdmi)) {
  1573. DRM_ERROR("failed to get clock 'hdmi'\n");
  1574. goto fail;
  1575. }
  1576. res->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1577. if (IS_ERR(res->sclk_hdmi)) {
  1578. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1579. goto fail;
  1580. }
  1581. res->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1582. if (IS_ERR(res->sclk_pixel)) {
  1583. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1584. goto fail;
  1585. }
  1586. res->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1587. if (IS_ERR(res->sclk_hdmiphy)) {
  1588. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1589. goto fail;
  1590. }
  1591. res->hdmiphy = devm_clk_get(dev, "hdmiphy");
  1592. if (IS_ERR(res->hdmiphy)) {
  1593. DRM_ERROR("failed to get clock 'hdmiphy'\n");
  1594. goto fail;
  1595. }
  1596. res->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1597. if (IS_ERR(res->mout_hdmi)) {
  1598. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1599. goto fail;
  1600. }
  1601. clk_set_parent(res->mout_hdmi, res->sclk_pixel);
  1602. res->regul_bulk = devm_kzalloc(dev, ARRAY_SIZE(supply) *
  1603. sizeof(res->regul_bulk[0]), GFP_KERNEL);
  1604. if (!res->regul_bulk)
  1605. goto fail;
  1606. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1607. res->regul_bulk[i].supply = supply[i];
  1608. res->regul_bulk[i].consumer = NULL;
  1609. }
  1610. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), res->regul_bulk);
  1611. if (ret) {
  1612. DRM_ERROR("failed to get regulators\n");
  1613. goto fail;
  1614. }
  1615. res->regul_count = ARRAY_SIZE(supply);
  1616. return 0;
  1617. fail:
  1618. DRM_ERROR("HDMI resource init - failed\n");
  1619. return -ENODEV;
  1620. }
  1621. static struct i2c_client *hdmi_ddc, *hdmi_hdmiphy;
  1622. void hdmi_attach_ddc_client(struct i2c_client *ddc)
  1623. {
  1624. if (ddc)
  1625. hdmi_ddc = ddc;
  1626. }
  1627. void hdmi_attach_hdmiphy_client(struct i2c_client *hdmiphy)
  1628. {
  1629. if (hdmiphy)
  1630. hdmi_hdmiphy = hdmiphy;
  1631. }
  1632. static struct s5p_hdmi_platform_data *drm_hdmi_dt_parse_pdata
  1633. (struct device *dev)
  1634. {
  1635. struct device_node *np = dev->of_node;
  1636. struct s5p_hdmi_platform_data *pd;
  1637. u32 value;
  1638. pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
  1639. if (!pd)
  1640. goto err_data;
  1641. if (!of_find_property(np, "hpd-gpio", &value)) {
  1642. DRM_ERROR("no hpd gpio property found\n");
  1643. goto err_data;
  1644. }
  1645. pd->hpd_gpio = of_get_named_gpio(np, "hpd-gpio", 0);
  1646. return pd;
  1647. err_data:
  1648. return NULL;
  1649. }
  1650. static struct of_device_id hdmi_match_types[] = {
  1651. {
  1652. .compatible = "samsung,exynos5-hdmi",
  1653. .data = (void *)HDMI_TYPE14,
  1654. }, {
  1655. .compatible = "samsung,exynos4212-hdmi",
  1656. .data = (void *)HDMI_TYPE14,
  1657. }, {
  1658. /* end node */
  1659. }
  1660. };
  1661. static int hdmi_probe(struct platform_device *pdev)
  1662. {
  1663. struct device *dev = &pdev->dev;
  1664. struct exynos_drm_hdmi_context *drm_hdmi_ctx;
  1665. struct hdmi_context *hdata;
  1666. struct s5p_hdmi_platform_data *pdata;
  1667. struct resource *res;
  1668. const struct of_device_id *match;
  1669. int ret;
  1670. if (!dev->of_node)
  1671. return -ENODEV;
  1672. pdata = drm_hdmi_dt_parse_pdata(dev);
  1673. if (!pdata)
  1674. return -EINVAL;
  1675. drm_hdmi_ctx = devm_kzalloc(dev, sizeof(*drm_hdmi_ctx), GFP_KERNEL);
  1676. if (!drm_hdmi_ctx)
  1677. return -ENOMEM;
  1678. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  1679. if (!hdata)
  1680. return -ENOMEM;
  1681. mutex_init(&hdata->hdmi_mutex);
  1682. drm_hdmi_ctx->ctx = (void *)hdata;
  1683. hdata->parent_ctx = (void *)drm_hdmi_ctx;
  1684. platform_set_drvdata(pdev, drm_hdmi_ctx);
  1685. match = of_match_node(hdmi_match_types, dev->of_node);
  1686. if (!match)
  1687. return -ENODEV;
  1688. hdata->type = (enum hdmi_type)match->data;
  1689. hdata->hpd_gpio = pdata->hpd_gpio;
  1690. hdata->dev = dev;
  1691. ret = hdmi_resources_init(hdata);
  1692. if (ret) {
  1693. DRM_ERROR("hdmi_resources_init failed\n");
  1694. return -EINVAL;
  1695. }
  1696. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1697. hdata->regs = devm_ioremap_resource(dev, res);
  1698. if (IS_ERR(hdata->regs))
  1699. return PTR_ERR(hdata->regs);
  1700. ret = devm_gpio_request(dev, hdata->hpd_gpio, "HPD");
  1701. if (ret) {
  1702. DRM_ERROR("failed to request HPD gpio\n");
  1703. return ret;
  1704. }
  1705. /* DDC i2c driver */
  1706. if (i2c_add_driver(&ddc_driver)) {
  1707. DRM_ERROR("failed to register ddc i2c driver\n");
  1708. return -ENOENT;
  1709. }
  1710. hdata->ddc_port = hdmi_ddc;
  1711. /* hdmiphy i2c driver */
  1712. if (i2c_add_driver(&hdmiphy_driver)) {
  1713. DRM_ERROR("failed to register hdmiphy i2c driver\n");
  1714. ret = -ENOENT;
  1715. goto err_ddc;
  1716. }
  1717. hdata->hdmiphy_port = hdmi_hdmiphy;
  1718. hdata->irq = gpio_to_irq(hdata->hpd_gpio);
  1719. if (hdata->irq < 0) {
  1720. DRM_ERROR("failed to get GPIO irq\n");
  1721. ret = hdata->irq;
  1722. goto err_hdmiphy;
  1723. }
  1724. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1725. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1726. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1727. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1728. "hdmi", drm_hdmi_ctx);
  1729. if (ret) {
  1730. DRM_ERROR("failed to register hdmi interrupt\n");
  1731. goto err_hdmiphy;
  1732. }
  1733. /* Attach HDMI Driver to common hdmi. */
  1734. exynos_hdmi_drv_attach(drm_hdmi_ctx);
  1735. /* register specific callbacks to common hdmi. */
  1736. exynos_hdmi_ops_register(&hdmi_ops);
  1737. pm_runtime_enable(dev);
  1738. return 0;
  1739. err_hdmiphy:
  1740. i2c_del_driver(&hdmiphy_driver);
  1741. err_ddc:
  1742. i2c_del_driver(&ddc_driver);
  1743. return ret;
  1744. }
  1745. static int hdmi_remove(struct platform_device *pdev)
  1746. {
  1747. struct device *dev = &pdev->dev;
  1748. pm_runtime_disable(dev);
  1749. /* hdmiphy i2c driver */
  1750. i2c_del_driver(&hdmiphy_driver);
  1751. /* DDC i2c driver */
  1752. i2c_del_driver(&ddc_driver);
  1753. return 0;
  1754. }
  1755. #ifdef CONFIG_PM_SLEEP
  1756. static int hdmi_suspend(struct device *dev)
  1757. {
  1758. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1759. struct hdmi_context *hdata = ctx->ctx;
  1760. disable_irq(hdata->irq);
  1761. hdata->hpd = false;
  1762. if (ctx->drm_dev)
  1763. drm_helper_hpd_irq_event(ctx->drm_dev);
  1764. if (pm_runtime_suspended(dev)) {
  1765. DRM_DEBUG_KMS("Already suspended\n");
  1766. return 0;
  1767. }
  1768. hdmi_poweroff(hdata);
  1769. return 0;
  1770. }
  1771. static int hdmi_resume(struct device *dev)
  1772. {
  1773. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1774. struct hdmi_context *hdata = ctx->ctx;
  1775. hdata->hpd = gpio_get_value(hdata->hpd_gpio);
  1776. enable_irq(hdata->irq);
  1777. if (!pm_runtime_suspended(dev)) {
  1778. DRM_DEBUG_KMS("Already resumed\n");
  1779. return 0;
  1780. }
  1781. hdmi_poweron(hdata);
  1782. return 0;
  1783. }
  1784. #endif
  1785. #ifdef CONFIG_PM_RUNTIME
  1786. static int hdmi_runtime_suspend(struct device *dev)
  1787. {
  1788. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1789. struct hdmi_context *hdata = ctx->ctx;
  1790. hdmi_poweroff(hdata);
  1791. return 0;
  1792. }
  1793. static int hdmi_runtime_resume(struct device *dev)
  1794. {
  1795. struct exynos_drm_hdmi_context *ctx = get_hdmi_context(dev);
  1796. struct hdmi_context *hdata = ctx->ctx;
  1797. hdmi_poweron(hdata);
  1798. return 0;
  1799. }
  1800. #endif
  1801. static const struct dev_pm_ops hdmi_pm_ops = {
  1802. SET_SYSTEM_SLEEP_PM_OPS(hdmi_suspend, hdmi_resume)
  1803. SET_RUNTIME_PM_OPS(hdmi_runtime_suspend, hdmi_runtime_resume, NULL)
  1804. };
  1805. struct platform_driver hdmi_driver = {
  1806. .probe = hdmi_probe,
  1807. .remove = hdmi_remove,
  1808. .driver = {
  1809. .name = "exynos-hdmi",
  1810. .owner = THIS_MODULE,
  1811. .pm = &hdmi_pm_ops,
  1812. .of_match_table = hdmi_match_types,
  1813. },
  1814. };