intel_sdvo.c 79 KB

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