intel_sdvo.c 80 KB

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