1 /*
2  * Copyright (c) 2023 Intel Corporation
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _SEDI_SOC_H_
8 #define _SEDI_SOC_H_
9 
10 #define SEDI_CONFIG_ARCH_X86	(1)
11 
12 #if defined(CONFIG_ISH_PLATFORM_FPGA)
13 /* ISH SoC clock is lower on FPGA than Silicon */
14 #define SEDI_SOC_CLK_DIVISOR (5)
15 #endif
16 
17 #ifndef SEDI_SOC_CLK_DIVISOR
18 #define SEDI_SOC_CLK_DIVISOR (1)
19 #endif
20 
21 #ifndef ISH_CONFIG_HBW_CLK_DIVIDER
22 #define ISH_CONFIG_HBW_CLK_DIVIDER (1)
23 #endif
24 
25 #define SEDI_RTC_BASE_FREQ (32768)
26 #define SEDI_RTC_TICKS_PER_SECOND (SEDI_RTC_BASE_FREQ / SEDI_SOC_CLK_DIVISOR)
27 #define SEDI_RTC_TICKS2US(ticks) (ticks * 1000000 * SEDI_SOC_CLK_DIVISOR \
28 		/ SEDI_RTC_BASE_FREQ)
29 
30 #define SEDI_MHZ_TO_HZ(mhz) ((mhz) * 1000000)
31 
32 #ifndef ISH_CONFIG_CLK_FREQUENCY_MHZ
33 #define ISH_CONFIG_CLK_FREQUENCY_MHZ (100 / SEDI_SOC_CLK_DIVISOR)
34 #endif
35 
36 /*!
37  * \defgroup sedi_soc_ish Intel ISH SoC
38  */
39 
40 /*!
41  * \fn uint32_t sedi_pm_get_hbw_clock(void)
42  * \brief Get current HBW clock frequency
43  * \return uint32_t current HBW clock frequency
44  * \ingroup sedi_soc_ish
45  */
sedi_pm_get_hbw_clock(void)46 static inline uint32_t sedi_pm_get_hbw_clock(void)
47 {
48 	return SEDI_MHZ_TO_HZ(ISH_CONFIG_CLK_FREQUENCY_MHZ /
49 			ISH_CONFIG_HBW_CLK_DIVIDER);
50 }
51 
52 /*!
53  * \fn uint32_t sedi_pm_get_lbw_clock(void)
54  * \brief Get current LBW clock frequency
55  * \return uint32_t current LBW clock frequency
56  * \ingroup sedi_soc_ish
57  */
sedi_pm_get_lbw_clock(void)58 static inline uint32_t sedi_pm_get_lbw_clock(void)
59 {
60 	return SEDI_MHZ_TO_HZ(ISH_CONFIG_CLK_FREQUENCY_MHZ);
61 }
62 
63 /*!
64  * \enum vnn_id_t
65  * \brief VNN ID bit for different drivers
66  * \ingroup sedi_soc_ish
67  */
68 typedef enum {
69 	VNN_ID_FIRST = 0,
70 	VNN_ID_AON_TASK = VNN_ID_FIRST,
71 	VNN_ID_IPC_HOST_W,
72 	VNN_ID_IPC_HOST_R,
73 	VNN_ID_IPC_CSME_W,
74 	VNN_ID_IPC_CSME_R,
75 	VNN_ID_IPC_PMC_W = 5,
76 	VNN_ID_IPC_PMC_R,
77 	VNN_ID_DMA0,
78 	VNN_ID_SIDEBAND,
79 	VNN_ID_TOP,
80 } vnn_id_t;
81 
82 #define VNN_ID_IPC_CSE_R VNN_ID_IPC_CSME_R
83 #define VNN_ID_IPC_CSE_W VNN_ID_IPC_CSME_W
84 
85 #ifndef SEDI_PMU_BASE
86 #define SEDI_PMU_BASE (0x04200000)
87 #endif
88 
89 #define PMU_VNN_REQ_31_0 (SEDI_PMU_BASE + 0x3c)
90 #define PMU_VNN_REQ_ACK (SEDI_PMU_BASE + 0x40)
91 #define PMU_VNN_REQ_ACK_STS BIT(0)
92 
93 /*!
94  * \enum sedi_devid_t
95  * \brief SEDI device ID table
96  * \ingroup sedi_soc_ish
97  */
98 typedef enum {
99 	SEDI_DEVID_FIRST = 0,
100 	SEDI_DEVID_I2C0 = SEDI_DEVID_FIRST,
101 	SEDI_DEVID_I2C1,
102 	SEDI_DEVID_I2C2,
103 	SEDI_DEVID_UART0,
104 	SEDI_DEVID_UART1,
105 	SEDI_DEVID_UART2,
106 	SEDI_DEVID_GPIO0,
107 	SEDI_DEVID_DMA0,
108 	SEDI_DEVID_SPI0,
109 	SEDI_DEVID_SPI1,
110 	SEDI_DEVID_TOP
111 } sedi_devid_t;
112 
113 /*!
114  * peripheral device id for dma handshake
115  */
116 typedef enum {
117 	DMA_HWID_I2C0_RX = 0,
118 	DMA_HWID_I2C0_TX = 1,
119 	DMA_HWID_I2C1_RX = 2,
120 	DMA_HWID_I2C1_TX = 3,
121 	DMA_HWID_I2C2_RX = 4,
122 	DMA_HWID_I2C2_TX = 5,
123 	DMA_HWID_UART0_RX = 6,
124 	DMA_HWID_UART0_TX = 7,
125 	DMA_HWID_UART1_RX = 8,
126 	DMA_HWID_UART1_TX = 9,
127 	DMA_HWID_UART2_RX = 10,
128 	DMA_HWID_UART2_TX = 11,
129 	DMA_HWID_SPI0_RX = 12,
130 	DMA_HWID_SPI0_TX = 13,
131 	DMA_HWID_SPI1_RX = 14,
132 	DMA_HWID_SPI1_TX = 15,
133 } dma_hs_per_dev_id_t;
134 
135 /*!
136  * \brief check if a device is owned by SoC itself
137  * \param[in] dev: device id to check
138  * \return true/false
139  * \ingroup sedi_soc_ish
140  */
sedi_dev_is_self_owned(sedi_devid_t dev)141 static inline bool sedi_dev_is_self_owned(sedi_devid_t dev)
142 {
143 	(void)dev;
144 
145 	return true;
146 }
147 
148 /*!
149  * \brief Request VNN for a device
150  * \param[in] vnn_id: device id
151  * \return void
152  * \ingroup sedi_soc_ish
153  */
154 void PM_VNN_DRIVER_REQ(vnn_id_t vnn_id);
155 
156 /*!
157  * \brief De-request VNN for a device
158  * \param[in] vnn_id: device id
159  * \return void
160  * \ingroup sedi_soc_ish
161  */
162 void PM_VNN_DRIVER_DEREQ(vnn_id_t vnn_id);
163 
164 /*!
165  * \brief Reset VNN for all devices
166  * \return void
167  * \ingroup sedi_soc_ish
168  */
169 void PM_VNN_ALL_RESET(void);
170 
171 /*!
172  * \brief Reset VNN for a device
173  * \param[in] vnn_id: device id
174  * \return void
175  * \ingroup sedi_soc_ish
176  */
177 void PM_VNN_DRIVER_RESET(vnn_id_t vnn_id);
178 
179 #endif
180