intel_sdvo.c 79 KB

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