dw-hdmi.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537
  1. /*
  2. * DesignWare High-Definition Multimedia Interface (HDMI) driver
  3. *
  4. * Copyright (C) 2013-2015 Mentor Graphics Inc.
  5. * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
  6. * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/irq.h>
  16. #include <linux/delay.h>
  17. #include <linux/err.h>
  18. #include <linux/clk.h>
  19. #include <linux/hdmi.h>
  20. #include <linux/mutex.h>
  21. #include <linux/of_device.h>
  22. #include <linux/regmap.h>
  23. #include <linux/spinlock.h>
  24. #include <drm/drm_of.h>
  25. #include <drm/drmP.h>
  26. #include <drm/drm_atomic_helper.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include <drm/drm_edid.h>
  29. #include <drm/drm_encoder_slave.h>
  30. #include <drm/bridge/dw_hdmi.h>
  31. #include <uapi/linux/media-bus-format.h>
  32. #include <uapi/linux/videodev2.h>
  33. #include "dw-hdmi.h"
  34. #include "dw-hdmi-audio.h"
  35. #define DDC_SEGMENT_ADDR 0x30
  36. #define HDMI_EDID_LEN 512
  37. enum hdmi_datamap {
  38. RGB444_8B = 0x01,
  39. RGB444_10B = 0x03,
  40. RGB444_12B = 0x05,
  41. RGB444_16B = 0x07,
  42. YCbCr444_8B = 0x09,
  43. YCbCr444_10B = 0x0B,
  44. YCbCr444_12B = 0x0D,
  45. YCbCr444_16B = 0x0F,
  46. YCbCr422_8B = 0x16,
  47. YCbCr422_10B = 0x14,
  48. YCbCr422_12B = 0x12,
  49. };
  50. static const u16 csc_coeff_default[3][4] = {
  51. { 0x2000, 0x0000, 0x0000, 0x0000 },
  52. { 0x0000, 0x2000, 0x0000, 0x0000 },
  53. { 0x0000, 0x0000, 0x2000, 0x0000 }
  54. };
  55. static const u16 csc_coeff_rgb_out_eitu601[3][4] = {
  56. { 0x2000, 0x6926, 0x74fd, 0x010e },
  57. { 0x2000, 0x2cdd, 0x0000, 0x7e9a },
  58. { 0x2000, 0x0000, 0x38b4, 0x7e3b }
  59. };
  60. static const u16 csc_coeff_rgb_out_eitu709[3][4] = {
  61. { 0x2000, 0x7106, 0x7a02, 0x00a7 },
  62. { 0x2000, 0x3264, 0x0000, 0x7e6d },
  63. { 0x2000, 0x0000, 0x3b61, 0x7e25 }
  64. };
  65. static const u16 csc_coeff_rgb_in_eitu601[3][4] = {
  66. { 0x2591, 0x1322, 0x074b, 0x0000 },
  67. { 0x6535, 0x2000, 0x7acc, 0x0200 },
  68. { 0x6acd, 0x7534, 0x2000, 0x0200 }
  69. };
  70. static const u16 csc_coeff_rgb_in_eitu709[3][4] = {
  71. { 0x2dc5, 0x0d9b, 0x049e, 0x0000 },
  72. { 0x62f0, 0x2000, 0x7d11, 0x0200 },
  73. { 0x6756, 0x78ab, 0x2000, 0x0200 }
  74. };
  75. struct hdmi_vmode {
  76. bool mdataenablepolarity;
  77. unsigned int mpixelclock;
  78. unsigned int mpixelrepetitioninput;
  79. unsigned int mpixelrepetitionoutput;
  80. };
  81. struct hdmi_data_info {
  82. unsigned int enc_in_bus_format;
  83. unsigned int enc_out_bus_format;
  84. unsigned int enc_in_encoding;
  85. unsigned int enc_out_encoding;
  86. unsigned int pix_repet_factor;
  87. unsigned int hdcp_enable;
  88. struct hdmi_vmode video_mode;
  89. };
  90. struct dw_hdmi_i2c {
  91. struct i2c_adapter adap;
  92. struct mutex lock; /* used to serialize data transfers */
  93. struct completion cmp;
  94. u8 stat;
  95. u8 slave_reg;
  96. bool is_regaddr;
  97. bool is_segment;
  98. };
  99. struct dw_hdmi_phy_data {
  100. enum dw_hdmi_phy_type type;
  101. const char *name;
  102. unsigned int gen;
  103. bool has_svsret;
  104. int (*configure)(struct dw_hdmi *hdmi,
  105. const struct dw_hdmi_plat_data *pdata,
  106. unsigned long mpixelclock);
  107. };
  108. struct dw_hdmi {
  109. struct drm_connector connector;
  110. struct drm_bridge bridge;
  111. unsigned int version;
  112. struct platform_device *audio;
  113. struct device *dev;
  114. struct clk *isfr_clk;
  115. struct clk *iahb_clk;
  116. struct dw_hdmi_i2c *i2c;
  117. struct hdmi_data_info hdmi_data;
  118. const struct dw_hdmi_plat_data *plat_data;
  119. int vic;
  120. u8 edid[HDMI_EDID_LEN];
  121. bool cable_plugin;
  122. struct {
  123. const struct dw_hdmi_phy_ops *ops;
  124. const char *name;
  125. void *data;
  126. bool enabled;
  127. } phy;
  128. struct drm_display_mode previous_mode;
  129. struct i2c_adapter *ddc;
  130. void __iomem *regs;
  131. bool sink_is_hdmi;
  132. bool sink_has_audio;
  133. struct mutex mutex; /* for state below and previous_mode */
  134. enum drm_connector_force force; /* mutex-protected force state */
  135. bool disabled; /* DRM has disabled our bridge */
  136. bool bridge_is_on; /* indicates the bridge is on */
  137. bool rxsense; /* rxsense state */
  138. u8 phy_mask; /* desired phy int mask settings */
  139. spinlock_t audio_lock;
  140. struct mutex audio_mutex;
  141. unsigned int sample_rate;
  142. unsigned int audio_cts;
  143. unsigned int audio_n;
  144. bool audio_enable;
  145. unsigned int reg_shift;
  146. struct regmap *regm;
  147. };
  148. #define HDMI_IH_PHY_STAT0_RX_SENSE \
  149. (HDMI_IH_PHY_STAT0_RX_SENSE0 | HDMI_IH_PHY_STAT0_RX_SENSE1 | \
  150. HDMI_IH_PHY_STAT0_RX_SENSE2 | HDMI_IH_PHY_STAT0_RX_SENSE3)
  151. #define HDMI_PHY_RX_SENSE \
  152. (HDMI_PHY_RX_SENSE0 | HDMI_PHY_RX_SENSE1 | \
  153. HDMI_PHY_RX_SENSE2 | HDMI_PHY_RX_SENSE3)
  154. static inline void hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset)
  155. {
  156. regmap_write(hdmi->regm, offset << hdmi->reg_shift, val);
  157. }
  158. static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset)
  159. {
  160. unsigned int val = 0;
  161. regmap_read(hdmi->regm, offset << hdmi->reg_shift, &val);
  162. return val;
  163. }
  164. static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg)
  165. {
  166. regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data);
  167. }
  168. static void hdmi_mask_writeb(struct dw_hdmi *hdmi, u8 data, unsigned int reg,
  169. u8 shift, u8 mask)
  170. {
  171. hdmi_modb(hdmi, data << shift, mask, reg);
  172. }
  173. static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi)
  174. {
  175. /* Software reset */
  176. hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ);
  177. /* Set Standard Mode speed (determined to be 100KHz on iMX6) */
  178. hdmi_writeb(hdmi, 0x00, HDMI_I2CM_DIV);
  179. /* Set done, not acknowledged and arbitration interrupt polarities */
  180. hdmi_writeb(hdmi, HDMI_I2CM_INT_DONE_POL, HDMI_I2CM_INT);
  181. hdmi_writeb(hdmi, HDMI_I2CM_CTLINT_NAC_POL | HDMI_I2CM_CTLINT_ARB_POL,
  182. HDMI_I2CM_CTLINT);
  183. /* Clear DONE and ERROR interrupts */
  184. hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE,
  185. HDMI_IH_I2CM_STAT0);
  186. /* Mute DONE and ERROR interrupts */
  187. hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE,
  188. HDMI_IH_MUTE_I2CM_STAT0);
  189. }
  190. static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi,
  191. unsigned char *buf, unsigned int length)
  192. {
  193. struct dw_hdmi_i2c *i2c = hdmi->i2c;
  194. int stat;
  195. if (!i2c->is_regaddr) {
  196. dev_dbg(hdmi->dev, "set read register address to 0\n");
  197. i2c->slave_reg = 0x00;
  198. i2c->is_regaddr = true;
  199. }
  200. while (length--) {
  201. reinit_completion(&i2c->cmp);
  202. hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS);
  203. if (i2c->is_segment)
  204. hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT,
  205. HDMI_I2CM_OPERATION);
  206. else
  207. hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ,
  208. HDMI_I2CM_OPERATION);
  209. stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10);
  210. if (!stat)
  211. return -EAGAIN;
  212. /* Check for error condition on the bus */
  213. if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR)
  214. return -EIO;
  215. *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI);
  216. }
  217. i2c->is_segment = false;
  218. return 0;
  219. }
  220. static int dw_hdmi_i2c_write(struct dw_hdmi *hdmi,
  221. unsigned char *buf, unsigned int length)
  222. {
  223. struct dw_hdmi_i2c *i2c = hdmi->i2c;
  224. int stat;
  225. if (!i2c->is_regaddr) {
  226. /* Use the first write byte as register address */
  227. i2c->slave_reg = buf[0];
  228. length--;
  229. buf++;
  230. i2c->is_regaddr = true;
  231. }
  232. while (length--) {
  233. reinit_completion(&i2c->cmp);
  234. hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO);
  235. hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS);
  236. hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE,
  237. HDMI_I2CM_OPERATION);
  238. stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10);
  239. if (!stat)
  240. return -EAGAIN;
  241. /* Check for error condition on the bus */
  242. if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR)
  243. return -EIO;
  244. }
  245. return 0;
  246. }
  247. static int dw_hdmi_i2c_xfer(struct i2c_adapter *adap,
  248. struct i2c_msg *msgs, int num)
  249. {
  250. struct dw_hdmi *hdmi = i2c_get_adapdata(adap);
  251. struct dw_hdmi_i2c *i2c = hdmi->i2c;
  252. u8 addr = msgs[0].addr;
  253. int i, ret = 0;
  254. dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr);
  255. for (i = 0; i < num; i++) {
  256. if (msgs[i].len == 0) {
  257. dev_dbg(hdmi->dev,
  258. "unsupported transfer %d/%d, no data\n",
  259. i + 1, num);
  260. return -EOPNOTSUPP;
  261. }
  262. }
  263. mutex_lock(&i2c->lock);
  264. /* Unmute DONE and ERROR interrupts */
  265. hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0);
  266. /* Set slave device address taken from the first I2C message */
  267. hdmi_writeb(hdmi, addr, HDMI_I2CM_SLAVE);
  268. /* Set slave device register address on transfer */
  269. i2c->is_regaddr = false;
  270. /* Set segment pointer for I2C extended read mode operation */
  271. i2c->is_segment = false;
  272. for (i = 0; i < num; i++) {
  273. dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n",
  274. i + 1, num, msgs[i].len, msgs[i].flags);
  275. if (msgs[i].addr == DDC_SEGMENT_ADDR && msgs[i].len == 1) {
  276. i2c->is_segment = true;
  277. hdmi_writeb(hdmi, DDC_SEGMENT_ADDR, HDMI_I2CM_SEGADDR);
  278. hdmi_writeb(hdmi, *msgs[i].buf, HDMI_I2CM_SEGPTR);
  279. } else {
  280. if (msgs[i].flags & I2C_M_RD)
  281. ret = dw_hdmi_i2c_read(hdmi, msgs[i].buf,
  282. msgs[i].len);
  283. else
  284. ret = dw_hdmi_i2c_write(hdmi, msgs[i].buf,
  285. msgs[i].len);
  286. }
  287. if (ret < 0)
  288. break;
  289. }
  290. if (!ret)
  291. ret = num;
  292. /* Mute DONE and ERROR interrupts */
  293. hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE,
  294. HDMI_IH_MUTE_I2CM_STAT0);
  295. mutex_unlock(&i2c->lock);
  296. return ret;
  297. }
  298. static u32 dw_hdmi_i2c_func(struct i2c_adapter *adapter)
  299. {
  300. return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
  301. }
  302. static const struct i2c_algorithm dw_hdmi_algorithm = {
  303. .master_xfer = dw_hdmi_i2c_xfer,
  304. .functionality = dw_hdmi_i2c_func,
  305. };
  306. static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi)
  307. {
  308. struct i2c_adapter *adap;
  309. struct dw_hdmi_i2c *i2c;
  310. int ret;
  311. i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL);
  312. if (!i2c)
  313. return ERR_PTR(-ENOMEM);
  314. mutex_init(&i2c->lock);
  315. init_completion(&i2c->cmp);
  316. adap = &i2c->adap;
  317. adap->class = I2C_CLASS_DDC;
  318. adap->owner = THIS_MODULE;
  319. adap->dev.parent = hdmi->dev;
  320. adap->algo = &dw_hdmi_algorithm;
  321. strlcpy(adap->name, "DesignWare HDMI", sizeof(adap->name));
  322. i2c_set_adapdata(adap, hdmi);
  323. ret = i2c_add_adapter(adap);
  324. if (ret) {
  325. dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name);
  326. devm_kfree(hdmi->dev, i2c);
  327. return ERR_PTR(ret);
  328. }
  329. hdmi->i2c = i2c;
  330. dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name);
  331. return adap;
  332. }
  333. static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts,
  334. unsigned int n)
  335. {
  336. /* Must be set/cleared first */
  337. hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3);
  338. /* nshift factor = 0 */
  339. hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3);
  340. hdmi_writeb(hdmi, ((cts >> 16) & HDMI_AUD_CTS3_AUDCTS19_16_MASK) |
  341. HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3);
  342. hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2);
  343. hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1);
  344. hdmi_writeb(hdmi, (n >> 16) & 0x0f, HDMI_AUD_N3);
  345. hdmi_writeb(hdmi, (n >> 8) & 0xff, HDMI_AUD_N2);
  346. hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1);
  347. }
  348. static unsigned int hdmi_compute_n(unsigned int freq, unsigned long pixel_clk)
  349. {
  350. unsigned int n = (128 * freq) / 1000;
  351. unsigned int mult = 1;
  352. while (freq > 48000) {
  353. mult *= 2;
  354. freq /= 2;
  355. }
  356. switch (freq) {
  357. case 32000:
  358. if (pixel_clk == 25175000)
  359. n = 4576;
  360. else if (pixel_clk == 27027000)
  361. n = 4096;
  362. else if (pixel_clk == 74176000 || pixel_clk == 148352000)
  363. n = 11648;
  364. else
  365. n = 4096;
  366. n *= mult;
  367. break;
  368. case 44100:
  369. if (pixel_clk == 25175000)
  370. n = 7007;
  371. else if (pixel_clk == 74176000)
  372. n = 17836;
  373. else if (pixel_clk == 148352000)
  374. n = 8918;
  375. else
  376. n = 6272;
  377. n *= mult;
  378. break;
  379. case 48000:
  380. if (pixel_clk == 25175000)
  381. n = 6864;
  382. else if (pixel_clk == 27027000)
  383. n = 6144;
  384. else if (pixel_clk == 74176000)
  385. n = 11648;
  386. else if (pixel_clk == 148352000)
  387. n = 5824;
  388. else
  389. n = 6144;
  390. n *= mult;
  391. break;
  392. default:
  393. break;
  394. }
  395. return n;
  396. }
  397. static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi,
  398. unsigned long pixel_clk, unsigned int sample_rate)
  399. {
  400. unsigned long ftdms = pixel_clk;
  401. unsigned int n, cts;
  402. u64 tmp;
  403. n = hdmi_compute_n(sample_rate, pixel_clk);
  404. /*
  405. * Compute the CTS value from the N value. Note that CTS and N
  406. * can be up to 20 bits in total, so we need 64-bit math. Also
  407. * note that our TDMS clock is not fully accurate; it is accurate
  408. * to kHz. This can introduce an unnecessary remainder in the
  409. * calculation below, so we don't try to warn about that.
  410. */
  411. tmp = (u64)ftdms * n;
  412. do_div(tmp, 128 * sample_rate);
  413. cts = tmp;
  414. dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n",
  415. __func__, sample_rate, ftdms / 1000000, (ftdms / 1000) % 1000,
  416. n, cts);
  417. spin_lock_irq(&hdmi->audio_lock);
  418. hdmi->audio_n = n;
  419. hdmi->audio_cts = cts;
  420. hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0);
  421. spin_unlock_irq(&hdmi->audio_lock);
  422. }
  423. static void hdmi_init_clk_regenerator(struct dw_hdmi *hdmi)
  424. {
  425. mutex_lock(&hdmi->audio_mutex);
  426. hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate);
  427. mutex_unlock(&hdmi->audio_mutex);
  428. }
  429. static void hdmi_clk_regenerator_update_pixel_clock(struct dw_hdmi *hdmi)
  430. {
  431. mutex_lock(&hdmi->audio_mutex);
  432. hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mpixelclock,
  433. hdmi->sample_rate);
  434. mutex_unlock(&hdmi->audio_mutex);
  435. }
  436. void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate)
  437. {
  438. mutex_lock(&hdmi->audio_mutex);
  439. hdmi->sample_rate = rate;
  440. hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mpixelclock,
  441. hdmi->sample_rate);
  442. mutex_unlock(&hdmi->audio_mutex);
  443. }
  444. EXPORT_SYMBOL_GPL(dw_hdmi_set_sample_rate);
  445. void dw_hdmi_audio_enable(struct dw_hdmi *hdmi)
  446. {
  447. unsigned long flags;
  448. spin_lock_irqsave(&hdmi->audio_lock, flags);
  449. hdmi->audio_enable = true;
  450. hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n);
  451. spin_unlock_irqrestore(&hdmi->audio_lock, flags);
  452. }
  453. EXPORT_SYMBOL_GPL(dw_hdmi_audio_enable);
  454. void dw_hdmi_audio_disable(struct dw_hdmi *hdmi)
  455. {
  456. unsigned long flags;
  457. spin_lock_irqsave(&hdmi->audio_lock, flags);
  458. hdmi->audio_enable = false;
  459. hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0);
  460. spin_unlock_irqrestore(&hdmi->audio_lock, flags);
  461. }
  462. EXPORT_SYMBOL_GPL(dw_hdmi_audio_disable);
  463. static bool hdmi_bus_fmt_is_rgb(unsigned int bus_format)
  464. {
  465. switch (bus_format) {
  466. case MEDIA_BUS_FMT_RGB888_1X24:
  467. case MEDIA_BUS_FMT_RGB101010_1X30:
  468. case MEDIA_BUS_FMT_RGB121212_1X36:
  469. case MEDIA_BUS_FMT_RGB161616_1X48:
  470. return true;
  471. default:
  472. return false;
  473. }
  474. }
  475. static bool hdmi_bus_fmt_is_yuv444(unsigned int bus_format)
  476. {
  477. switch (bus_format) {
  478. case MEDIA_BUS_FMT_YUV8_1X24:
  479. case MEDIA_BUS_FMT_YUV10_1X30:
  480. case MEDIA_BUS_FMT_YUV12_1X36:
  481. case MEDIA_BUS_FMT_YUV16_1X48:
  482. return true;
  483. default:
  484. return false;
  485. }
  486. }
  487. static bool hdmi_bus_fmt_is_yuv422(unsigned int bus_format)
  488. {
  489. switch (bus_format) {
  490. case MEDIA_BUS_FMT_UYVY8_1X16:
  491. case MEDIA_BUS_FMT_UYVY10_1X20:
  492. case MEDIA_BUS_FMT_UYVY12_1X24:
  493. return true;
  494. default:
  495. return false;
  496. }
  497. }
  498. static int hdmi_bus_fmt_color_depth(unsigned int bus_format)
  499. {
  500. switch (bus_format) {
  501. case MEDIA_BUS_FMT_RGB888_1X24:
  502. case MEDIA_BUS_FMT_YUV8_1X24:
  503. case MEDIA_BUS_FMT_UYVY8_1X16:
  504. case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
  505. return 8;
  506. case MEDIA_BUS_FMT_RGB101010_1X30:
  507. case MEDIA_BUS_FMT_YUV10_1X30:
  508. case MEDIA_BUS_FMT_UYVY10_1X20:
  509. case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
  510. return 10;
  511. case MEDIA_BUS_FMT_RGB121212_1X36:
  512. case MEDIA_BUS_FMT_YUV12_1X36:
  513. case MEDIA_BUS_FMT_UYVY12_1X24:
  514. case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
  515. return 12;
  516. case MEDIA_BUS_FMT_RGB161616_1X48:
  517. case MEDIA_BUS_FMT_YUV16_1X48:
  518. case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
  519. return 16;
  520. default:
  521. return 0;
  522. }
  523. }
  524. /*
  525. * this submodule is responsible for the video data synchronization.
  526. * for example, for RGB 4:4:4 input, the data map is defined as
  527. * pin{47~40} <==> R[7:0]
  528. * pin{31~24} <==> G[7:0]
  529. * pin{15~8} <==> B[7:0]
  530. */
  531. static void hdmi_video_sample(struct dw_hdmi *hdmi)
  532. {
  533. int color_format = 0;
  534. u8 val;
  535. switch (hdmi->hdmi_data.enc_in_bus_format) {
  536. case MEDIA_BUS_FMT_RGB888_1X24:
  537. color_format = 0x01;
  538. break;
  539. case MEDIA_BUS_FMT_RGB101010_1X30:
  540. color_format = 0x03;
  541. break;
  542. case MEDIA_BUS_FMT_RGB121212_1X36:
  543. color_format = 0x05;
  544. break;
  545. case MEDIA_BUS_FMT_RGB161616_1X48:
  546. color_format = 0x07;
  547. break;
  548. case MEDIA_BUS_FMT_YUV8_1X24:
  549. case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
  550. color_format = 0x09;
  551. break;
  552. case MEDIA_BUS_FMT_YUV10_1X30:
  553. case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
  554. color_format = 0x0B;
  555. break;
  556. case MEDIA_BUS_FMT_YUV12_1X36:
  557. case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
  558. color_format = 0x0D;
  559. break;
  560. case MEDIA_BUS_FMT_YUV16_1X48:
  561. case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
  562. color_format = 0x0F;
  563. break;
  564. case MEDIA_BUS_FMT_UYVY8_1X16:
  565. color_format = 0x16;
  566. break;
  567. case MEDIA_BUS_FMT_UYVY10_1X20:
  568. color_format = 0x14;
  569. break;
  570. case MEDIA_BUS_FMT_UYVY12_1X24:
  571. color_format = 0x12;
  572. break;
  573. default:
  574. return;
  575. }
  576. val = HDMI_TX_INVID0_INTERNAL_DE_GENERATOR_DISABLE |
  577. ((color_format << HDMI_TX_INVID0_VIDEO_MAPPING_OFFSET) &
  578. HDMI_TX_INVID0_VIDEO_MAPPING_MASK);
  579. hdmi_writeb(hdmi, val, HDMI_TX_INVID0);
  580. /* Enable TX stuffing: When DE is inactive, fix the output data to 0 */
  581. val = HDMI_TX_INSTUFFING_BDBDATA_STUFFING_ENABLE |
  582. HDMI_TX_INSTUFFING_RCRDATA_STUFFING_ENABLE |
  583. HDMI_TX_INSTUFFING_GYDATA_STUFFING_ENABLE;
  584. hdmi_writeb(hdmi, val, HDMI_TX_INSTUFFING);
  585. hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA0);
  586. hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA1);
  587. hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA0);
  588. hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA1);
  589. hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA0);
  590. hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA1);
  591. }
  592. static int is_color_space_conversion(struct dw_hdmi *hdmi)
  593. {
  594. return hdmi->hdmi_data.enc_in_bus_format != hdmi->hdmi_data.enc_out_bus_format;
  595. }
  596. static int is_color_space_decimation(struct dw_hdmi *hdmi)
  597. {
  598. if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format))
  599. return 0;
  600. if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) ||
  601. hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_in_bus_format))
  602. return 1;
  603. return 0;
  604. }
  605. static int is_color_space_interpolation(struct dw_hdmi *hdmi)
  606. {
  607. if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format))
  608. return 0;
  609. if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) ||
  610. hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format))
  611. return 1;
  612. return 0;
  613. }
  614. static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi)
  615. {
  616. const u16 (*csc_coeff)[3][4] = &csc_coeff_default;
  617. unsigned i;
  618. u32 csc_scale = 1;
  619. if (is_color_space_conversion(hdmi)) {
  620. if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) {
  621. if (hdmi->hdmi_data.enc_out_encoding ==
  622. V4L2_YCBCR_ENC_601)
  623. csc_coeff = &csc_coeff_rgb_out_eitu601;
  624. else
  625. csc_coeff = &csc_coeff_rgb_out_eitu709;
  626. } else if (hdmi_bus_fmt_is_rgb(
  627. hdmi->hdmi_data.enc_in_bus_format)) {
  628. if (hdmi->hdmi_data.enc_out_encoding ==
  629. V4L2_YCBCR_ENC_601)
  630. csc_coeff = &csc_coeff_rgb_in_eitu601;
  631. else
  632. csc_coeff = &csc_coeff_rgb_in_eitu709;
  633. csc_scale = 0;
  634. }
  635. }
  636. /* The CSC registers are sequential, alternating MSB then LSB */
  637. for (i = 0; i < ARRAY_SIZE(csc_coeff_default[0]); i++) {
  638. u16 coeff_a = (*csc_coeff)[0][i];
  639. u16 coeff_b = (*csc_coeff)[1][i];
  640. u16 coeff_c = (*csc_coeff)[2][i];
  641. hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2);
  642. hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2);
  643. hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2);
  644. hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2);
  645. hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2);
  646. hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2);
  647. }
  648. hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK,
  649. HDMI_CSC_SCALE);
  650. }
  651. static void hdmi_video_csc(struct dw_hdmi *hdmi)
  652. {
  653. int color_depth = 0;
  654. int interpolation = HDMI_CSC_CFG_INTMODE_DISABLE;
  655. int decimation = 0;
  656. /* YCC422 interpolation to 444 mode */
  657. if (is_color_space_interpolation(hdmi))
  658. interpolation = HDMI_CSC_CFG_INTMODE_CHROMA_INT_FORMULA1;
  659. else if (is_color_space_decimation(hdmi))
  660. decimation = HDMI_CSC_CFG_DECMODE_CHROMA_INT_FORMULA3;
  661. switch (hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format)) {
  662. case 8:
  663. color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_24BPP;
  664. break;
  665. case 10:
  666. color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_30BPP;
  667. break;
  668. case 12:
  669. color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_36BPP;
  670. break;
  671. case 16:
  672. color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_48BPP;
  673. break;
  674. default:
  675. return;
  676. }
  677. /* Configure the CSC registers */
  678. hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG);
  679. hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK,
  680. HDMI_CSC_SCALE);
  681. dw_hdmi_update_csc_coeffs(hdmi);
  682. }
  683. /*
  684. * HDMI video packetizer is used to packetize the data.
  685. * for example, if input is YCC422 mode or repeater is used,
  686. * data should be repacked this module can be bypassed.
  687. */
  688. static void hdmi_video_packetize(struct dw_hdmi *hdmi)
  689. {
  690. unsigned int color_depth = 0;
  691. unsigned int remap_size = HDMI_VP_REMAP_YCC422_16bit;
  692. unsigned int output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_PP;
  693. struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data;
  694. u8 val, vp_conf;
  695. if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) ||
  696. hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) {
  697. switch (hdmi_bus_fmt_color_depth(
  698. hdmi->hdmi_data.enc_out_bus_format)) {
  699. case 8:
  700. color_depth = 4;
  701. output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS;
  702. break;
  703. case 10:
  704. color_depth = 5;
  705. break;
  706. case 12:
  707. color_depth = 6;
  708. break;
  709. case 16:
  710. color_depth = 7;
  711. break;
  712. default:
  713. output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS;
  714. }
  715. } else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) {
  716. switch (hdmi_bus_fmt_color_depth(
  717. hdmi->hdmi_data.enc_out_bus_format)) {
  718. case 0:
  719. case 8:
  720. remap_size = HDMI_VP_REMAP_YCC422_16bit;
  721. break;
  722. case 10:
  723. remap_size = HDMI_VP_REMAP_YCC422_20bit;
  724. break;
  725. case 12:
  726. remap_size = HDMI_VP_REMAP_YCC422_24bit;
  727. break;
  728. default:
  729. return;
  730. }
  731. output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422;
  732. } else {
  733. return;
  734. }
  735. /* set the packetizer registers */
  736. val = ((color_depth << HDMI_VP_PR_CD_COLOR_DEPTH_OFFSET) &
  737. HDMI_VP_PR_CD_COLOR_DEPTH_MASK) |
  738. ((hdmi_data->pix_repet_factor <<
  739. HDMI_VP_PR_CD_DESIRED_PR_FACTOR_OFFSET) &
  740. HDMI_VP_PR_CD_DESIRED_PR_FACTOR_MASK);
  741. hdmi_writeb(hdmi, val, HDMI_VP_PR_CD);
  742. hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE,
  743. HDMI_VP_STUFF_PR_STUFFING_MASK, HDMI_VP_STUFF);
  744. /* Data from pixel repeater block */
  745. if (hdmi_data->pix_repet_factor > 1) {
  746. vp_conf = HDMI_VP_CONF_PR_EN_ENABLE |
  747. HDMI_VP_CONF_BYPASS_SELECT_PIX_REPEATER;
  748. } else { /* data from packetizer block */
  749. vp_conf = HDMI_VP_CONF_PR_EN_DISABLE |
  750. HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER;
  751. }
  752. hdmi_modb(hdmi, vp_conf,
  753. HDMI_VP_CONF_PR_EN_MASK |
  754. HDMI_VP_CONF_BYPASS_SELECT_MASK, HDMI_VP_CONF);
  755. hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET,
  756. HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, HDMI_VP_STUFF);
  757. hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP);
  758. if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_PP) {
  759. vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE |
  760. HDMI_VP_CONF_PP_EN_ENABLE |
  761. HDMI_VP_CONF_YCC422_EN_DISABLE;
  762. } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422) {
  763. vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE |
  764. HDMI_VP_CONF_PP_EN_DISABLE |
  765. HDMI_VP_CONF_YCC422_EN_ENABLE;
  766. } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS) {
  767. vp_conf = HDMI_VP_CONF_BYPASS_EN_ENABLE |
  768. HDMI_VP_CONF_PP_EN_DISABLE |
  769. HDMI_VP_CONF_YCC422_EN_DISABLE;
  770. } else {
  771. return;
  772. }
  773. hdmi_modb(hdmi, vp_conf,
  774. HDMI_VP_CONF_BYPASS_EN_MASK | HDMI_VP_CONF_PP_EN_ENMASK |
  775. HDMI_VP_CONF_YCC422_EN_MASK, HDMI_VP_CONF);
  776. hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE |
  777. HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE,
  778. HDMI_VP_STUFF_PP_STUFFING_MASK |
  779. HDMI_VP_STUFF_YCC422_STUFFING_MASK, HDMI_VP_STUFF);
  780. hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK,
  781. HDMI_VP_CONF);
  782. }
  783. /* -----------------------------------------------------------------------------
  784. * Synopsys PHY Handling
  785. */
  786. static inline void hdmi_phy_test_clear(struct dw_hdmi *hdmi,
  787. unsigned char bit)
  788. {
  789. hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET,
  790. HDMI_PHY_TST0_TSTCLR_MASK, HDMI_PHY_TST0);
  791. }
  792. static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec)
  793. {
  794. u32 val;
  795. while ((val = hdmi_readb(hdmi, HDMI_IH_I2CMPHY_STAT0) & 0x3) == 0) {
  796. if (msec-- == 0)
  797. return false;
  798. udelay(1000);
  799. }
  800. hdmi_writeb(hdmi, val, HDMI_IH_I2CMPHY_STAT0);
  801. return true;
  802. }
  803. void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data,
  804. unsigned char addr)
  805. {
  806. hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0);
  807. hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR);
  808. hdmi_writeb(hdmi, (unsigned char)(data >> 8),
  809. HDMI_PHY_I2CM_DATAO_1_ADDR);
  810. hdmi_writeb(hdmi, (unsigned char)(data >> 0),
  811. HDMI_PHY_I2CM_DATAO_0_ADDR);
  812. hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE,
  813. HDMI_PHY_I2CM_OPERATION_ADDR);
  814. hdmi_phy_wait_i2c_done(hdmi, 1000);
  815. }
  816. EXPORT_SYMBOL_GPL(dw_hdmi_phy_i2c_write);
  817. static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable)
  818. {
  819. hdmi_mask_writeb(hdmi, !enable, HDMI_PHY_CONF0,
  820. HDMI_PHY_CONF0_PDZ_OFFSET,
  821. HDMI_PHY_CONF0_PDZ_MASK);
  822. }
  823. static void dw_hdmi_phy_enable_tmds(struct dw_hdmi *hdmi, u8 enable)
  824. {
  825. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  826. HDMI_PHY_CONF0_ENTMDS_OFFSET,
  827. HDMI_PHY_CONF0_ENTMDS_MASK);
  828. }
  829. static void dw_hdmi_phy_enable_svsret(struct dw_hdmi *hdmi, u8 enable)
  830. {
  831. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  832. HDMI_PHY_CONF0_SVSRET_OFFSET,
  833. HDMI_PHY_CONF0_SVSRET_MASK);
  834. }
  835. static void dw_hdmi_phy_gen2_pddq(struct dw_hdmi *hdmi, u8 enable)
  836. {
  837. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  838. HDMI_PHY_CONF0_GEN2_PDDQ_OFFSET,
  839. HDMI_PHY_CONF0_GEN2_PDDQ_MASK);
  840. }
  841. static void dw_hdmi_phy_gen2_txpwron(struct dw_hdmi *hdmi, u8 enable)
  842. {
  843. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  844. HDMI_PHY_CONF0_GEN2_TXPWRON_OFFSET,
  845. HDMI_PHY_CONF0_GEN2_TXPWRON_MASK);
  846. }
  847. static void dw_hdmi_phy_sel_data_en_pol(struct dw_hdmi *hdmi, u8 enable)
  848. {
  849. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  850. HDMI_PHY_CONF0_SELDATAENPOL_OFFSET,
  851. HDMI_PHY_CONF0_SELDATAENPOL_MASK);
  852. }
  853. static void dw_hdmi_phy_sel_interface_control(struct dw_hdmi *hdmi, u8 enable)
  854. {
  855. hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0,
  856. HDMI_PHY_CONF0_SELDIPIF_OFFSET,
  857. HDMI_PHY_CONF0_SELDIPIF_MASK);
  858. }
  859. static void dw_hdmi_phy_power_off(struct dw_hdmi *hdmi)
  860. {
  861. const struct dw_hdmi_phy_data *phy = hdmi->phy.data;
  862. unsigned int i;
  863. u16 val;
  864. if (phy->gen == 1) {
  865. dw_hdmi_phy_enable_tmds(hdmi, 0);
  866. dw_hdmi_phy_enable_powerdown(hdmi, true);
  867. return;
  868. }
  869. dw_hdmi_phy_gen2_txpwron(hdmi, 0);
  870. /*
  871. * Wait for TX_PHY_LOCK to be deasserted to indicate that the PHY went
  872. * to low power mode.
  873. */
  874. for (i = 0; i < 5; ++i) {
  875. val = hdmi_readb(hdmi, HDMI_PHY_STAT0);
  876. if (!(val & HDMI_PHY_TX_PHY_LOCK))
  877. break;
  878. usleep_range(1000, 2000);
  879. }
  880. if (val & HDMI_PHY_TX_PHY_LOCK)
  881. dev_warn(hdmi->dev, "PHY failed to power down\n");
  882. else
  883. dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i);
  884. dw_hdmi_phy_gen2_pddq(hdmi, 1);
  885. }
  886. static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi)
  887. {
  888. const struct dw_hdmi_phy_data *phy = hdmi->phy.data;
  889. unsigned int i;
  890. u8 val;
  891. if (phy->gen == 1) {
  892. dw_hdmi_phy_enable_powerdown(hdmi, false);
  893. /* Toggle TMDS enable. */
  894. dw_hdmi_phy_enable_tmds(hdmi, 0);
  895. dw_hdmi_phy_enable_tmds(hdmi, 1);
  896. return 0;
  897. }
  898. dw_hdmi_phy_gen2_txpwron(hdmi, 1);
  899. dw_hdmi_phy_gen2_pddq(hdmi, 0);
  900. /* Wait for PHY PLL lock */
  901. for (i = 0; i < 5; ++i) {
  902. val = hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_TX_PHY_LOCK;
  903. if (val)
  904. break;
  905. usleep_range(1000, 2000);
  906. }
  907. if (!val) {
  908. dev_err(hdmi->dev, "PHY PLL failed to lock\n");
  909. return -ETIMEDOUT;
  910. }
  911. dev_dbg(hdmi->dev, "PHY PLL locked %u iterations\n", i);
  912. return 0;
  913. }
  914. /*
  915. * PHY configuration function for the DWC HDMI 3D TX PHY. Based on the available
  916. * information the DWC MHL PHY has the same register layout and is thus also
  917. * supported by this function.
  918. */
  919. static int hdmi_phy_configure_dwc_hdmi_3d_tx(struct dw_hdmi *hdmi,
  920. const struct dw_hdmi_plat_data *pdata,
  921. unsigned long mpixelclock)
  922. {
  923. const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg;
  924. const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr;
  925. const struct dw_hdmi_phy_config *phy_config = pdata->phy_config;
  926. /* PLL/MPLL Cfg - always match on final entry */
  927. for (; mpll_config->mpixelclock != ~0UL; mpll_config++)
  928. if (mpixelclock <= mpll_config->mpixelclock)
  929. break;
  930. for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++)
  931. if (mpixelclock <= curr_ctrl->mpixelclock)
  932. break;
  933. for (; phy_config->mpixelclock != ~0UL; phy_config++)
  934. if (mpixelclock <= phy_config->mpixelclock)
  935. break;
  936. if (mpll_config->mpixelclock == ~0UL ||
  937. curr_ctrl->mpixelclock == ~0UL ||
  938. phy_config->mpixelclock == ~0UL)
  939. return -EINVAL;
  940. dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce,
  941. HDMI_3D_TX_PHY_CPCE_CTRL);
  942. dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp,
  943. HDMI_3D_TX_PHY_GMPCTRL);
  944. dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0],
  945. HDMI_3D_TX_PHY_CURRCTRL);
  946. dw_hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL);
  947. dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK,
  948. HDMI_3D_TX_PHY_MSM_CTRL);
  949. dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM);
  950. dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr,
  951. HDMI_3D_TX_PHY_CKSYMTXCTRL);
  952. dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr,
  953. HDMI_3D_TX_PHY_VLEVCTRL);
  954. /* Override and disable clock termination. */
  955. dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE,
  956. HDMI_3D_TX_PHY_CKCALCTRL);
  957. return 0;
  958. }
  959. static int hdmi_phy_configure(struct dw_hdmi *hdmi)
  960. {
  961. const struct dw_hdmi_phy_data *phy = hdmi->phy.data;
  962. const struct dw_hdmi_plat_data *pdata = hdmi->plat_data;
  963. unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock;
  964. int ret;
  965. dw_hdmi_phy_power_off(hdmi);
  966. /* Leave low power consumption mode by asserting SVSRET. */
  967. if (phy->has_svsret)
  968. dw_hdmi_phy_enable_svsret(hdmi, 1);
  969. /* PHY reset. The reset signal is active high on Gen2 PHYs. */
  970. hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ);
  971. hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ);
  972. hdmi_writeb(hdmi, HDMI_MC_HEACPHY_RST_ASSERT, HDMI_MC_HEACPHY_RST);
  973. hdmi_phy_test_clear(hdmi, 1);
  974. hdmi_writeb(hdmi, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2,
  975. HDMI_PHY_I2CM_SLAVE_ADDR);
  976. hdmi_phy_test_clear(hdmi, 0);
  977. /* Write to the PHY as configured by the platform */
  978. if (pdata->configure_phy)
  979. ret = pdata->configure_phy(hdmi, pdata, mpixelclock);
  980. else
  981. ret = phy->configure(hdmi, pdata, mpixelclock);
  982. if (ret) {
  983. dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n",
  984. mpixelclock);
  985. return ret;
  986. }
  987. return dw_hdmi_phy_power_on(hdmi);
  988. }
  989. static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data,
  990. struct drm_display_mode *mode)
  991. {
  992. int i, ret;
  993. /* HDMI Phy spec says to do the phy initialization sequence twice */
  994. for (i = 0; i < 2; i++) {
  995. dw_hdmi_phy_sel_data_en_pol(hdmi, 1);
  996. dw_hdmi_phy_sel_interface_control(hdmi, 0);
  997. ret = hdmi_phy_configure(hdmi);
  998. if (ret)
  999. return ret;
  1000. }
  1001. return 0;
  1002. }
  1003. static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi, void *data)
  1004. {
  1005. dw_hdmi_phy_power_off(hdmi);
  1006. }
  1007. static enum drm_connector_status dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi,
  1008. void *data)
  1009. {
  1010. return hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD ?
  1011. connector_status_connected : connector_status_disconnected;
  1012. }
  1013. static void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data,
  1014. bool force, bool disabled, bool rxsense)
  1015. {
  1016. u8 old_mask = hdmi->phy_mask;
  1017. if (force || disabled || !rxsense)
  1018. hdmi->phy_mask |= HDMI_PHY_RX_SENSE;
  1019. else
  1020. hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE;
  1021. if (old_mask != hdmi->phy_mask)
  1022. hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
  1023. }
  1024. static void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data)
  1025. {
  1026. /*
  1027. * Configure the PHY RX SENSE and HPD interrupts polarities and clear
  1028. * any pending interrupt.
  1029. */
  1030. hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0);
  1031. hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
  1032. HDMI_IH_PHY_STAT0);
  1033. /* Enable cable hot plug irq. */
  1034. hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0);
  1035. /* Clear and unmute interrupts. */
  1036. hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE,
  1037. HDMI_IH_PHY_STAT0);
  1038. hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
  1039. HDMI_IH_MUTE_PHY_STAT0);
  1040. }
  1041. static const struct dw_hdmi_phy_ops dw_hdmi_synopsys_phy_ops = {
  1042. .init = dw_hdmi_phy_init,
  1043. .disable = dw_hdmi_phy_disable,
  1044. .read_hpd = dw_hdmi_phy_read_hpd,
  1045. .update_hpd = dw_hdmi_phy_update_hpd,
  1046. .setup_hpd = dw_hdmi_phy_setup_hpd,
  1047. };
  1048. /* -----------------------------------------------------------------------------
  1049. * HDMI TX Setup
  1050. */
  1051. static void hdmi_tx_hdcp_config(struct dw_hdmi *hdmi)
  1052. {
  1053. u8 de;
  1054. if (hdmi->hdmi_data.video_mode.mdataenablepolarity)
  1055. de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_HIGH;
  1056. else
  1057. de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_LOW;
  1058. /* disable rx detect */
  1059. hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE,
  1060. HDMI_A_HDCPCFG0_RXDETECT_MASK, HDMI_A_HDCPCFG0);
  1061. hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG);
  1062. hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE,
  1063. HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_MASK, HDMI_A_HDCPCFG1);
  1064. }
  1065. static void hdmi_config_AVI(struct dw_hdmi *hdmi, struct drm_display_mode *mode)
  1066. {
  1067. struct hdmi_avi_infoframe frame;
  1068. u8 val;
  1069. /* Initialise info frame from DRM mode */
  1070. drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
  1071. if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format))
  1072. frame.colorspace = HDMI_COLORSPACE_YUV444;
  1073. else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format))
  1074. frame.colorspace = HDMI_COLORSPACE_YUV422;
  1075. else
  1076. frame.colorspace = HDMI_COLORSPACE_RGB;
  1077. /* Set up colorimetry */
  1078. switch (hdmi->hdmi_data.enc_out_encoding) {
  1079. case V4L2_YCBCR_ENC_601:
  1080. if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV601)
  1081. frame.colorimetry = HDMI_COLORIMETRY_EXTENDED;
  1082. else
  1083. frame.colorimetry = HDMI_COLORIMETRY_ITU_601;
  1084. frame.extended_colorimetry =
  1085. HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
  1086. break;
  1087. case V4L2_YCBCR_ENC_709:
  1088. if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV709)
  1089. frame.colorimetry = HDMI_COLORIMETRY_EXTENDED;
  1090. else
  1091. frame.colorimetry = HDMI_COLORIMETRY_ITU_709;
  1092. frame.extended_colorimetry =
  1093. HDMI_EXTENDED_COLORIMETRY_XV_YCC_709;
  1094. break;
  1095. default: /* Carries no data */
  1096. frame.colorimetry = HDMI_COLORIMETRY_ITU_601;
  1097. frame.extended_colorimetry =
  1098. HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
  1099. break;
  1100. }
  1101. frame.scan_mode = HDMI_SCAN_MODE_NONE;
  1102. /*
  1103. * The Designware IP uses a different byte format from standard
  1104. * AVI info frames, though generally the bits are in the correct
  1105. * bytes.
  1106. */
  1107. /*
  1108. * AVI data byte 1 differences: Colorspace in bits 0,1 rather than 5,6,
  1109. * scan info in bits 4,5 rather than 0,1 and active aspect present in
  1110. * bit 6 rather than 4.
  1111. */
  1112. val = (frame.scan_mode & 3) << 4 | (frame.colorspace & 3);
  1113. if (frame.active_aspect & 15)
  1114. val |= HDMI_FC_AVICONF0_ACTIVE_FMT_INFO_PRESENT;
  1115. if (frame.top_bar || frame.bottom_bar)
  1116. val |= HDMI_FC_AVICONF0_BAR_DATA_HORIZ_BAR;
  1117. if (frame.left_bar || frame.right_bar)
  1118. val |= HDMI_FC_AVICONF0_BAR_DATA_VERT_BAR;
  1119. hdmi_writeb(hdmi, val, HDMI_FC_AVICONF0);
  1120. /* AVI data byte 2 differences: none */
  1121. val = ((frame.colorimetry & 0x3) << 6) |
  1122. ((frame.picture_aspect & 0x3) << 4) |
  1123. (frame.active_aspect & 0xf);
  1124. hdmi_writeb(hdmi, val, HDMI_FC_AVICONF1);
  1125. /* AVI data byte 3 differences: none */
  1126. val = ((frame.extended_colorimetry & 0x7) << 4) |
  1127. ((frame.quantization_range & 0x3) << 2) |
  1128. (frame.nups & 0x3);
  1129. if (frame.itc)
  1130. val |= HDMI_FC_AVICONF2_IT_CONTENT_VALID;
  1131. hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2);
  1132. /* AVI data byte 4 differences: none */
  1133. val = frame.video_code & 0x7f;
  1134. hdmi_writeb(hdmi, val, HDMI_FC_AVIVID);
  1135. /* AVI Data Byte 5- set up input and output pixel repetition */
  1136. val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) <<
  1137. HDMI_FC_PRCONF_INCOMING_PR_FACTOR_OFFSET) &
  1138. HDMI_FC_PRCONF_INCOMING_PR_FACTOR_MASK) |
  1139. ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput <<
  1140. HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_OFFSET) &
  1141. HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_MASK);
  1142. hdmi_writeb(hdmi, val, HDMI_FC_PRCONF);
  1143. /*
  1144. * AVI data byte 5 differences: content type in 0,1 rather than 4,5,
  1145. * ycc range in bits 2,3 rather than 6,7
  1146. */
  1147. val = ((frame.ycc_quantization_range & 0x3) << 2) |
  1148. (frame.content_type & 0x3);
  1149. hdmi_writeb(hdmi, val, HDMI_FC_AVICONF3);
  1150. /* AVI Data Bytes 6-13 */
  1151. hdmi_writeb(hdmi, frame.top_bar & 0xff, HDMI_FC_AVIETB0);
  1152. hdmi_writeb(hdmi, (frame.top_bar >> 8) & 0xff, HDMI_FC_AVIETB1);
  1153. hdmi_writeb(hdmi, frame.bottom_bar & 0xff, HDMI_FC_AVISBB0);
  1154. hdmi_writeb(hdmi, (frame.bottom_bar >> 8) & 0xff, HDMI_FC_AVISBB1);
  1155. hdmi_writeb(hdmi, frame.left_bar & 0xff, HDMI_FC_AVIELB0);
  1156. hdmi_writeb(hdmi, (frame.left_bar >> 8) & 0xff, HDMI_FC_AVIELB1);
  1157. hdmi_writeb(hdmi, frame.right_bar & 0xff, HDMI_FC_AVISRB0);
  1158. hdmi_writeb(hdmi, (frame.right_bar >> 8) & 0xff, HDMI_FC_AVISRB1);
  1159. }
  1160. static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
  1161. struct drm_display_mode *mode)
  1162. {
  1163. struct hdmi_vendor_infoframe frame;
  1164. u8 buffer[10];
  1165. ssize_t err;
  1166. err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
  1167. if (err < 0)
  1168. /*
  1169. * Going into that statement does not means vendor infoframe
  1170. * fails. It just informed us that vendor infoframe is not
  1171. * needed for the selected mode. Only 4k or stereoscopic 3D
  1172. * mode requires vendor infoframe. So just simply return.
  1173. */
  1174. return;
  1175. err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
  1176. if (err < 0) {
  1177. dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n",
  1178. err);
  1179. return;
  1180. }
  1181. hdmi_mask_writeb(hdmi, 0, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET,
  1182. HDMI_FC_DATAUTO0_VSD_MASK);
  1183. /* Set the length of HDMI vendor specific InfoFrame payload */
  1184. hdmi_writeb(hdmi, buffer[2], HDMI_FC_VSDSIZE);
  1185. /* Set 24bit IEEE Registration Identifier */
  1186. hdmi_writeb(hdmi, buffer[4], HDMI_FC_VSDIEEEID0);
  1187. hdmi_writeb(hdmi, buffer[5], HDMI_FC_VSDIEEEID1);
  1188. hdmi_writeb(hdmi, buffer[6], HDMI_FC_VSDIEEEID2);
  1189. /* Set HDMI_Video_Format and HDMI_VIC/3D_Structure */
  1190. hdmi_writeb(hdmi, buffer[7], HDMI_FC_VSDPAYLOAD0);
  1191. hdmi_writeb(hdmi, buffer[8], HDMI_FC_VSDPAYLOAD1);
  1192. if (frame.s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
  1193. hdmi_writeb(hdmi, buffer[9], HDMI_FC_VSDPAYLOAD2);
  1194. /* Packet frame interpolation */
  1195. hdmi_writeb(hdmi, 1, HDMI_FC_DATAUTO1);
  1196. /* Auto packets per frame and line spacing */
  1197. hdmi_writeb(hdmi, 0x11, HDMI_FC_DATAUTO2);
  1198. /* Configures the Frame Composer On RDRB mode */
  1199. hdmi_mask_writeb(hdmi, 1, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET,
  1200. HDMI_FC_DATAUTO0_VSD_MASK);
  1201. }
  1202. static void hdmi_av_composer(struct dw_hdmi *hdmi,
  1203. const struct drm_display_mode *mode)
  1204. {
  1205. u8 inv_val;
  1206. struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode;
  1207. int hblank, vblank, h_de_hs, v_de_vs, hsync_len, vsync_len;
  1208. unsigned int vdisplay;
  1209. vmode->mpixelclock = mode->clock * 1000;
  1210. dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock);
  1211. /* Set up HDMI_FC_INVIDCONF */
  1212. inv_val = (hdmi->hdmi_data.hdcp_enable ?
  1213. HDMI_FC_INVIDCONF_HDCP_KEEPOUT_ACTIVE :
  1214. HDMI_FC_INVIDCONF_HDCP_KEEPOUT_INACTIVE);
  1215. inv_val |= mode->flags & DRM_MODE_FLAG_PVSYNC ?
  1216. HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_HIGH :
  1217. HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_LOW;
  1218. inv_val |= mode->flags & DRM_MODE_FLAG_PHSYNC ?
  1219. HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_HIGH :
  1220. HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_LOW;
  1221. inv_val |= (vmode->mdataenablepolarity ?
  1222. HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH :
  1223. HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW);
  1224. if (hdmi->vic == 39)
  1225. inv_val |= HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH;
  1226. else
  1227. inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
  1228. HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH :
  1229. HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW;
  1230. inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ?
  1231. HDMI_FC_INVIDCONF_IN_I_P_INTERLACED :
  1232. HDMI_FC_INVIDCONF_IN_I_P_PROGRESSIVE;
  1233. inv_val |= hdmi->sink_is_hdmi ?
  1234. HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE :
  1235. HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE;
  1236. hdmi_writeb(hdmi, inv_val, HDMI_FC_INVIDCONF);
  1237. vdisplay = mode->vdisplay;
  1238. vblank = mode->vtotal - mode->vdisplay;
  1239. v_de_vs = mode->vsync_start - mode->vdisplay;
  1240. vsync_len = mode->vsync_end - mode->vsync_start;
  1241. /*
  1242. * When we're setting an interlaced mode, we need
  1243. * to adjust the vertical timing to suit.
  1244. */
  1245. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  1246. vdisplay /= 2;
  1247. vblank /= 2;
  1248. v_de_vs /= 2;
  1249. vsync_len /= 2;
  1250. }
  1251. /* Set up horizontal active pixel width */
  1252. hdmi_writeb(hdmi, mode->hdisplay >> 8, HDMI_FC_INHACTV1);
  1253. hdmi_writeb(hdmi, mode->hdisplay, HDMI_FC_INHACTV0);
  1254. /* Set up vertical active lines */
  1255. hdmi_writeb(hdmi, vdisplay >> 8, HDMI_FC_INVACTV1);
  1256. hdmi_writeb(hdmi, vdisplay, HDMI_FC_INVACTV0);
  1257. /* Set up horizontal blanking pixel region width */
  1258. hblank = mode->htotal - mode->hdisplay;
  1259. hdmi_writeb(hdmi, hblank >> 8, HDMI_FC_INHBLANK1);
  1260. hdmi_writeb(hdmi, hblank, HDMI_FC_INHBLANK0);
  1261. /* Set up vertical blanking pixel region width */
  1262. hdmi_writeb(hdmi, vblank, HDMI_FC_INVBLANK);
  1263. /* Set up HSYNC active edge delay width (in pixel clks) */
  1264. h_de_hs = mode->hsync_start - mode->hdisplay;
  1265. hdmi_writeb(hdmi, h_de_hs >> 8, HDMI_FC_HSYNCINDELAY1);
  1266. hdmi_writeb(hdmi, h_de_hs, HDMI_FC_HSYNCINDELAY0);
  1267. /* Set up VSYNC active edge delay (in lines) */
  1268. hdmi_writeb(hdmi, v_de_vs, HDMI_FC_VSYNCINDELAY);
  1269. /* Set up HSYNC active pulse width (in pixel clks) */
  1270. hsync_len = mode->hsync_end - mode->hsync_start;
  1271. hdmi_writeb(hdmi, hsync_len >> 8, HDMI_FC_HSYNCINWIDTH1);
  1272. hdmi_writeb(hdmi, hsync_len, HDMI_FC_HSYNCINWIDTH0);
  1273. /* Set up VSYNC active edge delay (in lines) */
  1274. hdmi_writeb(hdmi, vsync_len, HDMI_FC_VSYNCINWIDTH);
  1275. }
  1276. /* HDMI Initialization Step B.4 */
  1277. static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi)
  1278. {
  1279. u8 clkdis;
  1280. /* control period minimum duration */
  1281. hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR);
  1282. hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR);
  1283. hdmi_writeb(hdmi, 1, HDMI_FC_EXCTRLSPAC);
  1284. /* Set to fill TMDS data channels */
  1285. hdmi_writeb(hdmi, 0x0B, HDMI_FC_CH0PREAM);
  1286. hdmi_writeb(hdmi, 0x16, HDMI_FC_CH1PREAM);
  1287. hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM);
  1288. /* Enable pixel clock and tmds data path */
  1289. clkdis = 0x7F;
  1290. clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE;
  1291. hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
  1292. clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE;
  1293. hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
  1294. /* Enable csc path */
  1295. if (is_color_space_conversion(hdmi)) {
  1296. clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE;
  1297. hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
  1298. }
  1299. /* Enable color space conversion if needed */
  1300. if (is_color_space_conversion(hdmi))
  1301. hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH,
  1302. HDMI_MC_FLOWCTRL);
  1303. else
  1304. hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS,
  1305. HDMI_MC_FLOWCTRL);
  1306. }
  1307. static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi)
  1308. {
  1309. hdmi_modb(hdmi, 0, HDMI_MC_CLKDIS_AUDCLK_DISABLE, HDMI_MC_CLKDIS);
  1310. }
  1311. /* Workaround to clear the overflow condition */
  1312. static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi)
  1313. {
  1314. unsigned int count;
  1315. unsigned int i;
  1316. u8 val;
  1317. /*
  1318. * Under some circumstances the Frame Composer arithmetic unit can miss
  1319. * an FC register write due to being busy processing the previous one.
  1320. * The issue can be worked around by issuing a TMDS software reset and
  1321. * then write one of the FC registers several times.
  1322. *
  1323. * The number of iterations matters and depends on the HDMI TX revision
  1324. * (and possibly on the platform). So far only i.MX6Q (v1.30a) and
  1325. * i.MX6DL (v1.31a) have been identified as needing the workaround, with
  1326. * 4 and 1 iterations respectively.
  1327. */
  1328. switch (hdmi->version) {
  1329. case 0x130a:
  1330. count = 4;
  1331. break;
  1332. case 0x131a:
  1333. count = 1;
  1334. break;
  1335. default:
  1336. return;
  1337. }
  1338. /* TMDS software reset */
  1339. hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, HDMI_MC_SWRSTZ);
  1340. val = hdmi_readb(hdmi, HDMI_FC_INVIDCONF);
  1341. for (i = 0; i < count; i++)
  1342. hdmi_writeb(hdmi, val, HDMI_FC_INVIDCONF);
  1343. }
  1344. static void hdmi_enable_overflow_interrupts(struct dw_hdmi *hdmi)
  1345. {
  1346. hdmi_writeb(hdmi, 0, HDMI_FC_MASK2);
  1347. hdmi_writeb(hdmi, 0, HDMI_IH_MUTE_FC_STAT2);
  1348. }
  1349. static void hdmi_disable_overflow_interrupts(struct dw_hdmi *hdmi)
  1350. {
  1351. hdmi_writeb(hdmi, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK,
  1352. HDMI_IH_MUTE_FC_STAT2);
  1353. }
  1354. static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct drm_display_mode *mode)
  1355. {
  1356. int ret;
  1357. hdmi_disable_overflow_interrupts(hdmi);
  1358. hdmi->vic = drm_match_cea_mode(mode);
  1359. if (!hdmi->vic) {
  1360. dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n");
  1361. } else {
  1362. dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic);
  1363. }
  1364. if ((hdmi->vic == 6) || (hdmi->vic == 7) ||
  1365. (hdmi->vic == 21) || (hdmi->vic == 22) ||
  1366. (hdmi->vic == 2) || (hdmi->vic == 3) ||
  1367. (hdmi->vic == 17) || (hdmi->vic == 18))
  1368. hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601;
  1369. else
  1370. hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709;
  1371. hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0;
  1372. hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0;
  1373. /* TOFIX: Get input format from plat data or fallback to RGB888 */
  1374. if (hdmi->plat_data->input_bus_format)
  1375. hdmi->hdmi_data.enc_in_bus_format =
  1376. hdmi->plat_data->input_bus_format;
  1377. else
  1378. hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
  1379. /* TOFIX: Get input encoding from plat data or fallback to none */
  1380. if (hdmi->plat_data->input_bus_encoding)
  1381. hdmi->hdmi_data.enc_in_encoding =
  1382. hdmi->plat_data->input_bus_encoding;
  1383. else
  1384. hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT;
  1385. /* TOFIX: Default to RGB888 output format */
  1386. hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24;
  1387. hdmi->hdmi_data.pix_repet_factor = 0;
  1388. hdmi->hdmi_data.hdcp_enable = 0;
  1389. hdmi->hdmi_data.video_mode.mdataenablepolarity = true;
  1390. /* HDMI Initialization Step B.1 */
  1391. hdmi_av_composer(hdmi, mode);
  1392. /* HDMI Initializateion Step B.2 */
  1393. ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, &hdmi->previous_mode);
  1394. if (ret)
  1395. return ret;
  1396. hdmi->phy.enabled = true;
  1397. /* HDMI Initialization Step B.3 */
  1398. dw_hdmi_enable_video_path(hdmi);
  1399. if (hdmi->sink_has_audio) {
  1400. dev_dbg(hdmi->dev, "sink has audio support\n");
  1401. /* HDMI Initialization Step E - Configure audio */
  1402. hdmi_clk_regenerator_update_pixel_clock(hdmi);
  1403. hdmi_enable_audio_clk(hdmi);
  1404. }
  1405. /* not for DVI mode */
  1406. if (hdmi->sink_is_hdmi) {
  1407. dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__);
  1408. /* HDMI Initialization Step F - Configure AVI InfoFrame */
  1409. hdmi_config_AVI(hdmi, mode);
  1410. hdmi_config_vendor_specific_infoframe(hdmi, mode);
  1411. } else {
  1412. dev_dbg(hdmi->dev, "%s DVI mode\n", __func__);
  1413. }
  1414. hdmi_video_packetize(hdmi);
  1415. hdmi_video_csc(hdmi);
  1416. hdmi_video_sample(hdmi);
  1417. hdmi_tx_hdcp_config(hdmi);
  1418. dw_hdmi_clear_overflow(hdmi);
  1419. if (hdmi->cable_plugin && hdmi->sink_is_hdmi)
  1420. hdmi_enable_overflow_interrupts(hdmi);
  1421. return 0;
  1422. }
  1423. static void dw_hdmi_setup_i2c(struct dw_hdmi *hdmi)
  1424. {
  1425. hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL,
  1426. HDMI_PHY_I2CM_INT_ADDR);
  1427. hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL |
  1428. HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL,
  1429. HDMI_PHY_I2CM_CTLINT_ADDR);
  1430. }
  1431. static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi)
  1432. {
  1433. u8 ih_mute;
  1434. /*
  1435. * Boot up defaults are:
  1436. * HDMI_IH_MUTE = 0x03 (disabled)
  1437. * HDMI_IH_MUTE_* = 0x00 (enabled)
  1438. *
  1439. * Disable top level interrupt bits in HDMI block
  1440. */
  1441. ih_mute = hdmi_readb(hdmi, HDMI_IH_MUTE) |
  1442. HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT |
  1443. HDMI_IH_MUTE_MUTE_ALL_INTERRUPT;
  1444. hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE);
  1445. /* by default mask all interrupts */
  1446. hdmi_writeb(hdmi, 0xff, HDMI_VP_MASK);
  1447. hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK0);
  1448. hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK1);
  1449. hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK2);
  1450. hdmi_writeb(hdmi, 0xff, HDMI_PHY_MASK0);
  1451. hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_INT_ADDR);
  1452. hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR);
  1453. hdmi_writeb(hdmi, 0xff, HDMI_AUD_INT);
  1454. hdmi_writeb(hdmi, 0xff, HDMI_AUD_SPDIFINT);
  1455. hdmi_writeb(hdmi, 0xff, HDMI_AUD_HBR_MASK);
  1456. hdmi_writeb(hdmi, 0xff, HDMI_GP_MASK);
  1457. hdmi_writeb(hdmi, 0xff, HDMI_A_APIINTMSK);
  1458. hdmi_writeb(hdmi, 0xff, HDMI_CEC_MASK);
  1459. hdmi_writeb(hdmi, 0xff, HDMI_I2CM_INT);
  1460. hdmi_writeb(hdmi, 0xff, HDMI_I2CM_CTLINT);
  1461. /* Disable interrupts in the IH_MUTE_* registers */
  1462. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT0);
  1463. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT1);
  1464. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT2);
  1465. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AS_STAT0);
  1466. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_PHY_STAT0);
  1467. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CM_STAT0);
  1468. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_CEC_STAT0);
  1469. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_VP_STAT0);
  1470. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0);
  1471. hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0);
  1472. /* Enable top level interrupt bits in HDMI block */
  1473. ih_mute &= ~(HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT |
  1474. HDMI_IH_MUTE_MUTE_ALL_INTERRUPT);
  1475. hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE);
  1476. }
  1477. static void dw_hdmi_poweron(struct dw_hdmi *hdmi)
  1478. {
  1479. hdmi->bridge_is_on = true;
  1480. dw_hdmi_setup(hdmi, &hdmi->previous_mode);
  1481. }
  1482. static void dw_hdmi_poweroff(struct dw_hdmi *hdmi)
  1483. {
  1484. if (hdmi->phy.enabled) {
  1485. hdmi->phy.ops->disable(hdmi, hdmi->phy.data);
  1486. hdmi->phy.enabled = false;
  1487. }
  1488. hdmi->bridge_is_on = false;
  1489. }
  1490. static void dw_hdmi_update_power(struct dw_hdmi *hdmi)
  1491. {
  1492. int force = hdmi->force;
  1493. if (hdmi->disabled) {
  1494. force = DRM_FORCE_OFF;
  1495. } else if (force == DRM_FORCE_UNSPECIFIED) {
  1496. if (hdmi->rxsense)
  1497. force = DRM_FORCE_ON;
  1498. else
  1499. force = DRM_FORCE_OFF;
  1500. }
  1501. if (force == DRM_FORCE_OFF) {
  1502. if (hdmi->bridge_is_on)
  1503. dw_hdmi_poweroff(hdmi);
  1504. } else {
  1505. if (!hdmi->bridge_is_on)
  1506. dw_hdmi_poweron(hdmi);
  1507. }
  1508. }
  1509. /*
  1510. * Adjust the detection of RXSENSE according to whether we have a forced
  1511. * connection mode enabled, or whether we have been disabled. There is
  1512. * no point processing RXSENSE interrupts if we have a forced connection
  1513. * state, or DRM has us disabled.
  1514. *
  1515. * We also disable rxsense interrupts when we think we're disconnected
  1516. * to avoid floating TDMS signals giving false rxsense interrupts.
  1517. *
  1518. * Note: we still need to listen for HPD interrupts even when DRM has us
  1519. * disabled so that we can detect a connect event.
  1520. */
  1521. static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi)
  1522. {
  1523. if (hdmi->phy.ops->update_hpd)
  1524. hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data,
  1525. hdmi->force, hdmi->disabled,
  1526. hdmi->rxsense);
  1527. }
  1528. static enum drm_connector_status
  1529. dw_hdmi_connector_detect(struct drm_connector *connector, bool force)
  1530. {
  1531. struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi,
  1532. connector);
  1533. mutex_lock(&hdmi->mutex);
  1534. hdmi->force = DRM_FORCE_UNSPECIFIED;
  1535. dw_hdmi_update_power(hdmi);
  1536. dw_hdmi_update_phy_mask(hdmi);
  1537. mutex_unlock(&hdmi->mutex);
  1538. return hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
  1539. }
  1540. static int dw_hdmi_connector_get_modes(struct drm_connector *connector)
  1541. {
  1542. struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi,
  1543. connector);
  1544. struct edid *edid;
  1545. int ret = 0;
  1546. if (!hdmi->ddc)
  1547. return 0;
  1548. edid = drm_get_edid(connector, hdmi->ddc);
  1549. if (edid) {
  1550. dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n",
  1551. edid->width_cm, edid->height_cm);
  1552. hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid);
  1553. hdmi->sink_has_audio = drm_detect_monitor_audio(edid);
  1554. drm_mode_connector_update_edid_property(connector, edid);
  1555. ret = drm_add_edid_modes(connector, edid);
  1556. /* Store the ELD */
  1557. drm_edid_to_eld(connector, edid);
  1558. kfree(edid);
  1559. } else {
  1560. dev_dbg(hdmi->dev, "failed to get edid\n");
  1561. }
  1562. return ret;
  1563. }
  1564. static enum drm_mode_status
  1565. dw_hdmi_connector_mode_valid(struct drm_connector *connector,
  1566. struct drm_display_mode *mode)
  1567. {
  1568. struct dw_hdmi *hdmi = container_of(connector,
  1569. struct dw_hdmi, connector);
  1570. enum drm_mode_status mode_status = MODE_OK;
  1571. /* We don't support double-clocked modes */
  1572. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  1573. return MODE_BAD;
  1574. if (hdmi->plat_data->mode_valid)
  1575. mode_status = hdmi->plat_data->mode_valid(connector, mode);
  1576. return mode_status;
  1577. }
  1578. static void dw_hdmi_connector_force(struct drm_connector *connector)
  1579. {
  1580. struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi,
  1581. connector);
  1582. mutex_lock(&hdmi->mutex);
  1583. hdmi->force = connector->force;
  1584. dw_hdmi_update_power(hdmi);
  1585. dw_hdmi_update_phy_mask(hdmi);
  1586. mutex_unlock(&hdmi->mutex);
  1587. }
  1588. static const struct drm_connector_funcs dw_hdmi_connector_funcs = {
  1589. .dpms = drm_atomic_helper_connector_dpms,
  1590. .fill_modes = drm_helper_probe_single_connector_modes,
  1591. .detect = dw_hdmi_connector_detect,
  1592. .destroy = drm_connector_cleanup,
  1593. .force = dw_hdmi_connector_force,
  1594. .reset = drm_atomic_helper_connector_reset,
  1595. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  1596. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1597. };
  1598. static const struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs = {
  1599. .get_modes = dw_hdmi_connector_get_modes,
  1600. .mode_valid = dw_hdmi_connector_mode_valid,
  1601. .best_encoder = drm_atomic_helper_best_encoder,
  1602. };
  1603. static int dw_hdmi_bridge_attach(struct drm_bridge *bridge)
  1604. {
  1605. struct dw_hdmi *hdmi = bridge->driver_private;
  1606. struct drm_encoder *encoder = bridge->encoder;
  1607. struct drm_connector *connector = &hdmi->connector;
  1608. connector->interlace_allowed = 1;
  1609. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1610. drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs);
  1611. drm_connector_init(bridge->dev, connector, &dw_hdmi_connector_funcs,
  1612. DRM_MODE_CONNECTOR_HDMIA);
  1613. drm_mode_connector_attach_encoder(connector, encoder);
  1614. return 0;
  1615. }
  1616. static bool dw_hdmi_bridge_mode_fixup(struct drm_bridge *bridge,
  1617. const struct drm_display_mode *orig_mode,
  1618. struct drm_display_mode *mode)
  1619. {
  1620. struct dw_hdmi *hdmi = bridge->driver_private;
  1621. struct drm_connector *connector = &hdmi->connector;
  1622. enum drm_mode_status status;
  1623. status = dw_hdmi_connector_mode_valid(connector, mode);
  1624. if (status != MODE_OK)
  1625. return false;
  1626. return true;
  1627. }
  1628. static void dw_hdmi_bridge_mode_set(struct drm_bridge *bridge,
  1629. struct drm_display_mode *orig_mode,
  1630. struct drm_display_mode *mode)
  1631. {
  1632. struct dw_hdmi *hdmi = bridge->driver_private;
  1633. mutex_lock(&hdmi->mutex);
  1634. /* Store the display mode for plugin/DKMS poweron events */
  1635. memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode));
  1636. mutex_unlock(&hdmi->mutex);
  1637. }
  1638. static void dw_hdmi_bridge_disable(struct drm_bridge *bridge)
  1639. {
  1640. struct dw_hdmi *hdmi = bridge->driver_private;
  1641. mutex_lock(&hdmi->mutex);
  1642. hdmi->disabled = true;
  1643. dw_hdmi_update_power(hdmi);
  1644. dw_hdmi_update_phy_mask(hdmi);
  1645. mutex_unlock(&hdmi->mutex);
  1646. }
  1647. static void dw_hdmi_bridge_enable(struct drm_bridge *bridge)
  1648. {
  1649. struct dw_hdmi *hdmi = bridge->driver_private;
  1650. mutex_lock(&hdmi->mutex);
  1651. hdmi->disabled = false;
  1652. dw_hdmi_update_power(hdmi);
  1653. dw_hdmi_update_phy_mask(hdmi);
  1654. mutex_unlock(&hdmi->mutex);
  1655. }
  1656. static const struct drm_bridge_funcs dw_hdmi_bridge_funcs = {
  1657. .attach = dw_hdmi_bridge_attach,
  1658. .enable = dw_hdmi_bridge_enable,
  1659. .disable = dw_hdmi_bridge_disable,
  1660. .mode_set = dw_hdmi_bridge_mode_set,
  1661. .mode_fixup = dw_hdmi_bridge_mode_fixup,
  1662. };
  1663. static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi)
  1664. {
  1665. struct dw_hdmi_i2c *i2c = hdmi->i2c;
  1666. unsigned int stat;
  1667. stat = hdmi_readb(hdmi, HDMI_IH_I2CM_STAT0);
  1668. if (!stat)
  1669. return IRQ_NONE;
  1670. hdmi_writeb(hdmi, stat, HDMI_IH_I2CM_STAT0);
  1671. i2c->stat = stat;
  1672. complete(&i2c->cmp);
  1673. return IRQ_HANDLED;
  1674. }
  1675. static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id)
  1676. {
  1677. struct dw_hdmi *hdmi = dev_id;
  1678. u8 intr_stat;
  1679. irqreturn_t ret = IRQ_NONE;
  1680. if (hdmi->i2c)
  1681. ret = dw_hdmi_i2c_irq(hdmi);
  1682. intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0);
  1683. if (intr_stat) {
  1684. hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
  1685. return IRQ_WAKE_THREAD;
  1686. }
  1687. return ret;
  1688. }
  1689. void __dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense)
  1690. {
  1691. mutex_lock(&hdmi->mutex);
  1692. if (!hdmi->force) {
  1693. /*
  1694. * If the RX sense status indicates we're disconnected,
  1695. * clear the software rxsense status.
  1696. */
  1697. if (!rx_sense)
  1698. hdmi->rxsense = false;
  1699. /*
  1700. * Only set the software rxsense status when both
  1701. * rxsense and hpd indicates we're connected.
  1702. * This avoids what seems to be bad behaviour in
  1703. * at least iMX6S versions of the phy.
  1704. */
  1705. if (hpd)
  1706. hdmi->rxsense = true;
  1707. dw_hdmi_update_power(hdmi);
  1708. dw_hdmi_update_phy_mask(hdmi);
  1709. }
  1710. mutex_unlock(&hdmi->mutex);
  1711. }
  1712. void dw_hdmi_setup_rx_sense(struct device *dev, bool hpd, bool rx_sense)
  1713. {
  1714. struct dw_hdmi *hdmi = dev_get_drvdata(dev);
  1715. __dw_hdmi_setup_rx_sense(hdmi, hpd, rx_sense);
  1716. }
  1717. EXPORT_SYMBOL_GPL(dw_hdmi_setup_rx_sense);
  1718. static irqreturn_t dw_hdmi_irq(int irq, void *dev_id)
  1719. {
  1720. struct dw_hdmi *hdmi = dev_id;
  1721. u8 intr_stat, phy_int_pol, phy_pol_mask, phy_stat;
  1722. intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0);
  1723. phy_int_pol = hdmi_readb(hdmi, HDMI_PHY_POL0);
  1724. phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0);
  1725. phy_pol_mask = 0;
  1726. if (intr_stat & HDMI_IH_PHY_STAT0_HPD)
  1727. phy_pol_mask |= HDMI_PHY_HPD;
  1728. if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE0)
  1729. phy_pol_mask |= HDMI_PHY_RX_SENSE0;
  1730. if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE1)
  1731. phy_pol_mask |= HDMI_PHY_RX_SENSE1;
  1732. if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE2)
  1733. phy_pol_mask |= HDMI_PHY_RX_SENSE2;
  1734. if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE3)
  1735. phy_pol_mask |= HDMI_PHY_RX_SENSE3;
  1736. if (phy_pol_mask)
  1737. hdmi_modb(hdmi, ~phy_int_pol, phy_pol_mask, HDMI_PHY_POL0);
  1738. /*
  1739. * RX sense tells us whether the TDMS transmitters are detecting
  1740. * load - in other words, there's something listening on the
  1741. * other end of the link. Use this to decide whether we should
  1742. * power on the phy as HPD may be toggled by the sink to merely
  1743. * ask the source to re-read the EDID.
  1744. */
  1745. if (intr_stat &
  1746. (HDMI_IH_PHY_STAT0_RX_SENSE | HDMI_IH_PHY_STAT0_HPD))
  1747. __dw_hdmi_setup_rx_sense(hdmi,
  1748. phy_stat & HDMI_PHY_HPD,
  1749. phy_stat & HDMI_PHY_RX_SENSE);
  1750. if (intr_stat & HDMI_IH_PHY_STAT0_HPD) {
  1751. dev_dbg(hdmi->dev, "EVENT=%s\n",
  1752. phy_int_pol & HDMI_PHY_HPD ? "plugin" : "plugout");
  1753. if (hdmi->bridge.dev)
  1754. drm_helper_hpd_irq_event(hdmi->bridge.dev);
  1755. }
  1756. hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0);
  1757. hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE),
  1758. HDMI_IH_MUTE_PHY_STAT0);
  1759. return IRQ_HANDLED;
  1760. }
  1761. static const struct dw_hdmi_phy_data dw_hdmi_phys[] = {
  1762. {
  1763. .type = DW_HDMI_PHY_DWC_HDMI_TX_PHY,
  1764. .name = "DWC HDMI TX PHY",
  1765. .gen = 1,
  1766. }, {
  1767. .type = DW_HDMI_PHY_DWC_MHL_PHY_HEAC,
  1768. .name = "DWC MHL PHY + HEAC PHY",
  1769. .gen = 2,
  1770. .has_svsret = true,
  1771. .configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
  1772. }, {
  1773. .type = DW_HDMI_PHY_DWC_MHL_PHY,
  1774. .name = "DWC MHL PHY",
  1775. .gen = 2,
  1776. .has_svsret = true,
  1777. .configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
  1778. }, {
  1779. .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY_HEAC,
  1780. .name = "DWC HDMI 3D TX PHY + HEAC PHY",
  1781. .gen = 2,
  1782. .configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
  1783. }, {
  1784. .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY,
  1785. .name = "DWC HDMI 3D TX PHY",
  1786. .gen = 2,
  1787. .configure = hdmi_phy_configure_dwc_hdmi_3d_tx,
  1788. }, {
  1789. .type = DW_HDMI_PHY_DWC_HDMI20_TX_PHY,
  1790. .name = "DWC HDMI 2.0 TX PHY",
  1791. .gen = 2,
  1792. .has_svsret = true,
  1793. }, {
  1794. .type = DW_HDMI_PHY_VENDOR_PHY,
  1795. .name = "Vendor PHY",
  1796. }
  1797. };
  1798. static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi)
  1799. {
  1800. unsigned int i;
  1801. u8 phy_type;
  1802. phy_type = hdmi_readb(hdmi, HDMI_CONFIG2_ID);
  1803. if (phy_type == DW_HDMI_PHY_VENDOR_PHY) {
  1804. /* Vendor PHYs require support from the glue layer. */
  1805. if (!hdmi->plat_data->phy_ops || !hdmi->plat_data->phy_name) {
  1806. dev_err(hdmi->dev,
  1807. "Vendor HDMI PHY not supported by glue layer\n");
  1808. return -ENODEV;
  1809. }
  1810. hdmi->phy.ops = hdmi->plat_data->phy_ops;
  1811. hdmi->phy.data = hdmi->plat_data->phy_data;
  1812. hdmi->phy.name = hdmi->plat_data->phy_name;
  1813. return 0;
  1814. }
  1815. /* Synopsys PHYs are handled internally. */
  1816. for (i = 0; i < ARRAY_SIZE(dw_hdmi_phys); ++i) {
  1817. if (dw_hdmi_phys[i].type == phy_type) {
  1818. hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops;
  1819. hdmi->phy.name = dw_hdmi_phys[i].name;
  1820. hdmi->phy.data = (void *)&dw_hdmi_phys[i];
  1821. if (!dw_hdmi_phys[i].configure &&
  1822. !hdmi->plat_data->configure_phy) {
  1823. dev_err(hdmi->dev, "%s requires platform support\n",
  1824. hdmi->phy.name);
  1825. return -ENODEV;
  1826. }
  1827. return 0;
  1828. }
  1829. }
  1830. dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", phy_type);
  1831. return -ENODEV;
  1832. }
  1833. static const struct regmap_config hdmi_regmap_8bit_config = {
  1834. .reg_bits = 32,
  1835. .val_bits = 8,
  1836. .reg_stride = 1,
  1837. .max_register = HDMI_I2CM_FS_SCL_LCNT_0_ADDR,
  1838. };
  1839. static const struct regmap_config hdmi_regmap_32bit_config = {
  1840. .reg_bits = 32,
  1841. .val_bits = 32,
  1842. .reg_stride = 4,
  1843. .max_register = HDMI_I2CM_FS_SCL_LCNT_0_ADDR << 2,
  1844. };
  1845. static struct dw_hdmi *
  1846. __dw_hdmi_probe(struct platform_device *pdev,
  1847. const struct dw_hdmi_plat_data *plat_data)
  1848. {
  1849. struct device *dev = &pdev->dev;
  1850. struct device_node *np = dev->of_node;
  1851. struct platform_device_info pdevinfo;
  1852. struct device_node *ddc_node;
  1853. struct dw_hdmi *hdmi;
  1854. struct resource *iores = NULL;
  1855. int irq;
  1856. int ret;
  1857. u32 val = 1;
  1858. u8 prod_id0;
  1859. u8 prod_id1;
  1860. u8 config0;
  1861. u8 config3;
  1862. hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
  1863. if (!hdmi)
  1864. return ERR_PTR(-ENOMEM);
  1865. hdmi->plat_data = plat_data;
  1866. hdmi->dev = dev;
  1867. hdmi->sample_rate = 48000;
  1868. hdmi->disabled = true;
  1869. hdmi->rxsense = true;
  1870. hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE);
  1871. mutex_init(&hdmi->mutex);
  1872. mutex_init(&hdmi->audio_mutex);
  1873. spin_lock_init(&hdmi->audio_lock);
  1874. ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0);
  1875. if (ddc_node) {
  1876. hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node);
  1877. of_node_put(ddc_node);
  1878. if (!hdmi->ddc) {
  1879. dev_dbg(hdmi->dev, "failed to read ddc node\n");
  1880. return ERR_PTR(-EPROBE_DEFER);
  1881. }
  1882. } else {
  1883. dev_dbg(hdmi->dev, "no ddc property found\n");
  1884. }
  1885. if (!plat_data->regm) {
  1886. const struct regmap_config *reg_config;
  1887. of_property_read_u32(np, "reg-io-width", &val);
  1888. switch (val) {
  1889. case 4:
  1890. reg_config = &hdmi_regmap_32bit_config;
  1891. hdmi->reg_shift = 2;
  1892. break;
  1893. case 1:
  1894. reg_config = &hdmi_regmap_8bit_config;
  1895. break;
  1896. default:
  1897. dev_err(dev, "reg-io-width must be 1 or 4\n");
  1898. return ERR_PTR(-EINVAL);
  1899. }
  1900. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1901. hdmi->regs = devm_ioremap_resource(dev, iores);
  1902. if (IS_ERR(hdmi->regs)) {
  1903. ret = PTR_ERR(hdmi->regs);
  1904. goto err_res;
  1905. }
  1906. hdmi->regm = devm_regmap_init_mmio(dev, hdmi->regs, reg_config);
  1907. if (IS_ERR(hdmi->regm)) {
  1908. dev_err(dev, "Failed to configure regmap\n");
  1909. ret = PTR_ERR(hdmi->regm);
  1910. goto err_res;
  1911. }
  1912. } else {
  1913. hdmi->regm = plat_data->regm;
  1914. }
  1915. hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr");
  1916. if (IS_ERR(hdmi->isfr_clk)) {
  1917. ret = PTR_ERR(hdmi->isfr_clk);
  1918. dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret);
  1919. goto err_res;
  1920. }
  1921. ret = clk_prepare_enable(hdmi->isfr_clk);
  1922. if (ret) {
  1923. dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret);
  1924. goto err_res;
  1925. }
  1926. hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb");
  1927. if (IS_ERR(hdmi->iahb_clk)) {
  1928. ret = PTR_ERR(hdmi->iahb_clk);
  1929. dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret);
  1930. goto err_isfr;
  1931. }
  1932. ret = clk_prepare_enable(hdmi->iahb_clk);
  1933. if (ret) {
  1934. dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret);
  1935. goto err_isfr;
  1936. }
  1937. /* Product and revision IDs */
  1938. hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8)
  1939. | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0);
  1940. prod_id0 = hdmi_readb(hdmi, HDMI_PRODUCT_ID0);
  1941. prod_id1 = hdmi_readb(hdmi, HDMI_PRODUCT_ID1);
  1942. if (prod_id0 != HDMI_PRODUCT_ID0_HDMI_TX ||
  1943. (prod_id1 & ~HDMI_PRODUCT_ID1_HDCP) != HDMI_PRODUCT_ID1_HDMI_TX) {
  1944. dev_err(dev, "Unsupported HDMI controller (%04x:%02x:%02x)\n",
  1945. hdmi->version, prod_id0, prod_id1);
  1946. ret = -ENODEV;
  1947. goto err_iahb;
  1948. }
  1949. ret = dw_hdmi_detect_phy(hdmi);
  1950. if (ret < 0)
  1951. goto err_iahb;
  1952. dev_info(dev, "Detected HDMI TX controller v%x.%03x %s HDCP (%s)\n",
  1953. hdmi->version >> 12, hdmi->version & 0xfff,
  1954. prod_id1 & HDMI_PRODUCT_ID1_HDCP ? "with" : "without",
  1955. hdmi->phy.name);
  1956. initialize_hdmi_ih_mutes(hdmi);
  1957. irq = platform_get_irq(pdev, 0);
  1958. if (irq < 0) {
  1959. ret = irq;
  1960. goto err_iahb;
  1961. }
  1962. ret = devm_request_threaded_irq(dev, irq, dw_hdmi_hardirq,
  1963. dw_hdmi_irq, IRQF_SHARED,
  1964. dev_name(dev), hdmi);
  1965. if (ret)
  1966. goto err_iahb;
  1967. /*
  1968. * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
  1969. * N and cts values before enabling phy
  1970. */
  1971. hdmi_init_clk_regenerator(hdmi);
  1972. /* If DDC bus is not specified, try to register HDMI I2C bus */
  1973. if (!hdmi->ddc) {
  1974. hdmi->ddc = dw_hdmi_i2c_adapter(hdmi);
  1975. if (IS_ERR(hdmi->ddc))
  1976. hdmi->ddc = NULL;
  1977. }
  1978. hdmi->bridge.driver_private = hdmi;
  1979. hdmi->bridge.funcs = &dw_hdmi_bridge_funcs;
  1980. #ifdef CONFIG_OF
  1981. hdmi->bridge.of_node = pdev->dev.of_node;
  1982. #endif
  1983. dw_hdmi_setup_i2c(hdmi);
  1984. if (hdmi->phy.ops->setup_hpd)
  1985. hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data);
  1986. memset(&pdevinfo, 0, sizeof(pdevinfo));
  1987. pdevinfo.parent = dev;
  1988. pdevinfo.id = PLATFORM_DEVID_AUTO;
  1989. config0 = hdmi_readb(hdmi, HDMI_CONFIG0_ID);
  1990. config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID);
  1991. if (iores && config3 & HDMI_CONFIG3_AHBAUDDMA) {
  1992. struct dw_hdmi_audio_data audio;
  1993. audio.phys = iores->start;
  1994. audio.base = hdmi->regs;
  1995. audio.irq = irq;
  1996. audio.hdmi = hdmi;
  1997. audio.eld = hdmi->connector.eld;
  1998. pdevinfo.name = "dw-hdmi-ahb-audio";
  1999. pdevinfo.data = &audio;
  2000. pdevinfo.size_data = sizeof(audio);
  2001. pdevinfo.dma_mask = DMA_BIT_MASK(32);
  2002. hdmi->audio = platform_device_register_full(&pdevinfo);
  2003. } else if (config0 & HDMI_CONFIG0_I2S) {
  2004. struct dw_hdmi_i2s_audio_data audio;
  2005. audio.hdmi = hdmi;
  2006. audio.write = hdmi_writeb;
  2007. audio.read = hdmi_readb;
  2008. pdevinfo.name = "dw-hdmi-i2s-audio";
  2009. pdevinfo.data = &audio;
  2010. pdevinfo.size_data = sizeof(audio);
  2011. pdevinfo.dma_mask = DMA_BIT_MASK(32);
  2012. hdmi->audio = platform_device_register_full(&pdevinfo);
  2013. }
  2014. /* Reset HDMI DDC I2C master controller and mute I2CM interrupts */
  2015. if (hdmi->i2c)
  2016. dw_hdmi_i2c_init(hdmi);
  2017. platform_set_drvdata(pdev, hdmi);
  2018. return hdmi;
  2019. err_iahb:
  2020. if (hdmi->i2c) {
  2021. i2c_del_adapter(&hdmi->i2c->adap);
  2022. hdmi->ddc = NULL;
  2023. }
  2024. clk_disable_unprepare(hdmi->iahb_clk);
  2025. err_isfr:
  2026. clk_disable_unprepare(hdmi->isfr_clk);
  2027. err_res:
  2028. i2c_put_adapter(hdmi->ddc);
  2029. return ERR_PTR(ret);
  2030. }
  2031. static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
  2032. {
  2033. if (hdmi->audio && !IS_ERR(hdmi->audio))
  2034. platform_device_unregister(hdmi->audio);
  2035. /* Disable all interrupts */
  2036. hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
  2037. clk_disable_unprepare(hdmi->iahb_clk);
  2038. clk_disable_unprepare(hdmi->isfr_clk);
  2039. if (hdmi->i2c)
  2040. i2c_del_adapter(&hdmi->i2c->adap);
  2041. else
  2042. i2c_put_adapter(hdmi->ddc);
  2043. }
  2044. /* -----------------------------------------------------------------------------
  2045. * Probe/remove API, used from platforms based on the DRM bridge API.
  2046. */
  2047. int dw_hdmi_probe(struct platform_device *pdev,
  2048. const struct dw_hdmi_plat_data *plat_data)
  2049. {
  2050. struct dw_hdmi *hdmi;
  2051. int ret;
  2052. hdmi = __dw_hdmi_probe(pdev, plat_data);
  2053. if (IS_ERR(hdmi))
  2054. return PTR_ERR(hdmi);
  2055. ret = drm_bridge_add(&hdmi->bridge);
  2056. if (ret < 0) {
  2057. __dw_hdmi_remove(hdmi);
  2058. return ret;
  2059. }
  2060. return 0;
  2061. }
  2062. EXPORT_SYMBOL_GPL(dw_hdmi_probe);
  2063. void dw_hdmi_remove(struct platform_device *pdev)
  2064. {
  2065. struct dw_hdmi *hdmi = platform_get_drvdata(pdev);
  2066. drm_bridge_remove(&hdmi->bridge);
  2067. __dw_hdmi_remove(hdmi);
  2068. }
  2069. EXPORT_SYMBOL_GPL(dw_hdmi_remove);
  2070. /* -----------------------------------------------------------------------------
  2071. * Bind/unbind API, used from platforms based on the component framework.
  2072. */
  2073. int dw_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
  2074. const struct dw_hdmi_plat_data *plat_data)
  2075. {
  2076. struct dw_hdmi *hdmi;
  2077. int ret;
  2078. hdmi = __dw_hdmi_probe(pdev, plat_data);
  2079. if (IS_ERR(hdmi))
  2080. return PTR_ERR(hdmi);
  2081. ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL);
  2082. if (ret) {
  2083. dw_hdmi_remove(pdev);
  2084. DRM_ERROR("Failed to initialize bridge with drm\n");
  2085. return ret;
  2086. }
  2087. return 0;
  2088. }
  2089. EXPORT_SYMBOL_GPL(dw_hdmi_bind);
  2090. void dw_hdmi_unbind(struct device *dev)
  2091. {
  2092. struct dw_hdmi *hdmi = dev_get_drvdata(dev);
  2093. __dw_hdmi_remove(hdmi);
  2094. }
  2095. EXPORT_SYMBOL_GPL(dw_hdmi_unbind);
  2096. MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
  2097. MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
  2098. MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
  2099. MODULE_AUTHOR("Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>");
  2100. MODULE_DESCRIPTION("DW HDMI transmitter driver");
  2101. MODULE_LICENSE("GPL");
  2102. MODULE_ALIAS("platform:dw-hdmi");