intel_sdvo.c 78 KB

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