intel_sdvo.c 78 KB

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