mmci.c 32 KB

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