diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2011-04-14 21:16:55 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2011-05-15 20:50:25 -0400 |
commit | dac55b58253fe4ced44979543bde35d25eaf56dc (patch) | |
tree | f71b2d27b38044d5734e328b51373cbbe8bff122 /drivers/gpu/drm/nouveau | |
parent | aa58c4056355afd349aa4a0092de5141a425142a (diff) |
drm/nva3/pm: initial pass at set_clock() hook
I still discourage anyone from actually doing this yet.
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau')
-rw-r--r-- | drivers/gpu/drm/nouveau/nva3_pm.c | 115 |
1 files changed, 94 insertions, 21 deletions
diff --git a/drivers/gpu/drm/nouveau/nva3_pm.c b/drivers/gpu/drm/nouveau/nva3_pm.c index 5a68958f076b..5285b9813700 100644 --- a/drivers/gpu/drm/nouveau/nva3_pm.c +++ b/drivers/gpu/drm/nouveau/nva3_pm.c | |||
@@ -34,8 +34,14 @@ | |||
34 | */ | 34 | */ |
35 | 35 | ||
36 | struct nva3_pm_state { | 36 | struct nva3_pm_state { |
37 | struct pll_lims pll; | 37 | enum pll_types type; |
38 | int N, M, P; | 38 | u32 src0; |
39 | u32 src1; | ||
40 | u32 ctrl; | ||
41 | u32 coef; | ||
42 | u32 old_pnm; | ||
43 | u32 new_pnm; | ||
44 | u32 new_div; | ||
39 | }; | 45 | }; |
40 | 46 | ||
41 | static int | 47 | static int |
@@ -96,36 +102,103 @@ void * | |||
96 | nva3_pm_clock_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl, | 102 | nva3_pm_clock_pre(struct drm_device *dev, struct nouveau_pm_level *perflvl, |
97 | u32 id, int khz) | 103 | u32 id, int khz) |
98 | { | 104 | { |
99 | struct nva3_pm_state *state; | 105 | struct nva3_pm_state *pll; |
100 | int dummy, ret; | 106 | struct pll_lims limits; |
101 | 107 | int N, fN, M, P, diff; | |
102 | state = kzalloc(sizeof(*state), GFP_KERNEL); | 108 | int ret, off; |
103 | if (!state) | ||
104 | return ERR_PTR(-ENOMEM); | ||
105 | 109 | ||
106 | ret = get_pll_limits(dev, id, &state->pll); | 110 | ret = get_pll_limits(dev, id, &limits); |
107 | if (ret < 0) { | 111 | if (ret < 0) |
108 | kfree(state); | ||
109 | return (ret == -ENOENT) ? NULL : ERR_PTR(ret); | 112 | return (ret == -ENOENT) ? NULL : ERR_PTR(ret); |
113 | |||
114 | off = nva3_pm_pll_offset(id); | ||
115 | if (id < 0) | ||
116 | return ERR_PTR(-EINVAL); | ||
117 | |||
118 | |||
119 | pll = kzalloc(sizeof(*pll), GFP_KERNEL); | ||
120 | if (!pll) | ||
121 | return ERR_PTR(-ENOMEM); | ||
122 | pll->type = id; | ||
123 | pll->src0 = 0x004120 + (off * 4); | ||
124 | pll->src1 = 0x004160 + (off * 4); | ||
125 | pll->ctrl = limits.reg + 0; | ||
126 | pll->coef = limits.reg + 4; | ||
127 | |||
128 | /* If target clock is within [-2, 3) MHz of a divisor, we'll | ||
129 | * use that instead of calculating MNP values | ||
130 | */ | ||
131 | pll->new_div = ((limits.refclk * 2) / (khz - 2999)) & 0x0f; | ||
132 | if (pll->new_div) { | ||
133 | diff = khz - ((limits.refclk * 2) / pll->new_div); | ||
134 | if (diff < -2000 || diff >= 3000) | ||
135 | pll->new_div = 0; | ||
110 | } | 136 | } |
111 | 137 | ||
112 | ret = nv50_calc_pll2(dev, &state->pll, khz, &state->N, &dummy, | 138 | if (!pll->new_div) { |
113 | &state->M, &state->P); | 139 | ret = nv50_calc_pll2(dev, &limits, khz, &N, &fN, &M, &P); |
114 | if (ret < 0) { | 140 | if (ret < 0) |
115 | kfree(state); | 141 | return ERR_PTR(ret); |
116 | return ERR_PTR(ret); | 142 | |
143 | pll->new_pnm = (P << 16) | (N << 8) | M; | ||
144 | pll->new_div = 2 - 1; | ||
145 | } else { | ||
146 | pll->new_pnm = 0; | ||
147 | pll->new_div--; | ||
117 | } | 148 | } |
118 | 149 | ||
119 | return state; | 150 | if ((nv_rd32(dev, pll->src1) & 0x00000101) != 0x00000101) |
151 | pll->old_pnm = nv_rd32(dev, pll->coef); | ||
152 | return pll; | ||
120 | } | 153 | } |
121 | 154 | ||
122 | void | 155 | void |
123 | nva3_pm_clock_set(struct drm_device *dev, void *pre_state) | 156 | nva3_pm_clock_set(struct drm_device *dev, void *pre_state) |
124 | { | 157 | { |
125 | struct nva3_pm_state *state = pre_state; | 158 | struct nva3_pm_state *pll = pre_state; |
126 | u32 reg = state->pll.reg; | 159 | u32 ctrl = 0; |
160 | |||
161 | /* For the memory clock, NVIDIA will build a "script" describing | ||
162 | * the reclocking process and ask PDAEMON to execute it. | ||
163 | */ | ||
164 | if (pll->type == PLL_MEMORY) { | ||
165 | nv_wr32(dev, 0x100210, 0); | ||
166 | nv_wr32(dev, 0x1002dc, 1); | ||
167 | nv_wr32(dev, 0x004018, 0x00001000); | ||
168 | ctrl = 0x18000100; | ||
169 | } | ||
170 | |||
171 | if (pll->old_pnm || !pll->new_pnm) { | ||
172 | nv_mask(dev, pll->src1, 0x003c0101, 0x00000101 | | ||
173 | (pll->new_div << 18)); | ||
174 | nv_wr32(dev, pll->ctrl, 0x0001001d | ctrl); | ||
175 | nv_mask(dev, pll->ctrl, 0x00000001, 0x00000000); | ||
176 | } | ||
177 | |||
178 | if (pll->new_pnm) { | ||
179 | nv_mask(dev, pll->src0, 0x00000101, 0x00000101); | ||
180 | nv_wr32(dev, pll->coef, pll->new_pnm); | ||
181 | nv_wr32(dev, pll->ctrl, 0x0001001d | ctrl); | ||
182 | nv_mask(dev, pll->ctrl, 0x00000010, 0x00000000); | ||
183 | nv_mask(dev, pll->ctrl, 0x00020010, 0x00020010); | ||
184 | nv_wr32(dev, pll->ctrl, 0x00010015 | ctrl); | ||
185 | nv_mask(dev, pll->src1, 0x00000100, 0x00000000); | ||
186 | nv_mask(dev, pll->src1, 0x00000001, 0x00000000); | ||
187 | if (pll->type == PLL_MEMORY) | ||
188 | nv_wr32(dev, 0x4018, 0x10005000); | ||
189 | } else { | ||
190 | nv_mask(dev, pll->ctrl, 0x00000001, 0x00000000); | ||
191 | nv_mask(dev, pll->src0, 0x00000100, 0x00000000); | ||
192 | nv_mask(dev, pll->src0, 0x00000001, 0x00000000); | ||
193 | if (pll->type == PLL_MEMORY) | ||
194 | nv_wr32(dev, 0x4018, 0x1000d000); | ||
195 | } | ||
196 | |||
197 | if (pll->type == PLL_MEMORY) { | ||
198 | nv_wr32(dev, 0x1002dc, 0); | ||
199 | nv_wr32(dev, 0x100210, 0x80000000); | ||
200 | } | ||
127 | 201 | ||
128 | nv_wr32(dev, reg + 4, (state->P << 16) | (state->N << 8) | state->M); | 202 | kfree(pll); |
129 | kfree(state); | ||
130 | } | 203 | } |
131 | 204 | ||