intel_sdvo.c 79 KB

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