intel_sdvo.c 59 KB

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