sdhci-pci.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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 <asm/scatterlist.h>
  22. #include <asm/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. return 0;
  275. }
  276. static void jmicron_enable_mmc(struct sdhci_host *host, int on)
  277. {
  278. u8 scratch;
  279. scratch = readb(host->ioaddr + 0xC0);
  280. if (on)
  281. scratch |= 0x01;
  282. else
  283. scratch &= ~0x01;
  284. writeb(scratch, host->ioaddr + 0xC0);
  285. }
  286. static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
  287. {
  288. if (slot->chip->pdev->revision == 0) {
  289. u16 version;
  290. version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
  291. version = (version & SDHCI_VENDOR_VER_MASK) >>
  292. SDHCI_VENDOR_VER_SHIFT;
  293. /*
  294. * Older versions of the chip have lots of nasty glitches
  295. * in the ADMA engine. It's best just to avoid it
  296. * completely.
  297. */
  298. if (version < 0xAC)
  299. slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
  300. }
  301. /* JM388 MMC doesn't support 1.8V while SD supports it */
  302. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  303. slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
  304. MMC_VDD_29_30 | MMC_VDD_30_31 |
  305. MMC_VDD_165_195; /* allow 1.8V */
  306. slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
  307. MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
  308. }
  309. /*
  310. * The secondary interface requires a bit set to get the
  311. * interrupts.
  312. */
  313. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  314. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  315. jmicron_enable_mmc(slot->host, 1);
  316. return 0;
  317. }
  318. static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
  319. {
  320. if (dead)
  321. return;
  322. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  323. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  324. jmicron_enable_mmc(slot->host, 0);
  325. }
  326. static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state)
  327. {
  328. int i;
  329. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  330. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  331. for (i = 0;i < chip->num_slots;i++)
  332. jmicron_enable_mmc(chip->slots[i]->host, 0);
  333. }
  334. return 0;
  335. }
  336. static int jmicron_resume(struct sdhci_pci_chip *chip)
  337. {
  338. int ret, i;
  339. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  340. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  341. for (i = 0;i < chip->num_slots;i++)
  342. jmicron_enable_mmc(chip->slots[i]->host, 1);
  343. }
  344. ret = jmicron_pmos(chip, 1);
  345. if (ret) {
  346. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  347. return ret;
  348. }
  349. return 0;
  350. }
  351. static const struct sdhci_pci_fixes sdhci_o2 = {
  352. .probe = o2_probe,
  353. };
  354. static const struct sdhci_pci_fixes sdhci_jmicron = {
  355. .probe = jmicron_probe,
  356. .probe_slot = jmicron_probe_slot,
  357. .remove_slot = jmicron_remove_slot,
  358. .suspend = jmicron_suspend,
  359. .resume = jmicron_resume,
  360. };
  361. /* SysKonnect CardBus2SDIO extra registers */
  362. #define SYSKT_CTRL 0x200
  363. #define SYSKT_RDFIFO_STAT 0x204
  364. #define SYSKT_WRFIFO_STAT 0x208
  365. #define SYSKT_POWER_DATA 0x20c
  366. #define SYSKT_POWER_330 0xef
  367. #define SYSKT_POWER_300 0xf8
  368. #define SYSKT_POWER_184 0xcc
  369. #define SYSKT_POWER_CMD 0x20d
  370. #define SYSKT_POWER_START (1 << 7)
  371. #define SYSKT_POWER_STATUS 0x20e
  372. #define SYSKT_POWER_STATUS_OK (1 << 0)
  373. #define SYSKT_BOARD_REV 0x210
  374. #define SYSKT_CHIP_REV 0x211
  375. #define SYSKT_CONF_DATA 0x212
  376. #define SYSKT_CONF_DATA_1V8 (1 << 2)
  377. #define SYSKT_CONF_DATA_2V5 (1 << 1)
  378. #define SYSKT_CONF_DATA_3V3 (1 << 0)
  379. static int syskt_probe(struct sdhci_pci_chip *chip)
  380. {
  381. if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  382. chip->pdev->class &= ~0x0000FF;
  383. chip->pdev->class |= PCI_SDHCI_IFDMA;
  384. }
  385. return 0;
  386. }
  387. static int syskt_probe_slot(struct sdhci_pci_slot *slot)
  388. {
  389. int tm, ps;
  390. u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
  391. u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
  392. dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
  393. "board rev %d.%d, chip rev %d.%d\n",
  394. board_rev >> 4, board_rev & 0xf,
  395. chip_rev >> 4, chip_rev & 0xf);
  396. if (chip_rev >= 0x20)
  397. slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
  398. writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
  399. writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
  400. udelay(50);
  401. tm = 10; /* Wait max 1 ms */
  402. do {
  403. ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
  404. if (ps & SYSKT_POWER_STATUS_OK)
  405. break;
  406. udelay(100);
  407. } while (--tm);
  408. if (!tm) {
  409. dev_err(&slot->chip->pdev->dev,
  410. "power regulator never stabilized");
  411. writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
  412. return -ENODEV;
  413. }
  414. return 0;
  415. }
  416. static const struct sdhci_pci_fixes sdhci_syskt = {
  417. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
  418. .probe = syskt_probe,
  419. .probe_slot = syskt_probe_slot,
  420. };
  421. static int via_probe(struct sdhci_pci_chip *chip)
  422. {
  423. if (chip->pdev->revision == 0x10)
  424. chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
  425. return 0;
  426. }
  427. static const struct sdhci_pci_fixes sdhci_via = {
  428. .probe = via_probe,
  429. };
  430. static const struct pci_device_id pci_ids[] __devinitdata = {
  431. {
  432. .vendor = PCI_VENDOR_ID_RICOH,
  433. .device = PCI_DEVICE_ID_RICOH_R5C822,
  434. .subvendor = PCI_ANY_ID,
  435. .subdevice = PCI_ANY_ID,
  436. .driver_data = (kernel_ulong_t)&sdhci_ricoh,
  437. },
  438. {
  439. .vendor = PCI_VENDOR_ID_RICOH,
  440. .device = 0x843,
  441. .subvendor = PCI_ANY_ID,
  442. .subdevice = PCI_ANY_ID,
  443. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  444. },
  445. {
  446. .vendor = PCI_VENDOR_ID_RICOH,
  447. .device = 0xe822,
  448. .subvendor = PCI_ANY_ID,
  449. .subdevice = PCI_ANY_ID,
  450. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  451. },
  452. {
  453. .vendor = PCI_VENDOR_ID_ENE,
  454. .device = PCI_DEVICE_ID_ENE_CB712_SD,
  455. .subvendor = PCI_ANY_ID,
  456. .subdevice = PCI_ANY_ID,
  457. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  458. },
  459. {
  460. .vendor = PCI_VENDOR_ID_ENE,
  461. .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
  462. .subvendor = PCI_ANY_ID,
  463. .subdevice = PCI_ANY_ID,
  464. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  465. },
  466. {
  467. .vendor = PCI_VENDOR_ID_ENE,
  468. .device = PCI_DEVICE_ID_ENE_CB714_SD,
  469. .subvendor = PCI_ANY_ID,
  470. .subdevice = PCI_ANY_ID,
  471. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  472. },
  473. {
  474. .vendor = PCI_VENDOR_ID_ENE,
  475. .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
  476. .subvendor = PCI_ANY_ID,
  477. .subdevice = PCI_ANY_ID,
  478. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  479. },
  480. {
  481. .vendor = PCI_VENDOR_ID_MARVELL,
  482. .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
  483. .subvendor = PCI_ANY_ID,
  484. .subdevice = PCI_ANY_ID,
  485. .driver_data = (kernel_ulong_t)&sdhci_cafe,
  486. },
  487. {
  488. .vendor = PCI_VENDOR_ID_JMICRON,
  489. .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
  490. .subvendor = PCI_ANY_ID,
  491. .subdevice = PCI_ANY_ID,
  492. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  493. },
  494. {
  495. .vendor = PCI_VENDOR_ID_JMICRON,
  496. .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
  497. .subvendor = PCI_ANY_ID,
  498. .subdevice = PCI_ANY_ID,
  499. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  500. },
  501. {
  502. .vendor = PCI_VENDOR_ID_JMICRON,
  503. .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
  504. .subvendor = PCI_ANY_ID,
  505. .subdevice = PCI_ANY_ID,
  506. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  507. },
  508. {
  509. .vendor = PCI_VENDOR_ID_JMICRON,
  510. .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
  511. .subvendor = PCI_ANY_ID,
  512. .subdevice = PCI_ANY_ID,
  513. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  514. },
  515. {
  516. .vendor = PCI_VENDOR_ID_SYSKONNECT,
  517. .device = 0x8000,
  518. .subvendor = PCI_ANY_ID,
  519. .subdevice = PCI_ANY_ID,
  520. .driver_data = (kernel_ulong_t)&sdhci_syskt,
  521. },
  522. {
  523. .vendor = PCI_VENDOR_ID_VIA,
  524. .device = 0x95d0,
  525. .subvendor = PCI_ANY_ID,
  526. .subdevice = PCI_ANY_ID,
  527. .driver_data = (kernel_ulong_t)&sdhci_via,
  528. },
  529. {
  530. .vendor = PCI_VENDOR_ID_INTEL,
  531. .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
  532. .subvendor = PCI_ANY_ID,
  533. .subdevice = PCI_ANY_ID,
  534. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
  535. },
  536. {
  537. .vendor = PCI_VENDOR_ID_INTEL,
  538. .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
  539. .subvendor = PCI_ANY_ID,
  540. .subdevice = PCI_ANY_ID,
  541. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  542. },
  543. {
  544. .vendor = PCI_VENDOR_ID_INTEL,
  545. .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
  546. .subvendor = PCI_ANY_ID,
  547. .subdevice = PCI_ANY_ID,
  548. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  549. },
  550. {
  551. .vendor = PCI_VENDOR_ID_INTEL,
  552. .device = PCI_DEVICE_ID_INTEL_MFD_SD,
  553. .subvendor = PCI_ANY_ID,
  554. .subdevice = PCI_ANY_ID,
  555. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  556. },
  557. {
  558. .vendor = PCI_VENDOR_ID_INTEL,
  559. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
  560. .subvendor = PCI_ANY_ID,
  561. .subdevice = PCI_ANY_ID,
  562. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
  563. },
  564. {
  565. .vendor = PCI_VENDOR_ID_INTEL,
  566. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
  567. .subvendor = PCI_ANY_ID,
  568. .subdevice = PCI_ANY_ID,
  569. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
  570. },
  571. {
  572. .vendor = PCI_VENDOR_ID_INTEL,
  573. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
  574. .subvendor = PCI_ANY_ID,
  575. .subdevice = PCI_ANY_ID,
  576. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
  577. },
  578. {
  579. .vendor = PCI_VENDOR_ID_INTEL,
  580. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
  581. .subvendor = PCI_ANY_ID,
  582. .subdevice = PCI_ANY_ID,
  583. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc_sdio,
  584. },
  585. {
  586. .vendor = PCI_VENDOR_ID_O2,
  587. .device = PCI_DEVICE_ID_O2_8120,
  588. .subvendor = PCI_ANY_ID,
  589. .subdevice = PCI_ANY_ID,
  590. .driver_data = (kernel_ulong_t)&sdhci_o2,
  591. },
  592. {
  593. .vendor = PCI_VENDOR_ID_O2,
  594. .device = PCI_DEVICE_ID_O2_8220,
  595. .subvendor = PCI_ANY_ID,
  596. .subdevice = PCI_ANY_ID,
  597. .driver_data = (kernel_ulong_t)&sdhci_o2,
  598. },
  599. {
  600. .vendor = PCI_VENDOR_ID_O2,
  601. .device = PCI_DEVICE_ID_O2_8221,
  602. .subvendor = PCI_ANY_ID,
  603. .subdevice = PCI_ANY_ID,
  604. .driver_data = (kernel_ulong_t)&sdhci_o2,
  605. },
  606. {
  607. .vendor = PCI_VENDOR_ID_O2,
  608. .device = PCI_DEVICE_ID_O2_8320,
  609. .subvendor = PCI_ANY_ID,
  610. .subdevice = PCI_ANY_ID,
  611. .driver_data = (kernel_ulong_t)&sdhci_o2,
  612. },
  613. {
  614. .vendor = PCI_VENDOR_ID_O2,
  615. .device = PCI_DEVICE_ID_O2_8321,
  616. .subvendor = PCI_ANY_ID,
  617. .subdevice = PCI_ANY_ID,
  618. .driver_data = (kernel_ulong_t)&sdhci_o2,
  619. },
  620. { /* Generic SD host controller */
  621. PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
  622. },
  623. { /* end: all zeroes */ },
  624. };
  625. MODULE_DEVICE_TABLE(pci, pci_ids);
  626. /*****************************************************************************\
  627. * *
  628. * SDHCI core callbacks *
  629. * *
  630. \*****************************************************************************/
  631. static int sdhci_pci_enable_dma(struct sdhci_host *host)
  632. {
  633. struct sdhci_pci_slot *slot;
  634. struct pci_dev *pdev;
  635. int ret;
  636. slot = sdhci_priv(host);
  637. pdev = slot->chip->pdev;
  638. if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
  639. ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
  640. (host->flags & SDHCI_USE_SDMA)) {
  641. dev_warn(&pdev->dev, "Will use DMA mode even though HW "
  642. "doesn't fully claim to support it.\n");
  643. }
  644. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  645. if (ret)
  646. return ret;
  647. pci_set_master(pdev);
  648. return 0;
  649. }
  650. static struct sdhci_ops sdhci_pci_ops = {
  651. .enable_dma = sdhci_pci_enable_dma,
  652. };
  653. /*****************************************************************************\
  654. * *
  655. * Suspend/resume *
  656. * *
  657. \*****************************************************************************/
  658. #ifdef CONFIG_PM
  659. static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state)
  660. {
  661. struct sdhci_pci_chip *chip;
  662. struct sdhci_pci_slot *slot;
  663. mmc_pm_flag_t slot_pm_flags;
  664. mmc_pm_flag_t pm_flags = 0;
  665. int i, ret;
  666. chip = pci_get_drvdata(pdev);
  667. if (!chip)
  668. return 0;
  669. for (i = 0;i < chip->num_slots;i++) {
  670. slot = chip->slots[i];
  671. if (!slot)
  672. continue;
  673. ret = sdhci_suspend_host(slot->host, state);
  674. if (ret) {
  675. for (i--;i >= 0;i--)
  676. sdhci_resume_host(chip->slots[i]->host);
  677. return ret;
  678. }
  679. slot_pm_flags = slot->host->mmc->pm_flags;
  680. if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  681. sdhci_enable_irq_wakeups(slot->host);
  682. pm_flags |= slot_pm_flags;
  683. }
  684. if (chip->fixes && chip->fixes->suspend) {
  685. ret = chip->fixes->suspend(chip, state);
  686. if (ret) {
  687. for (i = chip->num_slots - 1;i >= 0;i--)
  688. sdhci_resume_host(chip->slots[i]->host);
  689. return ret;
  690. }
  691. }
  692. pci_save_state(pdev);
  693. if (pm_flags & MMC_PM_KEEP_POWER) {
  694. if (pm_flags & MMC_PM_WAKE_SDIO_IRQ) {
  695. pci_pme_active(pdev, true);
  696. pci_enable_wake(pdev, PCI_D3hot, 1);
  697. }
  698. pci_set_power_state(pdev, PCI_D3hot);
  699. } else {
  700. pci_enable_wake(pdev, pci_choose_state(pdev, state), 0);
  701. pci_disable_device(pdev);
  702. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  703. }
  704. return 0;
  705. }
  706. static int sdhci_pci_resume (struct pci_dev *pdev)
  707. {
  708. struct sdhci_pci_chip *chip;
  709. struct sdhci_pci_slot *slot;
  710. int i, ret;
  711. chip = pci_get_drvdata(pdev);
  712. if (!chip)
  713. return 0;
  714. pci_set_power_state(pdev, PCI_D0);
  715. pci_restore_state(pdev);
  716. ret = pci_enable_device(pdev);
  717. if (ret)
  718. return ret;
  719. if (chip->fixes && chip->fixes->resume) {
  720. ret = chip->fixes->resume(chip);
  721. if (ret)
  722. return ret;
  723. }
  724. for (i = 0;i < chip->num_slots;i++) {
  725. slot = chip->slots[i];
  726. if (!slot)
  727. continue;
  728. ret = sdhci_resume_host(slot->host);
  729. if (ret)
  730. return ret;
  731. }
  732. return 0;
  733. }
  734. #else /* CONFIG_PM */
  735. #define sdhci_pci_suspend NULL
  736. #define sdhci_pci_resume NULL
  737. #endif /* CONFIG_PM */
  738. /*****************************************************************************\
  739. * *
  740. * Device probing/removal *
  741. * *
  742. \*****************************************************************************/
  743. static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
  744. struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar)
  745. {
  746. struct sdhci_pci_slot *slot;
  747. struct sdhci_host *host;
  748. resource_size_t addr;
  749. int ret;
  750. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  751. dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
  752. return ERR_PTR(-ENODEV);
  753. }
  754. if (pci_resource_len(pdev, bar) != 0x100) {
  755. dev_err(&pdev->dev, "Invalid iomem size. You may "
  756. "experience problems.\n");
  757. }
  758. if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  759. dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
  760. return ERR_PTR(-ENODEV);
  761. }
  762. if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
  763. dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
  764. return ERR_PTR(-ENODEV);
  765. }
  766. host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
  767. if (IS_ERR(host)) {
  768. dev_err(&pdev->dev, "cannot allocate host\n");
  769. return ERR_CAST(host);
  770. }
  771. slot = sdhci_priv(host);
  772. slot->chip = chip;
  773. slot->host = host;
  774. slot->pci_bar = bar;
  775. host->hw_name = "PCI";
  776. host->ops = &sdhci_pci_ops;
  777. host->quirks = chip->quirks;
  778. host->irq = pdev->irq;
  779. ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
  780. if (ret) {
  781. dev_err(&pdev->dev, "cannot request region\n");
  782. goto free;
  783. }
  784. addr = pci_resource_start(pdev, bar);
  785. host->ioaddr = pci_ioremap_bar(pdev, bar);
  786. if (!host->ioaddr) {
  787. dev_err(&pdev->dev, "failed to remap registers\n");
  788. goto release;
  789. }
  790. if (chip->fixes && chip->fixes->probe_slot) {
  791. ret = chip->fixes->probe_slot(slot);
  792. if (ret)
  793. goto unmap;
  794. }
  795. host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
  796. ret = sdhci_add_host(host);
  797. if (ret)
  798. goto remove;
  799. return slot;
  800. remove:
  801. if (chip->fixes && chip->fixes->remove_slot)
  802. chip->fixes->remove_slot(slot, 0);
  803. unmap:
  804. iounmap(host->ioaddr);
  805. release:
  806. pci_release_region(pdev, bar);
  807. free:
  808. sdhci_free_host(host);
  809. return ERR_PTR(ret);
  810. }
  811. static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
  812. {
  813. int dead;
  814. u32 scratch;
  815. dead = 0;
  816. scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
  817. if (scratch == (u32)-1)
  818. dead = 1;
  819. sdhci_remove_host(slot->host, dead);
  820. if (slot->chip->fixes && slot->chip->fixes->remove_slot)
  821. slot->chip->fixes->remove_slot(slot, dead);
  822. pci_release_region(slot->chip->pdev, slot->pci_bar);
  823. sdhci_free_host(slot->host);
  824. }
  825. static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
  826. const struct pci_device_id *ent)
  827. {
  828. struct sdhci_pci_chip *chip;
  829. struct sdhci_pci_slot *slot;
  830. u8 slots, rev, first_bar;
  831. int ret, i;
  832. BUG_ON(pdev == NULL);
  833. BUG_ON(ent == NULL);
  834. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
  835. dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
  836. (int)pdev->vendor, (int)pdev->device, (int)rev);
  837. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
  838. if (ret)
  839. return ret;
  840. slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
  841. dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
  842. if (slots == 0)
  843. return -ENODEV;
  844. BUG_ON(slots > MAX_SLOTS);
  845. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
  846. if (ret)
  847. return ret;
  848. first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
  849. if (first_bar > 5) {
  850. dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
  851. return -ENODEV;
  852. }
  853. ret = pci_enable_device(pdev);
  854. if (ret)
  855. return ret;
  856. chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
  857. if (!chip) {
  858. ret = -ENOMEM;
  859. goto err;
  860. }
  861. chip->pdev = pdev;
  862. chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data;
  863. if (chip->fixes)
  864. chip->quirks = chip->fixes->quirks;
  865. chip->num_slots = slots;
  866. pci_set_drvdata(pdev, chip);
  867. if (chip->fixes && chip->fixes->probe) {
  868. ret = chip->fixes->probe(chip);
  869. if (ret)
  870. goto free;
  871. }
  872. slots = chip->num_slots; /* Quirk may have changed this */
  873. for (i = 0;i < slots;i++) {
  874. slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i);
  875. if (IS_ERR(slot)) {
  876. for (i--;i >= 0;i--)
  877. sdhci_pci_remove_slot(chip->slots[i]);
  878. ret = PTR_ERR(slot);
  879. goto free;
  880. }
  881. chip->slots[i] = slot;
  882. }
  883. return 0;
  884. free:
  885. pci_set_drvdata(pdev, NULL);
  886. kfree(chip);
  887. err:
  888. pci_disable_device(pdev);
  889. return ret;
  890. }
  891. static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
  892. {
  893. int i;
  894. struct sdhci_pci_chip *chip;
  895. chip = pci_get_drvdata(pdev);
  896. if (chip) {
  897. for (i = 0;i < chip->num_slots; i++)
  898. sdhci_pci_remove_slot(chip->slots[i]);
  899. pci_set_drvdata(pdev, NULL);
  900. kfree(chip);
  901. }
  902. pci_disable_device(pdev);
  903. }
  904. static struct pci_driver sdhci_driver = {
  905. .name = "sdhci-pci",
  906. .id_table = pci_ids,
  907. .probe = sdhci_pci_probe,
  908. .remove = __devexit_p(sdhci_pci_remove),
  909. .suspend = sdhci_pci_suspend,
  910. .resume = sdhci_pci_resume,
  911. };
  912. /*****************************************************************************\
  913. * *
  914. * Driver init/exit *
  915. * *
  916. \*****************************************************************************/
  917. static int __init sdhci_drv_init(void)
  918. {
  919. return pci_register_driver(&sdhci_driver);
  920. }
  921. static void __exit sdhci_drv_exit(void)
  922. {
  923. pci_unregister_driver(&sdhci_driver);
  924. }
  925. module_init(sdhci_drv_init);
  926. module_exit(sdhci_drv_exit);
  927. MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
  928. MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
  929. MODULE_LICENSE("GPL");