1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (c) 2015, The Linux Foundation. All rights reserved.
4 #ifndef LINUX_MMC_CQHCI_H
5 #define LINUX_MMC_CQHCI_H
7 #include <linux/compiler.h>
8 #include <linux/bitops.h>
9 #include <linux/spinlock_types.h>
10 #include <linux/types.h>
11 #include <linux/completion.h>
12 #include <linux/wait.h>
13 #include <linux/irqreturn.h>
18 #define CQHCI_VER 0x00
19 #define CQHCI_VER_MAJOR(x) (((x) & GENMASK(11, 8)) >> 8)
20 #define CQHCI_VER_MINOR1(x) (((x) & GENMASK(7, 4)) >> 4)
21 #define CQHCI_VER_MINOR2(x) ((x) & GENMASK(3, 0))
24 #define CQHCI_CAP 0x04
26 #define CQHCI_CFG 0x08
27 #define CQHCI_DCMD 0x00001000
28 #define CQHCI_TASK_DESC_SZ 0x00000100
29 #define CQHCI_ENABLE 0x00000001
32 #define CQHCI_CTL 0x0C
33 #define CQHCI_CLEAR_ALL_TASKS 0x00000100
34 #define CQHCI_HALT 0x00000001
36 /* interrupt status */
38 #define CQHCI_IS_HAC BIT(0)
39 #define CQHCI_IS_TCC BIT(1)
40 #define CQHCI_IS_RED BIT(2)
41 #define CQHCI_IS_TCL BIT(3)
43 #define CQHCI_IS_MASK (CQHCI_IS_TCC | CQHCI_IS_RED)
45 /* interrupt status enable */
46 #define CQHCI_ISTE 0x14
48 /* interrupt signal enable */
49 #define CQHCI_ISGE 0x18
51 /* interrupt coalescing */
53 #define CQHCI_IC_ENABLE BIT(31)
54 #define CQHCI_IC_RESET BIT(16)
55 #define CQHCI_IC_ICCTHWEN BIT(15)
56 #define CQHCI_IC_ICCTH(x) (((x) & 0x1F) << 8)
57 #define CQHCI_IC_ICTOVALWEN BIT(7)
58 #define CQHCI_IC_ICTOVAL(x) ((x) & 0x7F)
60 /* task list base address */
61 #define CQHCI_TDLBA 0x20
63 /* task list base address upper */
64 #define CQHCI_TDLBAU 0x24
67 #define CQHCI_TDBR 0x28
69 /* task completion notification */
70 #define CQHCI_TCN 0x2C
72 /* device queue status */
73 #define CQHCI_DQS 0x30
75 /* device pending tasks */
76 #define CQHCI_DPT 0x34
79 #define CQHCI_TCLR 0x38
81 /* send status config 1 */
82 #define CQHCI_SSC1 0x40
83 #define CQHCI_SSC1_CBC_MASK GENMASK(19, 16)
85 /* send status config 2 */
86 #define CQHCI_SSC2 0x44
88 /* response for dcmd */
89 #define CQHCI_CRDCT 0x48
91 /* response mode error mask */
92 #define CQHCI_RMEM 0x50
95 #define CQHCI_TERRI 0x54
97 #define CQHCI_TERRI_C_INDEX(x) ((x) & GENMASK(5, 0))
98 #define CQHCI_TERRI_C_TASK(x) (((x) & GENMASK(12, 8)) >> 8)
99 #define CQHCI_TERRI_C_VALID(x) ((x) & BIT(15))
100 #define CQHCI_TERRI_D_INDEX(x) (((x) & GENMASK(21, 16)) >> 16)
101 #define CQHCI_TERRI_D_TASK(x) (((x) & GENMASK(28, 24)) >> 24)
102 #define CQHCI_TERRI_D_VALID(x) ((x) & BIT(31))
104 /* command response index */
105 #define CQHCI_CRI 0x58
107 /* command response argument */
108 #define CQHCI_CRA 0x5C
110 #define CQHCI_INT_ALL 0xF
111 #define CQHCI_IC_DEFAULT_ICCTH 31
112 #define CQHCI_IC_DEFAULT_ICTOVAL 1
114 /* attribute fields */
115 #define CQHCI_VALID(x) (((x) & 1) << 0)
116 #define CQHCI_END(x) (((x) & 1) << 1)
117 #define CQHCI_INT(x) (((x) & 1) << 2)
118 #define CQHCI_ACT(x) (((x) & 0x7) << 3)
120 /* data command task descriptor fields */
121 #define CQHCI_FORCED_PROG(x) (((x) & 1) << 6)
122 #define CQHCI_CONTEXT(x) (((x) & 0xF) << 7)
123 #define CQHCI_DATA_TAG(x) (((x) & 1) << 11)
124 #define CQHCI_DATA_DIR(x) (((x) & 1) << 12)
125 #define CQHCI_PRIORITY(x) (((x) & 1) << 13)
126 #define CQHCI_QBAR(x) (((x) & 1) << 14)
127 #define CQHCI_REL_WRITE(x) (((x) & 1) << 15)
128 #define CQHCI_BLK_COUNT(x) (((x) & 0xFFFF) << 16)
129 #define CQHCI_BLK_ADDR(x) (((x) & 0xFFFFFFFF) << 32)
131 /* direct command task descriptor fields */
132 #define CQHCI_CMD_INDEX(x) (((x) & 0x3F) << 16)
133 #define CQHCI_CMD_TIMING(x) (((x) & 1) << 22)
134 #define CQHCI_RESP_TYPE(x) (((x) & 0x3) << 23)
136 /* transfer descriptor fields */
137 #define CQHCI_DAT_LENGTH(x) (((x) & 0xFFFF) << 16)
138 #define CQHCI_DAT_ADDR_LO(x) (((x) & 0xFFFFFFFF) << 32)
139 #define CQHCI_DAT_ADDR_HI(x) (((x) & 0xFFFFFFFF) << 0)
141 struct cqhci_host_ops
;
147 const struct cqhci_host_ops
*ops
;
149 struct mmc_host
*mmc
;
153 /* relative card address of device */
163 #define CQHCI_TASK_DESC_SZ_128 0x1
166 #define CQHCI_QUIRK_SHORT_TXFR_DESC_SZ 0x1
172 bool waiting_for_idle
;
180 /* total descriptor size */
183 /* 64/128 bit depends on CQHCI_CFG */
186 /* 64 bit on 32-bit arch, 128 bit on 64-bit */
190 /* same length as transfer descriptor */
193 dma_addr_t desc_dma_base
;
194 dma_addr_t trans_desc_dma_base
;
196 struct completion halt_comp
;
197 wait_queue_head_t wait_queue
;
198 struct cqhci_slot
*slot
;
201 struct cqhci_host_ops
{
202 void (*dumpregs
)(struct mmc_host
*mmc
);
203 void (*write_l
)(struct cqhci_host
*host
, u32 val
, int reg
);
204 u32 (*read_l
)(struct cqhci_host
*host
, int reg
);
205 void (*enable
)(struct mmc_host
*mmc
);
206 void (*disable
)(struct mmc_host
*mmc
, bool recovery
);
207 void (*update_dcmd_desc
)(struct mmc_host
*mmc
, struct mmc_request
*mrq
,
209 void (*pre_enable
)(struct mmc_host
*mmc
);
210 void (*post_disable
)(struct mmc_host
*mmc
);
213 static inline void cqhci_writel(struct cqhci_host
*host
, u32 val
, int reg
)
215 if (unlikely(host
->ops
->write_l
))
216 host
->ops
->write_l(host
, val
, reg
);
218 writel_relaxed(val
, host
->mmio
+ reg
);
221 static inline u32
cqhci_readl(struct cqhci_host
*host
, int reg
)
223 if (unlikely(host
->ops
->read_l
))
224 return host
->ops
->read_l(host
, reg
);
226 return readl_relaxed(host
->mmio
+ reg
);
229 struct platform_device
;
231 irqreturn_t
cqhci_irq(struct mmc_host
*mmc
, u32 intmask
, int cmd_error
,
233 int cqhci_init(struct cqhci_host
*cq_host
, struct mmc_host
*mmc
, bool dma64
);
234 struct cqhci_host
*cqhci_pltfm_init(struct platform_device
*pdev
);
235 int cqhci_deactivate(struct mmc_host
*mmc
);
236 static inline int cqhci_suspend(struct mmc_host
*mmc
)
238 return cqhci_deactivate(mmc
);
240 int cqhci_resume(struct mmc_host
*mmc
);