intel_sdvo.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966
  1. /*
  2. * Copyright 2006 Dave Airlie <airlied@linux.ie>
  3. * Copyright © 2006-2007 Intel Corporation
  4. * Jesse Barnes <jesse.barnes@intel.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. * Authors:
  26. * Eric Anholt <eric@anholt.net>
  27. */
  28. #include <linux/i2c.h>
  29. #include <linux/slab.h>
  30. #include <linux/delay.h>
  31. #include <linux/export.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm_crtc.h>
  34. #include <drm/drm_edid.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "intel_sdvo_regs.h"
  39. #define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)
  40. #define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1)
  41. #define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1)
  42. #define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_YPRPB0)
  43. #define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\
  44. SDVO_TV_MASK)
  45. #define IS_TV(c) (c->output_flag & SDVO_TV_MASK)
  46. #define IS_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
  47. #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
  48. #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
  49. #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
  50. static const char *tv_format_names[] = {
  51. "NTSC_M" , "NTSC_J" , "NTSC_443",
  52. "PAL_B" , "PAL_D" , "PAL_G" ,
  53. "PAL_H" , "PAL_I" , "PAL_M" ,
  54. "PAL_N" , "PAL_NC" , "PAL_60" ,
  55. "SECAM_B" , "SECAM_D" , "SECAM_G" ,
  56. "SECAM_K" , "SECAM_K1", "SECAM_L" ,
  57. "SECAM_60"
  58. };
  59. #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
  60. struct intel_sdvo {
  61. struct intel_encoder base;
  62. struct i2c_adapter *i2c;
  63. u8 slave_addr;
  64. struct i2c_adapter ddc;
  65. /* Register for the SDVO device: SDVOB or SDVOC */
  66. uint32_t sdvo_reg;
  67. /* Active outputs controlled by this SDVO output */
  68. uint16_t controlled_output;
  69. /*
  70. * Capabilities of the SDVO device returned by
  71. * intel_sdvo_get_capabilities()
  72. */
  73. struct intel_sdvo_caps caps;
  74. /* Pixel clock limitations reported by the SDVO device, in kHz */
  75. int pixel_clock_min, pixel_clock_max;
  76. /*
  77. * For multiple function SDVO device,
  78. * this is for current attached outputs.
  79. */
  80. uint16_t attached_output;
  81. /*
  82. * Hotplug activation bits for this device
  83. */
  84. uint16_t hotplug_active;
  85. /**
  86. * This is used to select the color range of RBG outputs in HDMI mode.
  87. * It is only valid when using TMDS encoding and 8 bit per color mode.
  88. */
  89. uint32_t color_range;
  90. bool color_range_auto;
  91. /**
  92. * This is set if we're going to treat the device as TV-out.
  93. *
  94. * While we have these nice friendly flags for output types that ought
  95. * to decide this for us, the S-Video output on our HDMI+S-Video card
  96. * shows up as RGB1 (VGA).
  97. */
  98. bool is_tv;
  99. /* On different gens SDVOB is at different places. */
  100. bool is_sdvob;
  101. /* This is for current tv format name */
  102. int tv_format_index;
  103. /**
  104. * This is set if we treat the device as HDMI, instead of DVI.
  105. */
  106. bool is_hdmi;
  107. bool has_hdmi_monitor;
  108. bool has_hdmi_audio;
  109. bool rgb_quant_range_selectable;
  110. /**
  111. * This is set if we detect output of sdvo device as LVDS and
  112. * have a valid fixed mode to use with the panel.
  113. */
  114. bool is_lvds;
  115. /**
  116. * This is sdvo fixed pannel mode pointer
  117. */
  118. struct drm_display_mode *sdvo_lvds_fixed_mode;
  119. /* DDC bus used by this SDVO encoder */
  120. uint8_t ddc_bus;
  121. /*
  122. * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
  123. */
  124. uint8_t dtd_sdvo_flags;
  125. };
  126. struct intel_sdvo_connector {
  127. struct intel_connector base;
  128. /* Mark the type of connector */
  129. uint16_t output_flag;
  130. enum hdmi_force_audio force_audio;
  131. /* This contains all current supported TV format */
  132. u8 tv_format_supported[TV_FORMAT_NUM];
  133. int format_supported_num;
  134. struct drm_property *tv_format;
  135. /* add the property for the SDVO-TV */
  136. struct drm_property *left;
  137. struct drm_property *right;
  138. struct drm_property *top;
  139. struct drm_property *bottom;
  140. struct drm_property *hpos;
  141. struct drm_property *vpos;
  142. struct drm_property *contrast;
  143. struct drm_property *saturation;
  144. struct drm_property *hue;
  145. struct drm_property *sharpness;
  146. struct drm_property *flicker_filter;
  147. struct drm_property *flicker_filter_adaptive;
  148. struct drm_property *flicker_filter_2d;
  149. struct drm_property *tv_chroma_filter;
  150. struct drm_property *tv_luma_filter;
  151. struct drm_property *dot_crawl;
  152. /* add the property for the SDVO-TV/LVDS */
  153. struct drm_property *brightness;
  154. /* Add variable to record current setting for the above property */
  155. u32 left_margin, right_margin, top_margin, bottom_margin;
  156. /* this is to get the range of margin.*/
  157. u32 max_hscan, max_vscan;
  158. u32 max_hpos, cur_hpos;
  159. u32 max_vpos, cur_vpos;
  160. u32 cur_brightness, max_brightness;
  161. u32 cur_contrast, max_contrast;
  162. u32 cur_saturation, max_saturation;
  163. u32 cur_hue, max_hue;
  164. u32 cur_sharpness, max_sharpness;
  165. u32 cur_flicker_filter, max_flicker_filter;
  166. u32 cur_flicker_filter_adaptive, max_flicker_filter_adaptive;
  167. u32 cur_flicker_filter_2d, max_flicker_filter_2d;
  168. u32 cur_tv_chroma_filter, max_tv_chroma_filter;
  169. u32 cur_tv_luma_filter, max_tv_luma_filter;
  170. u32 cur_dot_crawl, max_dot_crawl;
  171. };
  172. static struct intel_sdvo *to_intel_sdvo(struct drm_encoder *encoder)
  173. {
  174. return container_of(encoder, struct intel_sdvo, base.base);
  175. }
  176. static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
  177. {
  178. return container_of(intel_attached_encoder(connector),
  179. struct intel_sdvo, base);
  180. }
  181. static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector)
  182. {
  183. return container_of(to_intel_connector(connector), struct intel_sdvo_connector, base);
  184. }
  185. static bool
  186. intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags);
  187. static bool
  188. intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
  189. struct intel_sdvo_connector *intel_sdvo_connector,
  190. int type);
  191. static bool
  192. intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
  193. struct intel_sdvo_connector *intel_sdvo_connector);
  194. /**
  195. * Writes the SDVOB or SDVOC with the given value, but always writes both
  196. * SDVOB and SDVOC to work around apparent hardware issues (according to
  197. * comments in the BIOS).
  198. */
  199. static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
  200. {
  201. struct drm_device *dev = intel_sdvo->base.base.dev;
  202. struct drm_i915_private *dev_priv = dev->dev_private;
  203. u32 bval = val, cval = val;
  204. int i;
  205. if (intel_sdvo->sdvo_reg == PCH_SDVOB) {
  206. I915_WRITE(intel_sdvo->sdvo_reg, val);
  207. I915_READ(intel_sdvo->sdvo_reg);
  208. return;
  209. }
  210. if (intel_sdvo->sdvo_reg == GEN3_SDVOB)
  211. cval = I915_READ(GEN3_SDVOC);
  212. else
  213. bval = I915_READ(GEN3_SDVOB);
  214. /*
  215. * Write the registers twice for luck. Sometimes,
  216. * writing them only once doesn't appear to 'stick'.
  217. * The BIOS does this too. Yay, magic
  218. */
  219. for (i = 0; i < 2; i++)
  220. {
  221. I915_WRITE(GEN3_SDVOB, bval);
  222. I915_READ(GEN3_SDVOB);
  223. I915_WRITE(GEN3_SDVOC, cval);
  224. I915_READ(GEN3_SDVOC);
  225. }
  226. }
  227. static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
  228. {
  229. struct i2c_msg msgs[] = {
  230. {
  231. .addr = intel_sdvo->slave_addr,
  232. .flags = 0,
  233. .len = 1,
  234. .buf = &addr,
  235. },
  236. {
  237. .addr = intel_sdvo->slave_addr,
  238. .flags = I2C_M_RD,
  239. .len = 1,
  240. .buf = ch,
  241. }
  242. };
  243. int ret;
  244. if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
  245. return true;
  246. DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
  247. return false;
  248. }
  249. #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
  250. /** Mapping of command numbers to names, for debug output */
  251. static const struct _sdvo_cmd_name {
  252. u8 cmd;
  253. const char *name;
  254. } sdvo_cmd_names[] = {
  255. SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
  256. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
  257. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
  258. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
  259. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
  260. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
  261. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
  262. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
  263. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
  264. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
  265. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
  266. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
  267. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
  268. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
  269. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
  270. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
  271. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
  272. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  273. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
  274. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  275. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
  276. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
  277. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
  278. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
  279. SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
  280. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
  281. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
  282. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
  283. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
  284. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
  285. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
  286. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
  287. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
  288. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
  289. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
  290. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
  291. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
  292. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
  293. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
  294. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
  295. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
  296. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
  297. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
  298. /* Add the op code for SDVO enhancements */
  299. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS),
  300. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS),
  301. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS),
  302. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS),
  303. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS),
  304. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS),
  305. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
  306. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
  307. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
  308. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
  309. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
  310. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
  311. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
  312. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
  313. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
  314. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
  315. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
  316. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
  317. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
  318. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
  319. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
  320. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
  321. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
  322. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
  323. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER),
  324. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER),
  325. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER),
  326. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE),
  327. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE),
  328. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE),
  329. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D),
  330. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D),
  331. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D),
  332. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS),
  333. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS),
  334. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS),
  335. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL),
  336. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL),
  337. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER),
  338. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER),
  339. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER),
  340. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER),
  341. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER),
  342. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER),
  343. /* HDMI op code */
  344. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
  345. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
  346. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
  347. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
  348. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
  349. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
  350. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
  351. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
  352. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
  353. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
  354. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
  355. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
  356. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
  357. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
  358. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
  359. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
  360. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
  361. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
  362. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
  363. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
  364. };
  365. #define SDVO_NAME(svdo) ((svdo)->is_sdvob ? "SDVOB" : "SDVOC")
  366. static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
  367. const void *args, int args_len)
  368. {
  369. int i;
  370. DRM_DEBUG_KMS("%s: W: %02X ",
  371. SDVO_NAME(intel_sdvo), cmd);
  372. for (i = 0; i < args_len; i++)
  373. DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
  374. for (; i < 8; i++)
  375. DRM_LOG_KMS(" ");
  376. for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
  377. if (cmd == sdvo_cmd_names[i].cmd) {
  378. DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
  379. break;
  380. }
  381. }
  382. if (i == ARRAY_SIZE(sdvo_cmd_names))
  383. DRM_LOG_KMS("(%02X)", cmd);
  384. DRM_LOG_KMS("\n");
  385. }
  386. static const char *cmd_status_names[] = {
  387. "Power on",
  388. "Success",
  389. "Not supported",
  390. "Invalid arg",
  391. "Pending",
  392. "Target not specified",
  393. "Scaling not supported"
  394. };
  395. static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
  396. const void *args, int args_len)
  397. {
  398. u8 *buf, status;
  399. struct i2c_msg *msgs;
  400. int i, ret = true;
  401. /* Would be simpler to allocate both in one go ? */
  402. buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
  403. if (!buf)
  404. return false;
  405. msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
  406. if (!msgs) {
  407. kfree(buf);
  408. return false;
  409. }
  410. intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
  411. for (i = 0; i < args_len; i++) {
  412. msgs[i].addr = intel_sdvo->slave_addr;
  413. msgs[i].flags = 0;
  414. msgs[i].len = 2;
  415. msgs[i].buf = buf + 2 *i;
  416. buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
  417. buf[2*i + 1] = ((u8*)args)[i];
  418. }
  419. msgs[i].addr = intel_sdvo->slave_addr;
  420. msgs[i].flags = 0;
  421. msgs[i].len = 2;
  422. msgs[i].buf = buf + 2*i;
  423. buf[2*i + 0] = SDVO_I2C_OPCODE;
  424. buf[2*i + 1] = cmd;
  425. /* the following two are to read the response */
  426. status = SDVO_I2C_CMD_STATUS;
  427. msgs[i+1].addr = intel_sdvo->slave_addr;
  428. msgs[i+1].flags = 0;
  429. msgs[i+1].len = 1;
  430. msgs[i+1].buf = &status;
  431. msgs[i+2].addr = intel_sdvo->slave_addr;
  432. msgs[i+2].flags = I2C_M_RD;
  433. msgs[i+2].len = 1;
  434. msgs[i+2].buf = &status;
  435. ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
  436. if (ret < 0) {
  437. DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
  438. ret = false;
  439. goto out;
  440. }
  441. if (ret != i+3) {
  442. /* failure in I2C transfer */
  443. DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
  444. ret = false;
  445. }
  446. out:
  447. kfree(msgs);
  448. kfree(buf);
  449. return ret;
  450. }
  451. static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
  452. void *response, int response_len)
  453. {
  454. u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
  455. u8 status;
  456. int i;
  457. DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
  458. /*
  459. * The documentation states that all commands will be
  460. * processed within 15µs, and that we need only poll
  461. * the status byte a maximum of 3 times in order for the
  462. * command to be complete.
  463. *
  464. * Check 5 times in case the hardware failed to read the docs.
  465. *
  466. * Also beware that the first response by many devices is to
  467. * reply PENDING and stall for time. TVs are notorious for
  468. * requiring longer than specified to complete their replies.
  469. * Originally (in the DDX long ago), the delay was only ever 15ms
  470. * with an additional delay of 30ms applied for TVs added later after
  471. * many experiments. To accommodate both sets of delays, we do a
  472. * sequence of slow checks if the device is falling behind and fails
  473. * to reply within 5*15µs.
  474. */
  475. if (!intel_sdvo_read_byte(intel_sdvo,
  476. SDVO_I2C_CMD_STATUS,
  477. &status))
  478. goto log_fail;
  479. while (status == SDVO_CMD_STATUS_PENDING && --retry) {
  480. if (retry < 10)
  481. msleep(15);
  482. else
  483. udelay(15);
  484. if (!intel_sdvo_read_byte(intel_sdvo,
  485. SDVO_I2C_CMD_STATUS,
  486. &status))
  487. goto log_fail;
  488. }
  489. if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
  490. DRM_LOG_KMS("(%s)", cmd_status_names[status]);
  491. else
  492. DRM_LOG_KMS("(??? %d)", status);
  493. if (status != SDVO_CMD_STATUS_SUCCESS)
  494. goto log_fail;
  495. /* Read the command response */
  496. for (i = 0; i < response_len; i++) {
  497. if (!intel_sdvo_read_byte(intel_sdvo,
  498. SDVO_I2C_RETURN_0 + i,
  499. &((u8 *)response)[i]))
  500. goto log_fail;
  501. DRM_LOG_KMS(" %02X", ((u8 *)response)[i]);
  502. }
  503. DRM_LOG_KMS("\n");
  504. return true;
  505. log_fail:
  506. DRM_LOG_KMS("... failed\n");
  507. return false;
  508. }
  509. static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
  510. {
  511. if (mode->clock >= 100000)
  512. return 1;
  513. else if (mode->clock >= 50000)
  514. return 2;
  515. else
  516. return 4;
  517. }
  518. static bool intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
  519. u8 ddc_bus)
  520. {
  521. /* This must be the immediately preceding write before the i2c xfer */
  522. return intel_sdvo_write_cmd(intel_sdvo,
  523. SDVO_CMD_SET_CONTROL_BUS_SWITCH,
  524. &ddc_bus, 1);
  525. }
  526. static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
  527. {
  528. if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
  529. return false;
  530. return intel_sdvo_read_response(intel_sdvo, NULL, 0);
  531. }
  532. static bool
  533. intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
  534. {
  535. if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
  536. return false;
  537. return intel_sdvo_read_response(intel_sdvo, value, len);
  538. }
  539. static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
  540. {
  541. struct intel_sdvo_set_target_input_args targets = {0};
  542. return intel_sdvo_set_value(intel_sdvo,
  543. SDVO_CMD_SET_TARGET_INPUT,
  544. &targets, sizeof(targets));
  545. }
  546. /**
  547. * Return whether each input is trained.
  548. *
  549. * This function is making an assumption about the layout of the response,
  550. * which should be checked against the docs.
  551. */
  552. static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
  553. {
  554. struct intel_sdvo_get_trained_inputs_response response;
  555. BUILD_BUG_ON(sizeof(response) != 1);
  556. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
  557. &response, sizeof(response)))
  558. return false;
  559. *input_1 = response.input0_trained;
  560. *input_2 = response.input1_trained;
  561. return true;
  562. }
  563. static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
  564. u16 outputs)
  565. {
  566. return intel_sdvo_set_value(intel_sdvo,
  567. SDVO_CMD_SET_ACTIVE_OUTPUTS,
  568. &outputs, sizeof(outputs));
  569. }
  570. static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
  571. u16 *outputs)
  572. {
  573. return intel_sdvo_get_value(intel_sdvo,
  574. SDVO_CMD_GET_ACTIVE_OUTPUTS,
  575. outputs, sizeof(*outputs));
  576. }
  577. static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
  578. int mode)
  579. {
  580. u8 state = SDVO_ENCODER_STATE_ON;
  581. switch (mode) {
  582. case DRM_MODE_DPMS_ON:
  583. state = SDVO_ENCODER_STATE_ON;
  584. break;
  585. case DRM_MODE_DPMS_STANDBY:
  586. state = SDVO_ENCODER_STATE_STANDBY;
  587. break;
  588. case DRM_MODE_DPMS_SUSPEND:
  589. state = SDVO_ENCODER_STATE_SUSPEND;
  590. break;
  591. case DRM_MODE_DPMS_OFF:
  592. state = SDVO_ENCODER_STATE_OFF;
  593. break;
  594. }
  595. return intel_sdvo_set_value(intel_sdvo,
  596. SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
  597. }
  598. static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
  599. int *clock_min,
  600. int *clock_max)
  601. {
  602. struct intel_sdvo_pixel_clock_range clocks;
  603. BUILD_BUG_ON(sizeof(clocks) != 4);
  604. if (!intel_sdvo_get_value(intel_sdvo,
  605. SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
  606. &clocks, sizeof(clocks)))
  607. return false;
  608. /* Convert the values from units of 10 kHz to kHz. */
  609. *clock_min = clocks.min * 10;
  610. *clock_max = clocks.max * 10;
  611. return true;
  612. }
  613. static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
  614. u16 outputs)
  615. {
  616. return intel_sdvo_set_value(intel_sdvo,
  617. SDVO_CMD_SET_TARGET_OUTPUT,
  618. &outputs, sizeof(outputs));
  619. }
  620. static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
  621. struct intel_sdvo_dtd *dtd)
  622. {
  623. return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
  624. intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  625. }
  626. static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
  627. struct intel_sdvo_dtd *dtd)
  628. {
  629. return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
  630. intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  631. }
  632. static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
  633. struct intel_sdvo_dtd *dtd)
  634. {
  635. return intel_sdvo_set_timing(intel_sdvo,
  636. SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
  637. }
  638. static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
  639. struct intel_sdvo_dtd *dtd)
  640. {
  641. return intel_sdvo_set_timing(intel_sdvo,
  642. SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
  643. }
  644. static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
  645. struct intel_sdvo_dtd *dtd)
  646. {
  647. return intel_sdvo_get_timing(intel_sdvo,
  648. SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
  649. }
  650. static bool
  651. intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
  652. uint16_t clock,
  653. uint16_t width,
  654. uint16_t height)
  655. {
  656. struct intel_sdvo_preferred_input_timing_args args;
  657. memset(&args, 0, sizeof(args));
  658. args.clock = clock;
  659. args.width = width;
  660. args.height = height;
  661. args.interlace = 0;
  662. if (intel_sdvo->is_lvds &&
  663. (intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width ||
  664. intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height))
  665. args.scaled = 1;
  666. return intel_sdvo_set_value(intel_sdvo,
  667. SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
  668. &args, sizeof(args));
  669. }
  670. static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
  671. struct intel_sdvo_dtd *dtd)
  672. {
  673. BUILD_BUG_ON(sizeof(dtd->part1) != 8);
  674. BUILD_BUG_ON(sizeof(dtd->part2) != 8);
  675. return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
  676. &dtd->part1, sizeof(dtd->part1)) &&
  677. intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
  678. &dtd->part2, sizeof(dtd->part2));
  679. }
  680. static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
  681. {
  682. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
  683. }
  684. static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
  685. const struct drm_display_mode *mode)
  686. {
  687. uint16_t width, height;
  688. uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
  689. uint16_t h_sync_offset, v_sync_offset;
  690. int mode_clock;
  691. width = mode->hdisplay;
  692. height = mode->vdisplay;
  693. /* do some mode translations */
  694. h_blank_len = mode->htotal - mode->hdisplay;
  695. h_sync_len = mode->hsync_end - mode->hsync_start;
  696. v_blank_len = mode->vtotal - mode->vdisplay;
  697. v_sync_len = mode->vsync_end - mode->vsync_start;
  698. h_sync_offset = mode->hsync_start - mode->hdisplay;
  699. v_sync_offset = mode->vsync_start - mode->vdisplay;
  700. mode_clock = mode->clock;
  701. mode_clock /= 10;
  702. dtd->part1.clock = mode_clock;
  703. dtd->part1.h_active = width & 0xff;
  704. dtd->part1.h_blank = h_blank_len & 0xff;
  705. dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
  706. ((h_blank_len >> 8) & 0xf);
  707. dtd->part1.v_active = height & 0xff;
  708. dtd->part1.v_blank = v_blank_len & 0xff;
  709. dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
  710. ((v_blank_len >> 8) & 0xf);
  711. dtd->part2.h_sync_off = h_sync_offset & 0xff;
  712. dtd->part2.h_sync_width = h_sync_len & 0xff;
  713. dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
  714. (v_sync_len & 0xf);
  715. dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
  716. ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
  717. ((v_sync_len & 0x30) >> 4);
  718. dtd->part2.dtd_flags = 0x18;
  719. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  720. dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
  721. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  722. dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
  723. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  724. dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
  725. dtd->part2.sdvo_flags = 0;
  726. dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
  727. dtd->part2.reserved = 0;
  728. }
  729. static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
  730. const struct intel_sdvo_dtd *dtd)
  731. {
  732. mode->hdisplay = dtd->part1.h_active;
  733. mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
  734. mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
  735. mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
  736. mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
  737. mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
  738. mode->htotal = mode->hdisplay + dtd->part1.h_blank;
  739. mode->htotal += (dtd->part1.h_high & 0xf) << 8;
  740. mode->vdisplay = dtd->part1.v_active;
  741. mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
  742. mode->vsync_start = mode->vdisplay;
  743. mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
  744. mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
  745. mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
  746. mode->vsync_end = mode->vsync_start +
  747. (dtd->part2.v_sync_off_width & 0xf);
  748. mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
  749. mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
  750. mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
  751. mode->clock = dtd->part1.clock * 10;
  752. mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
  753. if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
  754. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  755. if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
  756. mode->flags |= DRM_MODE_FLAG_PHSYNC;
  757. if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
  758. mode->flags |= DRM_MODE_FLAG_PVSYNC;
  759. }
  760. static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
  761. {
  762. struct intel_sdvo_encode encode;
  763. BUILD_BUG_ON(sizeof(encode) != 2);
  764. return intel_sdvo_get_value(intel_sdvo,
  765. SDVO_CMD_GET_SUPP_ENCODE,
  766. &encode, sizeof(encode));
  767. }
  768. static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
  769. uint8_t mode)
  770. {
  771. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
  772. }
  773. static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
  774. uint8_t mode)
  775. {
  776. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
  777. }
  778. #if 0
  779. static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
  780. {
  781. int i, j;
  782. uint8_t set_buf_index[2];
  783. uint8_t av_split;
  784. uint8_t buf_size;
  785. uint8_t buf[48];
  786. uint8_t *pos;
  787. intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
  788. for (i = 0; i <= av_split; i++) {
  789. set_buf_index[0] = i; set_buf_index[1] = 0;
  790. intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
  791. set_buf_index, 2);
  792. intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
  793. intel_sdvo_read_response(encoder, &buf_size, 1);
  794. pos = buf;
  795. for (j = 0; j <= buf_size; j += 8) {
  796. intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
  797. NULL, 0);
  798. intel_sdvo_read_response(encoder, pos, 8);
  799. pos += 8;
  800. }
  801. }
  802. }
  803. #endif
  804. static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
  805. unsigned if_index, uint8_t tx_rate,
  806. uint8_t *data, unsigned length)
  807. {
  808. uint8_t set_buf_index[2] = { if_index, 0 };
  809. uint8_t hbuf_size, tmp[8];
  810. int i;
  811. if (!intel_sdvo_set_value(intel_sdvo,
  812. SDVO_CMD_SET_HBUF_INDEX,
  813. set_buf_index, 2))
  814. return false;
  815. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
  816. &hbuf_size, 1))
  817. return false;
  818. /* Buffer size is 0 based, hooray! */
  819. hbuf_size++;
  820. DRM_DEBUG_KMS("writing sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
  821. if_index, length, hbuf_size);
  822. for (i = 0; i < hbuf_size; i += 8) {
  823. memset(tmp, 0, 8);
  824. if (i < length)
  825. memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
  826. if (!intel_sdvo_set_value(intel_sdvo,
  827. SDVO_CMD_SET_HBUF_DATA,
  828. tmp, 8))
  829. return false;
  830. }
  831. return intel_sdvo_set_value(intel_sdvo,
  832. SDVO_CMD_SET_HBUF_TXRATE,
  833. &tx_rate, 1);
  834. }
  835. static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
  836. const struct drm_display_mode *adjusted_mode)
  837. {
  838. struct dip_infoframe avi_if = {
  839. .type = DIP_TYPE_AVI,
  840. .ver = DIP_VERSION_AVI,
  841. .len = DIP_LEN_AVI,
  842. };
  843. uint8_t sdvo_data[4 + sizeof(avi_if.body.avi)];
  844. struct intel_crtc *intel_crtc = to_intel_crtc(intel_sdvo->base.base.crtc);
  845. if (intel_sdvo->rgb_quant_range_selectable) {
  846. if (intel_crtc->config.limited_color_range)
  847. avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
  848. else
  849. avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
  850. }
  851. avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
  852. intel_dip_infoframe_csum(&avi_if);
  853. /* sdvo spec says that the ecc is handled by the hw, and it looks like
  854. * we must not send the ecc field, either. */
  855. memcpy(sdvo_data, &avi_if, 3);
  856. sdvo_data[3] = avi_if.checksum;
  857. memcpy(&sdvo_data[4], &avi_if.body, sizeof(avi_if.body.avi));
  858. return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
  859. SDVO_HBUF_TX_VSYNC,
  860. sdvo_data, sizeof(sdvo_data));
  861. }
  862. static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo)
  863. {
  864. struct intel_sdvo_tv_format format;
  865. uint32_t format_map;
  866. format_map = 1 << intel_sdvo->tv_format_index;
  867. memset(&format, 0, sizeof(format));
  868. memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
  869. BUILD_BUG_ON(sizeof(format) != 6);
  870. return intel_sdvo_set_value(intel_sdvo,
  871. SDVO_CMD_SET_TV_FORMAT,
  872. &format, sizeof(format));
  873. }
  874. static bool
  875. intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
  876. const struct drm_display_mode *mode)
  877. {
  878. struct intel_sdvo_dtd output_dtd;
  879. if (!intel_sdvo_set_target_output(intel_sdvo,
  880. intel_sdvo->attached_output))
  881. return false;
  882. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  883. if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
  884. return false;
  885. return true;
  886. }
  887. /* Asks the sdvo controller for the preferred input mode given the output mode.
  888. * Unfortunately we have to set up the full output mode to do that. */
  889. static bool
  890. intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
  891. const struct drm_display_mode *mode,
  892. struct drm_display_mode *adjusted_mode)
  893. {
  894. struct intel_sdvo_dtd input_dtd;
  895. /* Reset the input timing to the screen. Assume always input 0. */
  896. if (!intel_sdvo_set_target_input(intel_sdvo))
  897. return false;
  898. if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
  899. mode->clock / 10,
  900. mode->hdisplay,
  901. mode->vdisplay))
  902. return false;
  903. if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
  904. &input_dtd))
  905. return false;
  906. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  907. intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
  908. return true;
  909. }
  910. static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_config *pipe_config)
  911. {
  912. unsigned dotclock = pipe_config->adjusted_mode.clock;
  913. struct dpll *clock = &pipe_config->dpll;
  914. /* SDVO TV has fixed PLL values depend on its clock range,
  915. this mirrors vbios setting. */
  916. if (dotclock >= 100000 && dotclock < 140500) {
  917. clock->p1 = 2;
  918. clock->p2 = 10;
  919. clock->n = 3;
  920. clock->m1 = 16;
  921. clock->m2 = 8;
  922. } else if (dotclock >= 140500 && dotclock <= 200000) {
  923. clock->p1 = 1;
  924. clock->p2 = 10;
  925. clock->n = 6;
  926. clock->m1 = 12;
  927. clock->m2 = 8;
  928. } else {
  929. WARN(1, "SDVO TV clock out of range: %i\n", dotclock);
  930. }
  931. pipe_config->clock_set = true;
  932. }
  933. static bool intel_sdvo_compute_config(struct intel_encoder *encoder,
  934. struct intel_crtc_config *pipe_config)
  935. {
  936. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  937. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  938. struct drm_display_mode *mode = &pipe_config->requested_mode;
  939. DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
  940. pipe_config->pipe_bpp = 8*3;
  941. if (HAS_PCH_SPLIT(encoder->base.dev))
  942. pipe_config->has_pch_encoder = true;
  943. /* We need to construct preferred input timings based on our
  944. * output timings. To do that, we have to set the output
  945. * timings, even though this isn't really the right place in
  946. * the sequence to do it. Oh well.
  947. */
  948. if (intel_sdvo->is_tv) {
  949. if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
  950. return false;
  951. (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
  952. mode,
  953. adjusted_mode);
  954. pipe_config->sdvo_tv_clock = true;
  955. } else if (intel_sdvo->is_lvds) {
  956. if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
  957. intel_sdvo->sdvo_lvds_fixed_mode))
  958. return false;
  959. (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
  960. mode,
  961. adjusted_mode);
  962. }
  963. /* Make the CRTC code factor in the SDVO pixel multiplier. The
  964. * SDVO device will factor out the multiplier during mode_set.
  965. */
  966. pipe_config->pixel_multiplier =
  967. intel_sdvo_get_pixel_multiplier(adjusted_mode);
  968. adjusted_mode->clock *= pipe_config->pixel_multiplier;
  969. if (intel_sdvo->color_range_auto) {
  970. /* See CEA-861-E - 5.1 Default Encoding Parameters */
  971. /* FIXME: This bit is only valid when using TMDS encoding and 8
  972. * bit per color mode. */
  973. if (intel_sdvo->has_hdmi_monitor &&
  974. drm_match_cea_mode(adjusted_mode) > 1)
  975. intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
  976. else
  977. intel_sdvo->color_range = 0;
  978. }
  979. if (intel_sdvo->color_range)
  980. pipe_config->limited_color_range = true;
  981. /* Clock computation needs to happen after pixel multiplier. */
  982. if (intel_sdvo->is_tv)
  983. i9xx_adjust_sdvo_tv_clock(pipe_config);
  984. return true;
  985. }
  986. static void intel_sdvo_mode_set(struct intel_encoder *intel_encoder)
  987. {
  988. struct drm_device *dev = intel_encoder->base.dev;
  989. struct drm_i915_private *dev_priv = dev->dev_private;
  990. struct drm_crtc *crtc = intel_encoder->base.crtc;
  991. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  992. struct drm_display_mode *adjusted_mode =
  993. &intel_crtc->config.adjusted_mode;
  994. struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
  995. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&intel_encoder->base);
  996. u32 sdvox;
  997. struct intel_sdvo_in_out_map in_out;
  998. struct intel_sdvo_dtd input_dtd, output_dtd;
  999. int rate;
  1000. if (!mode)
  1001. return;
  1002. /* First, set the input mapping for the first input to our controlled
  1003. * output. This is only correct if we're a single-input device, in
  1004. * which case the first input is the output from the appropriate SDVO
  1005. * channel on the motherboard. In a two-input device, the first input
  1006. * will be SDVOB and the second SDVOC.
  1007. */
  1008. in_out.in0 = intel_sdvo->attached_output;
  1009. in_out.in1 = 0;
  1010. intel_sdvo_set_value(intel_sdvo,
  1011. SDVO_CMD_SET_IN_OUT_MAP,
  1012. &in_out, sizeof(in_out));
  1013. /* Set the output timings to the screen */
  1014. if (!intel_sdvo_set_target_output(intel_sdvo,
  1015. intel_sdvo->attached_output))
  1016. return;
  1017. /* lvds has a special fixed output timing. */
  1018. if (intel_sdvo->is_lvds)
  1019. intel_sdvo_get_dtd_from_mode(&output_dtd,
  1020. intel_sdvo->sdvo_lvds_fixed_mode);
  1021. else
  1022. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  1023. if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
  1024. DRM_INFO("Setting output timings on %s failed\n",
  1025. SDVO_NAME(intel_sdvo));
  1026. /* Set the input timing to the screen. Assume always input 0. */
  1027. if (!intel_sdvo_set_target_input(intel_sdvo))
  1028. return;
  1029. if (intel_sdvo->has_hdmi_monitor) {
  1030. intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
  1031. intel_sdvo_set_colorimetry(intel_sdvo,
  1032. SDVO_COLORIMETRY_RGB256);
  1033. intel_sdvo_set_avi_infoframe(intel_sdvo, adjusted_mode);
  1034. } else
  1035. intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
  1036. if (intel_sdvo->is_tv &&
  1037. !intel_sdvo_set_tv_format(intel_sdvo))
  1038. return;
  1039. /* We have tried to get input timing in mode_fixup, and filled into
  1040. * adjusted_mode.
  1041. */
  1042. intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
  1043. if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
  1044. input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
  1045. if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
  1046. DRM_INFO("Setting input timings on %s failed\n",
  1047. SDVO_NAME(intel_sdvo));
  1048. switch (intel_crtc->config.pixel_multiplier) {
  1049. default:
  1050. WARN(1, "unknown pixel mutlipler specified\n");
  1051. case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
  1052. case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
  1053. case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
  1054. }
  1055. if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
  1056. return;
  1057. /* Set the SDVO control regs. */
  1058. if (INTEL_INFO(dev)->gen >= 4) {
  1059. /* The real mode polarity is set by the SDVO commands, using
  1060. * struct intel_sdvo_dtd. */
  1061. sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
  1062. if (!HAS_PCH_SPLIT(dev) && intel_sdvo->is_hdmi)
  1063. sdvox |= intel_sdvo->color_range;
  1064. if (INTEL_INFO(dev)->gen < 5)
  1065. sdvox |= SDVO_BORDER_ENABLE;
  1066. } else {
  1067. sdvox = I915_READ(intel_sdvo->sdvo_reg);
  1068. switch (intel_sdvo->sdvo_reg) {
  1069. case GEN3_SDVOB:
  1070. sdvox &= SDVOB_PRESERVE_MASK;
  1071. break;
  1072. case GEN3_SDVOC:
  1073. sdvox &= SDVOC_PRESERVE_MASK;
  1074. break;
  1075. }
  1076. sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
  1077. }
  1078. if (INTEL_PCH_TYPE(dev) >= PCH_CPT)
  1079. sdvox |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
  1080. else
  1081. sdvox |= SDVO_PIPE_SEL(intel_crtc->pipe);
  1082. if (intel_sdvo->has_hdmi_audio)
  1083. sdvox |= SDVO_AUDIO_ENABLE;
  1084. if (INTEL_INFO(dev)->gen >= 4) {
  1085. /* done in crtc_mode_set as the dpll_md reg must be written early */
  1086. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  1087. /* done in crtc_mode_set as it lives inside the dpll register */
  1088. } else {
  1089. sdvox |= (intel_crtc->config.pixel_multiplier - 1)
  1090. << SDVO_PORT_MULTIPLY_SHIFT;
  1091. }
  1092. if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
  1093. INTEL_INFO(dev)->gen < 5)
  1094. sdvox |= SDVO_STALL_SELECT;
  1095. intel_sdvo_write_sdvox(intel_sdvo, sdvox);
  1096. }
  1097. static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
  1098. {
  1099. struct intel_sdvo_connector *intel_sdvo_connector =
  1100. to_intel_sdvo_connector(&connector->base);
  1101. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
  1102. u16 active_outputs = 0;
  1103. intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
  1104. if (active_outputs & intel_sdvo_connector->output_flag)
  1105. return true;
  1106. else
  1107. return false;
  1108. }
  1109. static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
  1110. enum pipe *pipe)
  1111. {
  1112. struct drm_device *dev = encoder->base.dev;
  1113. struct drm_i915_private *dev_priv = dev->dev_private;
  1114. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  1115. u16 active_outputs = 0;
  1116. u32 tmp;
  1117. tmp = I915_READ(intel_sdvo->sdvo_reg);
  1118. intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
  1119. if (!(tmp & SDVO_ENABLE) && (active_outputs == 0))
  1120. return false;
  1121. if (HAS_PCH_CPT(dev))
  1122. *pipe = PORT_TO_PIPE_CPT(tmp);
  1123. else
  1124. *pipe = PORT_TO_PIPE(tmp);
  1125. return true;
  1126. }
  1127. static void intel_sdvo_get_config(struct intel_encoder *encoder,
  1128. struct intel_crtc_config *pipe_config)
  1129. {
  1130. struct drm_device *dev = encoder->base.dev;
  1131. struct drm_i915_private *dev_priv = dev->dev_private;
  1132. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  1133. struct intel_sdvo_dtd dtd;
  1134. int encoder_pixel_multiplier = 0;
  1135. u32 flags = 0, sdvox;
  1136. u8 val;
  1137. bool ret;
  1138. ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
  1139. if (!ret) {
  1140. /* Some sdvo encoders are not spec compliant and don't
  1141. * implement the mandatory get_timings function. */
  1142. DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
  1143. pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
  1144. } else {
  1145. if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
  1146. flags |= DRM_MODE_FLAG_PHSYNC;
  1147. else
  1148. flags |= DRM_MODE_FLAG_NHSYNC;
  1149. if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
  1150. flags |= DRM_MODE_FLAG_PVSYNC;
  1151. else
  1152. flags |= DRM_MODE_FLAG_NVSYNC;
  1153. }
  1154. pipe_config->adjusted_mode.flags |= flags;
  1155. /*
  1156. * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
  1157. * the sdvo port register, on all other platforms it is part of the dpll
  1158. * state. Since the general pipe state readout happens before the
  1159. * encoder->get_config we so already have a valid pixel multplier on all
  1160. * other platfroms.
  1161. */
  1162. if (IS_I915G(dev) || IS_I915GM(dev)) {
  1163. sdvox = I915_READ(intel_sdvo->sdvo_reg);
  1164. pipe_config->pixel_multiplier =
  1165. ((sdvox & SDVO_PORT_MULTIPLY_MASK)
  1166. >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
  1167. }
  1168. /* Cross check the port pixel multiplier with the sdvo encoder state. */
  1169. intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
  1170. switch (val) {
  1171. case SDVO_CLOCK_RATE_MULT_1X:
  1172. encoder_pixel_multiplier = 1;
  1173. break;
  1174. case SDVO_CLOCK_RATE_MULT_2X:
  1175. encoder_pixel_multiplier = 2;
  1176. break;
  1177. case SDVO_CLOCK_RATE_MULT_4X:
  1178. encoder_pixel_multiplier = 4;
  1179. break;
  1180. }
  1181. WARN(encoder_pixel_multiplier != pipe_config->pixel_multiplier,
  1182. "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
  1183. pipe_config->pixel_multiplier, encoder_pixel_multiplier);
  1184. }
  1185. static void intel_disable_sdvo(struct intel_encoder *encoder)
  1186. {
  1187. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1188. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  1189. u32 temp;
  1190. intel_sdvo_set_active_outputs(intel_sdvo, 0);
  1191. if (0)
  1192. intel_sdvo_set_encoder_power_state(intel_sdvo,
  1193. DRM_MODE_DPMS_OFF);
  1194. temp = I915_READ(intel_sdvo->sdvo_reg);
  1195. if ((temp & SDVO_ENABLE) != 0) {
  1196. /* HW workaround for IBX, we need to move the port to
  1197. * transcoder A before disabling it. */
  1198. if (HAS_PCH_IBX(encoder->base.dev)) {
  1199. struct drm_crtc *crtc = encoder->base.crtc;
  1200. int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
  1201. if (temp & SDVO_PIPE_B_SELECT) {
  1202. temp &= ~SDVO_PIPE_B_SELECT;
  1203. I915_WRITE(intel_sdvo->sdvo_reg, temp);
  1204. POSTING_READ(intel_sdvo->sdvo_reg);
  1205. /* Again we need to write this twice. */
  1206. I915_WRITE(intel_sdvo->sdvo_reg, temp);
  1207. POSTING_READ(intel_sdvo->sdvo_reg);
  1208. /* Transcoder selection bits only update
  1209. * effectively on vblank. */
  1210. if (crtc)
  1211. intel_wait_for_vblank(encoder->base.dev, pipe);
  1212. else
  1213. msleep(50);
  1214. }
  1215. }
  1216. intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
  1217. }
  1218. }
  1219. static void intel_enable_sdvo(struct intel_encoder *encoder)
  1220. {
  1221. struct drm_device *dev = encoder->base.dev;
  1222. struct drm_i915_private *dev_priv = dev->dev_private;
  1223. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  1224. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1225. u32 temp;
  1226. bool input1, input2;
  1227. int i;
  1228. u8 status;
  1229. temp = I915_READ(intel_sdvo->sdvo_reg);
  1230. if ((temp & SDVO_ENABLE) == 0) {
  1231. /* HW workaround for IBX, we need to move the port
  1232. * to transcoder A before disabling it, so restore it here. */
  1233. if (HAS_PCH_IBX(dev))
  1234. temp |= SDVO_PIPE_SEL(intel_crtc->pipe);
  1235. intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
  1236. }
  1237. for (i = 0; i < 2; i++)
  1238. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1239. status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
  1240. /* Warn if the device reported failure to sync.
  1241. * A lot of SDVO devices fail to notify of sync, but it's
  1242. * a given it the status is a success, we succeeded.
  1243. */
  1244. if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
  1245. DRM_DEBUG_KMS("First %s output reported failure to "
  1246. "sync\n", SDVO_NAME(intel_sdvo));
  1247. }
  1248. if (0)
  1249. intel_sdvo_set_encoder_power_state(intel_sdvo,
  1250. DRM_MODE_DPMS_ON);
  1251. intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
  1252. }
  1253. /* Special dpms function to support cloning between dvo/sdvo/crt. */
  1254. static void intel_sdvo_dpms(struct drm_connector *connector, int mode)
  1255. {
  1256. struct drm_crtc *crtc;
  1257. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1258. /* dvo supports only 2 dpms states. */
  1259. if (mode != DRM_MODE_DPMS_ON)
  1260. mode = DRM_MODE_DPMS_OFF;
  1261. if (mode == connector->dpms)
  1262. return;
  1263. connector->dpms = mode;
  1264. /* Only need to change hw state when actually enabled */
  1265. crtc = intel_sdvo->base.base.crtc;
  1266. if (!crtc) {
  1267. intel_sdvo->base.connectors_active = false;
  1268. return;
  1269. }
  1270. /* We set active outputs manually below in case pipe dpms doesn't change
  1271. * due to cloning. */
  1272. if (mode != DRM_MODE_DPMS_ON) {
  1273. intel_sdvo_set_active_outputs(intel_sdvo, 0);
  1274. if (0)
  1275. intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
  1276. intel_sdvo->base.connectors_active = false;
  1277. intel_crtc_update_dpms(crtc);
  1278. } else {
  1279. intel_sdvo->base.connectors_active = true;
  1280. intel_crtc_update_dpms(crtc);
  1281. if (0)
  1282. intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
  1283. intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
  1284. }
  1285. intel_modeset_check_state(connector->dev);
  1286. }
  1287. static int intel_sdvo_mode_valid(struct drm_connector *connector,
  1288. struct drm_display_mode *mode)
  1289. {
  1290. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1291. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1292. return MODE_NO_DBLESCAN;
  1293. if (intel_sdvo->pixel_clock_min > mode->clock)
  1294. return MODE_CLOCK_LOW;
  1295. if (intel_sdvo->pixel_clock_max < mode->clock)
  1296. return MODE_CLOCK_HIGH;
  1297. if (intel_sdvo->is_lvds) {
  1298. if (mode->hdisplay > intel_sdvo->sdvo_lvds_fixed_mode->hdisplay)
  1299. return MODE_PANEL;
  1300. if (mode->vdisplay > intel_sdvo->sdvo_lvds_fixed_mode->vdisplay)
  1301. return MODE_PANEL;
  1302. }
  1303. return MODE_OK;
  1304. }
  1305. static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
  1306. {
  1307. BUILD_BUG_ON(sizeof(*caps) != 8);
  1308. if (!intel_sdvo_get_value(intel_sdvo,
  1309. SDVO_CMD_GET_DEVICE_CAPS,
  1310. caps, sizeof(*caps)))
  1311. return false;
  1312. DRM_DEBUG_KMS("SDVO capabilities:\n"
  1313. " vendor_id: %d\n"
  1314. " device_id: %d\n"
  1315. " device_rev_id: %d\n"
  1316. " sdvo_version_major: %d\n"
  1317. " sdvo_version_minor: %d\n"
  1318. " sdvo_inputs_mask: %d\n"
  1319. " smooth_scaling: %d\n"
  1320. " sharp_scaling: %d\n"
  1321. " up_scaling: %d\n"
  1322. " down_scaling: %d\n"
  1323. " stall_support: %d\n"
  1324. " output_flags: %d\n",
  1325. caps->vendor_id,
  1326. caps->device_id,
  1327. caps->device_rev_id,
  1328. caps->sdvo_version_major,
  1329. caps->sdvo_version_minor,
  1330. caps->sdvo_inputs_mask,
  1331. caps->smooth_scaling,
  1332. caps->sharp_scaling,
  1333. caps->up_scaling,
  1334. caps->down_scaling,
  1335. caps->stall_support,
  1336. caps->output_flags);
  1337. return true;
  1338. }
  1339. static uint16_t intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
  1340. {
  1341. struct drm_device *dev = intel_sdvo->base.base.dev;
  1342. uint16_t hotplug;
  1343. /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
  1344. * on the line. */
  1345. if (IS_I945G(dev) || IS_I945GM(dev))
  1346. return 0;
  1347. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
  1348. &hotplug, sizeof(hotplug)))
  1349. return 0;
  1350. return hotplug;
  1351. }
  1352. static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
  1353. {
  1354. struct intel_sdvo *intel_sdvo = to_intel_sdvo(&encoder->base);
  1355. intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
  1356. &intel_sdvo->hotplug_active, 2);
  1357. }
  1358. static bool
  1359. intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
  1360. {
  1361. /* Is there more than one type of output? */
  1362. return hweight16(intel_sdvo->caps.output_flags) > 1;
  1363. }
  1364. static struct edid *
  1365. intel_sdvo_get_edid(struct drm_connector *connector)
  1366. {
  1367. struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
  1368. return drm_get_edid(connector, &sdvo->ddc);
  1369. }
  1370. /* Mac mini hack -- use the same DDC as the analog connector */
  1371. static struct edid *
  1372. intel_sdvo_get_analog_edid(struct drm_connector *connector)
  1373. {
  1374. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1375. return drm_get_edid(connector,
  1376. intel_gmbus_get_adapter(dev_priv,
  1377. dev_priv->vbt.crt_ddc_pin));
  1378. }
  1379. static enum drm_connector_status
  1380. intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
  1381. {
  1382. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1383. enum drm_connector_status status;
  1384. struct edid *edid;
  1385. edid = intel_sdvo_get_edid(connector);
  1386. if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
  1387. u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
  1388. /*
  1389. * Don't use the 1 as the argument of DDC bus switch to get
  1390. * the EDID. It is used for SDVO SPD ROM.
  1391. */
  1392. for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
  1393. intel_sdvo->ddc_bus = ddc;
  1394. edid = intel_sdvo_get_edid(connector);
  1395. if (edid)
  1396. break;
  1397. }
  1398. /*
  1399. * If we found the EDID on the other bus,
  1400. * assume that is the correct DDC bus.
  1401. */
  1402. if (edid == NULL)
  1403. intel_sdvo->ddc_bus = saved_ddc;
  1404. }
  1405. /*
  1406. * When there is no edid and no monitor is connected with VGA
  1407. * port, try to use the CRT ddc to read the EDID for DVI-connector.
  1408. */
  1409. if (edid == NULL)
  1410. edid = intel_sdvo_get_analog_edid(connector);
  1411. status = connector_status_unknown;
  1412. if (edid != NULL) {
  1413. /* DDC bus is shared, match EDID to connector type */
  1414. if (edid->input & DRM_EDID_INPUT_DIGITAL) {
  1415. status = connector_status_connected;
  1416. if (intel_sdvo->is_hdmi) {
  1417. intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
  1418. intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
  1419. intel_sdvo->rgb_quant_range_selectable =
  1420. drm_rgb_quant_range_selectable(edid);
  1421. }
  1422. } else
  1423. status = connector_status_disconnected;
  1424. kfree(edid);
  1425. }
  1426. if (status == connector_status_connected) {
  1427. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1428. if (intel_sdvo_connector->force_audio != HDMI_AUDIO_AUTO)
  1429. intel_sdvo->has_hdmi_audio = (intel_sdvo_connector->force_audio == HDMI_AUDIO_ON);
  1430. }
  1431. return status;
  1432. }
  1433. static bool
  1434. intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
  1435. struct edid *edid)
  1436. {
  1437. bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
  1438. bool connector_is_digital = !!IS_DIGITAL(sdvo);
  1439. DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
  1440. connector_is_digital, monitor_is_digital);
  1441. return connector_is_digital == monitor_is_digital;
  1442. }
  1443. static enum drm_connector_status
  1444. intel_sdvo_detect(struct drm_connector *connector, bool force)
  1445. {
  1446. uint16_t response;
  1447. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1448. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1449. enum drm_connector_status ret;
  1450. if (!intel_sdvo_get_value(intel_sdvo,
  1451. SDVO_CMD_GET_ATTACHED_DISPLAYS,
  1452. &response, 2))
  1453. return connector_status_unknown;
  1454. DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
  1455. response & 0xff, response >> 8,
  1456. intel_sdvo_connector->output_flag);
  1457. if (response == 0)
  1458. return connector_status_disconnected;
  1459. intel_sdvo->attached_output = response;
  1460. intel_sdvo->has_hdmi_monitor = false;
  1461. intel_sdvo->has_hdmi_audio = false;
  1462. intel_sdvo->rgb_quant_range_selectable = false;
  1463. if ((intel_sdvo_connector->output_flag & response) == 0)
  1464. ret = connector_status_disconnected;
  1465. else if (IS_TMDS(intel_sdvo_connector))
  1466. ret = intel_sdvo_tmds_sink_detect(connector);
  1467. else {
  1468. struct edid *edid;
  1469. /* if we have an edid check it matches the connection */
  1470. edid = intel_sdvo_get_edid(connector);
  1471. if (edid == NULL)
  1472. edid = intel_sdvo_get_analog_edid(connector);
  1473. if (edid != NULL) {
  1474. if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
  1475. edid))
  1476. ret = connector_status_connected;
  1477. else
  1478. ret = connector_status_disconnected;
  1479. kfree(edid);
  1480. } else
  1481. ret = connector_status_connected;
  1482. }
  1483. /* May update encoder flag for like clock for SDVO TV, etc.*/
  1484. if (ret == connector_status_connected) {
  1485. intel_sdvo->is_tv = false;
  1486. intel_sdvo->is_lvds = false;
  1487. if (response & SDVO_TV_MASK)
  1488. intel_sdvo->is_tv = true;
  1489. if (response & SDVO_LVDS_MASK)
  1490. intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
  1491. }
  1492. return ret;
  1493. }
  1494. static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
  1495. {
  1496. struct edid *edid;
  1497. /* set the bus switch and get the modes */
  1498. edid = intel_sdvo_get_edid(connector);
  1499. /*
  1500. * Mac mini hack. On this device, the DVI-I connector shares one DDC
  1501. * link between analog and digital outputs. So, if the regular SDVO
  1502. * DDC fails, check to see if the analog output is disconnected, in
  1503. * which case we'll look there for the digital DDC data.
  1504. */
  1505. if (edid == NULL)
  1506. edid = intel_sdvo_get_analog_edid(connector);
  1507. if (edid != NULL) {
  1508. if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
  1509. edid)) {
  1510. drm_mode_connector_update_edid_property(connector, edid);
  1511. drm_add_edid_modes(connector, edid);
  1512. }
  1513. kfree(edid);
  1514. }
  1515. }
  1516. /*
  1517. * Set of SDVO TV modes.
  1518. * Note! This is in reply order (see loop in get_tv_modes).
  1519. * XXX: all 60Hz refresh?
  1520. */
  1521. static const struct drm_display_mode sdvo_tv_modes[] = {
  1522. { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
  1523. 416, 0, 200, 201, 232, 233, 0,
  1524. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1525. { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
  1526. 416, 0, 240, 241, 272, 273, 0,
  1527. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1528. { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
  1529. 496, 0, 300, 301, 332, 333, 0,
  1530. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1531. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
  1532. 736, 0, 350, 351, 382, 383, 0,
  1533. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1534. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
  1535. 736, 0, 400, 401, 432, 433, 0,
  1536. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1537. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
  1538. 736, 0, 480, 481, 512, 513, 0,
  1539. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1540. { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
  1541. 800, 0, 480, 481, 512, 513, 0,
  1542. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1543. { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
  1544. 800, 0, 576, 577, 608, 609, 0,
  1545. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1546. { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
  1547. 816, 0, 350, 351, 382, 383, 0,
  1548. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1549. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
  1550. 816, 0, 400, 401, 432, 433, 0,
  1551. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1552. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
  1553. 816, 0, 480, 481, 512, 513, 0,
  1554. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1555. { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
  1556. 816, 0, 540, 541, 572, 573, 0,
  1557. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1558. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
  1559. 816, 0, 576, 577, 608, 609, 0,
  1560. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1561. { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
  1562. 864, 0, 576, 577, 608, 609, 0,
  1563. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1564. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
  1565. 896, 0, 600, 601, 632, 633, 0,
  1566. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1567. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
  1568. 928, 0, 624, 625, 656, 657, 0,
  1569. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1570. { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
  1571. 1016, 0, 766, 767, 798, 799, 0,
  1572. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1573. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
  1574. 1120, 0, 768, 769, 800, 801, 0,
  1575. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1576. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
  1577. 1376, 0, 1024, 1025, 1056, 1057, 0,
  1578. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1579. };
  1580. static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
  1581. {
  1582. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1583. struct intel_sdvo_sdtv_resolution_request tv_res;
  1584. uint32_t reply = 0, format_map = 0;
  1585. int i;
  1586. /* Read the list of supported input resolutions for the selected TV
  1587. * format.
  1588. */
  1589. format_map = 1 << intel_sdvo->tv_format_index;
  1590. memcpy(&tv_res, &format_map,
  1591. min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
  1592. if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
  1593. return;
  1594. BUILD_BUG_ON(sizeof(tv_res) != 3);
  1595. if (!intel_sdvo_write_cmd(intel_sdvo,
  1596. SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
  1597. &tv_res, sizeof(tv_res)))
  1598. return;
  1599. if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
  1600. return;
  1601. for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
  1602. if (reply & (1 << i)) {
  1603. struct drm_display_mode *nmode;
  1604. nmode = drm_mode_duplicate(connector->dev,
  1605. &sdvo_tv_modes[i]);
  1606. if (nmode)
  1607. drm_mode_probed_add(connector, nmode);
  1608. }
  1609. }
  1610. static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
  1611. {
  1612. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1613. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1614. struct drm_display_mode *newmode;
  1615. /*
  1616. * Fetch modes from VBT. For SDVO prefer the VBT mode since some
  1617. * SDVO->LVDS transcoders can't cope with the EDID mode.
  1618. */
  1619. if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
  1620. newmode = drm_mode_duplicate(connector->dev,
  1621. dev_priv->vbt.sdvo_lvds_vbt_mode);
  1622. if (newmode != NULL) {
  1623. /* Guarantee the mode is preferred */
  1624. newmode->type = (DRM_MODE_TYPE_PREFERRED |
  1625. DRM_MODE_TYPE_DRIVER);
  1626. drm_mode_probed_add(connector, newmode);
  1627. }
  1628. }
  1629. /*
  1630. * Attempt to get the mode list from DDC.
  1631. * Assume that the preferred modes are
  1632. * arranged in priority order.
  1633. */
  1634. intel_ddc_get_modes(connector, &intel_sdvo->ddc);
  1635. list_for_each_entry(newmode, &connector->probed_modes, head) {
  1636. if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
  1637. intel_sdvo->sdvo_lvds_fixed_mode =
  1638. drm_mode_duplicate(connector->dev, newmode);
  1639. intel_sdvo->is_lvds = true;
  1640. break;
  1641. }
  1642. }
  1643. }
  1644. static int intel_sdvo_get_modes(struct drm_connector *connector)
  1645. {
  1646. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1647. if (IS_TV(intel_sdvo_connector))
  1648. intel_sdvo_get_tv_modes(connector);
  1649. else if (IS_LVDS(intel_sdvo_connector))
  1650. intel_sdvo_get_lvds_modes(connector);
  1651. else
  1652. intel_sdvo_get_ddc_modes(connector);
  1653. return !list_empty(&connector->probed_modes);
  1654. }
  1655. static void
  1656. intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
  1657. {
  1658. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1659. struct drm_device *dev = connector->dev;
  1660. if (intel_sdvo_connector->left)
  1661. drm_property_destroy(dev, intel_sdvo_connector->left);
  1662. if (intel_sdvo_connector->right)
  1663. drm_property_destroy(dev, intel_sdvo_connector->right);
  1664. if (intel_sdvo_connector->top)
  1665. drm_property_destroy(dev, intel_sdvo_connector->top);
  1666. if (intel_sdvo_connector->bottom)
  1667. drm_property_destroy(dev, intel_sdvo_connector->bottom);
  1668. if (intel_sdvo_connector->hpos)
  1669. drm_property_destroy(dev, intel_sdvo_connector->hpos);
  1670. if (intel_sdvo_connector->vpos)
  1671. drm_property_destroy(dev, intel_sdvo_connector->vpos);
  1672. if (intel_sdvo_connector->saturation)
  1673. drm_property_destroy(dev, intel_sdvo_connector->saturation);
  1674. if (intel_sdvo_connector->contrast)
  1675. drm_property_destroy(dev, intel_sdvo_connector->contrast);
  1676. if (intel_sdvo_connector->hue)
  1677. drm_property_destroy(dev, intel_sdvo_connector->hue);
  1678. if (intel_sdvo_connector->sharpness)
  1679. drm_property_destroy(dev, intel_sdvo_connector->sharpness);
  1680. if (intel_sdvo_connector->flicker_filter)
  1681. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter);
  1682. if (intel_sdvo_connector->flicker_filter_2d)
  1683. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_2d);
  1684. if (intel_sdvo_connector->flicker_filter_adaptive)
  1685. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_adaptive);
  1686. if (intel_sdvo_connector->tv_luma_filter)
  1687. drm_property_destroy(dev, intel_sdvo_connector->tv_luma_filter);
  1688. if (intel_sdvo_connector->tv_chroma_filter)
  1689. drm_property_destroy(dev, intel_sdvo_connector->tv_chroma_filter);
  1690. if (intel_sdvo_connector->dot_crawl)
  1691. drm_property_destroy(dev, intel_sdvo_connector->dot_crawl);
  1692. if (intel_sdvo_connector->brightness)
  1693. drm_property_destroy(dev, intel_sdvo_connector->brightness);
  1694. }
  1695. static void intel_sdvo_destroy(struct drm_connector *connector)
  1696. {
  1697. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1698. if (intel_sdvo_connector->tv_format)
  1699. drm_property_destroy(connector->dev,
  1700. intel_sdvo_connector->tv_format);
  1701. intel_sdvo_destroy_enhance_property(connector);
  1702. drm_sysfs_connector_remove(connector);
  1703. drm_connector_cleanup(connector);
  1704. kfree(intel_sdvo_connector);
  1705. }
  1706. static bool intel_sdvo_detect_hdmi_audio(struct drm_connector *connector)
  1707. {
  1708. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1709. struct edid *edid;
  1710. bool has_audio = false;
  1711. if (!intel_sdvo->is_hdmi)
  1712. return false;
  1713. edid = intel_sdvo_get_edid(connector);
  1714. if (edid != NULL && edid->input & DRM_EDID_INPUT_DIGITAL)
  1715. has_audio = drm_detect_monitor_audio(edid);
  1716. kfree(edid);
  1717. return has_audio;
  1718. }
  1719. static int
  1720. intel_sdvo_set_property(struct drm_connector *connector,
  1721. struct drm_property *property,
  1722. uint64_t val)
  1723. {
  1724. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1725. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1726. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1727. uint16_t temp_value;
  1728. uint8_t cmd;
  1729. int ret;
  1730. ret = drm_object_property_set_value(&connector->base, property, val);
  1731. if (ret)
  1732. return ret;
  1733. if (property == dev_priv->force_audio_property) {
  1734. int i = val;
  1735. bool has_audio;
  1736. if (i == intel_sdvo_connector->force_audio)
  1737. return 0;
  1738. intel_sdvo_connector->force_audio = i;
  1739. if (i == HDMI_AUDIO_AUTO)
  1740. has_audio = intel_sdvo_detect_hdmi_audio(connector);
  1741. else
  1742. has_audio = (i == HDMI_AUDIO_ON);
  1743. if (has_audio == intel_sdvo->has_hdmi_audio)
  1744. return 0;
  1745. intel_sdvo->has_hdmi_audio = has_audio;
  1746. goto done;
  1747. }
  1748. if (property == dev_priv->broadcast_rgb_property) {
  1749. bool old_auto = intel_sdvo->color_range_auto;
  1750. uint32_t old_range = intel_sdvo->color_range;
  1751. switch (val) {
  1752. case INTEL_BROADCAST_RGB_AUTO:
  1753. intel_sdvo->color_range_auto = true;
  1754. break;
  1755. case INTEL_BROADCAST_RGB_FULL:
  1756. intel_sdvo->color_range_auto = false;
  1757. intel_sdvo->color_range = 0;
  1758. break;
  1759. case INTEL_BROADCAST_RGB_LIMITED:
  1760. intel_sdvo->color_range_auto = false;
  1761. /* FIXME: this bit is only valid when using TMDS
  1762. * encoding and 8 bit per color mode. */
  1763. intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
  1764. break;
  1765. default:
  1766. return -EINVAL;
  1767. }
  1768. if (old_auto == intel_sdvo->color_range_auto &&
  1769. old_range == intel_sdvo->color_range)
  1770. return 0;
  1771. goto done;
  1772. }
  1773. #define CHECK_PROPERTY(name, NAME) \
  1774. if (intel_sdvo_connector->name == property) { \
  1775. if (intel_sdvo_connector->cur_##name == temp_value) return 0; \
  1776. if (intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
  1777. cmd = SDVO_CMD_SET_##NAME; \
  1778. intel_sdvo_connector->cur_##name = temp_value; \
  1779. goto set_value; \
  1780. }
  1781. if (property == intel_sdvo_connector->tv_format) {
  1782. if (val >= TV_FORMAT_NUM)
  1783. return -EINVAL;
  1784. if (intel_sdvo->tv_format_index ==
  1785. intel_sdvo_connector->tv_format_supported[val])
  1786. return 0;
  1787. intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[val];
  1788. goto done;
  1789. } else if (IS_TV_OR_LVDS(intel_sdvo_connector)) {
  1790. temp_value = val;
  1791. if (intel_sdvo_connector->left == property) {
  1792. drm_object_property_set_value(&connector->base,
  1793. intel_sdvo_connector->right, val);
  1794. if (intel_sdvo_connector->left_margin == temp_value)
  1795. return 0;
  1796. intel_sdvo_connector->left_margin = temp_value;
  1797. intel_sdvo_connector->right_margin = temp_value;
  1798. temp_value = intel_sdvo_connector->max_hscan -
  1799. intel_sdvo_connector->left_margin;
  1800. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1801. goto set_value;
  1802. } else if (intel_sdvo_connector->right == property) {
  1803. drm_object_property_set_value(&connector->base,
  1804. intel_sdvo_connector->left, val);
  1805. if (intel_sdvo_connector->right_margin == temp_value)
  1806. return 0;
  1807. intel_sdvo_connector->left_margin = temp_value;
  1808. intel_sdvo_connector->right_margin = temp_value;
  1809. temp_value = intel_sdvo_connector->max_hscan -
  1810. intel_sdvo_connector->left_margin;
  1811. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1812. goto set_value;
  1813. } else if (intel_sdvo_connector->top == property) {
  1814. drm_object_property_set_value(&connector->base,
  1815. intel_sdvo_connector->bottom, val);
  1816. if (intel_sdvo_connector->top_margin == temp_value)
  1817. return 0;
  1818. intel_sdvo_connector->top_margin = temp_value;
  1819. intel_sdvo_connector->bottom_margin = temp_value;
  1820. temp_value = intel_sdvo_connector->max_vscan -
  1821. intel_sdvo_connector->top_margin;
  1822. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1823. goto set_value;
  1824. } else if (intel_sdvo_connector->bottom == property) {
  1825. drm_object_property_set_value(&connector->base,
  1826. intel_sdvo_connector->top, val);
  1827. if (intel_sdvo_connector->bottom_margin == temp_value)
  1828. return 0;
  1829. intel_sdvo_connector->top_margin = temp_value;
  1830. intel_sdvo_connector->bottom_margin = temp_value;
  1831. temp_value = intel_sdvo_connector->max_vscan -
  1832. intel_sdvo_connector->top_margin;
  1833. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1834. goto set_value;
  1835. }
  1836. CHECK_PROPERTY(hpos, HPOS)
  1837. CHECK_PROPERTY(vpos, VPOS)
  1838. CHECK_PROPERTY(saturation, SATURATION)
  1839. CHECK_PROPERTY(contrast, CONTRAST)
  1840. CHECK_PROPERTY(hue, HUE)
  1841. CHECK_PROPERTY(brightness, BRIGHTNESS)
  1842. CHECK_PROPERTY(sharpness, SHARPNESS)
  1843. CHECK_PROPERTY(flicker_filter, FLICKER_FILTER)
  1844. CHECK_PROPERTY(flicker_filter_2d, FLICKER_FILTER_2D)
  1845. CHECK_PROPERTY(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE)
  1846. CHECK_PROPERTY(tv_chroma_filter, TV_CHROMA_FILTER)
  1847. CHECK_PROPERTY(tv_luma_filter, TV_LUMA_FILTER)
  1848. CHECK_PROPERTY(dot_crawl, DOT_CRAWL)
  1849. }
  1850. return -EINVAL; /* unknown property */
  1851. set_value:
  1852. if (!intel_sdvo_set_value(intel_sdvo, cmd, &temp_value, 2))
  1853. return -EIO;
  1854. done:
  1855. if (intel_sdvo->base.base.crtc)
  1856. intel_crtc_restore_mode(intel_sdvo->base.base.crtc);
  1857. return 0;
  1858. #undef CHECK_PROPERTY
  1859. }
  1860. static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
  1861. .dpms = intel_sdvo_dpms,
  1862. .detect = intel_sdvo_detect,
  1863. .fill_modes = drm_helper_probe_single_connector_modes,
  1864. .set_property = intel_sdvo_set_property,
  1865. .destroy = intel_sdvo_destroy,
  1866. };
  1867. static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
  1868. .get_modes = intel_sdvo_get_modes,
  1869. .mode_valid = intel_sdvo_mode_valid,
  1870. .best_encoder = intel_best_encoder,
  1871. };
  1872. static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
  1873. {
  1874. struct intel_sdvo *intel_sdvo = to_intel_sdvo(encoder);
  1875. if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
  1876. drm_mode_destroy(encoder->dev,
  1877. intel_sdvo->sdvo_lvds_fixed_mode);
  1878. i2c_del_adapter(&intel_sdvo->ddc);
  1879. intel_encoder_destroy(encoder);
  1880. }
  1881. static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
  1882. .destroy = intel_sdvo_enc_destroy,
  1883. };
  1884. static void
  1885. intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
  1886. {
  1887. uint16_t mask = 0;
  1888. unsigned int num_bits;
  1889. /* Make a mask of outputs less than or equal to our own priority in the
  1890. * list.
  1891. */
  1892. switch (sdvo->controlled_output) {
  1893. case SDVO_OUTPUT_LVDS1:
  1894. mask |= SDVO_OUTPUT_LVDS1;
  1895. case SDVO_OUTPUT_LVDS0:
  1896. mask |= SDVO_OUTPUT_LVDS0;
  1897. case SDVO_OUTPUT_TMDS1:
  1898. mask |= SDVO_OUTPUT_TMDS1;
  1899. case SDVO_OUTPUT_TMDS0:
  1900. mask |= SDVO_OUTPUT_TMDS0;
  1901. case SDVO_OUTPUT_RGB1:
  1902. mask |= SDVO_OUTPUT_RGB1;
  1903. case SDVO_OUTPUT_RGB0:
  1904. mask |= SDVO_OUTPUT_RGB0;
  1905. break;
  1906. }
  1907. /* Count bits to find what number we are in the priority list. */
  1908. mask &= sdvo->caps.output_flags;
  1909. num_bits = hweight16(mask);
  1910. /* If more than 3 outputs, default to DDC bus 3 for now. */
  1911. if (num_bits > 3)
  1912. num_bits = 3;
  1913. /* Corresponds to SDVO_CONTROL_BUS_DDCx */
  1914. sdvo->ddc_bus = 1 << num_bits;
  1915. }
  1916. /**
  1917. * Choose the appropriate DDC bus for control bus switch command for this
  1918. * SDVO output based on the controlled output.
  1919. *
  1920. * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
  1921. * outputs, then LVDS outputs.
  1922. */
  1923. static void
  1924. intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
  1925. struct intel_sdvo *sdvo, u32 reg)
  1926. {
  1927. struct sdvo_device_mapping *mapping;
  1928. if (sdvo->is_sdvob)
  1929. mapping = &(dev_priv->sdvo_mappings[0]);
  1930. else
  1931. mapping = &(dev_priv->sdvo_mappings[1]);
  1932. if (mapping->initialized)
  1933. sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
  1934. else
  1935. intel_sdvo_guess_ddc_bus(sdvo);
  1936. }
  1937. static void
  1938. intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
  1939. struct intel_sdvo *sdvo, u32 reg)
  1940. {
  1941. struct sdvo_device_mapping *mapping;
  1942. u8 pin;
  1943. if (sdvo->is_sdvob)
  1944. mapping = &dev_priv->sdvo_mappings[0];
  1945. else
  1946. mapping = &dev_priv->sdvo_mappings[1];
  1947. if (mapping->initialized && intel_gmbus_is_port_valid(mapping->i2c_pin))
  1948. pin = mapping->i2c_pin;
  1949. else
  1950. pin = GMBUS_PORT_DPB;
  1951. sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
  1952. /* With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
  1953. * our code totally fails once we start using gmbus. Hence fall back to
  1954. * bit banging for now. */
  1955. intel_gmbus_force_bit(sdvo->i2c, true);
  1956. }
  1957. /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
  1958. static void
  1959. intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
  1960. {
  1961. intel_gmbus_force_bit(sdvo->i2c, false);
  1962. }
  1963. static bool
  1964. intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
  1965. {
  1966. return intel_sdvo_check_supp_encode(intel_sdvo);
  1967. }
  1968. static u8
  1969. intel_sdvo_get_slave_addr(struct drm_device *dev, struct intel_sdvo *sdvo)
  1970. {
  1971. struct drm_i915_private *dev_priv = dev->dev_private;
  1972. struct sdvo_device_mapping *my_mapping, *other_mapping;
  1973. if (sdvo->is_sdvob) {
  1974. my_mapping = &dev_priv->sdvo_mappings[0];
  1975. other_mapping = &dev_priv->sdvo_mappings[1];
  1976. } else {
  1977. my_mapping = &dev_priv->sdvo_mappings[1];
  1978. other_mapping = &dev_priv->sdvo_mappings[0];
  1979. }
  1980. /* If the BIOS described our SDVO device, take advantage of it. */
  1981. if (my_mapping->slave_addr)
  1982. return my_mapping->slave_addr;
  1983. /* If the BIOS only described a different SDVO device, use the
  1984. * address that it isn't using.
  1985. */
  1986. if (other_mapping->slave_addr) {
  1987. if (other_mapping->slave_addr == 0x70)
  1988. return 0x72;
  1989. else
  1990. return 0x70;
  1991. }
  1992. /* No SDVO device info is found for another DVO port,
  1993. * so use mapping assumption we had before BIOS parsing.
  1994. */
  1995. if (sdvo->is_sdvob)
  1996. return 0x70;
  1997. else
  1998. return 0x72;
  1999. }
  2000. static void
  2001. intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
  2002. struct intel_sdvo *encoder)
  2003. {
  2004. drm_connector_init(encoder->base.base.dev,
  2005. &connector->base.base,
  2006. &intel_sdvo_connector_funcs,
  2007. connector->base.base.connector_type);
  2008. drm_connector_helper_add(&connector->base.base,
  2009. &intel_sdvo_connector_helper_funcs);
  2010. connector->base.base.interlace_allowed = 1;
  2011. connector->base.base.doublescan_allowed = 0;
  2012. connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
  2013. connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
  2014. intel_connector_attach_encoder(&connector->base, &encoder->base);
  2015. drm_sysfs_connector_add(&connector->base.base);
  2016. }
  2017. static void
  2018. intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
  2019. struct intel_sdvo_connector *connector)
  2020. {
  2021. struct drm_device *dev = connector->base.base.dev;
  2022. intel_attach_force_audio_property(&connector->base.base);
  2023. if (INTEL_INFO(dev)->gen >= 4 && IS_MOBILE(dev)) {
  2024. intel_attach_broadcast_rgb_property(&connector->base.base);
  2025. intel_sdvo->color_range_auto = true;
  2026. }
  2027. }
  2028. static bool
  2029. intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
  2030. {
  2031. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2032. struct drm_connector *connector;
  2033. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2034. struct intel_connector *intel_connector;
  2035. struct intel_sdvo_connector *intel_sdvo_connector;
  2036. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2037. if (!intel_sdvo_connector)
  2038. return false;
  2039. if (device == 0) {
  2040. intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
  2041. intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
  2042. } else if (device == 1) {
  2043. intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
  2044. intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
  2045. }
  2046. intel_connector = &intel_sdvo_connector->base;
  2047. connector = &intel_connector->base;
  2048. if (intel_sdvo_get_hotplug_support(intel_sdvo) &
  2049. intel_sdvo_connector->output_flag) {
  2050. intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
  2051. /* Some SDVO devices have one-shot hotplug interrupts.
  2052. * Ensure that they get re-enabled when an interrupt happens.
  2053. */
  2054. intel_encoder->hot_plug = intel_sdvo_enable_hotplug;
  2055. intel_sdvo_enable_hotplug(intel_encoder);
  2056. } else {
  2057. intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
  2058. }
  2059. encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
  2060. connector->connector_type = DRM_MODE_CONNECTOR_DVID;
  2061. if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
  2062. connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
  2063. intel_sdvo->is_hdmi = true;
  2064. }
  2065. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2066. if (intel_sdvo->is_hdmi)
  2067. intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
  2068. return true;
  2069. }
  2070. static bool
  2071. intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
  2072. {
  2073. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2074. struct drm_connector *connector;
  2075. struct intel_connector *intel_connector;
  2076. struct intel_sdvo_connector *intel_sdvo_connector;
  2077. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2078. if (!intel_sdvo_connector)
  2079. return false;
  2080. intel_connector = &intel_sdvo_connector->base;
  2081. connector = &intel_connector->base;
  2082. encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
  2083. connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
  2084. intel_sdvo->controlled_output |= type;
  2085. intel_sdvo_connector->output_flag = type;
  2086. intel_sdvo->is_tv = true;
  2087. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2088. if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
  2089. goto err;
  2090. if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
  2091. goto err;
  2092. return true;
  2093. err:
  2094. intel_sdvo_destroy(connector);
  2095. return false;
  2096. }
  2097. static bool
  2098. intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
  2099. {
  2100. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2101. struct drm_connector *connector;
  2102. struct intel_connector *intel_connector;
  2103. struct intel_sdvo_connector *intel_sdvo_connector;
  2104. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2105. if (!intel_sdvo_connector)
  2106. return false;
  2107. intel_connector = &intel_sdvo_connector->base;
  2108. connector = &intel_connector->base;
  2109. intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  2110. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  2111. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  2112. if (device == 0) {
  2113. intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
  2114. intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
  2115. } else if (device == 1) {
  2116. intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
  2117. intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
  2118. }
  2119. intel_sdvo_connector_init(intel_sdvo_connector,
  2120. intel_sdvo);
  2121. return true;
  2122. }
  2123. static bool
  2124. intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
  2125. {
  2126. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2127. struct drm_connector *connector;
  2128. struct intel_connector *intel_connector;
  2129. struct intel_sdvo_connector *intel_sdvo_connector;
  2130. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2131. if (!intel_sdvo_connector)
  2132. return false;
  2133. intel_connector = &intel_sdvo_connector->base;
  2134. connector = &intel_connector->base;
  2135. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  2136. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  2137. if (device == 0) {
  2138. intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
  2139. intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
  2140. } else if (device == 1) {
  2141. intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
  2142. intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
  2143. }
  2144. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2145. if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
  2146. goto err;
  2147. return true;
  2148. err:
  2149. intel_sdvo_destroy(connector);
  2150. return false;
  2151. }
  2152. static bool
  2153. intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
  2154. {
  2155. intel_sdvo->is_tv = false;
  2156. intel_sdvo->is_lvds = false;
  2157. /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
  2158. if (flags & SDVO_OUTPUT_TMDS0)
  2159. if (!intel_sdvo_dvi_init(intel_sdvo, 0))
  2160. return false;
  2161. if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
  2162. if (!intel_sdvo_dvi_init(intel_sdvo, 1))
  2163. return false;
  2164. /* TV has no XXX1 function block */
  2165. if (flags & SDVO_OUTPUT_SVID0)
  2166. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
  2167. return false;
  2168. if (flags & SDVO_OUTPUT_CVBS0)
  2169. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
  2170. return false;
  2171. if (flags & SDVO_OUTPUT_YPRPB0)
  2172. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
  2173. return false;
  2174. if (flags & SDVO_OUTPUT_RGB0)
  2175. if (!intel_sdvo_analog_init(intel_sdvo, 0))
  2176. return false;
  2177. if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
  2178. if (!intel_sdvo_analog_init(intel_sdvo, 1))
  2179. return false;
  2180. if (flags & SDVO_OUTPUT_LVDS0)
  2181. if (!intel_sdvo_lvds_init(intel_sdvo, 0))
  2182. return false;
  2183. if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
  2184. if (!intel_sdvo_lvds_init(intel_sdvo, 1))
  2185. return false;
  2186. if ((flags & SDVO_OUTPUT_MASK) == 0) {
  2187. unsigned char bytes[2];
  2188. intel_sdvo->controlled_output = 0;
  2189. memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
  2190. DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
  2191. SDVO_NAME(intel_sdvo),
  2192. bytes[0], bytes[1]);
  2193. return false;
  2194. }
  2195. intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2196. return true;
  2197. }
  2198. static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
  2199. {
  2200. struct drm_device *dev = intel_sdvo->base.base.dev;
  2201. struct drm_connector *connector, *tmp;
  2202. list_for_each_entry_safe(connector, tmp,
  2203. &dev->mode_config.connector_list, head) {
  2204. if (intel_attached_encoder(connector) == &intel_sdvo->base)
  2205. intel_sdvo_destroy(connector);
  2206. }
  2207. }
  2208. static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
  2209. struct intel_sdvo_connector *intel_sdvo_connector,
  2210. int type)
  2211. {
  2212. struct drm_device *dev = intel_sdvo->base.base.dev;
  2213. struct intel_sdvo_tv_format format;
  2214. uint32_t format_map, i;
  2215. if (!intel_sdvo_set_target_output(intel_sdvo, type))
  2216. return false;
  2217. BUILD_BUG_ON(sizeof(format) != 6);
  2218. if (!intel_sdvo_get_value(intel_sdvo,
  2219. SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
  2220. &format, sizeof(format)))
  2221. return false;
  2222. memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
  2223. if (format_map == 0)
  2224. return false;
  2225. intel_sdvo_connector->format_supported_num = 0;
  2226. for (i = 0 ; i < TV_FORMAT_NUM; i++)
  2227. if (format_map & (1 << i))
  2228. intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
  2229. intel_sdvo_connector->tv_format =
  2230. drm_property_create(dev, DRM_MODE_PROP_ENUM,
  2231. "mode", intel_sdvo_connector->format_supported_num);
  2232. if (!intel_sdvo_connector->tv_format)
  2233. return false;
  2234. for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
  2235. drm_property_add_enum(
  2236. intel_sdvo_connector->tv_format, i,
  2237. i, tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
  2238. intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[0];
  2239. drm_object_attach_property(&intel_sdvo_connector->base.base.base,
  2240. intel_sdvo_connector->tv_format, 0);
  2241. return true;
  2242. }
  2243. #define ENHANCEMENT(name, NAME) do { \
  2244. if (enhancements.name) { \
  2245. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
  2246. !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
  2247. return false; \
  2248. intel_sdvo_connector->max_##name = data_value[0]; \
  2249. intel_sdvo_connector->cur_##name = response; \
  2250. intel_sdvo_connector->name = \
  2251. drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
  2252. if (!intel_sdvo_connector->name) return false; \
  2253. drm_object_attach_property(&connector->base, \
  2254. intel_sdvo_connector->name, \
  2255. intel_sdvo_connector->cur_##name); \
  2256. DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
  2257. data_value[0], data_value[1], response); \
  2258. } \
  2259. } while (0)
  2260. static bool
  2261. intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
  2262. struct intel_sdvo_connector *intel_sdvo_connector,
  2263. struct intel_sdvo_enhancements_reply enhancements)
  2264. {
  2265. struct drm_device *dev = intel_sdvo->base.base.dev;
  2266. struct drm_connector *connector = &intel_sdvo_connector->base.base;
  2267. uint16_t response, data_value[2];
  2268. /* when horizontal overscan is supported, Add the left/right property */
  2269. if (enhancements.overscan_h) {
  2270. if (!intel_sdvo_get_value(intel_sdvo,
  2271. SDVO_CMD_GET_MAX_OVERSCAN_H,
  2272. &data_value, 4))
  2273. return false;
  2274. if (!intel_sdvo_get_value(intel_sdvo,
  2275. SDVO_CMD_GET_OVERSCAN_H,
  2276. &response, 2))
  2277. return false;
  2278. intel_sdvo_connector->max_hscan = data_value[0];
  2279. intel_sdvo_connector->left_margin = data_value[0] - response;
  2280. intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
  2281. intel_sdvo_connector->left =
  2282. drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
  2283. if (!intel_sdvo_connector->left)
  2284. return false;
  2285. drm_object_attach_property(&connector->base,
  2286. intel_sdvo_connector->left,
  2287. intel_sdvo_connector->left_margin);
  2288. intel_sdvo_connector->right =
  2289. drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
  2290. if (!intel_sdvo_connector->right)
  2291. return false;
  2292. drm_object_attach_property(&connector->base,
  2293. intel_sdvo_connector->right,
  2294. intel_sdvo_connector->right_margin);
  2295. DRM_DEBUG_KMS("h_overscan: max %d, "
  2296. "default %d, current %d\n",
  2297. data_value[0], data_value[1], response);
  2298. }
  2299. if (enhancements.overscan_v) {
  2300. if (!intel_sdvo_get_value(intel_sdvo,
  2301. SDVO_CMD_GET_MAX_OVERSCAN_V,
  2302. &data_value, 4))
  2303. return false;
  2304. if (!intel_sdvo_get_value(intel_sdvo,
  2305. SDVO_CMD_GET_OVERSCAN_V,
  2306. &response, 2))
  2307. return false;
  2308. intel_sdvo_connector->max_vscan = data_value[0];
  2309. intel_sdvo_connector->top_margin = data_value[0] - response;
  2310. intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
  2311. intel_sdvo_connector->top =
  2312. drm_property_create_range(dev, 0,
  2313. "top_margin", 0, data_value[0]);
  2314. if (!intel_sdvo_connector->top)
  2315. return false;
  2316. drm_object_attach_property(&connector->base,
  2317. intel_sdvo_connector->top,
  2318. intel_sdvo_connector->top_margin);
  2319. intel_sdvo_connector->bottom =
  2320. drm_property_create_range(dev, 0,
  2321. "bottom_margin", 0, data_value[0]);
  2322. if (!intel_sdvo_connector->bottom)
  2323. return false;
  2324. drm_object_attach_property(&connector->base,
  2325. intel_sdvo_connector->bottom,
  2326. intel_sdvo_connector->bottom_margin);
  2327. DRM_DEBUG_KMS("v_overscan: max %d, "
  2328. "default %d, current %d\n",
  2329. data_value[0], data_value[1], response);
  2330. }
  2331. ENHANCEMENT(hpos, HPOS);
  2332. ENHANCEMENT(vpos, VPOS);
  2333. ENHANCEMENT(saturation, SATURATION);
  2334. ENHANCEMENT(contrast, CONTRAST);
  2335. ENHANCEMENT(hue, HUE);
  2336. ENHANCEMENT(sharpness, SHARPNESS);
  2337. ENHANCEMENT(brightness, BRIGHTNESS);
  2338. ENHANCEMENT(flicker_filter, FLICKER_FILTER);
  2339. ENHANCEMENT(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
  2340. ENHANCEMENT(flicker_filter_2d, FLICKER_FILTER_2D);
  2341. ENHANCEMENT(tv_chroma_filter, TV_CHROMA_FILTER);
  2342. ENHANCEMENT(tv_luma_filter, TV_LUMA_FILTER);
  2343. if (enhancements.dot_crawl) {
  2344. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
  2345. return false;
  2346. intel_sdvo_connector->max_dot_crawl = 1;
  2347. intel_sdvo_connector->cur_dot_crawl = response & 0x1;
  2348. intel_sdvo_connector->dot_crawl =
  2349. drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
  2350. if (!intel_sdvo_connector->dot_crawl)
  2351. return false;
  2352. drm_object_attach_property(&connector->base,
  2353. intel_sdvo_connector->dot_crawl,
  2354. intel_sdvo_connector->cur_dot_crawl);
  2355. DRM_DEBUG_KMS("dot crawl: current %d\n", response);
  2356. }
  2357. return true;
  2358. }
  2359. static bool
  2360. intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
  2361. struct intel_sdvo_connector *intel_sdvo_connector,
  2362. struct intel_sdvo_enhancements_reply enhancements)
  2363. {
  2364. struct drm_device *dev = intel_sdvo->base.base.dev;
  2365. struct drm_connector *connector = &intel_sdvo_connector->base.base;
  2366. uint16_t response, data_value[2];
  2367. ENHANCEMENT(brightness, BRIGHTNESS);
  2368. return true;
  2369. }
  2370. #undef ENHANCEMENT
  2371. static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
  2372. struct intel_sdvo_connector *intel_sdvo_connector)
  2373. {
  2374. union {
  2375. struct intel_sdvo_enhancements_reply reply;
  2376. uint16_t response;
  2377. } enhancements;
  2378. BUILD_BUG_ON(sizeof(enhancements) != 2);
  2379. enhancements.response = 0;
  2380. intel_sdvo_get_value(intel_sdvo,
  2381. SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
  2382. &enhancements, sizeof(enhancements));
  2383. if (enhancements.response == 0) {
  2384. DRM_DEBUG_KMS("No enhancement is supported\n");
  2385. return true;
  2386. }
  2387. if (IS_TV(intel_sdvo_connector))
  2388. return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
  2389. else if (IS_LVDS(intel_sdvo_connector))
  2390. return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
  2391. else
  2392. return true;
  2393. }
  2394. static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
  2395. struct i2c_msg *msgs,
  2396. int num)
  2397. {
  2398. struct intel_sdvo *sdvo = adapter->algo_data;
  2399. if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
  2400. return -EIO;
  2401. return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
  2402. }
  2403. static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
  2404. {
  2405. struct intel_sdvo *sdvo = adapter->algo_data;
  2406. return sdvo->i2c->algo->functionality(sdvo->i2c);
  2407. }
  2408. static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
  2409. .master_xfer = intel_sdvo_ddc_proxy_xfer,
  2410. .functionality = intel_sdvo_ddc_proxy_func
  2411. };
  2412. static bool
  2413. intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
  2414. struct drm_device *dev)
  2415. {
  2416. sdvo->ddc.owner = THIS_MODULE;
  2417. sdvo->ddc.class = I2C_CLASS_DDC;
  2418. snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
  2419. sdvo->ddc.dev.parent = &dev->pdev->dev;
  2420. sdvo->ddc.algo_data = sdvo;
  2421. sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
  2422. return i2c_add_adapter(&sdvo->ddc) == 0;
  2423. }
  2424. bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
  2425. {
  2426. struct drm_i915_private *dev_priv = dev->dev_private;
  2427. struct intel_encoder *intel_encoder;
  2428. struct intel_sdvo *intel_sdvo;
  2429. int i;
  2430. intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
  2431. if (!intel_sdvo)
  2432. return false;
  2433. intel_sdvo->sdvo_reg = sdvo_reg;
  2434. intel_sdvo->is_sdvob = is_sdvob;
  2435. intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, intel_sdvo) >> 1;
  2436. intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg);
  2437. if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev))
  2438. goto err_i2c_bus;
  2439. /* encoder type will be decided later */
  2440. intel_encoder = &intel_sdvo->base;
  2441. intel_encoder->type = INTEL_OUTPUT_SDVO;
  2442. drm_encoder_init(dev, &intel_encoder->base, &intel_sdvo_enc_funcs, 0);
  2443. /* Read the regs to test if we can talk to the device */
  2444. for (i = 0; i < 0x40; i++) {
  2445. u8 byte;
  2446. if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
  2447. DRM_DEBUG_KMS("No SDVO device found on %s\n",
  2448. SDVO_NAME(intel_sdvo));
  2449. goto err;
  2450. }
  2451. }
  2452. intel_encoder->compute_config = intel_sdvo_compute_config;
  2453. intel_encoder->disable = intel_disable_sdvo;
  2454. intel_encoder->mode_set = intel_sdvo_mode_set;
  2455. intel_encoder->enable = intel_enable_sdvo;
  2456. intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
  2457. intel_encoder->get_config = intel_sdvo_get_config;
  2458. /* In default case sdvo lvds is false */
  2459. if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
  2460. goto err;
  2461. if (intel_sdvo_output_setup(intel_sdvo,
  2462. intel_sdvo->caps.output_flags) != true) {
  2463. DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
  2464. SDVO_NAME(intel_sdvo));
  2465. /* Output_setup can leave behind connectors! */
  2466. goto err_output;
  2467. }
  2468. /* Only enable the hotplug irq if we need it, to work around noisy
  2469. * hotplug lines.
  2470. */
  2471. if (intel_sdvo->hotplug_active) {
  2472. intel_encoder->hpd_pin =
  2473. intel_sdvo->is_sdvob ? HPD_SDVO_B : HPD_SDVO_C;
  2474. }
  2475. /*
  2476. * Cloning SDVO with anything is often impossible, since the SDVO
  2477. * encoder can request a special input timing mode. And even if that's
  2478. * not the case we have evidence that cloning a plain unscaled mode with
  2479. * VGA doesn't really work. Furthermore the cloning flags are way too
  2480. * simplistic anyway to express such constraints, so just give up on
  2481. * cloning for SDVO encoders.
  2482. */
  2483. intel_sdvo->base.cloneable = false;
  2484. intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
  2485. /* Set the input timing to the screen. Assume always input 0. */
  2486. if (!intel_sdvo_set_target_input(intel_sdvo))
  2487. goto err_output;
  2488. if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
  2489. &intel_sdvo->pixel_clock_min,
  2490. &intel_sdvo->pixel_clock_max))
  2491. goto err_output;
  2492. DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
  2493. "clock range %dMHz - %dMHz, "
  2494. "input 1: %c, input 2: %c, "
  2495. "output 1: %c, output 2: %c\n",
  2496. SDVO_NAME(intel_sdvo),
  2497. intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
  2498. intel_sdvo->caps.device_rev_id,
  2499. intel_sdvo->pixel_clock_min / 1000,
  2500. intel_sdvo->pixel_clock_max / 1000,
  2501. (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
  2502. (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
  2503. /* check currently supported outputs */
  2504. intel_sdvo->caps.output_flags &
  2505. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
  2506. intel_sdvo->caps.output_flags &
  2507. (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
  2508. return true;
  2509. err_output:
  2510. intel_sdvo_output_cleanup(intel_sdvo);
  2511. err:
  2512. drm_encoder_cleanup(&intel_encoder->base);
  2513. i2c_del_adapter(&intel_sdvo->ddc);
  2514. err_i2c_bus:
  2515. intel_sdvo_unselect_i2c_bus(intel_sdvo);
  2516. kfree(intel_sdvo);
  2517. return false;
  2518. }