intel_sdvo.c 90 KB

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