exynos_hdmi.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  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 <drm/drm_atomic_helper.h>
  20. #include "regs-hdmi.h"
  21. #include <linux/kernel.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/gpio/consumer.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/io.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_device.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. #define HOTPLUG_DEBOUNCE_MS 1100
  43. /* AVI header and aspect ratio */
  44. #define HDMI_AVI_VERSION 0x02
  45. #define HDMI_AVI_LENGTH 0x0D
  46. /* AUI header info */
  47. #define HDMI_AUI_VERSION 0x01
  48. #define HDMI_AUI_LENGTH 0x0A
  49. #define AVI_SAME_AS_PIC_ASPECT_RATIO 0x8
  50. #define AVI_4_3_CENTER_RATIO 0x9
  51. #define AVI_16_9_CENTER_RATIO 0xa
  52. enum hdmi_type {
  53. HDMI_TYPE13,
  54. HDMI_TYPE14,
  55. HDMI_TYPE_COUNT
  56. };
  57. #define HDMI_MAPPED_BASE 0xffff0000
  58. enum hdmi_mapped_regs {
  59. HDMI_PHY_STATUS = HDMI_MAPPED_BASE,
  60. HDMI_PHY_RSTOUT,
  61. HDMI_ACR_CON,
  62. HDMI_ACR_MCTS0,
  63. HDMI_ACR_CTS0,
  64. HDMI_ACR_N0
  65. };
  66. static const u32 hdmi_reg_map[][HDMI_TYPE_COUNT] = {
  67. { HDMI_V13_PHY_STATUS, HDMI_PHY_STATUS_0 },
  68. { HDMI_V13_PHY_RSTOUT, HDMI_V14_PHY_RSTOUT },
  69. { HDMI_V13_ACR_CON, HDMI_V14_ACR_CON },
  70. { HDMI_V13_ACR_MCTS0, HDMI_V14_ACR_MCTS0 },
  71. { HDMI_V13_ACR_CTS0, HDMI_V14_ACR_CTS0 },
  72. { HDMI_V13_ACR_N0, HDMI_V14_ACR_N0 },
  73. };
  74. static const char * const supply[] = {
  75. "vdd",
  76. "vdd_osc",
  77. "vdd_pll",
  78. };
  79. struct hdmi_driver_data {
  80. unsigned int type;
  81. const struct hdmiphy_config *phy_confs;
  82. unsigned int phy_conf_count;
  83. unsigned int is_apb_phy:1;
  84. };
  85. struct hdmi_context {
  86. struct drm_encoder encoder;
  87. struct device *dev;
  88. struct drm_device *drm_dev;
  89. struct drm_connector connector;
  90. bool powered;
  91. bool dvi_mode;
  92. struct delayed_work hotplug_work;
  93. struct drm_display_mode current_mode;
  94. u8 cea_video_id;
  95. const struct hdmi_driver_data *drv_data;
  96. void __iomem *regs;
  97. void __iomem *regs_hdmiphy;
  98. struct i2c_client *hdmiphy_port;
  99. struct i2c_adapter *ddc_adpt;
  100. struct gpio_desc *hpd_gpio;
  101. int irq;
  102. struct regmap *pmureg;
  103. struct clk *hdmi;
  104. struct clk *sclk_hdmi;
  105. struct clk *sclk_pixel;
  106. struct clk *sclk_hdmiphy;
  107. struct clk *mout_hdmi;
  108. struct regulator_bulk_data regul_bulk[ARRAY_SIZE(supply)];
  109. struct regulator *reg_hdmi_en;
  110. };
  111. static inline struct hdmi_context *encoder_to_hdmi(struct drm_encoder *e)
  112. {
  113. return container_of(e, struct hdmi_context, encoder);
  114. }
  115. static inline struct hdmi_context *connector_to_hdmi(struct drm_connector *c)
  116. {
  117. return container_of(c, struct hdmi_context, connector);
  118. }
  119. struct hdmiphy_config {
  120. int pixel_clock;
  121. u8 conf[32];
  122. };
  123. /* list of phy config settings */
  124. static const struct hdmiphy_config hdmiphy_v13_configs[] = {
  125. {
  126. .pixel_clock = 27000000,
  127. .conf = {
  128. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x1C, 0x30, 0x40,
  129. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  130. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  131. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x80,
  132. },
  133. },
  134. {
  135. .pixel_clock = 27027000,
  136. .conf = {
  137. 0x01, 0x05, 0x00, 0xD4, 0x10, 0x9C, 0x09, 0x64,
  138. 0x6B, 0x10, 0x02, 0x51, 0xDF, 0xF2, 0x54, 0x87,
  139. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  140. 0x22, 0x40, 0xE3, 0x26, 0x00, 0x00, 0x00, 0x80,
  141. },
  142. },
  143. {
  144. .pixel_clock = 74176000,
  145. .conf = {
  146. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xef, 0x5B,
  147. 0x6D, 0x10, 0x01, 0x51, 0xef, 0xF3, 0x54, 0xb9,
  148. 0x84, 0x00, 0x30, 0x38, 0x00, 0x08, 0x10, 0xE0,
  149. 0x22, 0x40, 0xa5, 0x26, 0x01, 0x00, 0x00, 0x80,
  150. },
  151. },
  152. {
  153. .pixel_clock = 74250000,
  154. .conf = {
  155. 0x01, 0x05, 0x00, 0xd8, 0x10, 0x9c, 0xf8, 0x40,
  156. 0x6a, 0x10, 0x01, 0x51, 0xff, 0xf1, 0x54, 0xba,
  157. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xe0,
  158. 0x22, 0x40, 0xa4, 0x26, 0x01, 0x00, 0x00, 0x80,
  159. },
  160. },
  161. {
  162. .pixel_clock = 148500000,
  163. .conf = {
  164. 0x01, 0x05, 0x00, 0xD8, 0x10, 0x9C, 0xf8, 0x40,
  165. 0x6A, 0x18, 0x00, 0x51, 0xff, 0xF1, 0x54, 0xba,
  166. 0x84, 0x00, 0x10, 0x38, 0x00, 0x08, 0x10, 0xE0,
  167. 0x22, 0x40, 0xa4, 0x26, 0x02, 0x00, 0x00, 0x80,
  168. },
  169. },
  170. };
  171. static const struct hdmiphy_config hdmiphy_v14_configs[] = {
  172. {
  173. .pixel_clock = 25200000,
  174. .conf = {
  175. 0x01, 0x51, 0x2A, 0x75, 0x40, 0x01, 0x00, 0x08,
  176. 0x82, 0x80, 0xfc, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  177. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  178. 0x54, 0xf4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  179. },
  180. },
  181. {
  182. .pixel_clock = 27000000,
  183. .conf = {
  184. 0x01, 0xd1, 0x22, 0x51, 0x40, 0x08, 0xfc, 0x20,
  185. 0x98, 0xa0, 0xcb, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  186. 0x06, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  187. 0x54, 0xe4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  188. },
  189. },
  190. {
  191. .pixel_clock = 27027000,
  192. .conf = {
  193. 0x01, 0xd1, 0x2d, 0x72, 0x40, 0x64, 0x12, 0x08,
  194. 0x43, 0xa0, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  195. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  196. 0x54, 0xe3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  197. },
  198. },
  199. {
  200. .pixel_clock = 36000000,
  201. .conf = {
  202. 0x01, 0x51, 0x2d, 0x55, 0x40, 0x01, 0x00, 0x08,
  203. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  204. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  205. 0x54, 0xab, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  206. },
  207. },
  208. {
  209. .pixel_clock = 40000000,
  210. .conf = {
  211. 0x01, 0x51, 0x32, 0x55, 0x40, 0x01, 0x00, 0x08,
  212. 0x82, 0x80, 0x2c, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  213. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  214. 0x54, 0x9a, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  215. },
  216. },
  217. {
  218. .pixel_clock = 65000000,
  219. .conf = {
  220. 0x01, 0xd1, 0x36, 0x34, 0x40, 0x1e, 0x0a, 0x08,
  221. 0x82, 0xa0, 0x45, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  222. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  223. 0x54, 0xbd, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  224. },
  225. },
  226. {
  227. .pixel_clock = 71000000,
  228. .conf = {
  229. 0x01, 0xd1, 0x3b, 0x35, 0x40, 0x0c, 0x04, 0x08,
  230. 0x85, 0xa0, 0x63, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  231. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  232. 0x54, 0xad, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  233. },
  234. },
  235. {
  236. .pixel_clock = 73250000,
  237. .conf = {
  238. 0x01, 0xd1, 0x3d, 0x35, 0x40, 0x18, 0x02, 0x08,
  239. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  240. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  241. 0x54, 0xa8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  242. },
  243. },
  244. {
  245. .pixel_clock = 74176000,
  246. .conf = {
  247. 0x01, 0xd1, 0x3e, 0x35, 0x40, 0x5b, 0xde, 0x08,
  248. 0x82, 0xa0, 0x73, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  249. 0x56, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  250. 0x54, 0xa6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  251. },
  252. },
  253. {
  254. .pixel_clock = 74250000,
  255. .conf = {
  256. 0x01, 0xd1, 0x1f, 0x10, 0x40, 0x40, 0xf8, 0x08,
  257. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  258. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  259. 0x54, 0xa5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  260. },
  261. },
  262. {
  263. .pixel_clock = 83500000,
  264. .conf = {
  265. 0x01, 0xd1, 0x23, 0x11, 0x40, 0x0c, 0xfb, 0x08,
  266. 0x85, 0xa0, 0xd1, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  267. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  268. 0x54, 0x93, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  269. },
  270. },
  271. {
  272. .pixel_clock = 106500000,
  273. .conf = {
  274. 0x01, 0xd1, 0x2c, 0x12, 0x40, 0x0c, 0x09, 0x08,
  275. 0x84, 0xa0, 0x0a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  276. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  277. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  278. },
  279. },
  280. {
  281. .pixel_clock = 108000000,
  282. .conf = {
  283. 0x01, 0x51, 0x2d, 0x15, 0x40, 0x01, 0x00, 0x08,
  284. 0x82, 0x80, 0x0e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  285. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  286. 0x54, 0xc7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  287. },
  288. },
  289. {
  290. .pixel_clock = 115500000,
  291. .conf = {
  292. 0x01, 0xd1, 0x30, 0x12, 0x40, 0x40, 0x10, 0x08,
  293. 0x80, 0x80, 0x21, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  294. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  295. 0x54, 0xaa, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  296. },
  297. },
  298. {
  299. .pixel_clock = 119000000,
  300. .conf = {
  301. 0x01, 0xd1, 0x32, 0x1a, 0x40, 0x30, 0xd8, 0x08,
  302. 0x04, 0xa0, 0x2a, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  303. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  304. 0x54, 0x9d, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  305. },
  306. },
  307. {
  308. .pixel_clock = 146250000,
  309. .conf = {
  310. 0x01, 0xd1, 0x3d, 0x15, 0x40, 0x18, 0xfd, 0x08,
  311. 0x83, 0xa0, 0x6e, 0xd9, 0x45, 0xa0, 0xac, 0x80,
  312. 0x08, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  313. 0x54, 0x50, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  314. },
  315. },
  316. {
  317. .pixel_clock = 148500000,
  318. .conf = {
  319. 0x01, 0xd1, 0x1f, 0x00, 0x40, 0x40, 0xf8, 0x08,
  320. 0x81, 0xa0, 0xba, 0xd8, 0x45, 0xa0, 0xac, 0x80,
  321. 0x3c, 0x80, 0x11, 0x04, 0x02, 0x22, 0x44, 0x86,
  322. 0x54, 0x4b, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  323. },
  324. },
  325. };
  326. static const struct hdmiphy_config hdmiphy_5420_configs[] = {
  327. {
  328. .pixel_clock = 25200000,
  329. .conf = {
  330. 0x01, 0x52, 0x3F, 0x55, 0x40, 0x01, 0x00, 0xC8,
  331. 0x82, 0xC8, 0xBD, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  332. 0x06, 0x80, 0x01, 0x84, 0x05, 0x02, 0x24, 0x66,
  333. 0x54, 0xF4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  334. },
  335. },
  336. {
  337. .pixel_clock = 27000000,
  338. .conf = {
  339. 0x01, 0xD1, 0x22, 0x51, 0x40, 0x08, 0xFC, 0xE0,
  340. 0x98, 0xE8, 0xCB, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  341. 0x06, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  342. 0x54, 0xE4, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  343. },
  344. },
  345. {
  346. .pixel_clock = 27027000,
  347. .conf = {
  348. 0x01, 0xD1, 0x2D, 0x72, 0x40, 0x64, 0x12, 0xC8,
  349. 0x43, 0xE8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  350. 0x26, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  351. 0x54, 0xE3, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  352. },
  353. },
  354. {
  355. .pixel_clock = 36000000,
  356. .conf = {
  357. 0x01, 0x51, 0x2D, 0x55, 0x40, 0x40, 0x00, 0xC8,
  358. 0x02, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  359. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  360. 0x54, 0xAB, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  361. },
  362. },
  363. {
  364. .pixel_clock = 40000000,
  365. .conf = {
  366. 0x01, 0xD1, 0x21, 0x31, 0x40, 0x3C, 0x28, 0xC8,
  367. 0x87, 0xE8, 0xC8, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  368. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  369. 0x54, 0x9A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  370. },
  371. },
  372. {
  373. .pixel_clock = 65000000,
  374. .conf = {
  375. 0x01, 0xD1, 0x36, 0x34, 0x40, 0x0C, 0x04, 0xC8,
  376. 0x82, 0xE8, 0x45, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  377. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  378. 0x54, 0xBD, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  379. },
  380. },
  381. {
  382. .pixel_clock = 71000000,
  383. .conf = {
  384. 0x01, 0xD1, 0x3B, 0x35, 0x40, 0x0C, 0x04, 0xC8,
  385. 0x85, 0xE8, 0x63, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  386. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  387. 0x54, 0x57, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  388. },
  389. },
  390. {
  391. .pixel_clock = 73250000,
  392. .conf = {
  393. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x78, 0x8D, 0xC8,
  394. 0x81, 0xE8, 0xB7, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  395. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  396. 0x54, 0xA8, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  397. },
  398. },
  399. {
  400. .pixel_clock = 74176000,
  401. .conf = {
  402. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x5B, 0xEF, 0xC8,
  403. 0x81, 0xE8, 0xB9, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  404. 0x56, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  405. 0x54, 0xA6, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  406. },
  407. },
  408. {
  409. .pixel_clock = 74250000,
  410. .conf = {
  411. 0x01, 0xD1, 0x1F, 0x10, 0x40, 0x40, 0xF8, 0x08,
  412. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  413. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  414. 0x54, 0xA5, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  415. },
  416. },
  417. {
  418. .pixel_clock = 83500000,
  419. .conf = {
  420. 0x01, 0xD1, 0x23, 0x11, 0x40, 0x0C, 0xFB, 0xC8,
  421. 0x85, 0xE8, 0xD1, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  422. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  423. 0x54, 0x4A, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  424. },
  425. },
  426. {
  427. .pixel_clock = 88750000,
  428. .conf = {
  429. 0x01, 0xD1, 0x25, 0x11, 0x40, 0x18, 0xFF, 0xC8,
  430. 0x83, 0xE8, 0xDE, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  431. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  432. 0x54, 0x45, 0x24, 0x00, 0x00, 0x00, 0x01, 0x80,
  433. },
  434. },
  435. {
  436. .pixel_clock = 106500000,
  437. .conf = {
  438. 0x01, 0xD1, 0x2C, 0x12, 0x40, 0x0C, 0x09, 0xC8,
  439. 0x84, 0xE8, 0x0A, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  440. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  441. 0x54, 0x73, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  442. },
  443. },
  444. {
  445. .pixel_clock = 108000000,
  446. .conf = {
  447. 0x01, 0x51, 0x2D, 0x15, 0x40, 0x01, 0x00, 0xC8,
  448. 0x82, 0xC8, 0x0E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  449. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  450. 0x54, 0xC7, 0x25, 0x03, 0x00, 0x00, 0x01, 0x80,
  451. },
  452. },
  453. {
  454. .pixel_clock = 115500000,
  455. .conf = {
  456. 0x01, 0xD1, 0x30, 0x14, 0x40, 0x0C, 0x03, 0xC8,
  457. 0x88, 0xE8, 0x21, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  458. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  459. 0x54, 0x6A, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  460. },
  461. },
  462. {
  463. .pixel_clock = 146250000,
  464. .conf = {
  465. 0x01, 0xD1, 0x3D, 0x15, 0x40, 0x18, 0xFD, 0xC8,
  466. 0x83, 0xE8, 0x6E, 0xD9, 0x45, 0xA0, 0xAC, 0x80,
  467. 0x08, 0x80, 0x09, 0x84, 0x05, 0x02, 0x24, 0x66,
  468. 0x54, 0x54, 0x24, 0x01, 0x00, 0x00, 0x01, 0x80,
  469. },
  470. },
  471. {
  472. .pixel_clock = 148500000,
  473. .conf = {
  474. 0x01, 0xD1, 0x1F, 0x00, 0x40, 0x40, 0xF8, 0x08,
  475. 0x81, 0xE8, 0xBA, 0xD8, 0x45, 0xA0, 0xAC, 0x80,
  476. 0x26, 0x80, 0x09, 0x84, 0x05, 0x22, 0x24, 0x66,
  477. 0x54, 0x4B, 0x25, 0x03, 0x00, 0x80, 0x01, 0x80,
  478. },
  479. },
  480. };
  481. static struct hdmi_driver_data exynos5420_hdmi_driver_data = {
  482. .type = HDMI_TYPE14,
  483. .phy_confs = hdmiphy_5420_configs,
  484. .phy_conf_count = ARRAY_SIZE(hdmiphy_5420_configs),
  485. .is_apb_phy = 1,
  486. };
  487. static struct hdmi_driver_data exynos4212_hdmi_driver_data = {
  488. .type = HDMI_TYPE14,
  489. .phy_confs = hdmiphy_v14_configs,
  490. .phy_conf_count = ARRAY_SIZE(hdmiphy_v14_configs),
  491. .is_apb_phy = 0,
  492. };
  493. static struct hdmi_driver_data exynos4210_hdmi_driver_data = {
  494. .type = HDMI_TYPE13,
  495. .phy_confs = hdmiphy_v13_configs,
  496. .phy_conf_count = ARRAY_SIZE(hdmiphy_v13_configs),
  497. .is_apb_phy = 0,
  498. };
  499. static inline u32 hdmi_map_reg(struct hdmi_context *hdata, u32 reg_id)
  500. {
  501. if ((reg_id & 0xffff0000) == HDMI_MAPPED_BASE)
  502. return hdmi_reg_map[reg_id & 0xffff][hdata->drv_data->type];
  503. return reg_id;
  504. }
  505. static inline u32 hdmi_reg_read(struct hdmi_context *hdata, u32 reg_id)
  506. {
  507. return readl(hdata->regs + hdmi_map_reg(hdata, reg_id));
  508. }
  509. static inline void hdmi_reg_writeb(struct hdmi_context *hdata,
  510. u32 reg_id, u8 value)
  511. {
  512. writel(value, hdata->regs + hdmi_map_reg(hdata, reg_id));
  513. }
  514. static inline void hdmi_reg_writev(struct hdmi_context *hdata, u32 reg_id,
  515. int bytes, u32 val)
  516. {
  517. reg_id = hdmi_map_reg(hdata, reg_id);
  518. while (--bytes >= 0) {
  519. writel(val & 0xff, hdata->regs + reg_id);
  520. val >>= 8;
  521. reg_id += 4;
  522. }
  523. }
  524. static inline void hdmi_reg_writemask(struct hdmi_context *hdata,
  525. u32 reg_id, u32 value, u32 mask)
  526. {
  527. u32 old;
  528. reg_id = hdmi_map_reg(hdata, reg_id);
  529. old = readl(hdata->regs + reg_id);
  530. value = (value & mask) | (old & ~mask);
  531. writel(value, hdata->regs + reg_id);
  532. }
  533. static int hdmiphy_reg_write_buf(struct hdmi_context *hdata,
  534. u32 reg_offset, const u8 *buf, u32 len)
  535. {
  536. if ((reg_offset + len) > 32)
  537. return -EINVAL;
  538. if (hdata->hdmiphy_port) {
  539. int ret;
  540. ret = i2c_master_send(hdata->hdmiphy_port, buf, len);
  541. if (ret == len)
  542. return 0;
  543. return ret;
  544. } else {
  545. int i;
  546. for (i = 0; i < len; i++)
  547. writel(buf[i], hdata->regs_hdmiphy +
  548. ((reg_offset + i)<<2));
  549. return 0;
  550. }
  551. }
  552. static void hdmi_v13_regs_dump(struct hdmi_context *hdata, char *prefix)
  553. {
  554. #define DUMPREG(reg_id) \
  555. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  556. readl(hdata->regs + reg_id))
  557. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  558. DUMPREG(HDMI_INTC_FLAG);
  559. DUMPREG(HDMI_INTC_CON);
  560. DUMPREG(HDMI_HPD_STATUS);
  561. DUMPREG(HDMI_V13_PHY_RSTOUT);
  562. DUMPREG(HDMI_V13_PHY_VPLL);
  563. DUMPREG(HDMI_V13_PHY_CMU);
  564. DUMPREG(HDMI_V13_CORE_RSTOUT);
  565. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  566. DUMPREG(HDMI_CON_0);
  567. DUMPREG(HDMI_CON_1);
  568. DUMPREG(HDMI_CON_2);
  569. DUMPREG(HDMI_SYS_STATUS);
  570. DUMPREG(HDMI_V13_PHY_STATUS);
  571. DUMPREG(HDMI_STATUS_EN);
  572. DUMPREG(HDMI_HPD);
  573. DUMPREG(HDMI_MODE_SEL);
  574. DUMPREG(HDMI_V13_HPD_GEN);
  575. DUMPREG(HDMI_V13_DC_CONTROL);
  576. DUMPREG(HDMI_V13_VIDEO_PATTERN_GEN);
  577. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  578. DUMPREG(HDMI_H_BLANK_0);
  579. DUMPREG(HDMI_H_BLANK_1);
  580. DUMPREG(HDMI_V13_V_BLANK_0);
  581. DUMPREG(HDMI_V13_V_BLANK_1);
  582. DUMPREG(HDMI_V13_V_BLANK_2);
  583. DUMPREG(HDMI_V13_H_V_LINE_0);
  584. DUMPREG(HDMI_V13_H_V_LINE_1);
  585. DUMPREG(HDMI_V13_H_V_LINE_2);
  586. DUMPREG(HDMI_VSYNC_POL);
  587. DUMPREG(HDMI_INT_PRO_MODE);
  588. DUMPREG(HDMI_V13_V_BLANK_F_0);
  589. DUMPREG(HDMI_V13_V_BLANK_F_1);
  590. DUMPREG(HDMI_V13_V_BLANK_F_2);
  591. DUMPREG(HDMI_V13_H_SYNC_GEN_0);
  592. DUMPREG(HDMI_V13_H_SYNC_GEN_1);
  593. DUMPREG(HDMI_V13_H_SYNC_GEN_2);
  594. DUMPREG(HDMI_V13_V_SYNC_GEN_1_0);
  595. DUMPREG(HDMI_V13_V_SYNC_GEN_1_1);
  596. DUMPREG(HDMI_V13_V_SYNC_GEN_1_2);
  597. DUMPREG(HDMI_V13_V_SYNC_GEN_2_0);
  598. DUMPREG(HDMI_V13_V_SYNC_GEN_2_1);
  599. DUMPREG(HDMI_V13_V_SYNC_GEN_2_2);
  600. DUMPREG(HDMI_V13_V_SYNC_GEN_3_0);
  601. DUMPREG(HDMI_V13_V_SYNC_GEN_3_1);
  602. DUMPREG(HDMI_V13_V_SYNC_GEN_3_2);
  603. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  604. DUMPREG(HDMI_TG_CMD);
  605. DUMPREG(HDMI_TG_H_FSZ_L);
  606. DUMPREG(HDMI_TG_H_FSZ_H);
  607. DUMPREG(HDMI_TG_HACT_ST_L);
  608. DUMPREG(HDMI_TG_HACT_ST_H);
  609. DUMPREG(HDMI_TG_HACT_SZ_L);
  610. DUMPREG(HDMI_TG_HACT_SZ_H);
  611. DUMPREG(HDMI_TG_V_FSZ_L);
  612. DUMPREG(HDMI_TG_V_FSZ_H);
  613. DUMPREG(HDMI_TG_VSYNC_L);
  614. DUMPREG(HDMI_TG_VSYNC_H);
  615. DUMPREG(HDMI_TG_VSYNC2_L);
  616. DUMPREG(HDMI_TG_VSYNC2_H);
  617. DUMPREG(HDMI_TG_VACT_ST_L);
  618. DUMPREG(HDMI_TG_VACT_ST_H);
  619. DUMPREG(HDMI_TG_VACT_SZ_L);
  620. DUMPREG(HDMI_TG_VACT_SZ_H);
  621. DUMPREG(HDMI_TG_FIELD_CHG_L);
  622. DUMPREG(HDMI_TG_FIELD_CHG_H);
  623. DUMPREG(HDMI_TG_VACT_ST2_L);
  624. DUMPREG(HDMI_TG_VACT_ST2_H);
  625. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  626. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  627. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  628. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  629. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  630. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  631. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  632. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  633. #undef DUMPREG
  634. }
  635. static void hdmi_v14_regs_dump(struct hdmi_context *hdata, char *prefix)
  636. {
  637. int i;
  638. #define DUMPREG(reg_id) \
  639. DRM_DEBUG_KMS("%s:" #reg_id " = %08x\n", prefix, \
  640. readl(hdata->regs + reg_id))
  641. DRM_DEBUG_KMS("%s: ---- CONTROL REGISTERS ----\n", prefix);
  642. DUMPREG(HDMI_INTC_CON);
  643. DUMPREG(HDMI_INTC_FLAG);
  644. DUMPREG(HDMI_HPD_STATUS);
  645. DUMPREG(HDMI_INTC_CON_1);
  646. DUMPREG(HDMI_INTC_FLAG_1);
  647. DUMPREG(HDMI_PHY_STATUS_0);
  648. DUMPREG(HDMI_PHY_STATUS_PLL);
  649. DUMPREG(HDMI_PHY_CON_0);
  650. DUMPREG(HDMI_V14_PHY_RSTOUT);
  651. DUMPREG(HDMI_PHY_VPLL);
  652. DUMPREG(HDMI_PHY_CMU);
  653. DUMPREG(HDMI_CORE_RSTOUT);
  654. DRM_DEBUG_KMS("%s: ---- CORE REGISTERS ----\n", prefix);
  655. DUMPREG(HDMI_CON_0);
  656. DUMPREG(HDMI_CON_1);
  657. DUMPREG(HDMI_CON_2);
  658. DUMPREG(HDMI_SYS_STATUS);
  659. DUMPREG(HDMI_PHY_STATUS_0);
  660. DUMPREG(HDMI_STATUS_EN);
  661. DUMPREG(HDMI_HPD);
  662. DUMPREG(HDMI_MODE_SEL);
  663. DUMPREG(HDMI_ENC_EN);
  664. DUMPREG(HDMI_DC_CONTROL);
  665. DUMPREG(HDMI_VIDEO_PATTERN_GEN);
  666. DRM_DEBUG_KMS("%s: ---- CORE SYNC REGISTERS ----\n", prefix);
  667. DUMPREG(HDMI_H_BLANK_0);
  668. DUMPREG(HDMI_H_BLANK_1);
  669. DUMPREG(HDMI_V2_BLANK_0);
  670. DUMPREG(HDMI_V2_BLANK_1);
  671. DUMPREG(HDMI_V1_BLANK_0);
  672. DUMPREG(HDMI_V1_BLANK_1);
  673. DUMPREG(HDMI_V_LINE_0);
  674. DUMPREG(HDMI_V_LINE_1);
  675. DUMPREG(HDMI_H_LINE_0);
  676. DUMPREG(HDMI_H_LINE_1);
  677. DUMPREG(HDMI_HSYNC_POL);
  678. DUMPREG(HDMI_VSYNC_POL);
  679. DUMPREG(HDMI_INT_PRO_MODE);
  680. DUMPREG(HDMI_V_BLANK_F0_0);
  681. DUMPREG(HDMI_V_BLANK_F0_1);
  682. DUMPREG(HDMI_V_BLANK_F1_0);
  683. DUMPREG(HDMI_V_BLANK_F1_1);
  684. DUMPREG(HDMI_H_SYNC_START_0);
  685. DUMPREG(HDMI_H_SYNC_START_1);
  686. DUMPREG(HDMI_H_SYNC_END_0);
  687. DUMPREG(HDMI_H_SYNC_END_1);
  688. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_0);
  689. DUMPREG(HDMI_V_SYNC_LINE_BEF_2_1);
  690. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_0);
  691. DUMPREG(HDMI_V_SYNC_LINE_BEF_1_1);
  692. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_0);
  693. DUMPREG(HDMI_V_SYNC_LINE_AFT_2_1);
  694. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_0);
  695. DUMPREG(HDMI_V_SYNC_LINE_AFT_1_1);
  696. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_0);
  697. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_2_1);
  698. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_0);
  699. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_1_1);
  700. DUMPREG(HDMI_V_BLANK_F2_0);
  701. DUMPREG(HDMI_V_BLANK_F2_1);
  702. DUMPREG(HDMI_V_BLANK_F3_0);
  703. DUMPREG(HDMI_V_BLANK_F3_1);
  704. DUMPREG(HDMI_V_BLANK_F4_0);
  705. DUMPREG(HDMI_V_BLANK_F4_1);
  706. DUMPREG(HDMI_V_BLANK_F5_0);
  707. DUMPREG(HDMI_V_BLANK_F5_1);
  708. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_0);
  709. DUMPREG(HDMI_V_SYNC_LINE_AFT_3_1);
  710. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_0);
  711. DUMPREG(HDMI_V_SYNC_LINE_AFT_4_1);
  712. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_0);
  713. DUMPREG(HDMI_V_SYNC_LINE_AFT_5_1);
  714. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_0);
  715. DUMPREG(HDMI_V_SYNC_LINE_AFT_6_1);
  716. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_0);
  717. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_3_1);
  718. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_0);
  719. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_4_1);
  720. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_0);
  721. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_5_1);
  722. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_0);
  723. DUMPREG(HDMI_V_SYNC_LINE_AFT_PXL_6_1);
  724. DUMPREG(HDMI_VACT_SPACE_1_0);
  725. DUMPREG(HDMI_VACT_SPACE_1_1);
  726. DUMPREG(HDMI_VACT_SPACE_2_0);
  727. DUMPREG(HDMI_VACT_SPACE_2_1);
  728. DUMPREG(HDMI_VACT_SPACE_3_0);
  729. DUMPREG(HDMI_VACT_SPACE_3_1);
  730. DUMPREG(HDMI_VACT_SPACE_4_0);
  731. DUMPREG(HDMI_VACT_SPACE_4_1);
  732. DUMPREG(HDMI_VACT_SPACE_5_0);
  733. DUMPREG(HDMI_VACT_SPACE_5_1);
  734. DUMPREG(HDMI_VACT_SPACE_6_0);
  735. DUMPREG(HDMI_VACT_SPACE_6_1);
  736. DRM_DEBUG_KMS("%s: ---- TG REGISTERS ----\n", prefix);
  737. DUMPREG(HDMI_TG_CMD);
  738. DUMPREG(HDMI_TG_H_FSZ_L);
  739. DUMPREG(HDMI_TG_H_FSZ_H);
  740. DUMPREG(HDMI_TG_HACT_ST_L);
  741. DUMPREG(HDMI_TG_HACT_ST_H);
  742. DUMPREG(HDMI_TG_HACT_SZ_L);
  743. DUMPREG(HDMI_TG_HACT_SZ_H);
  744. DUMPREG(HDMI_TG_V_FSZ_L);
  745. DUMPREG(HDMI_TG_V_FSZ_H);
  746. DUMPREG(HDMI_TG_VSYNC_L);
  747. DUMPREG(HDMI_TG_VSYNC_H);
  748. DUMPREG(HDMI_TG_VSYNC2_L);
  749. DUMPREG(HDMI_TG_VSYNC2_H);
  750. DUMPREG(HDMI_TG_VACT_ST_L);
  751. DUMPREG(HDMI_TG_VACT_ST_H);
  752. DUMPREG(HDMI_TG_VACT_SZ_L);
  753. DUMPREG(HDMI_TG_VACT_SZ_H);
  754. DUMPREG(HDMI_TG_FIELD_CHG_L);
  755. DUMPREG(HDMI_TG_FIELD_CHG_H);
  756. DUMPREG(HDMI_TG_VACT_ST2_L);
  757. DUMPREG(HDMI_TG_VACT_ST2_H);
  758. DUMPREG(HDMI_TG_VACT_ST3_L);
  759. DUMPREG(HDMI_TG_VACT_ST3_H);
  760. DUMPREG(HDMI_TG_VACT_ST4_L);
  761. DUMPREG(HDMI_TG_VACT_ST4_H);
  762. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_L);
  763. DUMPREG(HDMI_TG_VSYNC_TOP_HDMI_H);
  764. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_L);
  765. DUMPREG(HDMI_TG_VSYNC_BOT_HDMI_H);
  766. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_L);
  767. DUMPREG(HDMI_TG_FIELD_TOP_HDMI_H);
  768. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_L);
  769. DUMPREG(HDMI_TG_FIELD_BOT_HDMI_H);
  770. DUMPREG(HDMI_TG_3D);
  771. DRM_DEBUG_KMS("%s: ---- PACKET REGISTERS ----\n", prefix);
  772. DUMPREG(HDMI_AVI_CON);
  773. DUMPREG(HDMI_AVI_HEADER0);
  774. DUMPREG(HDMI_AVI_HEADER1);
  775. DUMPREG(HDMI_AVI_HEADER2);
  776. DUMPREG(HDMI_AVI_CHECK_SUM);
  777. DUMPREG(HDMI_VSI_CON);
  778. DUMPREG(HDMI_VSI_HEADER0);
  779. DUMPREG(HDMI_VSI_HEADER1);
  780. DUMPREG(HDMI_VSI_HEADER2);
  781. for (i = 0; i < 7; ++i)
  782. DUMPREG(HDMI_VSI_DATA(i));
  783. #undef DUMPREG
  784. }
  785. static void hdmi_regs_dump(struct hdmi_context *hdata, char *prefix)
  786. {
  787. if (hdata->drv_data->type == HDMI_TYPE13)
  788. hdmi_v13_regs_dump(hdata, prefix);
  789. else
  790. hdmi_v14_regs_dump(hdata, prefix);
  791. }
  792. static u8 hdmi_chksum(struct hdmi_context *hdata,
  793. u32 start, u8 len, u32 hdr_sum)
  794. {
  795. int i;
  796. /* hdr_sum : header0 + header1 + header2
  797. * start : start address of packet byte1
  798. * len : packet bytes - 1 */
  799. for (i = 0; i < len; ++i)
  800. hdr_sum += 0xff & hdmi_reg_read(hdata, start + i * 4);
  801. /* return 2's complement of 8 bit hdr_sum */
  802. return (u8)(~(hdr_sum & 0xff) + 1);
  803. }
  804. static void hdmi_reg_infoframe(struct hdmi_context *hdata,
  805. union hdmi_infoframe *infoframe)
  806. {
  807. u32 hdr_sum;
  808. u8 chksum;
  809. u8 ar;
  810. if (hdata->dvi_mode) {
  811. hdmi_reg_writeb(hdata, HDMI_VSI_CON,
  812. HDMI_VSI_CON_DO_NOT_TRANSMIT);
  813. hdmi_reg_writeb(hdata, HDMI_AVI_CON,
  814. HDMI_AVI_CON_DO_NOT_TRANSMIT);
  815. hdmi_reg_writeb(hdata, HDMI_AUI_CON, HDMI_AUI_CON_NO_TRAN);
  816. return;
  817. }
  818. switch (infoframe->any.type) {
  819. case HDMI_INFOFRAME_TYPE_AVI:
  820. hdmi_reg_writeb(hdata, HDMI_AVI_CON, HDMI_AVI_CON_EVERY_VSYNC);
  821. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER0, infoframe->any.type);
  822. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER1,
  823. infoframe->any.version);
  824. hdmi_reg_writeb(hdata, HDMI_AVI_HEADER2, infoframe->any.length);
  825. hdr_sum = infoframe->any.type + infoframe->any.version +
  826. infoframe->any.length;
  827. /* Output format zero hardcoded ,RGB YBCR selection */
  828. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(1), 0 << 5 |
  829. AVI_ACTIVE_FORMAT_VALID |
  830. AVI_UNDERSCANNED_DISPLAY_VALID);
  831. /*
  832. * Set the aspect ratio as per the mode, mentioned in
  833. * Table 9 AVI InfoFrame Data Byte 2 of CEA-861-D Standard
  834. */
  835. ar = hdata->current_mode.picture_aspect_ratio;
  836. switch (ar) {
  837. case HDMI_PICTURE_ASPECT_4_3:
  838. ar |= AVI_4_3_CENTER_RATIO;
  839. break;
  840. case HDMI_PICTURE_ASPECT_16_9:
  841. ar |= AVI_16_9_CENTER_RATIO;
  842. break;
  843. case HDMI_PICTURE_ASPECT_NONE:
  844. default:
  845. ar |= AVI_SAME_AS_PIC_ASPECT_RATIO;
  846. break;
  847. }
  848. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(2), ar);
  849. hdmi_reg_writeb(hdata, HDMI_AVI_BYTE(4), hdata->cea_video_id);
  850. chksum = hdmi_chksum(hdata, HDMI_AVI_BYTE(1),
  851. infoframe->any.length, hdr_sum);
  852. DRM_DEBUG_KMS("AVI checksum = 0x%x\n", chksum);
  853. hdmi_reg_writeb(hdata, HDMI_AVI_CHECK_SUM, chksum);
  854. break;
  855. case HDMI_INFOFRAME_TYPE_AUDIO:
  856. hdmi_reg_writeb(hdata, HDMI_AUI_CON, 0x02);
  857. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER0, infoframe->any.type);
  858. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER1,
  859. infoframe->any.version);
  860. hdmi_reg_writeb(hdata, HDMI_AUI_HEADER2, infoframe->any.length);
  861. hdr_sum = infoframe->any.type + infoframe->any.version +
  862. infoframe->any.length;
  863. chksum = hdmi_chksum(hdata, HDMI_AUI_BYTE(1),
  864. infoframe->any.length, hdr_sum);
  865. DRM_DEBUG_KMS("AUI checksum = 0x%x\n", chksum);
  866. hdmi_reg_writeb(hdata, HDMI_AUI_CHECK_SUM, chksum);
  867. break;
  868. default:
  869. break;
  870. }
  871. }
  872. static enum drm_connector_status hdmi_detect(struct drm_connector *connector,
  873. bool force)
  874. {
  875. struct hdmi_context *hdata = connector_to_hdmi(connector);
  876. if (gpiod_get_value(hdata->hpd_gpio))
  877. return connector_status_connected;
  878. return connector_status_disconnected;
  879. }
  880. static void hdmi_connector_destroy(struct drm_connector *connector)
  881. {
  882. drm_connector_unregister(connector);
  883. drm_connector_cleanup(connector);
  884. }
  885. static const struct drm_connector_funcs hdmi_connector_funcs = {
  886. .dpms = drm_atomic_helper_connector_dpms,
  887. .fill_modes = drm_helper_probe_single_connector_modes,
  888. .detect = hdmi_detect,
  889. .destroy = hdmi_connector_destroy,
  890. .reset = drm_atomic_helper_connector_reset,
  891. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  892. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  893. };
  894. static int hdmi_get_modes(struct drm_connector *connector)
  895. {
  896. struct hdmi_context *hdata = connector_to_hdmi(connector);
  897. struct edid *edid;
  898. int ret;
  899. if (!hdata->ddc_adpt)
  900. return -ENODEV;
  901. edid = drm_get_edid(connector, hdata->ddc_adpt);
  902. if (!edid)
  903. return -ENODEV;
  904. hdata->dvi_mode = !drm_detect_hdmi_monitor(edid);
  905. DRM_DEBUG_KMS("%s : width[%d] x height[%d]\n",
  906. (hdata->dvi_mode ? "dvi monitor" : "hdmi monitor"),
  907. edid->width_cm, edid->height_cm);
  908. drm_mode_connector_update_edid_property(connector, edid);
  909. ret = drm_add_edid_modes(connector, edid);
  910. kfree(edid);
  911. return ret;
  912. }
  913. static int hdmi_find_phy_conf(struct hdmi_context *hdata, u32 pixel_clock)
  914. {
  915. int i;
  916. for (i = 0; i < hdata->drv_data->phy_conf_count; i++)
  917. if (hdata->drv_data->phy_confs[i].pixel_clock == pixel_clock)
  918. return i;
  919. DRM_DEBUG_KMS("Could not find phy config for %d\n", pixel_clock);
  920. return -EINVAL;
  921. }
  922. static int hdmi_mode_valid(struct drm_connector *connector,
  923. struct drm_display_mode *mode)
  924. {
  925. struct hdmi_context *hdata = connector_to_hdmi(connector);
  926. int ret;
  927. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
  928. mode->hdisplay, mode->vdisplay, mode->vrefresh,
  929. (mode->flags & DRM_MODE_FLAG_INTERLACE) ? true :
  930. false, mode->clock * 1000);
  931. ret = hdmi_find_phy_conf(hdata, mode->clock * 1000);
  932. if (ret < 0)
  933. return MODE_BAD;
  934. return MODE_OK;
  935. }
  936. static struct drm_encoder *hdmi_best_encoder(struct drm_connector *connector)
  937. {
  938. struct hdmi_context *hdata = connector_to_hdmi(connector);
  939. return &hdata->encoder;
  940. }
  941. static const struct drm_connector_helper_funcs hdmi_connector_helper_funcs = {
  942. .get_modes = hdmi_get_modes,
  943. .mode_valid = hdmi_mode_valid,
  944. .best_encoder = hdmi_best_encoder,
  945. };
  946. static int hdmi_create_connector(struct drm_encoder *encoder)
  947. {
  948. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  949. struct drm_connector *connector = &hdata->connector;
  950. int ret;
  951. connector->interlace_allowed = true;
  952. connector->polled = DRM_CONNECTOR_POLL_HPD;
  953. ret = drm_connector_init(hdata->drm_dev, connector,
  954. &hdmi_connector_funcs, DRM_MODE_CONNECTOR_HDMIA);
  955. if (ret) {
  956. DRM_ERROR("Failed to initialize connector with drm\n");
  957. return ret;
  958. }
  959. drm_connector_helper_add(connector, &hdmi_connector_helper_funcs);
  960. drm_connector_register(connector);
  961. drm_mode_connector_attach_encoder(connector, encoder);
  962. return 0;
  963. }
  964. static bool hdmi_mode_fixup(struct drm_encoder *encoder,
  965. const struct drm_display_mode *mode,
  966. struct drm_display_mode *adjusted_mode)
  967. {
  968. struct drm_device *dev = encoder->dev;
  969. struct drm_connector *connector;
  970. struct drm_display_mode *m;
  971. int mode_ok;
  972. drm_mode_set_crtcinfo(adjusted_mode, 0);
  973. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  974. if (connector->encoder == encoder)
  975. break;
  976. }
  977. if (connector->encoder != encoder)
  978. return true;
  979. mode_ok = hdmi_mode_valid(connector, adjusted_mode);
  980. /* just return if user desired mode exists. */
  981. if (mode_ok == MODE_OK)
  982. return true;
  983. /*
  984. * otherwise, find the most suitable mode among modes and change it
  985. * to adjusted_mode.
  986. */
  987. list_for_each_entry(m, &connector->modes, head) {
  988. mode_ok = hdmi_mode_valid(connector, m);
  989. if (mode_ok == MODE_OK) {
  990. DRM_INFO("desired mode doesn't exist so\n");
  991. DRM_INFO("use the most suitable mode among modes.\n");
  992. DRM_DEBUG_KMS("Adjusted Mode: [%d]x[%d] [%d]Hz\n",
  993. m->hdisplay, m->vdisplay, m->vrefresh);
  994. drm_mode_copy(adjusted_mode, m);
  995. break;
  996. }
  997. }
  998. return true;
  999. }
  1000. static void hdmi_reg_acr(struct hdmi_context *hdata, u32 freq)
  1001. {
  1002. u32 n, cts;
  1003. cts = (freq % 9) ? 27000 : 30000;
  1004. n = 128 * freq / (27000000 / cts);
  1005. hdmi_reg_writev(hdata, HDMI_ACR_N0, 3, n);
  1006. hdmi_reg_writev(hdata, HDMI_ACR_MCTS0, 3, cts);
  1007. hdmi_reg_writev(hdata, HDMI_ACR_CTS0, 3, cts);
  1008. hdmi_reg_writeb(hdata, HDMI_ACR_CON, 4);
  1009. }
  1010. static void hdmi_audio_init(struct hdmi_context *hdata)
  1011. {
  1012. u32 sample_rate, bits_per_sample;
  1013. u32 data_num, bit_ch, sample_frq;
  1014. u32 val;
  1015. sample_rate = 44100;
  1016. bits_per_sample = 16;
  1017. switch (bits_per_sample) {
  1018. case 20:
  1019. data_num = 2;
  1020. bit_ch = 1;
  1021. break;
  1022. case 24:
  1023. data_num = 3;
  1024. bit_ch = 1;
  1025. break;
  1026. default:
  1027. data_num = 1;
  1028. bit_ch = 0;
  1029. break;
  1030. }
  1031. hdmi_reg_acr(hdata, sample_rate);
  1032. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CON, HDMI_I2S_IN_DISABLE
  1033. | HDMI_I2S_AUD_I2S | HDMI_I2S_CUV_I2S_ENABLE
  1034. | HDMI_I2S_MUX_ENABLE);
  1035. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CH, HDMI_I2S_CH0_EN
  1036. | HDMI_I2S_CH1_EN | HDMI_I2S_CH2_EN);
  1037. hdmi_reg_writeb(hdata, HDMI_I2S_MUX_CUV, HDMI_I2S_CUV_RL_EN);
  1038. sample_frq = (sample_rate == 44100) ? 0 :
  1039. (sample_rate == 48000) ? 2 :
  1040. (sample_rate == 32000) ? 3 :
  1041. (sample_rate == 96000) ? 0xa : 0x0;
  1042. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_DIS);
  1043. hdmi_reg_writeb(hdata, HDMI_I2S_CLK_CON, HDMI_I2S_CLK_EN);
  1044. val = hdmi_reg_read(hdata, HDMI_I2S_DSD_CON) | 0x01;
  1045. hdmi_reg_writeb(hdata, HDMI_I2S_DSD_CON, val);
  1046. /* Configuration I2S input ports. Configure I2S_PIN_SEL_0~4 */
  1047. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_0, HDMI_I2S_SEL_SCLK(5)
  1048. | HDMI_I2S_SEL_LRCK(6));
  1049. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_1, HDMI_I2S_SEL_SDATA1(1)
  1050. | HDMI_I2S_SEL_SDATA2(4));
  1051. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_2, HDMI_I2S_SEL_SDATA3(1)
  1052. | HDMI_I2S_SEL_SDATA2(2));
  1053. hdmi_reg_writeb(hdata, HDMI_I2S_PIN_SEL_3, HDMI_I2S_SEL_DSD(0));
  1054. /* I2S_CON_1 & 2 */
  1055. hdmi_reg_writeb(hdata, HDMI_I2S_CON_1, HDMI_I2S_SCLK_FALLING_EDGE
  1056. | HDMI_I2S_L_CH_LOW_POL);
  1057. hdmi_reg_writeb(hdata, HDMI_I2S_CON_2, HDMI_I2S_MSB_FIRST_MODE
  1058. | HDMI_I2S_SET_BIT_CH(bit_ch)
  1059. | HDMI_I2S_SET_SDATA_BIT(data_num)
  1060. | HDMI_I2S_BASIC_FORMAT);
  1061. /* Configure register related to CUV information */
  1062. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_0, HDMI_I2S_CH_STATUS_MODE_0
  1063. | HDMI_I2S_2AUD_CH_WITHOUT_PREEMPH
  1064. | HDMI_I2S_COPYRIGHT
  1065. | HDMI_I2S_LINEAR_PCM
  1066. | HDMI_I2S_CONSUMER_FORMAT);
  1067. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_1, HDMI_I2S_CD_PLAYER);
  1068. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_2, HDMI_I2S_SET_SOURCE_NUM(0));
  1069. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_3, HDMI_I2S_CLK_ACCUR_LEVEL_2
  1070. | HDMI_I2S_SET_SMP_FREQ(sample_frq));
  1071. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_4,
  1072. HDMI_I2S_ORG_SMP_FREQ_44_1
  1073. | HDMI_I2S_WORD_LEN_MAX24_24BITS
  1074. | HDMI_I2S_WORD_LEN_MAX_24BITS);
  1075. hdmi_reg_writeb(hdata, HDMI_I2S_CH_ST_CON, HDMI_I2S_CH_STATUS_RELOAD);
  1076. }
  1077. static void hdmi_audio_control(struct hdmi_context *hdata, bool onoff)
  1078. {
  1079. if (hdata->dvi_mode)
  1080. return;
  1081. hdmi_reg_writeb(hdata, HDMI_AUI_CON, onoff ? 2 : 0);
  1082. hdmi_reg_writemask(hdata, HDMI_CON_0, onoff ?
  1083. HDMI_ASP_EN : HDMI_ASP_DIS, HDMI_ASP_MASK);
  1084. }
  1085. static void hdmi_start(struct hdmi_context *hdata, bool start)
  1086. {
  1087. u32 val = start ? HDMI_TG_EN : 0;
  1088. if (hdata->current_mode.flags & DRM_MODE_FLAG_INTERLACE)
  1089. val |= HDMI_FIELD_EN;
  1090. hdmi_reg_writemask(hdata, HDMI_CON_0, val, HDMI_EN);
  1091. hdmi_reg_writemask(hdata, HDMI_TG_CMD, val, HDMI_TG_EN | HDMI_FIELD_EN);
  1092. }
  1093. static void hdmi_conf_init(struct hdmi_context *hdata)
  1094. {
  1095. union hdmi_infoframe infoframe;
  1096. /* disable HPD interrupts from HDMI IP block, use GPIO instead */
  1097. hdmi_reg_writemask(hdata, HDMI_INTC_CON, 0, HDMI_INTC_EN_GLOBAL |
  1098. HDMI_INTC_EN_HPD_PLUG | HDMI_INTC_EN_HPD_UNPLUG);
  1099. /* choose HDMI mode */
  1100. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1101. HDMI_MODE_HDMI_EN, HDMI_MODE_MASK);
  1102. /* Apply Video preable and Guard band in HDMI mode only */
  1103. hdmi_reg_writeb(hdata, HDMI_CON_2, 0);
  1104. /* disable bluescreen */
  1105. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_BLUE_SCR_EN);
  1106. if (hdata->dvi_mode) {
  1107. /* choose DVI mode */
  1108. hdmi_reg_writemask(hdata, HDMI_MODE_SEL,
  1109. HDMI_MODE_DVI_EN, HDMI_MODE_MASK);
  1110. hdmi_reg_writeb(hdata, HDMI_CON_2,
  1111. HDMI_VID_PREAMBLE_DIS | HDMI_GUARD_BAND_DIS);
  1112. }
  1113. if (hdata->drv_data->type == HDMI_TYPE13) {
  1114. /* choose bluescreen (fecal) color */
  1115. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_0, 0x12);
  1116. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_1, 0x34);
  1117. hdmi_reg_writeb(hdata, HDMI_V13_BLUE_SCREEN_2, 0x56);
  1118. /* enable AVI packet every vsync, fixes purple line problem */
  1119. hdmi_reg_writeb(hdata, HDMI_V13_AVI_CON, 0x02);
  1120. /* force RGB, look to CEA-861-D, table 7 for more detail */
  1121. hdmi_reg_writeb(hdata, HDMI_V13_AVI_BYTE(0), 0 << 5);
  1122. hdmi_reg_writemask(hdata, HDMI_CON_1, 0x10 << 5, 0x11 << 5);
  1123. hdmi_reg_writeb(hdata, HDMI_V13_SPD_CON, 0x02);
  1124. hdmi_reg_writeb(hdata, HDMI_V13_AUI_CON, 0x02);
  1125. hdmi_reg_writeb(hdata, HDMI_V13_ACR_CON, 0x04);
  1126. } else {
  1127. infoframe.any.type = HDMI_INFOFRAME_TYPE_AVI;
  1128. infoframe.any.version = HDMI_AVI_VERSION;
  1129. infoframe.any.length = HDMI_AVI_LENGTH;
  1130. hdmi_reg_infoframe(hdata, &infoframe);
  1131. infoframe.any.type = HDMI_INFOFRAME_TYPE_AUDIO;
  1132. infoframe.any.version = HDMI_AUI_VERSION;
  1133. infoframe.any.length = HDMI_AUI_LENGTH;
  1134. hdmi_reg_infoframe(hdata, &infoframe);
  1135. /* enable AVI packet every vsync, fixes purple line problem */
  1136. hdmi_reg_writemask(hdata, HDMI_CON_1, 2, 3 << 5);
  1137. }
  1138. }
  1139. static void hdmiphy_wait_for_pll(struct hdmi_context *hdata)
  1140. {
  1141. int tries;
  1142. for (tries = 0; tries < 10; ++tries) {
  1143. u32 val = hdmi_reg_read(hdata, HDMI_PHY_STATUS);
  1144. if (val & HDMI_PHY_STATUS_READY) {
  1145. DRM_DEBUG_KMS("PLL stabilized after %d tries\n", tries);
  1146. return;
  1147. }
  1148. usleep_range(10, 20);
  1149. }
  1150. DRM_ERROR("PLL could not reach steady state\n");
  1151. }
  1152. static void hdmi_v13_mode_apply(struct hdmi_context *hdata)
  1153. {
  1154. struct drm_display_mode *m = &hdata->current_mode;
  1155. unsigned int val;
  1156. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1157. hdmi_reg_writev(hdata, HDMI_V13_H_V_LINE_0, 3,
  1158. (m->htotal << 12) | m->vtotal);
  1159. val = (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0;
  1160. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1, val);
  1161. val = (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0;
  1162. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1, val);
  1163. val = (m->hsync_start - m->hdisplay - 2);
  1164. val |= ((m->hsync_end - m->hdisplay - 2) << 10);
  1165. val |= ((m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0)<<20;
  1166. hdmi_reg_writev(hdata, HDMI_V13_H_SYNC_GEN_0, 3, val);
  1167. /*
  1168. * Quirk requirement for exynos HDMI IP design,
  1169. * 2 pixels less than the actual calculation for hsync_start
  1170. * and end.
  1171. */
  1172. /* Following values & calculations differ for different type of modes */
  1173. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1174. /* Interlaced Mode */
  1175. val = ((m->vsync_end - m->vdisplay) / 2);
  1176. val |= ((m->vsync_start - m->vdisplay) / 2) << 12;
  1177. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1178. val = m->vtotal / 2;
  1179. val |= ((m->vtotal - m->vdisplay) / 2) << 11;
  1180. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1181. val = (m->vtotal +
  1182. ((m->vsync_end - m->vsync_start) * 4) + 5) / 2;
  1183. val |= m->vtotal << 11;
  1184. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, val);
  1185. val = ((m->vtotal / 2) + 7);
  1186. val |= ((m->vtotal / 2) + 2) << 12;
  1187. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, val);
  1188. val = ((m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1189. val |= ((m->htotal / 2) +
  1190. (m->hsync_start - m->hdisplay)) << 12;
  1191. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, val);
  1192. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1193. (m->vtotal - m->vdisplay) / 2);
  1194. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1195. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x249);
  1196. } else {
  1197. /* Progressive Mode */
  1198. val = m->vtotal;
  1199. val |= (m->vtotal - m->vdisplay) << 11;
  1200. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_0, 3, val);
  1201. hdmi_reg_writev(hdata, HDMI_V13_V_BLANK_F_0, 3, 0);
  1202. val = (m->vsync_end - m->vdisplay);
  1203. val |= ((m->vsync_start - m->vdisplay) << 12);
  1204. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_1_0, 3, val);
  1205. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_2_0, 3, 0x1001);
  1206. hdmi_reg_writev(hdata, HDMI_V13_V_SYNC_GEN_3_0, 3, 0x1001);
  1207. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1208. m->vtotal - m->vdisplay);
  1209. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1210. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x248);
  1211. }
  1212. /* Timing generator registers */
  1213. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1214. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1215. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1216. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1217. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_L, 2, 0x1);
  1218. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2, 0x233);
  1219. hdmi_reg_writev(hdata, HDMI_TG_FIELD_CHG_L, 2, 0x233);
  1220. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, 2, 0x1);
  1221. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2, 0x233);
  1222. hdmi_reg_writev(hdata, HDMI_TG_FIELD_TOP_HDMI_L, 2, 0x1);
  1223. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2, 0x233);
  1224. }
  1225. static void hdmi_v14_mode_apply(struct hdmi_context *hdata)
  1226. {
  1227. struct drm_display_mode *m = &hdata->current_mode;
  1228. hdmi_reg_writev(hdata, HDMI_H_BLANK_0, 2, m->htotal - m->hdisplay);
  1229. hdmi_reg_writev(hdata, HDMI_V_LINE_0, 2, m->vtotal);
  1230. hdmi_reg_writev(hdata, HDMI_H_LINE_0, 2, m->htotal);
  1231. hdmi_reg_writev(hdata, HDMI_HSYNC_POL, 1,
  1232. (m->flags & DRM_MODE_FLAG_NHSYNC) ? 1 : 0);
  1233. hdmi_reg_writev(hdata, HDMI_VSYNC_POL, 1,
  1234. (m->flags & DRM_MODE_FLAG_NVSYNC) ? 1 : 0);
  1235. hdmi_reg_writev(hdata, HDMI_INT_PRO_MODE, 1,
  1236. (m->flags & DRM_MODE_FLAG_INTERLACE) ? 1 : 0);
  1237. /*
  1238. * Quirk requirement for exynos 5 HDMI IP design,
  1239. * 2 pixels less than the actual calculation for hsync_start
  1240. * and end.
  1241. */
  1242. /* Following values & calculations differ for different type of modes */
  1243. if (m->flags & DRM_MODE_FLAG_INTERLACE) {
  1244. /* Interlaced Mode */
  1245. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1246. (m->vsync_end - m->vdisplay) / 2);
  1247. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1248. (m->vsync_start - m->vdisplay) / 2);
  1249. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal / 2);
  1250. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1251. (m->vtotal - m->vdisplay) / 2);
  1252. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2,
  1253. m->vtotal - m->vdisplay / 2);
  1254. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, m->vtotal);
  1255. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2,
  1256. (m->vtotal / 2) + 7);
  1257. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2,
  1258. (m->vtotal / 2) + 2);
  1259. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2,
  1260. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1261. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2,
  1262. (m->htotal / 2) + (m->hsync_start - m->hdisplay));
  1263. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1264. (m->vtotal - m->vdisplay) / 2);
  1265. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay / 2);
  1266. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2,
  1267. m->vtotal - m->vdisplay / 2);
  1268. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2,
  1269. (m->vtotal / 2) + 1);
  1270. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2,
  1271. (m->vtotal / 2) + 1);
  1272. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2,
  1273. (m->vtotal / 2) + 1);
  1274. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST3_L, 2, 0x0);
  1275. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST4_L, 2, 0x0);
  1276. } else {
  1277. /* Progressive Mode */
  1278. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_2_0, 2,
  1279. m->vsync_end - m->vdisplay);
  1280. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_BEF_1_0, 2,
  1281. m->vsync_start - m->vdisplay);
  1282. hdmi_reg_writev(hdata, HDMI_V2_BLANK_0, 2, m->vtotal);
  1283. hdmi_reg_writev(hdata, HDMI_V1_BLANK_0, 2,
  1284. m->vtotal - m->vdisplay);
  1285. hdmi_reg_writev(hdata, HDMI_V_BLANK_F0_0, 2, 0xffff);
  1286. hdmi_reg_writev(hdata, HDMI_V_BLANK_F1_0, 2, 0xffff);
  1287. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_2_0, 2, 0xffff);
  1288. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_1_0, 2, 0xffff);
  1289. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_2_0, 2, 0xffff);
  1290. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_1_0, 2, 0xffff);
  1291. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST_L, 2,
  1292. m->vtotal - m->vdisplay);
  1293. hdmi_reg_writev(hdata, HDMI_TG_VACT_SZ_L, 2, m->vdisplay);
  1294. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST2_L, 2, 0x248);
  1295. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST3_L, 2, 0x47b);
  1296. hdmi_reg_writev(hdata, HDMI_TG_VACT_ST4_L, 2, 0x6ae);
  1297. hdmi_reg_writev(hdata, HDMI_TG_VSYNC2_L, 2, 0x233);
  1298. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_BOT_HDMI_L, 2, 0x233);
  1299. hdmi_reg_writev(hdata, HDMI_TG_FIELD_BOT_HDMI_L, 2, 0x233);
  1300. }
  1301. /* Following values & calculations are same irrespective of mode type */
  1302. hdmi_reg_writev(hdata, HDMI_H_SYNC_START_0, 2,
  1303. m->hsync_start - m->hdisplay - 2);
  1304. hdmi_reg_writev(hdata, HDMI_H_SYNC_END_0, 2,
  1305. m->hsync_end - m->hdisplay - 2);
  1306. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_1_0, 2, 0xffff);
  1307. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_2_0, 2, 0xffff);
  1308. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_3_0, 2, 0xffff);
  1309. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_4_0, 2, 0xffff);
  1310. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_5_0, 2, 0xffff);
  1311. hdmi_reg_writev(hdata, HDMI_VACT_SPACE_6_0, 2, 0xffff);
  1312. hdmi_reg_writev(hdata, HDMI_V_BLANK_F2_0, 2, 0xffff);
  1313. hdmi_reg_writev(hdata, HDMI_V_BLANK_F3_0, 2, 0xffff);
  1314. hdmi_reg_writev(hdata, HDMI_V_BLANK_F4_0, 2, 0xffff);
  1315. hdmi_reg_writev(hdata, HDMI_V_BLANK_F5_0, 2, 0xffff);
  1316. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_3_0, 2, 0xffff);
  1317. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_4_0, 2, 0xffff);
  1318. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_5_0, 2, 0xffff);
  1319. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_6_0, 2, 0xffff);
  1320. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_3_0, 2, 0xffff);
  1321. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_4_0, 2, 0xffff);
  1322. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_5_0, 2, 0xffff);
  1323. hdmi_reg_writev(hdata, HDMI_V_SYNC_LINE_AFT_PXL_6_0, 2, 0xffff);
  1324. /* Timing generator registers */
  1325. hdmi_reg_writev(hdata, HDMI_TG_H_FSZ_L, 2, m->htotal);
  1326. hdmi_reg_writev(hdata, HDMI_TG_HACT_ST_L, 2, m->htotal - m->hdisplay);
  1327. hdmi_reg_writev(hdata, HDMI_TG_HACT_SZ_L, 2, m->hdisplay);
  1328. hdmi_reg_writev(hdata, HDMI_TG_V_FSZ_L, 2, m->vtotal);
  1329. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_L, 2, 0x1);
  1330. hdmi_reg_writev(hdata, HDMI_TG_FIELD_CHG_L, 2, 0x233);
  1331. hdmi_reg_writev(hdata, HDMI_TG_VSYNC_TOP_HDMI_L, 2, 0x1);
  1332. hdmi_reg_writev(hdata, HDMI_TG_FIELD_TOP_HDMI_L, 2, 0x1);
  1333. hdmi_reg_writev(hdata, HDMI_TG_3D, 1, 0x0);
  1334. }
  1335. static void hdmi_mode_apply(struct hdmi_context *hdata)
  1336. {
  1337. if (hdata->drv_data->type == HDMI_TYPE13)
  1338. hdmi_v13_mode_apply(hdata);
  1339. else
  1340. hdmi_v14_mode_apply(hdata);
  1341. hdmiphy_wait_for_pll(hdata);
  1342. clk_set_parent(hdata->mout_hdmi, hdata->sclk_hdmiphy);
  1343. /* enable HDMI and timing generator */
  1344. hdmi_start(hdata, true);
  1345. }
  1346. static void hdmiphy_conf_reset(struct hdmi_context *hdata)
  1347. {
  1348. clk_set_parent(hdata->mout_hdmi, hdata->sclk_pixel);
  1349. /* reset hdmiphy */
  1350. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, ~0, HDMI_PHY_SW_RSTOUT);
  1351. usleep_range(10000, 12000);
  1352. hdmi_reg_writemask(hdata, HDMI_PHY_RSTOUT, 0, HDMI_PHY_SW_RSTOUT);
  1353. usleep_range(10000, 12000);
  1354. }
  1355. static void hdmiphy_conf_apply(struct hdmi_context *hdata)
  1356. {
  1357. int ret;
  1358. int i;
  1359. /* pixel clock */
  1360. i = hdmi_find_phy_conf(hdata, hdata->current_mode.clock * 1000);
  1361. if (i < 0) {
  1362. DRM_ERROR("failed to find hdmiphy conf\n");
  1363. return;
  1364. }
  1365. ret = hdmiphy_reg_write_buf(hdata, 0,
  1366. hdata->drv_data->phy_confs[i].conf, 32);
  1367. if (ret) {
  1368. DRM_ERROR("failed to configure hdmiphy\n");
  1369. return;
  1370. }
  1371. usleep_range(10000, 12000);
  1372. }
  1373. static void hdmi_conf_apply(struct hdmi_context *hdata)
  1374. {
  1375. hdmiphy_conf_reset(hdata);
  1376. hdmiphy_conf_apply(hdata);
  1377. hdmi_start(hdata, false);
  1378. hdmi_conf_init(hdata);
  1379. hdmi_audio_init(hdata);
  1380. /* setting core registers */
  1381. hdmi_mode_apply(hdata);
  1382. hdmi_audio_control(hdata, true);
  1383. hdmi_regs_dump(hdata, "start");
  1384. }
  1385. static void hdmi_mode_set(struct drm_encoder *encoder,
  1386. struct drm_display_mode *mode,
  1387. struct drm_display_mode *adjusted_mode)
  1388. {
  1389. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1390. struct drm_display_mode *m = adjusted_mode;
  1391. DRM_DEBUG_KMS("xres=%d, yres=%d, refresh=%d, intl=%s\n",
  1392. m->hdisplay, m->vdisplay,
  1393. m->vrefresh, (m->flags & DRM_MODE_FLAG_INTERLACE) ?
  1394. "INTERLACED" : "PROGRESSIVE");
  1395. drm_mode_copy(&hdata->current_mode, m);
  1396. hdata->cea_video_id = drm_match_cea_mode(mode);
  1397. }
  1398. static void hdmi_enable(struct drm_encoder *encoder)
  1399. {
  1400. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1401. if (hdata->powered)
  1402. return;
  1403. pm_runtime_get_sync(hdata->dev);
  1404. if (regulator_bulk_enable(ARRAY_SIZE(supply), hdata->regul_bulk))
  1405. DRM_DEBUG_KMS("failed to enable regulator bulk\n");
  1406. /* set pmu hdmiphy control bit to enable hdmiphy */
  1407. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1408. PMU_HDMI_PHY_ENABLE_BIT, 1);
  1409. hdmi_conf_apply(hdata);
  1410. hdata->powered = true;
  1411. }
  1412. static void hdmi_disable(struct drm_encoder *encoder)
  1413. {
  1414. struct hdmi_context *hdata = encoder_to_hdmi(encoder);
  1415. struct drm_crtc *crtc = encoder->crtc;
  1416. const struct drm_crtc_helper_funcs *funcs = NULL;
  1417. if (!hdata->powered)
  1418. return;
  1419. /*
  1420. * The SFRs of VP and Mixer are updated by Vertical Sync of
  1421. * Timing generator which is a part of HDMI so the sequence
  1422. * to disable TV Subsystem should be as following,
  1423. * VP -> Mixer -> HDMI
  1424. *
  1425. * Below codes will try to disable Mixer and VP(if used)
  1426. * prior to disabling HDMI.
  1427. */
  1428. if (crtc)
  1429. funcs = crtc->helper_private;
  1430. if (funcs && funcs->disable)
  1431. (*funcs->disable)(crtc);
  1432. /* HDMI System Disable */
  1433. hdmi_reg_writemask(hdata, HDMI_CON_0, 0, HDMI_EN);
  1434. cancel_delayed_work(&hdata->hotplug_work);
  1435. /* reset pmu hdmiphy control bit to disable hdmiphy */
  1436. regmap_update_bits(hdata->pmureg, PMU_HDMI_PHY_CONTROL,
  1437. PMU_HDMI_PHY_ENABLE_BIT, 0);
  1438. regulator_bulk_disable(ARRAY_SIZE(supply), hdata->regul_bulk);
  1439. pm_runtime_put_sync(hdata->dev);
  1440. hdata->powered = false;
  1441. }
  1442. static const struct drm_encoder_helper_funcs exynos_hdmi_encoder_helper_funcs = {
  1443. .mode_fixup = hdmi_mode_fixup,
  1444. .mode_set = hdmi_mode_set,
  1445. .enable = hdmi_enable,
  1446. .disable = hdmi_disable,
  1447. };
  1448. static const struct drm_encoder_funcs exynos_hdmi_encoder_funcs = {
  1449. .destroy = drm_encoder_cleanup,
  1450. };
  1451. static void hdmi_hotplug_work_func(struct work_struct *work)
  1452. {
  1453. struct hdmi_context *hdata;
  1454. hdata = container_of(work, struct hdmi_context, hotplug_work.work);
  1455. if (hdata->drm_dev)
  1456. drm_helper_hpd_irq_event(hdata->drm_dev);
  1457. }
  1458. static irqreturn_t hdmi_irq_thread(int irq, void *arg)
  1459. {
  1460. struct hdmi_context *hdata = arg;
  1461. mod_delayed_work(system_wq, &hdata->hotplug_work,
  1462. msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
  1463. return IRQ_HANDLED;
  1464. }
  1465. static int hdmi_resources_init(struct hdmi_context *hdata)
  1466. {
  1467. struct device *dev = hdata->dev;
  1468. int i, ret;
  1469. DRM_DEBUG_KMS("HDMI resource init\n");
  1470. hdata->hpd_gpio = devm_gpiod_get(dev, "hpd", GPIOD_IN);
  1471. if (IS_ERR(hdata->hpd_gpio)) {
  1472. DRM_ERROR("cannot get hpd gpio property\n");
  1473. return PTR_ERR(hdata->hpd_gpio);
  1474. }
  1475. hdata->irq = gpiod_to_irq(hdata->hpd_gpio);
  1476. if (hdata->irq < 0) {
  1477. DRM_ERROR("failed to get GPIO irq\n");
  1478. return hdata->irq;
  1479. }
  1480. /* get clocks, power */
  1481. hdata->hdmi = devm_clk_get(dev, "hdmi");
  1482. if (IS_ERR(hdata->hdmi)) {
  1483. DRM_ERROR("failed to get clock 'hdmi'\n");
  1484. ret = PTR_ERR(hdata->hdmi);
  1485. goto fail;
  1486. }
  1487. hdata->sclk_hdmi = devm_clk_get(dev, "sclk_hdmi");
  1488. if (IS_ERR(hdata->sclk_hdmi)) {
  1489. DRM_ERROR("failed to get clock 'sclk_hdmi'\n");
  1490. ret = PTR_ERR(hdata->sclk_hdmi);
  1491. goto fail;
  1492. }
  1493. hdata->sclk_pixel = devm_clk_get(dev, "sclk_pixel");
  1494. if (IS_ERR(hdata->sclk_pixel)) {
  1495. DRM_ERROR("failed to get clock 'sclk_pixel'\n");
  1496. ret = PTR_ERR(hdata->sclk_pixel);
  1497. goto fail;
  1498. }
  1499. hdata->sclk_hdmiphy = devm_clk_get(dev, "sclk_hdmiphy");
  1500. if (IS_ERR(hdata->sclk_hdmiphy)) {
  1501. DRM_ERROR("failed to get clock 'sclk_hdmiphy'\n");
  1502. ret = PTR_ERR(hdata->sclk_hdmiphy);
  1503. goto fail;
  1504. }
  1505. hdata->mout_hdmi = devm_clk_get(dev, "mout_hdmi");
  1506. if (IS_ERR(hdata->mout_hdmi)) {
  1507. DRM_ERROR("failed to get clock 'mout_hdmi'\n");
  1508. ret = PTR_ERR(hdata->mout_hdmi);
  1509. goto fail;
  1510. }
  1511. clk_set_parent(hdata->mout_hdmi, hdata->sclk_pixel);
  1512. for (i = 0; i < ARRAY_SIZE(supply); ++i) {
  1513. hdata->regul_bulk[i].supply = supply[i];
  1514. hdata->regul_bulk[i].consumer = NULL;
  1515. }
  1516. ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(supply), hdata->regul_bulk);
  1517. if (ret) {
  1518. DRM_ERROR("failed to get regulators\n");
  1519. return ret;
  1520. }
  1521. hdata->reg_hdmi_en = devm_regulator_get_optional(dev, "hdmi-en");
  1522. if (PTR_ERR(hdata->reg_hdmi_en) == -ENODEV)
  1523. return 0;
  1524. if (IS_ERR(hdata->reg_hdmi_en))
  1525. return PTR_ERR(hdata->reg_hdmi_en);
  1526. ret = regulator_enable(hdata->reg_hdmi_en);
  1527. if (ret)
  1528. DRM_ERROR("failed to enable hdmi-en regulator\n");
  1529. return ret;
  1530. fail:
  1531. DRM_ERROR("HDMI resource init - failed\n");
  1532. return ret;
  1533. }
  1534. static struct of_device_id hdmi_match_types[] = {
  1535. {
  1536. .compatible = "samsung,exynos4210-hdmi",
  1537. .data = &exynos4210_hdmi_driver_data,
  1538. }, {
  1539. .compatible = "samsung,exynos4212-hdmi",
  1540. .data = &exynos4212_hdmi_driver_data,
  1541. }, {
  1542. .compatible = "samsung,exynos5420-hdmi",
  1543. .data = &exynos5420_hdmi_driver_data,
  1544. }, {
  1545. /* end node */
  1546. }
  1547. };
  1548. MODULE_DEVICE_TABLE (of, hdmi_match_types);
  1549. static int hdmi_bind(struct device *dev, struct device *master, void *data)
  1550. {
  1551. struct drm_device *drm_dev = data;
  1552. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1553. struct drm_encoder *encoder = &hdata->encoder;
  1554. int ret, pipe;
  1555. hdata->drm_dev = drm_dev;
  1556. pipe = exynos_drm_crtc_get_pipe_from_type(drm_dev,
  1557. EXYNOS_DISPLAY_TYPE_HDMI);
  1558. if (pipe < 0)
  1559. return pipe;
  1560. encoder->possible_crtcs = 1 << pipe;
  1561. DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs);
  1562. drm_encoder_init(drm_dev, encoder, &exynos_hdmi_encoder_funcs,
  1563. DRM_MODE_ENCODER_TMDS, NULL);
  1564. drm_encoder_helper_add(encoder, &exynos_hdmi_encoder_helper_funcs);
  1565. ret = hdmi_create_connector(encoder);
  1566. if (ret) {
  1567. DRM_ERROR("failed to create connector ret = %d\n", ret);
  1568. drm_encoder_cleanup(encoder);
  1569. return ret;
  1570. }
  1571. return 0;
  1572. }
  1573. static void hdmi_unbind(struct device *dev, struct device *master, void *data)
  1574. {
  1575. }
  1576. static const struct component_ops hdmi_component_ops = {
  1577. .bind = hdmi_bind,
  1578. .unbind = hdmi_unbind,
  1579. };
  1580. static struct device_node *hdmi_legacy_ddc_dt_binding(struct device *dev)
  1581. {
  1582. const char *compatible_str = "samsung,exynos4210-hdmiddc";
  1583. struct device_node *np;
  1584. np = of_find_compatible_node(NULL, NULL, compatible_str);
  1585. if (np)
  1586. return of_get_next_parent(np);
  1587. return NULL;
  1588. }
  1589. static struct device_node *hdmi_legacy_phy_dt_binding(struct device *dev)
  1590. {
  1591. const char *compatible_str = "samsung,exynos4212-hdmiphy";
  1592. return of_find_compatible_node(NULL, NULL, compatible_str);
  1593. }
  1594. static int hdmi_probe(struct platform_device *pdev)
  1595. {
  1596. struct device_node *ddc_node, *phy_node;
  1597. const struct of_device_id *match;
  1598. struct device *dev = &pdev->dev;
  1599. struct hdmi_context *hdata;
  1600. struct resource *res;
  1601. int ret;
  1602. hdata = devm_kzalloc(dev, sizeof(struct hdmi_context), GFP_KERNEL);
  1603. if (!hdata)
  1604. return -ENOMEM;
  1605. match = of_match_device(hdmi_match_types, dev);
  1606. if (!match)
  1607. return -ENODEV;
  1608. hdata->drv_data = match->data;
  1609. platform_set_drvdata(pdev, hdata);
  1610. hdata->dev = dev;
  1611. ret = hdmi_resources_init(hdata);
  1612. if (ret) {
  1613. DRM_ERROR("hdmi_resources_init failed\n");
  1614. return ret;
  1615. }
  1616. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1617. hdata->regs = devm_ioremap_resource(dev, res);
  1618. if (IS_ERR(hdata->regs)) {
  1619. ret = PTR_ERR(hdata->regs);
  1620. return ret;
  1621. }
  1622. ddc_node = hdmi_legacy_ddc_dt_binding(dev);
  1623. if (ddc_node)
  1624. goto out_get_ddc_adpt;
  1625. /* DDC i2c driver */
  1626. ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
  1627. if (!ddc_node) {
  1628. DRM_ERROR("Failed to find ddc node in device tree\n");
  1629. return -ENODEV;
  1630. }
  1631. out_get_ddc_adpt:
  1632. hdata->ddc_adpt = of_find_i2c_adapter_by_node(ddc_node);
  1633. if (!hdata->ddc_adpt) {
  1634. DRM_ERROR("Failed to get ddc i2c adapter by node\n");
  1635. return -EPROBE_DEFER;
  1636. }
  1637. phy_node = hdmi_legacy_phy_dt_binding(dev);
  1638. if (phy_node)
  1639. goto out_get_phy_port;
  1640. /* hdmiphy i2c driver */
  1641. phy_node = of_parse_phandle(dev->of_node, "phy", 0);
  1642. if (!phy_node) {
  1643. DRM_ERROR("Failed to find hdmiphy node in device tree\n");
  1644. ret = -ENODEV;
  1645. goto err_ddc;
  1646. }
  1647. out_get_phy_port:
  1648. if (hdata->drv_data->is_apb_phy) {
  1649. hdata->regs_hdmiphy = of_iomap(phy_node, 0);
  1650. if (!hdata->regs_hdmiphy) {
  1651. DRM_ERROR("failed to ioremap hdmi phy\n");
  1652. ret = -ENOMEM;
  1653. goto err_ddc;
  1654. }
  1655. } else {
  1656. hdata->hdmiphy_port = of_find_i2c_device_by_node(phy_node);
  1657. if (!hdata->hdmiphy_port) {
  1658. DRM_ERROR("Failed to get hdmi phy i2c client\n");
  1659. ret = -EPROBE_DEFER;
  1660. goto err_ddc;
  1661. }
  1662. }
  1663. INIT_DELAYED_WORK(&hdata->hotplug_work, hdmi_hotplug_work_func);
  1664. ret = devm_request_threaded_irq(dev, hdata->irq, NULL,
  1665. hdmi_irq_thread, IRQF_TRIGGER_RISING |
  1666. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  1667. "hdmi", hdata);
  1668. if (ret) {
  1669. DRM_ERROR("failed to register hdmi interrupt\n");
  1670. goto err_hdmiphy;
  1671. }
  1672. hdata->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  1673. "samsung,syscon-phandle");
  1674. if (IS_ERR(hdata->pmureg)) {
  1675. DRM_ERROR("syscon regmap lookup failed.\n");
  1676. ret = -EPROBE_DEFER;
  1677. goto err_hdmiphy;
  1678. }
  1679. pm_runtime_enable(dev);
  1680. ret = component_add(&pdev->dev, &hdmi_component_ops);
  1681. if (ret)
  1682. goto err_disable_pm_runtime;
  1683. return ret;
  1684. err_disable_pm_runtime:
  1685. pm_runtime_disable(dev);
  1686. err_hdmiphy:
  1687. if (hdata->hdmiphy_port)
  1688. put_device(&hdata->hdmiphy_port->dev);
  1689. err_ddc:
  1690. put_device(&hdata->ddc_adpt->dev);
  1691. return ret;
  1692. }
  1693. static int hdmi_remove(struct platform_device *pdev)
  1694. {
  1695. struct hdmi_context *hdata = platform_get_drvdata(pdev);
  1696. cancel_delayed_work_sync(&hdata->hotplug_work);
  1697. component_del(&pdev->dev, &hdmi_component_ops);
  1698. pm_runtime_disable(&pdev->dev);
  1699. if (!IS_ERR(hdata->reg_hdmi_en))
  1700. regulator_disable(hdata->reg_hdmi_en);
  1701. if (hdata->hdmiphy_port)
  1702. put_device(&hdata->hdmiphy_port->dev);
  1703. put_device(&hdata->ddc_adpt->dev);
  1704. return 0;
  1705. }
  1706. #ifdef CONFIG_PM
  1707. static int exynos_hdmi_suspend(struct device *dev)
  1708. {
  1709. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1710. clk_disable_unprepare(hdata->sclk_hdmi);
  1711. clk_disable_unprepare(hdata->hdmi);
  1712. return 0;
  1713. }
  1714. static int exynos_hdmi_resume(struct device *dev)
  1715. {
  1716. struct hdmi_context *hdata = dev_get_drvdata(dev);
  1717. int ret;
  1718. ret = clk_prepare_enable(hdata->hdmi);
  1719. if (ret < 0) {
  1720. DRM_ERROR("Failed to prepare_enable the hdmi clk [%d]\n", ret);
  1721. return ret;
  1722. }
  1723. ret = clk_prepare_enable(hdata->sclk_hdmi);
  1724. if (ret < 0) {
  1725. DRM_ERROR("Failed to prepare_enable the sclk_mixer clk [%d]\n",
  1726. ret);
  1727. return ret;
  1728. }
  1729. return 0;
  1730. }
  1731. #endif
  1732. static const struct dev_pm_ops exynos_hdmi_pm_ops = {
  1733. SET_RUNTIME_PM_OPS(exynos_hdmi_suspend, exynos_hdmi_resume, NULL)
  1734. };
  1735. struct platform_driver hdmi_driver = {
  1736. .probe = hdmi_probe,
  1737. .remove = hdmi_remove,
  1738. .driver = {
  1739. .name = "exynos-hdmi",
  1740. .owner = THIS_MODULE,
  1741. .pm = &exynos_hdmi_pm_ops,
  1742. .of_match_table = hdmi_match_types,
  1743. },
  1744. };