1 /*
2 * Copyright (c) 2023 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] != 0) {
47 goto out;
48 }
49
50 SEDI_ASSERT((read32(PMU_VNN_REQ_31_0) & BIT(vnn_id)) == 0);
51 write32(PMU_VNN_REQ_31_0, BIT(vnn_id));
52 while (!(read32(PMU_VNN_REQ_ACK) & PMU_VNN_REQ_ACK_STS))
53 ;
54 out:
55 vnn_req_counter[vnn_id]++;
56 sedi_core_irq_unlock(key);
57 }
58
PM_VNN_DRIVER_DEREQ(vnn_id_t vnn_id)59 void PM_VNN_DRIVER_DEREQ(vnn_id_t vnn_id)
60 {
61 unsigned int key = sedi_core_irq_lock();
62
63 if (vnn_req_counter[vnn_id] == 0) {
64 goto out;
65 }
66 vnn_req_counter[vnn_id]--;
67 if (vnn_req_counter[vnn_id] != 0) {
68 goto out;
69 }
70
71 write32(PMU_VNN_REQ_31_0, BIT(vnn_id));
72 write32(PMU_VNN_REQ_ACK, read32(PMU_VNN_REQ_ACK));
73 out:
74 sedi_core_irq_unlock(key);
75 }
76
PM_VNN_ALL_RESET(void)77 void PM_VNN_ALL_RESET(void)
78 {
79 unsigned int key = sedi_core_irq_lock();
80
81 write32(PMU_VNN_REQ_31_0, read32(PMU_VNN_REQ_31_0));
82 write32(PMU_VNN_REQ_ACK, read32(PMU_VNN_REQ_ACK));
83
84 for (int i = 0; i < VNN_ID_TOP; i++) {
85 vnn_req_counter[i] = 0;
86 }
87
88 sedi_core_irq_unlock(key);
89 }
90
PM_VNN_DRIVER_RESET(vnn_id_t vnn_id)91 void PM_VNN_DRIVER_RESET(vnn_id_t vnn_id)
92 {
93 unsigned int key = sedi_core_irq_lock();
94
95 write32(PMU_VNN_REQ_31_0, read32(PMU_VNN_REQ_31_0) & BIT(vnn_id));
96 vnn_req_counter[vnn_id] = 0;
97
98 sedi_core_irq_unlock(key);
99 }
100