exynos_hdmi.c 52 KB

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