intel_sdvo.c 90 KB

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