0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _DW_MMC_H_
0011 #define _DW_MMC_H_
0012
0013 #include <linux/scatterlist.h>
0014 #include <linux/mmc/core.h>
0015 #include <linux/dmaengine.h>
0016 #include <linux/reset.h>
0017 #include <linux/fault-inject.h>
0018 #include <linux/hrtimer.h>
0019 #include <linux/interrupt.h>
0020
0021 enum dw_mci_state {
0022 STATE_IDLE = 0,
0023 STATE_SENDING_CMD,
0024 STATE_SENDING_DATA,
0025 STATE_DATA_BUSY,
0026 STATE_SENDING_STOP,
0027 STATE_DATA_ERROR,
0028 STATE_SENDING_CMD11,
0029 STATE_WAITING_CMD11_DONE,
0030 };
0031
0032 enum {
0033 EVENT_CMD_COMPLETE = 0,
0034 EVENT_XFER_COMPLETE,
0035 EVENT_DATA_COMPLETE,
0036 EVENT_DATA_ERROR,
0037 };
0038
0039 enum dw_mci_cookie {
0040 COOKIE_UNMAPPED,
0041 COOKIE_PRE_MAPPED,
0042 COOKIE_MAPPED,
0043 };
0044
0045 struct mmc_data;
0046
0047 enum {
0048 TRANS_MODE_PIO = 0,
0049 TRANS_MODE_IDMAC,
0050 TRANS_MODE_EDMAC
0051 };
0052
0053 struct dw_mci_dma_slave {
0054 struct dma_chan *ch;
0055 enum dma_transfer_direction direction;
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159 struct dw_mci {
0160 spinlock_t lock;
0161 spinlock_t irq_lock;
0162 void __iomem *regs;
0163 void __iomem *fifo_reg;
0164 u32 data_addr_override;
0165 bool wm_aligned;
0166
0167 struct scatterlist *sg;
0168 struct sg_mapping_iter sg_miter;
0169
0170 struct mmc_request *mrq;
0171 struct mmc_command *cmd;
0172 struct mmc_data *data;
0173 struct mmc_command stop_abort;
0174 unsigned int prev_blksz;
0175 unsigned char timing;
0176
0177
0178 int use_dma;
0179 int using_dma;
0180 int dma_64bit_address;
0181
0182 dma_addr_t sg_dma;
0183 void *sg_cpu;
0184 const struct dw_mci_dma_ops *dma_ops;
0185
0186 unsigned int ring_size;
0187
0188
0189 struct dw_mci_dma_slave *dms;
0190
0191 resource_size_t phy_regs;
0192
0193 u32 cmd_status;
0194 u32 data_status;
0195 u32 stop_cmdr;
0196 u32 dir_status;
0197 struct tasklet_struct tasklet;
0198 unsigned long pending_events;
0199 unsigned long completed_events;
0200 enum dw_mci_state state;
0201 struct list_head queue;
0202
0203 u32 bus_hz;
0204 u32 current_speed;
0205 u32 minimum_speed;
0206 u32 fifoth_val;
0207 u16 verid;
0208 struct device *dev;
0209 struct dw_mci_board *pdata;
0210 const struct dw_mci_drv_data *drv_data;
0211 void *priv;
0212 struct clk *biu_clk;
0213 struct clk *ciu_clk;
0214 struct dw_mci_slot *slot;
0215
0216
0217 int fifo_depth;
0218 int data_shift;
0219 u8 part_buf_start;
0220 u8 part_buf_count;
0221 union {
0222 u16 part_buf16;
0223 u32 part_buf32;
0224 u64 part_buf;
0225 };
0226 void (*push_data)(struct dw_mci *host, void *buf, int cnt);
0227 void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
0228
0229 u32 quirks;
0230 bool vqmmc_enabled;
0231 unsigned long irq_flags;
0232 int irq;
0233
0234 int sdio_id0;
0235
0236 struct timer_list cmd11_timer;
0237 struct timer_list cto_timer;
0238 struct timer_list dto_timer;
0239
0240 #ifdef CONFIG_FAULT_INJECTION
0241 struct fault_attr fail_data_crc;
0242 struct hrtimer fault_timer;
0243 #endif
0244 };
0245
0246
0247 struct dw_mci_dma_ops {
0248
0249 int (*init)(struct dw_mci *host);
0250 int (*start)(struct dw_mci *host, unsigned int sg_len);
0251 void (*complete)(void *host);
0252 void (*stop)(struct dw_mci *host);
0253 void (*cleanup)(struct dw_mci *host);
0254 void (*exit)(struct dw_mci *host);
0255 };
0256
0257 struct dma_pdata;
0258
0259
0260 struct dw_mci_board {
0261 unsigned int bus_hz;
0262
0263 u32 caps;
0264 u32 caps2;
0265 u32 pm_caps;
0266
0267
0268
0269
0270
0271 unsigned int fifo_depth;
0272
0273
0274 u32 detect_delay_ms;
0275
0276 struct reset_control *rstc;
0277 struct dw_mci_dma_ops *dma_ops;
0278 struct dma_pdata *data;
0279 };
0280
0281
0282 #define DW_MMC_QUIRK_EXTENDED_TMOUT BIT(0)
0283
0284 #define DW_MMC_240A 0x240a
0285 #define DW_MMC_280A 0x280a
0286
0287 #define SDMMC_CTRL 0x000
0288 #define SDMMC_PWREN 0x004
0289 #define SDMMC_CLKDIV 0x008
0290 #define SDMMC_CLKSRC 0x00c
0291 #define SDMMC_CLKENA 0x010
0292 #define SDMMC_TMOUT 0x014
0293 #define SDMMC_CTYPE 0x018
0294 #define SDMMC_BLKSIZ 0x01c
0295 #define SDMMC_BYTCNT 0x020
0296 #define SDMMC_INTMASK 0x024
0297 #define SDMMC_CMDARG 0x028
0298 #define SDMMC_CMD 0x02c
0299 #define SDMMC_RESP0 0x030
0300 #define SDMMC_RESP1 0x034
0301 #define SDMMC_RESP2 0x038
0302 #define SDMMC_RESP3 0x03c
0303 #define SDMMC_MINTSTS 0x040
0304 #define SDMMC_RINTSTS 0x044
0305 #define SDMMC_STATUS 0x048
0306 #define SDMMC_FIFOTH 0x04c
0307 #define SDMMC_CDETECT 0x050
0308 #define SDMMC_WRTPRT 0x054
0309 #define SDMMC_GPIO 0x058
0310 #define SDMMC_TCBCNT 0x05c
0311 #define SDMMC_TBBCNT 0x060
0312 #define SDMMC_DEBNCE 0x064
0313 #define SDMMC_USRID 0x068
0314 #define SDMMC_VERID 0x06c
0315 #define SDMMC_HCON 0x070
0316 #define SDMMC_UHS_REG 0x074
0317 #define SDMMC_RST_N 0x078
0318 #define SDMMC_BMOD 0x080
0319 #define SDMMC_PLDMND 0x084
0320 #define SDMMC_DBADDR 0x088
0321 #define SDMMC_IDSTS 0x08c
0322 #define SDMMC_IDINTEN 0x090
0323 #define SDMMC_DSCADDR 0x094
0324 #define SDMMC_BUFADDR 0x098
0325 #define SDMMC_CDTHRCTL 0x100
0326 #define SDMMC_UHS_REG_EXT 0x108
0327 #define SDMMC_DDR_REG 0x10c
0328 #define SDMMC_ENABLE_SHIFT 0x110
0329 #define SDMMC_DATA(x) (x)
0330
0331
0332
0333 #define SDMMC_DBADDRL 0x088
0334 #define SDMMC_DBADDRU 0x08c
0335 #define SDMMC_IDSTS64 0x090
0336 #define SDMMC_IDINTEN64 0x094
0337 #define SDMMC_DSCADDRL 0x098
0338 #define SDMMC_DSCADDRU 0x09c
0339 #define SDMMC_BUFADDRL 0x0A0
0340 #define SDMMC_BUFADDRU 0x0A4
0341
0342
0343
0344
0345
0346 #define DATA_OFFSET 0x100
0347 #define DATA_240A_OFFSET 0x200
0348
0349
0350 #define _SBF(f, v) ((v) << (f))
0351
0352
0353 #define SDMMC_CTRL_USE_IDMAC BIT(25)
0354 #define SDMMC_CTRL_CEATA_INT_EN BIT(11)
0355 #define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
0356 #define SDMMC_CTRL_SEND_CCSD BIT(9)
0357 #define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
0358 #define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
0359 #define SDMMC_CTRL_READ_WAIT BIT(6)
0360 #define SDMMC_CTRL_DMA_ENABLE BIT(5)
0361 #define SDMMC_CTRL_INT_ENABLE BIT(4)
0362 #define SDMMC_CTRL_DMA_RESET BIT(2)
0363 #define SDMMC_CTRL_FIFO_RESET BIT(1)
0364 #define SDMMC_CTRL_RESET BIT(0)
0365
0366 #define SDMMC_CLKEN_LOW_PWR BIT(16)
0367 #define SDMMC_CLKEN_ENABLE BIT(0)
0368
0369 #define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
0370 #define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
0371 #define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
0372 #define SDMMC_TMOUT_RESP_MSK 0xFF
0373
0374 #define SDMMC_CTYPE_8BIT BIT(16)
0375 #define SDMMC_CTYPE_4BIT BIT(0)
0376 #define SDMMC_CTYPE_1BIT 0
0377
0378 #define SDMMC_INT_SDIO(n) BIT(16 + (n))
0379 #define SDMMC_INT_EBE BIT(15)
0380 #define SDMMC_INT_ACD BIT(14)
0381 #define SDMMC_INT_SBE BIT(13)
0382 #define SDMMC_INT_HLE BIT(12)
0383 #define SDMMC_INT_FRUN BIT(11)
0384 #define SDMMC_INT_HTO BIT(10)
0385 #define SDMMC_INT_VOLT_SWITCH BIT(10)
0386 #define SDMMC_INT_DRTO BIT(9)
0387 #define SDMMC_INT_RTO BIT(8)
0388 #define SDMMC_INT_DCRC BIT(7)
0389 #define SDMMC_INT_RCRC BIT(6)
0390 #define SDMMC_INT_RXDR BIT(5)
0391 #define SDMMC_INT_TXDR BIT(4)
0392 #define SDMMC_INT_DATA_OVER BIT(3)
0393 #define SDMMC_INT_CMD_DONE BIT(2)
0394 #define SDMMC_INT_RESP_ERR BIT(1)
0395 #define SDMMC_INT_CD BIT(0)
0396 #define SDMMC_INT_ERROR 0xbfc2
0397
0398 #define SDMMC_CMD_START BIT(31)
0399 #define SDMMC_CMD_USE_HOLD_REG BIT(29)
0400 #define SDMMC_CMD_VOLT_SWITCH BIT(28)
0401 #define SDMMC_CMD_CCS_EXP BIT(23)
0402 #define SDMMC_CMD_CEATA_RD BIT(22)
0403 #define SDMMC_CMD_UPD_CLK BIT(21)
0404 #define SDMMC_CMD_INIT BIT(15)
0405 #define SDMMC_CMD_STOP BIT(14)
0406 #define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
0407 #define SDMMC_CMD_SEND_STOP BIT(12)
0408 #define SDMMC_CMD_STRM_MODE BIT(11)
0409 #define SDMMC_CMD_DAT_WR BIT(10)
0410 #define SDMMC_CMD_DAT_EXP BIT(9)
0411 #define SDMMC_CMD_RESP_CRC BIT(8)
0412 #define SDMMC_CMD_RESP_LONG BIT(7)
0413 #define SDMMC_CMD_RESP_EXP BIT(6)
0414 #define SDMMC_CMD_INDX(n) ((n) & 0x1F)
0415
0416 #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
0417 #define SDMMC_STATUS_DMA_REQ BIT(31)
0418 #define SDMMC_STATUS_BUSY BIT(9)
0419
0420 #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
0421 ((r) & 0xFFF) << 16 | \
0422 ((t) & 0xFFF))
0423
0424 #define DMA_INTERFACE_IDMA (0x0)
0425 #define DMA_INTERFACE_DWDMA (0x1)
0426 #define DMA_INTERFACE_GDMA (0x2)
0427 #define DMA_INTERFACE_NODMA (0x3)
0428 #define SDMMC_GET_TRANS_MODE(x) (((x)>>16) & 0x3)
0429 #define SDMMC_GET_SLOT_NUM(x) ((((x)>>1) & 0x1F) + 1)
0430 #define SDMMC_GET_HDATA_WIDTH(x) (((x)>>7) & 0x7)
0431 #define SDMMC_GET_ADDR_CONFIG(x) (((x)>>27) & 0x1)
0432
0433 #define SDMMC_IDMAC_INT_AI BIT(9)
0434 #define SDMMC_IDMAC_INT_NI BIT(8)
0435 #define SDMMC_IDMAC_INT_CES BIT(5)
0436 #define SDMMC_IDMAC_INT_DU BIT(4)
0437 #define SDMMC_IDMAC_INT_FBE BIT(2)
0438 #define SDMMC_IDMAC_INT_RI BIT(1)
0439 #define SDMMC_IDMAC_INT_TI BIT(0)
0440
0441 #define SDMMC_IDMAC_ENABLE BIT(7)
0442 #define SDMMC_IDMAC_FB BIT(1)
0443 #define SDMMC_IDMAC_SWRESET BIT(0)
0444
0445 #define SDMMC_RST_HWACTIVE 0x1
0446
0447 #define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
0448
0449 #define SDMMC_SET_THLD(v, x) (((v) & 0xFFF) << 16 | (x))
0450 #define SDMMC_CARD_WR_THR_EN BIT(2)
0451 #define SDMMC_CARD_RD_THR_EN BIT(0)
0452
0453 #define SDMMC_UHS_DDR BIT(16)
0454 #define SDMMC_UHS_18V BIT(0)
0455
0456 #define SDMMC_DDR_HS400 BIT(31)
0457
0458 #define SDMMC_ENABLE_PHASE BIT(0)
0459
0460 #define SDMMC_CTRL_ALL_RESET_FLAGS \
0461 (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
0462
0463
0464
0465
0466 #define mci_fifo_readw(__reg) __raw_readw(__reg)
0467 #define mci_fifo_readl(__reg) __raw_readl(__reg)
0468 #define mci_fifo_readq(__reg) __raw_readq(__reg)
0469
0470 #define mci_fifo_writew(__value, __reg) __raw_writew(__reg, __value)
0471 #define mci_fifo_writel(__value, __reg) __raw_writel(__reg, __value)
0472 #define mci_fifo_writeq(__value, __reg) __raw_writeq(__reg, __value)
0473
0474
0475 #define mci_readl(dev, reg) \
0476 readl_relaxed((dev)->regs + SDMMC_##reg)
0477 #define mci_writel(dev, reg, value) \
0478 writel_relaxed((value), (dev)->regs + SDMMC_##reg)
0479
0480
0481 #define mci_readw(dev, reg) \
0482 readw_relaxed((dev)->regs + SDMMC_##reg)
0483 #define mci_writew(dev, reg, value) \
0484 writew_relaxed((value), (dev)->regs + SDMMC_##reg)
0485
0486
0487 #ifdef readq
0488 #define mci_readq(dev, reg) \
0489 readq_relaxed((dev)->regs + SDMMC_##reg)
0490 #define mci_writeq(dev, reg, value) \
0491 writeq_relaxed((value), (dev)->regs + SDMMC_##reg)
0492 #else
0493
0494
0495
0496
0497
0498
0499
0500
0501 #define mci_readq(dev, reg) \
0502 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
0503 #define mci_writeq(dev, reg, value) \
0504 (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
0505
0506 #define __raw_writeq(__value, __reg) \
0507 (*(volatile u64 __force *)(__reg) = (__value))
0508 #define __raw_readq(__reg) (*(volatile u64 __force *)(__reg))
0509 #endif
0510
0511 extern int dw_mci_probe(struct dw_mci *host);
0512 extern void dw_mci_remove(struct dw_mci *host);
0513 #ifdef CONFIG_PM
0514 extern int dw_mci_runtime_suspend(struct device *device);
0515 extern int dw_mci_runtime_resume(struct device *device);
0516 #endif
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534 struct dw_mci_slot {
0535 struct mmc_host *mmc;
0536 struct dw_mci *host;
0537
0538 u32 ctype;
0539
0540 struct mmc_request *mrq;
0541 struct list_head queue_node;
0542
0543 unsigned int clock;
0544 unsigned int __clk_old;
0545
0546 unsigned long flags;
0547 #define DW_MMC_CARD_PRESENT 0
0548 #define DW_MMC_CARD_NEED_INIT 1
0549 #define DW_MMC_CARD_NO_LOW_PWR 2
0550 #define DW_MMC_CARD_NO_USE_HOLD 3
0551 #define DW_MMC_CARD_NEEDS_POLL 4
0552 int id;
0553 int sdio_id;
0554 };
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573 struct dw_mci_drv_data {
0574 unsigned long *caps;
0575 u32 num_caps;
0576 u32 common_caps;
0577 int (*init)(struct dw_mci *host);
0578 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
0579 int (*parse_dt)(struct dw_mci *host);
0580 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode);
0581 int (*prepare_hs400_tuning)(struct dw_mci *host,
0582 struct mmc_ios *ios);
0583 int (*switch_voltage)(struct mmc_host *mmc,
0584 struct mmc_ios *ios);
0585 void (*set_data_timeout)(struct dw_mci *host,
0586 unsigned int timeout_ns);
0587 u32 (*get_drto_clks)(struct dw_mci *host);
0588 };
0589 #endif