sdhci-pci.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface
  2. *
  3. * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * Thanks to the following companies for their support:
  11. *
  12. * - JMicron (hardware and technical support)
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/highmem.h>
  16. #include <linux/pci.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/mmc/host.h>
  19. #include <asm/scatterlist.h>
  20. #include <asm/io.h>
  21. #include "sdhci.h"
  22. /*
  23. * PCI registers
  24. */
  25. #define PCI_SDHCI_IFPIO 0x00
  26. #define PCI_SDHCI_IFDMA 0x01
  27. #define PCI_SDHCI_IFVENDOR 0x02
  28. #define PCI_SLOT_INFO 0x40 /* 8 bits */
  29. #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
  30. #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
  31. #define MAX_SLOTS 8
  32. struct sdhci_pci_chip;
  33. struct sdhci_pci_slot;
  34. struct sdhci_pci_fixes {
  35. unsigned int quirks;
  36. int (*probe)(struct sdhci_pci_chip*);
  37. int (*probe_slot)(struct sdhci_pci_slot*);
  38. void (*remove_slot)(struct sdhci_pci_slot*, int);
  39. int (*suspend)(struct sdhci_pci_chip*,
  40. pm_message_t);
  41. int (*resume)(struct sdhci_pci_chip*);
  42. };
  43. struct sdhci_pci_slot {
  44. struct sdhci_pci_chip *chip;
  45. struct sdhci_host *host;
  46. int pci_bar;
  47. };
  48. struct sdhci_pci_chip {
  49. struct pci_dev *pdev;
  50. unsigned int quirks;
  51. const struct sdhci_pci_fixes *fixes;
  52. int num_slots; /* Slots on controller */
  53. struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
  54. };
  55. /*****************************************************************************\
  56. * *
  57. * Hardware specific quirk handling *
  58. * *
  59. \*****************************************************************************/
  60. static int ricoh_probe(struct sdhci_pci_chip *chip)
  61. {
  62. if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
  63. chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET;
  64. if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)
  65. chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
  66. return 0;
  67. }
  68. static const struct sdhci_pci_fixes sdhci_ricoh = {
  69. .probe = ricoh_probe,
  70. .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR,
  71. };
  72. static const struct sdhci_pci_fixes sdhci_ene_712 = {
  73. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  74. SDHCI_QUIRK_BROKEN_DMA,
  75. };
  76. static const struct sdhci_pci_fixes sdhci_ene_714 = {
  77. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  78. SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
  79. SDHCI_QUIRK_BROKEN_DMA,
  80. };
  81. static const struct sdhci_pci_fixes sdhci_cafe = {
  82. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
  83. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
  84. };
  85. static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
  86. {
  87. u8 scratch;
  88. int ret;
  89. ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
  90. if (ret)
  91. return ret;
  92. /*
  93. * Turn PMOS on [bit 0], set over current detection to 2.4 V
  94. * [bit 1:2] and enable over current debouncing [bit 6].
  95. */
  96. if (on)
  97. scratch |= 0x47;
  98. else
  99. scratch &= ~0x47;
  100. ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
  101. if (ret)
  102. return ret;
  103. return 0;
  104. }
  105. static int jmicron_probe(struct sdhci_pci_chip *chip)
  106. {
  107. int ret;
  108. if (chip->pdev->revision == 0) {
  109. chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
  110. SDHCI_QUIRK_32BIT_DMA_SIZE |
  111. SDHCI_QUIRK_32BIT_ADMA_SIZE |
  112. SDHCI_QUIRK_RESET_AFTER_REQUEST;
  113. }
  114. /*
  115. * JMicron chips can have two interfaces to the same hardware
  116. * in order to work around limitations in Microsoft's driver.
  117. * We need to make sure we only bind to one of them.
  118. *
  119. * This code assumes two things:
  120. *
  121. * 1. The PCI code adds subfunctions in order.
  122. *
  123. * 2. The MMC interface has a lower subfunction number
  124. * than the SD interface.
  125. */
  126. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) {
  127. struct pci_dev *sd_dev;
  128. sd_dev = NULL;
  129. while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
  130. PCI_DEVICE_ID_JMICRON_JMB38X_MMC, sd_dev)) != NULL) {
  131. if ((PCI_SLOT(chip->pdev->devfn) ==
  132. PCI_SLOT(sd_dev->devfn)) &&
  133. (chip->pdev->bus == sd_dev->bus))
  134. break;
  135. }
  136. if (sd_dev) {
  137. pci_dev_put(sd_dev);
  138. dev_info(&chip->pdev->dev, "Refusing to bind to "
  139. "secondary interface.\n");
  140. return -ENODEV;
  141. }
  142. }
  143. /*
  144. * JMicron chips need a bit of a nudge to enable the power
  145. * output pins.
  146. */
  147. ret = jmicron_pmos(chip, 1);
  148. if (ret) {
  149. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  150. return ret;
  151. }
  152. return 0;
  153. }
  154. static void jmicron_enable_mmc(struct sdhci_host *host, int on)
  155. {
  156. u8 scratch;
  157. scratch = readb(host->ioaddr + 0xC0);
  158. if (on)
  159. scratch |= 0x01;
  160. else
  161. scratch &= ~0x01;
  162. writeb(scratch, host->ioaddr + 0xC0);
  163. }
  164. static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
  165. {
  166. if (slot->chip->pdev->revision == 0) {
  167. u16 version;
  168. version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
  169. version = (version & SDHCI_VENDOR_VER_MASK) >>
  170. SDHCI_VENDOR_VER_SHIFT;
  171. /*
  172. * Older versions of the chip have lots of nasty glitches
  173. * in the ADMA engine. It's best just to avoid it
  174. * completely.
  175. */
  176. if (version < 0xAC)
  177. slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
  178. }
  179. /*
  180. * The secondary interface requires a bit set to get the
  181. * interrupts.
  182. */
  183. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
  184. jmicron_enable_mmc(slot->host, 1);
  185. return 0;
  186. }
  187. static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
  188. {
  189. if (dead)
  190. return;
  191. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC)
  192. jmicron_enable_mmc(slot->host, 0);
  193. }
  194. static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state)
  195. {
  196. int i;
  197. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
  198. for (i = 0;i < chip->num_slots;i++)
  199. jmicron_enable_mmc(chip->slots[i]->host, 0);
  200. }
  201. return 0;
  202. }
  203. static int jmicron_resume(struct sdhci_pci_chip *chip)
  204. {
  205. int ret, i;
  206. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) {
  207. for (i = 0;i < chip->num_slots;i++)
  208. jmicron_enable_mmc(chip->slots[i]->host, 1);
  209. }
  210. ret = jmicron_pmos(chip, 1);
  211. if (ret) {
  212. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  213. return ret;
  214. }
  215. return 0;
  216. }
  217. static const struct sdhci_pci_fixes sdhci_jmicron = {
  218. .probe = jmicron_probe,
  219. .probe_slot = jmicron_probe_slot,
  220. .remove_slot = jmicron_remove_slot,
  221. .suspend = jmicron_suspend,
  222. .resume = jmicron_resume,
  223. };
  224. static const struct pci_device_id pci_ids[] __devinitdata = {
  225. {
  226. .vendor = PCI_VENDOR_ID_RICOH,
  227. .device = PCI_DEVICE_ID_RICOH_R5C822,
  228. .subvendor = PCI_ANY_ID,
  229. .subdevice = PCI_ANY_ID,
  230. .driver_data = (kernel_ulong_t)&sdhci_ricoh,
  231. },
  232. {
  233. .vendor = PCI_VENDOR_ID_ENE,
  234. .device = PCI_DEVICE_ID_ENE_CB712_SD,
  235. .subvendor = PCI_ANY_ID,
  236. .subdevice = PCI_ANY_ID,
  237. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  238. },
  239. {
  240. .vendor = PCI_VENDOR_ID_ENE,
  241. .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
  242. .subvendor = PCI_ANY_ID,
  243. .subdevice = PCI_ANY_ID,
  244. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  245. },
  246. {
  247. .vendor = PCI_VENDOR_ID_ENE,
  248. .device = PCI_DEVICE_ID_ENE_CB714_SD,
  249. .subvendor = PCI_ANY_ID,
  250. .subdevice = PCI_ANY_ID,
  251. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  252. },
  253. {
  254. .vendor = PCI_VENDOR_ID_ENE,
  255. .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
  256. .subvendor = PCI_ANY_ID,
  257. .subdevice = PCI_ANY_ID,
  258. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  259. },
  260. {
  261. .vendor = PCI_VENDOR_ID_MARVELL,
  262. .device = PCI_DEVICE_ID_MARVELL_CAFE_SD,
  263. .subvendor = PCI_ANY_ID,
  264. .subdevice = PCI_ANY_ID,
  265. .driver_data = (kernel_ulong_t)&sdhci_cafe,
  266. },
  267. {
  268. .vendor = PCI_VENDOR_ID_JMICRON,
  269. .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
  270. .subvendor = PCI_ANY_ID,
  271. .subdevice = PCI_ANY_ID,
  272. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  273. },
  274. {
  275. .vendor = PCI_VENDOR_ID_JMICRON,
  276. .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
  277. .subvendor = PCI_ANY_ID,
  278. .subdevice = PCI_ANY_ID,
  279. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  280. },
  281. { /* Generic SD host controller */
  282. PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
  283. },
  284. { /* end: all zeroes */ },
  285. };
  286. MODULE_DEVICE_TABLE(pci, pci_ids);
  287. /*****************************************************************************\
  288. * *
  289. * SDHCI core callbacks *
  290. * *
  291. \*****************************************************************************/
  292. static int sdhci_pci_enable_dma(struct sdhci_host *host)
  293. {
  294. struct sdhci_pci_slot *slot;
  295. struct pci_dev *pdev;
  296. int ret;
  297. slot = sdhci_priv(host);
  298. pdev = slot->chip->pdev;
  299. if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
  300. ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
  301. (host->flags & SDHCI_USE_DMA)) {
  302. dev_warn(&pdev->dev, "Will use DMA mode even though HW "
  303. "doesn't fully claim to support it.\n");
  304. }
  305. ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  306. if (ret)
  307. return ret;
  308. pci_set_master(pdev);
  309. return 0;
  310. }
  311. static struct sdhci_ops sdhci_pci_ops = {
  312. .enable_dma = sdhci_pci_enable_dma,
  313. };
  314. /*****************************************************************************\
  315. * *
  316. * Suspend/resume *
  317. * *
  318. \*****************************************************************************/
  319. #ifdef CONFIG_PM
  320. static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
  321. {
  322. struct sdhci_pci_chip *chip;
  323. struct sdhci_pci_slot *slot;
  324. int i, ret;
  325. chip = pci_get_drvdata(pdev);
  326. if (!chip)
  327. return 0;
  328. for (i = 0;i < chip->num_slots;i++) {
  329. slot = chip->slots[i];
  330. if (!slot)
  331. continue;
  332. ret = sdhci_suspend_host(slot->host, state);
  333. if (ret) {
  334. for (i--;i >= 0;i--)
  335. sdhci_resume_host(chip->slots[i]->host);
  336. return ret;
  337. }
  338. }
  339. if (chip->fixes && chip->fixes->suspend) {
  340. ret = chip->fixes->suspend(chip, state);
  341. if (ret) {
  342. for (i = chip->num_slots - 1;i >= 0;i--)
  343. sdhci_resume_host(chip->slots[i]->host);
  344. return ret;
  345. }
  346. }
  347. pci_save_state(pdev);
  348. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  349. pci_disable_device(pdev);
  350. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  351. return 0;
  352. }
  353. static int sdhci_pci_resume (struct pci_dev *pdev)
  354. {
  355. struct sdhci_pci_chip *chip;
  356. struct sdhci_pci_slot *slot;
  357. int i, ret;
  358. chip = pci_get_drvdata(pdev);
  359. if (!chip)
  360. return 0;
  361. pci_set_power_state(pdev, PCI_D0);
  362. pci_restore_state(pdev);
  363. ret = pci_enable_device(pdev);
  364. if (ret)
  365. return ret;
  366. if (chip->fixes && chip->fixes->resume) {
  367. ret = chip->fixes->resume(chip);
  368. if (ret)
  369. return ret;
  370. }
  371. for (i = 0;i < chip->num_slots;i++) {
  372. slot = chip->slots[i];
  373. if (!slot)
  374. continue;
  375. ret = sdhci_resume_host(slot->host);
  376. if (ret)
  377. return ret;
  378. }
  379. return 0;
  380. }
  381. #else /* CONFIG_PM */
  382. #define sdhci_pci_suspend NULL
  383. #define sdhci_pci_resume NULL
  384. #endif /* CONFIG_PM */
  385. /*****************************************************************************\
  386. * *
  387. * Device probing/removal *
  388. * *
  389. \*****************************************************************************/
  390. static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
  391. struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
  392. {
  393. struct sdhci_pci_slot *slot;
  394. struct sdhci_host *host;
  395. resource_size_t addr;
  396. int ret;
  397. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  398. dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
  399. return ERR_PTR(-ENODEV);
  400. }
  401. if (pci_resource_len(pdev, bar) != 0x100) {
  402. dev_err(&pdev->dev, "Invalid iomem size. You may "
  403. "experience problems.\n");
  404. }
  405. if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  406. dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
  407. return ERR_PTR(-ENODEV);
  408. }
  409. if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
  410. dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
  411. return ERR_PTR(-ENODEV);
  412. }
  413. host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
  414. if (IS_ERR(host)) {
  415. ret = PTR_ERR(host);
  416. goto unmap;
  417. }
  418. slot = sdhci_priv(host);
  419. slot->chip = chip;
  420. slot->host = host;
  421. slot->pci_bar = bar;
  422. host->hw_name = "PCI";
  423. host->ops = &sdhci_pci_ops;
  424. host->quirks = chip->quirks;
  425. host->irq = pdev->irq;
  426. ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
  427. if (ret) {
  428. dev_err(&pdev->dev, "cannot request region\n");
  429. return ERR_PTR(ret);
  430. }
  431. addr = pci_resource_start(pdev, bar);
  432. host->ioaddr = ioremap_nocache(addr, pci_resource_len(pdev, bar));
  433. if (!host->ioaddr) {
  434. dev_err(&pdev->dev, "failed to remap registers\n");
  435. goto release;
  436. }
  437. if (chip->fixes && chip->fixes->probe_slot) {
  438. ret = chip->fixes->probe_slot(slot);
  439. if (ret)
  440. goto unmap;
  441. }
  442. ret = sdhci_add_host(host);
  443. if (ret)
  444. goto remove;
  445. return slot;
  446. remove:
  447. if (chip->fixes && chip->fixes->remove_slot)
  448. chip->fixes->remove_slot(slot, 0);
  449. unmap:
  450. iounmap(host->ioaddr);
  451. release:
  452. pci_release_region(pdev, bar);
  453. sdhci_free_host(host);
  454. return ERR_PTR(ret);
  455. }
  456. static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
  457. {
  458. int dead;
  459. u32 scratch;
  460. dead = 0;
  461. scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
  462. if (scratch == (u32)-1)
  463. dead = 1;
  464. sdhci_remove_host(slot->host, dead);
  465. if (slot->chip->fixes && slot->chip->fixes->remove_slot)
  466. slot->chip->fixes->remove_slot(slot, dead);
  467. pci_release_region(slot->chip->pdev, slot->pci_bar);
  468. sdhci_free_host(slot->host);
  469. }
  470. static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
  471. const struct pci_device_id *ent)
  472. {
  473. struct sdhci_pci_chip *chip;
  474. struct sdhci_pci_slot *slot;
  475. u8 slots, rev, first_bar;
  476. int ret, i;
  477. BUG_ON(pdev == NULL);
  478. BUG_ON(ent == NULL);
  479. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
  480. dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
  481. (int)pdev->vendor, (int)pdev->device, (int)rev);
  482. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
  483. if (ret)
  484. return ret;
  485. slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
  486. dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
  487. if (slots == 0)
  488. return -ENODEV;
  489. BUG_ON(slots > MAX_SLOTS);
  490. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
  491. if (ret)
  492. return ret;
  493. first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
  494. if (first_bar > 5) {
  495. dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
  496. return -ENODEV;
  497. }
  498. ret = pci_enable_device(pdev);
  499. if (ret)
  500. return ret;
  501. chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
  502. if (!chip) {
  503. ret = -ENOMEM;
  504. goto err;
  505. }
  506. chip->pdev = pdev;
  507. chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data;
  508. if (chip->fixes)
  509. chip->quirks = chip->fixes->quirks;
  510. chip->num_slots = slots;
  511. pci_set_drvdata(pdev, chip);
  512. if (chip->fixes && chip->fixes->probe) {
  513. ret = chip->fixes->probe(chip);
  514. if (ret)
  515. goto free;
  516. }
  517. for (i = 0;i < slots;i++) {
  518. slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
  519. if (IS_ERR(slot)) {
  520. for (i--;i >= 0;i--)
  521. sdhci_pci_remove_slot(chip->slots[i]);
  522. ret = PTR_ERR(slot);
  523. goto free;
  524. }
  525. chip->slots[i] = slot;
  526. }
  527. return 0;
  528. free:
  529. pci_set_drvdata(pdev, NULL);
  530. kfree(chip);
  531. err:
  532. pci_disable_device(pdev);
  533. return ret;
  534. }
  535. static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
  536. {
  537. int i;
  538. struct sdhci_pci_chip *chip;
  539. chip = pci_get_drvdata(pdev);
  540. if (chip) {
  541. for (i = 0;i < chip->num_slots; i++)
  542. sdhci_pci_remove_slot(chip->slots[i]);
  543. pci_set_drvdata(pdev, NULL);
  544. kfree(chip);
  545. }
  546. pci_disable_device(pdev);
  547. }
  548. static struct pci_driver sdhci_driver = {
  549. .name = "sdhci-pci",
  550. .id_table = pci_ids,
  551. .probe = sdhci_pci_probe,
  552. .remove = __devexit_p(sdhci_pci_remove),
  553. .suspend = sdhci_pci_suspend,
  554. .resume = sdhci_pci_resume,
  555. };
  556. /*****************************************************************************\
  557. * *
  558. * Driver init/exit *
  559. * *
  560. \*****************************************************************************/
  561. static int __init sdhci_drv_init(void)
  562. {
  563. return pci_register_driver(&sdhci_driver);
  564. }
  565. static void __exit sdhci_drv_exit(void)
  566. {
  567. pci_unregister_driver(&sdhci_driver);
  568. }
  569. module_init(sdhci_drv_init);
  570. module_exit(sdhci_drv_exit);
  571. MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
  572. MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
  573. MODULE_LICENSE("GPL");