intel_sdvo.c 90 KB

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