aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-22 10:38:37 -0500
commitfcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch)
treea57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/mmc
parent8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff)
Added missing tegra files.HEADmaster
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/at91_mci.c1216
-rw-r--r--drivers/mmc/host/at91_mci.h115
-rw-r--r--drivers/mmc/host/imxmmc.c1169
-rw-r--r--drivers/mmc/host/imxmmc.h64
4 files changed, 2564 insertions, 0 deletions
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
new file mode 100644
index 00000000000..a4aa3af86fe
--- /dev/null
+++ b/drivers/mmc/host/at91_mci.c
@@ -0,0 +1,1216 @@
1/*
2 * linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver
3 *
4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
5 *
6 * Copyright (C) 2006 Malcolm Noyes
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 version 2 as
10 * published by the Free Software Foundation.
11 */
12
13/*
14 This is the AT91 MCI driver that has been tested with both MMC cards
15 and SD-cards. Boards that support write protect are now supported.
16 The CCAT91SBC001 board does not support SD cards.
17
18 The three entry points are at91_mci_request, at91_mci_set_ios
19 and at91_mci_get_ro.
20
21 SET IOS
22 This configures the device to put it into the correct mode and clock speed
23 required.
24
25 MCI REQUEST
26 MCI request processes the commands sent in the mmc_request structure. This
27 can consist of a processing command and a stop command in the case of
28 multiple block transfers.
29
30 There are three main types of request, commands, reads and writes.
31
32 Commands are straight forward. The command is submitted to the controller and
33 the request function returns. When the controller generates an interrupt to indicate
34 the command is finished, the response to the command are read and the mmc_request_done
35 function called to end the request.
36
37 Reads and writes work in a similar manner to normal commands but involve the PDC (DMA)
38 controller to manage the transfers.
39
40 A read is done from the controller directly to the scatterlist passed in from the request.
41 Due to a bug in the AT91RM9200 controller, when a read is completed, all the words are byte
42 swapped in the scatterlist buffers. AT91SAM926x are not affected by this bug.
43
44 The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY
45
46 A write is slightly different in that the bytes to write are read from the scatterlist
47 into a dma memory buffer (this is in case the source buffer should be read only). The
48 entire write buffer is then done from this single dma memory buffer.
49
50 The sequence of write interrupts is: ENDTX, TXBUFE, NOTBUSY, CMDRDY
51
52 GET RO
53 Gets the status of the write protect pin, if available.
54*/
55
56#include <linux/module.h>
57#include <linux/moduleparam.h>
58#include <linux/init.h>
59#include <linux/ioport.h>
60#include <linux/platform_device.h>
61#include <linux/interrupt.h>
62#include <linux/blkdev.h>
63#include <linux/delay.h>
64#include <linux/err.h>
65#include <linux/dma-mapping.h>
66#include <linux/clk.h>
67#include <linux/atmel_pdc.h>
68#include <linux/gfp.h>
69#include <linux/highmem.h>
70
71#include <linux/mmc/host.h>
72#include <linux/mmc/sdio.h>
73
74#include <asm/io.h>
75#include <asm/irq.h>
76#include <asm/gpio.h>
77
78#include <mach/board.h>
79#include <mach/cpu.h>
80
81#include "at91_mci.h"
82
83#define DRIVER_NAME "at91_mci"
84
85static inline int at91mci_is_mci1rev2xx(void)
86{
87 return ( cpu_is_at91sam9260()
88 || cpu_is_at91sam9263()
89 || cpu_is_at91cap9()
90 || cpu_is_at91sam9rl()
91 || cpu_is_at91sam9g10()
92 || cpu_is_at91sam9g20()
93 );
94}
95
96#define FL_SENT_COMMAND (1 << 0)
97#define FL_SENT_STOP (1 << 1)
98
99#define AT91_MCI_ERRORS (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE \
100 | AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE \
101 | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)
102
103#define at91_mci_read(host, reg) __raw_readl((host)->baseaddr + (reg))
104#define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg))
105
106#define MCI_BLKSIZE 512
107#define MCI_MAXBLKSIZE 4095
108#define MCI_BLKATONCE 256
109#define MCI_BUFSIZE (MCI_BLKSIZE * MCI_BLKATONCE)
110
111/*
112 * Low level type for this driver
113 */
114struct at91mci_host
115{
116 struct mmc_host *mmc;
117 struct mmc_command *cmd;
118 struct mmc_request *request;
119
120 void __iomem *baseaddr;
121 int irq;
122
123 struct at91_mmc_data *board;
124 int present;
125
126 struct clk *mci_clk;
127
128 /*
129 * Flag indicating when the command has been sent. This is used to
130 * work out whether or not to send the stop
131 */
132 unsigned int flags;
133 /* flag for current bus settings */
134 u32 bus_mode;
135
136 /* DMA buffer used for transmitting */
137 unsigned int* buffer;
138 dma_addr_t physical_address;
139 unsigned int total_length;
140
141 /* Latest in the scatterlist that has been enabled for transfer, but not freed */
142 int in_use_index;
143
144 /* Latest in the scatterlist that has been enabled for transfer */
145 int transfer_index;
146
147 /* Timer for timeouts */
148 struct timer_list timer;
149};
150
151/*
152 * Reset the controller and restore most of the state
153 */
154static void at91_reset_host(struct at91mci_host *host)
155{
156 unsigned long flags;
157 u32 mr;
158 u32 sdcr;
159 u32 dtor;
160 u32 imr;
161
162 local_irq_save(flags);
163 imr = at91_mci_read(host, AT91_MCI_IMR);
164
165 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
166
167 /* save current state */
168 mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
169 sdcr = at91_mci_read(host, AT91_MCI_SDCR);
170 dtor = at91_mci_read(host, AT91_MCI_DTOR);
171
172 /* reset the controller */
173 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
174
175 /* restore state */
176 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
177 at91_mci_write(host, AT91_MCI_MR, mr);
178 at91_mci_write(host, AT91_MCI_SDCR, sdcr);
179 at91_mci_write(host, AT91_MCI_DTOR, dtor);
180 at91_mci_write(host, AT91_MCI_IER, imr);
181
182 /* make sure sdio interrupts will fire */
183 at91_mci_read(host, AT91_MCI_SR);
184
185 local_irq_restore(flags);
186}
187
188static void at91_timeout_timer(unsigned long data)
189{
190 struct at91mci_host *host;
191
192 host = (struct at91mci_host *)data;
193
194 if (host->request) {
195 dev_err(host->mmc->parent, "Timeout waiting end of packet\n");
196
197 if (host->cmd && host->cmd->data) {
198 host->cmd->data->error = -ETIMEDOUT;
199 } else {
200 if (host->cmd)
201 host->cmd->error = -ETIMEDOUT;
202 else
203 host->request->cmd->error = -ETIMEDOUT;
204 }
205
206 at91_reset_host(host);
207 mmc_request_done(host->mmc, host->request);
208 }
209}
210
211/*
212 * Copy from sg to a dma block - used for transfers