intel_sdvo.c 77 KB

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