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 "nouveau_drm.h"
27 #include "nouveau_reg.h"
28 #include "dispnv04/hw.h"
29 #include "nouveau_pm.h"
31 #include <subdev/bios/pll.h>
32 #include <subdev/clock.h>
33 #include <subdev/timer.h>
36 nv04_pm_clocks_get(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
40 ret
= nouveau_hw_get_clock(dev
, PLL_CORE
);
45 ret
= nouveau_hw_get_clock(dev
, PLL_MEMORY
);
48 perflvl
->memory
= ret
;
53 struct nv04_pm_clock
{
54 struct nvbios_pll pll
;
55 struct nouveau_pll_vals calc
;
58 struct nv04_pm_state
{
59 struct nv04_pm_clock core
;
60 struct nv04_pm_clock memory
;
64 calc_pll(struct drm_device
*dev
, u32 id
, int khz
, struct nv04_pm_clock
*clk
)
66 struct nouveau_device
*device
= nouveau_dev(dev
);
67 struct nouveau_bios
*bios
= nouveau_bios(device
);
68 struct nouveau_clock
*pclk
= nouveau_clock(device
);
71 ret
= nvbios_pll_parse(bios
, id
, &clk
->pll
);
75 ret
= pclk
->pll_calc(pclk
, &clk
->pll
, khz
, &clk
->calc
);
83 nv04_pm_clocks_pre(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
85 struct nv04_pm_state
*info
;
88 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
90 return ERR_PTR(-ENOMEM
);
92 ret
= calc_pll(dev
, PLL_CORE
, perflvl
->core
, &info
->core
);
96 if (perflvl
->memory
) {
97 ret
= calc_pll(dev
, PLL_MEMORY
, perflvl
->memory
, &info
->memory
);
109 prog_pll(struct drm_device
*dev
, struct nv04_pm_clock
*clk
)
111 struct nouveau_device
*device
= nouveau_dev(dev
);
112 struct nouveau_clock
*pclk
= nouveau_clock(device
);
113 u32 reg
= clk
->pll
.reg
;
115 /* thank the insane nouveau_hw_setpll() interface for this */
116 if (device
->card_type
>= NV_40
)
119 pclk
->pll_prog(pclk
, reg
, &clk
->calc
);
123 nv04_pm_clocks_set(struct drm_device
*dev
, void *pre_state
)
125 struct nouveau_device
*device
= nouveau_dev(dev
);
126 struct nouveau_timer
*ptimer
= nouveau_timer(device
);
127 struct nv04_pm_state
*state
= pre_state
;
129 prog_pll(dev
, &state
->core
);
131 if (state
->memory
.pll
.reg
) {
132 prog_pll(dev
, &state
->memory
);
133 if (device
->card_type
< NV_30
) {
134 if (device
->card_type
== NV_20
)
135 nv_mask(device
, 0x1002c4, 0, 1 << 20);
138 nv_mask(device
, 0x1002c0, 0, 1 << 8);
142 nv_ofuncs(ptimer
)->init(nv_object(ptimer
));