| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- #ifndef _SDMMC_H
- #define _SDMMC_H
- #define MMC_FEQ_MIN 400000
- #define MMC_FEQ_MAX 24000000
- #define CARD_UNPLUGED 1
- #define CARD_PLUGED 0
- #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
- SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
- SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
- SDMMC_IDMAC_INT_TI)
- #define DESC_RING_BUF_SZ (128*1024)//PAGE_SIZE
- #define GFP_KERNEL ((gfp_t) 0)
- enum {
- TRANS_MODE_PIO = 0,
- TRANS_MODE_IDMAC,
- TRANS_MODE_EDMAC
- };
- struct dw_mci_dma_slave {
- struct dma_chan *ch;
- enum dma_transfer_direction direction;
- };
- #define SDMMC_CTRL 0x000
- #define SDMMC_PWREN 0x004
- #define SDMMC_CLKDIV 0x008
- #define SDMMC_CLKSRC 0x00c
- #define SDMMC_CLKENA 0x010
- #define SDMMC_TMOUT 0x014
- #define SDMMC_CTYPE 0x018
- #define SDMMC_BLKSIZ 0x01c
- #define SDMMC_BYTCNT 0x020
- #define SDMMC_INTMASK 0x024
- #define SDMMC_CMDARG 0x028
- #define SDMMC_CMD 0x02c
- #define SDMMC_RESP0 0x030
- #define SDMMC_RESP1 0x034
- #define SDMMC_RESP2 0x038
- #define SDMMC_RESP3 0x03c
- #define SDMMC_MINTSTS 0x040
- #define SDMMC_RINTSTS 0x044
- #define SDMMC_STATUS 0x048
- #define SDMMC_FIFOTH 0x04c
- #define SDMMC_CDETECT 0x050
- #define SDMMC_WRTPRT 0x054
- #define SDMMC_GPIO 0x058
- #define SDMMC_TCBCNT 0x05c
- #define SDMMC_TBBCNT 0x060
- #define SDMMC_DEBNCE 0x064
- #define SDMMC_USRID 0x068
- #define SDMMC_VERID 0x06c
- #define SDMMC_HCON 0x070
- #define SDMMC_UHS_REG 0x074
- #define SDMMC_RST_N 0x078
- #define SDMMC_BMOD 0x080
- #define SDMMC_PLDMND 0x084
- #define SDMMC_DBADDR 0x088
- #define SDMMC_IDSTS 0x08c
- #define SDMMC_IDINTEN 0x090
- #define SDMMC_DSCADDR 0x094
- #define SDMMC_BUFADDR 0x098
- #define SDMMC_FIFO 0x200 // 0x100
- #define SDMMC_DATA(x) (x)
- /*
- * Registers to support idmac 64-bit address mode
- */
- #define SDMMC_DBADDRL 0x088
- #define SDMMC_DBADDRU 0x08c
- #define SDMMC_IDSTS64 0x090
- #define SDMMC_IDINTEN64 0x094
- #define SDMMC_DSCADDRL 0x098
- #define SDMMC_DSCADDRU 0x09c
- #define SDMMC_BUFADDRL 0x0A0
- #define SDMMC_BUFADDRU 0x0A4
- #define SDMMC_FIFO_DEPTH 64//32
- /* Control register defines */
- #define SDMMC_CTRL_USE_IDMAC BIT(25)
- #define SDMMC_CTRL_CEATA_INT_EN BIT(11)
- #define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
- #define SDMMC_CTRL_SEND_CCSD BIT(9)
- #define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
- #define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
- #define SDMMC_CTRL_READ_WAIT BIT(6)
- #define SDMMC_CTRL_DMA_ENABLE BIT(5)
- #define SDMMC_CTRL_INT_ENABLE BIT(4)
- #define SDMMC_CTRL_DMA_RESET BIT(2)
- #define SDMMC_CTRL_FIFO_RESET BIT(1)
- #define SDMMC_CTRL_RESET BIT(0)
- /* Clock Enable register defines */
- #define SDMMC_CLKEN_LOW_PWR BIT(16)
- #define SDMMC_CLKEN_ENABLE BIT(0)
- /* time-out register defines */
- #define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
- #define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
- #define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
- #define SDMMC_TMOUT_RESP_MSK 0xFF
- /* card-type register defines */
- #define SDMMC_CTYPE_8BIT BIT(16)
- #define SDMMC_CTYPE_4BIT BIT(0)
- #define SDMMC_CTYPE_1BIT 0
- /* Interrupt status & mask register defines */
- #define SDMMC_INT_SDIO BIT(16)
- #define SDMMC_INT_EBE BIT(15)
- #define SDMMC_INT_ACD BIT(14)
- #define SDMMC_INT_SBE BIT(13)
- #define SDMMC_INT_HLE BIT(12)
- #define SDMMC_INT_FRUN BIT(11)
- #define SDMMC_INT_HTO BIT(10)
- #define SDMMC_INT_VOLT_SWITCH BIT(10) /* overloads bit 10! */
- #define SDMMC_INT_DRTO BIT(9)
- #define SDMMC_INT_RTO BIT(8)
- #define SDMMC_INT_DCRC BIT(7)
- #define SDMMC_INT_RCRC BIT(6)
- #define SDMMC_INT_RXDR BIT(5)
- #define SDMMC_INT_TXDR BIT(4)
- #define SDMMC_INT_DATA_OVER BIT(3)
- #define SDMMC_INT_CMD_DONE BIT(2)
- #define SDMMC_INT_RESP_ERR BIT(1)
- #define SDMMC_INT_CD BIT(0)
- #define SDMMC_INT_ALL (~0)
- #define SDMMC_INT_DATA_ERROR (SDMMC_INT_DCRC | SDMMC_INT_SBE | SDMMC_INT_EBE)
- #define SDMMC_INT_STATUS_DATA (SDMMC_INT_DATA_OVER | SDMMC_INT_DATA_ERROR \
- | SDMMC_INT_TXDR | SDMMC_INT_RXDR)
- /* Common flag combinations */
- #define SDMMC_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \
- SDMMC_INT_HTO | SDMMC_INT_SBE | \
- SDMMC_INT_EBE | SDMMC_INT_HLE)
- #define SDMMC_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
- SDMMC_INT_RESP_ERR | SDMMC_INT_HLE)
- #define SDMMC_ERROR_FLAGS (SDMMC_DATA_ERROR_FLAGS | \
- SDMMC_CMD_ERROR_FLAGS)
- #define SDMMC_INT_ERROR 0xbfc2
- /* Command register defines */
- #define SDMMC_CMD_START BIT(31)
- #define SDMMC_CMD_USE_HOLD_REG BIT(29)
- #define SDMMC_CMD_VOLT_SWITCH BIT(28)
- #define SDMMC_CMD_CCS_EXP BIT(23)
- #define SDMMC_CMD_CEATA_RD BIT(22)
- #define SDMMC_CMD_UPD_CLK BIT(21)
- #define SDMMC_CMD_INIT BIT(15)
- #define SDMMC_CMD_STOP BIT(14)
- #define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
- #define SDMMC_CMD_SEND_STOP BIT(12)
- #define SDMMC_CMD_STRM_MODE BIT(11)
- #define SDMMC_CMD_DAT_WR BIT(10)
- #define SDMMC_CMD_DAT_EXP BIT(9)
- #define SDMMC_CMD_RESP_CRC BIT(8)
- #define SDMMC_CMD_RESP_LONG BIT(7)
- #define SDMMC_CMD_RESP_EXP BIT(6)
- #define SDMMC_CMD_INDX(n) ((n) & 0x1F)
- /* Status register defines */
- #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
- #define SDMMC_STATUS_DMA_REQ BIT(31)
- #define SDMMC_STATUS_BUSY BIT(9)
- /* FIFOTH register defines */
- #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
- ((r) & 0xFFF) << 16 | \
- ((t) & 0xFFF))
- /* HCON register defines */
- #define DMA_INTERFACE_IDMA (0x0)
- #define DMA_INTERFACE_DWDMA (0x1)
- #define DMA_INTERFACE_GDMA (0x2)
- #define DMA_INTERFACE_NODMA (0x3)
- #define SDMMC_GET_TRANS_MODE(x) (((x)>>16) & 0x3)
- #define SDMMC_GET_SLOT_NUM(x) ((((x)>>1) & 0x1F) + 1)
- #define SDMMC_GET_HDATA_WIDTH(x) (((x)>>7) & 0x7)
- #define SDMMC_GET_ADDR_CONFIG(x) (((x)>>27) & 0x1)
- /* Internal DMAC interrupt defines */
- #define SDMMC_IDMAC_INT_AI BIT(9)
- #define SDMMC_IDMAC_INT_NI BIT(8)
- #define SDMMC_IDMAC_INT_CES BIT(5)
- #define SDMMC_IDMAC_INT_DU BIT(4)
- #define SDMMC_IDMAC_INT_FBE BIT(2)
- #define SDMMC_IDMAC_INT_RI BIT(1)
- #define SDMMC_IDMAC_INT_TI BIT(0)
- /* Internal DMAC bus mode bits */
- #define SDMMC_IDMAC_ENABLE BIT(7)
- #define SDMMC_IDMAC_FB BIT(1)
- #define SDMMC_IDMAC_SWRESET BIT(0)
- /* H/W reset */
- #define SDMMC_RST_HWACTIVE 0x1
- /* Version ID register define */
- #define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
- /* Card read threshold */
- #define SDMMC_SET_THLD(v, x) (((v) & 0xFFF) << 16 | (x))
- #define SDMMC_CARD_WR_THR_EN BIT(2)
- #define SDMMC_CARD_RD_THR_EN BIT(0)
- /* UHS-1 register defines */
- #define SDMMC_UHS_18V BIT(0)
- #define IDMAC_DES0_ER BIT(5)
- /* All ctrl reset bits */
- #define SDMMC_CTRL_ALL_RESET_FLAGS \
- (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
- struct mmc_driver
- {
- uint32_t max_desc;
- struct mmcsd_host *host;
- struct mmcsd_req *req;
- struct mmcsd_data *data;
- struct mmcsd_cmd *cmd;
- void* priv;
- };
- struct ark_mmc_obj;
- /* DMA ops for Internal/External DMAC interface */
- struct dw_mci_dma_ops {
- /* DMA Ops */
- int (*init)(struct ark_mmc_obj *mmc_obj);
- int (*start)(struct ark_mmc_obj *mmc_obj, struct mmcsd_data *data);
- void (*stop)(struct ark_mmc_obj *mmc_obj);
- void (*cleanup)(struct ark_mmc_obj *mmc_obj);
- void (*exit)(struct ark_mmc_obj *mmc_obj);
- };
- struct ark_mmc_obj
- {
- uint32_t id;
- uint32_t irq;
- uint32_t base;
- int softreset_id;
- int clk_id;
- int sema_id;
- uint32_t power_pin_gpio;
- uint32_t fifoth_val;
- uint32_t prev_blksz;
- int result;
- int use_dma;
- int using_dma;
- struct dw_mci_dma_ops *dma_ops;
- struct dw_mci_dma_slave *dms;
- struct mmcsd_data *data;
- QueueHandle_t transfer_completion;
- char *tx_dummy_buffer;
- char *rx_dummy_buffer;
- int dummy_buffer_used;
- void (*mmc_reset)(struct ark_mmc_obj *);
- int dma_64bit_address;
- dma_addr_t sg_dma;
- void *sg_cpu;
- };
- int mmc_init(void);
- #endif /* _SDMMC_H */
|