Subversion Repositories Kolibri OS

Rev

Rev 1275 | Rev 1404 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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