2010-05-27 04:41:59 +07:00
|
|
|
/*
|
|
|
|
* MMCIF eMMC driver.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Renesas Solutions Corp.
|
|
|
|
* Yusuke Goda <yusuke.goda.sx@renesas.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License.
|
|
|
|
*/
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
/*
|
|
|
|
* The MMCIF driver is now processing MMC requests asynchronously, according
|
|
|
|
* to the Linux MMC API requirement.
|
|
|
|
*
|
|
|
|
* The MMCIF driver processes MMC requests in up to 3 stages: command, optional
|
|
|
|
* data, and optional stop. To achieve asynchronous processing each of these
|
|
|
|
* stages is split into two halves: a top and a bottom half. The top half
|
|
|
|
* initialises the hardware, installs a timeout handler to handle completion
|
|
|
|
* timeouts, and returns. In case of the command stage this immediately returns
|
|
|
|
* control to the caller, leaving all further processing to run asynchronously.
|
|
|
|
* All further request processing is performed by the bottom halves.
|
|
|
|
*
|
|
|
|
* The bottom half further consists of a "hard" IRQ handler, an IRQ handler
|
|
|
|
* thread, a DMA completion callback, if DMA is used, a timeout work, and
|
|
|
|
* request- and stage-specific handler methods.
|
|
|
|
*
|
|
|
|
* Each bottom half run begins with either a hardware interrupt, a DMA callback
|
|
|
|
* invocation, or a timeout work run. In case of an error or a successful
|
|
|
|
* processing completion, the MMC core is informed and the request processing is
|
|
|
|
* finished. In case processing has to continue, i.e., if data has to be read
|
|
|
|
* from or written to the card, or if a stop command has to be sent, the next
|
|
|
|
* top half is called, which performs the necessary hardware handling and
|
|
|
|
* reschedules the timeout work. This returns the driver state machine into the
|
|
|
|
* bottom half waiting state.
|
|
|
|
*/
|
|
|
|
|
2011-11-23 21:52:30 +07:00
|
|
|
#include <linux/bitops.h>
|
2010-11-24 17:05:12 +07:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/completion.h>
|
2010-11-24 17:05:18 +07:00
|
|
|
#include <linux/delay.h>
|
2010-05-27 04:41:59 +07:00
|
|
|
#include <linux/dma-mapping.h>
|
2010-11-24 17:05:22 +07:00
|
|
|
#include <linux/dmaengine.h>
|
2010-05-27 04:41:59 +07:00
|
|
|
#include <linux/mmc/card.h>
|
|
|
|
#include <linux/mmc/core.h>
|
2010-11-24 17:05:18 +07:00
|
|
|
#include <linux/mmc/host.h>
|
2010-05-27 04:41:59 +07:00
|
|
|
#include <linux/mmc/mmc.h>
|
|
|
|
#include <linux/mmc/sdio.h>
|
|
|
|
#include <linux/mmc/sh_mmcif.h>
|
2012-06-14 19:24:35 +07:00
|
|
|
#include <linux/mmc/slot-gpio.h>
|
2012-05-01 23:18:16 +07:00
|
|
|
#include <linux/mod_devicetable.h>
|
2012-12-12 21:38:14 +07:00
|
|
|
#include <linux/mutex.h>
|
2015-05-14 14:22:46 +07:00
|
|
|
#include <linux/of_device.h>
|
2010-11-24 17:05:22 +07:00
|
|
|
#include <linux/pagemap.h>
|
2010-11-24 17:05:18 +07:00
|
|
|
#include <linux/platform_device.h>
|
2012-03-13 07:02:15 +07:00
|
|
|
#include <linux/pm_qos.h>
|
2011-05-05 23:20:48 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2013-08-02 19:48:02 +07:00
|
|
|
#include <linux/sh_dma.h>
|
2011-04-16 01:30:47 +07:00
|
|
|
#include <linux/spinlock.h>
|
2011-07-04 02:15:51 +07:00
|
|
|
#include <linux/module.h>
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
#define DRIVER_NAME "sh_mmcif"
|
|
|
|
|
|
|
|
/* CE_CMD_SET */
|
|
|
|
#define CMD_MASK 0x3f000000
|
|
|
|
#define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22))
|
|
|
|
#define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22)) /* R1/R1b/R3/R4/R5 */
|
|
|
|
#define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22)) /* R2 */
|
|
|
|
#define CMD_SET_RBSY (1 << 21) /* R1b */
|
|
|
|
#define CMD_SET_CCSEN (1 << 20)
|
|
|
|
#define CMD_SET_WDAT (1 << 19) /* 1: on data, 0: no data */
|
|
|
|
#define CMD_SET_DWEN (1 << 18) /* 1: write, 0: read */
|
|
|
|
#define CMD_SET_CMLTE (1 << 17) /* 1: multi block trans, 0: single */
|
|
|
|
#define CMD_SET_CMD12EN (1 << 16) /* 1: CMD12 auto issue */
|
|
|
|
#define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14)) /* index check */
|
|
|
|
#define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14)) /* check bits check */
|
|
|
|
#define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14)) /* no check */
|
|
|
|
#define CMD_SET_CRC7C ((0 << 13) | (0 << 12)) /* CRC7 check*/
|
|
|
|
#define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12)) /* check bits check*/
|
|
|
|
#define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12)) /* internal CRC7 check*/
|
|
|
|
#define CMD_SET_CRC16C (1 << 10) /* 0: CRC16 check*/
|
|
|
|
#define CMD_SET_CRCSTE (1 << 8) /* 1: not receive CRC status */
|
|
|
|
#define CMD_SET_TBIT (1 << 7) /* 1: tran mission bit "Low" */
|
|
|
|
#define CMD_SET_OPDM (1 << 6) /* 1: open/drain */
|
|
|
|
#define CMD_SET_CCSH (1 << 5)
|
2012-12-12 21:38:08 +07:00
|
|
|
#define CMD_SET_DARS (1 << 2) /* Dual Data Rate */
|
2010-05-27 04:41:59 +07:00
|
|
|
#define CMD_SET_DATW_1 ((0 << 1) | (0 << 0)) /* 1bit */
|
|
|
|
#define CMD_SET_DATW_4 ((0 << 1) | (1 << 0)) /* 4bit */
|
|
|
|
#define CMD_SET_DATW_8 ((1 << 1) | (0 << 0)) /* 8bit */
|
|
|
|
|
|
|
|
/* CE_CMD_CTRL */
|
|
|
|
#define CMD_CTRL_BREAK (1 << 0)
|
|
|
|
|
|
|
|
/* CE_BLOCK_SET */
|
|
|
|
#define BLOCK_SIZE_MASK 0x0000ffff
|
|
|
|
|
|
|
|
/* CE_INT */
|
|
|
|
#define INT_CCSDE (1 << 29)
|
|
|
|
#define INT_CMD12DRE (1 << 26)
|
|
|
|
#define INT_CMD12RBE (1 << 25)
|
|
|
|
#define INT_CMD12CRE (1 << 24)
|
|
|
|
#define INT_DTRANE (1 << 23)
|
|
|
|
#define INT_BUFRE (1 << 22)
|
|
|
|
#define INT_BUFWEN (1 << 21)
|
|
|
|
#define INT_BUFREN (1 << 20)
|
|
|
|
#define INT_CCSRCV (1 << 19)
|
|
|
|
#define INT_RBSYE (1 << 17)
|
|
|
|
#define INT_CRSPE (1 << 16)
|
|
|
|
#define INT_CMDVIO (1 << 15)
|
|
|
|
#define INT_BUFVIO (1 << 14)
|
|
|
|
#define INT_WDATERR (1 << 11)
|
|
|
|
#define INT_RDATERR (1 << 10)
|
|
|
|
#define INT_RIDXERR (1 << 9)
|
|
|
|
#define INT_RSPERR (1 << 8)
|
|
|
|
#define INT_CCSTO (1 << 5)
|
|
|
|
#define INT_CRCSTO (1 << 4)
|
|
|
|
#define INT_WDATTO (1 << 3)
|
|
|
|
#define INT_RDATTO (1 << 2)
|
|
|
|
#define INT_RBSYTO (1 << 1)
|
|
|
|
#define INT_RSPTO (1 << 0)
|
|
|
|
#define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \
|
|
|
|
INT_RDATERR | INT_RIDXERR | INT_RSPERR | \
|
|
|
|
INT_CCSTO | INT_CRCSTO | INT_WDATTO | \
|
|
|
|
INT_RDATTO | INT_RBSYTO | INT_RSPTO)
|
|
|
|
|
2012-12-12 21:45:14 +07:00
|
|
|
#define INT_ALL (INT_RBSYE | INT_CRSPE | INT_BUFREN | \
|
|
|
|
INT_BUFWEN | INT_CMD12DRE | INT_BUFRE | \
|
|
|
|
INT_DTRANE | INT_CMD12RBE | INT_CMD12CRE)
|
|
|
|
|
2013-07-11 02:21:12 +07:00
|
|
|
#define INT_CCS (INT_CCSTO | INT_CCSRCV | INT_CCSDE)
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
/* CE_INT_MASK */
|
|
|
|
#define MASK_ALL 0x00000000
|
|
|
|
#define MASK_MCCSDE (1 << 29)
|
|
|
|
#define MASK_MCMD12DRE (1 << 26)
|
|
|
|
#define MASK_MCMD12RBE (1 << 25)
|
|
|
|
#define MASK_MCMD12CRE (1 << 24)
|
|
|
|
#define MASK_MDTRANE (1 << 23)
|
|
|
|
#define MASK_MBUFRE (1 << 22)
|
|
|
|
#define MASK_MBUFWEN (1 << 21)
|
|
|
|
#define MASK_MBUFREN (1 << 20)
|
|
|
|
#define MASK_MCCSRCV (1 << 19)
|
|
|
|
#define MASK_MRBSYE (1 << 17)
|
|
|
|
#define MASK_MCRSPE (1 << 16)
|
|
|
|
#define MASK_MCMDVIO (1 << 15)
|
|
|
|
#define MASK_MBUFVIO (1 << 14)
|
|
|
|
#define MASK_MWDATERR (1 << 11)
|
|
|
|
#define MASK_MRDATERR (1 << 10)
|
|
|
|
#define MASK_MRIDXERR (1 << 9)
|
|
|
|
#define MASK_MRSPERR (1 << 8)
|
|
|
|
#define MASK_MCCSTO (1 << 5)
|
|
|
|
#define MASK_MCRCSTO (1 << 4)
|
|
|
|
#define MASK_MWDATTO (1 << 3)
|
|
|
|
#define MASK_MRDATTO (1 << 2)
|
|
|
|
#define MASK_MRBSYTO (1 << 1)
|
|
|
|
#define MASK_MRSPTO (1 << 0)
|
|
|
|
|
2011-12-15 01:31:52 +07:00
|
|
|
#define MASK_START_CMD (MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR | \
|
|
|
|
MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR | \
|
2013-07-11 02:21:12 +07:00
|
|
|
MASK_MCRCSTO | MASK_MWDATTO | \
|
2011-12-15 01:31:52 +07:00
|
|
|
MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO)
|
|
|
|
|
2012-12-12 21:45:14 +07:00
|
|
|
#define MASK_CLEAN (INT_ERR_STS | MASK_MRBSYE | MASK_MCRSPE | \
|
|
|
|
MASK_MBUFREN | MASK_MBUFWEN | \
|
|
|
|
MASK_MCMD12DRE | MASK_MBUFRE | MASK_MDTRANE | \
|
|
|
|
MASK_MCMD12RBE | MASK_MCMD12CRE)
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
/* CE_HOST_STS1 */
|
|
|
|
#define STS1_CMDSEQ (1 << 31)
|
|
|
|
|
|
|
|
/* CE_HOST_STS2 */
|
|
|
|
#define STS2_CRCSTE (1 << 31)
|
|
|
|
#define STS2_CRC16E (1 << 30)
|
|
|
|
#define STS2_AC12CRCE (1 << 29)
|
|
|
|
#define STS2_RSPCRC7E (1 << 28)
|
|
|
|
#define STS2_CRCSTEBE (1 << 27)
|
|
|
|
#define STS2_RDATEBE (1 << 26)
|
|
|
|
#define STS2_AC12REBE (1 << 25)
|
|
|
|
#define STS2_RSPEBE (1 << 24)
|
|
|
|
#define STS2_AC12IDXE (1 << 23)
|
|
|
|
#define STS2_RSPIDXE (1 << 22)
|
|
|
|
#define STS2_CCSTO (1 << 15)
|
|
|
|
#define STS2_RDATTO (1 << 14)
|
|
|
|
#define STS2_DATBSYTO (1 << 13)
|
|
|
|
#define STS2_CRCSTTO (1 << 12)
|
|
|
|
#define STS2_AC12BSYTO (1 << 11)
|
|
|
|
#define STS2_RSPBSYTO (1 << 10)
|
|
|
|
#define STS2_AC12RSPTO (1 << 9)
|
|
|
|
#define STS2_RSPTO (1 << 8)
|
|
|
|
#define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \
|
|
|
|
STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE)
|
|
|
|
#define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \
|
|
|
|
STS2_DATBSYTO | STS2_CRCSTTO | \
|
|
|
|
STS2_AC12BSYTO | STS2_RSPBSYTO | \
|
|
|
|
STS2_AC12RSPTO | STS2_RSPTO)
|
|
|
|
|
|
|
|
#define CLKDEV_EMMC_DATA 52000000 /* 52MHz */
|
|
|
|
#define CLKDEV_MMC_DATA 20000000 /* 20MHz */
|
|
|
|
#define CLKDEV_INIT 400000 /* 400 KHz */
|
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
enum sh_mmcif_state {
|
2011-04-16 01:30:47 +07:00
|
|
|
STATE_IDLE,
|
|
|
|
STATE_REQUEST,
|
|
|
|
STATE_IOS,
|
2012-12-12 21:38:14 +07:00
|
|
|
STATE_TIMEOUT,
|
2011-04-16 01:30:47 +07:00
|
|
|
};
|
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
enum sh_mmcif_wait_for {
|
2011-12-26 03:07:52 +07:00
|
|
|
MMCIF_WAIT_FOR_REQUEST,
|
|
|
|
MMCIF_WAIT_FOR_CMD,
|
|
|
|
MMCIF_WAIT_FOR_MREAD,
|
|
|
|
MMCIF_WAIT_FOR_MWRITE,
|
|
|
|
MMCIF_WAIT_FOR_READ,
|
|
|
|
MMCIF_WAIT_FOR_WRITE,
|
|
|
|
MMCIF_WAIT_FOR_READ_END,
|
|
|
|
MMCIF_WAIT_FOR_WRITE_END,
|
|
|
|
MMCIF_WAIT_FOR_STOP,
|
|
|
|
};
|
|
|
|
|
2015-05-14 14:22:46 +07:00
|
|
|
/*
|
|
|
|
* difference for each SoC
|
|
|
|
*/
|
2010-05-27 04:41:59 +07:00
|
|
|
struct sh_mmcif_host {
|
|
|
|
struct mmc_host *mmc;
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_request *mrq;
|
2010-05-27 04:41:59 +07:00
|
|
|
struct platform_device *pd;
|
2015-04-23 15:15:08 +07:00
|
|
|
struct clk *clk;
|
2010-05-27 04:41:59 +07:00
|
|
|
int bus_width;
|
2012-12-12 21:38:08 +07:00
|
|
|
unsigned char timing;
|
2010-11-24 17:05:12 +07:00
|
|
|
bool sd_error;
|
2011-12-26 03:07:52 +07:00
|
|
|
bool dying;
|
2010-05-27 04:41:59 +07:00
|
|
|
long timeout;
|
|
|
|
void __iomem *addr;
|
2011-12-26 03:07:52 +07:00
|
|
|
u32 *pio_ptr;
|
2011-12-15 01:31:52 +07:00
|
|
|
spinlock_t lock; /* protect sh_mmcif_host::state */
|
2015-05-14 14:21:36 +07:00
|
|
|
enum sh_mmcif_state state;
|
|
|
|
enum sh_mmcif_wait_for wait_for;
|
2011-12-26 03:07:52 +07:00
|
|
|
struct delayed_work timeout_work;
|
|
|
|
size_t blocksize;
|
|
|
|
int sg_idx;
|
|
|
|
int sg_blkidx;
|
2011-05-05 23:20:48 +07:00
|
|
|
bool power;
|
2013-07-11 02:21:12 +07:00
|
|
|
bool ccs_enable; /* Command Completion Signal support */
|
2013-07-11 02:21:13 +07:00
|
|
|
bool clk_ctrl2_enable;
|
2012-12-12 21:38:14 +07:00
|
|
|
struct mutex thread_lock;
|
2015-05-14 14:22:46 +07:00
|
|
|
u32 clkdiv_map; /* see CE_CLK_CTRL::CLKDIV */
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2010-11-24 17:05:22 +07:00
|
|
|
/* DMA support */
|
|
|
|
struct dma_chan *chan_rx;
|
|
|
|
struct dma_chan *chan_tx;
|
|
|
|
struct completion dma_complete;
|
2011-02-10 22:09:50 +07:00
|
|
|
bool dma_active;
|
2010-11-24 17:05:22 +07:00
|
|
|
};
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
static const struct of_device_id sh_mmcif_of_match[] = {
|
2015-04-23 15:13:25 +07:00
|
|
|
{ .compatible = "renesas,sh-mmcif" },
|
|
|
|
{ }
|
|
|
|
};
|
2015-05-14 14:21:36 +07:00
|
|
|
MODULE_DEVICE_TABLE(of, sh_mmcif_of_match);
|
2015-04-23 15:13:25 +07:00
|
|
|
|
2015-05-14 14:21:18 +07:00
|
|
|
#define sh_mmcif_host_to_dev(host) (&host->pd->dev)
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
static inline void sh_mmcif_bitset(struct sh_mmcif_host *host,
|
|
|
|
unsigned int reg, u32 val)
|
|
|
|
{
|
2010-05-18 21:42:51 +07:00
|
|
|
writel(val | readl(host->addr + reg), host->addr + reg);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host,
|
|
|
|
unsigned int reg, u32 val)
|
|
|
|
{
|
2010-05-18 21:42:51 +07:00
|
|
|
writel(~val & readl(host->addr + reg), host->addr + reg);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
static void sh_mmcif_dma_complete(void *arg)
|
2010-11-24 17:05:22 +07:00
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = arg;
|
2012-12-12 21:38:14 +07:00
|
|
|
struct mmc_request *mrq = host->mrq;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-27 00:52:13 +07:00
|
|
|
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "Command completed\n");
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
if (WARN(!mrq || !mrq->data, "%s: NULL data in DMA completion!\n",
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_name(dev)))
|
2010-11-24 17:05:22 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
complete(&host->dma_complete);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
|
|
|
|
{
|
2011-12-27 00:52:13 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
struct scatterlist *sg = data->sg;
|
2010-11-24 17:05:22 +07:00
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
struct dma_chan *chan = host->chan_rx;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2010-11-24 17:05:22 +07:00
|
|
|
dma_cookie_t cookie = -EINVAL;
|
|
|
|
int ret;
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
|
2011-02-10 22:09:29 +07:00
|
|
|
DMA_FROM_DEVICE);
|
2010-11-24 17:05:22 +07:00
|
|
|
if (ret > 0) {
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = true;
|
2012-03-09 04:11:18 +07:00
|
|
|
desc = dmaengine_prep_slave_sg(chan, sg, ret,
|
2011-10-14 12:15:11 +07:00
|
|
|
DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc) {
|
2015-05-14 14:21:36 +07:00
|
|
|
desc->callback = sh_mmcif_dma_complete;
|
2010-11-24 17:05:22 +07:00
|
|
|
desc->callback_param = host;
|
2011-02-10 22:10:00 +07:00
|
|
|
cookie = dmaengine_submit(desc);
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
|
|
|
|
dma_async_issue_pending(chan);
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): mapped %d -> %d, cookie %d\n",
|
2011-12-27 00:52:13 +07:00
|
|
|
__func__, data->sg_len, ret, cookie);
|
2010-11-24 17:05:22 +07:00
|
|
|
|
|
|
|
if (!desc) {
|
|
|
|
/* DMA failed, fall back to PIO */
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = -EIO;
|
|
|
|
host->chan_rx = NULL;
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = false;
|
2010-11-24 17:05:22 +07:00
|
|
|
dma_release_channel(chan);
|
|
|
|
/* Free the Tx channel too */
|
|
|
|
chan = host->chan_tx;
|
|
|
|
if (chan) {
|
|
|
|
host->chan_tx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_warn(dev,
|
2010-11-24 17:05:22 +07:00
|
|
|
"DMA failed: %d, falling back to PIO\n", ret);
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
|
2011-12-27 00:52:13 +07:00
|
|
|
desc, cookie, data->sg_len);
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
|
|
|
|
{
|
2011-12-27 00:52:13 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
struct scatterlist *sg = data->sg;
|
2010-11-24 17:05:22 +07:00
|
|
|
struct dma_async_tx_descriptor *desc = NULL;
|
|
|
|
struct dma_chan *chan = host->chan_tx;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2010-11-24 17:05:22 +07:00
|
|
|
dma_cookie_t cookie = -EINVAL;
|
|
|
|
int ret;
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
|
2011-02-10 22:09:29 +07:00
|
|
|
DMA_TO_DEVICE);
|
2010-11-24 17:05:22 +07:00
|
|
|
if (ret > 0) {
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = true;
|
2012-03-09 04:11:18 +07:00
|
|
|
desc = dmaengine_prep_slave_sg(chan, sg, ret,
|
2011-10-14 12:15:11 +07:00
|
|
|
DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc) {
|
2015-05-14 14:21:36 +07:00
|
|
|
desc->callback = sh_mmcif_dma_complete;
|
2010-11-24 17:05:22 +07:00
|
|
|
desc->callback_param = host;
|
2011-02-10 22:10:00 +07:00
|
|
|
cookie = dmaengine_submit(desc);
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
|
|
|
|
dma_async_issue_pending(chan);
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): mapped %d -> %d, cookie %d\n",
|
2011-12-27 00:52:13 +07:00
|
|
|
__func__, data->sg_len, ret, cookie);
|
2010-11-24 17:05:22 +07:00
|
|
|
|
|
|
|
if (!desc) {
|
|
|
|
/* DMA failed, fall back to PIO */
|
|
|
|
if (ret >= 0)
|
|
|
|
ret = -EIO;
|
|
|
|
host->chan_tx = NULL;
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = false;
|
2010-11-24 17:05:22 +07:00
|
|
|
dma_release_channel(chan);
|
|
|
|
/* Free the Rx channel too */
|
|
|
|
chan = host->chan_rx;
|
|
|
|
if (chan) {
|
|
|
|
host->chan_rx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_warn(dev,
|
2010-11-24 17:05:22 +07:00
|
|
|
"DMA failed: %d, falling back to PIO\n", ret);
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): desc %p, cookie %d\n", __func__,
|
2010-11-24 17:05:22 +07:00
|
|
|
desc, cookie);
|
|
|
|
}
|
|
|
|
|
2013-10-30 18:34:51 +07:00
|
|
|
static struct dma_chan *
|
2015-11-16 23:08:41 +07:00
|
|
|
sh_mmcif_request_dma_pdata(struct sh_mmcif_host *host, uintptr_t slave_id)
|
2010-11-24 17:05:22 +07:00
|
|
|
{
|
2012-07-05 17:29:43 +07:00
|
|
|
dma_cap_mask_t mask;
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2013-10-30 18:34:51 +07:00
|
|
|
dma_cap_zero(mask);
|
|
|
|
dma_cap_set(DMA_SLAVE, mask);
|
2015-11-16 23:08:41 +07:00
|
|
|
if (slave_id <= 0)
|
|
|
|
return NULL;
|
2013-10-30 18:34:51 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
return dma_request_channel(mask, shdma_chan_filter, (void *)slave_id);
|
|
|
|
}
|
2013-10-30 18:34:51 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
static int sh_mmcif_dma_slave_config(struct sh_mmcif_host *host,
|
|
|
|
struct dma_chan *chan,
|
|
|
|
enum dma_transfer_direction direction)
|
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
struct dma_slave_config cfg = { 0, };
|
2013-10-30 18:34:51 +07:00
|
|
|
|
|
|
|
res = platform_get_resource(host->pd, IORESOURCE_MEM, 0);
|
|
|
|
cfg.direction = direction;
|
2014-07-16 05:45:12 +07:00
|
|
|
|
2014-07-16 05:45:13 +07:00
|
|
|
if (direction == DMA_DEV_TO_MEM) {
|
2014-07-16 05:45:12 +07:00
|
|
|
cfg.src_addr = res->start + MMCIF_CE_DATA;
|
2014-07-16 05:45:13 +07:00
|
|
|
cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
|
|
|
} else {
|
2014-07-16 05:45:12 +07:00
|
|
|
cfg.dst_addr = res->start + MMCIF_CE_DATA;
|
2014-07-16 05:45:13 +07:00
|
|
|
cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
|
|
|
}
|
2014-07-16 05:45:12 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
return dmaengine_slave_config(chan, &cfg);
|
2013-10-30 18:34:51 +07:00
|
|
|
}
|
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
static void sh_mmcif_request_dma(struct sh_mmcif_host *host)
|
2013-10-30 18:34:51 +07:00
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = false;
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
/* We can only either use DMA for both Tx and Rx or not use it at all */
|
|
|
|
if (IS_ENABLED(CONFIG_SUPERH) && dev->platform_data) {
|
|
|
|
struct sh_mmcif_plat_data *pdata = dev->platform_data;
|
|
|
|
|
|
|
|
host->chan_tx = sh_mmcif_request_dma_pdata(host,
|
|
|
|
pdata->slave_id_tx);
|
|
|
|
host->chan_rx = sh_mmcif_request_dma_pdata(host,
|
|
|
|
pdata->slave_id_rx);
|
|
|
|
} else {
|
|
|
|
host->chan_tx = dma_request_slave_channel(dev, "tx");
|
2016-02-10 21:07:01 +07:00
|
|
|
host->chan_rx = dma_request_slave_channel(dev, "rx");
|
2013-06-24 19:36:34 +07:00
|
|
|
}
|
2015-11-16 23:08:41 +07:00
|
|
|
dev_dbg(dev, "%s: got channel TX %p RX %p\n", __func__, host->chan_tx,
|
|
|
|
host->chan_rx);
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
if (!host->chan_tx || !host->chan_rx ||
|
|
|
|
sh_mmcif_dma_slave_config(host, host->chan_tx, DMA_MEM_TO_DEV) ||
|
|
|
|
sh_mmcif_dma_slave_config(host, host->chan_rx, DMA_DEV_TO_MEM))
|
|
|
|
goto error;
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2015-11-16 23:08:41 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (host->chan_tx)
|
2013-10-30 18:34:51 +07:00
|
|
|
dma_release_channel(host->chan_tx);
|
2015-11-16 23:08:41 +07:00
|
|
|
if (host->chan_rx)
|
|
|
|
dma_release_channel(host->chan_rx);
|
|
|
|
host->chan_tx = host->chan_rx = NULL;
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
|
|
|
|
{
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
|
|
|
|
/* Descriptors are freed automatically */
|
|
|
|
if (host->chan_tx) {
|
|
|
|
struct dma_chan *chan = host->chan_tx;
|
|
|
|
host->chan_tx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
if (host->chan_rx) {
|
|
|
|
struct dma_chan *chan = host->chan_rx;
|
|
|
|
host->chan_rx = NULL;
|
|
|
|
dma_release_channel(chan);
|
|
|
|
}
|
|
|
|
|
2011-02-10 22:09:50 +07:00
|
|
|
host->dma_active = false;
|
2010-11-24 17:05:22 +07:00
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
|
|
|
struct sh_mmcif_plat_data *p = dev->platform_data;
|
2012-05-01 23:18:16 +07:00
|
|
|
bool sup_pclk = p ? p->sup_pclk : false;
|
2015-04-23 15:15:08 +07:00
|
|
|
unsigned int current_clk = clk_get_rate(host->clk);
|
2015-05-14 14:22:46 +07:00
|
|
|
unsigned int clkdiv;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
|
|
|
|
|
|
|
|
if (!clk)
|
|
|
|
return;
|
|
|
|
|
2015-05-14 14:22:46 +07:00
|
|
|
if (host->clkdiv_map) {
|
|
|
|
unsigned int freq, best_freq, myclk, div, diff_min, diff;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
clkdiv = 0;
|
|
|
|
diff_min = ~0;
|
|
|
|
best_freq = 0;
|
|
|
|
for (i = 31; i >= 0; i--) {
|
|
|
|
if (!((1 << i) & host->clkdiv_map))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clk = parent_freq / div
|
|
|
|
* -> parent_freq = clk x div
|
|
|
|
*/
|
|
|
|
|
|
|
|
div = 1 << (i + 1);
|
|
|
|
freq = clk_round_rate(host->clk, clk * div);
|
|
|
|
myclk = freq / div;
|
|
|
|
diff = (myclk > clk) ? myclk - clk : clk - myclk;
|
|
|
|
|
|
|
|
if (diff <= diff_min) {
|
|
|
|
best_freq = freq;
|
|
|
|
clkdiv = i;
|
|
|
|
diff_min = diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(dev, "clk %u/%u (%u, 0x%x)\n",
|
|
|
|
(best_freq / (1 << (clkdiv + 1))), clk,
|
|
|
|
best_freq, clkdiv);
|
|
|
|
|
|
|
|
clk_set_rate(host->clk, best_freq);
|
|
|
|
clkdiv = clkdiv << 16;
|
|
|
|
} else if (sup_pclk && clk == current_clk) {
|
|
|
|
clkdiv = CLK_SUP_PCLK;
|
|
|
|
} else {
|
|
|
|
clkdiv = (fls(DIV_ROUND_UP(current_clk, clk) - 1) - 1) << 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & clkdiv);
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
2010-05-18 21:42:51 +07:00
|
|
|
tmp = 0x010f0000 & sh_mmcif_readl(host->addr, MMCIF_CE_CLK_CTRL);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_ON);
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_OFF);
|
2013-07-11 02:21:12 +07:00
|
|
|
if (host->ccs_enable)
|
|
|
|
tmp |= SCCSTO_29;
|
2013-07-11 02:21:13 +07:00
|
|
|
if (host->clk_ctrl2_enable)
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_CLK_CTRL2, 0x0F0F0000);
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, tmp |
|
2013-07-11 02:21:12 +07:00
|
|
|
SRSPTO_256 | SRBSYTO_29 | SRWDTO_29);
|
2010-05-27 04:41:59 +07:00
|
|
|
/* byte swap on */
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2010-05-27 04:41:59 +07:00
|
|
|
u32 state1, state2;
|
2011-12-15 01:31:52 +07:00
|
|
|
int ret, timeout;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2010-11-24 17:05:12 +07:00
|
|
|
host->sd_error = false;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2010-05-18 21:42:51 +07:00
|
|
|
state1 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1);
|
|
|
|
state2 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS2);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "ERR HOST_STS1 = %08x\n", state1);
|
|
|
|
dev_dbg(dev, "ERR HOST_STS2 = %08x\n", state2);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
if (state1 & STS1_CMDSEQ) {
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK);
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK);
|
2016-06-21 20:12:50 +07:00
|
|
|
for (timeout = 10000; timeout; timeout--) {
|
2010-05-18 21:42:51 +07:00
|
|
|
if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1)
|
2011-12-15 01:31:52 +07:00
|
|
|
& STS1_CMDSEQ))
|
2010-05-27 04:41:59 +07:00
|
|
|
break;
|
|
|
|
mdelay(1);
|
|
|
|
}
|
2011-12-15 01:31:52 +07:00
|
|
|
if (!timeout) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev,
|
2011-12-15 01:31:52 +07:00
|
|
|
"Forced end of command sequence timeout err\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_sync_reset(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "Forced end of command sequence\n");
|
2010-05-27 04:41:59 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state2 & STS2_CRC_ERR) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, " CRC error: state %u, wait %u\n",
|
2012-12-12 21:38:18 +07:00
|
|
|
host->state, host->wait_for);
|
2010-05-27 04:41:59 +07:00
|
|
|
ret = -EIO;
|
|
|
|
} else if (state2 & STS2_TIMEOUT_ERR) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, " Timeout: state %u, wait %u\n",
|
2012-12-12 21:38:18 +07:00
|
|
|
host->state, host->wait_for);
|
2010-05-27 04:41:59 +07:00
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
} else {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, " End/Index error: state %u, wait %u\n",
|
2012-12-12 21:38:18 +07:00
|
|
|
host->state, host->wait_for);
|
2010-05-27 04:41:59 +07:00
|
|
|
ret = -EIO;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static bool sh_mmcif_next_block(struct sh_mmcif_host *host, u32 *p)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
|
|
|
|
host->sg_blkidx += host->blocksize;
|
|
|
|
|
|
|
|
/* data->sg->length must be a multiple of host->blocksize? */
|
|
|
|
BUG_ON(host->sg_blkidx > data->sg->length);
|
|
|
|
|
|
|
|
if (host->sg_blkidx == data->sg->length) {
|
|
|
|
host->sg_blkidx = 0;
|
|
|
|
if (++host->sg_idx < data->sg_len)
|
|
|
|
host->pio_ptr = sg_virt(++data->sg);
|
|
|
|
} else {
|
|
|
|
host->pio_ptr = p;
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:38:13 +07:00
|
|
|
return host->sg_idx != data->sg_len;
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_single_read(struct sh_mmcif_host *host,
|
|
|
|
struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
|
|
|
|
BLOCK_SIZE_MASK) + 3;
|
|
|
|
|
|
|
|
host->wait_for = MMCIF_WAIT_FOR_READ;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
/* buf read enable */
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool sh_mmcif_read_block(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
u32 *p = sg_virt(data->sg);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (host->sd_error) {
|
|
|
|
data->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, data->error);
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < host->blocksize / 4; i++)
|
2010-05-18 21:42:51 +07:00
|
|
|
*p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
/* buffer read end */
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_READ_END;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
return true;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static void sh_mmcif_multi_read(struct sh_mmcif_host *host,
|
|
|
|
struct mmc_request *mrq)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
|
|
|
struct mmc_data *data = mrq->data;
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
if (!data->sg_len || !data->sg->length)
|
|
|
|
return;
|
|
|
|
|
|
|
|
host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
|
|
|
|
BLOCK_SIZE_MASK;
|
|
|
|
|
|
|
|
host->wait_for = MMCIF_WAIT_FOR_MREAD;
|
|
|
|
host->sg_idx = 0;
|
|
|
|
host->sg_blkidx = 0;
|
|
|
|
host->pio_ptr = sg_virt(data->sg);
|
2012-12-12 21:38:11 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sh_mmcif_mread_block(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
u32 *p = host->pio_ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (host->sd_error) {
|
|
|
|
data->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, data->error);
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
BUG_ON(!data->sg->length);
|
|
|
|
|
|
|
|
for (i = 0; i < host->blocksize / 4; i++)
|
|
|
|
*p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
|
|
|
|
|
|
|
|
if (!sh_mmcif_next_block(host, p))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
|
|
|
|
|
|
|
|
return true;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static void sh_mmcif_single_write(struct sh_mmcif_host *host,
|
2010-05-27 04:41:59 +07:00
|
|
|
struct mmc_request *mrq)
|
|
|
|
{
|
2011-12-26 03:07:52 +07:00
|
|
|
host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
|
|
|
|
BLOCK_SIZE_MASK) + 3;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_WRITE;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
/* buf write enable */
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sh_mmcif_write_block(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
u32 *p = sg_virt(data->sg);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (host->sd_error) {
|
|
|
|
data->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, data->error);
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < host->blocksize / 4; i++)
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
/* buffer write end */
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_WRITE_END;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
return true;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static void sh_mmcif_multi_write(struct sh_mmcif_host *host,
|
|
|
|
struct mmc_request *mrq)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
|
|
|
struct mmc_data *data = mrq->data;
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
if (!data->sg_len || !data->sg->length)
|
|
|
|
return;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
|
|
|
|
BLOCK_SIZE_MASK;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_MWRITE;
|
|
|
|
host->sg_idx = 0;
|
|
|
|
host->sg_blkidx = 0;
|
|
|
|
host->pio_ptr = sg_virt(data->sg);
|
2012-12-12 21:38:11 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
|
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static bool sh_mmcif_mwrite_block(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
|
|
|
u32 *p = host->pio_ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (host->sd_error) {
|
|
|
|
data->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, data->error);
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
BUG_ON(!data->sg->length);
|
|
|
|
|
|
|
|
for (i = 0; i < host->blocksize / 4; i++)
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
|
|
|
|
|
|
|
|
if (!sh_mmcif_next_block(host, p))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
|
|
|
|
|
|
|
|
return true;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_get_response(struct sh_mmcif_host *host,
|
|
|
|
struct mmc_command *cmd)
|
|
|
|
{
|
|
|
|
if (cmd->flags & MMC_RSP_136) {
|
2010-05-18 21:42:51 +07:00
|
|
|
cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP3);
|
|
|
|
cmd->resp[1] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP2);
|
|
|
|
cmd->resp[2] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP1);
|
|
|
|
cmd->resp[3] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
|
2010-05-27 04:41:59 +07:00
|
|
|
} else
|
2010-05-18 21:42:51 +07:00
|
|
|
cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
|
|
|
|
struct mmc_command *cmd)
|
|
|
|
{
|
2010-05-18 21:42:51 +07:00
|
|
|
cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP_CMD12);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
|
2011-12-27 00:52:13 +07:00
|
|
|
struct mmc_request *mrq)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-27 00:52:13 +07:00
|
|
|
struct mmc_data *data = mrq->data;
|
|
|
|
struct mmc_command *cmd = mrq->cmd;
|
|
|
|
u32 opc = cmd->opcode;
|
2010-05-27 04:41:59 +07:00
|
|
|
u32 tmp = 0;
|
|
|
|
|
|
|
|
/* Response Type check */
|
|
|
|
switch (mmc_resp_type(cmd)) {
|
|
|
|
case MMC_RSP_NONE:
|
|
|
|
tmp |= CMD_SET_RTYP_NO;
|
|
|
|
break;
|
|
|
|
case MMC_RSP_R1:
|
|
|
|
case MMC_RSP_R3:
|
|
|
|
tmp |= CMD_SET_RTYP_6B;
|
|
|
|
break;
|
2016-06-21 20:12:48 +07:00
|
|
|
case MMC_RSP_R1B:
|
|
|
|
tmp |= CMD_SET_RBSY | CMD_SET_RTYP_6B;
|
|
|
|
break;
|
2010-05-27 04:41:59 +07:00
|
|
|
case MMC_RSP_R2:
|
|
|
|
tmp |= CMD_SET_RTYP_17B;
|
|
|
|
break;
|
|
|
|
default:
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, "Unsupported response type.\n");
|
2010-05-27 04:41:59 +07:00
|
|
|
break;
|
|
|
|
}
|
2016-06-21 20:12:48 +07:00
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
/* WDAT / DATW */
|
2011-12-27 00:52:13 +07:00
|
|
|
if (data) {
|
2010-05-27 04:41:59 +07:00
|
|
|
tmp |= CMD_SET_WDAT;
|
|
|
|
switch (host->bus_width) {
|
|
|
|
case MMC_BUS_WIDTH_1:
|
|
|
|
tmp |= CMD_SET_DATW_1;
|
|
|
|
break;
|
|
|
|
case MMC_BUS_WIDTH_4:
|
|
|
|
tmp |= CMD_SET_DATW_4;
|
|
|
|
break;
|
|
|
|
case MMC_BUS_WIDTH_8:
|
|
|
|
tmp |= CMD_SET_DATW_8;
|
|
|
|
break;
|
|
|
|
default:
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, "Unsupported bus width.\n");
|
2010-05-27 04:41:59 +07:00
|
|
|
break;
|
|
|
|
}
|
2012-12-12 21:38:08 +07:00
|
|
|
switch (host->timing) {
|
2014-03-14 19:12:33 +07:00
|
|
|
case MMC_TIMING_MMC_DDR52:
|
2012-12-12 21:38:08 +07:00
|
|
|
/*
|
|
|
|
* MMC core will only set this timing, if the host
|
2014-03-14 19:12:33 +07:00
|
|
|
* advertises the MMC_CAP_1_8V_DDR/MMC_CAP_1_2V_DDR
|
|
|
|
* capability. MMCIF implementations with this
|
|
|
|
* capability, e.g. sh73a0, will have to set it
|
|
|
|
* in their platform data.
|
2012-12-12 21:38:08 +07:00
|
|
|
*/
|
|
|
|
tmp |= CMD_SET_DARS;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
/* DWEN */
|
|
|
|
if (opc == MMC_WRITE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK)
|
|
|
|
tmp |= CMD_SET_DWEN;
|
|
|
|
/* CMLTE/CMD12EN */
|
|
|
|
if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) {
|
|
|
|
tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
|
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET,
|
2011-12-27 00:52:13 +07:00
|
|
|
data->blocks << 16);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
/* RIDXC[1:0] check bits */
|
|
|
|
if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID ||
|
|
|
|
opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
|
|
|
|
tmp |= CMD_SET_RIDXC_BITS;
|
|
|
|
/* RCRC7C[1:0] check bits */
|
|
|
|
if (opc == MMC_SEND_OP_COND)
|
|
|
|
tmp |= CMD_SET_CRC7C_BITS;
|
|
|
|
/* RCRC7C[1:0] internal CRC7 */
|
|
|
|
if (opc == MMC_ALL_SEND_CID ||
|
|
|
|
opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
|
|
|
|
tmp |= CMD_SET_CRC7C_INTERNAL;
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
return (opc << 24) | tmp;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2010-11-24 17:05:18 +07:00
|
|
|
static int sh_mmcif_data_trans(struct sh_mmcif_host *host,
|
2011-12-26 03:07:52 +07:00
|
|
|
struct mmc_request *mrq, u32 opc)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
switch (opc) {
|
|
|
|
case MMC_READ_MULTIPLE_BLOCK:
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_multi_read(host, mrq);
|
|
|
|
return 0;
|
2010-05-27 04:41:59 +07:00
|
|
|
case MMC_WRITE_MULTIPLE_BLOCK:
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_multi_write(host, mrq);
|
|
|
|
return 0;
|
2010-05-27 04:41:59 +07:00
|
|
|
case MMC_WRITE_BLOCK:
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_single_write(host, mrq);
|
|
|
|
return 0;
|
2010-05-27 04:41:59 +07:00
|
|
|
case MMC_READ_SINGLE_BLOCK:
|
|
|
|
case MMC_SEND_EXT_CSD:
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_single_read(host, mrq);
|
|
|
|
return 0;
|
2010-05-27 04:41:59 +07:00
|
|
|
default:
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, "Unsupported CMD%d\n", opc);
|
2011-12-15 01:31:52 +07:00
|
|
|
return -EINVAL;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
|
2011-12-15 01:31:52 +07:00
|
|
|
struct mmc_request *mrq)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
2011-12-15 01:31:52 +07:00
|
|
|
struct mmc_command *cmd = mrq->cmd;
|
2018-01-17 20:41:57 +07:00
|
|
|
u32 opc;
|
2016-06-21 20:12:48 +07:00
|
|
|
u32 mask = 0;
|
2015-02-15 21:46:46 +07:00
|
|
|
unsigned long flags;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2016-06-21 20:12:48 +07:00
|
|
|
if (cmd->flags & MMC_RSP_BUSY)
|
2011-12-15 01:31:52 +07:00
|
|
|
mask = MASK_START_CMD | MASK_MRBSYE;
|
2016-06-21 20:12:48 +07:00
|
|
|
else
|
2011-12-15 01:31:52 +07:00
|
|
|
mask = MASK_START_CMD | MASK_MCRSPE;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2013-07-11 02:21:12 +07:00
|
|
|
if (host->ccs_enable)
|
|
|
|
mask |= MASK_MCCSTO;
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
if (mrq->data) {
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0);
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET,
|
|
|
|
mrq->data->blksz);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
2011-12-27 00:52:13 +07:00
|
|
|
opc = sh_mmcif_set_cmd(host, mrq);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2013-07-11 02:21:12 +07:00
|
|
|
if (host->ccs_enable)
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0);
|
|
|
|
else
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0 | INT_CCS);
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask);
|
2010-05-27 04:41:59 +07:00
|
|
|
/* set arg */
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg);
|
2010-05-27 04:41:59 +07:00
|
|
|
/* set cmd */
|
2015-02-15 21:46:46 +07:00
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
2010-05-18 21:42:51 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_CMD;
|
|
|
|
schedule_delayed_work(&host->timeout_work, host->timeout);
|
2015-02-15 21:46:46 +07:00
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
|
2011-12-15 01:31:52 +07:00
|
|
|
struct mmc_request *mrq)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
switch (mrq->cmd->opcode) {
|
|
|
|
case MMC_READ_MULTIPLE_BLOCK:
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
|
2011-12-27 00:52:13 +07:00
|
|
|
break;
|
|
|
|
case MMC_WRITE_MULTIPLE_BLOCK:
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
|
2011-12-27 00:52:13 +07:00
|
|
|
break;
|
|
|
|
default:
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, "unsupported stop cmd\n");
|
2011-12-27 00:52:13 +07:00
|
|
|
mrq->stop->error = sh_mmcif_error_manage(host);
|
2010-05-27 04:41:59 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->wait_for = MMCIF_WAIT_FOR_STOP;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = mmc_priv(mmc);
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-04-16 01:30:47 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
if (host->state != STATE_IDLE) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s() rejected, state %u\n",
|
|
|
|
__func__, host->state);
|
2011-04-16 01:30:47 +07:00
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
|
|
mrq->cmd->error = -EAGAIN;
|
|
|
|
mmc_request_done(mmc, mrq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->state = STATE_REQUEST;
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->mrq = mrq;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_start_cmd(host, mrq);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2015-04-23 15:16:04 +07:00
|
|
|
static void sh_mmcif_clk_setup(struct sh_mmcif_host *host)
|
2012-04-19 23:02:50 +07:00
|
|
|
{
|
2015-05-14 14:22:46 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
|
|
|
|
|
|
|
if (host->mmc->f_max) {
|
|
|
|
unsigned int f_max, f_min = 0, f_min_old;
|
|
|
|
|
|
|
|
f_max = host->mmc->f_max;
|
|
|
|
for (f_min_old = f_max; f_min_old > 2;) {
|
|
|
|
f_min = clk_round_rate(host->clk, f_min_old / 2);
|
|
|
|
if (f_min == f_min_old)
|
|
|
|
break;
|
|
|
|
f_min_old = f_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This driver assumes this SoC is R-Car Gen2 or later
|
|
|
|
*/
|
|
|
|
host->clkdiv_map = 0x3ff;
|
|
|
|
|
|
|
|
host->mmc->f_max = f_max / (1 << ffs(host->clkdiv_map));
|
|
|
|
host->mmc->f_min = f_min / (1 << fls(host->clkdiv_map));
|
|
|
|
} else {
|
|
|
|
unsigned int clk = clk_get_rate(host->clk);
|
|
|
|
|
|
|
|
host->mmc->f_max = clk / 2;
|
|
|
|
host->mmc->f_min = clk / 512;
|
|
|
|
}
|
2012-04-19 23:02:50 +07:00
|
|
|
|
2015-05-14 14:22:46 +07:00
|
|
|
dev_dbg(dev, "clk max/min = %d/%d\n",
|
|
|
|
host->mmc->f_max, host->mmc->f_min);
|
2012-04-19 23:02:50 +07:00
|
|
|
}
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
|
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = mmc_priv(mmc);
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-04-16 01:30:47 +07:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
if (host->state != STATE_IDLE) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s() rejected, state %u\n",
|
|
|
|
__func__, host->state);
|
2011-04-16 01:30:47 +07:00
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
host->state = STATE_IOS;
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2016-02-11 19:59:54 +07:00
|
|
|
switch (ios->power_mode) {
|
|
|
|
case MMC_POWER_UP:
|
2016-02-11 19:59:55 +07:00
|
|
|
if (!IS_ERR(mmc->supply.vmmc))
|
|
|
|
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
|
2016-02-11 19:59:54 +07:00
|
|
|
if (!host->power) {
|
|
|
|
clk_prepare_enable(host->clk);
|
|
|
|
pm_runtime_get_sync(dev);
|
|
|
|
sh_mmcif_sync_reset(host);
|
2015-11-16 23:08:41 +07:00
|
|
|
sh_mmcif_request_dma(host);
|
2016-02-11 19:59:54 +07:00
|
|
|
host->power = true;
|
2011-05-05 23:20:48 +07:00
|
|
|
}
|
2016-02-11 19:59:54 +07:00
|
|
|
break;
|
|
|
|
case MMC_POWER_OFF:
|
2016-02-11 19:59:55 +07:00
|
|
|
if (!IS_ERR(mmc->supply.vmmc))
|
|
|
|
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
|
2011-05-26 20:33:30 +07:00
|
|
|
if (host->power) {
|
2016-02-11 19:59:54 +07:00
|
|
|
sh_mmcif_clock_control(host, 0);
|
|
|
|
sh_mmcif_release_dma(host);
|
|
|
|
pm_runtime_put(dev);
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_disable_unprepare(host->clk);
|
2011-05-26 20:33:30 +07:00
|
|
|
host->power = false;
|
|
|
|
}
|
2016-02-11 19:59:54 +07:00
|
|
|
break;
|
|
|
|
case MMC_POWER_ON:
|
2010-05-27 04:41:59 +07:00
|
|
|
sh_mmcif_clock_control(host, ios->clock);
|
2016-02-11 19:59:54 +07:00
|
|
|
break;
|
2011-05-26 20:33:30 +07:00
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2012-12-12 21:38:08 +07:00
|
|
|
host->timing = ios->timing;
|
2010-05-27 04:41:59 +07:00
|
|
|
host->bus_width = ios->bus_width;
|
2011-04-16 01:30:47 +07:00
|
|
|
host->state = STATE_IDLE;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:59:34 +07:00
|
|
|
static const struct mmc_host_ops sh_mmcif_ops = {
|
2010-05-27 04:41:59 +07:00
|
|
|
.request = sh_mmcif_request,
|
|
|
|
.set_ios = sh_mmcif_set_ios,
|
2016-12-30 19:47:17 +07:00
|
|
|
.get_cd = mmc_gpio_get_cd,
|
2010-05-27 04:41:59 +07:00
|
|
|
};
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
static bool sh_mmcif_end_cmd(struct sh_mmcif_host *host)
|
|
|
|
{
|
|
|
|
struct mmc_command *cmd = host->mrq->cmd;
|
2011-12-27 00:52:13 +07:00
|
|
|
struct mmc_data *data = host->mrq->data;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
long time;
|
|
|
|
|
|
|
|
if (host->sd_error) {
|
|
|
|
switch (cmd->opcode) {
|
|
|
|
case MMC_ALL_SEND_CID:
|
|
|
|
case MMC_SELECT_CARD:
|
|
|
|
case MMC_APP_CMD:
|
|
|
|
cmd->error = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cmd->error = sh_mmcif_error_manage(host);
|
|
|
|
break;
|
|
|
|
}
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "CMD%d error %d\n",
|
2012-12-12 21:38:18 +07:00
|
|
|
cmd->opcode, cmd->error);
|
2012-12-12 21:38:15 +07:00
|
|
|
host->sd_error = false;
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(cmd->flags & MMC_RSP_PRESENT)) {
|
|
|
|
cmd->error = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sh_mmcif_get_response(host, cmd);
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
if (!data)
|
2011-12-26 03:07:52 +07:00
|
|
|
return false;
|
|
|
|
|
2012-12-12 21:38:16 +07:00
|
|
|
/*
|
|
|
|
* Completion can be signalled from DMA callback and error, so, have to
|
|
|
|
* reset here, before setting .dma_active
|
|
|
|
*/
|
|
|
|
init_completion(&host->dma_complete);
|
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
if (data->flags & MMC_DATA_READ) {
|
2011-12-26 03:07:52 +07:00
|
|
|
if (host->chan_rx)
|
|
|
|
sh_mmcif_start_dma_rx(host);
|
|
|
|
} else {
|
|
|
|
if (host->chan_tx)
|
|
|
|
sh_mmcif_start_dma_tx(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!host->dma_active) {
|
2011-12-27 00:52:13 +07:00
|
|
|
data->error = sh_mmcif_data_trans(host, host->mrq, cmd->opcode);
|
2012-12-12 21:38:13 +07:00
|
|
|
return !data->error;
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Running in the IRQ thread, can sleep */
|
|
|
|
time = wait_for_completion_interruptible_timeout(&host->dma_complete,
|
|
|
|
host->timeout);
|
2012-12-12 21:38:12 +07:00
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
dma_unmap_sg(host->chan_rx->device->dev,
|
|
|
|
data->sg, data->sg_len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
else
|
|
|
|
dma_unmap_sg(host->chan_tx->device->dev,
|
|
|
|
data->sg, data->sg_len,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
if (host->sd_error) {
|
|
|
|
dev_err(host->mmc->parent,
|
|
|
|
"Error IRQ while waiting for DMA completion!\n");
|
|
|
|
/* Woken up by an error IRQ: abort DMA */
|
2011-12-27 00:52:13 +07:00
|
|
|
data->error = sh_mmcif_error_manage(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
} else if (!time) {
|
2012-12-12 21:38:18 +07:00
|
|
|
dev_err(host->mmc->parent, "DMA timeout!\n");
|
2011-12-27 00:52:13 +07:00
|
|
|
data->error = -ETIMEDOUT;
|
2011-12-26 03:07:52 +07:00
|
|
|
} else if (time < 0) {
|
2012-12-12 21:38:18 +07:00
|
|
|
dev_err(host->mmc->parent,
|
|
|
|
"wait_for_completion_...() error %ld!\n", time);
|
2011-12-27 00:52:13 +07:00
|
|
|
data->error = time;
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
|
|
|
|
BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
|
|
|
|
host->dma_active = false;
|
|
|
|
|
2012-12-12 21:38:12 +07:00
|
|
|
if (data->error) {
|
2011-12-27 00:52:13 +07:00
|
|
|
data->bytes_xfered = 0;
|
2012-12-12 21:38:12 +07:00
|
|
|
/* Abort DMA */
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
dmaengine_terminate_all(host->chan_rx);
|
|
|
|
else
|
|
|
|
dmaengine_terminate_all(host->chan_tx);
|
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t sh_mmcif_irqt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = dev_id;
|
2012-12-12 21:38:14 +07:00
|
|
|
struct mmc_request *mrq;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2012-12-12 21:38:11 +07:00
|
|
|
bool wait = false;
|
2015-02-15 21:46:46 +07:00
|
|
|
unsigned long flags;
|
|
|
|
int wait_work;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
wait_work = host->wait_for;
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
cancel_delayed_work_sync(&host->timeout_work);
|
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_lock(&host->thread_lock);
|
|
|
|
|
|
|
|
mrq = host->mrq;
|
|
|
|
if (!mrq) {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "IRQ thread state %u, wait %u: NULL mrq!\n",
|
2012-12-12 21:38:14 +07:00
|
|
|
host->state, host->wait_for);
|
|
|
|
mutex_unlock(&host->thread_lock);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
/*
|
|
|
|
* All handlers return true, if processing continues, and false, if the
|
|
|
|
* request has to be completed - successfully or not
|
|
|
|
*/
|
2015-02-15 21:46:46 +07:00
|
|
|
switch (wait_work) {
|
2011-12-26 03:07:52 +07:00
|
|
|
case MMCIF_WAIT_FOR_REQUEST:
|
|
|
|
/* We're too late, the timeout has already kicked in */
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_unlock(&host->thread_lock);
|
2011-12-26 03:07:52 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
case MMCIF_WAIT_FOR_CMD:
|
2012-12-12 21:38:11 +07:00
|
|
|
/* Wait for data? */
|
|
|
|
wait = sh_mmcif_end_cmd(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_MREAD:
|
2012-12-12 21:38:11 +07:00
|
|
|
/* Wait for more data? */
|
|
|
|
wait = sh_mmcif_mread_block(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_READ:
|
2012-12-12 21:38:11 +07:00
|
|
|
/* Wait for data end? */
|
|
|
|
wait = sh_mmcif_read_block(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_MWRITE:
|
2012-12-12 21:38:11 +07:00
|
|
|
/* Wait data to write? */
|
|
|
|
wait = sh_mmcif_mwrite_block(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_WRITE:
|
2012-12-12 21:38:11 +07:00
|
|
|
/* Wait for data end? */
|
|
|
|
wait = sh_mmcif_write_block(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_STOP:
|
|
|
|
if (host->sd_error) {
|
|
|
|
mrq->stop->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, mrq->stop->error);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sh_mmcif_get_cmd12response(host, mrq->stop);
|
|
|
|
mrq->stop->error = 0;
|
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_READ_END:
|
|
|
|
case MMCIF_WAIT_FOR_WRITE_END:
|
2012-12-12 21:38:18 +07:00
|
|
|
if (host->sd_error) {
|
2012-08-22 13:49:47 +07:00
|
|
|
mrq->data->error = sh_mmcif_error_manage(host);
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "%s(): %d\n", __func__, mrq->data->error);
|
2012-12-12 21:38:18 +07:00
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:38:11 +07:00
|
|
|
if (wait) {
|
|
|
|
schedule_delayed_work(&host->timeout_work, host->timeout);
|
|
|
|
/* Wait for more data */
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_unlock(&host->thread_lock);
|
2012-12-12 21:38:11 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
if (host->wait_for != MMCIF_WAIT_FOR_STOP) {
|
2012-08-22 13:49:47 +07:00
|
|
|
struct mmc_data *data = mrq->data;
|
2011-12-27 00:52:13 +07:00
|
|
|
if (!mrq->cmd->error && data && !data->error)
|
|
|
|
data->bytes_xfered =
|
|
|
|
data->blocks * data->blksz;
|
2011-12-26 03:07:52 +07:00
|
|
|
|
2011-12-27 00:52:13 +07:00
|
|
|
if (mrq->stop && !mrq->cmd->error && (!data || !data->error)) {
|
2011-12-26 03:07:52 +07:00
|
|
|
sh_mmcif_stop_cmd(host, mrq);
|
2012-12-12 21:38:11 +07:00
|
|
|
if (!mrq->stop->error) {
|
|
|
|
schedule_delayed_work(&host->timeout_work, host->timeout);
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_unlock(&host->thread_lock);
|
2011-12-26 03:07:52 +07:00
|
|
|
return IRQ_HANDLED;
|
2012-12-12 21:38:11 +07:00
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
host->wait_for = MMCIF_WAIT_FOR_REQUEST;
|
|
|
|
host->state = STATE_IDLE;
|
2011-12-27 00:52:13 +07:00
|
|
|
host->mrq = NULL;
|
2011-12-26 03:07:52 +07:00
|
|
|
mmc_request_done(host->mmc, mrq);
|
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_unlock(&host->thread_lock);
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = dev_id;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2013-07-11 02:21:12 +07:00
|
|
|
u32 state, mask;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2010-05-18 21:42:51 +07:00
|
|
|
state = sh_mmcif_readl(host->addr, MMCIF_CE_INT);
|
2013-07-11 02:21:12 +07:00
|
|
|
mask = sh_mmcif_readl(host->addr, MMCIF_CE_INT_MASK);
|
|
|
|
if (host->ccs_enable)
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~(state & mask));
|
|
|
|
else
|
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT, INT_CCS | ~(state & mask));
|
2012-12-12 21:45:14 +07:00
|
|
|
sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state & MASK_CLEAN);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2012-12-12 21:45:14 +07:00
|
|
|
if (state & ~MASK_CLEAN)
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "IRQ state = 0x%08x incompletely cleared\n",
|
2012-12-12 21:45:14 +07:00
|
|
|
state);
|
|
|
|
|
|
|
|
if (state & INT_ERR_STS || state & ~INT_ALL) {
|
2010-11-24 17:05:12 +07:00
|
|
|
host->sd_error = true;
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "int err state = 0x%08x\n", state);
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
2011-12-26 03:07:52 +07:00
|
|
|
if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) {
|
2012-12-12 21:45:14 +07:00
|
|
|
if (!host->mrq)
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "NULL IRQ state = 0x%08x\n", state);
|
2011-12-26 03:07:52 +07:00
|
|
|
if (!host->dma_active)
|
|
|
|
return IRQ_WAKE_THREAD;
|
|
|
|
else if (host->sd_error)
|
2015-05-14 14:21:36 +07:00
|
|
|
sh_mmcif_dma_complete(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
} else {
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_dbg(dev, "Unexpected IRQ 0x%x\n", state);
|
2011-12-26 03:07:52 +07:00
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
static void sh_mmcif_timeout_work(struct work_struct *work)
|
2011-12-26 03:07:52 +07:00
|
|
|
{
|
2016-01-01 21:59:09 +07:00
|
|
|
struct delayed_work *d = to_delayed_work(work);
|
2011-12-26 03:07:52 +07:00
|
|
|
struct sh_mmcif_host *host = container_of(d, struct sh_mmcif_host, timeout_work);
|
|
|
|
struct mmc_request *mrq = host->mrq;
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
2012-12-12 21:38:14 +07:00
|
|
|
unsigned long flags;
|
2011-12-26 03:07:52 +07:00
|
|
|
|
|
|
|
if (host->dying)
|
|
|
|
/* Don't run after mmc_remove_host() */
|
|
|
|
return;
|
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
spin_lock_irqsave(&host->lock, flags);
|
|
|
|
if (host->state == STATE_IDLE) {
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-14 14:21:18 +07:00
|
|
|
dev_err(dev, "Timeout waiting for %u on CMD%u\n",
|
2015-02-15 21:46:47 +07:00
|
|
|
host->wait_for, mrq->cmd->opcode);
|
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
host->state = STATE_TIMEOUT;
|
|
|
|
spin_unlock_irqrestore(&host->lock, flags);
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
/*
|
|
|
|
* Handle races with cancel_delayed_work(), unless
|
|
|
|
* cancel_delayed_work_sync() is used
|
|
|
|
*/
|
|
|
|
switch (host->wait_for) {
|
|
|
|
case MMCIF_WAIT_FOR_CMD:
|
|
|
|
mrq->cmd->error = sh_mmcif_error_manage(host);
|
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_STOP:
|
|
|
|
mrq->stop->error = sh_mmcif_error_manage(host);
|
|
|
|
break;
|
|
|
|
case MMCIF_WAIT_FOR_MREAD:
|
|
|
|
case MMCIF_WAIT_FOR_MWRITE:
|
|
|
|
case MMCIF_WAIT_FOR_READ:
|
|
|
|
case MMCIF_WAIT_FOR_WRITE:
|
|
|
|
case MMCIF_WAIT_FOR_READ_END:
|
|
|
|
case MMCIF_WAIT_FOR_WRITE_END:
|
2011-12-27 00:52:13 +07:00
|
|
|
mrq->data->error = sh_mmcif_error_manage(host);
|
2011-12-26 03:07:52 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
|
|
|
host->state = STATE_IDLE;
|
|
|
|
host->wait_for = MMCIF_WAIT_FOR_REQUEST;
|
|
|
|
host->mrq = NULL;
|
|
|
|
mmc_request_done(host->mmc, mrq);
|
|
|
|
}
|
|
|
|
|
2012-04-20 23:27:13 +07:00
|
|
|
static void sh_mmcif_init_ocr(struct sh_mmcif_host *host)
|
|
|
|
{
|
2015-05-14 14:21:18 +07:00
|
|
|
struct device *dev = sh_mmcif_host_to_dev(host);
|
|
|
|
struct sh_mmcif_plat_data *pd = dev->platform_data;
|
2012-04-20 23:27:13 +07:00
|
|
|
struct mmc_host *mmc = host->mmc;
|
|
|
|
|
|
|
|
mmc_regulator_get_supply(mmc);
|
|
|
|
|
2012-05-01 23:18:16 +07:00
|
|
|
if (!pd)
|
|
|
|
return;
|
|
|
|
|
2012-04-20 23:27:13 +07:00
|
|
|
if (!mmc->ocr_avail)
|
|
|
|
mmc->ocr_avail = pd->ocr;
|
|
|
|
else if (pd->ocr)
|
|
|
|
dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
|
|
|
|
}
|
|
|
|
|
2012-11-20 01:23:06 +07:00
|
|
|
static int sh_mmcif_probe(struct platform_device *pdev)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
|
|
|
int ret = 0, irq[2];
|
|
|
|
struct mmc_host *mmc;
|
2010-11-24 17:05:18 +07:00
|
|
|
struct sh_mmcif_host *host;
|
2015-04-23 15:14:12 +07:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct sh_mmcif_plat_data *pd = dev->platform_data;
|
2010-05-27 04:41:59 +07:00
|
|
|
struct resource *res;
|
|
|
|
void __iomem *reg;
|
2013-01-15 02:12:36 +07:00
|
|
|
const char *name;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
irq[0] = platform_get_irq(pdev, 0);
|
|
|
|
irq[1] = platform_get_irq(pdev, 1);
|
2013-01-15 02:12:36 +07:00
|
|
|
if (irq[0] < 0) {
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_err(dev, "Get irq error\n");
|
2010-05-27 04:41:59 +07:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
2014-06-04 18:42:09 +07:00
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2015-04-23 15:14:12 +07:00
|
|
|
reg = devm_ioremap_resource(dev, res);
|
2014-06-04 18:42:09 +07:00
|
|
|
if (IS_ERR(reg))
|
|
|
|
return PTR_ERR(reg);
|
2012-04-19 21:15:52 +07:00
|
|
|
|
2015-04-23 15:14:12 +07:00
|
|
|
mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), dev);
|
2014-06-04 18:42:09 +07:00
|
|
|
if (!mmc)
|
|
|
|
return -ENOMEM;
|
2013-06-10 03:14:12 +07:00
|
|
|
|
|
|
|
ret = mmc_of_parse(mmc);
|
|
|
|
if (ret < 0)
|
2014-06-04 18:42:10 +07:00
|
|
|
goto err_host;
|
2013-06-10 03:14:12 +07:00
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
host = mmc_priv(mmc);
|
|
|
|
host->mmc = mmc;
|
|
|
|
host->addr = reg;
|
2015-04-30 00:03:51 +07:00
|
|
|
host->timeout = msecs_to_jiffies(10000);
|
2016-12-30 19:47:18 +07:00
|
|
|
host->ccs_enable = true;
|
2016-12-30 19:47:19 +07:00
|
|
|
host->clk_ctrl2_enable = false;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
host->pd = pdev;
|
|
|
|
|
2011-04-16 01:30:47 +07:00
|
|
|
spin_lock_init(&host->lock);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
mmc->ops = &sh_mmcif_ops;
|
2012-04-20 23:27:13 +07:00
|
|
|
sh_mmcif_init_ocr(host);
|
|
|
|
|
2013-02-15 22:13:54 +07:00
|
|
|
mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_WAIT_WHILE_BUSY;
|
2016-06-21 20:12:47 +07:00
|
|
|
mmc->caps2 |= MMC_CAP2_NO_SD | MMC_CAP2_NO_SDIO;
|
2016-06-21 20:12:49 +07:00
|
|
|
mmc->max_busy_timeout = 10000;
|
2016-06-21 20:12:47 +07:00
|
|
|
|
2012-05-01 23:18:16 +07:00
|
|
|
if (pd && pd->caps)
|
2010-05-27 04:41:59 +07:00
|
|
|
mmc->caps |= pd->caps;
|
2010-11-24 17:05:22 +07:00
|
|
|
mmc->max_segs = 32;
|
2010-05-27 04:41:59 +07:00
|
|
|
mmc->max_blk_size = 512;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
mmc->max_req_size = PAGE_SIZE * mmc->max_segs;
|
2010-11-24 17:05:22 +07:00
|
|
|
mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
|
2010-05-27 04:41:59 +07:00
|
|
|
mmc->max_seg_size = mmc->max_req_size;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, host);
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2015-04-23 15:15:08 +07:00
|
|
|
host->clk = devm_clk_get(dev, NULL);
|
|
|
|
if (IS_ERR(host->clk)) {
|
|
|
|
ret = PTR_ERR(host->clk);
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_err(dev, "cannot get clock: %d\n", ret);
|
2016-02-11 19:59:53 +07:00
|
|
|
goto err_host;
|
2012-04-19 23:02:05 +07:00
|
|
|
}
|
2015-04-23 15:16:04 +07:00
|
|
|
|
|
|
|
ret = clk_prepare_enable(host->clk);
|
2012-04-19 23:02:50 +07:00
|
|
|
if (ret < 0)
|
2016-02-11 19:59:53 +07:00
|
|
|
goto err_host;
|
2012-04-19 23:02:05 +07:00
|
|
|
|
2015-04-23 15:16:04 +07:00
|
|
|
sh_mmcif_clk_setup(host);
|
|
|
|
|
2016-02-11 19:59:53 +07:00
|
|
|
pm_runtime_enable(dev);
|
|
|
|
host->power = false;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(dev);
|
2011-05-05 23:20:48 +07:00
|
|
|
if (ret < 0)
|
2014-06-04 18:42:10 +07:00
|
|
|
goto err_clk;
|
2010-11-24 17:05:22 +07:00
|
|
|
|
2015-05-14 14:21:36 +07:00
|
|
|
INIT_DELAYED_WORK(&host->timeout_work, sh_mmcif_timeout_work);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2012-04-19 23:02:05 +07:00
|
|
|
sh_mmcif_sync_reset(host);
|
2011-04-16 01:30:47 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
|
|
|
|
|
2015-04-23 15:14:12 +07:00
|
|
|
name = irq[1] < 0 ? dev_name(dev) : "sh_mmc:error";
|
|
|
|
ret = devm_request_threaded_irq(dev, irq[0], sh_mmcif_intr,
|
2014-06-04 18:42:11 +07:00
|
|
|
sh_mmcif_irqt, 0, name, host);
|
2010-05-27 04:41:59 +07:00
|
|
|
if (ret) {
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_err(dev, "request_irq error (%s)\n", name);
|
2014-06-04 18:42:12 +07:00
|
|
|
goto err_clk;
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
2013-01-15 02:12:36 +07:00
|
|
|
if (irq[1] >= 0) {
|
2015-04-23 15:14:12 +07:00
|
|
|
ret = devm_request_threaded_irq(dev, irq[1],
|
2014-06-04 18:42:11 +07:00
|
|
|
sh_mmcif_intr, sh_mmcif_irqt,
|
|
|
|
0, "sh_mmc:int", host);
|
2013-01-15 02:12:36 +07:00
|
|
|
if (ret) {
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_err(dev, "request_irq error (sh_mmc:int)\n");
|
2014-06-04 18:42:12 +07:00
|
|
|
goto err_clk;
|
2013-01-15 02:12:36 +07:00
|
|
|
}
|
2010-05-27 04:41:59 +07:00
|
|
|
}
|
|
|
|
|
2012-12-12 21:38:14 +07:00
|
|
|
mutex_init(&host->thread_lock);
|
|
|
|
|
2012-01-21 06:41:28 +07:00
|
|
|
ret = mmc_add_host(mmc);
|
|
|
|
if (ret < 0)
|
2014-06-04 18:42:13 +07:00
|
|
|
goto err_clk;
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_pm_qos_expose_latency_limit(dev, 100);
|
2012-03-13 07:02:15 +07:00
|
|
|
|
2015-04-23 15:14:12 +07:00
|
|
|
dev_info(dev, "Chip version 0x%04x, clock rate %luMHz\n",
|
2014-06-04 18:42:08 +07:00
|
|
|
sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0xffff,
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_get_rate(host->clk) / 1000000UL);
|
2014-06-04 18:42:08 +07:00
|
|
|
|
2016-02-11 19:59:53 +07:00
|
|
|
pm_runtime_put(dev);
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_disable_unprepare(host->clk);
|
2010-05-27 04:41:59 +07:00
|
|
|
return ret;
|
|
|
|
|
2014-06-04 18:42:10 +07:00
|
|
|
err_clk:
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_disable_unprepare(host->clk);
|
2016-02-11 19:59:53 +07:00
|
|
|
pm_runtime_put_sync(dev);
|
2015-04-23 15:14:12 +07:00
|
|
|
pm_runtime_disable(dev);
|
2014-06-04 18:42:10 +07:00
|
|
|
err_host:
|
2010-05-27 04:41:59 +07:00
|
|
|
mmc_free_host(mmc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-20 01:26:03 +07:00
|
|
|
static int sh_mmcif_remove(struct platform_device *pdev)
|
2010-05-27 04:41:59 +07:00
|
|
|
{
|
|
|
|
struct sh_mmcif_host *host = platform_get_drvdata(pdev);
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
host->dying = true;
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_prepare_enable(host->clk);
|
2011-05-05 23:20:48 +07:00
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
2012-03-13 07:02:15 +07:00
|
|
|
dev_pm_qos_hide_latency_limit(&pdev->dev);
|
|
|
|
|
2011-05-05 23:20:48 +07:00
|
|
|
mmc_remove_host(host->mmc);
|
2011-04-16 01:30:47 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
|
|
|
|
|
2011-12-26 03:07:52 +07:00
|
|
|
/*
|
|
|
|
* FIXME: cancel_delayed_work(_sync)() and free_irq() race with the
|
|
|
|
* mmc_remove_host() call above. But swapping order doesn't help either
|
|
|
|
* (a query on the linux-mmc mailing list didn't bring any replies).
|
|
|
|
*/
|
|
|
|
cancel_delayed_work_sync(&host->timeout_work);
|
|
|
|
|
2015-04-23 15:15:08 +07:00
|
|
|
clk_disable_unprepare(host->clk);
|
2010-05-27 04:41:59 +07:00
|
|
|
mmc_free_host(host->mmc);
|
2011-05-05 23:20:48 +07:00
|
|
|
pm_runtime_put_sync(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-01 19:01:46 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2011-05-05 23:20:48 +07:00
|
|
|
static int sh_mmcif_suspend(struct device *dev)
|
|
|
|
{
|
2012-04-19 23:02:05 +07:00
|
|
|
struct sh_mmcif_host *host = dev_get_drvdata(dev);
|
2011-05-05 23:20:48 +07:00
|
|
|
|
2015-08-23 19:58:08 +07:00
|
|
|
pm_runtime_get_sync(dev);
|
2013-09-26 15:19:09 +07:00
|
|
|
sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
|
2015-08-23 19:58:08 +07:00
|
|
|
pm_runtime_put(dev);
|
2011-05-05 23:20:48 +07:00
|
|
|
|
2013-09-26 15:19:09 +07:00
|
|
|
return 0;
|
2011-05-05 23:20:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mmcif_resume(struct device *dev)
|
|
|
|
{
|
2013-09-26 15:19:09 +07:00
|
|
|
return 0;
|
2011-05-05 23:20:48 +07:00
|
|
|
}
|
2013-10-01 19:01:46 +07:00
|
|
|
#endif
|
2011-05-05 23:20:48 +07:00
|
|
|
|
|
|
|
static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
|
2013-10-01 19:01:46 +07:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(sh_mmcif_suspend, sh_mmcif_resume)
|
2011-05-05 23:20:48 +07:00
|
|
|
};
|
|
|
|
|
2010-05-27 04:41:59 +07:00
|
|
|
static struct platform_driver sh_mmcif_driver = {
|
|
|
|
.probe = sh_mmcif_probe,
|
|
|
|
.remove = sh_mmcif_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2011-05-05 23:20:48 +07:00
|
|
|
.pm = &sh_mmcif_dev_pm_ops,
|
2015-05-14 14:21:36 +07:00
|
|
|
.of_match_table = sh_mmcif_of_match,
|
2010-05-27 04:41:59 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-26 11:55:43 +07:00
|
|
|
module_platform_driver(sh_mmcif_driver);
|
2010-05-27 04:41:59 +07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2010-11-24 17:05:12 +07:00
|
|
|
MODULE_ALIAS("platform:" DRIVER_NAME);
|
2010-05-27 04:41:59 +07:00
|
|
|
MODULE_AUTHOR("Yusuke Goda <yusuke.goda.sx@renesas.com>");
|