intel_sdvo.c 91 KB

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