intel_sdvo.c 79 KB

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