2 * Copyright 2010 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include "drm_fixed.h"
27 #include "nouveau_drv.h"
28 #include "nouveau_hw.h"
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
)
34 struct nouveau_pll_vals pll_vals
;
37 ret
= nouveau_calc_pll_mnp(dev
, pll
, clk
, &pll_vals
);
50 nv50_calc_pll2(struct drm_device
*dev
, struct pll_lims
*pll
, int clk
,
51 int *N
, int *fN
, int *M
, int *P
)
53 fixed20_12 fb_div
, a
, b
;
55 *P
= pll
->vco1
.maxfreq
/ clk
;
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
);
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
);
74 /* *N = floor(fb_div); */
75 a
.full
= dfixed_floor(fb_div
);
76 *N
= dfixed_trunc(fb_div
);
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;