intel_sdvo.c 83 KB

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