radeon_legacy_crtc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include <drm/radeon_drm.h>
  29. #include <drm/drm_fixed.h>
  30. #include "radeon.h"
  31. #include "atom.h"
  32. static void radeon_overscan_setup(struct drm_crtc *crtc,
  33. struct drm_display_mode *mode)
  34. {
  35. struct drm_device *dev = crtc->dev;
  36. struct radeon_device *rdev = dev->dev_private;
  37. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  38. WREG32(RADEON_OVR_CLR + radeon_crtc->crtc_offset, 0);
  39. WREG32(RADEON_OVR_WID_LEFT_RIGHT + radeon_crtc->crtc_offset, 0);
  40. WREG32(RADEON_OVR_WID_TOP_BOTTOM + radeon_crtc->crtc_offset, 0);
  41. }
  42. static void radeon_legacy_rmx_mode_set(struct drm_crtc *crtc,
  43. struct drm_display_mode *mode)
  44. {
  45. struct drm_device *dev = crtc->dev;
  46. struct radeon_device *rdev = dev->dev_private;
  47. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  48. int xres = mode->hdisplay;
  49. int yres = mode->vdisplay;
  50. bool hscale = true, vscale = true;
  51. int hsync_wid;
  52. int vsync_wid;
  53. int hsync_start;
  54. int blank_width;
  55. u32 scale, inc, crtc_more_cntl;
  56. u32 fp_horz_stretch, fp_vert_stretch, fp_horz_vert_active;
  57. u32 fp_h_sync_strt_wid, fp_crtc_h_total_disp;
  58. u32 fp_v_sync_strt_wid, fp_crtc_v_total_disp;
  59. struct drm_display_mode *native_mode = &radeon_crtc->native_mode;
  60. fp_vert_stretch = RREG32(RADEON_FP_VERT_STRETCH) &
  61. (RADEON_VERT_STRETCH_RESERVED |
  62. RADEON_VERT_AUTO_RATIO_INC);
  63. fp_horz_stretch = RREG32(RADEON_FP_HORZ_STRETCH) &
  64. (RADEON_HORZ_FP_LOOP_STRETCH |
  65. RADEON_HORZ_AUTO_RATIO_INC);
  66. crtc_more_cntl = 0;
  67. if ((rdev->family == CHIP_RS100) ||
  68. (rdev->family == CHIP_RS200)) {
  69. /* This is to workaround the asic bug for RMX, some versions
  70. of BIOS dosen't have this register initialized correctly. */
  71. crtc_more_cntl |= RADEON_CRTC_H_CUTOFF_ACTIVE_EN;
  72. }
  73. fp_crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff)
  74. | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
  75. hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
  76. if (!hsync_wid)
  77. hsync_wid = 1;
  78. hsync_start = mode->crtc_hsync_start - 8;
  79. fp_h_sync_strt_wid = ((hsync_start & 0x1fff)
  80. | ((hsync_wid & 0x3f) << 16)
  81. | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
  82. ? RADEON_CRTC_H_SYNC_POL
  83. : 0));
  84. fp_crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff)
  85. | ((mode->crtc_vdisplay - 1) << 16));
  86. vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
  87. if (!vsync_wid)
  88. vsync_wid = 1;
  89. fp_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff)
  90. | ((vsync_wid & 0x1f) << 16)
  91. | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
  92. ? RADEON_CRTC_V_SYNC_POL
  93. : 0));
  94. fp_horz_vert_active = 0;
  95. if (native_mode->hdisplay == 0 ||
  96. native_mode->vdisplay == 0) {
  97. hscale = false;
  98. vscale = false;
  99. } else {
  100. if (xres > native_mode->hdisplay)
  101. xres = native_mode->hdisplay;
  102. if (yres > native_mode->vdisplay)
  103. yres = native_mode->vdisplay;
  104. if (xres == native_mode->hdisplay)
  105. hscale = false;
  106. if (yres == native_mode->vdisplay)
  107. vscale = false;
  108. }
  109. switch (radeon_crtc->rmx_type) {
  110. case RMX_FULL:
  111. case RMX_ASPECT:
  112. if (!hscale)
  113. fp_horz_stretch |= ((xres/8-1) << 16);
  114. else {
  115. inc = (fp_horz_stretch & RADEON_HORZ_AUTO_RATIO_INC) ? 1 : 0;
  116. scale = ((xres + inc) * RADEON_HORZ_STRETCH_RATIO_MAX)
  117. / native_mode->hdisplay + 1;
  118. fp_horz_stretch |= (((scale) & RADEON_HORZ_STRETCH_RATIO_MASK) |
  119. RADEON_HORZ_STRETCH_BLEND |
  120. RADEON_HORZ_STRETCH_ENABLE |
  121. ((native_mode->hdisplay/8-1) << 16));
  122. }
  123. if (!vscale)
  124. fp_vert_stretch |= ((yres-1) << 12);
  125. else {
  126. inc = (fp_vert_stretch & RADEON_VERT_AUTO_RATIO_INC) ? 1 : 0;
  127. scale = ((yres + inc) * RADEON_VERT_STRETCH_RATIO_MAX)
  128. / native_mode->vdisplay + 1;
  129. fp_vert_stretch |= (((scale) & RADEON_VERT_STRETCH_RATIO_MASK) |
  130. RADEON_VERT_STRETCH_ENABLE |
  131. RADEON_VERT_STRETCH_BLEND |
  132. ((native_mode->vdisplay-1) << 12));
  133. }
  134. break;
  135. case RMX_CENTER:
  136. fp_horz_stretch |= ((xres/8-1) << 16);
  137. fp_vert_stretch |= ((yres-1) << 12);
  138. crtc_more_cntl |= (RADEON_CRTC_AUTO_HORZ_CENTER_EN |
  139. RADEON_CRTC_AUTO_VERT_CENTER_EN);
  140. blank_width = (mode->crtc_hblank_end - mode->crtc_hblank_start) / 8;
  141. if (blank_width > 110)
  142. blank_width = 110;
  143. fp_crtc_h_total_disp = (((blank_width) & 0x3ff)
  144. | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
  145. hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
  146. if (!hsync_wid)
  147. hsync_wid = 1;
  148. fp_h_sync_strt_wid = ((((mode->crtc_hsync_start - mode->crtc_hblank_start) / 8) & 0x1fff)
  149. | ((hsync_wid & 0x3f) << 16)
  150. | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
  151. ? RADEON_CRTC_H_SYNC_POL
  152. : 0));
  153. fp_crtc_v_total_disp = (((mode->crtc_vblank_end - mode->crtc_vblank_start) & 0xffff)
  154. | ((mode->crtc_vdisplay - 1) << 16));
  155. vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
  156. if (!vsync_wid)
  157. vsync_wid = 1;
  158. fp_v_sync_strt_wid = ((((mode->crtc_vsync_start - mode->crtc_vblank_start) & 0xfff)
  159. | ((vsync_wid & 0x1f) << 16)
  160. | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
  161. ? RADEON_CRTC_V_SYNC_POL
  162. : 0)));
  163. fp_horz_vert_active = (((native_mode->vdisplay) & 0xfff) |
  164. (((native_mode->hdisplay / 8) & 0x1ff) << 16));
  165. break;
  166. case RMX_OFF:
  167. default:
  168. fp_horz_stretch |= ((xres/8-1) << 16);
  169. fp_vert_stretch |= ((yres-1) << 12);
  170. break;
  171. }
  172. WREG32(RADEON_FP_HORZ_STRETCH, fp_horz_stretch);
  173. WREG32(RADEON_FP_VERT_STRETCH, fp_vert_stretch);
  174. WREG32(RADEON_CRTC_MORE_CNTL, crtc_more_cntl);
  175. WREG32(RADEON_FP_HORZ_VERT_ACTIVE, fp_horz_vert_active);
  176. WREG32(RADEON_FP_H_SYNC_STRT_WID, fp_h_sync_strt_wid);
  177. WREG32(RADEON_FP_V_SYNC_STRT_WID, fp_v_sync_strt_wid);
  178. WREG32(RADEON_FP_CRTC_H_TOTAL_DISP, fp_crtc_h_total_disp);
  179. WREG32(RADEON_FP_CRTC_V_TOTAL_DISP, fp_crtc_v_total_disp);
  180. }
  181. void radeon_restore_common_regs(struct drm_device *dev)
  182. {
  183. /* don't need this yet */
  184. }
  185. static void radeon_pll_wait_for_read_update_complete(struct drm_device *dev)
  186. {
  187. struct radeon_device *rdev = dev->dev_private;
  188. int i = 0;
  189. /* FIXME: Certain revisions of R300 can't recover here. Not sure of
  190. the cause yet, but this workaround will mask the problem for now.
  191. Other chips usually will pass at the very first test, so the
  192. workaround shouldn't have any effect on them. */
  193. for (i = 0;
  194. (i < 10000 &&
  195. RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_ATOMIC_UPDATE_R);
  196. i++);
  197. }
  198. static void radeon_pll_write_update(struct drm_device *dev)
  199. {
  200. struct radeon_device *rdev = dev->dev_private;
  201. while (RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_ATOMIC_UPDATE_R);
  202. WREG32_PLL_P(RADEON_PPLL_REF_DIV,
  203. RADEON_PPLL_ATOMIC_UPDATE_W,
  204. ~(RADEON_PPLL_ATOMIC_UPDATE_W));
  205. }
  206. static void radeon_pll2_wait_for_read_update_complete(struct drm_device *dev)
  207. {
  208. struct radeon_device *rdev = dev->dev_private;
  209. int i = 0;
  210. /* FIXME: Certain revisions of R300 can't recover here. Not sure of
  211. the cause yet, but this workaround will mask the problem for now.
  212. Other chips usually will pass at the very first test, so the
  213. workaround shouldn't have any effect on them. */
  214. for (i = 0;
  215. (i < 10000 &&
  216. RREG32_PLL(RADEON_P2PLL_REF_DIV) & RADEON_P2PLL_ATOMIC_UPDATE_R);
  217. i++);
  218. }
  219. static void radeon_pll2_write_update(struct drm_device *dev)
  220. {
  221. struct radeon_device *rdev = dev->dev_private;
  222. while (RREG32_PLL(RADEON_P2PLL_REF_DIV) & RADEON_P2PLL_ATOMIC_UPDATE_R);
  223. WREG32_PLL_P(RADEON_P2PLL_REF_DIV,
  224. RADEON_P2PLL_ATOMIC_UPDATE_W,
  225. ~(RADEON_P2PLL_ATOMIC_UPDATE_W));
  226. }
  227. static uint8_t radeon_compute_pll_gain(uint16_t ref_freq, uint16_t ref_div,
  228. uint16_t fb_div)
  229. {
  230. unsigned int vcoFreq;
  231. if (!ref_div)
  232. return 1;
  233. vcoFreq = ((unsigned)ref_freq & fb_div) / ref_div;
  234. /*
  235. * This is horribly crude: the VCO frequency range is divided into
  236. * 3 parts, each part having a fixed PLL gain value.
  237. */
  238. if (vcoFreq >= 30000)
  239. /*
  240. * [300..max] MHz : 7
  241. */
  242. return 7;
  243. else if (vcoFreq >= 18000)
  244. /*
  245. * [180..300) MHz : 4
  246. */
  247. return 4;
  248. else
  249. /*
  250. * [0..180) MHz : 1
  251. */
  252. return 1;
  253. }
  254. void radeon_crtc_dpms(struct drm_crtc *crtc, int mode)
  255. {
  256. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  257. struct drm_device *dev = crtc->dev;
  258. struct radeon_device *rdev = dev->dev_private;
  259. uint32_t mask;
  260. if (radeon_crtc->crtc_id)
  261. mask = (RADEON_CRTC2_DISP_DIS |
  262. RADEON_CRTC2_VSYNC_DIS |
  263. RADEON_CRTC2_HSYNC_DIS |
  264. RADEON_CRTC2_DISP_REQ_EN_B);
  265. else
  266. mask = (RADEON_CRTC_DISPLAY_DIS |
  267. RADEON_CRTC_VSYNC_DIS |
  268. RADEON_CRTC_HSYNC_DIS);
  269. switch (mode) {
  270. case DRM_MODE_DPMS_ON:
  271. radeon_crtc->enabled = true;
  272. /* adjust pm to dpms changes BEFORE enabling crtcs */
  273. radeon_pm_compute_clocks(rdev);
  274. if (radeon_crtc->crtc_id)
  275. WREG32_P(RADEON_CRTC2_GEN_CNTL, RADEON_CRTC2_EN, ~(RADEON_CRTC2_EN | mask));
  276. else {
  277. WREG32_P(RADEON_CRTC_GEN_CNTL, RADEON_CRTC_EN, ~(RADEON_CRTC_EN |
  278. RADEON_CRTC_DISP_REQ_EN_B));
  279. WREG32_P(RADEON_CRTC_EXT_CNTL, 0, ~mask);
  280. }
  281. drm_vblank_post_modeset(dev, radeon_crtc->crtc_id);
  282. radeon_crtc_load_lut(crtc);
  283. break;
  284. case DRM_MODE_DPMS_STANDBY:
  285. case DRM_MODE_DPMS_SUSPEND:
  286. case DRM_MODE_DPMS_OFF:
  287. drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id);
  288. if (radeon_crtc->crtc_id)
  289. WREG32_P(RADEON_CRTC2_GEN_CNTL, mask, ~(RADEON_CRTC2_EN | mask));
  290. else {
  291. WREG32_P(RADEON_CRTC_GEN_CNTL, RADEON_CRTC_DISP_REQ_EN_B, ~(RADEON_CRTC_EN |
  292. RADEON_CRTC_DISP_REQ_EN_B));
  293. WREG32_P(RADEON_CRTC_EXT_CNTL, mask, ~mask);
  294. }
  295. radeon_crtc->enabled = false;
  296. /* adjust pm to dpms changes AFTER disabling crtcs */
  297. radeon_pm_compute_clocks(rdev);
  298. break;
  299. }
  300. }
  301. int radeon_crtc_set_base(struct drm_crtc *crtc, int x, int y,
  302. struct drm_framebuffer *old_fb)
  303. {
  304. struct drm_device *dev = crtc->dev;
  305. struct radeon_device *rdev = dev->dev_private;
  306. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  307. struct radeon_framebuffer *radeon_fb;
  308. struct drm_gem_object *obj;
  309. struct radeon_bo *rbo;
  310. uint64_t base;
  311. uint32_t crtc_offset, crtc_offset_cntl, crtc_tile_x0_y0 = 0;
  312. uint32_t crtc_pitch, pitch_pixels;
  313. uint32_t tiling_flags;
  314. int format;
  315. uint32_t gen_cntl_reg, gen_cntl_val;
  316. int r;
  317. DRM_DEBUG("\n");
  318. /* no fb bound */
  319. if (!crtc->fb) {
  320. DRM_DEBUG("No FB bound\n");
  321. return 0;
  322. }
  323. radeon_fb = to_radeon_framebuffer(crtc->fb);
  324. switch (crtc->fb->bits_per_pixel) {
  325. case 8:
  326. format = 2;
  327. break;
  328. case 15: /* 555 */
  329. format = 3;
  330. break;
  331. case 16: /* 565 */
  332. format = 4;
  333. break;
  334. case 24: /* RGB */
  335. format = 5;
  336. break;
  337. case 32: /* xRGB */
  338. format = 6;
  339. break;
  340. default:
  341. return false;
  342. }
  343. /* Pin framebuffer & get tilling informations */
  344. obj = radeon_fb->obj;
  345. rbo = obj->driver_private;
  346. r = radeon_bo_reserve(rbo, false);
  347. if (unlikely(r != 0))
  348. return r;
  349. r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &base);
  350. if (unlikely(r != 0)) {
  351. radeon_bo_unreserve(rbo);
  352. return -EINVAL;
  353. }
  354. radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL);
  355. radeon_bo_unreserve(rbo);
  356. if (tiling_flags & RADEON_TILING_MICRO)
  357. DRM_ERROR("trying to scanout microtiled buffer\n");
  358. /* if scanout was in GTT this really wouldn't work */
  359. /* crtc offset is from display base addr not FB location */
  360. radeon_crtc->legacy_display_base_addr = rdev->mc.vram_start;
  361. base -= radeon_crtc->legacy_display_base_addr;
  362. crtc_offset_cntl = 0;
  363. pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8);
  364. crtc_pitch = (((pitch_pixels * crtc->fb->bits_per_pixel) +
  365. ((crtc->fb->bits_per_pixel * 8) - 1)) /
  366. (crtc->fb->bits_per_pixel * 8));
  367. crtc_pitch |= crtc_pitch << 16;
  368. if (tiling_flags & RADEON_TILING_MACRO) {
  369. if (ASIC_IS_R300(rdev))
  370. crtc_offset_cntl |= (R300_CRTC_X_Y_MODE_EN |
  371. R300_CRTC_MICRO_TILE_BUFFER_DIS |
  372. R300_CRTC_MACRO_TILE_EN);
  373. else
  374. crtc_offset_cntl |= RADEON_CRTC_TILE_EN;
  375. } else {
  376. if (ASIC_IS_R300(rdev))
  377. crtc_offset_cntl &= ~(R300_CRTC_X_Y_MODE_EN |
  378. R300_CRTC_MICRO_TILE_BUFFER_DIS |
  379. R300_CRTC_MACRO_TILE_EN);
  380. else
  381. crtc_offset_cntl &= ~RADEON_CRTC_TILE_EN;
  382. }
  383. if (tiling_flags & RADEON_TILING_MACRO) {
  384. if (ASIC_IS_R300(rdev)) {
  385. crtc_tile_x0_y0 = x | (y << 16);
  386. base &= ~0x7ff;
  387. } else {
  388. int byteshift = crtc->fb->bits_per_pixel >> 4;
  389. int tile_addr = (((y >> 3) * pitch_pixels + x) >> (8 - byteshift)) << 11;
  390. base += tile_addr + ((x << byteshift) % 256) + ((y % 8) << 8);
  391. crtc_offset_cntl |= (y % 16);
  392. }
  393. } else {
  394. int offset = y * pitch_pixels + x;
  395. switch (crtc->fb->bits_per_pixel) {
  396. case 8:
  397. offset *= 1;
  398. break;
  399. case 15:
  400. case 16:
  401. offset *= 2;
  402. break;
  403. case 24:
  404. offset *= 3;
  405. break;
  406. case 32:
  407. offset *= 4;
  408. break;
  409. default:
  410. return false;
  411. }
  412. base += offset;
  413. }
  414. base &= ~7;
  415. if (radeon_crtc->crtc_id == 1)
  416. gen_cntl_reg = RADEON_CRTC2_GEN_CNTL;
  417. else
  418. gen_cntl_reg = RADEON_CRTC_GEN_CNTL;
  419. gen_cntl_val = RREG32(gen_cntl_reg);
  420. gen_cntl_val &= ~(0xf << 8);
  421. gen_cntl_val |= (format << 8);
  422. WREG32(gen_cntl_reg, gen_cntl_val);
  423. crtc_offset = (u32)base;
  424. WREG32(RADEON_DISPLAY_BASE_ADDR + radeon_crtc->crtc_offset, radeon_crtc->legacy_display_base_addr);
  425. if (ASIC_IS_R300(rdev)) {
  426. if (radeon_crtc->crtc_id)
  427. WREG32(R300_CRTC2_TILE_X0_Y0, crtc_tile_x0_y0);
  428. else
  429. WREG32(R300_CRTC_TILE_X0_Y0, crtc_tile_x0_y0);
  430. }
  431. WREG32(RADEON_CRTC_OFFSET_CNTL + radeon_crtc->crtc_offset, crtc_offset_cntl);
  432. WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, crtc_offset);
  433. WREG32(RADEON_CRTC_PITCH + radeon_crtc->crtc_offset, crtc_pitch);
  434. if (old_fb && old_fb != crtc->fb) {
  435. radeon_fb = to_radeon_framebuffer(old_fb);
  436. rbo = radeon_fb->obj->driver_private;
  437. r = radeon_bo_reserve(rbo, false);
  438. if (unlikely(r != 0))
  439. return r;
  440. radeon_bo_unpin(rbo);
  441. radeon_bo_unreserve(rbo);
  442. }
  443. /* Bytes per pixel may have changed */
  444. radeon_bandwidth_update(rdev);
  445. return 0;
  446. }
  447. static bool radeon_set_crtc_timing(struct drm_crtc *crtc, struct drm_display_mode *mode)
  448. {
  449. struct drm_device *dev = crtc->dev;
  450. struct radeon_device *rdev = dev->dev_private;
  451. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  452. struct drm_encoder *encoder;
  453. int format;
  454. int hsync_start;
  455. int hsync_wid;
  456. int vsync_wid;
  457. uint32_t crtc_h_total_disp;
  458. uint32_t crtc_h_sync_strt_wid;
  459. uint32_t crtc_v_total_disp;
  460. uint32_t crtc_v_sync_strt_wid;
  461. bool is_tv = false;
  462. DRM_DEBUG("\n");
  463. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  464. if (encoder->crtc == crtc) {
  465. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  466. if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) {
  467. is_tv = true;
  468. DRM_INFO("crtc %d is connected to a TV\n", radeon_crtc->crtc_id);
  469. break;
  470. }
  471. }
  472. }
  473. switch (crtc->fb->bits_per_pixel) {
  474. case 8:
  475. format = 2;
  476. break;
  477. case 15: /* 555 */
  478. format = 3;
  479. break;
  480. case 16: /* 565 */
  481. format = 4;
  482. break;
  483. case 24: /* RGB */
  484. format = 5;
  485. break;
  486. case 32: /* xRGB */
  487. format = 6;
  488. break;
  489. default:
  490. return false;
  491. }
  492. crtc_h_total_disp = ((((mode->crtc_htotal / 8) - 1) & 0x3ff)
  493. | ((((mode->crtc_hdisplay / 8) - 1) & 0x1ff) << 16));
  494. hsync_wid = (mode->crtc_hsync_end - mode->crtc_hsync_start) / 8;
  495. if (!hsync_wid)
  496. hsync_wid = 1;
  497. hsync_start = mode->crtc_hsync_start - 8;
  498. crtc_h_sync_strt_wid = ((hsync_start & 0x1fff)
  499. | ((hsync_wid & 0x3f) << 16)
  500. | ((mode->flags & DRM_MODE_FLAG_NHSYNC)
  501. ? RADEON_CRTC_H_SYNC_POL
  502. : 0));
  503. /* This works for double scan mode. */
  504. crtc_v_total_disp = (((mode->crtc_vtotal - 1) & 0xffff)
  505. | ((mode->crtc_vdisplay - 1) << 16));
  506. vsync_wid = mode->crtc_vsync_end - mode->crtc_vsync_start;
  507. if (!vsync_wid)
  508. vsync_wid = 1;
  509. crtc_v_sync_strt_wid = (((mode->crtc_vsync_start - 1) & 0xfff)
  510. | ((vsync_wid & 0x1f) << 16)
  511. | ((mode->flags & DRM_MODE_FLAG_NVSYNC)
  512. ? RADEON_CRTC_V_SYNC_POL
  513. : 0));
  514. if (radeon_crtc->crtc_id) {
  515. uint32_t crtc2_gen_cntl;
  516. uint32_t disp2_merge_cntl;
  517. /* if TV DAC is enabled for another crtc and keep it enabled */
  518. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL) & 0x00718080;
  519. crtc2_gen_cntl |= ((format << 8)
  520. | RADEON_CRTC2_VSYNC_DIS
  521. | RADEON_CRTC2_HSYNC_DIS
  522. | RADEON_CRTC2_DISP_DIS
  523. | RADEON_CRTC2_DISP_REQ_EN_B
  524. | ((mode->flags & DRM_MODE_FLAG_DBLSCAN)
  525. ? RADEON_CRTC2_DBL_SCAN_EN
  526. : 0)
  527. | ((mode->flags & DRM_MODE_FLAG_CSYNC)
  528. ? RADEON_CRTC2_CSYNC_EN
  529. : 0)
  530. | ((mode->flags & DRM_MODE_FLAG_INTERLACE)
  531. ? RADEON_CRTC2_INTERLACE_EN
  532. : 0));
  533. /* rs4xx chips seem to like to have the crtc enabled when the timing is set */
  534. if ((rdev->family == CHIP_RS400) || (rdev->family == CHIP_RS480))
  535. crtc2_gen_cntl |= RADEON_CRTC2_EN;
  536. disp2_merge_cntl = RREG32(RADEON_DISP2_MERGE_CNTL);
  537. disp2_merge_cntl &= ~RADEON_DISP2_RGB_OFFSET_EN;
  538. WREG32(RADEON_DISP2_MERGE_CNTL, disp2_merge_cntl);
  539. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  540. WREG32(RADEON_FP_H2_SYNC_STRT_WID, crtc_h_sync_strt_wid);
  541. WREG32(RADEON_FP_V2_SYNC_STRT_WID, crtc_v_sync_strt_wid);
  542. } else {
  543. uint32_t crtc_gen_cntl;
  544. uint32_t crtc_ext_cntl;
  545. uint32_t disp_merge_cntl;
  546. crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL) & 0x00718000;
  547. crtc_gen_cntl |= (RADEON_CRTC_EXT_DISP_EN
  548. | (format << 8)
  549. | RADEON_CRTC_DISP_REQ_EN_B
  550. | ((mode->flags & DRM_MODE_FLAG_DBLSCAN)
  551. ? RADEON_CRTC_DBL_SCAN_EN
  552. : 0)
  553. | ((mode->flags & DRM_MODE_FLAG_CSYNC)
  554. ? RADEON_CRTC_CSYNC_EN
  555. : 0)
  556. | ((mode->flags & DRM_MODE_FLAG_INTERLACE)
  557. ? RADEON_CRTC_INTERLACE_EN
  558. : 0));
  559. /* rs4xx chips seem to like to have the crtc enabled when the timing is set */
  560. if ((rdev->family == CHIP_RS400) || (rdev->family == CHIP_RS480))
  561. crtc_gen_cntl |= RADEON_CRTC_EN;
  562. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  563. crtc_ext_cntl |= (RADEON_XCRT_CNT_EN |
  564. RADEON_CRTC_VSYNC_DIS |
  565. RADEON_CRTC_HSYNC_DIS |
  566. RADEON_CRTC_DISPLAY_DIS);
  567. disp_merge_cntl = RREG32(RADEON_DISP_MERGE_CNTL);
  568. disp_merge_cntl &= ~RADEON_DISP_RGB_OFFSET_EN;
  569. WREG32(RADEON_DISP_MERGE_CNTL, disp_merge_cntl);
  570. WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl);
  571. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  572. }
  573. if (is_tv)
  574. radeon_legacy_tv_adjust_crtc_reg(encoder, &crtc_h_total_disp,
  575. &crtc_h_sync_strt_wid, &crtc_v_total_disp,
  576. &crtc_v_sync_strt_wid);
  577. WREG32(RADEON_CRTC_H_TOTAL_DISP + radeon_crtc->crtc_offset, crtc_h_total_disp);
  578. WREG32(RADEON_CRTC_H_SYNC_STRT_WID + radeon_crtc->crtc_offset, crtc_h_sync_strt_wid);
  579. WREG32(RADEON_CRTC_V_TOTAL_DISP + radeon_crtc->crtc_offset, crtc_v_total_disp);
  580. WREG32(RADEON_CRTC_V_SYNC_STRT_WID + radeon_crtc->crtc_offset, crtc_v_sync_strt_wid);
  581. return true;
  582. }
  583. static void radeon_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode)
  584. {
  585. struct drm_device *dev = crtc->dev;
  586. struct radeon_device *rdev = dev->dev_private;
  587. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  588. struct drm_encoder *encoder;
  589. uint32_t feedback_div = 0;
  590. uint32_t frac_fb_div = 0;
  591. uint32_t reference_div = 0;
  592. uint32_t post_divider = 0;
  593. uint32_t freq = 0;
  594. uint8_t pll_gain;
  595. bool use_bios_divs = false;
  596. /* PLL registers */
  597. uint32_t pll_ref_div = 0;
  598. uint32_t pll_fb_post_div = 0;
  599. uint32_t htotal_cntl = 0;
  600. bool is_tv = false;
  601. struct radeon_pll *pll;
  602. struct {
  603. int divider;
  604. int bitvalue;
  605. } *post_div, post_divs[] = {
  606. /* From RAGE 128 VR/RAGE 128 GL Register
  607. * Reference Manual (Technical Reference
  608. * Manual P/N RRG-G04100-C Rev. 0.04), page
  609. * 3-17 (PLL_DIV_[3:0]).
  610. */
  611. { 1, 0 }, /* VCLK_SRC */
  612. { 2, 1 }, /* VCLK_SRC/2 */
  613. { 4, 2 }, /* VCLK_SRC/4 */
  614. { 8, 3 }, /* VCLK_SRC/8 */
  615. { 3, 4 }, /* VCLK_SRC/3 */
  616. { 16, 5 }, /* VCLK_SRC/16 */
  617. { 6, 6 }, /* VCLK_SRC/6 */
  618. { 12, 7 }, /* VCLK_SRC/12 */
  619. { 0, 0 }
  620. };
  621. if (radeon_crtc->crtc_id)
  622. pll = &rdev->clock.p2pll;
  623. else
  624. pll = &rdev->clock.p1pll;
  625. pll->flags = RADEON_PLL_LEGACY;
  626. if (radeon_new_pll == 1)
  627. pll->algo = PLL_ALGO_NEW;
  628. else
  629. pll->algo = PLL_ALGO_LEGACY;
  630. if (mode->clock > 200000) /* range limits??? */
  631. pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV;
  632. else
  633. pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV;
  634. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  635. if (encoder->crtc == crtc) {
  636. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  637. if (radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT) {
  638. is_tv = true;
  639. break;
  640. }
  641. if (encoder->encoder_type != DRM_MODE_ENCODER_DAC)
  642. pll->flags |= RADEON_PLL_NO_ODD_POST_DIV;
  643. if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS) {
  644. if (!rdev->is_atom_bios) {
  645. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  646. struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv;
  647. if (lvds) {
  648. if (lvds->use_bios_dividers) {
  649. pll_ref_div = lvds->panel_ref_divider;
  650. pll_fb_post_div = (lvds->panel_fb_divider |
  651. (lvds->panel_post_divider << 16));
  652. htotal_cntl = 0;
  653. use_bios_divs = true;
  654. }
  655. }
  656. }
  657. pll->flags |= RADEON_PLL_USE_REF_DIV;
  658. }
  659. }
  660. }
  661. DRM_DEBUG("\n");
  662. if (!use_bios_divs) {
  663. radeon_compute_pll(pll, mode->clock,
  664. &freq, &feedback_div, &frac_fb_div,
  665. &reference_div, &post_divider);
  666. for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
  667. if (post_div->divider == post_divider)
  668. break;
  669. }
  670. if (!post_div->divider)
  671. post_div = &post_divs[0];
  672. DRM_DEBUG("dc=%u, fd=%d, rd=%d, pd=%d\n",
  673. (unsigned)freq,
  674. feedback_div,
  675. reference_div,
  676. post_divider);
  677. pll_ref_div = reference_div;
  678. #if defined(__powerpc__) && (0) /* TODO */
  679. /* apparently programming this otherwise causes a hang??? */
  680. if (info->MacModel == RADEON_MAC_IBOOK)
  681. pll_fb_post_div = 0x000600ad;
  682. else
  683. #endif
  684. pll_fb_post_div = (feedback_div | (post_div->bitvalue << 16));
  685. htotal_cntl = mode->htotal & 0x7;
  686. }
  687. pll_gain = radeon_compute_pll_gain(pll->reference_freq,
  688. pll_ref_div & 0x3ff,
  689. pll_fb_post_div & 0x7ff);
  690. if (radeon_crtc->crtc_id) {
  691. uint32_t pixclks_cntl = ((RREG32_PLL(RADEON_PIXCLKS_CNTL) &
  692. ~(RADEON_PIX2CLK_SRC_SEL_MASK)) |
  693. RADEON_PIX2CLK_SRC_SEL_P2PLLCLK);
  694. if (is_tv) {
  695. radeon_legacy_tv_adjust_pll2(encoder, &htotal_cntl,
  696. &pll_ref_div, &pll_fb_post_div,
  697. &pixclks_cntl);
  698. }
  699. WREG32_PLL_P(RADEON_PIXCLKS_CNTL,
  700. RADEON_PIX2CLK_SRC_SEL_CPUCLK,
  701. ~(RADEON_PIX2CLK_SRC_SEL_MASK));
  702. WREG32_PLL_P(RADEON_P2PLL_CNTL,
  703. RADEON_P2PLL_RESET
  704. | RADEON_P2PLL_ATOMIC_UPDATE_EN
  705. | ((uint32_t)pll_gain << RADEON_P2PLL_PVG_SHIFT),
  706. ~(RADEON_P2PLL_RESET
  707. | RADEON_P2PLL_ATOMIC_UPDATE_EN
  708. | RADEON_P2PLL_PVG_MASK));
  709. WREG32_PLL_P(RADEON_P2PLL_REF_DIV,
  710. pll_ref_div,
  711. ~RADEON_P2PLL_REF_DIV_MASK);
  712. WREG32_PLL_P(RADEON_P2PLL_DIV_0,
  713. pll_fb_post_div,
  714. ~RADEON_P2PLL_FB0_DIV_MASK);
  715. WREG32_PLL_P(RADEON_P2PLL_DIV_0,
  716. pll_fb_post_div,
  717. ~RADEON_P2PLL_POST0_DIV_MASK);
  718. radeon_pll2_write_update(dev);
  719. radeon_pll2_wait_for_read_update_complete(dev);
  720. WREG32_PLL(RADEON_HTOTAL2_CNTL, htotal_cntl);
  721. WREG32_PLL_P(RADEON_P2PLL_CNTL,
  722. 0,
  723. ~(RADEON_P2PLL_RESET
  724. | RADEON_P2PLL_SLEEP
  725. | RADEON_P2PLL_ATOMIC_UPDATE_EN));
  726. DRM_DEBUG("Wrote2: 0x%08x 0x%08x 0x%08x (0x%08x)\n",
  727. (unsigned)pll_ref_div,
  728. (unsigned)pll_fb_post_div,
  729. (unsigned)htotal_cntl,
  730. RREG32_PLL(RADEON_P2PLL_CNTL));
  731. DRM_DEBUG("Wrote2: rd=%u, fd=%u, pd=%u\n",
  732. (unsigned)pll_ref_div & RADEON_P2PLL_REF_DIV_MASK,
  733. (unsigned)pll_fb_post_div & RADEON_P2PLL_FB0_DIV_MASK,
  734. (unsigned)((pll_fb_post_div &
  735. RADEON_P2PLL_POST0_DIV_MASK) >> 16));
  736. mdelay(50); /* Let the clock to lock */
  737. WREG32_PLL_P(RADEON_PIXCLKS_CNTL,
  738. RADEON_PIX2CLK_SRC_SEL_P2PLLCLK,
  739. ~(RADEON_PIX2CLK_SRC_SEL_MASK));
  740. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  741. } else {
  742. uint32_t pixclks_cntl;
  743. if (is_tv) {
  744. pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
  745. radeon_legacy_tv_adjust_pll1(encoder, &htotal_cntl, &pll_ref_div,
  746. &pll_fb_post_div, &pixclks_cntl);
  747. }
  748. if (rdev->flags & RADEON_IS_MOBILITY) {
  749. /* A temporal workaround for the occational blanking on certain laptop panels.
  750. This appears to related to the PLL divider registers (fail to lock?).
  751. It occurs even when all dividers are the same with their old settings.
  752. In this case we really don't need to fiddle with PLL registers.
  753. By doing this we can avoid the blanking problem with some panels.
  754. */
  755. if ((pll_ref_div == (RREG32_PLL(RADEON_PPLL_REF_DIV) & RADEON_PPLL_REF_DIV_MASK)) &&
  756. (pll_fb_post_div == (RREG32_PLL(RADEON_PPLL_DIV_3) &
  757. (RADEON_PPLL_POST3_DIV_MASK | RADEON_PPLL_FB3_DIV_MASK)))) {
  758. WREG32_P(RADEON_CLOCK_CNTL_INDEX,
  759. RADEON_PLL_DIV_SEL,
  760. ~(RADEON_PLL_DIV_SEL));
  761. r100_pll_errata_after_index(rdev);
  762. return;
  763. }
  764. }
  765. WREG32_PLL_P(RADEON_VCLK_ECP_CNTL,
  766. RADEON_VCLK_SRC_SEL_CPUCLK,
  767. ~(RADEON_VCLK_SRC_SEL_MASK));
  768. WREG32_PLL_P(RADEON_PPLL_CNTL,
  769. RADEON_PPLL_RESET
  770. | RADEON_PPLL_ATOMIC_UPDATE_EN
  771. | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN
  772. | ((uint32_t)pll_gain << RADEON_PPLL_PVG_SHIFT),
  773. ~(RADEON_PPLL_RESET
  774. | RADEON_PPLL_ATOMIC_UPDATE_EN
  775. | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN
  776. | RADEON_PPLL_PVG_MASK));
  777. WREG32_P(RADEON_CLOCK_CNTL_INDEX,
  778. RADEON_PLL_DIV_SEL,
  779. ~(RADEON_PLL_DIV_SEL));
  780. r100_pll_errata_after_index(rdev);
  781. if (ASIC_IS_R300(rdev) ||
  782. (rdev->family == CHIP_RS300) ||
  783. (rdev->family == CHIP_RS400) ||
  784. (rdev->family == CHIP_RS480)) {
  785. if (pll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
  786. /* When restoring console mode, use saved PPLL_REF_DIV
  787. * setting.
  788. */
  789. WREG32_PLL_P(RADEON_PPLL_REF_DIV,
  790. pll_ref_div,
  791. 0);
  792. } else {
  793. /* R300 uses ref_div_acc field as real ref divider */
  794. WREG32_PLL_P(RADEON_PPLL_REF_DIV,
  795. (pll_ref_div << R300_PPLL_REF_DIV_ACC_SHIFT),
  796. ~R300_PPLL_REF_DIV_ACC_MASK);
  797. }
  798. } else
  799. WREG32_PLL_P(RADEON_PPLL_REF_DIV,
  800. pll_ref_div,
  801. ~RADEON_PPLL_REF_DIV_MASK);
  802. WREG32_PLL_P(RADEON_PPLL_DIV_3,
  803. pll_fb_post_div,
  804. ~RADEON_PPLL_FB3_DIV_MASK);
  805. WREG32_PLL_P(RADEON_PPLL_DIV_3,
  806. pll_fb_post_div,
  807. ~RADEON_PPLL_POST3_DIV_MASK);
  808. radeon_pll_write_update(dev);
  809. radeon_pll_wait_for_read_update_complete(dev);
  810. WREG32_PLL(RADEON_HTOTAL_CNTL, htotal_cntl);
  811. WREG32_PLL_P(RADEON_PPLL_CNTL,
  812. 0,
  813. ~(RADEON_PPLL_RESET
  814. | RADEON_PPLL_SLEEP
  815. | RADEON_PPLL_ATOMIC_UPDATE_EN
  816. | RADEON_PPLL_VGA_ATOMIC_UPDATE_EN));
  817. DRM_DEBUG("Wrote: 0x%08x 0x%08x 0x%08x (0x%08x)\n",
  818. pll_ref_div,
  819. pll_fb_post_div,
  820. (unsigned)htotal_cntl,
  821. RREG32_PLL(RADEON_PPLL_CNTL));
  822. DRM_DEBUG("Wrote: rd=%d, fd=%d, pd=%d\n",
  823. pll_ref_div & RADEON_PPLL_REF_DIV_MASK,
  824. pll_fb_post_div & RADEON_PPLL_FB3_DIV_MASK,
  825. (pll_fb_post_div & RADEON_PPLL_POST3_DIV_MASK) >> 16);
  826. mdelay(50); /* Let the clock to lock */
  827. WREG32_PLL_P(RADEON_VCLK_ECP_CNTL,
  828. RADEON_VCLK_SRC_SEL_PPLLCLK,
  829. ~(RADEON_VCLK_SRC_SEL_MASK));
  830. if (is_tv)
  831. WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
  832. }
  833. }
  834. static bool radeon_crtc_mode_fixup(struct drm_crtc *crtc,
  835. struct drm_display_mode *mode,
  836. struct drm_display_mode *adjusted_mode)
  837. {
  838. struct drm_device *dev = crtc->dev;
  839. struct radeon_device *rdev = dev->dev_private;
  840. /* adjust pm to upcoming mode change */
  841. radeon_pm_compute_clocks(rdev);
  842. if (!radeon_crtc_scaling_mode_fixup(crtc, mode, adjusted_mode))
  843. return false;
  844. return true;
  845. }
  846. static int radeon_crtc_mode_set(struct drm_crtc *crtc,
  847. struct drm_display_mode *mode,
  848. struct drm_display_mode *adjusted_mode,
  849. int x, int y, struct drm_framebuffer *old_fb)
  850. {
  851. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  852. /* TODO TV */
  853. radeon_crtc_set_base(crtc, x, y, old_fb);
  854. radeon_set_crtc_timing(crtc, adjusted_mode);
  855. radeon_set_pll(crtc, adjusted_mode);
  856. radeon_overscan_setup(crtc, adjusted_mode);
  857. if (radeon_crtc->crtc_id == 0) {
  858. radeon_legacy_rmx_mode_set(crtc, adjusted_mode);
  859. } else {
  860. if (radeon_crtc->rmx_type != RMX_OFF) {
  861. /* FIXME: only first crtc has rmx what should we
  862. * do ?
  863. */
  864. DRM_ERROR("Mode need scaling but only first crtc can do that.\n");
  865. }
  866. }
  867. return 0;
  868. }
  869. static void radeon_crtc_prepare(struct drm_crtc *crtc)
  870. {
  871. struct drm_device *dev = crtc->dev;
  872. struct drm_crtc *crtci;
  873. /*
  874. * The hardware wedges sometimes if you reconfigure one CRTC
  875. * whilst another is running (see fdo bug #24611).
  876. */
  877. list_for_each_entry(crtci, &dev->mode_config.crtc_list, head)
  878. radeon_crtc_dpms(crtci, DRM_MODE_DPMS_OFF);
  879. }
  880. static void radeon_crtc_commit(struct drm_crtc *crtc)
  881. {
  882. struct drm_device *dev = crtc->dev;
  883. struct drm_crtc *crtci;
  884. /*
  885. * Reenable the CRTCs that should be running.
  886. */
  887. list_for_each_entry(crtci, &dev->mode_config.crtc_list, head) {
  888. if (crtci->enabled)
  889. radeon_crtc_dpms(crtci, DRM_MODE_DPMS_ON);
  890. }
  891. }
  892. static const struct drm_crtc_helper_funcs legacy_helper_funcs = {
  893. .dpms = radeon_crtc_dpms,
  894. .mode_fixup = radeon_crtc_mode_fixup,
  895. .mode_set = radeon_crtc_mode_set,
  896. .mode_set_base = radeon_crtc_set_base,
  897. .prepare = radeon_crtc_prepare,
  898. .commit = radeon_crtc_commit,
  899. .load_lut = radeon_crtc_load_lut,
  900. };
  901. void radeon_legacy_init_crtc(struct drm_device *dev,
  902. struct radeon_crtc *radeon_crtc)
  903. {
  904. if (radeon_crtc->crtc_id == 1)
  905. radeon_crtc->crtc_offset = RADEON_CRTC2_H_TOTAL_DISP - RADEON_CRTC_H_TOTAL_DISP;
  906. drm_crtc_helper_add(&radeon_crtc->base, &legacy_helper_funcs);
  907. }