intel_sdvo.c 89 KB

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