2006-04-02 12:18:51 -06:00
|
|
|
/*
|
2007-07-11 12:04:50 -06:00
|
|
|
* linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver
|
2006-04-02 12:18:51 -06:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Malcolm Noyes
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2006-12-11 04:40:23 -07:00
|
|
|
This is the AT91 MCI driver that has been tested with both MMC cards
|
2006-04-02 12:18:51 -06:00
|
|
|
and SD-cards. Boards that support write protect are now supported.
|
|
|
|
The CCAT91SBC001 board does not support SD cards.
|
|
|
|
|
|
|
|
The three entry points are at91_mci_request, at91_mci_set_ios
|
|
|
|
and at91_mci_get_ro.
|
|
|
|
|
|
|
|
SET IOS
|
|
|
|
This configures the device to put it into the correct mode and clock speed
|
|
|
|
required.
|
|
|
|
|
|
|
|
MCI REQUEST
|
|
|
|
MCI request processes the commands sent in the mmc_request structure. This
|
|
|
|
can consist of a processing command and a stop command in the case of
|
|
|
|
multiple block transfers.
|
|
|
|
|
|
|
|
There are three main types of request, commands, reads and writes.
|
|
|
|
|
|
|
|
Commands are straight forward. The command is submitted to the controller and
|
|
|
|
the request function returns. When the controller generates an interrupt to indicate
|
|
|
|
the command is finished, the response to the command are read and the mmc_request_done
|
|
|
|
function called to end the request.
|
|
|
|
|
|
|
|
Reads and writes work in a similar manner to normal commands but involve the PDC (DMA)
|
|
|
|
controller to manage the transfers.
|
|
|
|
|
|
|
|
A read is done from the controller directly to the scatterlist passed in from the request.
|
2006-12-11 04:40:23 -07:00
|
|
|
Due to a bug in the AT91RM9200 controller, when a read is completed, all the words are byte
|
|
|
|
swapped in the scatterlist buffers. AT91SAM926x are not affected by this bug.
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY
|
|
|
|
|
|
|
|
A write is slightly different in that the bytes to write are read from the scatterlist
|
|
|
|
into a dma memory buffer (this is in case the source buffer should be read only). The
|
|
|
|
entire write buffer is then done from this single dma memory buffer.
|
|
|
|
|
|
|
|
The sequence of write interrupts is: ENDTX, TXBUFE, NOTBUSY, CMDRDY
|
|
|
|
|
|
|
|
GET RO
|
|
|
|
Gets the status of the write protect pin, if available.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/clk.h>
|
2007-02-08 03:31:22 -07:00
|
|
|
#include <linux/atmel_pdc.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/gfp.h>
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
2008-02-04 10:12:48 -07:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
2008-08-05 09:14:15 -06:00
|
|
|
#include <mach/board.h>
|
|
|
|
#include <mach/cpu.h>
|
|
|
|
#include <mach/at91_mci.h>
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
#define DRIVER_NAME "at91_mci"
|
|
|
|
|
2010-03-05 14:43:44 -07:00
|
|
|
static inline int at91mci_is_mci1rev2xx(void)
|
|
|
|
{
|
|
|
|
return ( cpu_is_at91sam9260()
|
|
|
|
|| cpu_is_at91sam9263()
|
|
|
|
|| cpu_is_at91cap9()
|
|
|
|
|| cpu_is_at91sam9rl()
|
|
|
|
|| cpu_is_at91sam9g10()
|
|
|
|
|| cpu_is_at91sam9g20()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
#define FL_SENT_COMMAND (1 << 0)
|
|
|
|
#define FL_SENT_STOP (1 << 1)
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
#define AT91_MCI_ERRORS (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE \
|
|
|
|
| AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE \
|
2007-08-08 04:01:44 -06:00
|
|
|
| AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
#define at91_mci_read(host, reg) __raw_readl((host)->baseaddr + (reg))
|
|
|
|
#define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg))
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:40 -07:00
|
|
|
#define MCI_BLKSIZE 512
|
|
|
|
#define MCI_MAXBLKSIZE 4095
|
|
|
|
#define MCI_BLKATONCE 256
|
|
|
|
#define MCI_BUFSIZE (MCI_BLKSIZE * MCI_BLKATONCE)
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Low level type for this driver
|
|
|
|
*/
|
|
|
|
struct at91mci_host
|
|
|
|
{
|
|
|
|
struct mmc_host *mmc;
|
|
|
|
struct mmc_command *cmd;
|
|
|
|
struct mmc_request *request;
|
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
void __iomem *baseaddr;
|
2006-10-23 06:44:40 -06:00
|
|
|
int irq;
|
2006-10-25 11:42:38 -06:00
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
struct at91_mmc_data *board;
|
|
|
|
int present;
|
|
|
|
|
2006-10-23 06:46:54 -06:00
|
|
|
struct clk *mci_clk;
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Flag indicating when the command has been sent. This is used to
|
|
|
|
* work out whether or not to send the stop
|
|
|
|
*/
|
|
|
|
unsigned int flags;
|
|
|
|
/* flag for current bus settings */
|
|
|
|
u32 bus_mode;
|
|
|
|
|
|
|
|
/* DMA buffer used for transmitting */
|
|
|
|
unsigned int* buffer;
|
|
|
|
dma_addr_t physical_address;
|
|
|
|
unsigned int total_length;
|
|
|
|
|
|
|
|
/* Latest in the scatterlist that has been enabled for transfer, but not freed */
|
|
|
|
int in_use_index;
|
|
|
|
|
|
|
|
/* Latest in the scatterlist that has been enabled for transfer */
|
|
|
|
int transfer_index;
|
2008-05-30 06:06:32 -06:00
|
|
|
|
|
|
|
/* Timer for timeouts */
|
|
|
|
struct timer_list timer;
|
2006-04-02 12:18:51 -06:00
|
|
|
};
|
|
|
|
|
2008-05-30 06:07:47 -06:00
|
|
|
/*
|
|
|
|
* Reset the controller and restore most of the state
|
|
|
|
*/
|
|
|
|
static void at91_reset_host(struct at91mci_host *host)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u32 mr;
|
|
|
|
u32 sdcr;
|
|
|
|
u32 dtor;
|
|
|
|
u32 imr;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
imr = at91_mci_read(host, AT91_MCI_IMR);
|
|
|
|
|
|
|
|
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
|
|
|
|
|
|
|
|
/* save current state */
|
|
|
|
mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
|
|
|
|
sdcr = at91_mci_read(host, AT91_MCI_SDCR);
|
|
|
|
dtor = at91_mci_read(host, AT91_MCI_DTOR);
|
|
|
|
|
|
|
|
/* reset the controller */
|
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
|
|
|
|
|
|
|
|
/* restore state */
|
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
|
|
|
|
at91_mci_write(host, AT91_MCI_MR, mr);
|
|
|
|
at91_mci_write(host, AT91_MCI_SDCR, sdcr);
|
|
|
|
at91_mci_write(host, AT91_MCI_DTOR, dtor);
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, imr);
|
|
|
|
|
|
|
|
/* make sure sdio interrupts will fire */
|
|
|
|
at91_mci_read(host, AT91_MCI_SR);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
}
|
|
|
|
|
2008-05-30 06:06:32 -06:00
|
|
|
static void at91_timeout_timer(unsigned long data)
|
|
|
|
{
|
|
|
|
struct at91mci_host *host;
|
|
|
|
|
|
|
|
host = (struct at91mci_host *)data;
|
|
|
|
|
|
|
|
if (host->request) {
|
|
|
|
dev_err(host->mmc->parent, "Timeout waiting end of packet\n");
|
|
|
|
|
|
|
|
if (host->cmd && host->cmd->data) {
|
|
|
|
host->cmd->data->error = -ETIMEDOUT;
|
|
|
|
} else {
|
|
|
|
if (host->cmd)
|
|
|
|
host->cmd->error = -ETIMEDOUT;
|
|
|
|
else
|
|
|
|
host->request->cmd->error = -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2008-05-30 06:07:47 -06:00
|
|
|
at91_reset_host(host);
|
2008-05-30 06:06:32 -06:00
|
|
|
mmc_request_done(host->mmc, host->request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Copy from sg to a dma block - used for transfers
|
|
|
|
*/
|
2007-06-19 10:32:34 -06:00
|
|
|
static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
unsigned int len, i, size;
|
|
|
|
unsigned *dmabuf = host->buffer;
|
|
|
|
|
2008-06-14 11:27:20 -06:00
|
|
|
size = data->blksz * data->blocks;
|
2006-04-02 12:18:51 -06:00
|
|
|
len = data->sg_len;
|
|
|
|
|
2010-03-05 14:43:44 -07:00
|
|
|
/* MCI1 rev2xx Data Write Operation and number of bytes erratum */
|
|
|
|
if (at91mci_is_mci1rev2xx())
|
2008-06-14 11:27:20 -06:00
|
|
|
if (host->total_length == 12)
|
|
|
|
memset(dmabuf, 0, 12);
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Just loop through all entries. Size might not
|
|
|
|
* be the entire list though so make sure that
|
|
|
|
* we do not transfer too much.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
struct scatterlist *sg;
|
|
|
|
int amount;
|
|
|
|
unsigned int *sgbuffer;
|
|
|
|
|
|
|
|
sg = &data->sg[i];
|
|
|
|
|
2007-10-22 13:19:53 -06:00
|
|
|
sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
|
2006-04-02 12:18:51 -06:00
|
|
|
amount = min(size, sg->length);
|
|
|
|
size -= amount;
|
|
|
|
|
2006-12-11 04:40:23 -07:00
|
|
|
if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for (index = 0; index < (amount / 4); index++)
|
|
|
|
*dmabuf++ = swab32(sgbuffer[index]);
|
2008-06-14 11:27:20 -06:00
|
|
|
} else {
|
2010-03-05 14:43:38 -07:00
|
|
|
char *tmpv = (char *)dmabuf;
|
|
|
|
memcpy(tmpv, sgbuffer, amount);
|
|
|
|
tmpv += amount;
|
|
|
|
dmabuf = (unsigned *)tmpv;
|
2008-06-14 11:27:20 -06:00
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:45 -07:00
|
|
|
kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (size == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that we didn't get a request to transfer
|
|
|
|
* more data than can fit into the SG list.
|
|
|
|
*/
|
|
|
|
BUG_ON(size != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle after a dma read
|
|
|
|
*/
|
2007-06-19 10:32:34 -06:00
|
|
|
static void at91_mci_post_dma_read(struct at91mci_host *host)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct mmc_command *cmd;
|
|
|
|
struct mmc_data *data;
|
2010-03-05 14:43:41 -07:00
|
|
|
unsigned int len, i, size;
|
|
|
|
unsigned *dmabuf = host->buffer;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("post dma read\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
cmd = host->cmd;
|
|
|
|
if (!cmd) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("no command\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = cmd->data;
|
|
|
|
if (!data) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("no data\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
size = data->blksz * data->blocks;
|
|
|
|
len = data->sg_len;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX);
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
struct scatterlist *sg;
|
|
|
|
int amount;
|
|
|
|
unsigned int *sgbuffer;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
sg = &data->sg[i];
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
|
|
|
|
amount = min(size, sg->length);
|
|
|
|
size -= amount;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-12-11 04:40:23 -07:00
|
|
|
if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
|
|
|
|
int index;
|
2010-03-05 14:43:41 -07:00
|
|
|
for (index = 0; index < (amount / 4); index++)
|
|
|
|
sgbuffer[index] = swab32(*dmabuf++);
|
|
|
|
} else {
|
|
|
|
char *tmpv = (char *)dmabuf;
|
|
|
|
memcpy(sgbuffer, tmpv, amount);
|
|
|
|
tmpv += amount;
|
|
|
|
dmabuf = (unsigned *)tmpv;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
2006-12-11 04:40:23 -07:00
|
|
|
|
2010-05-15 10:32:31 -06:00
|
|
|
flush_kernel_dcache_page(sg_page(sg));
|
2010-03-05 14:43:45 -07:00
|
|
|
kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
|
2010-03-05 14:43:41 -07:00
|
|
|
data->bytes_xfered += amount;
|
|
|
|
if (size == 0)
|
|
|
|
break;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("post dma read done\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle transmitted data
|
|
|
|
*/
|
|
|
|
static void at91_mci_handle_transmitted(struct at91mci_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_command *cmd;
|
|
|
|
struct mmc_data *data;
|
|
|
|
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Handling the transmit\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
/* Disable the transfer */
|
2007-02-08 03:31:22 -07:00
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
/* Now wait for cmd ready */
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
cmd = host->cmd;
|
|
|
|
if (!cmd) return;
|
|
|
|
|
|
|
|
data = cmd->data;
|
|
|
|
if (!data) return;
|
|
|
|
|
2007-07-24 13:11:47 -06:00
|
|
|
if (cmd->data->blocks > 1) {
|
2007-07-09 06:58:16 -06:00
|
|
|
pr_debug("multiple write : wait for BLKE...\n");
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
|
|
|
|
} else
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
|
2008-05-30 06:18:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update bytes tranfered count during a write operation
|
|
|
|
*/
|
|
|
|
static void at91_mci_update_bytes_xfered(struct at91mci_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_data *data;
|
2007-07-09 06:58:16 -06:00
|
|
|
|
2008-05-30 06:18:57 -06:00
|
|
|
/* always deal with the effective request (and not the current cmd) */
|
|
|
|
|
|
|
|
if (host->request->cmd && host->request->cmd->error != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (host->request->data) {
|
|
|
|
data = host->request->data;
|
|
|
|
if (data->flags & MMC_DATA_WRITE) {
|
|
|
|
/* card is in IDLE mode now */
|
|
|
|
pr_debug("-> bytes_xfered %d, total_length = %d\n",
|
|
|
|
data->bytes_xfered, host->total_length);
|
2008-06-14 11:27:20 -06:00
|
|
|
data->bytes_xfered = data->blksz * data->blocks;
|
2008-05-30 06:18:57 -06:00
|
|
|
}
|
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2008-05-30 06:18:57 -06:00
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
/*Handle after command sent ready*/
|
|
|
|
static int at91_mci_handle_cmdrdy(struct at91mci_host *host)
|
|
|
|
{
|
|
|
|
if (!host->cmd)
|
|
|
|
return 1;
|
|
|
|
else if (!host->cmd->data) {
|
|
|
|
if (host->flags & FL_SENT_STOP) {
|
|
|
|
/*After multi block write, we must wait for NOTBUSY*/
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
|
|
|
|
} else return 1;
|
|
|
|
} else if (host->cmd->data->flags & MMC_DATA_WRITE) {
|
|
|
|
/*After sendding multi-block-write command, start DMA transfer*/
|
2008-05-30 06:18:57 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE | AT91_MCI_BLKE);
|
2007-07-09 06:58:16 -06:00
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* command not completed, have to wait */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Enable the controller
|
|
|
|
*/
|
2006-10-25 11:42:38 -06:00
|
|
|
static void at91_mci_enable(struct at91mci_host *host)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
2007-07-09 06:58:16 -06:00
|
|
|
unsigned int mr;
|
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
|
2006-10-23 06:53:20 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
|
2007-07-09 06:58:16 -06:00
|
|
|
mr = AT91_MCI_PDCMODE | 0x34a;
|
|
|
|
|
2010-03-05 14:43:44 -07:00
|
|
|
if (at91mci_is_mci1rev2xx())
|
2007-07-09 06:58:16 -06:00
|
|
|
mr |= AT91_MCI_RDPROOF | AT91_MCI_WRPROOF;
|
|
|
|
|
|
|
|
at91_mci_write(host, AT91_MCI_MR, mr);
|
2006-12-11 04:40:23 -07:00
|
|
|
|
|
|
|
/* use Slot A or B (only one at same time) */
|
|
|
|
at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the controller
|
|
|
|
*/
|
2006-10-25 11:42:38 -06:00
|
|
|
static void at91_mci_disable(struct at91mci_host *host)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command
|
|
|
|
*/
|
2007-07-09 06:58:16 -06:00
|
|
|
static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
unsigned int cmdr, mr;
|
|
|
|
unsigned int block_length;
|
|
|
|
struct mmc_data *data = cmd->data;
|
|
|
|
|
|
|
|
unsigned int blocks;
|
|
|
|
unsigned int ier = 0;
|
|
|
|
|
|
|
|
host->cmd = cmd;
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
/* Needed for leaving busy state before CMD1 */
|
2006-10-25 11:42:38 -06:00
|
|
|
if ((at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Clearing timeout\n");
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_ARGR, 0);
|
|
|
|
at91_mci_write(host, AT91_MCI_CMDR, AT91_MCI_OPDCMD);
|
|
|
|
while (!(at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_CMDRDY)) {
|
2006-04-02 12:18:51 -06:00
|
|
|
/* spin */
|
2006-10-25 11:42:38 -06:00
|
|
|
pr_debug("Clearing: SR = %08X\n", at91_mci_read(host, AT91_MCI_SR));
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
}
|
2007-07-09 06:58:16 -06:00
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
cmdr = cmd->opcode;
|
|
|
|
|
|
|
|
if (mmc_resp_type(cmd) == MMC_RSP_NONE)
|
|
|
|
cmdr |= AT91_MCI_RSPTYP_NONE;
|
|
|
|
else {
|
|
|
|
/* if a response is expected then allow maximum response latancy */
|
|
|
|
cmdr |= AT91_MCI_MAXLAT;
|
|
|
|
/* set 136 bit response for R2, 48 bit response otherwise */
|
|
|
|
if (mmc_resp_type(cmd) == MMC_RSP_R2)
|
|
|
|
cmdr |= AT91_MCI_RSPTYP_136;
|
|
|
|
else
|
|
|
|
cmdr |= AT91_MCI_RSPTYP_48;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
2007-08-09 05:56:29 -06:00
|
|
|
|
2008-06-09 13:06:44 -06:00
|
|
|
if (cpu_is_at91rm9200() || cpu_is_at91sam9261()) {
|
|
|
|
if (data->blksz & 0x3) {
|
|
|
|
pr_debug("Unsupported block size\n");
|
|
|
|
cmd->error = -EINVAL;
|
|
|
|
mmc_request_done(host->mmc, host->request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data->flags & MMC_DATA_STREAM) {
|
|
|
|
pr_debug("Stream commands not supported\n");
|
|
|
|
cmd->error = -EINVAL;
|
|
|
|
mmc_request_done(host->mmc, host->request);
|
|
|
|
return;
|
|
|
|
}
|
2007-08-09 05:56:29 -06:00
|
|
|
}
|
|
|
|
|
2006-06-04 10:51:15 -06:00
|
|
|
block_length = data->blksz;
|
2006-04-02 12:18:51 -06:00
|
|
|
blocks = data->blocks;
|
|
|
|
|
|
|
|
/* always set data start - also set direction flag for read */
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
cmdr |= (AT91_MCI_TRDIR | AT91_MCI_TRCMD_START);
|
|
|
|
else if (data->flags & MMC_DATA_WRITE)
|
|
|
|
cmdr |= AT91_MCI_TRCMD_START;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_STREAM)
|
|
|
|
cmdr |= AT91_MCI_TRTYP_STREAM;
|
2007-07-24 13:11:47 -06:00
|
|
|
if (data->blocks > 1)
|
2006-04-02 12:18:51 -06:00
|
|
|
cmdr |= AT91_MCI_TRTYP_MULTIPLE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
block_length = 0;
|
|
|
|
blocks = 0;
|
|
|
|
}
|
|
|
|
|
2007-06-06 12:27:59 -06:00
|
|
|
if (host->flags & FL_SENT_STOP)
|
2006-04-02 12:18:51 -06:00
|
|
|
cmdr |= AT91_MCI_TRCMD_STOP;
|
|
|
|
|
|
|
|
if (host->bus_mode == MMC_BUSMODE_OPENDRAIN)
|
|
|
|
cmdr |= AT91_MCI_OPDCMD;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the arguments and send the command
|
|
|
|
*/
|
2006-10-23 06:53:20 -06:00
|
|
|
pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08X)\n",
|
2006-10-25 11:42:38 -06:00
|
|
|
cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR));
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (!data) {
|
2007-02-08 03:31:22 -07:00
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS | ATMEL_PDC_RXTDIS);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RPR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RCR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RNPR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RNCR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_TPR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_TCR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_TNPR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_TNCR, 0);
|
2007-07-09 06:58:16 -06:00
|
|
|
ier = AT91_MCI_CMDRDY;
|
|
|
|
} else {
|
|
|
|
/* zero block length and PDC mode */
|
2008-06-09 13:06:45 -06:00
|
|
|
mr = at91_mci_read(host, AT91_MCI_MR) & 0x5fff;
|
2008-05-30 06:05:24 -06:00
|
|
|
mr |= (data->blksz & 0x3) ? AT91_MCI_PDCFBYTE : 0;
|
|
|
|
mr |= (block_length << 16);
|
|
|
|
mr |= AT91_MCI_PDCMODE;
|
|
|
|
at91_mci_write(host, AT91_MCI_MR, mr);
|
2006-10-25 11:42:38 -06:00
|
|
|
|
2008-06-09 13:06:44 -06:00
|
|
|
if (!(cpu_is_at91rm9200() || cpu_is_at91sam9261()))
|
2008-05-30 06:07:47 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_BLKR,
|
|
|
|
AT91_MCI_BLKR_BCNT(blocks) |
|
|
|
|
AT91_MCI_BLKR_BLKLEN(block_length));
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
/*
|
|
|
|
* Disable the PDC controller
|
|
|
|
*/
|
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
if (cmdr & AT91_MCI_TRCMD_START) {
|
|
|
|
data->bytes_xfered = 0;
|
|
|
|
host->transfer_index = 0;
|
|
|
|
host->in_use_index = 0;
|
|
|
|
if (cmdr & AT91_MCI_TRDIR) {
|
|
|
|
/*
|
|
|
|
* Handle a read
|
|
|
|
*/
|
|
|
|
host->total_length = 0;
|
|
|
|
|
2010-03-05 14:43:41 -07:00
|
|
|
at91_mci_write(host, ATMEL_PDC_RPR, host->physical_address);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RCR, (data->blksz & 0x3) ?
|
|
|
|
(blocks * block_length) : (blocks * block_length) / 4);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RNPR, 0);
|
|
|
|
at91_mci_write(host, ATMEL_PDC_RNCR, 0);
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Handle a write
|
|
|
|
*/
|
|
|
|
host->total_length = block_length * blocks;
|
2008-06-14 11:27:20 -06:00
|
|
|
/*
|
2010-03-05 14:43:44 -07:00
|
|
|
* MCI1 rev2xx Data Write Operation and
|
2008-06-14 11:27:20 -06:00
|
|
|
* number of bytes erratum
|
|
|
|
*/
|
2010-03-05 14:43:44 -07:00
|
|
|
if (at91mci_is_mci1rev2xx())
|
2008-06-14 11:27:20 -06:00
|
|
|
if (host->total_length < 12)
|
|
|
|
host->total_length = 12;
|
2008-09-02 15:35:46 -06:00
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
at91_mci_sg_to_dma(host, data);
|
|
|
|
|
|
|
|
pr_debug("Transmitting %d bytes\n", host->total_length);
|
|
|
|
|
|
|
|
at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
|
2008-05-30 06:05:24 -06:00
|
|
|
at91_mci_write(host, ATMEL_PDC_TCR, (data->blksz & 0x3) ?
|
|
|
|
host->total_length : host->total_length / 4);
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
ier = AT91_MCI_CMDRDY;
|
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the command and then enable the PDC - not the other way round as
|
|
|
|
* the data sheet says
|
|
|
|
*/
|
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
|
|
|
|
at91_mci_write(host, AT91_MCI_CMDR, cmdr);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (cmdr & AT91_MCI_TRCMD_START) {
|
|
|
|
if (cmdr & AT91_MCI_TRDIR)
|
2007-02-08 03:31:22 -07:00
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
/* Enable selected interrupts */
|
2006-10-23 06:50:09 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the next step in the request
|
|
|
|
*/
|
2007-06-19 10:32:34 -06:00
|
|
|
static void at91_mci_process_next(struct at91mci_host *host)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
if (!(host->flags & FL_SENT_COMMAND)) {
|
|
|
|
host->flags |= FL_SENT_COMMAND;
|
2007-07-09 06:58:16 -06:00
|
|
|
at91_mci_send_command(host, host->request->cmd);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) {
|
|
|
|
host->flags |= FL_SENT_STOP;
|
2007-07-09 06:58:16 -06:00
|
|
|
at91_mci_send_command(host, host->request->stop);
|
2008-05-30 06:06:32 -06:00
|
|
|
} else {
|
|
|
|
del_timer(&host->timer);
|
2008-05-30 06:07:47 -06:00
|
|
|
/* the at91rm9200 mci controller hangs after some transfers,
|
|
|
|
* and the workaround is to reset it after each transfer.
|
|
|
|
*/
|
|
|
|
if (cpu_is_at91rm9200())
|
|
|
|
at91_reset_host(host);
|
2006-04-02 12:18:51 -06:00
|
|
|
mmc_request_done(host->mmc, host->request);
|
2008-05-30 06:06:32 -06:00
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a command that has been completed
|
|
|
|
*/
|
2008-05-30 06:28:45 -06:00
|
|
|
static void at91_mci_completed_command(struct at91mci_host *host, unsigned int status)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct mmc_command *cmd = host->cmd;
|
2008-06-10 03:27:29 -06:00
|
|
|
struct mmc_data *data = cmd->data;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2008-05-30 06:26:05 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB));
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
cmd->resp[0] = at91_mci_read(host, AT91_MCI_RSPR(0));
|
|
|
|
cmd->resp[1] = at91_mci_read(host, AT91_MCI_RSPR(1));
|
|
|
|
cmd->resp[2] = at91_mci_read(host, AT91_MCI_RSPR(2));
|
|
|
|
cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3));
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2008-05-30 06:28:45 -06:00
|
|
|
pr_debug("Status = %08X/%08x [%08X %08X %08X %08X]\n",
|
|
|
|
status, at91_mci_read(host, AT91_MCI_SR),
|
|
|
|
cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2007-10-17 03:53:40 -06:00
|
|
|
if (status & AT91_MCI_ERRORS) {
|
2007-06-06 12:27:59 -06:00
|
|
|
if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) {
|
2007-07-22 14:18:46 -06:00
|
|
|
cmd->error = 0;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
else {
|
2008-06-10 03:27:29 -06:00
|
|
|
if (status & (AT91_MCI_DTOE | AT91_MCI_DCRCE)) {
|
|
|
|
if (data) {
|
|
|
|
if (status & AT91_MCI_DTOE)
|
|
|
|
data->error = -ETIMEDOUT;
|
|
|
|
else if (status & AT91_MCI_DCRCE)
|
|
|
|
data->error = -EILSEQ;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (status & AT91_MCI_RTOE)
|
|
|
|
cmd->error = -ETIMEDOUT;
|
|
|
|
else if (status & AT91_MCI_RCRCE)
|
|
|
|
cmd->error = -EILSEQ;
|
|
|
|
else
|
|
|
|
cmd->error = -EIO;
|
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2008-06-10 03:27:29 -06:00
|
|
|
pr_debug("Error detected and set to %d/%d (cmd = %d, retries = %d)\n",
|
|
|
|
cmd->error, data ? data->error : 0,
|
|
|
|
cmd->opcode, cmd->retries);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-07-22 14:18:46 -06:00
|
|
|
cmd->error = 0;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2007-06-19 10:32:34 -06:00
|
|
|
at91_mci_process_next(host);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an MMC request
|
|
|
|
*/
|
|
|
|
static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
|
|
|
host->request = mrq;
|
|
|
|
host->flags = 0;
|
|
|
|
|
2010-03-05 14:43:39 -07:00
|
|
|
/* more than 1s timeout needed with slow SD cards */
|
|
|
|
mod_timer(&host->timer, jiffies + msecs_to_jiffies(2000));
|
2008-05-30 06:06:32 -06:00
|
|
|
|
2007-06-19 10:32:34 -06:00
|
|
|
at91_mci_process_next(host);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the IOS
|
|
|
|
*/
|
|
|
|
static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
|
|
{
|
|
|
|
int clkdiv;
|
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
2006-10-23 06:46:54 -06:00
|
|
|
unsigned long at91_master_clock = clk_get_rate(host->mci_clk);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-06-19 06:06:05 -06:00
|
|
|
host->bus_mode = ios->bus_mode;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (ios->clock == 0) {
|
|
|
|
/* Disable the MCI controller */
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS);
|
2006-04-02 12:18:51 -06:00
|
|
|
clkdiv = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Enable the MCI controller */
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if ((at91_master_clock % (ios->clock * 2)) == 0)
|
|
|
|
clkdiv = ((at91_master_clock / ios->clock) / 2) - 1;
|
|
|
|
else
|
|
|
|
clkdiv = (at91_master_clock / ios->clock) / 2;
|
|
|
|
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("clkdiv = %d. mcck = %ld\n", clkdiv,
|
2006-04-02 12:18:51 -06:00
|
|
|
at91_master_clock / (2 * (clkdiv + 1)));
|
|
|
|
}
|
|
|
|
if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("MMC: Setting controller bus width to 4\n");
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) | AT91_MCI_SDCBUS);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("MMC: Setting controller bus width to 1\n");
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the clock divider */
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_MR, (at91_mci_read(host, AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
/* maybe switch power to the card */
|
2006-06-19 06:06:05 -06:00
|
|
|
if (host->board->vcc_pin) {
|
2006-04-02 12:18:51 -06:00
|
|
|
switch (ios->power_mode) {
|
|
|
|
case MMC_POWER_OFF:
|
2008-02-04 10:12:48 -07:00
|
|
|
gpio_set_value(host->board->vcc_pin, 0);
|
2006-04-02 12:18:51 -06:00
|
|
|
break;
|
|
|
|
case MMC_POWER_UP:
|
2008-02-04 10:12:48 -07:00
|
|
|
gpio_set_value(host->board->vcc_pin, 1);
|
2006-04-02 12:18:51 -06:00
|
|
|
break;
|
2008-05-09 03:07:07 -06:00
|
|
|
case MMC_POWER_ON:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN_ON(1);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an interrupt
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static irqreturn_t at91_mci_irq(int irq, void *devid)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct at91mci_host *host = devid;
|
|
|
|
int completed = 0;
|
2006-10-23 06:50:09 -06:00
|
|
|
unsigned int int_status, int_mask;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
int_status = at91_mci_read(host, AT91_MCI_SR);
|
2006-10-23 06:50:09 -06:00
|
|
|
int_mask = at91_mci_read(host, AT91_MCI_IMR);
|
2007-08-08 04:01:44 -06:00
|
|
|
|
2006-10-23 06:53:20 -06:00
|
|
|
pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask,
|
2006-10-23 06:50:09 -06:00
|
|
|
int_status & int_mask);
|
2007-08-08 04:01:44 -06:00
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
int_status = int_status & int_mask;
|
|
|
|
|
|
|
|
if (int_status & AT91_MCI_ERRORS) {
|
2006-04-02 12:18:51 -06:00
|
|
|
completed = 1;
|
2007-08-08 04:01:44 -06:00
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
if (int_status & AT91_MCI_UNRE)
|
|
|
|
pr_debug("MMC: Underrun error\n");
|
|
|
|
if (int_status & AT91_MCI_OVRE)
|
|
|
|
pr_debug("MMC: Overrun error\n");
|
|
|
|
if (int_status & AT91_MCI_DTOE)
|
|
|
|
pr_debug("MMC: Data timeout\n");
|
|
|
|
if (int_status & AT91_MCI_DCRCE)
|
|
|
|
pr_debug("MMC: CRC error in data\n");
|
|
|
|
if (int_status & AT91_MCI_RTOE)
|
|
|
|
pr_debug("MMC: Response timeout\n");
|
|
|
|
if (int_status & AT91_MCI_RENDE)
|
|
|
|
pr_debug("MMC: Response end bit error\n");
|
|
|
|
if (int_status & AT91_MCI_RCRCE)
|
|
|
|
pr_debug("MMC: Response CRC error\n");
|
|
|
|
if (int_status & AT91_MCI_RDIRE)
|
|
|
|
pr_debug("MMC: Response direction error\n");
|
|
|
|
if (int_status & AT91_MCI_RINDE)
|
|
|
|
pr_debug("MMC: Response index error\n");
|
|
|
|
} else {
|
|
|
|
/* Only continue processing if no errors */
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (int_status & AT91_MCI_TXBUFE) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("TX buffer empty\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
at91_mci_handle_transmitted(host);
|
|
|
|
}
|
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
if (int_status & AT91_MCI_ENDRX) {
|
|
|
|
pr_debug("ENDRX\n");
|
|
|
|
at91_mci_post_dma_read(host);
|
|
|
|
}
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
if (int_status & AT91_MCI_RXBUFF) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("RX buffer full\n");
|
2007-07-09 06:58:16 -06:00
|
|
|
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
|
|
|
|
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_RXBUFF | AT91_MCI_ENDRX);
|
|
|
|
completed = 1;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
if (int_status & AT91_MCI_ENDTX)
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Transmit has ended\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (int_status & AT91_MCI_NOTBUSY) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Card is ready\n");
|
2008-05-30 06:18:57 -06:00
|
|
|
at91_mci_update_bytes_xfered(host);
|
2007-07-09 06:58:16 -06:00
|
|
|
completed = 1;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
if (int_status & AT91_MCI_DTIP)
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Data transfer in progress\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2007-07-09 06:58:16 -06:00
|
|
|
if (int_status & AT91_MCI_BLKE) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Block transfer has ended\n");
|
2008-05-30 06:18:57 -06:00
|
|
|
if (host->request->data && host->request->data->blocks > 1) {
|
|
|
|
/* multi block write : complete multi write
|
|
|
|
* command and send stop */
|
|
|
|
completed = 1;
|
|
|
|
} else {
|
|
|
|
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
|
|
|
|
}
|
2007-07-09 06:58:16 -06:00
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2008-05-30 06:26:05 -06:00
|
|
|
if (int_status & AT91_MCI_SDIOIRQA)
|
|
|
|
mmc_signal_sdio_irq(host->mmc);
|
|
|
|
|
|
|
|
if (int_status & AT91_MCI_SDIOIRQB)
|
|
|
|
mmc_signal_sdio_irq(host->mmc);
|
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
if (int_status & AT91_MCI_TXRDY)
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Ready to transmit\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-23 06:50:09 -06:00
|
|
|
if (int_status & AT91_MCI_RXRDY)
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Ready to receive\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (int_status & AT91_MCI_CMDRDY) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Command ready\n");
|
2007-07-09 06:58:16 -06:00
|
|
|
completed = at91_mci_handle_cmdrdy(host);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (completed) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("Completed command\n");
|
2008-05-30 06:26:05 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB));
|
2008-05-30 06:28:45 -06:00
|
|
|
at91_mci_completed_command(host, int_status);
|
2006-10-23 06:50:09 -06:00
|
|
|
} else
|
2008-05-30 06:26:05 -06:00
|
|
|
at91_mci_write(host, AT91_MCI_IDR, int_status & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB));
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 07:55:46 -06:00
|
|
|
static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct at91mci_host *host = _host;
|
2008-02-04 10:12:48 -07:00
|
|
|
int present = !gpio_get_value(irq_to_gpio(irq));
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we expect this irq on both insert and remove,
|
|
|
|
* and use a short delay to debounce.
|
|
|
|
*/
|
|
|
|
if (present != host->present) {
|
|
|
|
host->present = present;
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("%s: card %s\n", mmc_hostname(host->mmc),
|
2006-04-02 12:18:51 -06:00
|
|
|
present ? "insert" : "remove");
|
|
|
|
if (!present) {
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("****** Resetting SD-card bus width ******\n");
|
2006-12-11 04:40:23 -07:00
|
|
|
at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
2010-03-05 14:43:39 -07:00
|
|
|
/* 0.5s needed because of early card detect switch firing */
|
|
|
|
mmc_detect_change(host->mmc, msecs_to_jiffies(500));
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2006-12-26 15:45:26 -07:00
|
|
|
static int at91_mci_get_ro(struct mmc_host *mmc)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
|
|
|
|
2008-06-17 08:17:39 -06:00
|
|
|
if (host->board->wp_pin)
|
|
|
|
return !!gpio_get_value(host->board->wp_pin);
|
|
|
|
/*
|
|
|
|
* Board doesn't support read only detection; let the mmc core
|
|
|
|
* decide what to do.
|
|
|
|
*/
|
|
|
|
return -ENOSYS;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2008-05-30 06:26:05 -06:00
|
|
|
static void at91_mci_enable_sdio_irq(struct mmc_host *mmc, int enable)
|
|
|
|
{
|
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
|
|
|
|
|
|
|
pr_debug("%s: sdio_irq %c : %s\n", mmc_hostname(host->mmc),
|
|
|
|
host->board->slot_b ? 'B':'A', enable ? "enable" : "disable");
|
|
|
|
at91_mci_write(host, enable ? AT91_MCI_IER : AT91_MCI_IDR,
|
|
|
|
host->board->slot_b ? AT91_MCI_SDIOIRQB : AT91_MCI_SDIOIRQA);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-11-12 18:55:30 -07:00
|
|
|
static const struct mmc_host_ops at91_mci_ops = {
|
2006-04-02 12:18:51 -06:00
|
|
|
.request = at91_mci_request,
|
|
|
|
.set_ios = at91_mci_set_ios,
|
|
|
|
.get_ro = at91_mci_get_ro,
|
2008-05-30 06:26:05 -06:00
|
|
|
.enable_sdio_irq = at91_mci_enable_sdio_irq,
|
2006-04-02 12:18:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for the device
|
|
|
|
*/
|
2006-12-26 15:45:26 -07:00
|
|
|
static int __init at91_mci_probe(struct platform_device *pdev)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct mmc_host *mmc;
|
|
|
|
struct at91mci_host *host;
|
2006-10-23 06:44:40 -06:00
|
|
|
struct resource *res;
|
2006-04-02 12:18:51 -06:00
|
|
|
int ret;
|
|
|
|
|
2006-10-23 06:44:40 -06:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (!request_mem_region(res->start, res->end - res->start + 1, DRIVER_NAME))
|
|
|
|
return -EBUSY;
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev);
|
|
|
|
if (!mmc) {
|
2008-02-04 10:12:48 -07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
dev_dbg(&pdev->dev, "couldn't allocate mmc host\n");
|
|
|
|
goto fail6;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
mmc->ops = &at91_mci_ops;
|
|
|
|
mmc->f_min = 375000;
|
|
|
|
mmc->f_max = 25000000;
|
|
|
|
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
|
2010-03-05 14:43:43 -07:00
|
|
|
mmc->caps = 0;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2010-03-05 14:43:40 -07:00
|
|
|
mmc->max_blk_size = MCI_MAXBLKSIZE;
|
|
|
|
mmc->max_blk_count = MCI_BLKATONCE;
|
|
|
|
mmc->max_req_size = MCI_BUFSIZE;
|
2010-03-05 14:43:42 -07:00
|
|
|
mmc->max_phys_segs = MCI_BLKATONCE;
|
|
|
|
mmc->max_hw_segs = MCI_BLKATONCE;
|
|
|
|
mmc->max_seg_size = MCI_BUFSIZE;
|
2006-11-21 09:54:23 -07:00
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
host = mmc_priv(mmc);
|
|
|
|
host->mmc = mmc;
|
|
|
|
host->bus_mode = 0;
|
|
|
|
host->board = pdev->dev.platform_data;
|
|
|
|
if (host->board->wire4) {
|
2010-03-05 14:43:44 -07:00
|
|
|
if (at91mci_is_mci1rev2xx())
|
2007-07-09 06:58:16 -06:00
|
|
|
mmc->caps |= MMC_CAP_4_BIT_DATA;
|
|
|
|
else
|
2008-02-04 10:12:48 -07:00
|
|
|
dev_warn(&pdev->dev, "4 wire bus mode not supported"
|
2007-07-09 06:58:16 -06:00
|
|
|
" - using 1 wire\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2010-03-05 14:43:40 -07:00
|
|
|
host->buffer = dma_alloc_coherent(&pdev->dev, MCI_BUFSIZE,
|
|
|
|
&host->physical_address, GFP_KERNEL);
|
|
|
|
if (!host->buffer) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
dev_err(&pdev->dev, "Can't allocate transmit buffer\n");
|
|
|
|
goto fail5;
|
|
|
|
}
|
|
|
|
|
2010-03-05 14:43:43 -07:00
|
|
|
/* Add SDIO capability when available */
|
2010-03-05 14:43:44 -07:00
|
|
|
if (at91mci_is_mci1rev2xx()) {
|
|
|
|
/* at91mci MCI1 rev2xx sdio interrupt erratum */
|
2010-03-05 14:43:43 -07:00
|
|
|
if (host->board->wire4 || !host->board->slot_b)
|
|
|
|
mmc->caps |= MMC_CAP_SDIO_IRQ;
|
|
|
|
}
|
|
|
|
|
2008-02-04 10:12:48 -07:00
|
|
|
/*
|
|
|
|
* Reserve GPIOs ... board init code makes sure these pins are set
|
|
|
|
* up as GPIOs with the right direction (input, except for vcc)
|
|
|
|
*/
|
|
|
|
if (host->board->det_pin) {
|
|
|
|
ret = gpio_request(host->board->det_pin, "mmc_detect");
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_dbg(&pdev->dev, "couldn't claim card detect pin\n");
|
2010-03-05 14:43:40 -07:00
|
|
|
goto fail4b;
|
2008-02-04 10:12:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (host->board->wp_pin) {
|
|
|
|
ret = gpio_request(host->board->wp_pin, "mmc_wp");
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_dbg(&pdev->dev, "couldn't claim wp sense pin\n");
|
|
|
|
goto fail4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (host->board->vcc_pin) {
|
|
|
|
ret = gpio_request(host->board->vcc_pin, "mmc_vcc");
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_dbg(&pdev->dev, "couldn't claim vcc switch pin\n");
|
|
|
|
goto fail3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Get Clock
|
|
|
|
*/
|
2006-10-23 06:46:54 -06:00
|
|
|
host->mci_clk = clk_get(&pdev->dev, "mci_clk");
|
|
|
|
if (IS_ERR(host->mci_clk)) {
|
2008-02-04 10:12:48 -07:00
|
|
|
ret = -ENODEV;
|
|
|
|
dev_dbg(&pdev->dev, "no mci_clk?\n");
|
|
|
|
goto fail2;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-10-23 06:44:40 -06:00
|
|
|
/*
|
|
|
|
* Map I/O region
|
|
|
|
*/
|
|
|
|
host->baseaddr = ioremap(res->start, res->end - res->start + 1);
|
|
|
|
if (!host->baseaddr) {
|
2008-02-04 10:12:48 -07:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail1;
|
2006-10-23 06:44:40 -06:00
|
|
|
}
|
2006-10-25 11:42:38 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset hardware
|
|
|
|
*/
|
2006-10-23 06:46:54 -06:00
|
|
|
clk_enable(host->mci_clk); /* Enable the peripheral clock */
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_disable(host);
|
|
|
|
at91_mci_enable(host);
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
/*
|
|
|
|
* Allocate the MCI interrupt
|
|
|
|
*/
|
2006-10-23 06:44:40 -06:00
|
|
|
host->irq = platform_get_irq(pdev, 0);
|
2008-02-04 10:12:48 -07:00
|
|
|
ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED,
|
|
|
|
mmc_hostname(mmc), host);
|
2006-04-02 12:18:51 -06:00
|
|
|
if (ret) {
|
2008-02-04 10:12:48 -07:00
|
|
|
dev_dbg(&pdev->dev, "request MCI interrupt failed\n");
|
|
|
|
goto fail0;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2008-11-27 09:23:49 -07:00
|
|
|
setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host);
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
platform_set_drvdata(pdev, mmc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add host to MMC layer
|
|
|
|
*/
|
2007-07-16 03:07:02 -06:00
|
|
|
if (host->board->det_pin) {
|
2008-02-04 10:12:48 -07:00
|
|
|
host->present = !gpio_get_value(host->board->det_pin);
|
2007-07-16 03:07:02 -06:00
|
|
|
}
|
2006-04-02 12:18:51 -06:00
|
|
|
else
|
|
|
|
host->present = -1;
|
|
|
|
|
|
|
|
mmc_add_host(mmc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* monitor card insertion/removal if we can
|
|
|
|
*/
|
|
|
|
if (host->board->det_pin) {
|
2008-02-04 10:12:48 -07:00
|
|
|
ret = request_irq(gpio_to_irq(host->board->det_pin),
|
|
|
|
at91_mmc_det_irq, 0, mmc_hostname(mmc), host);
|
2006-04-02 12:18:51 -06:00
|
|
|
if (ret)
|
2008-02-04 10:12:48 -07:00
|
|
|
dev_warn(&pdev->dev, "request MMC detect irq failed\n");
|
|
|
|
else
|
|
|
|
device_init_wakeup(&pdev->dev, 1);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-10-23 06:53:20 -06:00
|
|
|
pr_debug("Added MCI driver\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
return 0;
|
2008-02-04 10:12:48 -07:00
|
|
|
|
|
|
|
fail0:
|
|
|
|
clk_disable(host->mci_clk);
|
|
|
|
iounmap(host->baseaddr);
|
|
|
|
fail1:
|
|
|
|
clk_put(host->mci_clk);
|
|
|
|
fail2:
|
|
|
|
if (host->board->vcc_pin)
|
|
|
|
gpio_free(host->board->vcc_pin);
|
|
|
|
fail3:
|
|
|
|
if (host->board->wp_pin)
|
|
|
|
gpio_free(host->board->wp_pin);
|
|
|
|
fail4:
|
|
|
|
if (host->board->det_pin)
|
|
|
|
gpio_free(host->board->det_pin);
|
2010-03-05 14:43:40 -07:00
|
|
|
fail4b:
|
|
|
|
if (host->buffer)
|
|
|
|
dma_free_coherent(&pdev->dev, MCI_BUFSIZE,
|
|
|
|
host->buffer, host->physical_address);
|
2008-02-04 10:12:48 -07:00
|
|
|
fail5:
|
|
|
|
mmc_free_host(mmc);
|
|
|
|
fail6:
|
|
|
|
release_mem_region(res->start, res->end - res->start + 1);
|
|
|
|
dev_err(&pdev->dev, "probe failed, err %d\n", ret);
|
|
|
|
return ret;
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a device
|
|
|
|
*/
|
2006-12-26 15:45:26 -07:00
|
|
|
static int __exit at91_mci_remove(struct platform_device *pdev)
|
2006-04-02 12:18:51 -06:00
|
|
|
{
|
|
|
|
struct mmc_host *mmc = platform_get_drvdata(pdev);
|
|
|
|
struct at91mci_host *host;
|
2006-10-23 06:44:40 -06:00
|
|
|
struct resource *res;
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
if (!mmc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
host = mmc_priv(mmc);
|
|
|
|
|
2010-03-05 14:43:40 -07:00
|
|
|
if (host->buffer)
|
|
|
|
dma_free_coherent(&pdev->dev, MCI_BUFSIZE,
|
|
|
|
host->buffer, host->physical_address);
|
|
|
|
|
2007-08-30 08:15:16 -06:00
|
|
|
if (host->board->det_pin) {
|
2008-02-04 10:12:48 -07:00
|
|
|
if (device_can_wakeup(&pdev->dev))
|
|
|
|
free_irq(gpio_to_irq(host->board->det_pin), host);
|
2007-07-16 03:07:02 -06:00
|
|
|
device_init_wakeup(&pdev->dev, 0);
|
2008-02-04 10:12:48 -07:00
|
|
|
gpio_free(host->board->det_pin);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
2006-10-25 11:42:38 -06:00
|
|
|
at91_mci_disable(host);
|
2008-05-30 06:06:32 -06:00
|
|
|
del_timer_sync(&host->timer);
|
2006-10-23 06:44:40 -06:00
|
|
|
mmc_remove_host(mmc);
|
|
|
|
free_irq(host->irq, host);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-23 06:46:54 -06:00
|
|
|
clk_disable(host->mci_clk); /* Disable the peripheral clock */
|
|
|
|
clk_put(host->mci_clk);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2008-02-04 10:12:48 -07:00
|
|
|
if (host->board->vcc_pin)
|
|
|
|
gpio_free(host->board->vcc_pin);
|
|
|
|
if (host->board->wp_pin)
|
|
|
|
gpio_free(host->board->wp_pin);
|
|
|
|
|
2006-10-23 06:44:40 -06:00
|
|
|
iounmap(host->baseaddr);
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
release_mem_region(res->start, res->end - res->start + 1);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
2006-10-23 06:44:40 -06:00
|
|
|
mmc_free_host(mmc);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
2006-06-19 06:06:05 -06:00
|
|
|
pr_debug("MCI Removed\n");
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct mmc_host *mmc = platform_get_drvdata(pdev);
|
2007-07-16 03:07:02 -06:00
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
2006-04-02 12:18:51 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
2007-08-30 08:15:16 -06:00
|
|
|
if (host->board->det_pin && device_may_wakeup(&pdev->dev))
|
2007-07-16 03:07:02 -06:00
|
|
|
enable_irq_wake(host->board->det_pin);
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
if (mmc)
|
2010-05-26 15:42:08 -06:00
|
|
|
ret = mmc_suspend_host(mmc);
|
2006-04-02 12:18:51 -06:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int at91_mci_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct mmc_host *mmc = platform_get_drvdata(pdev);
|
2007-07-16 03:07:02 -06:00
|
|
|
struct at91mci_host *host = mmc_priv(mmc);
|
2006-04-02 12:18:51 -06:00
|
|
|
int ret = 0;
|
|
|
|
|
2007-08-30 08:15:16 -06:00
|
|
|
if (host->board->det_pin && device_may_wakeup(&pdev->dev))
|
2007-07-16 03:07:02 -06:00
|
|
|
disable_irq_wake(host->board->det_pin);
|
|
|
|
|
2006-04-02 12:18:51 -06:00
|
|
|
if (mmc)
|
|
|
|
ret = mmc_resume_host(mmc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define at91_mci_suspend NULL
|
|
|
|
#define at91_mci_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct platform_driver at91_mci_driver = {
|
2006-12-26 15:45:26 -07:00
|
|
|
.remove = __exit_p(at91_mci_remove),
|
2006-04-02 12:18:51 -06:00
|
|
|
.suspend = at91_mci_suspend,
|
|
|
|
.resume = at91_mci_resume,
|
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init at91_mci_init(void)
|
|
|
|
{
|
2006-12-26 15:45:26 -07:00
|
|
|
return platform_driver_probe(&at91_mci_driver, at91_mci_probe);
|
2006-04-02 12:18:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit at91_mci_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&at91_mci_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(at91_mci_init);
|
|
|
|
module_exit(at91_mci_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("AT91 Multimedia Card Interface driver");
|
|
|
|
MODULE_AUTHOR("Nick Randell");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-15 15:34:28 -06:00
|
|
|
MODULE_ALIAS("platform:at91_mci");
|