1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
6 #ifndef _LINUX_QCOM_GENI_SE
7 #define _LINUX_QCOM_GENI_SE
9 #include <linux/interconnect.h>
12 * enum geni_se_xfer_mode: Transfer modes supported by Serial Engines
14 * @GENI_SE_INVALID: Invalid mode
15 * @GENI_SE_FIFO: FIFO mode. Data is transferred with SE FIFO
16 * by programmed IO method
17 * @GENI_SE_DMA: Serial Engine DMA mode. Data is transferred
18 * with SE by DMAengine internal to SE
19 * @GENI_GPI_DMA: GPI DMA mode. Data is transferred using a DMAengine
20 * configured by a firmware residing on a GSI engine. This DMA name is
21 * interchangeably used as GSI or GPI which seem to imply the same DMAengine
24 enum geni_se_xfer_mode {
31 /* Protocols supported by GENI Serial Engines */
32 enum geni_se_protocol_type {
43 enum geni_icc_path_index {
49 struct geni_icc_path {
50 struct icc_path *path;
55 * struct geni_se - GENI Serial Engine
56 * @base: Base Address of the Serial Engine's register block
57 * @dev: Pointer to the Serial Engine device
58 * @wrapper: Pointer to the parent QUP Wrapper core
59 * @clk: Handle to the core serial engine clock
60 * @num_clk_levels: Number of valid clock levels in clk_perf_tbl
61 * @clk_perf_tbl: Table of clock frequency input to serial engine clock
62 * @icc_paths: Array of ICC paths for SE
67 struct geni_wrapper *wrapper;
69 unsigned int num_clk_levels;
70 unsigned long *clk_perf_tbl;
71 struct geni_icc_path icc_paths[3];
74 /* Common SE registers */
75 #define GENI_FORCE_DEFAULT_REG 0x20
76 #define SE_GENI_STATUS 0x40
77 #define GENI_SER_M_CLK_CFG 0x48
78 #define GENI_SER_S_CLK_CFG 0x4c
79 #define GENI_IF_DISABLE_RO 0x64
80 #define GENI_FW_REVISION_RO 0x68
81 #define SE_GENI_CLK_SEL 0x7c
82 #define SE_GENI_DMA_MODE_EN 0x258
83 #define SE_GENI_M_CMD0 0x600
84 #define SE_GENI_M_CMD_CTRL_REG 0x604
85 #define SE_GENI_M_IRQ_STATUS 0x610
86 #define SE_GENI_M_IRQ_EN 0x614
87 #define SE_GENI_M_IRQ_CLEAR 0x618
88 #define SE_GENI_S_CMD0 0x630
89 #define SE_GENI_S_CMD_CTRL_REG 0x634
90 #define SE_GENI_S_IRQ_STATUS 0x640
91 #define SE_GENI_S_IRQ_EN 0x644
92 #define SE_GENI_S_IRQ_CLEAR 0x648
93 #define SE_GENI_TX_FIFOn 0x700
94 #define SE_GENI_RX_FIFOn 0x780
95 #define SE_GENI_TX_FIFO_STATUS 0x800
96 #define SE_GENI_RX_FIFO_STATUS 0x804
97 #define SE_GENI_TX_WATERMARK_REG 0x80c
98 #define SE_GENI_RX_WATERMARK_REG 0x810
99 #define SE_GENI_RX_RFR_WATERMARK_REG 0x814
100 #define SE_GENI_IOS 0x908
101 #define SE_DMA_TX_IRQ_STAT 0xc40
102 #define SE_DMA_TX_IRQ_CLR 0xc44
103 #define SE_DMA_TX_FSM_RST 0xc58
104 #define SE_DMA_RX_IRQ_STAT 0xd40
105 #define SE_DMA_RX_IRQ_CLR 0xd44
106 #define SE_DMA_RX_FSM_RST 0xd58
107 #define SE_HW_PARAM_0 0xe24
108 #define SE_HW_PARAM_1 0xe28
110 /* GENI_FORCE_DEFAULT_REG fields */
111 #define FORCE_DEFAULT BIT(0)
113 /* GENI_STATUS fields */
114 #define M_GENI_CMD_ACTIVE BIT(0)
115 #define S_GENI_CMD_ACTIVE BIT(12)
117 /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
118 #define SER_CLK_EN BIT(0)
119 #define CLK_DIV_MSK GENMASK(15, 4)
120 #define CLK_DIV_SHFT 4
122 /* GENI_IF_DISABLE_RO fields */
123 #define FIFO_IF_DISABLE (BIT(0))
125 /* GENI_FW_REVISION_RO fields */
126 #define FW_REV_PROTOCOL_MSK GENMASK(15, 8)
127 #define FW_REV_PROTOCOL_SHFT 8
129 /* GENI_CLK_SEL fields */
130 #define CLK_SEL_MSK GENMASK(2, 0)
132 /* SE_GENI_DMA_MODE_EN */
133 #define GENI_DMA_MODE_EN BIT(0)
135 /* GENI_M_CMD0 fields */
136 #define M_OPCODE_MSK GENMASK(31, 27)
137 #define M_OPCODE_SHFT 27
138 #define M_PARAMS_MSK GENMASK(26, 0)
140 /* GENI_M_CMD_CTRL_REG */
141 #define M_GENI_CMD_CANCEL BIT(2)
142 #define M_GENI_CMD_ABORT BIT(1)
143 #define M_GENI_DISABLE BIT(0)
145 /* GENI_S_CMD0 fields */
146 #define S_OPCODE_MSK GENMASK(31, 27)
147 #define S_OPCODE_SHFT 27
148 #define S_PARAMS_MSK GENMASK(26, 0)
150 /* GENI_S_CMD_CTRL_REG */
151 #define S_GENI_CMD_CANCEL BIT(2)
152 #define S_GENI_CMD_ABORT BIT(1)
153 #define S_GENI_DISABLE BIT(0)
155 /* GENI_M_IRQ_EN fields */
156 #define M_CMD_DONE_EN BIT(0)
157 #define M_CMD_OVERRUN_EN BIT(1)
158 #define M_ILLEGAL_CMD_EN BIT(2)
159 #define M_CMD_FAILURE_EN BIT(3)
160 #define M_CMD_CANCEL_EN BIT(4)
161 #define M_CMD_ABORT_EN BIT(5)
162 #define M_TIMESTAMP_EN BIT(6)
163 #define M_RX_IRQ_EN BIT(7)
164 #define M_GP_SYNC_IRQ_0_EN BIT(8)
165 #define M_GP_IRQ_0_EN BIT(9)
166 #define M_GP_IRQ_1_EN BIT(10)
167 #define M_GP_IRQ_2_EN BIT(11)
168 #define M_GP_IRQ_3_EN BIT(12)
169 #define M_GP_IRQ_4_EN BIT(13)
170 #define M_GP_IRQ_5_EN BIT(14)
171 #define M_IO_DATA_DEASSERT_EN BIT(22)
172 #define M_IO_DATA_ASSERT_EN BIT(23)
173 #define M_RX_FIFO_RD_ERR_EN BIT(24)
174 #define M_RX_FIFO_WR_ERR_EN BIT(25)
175 #define M_RX_FIFO_WATERMARK_EN BIT(26)
176 #define M_RX_FIFO_LAST_EN BIT(27)
177 #define M_TX_FIFO_RD_ERR_EN BIT(28)
178 #define M_TX_FIFO_WR_ERR_EN BIT(29)
179 #define M_TX_FIFO_WATERMARK_EN BIT(30)
180 #define M_SEC_IRQ_EN BIT(31)
181 #define M_COMMON_GENI_M_IRQ_EN (GENMASK(6, 1) | \
182 M_IO_DATA_DEASSERT_EN | \
183 M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
184 M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
187 /* GENI_S_IRQ_EN fields */
188 #define S_CMD_DONE_EN BIT(0)
189 #define S_CMD_OVERRUN_EN BIT(1)
190 #define S_ILLEGAL_CMD_EN BIT(2)
191 #define S_CMD_FAILURE_EN BIT(3)
192 #define S_CMD_CANCEL_EN BIT(4)
193 #define S_CMD_ABORT_EN BIT(5)
194 #define S_GP_SYNC_IRQ_0_EN BIT(8)
195 #define S_GP_IRQ_0_EN BIT(9)
196 #define S_GP_IRQ_1_EN BIT(10)
197 #define S_GP_IRQ_2_EN BIT(11)
198 #define S_GP_IRQ_3_EN BIT(12)
199 #define S_GP_IRQ_4_EN BIT(13)
200 #define S_GP_IRQ_5_EN BIT(14)
201 #define S_IO_DATA_DEASSERT_EN BIT(22)
202 #define S_IO_DATA_ASSERT_EN BIT(23)
203 #define S_RX_FIFO_RD_ERR_EN BIT(24)
204 #define S_RX_FIFO_WR_ERR_EN BIT(25)
205 #define S_RX_FIFO_WATERMARK_EN BIT(26)
206 #define S_RX_FIFO_LAST_EN BIT(27)
207 #define S_COMMON_GENI_S_IRQ_EN (GENMASK(5, 1) | GENMASK(13, 9) | \
208 S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
210 /* GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
211 #define WATERMARK_MSK GENMASK(5, 0)
213 /* GENI_TX_FIFO_STATUS fields */
214 #define TX_FIFO_WC GENMASK(27, 0)
216 /* GENI_RX_FIFO_STATUS fields */
217 #define RX_LAST BIT(31)
218 #define RX_LAST_BYTE_VALID_MSK GENMASK(30, 28)
219 #define RX_LAST_BYTE_VALID_SHFT 28
220 #define RX_FIFO_WC_MSK GENMASK(24, 0)
222 /* SE_GENI_IOS fields */
223 #define IO2_DATA_IN BIT(1)
224 #define RX_DATA_IN BIT(0)
226 /* SE_DMA_TX_IRQ_STAT Register fields */
227 #define TX_DMA_DONE BIT(0)
228 #define TX_EOT BIT(1)
229 #define TX_SBE BIT(2)
230 #define TX_RESET_DONE BIT(3)
232 /* SE_DMA_RX_IRQ_STAT Register fields */
233 #define RX_DMA_DONE BIT(0)
234 #define RX_EOT BIT(1)
235 #define RX_SBE BIT(2)
236 #define RX_RESET_DONE BIT(3)
237 #define RX_FLUSH_DONE BIT(4)
238 #define RX_GENI_GP_IRQ GENMASK(10, 5)
239 #define RX_GENI_CANCEL_IRQ BIT(11)
240 #define RX_GENI_GP_IRQ_EXT GENMASK(13, 12)
242 /* SE_HW_PARAM_0 fields */
243 #define TX_FIFO_WIDTH_MSK GENMASK(29, 24)
244 #define TX_FIFO_WIDTH_SHFT 24
245 #define TX_FIFO_DEPTH_MSK GENMASK(21, 16)
246 #define TX_FIFO_DEPTH_SHFT 16
248 /* SE_HW_PARAM_1 fields */
249 #define RX_FIFO_WIDTH_MSK GENMASK(29, 24)
250 #define RX_FIFO_WIDTH_SHFT 24
251 #define RX_FIFO_DEPTH_MSK GENMASK(21, 16)
252 #define RX_FIFO_DEPTH_SHFT 16
254 #define HW_VER_MAJOR_MASK GENMASK(31, 28)
255 #define HW_VER_MAJOR_SHFT 28
256 #define HW_VER_MINOR_MASK GENMASK(27, 16)
257 #define HW_VER_MINOR_SHFT 16
258 #define HW_VER_STEP_MASK GENMASK(15, 0)
260 #define GENI_SE_VERSION_MAJOR(ver) ((ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT)
261 #define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT)
262 #define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK)
264 /* QUP SE VERSION value for major number 2 and minor number 5 */
265 #define QUP_SE_VERSION_2_5 0x20050000
268 * Define bandwidth thresholds that cause the underlying Core 2X interconnect
269 * clock to run at the named frequency. These baseline values are recommended
270 * by the hardware team, and are not dynamically scaled with GENI bandwidth
271 * beyond basic on/off.
273 #define CORE_2X_19_2_MHZ 960
274 #define CORE_2X_50_MHZ 2500
275 #define CORE_2X_100_MHZ 5000
276 #define CORE_2X_150_MHZ 7500
277 #define CORE_2X_200_MHZ 10000
278 #define CORE_2X_236_MHZ 16383
280 #define GENI_DEFAULT_BW Bps_to_icc(1000)
282 #if IS_ENABLED(CONFIG_QCOM_GENI_SE)
284 u32 geni_se_get_qup_hw_version(struct geni_se *se);
287 * geni_se_read_proto() - Read the protocol configured for a serial engine
288 * @se: Pointer to the concerned serial engine.
290 * Return: Protocol value as configured in the serial engine.
292 static inline u32 geni_se_read_proto(struct geni_se *se)
296 val = readl_relaxed(se->base + GENI_FW_REVISION_RO);
298 return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;
302 * geni_se_setup_m_cmd() - Setup the primary sequencer
303 * @se: Pointer to the concerned serial engine.
304 * @cmd: Command/Operation to setup in the primary sequencer.
305 * @params: Parameter for the sequencer command.
307 * This function is used to configure the primary sequencer with the
308 * command and its associated parameters.
310 static inline void geni_se_setup_m_cmd(struct geni_se *se, u32 cmd, u32 params)
314 m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
315 writel(m_cmd, se->base + SE_GENI_M_CMD0);
319 * geni_se_setup_s_cmd() - Setup the secondary sequencer
320 * @se: Pointer to the concerned serial engine.
321 * @cmd: Command/Operation to setup in the secondary sequencer.
322 * @params: Parameter for the sequencer command.
324 * This function is used to configure the secondary sequencer with the
325 * command and its associated parameters.
327 static inline void geni_se_setup_s_cmd(struct geni_se *se, u32 cmd, u32 params)
331 s_cmd = readl_relaxed(se->base + SE_GENI_S_CMD0);
332 s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK);
333 s_cmd |= (cmd << S_OPCODE_SHFT);
334 s_cmd |= (params & S_PARAMS_MSK);
335 writel(s_cmd, se->base + SE_GENI_S_CMD0);
339 * geni_se_cancel_m_cmd() - Cancel the command configured in the primary
341 * @se: Pointer to the concerned serial engine.
343 * This function is used to cancel the currently configured command in the
346 static inline void geni_se_cancel_m_cmd(struct geni_se *se)
348 writel_relaxed(M_GENI_CMD_CANCEL, se->base + SE_GENI_M_CMD_CTRL_REG);
352 * geni_se_cancel_s_cmd() - Cancel the command configured in the secondary
354 * @se: Pointer to the concerned serial engine.
356 * This function is used to cancel the currently configured command in the
357 * secondary sequencer.
359 static inline void geni_se_cancel_s_cmd(struct geni_se *se)
361 writel_relaxed(S_GENI_CMD_CANCEL, se->base + SE_GENI_S_CMD_CTRL_REG);
365 * geni_se_abort_m_cmd() - Abort the command configured in the primary sequencer
366 * @se: Pointer to the concerned serial engine.
368 * This function is used to force abort the currently configured command in the
371 static inline void geni_se_abort_m_cmd(struct geni_se *se)
373 writel_relaxed(M_GENI_CMD_ABORT, se->base + SE_GENI_M_CMD_CTRL_REG);
377 * geni_se_abort_s_cmd() - Abort the command configured in the secondary
379 * @se: Pointer to the concerned serial engine.
381 * This function is used to force abort the currently configured command in the
382 * secondary sequencer.
384 static inline void geni_se_abort_s_cmd(struct geni_se *se)
386 writel_relaxed(S_GENI_CMD_ABORT, se->base + SE_GENI_S_CMD_CTRL_REG);
390 * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
391 * @se: Pointer to the concerned serial engine.
393 * This function is used to get the depth i.e. number of elements in the
394 * TX fifo of the serial engine.
396 * Return: TX fifo depth in units of FIFO words.
398 static inline u32 geni_se_get_tx_fifo_depth(struct geni_se *se)
402 val = readl_relaxed(se->base + SE_HW_PARAM_0);
404 return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;
408 * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
409 * @se: Pointer to the concerned serial engine.
411 * This function is used to get the width i.e. word size per element in the
412 * TX fifo of the serial engine.
414 * Return: TX fifo width in bits
416 static inline u32 geni_se_get_tx_fifo_width(struct geni_se *se)
420 val = readl_relaxed(se->base + SE_HW_PARAM_0);
422 return (val & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT;
426 * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
427 * @se: Pointer to the concerned serial engine.
429 * This function is used to get the depth i.e. number of elements in the
430 * RX fifo of the serial engine.
432 * Return: RX fifo depth in units of FIFO words
434 static inline u32 geni_se_get_rx_fifo_depth(struct geni_se *se)
438 val = readl_relaxed(se->base + SE_HW_PARAM_1);
440 return (val & RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT;
443 void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr);
445 void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode);
447 void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words,
448 bool msb_to_lsb, bool tx_cfg, bool rx_cfg);
450 int geni_se_resources_off(struct geni_se *se);
452 int geni_se_resources_on(struct geni_se *se);
454 int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl);
456 int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
457 unsigned int *index, unsigned long *res_freq,
460 int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
463 int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
466 void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
468 void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
470 int geni_icc_get(struct geni_se *se, const char *icc_ddr);
472 int geni_icc_set_bw(struct geni_se *se);
473 void geni_icc_set_tag(struct geni_se *se, u32 tag);
475 int geni_icc_enable(struct geni_se *se);
477 int geni_icc_disable(struct geni_se *se);