1 /*
2 * Copyright (c) 2023 - 2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include "sedi_driver_common.h"
8 #include "sedi_driver_core.h"
9
10 /* counter for vnn_req/vnn_dereq per vnn_id */
11 static uint8_t vnn_req_counter[VNN_ID_TOP];
12
sedi_log(int level,const char * fmt,...)13 void __attribute__((weak)) sedi_log(int level, const char *fmt, ...)
14 {
15 PARAM_UNUSED(level);
16 PARAM_UNUSED(fmt);
17 }
18
19 #ifdef CONFIG_DEBUG
sedi_assert_halt(void)20 void __attribute__((weak)) sedi_assert_halt(void)
21 {
22 while (1)
23 ;
24 }
25 #endif
26
27 /* weak PM functions used by SEDI drivers when SEDI PM driver is not enabled */
28
sedi_pm_set_device_power(IN sedi_devid_t id,IN sedi_power_state_t state)29 void __attribute__((weak)) sedi_pm_set_device_power(IN sedi_devid_t id, IN sedi_power_state_t state)
30 {
31 PARAM_UNUSED(id);
32 PARAM_UNUSED(state);
33 }
34
sedi_pm_get_device_power(IN sedi_devid_t id)35 sedi_power_state_t __attribute__((weak)) sedi_pm_get_device_power(IN sedi_devid_t id)
36 {
37 PARAM_UNUSED(id);
38
39 return SEDI_POWER_FULL;
40 }
41
PM_VNN_DRIVER_REQ(vnn_id_t vnn_id)42 void PM_VNN_DRIVER_REQ(vnn_id_t vnn_id)
43 {
44 unsigned int key = sedi_core_irq_lock();
45
46 if (!vnn_req_counter[vnn_id])
47 write32(PMU_VNN_REQ_31_0, BIT(vnn_id));
48 ++vnn_req_counter[vnn_id];
49
50 sedi_core_irq_unlock(key);
51
52 while (!(read32(PMU_VNN_REQ_ACK) & PMU_VNN_REQ_ACK_STS))
53 ;
54 }
55
PM_VNN_DRIVER_DEREQ(vnn_id_t vnn_id)56 void PM_VNN_DRIVER_DEREQ(vnn_id_t vnn_id)
57 {
58 unsigned int key = sedi_core_irq_lock();
59
60 if (vnn_req_counter[vnn_id] == 0) {
61 goto out;
62 }
63 vnn_req_counter[vnn_id]--;
64 if (vnn_req_counter[vnn_id] != 0) {
65 goto out;
66 }
67
68 write32(PMU_VNN_REQ_31_0, BIT(vnn_id));
69 write32(PMU_VNN_REQ_ACK, read32(PMU_VNN_REQ_ACK));
70 out:
71 sedi_core_irq_unlock(key);
72 }
73
PM_VNN_ALL_RESET(void)74 void PM_VNN_ALL_RESET(void)
75 {
76 unsigned int key = sedi_core_irq_lock();
77
78 write32(PMU_VNN_REQ_31_0, read32(PMU_VNN_REQ_31_0));
79 write32(PMU_VNN_REQ_ACK, read32(PMU_VNN_REQ_ACK));
80
81 for (int i = 0; i < VNN_ID_TOP; i++) {
82 vnn_req_counter[i] = 0;
83 }
84
85 sedi_core_irq_unlock(key);
86 }
87
PM_VNN_DRIVER_RESET(vnn_id_t vnn_id)88 void PM_VNN_DRIVER_RESET(vnn_id_t vnn_id)
89 {
90 unsigned int key = sedi_core_irq_lock();
91
92 write32(PMU_VNN_REQ_31_0, read32(PMU_VNN_REQ_31_0) & BIT(vnn_id));
93 vnn_req_counter[vnn_id] = 0;
94
95 sedi_core_irq_unlock(key);
96 }
97