intel_sdvo.c 81 KB

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