1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Description:
8 * TC0 Power Model.
9 */
10
11 #include <mod_tc0_power_model.h>
12 #include <mod_thermal_mgmt.h>
13
14 #include <fwk_id.h>
15 #include <fwk_module.h>
16 #include <fwk_module_idx.h>
17
18 #include <stdint.h>
19
tc0_pm_level_to_power(fwk_id_t pm_id,const uint32_t level)20 uint32_t tc0_pm_level_to_power(fwk_id_t pm_id, const uint32_t level)
21 {
22 const struct mod_tc0_power_model_dev_config *config;
23
24 config = fwk_module_get_data(pm_id);
25 return (config->coeff * level);
26 }
27
tc0_pm_power_to_level(fwk_id_t pm_id,const uint32_t power)28 uint32_t tc0_pm_power_to_level(fwk_id_t pm_id, const uint32_t power)
29 {
30 const struct mod_tc0_power_model_dev_config *config;
31
32 config = fwk_module_get_data(pm_id);
33 return (power / config->coeff);
34 }
35
36 static const struct mod_thermal_mgmt_driver_api tc0_thermal_mgmt_driver_api = {
37 .level_to_power = tc0_pm_level_to_power,
38 .power_to_level = tc0_pm_power_to_level,
39 };
40
41 /*
42 * Framework handlers.
43 */
44
tc0_power_model_mod_init(fwk_id_t module_id,unsigned int unused,const void * data)45 static int tc0_power_model_mod_init(
46 fwk_id_t module_id,
47 unsigned int unused,
48 const void *data)
49 {
50 return FWK_SUCCESS;
51 }
52
tc0_power_model_elem_init(fwk_id_t element_id,unsigned int sub_element_count,const void * data)53 static int tc0_power_model_elem_init(
54 fwk_id_t element_id,
55 unsigned int sub_element_count,
56 const void *data)
57 {
58 return FWK_SUCCESS;
59 }
60
tc0_power_model_bind(fwk_id_t id,unsigned int round)61 static int tc0_power_model_bind(fwk_id_t id, unsigned int round)
62 {
63 return FWK_SUCCESS;
64 }
65
tc0_power_model_process_bind_request(fwk_id_t requester_id,fwk_id_t pd_id,fwk_id_t api_id,const void ** api)66 static int tc0_power_model_process_bind_request(
67 fwk_id_t requester_id,
68 fwk_id_t pd_id,
69 fwk_id_t api_id,
70 const void **api)
71 {
72 fwk_id_t power_model_api_id = FWK_ID_API(
73 FWK_MODULE_IDX_TC0_POWER_MODEL,
74 MOD_TC0_POWER_MODEL_THERMAL_DRIVER_API_IDX);
75
76 if (fwk_id_is_equal(api_id, power_model_api_id)) {
77 *api = &tc0_thermal_mgmt_driver_api;
78
79 return FWK_SUCCESS;
80 }
81
82 return FWK_E_ACCESS;
83 }
84
85 const struct fwk_module module_tc0_power_model = {
86 .type = FWK_MODULE_TYPE_DRIVER,
87 .api_count = 1,
88 .init = tc0_power_model_mod_init,
89 .element_init = tc0_power_model_elem_init,
90 .bind = tc0_power_model_bind,
91 .process_bind_request = tc0_power_model_process_bind_request,
92 };
93