block: add QUEUE_FLAG_NOWAIT
[linux-2.6-microblaze.git] / include / linux / qcom-geni-se.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
4  */
5
6 #ifndef _LINUX_QCOM_GENI_SE
7 #define _LINUX_QCOM_GENI_SE
8
9 #include <linux/interconnect.h>
10
11 /* Transfer mode supported by GENI Serial Engines */
12 enum geni_se_xfer_mode {
13         GENI_SE_INVALID,
14         GENI_SE_FIFO,
15         GENI_SE_DMA,
16 };
17
18 /* Protocols supported by GENI Serial Engines */
19 enum geni_se_protocol_type {
20         GENI_SE_NONE,
21         GENI_SE_SPI,
22         GENI_SE_UART,
23         GENI_SE_I2C,
24         GENI_SE_I3C,
25 };
26
27 struct geni_wrapper;
28 struct clk;
29
30 enum geni_icc_path_index {
31         GENI_TO_CORE,
32         CPU_TO_GENI,
33         GENI_TO_DDR
34 };
35
36 struct geni_icc_path {
37         struct icc_path *path;
38         unsigned int avg_bw;
39 };
40
41 /**
42  * struct geni_se - GENI Serial Engine
43  * @base:               Base Address of the Serial Engine's register block
44  * @dev:                Pointer to the Serial Engine device
45  * @wrapper:            Pointer to the parent QUP Wrapper core
46  * @clk:                Handle to the core serial engine clock
47  * @num_clk_levels:     Number of valid clock levels in clk_perf_tbl
48  * @clk_perf_tbl:       Table of clock frequency input to serial engine clock
49  * @icc_paths:          Array of ICC paths for SE
50  * @opp_table:          Pointer to the OPP table
51  * @has_opp_table:      Specifies if the SE has an OPP table
52  */
53 struct geni_se {
54         void __iomem *base;
55         struct device *dev;
56         struct geni_wrapper *wrapper;
57         struct clk *clk;
58         unsigned int num_clk_levels;
59         unsigned long *clk_perf_tbl;
60         struct geni_icc_path icc_paths[3];
61         struct opp_table *opp_table;
62         bool has_opp_table;
63 };
64
65 /* Common SE registers */
66 #define GENI_FORCE_DEFAULT_REG          0x20
67 #define SE_GENI_STATUS                  0x40
68 #define GENI_SER_M_CLK_CFG              0x48
69 #define GENI_SER_S_CLK_CFG              0x4c
70 #define GENI_FW_REVISION_RO             0x68
71 #define SE_GENI_CLK_SEL                 0x7c
72 #define SE_GENI_DMA_MODE_EN             0x258
73 #define SE_GENI_M_CMD0                  0x600
74 #define SE_GENI_M_CMD_CTRL_REG          0x604
75 #define SE_GENI_M_IRQ_STATUS            0x610
76 #define SE_GENI_M_IRQ_EN                0x614
77 #define SE_GENI_M_IRQ_CLEAR             0x618
78 #define SE_GENI_S_CMD0                  0x630
79 #define SE_GENI_S_CMD_CTRL_REG          0x634
80 #define SE_GENI_S_IRQ_STATUS            0x640
81 #define SE_GENI_S_IRQ_EN                0x644
82 #define SE_GENI_S_IRQ_CLEAR             0x648
83 #define SE_GENI_TX_FIFOn                0x700
84 #define SE_GENI_RX_FIFOn                0x780
85 #define SE_GENI_TX_FIFO_STATUS          0x800
86 #define SE_GENI_RX_FIFO_STATUS          0x804
87 #define SE_GENI_TX_WATERMARK_REG        0x80c
88 #define SE_GENI_RX_WATERMARK_REG        0x810
89 #define SE_GENI_RX_RFR_WATERMARK_REG    0x814
90 #define SE_GENI_IOS                     0x908
91 #define SE_DMA_TX_IRQ_STAT              0xc40
92 #define SE_DMA_TX_IRQ_CLR               0xc44
93 #define SE_DMA_TX_FSM_RST               0xc58
94 #define SE_DMA_RX_IRQ_STAT              0xd40
95 #define SE_DMA_RX_IRQ_CLR               0xd44
96 #define SE_DMA_RX_FSM_RST               0xd58
97 #define SE_HW_PARAM_0                   0xe24
98 #define SE_HW_PARAM_1                   0xe28
99
100 /* GENI_FORCE_DEFAULT_REG fields */
101 #define FORCE_DEFAULT   BIT(0)
102
103 /* GENI_STATUS fields */
104 #define M_GENI_CMD_ACTIVE               BIT(0)
105 #define S_GENI_CMD_ACTIVE               BIT(12)
106
107 /* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
108 #define SER_CLK_EN                      BIT(0)
109 #define CLK_DIV_MSK                     GENMASK(15, 4)
110 #define CLK_DIV_SHFT                    4
111
112 /* GENI_FW_REVISION_RO fields */
113 #define FW_REV_PROTOCOL_MSK             GENMASK(15, 8)
114 #define FW_REV_PROTOCOL_SHFT            8
115
116 /* GENI_CLK_SEL fields */
117 #define CLK_SEL_MSK                     GENMASK(2, 0)
118
119 /* SE_GENI_DMA_MODE_EN */
120 #define GENI_DMA_MODE_EN                BIT(0)
121
122 /* GENI_M_CMD0 fields */
123 #define M_OPCODE_MSK                    GENMASK(31, 27)
124 #define M_OPCODE_SHFT                   27
125 #define M_PARAMS_MSK                    GENMASK(26, 0)
126
127 /* GENI_M_CMD_CTRL_REG */
128 #define M_GENI_CMD_CANCEL               BIT(2)
129 #define M_GENI_CMD_ABORT                BIT(1)
130 #define M_GENI_DISABLE                  BIT(0)
131
132 /* GENI_S_CMD0 fields */
133 #define S_OPCODE_MSK                    GENMASK(31, 27)
134 #define S_OPCODE_SHFT                   27
135 #define S_PARAMS_MSK                    GENMASK(26, 0)
136
137 /* GENI_S_CMD_CTRL_REG */
138 #define S_GENI_CMD_CANCEL               BIT(2)
139 #define S_GENI_CMD_ABORT                BIT(1)
140 #define S_GENI_DISABLE                  BIT(0)
141
142 /* GENI_M_IRQ_EN fields */
143 #define M_CMD_DONE_EN                   BIT(0)
144 #define M_CMD_OVERRUN_EN                BIT(1)
145 #define M_ILLEGAL_CMD_EN                BIT(2)
146 #define M_CMD_FAILURE_EN                BIT(3)
147 #define M_CMD_CANCEL_EN                 BIT(4)
148 #define M_CMD_ABORT_EN                  BIT(5)
149 #define M_TIMESTAMP_EN                  BIT(6)
150 #define M_RX_IRQ_EN                     BIT(7)
151 #define M_GP_SYNC_IRQ_0_EN              BIT(8)
152 #define M_GP_IRQ_0_EN                   BIT(9)
153 #define M_GP_IRQ_1_EN                   BIT(10)
154 #define M_GP_IRQ_2_EN                   BIT(11)
155 #define M_GP_IRQ_3_EN                   BIT(12)
156 #define M_GP_IRQ_4_EN                   BIT(13)
157 #define M_GP_IRQ_5_EN                   BIT(14)
158 #define M_IO_DATA_DEASSERT_EN           BIT(22)
159 #define M_IO_DATA_ASSERT_EN             BIT(23)
160 #define M_RX_FIFO_RD_ERR_EN             BIT(24)
161 #define M_RX_FIFO_WR_ERR_EN             BIT(25)
162 #define M_RX_FIFO_WATERMARK_EN          BIT(26)
163 #define M_RX_FIFO_LAST_EN               BIT(27)
164 #define M_TX_FIFO_RD_ERR_EN             BIT(28)
165 #define M_TX_FIFO_WR_ERR_EN             BIT(29)
166 #define M_TX_FIFO_WATERMARK_EN          BIT(30)
167 #define M_SEC_IRQ_EN                    BIT(31)
168 #define M_COMMON_GENI_M_IRQ_EN  (GENMASK(6, 1) | \
169                                 M_IO_DATA_DEASSERT_EN | \
170                                 M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
171                                 M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
172                                 M_TX_FIFO_WR_ERR_EN)
173
174 /* GENI_S_IRQ_EN fields */
175 #define S_CMD_DONE_EN                   BIT(0)
176 #define S_CMD_OVERRUN_EN                BIT(1)
177 #define S_ILLEGAL_CMD_EN                BIT(2)
178 #define S_CMD_FAILURE_EN                BIT(3)
179 #define S_CMD_CANCEL_EN                 BIT(4)
180 #define S_CMD_ABORT_EN                  BIT(5)
181 #define S_GP_SYNC_IRQ_0_EN              BIT(8)
182 #define S_GP_IRQ_0_EN                   BIT(9)
183 #define S_GP_IRQ_1_EN                   BIT(10)
184 #define S_GP_IRQ_2_EN                   BIT(11)
185 #define S_GP_IRQ_3_EN                   BIT(12)
186 #define S_GP_IRQ_4_EN                   BIT(13)
187 #define S_GP_IRQ_5_EN                   BIT(14)
188 #define S_IO_DATA_DEASSERT_EN           BIT(22)
189 #define S_IO_DATA_ASSERT_EN             BIT(23)
190 #define S_RX_FIFO_RD_ERR_EN             BIT(24)
191 #define S_RX_FIFO_WR_ERR_EN             BIT(25)
192 #define S_RX_FIFO_WATERMARK_EN          BIT(26)
193 #define S_RX_FIFO_LAST_EN               BIT(27)
194 #define S_COMMON_GENI_S_IRQ_EN  (GENMASK(5, 1) | GENMASK(13, 9) | \
195                                  S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
196
197 /*  GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
198 #define WATERMARK_MSK                   GENMASK(5, 0)
199
200 /* GENI_TX_FIFO_STATUS fields */
201 #define TX_FIFO_WC                      GENMASK(27, 0)
202
203 /*  GENI_RX_FIFO_STATUS fields */
204 #define RX_LAST                         BIT(31)
205 #define RX_LAST_BYTE_VALID_MSK          GENMASK(30, 28)
206 #define RX_LAST_BYTE_VALID_SHFT         28
207 #define RX_FIFO_WC_MSK                  GENMASK(24, 0)
208
209 /* SE_GENI_IOS fields */
210 #define IO2_DATA_IN                     BIT(1)
211 #define RX_DATA_IN                      BIT(0)
212
213 /* SE_DMA_TX_IRQ_STAT Register fields */
214 #define TX_DMA_DONE                     BIT(0)
215 #define TX_EOT                          BIT(1)
216 #define TX_SBE                          BIT(2)
217 #define TX_RESET_DONE                   BIT(3)
218
219 /* SE_DMA_RX_IRQ_STAT Register fields */
220 #define RX_DMA_DONE                     BIT(0)
221 #define RX_EOT                          BIT(1)
222 #define RX_SBE                          BIT(2)
223 #define RX_RESET_DONE                   BIT(3)
224 #define RX_FLUSH_DONE                   BIT(4)
225 #define RX_GENI_GP_IRQ                  GENMASK(10, 5)
226 #define RX_GENI_CANCEL_IRQ              BIT(11)
227 #define RX_GENI_GP_IRQ_EXT              GENMASK(13, 12)
228
229 /* SE_HW_PARAM_0 fields */
230 #define TX_FIFO_WIDTH_MSK               GENMASK(29, 24)
231 #define TX_FIFO_WIDTH_SHFT              24
232 #define TX_FIFO_DEPTH_MSK               GENMASK(21, 16)
233 #define TX_FIFO_DEPTH_SHFT              16
234
235 /* SE_HW_PARAM_1 fields */
236 #define RX_FIFO_WIDTH_MSK               GENMASK(29, 24)
237 #define RX_FIFO_WIDTH_SHFT              24
238 #define RX_FIFO_DEPTH_MSK               GENMASK(21, 16)
239 #define RX_FIFO_DEPTH_SHFT              16
240
241 #define HW_VER_MAJOR_MASK               GENMASK(31, 28)
242 #define HW_VER_MAJOR_SHFT               28
243 #define HW_VER_MINOR_MASK               GENMASK(27, 16)
244 #define HW_VER_MINOR_SHFT               16
245 #define HW_VER_STEP_MASK                GENMASK(15, 0)
246
247 #define GENI_SE_VERSION_MAJOR(ver) ((ver & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT)
248 #define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT)
249 #define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK)
250
251 /*
252  * Define bandwidth thresholds that cause the underlying Core 2X interconnect
253  * clock to run at the named frequency. These baseline values are recommended
254  * by the hardware team, and are not dynamically scaled with GENI bandwidth
255  * beyond basic on/off.
256  */
257 #define CORE_2X_19_2_MHZ                960
258 #define CORE_2X_50_MHZ                  2500
259 #define CORE_2X_100_MHZ                 5000
260 #define CORE_2X_150_MHZ                 7500
261 #define CORE_2X_200_MHZ                 10000
262 #define CORE_2X_236_MHZ                 16383
263
264 #define GENI_DEFAULT_BW                 Bps_to_icc(1000)
265
266 #if IS_ENABLED(CONFIG_QCOM_GENI_SE)
267
268 u32 geni_se_get_qup_hw_version(struct geni_se *se);
269
270 /**
271  * geni_se_read_proto() - Read the protocol configured for a serial engine
272  * @se:         Pointer to the concerned serial engine.
273  *
274  * Return: Protocol value as configured in the serial engine.
275  */
276 static inline u32 geni_se_read_proto(struct geni_se *se)
277 {
278         u32 val;
279
280         val = readl_relaxed(se->base + GENI_FW_REVISION_RO);
281
282         return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;
283 }
284
285 /**
286  * geni_se_setup_m_cmd() - Setup the primary sequencer
287  * @se:         Pointer to the concerned serial engine.
288  * @cmd:        Command/Operation to setup in the primary sequencer.
289  * @params:     Parameter for the sequencer command.
290  *
291  * This function is used to configure the primary sequencer with the
292  * command and its associated parameters.
293  */
294 static inline void geni_se_setup_m_cmd(struct geni_se *se, u32 cmd, u32 params)
295 {
296         u32 m_cmd;
297
298         m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
299         writel_relaxed(m_cmd, se->base + SE_GENI_M_CMD0);
300 }
301
302 /**
303  * geni_se_setup_s_cmd() - Setup the secondary sequencer
304  * @se:         Pointer to the concerned serial engine.
305  * @cmd:        Command/Operation to setup in the secondary sequencer.
306  * @params:     Parameter for the sequencer command.
307  *
308  * This function is used to configure the secondary sequencer with the
309  * command and its associated parameters.
310  */
311 static inline void geni_se_setup_s_cmd(struct geni_se *se, u32 cmd, u32 params)
312 {
313         u32 s_cmd;
314
315         s_cmd = readl_relaxed(se->base + SE_GENI_S_CMD0);
316         s_cmd &= ~(S_OPCODE_MSK | S_PARAMS_MSK);
317         s_cmd |= (cmd << S_OPCODE_SHFT);
318         s_cmd |= (params & S_PARAMS_MSK);
319         writel_relaxed(s_cmd, se->base + SE_GENI_S_CMD0);
320 }
321
322 /**
323  * geni_se_cancel_m_cmd() - Cancel the command configured in the primary
324  *                          sequencer
325  * @se: Pointer to the concerned serial engine.
326  *
327  * This function is used to cancel the currently configured command in the
328  * primary sequencer.
329  */
330 static inline void geni_se_cancel_m_cmd(struct geni_se *se)
331 {
332         writel_relaxed(M_GENI_CMD_CANCEL, se->base + SE_GENI_M_CMD_CTRL_REG);
333 }
334
335 /**
336  * geni_se_cancel_s_cmd() - Cancel the command configured in the secondary
337  *                          sequencer
338  * @se: Pointer to the concerned serial engine.
339  *
340  * This function is used to cancel the currently configured command in the
341  * secondary sequencer.
342  */
343 static inline void geni_se_cancel_s_cmd(struct geni_se *se)
344 {
345         writel_relaxed(S_GENI_CMD_CANCEL, se->base + SE_GENI_S_CMD_CTRL_REG);
346 }
347
348 /**
349  * geni_se_abort_m_cmd() - Abort the command configured in the primary sequencer
350  * @se: Pointer to the concerned serial engine.
351  *
352  * This function is used to force abort the currently configured command in the
353  * primary sequencer.
354  */
355 static inline void geni_se_abort_m_cmd(struct geni_se *se)
356 {
357         writel_relaxed(M_GENI_CMD_ABORT, se->base + SE_GENI_M_CMD_CTRL_REG);
358 }
359
360 /**
361  * geni_se_abort_s_cmd() - Abort the command configured in the secondary
362  *                         sequencer
363  * @se: Pointer to the concerned serial engine.
364  *
365  * This function is used to force abort the currently configured command in the
366  * secondary sequencer.
367  */
368 static inline void geni_se_abort_s_cmd(struct geni_se *se)
369 {
370         writel_relaxed(S_GENI_CMD_ABORT, se->base + SE_GENI_S_CMD_CTRL_REG);
371 }
372
373 /**
374  * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
375  * @se: Pointer to the concerned serial engine.
376  *
377  * This function is used to get the depth i.e. number of elements in the
378  * TX fifo of the serial engine.
379  *
380  * Return: TX fifo depth in units of FIFO words.
381  */
382 static inline u32 geni_se_get_tx_fifo_depth(struct geni_se *se)
383 {
384         u32 val;
385
386         val = readl_relaxed(se->base + SE_HW_PARAM_0);
387
388         return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;
389 }
390
391 /**
392  * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
393  * @se: Pointer to the concerned serial engine.
394  *
395  * This function is used to get the width i.e. word size per element in the
396  * TX fifo of the serial engine.
397  *
398  * Return: TX fifo width in bits
399  */
400 static inline u32 geni_se_get_tx_fifo_width(struct geni_se *se)
401 {
402         u32 val;
403
404         val = readl_relaxed(se->base + SE_HW_PARAM_0);
405
406         return (val & TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT;
407 }
408
409 /**
410  * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
411  * @se: Pointer to the concerned serial engine.
412  *
413  * This function is used to get the depth i.e. number of elements in the
414  * RX fifo of the serial engine.
415  *
416  * Return: RX fifo depth in units of FIFO words
417  */
418 static inline u32 geni_se_get_rx_fifo_depth(struct geni_se *se)
419 {
420         u32 val;
421
422         val = readl_relaxed(se->base + SE_HW_PARAM_1);
423
424         return (val & RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT;
425 }
426
427 void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr);
428
429 void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode);
430
431 void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words,
432                             bool msb_to_lsb, bool tx_cfg, bool rx_cfg);
433
434 int geni_se_resources_off(struct geni_se *se);
435
436 int geni_se_resources_on(struct geni_se *se);
437
438 int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl);
439
440 int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq,
441                            unsigned int *index, unsigned long *res_freq,
442                            bool exact);
443
444 int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
445                         dma_addr_t *iova);
446
447 int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
448                         dma_addr_t *iova);
449
450 void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
451
452 void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
453
454 int geni_icc_get(struct geni_se *se, const char *icc_ddr);
455
456 int geni_icc_set_bw(struct geni_se *se);
457 void geni_icc_set_tag(struct geni_se *se, u32 tag);
458
459 int geni_icc_enable(struct geni_se *se);
460
461 int geni_icc_disable(struct geni_se *se);
462
463 void geni_remove_earlycon_icc_vote(void);
464 #endif
465 #endif