intel_sdvo.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154
  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/delay.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "drm_crtc.h"
  33. #include "intel_drv.h"
  34. #include "drm_edid.h"
  35. #include "i915_drm.h"
  36. #include "i915_drv.h"
  37. #include "intel_sdvo_regs.h"
  38. #undef SDVO_DEBUG
  39. #define I915_SDVO "i915_sdvo"
  40. struct intel_sdvo_priv {
  41. u8 slave_addr;
  42. /* Register for the SDVO device: SDVOB or SDVOC */
  43. int output_device;
  44. /* Active outputs controlled by this SDVO output */
  45. uint16_t controlled_output;
  46. /*
  47. * Capabilities of the SDVO device returned by
  48. * i830_sdvo_get_capabilities()
  49. */
  50. struct intel_sdvo_caps caps;
  51. /* Pixel clock limitations reported by the SDVO device, in kHz */
  52. int pixel_clock_min, pixel_clock_max;
  53. /*
  54. * For multiple function SDVO device,
  55. * this is for current attached outputs.
  56. */
  57. uint16_t attached_output;
  58. /**
  59. * This is set if we're going to treat the device as TV-out.
  60. *
  61. * While we have these nice friendly flags for output types that ought
  62. * to decide this for us, the S-Video output on our HDMI+S-Video card
  63. * shows up as RGB1 (VGA).
  64. */
  65. bool is_tv;
  66. /**
  67. * This is set if we treat the device as HDMI, instead of DVI.
  68. */
  69. bool is_hdmi;
  70. /**
  71. * This is set if we detect output of sdvo device as LVDS.
  72. */
  73. bool is_lvds;
  74. /**
  75. * This is sdvo flags for input timing.
  76. */
  77. uint8_t sdvo_flags;
  78. /**
  79. * This is sdvo fixed pannel mode pointer
  80. */
  81. struct drm_display_mode *sdvo_lvds_fixed_mode;
  82. /**
  83. * Returned SDTV resolutions allowed for the current format, if the
  84. * device reported it.
  85. */
  86. struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions;
  87. /**
  88. * Current selected TV format.
  89. *
  90. * This is stored in the same structure that's passed to the device, for
  91. * convenience.
  92. */
  93. struct intel_sdvo_tv_format tv_format;
  94. /*
  95. * supported encoding mode, used to determine whether HDMI is
  96. * supported
  97. */
  98. struct intel_sdvo_encode encode;
  99. /* DDC bus used by this SDVO output */
  100. uint8_t ddc_bus;
  101. int save_sdvo_mult;
  102. u16 save_active_outputs;
  103. struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2;
  104. struct intel_sdvo_dtd save_output_dtd[16];
  105. u32 save_SDVOX;
  106. };
  107. static bool
  108. intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags);
  109. /**
  110. * Writes the SDVOB or SDVOC with the given value, but always writes both
  111. * SDVOB and SDVOC to work around apparent hardware issues (according to
  112. * comments in the BIOS).
  113. */
  114. static void intel_sdvo_write_sdvox(struct intel_output *intel_output, u32 val)
  115. {
  116. struct drm_device *dev = intel_output->base.dev;
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  119. u32 bval = val, cval = val;
  120. int i;
  121. if (sdvo_priv->output_device == SDVOB) {
  122. cval = I915_READ(SDVOC);
  123. } else {
  124. bval = I915_READ(SDVOB);
  125. }
  126. /*
  127. * Write the registers twice for luck. Sometimes,
  128. * writing them only once doesn't appear to 'stick'.
  129. * The BIOS does this too. Yay, magic
  130. */
  131. for (i = 0; i < 2; i++)
  132. {
  133. I915_WRITE(SDVOB, bval);
  134. I915_READ(SDVOB);
  135. I915_WRITE(SDVOC, cval);
  136. I915_READ(SDVOC);
  137. }
  138. }
  139. static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr,
  140. u8 *ch)
  141. {
  142. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  143. u8 out_buf[2];
  144. u8 buf[2];
  145. int ret;
  146. struct i2c_msg msgs[] = {
  147. {
  148. .addr = sdvo_priv->slave_addr >> 1,
  149. .flags = 0,
  150. .len = 1,
  151. .buf = out_buf,
  152. },
  153. {
  154. .addr = sdvo_priv->slave_addr >> 1,
  155. .flags = I2C_M_RD,
  156. .len = 1,
  157. .buf = buf,
  158. }
  159. };
  160. out_buf[0] = addr;
  161. out_buf[1] = 0;
  162. if ((ret = i2c_transfer(intel_output->i2c_bus, msgs, 2)) == 2)
  163. {
  164. *ch = buf[0];
  165. return true;
  166. }
  167. DRM_DEBUG("i2c transfer returned %d\n", ret);
  168. return false;
  169. }
  170. static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr,
  171. u8 ch)
  172. {
  173. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  174. u8 out_buf[2];
  175. struct i2c_msg msgs[] = {
  176. {
  177. .addr = sdvo_priv->slave_addr >> 1,
  178. .flags = 0,
  179. .len = 2,
  180. .buf = out_buf,
  181. }
  182. };
  183. out_buf[0] = addr;
  184. out_buf[1] = ch;
  185. if (i2c_transfer(intel_output->i2c_bus, msgs, 1) == 1)
  186. {
  187. return true;
  188. }
  189. return false;
  190. }
  191. #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
  192. /** Mapping of command numbers to names, for debug output */
  193. static const struct _sdvo_cmd_name {
  194. u8 cmd;
  195. char *name;
  196. } sdvo_cmd_names[] = {
  197. SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
  198. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
  199. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
  200. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
  201. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
  202. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
  203. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
  204. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
  205. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
  206. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
  207. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
  208. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
  209. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
  210. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
  211. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
  212. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
  213. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
  214. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  215. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
  216. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  217. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
  218. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
  219. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
  220. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
  221. SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
  222. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
  223. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
  224. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
  225. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
  226. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
  227. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
  228. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
  229. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
  230. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
  231. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
  232. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
  233. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
  234. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
  235. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
  236. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
  237. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
  238. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
  239. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
  240. /* HDMI op code */
  241. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
  242. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
  243. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
  244. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
  245. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
  246. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
  247. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
  248. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
  249. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
  250. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
  251. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
  252. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
  253. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
  254. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
  255. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
  256. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
  257. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
  258. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
  259. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
  260. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
  261. };
  262. #define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC")
  263. #define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv)
  264. #ifdef SDVO_DEBUG
  265. static void intel_sdvo_debug_write(struct intel_output *intel_output, u8 cmd,
  266. void *args, int args_len)
  267. {
  268. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  269. int i;
  270. DRM_DEBUG_KMS(I915_SDVO, "%s: W: %02X ",
  271. SDVO_NAME(sdvo_priv), cmd);
  272. for (i = 0; i < args_len; i++)
  273. DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
  274. for (; i < 8; i++)
  275. DRM_LOG_KMS(" ");
  276. for (i = 0; i < sizeof(sdvo_cmd_names) / sizeof(sdvo_cmd_names[0]); i++) {
  277. if (cmd == sdvo_cmd_names[i].cmd) {
  278. DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
  279. break;
  280. }
  281. }
  282. if (i == sizeof(sdvo_cmd_names)/ sizeof(sdvo_cmd_names[0]))
  283. DRM_LOG_KMS("(%02X)", cmd);
  284. DRM_LOG_KMS("\n");
  285. }
  286. #else
  287. #define intel_sdvo_debug_write(o, c, a, l)
  288. #endif
  289. static void intel_sdvo_write_cmd(struct intel_output *intel_output, u8 cmd,
  290. void *args, int args_len)
  291. {
  292. int i;
  293. intel_sdvo_debug_write(intel_output, cmd, args, args_len);
  294. for (i = 0; i < args_len; i++) {
  295. intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0 - i,
  296. ((u8*)args)[i]);
  297. }
  298. intel_sdvo_write_byte(intel_output, SDVO_I2C_OPCODE, cmd);
  299. }
  300. #ifdef SDVO_DEBUG
  301. static const char *cmd_status_names[] = {
  302. "Power on",
  303. "Success",
  304. "Not supported",
  305. "Invalid arg",
  306. "Pending",
  307. "Target not specified",
  308. "Scaling not supported"
  309. };
  310. static void intel_sdvo_debug_response(struct intel_output *intel_output,
  311. void *response, int response_len,
  312. u8 status)
  313. {
  314. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  315. int i;
  316. DRM_DEBUG_KMS(I915_SDVO, "%s: R: ", SDVO_NAME(sdvo_priv));
  317. for (i = 0; i < response_len; i++)
  318. DRM_LOG_KMS("%02X ", ((u8 *)response)[i]);
  319. for (; i < 8; i++)
  320. DRM_LOG_KMS(" ");
  321. if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
  322. DRM_LOG_KMS("(%s)", cmd_status_names[status]);
  323. else
  324. DRM_LOG_KMS("(??? %d)", status);
  325. DRM_LOG_KMS("\n");
  326. }
  327. #else
  328. #define intel_sdvo_debug_response(o, r, l, s)
  329. #endif
  330. static u8 intel_sdvo_read_response(struct intel_output *intel_output,
  331. void *response, int response_len)
  332. {
  333. int i;
  334. u8 status;
  335. u8 retry = 50;
  336. while (retry--) {
  337. /* Read the command response */
  338. for (i = 0; i < response_len; i++) {
  339. intel_sdvo_read_byte(intel_output,
  340. SDVO_I2C_RETURN_0 + i,
  341. &((u8 *)response)[i]);
  342. }
  343. /* read the return status */
  344. intel_sdvo_read_byte(intel_output, SDVO_I2C_CMD_STATUS,
  345. &status);
  346. intel_sdvo_debug_response(intel_output, response, response_len,
  347. status);
  348. if (status != SDVO_CMD_STATUS_PENDING)
  349. return status;
  350. mdelay(50);
  351. }
  352. return status;
  353. }
  354. static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
  355. {
  356. if (mode->clock >= 100000)
  357. return 1;
  358. else if (mode->clock >= 50000)
  359. return 2;
  360. else
  361. return 4;
  362. }
  363. /**
  364. * Don't check status code from this as it switches the bus back to the
  365. * SDVO chips which defeats the purpose of doing a bus switch in the first
  366. * place.
  367. */
  368. static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output,
  369. u8 target)
  370. {
  371. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CONTROL_BUS_SWITCH, &target, 1);
  372. }
  373. static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool target_0, bool target_1)
  374. {
  375. struct intel_sdvo_set_target_input_args targets = {0};
  376. u8 status;
  377. if (target_0 && target_1)
  378. return SDVO_CMD_STATUS_NOTSUPP;
  379. if (target_1)
  380. targets.target_1 = 1;
  381. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_INPUT, &targets,
  382. sizeof(targets));
  383. status = intel_sdvo_read_response(intel_output, NULL, 0);
  384. return (status == SDVO_CMD_STATUS_SUCCESS);
  385. }
  386. /**
  387. * Return whether each input is trained.
  388. *
  389. * This function is making an assumption about the layout of the response,
  390. * which should be checked against the docs.
  391. */
  392. static bool intel_sdvo_get_trained_inputs(struct intel_output *intel_output, bool *input_1, bool *input_2)
  393. {
  394. struct intel_sdvo_get_trained_inputs_response response;
  395. u8 status;
  396. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0);
  397. status = intel_sdvo_read_response(intel_output, &response, sizeof(response));
  398. if (status != SDVO_CMD_STATUS_SUCCESS)
  399. return false;
  400. *input_1 = response.input0_trained;
  401. *input_2 = response.input1_trained;
  402. return true;
  403. }
  404. static bool intel_sdvo_get_active_outputs(struct intel_output *intel_output,
  405. u16 *outputs)
  406. {
  407. u8 status;
  408. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_OUTPUTS, NULL, 0);
  409. status = intel_sdvo_read_response(intel_output, outputs, sizeof(*outputs));
  410. return (status == SDVO_CMD_STATUS_SUCCESS);
  411. }
  412. static bool intel_sdvo_set_active_outputs(struct intel_output *intel_output,
  413. u16 outputs)
  414. {
  415. u8 status;
  416. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs,
  417. sizeof(outputs));
  418. status = intel_sdvo_read_response(intel_output, NULL, 0);
  419. return (status == SDVO_CMD_STATUS_SUCCESS);
  420. }
  421. static bool intel_sdvo_set_encoder_power_state(struct intel_output *intel_output,
  422. int mode)
  423. {
  424. u8 status, state = SDVO_ENCODER_STATE_ON;
  425. switch (mode) {
  426. case DRM_MODE_DPMS_ON:
  427. state = SDVO_ENCODER_STATE_ON;
  428. break;
  429. case DRM_MODE_DPMS_STANDBY:
  430. state = SDVO_ENCODER_STATE_STANDBY;
  431. break;
  432. case DRM_MODE_DPMS_SUSPEND:
  433. state = SDVO_ENCODER_STATE_SUSPEND;
  434. break;
  435. case DRM_MODE_DPMS_OFF:
  436. state = SDVO_ENCODER_STATE_OFF;
  437. break;
  438. }
  439. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ENCODER_POWER_STATE, &state,
  440. sizeof(state));
  441. status = intel_sdvo_read_response(intel_output, NULL, 0);
  442. return (status == SDVO_CMD_STATUS_SUCCESS);
  443. }
  444. static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output *intel_output,
  445. int *clock_min,
  446. int *clock_max)
  447. {
  448. struct intel_sdvo_pixel_clock_range clocks;
  449. u8 status;
  450. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
  451. NULL, 0);
  452. status = intel_sdvo_read_response(intel_output, &clocks, sizeof(clocks));
  453. if (status != SDVO_CMD_STATUS_SUCCESS)
  454. return false;
  455. /* Convert the values from units of 10 kHz to kHz. */
  456. *clock_min = clocks.min * 10;
  457. *clock_max = clocks.max * 10;
  458. return true;
  459. }
  460. static bool intel_sdvo_set_target_output(struct intel_output *intel_output,
  461. u16 outputs)
  462. {
  463. u8 status;
  464. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_OUTPUT, &outputs,
  465. sizeof(outputs));
  466. status = intel_sdvo_read_response(intel_output, NULL, 0);
  467. return (status == SDVO_CMD_STATUS_SUCCESS);
  468. }
  469. static bool intel_sdvo_get_timing(struct intel_output *intel_output, u8 cmd,
  470. struct intel_sdvo_dtd *dtd)
  471. {
  472. u8 status;
  473. intel_sdvo_write_cmd(intel_output, cmd, NULL, 0);
  474. status = intel_sdvo_read_response(intel_output, &dtd->part1,
  475. sizeof(dtd->part1));
  476. if (status != SDVO_CMD_STATUS_SUCCESS)
  477. return false;
  478. intel_sdvo_write_cmd(intel_output, cmd + 1, NULL, 0);
  479. status = intel_sdvo_read_response(intel_output, &dtd->part2,
  480. sizeof(dtd->part2));
  481. if (status != SDVO_CMD_STATUS_SUCCESS)
  482. return false;
  483. return true;
  484. }
  485. static bool intel_sdvo_get_input_timing(struct intel_output *intel_output,
  486. struct intel_sdvo_dtd *dtd)
  487. {
  488. return intel_sdvo_get_timing(intel_output,
  489. SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
  490. }
  491. static bool intel_sdvo_get_output_timing(struct intel_output *intel_output,
  492. struct intel_sdvo_dtd *dtd)
  493. {
  494. return intel_sdvo_get_timing(intel_output,
  495. SDVO_CMD_GET_OUTPUT_TIMINGS_PART1, dtd);
  496. }
  497. static bool intel_sdvo_set_timing(struct intel_output *intel_output, u8 cmd,
  498. struct intel_sdvo_dtd *dtd)
  499. {
  500. u8 status;
  501. intel_sdvo_write_cmd(intel_output, cmd, &dtd->part1, sizeof(dtd->part1));
  502. status = intel_sdvo_read_response(intel_output, NULL, 0);
  503. if (status != SDVO_CMD_STATUS_SUCCESS)
  504. return false;
  505. intel_sdvo_write_cmd(intel_output, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  506. status = intel_sdvo_read_response(intel_output, NULL, 0);
  507. if (status != SDVO_CMD_STATUS_SUCCESS)
  508. return false;
  509. return true;
  510. }
  511. static bool intel_sdvo_set_input_timing(struct intel_output *intel_output,
  512. struct intel_sdvo_dtd *dtd)
  513. {
  514. return intel_sdvo_set_timing(intel_output,
  515. SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
  516. }
  517. static bool intel_sdvo_set_output_timing(struct intel_output *intel_output,
  518. struct intel_sdvo_dtd *dtd)
  519. {
  520. return intel_sdvo_set_timing(intel_output,
  521. SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
  522. }
  523. static bool
  524. intel_sdvo_create_preferred_input_timing(struct intel_output *output,
  525. uint16_t clock,
  526. uint16_t width,
  527. uint16_t height)
  528. {
  529. struct intel_sdvo_preferred_input_timing_args args;
  530. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  531. uint8_t status;
  532. memset(&args, 0, sizeof(args));
  533. args.clock = clock;
  534. args.width = width;
  535. args.height = height;
  536. args.interlace = 0;
  537. if (sdvo_priv->is_lvds &&
  538. (sdvo_priv->sdvo_lvds_fixed_mode->hdisplay != width ||
  539. sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height))
  540. args.scaled = 1;
  541. intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
  542. &args, sizeof(args));
  543. status = intel_sdvo_read_response(output, NULL, 0);
  544. if (status != SDVO_CMD_STATUS_SUCCESS)
  545. return false;
  546. return true;
  547. }
  548. static bool intel_sdvo_get_preferred_input_timing(struct intel_output *output,
  549. struct intel_sdvo_dtd *dtd)
  550. {
  551. bool status;
  552. intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
  553. NULL, 0);
  554. status = intel_sdvo_read_response(output, &dtd->part1,
  555. sizeof(dtd->part1));
  556. if (status != SDVO_CMD_STATUS_SUCCESS)
  557. return false;
  558. intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
  559. NULL, 0);
  560. status = intel_sdvo_read_response(output, &dtd->part2,
  561. sizeof(dtd->part2));
  562. if (status != SDVO_CMD_STATUS_SUCCESS)
  563. return false;
  564. return false;
  565. }
  566. static int intel_sdvo_get_clock_rate_mult(struct intel_output *intel_output)
  567. {
  568. u8 response, status;
  569. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_CLOCK_RATE_MULT, NULL, 0);
  570. status = intel_sdvo_read_response(intel_output, &response, 1);
  571. if (status != SDVO_CMD_STATUS_SUCCESS) {
  572. DRM_DEBUG("Couldn't get SDVO clock rate multiplier\n");
  573. return SDVO_CLOCK_RATE_MULT_1X;
  574. } else {
  575. DRM_DEBUG("Current clock rate multiplier: %d\n", response);
  576. }
  577. return response;
  578. }
  579. static bool intel_sdvo_set_clock_rate_mult(struct intel_output *intel_output, u8 val)
  580. {
  581. u8 status;
  582. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
  583. status = intel_sdvo_read_response(intel_output, NULL, 0);
  584. if (status != SDVO_CMD_STATUS_SUCCESS)
  585. return false;
  586. return true;
  587. }
  588. static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
  589. struct drm_display_mode *mode)
  590. {
  591. uint16_t width, height;
  592. uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
  593. uint16_t h_sync_offset, v_sync_offset;
  594. width = mode->crtc_hdisplay;
  595. height = mode->crtc_vdisplay;
  596. /* do some mode translations */
  597. h_blank_len = mode->crtc_hblank_end - mode->crtc_hblank_start;
  598. h_sync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
  599. v_blank_len = mode->crtc_vblank_end - mode->crtc_vblank_start;
  600. v_sync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
  601. h_sync_offset = mode->crtc_hsync_start - mode->crtc_hblank_start;
  602. v_sync_offset = mode->crtc_vsync_start - mode->crtc_vblank_start;
  603. dtd->part1.clock = mode->clock / 10;
  604. dtd->part1.h_active = width & 0xff;
  605. dtd->part1.h_blank = h_blank_len & 0xff;
  606. dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
  607. ((h_blank_len >> 8) & 0xf);
  608. dtd->part1.v_active = height & 0xff;
  609. dtd->part1.v_blank = v_blank_len & 0xff;
  610. dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
  611. ((v_blank_len >> 8) & 0xf);
  612. dtd->part2.h_sync_off = h_sync_offset & 0xff;
  613. dtd->part2.h_sync_width = h_sync_len & 0xff;
  614. dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
  615. (v_sync_len & 0xf);
  616. dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
  617. ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
  618. ((v_sync_len & 0x30) >> 4);
  619. dtd->part2.dtd_flags = 0x18;
  620. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  621. dtd->part2.dtd_flags |= 0x2;
  622. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  623. dtd->part2.dtd_flags |= 0x4;
  624. dtd->part2.sdvo_flags = 0;
  625. dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
  626. dtd->part2.reserved = 0;
  627. }
  628. static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode,
  629. struct intel_sdvo_dtd *dtd)
  630. {
  631. mode->hdisplay = dtd->part1.h_active;
  632. mode->hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
  633. mode->hsync_start = mode->hdisplay + dtd->part2.h_sync_off;
  634. mode->hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
  635. mode->hsync_end = mode->hsync_start + dtd->part2.h_sync_width;
  636. mode->hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
  637. mode->htotal = mode->hdisplay + dtd->part1.h_blank;
  638. mode->htotal += (dtd->part1.h_high & 0xf) << 8;
  639. mode->vdisplay = dtd->part1.v_active;
  640. mode->vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
  641. mode->vsync_start = mode->vdisplay;
  642. mode->vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
  643. mode->vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
  644. mode->vsync_start += dtd->part2.v_sync_off_high & 0xc0;
  645. mode->vsync_end = mode->vsync_start +
  646. (dtd->part2.v_sync_off_width & 0xf);
  647. mode->vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
  648. mode->vtotal = mode->vdisplay + dtd->part1.v_blank;
  649. mode->vtotal += (dtd->part1.v_high & 0xf) << 8;
  650. mode->clock = dtd->part1.clock * 10;
  651. mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC);
  652. if (dtd->part2.dtd_flags & 0x2)
  653. mode->flags |= DRM_MODE_FLAG_PHSYNC;
  654. if (dtd->part2.dtd_flags & 0x4)
  655. mode->flags |= DRM_MODE_FLAG_PVSYNC;
  656. }
  657. static bool intel_sdvo_get_supp_encode(struct intel_output *output,
  658. struct intel_sdvo_encode *encode)
  659. {
  660. uint8_t status;
  661. intel_sdvo_write_cmd(output, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0);
  662. status = intel_sdvo_read_response(output, encode, sizeof(*encode));
  663. if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */
  664. memset(encode, 0, sizeof(*encode));
  665. return false;
  666. }
  667. return true;
  668. }
  669. static bool intel_sdvo_set_encode(struct intel_output *output, uint8_t mode)
  670. {
  671. uint8_t status;
  672. intel_sdvo_write_cmd(output, SDVO_CMD_SET_ENCODE, &mode, 1);
  673. status = intel_sdvo_read_response(output, NULL, 0);
  674. return (status == SDVO_CMD_STATUS_SUCCESS);
  675. }
  676. static bool intel_sdvo_set_colorimetry(struct intel_output *output,
  677. uint8_t mode)
  678. {
  679. uint8_t status;
  680. intel_sdvo_write_cmd(output, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
  681. status = intel_sdvo_read_response(output, NULL, 0);
  682. return (status == SDVO_CMD_STATUS_SUCCESS);
  683. }
  684. #if 0
  685. static void intel_sdvo_dump_hdmi_buf(struct intel_output *output)
  686. {
  687. int i, j;
  688. uint8_t set_buf_index[2];
  689. uint8_t av_split;
  690. uint8_t buf_size;
  691. uint8_t buf[48];
  692. uint8_t *pos;
  693. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0);
  694. intel_sdvo_read_response(output, &av_split, 1);
  695. for (i = 0; i <= av_split; i++) {
  696. set_buf_index[0] = i; set_buf_index[1] = 0;
  697. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX,
  698. set_buf_index, 2);
  699. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
  700. intel_sdvo_read_response(output, &buf_size, 1);
  701. pos = buf;
  702. for (j = 0; j <= buf_size; j += 8) {
  703. intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_DATA,
  704. NULL, 0);
  705. intel_sdvo_read_response(output, pos, 8);
  706. pos += 8;
  707. }
  708. }
  709. }
  710. #endif
  711. static void intel_sdvo_set_hdmi_buf(struct intel_output *output, int index,
  712. uint8_t *data, int8_t size, uint8_t tx_rate)
  713. {
  714. uint8_t set_buf_index[2];
  715. set_buf_index[0] = index;
  716. set_buf_index[1] = 0;
  717. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2);
  718. for (; size > 0; size -= 8) {
  719. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_DATA, data, 8);
  720. data += 8;
  721. }
  722. intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1);
  723. }
  724. static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size)
  725. {
  726. uint8_t csum = 0;
  727. int i;
  728. for (i = 0; i < size; i++)
  729. csum += data[i];
  730. return 0x100 - csum;
  731. }
  732. #define DIP_TYPE_AVI 0x82
  733. #define DIP_VERSION_AVI 0x2
  734. #define DIP_LEN_AVI 13
  735. struct dip_infoframe {
  736. uint8_t type;
  737. uint8_t version;
  738. uint8_t len;
  739. uint8_t checksum;
  740. union {
  741. struct {
  742. /* Packet Byte #1 */
  743. uint8_t S:2;
  744. uint8_t B:2;
  745. uint8_t A:1;
  746. uint8_t Y:2;
  747. uint8_t rsvd1:1;
  748. /* Packet Byte #2 */
  749. uint8_t R:4;
  750. uint8_t M:2;
  751. uint8_t C:2;
  752. /* Packet Byte #3 */
  753. uint8_t SC:2;
  754. uint8_t Q:2;
  755. uint8_t EC:3;
  756. uint8_t ITC:1;
  757. /* Packet Byte #4 */
  758. uint8_t VIC:7;
  759. uint8_t rsvd2:1;
  760. /* Packet Byte #5 */
  761. uint8_t PR:4;
  762. uint8_t rsvd3:4;
  763. /* Packet Byte #6~13 */
  764. uint16_t top_bar_end;
  765. uint16_t bottom_bar_start;
  766. uint16_t left_bar_end;
  767. uint16_t right_bar_start;
  768. } avi;
  769. struct {
  770. /* Packet Byte #1 */
  771. uint8_t channel_count:3;
  772. uint8_t rsvd1:1;
  773. uint8_t coding_type:4;
  774. /* Packet Byte #2 */
  775. uint8_t sample_size:2; /* SS0, SS1 */
  776. uint8_t sample_frequency:3;
  777. uint8_t rsvd2:3;
  778. /* Packet Byte #3 */
  779. uint8_t coding_type_private:5;
  780. uint8_t rsvd3:3;
  781. /* Packet Byte #4 */
  782. uint8_t channel_allocation;
  783. /* Packet Byte #5 */
  784. uint8_t rsvd4:3;
  785. uint8_t level_shift:4;
  786. uint8_t downmix_inhibit:1;
  787. } audio;
  788. uint8_t payload[28];
  789. } __attribute__ ((packed)) u;
  790. } __attribute__((packed));
  791. static void intel_sdvo_set_avi_infoframe(struct intel_output *output,
  792. struct drm_display_mode * mode)
  793. {
  794. struct dip_infoframe avi_if = {
  795. .type = DIP_TYPE_AVI,
  796. .version = DIP_VERSION_AVI,
  797. .len = DIP_LEN_AVI,
  798. };
  799. avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if,
  800. 4 + avi_if.len);
  801. intel_sdvo_set_hdmi_buf(output, 1, (uint8_t *)&avi_if, 4 + avi_if.len,
  802. SDVO_HBUF_TX_VSYNC);
  803. }
  804. static void intel_sdvo_set_tv_format(struct intel_output *output)
  805. {
  806. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  807. struct intel_sdvo_tv_format *format, unset;
  808. u8 status;
  809. format = &sdvo_priv->tv_format;
  810. memset(&unset, 0, sizeof(unset));
  811. if (memcmp(format, &unset, sizeof(*format))) {
  812. DRM_DEBUG("%s: Choosing default TV format of NTSC-M\n",
  813. SDVO_NAME(sdvo_priv));
  814. format->ntsc_m = 1;
  815. intel_sdvo_write_cmd(output, SDVO_CMD_SET_TV_FORMAT, format,
  816. sizeof(*format));
  817. status = intel_sdvo_read_response(output, NULL, 0);
  818. if (status != SDVO_CMD_STATUS_SUCCESS)
  819. DRM_DEBUG("%s: Failed to set TV format\n",
  820. SDVO_NAME(sdvo_priv));
  821. }
  822. }
  823. static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder,
  824. struct drm_display_mode *mode,
  825. struct drm_display_mode *adjusted_mode)
  826. {
  827. struct intel_output *output = enc_to_intel_output(encoder);
  828. struct intel_sdvo_priv *dev_priv = output->dev_priv;
  829. if (dev_priv->is_tv) {
  830. struct intel_sdvo_dtd output_dtd;
  831. bool success;
  832. /* We need to construct preferred input timings based on our
  833. * output timings. To do that, we have to set the output
  834. * timings, even though this isn't really the right place in
  835. * the sequence to do it. Oh well.
  836. */
  837. /* Set output timings */
  838. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  839. intel_sdvo_set_target_output(output,
  840. dev_priv->controlled_output);
  841. intel_sdvo_set_output_timing(output, &output_dtd);
  842. /* Set the input timing to the screen. Assume always input 0. */
  843. intel_sdvo_set_target_input(output, true, false);
  844. success = intel_sdvo_create_preferred_input_timing(output,
  845. mode->clock / 10,
  846. mode->hdisplay,
  847. mode->vdisplay);
  848. if (success) {
  849. struct intel_sdvo_dtd input_dtd;
  850. intel_sdvo_get_preferred_input_timing(output,
  851. &input_dtd);
  852. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  853. dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
  854. drm_mode_set_crtcinfo(adjusted_mode, 0);
  855. mode->clock = adjusted_mode->clock;
  856. adjusted_mode->clock *=
  857. intel_sdvo_get_pixel_multiplier(mode);
  858. } else {
  859. return false;
  860. }
  861. } else if (dev_priv->is_lvds) {
  862. struct intel_sdvo_dtd output_dtd;
  863. bool success;
  864. drm_mode_set_crtcinfo(dev_priv->sdvo_lvds_fixed_mode, 0);
  865. /* Set output timings */
  866. intel_sdvo_get_dtd_from_mode(&output_dtd,
  867. dev_priv->sdvo_lvds_fixed_mode);
  868. intel_sdvo_set_target_output(output,
  869. dev_priv->controlled_output);
  870. intel_sdvo_set_output_timing(output, &output_dtd);
  871. /* Set the input timing to the screen. Assume always input 0. */
  872. intel_sdvo_set_target_input(output, true, false);
  873. success = intel_sdvo_create_preferred_input_timing(
  874. output,
  875. mode->clock / 10,
  876. mode->hdisplay,
  877. mode->vdisplay);
  878. if (success) {
  879. struct intel_sdvo_dtd input_dtd;
  880. intel_sdvo_get_preferred_input_timing(output,
  881. &input_dtd);
  882. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  883. dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags;
  884. drm_mode_set_crtcinfo(adjusted_mode, 0);
  885. mode->clock = adjusted_mode->clock;
  886. adjusted_mode->clock *=
  887. intel_sdvo_get_pixel_multiplier(mode);
  888. } else {
  889. return false;
  890. }
  891. } else {
  892. /* Make the CRTC code factor in the SDVO pixel multiplier. The
  893. * SDVO device will be told of the multiplier during mode_set.
  894. */
  895. adjusted_mode->clock *= intel_sdvo_get_pixel_multiplier(mode);
  896. }
  897. return true;
  898. }
  899. static void intel_sdvo_mode_set(struct drm_encoder *encoder,
  900. struct drm_display_mode *mode,
  901. struct drm_display_mode *adjusted_mode)
  902. {
  903. struct drm_device *dev = encoder->dev;
  904. struct drm_i915_private *dev_priv = dev->dev_private;
  905. struct drm_crtc *crtc = encoder->crtc;
  906. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  907. struct intel_output *output = enc_to_intel_output(encoder);
  908. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  909. u32 sdvox = 0;
  910. int sdvo_pixel_multiply;
  911. struct intel_sdvo_in_out_map in_out;
  912. struct intel_sdvo_dtd input_dtd;
  913. u8 status;
  914. if (!mode)
  915. return;
  916. /* First, set the input mapping for the first input to our controlled
  917. * output. This is only correct if we're a single-input device, in
  918. * which case the first input is the output from the appropriate SDVO
  919. * channel on the motherboard. In a two-input device, the first input
  920. * will be SDVOB and the second SDVOC.
  921. */
  922. in_out.in0 = sdvo_priv->controlled_output;
  923. in_out.in1 = 0;
  924. intel_sdvo_write_cmd(output, SDVO_CMD_SET_IN_OUT_MAP,
  925. &in_out, sizeof(in_out));
  926. status = intel_sdvo_read_response(output, NULL, 0);
  927. if (sdvo_priv->is_hdmi) {
  928. intel_sdvo_set_avi_infoframe(output, mode);
  929. sdvox |= SDVO_AUDIO_ENABLE;
  930. }
  931. /* We have tried to get input timing in mode_fixup, and filled into
  932. adjusted_mode */
  933. if (sdvo_priv->is_tv || sdvo_priv->is_lvds) {
  934. intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
  935. input_dtd.part2.sdvo_flags = sdvo_priv->sdvo_flags;
  936. } else
  937. intel_sdvo_get_dtd_from_mode(&input_dtd, mode);
  938. /* If it's a TV, we already set the output timing in mode_fixup.
  939. * Otherwise, the output timing is equal to the input timing.
  940. */
  941. if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) {
  942. /* Set the output timing to the screen */
  943. intel_sdvo_set_target_output(output,
  944. sdvo_priv->controlled_output);
  945. intel_sdvo_set_output_timing(output, &input_dtd);
  946. }
  947. /* Set the input timing to the screen. Assume always input 0. */
  948. intel_sdvo_set_target_input(output, true, false);
  949. if (sdvo_priv->is_tv)
  950. intel_sdvo_set_tv_format(output);
  951. /* We would like to use intel_sdvo_create_preferred_input_timing() to
  952. * provide the device with a timing it can support, if it supports that
  953. * feature. However, presumably we would need to adjust the CRTC to
  954. * output the preferred timing, and we don't support that currently.
  955. */
  956. #if 0
  957. success = intel_sdvo_create_preferred_input_timing(output, clock,
  958. width, height);
  959. if (success) {
  960. struct intel_sdvo_dtd *input_dtd;
  961. intel_sdvo_get_preferred_input_timing(output, &input_dtd);
  962. intel_sdvo_set_input_timing(output, &input_dtd);
  963. }
  964. #else
  965. intel_sdvo_set_input_timing(output, &input_dtd);
  966. #endif
  967. switch (intel_sdvo_get_pixel_multiplier(mode)) {
  968. case 1:
  969. intel_sdvo_set_clock_rate_mult(output,
  970. SDVO_CLOCK_RATE_MULT_1X);
  971. break;
  972. case 2:
  973. intel_sdvo_set_clock_rate_mult(output,
  974. SDVO_CLOCK_RATE_MULT_2X);
  975. break;
  976. case 4:
  977. intel_sdvo_set_clock_rate_mult(output,
  978. SDVO_CLOCK_RATE_MULT_4X);
  979. break;
  980. }
  981. /* Set the SDVO control regs. */
  982. if (IS_I965G(dev)) {
  983. sdvox |= SDVO_BORDER_ENABLE |
  984. SDVO_VSYNC_ACTIVE_HIGH |
  985. SDVO_HSYNC_ACTIVE_HIGH;
  986. } else {
  987. sdvox |= I915_READ(sdvo_priv->output_device);
  988. switch (sdvo_priv->output_device) {
  989. case SDVOB:
  990. sdvox &= SDVOB_PRESERVE_MASK;
  991. break;
  992. case SDVOC:
  993. sdvox &= SDVOC_PRESERVE_MASK;
  994. break;
  995. }
  996. sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
  997. }
  998. if (intel_crtc->pipe == 1)
  999. sdvox |= SDVO_PIPE_B_SELECT;
  1000. sdvo_pixel_multiply = intel_sdvo_get_pixel_multiplier(mode);
  1001. if (IS_I965G(dev)) {
  1002. /* done in crtc_mode_set as the dpll_md reg must be written early */
  1003. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  1004. /* done in crtc_mode_set as it lives inside the dpll register */
  1005. } else {
  1006. sdvox |= (sdvo_pixel_multiply - 1) << SDVO_PORT_MULTIPLY_SHIFT;
  1007. }
  1008. if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL)
  1009. sdvox |= SDVO_STALL_SELECT;
  1010. intel_sdvo_write_sdvox(output, sdvox);
  1011. }
  1012. static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode)
  1013. {
  1014. struct drm_device *dev = encoder->dev;
  1015. struct drm_i915_private *dev_priv = dev->dev_private;
  1016. struct intel_output *intel_output = enc_to_intel_output(encoder);
  1017. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1018. u32 temp;
  1019. if (mode != DRM_MODE_DPMS_ON) {
  1020. intel_sdvo_set_active_outputs(intel_output, 0);
  1021. if (0)
  1022. intel_sdvo_set_encoder_power_state(intel_output, mode);
  1023. if (mode == DRM_MODE_DPMS_OFF) {
  1024. temp = I915_READ(sdvo_priv->output_device);
  1025. if ((temp & SDVO_ENABLE) != 0) {
  1026. intel_sdvo_write_sdvox(intel_output, temp & ~SDVO_ENABLE);
  1027. }
  1028. }
  1029. } else {
  1030. bool input1, input2;
  1031. int i;
  1032. u8 status;
  1033. temp = I915_READ(sdvo_priv->output_device);
  1034. if ((temp & SDVO_ENABLE) == 0)
  1035. intel_sdvo_write_sdvox(intel_output, temp | SDVO_ENABLE);
  1036. for (i = 0; i < 2; i++)
  1037. intel_wait_for_vblank(dev);
  1038. status = intel_sdvo_get_trained_inputs(intel_output, &input1,
  1039. &input2);
  1040. /* Warn if the device reported failure to sync.
  1041. * A lot of SDVO devices fail to notify of sync, but it's
  1042. * a given it the status is a success, we succeeded.
  1043. */
  1044. if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
  1045. DRM_DEBUG("First %s output reported failure to sync\n",
  1046. SDVO_NAME(sdvo_priv));
  1047. }
  1048. if (0)
  1049. intel_sdvo_set_encoder_power_state(intel_output, mode);
  1050. intel_sdvo_set_active_outputs(intel_output, sdvo_priv->controlled_output);
  1051. }
  1052. return;
  1053. }
  1054. static void intel_sdvo_save(struct drm_connector *connector)
  1055. {
  1056. struct drm_device *dev = connector->dev;
  1057. struct drm_i915_private *dev_priv = dev->dev_private;
  1058. struct intel_output *intel_output = to_intel_output(connector);
  1059. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1060. int o;
  1061. sdvo_priv->save_sdvo_mult = intel_sdvo_get_clock_rate_mult(intel_output);
  1062. intel_sdvo_get_active_outputs(intel_output, &sdvo_priv->save_active_outputs);
  1063. if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
  1064. intel_sdvo_set_target_input(intel_output, true, false);
  1065. intel_sdvo_get_input_timing(intel_output,
  1066. &sdvo_priv->save_input_dtd_1);
  1067. }
  1068. if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
  1069. intel_sdvo_set_target_input(intel_output, false, true);
  1070. intel_sdvo_get_input_timing(intel_output,
  1071. &sdvo_priv->save_input_dtd_2);
  1072. }
  1073. for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
  1074. {
  1075. u16 this_output = (1 << o);
  1076. if (sdvo_priv->caps.output_flags & this_output)
  1077. {
  1078. intel_sdvo_set_target_output(intel_output, this_output);
  1079. intel_sdvo_get_output_timing(intel_output,
  1080. &sdvo_priv->save_output_dtd[o]);
  1081. }
  1082. }
  1083. if (sdvo_priv->is_tv) {
  1084. /* XXX: Save TV format/enhancements. */
  1085. }
  1086. sdvo_priv->save_SDVOX = I915_READ(sdvo_priv->output_device);
  1087. }
  1088. static void intel_sdvo_restore(struct drm_connector *connector)
  1089. {
  1090. struct drm_device *dev = connector->dev;
  1091. struct intel_output *intel_output = to_intel_output(connector);
  1092. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1093. int o;
  1094. int i;
  1095. bool input1, input2;
  1096. u8 status;
  1097. intel_sdvo_set_active_outputs(intel_output, 0);
  1098. for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++)
  1099. {
  1100. u16 this_output = (1 << o);
  1101. if (sdvo_priv->caps.output_flags & this_output) {
  1102. intel_sdvo_set_target_output(intel_output, this_output);
  1103. intel_sdvo_set_output_timing(intel_output, &sdvo_priv->save_output_dtd[o]);
  1104. }
  1105. }
  1106. if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) {
  1107. intel_sdvo_set_target_input(intel_output, true, false);
  1108. intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_1);
  1109. }
  1110. if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) {
  1111. intel_sdvo_set_target_input(intel_output, false, true);
  1112. intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_2);
  1113. }
  1114. intel_sdvo_set_clock_rate_mult(intel_output, sdvo_priv->save_sdvo_mult);
  1115. if (sdvo_priv->is_tv) {
  1116. /* XXX: Restore TV format/enhancements. */
  1117. }
  1118. intel_sdvo_write_sdvox(intel_output, sdvo_priv->save_SDVOX);
  1119. if (sdvo_priv->save_SDVOX & SDVO_ENABLE)
  1120. {
  1121. for (i = 0; i < 2; i++)
  1122. intel_wait_for_vblank(dev);
  1123. status = intel_sdvo_get_trained_inputs(intel_output, &input1, &input2);
  1124. if (status == SDVO_CMD_STATUS_SUCCESS && !input1)
  1125. DRM_DEBUG("First %s output reported failure to sync\n",
  1126. SDVO_NAME(sdvo_priv));
  1127. }
  1128. intel_sdvo_set_active_outputs(intel_output, sdvo_priv->save_active_outputs);
  1129. }
  1130. static int intel_sdvo_mode_valid(struct drm_connector *connector,
  1131. struct drm_display_mode *mode)
  1132. {
  1133. struct intel_output *intel_output = to_intel_output(connector);
  1134. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1135. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1136. return MODE_NO_DBLESCAN;
  1137. if (sdvo_priv->pixel_clock_min > mode->clock)
  1138. return MODE_CLOCK_LOW;
  1139. if (sdvo_priv->pixel_clock_max < mode->clock)
  1140. return MODE_CLOCK_HIGH;
  1141. if (sdvo_priv->is_lvds == true) {
  1142. if (sdvo_priv->sdvo_lvds_fixed_mode == NULL)
  1143. return MODE_PANEL;
  1144. if (mode->hdisplay > sdvo_priv->sdvo_lvds_fixed_mode->hdisplay)
  1145. return MODE_PANEL;
  1146. if (mode->vdisplay > sdvo_priv->sdvo_lvds_fixed_mode->vdisplay)
  1147. return MODE_PANEL;
  1148. }
  1149. return MODE_OK;
  1150. }
  1151. static bool intel_sdvo_get_capabilities(struct intel_output *intel_output, struct intel_sdvo_caps *caps)
  1152. {
  1153. u8 status;
  1154. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0);
  1155. status = intel_sdvo_read_response(intel_output, caps, sizeof(*caps));
  1156. if (status != SDVO_CMD_STATUS_SUCCESS)
  1157. return false;
  1158. return true;
  1159. }
  1160. struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB)
  1161. {
  1162. struct drm_connector *connector = NULL;
  1163. struct intel_output *iout = NULL;
  1164. struct intel_sdvo_priv *sdvo;
  1165. /* find the sdvo connector */
  1166. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1167. iout = to_intel_output(connector);
  1168. if (iout->type != INTEL_OUTPUT_SDVO)
  1169. continue;
  1170. sdvo = iout->dev_priv;
  1171. if (sdvo->output_device == SDVOB && sdvoB)
  1172. return connector;
  1173. if (sdvo->output_device == SDVOC && !sdvoB)
  1174. return connector;
  1175. }
  1176. return NULL;
  1177. }
  1178. int intel_sdvo_supports_hotplug(struct drm_connector *connector)
  1179. {
  1180. u8 response[2];
  1181. u8 status;
  1182. struct intel_output *intel_output;
  1183. DRM_DEBUG("\n");
  1184. if (!connector)
  1185. return 0;
  1186. intel_output = to_intel_output(connector);
  1187. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
  1188. status = intel_sdvo_read_response(intel_output, &response, 2);
  1189. if (response[0] !=0)
  1190. return 1;
  1191. return 0;
  1192. }
  1193. void intel_sdvo_set_hotplug(struct drm_connector *connector, int on)
  1194. {
  1195. u8 response[2];
  1196. u8 status;
  1197. struct intel_output *intel_output = to_intel_output(connector);
  1198. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
  1199. intel_sdvo_read_response(intel_output, &response, 2);
  1200. if (on) {
  1201. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0);
  1202. status = intel_sdvo_read_response(intel_output, &response, 2);
  1203. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
  1204. } else {
  1205. response[0] = 0;
  1206. response[1] = 0;
  1207. intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2);
  1208. }
  1209. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0);
  1210. intel_sdvo_read_response(intel_output, &response, 2);
  1211. }
  1212. static bool
  1213. intel_sdvo_multifunc_encoder(struct intel_output *intel_output)
  1214. {
  1215. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1216. int caps = 0;
  1217. if (sdvo_priv->caps.output_flags &
  1218. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
  1219. caps++;
  1220. if (sdvo_priv->caps.output_flags &
  1221. (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1))
  1222. caps++;
  1223. if (sdvo_priv->caps.output_flags &
  1224. (SDVO_OUTPUT_SVID0 | SDVO_OUTPUT_SVID1))
  1225. caps++;
  1226. if (sdvo_priv->caps.output_flags &
  1227. (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_CVBS1))
  1228. caps++;
  1229. if (sdvo_priv->caps.output_flags &
  1230. (SDVO_OUTPUT_YPRPB0 | SDVO_OUTPUT_YPRPB1))
  1231. caps++;
  1232. if (sdvo_priv->caps.output_flags &
  1233. (SDVO_OUTPUT_SCART0 | SDVO_OUTPUT_SCART1))
  1234. caps++;
  1235. if (sdvo_priv->caps.output_flags &
  1236. (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1))
  1237. caps++;
  1238. return (caps > 1);
  1239. }
  1240. enum drm_connector_status
  1241. intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response)
  1242. {
  1243. struct intel_output *intel_output = to_intel_output(connector);
  1244. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1245. enum drm_connector_status status = connector_status_connected;
  1246. struct edid *edid = NULL;
  1247. edid = drm_get_edid(&intel_output->base,
  1248. intel_output->ddc_bus);
  1249. if (edid != NULL) {
  1250. /* Don't report the output as connected if it's a DVI-I
  1251. * connector with a non-digital EDID coming out.
  1252. */
  1253. if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
  1254. if (edid->input & DRM_EDID_INPUT_DIGITAL)
  1255. sdvo_priv->is_hdmi =
  1256. drm_detect_hdmi_monitor(edid);
  1257. else
  1258. status = connector_status_disconnected;
  1259. }
  1260. kfree(edid);
  1261. intel_output->base.display_info.raw_edid = NULL;
  1262. } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1))
  1263. status = connector_status_disconnected;
  1264. return status;
  1265. }
  1266. static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector)
  1267. {
  1268. uint16_t response;
  1269. u8 status;
  1270. struct intel_output *intel_output = to_intel_output(connector);
  1271. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1272. intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0);
  1273. status = intel_sdvo_read_response(intel_output, &response, 2);
  1274. DRM_DEBUG("SDVO response %d %d\n", response & 0xff, response >> 8);
  1275. if (status != SDVO_CMD_STATUS_SUCCESS)
  1276. return connector_status_unknown;
  1277. if (response == 0)
  1278. return connector_status_disconnected;
  1279. if (intel_sdvo_multifunc_encoder(intel_output) &&
  1280. sdvo_priv->attached_output != response) {
  1281. if (sdvo_priv->controlled_output != response &&
  1282. intel_sdvo_output_setup(intel_output, response) != true)
  1283. return connector_status_unknown;
  1284. sdvo_priv->attached_output = response;
  1285. }
  1286. return intel_sdvo_hdmi_sink_detect(connector, response);
  1287. }
  1288. static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
  1289. {
  1290. struct intel_output *intel_output = to_intel_output(connector);
  1291. /* set the bus switch and get the modes */
  1292. intel_ddc_get_modes(intel_output);
  1293. #if 0
  1294. struct drm_device *dev = encoder->dev;
  1295. struct drm_i915_private *dev_priv = dev->dev_private;
  1296. /* Mac mini hack. On this device, I get DDC through the analog, which
  1297. * load-detects as disconnected. I fail to DDC through the SDVO DDC,
  1298. * but it does load-detect as connected. So, just steal the DDC bits
  1299. * from analog when we fail at finding it the right way.
  1300. */
  1301. crt = xf86_config->output[0];
  1302. intel_output = crt->driver_private;
  1303. if (intel_output->type == I830_OUTPUT_ANALOG &&
  1304. crt->funcs->detect(crt) == XF86OutputStatusDisconnected) {
  1305. I830I2CInit(pScrn, &intel_output->pDDCBus, GPIOA, "CRTDDC_A");
  1306. edid_mon = xf86OutputGetEDID(crt, intel_output->pDDCBus);
  1307. xf86DestroyI2CBusRec(intel_output->pDDCBus, true, true);
  1308. }
  1309. if (edid_mon) {
  1310. xf86OutputSetEDID(output, edid_mon);
  1311. modes = xf86OutputGetEDIDModes(output);
  1312. }
  1313. #endif
  1314. }
  1315. /**
  1316. * This function checks the current TV format, and chooses a default if
  1317. * it hasn't been set.
  1318. */
  1319. static void
  1320. intel_sdvo_check_tv_format(struct intel_output *output)
  1321. {
  1322. struct intel_sdvo_priv *dev_priv = output->dev_priv;
  1323. struct intel_sdvo_tv_format format;
  1324. uint8_t status;
  1325. intel_sdvo_write_cmd(output, SDVO_CMD_GET_TV_FORMAT, NULL, 0);
  1326. status = intel_sdvo_read_response(output, &format, sizeof(format));
  1327. if (status != SDVO_CMD_STATUS_SUCCESS)
  1328. return;
  1329. memcpy(&dev_priv->tv_format, &format, sizeof(format));
  1330. }
  1331. /*
  1332. * Set of SDVO TV modes.
  1333. * Note! This is in reply order (see loop in get_tv_modes).
  1334. * XXX: all 60Hz refresh?
  1335. */
  1336. struct drm_display_mode sdvo_tv_modes[] = {
  1337. { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
  1338. 416, 0, 200, 201, 232, 233, 0,
  1339. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1340. { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
  1341. 416, 0, 240, 241, 272, 273, 0,
  1342. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1343. { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
  1344. 496, 0, 300, 301, 332, 333, 0,
  1345. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1346. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
  1347. 736, 0, 350, 351, 382, 383, 0,
  1348. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1349. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
  1350. 736, 0, 400, 401, 432, 433, 0,
  1351. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1352. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
  1353. 736, 0, 480, 481, 512, 513, 0,
  1354. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1355. { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
  1356. 800, 0, 480, 481, 512, 513, 0,
  1357. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1358. { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
  1359. 800, 0, 576, 577, 608, 609, 0,
  1360. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1361. { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
  1362. 816, 0, 350, 351, 382, 383, 0,
  1363. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1364. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
  1365. 816, 0, 400, 401, 432, 433, 0,
  1366. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1367. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
  1368. 816, 0, 480, 481, 512, 513, 0,
  1369. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1370. { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
  1371. 816, 0, 540, 541, 572, 573, 0,
  1372. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1373. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
  1374. 816, 0, 576, 577, 608, 609, 0,
  1375. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1376. { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
  1377. 864, 0, 576, 577, 608, 609, 0,
  1378. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1379. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
  1380. 896, 0, 600, 601, 632, 633, 0,
  1381. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1382. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
  1383. 928, 0, 624, 625, 656, 657, 0,
  1384. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1385. { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
  1386. 1016, 0, 766, 767, 798, 799, 0,
  1387. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1388. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
  1389. 1120, 0, 768, 769, 800, 801, 0,
  1390. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1391. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
  1392. 1376, 0, 1024, 1025, 1056, 1057, 0,
  1393. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1394. };
  1395. static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
  1396. {
  1397. struct intel_output *output = to_intel_output(connector);
  1398. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1399. struct intel_sdvo_sdtv_resolution_request tv_res;
  1400. uint32_t reply = 0;
  1401. uint8_t status;
  1402. int i = 0;
  1403. intel_sdvo_check_tv_format(output);
  1404. /* Read the list of supported input resolutions for the selected TV
  1405. * format.
  1406. */
  1407. memset(&tv_res, 0, sizeof(tv_res));
  1408. memcpy(&tv_res, &sdvo_priv->tv_format, sizeof(tv_res));
  1409. intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
  1410. &tv_res, sizeof(tv_res));
  1411. status = intel_sdvo_read_response(output, &reply, 3);
  1412. if (status != SDVO_CMD_STATUS_SUCCESS)
  1413. return;
  1414. for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
  1415. if (reply & (1 << i)) {
  1416. struct drm_display_mode *nmode;
  1417. nmode = drm_mode_duplicate(connector->dev,
  1418. &sdvo_tv_modes[i]);
  1419. if (nmode)
  1420. drm_mode_probed_add(connector, nmode);
  1421. }
  1422. }
  1423. static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
  1424. {
  1425. struct intel_output *intel_output = to_intel_output(connector);
  1426. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1427. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1428. struct drm_display_mode *newmode;
  1429. /*
  1430. * Attempt to get the mode list from DDC.
  1431. * Assume that the preferred modes are
  1432. * arranged in priority order.
  1433. */
  1434. intel_ddc_get_modes(intel_output);
  1435. if (list_empty(&connector->probed_modes) == false)
  1436. goto end;
  1437. /* Fetch modes from VBT */
  1438. if (dev_priv->sdvo_lvds_vbt_mode != NULL) {
  1439. newmode = drm_mode_duplicate(connector->dev,
  1440. dev_priv->sdvo_lvds_vbt_mode);
  1441. if (newmode != NULL) {
  1442. /* Guarantee the mode is preferred */
  1443. newmode->type = (DRM_MODE_TYPE_PREFERRED |
  1444. DRM_MODE_TYPE_DRIVER);
  1445. drm_mode_probed_add(connector, newmode);
  1446. }
  1447. }
  1448. end:
  1449. list_for_each_entry(newmode, &connector->probed_modes, head) {
  1450. if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
  1451. sdvo_priv->sdvo_lvds_fixed_mode =
  1452. drm_mode_duplicate(connector->dev, newmode);
  1453. break;
  1454. }
  1455. }
  1456. }
  1457. static int intel_sdvo_get_modes(struct drm_connector *connector)
  1458. {
  1459. struct intel_output *output = to_intel_output(connector);
  1460. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1461. if (sdvo_priv->is_tv)
  1462. intel_sdvo_get_tv_modes(connector);
  1463. else if (sdvo_priv->is_lvds == true)
  1464. intel_sdvo_get_lvds_modes(connector);
  1465. else
  1466. intel_sdvo_get_ddc_modes(connector);
  1467. if (list_empty(&connector->probed_modes))
  1468. return 0;
  1469. return 1;
  1470. }
  1471. static void intel_sdvo_destroy(struct drm_connector *connector)
  1472. {
  1473. struct intel_output *intel_output = to_intel_output(connector);
  1474. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1475. if (intel_output->i2c_bus)
  1476. intel_i2c_destroy(intel_output->i2c_bus);
  1477. if (intel_output->ddc_bus)
  1478. intel_i2c_destroy(intel_output->ddc_bus);
  1479. if (sdvo_priv->sdvo_lvds_fixed_mode != NULL)
  1480. drm_mode_destroy(connector->dev,
  1481. sdvo_priv->sdvo_lvds_fixed_mode);
  1482. drm_sysfs_connector_remove(connector);
  1483. drm_connector_cleanup(connector);
  1484. kfree(intel_output);
  1485. }
  1486. static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = {
  1487. .dpms = intel_sdvo_dpms,
  1488. .mode_fixup = intel_sdvo_mode_fixup,
  1489. .prepare = intel_encoder_prepare,
  1490. .mode_set = intel_sdvo_mode_set,
  1491. .commit = intel_encoder_commit,
  1492. };
  1493. static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
  1494. .dpms = drm_helper_connector_dpms,
  1495. .save = intel_sdvo_save,
  1496. .restore = intel_sdvo_restore,
  1497. .detect = intel_sdvo_detect,
  1498. .fill_modes = drm_helper_probe_single_connector_modes,
  1499. .destroy = intel_sdvo_destroy,
  1500. };
  1501. static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
  1502. .get_modes = intel_sdvo_get_modes,
  1503. .mode_valid = intel_sdvo_mode_valid,
  1504. .best_encoder = intel_best_encoder,
  1505. };
  1506. static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
  1507. {
  1508. drm_encoder_cleanup(encoder);
  1509. }
  1510. static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
  1511. .destroy = intel_sdvo_enc_destroy,
  1512. };
  1513. /**
  1514. * Choose the appropriate DDC bus for control bus switch command for this
  1515. * SDVO output based on the controlled output.
  1516. *
  1517. * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
  1518. * outputs, then LVDS outputs.
  1519. */
  1520. static void
  1521. intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv)
  1522. {
  1523. uint16_t mask = 0;
  1524. unsigned int num_bits;
  1525. /* Make a mask of outputs less than or equal to our own priority in the
  1526. * list.
  1527. */
  1528. switch (dev_priv->controlled_output) {
  1529. case SDVO_OUTPUT_LVDS1:
  1530. mask |= SDVO_OUTPUT_LVDS1;
  1531. case SDVO_OUTPUT_LVDS0:
  1532. mask |= SDVO_OUTPUT_LVDS0;
  1533. case SDVO_OUTPUT_TMDS1:
  1534. mask |= SDVO_OUTPUT_TMDS1;
  1535. case SDVO_OUTPUT_TMDS0:
  1536. mask |= SDVO_OUTPUT_TMDS0;
  1537. case SDVO_OUTPUT_RGB1:
  1538. mask |= SDVO_OUTPUT_RGB1;
  1539. case SDVO_OUTPUT_RGB0:
  1540. mask |= SDVO_OUTPUT_RGB0;
  1541. break;
  1542. }
  1543. /* Count bits to find what number we are in the priority list. */
  1544. mask &= dev_priv->caps.output_flags;
  1545. num_bits = hweight16(mask);
  1546. if (num_bits > 3) {
  1547. /* if more than 3 outputs, default to DDC bus 3 for now */
  1548. num_bits = 3;
  1549. }
  1550. /* Corresponds to SDVO_CONTROL_BUS_DDCx */
  1551. dev_priv->ddc_bus = 1 << num_bits;
  1552. }
  1553. static bool
  1554. intel_sdvo_get_digital_encoding_mode(struct intel_output *output)
  1555. {
  1556. struct intel_sdvo_priv *sdvo_priv = output->dev_priv;
  1557. uint8_t status;
  1558. intel_sdvo_set_target_output(output, sdvo_priv->controlled_output);
  1559. intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0);
  1560. status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1);
  1561. if (status != SDVO_CMD_STATUS_SUCCESS)
  1562. return false;
  1563. return true;
  1564. }
  1565. static struct intel_output *
  1566. intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan)
  1567. {
  1568. struct drm_device *dev = chan->drm_dev;
  1569. struct drm_connector *connector;
  1570. struct intel_output *intel_output = NULL;
  1571. list_for_each_entry(connector,
  1572. &dev->mode_config.connector_list, head) {
  1573. if (to_intel_output(connector)->ddc_bus == &chan->adapter) {
  1574. intel_output = to_intel_output(connector);
  1575. break;
  1576. }
  1577. }
  1578. return intel_output;
  1579. }
  1580. static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap,
  1581. struct i2c_msg msgs[], int num)
  1582. {
  1583. struct intel_output *intel_output;
  1584. struct intel_sdvo_priv *sdvo_priv;
  1585. struct i2c_algo_bit_data *algo_data;
  1586. const struct i2c_algorithm *algo;
  1587. algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data;
  1588. intel_output =
  1589. intel_sdvo_chan_to_intel_output(
  1590. (struct intel_i2c_chan *)(algo_data->data));
  1591. if (intel_output == NULL)
  1592. return -EINVAL;
  1593. sdvo_priv = intel_output->dev_priv;
  1594. algo = intel_output->i2c_bus->algo;
  1595. intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus);
  1596. return algo->master_xfer(i2c_adap, msgs, num);
  1597. }
  1598. static struct i2c_algorithm intel_sdvo_i2c_bit_algo = {
  1599. .master_xfer = intel_sdvo_master_xfer,
  1600. };
  1601. static u8
  1602. intel_sdvo_get_slave_addr(struct drm_device *dev, int output_device)
  1603. {
  1604. struct drm_i915_private *dev_priv = dev->dev_private;
  1605. struct sdvo_device_mapping *my_mapping, *other_mapping;
  1606. if (output_device == SDVOB) {
  1607. my_mapping = &dev_priv->sdvo_mappings[0];
  1608. other_mapping = &dev_priv->sdvo_mappings[1];
  1609. } else {
  1610. my_mapping = &dev_priv->sdvo_mappings[1];
  1611. other_mapping = &dev_priv->sdvo_mappings[0];
  1612. }
  1613. /* If the BIOS described our SDVO device, take advantage of it. */
  1614. if (my_mapping->slave_addr)
  1615. return my_mapping->slave_addr;
  1616. /* If the BIOS only described a different SDVO device, use the
  1617. * address that it isn't using.
  1618. */
  1619. if (other_mapping->slave_addr) {
  1620. if (other_mapping->slave_addr == 0x70)
  1621. return 0x72;
  1622. else
  1623. return 0x70;
  1624. }
  1625. /* No SDVO device info is found for another DVO port,
  1626. * so use mapping assumption we had before BIOS parsing.
  1627. */
  1628. if (output_device == SDVOB)
  1629. return 0x70;
  1630. else
  1631. return 0x72;
  1632. }
  1633. static bool
  1634. intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags)
  1635. {
  1636. struct drm_connector *connector = &intel_output->base;
  1637. struct drm_encoder *encoder = &intel_output->enc;
  1638. struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv;
  1639. bool ret = true, registered = false;
  1640. sdvo_priv->is_tv = false;
  1641. intel_output->needs_tv_clock = false;
  1642. sdvo_priv->is_lvds = false;
  1643. if (device_is_registered(&connector->kdev)) {
  1644. drm_sysfs_connector_remove(connector);
  1645. registered = true;
  1646. }
  1647. if (flags &
  1648. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) {
  1649. if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0)
  1650. sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0;
  1651. else
  1652. sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1;
  1653. encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
  1654. connector->connector_type = DRM_MODE_CONNECTOR_DVID;
  1655. if (intel_sdvo_get_supp_encode(intel_output,
  1656. &sdvo_priv->encode) &&
  1657. intel_sdvo_get_digital_encoding_mode(intel_output) &&
  1658. sdvo_priv->is_hdmi) {
  1659. /* enable hdmi encoding mode if supported */
  1660. intel_sdvo_set_encode(intel_output, SDVO_ENCODE_HDMI);
  1661. intel_sdvo_set_colorimetry(intel_output,
  1662. SDVO_COLORIMETRY_RGB256);
  1663. connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
  1664. intel_output->clone_mask =
  1665. (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
  1666. (1 << INTEL_ANALOG_CLONE_BIT);
  1667. }
  1668. } else if (flags & SDVO_OUTPUT_SVID0) {
  1669. sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0;
  1670. encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
  1671. connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
  1672. sdvo_priv->is_tv = true;
  1673. intel_output->needs_tv_clock = true;
  1674. intel_output->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT;
  1675. } else if (flags & SDVO_OUTPUT_RGB0) {
  1676. sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0;
  1677. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  1678. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  1679. intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
  1680. (1 << INTEL_ANALOG_CLONE_BIT);
  1681. } else if (flags & SDVO_OUTPUT_RGB1) {
  1682. sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1;
  1683. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  1684. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  1685. } else if (flags & SDVO_OUTPUT_LVDS0) {
  1686. sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0;
  1687. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  1688. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  1689. sdvo_priv->is_lvds = true;
  1690. intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
  1691. (1 << INTEL_SDVO_LVDS_CLONE_BIT);
  1692. } else if (flags & SDVO_OUTPUT_LVDS1) {
  1693. sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1;
  1694. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  1695. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  1696. sdvo_priv->is_lvds = true;
  1697. intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) |
  1698. (1 << INTEL_SDVO_LVDS_CLONE_BIT);
  1699. } else {
  1700. unsigned char bytes[2];
  1701. sdvo_priv->controlled_output = 0;
  1702. memcpy(bytes, &sdvo_priv->caps.output_flags, 2);
  1703. DRM_DEBUG_KMS(I915_SDVO,
  1704. "%s: Unknown SDVO output type (0x%02x%02x)\n",
  1705. SDVO_NAME(sdvo_priv),
  1706. bytes[0], bytes[1]);
  1707. ret = false;
  1708. }
  1709. intel_output->crtc_mask = (1 << 0) | (1 << 1);
  1710. if (ret && registered)
  1711. ret = drm_sysfs_connector_add(connector) == 0 ? true : false;
  1712. return ret;
  1713. }
  1714. bool intel_sdvo_init(struct drm_device *dev, int output_device)
  1715. {
  1716. struct drm_connector *connector;
  1717. struct intel_output *intel_output;
  1718. struct intel_sdvo_priv *sdvo_priv;
  1719. u8 ch[0x40];
  1720. int i;
  1721. intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL);
  1722. if (!intel_output) {
  1723. return false;
  1724. }
  1725. sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1);
  1726. sdvo_priv->output_device = output_device;
  1727. intel_output->dev_priv = sdvo_priv;
  1728. intel_output->type = INTEL_OUTPUT_SDVO;
  1729. /* setup the DDC bus. */
  1730. if (output_device == SDVOB)
  1731. intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB");
  1732. else
  1733. intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC");
  1734. if (!intel_output->i2c_bus)
  1735. goto err_inteloutput;
  1736. sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
  1737. /* Save the bit-banging i2c functionality for use by the DDC wrapper */
  1738. intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
  1739. /* Read the regs to test if we can talk to the device */
  1740. for (i = 0; i < 0x40; i++) {
  1741. if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) {
  1742. DRM_DEBUG_KMS(I915_SDVO,
  1743. "No SDVO device found on SDVO%c\n",
  1744. output_device == SDVOB ? 'B' : 'C');
  1745. goto err_i2c;
  1746. }
  1747. }
  1748. /* setup the DDC bus. */
  1749. if (output_device == SDVOB)
  1750. intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS");
  1751. else
  1752. intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS");
  1753. if (intel_output->ddc_bus == NULL)
  1754. goto err_i2c;
  1755. /* Wrap with our custom algo which switches to DDC mode */
  1756. intel_output->ddc_bus->algo = &intel_sdvo_i2c_bit_algo;
  1757. /* In defaut case sdvo lvds is false */
  1758. intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps);
  1759. if (intel_sdvo_output_setup(intel_output,
  1760. sdvo_priv->caps.output_flags) != true) {
  1761. DRM_DEBUG("SDVO output failed to setup on SDVO%c\n",
  1762. output_device == SDVOB ? 'B' : 'C');
  1763. goto err_i2c;
  1764. }
  1765. connector = &intel_output->base;
  1766. drm_connector_init(dev, connector, &intel_sdvo_connector_funcs,
  1767. connector->connector_type);
  1768. drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs);
  1769. connector->interlace_allowed = 0;
  1770. connector->doublescan_allowed = 0;
  1771. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  1772. drm_encoder_init(dev, &intel_output->enc,
  1773. &intel_sdvo_enc_funcs, intel_output->enc.encoder_type);
  1774. drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs);
  1775. drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
  1776. drm_sysfs_connector_add(connector);
  1777. intel_sdvo_select_ddc_bus(sdvo_priv);
  1778. /* Set the input timing to the screen. Assume always input 0. */
  1779. intel_sdvo_set_target_input(intel_output, true, false);
  1780. intel_sdvo_get_input_pixel_clock_range(intel_output,
  1781. &sdvo_priv->pixel_clock_min,
  1782. &sdvo_priv->pixel_clock_max);
  1783. DRM_DEBUG_KMS(I915_SDVO, "%s device VID/DID: %02X:%02X.%02X, "
  1784. "clock range %dMHz - %dMHz, "
  1785. "input 1: %c, input 2: %c, "
  1786. "output 1: %c, output 2: %c\n",
  1787. SDVO_NAME(sdvo_priv),
  1788. sdvo_priv->caps.vendor_id, sdvo_priv->caps.device_id,
  1789. sdvo_priv->caps.device_rev_id,
  1790. sdvo_priv->pixel_clock_min / 1000,
  1791. sdvo_priv->pixel_clock_max / 1000,
  1792. (sdvo_priv->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
  1793. (sdvo_priv->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
  1794. /* check currently supported outputs */
  1795. sdvo_priv->caps.output_flags &
  1796. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
  1797. sdvo_priv->caps.output_flags &
  1798. (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
  1799. return true;
  1800. err_i2c:
  1801. if (intel_output->ddc_bus != NULL)
  1802. intel_i2c_destroy(intel_output->ddc_bus);
  1803. if (intel_output->i2c_bus != NULL)
  1804. intel_i2c_destroy(intel_output->i2c_bus);
  1805. err_inteloutput:
  1806. kfree(intel_output);
  1807. return false;
  1808. }