intel_sdvo.c 53 KB

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