blob: e7f5a158b8a2f88bb108c91a7915ef4d5dfaadde [file] [log] [blame]
Venkat Gopalakrishnan0225ff92015-05-29 17:25:46 -07001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12#ifndef LINUX_MMC_CQ_HCI_H
13#define LINUX_MMC_CQ_HCI_H
14#include <linux/mmc/core.h>
15
16/* registers */
17/* version */
18#define CQVER 0x00
19/* capabilities */
20#define CQCAP 0x04
21/* configuration */
22#define CQCFG 0x08
23#define CQ_DCMD 0x00001000
24#define CQ_TASK_DESC_SZ 0x00000100
25#define CQ_ENABLE 0x00000001
26
27/* control */
28#define CQCTL 0x0C
29#define CLEAR_ALL_TASKS 0x00000100
30#define HALT 0x00000001
31
32/* interrupt status */
33#define CQIS 0x10
34#define CQIS_HAC (1 << 0)
35#define CQIS_TCC (1 << 1)
36#define CQIS_RED (1 << 2)
37#define CQIS_TCL (1 << 3)
38
39/* interrupt status enable */
40#define CQISTE 0x14
41
42/* interrupt signal enable */
43#define CQISGE 0x18
44
45/* interrupt coalescing */
46#define CQIC 0x1C
47#define CQIC_ENABLE (1 << 31)
48#define CQIC_RESET (1 << 16)
49#define CQIC_ICCTHWEN (1 << 15)
50#define CQIC_ICCTH(x) ((x & 0x1F) << 8)
51#define CQIC_ICTOVALWEN (1 << 7)
52#define CQIC_ICTOVAL(x) (x & 0x7F)
53
54/* task list base address */
55#define CQTDLBA 0x20
56
57/* task list base address upper */
58#define CQTDLBAU 0x24
59
60/* door-bell */
61#define CQTDBR 0x28
62
63/* task completion notification */
64#define CQTCN 0x2C
65
66/* device queue status */
67#define CQDQS 0x30
68
69/* device pending tasks */
70#define CQDPT 0x34
71
72/* task clear */
73#define CQTCLR 0x38
74
75/* send status config 1 */
76#define CQSSC1 0x40
77/*
78 * Value n means CQE would send CMD13 during the transfer of data block
79 * BLOCK_CNT-n
80 */
81#define SEND_QSR_INTERVAL 0x70000
82
83/* send status config 2 */
84#define CQSSC2 0x44
85
86/* response for dcmd */
87#define CQCRDCT 0x48
88
89/* response mode error mask */
90#define CQRMEM 0x50
91
92/* task error info */
93#define CQTERRI 0x54
94
95/* command response index */
96#define CQCRI 0x58
97
98/* command response argument */
99#define CQCRA 0x5C
100
101#define CQ_INT_ALL 0xF
102#define CQIC_DEFAULT_ICCTH 31
103#define CQIC_DEFAULT_ICTOVAL 1
104
105#define CQ_CMD_DBG_RAM 0x158
106#define CQ_CMD_DBG_RAM_WA 0x198
107#define CQ_CMD_DBG_RAM_OL 0x19C
108
109/* attribute fields */
110#define VALID(x) ((x & 1) << 0)
111#define END(x) ((x & 1) << 1)
112#define INT(x) ((x & 1) << 2)
113#define ACT(x) ((x & 0x7) << 3)
114
115/* data command task descriptor fields */
116#define FORCED_PROG(x) ((x & 1) << 6)
117#define CONTEXT(x) ((x & 0xF) << 7)
118#define DATA_TAG(x) ((x & 1) << 11)
119#define DATA_DIR(x) ((x & 1) << 12)
120#define PRIORITY(x) ((x & 1) << 13)
121#define QBAR(x) ((x & 1) << 14)
122#define REL_WRITE(x) ((x & 1) << 15)
123#define BLK_COUNT(x) ((x & 0xFFFF) << 16)
124#define BLK_ADDR(x) ((x & 0xFFFFFFFF) << 32)
125
126/* direct command task descriptor fields */
127#define CMD_INDEX(x) ((x & 0x3F) << 16)
128#define CMD_TIMING(x) ((x & 1) << 22)
129#define RESP_TYPE(x) ((x & 0x3) << 23)
130
131/* transfer descriptor fields */
132#define DAT_LENGTH(x) ((x & 0xFFFF) << 16)
133#define DAT_ADDR_LO(x) ((x & 0xFFFFFFFF) << 32)
134#define DAT_ADDR_HI(x) ((x & 0xFFFFFFFF) << 0)
135
136struct cmdq_host {
137 const struct cmdq_host_ops *ops;
138 void __iomem *mmio;
139 struct mmc_host *mmc;
140
141 /* 64 bit DMA */
142 bool dma64;
143 int num_slots;
144
145 u32 dcmd_slot;
146 u32 caps;
147#define CMDQ_TASK_DESC_SZ_128 0x1
148
149 u32 quirks;
150#define CMDQ_QUIRK_SHORT_TXFR_DESC_SZ 0x1
151#define CMDQ_QUIRK_NO_DCMD 0x2
152
153 bool enabled;
154 bool halted;
155 bool init_done;
156
157 u8 *desc_base;
158
159 /* total descriptor size */
160 u8 slot_sz;
161
162 /* 64/128 bit depends on CQCFG */
163 u8 task_desc_len;
164
165 /* 64 bit on 32-bit arch, 128 bit on 64-bit */
166 u8 link_desc_len;
167
168 u8 *trans_desc_base;
169 /* same length as transfer descriptor */
170 u8 trans_desc_len;
171
172 dma_addr_t desc_dma_base;
173 dma_addr_t trans_desc_dma_base;
174
175 struct completion halt_comp;
176 struct mmc_request **mrq_slot;
177 void *private;
178};
179
180struct cmdq_host_ops {
181 void (*set_tranfer_params)(struct mmc_host *mmc);
182 void (*set_data_timeout)(struct mmc_host *mmc, u32 val);
183 void (*clear_set_irqs)(struct mmc_host *mmc, bool clear);
184 void (*set_block_size)(struct mmc_host *mmc);
185 void (*dump_vendor_regs)(struct mmc_host *mmc);
186 void (*write_l)(struct cmdq_host *host, u32 val, int reg);
187 u32 (*read_l)(struct cmdq_host *host, int reg);
188 void (*clear_set_dumpregs)(struct mmc_host *mmc, bool set);
189};
190
191static inline void cmdq_writel(struct cmdq_host *host, u32 val, int reg)
192{
193 if (unlikely(host->ops->write_l))
194 host->ops->write_l(host, val, reg);
195 else
196 writel_relaxed(val, host->mmio + reg);
197}
198
199static inline u32 cmdq_readl(struct cmdq_host *host, int reg)
200{
201 if (unlikely(host->ops->read_l))
202 return host->ops->read_l(host, reg);
203 else
204 return readl_relaxed(host->mmio + reg);
205}
206
207extern irqreturn_t cmdq_irq(struct mmc_host *mmc, u32 intmask);
208extern int cmdq_init(struct cmdq_host *cq_host, struct mmc_host *mmc,
209 bool dma64);
210extern struct cmdq_host *cmdq_pltfm_init(struct platform_device *pdev);
211#endif