exynos_hdmi.c 53 KB

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