Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 1 | /* |
| 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 Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 17 | #define DW_MMC_240A 0x240a |
| 18 | |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 19 | #define SDMMC_CTRL 0x000 |
| 20 | #define SDMMC_PWREN 0x004 |
| 21 | #define SDMMC_CLKDIV 0x008 |
| 22 | #define SDMMC_CLKSRC 0x00c |
| 23 | #define SDMMC_CLKENA 0x010 |
| 24 | #define SDMMC_TMOUT 0x014 |
| 25 | #define SDMMC_CTYPE 0x018 |
| 26 | #define SDMMC_BLKSIZ 0x01c |
| 27 | #define SDMMC_BYTCNT 0x020 |
| 28 | #define SDMMC_INTMASK 0x024 |
| 29 | #define SDMMC_CMDARG 0x028 |
| 30 | #define SDMMC_CMD 0x02c |
| 31 | #define SDMMC_RESP0 0x030 |
| 32 | #define SDMMC_RESP1 0x034 |
| 33 | #define SDMMC_RESP2 0x038 |
| 34 | #define SDMMC_RESP3 0x03c |
| 35 | #define SDMMC_MINTSTS 0x040 |
| 36 | #define SDMMC_RINTSTS 0x044 |
| 37 | #define SDMMC_STATUS 0x048 |
| 38 | #define SDMMC_FIFOTH 0x04c |
| 39 | #define SDMMC_CDETECT 0x050 |
| 40 | #define SDMMC_WRTPRT 0x054 |
| 41 | #define SDMMC_GPIO 0x058 |
| 42 | #define SDMMC_TCBCNT 0x05c |
| 43 | #define SDMMC_TBBCNT 0x060 |
| 44 | #define SDMMC_DEBNCE 0x064 |
| 45 | #define SDMMC_USRID 0x068 |
| 46 | #define SDMMC_VERID 0x06c |
| 47 | #define SDMMC_HCON 0x070 |
Jaehoon Chung | 41babf7 | 2011-02-24 13:46:11 +0900 | [diff] [blame] | 48 | #define SDMMC_UHS_REG 0x074 |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 49 | #define SDMMC_BMOD 0x080 |
| 50 | #define SDMMC_PLDMND 0x084 |
| 51 | #define SDMMC_DBADDR 0x088 |
| 52 | #define SDMMC_IDSTS 0x08c |
| 53 | #define SDMMC_IDINTEN 0x090 |
| 54 | #define SDMMC_DSCADDR 0x094 |
| 55 | #define SDMMC_BUFADDR 0x098 |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 56 | #define SDMMC_DATA(x) (x) |
| 57 | |
| 58 | /* |
| 59 | * Data offset is difference according to Version |
| 60 | * Lower than 2.40a : data register offest is 0x100 |
| 61 | */ |
| 62 | #define DATA_OFFSET 0x100 |
| 63 | #define DATA_240A_OFFSET 0x200 |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 64 | |
| 65 | /* shift bit field */ |
| 66 | #define _SBF(f, v) ((v) << (f)) |
| 67 | |
| 68 | /* Control register defines */ |
| 69 | #define SDMMC_CTRL_USE_IDMAC BIT(25) |
| 70 | #define SDMMC_CTRL_CEATA_INT_EN BIT(11) |
| 71 | #define SDMMC_CTRL_SEND_AS_CCSD BIT(10) |
| 72 | #define SDMMC_CTRL_SEND_CCSD BIT(9) |
| 73 | #define SDMMC_CTRL_ABRT_READ_DATA BIT(8) |
| 74 | #define SDMMC_CTRL_SEND_IRQ_RESP BIT(7) |
| 75 | #define SDMMC_CTRL_READ_WAIT BIT(6) |
| 76 | #define SDMMC_CTRL_DMA_ENABLE BIT(5) |
| 77 | #define SDMMC_CTRL_INT_ENABLE BIT(4) |
| 78 | #define SDMMC_CTRL_DMA_RESET BIT(2) |
| 79 | #define SDMMC_CTRL_FIFO_RESET BIT(1) |
| 80 | #define SDMMC_CTRL_RESET BIT(0) |
| 81 | /* Clock Enable register defines */ |
| 82 | #define SDMMC_CLKEN_LOW_PWR BIT(16) |
| 83 | #define SDMMC_CLKEN_ENABLE BIT(0) |
| 84 | /* time-out register defines */ |
| 85 | #define SDMMC_TMOUT_DATA(n) _SBF(8, (n)) |
| 86 | #define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00 |
| 87 | #define SDMMC_TMOUT_RESP(n) ((n) & 0xFF) |
| 88 | #define SDMMC_TMOUT_RESP_MSK 0xFF |
| 89 | /* card-type register defines */ |
| 90 | #define SDMMC_CTYPE_8BIT BIT(16) |
| 91 | #define SDMMC_CTYPE_4BIT BIT(0) |
| 92 | #define SDMMC_CTYPE_1BIT 0 |
| 93 | /* Interrupt status & mask register defines */ |
Shashidhar Hiremath | 1a5c8e1 | 2011-08-29 13:11:46 +0530 | [diff] [blame] | 94 | #define SDMMC_INT_SDIO(n) BIT(16 + (n)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 95 | #define SDMMC_INT_EBE BIT(15) |
| 96 | #define SDMMC_INT_ACD BIT(14) |
| 97 | #define SDMMC_INT_SBE BIT(13) |
| 98 | #define SDMMC_INT_HLE BIT(12) |
| 99 | #define SDMMC_INT_FRUN BIT(11) |
| 100 | #define SDMMC_INT_HTO BIT(10) |
Jaehoon Chung | 3f7eec6 | 2013-05-27 13:47:57 +0900 | [diff] [blame] | 101 | #define SDMMC_INT_DRTO BIT(9) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 102 | #define SDMMC_INT_RTO BIT(8) |
| 103 | #define SDMMC_INT_DCRC BIT(7) |
| 104 | #define SDMMC_INT_RCRC BIT(6) |
| 105 | #define SDMMC_INT_RXDR BIT(5) |
| 106 | #define SDMMC_INT_TXDR BIT(4) |
| 107 | #define SDMMC_INT_DATA_OVER BIT(3) |
| 108 | #define SDMMC_INT_CMD_DONE BIT(2) |
| 109 | #define SDMMC_INT_RESP_ERR BIT(1) |
| 110 | #define SDMMC_INT_CD BIT(0) |
| 111 | #define SDMMC_INT_ERROR 0xbfc2 |
| 112 | /* Command register defines */ |
| 113 | #define SDMMC_CMD_START BIT(31) |
Dinh Nguyen | eede211 | 2013-06-12 10:18:51 -0500 | [diff] [blame] | 114 | #define SDMMC_CMD_USE_HOLD_REG BIT(29) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 115 | #define SDMMC_CMD_CCS_EXP BIT(23) |
| 116 | #define SDMMC_CMD_CEATA_RD BIT(22) |
| 117 | #define SDMMC_CMD_UPD_CLK BIT(21) |
| 118 | #define SDMMC_CMD_INIT BIT(15) |
| 119 | #define SDMMC_CMD_STOP BIT(14) |
| 120 | #define SDMMC_CMD_PRV_DAT_WAIT BIT(13) |
| 121 | #define SDMMC_CMD_SEND_STOP BIT(12) |
| 122 | #define SDMMC_CMD_STRM_MODE BIT(11) |
| 123 | #define SDMMC_CMD_DAT_WR BIT(10) |
| 124 | #define SDMMC_CMD_DAT_EXP BIT(9) |
| 125 | #define SDMMC_CMD_RESP_CRC BIT(8) |
| 126 | #define SDMMC_CMD_RESP_LONG BIT(7) |
| 127 | #define SDMMC_CMD_RESP_EXP BIT(6) |
| 128 | #define SDMMC_CMD_INDX(n) ((n) & 0x1F) |
| 129 | /* Status register defines */ |
Jaehoon Chung | ee5d19b | 2012-01-05 19:12:57 +0900 | [diff] [blame] | 130 | #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF) |
Seungwon Jeon | 52426899 | 2013-08-31 00:13:42 +0900 | [diff] [blame^] | 131 | /* FIFOTH register defines */ |
| 132 | #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \ |
| 133 | ((r) & 0xFFF) << 16 | \ |
| 134 | ((t) & 0xFFF)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 135 | /* Internal DMAC interrupt defines */ |
| 136 | #define SDMMC_IDMAC_INT_AI BIT(9) |
| 137 | #define SDMMC_IDMAC_INT_NI BIT(8) |
| 138 | #define SDMMC_IDMAC_INT_CES BIT(5) |
| 139 | #define SDMMC_IDMAC_INT_DU BIT(4) |
| 140 | #define SDMMC_IDMAC_INT_FBE BIT(2) |
| 141 | #define SDMMC_IDMAC_INT_RI BIT(1) |
| 142 | #define SDMMC_IDMAC_INT_TI BIT(0) |
| 143 | /* Internal DMAC bus mode bits */ |
| 144 | #define SDMMC_IDMAC_ENABLE BIT(7) |
| 145 | #define SDMMC_IDMAC_FB BIT(1) |
| 146 | #define SDMMC_IDMAC_SWRESET BIT(0) |
Jaehoon Chung | 4e0a5ad | 2011-10-17 19:36:23 +0900 | [diff] [blame] | 147 | /* Version ID register define */ |
| 148 | #define SDMMC_GET_VERID(x) ((x) & 0xFFFF) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 149 | |
| 150 | /* Register access macros */ |
| 151 | #define mci_readl(dev, reg) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 152 | __raw_readl((dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 153 | #define mci_writel(dev, reg, value) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 154 | __raw_writel((value), (dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 155 | |
| 156 | /* 16-bit FIFO access macros */ |
| 157 | #define mci_readw(dev, reg) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 158 | __raw_readw((dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 159 | #define mci_writew(dev, reg, value) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 160 | __raw_writew((value), (dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 161 | |
| 162 | /* 64-bit FIFO access macros */ |
| 163 | #ifdef readq |
| 164 | #define mci_readq(dev, reg) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 165 | __raw_readq((dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 166 | #define mci_writeq(dev, reg, value) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 167 | __raw_writeq((value), (dev)->regs + SDMMC_##reg) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 168 | #else |
| 169 | /* |
| 170 | * Dummy readq implementation for architectures that don't define it. |
| 171 | * |
| 172 | * We would assume that none of these architectures would configure |
| 173 | * the IP block with a 64bit FIFO width, so this code will never be |
| 174 | * executed on those machines. Defining these macros here keeps the |
| 175 | * rest of the code free from ifdefs. |
| 176 | */ |
| 177 | #define mci_readq(dev, reg) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 178 | (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 179 | #define mci_writeq(dev, reg, value) \ |
James Hogan | 892b1e3 | 2011-06-24 13:56:38 +0100 | [diff] [blame] | 180 | (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value)) |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 181 | #endif |
| 182 | |
Shashidhar Hiremath | 62ca803 | 2012-01-13 16:04:57 +0530 | [diff] [blame] | 183 | extern int dw_mci_probe(struct dw_mci *host); |
| 184 | extern void dw_mci_remove(struct dw_mci *host); |
| 185 | #ifdef CONFIG_PM |
| 186 | extern int dw_mci_suspend(struct dw_mci *host); |
| 187 | extern int dw_mci_resume(struct dw_mci *host); |
| 188 | #endif |
| 189 | |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 190 | /** |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 191 | * struct dw_mci_slot - MMC slot state |
| 192 | * @mmc: The mmc_host representing this slot. |
| 193 | * @host: The MMC controller this slot is using. |
| 194 | * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX) |
| 195 | * @wp_gpio: If gpio_is_valid() we'll use this to read write protect. |
| 196 | * @ctype: Card type for this slot. |
| 197 | * @mrq: mmc_request currently being processed or waiting to be |
| 198 | * processed, or NULL when the slot is idle. |
| 199 | * @queue_node: List node for placing this node in the @queue list of |
| 200 | * &struct dw_mci. |
| 201 | * @clock: Clock rate configured by set_ios(). Protected by host->lock. |
| 202 | * @__clk_old: The last updated clock with reflecting clock divider. |
| 203 | * Keeping track of this helps us to avoid spamming the console |
| 204 | * with CONFIG_MMC_CLKGATE. |
| 205 | * @flags: Random state bits associated with the slot. |
| 206 | * @id: Number of this slot. |
| 207 | * @last_detect_state: Most recently observed card detect state. |
| 208 | */ |
| 209 | struct dw_mci_slot { |
| 210 | struct mmc_host *mmc; |
| 211 | struct dw_mci *host; |
| 212 | |
| 213 | int quirks; |
| 214 | int wp_gpio; |
| 215 | |
| 216 | u32 ctype; |
| 217 | |
| 218 | struct mmc_request *mrq; |
| 219 | struct list_head queue_node; |
| 220 | |
| 221 | unsigned int clock; |
| 222 | unsigned int __clk_old; |
| 223 | |
| 224 | unsigned long flags; |
| 225 | #define DW_MMC_CARD_PRESENT 0 |
| 226 | #define DW_MMC_CARD_NEED_INIT 1 |
| 227 | int id; |
| 228 | int last_detect_state; |
| 229 | }; |
| 230 | |
| 231 | struct dw_mci_tuning_data { |
| 232 | const u8 *blk_pattern; |
| 233 | unsigned int blksz; |
| 234 | }; |
| 235 | |
| 236 | /** |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 237 | * dw_mci driver data - dw-mshc implementation specific driver data. |
| 238 | * @caps: mmc subsystem specified capabilities of the controller(s). |
| 239 | * @init: early implementation specific initialization. |
| 240 | * @setup_clock: implementation specific clock configuration. |
| 241 | * @prepare_command: handle CMD register extensions. |
| 242 | * @set_ios: handle bus specific extensions. |
| 243 | * @parse_dt: parse implementation specific device tree properties. |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 244 | * |
| 245 | * Provide controller implementation specific extensions. The usage of this |
| 246 | * data structure is fully optional and usage of each member in this structure |
| 247 | * is optional as well. |
| 248 | */ |
| 249 | struct dw_mci_drv_data { |
| 250 | unsigned long *caps; |
| 251 | int (*init)(struct dw_mci *host); |
| 252 | int (*setup_clock)(struct dw_mci *host); |
| 253 | void (*prepare_command)(struct dw_mci *host, u32 *cmdr); |
| 254 | void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); |
| 255 | int (*parse_dt)(struct dw_mci *host); |
Seungwon Jeon | 0976f16 | 2013-08-31 00:12:42 +0900 | [diff] [blame] | 256 | int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode, |
| 257 | struct dw_mci_tuning_data *tuning_data); |
Thomas Abraham | 800d78b | 2012-09-17 18:16:42 +0000 | [diff] [blame] | 258 | }; |
Will Newton | f95f385 | 2011-01-02 01:11:59 -0500 | [diff] [blame] | 259 | #endif /* _DW_MMC_H_ */ |