blob: c97001e15227aba5b337c5cb07da0a799969d6dd [file] [log] [blame]
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +02001/*
2 * Atmel MultiMedia Card Interface driver
3 *
4 * Copyright (C) 2004-2006 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
Nicolas Ferre19911892009-06-12 17:58:29 +020010
11/*
12 * Superset of MCI IP registers integrated in Atmel AVR32 and AT91 Processors
Nicolas Ferre7f72134c2009-06-12 17:58:30 +020013 * Registers and bitfields marked with [2] are only available in MCI2
Nicolas Ferre19911892009-06-12 17:58:29 +020014 */
15
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +020016#ifndef __DRIVERS_MMC_ATMEL_MCI_H__
17#define __DRIVERS_MMC_ATMEL_MCI_H__
18
19/* MCI Register Definitions */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000020#define ATMCI_CR 0x0000 /* Control */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000021# define ATMCI_CR_MCIEN ( 1 << 0) /* MCI Enable */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000022# define ATMCI_CR_MCIDIS ( 1 << 1) /* MCI Disable */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000023# define ATMCI_CR_PWSEN ( 1 << 2) /* Power Save Enable */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000024# define ATMCI_CR_PWSDIS ( 1 << 3) /* Power Save Disable */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000025# define ATMCI_CR_SWRST ( 1 << 7) /* Software Reset */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000026#define ATMCI_MR 0x0004 /* Mode */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000027# define ATMCI_MR_CLKDIV(x) ((x) << 0) /* Clock Divider */
28# define ATMCI_MR_PWSDIV(x) ((x) << 8) /* Power Saving Divider */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000029# define ATMCI_MR_RDPROOF ( 1 << 11) /* Read Proof */
30# define ATMCI_MR_WRPROOF ( 1 << 12) /* Write Proof */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000031# define ATMCI_MR_PDCFBYTE ( 1 << 13) /* Force Byte Transfer */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000032# define ATMCI_MR_PDCPADV ( 1 << 14) /* Padding Value */
33# define ATMCI_MR_PDCMODE ( 1 << 15) /* PDC-oriented Mode */
Ludovic Desrochesfaf81802012-03-21 16:41:23 +010034# define ATMCI_MR_CLKODD(x) ((x) << 16) /* LSB of Clock Divider */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000035#define ATMCI_DTOR 0x0008 /* Data Timeout */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000036# define ATMCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */
37# define ATMCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000038#define ATMCI_SDCR 0x000c /* SD Card / SDIO */
39# define ATMCI_SDCSEL_SLOT_A ( 0 << 0) /* Select SD slot A */
40# define ATMCI_SDCSEL_SLOT_B ( 1 << 0) /* Select SD slot A */
41# define ATMCI_SDCSEL_MASK ( 3 << 0)
42# define ATMCI_SDCBUS_1BIT ( 0 << 6) /* 1-bit data bus */
43# define ATMCI_SDCBUS_4BIT ( 2 << 6) /* 4-bit data bus */
44# define ATMCI_SDCBUS_8BIT ( 3 << 6) /* 8-bit data bus[2] */
45# define ATMCI_SDCBUS_MASK ( 3 << 6)
46#define ATMCI_ARGR 0x0010 /* Command Argument */
47#define ATMCI_CMDR 0x0014 /* Command */
48# define ATMCI_CMDR_CMDNB(x) ((x) << 0) /* Command Opcode */
49# define ATMCI_CMDR_RSPTYP_NONE ( 0 << 6) /* No response */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000050# define ATMCI_CMDR_RSPTYP_48BIT ( 1 << 6) /* 48-bit response */
51# define ATMCI_CMDR_RSPTYP_136BIT ( 2 << 6) /* 136-bit response */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000052# define ATMCI_CMDR_SPCMD_INIT ( 1 << 8) /* Initialization command */
53# define ATMCI_CMDR_SPCMD_SYNC ( 2 << 8) /* Synchronized command */
54# define ATMCI_CMDR_SPCMD_INT ( 4 << 8) /* Interrupt command */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000055# define ATMCI_CMDR_SPCMD_INTRESP ( 5 << 8) /* Interrupt response */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000056# define ATMCI_CMDR_OPDCMD ( 1 << 11) /* Open Drain */
57# define ATMCI_CMDR_MAXLAT_5CYC ( 0 << 12) /* Max latency 5 cycles */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000058# define ATMCI_CMDR_MAXLAT_64CYC ( 1 << 12) /* Max latency 64 cycles */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000059# define ATMCI_CMDR_START_XFER ( 1 << 16) /* Start data transfer */
60# define ATMCI_CMDR_STOP_XFER ( 2 << 16) /* Stop data transfer */
61# define ATMCI_CMDR_TRDIR_WRITE ( 0 << 18) /* Write data */
62# define ATMCI_CMDR_TRDIR_READ ( 1 << 18) /* Read data */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000063# define ATMCI_CMDR_BLOCK ( 0 << 19) /* Single-block transfer */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000064# define ATMCI_CMDR_MULTI_BLOCK ( 1 << 19) /* Multi-block transfer */
65# define ATMCI_CMDR_STREAM ( 2 << 19) /* MMC Stream transfer */
66# define ATMCI_CMDR_SDIO_BYTE ( 4 << 19) /* SDIO Byte transfer */
67# define ATMCI_CMDR_SDIO_BLOCK ( 5 << 19) /* SDIO Block transfer */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000068# define ATMCI_CMDR_SDIO_SUSPEND ( 1 << 24) /* SDIO Suspend Command */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000069# define ATMCI_CMDR_SDIO_RESUME ( 2 << 24) /* SDIO Resume Command */
70#define ATMCI_BLKR 0x0018 /* Block */
71# define ATMCI_BCNT(x) ((x) << 0) /* Data Block Count */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000072# define ATMCI_BLKLEN(x) ((x) << 16) /* Data Block Length */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000073#define ATMCI_CSTOR 0x001c /* Completion Signal Timeout[2] */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000074# define ATMCI_CSTOCYC(x) ((x) << 0) /* CST cycles */
75# define ATMCI_CSTOMUL(x) ((x) << 4) /* CST multiplier */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000076#define ATMCI_RSPR 0x0020 /* Response 0 */
77#define ATMCI_RSPR1 0x0024 /* Response 1 */
78#define ATMCI_RSPR2 0x0028 /* Response 2 */
79#define ATMCI_RSPR3 0x002c /* Response 3 */
Ludovic Desroches2c96a292011-08-11 15:25:41 +000080#define ATMCI_RDR 0x0030 /* Receive Data */
81#define ATMCI_TDR 0x0034 /* Transmit Data */
82#define ATMCI_SR 0x0040 /* Status */
83#define ATMCI_IER 0x0044 /* Interrupt Enable */
84#define ATMCI_IDR 0x0048 /* Interrupt Disable */
85#define ATMCI_IMR 0x004c /* Interrupt Mask */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000086# define ATMCI_CMDRDY ( 1 << 0) /* Command Ready */
87# define ATMCI_RXRDY ( 1 << 1) /* Receiver Ready */
88# define ATMCI_TXRDY ( 1 << 2) /* Transmitter Ready */
89# define ATMCI_BLKE ( 1 << 3) /* Data Block Ended */
90# define ATMCI_DTIP ( 1 << 4) /* Data Transfer In Progress */
91# define ATMCI_NOTBUSY ( 1 << 5) /* Data Not Busy */
Ludovic Desroches796211b2011-08-11 15:25:44 +000092# define ATMCI_ENDRX ( 1 << 6) /* End of RX Buffer */
93# define ATMCI_ENDTX ( 1 << 7) /* End of TX Buffer */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +000094# define ATMCI_SDIOIRQA ( 1 << 8) /* SDIO IRQ in slot A */
95# define ATMCI_SDIOIRQB ( 1 << 9) /* SDIO IRQ in slot B */
Ludovic Desroches796211b2011-08-11 15:25:44 +000096# define ATMCI_SDIOWAIT ( 1 << 12) /* SDIO Read Wait Operation Status */
97# define ATMCI_CSRCV ( 1 << 13) /* CE-ATA Completion Signal Received */
98# define ATMCI_RXBUFF ( 1 << 14) /* RX Buffer Full */
99# define ATMCI_TXBUFE ( 1 << 15) /* TX Buffer Empty */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000100# define ATMCI_RINDE ( 1 << 16) /* Response Index Error */
101# define ATMCI_RDIRE ( 1 << 17) /* Response Direction Error */
102# define ATMCI_RCRCE ( 1 << 18) /* Response CRC Error */
103# define ATMCI_RENDE ( 1 << 19) /* Response End Bit Error */
104# define ATMCI_RTOE ( 1 << 20) /* Response Time-Out Error */
105# define ATMCI_DCRCE ( 1 << 21) /* Data CRC Error */
106# define ATMCI_DTOE ( 1 << 22) /* Data Time-Out Error */
Ludovic Desroches796211b2011-08-11 15:25:44 +0000107# define ATMCI_CSTOE ( 1 << 23) /* Completion Signal Time-out Error */
108# define ATMCI_BLKOVRE ( 1 << 24) /* DMA Block Overrun Error */
109# define ATMCI_DMADONE ( 1 << 25) /* DMA Transfer Done */
110# define ATMCI_FIFOEMPTY ( 1 << 26) /* FIFO Empty Flag */
111# define ATMCI_XFRDONE ( 1 << 27) /* Transfer Done Flag */
112# define ATMCI_ACKRCV ( 1 << 28) /* Boot Operation Acknowledge Received */
113# define ATMCI_ACKRCVE ( 1 << 29) /* Boot Operation Acknowledge Error */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000114# define ATMCI_OVRE ( 1 << 30) /* RX Overrun Error */
115# define ATMCI_UNRE ( 1 << 31) /* TX Underrun Error */
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000116#define ATMCI_DMA 0x0050 /* DMA Configuration[2] */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000117# define ATMCI_DMA_OFFSET(x) ((x) << 0) /* DMA Write Buffer Offset */
118# define ATMCI_DMA_CHKSIZE(x) ((x) << 4) /* DMA Channel Read and Write Chunk Size */
119# define ATMCI_DMAEN ( 1 << 8) /* DMA Hardware Handshaking Enable */
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000120#define ATMCI_CFG 0x0054 /* Configuration[2] */
121# define ATMCI_CFG_FIFOMODE_1DATA ( 1 << 0) /* MCI Internal FIFO control mode */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000122# define ATMCI_CFG_FERRCTRL_COR ( 1 << 4) /* Flow Error flag reset control mode */
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000123# define ATMCI_CFG_HSMODE ( 1 << 8) /* High Speed Mode */
124# define ATMCI_CFG_LSYNC ( 1 << 12) /* Synchronize on the last block */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000125#define ATMCI_WPMR 0x00e4 /* Write Protection Mode[2] */
126# define ATMCI_WP_EN ( 1 << 0) /* WP Enable */
127# define ATMCI_WP_KEY (0x4d4349 << 8) /* WP Key */
128#define ATMCI_WPSR 0x00e8 /* Write Protection Status[2] */
129# define ATMCI_GET_WP_VS(x) ((x) & 0x0f)
130# define ATMCI_GET_WP_VSRC(x) (((x) >> 8) & 0xffff)
Ludovic Desroches796211b2011-08-11 15:25:44 +0000131#define ATMCI_VERSION 0x00FC /* Version */
Ludovic Desrochesb9867f32011-08-11 15:25:43 +0000132#define ATMCI_FIFO_APERTURE 0x0200 /* FIFO Aperture[2] */
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200133
Nicolas Ferre7f72134c2009-06-12 17:58:30 +0200134/* This is not including the FIFO Aperture on MCI2 */
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000135#define ATMCI_REGS_SIZE 0x100
Haavard Skinnemoendeec9ae2008-07-24 14:18:59 +0200136
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200137/* Register access macros */
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000138#define atmci_readl(port,reg) \
Ludovic Desroches03fc9a72011-08-11 15:25:42 +0000139 __raw_readl((port)->regs + reg)
Ludovic Desroches2c96a292011-08-11 15:25:41 +0000140#define atmci_writel(port,reg,value) \
Ludovic Desroches03fc9a72011-08-11 15:25:42 +0000141 __raw_writel((value), (port)->regs + reg)
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200142
Hein_Tibosch6bf2af82012-08-30 16:34:27 +0000143/* On AVR chips the Peripheral DMA Controller is not connected to MCI. */
144#ifdef CONFIG_AVR32
145# define ATMCI_PDC_CONNECTED 0
146#else
147# define ATMCI_PDC_CONNECTED 1
148#endif
149
Nicolas Ferre693e5e22012-06-06 12:19:44 +0200150/*
151 * Fix sconfig's burst size according to atmel MCI. We need to convert them as:
152 * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
153 *
154 * This can be done by finding most significant bit set.
155 */
156static inline unsigned int atmci_convert_chksize(unsigned int maxburst)
157{
158 if (maxburst > 1)
159 return fls(maxburst) - 2;
160 else
161 return 0;
162}
163
Haavard Skinnemoen7d2be072008-06-30 18:35:03 +0200164#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */