sdhci.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. /*
  2. * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
  3. *
  4. * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * Thanks to the following companies for their support:
  12. *
  13. * - JMicron (hardware and technical support)
  14. */
  15. #include <linux/delay.h>
  16. #include <linux/highmem.h>
  17. #include <linux/io.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/scatterlist.h>
  20. #include <linux/leds.h>
  21. #include <linux/mmc/host.h>
  22. #include "sdhci.h"
  23. #define DRIVER_NAME "sdhci"
  24. #define DBG(f, x...) \
  25. pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  26. #if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \
  27. defined(CONFIG_MMC_SDHCI_MODULE))
  28. #define SDHCI_USE_LEDS_CLASS
  29. #endif
  30. static unsigned int debug_quirks = 0;
  31. static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
  32. static void sdhci_finish_data(struct sdhci_host *);
  33. static void sdhci_send_command(struct sdhci_host *, struct mmc_command *);
  34. static void sdhci_finish_command(struct sdhci_host *);
  35. static void sdhci_dumpregs(struct sdhci_host *host)
  36. {
  37. printk(KERN_DEBUG DRIVER_NAME ": ============== REGISTER DUMP ==============\n");
  38. printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
  39. sdhci_readl(host, SDHCI_DMA_ADDRESS),
  40. sdhci_readw(host, SDHCI_HOST_VERSION));
  41. printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
  42. sdhci_readw(host, SDHCI_BLOCK_SIZE),
  43. sdhci_readw(host, SDHCI_BLOCK_COUNT));
  44. printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
  45. sdhci_readl(host, SDHCI_ARGUMENT),
  46. sdhci_readw(host, SDHCI_TRANSFER_MODE));
  47. printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
  48. sdhci_readl(host, SDHCI_PRESENT_STATE),
  49. sdhci_readb(host, SDHCI_HOST_CONTROL));
  50. printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
  51. sdhci_readb(host, SDHCI_POWER_CONTROL),
  52. sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL));
  53. printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
  54. sdhci_readb(host, SDHCI_WAKE_UP_CONTROL),
  55. sdhci_readw(host, SDHCI_CLOCK_CONTROL));
  56. printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
  57. sdhci_readb(host, SDHCI_TIMEOUT_CONTROL),
  58. sdhci_readl(host, SDHCI_INT_STATUS));
  59. printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
  60. sdhci_readl(host, SDHCI_INT_ENABLE),
  61. sdhci_readl(host, SDHCI_SIGNAL_ENABLE));
  62. printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
  63. sdhci_readw(host, SDHCI_ACMD12_ERR),
  64. sdhci_readw(host, SDHCI_SLOT_INT_STATUS));
  65. printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Max curr: 0x%08x\n",
  66. sdhci_readl(host, SDHCI_CAPABILITIES),
  67. sdhci_readl(host, SDHCI_MAX_CURRENT));
  68. printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n");
  69. }
  70. /*****************************************************************************\
  71. * *
  72. * Low level functions *
  73. * *
  74. \*****************************************************************************/
  75. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  76. {
  77. u32 ier;
  78. ier = sdhci_readl(host, SDHCI_INT_ENABLE);
  79. ier &= ~clear;
  80. ier |= set;
  81. sdhci_writel(host, ier, SDHCI_INT_ENABLE);
  82. sdhci_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  83. }
  84. static void sdhci_unmask_irqs(struct sdhci_host *host, u32 irqs)
  85. {
  86. sdhci_clear_set_irqs(host, 0, irqs);
  87. }
  88. static void sdhci_mask_irqs(struct sdhci_host *host, u32 irqs)
  89. {
  90. sdhci_clear_set_irqs(host, irqs, 0);
  91. }
  92. static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
  93. {
  94. u32 irqs = SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT;
  95. if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
  96. return;
  97. if (enable)
  98. sdhci_unmask_irqs(host, irqs);
  99. else
  100. sdhci_mask_irqs(host, irqs);
  101. }
  102. static void sdhci_enable_card_detection(struct sdhci_host *host)
  103. {
  104. sdhci_set_card_detection(host, true);
  105. }
  106. static void sdhci_disable_card_detection(struct sdhci_host *host)
  107. {
  108. sdhci_set_card_detection(host, false);
  109. }
  110. static void sdhci_reset(struct sdhci_host *host, u8 mask)
  111. {
  112. unsigned long timeout;
  113. u32 uninitialized_var(ier);
  114. if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
  115. if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
  116. SDHCI_CARD_PRESENT))
  117. return;
  118. }
  119. if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
  120. ier = sdhci_readl(host, SDHCI_INT_ENABLE);
  121. sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
  122. if (mask & SDHCI_RESET_ALL)
  123. host->clock = 0;
  124. /* Wait max 100 ms */
  125. timeout = 100;
  126. /* hw clears the bit when it's done */
  127. while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
  128. if (timeout == 0) {
  129. printk(KERN_ERR "%s: Reset 0x%x never completed.\n",
  130. mmc_hostname(host->mmc), (int)mask);
  131. sdhci_dumpregs(host);
  132. return;
  133. }
  134. timeout--;
  135. mdelay(1);
  136. }
  137. if (host->quirks & SDHCI_QUIRK_RESTORE_IRQS_AFTER_RESET)
  138. sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK, ier);
  139. }
  140. static void sdhci_init(struct sdhci_host *host)
  141. {
  142. sdhci_reset(host, SDHCI_RESET_ALL);
  143. sdhci_clear_set_irqs(host, SDHCI_INT_ALL_MASK,
  144. SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT |
  145. SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX |
  146. SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT |
  147. SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE);
  148. }
  149. static void sdhci_reinit(struct sdhci_host *host)
  150. {
  151. sdhci_init(host);
  152. sdhci_enable_card_detection(host);
  153. }
  154. static void sdhci_activate_led(struct sdhci_host *host)
  155. {
  156. u8 ctrl;
  157. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  158. ctrl |= SDHCI_CTRL_LED;
  159. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  160. }
  161. static void sdhci_deactivate_led(struct sdhci_host *host)
  162. {
  163. u8 ctrl;
  164. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  165. ctrl &= ~SDHCI_CTRL_LED;
  166. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  167. }
  168. #ifdef SDHCI_USE_LEDS_CLASS
  169. static void sdhci_led_control(struct led_classdev *led,
  170. enum led_brightness brightness)
  171. {
  172. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  173. unsigned long flags;
  174. spin_lock_irqsave(&host->lock, flags);
  175. if (brightness == LED_OFF)
  176. sdhci_deactivate_led(host);
  177. else
  178. sdhci_activate_led(host);
  179. spin_unlock_irqrestore(&host->lock, flags);
  180. }
  181. #endif
  182. /*****************************************************************************\
  183. * *
  184. * Core functions *
  185. * *
  186. \*****************************************************************************/
  187. static void sdhci_read_block_pio(struct sdhci_host *host)
  188. {
  189. unsigned long flags;
  190. size_t blksize, len, chunk;
  191. u32 uninitialized_var(scratch);
  192. u8 *buf;
  193. DBG("PIO reading\n");
  194. blksize = host->data->blksz;
  195. chunk = 0;
  196. local_irq_save(flags);
  197. while (blksize) {
  198. if (!sg_miter_next(&host->sg_miter))
  199. BUG();
  200. len = min(host->sg_miter.length, blksize);
  201. blksize -= len;
  202. host->sg_miter.consumed = len;
  203. buf = host->sg_miter.addr;
  204. while (len) {
  205. if (chunk == 0) {
  206. scratch = sdhci_readl(host, SDHCI_BUFFER);
  207. chunk = 4;
  208. }
  209. *buf = scratch & 0xFF;
  210. buf++;
  211. scratch >>= 8;
  212. chunk--;
  213. len--;
  214. }
  215. }
  216. sg_miter_stop(&host->sg_miter);
  217. local_irq_restore(flags);
  218. }
  219. static void sdhci_write_block_pio(struct sdhci_host *host)
  220. {
  221. unsigned long flags;
  222. size_t blksize, len, chunk;
  223. u32 scratch;
  224. u8 *buf;
  225. DBG("PIO writing\n");
  226. blksize = host->data->blksz;
  227. chunk = 0;
  228. scratch = 0;
  229. local_irq_save(flags);
  230. while (blksize) {
  231. if (!sg_miter_next(&host->sg_miter))
  232. BUG();
  233. len = min(host->sg_miter.length, blksize);
  234. blksize -= len;
  235. host->sg_miter.consumed = len;
  236. buf = host->sg_miter.addr;
  237. while (len) {
  238. scratch |= (u32)*buf << (chunk * 8);
  239. buf++;
  240. chunk++;
  241. len--;
  242. if ((chunk == 4) || ((len == 0) && (blksize == 0))) {
  243. sdhci_writel(host, scratch, SDHCI_BUFFER);
  244. chunk = 0;
  245. scratch = 0;
  246. }
  247. }
  248. }
  249. sg_miter_stop(&host->sg_miter);
  250. local_irq_restore(flags);
  251. }
  252. static void sdhci_transfer_pio(struct sdhci_host *host)
  253. {
  254. u32 mask;
  255. BUG_ON(!host->data);
  256. if (host->blocks == 0)
  257. return;
  258. if (host->data->flags & MMC_DATA_READ)
  259. mask = SDHCI_DATA_AVAILABLE;
  260. else
  261. mask = SDHCI_SPACE_AVAILABLE;
  262. /*
  263. * Some controllers (JMicron JMB38x) mess up the buffer bits
  264. * for transfers < 4 bytes. As long as it is just one block,
  265. * we can ignore the bits.
  266. */
  267. if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) &&
  268. (host->data->blocks == 1))
  269. mask = ~0;
  270. while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  271. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  272. udelay(100);
  273. if (host->data->flags & MMC_DATA_READ)
  274. sdhci_read_block_pio(host);
  275. else
  276. sdhci_write_block_pio(host);
  277. host->blocks--;
  278. if (host->blocks == 0)
  279. break;
  280. }
  281. DBG("PIO transfer complete.\n");
  282. }
  283. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  284. {
  285. local_irq_save(*flags);
  286. return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
  287. }
  288. static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
  289. {
  290. kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
  291. local_irq_restore(*flags);
  292. }
  293. static int sdhci_adma_table_pre(struct sdhci_host *host,
  294. struct mmc_data *data)
  295. {
  296. int direction;
  297. u8 *desc;
  298. u8 *align;
  299. dma_addr_t addr;
  300. dma_addr_t align_addr;
  301. int len, offset;
  302. struct scatterlist *sg;
  303. int i;
  304. char *buffer;
  305. unsigned long flags;
  306. /*
  307. * The spec does not specify endianness of descriptor table.
  308. * We currently guess that it is LE.
  309. */
  310. if (data->flags & MMC_DATA_READ)
  311. direction = DMA_FROM_DEVICE;
  312. else
  313. direction = DMA_TO_DEVICE;
  314. /*
  315. * The ADMA descriptor table is mapped further down as we
  316. * need to fill it with data first.
  317. */
  318. host->align_addr = dma_map_single(mmc_dev(host->mmc),
  319. host->align_buffer, 128 * 4, direction);
  320. if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
  321. goto fail;
  322. BUG_ON(host->align_addr & 0x3);
  323. host->sg_count = dma_map_sg(mmc_dev(host->mmc),
  324. data->sg, data->sg_len, direction);
  325. if (host->sg_count == 0)
  326. goto unmap_align;
  327. desc = host->adma_desc;
  328. align = host->align_buffer;
  329. align_addr = host->align_addr;
  330. for_each_sg(data->sg, sg, host->sg_count, i) {
  331. addr = sg_dma_address(sg);
  332. len = sg_dma_len(sg);
  333. /*
  334. * The SDHCI specification states that ADMA
  335. * addresses must be 32-bit aligned. If they
  336. * aren't, then we use a bounce buffer for
  337. * the (up to three) bytes that screw up the
  338. * alignment.
  339. */
  340. offset = (4 - (addr & 0x3)) & 0x3;
  341. if (offset) {
  342. if (data->flags & MMC_DATA_WRITE) {
  343. buffer = sdhci_kmap_atomic(sg, &flags);
  344. WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
  345. memcpy(align, buffer, offset);
  346. sdhci_kunmap_atomic(buffer, &flags);
  347. }
  348. desc[7] = (align_addr >> 24) & 0xff;
  349. desc[6] = (align_addr >> 16) & 0xff;
  350. desc[5] = (align_addr >> 8) & 0xff;
  351. desc[4] = (align_addr >> 0) & 0xff;
  352. BUG_ON(offset > 65536);
  353. desc[3] = (offset >> 8) & 0xff;
  354. desc[2] = (offset >> 0) & 0xff;
  355. desc[1] = 0x00;
  356. desc[0] = 0x21; /* tran, valid */
  357. align += 4;
  358. align_addr += 4;
  359. desc += 8;
  360. addr += offset;
  361. len -= offset;
  362. }
  363. desc[7] = (addr >> 24) & 0xff;
  364. desc[6] = (addr >> 16) & 0xff;
  365. desc[5] = (addr >> 8) & 0xff;
  366. desc[4] = (addr >> 0) & 0xff;
  367. BUG_ON(len > 65536);
  368. desc[3] = (len >> 8) & 0xff;
  369. desc[2] = (len >> 0) & 0xff;
  370. desc[1] = 0x00;
  371. desc[0] = 0x21; /* tran, valid */
  372. desc += 8;
  373. /*
  374. * If this triggers then we have a calculation bug
  375. * somewhere. :/
  376. */
  377. WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4);
  378. }
  379. /*
  380. * Add a terminating entry.
  381. */
  382. desc[7] = 0;
  383. desc[6] = 0;
  384. desc[5] = 0;
  385. desc[4] = 0;
  386. desc[3] = 0;
  387. desc[2] = 0;
  388. desc[1] = 0x00;
  389. desc[0] = 0x03; /* nop, end, valid */
  390. /*
  391. * Resync align buffer as we might have changed it.
  392. */
  393. if (data->flags & MMC_DATA_WRITE) {
  394. dma_sync_single_for_device(mmc_dev(host->mmc),
  395. host->align_addr, 128 * 4, direction);
  396. }
  397. host->adma_addr = dma_map_single(mmc_dev(host->mmc),
  398. host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE);
  399. if (dma_mapping_error(mmc_dev(host->mmc), host->adma_addr))
  400. goto unmap_entries;
  401. BUG_ON(host->adma_addr & 0x3);
  402. return 0;
  403. unmap_entries:
  404. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  405. data->sg_len, direction);
  406. unmap_align:
  407. dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
  408. 128 * 4, direction);
  409. fail:
  410. return -EINVAL;
  411. }
  412. static void sdhci_adma_table_post(struct sdhci_host *host,
  413. struct mmc_data *data)
  414. {
  415. int direction;
  416. struct scatterlist *sg;
  417. int i, size;
  418. u8 *align;
  419. char *buffer;
  420. unsigned long flags;
  421. if (data->flags & MMC_DATA_READ)
  422. direction = DMA_FROM_DEVICE;
  423. else
  424. direction = DMA_TO_DEVICE;
  425. dma_unmap_single(mmc_dev(host->mmc), host->adma_addr,
  426. (128 * 2 + 1) * 4, DMA_TO_DEVICE);
  427. dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
  428. 128 * 4, direction);
  429. if (data->flags & MMC_DATA_READ) {
  430. dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg,
  431. data->sg_len, direction);
  432. align = host->align_buffer;
  433. for_each_sg(data->sg, sg, host->sg_count, i) {
  434. if (sg_dma_address(sg) & 0x3) {
  435. size = 4 - (sg_dma_address(sg) & 0x3);
  436. buffer = sdhci_kmap_atomic(sg, &flags);
  437. WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3));
  438. memcpy(buffer, align, size);
  439. sdhci_kunmap_atomic(buffer, &flags);
  440. align += 4;
  441. }
  442. }
  443. }
  444. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  445. data->sg_len, direction);
  446. }
  447. static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data)
  448. {
  449. u8 count;
  450. unsigned target_timeout, current_timeout;
  451. /*
  452. * If the host controller provides us with an incorrect timeout
  453. * value, just skip the check and use 0xE. The hardware may take
  454. * longer to time out, but that's much better than having a too-short
  455. * timeout value.
  456. */
  457. if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL))
  458. return 0xE;
  459. /* timeout in us */
  460. target_timeout = data->timeout_ns / 1000 +
  461. data->timeout_clks / host->clock;
  462. /*
  463. * Figure out needed cycles.
  464. * We do this in steps in order to fit inside a 32 bit int.
  465. * The first step is the minimum timeout, which will have a
  466. * minimum resolution of 6 bits:
  467. * (1) 2^13*1000 > 2^22,
  468. * (2) host->timeout_clk < 2^16
  469. * =>
  470. * (1) / (2) > 2^6
  471. */
  472. count = 0;
  473. current_timeout = (1 << 13) * 1000 / host->timeout_clk;
  474. while (current_timeout < target_timeout) {
  475. count++;
  476. current_timeout <<= 1;
  477. if (count >= 0xF)
  478. break;
  479. }
  480. if (count >= 0xF) {
  481. printk(KERN_WARNING "%s: Too large timeout requested!\n",
  482. mmc_hostname(host->mmc));
  483. count = 0xE;
  484. }
  485. return count;
  486. }
  487. static void sdhci_set_transfer_irqs(struct sdhci_host *host)
  488. {
  489. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  490. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  491. if (host->flags & SDHCI_REQ_USE_DMA)
  492. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  493. else
  494. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  495. }
  496. static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
  497. {
  498. u8 count;
  499. u8 ctrl;
  500. int ret;
  501. WARN_ON(host->data);
  502. if (data == NULL)
  503. return;
  504. /* Sanity checks */
  505. BUG_ON(data->blksz * data->blocks > 524288);
  506. BUG_ON(data->blksz > host->mmc->max_blk_size);
  507. BUG_ON(data->blocks > 65535);
  508. host->data = data;
  509. host->data_early = 0;
  510. count = sdhci_calc_timeout(host, data);
  511. sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL);
  512. if (host->flags & SDHCI_USE_DMA)
  513. host->flags |= SDHCI_REQ_USE_DMA;
  514. /*
  515. * FIXME: This doesn't account for merging when mapping the
  516. * scatterlist.
  517. */
  518. if (host->flags & SDHCI_REQ_USE_DMA) {
  519. int broken, i;
  520. struct scatterlist *sg;
  521. broken = 0;
  522. if (host->flags & SDHCI_USE_ADMA) {
  523. if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  524. broken = 1;
  525. } else {
  526. if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  527. broken = 1;
  528. }
  529. if (unlikely(broken)) {
  530. for_each_sg(data->sg, sg, data->sg_len, i) {
  531. if (sg->length & 0x3) {
  532. DBG("Reverting to PIO because of "
  533. "transfer size (%d)\n",
  534. sg->length);
  535. host->flags &= ~SDHCI_REQ_USE_DMA;
  536. break;
  537. }
  538. }
  539. }
  540. }
  541. /*
  542. * The assumption here being that alignment is the same after
  543. * translation to device address space.
  544. */
  545. if (host->flags & SDHCI_REQ_USE_DMA) {
  546. int broken, i;
  547. struct scatterlist *sg;
  548. broken = 0;
  549. if (host->flags & SDHCI_USE_ADMA) {
  550. /*
  551. * As we use 3 byte chunks to work around
  552. * alignment problems, we need to check this
  553. * quirk.
  554. */
  555. if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  556. broken = 1;
  557. } else {
  558. if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR)
  559. broken = 1;
  560. }
  561. if (unlikely(broken)) {
  562. for_each_sg(data->sg, sg, data->sg_len, i) {
  563. if (sg->offset & 0x3) {
  564. DBG("Reverting to PIO because of "
  565. "bad alignment\n");
  566. host->flags &= ~SDHCI_REQ_USE_DMA;
  567. break;
  568. }
  569. }
  570. }
  571. }
  572. if (host->flags & SDHCI_REQ_USE_DMA) {
  573. if (host->flags & SDHCI_USE_ADMA) {
  574. ret = sdhci_adma_table_pre(host, data);
  575. if (ret) {
  576. /*
  577. * This only happens when someone fed
  578. * us an invalid request.
  579. */
  580. WARN_ON(1);
  581. host->flags &= ~SDHCI_REQ_USE_DMA;
  582. } else {
  583. sdhci_writel(host, host->adma_addr,
  584. SDHCI_ADMA_ADDRESS);
  585. }
  586. } else {
  587. int sg_cnt;
  588. sg_cnt = dma_map_sg(mmc_dev(host->mmc),
  589. data->sg, data->sg_len,
  590. (data->flags & MMC_DATA_READ) ?
  591. DMA_FROM_DEVICE :
  592. DMA_TO_DEVICE);
  593. if (sg_cnt == 0) {
  594. /*
  595. * This only happens when someone fed
  596. * us an invalid request.
  597. */
  598. WARN_ON(1);
  599. host->flags &= ~SDHCI_REQ_USE_DMA;
  600. } else {
  601. WARN_ON(sg_cnt != 1);
  602. sdhci_writel(host, sg_dma_address(data->sg),
  603. SDHCI_DMA_ADDRESS);
  604. }
  605. }
  606. }
  607. /*
  608. * Always adjust the DMA selection as some controllers
  609. * (e.g. JMicron) can't do PIO properly when the selection
  610. * is ADMA.
  611. */
  612. if (host->version >= SDHCI_SPEC_200) {
  613. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  614. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  615. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  616. (host->flags & SDHCI_USE_ADMA))
  617. ctrl |= SDHCI_CTRL_ADMA32;
  618. else
  619. ctrl |= SDHCI_CTRL_SDMA;
  620. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  621. }
  622. if (!(host->flags & SDHCI_REQ_USE_DMA)) {
  623. sg_miter_start(&host->sg_miter,
  624. data->sg, data->sg_len, SG_MITER_ATOMIC);
  625. host->blocks = data->blocks;
  626. }
  627. sdhci_set_transfer_irqs(host);
  628. /* We do not handle DMA boundaries, so set it to max (512 KiB) */
  629. sdhci_writew(host, SDHCI_MAKE_BLKSZ(7, data->blksz), SDHCI_BLOCK_SIZE);
  630. sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
  631. }
  632. static void sdhci_set_transfer_mode(struct sdhci_host *host,
  633. struct mmc_data *data)
  634. {
  635. u16 mode;
  636. if (data == NULL)
  637. return;
  638. WARN_ON(!host->data);
  639. mode = SDHCI_TRNS_BLK_CNT_EN;
  640. if (data->blocks > 1)
  641. mode |= SDHCI_TRNS_MULTI;
  642. if (data->flags & MMC_DATA_READ)
  643. mode |= SDHCI_TRNS_READ;
  644. if (host->flags & SDHCI_REQ_USE_DMA)
  645. mode |= SDHCI_TRNS_DMA;
  646. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  647. }
  648. static void sdhci_finish_data(struct sdhci_host *host)
  649. {
  650. struct mmc_data *data;
  651. BUG_ON(!host->data);
  652. data = host->data;
  653. host->data = NULL;
  654. if (host->flags & SDHCI_REQ_USE_DMA) {
  655. if (host->flags & SDHCI_USE_ADMA)
  656. sdhci_adma_table_post(host, data);
  657. else {
  658. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  659. data->sg_len, (data->flags & MMC_DATA_READ) ?
  660. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  661. }
  662. }
  663. /*
  664. * The specification states that the block count register must
  665. * be updated, but it does not specify at what point in the
  666. * data flow. That makes the register entirely useless to read
  667. * back so we have to assume that nothing made it to the card
  668. * in the event of an error.
  669. */
  670. if (data->error)
  671. data->bytes_xfered = 0;
  672. else
  673. data->bytes_xfered = data->blksz * data->blocks;
  674. if (data->stop) {
  675. /*
  676. * The controller needs a reset of internal state machines
  677. * upon error conditions.
  678. */
  679. if (data->error) {
  680. sdhci_reset(host, SDHCI_RESET_CMD);
  681. sdhci_reset(host, SDHCI_RESET_DATA);
  682. }
  683. sdhci_send_command(host, data->stop);
  684. } else
  685. tasklet_schedule(&host->finish_tasklet);
  686. }
  687. static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
  688. {
  689. int flags;
  690. u32 mask;
  691. unsigned long timeout;
  692. WARN_ON(host->cmd);
  693. /* Wait max 10 ms */
  694. timeout = 10;
  695. mask = SDHCI_CMD_INHIBIT;
  696. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  697. mask |= SDHCI_DATA_INHIBIT;
  698. /* We shouldn't wait for data inihibit for stop commands, even
  699. though they might use busy signaling */
  700. if (host->mrq->data && (cmd == host->mrq->data->stop))
  701. mask &= ~SDHCI_DATA_INHIBIT;
  702. while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  703. if (timeout == 0) {
  704. printk(KERN_ERR "%s: Controller never released "
  705. "inhibit bit(s).\n", mmc_hostname(host->mmc));
  706. sdhci_dumpregs(host);
  707. cmd->error = -EIO;
  708. tasklet_schedule(&host->finish_tasklet);
  709. return;
  710. }
  711. timeout--;
  712. mdelay(1);
  713. }
  714. mod_timer(&host->timer, jiffies + 10 * HZ);
  715. host->cmd = cmd;
  716. sdhci_prepare_data(host, cmd->data);
  717. sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT);
  718. sdhci_set_transfer_mode(host, cmd->data);
  719. if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
  720. printk(KERN_ERR "%s: Unsupported response type!\n",
  721. mmc_hostname(host->mmc));
  722. cmd->error = -EINVAL;
  723. tasklet_schedule(&host->finish_tasklet);
  724. return;
  725. }
  726. if (!(cmd->flags & MMC_RSP_PRESENT))
  727. flags = SDHCI_CMD_RESP_NONE;
  728. else if (cmd->flags & MMC_RSP_136)
  729. flags = SDHCI_CMD_RESP_LONG;
  730. else if (cmd->flags & MMC_RSP_BUSY)
  731. flags = SDHCI_CMD_RESP_SHORT_BUSY;
  732. else
  733. flags = SDHCI_CMD_RESP_SHORT;
  734. if (cmd->flags & MMC_RSP_CRC)
  735. flags |= SDHCI_CMD_CRC;
  736. if (cmd->flags & MMC_RSP_OPCODE)
  737. flags |= SDHCI_CMD_INDEX;
  738. if (cmd->data)
  739. flags |= SDHCI_CMD_DATA;
  740. sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
  741. }
  742. static void sdhci_finish_command(struct sdhci_host *host)
  743. {
  744. int i;
  745. BUG_ON(host->cmd == NULL);
  746. if (host->cmd->flags & MMC_RSP_PRESENT) {
  747. if (host->cmd->flags & MMC_RSP_136) {
  748. /* CRC is stripped so we need to do some shifting. */
  749. for (i = 0;i < 4;i++) {
  750. host->cmd->resp[i] = sdhci_readl(host,
  751. SDHCI_RESPONSE + (3-i)*4) << 8;
  752. if (i != 3)
  753. host->cmd->resp[i] |=
  754. sdhci_readb(host,
  755. SDHCI_RESPONSE + (3-i)*4-1);
  756. }
  757. } else {
  758. host->cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE);
  759. }
  760. }
  761. host->cmd->error = 0;
  762. if (host->data && host->data_early)
  763. sdhci_finish_data(host);
  764. if (!host->cmd->data)
  765. tasklet_schedule(&host->finish_tasklet);
  766. host->cmd = NULL;
  767. }
  768. static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
  769. {
  770. int div;
  771. u16 clk;
  772. unsigned long timeout;
  773. if (clock == host->clock)
  774. return;
  775. if (host->ops->set_clock) {
  776. host->ops->set_clock(host, clock);
  777. if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK)
  778. return;
  779. }
  780. sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
  781. if (clock == 0)
  782. goto out;
  783. for (div = 1;div < 256;div *= 2) {
  784. if ((host->max_clk / div) <= clock)
  785. break;
  786. }
  787. div >>= 1;
  788. clk = div << SDHCI_DIVIDER_SHIFT;
  789. clk |= SDHCI_CLOCK_INT_EN;
  790. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  791. /* Wait max 10 ms */
  792. timeout = 10;
  793. while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
  794. & SDHCI_CLOCK_INT_STABLE)) {
  795. if (timeout == 0) {
  796. printk(KERN_ERR "%s: Internal clock never "
  797. "stabilised.\n", mmc_hostname(host->mmc));
  798. sdhci_dumpregs(host);
  799. return;
  800. }
  801. timeout--;
  802. mdelay(1);
  803. }
  804. clk |= SDHCI_CLOCK_CARD_EN;
  805. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  806. out:
  807. host->clock = clock;
  808. }
  809. static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
  810. {
  811. u8 pwr;
  812. if (host->power == power)
  813. return;
  814. if (power == (unsigned short)-1) {
  815. sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
  816. goto out;
  817. }
  818. /*
  819. * Spec says that we should clear the power reg before setting
  820. * a new value. Some controllers don't seem to like this though.
  821. */
  822. if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE))
  823. sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
  824. pwr = SDHCI_POWER_ON;
  825. switch (1 << power) {
  826. case MMC_VDD_165_195:
  827. pwr |= SDHCI_POWER_180;
  828. break;
  829. case MMC_VDD_29_30:
  830. case MMC_VDD_30_31:
  831. pwr |= SDHCI_POWER_300;
  832. break;
  833. case MMC_VDD_32_33:
  834. case MMC_VDD_33_34:
  835. pwr |= SDHCI_POWER_330;
  836. break;
  837. default:
  838. BUG();
  839. }
  840. /*
  841. * At least the Marvell CaFe chip gets confused if we set the voltage
  842. * and set turn on power at the same time, so set the voltage first.
  843. */
  844. if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
  845. sdhci_writeb(host, pwr & ~SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
  846. sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
  847. out:
  848. host->power = power;
  849. }
  850. /*****************************************************************************\
  851. * *
  852. * MMC callbacks *
  853. * *
  854. \*****************************************************************************/
  855. static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  856. {
  857. struct sdhci_host *host;
  858. bool present;
  859. unsigned long flags;
  860. host = mmc_priv(mmc);
  861. spin_lock_irqsave(&host->lock, flags);
  862. WARN_ON(host->mrq != NULL);
  863. #ifndef SDHCI_USE_LEDS_CLASS
  864. sdhci_activate_led(host);
  865. #endif
  866. host->mrq = mrq;
  867. /* If polling, assume that the card is always present. */
  868. if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
  869. present = true;
  870. else
  871. present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
  872. SDHCI_CARD_PRESENT;
  873. if (!present || host->flags & SDHCI_DEVICE_DEAD) {
  874. host->mrq->cmd->error = -ENOMEDIUM;
  875. tasklet_schedule(&host->finish_tasklet);
  876. } else
  877. sdhci_send_command(host, mrq->cmd);
  878. mmiowb();
  879. spin_unlock_irqrestore(&host->lock, flags);
  880. }
  881. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  882. {
  883. struct sdhci_host *host;
  884. unsigned long flags;
  885. u8 ctrl;
  886. host = mmc_priv(mmc);
  887. spin_lock_irqsave(&host->lock, flags);
  888. if (host->flags & SDHCI_DEVICE_DEAD)
  889. goto out;
  890. /*
  891. * Reset the chip on each power off.
  892. * Should clear out any weird states.
  893. */
  894. if (ios->power_mode == MMC_POWER_OFF) {
  895. sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
  896. sdhci_reinit(host);
  897. }
  898. sdhci_set_clock(host, ios->clock);
  899. if (ios->power_mode == MMC_POWER_OFF)
  900. sdhci_set_power(host, -1);
  901. else
  902. sdhci_set_power(host, ios->vdd);
  903. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  904. if (ios->bus_width == MMC_BUS_WIDTH_4)
  905. ctrl |= SDHCI_CTRL_4BITBUS;
  906. else
  907. ctrl &= ~SDHCI_CTRL_4BITBUS;
  908. if (ios->timing == MMC_TIMING_SD_HS)
  909. ctrl |= SDHCI_CTRL_HISPD;
  910. else
  911. ctrl &= ~SDHCI_CTRL_HISPD;
  912. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  913. /*
  914. * Some (ENE) controllers go apeshit on some ios operation,
  915. * signalling timeout and CRC errors even on CMD0. Resetting
  916. * it on each ios seems to solve the problem.
  917. */
  918. if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
  919. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  920. out:
  921. mmiowb();
  922. spin_unlock_irqrestore(&host->lock, flags);
  923. }
  924. static int sdhci_get_ro(struct mmc_host *mmc)
  925. {
  926. struct sdhci_host *host;
  927. unsigned long flags;
  928. int present;
  929. host = mmc_priv(mmc);
  930. spin_lock_irqsave(&host->lock, flags);
  931. if (host->flags & SDHCI_DEVICE_DEAD)
  932. present = 0;
  933. else
  934. present = sdhci_readl(host, SDHCI_PRESENT_STATE);
  935. spin_unlock_irqrestore(&host->lock, flags);
  936. if (host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT)
  937. return !!(present & SDHCI_WRITE_PROTECT);
  938. return !(present & SDHCI_WRITE_PROTECT);
  939. }
  940. static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
  941. {
  942. struct sdhci_host *host;
  943. unsigned long flags;
  944. host = mmc_priv(mmc);
  945. spin_lock_irqsave(&host->lock, flags);
  946. if (host->flags & SDHCI_DEVICE_DEAD)
  947. goto out;
  948. if (enable)
  949. sdhci_unmask_irqs(host, SDHCI_INT_CARD_INT);
  950. else
  951. sdhci_mask_irqs(host, SDHCI_INT_CARD_INT);
  952. out:
  953. mmiowb();
  954. spin_unlock_irqrestore(&host->lock, flags);
  955. }
  956. static const struct mmc_host_ops sdhci_ops = {
  957. .request = sdhci_request,
  958. .set_ios = sdhci_set_ios,
  959. .get_ro = sdhci_get_ro,
  960. .enable_sdio_irq = sdhci_enable_sdio_irq,
  961. };
  962. /*****************************************************************************\
  963. * *
  964. * Tasklets *
  965. * *
  966. \*****************************************************************************/
  967. static void sdhci_tasklet_card(unsigned long param)
  968. {
  969. struct sdhci_host *host;
  970. unsigned long flags;
  971. host = (struct sdhci_host*)param;
  972. spin_lock_irqsave(&host->lock, flags);
  973. if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
  974. if (host->mrq) {
  975. printk(KERN_ERR "%s: Card removed during transfer!\n",
  976. mmc_hostname(host->mmc));
  977. printk(KERN_ERR "%s: Resetting controller.\n",
  978. mmc_hostname(host->mmc));
  979. sdhci_reset(host, SDHCI_RESET_CMD);
  980. sdhci_reset(host, SDHCI_RESET_DATA);
  981. host->mrq->cmd->error = -ENOMEDIUM;
  982. tasklet_schedule(&host->finish_tasklet);
  983. }
  984. }
  985. spin_unlock_irqrestore(&host->lock, flags);
  986. mmc_detect_change(host->mmc, msecs_to_jiffies(200));
  987. }
  988. static void sdhci_tasklet_finish(unsigned long param)
  989. {
  990. struct sdhci_host *host;
  991. unsigned long flags;
  992. struct mmc_request *mrq;
  993. host = (struct sdhci_host*)param;
  994. spin_lock_irqsave(&host->lock, flags);
  995. del_timer(&host->timer);
  996. mrq = host->mrq;
  997. /*
  998. * The controller needs a reset of internal state machines
  999. * upon error conditions.
  1000. */
  1001. if (!(host->flags & SDHCI_DEVICE_DEAD) &&
  1002. (mrq->cmd->error ||
  1003. (mrq->data && (mrq->data->error ||
  1004. (mrq->data->stop && mrq->data->stop->error))) ||
  1005. (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) {
  1006. /* Some controllers need this kick or reset won't work here */
  1007. if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
  1008. unsigned int clock;
  1009. /* This is to force an update */
  1010. clock = host->clock;
  1011. host->clock = 0;
  1012. sdhci_set_clock(host, clock);
  1013. }
  1014. /* Spec says we should do both at the same time, but Ricoh
  1015. controllers do not like that. */
  1016. sdhci_reset(host, SDHCI_RESET_CMD);
  1017. sdhci_reset(host, SDHCI_RESET_DATA);
  1018. }
  1019. host->mrq = NULL;
  1020. host->cmd = NULL;
  1021. host->data = NULL;
  1022. #ifndef SDHCI_USE_LEDS_CLASS
  1023. sdhci_deactivate_led(host);
  1024. #endif
  1025. mmiowb();
  1026. spin_unlock_irqrestore(&host->lock, flags);
  1027. mmc_request_done(host->mmc, mrq);
  1028. }
  1029. static void sdhci_timeout_timer(unsigned long data)
  1030. {
  1031. struct sdhci_host *host;
  1032. unsigned long flags;
  1033. host = (struct sdhci_host*)data;
  1034. spin_lock_irqsave(&host->lock, flags);
  1035. if (host->mrq) {
  1036. printk(KERN_ERR "%s: Timeout waiting for hardware "
  1037. "interrupt.\n", mmc_hostname(host->mmc));
  1038. sdhci_dumpregs(host);
  1039. if (host->data) {
  1040. host->data->error = -ETIMEDOUT;
  1041. sdhci_finish_data(host);
  1042. } else {
  1043. if (host->cmd)
  1044. host->cmd->error = -ETIMEDOUT;
  1045. else
  1046. host->mrq->cmd->error = -ETIMEDOUT;
  1047. tasklet_schedule(&host->finish_tasklet);
  1048. }
  1049. }
  1050. mmiowb();
  1051. spin_unlock_irqrestore(&host->lock, flags);
  1052. }
  1053. /*****************************************************************************\
  1054. * *
  1055. * Interrupt handling *
  1056. * *
  1057. \*****************************************************************************/
  1058. static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
  1059. {
  1060. BUG_ON(intmask == 0);
  1061. if (!host->cmd) {
  1062. printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
  1063. "though no command operation was in progress.\n",
  1064. mmc_hostname(host->mmc), (unsigned)intmask);
  1065. sdhci_dumpregs(host);
  1066. return;
  1067. }
  1068. if (intmask & SDHCI_INT_TIMEOUT)
  1069. host->cmd->error = -ETIMEDOUT;
  1070. else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
  1071. SDHCI_INT_INDEX))
  1072. host->cmd->error = -EILSEQ;
  1073. if (host->cmd->error) {
  1074. tasklet_schedule(&host->finish_tasklet);
  1075. return;
  1076. }
  1077. /*
  1078. * The host can send and interrupt when the busy state has
  1079. * ended, allowing us to wait without wasting CPU cycles.
  1080. * Unfortunately this is overloaded on the "data complete"
  1081. * interrupt, so we need to take some care when handling
  1082. * it.
  1083. *
  1084. * Note: The 1.0 specification is a bit ambiguous about this
  1085. * feature so there might be some problems with older
  1086. * controllers.
  1087. */
  1088. if (host->cmd->flags & MMC_RSP_BUSY) {
  1089. if (host->cmd->data)
  1090. DBG("Cannot wait for busy signal when also "
  1091. "doing a data transfer");
  1092. else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ))
  1093. return;
  1094. /* The controller does not support the end-of-busy IRQ,
  1095. * fall through and take the SDHCI_INT_RESPONSE */
  1096. }
  1097. if (intmask & SDHCI_INT_RESPONSE)
  1098. sdhci_finish_command(host);
  1099. }
  1100. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  1101. {
  1102. BUG_ON(intmask == 0);
  1103. if (!host->data) {
  1104. /*
  1105. * The "data complete" interrupt is also used to
  1106. * indicate that a busy state has ended. See comment
  1107. * above in sdhci_cmd_irq().
  1108. */
  1109. if (host->cmd && (host->cmd->flags & MMC_RSP_BUSY)) {
  1110. if (intmask & SDHCI_INT_DATA_END) {
  1111. sdhci_finish_command(host);
  1112. return;
  1113. }
  1114. }
  1115. printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
  1116. "though no data operation was in progress.\n",
  1117. mmc_hostname(host->mmc), (unsigned)intmask);
  1118. sdhci_dumpregs(host);
  1119. return;
  1120. }
  1121. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  1122. host->data->error = -ETIMEDOUT;
  1123. else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
  1124. host->data->error = -EILSEQ;
  1125. else if (intmask & SDHCI_INT_ADMA_ERROR)
  1126. host->data->error = -EIO;
  1127. if (host->data->error)
  1128. sdhci_finish_data(host);
  1129. else {
  1130. if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  1131. sdhci_transfer_pio(host);
  1132. /*
  1133. * We currently don't do anything fancy with DMA
  1134. * boundaries, but as we can't disable the feature
  1135. * we need to at least restart the transfer.
  1136. */
  1137. if (intmask & SDHCI_INT_DMA_END)
  1138. sdhci_writel(host, sdhci_readl(host, SDHCI_DMA_ADDRESS),
  1139. SDHCI_DMA_ADDRESS);
  1140. if (intmask & SDHCI_INT_DATA_END) {
  1141. if (host->cmd) {
  1142. /*
  1143. * Data managed to finish before the
  1144. * command completed. Make sure we do
  1145. * things in the proper order.
  1146. */
  1147. host->data_early = 1;
  1148. } else {
  1149. sdhci_finish_data(host);
  1150. }
  1151. }
  1152. }
  1153. }
  1154. static irqreturn_t sdhci_irq(int irq, void *dev_id)
  1155. {
  1156. irqreturn_t result;
  1157. struct sdhci_host* host = dev_id;
  1158. u32 intmask;
  1159. int cardint = 0;
  1160. spin_lock(&host->lock);
  1161. intmask = sdhci_readl(host, SDHCI_INT_STATUS);
  1162. if (!intmask || intmask == 0xffffffff) {
  1163. result = IRQ_NONE;
  1164. goto out;
  1165. }
  1166. DBG("*** %s got interrupt: 0x%08x\n",
  1167. mmc_hostname(host->mmc), intmask);
  1168. if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) {
  1169. sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT |
  1170. SDHCI_INT_CARD_REMOVE), SDHCI_INT_STATUS);
  1171. tasklet_schedule(&host->card_tasklet);
  1172. }
  1173. intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE);
  1174. if (intmask & SDHCI_INT_CMD_MASK) {
  1175. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  1176. SDHCI_INT_STATUS);
  1177. sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK);
  1178. }
  1179. if (intmask & SDHCI_INT_DATA_MASK) {
  1180. sdhci_writel(host, intmask & SDHCI_INT_DATA_MASK,
  1181. SDHCI_INT_STATUS);
  1182. sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK);
  1183. }
  1184. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  1185. intmask &= ~SDHCI_INT_ERROR;
  1186. if (intmask & SDHCI_INT_BUS_POWER) {
  1187. printk(KERN_ERR "%s: Card is consuming too much power!\n",
  1188. mmc_hostname(host->mmc));
  1189. sdhci_writel(host, SDHCI_INT_BUS_POWER, SDHCI_INT_STATUS);
  1190. }
  1191. intmask &= ~SDHCI_INT_BUS_POWER;
  1192. if (intmask & SDHCI_INT_CARD_INT)
  1193. cardint = 1;
  1194. intmask &= ~SDHCI_INT_CARD_INT;
  1195. if (intmask) {
  1196. printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
  1197. mmc_hostname(host->mmc), intmask);
  1198. sdhci_dumpregs(host);
  1199. sdhci_writel(host, intmask, SDHCI_INT_STATUS);
  1200. }
  1201. result = IRQ_HANDLED;
  1202. mmiowb();
  1203. out:
  1204. spin_unlock(&host->lock);
  1205. /*
  1206. * We have to delay this as it calls back into the driver.
  1207. */
  1208. if (cardint)
  1209. mmc_signal_sdio_irq(host->mmc);
  1210. return result;
  1211. }
  1212. /*****************************************************************************\
  1213. * *
  1214. * Suspend/resume *
  1215. * *
  1216. \*****************************************************************************/
  1217. #ifdef CONFIG_PM
  1218. int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state)
  1219. {
  1220. int ret;
  1221. sdhci_disable_card_detection(host);
  1222. ret = mmc_suspend_host(host->mmc, state);
  1223. if (ret)
  1224. return ret;
  1225. free_irq(host->irq, host);
  1226. return 0;
  1227. }
  1228. EXPORT_SYMBOL_GPL(sdhci_suspend_host);
  1229. int sdhci_resume_host(struct sdhci_host *host)
  1230. {
  1231. int ret;
  1232. if (host->flags & SDHCI_USE_DMA) {
  1233. if (host->ops->enable_dma)
  1234. host->ops->enable_dma(host);
  1235. }
  1236. ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  1237. mmc_hostname(host->mmc), host);
  1238. if (ret)
  1239. return ret;
  1240. sdhci_init(host);
  1241. mmiowb();
  1242. ret = mmc_resume_host(host->mmc);
  1243. if (ret)
  1244. return ret;
  1245. sdhci_enable_card_detection(host);
  1246. return 0;
  1247. }
  1248. EXPORT_SYMBOL_GPL(sdhci_resume_host);
  1249. #endif /* CONFIG_PM */
  1250. /*****************************************************************************\
  1251. * *
  1252. * Device allocation/registration *
  1253. * *
  1254. \*****************************************************************************/
  1255. struct sdhci_host *sdhci_alloc_host(struct device *dev,
  1256. size_t priv_size)
  1257. {
  1258. struct mmc_host *mmc;
  1259. struct sdhci_host *host;
  1260. WARN_ON(dev == NULL);
  1261. mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev);
  1262. if (!mmc)
  1263. return ERR_PTR(-ENOMEM);
  1264. host = mmc_priv(mmc);
  1265. host->mmc = mmc;
  1266. return host;
  1267. }
  1268. EXPORT_SYMBOL_GPL(sdhci_alloc_host);
  1269. int sdhci_add_host(struct sdhci_host *host)
  1270. {
  1271. struct mmc_host *mmc;
  1272. unsigned int caps;
  1273. int ret;
  1274. WARN_ON(host == NULL);
  1275. if (host == NULL)
  1276. return -EINVAL;
  1277. mmc = host->mmc;
  1278. if (debug_quirks)
  1279. host->quirks = debug_quirks;
  1280. sdhci_reset(host, SDHCI_RESET_ALL);
  1281. host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
  1282. host->version = (host->version & SDHCI_SPEC_VER_MASK)
  1283. >> SDHCI_SPEC_VER_SHIFT;
  1284. if (host->version > SDHCI_SPEC_200) {
  1285. printk(KERN_ERR "%s: Unknown controller version (%d). "
  1286. "You may experience problems.\n", mmc_hostname(mmc),
  1287. host->version);
  1288. }
  1289. caps = sdhci_readl(host, SDHCI_CAPABILITIES);
  1290. if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
  1291. host->flags |= SDHCI_USE_DMA;
  1292. else if (!(caps & SDHCI_CAN_DO_DMA))
  1293. DBG("Controller doesn't have DMA capability\n");
  1294. else
  1295. host->flags |= SDHCI_USE_DMA;
  1296. if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
  1297. (host->flags & SDHCI_USE_DMA)) {
  1298. DBG("Disabling DMA as it is marked broken\n");
  1299. host->flags &= ~SDHCI_USE_DMA;
  1300. }
  1301. if (host->flags & SDHCI_USE_DMA) {
  1302. if ((host->version >= SDHCI_SPEC_200) &&
  1303. (caps & SDHCI_CAN_DO_ADMA2))
  1304. host->flags |= SDHCI_USE_ADMA;
  1305. }
  1306. if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) &&
  1307. (host->flags & SDHCI_USE_ADMA)) {
  1308. DBG("Disabling ADMA as it is marked broken\n");
  1309. host->flags &= ~SDHCI_USE_ADMA;
  1310. }
  1311. if (host->flags & SDHCI_USE_DMA) {
  1312. if (host->ops->enable_dma) {
  1313. if (host->ops->enable_dma(host)) {
  1314. printk(KERN_WARNING "%s: No suitable DMA "
  1315. "available. Falling back to PIO.\n",
  1316. mmc_hostname(mmc));
  1317. host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA);
  1318. }
  1319. }
  1320. }
  1321. if (host->flags & SDHCI_USE_ADMA) {
  1322. /*
  1323. * We need to allocate descriptors for all sg entries
  1324. * (128) and potentially one alignment transfer for
  1325. * each of those entries.
  1326. */
  1327. host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL);
  1328. host->align_buffer = kmalloc(128 * 4, GFP_KERNEL);
  1329. if (!host->adma_desc || !host->align_buffer) {
  1330. kfree(host->adma_desc);
  1331. kfree(host->align_buffer);
  1332. printk(KERN_WARNING "%s: Unable to allocate ADMA "
  1333. "buffers. Falling back to standard DMA.\n",
  1334. mmc_hostname(mmc));
  1335. host->flags &= ~SDHCI_USE_ADMA;
  1336. }
  1337. }
  1338. /*
  1339. * If we use DMA, then it's up to the caller to set the DMA
  1340. * mask, but PIO does not need the hw shim so we set a new
  1341. * mask here in that case.
  1342. */
  1343. if (!(host->flags & SDHCI_USE_DMA)) {
  1344. host->dma_mask = DMA_BIT_MASK(64);
  1345. mmc_dev(host->mmc)->dma_mask = &host->dma_mask;
  1346. }
  1347. host->max_clk =
  1348. (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT;
  1349. host->max_clk *= 1000000;
  1350. if (host->max_clk == 0) {
  1351. if (!host->ops->get_max_clock) {
  1352. printk(KERN_ERR
  1353. "%s: Hardware doesn't specify base clock "
  1354. "frequency.\n", mmc_hostname(mmc));
  1355. return -ENODEV;
  1356. }
  1357. host->max_clk = host->ops->get_max_clock(host);
  1358. }
  1359. host->timeout_clk =
  1360. (caps & SDHCI_TIMEOUT_CLK_MASK) >> SDHCI_TIMEOUT_CLK_SHIFT;
  1361. if (host->timeout_clk == 0) {
  1362. if (!host->ops->get_timeout_clock) {
  1363. printk(KERN_ERR
  1364. "%s: Hardware doesn't specify timeout clock "
  1365. "frequency.\n", mmc_hostname(mmc));
  1366. return -ENODEV;
  1367. }
  1368. host->timeout_clk = host->ops->get_timeout_clock(host);
  1369. }
  1370. if (caps & SDHCI_TIMEOUT_CLK_UNIT)
  1371. host->timeout_clk *= 1000;
  1372. /*
  1373. * Set host parameters.
  1374. */
  1375. mmc->ops = &sdhci_ops;
  1376. mmc->f_min = host->max_clk / 256;
  1377. mmc->f_max = host->max_clk;
  1378. mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
  1379. if (caps & SDHCI_CAN_DO_HISPD)
  1380. mmc->caps |= MMC_CAP_SD_HIGHSPEED;
  1381. if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
  1382. mmc->caps |= MMC_CAP_NEEDS_POLL;
  1383. mmc->ocr_avail = 0;
  1384. if (caps & SDHCI_CAN_VDD_330)
  1385. mmc->ocr_avail |= MMC_VDD_32_33|MMC_VDD_33_34;
  1386. if (caps & SDHCI_CAN_VDD_300)
  1387. mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31;
  1388. if (caps & SDHCI_CAN_VDD_180)
  1389. mmc->ocr_avail |= MMC_VDD_165_195;
  1390. if (mmc->ocr_avail == 0) {
  1391. printk(KERN_ERR "%s: Hardware doesn't report any "
  1392. "support voltages.\n", mmc_hostname(mmc));
  1393. return -ENODEV;
  1394. }
  1395. spin_lock_init(&host->lock);
  1396. /*
  1397. * Maximum number of segments. Depends on if the hardware
  1398. * can do scatter/gather or not.
  1399. */
  1400. if (host->flags & SDHCI_USE_ADMA)
  1401. mmc->max_hw_segs = 128;
  1402. else if (host->flags & SDHCI_USE_DMA)
  1403. mmc->max_hw_segs = 1;
  1404. else /* PIO */
  1405. mmc->max_hw_segs = 128;
  1406. mmc->max_phys_segs = 128;
  1407. /*
  1408. * Maximum number of sectors in one transfer. Limited by DMA boundary
  1409. * size (512KiB).
  1410. */
  1411. mmc->max_req_size = 524288;
  1412. /*
  1413. * Maximum segment size. Could be one segment with the maximum number
  1414. * of bytes. When doing hardware scatter/gather, each entry cannot
  1415. * be larger than 64 KiB though.
  1416. */
  1417. if (host->flags & SDHCI_USE_ADMA)
  1418. mmc->max_seg_size = 65536;
  1419. else
  1420. mmc->max_seg_size = mmc->max_req_size;
  1421. /*
  1422. * Maximum block size. This varies from controller to controller and
  1423. * is specified in the capabilities register.
  1424. */
  1425. if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) {
  1426. mmc->max_blk_size = 2;
  1427. } else {
  1428. mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >>
  1429. SDHCI_MAX_BLOCK_SHIFT;
  1430. if (mmc->max_blk_size >= 3) {
  1431. printk(KERN_WARNING "%s: Invalid maximum block size, "
  1432. "assuming 512 bytes\n", mmc_hostname(mmc));
  1433. mmc->max_blk_size = 0;
  1434. }
  1435. }
  1436. mmc->max_blk_size = 512 << mmc->max_blk_size;
  1437. /*
  1438. * Maximum block count.
  1439. */
  1440. mmc->max_blk_count = 65535;
  1441. /*
  1442. * Init tasklets.
  1443. */
  1444. tasklet_init(&host->card_tasklet,
  1445. sdhci_tasklet_card, (unsigned long)host);
  1446. tasklet_init(&host->finish_tasklet,
  1447. sdhci_tasklet_finish, (unsigned long)host);
  1448. setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
  1449. ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  1450. mmc_hostname(mmc), host);
  1451. if (ret)
  1452. goto untasklet;
  1453. sdhci_init(host);
  1454. #ifdef CONFIG_MMC_DEBUG
  1455. sdhci_dumpregs(host);
  1456. #endif
  1457. #ifdef SDHCI_USE_LEDS_CLASS
  1458. snprintf(host->led_name, sizeof(host->led_name),
  1459. "%s::", mmc_hostname(mmc));
  1460. host->led.name = host->led_name;
  1461. host->led.brightness = LED_OFF;
  1462. host->led.default_trigger = mmc_hostname(mmc);
  1463. host->led.brightness_set = sdhci_led_control;
  1464. ret = led_classdev_register(mmc_dev(mmc), &host->led);
  1465. if (ret)
  1466. goto reset;
  1467. #endif
  1468. mmiowb();
  1469. mmc_add_host(mmc);
  1470. printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n",
  1471. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  1472. (host->flags & SDHCI_USE_ADMA)?"A":"",
  1473. (host->flags & SDHCI_USE_DMA)?"DMA":"PIO");
  1474. sdhci_enable_card_detection(host);
  1475. return 0;
  1476. #ifdef SDHCI_USE_LEDS_CLASS
  1477. reset:
  1478. sdhci_reset(host, SDHCI_RESET_ALL);
  1479. free_irq(host->irq, host);
  1480. #endif
  1481. untasklet:
  1482. tasklet_kill(&host->card_tasklet);
  1483. tasklet_kill(&host->finish_tasklet);
  1484. return ret;
  1485. }
  1486. EXPORT_SYMBOL_GPL(sdhci_add_host);
  1487. void sdhci_remove_host(struct sdhci_host *host, int dead)
  1488. {
  1489. unsigned long flags;
  1490. if (dead) {
  1491. spin_lock_irqsave(&host->lock, flags);
  1492. host->flags |= SDHCI_DEVICE_DEAD;
  1493. if (host->mrq) {
  1494. printk(KERN_ERR "%s: Controller removed during "
  1495. " transfer!\n", mmc_hostname(host->mmc));
  1496. host->mrq->cmd->error = -ENOMEDIUM;
  1497. tasklet_schedule(&host->finish_tasklet);
  1498. }
  1499. spin_unlock_irqrestore(&host->lock, flags);
  1500. }
  1501. sdhci_disable_card_detection(host);
  1502. mmc_remove_host(host->mmc);
  1503. #ifdef SDHCI_USE_LEDS_CLASS
  1504. led_classdev_unregister(&host->led);
  1505. #endif
  1506. if (!dead)
  1507. sdhci_reset(host, SDHCI_RESET_ALL);
  1508. free_irq(host->irq, host);
  1509. del_timer_sync(&host->timer);
  1510. tasklet_kill(&host->card_tasklet);
  1511. tasklet_kill(&host->finish_tasklet);
  1512. kfree(host->adma_desc);
  1513. kfree(host->align_buffer);
  1514. host->adma_desc = NULL;
  1515. host->align_buffer = NULL;
  1516. }
  1517. EXPORT_SYMBOL_GPL(sdhci_remove_host);
  1518. void sdhci_free_host(struct sdhci_host *host)
  1519. {
  1520. mmc_free_host(host->mmc);
  1521. }
  1522. EXPORT_SYMBOL_GPL(sdhci_free_host);
  1523. /*****************************************************************************\
  1524. * *
  1525. * Driver init/exit *
  1526. * *
  1527. \*****************************************************************************/
  1528. static int __init sdhci_drv_init(void)
  1529. {
  1530. printk(KERN_INFO DRIVER_NAME
  1531. ": Secure Digital Host Controller Interface driver\n");
  1532. printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
  1533. return 0;
  1534. }
  1535. static void __exit sdhci_drv_exit(void)
  1536. {
  1537. }
  1538. module_init(sdhci_drv_init);
  1539. module_exit(sdhci_drv_exit);
  1540. module_param(debug_quirks, uint, 0444);
  1541. MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
  1542. MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
  1543. MODULE_LICENSE("GPL");
  1544. MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");