blob: 59471076f5cd4aad5c3859c6df881d00aaf7f870 [file] [log] [blame]
Sagar Dharia7c927c02016-11-23 11:51:43 -07001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef _LINUX_QCOM_GENI_SE
16#define _LINUX_QCOM_GENI_SE
Girish Mahadevanebeed352016-11-23 10:59:29 -070017#include <linux/clk.h>
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060018#include <linux/dma-direction.h>
19#include <linux/io.h>
20#include <linux/list.h>
Girish Mahadevanebeed352016-11-23 10:59:29 -070021#include <linux/msm-bus.h>
22#include <linux/msm-bus-board.h>
Sagar Dharia7c927c02016-11-23 11:51:43 -070023
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060024/* Transfer mode supported by GENI Serial Engines */
Sagar Dharia7c927c02016-11-23 11:51:43 -070025enum se_xfer_mode {
26 INVALID,
27 FIFO_MODE,
28 GSI_DMA,
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060029 SE_DMA,
Sagar Dharia7c927c02016-11-23 11:51:43 -070030};
31
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060032/* Protocols supported by GENI Serial Engines */
Sagar Dharia7c927c02016-11-23 11:51:43 -070033enum se_protocol_types {
34 NONE,
35 SPI,
36 UART,
37 I2C,
38 I3C
39};
40
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060041/**
42 * struct geni_se_rsc - GENI Serial Engine Resource
43 * @wrapper_dev: Pointer to the parent QUPv3 core.
44 * @se_clk: Handle to the core serial engine clock.
45 * @m_ahb_clk: Handle to the primary AHB clock.
46 * @s_ahb_clk: Handle to the secondary AHB clock.
47 * @ab_list: List Head of Average bus banwidth list.
48 * @ab: Average bus bandwidth request value.
49 * @ib_list: List Head of Instantaneous bus banwidth list.
50 * @ib: Instantaneous bus bandwidth request value.
51 * @geni_pinctrl: Handle to the pinctrl configuration.
52 * @geni_gpio_active: Handle to the default/active pinctrl state.
53 * @geni_gpi_sleep: Handle to the sleep pinctrl state.
54 */
Girish Mahadevanebeed352016-11-23 10:59:29 -070055struct se_geni_rsc {
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060056 struct device *wrapper_dev;
Girish Mahadevanebeed352016-11-23 10:59:29 -070057 struct clk *se_clk;
58 struct clk *m_ahb_clk;
59 struct clk *s_ahb_clk;
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060060 struct list_head ab_list;
Girish Mahadevanebeed352016-11-23 10:59:29 -070061 unsigned long ab;
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060062 struct list_head ib_list;
Girish Mahadevanebeed352016-11-23 10:59:29 -070063 unsigned long ib;
64 struct pinctrl *geni_pinctrl;
65 struct pinctrl_state *geni_gpio_active;
66 struct pinctrl_state *geni_gpio_sleep;
67};
68
69#define PINCTRL_DEFAULT "default"
70#define PINCTRL_SLEEP "sleep"
71
Girish Mahadevan2ef85af2017-02-14 14:42:22 -070072/* Common SE registers */
Sagar Dharia7c927c02016-11-23 11:51:43 -070073#define GENI_INIT_CFG_REVISION (0x0)
74#define GENI_S_INIT_CFG_REVISION (0x4)
75#define GENI_FORCE_DEFAULT_REG (0x20)
76#define GENI_OUTPUT_CTRL (0x24)
77#define GENI_CGC_CTRL (0x28)
78#define SE_GENI_STATUS (0x40)
79#define GENI_SER_M_CLK_CFG (0x48)
80#define GENI_SER_S_CLK_CFG (0x4C)
81#define GENI_CLK_CTRL_RO (0x60)
82#define GENI_IF_DISABLE_RO (0x64)
83#define GENI_FW_REVISION_RO (0x68)
84#define GENI_FW_S_REVISION_RO (0x6C)
85#define SE_GENI_CLK_SEL (0x7C)
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060086#define SE_GENI_BYTE_GRAN (0x254)
Sagar Dharia7c927c02016-11-23 11:51:43 -070087#define SE_GENI_DMA_MODE_EN (0x258)
88#define SE_GENI_TX_PACKING_CFG0 (0x260)
89#define SE_GENI_TX_PACKING_CFG1 (0x264)
90#define SE_GENI_RX_PACKING_CFG0 (0x284)
91#define SE_GENI_RX_PACKING_CFG1 (0x288)
92#define SE_GENI_M_CMD0 (0x600)
93#define SE_GENI_M_CMD_CTRL_REG (0x604)
94#define SE_GENI_M_IRQ_STATUS (0x610)
95#define SE_GENI_M_IRQ_EN (0x614)
96#define SE_GENI_M_IRQ_CLEAR (0x618)
97#define SE_GENI_S_CMD0 (0x630)
98#define SE_GENI_S_CMD_CTRL_REG (0x634)
99#define SE_GENI_S_IRQ_STATUS (0x640)
100#define SE_GENI_S_IRQ_EN (0x644)
101#define SE_GENI_S_IRQ_CLEAR (0x648)
102#define SE_GENI_TX_FIFOn (0x700)
103#define SE_GENI_RX_FIFOn (0x780)
104#define SE_GENI_TX_FIFO_STATUS (0x800)
105#define SE_GENI_RX_FIFO_STATUS (0x804)
106#define SE_GENI_TX_WATERMARK_REG (0x80C)
107#define SE_GENI_RX_WATERMARK_REG (0x810)
108#define SE_GENI_RX_RFR_WATERMARK_REG (0x814)
Girish Mahadevan7115f4e2017-03-15 15:18:34 -0600109#define SE_GENI_IOS (0x908)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700110#define SE_GENI_M_GP_LENGTH (0x910)
111#define SE_GENI_S_GP_LENGTH (0x914)
Girish Mahadevana95a3612017-04-19 11:49:24 -0600112#define SE_GSI_EVENT_EN (0xE18)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700113#define SE_IRQ_EN (0xE1C)
114#define SE_HW_PARAM_0 (0xE24)
115#define SE_HW_PARAM_1 (0xE28)
116#define SE_DMA_GENERAL_CFG (0xE30)
117
118/* GENI_OUTPUT_CTRL fields */
119#define DEFAULT_IO_OUTPUT_CTRL_MSK (GENMASK(6, 0))
120
121/* GENI_FORCE_DEFAULT_REG fields */
122#define FORCE_DEFAULT (BIT(0))
123
124/* GENI_CGC_CTRL fields */
125#define CFG_AHB_CLK_CGC_ON (BIT(0))
126#define CFG_AHB_WR_ACLK_CGC_ON (BIT(1))
127#define DATA_AHB_CLK_CGC_ON (BIT(2))
128#define SCLK_CGC_ON (BIT(3))
129#define TX_CLK_CGC_ON (BIT(4))
130#define RX_CLK_CGC_ON (BIT(5))
131#define EXT_CLK_CGC_ON (BIT(6))
132#define PROG_RAM_HCLK_OFF (BIT(8))
133#define PROG_RAM_SCLK_OFF (BIT(9))
134#define DEFAULT_CGC_EN (GENMASK(6, 0))
135
136/* GENI_STATUS fields */
137#define M_GENI_CMD_ACTIVE (BIT(0))
138#define S_GENI_CMD_ACTIVE (BIT(12))
139
140/* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
141#define SER_CLK_EN (BIT(0))
142#define CLK_DIV_MSK (GENMASK(15, 4))
143#define CLK_DIV_SHFT (4)
144
145/* CLK_CTRL_RO fields */
146
147/* IF_DISABLE_RO fields */
148
149/* FW_REVISION_RO fields */
150#define FW_REV_PROTOCOL_MSK (GENMASK(15, 8))
151#define FW_REV_PROTOCOL_SHFT (8)
152
Girish Mahadevan2ef85af2017-02-14 14:42:22 -0700153/* GENI_CLK_SEL fields */
154#define CLK_SEL_MSK (GENMASK(2, 0))
155
Sagar Dharia7c927c02016-11-23 11:51:43 -0700156/* SE_GENI_DMA_MODE_EN */
157#define GENI_DMA_MODE_EN (BIT(0))
158
159/* GENI_M_CMD0 fields */
160#define M_OPCODE_MSK (GENMASK(31, 27))
161#define M_OPCODE_SHFT (27)
162#define M_PARAMS_MSK (GENMASK(26, 0))
163
164/* GENI_M_CMD_CTRL_REG */
165#define M_GENI_CMD_CANCEL BIT(2)
166#define M_GENI_CMD_ABORT BIT(1)
167#define M_GENI_DISABLE BIT(0)
168
169/* GENI_S_CMD0 fields */
170#define S_OPCODE_MSK (GENMASK(31, 27))
171#define S_OPCODE_SHFT (27)
172#define S_PARAMS_MSK (GENMASK(26, 0))
173
174/* GENI_S_CMD_CTRL_REG */
175#define S_GENI_CMD_CANCEL (BIT(2))
176#define S_GENI_CMD_ABORT (BIT(1))
177#define S_GENI_DISABLE (BIT(0))
178
179/* GENI_M_IRQ_EN fields */
180#define M_CMD_DONE_EN (BIT(0))
181#define M_CMD_OVERRUN_EN (BIT(1))
182#define M_ILLEGAL_CMD_EN (BIT(2))
183#define M_CMD_FAILURE_EN (BIT(3))
184#define M_CMD_CANCEL_EN (BIT(4))
185#define M_CMD_ABORT_EN (BIT(5))
186#define M_TIMESTAMP_EN (BIT(6))
187#define M_RX_IRQ_EN (BIT(7))
188#define M_GP_SYNC_IRQ_0_EN (BIT(8))
189#define M_GP_IRQ_0_EN (BIT(9))
190#define M_GP_IRQ_1_EN (BIT(10))
191#define M_GP_IRQ_2_EN (BIT(11))
192#define M_GP_IRQ_3_EN (BIT(12))
193#define M_GP_IRQ_4_EN (BIT(13))
194#define M_GP_IRQ_5_EN (BIT(14))
195#define M_IO_DATA_DEASSERT_EN (BIT(22))
196#define M_IO_DATA_ASSERT_EN (BIT(23))
197#define M_RX_FIFO_RD_ERR_EN (BIT(24))
198#define M_RX_FIFO_WR_ERR_EN (BIT(25))
199#define M_RX_FIFO_WATERMARK_EN (BIT(26))
200#define M_RX_FIFO_LAST_EN (BIT(27))
201#define M_TX_FIFO_RD_ERR_EN (BIT(28))
202#define M_TX_FIFO_WR_ERR_EN (BIT(29))
203#define M_TX_FIFO_WATERMARK_EN (BIT(30))
204#define M_SEC_IRQ_EN (BIT(31))
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600205#define M_COMMON_GENI_M_IRQ_EN (GENMASK(6, 1) | \
206 M_IO_DATA_DEASSERT_EN | \
Sagar Dharia7c927c02016-11-23 11:51:43 -0700207 M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
208 M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600209 M_TX_FIFO_WR_ERR_EN)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700210
211/* GENI_S_IRQ_EN fields */
212#define S_CMD_DONE_EN (BIT(0))
213#define S_CMD_OVERRUN_EN (BIT(1))
214#define S_ILLEGAL_CMD_EN (BIT(2))
215#define S_CMD_FAILURE_EN (BIT(3))
216#define S_CMD_CANCEL_EN (BIT(4))
217#define S_CMD_ABORT_EN (BIT(5))
218#define S_GP_SYNC_IRQ_0_EN (BIT(8))
219#define S_GP_IRQ_0_EN (BIT(9))
220#define S_GP_IRQ_1_EN (BIT(10))
221#define S_GP_IRQ_2_EN (BIT(11))
222#define S_GP_IRQ_3_EN (BIT(12))
223#define S_GP_IRQ_4_EN (BIT(13))
224#define S_GP_IRQ_5_EN (BIT(14))
225#define S_IO_DATA_DEASSERT_EN (BIT(22))
226#define S_IO_DATA_ASSERT_EN (BIT(23))
227#define S_RX_FIFO_RD_ERR_EN (BIT(24))
228#define S_RX_FIFO_WR_ERR_EN (BIT(25))
229#define S_RX_FIFO_WATERMARK_EN (BIT(26))
230#define S_RX_FIFO_LAST_EN (BIT(27))
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600231#define S_COMMON_GENI_S_IRQ_EN (GENMASK(5, 1) | GENMASK(13, 9) | \
Sagar Dharia7c927c02016-11-23 11:51:43 -0700232 S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
233
234/* GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
235#define WATERMARK_MSK (GENMASK(5, 0))
236
237/* GENI_TX_FIFO_STATUS fields */
238#define TX_FIFO_WC (GENMASK(27, 0))
239
240/* GENI_RX_FIFO_STATUS fields */
241#define RX_LAST (BIT(31))
242#define RX_LAST_BYTE_VALID_MSK (GENMASK(30, 28))
243#define RX_LAST_BYTE_VALID_SHFT (28)
244#define RX_FIFO_WC_MSK (GENMASK(24, 0))
245
Girish Mahadevana95a3612017-04-19 11:49:24 -0600246/* SE_GSI_EVENT_EN fields */
247#define DMA_RX_EVENT_EN (BIT(0))
248#define DMA_TX_EVENT_EN (BIT(1))
249#define GENI_M_EVENT_EN (BIT(2))
250#define GENI_S_EVENT_EN (BIT(3))
251
Girish Mahadevan7115f4e2017-03-15 15:18:34 -0600252/* SE_GENI_IOS fields */
253#define IO2_DATA_IN (BIT(1))
254#define RX_DATA_IN (BIT(0))
255
Sagar Dharia7c927c02016-11-23 11:51:43 -0700256/* SE_IRQ_EN fields */
257#define DMA_RX_IRQ_EN (BIT(0))
258#define DMA_TX_IRQ_EN (BIT(1))
259#define GENI_M_IRQ_EN (BIT(2))
260#define GENI_S_IRQ_EN (BIT(3))
261
262/* SE_HW_PARAM_0 fields */
263#define TX_FIFO_WIDTH_MSK (GENMASK(29, 24))
264#define TX_FIFO_WIDTH_SHFT (24)
265#define TX_FIFO_DEPTH_MSK (GENMASK(21, 16))
266#define TX_FIFO_DEPTH_SHFT (16)
267
268/* SE_HW_PARAM_1 fields */
269#define RX_FIFO_WIDTH_MSK (GENMASK(29, 24))
270#define RX_FIFO_WIDTH_SHFT (24)
271#define RX_FIFO_DEPTH_MSK (GENMASK(21, 16))
272#define RX_FIFO_DEPTH_SHFT (16)
273
274/* SE_DMA_GENERAL_CFG */
275#define DMA_RX_CLK_CGC_ON (BIT(0))
276#define DMA_TX_CLK_CGC_ON (BIT(1))
277#define DMA_AHB_SLV_CFG_ON (BIT(2))
278#define AHB_SEC_SLV_CLK_CGC_ON (BIT(3))
279#define DUMMY_RX_NON_BUFFERABLE (BIT(4))
280#define RX_DMA_ZERO_PADDING_EN (BIT(5))
281#define RX_DMA_IRQ_DELAY_MSK (GENMASK(8, 6))
282#define RX_DMA_IRQ_DELAY_SHFT (6)
283
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600284#define SE_DMA_TX_PTR_L (0xC30)
285#define SE_DMA_TX_PTR_H (0xC34)
286#define SE_DMA_TX_ATTR (0xC38)
287#define SE_DMA_TX_LEN (0xC3C)
288#define SE_DMA_TX_IRQ_STAT (0xC40)
289#define SE_DMA_TX_IRQ_CLR (0xC44)
290#define SE_DMA_TX_IRQ_EN (0xC48)
291#define SE_DMA_TX_IRQ_EN_SET (0xC4C)
292#define SE_DMA_TX_IRQ_EN_CLR (0xC50)
293#define SE_DMA_TX_LEN_IN (0xC54)
294#define SE_DMA_TX_FSM_RST (0xC58)
295#define SE_DMA_TX_MAX_BURST (0xC5C)
296
297#define SE_DMA_RX_PTR_L (0xD30)
298#define SE_DMA_RX_PTR_H (0xD34)
299#define SE_DMA_RX_ATTR (0xD38)
300#define SE_DMA_RX_LEN (0xD3C)
301#define SE_DMA_RX_IRQ_STAT (0xD40)
302#define SE_DMA_RX_IRQ_CLR (0xD44)
303#define SE_DMA_RX_IRQ_EN (0xD48)
304#define SE_DMA_RX_IRQ_EN_SET (0xD4C)
305#define SE_DMA_RX_IRQ_EN_CLR (0xD50)
306#define SE_DMA_RX_LEN_IN (0xD54)
307#define SE_DMA_RX_FSM_RST (0xD58)
308#define SE_DMA_RX_MAX_BURST (0xD5C)
309#define SE_DMA_RX_FLUSH (0xD60)
310
Karthikeyan Ramasubramaniana5766572017-04-19 11:31:42 -0600311/* SE_DMA_TX_IRQ_STAT Register fields */
312#define TX_DMA_DONE (BIT(0))
313#define TX_EOT (BIT(1))
314#define TX_SBE (BIT(2))
315#define TX_RESET_DONE (BIT(3))
316
317/* SE_DMA_RX_IRQ_STAT Register fields */
318#define RX_DMA_DONE (BIT(0))
319#define RX_EOT (BIT(1))
320#define RX_SBE (BIT(2))
321#define RX_RESET_DONE (BIT(3))
322#define RX_FLUSH_DONE (BIT(4))
323#define RX_GENI_GP_IRQ (GENMASK(10, 5))
324#define RX_GENI_CANCEL_IRQ (BIT(11))
325#define RX_GENI_GP_IRQ_EXT (GENMASK(13, 12))
326
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600327#define DEFAULT_BUS_WIDTH (4)
328#define DEFAULT_SE_CLK (19200000)
329
330#define GENI_SE_ERR(log_ctx, print, dev, x...) do { \
331if (log_ctx) \
332 ipc_log_string(log_ctx, x); \
333if (print) { \
334 if (dev) \
335 dev_err((dev), x); \
336 else \
337 pr_err(x); \
338} \
339} while (0)
340
341#define GENI_SE_DBG(log_ctx, print, dev, x...) do { \
342if (log_ctx) \
343 ipc_log_string(log_ctx, x); \
344if (print) { \
345 if (dev) \
346 dev_dbg((dev), x); \
347 else \
348 pr_debug(x); \
349} \
350} while (0)
351
352
353#ifdef CONFIG_QCOM_GENI_SE
354/**
355 * geni_read_reg_nolog() - Helper function to read from a GENI register
356 * @base: Base address of the serial engine's register block.
357 * @offset: Offset within the serial engine's register block.
358 *
359 * Return: Return the contents of the register.
360 */
361unsigned int geni_read_reg_nolog(void __iomem *base, int offset);
362
363/**
364 * geni_write_reg_nolog() - Helper function to write into a GENI register
365 * @value: Value to be written into the register.
366 * @base: Base address of the serial engine's register block.
367 * @offset: Offset within the serial engine's register block.
368 */
369void geni_write_reg_nolog(unsigned int value, void __iomem *base, int offset);
370
371/**
372 * geni_read_reg() - Helper function to read from a GENI register
373 * @base: Base address of the serial engine's register block.
374 * @offset: Offset within the serial engine's register block.
375 *
376 * Return: Return the contents of the register.
377 */
378unsigned int geni_read_reg(void __iomem *base, int offset);
379
380/**
381 * geni_write_reg() - Helper function to write into a GENI register
382 * @value: Value to be written into the register.
383 * @base: Base address of the serial engine's register block.
384 * @offset: Offset within the serial engine's register block.
385 */
386void geni_write_reg(unsigned int value, void __iomem *base, int offset);
387
388/**
389 * get_se_proto() - Read the protocol configured for a serial engine
390 * @base: Base address of the serial engine's register block.
391 *
392 * Return: Protocol value as configured in the serial engine.
393 */
394int get_se_proto(void __iomem *base);
395
396/**
397 * geni_se_init() - Initialize the GENI Serial Engine
398 * @base: Base address of the serial engine's register block.
399 * @rx_wm: Receive watermark to be configured.
400 * @rx_rfr_wm: Ready-for-receive watermark to be configured.
401 *
402 * This function is used to initialize the GENI serial engine, configure
403 * the transfer mode, receive watermark and ready-for-receive watermarks.
404 *
405 * Return: 0 on success, standard Linux error codes on failure/error.
406 */
407int geni_se_init(void __iomem *base, unsigned int rx_wm, unsigned int rx_rfr);
408
409/**
410 * geni_se_select_mode() - Select the serial engine transfer mode
411 * @base: Base address of the serial engine's register block.
412 * @mode: Transfer mode to be selected.
413 *
414 * Return: 0 on success, standard Linux error codes on failure.
415 */
416int geni_se_select_mode(void __iomem *base, int mode);
417
418/**
419 * geni_setup_m_cmd() - Setup the primary sequencer
420 * @base: Base address of the serial engine's register block.
421 * @cmd: Command/Operation to setup in the primary sequencer.
422 * @params: Parameter for the sequencer command.
423 *
424 * This function is used to configure the primary sequencer with the
425 * command and its assoicated parameters.
426 */
427void geni_setup_m_cmd(void __iomem *base, u32 cmd, u32 params);
428
429/**
430 * geni_setup_s_cmd() - Setup the secondary sequencer
431 * @base: Base address of the serial engine's register block.
432 * @cmd: Command/Operation to setup in the secondary sequencer.
433 * @params: Parameter for the sequencer command.
434 *
435 * This function is used to configure the secondary sequencer with the
436 * command and its assoicated parameters.
437 */
438void geni_setup_s_cmd(void __iomem *base, u32 cmd, u32 params);
439
440/**
441 * geni_cancel_m_cmd() - Cancel the command configured in the primary sequencer
442 * @base: Base address of the serial engine's register block.
443 *
444 * This function is used to cancel the currently configured command in the
445 * primary sequencer.
446 */
447void geni_cancel_m_cmd(void __iomem *base);
448
449/**
450 * geni_cancel_s_cmd() - Cancel the command configured in the secondary
451 * sequencer
452 * @base: Base address of the serial engine's register block.
453 *
454 * This function is used to cancel the currently configured command in the
455 * secondary sequencer.
456 */
457void geni_cancel_s_cmd(void __iomem *base);
458
459/**
460 * geni_abort_m_cmd() - Abort the command configured in the primary sequencer
461 * @base: Base address of the serial engine's register block.
462 *
463 * This function is used to force abort the currently configured command in the
464 * primary sequencer.
465 */
466void geni_abort_m_cmd(void __iomem *base);
467
468/**
469 * geni_abort_s_cmd() - Abort the command configured in the secondary
470 * sequencer
471 * @base: Base address of the serial engine's register block.
472 *
473 * This function is used to force abort the currently configured command in the
474 * secondary sequencer.
475 */
476void geni_abort_s_cmd(void __iomem *base);
477
478/**
479 * get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
480 * @base: Base address of the serial engine's register block.
481 *
482 * This function is used to get the depth i.e. number of elements in the
483 * TX fifo of the serial engine.
484 *
485 * Return: TX fifo depth in units of FIFO words.
486 */
487int get_tx_fifo_depth(void __iomem *base);
488
489/**
490 * get_tx_fifo_width() - Get the TX fifo width of the serial engine
491 * @base: Base address of the serial engine's register block.
492 *
493 * This function is used to get the width i.e. word size per element in the
494 * TX fifo of the serial engine.
495 *
496 * Return: TX fifo width in bits.
497 */
498int get_tx_fifo_width(void __iomem *base);
499
500/**
501 * get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
502 * @base: Base address of the serial engine's register block.
503 *
504 * This function is used to get the depth i.e. number of elements in the
505 * RX fifo of the serial engine.
506 *
507 * Return: RX fifo depth in units of FIFO words.
508 */
509int get_rx_fifo_depth(void __iomem *base);
510
511/**
512 * se_get_packing_config() - Get the packing configuration based on input
513 * @bpw: Bits of data per transfer word.
514 * @pack_words: Number of words per fifo element.
515 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
516 * @cfg0: Output buffer to hold the first half of configuration.
517 * @cfg1: Output buffer to hold the second half of configuration.
518 *
519 * This function is used to calculate the packing configuration based on
520 * the input packing requirement and the configuration logic.
521 */
522void se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
523 unsigned long *cfg0, unsigned long *cfg1);
524
525/**
526 * se_config_packing() - Packing configuration of the serial engine
527 * @base: Base address of the serial engine's register block.
528 * @bpw: Bits of data per transfer word.
529 * @pack_words: Number of words per fifo element.
530 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
531 *
532 * This function is used to configure the packing rules for the current
533 * transfer.
534 */
535void se_config_packing(void __iomem *base, int bpw, int pack_words,
536 bool msb_to_lsb);
537
538/**
539 * se_geni_resources_off() - Turn off resources associated with the serial
540 * engine
541 * @rsc: Handle to resources associated with the serial engine.
542 *
543 * Return: 0 on success, standard Linux error codes on failure/error.
544 */
545int se_geni_resources_off(struct se_geni_rsc *rsc);
546
547/**
548 * se_geni_resources_on() - Turn on resources associated with the serial
549 * engine
550 * @rsc: Handle to resources associated with the serial engine.
551 *
552 * Return: 0 on success, standard Linux error codes on failure/error.
553 */
554int se_geni_resources_on(struct se_geni_rsc *rsc);
555
556/**
557 * geni_se_resources_init() - Init the SE resource structure
558 * @rsc: SE resource structure to be initialized.
559 * @ab: Initial Average bus bandwidth request value.
560 * @ib: Initial Instantaneous bus bandwidth request value.
561 *
562 * Return: 0 on success, standard Linux error codes on failure.
563 */
564int geni_se_resources_init(struct se_geni_rsc *rsc,
565 unsigned long ab, unsigned long ib);
566
567/**
568 * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
569 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
570 * @base: Base address of the SE register block.
571 * @tx_buf: Pointer to the TX buffer.
572 * @tx_len: Length of the TX buffer.
573 * @tx_dma: Pointer to store the mapped DMA address.
574 *
575 * This function is used to prepare the buffers for DMA TX.
576 *
577 * Return: 0 on success, standard Linux error codes on error/failure.
578 */
579int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
580 void *tx_buf, int tx_len, dma_addr_t *tx_dma);
581
582/**
583 * geni_se_rx_dma_prep() - Prepare the Serial Engine for RX DMA transfer
584 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
585 * @base: Base address of the SE register block.
586 * @rx_buf: Pointer to the RX buffer.
587 * @rx_len: Length of the RX buffer.
588 * @rx_dma: Pointer to store the mapped DMA address.
589 *
590 * This function is used to prepare the buffers for DMA RX.
591 *
592 * Return: 0 on success, standard Linux error codes on error/failure.
593 */
594int geni_se_rx_dma_prep(struct device *wrapper_dev, void __iomem *base,
595 void *rx_buf, int rx_len, dma_addr_t *rx_dma);
596
597/**
598 * geni_se_tx_dma_unprep() - Unprepare the Serial Engine after TX DMA transfer
599 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
600 * @tx_dma: DMA address of the TX buffer.
601 * @tx_len: Length of the TX buffer.
602 *
603 * This function is used to unprepare the DMA buffers after DMA TX.
604 */
605void geni_se_tx_dma_unprep(struct device *wrapper_dev,
606 dma_addr_t tx_dma, int tx_len);
607
608/**
609 * geni_se_rx_dma_unprep() - Unprepare the Serial Engine after RX DMA transfer
610 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
611 * @rx_dma: DMA address of the RX buffer.
612 * @rx_len: Length of the RX buffer.
613 *
614 * This function is used to unprepare the DMA buffers after DMA RX.
615 */
616void geni_se_rx_dma_unprep(struct device *wrapper_dev,
617 dma_addr_t rx_dma, int rx_len);
618
619/**
620 * geni_se_qupv3_hw_version() - Read the QUPv3 Hardware version
621 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
622 * @major: Buffer for Major Version field.
623 * @minor: Buffer for Minor Version field.
624 * @step: Buffer for Step Version field.
625 *
626 * Return: 0 on success, standard Linux error codes on failure/error.
627 */
628int geni_se_qupv3_hw_version(struct device *wrapper_dev, unsigned int *major,
629 unsigned int *minor, unsigned int *step);
630
631/**
632 * geni_se_iommu_map_buf() - Map a single buffer into QUPv3 context bank
633 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
634 * @iova: Pointer in which the mapped virtual address is stored.
635 * @buf: Address of the buffer that needs to be mapped.
636 * @size: Size of the buffer.
637 * @dir: Direction of the DMA transfer.
638 *
639 * This function is used to map an already allocated buffer into the
640 * QUPv3 context bank device space.
641 *
642 * Return: 0 on success, standard Linux error codes on failure/error.
643 */
644int geni_se_iommu_map_buf(struct device *wrapper_dev, dma_addr_t *iova,
645 void *buf, size_t size, enum dma_data_direction dir);
646
647/**
648 * geni_se_iommu_alloc_buf() - Allocate & map a single buffer into QUPv3
649 * context bank
650 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
651 * @iova: Pointer in which the mapped virtual address is stored.
652 * @size: Size of the buffer.
653 *
654 * This function is used to allocate a buffer and map it into the
655 * QUPv3 context bank device space.
656 *
657 * Return: address of the buffer on success, NULL or ERR_PTR on
658 * failure/error.
659 */
660void *geni_se_iommu_alloc_buf(struct device *wrapper_dev, dma_addr_t *iova,
661 size_t size);
662
663/**
664 * geni_se_iommu_unmap_buf() - Unmap a single buffer from QUPv3 context bank
665 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
666 * @iova: Pointer in which the mapped virtual address is stored.
667 * @size: Size of the buffer.
668 * @dir: Direction of the DMA transfer.
669 *
670 * This function is used to unmap an already mapped buffer from the
671 * QUPv3 context bank device space.
672 *
673 * Return: 0 on success, standard Linux error codes on failure/error.
674 */
675int geni_se_iommu_unmap_buf(struct device *wrapper_dev, dma_addr_t *iova,
676 size_t size, enum dma_data_direction dir);
677
678/**
679 * geni_se_iommu_free_buf() - Unmap & free a single buffer from QUPv3
680 * context bank
681 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
682 * @iova: Pointer in which the mapped virtual address is stored.
683 * @buf: Address of the buffer.
684 * @size: Size of the buffer.
685 *
686 * This function is used to unmap and free a buffer from the
687 * QUPv3 context bank device space.
688 *
689 * Return: 0 on success, standard Linux error codes on failure/error.
690 */
691int geni_se_iommu_free_buf(struct device *wrapper_dev, dma_addr_t *iova,
692 void *buf, size_t size);
693
694#else
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600695static inline unsigned int geni_read_reg_nolog(void __iomem *base, int offset)
696{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600697 return 0;
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600698}
699
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600700static inline void geni_write_reg_nolog(unsigned int value,
701 void __iomem *base, int offset)
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600702{
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600703}
704
Sagar Dharia7c927c02016-11-23 11:51:43 -0700705static inline unsigned int geni_read_reg(void __iomem *base, int offset)
706{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600707 return 0;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700708}
709
710static inline void geni_write_reg(unsigned int value, void __iomem *base,
711 int offset)
712{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700713}
714
715static inline int get_se_proto(void __iomem *base)
716{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600717 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700718}
719
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600720static inline int geni_se_init(void __iomem *base,
Sagar Dharia7c927c02016-11-23 11:51:43 -0700721 unsigned int rx_wm, unsigned int rx_rfr)
722{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600723 return -ENXIO;
724}
Sagar Dharia7c927c02016-11-23 11:51:43 -0700725
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600726static inline int geni_se_select_mode(void __iomem *base, int mode)
727{
728 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700729}
730
731static inline void geni_setup_m_cmd(void __iomem *base, u32 cmd,
732 u32 params)
733{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700734}
735
736static inline void geni_setup_s_cmd(void __iomem *base, u32 cmd,
737 u32 params)
738{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700739}
740
741static inline void geni_cancel_m_cmd(void __iomem *base)
742{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700743}
744
745static inline void geni_cancel_s_cmd(void __iomem *base)
746{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700747}
748
749static inline void geni_abort_m_cmd(void __iomem *base)
750{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700751}
752
Girish Mahadevan24f56592017-04-15 17:35:05 -0600753static inline void geni_abort_s_cmd(void __iomem *base)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700754{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700755}
756
757static inline int get_tx_fifo_depth(void __iomem *base)
758{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600759 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700760}
761
762static inline int get_tx_fifo_width(void __iomem *base)
763{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600764 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700765}
766
767static inline int get_rx_fifo_depth(void __iomem *base)
768{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600769 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700770}
771
Girish Mahadevanb1ab1722017-04-27 16:39:11 -0600772static inline void se_get_packing_config(int bpw, int pack_words,
773 bool msb_to_lsb, unsigned long *cfg0,
774 unsigned long *cfg1)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700775{
Girish Mahadevanb1ab1722017-04-27 16:39:11 -0600776}
777
778static inline void se_config_packing(void __iomem *base, int bpw,
779 int pack_words, bool msb_to_lsb)
780{
Girish Mahadevanebeed352016-11-23 10:59:29 -0700781}
782
783static inline int se_geni_resources_on(struct se_geni_rsc *rsc)
784{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600785 return -ENXIO;
Girish Mahadevanebeed352016-11-23 10:59:29 -0700786}
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600787
788static inline int se_geni_resources_off(struct se_geni_rsc *rsc)
789{
790 return -ENXIO;
791}
792
793static inline int geni_se_resources_init(struct se_geni_rsc *rsc,
794 unsigned long ab, unsigned long ib)
795{
796 return -ENXIO;
797}
798
799static inline int geni_se_tx_dma_prep(struct device *wrapper_dev,
800 void __iomem *base, void *tx_buf, int tx_len, dma_addr_t *tx_dma)
801{
802 return -ENXIO;
803}
804
805static inline int geni_se_rx_dma_prep(struct device *wrapper_dev,
806 void __iomem *base, void *rx_buf, int rx_len, dma_addr_t *rx_dma)
807{
808 return -ENXIO;
809}
810
811static inline void geni_se_tx_dma_unprep(struct device *wrapper_dev,
812 dma_addr_t tx_dma, int tx_len)
813{
814}
815
816static inline void geni_se_rx_dma_unprep(struct device *wrapper_dev,
817 dma_addr_t rx_dma, int rx_len)
818{
819}
820
821static inline int geni_se_qupv3_hw_version(struct device *wrapper_dev,
822 unsigned int *major, unsigned int *minor, unsigned int *step)
823{
824 return -ENXIO;
825}
826
827static inline int geni_se_iommu_map_buf(struct device *wrapper_dev,
828 dma_addr_t *iova, void *buf, size_t size, enum dma_data_direction dir)
829{
830 return -ENXIO;
831}
832
833static inline void *geni_se_iommu_alloc_buf(struct device *wrapper_dev,
834 dma_addr_t *iova, size_t size)
835{
836 return NULL;
837}
838
839static inline int geni_se_iommu_unmap_buf(struct device *wrapper_dev,
840 dma_addr_t *iova, size_t size, enum dma_data_direction dir)
841{
842 return -ENXIO;
843
844}
845
846static inline int geni_se_iommu_free_buf(struct device *wrapper_dev,
847 dma_addr_t *iova, void *buf, size_t size)
848{
849 return -ENXIO;
850}
851
852#endif
Sagar Dharia7c927c02016-11-23 11:51:43 -0700853#endif