atmel-mci.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. /*
  2. * Atmel MultiMedia Card Interface driver
  3. *
  4. * Copyright (C) 2004-2008 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/blkdev.h>
  11. #include <linux/clk.h>
  12. #include <linux/debugfs.h>
  13. #include <linux/device.h>
  14. #include <linux/dmaengine.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/err.h>
  17. #include <linux/gpio.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ioport.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/scatterlist.h>
  24. #include <linux/seq_file.h>
  25. #include <linux/slab.h>
  26. #include <linux/stat.h>
  27. #include <linux/mmc/host.h>
  28. #include <mach/atmel-mci.h>
  29. #include <linux/atmel-mci.h>
  30. #include <asm/io.h>
  31. #include <asm/unaligned.h>
  32. #include <mach/cpu.h>
  33. #include <mach/board.h>
  34. #include "atmel-mci-regs.h"
  35. #define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE)
  36. #define ATMCI_DMA_THRESHOLD 16
  37. enum {
  38. EVENT_CMD_COMPLETE = 0,
  39. EVENT_XFER_COMPLETE,
  40. EVENT_DATA_COMPLETE,
  41. EVENT_DATA_ERROR,
  42. };
  43. enum atmel_mci_state {
  44. STATE_IDLE = 0,
  45. STATE_SENDING_CMD,
  46. STATE_SENDING_DATA,
  47. STATE_DATA_BUSY,
  48. STATE_SENDING_STOP,
  49. STATE_DATA_ERROR,
  50. };
  51. struct atmel_mci_dma {
  52. #ifdef CONFIG_MMC_ATMELMCI_DMA
  53. struct dma_chan *chan;
  54. struct dma_async_tx_descriptor *data_desc;
  55. #endif
  56. };
  57. /**
  58. * struct atmel_mci - MMC controller state shared between all slots
  59. * @lock: Spinlock protecting the queue and associated data.
  60. * @regs: Pointer to MMIO registers.
  61. * @sg: Scatterlist entry currently being processed by PIO code, if any.
  62. * @pio_offset: Offset into the current scatterlist entry.
  63. * @cur_slot: The slot which is currently using the controller.
  64. * @mrq: The request currently being processed on @cur_slot,
  65. * or NULL if the controller is idle.
  66. * @cmd: The command currently being sent to the card, or NULL.
  67. * @data: The data currently being transferred, or NULL if no data
  68. * transfer is in progress.
  69. * @dma: DMA client state.
  70. * @data_chan: DMA channel being used for the current data transfer.
  71. * @cmd_status: Snapshot of SR taken upon completion of the current
  72. * command. Only valid when EVENT_CMD_COMPLETE is pending.
  73. * @data_status: Snapshot of SR taken upon completion of the current
  74. * data transfer. Only valid when EVENT_DATA_COMPLETE or
  75. * EVENT_DATA_ERROR is pending.
  76. * @stop_cmdr: Value to be loaded into CMDR when the stop command is
  77. * to be sent.
  78. * @tasklet: Tasklet running the request state machine.
  79. * @pending_events: Bitmask of events flagged by the interrupt handler
  80. * to be processed by the tasklet.
  81. * @completed_events: Bitmask of events which the state machine has
  82. * processed.
  83. * @state: Tasklet state.
  84. * @queue: List of slots waiting for access to the controller.
  85. * @need_clock_update: Update the clock rate before the next request.
  86. * @need_reset: Reset controller before next request.
  87. * @mode_reg: Value of the MR register.
  88. * @cfg_reg: Value of the CFG register.
  89. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
  90. * rate and timeout calculations.
  91. * @mapbase: Physical address of the MMIO registers.
  92. * @mck: The peripheral bus clock hooked up to the MMC controller.
  93. * @pdev: Platform device associated with the MMC controller.
  94. * @slot: Slots sharing this MMC controller.
  95. *
  96. * Locking
  97. * =======
  98. *
  99. * @lock is a softirq-safe spinlock protecting @queue as well as
  100. * @cur_slot, @mrq and @state. These must always be updated
  101. * at the same time while holding @lock.
  102. *
  103. * @lock also protects mode_reg and need_clock_update since these are
  104. * used to synchronize mode register updates with the queue
  105. * processing.
  106. *
  107. * The @mrq field of struct atmel_mci_slot is also protected by @lock,
  108. * and must always be written at the same time as the slot is added to
  109. * @queue.
  110. *
  111. * @pending_events and @completed_events are accessed using atomic bit
  112. * operations, so they don't need any locking.
  113. *
  114. * None of the fields touched by the interrupt handler need any
  115. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  116. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  117. * interrupts must be disabled and @data_status updated with a
  118. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  119. * CMDRDY interupt must be disabled and @cmd_status updated with a
  120. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  121. * bytes_xfered field of @data must be written. This is ensured by
  122. * using barriers.
  123. */
  124. struct atmel_mci {
  125. spinlock_t lock;
  126. void __iomem *regs;
  127. struct scatterlist *sg;
  128. unsigned int pio_offset;
  129. struct atmel_mci_slot *cur_slot;
  130. struct mmc_request *mrq;
  131. struct mmc_command *cmd;
  132. struct mmc_data *data;
  133. struct atmel_mci_dma dma;
  134. struct dma_chan *data_chan;
  135. u32 cmd_status;
  136. u32 data_status;
  137. u32 stop_cmdr;
  138. struct tasklet_struct tasklet;
  139. unsigned long pending_events;
  140. unsigned long completed_events;
  141. enum atmel_mci_state state;
  142. struct list_head queue;
  143. bool need_clock_update;
  144. bool need_reset;
  145. u32 mode_reg;
  146. u32 cfg_reg;
  147. unsigned long bus_hz;
  148. unsigned long mapbase;
  149. struct clk *mck;
  150. struct platform_device *pdev;
  151. struct atmel_mci_slot *slot[ATMEL_MCI_MAX_NR_SLOTS];
  152. };
  153. /**
  154. * struct atmel_mci_slot - MMC slot state
  155. * @mmc: The mmc_host representing this slot.
  156. * @host: The MMC controller this slot is using.
  157. * @sdc_reg: Value of SDCR to be written before using this slot.
  158. * @sdio_irq: SDIO irq mask for this slot.
  159. * @mrq: mmc_request currently being processed or waiting to be
  160. * processed, or NULL when the slot is idle.
  161. * @queue_node: List node for placing this node in the @queue list of
  162. * &struct atmel_mci.
  163. * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  164. * @flags: Random state bits associated with the slot.
  165. * @detect_pin: GPIO pin used for card detection, or negative if not
  166. * available.
  167. * @wp_pin: GPIO pin used for card write protect sending, or negative
  168. * if not available.
  169. * @detect_is_active_high: The state of the detect pin when it is active.
  170. * @detect_timer: Timer used for debouncing @detect_pin interrupts.
  171. */
  172. struct atmel_mci_slot {
  173. struct mmc_host *mmc;
  174. struct atmel_mci *host;
  175. u32 sdc_reg;
  176. u32 sdio_irq;
  177. struct mmc_request *mrq;
  178. struct list_head queue_node;
  179. unsigned int clock;
  180. unsigned long flags;
  181. #define ATMCI_CARD_PRESENT 0
  182. #define ATMCI_CARD_NEED_INIT 1
  183. #define ATMCI_SHUTDOWN 2
  184. int detect_pin;
  185. int wp_pin;
  186. bool detect_is_active_high;
  187. struct timer_list detect_timer;
  188. };
  189. #define atmci_test_and_clear_pending(host, event) \
  190. test_and_clear_bit(event, &host->pending_events)
  191. #define atmci_set_completed(host, event) \
  192. set_bit(event, &host->completed_events)
  193. #define atmci_set_pending(host, event) \
  194. set_bit(event, &host->pending_events)
  195. /*
  196. * Enable or disable features/registers based on
  197. * whether the processor supports them
  198. */
  199. static bool mci_has_rwproof(void)
  200. {
  201. if (cpu_is_at91sam9261() || cpu_is_at91rm9200())
  202. return false;
  203. else
  204. return true;
  205. }
  206. /*
  207. * The new MCI2 module isn't 100% compatible with the old MCI module,
  208. * and it has a few nice features which we want to use...
  209. */
  210. static inline bool atmci_is_mci2(void)
  211. {
  212. if (cpu_is_at91sam9g45())
  213. return true;
  214. return false;
  215. }
  216. /*
  217. * The debugfs stuff below is mostly optimized away when
  218. * CONFIG_DEBUG_FS is not set.
  219. */
  220. static int atmci_req_show(struct seq_file *s, void *v)
  221. {
  222. struct atmel_mci_slot *slot = s->private;
  223. struct mmc_request *mrq;
  224. struct mmc_command *cmd;
  225. struct mmc_command *stop;
  226. struct mmc_data *data;
  227. /* Make sure we get a consistent snapshot */
  228. spin_lock_bh(&slot->host->lock);
  229. mrq = slot->mrq;
  230. if (mrq) {
  231. cmd = mrq->cmd;
  232. data = mrq->data;
  233. stop = mrq->stop;
  234. if (cmd)
  235. seq_printf(s,
  236. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  237. cmd->opcode, cmd->arg, cmd->flags,
  238. cmd->resp[0], cmd->resp[1], cmd->resp[2],
  239. cmd->resp[3], cmd->error);
  240. if (data)
  241. seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
  242. data->bytes_xfered, data->blocks,
  243. data->blksz, data->flags, data->error);
  244. if (stop)
  245. seq_printf(s,
  246. "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
  247. stop->opcode, stop->arg, stop->flags,
  248. stop->resp[0], stop->resp[1], stop->resp[2],
  249. stop->resp[3], stop->error);
  250. }
  251. spin_unlock_bh(&slot->host->lock);
  252. return 0;
  253. }
  254. static int atmci_req_open(struct inode *inode, struct file *file)
  255. {
  256. return single_open(file, atmci_req_show, inode->i_private);
  257. }
  258. static const struct file_operations atmci_req_fops = {
  259. .owner = THIS_MODULE,
  260. .open = atmci_req_open,
  261. .read = seq_read,
  262. .llseek = seq_lseek,
  263. .release = single_release,
  264. };
  265. static void atmci_show_status_reg(struct seq_file *s,
  266. const char *regname, u32 value)
  267. {
  268. static const char *sr_bit[] = {
  269. [0] = "CMDRDY",
  270. [1] = "RXRDY",
  271. [2] = "TXRDY",
  272. [3] = "BLKE",
  273. [4] = "DTIP",
  274. [5] = "NOTBUSY",
  275. [6] = "ENDRX",
  276. [7] = "ENDTX",
  277. [8] = "SDIOIRQA",
  278. [9] = "SDIOIRQB",
  279. [12] = "SDIOWAIT",
  280. [14] = "RXBUFF",
  281. [15] = "TXBUFE",
  282. [16] = "RINDE",
  283. [17] = "RDIRE",
  284. [18] = "RCRCE",
  285. [19] = "RENDE",
  286. [20] = "RTOE",
  287. [21] = "DCRCE",
  288. [22] = "DTOE",
  289. [23] = "CSTOE",
  290. [24] = "BLKOVRE",
  291. [25] = "DMADONE",
  292. [26] = "FIFOEMPTY",
  293. [27] = "XFRDONE",
  294. [30] = "OVRE",
  295. [31] = "UNRE",
  296. };
  297. unsigned int i;
  298. seq_printf(s, "%s:\t0x%08x", regname, value);
  299. for (i = 0; i < ARRAY_SIZE(sr_bit); i++) {
  300. if (value & (1 << i)) {
  301. if (sr_bit[i])
  302. seq_printf(s, " %s", sr_bit[i]);
  303. else
  304. seq_puts(s, " UNKNOWN");
  305. }
  306. }
  307. seq_putc(s, '\n');
  308. }
  309. static int atmci_regs_show(struct seq_file *s, void *v)
  310. {
  311. struct atmel_mci *host = s->private;
  312. u32 *buf;
  313. buf = kmalloc(MCI_REGS_SIZE, GFP_KERNEL);
  314. if (!buf)
  315. return -ENOMEM;
  316. /*
  317. * Grab a more or less consistent snapshot. Note that we're
  318. * not disabling interrupts, so IMR and SR may not be
  319. * consistent.
  320. */
  321. spin_lock_bh(&host->lock);
  322. clk_enable(host->mck);
  323. memcpy_fromio(buf, host->regs, MCI_REGS_SIZE);
  324. clk_disable(host->mck);
  325. spin_unlock_bh(&host->lock);
  326. seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n",
  327. buf[MCI_MR / 4],
  328. buf[MCI_MR / 4] & MCI_MR_RDPROOF ? " RDPROOF" : "",
  329. buf[MCI_MR / 4] & MCI_MR_WRPROOF ? " WRPROOF" : "",
  330. buf[MCI_MR / 4] & 0xff);
  331. seq_printf(s, "DTOR:\t0x%08x\n", buf[MCI_DTOR / 4]);
  332. seq_printf(s, "SDCR:\t0x%08x\n", buf[MCI_SDCR / 4]);
  333. seq_printf(s, "ARGR:\t0x%08x\n", buf[MCI_ARGR / 4]);
  334. seq_printf(s, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u\n",
  335. buf[MCI_BLKR / 4],
  336. buf[MCI_BLKR / 4] & 0xffff,
  337. (buf[MCI_BLKR / 4] >> 16) & 0xffff);
  338. if (atmci_is_mci2())
  339. seq_printf(s, "CSTOR:\t0x%08x\n", buf[MCI_CSTOR / 4]);
  340. /* Don't read RSPR and RDR; it will consume the data there */
  341. atmci_show_status_reg(s, "SR", buf[MCI_SR / 4]);
  342. atmci_show_status_reg(s, "IMR", buf[MCI_IMR / 4]);
  343. if (atmci_is_mci2()) {
  344. u32 val;
  345. val = buf[MCI_DMA / 4];
  346. seq_printf(s, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s\n",
  347. val, val & 3,
  348. ((val >> 4) & 3) ?
  349. 1 << (((val >> 4) & 3) + 1) : 1,
  350. val & MCI_DMAEN ? " DMAEN" : "");
  351. val = buf[MCI_CFG / 4];
  352. seq_printf(s, "CFG:\t0x%08x%s%s%s%s\n",
  353. val,
  354. val & MCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "",
  355. val & MCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "",
  356. val & MCI_CFG_HSMODE ? " HSMODE" : "",
  357. val & MCI_CFG_LSYNC ? " LSYNC" : "");
  358. }
  359. kfree(buf);
  360. return 0;
  361. }
  362. static int atmci_regs_open(struct inode *inode, struct file *file)
  363. {
  364. return single_open(file, atmci_regs_show, inode->i_private);
  365. }
  366. static const struct file_operations atmci_regs_fops = {
  367. .owner = THIS_MODULE,
  368. .open = atmci_regs_open,
  369. .read = seq_read,
  370. .llseek = seq_lseek,
  371. .release = single_release,
  372. };
  373. static void atmci_init_debugfs(struct atmel_mci_slot *slot)
  374. {
  375. struct mmc_host *mmc = slot->mmc;
  376. struct atmel_mci *host = slot->host;
  377. struct dentry *root;
  378. struct dentry *node;
  379. root = mmc->debugfs_root;
  380. if (!root)
  381. return;
  382. node = debugfs_create_file("regs", S_IRUSR, root, host,
  383. &atmci_regs_fops);
  384. if (IS_ERR(node))
  385. return;
  386. if (!node)
  387. goto err;
  388. node = debugfs_create_file("req", S_IRUSR, root, slot, &atmci_req_fops);
  389. if (!node)
  390. goto err;
  391. node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
  392. if (!node)
  393. goto err;
  394. node = debugfs_create_x32("pending_events", S_IRUSR, root,
  395. (u32 *)&host->pending_events);
  396. if (!node)
  397. goto err;
  398. node = debugfs_create_x32("completed_events", S_IRUSR, root,
  399. (u32 *)&host->completed_events);
  400. if (!node)
  401. goto err;
  402. return;
  403. err:
  404. dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
  405. }
  406. static inline unsigned int ns_to_clocks(struct atmel_mci *host,
  407. unsigned int ns)
  408. {
  409. return (ns * (host->bus_hz / 1000000) + 999) / 1000;
  410. }
  411. static void atmci_set_timeout(struct atmel_mci *host,
  412. struct atmel_mci_slot *slot, struct mmc_data *data)
  413. {
  414. static unsigned dtomul_to_shift[] = {
  415. 0, 4, 7, 8, 10, 12, 16, 20
  416. };
  417. unsigned timeout;
  418. unsigned dtocyc;
  419. unsigned dtomul;
  420. timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks;
  421. for (dtomul = 0; dtomul < 8; dtomul++) {
  422. unsigned shift = dtomul_to_shift[dtomul];
  423. dtocyc = (timeout + (1 << shift) - 1) >> shift;
  424. if (dtocyc < 15)
  425. break;
  426. }
  427. if (dtomul >= 8) {
  428. dtomul = 7;
  429. dtocyc = 15;
  430. }
  431. dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n",
  432. dtocyc << dtomul_to_shift[dtomul]);
  433. mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc)));
  434. }
  435. /*
  436. * Return mask with command flags to be enabled for this command.
  437. */
  438. static u32 atmci_prepare_command(struct mmc_host *mmc,
  439. struct mmc_command *cmd)
  440. {
  441. struct mmc_data *data;
  442. u32 cmdr;
  443. cmd->error = -EINPROGRESS;
  444. cmdr = MCI_CMDR_CMDNB(cmd->opcode);
  445. if (cmd->flags & MMC_RSP_PRESENT) {
  446. if (cmd->flags & MMC_RSP_136)
  447. cmdr |= MCI_CMDR_RSPTYP_136BIT;
  448. else
  449. cmdr |= MCI_CMDR_RSPTYP_48BIT;
  450. }
  451. /*
  452. * This should really be MAXLAT_5 for CMD2 and ACMD41, but
  453. * it's too difficult to determine whether this is an ACMD or
  454. * not. Better make it 64.
  455. */
  456. cmdr |= MCI_CMDR_MAXLAT_64CYC;
  457. if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
  458. cmdr |= MCI_CMDR_OPDCMD;
  459. data = cmd->data;
  460. if (data) {
  461. cmdr |= MCI_CMDR_START_XFER;
  462. if (data->flags & MMC_DATA_STREAM)
  463. cmdr |= MCI_CMDR_STREAM;
  464. else if (data->blocks > 1)
  465. cmdr |= MCI_CMDR_MULTI_BLOCK;
  466. else
  467. cmdr |= MCI_CMDR_BLOCK;
  468. if (data->flags & MMC_DATA_READ)
  469. cmdr |= MCI_CMDR_TRDIR_READ;
  470. }
  471. return cmdr;
  472. }
  473. static void atmci_start_command(struct atmel_mci *host,
  474. struct mmc_command *cmd, u32 cmd_flags)
  475. {
  476. WARN_ON(host->cmd);
  477. host->cmd = cmd;
  478. dev_vdbg(&host->pdev->dev,
  479. "start command: ARGR=0x%08x CMDR=0x%08x\n",
  480. cmd->arg, cmd_flags);
  481. mci_writel(host, ARGR, cmd->arg);
  482. mci_writel(host, CMDR, cmd_flags);
  483. }
  484. static void send_stop_cmd(struct atmel_mci *host, struct mmc_data *data)
  485. {
  486. atmci_start_command(host, data->stop, host->stop_cmdr);
  487. mci_writel(host, IER, MCI_CMDRDY);
  488. }
  489. #ifdef CONFIG_MMC_ATMELMCI_DMA
  490. static void atmci_dma_cleanup(struct atmel_mci *host)
  491. {
  492. struct mmc_data *data = host->data;
  493. if (data)
  494. dma_unmap_sg(&host->pdev->dev, data->sg, data->sg_len,
  495. ((data->flags & MMC_DATA_WRITE)
  496. ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
  497. }
  498. static void atmci_stop_dma(struct atmel_mci *host)
  499. {
  500. struct dma_chan *chan = host->data_chan;
  501. if (chan) {
  502. chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
  503. atmci_dma_cleanup(host);
  504. } else {
  505. /* Data transfer was stopped by the interrupt handler */
  506. atmci_set_pending(host, EVENT_XFER_COMPLETE);
  507. mci_writel(host, IER, MCI_NOTBUSY);
  508. }
  509. }
  510. /* This function is called by the DMA driver from tasklet context. */
  511. static void atmci_dma_complete(void *arg)
  512. {
  513. struct atmel_mci *host = arg;
  514. struct mmc_data *data = host->data;
  515. dev_vdbg(&host->pdev->dev, "DMA complete\n");
  516. if (atmci_is_mci2())
  517. /* Disable DMA hardware handshaking on MCI */
  518. mci_writel(host, DMA, mci_readl(host, DMA) & ~MCI_DMAEN);
  519. atmci_dma_cleanup(host);
  520. /*
  521. * If the card was removed, data will be NULL. No point trying
  522. * to send the stop command or waiting for NBUSY in this case.
  523. */
  524. if (data) {
  525. atmci_set_pending(host, EVENT_XFER_COMPLETE);
  526. tasklet_schedule(&host->tasklet);
  527. /*
  528. * Regardless of what the documentation says, we have
  529. * to wait for NOTBUSY even after block read
  530. * operations.
  531. *
  532. * When the DMA transfer is complete, the controller
  533. * may still be reading the CRC from the card, i.e.
  534. * the data transfer is still in progress and we
  535. * haven't seen all the potential error bits yet.
  536. *
  537. * The interrupt handler will schedule a different
  538. * tasklet to finish things up when the data transfer
  539. * is completely done.
  540. *
  541. * We may not complete the mmc request here anyway
  542. * because the mmc layer may call back and cause us to
  543. * violate the "don't submit new operations from the
  544. * completion callback" rule of the dma engine
  545. * framework.
  546. */
  547. mci_writel(host, IER, MCI_NOTBUSY);
  548. }
  549. }
  550. static int
  551. atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
  552. {
  553. struct dma_chan *chan;
  554. struct dma_async_tx_descriptor *desc;
  555. struct scatterlist *sg;
  556. unsigned int i;
  557. enum dma_data_direction direction;
  558. unsigned int sglen;
  559. /*
  560. * We don't do DMA on "complex" transfers, i.e. with
  561. * non-word-aligned buffers or lengths. Also, we don't bother
  562. * with all the DMA setup overhead for short transfers.
  563. */
  564. if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD)
  565. return -EINVAL;
  566. if (data->blksz & 3)
  567. return -EINVAL;
  568. for_each_sg(data->sg, sg, data->sg_len, i) {
  569. if (sg->offset & 3 || sg->length & 3)
  570. return -EINVAL;
  571. }
  572. /* If we don't have a channel, we can't do DMA */
  573. chan = host->dma.chan;
  574. if (chan)
  575. host->data_chan = chan;
  576. if (!chan)
  577. return -ENODEV;
  578. if (atmci_is_mci2())
  579. mci_writel(host, DMA, MCI_DMA_CHKSIZE(3) | MCI_DMAEN);
  580. if (data->flags & MMC_DATA_READ)
  581. direction = DMA_FROM_DEVICE;
  582. else
  583. direction = DMA_TO_DEVICE;
  584. sglen = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, direction);
  585. if (sglen != data->sg_len)
  586. goto unmap_exit;
  587. desc = chan->device->device_prep_slave_sg(chan,
  588. data->sg, data->sg_len, direction,
  589. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  590. if (!desc)
  591. goto unmap_exit;
  592. host->dma.data_desc = desc;
  593. desc->callback = atmci_dma_complete;
  594. desc->callback_param = host;
  595. return 0;
  596. unmap_exit:
  597. dma_unmap_sg(&host->pdev->dev, data->sg, sglen, direction);
  598. return -ENOMEM;
  599. }
  600. static void atmci_submit_data(struct atmel_mci *host)
  601. {
  602. struct dma_chan *chan = host->data_chan;
  603. struct dma_async_tx_descriptor *desc = host->dma.data_desc;
  604. if (chan) {
  605. desc->tx_submit(desc);
  606. chan->device->device_issue_pending(chan);
  607. }
  608. }
  609. #else /* CONFIG_MMC_ATMELMCI_DMA */
  610. static int atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
  611. {
  612. return -ENOSYS;
  613. }
  614. static void atmci_submit_data(struct atmel_mci *host) {}
  615. static void atmci_stop_dma(struct atmel_mci *host)
  616. {
  617. /* Data transfer was stopped by the interrupt handler */
  618. atmci_set_pending(host, EVENT_XFER_COMPLETE);
  619. mci_writel(host, IER, MCI_NOTBUSY);
  620. }
  621. #endif /* CONFIG_MMC_ATMELMCI_DMA */
  622. /*
  623. * Returns a mask of interrupt flags to be enabled after the whole
  624. * request has been prepared.
  625. */
  626. static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data)
  627. {
  628. u32 iflags;
  629. data->error = -EINPROGRESS;
  630. WARN_ON(host->data);
  631. host->sg = NULL;
  632. host->data = data;
  633. iflags = ATMCI_DATA_ERROR_FLAGS;
  634. if (atmci_prepare_data_dma(host, data)) {
  635. host->data_chan = NULL;
  636. /*
  637. * Errata: MMC data write operation with less than 12
  638. * bytes is impossible.
  639. *
  640. * Errata: MCI Transmit Data Register (TDR) FIFO
  641. * corruption when length is not multiple of 4.
  642. */
  643. if (data->blocks * data->blksz < 12
  644. || (data->blocks * data->blksz) & 3)
  645. host->need_reset = true;
  646. host->sg = data->sg;
  647. host->pio_offset = 0;
  648. if (data->flags & MMC_DATA_READ)
  649. iflags |= MCI_RXRDY;
  650. else
  651. iflags |= MCI_TXRDY;
  652. }
  653. return iflags;
  654. }
  655. static void atmci_start_request(struct atmel_mci *host,
  656. struct atmel_mci_slot *slot)
  657. {
  658. struct mmc_request *mrq;
  659. struct mmc_command *cmd;
  660. struct mmc_data *data;
  661. u32 iflags;
  662. u32 cmdflags;
  663. mrq = slot->mrq;
  664. host->cur_slot = slot;
  665. host->mrq = mrq;
  666. host->pending_events = 0;
  667. host->completed_events = 0;
  668. host->data_status = 0;
  669. if (host->need_reset) {
  670. mci_writel(host, CR, MCI_CR_SWRST);
  671. mci_writel(host, CR, MCI_CR_MCIEN);
  672. mci_writel(host, MR, host->mode_reg);
  673. if (atmci_is_mci2())
  674. mci_writel(host, CFG, host->cfg_reg);
  675. host->need_reset = false;
  676. }
  677. mci_writel(host, SDCR, slot->sdc_reg);
  678. iflags = mci_readl(host, IMR);
  679. if (iflags & ~(MCI_SDIOIRQA | MCI_SDIOIRQB))
  680. dev_warn(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n",
  681. iflags);
  682. if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) {
  683. /* Send init sequence (74 clock cycles) */
  684. mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT);
  685. while (!(mci_readl(host, SR) & MCI_CMDRDY))
  686. cpu_relax();
  687. }
  688. iflags = 0;
  689. data = mrq->data;
  690. if (data) {
  691. atmci_set_timeout(host, slot, data);
  692. /* Must set block count/size before sending command */
  693. mci_writel(host, BLKR, MCI_BCNT(data->blocks)
  694. | MCI_BLKLEN(data->blksz));
  695. dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n",
  696. MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz));
  697. iflags |= atmci_prepare_data(host, data);
  698. }
  699. iflags |= MCI_CMDRDY;
  700. cmd = mrq->cmd;
  701. cmdflags = atmci_prepare_command(slot->mmc, cmd);
  702. atmci_start_command(host, cmd, cmdflags);
  703. if (data)
  704. atmci_submit_data(host);
  705. if (mrq->stop) {
  706. host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop);
  707. host->stop_cmdr |= MCI_CMDR_STOP_XFER;
  708. if (!(data->flags & MMC_DATA_WRITE))
  709. host->stop_cmdr |= MCI_CMDR_TRDIR_READ;
  710. if (data->flags & MMC_DATA_STREAM)
  711. host->stop_cmdr |= MCI_CMDR_STREAM;
  712. else
  713. host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK;
  714. }
  715. /*
  716. * We could have enabled interrupts earlier, but I suspect
  717. * that would open up a nice can of interesting race
  718. * conditions (e.g. command and data complete, but stop not
  719. * prepared yet.)
  720. */
  721. mci_writel(host, IER, iflags);
  722. }
  723. static void atmci_queue_request(struct atmel_mci *host,
  724. struct atmel_mci_slot *slot, struct mmc_request *mrq)
  725. {
  726. dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
  727. host->state);
  728. spin_lock_bh(&host->lock);
  729. slot->mrq = mrq;
  730. if (host->state == STATE_IDLE) {
  731. host->state = STATE_SENDING_CMD;
  732. atmci_start_request(host, slot);
  733. } else {
  734. list_add_tail(&slot->queue_node, &host->queue);
  735. }
  736. spin_unlock_bh(&host->lock);
  737. }
  738. static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  739. {
  740. struct atmel_mci_slot *slot = mmc_priv(mmc);
  741. struct atmel_mci *host = slot->host;
  742. struct mmc_data *data;
  743. WARN_ON(slot->mrq);
  744. /*
  745. * We may "know" the card is gone even though there's still an
  746. * electrical connection. If so, we really need to communicate
  747. * this to the MMC core since there won't be any more
  748. * interrupts as the card is completely removed. Otherwise,
  749. * the MMC core might believe the card is still there even
  750. * though the card was just removed very slowly.
  751. */
  752. if (!test_bit(ATMCI_CARD_PRESENT, &slot->flags)) {
  753. mrq->cmd->error = -ENOMEDIUM;
  754. mmc_request_done(mmc, mrq);
  755. return;
  756. }
  757. /* We don't support multiple blocks of weird lengths. */
  758. data = mrq->data;
  759. if (data && data->blocks > 1 && data->blksz & 3) {
  760. mrq->cmd->error = -EINVAL;
  761. mmc_request_done(mmc, mrq);
  762. }
  763. atmci_queue_request(host, slot, mrq);
  764. }
  765. static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  766. {
  767. struct atmel_mci_slot *slot = mmc_priv(mmc);
  768. struct atmel_mci *host = slot->host;
  769. unsigned int i;
  770. slot->sdc_reg &= ~MCI_SDCBUS_MASK;
  771. switch (ios->bus_width) {
  772. case MMC_BUS_WIDTH_1:
  773. slot->sdc_reg |= MCI_SDCBUS_1BIT;
  774. break;
  775. case MMC_BUS_WIDTH_4:
  776. slot->sdc_reg |= MCI_SDCBUS_4BIT;
  777. break;
  778. }
  779. if (ios->clock) {
  780. unsigned int clock_min = ~0U;
  781. u32 clkdiv;
  782. spin_lock_bh(&host->lock);
  783. if (!host->mode_reg) {
  784. clk_enable(host->mck);
  785. mci_writel(host, CR, MCI_CR_SWRST);
  786. mci_writel(host, CR, MCI_CR_MCIEN);
  787. if (atmci_is_mci2())
  788. mci_writel(host, CFG, host->cfg_reg);
  789. }
  790. /*
  791. * Use mirror of ios->clock to prevent race with mmc
  792. * core ios update when finding the minimum.
  793. */
  794. slot->clock = ios->clock;
  795. for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
  796. if (host->slot[i] && host->slot[i]->clock
  797. && host->slot[i]->clock < clock_min)
  798. clock_min = host->slot[i]->clock;
  799. }
  800. /* Calculate clock divider */
  801. clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1;
  802. if (clkdiv > 255) {
  803. dev_warn(&mmc->class_dev,
  804. "clock %u too slow; using %lu\n",
  805. clock_min, host->bus_hz / (2 * 256));
  806. clkdiv = 255;
  807. }
  808. host->mode_reg = MCI_MR_CLKDIV(clkdiv);
  809. /*
  810. * WRPROOF and RDPROOF prevent overruns/underruns by
  811. * stopping the clock when the FIFO is full/empty.
  812. * This state is not expected to last for long.
  813. */
  814. if (mci_has_rwproof())
  815. host->mode_reg |= (MCI_MR_WRPROOF | MCI_MR_RDPROOF);
  816. if (atmci_is_mci2()) {
  817. /* setup High Speed mode in relation with card capacity */
  818. if (ios->timing == MMC_TIMING_SD_HS)
  819. host->cfg_reg |= MCI_CFG_HSMODE;
  820. else
  821. host->cfg_reg &= ~MCI_CFG_HSMODE;
  822. }
  823. if (list_empty(&host->queue)) {
  824. mci_writel(host, MR, host->mode_reg);
  825. if (atmci_is_mci2())
  826. mci_writel(host, CFG, host->cfg_reg);
  827. } else {
  828. host->need_clock_update = true;
  829. }
  830. spin_unlock_bh(&host->lock);
  831. } else {
  832. bool any_slot_active = false;
  833. spin_lock_bh(&host->lock);
  834. slot->clock = 0;
  835. for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
  836. if (host->slot[i] && host->slot[i]->clock) {
  837. any_slot_active = true;
  838. break;
  839. }
  840. }
  841. if (!any_slot_active) {
  842. mci_writel(host, CR, MCI_CR_MCIDIS);
  843. if (host->mode_reg) {
  844. mci_readl(host, MR);
  845. clk_disable(host->mck);
  846. }
  847. host->mode_reg = 0;
  848. }
  849. spin_unlock_bh(&host->lock);
  850. }
  851. switch (ios->power_mode) {
  852. case MMC_POWER_UP:
  853. set_bit(ATMCI_CARD_NEED_INIT, &slot->flags);
  854. break;
  855. default:
  856. /*
  857. * TODO: None of the currently available AVR32-based
  858. * boards allow MMC power to be turned off. Implement
  859. * power control when this can be tested properly.
  860. *
  861. * We also need to hook this into the clock management
  862. * somehow so that newly inserted cards aren't
  863. * subjected to a fast clock before we have a chance
  864. * to figure out what the maximum rate is. Currently,
  865. * there's no way to avoid this, and there never will
  866. * be for boards that don't support power control.
  867. */
  868. break;
  869. }
  870. }
  871. static int atmci_get_ro(struct mmc_host *mmc)
  872. {
  873. int read_only = -ENOSYS;
  874. struct atmel_mci_slot *slot = mmc_priv(mmc);
  875. if (gpio_is_valid(slot->wp_pin)) {
  876. read_only = gpio_get_value(slot->wp_pin);
  877. dev_dbg(&mmc->class_dev, "card is %s\n",
  878. read_only ? "read-only" : "read-write");
  879. }
  880. return read_only;
  881. }
  882. static int atmci_get_cd(struct mmc_host *mmc)
  883. {
  884. int present = -ENOSYS;
  885. struct atmel_mci_slot *slot = mmc_priv(mmc);
  886. if (gpio_is_valid(slot->detect_pin)) {
  887. present = !(gpio_get_value(slot->detect_pin) ^
  888. slot->detect_is_active_high);
  889. dev_dbg(&mmc->class_dev, "card is %spresent\n",
  890. present ? "" : "not ");
  891. }
  892. return present;
  893. }
  894. static void atmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
  895. {
  896. struct atmel_mci_slot *slot = mmc_priv(mmc);
  897. struct atmel_mci *host = slot->host;
  898. if (enable)
  899. mci_writel(host, IER, slot->sdio_irq);
  900. else
  901. mci_writel(host, IDR, slot->sdio_irq);
  902. }
  903. static const struct mmc_host_ops atmci_ops = {
  904. .request = atmci_request,
  905. .set_ios = atmci_set_ios,
  906. .get_ro = atmci_get_ro,
  907. .get_cd = atmci_get_cd,
  908. .enable_sdio_irq = atmci_enable_sdio_irq,
  909. };
  910. /* Called with host->lock held */
  911. static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq)
  912. __releases(&host->lock)
  913. __acquires(&host->lock)
  914. {
  915. struct atmel_mci_slot *slot = NULL;
  916. struct mmc_host *prev_mmc = host->cur_slot->mmc;
  917. WARN_ON(host->cmd || host->data);
  918. /*
  919. * Update the MMC clock rate if necessary. This may be
  920. * necessary if set_ios() is called when a different slot is
  921. * busy transfering data.
  922. */
  923. if (host->need_clock_update) {
  924. mci_writel(host, MR, host->mode_reg);
  925. if (atmci_is_mci2())
  926. mci_writel(host, CFG, host->cfg_reg);
  927. }
  928. host->cur_slot->mrq = NULL;
  929. host->mrq = NULL;
  930. if (!list_empty(&host->queue)) {
  931. slot = list_entry(host->queue.next,
  932. struct atmel_mci_slot, queue_node);
  933. list_del(&slot->queue_node);
  934. dev_vdbg(&host->pdev->dev, "list not empty: %s is next\n",
  935. mmc_hostname(slot->mmc));
  936. host->state = STATE_SENDING_CMD;
  937. atmci_start_request(host, slot);
  938. } else {
  939. dev_vdbg(&host->pdev->dev, "list empty\n");
  940. host->state = STATE_IDLE;
  941. }
  942. spin_unlock(&host->lock);
  943. mmc_request_done(prev_mmc, mrq);
  944. spin_lock(&host->lock);
  945. }
  946. static void atmci_command_complete(struct atmel_mci *host,
  947. struct mmc_command *cmd)
  948. {
  949. u32 status = host->cmd_status;
  950. /* Read the response from the card (up to 16 bytes) */
  951. cmd->resp[0] = mci_readl(host, RSPR);
  952. cmd->resp[1] = mci_readl(host, RSPR);
  953. cmd->resp[2] = mci_readl(host, RSPR);
  954. cmd->resp[3] = mci_readl(host, RSPR);
  955. if (status & MCI_RTOE)
  956. cmd->error = -ETIMEDOUT;
  957. else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE))
  958. cmd->error = -EILSEQ;
  959. else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE))
  960. cmd->error = -EIO;
  961. else
  962. cmd->error = 0;
  963. if (cmd->error) {
  964. dev_dbg(&host->pdev->dev,
  965. "command error: status=0x%08x\n", status);
  966. if (cmd->data) {
  967. atmci_stop_dma(host);
  968. host->data = NULL;
  969. mci_writel(host, IDR, MCI_NOTBUSY
  970. | MCI_TXRDY | MCI_RXRDY
  971. | ATMCI_DATA_ERROR_FLAGS);
  972. }
  973. }
  974. }
  975. static void atmci_detect_change(unsigned long data)
  976. {
  977. struct atmel_mci_slot *slot = (struct atmel_mci_slot *)data;
  978. bool present;
  979. bool present_old;
  980. /*
  981. * atmci_cleanup_slot() sets the ATMCI_SHUTDOWN flag before
  982. * freeing the interrupt. We must not re-enable the interrupt
  983. * if it has been freed, and if we're shutting down, it
  984. * doesn't really matter whether the card is present or not.
  985. */
  986. smp_rmb();
  987. if (test_bit(ATMCI_SHUTDOWN, &slot->flags))
  988. return;
  989. enable_irq(gpio_to_irq(slot->detect_pin));
  990. present = !(gpio_get_value(slot->detect_pin) ^
  991. slot->detect_is_active_high);
  992. present_old = test_bit(ATMCI_CARD_PRESENT, &slot->flags);
  993. dev_vdbg(&slot->mmc->class_dev, "detect change: %d (was %d)\n",
  994. present, present_old);
  995. if (present != present_old) {
  996. struct atmel_mci *host = slot->host;
  997. struct mmc_request *mrq;
  998. dev_dbg(&slot->mmc->class_dev, "card %s\n",
  999. present ? "inserted" : "removed");
  1000. spin_lock(&host->lock);
  1001. if (!present)
  1002. clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
  1003. else
  1004. set_bit(ATMCI_CARD_PRESENT, &slot->flags);
  1005. /* Clean up queue if present */
  1006. mrq = slot->mrq;
  1007. if (mrq) {
  1008. if (mrq == host->mrq) {
  1009. /*
  1010. * Reset controller to terminate any ongoing
  1011. * commands or data transfers.
  1012. */
  1013. mci_writel(host, CR, MCI_CR_SWRST);
  1014. mci_writel(host, CR, MCI_CR_MCIEN);
  1015. mci_writel(host, MR, host->mode_reg);
  1016. if (atmci_is_mci2())
  1017. mci_writel(host, CFG, host->cfg_reg);
  1018. host->data = NULL;
  1019. host->cmd = NULL;
  1020. switch (host->state) {
  1021. case STATE_IDLE:
  1022. break;
  1023. case STATE_SENDING_CMD:
  1024. mrq->cmd->error = -ENOMEDIUM;
  1025. if (!mrq->data)
  1026. break;
  1027. /* fall through */
  1028. case STATE_SENDING_DATA:
  1029. mrq->data->error = -ENOMEDIUM;
  1030. atmci_stop_dma(host);
  1031. break;
  1032. case STATE_DATA_BUSY:
  1033. case STATE_DATA_ERROR:
  1034. if (mrq->data->error == -EINPROGRESS)
  1035. mrq->data->error = -ENOMEDIUM;
  1036. if (!mrq->stop)
  1037. break;
  1038. /* fall through */
  1039. case STATE_SENDING_STOP:
  1040. mrq->stop->error = -ENOMEDIUM;
  1041. break;
  1042. }
  1043. atmci_request_end(host, mrq);
  1044. } else {
  1045. list_del(&slot->queue_node);
  1046. mrq->cmd->error = -ENOMEDIUM;
  1047. if (mrq->data)
  1048. mrq->data->error = -ENOMEDIUM;
  1049. if (mrq->stop)
  1050. mrq->stop->error = -ENOMEDIUM;
  1051. spin_unlock(&host->lock);
  1052. mmc_request_done(slot->mmc, mrq);
  1053. spin_lock(&host->lock);
  1054. }
  1055. }
  1056. spin_unlock(&host->lock);
  1057. mmc_detect_change(slot->mmc, 0);
  1058. }
  1059. }
  1060. static void atmci_tasklet_func(unsigned long priv)
  1061. {
  1062. struct atmel_mci *host = (struct atmel_mci *)priv;
  1063. struct mmc_request *mrq = host->mrq;
  1064. struct mmc_data *data = host->data;
  1065. struct mmc_command *cmd = host->cmd;
  1066. enum atmel_mci_state state = host->state;
  1067. enum atmel_mci_state prev_state;
  1068. u32 status;
  1069. spin_lock(&host->lock);
  1070. state = host->state;
  1071. dev_vdbg(&host->pdev->dev,
  1072. "tasklet: state %u pending/completed/mask %lx/%lx/%x\n",
  1073. state, host->pending_events, host->completed_events,
  1074. mci_readl(host, IMR));
  1075. do {
  1076. prev_state = state;
  1077. switch (state) {
  1078. case STATE_IDLE:
  1079. break;
  1080. case STATE_SENDING_CMD:
  1081. if (!atmci_test_and_clear_pending(host,
  1082. EVENT_CMD_COMPLETE))
  1083. break;
  1084. host->cmd = NULL;
  1085. atmci_set_completed(host, EVENT_CMD_COMPLETE);
  1086. atmci_command_complete(host, mrq->cmd);
  1087. if (!mrq->data || cmd->error) {
  1088. atmci_request_end(host, host->mrq);
  1089. goto unlock;
  1090. }
  1091. prev_state = state = STATE_SENDING_DATA;
  1092. /* fall through */
  1093. case STATE_SENDING_DATA:
  1094. if (atmci_test_and_clear_pending(host,
  1095. EVENT_DATA_ERROR)) {
  1096. atmci_stop_dma(host);
  1097. if (data->stop)
  1098. send_stop_cmd(host, data);
  1099. state = STATE_DATA_ERROR;
  1100. break;
  1101. }
  1102. if (!atmci_test_and_clear_pending(host,
  1103. EVENT_XFER_COMPLETE))
  1104. break;
  1105. atmci_set_completed(host, EVENT_XFER_COMPLETE);
  1106. prev_state = state = STATE_DATA_BUSY;
  1107. /* fall through */
  1108. case STATE_DATA_BUSY:
  1109. if (!atmci_test_and_clear_pending(host,
  1110. EVENT_DATA_COMPLETE))
  1111. break;
  1112. host->data = NULL;
  1113. atmci_set_completed(host, EVENT_DATA_COMPLETE);
  1114. status = host->data_status;
  1115. if (unlikely(status & ATMCI_DATA_ERROR_FLAGS)) {
  1116. if (status & MCI_DTOE) {
  1117. dev_dbg(&host->pdev->dev,
  1118. "data timeout error\n");
  1119. data->error = -ETIMEDOUT;
  1120. } else if (status & MCI_DCRCE) {
  1121. dev_dbg(&host->pdev->dev,
  1122. "data CRC error\n");
  1123. data->error = -EILSEQ;
  1124. } else {
  1125. dev_dbg(&host->pdev->dev,
  1126. "data FIFO error (status=%08x)\n",
  1127. status);
  1128. data->error = -EIO;
  1129. }
  1130. } else {
  1131. data->bytes_xfered = data->blocks * data->blksz;
  1132. data->error = 0;
  1133. mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS);
  1134. }
  1135. if (!data->stop) {
  1136. atmci_request_end(host, host->mrq);
  1137. goto unlock;
  1138. }
  1139. prev_state = state = STATE_SENDING_STOP;
  1140. if (!data->error)
  1141. send_stop_cmd(host, data);
  1142. /* fall through */
  1143. case STATE_SENDING_STOP:
  1144. if (!atmci_test_and_clear_pending(host,
  1145. EVENT_CMD_COMPLETE))
  1146. break;
  1147. host->cmd = NULL;
  1148. atmci_command_complete(host, mrq->stop);
  1149. atmci_request_end(host, host->mrq);
  1150. goto unlock;
  1151. case STATE_DATA_ERROR:
  1152. if (!atmci_test_and_clear_pending(host,
  1153. EVENT_XFER_COMPLETE))
  1154. break;
  1155. state = STATE_DATA_BUSY;
  1156. break;
  1157. }
  1158. } while (state != prev_state);
  1159. host->state = state;
  1160. unlock:
  1161. spin_unlock(&host->lock);
  1162. }
  1163. static void atmci_read_data_pio(struct atmel_mci *host)
  1164. {
  1165. struct scatterlist *sg = host->sg;
  1166. void *buf = sg_virt(sg);
  1167. unsigned int offset = host->pio_offset;
  1168. struct mmc_data *data = host->data;
  1169. u32 value;
  1170. u32 status;
  1171. unsigned int nbytes = 0;
  1172. do {
  1173. value = mci_readl(host, RDR);
  1174. if (likely(offset + 4 <= sg->length)) {
  1175. put_unaligned(value, (u32 *)(buf + offset));
  1176. offset += 4;
  1177. nbytes += 4;
  1178. if (offset == sg->length) {
  1179. flush_dcache_page(sg_page(sg));
  1180. host->sg = sg = sg_next(sg);
  1181. if (!sg)
  1182. goto done;
  1183. offset = 0;
  1184. buf = sg_virt(sg);
  1185. }
  1186. } else {
  1187. unsigned int remaining = sg->length - offset;
  1188. memcpy(buf + offset, &value, remaining);
  1189. nbytes += remaining;
  1190. flush_dcache_page(sg_page(sg));
  1191. host->sg = sg = sg_next(sg);
  1192. if (!sg)
  1193. goto done;
  1194. offset = 4 - remaining;
  1195. buf = sg_virt(sg);
  1196. memcpy(buf, (u8 *)&value + remaining, offset);
  1197. nbytes += offset;
  1198. }
  1199. status = mci_readl(host, SR);
  1200. if (status & ATMCI_DATA_ERROR_FLAGS) {
  1201. mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY
  1202. | ATMCI_DATA_ERROR_FLAGS));
  1203. host->data_status = status;
  1204. data->bytes_xfered += nbytes;
  1205. smp_wmb();
  1206. atmci_set_pending(host, EVENT_DATA_ERROR);
  1207. tasklet_schedule(&host->tasklet);
  1208. return;
  1209. }
  1210. } while (status & MCI_RXRDY);
  1211. host->pio_offset = offset;
  1212. data->bytes_xfered += nbytes;
  1213. return;
  1214. done:
  1215. mci_writel(host, IDR, MCI_RXRDY);
  1216. mci_writel(host, IER, MCI_NOTBUSY);
  1217. data->bytes_xfered += nbytes;
  1218. smp_wmb();
  1219. atmci_set_pending(host, EVENT_XFER_COMPLETE);
  1220. }
  1221. static void atmci_write_data_pio(struct atmel_mci *host)
  1222. {
  1223. struct scatterlist *sg = host->sg;
  1224. void *buf = sg_virt(sg);
  1225. unsigned int offset = host->pio_offset;
  1226. struct mmc_data *data = host->data;
  1227. u32 value;
  1228. u32 status;
  1229. unsigned int nbytes = 0;
  1230. do {
  1231. if (likely(offset + 4 <= sg->length)) {
  1232. value = get_unaligned((u32 *)(buf + offset));
  1233. mci_writel(host, TDR, value);
  1234. offset += 4;
  1235. nbytes += 4;
  1236. if (offset == sg->length) {
  1237. host->sg = sg = sg_next(sg);
  1238. if (!sg)
  1239. goto done;
  1240. offset = 0;
  1241. buf = sg_virt(sg);
  1242. }
  1243. } else {
  1244. unsigned int remaining = sg->length - offset;
  1245. value = 0;
  1246. memcpy(&value, buf + offset, remaining);
  1247. nbytes += remaining;
  1248. host->sg = sg = sg_next(sg);
  1249. if (!sg) {
  1250. mci_writel(host, TDR, value);
  1251. goto done;
  1252. }
  1253. offset = 4 - remaining;
  1254. buf = sg_virt(sg);
  1255. memcpy((u8 *)&value + remaining, buf, offset);
  1256. mci_writel(host, TDR, value);
  1257. nbytes += offset;
  1258. }
  1259. status = mci_readl(host, SR);
  1260. if (status & ATMCI_DATA_ERROR_FLAGS) {
  1261. mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY
  1262. | ATMCI_DATA_ERROR_FLAGS));
  1263. host->data_status = status;
  1264. data->bytes_xfered += nbytes;
  1265. smp_wmb();
  1266. atmci_set_pending(host, EVENT_DATA_ERROR);
  1267. tasklet_schedule(&host->tasklet);
  1268. return;
  1269. }
  1270. } while (status & MCI_TXRDY);
  1271. host->pio_offset = offset;
  1272. data->bytes_xfered += nbytes;
  1273. return;
  1274. done:
  1275. mci_writel(host, IDR, MCI_TXRDY);
  1276. mci_writel(host, IER, MCI_NOTBUSY);
  1277. data->bytes_xfered += nbytes;
  1278. smp_wmb();
  1279. atmci_set_pending(host, EVENT_XFER_COMPLETE);
  1280. }
  1281. static void atmci_cmd_interrupt(struct atmel_mci *host, u32 status)
  1282. {
  1283. mci_writel(host, IDR, MCI_CMDRDY);
  1284. host->cmd_status = status;
  1285. smp_wmb();
  1286. atmci_set_pending(host, EVENT_CMD_COMPLETE);
  1287. tasklet_schedule(&host->tasklet);
  1288. }
  1289. static void atmci_sdio_interrupt(struct atmel_mci *host, u32 status)
  1290. {
  1291. int i;
  1292. for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
  1293. struct atmel_mci_slot *slot = host->slot[i];
  1294. if (slot && (status & slot->sdio_irq)) {
  1295. mmc_signal_sdio_irq(slot->mmc);
  1296. }
  1297. }
  1298. }
  1299. static irqreturn_t atmci_interrupt(int irq, void *dev_id)
  1300. {
  1301. struct atmel_mci *host = dev_id;
  1302. u32 status, mask, pending;
  1303. unsigned int pass_count = 0;
  1304. do {
  1305. status = mci_readl(host, SR);
  1306. mask = mci_readl(host, IMR);
  1307. pending = status & mask;
  1308. if (!pending)
  1309. break;
  1310. if (pending & ATMCI_DATA_ERROR_FLAGS) {
  1311. mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS
  1312. | MCI_RXRDY | MCI_TXRDY);
  1313. pending &= mci_readl(host, IMR);
  1314. host->data_status = status;
  1315. smp_wmb();
  1316. atmci_set_pending(host, EVENT_DATA_ERROR);
  1317. tasklet_schedule(&host->tasklet);
  1318. }
  1319. if (pending & MCI_NOTBUSY) {
  1320. mci_writel(host, IDR,
  1321. ATMCI_DATA_ERROR_FLAGS | MCI_NOTBUSY);
  1322. if (!host->data_status)
  1323. host->data_status = status;
  1324. smp_wmb();
  1325. atmci_set_pending(host, EVENT_DATA_COMPLETE);
  1326. tasklet_schedule(&host->tasklet);
  1327. }
  1328. if (pending & MCI_RXRDY)
  1329. atmci_read_data_pio(host);
  1330. if (pending & MCI_TXRDY)
  1331. atmci_write_data_pio(host);
  1332. if (pending & MCI_CMDRDY)
  1333. atmci_cmd_interrupt(host, status);
  1334. if (pending & (MCI_SDIOIRQA | MCI_SDIOIRQB))
  1335. atmci_sdio_interrupt(host, status);
  1336. } while (pass_count++ < 5);
  1337. return pass_count ? IRQ_HANDLED : IRQ_NONE;
  1338. }
  1339. static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id)
  1340. {
  1341. struct atmel_mci_slot *slot = dev_id;
  1342. /*
  1343. * Disable interrupts until the pin has stabilized and check
  1344. * the state then. Use mod_timer() since we may be in the
  1345. * middle of the timer routine when this interrupt triggers.
  1346. */
  1347. disable_irq_nosync(irq);
  1348. mod_timer(&slot->detect_timer, jiffies + msecs_to_jiffies(20));
  1349. return IRQ_HANDLED;
  1350. }
  1351. static int __init atmci_init_slot(struct atmel_mci *host,
  1352. struct mci_slot_pdata *slot_data, unsigned int id,
  1353. u32 sdc_reg, u32 sdio_irq)
  1354. {
  1355. struct mmc_host *mmc;
  1356. struct atmel_mci_slot *slot;
  1357. mmc = mmc_alloc_host(sizeof(struct atmel_mci_slot), &host->pdev->dev);
  1358. if (!mmc)
  1359. return -ENOMEM;
  1360. slot = mmc_priv(mmc);
  1361. slot->mmc = mmc;
  1362. slot->host = host;
  1363. slot->detect_pin = slot_data->detect_pin;
  1364. slot->wp_pin = slot_data->wp_pin;
  1365. slot->detect_is_active_high = slot_data->detect_is_active_high;
  1366. slot->sdc_reg = sdc_reg;
  1367. slot->sdio_irq = sdio_irq;
  1368. mmc->ops = &atmci_ops;
  1369. mmc->f_min = DIV_ROUND_UP(host->bus_hz, 512);
  1370. mmc->f_max = host->bus_hz / 2;
  1371. mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
  1372. if (sdio_irq)
  1373. mmc->caps |= MMC_CAP_SDIO_IRQ;
  1374. if (atmci_is_mci2())
  1375. mmc->caps |= MMC_CAP_SD_HIGHSPEED;
  1376. if (slot_data->bus_width >= 4)
  1377. mmc->caps |= MMC_CAP_4_BIT_DATA;
  1378. mmc->max_segs = 64;
  1379. mmc->max_req_size = 32768 * 512;
  1380. mmc->max_blk_size = 32768;
  1381. mmc->max_blk_count = 512;
  1382. /* Assume card is present initially */
  1383. set_bit(ATMCI_CARD_PRESENT, &slot->flags);
  1384. if (gpio_is_valid(slot->detect_pin)) {
  1385. if (gpio_request(slot->detect_pin, "mmc_detect")) {
  1386. dev_dbg(&mmc->class_dev, "no detect pin available\n");
  1387. slot->detect_pin = -EBUSY;
  1388. } else if (gpio_get_value(slot->detect_pin) ^
  1389. slot->detect_is_active_high) {
  1390. clear_bit(ATMCI_CARD_PRESENT, &slot->flags);
  1391. }
  1392. }
  1393. if (!gpio_is_valid(slot->detect_pin))
  1394. mmc->caps |= MMC_CAP_NEEDS_POLL;
  1395. if (gpio_is_valid(slot->wp_pin)) {
  1396. if (gpio_request(slot->wp_pin, "mmc_wp")) {
  1397. dev_dbg(&mmc->class_dev, "no WP pin available\n");
  1398. slot->wp_pin = -EBUSY;
  1399. }
  1400. }
  1401. host->slot[id] = slot;
  1402. mmc_add_host(mmc);
  1403. if (gpio_is_valid(slot->detect_pin)) {
  1404. int ret;
  1405. setup_timer(&slot->detect_timer, atmci_detect_change,
  1406. (unsigned long)slot);
  1407. ret = request_irq(gpio_to_irq(slot->detect_pin),
  1408. atmci_detect_interrupt,
  1409. IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
  1410. "mmc-detect", slot);
  1411. if (ret) {
  1412. dev_dbg(&mmc->class_dev,
  1413. "could not request IRQ %d for detect pin\n",
  1414. gpio_to_irq(slot->detect_pin));
  1415. gpio_free(slot->detect_pin);
  1416. slot->detect_pin = -EBUSY;
  1417. }
  1418. }
  1419. atmci_init_debugfs(slot);
  1420. return 0;
  1421. }
  1422. static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,
  1423. unsigned int id)
  1424. {
  1425. /* Debugfs stuff is cleaned up by mmc core */
  1426. set_bit(ATMCI_SHUTDOWN, &slot->flags);
  1427. smp_wmb();
  1428. mmc_remove_host(slot->mmc);
  1429. if (gpio_is_valid(slot->detect_pin)) {
  1430. int pin = slot->detect_pin;
  1431. free_irq(gpio_to_irq(pin), slot);
  1432. del_timer_sync(&slot->detect_timer);
  1433. gpio_free(pin);
  1434. }
  1435. if (gpio_is_valid(slot->wp_pin))
  1436. gpio_free(slot->wp_pin);
  1437. slot->host->slot[id] = NULL;
  1438. mmc_free_host(slot->mmc);
  1439. }
  1440. #ifdef CONFIG_MMC_ATMELMCI_DMA
  1441. static bool filter(struct dma_chan *chan, void *slave)
  1442. {
  1443. struct mci_dma_data *sl = slave;
  1444. if (sl && find_slave_dev(sl) == chan->device->dev) {
  1445. chan->private = slave_data_ptr(sl);
  1446. return true;
  1447. } else {
  1448. return false;
  1449. }
  1450. }
  1451. static void atmci_configure_dma(struct atmel_mci *host)
  1452. {
  1453. struct mci_platform_data *pdata;
  1454. if (host == NULL)
  1455. return;
  1456. pdata = host->pdev->dev.platform_data;
  1457. if (pdata && find_slave_dev(pdata->dma_slave)) {
  1458. dma_cap_mask_t mask;
  1459. setup_dma_addr(pdata->dma_slave,
  1460. host->mapbase + MCI_TDR,
  1461. host->mapbase + MCI_RDR);
  1462. /* Try to grab a DMA channel */
  1463. dma_cap_zero(mask);
  1464. dma_cap_set(DMA_SLAVE, mask);
  1465. host->dma.chan =
  1466. dma_request_channel(mask, filter, pdata->dma_slave);
  1467. }
  1468. if (!host->dma.chan)
  1469. dev_notice(&host->pdev->dev, "DMA not available, using PIO\n");
  1470. else
  1471. dev_info(&host->pdev->dev,
  1472. "Using %s for DMA transfers\n",
  1473. dma_chan_name(host->dma.chan));
  1474. }
  1475. #else
  1476. static void atmci_configure_dma(struct atmel_mci *host) {}
  1477. #endif
  1478. static int __init atmci_probe(struct platform_device *pdev)
  1479. {
  1480. struct mci_platform_data *pdata;
  1481. struct atmel_mci *host;
  1482. struct resource *regs;
  1483. unsigned int nr_slots;
  1484. int irq;
  1485. int ret;
  1486. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1487. if (!regs)
  1488. return -ENXIO;
  1489. pdata = pdev->dev.platform_data;
  1490. if (!pdata)
  1491. return -ENXIO;
  1492. irq = platform_get_irq(pdev, 0);
  1493. if (irq < 0)
  1494. return irq;
  1495. host = kzalloc(sizeof(struct atmel_mci), GFP_KERNEL);
  1496. if (!host)
  1497. return -ENOMEM;
  1498. host->pdev = pdev;
  1499. spin_lock_init(&host->lock);
  1500. INIT_LIST_HEAD(&host->queue);
  1501. host->mck = clk_get(&pdev->dev, "mci_clk");
  1502. if (IS_ERR(host->mck)) {
  1503. ret = PTR_ERR(host->mck);
  1504. goto err_clk_get;
  1505. }
  1506. ret = -ENOMEM;
  1507. host->regs = ioremap(regs->start, resource_size(regs));
  1508. if (!host->regs)
  1509. goto err_ioremap;
  1510. clk_enable(host->mck);
  1511. mci_writel(host, CR, MCI_CR_SWRST);
  1512. host->bus_hz = clk_get_rate(host->mck);
  1513. clk_disable(host->mck);
  1514. host->mapbase = regs->start;
  1515. tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host);
  1516. ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host);
  1517. if (ret)
  1518. goto err_request_irq;
  1519. atmci_configure_dma(host);
  1520. platform_set_drvdata(pdev, host);
  1521. /* We need at least one slot to succeed */
  1522. nr_slots = 0;
  1523. ret = -ENODEV;
  1524. if (pdata->slot[0].bus_width) {
  1525. ret = atmci_init_slot(host, &pdata->slot[0],
  1526. 0, MCI_SDCSEL_SLOT_A, MCI_SDIOIRQA);
  1527. if (!ret)
  1528. nr_slots++;
  1529. }
  1530. if (pdata->slot[1].bus_width) {
  1531. ret = atmci_init_slot(host, &pdata->slot[1],
  1532. 1, MCI_SDCSEL_SLOT_B, MCI_SDIOIRQB);
  1533. if (!ret)
  1534. nr_slots++;
  1535. }
  1536. if (!nr_slots) {
  1537. dev_err(&pdev->dev, "init failed: no slot defined\n");
  1538. goto err_init_slot;
  1539. }
  1540. dev_info(&pdev->dev,
  1541. "Atmel MCI controller at 0x%08lx irq %d, %u slots\n",
  1542. host->mapbase, irq, nr_slots);
  1543. return 0;
  1544. err_init_slot:
  1545. #ifdef CONFIG_MMC_ATMELMCI_DMA
  1546. if (host->dma.chan)
  1547. dma_release_channel(host->dma.chan);
  1548. #endif
  1549. free_irq(irq, host);
  1550. err_request_irq:
  1551. iounmap(host->regs);
  1552. err_ioremap:
  1553. clk_put(host->mck);
  1554. err_clk_get:
  1555. kfree(host);
  1556. return ret;
  1557. }
  1558. static int __exit atmci_remove(struct platform_device *pdev)
  1559. {
  1560. struct atmel_mci *host = platform_get_drvdata(pdev);
  1561. unsigned int i;
  1562. platform_set_drvdata(pdev, NULL);
  1563. for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) {
  1564. if (host->slot[i])
  1565. atmci_cleanup_slot(host->slot[i], i);
  1566. }
  1567. clk_enable(host->mck);
  1568. mci_writel(host, IDR, ~0UL);
  1569. mci_writel(host, CR, MCI_CR_MCIDIS);
  1570. mci_readl(host, SR);
  1571. clk_disable(host->mck);
  1572. #ifdef CONFIG_MMC_ATMELMCI_DMA
  1573. if (host->dma.chan)
  1574. dma_release_channel(host->dma.chan);
  1575. #endif
  1576. free_irq(platform_get_irq(pdev, 0), host);
  1577. iounmap(host->regs);
  1578. clk_put(host->mck);
  1579. kfree(host);
  1580. return 0;
  1581. }
  1582. static struct platform_driver atmci_driver = {
  1583. .remove = __exit_p(atmci_remove),
  1584. .driver = {
  1585. .name = "atmel_mci",
  1586. },
  1587. };
  1588. static int __init atmci_init(void)
  1589. {
  1590. return platform_driver_probe(&atmci_driver, atmci_probe);
  1591. }
  1592. static void __exit atmci_exit(void)
  1593. {
  1594. platform_driver_unregister(&atmci_driver);
  1595. }
  1596. late_initcall(atmci_init); /* try to load after dma driver when built-in */
  1597. module_exit(atmci_exit);
  1598. MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
  1599. MODULE_AUTHOR("Haavard Skinnemoen <haavard.skinnemoen@atmel.com>");
  1600. MODULE_LICENSE("GPL v2");