blob: fc02ece8a3db6c275787096908bf69dcd6b10e59 [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;
Shrey Vijay6f231202017-07-11 11:16:16 +053067 int clk_freq_out;
Girish Mahadevanebeed352016-11-23 10:59:29 -070068};
69
70#define PINCTRL_DEFAULT "default"
71#define PINCTRL_SLEEP "sleep"
72
Shrey Vijay6f231202017-07-11 11:16:16 +053073#define KHz(freq) (1000 * (freq))
74
Girish Mahadevan2ef85af2017-02-14 14:42:22 -070075/* Common SE registers */
Sagar Dharia7c927c02016-11-23 11:51:43 -070076#define GENI_INIT_CFG_REVISION (0x0)
77#define GENI_S_INIT_CFG_REVISION (0x4)
78#define GENI_FORCE_DEFAULT_REG (0x20)
79#define GENI_OUTPUT_CTRL (0x24)
80#define GENI_CGC_CTRL (0x28)
81#define SE_GENI_STATUS (0x40)
82#define GENI_SER_M_CLK_CFG (0x48)
83#define GENI_SER_S_CLK_CFG (0x4C)
84#define GENI_CLK_CTRL_RO (0x60)
Girish Mahadevanaf5f2bc2017-08-15 12:05:40 -060085#define GENI_IF_FIFO_DISABLE_RO (0x64)
Sagar Dharia7c927c02016-11-23 11:51:43 -070086#define GENI_FW_REVISION_RO (0x68)
87#define GENI_FW_S_REVISION_RO (0x6C)
88#define SE_GENI_CLK_SEL (0x7C)
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -060089#define SE_GENI_BYTE_GRAN (0x254)
Sagar Dharia7c927c02016-11-23 11:51:43 -070090#define SE_GENI_DMA_MODE_EN (0x258)
91#define SE_GENI_TX_PACKING_CFG0 (0x260)
92#define SE_GENI_TX_PACKING_CFG1 (0x264)
93#define SE_GENI_RX_PACKING_CFG0 (0x284)
94#define SE_GENI_RX_PACKING_CFG1 (0x288)
95#define SE_GENI_M_CMD0 (0x600)
96#define SE_GENI_M_CMD_CTRL_REG (0x604)
97#define SE_GENI_M_IRQ_STATUS (0x610)
98#define SE_GENI_M_IRQ_EN (0x614)
99#define SE_GENI_M_IRQ_CLEAR (0x618)
100#define SE_GENI_S_CMD0 (0x630)
101#define SE_GENI_S_CMD_CTRL_REG (0x634)
102#define SE_GENI_S_IRQ_STATUS (0x640)
103#define SE_GENI_S_IRQ_EN (0x644)
104#define SE_GENI_S_IRQ_CLEAR (0x648)
105#define SE_GENI_TX_FIFOn (0x700)
106#define SE_GENI_RX_FIFOn (0x780)
107#define SE_GENI_TX_FIFO_STATUS (0x800)
108#define SE_GENI_RX_FIFO_STATUS (0x804)
109#define SE_GENI_TX_WATERMARK_REG (0x80C)
110#define SE_GENI_RX_WATERMARK_REG (0x810)
111#define SE_GENI_RX_RFR_WATERMARK_REG (0x814)
Girish Mahadevan7115f4e2017-03-15 15:18:34 -0600112#define SE_GENI_IOS (0x908)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700113#define SE_GENI_M_GP_LENGTH (0x910)
114#define SE_GENI_S_GP_LENGTH (0x914)
Girish Mahadevana95a3612017-04-19 11:49:24 -0600115#define SE_GSI_EVENT_EN (0xE18)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700116#define SE_IRQ_EN (0xE1C)
117#define SE_HW_PARAM_0 (0xE24)
118#define SE_HW_PARAM_1 (0xE28)
119#define SE_DMA_GENERAL_CFG (0xE30)
Girish Mahadevan3b7e9742017-09-15 15:17:16 -0600120#define SE_DMA_DEBUG_REG0 (0xE40)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700121
122/* GENI_OUTPUT_CTRL fields */
123#define DEFAULT_IO_OUTPUT_CTRL_MSK (GENMASK(6, 0))
124
125/* GENI_FORCE_DEFAULT_REG fields */
126#define FORCE_DEFAULT (BIT(0))
127
128/* GENI_CGC_CTRL fields */
129#define CFG_AHB_CLK_CGC_ON (BIT(0))
130#define CFG_AHB_WR_ACLK_CGC_ON (BIT(1))
131#define DATA_AHB_CLK_CGC_ON (BIT(2))
132#define SCLK_CGC_ON (BIT(3))
133#define TX_CLK_CGC_ON (BIT(4))
134#define RX_CLK_CGC_ON (BIT(5))
135#define EXT_CLK_CGC_ON (BIT(6))
136#define PROG_RAM_HCLK_OFF (BIT(8))
137#define PROG_RAM_SCLK_OFF (BIT(9))
138#define DEFAULT_CGC_EN (GENMASK(6, 0))
139
140/* GENI_STATUS fields */
141#define M_GENI_CMD_ACTIVE (BIT(0))
142#define S_GENI_CMD_ACTIVE (BIT(12))
143
144/* GENI_SER_M_CLK_CFG/GENI_SER_S_CLK_CFG */
145#define SER_CLK_EN (BIT(0))
146#define CLK_DIV_MSK (GENMASK(15, 4))
147#define CLK_DIV_SHFT (4)
148
149/* CLK_CTRL_RO fields */
150
Girish Mahadevanaf5f2bc2017-08-15 12:05:40 -0600151/* FIFO_IF_DISABLE_RO fields */
152#define FIFO_IF_DISABLE (BIT(0))
Sagar Dharia7c927c02016-11-23 11:51:43 -0700153
154/* FW_REVISION_RO fields */
155#define FW_REV_PROTOCOL_MSK (GENMASK(15, 8))
156#define FW_REV_PROTOCOL_SHFT (8)
157
Girish Mahadevan2ef85af2017-02-14 14:42:22 -0700158/* GENI_CLK_SEL fields */
159#define CLK_SEL_MSK (GENMASK(2, 0))
160
Sagar Dharia7c927c02016-11-23 11:51:43 -0700161/* SE_GENI_DMA_MODE_EN */
162#define GENI_DMA_MODE_EN (BIT(0))
163
164/* GENI_M_CMD0 fields */
165#define M_OPCODE_MSK (GENMASK(31, 27))
166#define M_OPCODE_SHFT (27)
167#define M_PARAMS_MSK (GENMASK(26, 0))
168
169/* GENI_M_CMD_CTRL_REG */
170#define M_GENI_CMD_CANCEL BIT(2)
171#define M_GENI_CMD_ABORT BIT(1)
172#define M_GENI_DISABLE BIT(0)
173
174/* GENI_S_CMD0 fields */
175#define S_OPCODE_MSK (GENMASK(31, 27))
176#define S_OPCODE_SHFT (27)
177#define S_PARAMS_MSK (GENMASK(26, 0))
178
179/* GENI_S_CMD_CTRL_REG */
180#define S_GENI_CMD_CANCEL (BIT(2))
181#define S_GENI_CMD_ABORT (BIT(1))
182#define S_GENI_DISABLE (BIT(0))
183
184/* GENI_M_IRQ_EN fields */
185#define M_CMD_DONE_EN (BIT(0))
186#define M_CMD_OVERRUN_EN (BIT(1))
187#define M_ILLEGAL_CMD_EN (BIT(2))
188#define M_CMD_FAILURE_EN (BIT(3))
189#define M_CMD_CANCEL_EN (BIT(4))
190#define M_CMD_ABORT_EN (BIT(5))
191#define M_TIMESTAMP_EN (BIT(6))
192#define M_RX_IRQ_EN (BIT(7))
193#define M_GP_SYNC_IRQ_0_EN (BIT(8))
194#define M_GP_IRQ_0_EN (BIT(9))
195#define M_GP_IRQ_1_EN (BIT(10))
196#define M_GP_IRQ_2_EN (BIT(11))
197#define M_GP_IRQ_3_EN (BIT(12))
198#define M_GP_IRQ_4_EN (BIT(13))
199#define M_GP_IRQ_5_EN (BIT(14))
200#define M_IO_DATA_DEASSERT_EN (BIT(22))
201#define M_IO_DATA_ASSERT_EN (BIT(23))
202#define M_RX_FIFO_RD_ERR_EN (BIT(24))
203#define M_RX_FIFO_WR_ERR_EN (BIT(25))
204#define M_RX_FIFO_WATERMARK_EN (BIT(26))
205#define M_RX_FIFO_LAST_EN (BIT(27))
206#define M_TX_FIFO_RD_ERR_EN (BIT(28))
207#define M_TX_FIFO_WR_ERR_EN (BIT(29))
208#define M_TX_FIFO_WATERMARK_EN (BIT(30))
209#define M_SEC_IRQ_EN (BIT(31))
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600210#define M_COMMON_GENI_M_IRQ_EN (GENMASK(6, 1) | \
211 M_IO_DATA_DEASSERT_EN | \
Sagar Dharia7c927c02016-11-23 11:51:43 -0700212 M_IO_DATA_ASSERT_EN | M_RX_FIFO_RD_ERR_EN | \
213 M_RX_FIFO_WR_ERR_EN | M_TX_FIFO_RD_ERR_EN | \
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600214 M_TX_FIFO_WR_ERR_EN)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700215
216/* GENI_S_IRQ_EN fields */
217#define S_CMD_DONE_EN (BIT(0))
218#define S_CMD_OVERRUN_EN (BIT(1))
219#define S_ILLEGAL_CMD_EN (BIT(2))
220#define S_CMD_FAILURE_EN (BIT(3))
221#define S_CMD_CANCEL_EN (BIT(4))
222#define S_CMD_ABORT_EN (BIT(5))
223#define S_GP_SYNC_IRQ_0_EN (BIT(8))
224#define S_GP_IRQ_0_EN (BIT(9))
225#define S_GP_IRQ_1_EN (BIT(10))
226#define S_GP_IRQ_2_EN (BIT(11))
227#define S_GP_IRQ_3_EN (BIT(12))
228#define S_GP_IRQ_4_EN (BIT(13))
229#define S_GP_IRQ_5_EN (BIT(14))
230#define S_IO_DATA_DEASSERT_EN (BIT(22))
231#define S_IO_DATA_ASSERT_EN (BIT(23))
232#define S_RX_FIFO_RD_ERR_EN (BIT(24))
233#define S_RX_FIFO_WR_ERR_EN (BIT(25))
234#define S_RX_FIFO_WATERMARK_EN (BIT(26))
235#define S_RX_FIFO_LAST_EN (BIT(27))
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600236#define S_COMMON_GENI_S_IRQ_EN (GENMASK(5, 1) | GENMASK(13, 9) | \
Sagar Dharia7c927c02016-11-23 11:51:43 -0700237 S_RX_FIFO_RD_ERR_EN | S_RX_FIFO_WR_ERR_EN)
238
239/* GENI_/TX/RX/RX_RFR/_WATERMARK_REG fields */
240#define WATERMARK_MSK (GENMASK(5, 0))
241
242/* GENI_TX_FIFO_STATUS fields */
243#define TX_FIFO_WC (GENMASK(27, 0))
244
245/* GENI_RX_FIFO_STATUS fields */
246#define RX_LAST (BIT(31))
247#define RX_LAST_BYTE_VALID_MSK (GENMASK(30, 28))
248#define RX_LAST_BYTE_VALID_SHFT (28)
249#define RX_FIFO_WC_MSK (GENMASK(24, 0))
250
Girish Mahadevana95a3612017-04-19 11:49:24 -0600251/* SE_GSI_EVENT_EN fields */
252#define DMA_RX_EVENT_EN (BIT(0))
253#define DMA_TX_EVENT_EN (BIT(1))
254#define GENI_M_EVENT_EN (BIT(2))
255#define GENI_S_EVENT_EN (BIT(3))
256
Girish Mahadevan7115f4e2017-03-15 15:18:34 -0600257/* SE_GENI_IOS fields */
258#define IO2_DATA_IN (BIT(1))
259#define RX_DATA_IN (BIT(0))
260
Sagar Dharia7c927c02016-11-23 11:51:43 -0700261/* SE_IRQ_EN fields */
262#define DMA_RX_IRQ_EN (BIT(0))
263#define DMA_TX_IRQ_EN (BIT(1))
264#define GENI_M_IRQ_EN (BIT(2))
265#define GENI_S_IRQ_EN (BIT(3))
266
267/* SE_HW_PARAM_0 fields */
268#define TX_FIFO_WIDTH_MSK (GENMASK(29, 24))
269#define TX_FIFO_WIDTH_SHFT (24)
270#define TX_FIFO_DEPTH_MSK (GENMASK(21, 16))
271#define TX_FIFO_DEPTH_SHFT (16)
272
273/* SE_HW_PARAM_1 fields */
274#define RX_FIFO_WIDTH_MSK (GENMASK(29, 24))
275#define RX_FIFO_WIDTH_SHFT (24)
276#define RX_FIFO_DEPTH_MSK (GENMASK(21, 16))
277#define RX_FIFO_DEPTH_SHFT (16)
278
279/* SE_DMA_GENERAL_CFG */
280#define DMA_RX_CLK_CGC_ON (BIT(0))
281#define DMA_TX_CLK_CGC_ON (BIT(1))
282#define DMA_AHB_SLV_CFG_ON (BIT(2))
283#define AHB_SEC_SLV_CLK_CGC_ON (BIT(3))
284#define DUMMY_RX_NON_BUFFERABLE (BIT(4))
285#define RX_DMA_ZERO_PADDING_EN (BIT(5))
286#define RX_DMA_IRQ_DELAY_MSK (GENMASK(8, 6))
287#define RX_DMA_IRQ_DELAY_SHFT (6)
288
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600289#define SE_DMA_TX_PTR_L (0xC30)
290#define SE_DMA_TX_PTR_H (0xC34)
291#define SE_DMA_TX_ATTR (0xC38)
292#define SE_DMA_TX_LEN (0xC3C)
293#define SE_DMA_TX_IRQ_STAT (0xC40)
294#define SE_DMA_TX_IRQ_CLR (0xC44)
295#define SE_DMA_TX_IRQ_EN (0xC48)
296#define SE_DMA_TX_IRQ_EN_SET (0xC4C)
297#define SE_DMA_TX_IRQ_EN_CLR (0xC50)
298#define SE_DMA_TX_LEN_IN (0xC54)
299#define SE_DMA_TX_FSM_RST (0xC58)
300#define SE_DMA_TX_MAX_BURST (0xC5C)
301
302#define SE_DMA_RX_PTR_L (0xD30)
303#define SE_DMA_RX_PTR_H (0xD34)
304#define SE_DMA_RX_ATTR (0xD38)
305#define SE_DMA_RX_LEN (0xD3C)
306#define SE_DMA_RX_IRQ_STAT (0xD40)
307#define SE_DMA_RX_IRQ_CLR (0xD44)
308#define SE_DMA_RX_IRQ_EN (0xD48)
309#define SE_DMA_RX_IRQ_EN_SET (0xD4C)
310#define SE_DMA_RX_IRQ_EN_CLR (0xD50)
311#define SE_DMA_RX_LEN_IN (0xD54)
312#define SE_DMA_RX_FSM_RST (0xD58)
313#define SE_DMA_RX_MAX_BURST (0xD5C)
314#define SE_DMA_RX_FLUSH (0xD60)
315
Karthikeyan Ramasubramaniana5766572017-04-19 11:31:42 -0600316/* SE_DMA_TX_IRQ_STAT Register fields */
317#define TX_DMA_DONE (BIT(0))
318#define TX_EOT (BIT(1))
319#define TX_SBE (BIT(2))
320#define TX_RESET_DONE (BIT(3))
321
322/* SE_DMA_RX_IRQ_STAT Register fields */
323#define RX_DMA_DONE (BIT(0))
324#define RX_EOT (BIT(1))
325#define RX_SBE (BIT(2))
326#define RX_RESET_DONE (BIT(3))
327#define RX_FLUSH_DONE (BIT(4))
328#define RX_GENI_GP_IRQ (GENMASK(10, 5))
329#define RX_GENI_CANCEL_IRQ (BIT(11))
330#define RX_GENI_GP_IRQ_EXT (GENMASK(13, 12))
331
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600332#define DEFAULT_BUS_WIDTH (4)
333#define DEFAULT_SE_CLK (19200000)
334
Girish Mahadevanaf5f2bc2017-08-15 12:05:40 -0600335/* GSI TRE fields */
336/* Packing fields */
337#define GSI_TX_PACK_EN (BIT(0))
338#define GSI_RX_PACK_EN (BIT(1))
339#define GSI_PRESERVE_PACK (BIT(2))
340
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600341#define GENI_SE_ERR(log_ctx, print, dev, x...) do { \
342if (log_ctx) \
343 ipc_log_string(log_ctx, x); \
344if (print) { \
345 if (dev) \
346 dev_err((dev), x); \
347 else \
348 pr_err(x); \
349} \
350} while (0)
351
352#define GENI_SE_DBG(log_ctx, print, dev, x...) do { \
353if (log_ctx) \
354 ipc_log_string(log_ctx, x); \
355if (print) { \
356 if (dev) \
357 dev_dbg((dev), x); \
358 else \
359 pr_debug(x); \
360} \
361} while (0)
362
363
364#ifdef CONFIG_QCOM_GENI_SE
365/**
366 * geni_read_reg_nolog() - Helper function to read from a GENI register
367 * @base: Base address of the serial engine's register block.
368 * @offset: Offset within the serial engine's register block.
369 *
370 * Return: Return the contents of the register.
371 */
372unsigned int geni_read_reg_nolog(void __iomem *base, int offset);
373
374/**
375 * geni_write_reg_nolog() - Helper function to write into a GENI register
376 * @value: Value to be written into the register.
377 * @base: Base address of the serial engine's register block.
378 * @offset: Offset within the serial engine's register block.
379 */
380void geni_write_reg_nolog(unsigned int value, void __iomem *base, int offset);
381
382/**
383 * geni_read_reg() - Helper function to read from a GENI register
384 * @base: Base address of the serial engine's register block.
385 * @offset: Offset within the serial engine's register block.
386 *
387 * Return: Return the contents of the register.
388 */
389unsigned int geni_read_reg(void __iomem *base, int offset);
390
391/**
392 * geni_write_reg() - Helper function to write into a GENI register
393 * @value: Value to be written into the register.
394 * @base: Base address of the serial engine's register block.
395 * @offset: Offset within the serial engine's register block.
396 */
397void geni_write_reg(unsigned int value, void __iomem *base, int offset);
398
399/**
400 * get_se_proto() - Read the protocol configured for a serial engine
401 * @base: Base address of the serial engine's register block.
402 *
403 * Return: Protocol value as configured in the serial engine.
404 */
405int get_se_proto(void __iomem *base);
406
407/**
408 * geni_se_init() - Initialize the GENI Serial Engine
409 * @base: Base address of the serial engine's register block.
410 * @rx_wm: Receive watermark to be configured.
411 * @rx_rfr_wm: Ready-for-receive watermark to be configured.
412 *
413 * This function is used to initialize the GENI serial engine, configure
414 * the transfer mode, receive watermark and ready-for-receive watermarks.
415 *
416 * Return: 0 on success, standard Linux error codes on failure/error.
417 */
418int geni_se_init(void __iomem *base, unsigned int rx_wm, unsigned int rx_rfr);
419
420/**
421 * geni_se_select_mode() - Select the serial engine transfer mode
422 * @base: Base address of the serial engine's register block.
423 * @mode: Transfer mode to be selected.
424 *
425 * Return: 0 on success, standard Linux error codes on failure.
426 */
427int geni_se_select_mode(void __iomem *base, int mode);
428
429/**
430 * geni_setup_m_cmd() - Setup the primary sequencer
431 * @base: Base address of the serial engine's register block.
432 * @cmd: Command/Operation to setup in the primary sequencer.
433 * @params: Parameter for the sequencer command.
434 *
435 * This function is used to configure the primary sequencer with the
436 * command and its assoicated parameters.
437 */
438void geni_setup_m_cmd(void __iomem *base, u32 cmd, u32 params);
439
440/**
441 * geni_setup_s_cmd() - Setup the secondary sequencer
442 * @base: Base address of the serial engine's register block.
443 * @cmd: Command/Operation to setup in the secondary sequencer.
444 * @params: Parameter for the sequencer command.
445 *
446 * This function is used to configure the secondary sequencer with the
447 * command and its assoicated parameters.
448 */
449void geni_setup_s_cmd(void __iomem *base, u32 cmd, u32 params);
450
451/**
452 * geni_cancel_m_cmd() - Cancel the command configured in the primary sequencer
453 * @base: Base address of the serial engine's register block.
454 *
455 * This function is used to cancel the currently configured command in the
456 * primary sequencer.
457 */
458void geni_cancel_m_cmd(void __iomem *base);
459
460/**
461 * geni_cancel_s_cmd() - Cancel the command configured in the secondary
462 * sequencer
463 * @base: Base address of the serial engine's register block.
464 *
465 * This function is used to cancel the currently configured command in the
466 * secondary sequencer.
467 */
468void geni_cancel_s_cmd(void __iomem *base);
469
470/**
471 * geni_abort_m_cmd() - Abort the command configured in the primary sequencer
472 * @base: Base address of the serial engine's register block.
473 *
474 * This function is used to force abort the currently configured command in the
475 * primary sequencer.
476 */
477void geni_abort_m_cmd(void __iomem *base);
478
479/**
480 * geni_abort_s_cmd() - Abort the command configured in the secondary
481 * sequencer
482 * @base: Base address of the serial engine's register block.
483 *
484 * This function is used to force abort the currently configured command in the
485 * secondary sequencer.
486 */
487void geni_abort_s_cmd(void __iomem *base);
488
489/**
490 * get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
491 * @base: Base address of the serial engine's register block.
492 *
493 * This function is used to get the depth i.e. number of elements in the
494 * TX fifo of the serial engine.
495 *
496 * Return: TX fifo depth in units of FIFO words.
497 */
498int get_tx_fifo_depth(void __iomem *base);
499
500/**
501 * get_tx_fifo_width() - Get the TX fifo width of the serial engine
502 * @base: Base address of the serial engine's register block.
503 *
504 * This function is used to get the width i.e. word size per element in the
505 * TX fifo of the serial engine.
506 *
507 * Return: TX fifo width in bits.
508 */
509int get_tx_fifo_width(void __iomem *base);
510
511/**
512 * get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
513 * @base: Base address of the serial engine's register block.
514 *
515 * This function is used to get the depth i.e. number of elements in the
516 * RX fifo of the serial engine.
517 *
518 * Return: RX fifo depth in units of FIFO words.
519 */
520int get_rx_fifo_depth(void __iomem *base);
521
522/**
523 * se_get_packing_config() - Get the packing configuration based on input
524 * @bpw: Bits of data per transfer word.
525 * @pack_words: Number of words per fifo element.
526 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
527 * @cfg0: Output buffer to hold the first half of configuration.
528 * @cfg1: Output buffer to hold the second half of configuration.
529 *
530 * This function is used to calculate the packing configuration based on
531 * the input packing requirement and the configuration logic.
532 */
533void se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
534 unsigned long *cfg0, unsigned long *cfg1);
535
536/**
537 * se_config_packing() - Packing configuration of the serial engine
538 * @base: Base address of the serial engine's register block.
539 * @bpw: Bits of data per transfer word.
540 * @pack_words: Number of words per fifo element.
541 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
542 *
543 * This function is used to configure the packing rules for the current
544 * transfer.
545 */
546void se_config_packing(void __iomem *base, int bpw, int pack_words,
547 bool msb_to_lsb);
548
549/**
Karthikeyan Ramasubramanian383b41e2017-10-25 17:32:52 -0600550 * se_geni_clks_off() - Turn off clocks associated with the serial
551 * engine
552 * @rsc: Handle to resources associated with the serial engine.
553 *
554 * Return: 0 on success, standard Linux error codes on failure/error.
555 */
556int se_geni_clks_off(struct se_geni_rsc *rsc);
557
558/**
559 * se_geni_clks_on() - Turn on clocks associated with the serial
560 * engine
561 * @rsc: Handle to resources associated with the serial engine.
562 *
563 * Return: 0 on success, standard Linux error codes on failure/error.
564 */
565int se_geni_clks_on(struct se_geni_rsc *rsc);
566
567/**
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600568 * se_geni_resources_off() - Turn off resources associated with the serial
569 * engine
570 * @rsc: Handle to resources associated with the serial engine.
571 *
572 * Return: 0 on success, standard Linux error codes on failure/error.
573 */
574int se_geni_resources_off(struct se_geni_rsc *rsc);
575
576/**
577 * se_geni_resources_on() - Turn on resources associated with the serial
578 * engine
579 * @rsc: Handle to resources associated with the serial engine.
580 *
581 * Return: 0 on success, standard Linux error codes on failure/error.
582 */
583int se_geni_resources_on(struct se_geni_rsc *rsc);
584
585/**
586 * geni_se_resources_init() - Init the SE resource structure
587 * @rsc: SE resource structure to be initialized.
588 * @ab: Initial Average bus bandwidth request value.
589 * @ib: Initial Instantaneous bus bandwidth request value.
590 *
591 * Return: 0 on success, standard Linux error codes on failure.
592 */
593int geni_se_resources_init(struct se_geni_rsc *rsc,
594 unsigned long ab, unsigned long ib);
595
596/**
Karthikeyan Ramasubramanian8bef5ea2017-05-11 17:02:46 -0600597 * geni_se_clk_tbl_get() - Get the clock table to program DFS
598 * @rsc: Resource for which the clock table is requested.
599 * @tbl: Table in which the output is returned.
600 *
601 * This function is called by the protocol drivers to determine the different
602 * clock frequencies supported by Serail Engine Core Clock. The protocol
603 * drivers use the output to determine the clock frequency index to be
604 * programmed into DFS.
605 *
606 * Return: number of valid performance levels in the table on success,
607 * standard Linux error codes on failure.
608 */
609int geni_se_clk_tbl_get(struct se_geni_rsc *rsc, unsigned long **tbl);
610
611/**
612 * geni_se_clk_freq_match() - Get the matching or closest SE clock frequency
613 * @rsc: Resource for which the clock frequency is requested.
614 * @req_freq: Requested clock frequency.
615 * @index: Index of the resultant frequency in the table.
616 * @res_freq: Resultant frequency which matches or is closer to the
617 * requested frequency.
618 * @exact: Flag to indicate exact multiple requirement of the requested
619 * frequency .
620 *
621 * This function is called by the protocol drivers to determine the matching
622 * or closest frequency of the Serial Engine clock to be selected in order
623 * to meet the performance requirements.
624 *
625 * Return: 0 on success, standard Linux error codes on failure.
626 */
627int geni_se_clk_freq_match(struct se_geni_rsc *rsc, unsigned long req_freq,
628 unsigned int *index, unsigned long *res_freq,
629 bool exact);
630
631/**
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600632 * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
633 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
634 * @base: Base address of the SE register block.
635 * @tx_buf: Pointer to the TX buffer.
636 * @tx_len: Length of the TX buffer.
637 * @tx_dma: Pointer to store the mapped DMA address.
638 *
639 * This function is used to prepare the buffers for DMA TX.
640 *
641 * Return: 0 on success, standard Linux error codes on error/failure.
642 */
643int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
644 void *tx_buf, int tx_len, dma_addr_t *tx_dma);
645
646/**
647 * geni_se_rx_dma_prep() - Prepare the Serial Engine for RX DMA transfer
648 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
649 * @base: Base address of the SE register block.
650 * @rx_buf: Pointer to the RX buffer.
651 * @rx_len: Length of the RX buffer.
652 * @rx_dma: Pointer to store the mapped DMA address.
653 *
654 * This function is used to prepare the buffers for DMA RX.
655 *
656 * Return: 0 on success, standard Linux error codes on error/failure.
657 */
658int geni_se_rx_dma_prep(struct device *wrapper_dev, void __iomem *base,
659 void *rx_buf, int rx_len, dma_addr_t *rx_dma);
660
661/**
662 * geni_se_tx_dma_unprep() - Unprepare the Serial Engine after TX DMA transfer
663 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
664 * @tx_dma: DMA address of the TX buffer.
665 * @tx_len: Length of the TX buffer.
666 *
667 * This function is used to unprepare the DMA buffers after DMA TX.
668 */
669void geni_se_tx_dma_unprep(struct device *wrapper_dev,
670 dma_addr_t tx_dma, int tx_len);
671
672/**
673 * geni_se_rx_dma_unprep() - Unprepare the Serial Engine after RX DMA transfer
674 * @wrapper_dev: QUPv3 Wrapper Device to which the TX buffer is mapped.
675 * @rx_dma: DMA address of the RX buffer.
676 * @rx_len: Length of the RX buffer.
677 *
678 * This function is used to unprepare the DMA buffers after DMA RX.
679 */
680void geni_se_rx_dma_unprep(struct device *wrapper_dev,
681 dma_addr_t rx_dma, int rx_len);
682
683/**
684 * geni_se_qupv3_hw_version() - Read the QUPv3 Hardware version
685 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
686 * @major: Buffer for Major Version field.
687 * @minor: Buffer for Minor Version field.
688 * @step: Buffer for Step Version field.
689 *
690 * Return: 0 on success, standard Linux error codes on failure/error.
691 */
692int geni_se_qupv3_hw_version(struct device *wrapper_dev, unsigned int *major,
693 unsigned int *minor, unsigned int *step);
694
695/**
696 * geni_se_iommu_map_buf() - Map a single buffer into QUPv3 context bank
697 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
698 * @iova: Pointer in which the mapped virtual address is stored.
699 * @buf: Address of the buffer that needs to be mapped.
700 * @size: Size of the buffer.
701 * @dir: Direction of the DMA transfer.
702 *
703 * This function is used to map an already allocated buffer into the
704 * QUPv3 context bank device space.
705 *
706 * Return: 0 on success, standard Linux error codes on failure/error.
707 */
708int geni_se_iommu_map_buf(struct device *wrapper_dev, dma_addr_t *iova,
709 void *buf, size_t size, enum dma_data_direction dir);
710
711/**
712 * geni_se_iommu_alloc_buf() - Allocate & map a single buffer into QUPv3
713 * context bank
714 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
715 * @iova: Pointer in which the mapped virtual address is stored.
716 * @size: Size of the buffer.
717 *
718 * This function is used to allocate a buffer and map it into the
719 * QUPv3 context bank device space.
720 *
721 * Return: address of the buffer on success, NULL or ERR_PTR on
722 * failure/error.
723 */
724void *geni_se_iommu_alloc_buf(struct device *wrapper_dev, dma_addr_t *iova,
725 size_t size);
726
727/**
728 * geni_se_iommu_unmap_buf() - Unmap a single buffer from QUPv3 context bank
729 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
730 * @iova: Pointer in which the mapped virtual address is stored.
731 * @size: Size of the buffer.
732 * @dir: Direction of the DMA transfer.
733 *
734 * This function is used to unmap an already mapped buffer from the
735 * QUPv3 context bank device space.
736 *
737 * Return: 0 on success, standard Linux error codes on failure/error.
738 */
739int geni_se_iommu_unmap_buf(struct device *wrapper_dev, dma_addr_t *iova,
740 size_t size, enum dma_data_direction dir);
741
742/**
743 * geni_se_iommu_free_buf() - Unmap & free a single buffer from QUPv3
744 * context bank
745 * @wrapper_dev: Pointer to the corresponding QUPv3 wrapper core.
746 * @iova: Pointer in which the mapped virtual address is stored.
747 * @buf: Address of the buffer.
748 * @size: Size of the buffer.
749 *
750 * This function is used to unmap and free a buffer from the
751 * QUPv3 context bank device space.
752 *
753 * Return: 0 on success, standard Linux error codes on failure/error.
754 */
755int geni_se_iommu_free_buf(struct device *wrapper_dev, dma_addr_t *iova,
756 void *buf, size_t size);
757
Girish Mahadevan3b7e9742017-09-15 15:17:16 -0600758
759/**
760 * geni_se_dump_dbg_regs() - Print relevant registers that capture most
761 * accurately the state of an SE; meant to be called
762 * in case of errors to help debug.
763 * @_dev: Pointer to the SE's device.
764 * @iomem: Base address of the SE's register space.
765 * @ipc: IPC log context handle.
766 *
767 * This function is used to print out all the registers that capture the state
768 * of an SE to help debug any errors.
769 *
770 * Return: None
771 */
772void geni_se_dump_dbg_regs(struct se_geni_rsc *rsc, void __iomem *base,
773 void *ipc);
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600774#else
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600775static inline unsigned int geni_read_reg_nolog(void __iomem *base, int offset)
776{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600777 return 0;
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600778}
779
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600780static inline void geni_write_reg_nolog(unsigned int value,
781 void __iomem *base, int offset)
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600782{
Girish Mahadevanbd9b44f2017-04-11 13:11:10 -0600783}
784
Sagar Dharia7c927c02016-11-23 11:51:43 -0700785static inline unsigned int geni_read_reg(void __iomem *base, int offset)
786{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600787 return 0;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700788}
789
790static inline void geni_write_reg(unsigned int value, void __iomem *base,
791 int offset)
792{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700793}
794
795static inline int get_se_proto(void __iomem *base)
796{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600797 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700798}
799
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600800static inline int geni_se_init(void __iomem *base,
Sagar Dharia7c927c02016-11-23 11:51:43 -0700801 unsigned int rx_wm, unsigned int rx_rfr)
802{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600803 return -ENXIO;
804}
Sagar Dharia7c927c02016-11-23 11:51:43 -0700805
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600806static inline int geni_se_select_mode(void __iomem *base, int mode)
807{
808 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700809}
810
811static inline void geni_setup_m_cmd(void __iomem *base, u32 cmd,
812 u32 params)
813{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700814}
815
816static inline void geni_setup_s_cmd(void __iomem *base, u32 cmd,
817 u32 params)
818{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700819}
820
821static inline void geni_cancel_m_cmd(void __iomem *base)
822{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700823}
824
825static inline void geni_cancel_s_cmd(void __iomem *base)
826{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700827}
828
829static inline void geni_abort_m_cmd(void __iomem *base)
830{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700831}
832
Girish Mahadevan24f56592017-04-15 17:35:05 -0600833static inline void geni_abort_s_cmd(void __iomem *base)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700834{
Sagar Dharia7c927c02016-11-23 11:51:43 -0700835}
836
837static inline int get_tx_fifo_depth(void __iomem *base)
838{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600839 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700840}
841
842static inline int get_tx_fifo_width(void __iomem *base)
843{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600844 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700845}
846
847static inline int get_rx_fifo_depth(void __iomem *base)
848{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600849 return -ENXIO;
Sagar Dharia7c927c02016-11-23 11:51:43 -0700850}
851
Girish Mahadevanb1ab1722017-04-27 16:39:11 -0600852static inline void se_get_packing_config(int bpw, int pack_words,
853 bool msb_to_lsb, unsigned long *cfg0,
854 unsigned long *cfg1)
Sagar Dharia7c927c02016-11-23 11:51:43 -0700855{
Girish Mahadevanb1ab1722017-04-27 16:39:11 -0600856}
857
858static inline void se_config_packing(void __iomem *base, int bpw,
859 int pack_words, bool msb_to_lsb)
860{
Girish Mahadevanebeed352016-11-23 10:59:29 -0700861}
862
Karthikeyan Ramasubramanian383b41e2017-10-25 17:32:52 -0600863static inline int se_geni_clks_on(struct se_geni_rsc *rsc)
864{
865 return -ENXIO;
866}
867
868static inline int se_geni_clks_off(struct se_geni_rsc *rsc)
869{
870 return -ENXIO;
871}
872
Girish Mahadevanebeed352016-11-23 10:59:29 -0700873static inline int se_geni_resources_on(struct se_geni_rsc *rsc)
874{
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600875 return -ENXIO;
Girish Mahadevanebeed352016-11-23 10:59:29 -0700876}
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600877
878static inline int se_geni_resources_off(struct se_geni_rsc *rsc)
879{
880 return -ENXIO;
881}
882
883static inline int geni_se_resources_init(struct se_geni_rsc *rsc,
884 unsigned long ab, unsigned long ib)
885{
886 return -ENXIO;
887}
888
Karthikeyan Ramasubramanian8bef5ea2017-05-11 17:02:46 -0600889static inline int geni_se_clk_tbl_get(struct se_geni_rsc *rsc,
890 unsigned long **tbl)
891{
892 return -ENXIO;
893}
894
895static inline int geni_se_clk_freq_match(struct se_geni_rsc *rsc,
896 unsigned long req_freq, unsigned int *index,
897 unsigned long *res_freq, bool exact)
898{
899 return -ENXIO;
900}
901
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600902static inline int geni_se_tx_dma_prep(struct device *wrapper_dev,
903 void __iomem *base, void *tx_buf, int tx_len, dma_addr_t *tx_dma)
904{
905 return -ENXIO;
906}
907
908static inline int geni_se_rx_dma_prep(struct device *wrapper_dev,
909 void __iomem *base, void *rx_buf, int rx_len, dma_addr_t *rx_dma)
910{
911 return -ENXIO;
912}
913
914static inline void geni_se_tx_dma_unprep(struct device *wrapper_dev,
915 dma_addr_t tx_dma, int tx_len)
916{
917}
918
919static inline void geni_se_rx_dma_unprep(struct device *wrapper_dev,
920 dma_addr_t rx_dma, int rx_len)
921{
922}
923
924static inline int geni_se_qupv3_hw_version(struct device *wrapper_dev,
925 unsigned int *major, unsigned int *minor, unsigned int *step)
926{
927 return -ENXIO;
928}
929
930static inline int geni_se_iommu_map_buf(struct device *wrapper_dev,
931 dma_addr_t *iova, void *buf, size_t size, enum dma_data_direction dir)
932{
933 return -ENXIO;
934}
935
936static inline void *geni_se_iommu_alloc_buf(struct device *wrapper_dev,
937 dma_addr_t *iova, size_t size)
938{
939 return NULL;
940}
941
942static inline int geni_se_iommu_unmap_buf(struct device *wrapper_dev,
943 dma_addr_t *iova, size_t size, enum dma_data_direction dir)
944{
945 return -ENXIO;
946
947}
948
949static inline int geni_se_iommu_free_buf(struct device *wrapper_dev,
950 dma_addr_t *iova, void *buf, size_t size)
951{
952 return -ENXIO;
953}
954
Maria Yuecc03d72017-09-25 16:52:15 +0800955static void geni_se_dump_dbg_regs(struct se_geni_rsc *rsc, void __iomem *base,
Girish Mahadevan3b7e9742017-09-15 15:17:16 -0600956 void *ipc)
957{
958}
959
Karthikeyan Ramasubramanian0d578b72017-04-26 10:44:02 -0600960#endif
Sagar Dharia7c927c02016-11-23 11:51:43 -0700961#endif