xref: /openbmc/linux/include/linux/soc/qcom/geni-se.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1491581f4SElliot Berman /* SPDX-License-Identifier: GPL-2.0 */
2491581f4SElliot Berman /*
3491581f4SElliot Berman  * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
4491581f4SElliot Berman  */
5491581f4SElliot Berman 
6491581f4SElliot Berman #ifndef _LINUX_QCOM_GENI_SE
7491581f4SElliot Berman #define _LINUX_QCOM_GENI_SE
8491581f4SElliot Berman 
9491581f4SElliot Berman #include <linux/interconnect.h>
10491581f4SElliot Berman 
11491581f4SElliot Berman /**
12491581f4SElliot Berman  * enum geni_se_xfer_mode: Transfer modes supported by Serial Engines
13491581f4SElliot Berman  *
14491581f4SElliot Berman  * @GENI_SE_INVALID: Invalid mode
15491581f4SElliot Berman  * @GENI_SE_FIFO: FIFO mode. Data is transferred with SE FIFO
16491581f4SElliot Berman  * by programmed IO method
17491581f4SElliot Berman  * @GENI_SE_DMA: Serial Engine DMA mode. Data is transferred
18491581f4SElliot Berman  * with SE by DMAengine internal to SE
19491581f4SElliot Berman  * @GENI_GPI_DMA: GPI DMA mode. Data is transferred using a DMAengine
20491581f4SElliot Berman  * configured by a firmware residing on a GSI engine. This DMA name is
21491581f4SElliot Berman  * interchangeably used as GSI or GPI which seem to imply the same DMAengine
22491581f4SElliot Berman  */
23491581f4SElliot Berman 
24491581f4SElliot Berman enum geni_se_xfer_mode {
25491581f4SElliot Berman 	GENI_SE_INVALID,
26491581f4SElliot Berman 	GENI_SE_FIFO,
27491581f4SElliot Berman 	GENI_SE_DMA,
28491581f4SElliot Berman 	GENI_GPI_DMA,
29491581f4SElliot Berman };
30491581f4SElliot Berman 
31491581f4SElliot Berman /* Protocols supported by GENI Serial Engines */
32491581f4SElliot Berman enum geni_se_protocol_type {
33491581f4SElliot Berman 	GENI_SE_NONE,
34491581f4SElliot Berman 	GENI_SE_SPI,
35491581f4SElliot Berman 	GENI_SE_UART,
36491581f4SElliot Berman 	GENI_SE_I2C,
37491581f4SElliot Berman 	GENI_SE_I3C,
38*59bbe86bSPraveen Talari 	GENI_SE_SPI_SLAVE,
39491581f4SElliot Berman };
40491581f4SElliot Berman 
41491581f4SElliot Berman struct geni_wrapper;
42491581f4SElliot Berman struct clk;
43491581f4SElliot Berman 
44491581f4SElliot Berman enum geni_icc_path_index {
45491581f4SElliot Berman 	GENI_TO_CORE,
46491581f4SElliot Berman 	CPU_TO_GENI,
47491581f4SElliot Berman 	GENI_TO_DDR
48491581f4SElliot Berman };
49491581f4SElliot Berman 
50491581f4SElliot Berman struct geni_icc_path {
51491581f4SElliot Berman 	struct icc_path *path;
52491581f4SElliot Berman 	unsigned int avg_bw;
53491581f4SElliot Berman };
54491581f4SElliot Berman 
55491581f4SElliot Berman /**
56491581f4SElliot Berman  * struct geni_se - GENI Serial Engine
57491581f4SElliot Berman  * @base:		Base Address of the Serial Engine's register block
58491581f4SElliot Berman  * @dev:		Pointer to the Serial Engine device
59491581f4SElliot Berman  * @wrapper:		Pointer to the parent QUP Wrapper core
60491581f4SElliot Berman  * @clk:		Handle to the core serial engine clock
61491581f4SElliot Berman  * @num_clk_levels:	Number of valid clock levels in clk_perf_tbl
62491581f4SElliot Berman  * @clk_perf_tbl:	Table of clock frequency input to serial engine clock
63491581f4SElliot Berman  * @icc_paths:		Array of ICC paths for SE
64491581f4SElliot Berman  */
65491581f4SElliot Berman struct geni_se {
66491581f4SElliot Berman 	void __iomem *base;
67491581f4SElliot Berman 	struct device *dev;
68491581f4SElliot Berman 	struct geni_wrapper *wrapper;
69491581f4SElliot Berman 	struct clk *clk;
70491581f4SElliot Berman 	unsigned int num_clk_levels;
71491581f4SElliot Berman 	unsigned long *clk_perf_tbl;
72491581f4SElliot Berman 	struct geni_icc_path icc_paths[3];
73491581f4SElliot Berman };
74491581f4SElliot Berman 
75491581f4SElliot Berman /* Common SE registers */
76491581f4SElliot Berman #define GENI_FORCE_DEFAULT_REG		0x20
77*59bbe86bSPraveen Talari #define GENI_OUTPUT_CTRL		0x24
78491581f4SElliot Berman #define SE_GENI_STATUS			0x40
79491581f4SElliot Berman #define GENI_SER_M_CLK_CFG		0x48
80491581f4SElliot Berman #define GENI_SER_S_CLK_CFG		0x4c
81491581f4SElliot Berman #define GENI_IF_DISABLE_RO		0x64
82491581f4SElliot Berman #define GENI_FW_REVISION_RO		0x68
83491581f4SElliot Berman #define SE_GENI_CLK_SEL			0x7c
84*59bbe86bSPraveen Talari #define SE_GENI_CFG_SEQ_START		0x84
85491581f4SElliot Berman #define SE_GENI_DMA_MODE_EN		0x258
86491581f4SElliot Berman #define SE_GENI_M_CMD0			0x600
87491581f4SElliot Berman #define SE_GENI_M_CMD_CTRL_REG		0x604
88491581f4SElliot Berman #define SE_GENI_M_IRQ_STATUS		0x610
89491581f4SElliot Berman #define SE_GENI_M_IRQ_EN		0x614
90491581f4SElliot Berman #define SE_GENI_M_IRQ_CLEAR		0x618
91491581f4SElliot Berman #define SE_GENI_S_CMD0			0x630
92491581f4SElliot Berman #define SE_GENI_S_CMD_CTRL_REG		0x634
93491581f4SElliot Berman #define SE_GENI_S_IRQ_STATUS		0x640
94491581f4SElliot Berman #define SE_GENI_S_IRQ_EN		0x644
95491581f4SElliot Berman #define SE_GENI_S_IRQ_CLEAR		0x648
96491581f4SElliot Berman #define SE_GENI_TX_FIFOn		0x700
97491581f4SElliot Berman #define SE_GENI_RX_FIFOn		0x780
98491581f4SElliot Berman #define SE_GENI_TX_FIFO_STATUS		0x800
99491581f4SElliot Berman #define SE_GENI_RX_FIFO_STATUS		0x804
100491581f4SElliot Berman #define SE_GENI_TX_WATERMARK_REG	0x80c
101491581f4SElliot Berman #define SE_GENI_RX_WATERMARK_REG	0x810
102491581f4SElliot Berman #define SE_GENI_RX_RFR_WATERMARK_REG	0x814
103491581f4SElliot Berman #define SE_GENI_IOS			0x908
104491581f4SElliot Berman #define SE_DMA_TX_IRQ_STAT		0xc40
105491581f4SElliot Berman #define SE_DMA_TX_IRQ_CLR		0xc44
106491581f4SElliot Berman #define SE_DMA_TX_FSM_RST		0xc58
107491581f4SElliot Berman #define SE_DMA_RX_IRQ_STAT		0xd40
108491581f4SElliot Berman #define SE_DMA_RX_IRQ_CLR		0xd44
109491581f4SElliot Berman #define SE_DMA_RX_LEN_IN		0xd54
110491581f4SElliot Berman #define SE_DMA_RX_FSM_RST		0xd58
111491581f4SElliot Berman #define SE_HW_PARAM_0			0xe24
112491581f4SElliot Berman #define SE_HW_PARAM_1			0xe28
113491581f4SElliot Berman 
114491581f4SElliot Berman /* GENI_FORCE_DEFAULT_REG fields */
115491581f4SElliot Berman #define FORCE_DEFAULT	BIT(0)
116491581f4SElliot Berman 
117*59bbe86bSPraveen Talari /* GENI_OUTPUT_CTRL fields */
118*59bbe86bSPraveen Talari #define GENI_IO_MUX_0_EN		BIT(0)
119*59bbe86bSPraveen Talari 
120491581f4SElliot Berman /* GENI_STATUS fields */
121491581f4SElliot Berman #define M_GENI_CMD_ACTIVE		BIT(0)
122491581f4SElliot Berman #define S_GENI_CMD_ACTIVE		BIT(12)
123491581f4SElliot Berman 
124491581f4SElliot Berman /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
125491581f4SElliot Berman #define SER_CLK_EN			BIT(0)
126491581f4SElliot Berman #define CLK_DIV_MSK			GENMASK(15, 4)
127491581f4SElliot Berman #define CLK_DIV_SHFT			4
128491581f4SElliot Berman 
129491581f4SElliot Berman /* GENI_IF_DISABLE_RO fields */
130491581f4SElliot Berman #define FIFO_IF_DISABLE			(BIT(0))
131491581f4SElliot Berman 
132491581f4SElliot Berman /* GENI_FW_REVISION_RO fields */
133491581f4SElliot Berman #define FW_REV_PROTOCOL_MSK		GENMASK(15, 8)
134491581f4SElliot Berman #define FW_REV_PROTOCOL_SHFT		8
135491581f4SElliot Berman 
136491581f4SElliot Berman /* GENI_CLK_SEL fields */
137491581f4SElliot Berman #define CLK_SEL_MSK			GENMASK(2, 0)
138491581f4SElliot Berman 
139*59bbe86bSPraveen Talari /* SE_GENI_CFG_SEQ_START fields */
140*59bbe86bSPraveen Talari #define START_TRIGGER			BIT(0)
141*59bbe86bSPraveen Talari 
142491581f4SElliot Berman /* SE_GENI_DMA_MODE_EN */
143491581f4SElliot Berman #define GENI_DMA_MODE_EN		BIT(0)
144491581f4SElliot Berman 
145491581f4SElliot Berman /* GENI_M_CMD0 fields */
146491581f4SElliot Berman #define M_OPCODE_MSK			GENMASK(31, 27)
147491581f4SElliot Berman #define M_OPCODE_SHFT			27
148491581f4SElliot Berman #define M_PARAMS_MSK			GENMASK(26, 0)
149491581f4SElliot Berman 
150491581f4SElliot Berman /* GENI_M_CMD_CTRL_REG */
151491581f4SElliot Berman #define M_GENI_CMD_CANCEL		BIT(2)
152491581f4SElliot Berman #define M_GENI_CMD_ABORT		BIT(1)
153491581f4SElliot Berman #define M_GENI_DISABLE			BIT(0)
154491581f4SElliot Berman 
155491581f4SElliot Berman /* GENI_S_CMD0 fields */
156491581f4SElliot Berman #define S_OPCODE_MSK			GENMASK(31, 27)
157491581f4SElliot Berman #define S_OPCODE_SHFT			27
158491581f4SElliot Berman #define S_PARAMS_MSK			GENMASK(26, 0)
159491581f4SElliot Berman 
160491581f4SElliot Berman /* GENI_S_CMD_CTRL_REG */
161491581f4SElliot Berman #define S_GENI_CMD_CANCEL		BIT(2)
162491581f4SElliot Berman #define S_GENI_CMD_ABORT		BIT(1)
163491581f4SElliot Berman #define S_GENI_DISABLE			BIT(0)
164491581f4SElliot Berman 
165491581f4SElliot Berman /* GENI_M_IRQ_EN fields */
166491581f4SElliot Berman #define M_CMD_DONE_EN			BIT(0)
167491581f4SElliot Berman #define M_CMD_OVERRUN_EN		BIT(1)
168491581f4SElliot Berman #define M_ILLEGAL_CMD_EN		BIT(2)
169491581f4SElliot Berman #define M_CMD_FAILURE_EN		BIT(3)
170491581f4SElliot Berman #define M_CMD_CANCEL_EN			BIT(4)
171491581f4SElliot Berman #define M_CMD_ABORT_EN			BIT(5)
172491581f4SElliot Berman #define M_TIMESTAMP_EN			BIT(6)
173491581f4SElliot Berman #define M_RX_IRQ_EN			BIT(7)
174491581f4SElliot Berman #define M_GP_SYNC_IRQ_0_EN		BIT(8)
175491581f4SElliot Berman #define M_GP_IRQ_0_EN			BIT(9)
176491581f4SElliot Berman #define M_GP_IRQ_1_EN			BIT(10)
177491581f4SElliot Berman #define M_GP_IRQ_2_EN			BIT(11)
178491581f4SElliot Berman #define M_GP_IRQ_3_EN			BIT(12)
179491581f4SElliot Berman #define M_GP_IRQ_4_EN			BIT(13)
180491581f4SElliot Berman #define M_GP_IRQ_5_EN			BIT(14)
181491581f4SElliot Berman #define M_IO_DATA_DEASSERT_EN		BIT(22)
182491581f4SElliot Berman #define M_IO_DATA_ASSERT_EN		BIT(23)
183491581f4SElliot Berman #define M_RX_FIFO_RD_ERR_EN		BIT(24)
184491581f4SElliot Berman #define M_RX_FIFO_WR_ERR_EN		BIT(25)
185491581f4SElliot Berman #define M_RX_FIFO_WATERMARK_EN		BIT(26)
186491581f4SElliot Berman #define M_RX_FIFO_LAST_EN		BIT(27)
187491581f4SElliot Berman #define M_TX_FIFO_RD_ERR_EN		BIT(28)
188491581f4SElliot Berman #define M_TX_FIFO_WR_ERR_EN		BIT(29)
189491581f4SElliot Berman #define M_TX_FIFO_WATERMARK_EN		BIT(30)
190491581f4SElliot Berman #define M_SEC_IRQ_EN			BIT(31)
191491581f4SElliot Berman #define M_COMMON_GENI_M_IRQ_EN	(GENMASK(6, 1) | \
192491581f4SElliot Berman 				M_IO_DATA_DEASSERT_EN | \
193491581f4SElliot Berman 				M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
194491581f4SElliot Berman 				M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
195491581f4SElliot Berman 				M_TX_FIFO_WR_ERR_EN)
196491581f4SElliot Berman 
197491581f4SElliot Berman /* GENI_S_IRQ_EN fields */
198491581f4SElliot Berman #define S_CMD_DONE_EN			BIT(0)
199491581f4SElliot Berman #define S_CMD_OVERRUN_EN		BIT(1)
200491581f4SElliot Berman #define S_ILLEGAL_CMD_EN		BIT(2)
201491581f4SElliot Berman #define S_CMD_FAILURE_EN		BIT(3)
202491581f4SElliot Berman #define S_CMD_CANCEL_EN			BIT(4)
203491581f4SElliot Berman #define S_CMD_ABORT_EN			BIT(5)
204491581f4SElliot Berman #define S_GP_SYNC_IRQ_0_EN		BIT(8)
205491581f4SElliot Berman #define S_GP_IRQ_0_EN			BIT(9)
206491581f4SElliot Berman #define S_GP_IRQ_1_EN			BIT(10)
207491581f4SElliot Berman #define S_GP_IRQ_2_EN			BIT(11)
208491581f4SElliot Berman #define S_GP_IRQ_3_EN			BIT(12)
209491581f4SElliot Berman #define S_GP_IRQ_4_EN			BIT(13)
210491581f4SElliot Berman #define S_GP_IRQ_5_EN			BIT(14)
211491581f4SElliot Berman #define S_IO_DATA_DEASSERT_EN		BIT(22)
212491581f4SElliot Berman #define S_IO_DATA_ASSERT_EN		BIT(23)
213491581f4SElliot Berman #define S_RX_FIFO_RD_ERR_EN		BIT(24)
214491581f4SElliot Berman #define S_RX_FIFO_WR_ERR_EN		BIT(25)
215491581f4SElliot Berman #define S_RX_FIFO_WATERMARK_EN		BIT(26)
216491581f4SElliot Berman #define S_RX_FIFO_LAST_EN		BIT(27)
217491581f4SElliot Berman #define S_COMMON_GENI_S_IRQ_EN	(GENMASK(5, 1) | GENMASK(13, 9) | \
218491581f4SElliot Berman 				 S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
219491581f4SElliot Berman 
220491581f4SElliot Berman /*  GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
221491581f4SElliot Berman #define WATERMARK_MSK			GENMASK(5, 0)
222491581f4SElliot Berman 
223491581f4SElliot Berman /* GENI_TX_FIFO_STATUS fields */
224491581f4SElliot Berman #define TX_FIFO_WC			GENMASK(27, 0)
225491581f4SElliot Berman 
226491581f4SElliot Berman /*  GENI_RX_FIFO_STATUS fields */
227491581f4SElliot Berman #define RX_LAST				BIT(31)
228491581f4SElliot Berman #define RX_LAST_BYTE_VALID_MSK		GENMASK(30, 28)
229491581f4SElliot Berman #define RX_LAST_BYTE_VALID_SHFT		28
230491581f4SElliot Berman #define RX_FIFO_WC_MSK			GENMASK(24, 0)
231491581f4SElliot Berman 
232491581f4SElliot Berman /* SE_GENI_IOS fields */
233491581f4SElliot Berman #define IO2_DATA_IN			BIT(1)
234491581f4SElliot Berman #define RX_DATA_IN			BIT(0)
235491581f4SElliot Berman 
236491581f4SElliot Berman /* SE_DMA_TX_IRQ_STAT Register fields */
237491581f4SElliot Berman #define TX_DMA_DONE			BIT(0)
238491581f4SElliot Berman #define TX_EOT				BIT(1)
239491581f4SElliot Berman #define TX_SBE				BIT(2)
240491581f4SElliot Berman #define TX_RESET_DONE			BIT(3)
241491581f4SElliot Berman 
242491581f4SElliot Berman /* SE_DMA_RX_IRQ_STAT Register fields */
243491581f4SElliot Berman #define RX_DMA_DONE			BIT(0)
244491581f4SElliot Berman #define RX_EOT				BIT(1)
245491581f4SElliot Berman #define RX_SBE				BIT(2)
246491581f4SElliot Berman #define RX_RESET_DONE			BIT(3)
247491581f4SElliot Berman #define RX_FLUSH_DONE			BIT(4)
248491581f4SElliot Berman #define RX_DMA_PARITY_ERR		BIT(5)
249491581f4SElliot Berman #define RX_DMA_BREAK			GENMASK(8, 7)
250491581f4SElliot Berman #define RX_GENI_GP_IRQ			GENMASK(10, 5)
251491581f4SElliot Berman #define RX_GENI_CANCEL_IRQ		BIT(11)
252491581f4SElliot Berman #define RX_GENI_GP_IRQ_EXT		GENMASK(13, 12)
253491581f4SElliot Berman 
254491581f4SElliot Berman /* SE_HW_PARAM_0 fields */
255491581f4SElliot Berman #define TX_FIFO_WIDTH_MSK		GENMASK(29, 24)
256491581f4SElliot Berman #define TX_FIFO_WIDTH_SHFT		24
257fe8aa1baSVisweswara Tanuku /*
258fe8aa1baSVisweswara Tanuku  * For QUP HW Version >= 3.10 Tx fifo depth support is increased
259fe8aa1baSVisweswara Tanuku  * to 256bytes and corresponding bits are 16 to 23
260fe8aa1baSVisweswara Tanuku  */
261fe8aa1baSVisweswara Tanuku #define TX_FIFO_DEPTH_MSK_256_BYTES	GENMASK(23, 16)
262491581f4SElliot Berman #define TX_FIFO_DEPTH_MSK		GENMASK(21, 16)
263491581f4SElliot Berman #define TX_FIFO_DEPTH_SHFT		16
264491581f4SElliot Berman 
265491581f4SElliot Berman /* SE_HW_PARAM_1 fields */
266491581f4SElliot Berman #define RX_FIFO_WIDTH_MSK		GENMASK(29, 24)
267491581f4SElliot Berman #define RX_FIFO_WIDTH_SHFT		24
268fe8aa1baSVisweswara Tanuku /*
269fe8aa1baSVisweswara Tanuku  * For QUP HW Version >= 3.10 Rx fifo depth support is increased
270fe8aa1baSVisweswara Tanuku  * to 256bytes and corresponding bits are 16 to 23
271fe8aa1baSVisweswara Tanuku  */
272fe8aa1baSVisweswara Tanuku #define RX_FIFO_DEPTH_MSK_256_BYTES	GENMASK(23, 16)
273491581f4SElliot Berman #define RX_FIFO_DEPTH_MSK		GENMASK(21, 16)
274491581f4SElliot Berman #define RX_FIFO_DEPTH_SHFT		16
275491581f4SElliot Berman 
276491581f4SElliot Berman #define HW_VER_MAJOR_MASK		GENMASK(31, 28)
277491581f4SElliot Berman #define HW_VER_MAJOR_SHFT		28
278491581f4SElliot Berman #define HW_VER_MINOR_MASK		GENMASK(27, 16)
279491581f4SElliot Berman #define HW_VER_MINOR_SHFT		16
280491581f4SElliot Berman #define HW_VER_STEP_MASK		GENMASK(15, 0)
281491581f4SElliot Berman 
282491581f4SElliot Berman #define GENI_SE_VERSION_MAJOR(ver) ((ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT)
283491581f4SElliot Berman #define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT)
284491581f4SElliot Berman #define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK)
285491581f4SElliot Berman 
286491581f4SElliot Berman /* QUP SE VERSION value for major number 2 and minor number 5 */
287491581f4SElliot Berman #define QUP_SE_VERSION_2_5                  0x20050000
288491581f4SElliot Berman 
289491581f4SElliot Berman /*
290491581f4SElliot Berman  * Define bandwidth thresholds that cause the underlying Core 2X interconnect
291491581f4SElliot Berman  * clock to run at the named frequency. These baseline values are recommended
292491581f4SElliot Berman  * by the hardware team, and are not dynamically scaled with GENI bandwidth
293491581f4SElliot Berman  * beyond basic on/off.
294491581f4SElliot Berman  */
295491581f4SElliot Berman #define CORE_2X_19_2_MHZ		960
296491581f4SElliot Berman #define CORE_2X_50_MHZ			2500
297491581f4SElliot Berman #define CORE_2X_100_MHZ			5000
298491581f4SElliot Berman #define CORE_2X_150_MHZ			7500
299491581f4SElliot Berman #define CORE_2X_200_MHZ			10000
300491581f4SElliot Berman #define CORE_2X_236_MHZ			16383
301491581f4SElliot Berman 
302491581f4SElliot Berman #define GENI_DEFAULT_BW			Bps_to_icc(1000)
303491581f4SElliot Berman 
304491581f4SElliot Berman #if IS_ENABLED(CONFIG_QCOM_GENI_SE)
305491581f4SElliot Berman 
306491581f4SElliot Berman u32 geni_se_get_qup_hw_version(struct geni_se *se);
307491581f4SElliot Berman 
308491581f4SElliot Berman /**
309491581f4SElliot Berman  * geni_se_read_proto() - Read the protocol configured for a serial engine
310491581f4SElliot Berman  * @se:		Pointer to the concerned serial engine.
311491581f4SElliot Berman  *
312491581f4SElliot Berman  * Return: Protocol value as configured in the serial engine.
313491581f4SElliot Berman  */
geni_se_read_proto(struct geni_se * se)314491581f4SElliot Berman static inline u32 geni_se_read_proto(struct geni_se *se)
315491581f4SElliot Berman {
316491581f4SElliot Berman 	u32 val;
317491581f4SElliot Berman 
318491581f4SElliot Berman 	val = readl_relaxed(se->base + GENI_FW_REVISION_RO);
319491581f4SElliot Berman 
320491581f4SElliot Berman 	return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;
321491581f4SElliot Berman }
322491581f4SElliot Berman 
323491581f4SElliot Berman /**
324491581f4SElliot Berman  * geni_se_setup_m_cmd() - Setup the primary sequencer
325491581f4SElliot Berman  * @se:		Pointer to the concerned serial engine.
326491581f4SElliot Berman  * @cmd:	Command/Operation to setup in the primary sequencer.
327491581f4SElliot Berman  * @params:	Parameter for the sequencer command.
328491581f4SElliot Berman  *
329491581f4SElliot Berman  * This function is used to configure the primary sequencer with the
330491581f4SElliot Berman  * command and its associated parameters.
331491581f4SElliot Berman  */
geni_se_setup_m_cmd(struct geni_se * se,u32 cmd,u32 params)332491581f4SElliot Berman static inline void geni_se_setup_m_cmd(struct geni_se *se, u32 cmd, u32 params)
333491581f4SElliot Berman {
334491581f4SElliot Berman 	u32 m_cmd;
335491581f4SElliot Berman 
336491581f4SElliot Berman 	m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
337491581f4SElliot Berman 	writel(m_cmd, se->base + SE_GENI_M_CMD0);
338491581f4SElliot Berman }
339491581f4SElliot Berman 
340491581f4SElliot Berman /**
341491581f4SElliot Berman  * geni_se_setup_s_cmd() - Setup the secondary sequencer
342491581f4SElliot Berman  * @se:		Pointer to the concerned serial engine.
343491581f4SElliot Berman  * @cmd:	Command/Operation to setup in the secondary sequencer.
344491581f4SElliot Berman  * @params:	Parameter for the sequencer command.
345491581f4SElliot Berman  *
346491581f4SElliot Berman  * This function is used to configure the secondary sequencer with the
347491581f4SElliot Berman  * command and its associated parameters.
348491581f4SElliot Berman  */
geni_se_setup_s_cmd(struct geni_se * se,u32 cmd,u32 params)349491581f4SElliot Berman static inline void geni_se_setup_s_cmd(struct geni_se *se, u32 cmd, u32 params)
350491581f4SElliot Berman {
351491581f4SElliot Berman 	u32 s_cmd;
352491581f4SElliot Berman 
353491581f4SElliot Berman 	s_cmd = readl_relaxed(se->base + SE_GENI_S_CMD0);
354491581f4SElliot Berman 	s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK);
355491581f4SElliot Berman 	s_cmd |= (cmd << S_OPCODE_SHFT);
356491581f4SElliot Berman 	s_cmd |= (params & S_PARAMS_MSK);
357491581f4SElliot Berman 	writel(s_cmd, se->base + SE_GENI_S_CMD0);
358491581f4SElliot Berman }
359491581f4SElliot Berman 
360491581f4SElliot Berman /**
361491581f4SElliot Berman  * geni_se_cancel_m_cmd() - Cancel the command configured in the primary
362491581f4SElliot Berman  *                          sequencer
363491581f4SElliot Berman  * @se:	Pointer to the concerned serial engine.
364491581f4SElliot Berman  *
365491581f4SElliot Berman  * This function is used to cancel the currently configured command in the
366491581f4SElliot Berman  * primary sequencer.
367491581f4SElliot Berman  */
geni_se_cancel_m_cmd(struct geni_se * se)368491581f4SElliot Berman static inline void geni_se_cancel_m_cmd(struct geni_se *se)
369491581f4SElliot Berman {
370491581f4SElliot Berman 	writel_relaxed(M_GENI_CMD_CANCEL, se->base + SE_GENI_M_CMD_CTRL_REG);
371491581f4SElliot Berman }
372491581f4SElliot Berman 
373491581f4SElliot Berman /**
374491581f4SElliot Berman  * geni_se_cancel_s_cmd() - Cancel the command configured in the secondary
375491581f4SElliot Berman  *                          sequencer
376491581f4SElliot Berman  * @se:	Pointer to the concerned serial engine.
377491581f4SElliot Berman  *
378491581f4SElliot Berman  * This function is used to cancel the currently configured command in the
379491581f4SElliot Berman  * secondary sequencer.
380491581f4SElliot Berman  */
geni_se_cancel_s_cmd(struct geni_se * se)381491581f4SElliot Berman static inline void geni_se_cancel_s_cmd(struct geni_se *se)
382491581f4SElliot Berman {
383491581f4SElliot Berman 	writel_relaxed(S_GENI_CMD_CANCEL, se->base + SE_GENI_S_CMD_CTRL_REG);
384491581f4SElliot Berman }
385491581f4SElliot Berman 
386491581f4SElliot Berman /**
387491581f4SElliot Berman  * geni_se_abort_m_cmd() - Abort the command configured in the primary sequencer
388491581f4SElliot Berman  * @se:	Pointer to the concerned serial engine.
389491581f4SElliot Berman  *
390491581f4SElliot Berman  * This function is used to force abort the currently configured command in the
391491581f4SElliot Berman  * primary sequencer.
392491581f4SElliot Berman  */
geni_se_abort_m_cmd(struct geni_se * se)393491581f4SElliot Berman static inline void geni_se_abort_m_cmd(struct geni_se *se)
394491581f4SElliot Berman {
395491581f4SElliot Berman 	writel_relaxed(M_GENI_CMD_ABORT, se->base + SE_GENI_M_CMD_CTRL_REG);
396491581f4SElliot Berman }
397491581f4SElliot Berman 
398491581f4SElliot Berman /**
399491581f4SElliot Berman  * geni_se_abort_s_cmd() - Abort the command configured in the secondary
400491581f4SElliot Berman  *                         sequencer
401491581f4SElliot Berman  * @se:	Pointer to the concerned serial engine.
402491581f4SElliot Berman  *
403491581f4SElliot Berman  * This function is used to force abort the currently configured command in the
404491581f4SElliot Berman  * secondary sequencer.
405491581f4SElliot Berman  */
geni_se_abort_s_cmd(struct geni_se * se)406491581f4SElliot Berman static inline void geni_se_abort_s_cmd(struct geni_se *se)
407491581f4SElliot Berman {
408491581f4SElliot Berman 	writel_relaxed(S_GENI_CMD_ABORT, se->base + SE_GENI_S_CMD_CTRL_REG);
409491581f4SElliot Berman }
410491581f4SElliot Berman 
411491581f4SElliot Berman /**
412491581f4SElliot Berman  * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
413fe8aa1baSVisweswara Tanuku  * based on QUP HW version
414491581f4SElliot Berman  * @se: Pointer to the concerned serial engine.
415491581f4SElliot Berman  *
416491581f4SElliot Berman  * This function is used to get the depth i.e. number of elements in the
417491581f4SElliot Berman  * TX fifo of the serial engine.
418491581f4SElliot Berman  *
419491581f4SElliot Berman  * Return: TX fifo depth in units of FIFO words.
420491581f4SElliot Berman  */
geni_se_get_tx_fifo_depth(struct geni_se * se)421491581f4SElliot Berman static inline u32 geni_se_get_tx_fifo_depth(struct geni_se *se)
422491581f4SElliot Berman {
423fe8aa1baSVisweswara Tanuku 	u32 val, hw_version, hw_major, hw_minor, tx_fifo_depth_mask;
424fe8aa1baSVisweswara Tanuku 
425fe8aa1baSVisweswara Tanuku 	hw_version = geni_se_get_qup_hw_version(se);
426fe8aa1baSVisweswara Tanuku 	hw_major = GENI_SE_VERSION_MAJOR(hw_version);
427fe8aa1baSVisweswara Tanuku 	hw_minor = GENI_SE_VERSION_MINOR(hw_version);
428fe8aa1baSVisweswara Tanuku 
429fe8aa1baSVisweswara Tanuku 	if ((hw_major == 3 && hw_minor >= 10) || hw_major > 3)
430fe8aa1baSVisweswara Tanuku 		tx_fifo_depth_mask = TX_FIFO_DEPTH_MSK_256_BYTES;
431fe8aa1baSVisweswara Tanuku 	else
432fe8aa1baSVisweswara Tanuku 		tx_fifo_depth_mask = TX_FIFO_DEPTH_MSK;
433491581f4SElliot Berman 
434491581f4SElliot Berman 	val = readl_relaxed(se->base + SE_HW_PARAM_0);
435491581f4SElliot Berman 
436fe8aa1baSVisweswara Tanuku 	return (val & tx_fifo_depth_mask) >> TX_FIFO_DEPTH_SHFT;
437491581f4SElliot Berman }
438491581f4SElliot Berman 
439491581f4SElliot Berman /**
440491581f4SElliot Berman  * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
441491581f4SElliot Berman  * @se:	Pointer to the concerned serial engine.
442491581f4SElliot Berman  *
443491581f4SElliot Berman  * This function is used to get the width i.e. word size per element in the
444491581f4SElliot Berman  * TX fifo of the serial engine.
445491581f4SElliot Berman  *
446491581f4SElliot Berman  * Return: TX fifo width in bits
447491581f4SElliot Berman  */
geni_se_get_tx_fifo_width(struct geni_se * se)448491581f4SElliot Berman static inline u32 geni_se_get_tx_fifo_width(struct geni_se *se)
449491581f4SElliot Berman {
450491581f4SElliot Berman 	u32 val;
451491581f4SElliot Berman 
452491581f4SElliot Berman 	val = readl_relaxed(se->base + SE_HW_PARAM_0);
453491581f4SElliot Berman 
454491581f4SElliot Berman 	return (val & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT;
455491581f4SElliot Berman }
456491581f4SElliot Berman 
457491581f4SElliot Berman /**
458491581f4SElliot Berman  * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
459fe8aa1baSVisweswara Tanuku  * based on QUP HW version
460491581f4SElliot Berman  * @se: Pointer to the concerned serial engine.
461491581f4SElliot Berman  *
462491581f4SElliot Berman  * This function is used to get the depth i.e. number of elements in the
463491581f4SElliot Berman  * RX fifo of the serial engine.
464491581f4SElliot Berman  *
465491581f4SElliot Berman  * Return: RX fifo depth in units of FIFO words
466491581f4SElliot Berman  */
geni_se_get_rx_fifo_depth(struct geni_se * se)467491581f4SElliot Berman static inline u32 geni_se_get_rx_fifo_depth(struct geni_se *se)
468491581f4SElliot Berman {
469fe8aa1baSVisweswara Tanuku 	u32 val, hw_version, hw_major, hw_minor, rx_fifo_depth_mask;
470fe8aa1baSVisweswara Tanuku 
471fe8aa1baSVisweswara Tanuku 	hw_version = geni_se_get_qup_hw_version(se);
472fe8aa1baSVisweswara Tanuku 	hw_major = GENI_SE_VERSION_MAJOR(hw_version);
473fe8aa1baSVisweswara Tanuku 	hw_minor = GENI_SE_VERSION_MINOR(hw_version);
474fe8aa1baSVisweswara Tanuku 
475fe8aa1baSVisweswara Tanuku 	if ((hw_major == 3 && hw_minor >= 10) || hw_major > 3)
476fe8aa1baSVisweswara Tanuku 		rx_fifo_depth_mask = RX_FIFO_DEPTH_MSK_256_BYTES;
477fe8aa1baSVisweswara Tanuku 	else
478fe8aa1baSVisweswara Tanuku 		rx_fifo_depth_mask = RX_FIFO_DEPTH_MSK;
479491581f4SElliot Berman 
480491581f4SElliot Berman 	val = readl_relaxed(se->base + SE_HW_PARAM_1);
481491581f4SElliot Berman 
482fe8aa1baSVisweswara Tanuku 	return (val & rx_fifo_depth_mask) >> RX_FIFO_DEPTH_SHFT;
483491581f4SElliot Berman }
484491581f4SElliot Berman 
485491581f4SElliot Berman void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr);
486491581f4SElliot Berman 
487491581f4SElliot Berman void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode);
488491581f4SElliot Berman 
489491581f4SElliot Berman void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words,
490491581f4SElliot Berman 			    bool msb_to_lsb, bool tx_cfg, bool rx_cfg);
491491581f4SElliot Berman 
492491581f4SElliot Berman int geni_se_resources_off(struct geni_se *se);
493491581f4SElliot Berman 
494491581f4SElliot Berman int geni_se_resources_on(struct geni_se *se);
495491581f4SElliot Berman 
496491581f4SElliot Berman int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl);
497491581f4SElliot Berman 
498491581f4SElliot Berman int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
499491581f4SElliot Berman 			   unsigned int *index, unsigned long *res_freq,
500491581f4SElliot Berman 			   bool exact);
501491581f4SElliot Berman 
5026d6e5759SVijaya Krishna Nivarthi void geni_se_tx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len);
5036d6e5759SVijaya Krishna Nivarthi 
504491581f4SElliot Berman int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
505491581f4SElliot Berman 			dma_addr_t *iova);
506491581f4SElliot Berman 
5076d6e5759SVijaya Krishna Nivarthi void geni_se_rx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len);
5086d6e5759SVijaya Krishna Nivarthi 
509491581f4SElliot Berman int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
510491581f4SElliot Berman 			dma_addr_t *iova);
511491581f4SElliot Berman 
512491581f4SElliot Berman void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
513491581f4SElliot Berman 
514491581f4SElliot Berman void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
515491581f4SElliot Berman 
516491581f4SElliot Berman int geni_icc_get(struct geni_se *se, const char *icc_ddr);
517491581f4SElliot Berman 
518491581f4SElliot Berman int geni_icc_set_bw(struct geni_se *se);
519491581f4SElliot Berman void geni_icc_set_tag(struct geni_se *se, u32 tag);
520491581f4SElliot Berman 
521491581f4SElliot Berman int geni_icc_enable(struct geni_se *se);
522491581f4SElliot Berman 
523491581f4SElliot Berman int geni_icc_disable(struct geni_se *se);
524491581f4SElliot Berman #endif
525491581f4SElliot Berman #endif
526