intel_sdvo.c 90 KB

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