1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "drmP.h"
26#include "nouveau_drv.h"
27#include "nouveau_hw.h"
28#include "nouveau_pm.h"
29
30struct nv04_pm_state {
31 struct pll_lims pll;
32 struct nouveau_pll_vals calc;
33};
34
35int
36nv04_pm_clock_get(struct drm_device *dev, u32 id)
37{
38 return nouveau_hw_get_clock(dev, id);
39}
40
41void *
42nv04_pm_clock_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl,
43 u32 id, int khz)
44{
45 struct nv04_pm_state *state;
46 int ret;
47
48 state = kzalloc(sizeof(*state), GFP_KERNEL);
49 if (!state)
50 return ERR_PTR(-ENOMEM);
51
52 ret = get_pll_limits(dev, id, &state->pll);
53 if (ret) {
54 kfree(state);
55 return (ret == -ENOENT) ? NULL : ERR_PTR(ret);
56 }
57
58 ret = nouveau_calc_pll_mnp(dev, &state->pll, khz, &state->calc);
59 if (!ret) {
60 kfree(state);
61 return ERR_PTR(-EINVAL);
62 }
63
64 return state;
65}
66
67void
68nv04_pm_clock_set(struct drm_device *dev, void *pre_state)
69{
70 struct drm_nouveau_private *dev_priv = dev->dev_private;
71 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
72 struct nv04_pm_state *state = pre_state;
73 u32 reg = state->pll.reg;
74
75
76 if (dev_priv->card_type >= NV_40)
77 reg += 4;
78
79 nouveau_hw_setpll(dev, reg, &state->calc);
80
81 if (dev_priv->card_type < NV_30 && reg == NV_PRAMDAC_MPLL_COEFF) {
82 if (dev_priv->card_type == NV_20)
83 nv_mask(dev, 0x1002c4, 0, 1 << 20);
84
85
86 nv_mask(dev, 0x1002c0, 0, 1 << 8);
87 }
88
89 if (reg == NV_PRAMDAC_NVPLL_COEFF)
90 ptimer->init(dev);
91
92 kfree(state);
93}
94
95