2005-09-21 14:18:27 +08:00
|
|
|
/*
|
2007-07-12 02:04:50 +08:00
|
|
|
* linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver
|
2005-09-21 14:18:27 +08:00
|
|
|
*
|
|
|
|
* Copyright (c) 2005, Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Developed with help from the 2.4.30 MMC AU1XXX controller including
|
|
|
|
* the following copyright notices:
|
|
|
|
* Copyright (c) 2003-2004 Embedded Edge, LLC.
|
|
|
|
* Portions Copyright (C) 2002 Embedix, Inc
|
|
|
|
* Copyright 2002 Hewlett-Packard Company
|
|
|
|
|
|
|
|
* 2.6 version of this driver inspired by:
|
|
|
|
* (drivers/mmc/wbsd.c) Copyright (C) 2004-2005 Pierre Ossman,
|
|
|
|
* All Rights Reserved.
|
|
|
|
* (drivers/mmc/pxa.c) Copyright (C) 2003 Russell King,
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
/* Why don't we use the SD controllers' carddetect feature?
|
2005-09-21 14:18:27 +08:00
|
|
|
*
|
|
|
|
* From the AU1100 MMC application guide:
|
|
|
|
* If the Au1100-based design is intended to support both MultiMediaCards
|
|
|
|
* and 1- or 4-data bit SecureDigital cards, then the solution is to
|
|
|
|
* connect a weak (560KOhm) pull-up resistor to connector pin 1.
|
|
|
|
* In doing so, a MMC card never enters SPI-mode communications,
|
|
|
|
* but now the SecureDigital card-detect feature of CD/DAT3 is ineffective
|
|
|
|
* (the low to high transition will not occur).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
2006-03-05 07:01:13 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-09-21 14:18:27 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2007-10-28 02:40:46 +08:00
|
|
|
#include <linux/scatterlist.h>
|
2008-06-09 14:36:13 +08:00
|
|
|
#include <linux/leds.h>
|
2005-09-21 14:18:27 +08:00
|
|
|
#include <linux/mmc/host.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2008-06-09 14:36:13 +08:00
|
|
|
|
2005-09-21 14:18:27 +08:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/mach-au1x00/au1000.h>
|
|
|
|
#include <asm/mach-au1x00/au1xxx_dbdma.h>
|
|
|
|
#include <asm/mach-au1x00/au1100_mmc.h>
|
|
|
|
|
|
|
|
#define DRIVER_NAME "au1xxx-mmc"
|
|
|
|
|
|
|
|
/* Set this to enable special debugging macros */
|
2008-06-09 14:36:13 +08:00
|
|
|
/* #define DEBUG */
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2006-03-29 16:30:20 +08:00
|
|
|
#ifdef DEBUG
|
2008-06-09 14:38:35 +08:00
|
|
|
#define DBG(fmt, idx, args...) \
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_debug("au1xmmc(%d): DEBUG: " fmt, idx, ##args)
|
2005-09-21 14:18:27 +08:00
|
|
|
#else
|
2008-06-09 14:38:35 +08:00
|
|
|
#define DBG(fmt, idx, args...) do {} while (0)
|
2005-09-21 14:18:27 +08:00
|
|
|
#endif
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
/* Hardware definitions */
|
|
|
|
#define AU1XMMC_DESCRIPTOR_COUNT 1
|
2008-07-29 16:10:49 +08:00
|
|
|
|
|
|
|
/* max DMA seg size: 64KB on Au1100, 4MB on Au1200 */
|
2011-08-03 01:51:07 +08:00
|
|
|
#define AU1100_MMC_DESCRIPTOR_SIZE 0x0000ffff
|
|
|
|
#define AU1200_MMC_DESCRIPTOR_SIZE 0x003fffff
|
2008-06-09 14:38:35 +08:00
|
|
|
|
|
|
|
#define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \
|
|
|
|
MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \
|
|
|
|
MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36)
|
|
|
|
|
|
|
|
/* This gives us a hard value for the stop command that we can write directly
|
|
|
|
* to the command register.
|
|
|
|
*/
|
|
|
|
#define STOP_CMD \
|
|
|
|
(SD_CMD_RT_1B | SD_CMD_CT_7 | (0xC << SD_CMD_CI_SHIFT) | SD_CMD_GO)
|
|
|
|
|
|
|
|
/* This is the set of interrupts that we configure by default. */
|
|
|
|
#define AU1XMMC_INTERRUPTS \
|
|
|
|
(SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_RAT | \
|
|
|
|
SD_CONFIG_CR | SD_CONFIG_I)
|
|
|
|
|
|
|
|
/* The poll event (looking for insert/remove events runs twice a second. */
|
|
|
|
#define AU1XMMC_DETECT_TIMEOUT (HZ/2)
|
|
|
|
|
|
|
|
struct au1xmmc_host {
|
|
|
|
struct mmc_host *mmc;
|
|
|
|
struct mmc_request *mrq;
|
|
|
|
|
|
|
|
u32 flags;
|
|
|
|
u32 iobase;
|
|
|
|
u32 clock;
|
|
|
|
u32 bus_width;
|
|
|
|
u32 power_mode;
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int len;
|
|
|
|
int dir;
|
|
|
|
} dma;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int index;
|
|
|
|
int offset;
|
|
|
|
int len;
|
|
|
|
} pio;
|
|
|
|
|
|
|
|
u32 tx_chan;
|
|
|
|
u32 rx_chan;
|
|
|
|
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
struct tasklet_struct finish_task;
|
|
|
|
struct tasklet_struct data_task;
|
|
|
|
struct au1xmmc_platform_data *platdata;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct resource *ioarea;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Status flags used by the host structure */
|
|
|
|
#define HOST_F_XMIT 0x0001
|
|
|
|
#define HOST_F_RECV 0x0002
|
|
|
|
#define HOST_F_DMA 0x0010
|
2011-08-03 01:51:07 +08:00
|
|
|
#define HOST_F_DBDMA 0x0020
|
2008-06-09 14:38:35 +08:00
|
|
|
#define HOST_F_ACTIVE 0x0100
|
|
|
|
#define HOST_F_STOP 0x1000
|
|
|
|
|
|
|
|
#define HOST_S_IDLE 0x0001
|
|
|
|
#define HOST_S_CMD 0x0002
|
|
|
|
#define HOST_S_DATA 0x0003
|
|
|
|
#define HOST_S_STOP 0x0004
|
|
|
|
|
|
|
|
/* Easy access macros */
|
|
|
|
#define HOST_STATUS(h) ((h)->iobase + SD_STATUS)
|
|
|
|
#define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG)
|
|
|
|
#define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE)
|
|
|
|
#define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT)
|
|
|
|
#define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT)
|
|
|
|
#define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG)
|
|
|
|
#define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE)
|
|
|
|
#define HOST_CMD(h) ((h)->iobase + SD_CMD)
|
|
|
|
#define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2)
|
|
|
|
#define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT)
|
|
|
|
#define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG)
|
|
|
|
|
|
|
|
#define DMA_CHANNEL(h) \
|
|
|
|
(((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan)
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
static inline int has_dbdma(void)
|
|
|
|
{
|
|
|
|
switch (alchemy_get_cputype()) {
|
|
|
|
case ALCHEMY_CPU_AU1200:
|
2011-11-02 03:03:30 +08:00
|
|
|
case ALCHEMY_CPU_AU1300:
|
2011-08-03 01:51:07 +08:00
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-21 14:18:27 +08:00
|
|
|
static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask)
|
|
|
|
{
|
|
|
|
u32 val = au_readl(HOST_CONFIG(host));
|
|
|
|
val |= mask;
|
|
|
|
au_writel(val, HOST_CONFIG(host));
|
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void FLUSH_FIFO(struct au1xmmc_host *host)
|
|
|
|
{
|
|
|
|
u32 val = au_readl(HOST_CONFIG2(host));
|
|
|
|
|
|
|
|
au_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host));
|
|
|
|
au_sync_delay(1);
|
|
|
|
|
|
|
|
/* SEND_STOP will turn off clock control - this re-enables it */
|
|
|
|
val &= ~SD_CONFIG2_DF;
|
|
|
|
|
|
|
|
au_writel(val, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask)
|
|
|
|
{
|
|
|
|
u32 val = au_readl(HOST_CONFIG(host));
|
|
|
|
val &= ~mask;
|
|
|
|
au_writel(val, HOST_CONFIG(host));
|
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SEND_STOP(struct au1xmmc_host *host)
|
|
|
|
{
|
2008-06-09 14:37:33 +08:00
|
|
|
u32 config2;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
WARN_ON(host->status != HOST_S_DATA);
|
|
|
|
host->status = HOST_S_STOP;
|
|
|
|
|
2008-06-09 14:37:33 +08:00
|
|
|
config2 = au_readl(HOST_CONFIG2(host));
|
|
|
|
au_writel(config2 | SD_CONFIG2_DF, HOST_CONFIG2(host));
|
2005-09-21 14:18:27 +08:00
|
|
|
au_sync();
|
|
|
|
|
tree-wide: fix comment/printk typos
"gadget", "through", "command", "maintain", "maintain", "controller", "address",
"between", "initiali[zs]e", "instead", "function", "select", "already",
"equal", "access", "management", "hierarchy", "registration", "interest",
"relative", "memory", "offset", "already",
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2010-11-02 03:38:34 +08:00
|
|
|
/* Send the stop command */
|
2005-09-21 14:18:27 +08:00
|
|
|
au_writel(STOP_CMD, HOST_CMD(host));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_set_power(struct au1xmmc_host *host, int state)
|
|
|
|
{
|
2008-06-09 14:36:13 +08:00
|
|
|
if (host->platdata && host->platdata->set_power)
|
|
|
|
host->platdata->set_power(host->mmc, state);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
static int au1xmmc_card_inserted(struct mmc_host *mmc)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2008-06-28 00:25:18 +08:00
|
|
|
struct au1xmmc_host *host = mmc_priv(mmc);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
|
|
|
if (host->platdata && host->platdata->card_inserted)
|
2008-06-28 00:25:18 +08:00
|
|
|
return !!host->platdata->card_inserted(host->mmc);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
return -ENOSYS;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2007-01-25 17:29:24 +08:00
|
|
|
static int au1xmmc_card_readonly(struct mmc_host *mmc)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2007-01-25 17:29:24 +08:00
|
|
|
struct au1xmmc_host *host = mmc_priv(mmc);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
|
|
|
if (host->platdata && host->platdata->card_readonly)
|
2008-06-28 00:25:18 +08:00
|
|
|
return !!host->platdata->card_readonly(mmc);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
return -ENOSYS;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_finish_request(struct au1xmmc_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_request *mrq = host->mrq;
|
|
|
|
|
|
|
|
host->mrq = NULL;
|
2008-06-09 14:36:13 +08:00
|
|
|
host->flags &= HOST_F_ACTIVE | HOST_F_DMA;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
host->dma.len = 0;
|
|
|
|
host->dma.dir = 0;
|
|
|
|
|
|
|
|
host->pio.index = 0;
|
|
|
|
host->pio.offset = 0;
|
|
|
|
host->pio.len = 0;
|
|
|
|
|
|
|
|
host->status = HOST_S_IDLE;
|
|
|
|
|
|
|
|
mmc_request_done(host->mmc, mrq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_tasklet_finish(unsigned long param)
|
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = (struct au1xmmc_host *) param;
|
|
|
|
au1xmmc_finish_request(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
|
2007-07-25 03:11:47 +08:00
|
|
|
struct mmc_command *cmd, struct mmc_data *data)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
|
|
|
u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
|
|
|
|
|
2006-03-05 07:01:39 +08:00
|
|
|
switch (mmc_resp_type(cmd)) {
|
2007-01-25 17:27:41 +08:00
|
|
|
case MMC_RSP_NONE:
|
|
|
|
break;
|
2005-09-21 14:18:27 +08:00
|
|
|
case MMC_RSP_R1:
|
|
|
|
mmccmd |= SD_CMD_RT_1;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R1B:
|
|
|
|
mmccmd |= SD_CMD_RT_1B;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R2:
|
|
|
|
mmccmd |= SD_CMD_RT_2;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R3:
|
|
|
|
mmccmd |= SD_CMD_RT_3;
|
|
|
|
break;
|
2007-01-25 17:27:41 +08:00
|
|
|
default:
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info("au1xmmc: unhandled response type %02x\n",
|
2007-01-25 17:27:41 +08:00
|
|
|
mmc_resp_type(cmd));
|
2007-07-23 04:18:46 +08:00
|
|
|
return -EINVAL;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2007-07-25 03:11:47 +08:00
|
|
|
if (data) {
|
2007-10-23 00:16:16 +08:00
|
|
|
if (data->flags & MMC_DATA_READ) {
|
2007-07-25 03:11:47 +08:00
|
|
|
if (data->blocks > 1)
|
|
|
|
mmccmd |= SD_CMD_CT_4;
|
|
|
|
else
|
|
|
|
mmccmd |= SD_CMD_CT_2;
|
2007-10-23 00:16:16 +08:00
|
|
|
} else if (data->flags & MMC_DATA_WRITE) {
|
2007-07-25 03:11:47 +08:00
|
|
|
if (data->blocks > 1)
|
|
|
|
mmccmd |= SD_CMD_CT_3;
|
|
|
|
else
|
|
|
|
mmccmd |= SD_CMD_CT_1;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
au_writel(cmd->arg, HOST_CMDARG(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
if (wait)
|
|
|
|
IRQ_OFF(host, SD_CONFIG_CR);
|
|
|
|
|
|
|
|
au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
/* Wait for the command to go on the line */
|
2008-06-09 14:38:35 +08:00
|
|
|
while (au_readl(HOST_CMD(host)) & SD_CMD_GO)
|
|
|
|
/* nop */;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
/* Wait for the command to come back */
|
|
|
|
if (wait) {
|
|
|
|
u32 status = au_readl(HOST_STATUS(host));
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
while (!(status & SD_STATUS_CR))
|
2005-09-21 14:18:27 +08:00
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
|
|
|
|
/* Clear the CR status */
|
|
|
|
au_writel(SD_STATUS_CR, HOST_STATUS(host));
|
|
|
|
|
|
|
|
IRQ_ON(host, SD_CONFIG_CR);
|
|
|
|
}
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
return 0;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
|
|
|
|
{
|
|
|
|
struct mmc_request *mrq = host->mrq;
|
|
|
|
struct mmc_data *data;
|
|
|
|
u32 crc;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
WARN_ON((host->status != HOST_S_DATA) && (host->status != HOST_S_STOP));
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
if (host->mrq == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
data = mrq->cmd->data;
|
|
|
|
|
|
|
|
if (status == 0)
|
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
|
|
|
|
/* The transaction is really over when the SD_STATUS_DB bit is clear */
|
2008-06-09 14:38:35 +08:00
|
|
|
while ((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
|
2005-09-21 14:18:27 +08:00
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
data->error = 0;
|
2005-09-21 14:18:27 +08:00
|
|
|
dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
|
|
|
|
|
|
|
|
/* Process any errors */
|
|
|
|
crc = (status & (SD_STATUS_WC | SD_STATUS_RC));
|
|
|
|
if (host->flags & HOST_F_XMIT)
|
|
|
|
crc |= ((status & 0x07) == 0x02) ? 0 : 1;
|
|
|
|
|
|
|
|
if (crc)
|
2007-07-23 04:18:46 +08:00
|
|
|
data->error = -EILSEQ;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
/* Clear the CRC bits */
|
|
|
|
au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
|
|
|
|
|
|
|
|
data->bytes_xfered = 0;
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
if (!data->error) {
|
2011-08-03 01:51:07 +08:00
|
|
|
if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) {
|
2005-09-21 14:18:27 +08:00
|
|
|
u32 chan = DMA_CHANNEL(host);
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
chan_tab_t *c = *((chan_tab_t **)chan);
|
2005-09-21 14:18:27 +08:00
|
|
|
au1x_dma_chan_t *cp = c->chan_ptr;
|
|
|
|
data->bytes_xfered = cp->ddma_bytecnt;
|
2008-06-09 14:38:35 +08:00
|
|
|
} else
|
2005-09-21 14:18:27 +08:00
|
|
|
data->bytes_xfered =
|
2008-06-09 14:38:35 +08:00
|
|
|
(data->blocks * data->blksz) - host->pio.len;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
au1xmmc_finish_request(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_tasklet_data(unsigned long param)
|
|
|
|
{
|
2008-06-09 14:38:35 +08:00
|
|
|
struct au1xmmc_host *host = (struct au1xmmc_host *)param;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
u32 status = au_readl(HOST_STATUS(host));
|
|
|
|
au1xmmc_data_complete(host, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define AU1XMMC_MAX_TRANSFER 8
|
|
|
|
|
|
|
|
static void au1xmmc_send_pio(struct au1xmmc_host *host)
|
|
|
|
{
|
2008-06-09 14:38:35 +08:00
|
|
|
struct mmc_data *data;
|
|
|
|
int sg_len, max, count;
|
|
|
|
unsigned char *sg_ptr, val;
|
|
|
|
u32 status;
|
2005-09-21 14:18:27 +08:00
|
|
|
struct scatterlist *sg;
|
|
|
|
|
|
|
|
data = host->mrq->data;
|
|
|
|
|
|
|
|
if (!(host->flags & HOST_F_XMIT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* This is the pointer to the data buffer */
|
|
|
|
sg = &data->sg[host->pio.index];
|
2007-10-23 03:19:53 +08:00
|
|
|
sg_ptr = sg_virt(sg) + host->pio.offset;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
/* This is the space left inside the buffer */
|
|
|
|
sg_len = data->sg[host->pio.index].length - host->pio.offset;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
/* Check if we need less than the size of the sg_buffer */
|
2005-09-21 14:18:27 +08:00
|
|
|
max = (sg_len > host->pio.len) ? host->pio.len : sg_len;
|
2008-06-09 14:38:35 +08:00
|
|
|
if (max > AU1XMMC_MAX_TRANSFER)
|
|
|
|
max = AU1XMMC_MAX_TRANSFER;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
for (count = 0; count < max; count++) {
|
2005-09-21 14:18:27 +08:00
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
|
|
|
|
if (!(status & SD_STATUS_TH))
|
|
|
|
break;
|
|
|
|
|
|
|
|
val = *sg_ptr++;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
au_writel((unsigned long)val, HOST_TXPORT(host));
|
2005-09-21 14:18:27 +08:00
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
host->pio.len -= count;
|
|
|
|
host->pio.offset += count;
|
|
|
|
|
|
|
|
if (count == sg_len) {
|
|
|
|
host->pio.index++;
|
|
|
|
host->pio.offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (host->pio.len == 0) {
|
|
|
|
IRQ_OFF(host, SD_CONFIG_TH);
|
|
|
|
|
|
|
|
if (host->flags & HOST_F_STOP)
|
|
|
|
SEND_STOP(host);
|
|
|
|
|
|
|
|
tasklet_schedule(&host->data_task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_receive_pio(struct au1xmmc_host *host)
|
|
|
|
{
|
2008-06-09 14:38:35 +08:00
|
|
|
struct mmc_data *data;
|
|
|
|
int max, count, sg_len = 0;
|
|
|
|
unsigned char *sg_ptr = NULL;
|
|
|
|
u32 status, val;
|
2005-09-21 14:18:27 +08:00
|
|
|
struct scatterlist *sg;
|
|
|
|
|
|
|
|
data = host->mrq->data;
|
|
|
|
|
|
|
|
if (!(host->flags & HOST_F_RECV))
|
|
|
|
return;
|
|
|
|
|
|
|
|
max = host->pio.len;
|
|
|
|
|
|
|
|
if (host->pio.index < host->dma.len) {
|
|
|
|
sg = &data->sg[host->pio.index];
|
2007-10-23 03:19:53 +08:00
|
|
|
sg_ptr = sg_virt(sg) + host->pio.offset;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
/* This is the space left inside the buffer */
|
|
|
|
sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
/* Check if we need less than the size of the sg_buffer */
|
|
|
|
if (sg_len < max)
|
|
|
|
max = sg_len;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max > AU1XMMC_MAX_TRANSFER)
|
|
|
|
max = AU1XMMC_MAX_TRANSFER;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
for (count = 0; count < max; count++) {
|
2005-09-21 14:18:27 +08:00
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
|
|
|
|
if (!(status & SD_STATUS_NE))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (status & SD_STATUS_RC) {
|
2008-06-09 14:36:13 +08:00
|
|
|
DBG("RX CRC Error [%d + %d].\n", host->pdev->id,
|
2005-09-21 14:18:27 +08:00
|
|
|
host->pio.len, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SD_STATUS_RO) {
|
2008-06-09 14:36:13 +08:00
|
|
|
DBG("RX Overrun [%d + %d]\n", host->pdev->id,
|
2005-09-21 14:18:27 +08:00
|
|
|
host->pio.len, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (status & SD_STATUS_RU) {
|
2008-06-09 14:36:13 +08:00
|
|
|
DBG("RX Underrun [%d + %d]\n", host->pdev->id,
|
2005-09-21 14:18:27 +08:00
|
|
|
host->pio.len, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = au_readl(HOST_RXPORT(host));
|
|
|
|
|
|
|
|
if (sg_ptr)
|
2008-06-09 14:38:35 +08:00
|
|
|
*sg_ptr++ = (unsigned char)(val & 0xFF);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
host->pio.len -= count;
|
|
|
|
host->pio.offset += count;
|
|
|
|
|
|
|
|
if (sg_len && count == sg_len) {
|
|
|
|
host->pio.index++;
|
|
|
|
host->pio.offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (host->pio.len == 0) {
|
2008-06-09 14:38:35 +08:00
|
|
|
/* IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF); */
|
2005-09-21 14:18:27 +08:00
|
|
|
IRQ_OFF(host, SD_CONFIG_NE);
|
|
|
|
|
|
|
|
if (host->flags & HOST_F_STOP)
|
|
|
|
SEND_STOP(host);
|
|
|
|
|
|
|
|
tasklet_schedule(&host->data_task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
/* This is called when a command has been completed - grab the response
|
|
|
|
* and check for errors. Then start the data transfer if it is indicated.
|
|
|
|
*/
|
2005-09-21 14:18:27 +08:00
|
|
|
static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
|
|
|
|
{
|
|
|
|
struct mmc_request *mrq = host->mrq;
|
|
|
|
struct mmc_command *cmd;
|
2008-06-09 14:38:35 +08:00
|
|
|
u32 r[4];
|
|
|
|
int i, trans;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
if (!host->mrq)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cmd = mrq->cmd;
|
2007-07-23 04:18:46 +08:00
|
|
|
cmd->error = 0;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2006-02-02 20:23:12 +08:00
|
|
|
if (cmd->flags & MMC_RSP_PRESENT) {
|
|
|
|
if (cmd->flags & MMC_RSP_136) {
|
|
|
|
r[0] = au_readl(host->iobase + SD_RESP3);
|
|
|
|
r[1] = au_readl(host->iobase + SD_RESP2);
|
|
|
|
r[2] = au_readl(host->iobase + SD_RESP1);
|
|
|
|
r[3] = au_readl(host->iobase + SD_RESP0);
|
|
|
|
|
|
|
|
/* The CRC is omitted from the response, so really
|
|
|
|
* we only got 120 bytes, but the engine expects
|
2008-06-09 14:38:35 +08:00
|
|
|
* 128 bits, so we have to shift things up.
|
2006-02-02 20:23:12 +08:00
|
|
|
*/
|
2008-06-09 14:38:35 +08:00
|
|
|
for (i = 0; i < 4; i++) {
|
2006-02-02 20:23:12 +08:00
|
|
|
cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8;
|
|
|
|
if (i != 3)
|
|
|
|
cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Techincally, we should be getting all 48 bits of
|
|
|
|
* the response (SD_RESP1 + SD_RESP2), but because
|
|
|
|
* our response omits the CRC, our data ends up
|
|
|
|
* being shifted 8 bits to the right. In this case,
|
|
|
|
* that means that the OSR data starts at bit 31,
|
2008-06-09 14:38:35 +08:00
|
|
|
* so we can just read RESP0 and return that.
|
2006-02-02 20:23:12 +08:00
|
|
|
*/
|
|
|
|
cmd->resp[0] = au_readl(host->iobase + SD_RESP0);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Figure out errors */
|
|
|
|
if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
|
2007-07-23 04:18:46 +08:00
|
|
|
cmd->error = -EILSEQ;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
if (!trans || cmd->error) {
|
2008-06-09 14:38:35 +08:00
|
|
|
IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF);
|
2005-09-21 14:18:27 +08:00
|
|
|
tasklet_schedule(&host->finish_task);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->status = HOST_S_DATA;
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
if ((host->flags & (HOST_F_DMA | HOST_F_DBDMA))) {
|
2005-09-21 14:18:27 +08:00
|
|
|
u32 channel = DMA_CHANNEL(host);
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
/* Start the DBDMA as soon as the buffer gets something in it */
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
if (host->flags & HOST_F_RECV) {
|
|
|
|
u32 mask = SD_STATUS_DB | SD_STATUS_NE;
|
|
|
|
|
|
|
|
while((status & mask) != mask)
|
|
|
|
status = au_readl(HOST_STATUS(host));
|
|
|
|
}
|
|
|
|
|
|
|
|
au1xxx_dbdma_start(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
|
|
|
|
{
|
|
|
|
unsigned int pbus = get_au1x00_speed();
|
|
|
|
unsigned int divisor;
|
|
|
|
u32 config;
|
|
|
|
|
|
|
|
/* From databook:
|
2008-06-09 14:38:35 +08:00
|
|
|
* divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
|
|
|
|
*/
|
2005-09-21 14:18:27 +08:00
|
|
|
pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2);
|
|
|
|
pbus /= 2;
|
|
|
|
divisor = ((pbus / rate) / 2) - 1;
|
|
|
|
|
|
|
|
config = au_readl(HOST_CONFIG(host));
|
|
|
|
|
|
|
|
config &= ~(SD_CONFIG_DIV);
|
|
|
|
config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE;
|
|
|
|
|
|
|
|
au_writel(config, HOST_CONFIG(host));
|
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
static int au1xmmc_prepare_data(struct au1xmmc_host *host,
|
|
|
|
struct mmc_data *data)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2006-05-20 04:48:03 +08:00
|
|
|
int datalen = data->blocks * data->blksz;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
host->flags |= HOST_F_RECV;
|
|
|
|
else
|
|
|
|
host->flags |= HOST_F_XMIT;
|
|
|
|
|
|
|
|
if (host->mrq->stop)
|
|
|
|
host->flags |= HOST_F_STOP;
|
|
|
|
|
|
|
|
host->dma.dir = DMA_BIDIRECTIONAL;
|
|
|
|
|
|
|
|
host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg,
|
|
|
|
data->sg_len, host->dma.dir);
|
|
|
|
|
|
|
|
if (host->dma.len == 0)
|
2007-07-23 04:18:46 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2006-05-20 04:48:03 +08:00
|
|
|
au_writel(data->blksz - 1, HOST_BLKSIZE(host));
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) {
|
2005-09-21 14:18:27 +08:00
|
|
|
int i;
|
|
|
|
u32 channel = DMA_CHANNEL(host);
|
|
|
|
|
|
|
|
au1xxx_dbdma_stop(channel);
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
for (i = 0; i < host->dma.len; i++) {
|
2005-09-21 14:18:27 +08:00
|
|
|
u32 ret = 0, flags = DDMA_FLAGS_NOIE;
|
|
|
|
struct scatterlist *sg = &data->sg[i];
|
|
|
|
int sg_len = sg->length;
|
|
|
|
|
|
|
|
int len = (datalen > sg_len) ? sg_len : datalen;
|
|
|
|
|
|
|
|
if (i == host->dma.len - 1)
|
|
|
|
flags = DDMA_FLAGS_IE;
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
if (host->flags & HOST_F_XMIT) {
|
2009-10-14 02:22:34 +08:00
|
|
|
ret = au1xxx_dbdma_put_source(channel,
|
2009-10-14 02:22:35 +08:00
|
|
|
sg_phys(sg), len, flags);
|
2008-06-09 14:38:35 +08:00
|
|
|
} else {
|
2009-10-14 02:22:34 +08:00
|
|
|
ret = au1xxx_dbdma_put_dest(channel,
|
2009-10-14 02:22:35 +08:00
|
|
|
sg_phys(sg), len, flags);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
if (!ret)
|
2005-09-21 14:18:27 +08:00
|
|
|
goto dataerr;
|
|
|
|
|
|
|
|
datalen -= len;
|
|
|
|
}
|
2008-06-09 14:38:35 +08:00
|
|
|
} else {
|
2005-09-21 14:18:27 +08:00
|
|
|
host->pio.index = 0;
|
|
|
|
host->pio.offset = 0;
|
|
|
|
host->pio.len = datalen;
|
|
|
|
|
|
|
|
if (host->flags & HOST_F_XMIT)
|
|
|
|
IRQ_ON(host, SD_CONFIG_TH);
|
|
|
|
else
|
|
|
|
IRQ_ON(host, SD_CONFIG_NE);
|
2008-06-09 14:38:35 +08:00
|
|
|
/* IRQ_ON(host, SD_CONFIG_RA | SD_CONFIG_RF); */
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
return 0;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
dataerr:
|
|
|
|
dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
|
|
|
|
host->dma.dir);
|
2007-07-23 04:18:46 +08:00
|
|
|
return -ETIMEDOUT;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
/* This actually starts a command or data transaction */
|
2005-09-21 14:18:27 +08:00
|
|
|
static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
|
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = mmc_priv(mmc);
|
2007-07-23 04:18:46 +08:00
|
|
|
int ret = 0;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
WARN_ON(irqs_disabled());
|
|
|
|
WARN_ON(host->status != HOST_S_IDLE);
|
|
|
|
|
|
|
|
host->mrq = mrq;
|
|
|
|
host->status = HOST_S_CMD;
|
|
|
|
|
2008-06-09 14:39:11 +08:00
|
|
|
/* fail request immediately if no card is present */
|
2008-06-28 00:25:18 +08:00
|
|
|
if (0 == au1xmmc_card_inserted(mmc)) {
|
2008-06-09 14:39:11 +08:00
|
|
|
mrq->cmd->error = -ENOMEDIUM;
|
|
|
|
au1xmmc_finish_request(host);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-21 14:18:27 +08:00
|
|
|
if (mrq->data) {
|
|
|
|
FLUSH_FIFO(host);
|
|
|
|
ret = au1xmmc_prepare_data(host, mrq->data);
|
|
|
|
}
|
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
if (!ret)
|
2007-07-25 03:11:47 +08:00
|
|
|
ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2007-07-23 04:18:46 +08:00
|
|
|
if (ret) {
|
2005-09-21 14:18:27 +08:00
|
|
|
mrq->cmd->error = ret;
|
|
|
|
au1xmmc_finish_request(host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void au1xmmc_reset_controller(struct au1xmmc_host *host)
|
|
|
|
{
|
|
|
|
/* Apply the clock */
|
|
|
|
au_writel(SD_ENABLE_CE, HOST_ENABLE(host));
|
|
|
|
au_sync_delay(1);
|
|
|
|
|
|
|
|
au_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host));
|
|
|
|
au_sync_delay(5);
|
|
|
|
|
|
|
|
au_writel(~0, HOST_STATUS(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
au_writel(0, HOST_BLKSIZE(host));
|
|
|
|
au_writel(0x001fffff, HOST_TIMEOUT(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
au_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host));
|
|
|
|
au_sync_delay(1);
|
|
|
|
|
|
|
|
au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
/* Configure interrupts */
|
|
|
|
au_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host));
|
|
|
|
au_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-09 14:38:35 +08:00
|
|
|
static void au1xmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = mmc_priv(mmc);
|
2008-06-09 14:37:33 +08:00
|
|
|
u32 config2;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
if (ios->power_mode == MMC_POWER_OFF)
|
|
|
|
au1xmmc_set_power(host, 0);
|
|
|
|
else if (ios->power_mode == MMC_POWER_ON) {
|
|
|
|
au1xmmc_set_power(host, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ios->clock && ios->clock != host->clock) {
|
|
|
|
au1xmmc_set_clock(host, ios->clock);
|
|
|
|
host->clock = ios->clock;
|
|
|
|
}
|
2008-06-09 14:37:33 +08:00
|
|
|
|
|
|
|
config2 = au_readl(HOST_CONFIG2(host));
|
|
|
|
switch (ios->bus_width) {
|
2011-11-02 03:03:30 +08:00
|
|
|
case MMC_BUS_WIDTH_8:
|
|
|
|
config2 |= SD_CONFIG2_BB;
|
|
|
|
break;
|
2008-06-09 14:37:33 +08:00
|
|
|
case MMC_BUS_WIDTH_4:
|
2011-11-02 03:03:30 +08:00
|
|
|
config2 &= ~SD_CONFIG2_BB;
|
2008-06-09 14:37:33 +08:00
|
|
|
config2 |= SD_CONFIG2_WB;
|
|
|
|
break;
|
|
|
|
case MMC_BUS_WIDTH_1:
|
2011-11-02 03:03:30 +08:00
|
|
|
config2 &= ~(SD_CONFIG2_WB | SD_CONFIG2_BB);
|
2008-06-09 14:37:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
au_writel(config2, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
|
|
|
|
#define STATUS_DATA_IN (SD_STATUS_NE)
|
|
|
|
#define STATUS_DATA_OUT (SD_STATUS_TH)
|
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2008-06-09 14:36:13 +08:00
|
|
|
struct au1xmmc_host *host = dev_id;
|
2005-09-21 14:18:27 +08:00
|
|
|
u32 status;
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
status = au_readl(HOST_STATUS(host));
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
if (!(status & SD_STATUS_I))
|
|
|
|
return IRQ_NONE; /* not ours */
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:38:03 +08:00
|
|
|
if (status & SD_STATUS_SI) /* SDIO */
|
|
|
|
mmc_signal_sdio_irq(host->mmc);
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
if (host->mrq && (status & STATUS_TIMEOUT)) {
|
|
|
|
if (status & SD_STATUS_RAT)
|
|
|
|
host->mrq->cmd->error = -ETIMEDOUT;
|
|
|
|
else if (status & SD_STATUS_DT)
|
|
|
|
host->mrq->data->error = -ETIMEDOUT;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* In PIO mode, interrupts might still be enabled */
|
|
|
|
IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF); */
|
|
|
|
tasklet_schedule(&host->finish_task);
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
#if 0
|
2008-06-09 14:36:13 +08:00
|
|
|
else if (status & SD_STATUS_DD) {
|
|
|
|
/* Sometimes we get a DD before a NE in PIO mode */
|
|
|
|
if (!(host->flags & HOST_F_DMA) && (status & SD_STATUS_NE))
|
|
|
|
au1xmmc_receive_pio(host);
|
|
|
|
else {
|
|
|
|
au1xmmc_data_complete(host, status);
|
|
|
|
/* tasklet_schedule(&host->data_task); */
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
}
|
2008-06-09 14:36:13 +08:00
|
|
|
#endif
|
|
|
|
else if (status & SD_STATUS_CR) {
|
|
|
|
if (host->status == HOST_S_CMD)
|
|
|
|
au1xmmc_cmd_complete(host, status);
|
|
|
|
|
|
|
|
} else if (!(host->flags & HOST_F_DMA)) {
|
|
|
|
if ((host->flags & HOST_F_XMIT) && (status & STATUS_DATA_OUT))
|
|
|
|
au1xmmc_send_pio(host);
|
|
|
|
else if ((host->flags & HOST_F_RECV) && (status & STATUS_DATA_IN))
|
|
|
|
au1xmmc_receive_pio(host);
|
|
|
|
|
|
|
|
} else if (status & 0x203F3C70) {
|
|
|
|
DBG("Unhandled status %8.8x\n", host->pdev->id,
|
|
|
|
status);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
au_writel(status, HOST_STATUS(host));
|
|
|
|
au_sync();
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
return IRQ_HANDLED;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* 8bit memory DMA device */
|
|
|
|
static dbdev_tab_t au1xmmc_mem_dbdev = {
|
|
|
|
.dev_id = DSCR_CMD0_ALWAYS,
|
|
|
|
.dev_flags = DEV_FLAGS_ANYUSE,
|
|
|
|
.dev_tsize = 0,
|
|
|
|
.dev_devwidth = 8,
|
|
|
|
.dev_physaddr = 0x00000000,
|
|
|
|
.dev_intlevel = 0,
|
|
|
|
.dev_intpolarity = 0,
|
2005-09-21 14:18:27 +08:00
|
|
|
};
|
2008-06-09 14:36:13 +08:00
|
|
|
static int memid;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
static void au1xmmc_dbdma_callback(int irq, void *dev_id)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2008-06-09 14:36:13 +08:00
|
|
|
struct au1xmmc_host *host = (struct au1xmmc_host *)dev_id;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* Avoid spurious interrupts */
|
|
|
|
if (!host->mrq)
|
|
|
|
return;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
if (host->flags & HOST_F_STOP)
|
|
|
|
SEND_STOP(host);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
tasklet_schedule(&host->data_task);
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
static int au1xmmc_dbdma_init(struct au1xmmc_host *host)
|
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
int txid, rxid;
|
|
|
|
|
|
|
|
res = platform_get_resource(host->pdev, IORESOURCE_DMA, 0);
|
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
|
|
|
txid = res->start;
|
|
|
|
|
|
|
|
res = platform_get_resource(host->pdev, IORESOURCE_DMA, 1);
|
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
|
|
|
rxid = res->start;
|
|
|
|
|
|
|
|
if (!memid)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
host->tx_chan = au1xxx_dbdma_chan_alloc(memid, txid,
|
|
|
|
au1xmmc_dbdma_callback, (void *)host);
|
|
|
|
if (!host->tx_chan) {
|
|
|
|
dev_err(&host->pdev->dev, "cannot allocate TX DMA\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->rx_chan = au1xxx_dbdma_chan_alloc(rxid, memid,
|
|
|
|
au1xmmc_dbdma_callback, (void *)host);
|
|
|
|
if (!host->rx_chan) {
|
|
|
|
dev_err(&host->pdev->dev, "cannot allocate RX DMA\n");
|
|
|
|
au1xxx_dbdma_chan_free(host->tx_chan);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
au1xxx_dbdma_set_devwidth(host->tx_chan, 8);
|
|
|
|
au1xxx_dbdma_set_devwidth(host->rx_chan, 8);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
au1xxx_dbdma_ring_alloc(host->tx_chan, AU1XMMC_DESCRIPTOR_COUNT);
|
|
|
|
au1xxx_dbdma_ring_alloc(host->rx_chan, AU1XMMC_DESCRIPTOR_COUNT);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* DBDMA is good to go */
|
2011-08-03 01:51:07 +08:00
|
|
|
host->flags |= HOST_F_DMA | HOST_F_DBDMA;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
static void au1xmmc_dbdma_shutdown(struct au1xmmc_host *host)
|
|
|
|
{
|
|
|
|
if (host->flags & HOST_F_DMA) {
|
|
|
|
host->flags &= ~HOST_F_DMA;
|
|
|
|
au1xxx_dbdma_chan_free(host->tx_chan);
|
|
|
|
au1xxx_dbdma_chan_free(host->rx_chan);
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:38:03 +08:00
|
|
|
static void au1xmmc_enable_sdio_irq(struct mmc_host *mmc, int en)
|
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = mmc_priv(mmc);
|
|
|
|
|
|
|
|
if (en)
|
|
|
|
IRQ_ON(host, SD_CONFIG_SI);
|
|
|
|
else
|
|
|
|
IRQ_OFF(host, SD_CONFIG_SI);
|
|
|
|
}
|
|
|
|
|
2006-12-05 14:43:38 +08:00
|
|
|
static const struct mmc_host_ops au1xmmc_ops = {
|
2005-09-21 14:18:27 +08:00
|
|
|
.request = au1xmmc_request,
|
|
|
|
.set_ios = au1xmmc_set_ios,
|
2007-01-25 17:29:24 +08:00
|
|
|
.get_ro = au1xmmc_card_readonly,
|
2008-06-28 00:25:18 +08:00
|
|
|
.get_cd = au1xmmc_card_inserted,
|
2008-06-09 14:38:03 +08:00
|
|
|
.enable_sdio_irq = au1xmmc_enable_sdio_irq,
|
2005-09-21 14:18:27 +08:00
|
|
|
};
|
|
|
|
|
2012-11-20 02:23:06 +08:00
|
|
|
static int au1xmmc_probe(struct platform_device *pdev)
|
2008-06-09 14:36:13 +08:00
|
|
|
{
|
|
|
|
struct mmc_host *mmc;
|
|
|
|
struct au1xmmc_host *host;
|
|
|
|
struct resource *r;
|
2011-11-02 03:03:30 +08:00
|
|
|
int ret, iflag;
|
2008-06-09 14:36:13 +08:00
|
|
|
|
|
|
|
mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev);
|
|
|
|
if (!mmc) {
|
|
|
|
dev_err(&pdev->dev, "no memory for mmc_host\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out0;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
host = mmc_priv(mmc);
|
|
|
|
host->mmc = mmc;
|
|
|
|
host->platdata = pdev->dev.platform_data;
|
|
|
|
host->pdev = pdev;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!r) {
|
|
|
|
dev_err(&pdev->dev, "no mmio defined\n");
|
|
|
|
goto out1;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2009-12-15 03:28:06 +08:00
|
|
|
host->ioarea = request_mem_region(r->start, resource_size(r),
|
2008-06-09 14:36:13 +08:00
|
|
|
pdev->name);
|
|
|
|
if (!host->ioarea) {
|
|
|
|
dev_err(&pdev->dev, "mmio already in use\n");
|
|
|
|
goto out1;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
host->iobase = (unsigned long)ioremap(r->start, 0x3c);
|
|
|
|
if (!host->iobase) {
|
|
|
|
dev_err(&pdev->dev, "cannot remap mmio\n");
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (!r) {
|
|
|
|
dev_err(&pdev->dev, "no IRQ defined\n");
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
host->irq = r->start;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
mmc->ops = &au1xmmc_ops;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
mmc->f_min = 450000;
|
|
|
|
mmc->f_max = 24000000;
|
2006-11-22 00:54:23 +08:00
|
|
|
|
2011-11-02 03:03:30 +08:00
|
|
|
mmc->max_blk_size = 2048;
|
|
|
|
mmc->max_blk_count = 512;
|
|
|
|
|
|
|
|
mmc->ocr_avail = AU1XMMC_OCR;
|
|
|
|
mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
|
|
|
|
mmc->max_segs = AU1XMMC_DESCRIPTOR_COUNT;
|
|
|
|
|
|
|
|
iflag = IRQF_SHARED; /* Au1100/Au1200: one int for both ctrls */
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
switch (alchemy_get_cputype()) {
|
|
|
|
case ALCHEMY_CPU_AU1100:
|
|
|
|
mmc->max_seg_size = AU1100_MMC_DESCRIPTOR_SIZE;
|
|
|
|
break;
|
|
|
|
case ALCHEMY_CPU_AU1200:
|
|
|
|
mmc->max_seg_size = AU1200_MMC_DESCRIPTOR_SIZE;
|
2011-11-02 03:03:30 +08:00
|
|
|
break;
|
|
|
|
case ALCHEMY_CPU_AU1300:
|
|
|
|
iflag = 0; /* nothing is shared */
|
|
|
|
mmc->max_seg_size = AU1200_MMC_DESCRIPTOR_SIZE;
|
|
|
|
mmc->f_max = 52000000;
|
|
|
|
if (host->ioarea->start == AU1100_SD0_PHYS_ADDR)
|
|
|
|
mmc->caps |= MMC_CAP_8_BIT_DATA;
|
2011-08-03 01:51:07 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2011-11-02 03:03:30 +08:00
|
|
|
ret = request_irq(host->irq, au1xmmc_irq, iflag, DRIVER_NAME, host);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "cannot grab IRQ\n");
|
|
|
|
goto out3;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
host->status = HOST_S_IDLE;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
/* board-specific carddetect setup, if any */
|
|
|
|
if (host->platdata && host->platdata->cd_setup) {
|
|
|
|
ret = host->platdata->cd_setup(mmc, 1);
|
|
|
|
if (ret) {
|
2008-06-28 00:25:18 +08:00
|
|
|
dev_warn(&pdev->dev, "board CD setup failed\n");
|
|
|
|
mmc->caps |= MMC_CAP_NEEDS_POLL;
|
2008-06-09 14:36:13 +08:00
|
|
|
}
|
2008-06-28 00:25:18 +08:00
|
|
|
} else
|
|
|
|
mmc->caps |= MMC_CAP_NEEDS_POLL;
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2009-10-14 15:38:06 +08:00
|
|
|
/* platform may not be able to use all advertised caps */
|
|
|
|
if (host->platdata)
|
|
|
|
mmc->caps &= ~(host->platdata->mask_host_caps);
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
tasklet_init(&host->data_task, au1xmmc_tasklet_data,
|
|
|
|
(unsigned long)host);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
|
|
|
|
(unsigned long)host);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
if (has_dbdma()) {
|
|
|
|
ret = au1xmmc_dbdma_init(host);
|
|
|
|
if (ret)
|
2011-11-04 04:28:14 +08:00
|
|
|
pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n");
|
2011-08-03 01:51:07 +08:00
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
#ifdef CONFIG_LEDS_CLASS
|
|
|
|
if (host->platdata && host->platdata->led) {
|
|
|
|
struct led_classdev *led = host->platdata->led;
|
|
|
|
led->name = mmc_hostname(mmc);
|
|
|
|
led->brightness = LED_OFF;
|
|
|
|
led->default_trigger = mmc_hostname(mmc);
|
|
|
|
ret = led_classdev_register(mmc_dev(mmc), led);
|
|
|
|
if (ret)
|
|
|
|
goto out5;
|
|
|
|
}
|
|
|
|
#endif
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
au1xmmc_reset_controller(host);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
ret = mmc_add_host(mmc);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "cannot add mmc host\n");
|
|
|
|
goto out6;
|
|
|
|
}
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-07-17 19:07:28 +08:00
|
|
|
platform_set_drvdata(pdev, host);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2011-10-11 14:14:09 +08:00
|
|
|
pr_info(DRIVER_NAME ": MMC Controller %d set up at %8.8X"
|
2008-06-09 14:36:13 +08:00
|
|
|
" (mode=%s)\n", pdev->id, host->iobase,
|
|
|
|
host->flags & HOST_F_DMA ? "dma" : "pio");
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
return 0; /* all ok */
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
out6:
|
|
|
|
#ifdef CONFIG_LEDS_CLASS
|
|
|
|
if (host->platdata && host->platdata->led)
|
|
|
|
led_classdev_unregister(host->platdata->led);
|
|
|
|
out5:
|
|
|
|
#endif
|
|
|
|
au_writel(0, HOST_ENABLE(host));
|
|
|
|
au_writel(0, HOST_CONFIG(host));
|
|
|
|
au_writel(0, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
if (host->flags & HOST_F_DBDMA)
|
|
|
|
au1xmmc_dbdma_shutdown(host);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
|
|
|
tasklet_kill(&host->data_task);
|
|
|
|
tasklet_kill(&host->finish_task);
|
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
if (host->platdata && host->platdata->cd_setup &&
|
|
|
|
!(mmc->caps & MMC_CAP_NEEDS_POLL))
|
2008-06-09 14:36:13 +08:00
|
|
|
host->platdata->cd_setup(mmc, 0);
|
2008-06-28 00:25:18 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
free_irq(host->irq, host);
|
|
|
|
out3:
|
|
|
|
iounmap((void *)host->iobase);
|
|
|
|
out2:
|
|
|
|
release_resource(host->ioarea);
|
|
|
|
kfree(host->ioarea);
|
|
|
|
out1:
|
|
|
|
mmc_free_host(mmc);
|
|
|
|
out0:
|
|
|
|
return ret;
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:03 +08:00
|
|
|
static int au1xmmc_remove(struct platform_device *pdev)
|
2005-09-21 14:18:27 +08:00
|
|
|
{
|
2008-07-17 19:07:28 +08:00
|
|
|
struct au1xmmc_host *host = platform_get_drvdata(pdev);
|
2008-06-09 14:36:13 +08:00
|
|
|
|
2008-07-17 19:07:28 +08:00
|
|
|
if (host) {
|
|
|
|
mmc_remove_host(host->mmc);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
#ifdef CONFIG_LEDS_CLASS
|
|
|
|
if (host->platdata && host->platdata->led)
|
|
|
|
led_classdev_unregister(host->platdata->led);
|
|
|
|
#endif
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-28 00:25:18 +08:00
|
|
|
if (host->platdata && host->platdata->cd_setup &&
|
2008-07-17 19:07:28 +08:00
|
|
|
!(host->mmc->caps & MMC_CAP_NEEDS_POLL))
|
|
|
|
host->platdata->cd_setup(host->mmc, 0);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
au_writel(0, HOST_ENABLE(host));
|
|
|
|
au_writel(0, HOST_CONFIG(host));
|
|
|
|
au_writel(0, HOST_CONFIG2(host));
|
|
|
|
au_sync();
|
2005-09-21 14:18:27 +08:00
|
|
|
|
|
|
|
tasklet_kill(&host->data_task);
|
|
|
|
tasklet_kill(&host->finish_task);
|
|
|
|
|
2011-08-03 01:51:07 +08:00
|
|
|
if (host->flags & HOST_F_DBDMA)
|
|
|
|
au1xmmc_dbdma_shutdown(host);
|
|
|
|
|
2005-09-21 14:18:27 +08:00
|
|
|
au1xmmc_set_power(host, 0);
|
|
|
|
|
2008-06-09 14:36:13 +08:00
|
|
|
free_irq(host->irq, host);
|
|
|
|
iounmap((void *)host->iobase);
|
|
|
|
release_resource(host->ioarea);
|
|
|
|
kfree(host->ioarea);
|
2005-09-21 14:18:27 +08:00
|
|
|
|
2008-07-17 19:07:28 +08:00
|
|
|
mmc_free_host(host->mmc);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-17 19:07:28 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int au1xmmc_suspend(struct platform_device *pdev, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
au_writel(0, HOST_CONFIG2(host));
|
|
|
|
au_writel(0, HOST_CONFIG(host));
|
|
|
|
au_writel(0xffffffff, HOST_STATUS(host));
|
|
|
|
au_writel(0, HOST_ENABLE(host));
|
|
|
|
au_sync();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int au1xmmc_resume(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct au1xmmc_host *host = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
au1xmmc_reset_controller(host);
|
|
|
|
|
2013-09-25 16:55:23 +08:00
|
|
|
return 0;
|
2008-07-17 19:07:28 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define au1xmmc_suspend NULL
|
|
|
|
#define au1xmmc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2006-03-05 07:01:13 +08:00
|
|
|
static struct platform_driver au1xmmc_driver = {
|
2005-09-21 14:18:27 +08:00
|
|
|
.probe = au1xmmc_probe,
|
|
|
|
.remove = au1xmmc_remove,
|
2008-07-17 19:07:28 +08:00
|
|
|
.suspend = au1xmmc_suspend,
|
|
|
|
.resume = au1xmmc_resume,
|
2006-03-05 07:01:13 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2008-04-16 05:34:28 +08:00
|
|
|
.owner = THIS_MODULE,
|
2006-03-05 07:01:13 +08:00
|
|
|
},
|
2005-09-21 14:18:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init au1xmmc_init(void)
|
|
|
|
{
|
2011-08-03 01:51:07 +08:00
|
|
|
if (has_dbdma()) {
|
|
|
|
/* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
|
|
|
|
* of 8 bits. And since devices are shared, we need to create
|
|
|
|
* our own to avoid freaking out other devices.
|
|
|
|
*/
|
|
|
|
memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
|
|
|
|
if (!memid)
|
2011-11-04 04:28:14 +08:00
|
|
|
pr_err("au1xmmc: cannot add memory dbdma\n");
|
2011-08-03 01:51:07 +08:00
|
|
|
}
|
2006-03-05 07:01:13 +08:00
|
|
|
return platform_driver_register(&au1xmmc_driver);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit au1xmmc_exit(void)
|
|
|
|
{
|
2011-08-03 01:51:07 +08:00
|
|
|
if (has_dbdma() && memid)
|
2008-06-09 14:36:13 +08:00
|
|
|
au1xxx_ddma_del_device(memid);
|
2011-08-03 01:51:07 +08:00
|
|
|
|
2006-03-05 07:01:13 +08:00
|
|
|
platform_driver_unregister(&au1xmmc_driver);
|
2005-09-21 14:18:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(au1xmmc_init);
|
|
|
|
module_exit(au1xmmc_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Advanced Micro Devices, Inc");
|
|
|
|
MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-16 05:34:28 +08:00
|
|
|
MODULE_ALIAS("platform:au1xxx-mmc");
|