sdhci-pci.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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/slab.h>
  19. #include <linux/device.h>
  20. #include <linux/mmc/host.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/io.h>
  23. #include <linux/gpio.h>
  24. #include <linux/sfi.h>
  25. #include "sdhci.h"
  26. /*
  27. * PCI registers
  28. */
  29. #define PCI_SDHCI_IFPIO 0x00
  30. #define PCI_SDHCI_IFDMA 0x01
  31. #define PCI_SDHCI_IFVENDOR 0x02
  32. #define PCI_SLOT_INFO 0x40 /* 8 bits */
  33. #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7)
  34. #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07
  35. #define MAX_SLOTS 8
  36. struct sdhci_pci_chip;
  37. struct sdhci_pci_slot;
  38. struct sdhci_pci_fixes {
  39. unsigned int quirks;
  40. int (*probe) (struct sdhci_pci_chip *);
  41. int (*probe_slot) (struct sdhci_pci_slot *);
  42. void (*remove_slot) (struct sdhci_pci_slot *, int);
  43. int (*suspend) (struct sdhci_pci_chip *,
  44. pm_message_t);
  45. int (*resume) (struct sdhci_pci_chip *);
  46. };
  47. struct sdhci_pci_slot {
  48. struct sdhci_pci_chip *chip;
  49. struct sdhci_host *host;
  50. int pci_bar;
  51. int rst_n_gpio;
  52. };
  53. struct sdhci_pci_chip {
  54. struct pci_dev *pdev;
  55. unsigned int quirks;
  56. const struct sdhci_pci_fixes *fixes;
  57. int num_slots; /* Slots on controller */
  58. struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */
  59. };
  60. /*****************************************************************************\
  61. * *
  62. * Hardware specific quirk handling *
  63. * *
  64. \*****************************************************************************/
  65. static int ricoh_probe(struct sdhci_pci_chip *chip)
  66. {
  67. if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
  68. chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
  69. chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
  70. return 0;
  71. }
  72. static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
  73. {
  74. slot->host->caps =
  75. ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
  76. & SDHCI_TIMEOUT_CLK_MASK) |
  77. ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
  78. & SDHCI_CLOCK_BASE_MASK) |
  79. SDHCI_TIMEOUT_CLK_UNIT |
  80. SDHCI_CAN_VDD_330 |
  81. SDHCI_CAN_DO_SDMA;
  82. return 0;
  83. }
  84. static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
  85. {
  86. /* Apply a delay to allow controller to settle */
  87. /* Otherwise it becomes confused if card state changed
  88. during suspend */
  89. msleep(500);
  90. return 0;
  91. }
  92. static const struct sdhci_pci_fixes sdhci_ricoh = {
  93. .probe = ricoh_probe,
  94. .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
  95. SDHCI_QUIRK_FORCE_DMA |
  96. SDHCI_QUIRK_CLOCK_BEFORE_RESET,
  97. };
  98. static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
  99. .probe_slot = ricoh_mmc_probe_slot,
  100. .resume = ricoh_mmc_resume,
  101. .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
  102. SDHCI_QUIRK_CLOCK_BEFORE_RESET |
  103. SDHCI_QUIRK_NO_CARD_NO_RESET |
  104. SDHCI_QUIRK_MISSING_CAPS
  105. };
  106. static const struct sdhci_pci_fixes sdhci_ene_712 = {
  107. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  108. SDHCI_QUIRK_BROKEN_DMA,
  109. };
  110. static const struct sdhci_pci_fixes sdhci_ene_714 = {
  111. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  112. SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
  113. SDHCI_QUIRK_BROKEN_DMA,
  114. };
  115. static const struct sdhci_pci_fixes sdhci_cafe = {
  116. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
  117. SDHCI_QUIRK_NO_BUSY_IRQ |
  118. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
  119. };
  120. static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
  121. {
  122. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  123. return 0;
  124. }
  125. /*
  126. * ADMA operation is disabled for Moorestown platform due to
  127. * hardware bugs.
  128. */
  129. static int mrst_hc_probe(struct sdhci_pci_chip *chip)
  130. {
  131. /*
  132. * slots number is fixed here for MRST as SDIO3/5 are never used and
  133. * have hardware bugs.
  134. */
  135. chip->num_slots = 1;
  136. return 0;
  137. }
  138. /* Medfield eMMC hardware reset GPIOs */
  139. static int mfd_emmc0_rst_gpio = -EINVAL;
  140. static int mfd_emmc1_rst_gpio = -EINVAL;
  141. static int mfd_emmc_gpio_parse(struct sfi_table_header *table)
  142. {
  143. struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
  144. struct sfi_gpio_table_entry *entry;
  145. int i, num;
  146. num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
  147. entry = (struct sfi_gpio_table_entry *)sb->pentry;
  148. for (i = 0; i < num; i++, entry++) {
  149. if (!strncmp(entry->pin_name, "emmc0_rst", SFI_NAME_LEN))
  150. mfd_emmc0_rst_gpio = entry->pin_no;
  151. else if (!strncmp(entry->pin_name, "emmc1_rst", SFI_NAME_LEN))
  152. mfd_emmc1_rst_gpio = entry->pin_no;
  153. }
  154. return 0;
  155. }
  156. static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
  157. {
  158. const char *name = NULL;
  159. int gpio = -EINVAL;
  160. sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, mfd_emmc_gpio_parse);
  161. switch (slot->chip->pdev->device) {
  162. case PCI_DEVICE_ID_INTEL_MFD_EMMC0:
  163. gpio = mfd_emmc0_rst_gpio;
  164. name = "eMMC0_reset";
  165. break;
  166. case PCI_DEVICE_ID_INTEL_MFD_EMMC1:
  167. gpio = mfd_emmc1_rst_gpio;
  168. name = "eMMC1_reset";
  169. break;
  170. }
  171. if (!gpio_request(gpio, name)) {
  172. gpio_direction_output(gpio, 1);
  173. slot->rst_n_gpio = gpio;
  174. slot->host->mmc->caps |= MMC_CAP_HW_RESET;
  175. }
  176. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  177. slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC;
  178. return 0;
  179. }
  180. static void mfd_emmc_remove_slot(struct sdhci_pci_slot *slot, int dead)
  181. {
  182. gpio_free(slot->rst_n_gpio);
  183. }
  184. static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
  185. .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
  186. .probe_slot = mrst_hc_probe_slot,
  187. };
  188. static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
  189. .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
  190. .probe = mrst_hc_probe,
  191. };
  192. static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
  193. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  194. };
  195. static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
  196. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  197. };
  198. static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
  199. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  200. .probe_slot = mfd_emmc_probe_slot,
  201. .remove_slot = mfd_emmc_remove_slot,
  202. };
  203. /* O2Micro extra registers */
  204. #define O2_SD_LOCK_WP 0xD3
  205. #define O2_SD_MULTI_VCC3V 0xEE
  206. #define O2_SD_CLKREQ 0xEC
  207. #define O2_SD_CAPS 0xE0
  208. #define O2_SD_ADMA1 0xE2
  209. #define O2_SD_ADMA2 0xE7
  210. #define O2_SD_INF_MOD 0xF1
  211. static int o2_probe(struct sdhci_pci_chip *chip)
  212. {
  213. int ret;
  214. u8 scratch;
  215. switch (chip->pdev->device) {
  216. case PCI_DEVICE_ID_O2_8220:
  217. case PCI_DEVICE_ID_O2_8221:
  218. case PCI_DEVICE_ID_O2_8320:
  219. case PCI_DEVICE_ID_O2_8321:
  220. /* This extra setup is required due to broken ADMA. */
  221. ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
  222. if (ret)
  223. return ret;
  224. scratch &= 0x7f;
  225. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  226. /* Set Multi 3 to VCC3V# */
  227. pci_write_config_byte(chip->pdev, O2_SD_MULTI_VCC3V, 0x08);
  228. /* Disable CLK_REQ# support after media DET */
  229. ret = pci_read_config_byte(chip->pdev, O2_SD_CLKREQ, &scratch);
  230. if (ret)
  231. return ret;
  232. scratch |= 0x20;
  233. pci_write_config_byte(chip->pdev, O2_SD_CLKREQ, scratch);
  234. /* Choose capabilities, enable SDMA. We have to write 0x01
  235. * to the capabilities register first to unlock it.
  236. */
  237. ret = pci_read_config_byte(chip->pdev, O2_SD_CAPS, &scratch);
  238. if (ret)
  239. return ret;
  240. scratch |= 0x01;
  241. pci_write_config_byte(chip->pdev, O2_SD_CAPS, scratch);
  242. pci_write_config_byte(chip->pdev, O2_SD_CAPS, 0x73);
  243. /* Disable ADMA1/2 */
  244. pci_write_config_byte(chip->pdev, O2_SD_ADMA1, 0x39);
  245. pci_write_config_byte(chip->pdev, O2_SD_ADMA2, 0x08);
  246. /* Disable the infinite transfer mode */
  247. ret = pci_read_config_byte(chip->pdev, O2_SD_INF_MOD, &scratch);
  248. if (ret)
  249. return ret;
  250. scratch |= 0x08;
  251. pci_write_config_byte(chip->pdev, O2_SD_INF_MOD, scratch);
  252. /* Lock WP */
  253. ret = pci_read_config_byte(chip->pdev, O2_SD_LOCK_WP, &scratch);
  254. if (ret)
  255. return ret;
  256. scratch |= 0x80;
  257. pci_write_config_byte(chip->pdev, O2_SD_LOCK_WP, scratch);
  258. }
  259. return 0;
  260. }
  261. static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
  262. {
  263. u8 scratch;
  264. int ret;
  265. ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
  266. if (ret)
  267. return ret;
  268. /*
  269. * Turn PMOS on [bit 0], set over current detection to 2.4 V
  270. * [bit 1:2] and enable over current debouncing [bit 6].
  271. */
  272. if (on)
  273. scratch |= 0x47;
  274. else
  275. scratch &= ~0x47;
  276. ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
  277. if (ret)
  278. return ret;
  279. return 0;
  280. }
  281. static int jmicron_probe(struct sdhci_pci_chip *chip)
  282. {
  283. int ret;
  284. u16 mmcdev = 0;
  285. if (chip->pdev->revision == 0) {
  286. chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
  287. SDHCI_QUIRK_32BIT_DMA_SIZE |
  288. SDHCI_QUIRK_32BIT_ADMA_SIZE |
  289. SDHCI_QUIRK_RESET_AFTER_REQUEST |
  290. SDHCI_QUIRK_BROKEN_SMALL_PIO;
  291. }
  292. /*
  293. * JMicron chips can have two interfaces to the same hardware
  294. * in order to work around limitations in Microsoft's driver.
  295. * We need to make sure we only bind to one of them.
  296. *
  297. * This code assumes two things:
  298. *
  299. * 1. The PCI code adds subfunctions in order.
  300. *
  301. * 2. The MMC interface has a lower subfunction number
  302. * than the SD interface.
  303. */
  304. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
  305. mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
  306. else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
  307. mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
  308. if (mmcdev) {
  309. struct pci_dev *sd_dev;
  310. sd_dev = NULL;
  311. while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
  312. mmcdev, sd_dev)) != NULL) {
  313. if ((PCI_SLOT(chip->pdev->devfn) ==
  314. PCI_SLOT(sd_dev->devfn)) &&
  315. (chip->pdev->bus == sd_dev->bus))
  316. break;
  317. }
  318. if (sd_dev) {
  319. pci_dev_put(sd_dev);
  320. dev_info(&chip->pdev->dev, "Refusing to bind to "
  321. "secondary interface.\n");
  322. return -ENODEV;
  323. }
  324. }
  325. /*
  326. * JMicron chips need a bit of a nudge to enable the power
  327. * output pins.
  328. */
  329. ret = jmicron_pmos(chip, 1);
  330. if (ret) {
  331. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  332. return ret;
  333. }
  334. /* quirk for unsable RO-detection on JM388 chips */
  335. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
  336. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  337. chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
  338. return 0;
  339. }
  340. static void jmicron_enable_mmc(struct sdhci_host *host, int on)
  341. {
  342. u8 scratch;
  343. scratch = readb(host->ioaddr + 0xC0);
  344. if (on)
  345. scratch |= 0x01;
  346. else
  347. scratch &= ~0x01;
  348. writeb(scratch, host->ioaddr + 0xC0);
  349. }
  350. static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
  351. {
  352. if (slot->chip->pdev->revision == 0) {
  353. u16 version;
  354. version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
  355. version = (version & SDHCI_VENDOR_VER_MASK) >>
  356. SDHCI_VENDOR_VER_SHIFT;
  357. /*
  358. * Older versions of the chip have lots of nasty glitches
  359. * in the ADMA engine. It's best just to avoid it
  360. * completely.
  361. */
  362. if (version < 0xAC)
  363. slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
  364. }
  365. /* JM388 MMC doesn't support 1.8V while SD supports it */
  366. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  367. slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
  368. MMC_VDD_29_30 | MMC_VDD_30_31 |
  369. MMC_VDD_165_195; /* allow 1.8V */
  370. slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
  371. MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
  372. }
  373. /*
  374. * The secondary interface requires a bit set to get the
  375. * interrupts.
  376. */
  377. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  378. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  379. jmicron_enable_mmc(slot->host, 1);
  380. slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
  381. return 0;
  382. }
  383. static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
  384. {
  385. if (dead)
  386. return;
  387. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  388. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  389. jmicron_enable_mmc(slot->host, 0);
  390. }
  391. static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state)
  392. {
  393. int i;
  394. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  395. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  396. for (i = 0; i < chip->num_slots; i++)
  397. jmicron_enable_mmc(chip->slots[i]->host, 0);
  398. }
  399. return 0;
  400. }
  401. static int jmicron_resume(struct sdhci_pci_chip *chip)
  402. {
  403. int ret, i;
  404. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  405. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  406. for (i = 0; i < chip->num_slots; i++)
  407. jmicron_enable_mmc(chip->slots[i]->host, 1);
  408. }
  409. ret = jmicron_pmos(chip, 1);
  410. if (ret) {
  411. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  412. return ret;
  413. }
  414. return 0;
  415. }
  416. static const struct sdhci_pci_fixes sdhci_o2 = {
  417. .probe = o2_probe,
  418. };
  419. static const struct sdhci_pci_fixes sdhci_jmicron = {
  420. .probe = jmicron_probe,
  421. .probe_slot = jmicron_probe_slot,
  422. .remove_slot = jmicron_remove_slot,
  423. .suspend = jmicron_suspend,
  424. .resume = jmicron_resume,
  425. };
  426. /* SysKonnect CardBus2SDIO extra registers */
  427. #define SYSKT_CTRL 0x200
  428. #define SYSKT_RDFIFO_STAT 0x204
  429. #define SYSKT_WRFIFO_STAT 0x208
  430. #define SYSKT_POWER_DATA 0x20c
  431. #define SYSKT_POWER_330 0xef
  432. #define SYSKT_POWER_300 0xf8
  433. #define SYSKT_POWER_184 0xcc
  434. #define SYSKT_POWER_CMD 0x20d
  435. #define SYSKT_POWER_START (1 << 7)
  436. #define SYSKT_POWER_STATUS 0x20e
  437. #define SYSKT_POWER_STATUS_OK (1 << 0)
  438. #define SYSKT_BOARD_REV 0x210
  439. #define SYSKT_CHIP_REV 0x211
  440. #define SYSKT_CONF_DATA 0x212
  441. #define SYSKT_CONF_DATA_1V8 (1 << 2)
  442. #define SYSKT_CONF_DATA_2V5 (1 << 1)
  443. #define SYSKT_CONF_DATA_3V3 (1 << 0)
  444. static int syskt_probe(struct sdhci_pci_chip *chip)
  445. {
  446. if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  447. chip->pdev->class &= ~0x0000FF;
  448. chip->pdev->class |= PCI_SDHCI_IFDMA;
  449. }
  450. return 0;
  451. }
  452. static int syskt_probe_slot(struct sdhci_pci_slot *slot)
  453. {
  454. int tm, ps;
  455. u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
  456. u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
  457. dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
  458. "board rev %d.%d, chip rev %d.%d\n",
  459. board_rev >> 4, board_rev & 0xf,
  460. chip_rev >> 4, chip_rev & 0xf);
  461. if (chip_rev >= 0x20)
  462. slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
  463. writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
  464. writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
  465. udelay(50);
  466. tm = 10; /* Wait max 1 ms */
  467. do {
  468. ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
  469. if (ps & SYSKT_POWER_STATUS_OK)
  470. break;
  471. udelay(100);
  472. } while (--tm);
  473. if (!tm) {
  474. dev_err(&slot->chip->pdev->dev,
  475. "power regulator never stabilized");
  476. writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
  477. return -ENODEV;
  478. }
  479. return 0;
  480. }
  481. static const struct sdhci_pci_fixes sdhci_syskt = {
  482. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
  483. .probe = syskt_probe,
  484. .probe_slot = syskt_probe_slot,
  485. };
  486. static int via_probe(struct sdhci_pci_chip *chip)
  487. {
  488. if (chip->pdev->revision == 0x10)
  489. chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
  490. return 0;
  491. }
  492. static const struct sdhci_pci_fixes sdhci_via = {
  493. .probe = via_probe,
  494. };
  495. static const struct pci_device_id pci_ids[] __devinitdata = {
  496. {
  497. .vendor = PCI_VENDOR_ID_RICOH,
  498. .device = PCI_DEVICE_ID_RICOH_R5C822,
  499. .subvendor = PCI_ANY_ID,
  500. .subdevice = PCI_ANY_ID,
  501. .driver_data = (kernel_ulong_t)&sdhci_ricoh,
  502. },
  503. {
  504. .vendor = PCI_VENDOR_ID_RICOH,
  505. .device = 0x843,
  506. .subvendor = PCI_ANY_ID,
  507. .subdevice = PCI_ANY_ID,
  508. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  509. },
  510. {
  511. .vendor = PCI_VENDOR_ID_RICOH,
  512. .device = 0xe822,
  513. .subvendor = PCI_ANY_ID,
  514. .subdevice = PCI_ANY_ID,
  515. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  516. },
  517. {
  518. .vendor = PCI_VENDOR_ID_RICOH,
  519. .device = 0xe823,
  520. .subvendor = PCI_ANY_ID,
  521. .subdevice = PCI_ANY_ID,
  522. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  523. },
  524. {
  525. .vendor = PCI_VENDOR_ID_ENE,
  526. .device = PCI_DEVICE_ID_ENE_CB712_SD,
  527. .subvendor = PCI_ANY_ID,
  528. .subdevice = PCI_ANY_ID,
  529. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  530. },
  531. {
  532. .vendor = PCI_VENDOR_ID_ENE,
  533. .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
  534. .subvendor = PCI_ANY_ID,
  535. .subdevice = PCI_ANY_ID,
  536. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  537. },
  538. {
  539. .vendor = PCI_VENDOR_ID_ENE,
  540. .device = PCI_DEVICE_ID_ENE_CB714_SD,
  541. .subvendor = PCI_ANY_ID,
  542. .subdevice = PCI_ANY_ID,
  543. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  544. },
  545. {
  546. .vendor = PCI_VENDOR_ID_ENE,
  547. .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
  548. .subvendor = PCI_ANY_ID,
  549. .subdevice = PCI_ANY_ID,
  550. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  551. },
  552. {
  553. .vendor = PCI_VENDOR_ID_MARVELL,
  554. .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
  555. .subvendor = PCI_ANY_ID,
  556. .subdevice = PCI_ANY_ID,
  557. .driver_data = (kernel_ulong_t)&sdhci_cafe,
  558. },
  559. {
  560. .vendor = PCI_VENDOR_ID_JMICRON,
  561. .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
  562. .subvendor = PCI_ANY_ID,
  563. .subdevice = PCI_ANY_ID,
  564. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  565. },
  566. {
  567. .vendor = PCI_VENDOR_ID_JMICRON,
  568. .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
  569. .subvendor = PCI_ANY_ID,
  570. .subdevice = PCI_ANY_ID,
  571. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  572. },
  573. {
  574. .vendor = PCI_VENDOR_ID_JMICRON,
  575. .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
  576. .subvendor = PCI_ANY_ID,
  577. .subdevice = PCI_ANY_ID,
  578. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  579. },
  580. {
  581. .vendor = PCI_VENDOR_ID_JMICRON,
  582. .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
  583. .subvendor = PCI_ANY_ID,
  584. .subdevice = PCI_ANY_ID,
  585. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  586. },
  587. {
  588. .vendor = PCI_VENDOR_ID_SYSKONNECT,
  589. .device = 0x8000,
  590. .subvendor = PCI_ANY_ID,
  591. .subdevice = PCI_ANY_ID,
  592. .driver_data = (kernel_ulong_t)&sdhci_syskt,
  593. },
  594. {
  595. .vendor = PCI_VENDOR_ID_VIA,
  596. .device = 0x95d0,
  597. .subvendor = PCI_ANY_ID,
  598. .subdevice = PCI_ANY_ID,
  599. .driver_data = (kernel_ulong_t)&sdhci_via,
  600. },
  601. {
  602. .vendor = PCI_VENDOR_ID_INTEL,
  603. .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
  604. .subvendor = PCI_ANY_ID,
  605. .subdevice = PCI_ANY_ID,
  606. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
  607. },
  608. {
  609. .vendor = PCI_VENDOR_ID_INTEL,
  610. .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
  611. .subvendor = PCI_ANY_ID,
  612. .subdevice = PCI_ANY_ID,
  613. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  614. },
  615. {
  616. .vendor = PCI_VENDOR_ID_INTEL,
  617. .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
  618. .subvendor = PCI_ANY_ID,
  619. .subdevice = PCI_ANY_ID,
  620. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  621. },
  622. {
  623. .vendor = PCI_VENDOR_ID_INTEL,
  624. .device = PCI_DEVICE_ID_INTEL_MFD_SD,
  625. .subvendor = PCI_ANY_ID,
  626. .subdevice = PCI_ANY_ID,
  627. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  628. },
  629. {
  630. .vendor = PCI_VENDOR_ID_INTEL,
  631. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
  632. .subvendor = PCI_ANY_ID,
  633. .subdevice = PCI_ANY_ID,
  634. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  635. },
  636. {
  637. .vendor = PCI_VENDOR_ID_INTEL,
  638. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
  639. .subvendor = PCI_ANY_ID,
  640. .subdevice = PCI_ANY_ID,
  641. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  642. },
  643. {
  644. .vendor = PCI_VENDOR_ID_INTEL,
  645. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
  646. .subvendor = PCI_ANY_ID,
  647. .subdevice = PCI_ANY_ID,
  648. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  649. },
  650. {
  651. .vendor = PCI_VENDOR_ID_INTEL,
  652. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
  653. .subvendor = PCI_ANY_ID,
  654. .subdevice = PCI_ANY_ID,
  655. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  656. },
  657. {
  658. .vendor = PCI_VENDOR_ID_O2,
  659. .device = PCI_DEVICE_ID_O2_8120,
  660. .subvendor = PCI_ANY_ID,
  661. .subdevice = PCI_ANY_ID,
  662. .driver_data = (kernel_ulong_t)&sdhci_o2,
  663. },
  664. {
  665. .vendor = PCI_VENDOR_ID_O2,
  666. .device = PCI_DEVICE_ID_O2_8220,
  667. .subvendor = PCI_ANY_ID,
  668. .subdevice = PCI_ANY_ID,
  669. .driver_data = (kernel_ulong_t)&sdhci_o2,
  670. },
  671. {
  672. .vendor = PCI_VENDOR_ID_O2,
  673. .device = PCI_DEVICE_ID_O2_8221,
  674. .subvendor = PCI_ANY_ID,
  675. .subdevice = PCI_ANY_ID,
  676. .driver_data = (kernel_ulong_t)&sdhci_o2,
  677. },
  678. {
  679. .vendor = PCI_VENDOR_ID_O2,
  680. .device = PCI_DEVICE_ID_O2_8320,
  681. .subvendor = PCI_ANY_ID,
  682. .subdevice = PCI_ANY_ID,
  683. .driver_data = (kernel_ulong_t)&sdhci_o2,
  684. },
  685. {
  686. .vendor = PCI_VENDOR_ID_O2,
  687. .device = PCI_DEVICE_ID_O2_8321,
  688. .subvendor = PCI_ANY_ID,
  689. .subdevice = PCI_ANY_ID,
  690. .driver_data = (kernel_ulong_t)&sdhci_o2,
  691. },
  692. { /* Generic SD host controller */
  693. PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
  694. },
  695. { /* end: all zeroes */ },
  696. };
  697. MODULE_DEVICE_TABLE(pci, pci_ids);
  698. /*****************************************************************************\
  699. * *
  700. * SDHCI core callbacks *
  701. * *
  702. \*****************************************************************************/
  703. static int sdhci_pci_enable_dma(struct sdhci_host *host)
  704. {
  705. struct sdhci_pci_slot *slot;
  706. struct pci_dev *pdev;
  707. int ret;
  708. slot = sdhci_priv(host);
  709. pdev = slot->chip->pdev;
  710. if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
  711. ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
  712. (host->flags & SDHCI_USE_SDMA)) {
  713. dev_warn(&pdev->dev, "Will use DMA mode even though HW "
  714. "doesn't fully claim to support it.\n");
  715. }
  716. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  717. if (ret)
  718. return ret;
  719. pci_set_master(pdev);
  720. return 0;
  721. }
  722. static int sdhci_pci_8bit_width(struct sdhci_host *host, int width)
  723. {
  724. u8 ctrl;
  725. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  726. switch (width) {
  727. case MMC_BUS_WIDTH_8:
  728. ctrl |= SDHCI_CTRL_8BITBUS;
  729. ctrl &= ~SDHCI_CTRL_4BITBUS;
  730. break;
  731. case MMC_BUS_WIDTH_4:
  732. ctrl |= SDHCI_CTRL_4BITBUS;
  733. ctrl &= ~SDHCI_CTRL_8BITBUS;
  734. break;
  735. default:
  736. ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
  737. break;
  738. }
  739. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  740. return 0;
  741. }
  742. static void sdhci_pci_hw_reset(struct sdhci_host *host)
  743. {
  744. struct sdhci_pci_slot *slot = sdhci_priv(host);
  745. int rst_n_gpio = slot->rst_n_gpio;
  746. if (!gpio_is_valid(rst_n_gpio))
  747. return;
  748. gpio_set_value_cansleep(rst_n_gpio, 0);
  749. /* For eMMC, minimum is 1us but give it 10us for good measure */
  750. udelay(10);
  751. gpio_set_value_cansleep(rst_n_gpio, 1);
  752. /* For eMMC, minimum is 200us but give it 300us for good measure */
  753. usleep_range(300, 1000);
  754. }
  755. static struct sdhci_ops sdhci_pci_ops = {
  756. .enable_dma = sdhci_pci_enable_dma,
  757. .platform_8bit_width = sdhci_pci_8bit_width,
  758. .hw_reset = sdhci_pci_hw_reset,
  759. };
  760. /*****************************************************************************\
  761. * *
  762. * Suspend/resume *
  763. * *
  764. \*****************************************************************************/
  765. #ifdef CONFIG_PM
  766. static int sdhci_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  767. {
  768. struct sdhci_pci_chip *chip;
  769. struct sdhci_pci_slot *slot;
  770. mmc_pm_flag_t slot_pm_flags;
  771. mmc_pm_flag_t pm_flags = 0;
  772. int i, ret;
  773. chip = pci_get_drvdata(pdev);
  774. if (!chip)
  775. return 0;
  776. for (i = 0; i < chip->num_slots; i++) {
  777. slot = chip->slots[i];
  778. if (!slot)
  779. continue;
  780. ret = sdhci_suspend_host(slot->host, state);
  781. if (ret) {
  782. for (i--; i >= 0; i--)
  783. sdhci_resume_host(chip->slots[i]->host);
  784. return ret;
  785. }
  786. slot_pm_flags = slot->host->mmc->pm_flags;
  787. if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  788. sdhci_enable_irq_wakeups(slot->host);
  789. pm_flags |= slot_pm_flags;
  790. }
  791. if (chip->fixes && chip->fixes->suspend) {
  792. ret = chip->fixes->suspend(chip, state);
  793. if (ret) {
  794. for (i = chip->num_slots - 1; i >= 0; i--)
  795. sdhci_resume_host(chip->slots[i]->host);
  796. return ret;
  797. }
  798. }
  799. pci_save_state(pdev);
  800. if (pm_flags & MMC_PM_KEEP_POWER) {
  801. if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
  802. pci_pme_active(pdev, true);
  803. pci_enable_wake(pdev, PCI_D3hot, 1);
  804. }
  805. pci_set_power_state(pdev, PCI_D3hot);
  806. } else {
  807. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  808. pci_disable_device(pdev);
  809. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  810. }
  811. return 0;
  812. }
  813. static int sdhci_pci_resume(struct pci_dev *pdev)
  814. {
  815. struct sdhci_pci_chip *chip;
  816. struct sdhci_pci_slot *slot;
  817. int i, ret;
  818. chip = pci_get_drvdata(pdev);
  819. if (!chip)
  820. return 0;
  821. pci_set_power_state(pdev, PCI_D0);
  822. pci_restore_state(pdev);
  823. ret = pci_enable_device(pdev);
  824. if (ret)
  825. return ret;
  826. if (chip->fixes && chip->fixes->resume) {
  827. ret = chip->fixes->resume(chip);
  828. if (ret)
  829. return ret;
  830. }
  831. for (i = 0; i < chip->num_slots; i++) {
  832. slot = chip->slots[i];
  833. if (!slot)
  834. continue;
  835. ret = sdhci_resume_host(slot->host);
  836. if (ret)
  837. return ret;
  838. }
  839. return 0;
  840. }
  841. #else /* CONFIG_PM */
  842. #define sdhci_pci_suspend NULL
  843. #define sdhci_pci_resume NULL
  844. #endif /* CONFIG_PM */
  845. /*****************************************************************************\
  846. * *
  847. * Device probing/removal *
  848. * *
  849. \*****************************************************************************/
  850. static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
  851. struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
  852. {
  853. struct sdhci_pci_slot *slot;
  854. struct sdhci_host *host;
  855. int ret;
  856. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  857. dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
  858. return ERR_PTR(-ENODEV);
  859. }
  860. if (pci_resource_len(pdev, bar) != 0x100) {
  861. dev_err(&pdev->dev, "Invalid iomem size. You may "
  862. "experience problems.\n");
  863. }
  864. if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  865. dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
  866. return ERR_PTR(-ENODEV);
  867. }
  868. if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
  869. dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
  870. return ERR_PTR(-ENODEV);
  871. }
  872. host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
  873. if (IS_ERR(host)) {
  874. dev_err(&pdev->dev, "cannot allocate host\n");
  875. return ERR_CAST(host);
  876. }
  877. slot = sdhci_priv(host);
  878. slot->chip = chip;
  879. slot->host = host;
  880. slot->pci_bar = bar;
  881. slot->rst_n_gpio = -EINVAL;
  882. host->hw_name = "PCI";
  883. host->ops = &sdhci_pci_ops;
  884. host->quirks = chip->quirks;
  885. host->irq = pdev->irq;
  886. ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
  887. if (ret) {
  888. dev_err(&pdev->dev, "cannot request region\n");
  889. goto free;
  890. }
  891. host->ioaddr = pci_ioremap_bar(pdev, bar);
  892. if (!host->ioaddr) {
  893. dev_err(&pdev->dev, "failed to remap registers\n");
  894. ret = -ENOMEM;
  895. goto release;
  896. }
  897. if (chip->fixes && chip->fixes->probe_slot) {
  898. ret = chip->fixes->probe_slot(slot);
  899. if (ret)
  900. goto unmap;
  901. }
  902. host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
  903. ret = sdhci_add_host(host);
  904. if (ret)
  905. goto remove;
  906. return slot;
  907. remove:
  908. if (chip->fixes && chip->fixes->remove_slot)
  909. chip->fixes->remove_slot(slot, 0);
  910. unmap:
  911. iounmap(host->ioaddr);
  912. release:
  913. pci_release_region(pdev, bar);
  914. free:
  915. sdhci_free_host(host);
  916. return ERR_PTR(ret);
  917. }
  918. static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
  919. {
  920. int dead;
  921. u32 scratch;
  922. dead = 0;
  923. scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
  924. if (scratch == (u32)-1)
  925. dead = 1;
  926. sdhci_remove_host(slot->host, dead);
  927. if (slot->chip->fixes && slot->chip->fixes->remove_slot)
  928. slot->chip->fixes->remove_slot(slot, dead);
  929. pci_release_region(slot->chip->pdev, slot->pci_bar);
  930. sdhci_free_host(slot->host);
  931. }
  932. static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
  933. const struct pci_device_id *ent)
  934. {
  935. struct sdhci_pci_chip *chip;
  936. struct sdhci_pci_slot *slot;
  937. u8 slots, first_bar;
  938. int ret, i;
  939. BUG_ON(pdev == NULL);
  940. BUG_ON(ent == NULL);
  941. dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
  942. (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
  943. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
  944. if (ret)
  945. return ret;
  946. slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
  947. dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
  948. if (slots == 0)
  949. return -ENODEV;
  950. BUG_ON(slots > MAX_SLOTS);
  951. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
  952. if (ret)
  953. return ret;
  954. first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
  955. if (first_bar > 5) {
  956. dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
  957. return -ENODEV;
  958. }
  959. ret = pci_enable_device(pdev);
  960. if (ret)
  961. return ret;
  962. chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
  963. if (!chip) {
  964. ret = -ENOMEM;
  965. goto err;
  966. }
  967. chip->pdev = pdev;
  968. chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
  969. if (chip->fixes)
  970. chip->quirks = chip->fixes->quirks;
  971. chip->num_slots = slots;
  972. pci_set_drvdata(pdev, chip);
  973. if (chip->fixes && chip->fixes->probe) {
  974. ret = chip->fixes->probe(chip);
  975. if (ret)
  976. goto free;
  977. }
  978. slots = chip->num_slots; /* Quirk may have changed this */
  979. for (i = 0; i < slots; i++) {
  980. slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
  981. if (IS_ERR(slot)) {
  982. for (i--; i >= 0; i--)
  983. sdhci_pci_remove_slot(chip->slots[i]);
  984. ret = PTR_ERR(slot);
  985. goto free;
  986. }
  987. chip->slots[i] = slot;
  988. }
  989. return 0;
  990. free:
  991. pci_set_drvdata(pdev, NULL);
  992. kfree(chip);
  993. err:
  994. pci_disable_device(pdev);
  995. return ret;
  996. }
  997. static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
  998. {
  999. int i;
  1000. struct sdhci_pci_chip *chip;
  1001. chip = pci_get_drvdata(pdev);
  1002. if (chip) {
  1003. for (i = 0; i < chip->num_slots; i++)
  1004. sdhci_pci_remove_slot(chip->slots[i]);
  1005. pci_set_drvdata(pdev, NULL);
  1006. kfree(chip);
  1007. }
  1008. pci_disable_device(pdev);
  1009. }
  1010. static struct pci_driver sdhci_driver = {
  1011. .name = "sdhci-pci",
  1012. .id_table = pci_ids,
  1013. .probe = sdhci_pci_probe,
  1014. .remove = __devexit_p(sdhci_pci_remove),
  1015. .suspend = sdhci_pci_suspend,
  1016. .resume = sdhci_pci_resume,
  1017. };
  1018. /*****************************************************************************\
  1019. * *
  1020. * Driver init/exit *
  1021. * *
  1022. \*****************************************************************************/
  1023. static int __init sdhci_drv_init(void)
  1024. {
  1025. return pci_register_driver(&sdhci_driver);
  1026. }
  1027. static void __exit sdhci_drv_exit(void)
  1028. {
  1029. pci_unregister_driver(&sdhci_driver);
  1030. }
  1031. module_init(sdhci_drv_init);
  1032. module_exit(sdhci_drv_exit);
  1033. MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
  1034. MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
  1035. MODULE_LICENSE("GPL");