blob: 2764bd32703415064d9456f1ddd469773f5b7112 [file] [log] [blame]
Alex Deucher1f7371b2015-12-02 17:46:21 -05001/*
2 * Copyright 2015 Advanced Micro Devices, Inc.
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 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.
21 *
22 */
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/gfp.h>
Jammy Zhouac885b32015-07-21 17:43:02 +080026#include <linux/slab.h>
Alex Deucher1f7371b2015-12-02 17:46:21 -050027#include "amd_shared.h"
28#include "amd_powerplay.h"
Jammy Zhouac885b32015-07-21 17:43:02 +080029#include "pp_instance.h"
Rex Zhu577bbe02015-08-28 12:56:43 +080030#include "power_state.h"
31#include "eventmanager.h"
Alex Deucher1f7371b2015-12-02 17:46:21 -050032
Rex Zhua969e162015-12-29 13:56:03 +080033#define PP_CHECK(handle) \
34 do { \
35 if ((handle) == NULL || (handle)->pp_valid != PP_VALID) \
36 return -EINVAL; \
37 } while (0)
38
Alex Deucher1f7371b2015-12-02 17:46:21 -050039static int pp_early_init(void *handle)
40{
41 return 0;
42}
43
44static int pp_sw_init(void *handle)
45{
Jammy Zhou3bace352015-07-21 21:18:15 +080046 struct pp_instance *pp_handle;
47 struct pp_hwmgr *hwmgr;
48 int ret = 0;
49
50 if (handle == NULL)
51 return -EINVAL;
52
53 pp_handle = (struct pp_instance *)handle;
54 hwmgr = pp_handle->hwmgr;
55
56 if (hwmgr == NULL || hwmgr->pptable_func == NULL ||
57 hwmgr->hwmgr_func == NULL ||
58 hwmgr->pptable_func->pptable_init == NULL ||
59 hwmgr->hwmgr_func->backend_init == NULL)
60 return -EINVAL;
61
62 ret = hwmgr->pptable_func->pptable_init(hwmgr);
Rex Zhue92a0372015-09-23 15:14:54 +080063
Jammy Zhou3bace352015-07-21 21:18:15 +080064 if (ret == 0)
65 ret = hwmgr->hwmgr_func->backend_init(hwmgr);
66
67 return ret;
Alex Deucher1f7371b2015-12-02 17:46:21 -050068}
69
70static int pp_sw_fini(void *handle)
71{
Jammy Zhou3bace352015-07-21 21:18:15 +080072 struct pp_instance *pp_handle;
73 struct pp_hwmgr *hwmgr;
74 int ret = 0;
75
76 if (handle == NULL)
77 return -EINVAL;
78
79 pp_handle = (struct pp_instance *)handle;
80 hwmgr = pp_handle->hwmgr;
81
82 if (hwmgr != NULL || hwmgr->hwmgr_func != NULL ||
83 hwmgr->hwmgr_func->backend_fini != NULL)
84 ret = hwmgr->hwmgr_func->backend_fini(hwmgr);
85
86 return ret;
Alex Deucher1f7371b2015-12-02 17:46:21 -050087}
88
89static int pp_hw_init(void *handle)
90{
Jammy Zhouac885b32015-07-21 17:43:02 +080091 struct pp_instance *pp_handle;
92 struct pp_smumgr *smumgr;
Rex Zhue92a0372015-09-23 15:14:54 +080093 struct pp_eventmgr *eventmgr;
Jammy Zhouac885b32015-07-21 17:43:02 +080094 int ret = 0;
95
96 if (handle == NULL)
97 return -EINVAL;
98
99 pp_handle = (struct pp_instance *)handle;
100 smumgr = pp_handle->smu_mgr;
101
102 if (smumgr == NULL || smumgr->smumgr_funcs == NULL ||
103 smumgr->smumgr_funcs->smu_init == NULL ||
104 smumgr->smumgr_funcs->start_smu == NULL)
105 return -EINVAL;
106
107 ret = smumgr->smumgr_funcs->smu_init(smumgr);
108 if (ret) {
109 printk(KERN_ERR "[ powerplay ] smc initialization failed\n");
110 return ret;
111 }
112
113 ret = smumgr->smumgr_funcs->start_smu(smumgr);
114 if (ret) {
115 printk(KERN_ERR "[ powerplay ] smc start failed\n");
116 smumgr->smumgr_funcs->smu_fini(smumgr);
117 return ret;
118 }
Jammy Zhou3bace352015-07-21 21:18:15 +0800119
Rex Zhue92a0372015-09-23 15:14:54 +0800120 hw_init_power_state_table(pp_handle->hwmgr);
121 eventmgr = pp_handle->eventmgr;
122
123 if (eventmgr == NULL || eventmgr->pp_eventmgr_init == NULL)
124 return -EINVAL;
125
126 ret = eventmgr->pp_eventmgr_init(eventmgr);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500127 return 0;
128}
129
130static int pp_hw_fini(void *handle)
131{
Jammy Zhouac885b32015-07-21 17:43:02 +0800132 struct pp_instance *pp_handle;
133 struct pp_smumgr *smumgr;
Rex Zhue92a0372015-09-23 15:14:54 +0800134 struct pp_eventmgr *eventmgr;
Jammy Zhouac885b32015-07-21 17:43:02 +0800135
136 if (handle == NULL)
137 return -EINVAL;
138
139 pp_handle = (struct pp_instance *)handle;
Rex Zhue92a0372015-09-23 15:14:54 +0800140 eventmgr = pp_handle->eventmgr;
141
142 if (eventmgr != NULL || eventmgr->pp_eventmgr_fini != NULL)
143 eventmgr->pp_eventmgr_fini(eventmgr);
144
Jammy Zhouac885b32015-07-21 17:43:02 +0800145 smumgr = pp_handle->smu_mgr;
146
147 if (smumgr != NULL || smumgr->smumgr_funcs != NULL ||
148 smumgr->smumgr_funcs->smu_fini != NULL)
149 smumgr->smumgr_funcs->smu_fini(smumgr);
150
Alex Deucher1f7371b2015-12-02 17:46:21 -0500151 return 0;
152}
153
154static bool pp_is_idle(void *handle)
155{
156 return 0;
157}
158
159static int pp_wait_for_idle(void *handle)
160{
161 return 0;
162}
163
164static int pp_sw_reset(void *handle)
165{
166 return 0;
167}
168
169static void pp_print_status(void *handle)
170{
171
172}
173
174static int pp_set_clockgating_state(void *handle,
175 enum amd_clockgating_state state)
176{
177 return 0;
178}
179
180static int pp_set_powergating_state(void *handle,
181 enum amd_powergating_state state)
182{
183 return 0;
184}
185
186static int pp_suspend(void *handle)
187{
Rex Zhu577bbe02015-08-28 12:56:43 +0800188 struct pp_instance *pp_handle;
189 struct pp_eventmgr *eventmgr;
190 struct pem_event_data event_data = { {0} };
191
192 if (handle == NULL)
193 return -EINVAL;
194
195 pp_handle = (struct pp_instance *)handle;
196 eventmgr = pp_handle->eventmgr;
197 pem_handle_event(eventmgr, AMD_PP_EVENT_SUSPEND, &event_data);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500198 return 0;
199}
200
201static int pp_resume(void *handle)
202{
Rex Zhu577bbe02015-08-28 12:56:43 +0800203 struct pp_instance *pp_handle;
204 struct pp_eventmgr *eventmgr;
205 struct pem_event_data event_data = { {0} };
206
207 if (handle == NULL)
208 return -EINVAL;
209
210 pp_handle = (struct pp_instance *)handle;
211 eventmgr = pp_handle->eventmgr;
212 pem_handle_event(eventmgr, AMD_PP_EVENT_RESUME, &event_data);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500213 return 0;
214}
215
216const struct amd_ip_funcs pp_ip_funcs = {
217 .early_init = pp_early_init,
218 .late_init = NULL,
219 .sw_init = pp_sw_init,
220 .sw_fini = pp_sw_fini,
221 .hw_init = pp_hw_init,
222 .hw_fini = pp_hw_fini,
223 .suspend = pp_suspend,
224 .resume = pp_resume,
225 .is_idle = pp_is_idle,
226 .wait_for_idle = pp_wait_for_idle,
227 .soft_reset = pp_sw_reset,
228 .print_status = pp_print_status,
229 .set_clockgating_state = pp_set_clockgating_state,
230 .set_powergating_state = pp_set_powergating_state,
231};
232
233static int pp_dpm_load_fw(void *handle)
234{
235 return 0;
236}
237
238static int pp_dpm_fw_loading_complete(void *handle)
239{
240 return 0;
241}
242
243static int pp_dpm_force_performance_level(void *handle,
244 enum amd_dpm_forced_level level)
245{
Rex Zhu577bbe02015-08-28 12:56:43 +0800246 struct pp_instance *pp_handle;
247 struct pp_hwmgr *hwmgr;
248
249 if (handle == NULL)
250 return -EINVAL;
251
252 pp_handle = (struct pp_instance *)handle;
253
254 hwmgr = pp_handle->hwmgr;
255
256 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
257 hwmgr->hwmgr_func->force_dpm_level == NULL)
258 return -EINVAL;
259
260 hwmgr->hwmgr_func->force_dpm_level(hwmgr, level);
261
Alex Deucher1f7371b2015-12-02 17:46:21 -0500262 return 0;
263}
Rex Zhu577bbe02015-08-28 12:56:43 +0800264
Alex Deucher1f7371b2015-12-02 17:46:21 -0500265static enum amd_dpm_forced_level pp_dpm_get_performance_level(
266 void *handle)
267{
Rex Zhu577bbe02015-08-28 12:56:43 +0800268 struct pp_hwmgr *hwmgr;
269
270 if (handle == NULL)
271 return -EINVAL;
272
273 hwmgr = ((struct pp_instance *)handle)->hwmgr;
274
275 if (hwmgr == NULL)
276 return -EINVAL;
277
278 return (((struct pp_instance *)handle)->hwmgr->dpm_level);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500279}
Rex Zhu577bbe02015-08-28 12:56:43 +0800280
Alex Deucher1f7371b2015-12-02 17:46:21 -0500281static int pp_dpm_get_sclk(void *handle, bool low)
282{
Rex Zhu577bbe02015-08-28 12:56:43 +0800283 struct pp_hwmgr *hwmgr;
284
285 if (handle == NULL)
286 return -EINVAL;
287
288 hwmgr = ((struct pp_instance *)handle)->hwmgr;
289
290 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
291 hwmgr->hwmgr_func->get_sclk == NULL)
292 return -EINVAL;
293
294 return hwmgr->hwmgr_func->get_sclk(hwmgr, low);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500295}
Rex Zhu577bbe02015-08-28 12:56:43 +0800296
Alex Deucher1f7371b2015-12-02 17:46:21 -0500297static int pp_dpm_get_mclk(void *handle, bool low)
298{
Rex Zhu577bbe02015-08-28 12:56:43 +0800299 struct pp_hwmgr *hwmgr;
300
301 if (handle == NULL)
302 return -EINVAL;
303
304 hwmgr = ((struct pp_instance *)handle)->hwmgr;
305
306 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
307 hwmgr->hwmgr_func->get_mclk == NULL)
308 return -EINVAL;
309
310 return hwmgr->hwmgr_func->get_mclk(hwmgr, low);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500311}
Rex Zhu577bbe02015-08-28 12:56:43 +0800312
Alex Deucher1f7371b2015-12-02 17:46:21 -0500313static int pp_dpm_powergate_vce(void *handle, bool gate)
314{
Rex Zhu577bbe02015-08-28 12:56:43 +0800315 struct pp_hwmgr *hwmgr;
316
317 if (handle == NULL)
318 return -EINVAL;
319
320 hwmgr = ((struct pp_instance *)handle)->hwmgr;
321
322 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
323 hwmgr->hwmgr_func->powergate_vce == NULL)
324 return -EINVAL;
325
326 return hwmgr->hwmgr_func->powergate_vce(hwmgr, gate);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500327}
Rex Zhu577bbe02015-08-28 12:56:43 +0800328
Alex Deucher1f7371b2015-12-02 17:46:21 -0500329static int pp_dpm_powergate_uvd(void *handle, bool gate)
330{
Rex Zhu577bbe02015-08-28 12:56:43 +0800331 struct pp_hwmgr *hwmgr;
332
333 if (handle == NULL)
334 return -EINVAL;
335
336 hwmgr = ((struct pp_instance *)handle)->hwmgr;
337
338 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
339 hwmgr->hwmgr_func->powergate_uvd == NULL)
340 return -EINVAL;
341
342 return hwmgr->hwmgr_func->powergate_uvd(hwmgr, gate);
343}
344
345static enum PP_StateUILabel power_state_convert(enum amd_pm_state_type state)
346{
347 switch (state) {
348 case POWER_STATE_TYPE_BATTERY:
349 return PP_StateUILabel_Battery;
350 case POWER_STATE_TYPE_BALANCED:
351 return PP_StateUILabel_Balanced;
352 case POWER_STATE_TYPE_PERFORMANCE:
353 return PP_StateUILabel_Performance;
354 default:
355 return PP_StateUILabel_None;
356 }
Alex Deucher1f7371b2015-12-02 17:46:21 -0500357}
358
359int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, void *input, void *output)
360{
Rex Zhu577bbe02015-08-28 12:56:43 +0800361 int ret = 0;
362 struct pp_instance *pp_handle;
363 struct pem_event_data data = { {0} };
364
365 pp_handle = (struct pp_instance *)handle;
366
367 if (pp_handle == NULL)
368 return -EINVAL;
369
370 switch (event_id) {
371 case AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE:
372 ret = pem_handle_event(pp_handle->eventmgr, event_id, &data);
373 break;
374 case AMD_PP_EVENT_ENABLE_USER_STATE:
375 {
376 enum amd_pm_state_type ps;
377
378 if (input == NULL)
379 return -EINVAL;
380 ps = *(unsigned long *)input;
381
382 data.requested_ui_label = power_state_convert(ps);
383 ret = pem_handle_event(pp_handle->eventmgr, event_id, &data);
384 }
385 break;
386 default:
387 break;
388 }
389 return ret;
Alex Deucher1f7371b2015-12-02 17:46:21 -0500390}
Rex Zhu577bbe02015-08-28 12:56:43 +0800391
Alex Deucher1f7371b2015-12-02 17:46:21 -0500392enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
393{
Rex Zhu577bbe02015-08-28 12:56:43 +0800394 struct pp_hwmgr *hwmgr;
395 struct pp_power_state *state;
396
397 if (handle == NULL)
398 return -EINVAL;
399
400 hwmgr = ((struct pp_instance *)handle)->hwmgr;
401
402 if (hwmgr == NULL || hwmgr->current_ps == NULL)
403 return -EINVAL;
404
405 state = hwmgr->current_ps;
406
407 switch (state->classification.ui_label) {
408 case PP_StateUILabel_Battery:
409 return POWER_STATE_TYPE_BATTERY;
410 case PP_StateUILabel_Balanced:
411 return POWER_STATE_TYPE_BALANCED;
412 case PP_StateUILabel_Performance:
413 return POWER_STATE_TYPE_PERFORMANCE;
414 default:
415 return POWER_STATE_TYPE_DEFAULT;
416 }
Alex Deucher1f7371b2015-12-02 17:46:21 -0500417}
Rex Zhu577bbe02015-08-28 12:56:43 +0800418
Alex Deucher1f7371b2015-12-02 17:46:21 -0500419static void
420pp_debugfs_print_current_performance_level(void *handle,
421 struct seq_file *m)
422{
Rex Zhu577bbe02015-08-28 12:56:43 +0800423 struct pp_hwmgr *hwmgr;
424
425 if (handle == NULL)
426 return;
427
428 hwmgr = ((struct pp_instance *)handle)->hwmgr;
429
430 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
431 hwmgr->hwmgr_func->print_current_perforce_level == NULL)
432 return;
433
434 hwmgr->hwmgr_func->print_current_perforce_level(hwmgr, m);
Alex Deucher1f7371b2015-12-02 17:46:21 -0500435}
Jammy Zhou3bace352015-07-21 21:18:15 +0800436
Rex Zhucac9a192015-10-16 11:48:21 +0800437static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
438{
439 struct pp_hwmgr *hwmgr;
440
441 if (handle == NULL)
442 return -EINVAL;
443
444 hwmgr = ((struct pp_instance *)handle)->hwmgr;
445
446 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
447 hwmgr->hwmgr_func->set_fan_control_mode == NULL)
448 return -EINVAL;
449
450 return hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
451}
452
453static int pp_dpm_get_fan_control_mode(void *handle)
454{
455 struct pp_hwmgr *hwmgr;
456
457 if (handle == NULL)
458 return -EINVAL;
459
460 hwmgr = ((struct pp_instance *)handle)->hwmgr;
461
462 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
463 hwmgr->hwmgr_func->get_fan_control_mode == NULL)
464 return -EINVAL;
465
466 return hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
467}
468
469static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent)
470{
471 struct pp_hwmgr *hwmgr;
472
473 if (handle == NULL)
474 return -EINVAL;
475
476 hwmgr = ((struct pp_instance *)handle)->hwmgr;
477
478 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
479 hwmgr->hwmgr_func->set_fan_speed_percent == NULL)
480 return -EINVAL;
481
482 return hwmgr->hwmgr_func->set_fan_speed_percent(hwmgr, percent);
483}
484
485static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed)
486{
487 struct pp_hwmgr *hwmgr;
488
489 if (handle == NULL)
490 return -EINVAL;
491
492 hwmgr = ((struct pp_instance *)handle)->hwmgr;
493
494 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
495 hwmgr->hwmgr_func->get_fan_speed_percent == NULL)
496 return -EINVAL;
497
498 return hwmgr->hwmgr_func->get_fan_speed_percent(hwmgr, speed);
499}
500
501static int pp_dpm_get_temperature(void *handle)
502{
503 struct pp_hwmgr *hwmgr;
504
505 if (handle == NULL)
506 return -EINVAL;
507
508 hwmgr = ((struct pp_instance *)handle)->hwmgr;
509
510 if (hwmgr == NULL || hwmgr->hwmgr_func == NULL ||
511 hwmgr->hwmgr_func->get_temperature == NULL)
512 return -EINVAL;
513
514 return hwmgr->hwmgr_func->get_temperature(hwmgr);
515}
Rex Zhu577bbe02015-08-28 12:56:43 +0800516
Alex Deucher1f7371b2015-12-02 17:46:21 -0500517const struct amd_powerplay_funcs pp_dpm_funcs = {
Rex Zhucac9a192015-10-16 11:48:21 +0800518 .get_temperature = pp_dpm_get_temperature,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500519 .load_firmware = pp_dpm_load_fw,
520 .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
521 .force_performance_level = pp_dpm_force_performance_level,
522 .get_performance_level = pp_dpm_get_performance_level,
523 .get_current_power_state = pp_dpm_get_current_power_state,
524 .get_sclk = pp_dpm_get_sclk,
525 .get_mclk = pp_dpm_get_mclk,
526 .powergate_vce = pp_dpm_powergate_vce,
527 .powergate_uvd = pp_dpm_powergate_uvd,
528 .dispatch_tasks = pp_dpm_dispatch_tasks,
529 .print_current_performance_level = pp_debugfs_print_current_performance_level,
Rex Zhucac9a192015-10-16 11:48:21 +0800530 .set_fan_control_mode = pp_dpm_set_fan_control_mode,
531 .get_fan_control_mode = pp_dpm_get_fan_control_mode,
532 .set_fan_speed_percent = pp_dpm_set_fan_speed_percent,
533 .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
Alex Deucher1f7371b2015-12-02 17:46:21 -0500534};
535
Jammy Zhouac885b32015-07-21 17:43:02 +0800536static int amd_pp_instance_init(struct amd_pp_init *pp_init,
537 struct amd_powerplay *amd_pp)
538{
539 int ret;
540 struct pp_instance *handle;
541
542 handle = kzalloc(sizeof(struct pp_instance), GFP_KERNEL);
543 if (handle == NULL)
544 return -ENOMEM;
545
Rex Zhua969e162015-12-29 13:56:03 +0800546 handle->pp_valid = PP_VALID;
547
Jammy Zhouac885b32015-07-21 17:43:02 +0800548 ret = smum_init(pp_init, handle);
549 if (ret)
Jammy Zhou3bace352015-07-21 21:18:15 +0800550 goto fail_smum;
551
552 ret = hwmgr_init(pp_init, handle);
553 if (ret)
554 goto fail_hwmgr;
Jammy Zhouac885b32015-07-21 17:43:02 +0800555
Rex Zhue92a0372015-09-23 15:14:54 +0800556 ret = eventmgr_init(handle);
557 if (ret)
558 goto fail_eventmgr;
559
Jammy Zhouac885b32015-07-21 17:43:02 +0800560 amd_pp->pp_handle = handle;
561 return 0;
Jammy Zhou3bace352015-07-21 21:18:15 +0800562
Rex Zhue92a0372015-09-23 15:14:54 +0800563fail_eventmgr:
564 hwmgr_fini(handle->hwmgr);
Jammy Zhou3bace352015-07-21 21:18:15 +0800565fail_hwmgr:
566 smum_fini(handle->smu_mgr);
567fail_smum:
568 kfree(handle);
569 return ret;
Jammy Zhouac885b32015-07-21 17:43:02 +0800570}
571
572static int amd_pp_instance_fini(void *handle)
573{
574 struct pp_instance *instance = (struct pp_instance *)handle;
Rex Zhue92a0372015-09-23 15:14:54 +0800575
Jammy Zhouac885b32015-07-21 17:43:02 +0800576 if (instance == NULL)
577 return -EINVAL;
578
Rex Zhue92a0372015-09-23 15:14:54 +0800579 eventmgr_fini(instance->eventmgr);
580
Jammy Zhou3bace352015-07-21 21:18:15 +0800581 hwmgr_fini(instance->hwmgr);
582
Jammy Zhouac885b32015-07-21 17:43:02 +0800583 smum_fini(instance->smu_mgr);
584
585 kfree(handle);
586 return 0;
587}
588
Alex Deucher1f7371b2015-12-02 17:46:21 -0500589int amd_powerplay_init(struct amd_pp_init *pp_init,
590 struct amd_powerplay *amd_pp)
591{
Jammy Zhouac885b32015-07-21 17:43:02 +0800592 int ret;
593
Alex Deucher1f7371b2015-12-02 17:46:21 -0500594 if (pp_init == NULL || amd_pp == NULL)
595 return -EINVAL;
596
Jammy Zhouac885b32015-07-21 17:43:02 +0800597 ret = amd_pp_instance_init(pp_init, amd_pp);
598
599 if (ret)
600 return ret;
601
Alex Deucher1f7371b2015-12-02 17:46:21 -0500602 amd_pp->ip_funcs = &pp_ip_funcs;
603 amd_pp->pp_funcs = &pp_dpm_funcs;
604
605 return 0;
606}
607
608int amd_powerplay_fini(void *handle)
609{
Jammy Zhouac885b32015-07-21 17:43:02 +0800610 amd_pp_instance_fini(handle);
611
Alex Deucher1f7371b2015-12-02 17:46:21 -0500612 return 0;
613}
Rex Zhu7fb72a12015-11-19 13:35:30 +0800614
615/* export this function to DAL */
616
617int amd_powerplay_display_configuration_change(void *handle, const void *input)
618{
619 struct pp_hwmgr *hwmgr;
620 const struct amd_pp_display_configuration *display_config = input;
621
Rex Zhua969e162015-12-29 13:56:03 +0800622 PP_CHECK((struct pp_instance *)handle);
Rex Zhu7fb72a12015-11-19 13:35:30 +0800623
624 hwmgr = ((struct pp_instance *)handle)->hwmgr;
625
626 phm_store_dal_configuration_data(hwmgr, display_config);
627 return 0;
628}
Vitaly Prosyakc4dd2062015-11-30 16:39:53 -0500629
Vitaly Prosyak1c9a9082015-12-03 10:27:57 -0500630int amd_powerplay_get_display_power_level(void *handle,
631 struct amd_pp_dal_clock_info *output)
Vitaly Prosyakc4dd2062015-11-30 16:39:53 -0500632{
633 struct pp_hwmgr *hwmgr;
634
Rex Zhua969e162015-12-29 13:56:03 +0800635 PP_CHECK((struct pp_instance *)handle);
636
637 if (output == NULL)
Vitaly Prosyakc4dd2062015-11-30 16:39:53 -0500638 return -EINVAL;
639
640 hwmgr = ((struct pp_instance *)handle)->hwmgr;
641
Vitaly Prosyak1c9a9082015-12-03 10:27:57 -0500642 return phm_get_dal_power_level(hwmgr, output);
Vitaly Prosyakc4dd2062015-11-30 16:39:53 -0500643}