blob: 817392fc2d04dacb31933bbf3dd245be6653060e [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
David Howells760285e2012-10-02 18:01:07 +010026#include <drm/drmP.h>
27#include <drm/drm_crtc_helper.h>
28#include <drm/radeon_drm.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020029#include "radeon.h"
30#include "atom.h"
Michel Dänzer63ec0112011-03-22 16:30:23 -070031#include <linux/backlight.h>
32#ifdef CONFIG_PMAC_BACKLIGHT
33#include <asm/backlight.h>
34#endif
Jerome Glisse771fe6b2009-06-05 14:42:42 +020035
Dave Airlie4ce001a2009-08-13 16:32:14 +100036static void radeon_legacy_encoder_disable(struct drm_encoder *encoder)
37{
38 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
39 struct drm_encoder_helper_funcs *encoder_funcs;
40
41 encoder_funcs = encoder->helper_private;
42 encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
43 radeon_encoder->active_device = 0;
44}
Jerome Glisse771fe6b2009-06-05 14:42:42 +020045
Michel Dänzer63ec0112011-03-22 16:30:23 -070046static void radeon_legacy_lvds_update(struct drm_encoder *encoder, int mode)
Jerome Glisse771fe6b2009-06-05 14:42:42 +020047{
48 struct drm_device *dev = encoder->dev;
49 struct radeon_device *rdev = dev->dev_private;
50 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
51 uint32_t lvds_gen_cntl, lvds_pll_cntl, pixclks_cntl, disp_pwr_man;
52 int panel_pwr_delay = 2000;
Alex Deucher3890ddf2010-01-12 11:16:57 -050053 bool is_mac = false;
Michel Dänzer63ec0112011-03-22 16:30:23 -070054 uint8_t backlight_level;
Dave Airlied9fdaaf2010-08-02 10:42:55 +100055 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +020056
Michel Dänzer63ec0112011-03-22 16:30:23 -070057 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
58 backlight_level = (lvds_gen_cntl >> RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
59
Jerome Glisse771fe6b2009-06-05 14:42:42 +020060 if (radeon_encoder->enc_priv) {
61 if (rdev->is_atom_bios) {
62 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
63 panel_pwr_delay = lvds->panel_pwr_delay;
Michel Dänzer63ec0112011-03-22 16:30:23 -070064 if (lvds->bl_dev)
65 backlight_level = lvds->backlight_level;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020066 } else {
67 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
68 panel_pwr_delay = lvds->panel_pwr_delay;
Michel Dänzer63ec0112011-03-22 16:30:23 -070069 if (lvds->bl_dev)
70 backlight_level = lvds->backlight_level;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020071 }
72 }
73
Alex Deucher3890ddf2010-01-12 11:16:57 -050074 /* macs (and possibly some x86 oem systems?) wire up LVDS strangely
75 * Taken from radeonfb.
76 */
77 if ((rdev->mode_info.connector_table == CT_IBOOK) ||
78 (rdev->mode_info.connector_table == CT_POWERBOOK_EXTERNAL) ||
79 (rdev->mode_info.connector_table == CT_POWERBOOK_INTERNAL) ||
80 (rdev->mode_info.connector_table == CT_POWERBOOK_VGA))
81 is_mac = true;
82
Jerome Glisse771fe6b2009-06-05 14:42:42 +020083 switch (mode) {
84 case DRM_MODE_DPMS_ON:
85 disp_pwr_man = RREG32(RADEON_DISP_PWR_MAN);
86 disp_pwr_man |= RADEON_AUTO_PWRUP_EN;
87 WREG32(RADEON_DISP_PWR_MAN, disp_pwr_man);
88 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
89 lvds_pll_cntl |= RADEON_LVDS_PLL_EN;
90 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
Arnd Bergmann4de833c2012-04-05 12:58:22 -060091 mdelay(1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020092
93 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
94 lvds_pll_cntl &= ~RADEON_LVDS_PLL_RESET;
95 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
96
Michel Dänzer63ec0112011-03-22 16:30:23 -070097 lvds_gen_cntl &= ~(RADEON_LVDS_DISPLAY_DIS |
98 RADEON_LVDS_BL_MOD_LEVEL_MASK);
99 lvds_gen_cntl |= (RADEON_LVDS_ON | RADEON_LVDS_EN |
100 RADEON_LVDS_DIGON | RADEON_LVDS_BLON |
101 (backlight_level << RADEON_LVDS_BL_MOD_LEVEL_SHIFT));
Alex Deucher3890ddf2010-01-12 11:16:57 -0500102 if (is_mac)
103 lvds_gen_cntl |= RADEON_LVDS_BL_MOD_EN;
Arnd Bergmann4de833c2012-04-05 12:58:22 -0600104 mdelay(panel_pwr_delay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200105 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
106 break;
107 case DRM_MODE_DPMS_STANDBY:
108 case DRM_MODE_DPMS_SUSPEND:
109 case DRM_MODE_DPMS_OFF:
110 pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
111 WREG32_PLL_P(RADEON_PIXCLKS_CNTL, 0, ~RADEON_PIXCLK_LVDS_ALWAYS_ONb);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
Alex Deucher3890ddf2010-01-12 11:16:57 -0500113 if (is_mac) {
114 lvds_gen_cntl &= ~RADEON_LVDS_BL_MOD_EN;
115 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
116 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_EN);
117 } else {
118 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
119 lvds_gen_cntl &= ~(RADEON_LVDS_ON | RADEON_LVDS_BLON | RADEON_LVDS_EN | RADEON_LVDS_DIGON);
120 }
Arnd Bergmann4de833c2012-04-05 12:58:22 -0600121 mdelay(panel_pwr_delay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200122 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
123 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
Arnd Bergmann4de833c2012-04-05 12:58:22 -0600124 mdelay(panel_pwr_delay);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200125 break;
126 }
127
128 if (rdev->is_atom_bios)
129 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
130 else
131 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100132
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200133}
134
Michel Dänzer63ec0112011-03-22 16:30:23 -0700135static void radeon_legacy_lvds_dpms(struct drm_encoder *encoder, int mode)
136{
137 struct radeon_device *rdev = encoder->dev->dev_private;
138 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
139 DRM_DEBUG("\n");
140
141 if (radeon_encoder->enc_priv) {
142 if (rdev->is_atom_bios) {
143 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
144 lvds->dpms_mode = mode;
145 } else {
146 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
147 lvds->dpms_mode = mode;
148 }
149 }
150
151 radeon_legacy_lvds_update(encoder, mode);
152}
153
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200154static void radeon_legacy_lvds_prepare(struct drm_encoder *encoder)
155{
156 struct radeon_device *rdev = encoder->dev->dev_private;
157
158 if (rdev->is_atom_bios)
159 radeon_atom_output_lock(encoder, true);
160 else
161 radeon_combios_output_lock(encoder, true);
162 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_OFF);
163}
164
165static void radeon_legacy_lvds_commit(struct drm_encoder *encoder)
166{
167 struct radeon_device *rdev = encoder->dev->dev_private;
168
169 radeon_legacy_lvds_dpms(encoder, DRM_MODE_DPMS_ON);
170 if (rdev->is_atom_bios)
171 radeon_atom_output_lock(encoder, false);
172 else
173 radeon_combios_output_lock(encoder, false);
174}
175
176static void radeon_legacy_lvds_mode_set(struct drm_encoder *encoder,
177 struct drm_display_mode *mode,
178 struct drm_display_mode *adjusted_mode)
179{
180 struct drm_device *dev = encoder->dev;
181 struct radeon_device *rdev = dev->dev_private;
182 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
183 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
184 uint32_t lvds_pll_cntl, lvds_gen_cntl, lvds_ss_gen_cntl;
185
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000186 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200187
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200188 lvds_pll_cntl = RREG32(RADEON_LVDS_PLL_CNTL);
189 lvds_pll_cntl &= ~RADEON_LVDS_PLL_EN;
190
191 lvds_ss_gen_cntl = RREG32(RADEON_LVDS_SS_GEN_CNTL);
Alex Deucher32f48ff2009-11-30 01:54:16 -0500192 if (rdev->is_atom_bios) {
193 /* LVDS_GEN_CNTL parameters are computed in LVDSEncoderControl
194 * need to call that on resume to set up the reg properly.
195 */
196 radeon_encoder->pixel_clock = adjusted_mode->clock;
197 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
198 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
199 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200200 struct radeon_encoder_lvds *lvds = (struct radeon_encoder_lvds *)radeon_encoder->enc_priv;
201 if (lvds) {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000202 DRM_DEBUG_KMS("bios LVDS_GEN_CNTL: 0x%x\n", lvds->lvds_gen_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200203 lvds_gen_cntl = lvds->lvds_gen_cntl;
204 lvds_ss_gen_cntl &= ~((0xf << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
205 (0xf << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
206 lvds_ss_gen_cntl |= ((lvds->panel_digon_delay << RADEON_LVDS_PWRSEQ_DELAY1_SHIFT) |
207 (lvds->panel_blon_delay << RADEON_LVDS_PWRSEQ_DELAY2_SHIFT));
208 } else
209 lvds_gen_cntl = RREG32(RADEON_LVDS_GEN_CNTL);
Alex Deucher32f48ff2009-11-30 01:54:16 -0500210 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200211 lvds_gen_cntl |= RADEON_LVDS_DISPLAY_DIS;
212 lvds_gen_cntl &= ~(RADEON_LVDS_ON |
213 RADEON_LVDS_BLON |
214 RADEON_LVDS_EN |
215 RADEON_LVDS_RST_FM);
216
217 if (ASIC_IS_R300(rdev))
218 lvds_pll_cntl &= ~(R300_LVDS_SRC_SEL_MASK);
219
220 if (radeon_crtc->crtc_id == 0) {
221 if (ASIC_IS_R300(rdev)) {
Jerome Glissec93bb852009-07-13 21:04:08 +0200222 if (radeon_encoder->rmx_type != RMX_OFF)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200223 lvds_pll_cntl |= R300_LVDS_SRC_SEL_RMX;
224 } else
225 lvds_gen_cntl &= ~RADEON_LVDS_SEL_CRTC2;
226 } else {
227 if (ASIC_IS_R300(rdev))
228 lvds_pll_cntl |= R300_LVDS_SRC_SEL_CRTC2;
229 else
230 lvds_gen_cntl |= RADEON_LVDS_SEL_CRTC2;
231 }
232
233 WREG32(RADEON_LVDS_GEN_CNTL, lvds_gen_cntl);
234 WREG32(RADEON_LVDS_PLL_CNTL, lvds_pll_cntl);
235 WREG32(RADEON_LVDS_SS_GEN_CNTL, lvds_ss_gen_cntl);
236
237 if (rdev->family == CHIP_RV410)
238 WREG32(RADEON_CLOCK_CNTL_INDEX, 0);
239
240 if (rdev->is_atom_bios)
241 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
242 else
243 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
244}
245
Alex Deucher80297e82009-11-12 14:55:14 -0500246static bool radeon_legacy_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200247 const struct drm_display_mode *mode,
Alex Deucher80297e82009-11-12 14:55:14 -0500248 struct drm_display_mode *adjusted_mode)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200249{
250 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
251
Alex Deucher8c2a6d72009-10-14 02:00:42 -0400252 /* set the active encoder to connector routing */
253 radeon_encoder_set_active_device(encoder);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200254 drm_mode_set_crtcinfo(adjusted_mode, 0);
255
Alex Deucher80297e82009-11-12 14:55:14 -0500256 /* get the native mode for LVDS */
Alex Deucher35153872010-04-30 12:00:44 -0400257 if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT))
258 radeon_panel_mode_fixup(encoder, adjusted_mode);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200259
260 return true;
261}
262
263static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = {
264 .dpms = radeon_legacy_lvds_dpms,
Alex Deucher80297e82009-11-12 14:55:14 -0500265 .mode_fixup = radeon_legacy_mode_fixup,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200266 .prepare = radeon_legacy_lvds_prepare,
267 .mode_set = radeon_legacy_lvds_mode_set,
268 .commit = radeon_legacy_lvds_commit,
Dave Airlie4ce001a2009-08-13 16:32:14 +1000269 .disable = radeon_legacy_encoder_disable,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200270};
271
Alex Deucher6d92f812012-09-14 09:59:26 -0400272u8
273radeon_legacy_get_backlight_level(struct radeon_encoder *radeon_encoder)
Michel Dänzer63ec0112011-03-22 16:30:23 -0700274{
Alex Deucher6d92f812012-09-14 09:59:26 -0400275 struct drm_device *dev = radeon_encoder->base.dev;
276 struct radeon_device *rdev = dev->dev_private;
277 u8 backlight_level;
278
279 backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
280 RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
281
282 return backlight_level;
283}
284
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400285void
286radeon_legacy_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
Michel Dänzer63ec0112011-03-22 16:30:23 -0700287{
Michel Dänzer63ec0112011-03-22 16:30:23 -0700288 struct drm_device *dev = radeon_encoder->base.dev;
289 struct radeon_device *rdev = dev->dev_private;
290 int dpms_mode = DRM_MODE_DPMS_ON;
291
292 if (radeon_encoder->enc_priv) {
293 if (rdev->is_atom_bios) {
294 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400295 if (lvds->backlight_level > 0)
296 dpms_mode = lvds->dpms_mode;
297 else
298 dpms_mode = DRM_MODE_DPMS_OFF;
299 lvds->backlight_level = level;
Michel Dänzer63ec0112011-03-22 16:30:23 -0700300 } else {
301 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400302 if (lvds->backlight_level > 0)
303 dpms_mode = lvds->dpms_mode;
304 else
305 dpms_mode = DRM_MODE_DPMS_OFF;
306 lvds->backlight_level = level;
Michel Dänzer63ec0112011-03-22 16:30:23 -0700307 }
308 }
309
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400310 radeon_legacy_lvds_update(&radeon_encoder->base, dpms_mode);
311}
312
Alex Deuchercd234922012-10-04 09:10:10 -0400313#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
314
315static uint8_t radeon_legacy_lvds_level(struct backlight_device *bd)
316{
317 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
318 uint8_t level;
319
320 /* Convert brightness to hardware level */
321 if (bd->props.brightness < 0)
322 level = 0;
323 else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
324 level = RADEON_MAX_BL_LEVEL;
325 else
326 level = bd->props.brightness;
327
328 if (pdata->negative)
329 level = RADEON_MAX_BL_LEVEL - level;
330
331 return level;
332}
333
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400334static int radeon_legacy_backlight_update_status(struct backlight_device *bd)
335{
336 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
337 struct radeon_encoder *radeon_encoder = pdata->encoder;
338
339 radeon_legacy_set_backlight_level(radeon_encoder,
340 radeon_legacy_lvds_level(bd));
Michel Dänzer63ec0112011-03-22 16:30:23 -0700341
342 return 0;
343}
344
345static int radeon_legacy_backlight_get_brightness(struct backlight_device *bd)
346{
347 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
348 struct radeon_encoder *radeon_encoder = pdata->encoder;
349 struct drm_device *dev = radeon_encoder->base.dev;
350 struct radeon_device *rdev = dev->dev_private;
351 uint8_t backlight_level;
352
353 backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
354 RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
355
Alex Deucher91030882012-07-26 11:05:22 -0400356 return pdata->negative ? RADEON_MAX_BL_LEVEL - backlight_level : backlight_level;
Michel Dänzer63ec0112011-03-22 16:30:23 -0700357}
358
359static const struct backlight_ops radeon_backlight_ops = {
360 .get_brightness = radeon_legacy_backlight_get_brightness,
361 .update_status = radeon_legacy_backlight_update_status,
362};
363
364void radeon_legacy_backlight_init(struct radeon_encoder *radeon_encoder,
365 struct drm_connector *drm_connector)
366{
367 struct drm_device *dev = radeon_encoder->base.dev;
368 struct radeon_device *rdev = dev->dev_private;
369 struct backlight_device *bd;
370 struct backlight_properties props;
371 struct radeon_backlight_privdata *pdata;
372 uint8_t backlight_level;
Alex Deucher614499b2012-10-17 17:20:24 -0400373 char bl_name[16];
Michel Dänzer63ec0112011-03-22 16:30:23 -0700374
375 if (!radeon_encoder->enc_priv)
376 return;
377
378#ifdef CONFIG_PMAC_BACKLIGHT
379 if (!pmac_has_backlight_type("ati") &&
380 !pmac_has_backlight_type("mnca"))
381 return;
382#endif
383
384 pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL);
385 if (!pdata) {
386 DRM_ERROR("Memory allocation failed\n");
387 goto error;
388 }
389
Corentin Charyaf437cf2012-05-22 10:29:46 +0100390 memset(&props, 0, sizeof(props));
Alex Deucher91030882012-07-26 11:05:22 -0400391 props.max_brightness = RADEON_MAX_BL_LEVEL;
Michel Dänzer63ec0112011-03-22 16:30:23 -0700392 props.type = BACKLIGHT_RAW;
Alex Deucher614499b2012-10-17 17:20:24 -0400393 snprintf(bl_name, sizeof(bl_name),
394 "radeon_bl%d", dev->primary->index);
395 bd = backlight_device_register(bl_name, &drm_connector->kdev,
Michel Dänzer63ec0112011-03-22 16:30:23 -0700396 pdata, &radeon_backlight_ops, &props);
397 if (IS_ERR(bd)) {
398 DRM_ERROR("Backlight registration failed\n");
399 goto error;
400 }
401
402 pdata->encoder = radeon_encoder;
403
404 backlight_level = (RREG32(RADEON_LVDS_GEN_CNTL) >>
405 RADEON_LVDS_BL_MOD_LEVEL_SHIFT) & 0xff;
406
407 /* First, try to detect backlight level sense based on the assumption
408 * that firmware set it up at full brightness
409 */
410 if (backlight_level == 0)
411 pdata->negative = true;
412 else if (backlight_level == 0xff)
413 pdata->negative = false;
414 else {
415 /* XXX hack... maybe some day we can figure out in what direction
416 * backlight should work on a given panel?
417 */
418 pdata->negative = (rdev->family != CHIP_RV200 &&
419 rdev->family != CHIP_RV250 &&
420 rdev->family != CHIP_RV280 &&
421 rdev->family != CHIP_RV350);
422
423#ifdef CONFIG_PMAC_BACKLIGHT
424 pdata->negative = (pdata->negative ||
425 of_machine_is_compatible("PowerBook4,3") ||
426 of_machine_is_compatible("PowerBook6,3") ||
427 of_machine_is_compatible("PowerBook6,5"));
428#endif
429 }
430
431 if (rdev->is_atom_bios) {
432 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
433 lvds->bl_dev = bd;
434 } else {
435 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
436 lvds->bl_dev = bd;
437 }
438
439 bd->props.brightness = radeon_legacy_backlight_get_brightness(bd);
440 bd->props.power = FB_BLANK_UNBLANK;
441 backlight_update_status(bd);
442
443 DRM_INFO("radeon legacy LVDS backlight initialized\n");
444
445 return;
446
447error:
448 kfree(pdata);
449 return;
450}
451
452static void radeon_legacy_backlight_exit(struct radeon_encoder *radeon_encoder)
453{
454 struct drm_device *dev = radeon_encoder->base.dev;
455 struct radeon_device *rdev = dev->dev_private;
456 struct backlight_device *bd = NULL;
457
458 if (!radeon_encoder->enc_priv)
459 return;
460
461 if (rdev->is_atom_bios) {
462 struct radeon_encoder_atom_dig *lvds = radeon_encoder->enc_priv;
463 bd = lvds->bl_dev;
464 lvds->bl_dev = NULL;
465 } else {
466 struct radeon_encoder_lvds *lvds = radeon_encoder->enc_priv;
467 bd = lvds->bl_dev;
468 lvds->bl_dev = NULL;
469 }
470
471 if (bd) {
Alex Deucher91030882012-07-26 11:05:22 -0400472 struct radeon_backlight_privdata *pdata;
Michel Dänzer63ec0112011-03-22 16:30:23 -0700473
474 pdata = bl_get_data(bd);
475 backlight_device_unregister(bd);
476 kfree(pdata);
477
478 DRM_INFO("radeon legacy LVDS backlight unloaded\n");
479 }
480}
481
482#else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
483
484void radeon_legacy_backlight_init(struct radeon_encoder *encoder)
485{
486}
487
488static void radeon_legacy_backlight_exit(struct radeon_encoder *encoder)
489{
490}
491
492#endif
493
494
495static void radeon_lvds_enc_destroy(struct drm_encoder *encoder)
496{
497 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
498
499 if (radeon_encoder->enc_priv) {
500 radeon_legacy_backlight_exit(radeon_encoder);
501 kfree(radeon_encoder->enc_priv);
502 }
503 drm_encoder_cleanup(encoder);
504 kfree(radeon_encoder);
505}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200506
507static const struct drm_encoder_funcs radeon_legacy_lvds_enc_funcs = {
Michel Dänzer63ec0112011-03-22 16:30:23 -0700508 .destroy = radeon_lvds_enc_destroy,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200509};
510
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200511static void radeon_legacy_primary_dac_dpms(struct drm_encoder *encoder, int mode)
512{
513 struct drm_device *dev = encoder->dev;
514 struct radeon_device *rdev = dev->dev_private;
515 uint32_t crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
516 uint32_t dac_cntl = RREG32(RADEON_DAC_CNTL);
517 uint32_t dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
518
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000519 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200520
521 switch (mode) {
522 case DRM_MODE_DPMS_ON:
523 crtc_ext_cntl |= RADEON_CRTC_CRT_ON;
524 dac_cntl &= ~RADEON_DAC_PDWN;
525 dac_macro_cntl &= ~(RADEON_DAC_PDWN_R |
526 RADEON_DAC_PDWN_G |
527 RADEON_DAC_PDWN_B);
528 break;
529 case DRM_MODE_DPMS_STANDBY:
530 case DRM_MODE_DPMS_SUSPEND:
531 case DRM_MODE_DPMS_OFF:
532 crtc_ext_cntl &= ~RADEON_CRTC_CRT_ON;
533 dac_cntl |= RADEON_DAC_PDWN;
534 dac_macro_cntl |= (RADEON_DAC_PDWN_R |
535 RADEON_DAC_PDWN_G |
536 RADEON_DAC_PDWN_B);
537 break;
538 }
539
Egbert Eichf8c4d702012-10-29 13:46:48 +0100540 /* handled in radeon_crtc_dpms() */
541 if (!(rdev->flags & RADEON_SINGLE_CRTC))
542 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200543 WREG32(RADEON_DAC_CNTL, dac_cntl);
544 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
545
546 if (rdev->is_atom_bios)
547 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
548 else
549 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100550
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200551}
552
553static void radeon_legacy_primary_dac_prepare(struct drm_encoder *encoder)
554{
555 struct radeon_device *rdev = encoder->dev->dev_private;
556
557 if (rdev->is_atom_bios)
558 radeon_atom_output_lock(encoder, true);
559 else
560 radeon_combios_output_lock(encoder, true);
561 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
562}
563
564static void radeon_legacy_primary_dac_commit(struct drm_encoder *encoder)
565{
566 struct radeon_device *rdev = encoder->dev->dev_private;
567
568 radeon_legacy_primary_dac_dpms(encoder, DRM_MODE_DPMS_ON);
569
570 if (rdev->is_atom_bios)
571 radeon_atom_output_lock(encoder, false);
572 else
573 radeon_combios_output_lock(encoder, false);
574}
575
576static void radeon_legacy_primary_dac_mode_set(struct drm_encoder *encoder,
577 struct drm_display_mode *mode,
578 struct drm_display_mode *adjusted_mode)
579{
580 struct drm_device *dev = encoder->dev;
581 struct radeon_device *rdev = dev->dev_private;
582 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
583 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
584 uint32_t disp_output_cntl, dac_cntl, dac2_cntl, dac_macro_cntl;
585
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000586 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200587
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200588 if (radeon_crtc->crtc_id == 0) {
589 if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
590 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
591 ~(RADEON_DISP_DAC_SOURCE_MASK);
592 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
593 } else {
594 dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~(RADEON_DAC2_DAC_CLK_SEL);
595 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
596 }
597 } else {
598 if (rdev->family == CHIP_R200 || ASIC_IS_R300(rdev)) {
599 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL) &
600 ~(RADEON_DISP_DAC_SOURCE_MASK);
601 disp_output_cntl |= RADEON_DISP_DAC_SOURCE_CRTC2;
602 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
603 } else {
604 dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC_CLK_SEL;
605 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
606 }
607 }
608
609 dac_cntl = (RADEON_DAC_MASK_ALL |
610 RADEON_DAC_VGA_ADR_EN |
611 /* TODO 6-bits */
612 RADEON_DAC_8BIT_EN);
613
614 WREG32_P(RADEON_DAC_CNTL,
615 dac_cntl,
616 RADEON_DAC_RANGE_CNTL |
617 RADEON_DAC_BLANKING);
618
619 if (radeon_encoder->enc_priv) {
620 struct radeon_encoder_primary_dac *p_dac = (struct radeon_encoder_primary_dac *)radeon_encoder->enc_priv;
621 dac_macro_cntl = p_dac->ps2_pdac_adj;
622 } else
623 dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
624 dac_macro_cntl |= RADEON_DAC_PDWN_R | RADEON_DAC_PDWN_G | RADEON_DAC_PDWN_B;
625 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
626
627 if (rdev->is_atom_bios)
628 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
629 else
630 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
631}
632
633static enum drm_connector_status radeon_legacy_primary_dac_detect(struct drm_encoder *encoder,
634 struct drm_connector *connector)
635{
636 struct drm_device *dev = encoder->dev;
637 struct radeon_device *rdev = dev->dev_private;
638 uint32_t vclk_ecp_cntl, crtc_ext_cntl;
639 uint32_t dac_ext_cntl, dac_cntl, dac_macro_cntl, tmp;
640 enum drm_connector_status found = connector_status_disconnected;
641 bool color = true;
642
643 /* save the regs we need */
644 vclk_ecp_cntl = RREG32_PLL(RADEON_VCLK_ECP_CNTL);
645 crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
646 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
647 dac_cntl = RREG32(RADEON_DAC_CNTL);
648 dac_macro_cntl = RREG32(RADEON_DAC_MACRO_CNTL);
649
650 tmp = vclk_ecp_cntl &
651 ~(RADEON_PIXCLK_ALWAYS_ONb | RADEON_PIXCLK_DAC_ALWAYS_ONb);
652 WREG32_PLL(RADEON_VCLK_ECP_CNTL, tmp);
653
654 tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
655 WREG32(RADEON_CRTC_EXT_CNTL, tmp);
656
657 tmp = RADEON_DAC_FORCE_BLANK_OFF_EN |
658 RADEON_DAC_FORCE_DATA_EN;
659
660 if (color)
661 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
662 else
663 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
664
665 if (ASIC_IS_R300(rdev))
666 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
Egbert Eich9c50b1d2012-10-24 18:31:19 +0200667 else if (ASIC_IS_RV100(rdev))
668 tmp |= (0x1ac << RADEON_DAC_FORCE_DATA_SHIFT);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200669 else
670 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
671
672 WREG32(RADEON_DAC_EXT_CNTL, tmp);
673
674 tmp = dac_cntl & ~(RADEON_DAC_RANGE_CNTL_MASK | RADEON_DAC_PDWN);
675 tmp |= RADEON_DAC_RANGE_CNTL_PS2 | RADEON_DAC_CMP_EN;
676 WREG32(RADEON_DAC_CNTL, tmp);
677
Egbert Eich83325d02012-10-24 18:29:49 +0200678 tmp = dac_macro_cntl;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200679 tmp &= ~(RADEON_DAC_PDWN_R |
680 RADEON_DAC_PDWN_G |
681 RADEON_DAC_PDWN_B);
682
683 WREG32(RADEON_DAC_MACRO_CNTL, tmp);
684
Arnd Bergmann4de833c2012-04-05 12:58:22 -0600685 mdelay(2);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200686
687 if (RREG32(RADEON_DAC_CNTL) & RADEON_DAC_CMP_OUTPUT)
688 found = connector_status_connected;
689
690 /* restore the regs we used */
691 WREG32(RADEON_DAC_CNTL, dac_cntl);
692 WREG32(RADEON_DAC_MACRO_CNTL, dac_macro_cntl);
693 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
694 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
695 WREG32_PLL(RADEON_VCLK_ECP_CNTL, vclk_ecp_cntl);
696
697 return found;
698}
699
700static const struct drm_encoder_helper_funcs radeon_legacy_primary_dac_helper_funcs = {
701 .dpms = radeon_legacy_primary_dac_dpms,
Alex Deucher80297e82009-11-12 14:55:14 -0500702 .mode_fixup = radeon_legacy_mode_fixup,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200703 .prepare = radeon_legacy_primary_dac_prepare,
704 .mode_set = radeon_legacy_primary_dac_mode_set,
705 .commit = radeon_legacy_primary_dac_commit,
706 .detect = radeon_legacy_primary_dac_detect,
Dave Airlie4ce001a2009-08-13 16:32:14 +1000707 .disable = radeon_legacy_encoder_disable,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200708};
709
710
711static const struct drm_encoder_funcs radeon_legacy_primary_dac_enc_funcs = {
712 .destroy = radeon_enc_destroy,
713};
714
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200715static void radeon_legacy_tmds_int_dpms(struct drm_encoder *encoder, int mode)
716{
717 struct drm_device *dev = encoder->dev;
718 struct radeon_device *rdev = dev->dev_private;
719 uint32_t fp_gen_cntl = RREG32(RADEON_FP_GEN_CNTL);
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000720 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200721
722 switch (mode) {
723 case DRM_MODE_DPMS_ON:
724 fp_gen_cntl |= (RADEON_FP_FPON | RADEON_FP_TMDS_EN);
725 break;
726 case DRM_MODE_DPMS_STANDBY:
727 case DRM_MODE_DPMS_SUSPEND:
728 case DRM_MODE_DPMS_OFF:
729 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
730 break;
731 }
732
733 WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
734
735 if (rdev->is_atom_bios)
736 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
737 else
738 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100739
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200740}
741
742static void radeon_legacy_tmds_int_prepare(struct drm_encoder *encoder)
743{
744 struct radeon_device *rdev = encoder->dev->dev_private;
745
746 if (rdev->is_atom_bios)
747 radeon_atom_output_lock(encoder, true);
748 else
749 radeon_combios_output_lock(encoder, true);
750 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_OFF);
751}
752
753static void radeon_legacy_tmds_int_commit(struct drm_encoder *encoder)
754{
755 struct radeon_device *rdev = encoder->dev->dev_private;
756
757 radeon_legacy_tmds_int_dpms(encoder, DRM_MODE_DPMS_ON);
758
759 if (rdev->is_atom_bios)
760 radeon_atom_output_lock(encoder, true);
761 else
762 radeon_combios_output_lock(encoder, true);
763}
764
765static void radeon_legacy_tmds_int_mode_set(struct drm_encoder *encoder,
766 struct drm_display_mode *mode,
767 struct drm_display_mode *adjusted_mode)
768{
769 struct drm_device *dev = encoder->dev;
770 struct radeon_device *rdev = dev->dev_private;
771 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
772 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
773 uint32_t tmp, tmds_pll_cntl, tmds_transmitter_cntl, fp_gen_cntl;
774 int i;
775
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000776 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200777
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200778 tmp = tmds_pll_cntl = RREG32(RADEON_TMDS_PLL_CNTL);
779 tmp &= 0xfffff;
780 if (rdev->family == CHIP_RV280) {
781 /* bit 22 of TMDS_PLL_CNTL is read-back inverted */
782 tmp ^= (1 << 22);
783 tmds_pll_cntl ^= (1 << 22);
784 }
785
786 if (radeon_encoder->enc_priv) {
787 struct radeon_encoder_int_tmds *tmds = (struct radeon_encoder_int_tmds *)radeon_encoder->enc_priv;
788
789 for (i = 0; i < 4; i++) {
790 if (tmds->tmds_pll[i].freq == 0)
791 break;
792 if ((uint32_t)(mode->clock / 10) < tmds->tmds_pll[i].freq) {
793 tmp = tmds->tmds_pll[i].value ;
794 break;
795 }
796 }
797 }
798
799 if (ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV280)) {
800 if (tmp & 0xfff00000)
801 tmds_pll_cntl = tmp;
802 else {
803 tmds_pll_cntl &= 0xfff00000;
804 tmds_pll_cntl |= tmp;
805 }
806 } else
807 tmds_pll_cntl = tmp;
808
809 tmds_transmitter_cntl = RREG32(RADEON_TMDS_TRANSMITTER_CNTL) &
810 ~(RADEON_TMDS_TRANSMITTER_PLLRST);
811
812 if (rdev->family == CHIP_R200 ||
813 rdev->family == CHIP_R100 ||
814 ASIC_IS_R300(rdev))
815 tmds_transmitter_cntl &= ~(RADEON_TMDS_TRANSMITTER_PLLEN);
816 else /* RV chips got this bit reversed */
817 tmds_transmitter_cntl |= RADEON_TMDS_TRANSMITTER_PLLEN;
818
819 fp_gen_cntl = (RREG32(RADEON_FP_GEN_CNTL) |
820 (RADEON_FP_CRTC_DONT_SHADOW_VPAR |
821 RADEON_FP_CRTC_DONT_SHADOW_HEND));
822
823 fp_gen_cntl &= ~(RADEON_FP_FPON | RADEON_FP_TMDS_EN);
824
Alex Deucher1b4d7d72009-10-15 01:33:35 -0400825 fp_gen_cntl &= ~(RADEON_FP_RMX_HVSYNC_CONTROL_EN |
826 RADEON_FP_DFP_SYNC_SEL |
827 RADEON_FP_CRT_SYNC_SEL |
828 RADEON_FP_CRTC_LOCK_8DOT |
829 RADEON_FP_USE_SHADOW_EN |
830 RADEON_FP_CRTC_USE_SHADOW_VEND |
831 RADEON_FP_CRT_SYNC_ALT);
832
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200833 if (1) /* FIXME rgbBits == 8 */
834 fp_gen_cntl |= RADEON_FP_PANEL_FORMAT; /* 24 bit format */
835 else
836 fp_gen_cntl &= ~RADEON_FP_PANEL_FORMAT;/* 18 bit format */
837
838 if (radeon_crtc->crtc_id == 0) {
839 if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
840 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
Jerome Glissec93bb852009-07-13 21:04:08 +0200841 if (radeon_encoder->rmx_type != RMX_OFF)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200842 fp_gen_cntl |= R200_FP_SOURCE_SEL_RMX;
843 else
844 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC1;
845 } else
Alex Deucher1b4d7d72009-10-15 01:33:35 -0400846 fp_gen_cntl &= ~RADEON_FP_SEL_CRTC2;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847 } else {
848 if (ASIC_IS_R300(rdev) || rdev->family == CHIP_R200) {
849 fp_gen_cntl &= ~R200_FP_SOURCE_SEL_MASK;
850 fp_gen_cntl |= R200_FP_SOURCE_SEL_CRTC2;
851 } else
852 fp_gen_cntl |= RADEON_FP_SEL_CRTC2;
853 }
854
855 WREG32(RADEON_TMDS_PLL_CNTL, tmds_pll_cntl);
856 WREG32(RADEON_TMDS_TRANSMITTER_CNTL, tmds_transmitter_cntl);
857 WREG32(RADEON_FP_GEN_CNTL, fp_gen_cntl);
858
859 if (rdev->is_atom_bios)
860 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
861 else
862 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
863}
864
865static const struct drm_encoder_helper_funcs radeon_legacy_tmds_int_helper_funcs = {
866 .dpms = radeon_legacy_tmds_int_dpms,
Alex Deucher80297e82009-11-12 14:55:14 -0500867 .mode_fixup = radeon_legacy_mode_fixup,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200868 .prepare = radeon_legacy_tmds_int_prepare,
869 .mode_set = radeon_legacy_tmds_int_mode_set,
870 .commit = radeon_legacy_tmds_int_commit,
Dave Airlie4ce001a2009-08-13 16:32:14 +1000871 .disable = radeon_legacy_encoder_disable,
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200872};
873
874
875static const struct drm_encoder_funcs radeon_legacy_tmds_int_enc_funcs = {
876 .destroy = radeon_enc_destroy,
877};
878
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200879static void radeon_legacy_tmds_ext_dpms(struct drm_encoder *encoder, int mode)
880{
881 struct drm_device *dev = encoder->dev;
882 struct radeon_device *rdev = dev->dev_private;
883 uint32_t fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000884 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200885
886 switch (mode) {
887 case DRM_MODE_DPMS_ON:
888 fp2_gen_cntl &= ~RADEON_FP2_BLANK_EN;
889 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
890 break;
891 case DRM_MODE_DPMS_STANDBY:
892 case DRM_MODE_DPMS_SUSPEND:
893 case DRM_MODE_DPMS_OFF:
894 fp2_gen_cntl |= RADEON_FP2_BLANK_EN;
895 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
896 break;
897 }
898
899 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
900
901 if (rdev->is_atom_bios)
902 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
903 else
904 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100905
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200906}
907
908static void radeon_legacy_tmds_ext_prepare(struct drm_encoder *encoder)
909{
910 struct radeon_device *rdev = encoder->dev->dev_private;
911
912 if (rdev->is_atom_bios)
913 radeon_atom_output_lock(encoder, true);
914 else
915 radeon_combios_output_lock(encoder, true);
916 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_OFF);
917}
918
919static void radeon_legacy_tmds_ext_commit(struct drm_encoder *encoder)
920{
921 struct radeon_device *rdev = encoder->dev->dev_private;
922 radeon_legacy_tmds_ext_dpms(encoder, DRM_MODE_DPMS_ON);
923
924 if (rdev->is_atom_bios)
925 radeon_atom_output_lock(encoder, false);
926 else
927 radeon_combios_output_lock(encoder, false);
928}
929
930static void radeon_legacy_tmds_ext_mode_set(struct drm_encoder *encoder,
931 struct drm_display_mode *mode,
932 struct drm_display_mode *adjusted_mode)
933{
934 struct drm_device *dev = encoder->dev;
935 struct radeon_device *rdev = dev->dev_private;
936 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
937 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
938 uint32_t fp2_gen_cntl;
939
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000940 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200941
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200942 if (rdev->is_atom_bios) {
943 radeon_encoder->pixel_clock = adjusted_mode->clock;
Alex Deucher99999aa2010-11-16 12:09:41 -0500944 atombios_dvo_setup(encoder, ATOM_ENABLE);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200945 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
946 } else {
947 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
948
949 if (1) /* FIXME rgbBits == 8 */
950 fp2_gen_cntl |= RADEON_FP2_PANEL_FORMAT; /* 24 bit format, */
951 else
952 fp2_gen_cntl &= ~RADEON_FP2_PANEL_FORMAT;/* 18 bit format, */
953
954 fp2_gen_cntl &= ~(RADEON_FP2_ON |
955 RADEON_FP2_DVO_EN |
956 RADEON_FP2_DVO_RATE_SEL_SDR);
957
958 /* XXX: these are oem specific */
959 if (ASIC_IS_R300(rdev)) {
960 if ((dev->pdev->device == 0x4850) &&
961 (dev->pdev->subsystem_vendor == 0x1028) &&
962 (dev->pdev->subsystem_device == 0x2001)) /* Dell Inspiron 8600 */
963 fp2_gen_cntl |= R300_FP2_DVO_CLOCK_MODE_SINGLE;
964 else
965 fp2_gen_cntl |= RADEON_FP2_PAD_FLOP_EN | R300_FP2_DVO_CLOCK_MODE_SINGLE;
966
967 /*if (mode->clock > 165000)
968 fp2_gen_cntl |= R300_FP2_DVO_DUAL_CHANNEL_EN;*/
969 }
Alex Deucherfcec5702009-11-10 21:25:07 -0500970 if (!radeon_combios_external_tmds_setup(encoder))
971 radeon_external_tmds_setup(encoder);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200972 }
973
974 if (radeon_crtc->crtc_id == 0) {
975 if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
976 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
Jerome Glissec93bb852009-07-13 21:04:08 +0200977 if (radeon_encoder->rmx_type != RMX_OFF)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200978 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_RMX;
979 else
980 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC1;
981 } else
982 fp2_gen_cntl &= ~RADEON_FP2_SRC_SEL_CRTC2;
983 } else {
984 if ((rdev->family == CHIP_R200) || ASIC_IS_R300(rdev)) {
985 fp2_gen_cntl &= ~R200_FP2_SOURCE_SEL_MASK;
986 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
987 } else
988 fp2_gen_cntl |= RADEON_FP2_SRC_SEL_CRTC2;
989 }
990
991 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
992
993 if (rdev->is_atom_bios)
994 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
995 else
996 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
997}
998
Alex Deucherfcec5702009-11-10 21:25:07 -0500999static void radeon_ext_tmds_enc_destroy(struct drm_encoder *encoder)
1000{
1001 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Egbert Eich08291842012-10-15 08:21:39 +02001002 /* don't destroy the i2c bus record here, this will be done in radeon_i2c_fini */
Alex Deucherfcec5702009-11-10 21:25:07 -05001003 kfree(radeon_encoder->enc_priv);
1004 drm_encoder_cleanup(encoder);
1005 kfree(radeon_encoder);
1006}
1007
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001008static const struct drm_encoder_helper_funcs radeon_legacy_tmds_ext_helper_funcs = {
1009 .dpms = radeon_legacy_tmds_ext_dpms,
Alex Deucher80297e82009-11-12 14:55:14 -05001010 .mode_fixup = radeon_legacy_mode_fixup,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001011 .prepare = radeon_legacy_tmds_ext_prepare,
1012 .mode_set = radeon_legacy_tmds_ext_mode_set,
1013 .commit = radeon_legacy_tmds_ext_commit,
Dave Airlie4ce001a2009-08-13 16:32:14 +10001014 .disable = radeon_legacy_encoder_disable,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001015};
1016
1017
1018static const struct drm_encoder_funcs radeon_legacy_tmds_ext_enc_funcs = {
Alex Deucherfcec5702009-11-10 21:25:07 -05001019 .destroy = radeon_ext_tmds_enc_destroy,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001020};
1021
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001022static void radeon_legacy_tv_dac_dpms(struct drm_encoder *encoder, int mode)
1023{
1024 struct drm_device *dev = encoder->dev;
1025 struct radeon_device *rdev = dev->dev_private;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001026 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001027 uint32_t fp2_gen_cntl = 0, crtc2_gen_cntl = 0, tv_dac_cntl = 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001028 uint32_t tv_master_cntl = 0;
1029 bool is_tv;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001030 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001031
Dave Airlie4ce001a2009-08-13 16:32:14 +10001032 is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
1033
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001034 if (rdev->family == CHIP_R200)
1035 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
1036 else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001037 if (is_tv)
1038 tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
1039 else
1040 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001041 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1042 }
1043
1044 switch (mode) {
1045 case DRM_MODE_DPMS_ON:
1046 if (rdev->family == CHIP_R200) {
1047 fp2_gen_cntl |= (RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1048 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001049 if (is_tv)
1050 tv_master_cntl |= RADEON_TV_ON;
1051 else
1052 crtc2_gen_cntl |= RADEON_CRTC2_CRT2_ON;
1053
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001054 if (rdev->family == CHIP_R420 ||
Dave Airlie4ce001a2009-08-13 16:32:14 +10001055 rdev->family == CHIP_R423 ||
1056 rdev->family == CHIP_RV410)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001057 tv_dac_cntl &= ~(R420_TV_DAC_RDACPD |
Dave Airlie4ce001a2009-08-13 16:32:14 +10001058 R420_TV_DAC_GDACPD |
1059 R420_TV_DAC_BDACPD |
1060 RADEON_TV_DAC_BGSLEEP);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001061 else
1062 tv_dac_cntl &= ~(RADEON_TV_DAC_RDACPD |
Dave Airlie4ce001a2009-08-13 16:32:14 +10001063 RADEON_TV_DAC_GDACPD |
1064 RADEON_TV_DAC_BDACPD |
1065 RADEON_TV_DAC_BGSLEEP);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001066 }
1067 break;
1068 case DRM_MODE_DPMS_STANDBY:
1069 case DRM_MODE_DPMS_SUSPEND:
1070 case DRM_MODE_DPMS_OFF:
1071 if (rdev->family == CHIP_R200)
1072 fp2_gen_cntl &= ~(RADEON_FP2_ON | RADEON_FP2_DVO_EN);
1073 else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001074 if (is_tv)
1075 tv_master_cntl &= ~RADEON_TV_ON;
1076 else
1077 crtc2_gen_cntl &= ~RADEON_CRTC2_CRT2_ON;
1078
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001079 if (rdev->family == CHIP_R420 ||
Alex Deucher77416182010-04-06 00:05:46 -04001080 rdev->family == CHIP_R423 ||
1081 rdev->family == CHIP_RV410)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001082 tv_dac_cntl |= (R420_TV_DAC_RDACPD |
1083 R420_TV_DAC_GDACPD |
1084 R420_TV_DAC_BDACPD |
1085 RADEON_TV_DAC_BGSLEEP);
1086 else
1087 tv_dac_cntl |= (RADEON_TV_DAC_RDACPD |
1088 RADEON_TV_DAC_GDACPD |
1089 RADEON_TV_DAC_BDACPD |
1090 RADEON_TV_DAC_BGSLEEP);
1091 }
1092 break;
1093 }
1094
1095 if (rdev->family == CHIP_R200) {
1096 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
1097 } else {
Dave Airlie4ce001a2009-08-13 16:32:14 +10001098 if (is_tv)
1099 WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
Egbert Eichf8c4d702012-10-29 13:46:48 +01001100 /* handled in radeon_crtc_dpms() */
1101 else if (!(rdev->flags & RADEON_SINGLE_CRTC))
Dave Airlie4ce001a2009-08-13 16:32:14 +10001102 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001103 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1104 }
1105
1106 if (rdev->is_atom_bios)
1107 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
1108 else
1109 radeon_combios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
Rafał Miłeckic913e232009-12-22 23:02:16 +01001110
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001111}
1112
1113static void radeon_legacy_tv_dac_prepare(struct drm_encoder *encoder)
1114{
1115 struct radeon_device *rdev = encoder->dev->dev_private;
1116
1117 if (rdev->is_atom_bios)
1118 radeon_atom_output_lock(encoder, true);
1119 else
1120 radeon_combios_output_lock(encoder, true);
1121 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_OFF);
1122}
1123
1124static void radeon_legacy_tv_dac_commit(struct drm_encoder *encoder)
1125{
1126 struct radeon_device *rdev = encoder->dev->dev_private;
1127
1128 radeon_legacy_tv_dac_dpms(encoder, DRM_MODE_DPMS_ON);
1129
1130 if (rdev->is_atom_bios)
1131 radeon_atom_output_lock(encoder, true);
1132 else
1133 radeon_combios_output_lock(encoder, true);
1134}
1135
1136static void radeon_legacy_tv_dac_mode_set(struct drm_encoder *encoder,
1137 struct drm_display_mode *mode,
1138 struct drm_display_mode *adjusted_mode)
1139{
1140 struct drm_device *dev = encoder->dev;
1141 struct radeon_device *rdev = dev->dev_private;
1142 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1143 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001144 struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001145 uint32_t tv_dac_cntl, gpiopad_a = 0, dac2_cntl, disp_output_cntl = 0;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001146 uint32_t disp_hw_debug = 0, fp2_gen_cntl = 0, disp_tv_out_cntl = 0;
1147 bool is_tv = false;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001148
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001149 DRM_DEBUG_KMS("\n");
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001150
Dave Airlie4ce001a2009-08-13 16:32:14 +10001151 is_tv = radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT ? true : false;
1152
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001153 if (rdev->family != CHIP_R200) {
1154 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1155 if (rdev->family == CHIP_R420 ||
Alex Deucher77416182010-04-06 00:05:46 -04001156 rdev->family == CHIP_R423 ||
1157 rdev->family == CHIP_RV410) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001158 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
Alex Deucher77416182010-04-06 00:05:46 -04001159 RADEON_TV_DAC_BGADJ_MASK |
1160 R420_TV_DAC_DACADJ_MASK |
1161 R420_TV_DAC_RDACPD |
1162 R420_TV_DAC_GDACPD |
1163 R420_TV_DAC_BDACPD |
1164 R420_TV_DAC_TVENABLE);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001165 } else {
1166 tv_dac_cntl &= ~(RADEON_TV_DAC_STD_MASK |
Alex Deucher77416182010-04-06 00:05:46 -04001167 RADEON_TV_DAC_BGADJ_MASK |
1168 RADEON_TV_DAC_DACADJ_MASK |
1169 RADEON_TV_DAC_RDACPD |
1170 RADEON_TV_DAC_GDACPD |
1171 RADEON_TV_DAC_BDACPD);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001172 }
1173
Alex Deucher77416182010-04-06 00:05:46 -04001174 tv_dac_cntl |= RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD;
1175
1176 if (is_tv) {
1177 if (tv_dac->tv_std == TV_STD_NTSC ||
1178 tv_dac->tv_std == TV_STD_NTSC_J ||
1179 tv_dac->tv_std == TV_STD_PAL_M ||
1180 tv_dac->tv_std == TV_STD_PAL_60)
1181 tv_dac_cntl |= tv_dac->ntsc_tvdac_adj;
1182 else
1183 tv_dac_cntl |= tv_dac->pal_tvdac_adj;
1184
1185 if (tv_dac->tv_std == TV_STD_NTSC ||
1186 tv_dac->tv_std == TV_STD_NTSC_J)
1187 tv_dac_cntl |= RADEON_TV_DAC_STD_NTSC;
1188 else
1189 tv_dac_cntl |= RADEON_TV_DAC_STD_PAL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001190 } else
Alex Deucher77416182010-04-06 00:05:46 -04001191 tv_dac_cntl |= (RADEON_TV_DAC_STD_PS2 |
1192 tv_dac->ps2_tvdac_adj);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001193
1194 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1195 }
1196
1197 if (ASIC_IS_R300(rdev)) {
1198 gpiopad_a = RREG32(RADEON_GPIOPAD_A) | 1;
1199 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
Dave Airlie1ab064d2010-06-09 14:03:48 +10001200 } else if (rdev->family != CHIP_R200)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001201 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
Dave Airlie1ab064d2010-06-09 14:03:48 +10001202 else if (rdev->family == CHIP_R200)
Dave Airlie4ce001a2009-08-13 16:32:14 +10001203 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001204
Dave Airlie1ab064d2010-06-09 14:03:48 +10001205 if (rdev->family >= CHIP_R200)
1206 disp_tv_out_cntl = RREG32(RADEON_DISP_TV_OUT_CNTL);
1207
Dave Airlie4ce001a2009-08-13 16:32:14 +10001208 if (is_tv) {
1209 uint32_t dac_cntl;
1210
1211 dac_cntl = RREG32(RADEON_DAC_CNTL);
1212 dac_cntl &= ~RADEON_DAC_TVO_EN;
1213 WREG32(RADEON_DAC_CNTL, dac_cntl);
1214
1215 if (ASIC_IS_R300(rdev))
1216 gpiopad_a = RREG32(RADEON_GPIOPAD_A) & ~1;
1217
1218 dac2_cntl = RREG32(RADEON_DAC_CNTL2) & ~RADEON_DAC2_DAC2_CLK_SEL;
1219 if (radeon_crtc->crtc_id == 0) {
1220 if (ASIC_IS_R300(rdev)) {
1221 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1222 disp_output_cntl |= (RADEON_DISP_TVDAC_SOURCE_CRTC |
1223 RADEON_DISP_TV_SOURCE_CRTC);
1224 }
1225 if (rdev->family >= CHIP_R200) {
1226 disp_tv_out_cntl &= ~RADEON_DISP_TV_PATH_SRC_CRTC2;
1227 } else {
1228 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1229 }
1230 } else {
1231 if (ASIC_IS_R300(rdev)) {
1232 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1233 disp_output_cntl |= RADEON_DISP_TV_SOURCE_CRTC;
1234 }
1235 if (rdev->family >= CHIP_R200) {
1236 disp_tv_out_cntl |= RADEON_DISP_TV_PATH_SRC_CRTC2;
1237 } else {
1238 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
1239 }
1240 }
1241 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001242 } else {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001243
Dave Airlie4ce001a2009-08-13 16:32:14 +10001244 dac2_cntl = RREG32(RADEON_DAC_CNTL2) | RADEON_DAC2_DAC2_CLK_SEL;
1245
1246 if (radeon_crtc->crtc_id == 0) {
1247 if (ASIC_IS_R300(rdev)) {
1248 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1249 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC;
1250 } else if (rdev->family == CHIP_R200) {
1251 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1252 RADEON_FP2_DVO_RATE_SEL_SDR);
1253 } else
1254 disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
1255 } else {
1256 if (ASIC_IS_R300(rdev)) {
1257 disp_output_cntl &= ~RADEON_DISP_TVDAC_SOURCE_MASK;
1258 disp_output_cntl |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1259 } else if (rdev->family == CHIP_R200) {
1260 fp2_gen_cntl &= ~(R200_FP2_SOURCE_SEL_MASK |
1261 RADEON_FP2_DVO_RATE_SEL_SDR);
1262 fp2_gen_cntl |= R200_FP2_SOURCE_SEL_CRTC2;
1263 } else
1264 disp_hw_debug &= ~RADEON_CRT2_DISP1_SEL;
1265 }
1266 WREG32(RADEON_DAC_CNTL2, dac2_cntl);
1267 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001268
1269 if (ASIC_IS_R300(rdev)) {
1270 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001271 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
Dave Airlie1ab064d2010-06-09 14:03:48 +10001272 } else if (rdev->family != CHIP_R200)
1273 WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1274 else if (rdev->family == CHIP_R200)
1275 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001276
1277 if (rdev->family >= CHIP_R200)
1278 WREG32(RADEON_DISP_TV_OUT_CNTL, disp_tv_out_cntl);
Dave Airlie4ce001a2009-08-13 16:32:14 +10001279
1280 if (is_tv)
1281 radeon_legacy_tv_mode_set(encoder, mode, adjusted_mode);
1282
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001283 if (rdev->is_atom_bios)
1284 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1285 else
1286 radeon_combios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1287
1288}
1289
Dave Airlie4ce001a2009-08-13 16:32:14 +10001290static bool r300_legacy_tv_detect(struct drm_encoder *encoder,
1291 struct drm_connector *connector)
1292{
1293 struct drm_device *dev = encoder->dev;
1294 struct radeon_device *rdev = dev->dev_private;
1295 uint32_t crtc2_gen_cntl, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
1296 uint32_t disp_output_cntl, gpiopad_a, tmp;
1297 bool found = false;
1298
1299 /* save regs needed */
1300 gpiopad_a = RREG32(RADEON_GPIOPAD_A);
1301 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1302 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
1303 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
1304 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1305 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
1306
1307 WREG32_P(RADEON_GPIOPAD_A, 0, ~1);
1308
1309 WREG32(RADEON_DAC_CNTL2, RADEON_DAC2_DAC2_CLK_SEL);
1310
1311 WREG32(RADEON_CRTC2_GEN_CNTL,
1312 RADEON_CRTC2_CRT2_ON | RADEON_CRTC2_VSYNC_TRISTAT);
1313
1314 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1315 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1316 WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
1317
1318 WREG32(RADEON_DAC_EXT_CNTL,
1319 RADEON_DAC2_FORCE_BLANK_OFF_EN |
1320 RADEON_DAC2_FORCE_DATA_EN |
1321 RADEON_DAC_FORCE_DATA_SEL_RGB |
1322 (0xec << RADEON_DAC_FORCE_DATA_SHIFT));
1323
1324 WREG32(RADEON_TV_DAC_CNTL,
1325 RADEON_TV_DAC_STD_NTSC |
1326 (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
1327 (6 << RADEON_TV_DAC_DACADJ_SHIFT));
1328
1329 RREG32(RADEON_TV_DAC_CNTL);
1330 mdelay(4);
1331
1332 WREG32(RADEON_TV_DAC_CNTL,
1333 RADEON_TV_DAC_NBLANK |
1334 RADEON_TV_DAC_NHOLD |
1335 RADEON_TV_MONITOR_DETECT_EN |
1336 RADEON_TV_DAC_STD_NTSC |
1337 (8 << RADEON_TV_DAC_BGADJ_SHIFT) |
1338 (6 << RADEON_TV_DAC_DACADJ_SHIFT));
1339
1340 RREG32(RADEON_TV_DAC_CNTL);
1341 mdelay(6);
1342
1343 tmp = RREG32(RADEON_TV_DAC_CNTL);
1344 if ((tmp & RADEON_TV_DAC_GDACDET) != 0) {
1345 found = true;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001346 DRM_DEBUG_KMS("S-video TV connection detected\n");
Dave Airlie4ce001a2009-08-13 16:32:14 +10001347 } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
1348 found = true;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001349 DRM_DEBUG_KMS("Composite TV connection detected\n");
Dave Airlie4ce001a2009-08-13 16:32:14 +10001350 }
1351
1352 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1353 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1354 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1355 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1356 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1357 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1358 return found;
1359}
1360
1361static bool radeon_legacy_tv_detect(struct drm_encoder *encoder,
1362 struct drm_connector *connector)
1363{
1364 struct drm_device *dev = encoder->dev;
1365 struct radeon_device *rdev = dev->dev_private;
1366 uint32_t tv_dac_cntl, dac_cntl2;
1367 uint32_t config_cntl, tv_pre_dac_mux_cntl, tv_master_cntl, tmp;
1368 bool found = false;
1369
1370 if (ASIC_IS_R300(rdev))
1371 return r300_legacy_tv_detect(encoder, connector);
1372
1373 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1374 tv_master_cntl = RREG32(RADEON_TV_MASTER_CNTL);
1375 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1376 config_cntl = RREG32(RADEON_CONFIG_CNTL);
1377 tv_pre_dac_mux_cntl = RREG32(RADEON_TV_PRE_DAC_MUX_CNTL);
1378
1379 tmp = dac_cntl2 & ~RADEON_DAC2_DAC2_CLK_SEL;
1380 WREG32(RADEON_DAC_CNTL2, tmp);
1381
1382 tmp = tv_master_cntl | RADEON_TV_ON;
1383 tmp &= ~(RADEON_TV_ASYNC_RST |
1384 RADEON_RESTART_PHASE_FIX |
1385 RADEON_CRT_FIFO_CE_EN |
1386 RADEON_TV_FIFO_CE_EN |
1387 RADEON_RE_SYNC_NOW_SEL_MASK);
1388 tmp |= RADEON_TV_FIFO_ASYNC_RST | RADEON_CRT_ASYNC_RST;
1389 WREG32(RADEON_TV_MASTER_CNTL, tmp);
1390
1391 tmp = RADEON_TV_DAC_NBLANK | RADEON_TV_DAC_NHOLD |
1392 RADEON_TV_MONITOR_DETECT_EN | RADEON_TV_DAC_STD_NTSC |
1393 (8 << RADEON_TV_DAC_BGADJ_SHIFT);
1394
1395 if (config_cntl & RADEON_CFG_ATI_REV_ID_MASK)
1396 tmp |= (4 << RADEON_TV_DAC_DACADJ_SHIFT);
1397 else
1398 tmp |= (8 << RADEON_TV_DAC_DACADJ_SHIFT);
1399 WREG32(RADEON_TV_DAC_CNTL, tmp);
1400
1401 tmp = RADEON_C_GRN_EN | RADEON_CMP_BLU_EN |
1402 RADEON_RED_MX_FORCE_DAC_DATA |
1403 RADEON_GRN_MX_FORCE_DAC_DATA |
1404 RADEON_BLU_MX_FORCE_DAC_DATA |
1405 (0x109 << RADEON_TV_FORCE_DAC_DATA_SHIFT);
1406 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tmp);
1407
1408 mdelay(3);
1409 tmp = RREG32(RADEON_TV_DAC_CNTL);
1410 if (tmp & RADEON_TV_DAC_GDACDET) {
1411 found = true;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001412 DRM_DEBUG_KMS("S-video TV connection detected\n");
Dave Airlie4ce001a2009-08-13 16:32:14 +10001413 } else if ((tmp & RADEON_TV_DAC_BDACDET) != 0) {
1414 found = true;
Dave Airlied9fdaaf2010-08-02 10:42:55 +10001415 DRM_DEBUG_KMS("Composite TV connection detected\n");
Dave Airlie4ce001a2009-08-13 16:32:14 +10001416 }
1417
1418 WREG32(RADEON_TV_PRE_DAC_MUX_CNTL, tv_pre_dac_mux_cntl);
1419 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
1420 WREG32(RADEON_TV_MASTER_CNTL, tv_master_cntl);
1421 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1422 return found;
1423}
1424
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001425static enum drm_connector_status radeon_legacy_tv_dac_detect(struct drm_encoder *encoder,
1426 struct drm_connector *connector)
1427{
1428 struct drm_device *dev = encoder->dev;
1429 struct radeon_device *rdev = dev->dev_private;
Egbert Eich701337d2012-10-30 17:42:27 +01001430 uint32_t crtc2_gen_cntl = 0, tv_dac_cntl, dac_cntl2, dac_ext_cntl;
Egbert Eichd038db82012-10-30 17:42:26 +01001431 uint32_t gpiopad_a = 0, pixclks_cntl, tmp;
Egbert Eich701337d2012-10-30 17:42:27 +01001432 uint32_t disp_output_cntl = 0, disp_hw_debug = 0, crtc_ext_cntl = 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001433 enum drm_connector_status found = connector_status_disconnected;
Dave Airlie4ce001a2009-08-13 16:32:14 +10001434 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1435 struct radeon_encoder_tv_dac *tv_dac = radeon_encoder->enc_priv;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001436 bool color = true;
Dave Airlieb62e9482010-06-08 10:42:28 +10001437 struct drm_crtc *crtc;
1438
1439 /* find out if crtc2 is in use or if this encoder is using it */
1440 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
1441 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
1442 if ((radeon_crtc->crtc_id == 1) && crtc->enabled) {
1443 if (encoder->crtc != crtc) {
1444 return connector_status_disconnected;
1445 }
1446 }
1447 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001448
Dave Airlie4ce001a2009-08-13 16:32:14 +10001449 if (connector->connector_type == DRM_MODE_CONNECTOR_SVIDEO ||
1450 connector->connector_type == DRM_MODE_CONNECTOR_Composite ||
1451 connector->connector_type == DRM_MODE_CONNECTOR_9PinDIN) {
1452 bool tv_detect;
1453
1454 if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_TV_SUPPORT))
1455 return connector_status_disconnected;
1456
1457 tv_detect = radeon_legacy_tv_detect(encoder, connector);
1458 if (tv_detect && tv_dac)
1459 found = connector_status_connected;
1460 return found;
1461 }
1462
1463 /* don't probe if the encoder is being used for something else not CRT related */
1464 if (radeon_encoder->active_device && !(radeon_encoder->active_device & ATOM_DEVICE_CRT_SUPPORT)) {
1465 DRM_INFO("not detecting due to %08x\n", radeon_encoder->active_device);
1466 return connector_status_disconnected;
1467 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001468
1469 /* save the regs we need */
1470 pixclks_cntl = RREG32_PLL(RADEON_PIXCLKS_CNTL);
Egbert Eich701337d2012-10-30 17:42:27 +01001471
1472 if (rdev->flags & RADEON_SINGLE_CRTC) {
1473 crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
Egbert Eichd038db82012-10-30 17:42:26 +01001474 } else {
Egbert Eich701337d2012-10-30 17:42:27 +01001475 if (ASIC_IS_R300(rdev)) {
1476 gpiopad_a = RREG32(RADEON_GPIOPAD_A);
1477 disp_output_cntl = RREG32(RADEON_DISP_OUTPUT_CNTL);
1478 } else {
1479 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
1480 }
1481 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
Egbert Eichd038db82012-10-30 17:42:26 +01001482 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001483 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
1484 dac_ext_cntl = RREG32(RADEON_DAC_EXT_CNTL);
1485 dac_cntl2 = RREG32(RADEON_DAC_CNTL2);
1486
1487 tmp = pixclks_cntl & ~(RADEON_PIX2CLK_ALWAYS_ONb
1488 | RADEON_PIX2CLK_DAC_ALWAYS_ONb);
1489 WREG32_PLL(RADEON_PIXCLKS_CNTL, tmp);
1490
Egbert Eich701337d2012-10-30 17:42:27 +01001491 if (rdev->flags & RADEON_SINGLE_CRTC) {
1492 tmp = crtc_ext_cntl | RADEON_CRTC_CRT_ON;
1493 WREG32(RADEON_CRTC_EXT_CNTL, tmp);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001494 } else {
Egbert Eich701337d2012-10-30 17:42:27 +01001495 tmp = crtc2_gen_cntl & ~RADEON_CRTC2_PIX_WIDTH_MASK;
1496 tmp |= RADEON_CRTC2_CRT2_ON |
1497 (2 << RADEON_CRTC2_PIX_WIDTH_SHIFT);
1498 WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
1499
1500 if (ASIC_IS_R300(rdev)) {
1501 WREG32_P(RADEON_GPIOPAD_A, 1, ~1);
1502 tmp = disp_output_cntl & ~RADEON_DISP_TVDAC_SOURCE_MASK;
1503 tmp |= RADEON_DISP_TVDAC_SOURCE_CRTC2;
1504 WREG32(RADEON_DISP_OUTPUT_CNTL, tmp);
1505 } else {
1506 tmp = disp_hw_debug & ~RADEON_CRT2_DISP1_SEL;
1507 WREG32(RADEON_DISP_HW_DEBUG, tmp);
1508 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001509 }
1510
1511 tmp = RADEON_TV_DAC_NBLANK |
1512 RADEON_TV_DAC_NHOLD |
1513 RADEON_TV_MONITOR_DETECT_EN |
1514 RADEON_TV_DAC_STD_PS2;
1515
1516 WREG32(RADEON_TV_DAC_CNTL, tmp);
1517
1518 tmp = RADEON_DAC2_FORCE_BLANK_OFF_EN |
1519 RADEON_DAC2_FORCE_DATA_EN;
1520
1521 if (color)
1522 tmp |= RADEON_DAC_FORCE_DATA_SEL_RGB;
1523 else
1524 tmp |= RADEON_DAC_FORCE_DATA_SEL_G;
1525
1526 if (ASIC_IS_R300(rdev))
1527 tmp |= (0x1b6 << RADEON_DAC_FORCE_DATA_SHIFT);
1528 else
1529 tmp |= (0x180 << RADEON_DAC_FORCE_DATA_SHIFT);
1530
1531 WREG32(RADEON_DAC_EXT_CNTL, tmp);
1532
1533 tmp = dac_cntl2 | RADEON_DAC2_DAC2_CLK_SEL | RADEON_DAC2_CMP_EN;
1534 WREG32(RADEON_DAC_CNTL2, tmp);
1535
Arnd Bergmann4de833c2012-04-05 12:58:22 -06001536 mdelay(10);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001537
1538 if (ASIC_IS_R300(rdev)) {
1539 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUT_B)
1540 found = connector_status_connected;
1541 } else {
1542 if (RREG32(RADEON_DAC_CNTL2) & RADEON_DAC2_CMP_OUTPUT)
1543 found = connector_status_connected;
1544 }
1545
1546 /* restore regs we used */
1547 WREG32(RADEON_DAC_CNTL2, dac_cntl2);
1548 WREG32(RADEON_DAC_EXT_CNTL, dac_ext_cntl);
1549 WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001550
Egbert Eich701337d2012-10-30 17:42:27 +01001551 if (rdev->flags & RADEON_SINGLE_CRTC) {
1552 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001553 } else {
Egbert Eich701337d2012-10-30 17:42:27 +01001554 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
1555 if (ASIC_IS_R300(rdev)) {
1556 WREG32(RADEON_DISP_OUTPUT_CNTL, disp_output_cntl);
1557 WREG32_P(RADEON_GPIOPAD_A, gpiopad_a, ~1);
1558 } else {
1559 WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
1560 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001561 }
Egbert Eichd038db82012-10-30 17:42:26 +01001562
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001563 WREG32_PLL(RADEON_PIXCLKS_CNTL, pixclks_cntl);
1564
Dave Airlie4ce001a2009-08-13 16:32:14 +10001565 return found;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001566
1567}
1568
1569static const struct drm_encoder_helper_funcs radeon_legacy_tv_dac_helper_funcs = {
1570 .dpms = radeon_legacy_tv_dac_dpms,
Alex Deucher80297e82009-11-12 14:55:14 -05001571 .mode_fixup = radeon_legacy_mode_fixup,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001572 .prepare = radeon_legacy_tv_dac_prepare,
1573 .mode_set = radeon_legacy_tv_dac_mode_set,
1574 .commit = radeon_legacy_tv_dac_commit,
1575 .detect = radeon_legacy_tv_dac_detect,
Dave Airlie4ce001a2009-08-13 16:32:14 +10001576 .disable = radeon_legacy_encoder_disable,
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001577};
1578
1579
1580static const struct drm_encoder_funcs radeon_legacy_tv_dac_enc_funcs = {
1581 .destroy = radeon_enc_destroy,
1582};
1583
Dave Airlie445282d2009-09-09 17:40:54 +10001584
1585static struct radeon_encoder_int_tmds *radeon_legacy_get_tmds_info(struct radeon_encoder *encoder)
1586{
1587 struct drm_device *dev = encoder->base.dev;
1588 struct radeon_device *rdev = dev->dev_private;
1589 struct radeon_encoder_int_tmds *tmds = NULL;
1590 bool ret;
1591
1592 tmds = kzalloc(sizeof(struct radeon_encoder_int_tmds), GFP_KERNEL);
1593
1594 if (!tmds)
1595 return NULL;
1596
1597 if (rdev->is_atom_bios)
1598 ret = radeon_atombios_get_tmds_info(encoder, tmds);
1599 else
1600 ret = radeon_legacy_get_tmds_info_from_combios(encoder, tmds);
1601
1602 if (ret == false)
1603 radeon_legacy_get_tmds_info_from_table(encoder, tmds);
1604
1605 return tmds;
1606}
1607
Alex Deucherfcec5702009-11-10 21:25:07 -05001608static struct radeon_encoder_ext_tmds *radeon_legacy_get_ext_tmds_info(struct radeon_encoder *encoder)
1609{
1610 struct drm_device *dev = encoder->base.dev;
1611 struct radeon_device *rdev = dev->dev_private;
1612 struct radeon_encoder_ext_tmds *tmds = NULL;
1613 bool ret;
1614
1615 if (rdev->is_atom_bios)
1616 return NULL;
1617
1618 tmds = kzalloc(sizeof(struct radeon_encoder_ext_tmds), GFP_KERNEL);
1619
1620 if (!tmds)
1621 return NULL;
1622
1623 ret = radeon_legacy_get_ext_tmds_info_from_combios(encoder, tmds);
1624
1625 if (ret == false)
1626 radeon_legacy_get_ext_tmds_info_from_table(encoder, tmds);
1627
1628 return tmds;
1629}
1630
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001631void
Alex Deucher5137ee92010-08-12 18:58:47 -04001632radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum, uint32_t supported_device)
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001633{
1634 struct radeon_device *rdev = dev->dev_private;
1635 struct drm_encoder *encoder;
1636 struct radeon_encoder *radeon_encoder;
1637
1638 /* see if we already added it */
1639 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1640 radeon_encoder = to_radeon_encoder(encoder);
Alex Deucher5137ee92010-08-12 18:58:47 -04001641 if (radeon_encoder->encoder_enum == encoder_enum) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001642 radeon_encoder->devices |= supported_device;
1643 return;
1644 }
1645
1646 }
1647
1648 /* add a new one */
1649 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
1650 if (!radeon_encoder)
1651 return;
1652
1653 encoder = &radeon_encoder->base;
Dave Airliedfee5612009-10-02 09:19:09 +10001654 if (rdev->flags & RADEON_SINGLE_CRTC)
1655 encoder->possible_crtcs = 0x1;
1656 else
1657 encoder->possible_crtcs = 0x3;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001658
1659 radeon_encoder->enc_priv = NULL;
1660
Alex Deucher5137ee92010-08-12 18:58:47 -04001661 radeon_encoder->encoder_enum = encoder_enum;
1662 radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001663 radeon_encoder->devices = supported_device;
Jerome Glissec93bb852009-07-13 21:04:08 +02001664 radeon_encoder->rmx_type = RMX_OFF;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001665
1666 switch (radeon_encoder->encoder_id) {
1667 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
Dave Airlie80e69142009-08-17 10:22:37 +10001668 encoder->possible_crtcs = 0x1;
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001669 drm_encoder_init(dev, encoder, &radeon_legacy_lvds_enc_funcs, DRM_MODE_ENCODER_LVDS);
1670 drm_encoder_helper_add(encoder, &radeon_legacy_lvds_helper_funcs);
1671 if (rdev->is_atom_bios)
1672 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
1673 else
1674 radeon_encoder->enc_priv = radeon_combios_get_lvds_info(radeon_encoder);
1675 radeon_encoder->rmx_type = RMX_FULL;
1676 break;
1677 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1678 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_int_enc_funcs, DRM_MODE_ENCODER_TMDS);
1679 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_int_helper_funcs);
Dave Airlie445282d2009-09-09 17:40:54 +10001680 radeon_encoder->enc_priv = radeon_legacy_get_tmds_info(radeon_encoder);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001681 break;
1682 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1683 drm_encoder_init(dev, encoder, &radeon_legacy_primary_dac_enc_funcs, DRM_MODE_ENCODER_DAC);
1684 drm_encoder_helper_add(encoder, &radeon_legacy_primary_dac_helper_funcs);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001685 if (rdev->is_atom_bios)
1686 radeon_encoder->enc_priv = radeon_atombios_get_primary_dac_info(radeon_encoder);
1687 else
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001688 radeon_encoder->enc_priv = radeon_combios_get_primary_dac_info(radeon_encoder);
1689 break;
1690 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1691 drm_encoder_init(dev, encoder, &radeon_legacy_tv_dac_enc_funcs, DRM_MODE_ENCODER_TVDAC);
1692 drm_encoder_helper_add(encoder, &radeon_legacy_tv_dac_helper_funcs);
Alex Deucher6fe7ac32009-06-12 17:26:08 +00001693 if (rdev->is_atom_bios)
1694 radeon_encoder->enc_priv = radeon_atombios_get_tv_dac_info(radeon_encoder);
1695 else
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001696 radeon_encoder->enc_priv = radeon_combios_get_tv_dac_info(radeon_encoder);
1697 break;
1698 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1699 drm_encoder_init(dev, encoder, &radeon_legacy_tmds_ext_enc_funcs, DRM_MODE_ENCODER_TMDS);
1700 drm_encoder_helper_add(encoder, &radeon_legacy_tmds_ext_helper_funcs);
1701 if (!rdev->is_atom_bios)
Alex Deucherfcec5702009-11-10 21:25:07 -05001702 radeon_encoder->enc_priv = radeon_legacy_get_ext_tmds_info(radeon_encoder);
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001703 break;
1704 }
1705}