blob: 266036b10fec81f90cc8708f0394878e1b919d8b [file] [log] [blame]
Alex Deucher3f03ced2011-10-30 17:20:22 -04001/*
2 * Copyright 2007-11 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: Dave Airlie
24 * Alex Deucher
25 */
26#include "drmP.h"
27#include "drm_crtc_helper.h"
28#include "radeon_drm.h"
29#include "radeon.h"
30#include "atom.h"
Alex Deucherf3728732012-07-26 11:32:03 -040031#include <linux/backlight.h>
Alex Deucher3f03ced2011-10-30 17:20:22 -040032
33extern int atom_debug;
34
Alex Deucherf3728732012-07-26 11:32:03 -040035#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
36
37static u8
38radeon_atom_get_backlight_level_from_reg(struct radeon_device *rdev)
39{
40 u8 backlight_level;
41 u32 bios_2_scratch;
42
43 if (rdev->family >= CHIP_R600)
44 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
45 else
46 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
47
48 backlight_level = ((bios_2_scratch & ATOM_S2_CURRENT_BL_LEVEL_MASK) >>
49 ATOM_S2_CURRENT_BL_LEVEL_SHIFT);
50
51 return backlight_level;
52}
53
54static void
55radeon_atom_set_backlight_level_to_reg(struct radeon_device *rdev,
56 u8 backlight_level)
57{
58 u32 bios_2_scratch;
59
60 if (rdev->family >= CHIP_R600)
61 bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
62 else
63 bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
64
65 bios_2_scratch &= ~ATOM_S2_CURRENT_BL_LEVEL_MASK;
66 bios_2_scratch |= ((backlight_level << ATOM_S2_CURRENT_BL_LEVEL_SHIFT) &
67 ATOM_S2_CURRENT_BL_LEVEL_MASK);
68
69 if (rdev->family >= CHIP_R600)
70 WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
71 else
72 WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
73}
74
Luca Tettamantifda4b252012-07-30 21:20:35 +020075void
Alex Deucher37e9b6a2012-08-03 11:39:43 -040076atombios_set_backlight_level(struct radeon_encoder *radeon_encoder, u8 level)
Alex Deucherf3728732012-07-26 11:32:03 -040077{
78 struct drm_encoder *encoder = &radeon_encoder->base;
79 struct drm_device *dev = radeon_encoder->base.dev;
80 struct radeon_device *rdev = dev->dev_private;
81 struct radeon_encoder_atom_dig *dig;
82 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
83 int index;
84
Alex Deucher37e9b6a2012-08-03 11:39:43 -040085 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
86 return;
87
88 if ((radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
89 radeon_encoder->enc_priv) {
Alex Deucherf3728732012-07-26 11:32:03 -040090 dig = radeon_encoder->enc_priv;
Alex Deucher37e9b6a2012-08-03 11:39:43 -040091 dig->backlight_level = level;
Alex Deucherf3728732012-07-26 11:32:03 -040092 radeon_atom_set_backlight_level_to_reg(rdev, dig->backlight_level);
93
94 switch (radeon_encoder->encoder_id) {
95 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
96 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
97 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
98 if (dig->backlight_level == 0) {
99 args.ucAction = ATOM_LCD_BLOFF;
100 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
101 } else {
102 args.ucAction = ATOM_LCD_BL_BRIGHTNESS_CONTROL;
103 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
104 args.ucAction = ATOM_LCD_BLON;
105 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
106 }
107 break;
108 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
109 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
110 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
111 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
112 if (dig->backlight_level == 0)
113 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
114 else {
115 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_BL_BRIGHTNESS_CONTROL, 0, 0);
116 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
117 }
118 break;
119 default:
120 break;
121 }
122 }
123}
124
125static u8 radeon_atom_bl_level(struct backlight_device *bd)
126{
127 u8 level;
128
129 /* Convert brightness to hardware level */
130 if (bd->props.brightness < 0)
131 level = 0;
132 else if (bd->props.brightness > RADEON_MAX_BL_LEVEL)
133 level = RADEON_MAX_BL_LEVEL;
134 else
135 level = bd->props.brightness;
136
137 return level;
138}
139
140static int radeon_atom_backlight_update_status(struct backlight_device *bd)
141{
142 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
143 struct radeon_encoder *radeon_encoder = pdata->encoder;
144
Alex Deucher37e9b6a2012-08-03 11:39:43 -0400145 atombios_set_backlight_level(radeon_encoder, radeon_atom_bl_level(bd));
Alex Deucherf3728732012-07-26 11:32:03 -0400146
147 return 0;
148}
149
150static int radeon_atom_backlight_get_brightness(struct backlight_device *bd)
151{
152 struct radeon_backlight_privdata *pdata = bl_get_data(bd);
153 struct radeon_encoder *radeon_encoder = pdata->encoder;
154 struct drm_device *dev = radeon_encoder->base.dev;
155 struct radeon_device *rdev = dev->dev_private;
156
157 return radeon_atom_get_backlight_level_from_reg(rdev);
158}
159
160static const struct backlight_ops radeon_atom_backlight_ops = {
161 .get_brightness = radeon_atom_backlight_get_brightness,
162 .update_status = radeon_atom_backlight_update_status,
163};
164
165void radeon_atom_backlight_init(struct radeon_encoder *radeon_encoder,
166 struct drm_connector *drm_connector)
167{
168 struct drm_device *dev = radeon_encoder->base.dev;
169 struct radeon_device *rdev = dev->dev_private;
170 struct backlight_device *bd;
171 struct backlight_properties props;
172 struct radeon_backlight_privdata *pdata;
173 struct radeon_encoder_atom_dig *dig;
174 u8 backlight_level;
175
176 if (!radeon_encoder->enc_priv)
177 return;
178
179 if (!rdev->is_atom_bios)
180 return;
181
182 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
183 return;
184
185 pdata = kmalloc(sizeof(struct radeon_backlight_privdata), GFP_KERNEL);
186 if (!pdata) {
187 DRM_ERROR("Memory allocation failed\n");
188 goto error;
189 }
190
191 memset(&props, 0, sizeof(props));
192 props.max_brightness = RADEON_MAX_BL_LEVEL;
193 props.type = BACKLIGHT_RAW;
194 bd = backlight_device_register("radeon_bl", &drm_connector->kdev,
195 pdata, &radeon_atom_backlight_ops, &props);
196 if (IS_ERR(bd)) {
197 DRM_ERROR("Backlight registration failed\n");
198 goto error;
199 }
200
201 pdata->encoder = radeon_encoder;
202
203 backlight_level = radeon_atom_get_backlight_level_from_reg(rdev);
204
205 dig = radeon_encoder->enc_priv;
206 dig->bl_dev = bd;
207
208 bd->props.brightness = radeon_atom_backlight_get_brightness(bd);
209 bd->props.power = FB_BLANK_UNBLANK;
210 backlight_update_status(bd);
211
212 DRM_INFO("radeon atom DIG backlight initialized\n");
213
214 return;
215
216error:
217 kfree(pdata);
218 return;
219}
220
221static void radeon_atom_backlight_exit(struct radeon_encoder *radeon_encoder)
222{
223 struct drm_device *dev = radeon_encoder->base.dev;
224 struct radeon_device *rdev = dev->dev_private;
225 struct backlight_device *bd = NULL;
226 struct radeon_encoder_atom_dig *dig;
227
228 if (!radeon_encoder->enc_priv)
229 return;
230
231 if (!rdev->is_atom_bios)
232 return;
233
234 if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU))
235 return;
236
237 dig = radeon_encoder->enc_priv;
238 bd = dig->bl_dev;
239 dig->bl_dev = NULL;
240
241 if (bd) {
242 struct radeon_legacy_backlight_privdata *pdata;
243
244 pdata = bl_get_data(bd);
245 backlight_device_unregister(bd);
246 kfree(pdata);
247
248 DRM_INFO("radeon atom LVDS backlight unloaded\n");
249 }
250}
251
252#else /* !CONFIG_BACKLIGHT_CLASS_DEVICE */
253
254void radeon_atom_backlight_init(struct radeon_encoder *encoder)
255{
256}
257
258static void radeon_atom_backlight_exit(struct radeon_encoder *encoder)
259{
260}
261
262#endif
263
Alex Deucher3f03ced2011-10-30 17:20:22 -0400264/* evil but including atombios.h is much worse */
265bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
266 struct drm_display_mode *mode);
267
268
269static inline bool radeon_encoder_is_digital(struct drm_encoder *encoder)
270{
271 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
272 switch (radeon_encoder->encoder_id) {
273 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
274 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
275 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
276 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
277 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
278 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
279 case ENCODER_OBJECT_ID_INTERNAL_DDI:
280 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
281 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
282 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
283 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
284 return true;
285 default:
286 return false;
287 }
288}
289
Alex Deucher3f03ced2011-10-30 17:20:22 -0400290static bool radeon_atom_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +0200291 const struct drm_display_mode *mode,
Alex Deucher3f03ced2011-10-30 17:20:22 -0400292 struct drm_display_mode *adjusted_mode)
293{
294 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
295 struct drm_device *dev = encoder->dev;
296 struct radeon_device *rdev = dev->dev_private;
297
298 /* set the active encoder to connector routing */
299 radeon_encoder_set_active_device(encoder);
300 drm_mode_set_crtcinfo(adjusted_mode, 0);
301
302 /* hw bug */
303 if ((mode->flags & DRM_MODE_FLAG_INTERLACE)
304 && (mode->crtc_vsync_start < (mode->crtc_vdisplay + 2)))
305 adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vdisplay + 2;
306
307 /* get the native mode for LVDS */
308 if (radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT))
309 radeon_panel_mode_fixup(encoder, adjusted_mode);
310
311 /* get the native mode for TV */
312 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)) {
313 struct radeon_encoder_atom_dac *tv_dac = radeon_encoder->enc_priv;
314 if (tv_dac) {
315 if (tv_dac->tv_std == TV_STD_NTSC ||
316 tv_dac->tv_std == TV_STD_NTSC_J ||
317 tv_dac->tv_std == TV_STD_PAL_M)
318 radeon_atom_get_tv_timings(rdev, 0, adjusted_mode);
319 else
320 radeon_atom_get_tv_timings(rdev, 1, adjusted_mode);
321 }
322 }
323
324 if (ASIC_IS_DCE3(rdev) &&
325 ((radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
326 (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE))) {
327 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
328 radeon_dp_set_link_config(connector, mode);
329 }
330
331 return true;
332}
333
334static void
335atombios_dac_setup(struct drm_encoder *encoder, int action)
336{
337 struct drm_device *dev = encoder->dev;
338 struct radeon_device *rdev = dev->dev_private;
339 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
340 DAC_ENCODER_CONTROL_PS_ALLOCATION args;
341 int index = 0;
342 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
343
344 memset(&args, 0, sizeof(args));
345
346 switch (radeon_encoder->encoder_id) {
347 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
348 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
349 index = GetIndexIntoMasterTable(COMMAND, DAC1EncoderControl);
350 break;
351 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
352 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
353 index = GetIndexIntoMasterTable(COMMAND, DAC2EncoderControl);
354 break;
355 }
356
357 args.ucAction = action;
358
359 if (radeon_encoder->active_device & (ATOM_DEVICE_CRT_SUPPORT))
360 args.ucDacStandard = ATOM_DAC1_PS2;
361 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
362 args.ucDacStandard = ATOM_DAC1_CV;
363 else {
364 switch (dac_info->tv_std) {
365 case TV_STD_PAL:
366 case TV_STD_PAL_M:
367 case TV_STD_SCART_PAL:
368 case TV_STD_SECAM:
369 case TV_STD_PAL_CN:
370 args.ucDacStandard = ATOM_DAC1_PAL;
371 break;
372 case TV_STD_NTSC:
373 case TV_STD_NTSC_J:
374 case TV_STD_PAL_60:
375 default:
376 args.ucDacStandard = ATOM_DAC1_NTSC;
377 break;
378 }
379 }
380 args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
381
382 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
383
384}
385
386static void
387atombios_tv_setup(struct drm_encoder *encoder, int action)
388{
389 struct drm_device *dev = encoder->dev;
390 struct radeon_device *rdev = dev->dev_private;
391 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
392 TV_ENCODER_CONTROL_PS_ALLOCATION args;
393 int index = 0;
394 struct radeon_encoder_atom_dac *dac_info = radeon_encoder->enc_priv;
395
396 memset(&args, 0, sizeof(args));
397
398 index = GetIndexIntoMasterTable(COMMAND, TVEncoderControl);
399
400 args.sTVEncoder.ucAction = action;
401
402 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
403 args.sTVEncoder.ucTvStandard = ATOM_TV_CV;
404 else {
405 switch (dac_info->tv_std) {
406 case TV_STD_NTSC:
407 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
408 break;
409 case TV_STD_PAL:
410 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL;
411 break;
412 case TV_STD_PAL_M:
413 args.sTVEncoder.ucTvStandard = ATOM_TV_PALM;
414 break;
415 case TV_STD_PAL_60:
416 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL60;
417 break;
418 case TV_STD_NTSC_J:
419 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSCJ;
420 break;
421 case TV_STD_SCART_PAL:
422 args.sTVEncoder.ucTvStandard = ATOM_TV_PAL; /* ??? */
423 break;
424 case TV_STD_SECAM:
425 args.sTVEncoder.ucTvStandard = ATOM_TV_SECAM;
426 break;
427 case TV_STD_PAL_CN:
428 args.sTVEncoder.ucTvStandard = ATOM_TV_PALCN;
429 break;
430 default:
431 args.sTVEncoder.ucTvStandard = ATOM_TV_NTSC;
432 break;
433 }
434 }
435
436 args.sTVEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
437
438 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
439
440}
441
Alex Deucher1f0e2942012-08-17 10:31:34 -0400442static u8 radeon_atom_get_bpc(struct drm_encoder *encoder)
443{
444 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
445 int bpc = 8;
446
447 if (connector)
448 bpc = radeon_get_monitor_bpc(connector);
449
450 switch (bpc) {
451 case 0:
452 return PANEL_BPC_UNDEFINE;
453 case 6:
454 return PANEL_6BIT_PER_COLOR;
455 case 8:
456 default:
457 return PANEL_8BIT_PER_COLOR;
458 case 10:
459 return PANEL_10BIT_PER_COLOR;
460 case 12:
461 return PANEL_12BIT_PER_COLOR;
462 case 16:
463 return PANEL_16BIT_PER_COLOR;
464 }
465}
466
467
Alex Deucher3f03ced2011-10-30 17:20:22 -0400468union dvo_encoder_control {
469 ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ext_tmds;
470 DVO_ENCODER_CONTROL_PS_ALLOCATION dvo;
471 DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 dvo_v3;
472};
473
474void
475atombios_dvo_setup(struct drm_encoder *encoder, int action)
476{
477 struct drm_device *dev = encoder->dev;
478 struct radeon_device *rdev = dev->dev_private;
479 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
480 union dvo_encoder_control args;
481 int index = GetIndexIntoMasterTable(COMMAND, DVOEncoderControl);
Alex Deucher24153dd2011-10-28 18:18:50 -0400482 uint8_t frev, crev;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400483
484 memset(&args, 0, sizeof(args));
485
Alex Deucher24153dd2011-10-28 18:18:50 -0400486 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
487 return;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400488
Alex Deucherafceb932012-04-03 17:05:41 -0400489 /* some R4xx chips have the wrong frev */
490 if (rdev->family <= CHIP_RV410)
491 frev = 1;
492
Alex Deucher24153dd2011-10-28 18:18:50 -0400493 switch (frev) {
494 case 1:
495 switch (crev) {
496 case 1:
497 /* R4xx, R5xx */
498 args.ext_tmds.sXTmdsEncoder.ucEnable = action;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400499
Alex Deucher9aa59992012-01-20 15:03:30 -0500500 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher24153dd2011-10-28 18:18:50 -0400501 args.ext_tmds.sXTmdsEncoder.ucMisc |= PANEL_ENCODER_MISC_DUAL;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400502
Alex Deucher24153dd2011-10-28 18:18:50 -0400503 args.ext_tmds.sXTmdsEncoder.ucMisc |= ATOM_PANEL_MISC_888RGB;
504 break;
505 case 2:
506 /* RS600/690/740 */
507 args.dvo.sDVOEncoder.ucAction = action;
508 args.dvo.sDVOEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
509 /* DFP1, CRT1, TV1 depending on the type of port */
510 args.dvo.sDVOEncoder.ucDeviceType = ATOM_DEVICE_DFP1_INDEX;
511
Alex Deucher9aa59992012-01-20 15:03:30 -0500512 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher24153dd2011-10-28 18:18:50 -0400513 args.dvo.sDVOEncoder.usDevAttr.sDigAttrib.ucAttribute |= PANEL_ENCODER_MISC_DUAL;
514 break;
515 case 3:
516 /* R6xx */
517 args.dvo_v3.ucAction = action;
518 args.dvo_v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
519 args.dvo_v3.ucDVOConfig = 0; /* XXX */
520 break;
521 default:
522 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
523 break;
524 }
525 break;
526 default:
527 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
528 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400529 }
530
531 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
532}
533
534union lvds_encoder_control {
535 LVDS_ENCODER_CONTROL_PS_ALLOCATION v1;
536 LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 v2;
537};
538
539void
540atombios_digital_setup(struct drm_encoder *encoder, int action)
541{
542 struct drm_device *dev = encoder->dev;
543 struct radeon_device *rdev = dev->dev_private;
544 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
545 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
546 union lvds_encoder_control args;
547 int index = 0;
548 int hdmi_detected = 0;
549 uint8_t frev, crev;
550
551 if (!dig)
552 return;
553
554 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
555 hdmi_detected = 1;
556
557 memset(&args, 0, sizeof(args));
558
559 switch (radeon_encoder->encoder_id) {
560 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
561 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
562 break;
563 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
564 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
565 index = GetIndexIntoMasterTable(COMMAND, TMDS1EncoderControl);
566 break;
567 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
568 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
569 index = GetIndexIntoMasterTable(COMMAND, LVDSEncoderControl);
570 else
571 index = GetIndexIntoMasterTable(COMMAND, TMDS2EncoderControl);
572 break;
573 }
574
575 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
576 return;
577
578 switch (frev) {
579 case 1:
580 case 2:
581 switch (crev) {
582 case 1:
583 args.v1.ucMisc = 0;
584 args.v1.ucAction = action;
585 if (hdmi_detected)
586 args.v1.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
587 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
588 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
589 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
590 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
591 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
592 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
593 } else {
594 if (dig->linkb)
595 args.v1.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
Alex Deucher9aa59992012-01-20 15:03:30 -0500596 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher3f03ced2011-10-30 17:20:22 -0400597 args.v1.ucMisc |= PANEL_ENCODER_MISC_DUAL;
598 /*if (pScrn->rgbBits == 8) */
599 args.v1.ucMisc |= ATOM_PANEL_MISC_888RGB;
600 }
601 break;
602 case 2:
603 case 3:
604 args.v2.ucMisc = 0;
605 args.v2.ucAction = action;
606 if (crev == 3) {
607 if (dig->coherent_mode)
608 args.v2.ucMisc |= PANEL_ENCODER_MISC_COHERENT;
609 }
610 if (hdmi_detected)
611 args.v2.ucMisc |= PANEL_ENCODER_MISC_HDMI_TYPE;
612 args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
613 args.v2.ucTruncate = 0;
614 args.v2.ucSpatial = 0;
615 args.v2.ucTemporal = 0;
616 args.v2.ucFRC = 0;
617 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
618 if (dig->lcd_misc & ATOM_PANEL_MISC_DUAL)
619 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
620 if (dig->lcd_misc & ATOM_PANEL_MISC_SPATIAL) {
621 args.v2.ucSpatial = PANEL_ENCODER_SPATIAL_DITHER_EN;
622 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
623 args.v2.ucSpatial |= PANEL_ENCODER_SPATIAL_DITHER_DEPTH;
624 }
625 if (dig->lcd_misc & ATOM_PANEL_MISC_TEMPORAL) {
626 args.v2.ucTemporal = PANEL_ENCODER_TEMPORAL_DITHER_EN;
627 if (dig->lcd_misc & ATOM_PANEL_MISC_888RGB)
628 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_DITHER_DEPTH;
629 if (((dig->lcd_misc >> ATOM_PANEL_MISC_GREY_LEVEL_SHIFT) & 0x3) == 2)
630 args.v2.ucTemporal |= PANEL_ENCODER_TEMPORAL_LEVEL_4;
631 }
632 } else {
633 if (dig->linkb)
634 args.v2.ucMisc |= PANEL_ENCODER_MISC_TMDS_LINKB;
Alex Deucher9aa59992012-01-20 15:03:30 -0500635 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher3f03ced2011-10-30 17:20:22 -0400636 args.v2.ucMisc |= PANEL_ENCODER_MISC_DUAL;
637 }
638 break;
639 default:
640 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
641 break;
642 }
643 break;
644 default:
645 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
646 break;
647 }
648
649 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
650}
651
652int
653atombios_get_encoder_mode(struct drm_encoder *encoder)
654{
655 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -0400656 struct drm_connector *connector;
657 struct radeon_connector *radeon_connector;
658 struct radeon_connector_atom_dig *dig_connector;
659
660 /* dp bridges are always DP */
661 if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE)
662 return ATOM_ENCODER_MODE_DP;
663
664 /* DVO is always DVO */
Alex Deuchera59fbb82012-09-13 12:01:48 -0400665 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DVO1) ||
666 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1))
Alex Deucher3f03ced2011-10-30 17:20:22 -0400667 return ATOM_ENCODER_MODE_DVO;
668
669 connector = radeon_get_connector_for_encoder(encoder);
670 /* if we don't have an active device yet, just use one of
671 * the connectors tied to the encoder.
672 */
673 if (!connector)
674 connector = radeon_get_connector_for_encoder_init(encoder);
675 radeon_connector = to_radeon_connector(connector);
676
677 switch (connector->connector_type) {
678 case DRM_MODE_CONNECTOR_DVII:
679 case DRM_MODE_CONNECTOR_HDMIB: /* HDMI-B is basically DL-DVI; analog works fine */
Alex Deucher27d9cc82012-01-20 15:03:29 -0500680 if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
Rafał Miłeckif92e70c2011-12-08 00:02:34 +0100681 radeon_audio)
682 return ATOM_ENCODER_MODE_HDMI;
683 else if (radeon_connector->use_digital)
Alex Deucher3f03ced2011-10-30 17:20:22 -0400684 return ATOM_ENCODER_MODE_DVI;
685 else
686 return ATOM_ENCODER_MODE_CRT;
687 break;
688 case DRM_MODE_CONNECTOR_DVID:
689 case DRM_MODE_CONNECTOR_HDMIA:
690 default:
Alex Deucher27d9cc82012-01-20 15:03:29 -0500691 if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
Rafał Miłeckif92e70c2011-12-08 00:02:34 +0100692 radeon_audio)
693 return ATOM_ENCODER_MODE_HDMI;
694 else
Alex Deucher3f03ced2011-10-30 17:20:22 -0400695 return ATOM_ENCODER_MODE_DVI;
696 break;
697 case DRM_MODE_CONNECTOR_LVDS:
698 return ATOM_ENCODER_MODE_LVDS;
699 break;
700 case DRM_MODE_CONNECTOR_DisplayPort:
701 dig_connector = radeon_connector->con_priv;
702 if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) ||
703 (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP))
704 return ATOM_ENCODER_MODE_DP;
Alex Deucher27d9cc82012-01-20 15:03:29 -0500705 else if (drm_detect_hdmi_monitor(radeon_connector->edid) &&
Rafał Miłeckif92e70c2011-12-08 00:02:34 +0100706 radeon_audio)
707 return ATOM_ENCODER_MODE_HDMI;
708 else
Alex Deucher3f03ced2011-10-30 17:20:22 -0400709 return ATOM_ENCODER_MODE_DVI;
710 break;
711 case DRM_MODE_CONNECTOR_eDP:
712 return ATOM_ENCODER_MODE_DP;
713 case DRM_MODE_CONNECTOR_DVIA:
714 case DRM_MODE_CONNECTOR_VGA:
715 return ATOM_ENCODER_MODE_CRT;
716 break;
717 case DRM_MODE_CONNECTOR_Composite:
718 case DRM_MODE_CONNECTOR_SVIDEO:
719 case DRM_MODE_CONNECTOR_9PinDIN:
720 /* fix me */
721 return ATOM_ENCODER_MODE_TV;
722 /*return ATOM_ENCODER_MODE_CV;*/
723 break;
724 }
725}
726
727/*
728 * DIG Encoder/Transmitter Setup
729 *
730 * DCE 3.0/3.1
731 * - 2 DIG transmitter blocks. UNIPHY (links A and B) and LVTMA.
732 * Supports up to 3 digital outputs
733 * - 2 DIG encoder blocks.
734 * DIG1 can drive UNIPHY link A or link B
735 * DIG2 can drive UNIPHY link B or LVTMA
736 *
737 * DCE 3.2
738 * - 3 DIG transmitter blocks. UNIPHY0/1/2 (links A and B).
739 * Supports up to 5 digital outputs
740 * - 2 DIG encoder blocks.
741 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
742 *
Alex Deucher2d415862012-03-20 17:18:07 -0400743 * DCE 4.0/5.0/6.0
Alex Deucher3f03ced2011-10-30 17:20:22 -0400744 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
745 * Supports up to 6 digital outputs
746 * - 6 DIG encoder blocks.
747 * - DIG to PHY mapping is hardcoded
748 * DIG1 drives UNIPHY0 link A, A+B
749 * DIG2 drives UNIPHY0 link B
750 * DIG3 drives UNIPHY1 link A, A+B
751 * DIG4 drives UNIPHY1 link B
752 * DIG5 drives UNIPHY2 link A, A+B
753 * DIG6 drives UNIPHY2 link B
754 *
755 * DCE 4.1
756 * - 3 DIG transmitter blocks UNIPHY0/1/2 (links A and B).
757 * Supports up to 6 digital outputs
758 * - 2 DIG encoder blocks.
Alex Deucher2d415862012-03-20 17:18:07 -0400759 * llano
Alex Deucher3f03ced2011-10-30 17:20:22 -0400760 * DIG1/2 can drive UNIPHY0/1/2 link A or link B
Alex Deucher2d415862012-03-20 17:18:07 -0400761 * ontario
762 * DIG1 drives UNIPHY0/1/2 link A
763 * DIG2 drives UNIPHY0/1/2 link B
Alex Deucher3f03ced2011-10-30 17:20:22 -0400764 *
765 * Routing
766 * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links)
767 * Examples:
768 * crtc0 -> dig2 -> LVTMA links A+B -> TMDS/HDMI
769 * crtc1 -> dig1 -> UNIPHY0 link B -> DP
770 * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS
771 * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI
772 */
773
774union dig_encoder_control {
775 DIG_ENCODER_CONTROL_PS_ALLOCATION v1;
776 DIG_ENCODER_CONTROL_PARAMETERS_V2 v2;
777 DIG_ENCODER_CONTROL_PARAMETERS_V3 v3;
778 DIG_ENCODER_CONTROL_PARAMETERS_V4 v4;
779};
780
781void
782atombios_dig_encoder_setup(struct drm_encoder *encoder, int action, int panel_mode)
783{
784 struct drm_device *dev = encoder->dev;
785 struct radeon_device *rdev = dev->dev_private;
786 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
787 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
788 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
789 union dig_encoder_control args;
790 int index = 0;
791 uint8_t frev, crev;
792 int dp_clock = 0;
793 int dp_lane_count = 0;
794 int hpd_id = RADEON_HPD_NONE;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400795
796 if (connector) {
797 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
798 struct radeon_connector_atom_dig *dig_connector =
799 radeon_connector->con_priv;
800
801 dp_clock = dig_connector->dp_clock;
802 dp_lane_count = dig_connector->dp_lane_count;
803 hpd_id = radeon_connector->hpd.hpd;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400804 }
805
806 /* no dig encoder assigned */
807 if (dig->dig_encoder == -1)
808 return;
809
810 memset(&args, 0, sizeof(args));
811
812 if (ASIC_IS_DCE4(rdev))
813 index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl);
814 else {
815 if (dig->dig_encoder)
816 index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl);
817 else
818 index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl);
819 }
820
821 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
822 return;
823
Alex Deucher58cdcb82011-10-28 18:34:20 -0400824 switch (frev) {
825 case 1:
826 switch (crev) {
827 case 1:
828 args.v1.ucAction = action;
829 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
830 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
831 args.v3.ucPanelMode = panel_mode;
832 else
833 args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -0400834
Alex Deucher58cdcb82011-10-28 18:34:20 -0400835 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode))
836 args.v1.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -0500837 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400838 args.v1.ucLaneNum = 8;
839 else
840 args.v1.ucLaneNum = 4;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400841
Alex Deucher58cdcb82011-10-28 18:34:20 -0400842 if (ENCODER_MODE_IS_DP(args.v1.ucEncoderMode) && (dp_clock == 270000))
843 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
844 switch (radeon_encoder->encoder_id) {
845 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
846 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1;
847 break;
848 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
849 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
850 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2;
851 break;
852 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
853 args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3;
854 break;
855 }
856 if (dig->linkb)
857 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB;
858 else
859 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400860 break;
Alex Deucher58cdcb82011-10-28 18:34:20 -0400861 case 2:
862 case 3:
863 args.v3.ucAction = action;
864 args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
865 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
866 args.v3.ucPanelMode = panel_mode;
867 else
868 args.v3.ucEncoderMode = atombios_get_encoder_mode(encoder);
869
Alex Deucher2f6fa792012-09-06 12:26:09 -0400870 if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400871 args.v3.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -0500872 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400873 args.v3.ucLaneNum = 8;
874 else
875 args.v3.ucLaneNum = 4;
876
Alex Deucher2f6fa792012-09-06 12:26:09 -0400877 if (ENCODER_MODE_IS_DP(args.v3.ucEncoderMode) && (dp_clock == 270000))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400878 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
879 args.v3.acConfig.ucDigSel = dig->dig_encoder;
Alex Deucher1f0e2942012-08-17 10:31:34 -0400880 args.v3.ucBitPerColor = radeon_atom_get_bpc(encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -0400881 break;
Alex Deucher58cdcb82011-10-28 18:34:20 -0400882 case 4:
883 args.v4.ucAction = action;
884 args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
885 if (action == ATOM_ENCODER_CMD_SETUP_PANEL_MODE)
886 args.v4.ucPanelMode = panel_mode;
887 else
888 args.v4.ucEncoderMode = atombios_get_encoder_mode(encoder);
889
Alex Deucher2f6fa792012-09-06 12:26:09 -0400890 if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400891 args.v4.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -0500892 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher58cdcb82011-10-28 18:34:20 -0400893 args.v4.ucLaneNum = 8;
894 else
895 args.v4.ucLaneNum = 4;
896
Alex Deucher2f6fa792012-09-06 12:26:09 -0400897 if (ENCODER_MODE_IS_DP(args.v4.ucEncoderMode)) {
Alex Deucher58cdcb82011-10-28 18:34:20 -0400898 if (dp_clock == 270000)
899 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_2_70GHZ;
900 else if (dp_clock == 540000)
901 args.v1.ucConfig |= ATOM_ENCODER_CONFIG_V4_DPLINKRATE_5_40GHZ;
902 }
903 args.v4.acConfig.ucDigSel = dig->dig_encoder;
Alex Deucher1f0e2942012-08-17 10:31:34 -0400904 args.v4.ucBitPerColor = radeon_atom_get_bpc(encoder);
Alex Deucher58cdcb82011-10-28 18:34:20 -0400905 if (hpd_id == RADEON_HPD_NONE)
906 args.v4.ucHPD_ID = 0;
907 else
908 args.v4.ucHPD_ID = hpd_id + 1;
909 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400910 default:
Alex Deucher58cdcb82011-10-28 18:34:20 -0400911 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
Alex Deucher3f03ced2011-10-30 17:20:22 -0400912 break;
913 }
Alex Deucher58cdcb82011-10-28 18:34:20 -0400914 break;
915 default:
916 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
917 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400918 }
919
920 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
921
922}
923
924union dig_transmitter_control {
925 DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1;
926 DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2;
927 DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3;
928 DIG_TRANSMITTER_CONTROL_PARAMETERS_V4 v4;
Alex Deucher47aef7a2012-03-20 17:18:05 -0400929 DIG_TRANSMITTER_CONTROL_PARAMETERS_V1_5 v5;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400930};
931
932void
933atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t lane_num, uint8_t lane_set)
934{
935 struct drm_device *dev = encoder->dev;
936 struct radeon_device *rdev = dev->dev_private;
937 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
938 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
939 struct drm_connector *connector;
940 union dig_transmitter_control args;
941 int index = 0;
942 uint8_t frev, crev;
943 bool is_dp = false;
944 int pll_id = 0;
945 int dp_clock = 0;
946 int dp_lane_count = 0;
947 int connector_object_id = 0;
948 int igp_lane_info = 0;
949 int dig_encoder = dig->dig_encoder;
Alex Deucher47aef7a2012-03-20 17:18:05 -0400950 int hpd_id = RADEON_HPD_NONE;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400951
952 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
953 connector = radeon_get_connector_for_encoder_init(encoder);
954 /* just needed to avoid bailing in the encoder check. the encoder
955 * isn't used for init
956 */
957 dig_encoder = 0;
958 } else
959 connector = radeon_get_connector_for_encoder(encoder);
960
961 if (connector) {
962 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
963 struct radeon_connector_atom_dig *dig_connector =
964 radeon_connector->con_priv;
965
Alex Deucher47aef7a2012-03-20 17:18:05 -0400966 hpd_id = radeon_connector->hpd.hpd;
Alex Deucher3f03ced2011-10-30 17:20:22 -0400967 dp_clock = dig_connector->dp_clock;
968 dp_lane_count = dig_connector->dp_lane_count;
969 connector_object_id =
970 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
971 igp_lane_info = dig_connector->igp_lane_info;
972 }
973
Alex Deuchera3b08292011-10-28 18:46:37 -0400974 if (encoder->crtc) {
975 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
976 pll_id = radeon_crtc->pll_id;
977 }
978
Alex Deucher3f03ced2011-10-30 17:20:22 -0400979 /* no dig encoder assigned */
980 if (dig_encoder == -1)
981 return;
982
983 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)))
984 is_dp = true;
985
986 memset(&args, 0, sizeof(args));
987
988 switch (radeon_encoder->encoder_id) {
989 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
990 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
991 break;
992 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
993 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
994 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
995 index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
996 break;
997 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
998 index = GetIndexIntoMasterTable(COMMAND, LVTMATransmitterControl);
999 break;
1000 }
1001
1002 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1003 return;
1004
Alex Deuchera3b08292011-10-28 18:46:37 -04001005 switch (frev) {
1006 case 1:
1007 switch (crev) {
1008 case 1:
1009 args.v1.ucAction = action;
1010 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1011 args.v1.usInitInfo = cpu_to_le16(connector_object_id);
1012 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1013 args.v1.asMode.ucLaneSel = lane_num;
1014 args.v1.asMode.ucLaneSet = lane_set;
1015 } else {
1016 if (is_dp)
Alex Deucher6e76a2d2012-09-06 12:30:37 -04001017 args.v1.usPixelClock = cpu_to_le16(dp_clock / 10);
Alex Deucher9aa59992012-01-20 15:03:30 -05001018 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001019 args.v1.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1020 else
1021 args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1022 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001023
Alex Deuchera3b08292011-10-28 18:46:37 -04001024 args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001025
Alex Deuchera3b08292011-10-28 18:46:37 -04001026 if (dig_encoder)
1027 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER;
1028 else
1029 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001030
Alex Deuchera3b08292011-10-28 18:46:37 -04001031 if ((rdev->flags & RADEON_IS_IGP) &&
1032 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) {
Alex Deucher9aa59992012-01-20 15:03:30 -05001033 if (is_dp ||
1034 !radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock)) {
Alex Deuchera3b08292011-10-28 18:46:37 -04001035 if (igp_lane_info & 0x1)
1036 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3;
1037 else if (igp_lane_info & 0x2)
1038 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7;
1039 else if (igp_lane_info & 0x4)
1040 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11;
1041 else if (igp_lane_info & 0x8)
1042 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15;
1043 } else {
1044 if (igp_lane_info & 0x3)
1045 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7;
1046 else if (igp_lane_info & 0xc)
1047 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15;
1048 }
1049 }
1050
1051 if (dig->linkb)
1052 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB;
1053 else
1054 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKA;
1055
1056 if (is_dp)
1057 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
1058 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1059 if (dig->coherent_mode)
1060 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT;
Alex Deucher9aa59992012-01-20 15:03:30 -05001061 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001062 args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK;
1063 }
1064 break;
1065 case 2:
1066 args.v2.ucAction = action;
1067 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1068 args.v2.usInitInfo = cpu_to_le16(connector_object_id);
1069 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1070 args.v2.asMode.ucLaneSel = lane_num;
1071 args.v2.asMode.ucLaneSet = lane_set;
1072 } else {
1073 if (is_dp)
Alex Deucher6e76a2d2012-09-06 12:30:37 -04001074 args.v2.usPixelClock = cpu_to_le16(dp_clock / 10);
Alex Deucher9aa59992012-01-20 15:03:30 -05001075 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001076 args.v2.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1077 else
1078 args.v2.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1079 }
1080
1081 args.v2.acConfig.ucEncoderSel = dig_encoder;
1082 if (dig->linkb)
1083 args.v2.acConfig.ucLinkSel = 1;
1084
1085 switch (radeon_encoder->encoder_id) {
1086 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1087 args.v2.acConfig.ucTransmitterSel = 0;
1088 break;
1089 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1090 args.v2.acConfig.ucTransmitterSel = 1;
1091 break;
1092 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1093 args.v2.acConfig.ucTransmitterSel = 2;
1094 break;
1095 }
1096
1097 if (is_dp) {
1098 args.v2.acConfig.fCoherentMode = 1;
1099 args.v2.acConfig.fDPConnector = 1;
1100 } else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1101 if (dig->coherent_mode)
1102 args.v2.acConfig.fCoherentMode = 1;
Alex Deucher9aa59992012-01-20 15:03:30 -05001103 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001104 args.v2.acConfig.fDualLinkConnector = 1;
1105 }
1106 break;
1107 case 3:
1108 args.v3.ucAction = action;
1109 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1110 args.v3.usInitInfo = cpu_to_le16(connector_object_id);
1111 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1112 args.v3.asMode.ucLaneSel = lane_num;
1113 args.v3.asMode.ucLaneSet = lane_set;
1114 } else {
1115 if (is_dp)
Alex Deucher6e76a2d2012-09-06 12:30:37 -04001116 args.v3.usPixelClock = cpu_to_le16(dp_clock / 10);
Alex Deucher9aa59992012-01-20 15:03:30 -05001117 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001118 args.v3.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1119 else
1120 args.v3.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1121 }
1122
1123 if (is_dp)
1124 args.v3.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -05001125 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001126 args.v3.ucLaneNum = 8;
1127 else
1128 args.v3.ucLaneNum = 4;
1129
1130 if (dig->linkb)
1131 args.v3.acConfig.ucLinkSel = 1;
1132 if (dig_encoder & 1)
1133 args.v3.acConfig.ucEncoderSel = 1;
1134
1135 /* Select the PLL for the PHY
1136 * DP PHY should be clocked from external src if there is
1137 * one.
1138 */
1139 /* On DCE4, if there is an external clock, it generates the DP ref clock */
1140 if (is_dp && rdev->clock.dp_extclk)
1141 args.v3.acConfig.ucRefClkSource = 2; /* external src */
1142 else
1143 args.v3.acConfig.ucRefClkSource = pll_id;
1144
1145 switch (radeon_encoder->encoder_id) {
1146 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1147 args.v3.acConfig.ucTransmitterSel = 0;
1148 break;
1149 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1150 args.v3.acConfig.ucTransmitterSel = 1;
1151 break;
1152 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1153 args.v3.acConfig.ucTransmitterSel = 2;
1154 break;
1155 }
1156
1157 if (is_dp)
1158 args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */
1159 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1160 if (dig->coherent_mode)
1161 args.v3.acConfig.fCoherentMode = 1;
Alex Deucher9aa59992012-01-20 15:03:30 -05001162 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001163 args.v3.acConfig.fDualLinkConnector = 1;
1164 }
1165 break;
1166 case 4:
1167 args.v4.ucAction = action;
1168 if (action == ATOM_TRANSMITTER_ACTION_INIT) {
1169 args.v4.usInitInfo = cpu_to_le16(connector_object_id);
1170 } else if (action == ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH) {
1171 args.v4.asMode.ucLaneSel = lane_num;
1172 args.v4.asMode.ucLaneSet = lane_set;
1173 } else {
1174 if (is_dp)
Alex Deucher6e76a2d2012-09-06 12:30:37 -04001175 args.v4.usPixelClock = cpu_to_le16(dp_clock / 10);
Alex Deucher9aa59992012-01-20 15:03:30 -05001176 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001177 args.v4.usPixelClock = cpu_to_le16((radeon_encoder->pixel_clock / 2) / 10);
1178 else
1179 args.v4.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1180 }
1181
1182 if (is_dp)
1183 args.v4.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -05001184 else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001185 args.v4.ucLaneNum = 8;
1186 else
1187 args.v4.ucLaneNum = 4;
1188
1189 if (dig->linkb)
1190 args.v4.acConfig.ucLinkSel = 1;
1191 if (dig_encoder & 1)
1192 args.v4.acConfig.ucEncoderSel = 1;
1193
1194 /* Select the PLL for the PHY
1195 * DP PHY should be clocked from external src if there is
1196 * one.
1197 */
Alex Deucher3f03ced2011-10-30 17:20:22 -04001198 /* On DCE5 DCPLL usually generates the DP ref clock */
1199 if (is_dp) {
1200 if (rdev->clock.dp_extclk)
1201 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_EXTCLK;
1202 else
1203 args.v4.acConfig.ucRefClkSource = ENCODER_REFCLK_SRC_DCPLL;
1204 } else
1205 args.v4.acConfig.ucRefClkSource = pll_id;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001206
Alex Deuchera3b08292011-10-28 18:46:37 -04001207 switch (radeon_encoder->encoder_id) {
1208 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1209 args.v4.acConfig.ucTransmitterSel = 0;
1210 break;
1211 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1212 args.v4.acConfig.ucTransmitterSel = 1;
1213 break;
1214 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1215 args.v4.acConfig.ucTransmitterSel = 2;
1216 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001217 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001218
Alex Deuchera3b08292011-10-28 18:46:37 -04001219 if (is_dp)
1220 args.v4.acConfig.fCoherentMode = 1; /* DP requires coherent */
1221 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1222 if (dig->coherent_mode)
1223 args.v4.acConfig.fCoherentMode = 1;
Alex Deucher9aa59992012-01-20 15:03:30 -05001224 if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deuchera3b08292011-10-28 18:46:37 -04001225 args.v4.acConfig.fDualLinkConnector = 1;
1226 }
1227 break;
Alex Deucher47aef7a2012-03-20 17:18:05 -04001228 case 5:
1229 args.v5.ucAction = action;
1230 if (is_dp)
1231 args.v5.usSymClock = cpu_to_le16(dp_clock / 10);
1232 else
1233 args.v5.usSymClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1234
1235 switch (radeon_encoder->encoder_id) {
1236 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1237 if (dig->linkb)
1238 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYB;
1239 else
1240 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYA;
1241 break;
1242 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1243 if (dig->linkb)
1244 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYD;
1245 else
1246 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYC;
1247 break;
1248 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1249 if (dig->linkb)
1250 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYF;
1251 else
1252 args.v5.ucPhyId = ATOM_PHY_ID_UNIPHYE;
1253 break;
1254 }
1255 if (is_dp)
1256 args.v5.ucLaneNum = dp_lane_count;
1257 else if (radeon_encoder->pixel_clock > 165000)
1258 args.v5.ucLaneNum = 8;
1259 else
1260 args.v5.ucLaneNum = 4;
1261 args.v5.ucConnObjId = connector_object_id;
1262 args.v5.ucDigMode = atombios_get_encoder_mode(encoder);
1263
1264 if (is_dp && rdev->clock.dp_extclk)
1265 args.v5.asConfig.ucPhyClkSrcId = ENCODER_REFCLK_SRC_EXTCLK;
1266 else
1267 args.v5.asConfig.ucPhyClkSrcId = pll_id;
1268
1269 if (is_dp)
1270 args.v5.asConfig.ucCoherentMode = 1; /* DP requires coherent */
1271 else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) {
1272 if (dig->coherent_mode)
1273 args.v5.asConfig.ucCoherentMode = 1;
1274 }
1275 if (hpd_id == RADEON_HPD_NONE)
1276 args.v5.asConfig.ucHPDSel = 0;
1277 else
1278 args.v5.asConfig.ucHPDSel = hpd_id + 1;
1279 args.v5.ucDigEncoderSel = 1 << dig_encoder;
1280 args.v5.ucDPLaneSet = lane_set;
1281 break;
Alex Deuchera3b08292011-10-28 18:46:37 -04001282 default:
1283 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1284 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001285 }
Alex Deuchera3b08292011-10-28 18:46:37 -04001286 break;
1287 default:
1288 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1289 break;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001290 }
1291
1292 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1293}
1294
1295bool
1296atombios_set_edp_panel_power(struct drm_connector *connector, int action)
1297{
1298 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1299 struct drm_device *dev = radeon_connector->base.dev;
1300 struct radeon_device *rdev = dev->dev_private;
1301 union dig_transmitter_control args;
1302 int index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl);
1303 uint8_t frev, crev;
1304
1305 if (connector->connector_type != DRM_MODE_CONNECTOR_eDP)
1306 goto done;
1307
1308 if (!ASIC_IS_DCE4(rdev))
1309 goto done;
1310
1311 if ((action != ATOM_TRANSMITTER_ACTION_POWER_ON) &&
1312 (action != ATOM_TRANSMITTER_ACTION_POWER_OFF))
1313 goto done;
1314
1315 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1316 goto done;
1317
1318 memset(&args, 0, sizeof(args));
1319
1320 args.v1.ucAction = action;
1321
1322 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1323
1324 /* wait for the panel to power up */
1325 if (action == ATOM_TRANSMITTER_ACTION_POWER_ON) {
1326 int i;
1327
1328 for (i = 0; i < 300; i++) {
1329 if (radeon_hpd_sense(rdev, radeon_connector->hpd.hpd))
1330 return true;
1331 mdelay(1);
1332 }
1333 return false;
1334 }
1335done:
1336 return true;
1337}
1338
1339union external_encoder_control {
1340 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION v1;
1341 EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION_V3 v3;
1342};
1343
1344static void
1345atombios_external_encoder_setup(struct drm_encoder *encoder,
1346 struct drm_encoder *ext_encoder,
1347 int action)
1348{
1349 struct drm_device *dev = encoder->dev;
1350 struct radeon_device *rdev = dev->dev_private;
1351 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1352 struct radeon_encoder *ext_radeon_encoder = to_radeon_encoder(ext_encoder);
1353 union external_encoder_control args;
1354 struct drm_connector *connector;
1355 int index = GetIndexIntoMasterTable(COMMAND, ExternalEncoderControl);
1356 u8 frev, crev;
1357 int dp_clock = 0;
1358 int dp_lane_count = 0;
1359 int connector_object_id = 0;
1360 u32 ext_enum = (ext_radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001361
1362 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1363 connector = radeon_get_connector_for_encoder_init(encoder);
1364 else
1365 connector = radeon_get_connector_for_encoder(encoder);
1366
1367 if (connector) {
1368 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
1369 struct radeon_connector_atom_dig *dig_connector =
1370 radeon_connector->con_priv;
1371
1372 dp_clock = dig_connector->dp_clock;
1373 dp_lane_count = dig_connector->dp_lane_count;
1374 connector_object_id =
1375 (radeon_connector->connector_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001376 }
1377
1378 memset(&args, 0, sizeof(args));
1379
1380 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1381 return;
1382
1383 switch (frev) {
1384 case 1:
1385 /* no params on frev 1 */
1386 break;
1387 case 2:
1388 switch (crev) {
1389 case 1:
1390 case 2:
1391 args.v1.sDigEncoder.ucAction = action;
1392 args.v1.sDigEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1393 args.v1.sDigEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1394
1395 if (ENCODER_MODE_IS_DP(args.v1.sDigEncoder.ucEncoderMode)) {
1396 if (dp_clock == 270000)
1397 args.v1.sDigEncoder.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ;
1398 args.v1.sDigEncoder.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -05001399 } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher3f03ced2011-10-30 17:20:22 -04001400 args.v1.sDigEncoder.ucLaneNum = 8;
1401 else
1402 args.v1.sDigEncoder.ucLaneNum = 4;
1403 break;
1404 case 3:
1405 args.v3.sExtEncoder.ucAction = action;
1406 if (action == EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT)
1407 args.v3.sExtEncoder.usConnectorId = cpu_to_le16(connector_object_id);
1408 else
1409 args.v3.sExtEncoder.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10);
1410 args.v3.sExtEncoder.ucEncoderMode = atombios_get_encoder_mode(encoder);
1411
1412 if (ENCODER_MODE_IS_DP(args.v3.sExtEncoder.ucEncoderMode)) {
1413 if (dp_clock == 270000)
1414 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_2_70GHZ;
1415 else if (dp_clock == 540000)
1416 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_DPLINKRATE_5_40GHZ;
1417 args.v3.sExtEncoder.ucLaneNum = dp_lane_count;
Alex Deucher9aa59992012-01-20 15:03:30 -05001418 } else if (radeon_dig_monitor_is_duallink(encoder, radeon_encoder->pixel_clock))
Alex Deucher3f03ced2011-10-30 17:20:22 -04001419 args.v3.sExtEncoder.ucLaneNum = 8;
1420 else
1421 args.v3.sExtEncoder.ucLaneNum = 4;
1422 switch (ext_enum) {
1423 case GRAPH_OBJECT_ENUM_ID1:
1424 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER1;
1425 break;
1426 case GRAPH_OBJECT_ENUM_ID2:
1427 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER2;
1428 break;
1429 case GRAPH_OBJECT_ENUM_ID3:
1430 args.v3.sExtEncoder.ucConfig |= EXTERNAL_ENCODER_CONFIG_V3_ENCODER3;
1431 break;
1432 }
Alex Deucher1f0e2942012-08-17 10:31:34 -04001433 args.v3.sExtEncoder.ucBitPerColor = radeon_atom_get_bpc(encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -04001434 break;
1435 default:
1436 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1437 return;
1438 }
1439 break;
1440 default:
1441 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1442 return;
1443 }
1444 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1445}
1446
1447static void
1448atombios_yuv_setup(struct drm_encoder *encoder, bool enable)
1449{
1450 struct drm_device *dev = encoder->dev;
1451 struct radeon_device *rdev = dev->dev_private;
1452 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1453 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1454 ENABLE_YUV_PS_ALLOCATION args;
1455 int index = GetIndexIntoMasterTable(COMMAND, EnableYUV);
1456 uint32_t temp, reg;
1457
1458 memset(&args, 0, sizeof(args));
1459
1460 if (rdev->family >= CHIP_R600)
1461 reg = R600_BIOS_3_SCRATCH;
1462 else
1463 reg = RADEON_BIOS_3_SCRATCH;
1464
1465 /* XXX: fix up scratch reg handling */
1466 temp = RREG32(reg);
1467 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1468 WREG32(reg, (ATOM_S3_TV1_ACTIVE |
1469 (radeon_crtc->crtc_id << 18)));
1470 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1471 WREG32(reg, (ATOM_S3_CV_ACTIVE | (radeon_crtc->crtc_id << 24)));
1472 else
1473 WREG32(reg, 0);
1474
1475 if (enable)
1476 args.ucEnable = ATOM_ENABLE;
1477 args.ucCRTC = radeon_crtc->crtc_id;
1478
1479 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1480
1481 WREG32(reg, temp);
1482}
1483
1484static void
1485radeon_atom_encoder_dpms_avivo(struct drm_encoder *encoder, int mode)
1486{
1487 struct drm_device *dev = encoder->dev;
1488 struct radeon_device *rdev = dev->dev_private;
1489 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1490 DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION args;
1491 int index = 0;
1492
1493 memset(&args, 0, sizeof(args));
1494
1495 switch (radeon_encoder->encoder_id) {
1496 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1497 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1498 index = GetIndexIntoMasterTable(COMMAND, TMDSAOutputControl);
1499 break;
1500 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1501 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1502 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1503 index = GetIndexIntoMasterTable(COMMAND, DVOOutputControl);
1504 break;
1505 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1506 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1507 break;
1508 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1509 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1510 index = GetIndexIntoMasterTable(COMMAND, LCD1OutputControl);
1511 else
1512 index = GetIndexIntoMasterTable(COMMAND, LVTMAOutputControl);
1513 break;
1514 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1515 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1516 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1517 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1518 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1519 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1520 else
1521 index = GetIndexIntoMasterTable(COMMAND, DAC1OutputControl);
1522 break;
1523 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1524 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1525 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1526 index = GetIndexIntoMasterTable(COMMAND, TV1OutputControl);
1527 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1528 index = GetIndexIntoMasterTable(COMMAND, CV1OutputControl);
1529 else
1530 index = GetIndexIntoMasterTable(COMMAND, DAC2OutputControl);
1531 break;
1532 default:
1533 return;
1534 }
1535
1536 switch (mode) {
1537 case DRM_MODE_DPMS_ON:
1538 args.ucAction = ATOM_ENABLE;
1539 /* workaround for DVOOutputControl on some RS690 systems */
1540 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DDI) {
1541 u32 reg = RREG32(RADEON_BIOS_3_SCRATCH);
1542 WREG32(RADEON_BIOS_3_SCRATCH, reg & ~ATOM_S3_DFP2I_ACTIVE);
1543 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1544 WREG32(RADEON_BIOS_3_SCRATCH, reg);
1545 } else
1546 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1547 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1548 args.ucAction = ATOM_LCD_BLON;
1549 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1550 }
1551 break;
1552 case DRM_MODE_DPMS_STANDBY:
1553 case DRM_MODE_DPMS_SUSPEND:
1554 case DRM_MODE_DPMS_OFF:
1555 args.ucAction = ATOM_DISABLE;
1556 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1557 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
1558 args.ucAction = ATOM_LCD_BLOFF;
1559 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1560 }
1561 break;
1562 }
1563}
1564
1565static void
1566radeon_atom_encoder_dpms_dig(struct drm_encoder *encoder, int mode)
1567{
1568 struct drm_device *dev = encoder->dev;
1569 struct radeon_device *rdev = dev->dev_private;
1570 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucher8d1af572012-08-22 09:54:56 -04001571 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1572 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001573 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1574 struct radeon_connector *radeon_connector = NULL;
1575 struct radeon_connector_atom_dig *radeon_dig_connector = NULL;
1576
1577 if (connector) {
1578 radeon_connector = to_radeon_connector(connector);
1579 radeon_dig_connector = radeon_connector->con_priv;
1580 }
1581
1582 switch (mode) {
1583 case DRM_MODE_DPMS_ON:
Alex Deucher8d1af572012-08-22 09:54:56 -04001584 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
1585 if (!connector)
1586 dig->panel_mode = DP_PANEL_MODE_EXTERNAL_DP_MODE;
1587 else
1588 dig->panel_mode = radeon_dp_get_panel_mode(encoder, connector);
1589
1590 /* setup and enable the encoder */
1591 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
1592 atombios_dig_encoder_setup(encoder,
1593 ATOM_ENCODER_CMD_SETUP_PANEL_MODE,
1594 dig->panel_mode);
1595 if (ext_encoder) {
1596 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev))
1597 atombios_external_encoder_setup(encoder, ext_encoder,
1598 EXTERNAL_ENCODER_ACTION_V3_ENCODER_SETUP);
Jerome Glissefcedac62012-07-24 17:06:11 -04001599 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001600 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
Alex Deucher8d1af572012-08-22 09:54:56 -04001601 } else if (ASIC_IS_DCE4(rdev)) {
1602 /* setup and enable the encoder */
1603 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP, 0);
1604 /* enable the transmitter */
1605 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
Alex Deucher3f03ced2011-10-30 17:20:22 -04001606 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
Alex Deucher8d1af572012-08-22 09:54:56 -04001607 } else {
1608 /* setup and enable the encoder and transmitter */
1609 atombios_dig_encoder_setup(encoder, ATOM_ENABLE, 0);
1610 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0);
1611 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0);
1612 /* some early dce3.2 boards have a bug in their transmitter control table */
1613 if ((rdev->family != CHIP_RV710) || (rdev->family != CHIP_RV730))
1614 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0);
Jerome Glissefcedac62012-07-24 17:06:11 -04001615 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001616 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
1617 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1618 atombios_set_edp_panel_power(connector,
1619 ATOM_TRANSMITTER_ACTION_POWER_ON);
1620 radeon_dig_connector->edp_on = true;
1621 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001622 radeon_dp_link_train(encoder, connector);
1623 if (ASIC_IS_DCE4(rdev))
1624 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON, 0);
1625 }
1626 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1627 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLON, 0, 0);
1628 break;
1629 case DRM_MODE_DPMS_STANDBY:
1630 case DRM_MODE_DPMS_SUSPEND:
1631 case DRM_MODE_DPMS_OFF:
Alex Deucher8d1af572012-08-22 09:54:56 -04001632 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE5(rdev)) {
1633 /* disable the transmitter */
Alex Deucher3a478242012-01-20 15:01:30 -05001634 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
Alex Deucher8d1af572012-08-22 09:54:56 -04001635 } else if (ASIC_IS_DCE4(rdev)) {
1636 /* disable the transmitter */
Alex Deucher3a478242012-01-20 15:01:30 -05001637 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
Alex Deucher8d1af572012-08-22 09:54:56 -04001638 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1639 } else {
1640 /* disable the encoder and transmitter */
1641 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0);
1642 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0);
1643 atombios_dig_encoder_setup(encoder, ATOM_DISABLE, 0);
1644 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04001645 if (ENCODER_MODE_IS_DP(atombios_get_encoder_mode(encoder)) && connector) {
1646 if (ASIC_IS_DCE4(rdev))
1647 atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF, 0);
1648 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
1649 atombios_set_edp_panel_power(connector,
1650 ATOM_TRANSMITTER_ACTION_POWER_OFF);
1651 radeon_dig_connector->edp_on = false;
1652 }
1653 }
1654 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
1655 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_LCD_BLOFF, 0, 0);
1656 break;
1657 }
1658}
1659
1660static void
1661radeon_atom_encoder_dpms_ext(struct drm_encoder *encoder,
1662 struct drm_encoder *ext_encoder,
1663 int mode)
1664{
1665 struct drm_device *dev = encoder->dev;
1666 struct radeon_device *rdev = dev->dev_private;
1667
1668 switch (mode) {
1669 case DRM_MODE_DPMS_ON:
1670 default:
Alex Deucher1d3949c2012-03-20 17:18:35 -04001671 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) {
Alex Deucher3f03ced2011-10-30 17:20:22 -04001672 atombios_external_encoder_setup(encoder, ext_encoder,
1673 EXTERNAL_ENCODER_ACTION_V3_ENABLE_OUTPUT);
1674 atombios_external_encoder_setup(encoder, ext_encoder,
1675 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING_OFF);
1676 } else
1677 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_ENABLE);
1678 break;
1679 case DRM_MODE_DPMS_STANDBY:
1680 case DRM_MODE_DPMS_SUSPEND:
1681 case DRM_MODE_DPMS_OFF:
Alex Deucher1d3949c2012-03-20 17:18:35 -04001682 if (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)) {
Alex Deucher3f03ced2011-10-30 17:20:22 -04001683 atombios_external_encoder_setup(encoder, ext_encoder,
1684 EXTERNAL_ENCODER_ACTION_V3_ENCODER_BLANKING);
1685 atombios_external_encoder_setup(encoder, ext_encoder,
1686 EXTERNAL_ENCODER_ACTION_V3_DISABLE_OUTPUT);
1687 } else
1688 atombios_external_encoder_setup(encoder, ext_encoder, ATOM_DISABLE);
1689 break;
1690 }
1691}
1692
1693static void
1694radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode)
1695{
1696 struct drm_device *dev = encoder->dev;
1697 struct radeon_device *rdev = dev->dev_private;
1698 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1699 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
1700
1701 DRM_DEBUG_KMS("encoder dpms %d to mode %d, devices %08x, active_devices %08x\n",
1702 radeon_encoder->encoder_id, mode, radeon_encoder->devices,
1703 radeon_encoder->active_device);
1704 switch (radeon_encoder->encoder_id) {
1705 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1706 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1707 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1708 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1709 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1710 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1711 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1712 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1713 radeon_atom_encoder_dpms_avivo(encoder, mode);
1714 break;
1715 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1716 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1717 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1718 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1719 radeon_atom_encoder_dpms_dig(encoder, mode);
1720 break;
1721 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1722 if (ASIC_IS_DCE5(rdev)) {
1723 switch (mode) {
1724 case DRM_MODE_DPMS_ON:
1725 atombios_dvo_setup(encoder, ATOM_ENABLE);
1726 break;
1727 case DRM_MODE_DPMS_STANDBY:
1728 case DRM_MODE_DPMS_SUSPEND:
1729 case DRM_MODE_DPMS_OFF:
1730 atombios_dvo_setup(encoder, ATOM_DISABLE);
1731 break;
1732 }
1733 } else if (ASIC_IS_DCE3(rdev))
1734 radeon_atom_encoder_dpms_dig(encoder, mode);
1735 else
1736 radeon_atom_encoder_dpms_avivo(encoder, mode);
1737 break;
1738 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1739 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1740 if (ASIC_IS_DCE5(rdev)) {
1741 switch (mode) {
1742 case DRM_MODE_DPMS_ON:
1743 atombios_dac_setup(encoder, ATOM_ENABLE);
1744 break;
1745 case DRM_MODE_DPMS_STANDBY:
1746 case DRM_MODE_DPMS_SUSPEND:
1747 case DRM_MODE_DPMS_OFF:
1748 atombios_dac_setup(encoder, ATOM_DISABLE);
1749 break;
1750 }
1751 } else
1752 radeon_atom_encoder_dpms_avivo(encoder, mode);
1753 break;
1754 default:
1755 return;
1756 }
1757
1758 if (ext_encoder)
1759 radeon_atom_encoder_dpms_ext(encoder, ext_encoder, mode);
1760
1761 radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false);
1762
1763}
1764
1765union crtc_source_param {
1766 SELECT_CRTC_SOURCE_PS_ALLOCATION v1;
1767 SELECT_CRTC_SOURCE_PARAMETERS_V2 v2;
1768};
1769
1770static void
1771atombios_set_encoder_crtc_source(struct drm_encoder *encoder)
1772{
1773 struct drm_device *dev = encoder->dev;
1774 struct radeon_device *rdev = dev->dev_private;
1775 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1776 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1777 union crtc_source_param args;
1778 int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source);
1779 uint8_t frev, crev;
1780 struct radeon_encoder_atom_dig *dig;
1781
1782 memset(&args, 0, sizeof(args));
1783
1784 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
1785 return;
1786
1787 switch (frev) {
1788 case 1:
1789 switch (crev) {
1790 case 1:
1791 default:
1792 if (ASIC_IS_AVIVO(rdev))
1793 args.v1.ucCRTC = radeon_crtc->crtc_id;
1794 else {
1795 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) {
1796 args.v1.ucCRTC = radeon_crtc->crtc_id;
1797 } else {
1798 args.v1.ucCRTC = radeon_crtc->crtc_id << 2;
1799 }
1800 }
1801 switch (radeon_encoder->encoder_id) {
1802 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
1803 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
1804 args.v1.ucDevice = ATOM_DEVICE_DFP1_INDEX;
1805 break;
1806 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
1807 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
1808 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT)
1809 args.v1.ucDevice = ATOM_DEVICE_LCD1_INDEX;
1810 else
1811 args.v1.ucDevice = ATOM_DEVICE_DFP3_INDEX;
1812 break;
1813 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
1814 case ENCODER_OBJECT_ID_INTERNAL_DDI:
1815 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1816 args.v1.ucDevice = ATOM_DEVICE_DFP2_INDEX;
1817 break;
1818 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
1819 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1820 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1821 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1822 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1823 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1824 else
1825 args.v1.ucDevice = ATOM_DEVICE_CRT1_INDEX;
1826 break;
1827 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
1828 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1829 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1830 args.v1.ucDevice = ATOM_DEVICE_TV1_INDEX;
1831 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1832 args.v1.ucDevice = ATOM_DEVICE_CV_INDEX;
1833 else
1834 args.v1.ucDevice = ATOM_DEVICE_CRT2_INDEX;
1835 break;
1836 }
1837 break;
1838 case 2:
1839 args.v2.ucCRTC = radeon_crtc->crtc_id;
1840 if (radeon_encoder_get_dp_bridge_encoder_id(encoder) != ENCODER_OBJECT_ID_NONE) {
1841 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
1842
1843 if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS)
1844 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_LVDS;
1845 else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
1846 args.v2.ucEncodeMode = ATOM_ENCODER_MODE_CRT;
1847 else
1848 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1849 } else
1850 args.v2.ucEncodeMode = atombios_get_encoder_mode(encoder);
1851 switch (radeon_encoder->encoder_id) {
1852 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1853 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1854 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1855 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
1856 dig = radeon_encoder->enc_priv;
1857 switch (dig->dig_encoder) {
1858 case 0:
1859 args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID;
1860 break;
1861 case 1:
1862 args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID;
1863 break;
1864 case 2:
1865 args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID;
1866 break;
1867 case 3:
1868 args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID;
1869 break;
1870 case 4:
1871 args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID;
1872 break;
1873 case 5:
1874 args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID;
1875 break;
1876 }
1877 break;
1878 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
1879 args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID;
1880 break;
1881 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
1882 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1883 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1884 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1885 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1886 else
1887 args.v2.ucEncoderID = ASIC_INT_DAC1_ENCODER_ID;
1888 break;
1889 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
1890 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))
1891 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1892 else if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT))
1893 args.v2.ucEncoderID = ASIC_INT_TV_ENCODER_ID;
1894 else
1895 args.v2.ucEncoderID = ASIC_INT_DAC2_ENCODER_ID;
1896 break;
1897 }
1898 break;
1899 }
1900 break;
1901 default:
1902 DRM_ERROR("Unknown table version: %d, %d\n", frev, crev);
1903 return;
1904 }
1905
1906 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
1907
1908 /* update scratch regs with new routing */
1909 radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id);
1910}
1911
1912static void
1913atombios_apply_encoder_quirks(struct drm_encoder *encoder,
1914 struct drm_display_mode *mode)
1915{
1916 struct drm_device *dev = encoder->dev;
1917 struct radeon_device *rdev = dev->dev_private;
1918 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1919 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1920
1921 /* Funky macbooks */
1922 if ((dev->pdev->device == 0x71C5) &&
1923 (dev->pdev->subsystem_vendor == 0x106b) &&
1924 (dev->pdev->subsystem_device == 0x0080)) {
1925 if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
1926 uint32_t lvtma_bit_depth_control = RREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL);
1927
1928 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_TRUNCATE_EN;
1929 lvtma_bit_depth_control &= ~AVIVO_LVTMA_BIT_DEPTH_CONTROL_SPATIAL_DITHER_EN;
1930
1931 WREG32(AVIVO_LVTMA_BIT_DEPTH_CONTROL, lvtma_bit_depth_control);
1932 }
1933 }
1934
1935 /* set scaler clears this on some chips */
1936 if (ASIC_IS_AVIVO(rdev) &&
1937 (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT)))) {
1938 if (ASIC_IS_DCE4(rdev)) {
1939 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1940 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset,
1941 EVERGREEN_INTERLEAVE_EN);
1942 else
1943 WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1944 } else {
1945 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1946 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset,
1947 AVIVO_D1MODE_INTERLEAVE_EN);
1948 else
1949 WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, 0);
1950 }
1951 }
1952}
1953
1954static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder)
1955{
1956 struct drm_device *dev = encoder->dev;
1957 struct radeon_device *rdev = dev->dev_private;
1958 struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
1959 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1960 struct drm_encoder *test_encoder;
Alex Deucher41fa5432012-08-29 19:48:26 -04001961 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Alex Deucher3f03ced2011-10-30 17:20:22 -04001962 uint32_t dig_enc_in_use = 0;
1963
Alex Deucher41fa5432012-08-29 19:48:26 -04001964 if (ASIC_IS_DCE6(rdev)) {
1965 /* DCE6 */
1966 switch (radeon_encoder->encoder_id) {
1967 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
1968 if (dig->linkb)
1969 return 1;
1970 else
1971 return 0;
1972 break;
1973 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
1974 if (dig->linkb)
1975 return 3;
1976 else
1977 return 2;
1978 break;
1979 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
1980 if (dig->linkb)
1981 return 5;
1982 else
1983 return 4;
1984 break;
1985 }
1986 } else if (ASIC_IS_DCE4(rdev)) {
1987 /* DCE4/5 */
1988 if (ASIC_IS_DCE41(rdev) && !ASIC_IS_DCE61(rdev)) {
Alex Deucher3f03ced2011-10-30 17:20:22 -04001989 /* ontario follows DCE4 */
1990 if (rdev->family == CHIP_PALM) {
1991 if (dig->linkb)
1992 return 1;
1993 else
1994 return 0;
1995 } else
1996 /* llano follows DCE3.2 */
1997 return radeon_crtc->crtc_id;
1998 } else {
1999 switch (radeon_encoder->encoder_id) {
2000 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2001 if (dig->linkb)
2002 return 1;
2003 else
2004 return 0;
2005 break;
2006 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2007 if (dig->linkb)
2008 return 3;
2009 else
2010 return 2;
2011 break;
2012 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2013 if (dig->linkb)
2014 return 5;
2015 else
2016 return 4;
2017 break;
2018 }
2019 }
2020 }
2021
2022 /* on DCE32 and encoder can driver any block so just crtc id */
2023 if (ASIC_IS_DCE32(rdev)) {
2024 return radeon_crtc->crtc_id;
2025 }
2026
2027 /* on DCE3 - LVTMA can only be driven by DIGB */
2028 list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) {
2029 struct radeon_encoder *radeon_test_encoder;
2030
2031 if (encoder == test_encoder)
2032 continue;
2033
2034 if (!radeon_encoder_is_digital(test_encoder))
2035 continue;
2036
2037 radeon_test_encoder = to_radeon_encoder(test_encoder);
2038 dig = radeon_test_encoder->enc_priv;
2039
2040 if (dig->dig_encoder >= 0)
2041 dig_enc_in_use |= (1 << dig->dig_encoder);
2042 }
2043
2044 if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA) {
2045 if (dig_enc_in_use & 0x2)
2046 DRM_ERROR("LVDS required digital encoder 2 but it was in use - stealing\n");
2047 return 1;
2048 }
2049 if (!(dig_enc_in_use & 1))
2050 return 0;
2051 return 1;
2052}
2053
2054/* This only needs to be called once at startup */
2055void
2056radeon_atom_encoder_init(struct radeon_device *rdev)
2057{
2058 struct drm_device *dev = rdev->ddev;
2059 struct drm_encoder *encoder;
2060
2061 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2062 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2063 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
2064
2065 switch (radeon_encoder->encoder_id) {
2066 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2067 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2068 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2069 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2070 atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0);
2071 break;
2072 default:
2073 break;
2074 }
2075
Alex Deucher1d3949c2012-03-20 17:18:35 -04002076 if (ext_encoder && (ASIC_IS_DCE41(rdev) || ASIC_IS_DCE61(rdev)))
Alex Deucher3f03ced2011-10-30 17:20:22 -04002077 atombios_external_encoder_setup(encoder, ext_encoder,
2078 EXTERNAL_ENCODER_ACTION_V3_ENCODER_INIT);
2079 }
2080}
2081
2082static void
2083radeon_atom_encoder_mode_set(struct drm_encoder *encoder,
2084 struct drm_display_mode *mode,
2085 struct drm_display_mode *adjusted_mode)
2086{
2087 struct drm_device *dev = encoder->dev;
2088 struct radeon_device *rdev = dev->dev_private;
2089 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -04002090
2091 radeon_encoder->pixel_clock = adjusted_mode->clock;
2092
Alex Deucher8d1af572012-08-22 09:54:56 -04002093 /* need to call this here rather than in prepare() since we need some crtc info */
2094 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2095
Alex Deucher3f03ced2011-10-30 17:20:22 -04002096 if (ASIC_IS_AVIVO(rdev) && !ASIC_IS_DCE4(rdev)) {
2097 if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT))
2098 atombios_yuv_setup(encoder, true);
2099 else
2100 atombios_yuv_setup(encoder, false);
2101 }
2102
2103 switch (radeon_encoder->encoder_id) {
2104 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2105 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2106 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2107 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2108 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_ENABLE);
2109 break;
2110 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2111 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2112 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2113 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
Alex Deucher8d1af572012-08-22 09:54:56 -04002114 /* handled in dpms */
Alex Deucher3f03ced2011-10-30 17:20:22 -04002115 break;
2116 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2117 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2118 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2119 atombios_dvo_setup(encoder, ATOM_ENABLE);
2120 break;
2121 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2122 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2123 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2124 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2125 atombios_dac_setup(encoder, ATOM_ENABLE);
2126 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) {
2127 if (radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
2128 atombios_tv_setup(encoder, ATOM_ENABLE);
2129 else
2130 atombios_tv_setup(encoder, ATOM_DISABLE);
2131 }
2132 break;
2133 }
2134
Alex Deucher3f03ced2011-10-30 17:20:22 -04002135 atombios_apply_encoder_quirks(encoder, adjusted_mode);
2136
2137 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) {
2138 r600_hdmi_enable(encoder);
Rafał Miłecki6b53a052012-06-11 12:34:01 +02002139 if (ASIC_IS_DCE6(rdev))
2140 ; /* TODO (use pointers instead of if-s?) */
2141 else if (ASIC_IS_DCE4(rdev))
Rafał Miłeckie55d3e62012-05-06 17:29:44 +02002142 evergreen_hdmi_setmode(encoder, adjusted_mode);
2143 else
2144 r600_hdmi_setmode(encoder, adjusted_mode);
Alex Deucher3f03ced2011-10-30 17:20:22 -04002145 }
2146}
2147
2148static bool
2149atombios_dac_load_detect(struct drm_encoder *encoder, struct drm_connector *connector)
2150{
2151 struct drm_device *dev = encoder->dev;
2152 struct radeon_device *rdev = dev->dev_private;
2153 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2154 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2155
2156 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT |
2157 ATOM_DEVICE_CV_SUPPORT |
2158 ATOM_DEVICE_CRT_SUPPORT)) {
2159 DAC_LOAD_DETECTION_PS_ALLOCATION args;
2160 int index = GetIndexIntoMasterTable(COMMAND, DAC_LoadDetection);
2161 uint8_t frev, crev;
2162
2163 memset(&args, 0, sizeof(args));
2164
2165 if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
2166 return false;
2167
2168 args.sDacload.ucMisc = 0;
2169
2170 if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_DAC1) ||
2171 (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1))
2172 args.sDacload.ucDacType = ATOM_DAC_A;
2173 else
2174 args.sDacload.ucDacType = ATOM_DAC_B;
2175
2176 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)
2177 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT1_SUPPORT);
2178 else if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)
2179 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CRT2_SUPPORT);
2180 else if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2181 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_CV_SUPPORT);
2182 if (crev >= 3)
2183 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
2184 } else if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2185 args.sDacload.usDeviceID = cpu_to_le16(ATOM_DEVICE_TV1_SUPPORT);
2186 if (crev >= 3)
2187 args.sDacload.ucMisc = DAC_LOAD_MISC_YPrPb;
2188 }
2189
2190 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2191
2192 return true;
2193 } else
2194 return false;
2195}
2196
2197static enum drm_connector_status
2198radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
2199{
2200 struct drm_device *dev = encoder->dev;
2201 struct radeon_device *rdev = dev->dev_private;
2202 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2203 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2204 uint32_t bios_0_scratch;
2205
2206 if (!atombios_dac_load_detect(encoder, connector)) {
2207 DRM_DEBUG_KMS("detect returned false \n");
2208 return connector_status_unknown;
2209 }
2210
2211 if (rdev->family >= CHIP_R600)
2212 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2213 else
2214 bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
2215
2216 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
2217 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2218 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
2219 return connector_status_connected;
2220 }
2221 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2222 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
2223 return connector_status_connected;
2224 }
2225 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2226 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
2227 return connector_status_connected;
2228 }
2229 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2230 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
2231 return connector_status_connected; /* CTV */
2232 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
2233 return connector_status_connected; /* STV */
2234 }
2235 return connector_status_disconnected;
2236}
2237
2238static enum drm_connector_status
2239radeon_atom_dig_detect(struct drm_encoder *encoder, struct drm_connector *connector)
2240{
2241 struct drm_device *dev = encoder->dev;
2242 struct radeon_device *rdev = dev->dev_private;
2243 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2244 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2245 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
2246 u32 bios_0_scratch;
2247
2248 if (!ASIC_IS_DCE4(rdev))
2249 return connector_status_unknown;
2250
2251 if (!ext_encoder)
2252 return connector_status_unknown;
2253
2254 if ((radeon_connector->devices & ATOM_DEVICE_CRT_SUPPORT) == 0)
2255 return connector_status_unknown;
2256
2257 /* load detect on the dp bridge */
2258 atombios_external_encoder_setup(encoder, ext_encoder,
2259 EXTERNAL_ENCODER_ACTION_V3_DACLOAD_DETECTION);
2260
2261 bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
2262
2263 DRM_DEBUG_KMS("Bios 0 scratch %x %08x\n", bios_0_scratch, radeon_encoder->devices);
2264 if (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT) {
2265 if (bios_0_scratch & ATOM_S0_CRT1_MASK)
2266 return connector_status_connected;
2267 }
2268 if (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT) {
2269 if (bios_0_scratch & ATOM_S0_CRT2_MASK)
2270 return connector_status_connected;
2271 }
2272 if (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT) {
2273 if (bios_0_scratch & (ATOM_S0_CV_MASK|ATOM_S0_CV_MASK_A))
2274 return connector_status_connected;
2275 }
2276 if (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT) {
2277 if (bios_0_scratch & (ATOM_S0_TV1_COMPOSITE | ATOM_S0_TV1_COMPOSITE_A))
2278 return connector_status_connected; /* CTV */
2279 else if (bios_0_scratch & (ATOM_S0_TV1_SVIDEO | ATOM_S0_TV1_SVIDEO_A))
2280 return connector_status_connected; /* STV */
2281 }
2282 return connector_status_disconnected;
2283}
2284
2285void
2286radeon_atom_ext_encoder_setup_ddc(struct drm_encoder *encoder)
2287{
2288 struct drm_encoder *ext_encoder = radeon_get_external_encoder(encoder);
2289
2290 if (ext_encoder)
2291 /* ddc_setup on the dp bridge */
2292 atombios_external_encoder_setup(encoder, ext_encoder,
2293 EXTERNAL_ENCODER_ACTION_V3_DDC_SETUP);
2294
2295}
2296
2297static void radeon_atom_encoder_prepare(struct drm_encoder *encoder)
2298{
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +02002299 struct radeon_device *rdev = encoder->dev->dev_private;
Alex Deucher3f03ced2011-10-30 17:20:22 -04002300 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2301 struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
2302
2303 if ((radeon_encoder->active_device &
2304 (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) ||
2305 (radeon_encoder_get_dp_bridge_encoder_id(encoder) !=
2306 ENCODER_OBJECT_ID_NONE)) {
2307 struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +02002308 if (dig) {
Alex Deucher3f03ced2011-10-30 17:20:22 -04002309 dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder);
Rafał Miłeckicfcbd6d2012-05-14 16:52:30 +02002310 if (radeon_encoder->active_device & ATOM_DEVICE_DFP_SUPPORT) {
2311 if (rdev->family >= CHIP_R600)
2312 dig->afmt = rdev->mode_info.afmt[dig->dig_encoder];
2313 else
2314 /* RS600/690/740 have only 1 afmt block */
2315 dig->afmt = rdev->mode_info.afmt[0];
2316 }
2317 }
Alex Deucher3f03ced2011-10-30 17:20:22 -04002318 }
2319
2320 radeon_atom_output_lock(encoder, true);
Alex Deucher3f03ced2011-10-30 17:20:22 -04002321
2322 if (connector) {
2323 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
2324
2325 /* select the clock/data port if it uses a router */
2326 if (radeon_connector->router.cd_valid)
2327 radeon_router_select_cd_port(radeon_connector);
2328
2329 /* turn eDP panel on for mode set */
2330 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
2331 atombios_set_edp_panel_power(connector,
2332 ATOM_TRANSMITTER_ACTION_POWER_ON);
2333 }
2334
2335 /* this is needed for the pll/ss setup to work correctly in some cases */
2336 atombios_set_encoder_crtc_source(encoder);
2337}
2338
2339static void radeon_atom_encoder_commit(struct drm_encoder *encoder)
2340{
Alex Deucher8d1af572012-08-22 09:54:56 -04002341 /* need to call this here as we need the crtc set up */
Alex Deucher3f03ced2011-10-30 17:20:22 -04002342 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
2343 radeon_atom_output_lock(encoder, false);
2344}
2345
2346static void radeon_atom_encoder_disable(struct drm_encoder *encoder)
2347{
2348 struct drm_device *dev = encoder->dev;
2349 struct radeon_device *rdev = dev->dev_private;
2350 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2351 struct radeon_encoder_atom_dig *dig;
2352
2353 /* check for pre-DCE3 cards with shared encoders;
2354 * can't really use the links individually, so don't disable
2355 * the encoder if it's in use by another connector
2356 */
2357 if (!ASIC_IS_DCE3(rdev)) {
2358 struct drm_encoder *other_encoder;
2359 struct radeon_encoder *other_radeon_encoder;
2360
2361 list_for_each_entry(other_encoder, &dev->mode_config.encoder_list, head) {
2362 other_radeon_encoder = to_radeon_encoder(other_encoder);
2363 if ((radeon_encoder->encoder_id == other_radeon_encoder->encoder_id) &&
2364 drm_helper_encoder_in_use(other_encoder))
2365 goto disable_done;
2366 }
2367 }
2368
2369 radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
2370
2371 switch (radeon_encoder->encoder_id) {
2372 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2373 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2374 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2375 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2376 atombios_digital_setup(encoder, PANEL_ENCODER_ACTION_DISABLE);
2377 break;
2378 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2379 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2380 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2381 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
Alex Deucher8d1af572012-08-22 09:54:56 -04002382 /* handled in dpms */
Alex Deucher3f03ced2011-10-30 17:20:22 -04002383 break;
2384 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2385 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2386 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2387 atombios_dvo_setup(encoder, ATOM_DISABLE);
2388 break;
2389 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2390 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2391 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2392 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2393 atombios_dac_setup(encoder, ATOM_DISABLE);
2394 if (radeon_encoder->devices & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))
2395 atombios_tv_setup(encoder, ATOM_DISABLE);
2396 break;
2397 }
2398
2399disable_done:
2400 if (radeon_encoder_is_digital(encoder)) {
2401 if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI)
2402 r600_hdmi_disable(encoder);
2403 dig = radeon_encoder->enc_priv;
2404 dig->dig_encoder = -1;
2405 }
2406 radeon_encoder->active_device = 0;
2407}
2408
2409/* these are handled by the primary encoders */
2410static void radeon_atom_ext_prepare(struct drm_encoder *encoder)
2411{
2412
2413}
2414
2415static void radeon_atom_ext_commit(struct drm_encoder *encoder)
2416{
2417
2418}
2419
2420static void
2421radeon_atom_ext_mode_set(struct drm_encoder *encoder,
2422 struct drm_display_mode *mode,
2423 struct drm_display_mode *adjusted_mode)
2424{
2425
2426}
2427
2428static void radeon_atom_ext_disable(struct drm_encoder *encoder)
2429{
2430
2431}
2432
2433static void
2434radeon_atom_ext_dpms(struct drm_encoder *encoder, int mode)
2435{
2436
2437}
2438
2439static bool radeon_atom_ext_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +02002440 const struct drm_display_mode *mode,
Alex Deucher3f03ced2011-10-30 17:20:22 -04002441 struct drm_display_mode *adjusted_mode)
2442{
2443 return true;
2444}
2445
2446static const struct drm_encoder_helper_funcs radeon_atom_ext_helper_funcs = {
2447 .dpms = radeon_atom_ext_dpms,
2448 .mode_fixup = radeon_atom_ext_mode_fixup,
2449 .prepare = radeon_atom_ext_prepare,
2450 .mode_set = radeon_atom_ext_mode_set,
2451 .commit = radeon_atom_ext_commit,
2452 .disable = radeon_atom_ext_disable,
2453 /* no detect for TMDS/LVDS yet */
2454};
2455
2456static const struct drm_encoder_helper_funcs radeon_atom_dig_helper_funcs = {
2457 .dpms = radeon_atom_encoder_dpms,
2458 .mode_fixup = radeon_atom_mode_fixup,
2459 .prepare = radeon_atom_encoder_prepare,
2460 .mode_set = radeon_atom_encoder_mode_set,
2461 .commit = radeon_atom_encoder_commit,
2462 .disable = radeon_atom_encoder_disable,
2463 .detect = radeon_atom_dig_detect,
2464};
2465
2466static const struct drm_encoder_helper_funcs radeon_atom_dac_helper_funcs = {
2467 .dpms = radeon_atom_encoder_dpms,
2468 .mode_fixup = radeon_atom_mode_fixup,
2469 .prepare = radeon_atom_encoder_prepare,
2470 .mode_set = radeon_atom_encoder_mode_set,
2471 .commit = radeon_atom_encoder_commit,
2472 .detect = radeon_atom_dac_detect,
2473};
2474
2475void radeon_enc_destroy(struct drm_encoder *encoder)
2476{
2477 struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Alex Deucherf3728732012-07-26 11:32:03 -04002478 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2479 radeon_atom_backlight_exit(radeon_encoder);
Alex Deucher3f03ced2011-10-30 17:20:22 -04002480 kfree(radeon_encoder->enc_priv);
2481 drm_encoder_cleanup(encoder);
2482 kfree(radeon_encoder);
2483}
2484
2485static const struct drm_encoder_funcs radeon_atom_enc_funcs = {
2486 .destroy = radeon_enc_destroy,
2487};
2488
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002489static struct radeon_encoder_atom_dac *
Alex Deucher3f03ced2011-10-30 17:20:22 -04002490radeon_atombios_set_dac_info(struct radeon_encoder *radeon_encoder)
2491{
2492 struct drm_device *dev = radeon_encoder->base.dev;
2493 struct radeon_device *rdev = dev->dev_private;
2494 struct radeon_encoder_atom_dac *dac = kzalloc(sizeof(struct radeon_encoder_atom_dac), GFP_KERNEL);
2495
2496 if (!dac)
2497 return NULL;
2498
2499 dac->tv_std = radeon_atombios_get_tv_info(rdev);
2500 return dac;
2501}
2502
Lauri Kasanen1109ca02012-08-31 13:43:50 -04002503static struct radeon_encoder_atom_dig *
Alex Deucher3f03ced2011-10-30 17:20:22 -04002504radeon_atombios_set_dig_info(struct radeon_encoder *radeon_encoder)
2505{
2506 int encoder_enum = (radeon_encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
2507 struct radeon_encoder_atom_dig *dig = kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
2508
2509 if (!dig)
2510 return NULL;
2511
2512 /* coherent mode by default */
2513 dig->coherent_mode = true;
2514 dig->dig_encoder = -1;
2515
2516 if (encoder_enum == 2)
2517 dig->linkb = true;
2518 else
2519 dig->linkb = false;
2520
2521 return dig;
2522}
2523
2524void
2525radeon_add_atom_encoder(struct drm_device *dev,
2526 uint32_t encoder_enum,
2527 uint32_t supported_device,
2528 u16 caps)
2529{
2530 struct radeon_device *rdev = dev->dev_private;
2531 struct drm_encoder *encoder;
2532 struct radeon_encoder *radeon_encoder;
2533
2534 /* see if we already added it */
2535 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2536 radeon_encoder = to_radeon_encoder(encoder);
2537 if (radeon_encoder->encoder_enum == encoder_enum) {
2538 radeon_encoder->devices |= supported_device;
2539 return;
2540 }
2541
2542 }
2543
2544 /* add a new one */
2545 radeon_encoder = kzalloc(sizeof(struct radeon_encoder), GFP_KERNEL);
2546 if (!radeon_encoder)
2547 return;
2548
2549 encoder = &radeon_encoder->base;
2550 switch (rdev->num_crtc) {
2551 case 1:
2552 encoder->possible_crtcs = 0x1;
2553 break;
2554 case 2:
2555 default:
2556 encoder->possible_crtcs = 0x3;
2557 break;
2558 case 4:
2559 encoder->possible_crtcs = 0xf;
2560 break;
2561 case 6:
2562 encoder->possible_crtcs = 0x3f;
2563 break;
2564 }
2565
2566 radeon_encoder->enc_priv = NULL;
2567
2568 radeon_encoder->encoder_enum = encoder_enum;
2569 radeon_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
2570 radeon_encoder->devices = supported_device;
2571 radeon_encoder->rmx_type = RMX_OFF;
2572 radeon_encoder->underscan_type = UNDERSCAN_OFF;
2573 radeon_encoder->is_ext_encoder = false;
2574 radeon_encoder->caps = caps;
2575
2576 switch (radeon_encoder->encoder_id) {
2577 case ENCODER_OBJECT_ID_INTERNAL_LVDS:
2578 case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
2579 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
2580 case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
2581 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2582 radeon_encoder->rmx_type = RMX_FULL;
2583 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2584 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2585 } else {
2586 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2587 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2588 }
2589 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2590 break;
2591 case ENCODER_OBJECT_ID_INTERNAL_DAC1:
2592 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2593 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2594 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2595 break;
2596 case ENCODER_OBJECT_ID_INTERNAL_DAC2:
2597 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
2598 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
2599 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TVDAC);
2600 radeon_encoder->enc_priv = radeon_atombios_set_dac_info(radeon_encoder);
2601 drm_encoder_helper_add(encoder, &radeon_atom_dac_helper_funcs);
2602 break;
2603 case ENCODER_OBJECT_ID_INTERNAL_DVO1:
2604 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1:
2605 case ENCODER_OBJECT_ID_INTERNAL_DDI:
2606 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
2607 case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
2608 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
2609 case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
2610 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) {
2611 radeon_encoder->rmx_type = RMX_FULL;
2612 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2613 radeon_encoder->enc_priv = radeon_atombios_get_lvds_info(radeon_encoder);
2614 } else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT)) {
2615 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2616 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2617 } else {
2618 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2619 radeon_encoder->enc_priv = radeon_atombios_set_dig_info(radeon_encoder);
2620 }
2621 drm_encoder_helper_add(encoder, &radeon_atom_dig_helper_funcs);
2622 break;
2623 case ENCODER_OBJECT_ID_SI170B:
2624 case ENCODER_OBJECT_ID_CH7303:
2625 case ENCODER_OBJECT_ID_EXTERNAL_SDVOA:
2626 case ENCODER_OBJECT_ID_EXTERNAL_SDVOB:
2627 case ENCODER_OBJECT_ID_TITFP513:
2628 case ENCODER_OBJECT_ID_VT1623:
2629 case ENCODER_OBJECT_ID_HDMI_SI1930:
2630 case ENCODER_OBJECT_ID_TRAVIS:
2631 case ENCODER_OBJECT_ID_NUTMEG:
2632 /* these are handled by the primary encoders */
2633 radeon_encoder->is_ext_encoder = true;
2634 if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT))
2635 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_LVDS);
2636 else if (radeon_encoder->devices & (ATOM_DEVICE_CRT_SUPPORT))
2637 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_DAC);
2638 else
2639 drm_encoder_init(dev, encoder, &radeon_atom_enc_funcs, DRM_MODE_ENCODER_TMDS);
2640 drm_encoder_helper_add(encoder, &radeon_atom_ext_helper_funcs);
2641 break;
2642 }
2643}