intel_sdvo.c 85 KB

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