Subversion Repositories Kolibri OS

Rev

Rev 1321 | Rev 1430 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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