blob: e8cd2dec3263d308ed0ebc9f52271c4b72bc5f05 [file] [log] [blame]
Will Newtonf95f3852011-01-02 01:11:59 -05001/*
2 * Synopsys DesignWare Multimedia Card Interface driver
3 * (Based on NXP driver for lpc 31xx)
4 *
5 * Copyright (C) 2009 NXP Semiconductors
6 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#ifndef _DW_MMC_H_
15#define _DW_MMC_H_
16
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +090017#define DW_MMC_240A 0x240a
Jaehoon Chung7e4bf1b2016-06-21 14:35:38 +090018#define DW_MMC_280A 0x280a
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +090019
Will Newtonf95f3852011-01-02 01:11:59 -050020#define SDMMC_CTRL 0x000
21#define SDMMC_PWREN 0x004
22#define SDMMC_CLKDIV 0x008
23#define SDMMC_CLKSRC 0x00c
24#define SDMMC_CLKENA 0x010
25#define SDMMC_TMOUT 0x014
26#define SDMMC_CTYPE 0x018
27#define SDMMC_BLKSIZ 0x01c
28#define SDMMC_BYTCNT 0x020
29#define SDMMC_INTMASK 0x024
30#define SDMMC_CMDARG 0x028
31#define SDMMC_CMD 0x02c
32#define SDMMC_RESP0 0x030
33#define SDMMC_RESP1 0x034
34#define SDMMC_RESP2 0x038
35#define SDMMC_RESP3 0x03c
36#define SDMMC_MINTSTS 0x040
37#define SDMMC_RINTSTS 0x044
38#define SDMMC_STATUS 0x048
39#define SDMMC_FIFOTH 0x04c
40#define SDMMC_CDETECT 0x050
41#define SDMMC_WRTPRT 0x054
42#define SDMMC_GPIO 0x058
43#define SDMMC_TCBCNT 0x05c
44#define SDMMC_TBBCNT 0x060
45#define SDMMC_DEBNCE 0x064
46#define SDMMC_USRID 0x068
47#define SDMMC_VERID 0x06c
48#define SDMMC_HCON 0x070
Jaehoon Chung41babf72011-02-24 13:46:11 +090049#define SDMMC_UHS_REG 0x074
Shawn Lin935a6652016-01-14 09:08:02 +080050#define SDMMC_RST_N 0x078
Will Newtonf95f3852011-01-02 01:11:59 -050051#define SDMMC_BMOD 0x080
52#define SDMMC_PLDMND 0x084
53#define SDMMC_DBADDR 0x088
54#define SDMMC_IDSTS 0x08c
55#define SDMMC_IDINTEN 0x090
56#define SDMMC_DSCADDR 0x094
57#define SDMMC_BUFADDR 0x098
Seungwon Jeonf1d27362013-08-31 00:13:55 +090058#define SDMMC_CDTHRCTL 0x100
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +090059#define SDMMC_DATA(x) (x)
Prabu Thangamuthu69d99fd2014-10-20 07:12:33 +000060/*
61* Registers to support idmac 64-bit address mode
62*/
63#define SDMMC_DBADDRL 0x088
64#define SDMMC_DBADDRU 0x08c
65#define SDMMC_IDSTS64 0x090
66#define SDMMC_IDINTEN64 0x094
67#define SDMMC_DSCADDRL 0x098
68#define SDMMC_DSCADDRU 0x09c
69#define SDMMC_BUFADDRL 0x0A0
70#define SDMMC_BUFADDRU 0x0A4
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +090071
72/*
73 * Data offset is difference according to Version
74 * Lower than 2.40a : data register offest is 0x100
75 */
76#define DATA_OFFSET 0x100
77#define DATA_240A_OFFSET 0x200
Will Newtonf95f3852011-01-02 01:11:59 -050078
79/* shift bit field */
80#define _SBF(f, v) ((v) << (f))
81
82/* Control register defines */
83#define SDMMC_CTRL_USE_IDMAC BIT(25)
84#define SDMMC_CTRL_CEATA_INT_EN BIT(11)
85#define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
86#define SDMMC_CTRL_SEND_CCSD BIT(9)
87#define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
88#define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
89#define SDMMC_CTRL_READ_WAIT BIT(6)
90#define SDMMC_CTRL_DMA_ENABLE BIT(5)
91#define SDMMC_CTRL_INT_ENABLE BIT(4)
92#define SDMMC_CTRL_DMA_RESET BIT(2)
93#define SDMMC_CTRL_FIFO_RESET BIT(1)
94#define SDMMC_CTRL_RESET BIT(0)
95/* Clock Enable register defines */
96#define SDMMC_CLKEN_LOW_PWR BIT(16)
97#define SDMMC_CLKEN_ENABLE BIT(0)
98/* time-out register defines */
99#define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
100#define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
101#define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
102#define SDMMC_TMOUT_RESP_MSK 0xFF
103/* card-type register defines */
104#define SDMMC_CTYPE_8BIT BIT(16)
105#define SDMMC_CTYPE_4BIT BIT(0)
106#define SDMMC_CTYPE_1BIT 0
107/* Interrupt status & mask register defines */
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530108#define SDMMC_INT_SDIO(n) BIT(16 + (n))
Will Newtonf95f3852011-01-02 01:11:59 -0500109#define SDMMC_INT_EBE BIT(15)
110#define SDMMC_INT_ACD BIT(14)
111#define SDMMC_INT_SBE BIT(13)
112#define SDMMC_INT_HLE BIT(12)
113#define SDMMC_INT_FRUN BIT(11)
114#define SDMMC_INT_HTO BIT(10)
Doug Anderson01730552014-08-22 19:17:51 +0530115#define SDMMC_INT_VOLT_SWITCH BIT(10) /* overloads bit 10! */
Jaehoon Chung3f7eec62013-05-27 13:47:57 +0900116#define SDMMC_INT_DRTO BIT(9)
Will Newtonf95f3852011-01-02 01:11:59 -0500117#define SDMMC_INT_RTO BIT(8)
118#define SDMMC_INT_DCRC BIT(7)
119#define SDMMC_INT_RCRC BIT(6)
120#define SDMMC_INT_RXDR BIT(5)
121#define SDMMC_INT_TXDR BIT(4)
122#define SDMMC_INT_DATA_OVER BIT(3)
123#define SDMMC_INT_CMD_DONE BIT(2)
124#define SDMMC_INT_RESP_ERR BIT(1)
125#define SDMMC_INT_CD BIT(0)
126#define SDMMC_INT_ERROR 0xbfc2
127/* Command register defines */
128#define SDMMC_CMD_START BIT(31)
Dinh Nguyeneede2112013-06-12 10:18:51 -0500129#define SDMMC_CMD_USE_HOLD_REG BIT(29)
Doug Anderson01730552014-08-22 19:17:51 +0530130#define SDMMC_CMD_VOLT_SWITCH BIT(28)
Will Newtonf95f3852011-01-02 01:11:59 -0500131#define SDMMC_CMD_CCS_EXP BIT(23)
132#define SDMMC_CMD_CEATA_RD BIT(22)
133#define SDMMC_CMD_UPD_CLK BIT(21)
134#define SDMMC_CMD_INIT BIT(15)
135#define SDMMC_CMD_STOP BIT(14)
136#define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
137#define SDMMC_CMD_SEND_STOP BIT(12)
138#define SDMMC_CMD_STRM_MODE BIT(11)
139#define SDMMC_CMD_DAT_WR BIT(10)
140#define SDMMC_CMD_DAT_EXP BIT(9)
141#define SDMMC_CMD_RESP_CRC BIT(8)
142#define SDMMC_CMD_RESP_LONG BIT(7)
143#define SDMMC_CMD_RESP_EXP BIT(6)
144#define SDMMC_CMD_INDX(n) ((n) & 0x1F)
145/* Status register defines */
Jaehoon Chungee5d19b2012-01-05 19:12:57 +0900146#define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
Sonny Rao3a33a942014-08-04 18:19:50 -0700147#define SDMMC_STATUS_DMA_REQ BIT(31)
Doug Anderson01730552014-08-22 19:17:51 +0530148#define SDMMC_STATUS_BUSY BIT(9)
Seungwon Jeon52426892013-08-31 00:13:42 +0900149/* FIFOTH register defines */
150#define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
151 ((r) & 0xFFF) << 16 | \
152 ((t) & 0xFFF))
Shawn Lin3fc7eae2015-09-16 14:41:23 +0800153/* HCON register defines */
154#define DMA_INTERFACE_IDMA (0x0)
155#define DMA_INTERFACE_DWDMA (0x1)
156#define DMA_INTERFACE_GDMA (0x2)
157#define DMA_INTERFACE_NODMA (0x3)
158#define SDMMC_GET_TRANS_MODE(x) (((x)>>16) & 0x3)
Shawn Lin70692752015-09-16 14:41:37 +0800159#define SDMMC_GET_SLOT_NUM(x) ((((x)>>1) & 0x1F) + 1)
160#define SDMMC_GET_HDATA_WIDTH(x) (((x)>>7) & 0x7)
161#define SDMMC_GET_ADDR_CONFIG(x) (((x)>>27) & 0x1)
Will Newtonf95f3852011-01-02 01:11:59 -0500162/* Internal DMAC interrupt defines */
163#define SDMMC_IDMAC_INT_AI BIT(9)
164#define SDMMC_IDMAC_INT_NI BIT(8)
165#define SDMMC_IDMAC_INT_CES BIT(5)
166#define SDMMC_IDMAC_INT_DU BIT(4)
167#define SDMMC_IDMAC_INT_FBE BIT(2)
168#define SDMMC_IDMAC_INT_RI BIT(1)
169#define SDMMC_IDMAC_INT_TI BIT(0)
170/* Internal DMAC bus mode bits */
171#define SDMMC_IDMAC_ENABLE BIT(7)
172#define SDMMC_IDMAC_FB BIT(1)
173#define SDMMC_IDMAC_SWRESET BIT(0)
Shawn Lin935a6652016-01-14 09:08:02 +0800174/* H/W reset */
175#define SDMMC_RST_HWACTIVE 0x1
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +0900176/* Version ID register define */
177#define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
Seungwon Jeonf1d27362013-08-31 00:13:55 +0900178/* Card read threshold */
Jaehoon Chung7e4bf1b2016-06-21 14:35:38 +0900179#define SDMMC_SET_THLD(v, x) (((v) & 0xFFF) << 16 | (x))
180#define SDMMC_CARD_WR_THR_EN BIT(2)
181#define SDMMC_CARD_RD_THR_EN BIT(0)
182/* UHS-1 register defines */
Doug Anderson01730552014-08-22 19:17:51 +0530183#define SDMMC_UHS_18V BIT(0)
Sonny Rao3a33a942014-08-04 18:19:50 -0700184/* All ctrl reset bits */
185#define SDMMC_CTRL_ALL_RESET_FLAGS \
186 (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
187
Ben Dooks76184ac2015-03-25 11:27:52 +0000188/* FIFO register access macros. These should not change the data endian-ness
189 * as they are written to memory to be dealt with by the upper layers */
190#define mci_fifo_readw(__reg) __raw_readw(__reg)
191#define mci_fifo_readl(__reg) __raw_readl(__reg)
192#define mci_fifo_readq(__reg) __raw_readq(__reg)
193
194#define mci_fifo_writew(__value, __reg) __raw_writew(__reg, __value)
195#define mci_fifo_writel(__value, __reg) __raw_writel(__reg, __value)
196#define mci_fifo_writeq(__value, __reg) __raw_writeq(__reg, __value)
197
Will Newtonf95f3852011-01-02 01:11:59 -0500198/* Register access macros */
199#define mci_readl(dev, reg) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000200 readl_relaxed((dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500201#define mci_writel(dev, reg, value) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000202 writel_relaxed((value), (dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500203
204/* 16-bit FIFO access macros */
205#define mci_readw(dev, reg) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000206 readw_relaxed((dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500207#define mci_writew(dev, reg, value) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000208 writew_relaxed((value), (dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500209
210/* 64-bit FIFO access macros */
211#ifdef readq
212#define mci_readq(dev, reg) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000213 readq_relaxed((dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500214#define mci_writeq(dev, reg, value) \
Ben Dooksa2f17682015-03-25 11:27:50 +0000215 writeq_relaxed((value), (dev)->regs + SDMMC_##reg)
Will Newtonf95f3852011-01-02 01:11:59 -0500216#else
217/*
218 * Dummy readq implementation for architectures that don't define it.
219 *
220 * We would assume that none of these architectures would configure
221 * the IP block with a 64bit FIFO width, so this code will never be
222 * executed on those machines. Defining these macros here keeps the
223 * rest of the code free from ifdefs.
224 */
225#define mci_readq(dev, reg) \
James Hogan892b1e32011-06-24 13:56:38 +0100226 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
Will Newtonf95f3852011-01-02 01:11:59 -0500227#define mci_writeq(dev, reg, value) \
James Hogan892b1e32011-06-24 13:56:38 +0100228 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
Ben Dooks76184ac2015-03-25 11:27:52 +0000229
230#define __raw_writeq(__value, __reg) \
231 (*(volatile u64 __force *)(__reg) = (__value))
232#define __raw_readq(__reg) (*(volatile u64 __force *)(__reg))
Will Newtonf95f3852011-01-02 01:11:59 -0500233#endif
234
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530235extern int dw_mci_probe(struct dw_mci *host);
236extern void dw_mci_remove(struct dw_mci *host);
Felipe Balbi370aede2014-02-25 08:57:44 -0600237#ifdef CONFIG_PM_SLEEP
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530238extern int dw_mci_suspend(struct dw_mci *host);
239extern int dw_mci_resume(struct dw_mci *host);
240#endif
241
Thomas Abraham800d78b2012-09-17 18:16:42 +0000242/**
Seungwon Jeon0976f162013-08-31 00:12:42 +0900243 * struct dw_mci_slot - MMC slot state
244 * @mmc: The mmc_host representing this slot.
245 * @host: The MMC controller this slot is using.
Seungwon Jeon0976f162013-08-31 00:12:42 +0900246 * @ctype: Card type for this slot.
247 * @mrq: mmc_request currently being processed or waiting to be
248 * processed, or NULL when the slot is idle.
249 * @queue_node: List node for placing this node in the @queue list of
250 * &struct dw_mci.
251 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
Jaehoon Chung005d6752016-09-22 14:12:00 +0900252 * @__clk_old: The last clock value that was requested from core.
253 * Keeping track of this helps us to avoid spamming the console.
Seungwon Jeon0976f162013-08-31 00:12:42 +0900254 * @flags: Random state bits associated with the slot.
255 * @id: Number of this slot.
Addy Ke76756232014-11-04 22:03:09 +0800256 * @sdio_id: Number of this slot in the SDIO interrupt registers.
Seungwon Jeon0976f162013-08-31 00:12:42 +0900257 */
258struct dw_mci_slot {
259 struct mmc_host *mmc;
260 struct dw_mci *host;
261
Seungwon Jeon0976f162013-08-31 00:12:42 +0900262 u32 ctype;
263
264 struct mmc_request *mrq;
265 struct list_head queue_node;
266
267 unsigned int clock;
Jaehoon Chung005d6752016-09-22 14:12:00 +0900268 unsigned int __clk_old;
Seungwon Jeon0976f162013-08-31 00:12:42 +0900269
270 unsigned long flags;
271#define DW_MMC_CARD_PRESENT 0
272#define DW_MMC_CARD_NEED_INIT 1
Doug Andersonb24c8b22014-12-02 15:42:46 -0800273#define DW_MMC_CARD_NO_LOW_PWR 2
Jaehoon Chungaaaaeb72016-01-21 11:01:06 +0900274#define DW_MMC_CARD_NO_USE_HOLD 3
Seungwon Jeon0976f162013-08-31 00:12:42 +0900275 int id;
Addy Ke76756232014-11-04 22:03:09 +0800276 int sdio_id;
Seungwon Jeon0976f162013-08-31 00:12:42 +0900277};
278
Seungwon Jeon0976f162013-08-31 00:12:42 +0900279/**
Thomas Abraham800d78b2012-09-17 18:16:42 +0000280 * dw_mci driver data - dw-mshc implementation specific driver data.
281 * @caps: mmc subsystem specified capabilities of the controller(s).
282 * @init: early implementation specific initialization.
Thomas Abraham800d78b2012-09-17 18:16:42 +0000283 * @set_ios: handle bus specific extensions.
284 * @parse_dt: parse implementation specific device tree properties.
Sachin Kamat5532ec52014-02-25 15:18:25 +0530285 * @execute_tuning: implementation specific tuning procedure.
Thomas Abraham800d78b2012-09-17 18:16:42 +0000286 *
287 * Provide controller implementation specific extensions. The usage of this
288 * data structure is fully optional and usage of each member in this structure
289 * is optional as well.
290 */
291struct dw_mci_drv_data {
292 unsigned long *caps;
293 int (*init)(struct dw_mci *host);
Thomas Abraham800d78b2012-09-17 18:16:42 +0000294 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
295 int (*parse_dt)(struct dw_mci *host);
Chaotian Jing9979dbe2015-10-27 14:24:28 +0800296 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode);
Seungwon Jeon80113132015-01-29 08:11:57 +0530297 int (*prepare_hs400_tuning)(struct dw_mci *host,
298 struct mmc_ios *ios);
Zhangfei Gao8f7849c2015-05-14 16:45:18 +0800299 int (*switch_voltage)(struct mmc_host *mmc,
300 struct mmc_ios *ios);
Thomas Abraham800d78b2012-09-17 18:16:42 +0000301};
Will Newtonf95f3852011-01-02 01:11:59 -0500302#endif /* _DW_MMC_H_ */