intel_display.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/i2c.h>
  27. #include "drmP.h"
  28. #include "intel_drv.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #include "drm_crtc_helper.h"
  32. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  33. typedef struct {
  34. /* given values */
  35. int n;
  36. int m1, m2;
  37. int p1, p2;
  38. /* derived values */
  39. int dot;
  40. int vco;
  41. int m;
  42. int p;
  43. } intel_clock_t;
  44. typedef struct {
  45. int min, max;
  46. } intel_range_t;
  47. typedef struct {
  48. int dot_limit;
  49. int p2_slow, p2_fast;
  50. } intel_p2_t;
  51. #define INTEL_P2_NUM 2
  52. typedef struct intel_limit intel_limit_t;
  53. struct intel_limit {
  54. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  55. intel_p2_t p2;
  56. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  57. int, int, intel_clock_t *);
  58. };
  59. #define I8XX_DOT_MIN 25000
  60. #define I8XX_DOT_MAX 350000
  61. #define I8XX_VCO_MIN 930000
  62. #define I8XX_VCO_MAX 1400000
  63. #define I8XX_N_MIN 3
  64. #define I8XX_N_MAX 16
  65. #define I8XX_M_MIN 96
  66. #define I8XX_M_MAX 140
  67. #define I8XX_M1_MIN 18
  68. #define I8XX_M1_MAX 26
  69. #define I8XX_M2_MIN 6
  70. #define I8XX_M2_MAX 16
  71. #define I8XX_P_MIN 4
  72. #define I8XX_P_MAX 128
  73. #define I8XX_P1_MIN 2
  74. #define I8XX_P1_MAX 33
  75. #define I8XX_P1_LVDS_MIN 1
  76. #define I8XX_P1_LVDS_MAX 6
  77. #define I8XX_P2_SLOW 4
  78. #define I8XX_P2_FAST 2
  79. #define I8XX_P2_LVDS_SLOW 14
  80. #define I8XX_P2_LVDS_FAST 14 /* No fast option */
  81. #define I8XX_P2_SLOW_LIMIT 165000
  82. #define I9XX_DOT_MIN 20000
  83. #define I9XX_DOT_MAX 400000
  84. #define I9XX_VCO_MIN 1400000
  85. #define I9XX_VCO_MAX 2800000
  86. #define IGD_VCO_MIN 1700000
  87. #define IGD_VCO_MAX 3500000
  88. #define I9XX_N_MIN 1
  89. #define I9XX_N_MAX 6
  90. /* IGD's Ncounter is a ring counter */
  91. #define IGD_N_MIN 3
  92. #define IGD_N_MAX 6
  93. #define I9XX_M_MIN 70
  94. #define I9XX_M_MAX 120
  95. #define IGD_M_MIN 2
  96. #define IGD_M_MAX 256
  97. #define I9XX_M1_MIN 10
  98. #define I9XX_M1_MAX 22
  99. #define I9XX_M2_MIN 5
  100. #define I9XX_M2_MAX 9
  101. /* IGD M1 is reserved, and must be 0 */
  102. #define IGD_M1_MIN 0
  103. #define IGD_M1_MAX 0
  104. #define IGD_M2_MIN 0
  105. #define IGD_M2_MAX 254
  106. #define I9XX_P_SDVO_DAC_MIN 5
  107. #define I9XX_P_SDVO_DAC_MAX 80
  108. #define I9XX_P_LVDS_MIN 7
  109. #define I9XX_P_LVDS_MAX 98
  110. #define IGD_P_LVDS_MIN 7
  111. #define IGD_P_LVDS_MAX 112
  112. #define I9XX_P1_MIN 1
  113. #define I9XX_P1_MAX 8
  114. #define I9XX_P2_SDVO_DAC_SLOW 10
  115. #define I9XX_P2_SDVO_DAC_FAST 5
  116. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  117. #define I9XX_P2_LVDS_SLOW 14
  118. #define I9XX_P2_LVDS_FAST 7
  119. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  120. #define INTEL_LIMIT_I8XX_DVO_DAC 0
  121. #define INTEL_LIMIT_I8XX_LVDS 1
  122. #define INTEL_LIMIT_I9XX_SDVO_DAC 2
  123. #define INTEL_LIMIT_I9XX_LVDS 3
  124. #define INTEL_LIMIT_G4X_SDVO 4
  125. #define INTEL_LIMIT_G4X_HDMI_DAC 5
  126. #define INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS 6
  127. #define INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS 7
  128. #define INTEL_LIMIT_IGD_SDVO_DAC 8
  129. #define INTEL_LIMIT_IGD_LVDS 9
  130. /*The parameter is for SDVO on G4x platform*/
  131. #define G4X_DOT_SDVO_MIN 25000
  132. #define G4X_DOT_SDVO_MAX 270000
  133. #define G4X_VCO_MIN 1750000
  134. #define G4X_VCO_MAX 3500000
  135. #define G4X_N_SDVO_MIN 1
  136. #define G4X_N_SDVO_MAX 4
  137. #define G4X_M_SDVO_MIN 104
  138. #define G4X_M_SDVO_MAX 138
  139. #define G4X_M1_SDVO_MIN 17
  140. #define G4X_M1_SDVO_MAX 23
  141. #define G4X_M2_SDVO_MIN 5
  142. #define G4X_M2_SDVO_MAX 11
  143. #define G4X_P_SDVO_MIN 10
  144. #define G4X_P_SDVO_MAX 30
  145. #define G4X_P1_SDVO_MIN 1
  146. #define G4X_P1_SDVO_MAX 3
  147. #define G4X_P2_SDVO_SLOW 10
  148. #define G4X_P2_SDVO_FAST 10
  149. #define G4X_P2_SDVO_LIMIT 270000
  150. /*The parameter is for HDMI_DAC on G4x platform*/
  151. #define G4X_DOT_HDMI_DAC_MIN 22000
  152. #define G4X_DOT_HDMI_DAC_MAX 400000
  153. #define G4X_N_HDMI_DAC_MIN 1
  154. #define G4X_N_HDMI_DAC_MAX 4
  155. #define G4X_M_HDMI_DAC_MIN 104
  156. #define G4X_M_HDMI_DAC_MAX 138
  157. #define G4X_M1_HDMI_DAC_MIN 16
  158. #define G4X_M1_HDMI_DAC_MAX 23
  159. #define G4X_M2_HDMI_DAC_MIN 5
  160. #define G4X_M2_HDMI_DAC_MAX 11
  161. #define G4X_P_HDMI_DAC_MIN 5
  162. #define G4X_P_HDMI_DAC_MAX 80
  163. #define G4X_P1_HDMI_DAC_MIN 1
  164. #define G4X_P1_HDMI_DAC_MAX 8
  165. #define G4X_P2_HDMI_DAC_SLOW 10
  166. #define G4X_P2_HDMI_DAC_FAST 5
  167. #define G4X_P2_HDMI_DAC_LIMIT 165000
  168. /*The parameter is for SINGLE_CHANNEL_LVDS on G4x platform*/
  169. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MIN 20000
  170. #define G4X_DOT_SINGLE_CHANNEL_LVDS_MAX 115000
  171. #define G4X_N_SINGLE_CHANNEL_LVDS_MIN 1
  172. #define G4X_N_SINGLE_CHANNEL_LVDS_MAX 3
  173. #define G4X_M_SINGLE_CHANNEL_LVDS_MIN 104
  174. #define G4X_M_SINGLE_CHANNEL_LVDS_MAX 138
  175. #define G4X_M1_SINGLE_CHANNEL_LVDS_MIN 17
  176. #define G4X_M1_SINGLE_CHANNEL_LVDS_MAX 23
  177. #define G4X_M2_SINGLE_CHANNEL_LVDS_MIN 5
  178. #define G4X_M2_SINGLE_CHANNEL_LVDS_MAX 11
  179. #define G4X_P_SINGLE_CHANNEL_LVDS_MIN 28
  180. #define G4X_P_SINGLE_CHANNEL_LVDS_MAX 112
  181. #define G4X_P1_SINGLE_CHANNEL_LVDS_MIN 2
  182. #define G4X_P1_SINGLE_CHANNEL_LVDS_MAX 8
  183. #define G4X_P2_SINGLE_CHANNEL_LVDS_SLOW 14
  184. #define G4X_P2_SINGLE_CHANNEL_LVDS_FAST 14
  185. #define G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT 0
  186. /*The parameter is for DUAL_CHANNEL_LVDS on G4x platform*/
  187. #define G4X_DOT_DUAL_CHANNEL_LVDS_MIN 80000
  188. #define G4X_DOT_DUAL_CHANNEL_LVDS_MAX 224000
  189. #define G4X_N_DUAL_CHANNEL_LVDS_MIN 1
  190. #define G4X_N_DUAL_CHANNEL_LVDS_MAX 3
  191. #define G4X_M_DUAL_CHANNEL_LVDS_MIN 104
  192. #define G4X_M_DUAL_CHANNEL_LVDS_MAX 138
  193. #define G4X_M1_DUAL_CHANNEL_LVDS_MIN 17
  194. #define G4X_M1_DUAL_CHANNEL_LVDS_MAX 23
  195. #define G4X_M2_DUAL_CHANNEL_LVDS_MIN 5
  196. #define G4X_M2_DUAL_CHANNEL_LVDS_MAX 11
  197. #define G4X_P_DUAL_CHANNEL_LVDS_MIN 14
  198. #define G4X_P_DUAL_CHANNEL_LVDS_MAX 42
  199. #define G4X_P1_DUAL_CHANNEL_LVDS_MIN 2
  200. #define G4X_P1_DUAL_CHANNEL_LVDS_MAX 6
  201. #define G4X_P2_DUAL_CHANNEL_LVDS_SLOW 7
  202. #define G4X_P2_DUAL_CHANNEL_LVDS_FAST 7
  203. #define G4X_P2_DUAL_CHANNEL_LVDS_LIMIT 0
  204. static bool
  205. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  206. int target, int refclk, intel_clock_t *best_clock);
  207. static bool
  208. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  209. int target, int refclk, intel_clock_t *best_clock);
  210. static const intel_limit_t intel_limits[] = {
  211. { /* INTEL_LIMIT_I8XX_DVO_DAC */
  212. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  213. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  214. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  215. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  216. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  217. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  218. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  219. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  220. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  221. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  222. .find_pll = intel_find_best_PLL,
  223. },
  224. { /* INTEL_LIMIT_I8XX_LVDS */
  225. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  226. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  227. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  228. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  229. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  230. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  231. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  232. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  233. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  234. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  235. .find_pll = intel_find_best_PLL,
  236. },
  237. { /* INTEL_LIMIT_I9XX_SDVO_DAC */
  238. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  239. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  240. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  241. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  242. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  243. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  244. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  245. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  246. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  247. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  248. .find_pll = intel_find_best_PLL,
  249. },
  250. { /* INTEL_LIMIT_I9XX_LVDS */
  251. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  252. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  253. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  254. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  255. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  256. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  257. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  258. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  259. /* The single-channel range is 25-112Mhz, and dual-channel
  260. * is 80-224Mhz. Prefer single channel as much as possible.
  261. */
  262. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  263. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  264. .find_pll = intel_find_best_PLL,
  265. },
  266. /* below parameter and function is for G4X Chipset Family*/
  267. { /* INTEL_LIMIT_G4X_SDVO */
  268. .dot = { .min = G4X_DOT_SDVO_MIN, .max = G4X_DOT_SDVO_MAX },
  269. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  270. .n = { .min = G4X_N_SDVO_MIN, .max = G4X_N_SDVO_MAX },
  271. .m = { .min = G4X_M_SDVO_MIN, .max = G4X_M_SDVO_MAX },
  272. .m1 = { .min = G4X_M1_SDVO_MIN, .max = G4X_M1_SDVO_MAX },
  273. .m2 = { .min = G4X_M2_SDVO_MIN, .max = G4X_M2_SDVO_MAX },
  274. .p = { .min = G4X_P_SDVO_MIN, .max = G4X_P_SDVO_MAX },
  275. .p1 = { .min = G4X_P1_SDVO_MIN, .max = G4X_P1_SDVO_MAX},
  276. .p2 = { .dot_limit = G4X_P2_SDVO_LIMIT,
  277. .p2_slow = G4X_P2_SDVO_SLOW,
  278. .p2_fast = G4X_P2_SDVO_FAST
  279. },
  280. .find_pll = intel_g4x_find_best_PLL,
  281. },
  282. { /* INTEL_LIMIT_G4X_HDMI_DAC */
  283. .dot = { .min = G4X_DOT_HDMI_DAC_MIN, .max = G4X_DOT_HDMI_DAC_MAX },
  284. .vco = { .min = G4X_VCO_MIN, .max = G4X_VCO_MAX},
  285. .n = { .min = G4X_N_HDMI_DAC_MIN, .max = G4X_N_HDMI_DAC_MAX },
  286. .m = { .min = G4X_M_HDMI_DAC_MIN, .max = G4X_M_HDMI_DAC_MAX },
  287. .m1 = { .min = G4X_M1_HDMI_DAC_MIN, .max = G4X_M1_HDMI_DAC_MAX },
  288. .m2 = { .min = G4X_M2_HDMI_DAC_MIN, .max = G4X_M2_HDMI_DAC_MAX },
  289. .p = { .min = G4X_P_HDMI_DAC_MIN, .max = G4X_P_HDMI_DAC_MAX },
  290. .p1 = { .min = G4X_P1_HDMI_DAC_MIN, .max = G4X_P1_HDMI_DAC_MAX},
  291. .p2 = { .dot_limit = G4X_P2_HDMI_DAC_LIMIT,
  292. .p2_slow = G4X_P2_HDMI_DAC_SLOW,
  293. .p2_fast = G4X_P2_HDMI_DAC_FAST
  294. },
  295. .find_pll = intel_g4x_find_best_PLL,
  296. },
  297. { /* INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS */
  298. .dot = { .min = G4X_DOT_SINGLE_CHANNEL_LVDS_MIN,
  299. .max = G4X_DOT_SINGLE_CHANNEL_LVDS_MAX },
  300. .vco = { .min = G4X_VCO_MIN,
  301. .max = G4X_VCO_MAX },
  302. .n = { .min = G4X_N_SINGLE_CHANNEL_LVDS_MIN,
  303. .max = G4X_N_SINGLE_CHANNEL_LVDS_MAX },
  304. .m = { .min = G4X_M_SINGLE_CHANNEL_LVDS_MIN,
  305. .max = G4X_M_SINGLE_CHANNEL_LVDS_MAX },
  306. .m1 = { .min = G4X_M1_SINGLE_CHANNEL_LVDS_MIN,
  307. .max = G4X_M1_SINGLE_CHANNEL_LVDS_MAX },
  308. .m2 = { .min = G4X_M2_SINGLE_CHANNEL_LVDS_MIN,
  309. .max = G4X_M2_SINGLE_CHANNEL_LVDS_MAX },
  310. .p = { .min = G4X_P_SINGLE_CHANNEL_LVDS_MIN,
  311. .max = G4X_P_SINGLE_CHANNEL_LVDS_MAX },
  312. .p1 = { .min = G4X_P1_SINGLE_CHANNEL_LVDS_MIN,
  313. .max = G4X_P1_SINGLE_CHANNEL_LVDS_MAX },
  314. .p2 = { .dot_limit = G4X_P2_SINGLE_CHANNEL_LVDS_LIMIT,
  315. .p2_slow = G4X_P2_SINGLE_CHANNEL_LVDS_SLOW,
  316. .p2_fast = G4X_P2_SINGLE_CHANNEL_LVDS_FAST
  317. },
  318. .find_pll = intel_g4x_find_best_PLL,
  319. },
  320. { /* INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS */
  321. .dot = { .min = G4X_DOT_DUAL_CHANNEL_LVDS_MIN,
  322. .max = G4X_DOT_DUAL_CHANNEL_LVDS_MAX },
  323. .vco = { .min = G4X_VCO_MIN,
  324. .max = G4X_VCO_MAX },
  325. .n = { .min = G4X_N_DUAL_CHANNEL_LVDS_MIN,
  326. .max = G4X_N_DUAL_CHANNEL_LVDS_MAX },
  327. .m = { .min = G4X_M_DUAL_CHANNEL_LVDS_MIN,
  328. .max = G4X_M_DUAL_CHANNEL_LVDS_MAX },
  329. .m1 = { .min = G4X_M1_DUAL_CHANNEL_LVDS_MIN,
  330. .max = G4X_M1_DUAL_CHANNEL_LVDS_MAX },
  331. .m2 = { .min = G4X_M2_DUAL_CHANNEL_LVDS_MIN,
  332. .max = G4X_M2_DUAL_CHANNEL_LVDS_MAX },
  333. .p = { .min = G4X_P_DUAL_CHANNEL_LVDS_MIN,
  334. .max = G4X_P_DUAL_CHANNEL_LVDS_MAX },
  335. .p1 = { .min = G4X_P1_DUAL_CHANNEL_LVDS_MIN,
  336. .max = G4X_P1_DUAL_CHANNEL_LVDS_MAX },
  337. .p2 = { .dot_limit = G4X_P2_DUAL_CHANNEL_LVDS_LIMIT,
  338. .p2_slow = G4X_P2_DUAL_CHANNEL_LVDS_SLOW,
  339. .p2_fast = G4X_P2_DUAL_CHANNEL_LVDS_FAST
  340. },
  341. .find_pll = intel_g4x_find_best_PLL,
  342. },
  343. { /* INTEL_LIMIT_IGD_SDVO */
  344. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX},
  345. .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
  346. .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
  347. .m = { .min = IGD_M_MIN, .max = IGD_M_MAX },
  348. .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX },
  349. .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX },
  350. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  351. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  352. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  353. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  354. },
  355. { /* INTEL_LIMIT_IGD_LVDS */
  356. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  357. .vco = { .min = IGD_VCO_MIN, .max = IGD_VCO_MAX },
  358. .n = { .min = IGD_N_MIN, .max = IGD_N_MAX },
  359. .m = { .min = IGD_M_MIN, .max = IGD_M_MAX },
  360. .m1 = { .min = IGD_M1_MIN, .max = IGD_M1_MAX },
  361. .m2 = { .min = IGD_M2_MIN, .max = IGD_M2_MAX },
  362. .p = { .min = IGD_P_LVDS_MIN, .max = IGD_P_LVDS_MAX },
  363. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  364. /* IGD only supports single-channel mode. */
  365. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  366. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_SLOW },
  367. },
  368. };
  369. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  370. {
  371. struct drm_device *dev = crtc->dev;
  372. struct drm_i915_private *dev_priv = dev->dev_private;
  373. const intel_limit_t *limit;
  374. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  375. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  376. LVDS_CLKB_POWER_UP)
  377. /* LVDS with dual channel */
  378. limit = &intel_limits
  379. [INTEL_LIMIT_G4X_DUAL_CHANNEL_LVDS];
  380. else
  381. /* LVDS with dual channel */
  382. limit = &intel_limits
  383. [INTEL_LIMIT_G4X_SINGLE_CHANNEL_LVDS];
  384. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  385. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  386. limit = &intel_limits[INTEL_LIMIT_G4X_HDMI_DAC];
  387. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  388. limit = &intel_limits[INTEL_LIMIT_G4X_SDVO];
  389. } else /* The option is for other outputs */
  390. limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC];
  391. return limit;
  392. }
  393. static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
  394. {
  395. struct drm_device *dev = crtc->dev;
  396. const intel_limit_t *limit;
  397. if (IS_G4X(dev)) {
  398. limit = intel_g4x_limit(crtc);
  399. } else if (IS_I9XX(dev) && !IS_IGD(dev)) {
  400. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  401. limit = &intel_limits[INTEL_LIMIT_I9XX_LVDS];
  402. else
  403. limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC];
  404. } else if (IS_IGD(dev)) {
  405. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  406. limit = &intel_limits[INTEL_LIMIT_IGD_LVDS];
  407. else
  408. limit = &intel_limits[INTEL_LIMIT_IGD_SDVO_DAC];
  409. } else {
  410. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  411. limit = &intel_limits[INTEL_LIMIT_I8XX_LVDS];
  412. else
  413. limit = &intel_limits[INTEL_LIMIT_I8XX_DVO_DAC];
  414. }
  415. return limit;
  416. }
  417. /* m1 is reserved as 0 in IGD, n is a ring counter */
  418. static void igd_clock(int refclk, intel_clock_t *clock)
  419. {
  420. clock->m = clock->m2 + 2;
  421. clock->p = clock->p1 * clock->p2;
  422. clock->vco = refclk * clock->m / clock->n;
  423. clock->dot = clock->vco / clock->p;
  424. }
  425. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  426. {
  427. if (IS_IGD(dev)) {
  428. igd_clock(refclk, clock);
  429. return;
  430. }
  431. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  432. clock->p = clock->p1 * clock->p2;
  433. clock->vco = refclk * clock->m / (clock->n + 2);
  434. clock->dot = clock->vco / clock->p;
  435. }
  436. /**
  437. * Returns whether any output on the specified pipe is of the specified type
  438. */
  439. bool intel_pipe_has_type (struct drm_crtc *crtc, int type)
  440. {
  441. struct drm_device *dev = crtc->dev;
  442. struct drm_mode_config *mode_config = &dev->mode_config;
  443. struct drm_connector *l_entry;
  444. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  445. if (l_entry->encoder &&
  446. l_entry->encoder->crtc == crtc) {
  447. struct intel_output *intel_output = to_intel_output(l_entry);
  448. if (intel_output->type == type)
  449. return true;
  450. }
  451. }
  452. return false;
  453. }
  454. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  455. /**
  456. * Returns whether the given set of divisors are valid for a given refclk with
  457. * the given connectors.
  458. */
  459. static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock)
  460. {
  461. const intel_limit_t *limit = intel_limit (crtc);
  462. struct drm_device *dev = crtc->dev;
  463. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  464. INTELPllInvalid ("p1 out of range\n");
  465. if (clock->p < limit->p.min || limit->p.max < clock->p)
  466. INTELPllInvalid ("p out of range\n");
  467. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  468. INTELPllInvalid ("m2 out of range\n");
  469. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  470. INTELPllInvalid ("m1 out of range\n");
  471. if (clock->m1 <= clock->m2 && !IS_IGD(dev))
  472. INTELPllInvalid ("m1 <= m2\n");
  473. if (clock->m < limit->m.min || limit->m.max < clock->m)
  474. INTELPllInvalid ("m out of range\n");
  475. if (clock->n < limit->n.min || limit->n.max < clock->n)
  476. INTELPllInvalid ("n out of range\n");
  477. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  478. INTELPllInvalid ("vco out of range\n");
  479. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  480. * connector, etc., rather than just a single range.
  481. */
  482. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  483. INTELPllInvalid ("dot out of range\n");
  484. return true;
  485. }
  486. static bool
  487. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  488. int target, int refclk, intel_clock_t *best_clock)
  489. {
  490. struct drm_device *dev = crtc->dev;
  491. struct drm_i915_private *dev_priv = dev->dev_private;
  492. intel_clock_t clock;
  493. int err = target;
  494. if (IS_I9XX(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  495. (I915_READ(LVDS) & LVDS_PORT_EN) != 0) {
  496. /*
  497. * For LVDS, if the panel is on, just rely on its current
  498. * settings for dual-channel. We haven't figured out how to
  499. * reliably set up different single/dual channel state, if we
  500. * even can.
  501. */
  502. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  503. LVDS_CLKB_POWER_UP)
  504. clock.p2 = limit->p2.p2_fast;
  505. else
  506. clock.p2 = limit->p2.p2_slow;
  507. } else {
  508. if (target < limit->p2.dot_limit)
  509. clock.p2 = limit->p2.p2_slow;
  510. else
  511. clock.p2 = limit->p2.p2_fast;
  512. }
  513. memset (best_clock, 0, sizeof (*best_clock));
  514. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  515. for (clock.m2 = limit->m2.min; clock.m2 <= limit->m2.max; clock.m2++) {
  516. /* m1 is always 0 in IGD */
  517. if (clock.m2 >= clock.m1 && !IS_IGD(dev))
  518. break;
  519. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  520. clock.n++) {
  521. for (clock.p1 = limit->p1.min;
  522. clock.p1 <= limit->p1.max; clock.p1++) {
  523. int this_err;
  524. intel_clock(dev, refclk, &clock);
  525. if (!intel_PLL_is_valid(crtc, &clock))
  526. continue;
  527. this_err = abs(clock.dot - target);
  528. if (this_err < err) {
  529. *best_clock = clock;
  530. err = this_err;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. return (err != target);
  537. }
  538. static bool
  539. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  540. int target, int refclk, intel_clock_t *best_clock)
  541. {
  542. struct drm_device *dev = crtc->dev;
  543. struct drm_i915_private *dev_priv = dev->dev_private;
  544. intel_clock_t clock;
  545. int max_n;
  546. bool found;
  547. /* approximately equals target * 0.00488 */
  548. int err_most = (target >> 8) + (target >> 10);
  549. found = false;
  550. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  551. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  552. LVDS_CLKB_POWER_UP)
  553. clock.p2 = limit->p2.p2_fast;
  554. else
  555. clock.p2 = limit->p2.p2_slow;
  556. } else {
  557. if (target < limit->p2.dot_limit)
  558. clock.p2 = limit->p2.p2_slow;
  559. else
  560. clock.p2 = limit->p2.p2_fast;
  561. }
  562. memset(best_clock, 0, sizeof(*best_clock));
  563. max_n = limit->n.max;
  564. /* based on hardware requriment prefer smaller n to precision */
  565. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  566. /* based on hardware requirment prefere larger m1,m2, p1 */
  567. for (clock.m1 = limit->m1.max;
  568. clock.m1 >= limit->m1.min; clock.m1--) {
  569. for (clock.m2 = limit->m2.max;
  570. clock.m2 >= limit->m2.min; clock.m2--) {
  571. for (clock.p1 = limit->p1.max;
  572. clock.p1 >= limit->p1.min; clock.p1--) {
  573. int this_err;
  574. intel_clock(dev, refclk, &clock);
  575. if (!intel_PLL_is_valid(crtc, &clock))
  576. continue;
  577. this_err = abs(clock.dot - target) ;
  578. if (this_err < err_most) {
  579. *best_clock = clock;
  580. err_most = this_err;
  581. max_n = clock.n;
  582. found = true;
  583. }
  584. }
  585. }
  586. }
  587. }
  588. return found;
  589. }
  590. void
  591. intel_wait_for_vblank(struct drm_device *dev)
  592. {
  593. /* Wait for 20ms, i.e. one cycle at 50hz. */
  594. udelay(20000);
  595. }
  596. static int
  597. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  598. struct drm_framebuffer *old_fb)
  599. {
  600. struct drm_device *dev = crtc->dev;
  601. struct drm_i915_private *dev_priv = dev->dev_private;
  602. struct drm_i915_master_private *master_priv;
  603. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  604. struct intel_framebuffer *intel_fb;
  605. struct drm_i915_gem_object *obj_priv;
  606. struct drm_gem_object *obj;
  607. int pipe = intel_crtc->pipe;
  608. unsigned long Start, Offset;
  609. int dspbase = (pipe == 0 ? DSPAADDR : DSPBADDR);
  610. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  611. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  612. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  613. u32 dspcntr, alignment;
  614. int ret;
  615. /* no fb bound */
  616. if (!crtc->fb) {
  617. DRM_DEBUG("No FB bound\n");
  618. return 0;
  619. }
  620. switch (pipe) {
  621. case 0:
  622. case 1:
  623. break;
  624. default:
  625. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  626. return -EINVAL;
  627. }
  628. intel_fb = to_intel_framebuffer(crtc->fb);
  629. obj = intel_fb->obj;
  630. obj_priv = obj->driver_private;
  631. switch (obj_priv->tiling_mode) {
  632. case I915_TILING_NONE:
  633. alignment = 64 * 1024;
  634. break;
  635. case I915_TILING_X:
  636. /* pin() will align the object as required by fence */
  637. alignment = 0;
  638. break;
  639. case I915_TILING_Y:
  640. /* FIXME: Is this true? */
  641. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  642. return -EINVAL;
  643. default:
  644. BUG();
  645. }
  646. mutex_lock(&dev->struct_mutex);
  647. ret = i915_gem_object_pin(intel_fb->obj, alignment);
  648. if (ret != 0) {
  649. mutex_unlock(&dev->struct_mutex);
  650. return ret;
  651. }
  652. ret = i915_gem_object_set_to_gtt_domain(intel_fb->obj, 1);
  653. if (ret != 0) {
  654. i915_gem_object_unpin(intel_fb->obj);
  655. mutex_unlock(&dev->struct_mutex);
  656. return ret;
  657. }
  658. dspcntr = I915_READ(dspcntr_reg);
  659. /* Mask out pixel format bits in case we change it */
  660. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  661. switch (crtc->fb->bits_per_pixel) {
  662. case 8:
  663. dspcntr |= DISPPLANE_8BPP;
  664. break;
  665. case 16:
  666. if (crtc->fb->depth == 15)
  667. dspcntr |= DISPPLANE_15_16BPP;
  668. else
  669. dspcntr |= DISPPLANE_16BPP;
  670. break;
  671. case 24:
  672. case 32:
  673. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  674. break;
  675. default:
  676. DRM_ERROR("Unknown color depth\n");
  677. i915_gem_object_unpin(intel_fb->obj);
  678. mutex_unlock(&dev->struct_mutex);
  679. return -EINVAL;
  680. }
  681. I915_WRITE(dspcntr_reg, dspcntr);
  682. Start = obj_priv->gtt_offset;
  683. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  684. DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  685. I915_WRITE(dspstride, crtc->fb->pitch);
  686. if (IS_I965G(dev)) {
  687. I915_WRITE(dspbase, Offset);
  688. I915_READ(dspbase);
  689. I915_WRITE(dspsurf, Start);
  690. I915_READ(dspsurf);
  691. } else {
  692. I915_WRITE(dspbase, Start + Offset);
  693. I915_READ(dspbase);
  694. }
  695. intel_wait_for_vblank(dev);
  696. if (old_fb) {
  697. intel_fb = to_intel_framebuffer(old_fb);
  698. i915_gem_object_unpin(intel_fb->obj);
  699. }
  700. mutex_unlock(&dev->struct_mutex);
  701. if (!dev->primary->master)
  702. return 0;
  703. master_priv = dev->primary->master->driver_priv;
  704. if (!master_priv->sarea_priv)
  705. return 0;
  706. if (pipe) {
  707. master_priv->sarea_priv->pipeB_x = x;
  708. master_priv->sarea_priv->pipeB_y = y;
  709. } else {
  710. master_priv->sarea_priv->pipeA_x = x;
  711. master_priv->sarea_priv->pipeA_y = y;
  712. }
  713. return 0;
  714. }
  715. /**
  716. * Sets the power management mode of the pipe and plane.
  717. *
  718. * This code should probably grow support for turning the cursor off and back
  719. * on appropriately at the same time as we're turning the pipe off/on.
  720. */
  721. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  722. {
  723. struct drm_device *dev = crtc->dev;
  724. struct drm_i915_master_private *master_priv;
  725. struct drm_i915_private *dev_priv = dev->dev_private;
  726. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  727. int pipe = intel_crtc->pipe;
  728. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  729. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  730. int dspbase_reg = (pipe == 0) ? DSPAADDR : DSPBADDR;
  731. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  732. u32 temp;
  733. bool enabled;
  734. /* XXX: When our outputs are all unaware of DPMS modes other than off
  735. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  736. */
  737. switch (mode) {
  738. case DRM_MODE_DPMS_ON:
  739. case DRM_MODE_DPMS_STANDBY:
  740. case DRM_MODE_DPMS_SUSPEND:
  741. /* Enable the DPLL */
  742. temp = I915_READ(dpll_reg);
  743. if ((temp & DPLL_VCO_ENABLE) == 0) {
  744. I915_WRITE(dpll_reg, temp);
  745. I915_READ(dpll_reg);
  746. /* Wait for the clocks to stabilize. */
  747. udelay(150);
  748. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  749. I915_READ(dpll_reg);
  750. /* Wait for the clocks to stabilize. */
  751. udelay(150);
  752. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  753. I915_READ(dpll_reg);
  754. /* Wait for the clocks to stabilize. */
  755. udelay(150);
  756. }
  757. /* Enable the pipe */
  758. temp = I915_READ(pipeconf_reg);
  759. if ((temp & PIPEACONF_ENABLE) == 0)
  760. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  761. /* Enable the plane */
  762. temp = I915_READ(dspcntr_reg);
  763. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  764. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  765. /* Flush the plane changes */
  766. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  767. }
  768. intel_crtc_load_lut(crtc);
  769. /* Give the overlay scaler a chance to enable if it's on this pipe */
  770. //intel_crtc_dpms_video(crtc, true); TODO
  771. break;
  772. case DRM_MODE_DPMS_OFF:
  773. /* Give the overlay scaler a chance to disable if it's on this pipe */
  774. //intel_crtc_dpms_video(crtc, FALSE); TODO
  775. /* Disable the VGA plane that we never use */
  776. I915_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  777. /* Disable display plane */
  778. temp = I915_READ(dspcntr_reg);
  779. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  780. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  781. /* Flush the plane changes */
  782. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  783. I915_READ(dspbase_reg);
  784. }
  785. if (!IS_I9XX(dev)) {
  786. /* Wait for vblank for the disable to take effect */
  787. intel_wait_for_vblank(dev);
  788. }
  789. /* Next, disable display pipes */
  790. temp = I915_READ(pipeconf_reg);
  791. if ((temp & PIPEACONF_ENABLE) != 0) {
  792. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  793. I915_READ(pipeconf_reg);
  794. }
  795. /* Wait for vblank for the disable to take effect. */
  796. intel_wait_for_vblank(dev);
  797. temp = I915_READ(dpll_reg);
  798. if ((temp & DPLL_VCO_ENABLE) != 0) {
  799. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  800. I915_READ(dpll_reg);
  801. }
  802. /* Wait for the clocks to turn off. */
  803. udelay(150);
  804. break;
  805. }
  806. if (!dev->primary->master)
  807. return;
  808. master_priv = dev->primary->master->driver_priv;
  809. if (!master_priv->sarea_priv)
  810. return;
  811. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  812. switch (pipe) {
  813. case 0:
  814. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  815. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  816. break;
  817. case 1:
  818. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  819. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  820. break;
  821. default:
  822. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  823. break;
  824. }
  825. intel_crtc->dpms_mode = mode;
  826. }
  827. static void intel_crtc_prepare (struct drm_crtc *crtc)
  828. {
  829. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  830. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  831. }
  832. static void intel_crtc_commit (struct drm_crtc *crtc)
  833. {
  834. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  835. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  836. }
  837. void intel_encoder_prepare (struct drm_encoder *encoder)
  838. {
  839. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  840. /* lvds has its own version of prepare see intel_lvds_prepare */
  841. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  842. }
  843. void intel_encoder_commit (struct drm_encoder *encoder)
  844. {
  845. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  846. /* lvds has its own version of commit see intel_lvds_commit */
  847. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  848. }
  849. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  850. struct drm_display_mode *mode,
  851. struct drm_display_mode *adjusted_mode)
  852. {
  853. return true;
  854. }
  855. /** Returns the core display clock speed for i830 - i945 */
  856. static int intel_get_core_clock_speed(struct drm_device *dev)
  857. {
  858. /* Core clock values taken from the published datasheets.
  859. * The 830 may go up to 166 Mhz, which we should check.
  860. */
  861. if (IS_I945G(dev))
  862. return 400000;
  863. else if (IS_I915G(dev))
  864. return 333000;
  865. else if (IS_I945GM(dev) || IS_845G(dev) || IS_IGDGM(dev))
  866. return 200000;
  867. else if (IS_I915GM(dev)) {
  868. u16 gcfgc = 0;
  869. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  870. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  871. return 133000;
  872. else {
  873. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  874. case GC_DISPLAY_CLOCK_333_MHZ:
  875. return 333000;
  876. default:
  877. case GC_DISPLAY_CLOCK_190_200_MHZ:
  878. return 190000;
  879. }
  880. }
  881. } else if (IS_I865G(dev))
  882. return 266000;
  883. else if (IS_I855(dev)) {
  884. u16 hpllcc = 0;
  885. /* Assume that the hardware is in the high speed state. This
  886. * should be the default.
  887. */
  888. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  889. case GC_CLOCK_133_200:
  890. case GC_CLOCK_100_200:
  891. return 200000;
  892. case GC_CLOCK_166_250:
  893. return 250000;
  894. case GC_CLOCK_100_133:
  895. return 133000;
  896. }
  897. } else /* 852, 830 */
  898. return 133000;
  899. return 0; /* Silence gcc warning */
  900. }
  901. /**
  902. * Return the pipe currently connected to the panel fitter,
  903. * or -1 if the panel fitter is not present or not in use
  904. */
  905. static int intel_panel_fitter_pipe (struct drm_device *dev)
  906. {
  907. struct drm_i915_private *dev_priv = dev->dev_private;
  908. u32 pfit_control;
  909. /* i830 doesn't have a panel fitter */
  910. if (IS_I830(dev))
  911. return -1;
  912. pfit_control = I915_READ(PFIT_CONTROL);
  913. /* See if the panel fitter is in use */
  914. if ((pfit_control & PFIT_ENABLE) == 0)
  915. return -1;
  916. /* 965 can place panel fitter on either pipe */
  917. if (IS_I965G(dev))
  918. return (pfit_control >> 29) & 0x3;
  919. /* older chips can only use pipe 1 */
  920. return 1;
  921. }
  922. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  923. struct drm_display_mode *mode,
  924. struct drm_display_mode *adjusted_mode,
  925. int x, int y,
  926. struct drm_framebuffer *old_fb)
  927. {
  928. struct drm_device *dev = crtc->dev;
  929. struct drm_i915_private *dev_priv = dev->dev_private;
  930. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  931. int pipe = intel_crtc->pipe;
  932. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  933. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  934. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  935. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  936. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  937. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  938. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  939. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  940. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  941. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  942. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  943. int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
  944. int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
  945. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  946. int refclk, num_outputs = 0;
  947. intel_clock_t clock;
  948. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  949. bool ok, is_sdvo = false, is_dvo = false;
  950. bool is_crt = false, is_lvds = false, is_tv = false;
  951. struct drm_mode_config *mode_config = &dev->mode_config;
  952. struct drm_connector *connector;
  953. const intel_limit_t *limit;
  954. int ret;
  955. drm_vblank_pre_modeset(dev, pipe);
  956. list_for_each_entry(connector, &mode_config->connector_list, head) {
  957. struct intel_output *intel_output = to_intel_output(connector);
  958. if (!connector->encoder || connector->encoder->crtc != crtc)
  959. continue;
  960. switch (intel_output->type) {
  961. case INTEL_OUTPUT_LVDS:
  962. is_lvds = true;
  963. break;
  964. case INTEL_OUTPUT_SDVO:
  965. case INTEL_OUTPUT_HDMI:
  966. is_sdvo = true;
  967. if (intel_output->needs_tv_clock)
  968. is_tv = true;
  969. break;
  970. case INTEL_OUTPUT_DVO:
  971. is_dvo = true;
  972. break;
  973. case INTEL_OUTPUT_TVOUT:
  974. is_tv = true;
  975. break;
  976. case INTEL_OUTPUT_ANALOG:
  977. is_crt = true;
  978. break;
  979. }
  980. num_outputs++;
  981. }
  982. if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) {
  983. refclk = dev_priv->lvds_ssc_freq * 1000;
  984. DRM_DEBUG("using SSC reference clock of %d MHz\n", refclk / 1000);
  985. } else if (IS_I9XX(dev)) {
  986. refclk = 96000;
  987. } else {
  988. refclk = 48000;
  989. }
  990. /*
  991. * Returns a set of divisors for the desired target clock with the given
  992. * refclk, or FALSE. The returned values represent the clock equation:
  993. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  994. */
  995. limit = intel_limit(crtc);
  996. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  997. if (!ok) {
  998. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  999. return -EINVAL;
  1000. }
  1001. if (IS_IGD(dev))
  1002. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  1003. else
  1004. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  1005. dpll = DPLL_VGA_MODE_DIS;
  1006. if (IS_I9XX(dev)) {
  1007. if (is_lvds)
  1008. dpll |= DPLLB_MODE_LVDS;
  1009. else
  1010. dpll |= DPLLB_MODE_DAC_SERIAL;
  1011. if (is_sdvo) {
  1012. dpll |= DPLL_DVO_HIGH_SPEED;
  1013. if (IS_I945G(dev) || IS_I945GM(dev)) {
  1014. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  1015. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  1016. }
  1017. }
  1018. /* compute bitmask from p1 value */
  1019. if (IS_IGD(dev))
  1020. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_IGD;
  1021. else
  1022. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  1023. switch (clock.p2) {
  1024. case 5:
  1025. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  1026. break;
  1027. case 7:
  1028. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  1029. break;
  1030. case 10:
  1031. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  1032. break;
  1033. case 14:
  1034. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  1035. break;
  1036. }
  1037. if (IS_I965G(dev))
  1038. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  1039. } else {
  1040. if (is_lvds) {
  1041. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  1042. } else {
  1043. if (clock.p1 == 2)
  1044. dpll |= PLL_P1_DIVIDE_BY_TWO;
  1045. else
  1046. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  1047. if (clock.p2 == 4)
  1048. dpll |= PLL_P2_DIVIDE_BY_4;
  1049. }
  1050. }
  1051. if (is_sdvo && is_tv)
  1052. dpll |= PLL_REF_INPUT_TVCLKINBC;
  1053. else if (is_tv)
  1054. /* XXX: just matching BIOS for now */
  1055. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  1056. dpll |= 3;
  1057. else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2)
  1058. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  1059. else
  1060. dpll |= PLL_REF_INPUT_DREFCLK;
  1061. /* setup pipeconf */
  1062. pipeconf = I915_READ(pipeconf_reg);
  1063. /* Set up the display plane register */
  1064. dspcntr = DISPPLANE_GAMMA_ENABLE;
  1065. if (pipe == 0)
  1066. dspcntr |= DISPPLANE_SEL_PIPE_A;
  1067. else
  1068. dspcntr |= DISPPLANE_SEL_PIPE_B;
  1069. if (pipe == 0 && !IS_I965G(dev)) {
  1070. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  1071. * core speed.
  1072. *
  1073. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  1074. * pipe == 0 check?
  1075. */
  1076. if (mode->clock > intel_get_core_clock_speed(dev) * 9 / 10)
  1077. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  1078. else
  1079. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  1080. }
  1081. dspcntr |= DISPLAY_PLANE_ENABLE;
  1082. pipeconf |= PIPEACONF_ENABLE;
  1083. dpll |= DPLL_VCO_ENABLE;
  1084. /* Disable the panel fitter if it was on our pipe */
  1085. if (intel_panel_fitter_pipe(dev) == pipe)
  1086. I915_WRITE(PFIT_CONTROL, 0);
  1087. DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  1088. drm_mode_debug_printmodeline(mode);
  1089. if (dpll & DPLL_VCO_ENABLE) {
  1090. I915_WRITE(fp_reg, fp);
  1091. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  1092. I915_READ(dpll_reg);
  1093. udelay(150);
  1094. }
  1095. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  1096. * This is an exception to the general rule that mode_set doesn't turn
  1097. * things on.
  1098. */
  1099. if (is_lvds) {
  1100. u32 lvds = I915_READ(LVDS);
  1101. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT;
  1102. /* Set the B0-B3 data pairs corresponding to whether we're going to
  1103. * set the DPLLs for dual-channel mode or not.
  1104. */
  1105. if (clock.p2 == 7)
  1106. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  1107. else
  1108. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  1109. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  1110. * appropriately here, but we need to look more thoroughly into how
  1111. * panels behave in the two modes.
  1112. */
  1113. I915_WRITE(LVDS, lvds);
  1114. I915_READ(LVDS);
  1115. }
  1116. I915_WRITE(fp_reg, fp);
  1117. I915_WRITE(dpll_reg, dpll);
  1118. I915_READ(dpll_reg);
  1119. /* Wait for the clocks to stabilize. */
  1120. udelay(150);
  1121. if (IS_I965G(dev)) {
  1122. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  1123. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  1124. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  1125. } else {
  1126. /* write it again -- the BIOS does, after all */
  1127. I915_WRITE(dpll_reg, dpll);
  1128. }
  1129. I915_READ(dpll_reg);
  1130. /* Wait for the clocks to stabilize. */
  1131. udelay(150);
  1132. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  1133. ((adjusted_mode->crtc_htotal - 1) << 16));
  1134. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  1135. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  1136. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  1137. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  1138. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  1139. ((adjusted_mode->crtc_vtotal - 1) << 16));
  1140. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  1141. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  1142. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  1143. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  1144. /* pipesrc and dspsize control the size that is scaled from, which should
  1145. * always be the user's requested size.
  1146. */
  1147. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  1148. I915_WRITE(dsppos_reg, 0);
  1149. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  1150. I915_WRITE(pipeconf_reg, pipeconf);
  1151. I915_READ(pipeconf_reg);
  1152. intel_wait_for_vblank(dev);
  1153. I915_WRITE(dspcntr_reg, dspcntr);
  1154. /* Flush the plane changes */
  1155. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  1156. if (ret != 0)
  1157. return ret;
  1158. drm_vblank_post_modeset(dev, pipe);
  1159. return 0;
  1160. }
  1161. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  1162. void intel_crtc_load_lut(struct drm_crtc *crtc)
  1163. {
  1164. struct drm_device *dev = crtc->dev;
  1165. struct drm_i915_private *dev_priv = dev->dev_private;
  1166. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1167. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  1168. int i;
  1169. /* The clocks have to be on to load the palette. */
  1170. if (!crtc->enabled)
  1171. return;
  1172. for (i = 0; i < 256; i++) {
  1173. I915_WRITE(palreg + 4 * i,
  1174. (intel_crtc->lut_r[i] << 16) |
  1175. (intel_crtc->lut_g[i] << 8) |
  1176. intel_crtc->lut_b[i]);
  1177. }
  1178. }
  1179. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  1180. struct drm_file *file_priv,
  1181. uint32_t handle,
  1182. uint32_t width, uint32_t height)
  1183. {
  1184. struct drm_device *dev = crtc->dev;
  1185. struct drm_i915_private *dev_priv = dev->dev_private;
  1186. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1187. struct drm_gem_object *bo;
  1188. struct drm_i915_gem_object *obj_priv;
  1189. int pipe = intel_crtc->pipe;
  1190. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  1191. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  1192. uint32_t temp;
  1193. size_t addr;
  1194. int ret;
  1195. DRM_DEBUG("\n");
  1196. /* if we want to turn off the cursor ignore width and height */
  1197. if (!handle) {
  1198. DRM_DEBUG("cursor off\n");
  1199. temp = CURSOR_MODE_DISABLE;
  1200. addr = 0;
  1201. bo = NULL;
  1202. mutex_lock(&dev->struct_mutex);
  1203. goto finish;
  1204. }
  1205. /* Currently we only support 64x64 cursors */
  1206. if (width != 64 || height != 64) {
  1207. DRM_ERROR("we currently only support 64x64 cursors\n");
  1208. return -EINVAL;
  1209. }
  1210. bo = drm_gem_object_lookup(dev, file_priv, handle);
  1211. if (!bo)
  1212. return -ENOENT;
  1213. obj_priv = bo->driver_private;
  1214. if (bo->size < width * height * 4) {
  1215. DRM_ERROR("buffer is to small\n");
  1216. ret = -ENOMEM;
  1217. goto fail;
  1218. }
  1219. /* we only need to pin inside GTT if cursor is non-phy */
  1220. mutex_lock(&dev->struct_mutex);
  1221. if (!dev_priv->cursor_needs_physical) {
  1222. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  1223. if (ret) {
  1224. DRM_ERROR("failed to pin cursor bo\n");
  1225. goto fail_locked;
  1226. }
  1227. addr = obj_priv->gtt_offset;
  1228. } else {
  1229. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  1230. if (ret) {
  1231. DRM_ERROR("failed to attach phys object\n");
  1232. goto fail_locked;
  1233. }
  1234. addr = obj_priv->phys_obj->handle->busaddr;
  1235. }
  1236. temp = 0;
  1237. /* set the pipe for the cursor */
  1238. temp |= (pipe << 28);
  1239. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  1240. finish:
  1241. I915_WRITE(control, temp);
  1242. I915_WRITE(base, addr);
  1243. if (intel_crtc->cursor_bo) {
  1244. if (dev_priv->cursor_needs_physical) {
  1245. if (intel_crtc->cursor_bo != bo)
  1246. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  1247. } else
  1248. i915_gem_object_unpin(intel_crtc->cursor_bo);
  1249. drm_gem_object_unreference(intel_crtc->cursor_bo);
  1250. }
  1251. mutex_unlock(&dev->struct_mutex);
  1252. intel_crtc->cursor_addr = addr;
  1253. intel_crtc->cursor_bo = bo;
  1254. return 0;
  1255. fail:
  1256. mutex_lock(&dev->struct_mutex);
  1257. fail_locked:
  1258. drm_gem_object_unreference(bo);
  1259. mutex_unlock(&dev->struct_mutex);
  1260. return ret;
  1261. }
  1262. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  1263. {
  1264. struct drm_device *dev = crtc->dev;
  1265. struct drm_i915_private *dev_priv = dev->dev_private;
  1266. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1267. int pipe = intel_crtc->pipe;
  1268. uint32_t temp = 0;
  1269. uint32_t adder;
  1270. if (x < 0) {
  1271. temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
  1272. x = -x;
  1273. }
  1274. if (y < 0) {
  1275. temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
  1276. y = -y;
  1277. }
  1278. temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
  1279. temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
  1280. adder = intel_crtc->cursor_addr;
  1281. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  1282. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  1283. return 0;
  1284. }
  1285. /** Sets the color ramps on behalf of RandR */
  1286. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  1287. u16 blue, int regno)
  1288. {
  1289. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1290. intel_crtc->lut_r[regno] = red >> 8;
  1291. intel_crtc->lut_g[regno] = green >> 8;
  1292. intel_crtc->lut_b[regno] = blue >> 8;
  1293. }
  1294. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  1295. u16 *blue, uint32_t size)
  1296. {
  1297. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1298. int i;
  1299. if (size != 256)
  1300. return;
  1301. for (i = 0; i < 256; i++) {
  1302. intel_crtc->lut_r[i] = red[i] >> 8;
  1303. intel_crtc->lut_g[i] = green[i] >> 8;
  1304. intel_crtc->lut_b[i] = blue[i] >> 8;
  1305. }
  1306. intel_crtc_load_lut(crtc);
  1307. }
  1308. /**
  1309. * Get a pipe with a simple mode set on it for doing load-based monitor
  1310. * detection.
  1311. *
  1312. * It will be up to the load-detect code to adjust the pipe as appropriate for
  1313. * its requirements. The pipe will be connected to no other outputs.
  1314. *
  1315. * Currently this code will only succeed if there is a pipe with no outputs
  1316. * configured for it. In the future, it could choose to temporarily disable
  1317. * some outputs to free up a pipe for its use.
  1318. *
  1319. * \return crtc, or NULL if no pipes are available.
  1320. */
  1321. /* VESA 640x480x72Hz mode to set on the pipe */
  1322. static struct drm_display_mode load_detect_mode = {
  1323. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  1324. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  1325. };
  1326. struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
  1327. struct drm_display_mode *mode,
  1328. int *dpms_mode)
  1329. {
  1330. struct intel_crtc *intel_crtc;
  1331. struct drm_crtc *possible_crtc;
  1332. struct drm_crtc *supported_crtc =NULL;
  1333. struct drm_encoder *encoder = &intel_output->enc;
  1334. struct drm_crtc *crtc = NULL;
  1335. struct drm_device *dev = encoder->dev;
  1336. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1337. struct drm_crtc_helper_funcs *crtc_funcs;
  1338. int i = -1;
  1339. /*
  1340. * Algorithm gets a little messy:
  1341. * - if the connector already has an assigned crtc, use it (but make
  1342. * sure it's on first)
  1343. * - try to find the first unused crtc that can drive this connector,
  1344. * and use that if we find one
  1345. * - if there are no unused crtcs available, try to use the first
  1346. * one we found that supports the connector
  1347. */
  1348. /* See if we already have a CRTC for this connector */
  1349. if (encoder->crtc) {
  1350. crtc = encoder->crtc;
  1351. /* Make sure the crtc and connector are running */
  1352. intel_crtc = to_intel_crtc(crtc);
  1353. *dpms_mode = intel_crtc->dpms_mode;
  1354. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1355. crtc_funcs = crtc->helper_private;
  1356. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1357. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  1358. }
  1359. return crtc;
  1360. }
  1361. /* Find an unused one (if possible) */
  1362. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  1363. i++;
  1364. if (!(encoder->possible_crtcs & (1 << i)))
  1365. continue;
  1366. if (!possible_crtc->enabled) {
  1367. crtc = possible_crtc;
  1368. break;
  1369. }
  1370. if (!supported_crtc)
  1371. supported_crtc = possible_crtc;
  1372. }
  1373. /*
  1374. * If we didn't find an unused CRTC, don't use any.
  1375. */
  1376. if (!crtc) {
  1377. return NULL;
  1378. }
  1379. encoder->crtc = crtc;
  1380. intel_output->load_detect_temp = true;
  1381. intel_crtc = to_intel_crtc(crtc);
  1382. *dpms_mode = intel_crtc->dpms_mode;
  1383. if (!crtc->enabled) {
  1384. if (!mode)
  1385. mode = &load_detect_mode;
  1386. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  1387. } else {
  1388. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1389. crtc_funcs = crtc->helper_private;
  1390. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1391. }
  1392. /* Add this connector to the crtc */
  1393. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  1394. encoder_funcs->commit(encoder);
  1395. }
  1396. /* let the connector get through one full cycle before testing */
  1397. intel_wait_for_vblank(dev);
  1398. return crtc;
  1399. }
  1400. void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode)
  1401. {
  1402. struct drm_encoder *encoder = &intel_output->enc;
  1403. struct drm_device *dev = encoder->dev;
  1404. struct drm_crtc *crtc = encoder->crtc;
  1405. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1406. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1407. if (intel_output->load_detect_temp) {
  1408. encoder->crtc = NULL;
  1409. intel_output->load_detect_temp = false;
  1410. crtc->enabled = drm_helper_crtc_in_use(crtc);
  1411. drm_helper_disable_unused_functions(dev);
  1412. }
  1413. /* Switch crtc and output back off if necessary */
  1414. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  1415. if (encoder->crtc == crtc)
  1416. encoder_funcs->dpms(encoder, dpms_mode);
  1417. crtc_funcs->dpms(crtc, dpms_mode);
  1418. }
  1419. }
  1420. /* Returns the clock of the currently programmed mode of the given pipe. */
  1421. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  1422. {
  1423. struct drm_i915_private *dev_priv = dev->dev_private;
  1424. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1425. int pipe = intel_crtc->pipe;
  1426. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  1427. u32 fp;
  1428. intel_clock_t clock;
  1429. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  1430. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  1431. else
  1432. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  1433. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  1434. if (IS_IGD(dev)) {
  1435. clock.n = ffs((fp & FP_N_IGD_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  1436. clock.m2 = (fp & FP_M2_IGD_DIV_MASK) >> FP_M2_DIV_SHIFT;
  1437. } else {
  1438. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  1439. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  1440. }
  1441. if (IS_I9XX(dev)) {
  1442. if (IS_IGD(dev))
  1443. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_IGD) >>
  1444. DPLL_FPA01_P1_POST_DIV_SHIFT_IGD);
  1445. else
  1446. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  1447. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1448. switch (dpll & DPLL_MODE_MASK) {
  1449. case DPLLB_MODE_DAC_SERIAL:
  1450. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  1451. 5 : 10;
  1452. break;
  1453. case DPLLB_MODE_LVDS:
  1454. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  1455. 7 : 14;
  1456. break;
  1457. default:
  1458. DRM_DEBUG("Unknown DPLL mode %08x in programmed "
  1459. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  1460. return 0;
  1461. }
  1462. /* XXX: Handle the 100Mhz refclk */
  1463. intel_clock(dev, 96000, &clock);
  1464. } else {
  1465. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  1466. if (is_lvds) {
  1467. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  1468. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1469. clock.p2 = 14;
  1470. if ((dpll & PLL_REF_INPUT_MASK) ==
  1471. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  1472. /* XXX: might not be 66MHz */
  1473. intel_clock(dev, 66000, &clock);
  1474. } else
  1475. intel_clock(dev, 48000, &clock);
  1476. } else {
  1477. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  1478. clock.p1 = 2;
  1479. else {
  1480. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  1481. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  1482. }
  1483. if (dpll & PLL_P2_DIVIDE_BY_4)
  1484. clock.p2 = 4;
  1485. else
  1486. clock.p2 = 2;
  1487. intel_clock(dev, 48000, &clock);
  1488. }
  1489. }
  1490. /* XXX: It would be nice to validate the clocks, but we can't reuse
  1491. * i830PllIsValid() because it relies on the xf86_config connector
  1492. * configuration being accurate, which it isn't necessarily.
  1493. */
  1494. return clock.dot;
  1495. }
  1496. /** Returns the currently programmed mode of the given pipe. */
  1497. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  1498. struct drm_crtc *crtc)
  1499. {
  1500. struct drm_i915_private *dev_priv = dev->dev_private;
  1501. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1502. int pipe = intel_crtc->pipe;
  1503. struct drm_display_mode *mode;
  1504. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  1505. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  1506. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  1507. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  1508. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  1509. if (!mode)
  1510. return NULL;
  1511. mode->clock = intel_crtc_clock_get(dev, crtc);
  1512. mode->hdisplay = (htot & 0xffff) + 1;
  1513. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  1514. mode->hsync_start = (hsync & 0xffff) + 1;
  1515. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  1516. mode->vdisplay = (vtot & 0xffff) + 1;
  1517. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  1518. mode->vsync_start = (vsync & 0xffff) + 1;
  1519. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  1520. drm_mode_set_name(mode);
  1521. drm_mode_set_crtcinfo(mode, 0);
  1522. return mode;
  1523. }
  1524. static void intel_crtc_destroy(struct drm_crtc *crtc)
  1525. {
  1526. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1527. drm_crtc_cleanup(crtc);
  1528. kfree(intel_crtc);
  1529. }
  1530. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  1531. .dpms = intel_crtc_dpms,
  1532. .mode_fixup = intel_crtc_mode_fixup,
  1533. .mode_set = intel_crtc_mode_set,
  1534. .mode_set_base = intel_pipe_set_base,
  1535. .prepare = intel_crtc_prepare,
  1536. .commit = intel_crtc_commit,
  1537. };
  1538. static const struct drm_crtc_funcs intel_crtc_funcs = {
  1539. .cursor_set = intel_crtc_cursor_set,
  1540. .cursor_move = intel_crtc_cursor_move,
  1541. .gamma_set = intel_crtc_gamma_set,
  1542. .set_config = drm_crtc_helper_set_config,
  1543. .destroy = intel_crtc_destroy,
  1544. };
  1545. static void intel_crtc_init(struct drm_device *dev, int pipe)
  1546. {
  1547. struct intel_crtc *intel_crtc;
  1548. int i;
  1549. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  1550. if (intel_crtc == NULL)
  1551. return;
  1552. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  1553. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  1554. intel_crtc->pipe = pipe;
  1555. for (i = 0; i < 256; i++) {
  1556. intel_crtc->lut_r[i] = i;
  1557. intel_crtc->lut_g[i] = i;
  1558. intel_crtc->lut_b[i] = i;
  1559. }
  1560. intel_crtc->cursor_addr = 0;
  1561. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  1562. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  1563. intel_crtc->mode_set.crtc = &intel_crtc->base;
  1564. intel_crtc->mode_set.connectors = (struct drm_connector **)(intel_crtc + 1);
  1565. intel_crtc->mode_set.num_connectors = 0;
  1566. if (i915_fbpercrtc) {
  1567. }
  1568. }
  1569. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  1570. {
  1571. struct drm_crtc *crtc = NULL;
  1572. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1573. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1574. if (intel_crtc->pipe == pipe)
  1575. break;
  1576. }
  1577. return crtc;
  1578. }
  1579. static int intel_connector_clones(struct drm_device *dev, int type_mask)
  1580. {
  1581. int index_mask = 0;
  1582. struct drm_connector *connector;
  1583. int entry = 0;
  1584. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1585. struct intel_output *intel_output = to_intel_output(connector);
  1586. if (type_mask & (1 << intel_output->type))
  1587. index_mask |= (1 << entry);
  1588. entry++;
  1589. }
  1590. return index_mask;
  1591. }
  1592. static void intel_setup_outputs(struct drm_device *dev)
  1593. {
  1594. struct drm_i915_private *dev_priv = dev->dev_private;
  1595. struct drm_connector *connector;
  1596. intel_crt_init(dev);
  1597. /* Set up integrated LVDS */
  1598. if (IS_MOBILE(dev) && !IS_I830(dev))
  1599. intel_lvds_init(dev);
  1600. if (IS_I9XX(dev)) {
  1601. int found;
  1602. u32 reg;
  1603. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  1604. found = intel_sdvo_init(dev, SDVOB);
  1605. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1606. intel_hdmi_init(dev, SDVOB);
  1607. }
  1608. /* Before G4X SDVOC doesn't have its own detect register */
  1609. if (IS_G4X(dev))
  1610. reg = SDVOC;
  1611. else
  1612. reg = SDVOB;
  1613. if (I915_READ(reg) & SDVO_DETECTED) {
  1614. found = intel_sdvo_init(dev, SDVOC);
  1615. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1616. intel_hdmi_init(dev, SDVOC);
  1617. }
  1618. } else
  1619. intel_dvo_init(dev);
  1620. if (IS_I9XX(dev) && IS_MOBILE(dev))
  1621. intel_tv_init(dev);
  1622. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1623. struct intel_output *intel_output = to_intel_output(connector);
  1624. struct drm_encoder *encoder = &intel_output->enc;
  1625. int crtc_mask = 0, clone_mask = 0;
  1626. /* valid crtcs */
  1627. switch(intel_output->type) {
  1628. case INTEL_OUTPUT_HDMI:
  1629. crtc_mask = ((1 << 0)|
  1630. (1 << 1));
  1631. clone_mask = ((1 << INTEL_OUTPUT_HDMI));
  1632. break;
  1633. case INTEL_OUTPUT_DVO:
  1634. case INTEL_OUTPUT_SDVO:
  1635. crtc_mask = ((1 << 0)|
  1636. (1 << 1));
  1637. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1638. (1 << INTEL_OUTPUT_DVO) |
  1639. (1 << INTEL_OUTPUT_SDVO));
  1640. break;
  1641. case INTEL_OUTPUT_ANALOG:
  1642. crtc_mask = ((1 << 0)|
  1643. (1 << 1));
  1644. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1645. (1 << INTEL_OUTPUT_DVO) |
  1646. (1 << INTEL_OUTPUT_SDVO));
  1647. break;
  1648. case INTEL_OUTPUT_LVDS:
  1649. crtc_mask = (1 << 1);
  1650. clone_mask = (1 << INTEL_OUTPUT_LVDS);
  1651. break;
  1652. case INTEL_OUTPUT_TVOUT:
  1653. crtc_mask = ((1 << 0) |
  1654. (1 << 1));
  1655. clone_mask = (1 << INTEL_OUTPUT_TVOUT);
  1656. break;
  1657. }
  1658. encoder->possible_crtcs = crtc_mask;
  1659. encoder->possible_clones = intel_connector_clones(dev, clone_mask);
  1660. }
  1661. }
  1662. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  1663. {
  1664. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1665. struct drm_device *dev = fb->dev;
  1666. if (fb->fbdev)
  1667. intelfb_remove(dev, fb);
  1668. drm_framebuffer_cleanup(fb);
  1669. mutex_lock(&dev->struct_mutex);
  1670. drm_gem_object_unreference(intel_fb->obj);
  1671. mutex_unlock(&dev->struct_mutex);
  1672. kfree(intel_fb);
  1673. }
  1674. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  1675. struct drm_file *file_priv,
  1676. unsigned int *handle)
  1677. {
  1678. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1679. struct drm_gem_object *object = intel_fb->obj;
  1680. return drm_gem_handle_create(file_priv, object, handle);
  1681. }
  1682. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  1683. .destroy = intel_user_framebuffer_destroy,
  1684. .create_handle = intel_user_framebuffer_create_handle,
  1685. };
  1686. int intel_framebuffer_create(struct drm_device *dev,
  1687. struct drm_mode_fb_cmd *mode_cmd,
  1688. struct drm_framebuffer **fb,
  1689. struct drm_gem_object *obj)
  1690. {
  1691. struct intel_framebuffer *intel_fb;
  1692. int ret;
  1693. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  1694. if (!intel_fb)
  1695. return -ENOMEM;
  1696. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  1697. if (ret) {
  1698. DRM_ERROR("framebuffer init failed %d\n", ret);
  1699. return ret;
  1700. }
  1701. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  1702. intel_fb->obj = obj;
  1703. *fb = &intel_fb->base;
  1704. return 0;
  1705. }
  1706. static struct drm_framebuffer *
  1707. intel_user_framebuffer_create(struct drm_device *dev,
  1708. struct drm_file *filp,
  1709. struct drm_mode_fb_cmd *mode_cmd)
  1710. {
  1711. struct drm_gem_object *obj;
  1712. struct drm_framebuffer *fb;
  1713. int ret;
  1714. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  1715. if (!obj)
  1716. return NULL;
  1717. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  1718. if (ret) {
  1719. mutex_lock(&dev->struct_mutex);
  1720. drm_gem_object_unreference(obj);
  1721. mutex_unlock(&dev->struct_mutex);
  1722. return NULL;
  1723. }
  1724. return fb;
  1725. }
  1726. static const struct drm_mode_config_funcs intel_mode_funcs = {
  1727. .fb_create = intel_user_framebuffer_create,
  1728. .fb_changed = intelfb_probe,
  1729. };
  1730. void intel_modeset_init(struct drm_device *dev)
  1731. {
  1732. int num_pipe;
  1733. int i;
  1734. drm_mode_config_init(dev);
  1735. dev->mode_config.min_width = 0;
  1736. dev->mode_config.min_height = 0;
  1737. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  1738. if (IS_I965G(dev)) {
  1739. dev->mode_config.max_width = 8192;
  1740. dev->mode_config.max_height = 8192;
  1741. } else {
  1742. dev->mode_config.max_width = 2048;
  1743. dev->mode_config.max_height = 2048;
  1744. }
  1745. /* set memory base */
  1746. if (IS_I9XX(dev))
  1747. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  1748. else
  1749. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  1750. if (IS_MOBILE(dev) || IS_I9XX(dev))
  1751. num_pipe = 2;
  1752. else
  1753. num_pipe = 1;
  1754. DRM_DEBUG("%d display pipe%s available.\n",
  1755. num_pipe, num_pipe > 1 ? "s" : "");
  1756. for (i = 0; i < num_pipe; i++) {
  1757. intel_crtc_init(dev, i);
  1758. }
  1759. intel_setup_outputs(dev);
  1760. }
  1761. void intel_modeset_cleanup(struct drm_device *dev)
  1762. {
  1763. drm_mode_config_cleanup(dev);
  1764. }
  1765. /* current intel driver doesn't take advantage of encoders
  1766. always give back the encoder for the connector
  1767. */
  1768. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  1769. {
  1770. struct intel_output *intel_output = to_intel_output(connector);
  1771. return &intel_output->enc;
  1772. }