intel_sdvo.c 86 KB

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