2 * Copyright 2012 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.
25 #include <subdev/clock.h>
26 #include <subdev/bios.h>
27 #include <subdev/bios/pll.h>
31 struct nv40_clock_priv
{
32 struct nouveau_clock base
;
39 static struct nouveau_clocks
41 { nv_clk_src_crystal
, 0xff },
42 { nv_clk_src_href
, 0xff },
43 { nv_clk_src_core
, 0xff, 0, "core", 1000 },
44 { nv_clk_src_shader
, 0xff, 0, "shader", 1000 },
45 { nv_clk_src_mem
, 0xff, 0, "memory", 1000 },
50 read_pll_1(struct nv40_clock_priv
*priv
, u32 reg
)
52 u32 ctrl
= nv_rd32(priv
, reg
+ 0x00);
53 int P
= (ctrl
& 0x00070000) >> 16;
54 int N
= (ctrl
& 0x0000ff00) >> 8;
55 int M
= (ctrl
& 0x000000ff) >> 0;
56 u32 ref
= 27000, clk
= 0;
58 if (ctrl
& 0x80000000)
65 read_pll_2(struct nv40_clock_priv
*priv
, u32 reg
)
67 u32 ctrl
= nv_rd32(priv
, reg
+ 0x00);
68 u32 coef
= nv_rd32(priv
, reg
+ 0x04);
69 int N2
= (coef
& 0xff000000) >> 24;
70 int M2
= (coef
& 0x00ff0000) >> 16;
71 int N1
= (coef
& 0x0000ff00) >> 8;
72 int M1
= (coef
& 0x000000ff) >> 0;
73 int P
= (ctrl
& 0x00070000) >> 16;
74 u32 ref
= 27000, clk
= 0;
76 if ((ctrl
& 0x80000000) && M1
) {
78 if ((ctrl
& 0x40000100) == 0x40000000) {
90 read_clk(struct nv40_clock_priv
*priv
, u32 src
)
94 return read_pll_2(priv
, 0x004000);
96 return read_pll_1(priv
, 0x004008);
105 nv40_clock_read(struct nouveau_clock
*clk
, enum nv_clk_src src
)
107 struct nv40_clock_priv
*priv
= (void *)clk
;
108 u32 mast
= nv_rd32(priv
, 0x00c040);
111 case nv_clk_src_crystal
:
112 return nv_device(priv
)->crystal
;
113 case nv_clk_src_href
:
114 return 100000; /*XXX: PCIE/AGP differ*/
115 case nv_clk_src_core
:
116 return read_clk(priv
, (mast
& 0x00000003) >> 0);
117 case nv_clk_src_shader
:
118 return read_clk(priv
, (mast
& 0x00000030) >> 4);
120 return read_pll_2(priv
, 0x4020);
125 nv_debug(priv
, "unknown clock source %d 0x%08x\n", src
, mast
);
130 nv40_clock_calc_pll(struct nv40_clock_priv
*priv
, u32 reg
, u32 clk
,
131 int *N1
, int *M1
, int *N2
, int *M2
, int *log2P
)
133 struct nouveau_bios
*bios
= nouveau_bios(priv
);
134 struct nvbios_pll pll
;
137 ret
= nvbios_pll_parse(bios
, reg
, &pll
);
141 if (clk
< pll
.vco1
.max_freq
)
142 pll
.vco2
.max_freq
= 0;
144 ret
= nv04_pll_calc(nv_subdev(priv
), &pll
, clk
, N1
, M1
, N2
, M2
, log2P
);
151 nv40_clock_calc(struct nouveau_clock
*clk
, struct nouveau_cstate
*cstate
)
153 struct nv40_clock_priv
*priv
= (void *)clk
;
154 int gclk
= cstate
->domain
[nv_clk_src_core
];
155 int sclk
= cstate
->domain
[nv_clk_src_shader
];
156 int N1
, M1
, N2
, M2
, log2P
;
159 /* core/geometric clock */
160 ret
= nv40_clock_calc_pll(priv
, 0x004000, gclk
,
161 &N1
, &M1
, &N2
, &M2
, &log2P
);
166 priv
->npll_ctrl
= 0x80000100 | (log2P
<< 16);
167 priv
->npll_coef
= (N1
<< 8) | M1
;
169 priv
->npll_ctrl
= 0xc0000000 | (log2P
<< 16);
170 priv
->npll_coef
= (N2
<< 24) | (M2
<< 16) | (N1
<< 8) | M1
;
173 /* use the second pll for shader/rop clock, if it differs from core */
174 if (sclk
&& sclk
!= gclk
) {
175 ret
= nv40_clock_calc_pll(priv
, 0x004008, sclk
,
176 &N1
, &M1
, NULL
, NULL
, &log2P
);
180 priv
->spll
= 0xc0000000 | (log2P
<< 16) | (N1
<< 8) | M1
;
181 priv
->ctrl
= 0x00000223;
183 priv
->spll
= 0x00000000;
184 priv
->ctrl
= 0x00000333;
191 nv40_clock_prog(struct nouveau_clock
*clk
)
193 struct nv40_clock_priv
*priv
= (void *)clk
;
194 nv_mask(priv
, 0x00c040, 0x00000333, 0x00000000);
195 nv_wr32(priv
, 0x004004, priv
->npll_coef
);
196 nv_mask(priv
, 0x004000, 0xc0070100, priv
->npll_ctrl
);
197 nv_mask(priv
, 0x004008, 0xc007ffff, priv
->spll
);
199 nv_mask(priv
, 0x00c040, 0x00000333, priv
->ctrl
);
204 nv40_clock_tidy(struct nouveau_clock
*clk
)
209 nv40_clock_ctor(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
210 struct nouveau_oclass
*oclass
, void *data
, u32 size
,
211 struct nouveau_object
**pobject
)
213 struct nv40_clock_priv
*priv
;
216 ret
= nouveau_clock_create(parent
, engine
, oclass
, nv40_domain
, NULL
, 0,
218 *pobject
= nv_object(priv
);
222 priv
->base
.pll_calc
= nv04_clock_pll_calc
;
223 priv
->base
.pll_prog
= nv04_clock_pll_prog
;
224 priv
->base
.read
= nv40_clock_read
;
225 priv
->base
.calc
= nv40_clock_calc
;
226 priv
->base
.prog
= nv40_clock_prog
;
227 priv
->base
.tidy
= nv40_clock_tidy
;
231 struct nouveau_oclass
232 nv40_clock_oclass
= {
233 .handle
= NV_SUBDEV(CLOCK
, 0x40),
234 .ofuncs
= &(struct nouveau_ofuncs
) {
235 .ctor
= nv40_clock_ctor
,
236 .dtor
= _nouveau_clock_dtor
,
237 .init
= _nouveau_clock_init
,
238 .fini
= _nouveau_clock_fini
,
This page took 0.049932 seconds and 5 git commands to generate.