intel_sdvo.c 90 KB

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