intel_sdvo.c 79 KB

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