Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu/OLAND: clip the ref divider max value

This patch limits the ref_div_max value to 100, during the
calculation of PLL feedback reference divider. With current
value (128), the produced fb_ref_div value generates unstable
output at particular frequencies. Radeon driver limits this
value at 100.

On Oland, when we try to setup mode 2048x1280@60 (a bit weird,
I know), it demands a clock of 221270 Khz. It's been observed
that the PLL calculations using values 128 and 100 are vastly
different, and look like this:

+------------------------------------------+
|Parameter |AMDGPU |Radeon |
| | | |
+-------------+----------------------------+
|Clock feedback | |
|divider max | 128 | 100 |
|cap value | | |
| | | |
| | | |
+------------------------------------------+
|ref_div_max | | |
| | 42 | 20 |
| | | |
| | | |
+------------------------------------------+
|ref_div | 42 | 20 |
| | | |
+------------------------------------------+
|fb_div | 10326 | 8195 |
+------------------------------------------+
|fb_div | 1024 | 163 |
+------------------------------------------+
|fb_dev_p | 4 | 9 |
|frac fb_de^_p| | |
+----------------------------+-------------+

With ref_div_max value clipped at 100, AMDGPU driver can also
drive videmode 2048x1280@60 (221Mhz) and produce proper output
without any blanking and distortion on the screen.

PS: This value was changed from 128 to 100 in Radeon driver also, here:
https://github.com/freedesktop/drm-tip/commit/4b21ce1b4b5d262e7d4656b8ececc891fc3cb806

V1:
Got acks from:
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>

V2:
- Restricting the changes only for OLAND, just to avoid any regression
for other cards.
- Changed unsigned -> unsigned int to make checkpatch quiet.

V3: Apply the change on SI family (not only oland) (Christian)

Cc: Alex Deucher <Alexander.Deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Eddy Qin <Eddy.Qin@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Shashank Sharma <shashank.sharma@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Shashank Sharma and committed by
Alex Deucher
7301757e 234b4fd9

+16 -9
+13 -7
drivers/gpu/drm/amd/amdgpu/amdgpu_pll.c
··· 80 80 * Calculate feedback and reference divider for a given post divider. Makes 81 81 * sure we stay within the limits. 82 82 */ 83 - static void amdgpu_pll_get_fb_ref_div(unsigned nom, unsigned den, unsigned post_div, 84 - unsigned fb_div_max, unsigned ref_div_max, 85 - unsigned *fb_div, unsigned *ref_div) 83 + static void amdgpu_pll_get_fb_ref_div(struct amdgpu_device *adev, unsigned int nom, 84 + unsigned int den, unsigned int post_div, 85 + unsigned int fb_div_max, unsigned int ref_div_max, 86 + unsigned int *fb_div, unsigned int *ref_div) 86 87 { 88 + 87 89 /* limit reference * post divider to a maximum */ 88 - ref_div_max = min(128 / post_div, ref_div_max); 90 + if (adev->family == AMDGPU_FAMILY_SI) 91 + ref_div_max = min(100 / post_div, ref_div_max); 92 + else 93 + ref_div_max = min(128 / post_div, ref_div_max); 89 94 90 95 /* get matching reference and feedback divider */ 91 96 *ref_div = min(max(DIV_ROUND_CLOSEST(den, post_div), 1u), ref_div_max); ··· 117 112 * Try to calculate the PLL parameters to generate the given frequency: 118 113 * dot_clock = (ref_freq * feedback_div) / (ref_div * post_div) 119 114 */ 120 - void amdgpu_pll_compute(struct amdgpu_pll *pll, 115 + void amdgpu_pll_compute(struct amdgpu_device *adev, 116 + struct amdgpu_pll *pll, 121 117 u32 freq, 122 118 u32 *dot_clock_p, 123 119 u32 *fb_div_p, ··· 205 199 206 200 for (post_div = post_div_min; post_div <= post_div_max; ++post_div) { 207 201 unsigned diff; 208 - amdgpu_pll_get_fb_ref_div(nom, den, post_div, fb_div_max, 202 + amdgpu_pll_get_fb_ref_div(adev, nom, den, post_div, fb_div_max, 209 203 ref_div_max, &fb_div, &ref_div); 210 204 diff = abs(target_clock - (pll->reference_freq * fb_div) / 211 205 (ref_div * post_div)); ··· 220 214 post_div = post_div_best; 221 215 222 216 /* get the feedback and reference divider for the optimal value */ 223 - amdgpu_pll_get_fb_ref_div(nom, den, post_div, fb_div_max, ref_div_max, 217 + amdgpu_pll_get_fb_ref_div(adev, nom, den, post_div, fb_div_max, ref_div_max, 224 218 &fb_div, &ref_div); 225 219 226 220 /* reduce the numbers to a simpler ratio once more */
+2 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_pll.h
··· 24 24 #ifndef __AMDGPU_PLL_H__ 25 25 #define __AMDGPU_PLL_H__ 26 26 27 - void amdgpu_pll_compute(struct amdgpu_pll *pll, 27 + void amdgpu_pll_compute(struct amdgpu_device *adev, 28 + struct amdgpu_pll *pll, 28 29 u32 freq, 29 30 u32 *dot_clock_p, 30 31 u32 *fb_div_p,
+1 -1
drivers/gpu/drm/amd/amdgpu/atombios_crtc.c
··· 851 851 pll->reference_div = amdgpu_crtc->pll_reference_div; 852 852 pll->post_div = amdgpu_crtc->pll_post_div; 853 853 854 - amdgpu_pll_compute(pll, amdgpu_crtc->adjusted_clock, &pll_clock, 854 + amdgpu_pll_compute(adev, pll, amdgpu_crtc->adjusted_clock, &pll_clock, 855 855 &fb_div, &frac_fb_div, &ref_div, &post_div); 856 856 857 857 amdgpu_atombios_crtc_program_ss(adev, ATOM_DISABLE, amdgpu_crtc->pll_id,