xref: /linux/drivers/gpu/drm/radeon/atombios_encoders.c (revision 377bd8a98d7dccd9b71a1cef259821389f09da38)
13f03ced8SAlex Deucher /*
23f03ced8SAlex Deucher  * Copyright 2007-11 Advanced Micro Devices, Inc.
33f03ced8SAlex Deucher  * Copyright 2008 Red Hat Inc.
43f03ced8SAlex Deucher  *
53f03ced8SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
63f03ced8SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
73f03ced8SAlex Deucher  * to deal in the Software without restriction, including without limitation
83f03ced8SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
93f03ced8SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
103f03ced8SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
113f03ced8SAlex Deucher  *
123f03ced8SAlex Deucher  * The above copyright notice and this permission notice shall be included in
133f03ced8SAlex Deucher  * all copies or substantial portions of the Software.
143f03ced8SAlex Deucher  *
153f03ced8SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163f03ced8SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173f03ced8SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
183f03ced8SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
193f03ced8SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
203f03ced8SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
213f03ced8SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
223f03ced8SAlex Deucher  *
233f03ced8SAlex Deucher  * Authors: Dave Airlie
243f03ced8SAlex Deucher  *          Alex Deucher
253f03ced8SAlex Deucher  */
26760285e7SDavid Howells #include <drm/drmP.h>
27760285e7SDavid Howells #include <drm/drm_crtc_helper.h>
28760285e7SDavid Howells #include <drm/radeon_drm.h>
293f03ced8SAlex Deucher #include "radeon.h"
303f03ced8SAlex Deucher #include "atom.h"
31f3728734SAlex Deucher #include <linux/backlight.h>
323f03ced8SAlex Deucher 
333f03ced8SAlex Deucher extern int atom_debug;
343f03ced8SAlex Deucher 
35f3728734SAlex Deucher static u8
36f3728734SAlex Deucher radeon_atom_get_backlight_level_from_reg(struct radeon_device *rdev)
37f3728734SAlex Deucher {
38f3728734SAlex Deucher 	u8 backlight_level;
39f3728734SAlex Deucher 	u32 bios_2_scratch;
40f3728734SAlex Deucher 
41f3728734SAlex Deucher 	if (rdev->family >= CHIP_R600)
42f3728734SAlex Deucher 		bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
43f3728734SAlex Deucher 	else
44f3728734SAlex Deucher 		bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
45f3728734SAlex Deucher 
46f3728734SAlex Deucher 	backlight_level = ((bios_2_scratch & ATOM_S2_CURRENT_BL_LEVEL_MASK) >>
47f3728734SAlex Deucher 			   ATOM_S2_CURRENT_BL_LEVEL_SHIFT);
48f3728734SAlex Deucher 
49f3728734SAlex Deucher 	return backlight_level;
50f3728734SAlex Deucher }
51f3728734SAlex Deucher 
52f3728734SAlex Deucher static void
53f3728734SAlex Deucher radeon_atom_set_backlight_level_to_reg(struct radeon_device *rdev,
54f3728734SAlex Deucher 				       u8 backlight_level)
55f3728734SAlex Deucher {
56f3728734SAlex Deucher 	u32 bios_2_scratch;
57f3728734SAlex Deucher 
58f3728734SAlex Deucher 	if (rdev->family >= CHIP_R600)
59f3728734SAlex Deucher 		bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
60f3728734SAlex Deucher 	else
61f3728734SAlex Deucher 		bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
62f3728734SAlex Deucher 
63f3728734SAlex Deucher 	bios_2_scratch &= ~ATOM_S2_CURRENT_BL_LEVEL_MASK;
64f3728734SAlex Deucher 	bios_2_scratch |= ((backlight_level << ATOM_S2_CURRENT_BL_LEVEL_SHIFT) &
65f3728734SAlex Deucher 			   ATOM_S2_CURRENT_BL_LEVEL_MASK);
66f3728734SAlex Deucher 
67f3728734SAlex Deucher 	if (rdev->family >= CHIP_R600)
68f3728734SAlex Deucher 		WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
69f3728734SAlex Deucher 	else
70f3728734SAlex Deucher 		WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
71f3728734SAlex Deucher }
72f3728734SAlex Deucher 
736d92f81dSAlex Deucher u8
746d92f81dSAlex Deucher atombios_get_backlight_level(struct radeon_encoder *radeon_encoder)
756d92f81dSAlex Deucher {
766d92f81dSAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
776d92f81dSAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
786d92f81dSAlex Deucher 
796d92f81dSAlex Deucher 	if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
806d92f81dSAlex Deucher 		return 0;
816d92f81dSAlex Deucher 
826d92f81dSAlex Deucher 	return radeon_atom_get_backlight_level_from_reg(rdev);
836d92f81dSAlex Deucher }
846d92f81dSAlex Deucher 
85fda4b25cSLuca Tettamanti void
8637e9b6a6SAlex Deucher atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
87f3728734SAlex Deucher {
88f3728734SAlex Deucher 	struct drm_encoder *encoder = &radeon_encoder->base;
89f3728734SAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
90f3728734SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
91f3728734SAlex Deucher 	struct radeon_encoder_atom_dig *dig;
92f3728734SAlex Deucher 	DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
93f3728734SAlex Deucher 	int index;
94f3728734SAlex Deucher 
9537e9b6a6SAlex Deucher 	if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
9637e9b6a6SAlex Deucher 		return;
9737e9b6a6SAlex Deucher 
9837e9b6a6SAlex Deucher 	if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
9937e9b6a6SAlex Deucher 	    radeon_encoder->enc_priv) {
100f3728734SAlex Deucher 		dig = radeon_encoder->enc_priv;
10137e9b6a6SAlex Deucher 		dig->backlight_level = level;
102f3728734SAlex Deucher 		radeon_atom_set_backlight_level_to_reg(rdev, dig->backlight_level);
103f3728734SAlex Deucher 
104f3728734SAlex Deucher 		switch (radeon_encoder->encoder_id) {
105f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_LVDS:
106f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
107f3728734SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
108f3728734SAlex Deucher 			if (dig->backlight_level == 0) {
109f3728734SAlex Deucher 				args.ucAction = ATOM_LCD_BLOFF;
110f3728734SAlex Deucher 				atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
111f3728734SAlex Deucher 			} else {
112f3728734SAlex Deucher 				args.ucAction = ATOM_LCD_BL_BRIGHTNESS_CONTROL;
113f3728734SAlex Deucher 				atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
114f3728734SAlex Deucher 				args.ucAction = ATOM_LCD_BLON;
115f3728734SAlex Deucher 				atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
116f3728734SAlex Deucher 			}
117f3728734SAlex Deucher 			break;
118f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
119f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
120f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
121f3728734SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
122f3728734SAlex Deucher 			if (dig->backlight_level == 0)
123f3728734SAlex Deucher 				atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
124f3728734SAlex Deucher 			else {
125f3728734SAlex Deucher 				atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_BL_BRIGHTNESS_CONTROL, 0, 0);
126f3728734SAlex Deucher 				atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
127f3728734SAlex Deucher 			}
128f3728734SAlex Deucher 			break;
129f3728734SAlex Deucher 		default:
130f3728734SAlex Deucher 			break;
131f3728734SAlex Deucher 		}
132f3728734SAlex Deucher 	}
133f3728734SAlex Deucher }
134f3728734SAlex Deucher 
135bced76f2SAlex Deucher #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
136bced76f2SAlex Deucher 
137f3728734SAlex Deucher static u8 radeon_atom_bl_level(struct backlight_device *bd)
138f3728734SAlex Deucher {
139f3728734SAlex Deucher 	u8 level;
140f3728734SAlex Deucher 
141f3728734SAlex Deucher 	/* Convert brightness to hardware level */
142f3728734SAlex Deucher 	if (bd->props.brightness < 0)
143f3728734SAlex Deucher 		level = 0;
144f3728734SAlex Deucher 	else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
145f3728734SAlex Deucher 		level = RADEON_MAX_BL_LEVEL;
146f3728734SAlex Deucher 	else
147f3728734SAlex Deucher 		level = bd->props.brightness;
148f3728734SAlex Deucher 
149f3728734SAlex Deucher 	return level;
150f3728734SAlex Deucher }
151f3728734SAlex Deucher 
152f3728734SAlex Deucher static int radeon_atom_backlight_update_status(struct backlight_device *bd)
153f3728734SAlex Deucher {
154f3728734SAlex Deucher 	struct radeon_backlight_privdata *pdata = bl_get_data(bd);
155f3728734SAlex Deucher 	struct radeon_encoder *radeon_encoder = pdata->encoder;
156f3728734SAlex Deucher 
15737e9b6a6SAlex Deucher 	atombios_set_backlight_level(radeon_encoder, radeon_atom_bl_level(bd));
158f3728734SAlex Deucher 
159f3728734SAlex Deucher 	return 0;
160f3728734SAlex Deucher }
161f3728734SAlex Deucher 
162f3728734SAlex Deucher static int radeon_atom_backlight_get_brightness(struct backlight_device *bd)
163f3728734SAlex Deucher {
164f3728734SAlex Deucher 	struct radeon_backlight_privdata *pdata = bl_get_data(bd);
165f3728734SAlex Deucher 	struct radeon_encoder *radeon_encoder = pdata->encoder;
166f3728734SAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
167f3728734SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
168f3728734SAlex Deucher 
169f3728734SAlex Deucher 	return radeon_atom_get_backlight_level_from_reg(rdev);
170f3728734SAlex Deucher }
171f3728734SAlex Deucher 
172f3728734SAlex Deucher static const struct backlight_ops radeon_atom_backlight_ops = {
173f3728734SAlex Deucher 	.get_brightness = radeon_atom_backlight_get_brightness,
174f3728734SAlex Deucher 	.update_status	= radeon_atom_backlight_update_status,
175f3728734SAlex Deucher };
176f3728734SAlex Deucher 
177f3728734SAlex Deucher void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
178f3728734SAlex Deucher 				struct drm_connector *drm_connector)
179f3728734SAlex Deucher {
180f3728734SAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
181f3728734SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
182f3728734SAlex Deucher 	struct backlight_device *bd;
183f3728734SAlex Deucher 	struct backlight_properties props;
184f3728734SAlex Deucher 	struct radeon_backlight_privdata *pdata;
185f3728734SAlex Deucher 	struct radeon_encoder_atom_dig *dig;
186614499b4SAlex Deucher 	char bl_name[16];
187f3728734SAlex Deucher 
18880101790SAlex Deucher 	/* Mac laptops with multiple GPUs use the gmux driver for backlight
18980101790SAlex Deucher 	 * so don't register a backlight device
19080101790SAlex Deucher 	 */
19180101790SAlex Deucher 	if ((rdev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) &&
19280101790SAlex Deucher 	    (rdev->pdev->device == 0x6741))
19380101790SAlex Deucher 		return;
19480101790SAlex Deucher 
195f3728734SAlex Deucher 	if (!radeon_encoder->enc_priv)
196f3728734SAlex Deucher 		return;
197f3728734SAlex Deucher 
198f3728734SAlex Deucher 	if (!rdev->is_atom_bios)
199f3728734SAlex Deucher 		return;
200f3728734SAlex Deucher 
201f3728734SAlex Deucher 	if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
202f3728734SAlex Deucher 		return;
203f3728734SAlex Deucher 
204f3728734SAlex Deucher 	pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL);
205f3728734SAlex Deucher 	if (!pdata) {
206f3728734SAlex Deucher 		DRM_ERROR("Memory allocation failed\n");
207f3728734SAlex Deucher 		goto error;
208f3728734SAlex Deucher 	}
209f3728734SAlex Deucher 
210f3728734SAlex Deucher 	memset(&props, 0, sizeof(props));
211f3728734SAlex Deucher 	props.max_brightness = RADEON_MAX_BL_LEVEL;
212f3728734SAlex Deucher 	props.type = BACKLIGHT_RAW;
213614499b4SAlex Deucher 	snprintf(bl_name, sizeof(bl_name),
214614499b4SAlex Deucher 		 "radeon_bl%d", dev->primary->index);
2155bdebb18SDave Airlie 	bd = backlight_device_register(bl_name, drm_connector->kdev,
216f3728734SAlex Deucher 				       pdata, &radeon_atom_backlight_ops, &props);
217f3728734SAlex Deucher 	if (IS_ERR(bd)) {
218f3728734SAlex Deucher 		DRM_ERROR("Backlight registration failed\n");
219f3728734SAlex Deucher 		goto error;
220f3728734SAlex Deucher 	}
221f3728734SAlex Deucher 
222f3728734SAlex Deucher 	pdata->encoder = radeon_encoder;
223f3728734SAlex Deucher 
224f3728734SAlex Deucher 	dig = radeon_encoder->enc_priv;
225f3728734SAlex Deucher 	dig->bl_dev = bd;
226f3728734SAlex Deucher 
227f3728734SAlex Deucher 	bd->props.brightness = radeon_atom_backlight_get_brightness(bd);
228201bb624SAlex Deucher 	/* Set a reasonable default here if the level is 0 otherwise
229201bb624SAlex Deucher 	 * fbdev will attempt to turn the backlight on after console
230201bb624SAlex Deucher 	 * unblanking and it will try and restore 0 which turns the backlight
231201bb624SAlex Deucher 	 * off again.
232201bb624SAlex Deucher 	 */
233201bb624SAlex Deucher 	if (bd->props.brightness == 0)
234201bb624SAlex Deucher 		bd->props.brightness = RADEON_MAX_BL_LEVEL;
235f3728734SAlex Deucher 	bd->props.power = FB_BLANK_UNBLANK;
236f3728734SAlex Deucher 	backlight_update_status(bd);
237f3728734SAlex Deucher 
238f3728734SAlex Deucher 	DRM_INFO("radeon atom DIG backlight initialized\n");
239f3728734SAlex Deucher 
240f3728734SAlex Deucher 	return;
241f3728734SAlex Deucher 
242f3728734SAlex Deucher error:
243f3728734SAlex Deucher 	kfree(pdata);
244f3728734SAlex Deucher 	return;
245f3728734SAlex Deucher }
246f3728734SAlex Deucher 
247f3728734SAlex Deucher static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder)
248f3728734SAlex Deucher {
249f3728734SAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
250f3728734SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
251f3728734SAlex Deucher 	struct backlight_device *bd = NULL;
252f3728734SAlex Deucher 	struct radeon_encoder_atom_dig *dig;
253f3728734SAlex Deucher 
254f3728734SAlex Deucher 	if (!radeon_encoder->enc_priv)
255f3728734SAlex Deucher 		return;
256f3728734SAlex Deucher 
257f3728734SAlex Deucher 	if (!rdev->is_atom_bios)
258f3728734SAlex Deucher 		return;
259f3728734SAlex Deucher 
260f3728734SAlex Deucher 	if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
261f3728734SAlex Deucher 		return;
262f3728734SAlex Deucher 
263f3728734SAlex Deucher 	dig = radeon_encoder->enc_priv;
264f3728734SAlex Deucher 	bd = dig->bl_dev;
265f3728734SAlex Deucher 	dig->bl_dev = NULL;
266f3728734SAlex Deucher 
267f3728734SAlex Deucher 	if (bd) {
268f3728734SAlex Deucher 		struct radeon_legacy_backlight_privdata *pdata;
269f3728734SAlex Deucher 
270f3728734SAlex Deucher 		pdata = bl_get_data(bd);
271f3728734SAlex Deucher 		backlight_device_unregister(bd);
272f3728734SAlex Deucher 		kfree(pdata);
273f3728734SAlex Deucher 
274f3728734SAlex Deucher 		DRM_INFO("radeon atom LVDS backlight unloaded\n");
275f3728734SAlex Deucher 	}
276f3728734SAlex Deucher }
277f3728734SAlex Deucher 
278f3728734SAlex Deucher #else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
279f3728734SAlex Deucher 
280f3728734SAlex Deucher void radeon_atom_backlight_init(struct radeon_encoder *encoder)
281f3728734SAlex Deucher {
282f3728734SAlex Deucher }
283f3728734SAlex Deucher 
284f3728734SAlex Deucher static void radeon_atom_backlight_exit(struct radeon_encoder *encoder)
285f3728734SAlex Deucher {
286f3728734SAlex Deucher }
287f3728734SAlex Deucher 
288f3728734SAlex Deucher #endif
289f3728734SAlex Deucher 
2903f03ced8SAlex Deucher /* evil but including atombios.h is much worse */
2913f03ced8SAlex Deucher bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
2923f03ced8SAlex Deucher 				struct drm_display_mode *mode);
2933f03ced8SAlex Deucher 
2943f03ced8SAlex Deucher 
2953f03ced8SAlex Deucher static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
2963f03ced8SAlex Deucher {
2973f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2983f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
2993f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
3003f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
3013f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
3023f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
3033f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
3043f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
3053f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
3063f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
3073f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
3083f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
3093f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
310e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
3113f03ced8SAlex Deucher 		return true;
3123f03ced8SAlex Deucher 	default:
3133f03ced8SAlex Deucher 		return false;
3143f03ced8SAlex Deucher 	}
3153f03ced8SAlex Deucher }
3163f03ced8SAlex Deucher 
3173f03ced8SAlex Deucher static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
318e811f5aeSLaurent Pinchart 				   const struct drm_display_mode *mode,
3193f03ced8SAlex Deucher 				   struct drm_display_mode *adjusted_mode)
3203f03ced8SAlex Deucher {
3213f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3223f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
3233f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
3243f03ced8SAlex Deucher 
3253f03ced8SAlex Deucher 	/* set the active encoder to connector routing */
3263f03ced8SAlex Deucher 	radeon_encoder_set_active_device(encoder);
3273f03ced8SAlex Deucher 	drm_mode_set_crtcinfo(adjusted_mode, 0);
3283f03ced8SAlex Deucher 
3293f03ced8SAlex Deucher 	/* hw bug */
3303f03ced8SAlex Deucher 	if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
3313f03ced8SAlex Deucher 	    && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
3323f03ced8SAlex Deucher 		adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
3333f03ced8SAlex Deucher 
334da997620SAlex Deucher 	/* get the native mode for scaling */
335da997620SAlex Deucher 	if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) {
3363f03ced8SAlex Deucher 		radeon_panel_mode_fixup(encoder, adjusted_mode);
337da997620SAlex Deucher 	} else if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
3383f03ced8SAlex Deucher 		struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
3393f03ced8SAlex Deucher 		if (tv_dac) {
3403f03ced8SAlex Deucher 			if (tv_dac->tv_std == TV_STD_NTSC ||
3413f03ced8SAlex Deucher 			    tv_dac->tv_std == TV_STD_NTSC_J ||
3423f03ced8SAlex Deucher 			    tv_dac->tv_std == TV_STD_PAL_M)
3433f03ced8SAlex Deucher 				radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
3443f03ced8SAlex Deucher 			else
3453f03ced8SAlex Deucher 				radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
3463f03ced8SAlex Deucher 		}
347da997620SAlex Deucher 	} else if (radeon_encoder->rmx_type != RMX_OFF) {
348da997620SAlex Deucher 		radeon_panel_mode_fixup(encoder, adjusted_mode);
3493f03ced8SAlex Deucher 	}
3503f03ced8SAlex Deucher 
3513f03ced8SAlex Deucher 	if (ASIC_IS_DCE3(rdev) &&
3523f03ced8SAlex Deucher 	    ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
3533f03ced8SAlex Deucher 	     (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE))) {
3543f03ced8SAlex Deucher 		struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
35593927f9cSAlex Deucher 		radeon_dp_set_link_config(connector, adjusted_mode);
3563f03ced8SAlex Deucher 	}
3573f03ced8SAlex Deucher 
3583f03ced8SAlex Deucher 	return true;
3593f03ced8SAlex Deucher }
3603f03ced8SAlex Deucher 
3613f03ced8SAlex Deucher static void
3623f03ced8SAlex Deucher atombios_dac_setup(struct drm_encoder *encoder, int action)
3633f03ced8SAlex Deucher {
3643f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
3653f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
3663f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3673f03ced8SAlex Deucher 	DAC_ENCODER_CONTROL_PS_ALLOCATION args;
3683f03ced8SAlex Deucher 	int index = 0;
3693f03ced8SAlex Deucher 	struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
3703f03ced8SAlex Deucher 
3713f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
3723f03ced8SAlex Deucher 
3733f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
3743f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
3753f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
3763f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl);
3773f03ced8SAlex Deucher 		break;
3783f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
3793f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
3803f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl);
3813f03ced8SAlex Deucher 		break;
3823f03ced8SAlex Deucher 	}
3833f03ced8SAlex Deucher 
3843f03ced8SAlex Deucher 	args.ucAction = action;
3853f03ced8SAlex Deucher 
3863f03ced8SAlex Deucher 	if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT))
3873f03ced8SAlex Deucher 		args.ucDacStandard = ATOM_DAC1_PS2;
3883f03ced8SAlex Deucher 	else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
3893f03ced8SAlex Deucher 		args.ucDacStandard = ATOM_DAC1_CV;
3903f03ced8SAlex Deucher 	else {
3913f03ced8SAlex Deucher 		switch (dac_info->tv_std) {
3923f03ced8SAlex Deucher 		case TV_STD_PAL:
3933f03ced8SAlex Deucher 		case TV_STD_PAL_M:
3943f03ced8SAlex Deucher 		case TV_STD_SCART_PAL:
3953f03ced8SAlex Deucher 		case TV_STD_SECAM:
3963f03ced8SAlex Deucher 		case TV_STD_PAL_CN:
3973f03ced8SAlex Deucher 			args.ucDacStandard = ATOM_DAC1_PAL;
3983f03ced8SAlex Deucher 			break;
3993f03ced8SAlex Deucher 		case TV_STD_NTSC:
4003f03ced8SAlex Deucher 		case TV_STD_NTSC_J:
4013f03ced8SAlex Deucher 		case TV_STD_PAL_60:
4023f03ced8SAlex Deucher 		default:
4033f03ced8SAlex Deucher 			args.ucDacStandard = ATOM_DAC1_NTSC;
4043f03ced8SAlex Deucher 			break;
4053f03ced8SAlex Deucher 		}
4063f03ced8SAlex Deucher 	}
4073f03ced8SAlex Deucher 	args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
4083f03ced8SAlex Deucher 
4093f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
4103f03ced8SAlex Deucher 
4113f03ced8SAlex Deucher }
4123f03ced8SAlex Deucher 
4133f03ced8SAlex Deucher static void
4143f03ced8SAlex Deucher atombios_tv_setup(struct drm_encoder *encoder, int action)
4153f03ced8SAlex Deucher {
4163f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
4173f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
4183f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
4193f03ced8SAlex Deucher 	TV_ENCODER_CONTROL_PS_ALLOCATION args;
4203f03ced8SAlex Deucher 	int index = 0;
4213f03ced8SAlex Deucher 	struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
4223f03ced8SAlex Deucher 
4233f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
4243f03ced8SAlex Deucher 
4253f03ced8SAlex Deucher 	index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
4263f03ced8SAlex Deucher 
4273f03ced8SAlex Deucher 	args.sTVEncoder.ucAction = action;
4283f03ced8SAlex Deucher 
4293f03ced8SAlex Deucher 	if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
4303f03ced8SAlex Deucher 		args.sTVEncoder.ucTvStandard = ATOM_TV_CV;
4313f03ced8SAlex Deucher 	else {
4323f03ced8SAlex Deucher 		switch (dac_info->tv_std) {
4333f03ced8SAlex Deucher 		case TV_STD_NTSC:
4343f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
4353f03ced8SAlex Deucher 			break;
4363f03ced8SAlex Deucher 		case TV_STD_PAL:
4373f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_PAL;
4383f03ced8SAlex Deucher 			break;
4393f03ced8SAlex Deucher 		case TV_STD_PAL_M:
4403f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_PALM;
4413f03ced8SAlex Deucher 			break;
4423f03ced8SAlex Deucher 		case TV_STD_PAL_60:
4433f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60;
4443f03ced8SAlex Deucher 			break;
4453f03ced8SAlex Deucher 		case TV_STD_NTSC_J:
4463f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ;
4473f03ced8SAlex Deucher 			break;
4483f03ced8SAlex Deucher 		case TV_STD_SCART_PAL:
4493f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */
4503f03ced8SAlex Deucher 			break;
4513f03ced8SAlex Deucher 		case TV_STD_SECAM:
4523f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM;
4533f03ced8SAlex Deucher 			break;
4543f03ced8SAlex Deucher 		case TV_STD_PAL_CN:
4553f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN;
4563f03ced8SAlex Deucher 			break;
4573f03ced8SAlex Deucher 		default:
4583f03ced8SAlex Deucher 			args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
4593f03ced8SAlex Deucher 			break;
4603f03ced8SAlex Deucher 		}
4613f03ced8SAlex Deucher 	}
4623f03ced8SAlex Deucher 
4633f03ced8SAlex Deucher 	args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
4643f03ced8SAlex Deucher 
4653f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
4663f03ced8SAlex Deucher 
4673f03ced8SAlex Deucher }
4683f03ced8SAlex Deucher 
4691f0e2943SAlex Deucher static u8 radeon_atom_get_bpc(struct drm_encoder *encoder)
4701f0e2943SAlex Deucher {
4711f0e2943SAlex Deucher 	int bpc = 8;
4721f0e2943SAlex Deucher 
4737d5a33b0SAlex Deucher 	if (encoder->crtc) {
4747d5a33b0SAlex Deucher 		struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
4757d5a33b0SAlex Deucher 		bpc = radeon_crtc->bpc;
4767d5a33b0SAlex Deucher 	}
4771f0e2943SAlex Deucher 
4781f0e2943SAlex Deucher 	switch (bpc) {
4791f0e2943SAlex Deucher 	case 0:
4801f0e2943SAlex Deucher 		return PANEL_BPC_UNDEFINE;
4811f0e2943SAlex Deucher 	case 6:
4821f0e2943SAlex Deucher 		return PANEL_6BIT_PER_COLOR;
4831f0e2943SAlex Deucher 	case 8:
4841f0e2943SAlex Deucher 	default:
4851f0e2943SAlex Deucher 		return PANEL_8BIT_PER_COLOR;
4861f0e2943SAlex Deucher 	case 10:
4871f0e2943SAlex Deucher 		return PANEL_10BIT_PER_COLOR;
4881f0e2943SAlex Deucher 	case 12:
4891f0e2943SAlex Deucher 		return PANEL_12BIT_PER_COLOR;
4901f0e2943SAlex Deucher 	case 16:
4911f0e2943SAlex Deucher 		return PANEL_16BIT_PER_COLOR;
4921f0e2943SAlex Deucher 	}
4931f0e2943SAlex Deucher }
4941f0e2943SAlex Deucher 
4953f03ced8SAlex Deucher union dvo_encoder_control {
4963f03ced8SAlex Deucher 	ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
4973f03ced8SAlex Deucher 	DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
4983f03ced8SAlex Deucher 	DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
499aea65641SAlex Deucher 	DVO_ENCODER_CONTROL_PS_ALLOCATION_V1_4 dvo_v4;
5003f03ced8SAlex Deucher };
5013f03ced8SAlex Deucher 
5023f03ced8SAlex Deucher void
5033f03ced8SAlex Deucher atombios_dvo_setup(struct drm_encoder *encoder, int action)
5043f03ced8SAlex Deucher {
5053f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
5063f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
5073f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
5083f03ced8SAlex Deucher 	union dvo_encoder_control args;
5093f03ced8SAlex Deucher 	int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
51024153dd3SAlex Deucher 	uint8_t frev, crev;
5113f03ced8SAlex Deucher 
5123f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
5133f03ced8SAlex Deucher 
51424153dd3SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
51524153dd3SAlex Deucher 		return;
51624153dd3SAlex Deucher 
517afceb931SAlex Deucher 	/* some R4xx chips have the wrong frev */
518afceb931SAlex Deucher 	if (rdev->family <= CHIP_RV410)
519afceb931SAlex Deucher 		frev = 1;
520afceb931SAlex Deucher 
52124153dd3SAlex Deucher 	switch (frev) {
52224153dd3SAlex Deucher 	case 1:
52324153dd3SAlex Deucher 		switch (crev) {
52424153dd3SAlex Deucher 		case 1:
52524153dd3SAlex Deucher 			/* R4xx, R5xx */
52624153dd3SAlex Deucher 			args.ext_tmds.sXTmdsEncoder.ucEnable = action;
52724153dd3SAlex Deucher 
5289aa59993SAlex Deucher 			if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
52924153dd3SAlex Deucher 				args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
53024153dd3SAlex Deucher 
53124153dd3SAlex Deucher 			args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
53224153dd3SAlex Deucher 			break;
53324153dd3SAlex Deucher 		case 2:
53424153dd3SAlex Deucher 			/* RS600/690/740 */
5353f03ced8SAlex Deucher 			args.dvo.sDVOEncoder.ucAction = action;
5363f03ced8SAlex Deucher 			args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
5373f03ced8SAlex Deucher 			/* DFP1, CRT1, TV1 depending on the type of port */
5383f03ced8SAlex Deucher 			args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
5393f03ced8SAlex Deucher 
5409aa59993SAlex Deucher 			if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
5413f03ced8SAlex Deucher 				args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
54224153dd3SAlex Deucher 			break;
54324153dd3SAlex Deucher 		case 3:
54424153dd3SAlex Deucher 			/* R6xx */
54524153dd3SAlex Deucher 			args.dvo_v3.ucAction = action;
54624153dd3SAlex Deucher 			args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
54724153dd3SAlex Deucher 			args.dvo_v3.ucDVOConfig = 0; /* XXX */
54824153dd3SAlex Deucher 			break;
549aea65641SAlex Deucher 		case 4:
550aea65641SAlex Deucher 			/* DCE8 */
551aea65641SAlex Deucher 			args.dvo_v4.ucAction = action;
552aea65641SAlex Deucher 			args.dvo_v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
553aea65641SAlex Deucher 			args.dvo_v4.ucDVOConfig = 0; /* XXX */
554aea65641SAlex Deucher 			args.dvo_v4.ucBitPerColor = radeon_atom_get_bpc(encoder);
555aea65641SAlex Deucher 			break;
55624153dd3SAlex Deucher 		default:
55724153dd3SAlex Deucher 			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
55824153dd3SAlex Deucher 			break;
55924153dd3SAlex Deucher 		}
56024153dd3SAlex Deucher 		break;
56124153dd3SAlex Deucher 	default:
56224153dd3SAlex Deucher 		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
56324153dd3SAlex Deucher 		break;
5643f03ced8SAlex Deucher 	}
5653f03ced8SAlex Deucher 
5663f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
5673f03ced8SAlex Deucher }
5683f03ced8SAlex Deucher 
5693f03ced8SAlex Deucher union lvds_encoder_control {
5703f03ced8SAlex Deucher 	LVDS_ENCODER_CONTROL_PS_ALLOCATION    v1;
5713f03ced8SAlex Deucher 	LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
5723f03ced8SAlex Deucher };
5733f03ced8SAlex Deucher 
5743f03ced8SAlex Deucher void
5753f03ced8SAlex Deucher atombios_digital_setup(struct drm_encoder *encoder, int action)
5763f03ced8SAlex Deucher {
5773f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
5783f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
5793f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
5803f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
5813f03ced8SAlex Deucher 	union lvds_encoder_control args;
5823f03ced8SAlex Deucher 	int index = 0;
5833f03ced8SAlex Deucher 	int hdmi_detected = 0;
5843f03ced8SAlex Deucher 	uint8_t frev, crev;
5853f03ced8SAlex Deucher 
5863f03ced8SAlex Deucher 	if (!dig)
5873f03ced8SAlex Deucher 		return;
5883f03ced8SAlex Deucher 
5893f03ced8SAlex Deucher 	if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
5903f03ced8SAlex Deucher 		hdmi_detected = 1;
5913f03ced8SAlex Deucher 
5923f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
5933f03ced8SAlex Deucher 
5943f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
5953f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
5963f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
5973f03ced8SAlex Deucher 		break;
5983f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
5993f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
6003f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl);
6013f03ced8SAlex Deucher 		break;
6023f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
6033f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
6043f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
6053f03ced8SAlex Deucher 		else
6063f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl);
6073f03ced8SAlex Deucher 		break;
6083f03ced8SAlex Deucher 	}
6093f03ced8SAlex Deucher 
6103f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
6113f03ced8SAlex Deucher 		return;
6123f03ced8SAlex Deucher 
6133f03ced8SAlex Deucher 	switch (frev) {
6143f03ced8SAlex Deucher 	case 1:
6153f03ced8SAlex Deucher 	case 2:
6163f03ced8SAlex Deucher 		switch (crev) {
6173f03ced8SAlex Deucher 		case 1:
6183f03ced8SAlex Deucher 			args.v1.ucMisc = 0;
6193f03ced8SAlex Deucher 			args.v1.ucAction = action;
6203f03ced8SAlex Deucher 			if (hdmi_detected)
6213f03ced8SAlex Deucher 				args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
6223f03ced8SAlex Deucher 			args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
6233f03ced8SAlex Deucher 			if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
6243f03ced8SAlex Deucher 				if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
6253f03ced8SAlex Deucher 					args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
6263f03ced8SAlex Deucher 				if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
6273f03ced8SAlex Deucher 					args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
6283f03ced8SAlex Deucher 			} else {
6293f03ced8SAlex Deucher 				if (dig->linkb)
6303f03ced8SAlex Deucher 					args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
6319aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
6323f03ced8SAlex Deucher 					args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
6333f03ced8SAlex Deucher 				/*if (pScrn->rgbBits == 8) */
6343f03ced8SAlex Deucher 				args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
6353f03ced8SAlex Deucher 			}
6363f03ced8SAlex Deucher 			break;
6373f03ced8SAlex Deucher 		case 2:
6383f03ced8SAlex Deucher 		case 3:
6393f03ced8SAlex Deucher 			args.v2.ucMisc = 0;
6403f03ced8SAlex Deucher 			args.v2.ucAction = action;
6413f03ced8SAlex Deucher 			if (crev == 3) {
6423f03ced8SAlex Deucher 				if (dig->coherent_mode)
6433f03ced8SAlex Deucher 					args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
6443f03ced8SAlex Deucher 			}
6453f03ced8SAlex Deucher 			if (hdmi_detected)
6463f03ced8SAlex Deucher 				args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
6473f03ced8SAlex Deucher 			args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
6483f03ced8SAlex Deucher 			args.v2.ucTruncate = 0;
6493f03ced8SAlex Deucher 			args.v2.ucSpatial = 0;
6503f03ced8SAlex Deucher 			args.v2.ucTemporal = 0;
6513f03ced8SAlex Deucher 			args.v2.ucFRC = 0;
6523f03ced8SAlex Deucher 			if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
6533f03ced8SAlex Deucher 				if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
6543f03ced8SAlex Deucher 					args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
6553f03ced8SAlex Deucher 				if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) {
6563f03ced8SAlex Deucher 					args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN;
6573f03ced8SAlex Deucher 					if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
6583f03ced8SAlex Deucher 						args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH;
6593f03ced8SAlex Deucher 				}
6603f03ced8SAlex Deucher 				if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) {
6613f03ced8SAlex Deucher 					args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN;
6623f03ced8SAlex Deucher 					if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
6633f03ced8SAlex Deucher 						args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH;
6643f03ced8SAlex Deucher 					if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2)
6653f03ced8SAlex Deucher 						args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4;
6663f03ced8SAlex Deucher 				}
6673f03ced8SAlex Deucher 			} else {
6683f03ced8SAlex Deucher 				if (dig->linkb)
6693f03ced8SAlex Deucher 					args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
6709aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
6713f03ced8SAlex Deucher 					args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
6723f03ced8SAlex Deucher 			}
6733f03ced8SAlex Deucher 			break;
6743f03ced8SAlex Deucher 		default:
6753f03ced8SAlex Deucher 			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
6763f03ced8SAlex Deucher 			break;
6773f03ced8SAlex Deucher 		}
6783f03ced8SAlex Deucher 		break;
6793f03ced8SAlex Deucher 	default:
6803f03ced8SAlex Deucher 		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
6813f03ced8SAlex Deucher 		break;
6823f03ced8SAlex Deucher 	}
6833f03ced8SAlex Deucher 
6843f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
6853f03ced8SAlex Deucher }
6863f03ced8SAlex Deucher 
6873f03ced8SAlex Deucher int
6883f03ced8SAlex Deucher atombios_get_encoder_mode(struct drm_encoder *encoder)
6893f03ced8SAlex Deucher {
6903f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
6913f03ced8SAlex Deucher 	struct drm_connector *connector;
6923f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector;
6933f03ced8SAlex Deucher 	struct radeon_connector_atom_dig *dig_connector;
6943f03ced8SAlex Deucher 
6953f03ced8SAlex Deucher 	/* dp bridges are always DP */
6963f03ced8SAlex Deucher 	if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)
6973f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_DP;
6983f03ced8SAlex Deucher 
6993f03ced8SAlex Deucher 	/* DVO is always DVO */
700a59fbb8eSAlex Deucher 	if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DVO1) ||
701a59fbb8eSAlex Deucher 	    (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1))
7023f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_DVO;
7033f03ced8SAlex Deucher 
7043f03ced8SAlex Deucher 	connector = radeon_get_connector_for_encoder(encoder);
7053f03ced8SAlex Deucher 	/* if we don't have an active device yet, just use one of
7063f03ced8SAlex Deucher 	 * the connectors tied to the encoder.
7073f03ced8SAlex Deucher 	 */
7083f03ced8SAlex Deucher 	if (!connector)
7093f03ced8SAlex Deucher 		connector = radeon_get_connector_for_encoder_init(encoder);
7103f03ced8SAlex Deucher 	radeon_connector = to_radeon_connector(connector);
7113f03ced8SAlex Deucher 
7123f03ced8SAlex Deucher 	switch (connector->connector_type) {
7133f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_DVII:
7143f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
715108dc8e8SAlex Deucher 		if (radeon_audio != 0) {
716108dc8e8SAlex Deucher 			if (radeon_connector->use_digital &&
717108dc8e8SAlex Deucher 			    (radeon_connector->audio == RADEON_AUDIO_ENABLE))
718108dc8e8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
719*377bd8a9SAlex Deucher 			else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) &&
720108dc8e8SAlex Deucher 				 (radeon_connector->audio == RADEON_AUDIO_AUTO))
7213f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
722f92e70caSRafał Miłecki 			else if (radeon_connector->use_digital)
7233f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_DVI;
7243f03ced8SAlex Deucher 			else
7253f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_CRT;
726108dc8e8SAlex Deucher 		} else if (radeon_connector->use_digital) {
727108dc8e8SAlex Deucher 			return ATOM_ENCODER_MODE_DVI;
728108dc8e8SAlex Deucher 		} else {
729108dc8e8SAlex Deucher 			return ATOM_ENCODER_MODE_CRT;
730108dc8e8SAlex Deucher 		}
7313f03ced8SAlex Deucher 		break;
7323f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_DVID:
7333f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_HDMIA:
7343f03ced8SAlex Deucher 	default:
735108dc8e8SAlex Deucher 		if (radeon_audio != 0) {
736108dc8e8SAlex Deucher 			if (radeon_connector->audio == RADEON_AUDIO_ENABLE)
737108dc8e8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
738*377bd8a9SAlex Deucher 			else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) &&
739108dc8e8SAlex Deucher 				 (radeon_connector->audio == RADEON_AUDIO_AUTO))
7403f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
741f92e70caSRafał Miłecki 			else
7423f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_DVI;
743108dc8e8SAlex Deucher 		} else {
744108dc8e8SAlex Deucher 			return ATOM_ENCODER_MODE_DVI;
745108dc8e8SAlex Deucher 		}
7463f03ced8SAlex Deucher 		break;
7473f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_LVDS:
7483f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_LVDS;
7493f03ced8SAlex Deucher 		break;
7503f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_DisplayPort:
7513f03ced8SAlex Deucher 		dig_connector = radeon_connector->con_priv;
7523f03ced8SAlex Deucher 		if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
753108dc8e8SAlex Deucher 		    (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) {
7543f03ced8SAlex Deucher 			return ATOM_ENCODER_MODE_DP;
755108dc8e8SAlex Deucher 		} else if (radeon_audio != 0) {
756108dc8e8SAlex Deucher 			if (radeon_connector->audio == RADEON_AUDIO_ENABLE)
757108dc8e8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
758*377bd8a9SAlex Deucher 			else if (drm_detect_hdmi_monitor(radeon_connector_edid(connector)) &&
759108dc8e8SAlex Deucher 				 (radeon_connector->audio == RADEON_AUDIO_AUTO))
7603f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_HDMI;
761f92e70caSRafał Miłecki 			else
7623f03ced8SAlex Deucher 				return ATOM_ENCODER_MODE_DVI;
763108dc8e8SAlex Deucher 		} else {
764108dc8e8SAlex Deucher 			return ATOM_ENCODER_MODE_DVI;
765108dc8e8SAlex Deucher 		}
7663f03ced8SAlex Deucher 		break;
7673f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_eDP:
7683f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_DP;
7693f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_DVIA:
7703f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_VGA:
7713f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_CRT;
7723f03ced8SAlex Deucher 		break;
7733f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_Composite:
7743f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_SVIDEO:
7753f03ced8SAlex Deucher 	case DRM_MODE_CONNECTOR_9PinDIN:
7763f03ced8SAlex Deucher 		/* fix me */
7773f03ced8SAlex Deucher 		return ATOM_ENCODER_MODE_TV;
7783f03ced8SAlex Deucher 		/*return ATOM_ENCODER_MODE_CV;*/
7793f03ced8SAlex Deucher 		break;
7803f03ced8SAlex Deucher 	}
7813f03ced8SAlex Deucher }
7823f03ced8SAlex Deucher 
7833f03ced8SAlex Deucher /*
7843f03ced8SAlex Deucher  * DIG Encoder/Transmitter Setup
7853f03ced8SAlex Deucher  *
7863f03ced8SAlex Deucher  * DCE 3.0/3.1
7873f03ced8SAlex Deucher  * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
7883f03ced8SAlex Deucher  * Supports up to 3 digital outputs
7893f03ced8SAlex Deucher  * - 2 DIG encoder blocks.
7903f03ced8SAlex Deucher  * DIG1 can drive UNIPHY link A or link B
7913f03ced8SAlex Deucher  * DIG2 can drive UNIPHY link B or LVTMA
7923f03ced8SAlex Deucher  *
7933f03ced8SAlex Deucher  * DCE 3.2
7943f03ced8SAlex Deucher  * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
7953f03ced8SAlex Deucher  * Supports up to 5 digital outputs
7963f03ced8SAlex Deucher  * - 2 DIG encoder blocks.
7973f03ced8SAlex Deucher  * DIG1/2 can drive UNIPHY0/1/2 link A or link B
7983f03ced8SAlex Deucher  *
7992d415869SAlex Deucher  * DCE 4.0/5.0/6.0
8003f03ced8SAlex Deucher  * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
8013f03ced8SAlex Deucher  * Supports up to 6 digital outputs
8023f03ced8SAlex Deucher  * - 6 DIG encoder blocks.
8033f03ced8SAlex Deucher  * - DIG to PHY mapping is hardcoded
8043f03ced8SAlex Deucher  * DIG1 drives UNIPHY0 link A, A+B
8053f03ced8SAlex Deucher  * DIG2 drives UNIPHY0 link B
8063f03ced8SAlex Deucher  * DIG3 drives UNIPHY1 link A, A+B
8073f03ced8SAlex Deucher  * DIG4 drives UNIPHY1 link B
8083f03ced8SAlex Deucher  * DIG5 drives UNIPHY2 link A, A+B
8093f03ced8SAlex Deucher  * DIG6 drives UNIPHY2 link B
8103f03ced8SAlex Deucher  *
8113f03ced8SAlex Deucher  * DCE 4.1
8123f03ced8SAlex Deucher  * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
8133f03ced8SAlex Deucher  * Supports up to 6 digital outputs
8143f03ced8SAlex Deucher  * - 2 DIG encoder blocks.
8152d415869SAlex Deucher  * llano
8163f03ced8SAlex Deucher  * DIG1/2 can drive UNIPHY0/1/2 link A or link B
8172d415869SAlex Deucher  * ontario
8182d415869SAlex Deucher  * DIG1 drives UNIPHY0/1/2 link A
8192d415869SAlex Deucher  * DIG2 drives UNIPHY0/1/2 link B
8203f03ced8SAlex Deucher  *
8213f03ced8SAlex Deucher  * Routing
8223f03ced8SAlex Deucher  * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
8233f03ced8SAlex Deucher  * Examples:
8243f03ced8SAlex Deucher  * crtc0 -> dig2 -> LVTMA   links A+B -> TMDS/HDMI
8253f03ced8SAlex Deucher  * crtc1 -> dig1 -> UNIPHY0 link  B   -> DP
8263f03ced8SAlex Deucher  * crtc0 -> dig1 -> UNIPHY2 link  A   -> LVDS
8273f03ced8SAlex Deucher  * crtc1 -> dig2 -> UNIPHY1 link  B+A -> TMDS/HDMI
8283f03ced8SAlex Deucher  */
8293f03ced8SAlex Deucher 
8303f03ced8SAlex Deucher union dig_encoder_control {
8313f03ced8SAlex Deucher 	DIG_ENCODER_CONTROL_PS_ALLOCATION v1;
8323f03ced8SAlex Deucher 	DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
8333f03ced8SAlex Deucher 	DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
8343f03ced8SAlex Deucher 	DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
8353f03ced8SAlex Deucher };
8363f03ced8SAlex Deucher 
8373f03ced8SAlex Deucher void
8383f03ced8SAlex Deucher atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode)
8393f03ced8SAlex Deucher {
8403f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
8413f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
8423f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
8433f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
8443f03ced8SAlex Deucher 	struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
8453f03ced8SAlex Deucher 	union dig_encoder_control args;
8463f03ced8SAlex Deucher 	int index = 0;
8473f03ced8SAlex Deucher 	uint8_t frev, crev;
8483f03ced8SAlex Deucher 	int dp_clock = 0;
8493f03ced8SAlex Deucher 	int dp_lane_count = 0;
8503f03ced8SAlex Deucher 	int hpd_id = RADEON_HPD_NONE;
8513f03ced8SAlex Deucher 
8523f03ced8SAlex Deucher 	if (connector) {
8533f03ced8SAlex Deucher 		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
8543f03ced8SAlex Deucher 		struct radeon_connector_atom_dig *dig_connector =
8553f03ced8SAlex Deucher 			radeon_connector->con_priv;
8563f03ced8SAlex Deucher 
8573f03ced8SAlex Deucher 		dp_clock = dig_connector->dp_clock;
8583f03ced8SAlex Deucher 		dp_lane_count = dig_connector->dp_lane_count;
8593f03ced8SAlex Deucher 		hpd_id = radeon_connector->hpd.hpd;
8603f03ced8SAlex Deucher 	}
8613f03ced8SAlex Deucher 
8623f03ced8SAlex Deucher 	/* no dig encoder assigned */
8633f03ced8SAlex Deucher 	if (dig->dig_encoder == -1)
8643f03ced8SAlex Deucher 		return;
8653f03ced8SAlex Deucher 
8663f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
8673f03ced8SAlex Deucher 
8683f03ced8SAlex Deucher 	if (ASIC_IS_DCE4(rdev))
8693f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl);
8703f03ced8SAlex Deucher 	else {
8713f03ced8SAlex Deucher 		if (dig->dig_encoder)
8723f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
8733f03ced8SAlex Deucher 		else
8743f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
8753f03ced8SAlex Deucher 	}
8763f03ced8SAlex Deucher 
8773f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
8783f03ced8SAlex Deucher 		return;
8793f03ced8SAlex Deucher 
88058cdcb8bSAlex Deucher 	switch (frev) {
88158cdcb8bSAlex Deucher 	case 1:
88258cdcb8bSAlex Deucher 		switch (crev) {
88358cdcb8bSAlex Deucher 		case 1:
8843f03ced8SAlex Deucher 			args.v1.ucAction = action;
8853f03ced8SAlex Deucher 			args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
8863f03ced8SAlex Deucher 			if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
8873f03ced8SAlex Deucher 				args.v3.ucPanelMode = panel_mode;
8883f03ced8SAlex Deucher 			else
8893f03ced8SAlex Deucher 				args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder);
8903f03ced8SAlex Deucher 
8913f03ced8SAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
8923f03ced8SAlex Deucher 				args.v1.ucLaneNum = dp_lane_count;
8939aa59993SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
8943f03ced8SAlex Deucher 				args.v1.ucLaneNum = 8;
8953f03ced8SAlex Deucher 			else
8963f03ced8SAlex Deucher 				args.v1.ucLaneNum = 4;
8973f03ced8SAlex Deucher 
89858cdcb8bSAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
89958cdcb8bSAlex Deucher 				args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
90058cdcb8bSAlex Deucher 			switch (radeon_encoder->encoder_id) {
90158cdcb8bSAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
90258cdcb8bSAlex Deucher 				args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1;
90358cdcb8bSAlex Deucher 				break;
90458cdcb8bSAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
90558cdcb8bSAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
90658cdcb8bSAlex Deucher 				args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2;
90758cdcb8bSAlex Deucher 				break;
90858cdcb8bSAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
90958cdcb8bSAlex Deucher 				args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3;
91058cdcb8bSAlex Deucher 				break;
91158cdcb8bSAlex Deucher 			}
91258cdcb8bSAlex Deucher 			if (dig->linkb)
91358cdcb8bSAlex Deucher 				args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
91458cdcb8bSAlex Deucher 			else
91558cdcb8bSAlex Deucher 				args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
91658cdcb8bSAlex Deucher 			break;
91758cdcb8bSAlex Deucher 		case 2:
91858cdcb8bSAlex Deucher 		case 3:
91958cdcb8bSAlex Deucher 			args.v3.ucAction = action;
92058cdcb8bSAlex Deucher 			args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
92158cdcb8bSAlex Deucher 			if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
92258cdcb8bSAlex Deucher 				args.v3.ucPanelMode = panel_mode;
92358cdcb8bSAlex Deucher 			else
92458cdcb8bSAlex Deucher 				args.v3.ucEncoderMode = atombios_get_encoder_mode(encoder);
92558cdcb8bSAlex Deucher 
9262f6fa79aSAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode))
92758cdcb8bSAlex Deucher 				args.v3.ucLaneNum = dp_lane_count;
9289aa59993SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
92958cdcb8bSAlex Deucher 				args.v3.ucLaneNum = 8;
93058cdcb8bSAlex Deucher 			else
93158cdcb8bSAlex Deucher 				args.v3.ucLaneNum = 4;
93258cdcb8bSAlex Deucher 
9332f6fa79aSAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode) && (dp_clock == 270000))
93458cdcb8bSAlex Deucher 				args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
93558cdcb8bSAlex Deucher 			args.v3.acConfig.ucDigSel = dig->dig_encoder;
9361f0e2943SAlex Deucher 			args.v3.ucBitPerColor = radeon_atom_get_bpc(encoder);
93758cdcb8bSAlex Deucher 			break;
93858cdcb8bSAlex Deucher 		case 4:
93958cdcb8bSAlex Deucher 			args.v4.ucAction = action;
94058cdcb8bSAlex Deucher 			args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
94158cdcb8bSAlex Deucher 			if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
94258cdcb8bSAlex Deucher 				args.v4.ucPanelMode = panel_mode;
94358cdcb8bSAlex Deucher 			else
94458cdcb8bSAlex Deucher 				args.v4.ucEncoderMode = atombios_get_encoder_mode(encoder);
94558cdcb8bSAlex Deucher 
9462f6fa79aSAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode))
94758cdcb8bSAlex Deucher 				args.v4.ucLaneNum = dp_lane_count;
9489aa59993SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
94958cdcb8bSAlex Deucher 				args.v4.ucLaneNum = 8;
95058cdcb8bSAlex Deucher 			else
95158cdcb8bSAlex Deucher 				args.v4.ucLaneNum = 4;
95258cdcb8bSAlex Deucher 
9532f6fa79aSAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode)) {
954e68adef8SAlex Deucher 				if (dp_clock == 540000)
9553f03ced8SAlex Deucher 					args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ;
956e68adef8SAlex Deucher 				else if (dp_clock == 324000)
957e68adef8SAlex Deucher 					args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_3_24GHZ;
958e68adef8SAlex Deucher 				else if (dp_clock == 270000)
959e68adef8SAlex Deucher 					args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ;
960e68adef8SAlex Deucher 				else
961e68adef8SAlex Deucher 					args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_1_62GHZ;
9623f03ced8SAlex Deucher 			}
9633f03ced8SAlex Deucher 			args.v4.acConfig.ucDigSel = dig->dig_encoder;
9641f0e2943SAlex Deucher 			args.v4.ucBitPerColor = radeon_atom_get_bpc(encoder);
9653f03ced8SAlex Deucher 			if (hpd_id == RADEON_HPD_NONE)
9663f03ced8SAlex Deucher 				args.v4.ucHPD_ID = 0;
9673f03ced8SAlex Deucher 			else
9683f03ced8SAlex Deucher 				args.v4.ucHPD_ID = hpd_id + 1;
9693f03ced8SAlex Deucher 			break;
9703f03ced8SAlex Deucher 		default:
97158cdcb8bSAlex Deucher 			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
9723f03ced8SAlex Deucher 			break;
9733f03ced8SAlex Deucher 		}
9743f03ced8SAlex Deucher 		break;
97558cdcb8bSAlex Deucher 	default:
97658cdcb8bSAlex Deucher 		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
9773f03ced8SAlex Deucher 		break;
9783f03ced8SAlex Deucher 	}
9793f03ced8SAlex Deucher 
9803f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
9813f03ced8SAlex Deucher 
9823f03ced8SAlex Deucher }
9833f03ced8SAlex Deucher 
9843f03ced8SAlex Deucher union dig_transmitter_control {
9853f03ced8SAlex Deucher 	DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
9863f03ced8SAlex Deucher 	DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
9873f03ced8SAlex Deucher 	DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
9883f03ced8SAlex Deucher 	DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
98947aef7a8SAlex Deucher 	DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5;
9903f03ced8SAlex Deucher };
9913f03ced8SAlex Deucher 
9923f03ced8SAlex Deucher void
9933f03ced8SAlex Deucher atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
9943f03ced8SAlex Deucher {
9953f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
9963f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
9973f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
9983f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
9993f03ced8SAlex Deucher 	struct drm_connector *connector;
10003f03ced8SAlex Deucher 	union dig_transmitter_control args;
10013f03ced8SAlex Deucher 	int index = 0;
10023f03ced8SAlex Deucher 	uint8_t frev, crev;
10033f03ced8SAlex Deucher 	bool is_dp = false;
10043f03ced8SAlex Deucher 	int pll_id = 0;
10053f03ced8SAlex Deucher 	int dp_clock = 0;
10063f03ced8SAlex Deucher 	int dp_lane_count = 0;
10073f03ced8SAlex Deucher 	int connector_object_id = 0;
10083f03ced8SAlex Deucher 	int igp_lane_info = 0;
10093f03ced8SAlex Deucher 	int dig_encoder = dig->dig_encoder;
101047aef7a8SAlex Deucher 	int hpd_id = RADEON_HPD_NONE;
10113f03ced8SAlex Deucher 
10123f03ced8SAlex Deucher 	if (action == ATOM_TRANSMITTER_ACTION_INIT) {
10133f03ced8SAlex Deucher 		connector = radeon_get_connector_for_encoder_init(encoder);
10143f03ced8SAlex Deucher 		/* just needed to avoid bailing in the encoder check.  the encoder
10153f03ced8SAlex Deucher 		 * isn't used for init
10163f03ced8SAlex Deucher 		 */
10173f03ced8SAlex Deucher 		dig_encoder = 0;
10183f03ced8SAlex Deucher 	} else
10193f03ced8SAlex Deucher 		connector = radeon_get_connector_for_encoder(encoder);
10203f03ced8SAlex Deucher 
10213f03ced8SAlex Deucher 	if (connector) {
10223f03ced8SAlex Deucher 		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
10233f03ced8SAlex Deucher 		struct radeon_connector_atom_dig *dig_connector =
10243f03ced8SAlex Deucher 			radeon_connector->con_priv;
10253f03ced8SAlex Deucher 
102647aef7a8SAlex Deucher 		hpd_id = radeon_connector->hpd.hpd;
10273f03ced8SAlex Deucher 		dp_clock = dig_connector->dp_clock;
10283f03ced8SAlex Deucher 		dp_lane_count = dig_connector->dp_lane_count;
10293f03ced8SAlex Deucher 		connector_object_id =
10303f03ced8SAlex Deucher 			(radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
10313f03ced8SAlex Deucher 		igp_lane_info = dig_connector->igp_lane_info;
10323f03ced8SAlex Deucher 	}
10333f03ced8SAlex Deucher 
1034a3b08294SAlex Deucher 	if (encoder->crtc) {
1035a3b08294SAlex Deucher 		struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1036a3b08294SAlex Deucher 		pll_id = radeon_crtc->pll_id;
1037a3b08294SAlex Deucher 	}
1038a3b08294SAlex Deucher 
10393f03ced8SAlex Deucher 	/* no dig encoder assigned */
10403f03ced8SAlex Deucher 	if (dig_encoder == -1)
10413f03ced8SAlex Deucher 		return;
10423f03ced8SAlex Deucher 
10433f03ced8SAlex Deucher 	if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)))
10443f03ced8SAlex Deucher 		is_dp = true;
10453f03ced8SAlex Deucher 
10463f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
10473f03ced8SAlex Deucher 
10483f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
10493f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
10503f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
10513f03ced8SAlex Deucher 		break;
10523f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
10533f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
10543f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1055e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
10563f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
10573f03ced8SAlex Deucher 		break;
10583f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
10593f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl);
10603f03ced8SAlex Deucher 		break;
10613f03ced8SAlex Deucher 	}
10623f03ced8SAlex Deucher 
10633f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
10643f03ced8SAlex Deucher 		return;
10653f03ced8SAlex Deucher 
1066a3b08294SAlex Deucher 	switch (frev) {
1067a3b08294SAlex Deucher 	case 1:
1068a3b08294SAlex Deucher 		switch (crev) {
1069a3b08294SAlex Deucher 		case 1:
10703f03ced8SAlex Deucher 			args.v1.ucAction = action;
10713f03ced8SAlex Deucher 			if (action == ATOM_TRANSMITTER_ACTION_INIT) {
10723f03ced8SAlex Deucher 				args.v1.usInitInfo = cpu_to_le16(connector_object_id);
10733f03ced8SAlex Deucher 			} else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
10743f03ced8SAlex Deucher 				args.v1.asMode.ucLaneSel = lane_num;
10753f03ced8SAlex Deucher 				args.v1.asMode.ucLaneSet = lane_set;
10763f03ced8SAlex Deucher 			} else {
10773f03ced8SAlex Deucher 				if (is_dp)
10786e76a2dfSAlex Deucher 					args.v1.usPixelClock = cpu_to_le16(dp_clock / 10);
10799aa59993SAlex Deucher 				else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
10803f03ced8SAlex Deucher 					args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
10813f03ced8SAlex Deucher 				else
10823f03ced8SAlex Deucher 					args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
10833f03ced8SAlex Deucher 			}
10843f03ced8SAlex Deucher 
10853f03ced8SAlex Deucher 			args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
10863f03ced8SAlex Deucher 
10873f03ced8SAlex Deucher 			if (dig_encoder)
10883f03ced8SAlex Deucher 				args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
10893f03ced8SAlex Deucher 			else
10903f03ced8SAlex Deucher 				args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
10913f03ced8SAlex Deucher 
10923f03ced8SAlex Deucher 			if ((rdev->flags & RADEON_IS_IGP) &&
10933f03ced8SAlex Deucher 			    (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) {
10949aa59993SAlex Deucher 				if (is_dp ||
10959aa59993SAlex Deucher 				    !radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) {
10963f03ced8SAlex Deucher 					if (igp_lane_info & 0x1)
10973f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
10983f03ced8SAlex Deucher 					else if (igp_lane_info & 0x2)
10993f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7;
11003f03ced8SAlex Deucher 					else if (igp_lane_info & 0x4)
11013f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11;
11023f03ced8SAlex Deucher 					else if (igp_lane_info & 0x8)
11033f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
11043f03ced8SAlex Deucher 				} else {
11053f03ced8SAlex Deucher 					if (igp_lane_info & 0x3)
11063f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
11073f03ced8SAlex Deucher 					else if (igp_lane_info & 0xc)
11083f03ced8SAlex Deucher 						args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
11093f03ced8SAlex Deucher 				}
11103f03ced8SAlex Deucher 			}
11113f03ced8SAlex Deucher 
11123f03ced8SAlex Deucher 			if (dig->linkb)
11133f03ced8SAlex Deucher 				args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
11143f03ced8SAlex Deucher 			else
11153f03ced8SAlex Deucher 				args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
11163f03ced8SAlex Deucher 
11173f03ced8SAlex Deucher 			if (is_dp)
11183f03ced8SAlex Deucher 				args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
11193f03ced8SAlex Deucher 			else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
11203f03ced8SAlex Deucher 				if (dig->coherent_mode)
11213f03ced8SAlex Deucher 					args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
11229aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
11233f03ced8SAlex Deucher 					args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
11243f03ced8SAlex Deucher 			}
1125a3b08294SAlex Deucher 			break;
1126a3b08294SAlex Deucher 		case 2:
1127a3b08294SAlex Deucher 			args.v2.ucAction = action;
1128a3b08294SAlex Deucher 			if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1129a3b08294SAlex Deucher 				args.v2.usInitInfo = cpu_to_le16(connector_object_id);
1130a3b08294SAlex Deucher 			} else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1131a3b08294SAlex Deucher 				args.v2.asMode.ucLaneSel = lane_num;
1132a3b08294SAlex Deucher 				args.v2.asMode.ucLaneSet = lane_set;
1133a3b08294SAlex Deucher 			} else {
1134a3b08294SAlex Deucher 				if (is_dp)
11356e76a2dfSAlex Deucher 					args.v2.usPixelClock = cpu_to_le16(dp_clock / 10);
11369aa59993SAlex Deucher 				else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1137a3b08294SAlex Deucher 					args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1138a3b08294SAlex Deucher 				else
1139a3b08294SAlex Deucher 					args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1140a3b08294SAlex Deucher 			}
1141a3b08294SAlex Deucher 
1142a3b08294SAlex Deucher 			args.v2.acConfig.ucEncoderSel = dig_encoder;
1143a3b08294SAlex Deucher 			if (dig->linkb)
1144a3b08294SAlex Deucher 				args.v2.acConfig.ucLinkSel = 1;
1145a3b08294SAlex Deucher 
1146a3b08294SAlex Deucher 			switch (radeon_encoder->encoder_id) {
1147a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1148a3b08294SAlex Deucher 				args.v2.acConfig.ucTransmitterSel = 0;
1149a3b08294SAlex Deucher 				break;
1150a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1151a3b08294SAlex Deucher 				args.v2.acConfig.ucTransmitterSel = 1;
1152a3b08294SAlex Deucher 				break;
1153a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1154a3b08294SAlex Deucher 				args.v2.acConfig.ucTransmitterSel = 2;
1155a3b08294SAlex Deucher 				break;
1156a3b08294SAlex Deucher 			}
1157a3b08294SAlex Deucher 
1158a3b08294SAlex Deucher 			if (is_dp) {
1159a3b08294SAlex Deucher 				args.v2.acConfig.fCoherentMode = 1;
1160a3b08294SAlex Deucher 				args.v2.acConfig.fDPConnector = 1;
1161a3b08294SAlex Deucher 			} else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1162a3b08294SAlex Deucher 				if (dig->coherent_mode)
1163a3b08294SAlex Deucher 					args.v2.acConfig.fCoherentMode = 1;
11649aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1165a3b08294SAlex Deucher 					args.v2.acConfig.fDualLinkConnector = 1;
1166a3b08294SAlex Deucher 			}
1167a3b08294SAlex Deucher 			break;
1168a3b08294SAlex Deucher 		case 3:
1169a3b08294SAlex Deucher 			args.v3.ucAction = action;
1170a3b08294SAlex Deucher 			if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1171a3b08294SAlex Deucher 				args.v3.usInitInfo = cpu_to_le16(connector_object_id);
1172a3b08294SAlex Deucher 			} else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1173a3b08294SAlex Deucher 				args.v3.asMode.ucLaneSel = lane_num;
1174a3b08294SAlex Deucher 				args.v3.asMode.ucLaneSet = lane_set;
1175a3b08294SAlex Deucher 			} else {
1176a3b08294SAlex Deucher 				if (is_dp)
11776e76a2dfSAlex Deucher 					args.v3.usPixelClock = cpu_to_le16(dp_clock / 10);
11789aa59993SAlex Deucher 				else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1179a3b08294SAlex Deucher 					args.v3.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1180a3b08294SAlex Deucher 				else
1181a3b08294SAlex Deucher 					args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1182a3b08294SAlex Deucher 			}
1183a3b08294SAlex Deucher 
1184a3b08294SAlex Deucher 			if (is_dp)
1185a3b08294SAlex Deucher 				args.v3.ucLaneNum = dp_lane_count;
11869aa59993SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1187a3b08294SAlex Deucher 				args.v3.ucLaneNum = 8;
1188a3b08294SAlex Deucher 			else
1189a3b08294SAlex Deucher 				args.v3.ucLaneNum = 4;
1190a3b08294SAlex Deucher 
1191a3b08294SAlex Deucher 			if (dig->linkb)
1192a3b08294SAlex Deucher 				args.v3.acConfig.ucLinkSel = 1;
1193a3b08294SAlex Deucher 			if (dig_encoder & 1)
1194a3b08294SAlex Deucher 				args.v3.acConfig.ucEncoderSel = 1;
1195a3b08294SAlex Deucher 
1196a3b08294SAlex Deucher 			/* Select the PLL for the PHY
1197a3b08294SAlex Deucher 			 * DP PHY should be clocked from external src if there is
1198a3b08294SAlex Deucher 			 * one.
1199a3b08294SAlex Deucher 			 */
1200a3b08294SAlex Deucher 			/* On DCE4, if there is an external clock, it generates the DP ref clock */
1201a3b08294SAlex Deucher 			if (is_dp && rdev->clock.dp_extclk)
1202a3b08294SAlex Deucher 				args.v3.acConfig.ucRefClkSource = 2; /* external src */
1203a3b08294SAlex Deucher 			else
1204a3b08294SAlex Deucher 				args.v3.acConfig.ucRefClkSource = pll_id;
1205a3b08294SAlex Deucher 
1206a3b08294SAlex Deucher 			switch (radeon_encoder->encoder_id) {
1207a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1208a3b08294SAlex Deucher 				args.v3.acConfig.ucTransmitterSel = 0;
1209a3b08294SAlex Deucher 				break;
1210a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1211a3b08294SAlex Deucher 				args.v3.acConfig.ucTransmitterSel = 1;
1212a3b08294SAlex Deucher 				break;
1213a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1214a3b08294SAlex Deucher 				args.v3.acConfig.ucTransmitterSel = 2;
1215a3b08294SAlex Deucher 				break;
1216a3b08294SAlex Deucher 			}
1217a3b08294SAlex Deucher 
1218a3b08294SAlex Deucher 			if (is_dp)
1219a3b08294SAlex Deucher 				args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */
1220a3b08294SAlex Deucher 			else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1221a3b08294SAlex Deucher 				if (dig->coherent_mode)
1222a3b08294SAlex Deucher 					args.v3.acConfig.fCoherentMode = 1;
12239aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1224a3b08294SAlex Deucher 					args.v3.acConfig.fDualLinkConnector = 1;
1225a3b08294SAlex Deucher 			}
1226a3b08294SAlex Deucher 			break;
1227a3b08294SAlex Deucher 		case 4:
1228a3b08294SAlex Deucher 			args.v4.ucAction = action;
1229a3b08294SAlex Deucher 			if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1230a3b08294SAlex Deucher 				args.v4.usInitInfo = cpu_to_le16(connector_object_id);
1231a3b08294SAlex Deucher 			} else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1232a3b08294SAlex Deucher 				args.v4.asMode.ucLaneSel = lane_num;
1233a3b08294SAlex Deucher 				args.v4.asMode.ucLaneSet = lane_set;
1234a3b08294SAlex Deucher 			} else {
1235a3b08294SAlex Deucher 				if (is_dp)
12366e76a2dfSAlex Deucher 					args.v4.usPixelClock = cpu_to_le16(dp_clock / 10);
12379aa59993SAlex Deucher 				else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1238a3b08294SAlex Deucher 					args.v4.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1239a3b08294SAlex Deucher 				else
1240a3b08294SAlex Deucher 					args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1241a3b08294SAlex Deucher 			}
1242a3b08294SAlex Deucher 
1243a3b08294SAlex Deucher 			if (is_dp)
1244a3b08294SAlex Deucher 				args.v4.ucLaneNum = dp_lane_count;
12459aa59993SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1246a3b08294SAlex Deucher 				args.v4.ucLaneNum = 8;
1247a3b08294SAlex Deucher 			else
1248a3b08294SAlex Deucher 				args.v4.ucLaneNum = 4;
1249a3b08294SAlex Deucher 
1250a3b08294SAlex Deucher 			if (dig->linkb)
1251a3b08294SAlex Deucher 				args.v4.acConfig.ucLinkSel = 1;
1252a3b08294SAlex Deucher 			if (dig_encoder & 1)
1253a3b08294SAlex Deucher 				args.v4.acConfig.ucEncoderSel = 1;
1254a3b08294SAlex Deucher 
1255a3b08294SAlex Deucher 			/* Select the PLL for the PHY
1256a3b08294SAlex Deucher 			 * DP PHY should be clocked from external src if there is
1257a3b08294SAlex Deucher 			 * one.
1258a3b08294SAlex Deucher 			 */
1259a3b08294SAlex Deucher 			/* On DCE5 DCPLL usually generates the DP ref clock */
1260a3b08294SAlex Deucher 			if (is_dp) {
1261a3b08294SAlex Deucher 				if (rdev->clock.dp_extclk)
1262a3b08294SAlex Deucher 					args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK;
1263a3b08294SAlex Deucher 				else
1264a3b08294SAlex Deucher 					args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL;
1265a3b08294SAlex Deucher 			} else
1266a3b08294SAlex Deucher 				args.v4.acConfig.ucRefClkSource = pll_id;
1267a3b08294SAlex Deucher 
1268a3b08294SAlex Deucher 			switch (radeon_encoder->encoder_id) {
1269a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1270a3b08294SAlex Deucher 				args.v4.acConfig.ucTransmitterSel = 0;
1271a3b08294SAlex Deucher 				break;
1272a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1273a3b08294SAlex Deucher 				args.v4.acConfig.ucTransmitterSel = 1;
1274a3b08294SAlex Deucher 				break;
1275a3b08294SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1276a3b08294SAlex Deucher 				args.v4.acConfig.ucTransmitterSel = 2;
1277a3b08294SAlex Deucher 				break;
1278a3b08294SAlex Deucher 			}
1279a3b08294SAlex Deucher 
1280a3b08294SAlex Deucher 			if (is_dp)
1281a3b08294SAlex Deucher 				args.v4.acConfig.fCoherentMode = 1; /* DP requires coherent */
1282a3b08294SAlex Deucher 			else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1283a3b08294SAlex Deucher 				if (dig->coherent_mode)
1284a3b08294SAlex Deucher 					args.v4.acConfig.fCoherentMode = 1;
12859aa59993SAlex Deucher 				if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
1286a3b08294SAlex Deucher 					args.v4.acConfig.fDualLinkConnector = 1;
1287a3b08294SAlex Deucher 			}
1288a3b08294SAlex Deucher 			break;
128947aef7a8SAlex Deucher 		case 5:
129047aef7a8SAlex Deucher 			args.v5.ucAction = action;
129147aef7a8SAlex Deucher 			if (is_dp)
129247aef7a8SAlex Deucher 				args.v5.usSymClock = cpu_to_le16(dp_clock / 10);
129347aef7a8SAlex Deucher 			else
129447aef7a8SAlex Deucher 				args.v5.usSymClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
129547aef7a8SAlex Deucher 
129647aef7a8SAlex Deucher 			switch (radeon_encoder->encoder_id) {
129747aef7a8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
129847aef7a8SAlex Deucher 				if (dig->linkb)
129947aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYB;
130047aef7a8SAlex Deucher 				else
130147aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYA;
130247aef7a8SAlex Deucher 				break;
130347aef7a8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
130447aef7a8SAlex Deucher 				if (dig->linkb)
130547aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYD;
130647aef7a8SAlex Deucher 				else
130747aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYC;
130847aef7a8SAlex Deucher 				break;
130947aef7a8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
131047aef7a8SAlex Deucher 				if (dig->linkb)
131147aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYF;
131247aef7a8SAlex Deucher 				else
131347aef7a8SAlex Deucher 					args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYE;
131447aef7a8SAlex Deucher 				break;
1315e68adef8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
1316e68adef8SAlex Deucher 				args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYG;
1317e68adef8SAlex Deucher 				break;
131847aef7a8SAlex Deucher 			}
131947aef7a8SAlex Deucher 			if (is_dp)
132047aef7a8SAlex Deucher 				args.v5.ucLaneNum = dp_lane_count;
1321d03874c8SAlex Deucher 			else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
132247aef7a8SAlex Deucher 				args.v5.ucLaneNum = 8;
132347aef7a8SAlex Deucher 			else
132447aef7a8SAlex Deucher 				args.v5.ucLaneNum = 4;
132547aef7a8SAlex Deucher 			args.v5.ucConnObjId = connector_object_id;
132647aef7a8SAlex Deucher 			args.v5.ucDigMode = atombios_get_encoder_mode(encoder);
132747aef7a8SAlex Deucher 
132847aef7a8SAlex Deucher 			if (is_dp && rdev->clock.dp_extclk)
132947aef7a8SAlex Deucher 				args.v5.asConfig.ucPhyClkSrcId = ENCODER_REFCLK_SRC_EXTCLK;
133047aef7a8SAlex Deucher 			else
133147aef7a8SAlex Deucher 				args.v5.asConfig.ucPhyClkSrcId = pll_id;
133247aef7a8SAlex Deucher 
133347aef7a8SAlex Deucher 			if (is_dp)
133447aef7a8SAlex Deucher 				args.v5.asConfig.ucCoherentMode = 1; /* DP requires coherent */
133547aef7a8SAlex Deucher 			else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
133647aef7a8SAlex Deucher 				if (dig->coherent_mode)
133747aef7a8SAlex Deucher 					args.v5.asConfig.ucCoherentMode = 1;
133847aef7a8SAlex Deucher 			}
133947aef7a8SAlex Deucher 			if (hpd_id == RADEON_HPD_NONE)
134047aef7a8SAlex Deucher 				args.v5.asConfig.ucHPDSel = 0;
134147aef7a8SAlex Deucher 			else
134247aef7a8SAlex Deucher 				args.v5.asConfig.ucHPDSel = hpd_id + 1;
134347aef7a8SAlex Deucher 			args.v5.ucDigEncoderSel = 1 << dig_encoder;
134447aef7a8SAlex Deucher 			args.v5.ucDPLaneSet = lane_set;
134547aef7a8SAlex Deucher 			break;
1346a3b08294SAlex Deucher 		default:
1347a3b08294SAlex Deucher 			DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1348a3b08294SAlex Deucher 			break;
1349a3b08294SAlex Deucher 		}
1350a3b08294SAlex Deucher 		break;
1351a3b08294SAlex Deucher 	default:
1352a3b08294SAlex Deucher 		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1353a3b08294SAlex Deucher 		break;
13543f03ced8SAlex Deucher 	}
13553f03ced8SAlex Deucher 
13563f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
13573f03ced8SAlex Deucher }
13583f03ced8SAlex Deucher 
13593f03ced8SAlex Deucher bool
13603f03ced8SAlex Deucher atombios_set_edp_panel_power(struct drm_connector *connector, int action)
13613f03ced8SAlex Deucher {
13623f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
13633f03ced8SAlex Deucher 	struct drm_device *dev = radeon_connector->base.dev;
13643f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
13653f03ced8SAlex Deucher 	union dig_transmitter_control args;
13663f03ced8SAlex Deucher 	int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
13673f03ced8SAlex Deucher 	uint8_t frev, crev;
13683f03ced8SAlex Deucher 
13693f03ced8SAlex Deucher 	if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
13703f03ced8SAlex Deucher 		goto done;
13713f03ced8SAlex Deucher 
13723f03ced8SAlex Deucher 	if (!ASIC_IS_DCE4(rdev))
13733f03ced8SAlex Deucher 		goto done;
13743f03ced8SAlex Deucher 
13753f03ced8SAlex Deucher 	if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) &&
13763f03ced8SAlex Deucher 	    (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
13773f03ced8SAlex Deucher 		goto done;
13783f03ced8SAlex Deucher 
13793f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
13803f03ced8SAlex Deucher 		goto done;
13813f03ced8SAlex Deucher 
13823f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
13833f03ced8SAlex Deucher 
13843f03ced8SAlex Deucher 	args.v1.ucAction = action;
13853f03ced8SAlex Deucher 
13863f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
13873f03ced8SAlex Deucher 
13883f03ced8SAlex Deucher 	/* wait for the panel to power up */
13893f03ced8SAlex Deucher 	if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) {
13903f03ced8SAlex Deucher 		int i;
13913f03ced8SAlex Deucher 
13923f03ced8SAlex Deucher 		for (i = 0; i < 300; i++) {
13933f03ced8SAlex Deucher 			if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
13943f03ced8SAlex Deucher 				return true;
13953f03ced8SAlex Deucher 			mdelay(1);
13963f03ced8SAlex Deucher 		}
13973f03ced8SAlex Deucher 		return false;
13983f03ced8SAlex Deucher 	}
13993f03ced8SAlex Deucher done:
14003f03ced8SAlex Deucher 	return true;
14013f03ced8SAlex Deucher }
14023f03ced8SAlex Deucher 
14033f03ced8SAlex Deucher union external_encoder_control {
14043f03ced8SAlex Deucher 	EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
14053f03ced8SAlex Deucher 	EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3;
14063f03ced8SAlex Deucher };
14073f03ced8SAlex Deucher 
14083f03ced8SAlex Deucher static void
14093f03ced8SAlex Deucher atombios_external_encoder_setup(struct drm_encoder *encoder,
14103f03ced8SAlex Deucher 				struct drm_encoder *ext_encoder,
14113f03ced8SAlex Deucher 				int action)
14123f03ced8SAlex Deucher {
14133f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
14143f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
14153f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
14163f03ced8SAlex Deucher 	struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder);
14173f03ced8SAlex Deucher 	union external_encoder_control args;
14183f03ced8SAlex Deucher 	struct drm_connector *connector;
14193f03ced8SAlex Deucher 	int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
14203f03ced8SAlex Deucher 	u8 frev, crev;
14213f03ced8SAlex Deucher 	int dp_clock = 0;
14223f03ced8SAlex Deucher 	int dp_lane_count = 0;
14233f03ced8SAlex Deucher 	int connector_object_id = 0;
14243f03ced8SAlex Deucher 	u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
14253f03ced8SAlex Deucher 
14263f03ced8SAlex Deucher 	if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
14273f03ced8SAlex Deucher 		connector = radeon_get_connector_for_encoder_init(encoder);
14283f03ced8SAlex Deucher 	else
14293f03ced8SAlex Deucher 		connector = radeon_get_connector_for_encoder(encoder);
14303f03ced8SAlex Deucher 
14313f03ced8SAlex Deucher 	if (connector) {
14323f03ced8SAlex Deucher 		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
14333f03ced8SAlex Deucher 		struct radeon_connector_atom_dig *dig_connector =
14343f03ced8SAlex Deucher 			radeon_connector->con_priv;
14353f03ced8SAlex Deucher 
14363f03ced8SAlex Deucher 		dp_clock = dig_connector->dp_clock;
14373f03ced8SAlex Deucher 		dp_lane_count = dig_connector->dp_lane_count;
14383f03ced8SAlex Deucher 		connector_object_id =
14393f03ced8SAlex Deucher 			(radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
14403f03ced8SAlex Deucher 	}
14413f03ced8SAlex Deucher 
14423f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
14433f03ced8SAlex Deucher 
14443f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
14453f03ced8SAlex Deucher 		return;
14463f03ced8SAlex Deucher 
14473f03ced8SAlex Deucher 	switch (frev) {
14483f03ced8SAlex Deucher 	case 1:
14493f03ced8SAlex Deucher 		/* no params on frev 1 */
14503f03ced8SAlex Deucher 		break;
14513f03ced8SAlex Deucher 	case 2:
14523f03ced8SAlex Deucher 		switch (crev) {
14533f03ced8SAlex Deucher 		case 1:
14543f03ced8SAlex Deucher 		case 2:
14553f03ced8SAlex Deucher 			args.v1.sDigEncoder.ucAction = action;
14563f03ced8SAlex Deucher 			args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
14573f03ced8SAlex Deucher 			args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
14583f03ced8SAlex Deucher 
14593f03ced8SAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v1.sDigEncoder.ucEncoderMode)) {
14603f03ced8SAlex Deucher 				if (dp_clock == 270000)
14613f03ced8SAlex Deucher 					args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
14623f03ced8SAlex Deucher 				args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
14639aa59993SAlex Deucher 			} else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
14643f03ced8SAlex Deucher 				args.v1.sDigEncoder.ucLaneNum = 8;
14653f03ced8SAlex Deucher 			else
14663f03ced8SAlex Deucher 				args.v1.sDigEncoder.ucLaneNum = 4;
14673f03ced8SAlex Deucher 			break;
14683f03ced8SAlex Deucher 		case 3:
14693f03ced8SAlex Deucher 			args.v3.sExtEncoder.ucAction = action;
14703f03ced8SAlex Deucher 			if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
14713f03ced8SAlex Deucher 				args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id);
14723f03ced8SAlex Deucher 			else
14733f03ced8SAlex Deucher 				args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
14743f03ced8SAlex Deucher 			args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
14753f03ced8SAlex Deucher 
14763f03ced8SAlex Deucher 			if (ENCODER_MODE_IS_DP(args.v3.sExtEncoder.ucEncoderMode)) {
14773f03ced8SAlex Deucher 				if (dp_clock == 270000)
14783f03ced8SAlex Deucher 					args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
14793f03ced8SAlex Deucher 				else if (dp_clock == 540000)
14803f03ced8SAlex Deucher 					args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ;
14813f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucLaneNum = dp_lane_count;
14829aa59993SAlex Deucher 			} else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
14833f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucLaneNum = 8;
14843f03ced8SAlex Deucher 			else
14853f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucLaneNum = 4;
14863f03ced8SAlex Deucher 			switch (ext_enum) {
14873f03ced8SAlex Deucher 			case GRAPH_OBJECT_ENUM_ID1:
14883f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1;
14893f03ced8SAlex Deucher 				break;
14903f03ced8SAlex Deucher 			case GRAPH_OBJECT_ENUM_ID2:
14913f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2;
14923f03ced8SAlex Deucher 				break;
14933f03ced8SAlex Deucher 			case GRAPH_OBJECT_ENUM_ID3:
14943f03ced8SAlex Deucher 				args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3;
14953f03ced8SAlex Deucher 				break;
14963f03ced8SAlex Deucher 			}
14971f0e2943SAlex Deucher 			args.v3.sExtEncoder.ucBitPerColor = radeon_atom_get_bpc(encoder);
14983f03ced8SAlex Deucher 			break;
14993f03ced8SAlex Deucher 		default:
15003f03ced8SAlex Deucher 			DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
15013f03ced8SAlex Deucher 			return;
15023f03ced8SAlex Deucher 		}
15033f03ced8SAlex Deucher 		break;
15043f03ced8SAlex Deucher 	default:
15053f03ced8SAlex Deucher 		DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
15063f03ced8SAlex Deucher 		return;
15073f03ced8SAlex Deucher 	}
15083f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
15093f03ced8SAlex Deucher }
15103f03ced8SAlex Deucher 
15113f03ced8SAlex Deucher static void
15123f03ced8SAlex Deucher atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
15133f03ced8SAlex Deucher {
15143f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
15153f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
15163f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
15173f03ced8SAlex Deucher 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
15183f03ced8SAlex Deucher 	ENABLE_YUV_PS_ALLOCATION args;
15193f03ced8SAlex Deucher 	int index = GetIndexIntoMasterTable(COMMAND, EnableYUV);
15203f03ced8SAlex Deucher 	uint32_t temp, reg;
15213f03ced8SAlex Deucher 
15223f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
15233f03ced8SAlex Deucher 
15243f03ced8SAlex Deucher 	if (rdev->family >= CHIP_R600)
15253f03ced8SAlex Deucher 		reg = R600_BIOS_3_SCRATCH;
15263f03ced8SAlex Deucher 	else
15273f03ced8SAlex Deucher 		reg = RADEON_BIOS_3_SCRATCH;
15283f03ced8SAlex Deucher 
15293f03ced8SAlex Deucher 	/* XXX: fix up scratch reg handling */
15303f03ced8SAlex Deucher 	temp = RREG32(reg);
15313f03ced8SAlex Deucher 	if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
15323f03ced8SAlex Deucher 		WREG32(reg, (ATOM_S3_TV1_ACTIVE |
15333f03ced8SAlex Deucher 			     (radeon_crtc->crtc_id << 18)));
15343f03ced8SAlex Deucher 	else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
15353f03ced8SAlex Deucher 		WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24)));
15363f03ced8SAlex Deucher 	else
15373f03ced8SAlex Deucher 		WREG32(reg, 0);
15383f03ced8SAlex Deucher 
15393f03ced8SAlex Deucher 	if (enable)
15403f03ced8SAlex Deucher 		args.ucEnable = ATOM_ENABLE;
15413f03ced8SAlex Deucher 	args.ucCRTC = radeon_crtc->crtc_id;
15423f03ced8SAlex Deucher 
15433f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
15443f03ced8SAlex Deucher 
15453f03ced8SAlex Deucher 	WREG32(reg, temp);
15463f03ced8SAlex Deucher }
15473f03ced8SAlex Deucher 
15483f03ced8SAlex Deucher static void
15493f03ced8SAlex Deucher radeon_atom_encoder_dpms_avivo(struct drm_encoder *encoder, int mode)
15503f03ced8SAlex Deucher {
15513f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
15523f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
15533f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
15543f03ced8SAlex Deucher 	DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
15553f03ced8SAlex Deucher 	int index = 0;
15563f03ced8SAlex Deucher 
15573f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
15583f03ced8SAlex Deucher 
15593f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
15603f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
15613f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
15623f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl);
15633f03ced8SAlex Deucher 		break;
15643f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
15653f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
15663f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
15673f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
15683f03ced8SAlex Deucher 		break;
15693f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
15703f03ced8SAlex Deucher 		index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
15713f03ced8SAlex Deucher 		break;
15723f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
15733f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
15743f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
15753f03ced8SAlex Deucher 		else
15763f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl);
15773f03ced8SAlex Deucher 		break;
15783f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
15793f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
15803f03ced8SAlex Deucher 		if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
15813f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
15823f03ced8SAlex Deucher 		else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
15833f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
15843f03ced8SAlex Deucher 		else
15853f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
15863f03ced8SAlex Deucher 		break;
15873f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
15883f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
15893f03ced8SAlex Deucher 		if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
15903f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
15913f03ced8SAlex Deucher 		else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
15923f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
15933f03ced8SAlex Deucher 		else
15943f03ced8SAlex Deucher 			index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
15953f03ced8SAlex Deucher 		break;
15963f03ced8SAlex Deucher 	default:
15973f03ced8SAlex Deucher 		return;
15983f03ced8SAlex Deucher 	}
15993f03ced8SAlex Deucher 
16003f03ced8SAlex Deucher 	switch (mode) {
16013f03ced8SAlex Deucher 	case DRM_MODE_DPMS_ON:
16023f03ced8SAlex Deucher 		args.ucAction = ATOM_ENABLE;
16033f03ced8SAlex Deucher 		/* workaround for DVOOutputControl on some RS690 systems */
16043f03ced8SAlex Deucher 		if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) {
16053f03ced8SAlex Deucher 			u32 reg = RREG32(RADEON_BIOS_3_SCRATCH);
16063f03ced8SAlex Deucher 			WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE);
16073f03ced8SAlex Deucher 			atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
16083f03ced8SAlex Deucher 			WREG32(RADEON_BIOS_3_SCRATCH, reg);
16093f03ced8SAlex Deucher 		} else
16103f03ced8SAlex Deucher 			atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
16113f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
16123f03ced8SAlex Deucher 			args.ucAction = ATOM_LCD_BLON;
16133f03ced8SAlex Deucher 			atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
16143f03ced8SAlex Deucher 		}
16153f03ced8SAlex Deucher 		break;
16163f03ced8SAlex Deucher 	case DRM_MODE_DPMS_STANDBY:
16173f03ced8SAlex Deucher 	case DRM_MODE_DPMS_SUSPEND:
16183f03ced8SAlex Deucher 	case DRM_MODE_DPMS_OFF:
16193f03ced8SAlex Deucher 		args.ucAction = ATOM_DISABLE;
16203f03ced8SAlex Deucher 		atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
16213f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
16223f03ced8SAlex Deucher 			args.ucAction = ATOM_LCD_BLOFF;
16233f03ced8SAlex Deucher 			atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
16243f03ced8SAlex Deucher 		}
16253f03ced8SAlex Deucher 		break;
16263f03ced8SAlex Deucher 	}
16273f03ced8SAlex Deucher }
16283f03ced8SAlex Deucher 
16293f03ced8SAlex Deucher static void
16303f03ced8SAlex Deucher radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode)
16313f03ced8SAlex Deucher {
16323f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
16333f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
16343f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
16358d1af57aSAlex Deucher 	struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
16368d1af57aSAlex Deucher 	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
16373f03ced8SAlex Deucher 	struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
16383f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector = NULL;
16393f03ced8SAlex Deucher 	struct radeon_connector_atom_dig *radeon_dig_connector = NULL;
16406f50e075SAlex Deucher 	bool travis_quirk = false;
16413f03ced8SAlex Deucher 
16423f03ced8SAlex Deucher 	if (connector) {
16433f03ced8SAlex Deucher 		radeon_connector = to_radeon_connector(connector);
16443f03ced8SAlex Deucher 		radeon_dig_connector = radeon_connector->con_priv;
16456f50e075SAlex Deucher 		if ((radeon_connector_encoder_get_dp_bridge_encoder_id(connector) ==
16466f50e075SAlex Deucher 		     ENCODER_OBJECT_ID_TRAVIS) &&
16476f50e075SAlex Deucher 		    (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
16486f50e075SAlex Deucher 		    !ASIC_IS_DCE5(rdev))
16496f50e075SAlex Deucher 			travis_quirk = true;
16503f03ced8SAlex Deucher 	}
16513f03ced8SAlex Deucher 
16523f03ced8SAlex Deucher 	switch (mode) {
16533f03ced8SAlex Deucher 	case DRM_MODE_DPMS_ON:
16548d1af57aSAlex Deucher 		if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
16558d1af57aSAlex Deucher 			if (!connector)
16568d1af57aSAlex Deucher 				dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE;
16578d1af57aSAlex Deucher 			else
16588d1af57aSAlex Deucher 				dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector);
16598d1af57aSAlex Deucher 
16608d1af57aSAlex Deucher 			/* setup and enable the encoder */
1661fcedac67SJerome Glisse 			atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
16628d1af57aSAlex Deucher 			atombios_dig_encoder_setup(encoder,
16638d1af57aSAlex Deucher 						   ATOM_ENCODER_CMD_SETUP_PANEL_MODE,
16648d1af57aSAlex Deucher 						   dig->panel_mode);
16658d1af57aSAlex Deucher 			if (ext_encoder) {
16668d1af57aSAlex Deucher 				if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))
16678d1af57aSAlex Deucher 					atombios_external_encoder_setup(encoder, ext_encoder,
16688d1af57aSAlex Deucher 									EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP);
1669fcedac67SJerome Glisse 			}
16708d1af57aSAlex Deucher 		} else if (ASIC_IS_DCE4(rdev)) {
16718d1af57aSAlex Deucher 			/* setup and enable the encoder */
16728d1af57aSAlex Deucher 			atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
1673fcedac67SJerome Glisse 		} else {
16748d1af57aSAlex Deucher 			/* setup and enable the encoder and transmitter */
16758d1af57aSAlex Deucher 			atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0);
16768d1af57aSAlex Deucher 			atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
1677fcedac67SJerome Glisse 		}
16783f03ced8SAlex Deucher 		if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
16793f03ced8SAlex Deucher 			if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
16803f03ced8SAlex Deucher 				atombios_set_edp_panel_power(connector,
16813f03ced8SAlex Deucher 							     ATOM_TRANSMITTER_ACTION_POWER_ON);
16823f03ced8SAlex Deucher 				radeon_dig_connector->edp_on = true;
16833f03ced8SAlex Deucher 			}
16846f50e075SAlex Deucher 		}
16856f50e075SAlex Deucher 		/* enable the transmitter */
16866f50e075SAlex Deucher 		atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
16876f50e075SAlex Deucher 		if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
16886f50e075SAlex Deucher 			/* DP_SET_POWER_D0 is set in radeon_dp_link_train */
16893f03ced8SAlex Deucher 			radeon_dp_link_train(encoder, connector);
16903f03ced8SAlex Deucher 			if (ASIC_IS_DCE4(rdev))
16913f03ced8SAlex Deucher 				atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0);
16923f03ced8SAlex Deucher 		}
16933f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
16946f50e075SAlex Deucher 			atombios_dig_transmitter_setup(encoder,
16956f50e075SAlex Deucher 						       ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
16966f50e075SAlex Deucher 		if (ext_encoder)
16976f50e075SAlex Deucher 			atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
16983f03ced8SAlex Deucher 		break;
16993f03ced8SAlex Deucher 	case DRM_MODE_DPMS_STANDBY:
17003f03ced8SAlex Deucher 	case DRM_MODE_DPMS_SUSPEND:
17013f03ced8SAlex Deucher 	case DRM_MODE_DPMS_OFF:
170240390961SAlex Deucher 		if (ASIC_IS_DCE4(rdev)) {
17036f50e075SAlex Deucher 			if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector)
17046f50e075SAlex Deucher 				atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
17056f50e075SAlex Deucher 		}
17066f50e075SAlex Deucher 		if (ext_encoder)
17076f50e075SAlex Deucher 			atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE);
17086f50e075SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
17096f50e075SAlex Deucher 			atombios_dig_transmitter_setup(encoder,
17106f50e075SAlex Deucher 						       ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
17116f50e075SAlex Deucher 
17126f50e075SAlex Deucher 		if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) &&
17136f50e075SAlex Deucher 		    connector && !travis_quirk)
17146f50e075SAlex Deucher 			radeon_dp_set_rx_power_state(connector, DP_SET_POWER_D3);
17156f50e075SAlex Deucher 		if (ASIC_IS_DCE4(rdev)) {
17168d1af57aSAlex Deucher 			/* disable the transmitter */
17176f50e075SAlex Deucher 			atombios_dig_transmitter_setup(encoder,
17186f50e075SAlex Deucher 						       ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
17198d1af57aSAlex Deucher 		} else {
17208d1af57aSAlex Deucher 			/* disable the encoder and transmitter */
17216f50e075SAlex Deucher 			atombios_dig_transmitter_setup(encoder,
17226f50e075SAlex Deucher 						       ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
17238d1af57aSAlex Deucher 			atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
17248d1af57aSAlex Deucher 		}
17253f03ced8SAlex Deucher 		if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
17266f50e075SAlex Deucher 			if (travis_quirk)
17276f50e075SAlex Deucher 				radeon_dp_set_rx_power_state(connector, DP_SET_POWER_D3);
17283f03ced8SAlex Deucher 			if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
17293f03ced8SAlex Deucher 				atombios_set_edp_panel_power(connector,
17303f03ced8SAlex Deucher 							     ATOM_TRANSMITTER_ACTION_POWER_OFF);
17313f03ced8SAlex Deucher 				radeon_dig_connector->edp_on = false;
17323f03ced8SAlex Deucher 			}
17333f03ced8SAlex Deucher 		}
17343f03ced8SAlex Deucher 		break;
17353f03ced8SAlex Deucher 	}
17363f03ced8SAlex Deucher }
17373f03ced8SAlex Deucher 
17383f03ced8SAlex Deucher static void
17393f03ced8SAlex Deucher radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
17403f03ced8SAlex Deucher {
17413f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
17423f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
17433f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
17443f03ced8SAlex Deucher 
17453f03ced8SAlex Deucher 	DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
17463f03ced8SAlex Deucher 		  radeon_encoder->encoder_id, mode, radeon_encoder->devices,
17473f03ced8SAlex Deucher 		  radeon_encoder->active_device);
17483f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
17493f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
17503f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
17513f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
17523f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
17533f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
17543f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
17553f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
17563f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
17573f03ced8SAlex Deucher 		radeon_atom_encoder_dpms_avivo(encoder, mode);
17583f03ced8SAlex Deucher 		break;
17593f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
17603f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
17613f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1762e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
17633f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
17643f03ced8SAlex Deucher 		radeon_atom_encoder_dpms_dig(encoder, mode);
17653f03ced8SAlex Deucher 		break;
17663f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
17673f03ced8SAlex Deucher 		if (ASIC_IS_DCE5(rdev)) {
17683f03ced8SAlex Deucher 			switch (mode) {
17693f03ced8SAlex Deucher 			case DRM_MODE_DPMS_ON:
17703f03ced8SAlex Deucher 				atombios_dvo_setup(encoder, ATOM_ENABLE);
17713f03ced8SAlex Deucher 				break;
17723f03ced8SAlex Deucher 			case DRM_MODE_DPMS_STANDBY:
17733f03ced8SAlex Deucher 			case DRM_MODE_DPMS_SUSPEND:
17743f03ced8SAlex Deucher 			case DRM_MODE_DPMS_OFF:
17753f03ced8SAlex Deucher 				atombios_dvo_setup(encoder, ATOM_DISABLE);
17763f03ced8SAlex Deucher 				break;
17773f03ced8SAlex Deucher 			}
17783f03ced8SAlex Deucher 		} else if (ASIC_IS_DCE3(rdev))
17793f03ced8SAlex Deucher 			radeon_atom_encoder_dpms_dig(encoder, mode);
17803f03ced8SAlex Deucher 		else
17813f03ced8SAlex Deucher 			radeon_atom_encoder_dpms_avivo(encoder, mode);
17823f03ced8SAlex Deucher 		break;
17833f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
17843f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
17853f03ced8SAlex Deucher 		if (ASIC_IS_DCE5(rdev)) {
17863f03ced8SAlex Deucher 			switch (mode) {
17873f03ced8SAlex Deucher 			case DRM_MODE_DPMS_ON:
17883f03ced8SAlex Deucher 				atombios_dac_setup(encoder, ATOM_ENABLE);
17893f03ced8SAlex Deucher 				break;
17903f03ced8SAlex Deucher 			case DRM_MODE_DPMS_STANDBY:
17913f03ced8SAlex Deucher 			case DRM_MODE_DPMS_SUSPEND:
17923f03ced8SAlex Deucher 			case DRM_MODE_DPMS_OFF:
17933f03ced8SAlex Deucher 				atombios_dac_setup(encoder, ATOM_DISABLE);
17943f03ced8SAlex Deucher 				break;
17953f03ced8SAlex Deucher 			}
17963f03ced8SAlex Deucher 		} else
17973f03ced8SAlex Deucher 			radeon_atom_encoder_dpms_avivo(encoder, mode);
17983f03ced8SAlex Deucher 		break;
17993f03ced8SAlex Deucher 	default:
18003f03ced8SAlex Deucher 		return;
18013f03ced8SAlex Deucher 	}
18023f03ced8SAlex Deucher 
18033f03ced8SAlex Deucher 	radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
18043f03ced8SAlex Deucher 
18053f03ced8SAlex Deucher }
18063f03ced8SAlex Deucher 
18073f03ced8SAlex Deucher union crtc_source_param {
18083f03ced8SAlex Deucher 	SELECT_CRTC_SOURCE_PS_ALLOCATION v1;
18093f03ced8SAlex Deucher 	SELECT_CRTC_SOURCE_PARAMETERS_V2 v2;
18103f03ced8SAlex Deucher };
18113f03ced8SAlex Deucher 
18123f03ced8SAlex Deucher static void
18133f03ced8SAlex Deucher atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
18143f03ced8SAlex Deucher {
18153f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
18163f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
18173f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
18183f03ced8SAlex Deucher 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
18193f03ced8SAlex Deucher 	union crtc_source_param args;
18203f03ced8SAlex Deucher 	int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source);
18213f03ced8SAlex Deucher 	uint8_t frev, crev;
18223f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig;
18233f03ced8SAlex Deucher 
18243f03ced8SAlex Deucher 	memset(&args, 0, sizeof(args));
18253f03ced8SAlex Deucher 
18263f03ced8SAlex Deucher 	if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
18273f03ced8SAlex Deucher 		return;
18283f03ced8SAlex Deucher 
18293f03ced8SAlex Deucher 	switch (frev) {
18303f03ced8SAlex Deucher 	case 1:
18313f03ced8SAlex Deucher 		switch (crev) {
18323f03ced8SAlex Deucher 		case 1:
18333f03ced8SAlex Deucher 		default:
18343f03ced8SAlex Deucher 			if (ASIC_IS_AVIVO(rdev))
18353f03ced8SAlex Deucher 				args.v1.ucCRTC = radeon_crtc->crtc_id;
18363f03ced8SAlex Deucher 			else {
18373f03ced8SAlex Deucher 				if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) {
18383f03ced8SAlex Deucher 					args.v1.ucCRTC = radeon_crtc->crtc_id;
18393f03ced8SAlex Deucher 				} else {
18403f03ced8SAlex Deucher 					args.v1.ucCRTC = radeon_crtc->crtc_id << 2;
18413f03ced8SAlex Deucher 				}
18423f03ced8SAlex Deucher 			}
18433f03ced8SAlex Deucher 			switch (radeon_encoder->encoder_id) {
18443f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
18453f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
18463f03ced8SAlex Deucher 				args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX;
18473f03ced8SAlex Deucher 				break;
18483f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_LVDS:
18493f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
18503f03ced8SAlex Deucher 				if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT)
18513f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX;
18523f03ced8SAlex Deucher 				else
18533f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX;
18543f03ced8SAlex Deucher 				break;
18553f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_DVO1:
18563f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_DDI:
18573f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
18583f03ced8SAlex Deucher 				args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX;
18593f03ced8SAlex Deucher 				break;
18603f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_DAC1:
18613f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
18623f03ced8SAlex Deucher 				if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
18633f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
18643f03ced8SAlex Deucher 				else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
18653f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
18663f03ced8SAlex Deucher 				else
18673f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX;
18683f03ced8SAlex Deucher 				break;
18693f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_DAC2:
18703f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
18713f03ced8SAlex Deucher 				if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
18723f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
18733f03ced8SAlex Deucher 				else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
18743f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
18753f03ced8SAlex Deucher 				else
18763f03ced8SAlex Deucher 					args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX;
18773f03ced8SAlex Deucher 				break;
18783f03ced8SAlex Deucher 			}
18793f03ced8SAlex Deucher 			break;
18803f03ced8SAlex Deucher 		case 2:
18813f03ced8SAlex Deucher 			args.v2.ucCRTC = radeon_crtc->crtc_id;
18823f03ced8SAlex Deucher 			if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) {
18833f03ced8SAlex Deucher 				struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
18843f03ced8SAlex Deucher 
18853f03ced8SAlex Deucher 				if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
18863f03ced8SAlex Deucher 					args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
18873f03ced8SAlex Deucher 				else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
18883f03ced8SAlex Deucher 					args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT;
18893f03ced8SAlex Deucher 				else
18903f03ced8SAlex Deucher 					args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
189164252835SAlex Deucher 			} else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
189264252835SAlex Deucher 				args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
189364252835SAlex Deucher 			} else {
18943f03ced8SAlex Deucher 				args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
189564252835SAlex Deucher 			}
18963f03ced8SAlex Deucher 			switch (radeon_encoder->encoder_id) {
18973f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
18983f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
18993f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1900e68adef8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
19013f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
19023f03ced8SAlex Deucher 				dig = radeon_encoder->enc_priv;
19033f03ced8SAlex Deucher 				switch (dig->dig_encoder) {
19043f03ced8SAlex Deucher 				case 0:
19053f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
19063f03ced8SAlex Deucher 					break;
19073f03ced8SAlex Deucher 				case 1:
19083f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
19093f03ced8SAlex Deucher 					break;
19103f03ced8SAlex Deucher 				case 2:
19113f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID;
19123f03ced8SAlex Deucher 					break;
19133f03ced8SAlex Deucher 				case 3:
19143f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID;
19153f03ced8SAlex Deucher 					break;
19163f03ced8SAlex Deucher 				case 4:
19173f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID;
19183f03ced8SAlex Deucher 					break;
19193f03ced8SAlex Deucher 				case 5:
19203f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID;
19213f03ced8SAlex Deucher 					break;
1922e68adef8SAlex Deucher 				case 6:
1923e68adef8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DIG7_ENCODER_ID;
1924e68adef8SAlex Deucher 					break;
19253f03ced8SAlex Deucher 				}
19263f03ced8SAlex Deucher 				break;
19273f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
19283f03ced8SAlex Deucher 				args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
19293f03ced8SAlex Deucher 				break;
19303f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
19313f03ced8SAlex Deucher 				if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
19323f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
19333f03ced8SAlex Deucher 				else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
19343f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
19353f03ced8SAlex Deucher 				else
19363f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID;
19373f03ced8SAlex Deucher 				break;
19383f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
19393f03ced8SAlex Deucher 				if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
19403f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
19413f03ced8SAlex Deucher 				else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
19423f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
19433f03ced8SAlex Deucher 				else
19443f03ced8SAlex Deucher 					args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID;
19453f03ced8SAlex Deucher 				break;
19463f03ced8SAlex Deucher 			}
19473f03ced8SAlex Deucher 			break;
19483f03ced8SAlex Deucher 		}
19493f03ced8SAlex Deucher 		break;
19503f03ced8SAlex Deucher 	default:
19513f03ced8SAlex Deucher 		DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
19523f03ced8SAlex Deucher 		return;
19533f03ced8SAlex Deucher 	}
19543f03ced8SAlex Deucher 
19553f03ced8SAlex Deucher 	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
19563f03ced8SAlex Deucher 
19573f03ced8SAlex Deucher 	/* update scratch regs with new routing */
19583f03ced8SAlex Deucher 	radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
19593f03ced8SAlex Deucher }
19603f03ced8SAlex Deucher 
19613f03ced8SAlex Deucher static void
19623f03ced8SAlex Deucher atombios_apply_encoder_quirks(struct drm_encoder *encoder,
19633f03ced8SAlex Deucher 			      struct drm_display_mode *mode)
19643f03ced8SAlex Deucher {
19653f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
19663f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
19673f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
19683f03ced8SAlex Deucher 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
19693f03ced8SAlex Deucher 
19703f03ced8SAlex Deucher 	/* Funky macbooks */
19713f03ced8SAlex Deucher 	if ((dev->pdev->device == 0x71C5) &&
19723f03ced8SAlex Deucher 	    (dev->pdev->subsystem_vendor == 0x106b) &&
19733f03ced8SAlex Deucher 	    (dev->pdev->subsystem_device == 0x0080)) {
19743f03ced8SAlex Deucher 		if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
19753f03ced8SAlex Deucher 			uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL);
19763f03ced8SAlex Deucher 
19773f03ced8SAlex Deucher 			lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN;
19783f03ced8SAlex Deucher 			lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN;
19793f03ced8SAlex Deucher 
19803f03ced8SAlex Deucher 			WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control);
19813f03ced8SAlex Deucher 		}
19823f03ced8SAlex Deucher 	}
19833f03ced8SAlex Deucher 
19843f03ced8SAlex Deucher 	/* set scaler clears this on some chips */
19853f03ced8SAlex Deucher 	if (ASIC_IS_AVIVO(rdev) &&
19863f03ced8SAlex Deucher 	    (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) {
1987d798f2f2SAlex Deucher 		if (ASIC_IS_DCE8(rdev)) {
1988d798f2f2SAlex Deucher 			if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1989d798f2f2SAlex Deucher 				WREG32(CIK_LB_DATA_FORMAT + radeon_crtc->crtc_offset,
1990d798f2f2SAlex Deucher 				       CIK_INTERLEAVE_EN);
1991d798f2f2SAlex Deucher 			else
1992d798f2f2SAlex Deucher 				WREG32(CIK_LB_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1993d798f2f2SAlex Deucher 		} else if (ASIC_IS_DCE4(rdev)) {
19943f03ced8SAlex Deucher 			if (mode->flags & DRM_MODE_FLAG_INTERLACE)
19953f03ced8SAlex Deucher 				WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset,
19963f03ced8SAlex Deucher 				       EVERGREEN_INTERLEAVE_EN);
19973f03ced8SAlex Deucher 			else
19983f03ced8SAlex Deucher 				WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
19993f03ced8SAlex Deucher 		} else {
20003f03ced8SAlex Deucher 			if (mode->flags & DRM_MODE_FLAG_INTERLACE)
20013f03ced8SAlex Deucher 				WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
20023f03ced8SAlex Deucher 				       AVIVO_D1MODE_INTERLEAVE_EN);
20033f03ced8SAlex Deucher 			else
20043f03ced8SAlex Deucher 				WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
20053f03ced8SAlex Deucher 		}
20063f03ced8SAlex Deucher 	}
20073f03ced8SAlex Deucher }
20083f03ced8SAlex Deucher 
20093f03ced8SAlex Deucher static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder)
20103f03ced8SAlex Deucher {
20113f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
20123f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
20133f03ced8SAlex Deucher 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
20143f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
20153f03ced8SAlex Deucher 	struct drm_encoder *test_encoder;
201641fa5437SAlex Deucher 	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
20173f03ced8SAlex Deucher 	uint32_t dig_enc_in_use = 0;
20183f03ced8SAlex Deucher 
201941fa5437SAlex Deucher 	if (ASIC_IS_DCE6(rdev)) {
202041fa5437SAlex Deucher 		/* DCE6 */
202141fa5437SAlex Deucher 		switch (radeon_encoder->encoder_id) {
202241fa5437SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
202341fa5437SAlex Deucher 			if (dig->linkb)
202441fa5437SAlex Deucher 				return 1;
202541fa5437SAlex Deucher 			else
202641fa5437SAlex Deucher 				return 0;
202741fa5437SAlex Deucher 			break;
202841fa5437SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
202941fa5437SAlex Deucher 			if (dig->linkb)
203041fa5437SAlex Deucher 				return 3;
203141fa5437SAlex Deucher 			else
203241fa5437SAlex Deucher 				return 2;
203341fa5437SAlex Deucher 			break;
203441fa5437SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
203541fa5437SAlex Deucher 			if (dig->linkb)
203641fa5437SAlex Deucher 				return 5;
203741fa5437SAlex Deucher 			else
203841fa5437SAlex Deucher 				return 4;
203941fa5437SAlex Deucher 			break;
2040e68adef8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
2041e68adef8SAlex Deucher 			return 6;
2042e68adef8SAlex Deucher 			break;
204341fa5437SAlex Deucher 		}
204441fa5437SAlex Deucher 	} else if (ASIC_IS_DCE4(rdev)) {
20453f03ced8SAlex Deucher 		/* DCE4/5 */
204641fa5437SAlex Deucher 		if (ASIC_IS_DCE41(rdev) && !ASIC_IS_DCE61(rdev)) {
20473f03ced8SAlex Deucher 			/* ontario follows DCE4 */
20483f03ced8SAlex Deucher 			if (rdev->family == CHIP_PALM) {
20493f03ced8SAlex Deucher 				if (dig->linkb)
20503f03ced8SAlex Deucher 					return 1;
20513f03ced8SAlex Deucher 				else
20523f03ced8SAlex Deucher 					return 0;
20533f03ced8SAlex Deucher 			} else
20543f03ced8SAlex Deucher 				/* llano follows DCE3.2 */
20553f03ced8SAlex Deucher 				return radeon_crtc->crtc_id;
20563f03ced8SAlex Deucher 		} else {
20573f03ced8SAlex Deucher 			switch (radeon_encoder->encoder_id) {
20583f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
20593f03ced8SAlex Deucher 				if (dig->linkb)
20603f03ced8SAlex Deucher 					return 1;
20613f03ced8SAlex Deucher 				else
20623f03ced8SAlex Deucher 					return 0;
20633f03ced8SAlex Deucher 				break;
20643f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
20653f03ced8SAlex Deucher 				if (dig->linkb)
20663f03ced8SAlex Deucher 					return 3;
20673f03ced8SAlex Deucher 				else
20683f03ced8SAlex Deucher 					return 2;
20693f03ced8SAlex Deucher 				break;
20703f03ced8SAlex Deucher 			case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
20713f03ced8SAlex Deucher 				if (dig->linkb)
20723f03ced8SAlex Deucher 					return 5;
20733f03ced8SAlex Deucher 				else
20743f03ced8SAlex Deucher 					return 4;
20753f03ced8SAlex Deucher 				break;
20763f03ced8SAlex Deucher 			}
20773f03ced8SAlex Deucher 		}
20783f03ced8SAlex Deucher 	}
20793f03ced8SAlex Deucher 
20803f03ced8SAlex Deucher 	/* on DCE32 and encoder can driver any block so just crtc id */
20813f03ced8SAlex Deucher 	if (ASIC_IS_DCE32(rdev)) {
20823f03ced8SAlex Deucher 		return radeon_crtc->crtc_id;
20833f03ced8SAlex Deucher 	}
20843f03ced8SAlex Deucher 
20853f03ced8SAlex Deucher 	/* on DCE3 - LVTMA can only be driven by DIGB */
20863f03ced8SAlex Deucher 	list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
20873f03ced8SAlex Deucher 		struct radeon_encoder *radeon_test_encoder;
20883f03ced8SAlex Deucher 
20893f03ced8SAlex Deucher 		if (encoder == test_encoder)
20903f03ced8SAlex Deucher 			continue;
20913f03ced8SAlex Deucher 
20923f03ced8SAlex Deucher 		if (!radeon_encoder_is_digital(test_encoder))
20933f03ced8SAlex Deucher 			continue;
20943f03ced8SAlex Deucher 
20953f03ced8SAlex Deucher 		radeon_test_encoder = to_radeon_encoder(test_encoder);
20963f03ced8SAlex Deucher 		dig = radeon_test_encoder->enc_priv;
20973f03ced8SAlex Deucher 
20983f03ced8SAlex Deucher 		if (dig->dig_encoder >= 0)
20993f03ced8SAlex Deucher 			dig_enc_in_use |= (1 << dig->dig_encoder);
21003f03ced8SAlex Deucher 	}
21013f03ced8SAlex Deucher 
21023f03ced8SAlex Deucher 	if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) {
21033f03ced8SAlex Deucher 		if (dig_enc_in_use & 0x2)
21043f03ced8SAlex Deucher 			DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
21053f03ced8SAlex Deucher 		return 1;
21063f03ced8SAlex Deucher 	}
21073f03ced8SAlex Deucher 	if (!(dig_enc_in_use & 1))
21083f03ced8SAlex Deucher 		return 0;
21093f03ced8SAlex Deucher 	return 1;
21103f03ced8SAlex Deucher }
21113f03ced8SAlex Deucher 
21123f03ced8SAlex Deucher /* This only needs to be called once at startup */
21133f03ced8SAlex Deucher void
21143f03ced8SAlex Deucher radeon_atom_encoder_init(struct radeon_device *rdev)
21153f03ced8SAlex Deucher {
21163f03ced8SAlex Deucher 	struct drm_device *dev = rdev->ddev;
21173f03ced8SAlex Deucher 	struct drm_encoder *encoder;
21183f03ced8SAlex Deucher 
21193f03ced8SAlex Deucher 	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
21203f03ced8SAlex Deucher 		struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
21213f03ced8SAlex Deucher 		struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
21223f03ced8SAlex Deucher 
21233f03ced8SAlex Deucher 		switch (radeon_encoder->encoder_id) {
21243f03ced8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
21253f03ced8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
21263f03ced8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2127e68adef8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
21283f03ced8SAlex Deucher 		case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
21293f03ced8SAlex Deucher 			atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
21303f03ced8SAlex Deucher 			break;
21313f03ced8SAlex Deucher 		default:
21323f03ced8SAlex Deucher 			break;
21333f03ced8SAlex Deucher 		}
21343f03ced8SAlex Deucher 
21351d3949c4SAlex Deucher 		if (ext_encoder && (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)))
21363f03ced8SAlex Deucher 			atombios_external_encoder_setup(encoder, ext_encoder,
21373f03ced8SAlex Deucher 							EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT);
21383f03ced8SAlex Deucher 	}
21393f03ced8SAlex Deucher }
21403f03ced8SAlex Deucher 
21413f03ced8SAlex Deucher static void
21423f03ced8SAlex Deucher radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
21433f03ced8SAlex Deucher 			     struct drm_display_mode *mode,
21443f03ced8SAlex Deucher 			     struct drm_display_mode *adjusted_mode)
21453f03ced8SAlex Deucher {
21463f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
21473f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
21483f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
21493f03ced8SAlex Deucher 
21503f03ced8SAlex Deucher 	radeon_encoder->pixel_clock = adjusted_mode->clock;
21513f03ced8SAlex Deucher 
21528d1af57aSAlex Deucher 	/* need to call this here rather than in prepare() since we need some crtc info */
21538d1af57aSAlex Deucher 	radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
21548d1af57aSAlex Deucher 
21553f03ced8SAlex Deucher 	if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) {
21563f03ced8SAlex Deucher 		if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT))
21573f03ced8SAlex Deucher 			atombios_yuv_setup(encoder, true);
21583f03ced8SAlex Deucher 		else
21593f03ced8SAlex Deucher 			atombios_yuv_setup(encoder, false);
21603f03ced8SAlex Deucher 	}
21613f03ced8SAlex Deucher 
21623f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
21633f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
21643f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
21653f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
21663f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
21673f03ced8SAlex Deucher 		atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
21683f03ced8SAlex Deucher 		break;
21693f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
21703f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
21713f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2172e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
21733f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
21748d1af57aSAlex Deucher 		/* handled in dpms */
21753f03ced8SAlex Deucher 		break;
21763f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
21773f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
21783f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
21793f03ced8SAlex Deucher 		atombios_dvo_setup(encoder, ATOM_ENABLE);
21803f03ced8SAlex Deucher 		break;
21813f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
21823f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
21833f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
21843f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
21853f03ced8SAlex Deucher 		atombios_dac_setup(encoder, ATOM_ENABLE);
21863f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) {
21873f03ced8SAlex Deucher 			if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
21883f03ced8SAlex Deucher 				atombios_tv_setup(encoder, ATOM_ENABLE);
21893f03ced8SAlex Deucher 			else
21903f03ced8SAlex Deucher 				atombios_tv_setup(encoder, ATOM_DISABLE);
21913f03ced8SAlex Deucher 		}
21923f03ced8SAlex Deucher 		break;
21933f03ced8SAlex Deucher 	}
21943f03ced8SAlex Deucher 
21953f03ced8SAlex Deucher 	atombios_apply_encoder_quirks(encoder, adjusted_mode);
21963f03ced8SAlex Deucher 
21973f03ced8SAlex Deucher 	if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
2198a973bea1SAlex Deucher 		if (rdev->asic->display.hdmi_enable)
2199a973bea1SAlex Deucher 			radeon_hdmi_enable(rdev, encoder, true);
2200a973bea1SAlex Deucher 		if (rdev->asic->display.hdmi_setmode)
2201a973bea1SAlex Deucher 			radeon_hdmi_setmode(rdev, encoder, adjusted_mode);
22023f03ced8SAlex Deucher 	}
22033f03ced8SAlex Deucher }
22043f03ced8SAlex Deucher 
22053f03ced8SAlex Deucher static bool
22063f03ced8SAlex Deucher atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector)
22073f03ced8SAlex Deucher {
22083f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
22093f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
22103f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
22113f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
22123f03ced8SAlex Deucher 
22133f03ced8SAlex Deucher 	if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT |
22143f03ced8SAlex Deucher 				       ATOM_DEVICE_CV_SUPPORT |
22153f03ced8SAlex Deucher 				       ATOM_DEVICE_CRT_SUPPORT)) {
22163f03ced8SAlex Deucher 		DAC_LOAD_DETECTION_PS_ALLOCATION args;
22173f03ced8SAlex Deucher 		int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection);
22183f03ced8SAlex Deucher 		uint8_t frev, crev;
22193f03ced8SAlex Deucher 
22203f03ced8SAlex Deucher 		memset(&args, 0, sizeof(args));
22213f03ced8SAlex Deucher 
22223f03ced8SAlex Deucher 		if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
22233f03ced8SAlex Deucher 			return false;
22243f03ced8SAlex Deucher 
22253f03ced8SAlex Deucher 		args.sDacload.ucMisc = 0;
22263f03ced8SAlex Deucher 
22273f03ced8SAlex Deucher 		if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) ||
22283f03ced8SAlex Deucher 		    (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1))
22293f03ced8SAlex Deucher 			args.sDacload.ucDacType = ATOM_DAC_A;
22303f03ced8SAlex Deucher 		else
22313f03ced8SAlex Deucher 			args.sDacload.ucDacType = ATOM_DAC_B;
22323f03ced8SAlex Deucher 
22333f03ced8SAlex Deucher 		if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)
22343f03ced8SAlex Deucher 			args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT);
22353f03ced8SAlex Deucher 		else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)
22363f03ced8SAlex Deucher 			args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT);
22373f03ced8SAlex Deucher 		else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
22383f03ced8SAlex Deucher 			args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT);
22393f03ced8SAlex Deucher 			if (crev >= 3)
22403f03ced8SAlex Deucher 				args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
22413f03ced8SAlex Deucher 		} else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
22423f03ced8SAlex Deucher 			args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT);
22433f03ced8SAlex Deucher 			if (crev >= 3)
22443f03ced8SAlex Deucher 				args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
22453f03ced8SAlex Deucher 		}
22463f03ced8SAlex Deucher 
22473f03ced8SAlex Deucher 		atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
22483f03ced8SAlex Deucher 
22493f03ced8SAlex Deucher 		return true;
22503f03ced8SAlex Deucher 	} else
22513f03ced8SAlex Deucher 		return false;
22523f03ced8SAlex Deucher }
22533f03ced8SAlex Deucher 
22543f03ced8SAlex Deucher static enum drm_connector_status
22553f03ced8SAlex Deucher radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
22563f03ced8SAlex Deucher {
22573f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
22583f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
22593f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
22603f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
22613f03ced8SAlex Deucher 	uint32_t bios_0_scratch;
22623f03ced8SAlex Deucher 
22633f03ced8SAlex Deucher 	if (!atombios_dac_load_detect(encoder, connector)) {
22643f03ced8SAlex Deucher 		DRM_DEBUG_KMS("detect returned false \n");
22653f03ced8SAlex Deucher 		return connector_status_unknown;
22663f03ced8SAlex Deucher 	}
22673f03ced8SAlex Deucher 
22683f03ced8SAlex Deucher 	if (rdev->family >= CHIP_R600)
22693f03ced8SAlex Deucher 		bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
22703f03ced8SAlex Deucher 	else
22713f03ced8SAlex Deucher 		bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
22723f03ced8SAlex Deucher 
22733f03ced8SAlex Deucher 	DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
22743f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
22753f03ced8SAlex Deucher 		if (bios_0_scratch & ATOM_S0_CRT1_MASK)
22763f03ced8SAlex Deucher 			return connector_status_connected;
22773f03ced8SAlex Deucher 	}
22783f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
22793f03ced8SAlex Deucher 		if (bios_0_scratch & ATOM_S0_CRT2_MASK)
22803f03ced8SAlex Deucher 			return connector_status_connected;
22813f03ced8SAlex Deucher 	}
22823f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
22833f03ced8SAlex Deucher 		if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
22843f03ced8SAlex Deucher 			return connector_status_connected;
22853f03ced8SAlex Deucher 	}
22863f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
22873f03ced8SAlex Deucher 		if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
22883f03ced8SAlex Deucher 			return connector_status_connected; /* CTV */
22893f03ced8SAlex Deucher 		else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
22903f03ced8SAlex Deucher 			return connector_status_connected; /* STV */
22913f03ced8SAlex Deucher 	}
22923f03ced8SAlex Deucher 	return connector_status_disconnected;
22933f03ced8SAlex Deucher }
22943f03ced8SAlex Deucher 
22953f03ced8SAlex Deucher static enum drm_connector_status
22963f03ced8SAlex Deucher radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector)
22973f03ced8SAlex Deucher {
22983f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
22993f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
23003f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
23013f03ced8SAlex Deucher 	struct radeon_connector *radeon_connector = to_radeon_connector(connector);
23023f03ced8SAlex Deucher 	struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
23033f03ced8SAlex Deucher 	u32 bios_0_scratch;
23043f03ced8SAlex Deucher 
23053f03ced8SAlex Deucher 	if (!ASIC_IS_DCE4(rdev))
23063f03ced8SAlex Deucher 		return connector_status_unknown;
23073f03ced8SAlex Deucher 
23083f03ced8SAlex Deucher 	if (!ext_encoder)
23093f03ced8SAlex Deucher 		return connector_status_unknown;
23103f03ced8SAlex Deucher 
23113f03ced8SAlex Deucher 	if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0)
23123f03ced8SAlex Deucher 		return connector_status_unknown;
23133f03ced8SAlex Deucher 
23143f03ced8SAlex Deucher 	/* load detect on the dp bridge */
23153f03ced8SAlex Deucher 	atombios_external_encoder_setup(encoder, ext_encoder,
23163f03ced8SAlex Deucher 					EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION);
23173f03ced8SAlex Deucher 
23183f03ced8SAlex Deucher 	bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
23193f03ced8SAlex Deucher 
23203f03ced8SAlex Deucher 	DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
23213f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
23223f03ced8SAlex Deucher 		if (bios_0_scratch & ATOM_S0_CRT1_MASK)
23233f03ced8SAlex Deucher 			return connector_status_connected;
23243f03ced8SAlex Deucher 	}
23253f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
23263f03ced8SAlex Deucher 		if (bios_0_scratch & ATOM_S0_CRT2_MASK)
23273f03ced8SAlex Deucher 			return connector_status_connected;
23283f03ced8SAlex Deucher 	}
23293f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
23303f03ced8SAlex Deucher 		if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
23313f03ced8SAlex Deucher 			return connector_status_connected;
23323f03ced8SAlex Deucher 	}
23333f03ced8SAlex Deucher 	if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
23343f03ced8SAlex Deucher 		if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
23353f03ced8SAlex Deucher 			return connector_status_connected; /* CTV */
23363f03ced8SAlex Deucher 		else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
23373f03ced8SAlex Deucher 			return connector_status_connected; /* STV */
23383f03ced8SAlex Deucher 	}
23393f03ced8SAlex Deucher 	return connector_status_disconnected;
23403f03ced8SAlex Deucher }
23413f03ced8SAlex Deucher 
23423f03ced8SAlex Deucher void
23433f03ced8SAlex Deucher radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder)
23443f03ced8SAlex Deucher {
23453f03ced8SAlex Deucher 	struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
23463f03ced8SAlex Deucher 
23473f03ced8SAlex Deucher 	if (ext_encoder)
23483f03ced8SAlex Deucher 		/* ddc_setup on the dp bridge */
23493f03ced8SAlex Deucher 		atombios_external_encoder_setup(encoder, ext_encoder,
23503f03ced8SAlex Deucher 						EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP);
23513f03ced8SAlex Deucher 
23523f03ced8SAlex Deucher }
23533f03ced8SAlex Deucher 
23543f03ced8SAlex Deucher static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
23553f03ced8SAlex Deucher {
2356cfcbd6d3SRafał Miłecki 	struct radeon_device *rdev = encoder->dev->dev_private;
23573f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
23583f03ced8SAlex Deucher 	struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
23593f03ced8SAlex Deucher 
23603f03ced8SAlex Deucher 	if ((radeon_encoder->active_device &
23613f03ced8SAlex Deucher 	     (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
23623f03ced8SAlex Deucher 	    (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
23633f03ced8SAlex Deucher 	     ENCODER_OBJECT_ID_NONE)) {
23643f03ced8SAlex Deucher 		struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
2365cfcbd6d3SRafał Miłecki 		if (dig) {
23663f03ced8SAlex Deucher 			dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder);
2367cfcbd6d3SRafał Miłecki 			if (radeon_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT) {
2368cfcbd6d3SRafał Miłecki 				if (rdev->family >= CHIP_R600)
2369cfcbd6d3SRafał Miłecki 					dig->afmt = rdev->mode_info.afmt[dig->dig_encoder];
2370cfcbd6d3SRafał Miłecki 				else
2371cfcbd6d3SRafał Miłecki 					/* RS600/690/740 have only 1 afmt block */
2372cfcbd6d3SRafał Miłecki 					dig->afmt = rdev->mode_info.afmt[0];
2373cfcbd6d3SRafał Miłecki 			}
2374cfcbd6d3SRafał Miłecki 		}
23753f03ced8SAlex Deucher 	}
23763f03ced8SAlex Deucher 
23773f03ced8SAlex Deucher 	radeon_atom_output_lock(encoder, true);
23783f03ced8SAlex Deucher 
23793f03ced8SAlex Deucher 	if (connector) {
23803f03ced8SAlex Deucher 		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
23813f03ced8SAlex Deucher 
23823f03ced8SAlex Deucher 		/* select the clock/data port if it uses a router */
23833f03ced8SAlex Deucher 		if (radeon_connector->router.cd_valid)
23843f03ced8SAlex Deucher 			radeon_router_select_cd_port(radeon_connector);
23853f03ced8SAlex Deucher 
23863f03ced8SAlex Deucher 		/* turn eDP panel on for mode set */
23873f03ced8SAlex Deucher 		if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
23883f03ced8SAlex Deucher 			atombios_set_edp_panel_power(connector,
23893f03ced8SAlex Deucher 						     ATOM_TRANSMITTER_ACTION_POWER_ON);
23903f03ced8SAlex Deucher 	}
23913f03ced8SAlex Deucher 
23923f03ced8SAlex Deucher 	/* this is needed for the pll/ss setup to work correctly in some cases */
23933f03ced8SAlex Deucher 	atombios_set_encoder_crtc_source(encoder);
2394134b480fSAlex Deucher 	/* set up the FMT blocks */
2395134b480fSAlex Deucher 	if (ASIC_IS_DCE8(rdev))
2396134b480fSAlex Deucher 		dce8_program_fmt(encoder);
2397134b480fSAlex Deucher 	else if (ASIC_IS_DCE4(rdev))
2398134b480fSAlex Deucher 		dce4_program_fmt(encoder);
2399134b480fSAlex Deucher 	else if (ASIC_IS_DCE3(rdev))
2400134b480fSAlex Deucher 		dce3_program_fmt(encoder);
2401134b480fSAlex Deucher 	else if (ASIC_IS_AVIVO(rdev))
2402134b480fSAlex Deucher 		avivo_program_fmt(encoder);
24033f03ced8SAlex Deucher }
24043f03ced8SAlex Deucher 
24053f03ced8SAlex Deucher static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
24063f03ced8SAlex Deucher {
24078d1af57aSAlex Deucher 	/* need to call this here as we need the crtc set up */
24083f03ced8SAlex Deucher 	radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
24093f03ced8SAlex Deucher 	radeon_atom_output_lock(encoder, false);
24103f03ced8SAlex Deucher }
24113f03ced8SAlex Deucher 
24123f03ced8SAlex Deucher static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
24133f03ced8SAlex Deucher {
24143f03ced8SAlex Deucher 	struct drm_device *dev = encoder->dev;
24153f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
24163f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
24173f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig;
24183f03ced8SAlex Deucher 
24193f03ced8SAlex Deucher 	/* check for pre-DCE3 cards with shared encoders;
24203f03ced8SAlex Deucher 	 * can't really use the links individually, so don't disable
24213f03ced8SAlex Deucher 	 * the encoder if it's in use by another connector
24223f03ced8SAlex Deucher 	 */
24233f03ced8SAlex Deucher 	if (!ASIC_IS_DCE3(rdev)) {
24243f03ced8SAlex Deucher 		struct drm_encoder *other_encoder;
24253f03ced8SAlex Deucher 		struct radeon_encoder *other_radeon_encoder;
24263f03ced8SAlex Deucher 
24273f03ced8SAlex Deucher 		list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
24283f03ced8SAlex Deucher 			other_radeon_encoder = to_radeon_encoder(other_encoder);
24293f03ced8SAlex Deucher 			if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
24303f03ced8SAlex Deucher 			    drm_helper_encoder_in_use(other_encoder))
24313f03ced8SAlex Deucher 				goto disable_done;
24323f03ced8SAlex Deucher 		}
24333f03ced8SAlex Deucher 	}
24343f03ced8SAlex Deucher 
24353f03ced8SAlex Deucher 	radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
24363f03ced8SAlex Deucher 
24373f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
24383f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
24393f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
24403f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
24413f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
24423f03ced8SAlex Deucher 		atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE);
24433f03ced8SAlex Deucher 		break;
24443f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
24453f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
24463f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2447e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
24483f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
24498d1af57aSAlex Deucher 		/* handled in dpms */
24503f03ced8SAlex Deucher 		break;
24513f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
24523f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
24533f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
24543f03ced8SAlex Deucher 		atombios_dvo_setup(encoder, ATOM_DISABLE);
24553f03ced8SAlex Deucher 		break;
24563f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
24573f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
24583f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
24593f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
24603f03ced8SAlex Deucher 		atombios_dac_setup(encoder, ATOM_DISABLE);
24613f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
24623f03ced8SAlex Deucher 			atombios_tv_setup(encoder, ATOM_DISABLE);
24633f03ced8SAlex Deucher 		break;
24643f03ced8SAlex Deucher 	}
24653f03ced8SAlex Deucher 
24663f03ced8SAlex Deucher disable_done:
24673f03ced8SAlex Deucher 	if (radeon_encoder_is_digital(encoder)) {
2468a973bea1SAlex Deucher 		if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
2469a973bea1SAlex Deucher 			if (rdev->asic->display.hdmi_enable)
2470a973bea1SAlex Deucher 				radeon_hdmi_enable(rdev, encoder, false);
2471a973bea1SAlex Deucher 		}
24723f03ced8SAlex Deucher 		dig = radeon_encoder->enc_priv;
24733f03ced8SAlex Deucher 		dig->dig_encoder = -1;
24743f03ced8SAlex Deucher 	}
24753f03ced8SAlex Deucher 	radeon_encoder->active_device = 0;
24763f03ced8SAlex Deucher }
24773f03ced8SAlex Deucher 
24783f03ced8SAlex Deucher /* these are handled by the primary encoders */
24793f03ced8SAlex Deucher static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
24803f03ced8SAlex Deucher {
24813f03ced8SAlex Deucher 
24823f03ced8SAlex Deucher }
24833f03ced8SAlex Deucher 
24843f03ced8SAlex Deucher static void radeon_atom_ext_commit(struct drm_encoder *encoder)
24853f03ced8SAlex Deucher {
24863f03ced8SAlex Deucher 
24873f03ced8SAlex Deucher }
24883f03ced8SAlex Deucher 
24893f03ced8SAlex Deucher static void
24903f03ced8SAlex Deucher radeon_atom_ext_mode_set(struct drm_encoder *encoder,
24913f03ced8SAlex Deucher 			 struct drm_display_mode *mode,
24923f03ced8SAlex Deucher 			 struct drm_display_mode *adjusted_mode)
24933f03ced8SAlex Deucher {
24943f03ced8SAlex Deucher 
24953f03ced8SAlex Deucher }
24963f03ced8SAlex Deucher 
24973f03ced8SAlex Deucher static void radeon_atom_ext_disable(struct drm_encoder *encoder)
24983f03ced8SAlex Deucher {
24993f03ced8SAlex Deucher 
25003f03ced8SAlex Deucher }
25013f03ced8SAlex Deucher 
25023f03ced8SAlex Deucher static void
25033f03ced8SAlex Deucher radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
25043f03ced8SAlex Deucher {
25053f03ced8SAlex Deucher 
25063f03ced8SAlex Deucher }
25073f03ced8SAlex Deucher 
25083f03ced8SAlex Deucher static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
2509e811f5aeSLaurent Pinchart 				       const struct drm_display_mode *mode,
25103f03ced8SAlex Deucher 				       struct drm_display_mode *adjusted_mode)
25113f03ced8SAlex Deucher {
25123f03ced8SAlex Deucher 	return true;
25133f03ced8SAlex Deucher }
25143f03ced8SAlex Deucher 
25153f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
25163f03ced8SAlex Deucher 	.dpms = radeon_atom_ext_dpms,
25173f03ced8SAlex Deucher 	.mode_fixup = radeon_atom_ext_mode_fixup,
25183f03ced8SAlex Deucher 	.prepare = radeon_atom_ext_prepare,
25193f03ced8SAlex Deucher 	.mode_set = radeon_atom_ext_mode_set,
25203f03ced8SAlex Deucher 	.commit = radeon_atom_ext_commit,
25213f03ced8SAlex Deucher 	.disable = radeon_atom_ext_disable,
25223f03ced8SAlex Deucher 	/* no detect for TMDS/LVDS yet */
25233f03ced8SAlex Deucher };
25243f03ced8SAlex Deucher 
25253f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
25263f03ced8SAlex Deucher 	.dpms = radeon_atom_encoder_dpms,
25273f03ced8SAlex Deucher 	.mode_fixup = radeon_atom_mode_fixup,
25283f03ced8SAlex Deucher 	.prepare = radeon_atom_encoder_prepare,
25293f03ced8SAlex Deucher 	.mode_set = radeon_atom_encoder_mode_set,
25303f03ced8SAlex Deucher 	.commit = radeon_atom_encoder_commit,
25313f03ced8SAlex Deucher 	.disable = radeon_atom_encoder_disable,
25323f03ced8SAlex Deucher 	.detect = radeon_atom_dig_detect,
25333f03ced8SAlex Deucher };
25343f03ced8SAlex Deucher 
25353f03ced8SAlex Deucher static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = {
25363f03ced8SAlex Deucher 	.dpms = radeon_atom_encoder_dpms,
25373f03ced8SAlex Deucher 	.mode_fixup = radeon_atom_mode_fixup,
25383f03ced8SAlex Deucher 	.prepare = radeon_atom_encoder_prepare,
25393f03ced8SAlex Deucher 	.mode_set = radeon_atom_encoder_mode_set,
25403f03ced8SAlex Deucher 	.commit = radeon_atom_encoder_commit,
25413f03ced8SAlex Deucher 	.detect = radeon_atom_dac_detect,
25423f03ced8SAlex Deucher };
25433f03ced8SAlex Deucher 
25443f03ced8SAlex Deucher void radeon_enc_destroy(struct drm_encoder *encoder)
25453f03ced8SAlex Deucher {
25463f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2547f3728734SAlex Deucher 	if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2548f3728734SAlex Deucher 		radeon_atom_backlight_exit(radeon_encoder);
25493f03ced8SAlex Deucher 	kfree(radeon_encoder->enc_priv);
25503f03ced8SAlex Deucher 	drm_encoder_cleanup(encoder);
25513f03ced8SAlex Deucher 	kfree(radeon_encoder);
25523f03ced8SAlex Deucher }
25533f03ced8SAlex Deucher 
25543f03ced8SAlex Deucher static const struct drm_encoder_funcs radeon_atom_enc_funcs = {
25553f03ced8SAlex Deucher 	.destroy = radeon_enc_destroy,
25563f03ced8SAlex Deucher };
25573f03ced8SAlex Deucher 
25581109ca09SLauri Kasanen static struct radeon_encoder_atom_dac *
25593f03ced8SAlex Deucher radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder)
25603f03ced8SAlex Deucher {
25613f03ced8SAlex Deucher 	struct drm_device *dev = radeon_encoder->base.dev;
25623f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
25633f03ced8SAlex Deucher 	struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL);
25643f03ced8SAlex Deucher 
25653f03ced8SAlex Deucher 	if (!dac)
25663f03ced8SAlex Deucher 		return NULL;
25673f03ced8SAlex Deucher 
25683f03ced8SAlex Deucher 	dac->tv_std = radeon_atombios_get_tv_info(rdev);
25693f03ced8SAlex Deucher 	return dac;
25703f03ced8SAlex Deucher }
25713f03ced8SAlex Deucher 
25721109ca09SLauri Kasanen static struct radeon_encoder_atom_dig *
25733f03ced8SAlex Deucher radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
25743f03ced8SAlex Deucher {
25753f03ced8SAlex Deucher 	int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
25763f03ced8SAlex Deucher 	struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
25773f03ced8SAlex Deucher 
25783f03ced8SAlex Deucher 	if (!dig)
25793f03ced8SAlex Deucher 		return NULL;
25803f03ced8SAlex Deucher 
25813f03ced8SAlex Deucher 	/* coherent mode by default */
25823f03ced8SAlex Deucher 	dig->coherent_mode = true;
25833f03ced8SAlex Deucher 	dig->dig_encoder = -1;
25843f03ced8SAlex Deucher 
25853f03ced8SAlex Deucher 	if (encoder_enum == 2)
25863f03ced8SAlex Deucher 		dig->linkb = true;
25873f03ced8SAlex Deucher 	else
25883f03ced8SAlex Deucher 		dig->linkb = false;
25893f03ced8SAlex Deucher 
25903f03ced8SAlex Deucher 	return dig;
25913f03ced8SAlex Deucher }
25923f03ced8SAlex Deucher 
25933f03ced8SAlex Deucher void
25943f03ced8SAlex Deucher radeon_add_atom_encoder(struct drm_device *dev,
25953f03ced8SAlex Deucher 			uint32_t encoder_enum,
25963f03ced8SAlex Deucher 			uint32_t supported_device,
25973f03ced8SAlex Deucher 			u16 caps)
25983f03ced8SAlex Deucher {
25993f03ced8SAlex Deucher 	struct radeon_device *rdev = dev->dev_private;
26003f03ced8SAlex Deucher 	struct drm_encoder *encoder;
26013f03ced8SAlex Deucher 	struct radeon_encoder *radeon_encoder;
26023f03ced8SAlex Deucher 
26033f03ced8SAlex Deucher 	/* see if we already added it */
26043f03ced8SAlex Deucher 	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
26053f03ced8SAlex Deucher 		radeon_encoder = to_radeon_encoder(encoder);
26063f03ced8SAlex Deucher 		if (radeon_encoder->encoder_enum == encoder_enum) {
26073f03ced8SAlex Deucher 			radeon_encoder->devices |= supported_device;
26083f03ced8SAlex Deucher 			return;
26093f03ced8SAlex Deucher 		}
26103f03ced8SAlex Deucher 
26113f03ced8SAlex Deucher 	}
26123f03ced8SAlex Deucher 
26133f03ced8SAlex Deucher 	/* add a new one */
26143f03ced8SAlex Deucher 	radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
26153f03ced8SAlex Deucher 	if (!radeon_encoder)
26163f03ced8SAlex Deucher 		return;
26173f03ced8SAlex Deucher 
26183f03ced8SAlex Deucher 	encoder = &radeon_encoder->base;
26193f03ced8SAlex Deucher 	switch (rdev->num_crtc) {
26203f03ced8SAlex Deucher 	case 1:
26213f03ced8SAlex Deucher 		encoder->possible_crtcs = 0x1;
26223f03ced8SAlex Deucher 		break;
26233f03ced8SAlex Deucher 	case 2:
26243f03ced8SAlex Deucher 	default:
26253f03ced8SAlex Deucher 		encoder->possible_crtcs = 0x3;
26263f03ced8SAlex Deucher 		break;
26273f03ced8SAlex Deucher 	case 4:
26283f03ced8SAlex Deucher 		encoder->possible_crtcs = 0xf;
26293f03ced8SAlex Deucher 		break;
26303f03ced8SAlex Deucher 	case 6:
26313f03ced8SAlex Deucher 		encoder->possible_crtcs = 0x3f;
26323f03ced8SAlex Deucher 		break;
26333f03ced8SAlex Deucher 	}
26343f03ced8SAlex Deucher 
26353f03ced8SAlex Deucher 	radeon_encoder->enc_priv = NULL;
26363f03ced8SAlex Deucher 
26373f03ced8SAlex Deucher 	radeon_encoder->encoder_enum = encoder_enum;
26383f03ced8SAlex Deucher 	radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
26393f03ced8SAlex Deucher 	radeon_encoder->devices = supported_device;
26403f03ced8SAlex Deucher 	radeon_encoder->rmx_type = RMX_OFF;
26413f03ced8SAlex Deucher 	radeon_encoder->underscan_type = UNDERSCAN_OFF;
26423f03ced8SAlex Deucher 	radeon_encoder->is_ext_encoder = false;
26433f03ced8SAlex Deucher 	radeon_encoder->caps = caps;
26443f03ced8SAlex Deucher 
26453f03ced8SAlex Deucher 	switch (radeon_encoder->encoder_id) {
26463f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
26473f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
26483f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
26493f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
26503f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
26513f03ced8SAlex Deucher 			radeon_encoder->rmx_type = RMX_FULL;
26523f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
26533f03ced8SAlex Deucher 			radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
26543f03ced8SAlex Deucher 		} else {
26553f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
26563f03ced8SAlex Deucher 			radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
26573f03ced8SAlex Deucher 		}
26583f03ced8SAlex Deucher 		drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
26593f03ced8SAlex Deucher 		break;
26603f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
26613f03ced8SAlex Deucher 		drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
26623f03ced8SAlex Deucher 		radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
26633f03ced8SAlex Deucher 		drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
26643f03ced8SAlex Deucher 		break;
26653f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
26663f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
26673f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
26683f03ced8SAlex Deucher 		drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC);
26693f03ced8SAlex Deucher 		radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
26703f03ced8SAlex Deucher 		drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
26713f03ced8SAlex Deucher 		break;
26723f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DVO1:
26733f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
26743f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_DDI:
26753f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
26763f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
26773f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
26783f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2679e68adef8SAlex Deucher 	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
26803f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
26813f03ced8SAlex Deucher 			radeon_encoder->rmx_type = RMX_FULL;
26823f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
26833f03ced8SAlex Deucher 			radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
26843f03ced8SAlex Deucher 		} else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
26853f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
26863f03ced8SAlex Deucher 			radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
26873f03ced8SAlex Deucher 		} else {
26883f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
26893f03ced8SAlex Deucher 			radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
26903f03ced8SAlex Deucher 		}
26913f03ced8SAlex Deucher 		drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
26923f03ced8SAlex Deucher 		break;
26933f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_SI170B:
26943f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_CH7303:
26953f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
26963f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
26973f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_TITFP513:
26983f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_VT1623:
26993f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_HDMI_SI1930:
27003f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_TRAVIS:
27013f03ced8SAlex Deucher 	case ENCODER_OBJECT_ID_NUTMEG:
27023f03ced8SAlex Deucher 		/* these are handled by the primary encoders */
27033f03ced8SAlex Deucher 		radeon_encoder->is_ext_encoder = true;
27043f03ced8SAlex Deucher 		if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
27053f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
27063f03ced8SAlex Deucher 		else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
27073f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
27083f03ced8SAlex Deucher 		else
27093f03ced8SAlex Deucher 			drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
27103f03ced8SAlex Deucher 		drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
27113f03ced8SAlex Deucher 		break;
27123f03ced8SAlex Deucher 	}
27133f03ced8SAlex Deucher }
2714