Commit | Line | Data |
---|---|---|
e9ebb68b BS |
1 | /* |
2 | * Copyright 2010 Red Hat Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
20 | * OTHER DEALINGS IN THE SOFTWARE. | |
21 | * | |
22 | * Authors: Ben Skeggs | |
23 | */ | |
24 | ||
25 | #include "drmP.h" | |
26 | #include "drm_fixed.h" | |
27 | #include "nouveau_drv.h" | |
28 | #include "nouveau_hw.h" | |
29 | ||
30 | int | |
31 | nv50_calc_pll(struct drm_device *dev, struct pll_lims *pll, int clk, | |
32 | int *N1, int *M1, int *N2, int *M2, int *P) | |
33 | { | |
34 | struct nouveau_pll_vals pll_vals; | |
35 | int ret; | |
36 | ||
37 | ret = nouveau_calc_pll_mnp(dev, pll, clk, &pll_vals); | |
38 | if (ret <= 0) | |
39 | return ret; | |
40 | ||
41 | *N1 = pll_vals.N1; | |
42 | *M1 = pll_vals.M1; | |
43 | *N2 = pll_vals.N2; | |
44 | *M2 = pll_vals.M2; | |
45 | *P = pll_vals.log2P; | |
46 | return ret; | |
47 | } | |
48 | ||
49 | int | |
50 | nv50_calc_pll2(struct drm_device *dev, struct pll_lims *pll, int clk, | |
51 | int *N, int *fN, int *M, int *P) | |
52 | { | |
53 | fixed20_12 fb_div, a, b; | |
54 | ||
55 | *P = pll->vco1.maxfreq / clk; | |
56 | if (*P > pll->max_p) | |
57 | *P = pll->max_p; | |
58 | if (*P < pll->min_p) | |
59 | *P = pll->min_p; | |
60 | ||
61 | /* *M = ceil(refclk / pll->vco.max_inputfreq); */ | |
62 | a.full = dfixed_const(pll->refclk); | |
63 | b.full = dfixed_const(pll->vco1.max_inputfreq); | |
64 | a.full = dfixed_div(a, b); | |
65 | a.full = dfixed_ceil(a); | |
66 | *M = dfixed_trunc(a); | |
67 | ||
68 | /* fb_div = (vco * *M) / refclk; */ | |
69 | fb_div.full = dfixed_const(clk * *P); | |
70 | fb_div.full = dfixed_mul(fb_div, a); | |
71 | a.full = dfixed_const(pll->refclk); | |
72 | fb_div.full = dfixed_div(fb_div, a); | |
73 | ||
74 | /* *N = floor(fb_div); */ | |
75 | a.full = dfixed_floor(fb_div); | |
76 | *N = dfixed_trunc(fb_div); | |
77 | ||
78 | /* *fN = (fmod(fb_div, 1.0) * 8192) - 4096; */ | |
79 | b.full = dfixed_const(8192); | |
80 | a.full = dfixed_mul(a, b); | |
81 | fb_div.full = dfixed_mul(fb_div, b); | |
82 | fb_div.full = fb_div.full - a.full; | |
83 | *fN = dfixed_trunc(fb_div) - 4096; | |
84 | *fN &= 0xffff; | |
85 | ||
86 | return clk; | |
87 | } |