sdhci-pci.c 26 KB

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