intel_sdvo.c 85 KB

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