sdhci-pci.c 28 KB

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