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