intel_sdvo.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904
  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/delay.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "drm_crtc.h"
  33. #include "intel_drv.h"
  34. #include "drm_edid.h"
  35. #include "i915_drm.h"
  36. #include "i915_drv.h"
  37. #include "intel_sdvo_regs.h"
  38. #include <linux/dmi.h>
  39. static char *tv_format_names[] = {
  40. "NTSC_M" , "NTSC_J" , "NTSC_443",
  41. "PAL_B" , "PAL_D" , "PAL_G" ,
  42. "PAL_H" , "PAL_I" , "PAL_M" ,
  43. "PAL_N" , "PAL_NC" , "PAL_60" ,
  44. "SECAM_B" , "SECAM_D" , "SECAM_G" ,
  45. "SECAM_K" , "SECAM_K1", "SECAM_L" ,
  46. "SECAM_60"
  47. };
  48. #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
  49. struct intel_sdvo_priv {
  50. u8 slave_addr;
  51. /* Register for the SDVO device: SDVOB or SDVOC */
  52. int output_device;
  53. /* Active outputs controlled by this SDVO output */
  54. uint16_t controlled_output;
  55. /*
  56. * Capabilities of the SDVO device returned by
  57. * i830_sdvo_get_capabilities()
  58. */
  59. struct intel_sdvo_caps caps;
  60. /* Pixel clock limitations reported by the SDVO device, in kHz */
  61. int pixel_clock_min, pixel_clock_max;
  62. /*
  63. * For multiple function SDVO device,
  64. * this is for current attached outputs.
  65. */
  66. uint16_t attached_output;
  67. /**
  68. * This is set if we're going to treat the device as TV-out.
  69. *
  70. * While we have these nice friendly flags for output types that ought
  71. * to decide this for us, the S-Video output on our HDMI+S-Video card
  72. * shows up as RGB1 (VGA).
  73. */
  74. bool is_tv;
  75. /* This is for current tv format name */
  76. char *tv_format_name;
  77. /* This contains all current supported TV format */
  78. char *tv_format_supported[TV_FORMAT_NUM];
  79. int format_supported_num;
  80. struct drm_property *tv_format_property;
  81. struct drm_property *tv_format_name_property[TV_FORMAT_NUM];
  82. /**
  83. * This is set if we treat the device as HDMI, instead of DVI.
  84. */
  85. bool is_hdmi;
  86. /**
  87. * This is set if we detect output of sdvo device as LVDS.
  88. */
  89. bool is_lvds;
  90. /**
  91. * This is sdvo flags for input timing.
  92. */
  93. uint8_t sdvo_flags;
  94. /**
  95. * This is sdvo fixed pannel mode pointer
  96. */
  97. struct drm_display_mode *sdvo_lvds_fixed_mode;
  98. /**
  99. * Returned SDTV resolutions allowed for the current format, if the
  100. * device reported it.
  101. */
  102. struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
  103. /*
  104. * supported encoding mode, used to determine whether HDMI is
  105. * supported
  106. */
  107. struct intel_sdvo_encode encode;
  108. /* DDC bus used by this SDVO output */
  109. uint8_t ddc_bus;
  110. /* Mac mini hack -- use the same DDC as the analog connector */
  111. struct i2c_adapter *analog_ddc_bus;
  112. int save_sdvo_mult;
  113. u16 save_active_outputs;
  114. struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2;
  115. struct intel_sdvo_dtd save_output_dtd[16];
  116. u32 save_SDVOX;
  117. /* add the property for the SDVO-TV */
  118. struct drm_property *left_property;
  119. struct drm_property *right_property;
  120. struct drm_property *top_property;
  121. struct drm_property *bottom_property;
  122. struct drm_property *hpos_property;
  123. struct drm_property *vpos_property;
  124. /* add the property for the SDVO-TV/LVDS */
  125. struct drm_property *brightness_property;
  126. struct drm_property *contrast_property;
  127. struct drm_property *saturation_property;
  128. struct drm_property *hue_property;
  129. /* Add variable to record current setting for the above property */
  130. u32 left_margin, right_margin, top_margin, bottom_margin;
  131. /* this is to get the range of margin.*/
  132. u32 max_hscan, max_vscan;
  133. u32 max_hpos, cur_hpos;
  134. u32 max_vpos, cur_vpos;
  135. u32 cur_brightness, max_brightness;
  136. u32 cur_contrast, max_contrast;
  137. u32 cur_saturation, max_saturation;
  138. u32 cur_hue, max_hue;
  139. };
  140. static bool
  141. intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags);
  142. /**
  143. * Writes the SDVOB or SDVOC with the given value, but always writes both
  144. * SDVOB and SDVOC to work around apparent hardware issues (according to
  145. * comments in the BIOS).
  146. */
  147. static void intel_sdvo_write_sdvox(struct intel_output *intel_output, u32 val)
  148. {
  149. struct drm_device *dev = intel_output->base.dev;
  150. struct drm_i915_private *dev_priv = dev->dev_private;
  151. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  152. u32 bval = val, cval = val;
  153. int i;
  154. if (sdvo_priv->output_device == SDVOB) {
  155. cval = I915_READ(SDVOC);
  156. } else {
  157. bval = I915_READ(SDVOB);
  158. }
  159. /*
  160. * Write the registers twice for luck. Sometimes,
  161. * writing them only once doesn't appear to 'stick'.
  162. * The BIOS does this too. Yay, magic
  163. */
  164. for (i = 0; i < 2; i++)
  165. {
  166. I915_WRITE(SDVOB, bval);
  167. I915_READ(SDVOB);
  168. I915_WRITE(SDVOC, cval);
  169. I915_READ(SDVOC);
  170. }
  171. }
  172. static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
  173. u8 *ch)
  174. {
  175. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  176. u8 out_buf[2];
  177. u8 buf[2];
  178. int ret;
  179. struct i2c_msg msgs[] = {
  180. {
  181. .addr = sdvo_priv->slave_addr >> 1,
  182. .flags = 0,
  183. .len = 1,
  184. .buf = out_buf,
  185. },
  186. {
  187. .addr = sdvo_priv->slave_addr >> 1,
  188. .flags = I2C_M_RD,
  189. .len = 1,
  190. .buf = buf,
  191. }
  192. };
  193. out_buf[0] = addr;
  194. out_buf[1] = 0;
  195. if ((ret = i2c_transfer(intel_output->i2c_bus, msgs, 2)) == 2)
  196. {
  197. *ch = buf[0];
  198. return true;
  199. }
  200. DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
  201. return false;
  202. }
  203. static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
  204. u8 ch)
  205. {
  206. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  207. u8 out_buf[2];
  208. struct i2c_msg msgs[] = {
  209. {
  210. .addr = sdvo_priv->slave_addr >> 1,
  211. .flags = 0,
  212. .len = 2,
  213. .buf = out_buf,
  214. }
  215. };
  216. out_buf[0] = addr;
  217. out_buf[1] = ch;
  218. if (i2c_transfer(intel_output->i2c_bus, msgs, 1) == 1)
  219. {
  220. return true;
  221. }
  222. return false;
  223. }
  224. #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
  225. /** Mapping of command numbers to names, for debug output */
  226. static const struct _sdvo_cmd_name {
  227. u8 cmd;
  228. char *name;
  229. } sdvo_cmd_names[] = {
  230. SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
  231. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
  232. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
  233. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
  234. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
  235. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
  236. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
  237. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
  238. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
  239. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
  240. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
  241. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
  242. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
  243. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
  244. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
  245. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
  246. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
  247. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  248. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
  249. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  250. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
  251. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
  252. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
  253. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
  254. SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
  255. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
  256. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
  257. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
  258. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
  259. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
  260. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
  261. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
  262. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
  263. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
  264. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
  265. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
  266. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
  267. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
  268. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
  269. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
  270. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
  271. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
  272. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
  273. /* Add the op code for SDVO enhancements */
  274. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_H),
  275. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_H),
  276. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_H),
  277. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_POSITION_V),
  278. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POSITION_V),
  279. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_POSITION_V),
  280. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
  281. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
  282. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
  283. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
  284. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
  285. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
  286. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
  287. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
  288. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
  289. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
  290. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
  291. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
  292. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
  293. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
  294. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
  295. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
  296. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
  297. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
  298. /* HDMI op code */
  299. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
  300. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
  301. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
  302. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
  303. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
  304. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
  305. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
  306. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
  307. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
  308. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
  309. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
  310. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
  311. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
  312. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
  313. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
  314. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
  315. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
  316. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
  317. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
  318. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
  319. };
  320. #define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC")
  321. #define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv)
  322. static void intel_sdvo_debug_write(struct intel_output *intel_output, u8 cmd,
  323. void *args, int args_len)
  324. {
  325. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  326. int i;
  327. DRM_DEBUG_KMS("%s: W: %02X ",
  328. SDVO_NAME(sdvo_priv), cmd);
  329. for (i = 0; i < args_len; i++)
  330. DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
  331. for (; i < 8; i++)
  332. DRM_LOG_KMS(" ");
  333. for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
  334. if (cmd == sdvo_cmd_names[i].cmd) {
  335. DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
  336. break;
  337. }
  338. }
  339. if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
  340. DRM_LOG_KMS("(%02X)", cmd);
  341. DRM_LOG_KMS("\n");
  342. }
  343. static void intel_sdvo_write_cmd(struct intel_output *intel_output, u8 cmd,
  344. void *args, int args_len)
  345. {
  346. int i;
  347. intel_sdvo_debug_write(intel_output, cmd, args, args_len);
  348. for (i = 0; i < args_len; i++) {
  349. intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0 - i,
  350. ((u8*)args)[i]);
  351. }
  352. intel_sdvo_write_byte(intel_output, SDVO_I2C_OPCODE, cmd);
  353. }
  354. static const char *cmd_status_names[] = {
  355. "Power on",
  356. "Success",
  357. "Not supported",
  358. "Invalid arg",
  359. "Pending",
  360. "Target not specified",
  361. "Scaling not supported"
  362. };
  363. static void intel_sdvo_debug_response(struct intel_output *intel_output,
  364. void *response, int response_len,
  365. u8 status)
  366. {
  367. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  368. int i;
  369. DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv));
  370. for (i = 0; i < response_len; i++)
  371. DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
  372. for (; i < 8; i++)
  373. DRM_LOG_KMS(" ");
  374. if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
  375. DRM_LOG_KMS("(%s)", cmd_status_names[status]);
  376. else
  377. DRM_LOG_KMS("(??? %d)", status);
  378. DRM_LOG_KMS("\n");
  379. }
  380. static u8 intel_sdvo_read_response(struct intel_output *intel_output,
  381. void *response, int response_len)
  382. {
  383. int i;
  384. u8 status;
  385. u8 retry = 50;
  386. while (retry--) {
  387. /* Read the command response */
  388. for (i = 0; i < response_len; i++) {
  389. intel_sdvo_read_byte(intel_output,
  390. SDVO_I2C_RETURN_0 + i,
  391. &((u8 *)response)[i]);
  392. }
  393. /* read the return status */
  394. intel_sdvo_read_byte(intel_output, SDVO_I2C_CMD_STATUS,
  395. &status);
  396. intel_sdvo_debug_response(intel_output, response, response_len,
  397. status);
  398. if (status != SDVO_CMD_STATUS_PENDING)
  399. return status;
  400. mdelay(50);
  401. }
  402. return status;
  403. }
  404. static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
  405. {
  406. if (mode->clock >= 100000)
  407. return 1;
  408. else if (mode->clock >= 50000)
  409. return 2;
  410. else
  411. return 4;
  412. }
  413. /**
  414. * Try to read the response after issuie the DDC switch command. But it
  415. * is noted that we must do the action of reading response and issuing DDC
  416. * switch command in one I2C transaction. Otherwise when we try to start
  417. * another I2C transaction after issuing the DDC bus switch, it will be
  418. * switched to the internal SDVO register.
  419. */
  420. static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output,
  421. u8 target)
  422. {
  423. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  424. u8 out_buf[2], cmd_buf[2], ret_value[2], ret;
  425. struct i2c_msg msgs[] = {
  426. {
  427. .addr = sdvo_priv->slave_addr >> 1,
  428. .flags = 0,
  429. .len = 2,
  430. .buf = out_buf,
  431. },
  432. /* the following two are to read the response */
  433. {
  434. .addr = sdvo_priv->slave_addr >> 1,
  435. .flags = 0,
  436. .len = 1,
  437. .buf = cmd_buf,
  438. },
  439. {
  440. .addr = sdvo_priv->slave_addr >> 1,
  441. .flags = I2C_M_RD,
  442. .len = 1,
  443. .buf = ret_value,
  444. },
  445. };
  446. intel_sdvo_debug_write(intel_output, SDVO_CMD_SET_CONTROL_BUS_SWITCH,
  447. &target, 1);
  448. /* write the DDC switch command argument */
  449. intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0, target);
  450. out_buf[0] = SDVO_I2C_OPCODE;
  451. out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH;
  452. cmd_buf[0] = SDVO_I2C_CMD_STATUS;
  453. cmd_buf[1] = 0;
  454. ret_value[0] = 0;
  455. ret_value[1] = 0;
  456. ret = i2c_transfer(intel_output->i2c_bus, msgs, 3);
  457. if (ret != 3) {
  458. /* failure in I2C transfer */
  459. DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
  460. return;
  461. }
  462. if (ret_value[0] != SDVO_CMD_STATUS_SUCCESS) {
  463. DRM_DEBUG_KMS("DDC switch command returns response %d\n",
  464. ret_value[0]);
  465. return;
  466. }
  467. return;
  468. }
  469. static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool target_0, bool target_1)
  470. {
  471. struct intel_sdvo_set_target_input_args targets = {0};
  472. u8 status;
  473. if (target_0 && target_1)
  474. return SDVO_CMD_STATUS_NOTSUPP;
  475. if (target_1)
  476. targets.target_1 = 1;
  477. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_INPUT, &targets,
  478. sizeof(targets));
  479. status = intel_sdvo_read_response(intel_output, NULL, 0);
  480. return (status == SDVO_CMD_STATUS_SUCCESS);
  481. }
  482. /**
  483. * Return whether each input is trained.
  484. *
  485. * This function is making an assumption about the layout of the response,
  486. * which should be checked against the docs.
  487. */
  488. static bool intel_sdvo_get_trained_inputs(struct intel_output *intel_output, bool *input_1, bool *input_2)
  489. {
  490. struct intel_sdvo_get_trained_inputs_response response;
  491. u8 status;
  492. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
  493. status = intel_sdvo_read_response(intel_output, &response, sizeof(response));
  494. if (status != SDVO_CMD_STATUS_SUCCESS)
  495. return false;
  496. *input_1 = response.input0_trained;
  497. *input_2 = response.input1_trained;
  498. return true;
  499. }
  500. static bool intel_sdvo_get_active_outputs(struct intel_output *intel_output,
  501. u16 *outputs)
  502. {
  503. u8 status;
  504. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_OUTPUTS, NULL, 0);
  505. status = intel_sdvo_read_response(intel_output, outputs, sizeof(*outputs));
  506. return (status == SDVO_CMD_STATUS_SUCCESS);
  507. }
  508. static bool intel_sdvo_set_active_outputs(struct intel_output *intel_output,
  509. u16 outputs)
  510. {
  511. u8 status;
  512. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
  513. sizeof(outputs));
  514. status = intel_sdvo_read_response(intel_output, NULL, 0);
  515. return (status == SDVO_CMD_STATUS_SUCCESS);
  516. }
  517. static bool intel_sdvo_set_encoder_power_state(struct intel_output *intel_output,
  518. int mode)
  519. {
  520. u8 status, state = SDVO_ENCODER_STATE_ON;
  521. switch (mode) {
  522. case DRM_MODE_DPMS_ON:
  523. state = SDVO_ENCODER_STATE_ON;
  524. break;
  525. case DRM_MODE_DPMS_STANDBY:
  526. state = SDVO_ENCODER_STATE_STANDBY;
  527. break;
  528. case DRM_MODE_DPMS_SUSPEND:
  529. state = SDVO_ENCODER_STATE_SUSPEND;
  530. break;
  531. case DRM_MODE_DPMS_OFF:
  532. state = SDVO_ENCODER_STATE_OFF;
  533. break;
  534. }
  535. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
  536. sizeof(state));
  537. status = intel_sdvo_read_response(intel_output, NULL, 0);
  538. return (status == SDVO_CMD_STATUS_SUCCESS);
  539. }
  540. static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output *intel_output,
  541. int *clock_min,
  542. int *clock_max)
  543. {
  544. struct intel_sdvo_pixel_clock_range clocks;
  545. u8 status;
  546. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
  547. NULL, 0);
  548. status = intel_sdvo_read_response(intel_output, &clocks, sizeof(clocks));
  549. if (status != SDVO_CMD_STATUS_SUCCESS)
  550. return false;
  551. /* Convert the values from units of 10 kHz to kHz. */
  552. *clock_min = clocks.min * 10;
  553. *clock_max = clocks.max * 10;
  554. return true;
  555. }
  556. static bool intel_sdvo_set_target_output(struct intel_output *intel_output,
  557. u16 outputs)
  558. {
  559. u8 status;
  560. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
  561. sizeof(outputs));
  562. status = intel_sdvo_read_response(intel_output, NULL, 0);
  563. return (status == SDVO_CMD_STATUS_SUCCESS);
  564. }
  565. static bool intel_sdvo_get_timing(struct intel_output *intel_output, u8 cmd,
  566. struct intel_sdvo_dtd *dtd)
  567. {
  568. u8 status;
  569. intel_sdvo_write_cmd(intel_output, cmd, NULL, 0);
  570. status = intel_sdvo_read_response(intel_output, &dtd->part1,
  571. sizeof(dtd->part1));
  572. if (status != SDVO_CMD_STATUS_SUCCESS)
  573. return false;
  574. intel_sdvo_write_cmd(intel_output, cmd + 1, NULL, 0);
  575. status = intel_sdvo_read_response(intel_output, &dtd->part2,
  576. sizeof(dtd->part2));
  577. if (status != SDVO_CMD_STATUS_SUCCESS)
  578. return false;
  579. return true;
  580. }
  581. static bool intel_sdvo_get_input_timing(struct intel_output *intel_output,
  582. struct intel_sdvo_dtd *dtd)
  583. {
  584. return intel_sdvo_get_timing(intel_output,
  585. SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
  586. }
  587. static bool intel_sdvo_get_output_timing(struct intel_output *intel_output,
  588. struct intel_sdvo_dtd *dtd)
  589. {
  590. return intel_sdvo_get_timing(intel_output,
  591. SDVO_CMD_GET_OUTPUT_TIMINGS_PART1, dtd);
  592. }
  593. static bool intel_sdvo_set_timing(struct intel_output *intel_output, u8 cmd,
  594. struct intel_sdvo_dtd *dtd)
  595. {
  596. u8 status;
  597. intel_sdvo_write_cmd(intel_output, cmd, &dtd->part1, sizeof(dtd->part1));
  598. status = intel_sdvo_read_response(intel_output, NULL, 0);
  599. if (status != SDVO_CMD_STATUS_SUCCESS)
  600. return false;
  601. intel_sdvo_write_cmd(intel_output, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  602. status = intel_sdvo_read_response(intel_output, NULL, 0);
  603. if (status != SDVO_CMD_STATUS_SUCCESS)
  604. return false;
  605. return true;
  606. }
  607. static bool intel_sdvo_set_input_timing(struct intel_output *intel_output,
  608. struct intel_sdvo_dtd *dtd)
  609. {
  610. return intel_sdvo_set_timing(intel_output,
  611. SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
  612. }
  613. static bool intel_sdvo_set_output_timing(struct intel_output *intel_output,
  614. struct intel_sdvo_dtd *dtd)
  615. {
  616. return intel_sdvo_set_timing(intel_output,
  617. SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
  618. }
  619. static bool
  620. intel_sdvo_create_preferred_input_timing(struct intel_output *output,
  621. uint16_t clock,
  622. uint16_t width,
  623. uint16_t height)
  624. {
  625. struct intel_sdvo_preferred_input_timing_args args;
  626. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  627. uint8_t status;
  628. memset(&args, 0, sizeof(args));
  629. args.clock = clock;
  630. args.width = width;
  631. args.height = height;
  632. args.interlace = 0;
  633. if (sdvo_priv->is_lvds &&
  634. (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
  635. sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
  636. args.scaled = 1;
  637. intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
  638. &args, sizeof(args));
  639. status = intel_sdvo_read_response(output, NULL, 0);
  640. if (status != SDVO_CMD_STATUS_SUCCESS)
  641. return false;
  642. return true;
  643. }
  644. static bool intel_sdvo_get_preferred_input_timing(struct intel_output *output,
  645. struct intel_sdvo_dtd *dtd)
  646. {
  647. bool status;
  648. intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
  649. NULL, 0);
  650. status = intel_sdvo_read_response(output, &dtd->part1,
  651. sizeof(dtd->part1));
  652. if (status != SDVO_CMD_STATUS_SUCCESS)
  653. return false;
  654. intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
  655. NULL, 0);
  656. status = intel_sdvo_read_response(output, &dtd->part2,
  657. sizeof(dtd->part2));
  658. if (status != SDVO_CMD_STATUS_SUCCESS)
  659. return false;
  660. return false;
  661. }
  662. static int intel_sdvo_get_clock_rate_mult(struct intel_output *intel_output)
  663. {
  664. u8 response, status;
  665. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_CLOCK_RATE_MULT, NULL, 0);
  666. status = intel_sdvo_read_response(intel_output, &response, 1);
  667. if (status != SDVO_CMD_STATUS_SUCCESS) {
  668. DRM_DEBUG_KMS("Couldn't get SDVO clock rate multiplier\n");
  669. return SDVO_CLOCK_RATE_MULT_1X;
  670. } else {
  671. DRM_DEBUG_KMS("Current clock rate multiplier: %d\n", response);
  672. }
  673. return response;
  674. }
  675. static bool intel_sdvo_set_clock_rate_mult(struct intel_output *intel_output, u8 val)
  676. {
  677. u8 status;
  678. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
  679. status = intel_sdvo_read_response(intel_output, NULL, 0);
  680. if (status != SDVO_CMD_STATUS_SUCCESS)
  681. return false;
  682. return true;
  683. }
  684. static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
  685. struct drm_display_mode *mode)
  686. {
  687. uint16_t width, height;
  688. uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
  689. uint16_t h_sync_offset, v_sync_offset;
  690. width = mode->crtc_hdisplay;
  691. height = mode->crtc_vdisplay;
  692. /* do some mode translations */
  693. h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
  694. h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
  695. v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
  696. v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
  697. h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
  698. v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
  699. dtd->part1.clock = mode->clock / 10;
  700. dtd->part1.h_active = width & 0xff;
  701. dtd->part1.h_blank = h_blank_len & 0xff;
  702. dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
  703. ((h_blank_len >> 8) & 0xf);
  704. dtd->part1.v_active = height & 0xff;
  705. dtd->part1.v_blank = v_blank_len & 0xff;
  706. dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
  707. ((v_blank_len >> 8) & 0xf);
  708. dtd->part2.h_sync_off = h_sync_offset & 0xff;
  709. dtd->part2.h_sync_width = h_sync_len & 0xff;
  710. dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
  711. (v_sync_len & 0xf);
  712. dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
  713. ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
  714. ((v_sync_len & 0x30) >> 4);
  715. dtd->part2.dtd_flags = 0x18;
  716. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  717. dtd->part2.dtd_flags |= 0x2;
  718. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  719. dtd->part2.dtd_flags |= 0x4;
  720. dtd->part2.sdvo_flags = 0;
  721. dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
  722. dtd->part2.reserved = 0;
  723. }
  724. static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
  725. struct intel_sdvo_dtd *dtd)
  726. {
  727. mode->hdisplay = dtd->part1.h_active;
  728. mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
  729. mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
  730. mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
  731. mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
  732. mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
  733. mode->htotal = mode->hdisplay + dtd->part1.h_blank;
  734. mode->htotal += (dtd->part1.h_high & 0xf) << 8;
  735. mode->vdisplay = dtd->part1.v_active;
  736. mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
  737. mode->vsync_start = mode->vdisplay;
  738. mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
  739. mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
  740. mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
  741. mode->vsync_end = mode->vsync_start +
  742. (dtd->part2.v_sync_off_width & 0xf);
  743. mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
  744. mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
  745. mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
  746. mode->clock = dtd->part1.clock * 10;
  747. mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
  748. if (dtd->part2.dtd_flags & 0x2)
  749. mode->flags |= DRM_MODE_FLAG_PHSYNC;
  750. if (dtd->part2.dtd_flags & 0x4)
  751. mode->flags |= DRM_MODE_FLAG_PVSYNC;
  752. }
  753. static bool intel_sdvo_get_supp_encode(struct intel_output *output,
  754. struct intel_sdvo_encode *encode)
  755. {
  756. uint8_t status;
  757. intel_sdvo_write_cmd(output, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
  758. status = intel_sdvo_read_response(output, encode, sizeof(*encode));
  759. if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
  760. memset(encode, 0, sizeof(*encode));
  761. return false;
  762. }
  763. return true;
  764. }
  765. static bool intel_sdvo_set_encode(struct intel_output *output, uint8_t mode)
  766. {
  767. uint8_t status;
  768. intel_sdvo_write_cmd(output, SDVO_CMD_SET_ENCODE, &mode, 1);
  769. status = intel_sdvo_read_response(output, NULL, 0);
  770. return (status == SDVO_CMD_STATUS_SUCCESS);
  771. }
  772. static bool intel_sdvo_set_colorimetry(struct intel_output *output,
  773. uint8_t mode)
  774. {
  775. uint8_t status;
  776. intel_sdvo_write_cmd(output, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
  777. status = intel_sdvo_read_response(output, NULL, 0);
  778. return (status == SDVO_CMD_STATUS_SUCCESS);
  779. }
  780. #if 0
  781. static void intel_sdvo_dump_hdmi_buf(struct intel_output *output)
  782. {
  783. int i, j;
  784. uint8_t set_buf_index[2];
  785. uint8_t av_split;
  786. uint8_t buf_size;
  787. uint8_t buf[48];
  788. uint8_t *pos;
  789. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
  790. intel_sdvo_read_response(output, &av_split, 1);
  791. for (i = 0; i <= av_split; i++) {
  792. set_buf_index[0] = i; set_buf_index[1] = 0;
  793. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX,
  794. set_buf_index, 2);
  795. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
  796. intel_sdvo_read_response(output, &buf_size, 1);
  797. pos = buf;
  798. for (j = 0; j <= buf_size; j += 8) {
  799. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_DATA,
  800. NULL, 0);
  801. intel_sdvo_read_response(output, pos, 8);
  802. pos += 8;
  803. }
  804. }
  805. }
  806. #endif
  807. static void intel_sdvo_set_hdmi_buf(struct intel_output *output, int index,
  808. uint8_t *data, int8_t size, uint8_t tx_rate)
  809. {
  810. uint8_t set_buf_index[2];
  811. set_buf_index[0] = index;
  812. set_buf_index[1] = 0;
  813. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2);
  814. for (; size > 0; size -= 8) {
  815. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_DATA, data, 8);
  816. data += 8;
  817. }
  818. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
  819. }
  820. static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
  821. {
  822. uint8_t csum = 0;
  823. int i;
  824. for (i = 0; i < size; i++)
  825. csum += data[i];
  826. return 0x100 - csum;
  827. }
  828. #define DIP_TYPE_AVI 0x82
  829. #define DIP_VERSION_AVI 0x2
  830. #define DIP_LEN_AVI 13
  831. struct dip_infoframe {
  832. uint8_t type;
  833. uint8_t version;
  834. uint8_t len;
  835. uint8_t checksum;
  836. union {
  837. struct {
  838. /* Packet Byte #1 */
  839. uint8_t S:2;
  840. uint8_t B:2;
  841. uint8_t A:1;
  842. uint8_t Y:2;
  843. uint8_t rsvd1:1;
  844. /* Packet Byte #2 */
  845. uint8_t R:4;
  846. uint8_t M:2;
  847. uint8_t C:2;
  848. /* Packet Byte #3 */
  849. uint8_t SC:2;
  850. uint8_t Q:2;
  851. uint8_t EC:3;
  852. uint8_t ITC:1;
  853. /* Packet Byte #4 */
  854. uint8_t VIC:7;
  855. uint8_t rsvd2:1;
  856. /* Packet Byte #5 */
  857. uint8_t PR:4;
  858. uint8_t rsvd3:4;
  859. /* Packet Byte #6~13 */
  860. uint16_t top_bar_end;
  861. uint16_t bottom_bar_start;
  862. uint16_t left_bar_end;
  863. uint16_t right_bar_start;
  864. } avi;
  865. struct {
  866. /* Packet Byte #1 */
  867. uint8_t channel_count:3;
  868. uint8_t rsvd1:1;
  869. uint8_t coding_type:4;
  870. /* Packet Byte #2 */
  871. uint8_t sample_size:2; /* SS0, SS1 */
  872. uint8_t sample_frequency:3;
  873. uint8_t rsvd2:3;
  874. /* Packet Byte #3 */
  875. uint8_t coding_type_private:5;
  876. uint8_t rsvd3:3;
  877. /* Packet Byte #4 */
  878. uint8_t channel_allocation;
  879. /* Packet Byte #5 */
  880. uint8_t rsvd4:3;
  881. uint8_t level_shift:4;
  882. uint8_t downmix_inhibit:1;
  883. } audio;
  884. uint8_t payload[28];
  885. } __attribute__ ((packed)) u;
  886. } __attribute__((packed));
  887. static void intel_sdvo_set_avi_infoframe(struct intel_output *output,
  888. struct drm_display_mode * mode)
  889. {
  890. struct dip_infoframe avi_if = {
  891. .type = DIP_TYPE_AVI,
  892. .version = DIP_VERSION_AVI,
  893. .len = DIP_LEN_AVI,
  894. };
  895. avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
  896. 4 + avi_if.len);
  897. intel_sdvo_set_hdmi_buf(output, 1, (uint8_t *)&avi_if, 4 + avi_if.len,
  898. SDVO_HBUF_TX_VSYNC);
  899. }
  900. static void intel_sdvo_set_tv_format(struct intel_output *output)
  901. {
  902. struct intel_sdvo_tv_format format;
  903. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  904. uint32_t format_map, i;
  905. uint8_t status;
  906. for (i = 0; i < TV_FORMAT_NUM; i++)
  907. if (tv_format_names[i] == sdvo_priv->tv_format_name)
  908. break;
  909. format_map = 1 << i;
  910. memset(&format, 0, sizeof(format));
  911. memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ?
  912. sizeof(format) : sizeof(format_map));
  913. intel_sdvo_write_cmd(output, SDVO_CMD_SET_TV_FORMAT, &format_map,
  914. sizeof(format));
  915. status = intel_sdvo_read_response(output, NULL, 0);
  916. if (status != SDVO_CMD_STATUS_SUCCESS)
  917. DRM_DEBUG_KMS("%s: Failed to set TV format\n",
  918. SDVO_NAME(sdvo_priv));
  919. }
  920. static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
  921. struct drm_display_mode *mode,
  922. struct drm_display_mode *adjusted_mode)
  923. {
  924. struct intel_output *output = enc_to_intel_output(encoder);
  925. struct intel_sdvo_priv *dev_priv = output->dev_priv;
  926. if (dev_priv->is_tv) {
  927. struct intel_sdvo_dtd output_dtd;
  928. bool success;
  929. /* We need to construct preferred input timings based on our
  930. * output timings. To do that, we have to set the output
  931. * timings, even though this isn't really the right place in
  932. * the sequence to do it. Oh well.
  933. */
  934. /* Set output timings */
  935. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  936. intel_sdvo_set_target_output(output,
  937. dev_priv->controlled_output);
  938. intel_sdvo_set_output_timing(output, &output_dtd);
  939. /* Set the input timing to the screen. Assume always input 0. */
  940. intel_sdvo_set_target_input(output, true, false);
  941. success = intel_sdvo_create_preferred_input_timing(output,
  942. mode->clock / 10,
  943. mode->hdisplay,
  944. mode->vdisplay);
  945. if (success) {
  946. struct intel_sdvo_dtd input_dtd;
  947. intel_sdvo_get_preferred_input_timing(output,
  948. &input_dtd);
  949. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  950. dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
  951. drm_mode_set_crtcinfo(adjusted_mode, 0);
  952. mode->clock = adjusted_mode->clock;
  953. adjusted_mode->clock *=
  954. intel_sdvo_get_pixel_multiplier(mode);
  955. } else {
  956. return false;
  957. }
  958. } else if (dev_priv->is_lvds) {
  959. struct intel_sdvo_dtd output_dtd;
  960. bool success;
  961. drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
  962. /* Set output timings */
  963. intel_sdvo_get_dtd_from_mode(&output_dtd,
  964. dev_priv->sdvo_lvds_fixed_mode);
  965. intel_sdvo_set_target_output(output,
  966. dev_priv->controlled_output);
  967. intel_sdvo_set_output_timing(output, &output_dtd);
  968. /* Set the input timing to the screen. Assume always input 0. */
  969. intel_sdvo_set_target_input(output, true, false);
  970. success = intel_sdvo_create_preferred_input_timing(
  971. output,
  972. mode->clock / 10,
  973. mode->hdisplay,
  974. mode->vdisplay);
  975. if (success) {
  976. struct intel_sdvo_dtd input_dtd;
  977. intel_sdvo_get_preferred_input_timing(output,
  978. &input_dtd);
  979. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  980. dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
  981. drm_mode_set_crtcinfo(adjusted_mode, 0);
  982. mode->clock = adjusted_mode->clock;
  983. adjusted_mode->clock *=
  984. intel_sdvo_get_pixel_multiplier(mode);
  985. } else {
  986. return false;
  987. }
  988. } else {
  989. /* Make the CRTC code factor in the SDVO pixel multiplier. The
  990. * SDVO device will be told of the multiplier during mode_set.
  991. */
  992. adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
  993. }
  994. return true;
  995. }
  996. static void intel_sdvo_mode_set(struct drm_encoder *encoder,
  997. struct drm_display_mode *mode,
  998. struct drm_display_mode *adjusted_mode)
  999. {
  1000. struct drm_device *dev = encoder->dev;
  1001. struct drm_i915_private *dev_priv = dev->dev_private;
  1002. struct drm_crtc *crtc = encoder->crtc;
  1003. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1004. struct intel_output *output = enc_to_intel_output(encoder);
  1005. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1006. u32 sdvox = 0;
  1007. int sdvo_pixel_multiply;
  1008. struct intel_sdvo_in_out_map in_out;
  1009. struct intel_sdvo_dtd input_dtd;
  1010. u8 status;
  1011. if (!mode)
  1012. return;
  1013. /* First, set the input mapping for the first input to our controlled
  1014. * output. This is only correct if we're a single-input device, in
  1015. * which case the first input is the output from the appropriate SDVO
  1016. * channel on the motherboard. In a two-input device, the first input
  1017. * will be SDVOB and the second SDVOC.
  1018. */
  1019. in_out.in0 = sdvo_priv->controlled_output;
  1020. in_out.in1 = 0;
  1021. intel_sdvo_write_cmd(output, SDVO_CMD_SET_IN_OUT_MAP,
  1022. &in_out, sizeof(in_out));
  1023. status = intel_sdvo_read_response(output, NULL, 0);
  1024. if (sdvo_priv->is_hdmi) {
  1025. intel_sdvo_set_avi_infoframe(output, mode);
  1026. sdvox |= SDVO_AUDIO_ENABLE;
  1027. }
  1028. /* We have tried to get input timing in mode_fixup, and filled into
  1029. adjusted_mode */
  1030. if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
  1031. intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
  1032. input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
  1033. } else
  1034. intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
  1035. /* If it's a TV, we already set the output timing in mode_fixup.
  1036. * Otherwise, the output timing is equal to the input timing.
  1037. */
  1038. if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
  1039. /* Set the output timing to the screen */
  1040. intel_sdvo_set_target_output(output,
  1041. sdvo_priv->controlled_output);
  1042. intel_sdvo_set_output_timing(output, &input_dtd);
  1043. }
  1044. /* Set the input timing to the screen. Assume always input 0. */
  1045. intel_sdvo_set_target_input(output, true, false);
  1046. if (sdvo_priv->is_tv)
  1047. intel_sdvo_set_tv_format(output);
  1048. /* We would like to use intel_sdvo_create_preferred_input_timing() to
  1049. * provide the device with a timing it can support, if it supports that
  1050. * feature. However, presumably we would need to adjust the CRTC to
  1051. * output the preferred timing, and we don't support that currently.
  1052. */
  1053. #if 0
  1054. success = intel_sdvo_create_preferred_input_timing(output, clock,
  1055. width, height);
  1056. if (success) {
  1057. struct intel_sdvo_dtd *input_dtd;
  1058. intel_sdvo_get_preferred_input_timing(output, &input_dtd);
  1059. intel_sdvo_set_input_timing(output, &input_dtd);
  1060. }
  1061. #else
  1062. intel_sdvo_set_input_timing(output, &input_dtd);
  1063. #endif
  1064. switch (intel_sdvo_get_pixel_multiplier(mode)) {
  1065. case 1:
  1066. intel_sdvo_set_clock_rate_mult(output,
  1067. SDVO_CLOCK_RATE_MULT_1X);
  1068. break;
  1069. case 2:
  1070. intel_sdvo_set_clock_rate_mult(output,
  1071. SDVO_CLOCK_RATE_MULT_2X);
  1072. break;
  1073. case 4:
  1074. intel_sdvo_set_clock_rate_mult(output,
  1075. SDVO_CLOCK_RATE_MULT_4X);
  1076. break;
  1077. }
  1078. /* Set the SDVO control regs. */
  1079. if (IS_I965G(dev)) {
  1080. sdvox |= SDVO_BORDER_ENABLE |
  1081. SDVO_VSYNC_ACTIVE_HIGH |
  1082. SDVO_HSYNC_ACTIVE_HIGH;
  1083. } else {
  1084. sdvox |= I915_READ(sdvo_priv->output_device);
  1085. switch (sdvo_priv->output_device) {
  1086. case SDVOB:
  1087. sdvox &= SDVOB_PRESERVE_MASK;
  1088. break;
  1089. case SDVOC:
  1090. sdvox &= SDVOC_PRESERVE_MASK;
  1091. break;
  1092. }
  1093. sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
  1094. }
  1095. if (intel_crtc->pipe == 1)
  1096. sdvox |= SDVO_PIPE_B_SELECT;
  1097. sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
  1098. if (IS_I965G(dev)) {
  1099. /* done in crtc_mode_set as the dpll_md reg must be written early */
  1100. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  1101. /* done in crtc_mode_set as it lives inside the dpll register */
  1102. } else {
  1103. sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
  1104. }
  1105. if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
  1106. sdvox |= SDVO_STALL_SELECT;
  1107. intel_sdvo_write_sdvox(output, sdvox);
  1108. }
  1109. static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
  1110. {
  1111. struct drm_device *dev = encoder->dev;
  1112. struct drm_i915_private *dev_priv = dev->dev_private;
  1113. struct intel_output *intel_output = enc_to_intel_output(encoder);
  1114. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1115. u32 temp;
  1116. if (mode != DRM_MODE_DPMS_ON) {
  1117. intel_sdvo_set_active_outputs(intel_output, 0);
  1118. if (0)
  1119. intel_sdvo_set_encoder_power_state(intel_output, mode);
  1120. if (mode == DRM_MODE_DPMS_OFF) {
  1121. temp = I915_READ(sdvo_priv->output_device);
  1122. if ((temp & SDVO_ENABLE) != 0) {
  1123. intel_sdvo_write_sdvox(intel_output, temp & ~SDVO_ENABLE);
  1124. }
  1125. }
  1126. } else {
  1127. bool input1, input2;
  1128. int i;
  1129. u8 status;
  1130. temp = I915_READ(sdvo_priv->output_device);
  1131. if ((temp & SDVO_ENABLE) == 0)
  1132. intel_sdvo_write_sdvox(intel_output, temp | SDVO_ENABLE);
  1133. for (i = 0; i < 2; i++)
  1134. intel_wait_for_vblank(dev);
  1135. status = intel_sdvo_get_trained_inputs(intel_output, &input1,
  1136. &input2);
  1137. /* Warn if the device reported failure to sync.
  1138. * A lot of SDVO devices fail to notify of sync, but it's
  1139. * a given it the status is a success, we succeeded.
  1140. */
  1141. if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
  1142. DRM_DEBUG_KMS("First %s output reported failure to "
  1143. "sync\n", SDVO_NAME(sdvo_priv));
  1144. }
  1145. if (0)
  1146. intel_sdvo_set_encoder_power_state(intel_output, mode);
  1147. intel_sdvo_set_active_outputs(intel_output, sdvo_priv->controlled_output);
  1148. }
  1149. return;
  1150. }
  1151. static void intel_sdvo_save(struct drm_connector *connector)
  1152. {
  1153. struct drm_device *dev = connector->dev;
  1154. struct drm_i915_private *dev_priv = dev->dev_private;
  1155. struct intel_output *intel_output = to_intel_output(connector);
  1156. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1157. int o;
  1158. sdvo_priv->save_sdvo_mult = intel_sdvo_get_clock_rate_mult(intel_output);
  1159. intel_sdvo_get_active_outputs(intel_output, &sdvo_priv->save_active_outputs);
  1160. if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
  1161. intel_sdvo_set_target_input(intel_output, true, false);
  1162. intel_sdvo_get_input_timing(intel_output,
  1163. &sdvo_priv->save_input_dtd_1);
  1164. }
  1165. if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
  1166. intel_sdvo_set_target_input(intel_output, false, true);
  1167. intel_sdvo_get_input_timing(intel_output,
  1168. &sdvo_priv->save_input_dtd_2);
  1169. }
  1170. for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
  1171. {
  1172. u16 this_output = (1 << o);
  1173. if (sdvo_priv->caps.output_flags & this_output)
  1174. {
  1175. intel_sdvo_set_target_output(intel_output, this_output);
  1176. intel_sdvo_get_output_timing(intel_output,
  1177. &sdvo_priv->save_output_dtd[o]);
  1178. }
  1179. }
  1180. if (sdvo_priv->is_tv) {
  1181. /* XXX: Save TV format/enhancements. */
  1182. }
  1183. sdvo_priv->save_SDVOX = I915_READ(sdvo_priv->output_device);
  1184. }
  1185. static void intel_sdvo_restore(struct drm_connector *connector)
  1186. {
  1187. struct drm_device *dev = connector->dev;
  1188. struct intel_output *intel_output = to_intel_output(connector);
  1189. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1190. int o;
  1191. int i;
  1192. bool input1, input2;
  1193. u8 status;
  1194. intel_sdvo_set_active_outputs(intel_output, 0);
  1195. for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
  1196. {
  1197. u16 this_output = (1 << o);
  1198. if (sdvo_priv->caps.output_flags & this_output) {
  1199. intel_sdvo_set_target_output(intel_output, this_output);
  1200. intel_sdvo_set_output_timing(intel_output, &sdvo_priv->save_output_dtd[o]);
  1201. }
  1202. }
  1203. if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
  1204. intel_sdvo_set_target_input(intel_output, true, false);
  1205. intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_1);
  1206. }
  1207. if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
  1208. intel_sdvo_set_target_input(intel_output, false, true);
  1209. intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_2);
  1210. }
  1211. intel_sdvo_set_clock_rate_mult(intel_output, sdvo_priv->save_sdvo_mult);
  1212. if (sdvo_priv->is_tv) {
  1213. /* XXX: Restore TV format/enhancements. */
  1214. }
  1215. intel_sdvo_write_sdvox(intel_output, sdvo_priv->save_SDVOX);
  1216. if (sdvo_priv->save_SDVOX & SDVO_ENABLE)
  1217. {
  1218. for (i = 0; i < 2; i++)
  1219. intel_wait_for_vblank(dev);
  1220. status = intel_sdvo_get_trained_inputs(intel_output, &input1, &input2);
  1221. if (status == SDVO_CMD_STATUS_SUCCESS && !input1)
  1222. DRM_DEBUG_KMS("First %s output reported failure to "
  1223. "sync\n", SDVO_NAME(sdvo_priv));
  1224. }
  1225. intel_sdvo_set_active_outputs(intel_output, sdvo_priv->save_active_outputs);
  1226. }
  1227. static int intel_sdvo_mode_valid(struct drm_connector *connector,
  1228. struct drm_display_mode *mode)
  1229. {
  1230. struct intel_output *intel_output = to_intel_output(connector);
  1231. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1232. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1233. return MODE_NO_DBLESCAN;
  1234. if (sdvo_priv->pixel_clock_min > mode->clock)
  1235. return MODE_CLOCK_LOW;
  1236. if (sdvo_priv->pixel_clock_max < mode->clock)
  1237. return MODE_CLOCK_HIGH;
  1238. if (sdvo_priv->is_lvds == true) {
  1239. if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
  1240. return MODE_PANEL;
  1241. if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
  1242. return MODE_PANEL;
  1243. if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
  1244. return MODE_PANEL;
  1245. }
  1246. return MODE_OK;
  1247. }
  1248. static bool intel_sdvo_get_capabilities(struct intel_output *intel_output, struct intel_sdvo_caps *caps)
  1249. {
  1250. u8 status;
  1251. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
  1252. status = intel_sdvo_read_response(intel_output, caps, sizeof(*caps));
  1253. if (status != SDVO_CMD_STATUS_SUCCESS)
  1254. return false;
  1255. return true;
  1256. }
  1257. struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
  1258. {
  1259. struct drm_connector *connector = NULL;
  1260. struct intel_output *iout = NULL;
  1261. struct intel_sdvo_priv *sdvo;
  1262. /* find the sdvo connector */
  1263. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1264. iout = to_intel_output(connector);
  1265. if (iout->type != INTEL_OUTPUT_SDVO)
  1266. continue;
  1267. sdvo = iout->dev_priv;
  1268. if (sdvo->output_device == SDVOB && sdvoB)
  1269. return connector;
  1270. if (sdvo->output_device == SDVOC && !sdvoB)
  1271. return connector;
  1272. }
  1273. return NULL;
  1274. }
  1275. int intel_sdvo_supports_hotplug(struct drm_connector *connector)
  1276. {
  1277. u8 response[2];
  1278. u8 status;
  1279. struct intel_output *intel_output;
  1280. DRM_DEBUG_KMS("\n");
  1281. if (!connector)
  1282. return 0;
  1283. intel_output = to_intel_output(connector);
  1284. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
  1285. status = intel_sdvo_read_response(intel_output, &response, 2);
  1286. if (response[0] !=0)
  1287. return 1;
  1288. return 0;
  1289. }
  1290. void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
  1291. {
  1292. u8 response[2];
  1293. u8 status;
  1294. struct intel_output *intel_output = to_intel_output(connector);
  1295. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
  1296. intel_sdvo_read_response(intel_output, &response, 2);
  1297. if (on) {
  1298. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
  1299. status = intel_sdvo_read_response(intel_output, &response, 2);
  1300. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
  1301. } else {
  1302. response[0] = 0;
  1303. response[1] = 0;
  1304. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
  1305. }
  1306. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
  1307. intel_sdvo_read_response(intel_output, &response, 2);
  1308. }
  1309. static bool
  1310. intel_sdvo_multifunc_encoder(struct intel_output *intel_output)
  1311. {
  1312. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1313. int caps = 0;
  1314. if (sdvo_priv->caps.output_flags &
  1315. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
  1316. caps++;
  1317. if (sdvo_priv->caps.output_flags &
  1318. (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
  1319. caps++;
  1320. if (sdvo_priv->caps.output_flags &
  1321. (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
  1322. caps++;
  1323. if (sdvo_priv->caps.output_flags &
  1324. (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
  1325. caps++;
  1326. if (sdvo_priv->caps.output_flags &
  1327. (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
  1328. caps++;
  1329. if (sdvo_priv->caps.output_flags &
  1330. (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
  1331. caps++;
  1332. if (sdvo_priv->caps.output_flags &
  1333. (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
  1334. caps++;
  1335. return (caps > 1);
  1336. }
  1337. static struct drm_connector *
  1338. intel_find_analog_connector(struct drm_device *dev)
  1339. {
  1340. struct drm_connector *connector;
  1341. struct intel_output *intel_output;
  1342. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1343. intel_output = to_intel_output(connector);
  1344. if (intel_output->type == INTEL_OUTPUT_ANALOG)
  1345. return connector;
  1346. }
  1347. return NULL;
  1348. }
  1349. static int
  1350. intel_analog_is_connected(struct drm_device *dev)
  1351. {
  1352. struct drm_connector *analog_connector;
  1353. analog_connector = intel_find_analog_connector(dev);
  1354. if (!analog_connector)
  1355. return false;
  1356. if (analog_connector->funcs->detect(analog_connector) ==
  1357. connector_status_disconnected)
  1358. return false;
  1359. return true;
  1360. }
  1361. enum drm_connector_status
  1362. intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
  1363. {
  1364. struct intel_output *intel_output = to_intel_output(connector);
  1365. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1366. enum drm_connector_status status = connector_status_connected;
  1367. struct edid *edid = NULL;
  1368. edid = drm_get_edid(&intel_output->base,
  1369. intel_output->ddc_bus);
  1370. /* This is only applied to SDVO cards with multiple outputs */
  1371. if (edid == NULL && intel_sdvo_multifunc_encoder(intel_output)) {
  1372. uint8_t saved_ddc, temp_ddc;
  1373. saved_ddc = sdvo_priv->ddc_bus;
  1374. temp_ddc = sdvo_priv->ddc_bus >> 1;
  1375. /*
  1376. * Don't use the 1 as the argument of DDC bus switch to get
  1377. * the EDID. It is used for SDVO SPD ROM.
  1378. */
  1379. while(temp_ddc > 1) {
  1380. sdvo_priv->ddc_bus = temp_ddc;
  1381. edid = drm_get_edid(&intel_output->base,
  1382. intel_output->ddc_bus);
  1383. if (edid) {
  1384. /*
  1385. * When we can get the EDID, maybe it is the
  1386. * correct DDC bus. Update it.
  1387. */
  1388. sdvo_priv->ddc_bus = temp_ddc;
  1389. break;
  1390. }
  1391. temp_ddc >>= 1;
  1392. }
  1393. if (edid == NULL)
  1394. sdvo_priv->ddc_bus = saved_ddc;
  1395. }
  1396. /* when there is no edid and no monitor is connected with VGA
  1397. * port, try to use the CRT ddc to read the EDID for DVI-connector
  1398. */
  1399. if (edid == NULL &&
  1400. sdvo_priv->analog_ddc_bus &&
  1401. !intel_analog_is_connected(intel_output->base.dev))
  1402. edid = drm_get_edid(&intel_output->base,
  1403. sdvo_priv->analog_ddc_bus);
  1404. if (edid != NULL) {
  1405. /* Don't report the output as connected if it's a DVI-I
  1406. * connector with a non-digital EDID coming out.
  1407. */
  1408. if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
  1409. if (edid->input & DRM_EDID_INPUT_DIGITAL)
  1410. sdvo_priv->is_hdmi =
  1411. drm_detect_hdmi_monitor(edid);
  1412. else
  1413. status = connector_status_disconnected;
  1414. }
  1415. kfree(edid);
  1416. intel_output->base.display_info.raw_edid = NULL;
  1417. } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
  1418. status = connector_status_disconnected;
  1419. return status;
  1420. }
  1421. static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
  1422. {
  1423. uint16_t response;
  1424. u8 status;
  1425. struct intel_output *intel_output = to_intel_output(connector);
  1426. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1427. intel_sdvo_write_cmd(intel_output,
  1428. SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
  1429. if (sdvo_priv->is_tv) {
  1430. /* add 30ms delay when the output type is SDVO-TV */
  1431. mdelay(30);
  1432. }
  1433. status = intel_sdvo_read_response(intel_output, &response, 2);
  1434. DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8);
  1435. if (status != SDVO_CMD_STATUS_SUCCESS)
  1436. return connector_status_unknown;
  1437. if (response == 0)
  1438. return connector_status_disconnected;
  1439. if (intel_sdvo_multifunc_encoder(intel_output) &&
  1440. sdvo_priv->attached_output != response) {
  1441. if (sdvo_priv->controlled_output != response &&
  1442. intel_sdvo_output_setup(intel_output, response) != true)
  1443. return connector_status_unknown;
  1444. sdvo_priv->attached_output = response;
  1445. }
  1446. return intel_sdvo_hdmi_sink_detect(connector, response);
  1447. }
  1448. static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
  1449. {
  1450. struct intel_output *intel_output = to_intel_output(connector);
  1451. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1452. int num_modes;
  1453. /* set the bus switch and get the modes */
  1454. num_modes = intel_ddc_get_modes(intel_output);
  1455. /*
  1456. * Mac mini hack. On this device, the DVI-I connector shares one DDC
  1457. * link between analog and digital outputs. So, if the regular SDVO
  1458. * DDC fails, check to see if the analog output is disconnected, in
  1459. * which case we'll look there for the digital DDC data.
  1460. */
  1461. if (num_modes == 0 &&
  1462. sdvo_priv->analog_ddc_bus &&
  1463. !intel_analog_is_connected(intel_output->base.dev)) {
  1464. struct i2c_adapter *digital_ddc_bus;
  1465. /* Switch to the analog ddc bus and try that
  1466. */
  1467. digital_ddc_bus = intel_output->ddc_bus;
  1468. intel_output->ddc_bus = sdvo_priv->analog_ddc_bus;
  1469. (void) intel_ddc_get_modes(intel_output);
  1470. intel_output->ddc_bus = digital_ddc_bus;
  1471. }
  1472. }
  1473. /*
  1474. * Set of SDVO TV modes.
  1475. * Note! This is in reply order (see loop in get_tv_modes).
  1476. * XXX: all 60Hz refresh?
  1477. */
  1478. struct drm_display_mode sdvo_tv_modes[] = {
  1479. { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
  1480. 416, 0, 200, 201, 232, 233, 0,
  1481. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1482. { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
  1483. 416, 0, 240, 241, 272, 273, 0,
  1484. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1485. { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
  1486. 496, 0, 300, 301, 332, 333, 0,
  1487. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1488. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
  1489. 736, 0, 350, 351, 382, 383, 0,
  1490. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1491. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
  1492. 736, 0, 400, 401, 432, 433, 0,
  1493. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1494. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
  1495. 736, 0, 480, 481, 512, 513, 0,
  1496. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1497. { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
  1498. 800, 0, 480, 481, 512, 513, 0,
  1499. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1500. { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
  1501. 800, 0, 576, 577, 608, 609, 0,
  1502. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1503. { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
  1504. 816, 0, 350, 351, 382, 383, 0,
  1505. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1506. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
  1507. 816, 0, 400, 401, 432, 433, 0,
  1508. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1509. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
  1510. 816, 0, 480, 481, 512, 513, 0,
  1511. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1512. { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
  1513. 816, 0, 540, 541, 572, 573, 0,
  1514. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1515. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
  1516. 816, 0, 576, 577, 608, 609, 0,
  1517. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1518. { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
  1519. 864, 0, 576, 577, 608, 609, 0,
  1520. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1521. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
  1522. 896, 0, 600, 601, 632, 633, 0,
  1523. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1524. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
  1525. 928, 0, 624, 625, 656, 657, 0,
  1526. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1527. { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
  1528. 1016, 0, 766, 767, 798, 799, 0,
  1529. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1530. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
  1531. 1120, 0, 768, 769, 800, 801, 0,
  1532. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1533. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
  1534. 1376, 0, 1024, 1025, 1056, 1057, 0,
  1535. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1536. };
  1537. static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
  1538. {
  1539. struct intel_output *output = to_intel_output(connector);
  1540. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1541. struct intel_sdvo_sdtv_resolution_request tv_res;
  1542. uint32_t reply = 0, format_map = 0;
  1543. int i;
  1544. uint8_t status;
  1545. /* Read the list of supported input resolutions for the selected TV
  1546. * format.
  1547. */
  1548. for (i = 0; i < TV_FORMAT_NUM; i++)
  1549. if (tv_format_names[i] == sdvo_priv->tv_format_name)
  1550. break;
  1551. format_map = (1 << i);
  1552. memcpy(&tv_res, &format_map,
  1553. sizeof(struct intel_sdvo_sdtv_resolution_request) >
  1554. sizeof(format_map) ? sizeof(format_map) :
  1555. sizeof(struct intel_sdvo_sdtv_resolution_request));
  1556. intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
  1557. intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
  1558. &tv_res, sizeof(tv_res));
  1559. status = intel_sdvo_read_response(output, &reply, 3);
  1560. if (status != SDVO_CMD_STATUS_SUCCESS)
  1561. return;
  1562. for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
  1563. if (reply & (1 << i)) {
  1564. struct drm_display_mode *nmode;
  1565. nmode = drm_mode_duplicate(connector->dev,
  1566. &sdvo_tv_modes[i]);
  1567. if (nmode)
  1568. drm_mode_probed_add(connector, nmode);
  1569. }
  1570. }
  1571. static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
  1572. {
  1573. struct intel_output *intel_output = to_intel_output(connector);
  1574. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1575. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1576. struct drm_display_mode *newmode;
  1577. /*
  1578. * Attempt to get the mode list from DDC.
  1579. * Assume that the preferred modes are
  1580. * arranged in priority order.
  1581. */
  1582. intel_ddc_get_modes(intel_output);
  1583. if (list_empty(&connector->probed_modes) == false)
  1584. goto end;
  1585. /* Fetch modes from VBT */
  1586. if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
  1587. newmode = drm_mode_duplicate(connector->dev,
  1588. dev_priv->sdvo_lvds_vbt_mode);
  1589. if (newmode != NULL) {
  1590. /* Guarantee the mode is preferred */
  1591. newmode->type = (DRM_MODE_TYPE_PREFERRED |
  1592. DRM_MODE_TYPE_DRIVER);
  1593. drm_mode_probed_add(connector, newmode);
  1594. }
  1595. }
  1596. end:
  1597. list_for_each_entry(newmode, &connector->probed_modes, head) {
  1598. if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
  1599. sdvo_priv->sdvo_lvds_fixed_mode =
  1600. drm_mode_duplicate(connector->dev, newmode);
  1601. break;
  1602. }
  1603. }
  1604. }
  1605. static int intel_sdvo_get_modes(struct drm_connector *connector)
  1606. {
  1607. struct intel_output *output = to_intel_output(connector);
  1608. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1609. if (sdvo_priv->is_tv)
  1610. intel_sdvo_get_tv_modes(connector);
  1611. else if (sdvo_priv->is_lvds == true)
  1612. intel_sdvo_get_lvds_modes(connector);
  1613. else
  1614. intel_sdvo_get_ddc_modes(connector);
  1615. if (list_empty(&connector->probed_modes))
  1616. return 0;
  1617. return 1;
  1618. }
  1619. static
  1620. void intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
  1621. {
  1622. struct intel_output *intel_output = to_intel_output(connector);
  1623. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1624. struct drm_device *dev = connector->dev;
  1625. if (sdvo_priv->is_tv) {
  1626. if (sdvo_priv->left_property)
  1627. drm_property_destroy(dev, sdvo_priv->left_property);
  1628. if (sdvo_priv->right_property)
  1629. drm_property_destroy(dev, sdvo_priv->right_property);
  1630. if (sdvo_priv->top_property)
  1631. drm_property_destroy(dev, sdvo_priv->top_property);
  1632. if (sdvo_priv->bottom_property)
  1633. drm_property_destroy(dev, sdvo_priv->bottom_property);
  1634. if (sdvo_priv->hpos_property)
  1635. drm_property_destroy(dev, sdvo_priv->hpos_property);
  1636. if (sdvo_priv->vpos_property)
  1637. drm_property_destroy(dev, sdvo_priv->vpos_property);
  1638. }
  1639. if (sdvo_priv->is_tv) {
  1640. if (sdvo_priv->saturation_property)
  1641. drm_property_destroy(dev,
  1642. sdvo_priv->saturation_property);
  1643. if (sdvo_priv->contrast_property)
  1644. drm_property_destroy(dev,
  1645. sdvo_priv->contrast_property);
  1646. if (sdvo_priv->hue_property)
  1647. drm_property_destroy(dev, sdvo_priv->hue_property);
  1648. }
  1649. if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
  1650. if (sdvo_priv->brightness_property)
  1651. drm_property_destroy(dev,
  1652. sdvo_priv->brightness_property);
  1653. }
  1654. return;
  1655. }
  1656. static void intel_sdvo_destroy(struct drm_connector *connector)
  1657. {
  1658. struct intel_output *intel_output = to_intel_output(connector);
  1659. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1660. if (intel_output->i2c_bus)
  1661. intel_i2c_destroy(intel_output->i2c_bus);
  1662. if (intel_output->ddc_bus)
  1663. intel_i2c_destroy(intel_output->ddc_bus);
  1664. if (sdvo_priv->analog_ddc_bus)
  1665. intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
  1666. if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
  1667. drm_mode_destroy(connector->dev,
  1668. sdvo_priv->sdvo_lvds_fixed_mode);
  1669. if (sdvo_priv->tv_format_property)
  1670. drm_property_destroy(connector->dev,
  1671. sdvo_priv->tv_format_property);
  1672. if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
  1673. intel_sdvo_destroy_enhance_property(connector);
  1674. drm_sysfs_connector_remove(connector);
  1675. drm_connector_cleanup(connector);
  1676. kfree(intel_output);
  1677. }
  1678. static int
  1679. intel_sdvo_set_property(struct drm_connector *connector,
  1680. struct drm_property *property,
  1681. uint64_t val)
  1682. {
  1683. struct intel_output *intel_output = to_intel_output(connector);
  1684. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1685. struct drm_encoder *encoder = &intel_output->enc;
  1686. struct drm_crtc *crtc = encoder->crtc;
  1687. int ret = 0;
  1688. bool changed = false;
  1689. uint8_t cmd, status;
  1690. uint16_t temp_value;
  1691. ret = drm_connector_property_set_value(connector, property, val);
  1692. if (ret < 0)
  1693. goto out;
  1694. if (property == sdvo_priv->tv_format_property) {
  1695. if (val >= TV_FORMAT_NUM) {
  1696. ret = -EINVAL;
  1697. goto out;
  1698. }
  1699. if (sdvo_priv->tv_format_name ==
  1700. sdvo_priv->tv_format_supported[val])
  1701. goto out;
  1702. sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val];
  1703. changed = true;
  1704. }
  1705. if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
  1706. cmd = 0;
  1707. temp_value = val;
  1708. if (sdvo_priv->left_property == property) {
  1709. drm_connector_property_set_value(connector,
  1710. sdvo_priv->right_property, val);
  1711. if (sdvo_priv->left_margin == temp_value)
  1712. goto out;
  1713. sdvo_priv->left_margin = temp_value;
  1714. sdvo_priv->right_margin = temp_value;
  1715. temp_value = sdvo_priv->max_hscan -
  1716. sdvo_priv->left_margin;
  1717. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1718. } else if (sdvo_priv->right_property == property) {
  1719. drm_connector_property_set_value(connector,
  1720. sdvo_priv->left_property, val);
  1721. if (sdvo_priv->right_margin == temp_value)
  1722. goto out;
  1723. sdvo_priv->left_margin = temp_value;
  1724. sdvo_priv->right_margin = temp_value;
  1725. temp_value = sdvo_priv->max_hscan -
  1726. sdvo_priv->left_margin;
  1727. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1728. } else if (sdvo_priv->top_property == property) {
  1729. drm_connector_property_set_value(connector,
  1730. sdvo_priv->bottom_property, val);
  1731. if (sdvo_priv->top_margin == temp_value)
  1732. goto out;
  1733. sdvo_priv->top_margin = temp_value;
  1734. sdvo_priv->bottom_margin = temp_value;
  1735. temp_value = sdvo_priv->max_vscan -
  1736. sdvo_priv->top_margin;
  1737. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1738. } else if (sdvo_priv->bottom_property == property) {
  1739. drm_connector_property_set_value(connector,
  1740. sdvo_priv->top_property, val);
  1741. if (sdvo_priv->bottom_margin == temp_value)
  1742. goto out;
  1743. sdvo_priv->top_margin = temp_value;
  1744. sdvo_priv->bottom_margin = temp_value;
  1745. temp_value = sdvo_priv->max_vscan -
  1746. sdvo_priv->top_margin;
  1747. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1748. } else if (sdvo_priv->hpos_property == property) {
  1749. if (sdvo_priv->cur_hpos == temp_value)
  1750. goto out;
  1751. cmd = SDVO_CMD_SET_POSITION_H;
  1752. sdvo_priv->cur_hpos = temp_value;
  1753. } else if (sdvo_priv->vpos_property == property) {
  1754. if (sdvo_priv->cur_vpos == temp_value)
  1755. goto out;
  1756. cmd = SDVO_CMD_SET_POSITION_V;
  1757. sdvo_priv->cur_vpos = temp_value;
  1758. } else if (sdvo_priv->saturation_property == property) {
  1759. if (sdvo_priv->cur_saturation == temp_value)
  1760. goto out;
  1761. cmd = SDVO_CMD_SET_SATURATION;
  1762. sdvo_priv->cur_saturation = temp_value;
  1763. } else if (sdvo_priv->contrast_property == property) {
  1764. if (sdvo_priv->cur_contrast == temp_value)
  1765. goto out;
  1766. cmd = SDVO_CMD_SET_CONTRAST;
  1767. sdvo_priv->cur_contrast = temp_value;
  1768. } else if (sdvo_priv->hue_property == property) {
  1769. if (sdvo_priv->cur_hue == temp_value)
  1770. goto out;
  1771. cmd = SDVO_CMD_SET_HUE;
  1772. sdvo_priv->cur_hue = temp_value;
  1773. } else if (sdvo_priv->brightness_property == property) {
  1774. if (sdvo_priv->cur_brightness == temp_value)
  1775. goto out;
  1776. cmd = SDVO_CMD_SET_BRIGHTNESS;
  1777. sdvo_priv->cur_brightness = temp_value;
  1778. }
  1779. if (cmd) {
  1780. intel_sdvo_write_cmd(intel_output, cmd, &temp_value, 2);
  1781. status = intel_sdvo_read_response(intel_output,
  1782. NULL, 0);
  1783. if (status != SDVO_CMD_STATUS_SUCCESS) {
  1784. DRM_DEBUG_KMS("Incorrect SDVO command \n");
  1785. return -EINVAL;
  1786. }
  1787. changed = true;
  1788. }
  1789. }
  1790. if (changed && crtc)
  1791. drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
  1792. crtc->y, crtc->fb);
  1793. out:
  1794. return ret;
  1795. }
  1796. static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
  1797. .dpms = intel_sdvo_dpms,
  1798. .mode_fixup = intel_sdvo_mode_fixup,
  1799. .prepare = intel_encoder_prepare,
  1800. .mode_set = intel_sdvo_mode_set,
  1801. .commit = intel_encoder_commit,
  1802. };
  1803. static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
  1804. .dpms = drm_helper_connector_dpms,
  1805. .save = intel_sdvo_save,
  1806. .restore = intel_sdvo_restore,
  1807. .detect = intel_sdvo_detect,
  1808. .fill_modes = drm_helper_probe_single_connector_modes,
  1809. .set_property = intel_sdvo_set_property,
  1810. .destroy = intel_sdvo_destroy,
  1811. };
  1812. static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
  1813. .get_modes = intel_sdvo_get_modes,
  1814. .mode_valid = intel_sdvo_mode_valid,
  1815. .best_encoder = intel_best_encoder,
  1816. };
  1817. static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
  1818. {
  1819. drm_encoder_cleanup(encoder);
  1820. }
  1821. static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
  1822. .destroy = intel_sdvo_enc_destroy,
  1823. };
  1824. /**
  1825. * Choose the appropriate DDC bus for control bus switch command for this
  1826. * SDVO output based on the controlled output.
  1827. *
  1828. * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
  1829. * outputs, then LVDS outputs.
  1830. */
  1831. static void
  1832. intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
  1833. {
  1834. uint16_t mask = 0;
  1835. unsigned int num_bits;
  1836. /* Make a mask of outputs less than or equal to our own priority in the
  1837. * list.
  1838. */
  1839. switch (dev_priv->controlled_output) {
  1840. case SDVO_OUTPUT_LVDS1:
  1841. mask |= SDVO_OUTPUT_LVDS1;
  1842. case SDVO_OUTPUT_LVDS0:
  1843. mask |= SDVO_OUTPUT_LVDS0;
  1844. case SDVO_OUTPUT_TMDS1:
  1845. mask |= SDVO_OUTPUT_TMDS1;
  1846. case SDVO_OUTPUT_TMDS0:
  1847. mask |= SDVO_OUTPUT_TMDS0;
  1848. case SDVO_OUTPUT_RGB1:
  1849. mask |= SDVO_OUTPUT_RGB1;
  1850. case SDVO_OUTPUT_RGB0:
  1851. mask |= SDVO_OUTPUT_RGB0;
  1852. break;
  1853. }
  1854. /* Count bits to find what number we are in the priority list. */
  1855. mask &= dev_priv->caps.output_flags;
  1856. num_bits = hweight16(mask);
  1857. if (num_bits > 3) {
  1858. /* if more than 3 outputs, default to DDC bus 3 for now */
  1859. num_bits = 3;
  1860. }
  1861. /* Corresponds to SDVO_CONTROL_BUS_DDCx */
  1862. dev_priv->ddc_bus = 1 << num_bits;
  1863. }
  1864. static bool
  1865. intel_sdvo_get_digital_encoding_mode(struct intel_output *output)
  1866. {
  1867. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1868. uint8_t status;
  1869. intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
  1870. intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
  1871. status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
  1872. if (status != SDVO_CMD_STATUS_SUCCESS)
  1873. return false;
  1874. return true;
  1875. }
  1876. static struct intel_output *
  1877. intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan)
  1878. {
  1879. struct drm_device *dev = chan->drm_dev;
  1880. struct drm_connector *connector;
  1881. struct intel_output *intel_output = NULL;
  1882. list_for_each_entry(connector,
  1883. &dev->mode_config.connector_list, head) {
  1884. if (to_intel_output(connector)->ddc_bus == &chan->adapter) {
  1885. intel_output = to_intel_output(connector);
  1886. break;
  1887. }
  1888. }
  1889. return intel_output;
  1890. }
  1891. static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
  1892. struct i2c_msg msgs[], int num)
  1893. {
  1894. struct intel_output *intel_output;
  1895. struct intel_sdvo_priv *sdvo_priv;
  1896. struct i2c_algo_bit_data *algo_data;
  1897. const struct i2c_algorithm *algo;
  1898. algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
  1899. intel_output =
  1900. intel_sdvo_chan_to_intel_output(
  1901. (struct intel_i2c_chan *)(algo_data->data));
  1902. if (intel_output == NULL)
  1903. return -EINVAL;
  1904. sdvo_priv = intel_output->dev_priv;
  1905. algo = intel_output->i2c_bus->algo;
  1906. intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
  1907. return algo->master_xfer(i2c_adap, msgs, num);
  1908. }
  1909. static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
  1910. .master_xfer = intel_sdvo_master_xfer,
  1911. };
  1912. static u8
  1913. intel_sdvo_get_slave_addr(struct drm_device *dev, int output_device)
  1914. {
  1915. struct drm_i915_private *dev_priv = dev->dev_private;
  1916. struct sdvo_device_mapping *my_mapping, *other_mapping;
  1917. if (output_device == SDVOB) {
  1918. my_mapping = &dev_priv->sdvo_mappings[0];
  1919. other_mapping = &dev_priv->sdvo_mappings[1];
  1920. } else {
  1921. my_mapping = &dev_priv->sdvo_mappings[1];
  1922. other_mapping = &dev_priv->sdvo_mappings[0];
  1923. }
  1924. /* If the BIOS described our SDVO device, take advantage of it. */
  1925. if (my_mapping->slave_addr)
  1926. return my_mapping->slave_addr;
  1927. /* If the BIOS only described a different SDVO device, use the
  1928. * address that it isn't using.
  1929. */
  1930. if (other_mapping->slave_addr) {
  1931. if (other_mapping->slave_addr == 0x70)
  1932. return 0x72;
  1933. else
  1934. return 0x70;
  1935. }
  1936. /* No SDVO device info is found for another DVO port,
  1937. * so use mapping assumption we had before BIOS parsing.
  1938. */
  1939. if (output_device == SDVOB)
  1940. return 0x70;
  1941. else
  1942. return 0x72;
  1943. }
  1944. static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id)
  1945. {
  1946. DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident);
  1947. return 1;
  1948. }
  1949. static struct dmi_system_id intel_sdvo_bad_tv[] = {
  1950. {
  1951. .callback = intel_sdvo_bad_tv_callback,
  1952. .ident = "IntelG45/ICH10R/DME1737",
  1953. .matches = {
  1954. DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"),
  1955. DMI_MATCH(DMI_PRODUCT_NAME, "4800784"),
  1956. },
  1957. },
  1958. { } /* terminating entry */
  1959. };
  1960. static bool
  1961. intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags)
  1962. {
  1963. struct drm_connector *connector = &intel_output->base;
  1964. struct drm_encoder *encoder = &intel_output->enc;
  1965. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1966. bool ret = true, registered = false;
  1967. sdvo_priv->is_tv = false;
  1968. intel_output->needs_tv_clock = false;
  1969. sdvo_priv->is_lvds = false;
  1970. if (device_is_registered(&connector->kdev)) {
  1971. drm_sysfs_connector_remove(connector);
  1972. registered = true;
  1973. }
  1974. if (flags &
  1975. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
  1976. if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0)
  1977. sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0;
  1978. else
  1979. sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1;
  1980. encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
  1981. connector->connector_type = DRM_MODE_CONNECTOR_DVID;
  1982. if (intel_sdvo_get_supp_encode(intel_output,
  1983. &sdvo_priv->encode) &&
  1984. intel_sdvo_get_digital_encoding_mode(intel_output) &&
  1985. sdvo_priv->is_hdmi) {
  1986. /* enable hdmi encoding mode if supported */
  1987. intel_sdvo_set_encode(intel_output, SDVO_ENCODE_HDMI);
  1988. intel_sdvo_set_colorimetry(intel_output,
  1989. SDVO_COLORIMETRY_RGB256);
  1990. connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
  1991. intel_output->clone_mask =
  1992. (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
  1993. (1 << INTEL_ANALOG_CLONE_BIT);
  1994. }
  1995. } else if ((flags & SDVO_OUTPUT_SVID0) &&
  1996. !dmi_check_system(intel_sdvo_bad_tv)) {
  1997. sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0;
  1998. encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
  1999. connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
  2000. sdvo_priv->is_tv = true;
  2001. intel_output->needs_tv_clock = true;
  2002. intel_output->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
  2003. } else if (flags & SDVO_OUTPUT_RGB0) {
  2004. sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
  2005. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  2006. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  2007. intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
  2008. (1 << INTEL_ANALOG_CLONE_BIT);
  2009. } else if (flags & SDVO_OUTPUT_RGB1) {
  2010. sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
  2011. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  2012. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  2013. intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
  2014. (1 << INTEL_ANALOG_CLONE_BIT);
  2015. } else if (flags & SDVO_OUTPUT_CVBS0) {
  2016. sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0;
  2017. encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
  2018. connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
  2019. sdvo_priv->is_tv = true;
  2020. intel_output->needs_tv_clock = true;
  2021. intel_output->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
  2022. } else if (flags & SDVO_OUTPUT_LVDS0) {
  2023. sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
  2024. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  2025. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  2026. sdvo_priv->is_lvds = true;
  2027. intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
  2028. (1 << INTEL_SDVO_LVDS_CLONE_BIT);
  2029. } else if (flags & SDVO_OUTPUT_LVDS1) {
  2030. sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
  2031. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  2032. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  2033. sdvo_priv->is_lvds = true;
  2034. intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
  2035. (1 << INTEL_SDVO_LVDS_CLONE_BIT);
  2036. } else {
  2037. unsigned char bytes[2];
  2038. sdvo_priv->controlled_output = 0;
  2039. memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
  2040. DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
  2041. SDVO_NAME(sdvo_priv),
  2042. bytes[0], bytes[1]);
  2043. ret = false;
  2044. }
  2045. intel_output->crtc_mask = (1 << 0) | (1 << 1);
  2046. if (ret && registered)
  2047. ret = drm_sysfs_connector_add(connector) == 0 ? true : false;
  2048. return ret;
  2049. }
  2050. static void intel_sdvo_tv_create_property(struct drm_connector *connector)
  2051. {
  2052. struct intel_output *intel_output = to_intel_output(connector);
  2053. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  2054. struct intel_sdvo_tv_format format;
  2055. uint32_t format_map, i;
  2056. uint8_t status;
  2057. intel_sdvo_set_target_output(intel_output,
  2058. sdvo_priv->controlled_output);
  2059. intel_sdvo_write_cmd(intel_output,
  2060. SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0);
  2061. status = intel_sdvo_read_response(intel_output,
  2062. &format, sizeof(format));
  2063. if (status != SDVO_CMD_STATUS_SUCCESS)
  2064. return;
  2065. memcpy(&format_map, &format, sizeof(format) > sizeof(format_map) ?
  2066. sizeof(format_map) : sizeof(format));
  2067. if (format_map == 0)
  2068. return;
  2069. sdvo_priv->format_supported_num = 0;
  2070. for (i = 0 ; i < TV_FORMAT_NUM; i++)
  2071. if (format_map & (1 << i)) {
  2072. sdvo_priv->tv_format_supported
  2073. [sdvo_priv->format_supported_num++] =
  2074. tv_format_names[i];
  2075. }
  2076. sdvo_priv->tv_format_property =
  2077. drm_property_create(
  2078. connector->dev, DRM_MODE_PROP_ENUM,
  2079. "mode", sdvo_priv->format_supported_num);
  2080. for (i = 0; i < sdvo_priv->format_supported_num; i++)
  2081. drm_property_add_enum(
  2082. sdvo_priv->tv_format_property, i,
  2083. i, sdvo_priv->tv_format_supported[i]);
  2084. sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0];
  2085. drm_connector_attach_property(
  2086. connector, sdvo_priv->tv_format_property, 0);
  2087. }
  2088. static void intel_sdvo_create_enhance_property(struct drm_connector *connector)
  2089. {
  2090. struct intel_output *intel_output = to_intel_output(connector);
  2091. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  2092. struct intel_sdvo_enhancements_reply sdvo_data;
  2093. struct drm_device *dev = connector->dev;
  2094. uint8_t status;
  2095. uint16_t response, data_value[2];
  2096. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
  2097. NULL, 0);
  2098. status = intel_sdvo_read_response(intel_output, &sdvo_data,
  2099. sizeof(sdvo_data));
  2100. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2101. DRM_DEBUG_KMS(" incorrect response is returned\n");
  2102. return;
  2103. }
  2104. response = *((uint16_t *)&sdvo_data);
  2105. if (!response) {
  2106. DRM_DEBUG_KMS("No enhancement is supported\n");
  2107. return;
  2108. }
  2109. if (sdvo_priv->is_tv) {
  2110. /* when horizontal overscan is supported, Add the left/right
  2111. * property
  2112. */
  2113. if (sdvo_data.overscan_h) {
  2114. intel_sdvo_write_cmd(intel_output,
  2115. SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0);
  2116. status = intel_sdvo_read_response(intel_output,
  2117. &data_value, 4);
  2118. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2119. DRM_DEBUG_KMS("Incorrect SDVO max "
  2120. "h_overscan\n");
  2121. return;
  2122. }
  2123. intel_sdvo_write_cmd(intel_output,
  2124. SDVO_CMD_GET_OVERSCAN_H, NULL, 0);
  2125. status = intel_sdvo_read_response(intel_output,
  2126. &response, 2);
  2127. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2128. DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n");
  2129. return;
  2130. }
  2131. sdvo_priv->max_hscan = data_value[0];
  2132. sdvo_priv->left_margin = data_value[0] - response;
  2133. sdvo_priv->right_margin = sdvo_priv->left_margin;
  2134. sdvo_priv->left_property =
  2135. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2136. "left_margin", 2);
  2137. sdvo_priv->left_property->values[0] = 0;
  2138. sdvo_priv->left_property->values[1] = data_value[0];
  2139. drm_connector_attach_property(connector,
  2140. sdvo_priv->left_property,
  2141. sdvo_priv->left_margin);
  2142. sdvo_priv->right_property =
  2143. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2144. "right_margin", 2);
  2145. sdvo_priv->right_property->values[0] = 0;
  2146. sdvo_priv->right_property->values[1] = data_value[0];
  2147. drm_connector_attach_property(connector,
  2148. sdvo_priv->right_property,
  2149. sdvo_priv->right_margin);
  2150. DRM_DEBUG_KMS("h_overscan: max %d, "
  2151. "default %d, current %d\n",
  2152. data_value[0], data_value[1], response);
  2153. }
  2154. if (sdvo_data.overscan_v) {
  2155. intel_sdvo_write_cmd(intel_output,
  2156. SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0);
  2157. status = intel_sdvo_read_response(intel_output,
  2158. &data_value, 4);
  2159. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2160. DRM_DEBUG_KMS("Incorrect SDVO max "
  2161. "v_overscan\n");
  2162. return;
  2163. }
  2164. intel_sdvo_write_cmd(intel_output,
  2165. SDVO_CMD_GET_OVERSCAN_V, NULL, 0);
  2166. status = intel_sdvo_read_response(intel_output,
  2167. &response, 2);
  2168. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2169. DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n");
  2170. return;
  2171. }
  2172. sdvo_priv->max_vscan = data_value[0];
  2173. sdvo_priv->top_margin = data_value[0] - response;
  2174. sdvo_priv->bottom_margin = sdvo_priv->top_margin;
  2175. sdvo_priv->top_property =
  2176. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2177. "top_margin", 2);
  2178. sdvo_priv->top_property->values[0] = 0;
  2179. sdvo_priv->top_property->values[1] = data_value[0];
  2180. drm_connector_attach_property(connector,
  2181. sdvo_priv->top_property,
  2182. sdvo_priv->top_margin);
  2183. sdvo_priv->bottom_property =
  2184. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2185. "bottom_margin", 2);
  2186. sdvo_priv->bottom_property->values[0] = 0;
  2187. sdvo_priv->bottom_property->values[1] = data_value[0];
  2188. drm_connector_attach_property(connector,
  2189. sdvo_priv->bottom_property,
  2190. sdvo_priv->bottom_margin);
  2191. DRM_DEBUG_KMS("v_overscan: max %d, "
  2192. "default %d, current %d\n",
  2193. data_value[0], data_value[1], response);
  2194. }
  2195. if (sdvo_data.position_h) {
  2196. intel_sdvo_write_cmd(intel_output,
  2197. SDVO_CMD_GET_MAX_POSITION_H, NULL, 0);
  2198. status = intel_sdvo_read_response(intel_output,
  2199. &data_value, 4);
  2200. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2201. DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n");
  2202. return;
  2203. }
  2204. intel_sdvo_write_cmd(intel_output,
  2205. SDVO_CMD_GET_POSITION_H, NULL, 0);
  2206. status = intel_sdvo_read_response(intel_output,
  2207. &response, 2);
  2208. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2209. DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n");
  2210. return;
  2211. }
  2212. sdvo_priv->max_hpos = data_value[0];
  2213. sdvo_priv->cur_hpos = response;
  2214. sdvo_priv->hpos_property =
  2215. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2216. "hpos", 2);
  2217. sdvo_priv->hpos_property->values[0] = 0;
  2218. sdvo_priv->hpos_property->values[1] = data_value[0];
  2219. drm_connector_attach_property(connector,
  2220. sdvo_priv->hpos_property,
  2221. sdvo_priv->cur_hpos);
  2222. DRM_DEBUG_KMS("h_position: max %d, "
  2223. "default %d, current %d\n",
  2224. data_value[0], data_value[1], response);
  2225. }
  2226. if (sdvo_data.position_v) {
  2227. intel_sdvo_write_cmd(intel_output,
  2228. SDVO_CMD_GET_MAX_POSITION_V, NULL, 0);
  2229. status = intel_sdvo_read_response(intel_output,
  2230. &data_value, 4);
  2231. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2232. DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n");
  2233. return;
  2234. }
  2235. intel_sdvo_write_cmd(intel_output,
  2236. SDVO_CMD_GET_POSITION_V, NULL, 0);
  2237. status = intel_sdvo_read_response(intel_output,
  2238. &response, 2);
  2239. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2240. DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n");
  2241. return;
  2242. }
  2243. sdvo_priv->max_vpos = data_value[0];
  2244. sdvo_priv->cur_vpos = response;
  2245. sdvo_priv->vpos_property =
  2246. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2247. "vpos", 2);
  2248. sdvo_priv->vpos_property->values[0] = 0;
  2249. sdvo_priv->vpos_property->values[1] = data_value[0];
  2250. drm_connector_attach_property(connector,
  2251. sdvo_priv->vpos_property,
  2252. sdvo_priv->cur_vpos);
  2253. DRM_DEBUG_KMS("v_position: max %d, "
  2254. "default %d, current %d\n",
  2255. data_value[0], data_value[1], response);
  2256. }
  2257. }
  2258. if (sdvo_priv->is_tv) {
  2259. if (sdvo_data.saturation) {
  2260. intel_sdvo_write_cmd(intel_output,
  2261. SDVO_CMD_GET_MAX_SATURATION, NULL, 0);
  2262. status = intel_sdvo_read_response(intel_output,
  2263. &data_value, 4);
  2264. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2265. DRM_DEBUG_KMS("Incorrect SDVO Max sat\n");
  2266. return;
  2267. }
  2268. intel_sdvo_write_cmd(intel_output,
  2269. SDVO_CMD_GET_SATURATION, NULL, 0);
  2270. status = intel_sdvo_read_response(intel_output,
  2271. &response, 2);
  2272. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2273. DRM_DEBUG_KMS("Incorrect SDVO get sat\n");
  2274. return;
  2275. }
  2276. sdvo_priv->max_saturation = data_value[0];
  2277. sdvo_priv->cur_saturation = response;
  2278. sdvo_priv->saturation_property =
  2279. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2280. "saturation", 2);
  2281. sdvo_priv->saturation_property->values[0] = 0;
  2282. sdvo_priv->saturation_property->values[1] =
  2283. data_value[0];
  2284. drm_connector_attach_property(connector,
  2285. sdvo_priv->saturation_property,
  2286. sdvo_priv->cur_saturation);
  2287. DRM_DEBUG_KMS("saturation: max %d, "
  2288. "default %d, current %d\n",
  2289. data_value[0], data_value[1], response);
  2290. }
  2291. if (sdvo_data.contrast) {
  2292. intel_sdvo_write_cmd(intel_output,
  2293. SDVO_CMD_GET_MAX_CONTRAST, NULL, 0);
  2294. status = intel_sdvo_read_response(intel_output,
  2295. &data_value, 4);
  2296. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2297. DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n");
  2298. return;
  2299. }
  2300. intel_sdvo_write_cmd(intel_output,
  2301. SDVO_CMD_GET_CONTRAST, NULL, 0);
  2302. status = intel_sdvo_read_response(intel_output,
  2303. &response, 2);
  2304. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2305. DRM_DEBUG_KMS("Incorrect SDVO get contrast\n");
  2306. return;
  2307. }
  2308. sdvo_priv->max_contrast = data_value[0];
  2309. sdvo_priv->cur_contrast = response;
  2310. sdvo_priv->contrast_property =
  2311. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2312. "contrast", 2);
  2313. sdvo_priv->contrast_property->values[0] = 0;
  2314. sdvo_priv->contrast_property->values[1] = data_value[0];
  2315. drm_connector_attach_property(connector,
  2316. sdvo_priv->contrast_property,
  2317. sdvo_priv->cur_contrast);
  2318. DRM_DEBUG_KMS("contrast: max %d, "
  2319. "default %d, current %d\n",
  2320. data_value[0], data_value[1], response);
  2321. }
  2322. if (sdvo_data.hue) {
  2323. intel_sdvo_write_cmd(intel_output,
  2324. SDVO_CMD_GET_MAX_HUE, NULL, 0);
  2325. status = intel_sdvo_read_response(intel_output,
  2326. &data_value, 4);
  2327. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2328. DRM_DEBUG_KMS("Incorrect SDVO Max hue\n");
  2329. return;
  2330. }
  2331. intel_sdvo_write_cmd(intel_output,
  2332. SDVO_CMD_GET_HUE, NULL, 0);
  2333. status = intel_sdvo_read_response(intel_output,
  2334. &response, 2);
  2335. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2336. DRM_DEBUG_KMS("Incorrect SDVO get hue\n");
  2337. return;
  2338. }
  2339. sdvo_priv->max_hue = data_value[0];
  2340. sdvo_priv->cur_hue = response;
  2341. sdvo_priv->hue_property =
  2342. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2343. "hue", 2);
  2344. sdvo_priv->hue_property->values[0] = 0;
  2345. sdvo_priv->hue_property->values[1] =
  2346. data_value[0];
  2347. drm_connector_attach_property(connector,
  2348. sdvo_priv->hue_property,
  2349. sdvo_priv->cur_hue);
  2350. DRM_DEBUG_KMS("hue: max %d, default %d, current %d\n",
  2351. data_value[0], data_value[1], response);
  2352. }
  2353. }
  2354. if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
  2355. if (sdvo_data.brightness) {
  2356. intel_sdvo_write_cmd(intel_output,
  2357. SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0);
  2358. status = intel_sdvo_read_response(intel_output,
  2359. &data_value, 4);
  2360. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2361. DRM_DEBUG_KMS("Incorrect SDVO Max bright\n");
  2362. return;
  2363. }
  2364. intel_sdvo_write_cmd(intel_output,
  2365. SDVO_CMD_GET_BRIGHTNESS, NULL, 0);
  2366. status = intel_sdvo_read_response(intel_output,
  2367. &response, 2);
  2368. if (status != SDVO_CMD_STATUS_SUCCESS) {
  2369. DRM_DEBUG_KMS("Incorrect SDVO get brigh\n");
  2370. return;
  2371. }
  2372. sdvo_priv->max_brightness = data_value[0];
  2373. sdvo_priv->cur_brightness = response;
  2374. sdvo_priv->brightness_property =
  2375. drm_property_create(dev, DRM_MODE_PROP_RANGE,
  2376. "brightness", 2);
  2377. sdvo_priv->brightness_property->values[0] = 0;
  2378. sdvo_priv->brightness_property->values[1] =
  2379. data_value[0];
  2380. drm_connector_attach_property(connector,
  2381. sdvo_priv->brightness_property,
  2382. sdvo_priv->cur_brightness);
  2383. DRM_DEBUG_KMS("brightness: max %d, "
  2384. "default %d, current %d\n",
  2385. data_value[0], data_value[1], response);
  2386. }
  2387. }
  2388. return;
  2389. }
  2390. bool intel_sdvo_init(struct drm_device *dev, int output_device)
  2391. {
  2392. struct drm_i915_private *dev_priv = dev->dev_private;
  2393. struct drm_connector *connector;
  2394. struct intel_output *intel_output;
  2395. struct intel_sdvo_priv *sdvo_priv;
  2396. u8 ch[0x40];
  2397. int i;
  2398. intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
  2399. if (!intel_output) {
  2400. return false;
  2401. }
  2402. sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1);
  2403. sdvo_priv->output_device = output_device;
  2404. intel_output->dev_priv = sdvo_priv;
  2405. intel_output->type = INTEL_OUTPUT_SDVO;
  2406. /* setup the DDC bus. */
  2407. if (output_device == SDVOB)
  2408. intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
  2409. else
  2410. intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
  2411. if (!intel_output->i2c_bus)
  2412. goto err_inteloutput;
  2413. sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
  2414. /* Save the bit-banging i2c functionality for use by the DDC wrapper */
  2415. intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
  2416. /* Read the regs to test if we can talk to the device */
  2417. for (i = 0; i < 0x40; i++) {
  2418. if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) {
  2419. DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n",
  2420. output_device == SDVOB ? 'B' : 'C');
  2421. goto err_i2c;
  2422. }
  2423. }
  2424. /* setup the DDC bus. */
  2425. if (output_device == SDVOB) {
  2426. intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
  2427. sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
  2428. "SDVOB/VGA DDC BUS");
  2429. dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS;
  2430. } else {
  2431. intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
  2432. sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA,
  2433. "SDVOC/VGA DDC BUS");
  2434. dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS;
  2435. }
  2436. if (intel_output->ddc_bus == NULL)
  2437. goto err_i2c;
  2438. /* Wrap with our custom algo which switches to DDC mode */
  2439. intel_output->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
  2440. /* In default case sdvo lvds is false */
  2441. intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps);
  2442. if (intel_sdvo_output_setup(intel_output,
  2443. sdvo_priv->caps.output_flags) != true) {
  2444. DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n",
  2445. output_device == SDVOB ? 'B' : 'C');
  2446. goto err_i2c;
  2447. }
  2448. connector = &intel_output->base;
  2449. drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
  2450. connector->connector_type);
  2451. drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
  2452. connector->interlace_allowed = 0;
  2453. connector->doublescan_allowed = 0;
  2454. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  2455. drm_encoder_init(dev, &intel_output->enc,
  2456. &intel_sdvo_enc_funcs, intel_output->enc.encoder_type);
  2457. drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs);
  2458. drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
  2459. if (sdvo_priv->is_tv)
  2460. intel_sdvo_tv_create_property(connector);
  2461. if (sdvo_priv->is_tv || sdvo_priv->is_lvds)
  2462. intel_sdvo_create_enhance_property(connector);
  2463. drm_sysfs_connector_add(connector);
  2464. intel_sdvo_select_ddc_bus(sdvo_priv);
  2465. /* Set the input timing to the screen. Assume always input 0. */
  2466. intel_sdvo_set_target_input(intel_output, true, false);
  2467. intel_sdvo_get_input_pixel_clock_range(intel_output,
  2468. &sdvo_priv->pixel_clock_min,
  2469. &sdvo_priv->pixel_clock_max);
  2470. DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
  2471. "clock range %dMHz - %dMHz, "
  2472. "input 1: %c, input 2: %c, "
  2473. "output 1: %c, output 2: %c\n",
  2474. SDVO_NAME(sdvo_priv),
  2475. sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
  2476. sdvo_priv->caps.device_rev_id,
  2477. sdvo_priv->pixel_clock_min / 1000,
  2478. sdvo_priv->pixel_clock_max / 1000,
  2479. (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
  2480. (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
  2481. /* check currently supported outputs */
  2482. sdvo_priv->caps.output_flags &
  2483. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
  2484. sdvo_priv->caps.output_flags &
  2485. (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
  2486. return true;
  2487. err_i2c:
  2488. if (sdvo_priv->analog_ddc_bus != NULL)
  2489. intel_i2c_destroy(sdvo_priv->analog_ddc_bus);
  2490. if (intel_output->ddc_bus != NULL)
  2491. intel_i2c_destroy(intel_output->ddc_bus);
  2492. if (intel_output->i2c_bus != NULL)
  2493. intel_i2c_destroy(intel_output->i2c_bus);
  2494. err_inteloutput:
  2495. kfree(intel_output);
  2496. return false;
  2497. }