sdhci-pci.c 17 KB

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