Rev 1404 | Rev 1630 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1404 | Rev 1430 | ||
---|---|---|---|
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 "drmP.h" |
26 | #include "drmP.h" |
27 | #include "radeon_drm.h" |
27 | #include "radeon_drm.h" |
28 | #include "radeon.h" |
28 | #include "radeon.h" |
29 | 29 | ||
30 | #include "atom.h" |
30 | #include "atom.h" |
31 | //#include |
31 | //#include |
32 | 32 | ||
33 | #include "drm_crtc_helper.h" |
33 | #include "drm_crtc_helper.h" |
34 | #include "drm_edid.h" |
34 | #include "drm_edid.h" |
35 | 35 | ||
36 | static int radeon_ddc_dump(struct drm_connector *connector); |
36 | static int radeon_ddc_dump(struct drm_connector *connector); |
37 | 37 | ||
38 | static void avivo_crtc_load_lut(struct drm_crtc *crtc) |
38 | static void avivo_crtc_load_lut(struct drm_crtc *crtc) |
39 | { |
39 | { |
40 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
40 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
41 | struct drm_device *dev = crtc->dev; |
41 | struct drm_device *dev = crtc->dev; |
42 | struct radeon_device *rdev = dev->dev_private; |
42 | struct radeon_device *rdev = dev->dev_private; |
43 | int i; |
43 | int i; |
44 | 44 | ||
45 | DRM_DEBUG("%d\n", radeon_crtc->crtc_id); |
45 | DRM_DEBUG("%d\n", radeon_crtc->crtc_id); |
46 | WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0); |
46 | WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0); |
47 | 47 | ||
48 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
48 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
49 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
49 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
50 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
50 | WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
51 | 51 | ||
52 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
52 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
53 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
53 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
54 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
54 | WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
55 | 55 | ||
56 | WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id); |
56 | WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id); |
57 | WREG32(AVIVO_DC_LUT_RW_MODE, 0); |
57 | WREG32(AVIVO_DC_LUT_RW_MODE, 0); |
58 | WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f); |
58 | WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f); |
59 | 59 | ||
60 | WREG8(AVIVO_DC_LUT_RW_INDEX, 0); |
60 | WREG8(AVIVO_DC_LUT_RW_INDEX, 0); |
61 | for (i = 0; i < 256; i++) { |
61 | for (i = 0; i < 256; i++) { |
62 | WREG32(AVIVO_DC_LUT_30_COLOR, |
62 | WREG32(AVIVO_DC_LUT_30_COLOR, |
63 | (radeon_crtc->lut_r[i] << 20) | |
63 | (radeon_crtc->lut_r[i] << 20) | |
64 | (radeon_crtc->lut_g[i] << 10) | |
64 | (radeon_crtc->lut_g[i] << 10) | |
65 | (radeon_crtc->lut_b[i] << 0)); |
65 | (radeon_crtc->lut_b[i] << 0)); |
66 | } |
66 | } |
67 | 67 | ||
68 | WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id); |
68 | WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id); |
69 | } |
69 | } |
- | 70 | ||
- | 71 | static void evergreen_crtc_load_lut(struct drm_crtc *crtc) |
|
- | 72 | { |
|
- | 73 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
|
- | 74 | struct drm_device *dev = crtc->dev; |
|
- | 75 | struct radeon_device *rdev = dev->dev_private; |
|
- | 76 | int i; |
|
- | 77 | ||
- | 78 | DRM_DEBUG("%d\n", radeon_crtc->crtc_id); |
|
- | 79 | WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); |
|
- | 80 | ||
- | 81 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); |
|
- | 82 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); |
|
- | 83 | WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); |
|
- | 84 | ||
- | 85 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); |
|
- | 86 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); |
|
- | 87 | WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); |
|
- | 88 | ||
- | 89 | WREG32(EVERGREEN_DC_LUT_RW_MODE, radeon_crtc->crtc_id); |
|
- | 90 | WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK, 0x00000007); |
|
- | 91 | ||
- | 92 | WREG32(EVERGREEN_DC_LUT_RW_INDEX, 0); |
|
- | 93 | for (i = 0; i < 256; i++) { |
|
- | 94 | WREG32(EVERGREEN_DC_LUT_30_COLOR, |
|
- | 95 | (radeon_crtc->lut_r[i] << 20) | |
|
- | 96 | (radeon_crtc->lut_g[i] << 10) | |
|
- | 97 | (radeon_crtc->lut_b[i] << 0)); |
|
- | 98 | } |
|
- | 99 | } |
|
70 | 100 | ||
71 | static void legacy_crtc_load_lut(struct drm_crtc *crtc) |
101 | static void legacy_crtc_load_lut(struct drm_crtc *crtc) |
72 | { |
102 | { |
73 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
103 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
74 | struct drm_device *dev = crtc->dev; |
104 | struct drm_device *dev = crtc->dev; |
75 | struct radeon_device *rdev = dev->dev_private; |
105 | struct radeon_device *rdev = dev->dev_private; |
76 | int i; |
106 | int i; |
77 | uint32_t dac2_cntl; |
107 | uint32_t dac2_cntl; |
78 | 108 | ||
79 | dac2_cntl = RREG32(RADEON_DAC_CNTL2); |
109 | dac2_cntl = RREG32(RADEON_DAC_CNTL2); |
80 | if (radeon_crtc->crtc_id == 0) |
110 | if (radeon_crtc->crtc_id == 0) |
81 | dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL; |
111 | dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL; |
82 | else |
112 | else |
83 | dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL; |
113 | dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL; |
84 | WREG32(RADEON_DAC_CNTL2, dac2_cntl); |
114 | WREG32(RADEON_DAC_CNTL2, dac2_cntl); |
85 | 115 | ||
86 | WREG8(RADEON_PALETTE_INDEX, 0); |
116 | WREG8(RADEON_PALETTE_INDEX, 0); |
87 | for (i = 0; i < 256; i++) { |
117 | for (i = 0; i < 256; i++) { |
88 | WREG32(RADEON_PALETTE_30_DATA, |
118 | WREG32(RADEON_PALETTE_30_DATA, |
89 | (radeon_crtc->lut_r[i] << 20) | |
119 | (radeon_crtc->lut_r[i] << 20) | |
90 | (radeon_crtc->lut_g[i] << 10) | |
120 | (radeon_crtc->lut_g[i] << 10) | |
91 | (radeon_crtc->lut_b[i] << 0)); |
121 | (radeon_crtc->lut_b[i] << 0)); |
92 | } |
122 | } |
93 | } |
123 | } |
94 | 124 | ||
95 | void radeon_crtc_load_lut(struct drm_crtc *crtc) |
125 | void radeon_crtc_load_lut(struct drm_crtc *crtc) |
96 | { |
126 | { |
97 | struct drm_device *dev = crtc->dev; |
127 | struct drm_device *dev = crtc->dev; |
98 | struct radeon_device *rdev = dev->dev_private; |
128 | struct radeon_device *rdev = dev->dev_private; |
99 | 129 | ||
100 | if (!crtc->enabled) |
130 | if (!crtc->enabled) |
101 | return; |
131 | return; |
- | 132 | ||
- | 133 | if (ASIC_IS_DCE4(rdev)) |
|
102 | 134 | evergreen_crtc_load_lut(crtc); |
|
103 | if (ASIC_IS_AVIVO(rdev)) |
135 | else if (ASIC_IS_AVIVO(rdev)) |
104 | avivo_crtc_load_lut(crtc); |
136 | avivo_crtc_load_lut(crtc); |
105 | else |
137 | else |
106 | legacy_crtc_load_lut(crtc); |
138 | legacy_crtc_load_lut(crtc); |
107 | } |
139 | } |
108 | 140 | ||
109 | /** Sets the color ramps on behalf of fbcon */ |
141 | /** Sets the color ramps on behalf of fbcon */ |
110 | void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
142 | void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
111 | u16 blue, int regno) |
143 | u16 blue, int regno) |
112 | { |
144 | { |
113 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
145 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
114 | 146 | ||
115 | radeon_crtc->lut_r[regno] = red >> 6; |
147 | radeon_crtc->lut_r[regno] = red >> 6; |
116 | radeon_crtc->lut_g[regno] = green >> 6; |
148 | radeon_crtc->lut_g[regno] = green >> 6; |
117 | radeon_crtc->lut_b[regno] = blue >> 6; |
149 | radeon_crtc->lut_b[regno] = blue >> 6; |
118 | } |
150 | } |
119 | 151 | ||
120 | /** Gets the color ramps on behalf of fbcon */ |
152 | /** Gets the color ramps on behalf of fbcon */ |
121 | void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
153 | void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
122 | u16 *blue, int regno) |
154 | u16 *blue, int regno) |
123 | { |
155 | { |
124 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
156 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
125 | 157 | ||
126 | *red = radeon_crtc->lut_r[regno] << 6; |
158 | *red = radeon_crtc->lut_r[regno] << 6; |
127 | *green = radeon_crtc->lut_g[regno] << 6; |
159 | *green = radeon_crtc->lut_g[regno] << 6; |
128 | *blue = radeon_crtc->lut_b[regno] << 6; |
160 | *blue = radeon_crtc->lut_b[regno] << 6; |
129 | } |
161 | } |
130 | 162 | ||
131 | static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
163 | static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
132 | u16 *blue, uint32_t size) |
164 | u16 *blue, uint32_t size) |
133 | { |
165 | { |
134 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
166 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
135 | int i; |
167 | int i; |
136 | 168 | ||
137 | if (size != 256) { |
169 | if (size != 256) { |
138 | return; |
170 | return; |
139 | } |
171 | } |
140 | 172 | ||
141 | /* userspace palettes are always correct as is */ |
173 | /* userspace palettes are always correct as is */ |
142 | for (i = 0; i < 256; i++) { |
174 | for (i = 0; i < 256; i++) { |
143 | radeon_crtc->lut_r[i] = red[i] >> 6; |
175 | radeon_crtc->lut_r[i] = red[i] >> 6; |
144 | radeon_crtc->lut_g[i] = green[i] >> 6; |
176 | radeon_crtc->lut_g[i] = green[i] >> 6; |
145 | radeon_crtc->lut_b[i] = blue[i] >> 6; |
177 | radeon_crtc->lut_b[i] = blue[i] >> 6; |
146 | } |
178 | } |
147 | radeon_crtc_load_lut(crtc); |
179 | radeon_crtc_load_lut(crtc); |
148 | } |
180 | } |
149 | 181 | ||
150 | static void radeon_crtc_destroy(struct drm_crtc *crtc) |
182 | static void radeon_crtc_destroy(struct drm_crtc *crtc) |
151 | { |
183 | { |
152 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
184 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
153 | 185 | ||
154 | drm_crtc_cleanup(crtc); |
186 | drm_crtc_cleanup(crtc); |
155 | kfree(radeon_crtc); |
187 | kfree(radeon_crtc); |
156 | } |
188 | } |
157 | 189 | ||
158 | static const struct drm_crtc_funcs radeon_crtc_funcs = { |
190 | static const struct drm_crtc_funcs radeon_crtc_funcs = { |
159 | .cursor_set = NULL, |
191 | .cursor_set = NULL, |
160 | .cursor_move = NULL, |
192 | .cursor_move = NULL, |
161 | .gamma_set = radeon_crtc_gamma_set, |
193 | .gamma_set = radeon_crtc_gamma_set, |
162 | .set_config = drm_crtc_helper_set_config, |
194 | .set_config = drm_crtc_helper_set_config, |
163 | .destroy = radeon_crtc_destroy, |
195 | .destroy = radeon_crtc_destroy, |
164 | }; |
196 | }; |
165 | 197 | ||
166 | static void radeon_crtc_init(struct drm_device *dev, int index) |
198 | static void radeon_crtc_init(struct drm_device *dev, int index) |
167 | { |
199 | { |
168 | struct radeon_device *rdev = dev->dev_private; |
200 | struct radeon_device *rdev = dev->dev_private; |
169 | struct radeon_crtc *radeon_crtc; |
201 | struct radeon_crtc *radeon_crtc; |
170 | int i; |
202 | int i; |
171 | 203 | ||
172 | radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
204 | radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
173 | if (radeon_crtc == NULL) |
205 | if (radeon_crtc == NULL) |
174 | return; |
206 | return; |
175 | 207 | ||
176 | drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs); |
208 | drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs); |
177 | 209 | ||
178 | drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256); |
210 | drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256); |
179 | radeon_crtc->crtc_id = index; |
211 | radeon_crtc->crtc_id = index; |
180 | rdev->mode_info.crtcs[index] = radeon_crtc; |
212 | rdev->mode_info.crtcs[index] = radeon_crtc; |
181 | 213 | ||
182 | #if 0 |
214 | #if 0 |
183 | radeon_crtc->mode_set.crtc = &radeon_crtc->base; |
215 | radeon_crtc->mode_set.crtc = &radeon_crtc->base; |
184 | radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1); |
216 | radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1); |
185 | radeon_crtc->mode_set.num_connectors = 0; |
217 | radeon_crtc->mode_set.num_connectors = 0; |
186 | #endif |
218 | #endif |
187 | 219 | ||
188 | for (i = 0; i < 256; i++) { |
220 | for (i = 0; i < 256; i++) { |
189 | radeon_crtc->lut_r[i] = i << 2; |
221 | radeon_crtc->lut_r[i] = i << 2; |
190 | radeon_crtc->lut_g[i] = i << 2; |
222 | radeon_crtc->lut_g[i] = i << 2; |
191 | radeon_crtc->lut_b[i] = i << 2; |
223 | radeon_crtc->lut_b[i] = i << 2; |
192 | } |
224 | } |
193 | 225 | ||
194 | if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)) |
226 | if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)) |
195 | radeon_atombios_init_crtc(dev, radeon_crtc); |
227 | radeon_atombios_init_crtc(dev, radeon_crtc); |
196 | else |
228 | else |
197 | radeon_legacy_init_crtc(dev, radeon_crtc); |
229 | radeon_legacy_init_crtc(dev, radeon_crtc); |
198 | } |
230 | } |
199 | 231 | ||
200 | static const char *encoder_names[34] = { |
232 | static const char *encoder_names[34] = { |
201 | "NONE", |
233 | "NONE", |
202 | "INTERNAL_LVDS", |
234 | "INTERNAL_LVDS", |
203 | "INTERNAL_TMDS1", |
235 | "INTERNAL_TMDS1", |
204 | "INTERNAL_TMDS2", |
236 | "INTERNAL_TMDS2", |
205 | "INTERNAL_DAC1", |
237 | "INTERNAL_DAC1", |
206 | "INTERNAL_DAC2", |
238 | "INTERNAL_DAC2", |
207 | "INTERNAL_SDVOA", |
239 | "INTERNAL_SDVOA", |
208 | "INTERNAL_SDVOB", |
240 | "INTERNAL_SDVOB", |
209 | "SI170B", |
241 | "SI170B", |
210 | "CH7303", |
242 | "CH7303", |
211 | "CH7301", |
243 | "CH7301", |
212 | "INTERNAL_DVO1", |
244 | "INTERNAL_DVO1", |
213 | "EXTERNAL_SDVOA", |
245 | "EXTERNAL_SDVOA", |
214 | "EXTERNAL_SDVOB", |
246 | "EXTERNAL_SDVOB", |
215 | "TITFP513", |
247 | "TITFP513", |
216 | "INTERNAL_LVTM1", |
248 | "INTERNAL_LVTM1", |
217 | "VT1623", |
249 | "VT1623", |
218 | "HDMI_SI1930", |
250 | "HDMI_SI1930", |
219 | "HDMI_INTERNAL", |
251 | "HDMI_INTERNAL", |
220 | "INTERNAL_KLDSCP_TMDS1", |
252 | "INTERNAL_KLDSCP_TMDS1", |
221 | "INTERNAL_KLDSCP_DVO1", |
253 | "INTERNAL_KLDSCP_DVO1", |
222 | "INTERNAL_KLDSCP_DAC1", |
254 | "INTERNAL_KLDSCP_DAC1", |
223 | "INTERNAL_KLDSCP_DAC2", |
255 | "INTERNAL_KLDSCP_DAC2", |
224 | "SI178", |
256 | "SI178", |
225 | "MVPU_FPGA", |
257 | "MVPU_FPGA", |
226 | "INTERNAL_DDI", |
258 | "INTERNAL_DDI", |
227 | "VT1625", |
259 | "VT1625", |
228 | "HDMI_SI1932", |
260 | "HDMI_SI1932", |
229 | "DP_AN9801", |
261 | "DP_AN9801", |
230 | "DP_DP501", |
262 | "DP_DP501", |
231 | "INTERNAL_UNIPHY", |
263 | "INTERNAL_UNIPHY", |
232 | "INTERNAL_KLDSCP_LVTMA", |
264 | "INTERNAL_KLDSCP_LVTMA", |
233 | "INTERNAL_UNIPHY1", |
265 | "INTERNAL_UNIPHY1", |
234 | "INTERNAL_UNIPHY2", |
266 | "INTERNAL_UNIPHY2", |
235 | }; |
267 | }; |
236 | 268 | ||
237 | static const char *connector_names[15] = { |
269 | static const char *connector_names[15] = { |
238 | "Unknown", |
270 | "Unknown", |
239 | "VGA", |
271 | "VGA", |
240 | "DVI-I", |
272 | "DVI-I", |
241 | "DVI-D", |
273 | "DVI-D", |
242 | "DVI-A", |
274 | "DVI-A", |
243 | "Composite", |
275 | "Composite", |
244 | "S-video", |
276 | "S-video", |
245 | "LVDS", |
277 | "LVDS", |
246 | "Component", |
278 | "Component", |
247 | "DIN", |
279 | "DIN", |
248 | "DisplayPort", |
280 | "DisplayPort", |
249 | "HDMI-A", |
281 | "HDMI-A", |
250 | "HDMI-B", |
282 | "HDMI-B", |
251 | "TV", |
283 | "TV", |
252 | "eDP", |
284 | "eDP", |
253 | }; |
285 | }; |
254 | 286 | ||
255 | static const char *hpd_names[7] = { |
287 | static const char *hpd_names[7] = { |
256 | "NONE", |
288 | "NONE", |
257 | "HPD1", |
289 | "HPD1", |
258 | "HPD2", |
290 | "HPD2", |
259 | "HPD3", |
291 | "HPD3", |
260 | "HPD4", |
292 | "HPD4", |
261 | "HPD5", |
293 | "HPD5", |
262 | "HPD6", |
294 | "HPD6", |
263 | }; |
295 | }; |
264 | 296 | ||
265 | static void radeon_print_display_setup(struct drm_device *dev) |
297 | static void radeon_print_display_setup(struct drm_device *dev) |
266 | { |
298 | { |
267 | struct drm_connector *connector; |
299 | struct drm_connector *connector; |
268 | struct radeon_connector *radeon_connector; |
300 | struct radeon_connector *radeon_connector; |
269 | struct drm_encoder *encoder; |
301 | struct drm_encoder *encoder; |
270 | struct radeon_encoder *radeon_encoder; |
302 | struct radeon_encoder *radeon_encoder; |
271 | uint32_t devices; |
303 | uint32_t devices; |
272 | int i = 0; |
304 | int i = 0; |
273 | 305 | ||
274 | DRM_INFO("Radeon Display Connectors\n"); |
306 | DRM_INFO("Radeon Display Connectors\n"); |
275 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
307 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
276 | radeon_connector = to_radeon_connector(connector); |
308 | radeon_connector = to_radeon_connector(connector); |
277 | DRM_INFO("Connector %d:\n", i); |
309 | DRM_INFO("Connector %d:\n", i); |
278 | DRM_INFO(" %s\n", connector_names[connector->connector_type]); |
310 | DRM_INFO(" %s\n", connector_names[connector->connector_type]); |
279 | if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) |
311 | if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) |
280 | DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]); |
312 | DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]); |
281 | if (radeon_connector->ddc_bus) { |
313 | if (radeon_connector->ddc_bus) { |
282 | DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
314 | DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", |
283 | radeon_connector->ddc_bus->rec.mask_clk_reg, |
315 | radeon_connector->ddc_bus->rec.mask_clk_reg, |
284 | radeon_connector->ddc_bus->rec.mask_data_reg, |
316 | radeon_connector->ddc_bus->rec.mask_data_reg, |
285 | radeon_connector->ddc_bus->rec.a_clk_reg, |
317 | radeon_connector->ddc_bus->rec.a_clk_reg, |
286 | radeon_connector->ddc_bus->rec.a_data_reg, |
318 | radeon_connector->ddc_bus->rec.a_data_reg, |
287 | radeon_connector->ddc_bus->rec.en_clk_reg, |
319 | radeon_connector->ddc_bus->rec.en_clk_reg, |
288 | radeon_connector->ddc_bus->rec.en_data_reg, |
320 | radeon_connector->ddc_bus->rec.en_data_reg, |
289 | radeon_connector->ddc_bus->rec.y_clk_reg, |
321 | radeon_connector->ddc_bus->rec.y_clk_reg, |
290 | radeon_connector->ddc_bus->rec.y_data_reg); |
322 | radeon_connector->ddc_bus->rec.y_data_reg); |
291 | } else { |
323 | } else { |
292 | if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || |
324 | if (connector->connector_type == DRM_MODE_CONNECTOR_VGA || |
293 | connector->connector_type == DRM_MODE_CONNECTOR_DVII || |
325 | connector->connector_type == DRM_MODE_CONNECTOR_DVII || |
294 | connector->connector_type == DRM_MODE_CONNECTOR_DVID || |
326 | connector->connector_type == DRM_MODE_CONNECTOR_DVID || |
295 | connector->connector_type == DRM_MODE_CONNECTOR_DVIA || |
327 | connector->connector_type == DRM_MODE_CONNECTOR_DVIA || |
296 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || |
328 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || |
297 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) |
329 | connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) |
298 | DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n"); |
330 | DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n"); |
299 | } |
331 | } |
300 | DRM_INFO(" Encoders:\n"); |
332 | DRM_INFO(" Encoders:\n"); |
301 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
333 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
302 | radeon_encoder = to_radeon_encoder(encoder); |
334 | radeon_encoder = to_radeon_encoder(encoder); |
303 | devices = radeon_encoder->devices & radeon_connector->devices; |
335 | devices = radeon_encoder->devices & radeon_connector->devices; |
304 | if (devices) { |
336 | if (devices) { |
305 | if (devices & ATOM_DEVICE_CRT1_SUPPORT) |
337 | if (devices & ATOM_DEVICE_CRT1_SUPPORT) |
306 | DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
338 | DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
307 | if (devices & ATOM_DEVICE_CRT2_SUPPORT) |
339 | if (devices & ATOM_DEVICE_CRT2_SUPPORT) |
308 | DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
340 | DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
309 | if (devices & ATOM_DEVICE_LCD1_SUPPORT) |
341 | if (devices & ATOM_DEVICE_LCD1_SUPPORT) |
310 | DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
342 | DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
311 | if (devices & ATOM_DEVICE_DFP1_SUPPORT) |
343 | if (devices & ATOM_DEVICE_DFP1_SUPPORT) |
312 | DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
344 | DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
313 | if (devices & ATOM_DEVICE_DFP2_SUPPORT) |
345 | if (devices & ATOM_DEVICE_DFP2_SUPPORT) |
314 | DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
346 | DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]); |
315 | if (devices & ATOM_DEVICE_DFP3_SUPPORT) |
347 | if (devices & ATOM_DEVICE_DFP3_SUPPORT) |
316 | DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]); |
348 | DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]); |
317 | if (devices & ATOM_DEVICE_DFP4_SUPPORT) |
349 | if (devices & ATOM_DEVICE_DFP4_SUPPORT) |
318 | DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]); |
350 | DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]); |
319 | if (devices & ATOM_DEVICE_DFP5_SUPPORT) |
351 | if (devices & ATOM_DEVICE_DFP5_SUPPORT) |
320 | DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]); |
352 | DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]); |
321 | if (devices & ATOM_DEVICE_TV1_SUPPORT) |
353 | if (devices & ATOM_DEVICE_TV1_SUPPORT) |
322 | DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
354 | DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]); |
323 | if (devices & ATOM_DEVICE_CV_SUPPORT) |
355 | if (devices & ATOM_DEVICE_CV_SUPPORT) |
324 | DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]); |
356 | DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]); |
325 | } |
357 | } |
326 | } |
358 | } |
327 | i++; |
359 | i++; |
328 | } |
360 | } |
329 | } |
361 | } |
330 | 362 | ||
331 | static bool radeon_setup_enc_conn(struct drm_device *dev) |
363 | static bool radeon_setup_enc_conn(struct drm_device *dev) |
332 | { |
364 | { |
333 | struct radeon_device *rdev = dev->dev_private; |
365 | struct radeon_device *rdev = dev->dev_private; |
334 | struct drm_connector *drm_connector; |
366 | struct drm_connector *drm_connector; |
335 | bool ret = false; |
367 | bool ret = false; |
336 | 368 | ||
337 | if (rdev->bios) { |
369 | if (rdev->bios) { |
338 | if (rdev->is_atom_bios) { |
370 | if (rdev->is_atom_bios) { |
339 | if (rdev->family >= CHIP_R600) |
371 | if (rdev->family >= CHIP_R600) |
340 | ret = radeon_get_atom_connector_info_from_object_table(dev); |
372 | ret = radeon_get_atom_connector_info_from_object_table(dev); |
341 | else |
373 | else |
342 | ret = radeon_get_atom_connector_info_from_supported_devices_table(dev); |
374 | ret = radeon_get_atom_connector_info_from_supported_devices_table(dev); |
343 | } else { |
375 | } else { |
344 | ret = radeon_get_legacy_connector_info_from_bios(dev); |
376 | ret = radeon_get_legacy_connector_info_from_bios(dev); |
345 | if (ret == false) |
377 | if (ret == false) |
346 | ret = radeon_get_legacy_connector_info_from_table(dev); |
378 | ret = radeon_get_legacy_connector_info_from_table(dev); |
347 | } |
379 | } |
348 | } else { |
380 | } else { |
349 | if (!ASIC_IS_AVIVO(rdev)) |
381 | if (!ASIC_IS_AVIVO(rdev)) |
350 | ret = radeon_get_legacy_connector_info_from_table(dev); |
382 | ret = radeon_get_legacy_connector_info_from_table(dev); |
351 | } |
383 | } |
352 | if (ret) { |
384 | if (ret) { |
353 | radeon_setup_encoder_clones(dev); |
385 | radeon_setup_encoder_clones(dev); |
354 | radeon_print_display_setup(dev); |
386 | radeon_print_display_setup(dev); |
355 | list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) |
387 | list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) |
356 | radeon_ddc_dump(drm_connector); |
388 | radeon_ddc_dump(drm_connector); |
357 | } |
389 | } |
358 | 390 | ||
359 | return ret; |
391 | return ret; |
360 | } |
392 | } |
361 | 393 | ||
362 | int radeon_ddc_get_modes(struct radeon_connector *radeon_connector) |
394 | int radeon_ddc_get_modes(struct radeon_connector *radeon_connector) |
363 | { |
395 | { |
- | 396 | struct drm_device *dev = radeon_connector->base.dev; |
|
- | 397 | struct radeon_device *rdev = dev->dev_private; |
|
364 | int ret = 0; |
398 | int ret = 0; |
365 | 399 | ||
366 | if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || |
400 | if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) || |
367 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { |
401 | (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) { |
368 | struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; |
402 | struct radeon_connector_atom_dig *dig = radeon_connector->con_priv; |
369 | if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || |
403 | if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT || |
370 | dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && dig->dp_i2c_bus) |
404 | dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && dig->dp_i2c_bus) |
371 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &dig->dp_i2c_bus->adapter); |
405 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &dig->dp_i2c_bus->adapter); |
372 | } |
406 | } |
373 | if (!radeon_connector->ddc_bus) |
407 | if (!radeon_connector->ddc_bus) |
374 | return -1; |
408 | return -1; |
375 | if (!radeon_connector->edid) { |
409 | if (!radeon_connector->edid) { |
376 | radeon_i2c_do_lock(radeon_connector->ddc_bus, 1); |
- | |
377 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); |
410 | radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter); |
378 | radeon_i2c_do_lock(radeon_connector->ddc_bus, 0); |
- | |
379 | } |
411 | } |
380 | - | ||
- | 412 | /* some servers provide a hardcoded edid in rom for KVMs */ |
|
- | 413 | if (!radeon_connector->edid) |
|
- | 414 | radeon_connector->edid = radeon_combios_get_hardcoded_edid(rdev); |
|
381 | if (radeon_connector->edid) { |
415 | if (radeon_connector->edid) { |
382 | drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid); |
416 | drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid); |
383 | ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid); |
417 | ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid); |
384 | return ret; |
418 | return ret; |
385 | } |
419 | } |
386 | drm_mode_connector_update_edid_property(&radeon_connector->base, NULL); |
420 | drm_mode_connector_update_edid_property(&radeon_connector->base, NULL); |
387 | return 0; |
421 | return 0; |
388 | } |
422 | } |
389 | 423 | ||
390 | static int radeon_ddc_dump(struct drm_connector *connector) |
424 | static int radeon_ddc_dump(struct drm_connector *connector) |
391 | { |
425 | { |
392 | struct edid *edid; |
426 | struct edid *edid; |
393 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
427 | struct radeon_connector *radeon_connector = to_radeon_connector(connector); |
394 | int ret = 0; |
428 | int ret = 0; |
395 | 429 | ||
396 | if (!radeon_connector->ddc_bus) |
430 | if (!radeon_connector->ddc_bus) |
397 | return -1; |
431 | return -1; |
398 | radeon_i2c_do_lock(radeon_connector->ddc_bus, 1); |
- | |
399 | edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); |
432 | edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter); |
400 | radeon_i2c_do_lock(radeon_connector->ddc_bus, 0); |
- | |
401 | if (edid) { |
433 | if (edid) { |
402 | kfree(edid); |
434 | kfree(edid); |
403 | } |
435 | } |
404 | return ret; |
436 | return ret; |
405 | } |
437 | } |
406 | 438 | ||
407 | static inline uint32_t radeon_div(uint64_t n, uint32_t d) |
439 | static inline uint32_t radeon_div(uint64_t n, uint32_t d) |
408 | { |
440 | { |
409 | uint64_t mod; |
441 | uint64_t mod; |
410 | 442 | ||
411 | n += d / 2; |
443 | n += d / 2; |
412 | 444 | ||
413 | mod = do_div(n, d); |
445 | mod = do_div(n, d); |
414 | return n; |
446 | return n; |
415 | } |
447 | } |
416 | 448 | ||
417 | void radeon_compute_pll(struct radeon_pll *pll, |
449 | static void radeon_compute_pll_legacy(struct radeon_pll *pll, |
418 | uint64_t freq, |
450 | uint64_t freq, |
419 | uint32_t *dot_clock_p, |
451 | uint32_t *dot_clock_p, |
420 | uint32_t *fb_div_p, |
452 | uint32_t *fb_div_p, |
421 | uint32_t *frac_fb_div_p, |
453 | uint32_t *frac_fb_div_p, |
422 | uint32_t *ref_div_p, |
454 | uint32_t *ref_div_p, |
423 | uint32_t *post_div_p) |
455 | uint32_t *post_div_p) |
424 | { |
456 | { |
425 | uint32_t min_ref_div = pll->min_ref_div; |
457 | uint32_t min_ref_div = pll->min_ref_div; |
426 | uint32_t max_ref_div = pll->max_ref_div; |
458 | uint32_t max_ref_div = pll->max_ref_div; |
427 | uint32_t min_post_div = pll->min_post_div; |
459 | uint32_t min_post_div = pll->min_post_div; |
428 | uint32_t max_post_div = pll->max_post_div; |
460 | uint32_t max_post_div = pll->max_post_div; |
429 | uint32_t min_fractional_feed_div = 0; |
461 | uint32_t min_fractional_feed_div = 0; |
430 | uint32_t max_fractional_feed_div = 0; |
462 | uint32_t max_fractional_feed_div = 0; |
431 | uint32_t best_vco = pll->best_vco; |
463 | uint32_t best_vco = pll->best_vco; |
432 | uint32_t best_post_div = 1; |
464 | uint32_t best_post_div = 1; |
433 | uint32_t best_ref_div = 1; |
465 | uint32_t best_ref_div = 1; |
434 | uint32_t best_feedback_div = 1; |
466 | uint32_t best_feedback_div = 1; |
435 | uint32_t best_frac_feedback_div = 0; |
467 | uint32_t best_frac_feedback_div = 0; |
436 | uint32_t best_freq = -1; |
468 | uint32_t best_freq = -1; |
437 | uint32_t best_error = 0xffffffff; |
469 | uint32_t best_error = 0xffffffff; |
438 | uint32_t best_vco_diff = 1; |
470 | uint32_t best_vco_diff = 1; |
439 | uint32_t post_div; |
471 | uint32_t post_div; |
440 | 472 | ||
441 | DRM_DEBUG("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div); |
473 | DRM_DEBUG("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div); |
442 | freq = freq * 1000; |
474 | freq = freq * 1000; |
443 | 475 | ||
444 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
476 | if (pll->flags & RADEON_PLL_USE_REF_DIV) |
445 | min_ref_div = max_ref_div = pll->reference_div; |
477 | min_ref_div = max_ref_div = pll->reference_div; |
446 | else { |
478 | else { |
447 | while (min_ref_div < max_ref_div-1) { |
479 | while (min_ref_div < max_ref_div-1) { |
448 | uint32_t mid = (min_ref_div + max_ref_div) / 2; |
480 | uint32_t mid = (min_ref_div + max_ref_div) / 2; |
449 | uint32_t pll_in = pll->reference_freq / mid; |
481 | uint32_t pll_in = pll->reference_freq / mid; |
450 | if (pll_in < pll->pll_in_min) |
482 | if (pll_in < pll->pll_in_min) |
451 | max_ref_div = mid; |
483 | max_ref_div = mid; |
452 | else if (pll_in > pll->pll_in_max) |
484 | else if (pll_in > pll->pll_in_max) |
453 | min_ref_div = mid; |
485 | min_ref_div = mid; |
454 | else |
486 | else |
455 | break; |
487 | break; |
456 | } |
488 | } |
457 | } |
489 | } |
458 | 490 | ||
459 | if (pll->flags & RADEON_PLL_USE_POST_DIV) |
491 | if (pll->flags & RADEON_PLL_USE_POST_DIV) |
460 | min_post_div = max_post_div = pll->post_div; |
492 | min_post_div = max_post_div = pll->post_div; |
461 | 493 | ||
462 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
494 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
463 | min_fractional_feed_div = pll->min_frac_feedback_div; |
495 | min_fractional_feed_div = pll->min_frac_feedback_div; |
464 | max_fractional_feed_div = pll->max_frac_feedback_div; |
496 | max_fractional_feed_div = pll->max_frac_feedback_div; |
465 | } |
497 | } |
466 | 498 | ||
467 | for (post_div = min_post_div; post_div <= max_post_div; ++post_div) { |
499 | for (post_div = min_post_div; post_div <= max_post_div; ++post_div) { |
468 | uint32_t ref_div; |
500 | uint32_t ref_div; |
469 | 501 | ||
470 | if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1)) |
502 | if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1)) |
471 | continue; |
503 | continue; |
472 | 504 | ||
473 | /* legacy radeons only have a few post_divs */ |
505 | /* legacy radeons only have a few post_divs */ |
474 | if (pll->flags & RADEON_PLL_LEGACY) { |
506 | if (pll->flags & RADEON_PLL_LEGACY) { |
475 | if ((post_div == 5) || |
507 | if ((post_div == 5) || |
476 | (post_div == 7) || |
508 | (post_div == 7) || |
477 | (post_div == 9) || |
509 | (post_div == 9) || |
478 | (post_div == 10) || |
510 | (post_div == 10) || |
479 | (post_div == 11) || |
511 | (post_div == 11) || |
480 | (post_div == 13) || |
512 | (post_div == 13) || |
481 | (post_div == 14) || |
513 | (post_div == 14) || |
482 | (post_div == 15)) |
514 | (post_div == 15)) |
483 | continue; |
515 | continue; |
484 | } |
516 | } |
485 | 517 | ||
486 | for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) { |
518 | for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) { |
487 | uint32_t feedback_div, current_freq = 0, error, vco_diff; |
519 | uint32_t feedback_div, current_freq = 0, error, vco_diff; |
488 | uint32_t pll_in = pll->reference_freq / ref_div; |
520 | uint32_t pll_in = pll->reference_freq / ref_div; |
489 | uint32_t min_feed_div = pll->min_feedback_div; |
521 | uint32_t min_feed_div = pll->min_feedback_div; |
490 | uint32_t max_feed_div = pll->max_feedback_div + 1; |
522 | uint32_t max_feed_div = pll->max_feedback_div + 1; |
491 | 523 | ||
492 | if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max) |
524 | if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max) |
493 | continue; |
525 | continue; |
494 | 526 | ||
495 | while (min_feed_div < max_feed_div) { |
527 | while (min_feed_div < max_feed_div) { |
496 | uint32_t vco; |
528 | uint32_t vco; |
497 | uint32_t min_frac_feed_div = min_fractional_feed_div; |
529 | uint32_t min_frac_feed_div = min_fractional_feed_div; |
498 | uint32_t max_frac_feed_div = max_fractional_feed_div + 1; |
530 | uint32_t max_frac_feed_div = max_fractional_feed_div + 1; |
499 | uint32_t frac_feedback_div; |
531 | uint32_t frac_feedback_div; |
500 | uint64_t tmp; |
532 | uint64_t tmp; |
501 | 533 | ||
502 | feedback_div = (min_feed_div + max_feed_div) / 2; |
534 | feedback_div = (min_feed_div + max_feed_div) / 2; |
503 | 535 | ||
504 | tmp = (uint64_t)pll->reference_freq * feedback_div; |
536 | tmp = (uint64_t)pll->reference_freq * feedback_div; |
505 | vco = radeon_div(tmp, ref_div); |
537 | vco = radeon_div(tmp, ref_div); |
506 | 538 | ||
507 | if (vco < pll->pll_out_min) { |
539 | if (vco < pll->pll_out_min) { |
508 | min_feed_div = feedback_div + 1; |
540 | min_feed_div = feedback_div + 1; |
509 | continue; |
541 | continue; |
510 | } else if (vco > pll->pll_out_max) { |
542 | } else if (vco > pll->pll_out_max) { |
511 | max_feed_div = feedback_div; |
543 | max_feed_div = feedback_div; |
512 | continue; |
544 | continue; |
513 | } |
545 | } |
514 | 546 | ||
515 | while (min_frac_feed_div < max_frac_feed_div) { |
547 | while (min_frac_feed_div < max_frac_feed_div) { |
516 | frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2; |
548 | frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2; |
517 | tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div; |
549 | tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div; |
518 | tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div; |
550 | tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div; |
519 | current_freq = radeon_div(tmp, ref_div * post_div); |
551 | current_freq = radeon_div(tmp, ref_div * post_div); |
520 | 552 | ||
521 | if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) { |
553 | if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) { |
522 | error = freq - current_freq; |
554 | error = freq - current_freq; |
523 | error = error < 0 ? 0xffffffff : error; |
555 | error = error < 0 ? 0xffffffff : error; |
524 | } else |
556 | } else |
525 | error = abs(current_freq - freq); |
557 | error = abs(current_freq - freq); |
526 | vco_diff = abs(vco - best_vco); |
558 | vco_diff = abs(vco - best_vco); |
527 | 559 | ||
528 | if ((best_vco == 0 && error < best_error) || |
560 | if ((best_vco == 0 && error < best_error) || |
529 | (best_vco != 0 && |
561 | (best_vco != 0 && |
530 | (error < best_error - 100 || |
562 | (error < best_error - 100 || |
531 | (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) { |
563 | (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) { |
532 | best_post_div = post_div; |
564 | best_post_div = post_div; |
533 | best_ref_div = ref_div; |
565 | best_ref_div = ref_div; |
534 | best_feedback_div = feedback_div; |
566 | best_feedback_div = feedback_div; |
535 | best_frac_feedback_div = frac_feedback_div; |
567 | best_frac_feedback_div = frac_feedback_div; |
536 | best_freq = current_freq; |
568 | best_freq = current_freq; |
537 | best_error = error; |
569 | best_error = error; |
538 | best_vco_diff = vco_diff; |
570 | best_vco_diff = vco_diff; |
539 | } else if (current_freq == freq) { |
571 | } else if (current_freq == freq) { |
540 | if (best_freq == -1) { |
572 | if (best_freq == -1) { |
541 | best_post_div = post_div; |
573 | best_post_div = post_div; |
542 | best_ref_div = ref_div; |
574 | best_ref_div = ref_div; |
543 | best_feedback_div = feedback_div; |
575 | best_feedback_div = feedback_div; |
544 | best_frac_feedback_div = frac_feedback_div; |
576 | best_frac_feedback_div = frac_feedback_div; |
545 | best_freq = current_freq; |
577 | best_freq = current_freq; |
546 | best_error = error; |
578 | best_error = error; |
547 | best_vco_diff = vco_diff; |
579 | best_vco_diff = vco_diff; |
548 | } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) || |
580 | } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) || |
549 | ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) || |
581 | ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) || |
550 | ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) || |
582 | ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) || |
551 | ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) || |
583 | ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) || |
552 | ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) || |
584 | ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) || |
553 | ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) { |
585 | ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) { |
554 | best_post_div = post_div; |
586 | best_post_div = post_div; |
555 | best_ref_div = ref_div; |
587 | best_ref_div = ref_div; |
556 | best_feedback_div = feedback_div; |
588 | best_feedback_div = feedback_div; |
557 | best_frac_feedback_div = frac_feedback_div; |
589 | best_frac_feedback_div = frac_feedback_div; |
558 | best_freq = current_freq; |
590 | best_freq = current_freq; |
559 | best_error = error; |
591 | best_error = error; |
560 | best_vco_diff = vco_diff; |
592 | best_vco_diff = vco_diff; |
561 | } |
593 | } |
562 | } |
594 | } |
563 | if (current_freq < freq) |
595 | if (current_freq < freq) |
564 | min_frac_feed_div = frac_feedback_div + 1; |
596 | min_frac_feed_div = frac_feedback_div + 1; |
565 | else |
597 | else |
566 | max_frac_feed_div = frac_feedback_div; |
598 | max_frac_feed_div = frac_feedback_div; |
567 | } |
599 | } |
568 | if (current_freq < freq) |
600 | if (current_freq < freq) |
569 | min_feed_div = feedback_div + 1; |
601 | min_feed_div = feedback_div + 1; |
570 | else |
602 | else |
571 | max_feed_div = feedback_div; |
603 | max_feed_div = feedback_div; |
572 | } |
604 | } |
573 | } |
605 | } |
574 | } |
606 | } |
575 | 607 | ||
576 | *dot_clock_p = best_freq / 10000; |
608 | *dot_clock_p = best_freq / 10000; |
577 | *fb_div_p = best_feedback_div; |
609 | *fb_div_p = best_feedback_div; |
578 | *frac_fb_div_p = best_frac_feedback_div; |
610 | *frac_fb_div_p = best_frac_feedback_div; |
579 | *ref_div_p = best_ref_div; |
611 | *ref_div_p = best_ref_div; |
580 | *post_div_p = best_post_div; |
612 | *post_div_p = best_post_div; |
581 | } |
613 | } |
- | 614 | ||
- | 615 | static bool |
|
- | 616 | calc_fb_div(struct radeon_pll *pll, |
|
- | 617 | uint32_t freq, |
|
- | 618 | uint32_t post_div, |
|
- | 619 | uint32_t ref_div, |
|
- | 620 | uint32_t *fb_div, |
|
- | 621 | uint32_t *fb_div_frac) |
|
- | 622 | { |
|
- | 623 | fixed20_12 feedback_divider, a, b; |
|
- | 624 | u32 vco_freq; |
|
- | 625 | ||
- | 626 | vco_freq = freq * post_div; |
|
- | 627 | /* feedback_divider = vco_freq * ref_div / pll->reference_freq; */ |
|
- | 628 | a.full = rfixed_const(pll->reference_freq); |
|
- | 629 | feedback_divider.full = rfixed_const(vco_freq); |
|
- | 630 | feedback_divider.full = rfixed_div(feedback_divider, a); |
|
- | 631 | a.full = rfixed_const(ref_div); |
|
- | 632 | feedback_divider.full = rfixed_mul(feedback_divider, a); |
|
- | 633 | ||
- | 634 | if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) { |
|
- | 635 | /* feedback_divider = floor((feedback_divider * 10.0) + 0.5) * 0.1; */ |
|
- | 636 | a.full = rfixed_const(10); |
|
- | 637 | feedback_divider.full = rfixed_mul(feedback_divider, a); |
|
- | 638 | feedback_divider.full += rfixed_const_half(0); |
|
- | 639 | feedback_divider.full = rfixed_floor(feedback_divider); |
|
- | 640 | feedback_divider.full = rfixed_div(feedback_divider, a); |
|
- | 641 | ||
- | 642 | /* *fb_div = floor(feedback_divider); */ |
|
- | 643 | a.full = rfixed_floor(feedback_divider); |
|
- | 644 | *fb_div = rfixed_trunc(a); |
|
- | 645 | /* *fb_div_frac = fmod(feedback_divider, 1.0) * 10.0; */ |
|
- | 646 | a.full = rfixed_const(10); |
|
- | 647 | b.full = rfixed_mul(feedback_divider, a); |
|
- | 648 | ||
- | 649 | feedback_divider.full = rfixed_floor(feedback_divider); |
|
- | 650 | feedback_divider.full = rfixed_mul(feedback_divider, a); |
|
- | 651 | feedback_divider.full = b.full - feedback_divider.full; |
|
- | 652 | *fb_div_frac = rfixed_trunc(feedback_divider); |
|
- | 653 | } else { |
|
- | 654 | /* *fb_div = floor(feedback_divider + 0.5); */ |
|
- | 655 | feedback_divider.full += rfixed_const_half(0); |
|
- | 656 | feedback_divider.full = rfixed_floor(feedback_divider); |
|
- | 657 | ||
- | 658 | *fb_div = rfixed_trunc(feedback_divider); |
|
- | 659 | *fb_div_frac = 0; |
|
- | 660 | } |
|
- | 661 | ||
- | 662 | if (((*fb_div) < pll->min_feedback_div) || ((*fb_div) > pll->max_feedback_div)) |
|
- | 663 | return false; |
|
- | 664 | else |
|
- | 665 | return true; |
|
- | 666 | } |
|
- | 667 | ||
- | 668 | static bool |
|
- | 669 | calc_fb_ref_div(struct radeon_pll *pll, |
|
- | 670 | uint32_t freq, |
|
- | 671 | uint32_t post_div, |
|
- | 672 | uint32_t *fb_div, |
|
- | 673 | uint32_t *fb_div_frac, |
|
- | 674 | uint32_t *ref_div) |
|
- | 675 | { |
|
- | 676 | fixed20_12 ffreq, max_error, error, pll_out, a; |
|
- | 677 | u32 vco; |
|
- | 678 | ||
- | 679 | ffreq.full = rfixed_const(freq); |
|
- | 680 | /* max_error = ffreq * 0.0025; */ |
|
- | 681 | a.full = rfixed_const(400); |
|
- | 682 | max_error.full = rfixed_div(ffreq, a); |
|
- | 683 | ||
- | 684 | for ((*ref_div) = pll->min_ref_div; (*ref_div) < pll->max_ref_div; ++(*ref_div)) { |
|
- | 685 | if (calc_fb_div(pll, freq, post_div, (*ref_div), fb_div, fb_div_frac)) { |
|
- | 686 | vco = pll->reference_freq * (((*fb_div) * 10) + (*fb_div_frac)); |
|
- | 687 | vco = vco / ((*ref_div) * 10); |
|
- | 688 | ||
- | 689 | if ((vco < pll->pll_out_min) || (vco > pll->pll_out_max)) |
|
- | 690 | continue; |
|
- | 691 | ||
- | 692 | /* pll_out = vco / post_div; */ |
|
- | 693 | a.full = rfixed_const(post_div); |
|
- | 694 | pll_out.full = rfixed_const(vco); |
|
- | 695 | pll_out.full = rfixed_div(pll_out, a); |
|
- | 696 | ||
- | 697 | if (pll_out.full >= ffreq.full) { |
|
- | 698 | error.full = pll_out.full - ffreq.full; |
|
- | 699 | if (error.full <= max_error.full) |
|
- | 700 | return true; |
|
- | 701 | } |
|
- | 702 | } |
|
- | 703 | } |
|
- | 704 | return false; |
|
- | 705 | } |
|
582 | 706 | ||
583 | void radeon_compute_pll_avivo(struct radeon_pll *pll, |
707 | static void radeon_compute_pll_new(struct radeon_pll *pll, |
584 | uint64_t freq, |
708 | uint64_t freq, |
585 | uint32_t *dot_clock_p, |
709 | uint32_t *dot_clock_p, |
586 | uint32_t *fb_div_p, |
710 | uint32_t *fb_div_p, |
587 | uint32_t *frac_fb_div_p, |
711 | uint32_t *frac_fb_div_p, |
588 | uint32_t *ref_div_p, |
712 | uint32_t *ref_div_p, |
589 | uint32_t *post_div_p) |
713 | uint32_t *post_div_p) |
590 | { |
714 | { |
591 | fixed20_12 m, n, frac_n, p, f_vco, f_pclk, best_freq; |
715 | u32 fb_div = 0, fb_div_frac = 0, post_div = 0, ref_div = 0; |
592 | fixed20_12 pll_out_max, pll_out_min; |
- | |
593 | fixed20_12 pll_in_max, pll_in_min; |
- | |
594 | fixed20_12 reference_freq; |
- | |
595 | fixed20_12 error, ffreq, a, b; |
716 | u32 best_freq = 0, vco_frequency; |
596 | - | ||
597 | pll_out_max.full = rfixed_const(pll->pll_out_max); |
- | |
598 | pll_out_min.full = rfixed_const(pll->pll_out_min); |
- | |
599 | pll_in_max.full = rfixed_const(pll->pll_in_max); |
- | |
600 | pll_in_min.full = rfixed_const(pll->pll_in_min); |
- | |
601 | reference_freq.full = rfixed_const(pll->reference_freq); |
- | |
602 | do_div(freq, 10); |
- | |
603 | ffreq.full = rfixed_const(freq); |
- | |
604 | error.full = rfixed_const(100 * 100); |
- | |
605 | - | ||
606 | /* max p */ |
- | |
607 | p.full = rfixed_div(pll_out_max, ffreq); |
- | |
608 | p.full = rfixed_floor(p); |
- | |
609 | - | ||
610 | /* min m */ |
- | |
611 | m.full = rfixed_div(reference_freq, pll_in_max); |
- | |
612 | m.full = rfixed_ceil(m); |
- | |
613 | - | ||
614 | while (1) { |
- | |
615 | n.full = rfixed_div(ffreq, reference_freq); |
- | |
616 | n.full = rfixed_mul(n, m); |
- | |
617 | n.full = rfixed_mul(n, p); |
- | |
618 | - | ||
619 | f_vco.full = rfixed_div(n, m); |
- | |
620 | f_vco.full = rfixed_mul(f_vco, reference_freq); |
- | |
621 | - | ||
622 | f_pclk.full = rfixed_div(f_vco, p); |
- | |
623 | - | ||
624 | if (f_pclk.full > ffreq.full) |
- | |
625 | error.full = f_pclk.full - ffreq.full; |
- | |
626 | else |
- | |
627 | error.full = ffreq.full - f_pclk.full; |
- | |
628 | error.full = rfixed_div(error, f_pclk); |
- | |
629 | a.full = rfixed_const(100 * 100); |
- | |
630 | error.full = rfixed_mul(error, a); |
- | |
631 | 717 | ||
632 | a.full = rfixed_mul(m, p); |
718 | /* freq = freq / 10; */ |
633 | a.full = rfixed_div(n, a); |
- | |
- | 719 | do_div(freq, 10); |
|
- | 720 | ||
- | 721 | if (pll->flags & RADEON_PLL_USE_POST_DIV) { |
|
- | 722 | post_div = pll->post_div; |
|
- | 723 | if ((post_div < pll->min_post_div) || (post_div > pll->max_post_div)) |
|
- | 724 | goto done; |
|
- | 725 | ||
- | 726 | vco_frequency = freq * post_div; |
|
- | 727 | if ((vco_frequency < pll->pll_out_min) || (vco_frequency > pll->pll_out_max)) |
|
- | 728 | goto done; |
|
- | 729 | ||
- | 730 | if (pll->flags & RADEON_PLL_USE_REF_DIV) { |
|
- | 731 | ref_div = pll->reference_div; |
|
- | 732 | if ((ref_div < pll->min_ref_div) || (ref_div > pll->max_ref_div)) |
|
- | 733 | goto done; |
|
- | 734 | if (!calc_fb_div(pll, freq, post_div, ref_div, &fb_div, &fb_div_frac)) |
|
- | 735 | goto done; |
|
- | 736 | } |
|
- | 737 | } else { |
|
634 | best_freq.full = rfixed_mul(reference_freq, a); |
738 | for (post_div = pll->max_post_div; post_div >= pll->min_post_div; --post_div) { |
- | 739 | if (pll->flags & RADEON_PLL_LEGACY) { |
|
- | 740 | if ((post_div == 5) || |
|
- | 741 | (post_div == 7) || |
|
- | 742 | (post_div == 9) || |
|
- | 743 | (post_div == 10) || |
|
635 | 744 | (post_div == 11)) |
|
636 | if (rfixed_trunc(error) < 25) |
- | |
637 | break; |
- | |
638 | 745 | continue; |
|
639 | a.full = rfixed_const(1); |
- | |
640 | m.full = m.full + a.full; |
746 | } |
641 | a.full = rfixed_div(reference_freq, m); |
- | |
642 | if (a.full >= pll_in_min.full) |
- | |
643 | continue; |
- | |
644 | 747 | ||
645 | m.full = rfixed_div(reference_freq, pll_in_max); |
- | |
646 | m.full = rfixed_ceil(m); |
748 | if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1)) |
647 | a.full= rfixed_const(1); |
749 | continue; |
- | 750 | ||
- | 751 | vco_frequency = freq * post_div; |
|
- | 752 | if ((vco_frequency < pll->pll_out_min) || (vco_frequency > pll->pll_out_max)) |
|
- | 753 | continue; |
|
- | 754 | if (pll->flags & RADEON_PLL_USE_REF_DIV) { |
|
- | 755 | ref_div = pll->reference_div; |
|
648 | p.full = p.full - a.full; |
756 | if ((ref_div < pll->min_ref_div) || (ref_div > pll->max_ref_div)) |
649 | a.full = rfixed_mul(p, ffreq); |
757 | goto done; |
650 | if (a.full >= pll_out_min.full) |
758 | if (calc_fb_div(pll, freq, post_div, ref_div, &fb_div, &fb_div_frac)) |
651 | continue; |
759 | break; |
652 | else { |
760 | } else { |
653 | DRM_ERROR("Unable to find pll dividers\n"); |
761 | if (calc_fb_ref_div(pll, freq, post_div, &fb_div, &fb_div_frac, &ref_div)) |
654 | break; |
762 | break; |
655 | } |
763 | } |
656 | } |
764 | } |
- | 765 | } |
|
- | 766 | ||
- | 767 | best_freq = pll->reference_freq * 10 * fb_div; |
|
- | 768 | best_freq += pll->reference_freq * fb_div_frac; |
|
- | 769 | best_freq = best_freq / (ref_div * post_div); |
|
- | 770 | ||
657 | 771 | done: |
|
- | 772 | if (best_freq == 0) |
|
- | 773 | DRM_ERROR("Couldn't find valid PLL dividers\n"); |
|
658 | a.full = rfixed_const(10); |
774 | |
- | 775 | *dot_clock_p = best_freq / 10; |
|
- | 776 | *fb_div_p = fb_div; |
|
- | 777 | *frac_fb_div_p = fb_div_frac; |
|
- | 778 | *ref_div_p = ref_div; |
|
659 | b.full = rfixed_mul(n, a); |
- | |
660 | 779 | *post_div_p = post_div; |
|
661 | frac_n.full = rfixed_floor(n); |
- | |
662 | frac_n.full = rfixed_mul(frac_n, a); |
780 | |
663 | frac_n.full = b.full - frac_n.full; |
- | |
664 | - | ||
665 | *dot_clock_p = rfixed_trunc(best_freq); |
- | |
666 | *fb_div_p = rfixed_trunc(n); |
- | |
667 | *frac_fb_div_p = rfixed_trunc(frac_n); |
- | |
- | 781 | DRM_DEBUG("%u %d.%d, %d, %d\n", *dot_clock_p, *fb_div_p, *frac_fb_div_p, *ref_div_p, *post_div_p); |
|
- | 782 | } |
|
- | 783 | ||
- | 784 | void radeon_compute_pll(struct radeon_pll *pll, |
|
- | 785 | uint64_t freq, |
|
- | 786 | uint32_t *dot_clock_p, |
|
- | 787 | uint32_t *fb_div_p, |
|
- | 788 | uint32_t *frac_fb_div_p, |
|
- | 789 | uint32_t *ref_div_p, |
|
- | 790 | uint32_t *post_div_p) |
|
- | 791 | { |
|
668 | *ref_div_p = rfixed_trunc(m); |
792 | switch (pll->algo) { |
- | 793 | case PLL_ALGO_NEW: |
|
- | 794 | radeon_compute_pll_new(pll, freq, dot_clock_p, fb_div_p, |
|
- | 795 | frac_fb_div_p, ref_div_p, post_div_p); |
|
- | 796 | break; |
|
- | 797 | case PLL_ALGO_LEGACY: |
|
- | 798 | default: |
|
- | 799 | radeon_compute_pll_legacy(pll, freq, dot_clock_p, fb_div_p, |
|
669 | *post_div_p = rfixed_trunc(p); |
800 | frac_fb_div_p, ref_div_p, post_div_p); |
670 | 801 | break; |
|
671 | DRM_DEBUG("%u %d.%d, %d, %d\n", *dot_clock_p * 10, *fb_div_p, *frac_fb_div_p, *ref_div_p, *post_div_p); |
802 | } |
672 | } |
803 | } |
673 | 804 | ||
674 | static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb) |
805 | static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb) |
675 | { |
806 | { |
676 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
807 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
677 | struct drm_device *dev = fb->dev; |
808 | struct drm_device *dev = fb->dev; |
678 | 809 | ||
679 | if (fb->fbdev) |
810 | if (fb->fbdev) |
680 | radeonfb_remove(dev, fb); |
811 | radeonfb_remove(dev, fb); |
681 | 812 | ||
682 | // if (radeon_fb->obj) { |
813 | // if (radeon_fb->obj) { |
683 | // radeon_gem_object_unpin(radeon_fb->obj); |
814 | // radeon_gem_object_unpin(radeon_fb->obj); |
684 | // mutex_lock(&dev->struct_mutex); |
815 | // mutex_lock(&dev->struct_mutex); |
685 | // drm_gem_object_unreference(radeon_fb->obj); |
816 | // drm_gem_object_unreference(radeon_fb->obj); |
686 | // mutex_unlock(&dev->struct_mutex); |
817 | // mutex_unlock(&dev->struct_mutex); |
687 | // } |
818 | // } |
688 | drm_framebuffer_cleanup(fb); |
819 | drm_framebuffer_cleanup(fb); |
689 | kfree(radeon_fb); |
820 | kfree(radeon_fb); |
690 | } |
821 | } |
691 | 822 | ||
692 | static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
823 | static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
693 | struct drm_file *file_priv, |
824 | struct drm_file *file_priv, |
694 | unsigned int *handle) |
825 | unsigned int *handle) |
695 | { |
826 | { |
696 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
827 | struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); |
697 | 828 | ||
698 | return NULL; |
829 | return NULL; |
699 | // return drm_gem_handle_create(file_priv, radeon_fb->obj, handle); |
830 | // return drm_gem_handle_create(file_priv, radeon_fb->obj, handle); |
700 | } |
831 | } |
701 | 832 | ||
702 | static const struct drm_framebuffer_funcs radeon_fb_funcs = { |
833 | static const struct drm_framebuffer_funcs radeon_fb_funcs = { |
703 | .destroy = radeon_user_framebuffer_destroy, |
834 | .destroy = radeon_user_framebuffer_destroy, |
704 | .create_handle = radeon_user_framebuffer_create_handle, |
835 | .create_handle = radeon_user_framebuffer_create_handle, |
705 | }; |
836 | }; |
706 | 837 | ||
707 | struct drm_framebuffer * |
838 | struct drm_framebuffer * |
708 | radeon_framebuffer_create(struct drm_device *dev, |
839 | radeon_framebuffer_create(struct drm_device *dev, |
709 | struct drm_mode_fb_cmd *mode_cmd, |
840 | struct drm_mode_fb_cmd *mode_cmd, |
710 | struct drm_gem_object *obj) |
841 | struct drm_gem_object *obj) |
711 | { |
842 | { |
712 | struct radeon_framebuffer *radeon_fb; |
843 | struct radeon_framebuffer *radeon_fb; |
713 | 844 | ||
714 | radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL); |
845 | radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL); |
715 | if (radeon_fb == NULL) { |
846 | if (radeon_fb == NULL) { |
716 | return NULL; |
847 | return NULL; |
717 | } |
848 | } |
718 | drm_framebuffer_init(dev, &radeon_fb->base, &radeon_fb_funcs); |
849 | drm_framebuffer_init(dev, &radeon_fb->base, &radeon_fb_funcs); |
719 | drm_helper_mode_fill_fb_struct(&radeon_fb->base, mode_cmd); |
850 | drm_helper_mode_fill_fb_struct(&radeon_fb->base, mode_cmd); |
720 | radeon_fb->obj = obj; |
851 | radeon_fb->obj = obj; |
721 | return &radeon_fb->base; |
852 | return &radeon_fb->base; |
722 | } |
853 | } |
723 | 854 | ||
724 | static struct drm_framebuffer * |
855 | static struct drm_framebuffer * |
725 | radeon_user_framebuffer_create(struct drm_device *dev, |
856 | radeon_user_framebuffer_create(struct drm_device *dev, |
726 | struct drm_file *file_priv, |
857 | struct drm_file *file_priv, |
727 | struct drm_mode_fb_cmd *mode_cmd) |
858 | struct drm_mode_fb_cmd *mode_cmd) |
728 | { |
859 | { |
729 | struct drm_gem_object *obj; |
860 | struct drm_gem_object *obj; |
730 | 861 | ||
731 | return NULL; |
862 | return NULL; |
732 | 863 | ||
733 | // obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); |
864 | // obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); |
734 | // |
865 | // |
735 | // return radeon_framebuffer_create(dev, mode_cmd, obj); |
866 | // return radeon_framebuffer_create(dev, mode_cmd, obj); |
736 | } |
867 | } |
737 | 868 | ||
738 | static const struct drm_mode_config_funcs radeon_mode_funcs = { |
869 | static const struct drm_mode_config_funcs radeon_mode_funcs = { |
739 | // .fb_create = radeon_user_framebuffer_create, |
870 | // .fb_create = radeon_user_framebuffer_create, |
740 | .fb_changed = radeonfb_probe, |
871 | .fb_changed = radeonfb_probe, |
741 | }; |
872 | }; |
742 | 873 | ||
743 | struct drm_prop_enum_list { |
874 | struct drm_prop_enum_list { |
744 | int type; |
875 | int type; |
745 | char *name; |
876 | char *name; |
746 | }; |
877 | }; |
747 | 878 | ||
748 | static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] = |
879 | static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] = |
749 | { { 0, "driver" }, |
880 | { { 0, "driver" }, |
750 | { 1, "bios" }, |
881 | { 1, "bios" }, |
751 | }; |
882 | }; |
752 | 883 | ||
753 | static struct drm_prop_enum_list radeon_tv_std_enum_list[] = |
884 | static struct drm_prop_enum_list radeon_tv_std_enum_list[] = |
754 | { { TV_STD_NTSC, "ntsc" }, |
885 | { { TV_STD_NTSC, "ntsc" }, |
755 | { TV_STD_PAL, "pal" }, |
886 | { TV_STD_PAL, "pal" }, |
756 | { TV_STD_PAL_M, "pal-m" }, |
887 | { TV_STD_PAL_M, "pal-m" }, |
757 | { TV_STD_PAL_60, "pal-60" }, |
888 | { TV_STD_PAL_60, "pal-60" }, |
758 | { TV_STD_NTSC_J, "ntsc-j" }, |
889 | { TV_STD_NTSC_J, "ntsc-j" }, |
759 | { TV_STD_SCART_PAL, "scart-pal" }, |
890 | { TV_STD_SCART_PAL, "scart-pal" }, |
760 | { TV_STD_PAL_CN, "pal-cn" }, |
891 | { TV_STD_PAL_CN, "pal-cn" }, |
761 | { TV_STD_SECAM, "secam" }, |
892 | { TV_STD_SECAM, "secam" }, |
762 | }; |
893 | }; |
763 | 894 | ||
764 | static int radeon_modeset_create_props(struct radeon_device *rdev) |
895 | static int radeon_modeset_create_props(struct radeon_device *rdev) |
765 | { |
896 | { |
766 | int i, sz; |
897 | int i, sz; |
767 | 898 | ||
768 | if (rdev->is_atom_bios) { |
899 | if (rdev->is_atom_bios) { |
769 | rdev->mode_info.coherent_mode_property = |
900 | rdev->mode_info.coherent_mode_property = |
770 | drm_property_create(rdev->ddev, |
901 | drm_property_create(rdev->ddev, |
771 | DRM_MODE_PROP_RANGE, |
902 | DRM_MODE_PROP_RANGE, |
772 | "coherent", 2); |
903 | "coherent", 2); |
773 | if (!rdev->mode_info.coherent_mode_property) |
904 | if (!rdev->mode_info.coherent_mode_property) |
774 | return -ENOMEM; |
905 | return -ENOMEM; |
775 | 906 | ||
776 | rdev->mode_info.coherent_mode_property->values[0] = 0; |
907 | rdev->mode_info.coherent_mode_property->values[0] = 0; |
777 | rdev->mode_info.coherent_mode_property->values[1] = 1; |
908 | rdev->mode_info.coherent_mode_property->values[1] = 1; |
778 | } |
909 | } |
779 | 910 | ||
780 | if (!ASIC_IS_AVIVO(rdev)) { |
911 | if (!ASIC_IS_AVIVO(rdev)) { |
781 | sz = ARRAY_SIZE(radeon_tmds_pll_enum_list); |
912 | sz = ARRAY_SIZE(radeon_tmds_pll_enum_list); |
782 | rdev->mode_info.tmds_pll_property = |
913 | rdev->mode_info.tmds_pll_property = |
783 | drm_property_create(rdev->ddev, |
914 | drm_property_create(rdev->ddev, |
784 | DRM_MODE_PROP_ENUM, |
915 | DRM_MODE_PROP_ENUM, |
785 | "tmds_pll", sz); |
916 | "tmds_pll", sz); |
786 | for (i = 0; i < sz; i++) { |
917 | for (i = 0; i < sz; i++) { |
787 | drm_property_add_enum(rdev->mode_info.tmds_pll_property, |
918 | drm_property_add_enum(rdev->mode_info.tmds_pll_property, |
788 | i, |
919 | i, |
789 | radeon_tmds_pll_enum_list[i].type, |
920 | radeon_tmds_pll_enum_list[i].type, |
790 | radeon_tmds_pll_enum_list[i].name); |
921 | radeon_tmds_pll_enum_list[i].name); |
791 | } |
922 | } |
792 | } |
923 | } |
793 | 924 | ||
794 | rdev->mode_info.load_detect_property = |
925 | rdev->mode_info.load_detect_property = |
795 | drm_property_create(rdev->ddev, |
926 | drm_property_create(rdev->ddev, |
796 | DRM_MODE_PROP_RANGE, |
927 | DRM_MODE_PROP_RANGE, |
797 | "load detection", 2); |
928 | "load detection", 2); |
798 | if (!rdev->mode_info.load_detect_property) |
929 | if (!rdev->mode_info.load_detect_property) |
799 | return -ENOMEM; |
930 | return -ENOMEM; |
800 | rdev->mode_info.load_detect_property->values[0] = 0; |
931 | rdev->mode_info.load_detect_property->values[0] = 0; |
801 | rdev->mode_info.load_detect_property->values[1] = 1; |
932 | rdev->mode_info.load_detect_property->values[1] = 1; |
802 | 933 | ||
803 | drm_mode_create_scaling_mode_property(rdev->ddev); |
934 | drm_mode_create_scaling_mode_property(rdev->ddev); |
804 | 935 | ||
805 | sz = ARRAY_SIZE(radeon_tv_std_enum_list); |
936 | sz = ARRAY_SIZE(radeon_tv_std_enum_list); |
806 | rdev->mode_info.tv_std_property = |
937 | rdev->mode_info.tv_std_property = |
807 | drm_property_create(rdev->ddev, |
938 | drm_property_create(rdev->ddev, |
808 | DRM_MODE_PROP_ENUM, |
939 | DRM_MODE_PROP_ENUM, |
809 | "tv standard", sz); |
940 | "tv standard", sz); |
810 | for (i = 0; i < sz; i++) { |
941 | for (i = 0; i < sz; i++) { |
811 | drm_property_add_enum(rdev->mode_info.tv_std_property, |
942 | drm_property_add_enum(rdev->mode_info.tv_std_property, |
812 | i, |
943 | i, |
813 | radeon_tv_std_enum_list[i].type, |
944 | radeon_tv_std_enum_list[i].type, |
814 | radeon_tv_std_enum_list[i].name); |
945 | radeon_tv_std_enum_list[i].name); |
815 | } |
946 | } |
816 | 947 | ||
817 | return 0; |
948 | return 0; |
818 | } |
949 | } |
819 | 950 | ||
820 | int radeon_modeset_init(struct radeon_device *rdev) |
951 | int radeon_modeset_init(struct radeon_device *rdev) |
821 | { |
952 | { |
822 | int num_crtc = 2, i; |
953 | int i; |
823 | int ret; |
954 | int ret; |
824 | 955 | ||
825 | drm_mode_config_init(rdev->ddev); |
956 | drm_mode_config_init(rdev->ddev); |
826 | rdev->mode_info.mode_config_initialized = true; |
957 | rdev->mode_info.mode_config_initialized = true; |
827 | 958 | ||
828 | rdev->ddev->mode_config.funcs = (void *)&radeon_mode_funcs; |
959 | rdev->ddev->mode_config.funcs = (void *)&radeon_mode_funcs; |
829 | 960 | ||
830 | if (ASIC_IS_AVIVO(rdev)) { |
961 | if (ASIC_IS_AVIVO(rdev)) { |
831 | rdev->ddev->mode_config.max_width = 8192; |
962 | rdev->ddev->mode_config.max_width = 8192; |
832 | rdev->ddev->mode_config.max_height = 8192; |
963 | rdev->ddev->mode_config.max_height = 8192; |
833 | } else { |
964 | } else { |
834 | rdev->ddev->mode_config.max_width = 4096; |
965 | rdev->ddev->mode_config.max_width = 4096; |
835 | rdev->ddev->mode_config.max_height = 4096; |
966 | rdev->ddev->mode_config.max_height = 4096; |
836 | } |
967 | } |
837 | 968 | ||
838 | rdev->ddev->mode_config.fb_base = rdev->mc.aper_base; |
969 | rdev->ddev->mode_config.fb_base = rdev->mc.aper_base; |
839 | 970 | ||
840 | ret = radeon_modeset_create_props(rdev); |
971 | ret = radeon_modeset_create_props(rdev); |
841 | if (ret) { |
972 | if (ret) { |
842 | return ret; |
973 | return ret; |
843 | } |
974 | } |
- | 975 | ||
- | 976 | /* check combios for a valid hardcoded EDID - Sun servers */ |
|
- | 977 | if (!rdev->is_atom_bios) { |
|
- | 978 | /* check for hardcoded EDID in BIOS */ |
|
- | 979 | radeon_combios_check_hardcoded_edid(rdev); |
|
- | 980 | } |
|
844 | 981 | ||
845 | if (rdev->flags & RADEON_SINGLE_CRTC) |
982 | if (rdev->flags & RADEON_SINGLE_CRTC) |
- | 983 | rdev->num_crtc = 1; |
|
- | 984 | else { |
|
- | 985 | if (ASIC_IS_DCE4(rdev)) |
|
- | 986 | rdev->num_crtc = 6; |
|
- | 987 | else |
|
- | 988 | rdev->num_crtc = 2; |
|
846 | num_crtc = 1; |
989 | } |
847 | 990 | ||
848 | /* allocate crtcs */ |
991 | /* allocate crtcs */ |
849 | for (i = 0; i < num_crtc; i++) { |
992 | for (i = 0; i < rdev->num_crtc; i++) { |
850 | radeon_crtc_init(rdev->ddev, i); |
993 | radeon_crtc_init(rdev->ddev, i); |
851 | } |
994 | } |
852 | 995 | ||
853 | /* okay we should have all the bios connectors */ |
996 | /* okay we should have all the bios connectors */ |
854 | ret = radeon_setup_enc_conn(rdev->ddev); |
997 | ret = radeon_setup_enc_conn(rdev->ddev); |
855 | if (!ret) { |
998 | if (!ret) { |
856 | return ret; |
999 | return ret; |
857 | } |
1000 | } |
858 | /* initialize hpd */ |
1001 | /* initialize hpd */ |
859 | radeon_hpd_init(rdev); |
1002 | radeon_hpd_init(rdev); |
860 | drm_helper_initial_config(rdev->ddev); |
1003 | drm_helper_initial_config(rdev->ddev); |
861 | return 0; |
1004 | return 0; |
862 | } |
1005 | } |
863 | 1006 | ||
864 | void radeon_modeset_fini(struct radeon_device *rdev) |
1007 | void radeon_modeset_fini(struct radeon_device *rdev) |
865 | { |
1008 | { |
- | 1009 | kfree(rdev->mode_info.bios_hardcoded_edid); |
|
- | 1010 | ||
866 | if (rdev->mode_info.mode_config_initialized) { |
1011 | if (rdev->mode_info.mode_config_initialized) { |
867 | radeon_hpd_fini(rdev); |
1012 | radeon_hpd_fini(rdev); |
868 | drm_mode_config_cleanup(rdev->ddev); |
1013 | drm_mode_config_cleanup(rdev->ddev); |
869 | rdev->mode_info.mode_config_initialized = false; |
1014 | rdev->mode_info.mode_config_initialized = false; |
870 | } |
1015 | } |
871 | } |
1016 | } |
872 | 1017 | ||
873 | bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, |
1018 | bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc, |
874 | struct drm_display_mode *mode, |
1019 | struct drm_display_mode *mode, |
875 | struct drm_display_mode *adjusted_mode) |
1020 | struct drm_display_mode *adjusted_mode) |
876 | { |
1021 | { |
877 | struct drm_device *dev = crtc->dev; |
1022 | struct drm_device *dev = crtc->dev; |
878 | struct drm_encoder *encoder; |
1023 | struct drm_encoder *encoder; |
879 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
1024 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
880 | struct radeon_encoder *radeon_encoder; |
1025 | struct radeon_encoder *radeon_encoder; |
881 | bool first = true; |
1026 | bool first = true; |
882 | 1027 | ||
883 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
1028 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
884 | radeon_encoder = to_radeon_encoder(encoder); |
1029 | radeon_encoder = to_radeon_encoder(encoder); |
885 | if (encoder->crtc != crtc) |
1030 | if (encoder->crtc != crtc) |
886 | continue; |
1031 | continue; |
887 | if (first) { |
1032 | if (first) { |
888 | /* set scaling */ |
1033 | /* set scaling */ |
889 | if (radeon_encoder->rmx_type == RMX_OFF) |
1034 | if (radeon_encoder->rmx_type == RMX_OFF) |
890 | radeon_crtc->rmx_type = RMX_OFF; |
1035 | radeon_crtc->rmx_type = RMX_OFF; |
891 | else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay || |
1036 | else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay || |
892 | mode->vdisplay < radeon_encoder->native_mode.vdisplay) |
1037 | mode->vdisplay < radeon_encoder->native_mode.vdisplay) |
893 | radeon_crtc->rmx_type = radeon_encoder->rmx_type; |
1038 | radeon_crtc->rmx_type = radeon_encoder->rmx_type; |
894 | else |
1039 | else |
895 | radeon_crtc->rmx_type = RMX_OFF; |
1040 | radeon_crtc->rmx_type = RMX_OFF; |
896 | /* copy native mode */ |
1041 | /* copy native mode */ |
897 | memcpy(&radeon_crtc->native_mode, |
1042 | memcpy(&radeon_crtc->native_mode, |
898 | &radeon_encoder->native_mode, |
1043 | &radeon_encoder->native_mode, |
899 | sizeof(struct drm_display_mode)); |
1044 | sizeof(struct drm_display_mode)); |
900 | first = false; |
1045 | first = false; |
901 | } else { |
1046 | } else { |
902 | if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) { |
1047 | if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) { |
903 | /* WARNING: Right now this can't happen but |
1048 | /* WARNING: Right now this can't happen but |
904 | * in the future we need to check that scaling |
1049 | * in the future we need to check that scaling |
905 | * are consistent accross different encoder |
1050 | * are consistent accross different encoder |
906 | * (ie all encoder can work with the same |
1051 | * (ie all encoder can work with the same |
907 | * scaling). |
1052 | * scaling). |
908 | */ |
1053 | */ |
909 | DRM_ERROR("Scaling not consistent accross encoder.\n"); |
1054 | DRM_ERROR("Scaling not consistent accross encoder.\n"); |
910 | return false; |
1055 | return false; |
911 | } |
1056 | } |
912 | } |
1057 | } |
913 | } |
1058 | } |
914 | if (radeon_crtc->rmx_type != RMX_OFF) { |
1059 | if (radeon_crtc->rmx_type != RMX_OFF) { |
915 | fixed20_12 a, b; |
1060 | fixed20_12 a, b; |
916 | a.full = rfixed_const(crtc->mode.vdisplay); |
1061 | a.full = rfixed_const(crtc->mode.vdisplay); |
917 | b.full = rfixed_const(radeon_crtc->native_mode.hdisplay); |
1062 | b.full = rfixed_const(radeon_crtc->native_mode.hdisplay); |
918 | radeon_crtc->vsc.full = rfixed_div(a, b); |
1063 | radeon_crtc->vsc.full = rfixed_div(a, b); |
919 | a.full = rfixed_const(crtc->mode.hdisplay); |
1064 | a.full = rfixed_const(crtc->mode.hdisplay); |
920 | b.full = rfixed_const(radeon_crtc->native_mode.vdisplay); |
1065 | b.full = rfixed_const(radeon_crtc->native_mode.vdisplay); |
921 | radeon_crtc->hsc.full = rfixed_div(a, b); |
1066 | radeon_crtc->hsc.full = rfixed_div(a, b); |
922 | } else { |
1067 | } else { |
923 | radeon_crtc->vsc.full = rfixed_const(1); |
1068 | radeon_crtc->vsc.full = rfixed_const(1); |
924 | radeon_crtc->hsc.full = rfixed_const(1); |
1069 | radeon_crtc->hsc.full = rfixed_const(1); |
925 | } |
1070 | } |
926 | return true; |
1071 | return true; |
927 | }>>>>>>>>>>>>>>>>>>>>=>=>>>><>><>><>>>><>><>><>><>><>><>>><>><>><>> |
1072 | }>>>>>>>>>>=>>>>>>>>>>>>>>>>>>=>=>>>><>><>><>>>><>><>><>><>><>><>>><>><>><>>><>><>><>> |