intel_sdvo.c 80 KB

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