mmci.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  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/interrupt.h>
  17. #include <linux/kernel.h>
  18. #include <linux/delay.h>
  19. #include <linux/err.h>
  20. #include <linux/highmem.h>
  21. #include <linux/log2.h>
  22. #include <linux/mmc/host.h>
  23. #include <linux/mmc/card.h>
  24. #include <linux/amba/bus.h>
  25. #include <linux/clk.h>
  26. #include <linux/scatterlist.h>
  27. #include <linux/gpio.h>
  28. #include <linux/regulator/consumer.h>
  29. #include <linux/dmaengine.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/amba/mmci.h>
  32. #include <asm/div64.h>
  33. #include <asm/io.h>
  34. #include <asm/sizes.h>
  35. #include "mmci.h"
  36. #define DRIVER_NAME "mmci-pl18x"
  37. static unsigned int fmax = 515633;
  38. /**
  39. * struct variant_data - MMCI variant-specific quirks
  40. * @clkreg: default value for MCICLOCK register
  41. * @clkreg_enable: enable value for MMCICLOCK register
  42. * @datalength_bits: number of bits in the MMCIDATALENGTH register
  43. * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
  44. * is asserted (likewise for RX)
  45. * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
  46. * is asserted (likewise for RX)
  47. * @sdio: variant supports SDIO
  48. * @st_clkdiv: true if using a ST-specific clock divider algorithm
  49. * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
  50. */
  51. struct variant_data {
  52. unsigned int clkreg;
  53. unsigned int clkreg_enable;
  54. unsigned int datalength_bits;
  55. unsigned int fifosize;
  56. unsigned int fifohalfsize;
  57. bool sdio;
  58. bool st_clkdiv;
  59. bool blksz_datactrl16;
  60. };
  61. static struct variant_data variant_arm = {
  62. .fifosize = 16 * 4,
  63. .fifohalfsize = 8 * 4,
  64. .datalength_bits = 16,
  65. };
  66. static struct variant_data variant_arm_extended_fifo = {
  67. .fifosize = 128 * 4,
  68. .fifohalfsize = 64 * 4,
  69. .datalength_bits = 16,
  70. };
  71. static struct variant_data variant_u300 = {
  72. .fifosize = 16 * 4,
  73. .fifohalfsize = 8 * 4,
  74. .clkreg_enable = MCI_ST_U300_HWFCEN,
  75. .datalength_bits = 16,
  76. .sdio = true,
  77. };
  78. static struct variant_data variant_ux500 = {
  79. .fifosize = 30 * 4,
  80. .fifohalfsize = 8 * 4,
  81. .clkreg = MCI_CLK_ENABLE,
  82. .clkreg_enable = MCI_ST_UX500_HWFCEN,
  83. .datalength_bits = 24,
  84. .sdio = true,
  85. .st_clkdiv = true,
  86. };
  87. static struct variant_data variant_ux500v2 = {
  88. .fifosize = 30 * 4,
  89. .fifohalfsize = 8 * 4,
  90. .clkreg = MCI_CLK_ENABLE,
  91. .clkreg_enable = MCI_ST_UX500_HWFCEN,
  92. .datalength_bits = 24,
  93. .sdio = true,
  94. .st_clkdiv = true,
  95. .blksz_datactrl16 = true,
  96. };
  97. /*
  98. * This must be called with host->lock held
  99. */
  100. static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
  101. {
  102. struct variant_data *variant = host->variant;
  103. u32 clk = variant->clkreg;
  104. if (desired) {
  105. if (desired >= host->mclk) {
  106. clk = MCI_CLK_BYPASS;
  107. if (variant->st_clkdiv)
  108. clk |= MCI_ST_UX500_NEG_EDGE;
  109. host->cclk = host->mclk;
  110. } else if (variant->st_clkdiv) {
  111. /*
  112. * DB8500 TRM says f = mclk / (clkdiv + 2)
  113. * => clkdiv = (mclk / f) - 2
  114. * Round the divider up so we don't exceed the max
  115. * frequency
  116. */
  117. clk = DIV_ROUND_UP(host->mclk, desired) - 2;
  118. if (clk >= 256)
  119. clk = 255;
  120. host->cclk = host->mclk / (clk + 2);
  121. } else {
  122. /*
  123. * PL180 TRM says f = mclk / (2 * (clkdiv + 1))
  124. * => clkdiv = mclk / (2 * f) - 1
  125. */
  126. clk = host->mclk / (2 * desired) - 1;
  127. if (clk >= 256)
  128. clk = 255;
  129. host->cclk = host->mclk / (2 * (clk + 1));
  130. }
  131. clk |= variant->clkreg_enable;
  132. clk |= MCI_CLK_ENABLE;
  133. /* This hasn't proven to be worthwhile */
  134. /* clk |= MCI_CLK_PWRSAVE; */
  135. }
  136. if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
  137. clk |= MCI_4BIT_BUS;
  138. if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
  139. clk |= MCI_ST_8BIT_BUS;
  140. writel(clk, host->base + MMCICLOCK);
  141. }
  142. static void
  143. mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
  144. {
  145. writel(0, host->base + MMCICOMMAND);
  146. BUG_ON(host->data);
  147. host->mrq = NULL;
  148. host->cmd = NULL;
  149. /*
  150. * Need to drop the host lock here; mmc_request_done may call
  151. * back into the driver...
  152. */
  153. spin_unlock(&host->lock);
  154. mmc_request_done(host->mmc, mrq);
  155. spin_lock(&host->lock);
  156. }
  157. static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
  158. {
  159. void __iomem *base = host->base;
  160. if (host->singleirq) {
  161. unsigned int mask0 = readl(base + MMCIMASK0);
  162. mask0 &= ~MCI_IRQ1MASK;
  163. mask0 |= mask;
  164. writel(mask0, base + MMCIMASK0);
  165. }
  166. writel(mask, base + MMCIMASK1);
  167. }
  168. static void mmci_stop_data(struct mmci_host *host)
  169. {
  170. writel(0, host->base + MMCIDATACTRL);
  171. mmci_set_mask1(host, 0);
  172. host->data = NULL;
  173. }
  174. static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
  175. {
  176. unsigned int flags = SG_MITER_ATOMIC;
  177. if (data->flags & MMC_DATA_READ)
  178. flags |= SG_MITER_TO_SG;
  179. else
  180. flags |= SG_MITER_FROM_SG;
  181. sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  182. }
  183. /*
  184. * All the DMA operation mode stuff goes inside this ifdef.
  185. * This assumes that you have a generic DMA device interface,
  186. * no custom DMA interfaces are supported.
  187. */
  188. #ifdef CONFIG_DMA_ENGINE
  189. static void __devinit mmci_dma_setup(struct mmci_host *host)
  190. {
  191. struct mmci_platform_data *plat = host->plat;
  192. const char *rxname, *txname;
  193. dma_cap_mask_t mask;
  194. if (!plat || !plat->dma_filter) {
  195. dev_info(mmc_dev(host->mmc), "no DMA platform data\n");
  196. return;
  197. }
  198. /* Try to acquire a generic DMA engine slave channel */
  199. dma_cap_zero(mask);
  200. dma_cap_set(DMA_SLAVE, mask);
  201. /*
  202. * If only an RX channel is specified, the driver will
  203. * attempt to use it bidirectionally, however if it is
  204. * is specified but cannot be located, DMA will be disabled.
  205. */
  206. if (plat->dma_rx_param) {
  207. host->dma_rx_channel = dma_request_channel(mask,
  208. plat->dma_filter,
  209. plat->dma_rx_param);
  210. /* E.g if no DMA hardware is present */
  211. if (!host->dma_rx_channel)
  212. dev_err(mmc_dev(host->mmc), "no RX DMA channel\n");
  213. }
  214. if (plat->dma_tx_param) {
  215. host->dma_tx_channel = dma_request_channel(mask,
  216. plat->dma_filter,
  217. plat->dma_tx_param);
  218. if (!host->dma_tx_channel)
  219. dev_warn(mmc_dev(host->mmc), "no TX DMA channel\n");
  220. } else {
  221. host->dma_tx_channel = host->dma_rx_channel;
  222. }
  223. if (host->dma_rx_channel)
  224. rxname = dma_chan_name(host->dma_rx_channel);
  225. else
  226. rxname = "none";
  227. if (host->dma_tx_channel)
  228. txname = dma_chan_name(host->dma_tx_channel);
  229. else
  230. txname = "none";
  231. dev_info(mmc_dev(host->mmc), "DMA channels RX %s, TX %s\n",
  232. rxname, txname);
  233. /*
  234. * Limit the maximum segment size in any SG entry according to
  235. * the parameters of the DMA engine device.
  236. */
  237. if (host->dma_tx_channel) {
  238. struct device *dev = host->dma_tx_channel->device->dev;
  239. unsigned int max_seg_size = dma_get_max_seg_size(dev);
  240. if (max_seg_size < host->mmc->max_seg_size)
  241. host->mmc->max_seg_size = max_seg_size;
  242. }
  243. if (host->dma_rx_channel) {
  244. struct device *dev = host->dma_rx_channel->device->dev;
  245. unsigned int max_seg_size = dma_get_max_seg_size(dev);
  246. if (max_seg_size < host->mmc->max_seg_size)
  247. host->mmc->max_seg_size = max_seg_size;
  248. }
  249. }
  250. /*
  251. * This is used in __devinit or __devexit so inline it
  252. * so it can be discarded.
  253. */
  254. static inline void mmci_dma_release(struct mmci_host *host)
  255. {
  256. struct mmci_platform_data *plat = host->plat;
  257. if (host->dma_rx_channel)
  258. dma_release_channel(host->dma_rx_channel);
  259. if (host->dma_tx_channel && plat->dma_tx_param)
  260. dma_release_channel(host->dma_tx_channel);
  261. host->dma_rx_channel = host->dma_tx_channel = NULL;
  262. }
  263. static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
  264. {
  265. struct dma_chan *chan = host->dma_current;
  266. enum dma_data_direction dir;
  267. u32 status;
  268. int i;
  269. /* Wait up to 1ms for the DMA to complete */
  270. for (i = 0; ; i++) {
  271. status = readl(host->base + MMCISTATUS);
  272. if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100)
  273. break;
  274. udelay(10);
  275. }
  276. /*
  277. * Check to see whether we still have some data left in the FIFO -
  278. * this catches DMA controllers which are unable to monitor the
  279. * DMALBREQ and DMALSREQ signals while allowing us to DMA to non-
  280. * contiguous buffers. On TX, we'll get a FIFO underrun error.
  281. */
  282. if (status & MCI_RXDATAAVLBLMASK) {
  283. dmaengine_terminate_all(chan);
  284. if (!data->error)
  285. data->error = -EIO;
  286. }
  287. if (data->flags & MMC_DATA_WRITE) {
  288. dir = DMA_TO_DEVICE;
  289. } else {
  290. dir = DMA_FROM_DEVICE;
  291. }
  292. dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, dir);
  293. /*
  294. * Use of DMA with scatter-gather is impossible.
  295. * Give up with DMA and switch back to PIO mode.
  296. */
  297. if (status & MCI_RXDATAAVLBLMASK) {
  298. dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n");
  299. mmci_dma_release(host);
  300. }
  301. }
  302. static void mmci_dma_data_error(struct mmci_host *host)
  303. {
  304. dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n");
  305. dmaengine_terminate_all(host->dma_current);
  306. }
  307. static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
  308. {
  309. struct variant_data *variant = host->variant;
  310. struct dma_slave_config conf = {
  311. .src_addr = host->phybase + MMCIFIFO,
  312. .dst_addr = host->phybase + MMCIFIFO,
  313. .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  314. .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  315. .src_maxburst = variant->fifohalfsize >> 2, /* # of words */
  316. .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
  317. };
  318. struct mmc_data *data = host->data;
  319. struct dma_chan *chan;
  320. struct dma_device *device;
  321. struct dma_async_tx_descriptor *desc;
  322. int nr_sg;
  323. host->dma_current = NULL;
  324. if (data->flags & MMC_DATA_READ) {
  325. conf.direction = DMA_FROM_DEVICE;
  326. chan = host->dma_rx_channel;
  327. } else {
  328. conf.direction = DMA_TO_DEVICE;
  329. chan = host->dma_tx_channel;
  330. }
  331. /* If there's no DMA channel, fall back to PIO */
  332. if (!chan)
  333. return -EINVAL;
  334. /* If less than or equal to the fifo size, don't bother with DMA */
  335. if (host->size <= variant->fifosize)
  336. return -EINVAL;
  337. device = chan->device;
  338. nr_sg = dma_map_sg(device->dev, data->sg, data->sg_len, conf.direction);
  339. if (nr_sg == 0)
  340. return -EINVAL;
  341. dmaengine_slave_config(chan, &conf);
  342. desc = device->device_prep_slave_sg(chan, data->sg, nr_sg,
  343. conf.direction, DMA_CTRL_ACK);
  344. if (!desc)
  345. goto unmap_exit;
  346. /* Okay, go for it. */
  347. host->dma_current = chan;
  348. dev_vdbg(mmc_dev(host->mmc),
  349. "Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n",
  350. data->sg_len, data->blksz, data->blocks, data->flags);
  351. dmaengine_submit(desc);
  352. dma_async_issue_pending(chan);
  353. datactrl |= MCI_DPSM_DMAENABLE;
  354. /* Trigger the DMA transfer */
  355. writel(datactrl, host->base + MMCIDATACTRL);
  356. /*
  357. * Let the MMCI say when the data is ended and it's time
  358. * to fire next DMA request. When that happens, MMCI will
  359. * call mmci_data_end()
  360. */
  361. writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK,
  362. host->base + MMCIMASK0);
  363. return 0;
  364. unmap_exit:
  365. dmaengine_terminate_all(chan);
  366. dma_unmap_sg(device->dev, data->sg, data->sg_len, conf.direction);
  367. return -ENOMEM;
  368. }
  369. #else
  370. /* Blank functions if the DMA engine is not available */
  371. static inline void mmci_dma_setup(struct mmci_host *host)
  372. {
  373. }
  374. static inline void mmci_dma_release(struct mmci_host *host)
  375. {
  376. }
  377. static inline void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
  378. {
  379. }
  380. static inline void mmci_dma_data_error(struct mmci_host *host)
  381. {
  382. }
  383. static inline int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
  384. {
  385. return -ENOSYS;
  386. }
  387. #endif
  388. static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
  389. {
  390. struct variant_data *variant = host->variant;
  391. unsigned int datactrl, timeout, irqmask;
  392. unsigned long long clks;
  393. void __iomem *base;
  394. int blksz_bits;
  395. dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n",
  396. data->blksz, data->blocks, data->flags);
  397. host->data = data;
  398. host->size = data->blksz * data->blocks;
  399. data->bytes_xfered = 0;
  400. clks = (unsigned long long)data->timeout_ns * host->cclk;
  401. do_div(clks, 1000000000UL);
  402. timeout = data->timeout_clks + (unsigned int)clks;
  403. base = host->base;
  404. writel(timeout, base + MMCIDATATIMER);
  405. writel(host->size, base + MMCIDATALENGTH);
  406. blksz_bits = ffs(data->blksz) - 1;
  407. BUG_ON(1 << blksz_bits != data->blksz);
  408. if (variant->blksz_datactrl16)
  409. datactrl = MCI_DPSM_ENABLE | (data->blksz << 16);
  410. else
  411. datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
  412. if (data->flags & MMC_DATA_READ)
  413. datactrl |= MCI_DPSM_DIRECTION;
  414. /*
  415. * Attempt to use DMA operation mode, if this
  416. * should fail, fall back to PIO mode
  417. */
  418. if (!mmci_dma_start_data(host, datactrl))
  419. return;
  420. /* IRQ mode, map the SG list for CPU reading/writing */
  421. mmci_init_sg(host, data);
  422. if (data->flags & MMC_DATA_READ) {
  423. irqmask = MCI_RXFIFOHALFFULLMASK;
  424. /*
  425. * If we have less than the fifo 'half-full' threshold to
  426. * transfer, trigger a PIO interrupt as soon as any data
  427. * is available.
  428. */
  429. if (host->size < variant->fifohalfsize)
  430. irqmask |= MCI_RXDATAAVLBLMASK;
  431. } else {
  432. /*
  433. * We don't actually need to include "FIFO empty" here
  434. * since its implicit in "FIFO half empty".
  435. */
  436. irqmask = MCI_TXFIFOHALFEMPTYMASK;
  437. }
  438. /* The ST Micro variants has a special bit to enable SDIO */
  439. if (variant->sdio && host->mmc->card)
  440. if (mmc_card_sdio(host->mmc->card))
  441. datactrl |= MCI_ST_DPSM_SDIOEN;
  442. writel(datactrl, base + MMCIDATACTRL);
  443. writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
  444. mmci_set_mask1(host, irqmask);
  445. }
  446. static void
  447. mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c)
  448. {
  449. void __iomem *base = host->base;
  450. dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n",
  451. cmd->opcode, cmd->arg, cmd->flags);
  452. if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) {
  453. writel(0, base + MMCICOMMAND);
  454. udelay(1);
  455. }
  456. c |= cmd->opcode | MCI_CPSM_ENABLE;
  457. if (cmd->flags & MMC_RSP_PRESENT) {
  458. if (cmd->flags & MMC_RSP_136)
  459. c |= MCI_CPSM_LONGRSP;
  460. c |= MCI_CPSM_RESPONSE;
  461. }
  462. if (/*interrupt*/0)
  463. c |= MCI_CPSM_INTERRUPT;
  464. host->cmd = cmd;
  465. writel(cmd->arg, base + MMCIARGUMENT);
  466. writel(c, base + MMCICOMMAND);
  467. }
  468. static void
  469. mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
  470. unsigned int status)
  471. {
  472. /* First check for errors */
  473. if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
  474. u32 remain, success;
  475. /* Terminate the DMA transfer */
  476. if (dma_inprogress(host))
  477. mmci_dma_data_error(host);
  478. /*
  479. * Calculate how far we are into the transfer. Note that
  480. * the data counter gives the number of bytes transferred
  481. * on the MMC bus, not on the host side. On reads, this
  482. * can be as much as a FIFO-worth of data ahead. This
  483. * matters for FIFO overruns only.
  484. */
  485. remain = readl(host->base + MMCIDATACNT);
  486. success = data->blksz * data->blocks - remain;
  487. dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n",
  488. status, success);
  489. if (status & MCI_DATACRCFAIL) {
  490. /* Last block was not successful */
  491. success -= 1;
  492. data->error = -EILSEQ;
  493. } else if (status & MCI_DATATIMEOUT) {
  494. data->error = -ETIMEDOUT;
  495. } else if (status & MCI_TXUNDERRUN) {
  496. data->error = -EIO;
  497. } else if (status & MCI_RXOVERRUN) {
  498. if (success > host->variant->fifosize)
  499. success -= host->variant->fifosize;
  500. else
  501. success = 0;
  502. data->error = -EIO;
  503. }
  504. data->bytes_xfered = round_down(success, data->blksz);
  505. }
  506. if (status & MCI_DATABLOCKEND)
  507. dev_err(mmc_dev(host->mmc), "stray MCI_DATABLOCKEND interrupt\n");
  508. if (status & MCI_DATAEND || data->error) {
  509. if (dma_inprogress(host))
  510. mmci_dma_unmap(host, data);
  511. mmci_stop_data(host);
  512. if (!data->error)
  513. /* The error clause is handled above, success! */
  514. data->bytes_xfered = data->blksz * data->blocks;
  515. if (!data->stop) {
  516. mmci_request_end(host, data->mrq);
  517. } else {
  518. mmci_start_command(host, data->stop, 0);
  519. }
  520. }
  521. }
  522. static void
  523. mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
  524. unsigned int status)
  525. {
  526. void __iomem *base = host->base;
  527. host->cmd = NULL;
  528. if (status & MCI_CMDTIMEOUT) {
  529. cmd->error = -ETIMEDOUT;
  530. } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
  531. cmd->error = -EILSEQ;
  532. } else {
  533. cmd->resp[0] = readl(base + MMCIRESPONSE0);
  534. cmd->resp[1] = readl(base + MMCIRESPONSE1);
  535. cmd->resp[2] = readl(base + MMCIRESPONSE2);
  536. cmd->resp[3] = readl(base + MMCIRESPONSE3);
  537. }
  538. if (!cmd->data || cmd->error) {
  539. if (host->data)
  540. mmci_stop_data(host);
  541. mmci_request_end(host, cmd->mrq);
  542. } else if (!(cmd->data->flags & MMC_DATA_READ)) {
  543. mmci_start_data(host, cmd->data);
  544. }
  545. }
  546. static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain)
  547. {
  548. void __iomem *base = host->base;
  549. char *ptr = buffer;
  550. u32 status;
  551. int host_remain = host->size;
  552. do {
  553. int count = host_remain - (readl(base + MMCIFIFOCNT) << 2);
  554. if (count > remain)
  555. count = remain;
  556. if (count <= 0)
  557. break;
  558. readsl(base + MMCIFIFO, ptr, count >> 2);
  559. ptr += count;
  560. remain -= count;
  561. host_remain -= count;
  562. if (remain == 0)
  563. break;
  564. status = readl(base + MMCISTATUS);
  565. } while (status & MCI_RXDATAAVLBL);
  566. return ptr - buffer;
  567. }
  568. static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status)
  569. {
  570. struct variant_data *variant = host->variant;
  571. void __iomem *base = host->base;
  572. char *ptr = buffer;
  573. do {
  574. unsigned int count, maxcnt;
  575. maxcnt = status & MCI_TXFIFOEMPTY ?
  576. variant->fifosize : variant->fifohalfsize;
  577. count = min(remain, maxcnt);
  578. /*
  579. * The ST Micro variant for SDIO transfer sizes
  580. * less then 8 bytes should have clock H/W flow
  581. * control disabled.
  582. */
  583. if (variant->sdio &&
  584. mmc_card_sdio(host->mmc->card)) {
  585. if (count < 8)
  586. writel(readl(host->base + MMCICLOCK) &
  587. ~variant->clkreg_enable,
  588. host->base + MMCICLOCK);
  589. else
  590. writel(readl(host->base + MMCICLOCK) |
  591. variant->clkreg_enable,
  592. host->base + MMCICLOCK);
  593. }
  594. /*
  595. * SDIO especially may want to send something that is
  596. * not divisible by 4 (as opposed to card sectors
  597. * etc), and the FIFO only accept full 32-bit writes.
  598. * So compensate by adding +3 on the count, a single
  599. * byte become a 32bit write, 7 bytes will be two
  600. * 32bit writes etc.
  601. */
  602. writesl(base + MMCIFIFO, ptr, (count + 3) >> 2);
  603. ptr += count;
  604. remain -= count;
  605. if (remain == 0)
  606. break;
  607. status = readl(base + MMCISTATUS);
  608. } while (status & MCI_TXFIFOHALFEMPTY);
  609. return ptr - buffer;
  610. }
  611. /*
  612. * PIO data transfer IRQ handler.
  613. */
  614. static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
  615. {
  616. struct mmci_host *host = dev_id;
  617. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  618. struct variant_data *variant = host->variant;
  619. void __iomem *base = host->base;
  620. unsigned long flags;
  621. u32 status;
  622. status = readl(base + MMCISTATUS);
  623. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  624. local_irq_save(flags);
  625. do {
  626. unsigned int remain, len;
  627. char *buffer;
  628. /*
  629. * For write, we only need to test the half-empty flag
  630. * here - if the FIFO is completely empty, then by
  631. * definition it is more than half empty.
  632. *
  633. * For read, check for data available.
  634. */
  635. if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
  636. break;
  637. if (!sg_miter_next(sg_miter))
  638. break;
  639. buffer = sg_miter->addr;
  640. remain = sg_miter->length;
  641. len = 0;
  642. if (status & MCI_RXACTIVE)
  643. len = mmci_pio_read(host, buffer, remain);
  644. if (status & MCI_TXACTIVE)
  645. len = mmci_pio_write(host, buffer, remain, status);
  646. sg_miter->consumed = len;
  647. host->size -= len;
  648. remain -= len;
  649. if (remain)
  650. break;
  651. status = readl(base + MMCISTATUS);
  652. } while (1);
  653. sg_miter_stop(sg_miter);
  654. local_irq_restore(flags);
  655. /*
  656. * If we have less than the fifo 'half-full' threshold to transfer,
  657. * trigger a PIO interrupt as soon as any data is available.
  658. */
  659. if (status & MCI_RXACTIVE && host->size < variant->fifohalfsize)
  660. mmci_set_mask1(host, MCI_RXDATAAVLBLMASK);
  661. /*
  662. * If we run out of data, disable the data IRQs; this
  663. * prevents a race where the FIFO becomes empty before
  664. * the chip itself has disabled the data path, and
  665. * stops us racing with our data end IRQ.
  666. */
  667. if (host->size == 0) {
  668. mmci_set_mask1(host, 0);
  669. writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0);
  670. }
  671. return IRQ_HANDLED;
  672. }
  673. /*
  674. * Handle completion of command and data transfers.
  675. */
  676. static irqreturn_t mmci_irq(int irq, void *dev_id)
  677. {
  678. struct mmci_host *host = dev_id;
  679. u32 status;
  680. int ret = 0;
  681. spin_lock(&host->lock);
  682. do {
  683. struct mmc_command *cmd;
  684. struct mmc_data *data;
  685. status = readl(host->base + MMCISTATUS);
  686. if (host->singleirq) {
  687. if (status & readl(host->base + MMCIMASK1))
  688. mmci_pio_irq(irq, dev_id);
  689. status &= ~MCI_IRQ1MASK;
  690. }
  691. status &= readl(host->base + MMCIMASK0);
  692. writel(status, host->base + MMCICLEAR);
  693. dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status);
  694. data = host->data;
  695. if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|
  696. MCI_RXOVERRUN|MCI_DATAEND|MCI_DATABLOCKEND) && data)
  697. mmci_data_irq(host, data, status);
  698. cmd = host->cmd;
  699. if (status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND) && cmd)
  700. mmci_cmd_irq(host, cmd, status);
  701. ret = 1;
  702. } while (status);
  703. spin_unlock(&host->lock);
  704. return IRQ_RETVAL(ret);
  705. }
  706. static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  707. {
  708. struct mmci_host *host = mmc_priv(mmc);
  709. unsigned long flags;
  710. WARN_ON(host->mrq != NULL);
  711. if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
  712. dev_err(mmc_dev(mmc), "unsupported block size (%d bytes)\n",
  713. mrq->data->blksz);
  714. mrq->cmd->error = -EINVAL;
  715. mmc_request_done(mmc, mrq);
  716. return;
  717. }
  718. spin_lock_irqsave(&host->lock, flags);
  719. host->mrq = mrq;
  720. if (mrq->data && mrq->data->flags & MMC_DATA_READ)
  721. mmci_start_data(host, mrq->data);
  722. mmci_start_command(host, mrq->cmd, 0);
  723. spin_unlock_irqrestore(&host->lock, flags);
  724. }
  725. static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  726. {
  727. struct mmci_host *host = mmc_priv(mmc);
  728. u32 pwr = 0;
  729. unsigned long flags;
  730. int ret;
  731. switch (ios->power_mode) {
  732. case MMC_POWER_OFF:
  733. if (host->vcc)
  734. ret = mmc_regulator_set_ocr(mmc, host->vcc, 0);
  735. break;
  736. case MMC_POWER_UP:
  737. if (host->vcc) {
  738. ret = mmc_regulator_set_ocr(mmc, host->vcc, ios->vdd);
  739. if (ret) {
  740. dev_err(mmc_dev(mmc), "unable to set OCR\n");
  741. /*
  742. * The .set_ios() function in the mmc_host_ops
  743. * struct return void, and failing to set the
  744. * power should be rare so we print an error
  745. * and return here.
  746. */
  747. return;
  748. }
  749. }
  750. if (host->plat->vdd_handler)
  751. pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd,
  752. ios->power_mode);
  753. /* The ST version does not have this, fall through to POWER_ON */
  754. if (host->hw_designer != AMBA_VENDOR_ST) {
  755. pwr |= MCI_PWR_UP;
  756. break;
  757. }
  758. case MMC_POWER_ON:
  759. pwr |= MCI_PWR_ON;
  760. break;
  761. }
  762. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
  763. if (host->hw_designer != AMBA_VENDOR_ST)
  764. pwr |= MCI_ROD;
  765. else {
  766. /*
  767. * The ST Micro variant use the ROD bit for something
  768. * else and only has OD (Open Drain).
  769. */
  770. pwr |= MCI_OD;
  771. }
  772. }
  773. spin_lock_irqsave(&host->lock, flags);
  774. mmci_set_clkreg(host, ios->clock);
  775. if (host->pwr != pwr) {
  776. host->pwr = pwr;
  777. writel(pwr, host->base + MMCIPOWER);
  778. }
  779. spin_unlock_irqrestore(&host->lock, flags);
  780. }
  781. static int mmci_get_ro(struct mmc_host *mmc)
  782. {
  783. struct mmci_host *host = mmc_priv(mmc);
  784. if (host->gpio_wp == -ENOSYS)
  785. return -ENOSYS;
  786. return gpio_get_value_cansleep(host->gpio_wp);
  787. }
  788. static int mmci_get_cd(struct mmc_host *mmc)
  789. {
  790. struct mmci_host *host = mmc_priv(mmc);
  791. struct mmci_platform_data *plat = host->plat;
  792. unsigned int status;
  793. if (host->gpio_cd == -ENOSYS) {
  794. if (!plat->status)
  795. return 1; /* Assume always present */
  796. status = plat->status(mmc_dev(host->mmc));
  797. } else
  798. status = !!gpio_get_value_cansleep(host->gpio_cd)
  799. ^ plat->cd_invert;
  800. /*
  801. * Use positive logic throughout - status is zero for no card,
  802. * non-zero for card inserted.
  803. */
  804. return status;
  805. }
  806. static irqreturn_t mmci_cd_irq(int irq, void *dev_id)
  807. {
  808. struct mmci_host *host = dev_id;
  809. mmc_detect_change(host->mmc, msecs_to_jiffies(500));
  810. return IRQ_HANDLED;
  811. }
  812. static const struct mmc_host_ops mmci_ops = {
  813. .request = mmci_request,
  814. .set_ios = mmci_set_ios,
  815. .get_ro = mmci_get_ro,
  816. .get_cd = mmci_get_cd,
  817. };
  818. static int __devinit mmci_probe(struct amba_device *dev,
  819. const struct amba_id *id)
  820. {
  821. struct mmci_platform_data *plat = dev->dev.platform_data;
  822. struct variant_data *variant = id->data;
  823. struct mmci_host *host;
  824. struct mmc_host *mmc;
  825. int ret;
  826. /* must have platform data */
  827. if (!plat) {
  828. ret = -EINVAL;
  829. goto out;
  830. }
  831. ret = amba_request_regions(dev, DRIVER_NAME);
  832. if (ret)
  833. goto out;
  834. mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
  835. if (!mmc) {
  836. ret = -ENOMEM;
  837. goto rel_regions;
  838. }
  839. host = mmc_priv(mmc);
  840. host->mmc = mmc;
  841. host->gpio_wp = -ENOSYS;
  842. host->gpio_cd = -ENOSYS;
  843. host->gpio_cd_irq = -1;
  844. host->hw_designer = amba_manf(dev);
  845. host->hw_revision = amba_rev(dev);
  846. dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
  847. dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision);
  848. host->clk = clk_get(&dev->dev, NULL);
  849. if (IS_ERR(host->clk)) {
  850. ret = PTR_ERR(host->clk);
  851. host->clk = NULL;
  852. goto host_free;
  853. }
  854. ret = clk_enable(host->clk);
  855. if (ret)
  856. goto clk_free;
  857. host->plat = plat;
  858. host->variant = variant;
  859. host->mclk = clk_get_rate(host->clk);
  860. /*
  861. * According to the spec, mclk is max 100 MHz,
  862. * so we try to adjust the clock down to this,
  863. * (if possible).
  864. */
  865. if (host->mclk > 100000000) {
  866. ret = clk_set_rate(host->clk, 100000000);
  867. if (ret < 0)
  868. goto clk_disable;
  869. host->mclk = clk_get_rate(host->clk);
  870. dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n",
  871. host->mclk);
  872. }
  873. host->phybase = dev->res.start;
  874. host->base = ioremap(dev->res.start, resource_size(&dev->res));
  875. if (!host->base) {
  876. ret = -ENOMEM;
  877. goto clk_disable;
  878. }
  879. mmc->ops = &mmci_ops;
  880. mmc->f_min = (host->mclk + 511) / 512;
  881. /*
  882. * If the platform data supplies a maximum operating
  883. * frequency, this takes precedence. Else, we fall back
  884. * to using the module parameter, which has a (low)
  885. * default value in case it is not specified. Either
  886. * value must not exceed the clock rate into the block,
  887. * of course.
  888. */
  889. if (plat->f_max)
  890. mmc->f_max = min(host->mclk, plat->f_max);
  891. else
  892. mmc->f_max = min(host->mclk, fmax);
  893. dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
  894. #ifdef CONFIG_REGULATOR
  895. /* If we're using the regulator framework, try to fetch a regulator */
  896. host->vcc = regulator_get(&dev->dev, "vmmc");
  897. if (IS_ERR(host->vcc))
  898. host->vcc = NULL;
  899. else {
  900. int mask = mmc_regulator_get_ocrmask(host->vcc);
  901. if (mask < 0)
  902. dev_err(&dev->dev, "error getting OCR mask (%d)\n",
  903. mask);
  904. else {
  905. host->mmc->ocr_avail = (u32) mask;
  906. if (plat->ocr_mask)
  907. dev_warn(&dev->dev,
  908. "Provided ocr_mask/setpower will not be used "
  909. "(using regulator instead)\n");
  910. }
  911. }
  912. #endif
  913. /* Fall back to platform data if no regulator is found */
  914. if (host->vcc == NULL)
  915. mmc->ocr_avail = plat->ocr_mask;
  916. mmc->caps = plat->capabilities;
  917. /*
  918. * We can do SGIO
  919. */
  920. mmc->max_segs = NR_SG;
  921. /*
  922. * Since only a certain number of bits are valid in the data length
  923. * register, we must ensure that we don't exceed 2^num-1 bytes in a
  924. * single request.
  925. */
  926. mmc->max_req_size = (1 << variant->datalength_bits) - 1;
  927. /*
  928. * Set the maximum segment size. Since we aren't doing DMA
  929. * (yet) we are only limited by the data length register.
  930. */
  931. mmc->max_seg_size = mmc->max_req_size;
  932. /*
  933. * Block size can be up to 2048 bytes, but must be a power of two.
  934. */
  935. mmc->max_blk_size = 2048;
  936. /*
  937. * No limit on the number of blocks transferred.
  938. */
  939. mmc->max_blk_count = mmc->max_req_size;
  940. spin_lock_init(&host->lock);
  941. writel(0, host->base + MMCIMASK0);
  942. writel(0, host->base + MMCIMASK1);
  943. writel(0xfff, host->base + MMCICLEAR);
  944. if (gpio_is_valid(plat->gpio_cd)) {
  945. ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)");
  946. if (ret == 0)
  947. ret = gpio_direction_input(plat->gpio_cd);
  948. if (ret == 0)
  949. host->gpio_cd = plat->gpio_cd;
  950. else if (ret != -ENOSYS)
  951. goto err_gpio_cd;
  952. /*
  953. * A gpio pin that will detect cards when inserted and removed
  954. * will most likely want to trigger on the edges if it is
  955. * 0 when ejected and 1 when inserted (or mutatis mutandis
  956. * for the inverted case) so we request triggers on both
  957. * edges.
  958. */
  959. ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd),
  960. mmci_cd_irq,
  961. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  962. DRIVER_NAME " (cd)", host);
  963. if (ret >= 0)
  964. host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd);
  965. }
  966. if (gpio_is_valid(plat->gpio_wp)) {
  967. ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)");
  968. if (ret == 0)
  969. ret = gpio_direction_input(plat->gpio_wp);
  970. if (ret == 0)
  971. host->gpio_wp = plat->gpio_wp;
  972. else if (ret != -ENOSYS)
  973. goto err_gpio_wp;
  974. }
  975. if ((host->plat->status || host->gpio_cd != -ENOSYS)
  976. && host->gpio_cd_irq < 0)
  977. mmc->caps |= MMC_CAP_NEEDS_POLL;
  978. ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host);
  979. if (ret)
  980. goto unmap;
  981. if (dev->irq[1] == NO_IRQ)
  982. host->singleirq = true;
  983. else {
  984. ret = request_irq(dev->irq[1], mmci_pio_irq, IRQF_SHARED,
  985. DRIVER_NAME " (pio)", host);
  986. if (ret)
  987. goto irq0_free;
  988. }
  989. writel(MCI_IRQENABLE, host->base + MMCIMASK0);
  990. amba_set_drvdata(dev, mmc);
  991. dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
  992. mmc_hostname(mmc), amba_part(dev), amba_manf(dev),
  993. amba_rev(dev), (unsigned long long)dev->res.start,
  994. dev->irq[0], dev->irq[1]);
  995. mmci_dma_setup(host);
  996. mmc_add_host(mmc);
  997. return 0;
  998. irq0_free:
  999. free_irq(dev->irq[0], host);
  1000. unmap:
  1001. if (host->gpio_wp != -ENOSYS)
  1002. gpio_free(host->gpio_wp);
  1003. err_gpio_wp:
  1004. if (host->gpio_cd_irq >= 0)
  1005. free_irq(host->gpio_cd_irq, host);
  1006. if (host->gpio_cd != -ENOSYS)
  1007. gpio_free(host->gpio_cd);
  1008. err_gpio_cd:
  1009. iounmap(host->base);
  1010. clk_disable:
  1011. clk_disable(host->clk);
  1012. clk_free:
  1013. clk_put(host->clk);
  1014. host_free:
  1015. mmc_free_host(mmc);
  1016. rel_regions:
  1017. amba_release_regions(dev);
  1018. out:
  1019. return ret;
  1020. }
  1021. static int __devexit mmci_remove(struct amba_device *dev)
  1022. {
  1023. struct mmc_host *mmc = amba_get_drvdata(dev);
  1024. amba_set_drvdata(dev, NULL);
  1025. if (mmc) {
  1026. struct mmci_host *host = mmc_priv(mmc);
  1027. mmc_remove_host(mmc);
  1028. writel(0, host->base + MMCIMASK0);
  1029. writel(0, host->base + MMCIMASK1);
  1030. writel(0, host->base + MMCICOMMAND);
  1031. writel(0, host->base + MMCIDATACTRL);
  1032. mmci_dma_release(host);
  1033. free_irq(dev->irq[0], host);
  1034. if (!host->singleirq)
  1035. free_irq(dev->irq[1], host);
  1036. if (host->gpio_wp != -ENOSYS)
  1037. gpio_free(host->gpio_wp);
  1038. if (host->gpio_cd_irq >= 0)
  1039. free_irq(host->gpio_cd_irq, host);
  1040. if (host->gpio_cd != -ENOSYS)
  1041. gpio_free(host->gpio_cd);
  1042. iounmap(host->base);
  1043. clk_disable(host->clk);
  1044. clk_put(host->clk);
  1045. if (host->vcc)
  1046. mmc_regulator_set_ocr(mmc, host->vcc, 0);
  1047. regulator_put(host->vcc);
  1048. mmc_free_host(mmc);
  1049. amba_release_regions(dev);
  1050. }
  1051. return 0;
  1052. }
  1053. #ifdef CONFIG_PM
  1054. static int mmci_suspend(struct amba_device *dev, pm_message_t state)
  1055. {
  1056. struct mmc_host *mmc = amba_get_drvdata(dev);
  1057. int ret = 0;
  1058. if (mmc) {
  1059. struct mmci_host *host = mmc_priv(mmc);
  1060. ret = mmc_suspend_host(mmc);
  1061. if (ret == 0)
  1062. writel(0, host->base + MMCIMASK0);
  1063. }
  1064. return ret;
  1065. }
  1066. static int mmci_resume(struct amba_device *dev)
  1067. {
  1068. struct mmc_host *mmc = amba_get_drvdata(dev);
  1069. int ret = 0;
  1070. if (mmc) {
  1071. struct mmci_host *host = mmc_priv(mmc);
  1072. writel(MCI_IRQENABLE, host->base + MMCIMASK0);
  1073. ret = mmc_resume_host(mmc);
  1074. }
  1075. return ret;
  1076. }
  1077. #else
  1078. #define mmci_suspend NULL
  1079. #define mmci_resume NULL
  1080. #endif
  1081. static struct amba_id mmci_ids[] = {
  1082. {
  1083. .id = 0x00041180,
  1084. .mask = 0xff0fffff,
  1085. .data = &variant_arm,
  1086. },
  1087. {
  1088. .id = 0x01041180,
  1089. .mask = 0xff0fffff,
  1090. .data = &variant_arm_extended_fifo,
  1091. },
  1092. {
  1093. .id = 0x00041181,
  1094. .mask = 0x000fffff,
  1095. .data = &variant_arm,
  1096. },
  1097. /* ST Micro variants */
  1098. {
  1099. .id = 0x00180180,
  1100. .mask = 0x00ffffff,
  1101. .data = &variant_u300,
  1102. },
  1103. {
  1104. .id = 0x00280180,
  1105. .mask = 0x00ffffff,
  1106. .data = &variant_u300,
  1107. },
  1108. {
  1109. .id = 0x00480180,
  1110. .mask = 0xf0ffffff,
  1111. .data = &variant_ux500,
  1112. },
  1113. {
  1114. .id = 0x10480180,
  1115. .mask = 0xf0ffffff,
  1116. .data = &variant_ux500v2,
  1117. },
  1118. { 0, 0 },
  1119. };
  1120. static struct amba_driver mmci_driver = {
  1121. .drv = {
  1122. .name = DRIVER_NAME,
  1123. },
  1124. .probe = mmci_probe,
  1125. .remove = __devexit_p(mmci_remove),
  1126. .suspend = mmci_suspend,
  1127. .resume = mmci_resume,
  1128. .id_table = mmci_ids,
  1129. };
  1130. static int __init mmci_init(void)
  1131. {
  1132. return amba_driver_register(&mmci_driver);
  1133. }
  1134. static void __exit mmci_exit(void)
  1135. {
  1136. amba_driver_unregister(&mmci_driver);
  1137. }
  1138. module_init(mmci_init);
  1139. module_exit(mmci_exit);
  1140. module_param(fmax, uint, 0444);
  1141. MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
  1142. MODULE_LICENSE("GPL");