intel_sdvo.c 67 KB

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