Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * MMCIF eMMC driver. |
| 3 | * |
| 4 | * Copyright (C) 2010 Renesas Solutions Corp. |
| 5 | * Yusuke Goda <yusuke.goda.sx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License. |
| 10 | * |
| 11 | * |
| 12 | * TODO |
| 13 | * 1. DMA |
| 14 | * 2. Power management |
| 15 | * 3. Handle MMC errors better |
| 16 | * |
| 17 | */ |
| 18 | |
Guennadi Liakhovetski | 86df174 | 2011-11-23 15:52:30 +0100 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 20 | #include <linux/clk.h> |
| 21 | #include <linux/completion.h> |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 22 | #include <linux/delay.h> |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 23 | #include <linux/dma-mapping.h> |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 24 | #include <linux/dmaengine.h> |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 25 | #include <linux/mmc/card.h> |
| 26 | #include <linux/mmc/core.h> |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 27 | #include <linux/mmc/host.h> |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 28 | #include <linux/mmc/mmc.h> |
| 29 | #include <linux/mmc/sdio.h> |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 30 | #include <linux/mmc/sh_mmcif.h> |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 31 | #include <linux/pagemap.h> |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 34 | #include <linux/spinlock.h> |
Paul Gortmaker | 88b4767 | 2011-07-03 15:15:51 -0400 | [diff] [blame] | 35 | #include <linux/module.h> |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 36 | |
| 37 | #define DRIVER_NAME "sh_mmcif" |
| 38 | #define DRIVER_VERSION "2010-04-28" |
| 39 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 40 | /* CE_CMD_SET */ |
| 41 | #define CMD_MASK 0x3f000000 |
| 42 | #define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22)) |
| 43 | #define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22)) /* R1/R1b/R3/R4/R5 */ |
| 44 | #define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22)) /* R2 */ |
| 45 | #define CMD_SET_RBSY (1 << 21) /* R1b */ |
| 46 | #define CMD_SET_CCSEN (1 << 20) |
| 47 | #define CMD_SET_WDAT (1 << 19) /* 1: on data, 0: no data */ |
| 48 | #define CMD_SET_DWEN (1 << 18) /* 1: write, 0: read */ |
| 49 | #define CMD_SET_CMLTE (1 << 17) /* 1: multi block trans, 0: single */ |
| 50 | #define CMD_SET_CMD12EN (1 << 16) /* 1: CMD12 auto issue */ |
| 51 | #define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14)) /* index check */ |
| 52 | #define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14)) /* check bits check */ |
| 53 | #define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14)) /* no check */ |
| 54 | #define CMD_SET_CRC7C ((0 << 13) | (0 << 12)) /* CRC7 check*/ |
| 55 | #define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12)) /* check bits check*/ |
| 56 | #define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12)) /* internal CRC7 check*/ |
| 57 | #define CMD_SET_CRC16C (1 << 10) /* 0: CRC16 check*/ |
| 58 | #define CMD_SET_CRCSTE (1 << 8) /* 1: not receive CRC status */ |
| 59 | #define CMD_SET_TBIT (1 << 7) /* 1: tran mission bit "Low" */ |
| 60 | #define CMD_SET_OPDM (1 << 6) /* 1: open/drain */ |
| 61 | #define CMD_SET_CCSH (1 << 5) |
| 62 | #define CMD_SET_DATW_1 ((0 << 1) | (0 << 0)) /* 1bit */ |
| 63 | #define CMD_SET_DATW_4 ((0 << 1) | (1 << 0)) /* 4bit */ |
| 64 | #define CMD_SET_DATW_8 ((1 << 1) | (0 << 0)) /* 8bit */ |
| 65 | |
| 66 | /* CE_CMD_CTRL */ |
| 67 | #define CMD_CTRL_BREAK (1 << 0) |
| 68 | |
| 69 | /* CE_BLOCK_SET */ |
| 70 | #define BLOCK_SIZE_MASK 0x0000ffff |
| 71 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 72 | /* CE_INT */ |
| 73 | #define INT_CCSDE (1 << 29) |
| 74 | #define INT_CMD12DRE (1 << 26) |
| 75 | #define INT_CMD12RBE (1 << 25) |
| 76 | #define INT_CMD12CRE (1 << 24) |
| 77 | #define INT_DTRANE (1 << 23) |
| 78 | #define INT_BUFRE (1 << 22) |
| 79 | #define INT_BUFWEN (1 << 21) |
| 80 | #define INT_BUFREN (1 << 20) |
| 81 | #define INT_CCSRCV (1 << 19) |
| 82 | #define INT_RBSYE (1 << 17) |
| 83 | #define INT_CRSPE (1 << 16) |
| 84 | #define INT_CMDVIO (1 << 15) |
| 85 | #define INT_BUFVIO (1 << 14) |
| 86 | #define INT_WDATERR (1 << 11) |
| 87 | #define INT_RDATERR (1 << 10) |
| 88 | #define INT_RIDXERR (1 << 9) |
| 89 | #define INT_RSPERR (1 << 8) |
| 90 | #define INT_CCSTO (1 << 5) |
| 91 | #define INT_CRCSTO (1 << 4) |
| 92 | #define INT_WDATTO (1 << 3) |
| 93 | #define INT_RDATTO (1 << 2) |
| 94 | #define INT_RBSYTO (1 << 1) |
| 95 | #define INT_RSPTO (1 << 0) |
| 96 | #define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \ |
| 97 | INT_RDATERR | INT_RIDXERR | INT_RSPERR | \ |
| 98 | INT_CCSTO | INT_CRCSTO | INT_WDATTO | \ |
| 99 | INT_RDATTO | INT_RBSYTO | INT_RSPTO) |
| 100 | |
| 101 | /* CE_INT_MASK */ |
| 102 | #define MASK_ALL 0x00000000 |
| 103 | #define MASK_MCCSDE (1 << 29) |
| 104 | #define MASK_MCMD12DRE (1 << 26) |
| 105 | #define MASK_MCMD12RBE (1 << 25) |
| 106 | #define MASK_MCMD12CRE (1 << 24) |
| 107 | #define MASK_MDTRANE (1 << 23) |
| 108 | #define MASK_MBUFRE (1 << 22) |
| 109 | #define MASK_MBUFWEN (1 << 21) |
| 110 | #define MASK_MBUFREN (1 << 20) |
| 111 | #define MASK_MCCSRCV (1 << 19) |
| 112 | #define MASK_MRBSYE (1 << 17) |
| 113 | #define MASK_MCRSPE (1 << 16) |
| 114 | #define MASK_MCMDVIO (1 << 15) |
| 115 | #define MASK_MBUFVIO (1 << 14) |
| 116 | #define MASK_MWDATERR (1 << 11) |
| 117 | #define MASK_MRDATERR (1 << 10) |
| 118 | #define MASK_MRIDXERR (1 << 9) |
| 119 | #define MASK_MRSPERR (1 << 8) |
| 120 | #define MASK_MCCSTO (1 << 5) |
| 121 | #define MASK_MCRCSTO (1 << 4) |
| 122 | #define MASK_MWDATTO (1 << 3) |
| 123 | #define MASK_MRDATTO (1 << 2) |
| 124 | #define MASK_MRBSYTO (1 << 1) |
| 125 | #define MASK_MRSPTO (1 << 0) |
| 126 | |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 127 | #define MASK_START_CMD (MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR | \ |
| 128 | MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR | \ |
| 129 | MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO | \ |
| 130 | MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO) |
| 131 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 132 | /* CE_HOST_STS1 */ |
| 133 | #define STS1_CMDSEQ (1 << 31) |
| 134 | |
| 135 | /* CE_HOST_STS2 */ |
| 136 | #define STS2_CRCSTE (1 << 31) |
| 137 | #define STS2_CRC16E (1 << 30) |
| 138 | #define STS2_AC12CRCE (1 << 29) |
| 139 | #define STS2_RSPCRC7E (1 << 28) |
| 140 | #define STS2_CRCSTEBE (1 << 27) |
| 141 | #define STS2_RDATEBE (1 << 26) |
| 142 | #define STS2_AC12REBE (1 << 25) |
| 143 | #define STS2_RSPEBE (1 << 24) |
| 144 | #define STS2_AC12IDXE (1 << 23) |
| 145 | #define STS2_RSPIDXE (1 << 22) |
| 146 | #define STS2_CCSTO (1 << 15) |
| 147 | #define STS2_RDATTO (1 << 14) |
| 148 | #define STS2_DATBSYTO (1 << 13) |
| 149 | #define STS2_CRCSTTO (1 << 12) |
| 150 | #define STS2_AC12BSYTO (1 << 11) |
| 151 | #define STS2_RSPBSYTO (1 << 10) |
| 152 | #define STS2_AC12RSPTO (1 << 9) |
| 153 | #define STS2_RSPTO (1 << 8) |
| 154 | #define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \ |
| 155 | STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE) |
| 156 | #define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \ |
| 157 | STS2_DATBSYTO | STS2_CRCSTTO | \ |
| 158 | STS2_AC12BSYTO | STS2_RSPBSYTO | \ |
| 159 | STS2_AC12RSPTO | STS2_RSPTO) |
| 160 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 161 | #define CLKDEV_EMMC_DATA 52000000 /* 52MHz */ |
| 162 | #define CLKDEV_MMC_DATA 20000000 /* 20MHz */ |
| 163 | #define CLKDEV_INIT 400000 /* 400 KHz */ |
| 164 | |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 165 | enum mmcif_state { |
| 166 | STATE_IDLE, |
| 167 | STATE_REQUEST, |
| 168 | STATE_IOS, |
| 169 | }; |
| 170 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 171 | struct sh_mmcif_host { |
| 172 | struct mmc_host *mmc; |
| 173 | struct mmc_data *data; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 174 | struct platform_device *pd; |
Guennadi Liakhovetski | 714c4a6 | 2011-08-30 18:26:39 +0200 | [diff] [blame] | 175 | struct sh_dmae_slave dma_slave_tx; |
| 176 | struct sh_dmae_slave dma_slave_rx; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 177 | struct clk *hclk; |
| 178 | unsigned int clk; |
| 179 | int bus_width; |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 180 | bool sd_error; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 181 | long timeout; |
| 182 | void __iomem *addr; |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 183 | struct completion intr_wait; |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 184 | spinlock_t lock; /* protect sh_mmcif_host::state */ |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 185 | enum mmcif_state state; |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 186 | bool power; |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 187 | bool card_present; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 188 | |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 189 | /* DMA support */ |
| 190 | struct dma_chan *chan_rx; |
| 191 | struct dma_chan *chan_tx; |
| 192 | struct completion dma_complete; |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 193 | bool dma_active; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 194 | }; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 195 | |
| 196 | static inline void sh_mmcif_bitset(struct sh_mmcif_host *host, |
| 197 | unsigned int reg, u32 val) |
| 198 | { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 199 | writel(val | readl(host->addr + reg), host->addr + reg); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host, |
| 203 | unsigned int reg, u32 val) |
| 204 | { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 205 | writel(~val & readl(host->addr + reg), host->addr + reg); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 208 | static void mmcif_dma_complete(void *arg) |
| 209 | { |
| 210 | struct sh_mmcif_host *host = arg; |
| 211 | dev_dbg(&host->pd->dev, "Command completed\n"); |
| 212 | |
| 213 | if (WARN(!host->data, "%s: NULL data in DMA completion!\n", |
| 214 | dev_name(&host->pd->dev))) |
| 215 | return; |
| 216 | |
| 217 | if (host->data->flags & MMC_DATA_READ) |
Linus Walleij | 1ed828d | 2011-02-10 16:09:29 +0100 | [diff] [blame] | 218 | dma_unmap_sg(host->chan_rx->device->dev, |
Linus Walleij | 9dc3fb5 | 2011-02-10 16:09:40 +0100 | [diff] [blame] | 219 | host->data->sg, host->data->sg_len, |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 220 | DMA_FROM_DEVICE); |
| 221 | else |
Linus Walleij | 1ed828d | 2011-02-10 16:09:29 +0100 | [diff] [blame] | 222 | dma_unmap_sg(host->chan_tx->device->dev, |
Linus Walleij | 9dc3fb5 | 2011-02-10 16:09:40 +0100 | [diff] [blame] | 223 | host->data->sg, host->data->sg_len, |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 224 | DMA_TO_DEVICE); |
| 225 | |
| 226 | complete(&host->dma_complete); |
| 227 | } |
| 228 | |
| 229 | static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host) |
| 230 | { |
| 231 | struct scatterlist *sg = host->data->sg; |
| 232 | struct dma_async_tx_descriptor *desc = NULL; |
| 233 | struct dma_chan *chan = host->chan_rx; |
| 234 | dma_cookie_t cookie = -EINVAL; |
| 235 | int ret; |
| 236 | |
Linus Walleij | 1ed828d | 2011-02-10 16:09:29 +0100 | [diff] [blame] | 237 | ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len, |
| 238 | DMA_FROM_DEVICE); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 239 | if (ret > 0) { |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 240 | host->dma_active = true; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 241 | desc = chan->device->device_prep_slave_sg(chan, sg, ret, |
| 242 | DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 243 | } |
| 244 | |
| 245 | if (desc) { |
| 246 | desc->callback = mmcif_dma_complete; |
| 247 | desc->callback_param = host; |
Linus Walleij | a5ece7d | 2011-02-10 16:10:00 +0100 | [diff] [blame] | 248 | cookie = dmaengine_submit(desc); |
| 249 | sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN); |
| 250 | dma_async_issue_pending(chan); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 251 | } |
| 252 | dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", |
| 253 | __func__, host->data->sg_len, ret, cookie); |
| 254 | |
| 255 | if (!desc) { |
| 256 | /* DMA failed, fall back to PIO */ |
| 257 | if (ret >= 0) |
| 258 | ret = -EIO; |
| 259 | host->chan_rx = NULL; |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 260 | host->dma_active = false; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 261 | dma_release_channel(chan); |
| 262 | /* Free the Tx channel too */ |
| 263 | chan = host->chan_tx; |
| 264 | if (chan) { |
| 265 | host->chan_tx = NULL; |
| 266 | dma_release_channel(chan); |
| 267 | } |
| 268 | dev_warn(&host->pd->dev, |
| 269 | "DMA failed: %d, falling back to PIO\n", ret); |
| 270 | sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN); |
| 271 | } |
| 272 | |
| 273 | dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__, |
| 274 | desc, cookie, host->data->sg_len); |
| 275 | } |
| 276 | |
| 277 | static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host) |
| 278 | { |
| 279 | struct scatterlist *sg = host->data->sg; |
| 280 | struct dma_async_tx_descriptor *desc = NULL; |
| 281 | struct dma_chan *chan = host->chan_tx; |
| 282 | dma_cookie_t cookie = -EINVAL; |
| 283 | int ret; |
| 284 | |
Linus Walleij | 1ed828d | 2011-02-10 16:09:29 +0100 | [diff] [blame] | 285 | ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len, |
| 286 | DMA_TO_DEVICE); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 287 | if (ret > 0) { |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 288 | host->dma_active = true; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 289 | desc = chan->device->device_prep_slave_sg(chan, sg, ret, |
| 290 | DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 291 | } |
| 292 | |
| 293 | if (desc) { |
| 294 | desc->callback = mmcif_dma_complete; |
| 295 | desc->callback_param = host; |
Linus Walleij | a5ece7d | 2011-02-10 16:10:00 +0100 | [diff] [blame] | 296 | cookie = dmaengine_submit(desc); |
| 297 | sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN); |
| 298 | dma_async_issue_pending(chan); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 299 | } |
| 300 | dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n", |
| 301 | __func__, host->data->sg_len, ret, cookie); |
| 302 | |
| 303 | if (!desc) { |
| 304 | /* DMA failed, fall back to PIO */ |
| 305 | if (ret >= 0) |
| 306 | ret = -EIO; |
| 307 | host->chan_tx = NULL; |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 308 | host->dma_active = false; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 309 | dma_release_channel(chan); |
| 310 | /* Free the Rx channel too */ |
| 311 | chan = host->chan_rx; |
| 312 | if (chan) { |
| 313 | host->chan_rx = NULL; |
| 314 | dma_release_channel(chan); |
| 315 | } |
| 316 | dev_warn(&host->pd->dev, |
| 317 | "DMA failed: %d, falling back to PIO\n", ret); |
| 318 | sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN); |
| 319 | } |
| 320 | |
| 321 | dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d\n", __func__, |
| 322 | desc, cookie); |
| 323 | } |
| 324 | |
| 325 | static bool sh_mmcif_filter(struct dma_chan *chan, void *arg) |
| 326 | { |
| 327 | dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg); |
| 328 | chan->private = arg; |
| 329 | return true; |
| 330 | } |
| 331 | |
| 332 | static void sh_mmcif_request_dma(struct sh_mmcif_host *host, |
| 333 | struct sh_mmcif_plat_data *pdata) |
| 334 | { |
Guennadi Liakhovetski | 714c4a6 | 2011-08-30 18:26:39 +0200 | [diff] [blame] | 335 | struct sh_dmae_slave *tx, *rx; |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 336 | host->dma_active = false; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 337 | |
| 338 | /* We can only either use DMA for both Tx and Rx or not use it at all */ |
| 339 | if (pdata->dma) { |
Guennadi Liakhovetski | 714c4a6 | 2011-08-30 18:26:39 +0200 | [diff] [blame] | 340 | dev_warn(&host->pd->dev, |
| 341 | "Update your platform to use embedded DMA slave IDs\n"); |
| 342 | tx = &pdata->dma->chan_priv_tx; |
| 343 | rx = &pdata->dma->chan_priv_rx; |
| 344 | } else { |
| 345 | tx = &host->dma_slave_tx; |
| 346 | tx->slave_id = pdata->slave_id_tx; |
| 347 | rx = &host->dma_slave_rx; |
| 348 | rx->slave_id = pdata->slave_id_rx; |
| 349 | } |
| 350 | if (tx->slave_id > 0 && rx->slave_id > 0) { |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 351 | dma_cap_mask_t mask; |
| 352 | |
| 353 | dma_cap_zero(mask); |
| 354 | dma_cap_set(DMA_SLAVE, mask); |
| 355 | |
Guennadi Liakhovetski | 714c4a6 | 2011-08-30 18:26:39 +0200 | [diff] [blame] | 356 | host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, tx); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 357 | dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__, |
| 358 | host->chan_tx); |
| 359 | |
| 360 | if (!host->chan_tx) |
| 361 | return; |
| 362 | |
Guennadi Liakhovetski | 714c4a6 | 2011-08-30 18:26:39 +0200 | [diff] [blame] | 363 | host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, rx); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 364 | dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__, |
| 365 | host->chan_rx); |
| 366 | |
| 367 | if (!host->chan_rx) { |
| 368 | dma_release_channel(host->chan_tx); |
| 369 | host->chan_tx = NULL; |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | init_completion(&host->dma_complete); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static void sh_mmcif_release_dma(struct sh_mmcif_host *host) |
| 378 | { |
| 379 | sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN); |
| 380 | /* Descriptors are freed automatically */ |
| 381 | if (host->chan_tx) { |
| 382 | struct dma_chan *chan = host->chan_tx; |
| 383 | host->chan_tx = NULL; |
| 384 | dma_release_channel(chan); |
| 385 | } |
| 386 | if (host->chan_rx) { |
| 387 | struct dma_chan *chan = host->chan_rx; |
| 388 | host->chan_rx = NULL; |
| 389 | dma_release_channel(chan); |
| 390 | } |
| 391 | |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 392 | host->dma_active = false; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 393 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 394 | |
| 395 | static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) |
| 396 | { |
| 397 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; |
| 398 | |
| 399 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); |
| 400 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); |
| 401 | |
| 402 | if (!clk) |
| 403 | return; |
| 404 | if (p->sup_pclk && clk == host->clk) |
| 405 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); |
| 406 | else |
| 407 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & |
Guennadi Liakhovetski | 86df174 | 2011-11-23 15:52:30 +0100 | [diff] [blame] | 408 | ((fls(host->clk / clk) - 1) << 16)); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 409 | |
| 410 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); |
| 411 | } |
| 412 | |
| 413 | static void sh_mmcif_sync_reset(struct sh_mmcif_host *host) |
| 414 | { |
| 415 | u32 tmp; |
| 416 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 417 | tmp = 0x010f0000 & sh_mmcif_readl(host->addr, MMCIF_CE_CLK_CTRL); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 418 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 419 | sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_ON); |
| 420 | sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_OFF); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 421 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, tmp | |
| 422 | SRSPTO_256 | SRBSYTO_29 | SRWDTO_29 | SCCSTO_29); |
| 423 | /* byte swap on */ |
| 424 | sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP); |
| 425 | } |
| 426 | |
| 427 | static int sh_mmcif_error_manage(struct sh_mmcif_host *host) |
| 428 | { |
| 429 | u32 state1, state2; |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 430 | int ret, timeout; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 431 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 432 | host->sd_error = false; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 433 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 434 | state1 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1); |
| 435 | state2 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS2); |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 436 | dev_dbg(&host->pd->dev, "ERR HOST_STS1 = %08x\n", state1); |
| 437 | dev_dbg(&host->pd->dev, "ERR HOST_STS2 = %08x\n", state2); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 438 | |
| 439 | if (state1 & STS1_CMDSEQ) { |
| 440 | sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK); |
| 441 | sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK); |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 442 | for (timeout = 10000000; timeout; timeout--) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 443 | if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1) |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 444 | & STS1_CMDSEQ)) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 445 | break; |
| 446 | mdelay(1); |
| 447 | } |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 448 | if (!timeout) { |
| 449 | dev_err(&host->pd->dev, |
| 450 | "Forced end of command sequence timeout err\n"); |
| 451 | return -EIO; |
| 452 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 453 | sh_mmcif_sync_reset(host); |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 454 | dev_dbg(&host->pd->dev, "Forced end of command sequence\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 455 | return -EIO; |
| 456 | } |
| 457 | |
| 458 | if (state2 & STS2_CRC_ERR) { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 459 | dev_dbg(&host->pd->dev, ": CRC error\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 460 | ret = -EIO; |
| 461 | } else if (state2 & STS2_TIMEOUT_ERR) { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 462 | dev_dbg(&host->pd->dev, ": Timeout\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 463 | ret = -ETIMEDOUT; |
| 464 | } else { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 465 | dev_dbg(&host->pd->dev, ": End/Index error\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 466 | ret = -EIO; |
| 467 | } |
| 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | static int sh_mmcif_single_read(struct sh_mmcif_host *host, |
| 472 | struct mmc_request *mrq) |
| 473 | { |
| 474 | struct mmc_data *data = mrq->data; |
| 475 | long time; |
| 476 | u32 blocksize, i, *p = sg_virt(data->sg); |
| 477 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 478 | /* buf read enable */ |
| 479 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 480 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 481 | host->timeout); |
| 482 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 483 | return sh_mmcif_error_manage(host); |
| 484 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 485 | blocksize = (BLOCK_SIZE_MASK & |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 486 | sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 487 | for (i = 0; i < blocksize / 4; i++) |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 488 | *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 489 | |
| 490 | /* buffer read end */ |
| 491 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE); |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 492 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 493 | host->timeout); |
| 494 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 495 | return sh_mmcif_error_manage(host); |
| 496 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | static int sh_mmcif_multi_read(struct sh_mmcif_host *host, |
| 501 | struct mmc_request *mrq) |
| 502 | { |
| 503 | struct mmc_data *data = mrq->data; |
| 504 | long time; |
| 505 | u32 blocksize, i, j, sec, *p; |
| 506 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 507 | blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr, |
| 508 | MMCIF_CE_BLOCK_SET); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 509 | for (j = 0; j < data->sg_len; j++) { |
| 510 | p = sg_virt(data->sg); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 511 | for (sec = 0; sec < data->sg->length / blocksize; sec++) { |
| 512 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); |
| 513 | /* buf read enable */ |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 514 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 515 | host->timeout); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 516 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 517 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 518 | return sh_mmcif_error_manage(host); |
| 519 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 520 | for (i = 0; i < blocksize / 4; i++) |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 521 | *p++ = sh_mmcif_readl(host->addr, |
| 522 | MMCIF_CE_DATA); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 523 | } |
| 524 | if (j < data->sg_len - 1) |
| 525 | data->sg++; |
| 526 | } |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int sh_mmcif_single_write(struct sh_mmcif_host *host, |
| 531 | struct mmc_request *mrq) |
| 532 | { |
| 533 | struct mmc_data *data = mrq->data; |
| 534 | long time; |
| 535 | u32 blocksize, i, *p = sg_virt(data->sg); |
| 536 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 537 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN); |
| 538 | |
| 539 | /* buf write enable */ |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 540 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 541 | host->timeout); |
| 542 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 543 | return sh_mmcif_error_manage(host); |
| 544 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 545 | blocksize = (BLOCK_SIZE_MASK & |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 546 | sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 547 | for (i = 0; i < blocksize / 4; i++) |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 548 | sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 549 | |
| 550 | /* buffer write end */ |
| 551 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE); |
| 552 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 553 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 554 | host->timeout); |
| 555 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 556 | return sh_mmcif_error_manage(host); |
| 557 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int sh_mmcif_multi_write(struct sh_mmcif_host *host, |
| 562 | struct mmc_request *mrq) |
| 563 | { |
| 564 | struct mmc_data *data = mrq->data; |
| 565 | long time; |
| 566 | u32 i, sec, j, blocksize, *p; |
| 567 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 568 | blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr, |
| 569 | MMCIF_CE_BLOCK_SET); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 570 | |
| 571 | for (j = 0; j < data->sg_len; j++) { |
| 572 | p = sg_virt(data->sg); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 573 | for (sec = 0; sec < data->sg->length / blocksize; sec++) { |
| 574 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN); |
| 575 | /* buf write enable*/ |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 576 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 577 | host->timeout); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 578 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 579 | if (time <= 0 || host->sd_error) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 580 | return sh_mmcif_error_manage(host); |
| 581 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 582 | for (i = 0; i < blocksize / 4; i++) |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 583 | sh_mmcif_writel(host->addr, |
| 584 | MMCIF_CE_DATA, *p++); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 585 | } |
| 586 | if (j < data->sg_len - 1) |
| 587 | data->sg++; |
| 588 | } |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | static void sh_mmcif_get_response(struct sh_mmcif_host *host, |
| 593 | struct mmc_command *cmd) |
| 594 | { |
| 595 | if (cmd->flags & MMC_RSP_136) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 596 | cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP3); |
| 597 | cmd->resp[1] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP2); |
| 598 | cmd->resp[2] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP1); |
| 599 | cmd->resp[3] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 600 | } else |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 601 | cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host, |
| 605 | struct mmc_command *cmd) |
| 606 | { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 607 | cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP_CMD12); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host, |
| 611 | struct mmc_request *mrq, struct mmc_command *cmd, u32 opc) |
| 612 | { |
| 613 | u32 tmp = 0; |
| 614 | |
| 615 | /* Response Type check */ |
| 616 | switch (mmc_resp_type(cmd)) { |
| 617 | case MMC_RSP_NONE: |
| 618 | tmp |= CMD_SET_RTYP_NO; |
| 619 | break; |
| 620 | case MMC_RSP_R1: |
| 621 | case MMC_RSP_R1B: |
| 622 | case MMC_RSP_R3: |
| 623 | tmp |= CMD_SET_RTYP_6B; |
| 624 | break; |
| 625 | case MMC_RSP_R2: |
| 626 | tmp |= CMD_SET_RTYP_17B; |
| 627 | break; |
| 628 | default: |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 629 | dev_err(&host->pd->dev, "Unsupported response type.\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | switch (opc) { |
| 633 | /* RBSY */ |
| 634 | case MMC_SWITCH: |
| 635 | case MMC_STOP_TRANSMISSION: |
| 636 | case MMC_SET_WRITE_PROT: |
| 637 | case MMC_CLR_WRITE_PROT: |
| 638 | case MMC_ERASE: |
| 639 | case MMC_GEN_CMD: |
| 640 | tmp |= CMD_SET_RBSY; |
| 641 | break; |
| 642 | } |
| 643 | /* WDAT / DATW */ |
| 644 | if (host->data) { |
| 645 | tmp |= CMD_SET_WDAT; |
| 646 | switch (host->bus_width) { |
| 647 | case MMC_BUS_WIDTH_1: |
| 648 | tmp |= CMD_SET_DATW_1; |
| 649 | break; |
| 650 | case MMC_BUS_WIDTH_4: |
| 651 | tmp |= CMD_SET_DATW_4; |
| 652 | break; |
| 653 | case MMC_BUS_WIDTH_8: |
| 654 | tmp |= CMD_SET_DATW_8; |
| 655 | break; |
| 656 | default: |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 657 | dev_err(&host->pd->dev, "Unsupported bus width.\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 658 | break; |
| 659 | } |
| 660 | } |
| 661 | /* DWEN */ |
| 662 | if (opc == MMC_WRITE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) |
| 663 | tmp |= CMD_SET_DWEN; |
| 664 | /* CMLTE/CMD12EN */ |
| 665 | if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) { |
| 666 | tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN; |
| 667 | sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET, |
| 668 | mrq->data->blocks << 16); |
| 669 | } |
| 670 | /* RIDXC[1:0] check bits */ |
| 671 | if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID || |
| 672 | opc == MMC_SEND_CSD || opc == MMC_SEND_CID) |
| 673 | tmp |= CMD_SET_RIDXC_BITS; |
| 674 | /* RCRC7C[1:0] check bits */ |
| 675 | if (opc == MMC_SEND_OP_COND) |
| 676 | tmp |= CMD_SET_CRC7C_BITS; |
| 677 | /* RCRC7C[1:0] internal CRC7 */ |
| 678 | if (opc == MMC_ALL_SEND_CID || |
| 679 | opc == MMC_SEND_CSD || opc == MMC_SEND_CID) |
| 680 | tmp |= CMD_SET_CRC7C_INTERNAL; |
| 681 | |
| 682 | return opc = ((opc << 24) | tmp); |
| 683 | } |
| 684 | |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 685 | static int sh_mmcif_data_trans(struct sh_mmcif_host *host, |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 686 | struct mmc_request *mrq, u32 opc) |
| 687 | { |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 688 | switch (opc) { |
| 689 | case MMC_READ_MULTIPLE_BLOCK: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 690 | return sh_mmcif_multi_read(host, mrq); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 691 | case MMC_WRITE_MULTIPLE_BLOCK: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 692 | return sh_mmcif_multi_write(host, mrq); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 693 | case MMC_WRITE_BLOCK: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 694 | return sh_mmcif_single_write(host, mrq); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 695 | case MMC_READ_SINGLE_BLOCK: |
| 696 | case MMC_SEND_EXT_CSD: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 697 | return sh_mmcif_single_read(host, mrq); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 698 | default: |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 699 | dev_err(&host->pd->dev, "UNSUPPORTED CMD = d'%08d\n", opc); |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 700 | return -EINVAL; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 701 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static void sh_mmcif_start_cmd(struct sh_mmcif_host *host, |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 705 | struct mmc_request *mrq) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 706 | { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 707 | struct mmc_command *cmd = mrq->cmd; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 708 | long time; |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 709 | int ret = 0; |
| 710 | u32 mask, opc = cmd->opcode; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 711 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 712 | switch (opc) { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 713 | /* response busy check */ |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 714 | case MMC_SWITCH: |
| 715 | case MMC_STOP_TRANSMISSION: |
| 716 | case MMC_SET_WRITE_PROT: |
| 717 | case MMC_CLR_WRITE_PROT: |
| 718 | case MMC_ERASE: |
| 719 | case MMC_GEN_CMD: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 720 | mask = MASK_START_CMD | MASK_MRBSYE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 721 | break; |
| 722 | default: |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 723 | mask = MASK_START_CMD | MASK_MCRSPE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 724 | break; |
| 725 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 726 | |
| 727 | if (host->data) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 728 | sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0); |
| 729 | sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, |
| 730 | mrq->data->blksz); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 731 | } |
| 732 | opc = sh_mmcif_set_cmd(host, mrq, cmd, opc); |
| 733 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 734 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0); |
| 735 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 736 | /* set arg */ |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 737 | sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 738 | /* set cmd */ |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 739 | sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 740 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 741 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 742 | host->timeout); |
| 743 | if (time <= 0) { |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 744 | cmd->error = sh_mmcif_error_manage(host); |
| 745 | return; |
| 746 | } |
| 747 | if (host->sd_error) { |
| 748 | switch (cmd->opcode) { |
| 749 | case MMC_ALL_SEND_CID: |
| 750 | case MMC_SELECT_CARD: |
| 751 | case MMC_APP_CMD: |
| 752 | cmd->error = -ETIMEDOUT; |
| 753 | break; |
| 754 | default: |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 755 | dev_dbg(&host->pd->dev, "Cmd(d'%d) err\n", |
| 756 | cmd->opcode); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 757 | cmd->error = sh_mmcif_error_manage(host); |
| 758 | break; |
| 759 | } |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 760 | host->sd_error = false; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 761 | return; |
| 762 | } |
| 763 | if (!(cmd->flags & MMC_RSP_PRESENT)) { |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 764 | cmd->error = 0; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 765 | return; |
| 766 | } |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 767 | sh_mmcif_get_response(host, cmd); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 768 | if (host->data) { |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 769 | if (!host->dma_active) { |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 770 | ret = sh_mmcif_data_trans(host, mrq, cmd->opcode); |
| 771 | } else { |
| 772 | long time = |
| 773 | wait_for_completion_interruptible_timeout(&host->dma_complete, |
| 774 | host->timeout); |
| 775 | if (!time) |
| 776 | ret = -ETIMEDOUT; |
| 777 | else if (time < 0) |
| 778 | ret = time; |
| 779 | sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, |
| 780 | BUF_ACC_DMAREN | BUF_ACC_DMAWEN); |
Linus Walleij | f38f94c | 2011-02-10 16:09:50 +0100 | [diff] [blame] | 781 | host->dma_active = false; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 782 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 783 | if (ret < 0) |
| 784 | mrq->data->bytes_xfered = 0; |
| 785 | else |
| 786 | mrq->data->bytes_xfered = |
| 787 | mrq->data->blocks * mrq->data->blksz; |
| 788 | } |
| 789 | cmd->error = ret; |
| 790 | } |
| 791 | |
| 792 | static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host, |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 793 | struct mmc_request *mrq) |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 794 | { |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 795 | struct mmc_command *cmd = mrq->stop; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 796 | long time; |
| 797 | |
| 798 | if (mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK) |
| 799 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE); |
| 800 | else if (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK) |
| 801 | sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE); |
| 802 | else { |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 803 | dev_err(&host->pd->dev, "unsupported stop cmd\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 804 | cmd->error = sh_mmcif_error_manage(host); |
| 805 | return; |
| 806 | } |
| 807 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 808 | time = wait_for_completion_interruptible_timeout(&host->intr_wait, |
| 809 | host->timeout); |
| 810 | if (time <= 0 || host->sd_error) { |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 811 | cmd->error = sh_mmcif_error_manage(host); |
| 812 | return; |
| 813 | } |
| 814 | sh_mmcif_get_cmd12response(host, cmd); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 815 | cmd->error = 0; |
| 816 | } |
| 817 | |
| 818 | static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) |
| 819 | { |
| 820 | struct sh_mmcif_host *host = mmc_priv(mmc); |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 821 | unsigned long flags; |
| 822 | |
| 823 | spin_lock_irqsave(&host->lock, flags); |
| 824 | if (host->state != STATE_IDLE) { |
| 825 | spin_unlock_irqrestore(&host->lock, flags); |
| 826 | mrq->cmd->error = -EAGAIN; |
| 827 | mmc_request_done(mmc, mrq); |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | host->state = STATE_REQUEST; |
| 832 | spin_unlock_irqrestore(&host->lock, flags); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 833 | |
| 834 | switch (mrq->cmd->opcode) { |
| 835 | /* MMCIF does not support SD/SDIO command */ |
| 836 | case SD_IO_SEND_OP_COND: |
| 837 | case MMC_APP_CMD: |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 838 | host->state = STATE_IDLE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 839 | mrq->cmd->error = -ETIMEDOUT; |
| 840 | mmc_request_done(mmc, mrq); |
| 841 | return; |
| 842 | case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */ |
| 843 | if (!mrq->data) { |
| 844 | /* send_if_cond cmd (not support) */ |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 845 | host->state = STATE_IDLE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 846 | mrq->cmd->error = -ETIMEDOUT; |
| 847 | mmc_request_done(mmc, mrq); |
| 848 | return; |
| 849 | } |
| 850 | break; |
| 851 | default: |
| 852 | break; |
| 853 | } |
| 854 | host->data = mrq->data; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 855 | if (mrq->data) { |
| 856 | if (mrq->data->flags & MMC_DATA_READ) { |
| 857 | if (host->chan_rx) |
| 858 | sh_mmcif_start_dma_rx(host); |
| 859 | } else { |
| 860 | if (host->chan_tx) |
| 861 | sh_mmcif_start_dma_tx(host); |
| 862 | } |
| 863 | } |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 864 | sh_mmcif_start_cmd(host, mrq); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 865 | host->data = NULL; |
| 866 | |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 867 | if (!mrq->cmd->error && mrq->stop) |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 868 | sh_mmcif_stop_cmd(host, mrq); |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 869 | host->state = STATE_IDLE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 870 | mmc_request_done(mmc, mrq); |
| 871 | } |
| 872 | |
| 873 | static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 874 | { |
| 875 | struct sh_mmcif_host *host = mmc_priv(mmc); |
| 876 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 877 | unsigned long flags; |
| 878 | |
| 879 | spin_lock_irqsave(&host->lock, flags); |
| 880 | if (host->state != STATE_IDLE) { |
| 881 | spin_unlock_irqrestore(&host->lock, flags); |
| 882 | return; |
| 883 | } |
| 884 | |
| 885 | host->state = STATE_IOS; |
| 886 | spin_unlock_irqrestore(&host->lock, flags); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 887 | |
Guennadi Liakhovetski | f5e0cec | 2011-02-25 16:58:38 +0100 | [diff] [blame] | 888 | if (ios->power_mode == MMC_POWER_UP) { |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 889 | if (!host->card_present) { |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 890 | /* See if we also get DMA */ |
| 891 | sh_mmcif_request_dma(host, host->pd->dev.platform_data); |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 892 | host->card_present = true; |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 893 | } |
Guennadi Liakhovetski | f5e0cec | 2011-02-25 16:58:38 +0100 | [diff] [blame] | 894 | } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { |
| 895 | /* clock stop */ |
| 896 | sh_mmcif_clock_control(host, 0); |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 897 | if (ios->power_mode == MMC_POWER_OFF) { |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 898 | if (host->card_present) { |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 899 | sh_mmcif_release_dma(host); |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 900 | host->card_present = false; |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 901 | } |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 902 | } |
| 903 | if (host->power) { |
| 904 | pm_runtime_put(&host->pd->dev); |
| 905 | host->power = false; |
Guennadi Liakhovetski | f6bc41f | 2011-11-16 10:10:41 +0100 | [diff] [blame] | 906 | if (p->down_pwr && ios->power_mode == MMC_POWER_OFF) |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 907 | p->down_pwr(host->pd); |
| 908 | } |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 909 | host->state = STATE_IDLE; |
Guennadi Liakhovetski | f5e0cec | 2011-02-25 16:58:38 +0100 | [diff] [blame] | 910 | return; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 913 | if (ios->clock) { |
| 914 | if (!host->power) { |
| 915 | if (p->set_pwr) |
| 916 | p->set_pwr(host->pd, ios->power_mode); |
| 917 | pm_runtime_get_sync(&host->pd->dev); |
| 918 | host->power = true; |
| 919 | sh_mmcif_sync_reset(host); |
| 920 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 921 | sh_mmcif_clock_control(host, ios->clock); |
Guennadi Liakhovetski | c9b0cef | 2011-05-26 15:33:30 +0200 | [diff] [blame] | 922 | } |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 923 | |
| 924 | host->bus_width = ios->bus_width; |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 925 | host->state = STATE_IDLE; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Arnd Hannemann | 777271d | 2010-08-24 17:27:01 +0200 | [diff] [blame] | 928 | static int sh_mmcif_get_cd(struct mmc_host *mmc) |
| 929 | { |
| 930 | struct sh_mmcif_host *host = mmc_priv(mmc); |
| 931 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; |
| 932 | |
| 933 | if (!p->get_cd) |
| 934 | return -ENOSYS; |
| 935 | else |
| 936 | return p->get_cd(host->pd); |
| 937 | } |
| 938 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 939 | static struct mmc_host_ops sh_mmcif_ops = { |
| 940 | .request = sh_mmcif_request, |
| 941 | .set_ios = sh_mmcif_set_ios, |
Arnd Hannemann | 777271d | 2010-08-24 17:27:01 +0200 | [diff] [blame] | 942 | .get_cd = sh_mmcif_get_cd, |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 943 | }; |
| 944 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 945 | static irqreturn_t sh_mmcif_intr(int irq, void *dev_id) |
| 946 | { |
| 947 | struct sh_mmcif_host *host = dev_id; |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 948 | u32 state; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 949 | int err = 0; |
| 950 | |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 951 | state = sh_mmcif_readl(host->addr, MMCIF_CE_INT); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 952 | |
Guennadi Liakhovetski | 8a8284a | 2011-12-14 19:31:51 +0100 | [diff] [blame] | 953 | if (state & INT_ERR_STS) { |
| 954 | /* error interrupts - process first */ |
| 955 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state); |
| 956 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state); |
| 957 | err = 1; |
| 958 | } else if (state & INT_RBSYE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 959 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, |
| 960 | ~(INT_RBSYE | INT_CRSPE)); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 961 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MRBSYE); |
| 962 | } else if (state & INT_CRSPE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 963 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_CRSPE); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 964 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCRSPE); |
| 965 | } else if (state & INT_BUFREN) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 966 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFREN); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 967 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFREN); |
| 968 | } else if (state & INT_BUFWEN) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 969 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFWEN); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 970 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN); |
| 971 | } else if (state & INT_CMD12DRE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 972 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 973 | ~(INT_CMD12DRE | INT_CMD12RBE | |
| 974 | INT_CMD12CRE | INT_BUFRE)); |
| 975 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE); |
| 976 | } else if (state & INT_BUFRE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 977 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFRE); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 978 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFRE); |
| 979 | } else if (state & INT_DTRANE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 980 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_DTRANE); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 981 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MDTRANE); |
| 982 | } else if (state & INT_CMD12RBE) { |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 983 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 984 | ~(INT_CMD12RBE | INT_CMD12CRE)); |
| 985 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 986 | } else { |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 987 | dev_dbg(&host->pd->dev, "Unsupported interrupt: 0x%x\n", state); |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 988 | sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 989 | sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state); |
| 990 | err = 1; |
| 991 | } |
| 992 | if (err) { |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 993 | host->sd_error = true; |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 994 | dev_dbg(&host->pd->dev, "int err state = %08x\n", state); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 995 | } |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 996 | if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) |
| 997 | complete(&host->intr_wait); |
| 998 | else |
| 999 | dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1000 | |
| 1001 | return IRQ_HANDLED; |
| 1002 | } |
| 1003 | |
| 1004 | static int __devinit sh_mmcif_probe(struct platform_device *pdev) |
| 1005 | { |
| 1006 | int ret = 0, irq[2]; |
| 1007 | struct mmc_host *mmc; |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1008 | struct sh_mmcif_host *host; |
| 1009 | struct sh_mmcif_plat_data *pd; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1010 | struct resource *res; |
| 1011 | void __iomem *reg; |
| 1012 | char clk_name[8]; |
| 1013 | |
| 1014 | irq[0] = platform_get_irq(pdev, 0); |
| 1015 | irq[1] = platform_get_irq(pdev, 1); |
| 1016 | if (irq[0] < 0 || irq[1] < 0) { |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1017 | dev_err(&pdev->dev, "Get irq error\n"); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1018 | return -ENXIO; |
| 1019 | } |
| 1020 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1021 | if (!res) { |
| 1022 | dev_err(&pdev->dev, "platform_get_resource error.\n"); |
| 1023 | return -ENXIO; |
| 1024 | } |
| 1025 | reg = ioremap(res->start, resource_size(res)); |
| 1026 | if (!reg) { |
| 1027 | dev_err(&pdev->dev, "ioremap error.\n"); |
| 1028 | return -ENOMEM; |
| 1029 | } |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1030 | pd = pdev->dev.platform_data; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1031 | if (!pd) { |
| 1032 | dev_err(&pdev->dev, "sh_mmcif plat data error.\n"); |
| 1033 | ret = -ENXIO; |
| 1034 | goto clean_up; |
| 1035 | } |
| 1036 | mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev); |
| 1037 | if (!mmc) { |
| 1038 | ret = -ENOMEM; |
| 1039 | goto clean_up; |
| 1040 | } |
| 1041 | host = mmc_priv(mmc); |
| 1042 | host->mmc = mmc; |
| 1043 | host->addr = reg; |
| 1044 | host->timeout = 1000; |
| 1045 | |
| 1046 | snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id); |
| 1047 | host->hclk = clk_get(&pdev->dev, clk_name); |
| 1048 | if (IS_ERR(host->hclk)) { |
| 1049 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); |
| 1050 | ret = PTR_ERR(host->hclk); |
| 1051 | goto clean_up1; |
| 1052 | } |
| 1053 | clk_enable(host->hclk); |
| 1054 | host->clk = clk_get_rate(host->hclk); |
| 1055 | host->pd = pdev; |
| 1056 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 1057 | init_completion(&host->intr_wait); |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 1058 | spin_lock_init(&host->lock); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1059 | |
| 1060 | mmc->ops = &sh_mmcif_ops; |
| 1061 | mmc->f_max = host->clk; |
| 1062 | /* close to 400KHz */ |
| 1063 | if (mmc->f_max < 51200000) |
| 1064 | mmc->f_min = mmc->f_max / 128; |
| 1065 | else if (mmc->f_max < 102400000) |
| 1066 | mmc->f_min = mmc->f_max / 256; |
| 1067 | else |
| 1068 | mmc->f_min = mmc->f_max / 512; |
| 1069 | if (pd->ocr) |
| 1070 | mmc->ocr_avail = pd->ocr; |
| 1071 | mmc->caps = MMC_CAP_MMC_HIGHSPEED; |
| 1072 | if (pd->caps) |
| 1073 | mmc->caps |= pd->caps; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 1074 | mmc->max_segs = 32; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1075 | mmc->max_blk_size = 512; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 1076 | mmc->max_req_size = PAGE_CACHE_SIZE * mmc->max_segs; |
| 1077 | mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1078 | mmc->max_seg_size = mmc->max_req_size; |
| 1079 | |
| 1080 | sh_mmcif_sync_reset(host); |
| 1081 | platform_set_drvdata(pdev, host); |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 1082 | |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1083 | pm_runtime_enable(&pdev->dev); |
| 1084 | host->power = false; |
| 1085 | |
| 1086 | ret = pm_runtime_resume(&pdev->dev); |
| 1087 | if (ret < 0) |
| 1088 | goto clean_up2; |
Guennadi Liakhovetski | a782d68 | 2010-11-24 10:05:22 +0000 | [diff] [blame] | 1089 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1090 | mmc_add_host(mmc); |
| 1091 | |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 1092 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1093 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1094 | ret = request_irq(irq[0], sh_mmcif_intr, 0, "sh_mmc:error", host); |
| 1095 | if (ret) { |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1096 | dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1097 | goto clean_up3; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1098 | } |
| 1099 | ret = request_irq(irq[1], sh_mmcif_intr, 0, "sh_mmc:int", host); |
| 1100 | if (ret) { |
| 1101 | free_irq(irq[0], host); |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1102 | dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1103 | goto clean_up3; |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Guennadi Liakhovetski | ee4b888 | 2011-12-14 19:31:52 +0100 | [diff] [blame^] | 1106 | mmc_detect_change(host->mmc, 0); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1107 | |
Guennadi Liakhovetski | e47bf32 | 2010-11-24 10:05:18 +0000 | [diff] [blame] | 1108 | dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION); |
| 1109 | dev_dbg(&pdev->dev, "chip ver H'%04x\n", |
Magnus Damm | 487d9fc | 2010-05-18 14:42:51 +0000 | [diff] [blame] | 1110 | sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1111 | return ret; |
| 1112 | |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1113 | clean_up3: |
| 1114 | mmc_remove_host(mmc); |
| 1115 | pm_runtime_suspend(&pdev->dev); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1116 | clean_up2: |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1117 | pm_runtime_disable(&pdev->dev); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1118 | clk_disable(host->hclk); |
| 1119 | clean_up1: |
| 1120 | mmc_free_host(mmc); |
| 1121 | clean_up: |
| 1122 | if (reg) |
| 1123 | iounmap(reg); |
| 1124 | return ret; |
| 1125 | } |
| 1126 | |
| 1127 | static int __devexit sh_mmcif_remove(struct platform_device *pdev) |
| 1128 | { |
| 1129 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); |
| 1130 | int irq[2]; |
| 1131 | |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1132 | pm_runtime_get_sync(&pdev->dev); |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 1133 | |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1134 | mmc_remove_host(host->mmc); |
Guennadi Liakhovetski | 3b0beaf | 2011-04-15 18:30:47 +0000 | [diff] [blame] | 1135 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1136 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 1137 | if (host->addr) |
| 1138 | iounmap(host->addr); |
| 1139 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1140 | irq[0] = platform_get_irq(pdev, 0); |
| 1141 | irq[1] = platform_get_irq(pdev, 1); |
| 1142 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1143 | free_irq(irq[0], host); |
| 1144 | free_irq(irq[1], host); |
| 1145 | |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 1146 | platform_set_drvdata(pdev, NULL); |
| 1147 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1148 | clk_disable(host->hclk); |
| 1149 | mmc_free_host(host->mmc); |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1150 | pm_runtime_put_sync(&pdev->dev); |
| 1151 | pm_runtime_disable(&pdev->dev); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1156 | #ifdef CONFIG_PM |
| 1157 | static int sh_mmcif_suspend(struct device *dev) |
| 1158 | { |
| 1159 | struct platform_device *pdev = to_platform_device(dev); |
| 1160 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); |
| 1161 | int ret = mmc_suspend_host(host->mmc); |
| 1162 | |
| 1163 | if (!ret) { |
| 1164 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1165 | clk_disable(host->hclk); |
| 1166 | } |
| 1167 | |
| 1168 | return ret; |
| 1169 | } |
| 1170 | |
| 1171 | static int sh_mmcif_resume(struct device *dev) |
| 1172 | { |
| 1173 | struct platform_device *pdev = to_platform_device(dev); |
| 1174 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); |
| 1175 | |
| 1176 | clk_enable(host->hclk); |
| 1177 | |
| 1178 | return mmc_resume_host(host->mmc); |
| 1179 | } |
| 1180 | #else |
| 1181 | #define sh_mmcif_suspend NULL |
| 1182 | #define sh_mmcif_resume NULL |
| 1183 | #endif /* CONFIG_PM */ |
| 1184 | |
| 1185 | static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { |
| 1186 | .suspend = sh_mmcif_suspend, |
| 1187 | .resume = sh_mmcif_resume, |
| 1188 | }; |
| 1189 | |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1190 | static struct platform_driver sh_mmcif_driver = { |
| 1191 | .probe = sh_mmcif_probe, |
| 1192 | .remove = sh_mmcif_remove, |
| 1193 | .driver = { |
| 1194 | .name = DRIVER_NAME, |
Guennadi Liakhovetski | faca664 | 2011-05-05 16:20:48 +0000 | [diff] [blame] | 1195 | .pm = &sh_mmcif_dev_pm_ops, |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1196 | }, |
| 1197 | }; |
| 1198 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 1199 | module_platform_driver(sh_mmcif_driver); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1200 | |
| 1201 | MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver"); |
| 1202 | MODULE_LICENSE("GPL"); |
Guennadi Liakhovetski | aa0787a | 2010-11-24 10:05:12 +0000 | [diff] [blame] | 1203 | MODULE_ALIAS("platform:" DRIVER_NAME); |
Yusuke Goda | fdc50a9 | 2010-05-26 14:41:59 -0700 | [diff] [blame] | 1204 | MODULE_AUTHOR("Yusuke Goda <yusuke.goda.sx@renesas.com>"); |