34 static void atombios_overscan_setup(
struct drm_crtc *
crtc,
45 memset(&args, 0,
sizeof(args));
47 args.ucCRTC = radeon_crtc->
crtc_id;
79 static void atombios_scaler_setup(
struct drm_crtc *crtc)
90 bool is_tv =
false, is_cv =
false;
101 memset(&args, 0,
sizeof(args));
103 args.ucScaler = radeon_crtc->
crtc_id;
163 static void atombios_lock_crtc(
struct drm_crtc *crtc,
int lock)
172 memset(&args, 0,
sizeof(args));
174 args.ucCRTC = radeon_crtc->
crtc_id;
175 args.ucEnable = lock;
180 static void atombios_enable_crtc(
struct drm_crtc *crtc,
int state)
188 memset(&args, 0,
sizeof(args));
190 args.ucCRTC = radeon_crtc->
crtc_id;
191 args.ucEnable =
state;
196 static void atombios_enable_crtc_memreq(
struct drm_crtc *crtc,
int state)
204 memset(&args, 0,
sizeof(args));
206 args.ucCRTC = radeon_crtc->
crtc_id;
207 args.ucEnable =
state;
212 static void atombios_blank_crtc(
struct drm_crtc *crtc,
int state)
220 memset(&args, 0,
sizeof(args));
222 args.ucCRTC = radeon_crtc->
crtc_id;
223 args.ucBlanking =
state;
228 static void atombios_powergate_crtc(
struct drm_crtc *crtc,
int state)
236 memset(&args, 0,
sizeof(args));
283 atombios_set_crtc_dtd_timing(
struct drm_crtc *crtc,
293 memset(&args, 0,
sizeof(args));
328 static void atombios_crtc_set_timing(
struct drm_crtc *crtc,
338 memset(&args, 0,
sizeof(args));
350 args.ucOverscanRight = radeon_crtc->
h_border;
351 args.ucOverscanLeft = radeon_crtc->
h_border;
352 args.ucOverscanBottom = radeon_crtc->
v_border;
353 args.ucOverscanTop = radeon_crtc->
v_border;
367 args.ucCRTC = radeon_crtc->
crtc_id;
372 static void atombios_disable_ss(
struct radeon_device *rdev,
int pll_id)
420 static void atombios_crtc_program_ss(
struct radeon_device *rdev,
431 for (i = 0; i < rdev->
num_crtc; i++) {
435 pll_id == rdev->
mode_info.crtcs[i]->pll_id) {
445 memset(&args, 0,
sizeof(args));
492 args.
v1.ucSpreadSpectrumStep = ss->
step;
493 args.
v1.ucSpreadSpectrumDelay = ss->
delay;
494 args.
v1.ucSpreadSpectrumRange = ss->
range;
495 args.
v1.ucPpll = pll_id;
500 atombios_disable_ss(rdev, pll_id);
512 atombios_disable_ss(rdev, pll_id);
529 static u32 atombios_adjust_pll(
struct drm_crtc *crtc,
567 if (mode->
clock > 200000)
587 if (radeon_crtc->
ss.refdiv) {
599 adjusted_clock = mode->
clock * 2;
623 return adjusted_clock;
625 memset(&args, 0,
sizeof(args));
634 args.
v1.ucEncodeMode = encoder_mode;
635 if (radeon_crtc->
ss_enabled && radeon_crtc->
ss.percentage)
645 args.
v3.sInput.ucTransmitterID = radeon_encoder->
encoder_id;
646 args.
v3.sInput.ucEncodeMode = encoder_mode;
647 args.
v3.sInput.ucDispPllConfig = 0;
648 if (radeon_crtc->
ss_enabled && radeon_crtc->
ss.percentage)
649 args.
v3.sInput.ucDispPllConfig |=
652 args.
v3.sInput.ucDispPllConfig |=
660 args.
v3.sInput.usPixelClock =
663 args.
v3.sInput.ucDispPllConfig |=
666 args.
v3.sInput.ucDispPllConfig |=
671 args.
v3.sInput.ucExtTransmitterID =
674 args.
v3.sInput.ucExtTransmitterID = 0;
678 adjusted_clock =
le32_to_cpu(args.
v3.sOutput.ulDispPllFreq) * 10;
679 if (args.
v3.sOutput.ucRefDiv) {
684 if (args.
v3.sOutput.ucPostDiv) {
691 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
692 return adjusted_clock;
696 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
697 return adjusted_clock;
700 return adjusted_clock;
715 static void atombios_crtc_set_disp_eng_pll(
struct radeon_device *rdev,
722 memset(&args, 0,
sizeof(args));
753 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
758 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
764 static void atombios_crtc_program_pll(
struct drm_crtc *crtc,
784 memset(&args, 0,
sizeof(args));
799 args.
v1.ucFracFbDiv = frac_fb_div;
800 args.
v1.ucPostDiv = post_div;
801 args.
v1.ucPpll = pll_id;
802 args.
v1.ucCRTC = crtc_id;
803 args.
v1.ucRefDivSrc = 1;
809 args.
v2.ucFracFbDiv = frac_fb_div;
810 args.
v2.ucPostDiv = post_div;
811 args.
v2.ucPpll = pll_id;
812 args.
v2.ucCRTC = crtc_id;
813 args.
v2.ucRefDivSrc = 1;
819 args.
v3.ucFracFbDiv = frac_fb_div;
820 args.
v3.ucPostDiv = post_div;
821 args.
v3.ucPpll = pll_id;
828 args.
v3.ucTransmitterId = encoder_id;
829 args.
v3.ucEncoderMode = encoder_mode;
832 args.v5.ucCRTC = crtc_id;
834 args.v5.ucRefDiv = ref_div;
836 args.v5.ulFbDivDecFrac =
cpu_to_le32(frac_fb_div * 100000);
837 args.v5.ucPostDiv = post_div;
838 args.v5.ucMiscInfo = 0;
850 args.v5.ucTransmitterID = encoder_id;
851 args.v5.ucEncoderMode = encoder_mode;
852 args.v5.ucPpll = pll_id;
855 args.v6.ulDispEngClkFreq =
cpu_to_le32(crtc_id << 24 | clock / 10);
856 args.v6.ucRefDiv = ref_div;
858 args.v6.ulFbDivDecFrac =
cpu_to_le32(frac_fb_div * 100000);
859 args.v6.ucPostDiv = post_div;
860 args.v6.ucMiscInfo = 0;
878 args.v6.ucTransmitterID = encoder_id;
879 args.v6.ucEncoderMode = encoder_mode;
880 args.v6.ucPpll = pll_id;
883 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
888 DRM_ERROR(
"Unknown table version %d %d\n", frev, crev);
900 struct radeon_encoder *radeon_encoder =
904 radeon_crtc->
bpc = 8;
919 switch (encoder_mode) {
923 dp_clock = dig_connector->
dp_clock / 10;
930 if (dp_clock == 16200) {
992 struct radeon_encoder *radeon_encoder =
995 u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0;
999 switch (radeon_crtc->
pll_id) {
1001 pll = &rdev->
clock.p1pll;
1004 pll = &rdev->
clock.p2pll;
1009 pll = &rdev->
clock.dcpll;
1021 &fb_div, &frac_fb_div, &ref_div, &post_div);
1024 &fb_div, &frac_fb_div, &ref_div, &post_div);
1027 &fb_div, &frac_fb_div, &ref_div, &post_div);
1030 radeon_crtc->
crtc_id, &radeon_crtc->
ss);
1032 atombios_crtc_program_pll(crtc, radeon_crtc->
crtc_id, radeon_crtc->
pll_id,
1034 ref_div, fb_div, frac_fb_div, post_div,
1041 u32 amount = (((fb_div * 10) + frac_fb_div) * radeon_crtc->
ss.percentage) / 10000;
1046 step_size = (4 * amount * ref_div * (radeon_crtc->
ss.rate * 2048)) /
1049 step_size = (2 * amount * ref_div * (radeon_crtc->
ss.rate * 2048)) /
1055 radeon_crtc->
crtc_id, &radeon_crtc->
ss);
1059 static int dce4_crtc_do_set_base(
struct drm_crtc *crtc,
1061 int x,
int y,
int atomic)
1068 struct drm_gem_object *obj;
1072 unsigned bankw, bankh, mtaspect, tile_split;
1074 u32 tmp, viewport_w, viewport_h;
1078 if (!atomic && !crtc->
fb) {
1079 DRM_DEBUG_KMS(
"No FB bound\n");
1089 target_fb = crtc->
fb;
1095 obj = radeon_fb->
obj;
1102 fb_location = radeon_bo_gpu_offset(rbo);
1106 radeon_bo_unreserve(rbo);
1112 radeon_bo_unreserve(rbo);
1139 DRM_ERROR(
"Unsupported screen depth %d\n",
1152 switch ((tmp & 0xf0) >> 4) {
1181 switch (radeon_crtc->
crtc_id) {
1232 viewport_w = crtc->
mode.hdisplay;
1233 viewport_h = (crtc->
mode.vdisplay + 1) & ~1;
1235 (viewport_w << 16) | viewport_h);
1246 if (!atomic && fb && fb != crtc->
fb) {
1253 radeon_bo_unreserve(rbo);
1262 static int avivo_crtc_do_set_base(
struct drm_crtc *crtc,
1264 int x,
int y,
int atomic)
1270 struct drm_gem_object *obj;
1274 uint32_t fb_format, fb_pitch_pixels, tiling_flags;
1276 u32 tmp, viewport_w, viewport_h;
1280 if (!atomic && !crtc->
fb) {
1281 DRM_DEBUG_KMS(
"No FB bound\n");
1291 target_fb = crtc->
fb;
1294 obj = radeon_fb->
obj;
1304 fb_location = radeon_bo_gpu_offset(rbo);
1308 radeon_bo_unreserve(rbo);
1313 radeon_bo_unreserve(rbo);
1344 DRM_ERROR(
"Unsupported screen depth %d\n",
1350 if (tiling_flags & RADEON_TILING_MACRO)
1352 else if (tiling_flags & RADEON_TILING_MICRO)
1355 if (tiling_flags & RADEON_TILING_MACRO)
1358 if (tiling_flags & RADEON_TILING_MICRO)
1362 if (radeon_crtc->
crtc_id == 0)
1401 viewport_w = crtc->
mode.hdisplay;
1402 viewport_h = (crtc->
mode.vdisplay + 1) & ~1;
1404 (viewport_w << 16) | viewport_h);
1415 if (!atomic && fb && fb != crtc->
fb) {
1422 radeon_bo_unreserve(rbo);
1438 return dce4_crtc_do_set_base(crtc, old_fb, x, y, 0);
1440 return avivo_crtc_do_set_base(crtc, old_fb, x, y, 0);
1453 return dce4_crtc_do_set_base(crtc, fb, x, y, 1);
1455 return avivo_crtc_do_set_base(crtc, fb, x, y, 1);
1461 static void radeon_legacy_atom_fixup(
struct drm_crtc *crtc)
1466 u32 disp_merge_cntl;
1468 switch (radeon_crtc->
crtc_id) {
1491 static u32 radeon_get_pll_use_mask(
struct drm_crtc *crtc)
1495 struct radeon_crtc *test_radeon_crtc;
1499 if (crtc == test_crtc)
1504 pll_in_use |= (1 << test_radeon_crtc->
pll_id);
1518 static int radeon_get_shared_dp_ppll(
struct drm_crtc *crtc)
1522 struct radeon_crtc *test_radeon_crtc;
1525 if (crtc == test_crtc)
1528 if (test_radeon_crtc->
encoder &&
1532 return test_radeon_crtc->
pll_id;
1547 static int radeon_get_shared_nondp_ppll(
struct drm_crtc *crtc)
1552 struct radeon_crtc *test_radeon_crtc;
1557 if (adjusted_clock == 0)
1561 if (crtc == test_crtc)
1564 if (test_radeon_crtc->
encoder &&
1570 return test_radeon_crtc->
pll_id;
1574 if ((crtc->
mode.clock == test_crtc->
mode.clock) &&
1575 (adjusted_clock == test_adjusted_clock) &&
1578 return test_radeon_crtc->
pll_id;
1615 static int radeon_atom_pick_pll(
struct drm_crtc *crtc)
1620 struct radeon_encoder *radeon_encoder =
1630 (dig->
linkb ==
false))
1635 if (rdev->
clock.dp_extclk)
1640 pll = radeon_get_shared_dp_ppll(crtc);
1646 pll = radeon_get_shared_nondp_ppll(crtc);
1651 pll_in_use = radeon_get_pll_use_mask(crtc);
1656 DRM_ERROR(
"unable to allocate a PPLL\n");
1670 if (rdev->
clock.dp_extclk)
1681 pll = radeon_get_shared_dp_ppll(crtc);
1687 pll = radeon_get_shared_nondp_ppll(crtc);
1692 pll_in_use = radeon_get_pll_use_mask(crtc);
1697 DRM_ERROR(
"unable to allocate a PPLL\n");
1723 atombios_crtc_set_disp_eng_pll(rdev, rdev->
clock.default_dispclk);
1728 rdev->
clock.default_dispclk);
1732 atombios_crtc_set_disp_eng_pll(rdev, rdev->
clock.default_dispclk);
1747 struct radeon_encoder *radeon_encoder =
1749 bool is_tvcv =
false;
1755 atombios_crtc_set_pll(crtc, adjusted_mode);
1758 atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
1761 atombios_crtc_set_timing(crtc, adjusted_mode);
1763 atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
1765 atombios_crtc_set_timing(crtc, adjusted_mode);
1766 if (radeon_crtc->
crtc_id == 0)
1767 atombios_set_crtc_dtd_timing(crtc, adjusted_mode);
1768 radeon_legacy_atom_fixup(crtc);
1771 atombios_overscan_setup(crtc, mode, adjusted_mode);
1772 atombios_scaler_setup(crtc);
1776 static bool atombios_crtc_mode_fixup(
struct drm_crtc *crtc,
1786 if (encoder->
crtc == crtc) {
1787 radeon_crtc->
encoder = encoder;
1799 if (!atombios_crtc_prepare_pll(crtc, adjusted_mode))
1802 radeon_crtc->
pll_id = radeon_atom_pick_pll(crtc);
1811 static void atombios_crtc_prepare(
struct drm_crtc *crtc)
1827 static void atombios_crtc_commit(
struct drm_crtc *crtc)
1836 static void atombios_crtc_disable(
struct drm_crtc *crtc)
1846 for (i = 0; i < rdev->
num_crtc; i++) {
1858 switch (radeon_crtc->
pll_id) {
1862 atombios_crtc_program_pll(crtc, radeon_crtc->
crtc_id, radeon_crtc->
pll_id,
1868 atombios_crtc_program_pll(crtc, radeon_crtc->
crtc_id, radeon_crtc->
pll_id,
1883 .mode_fixup = atombios_crtc_mode_fixup,
1887 .prepare = atombios_crtc_prepare,
1888 .commit = atombios_crtc_commit,
1890 .disable = atombios_crtc_disable,
1894 struct radeon_crtc *radeon_crtc)
1899 switch (radeon_crtc->
crtc_id) {
1921 if (radeon_crtc->
crtc_id == 1)
1931 drm_crtc_helper_add(&radeon_crtc->
base, &atombios_helper_funcs);