aboutsummaryrefslogtreecommitdiffstats
path: root/include/clk/clk_vf_point.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/clk/clk_vf_point.c')
-rw-r--r--include/clk/clk_vf_point.c433
1 files changed, 433 insertions, 0 deletions
diff --git a/include/clk/clk_vf_point.c b/include/clk/clk_vf_point.c
new file mode 100644
index 0000000..96413c8
--- /dev/null
+++ b/include/clk/clk_vf_point.c
@@ -0,0 +1,433 @@
1/*
2 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/gk20a.h>
24
25#include "clk.h"
26#include "clk_vf_point.h"
27#include "boardobj/boardobjgrp.h"
28#include "boardobj/boardobjgrp_e32.h"
29#include "ctrl/ctrlclk.h"
30#include "ctrl/ctrlvolt.h"
31
32static int _clk_vf_point_pmudatainit_super(struct gk20a *g, struct boardobj
33 *board_obj_ptr, struct nv_pmu_boardobj *ppmudata);
34
35static int _clk_vf_points_pmudatainit(struct gk20a *g,
36 struct boardobjgrp *pboardobjgrp,
37 struct nv_pmu_boardobjgrp_super *pboardobjgrppmu)
38{
39 u32 status = 0;
40
41 status = boardobjgrp_pmudatainit_e32(g, pboardobjgrp, pboardobjgrppmu);
42 if (status) {
43 nvgpu_err(g,
44 "error updating pmu boardobjgrp for clk vfpoint 0x%x",
45 status);
46 goto done;
47 }
48
49done:
50 return status;
51}
52
53static int _clk_vf_points_pmudata_instget(struct gk20a *g,
54 struct nv_pmu_boardobjgrp *pmuboardobjgrp,
55 struct nv_pmu_boardobj **ppboardobjpmudata,
56 u8 idx)
57{
58 struct nv_pmu_clk_clk_vf_point_boardobj_grp_set *pgrp_set =
59 (struct nv_pmu_clk_clk_vf_point_boardobj_grp_set *)
60 pmuboardobjgrp;
61
62 nvgpu_log_info(g, " ");
63
64 /*check whether pmuboardobjgrp has a valid boardobj in index*/
65 if (idx >= CTRL_BOARDOBJGRP_E255_MAX_OBJECTS) {
66 return -EINVAL;
67 }
68
69 *ppboardobjpmudata = (struct nv_pmu_boardobj *)
70 &pgrp_set->objects[idx].data.board_obj;
71 nvgpu_log_info(g, " Done");
72 return 0;
73}
74
75static int _clk_vf_points_pmustatus_instget(struct gk20a *g,
76 void *pboardobjgrppmu,
77 struct nv_pmu_boardobj_query **ppboardobjpmustatus,
78 u8 idx)
79{
80 struct nv_pmu_clk_clk_vf_point_boardobj_grp_get_status *pgrp_get_status =
81 (struct nv_pmu_clk_clk_vf_point_boardobj_grp_get_status *)
82 pboardobjgrppmu;
83
84 /*check whether pmuboardobjgrp has a valid boardobj in index*/
85 if (idx >= CTRL_BOARDOBJGRP_E255_MAX_OBJECTS) {
86 return -EINVAL;
87 }
88
89 *ppboardobjpmustatus = (struct nv_pmu_boardobj_query *)
90 &pgrp_get_status->objects[idx].data.board_obj;
91 return 0;
92}
93
94int clk_vf_point_sw_setup(struct gk20a *g)
95{
96 int status;
97 struct boardobjgrp *pboardobjgrp = NULL;
98
99 nvgpu_log_info(g, " ");
100
101 status = boardobjgrpconstruct_e255(g, &g->clk_pmu.clk_vf_pointobjs.super);
102 if (status) {
103 nvgpu_err(g,
104 "error creating boardobjgrp for clk vfpoint, status - 0x%x",
105 status);
106 goto done;
107 }
108
109 pboardobjgrp = &g->clk_pmu.clk_vf_pointobjs.super.super;
110
111 BOARDOBJGRP_PMU_CONSTRUCT(pboardobjgrp, CLK, CLK_VF_POINT);
112
113 status = BOARDOBJGRP_PMU_CMD_GRP_SET_CONSTRUCT(g, pboardobjgrp,
114 clk, CLK, clk_vf_point, CLK_VF_POINT);
115 if (status) {
116 nvgpu_err(g,
117 "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x",
118 status);
119 goto done;
120 }
121
122 status = BOARDOBJGRP_PMU_CMD_GRP_GET_STATUS_CONSTRUCT(g,
123 &g->clk_pmu.clk_vf_pointobjs.super.super,
124 clk, CLK, clk_vf_point, CLK_VF_POINT);
125 if (status) {
126 nvgpu_err(g,
127 "error constructing PMU_BOARDOBJ_CMD_GRP_SET interface - 0x%x",
128 status);
129 goto done;
130 }
131
132 pboardobjgrp->pmudatainit = _clk_vf_points_pmudatainit;
133 pboardobjgrp->pmudatainstget = _clk_vf_points_pmudata_instget;
134 pboardobjgrp->pmustatusinstget = _clk_vf_points_pmustatus_instget;
135
136done:
137 nvgpu_log_info(g, " done status %x", status);
138 return status;
139}
140
141int clk_vf_point_pmu_setup(struct gk20a *g)
142{
143 int status;
144 struct boardobjgrp *pboardobjgrp = NULL;
145
146 nvgpu_log_info(g, " ");
147
148 pboardobjgrp = &g->clk_pmu.clk_vf_pointobjs.super.super;
149
150 if (!pboardobjgrp->bconstructed) {
151 return -EINVAL;
152 }
153
154 status = pboardobjgrp->pmuinithandle(g, pboardobjgrp);
155
156 nvgpu_log_info(g, "Done");
157 return status;
158}
159
160static int clk_vf_point_construct_super(struct gk20a *g,
161 struct boardobj **ppboardobj,
162 u16 size, void *pargs)
163{
164 struct clk_vf_point *pclkvfpoint;
165 struct clk_vf_point *ptmpvfpoint =
166 (struct clk_vf_point *)pargs;
167 int status = 0;
168
169 status = boardobj_construct_super(g, ppboardobj,
170 size, pargs);
171 if (status) {
172 return -EINVAL;
173 }
174
175 pclkvfpoint = (struct clk_vf_point *)*ppboardobj;
176
177 pclkvfpoint->super.pmudatainit =
178 _clk_vf_point_pmudatainit_super;
179
180 pclkvfpoint->vfe_equ_idx = ptmpvfpoint->vfe_equ_idx;
181 pclkvfpoint->volt_rail_idx = ptmpvfpoint->volt_rail_idx;
182
183 return status;
184}
185
186static int _clk_vf_point_pmudatainit_volt(struct gk20a *g,
187 struct boardobj *board_obj_ptr,
188 struct nv_pmu_boardobj *ppmudata)
189{
190 int status = 0;
191 struct clk_vf_point_volt *pclk_vf_point_volt;
192 struct nv_pmu_clk_clk_vf_point_volt_boardobj_set *pset;
193
194 nvgpu_log_info(g, " ");
195
196 status = _clk_vf_point_pmudatainit_super(g, board_obj_ptr, ppmudata);
197 if (status != 0) {
198 return status;
199 }
200
201 pclk_vf_point_volt =
202 (struct clk_vf_point_volt *)board_obj_ptr;
203
204 pset = (struct nv_pmu_clk_clk_vf_point_volt_boardobj_set *)
205 ppmudata;
206
207 pset->source_voltage_uv = pclk_vf_point_volt->source_voltage_uv;
208 pset->freq_delta.data = pclk_vf_point_volt->freq_delta.data;
209 pset->freq_delta.type = pclk_vf_point_volt->freq_delta.type;
210
211 return status;
212}
213
214static int _clk_vf_point_pmudatainit_freq(struct gk20a *g,
215 struct boardobj *board_obj_ptr,
216 struct nv_pmu_boardobj *ppmudata)
217{
218 int status = 0;
219 struct clk_vf_point_freq *pclk_vf_point_freq;
220 struct nv_pmu_clk_clk_vf_point_freq_boardobj_set *pset;
221
222 nvgpu_log_info(g, " ");
223
224 status = _clk_vf_point_pmudatainit_super(g, board_obj_ptr, ppmudata);
225 if (status != 0) {
226 return status;
227 }
228
229 pclk_vf_point_freq =
230 (struct clk_vf_point_freq *)board_obj_ptr;
231
232 pset = (struct nv_pmu_clk_clk_vf_point_freq_boardobj_set *)
233 ppmudata;
234
235 pset->freq_mhz =
236 clkvfpointfreqmhzget(g, &pclk_vf_point_freq->super);
237
238 pset->volt_delta_uv = pclk_vf_point_freq->volt_delta_uv;
239
240 return status;
241}
242
243static int clk_vf_point_construct_volt(struct gk20a *g,
244 struct boardobj **ppboardobj,
245 u16 size, void *pargs)
246{
247 struct boardobj *ptmpobj = (struct boardobj *)pargs;
248 struct clk_vf_point_volt *pclkvfpoint;
249 struct clk_vf_point_volt *ptmpvfpoint =
250 (struct clk_vf_point_volt *)pargs;
251 int status = 0;
252
253 if (BOARDOBJ_GET_TYPE(pargs) != CTRL_CLK_CLK_VF_POINT_TYPE_VOLT) {
254 return -EINVAL;
255 }
256
257 ptmpobj->type_mask = BIT(CTRL_CLK_CLK_VF_POINT_TYPE_VOLT);
258 status = clk_vf_point_construct_super(g, ppboardobj, size, pargs);
259 if (status) {
260 return -EINVAL;
261 }
262
263 pclkvfpoint = (struct clk_vf_point_volt *)*ppboardobj;
264
265 pclkvfpoint->super.super.pmudatainit =
266 _clk_vf_point_pmudatainit_volt;
267
268 pclkvfpoint->source_voltage_uv = ptmpvfpoint->source_voltage_uv;
269 pclkvfpoint->freq_delta = ptmpvfpoint->freq_delta;
270
271 return status;
272}
273
274static int clk_vf_point_construct_freq(struct gk20a *g,
275 struct boardobj **ppboardobj,
276 u16 size, void *pargs)
277{
278 struct boardobj *ptmpobj = (struct boardobj *)pargs;
279 struct clk_vf_point_freq *pclkvfpoint;
280 struct clk_vf_point_freq *ptmpvfpoint =
281 (struct clk_vf_point_freq *)pargs;
282 int status = 0;
283
284 if (BOARDOBJ_GET_TYPE(pargs) != CTRL_CLK_CLK_VF_POINT_TYPE_FREQ) {
285 return -EINVAL;
286 }
287
288 ptmpobj->type_mask = BIT(CTRL_CLK_CLK_VF_POINT_TYPE_FREQ);
289 status = clk_vf_point_construct_super(g, ppboardobj, size, pargs);
290 if (status) {
291 return -EINVAL;
292 }
293
294 pclkvfpoint = (struct clk_vf_point_freq *)*ppboardobj;
295
296 pclkvfpoint->super.super.pmudatainit =
297 _clk_vf_point_pmudatainit_freq;
298
299 clkvfpointfreqmhzset(g, &pclkvfpoint->super,
300 clkvfpointfreqmhzget(g, &ptmpvfpoint->super));
301
302 return status;
303}
304
305struct clk_vf_point *construct_clk_vf_point(struct gk20a *g, void *pargs)
306{
307 struct boardobj *board_obj_ptr = NULL;
308 int status;
309
310 nvgpu_log_info(g, " ");
311 switch (BOARDOBJ_GET_TYPE(pargs)) {
312 case CTRL_CLK_CLK_VF_POINT_TYPE_FREQ:
313 status = clk_vf_point_construct_freq(g, &board_obj_ptr,
314 sizeof(struct clk_vf_point_freq), pargs);
315 break;
316
317 case CTRL_CLK_CLK_VF_POINT_TYPE_VOLT:
318 status = clk_vf_point_construct_volt(g, &board_obj_ptr,
319 sizeof(struct clk_vf_point_volt), pargs);
320 break;
321
322 default:
323 return NULL;
324 }
325
326 if (status) {
327 return NULL;
328 }
329
330 nvgpu_log_info(g, " Done");
331
332 return (struct clk_vf_point *)board_obj_ptr;
333}
334
335static int _clk_vf_point_pmudatainit_super(struct gk20a *g,
336 struct boardobj *board_obj_ptr,
337 struct nv_pmu_boardobj *ppmudata)
338{
339 int status = 0;
340 struct clk_vf_point *pclk_vf_point;
341 struct nv_pmu_clk_clk_vf_point_boardobj_set *pset;
342
343 nvgpu_log_info(g, " ");
344
345 status = boardobj_pmudatainit_super(g, board_obj_ptr, ppmudata);
346 if (status != 0) {
347 return status;
348 }
349
350 pclk_vf_point =
351 (struct clk_vf_point *)board_obj_ptr;
352
353 pset = (struct nv_pmu_clk_clk_vf_point_boardobj_set *)
354 ppmudata;
355
356
357 pset->vfe_equ_idx = pclk_vf_point->vfe_equ_idx;
358 pset->volt_rail_idx = pclk_vf_point->volt_rail_idx;
359 return status;
360}
361
362
363static int clk_vf_point_update(struct gk20a *g,
364 struct boardobj *board_obj_ptr,
365 struct nv_pmu_boardobj *ppmudata)
366{
367 struct clk_vf_point *pclk_vf_point;
368 struct nv_pmu_clk_clk_vf_point_boardobj_get_status *pstatus;
369
370 nvgpu_log_info(g, " ");
371
372
373 pclk_vf_point =
374 (struct clk_vf_point *)board_obj_ptr;
375
376 pstatus = (struct nv_pmu_clk_clk_vf_point_boardobj_get_status *)
377 ppmudata;
378
379 if (pstatus->super.type != pclk_vf_point->super.type) {
380 nvgpu_err(g,
381 "pmu data and boardobj type not matching");
382 return -EINVAL;
383 }
384 /* now copy VF pair */
385 memcpy(&pclk_vf_point->pair, &pstatus->pair,
386 sizeof(struct ctrl_clk_vf_pair));
387 return 0;
388}
389
390/*get latest vf point data from PMU */
391int clk_vf_point_cache(struct gk20a *g)
392{
393
394 struct clk_vf_points *pclk_vf_points;
395 struct boardobjgrp *pboardobjgrp;
396 struct boardobjgrpmask *pboardobjgrpmask;
397 struct nv_pmu_boardobjgrp_super *pboardobjgrppmu;
398 struct boardobj *pboardobj = NULL;
399 struct nv_pmu_boardobj_query *pboardobjpmustatus = NULL;
400 int status;
401 u8 index;
402
403 nvgpu_log_info(g, " ");
404 pclk_vf_points = &g->clk_pmu.clk_vf_pointobjs;
405 pboardobjgrp = &pclk_vf_points->super.super;
406 pboardobjgrpmask = &pclk_vf_points->super.mask.super;
407
408 status = pboardobjgrp->pmugetstatus(g, pboardobjgrp, pboardobjgrpmask);
409 if (status) {
410 nvgpu_err(g, "err getting boardobjs from pmu");
411 return status;
412 }
413 pboardobjgrppmu = pboardobjgrp->pmu.getstatus.buf;
414
415 BOARDOBJGRP_FOR_EACH(pboardobjgrp, struct boardobj*, pboardobj, index) {
416 status = pboardobjgrp->pmustatusinstget(g,
417 (struct nv_pmu_boardobjgrp *)pboardobjgrppmu,
418 &pboardobjpmustatus, index);
419 if (status) {
420 nvgpu_err(g, "could not get status object instance");
421 return status;
422 }
423
424 status = clk_vf_point_update(g, pboardobj,
425 (struct nv_pmu_boardobj *)pboardobjpmustatus);
426 if (status) {
427 nvgpu_err(g, "invalid data from pmu at %d", index);
428 return status;
429 }
430 }
431
432 return 0;
433}
4 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822













































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
ÐÏࡱá