intel_sdvo.c 81 KB

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