bc7669d50c38afeabaee4b287f72463b2887b40a
[platform/kernel/linux-rpi.git] / drivers / mmc / host / mmci.c
1 /*
2  *  linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
3  *
4  *  Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
5  *  Copyright (C) 2010 ST-Ericsson SA
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 version 2 as
9  * published by the Free Software Foundation.
10  */
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/device.h>
16 #include <linux/io.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/delay.h>
21 #include <linux/err.h>
22 #include <linux/highmem.h>
23 #include <linux/log2.h>
24 #include <linux/mmc/pm.h>
25 #include <linux/mmc/host.h>
26 #include <linux/mmc/card.h>
27 #include <linux/mmc/slot-gpio.h>
28 #include <linux/amba/bus.h>
29 #include <linux/clk.h>
30 #include <linux/scatterlist.h>
31 #include <linux/gpio.h>
32 #include <linux/of_gpio.h>
33 #include <linux/regulator/consumer.h>
34 #include <linux/dmaengine.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/amba/mmci.h>
37 #include <linux/pm_runtime.h>
38 #include <linux/types.h>
39 #include <linux/pinctrl/consumer.h>
40
41 #include <asm/div64.h>
42 #include <asm/io.h>
43
44 #include "mmci.h"
45 #include "mmci_qcom_dml.h"
46
47 #define DRIVER_NAME "mmci-pl18x"
48
49 static unsigned int fmax = 515633;
50
51 /**
52  * struct variant_data - MMCI variant-specific quirks
53  * @clkreg: default value for MCICLOCK register
54  * @clkreg_enable: enable value for MMCICLOCK register
55  * @clkreg_8bit_bus_enable: enable value for 8 bit bus
56  * @clkreg_neg_edge_enable: enable value for inverted data/cmd output
57  * @datalength_bits: number of bits in the MMCIDATALENGTH register
58  * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
59  *            is asserted (likewise for RX)
60  * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
61  *                is asserted (likewise for RX)
62  * @data_cmd_enable: enable value for data commands.
63  * @st_sdio: enable ST specific SDIO logic
64  * @st_clkdiv: true if using a ST-specific clock divider algorithm
65  * @datactrl_mask_ddrmode: ddr mode mask in datactrl register.
66  * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
67  * @blksz_datactrl4: true if Block size is at b4..b16 position in datactrl
68  *                   register
69  * @datactrl_mask_sdio: SDIO enable mask in datactrl register
70  * @pwrreg_powerup: power up value for MMCIPOWER register
71  * @f_max: maximum clk frequency supported by the controller.
72  * @signal_direction: input/out direction of bus signals can be indicated
73  * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock
74  * @busy_detect: true if the variant supports busy detection on DAT0.
75  * @busy_dpsm_flag: bitmask enabling busy detection in the DPSM
76  * @busy_detect_flag: bitmask identifying the bit in the MMCISTATUS register
77  *                    indicating that the card is busy
78  * @busy_detect_mask: bitmask identifying the bit in the MMCIMASK0 to mask for
79  *                    getting busy end detection interrupts
80  * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply
81  * @explicit_mclk_control: enable explicit mclk control in driver.
82  * @qcom_fifo: enables qcom specific fifo pio read logic.
83  * @qcom_dml: enables qcom specific dma glue for dma transfers.
84  * @reversed_irq_handling: handle data irq before cmd irq.
85  * @mmcimask1: true if variant have a MMCIMASK1 register.
86  */
87 struct variant_data {
88         unsigned int            clkreg;
89         unsigned int            clkreg_enable;
90         unsigned int            clkreg_8bit_bus_enable;
91         unsigned int            clkreg_neg_edge_enable;
92         unsigned int            datalength_bits;
93         unsigned int            fifosize;
94         unsigned int            fifohalfsize;
95         unsigned int            data_cmd_enable;
96         unsigned int            datactrl_mask_ddrmode;
97         unsigned int            datactrl_mask_sdio;
98         bool                    st_sdio;
99         bool                    st_clkdiv;
100         bool                    blksz_datactrl16;
101         bool                    blksz_datactrl4;
102         u32                     pwrreg_powerup;
103         u32                     f_max;
104         bool                    signal_direction;
105         bool                    pwrreg_clkgate;
106         bool                    busy_detect;
107         u32                     busy_dpsm_flag;
108         u32                     busy_detect_flag;
109         u32                     busy_detect_mask;
110         bool                    pwrreg_nopower;
111         bool                    explicit_mclk_control;
112         bool                    qcom_fifo;
113         bool                    qcom_dml;
114         bool                    reversed_irq_handling;
115         bool                    mmcimask1;
116 };
117
118 static struct variant_data variant_arm = {
119         .fifosize               = 16 * 4,
120         .fifohalfsize           = 8 * 4,
121         .datalength_bits        = 16,
122         .pwrreg_powerup         = MCI_PWR_UP,
123         .f_max                  = 100000000,
124         .reversed_irq_handling  = true,
125         .mmcimask1              = true,
126 };
127
128 static struct variant_data variant_arm_extended_fifo = {
129         .fifosize               = 128 * 4,
130         .fifohalfsize           = 64 * 4,
131         .datalength_bits        = 16,
132         .pwrreg_powerup         = MCI_PWR_UP,
133         .f_max                  = 100000000,
134         .mmcimask1              = true,
135 };
136
137 static struct variant_data variant_arm_extended_fifo_hwfc = {
138         .fifosize               = 128 * 4,
139         .fifohalfsize           = 64 * 4,
140         .clkreg_enable          = MCI_ARM_HWFCEN,
141         .datalength_bits        = 16,
142         .pwrreg_powerup         = MCI_PWR_UP,
143         .f_max                  = 100000000,
144         .mmcimask1              = true,
145 };
146
147 static struct variant_data variant_u300 = {
148         .fifosize               = 16 * 4,
149         .fifohalfsize           = 8 * 4,
150         .clkreg_enable          = MCI_ST_U300_HWFCEN,
151         .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
152         .datalength_bits        = 16,
153         .datactrl_mask_sdio     = MCI_DPSM_ST_SDIOEN,
154         .st_sdio                        = true,
155         .pwrreg_powerup         = MCI_PWR_ON,
156         .f_max                  = 100000000,
157         .signal_direction       = true,
158         .pwrreg_clkgate         = true,
159         .pwrreg_nopower         = true,
160         .mmcimask1              = true,
161 };
162
163 static struct variant_data variant_nomadik = {
164         .fifosize               = 16 * 4,
165         .fifohalfsize           = 8 * 4,
166         .clkreg                 = MCI_CLK_ENABLE,
167         .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
168         .datalength_bits        = 24,
169         .datactrl_mask_sdio     = MCI_DPSM_ST_SDIOEN,
170         .st_sdio                = true,
171         .st_clkdiv              = true,
172         .pwrreg_powerup         = MCI_PWR_ON,
173         .f_max                  = 100000000,
174         .signal_direction       = true,
175         .pwrreg_clkgate         = true,
176         .pwrreg_nopower         = true,
177         .mmcimask1              = true,
178 };
179
180 static struct variant_data variant_ux500 = {
181         .fifosize               = 30 * 4,
182         .fifohalfsize           = 8 * 4,
183         .clkreg                 = MCI_CLK_ENABLE,
184         .clkreg_enable          = MCI_ST_UX500_HWFCEN,
185         .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
186         .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
187         .datalength_bits        = 24,
188         .datactrl_mask_sdio     = MCI_DPSM_ST_SDIOEN,
189         .st_sdio                = true,
190         .st_clkdiv              = true,
191         .pwrreg_powerup         = MCI_PWR_ON,
192         .f_max                  = 100000000,
193         .signal_direction       = true,
194         .pwrreg_clkgate         = true,
195         .busy_detect            = true,
196         .busy_dpsm_flag         = MCI_DPSM_ST_BUSYMODE,
197         .busy_detect_flag       = MCI_ST_CARDBUSY,
198         .busy_detect_mask       = MCI_ST_BUSYENDMASK,
199         .pwrreg_nopower         = true,
200         .mmcimask1              = true,
201 };
202
203 static struct variant_data variant_ux500v2 = {
204         .fifosize               = 30 * 4,
205         .fifohalfsize           = 8 * 4,
206         .clkreg                 = MCI_CLK_ENABLE,
207         .clkreg_enable          = MCI_ST_UX500_HWFCEN,
208         .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
209         .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
210         .datactrl_mask_ddrmode  = MCI_DPSM_ST_DDRMODE,
211         .datalength_bits        = 24,
212         .datactrl_mask_sdio     = MCI_DPSM_ST_SDIOEN,
213         .st_sdio                = true,
214         .st_clkdiv              = true,
215         .blksz_datactrl16       = true,
216         .pwrreg_powerup         = MCI_PWR_ON,
217         .f_max                  = 100000000,
218         .signal_direction       = true,
219         .pwrreg_clkgate         = true,
220         .busy_detect            = true,
221         .busy_dpsm_flag         = MCI_DPSM_ST_BUSYMODE,
222         .busy_detect_flag       = MCI_ST_CARDBUSY,
223         .busy_detect_mask       = MCI_ST_BUSYENDMASK,
224         .pwrreg_nopower         = true,
225         .mmcimask1              = true,
226 };
227
228 static struct variant_data variant_qcom = {
229         .fifosize               = 16 * 4,
230         .fifohalfsize           = 8 * 4,
231         .clkreg                 = MCI_CLK_ENABLE,
232         .clkreg_enable          = MCI_QCOM_CLK_FLOWENA |
233                                   MCI_QCOM_CLK_SELECT_IN_FBCLK,
234         .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8,
235         .datactrl_mask_ddrmode  = MCI_QCOM_CLK_SELECT_IN_DDR_MODE,
236         .data_cmd_enable        = MCI_CPSM_QCOM_DATCMD,
237         .blksz_datactrl4        = true,
238         .datalength_bits        = 24,
239         .pwrreg_powerup         = MCI_PWR_UP,
240         .f_max                  = 208000000,
241         .explicit_mclk_control  = true,
242         .qcom_fifo              = true,
243         .qcom_dml               = true,
244         .mmcimask1              = true,
245 };
246
247 /* Busy detection for the ST Micro variant */
248 static int mmci_card_busy(struct mmc_host *mmc)
249 {
250         struct mmci_host *host = mmc_priv(mmc);
251         unsigned long flags;
252         int busy = 0;
253
254         spin_lock_irqsave(&host->lock, flags);
255         if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag)
256                 busy = 1;
257         spin_unlock_irqrestore(&host->lock, flags);
258
259         return busy;
260 }
261
262 /*
263  * Validate mmc prerequisites
264  */
265 static int mmci_validate_data(struct mmci_host *host,
266                               struct mmc_data *data)
267 {
268         if (!data)
269                 return 0;
270
271         if (!is_power_of_2(data->blksz)) {
272                 dev_err(mmc_dev(host->mmc),
273                         "unsupported block size (%d bytes)\n", data->blksz);
274                 return -EINVAL;
275         }
276
277         return 0;
278 }
279
280 static void mmci_reg_delay(struct mmci_host *host)
281 {
282         /*
283          * According to the spec, at least three feedback clock cycles
284          * of max 52 MHz must pass between two writes to the MMCICLOCK reg.
285          * Three MCLK clock cycles must pass between two MMCIPOWER reg writes.
286          * Worst delay time during card init is at 100 kHz => 30 us.
287          * Worst delay time when up and running is at 25 MHz => 120 ns.
288          */
289         if (host->cclk < 25000000)
290                 udelay(30);
291         else
292                 ndelay(120);
293 }
294
295 /*
296  * This must be called with host->lock held
297  */
298 static void mmci_write_clkreg(struct mmci_host *host, u32 clk)
299 {
300         if (host->clk_reg != clk) {
301                 host->clk_reg = clk;
302                 writel(clk, host->base + MMCICLOCK);
303         }
304 }
305
306 /*
307  * This must be called with host->lock held
308  */
309 static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
310 {
311         if (host->pwr_reg != pwr) {
312                 host->pwr_reg = pwr;
313                 writel(pwr, host->base + MMCIPOWER);
314         }
315 }
316
317 /*
318  * This must be called with host->lock held
319  */
320 static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl)
321 {
322         /* Keep busy mode in DPSM if enabled */
323         datactrl |= host->datactrl_reg & host->variant->busy_dpsm_flag;
324
325         if (host->datactrl_reg != datactrl) {
326                 host->datactrl_reg = datactrl;
327                 writel(datactrl, host->base + MMCIDATACTRL);
328         }
329 }
330
331 /*
332  * This must be called with host->lock held
333  */
334 static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
335 {
336         struct variant_data *variant = host->variant;
337         u32 clk = variant->clkreg;
338
339         /* Make sure cclk reflects the current calculated clock */
340         host->cclk = 0;
341
342         if (desired) {
343                 if (variant->explicit_mclk_control) {
344                         host->cclk = host->mclk;
345                 } else if (desired >= host->mclk) {
346                         clk = MCI_CLK_BYPASS;
347                         if (variant->st_clkdiv)
348                                 clk |= MCI_ST_UX500_NEG_EDGE;
349                         host->cclk = host->mclk;
350                 } else if (variant->st_clkdiv) {
351                         /*
352                          * DB8500 TRM says f = mclk / (clkdiv + 2)
353                          * => clkdiv = (mclk / f) - 2
354                          * Round the divider up so we don't exceed the max
355                          * frequency
356                          */
357                         clk = DIV_ROUND_UP(host->mclk, desired) - 2;
358                         if (clk >= 256)
359                                 clk = 255;
360                         host->cclk = host->mclk / (clk + 2);
361                 } else {
362                         /*
363                          * PL180 TRM says f = mclk / (2 * (clkdiv + 1))
364                          * => clkdiv = mclk / (2 * f) - 1
365                          */
366                         clk = host->mclk / (2 * desired) - 1;
367                         if (clk >= 256)
368                                 clk = 255;
369                         host->cclk = host->mclk / (2 * (clk + 1));
370                 }
371
372                 clk |= variant->clkreg_enable;
373                 clk |= MCI_CLK_ENABLE;
374                 /* This hasn't proven to be worthwhile */
375                 /* clk |= MCI_CLK_PWRSAVE; */
376         }
377
378         /* Set actual clock for debug */
379         host->mmc->actual_clock = host->cclk;
380
381         if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
382                 clk |= MCI_4BIT_BUS;
383         if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
384                 clk |= variant->clkreg_8bit_bus_enable;
385
386         if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
387             host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
388                 clk |= variant->clkreg_neg_edge_enable;
389
390         mmci_write_clkreg(host, clk);
391 }
392
393 static void
394 mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
395 {
396         writel(0, host->base + MMCICOMMAND);
397
398         BUG_ON(host->data);
399
400         host->mrq = NULL;
401         host->cmd = NULL;
402
403         mmc_request_done(host->mmc, mrq);
404 }
405
406 static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
407 {
408         void __iomem *base = host->base;
409         struct variant_data *variant = host->variant;
410
411         if (host->singleirq) {
412                 unsigned int mask0 = readl(base + MMCIMASK0);
413
414                 mask0 &= ~MCI_IRQ1MASK;
415                 mask0 |= mask;
416
417                 writel(mask0, base + MMCIMASK0);
418         }
419
420         if (variant->mmcimask1)
421                 writel(mask, base + MMCIMASK1);
422
423         host->mask1_reg = mask;
424 }
425
426 static void mmci_stop_data(struct mmci_host *host)
427 {
428         mmci_write_datactrlreg(host, 0);
429         mmci_set_mask1(host, 0);
430         host->data = NULL;
431 }
432
433 static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
434 {
435         unsigned int flags = SG_MITER_ATOMIC;
436
437         if (data->flags & MMC_DATA_READ)
438                 flags |= SG_MITER_TO_SG;
439         else
440                 flags |= SG_MITER_FROM_SG;
441
442         sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
443 }
444
445 /*
446  * All the DMA operation mode stuff goes inside this ifdef.
447  * This assumes that you have a generic DMA device interface,
448  * no custom DMA interfaces are supported.
449  */
450 #ifdef CONFIG_DMA_ENGINE
451 static void mmci_dma_setup(struct mmci_host *host)
452 {
453         const char *rxname, *txname;
454         struct variant_data *variant = host->variant;
455
456         host->dma_rx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "rx");
457         host->dma_tx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "tx");
458
459         /* initialize pre request cookie */
460         host->next_data.cookie = 1;
461
462         /*
463          * If only an RX channel is specified, the driver will
464          * attempt to use it bidirectionally, however if it is
465          * is specified but cannot be located, DMA will be disabled.
466          */
467         if (host->dma_rx_channel && !host->dma_tx_channel)
468                 host->dma_tx_channel = host->dma_rx_channel;
469
470         if (host->dma_rx_channel)
471                 rxname = dma_chan_name(host->dma_rx_channel);
472         else
473                 rxname = "none";
474
475         if (host->dma_tx_channel)
476                 txname = dma_chan_name(host->dma_tx_channel);
477         else
478                 txname = "none";
479
480         dev_info(mmc_dev(host->mmc), "DMA channels RX %s, TX %s\n",
481                  rxname, txname);
482
483         /*
484          * Limit the maximum segment size in any SG entry according to
485          * the parameters of the DMA engine device.
486          */
487         if (host->dma_tx_channel) {
488                 struct device *dev = host->dma_tx_channel->device->dev;
489                 unsigned int max_seg_size = dma_get_max_seg_size(dev);
490
491                 if (max_seg_size < host->mmc->max_seg_size)
492                         host->mmc->max_seg_size = max_seg_size;
493         }
494         if (host->dma_rx_channel) {
495                 struct device *dev = host->dma_rx_channel->device->dev;
496                 unsigned int max_seg_size = dma_get_max_seg_size(dev);
497
498                 if (max_seg_size < host->mmc->max_seg_size)
499                         host->mmc->max_seg_size = max_seg_size;
500         }
501
502         if (variant->qcom_dml && host->dma_rx_channel && host->dma_tx_channel)
503                 if (dml_hw_init(host, host->mmc->parent->of_node))
504                         variant->qcom_dml = false;
505 }
506
507 /*
508  * This is used in or so inline it
509  * so it can be discarded.
510  */
511 static inline void mmci_dma_release(struct mmci_host *host)
512 {
513         if (host->dma_rx_channel)
514                 dma_release_channel(host->dma_rx_channel);
515         if (host->dma_tx_channel)
516                 dma_release_channel(host->dma_tx_channel);
517         host->dma_rx_channel = host->dma_tx_channel = NULL;
518 }
519
520 static void mmci_dma_data_error(struct mmci_host *host)
521 {
522         dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n");
523         dmaengine_terminate_all(host->dma_current);
524         host->dma_in_progress = false;
525         host->dma_current = NULL;
526         host->dma_desc_current = NULL;
527         host->data->host_cookie = 0;
528 }
529
530 static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
531 {
532         struct dma_chan *chan;
533
534         if (data->flags & MMC_DATA_READ)
535                 chan = host->dma_rx_channel;
536         else
537                 chan = host->dma_tx_channel;
538
539         dma_unmap_sg(chan->device->dev, data->sg, data->sg_len,
540                      mmc_get_dma_dir(data));
541 }
542
543 static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data)
544 {
545         u32 status;
546         int i;
547
548         /* Wait up to 1ms for the DMA to complete */
549         for (i = 0; ; i++) {
550                 status = readl(host->base + MMCISTATUS);
551                 if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100)
552                         break;
553                 udelay(10);
554         }
555
556         /*
557          * Check to see whether we still have some data left in the FIFO -
558          * this catches DMA controllers which are unable to monitor the
559          * DMALBREQ and DMALSREQ signals while allowing us to DMA to non-
560          * contiguous buffers.  On TX, we'll get a FIFO underrun error.
561          */
562         if (status & MCI_RXDATAAVLBLMASK) {
563                 mmci_dma_data_error(host);
564                 if (!data->error)
565                         data->error = -EIO;
566         }
567
568         if (!data->host_cookie)
569                 mmci_dma_unmap(host, data);
570
571         /*
572          * Use of DMA with scatter-gather is impossible.
573          * Give up with DMA and switch back to PIO mode.
574          */
575         if (status & MCI_RXDATAAVLBLMASK) {
576                 dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n");
577                 mmci_dma_release(host);
578         }
579
580         host->dma_in_progress = false;
581         host->dma_current = NULL;
582         host->dma_desc_current = NULL;
583 }
584
585 /* prepares DMA channel and DMA descriptor, returns non-zero on failure */
586 static int __mmci_dma_prep_data(struct mmci_host *host, struct mmc_data *data,
587                                 struct dma_chan **dma_chan,
588                                 struct dma_async_tx_descriptor **dma_desc)
589 {
590         struct variant_data *variant = host->variant;
591         struct dma_slave_config conf = {
592                 .src_addr = host->phybase + MMCIFIFO,
593                 .dst_addr = host->phybase + MMCIFIFO,
594                 .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
595                 .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
596                 .src_maxburst = variant->fifohalfsize >> 2, /* # of words */
597                 .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
598                 .device_fc = false,
599         };
600         struct dma_chan *chan;
601         struct dma_device *device;
602         struct dma_async_tx_descriptor *desc;
603         int nr_sg;
604         unsigned long flags = DMA_CTRL_ACK;
605
606         if (data->flags & MMC_DATA_READ) {
607                 conf.direction = DMA_DEV_TO_MEM;
608                 chan = host->dma_rx_channel;
609         } else {
610                 conf.direction = DMA_MEM_TO_DEV;
611                 chan = host->dma_tx_channel;
612         }
613
614         /* If there's no DMA channel, fall back to PIO */
615         if (!chan)
616                 return -EINVAL;
617
618         /* If less than or equal to the fifo size, don't bother with DMA */
619         if (data->blksz * data->blocks <= variant->fifosize)
620                 return -EINVAL;
621
622         device = chan->device;
623         nr_sg = dma_map_sg(device->dev, data->sg, data->sg_len,
624                            mmc_get_dma_dir(data));
625         if (nr_sg == 0)
626                 return -EINVAL;
627
628         if (host->variant->qcom_dml)
629                 flags |= DMA_PREP_INTERRUPT;
630
631         dmaengine_slave_config(chan, &conf);
632         desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg,
633                                             conf.direction, flags);
634         if (!desc)
635                 goto unmap_exit;
636
637         *dma_chan = chan;
638         *dma_desc = desc;
639
640         return 0;
641
642  unmap_exit:
643         dma_unmap_sg(device->dev, data->sg, data->sg_len,
644                      mmc_get_dma_dir(data));
645         return -ENOMEM;
646 }
647
648 static inline int mmci_dma_prep_data(struct mmci_host *host,
649                                      struct mmc_data *data)
650 {
651         /* Check if next job is already prepared. */
652         if (host->dma_current && host->dma_desc_current)
653                 return 0;
654
655         /* No job were prepared thus do it now. */
656         return __mmci_dma_prep_data(host, data, &host->dma_current,
657                                     &host->dma_desc_current);
658 }
659
660 static inline int mmci_dma_prep_next(struct mmci_host *host,
661                                      struct mmc_data *data)
662 {
663         struct mmci_host_next *nd = &host->next_data;
664         return __mmci_dma_prep_data(host, data, &nd->dma_chan, &nd->dma_desc);
665 }
666
667 static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
668 {
669         int ret;
670         struct mmc_data *data = host->data;
671
672         ret = mmci_dma_prep_data(host, host->data);
673         if (ret)
674                 return ret;
675
676         /* Okay, go for it. */
677         dev_vdbg(mmc_dev(host->mmc),
678                  "Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n",
679                  data->sg_len, data->blksz, data->blocks, data->flags);
680         host->dma_in_progress = true;
681         dmaengine_submit(host->dma_desc_current);
682         dma_async_issue_pending(host->dma_current);
683
684         if (host->variant->qcom_dml)
685                 dml_start_xfer(host, data);
686
687         datactrl |= MCI_DPSM_DMAENABLE;
688
689         /* Trigger the DMA transfer */
690         mmci_write_datactrlreg(host, datactrl);
691
692         /*
693          * Let the MMCI say when the data is ended and it's time
694          * to fire next DMA request. When that happens, MMCI will
695          * call mmci_data_end()
696          */
697         writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK,
698                host->base + MMCIMASK0);
699         return 0;
700 }
701
702 static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
703 {
704         struct mmci_host_next *next = &host->next_data;
705
706         WARN_ON(data->host_cookie && data->host_cookie != next->cookie);
707         WARN_ON(!data->host_cookie && (next->dma_desc || next->dma_chan));
708
709         host->dma_desc_current = next->dma_desc;
710         host->dma_current = next->dma_chan;
711         next->dma_desc = NULL;
712         next->dma_chan = NULL;
713 }
714
715 static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq)
716 {
717         struct mmci_host *host = mmc_priv(mmc);
718         struct mmc_data *data = mrq->data;
719         struct mmci_host_next *nd = &host->next_data;
720
721         if (!data)
722                 return;
723
724         BUG_ON(data->host_cookie);
725
726         if (mmci_validate_data(host, data))
727                 return;
728
729         if (!mmci_dma_prep_next(host, data))
730                 data->host_cookie = ++nd->cookie < 0 ? 1 : nd->cookie;
731 }
732
733 static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
734                               int err)
735 {
736         struct mmci_host *host = mmc_priv(mmc);
737         struct mmc_data *data = mrq->data;
738
739         if (!data || !data->host_cookie)
740                 return;
741
742         mmci_dma_unmap(host, data);
743
744         if (err) {
745                 struct mmci_host_next *next = &host->next_data;
746                 struct dma_chan *chan;
747                 if (data->flags & MMC_DATA_READ)
748                         chan = host->dma_rx_channel;
749                 else
750                         chan = host->dma_tx_channel;
751                 dmaengine_terminate_all(chan);
752
753                 if (host->dma_desc_current == next->dma_desc)
754                         host->dma_desc_current = NULL;
755
756                 if (host->dma_current == next->dma_chan) {
757                         host->dma_in_progress = false;
758                         host->dma_current = NULL;
759                 }
760
761                 next->dma_desc = NULL;
762                 next->dma_chan = NULL;
763                 data->host_cookie = 0;
764         }
765 }
766
767 #else
768 /* Blank functions if the DMA engine is not available */
769 static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
770 {
771 }
772 static inline void mmci_dma_setup(struct mmci_host *host)
773 {
774 }
775
776 static inline void mmci_dma_release(struct mmci_host *host)
777 {
778 }
779
780 static inline void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
781 {
782 }
783
784 static inline void mmci_dma_finalize(struct mmci_host *host,
785                                      struct mmc_data *data)
786 {
787 }
788
789 static inline void mmci_dma_data_error(struct mmci_host *host)
790 {
791 }
792
793 static inline int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
794 {
795         return -ENOSYS;
796 }
797
798 #define mmci_pre_request NULL
799 #define mmci_post_request NULL
800
801 #endif
802
803 static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
804 {
805         struct variant_data *variant = host->variant;
806         unsigned int datactrl, timeout, irqmask;
807         unsigned long long clks;
808         void __iomem *base;
809         int blksz_bits;
810
811         dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n",
812                 data->blksz, data->blocks, data->flags);
813
814         host->data = data;
815         host->size = data->blksz * data->blocks;
816         data->bytes_xfered = 0;
817
818         clks = (unsigned long long)data->timeout_ns * host->cclk;
819         do_div(clks, NSEC_PER_SEC);
820
821         timeout = data->timeout_clks + (unsigned int)clks;
822
823         base = host->base;
824         writel(timeout, base + MMCIDATATIMER);
825         writel(host->size, base + MMCIDATALENGTH);
826
827         blksz_bits = ffs(data->blksz) - 1;
828         BUG_ON(1 << blksz_bits != data->blksz);
829
830         if (variant->blksz_datactrl16)
831                 datactrl = MCI_DPSM_ENABLE | (data->blksz << 16);
832         else if (variant->blksz_datactrl4)
833                 datactrl = MCI_DPSM_ENABLE | (data->blksz << 4);
834         else
835                 datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
836
837         if (data->flags & MMC_DATA_READ)
838                 datactrl |= MCI_DPSM_DIRECTION;
839
840         if (host->mmc->card && mmc_card_sdio(host->mmc->card)) {
841                 u32 clk;
842
843                 datactrl |= variant->datactrl_mask_sdio;
844
845                 /*
846                  * The ST Micro variant for SDIO small write transfers
847                  * needs to have clock H/W flow control disabled,
848                  * otherwise the transfer will not start. The threshold
849                  * depends on the rate of MCLK.
850                  */
851                 if (variant->st_sdio && data->flags & MMC_DATA_WRITE &&
852                     (host->size < 8 ||
853                      (host->size <= 8 && host->mclk > 50000000)))
854                         clk = host->clk_reg & ~variant->clkreg_enable;
855                 else
856                         clk = host->clk_reg | variant->clkreg_enable;
857
858                 mmci_write_clkreg(host, clk);
859         }
860
861         if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
862             host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
863                 datactrl |= variant->datactrl_mask_ddrmode;
864
865         /*
866          * Attempt to use DMA operation mode, if this
867          * should fail, fall back to PIO mode
868          */
869         if (!mmci_dma_start_data(host, datactrl))
870                 return;
871
872         /* IRQ mode, map the SG list for CPU reading/writing */
873         mmci_init_sg(host, data);
874
875         if (data->flags & MMC_DATA_READ) {
876                 irqmask = MCI_RXFIFOHALFFULLMASK;
877
878                 /*
879                  * If we have less than the fifo 'half-full' threshold to
880                  * transfer, trigger a PIO interrupt as soon as any data
881                  * is available.
882                  */
883                 if (host->size < variant->fifohalfsize)
884                         irqmask |= MCI_RXDATAAVLBLMASK;
885         } else {
886                 /*
887                  * We don't actually need to include "FIFO empty" here
888                  * since its implicit in "FIFO half empty".
889                  */
890                 irqmask = MCI_TXFIFOHALFEMPTYMASK;
891         }
892
893         mmci_write_datactrlreg(host, datactrl);
894         writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
895         mmci_set_mask1(host, irqmask);
896 }
897
898 static void
899 mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c)
900 {
901         void __iomem *base = host->base;
902
903         dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n",
904             cmd->opcode, cmd->arg, cmd->flags);
905
906         if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) {
907                 writel(0, base + MMCICOMMAND);
908                 mmci_reg_delay(host);
909         }
910
911         c |= cmd->opcode | MCI_CPSM_ENABLE;
912         if (cmd->flags & MMC_RSP_PRESENT) {
913                 if (cmd->flags & MMC_RSP_136)
914                         c |= MCI_CPSM_LONGRSP;
915                 c |= MCI_CPSM_RESPONSE;
916         }
917         if (/*interrupt*/0)
918                 c |= MCI_CPSM_INTERRUPT;
919
920         if (mmc_cmd_type(cmd) == MMC_CMD_ADTC)
921                 c |= host->variant->data_cmd_enable;
922
923         host->cmd = cmd;
924
925         writel(cmd->arg, base + MMCIARGUMENT);
926         writel(c, base + MMCICOMMAND);
927 }
928
929 static void
930 mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
931               unsigned int status)
932 {
933         /* Make sure we have data to handle */
934         if (!data)
935                 return;
936
937         /* First check for errors */
938         if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_STARTBITERR|
939                       MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
940                 u32 remain, success;
941
942                 /* Terminate the DMA transfer */
943                 if (dma_inprogress(host)) {
944                         mmci_dma_data_error(host);
945                         mmci_dma_unmap(host, data);
946                 }
947
948                 /*
949                  * Calculate how far we are into the transfer.  Note that
950                  * the data counter gives the number of bytes transferred
951                  * on the MMC bus, not on the host side.  On reads, this
952                  * can be as much as a FIFO-worth of data ahead.  This
953                  * matters for FIFO overruns only.
954                  */
955                 remain = readl(host->base + MMCIDATACNT);
956                 success = data->blksz * data->blocks - remain;
957
958                 dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n",
959                         status, success);
960                 if (status & MCI_DATACRCFAIL) {
961                         /* Last block was not successful */
962                         success -= 1;
963                         data->error = -EILSEQ;
964                 } else if (status & MCI_DATATIMEOUT) {
965                         data->error = -ETIMEDOUT;
966                 } else if (status & MCI_STARTBITERR) {
967                         data->error = -ECOMM;
968                 } else if (status & MCI_TXUNDERRUN) {
969                         data->error = -EIO;
970                 } else if (status & MCI_RXOVERRUN) {
971                         if (success > host->variant->fifosize)
972                                 success -= host->variant->fifosize;
973                         else
974                                 success = 0;
975                         data->error = -EIO;
976                 }
977                 data->bytes_xfered = round_down(success, data->blksz);
978         }
979
980         if (status & MCI_DATABLOCKEND)
981                 dev_err(mmc_dev(host->mmc), "stray MCI_DATABLOCKEND interrupt\n");
982
983         if (status & MCI_DATAEND || data->error) {
984                 if (dma_inprogress(host))
985                         mmci_dma_finalize(host, data);
986                 mmci_stop_data(host);
987
988                 if (!data->error)
989                         /* The error clause is handled above, success! */
990                         data->bytes_xfered = data->blksz * data->blocks;
991
992                 if (!data->stop || host->mrq->sbc) {
993                         mmci_request_end(host, data->mrq);
994                 } else {
995                         mmci_start_command(host, data->stop, 0);
996                 }
997         }
998 }
999
1000 static void
1001 mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
1002              unsigned int status)
1003 {
1004         void __iomem *base = host->base;
1005         bool sbc;
1006
1007         if (!cmd)
1008                 return;
1009
1010         sbc = (cmd == host->mrq->sbc);
1011
1012         /*
1013          * We need to be one of these interrupts to be considered worth
1014          * handling. Note that we tag on any latent IRQs postponed
1015          * due to waiting for busy status.
1016          */
1017         if (!((status|host->busy_status) &
1018               (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND)))
1019                 return;
1020
1021         /*
1022          * ST Micro variant: handle busy detection.
1023          */
1024         if (host->variant->busy_detect) {
1025                 bool busy_resp = !!(cmd->flags & MMC_RSP_BUSY);
1026
1027                 /* We are busy with a command, return */
1028                 if (host->busy_status &&
1029                     (status & host->variant->busy_detect_flag))
1030                         return;
1031
1032                 /*
1033                  * We were not busy, but we now got a busy response on
1034                  * something that was not an error, and we double-check
1035                  * that the special busy status bit is still set before
1036                  * proceeding.
1037                  */
1038                 if (!host->busy_status && busy_resp &&
1039                     !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) &&
1040                     (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) {
1041
1042                         /* Clear the busy start IRQ */
1043                         writel(host->variant->busy_detect_mask,
1044                                host->base + MMCICLEAR);
1045
1046                         /* Unmask the busy end IRQ */
1047                         writel(readl(base + MMCIMASK0) |
1048                                host->variant->busy_detect_mask,
1049                                base + MMCIMASK0);
1050                         /*
1051                          * Now cache the last response status code (until
1052                          * the busy bit goes low), and return.
1053                          */
1054                         host->busy_status =
1055                                 status & (MCI_CMDSENT|MCI_CMDRESPEND);
1056                         return;
1057                 }
1058
1059                 /*
1060                  * At this point we are not busy with a command, we have
1061                  * not received a new busy request, clear and mask the busy
1062                  * end IRQ and fall through to process the IRQ.
1063                  */
1064                 if (host->busy_status) {
1065
1066                         writel(host->variant->busy_detect_mask,
1067                                host->base + MMCICLEAR);
1068
1069                         writel(readl(base + MMCIMASK0) &
1070                                ~host->variant->busy_detect_mask,
1071                                base + MMCIMASK0);
1072                         host->busy_status = 0;
1073                 }
1074         }
1075
1076         host->cmd = NULL;
1077
1078         if (status & MCI_CMDTIMEOUT) {
1079                 cmd->error = -ETIMEDOUT;
1080         } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
1081                 cmd->error = -EILSEQ;
1082         } else {
1083                 cmd->resp[0] = readl(base + MMCIRESPONSE0);
1084                 cmd->resp[1] = readl(base + MMCIRESPONSE1);
1085                 cmd->resp[2] = readl(base + MMCIRESPONSE2);
1086                 cmd->resp[3] = readl(base + MMCIRESPONSE3);
1087         }
1088
1089         if ((!sbc && !cmd->data) || cmd->error) {
1090                 if (host->data) {
1091                         /* Terminate the DMA transfer */
1092                         if (dma_inprogress(host)) {
1093                                 mmci_dma_data_error(host);
1094                                 mmci_dma_unmap(host, host->data);
1095                         }
1096                         mmci_stop_data(host);
1097                 }
1098                 mmci_request_end(host, host->mrq);
1099         } else if (sbc) {
1100                 mmci_start_command(host, host->mrq->cmd, 0);
1101         } else if (!(cmd->data->flags & MMC_DATA_READ)) {
1102                 mmci_start_data(host, cmd->data);
1103         }
1104 }
1105
1106 static int mmci_get_rx_fifocnt(struct mmci_host *host, u32 status, int remain)
1107 {
1108         return remain - (readl(host->base + MMCIFIFOCNT) << 2);
1109 }
1110
1111 static int mmci_qcom_get_rx_fifocnt(struct mmci_host *host, u32 status, int r)
1112 {
1113         /*
1114          * on qcom SDCC4 only 8 words are used in each burst so only 8 addresses
1115          * from the fifo range should be used
1116          */
1117         if (status & MCI_RXFIFOHALFFULL)
1118                 return host->variant->fifohalfsize;
1119         else if (status & MCI_RXDATAAVLBL)
1120                 return 4;
1121
1122         return 0;
1123 }
1124
1125 static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain)
1126 {
1127         void __iomem *base = host->base;
1128         char *ptr = buffer;
1129         u32 status = readl(host->base + MMCISTATUS);
1130         int host_remain = host->size;
1131
1132         do {
1133                 int count = host->get_rx_fifocnt(host, status, host_remain);
1134
1135                 if (count > remain)
1136                         count = remain;
1137
1138                 if (count <= 0)
1139                         break;
1140
1141                 /*
1142                  * SDIO especially may want to send something that is
1143                  * not divisible by 4 (as opposed to card sectors
1144                  * etc). Therefore make sure to always read the last bytes
1145                  * while only doing full 32-bit reads towards the FIFO.
1146                  */
1147                 if (unlikely(count & 0x3)) {
1148                         if (count < 4) {
1149                                 unsigned char buf[4];
1150                                 ioread32_rep(base + MMCIFIFO, buf, 1);
1151                                 memcpy(ptr, buf, count);
1152                         } else {
1153                                 ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
1154                                 count &= ~0x3;
1155                         }
1156                 } else {
1157                         ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
1158                 }
1159
1160                 ptr += count;
1161                 remain -= count;
1162                 host_remain -= count;
1163
1164                 if (remain == 0)
1165                         break;
1166
1167                 status = readl(base + MMCISTATUS);
1168         } while (status & MCI_RXDATAAVLBL);
1169
1170         return ptr - buffer;
1171 }
1172
1173 static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status)
1174 {
1175         struct variant_data *variant = host->variant;
1176         void __iomem *base = host->base;
1177         char *ptr = buffer;
1178
1179         do {
1180                 unsigned int count, maxcnt;
1181
1182                 maxcnt = status & MCI_TXFIFOEMPTY ?
1183                          variant->fifosize : variant->fifohalfsize;
1184                 count = min(remain, maxcnt);
1185
1186                 /*
1187                  * SDIO especially may want to send something that is
1188                  * not divisible by 4 (as opposed to card sectors
1189                  * etc), and the FIFO only accept full 32-bit writes.
1190                  * So compensate by adding +3 on the count, a single
1191                  * byte become a 32bit write, 7 bytes will be two
1192                  * 32bit writes etc.
1193                  */
1194                 iowrite32_rep(base + MMCIFIFO, ptr, (count + 3) >> 2);
1195
1196                 ptr += count;
1197                 remain -= count;
1198
1199                 if (remain == 0)
1200                         break;
1201
1202                 status = readl(base + MMCISTATUS);
1203         } while (status & MCI_TXFIFOHALFEMPTY);
1204
1205         return ptr - buffer;
1206 }
1207
1208 /*
1209  * PIO data transfer IRQ handler.
1210  */
1211 static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
1212 {
1213         struct mmci_host *host = dev_id;
1214         struct sg_mapping_iter *sg_miter = &host->sg_miter;
1215         struct variant_data *variant = host->variant;
1216         void __iomem *base = host->base;
1217         unsigned long flags;
1218         u32 status;
1219
1220         status = readl(base + MMCISTATUS);
1221
1222         dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
1223
1224         local_irq_save(flags);
1225
1226         do {
1227                 unsigned int remain, len;
1228                 char *buffer;
1229
1230                 /*
1231                  * For write, we only need to test the half-empty flag
1232                  * here - if the FIFO is completely empty, then by
1233                  * definition it is more than half empty.
1234                  *
1235                  * For read, check for data available.
1236                  */
1237                 if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
1238                         break;
1239
1240                 if (!sg_miter_next(sg_miter))
1241                         break;
1242
1243                 buffer = sg_miter->addr;
1244                 remain = sg_miter->length;
1245
1246                 len = 0;
1247                 if (status & MCI_RXACTIVE)
1248                         len = mmci_pio_read(host, buffer, remain);
1249                 if (status & MCI_TXACTIVE)
1250                         len = mmci_pio_write(host, buffer, remain, status);
1251
1252                 sg_miter->consumed = len;
1253
1254                 host->size -= len;
1255                 remain -= len;
1256
1257                 if (remain)
1258                         break;
1259
1260                 status = readl(base + MMCISTATUS);
1261         } while (1);
1262
1263         sg_miter_stop(sg_miter);
1264
1265         local_irq_restore(flags);
1266
1267         /*
1268          * If we have less than the fifo 'half-full' threshold to transfer,
1269          * trigger a PIO interrupt as soon as any data is available.
1270          */
1271         if (status & MCI_RXACTIVE && host->size < variant->fifohalfsize)
1272                 mmci_set_mask1(host, MCI_RXDATAAVLBLMASK);
1273
1274         /*
1275          * If we run out of data, disable the data IRQs; this
1276          * prevents a race where the FIFO becomes empty before
1277          * the chip itself has disabled the data path, and
1278          * stops us racing with our data end IRQ.
1279          */
1280         if (host->size == 0) {
1281                 mmci_set_mask1(host, 0);
1282                 writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0);
1283         }
1284
1285         return IRQ_HANDLED;
1286 }
1287
1288 /*
1289  * Handle completion of command and data transfers.
1290  */
1291 static irqreturn_t mmci_irq(int irq, void *dev_id)
1292 {
1293         struct mmci_host *host = dev_id;
1294         u32 status;
1295         int ret = 0;
1296
1297         spin_lock(&host->lock);
1298
1299         do {
1300                 status = readl(host->base + MMCISTATUS);
1301
1302                 if (host->singleirq) {
1303                         if (status & host->mask1_reg)
1304                                 mmci_pio_irq(irq, dev_id);
1305
1306                         status &= ~MCI_IRQ1MASK;
1307                 }
1308
1309                 /*
1310                  * We intentionally clear the MCI_ST_CARDBUSY IRQ (if it's
1311                  * enabled) in mmci_cmd_irq() function where ST Micro busy
1312                  * detection variant is handled. Considering the HW seems to be
1313                  * triggering the IRQ on both edges while monitoring DAT0 for
1314                  * busy completion and that same status bit is used to monitor
1315                  * start and end of busy detection, special care must be taken
1316                  * to make sure that both start and end interrupts are always
1317                  * cleared one after the other.
1318                  */
1319                 status &= readl(host->base + MMCIMASK0);
1320                 if (host->variant->busy_detect)
1321                         writel(status & ~host->variant->busy_detect_mask,
1322                                host->base + MMCICLEAR);
1323                 else
1324                         writel(status, host->base + MMCICLEAR);
1325
1326                 dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status);
1327
1328                 if (host->variant->reversed_irq_handling) {
1329                         mmci_data_irq(host, host->data, status);
1330                         mmci_cmd_irq(host, host->cmd, status);
1331                 } else {
1332                         mmci_cmd_irq(host, host->cmd, status);
1333                         mmci_data_irq(host, host->data, status);
1334                 }
1335
1336                 /*
1337                  * Don't poll for busy completion in irq context.
1338                  */
1339                 if (host->variant->busy_detect && host->busy_status)
1340                         status &= ~host->variant->busy_detect_flag;
1341
1342                 ret = 1;
1343         } while (status);
1344
1345         spin_unlock(&host->lock);
1346
1347         return IRQ_RETVAL(ret);
1348 }
1349
1350 static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1351 {
1352         struct mmci_host *host = mmc_priv(mmc);
1353         unsigned long flags;
1354
1355         WARN_ON(host->mrq != NULL);
1356
1357         mrq->cmd->error = mmci_validate_data(host, mrq->data);
1358         if (mrq->cmd->error) {
1359                 mmc_request_done(mmc, mrq);
1360                 return;
1361         }
1362
1363         spin_lock_irqsave(&host->lock, flags);
1364
1365         host->mrq = mrq;
1366
1367         if (mrq->data)
1368                 mmci_get_next_data(host, mrq->data);
1369
1370         if (mrq->data && mrq->data->flags & MMC_DATA_READ)
1371                 mmci_start_data(host, mrq->data);
1372
1373         if (mrq->sbc)
1374                 mmci_start_command(host, mrq->sbc, 0);
1375         else
1376                 mmci_start_command(host, mrq->cmd, 0);
1377
1378         spin_unlock_irqrestore(&host->lock, flags);
1379 }
1380
1381 static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1382 {
1383         struct mmci_host *host = mmc_priv(mmc);
1384         struct variant_data *variant = host->variant;
1385         u32 pwr = 0;
1386         unsigned long flags;
1387         int ret;
1388
1389         if (host->plat->ios_handler &&
1390                 host->plat->ios_handler(mmc_dev(mmc), ios))
1391                         dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
1392
1393         switch (ios->power_mode) {
1394         case MMC_POWER_OFF:
1395                 if (!IS_ERR(mmc->supply.vmmc))
1396                         mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
1397
1398                 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
1399                         regulator_disable(mmc->supply.vqmmc);
1400                         host->vqmmc_enabled = false;
1401                 }
1402
1403                 break;
1404         case MMC_POWER_UP:
1405                 if (!IS_ERR(mmc->supply.vmmc))
1406                         mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
1407
1408                 /*
1409                  * The ST Micro variant doesn't have the PL180s MCI_PWR_UP
1410                  * and instead uses MCI_PWR_ON so apply whatever value is
1411                  * configured in the variant data.
1412                  */
1413                 pwr |= variant->pwrreg_powerup;
1414
1415                 break;
1416         case MMC_POWER_ON:
1417                 if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
1418                         ret = regulator_enable(mmc->supply.vqmmc);
1419                         if (ret < 0)
1420                                 dev_err(mmc_dev(mmc),
1421                                         "failed to enable vqmmc regulator\n");
1422                         else
1423                                 host->vqmmc_enabled = true;
1424                 }
1425
1426                 pwr |= MCI_PWR_ON;
1427                 break;
1428         }
1429
1430         if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) {
1431                 /*
1432                  * The ST Micro variant has some additional bits
1433                  * indicating signal direction for the signals in
1434                  * the SD/MMC bus and feedback-clock usage.
1435                  */
1436                 pwr |= host->pwr_reg_add;
1437
1438                 if (ios->bus_width == MMC_BUS_WIDTH_4)
1439                         pwr &= ~MCI_ST_DATA74DIREN;
1440                 else if (ios->bus_width == MMC_BUS_WIDTH_1)
1441                         pwr &= (~MCI_ST_DATA74DIREN &
1442                                 ~MCI_ST_DATA31DIREN &
1443                                 ~MCI_ST_DATA2DIREN);
1444         }
1445
1446         if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
1447                 if (host->hw_designer != AMBA_VENDOR_ST)
1448                         pwr |= MCI_ROD;
1449                 else {
1450                         /*
1451                          * The ST Micro variant use the ROD bit for something
1452                          * else and only has OD (Open Drain).
1453                          */
1454                         pwr |= MCI_OD;
1455                 }
1456         }
1457
1458         /*
1459          * If clock = 0 and the variant requires the MMCIPOWER to be used for
1460          * gating the clock, the MCI_PWR_ON bit is cleared.
1461          */
1462         if (!ios->clock && variant->pwrreg_clkgate)
1463                 pwr &= ~MCI_PWR_ON;
1464
1465         if (host->variant->explicit_mclk_control &&
1466             ios->clock != host->clock_cache) {
1467                 ret = clk_set_rate(host->clk, ios->clock);
1468                 if (ret < 0)
1469                         dev_err(mmc_dev(host->mmc),
1470                                 "Error setting clock rate (%d)\n", ret);
1471                 else
1472                         host->mclk = clk_get_rate(host->clk);
1473         }
1474         host->clock_cache = ios->clock;
1475
1476         spin_lock_irqsave(&host->lock, flags);
1477
1478         mmci_set_clkreg(host, ios->clock);
1479         mmci_write_pwrreg(host, pwr);
1480         mmci_reg_delay(host);
1481
1482         spin_unlock_irqrestore(&host->lock, flags);
1483 }
1484
1485 static int mmci_get_cd(struct mmc_host *mmc)
1486 {
1487         struct mmci_host *host = mmc_priv(mmc);
1488         struct mmci_platform_data *plat = host->plat;
1489         unsigned int status = mmc_gpio_get_cd(mmc);
1490
1491         if (status == -ENOSYS) {
1492                 if (!plat->status)
1493                         return 1; /* Assume always present */
1494
1495                 status = plat->status(mmc_dev(host->mmc));
1496         }
1497         return status;
1498 }
1499
1500 static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1501 {
1502         int ret = 0;
1503
1504         if (!IS_ERR(mmc->supply.vqmmc)) {
1505
1506                 switch (ios->signal_voltage) {
1507                 case MMC_SIGNAL_VOLTAGE_330:
1508                         ret = regulator_set_voltage(mmc->supply.vqmmc,
1509                                                 2700000, 3600000);
1510                         break;
1511                 case MMC_SIGNAL_VOLTAGE_180:
1512                         ret = regulator_set_voltage(mmc->supply.vqmmc,
1513                                                 1700000, 1950000);
1514                         break;
1515                 case MMC_SIGNAL_VOLTAGE_120:
1516                         ret = regulator_set_voltage(mmc->supply.vqmmc,
1517                                                 1100000, 1300000);
1518                         break;
1519                 }
1520
1521                 if (ret)
1522                         dev_warn(mmc_dev(mmc), "Voltage switch failed\n");
1523         }
1524
1525         return ret;
1526 }
1527
1528 static struct mmc_host_ops mmci_ops = {
1529         .request        = mmci_request,
1530         .pre_req        = mmci_pre_request,
1531         .post_req       = mmci_post_request,
1532         .set_ios        = mmci_set_ios,
1533         .get_ro         = mmc_gpio_get_ro,
1534         .get_cd         = mmci_get_cd,
1535         .start_signal_voltage_switch = mmci_sig_volt_switch,
1536 };
1537
1538 static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
1539 {
1540         struct mmci_host *host = mmc_priv(mmc);
1541         int ret = mmc_of_parse(mmc);
1542
1543         if (ret)
1544                 return ret;
1545
1546         if (of_get_property(np, "st,sig-dir-dat0", NULL))
1547                 host->pwr_reg_add |= MCI_ST_DATA0DIREN;
1548         if (of_get_property(np, "st,sig-dir-dat2", NULL))
1549                 host->pwr_reg_add |= MCI_ST_DATA2DIREN;
1550         if (of_get_property(np, "st,sig-dir-dat31", NULL))
1551                 host->pwr_reg_add |= MCI_ST_DATA31DIREN;
1552         if (of_get_property(np, "st,sig-dir-dat74", NULL))
1553                 host->pwr_reg_add |= MCI_ST_DATA74DIREN;
1554         if (of_get_property(np, "st,sig-dir-cmd", NULL))
1555                 host->pwr_reg_add |= MCI_ST_CMDDIREN;
1556         if (of_get_property(np, "st,sig-pin-fbclk", NULL))
1557                 host->pwr_reg_add |= MCI_ST_FBCLKEN;
1558
1559         if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
1560                 mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
1561         if (of_get_property(np, "mmc-cap-sd-highspeed", NULL))
1562                 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1563
1564         return 0;
1565 }
1566
1567 static int mmci_probe(struct amba_device *dev,
1568         const struct amba_id *id)
1569 {
1570         struct mmci_platform_data *plat = dev->dev.platform_data;
1571         struct device_node *np = dev->dev.of_node;
1572         struct variant_data *variant = id->data;
1573         struct mmci_host *host;
1574         struct mmc_host *mmc;
1575         int ret;
1576
1577         /* Must have platform data or Device Tree. */
1578         if (!plat && !np) {
1579                 dev_err(&dev->dev, "No plat data or DT found\n");
1580                 return -EINVAL;
1581         }
1582
1583         if (!plat) {
1584                 plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL);
1585                 if (!plat)
1586                         return -ENOMEM;
1587         }
1588
1589         mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
1590         if (!mmc)
1591                 return -ENOMEM;
1592
1593         ret = mmci_of_parse(np, mmc);
1594         if (ret)
1595                 goto host_free;
1596
1597         host = mmc_priv(mmc);
1598         host->mmc = mmc;
1599
1600         host->hw_designer = amba_manf(dev);
1601         host->hw_revision = amba_rev(dev);
1602         dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
1603         dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision);
1604
1605         host->clk = devm_clk_get(&dev->dev, NULL);
1606         if (IS_ERR(host->clk)) {
1607                 ret = PTR_ERR(host->clk);
1608                 goto host_free;
1609         }
1610
1611         ret = clk_prepare_enable(host->clk);
1612         if (ret)
1613                 goto host_free;
1614
1615         if (variant->qcom_fifo)
1616                 host->get_rx_fifocnt = mmci_qcom_get_rx_fifocnt;
1617         else
1618                 host->get_rx_fifocnt = mmci_get_rx_fifocnt;
1619
1620         host->plat = plat;
1621         host->variant = variant;
1622         host->mclk = clk_get_rate(host->clk);
1623         /*
1624          * According to the spec, mclk is max 100 MHz,
1625          * so we try to adjust the clock down to this,
1626          * (if possible).
1627          */
1628         if (host->mclk > variant->f_max) {
1629                 ret = clk_set_rate(host->clk, variant->f_max);
1630                 if (ret < 0)
1631                         goto clk_disable;
1632                 host->mclk = clk_get_rate(host->clk);
1633                 dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n",
1634                         host->mclk);
1635         }
1636
1637         host->phybase = dev->res.start;
1638         host->base = devm_ioremap_resource(&dev->dev, &dev->res);
1639         if (IS_ERR(host->base)) {
1640                 ret = PTR_ERR(host->base);
1641                 goto clk_disable;
1642         }
1643
1644         /*
1645          * The ARM and ST versions of the block have slightly different
1646          * clock divider equations which means that the minimum divider
1647          * differs too.
1648          * on Qualcomm like controllers get the nearest minimum clock to 100Khz
1649          */
1650         if (variant->st_clkdiv)
1651                 mmc->f_min = DIV_ROUND_UP(host->mclk, 257);
1652         else if (variant->explicit_mclk_control)
1653                 mmc->f_min = clk_round_rate(host->clk, 100000);
1654         else
1655                 mmc->f_min = DIV_ROUND_UP(host->mclk, 512);
1656         /*
1657          * If no maximum operating frequency is supplied, fall back to use
1658          * the module parameter, which has a (low) default value in case it
1659          * is not specified. Either value must not exceed the clock rate into
1660          * the block, of course.
1661          */
1662         if (mmc->f_max)
1663                 mmc->f_max = variant->explicit_mclk_control ?
1664                                 min(variant->f_max, mmc->f_max) :
1665                                 min(host->mclk, mmc->f_max);
1666         else
1667                 mmc->f_max = variant->explicit_mclk_control ?
1668                                 fmax : min(host->mclk, fmax);
1669
1670
1671         dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
1672
1673         /* Get regulators and the supported OCR mask */
1674         ret = mmc_regulator_get_supply(mmc);
1675         if (ret)
1676                 goto clk_disable;
1677
1678         if (!mmc->ocr_avail)
1679                 mmc->ocr_avail = plat->ocr_mask;
1680         else if (plat->ocr_mask)
1681                 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1682
1683         /* DT takes precedence over platform data. */
1684         if (!np) {
1685                 if (!plat->cd_invert)
1686                         mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
1687                 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
1688         }
1689
1690         /* We support these capabilities. */
1691         mmc->caps |= MMC_CAP_CMD23;
1692
1693         /*
1694          * Enable busy detection.
1695          */
1696         if (variant->busy_detect) {
1697                 mmci_ops.card_busy = mmci_card_busy;
1698                 /*
1699                  * Not all variants have a flag to enable busy detection
1700                  * in the DPSM, but if they do, set it here.
1701                  */
1702                 if (variant->busy_dpsm_flag)
1703                         mmci_write_datactrlreg(host,
1704                                                host->variant->busy_dpsm_flag);
1705                 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
1706                 mmc->max_busy_timeout = 0;
1707         }
1708
1709         mmc->ops = &mmci_ops;
1710
1711         /* We support these PM capabilities. */
1712         mmc->pm_caps |= MMC_PM_KEEP_POWER;
1713
1714         /*
1715          * We can do SGIO
1716          */
1717         mmc->max_segs = NR_SG;
1718
1719         /*
1720          * Since only a certain number of bits are valid in the data length
1721          * register, we must ensure that we don't exceed 2^num-1 bytes in a
1722          * single request.
1723          */
1724         mmc->max_req_size = (1 << variant->datalength_bits) - 1;
1725
1726         /*
1727          * Set the maximum segment size.  Since we aren't doing DMA
1728          * (yet) we are only limited by the data length register.
1729          */
1730         mmc->max_seg_size = mmc->max_req_size;
1731
1732         /*
1733          * Block size can be up to 2048 bytes, but must be a power of two.
1734          */
1735         mmc->max_blk_size = 1 << 11;
1736
1737         /*
1738          * Limit the number of blocks transferred so that we don't overflow
1739          * the maximum request size.
1740          */
1741         mmc->max_blk_count = mmc->max_req_size >> 11;
1742
1743         spin_lock_init(&host->lock);
1744
1745         writel(0, host->base + MMCIMASK0);
1746
1747         if (variant->mmcimask1)
1748                 writel(0, host->base + MMCIMASK1);
1749
1750         writel(0xfff, host->base + MMCICLEAR);
1751
1752         /*
1753          * If:
1754          * - not using DT but using a descriptor table, or
1755          * - using a table of descriptors ALONGSIDE DT, or
1756          * look up these descriptors named "cd" and "wp" right here, fail
1757          * silently of these do not exist and proceed to try platform data
1758          */
1759         if (!np) {
1760                 ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL);
1761                 if (ret < 0) {
1762                         if (ret == -EPROBE_DEFER)
1763                                 goto clk_disable;
1764                         else if (gpio_is_valid(plat->gpio_cd)) {
1765                                 ret = mmc_gpio_request_cd(mmc, plat->gpio_cd, 0);
1766                                 if (ret)
1767                                         goto clk_disable;
1768                         }
1769                 }
1770
1771                 ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0, NULL);
1772                 if (ret < 0) {
1773                         if (ret == -EPROBE_DEFER)
1774                                 goto clk_disable;
1775                         else if (gpio_is_valid(plat->gpio_wp)) {
1776                                 ret = mmc_gpio_request_ro(mmc, plat->gpio_wp);
1777                                 if (ret)
1778                                         goto clk_disable;
1779                         }
1780                 }
1781         }
1782
1783         ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED,
1784                         DRIVER_NAME " (cmd)", host);
1785         if (ret)
1786                 goto clk_disable;
1787
1788         if (!dev->irq[1])
1789                 host->singleirq = true;
1790         else {
1791                 ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq,
1792                                 IRQF_SHARED, DRIVER_NAME " (pio)", host);
1793                 if (ret)
1794                         goto clk_disable;
1795         }
1796
1797         writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1798
1799         amba_set_drvdata(dev, mmc);
1800
1801         dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
1802                  mmc_hostname(mmc), amba_part(dev), amba_manf(dev),
1803                  amba_rev(dev), (unsigned long long)dev->res.start,
1804                  dev->irq[0], dev->irq[1]);
1805
1806         mmci_dma_setup(host);
1807
1808         pm_runtime_set_autosuspend_delay(&dev->dev, 50);
1809         pm_runtime_use_autosuspend(&dev->dev);
1810
1811         mmc_add_host(mmc);
1812
1813         pm_runtime_put(&dev->dev);
1814         return 0;
1815
1816  clk_disable:
1817         clk_disable_unprepare(host->clk);
1818  host_free:
1819         mmc_free_host(mmc);
1820         return ret;
1821 }
1822
1823 static int mmci_remove(struct amba_device *dev)
1824 {
1825         struct mmc_host *mmc = amba_get_drvdata(dev);
1826
1827         if (mmc) {
1828                 struct mmci_host *host = mmc_priv(mmc);
1829                 struct variant_data *variant = host->variant;
1830
1831                 /*
1832                  * Undo pm_runtime_put() in probe.  We use the _sync
1833                  * version here so that we can access the primecell.
1834                  */
1835                 pm_runtime_get_sync(&dev->dev);
1836
1837                 mmc_remove_host(mmc);
1838
1839                 writel(0, host->base + MMCIMASK0);
1840
1841                 if (variant->mmcimask1)
1842                         writel(0, host->base + MMCIMASK1);
1843
1844                 writel(0, host->base + MMCICOMMAND);
1845                 writel(0, host->base + MMCIDATACTRL);
1846
1847                 mmci_dma_release(host);
1848                 clk_disable_unprepare(host->clk);
1849                 mmc_free_host(mmc);
1850         }
1851
1852         return 0;
1853 }
1854
1855 #ifdef CONFIG_PM
1856 static void mmci_save(struct mmci_host *host)
1857 {
1858         unsigned long flags;
1859
1860         spin_lock_irqsave(&host->lock, flags);
1861
1862         writel(0, host->base + MMCIMASK0);
1863         if (host->variant->pwrreg_nopower) {
1864                 writel(0, host->base + MMCIDATACTRL);
1865                 writel(0, host->base + MMCIPOWER);
1866                 writel(0, host->base + MMCICLOCK);
1867         }
1868         mmci_reg_delay(host);
1869
1870         spin_unlock_irqrestore(&host->lock, flags);
1871 }
1872
1873 static void mmci_restore(struct mmci_host *host)
1874 {
1875         unsigned long flags;
1876
1877         spin_lock_irqsave(&host->lock, flags);
1878
1879         if (host->variant->pwrreg_nopower) {
1880                 writel(host->clk_reg, host->base + MMCICLOCK);
1881                 writel(host->datactrl_reg, host->base + MMCIDATACTRL);
1882                 writel(host->pwr_reg, host->base + MMCIPOWER);
1883         }
1884         writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1885         mmci_reg_delay(host);
1886
1887         spin_unlock_irqrestore(&host->lock, flags);
1888 }
1889
1890 static int mmci_runtime_suspend(struct device *dev)
1891 {
1892         struct amba_device *adev = to_amba_device(dev);
1893         struct mmc_host *mmc = amba_get_drvdata(adev);
1894
1895         if (mmc) {
1896                 struct mmci_host *host = mmc_priv(mmc);
1897                 pinctrl_pm_select_sleep_state(dev);
1898                 mmci_save(host);
1899                 clk_disable_unprepare(host->clk);
1900         }
1901
1902         return 0;
1903 }
1904
1905 static int mmci_runtime_resume(struct device *dev)
1906 {
1907         struct amba_device *adev = to_amba_device(dev);
1908         struct mmc_host *mmc = amba_get_drvdata(adev);
1909
1910         if (mmc) {
1911                 struct mmci_host *host = mmc_priv(mmc);
1912                 clk_prepare_enable(host->clk);
1913                 mmci_restore(host);
1914                 pinctrl_pm_select_default_state(dev);
1915         }
1916
1917         return 0;
1918 }
1919 #endif
1920
1921 static const struct dev_pm_ops mmci_dev_pm_ops = {
1922         SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1923                                 pm_runtime_force_resume)
1924         SET_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL)
1925 };
1926
1927 static const struct amba_id mmci_ids[] = {
1928         {
1929                 .id     = 0x00041180,
1930                 .mask   = 0xff0fffff,
1931                 .data   = &variant_arm,
1932         },
1933         {
1934                 .id     = 0x01041180,
1935                 .mask   = 0xff0fffff,
1936                 .data   = &variant_arm_extended_fifo,
1937         },
1938         {
1939                 .id     = 0x02041180,
1940                 .mask   = 0xff0fffff,
1941                 .data   = &variant_arm_extended_fifo_hwfc,
1942         },
1943         {
1944                 .id     = 0x00041181,
1945                 .mask   = 0x000fffff,
1946                 .data   = &variant_arm,
1947         },
1948         /* ST Micro variants */
1949         {
1950                 .id     = 0x00180180,
1951                 .mask   = 0x00ffffff,
1952                 .data   = &variant_u300,
1953         },
1954         {
1955                 .id     = 0x10180180,
1956                 .mask   = 0xf0ffffff,
1957                 .data   = &variant_nomadik,
1958         },
1959         {
1960                 .id     = 0x00280180,
1961                 .mask   = 0x00ffffff,
1962                 .data   = &variant_nomadik,
1963         },
1964         {
1965                 .id     = 0x00480180,
1966                 .mask   = 0xf0ffffff,
1967                 .data   = &variant_ux500,
1968         },
1969         {
1970                 .id     = 0x10480180,
1971                 .mask   = 0xf0ffffff,
1972                 .data   = &variant_ux500v2,
1973         },
1974         /* Qualcomm variants */
1975         {
1976                 .id     = 0x00051180,
1977                 .mask   = 0x000fffff,
1978                 .data   = &variant_qcom,
1979         },
1980         { 0, 0 },
1981 };
1982
1983 MODULE_DEVICE_TABLE(amba, mmci_ids);
1984
1985 static struct amba_driver mmci_driver = {
1986         .drv            = {
1987                 .name   = DRIVER_NAME,
1988                 .pm     = &mmci_dev_pm_ops,
1989         },
1990         .probe          = mmci_probe,
1991         .remove         = mmci_remove,
1992         .id_table       = mmci_ids,
1993 };
1994
1995 module_amba_driver(mmci_driver);
1996
1997 module_param(fmax, uint, 0444);
1998
1999 MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
2000 MODULE_LICENSE("GPL");