blob: 5f06c79023060c9b5a881ea530cab93401dbc787 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Pierre Ossman70f10482007-07-11 20:04:50 +02002 * linux/drivers/mmc/host/pxa.c - PXA MMCI driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This hardware is really sick:
11 * - No way to clear interrupts.
12 * - Have to turn off the clock whenever we touch the device.
13 * - Doesn't tell you how many data blocks were transferred.
14 * Yuck!
15 *
16 * 1 and 3 byte data transfers not supported
17 * max block length up to 1023
18 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010022#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/delay.h>
24#include <linux/interrupt.h>
Daniel Mack6464b712015-06-06 23:15:22 +020025#include <linux/dmaengine.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/dma-mapping.h>
Russell Kingebebd9b2007-08-20 10:20:03 +010027#include <linux/clk.h>
28#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/mmc/host.h>
Robert Jarzmikfd546ee2015-09-26 21:41:01 +020030#include <linux/mmc/slot-gpio.h>
Russell King05678a92008-11-28 16:04:54 +000031#include <linux/io.h>
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030032#include <linux/regulator/consumer.h>
Robert Jarzmikb405db62009-06-23 23:21:03 +020033#include <linux/gpio.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/gfp.h>
Daniel Macke6027b42012-07-28 12:07:34 +020035#include <linux/of.h>
Daniel Macke6027b42012-07-28 12:07:34 +020036#include <linux/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/sizes.h>
39
Russell King05678a92008-11-28 16:04:54 +000040#include <mach/hardware.h>
Arnd Bergmann293b2da2012-08-24 15:16:48 +020041#include <linux/platform_data/mmc-pxamci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include "pxamci.h"
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define DRIVER_NAME "pxa2xx-mci"
46
47#define NR_SG 1
Russell Kingd8cb70d2007-10-26 17:56:40 +010048#define CLKRT_OFF (~0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Haojian Zhuangfa3f9932009-08-31 21:52:53 +080050#define mmc_has_26MHz() (cpu_is_pxa300() || cpu_is_pxa310() \
51 || cpu_is_pxa935())
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053struct pxamci_host {
54 struct mmc_host *mmc;
55 spinlock_t lock;
56 struct resource *res;
57 void __iomem *base;
Russell Kingebebd9b2007-08-20 10:20:03 +010058 struct clk *clk;
59 unsigned long clkrate;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 unsigned int clkrt;
61 unsigned int cmdat;
62 unsigned int imask;
63 unsigned int power_mode;
Daniel Mack38a8dda2018-07-03 22:10:26 +020064 unsigned long detect_delay_ms;
Linus Walleijc914a272018-12-02 09:43:24 +010065 bool use_ro_gpio;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 struct pxamci_platform_data *pdata;
67
68 struct mmc_request *mrq;
69 struct mmc_command *cmd;
70 struct mmc_data *data;
71
Daniel Mack6464b712015-06-06 23:15:22 +020072 struct dma_chan *dma_chan_rx;
73 struct dma_chan *dma_chan_tx;
74 dma_cookie_t dma_cookie;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 unsigned int dma_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 unsigned int dma_dir;
77};
78
Daniel Mack61951fd2018-06-30 20:14:05 +020079static int pxamci_init_ocr(struct pxamci_host *host)
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030080{
Daniel Mack61951fd2018-06-30 20:14:05 +020081 struct mmc_host *mmc = host->mmc;
82 int ret;
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030083
Daniel Mack61951fd2018-06-30 20:14:05 +020084 ret = mmc_regulator_get_supply(mmc);
85 if (ret < 0)
86 return ret;
87
88 if (IS_ERR(mmc->supply.vmmc)) {
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030089 /* fall-back to platform data */
Daniel Mack61951fd2018-06-30 20:14:05 +020090 mmc->ocr_avail = host->pdata ?
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030091 host->pdata->ocr_mask :
92 MMC_VDD_32_33 | MMC_VDD_33_34;
93 }
Daniel Mack61951fd2018-06-30 20:14:05 +020094
95 return 0;
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -030096}
97
Linus Walleij99fc5132010-09-29 01:08:27 -040098static inline int pxamci_set_power(struct pxamci_host *host,
99 unsigned char power_mode,
100 unsigned int vdd)
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -0300101{
Daniel Mack61951fd2018-06-30 20:14:05 +0200102 struct mmc_host *mmc = host->mmc;
103 struct regulator *supply = mmc->supply.vmmc;
Robert Jarzmikb405db62009-06-23 23:21:03 +0200104 int on;
105
Daniel Mack61951fd2018-06-30 20:14:05 +0200106 if (!IS_ERR(supply))
107 return mmc_regulator_set_ocr(mmc, supply, vdd);
Linus Walleij99fc5132010-09-29 01:08:27 -0400108
Daniel Mack61951fd2018-06-30 20:14:05 +0200109 if (host->pdata &&
Robert Jarzmikb405db62009-06-23 23:21:03 +0200110 gpio_is_valid(host->pdata->gpio_power)) {
111 on = ((1 << vdd) & host->pdata->ocr_mask);
112 gpio_set_value(host->pdata->gpio_power,
113 !!on ^ host->pdata->gpio_power_invert);
114 }
Daniel Mack61951fd2018-06-30 20:14:05 +0200115
116 if (host->pdata && host->pdata->setpower)
Arnd Bergmanna829abf2013-07-05 17:51:20 +0200117 return host->pdata->setpower(mmc_dev(host->mmc), vdd);
Linus Walleij99fc5132010-09-29 01:08:27 -0400118
119 return 0;
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -0300120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static void pxamci_stop_clock(struct pxamci_host *host)
123{
124 if (readl(host->base + MMC_STAT) & STAT_CLK_EN) {
125 unsigned long timeout = 10000;
126 unsigned int v;
127
128 writel(STOP_CLOCK, host->base + MMC_STRPCL);
129
130 do {
131 v = readl(host->base + MMC_STAT);
132 if (!(v & STAT_CLK_EN))
133 break;
134 udelay(1);
135 } while (timeout--);
136
137 if (v & STAT_CLK_EN)
138 dev_err(mmc_dev(host->mmc), "unable to stop clock\n");
139 }
140}
141
142static void pxamci_enable_irq(struct pxamci_host *host, unsigned int mask)
143{
144 unsigned long flags;
145
146 spin_lock_irqsave(&host->lock, flags);
147 host->imask &= ~mask;
148 writel(host->imask, host->base + MMC_I_MASK);
149 spin_unlock_irqrestore(&host->lock, flags);
150}
151
152static void pxamci_disable_irq(struct pxamci_host *host, unsigned int mask)
153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&host->lock, flags);
157 host->imask |= mask;
158 writel(host->imask, host->base + MMC_I_MASK);
159 spin_unlock_irqrestore(&host->lock, flags);
160}
161
Daniel Mack6464b712015-06-06 23:15:22 +0200162static void pxamci_dma_irq(void *param);
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
165{
Daniel Mack6464b712015-06-06 23:15:22 +0200166 struct dma_async_tx_descriptor *tx;
167 enum dma_data_direction direction;
168 struct dma_slave_config config;
169 struct dma_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 unsigned int nob = data->blocks;
Russell King3d63abe2006-04-24 11:27:02 +0100171 unsigned long long clks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 unsigned int timeout;
Daniel Mack6464b712015-06-06 23:15:22 +0200173 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 host->data = data;
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 writel(nob, host->base + MMC_NOB);
Pavel Pisa2c171bf2006-05-19 21:48:03 +0100178 writel(data->blksz, host->base + MMC_BLKLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Russell Kingebebd9b2007-08-20 10:20:03 +0100180 clks = (unsigned long long)data->timeout_ns * host->clkrate;
Russell King3d63abe2006-04-24 11:27:02 +0100181 do_div(clks, 1000000000UL);
182 timeout = (unsigned int)clks + (data->timeout_clks << host->clkrt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 writel((timeout + 255) / 256, host->base + MMC_RDTO);
184
Daniel Mack6464b712015-06-06 23:15:22 +0200185 memset(&config, 0, sizeof(config));
186 config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
187 config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
188 config.src_addr = host->res->start + MMC_RXFIFO;
189 config.dst_addr = host->res->start + MMC_TXFIFO;
190 config.src_maxburst = 32;
191 config.dst_maxburst = 32;
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (data->flags & MMC_DATA_READ) {
194 host->dma_dir = DMA_FROM_DEVICE;
Daniel Mack6464b712015-06-06 23:15:22 +0200195 direction = DMA_DEV_TO_MEM;
196 chan = host->dma_chan_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 } else {
198 host->dma_dir = DMA_TO_DEVICE;
Daniel Mack6464b712015-06-06 23:15:22 +0200199 direction = DMA_MEM_TO_DEV;
200 chan = host->dma_chan_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
202
Daniel Mack6464b712015-06-06 23:15:22 +0200203 config.direction = direction;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Daniel Mack6464b712015-06-06 23:15:22 +0200205 ret = dmaengine_slave_config(chan, &config);
206 if (ret < 0) {
207 dev_err(mmc_dev(host->mmc), "dma slave config failed\n");
208 return;
209 }
210
211 host->dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 host->dma_dir);
213
Daniel Mack6464b712015-06-06 23:15:22 +0200214 tx = dmaengine_prep_slave_sg(chan, data->sg, host->dma_len, direction,
215 DMA_PREP_INTERRUPT);
216 if (!tx) {
217 dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n");
218 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Daniel Mack6464b712015-06-06 23:15:22 +0200221 if (!(data->flags & MMC_DATA_READ)) {
222 tx->callback = pxamci_dma_irq;
223 tx->callback_param = host;
224 }
225
226 host->dma_cookie = dmaengine_submit(tx);
Cliff Brakeb6018952009-01-22 17:07:03 -0500227
228 /*
229 * workaround for erratum #91:
230 * only start DMA now if we are doing a read,
231 * otherwise we wait until CMD/RESP has finished
232 * before starting DMA.
233 */
234 if (!cpu_is_pxa27x() || data->flags & MMC_DATA_READ)
Daniel Mack6464b712015-06-06 23:15:22 +0200235 dma_async_issue_pending(chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd, unsigned int cmdat)
239{
240 WARN_ON(host->cmd != NULL);
241 host->cmd = cmd;
242
243 if (cmd->flags & MMC_RSP_BUSY)
244 cmdat |= CMDAT_BUSY;
245
Russell Kinge9225172006-02-02 12:23:12 +0000246#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
247 switch (RSP_TYPE(mmc_resp_type(cmd))) {
Philip Langdale6f949902007-01-04 07:04:47 -0800248 case RSP_TYPE(MMC_RSP_R1): /* r1, r1b, r6, r7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 cmdat |= CMDAT_RESP_SHORT;
250 break;
Russell Kinge9225172006-02-02 12:23:12 +0000251 case RSP_TYPE(MMC_RSP_R3):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 cmdat |= CMDAT_RESP_R3;
253 break;
Russell Kinge9225172006-02-02 12:23:12 +0000254 case RSP_TYPE(MMC_RSP_R2):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 cmdat |= CMDAT_RESP_R2;
256 break;
257 default:
258 break;
259 }
260
261 writel(cmd->opcode, host->base + MMC_CMD);
262 writel(cmd->arg >> 16, host->base + MMC_ARGH);
263 writel(cmd->arg & 0xffff, host->base + MMC_ARGL);
264 writel(cmdat, host->base + MMC_CMDAT);
265 writel(host->clkrt, host->base + MMC_CLKRT);
266
267 writel(START_CLOCK, host->base + MMC_STRPCL);
268
269 pxamci_enable_irq(host, END_CMD_RES);
270}
271
272static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq)
273{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 host->mrq = NULL;
275 host->cmd = NULL;
276 host->data = NULL;
277 mmc_request_done(host->mmc, mrq);
278}
279
280static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
281{
282 struct mmc_command *cmd = host->cmd;
283 int i;
284 u32 v;
285
286 if (!cmd)
287 return 0;
288
289 host->cmd = NULL;
290
291 /*
292 * Did I mention this is Sick. We always need to
293 * discard the upper 8 bits of the first 16-bit word.
294 */
295 v = readl(host->base + MMC_RES) & 0xffff;
296 for (i = 0; i < 4; i++) {
297 u32 w1 = readl(host->base + MMC_RES) & 0xffff;
298 u32 w2 = readl(host->base + MMC_RES) & 0xffff;
299 cmd->resp[i] = v << 24 | w1 << 8 | w2 >> 8;
300 v = w2;
301 }
302
303 if (stat & STAT_TIME_OUT_RESPONSE) {
Pierre Ossman17b04292007-07-22 22:18:46 +0200304 cmd->error = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 } else if (stat & STAT_RES_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /*
307 * workaround for erratum #42:
308 * Intel PXA27x Family Processor Specification Update Rev 001
Nicolas Pitre90e07d92007-05-13 18:03:08 +0200309 * A bogus CRC error can appear if the msb of a 136 bit
310 * response is a one.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
Cliff Brakee10a8542009-01-22 16:58:58 -0500312 if (cpu_is_pxa27x() &&
313 (cmd->flags & MMC_RSP_136 && cmd->resp[0] & 0x80000000))
Nicolas Pitre90e07d92007-05-13 18:03:08 +0200314 pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode);
Cliff Brakee10a8542009-01-22 16:58:58 -0500315 else
316 cmd->error = -EILSEQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
318
319 pxamci_disable_irq(host, END_CMD_RES);
Pierre Ossman17b04292007-07-22 22:18:46 +0200320 if (host->data && !cmd->error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 pxamci_enable_irq(host, DATA_TRAN_DONE);
Cliff Brakeb6018952009-01-22 17:07:03 -0500322 /*
323 * workaround for erratum #91, if doing write
324 * enable DMA late
325 */
326 if (cpu_is_pxa27x() && host->data->flags & MMC_DATA_WRITE)
Daniel Mack6464b712015-06-06 23:15:22 +0200327 dma_async_issue_pending(host->dma_chan_tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } else {
329 pxamci_finish_request(host, host->mrq);
330 }
331
332 return 1;
333}
334
335static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
336{
337 struct mmc_data *data = host->data;
Daniel Mack6464b712015-06-06 23:15:22 +0200338 struct dma_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (!data)
341 return 0;
342
Daniel Mack6464b712015-06-06 23:15:22 +0200343 if (data->flags & MMC_DATA_READ)
344 chan = host->dma_chan_rx;
345 else
346 chan = host->dma_chan_tx;
347 dma_unmap_sg(chan->device->dev,
348 data->sg, data->sg_len, host->dma_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350 if (stat & STAT_READ_TIME_OUT)
Pierre Ossman17b04292007-07-22 22:18:46 +0200351 data->error = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 else if (stat & (STAT_CRC_READ_ERROR|STAT_CRC_WRITE_ERROR))
Pierre Ossman17b04292007-07-22 22:18:46 +0200353 data->error = -EILSEQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 /*
356 * There appears to be a hardware design bug here. There seems to
357 * be no way to find out how much data was transferred to the card.
358 * This means that if there was an error on any block, we mark all
359 * data blocks as being in error.
360 */
Pierre Ossman17b04292007-07-22 22:18:46 +0200361 if (!data->error)
Pavel Pisa2c171bf2006-05-19 21:48:03 +0100362 data->bytes_xfered = data->blocks * data->blksz;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 else
364 data->bytes_xfered = 0;
365
366 pxamci_disable_irq(host, DATA_TRAN_DONE);
367
368 host->data = NULL;
Russell King58741e82006-05-02 20:02:39 +0100369 if (host->mrq->stop) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 pxamci_stop_clock(host);
Bridge Wudf456f42007-09-25 19:09:19 +0200371 pxamci_start_cmd(host, host->mrq->stop, host->cmdat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 } else {
373 pxamci_finish_request(host, host->mrq);
374 }
375
376 return 1;
377}
378
David Howells7d12e782006-10-05 14:55:46 +0100379static irqreturn_t pxamci_irq(int irq, void *devid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 struct pxamci_host *host = devid;
382 unsigned int ireg;
383 int handled = 0;
384
Bridge Wu81ab570f2007-09-25 18:59:07 +0200385 ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 if (ireg) {
388 unsigned stat = readl(host->base + MMC_STAT);
389
Russell Kingd78e9072006-05-02 20:18:53 +0100390 pr_debug("PXAMCI: irq %08x stat %08x\n", ireg, stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 if (ireg & END_CMD_RES)
393 handled |= pxamci_cmd_done(host, stat);
394 if (ireg & DATA_TRAN_DONE)
395 handled |= pxamci_data_done(host, stat);
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200396 if (ireg & SDIO_INT) {
397 mmc_signal_sdio_irq(host->mmc);
398 handled = 1;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
401
402 return IRQ_RETVAL(handled);
403}
404
405static void pxamci_request(struct mmc_host *mmc, struct mmc_request *mrq)
406{
407 struct pxamci_host *host = mmc_priv(mmc);
408 unsigned int cmdat;
409
410 WARN_ON(host->mrq != NULL);
411
412 host->mrq = mrq;
413
414 pxamci_stop_clock(host);
415
416 cmdat = host->cmdat;
417 host->cmdat &= ~CMDAT_INIT;
418
419 if (mrq->data) {
420 pxamci_setup_data(host, mrq->data);
421
422 cmdat &= ~CMDAT_BUSY;
423 cmdat |= CMDAT_DATAEN | CMDAT_DMAEN;
424 if (mrq->data->flags & MMC_DATA_WRITE)
425 cmdat |= CMDAT_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
427
428 pxamci_start_cmd(host, mrq->cmd, cmdat);
429}
430
Richard Purdiee6195242005-09-06 15:18:56 -0700431static int pxamci_get_ro(struct mmc_host *mmc)
432{
433 struct pxamci_host *host = mmc_priv(mmc);
434
Linus Walleijc914a272018-12-02 09:43:24 +0100435 if (host->use_ro_gpio)
Robert Jarzmikfd546ee2015-09-26 21:41:01 +0200436 return mmc_gpio_get_ro(mmc);
Richard Purdiee6195242005-09-06 15:18:56 -0700437 if (host->pdata && host->pdata->get_ro)
Anton Vorontsov08f80bb2008-06-17 18:17:39 +0400438 return !!host->pdata->get_ro(mmc_dev(mmc));
439 /*
440 * Board doesn't support read only detection; let the mmc core
441 * decide what to do.
442 */
443 return -ENOSYS;
Richard Purdiee6195242005-09-06 15:18:56 -0700444}
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
447{
448 struct pxamci_host *host = mmc_priv(mmc);
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (ios->clock) {
Russell Kingebebd9b2007-08-20 10:20:03 +0100451 unsigned long rate = host->clkrate;
452 unsigned int clk = rate / ios->clock;
453
Russell Kingd8cb70d2007-10-26 17:56:40 +0100454 if (host->clkrt == CLKRT_OFF)
Robert Jarzmike7370812014-09-02 11:23:55 +0200455 clk_prepare_enable(host->clk);
Russell Kingd8cb70d2007-10-26 17:56:40 +0100456
Bridge Wu64eb0362007-12-13 07:24:30 +0100457 if (ios->clock == 26000000) {
Haojian Zhuangfa3f9932009-08-31 21:52:53 +0800458 /* to support 26MHz */
Bridge Wu64eb0362007-12-13 07:24:30 +0100459 host->clkrt = 7;
460 } else {
461 /* to handle (19.5MHz, 26MHz) */
462 if (!clk)
463 clk = 1;
464
465 /*
466 * clk might result in a lower divisor than we
467 * desire. check for that condition and adjust
468 * as appropriate.
469 */
470 if (rate / clk > ios->clock)
471 clk <<= 1;
472 host->clkrt = fls(clk) - 1;
473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 /*
476 * we write clkrt on the next command
477 */
478 } else {
479 pxamci_stop_clock(host);
Russell Kingd8cb70d2007-10-26 17:56:40 +0100480 if (host->clkrt != CLKRT_OFF) {
481 host->clkrt = CLKRT_OFF;
Robert Jarzmike7370812014-09-02 11:23:55 +0200482 clk_disable_unprepare(host->clk);
Russell Kingd8cb70d2007-10-26 17:56:40 +0100483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485
486 if (host->power_mode != ios->power_mode) {
Linus Walleij99fc5132010-09-29 01:08:27 -0400487 int ret;
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 host->power_mode = ios->power_mode;
490
Linus Walleij99fc5132010-09-29 01:08:27 -0400491 ret = pxamci_set_power(host, ios->power_mode, ios->vdd);
492 if (ret) {
493 dev_err(mmc_dev(mmc), "unable to set power\n");
494 /*
495 * The .set_ios() function in the mmc_host_ops
496 * struct return void, and failing to set the
497 * power should be rare so we print an error and
498 * return here.
499 */
500 return;
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 if (ios->power_mode == MMC_POWER_ON)
504 host->cmdat |= CMDAT_INIT;
505 }
506
Bridge Wudf456f42007-09-25 19:09:19 +0200507 if (ios->bus_width == MMC_BUS_WIDTH_4)
508 host->cmdat |= CMDAT_SD_4DAT;
509 else
510 host->cmdat &= ~CMDAT_SD_4DAT;
511
Linus Walleij99fc5132010-09-29 01:08:27 -0400512 dev_dbg(mmc_dev(mmc), "PXAMCI: clkrt = %x cmdat = %x\n",
513 host->clkrt, host->cmdat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200516static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
517{
518 struct pxamci_host *pxa_host = mmc_priv(host);
519
520 if (enable)
521 pxamci_enable_irq(pxa_host, SDIO_INT);
522 else
523 pxamci_disable_irq(pxa_host, SDIO_INT);
524}
525
David Brownellab7aefd2006-11-12 17:55:30 -0800526static const struct mmc_host_ops pxamci_ops = {
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200527 .request = pxamci_request,
Robert Jarzmikfd546ee2015-09-26 21:41:01 +0200528 .get_cd = mmc_gpio_get_cd,
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200529 .get_ro = pxamci_get_ro,
530 .set_ios = pxamci_set_ios,
531 .enable_sdio_irq = pxamci_enable_sdio_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532};
533
Daniel Mack6464b712015-06-06 23:15:22 +0200534static void pxamci_dma_irq(void *param)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Daniel Mack6464b712015-06-06 23:15:22 +0200536 struct pxamci_host *host = param;
537 struct dma_tx_state state;
538 enum dma_status status;
539 struct dma_chan *chan;
540 unsigned long flags;
Nicolas Pitrec7838372007-10-09 17:07:58 -0400541
Daniel Mack6464b712015-06-06 23:15:22 +0200542 spin_lock_irqsave(&host->lock, flags);
543
544 if (!host->data)
545 goto out_unlock;
546
547 if (host->data->flags & MMC_DATA_READ)
548 chan = host->dma_chan_rx;
549 else
550 chan = host->dma_chan_tx;
551
552 status = dmaengine_tx_status(chan, host->dma_cookie, &state);
553
554 if (likely(status == DMA_COMPLETE)) {
Nicolas Pitrec7838372007-10-09 17:07:58 -0400555 writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
556 } else {
Daniel Mack6464b712015-06-06 23:15:22 +0200557 pr_err("%s: DMA error on %s channel\n", mmc_hostname(host->mmc),
558 host->data->flags & MMC_DATA_READ ? "rx" : "tx");
Nicolas Pitrec7838372007-10-09 17:07:58 -0400559 host->data->error = -EIO;
560 pxamci_data_done(host, 0);
561 }
Daniel Mack6464b712015-06-06 23:15:22 +0200562
563out_unlock:
564 spin_unlock_irqrestore(&host->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565}
566
David Howells7d12e782006-10-05 14:55:46 +0100567static irqreturn_t pxamci_detect_irq(int irq, void *devid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Richard Purdiec26971c2005-09-08 22:48:16 +0100569 struct pxamci_host *host = mmc_priv(devid);
570
Daniel Mack38a8dda2018-07-03 22:10:26 +0200571 mmc_detect_change(devid, msecs_to_jiffies(host->detect_delay_ms));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return IRQ_HANDLED;
573}
574
Daniel Macke6027b42012-07-28 12:07:34 +0200575#ifdef CONFIG_OF
576static const struct of_device_id pxa_mmc_dt_ids[] = {
577 { .compatible = "marvell,pxa-mmc" },
578 { }
579};
580
581MODULE_DEVICE_TABLE(of, pxa_mmc_dt_ids);
582
Daniel Mackfa3a5112018-06-30 20:14:03 +0200583static int pxamci_of_init(struct platform_device *pdev,
584 struct mmc_host *mmc)
Daniel Macke6027b42012-07-28 12:07:34 +0200585{
Daniel Mack0da53582018-06-30 20:14:02 +0200586 struct device_node *np = pdev->dev.of_node;
Daniel Mack38a8dda2018-07-03 22:10:26 +0200587 struct pxamci_host *host = mmc_priv(mmc);
Daniel Mack0da53582018-06-30 20:14:02 +0200588 u32 tmp;
Daniel Mackfa3a5112018-06-30 20:14:03 +0200589 int ret;
Daniel Macke6027b42012-07-28 12:07:34 +0200590
Daniel Mack0da53582018-06-30 20:14:02 +0200591 if (!np)
592 return 0;
Daniel Macke6027b42012-07-28 12:07:34 +0200593
Daniel Macke6027b42012-07-28 12:07:34 +0200594 /* pxa-mmc specific */
Daniel Macke6027b42012-07-28 12:07:34 +0200595 if (of_property_read_u32(np, "pxa-mmc,detect-delay-ms", &tmp) == 0)
Daniel Mack38a8dda2018-07-03 22:10:26 +0200596 host->detect_delay_ms = tmp;
Daniel Macke6027b42012-07-28 12:07:34 +0200597
Daniel Mackfa3a5112018-06-30 20:14:03 +0200598 ret = mmc_of_parse(mmc);
599 if (ret < 0)
600 return ret;
601
Daniel Mack0da53582018-06-30 20:14:02 +0200602 return 0;
Daniel Macke6027b42012-07-28 12:07:34 +0200603}
604#else
Daniel Mackfa3a5112018-06-30 20:14:03 +0200605static int pxamci_of_init(struct platform_device *pdev,
606 struct mmc_host *mmc)
Daniel Macke6027b42012-07-28 12:07:34 +0200607{
608 return 0;
609}
610#endif
611
Russell King3ae5eae2005-11-09 22:32:44 +0000612static int pxamci_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 struct mmc_host *mmc;
615 struct pxamci_host *host = NULL;
Daniel Mack23f3ff72018-07-03 22:10:27 +0200616 struct device *dev = &pdev->dev;
Robert Jarzmik6b3348f9e2018-06-17 19:02:07 +0200617 struct resource *r;
Daniel Mack38a8dda2018-07-03 22:10:26 +0200618 int ret, irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
621 irq = platform_get_irq(pdev, 0);
Robert Jarzmik07e77162016-02-08 15:17:57 +0100622 if (irq < 0)
623 return irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Daniel Mack23f3ff72018-07-03 22:10:27 +0200625 mmc = mmc_alloc_host(sizeof(struct pxamci_host), dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 if (!mmc) {
627 ret = -ENOMEM;
628 goto out;
629 }
630
631 mmc->ops = &pxamci_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /*
634 * We can do SG-DMA, but we don't because we never know how much
635 * data we successfully wrote to the card.
636 */
Martin K. Petersena36274e2010-09-10 01:33:59 -0400637 mmc->max_segs = NR_SG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 /*
640 * Our hardware DMA can handle a maximum of one page per SG entry.
641 */
642 mmc->max_seg_size = PAGE_SIZE;
643
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +0100644 /*
Nicolas Pitrefe2dc442007-09-24 15:47:18 -0400645 * Block length register is only 10 bits before PXA27x.
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +0100646 */
Eric Miao0ffcbfd2008-09-11 10:27:30 +0800647 mmc->max_blk_size = cpu_is_pxa25x() ? 1023 : 2048;
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +0100648
Pierre Ossman55db8902006-11-21 17:55:45 +0100649 /*
650 * Block count register is 16 bits.
651 */
652 mmc->max_blk_count = 65535;
653
Daniel Mackfa3a5112018-06-30 20:14:03 +0200654 ret = pxamci_of_init(pdev, mmc);
655 if (ret)
656 return ret;
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 host = mmc_priv(mmc);
659 host->mmc = mmc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 host->pdata = pdev->dev.platform_data;
Russell Kingd8cb70d2007-10-26 17:56:40 +0100661 host->clkrt = CLKRT_OFF;
Russell Kingebebd9b2007-08-20 10:20:03 +0100662
Daniel Mack23f3ff72018-07-03 22:10:27 +0200663 host->clk = devm_clk_get(dev, NULL);
Russell Kingebebd9b2007-08-20 10:20:03 +0100664 if (IS_ERR(host->clk)) {
665 ret = PTR_ERR(host->clk);
666 host->clk = NULL;
667 goto out;
668 }
669
670 host->clkrate = clk_get_rate(host->clk);
671
672 /*
673 * Calculate minimum clock rate, rounding up.
674 */
675 mmc->f_min = (host->clkrate + 63) / 64;
Haojian Zhuangfa3f9932009-08-31 21:52:53 +0800676 mmc->f_max = (mmc_has_26MHz()) ? 26000000 : host->clkrate;
Russell Kingebebd9b2007-08-20 10:20:03 +0100677
Daniel Mack61951fd2018-06-30 20:14:05 +0200678 ret = pxamci_init_ocr(host);
679 if (ret < 0)
680 return ret;
Daniel Ribeiro8385f9c2009-05-21 08:54:18 -0300681
Linus Walleijde3ee992017-09-20 10:56:14 +0200682 mmc->caps = 0;
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200683 host->cmdat = 0;
Eric Miao0ffcbfd2008-09-11 10:27:30 +0800684 if (!cpu_is_pxa25x()) {
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200685 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
686 host->cmdat |= CMDAT_SDIO_INT_EN;
Haojian Zhuangfa3f9932009-08-31 21:52:53 +0800687 if (mmc_has_26MHz())
Bridge Wu64eb0362007-12-13 07:24:30 +0100688 mmc->caps |= MMC_CAP_MMC_HIGHSPEED |
689 MMC_CAP_SD_HIGHSPEED;
Bridge Wu5d3ad4e2007-09-25 19:11:00 +0200690 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 spin_lock_init(&host->lock);
693 host->res = r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 host->imask = MMC_I_MASK_ALL;
695
Daniel Mack23f3ff72018-07-03 22:10:27 +0200696 host->base = devm_ioremap_resource(dev, r);
Robert Jarzmik07e77162016-02-08 15:17:57 +0100697 if (IS_ERR(host->base)) {
698 ret = PTR_ERR(host->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 goto out;
700 }
701
702 /*
703 * Ensure that the host controller is shut down, and setup
704 * with our defaults.
705 */
706 pxamci_stop_clock(host);
707 writel(0, host->base + MMC_SPI);
708 writel(64, host->base + MMC_RESTO);
709 writel(host->imask, host->base + MMC_I_MASK);
710
Daniel Mack23f3ff72018-07-03 22:10:27 +0200711 ret = devm_request_irq(dev, irq, pxamci_irq, 0,
Robert Jarzmik07e77162016-02-08 15:17:57 +0100712 DRIVER_NAME, host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (ret)
714 goto out;
715
Russell King3ae5eae2005-11-09 22:32:44 +0000716 platform_set_drvdata(pdev, mmc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Daniel Mack23f3ff72018-07-03 22:10:27 +0200718 host->dma_chan_rx = dma_request_slave_channel(dev, "rx");
Daniel Mack6464b712015-06-06 23:15:22 +0200719 if (host->dma_chan_rx == NULL) {
Daniel Mack23f3ff72018-07-03 22:10:27 +0200720 dev_err(dev, "unable to request rx dma channel\n");
Daniel Mack6464b712015-06-06 23:15:22 +0200721 ret = -ENODEV;
Bridge Wu9a788c62007-12-14 10:40:25 +0100722 goto out;
723 }
Daniel Mack6464b712015-06-06 23:15:22 +0200724
Daniel Mack23f3ff72018-07-03 22:10:27 +0200725 host->dma_chan_tx = dma_request_slave_channel(dev, "tx");
Daniel Mack6464b712015-06-06 23:15:22 +0200726 if (host->dma_chan_tx == NULL) {
Daniel Mack23f3ff72018-07-03 22:10:27 +0200727 dev_err(dev, "unable to request tx dma channel\n");
Daniel Mack6464b712015-06-06 23:15:22 +0200728 ret = -ENODEV;
729 goto out;
730 }
Bridge Wu9a788c62007-12-14 10:40:25 +0100731
Robert Jarzmikb405db62009-06-23 23:21:03 +0200732 if (host->pdata) {
Daniel Mack38a8dda2018-07-03 22:10:26 +0200733 int gpio_cd = host->pdata->gpio_card_detect;
734 int gpio_ro = host->pdata->gpio_card_ro;
735 int gpio_power = host->pdata->gpio_power;
736
737 host->detect_delay_ms = host->pdata->detect_delay_ms;
738
739 if (gpio_is_valid(gpio_power)) {
Daniel Mack23f3ff72018-07-03 22:10:27 +0200740 ret = devm_gpio_request(dev, gpio_power,
Daniel Mack38a8dda2018-07-03 22:10:26 +0200741 "mmc card power");
742 if (ret) {
Daniel Mack23f3ff72018-07-03 22:10:27 +0200743 dev_err(dev,
Daniel Mack38a8dda2018-07-03 22:10:26 +0200744 "Failed requesting gpio_power %d\n",
745 gpio_power);
746 goto out;
747 }
748 gpio_direction_output(gpio_power,
749 host->pdata->gpio_power_invert);
750 }
751
Linus Walleijc914a272018-12-02 09:43:24 +0100752 /* FIXME: should we pass detection delay to debounce? */
753 ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL);
754 if (ret && ret != -ENOENT) {
755 dev_err(dev, "Failed requesting gpio_cd\n");
756 goto out;
757 }
758 if (ret == -ENOENT && gpio_is_valid(gpio_cd)) {
759 ret = mmc_gpio_request_cd(mmc, gpio_cd, 0);
760 if (ret) {
761 dev_err(dev, "Failed requesting gpio_cd %d\n",
762 gpio_cd);
763 }
764 }
765
766 ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0, NULL);
767 if (ret && ret != -ENOENT) {
768 dev_err(dev, "Failed requesting gpio_ro\n");
769 goto out;
770 }
771 /* Try platform data instead */
772 if (ret == -ENOENT && gpio_is_valid(gpio_ro)) {
Daniel Mack38a8dda2018-07-03 22:10:26 +0200773 ret = mmc_gpio_request_ro(mmc, gpio_ro);
774 if (ret) {
Daniel Mack23f3ff72018-07-03 22:10:27 +0200775 dev_err(dev,
Daniel Mack38a8dda2018-07-03 22:10:26 +0200776 "Failed requesting gpio_ro %d\n",
777 gpio_ro);
778 goto out;
Daniel Mack38a8dda2018-07-03 22:10:26 +0200779 }
780 }
Linus Walleijc914a272018-12-02 09:43:24 +0100781 if (!ret) {
782 host->use_ro_gpio = true;
783 mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
784 0 : MMC_CAP2_RO_ACTIVE_HIGH;
Robert Jarzmikb405db62009-06-23 23:21:03 +0200785 }
Robert Jarzmikb405db62009-06-23 23:21:03 +0200786
Daniel Mack38a8dda2018-07-03 22:10:26 +0200787 if (host->pdata->init)
Daniel Mack23f3ff72018-07-03 22:10:27 +0200788 host->pdata->init(dev, pxamci_detect_irq, mmc);
Daniel Mack38a8dda2018-07-03 22:10:26 +0200789
790 if (gpio_is_valid(gpio_power) && host->pdata->setpower)
Daniel Mack23f3ff72018-07-03 22:10:27 +0200791 dev_warn(dev, "gpio_power and setpower() both defined\n");
Linus Walleijc914a272018-12-02 09:43:24 +0100792 if (host->use_ro_gpio && host->pdata->get_ro)
Daniel Mack23f3ff72018-07-03 22:10:27 +0200793 dev_warn(dev, "gpio_ro and get_ro() both defined\n");
Robert Jarzmikb405db62009-06-23 23:21:03 +0200794 }
795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 mmc_add_host(mmc);
797
798 return 0;
799
Robert Jarzmikfd546ee2015-09-26 21:41:01 +0200800out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (host) {
Daniel Mack6464b712015-06-06 23:15:22 +0200802 if (host->dma_chan_rx)
803 dma_release_channel(host->dma_chan_rx);
804 if (host->dma_chan_tx)
805 dma_release_channel(host->dma_chan_tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
807 if (mmc)
808 mmc_free_host(mmc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 return ret;
810}
811
Russell King3ae5eae2005-11-09 22:32:44 +0000812static int pxamci_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Russell King3ae5eae2005-11-09 22:32:44 +0000814 struct mmc_host *mmc = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 if (mmc) {
817 struct pxamci_host *host = mmc_priv(mmc);
818
Daniel Mack5d6b1edf2009-12-01 18:17:18 +0100819 mmc_remove_host(mmc);
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 if (host->pdata && host->pdata->exit)
Russell King3ae5eae2005-11-09 22:32:44 +0000822 host->pdata->exit(&pdev->dev, mmc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 pxamci_stop_clock(host);
825 writel(TXFIFO_WR_REQ|RXFIFO_RD_REQ|CLK_IS_OFF|STOP_CMD|
826 END_CMD_RES|PRG_DONE|DATA_TRAN_DONE,
827 host->base + MMC_I_MASK);
828
Daniel Mack6464b712015-06-06 23:15:22 +0200829 dmaengine_terminate_all(host->dma_chan_rx);
830 dmaengine_terminate_all(host->dma_chan_tx);
831 dma_release_channel(host->dma_chan_rx);
832 dma_release_channel(host->dma_chan_tx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 mmc_free_host(mmc);
835 }
Daniel Mack52c09182018-06-30 20:14:01 +0200836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 return 0;
838}
839
Russell King3ae5eae2005-11-09 22:32:44 +0000840static struct platform_driver pxamci_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .probe = pxamci_probe,
842 .remove = pxamci_remove,
Russell King3ae5eae2005-11-09 22:32:44 +0000843 .driver = {
844 .name = DRIVER_NAME,
Daniel Macke6027b42012-07-28 12:07:34 +0200845 .of_match_table = of_match_ptr(pxa_mmc_dt_ids),
Russell King3ae5eae2005-11-09 22:32:44 +0000846 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847};
848
Axel Lind1f81a62011-11-26 12:55:43 +0800849module_platform_driver(pxamci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851MODULE_DESCRIPTION("PXA Multimedia Card Interface Driver");
852MODULE_LICENSE("GPL");
Kay Sieversbc65c722008-04-15 14:34:28 -0700853MODULE_ALIAS("platform:pxa2xx-mci");