diff options
Diffstat (limited to 'drivers/gpu/nvgpu/clk/clk_vf_point.c')
-rw-r--r-- | drivers/gpu/nvgpu/clk/clk_vf_point.c | 418 |
1 files changed, 418 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/clk/clk_vf_point.c b/drivers/gpu/nvgpu/clk/clk_vf_point.c new file mode 100644 index 00000000..4fde7226 --- /dev/null +++ b/drivers/gpu/nvgpu/clk/clk_vf_point.c | |||
@@ -0,0 +1,418 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | */ | ||
13 | |||
14 | #include "gk20a/gk20a.h" | ||
15 | #include "clk.h" | ||
16 | #include "clk_vf_point.h" | ||
17 | #include "include/bios.h" | ||
18 | #include "boardobj/boardobjgrp.h" | ||
19 | #include "boardobj/boardobjgrp_e32.h" | ||
20 | #include "pmuif/gpmuifboardobj.h" | ||
21 | #include "pmuif/gpmuifclk.h" | ||
22 | #include "gm206/bios_gm206.h" | ||
23 | #include "ctrl/ctrlclk.h" | ||
24 | #include "ctrl/ctrlvolt.h" | ||
25 | #include "gk20a/pmu_gk20a.h" | ||
26 | |||
27 | static u32 _clk_vf_point_pmudatainit_super(struct gk20a *g, struct boardobj | ||
28 | *board_obj_ptr, struct nv_pmu_boardobj *ppmudata); | ||
29 | |||
30 | static u32 _clk_vf_points_pmudatainit(struct gk20a *g, | ||
31 | struct boardobjgrp *pboardobjgrp, | ||
32 | struct nv_pmu_boardobjgrp_super *pboardobjgrppmu) | ||
33 | { | ||
34 | u32 status = 0; | ||
35 | |||
36 | status = boardobjgrp_pmudatainit_e32(g, pboardobjgrp, pboardobjgrppmu); | ||
37 | if (status) { | ||
38 | gk20a_err(dev_from_gk20a(g), | ||
39 | "error updating pmu boardobjgrp for clk vfpoint 0x%x", | ||
40 | status); | ||
41 | goto done; | ||
42 | } | ||
43 | |||
44 | done: | ||
45 | return status; | ||
46 | } | ||
47 | |||
48 | static u32 _clk_vf_points_pmudata_instget(struct gk20a *g, | ||
49 | struct nv_pmu_boardobjgrp *pmuboardobjgrp, | ||
50 | struct nv_pmu_boardobj **ppboardobjpmudata, | ||
51 | u8 idx) | ||
52 | { | ||
53 | struct nv_pmu_clk_clk_vf_point_boardobj_grp_set *pgrp_set = | ||
54 | (struct nv_pmu_clk_clk_vf_point_boardobj_grp_set *) | ||
55 | pmuboardobjgrp; | ||
56 | |||
57 | gk20a_dbg_info(""); | ||
58 | |||
59 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
60 | if (idx >= CTRL_BOARDOBJGRP_E255_MAX_OBJECTS) | ||
61 | return -EINVAL; | ||
62 | |||
63 | *ppboardobjpmudata = (struct nv_pmu_boardobj *) | ||
64 | &pgrp_set->objects[idx].data.board_obj; | ||
65 | gk20a_dbg_info(" Done"); | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static u32 _clk_vf_points_pmustatus_instget(struct gk20a *g, | ||
70 | void *pboardobjgrppmu, | ||
71 | struct nv_pmu_boardobj_query **ppboardobjpmustatus, | ||
72 | u8 idx) | ||
73 | { | ||
74 | struct nv_pmu_clk_clk_vf_point_boardobj_grp_get_status *pgrp_get_status = | ||
75 | (struct nv_pmu_clk_clk_vf_point_boardobj_grp_get_status *) | ||
76 | pboardobjgrppmu; | ||
77 | |||
78 | /*check whether pmuboardobjgrp has a valid boardobj in index*/ | ||
79 | if (idx >= CTRL_BOARDOBJGRP_E255_MAX_OBJECTS) | ||
80 | return -EINVAL; | ||
81 | |||
82 | *ppboardobjpmustatus = (struct nv_pmu_boardobj_query *) | ||
83 | &pgrp_get_status->objects[idx].data.board_obj; | ||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | u32 clk_vf_point_sw_setup(struct gk20a *g) | ||
88 | { | ||
89 | u32 status; | ||
90 | struct boardobjgrp *pboardobjgrp = NULL; | ||
91 | struct clk_vf_points *pclkvfpointobjs; | ||
92 | |||
93 | gk20a_dbg_info(""); | ||
94 | |||
95 | status = boardobjgrpconstruct_e255(&g->clk_pmu.clk_vf_pointobjs.super); | ||
96 | if (status) { | ||
97 | gk20a_err(dev_from_gk20a(g), | ||
98 | "error creating boardobjgrp for clk vfpoint, status - 0x%x", | ||
99 | status); | ||
100 | goto done; | ||
101 | } | ||
102 | |||
103 | pboardobjgrp = &g->clk_pmu.clk_vf_pointobjs.super.super; | ||
104 | pclkvfpointobjs = &(g->clk_pmu.clk_vf_pointobjs); | ||
105 | |||
106 | BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, CLK, CLK_VF_POINT); | ||
107 | |||
108 | status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp, | ||
109 | clk, CLK, clk_vf_point, CLK_VF_POINT); | ||
110 | if (status) { | ||
111 | gk20a_err(dev_from_gk20a(g), | ||
112 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
113 | status); | ||
114 | goto done; | ||
115 | } | ||
116 | |||
117 | status = BOARDOBJGRP_PMU_CMD_GRP_GET_STATUS_CONSTRUCT(g, | ||
118 | &g->clk_pmu.clk_vf_pointobjs.super.super, | ||
119 | clk, CLK, clk_vf_point, CLK_VF_POINT); | ||
120 | if (status) { | ||
121 | gk20a_err(dev_from_gk20a(g), | ||
122 | "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x", | ||
123 | status); | ||
124 | goto done; | ||
125 | } | ||
126 | |||
127 | pboardobjgrp->pmudatainit = _clk_vf_points_pmudatainit; | ||
128 | pboardobjgrp->pmudatainstget = _clk_vf_points_pmudata_instget; | ||
129 | pboardobjgrp->pmustatusinstget = _clk_vf_points_pmustatus_instget; | ||
130 | |||
131 | done: | ||
132 | gk20a_dbg_info(" done status %x", status); | ||
133 | return status; | ||
134 | } | ||
135 | |||
136 | u32 clk_vf_point_pmu_setup(struct gk20a *g) | ||
137 | { | ||
138 | u32 status; | ||
139 | struct boardobjgrp *pboardobjgrp = NULL; | ||
140 | |||
141 | gk20a_dbg_info(""); | ||
142 | |||
143 | pboardobjgrp = &g->clk_pmu.clk_vf_pointobjs.super.super; | ||
144 | |||
145 | if (!pboardobjgrp->bconstructed) | ||
146 | return -EINVAL; | ||
147 | |||
148 | status = pboardobjgrp->pmuinithandle(g, pboardobjgrp); | ||
149 | |||
150 | gk20a_dbg_info("Done"); | ||
151 | return status; | ||
152 | } | ||
153 | |||
154 | static u32 clk_vf_point_construct_super(struct gk20a *g, | ||
155 | struct boardobj **ppboardobj, | ||
156 | u16 size, void *pargs) | ||
157 | { | ||
158 | struct clk_vf_point *pclkvfpoint; | ||
159 | struct clk_vf_point *ptmpvfpoint = | ||
160 | (struct clk_vf_point *)pargs; | ||
161 | u32 status = 0; | ||
162 | |||
163 | status = boardobj_construct_super(g, ppboardobj, | ||
164 | size, pargs); | ||
165 | if (status) | ||
166 | return -EINVAL; | ||
167 | |||
168 | pclkvfpoint = (struct clk_vf_point *)*ppboardobj; | ||
169 | |||
170 | pclkvfpoint->super.pmudatainit = | ||
171 | _clk_vf_point_pmudatainit_super; | ||
172 | |||
173 | pclkvfpoint->vfe_equ_idx = ptmpvfpoint->vfe_equ_idx; | ||
174 | pclkvfpoint->volt_rail_idx = ptmpvfpoint->volt_rail_idx; | ||
175 | |||
176 | return status; | ||
177 | } | ||
178 | |||
179 | static u32 _clk_vf_point_pmudatainit_volt(struct gk20a *g, | ||
180 | struct boardobj *board_obj_ptr, | ||
181 | struct nv_pmu_boardobj *ppmudata) | ||
182 | { | ||
183 | u32 status = 0; | ||
184 | struct clk_vf_point_volt *pclk_vf_point_volt; | ||
185 | struct nv_pmu_clk_clk_vf_point_volt_boardobj_set *pset; | ||
186 | |||
187 | gk20a_dbg_info(""); | ||
188 | |||
189 | status = _clk_vf_point_pmudatainit_super(g, board_obj_ptr, ppmudata); | ||
190 | if (status != 0) | ||
191 | return status; | ||
192 | |||
193 | pclk_vf_point_volt = | ||
194 | (struct clk_vf_point_volt *)board_obj_ptr; | ||
195 | |||
196 | pset = (struct nv_pmu_clk_clk_vf_point_volt_boardobj_set *) | ||
197 | ppmudata; | ||
198 | |||
199 | pset->source_voltage_uv = pclk_vf_point_volt->source_voltage_uv; | ||
200 | pset->freq_delta_khz = pclk_vf_point_volt->freq_delta_khz; | ||
201 | |||
202 | return status; | ||
203 | } | ||
204 | |||
205 | static u32 _clk_vf_point_pmudatainit_freq(struct gk20a *g, | ||
206 | struct boardobj *board_obj_ptr, | ||
207 | struct nv_pmu_boardobj *ppmudata) | ||
208 | { | ||
209 | u32 status = 0; | ||
210 | struct clk_vf_point_freq *pclk_vf_point_freq; | ||
211 | struct nv_pmu_clk_clk_vf_point_freq_boardobj_set *pset; | ||
212 | |||
213 | gk20a_dbg_info(""); | ||
214 | |||
215 | status = _clk_vf_point_pmudatainit_super(g, board_obj_ptr, ppmudata); | ||
216 | if (status != 0) | ||
217 | return status; | ||
218 | |||
219 | pclk_vf_point_freq = | ||
220 | (struct clk_vf_point_freq *)board_obj_ptr; | ||
221 | |||
222 | pset = (struct nv_pmu_clk_clk_vf_point_freq_boardobj_set *) | ||
223 | ppmudata; | ||
224 | |||
225 | pset->freq_mhz = | ||
226 | clkvfpointfreqmhzget(g, &pclk_vf_point_freq->super); | ||
227 | |||
228 | pset->volt_delta_uv = pclk_vf_point_freq->volt_delta_uv; | ||
229 | |||
230 | return status; | ||
231 | } | ||
232 | |||
233 | static u32 clk_vf_point_construct_volt(struct gk20a *g, | ||
234 | struct boardobj **ppboardobj, | ||
235 | u16 size, void *pargs) | ||
236 | { | ||
237 | struct boardobj *ptmpobj = (struct boardobj *)pargs; | ||
238 | struct clk_vf_point_volt *pclkvfpoint; | ||
239 | struct clk_vf_point_volt *ptmpvfpoint = | ||
240 | (struct clk_vf_point_volt *)pargs; | ||
241 | u32 status = 0; | ||
242 | |||
243 | if (BOARDOBJ_GET_TYPE(pargs) != CTRL_CLK_CLK_VF_POINT_TYPE_VOLT) | ||
244 | return -EINVAL; | ||
245 | |||
246 | ptmpobj->type_mask = BIT(CTRL_CLK_CLK_VF_POINT_TYPE_VOLT); | ||
247 | status = clk_vf_point_construct_super(g, ppboardobj, size, pargs); | ||
248 | if (status) | ||
249 | return -EINVAL; | ||
250 | |||
251 | pclkvfpoint = (struct clk_vf_point_volt *)*ppboardobj; | ||
252 | |||
253 | pclkvfpoint->super.super.pmudatainit = | ||
254 | _clk_vf_point_pmudatainit_volt; | ||
255 | |||
256 | pclkvfpoint->source_voltage_uv = ptmpvfpoint->source_voltage_uv; | ||
257 | |||
258 | return status; | ||
259 | } | ||
260 | |||
261 | static u32 clk_vf_point_construct_freq(struct gk20a *g, | ||
262 | struct boardobj **ppboardobj, | ||
263 | u16 size, void *pargs) | ||
264 | { | ||
265 | struct boardobj *ptmpobj = (struct boardobj *)pargs; | ||
266 | struct clk_vf_point_freq *pclkvfpoint; | ||
267 | struct clk_vf_point_freq *ptmpvfpoint = | ||
268 | (struct clk_vf_point_freq *)pargs; | ||
269 | u32 status = 0; | ||
270 | |||
271 | if (BOARDOBJ_GET_TYPE(pargs) != CTRL_CLK_CLK_VF_POINT_TYPE_FREQ) | ||
272 | return -EINVAL; | ||
273 | |||
274 | ptmpobj->type_mask = BIT(CTRL_CLK_CLK_VF_POINT_TYPE_FREQ); | ||
275 | status = clk_vf_point_construct_super(g, ppboardobj, size, pargs); | ||
276 | if (status) | ||
277 | return -EINVAL; | ||
278 | |||
279 | pclkvfpoint = (struct clk_vf_point_freq *)*ppboardobj; | ||
280 | |||
281 | pclkvfpoint->super.super.pmudatainit = | ||
282 | _clk_vf_point_pmudatainit_freq; | ||
283 | |||
284 | clkvfpointfreqmhzset(g, &pclkvfpoint->super, | ||
285 | clkvfpointfreqmhzget(g, &ptmpvfpoint->super)); | ||
286 | |||
287 | return status; | ||
288 | } | ||
289 | |||
290 | struct clk_vf_point *construct_clk_vf_point(struct gk20a *g, void *pargs) | ||
291 | { | ||
292 | struct boardobj *board_obj_ptr = NULL; | ||
293 | u32 status; | ||
294 | |||
295 | gk20a_dbg_info(""); | ||
296 | switch (BOARDOBJ_GET_TYPE(pargs)) { | ||
297 | case CTRL_CLK_CLK_VF_POINT_TYPE_FREQ: | ||
298 | status = clk_vf_point_construct_freq(g, &board_obj_ptr, | ||
299 | sizeof(struct clk_vf_point_freq), pargs); | ||
300 | break; | ||
301 | |||
302 | case CTRL_CLK_CLK_VF_POINT_TYPE_VOLT: | ||
303 | status = clk_vf_point_construct_volt(g, &board_obj_ptr, | ||
304 | sizeof(struct clk_vf_point_volt), pargs); | ||
305 | break; | ||
306 | |||
307 | default: | ||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | if (status) | ||
312 | return NULL; | ||
313 | |||
314 | gk20a_dbg_info(" Done"); | ||
315 | |||
316 | return (struct clk_vf_point *)board_obj_ptr; | ||
317 | } | ||
318 | |||
319 | static u32 _clk_vf_point_pmudatainit_super(struct gk20a *g, | ||
320 | struct boardobj *board_obj_ptr, | ||
321 | struct nv_pmu_boardobj *ppmudata) | ||
322 | { | ||
323 | u32 status = 0; | ||
324 | struct clk_vf_point *pclk_vf_point; | ||
325 | struct nv_pmu_clk_clk_vf_point_boardobj_set *pset; | ||
326 | |||
327 | gk20a_dbg_info(""); | ||
328 | |||
329 | status = boardobj_pmudatainit_super(g, board_obj_ptr, ppmudata); | ||
330 | if (status != 0) | ||
331 | return status; | ||
332 | |||
333 | pclk_vf_point = | ||
334 | (struct clk_vf_point *)board_obj_ptr; | ||
335 | |||
336 | pset = (struct nv_pmu_clk_clk_vf_point_boardobj_set *) | ||
337 | ppmudata; | ||
338 | |||
339 | |||
340 | pset->vfe_equ_idx = pclk_vf_point->vfe_equ_idx; | ||
341 | pset->volt_rail_idx = pclk_vf_point->volt_rail_idx; | ||
342 | return status; | ||
343 | } | ||
344 | |||
345 | |||
346 | static u32 clk_vf_point_update(struct gk20a *g, | ||
347 | struct boardobj *board_obj_ptr, | ||
348 | struct nv_pmu_boardobj *ppmudata) | ||
349 | { | ||
350 | struct clk_vf_point *pclk_vf_point; | ||
351 | struct nv_pmu_clk_clk_vf_point_boardobj_get_status *pstatus; | ||
352 | |||
353 | gk20a_dbg_info(""); | ||
354 | |||
355 | |||
356 | pclk_vf_point = | ||
357 | (struct clk_vf_point *)board_obj_ptr; | ||
358 | |||
359 | pstatus = (struct nv_pmu_clk_clk_vf_point_boardobj_get_status *) | ||
360 | ppmudata; | ||
361 | |||
362 | if (pstatus->super.type != pclk_vf_point->super.type) { | ||
363 | gk20a_err(dev_from_gk20a(g), | ||
364 | "pmu data and boardobj type not matching"); | ||
365 | return -EINVAL; | ||
366 | } | ||
367 | /* now copy VF pair */ | ||
368 | memcpy(&pclk_vf_point->pair, &pstatus->pair, | ||
369 | sizeof(struct ctrl_clk_vf_pair)); | ||
370 | return 0; | ||
371 | } | ||
372 | |||
373 | /*get latest vf point data from PMU */ | ||
374 | u32 clk_vf_point_cache(struct gk20a *g) | ||
375 | { | ||
376 | |||
377 | struct clk_vf_points *pclk_vf_points; | ||
378 | struct boardobjgrp *pboardobjgrp; | ||
379 | struct boardobjgrpmask *pboardobjgrpmask; | ||
380 | struct nv_pmu_boardobjgrp_super *pboardobjgrppmu; | ||
381 | struct boardobj *pboardobj = NULL; | ||
382 | struct nv_pmu_boardobj_query *pboardobjpmustatus = NULL; | ||
383 | u32 status; | ||
384 | u8 index; | ||
385 | |||
386 | gk20a_dbg_info(""); | ||
387 | pclk_vf_points = &g->clk_pmu.clk_vf_pointobjs; | ||
388 | pboardobjgrp = &pclk_vf_points->super.super; | ||
389 | pboardobjgrpmask = &pclk_vf_points->super.mask.super; | ||
390 | |||
391 | status = pboardobjgrp->pmugetstatus(g, pboardobjgrp, pboardobjgrpmask); | ||
392 | if (status) { | ||
393 | gk20a_err(dev_from_gk20a(g), "err getting boardobjs from pmu"); | ||
394 | return status; | ||
395 | } | ||
396 | pboardobjgrppmu = pboardobjgrp->pmu.getstatus.buf; | ||
397 | |||
398 | BOARDOBJGRP_FOR_EACH(pboardobjgrp, struct boardobj*, pboardobj, index) { | ||
399 | status = pboardobjgrp->pmustatusinstget(g, | ||
400 | (struct nv_pmu_boardobjgrp *)pboardobjgrppmu, | ||
401 | &pboardobjpmustatus, index); | ||
402 | if (status) { | ||
403 | gk20a_err(dev_from_gk20a(g), | ||
404 | "could not get status object instance"); | ||
405 | return status; | ||
406 | } | ||
407 | |||
408 | status = clk_vf_point_update(g, pboardobj, | ||
409 | (struct nv_pmu_boardobj *)pboardobjpmustatus); | ||
410 | if (status) { | ||
411 | gk20a_err(dev_from_gk20a(g), | ||
412 | "invalid data from pmu at %d", index); | ||
413 | return status; | ||
414 | } | ||
415 | } | ||
416 | |||
417 | return 0; | ||
418 | } | ||