intel_sdvo.c 80 KB

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