intel_sdvo.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983
  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 <linux/export.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm_crtc.h>
  34. #include <drm/drm_edid.h>
  35. #include "intel_drv.h"
  36. #include <drm/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 | SDVO_OUTPUT_YPRPB0)
  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_TMDS(c) (c->output_flag & SDVO_TMDS_MASK)
  47. #define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK)
  48. #define IS_TV_OR_LVDS(c) (c->output_flag & (SDVO_TV_MASK | SDVO_LVDS_MASK))
  49. #define IS_DIGITAL(c) (c->output_flag & (SDVO_TMDS_MASK | SDVO_LVDS_MASK))
  50. static const char *tv_format_names[] = {
  51. "NTSC_M" , "NTSC_J" , "NTSC_443",
  52. "PAL_B" , "PAL_D" , "PAL_G" ,
  53. "PAL_H" , "PAL_I" , "PAL_M" ,
  54. "PAL_N" , "PAL_NC" , "PAL_60" ,
  55. "SECAM_B" , "SECAM_D" , "SECAM_G" ,
  56. "SECAM_K" , "SECAM_K1", "SECAM_L" ,
  57. "SECAM_60"
  58. };
  59. #define TV_FORMAT_NUM (sizeof(tv_format_names) / sizeof(*tv_format_names))
  60. struct intel_sdvo {
  61. struct intel_encoder base;
  62. struct i2c_adapter *i2c;
  63. u8 slave_addr;
  64. struct i2c_adapter ddc;
  65. /* Register for the SDVO device: SDVOB or SDVOC */
  66. uint32_t sdvo_reg;
  67. /* Active outputs controlled by this SDVO output */
  68. uint16_t controlled_output;
  69. /*
  70. * Capabilities of the SDVO device returned by
  71. * intel_sdvo_get_capabilities()
  72. */
  73. struct intel_sdvo_caps caps;
  74. /* Pixel clock limitations reported by the SDVO device, in kHz */
  75. int pixel_clock_min, pixel_clock_max;
  76. /*
  77. * For multiple function SDVO device,
  78. * this is for current attached outputs.
  79. */
  80. uint16_t attached_output;
  81. /*
  82. * Hotplug activation bits for this device
  83. */
  84. uint16_t hotplug_active;
  85. /**
  86. * This is used to select the color range of RBG outputs in HDMI mode.
  87. * It is only valid when using TMDS encoding and 8 bit per color mode.
  88. */
  89. uint32_t color_range;
  90. bool color_range_auto;
  91. /**
  92. * This is set if we're going to treat the device as TV-out.
  93. *
  94. * While we have these nice friendly flags for output types that ought
  95. * to decide this for us, the S-Video output on our HDMI+S-Video card
  96. * shows up as RGB1 (VGA).
  97. */
  98. bool is_tv;
  99. /* On different gens SDVOB is at different places. */
  100. bool is_sdvob;
  101. /* This is for current tv format name */
  102. int tv_format_index;
  103. /**
  104. * This is set if we treat the device as HDMI, instead of DVI.
  105. */
  106. bool is_hdmi;
  107. bool has_hdmi_monitor;
  108. bool has_hdmi_audio;
  109. bool rgb_quant_range_selectable;
  110. /**
  111. * This is set if we detect output of sdvo device as LVDS and
  112. * have a valid fixed mode to use with the panel.
  113. */
  114. bool is_lvds;
  115. /**
  116. * This is sdvo fixed pannel mode pointer
  117. */
  118. struct drm_display_mode *sdvo_lvds_fixed_mode;
  119. /* DDC bus used by this SDVO encoder */
  120. uint8_t ddc_bus;
  121. /*
  122. * the sdvo flag gets lost in round trip: dtd->adjusted_mode->dtd
  123. */
  124. uint8_t dtd_sdvo_flags;
  125. };
  126. struct intel_sdvo_connector {
  127. struct intel_connector base;
  128. /* Mark the type of connector */
  129. uint16_t output_flag;
  130. enum hdmi_force_audio force_audio;
  131. /* This contains all current supported TV format */
  132. u8 tv_format_supported[TV_FORMAT_NUM];
  133. int format_supported_num;
  134. struct drm_property *tv_format;
  135. /* add the property for the SDVO-TV */
  136. struct drm_property *left;
  137. struct drm_property *right;
  138. struct drm_property *top;
  139. struct drm_property *bottom;
  140. struct drm_property *hpos;
  141. struct drm_property *vpos;
  142. struct drm_property *contrast;
  143. struct drm_property *saturation;
  144. struct drm_property *hue;
  145. struct drm_property *sharpness;
  146. struct drm_property *flicker_filter;
  147. struct drm_property *flicker_filter_adaptive;
  148. struct drm_property *flicker_filter_2d;
  149. struct drm_property *tv_chroma_filter;
  150. struct drm_property *tv_luma_filter;
  151. struct drm_property *dot_crawl;
  152. /* add the property for the SDVO-TV/LVDS */
  153. struct drm_property *brightness;
  154. /* Add variable to record current setting for the above property */
  155. u32 left_margin, right_margin, top_margin, bottom_margin;
  156. /* this is to get the range of margin.*/
  157. u32 max_hscan, max_vscan;
  158. u32 max_hpos, cur_hpos;
  159. u32 max_vpos, cur_vpos;
  160. u32 cur_brightness, max_brightness;
  161. u32 cur_contrast, max_contrast;
  162. u32 cur_saturation, max_saturation;
  163. u32 cur_hue, max_hue;
  164. u32 cur_sharpness, max_sharpness;
  165. u32 cur_flicker_filter, max_flicker_filter;
  166. u32 cur_flicker_filter_adaptive, max_flicker_filter_adaptive;
  167. u32 cur_flicker_filter_2d, max_flicker_filter_2d;
  168. u32 cur_tv_chroma_filter, max_tv_chroma_filter;
  169. u32 cur_tv_luma_filter, max_tv_luma_filter;
  170. u32 cur_dot_crawl, max_dot_crawl;
  171. };
  172. static struct intel_sdvo *to_sdvo(struct intel_encoder *encoder)
  173. {
  174. return container_of(encoder, struct intel_sdvo, base);
  175. }
  176. static struct intel_sdvo *intel_attached_sdvo(struct drm_connector *connector)
  177. {
  178. return to_sdvo(intel_attached_encoder(connector));
  179. }
  180. static struct intel_sdvo_connector *to_intel_sdvo_connector(struct drm_connector *connector)
  181. {
  182. return container_of(to_intel_connector(connector), struct intel_sdvo_connector, base);
  183. }
  184. static bool
  185. intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags);
  186. static bool
  187. intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
  188. struct intel_sdvo_connector *intel_sdvo_connector,
  189. int type);
  190. static bool
  191. intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
  192. struct intel_sdvo_connector *intel_sdvo_connector);
  193. /**
  194. * Writes the SDVOB or SDVOC with the given value, but always writes both
  195. * SDVOB and SDVOC to work around apparent hardware issues (according to
  196. * comments in the BIOS).
  197. */
  198. static void intel_sdvo_write_sdvox(struct intel_sdvo *intel_sdvo, u32 val)
  199. {
  200. struct drm_device *dev = intel_sdvo->base.base.dev;
  201. struct drm_i915_private *dev_priv = dev->dev_private;
  202. u32 bval = val, cval = val;
  203. int i;
  204. if (intel_sdvo->sdvo_reg == PCH_SDVOB) {
  205. I915_WRITE(intel_sdvo->sdvo_reg, val);
  206. I915_READ(intel_sdvo->sdvo_reg);
  207. return;
  208. }
  209. if (intel_sdvo->sdvo_reg == GEN3_SDVOB)
  210. cval = I915_READ(GEN3_SDVOC);
  211. else
  212. bval = I915_READ(GEN3_SDVOB);
  213. /*
  214. * Write the registers twice for luck. Sometimes,
  215. * writing them only once doesn't appear to 'stick'.
  216. * The BIOS does this too. Yay, magic
  217. */
  218. for (i = 0; i < 2; i++)
  219. {
  220. I915_WRITE(GEN3_SDVOB, bval);
  221. I915_READ(GEN3_SDVOB);
  222. I915_WRITE(GEN3_SDVOC, cval);
  223. I915_READ(GEN3_SDVOC);
  224. }
  225. }
  226. static bool intel_sdvo_read_byte(struct intel_sdvo *intel_sdvo, u8 addr, u8 *ch)
  227. {
  228. struct i2c_msg msgs[] = {
  229. {
  230. .addr = intel_sdvo->slave_addr,
  231. .flags = 0,
  232. .len = 1,
  233. .buf = &addr,
  234. },
  235. {
  236. .addr = intel_sdvo->slave_addr,
  237. .flags = I2C_M_RD,
  238. .len = 1,
  239. .buf = ch,
  240. }
  241. };
  242. int ret;
  243. if ((ret = i2c_transfer(intel_sdvo->i2c, msgs, 2)) == 2)
  244. return true;
  245. DRM_DEBUG_KMS("i2c transfer returned %d\n", ret);
  246. return false;
  247. }
  248. #define SDVO_CMD_NAME_ENTRY(cmd) {cmd, #cmd}
  249. /** Mapping of command numbers to names, for debug output */
  250. static const struct _sdvo_cmd_name {
  251. u8 cmd;
  252. const char *name;
  253. } sdvo_cmd_names[] = {
  254. SDVO_CMD_NAME_ENTRY(SDVO_CMD_RESET),
  255. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DEVICE_CAPS),
  256. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FIRMWARE_REV),
  257. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TRAINED_INPUTS),
  258. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_OUTPUTS),
  259. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_OUTPUTS),
  260. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_IN_OUT_MAP),
  261. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_IN_OUT_MAP),
  262. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ATTACHED_DISPLAYS),
  263. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HOT_PLUG_SUPPORT),
  264. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ACTIVE_HOT_PLUG),
  265. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ACTIVE_HOT_PLUG),
  266. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INTERRUPT_EVENT_SOURCE),
  267. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_INPUT),
  268. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TARGET_OUTPUT),
  269. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART1),
  270. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_TIMINGS_PART2),
  271. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  272. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART2),
  273. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_INPUT_TIMINGS_PART1),
  274. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART1),
  275. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OUTPUT_TIMINGS_PART2),
  276. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART1),
  277. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_TIMINGS_PART2),
  278. SDVO_CMD_NAME_ENTRY(SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING),
  279. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1),
  280. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2),
  281. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE),
  282. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OUTPUT_PIXEL_CLOCK_RANGE),
  283. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_CLOCK_RATE_MULTS),
  284. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CLOCK_RATE_MULT),
  285. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CLOCK_RATE_MULT),
  286. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_TV_FORMATS),
  287. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_FORMAT),
  288. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_FORMAT),
  289. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_POWER_STATES),
  290. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_POWER_STATE),
  291. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODER_POWER_STATE),
  292. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DISPLAY_POWER_STATE),
  293. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTROL_BUS_SWITCH),
  294. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT),
  295. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SCALED_HDTV_RESOLUTION_SUPPORT),
  296. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS),
  297. /* Add the op code for SDVO enhancements */
  298. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HPOS),
  299. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HPOS),
  300. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HPOS),
  301. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_VPOS),
  302. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_VPOS),
  303. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_VPOS),
  304. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SATURATION),
  305. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SATURATION),
  306. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SATURATION),
  307. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_HUE),
  308. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HUE),
  309. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HUE),
  310. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_CONTRAST),
  311. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_CONTRAST),
  312. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_CONTRAST),
  313. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_BRIGHTNESS),
  314. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_BRIGHTNESS),
  315. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_BRIGHTNESS),
  316. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_H),
  317. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_H),
  318. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_H),
  319. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_OVERSCAN_V),
  320. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_OVERSCAN_V),
  321. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_OVERSCAN_V),
  322. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER),
  323. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER),
  324. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER),
  325. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_ADAPTIVE),
  326. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_ADAPTIVE),
  327. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_ADAPTIVE),
  328. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_FLICKER_FILTER_2D),
  329. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_FLICKER_FILTER_2D),
  330. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_FLICKER_FILTER_2D),
  331. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_SHARPNESS),
  332. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SHARPNESS),
  333. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_SHARPNESS),
  334. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_DOT_CRAWL),
  335. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_DOT_CRAWL),
  336. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_CHROMA_FILTER),
  337. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_CHROMA_FILTER),
  338. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_CHROMA_FILTER),
  339. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_MAX_TV_LUMA_FILTER),
  340. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_TV_LUMA_FILTER),
  341. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_TV_LUMA_FILTER),
  342. /* HDMI op code */
  343. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_SUPP_ENCODE),
  344. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_ENCODE),
  345. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_ENCODE),
  346. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_PIXEL_REPLI),
  347. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_PIXEL_REPLI),
  348. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY_CAP),
  349. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_COLORIMETRY),
  350. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_COLORIMETRY),
  351. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_ENCRYPT_PREFER),
  352. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_AUDIO_STAT),
  353. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_AUDIO_STAT),
  354. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INDEX),
  355. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_INDEX),
  356. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_INFO),
  357. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_AV_SPLIT),
  358. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_AV_SPLIT),
  359. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_TXRATE),
  360. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_TXRATE),
  361. SDVO_CMD_NAME_ENTRY(SDVO_CMD_SET_HBUF_DATA),
  362. SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA),
  363. };
  364. #define SDVO_NAME(svdo) ((svdo)->is_sdvob ? "SDVOB" : "SDVOC")
  365. static void intel_sdvo_debug_write(struct intel_sdvo *intel_sdvo, u8 cmd,
  366. const void *args, int args_len)
  367. {
  368. int i;
  369. DRM_DEBUG_KMS("%s: W: %02X ",
  370. SDVO_NAME(intel_sdvo), cmd);
  371. for (i = 0; i < args_len; i++)
  372. DRM_LOG_KMS("%02X ", ((u8 *)args)[i]);
  373. for (; i < 8; i++)
  374. DRM_LOG_KMS(" ");
  375. for (i = 0; i < ARRAY_SIZE(sdvo_cmd_names); i++) {
  376. if (cmd == sdvo_cmd_names[i].cmd) {
  377. DRM_LOG_KMS("(%s)", sdvo_cmd_names[i].name);
  378. break;
  379. }
  380. }
  381. if (i == ARRAY_SIZE(sdvo_cmd_names))
  382. DRM_LOG_KMS("(%02X)", cmd);
  383. DRM_LOG_KMS("\n");
  384. }
  385. static const char *cmd_status_names[] = {
  386. "Power on",
  387. "Success",
  388. "Not supported",
  389. "Invalid arg",
  390. "Pending",
  391. "Target not specified",
  392. "Scaling not supported"
  393. };
  394. static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd,
  395. const void *args, int args_len)
  396. {
  397. u8 *buf, status;
  398. struct i2c_msg *msgs;
  399. int i, ret = true;
  400. /* Would be simpler to allocate both in one go ? */
  401. buf = kzalloc(args_len * 2 + 2, GFP_KERNEL);
  402. if (!buf)
  403. return false;
  404. msgs = kcalloc(args_len + 3, sizeof(*msgs), GFP_KERNEL);
  405. if (!msgs) {
  406. kfree(buf);
  407. return false;
  408. }
  409. intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len);
  410. for (i = 0; i < args_len; i++) {
  411. msgs[i].addr = intel_sdvo->slave_addr;
  412. msgs[i].flags = 0;
  413. msgs[i].len = 2;
  414. msgs[i].buf = buf + 2 *i;
  415. buf[2*i + 0] = SDVO_I2C_ARG_0 - i;
  416. buf[2*i + 1] = ((u8*)args)[i];
  417. }
  418. msgs[i].addr = intel_sdvo->slave_addr;
  419. msgs[i].flags = 0;
  420. msgs[i].len = 2;
  421. msgs[i].buf = buf + 2*i;
  422. buf[2*i + 0] = SDVO_I2C_OPCODE;
  423. buf[2*i + 1] = cmd;
  424. /* the following two are to read the response */
  425. status = SDVO_I2C_CMD_STATUS;
  426. msgs[i+1].addr = intel_sdvo->slave_addr;
  427. msgs[i+1].flags = 0;
  428. msgs[i+1].len = 1;
  429. msgs[i+1].buf = &status;
  430. msgs[i+2].addr = intel_sdvo->slave_addr;
  431. msgs[i+2].flags = I2C_M_RD;
  432. msgs[i+2].len = 1;
  433. msgs[i+2].buf = &status;
  434. ret = i2c_transfer(intel_sdvo->i2c, msgs, i+3);
  435. if (ret < 0) {
  436. DRM_DEBUG_KMS("I2c transfer returned %d\n", ret);
  437. ret = false;
  438. goto out;
  439. }
  440. if (ret != i+3) {
  441. /* failure in I2C transfer */
  442. DRM_DEBUG_KMS("I2c transfer returned %d/%d\n", ret, i+3);
  443. ret = false;
  444. }
  445. out:
  446. kfree(msgs);
  447. kfree(buf);
  448. return ret;
  449. }
  450. static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo,
  451. void *response, int response_len)
  452. {
  453. u8 retry = 15; /* 5 quick checks, followed by 10 long checks */
  454. u8 status;
  455. int i;
  456. DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(intel_sdvo));
  457. /*
  458. * The documentation states that all commands will be
  459. * processed within 15µs, and that we need only poll
  460. * the status byte a maximum of 3 times in order for the
  461. * command to be complete.
  462. *
  463. * Check 5 times in case the hardware failed to read the docs.
  464. *
  465. * Also beware that the first response by many devices is to
  466. * reply PENDING and stall for time. TVs are notorious for
  467. * requiring longer than specified to complete their replies.
  468. * Originally (in the DDX long ago), the delay was only ever 15ms
  469. * with an additional delay of 30ms applied for TVs added later after
  470. * many experiments. To accommodate both sets of delays, we do a
  471. * sequence of slow checks if the device is falling behind and fails
  472. * to reply within 5*15µs.
  473. */
  474. if (!intel_sdvo_read_byte(intel_sdvo,
  475. SDVO_I2C_CMD_STATUS,
  476. &status))
  477. goto log_fail;
  478. while ((status == SDVO_CMD_STATUS_PENDING ||
  479. status == SDVO_CMD_STATUS_TARGET_NOT_SPECIFIED) && --retry) {
  480. if (retry < 10)
  481. msleep(15);
  482. else
  483. udelay(15);
  484. if (!intel_sdvo_read_byte(intel_sdvo,
  485. SDVO_I2C_CMD_STATUS,
  486. &status))
  487. goto log_fail;
  488. }
  489. if (status <= SDVO_CMD_STATUS_SCALING_NOT_SUPP)
  490. DRM_LOG_KMS("(%s)", cmd_status_names[status]);
  491. else
  492. DRM_LOG_KMS("(??? %d)", status);
  493. if (status != SDVO_CMD_STATUS_SUCCESS)
  494. goto log_fail;
  495. /* Read the command response */
  496. for (i = 0; i < response_len; i++) {
  497. if (!intel_sdvo_read_byte(intel_sdvo,
  498. SDVO_I2C_RETURN_0 + i,
  499. &((u8 *)response)[i]))
  500. goto log_fail;
  501. DRM_LOG_KMS(" %02X", ((u8 *)response)[i]);
  502. }
  503. DRM_LOG_KMS("\n");
  504. return true;
  505. log_fail:
  506. DRM_LOG_KMS("... failed\n");
  507. return false;
  508. }
  509. static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode)
  510. {
  511. if (mode->clock >= 100000)
  512. return 1;
  513. else if (mode->clock >= 50000)
  514. return 2;
  515. else
  516. return 4;
  517. }
  518. static bool intel_sdvo_set_control_bus_switch(struct intel_sdvo *intel_sdvo,
  519. u8 ddc_bus)
  520. {
  521. /* This must be the immediately preceding write before the i2c xfer */
  522. return intel_sdvo_write_cmd(intel_sdvo,
  523. SDVO_CMD_SET_CONTROL_BUS_SWITCH,
  524. &ddc_bus, 1);
  525. }
  526. static bool intel_sdvo_set_value(struct intel_sdvo *intel_sdvo, u8 cmd, const void *data, int len)
  527. {
  528. if (!intel_sdvo_write_cmd(intel_sdvo, cmd, data, len))
  529. return false;
  530. return intel_sdvo_read_response(intel_sdvo, NULL, 0);
  531. }
  532. static bool
  533. intel_sdvo_get_value(struct intel_sdvo *intel_sdvo, u8 cmd, void *value, int len)
  534. {
  535. if (!intel_sdvo_write_cmd(intel_sdvo, cmd, NULL, 0))
  536. return false;
  537. return intel_sdvo_read_response(intel_sdvo, value, len);
  538. }
  539. static bool intel_sdvo_set_target_input(struct intel_sdvo *intel_sdvo)
  540. {
  541. struct intel_sdvo_set_target_input_args targets = {0};
  542. return intel_sdvo_set_value(intel_sdvo,
  543. SDVO_CMD_SET_TARGET_INPUT,
  544. &targets, sizeof(targets));
  545. }
  546. /**
  547. * Return whether each input is trained.
  548. *
  549. * This function is making an assumption about the layout of the response,
  550. * which should be checked against the docs.
  551. */
  552. static bool intel_sdvo_get_trained_inputs(struct intel_sdvo *intel_sdvo, bool *input_1, bool *input_2)
  553. {
  554. struct intel_sdvo_get_trained_inputs_response response;
  555. BUILD_BUG_ON(sizeof(response) != 1);
  556. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_TRAINED_INPUTS,
  557. &response, sizeof(response)))
  558. return false;
  559. *input_1 = response.input0_trained;
  560. *input_2 = response.input1_trained;
  561. return true;
  562. }
  563. static bool intel_sdvo_set_active_outputs(struct intel_sdvo *intel_sdvo,
  564. u16 outputs)
  565. {
  566. return intel_sdvo_set_value(intel_sdvo,
  567. SDVO_CMD_SET_ACTIVE_OUTPUTS,
  568. &outputs, sizeof(outputs));
  569. }
  570. static bool intel_sdvo_get_active_outputs(struct intel_sdvo *intel_sdvo,
  571. u16 *outputs)
  572. {
  573. return intel_sdvo_get_value(intel_sdvo,
  574. SDVO_CMD_GET_ACTIVE_OUTPUTS,
  575. outputs, sizeof(*outputs));
  576. }
  577. static bool intel_sdvo_set_encoder_power_state(struct intel_sdvo *intel_sdvo,
  578. int mode)
  579. {
  580. u8 state = SDVO_ENCODER_STATE_ON;
  581. switch (mode) {
  582. case DRM_MODE_DPMS_ON:
  583. state = SDVO_ENCODER_STATE_ON;
  584. break;
  585. case DRM_MODE_DPMS_STANDBY:
  586. state = SDVO_ENCODER_STATE_STANDBY;
  587. break;
  588. case DRM_MODE_DPMS_SUSPEND:
  589. state = SDVO_ENCODER_STATE_SUSPEND;
  590. break;
  591. case DRM_MODE_DPMS_OFF:
  592. state = SDVO_ENCODER_STATE_OFF;
  593. break;
  594. }
  595. return intel_sdvo_set_value(intel_sdvo,
  596. SDVO_CMD_SET_ENCODER_POWER_STATE, &state, sizeof(state));
  597. }
  598. static bool intel_sdvo_get_input_pixel_clock_range(struct intel_sdvo *intel_sdvo,
  599. int *clock_min,
  600. int *clock_max)
  601. {
  602. struct intel_sdvo_pixel_clock_range clocks;
  603. BUILD_BUG_ON(sizeof(clocks) != 4);
  604. if (!intel_sdvo_get_value(intel_sdvo,
  605. SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE,
  606. &clocks, sizeof(clocks)))
  607. return false;
  608. /* Convert the values from units of 10 kHz to kHz. */
  609. *clock_min = clocks.min * 10;
  610. *clock_max = clocks.max * 10;
  611. return true;
  612. }
  613. static bool intel_sdvo_set_target_output(struct intel_sdvo *intel_sdvo,
  614. u16 outputs)
  615. {
  616. return intel_sdvo_set_value(intel_sdvo,
  617. SDVO_CMD_SET_TARGET_OUTPUT,
  618. &outputs, sizeof(outputs));
  619. }
  620. static bool intel_sdvo_set_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
  621. struct intel_sdvo_dtd *dtd)
  622. {
  623. return intel_sdvo_set_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
  624. intel_sdvo_set_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  625. }
  626. static bool intel_sdvo_get_timing(struct intel_sdvo *intel_sdvo, u8 cmd,
  627. struct intel_sdvo_dtd *dtd)
  628. {
  629. return intel_sdvo_get_value(intel_sdvo, cmd, &dtd->part1, sizeof(dtd->part1)) &&
  630. intel_sdvo_get_value(intel_sdvo, cmd + 1, &dtd->part2, sizeof(dtd->part2));
  631. }
  632. static bool intel_sdvo_set_input_timing(struct intel_sdvo *intel_sdvo,
  633. struct intel_sdvo_dtd *dtd)
  634. {
  635. return intel_sdvo_set_timing(intel_sdvo,
  636. SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd);
  637. }
  638. static bool intel_sdvo_set_output_timing(struct intel_sdvo *intel_sdvo,
  639. struct intel_sdvo_dtd *dtd)
  640. {
  641. return intel_sdvo_set_timing(intel_sdvo,
  642. SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd);
  643. }
  644. static bool intel_sdvo_get_input_timing(struct intel_sdvo *intel_sdvo,
  645. struct intel_sdvo_dtd *dtd)
  646. {
  647. return intel_sdvo_get_timing(intel_sdvo,
  648. SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd);
  649. }
  650. static bool
  651. intel_sdvo_create_preferred_input_timing(struct intel_sdvo *intel_sdvo,
  652. uint16_t clock,
  653. uint16_t width,
  654. uint16_t height)
  655. {
  656. struct intel_sdvo_preferred_input_timing_args args;
  657. memset(&args, 0, sizeof(args));
  658. args.clock = clock;
  659. args.width = width;
  660. args.height = height;
  661. args.interlace = 0;
  662. if (intel_sdvo->is_lvds &&
  663. (intel_sdvo->sdvo_lvds_fixed_mode->hdisplay != width ||
  664. intel_sdvo->sdvo_lvds_fixed_mode->vdisplay != height))
  665. args.scaled = 1;
  666. return intel_sdvo_set_value(intel_sdvo,
  667. SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING,
  668. &args, sizeof(args));
  669. }
  670. static bool intel_sdvo_get_preferred_input_timing(struct intel_sdvo *intel_sdvo,
  671. struct intel_sdvo_dtd *dtd)
  672. {
  673. BUILD_BUG_ON(sizeof(dtd->part1) != 8);
  674. BUILD_BUG_ON(sizeof(dtd->part2) != 8);
  675. return intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1,
  676. &dtd->part1, sizeof(dtd->part1)) &&
  677. intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2,
  678. &dtd->part2, sizeof(dtd->part2));
  679. }
  680. static bool intel_sdvo_set_clock_rate_mult(struct intel_sdvo *intel_sdvo, u8 val)
  681. {
  682. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1);
  683. }
  684. static void intel_sdvo_get_dtd_from_mode(struct intel_sdvo_dtd *dtd,
  685. const struct drm_display_mode *mode)
  686. {
  687. uint16_t width, height;
  688. uint16_t h_blank_len, h_sync_len, v_blank_len, v_sync_len;
  689. uint16_t h_sync_offset, v_sync_offset;
  690. int mode_clock;
  691. memset(dtd, 0, sizeof(*dtd));
  692. width = mode->hdisplay;
  693. height = mode->vdisplay;
  694. /* do some mode translations */
  695. h_blank_len = mode->htotal - mode->hdisplay;
  696. h_sync_len = mode->hsync_end - mode->hsync_start;
  697. v_blank_len = mode->vtotal - mode->vdisplay;
  698. v_sync_len = mode->vsync_end - mode->vsync_start;
  699. h_sync_offset = mode->hsync_start - mode->hdisplay;
  700. v_sync_offset = mode->vsync_start - mode->vdisplay;
  701. mode_clock = mode->clock;
  702. mode_clock /= 10;
  703. dtd->part1.clock = mode_clock;
  704. dtd->part1.h_active = width & 0xff;
  705. dtd->part1.h_blank = h_blank_len & 0xff;
  706. dtd->part1.h_high = (((width >> 8) & 0xf) << 4) |
  707. ((h_blank_len >> 8) & 0xf);
  708. dtd->part1.v_active = height & 0xff;
  709. dtd->part1.v_blank = v_blank_len & 0xff;
  710. dtd->part1.v_high = (((height >> 8) & 0xf) << 4) |
  711. ((v_blank_len >> 8) & 0xf);
  712. dtd->part2.h_sync_off = h_sync_offset & 0xff;
  713. dtd->part2.h_sync_width = h_sync_len & 0xff;
  714. dtd->part2.v_sync_off_width = (v_sync_offset & 0xf) << 4 |
  715. (v_sync_len & 0xf);
  716. dtd->part2.sync_off_width_high = ((h_sync_offset & 0x300) >> 2) |
  717. ((h_sync_len & 0x300) >> 4) | ((v_sync_offset & 0x30) >> 2) |
  718. ((v_sync_len & 0x30) >> 4);
  719. dtd->part2.dtd_flags = 0x18;
  720. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  721. dtd->part2.dtd_flags |= DTD_FLAG_INTERLACE;
  722. if (mode->flags & DRM_MODE_FLAG_PHSYNC)
  723. dtd->part2.dtd_flags |= DTD_FLAG_HSYNC_POSITIVE;
  724. if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  725. dtd->part2.dtd_flags |= DTD_FLAG_VSYNC_POSITIVE;
  726. dtd->part2.v_sync_off_high = v_sync_offset & 0xc0;
  727. }
  728. static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode *pmode,
  729. const struct intel_sdvo_dtd *dtd)
  730. {
  731. struct drm_display_mode mode = {};
  732. mode.hdisplay = dtd->part1.h_active;
  733. mode.hdisplay += ((dtd->part1.h_high >> 4) & 0x0f) << 8;
  734. mode.hsync_start = mode.hdisplay + dtd->part2.h_sync_off;
  735. mode.hsync_start += (dtd->part2.sync_off_width_high & 0xc0) << 2;
  736. mode.hsync_end = mode.hsync_start + dtd->part2.h_sync_width;
  737. mode.hsync_end += (dtd->part2.sync_off_width_high & 0x30) << 4;
  738. mode.htotal = mode.hdisplay + dtd->part1.h_blank;
  739. mode.htotal += (dtd->part1.h_high & 0xf) << 8;
  740. mode.vdisplay = dtd->part1.v_active;
  741. mode.vdisplay += ((dtd->part1.v_high >> 4) & 0x0f) << 8;
  742. mode.vsync_start = mode.vdisplay;
  743. mode.vsync_start += (dtd->part2.v_sync_off_width >> 4) & 0xf;
  744. mode.vsync_start += (dtd->part2.sync_off_width_high & 0x0c) << 2;
  745. mode.vsync_start += dtd->part2.v_sync_off_high & 0xc0;
  746. mode.vsync_end = mode.vsync_start +
  747. (dtd->part2.v_sync_off_width & 0xf);
  748. mode.vsync_end += (dtd->part2.sync_off_width_high & 0x3) << 4;
  749. mode.vtotal = mode.vdisplay + dtd->part1.v_blank;
  750. mode.vtotal += (dtd->part1.v_high & 0xf) << 8;
  751. mode.clock = dtd->part1.clock * 10;
  752. if (dtd->part2.dtd_flags & DTD_FLAG_INTERLACE)
  753. mode.flags |= DRM_MODE_FLAG_INTERLACE;
  754. if (dtd->part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
  755. mode.flags |= DRM_MODE_FLAG_PHSYNC;
  756. else
  757. mode.flags |= DRM_MODE_FLAG_NHSYNC;
  758. if (dtd->part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
  759. mode.flags |= DRM_MODE_FLAG_PVSYNC;
  760. else
  761. mode.flags |= DRM_MODE_FLAG_NVSYNC;
  762. drm_mode_set_crtcinfo(&mode, 0);
  763. drm_mode_copy(pmode, &mode);
  764. }
  765. static bool intel_sdvo_check_supp_encode(struct intel_sdvo *intel_sdvo)
  766. {
  767. struct intel_sdvo_encode encode;
  768. BUILD_BUG_ON(sizeof(encode) != 2);
  769. return intel_sdvo_get_value(intel_sdvo,
  770. SDVO_CMD_GET_SUPP_ENCODE,
  771. &encode, sizeof(encode));
  772. }
  773. static bool intel_sdvo_set_encode(struct intel_sdvo *intel_sdvo,
  774. uint8_t mode)
  775. {
  776. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_ENCODE, &mode, 1);
  777. }
  778. static bool intel_sdvo_set_colorimetry(struct intel_sdvo *intel_sdvo,
  779. uint8_t mode)
  780. {
  781. return intel_sdvo_set_value(intel_sdvo, SDVO_CMD_SET_COLORIMETRY, &mode, 1);
  782. }
  783. #if 0
  784. static void intel_sdvo_dump_hdmi_buf(struct intel_sdvo *intel_sdvo)
  785. {
  786. int i, j;
  787. uint8_t set_buf_index[2];
  788. uint8_t av_split;
  789. uint8_t buf_size;
  790. uint8_t buf[48];
  791. uint8_t *pos;
  792. intel_sdvo_get_value(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, &av_split, 1);
  793. for (i = 0; i <= av_split; i++) {
  794. set_buf_index[0] = i; set_buf_index[1] = 0;
  795. intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX,
  796. set_buf_index, 2);
  797. intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0);
  798. intel_sdvo_read_response(encoder, &buf_size, 1);
  799. pos = buf;
  800. for (j = 0; j <= buf_size; j += 8) {
  801. intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA,
  802. NULL, 0);
  803. intel_sdvo_read_response(encoder, pos, 8);
  804. pos += 8;
  805. }
  806. }
  807. }
  808. #endif
  809. static bool intel_sdvo_write_infoframe(struct intel_sdvo *intel_sdvo,
  810. unsigned if_index, uint8_t tx_rate,
  811. uint8_t *data, unsigned length)
  812. {
  813. uint8_t set_buf_index[2] = { if_index, 0 };
  814. uint8_t hbuf_size, tmp[8];
  815. int i;
  816. if (!intel_sdvo_set_value(intel_sdvo,
  817. SDVO_CMD_SET_HBUF_INDEX,
  818. set_buf_index, 2))
  819. return false;
  820. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HBUF_INFO,
  821. &hbuf_size, 1))
  822. return false;
  823. /* Buffer size is 0 based, hooray! */
  824. hbuf_size++;
  825. DRM_DEBUG_KMS("writing sdvo hbuf: %i, hbuf_size %i, hbuf_size: %i\n",
  826. if_index, length, hbuf_size);
  827. for (i = 0; i < hbuf_size; i += 8) {
  828. memset(tmp, 0, 8);
  829. if (i < length)
  830. memcpy(tmp, data + i, min_t(unsigned, 8, length - i));
  831. if (!intel_sdvo_set_value(intel_sdvo,
  832. SDVO_CMD_SET_HBUF_DATA,
  833. tmp, 8))
  834. return false;
  835. }
  836. return intel_sdvo_set_value(intel_sdvo,
  837. SDVO_CMD_SET_HBUF_TXRATE,
  838. &tx_rate, 1);
  839. }
  840. static bool intel_sdvo_set_avi_infoframe(struct intel_sdvo *intel_sdvo,
  841. const struct drm_display_mode *adjusted_mode)
  842. {
  843. uint8_t sdvo_data[HDMI_INFOFRAME_SIZE(AVI)];
  844. struct drm_crtc *crtc = intel_sdvo->base.base.crtc;
  845. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  846. union hdmi_infoframe frame;
  847. int ret;
  848. ssize_t len;
  849. ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
  850. adjusted_mode);
  851. if (ret < 0) {
  852. DRM_ERROR("couldn't fill AVI infoframe\n");
  853. return false;
  854. }
  855. if (intel_sdvo->rgb_quant_range_selectable) {
  856. if (intel_crtc->config.limited_color_range)
  857. frame.avi.quantization_range =
  858. HDMI_QUANTIZATION_RANGE_LIMITED;
  859. else
  860. frame.avi.quantization_range =
  861. HDMI_QUANTIZATION_RANGE_FULL;
  862. }
  863. len = hdmi_infoframe_pack(&frame, sdvo_data, sizeof(sdvo_data));
  864. if (len < 0)
  865. return false;
  866. return intel_sdvo_write_infoframe(intel_sdvo, SDVO_HBUF_INDEX_AVI_IF,
  867. SDVO_HBUF_TX_VSYNC,
  868. sdvo_data, sizeof(sdvo_data));
  869. }
  870. static bool intel_sdvo_set_tv_format(struct intel_sdvo *intel_sdvo)
  871. {
  872. struct intel_sdvo_tv_format format;
  873. uint32_t format_map;
  874. format_map = 1 << intel_sdvo->tv_format_index;
  875. memset(&format, 0, sizeof(format));
  876. memcpy(&format, &format_map, min(sizeof(format), sizeof(format_map)));
  877. BUILD_BUG_ON(sizeof(format) != 6);
  878. return intel_sdvo_set_value(intel_sdvo,
  879. SDVO_CMD_SET_TV_FORMAT,
  880. &format, sizeof(format));
  881. }
  882. static bool
  883. intel_sdvo_set_output_timings_from_mode(struct intel_sdvo *intel_sdvo,
  884. const struct drm_display_mode *mode)
  885. {
  886. struct intel_sdvo_dtd output_dtd;
  887. if (!intel_sdvo_set_target_output(intel_sdvo,
  888. intel_sdvo->attached_output))
  889. return false;
  890. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  891. if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
  892. return false;
  893. return true;
  894. }
  895. /* Asks the sdvo controller for the preferred input mode given the output mode.
  896. * Unfortunately we have to set up the full output mode to do that. */
  897. static bool
  898. intel_sdvo_get_preferred_input_mode(struct intel_sdvo *intel_sdvo,
  899. const struct drm_display_mode *mode,
  900. struct drm_display_mode *adjusted_mode)
  901. {
  902. struct intel_sdvo_dtd input_dtd;
  903. /* Reset the input timing to the screen. Assume always input 0. */
  904. if (!intel_sdvo_set_target_input(intel_sdvo))
  905. return false;
  906. if (!intel_sdvo_create_preferred_input_timing(intel_sdvo,
  907. mode->clock / 10,
  908. mode->hdisplay,
  909. mode->vdisplay))
  910. return false;
  911. if (!intel_sdvo_get_preferred_input_timing(intel_sdvo,
  912. &input_dtd))
  913. return false;
  914. intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd);
  915. intel_sdvo->dtd_sdvo_flags = input_dtd.part2.sdvo_flags;
  916. return true;
  917. }
  918. static void i9xx_adjust_sdvo_tv_clock(struct intel_crtc_config *pipe_config)
  919. {
  920. unsigned dotclock = pipe_config->adjusted_mode.clock;
  921. struct dpll *clock = &pipe_config->dpll;
  922. /* SDVO TV has fixed PLL values depend on its clock range,
  923. this mirrors vbios setting. */
  924. if (dotclock >= 100000 && dotclock < 140500) {
  925. clock->p1 = 2;
  926. clock->p2 = 10;
  927. clock->n = 3;
  928. clock->m1 = 16;
  929. clock->m2 = 8;
  930. } else if (dotclock >= 140500 && dotclock <= 200000) {
  931. clock->p1 = 1;
  932. clock->p2 = 10;
  933. clock->n = 6;
  934. clock->m1 = 12;
  935. clock->m2 = 8;
  936. } else {
  937. WARN(1, "SDVO TV clock out of range: %i\n", dotclock);
  938. }
  939. pipe_config->clock_set = true;
  940. }
  941. static bool intel_sdvo_compute_config(struct intel_encoder *encoder,
  942. struct intel_crtc_config *pipe_config)
  943. {
  944. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  945. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  946. struct drm_display_mode *mode = &pipe_config->requested_mode;
  947. DRM_DEBUG_KMS("forcing bpc to 8 for SDVO\n");
  948. pipe_config->pipe_bpp = 8*3;
  949. if (HAS_PCH_SPLIT(encoder->base.dev))
  950. pipe_config->has_pch_encoder = true;
  951. /* We need to construct preferred input timings based on our
  952. * output timings. To do that, we have to set the output
  953. * timings, even though this isn't really the right place in
  954. * the sequence to do it. Oh well.
  955. */
  956. if (intel_sdvo->is_tv) {
  957. if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo, mode))
  958. return false;
  959. (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
  960. mode,
  961. adjusted_mode);
  962. pipe_config->sdvo_tv_clock = true;
  963. } else if (intel_sdvo->is_lvds) {
  964. if (!intel_sdvo_set_output_timings_from_mode(intel_sdvo,
  965. intel_sdvo->sdvo_lvds_fixed_mode))
  966. return false;
  967. (void) intel_sdvo_get_preferred_input_mode(intel_sdvo,
  968. mode,
  969. adjusted_mode);
  970. }
  971. /* Make the CRTC code factor in the SDVO pixel multiplier. The
  972. * SDVO device will factor out the multiplier during mode_set.
  973. */
  974. pipe_config->pixel_multiplier =
  975. intel_sdvo_get_pixel_multiplier(adjusted_mode);
  976. adjusted_mode->clock *= pipe_config->pixel_multiplier;
  977. if (intel_sdvo->color_range_auto) {
  978. /* See CEA-861-E - 5.1 Default Encoding Parameters */
  979. /* FIXME: This bit is only valid when using TMDS encoding and 8
  980. * bit per color mode. */
  981. if (intel_sdvo->has_hdmi_monitor &&
  982. drm_match_cea_mode(adjusted_mode) > 1)
  983. intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
  984. else
  985. intel_sdvo->color_range = 0;
  986. }
  987. if (intel_sdvo->color_range)
  988. pipe_config->limited_color_range = true;
  989. /* Clock computation needs to happen after pixel multiplier. */
  990. if (intel_sdvo->is_tv)
  991. i9xx_adjust_sdvo_tv_clock(pipe_config);
  992. return true;
  993. }
  994. static void intel_sdvo_mode_set(struct intel_encoder *intel_encoder)
  995. {
  996. struct drm_device *dev = intel_encoder->base.dev;
  997. struct drm_i915_private *dev_priv = dev->dev_private;
  998. struct intel_crtc *crtc = to_intel_crtc(intel_encoder->base.crtc);
  999. struct drm_display_mode *adjusted_mode =
  1000. &crtc->config.adjusted_mode;
  1001. struct drm_display_mode *mode = &crtc->config.requested_mode;
  1002. struct intel_sdvo *intel_sdvo = to_sdvo(intel_encoder);
  1003. u32 sdvox;
  1004. struct intel_sdvo_in_out_map in_out;
  1005. struct intel_sdvo_dtd input_dtd, output_dtd;
  1006. int rate;
  1007. if (!mode)
  1008. return;
  1009. /* First, set the input mapping for the first input to our controlled
  1010. * output. This is only correct if we're a single-input device, in
  1011. * which case the first input is the output from the appropriate SDVO
  1012. * channel on the motherboard. In a two-input device, the first input
  1013. * will be SDVOB and the second SDVOC.
  1014. */
  1015. in_out.in0 = intel_sdvo->attached_output;
  1016. in_out.in1 = 0;
  1017. intel_sdvo_set_value(intel_sdvo,
  1018. SDVO_CMD_SET_IN_OUT_MAP,
  1019. &in_out, sizeof(in_out));
  1020. /* Set the output timings to the screen */
  1021. if (!intel_sdvo_set_target_output(intel_sdvo,
  1022. intel_sdvo->attached_output))
  1023. return;
  1024. /* lvds has a special fixed output timing. */
  1025. if (intel_sdvo->is_lvds)
  1026. intel_sdvo_get_dtd_from_mode(&output_dtd,
  1027. intel_sdvo->sdvo_lvds_fixed_mode);
  1028. else
  1029. intel_sdvo_get_dtd_from_mode(&output_dtd, mode);
  1030. if (!intel_sdvo_set_output_timing(intel_sdvo, &output_dtd))
  1031. DRM_INFO("Setting output timings on %s failed\n",
  1032. SDVO_NAME(intel_sdvo));
  1033. /* Set the input timing to the screen. Assume always input 0. */
  1034. if (!intel_sdvo_set_target_input(intel_sdvo))
  1035. return;
  1036. if (intel_sdvo->has_hdmi_monitor) {
  1037. intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);
  1038. intel_sdvo_set_colorimetry(intel_sdvo,
  1039. SDVO_COLORIMETRY_RGB256);
  1040. intel_sdvo_set_avi_infoframe(intel_sdvo, adjusted_mode);
  1041. } else
  1042. intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);
  1043. if (intel_sdvo->is_tv &&
  1044. !intel_sdvo_set_tv_format(intel_sdvo))
  1045. return;
  1046. /* We have tried to get input timing in mode_fixup, and filled into
  1047. * adjusted_mode.
  1048. */
  1049. intel_sdvo_get_dtd_from_mode(&input_dtd, adjusted_mode);
  1050. input_dtd.part1.clock /= crtc->config.pixel_multiplier;
  1051. if (intel_sdvo->is_tv || intel_sdvo->is_lvds)
  1052. input_dtd.part2.sdvo_flags = intel_sdvo->dtd_sdvo_flags;
  1053. if (!intel_sdvo_set_input_timing(intel_sdvo, &input_dtd))
  1054. DRM_INFO("Setting input timings on %s failed\n",
  1055. SDVO_NAME(intel_sdvo));
  1056. switch (crtc->config.pixel_multiplier) {
  1057. default:
  1058. WARN(1, "unknown pixel mutlipler specified\n");
  1059. case 1: rate = SDVO_CLOCK_RATE_MULT_1X; break;
  1060. case 2: rate = SDVO_CLOCK_RATE_MULT_2X; break;
  1061. case 4: rate = SDVO_CLOCK_RATE_MULT_4X; break;
  1062. }
  1063. if (!intel_sdvo_set_clock_rate_mult(intel_sdvo, rate))
  1064. return;
  1065. /* Set the SDVO control regs. */
  1066. if (INTEL_INFO(dev)->gen >= 4) {
  1067. /* The real mode polarity is set by the SDVO commands, using
  1068. * struct intel_sdvo_dtd. */
  1069. sdvox = SDVO_VSYNC_ACTIVE_HIGH | SDVO_HSYNC_ACTIVE_HIGH;
  1070. if (!HAS_PCH_SPLIT(dev) && intel_sdvo->is_hdmi)
  1071. sdvox |= intel_sdvo->color_range;
  1072. if (INTEL_INFO(dev)->gen < 5)
  1073. sdvox |= SDVO_BORDER_ENABLE;
  1074. } else {
  1075. sdvox = I915_READ(intel_sdvo->sdvo_reg);
  1076. switch (intel_sdvo->sdvo_reg) {
  1077. case GEN3_SDVOB:
  1078. sdvox &= SDVOB_PRESERVE_MASK;
  1079. break;
  1080. case GEN3_SDVOC:
  1081. sdvox &= SDVOC_PRESERVE_MASK;
  1082. break;
  1083. }
  1084. sdvox |= (9 << 19) | SDVO_BORDER_ENABLE;
  1085. }
  1086. if (INTEL_PCH_TYPE(dev) >= PCH_CPT)
  1087. sdvox |= SDVO_PIPE_SEL_CPT(crtc->pipe);
  1088. else
  1089. sdvox |= SDVO_PIPE_SEL(crtc->pipe);
  1090. if (intel_sdvo->has_hdmi_audio)
  1091. sdvox |= SDVO_AUDIO_ENABLE;
  1092. if (INTEL_INFO(dev)->gen >= 4) {
  1093. /* done in crtc_mode_set as the dpll_md reg must be written early */
  1094. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  1095. /* done in crtc_mode_set as it lives inside the dpll register */
  1096. } else {
  1097. sdvox |= (crtc->config.pixel_multiplier - 1)
  1098. << SDVO_PORT_MULTIPLY_SHIFT;
  1099. }
  1100. if (input_dtd.part2.sdvo_flags & SDVO_NEED_TO_STALL &&
  1101. INTEL_INFO(dev)->gen < 5)
  1102. sdvox |= SDVO_STALL_SELECT;
  1103. intel_sdvo_write_sdvox(intel_sdvo, sdvox);
  1104. }
  1105. static bool intel_sdvo_connector_get_hw_state(struct intel_connector *connector)
  1106. {
  1107. struct intel_sdvo_connector *intel_sdvo_connector =
  1108. to_intel_sdvo_connector(&connector->base);
  1109. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(&connector->base);
  1110. u16 active_outputs = 0;
  1111. intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
  1112. if (active_outputs & intel_sdvo_connector->output_flag)
  1113. return true;
  1114. else
  1115. return false;
  1116. }
  1117. static bool intel_sdvo_get_hw_state(struct intel_encoder *encoder,
  1118. enum pipe *pipe)
  1119. {
  1120. struct drm_device *dev = encoder->base.dev;
  1121. struct drm_i915_private *dev_priv = dev->dev_private;
  1122. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  1123. u16 active_outputs = 0;
  1124. u32 tmp;
  1125. tmp = I915_READ(intel_sdvo->sdvo_reg);
  1126. intel_sdvo_get_active_outputs(intel_sdvo, &active_outputs);
  1127. if (!(tmp & SDVO_ENABLE) && (active_outputs == 0))
  1128. return false;
  1129. if (HAS_PCH_CPT(dev))
  1130. *pipe = PORT_TO_PIPE_CPT(tmp);
  1131. else
  1132. *pipe = PORT_TO_PIPE(tmp);
  1133. return true;
  1134. }
  1135. static void intel_sdvo_get_config(struct intel_encoder *encoder,
  1136. struct intel_crtc_config *pipe_config)
  1137. {
  1138. struct drm_device *dev = encoder->base.dev;
  1139. struct drm_i915_private *dev_priv = dev->dev_private;
  1140. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  1141. struct intel_sdvo_dtd dtd;
  1142. int encoder_pixel_multiplier = 0;
  1143. u32 flags = 0, sdvox;
  1144. u8 val;
  1145. bool ret;
  1146. ret = intel_sdvo_get_input_timing(intel_sdvo, &dtd);
  1147. if (!ret) {
  1148. /* Some sdvo encoders are not spec compliant and don't
  1149. * implement the mandatory get_timings function. */
  1150. DRM_DEBUG_DRIVER("failed to retrieve SDVO DTD\n");
  1151. pipe_config->quirks |= PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS;
  1152. } else {
  1153. if (dtd.part2.dtd_flags & DTD_FLAG_HSYNC_POSITIVE)
  1154. flags |= DRM_MODE_FLAG_PHSYNC;
  1155. else
  1156. flags |= DRM_MODE_FLAG_NHSYNC;
  1157. if (dtd.part2.dtd_flags & DTD_FLAG_VSYNC_POSITIVE)
  1158. flags |= DRM_MODE_FLAG_PVSYNC;
  1159. else
  1160. flags |= DRM_MODE_FLAG_NVSYNC;
  1161. }
  1162. pipe_config->adjusted_mode.flags |= flags;
  1163. /*
  1164. * pixel multiplier readout is tricky: Only on i915g/gm it is stored in
  1165. * the sdvo port register, on all other platforms it is part of the dpll
  1166. * state. Since the general pipe state readout happens before the
  1167. * encoder->get_config we so already have a valid pixel multplier on all
  1168. * other platfroms.
  1169. */
  1170. if (IS_I915G(dev) || IS_I915GM(dev)) {
  1171. sdvox = I915_READ(intel_sdvo->sdvo_reg);
  1172. pipe_config->pixel_multiplier =
  1173. ((sdvox & SDVO_PORT_MULTIPLY_MASK)
  1174. >> SDVO_PORT_MULTIPLY_SHIFT) + 1;
  1175. }
  1176. /* Cross check the port pixel multiplier with the sdvo encoder state. */
  1177. if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
  1178. &val, 1)) {
  1179. switch (val) {
  1180. case SDVO_CLOCK_RATE_MULT_1X:
  1181. encoder_pixel_multiplier = 1;
  1182. break;
  1183. case SDVO_CLOCK_RATE_MULT_2X:
  1184. encoder_pixel_multiplier = 2;
  1185. break;
  1186. case SDVO_CLOCK_RATE_MULT_4X:
  1187. encoder_pixel_multiplier = 4;
  1188. break;
  1189. }
  1190. }
  1191. WARN(encoder_pixel_multiplier != pipe_config->pixel_multiplier,
  1192. "SDVO pixel multiplier mismatch, port: %i, encoder: %i\n",
  1193. pipe_config->pixel_multiplier, encoder_pixel_multiplier);
  1194. }
  1195. static void intel_disable_sdvo(struct intel_encoder *encoder)
  1196. {
  1197. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1198. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  1199. u32 temp;
  1200. intel_sdvo_set_active_outputs(intel_sdvo, 0);
  1201. if (0)
  1202. intel_sdvo_set_encoder_power_state(intel_sdvo,
  1203. DRM_MODE_DPMS_OFF);
  1204. temp = I915_READ(intel_sdvo->sdvo_reg);
  1205. if ((temp & SDVO_ENABLE) != 0) {
  1206. /* HW workaround for IBX, we need to move the port to
  1207. * transcoder A before disabling it. */
  1208. if (HAS_PCH_IBX(encoder->base.dev)) {
  1209. struct drm_crtc *crtc = encoder->base.crtc;
  1210. int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
  1211. if (temp & SDVO_PIPE_B_SELECT) {
  1212. temp &= ~SDVO_PIPE_B_SELECT;
  1213. I915_WRITE(intel_sdvo->sdvo_reg, temp);
  1214. POSTING_READ(intel_sdvo->sdvo_reg);
  1215. /* Again we need to write this twice. */
  1216. I915_WRITE(intel_sdvo->sdvo_reg, temp);
  1217. POSTING_READ(intel_sdvo->sdvo_reg);
  1218. /* Transcoder selection bits only update
  1219. * effectively on vblank. */
  1220. if (crtc)
  1221. intel_wait_for_vblank(encoder->base.dev, pipe);
  1222. else
  1223. msleep(50);
  1224. }
  1225. }
  1226. intel_sdvo_write_sdvox(intel_sdvo, temp & ~SDVO_ENABLE);
  1227. }
  1228. }
  1229. static void intel_enable_sdvo(struct intel_encoder *encoder)
  1230. {
  1231. struct drm_device *dev = encoder->base.dev;
  1232. struct drm_i915_private *dev_priv = dev->dev_private;
  1233. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  1234. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1235. u32 temp;
  1236. bool input1, input2;
  1237. int i;
  1238. u8 status;
  1239. temp = I915_READ(intel_sdvo->sdvo_reg);
  1240. if ((temp & SDVO_ENABLE) == 0) {
  1241. /* HW workaround for IBX, we need to move the port
  1242. * to transcoder A before disabling it, so restore it here. */
  1243. if (HAS_PCH_IBX(dev))
  1244. temp |= SDVO_PIPE_SEL(intel_crtc->pipe);
  1245. intel_sdvo_write_sdvox(intel_sdvo, temp | SDVO_ENABLE);
  1246. }
  1247. for (i = 0; i < 2; i++)
  1248. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1249. status = intel_sdvo_get_trained_inputs(intel_sdvo, &input1, &input2);
  1250. /* Warn if the device reported failure to sync.
  1251. * A lot of SDVO devices fail to notify of sync, but it's
  1252. * a given it the status is a success, we succeeded.
  1253. */
  1254. if (status == SDVO_CMD_STATUS_SUCCESS && !input1) {
  1255. DRM_DEBUG_KMS("First %s output reported failure to "
  1256. "sync\n", SDVO_NAME(intel_sdvo));
  1257. }
  1258. if (0)
  1259. intel_sdvo_set_encoder_power_state(intel_sdvo,
  1260. DRM_MODE_DPMS_ON);
  1261. intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
  1262. }
  1263. /* Special dpms function to support cloning between dvo/sdvo/crt. */
  1264. static void intel_sdvo_dpms(struct drm_connector *connector, int mode)
  1265. {
  1266. struct drm_crtc *crtc;
  1267. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1268. /* dvo supports only 2 dpms states. */
  1269. if (mode != DRM_MODE_DPMS_ON)
  1270. mode = DRM_MODE_DPMS_OFF;
  1271. if (mode == connector->dpms)
  1272. return;
  1273. connector->dpms = mode;
  1274. /* Only need to change hw state when actually enabled */
  1275. crtc = intel_sdvo->base.base.crtc;
  1276. if (!crtc) {
  1277. intel_sdvo->base.connectors_active = false;
  1278. return;
  1279. }
  1280. /* We set active outputs manually below in case pipe dpms doesn't change
  1281. * due to cloning. */
  1282. if (mode != DRM_MODE_DPMS_ON) {
  1283. intel_sdvo_set_active_outputs(intel_sdvo, 0);
  1284. if (0)
  1285. intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
  1286. intel_sdvo->base.connectors_active = false;
  1287. intel_crtc_update_dpms(crtc);
  1288. } else {
  1289. intel_sdvo->base.connectors_active = true;
  1290. intel_crtc_update_dpms(crtc);
  1291. if (0)
  1292. intel_sdvo_set_encoder_power_state(intel_sdvo, mode);
  1293. intel_sdvo_set_active_outputs(intel_sdvo, intel_sdvo->attached_output);
  1294. }
  1295. intel_modeset_check_state(connector->dev);
  1296. }
  1297. static int intel_sdvo_mode_valid(struct drm_connector *connector,
  1298. struct drm_display_mode *mode)
  1299. {
  1300. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1301. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1302. return MODE_NO_DBLESCAN;
  1303. if (intel_sdvo->pixel_clock_min > mode->clock)
  1304. return MODE_CLOCK_LOW;
  1305. if (intel_sdvo->pixel_clock_max < mode->clock)
  1306. return MODE_CLOCK_HIGH;
  1307. if (intel_sdvo->is_lvds) {
  1308. if (mode->hdisplay > intel_sdvo->sdvo_lvds_fixed_mode->hdisplay)
  1309. return MODE_PANEL;
  1310. if (mode->vdisplay > intel_sdvo->sdvo_lvds_fixed_mode->vdisplay)
  1311. return MODE_PANEL;
  1312. }
  1313. return MODE_OK;
  1314. }
  1315. static bool intel_sdvo_get_capabilities(struct intel_sdvo *intel_sdvo, struct intel_sdvo_caps *caps)
  1316. {
  1317. BUILD_BUG_ON(sizeof(*caps) != 8);
  1318. if (!intel_sdvo_get_value(intel_sdvo,
  1319. SDVO_CMD_GET_DEVICE_CAPS,
  1320. caps, sizeof(*caps)))
  1321. return false;
  1322. DRM_DEBUG_KMS("SDVO capabilities:\n"
  1323. " vendor_id: %d\n"
  1324. " device_id: %d\n"
  1325. " device_rev_id: %d\n"
  1326. " sdvo_version_major: %d\n"
  1327. " sdvo_version_minor: %d\n"
  1328. " sdvo_inputs_mask: %d\n"
  1329. " smooth_scaling: %d\n"
  1330. " sharp_scaling: %d\n"
  1331. " up_scaling: %d\n"
  1332. " down_scaling: %d\n"
  1333. " stall_support: %d\n"
  1334. " output_flags: %d\n",
  1335. caps->vendor_id,
  1336. caps->device_id,
  1337. caps->device_rev_id,
  1338. caps->sdvo_version_major,
  1339. caps->sdvo_version_minor,
  1340. caps->sdvo_inputs_mask,
  1341. caps->smooth_scaling,
  1342. caps->sharp_scaling,
  1343. caps->up_scaling,
  1344. caps->down_scaling,
  1345. caps->stall_support,
  1346. caps->output_flags);
  1347. return true;
  1348. }
  1349. static uint16_t intel_sdvo_get_hotplug_support(struct intel_sdvo *intel_sdvo)
  1350. {
  1351. struct drm_device *dev = intel_sdvo->base.base.dev;
  1352. uint16_t hotplug;
  1353. /* HW Erratum: SDVO Hotplug is broken on all i945G chips, there's noise
  1354. * on the line. */
  1355. if (IS_I945G(dev) || IS_I945GM(dev))
  1356. return 0;
  1357. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_HOT_PLUG_SUPPORT,
  1358. &hotplug, sizeof(hotplug)))
  1359. return 0;
  1360. return hotplug;
  1361. }
  1362. static void intel_sdvo_enable_hotplug(struct intel_encoder *encoder)
  1363. {
  1364. struct intel_sdvo *intel_sdvo = to_sdvo(encoder);
  1365. intel_sdvo_write_cmd(intel_sdvo, SDVO_CMD_SET_ACTIVE_HOT_PLUG,
  1366. &intel_sdvo->hotplug_active, 2);
  1367. }
  1368. static bool
  1369. intel_sdvo_multifunc_encoder(struct intel_sdvo *intel_sdvo)
  1370. {
  1371. /* Is there more than one type of output? */
  1372. return hweight16(intel_sdvo->caps.output_flags) > 1;
  1373. }
  1374. static struct edid *
  1375. intel_sdvo_get_edid(struct drm_connector *connector)
  1376. {
  1377. struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
  1378. return drm_get_edid(connector, &sdvo->ddc);
  1379. }
  1380. /* Mac mini hack -- use the same DDC as the analog connector */
  1381. static struct edid *
  1382. intel_sdvo_get_analog_edid(struct drm_connector *connector)
  1383. {
  1384. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1385. return drm_get_edid(connector,
  1386. intel_gmbus_get_adapter(dev_priv,
  1387. dev_priv->vbt.crt_ddc_pin));
  1388. }
  1389. static enum drm_connector_status
  1390. intel_sdvo_tmds_sink_detect(struct drm_connector *connector)
  1391. {
  1392. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1393. enum drm_connector_status status;
  1394. struct edid *edid;
  1395. edid = intel_sdvo_get_edid(connector);
  1396. if (edid == NULL && intel_sdvo_multifunc_encoder(intel_sdvo)) {
  1397. u8 ddc, saved_ddc = intel_sdvo->ddc_bus;
  1398. /*
  1399. * Don't use the 1 as the argument of DDC bus switch to get
  1400. * the EDID. It is used for SDVO SPD ROM.
  1401. */
  1402. for (ddc = intel_sdvo->ddc_bus >> 1; ddc > 1; ddc >>= 1) {
  1403. intel_sdvo->ddc_bus = ddc;
  1404. edid = intel_sdvo_get_edid(connector);
  1405. if (edid)
  1406. break;
  1407. }
  1408. /*
  1409. * If we found the EDID on the other bus,
  1410. * assume that is the correct DDC bus.
  1411. */
  1412. if (edid == NULL)
  1413. intel_sdvo->ddc_bus = saved_ddc;
  1414. }
  1415. /*
  1416. * When there is no edid and no monitor is connected with VGA
  1417. * port, try to use the CRT ddc to read the EDID for DVI-connector.
  1418. */
  1419. if (edid == NULL)
  1420. edid = intel_sdvo_get_analog_edid(connector);
  1421. status = connector_status_unknown;
  1422. if (edid != NULL) {
  1423. /* DDC bus is shared, match EDID to connector type */
  1424. if (edid->input & DRM_EDID_INPUT_DIGITAL) {
  1425. status = connector_status_connected;
  1426. if (intel_sdvo->is_hdmi) {
  1427. intel_sdvo->has_hdmi_monitor = drm_detect_hdmi_monitor(edid);
  1428. intel_sdvo->has_hdmi_audio = drm_detect_monitor_audio(edid);
  1429. intel_sdvo->rgb_quant_range_selectable =
  1430. drm_rgb_quant_range_selectable(edid);
  1431. }
  1432. } else
  1433. status = connector_status_disconnected;
  1434. kfree(edid);
  1435. }
  1436. if (status == connector_status_connected) {
  1437. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1438. if (intel_sdvo_connector->force_audio != HDMI_AUDIO_AUTO)
  1439. intel_sdvo->has_hdmi_audio = (intel_sdvo_connector->force_audio == HDMI_AUDIO_ON);
  1440. }
  1441. return status;
  1442. }
  1443. static bool
  1444. intel_sdvo_connector_matches_edid(struct intel_sdvo_connector *sdvo,
  1445. struct edid *edid)
  1446. {
  1447. bool monitor_is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL);
  1448. bool connector_is_digital = !!IS_DIGITAL(sdvo);
  1449. DRM_DEBUG_KMS("connector_is_digital? %d, monitor_is_digital? %d\n",
  1450. connector_is_digital, monitor_is_digital);
  1451. return connector_is_digital == monitor_is_digital;
  1452. }
  1453. static enum drm_connector_status
  1454. intel_sdvo_detect(struct drm_connector *connector, bool force)
  1455. {
  1456. uint16_t response;
  1457. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1458. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1459. enum drm_connector_status ret;
  1460. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  1461. connector->base.id, drm_get_connector_name(connector));
  1462. if (!intel_sdvo_get_value(intel_sdvo,
  1463. SDVO_CMD_GET_ATTACHED_DISPLAYS,
  1464. &response, 2))
  1465. return connector_status_unknown;
  1466. DRM_DEBUG_KMS("SDVO response %d %d [%x]\n",
  1467. response & 0xff, response >> 8,
  1468. intel_sdvo_connector->output_flag);
  1469. if (response == 0)
  1470. return connector_status_disconnected;
  1471. intel_sdvo->attached_output = response;
  1472. intel_sdvo->has_hdmi_monitor = false;
  1473. intel_sdvo->has_hdmi_audio = false;
  1474. intel_sdvo->rgb_quant_range_selectable = false;
  1475. if ((intel_sdvo_connector->output_flag & response) == 0)
  1476. ret = connector_status_disconnected;
  1477. else if (IS_TMDS(intel_sdvo_connector))
  1478. ret = intel_sdvo_tmds_sink_detect(connector);
  1479. else {
  1480. struct edid *edid;
  1481. /* if we have an edid check it matches the connection */
  1482. edid = intel_sdvo_get_edid(connector);
  1483. if (edid == NULL)
  1484. edid = intel_sdvo_get_analog_edid(connector);
  1485. if (edid != NULL) {
  1486. if (intel_sdvo_connector_matches_edid(intel_sdvo_connector,
  1487. edid))
  1488. ret = connector_status_connected;
  1489. else
  1490. ret = connector_status_disconnected;
  1491. kfree(edid);
  1492. } else
  1493. ret = connector_status_connected;
  1494. }
  1495. /* May update encoder flag for like clock for SDVO TV, etc.*/
  1496. if (ret == connector_status_connected) {
  1497. intel_sdvo->is_tv = false;
  1498. intel_sdvo->is_lvds = false;
  1499. if (response & SDVO_TV_MASK)
  1500. intel_sdvo->is_tv = true;
  1501. if (response & SDVO_LVDS_MASK)
  1502. intel_sdvo->is_lvds = intel_sdvo->sdvo_lvds_fixed_mode != NULL;
  1503. }
  1504. return ret;
  1505. }
  1506. static void intel_sdvo_get_ddc_modes(struct drm_connector *connector)
  1507. {
  1508. struct edid *edid;
  1509. /* set the bus switch and get the modes */
  1510. edid = intel_sdvo_get_edid(connector);
  1511. /*
  1512. * Mac mini hack. On this device, the DVI-I connector shares one DDC
  1513. * link between analog and digital outputs. So, if the regular SDVO
  1514. * DDC fails, check to see if the analog output is disconnected, in
  1515. * which case we'll look there for the digital DDC data.
  1516. */
  1517. if (edid == NULL)
  1518. edid = intel_sdvo_get_analog_edid(connector);
  1519. if (edid != NULL) {
  1520. if (intel_sdvo_connector_matches_edid(to_intel_sdvo_connector(connector),
  1521. edid)) {
  1522. drm_mode_connector_update_edid_property(connector, edid);
  1523. drm_add_edid_modes(connector, edid);
  1524. }
  1525. kfree(edid);
  1526. }
  1527. }
  1528. /*
  1529. * Set of SDVO TV modes.
  1530. * Note! This is in reply order (see loop in get_tv_modes).
  1531. * XXX: all 60Hz refresh?
  1532. */
  1533. static const struct drm_display_mode sdvo_tv_modes[] = {
  1534. { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 5815, 320, 321, 384,
  1535. 416, 0, 200, 201, 232, 233, 0,
  1536. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1537. { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 6814, 320, 321, 384,
  1538. 416, 0, 240, 241, 272, 273, 0,
  1539. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1540. { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 9910, 400, 401, 464,
  1541. 496, 0, 300, 301, 332, 333, 0,
  1542. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1543. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 16913, 640, 641, 704,
  1544. 736, 0, 350, 351, 382, 383, 0,
  1545. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1546. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 19121, 640, 641, 704,
  1547. 736, 0, 400, 401, 432, 433, 0,
  1548. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1549. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 22654, 640, 641, 704,
  1550. 736, 0, 480, 481, 512, 513, 0,
  1551. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1552. { DRM_MODE("704x480", DRM_MODE_TYPE_DRIVER, 24624, 704, 705, 768,
  1553. 800, 0, 480, 481, 512, 513, 0,
  1554. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1555. { DRM_MODE("704x576", DRM_MODE_TYPE_DRIVER, 29232, 704, 705, 768,
  1556. 800, 0, 576, 577, 608, 609, 0,
  1557. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1558. { DRM_MODE("720x350", DRM_MODE_TYPE_DRIVER, 18751, 720, 721, 784,
  1559. 816, 0, 350, 351, 382, 383, 0,
  1560. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1561. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 21199, 720, 721, 784,
  1562. 816, 0, 400, 401, 432, 433, 0,
  1563. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1564. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 25116, 720, 721, 784,
  1565. 816, 0, 480, 481, 512, 513, 0,
  1566. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1567. { DRM_MODE("720x540", DRM_MODE_TYPE_DRIVER, 28054, 720, 721, 784,
  1568. 816, 0, 540, 541, 572, 573, 0,
  1569. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1570. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 29816, 720, 721, 784,
  1571. 816, 0, 576, 577, 608, 609, 0,
  1572. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1573. { DRM_MODE("768x576", DRM_MODE_TYPE_DRIVER, 31570, 768, 769, 832,
  1574. 864, 0, 576, 577, 608, 609, 0,
  1575. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1576. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 34030, 800, 801, 864,
  1577. 896, 0, 600, 601, 632, 633, 0,
  1578. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1579. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 36581, 832, 833, 896,
  1580. 928, 0, 624, 625, 656, 657, 0,
  1581. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1582. { DRM_MODE("920x766", DRM_MODE_TYPE_DRIVER, 48707, 920, 921, 984,
  1583. 1016, 0, 766, 767, 798, 799, 0,
  1584. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1585. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 53827, 1024, 1025, 1088,
  1586. 1120, 0, 768, 769, 800, 801, 0,
  1587. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1588. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 87265, 1280, 1281, 1344,
  1589. 1376, 0, 1024, 1025, 1056, 1057, 0,
  1590. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  1591. };
  1592. static void intel_sdvo_get_tv_modes(struct drm_connector *connector)
  1593. {
  1594. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1595. struct intel_sdvo_sdtv_resolution_request tv_res;
  1596. uint32_t reply = 0, format_map = 0;
  1597. int i;
  1598. /* Read the list of supported input resolutions for the selected TV
  1599. * format.
  1600. */
  1601. format_map = 1 << intel_sdvo->tv_format_index;
  1602. memcpy(&tv_res, &format_map,
  1603. min(sizeof(format_map), sizeof(struct intel_sdvo_sdtv_resolution_request)));
  1604. if (!intel_sdvo_set_target_output(intel_sdvo, intel_sdvo->attached_output))
  1605. return;
  1606. BUILD_BUG_ON(sizeof(tv_res) != 3);
  1607. if (!intel_sdvo_write_cmd(intel_sdvo,
  1608. SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT,
  1609. &tv_res, sizeof(tv_res)))
  1610. return;
  1611. if (!intel_sdvo_read_response(intel_sdvo, &reply, 3))
  1612. return;
  1613. for (i = 0; i < ARRAY_SIZE(sdvo_tv_modes); i++)
  1614. if (reply & (1 << i)) {
  1615. struct drm_display_mode *nmode;
  1616. nmode = drm_mode_duplicate(connector->dev,
  1617. &sdvo_tv_modes[i]);
  1618. if (nmode)
  1619. drm_mode_probed_add(connector, nmode);
  1620. }
  1621. }
  1622. static void intel_sdvo_get_lvds_modes(struct drm_connector *connector)
  1623. {
  1624. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1625. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1626. struct drm_display_mode *newmode;
  1627. /*
  1628. * Fetch modes from VBT. For SDVO prefer the VBT mode since some
  1629. * SDVO->LVDS transcoders can't cope with the EDID mode.
  1630. */
  1631. if (dev_priv->vbt.sdvo_lvds_vbt_mode != NULL) {
  1632. newmode = drm_mode_duplicate(connector->dev,
  1633. dev_priv->vbt.sdvo_lvds_vbt_mode);
  1634. if (newmode != NULL) {
  1635. /* Guarantee the mode is preferred */
  1636. newmode->type = (DRM_MODE_TYPE_PREFERRED |
  1637. DRM_MODE_TYPE_DRIVER);
  1638. drm_mode_probed_add(connector, newmode);
  1639. }
  1640. }
  1641. /*
  1642. * Attempt to get the mode list from DDC.
  1643. * Assume that the preferred modes are
  1644. * arranged in priority order.
  1645. */
  1646. intel_ddc_get_modes(connector, &intel_sdvo->ddc);
  1647. list_for_each_entry(newmode, &connector->probed_modes, head) {
  1648. if (newmode->type & DRM_MODE_TYPE_PREFERRED) {
  1649. intel_sdvo->sdvo_lvds_fixed_mode =
  1650. drm_mode_duplicate(connector->dev, newmode);
  1651. intel_sdvo->is_lvds = true;
  1652. break;
  1653. }
  1654. }
  1655. }
  1656. static int intel_sdvo_get_modes(struct drm_connector *connector)
  1657. {
  1658. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1659. if (IS_TV(intel_sdvo_connector))
  1660. intel_sdvo_get_tv_modes(connector);
  1661. else if (IS_LVDS(intel_sdvo_connector))
  1662. intel_sdvo_get_lvds_modes(connector);
  1663. else
  1664. intel_sdvo_get_ddc_modes(connector);
  1665. return !list_empty(&connector->probed_modes);
  1666. }
  1667. static void
  1668. intel_sdvo_destroy_enhance_property(struct drm_connector *connector)
  1669. {
  1670. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1671. struct drm_device *dev = connector->dev;
  1672. if (intel_sdvo_connector->left)
  1673. drm_property_destroy(dev, intel_sdvo_connector->left);
  1674. if (intel_sdvo_connector->right)
  1675. drm_property_destroy(dev, intel_sdvo_connector->right);
  1676. if (intel_sdvo_connector->top)
  1677. drm_property_destroy(dev, intel_sdvo_connector->top);
  1678. if (intel_sdvo_connector->bottom)
  1679. drm_property_destroy(dev, intel_sdvo_connector->bottom);
  1680. if (intel_sdvo_connector->hpos)
  1681. drm_property_destroy(dev, intel_sdvo_connector->hpos);
  1682. if (intel_sdvo_connector->vpos)
  1683. drm_property_destroy(dev, intel_sdvo_connector->vpos);
  1684. if (intel_sdvo_connector->saturation)
  1685. drm_property_destroy(dev, intel_sdvo_connector->saturation);
  1686. if (intel_sdvo_connector->contrast)
  1687. drm_property_destroy(dev, intel_sdvo_connector->contrast);
  1688. if (intel_sdvo_connector->hue)
  1689. drm_property_destroy(dev, intel_sdvo_connector->hue);
  1690. if (intel_sdvo_connector->sharpness)
  1691. drm_property_destroy(dev, intel_sdvo_connector->sharpness);
  1692. if (intel_sdvo_connector->flicker_filter)
  1693. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter);
  1694. if (intel_sdvo_connector->flicker_filter_2d)
  1695. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_2d);
  1696. if (intel_sdvo_connector->flicker_filter_adaptive)
  1697. drm_property_destroy(dev, intel_sdvo_connector->flicker_filter_adaptive);
  1698. if (intel_sdvo_connector->tv_luma_filter)
  1699. drm_property_destroy(dev, intel_sdvo_connector->tv_luma_filter);
  1700. if (intel_sdvo_connector->tv_chroma_filter)
  1701. drm_property_destroy(dev, intel_sdvo_connector->tv_chroma_filter);
  1702. if (intel_sdvo_connector->dot_crawl)
  1703. drm_property_destroy(dev, intel_sdvo_connector->dot_crawl);
  1704. if (intel_sdvo_connector->brightness)
  1705. drm_property_destroy(dev, intel_sdvo_connector->brightness);
  1706. }
  1707. static void intel_sdvo_destroy(struct drm_connector *connector)
  1708. {
  1709. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1710. if (intel_sdvo_connector->tv_format)
  1711. drm_property_destroy(connector->dev,
  1712. intel_sdvo_connector->tv_format);
  1713. intel_sdvo_destroy_enhance_property(connector);
  1714. drm_sysfs_connector_remove(connector);
  1715. drm_connector_cleanup(connector);
  1716. kfree(intel_sdvo_connector);
  1717. }
  1718. static bool intel_sdvo_detect_hdmi_audio(struct drm_connector *connector)
  1719. {
  1720. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1721. struct edid *edid;
  1722. bool has_audio = false;
  1723. if (!intel_sdvo->is_hdmi)
  1724. return false;
  1725. edid = intel_sdvo_get_edid(connector);
  1726. if (edid != NULL && edid->input & DRM_EDID_INPUT_DIGITAL)
  1727. has_audio = drm_detect_monitor_audio(edid);
  1728. kfree(edid);
  1729. return has_audio;
  1730. }
  1731. static int
  1732. intel_sdvo_set_property(struct drm_connector *connector,
  1733. struct drm_property *property,
  1734. uint64_t val)
  1735. {
  1736. struct intel_sdvo *intel_sdvo = intel_attached_sdvo(connector);
  1737. struct intel_sdvo_connector *intel_sdvo_connector = to_intel_sdvo_connector(connector);
  1738. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1739. uint16_t temp_value;
  1740. uint8_t cmd;
  1741. int ret;
  1742. ret = drm_object_property_set_value(&connector->base, property, val);
  1743. if (ret)
  1744. return ret;
  1745. if (property == dev_priv->force_audio_property) {
  1746. int i = val;
  1747. bool has_audio;
  1748. if (i == intel_sdvo_connector->force_audio)
  1749. return 0;
  1750. intel_sdvo_connector->force_audio = i;
  1751. if (i == HDMI_AUDIO_AUTO)
  1752. has_audio = intel_sdvo_detect_hdmi_audio(connector);
  1753. else
  1754. has_audio = (i == HDMI_AUDIO_ON);
  1755. if (has_audio == intel_sdvo->has_hdmi_audio)
  1756. return 0;
  1757. intel_sdvo->has_hdmi_audio = has_audio;
  1758. goto done;
  1759. }
  1760. if (property == dev_priv->broadcast_rgb_property) {
  1761. bool old_auto = intel_sdvo->color_range_auto;
  1762. uint32_t old_range = intel_sdvo->color_range;
  1763. switch (val) {
  1764. case INTEL_BROADCAST_RGB_AUTO:
  1765. intel_sdvo->color_range_auto = true;
  1766. break;
  1767. case INTEL_BROADCAST_RGB_FULL:
  1768. intel_sdvo->color_range_auto = false;
  1769. intel_sdvo->color_range = 0;
  1770. break;
  1771. case INTEL_BROADCAST_RGB_LIMITED:
  1772. intel_sdvo->color_range_auto = false;
  1773. /* FIXME: this bit is only valid when using TMDS
  1774. * encoding and 8 bit per color mode. */
  1775. intel_sdvo->color_range = HDMI_COLOR_RANGE_16_235;
  1776. break;
  1777. default:
  1778. return -EINVAL;
  1779. }
  1780. if (old_auto == intel_sdvo->color_range_auto &&
  1781. old_range == intel_sdvo->color_range)
  1782. return 0;
  1783. goto done;
  1784. }
  1785. #define CHECK_PROPERTY(name, NAME) \
  1786. if (intel_sdvo_connector->name == property) { \
  1787. if (intel_sdvo_connector->cur_##name == temp_value) return 0; \
  1788. if (intel_sdvo_connector->max_##name < temp_value) return -EINVAL; \
  1789. cmd = SDVO_CMD_SET_##NAME; \
  1790. intel_sdvo_connector->cur_##name = temp_value; \
  1791. goto set_value; \
  1792. }
  1793. if (property == intel_sdvo_connector->tv_format) {
  1794. if (val >= TV_FORMAT_NUM)
  1795. return -EINVAL;
  1796. if (intel_sdvo->tv_format_index ==
  1797. intel_sdvo_connector->tv_format_supported[val])
  1798. return 0;
  1799. intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[val];
  1800. goto done;
  1801. } else if (IS_TV_OR_LVDS(intel_sdvo_connector)) {
  1802. temp_value = val;
  1803. if (intel_sdvo_connector->left == property) {
  1804. drm_object_property_set_value(&connector->base,
  1805. intel_sdvo_connector->right, val);
  1806. if (intel_sdvo_connector->left_margin == temp_value)
  1807. return 0;
  1808. intel_sdvo_connector->left_margin = temp_value;
  1809. intel_sdvo_connector->right_margin = temp_value;
  1810. temp_value = intel_sdvo_connector->max_hscan -
  1811. intel_sdvo_connector->left_margin;
  1812. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1813. goto set_value;
  1814. } else if (intel_sdvo_connector->right == property) {
  1815. drm_object_property_set_value(&connector->base,
  1816. intel_sdvo_connector->left, val);
  1817. if (intel_sdvo_connector->right_margin == temp_value)
  1818. return 0;
  1819. intel_sdvo_connector->left_margin = temp_value;
  1820. intel_sdvo_connector->right_margin = temp_value;
  1821. temp_value = intel_sdvo_connector->max_hscan -
  1822. intel_sdvo_connector->left_margin;
  1823. cmd = SDVO_CMD_SET_OVERSCAN_H;
  1824. goto set_value;
  1825. } else if (intel_sdvo_connector->top == property) {
  1826. drm_object_property_set_value(&connector->base,
  1827. intel_sdvo_connector->bottom, val);
  1828. if (intel_sdvo_connector->top_margin == temp_value)
  1829. return 0;
  1830. intel_sdvo_connector->top_margin = temp_value;
  1831. intel_sdvo_connector->bottom_margin = temp_value;
  1832. temp_value = intel_sdvo_connector->max_vscan -
  1833. intel_sdvo_connector->top_margin;
  1834. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1835. goto set_value;
  1836. } else if (intel_sdvo_connector->bottom == property) {
  1837. drm_object_property_set_value(&connector->base,
  1838. intel_sdvo_connector->top, val);
  1839. if (intel_sdvo_connector->bottom_margin == temp_value)
  1840. return 0;
  1841. intel_sdvo_connector->top_margin = temp_value;
  1842. intel_sdvo_connector->bottom_margin = temp_value;
  1843. temp_value = intel_sdvo_connector->max_vscan -
  1844. intel_sdvo_connector->top_margin;
  1845. cmd = SDVO_CMD_SET_OVERSCAN_V;
  1846. goto set_value;
  1847. }
  1848. CHECK_PROPERTY(hpos, HPOS)
  1849. CHECK_PROPERTY(vpos, VPOS)
  1850. CHECK_PROPERTY(saturation, SATURATION)
  1851. CHECK_PROPERTY(contrast, CONTRAST)
  1852. CHECK_PROPERTY(hue, HUE)
  1853. CHECK_PROPERTY(brightness, BRIGHTNESS)
  1854. CHECK_PROPERTY(sharpness, SHARPNESS)
  1855. CHECK_PROPERTY(flicker_filter, FLICKER_FILTER)
  1856. CHECK_PROPERTY(flicker_filter_2d, FLICKER_FILTER_2D)
  1857. CHECK_PROPERTY(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE)
  1858. CHECK_PROPERTY(tv_chroma_filter, TV_CHROMA_FILTER)
  1859. CHECK_PROPERTY(tv_luma_filter, TV_LUMA_FILTER)
  1860. CHECK_PROPERTY(dot_crawl, DOT_CRAWL)
  1861. }
  1862. return -EINVAL; /* unknown property */
  1863. set_value:
  1864. if (!intel_sdvo_set_value(intel_sdvo, cmd, &temp_value, 2))
  1865. return -EIO;
  1866. done:
  1867. if (intel_sdvo->base.base.crtc)
  1868. intel_crtc_restore_mode(intel_sdvo->base.base.crtc);
  1869. return 0;
  1870. #undef CHECK_PROPERTY
  1871. }
  1872. static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
  1873. .dpms = intel_sdvo_dpms,
  1874. .detect = intel_sdvo_detect,
  1875. .fill_modes = drm_helper_probe_single_connector_modes,
  1876. .set_property = intel_sdvo_set_property,
  1877. .destroy = intel_sdvo_destroy,
  1878. };
  1879. static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = {
  1880. .get_modes = intel_sdvo_get_modes,
  1881. .mode_valid = intel_sdvo_mode_valid,
  1882. .best_encoder = intel_best_encoder,
  1883. };
  1884. static void intel_sdvo_enc_destroy(struct drm_encoder *encoder)
  1885. {
  1886. struct intel_sdvo *intel_sdvo = to_sdvo(to_intel_encoder(encoder));
  1887. if (intel_sdvo->sdvo_lvds_fixed_mode != NULL)
  1888. drm_mode_destroy(encoder->dev,
  1889. intel_sdvo->sdvo_lvds_fixed_mode);
  1890. i2c_del_adapter(&intel_sdvo->ddc);
  1891. intel_encoder_destroy(encoder);
  1892. }
  1893. static const struct drm_encoder_funcs intel_sdvo_enc_funcs = {
  1894. .destroy = intel_sdvo_enc_destroy,
  1895. };
  1896. static void
  1897. intel_sdvo_guess_ddc_bus(struct intel_sdvo *sdvo)
  1898. {
  1899. uint16_t mask = 0;
  1900. unsigned int num_bits;
  1901. /* Make a mask of outputs less than or equal to our own priority in the
  1902. * list.
  1903. */
  1904. switch (sdvo->controlled_output) {
  1905. case SDVO_OUTPUT_LVDS1:
  1906. mask |= SDVO_OUTPUT_LVDS1;
  1907. case SDVO_OUTPUT_LVDS0:
  1908. mask |= SDVO_OUTPUT_LVDS0;
  1909. case SDVO_OUTPUT_TMDS1:
  1910. mask |= SDVO_OUTPUT_TMDS1;
  1911. case SDVO_OUTPUT_TMDS0:
  1912. mask |= SDVO_OUTPUT_TMDS0;
  1913. case SDVO_OUTPUT_RGB1:
  1914. mask |= SDVO_OUTPUT_RGB1;
  1915. case SDVO_OUTPUT_RGB0:
  1916. mask |= SDVO_OUTPUT_RGB0;
  1917. break;
  1918. }
  1919. /* Count bits to find what number we are in the priority list. */
  1920. mask &= sdvo->caps.output_flags;
  1921. num_bits = hweight16(mask);
  1922. /* If more than 3 outputs, default to DDC bus 3 for now. */
  1923. if (num_bits > 3)
  1924. num_bits = 3;
  1925. /* Corresponds to SDVO_CONTROL_BUS_DDCx */
  1926. sdvo->ddc_bus = 1 << num_bits;
  1927. }
  1928. /**
  1929. * Choose the appropriate DDC bus for control bus switch command for this
  1930. * SDVO output based on the controlled output.
  1931. *
  1932. * DDC bus number assignment is in a priority order of RGB outputs, then TMDS
  1933. * outputs, then LVDS outputs.
  1934. */
  1935. static void
  1936. intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv,
  1937. struct intel_sdvo *sdvo, u32 reg)
  1938. {
  1939. struct sdvo_device_mapping *mapping;
  1940. if (sdvo->is_sdvob)
  1941. mapping = &(dev_priv->sdvo_mappings[0]);
  1942. else
  1943. mapping = &(dev_priv->sdvo_mappings[1]);
  1944. if (mapping->initialized)
  1945. sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4);
  1946. else
  1947. intel_sdvo_guess_ddc_bus(sdvo);
  1948. }
  1949. static void
  1950. intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
  1951. struct intel_sdvo *sdvo, u32 reg)
  1952. {
  1953. struct sdvo_device_mapping *mapping;
  1954. u8 pin;
  1955. if (sdvo->is_sdvob)
  1956. mapping = &dev_priv->sdvo_mappings[0];
  1957. else
  1958. mapping = &dev_priv->sdvo_mappings[1];
  1959. if (mapping->initialized && intel_gmbus_is_port_valid(mapping->i2c_pin))
  1960. pin = mapping->i2c_pin;
  1961. else
  1962. pin = GMBUS_PORT_DPB;
  1963. sdvo->i2c = intel_gmbus_get_adapter(dev_priv, pin);
  1964. /* With gmbus we should be able to drive sdvo i2c at 2MHz, but somehow
  1965. * our code totally fails once we start using gmbus. Hence fall back to
  1966. * bit banging for now. */
  1967. intel_gmbus_force_bit(sdvo->i2c, true);
  1968. }
  1969. /* undo any changes intel_sdvo_select_i2c_bus() did to sdvo->i2c */
  1970. static void
  1971. intel_sdvo_unselect_i2c_bus(struct intel_sdvo *sdvo)
  1972. {
  1973. intel_gmbus_force_bit(sdvo->i2c, false);
  1974. }
  1975. static bool
  1976. intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)
  1977. {
  1978. return intel_sdvo_check_supp_encode(intel_sdvo);
  1979. }
  1980. static u8
  1981. intel_sdvo_get_slave_addr(struct drm_device *dev, struct intel_sdvo *sdvo)
  1982. {
  1983. struct drm_i915_private *dev_priv = dev->dev_private;
  1984. struct sdvo_device_mapping *my_mapping, *other_mapping;
  1985. if (sdvo->is_sdvob) {
  1986. my_mapping = &dev_priv->sdvo_mappings[0];
  1987. other_mapping = &dev_priv->sdvo_mappings[1];
  1988. } else {
  1989. my_mapping = &dev_priv->sdvo_mappings[1];
  1990. other_mapping = &dev_priv->sdvo_mappings[0];
  1991. }
  1992. /* If the BIOS described our SDVO device, take advantage of it. */
  1993. if (my_mapping->slave_addr)
  1994. return my_mapping->slave_addr;
  1995. /* If the BIOS only described a different SDVO device, use the
  1996. * address that it isn't using.
  1997. */
  1998. if (other_mapping->slave_addr) {
  1999. if (other_mapping->slave_addr == 0x70)
  2000. return 0x72;
  2001. else
  2002. return 0x70;
  2003. }
  2004. /* No SDVO device info is found for another DVO port,
  2005. * so use mapping assumption we had before BIOS parsing.
  2006. */
  2007. if (sdvo->is_sdvob)
  2008. return 0x70;
  2009. else
  2010. return 0x72;
  2011. }
  2012. static void
  2013. intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
  2014. struct intel_sdvo *encoder)
  2015. {
  2016. drm_connector_init(encoder->base.base.dev,
  2017. &connector->base.base,
  2018. &intel_sdvo_connector_funcs,
  2019. connector->base.base.connector_type);
  2020. drm_connector_helper_add(&connector->base.base,
  2021. &intel_sdvo_connector_helper_funcs);
  2022. connector->base.base.interlace_allowed = 1;
  2023. connector->base.base.doublescan_allowed = 0;
  2024. connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
  2025. connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
  2026. intel_connector_attach_encoder(&connector->base, &encoder->base);
  2027. drm_sysfs_connector_add(&connector->base.base);
  2028. }
  2029. static void
  2030. intel_sdvo_add_hdmi_properties(struct intel_sdvo *intel_sdvo,
  2031. struct intel_sdvo_connector *connector)
  2032. {
  2033. struct drm_device *dev = connector->base.base.dev;
  2034. intel_attach_force_audio_property(&connector->base.base);
  2035. if (INTEL_INFO(dev)->gen >= 4 && IS_MOBILE(dev)) {
  2036. intel_attach_broadcast_rgb_property(&connector->base.base);
  2037. intel_sdvo->color_range_auto = true;
  2038. }
  2039. }
  2040. static bool
  2041. intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device)
  2042. {
  2043. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2044. struct drm_connector *connector;
  2045. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2046. struct intel_connector *intel_connector;
  2047. struct intel_sdvo_connector *intel_sdvo_connector;
  2048. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2049. if (!intel_sdvo_connector)
  2050. return false;
  2051. if (device == 0) {
  2052. intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS0;
  2053. intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0;
  2054. } else if (device == 1) {
  2055. intel_sdvo->controlled_output |= SDVO_OUTPUT_TMDS1;
  2056. intel_sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1;
  2057. }
  2058. intel_connector = &intel_sdvo_connector->base;
  2059. connector = &intel_connector->base;
  2060. if (intel_sdvo_get_hotplug_support(intel_sdvo) &
  2061. intel_sdvo_connector->output_flag) {
  2062. intel_sdvo->hotplug_active |= intel_sdvo_connector->output_flag;
  2063. /* Some SDVO devices have one-shot hotplug interrupts.
  2064. * Ensure that they get re-enabled when an interrupt happens.
  2065. */
  2066. intel_encoder->hot_plug = intel_sdvo_enable_hotplug;
  2067. intel_sdvo_enable_hotplug(intel_encoder);
  2068. } else {
  2069. intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
  2070. }
  2071. encoder->encoder_type = DRM_MODE_ENCODER_TMDS;
  2072. connector->connector_type = DRM_MODE_CONNECTOR_DVID;
  2073. if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {
  2074. connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;
  2075. intel_sdvo->is_hdmi = true;
  2076. }
  2077. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2078. if (intel_sdvo->is_hdmi)
  2079. intel_sdvo_add_hdmi_properties(intel_sdvo, intel_sdvo_connector);
  2080. return true;
  2081. }
  2082. static bool
  2083. intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
  2084. {
  2085. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2086. struct drm_connector *connector;
  2087. struct intel_connector *intel_connector;
  2088. struct intel_sdvo_connector *intel_sdvo_connector;
  2089. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2090. if (!intel_sdvo_connector)
  2091. return false;
  2092. intel_connector = &intel_sdvo_connector->base;
  2093. connector = &intel_connector->base;
  2094. encoder->encoder_type = DRM_MODE_ENCODER_TVDAC;
  2095. connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO;
  2096. intel_sdvo->controlled_output |= type;
  2097. intel_sdvo_connector->output_flag = type;
  2098. intel_sdvo->is_tv = true;
  2099. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2100. if (!intel_sdvo_tv_create_property(intel_sdvo, intel_sdvo_connector, type))
  2101. goto err;
  2102. if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
  2103. goto err;
  2104. return true;
  2105. err:
  2106. intel_sdvo_destroy(connector);
  2107. return false;
  2108. }
  2109. static bool
  2110. intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device)
  2111. {
  2112. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2113. struct drm_connector *connector;
  2114. struct intel_connector *intel_connector;
  2115. struct intel_sdvo_connector *intel_sdvo_connector;
  2116. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2117. if (!intel_sdvo_connector)
  2118. return false;
  2119. intel_connector = &intel_sdvo_connector->base;
  2120. connector = &intel_connector->base;
  2121. intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  2122. encoder->encoder_type = DRM_MODE_ENCODER_DAC;
  2123. connector->connector_type = DRM_MODE_CONNECTOR_VGA;
  2124. if (device == 0) {
  2125. intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB0;
  2126. intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB0;
  2127. } else if (device == 1) {
  2128. intel_sdvo->controlled_output |= SDVO_OUTPUT_RGB1;
  2129. intel_sdvo_connector->output_flag = SDVO_OUTPUT_RGB1;
  2130. }
  2131. intel_sdvo_connector_init(intel_sdvo_connector,
  2132. intel_sdvo);
  2133. return true;
  2134. }
  2135. static bool
  2136. intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
  2137. {
  2138. struct drm_encoder *encoder = &intel_sdvo->base.base;
  2139. struct drm_connector *connector;
  2140. struct intel_connector *intel_connector;
  2141. struct intel_sdvo_connector *intel_sdvo_connector;
  2142. intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL);
  2143. if (!intel_sdvo_connector)
  2144. return false;
  2145. intel_connector = &intel_sdvo_connector->base;
  2146. connector = &intel_connector->base;
  2147. encoder->encoder_type = DRM_MODE_ENCODER_LVDS;
  2148. connector->connector_type = DRM_MODE_CONNECTOR_LVDS;
  2149. if (device == 0) {
  2150. intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS0;
  2151. intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0;
  2152. } else if (device == 1) {
  2153. intel_sdvo->controlled_output |= SDVO_OUTPUT_LVDS1;
  2154. intel_sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1;
  2155. }
  2156. intel_sdvo_connector_init(intel_sdvo_connector, intel_sdvo);
  2157. if (!intel_sdvo_create_enhance_property(intel_sdvo, intel_sdvo_connector))
  2158. goto err;
  2159. return true;
  2160. err:
  2161. intel_sdvo_destroy(connector);
  2162. return false;
  2163. }
  2164. static bool
  2165. intel_sdvo_output_setup(struct intel_sdvo *intel_sdvo, uint16_t flags)
  2166. {
  2167. intel_sdvo->is_tv = false;
  2168. intel_sdvo->is_lvds = false;
  2169. /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/
  2170. if (flags & SDVO_OUTPUT_TMDS0)
  2171. if (!intel_sdvo_dvi_init(intel_sdvo, 0))
  2172. return false;
  2173. if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK)
  2174. if (!intel_sdvo_dvi_init(intel_sdvo, 1))
  2175. return false;
  2176. /* TV has no XXX1 function block */
  2177. if (flags & SDVO_OUTPUT_SVID0)
  2178. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_SVID0))
  2179. return false;
  2180. if (flags & SDVO_OUTPUT_CVBS0)
  2181. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_CVBS0))
  2182. return false;
  2183. if (flags & SDVO_OUTPUT_YPRPB0)
  2184. if (!intel_sdvo_tv_init(intel_sdvo, SDVO_OUTPUT_YPRPB0))
  2185. return false;
  2186. if (flags & SDVO_OUTPUT_RGB0)
  2187. if (!intel_sdvo_analog_init(intel_sdvo, 0))
  2188. return false;
  2189. if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK)
  2190. if (!intel_sdvo_analog_init(intel_sdvo, 1))
  2191. return false;
  2192. if (flags & SDVO_OUTPUT_LVDS0)
  2193. if (!intel_sdvo_lvds_init(intel_sdvo, 0))
  2194. return false;
  2195. if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK)
  2196. if (!intel_sdvo_lvds_init(intel_sdvo, 1))
  2197. return false;
  2198. if ((flags & SDVO_OUTPUT_MASK) == 0) {
  2199. unsigned char bytes[2];
  2200. intel_sdvo->controlled_output = 0;
  2201. memcpy(bytes, &intel_sdvo->caps.output_flags, 2);
  2202. DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n",
  2203. SDVO_NAME(intel_sdvo),
  2204. bytes[0], bytes[1]);
  2205. return false;
  2206. }
  2207. intel_sdvo->base.crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2208. return true;
  2209. }
  2210. static void intel_sdvo_output_cleanup(struct intel_sdvo *intel_sdvo)
  2211. {
  2212. struct drm_device *dev = intel_sdvo->base.base.dev;
  2213. struct drm_connector *connector, *tmp;
  2214. list_for_each_entry_safe(connector, tmp,
  2215. &dev->mode_config.connector_list, head) {
  2216. if (intel_attached_encoder(connector) == &intel_sdvo->base)
  2217. intel_sdvo_destroy(connector);
  2218. }
  2219. }
  2220. static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
  2221. struct intel_sdvo_connector *intel_sdvo_connector,
  2222. int type)
  2223. {
  2224. struct drm_device *dev = intel_sdvo->base.base.dev;
  2225. struct intel_sdvo_tv_format format;
  2226. uint32_t format_map, i;
  2227. if (!intel_sdvo_set_target_output(intel_sdvo, type))
  2228. return false;
  2229. BUILD_BUG_ON(sizeof(format) != 6);
  2230. if (!intel_sdvo_get_value(intel_sdvo,
  2231. SDVO_CMD_GET_SUPPORTED_TV_FORMATS,
  2232. &format, sizeof(format)))
  2233. return false;
  2234. memcpy(&format_map, &format, min(sizeof(format_map), sizeof(format)));
  2235. if (format_map == 0)
  2236. return false;
  2237. intel_sdvo_connector->format_supported_num = 0;
  2238. for (i = 0 ; i < TV_FORMAT_NUM; i++)
  2239. if (format_map & (1 << i))
  2240. intel_sdvo_connector->tv_format_supported[intel_sdvo_connector->format_supported_num++] = i;
  2241. intel_sdvo_connector->tv_format =
  2242. drm_property_create(dev, DRM_MODE_PROP_ENUM,
  2243. "mode", intel_sdvo_connector->format_supported_num);
  2244. if (!intel_sdvo_connector->tv_format)
  2245. return false;
  2246. for (i = 0; i < intel_sdvo_connector->format_supported_num; i++)
  2247. drm_property_add_enum(
  2248. intel_sdvo_connector->tv_format, i,
  2249. i, tv_format_names[intel_sdvo_connector->tv_format_supported[i]]);
  2250. intel_sdvo->tv_format_index = intel_sdvo_connector->tv_format_supported[0];
  2251. drm_object_attach_property(&intel_sdvo_connector->base.base.base,
  2252. intel_sdvo_connector->tv_format, 0);
  2253. return true;
  2254. }
  2255. #define ENHANCEMENT(name, NAME) do { \
  2256. if (enhancements.name) { \
  2257. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_MAX_##NAME, &data_value, 4) || \
  2258. !intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_##NAME, &response, 2)) \
  2259. return false; \
  2260. intel_sdvo_connector->max_##name = data_value[0]; \
  2261. intel_sdvo_connector->cur_##name = response; \
  2262. intel_sdvo_connector->name = \
  2263. drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
  2264. if (!intel_sdvo_connector->name) return false; \
  2265. drm_object_attach_property(&connector->base, \
  2266. intel_sdvo_connector->name, \
  2267. intel_sdvo_connector->cur_##name); \
  2268. DRM_DEBUG_KMS(#name ": max %d, default %d, current %d\n", \
  2269. data_value[0], data_value[1], response); \
  2270. } \
  2271. } while (0)
  2272. static bool
  2273. intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
  2274. struct intel_sdvo_connector *intel_sdvo_connector,
  2275. struct intel_sdvo_enhancements_reply enhancements)
  2276. {
  2277. struct drm_device *dev = intel_sdvo->base.base.dev;
  2278. struct drm_connector *connector = &intel_sdvo_connector->base.base;
  2279. uint16_t response, data_value[2];
  2280. /* when horizontal overscan is supported, Add the left/right property */
  2281. if (enhancements.overscan_h) {
  2282. if (!intel_sdvo_get_value(intel_sdvo,
  2283. SDVO_CMD_GET_MAX_OVERSCAN_H,
  2284. &data_value, 4))
  2285. return false;
  2286. if (!intel_sdvo_get_value(intel_sdvo,
  2287. SDVO_CMD_GET_OVERSCAN_H,
  2288. &response, 2))
  2289. return false;
  2290. intel_sdvo_connector->max_hscan = data_value[0];
  2291. intel_sdvo_connector->left_margin = data_value[0] - response;
  2292. intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
  2293. intel_sdvo_connector->left =
  2294. drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
  2295. if (!intel_sdvo_connector->left)
  2296. return false;
  2297. drm_object_attach_property(&connector->base,
  2298. intel_sdvo_connector->left,
  2299. intel_sdvo_connector->left_margin);
  2300. intel_sdvo_connector->right =
  2301. drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
  2302. if (!intel_sdvo_connector->right)
  2303. return false;
  2304. drm_object_attach_property(&connector->base,
  2305. intel_sdvo_connector->right,
  2306. intel_sdvo_connector->right_margin);
  2307. DRM_DEBUG_KMS("h_overscan: max %d, "
  2308. "default %d, current %d\n",
  2309. data_value[0], data_value[1], response);
  2310. }
  2311. if (enhancements.overscan_v) {
  2312. if (!intel_sdvo_get_value(intel_sdvo,
  2313. SDVO_CMD_GET_MAX_OVERSCAN_V,
  2314. &data_value, 4))
  2315. return false;
  2316. if (!intel_sdvo_get_value(intel_sdvo,
  2317. SDVO_CMD_GET_OVERSCAN_V,
  2318. &response, 2))
  2319. return false;
  2320. intel_sdvo_connector->max_vscan = data_value[0];
  2321. intel_sdvo_connector->top_margin = data_value[0] - response;
  2322. intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
  2323. intel_sdvo_connector->top =
  2324. drm_property_create_range(dev, 0,
  2325. "top_margin", 0, data_value[0]);
  2326. if (!intel_sdvo_connector->top)
  2327. return false;
  2328. drm_object_attach_property(&connector->base,
  2329. intel_sdvo_connector->top,
  2330. intel_sdvo_connector->top_margin);
  2331. intel_sdvo_connector->bottom =
  2332. drm_property_create_range(dev, 0,
  2333. "bottom_margin", 0, data_value[0]);
  2334. if (!intel_sdvo_connector->bottom)
  2335. return false;
  2336. drm_object_attach_property(&connector->base,
  2337. intel_sdvo_connector->bottom,
  2338. intel_sdvo_connector->bottom_margin);
  2339. DRM_DEBUG_KMS("v_overscan: max %d, "
  2340. "default %d, current %d\n",
  2341. data_value[0], data_value[1], response);
  2342. }
  2343. ENHANCEMENT(hpos, HPOS);
  2344. ENHANCEMENT(vpos, VPOS);
  2345. ENHANCEMENT(saturation, SATURATION);
  2346. ENHANCEMENT(contrast, CONTRAST);
  2347. ENHANCEMENT(hue, HUE);
  2348. ENHANCEMENT(sharpness, SHARPNESS);
  2349. ENHANCEMENT(brightness, BRIGHTNESS);
  2350. ENHANCEMENT(flicker_filter, FLICKER_FILTER);
  2351. ENHANCEMENT(flicker_filter_adaptive, FLICKER_FILTER_ADAPTIVE);
  2352. ENHANCEMENT(flicker_filter_2d, FLICKER_FILTER_2D);
  2353. ENHANCEMENT(tv_chroma_filter, TV_CHROMA_FILTER);
  2354. ENHANCEMENT(tv_luma_filter, TV_LUMA_FILTER);
  2355. if (enhancements.dot_crawl) {
  2356. if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_DOT_CRAWL, &response, 2))
  2357. return false;
  2358. intel_sdvo_connector->max_dot_crawl = 1;
  2359. intel_sdvo_connector->cur_dot_crawl = response & 0x1;
  2360. intel_sdvo_connector->dot_crawl =
  2361. drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
  2362. if (!intel_sdvo_connector->dot_crawl)
  2363. return false;
  2364. drm_object_attach_property(&connector->base,
  2365. intel_sdvo_connector->dot_crawl,
  2366. intel_sdvo_connector->cur_dot_crawl);
  2367. DRM_DEBUG_KMS("dot crawl: current %d\n", response);
  2368. }
  2369. return true;
  2370. }
  2371. static bool
  2372. intel_sdvo_create_enhance_property_lvds(struct intel_sdvo *intel_sdvo,
  2373. struct intel_sdvo_connector *intel_sdvo_connector,
  2374. struct intel_sdvo_enhancements_reply enhancements)
  2375. {
  2376. struct drm_device *dev = intel_sdvo->base.base.dev;
  2377. struct drm_connector *connector = &intel_sdvo_connector->base.base;
  2378. uint16_t response, data_value[2];
  2379. ENHANCEMENT(brightness, BRIGHTNESS);
  2380. return true;
  2381. }
  2382. #undef ENHANCEMENT
  2383. static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
  2384. struct intel_sdvo_connector *intel_sdvo_connector)
  2385. {
  2386. union {
  2387. struct intel_sdvo_enhancements_reply reply;
  2388. uint16_t response;
  2389. } enhancements;
  2390. BUILD_BUG_ON(sizeof(enhancements) != 2);
  2391. enhancements.response = 0;
  2392. intel_sdvo_get_value(intel_sdvo,
  2393. SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
  2394. &enhancements, sizeof(enhancements));
  2395. if (enhancements.response == 0) {
  2396. DRM_DEBUG_KMS("No enhancement is supported\n");
  2397. return true;
  2398. }
  2399. if (IS_TV(intel_sdvo_connector))
  2400. return intel_sdvo_create_enhance_property_tv(intel_sdvo, intel_sdvo_connector, enhancements.reply);
  2401. else if (IS_LVDS(intel_sdvo_connector))
  2402. return intel_sdvo_create_enhance_property_lvds(intel_sdvo, intel_sdvo_connector, enhancements.reply);
  2403. else
  2404. return true;
  2405. }
  2406. static int intel_sdvo_ddc_proxy_xfer(struct i2c_adapter *adapter,
  2407. struct i2c_msg *msgs,
  2408. int num)
  2409. {
  2410. struct intel_sdvo *sdvo = adapter->algo_data;
  2411. if (!intel_sdvo_set_control_bus_switch(sdvo, sdvo->ddc_bus))
  2412. return -EIO;
  2413. return sdvo->i2c->algo->master_xfer(sdvo->i2c, msgs, num);
  2414. }
  2415. static u32 intel_sdvo_ddc_proxy_func(struct i2c_adapter *adapter)
  2416. {
  2417. struct intel_sdvo *sdvo = adapter->algo_data;
  2418. return sdvo->i2c->algo->functionality(sdvo->i2c);
  2419. }
  2420. static const struct i2c_algorithm intel_sdvo_ddc_proxy = {
  2421. .master_xfer = intel_sdvo_ddc_proxy_xfer,
  2422. .functionality = intel_sdvo_ddc_proxy_func
  2423. };
  2424. static bool
  2425. intel_sdvo_init_ddc_proxy(struct intel_sdvo *sdvo,
  2426. struct drm_device *dev)
  2427. {
  2428. sdvo->ddc.owner = THIS_MODULE;
  2429. sdvo->ddc.class = I2C_CLASS_DDC;
  2430. snprintf(sdvo->ddc.name, I2C_NAME_SIZE, "SDVO DDC proxy");
  2431. sdvo->ddc.dev.parent = &dev->pdev->dev;
  2432. sdvo->ddc.algo_data = sdvo;
  2433. sdvo->ddc.algo = &intel_sdvo_ddc_proxy;
  2434. return i2c_add_adapter(&sdvo->ddc) == 0;
  2435. }
  2436. bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob)
  2437. {
  2438. struct drm_i915_private *dev_priv = dev->dev_private;
  2439. struct intel_encoder *intel_encoder;
  2440. struct intel_sdvo *intel_sdvo;
  2441. int i;
  2442. intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL);
  2443. if (!intel_sdvo)
  2444. return false;
  2445. intel_sdvo->sdvo_reg = sdvo_reg;
  2446. intel_sdvo->is_sdvob = is_sdvob;
  2447. intel_sdvo->slave_addr = intel_sdvo_get_slave_addr(dev, intel_sdvo) >> 1;
  2448. intel_sdvo_select_i2c_bus(dev_priv, intel_sdvo, sdvo_reg);
  2449. if (!intel_sdvo_init_ddc_proxy(intel_sdvo, dev))
  2450. goto err_i2c_bus;
  2451. /* encoder type will be decided later */
  2452. intel_encoder = &intel_sdvo->base;
  2453. intel_encoder->type = INTEL_OUTPUT_SDVO;
  2454. drm_encoder_init(dev, &intel_encoder->base, &intel_sdvo_enc_funcs, 0);
  2455. /* Read the regs to test if we can talk to the device */
  2456. for (i = 0; i < 0x40; i++) {
  2457. u8 byte;
  2458. if (!intel_sdvo_read_byte(intel_sdvo, i, &byte)) {
  2459. DRM_DEBUG_KMS("No SDVO device found on %s\n",
  2460. SDVO_NAME(intel_sdvo));
  2461. goto err;
  2462. }
  2463. }
  2464. intel_encoder->compute_config = intel_sdvo_compute_config;
  2465. intel_encoder->disable = intel_disable_sdvo;
  2466. intel_encoder->mode_set = intel_sdvo_mode_set;
  2467. intel_encoder->enable = intel_enable_sdvo;
  2468. intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
  2469. intel_encoder->get_config = intel_sdvo_get_config;
  2470. /* In default case sdvo lvds is false */
  2471. if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
  2472. goto err;
  2473. if (intel_sdvo_output_setup(intel_sdvo,
  2474. intel_sdvo->caps.output_flags) != true) {
  2475. DRM_DEBUG_KMS("SDVO output failed to setup on %s\n",
  2476. SDVO_NAME(intel_sdvo));
  2477. /* Output_setup can leave behind connectors! */
  2478. goto err_output;
  2479. }
  2480. /* Only enable the hotplug irq if we need it, to work around noisy
  2481. * hotplug lines.
  2482. */
  2483. if (intel_sdvo->hotplug_active) {
  2484. intel_encoder->hpd_pin =
  2485. intel_sdvo->is_sdvob ? HPD_SDVO_B : HPD_SDVO_C;
  2486. }
  2487. /*
  2488. * Cloning SDVO with anything is often impossible, since the SDVO
  2489. * encoder can request a special input timing mode. And even if that's
  2490. * not the case we have evidence that cloning a plain unscaled mode with
  2491. * VGA doesn't really work. Furthermore the cloning flags are way too
  2492. * simplistic anyway to express such constraints, so just give up on
  2493. * cloning for SDVO encoders.
  2494. */
  2495. intel_sdvo->base.cloneable = false;
  2496. intel_sdvo_select_ddc_bus(dev_priv, intel_sdvo, sdvo_reg);
  2497. /* Set the input timing to the screen. Assume always input 0. */
  2498. if (!intel_sdvo_set_target_input(intel_sdvo))
  2499. goto err_output;
  2500. if (!intel_sdvo_get_input_pixel_clock_range(intel_sdvo,
  2501. &intel_sdvo->pixel_clock_min,
  2502. &intel_sdvo->pixel_clock_max))
  2503. goto err_output;
  2504. DRM_DEBUG_KMS("%s device VID/DID: %02X:%02X.%02X, "
  2505. "clock range %dMHz - %dMHz, "
  2506. "input 1: %c, input 2: %c, "
  2507. "output 1: %c, output 2: %c\n",
  2508. SDVO_NAME(intel_sdvo),
  2509. intel_sdvo->caps.vendor_id, intel_sdvo->caps.device_id,
  2510. intel_sdvo->caps.device_rev_id,
  2511. intel_sdvo->pixel_clock_min / 1000,
  2512. intel_sdvo->pixel_clock_max / 1000,
  2513. (intel_sdvo->caps.sdvo_inputs_mask & 0x1) ? 'Y' : 'N',
  2514. (intel_sdvo->caps.sdvo_inputs_mask & 0x2) ? 'Y' : 'N',
  2515. /* check currently supported outputs */
  2516. intel_sdvo->caps.output_flags &
  2517. (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_RGB0) ? 'Y' : 'N',
  2518. intel_sdvo->caps.output_flags &
  2519. (SDVO_OUTPUT_TMDS1 | SDVO_OUTPUT_RGB1) ? 'Y' : 'N');
  2520. return true;
  2521. err_output:
  2522. intel_sdvo_output_cleanup(intel_sdvo);
  2523. err:
  2524. drm_encoder_cleanup(&intel_encoder->base);
  2525. i2c_del_adapter(&intel_sdvo->ddc);
  2526. err_i2c_bus:
  2527. intel_sdvo_unselect_i2c_bus(intel_sdvo);
  2528. kfree(intel_sdvo);
  2529. return false;
  2530. }