intel_sdvo.c 83 KB

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