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