intel_sdvo.c 89 KB

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