intel_sdvo.c 77 KB

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