psb_intel_sdvo.c 82 KB

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