sdhci-pci.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645
  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/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/slab.h>
  20. #include <linux/device.h>
  21. #include <linux/mmc/host.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/io.h>
  24. #include <linux/gpio.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/mmc/slot-gpio.h>
  27. #include <linux/mmc/sdhci-pci-data.h>
  28. #include "sdhci.h"
  29. #include "sdhci-pci.h"
  30. #include "sdhci-pci-o2micro.h"
  31. /*****************************************************************************\
  32. * *
  33. * Hardware specific quirk handling *
  34. * *
  35. \*****************************************************************************/
  36. static int ricoh_probe(struct sdhci_pci_chip *chip)
  37. {
  38. if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG ||
  39. chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SONY)
  40. chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET;
  41. return 0;
  42. }
  43. static int ricoh_mmc_probe_slot(struct sdhci_pci_slot *slot)
  44. {
  45. slot->host->caps =
  46. ((0x21 << SDHCI_TIMEOUT_CLK_SHIFT)
  47. & SDHCI_TIMEOUT_CLK_MASK) |
  48. ((0x21 << SDHCI_CLOCK_BASE_SHIFT)
  49. & SDHCI_CLOCK_BASE_MASK) |
  50. SDHCI_TIMEOUT_CLK_UNIT |
  51. SDHCI_CAN_VDD_330 |
  52. SDHCI_CAN_DO_HISPD |
  53. SDHCI_CAN_DO_SDMA;
  54. return 0;
  55. }
  56. static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
  57. {
  58. /* Apply a delay to allow controller to settle */
  59. /* Otherwise it becomes confused if card state changed
  60. during suspend */
  61. msleep(500);
  62. return 0;
  63. }
  64. static const struct sdhci_pci_fixes sdhci_ricoh = {
  65. .probe = ricoh_probe,
  66. .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
  67. SDHCI_QUIRK_FORCE_DMA |
  68. SDHCI_QUIRK_CLOCK_BEFORE_RESET,
  69. };
  70. static const struct sdhci_pci_fixes sdhci_ricoh_mmc = {
  71. .probe_slot = ricoh_mmc_probe_slot,
  72. .resume = ricoh_mmc_resume,
  73. .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
  74. SDHCI_QUIRK_CLOCK_BEFORE_RESET |
  75. SDHCI_QUIRK_NO_CARD_NO_RESET |
  76. SDHCI_QUIRK_MISSING_CAPS
  77. };
  78. static const struct sdhci_pci_fixes sdhci_ene_712 = {
  79. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  80. SDHCI_QUIRK_BROKEN_DMA,
  81. };
  82. static const struct sdhci_pci_fixes sdhci_ene_714 = {
  83. .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE |
  84. SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS |
  85. SDHCI_QUIRK_BROKEN_DMA,
  86. };
  87. static const struct sdhci_pci_fixes sdhci_cafe = {
  88. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
  89. SDHCI_QUIRK_NO_BUSY_IRQ |
  90. SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  91. SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
  92. };
  93. static const struct sdhci_pci_fixes sdhci_intel_qrk = {
  94. .quirks = SDHCI_QUIRK_NO_HISPD_BIT,
  95. };
  96. static int mrst_hc_probe_slot(struct sdhci_pci_slot *slot)
  97. {
  98. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  99. return 0;
  100. }
  101. /*
  102. * ADMA operation is disabled for Moorestown platform due to
  103. * hardware bugs.
  104. */
  105. static int mrst_hc_probe(struct sdhci_pci_chip *chip)
  106. {
  107. /*
  108. * slots number is fixed here for MRST as SDIO3/5 are never used and
  109. * have hardware bugs.
  110. */
  111. chip->num_slots = 1;
  112. return 0;
  113. }
  114. static int pch_hc_probe_slot(struct sdhci_pci_slot *slot)
  115. {
  116. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  117. return 0;
  118. }
  119. #ifdef CONFIG_PM_RUNTIME
  120. static irqreturn_t sdhci_pci_sd_cd(int irq, void *dev_id)
  121. {
  122. struct sdhci_pci_slot *slot = dev_id;
  123. struct sdhci_host *host = slot->host;
  124. mmc_detect_change(host->mmc, msecs_to_jiffies(200));
  125. return IRQ_HANDLED;
  126. }
  127. static void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
  128. {
  129. int err, irq, gpio = slot->cd_gpio;
  130. slot->cd_gpio = -EINVAL;
  131. slot->cd_irq = -EINVAL;
  132. if (!gpio_is_valid(gpio))
  133. return;
  134. err = gpio_request(gpio, "sd_cd");
  135. if (err < 0)
  136. goto out;
  137. err = gpio_direction_input(gpio);
  138. if (err < 0)
  139. goto out_free;
  140. irq = gpio_to_irq(gpio);
  141. if (irq < 0)
  142. goto out_free;
  143. err = request_irq(irq, sdhci_pci_sd_cd, IRQF_TRIGGER_RISING |
  144. IRQF_TRIGGER_FALLING, "sd_cd", slot);
  145. if (err)
  146. goto out_free;
  147. slot->cd_gpio = gpio;
  148. slot->cd_irq = irq;
  149. return;
  150. out_free:
  151. gpio_free(gpio);
  152. out:
  153. dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
  154. }
  155. static void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
  156. {
  157. if (slot->cd_irq >= 0)
  158. free_irq(slot->cd_irq, slot);
  159. if (gpio_is_valid(slot->cd_gpio))
  160. gpio_free(slot->cd_gpio);
  161. }
  162. #else
  163. static inline void sdhci_pci_add_own_cd(struct sdhci_pci_slot *slot)
  164. {
  165. }
  166. static inline void sdhci_pci_remove_own_cd(struct sdhci_pci_slot *slot)
  167. {
  168. }
  169. #endif
  170. static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
  171. {
  172. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
  173. slot->host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC |
  174. MMC_CAP2_HC_ERASE_SZ;
  175. return 0;
  176. }
  177. static int mfd_sdio_probe_slot(struct sdhci_pci_slot *slot)
  178. {
  179. slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
  180. return 0;
  181. }
  182. static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
  183. .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
  184. .probe_slot = mrst_hc_probe_slot,
  185. };
  186. static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
  187. .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
  188. .probe = mrst_hc_probe,
  189. };
  190. static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
  191. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  192. .allow_runtime_pm = true,
  193. .own_cd_for_runtime_pm = true,
  194. };
  195. static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
  196. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  197. .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
  198. .allow_runtime_pm = true,
  199. .probe_slot = mfd_sdio_probe_slot,
  200. };
  201. static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
  202. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  203. .allow_runtime_pm = true,
  204. .probe_slot = mfd_emmc_probe_slot,
  205. };
  206. static const struct sdhci_pci_fixes sdhci_intel_pch_sdio = {
  207. .quirks = SDHCI_QUIRK_BROKEN_ADMA,
  208. .probe_slot = pch_hc_probe_slot,
  209. };
  210. static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
  211. {
  212. u8 reg;
  213. reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
  214. reg |= 0x10;
  215. sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
  216. /* For eMMC, minimum is 1us but give it 9us for good measure */
  217. udelay(9);
  218. reg &= ~0x10;
  219. sdhci_writeb(host, reg, SDHCI_POWER_CONTROL);
  220. /* For eMMC, minimum is 200us but give it 300us for good measure */
  221. usleep_range(300, 1000);
  222. }
  223. static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
  224. {
  225. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
  226. MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR;
  227. slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
  228. slot->hw_reset = sdhci_pci_int_hw_reset;
  229. if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
  230. slot->host->timeout_clk = 1000; /* 1000 kHz i.e. 1 MHz */
  231. return 0;
  232. }
  233. static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
  234. {
  235. slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE;
  236. return 0;
  237. }
  238. static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
  239. {
  240. slot->cd_con_id = NULL;
  241. slot->cd_idx = 0;
  242. slot->cd_override_level = true;
  243. return 0;
  244. }
  245. static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
  246. .allow_runtime_pm = true,
  247. .probe_slot = byt_emmc_probe_slot,
  248. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  249. SDHCI_QUIRK2_STOP_WITH_TC,
  250. };
  251. static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
  252. .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
  253. SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  254. .allow_runtime_pm = true,
  255. .probe_slot = byt_sdio_probe_slot,
  256. };
  257. static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
  258. .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
  259. SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  260. SDHCI_QUIRK2_STOP_WITH_TC,
  261. .allow_runtime_pm = true,
  262. .own_cd_for_runtime_pm = true,
  263. .probe_slot = byt_sd_probe_slot,
  264. };
  265. /* Define Host controllers for Intel Merrifield platform */
  266. #define INTEL_MRFL_EMMC_0 0
  267. #define INTEL_MRFL_EMMC_1 1
  268. static int intel_mrfl_mmc_probe_slot(struct sdhci_pci_slot *slot)
  269. {
  270. if ((PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_0) &&
  271. (PCI_FUNC(slot->chip->pdev->devfn) != INTEL_MRFL_EMMC_1))
  272. /* SD support is not ready yet */
  273. return -ENODEV;
  274. slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
  275. MMC_CAP_1_8V_DDR;
  276. return 0;
  277. }
  278. static const struct sdhci_pci_fixes sdhci_intel_mrfl_mmc = {
  279. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  280. .quirks2 = SDHCI_QUIRK2_BROKEN_HS200 |
  281. SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
  282. .allow_runtime_pm = true,
  283. .probe_slot = intel_mrfl_mmc_probe_slot,
  284. };
  285. /* O2Micro extra registers */
  286. #define O2_SD_LOCK_WP 0xD3
  287. #define O2_SD_MULTI_VCC3V 0xEE
  288. #define O2_SD_CLKREQ 0xEC
  289. #define O2_SD_CAPS 0xE0
  290. #define O2_SD_ADMA1 0xE2
  291. #define O2_SD_ADMA2 0xE7
  292. #define O2_SD_INF_MOD 0xF1
  293. static int jmicron_pmos(struct sdhci_pci_chip *chip, int on)
  294. {
  295. u8 scratch;
  296. int ret;
  297. ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch);
  298. if (ret)
  299. return ret;
  300. /*
  301. * Turn PMOS on [bit 0], set over current detection to 2.4 V
  302. * [bit 1:2] and enable over current debouncing [bit 6].
  303. */
  304. if (on)
  305. scratch |= 0x47;
  306. else
  307. scratch &= ~0x47;
  308. ret = pci_write_config_byte(chip->pdev, 0xAE, scratch);
  309. if (ret)
  310. return ret;
  311. return 0;
  312. }
  313. static int jmicron_probe(struct sdhci_pci_chip *chip)
  314. {
  315. int ret;
  316. u16 mmcdev = 0;
  317. if (chip->pdev->revision == 0) {
  318. chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR |
  319. SDHCI_QUIRK_32BIT_DMA_SIZE |
  320. SDHCI_QUIRK_32BIT_ADMA_SIZE |
  321. SDHCI_QUIRK_RESET_AFTER_REQUEST |
  322. SDHCI_QUIRK_BROKEN_SMALL_PIO;
  323. }
  324. /*
  325. * JMicron chips can have two interfaces to the same hardware
  326. * in order to work around limitations in Microsoft's driver.
  327. * We need to make sure we only bind to one of them.
  328. *
  329. * This code assumes two things:
  330. *
  331. * 1. The PCI code adds subfunctions in order.
  332. *
  333. * 2. The MMC interface has a lower subfunction number
  334. * than the SD interface.
  335. */
  336. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD)
  337. mmcdev = PCI_DEVICE_ID_JMICRON_JMB38X_MMC;
  338. else if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD)
  339. mmcdev = PCI_DEVICE_ID_JMICRON_JMB388_ESD;
  340. if (mmcdev) {
  341. struct pci_dev *sd_dev;
  342. sd_dev = NULL;
  343. while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON,
  344. mmcdev, sd_dev)) != NULL) {
  345. if ((PCI_SLOT(chip->pdev->devfn) ==
  346. PCI_SLOT(sd_dev->devfn)) &&
  347. (chip->pdev->bus == sd_dev->bus))
  348. break;
  349. }
  350. if (sd_dev) {
  351. pci_dev_put(sd_dev);
  352. dev_info(&chip->pdev->dev, "Refusing to bind to "
  353. "secondary interface.\n");
  354. return -ENODEV;
  355. }
  356. }
  357. /*
  358. * JMicron chips need a bit of a nudge to enable the power
  359. * output pins.
  360. */
  361. ret = jmicron_pmos(chip, 1);
  362. if (ret) {
  363. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  364. return ret;
  365. }
  366. /* quirk for unsable RO-detection on JM388 chips */
  367. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_SD ||
  368. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  369. chip->quirks |= SDHCI_QUIRK_UNSTABLE_RO_DETECT;
  370. return 0;
  371. }
  372. static void jmicron_enable_mmc(struct sdhci_host *host, int on)
  373. {
  374. u8 scratch;
  375. scratch = readb(host->ioaddr + 0xC0);
  376. if (on)
  377. scratch |= 0x01;
  378. else
  379. scratch &= ~0x01;
  380. writeb(scratch, host->ioaddr + 0xC0);
  381. }
  382. static int jmicron_probe_slot(struct sdhci_pci_slot *slot)
  383. {
  384. if (slot->chip->pdev->revision == 0) {
  385. u16 version;
  386. version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION);
  387. version = (version & SDHCI_VENDOR_VER_MASK) >>
  388. SDHCI_VENDOR_VER_SHIFT;
  389. /*
  390. * Older versions of the chip have lots of nasty glitches
  391. * in the ADMA engine. It's best just to avoid it
  392. * completely.
  393. */
  394. if (version < 0xAC)
  395. slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA;
  396. }
  397. /* JM388 MMC doesn't support 1.8V while SD supports it */
  398. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  399. slot->host->ocr_avail_sd = MMC_VDD_32_33 | MMC_VDD_33_34 |
  400. MMC_VDD_29_30 | MMC_VDD_30_31 |
  401. MMC_VDD_165_195; /* allow 1.8V */
  402. slot->host->ocr_avail_mmc = MMC_VDD_32_33 | MMC_VDD_33_34 |
  403. MMC_VDD_29_30 | MMC_VDD_30_31; /* no 1.8V for MMC */
  404. }
  405. /*
  406. * The secondary interface requires a bit set to get the
  407. * interrupts.
  408. */
  409. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  410. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  411. jmicron_enable_mmc(slot->host, 1);
  412. slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST;
  413. return 0;
  414. }
  415. static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
  416. {
  417. if (dead)
  418. return;
  419. if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  420. slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD)
  421. jmicron_enable_mmc(slot->host, 0);
  422. }
  423. static int jmicron_suspend(struct sdhci_pci_chip *chip)
  424. {
  425. int i;
  426. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  427. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  428. for (i = 0; i < chip->num_slots; i++)
  429. jmicron_enable_mmc(chip->slots[i]->host, 0);
  430. }
  431. return 0;
  432. }
  433. static int jmicron_resume(struct sdhci_pci_chip *chip)
  434. {
  435. int ret, i;
  436. if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
  437. chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
  438. for (i = 0; i < chip->num_slots; i++)
  439. jmicron_enable_mmc(chip->slots[i]->host, 1);
  440. }
  441. ret = jmicron_pmos(chip, 1);
  442. if (ret) {
  443. dev_err(&chip->pdev->dev, "Failure enabling card power\n");
  444. return ret;
  445. }
  446. return 0;
  447. }
  448. static const struct sdhci_pci_fixes sdhci_o2 = {
  449. .probe = sdhci_pci_o2_probe,
  450. .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
  451. .probe_slot = sdhci_pci_o2_probe_slot,
  452. .resume = sdhci_pci_o2_resume,
  453. };
  454. static const struct sdhci_pci_fixes sdhci_jmicron = {
  455. .probe = jmicron_probe,
  456. .probe_slot = jmicron_probe_slot,
  457. .remove_slot = jmicron_remove_slot,
  458. .suspend = jmicron_suspend,
  459. .resume = jmicron_resume,
  460. };
  461. /* SysKonnect CardBus2SDIO extra registers */
  462. #define SYSKT_CTRL 0x200
  463. #define SYSKT_RDFIFO_STAT 0x204
  464. #define SYSKT_WRFIFO_STAT 0x208
  465. #define SYSKT_POWER_DATA 0x20c
  466. #define SYSKT_POWER_330 0xef
  467. #define SYSKT_POWER_300 0xf8
  468. #define SYSKT_POWER_184 0xcc
  469. #define SYSKT_POWER_CMD 0x20d
  470. #define SYSKT_POWER_START (1 << 7)
  471. #define SYSKT_POWER_STATUS 0x20e
  472. #define SYSKT_POWER_STATUS_OK (1 << 0)
  473. #define SYSKT_BOARD_REV 0x210
  474. #define SYSKT_CHIP_REV 0x211
  475. #define SYSKT_CONF_DATA 0x212
  476. #define SYSKT_CONF_DATA_1V8 (1 << 2)
  477. #define SYSKT_CONF_DATA_2V5 (1 << 1)
  478. #define SYSKT_CONF_DATA_3V3 (1 << 0)
  479. static int syskt_probe(struct sdhci_pci_chip *chip)
  480. {
  481. if ((chip->pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  482. chip->pdev->class &= ~0x0000FF;
  483. chip->pdev->class |= PCI_SDHCI_IFDMA;
  484. }
  485. return 0;
  486. }
  487. static int syskt_probe_slot(struct sdhci_pci_slot *slot)
  488. {
  489. int tm, ps;
  490. u8 board_rev = readb(slot->host->ioaddr + SYSKT_BOARD_REV);
  491. u8 chip_rev = readb(slot->host->ioaddr + SYSKT_CHIP_REV);
  492. dev_info(&slot->chip->pdev->dev, "SysKonnect CardBus2SDIO, "
  493. "board rev %d.%d, chip rev %d.%d\n",
  494. board_rev >> 4, board_rev & 0xf,
  495. chip_rev >> 4, chip_rev & 0xf);
  496. if (chip_rev >= 0x20)
  497. slot->host->quirks |= SDHCI_QUIRK_FORCE_DMA;
  498. writeb(SYSKT_POWER_330, slot->host->ioaddr + SYSKT_POWER_DATA);
  499. writeb(SYSKT_POWER_START, slot->host->ioaddr + SYSKT_POWER_CMD);
  500. udelay(50);
  501. tm = 10; /* Wait max 1 ms */
  502. do {
  503. ps = readw(slot->host->ioaddr + SYSKT_POWER_STATUS);
  504. if (ps & SYSKT_POWER_STATUS_OK)
  505. break;
  506. udelay(100);
  507. } while (--tm);
  508. if (!tm) {
  509. dev_err(&slot->chip->pdev->dev,
  510. "power regulator never stabilized");
  511. writeb(0, slot->host->ioaddr + SYSKT_POWER_CMD);
  512. return -ENODEV;
  513. }
  514. return 0;
  515. }
  516. static const struct sdhci_pci_fixes sdhci_syskt = {
  517. .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER,
  518. .probe = syskt_probe,
  519. .probe_slot = syskt_probe_slot,
  520. };
  521. static int via_probe(struct sdhci_pci_chip *chip)
  522. {
  523. if (chip->pdev->revision == 0x10)
  524. chip->quirks |= SDHCI_QUIRK_DELAY_AFTER_POWER;
  525. return 0;
  526. }
  527. static const struct sdhci_pci_fixes sdhci_via = {
  528. .probe = via_probe,
  529. };
  530. static int rtsx_probe_slot(struct sdhci_pci_slot *slot)
  531. {
  532. slot->host->mmc->caps2 |= MMC_CAP2_HS200;
  533. return 0;
  534. }
  535. static const struct sdhci_pci_fixes sdhci_rtsx = {
  536. .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
  537. SDHCI_QUIRK2_BROKEN_DDR50,
  538. .probe_slot = rtsx_probe_slot,
  539. };
  540. static const struct pci_device_id pci_ids[] = {
  541. {
  542. .vendor = PCI_VENDOR_ID_RICOH,
  543. .device = PCI_DEVICE_ID_RICOH_R5C822,
  544. .subvendor = PCI_ANY_ID,
  545. .subdevice = PCI_ANY_ID,
  546. .driver_data = (kernel_ulong_t)&sdhci_ricoh,
  547. },
  548. {
  549. .vendor = PCI_VENDOR_ID_RICOH,
  550. .device = 0x843,
  551. .subvendor = PCI_ANY_ID,
  552. .subdevice = PCI_ANY_ID,
  553. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  554. },
  555. {
  556. .vendor = PCI_VENDOR_ID_RICOH,
  557. .device = 0xe822,
  558. .subvendor = PCI_ANY_ID,
  559. .subdevice = PCI_ANY_ID,
  560. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  561. },
  562. {
  563. .vendor = PCI_VENDOR_ID_RICOH,
  564. .device = 0xe823,
  565. .subvendor = PCI_ANY_ID,
  566. .subdevice = PCI_ANY_ID,
  567. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  568. },
  569. {
  570. .vendor = PCI_VENDOR_ID_ENE,
  571. .device = PCI_DEVICE_ID_ENE_CB712_SD,
  572. .subvendor = PCI_ANY_ID,
  573. .subdevice = PCI_ANY_ID,
  574. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  575. },
  576. {
  577. .vendor = PCI_VENDOR_ID_ENE,
  578. .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
  579. .subvendor = PCI_ANY_ID,
  580. .subdevice = PCI_ANY_ID,
  581. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  582. },
  583. {
  584. .vendor = PCI_VENDOR_ID_ENE,
  585. .device = PCI_DEVICE_ID_ENE_CB714_SD,
  586. .subvendor = PCI_ANY_ID,
  587. .subdevice = PCI_ANY_ID,
  588. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  589. },
  590. {
  591. .vendor = PCI_VENDOR_ID_ENE,
  592. .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
  593. .subvendor = PCI_ANY_ID,
  594. .subdevice = PCI_ANY_ID,
  595. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  596. },
  597. {
  598. .vendor = PCI_VENDOR_ID_MARVELL,
  599. .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
  600. .subvendor = PCI_ANY_ID,
  601. .subdevice = PCI_ANY_ID,
  602. .driver_data = (kernel_ulong_t)&sdhci_cafe,
  603. },
  604. {
  605. .vendor = PCI_VENDOR_ID_JMICRON,
  606. .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
  607. .subvendor = PCI_ANY_ID,
  608. .subdevice = PCI_ANY_ID,
  609. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  610. },
  611. {
  612. .vendor = PCI_VENDOR_ID_JMICRON,
  613. .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
  614. .subvendor = PCI_ANY_ID,
  615. .subdevice = PCI_ANY_ID,
  616. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  617. },
  618. {
  619. .vendor = PCI_VENDOR_ID_JMICRON,
  620. .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
  621. .subvendor = PCI_ANY_ID,
  622. .subdevice = PCI_ANY_ID,
  623. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  624. },
  625. {
  626. .vendor = PCI_VENDOR_ID_JMICRON,
  627. .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
  628. .subvendor = PCI_ANY_ID,
  629. .subdevice = PCI_ANY_ID,
  630. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  631. },
  632. {
  633. .vendor = PCI_VENDOR_ID_SYSKONNECT,
  634. .device = 0x8000,
  635. .subvendor = PCI_ANY_ID,
  636. .subdevice = PCI_ANY_ID,
  637. .driver_data = (kernel_ulong_t)&sdhci_syskt,
  638. },
  639. {
  640. .vendor = PCI_VENDOR_ID_VIA,
  641. .device = 0x95d0,
  642. .subvendor = PCI_ANY_ID,
  643. .subdevice = PCI_ANY_ID,
  644. .driver_data = (kernel_ulong_t)&sdhci_via,
  645. },
  646. {
  647. .vendor = PCI_VENDOR_ID_REALTEK,
  648. .device = 0x5250,
  649. .subvendor = PCI_ANY_ID,
  650. .subdevice = PCI_ANY_ID,
  651. .driver_data = (kernel_ulong_t)&sdhci_rtsx,
  652. },
  653. {
  654. .vendor = PCI_VENDOR_ID_INTEL,
  655. .device = PCI_DEVICE_ID_INTEL_QRK_SD,
  656. .subvendor = PCI_ANY_ID,
  657. .subdevice = PCI_ANY_ID,
  658. .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
  659. },
  660. {
  661. .vendor = PCI_VENDOR_ID_INTEL,
  662. .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
  663. .subvendor = PCI_ANY_ID,
  664. .subdevice = PCI_ANY_ID,
  665. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
  666. },
  667. {
  668. .vendor = PCI_VENDOR_ID_INTEL,
  669. .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
  670. .subvendor = PCI_ANY_ID,
  671. .subdevice = PCI_ANY_ID,
  672. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  673. },
  674. {
  675. .vendor = PCI_VENDOR_ID_INTEL,
  676. .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
  677. .subvendor = PCI_ANY_ID,
  678. .subdevice = PCI_ANY_ID,
  679. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  680. },
  681. {
  682. .vendor = PCI_VENDOR_ID_INTEL,
  683. .device = PCI_DEVICE_ID_INTEL_MFD_SD,
  684. .subvendor = PCI_ANY_ID,
  685. .subdevice = PCI_ANY_ID,
  686. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  687. },
  688. {
  689. .vendor = PCI_VENDOR_ID_INTEL,
  690. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
  691. .subvendor = PCI_ANY_ID,
  692. .subdevice = PCI_ANY_ID,
  693. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  694. },
  695. {
  696. .vendor = PCI_VENDOR_ID_INTEL,
  697. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
  698. .subvendor = PCI_ANY_ID,
  699. .subdevice = PCI_ANY_ID,
  700. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  701. },
  702. {
  703. .vendor = PCI_VENDOR_ID_INTEL,
  704. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
  705. .subvendor = PCI_ANY_ID,
  706. .subdevice = PCI_ANY_ID,
  707. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  708. },
  709. {
  710. .vendor = PCI_VENDOR_ID_INTEL,
  711. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
  712. .subvendor = PCI_ANY_ID,
  713. .subdevice = PCI_ANY_ID,
  714. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  715. },
  716. {
  717. .vendor = PCI_VENDOR_ID_INTEL,
  718. .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
  719. .subvendor = PCI_ANY_ID,
  720. .subdevice = PCI_ANY_ID,
  721. .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
  722. },
  723. {
  724. .vendor = PCI_VENDOR_ID_INTEL,
  725. .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
  726. .subvendor = PCI_ANY_ID,
  727. .subdevice = PCI_ANY_ID,
  728. .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
  729. },
  730. {
  731. .vendor = PCI_VENDOR_ID_INTEL,
  732. .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
  733. .subvendor = PCI_ANY_ID,
  734. .subdevice = PCI_ANY_ID,
  735. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  736. },
  737. {
  738. .vendor = PCI_VENDOR_ID_INTEL,
  739. .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
  740. .subvendor = PCI_ANY_ID,
  741. .subdevice = PCI_ANY_ID,
  742. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  743. },
  744. {
  745. .vendor = PCI_VENDOR_ID_INTEL,
  746. .device = PCI_DEVICE_ID_INTEL_BYT_SD,
  747. .subvendor = PCI_ANY_ID,
  748. .subdevice = PCI_ANY_ID,
  749. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  750. },
  751. {
  752. .vendor = PCI_VENDOR_ID_INTEL,
  753. .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
  754. .subvendor = PCI_ANY_ID,
  755. .subdevice = PCI_ANY_ID,
  756. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  757. },
  758. {
  759. .vendor = PCI_VENDOR_ID_INTEL,
  760. .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
  761. .subvendor = PCI_ANY_ID,
  762. .subdevice = PCI_ANY_ID,
  763. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  764. },
  765. {
  766. .vendor = PCI_VENDOR_ID_INTEL,
  767. .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
  768. .subvendor = PCI_ANY_ID,
  769. .subdevice = PCI_ANY_ID,
  770. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  771. },
  772. {
  773. .vendor = PCI_VENDOR_ID_INTEL,
  774. .device = PCI_DEVICE_ID_INTEL_BSW_SD,
  775. .subvendor = PCI_ANY_ID,
  776. .subdevice = PCI_ANY_ID,
  777. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  778. },
  779. {
  780. .vendor = PCI_VENDOR_ID_INTEL,
  781. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
  782. .subvendor = PCI_ANY_ID,
  783. .subdevice = PCI_ANY_ID,
  784. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  785. },
  786. {
  787. .vendor = PCI_VENDOR_ID_INTEL,
  788. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
  789. .subvendor = PCI_ANY_ID,
  790. .subdevice = PCI_ANY_ID,
  791. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  792. },
  793. {
  794. .vendor = PCI_VENDOR_ID_INTEL,
  795. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
  796. .subvendor = PCI_ANY_ID,
  797. .subdevice = PCI_ANY_ID,
  798. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  799. },
  800. {
  801. .vendor = PCI_VENDOR_ID_INTEL,
  802. .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
  803. .subvendor = PCI_ANY_ID,
  804. .subdevice = PCI_ANY_ID,
  805. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  806. },
  807. {
  808. .vendor = PCI_VENDOR_ID_INTEL,
  809. .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
  810. .subvendor = PCI_ANY_ID,
  811. .subdevice = PCI_ANY_ID,
  812. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  813. },
  814. {
  815. .vendor = PCI_VENDOR_ID_INTEL,
  816. .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
  817. .subvendor = PCI_ANY_ID,
  818. .subdevice = PCI_ANY_ID,
  819. .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
  820. },
  821. {
  822. .vendor = PCI_VENDOR_ID_O2,
  823. .device = PCI_DEVICE_ID_O2_8120,
  824. .subvendor = PCI_ANY_ID,
  825. .subdevice = PCI_ANY_ID,
  826. .driver_data = (kernel_ulong_t)&sdhci_o2,
  827. },
  828. {
  829. .vendor = PCI_VENDOR_ID_O2,
  830. .device = PCI_DEVICE_ID_O2_8220,
  831. .subvendor = PCI_ANY_ID,
  832. .subdevice = PCI_ANY_ID,
  833. .driver_data = (kernel_ulong_t)&sdhci_o2,
  834. },
  835. {
  836. .vendor = PCI_VENDOR_ID_O2,
  837. .device = PCI_DEVICE_ID_O2_8221,
  838. .subvendor = PCI_ANY_ID,
  839. .subdevice = PCI_ANY_ID,
  840. .driver_data = (kernel_ulong_t)&sdhci_o2,
  841. },
  842. {
  843. .vendor = PCI_VENDOR_ID_O2,
  844. .device = PCI_DEVICE_ID_O2_8320,
  845. .subvendor = PCI_ANY_ID,
  846. .subdevice = PCI_ANY_ID,
  847. .driver_data = (kernel_ulong_t)&sdhci_o2,
  848. },
  849. {
  850. .vendor = PCI_VENDOR_ID_O2,
  851. .device = PCI_DEVICE_ID_O2_8321,
  852. .subvendor = PCI_ANY_ID,
  853. .subdevice = PCI_ANY_ID,
  854. .driver_data = (kernel_ulong_t)&sdhci_o2,
  855. },
  856. {
  857. .vendor = PCI_VENDOR_ID_O2,
  858. .device = PCI_DEVICE_ID_O2_FUJIN2,
  859. .subvendor = PCI_ANY_ID,
  860. .subdevice = PCI_ANY_ID,
  861. .driver_data = (kernel_ulong_t)&sdhci_o2,
  862. },
  863. {
  864. .vendor = PCI_VENDOR_ID_O2,
  865. .device = PCI_DEVICE_ID_O2_SDS0,
  866. .subvendor = PCI_ANY_ID,
  867. .subdevice = PCI_ANY_ID,
  868. .driver_data = (kernel_ulong_t)&sdhci_o2,
  869. },
  870. {
  871. .vendor = PCI_VENDOR_ID_O2,
  872. .device = PCI_DEVICE_ID_O2_SDS1,
  873. .subvendor = PCI_ANY_ID,
  874. .subdevice = PCI_ANY_ID,
  875. .driver_data = (kernel_ulong_t)&sdhci_o2,
  876. },
  877. {
  878. .vendor = PCI_VENDOR_ID_O2,
  879. .device = PCI_DEVICE_ID_O2_SEABIRD0,
  880. .subvendor = PCI_ANY_ID,
  881. .subdevice = PCI_ANY_ID,
  882. .driver_data = (kernel_ulong_t)&sdhci_o2,
  883. },
  884. {
  885. .vendor = PCI_VENDOR_ID_O2,
  886. .device = PCI_DEVICE_ID_O2_SEABIRD1,
  887. .subvendor = PCI_ANY_ID,
  888. .subdevice = PCI_ANY_ID,
  889. .driver_data = (kernel_ulong_t)&sdhci_o2,
  890. },
  891. { /* Generic SD host controller */
  892. PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
  893. },
  894. { /* end: all zeroes */ },
  895. };
  896. MODULE_DEVICE_TABLE(pci, pci_ids);
  897. /*****************************************************************************\
  898. * *
  899. * SDHCI core callbacks *
  900. * *
  901. \*****************************************************************************/
  902. static int sdhci_pci_enable_dma(struct sdhci_host *host)
  903. {
  904. struct sdhci_pci_slot *slot;
  905. struct pci_dev *pdev;
  906. int ret;
  907. slot = sdhci_priv(host);
  908. pdev = slot->chip->pdev;
  909. if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
  910. ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
  911. (host->flags & SDHCI_USE_SDMA)) {
  912. dev_warn(&pdev->dev, "Will use DMA mode even though HW "
  913. "doesn't fully claim to support it.\n");
  914. }
  915. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  916. if (ret)
  917. return ret;
  918. pci_set_master(pdev);
  919. return 0;
  920. }
  921. static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
  922. {
  923. u8 ctrl;
  924. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  925. switch (width) {
  926. case MMC_BUS_WIDTH_8:
  927. ctrl |= SDHCI_CTRL_8BITBUS;
  928. ctrl &= ~SDHCI_CTRL_4BITBUS;
  929. break;
  930. case MMC_BUS_WIDTH_4:
  931. ctrl |= SDHCI_CTRL_4BITBUS;
  932. ctrl &= ~SDHCI_CTRL_8BITBUS;
  933. break;
  934. default:
  935. ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
  936. break;
  937. }
  938. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  939. }
  940. static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
  941. {
  942. struct sdhci_pci_slot *slot = sdhci_priv(host);
  943. int rst_n_gpio = slot->rst_n_gpio;
  944. if (!gpio_is_valid(rst_n_gpio))
  945. return;
  946. gpio_set_value_cansleep(rst_n_gpio, 0);
  947. /* For eMMC, minimum is 1us but give it 10us for good measure */
  948. udelay(10);
  949. gpio_set_value_cansleep(rst_n_gpio, 1);
  950. /* For eMMC, minimum is 200us but give it 300us for good measure */
  951. usleep_range(300, 1000);
  952. }
  953. static void sdhci_pci_hw_reset(struct sdhci_host *host)
  954. {
  955. struct sdhci_pci_slot *slot = sdhci_priv(host);
  956. if (slot->hw_reset)
  957. slot->hw_reset(host);
  958. }
  959. static const struct sdhci_ops sdhci_pci_ops = {
  960. .set_clock = sdhci_set_clock,
  961. .enable_dma = sdhci_pci_enable_dma,
  962. .set_bus_width = sdhci_pci_set_bus_width,
  963. .reset = sdhci_reset,
  964. .set_uhs_signaling = sdhci_set_uhs_signaling,
  965. .hw_reset = sdhci_pci_hw_reset,
  966. };
  967. /*****************************************************************************\
  968. * *
  969. * Suspend/resume *
  970. * *
  971. \*****************************************************************************/
  972. #ifdef CONFIG_PM
  973. static int sdhci_pci_suspend(struct device *dev)
  974. {
  975. struct pci_dev *pdev = to_pci_dev(dev);
  976. struct sdhci_pci_chip *chip;
  977. struct sdhci_pci_slot *slot;
  978. mmc_pm_flag_t slot_pm_flags;
  979. mmc_pm_flag_t pm_flags = 0;
  980. int i, ret;
  981. chip = pci_get_drvdata(pdev);
  982. if (!chip)
  983. return 0;
  984. for (i = 0; i < chip->num_slots; i++) {
  985. slot = chip->slots[i];
  986. if (!slot)
  987. continue;
  988. ret = sdhci_suspend_host(slot->host);
  989. if (ret)
  990. goto err_pci_suspend;
  991. slot_pm_flags = slot->host->mmc->pm_flags;
  992. if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  993. sdhci_enable_irq_wakeups(slot->host);
  994. pm_flags |= slot_pm_flags;
  995. }
  996. if (chip->fixes && chip->fixes->suspend) {
  997. ret = chip->fixes->suspend(chip);
  998. if (ret)
  999. goto err_pci_suspend;
  1000. }
  1001. if (pm_flags & MMC_PM_KEEP_POWER) {
  1002. if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  1003. device_init_wakeup(dev, true);
  1004. else
  1005. device_init_wakeup(dev, false);
  1006. } else
  1007. device_init_wakeup(dev, false);
  1008. return 0;
  1009. err_pci_suspend:
  1010. while (--i >= 0)
  1011. sdhci_resume_host(chip->slots[i]->host);
  1012. return ret;
  1013. }
  1014. static int sdhci_pci_resume(struct device *dev)
  1015. {
  1016. struct pci_dev *pdev = to_pci_dev(dev);
  1017. struct sdhci_pci_chip *chip;
  1018. struct sdhci_pci_slot *slot;
  1019. int i, ret;
  1020. chip = pci_get_drvdata(pdev);
  1021. if (!chip)
  1022. return 0;
  1023. if (chip->fixes && chip->fixes->resume) {
  1024. ret = chip->fixes->resume(chip);
  1025. if (ret)
  1026. return ret;
  1027. }
  1028. for (i = 0; i < chip->num_slots; i++) {
  1029. slot = chip->slots[i];
  1030. if (!slot)
  1031. continue;
  1032. ret = sdhci_resume_host(slot->host);
  1033. if (ret)
  1034. return ret;
  1035. }
  1036. return 0;
  1037. }
  1038. #else /* CONFIG_PM */
  1039. #define sdhci_pci_suspend NULL
  1040. #define sdhci_pci_resume NULL
  1041. #endif /* CONFIG_PM */
  1042. #ifdef CONFIG_PM_RUNTIME
  1043. static int sdhci_pci_runtime_suspend(struct device *dev)
  1044. {
  1045. struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
  1046. struct sdhci_pci_chip *chip;
  1047. struct sdhci_pci_slot *slot;
  1048. int i, ret;
  1049. chip = pci_get_drvdata(pdev);
  1050. if (!chip)
  1051. return 0;
  1052. for (i = 0; i < chip->num_slots; i++) {
  1053. slot = chip->slots[i];
  1054. if (!slot)
  1055. continue;
  1056. ret = sdhci_runtime_suspend_host(slot->host);
  1057. if (ret)
  1058. goto err_pci_runtime_suspend;
  1059. }
  1060. if (chip->fixes && chip->fixes->suspend) {
  1061. ret = chip->fixes->suspend(chip);
  1062. if (ret)
  1063. goto err_pci_runtime_suspend;
  1064. }
  1065. return 0;
  1066. err_pci_runtime_suspend:
  1067. while (--i >= 0)
  1068. sdhci_runtime_resume_host(chip->slots[i]->host);
  1069. return ret;
  1070. }
  1071. static int sdhci_pci_runtime_resume(struct device *dev)
  1072. {
  1073. struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
  1074. struct sdhci_pci_chip *chip;
  1075. struct sdhci_pci_slot *slot;
  1076. int i, ret;
  1077. chip = pci_get_drvdata(pdev);
  1078. if (!chip)
  1079. return 0;
  1080. if (chip->fixes && chip->fixes->resume) {
  1081. ret = chip->fixes->resume(chip);
  1082. if (ret)
  1083. return ret;
  1084. }
  1085. for (i = 0; i < chip->num_slots; i++) {
  1086. slot = chip->slots[i];
  1087. if (!slot)
  1088. continue;
  1089. ret = sdhci_runtime_resume_host(slot->host);
  1090. if (ret)
  1091. return ret;
  1092. }
  1093. return 0;
  1094. }
  1095. static int sdhci_pci_runtime_idle(struct device *dev)
  1096. {
  1097. return 0;
  1098. }
  1099. #endif
  1100. static const struct dev_pm_ops sdhci_pci_pm_ops = {
  1101. .suspend = sdhci_pci_suspend,
  1102. .resume = sdhci_pci_resume,
  1103. SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
  1104. sdhci_pci_runtime_resume, sdhci_pci_runtime_idle)
  1105. };
  1106. /*****************************************************************************\
  1107. * *
  1108. * Device probing/removal *
  1109. * *
  1110. \*****************************************************************************/
  1111. static struct sdhci_pci_slot *sdhci_pci_probe_slot(
  1112. struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
  1113. int slotno)
  1114. {
  1115. struct sdhci_pci_slot *slot;
  1116. struct sdhci_host *host;
  1117. int ret, bar = first_bar + slotno;
  1118. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  1119. dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
  1120. return ERR_PTR(-ENODEV);
  1121. }
  1122. if (pci_resource_len(pdev, bar) < 0x100) {
  1123. dev_err(&pdev->dev, "Invalid iomem size. You may "
  1124. "experience problems.\n");
  1125. }
  1126. if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  1127. dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
  1128. return ERR_PTR(-ENODEV);
  1129. }
  1130. if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
  1131. dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
  1132. return ERR_PTR(-ENODEV);
  1133. }
  1134. host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
  1135. if (IS_ERR(host)) {
  1136. dev_err(&pdev->dev, "cannot allocate host\n");
  1137. return ERR_CAST(host);
  1138. }
  1139. slot = sdhci_priv(host);
  1140. slot->chip = chip;
  1141. slot->host = host;
  1142. slot->pci_bar = bar;
  1143. slot->rst_n_gpio = -EINVAL;
  1144. slot->cd_gpio = -EINVAL;
  1145. slot->cd_idx = -1;
  1146. /* Retrieve platform data if there is any */
  1147. if (*sdhci_pci_get_data)
  1148. slot->data = sdhci_pci_get_data(pdev, slotno);
  1149. if (slot->data) {
  1150. if (slot->data->setup) {
  1151. ret = slot->data->setup(slot->data);
  1152. if (ret) {
  1153. dev_err(&pdev->dev, "platform setup failed\n");
  1154. goto free;
  1155. }
  1156. }
  1157. slot->rst_n_gpio = slot->data->rst_n_gpio;
  1158. slot->cd_gpio = slot->data->cd_gpio;
  1159. }
  1160. host->hw_name = "PCI";
  1161. host->ops = &sdhci_pci_ops;
  1162. host->quirks = chip->quirks;
  1163. host->quirks2 = chip->quirks2;
  1164. host->irq = pdev->irq;
  1165. ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
  1166. if (ret) {
  1167. dev_err(&pdev->dev, "cannot request region\n");
  1168. goto cleanup;
  1169. }
  1170. host->ioaddr = pci_ioremap_bar(pdev, bar);
  1171. if (!host->ioaddr) {
  1172. dev_err(&pdev->dev, "failed to remap registers\n");
  1173. ret = -ENOMEM;
  1174. goto release;
  1175. }
  1176. if (chip->fixes && chip->fixes->probe_slot) {
  1177. ret = chip->fixes->probe_slot(slot);
  1178. if (ret)
  1179. goto unmap;
  1180. }
  1181. if (gpio_is_valid(slot->rst_n_gpio)) {
  1182. if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
  1183. gpio_direction_output(slot->rst_n_gpio, 1);
  1184. slot->host->mmc->caps |= MMC_CAP_HW_RESET;
  1185. slot->hw_reset = sdhci_pci_gpio_hw_reset;
  1186. } else {
  1187. dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
  1188. slot->rst_n_gpio = -EINVAL;
  1189. }
  1190. }
  1191. host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
  1192. host->mmc->slotno = slotno;
  1193. host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
  1194. if (slot->cd_idx >= 0 &&
  1195. mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
  1196. slot->cd_override_level, 0, NULL)) {
  1197. dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
  1198. slot->cd_idx = -1;
  1199. }
  1200. ret = sdhci_add_host(host);
  1201. if (ret)
  1202. goto remove;
  1203. sdhci_pci_add_own_cd(slot);
  1204. /*
  1205. * Check if the chip needs a separate GPIO for card detect to wake up
  1206. * from runtime suspend. If it is not there, don't allow runtime PM.
  1207. * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
  1208. */
  1209. if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
  1210. !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0)
  1211. chip->allow_runtime_pm = false;
  1212. return slot;
  1213. remove:
  1214. if (gpio_is_valid(slot->rst_n_gpio))
  1215. gpio_free(slot->rst_n_gpio);
  1216. if (chip->fixes && chip->fixes->remove_slot)
  1217. chip->fixes->remove_slot(slot, 0);
  1218. unmap:
  1219. iounmap(host->ioaddr);
  1220. release:
  1221. pci_release_region(pdev, bar);
  1222. cleanup:
  1223. if (slot->data && slot->data->cleanup)
  1224. slot->data->cleanup(slot->data);
  1225. free:
  1226. sdhci_free_host(host);
  1227. return ERR_PTR(ret);
  1228. }
  1229. static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
  1230. {
  1231. int dead;
  1232. u32 scratch;
  1233. sdhci_pci_remove_own_cd(slot);
  1234. dead = 0;
  1235. scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
  1236. if (scratch == (u32)-1)
  1237. dead = 1;
  1238. sdhci_remove_host(slot->host, dead);
  1239. if (gpio_is_valid(slot->rst_n_gpio))
  1240. gpio_free(slot->rst_n_gpio);
  1241. if (slot->chip->fixes && slot->chip->fixes->remove_slot)
  1242. slot->chip->fixes->remove_slot(slot, dead);
  1243. if (slot->data && slot->data->cleanup)
  1244. slot->data->cleanup(slot->data);
  1245. pci_release_region(slot->chip->pdev, slot->pci_bar);
  1246. sdhci_free_host(slot->host);
  1247. }
  1248. static void sdhci_pci_runtime_pm_allow(struct device *dev)
  1249. {
  1250. pm_runtime_put_noidle(dev);
  1251. pm_runtime_allow(dev);
  1252. pm_runtime_set_autosuspend_delay(dev, 50);
  1253. pm_runtime_use_autosuspend(dev);
  1254. pm_suspend_ignore_children(dev, 1);
  1255. }
  1256. static void sdhci_pci_runtime_pm_forbid(struct device *dev)
  1257. {
  1258. pm_runtime_forbid(dev);
  1259. pm_runtime_get_noresume(dev);
  1260. }
  1261. static int sdhci_pci_probe(struct pci_dev *pdev,
  1262. const struct pci_device_id *ent)
  1263. {
  1264. struct sdhci_pci_chip *chip;
  1265. struct sdhci_pci_slot *slot;
  1266. u8 slots, first_bar;
  1267. int ret, i;
  1268. BUG_ON(pdev == NULL);
  1269. BUG_ON(ent == NULL);
  1270. dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
  1271. (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
  1272. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
  1273. if (ret)
  1274. return ret;
  1275. slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
  1276. dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
  1277. if (slots == 0)
  1278. return -ENODEV;
  1279. BUG_ON(slots > MAX_SLOTS);
  1280. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
  1281. if (ret)
  1282. return ret;
  1283. first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
  1284. if (first_bar > 5) {
  1285. dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
  1286. return -ENODEV;
  1287. }
  1288. ret = pci_enable_device(pdev);
  1289. if (ret)
  1290. return ret;
  1291. chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
  1292. if (!chip) {
  1293. ret = -ENOMEM;
  1294. goto err;
  1295. }
  1296. chip->pdev = pdev;
  1297. chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
  1298. if (chip->fixes) {
  1299. chip->quirks = chip->fixes->quirks;
  1300. chip->quirks2 = chip->fixes->quirks2;
  1301. chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
  1302. }
  1303. chip->num_slots = slots;
  1304. pci_set_drvdata(pdev, chip);
  1305. if (chip->fixes && chip->fixes->probe) {
  1306. ret = chip->fixes->probe(chip);
  1307. if (ret)
  1308. goto free;
  1309. }
  1310. slots = chip->num_slots; /* Quirk may have changed this */
  1311. for (i = 0; i < slots; i++) {
  1312. slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
  1313. if (IS_ERR(slot)) {
  1314. for (i--; i >= 0; i--)
  1315. sdhci_pci_remove_slot(chip->slots[i]);
  1316. ret = PTR_ERR(slot);
  1317. goto free;
  1318. }
  1319. chip->slots[i] = slot;
  1320. }
  1321. if (chip->allow_runtime_pm)
  1322. sdhci_pci_runtime_pm_allow(&pdev->dev);
  1323. return 0;
  1324. free:
  1325. pci_set_drvdata(pdev, NULL);
  1326. kfree(chip);
  1327. err:
  1328. pci_disable_device(pdev);
  1329. return ret;
  1330. }
  1331. static void sdhci_pci_remove(struct pci_dev *pdev)
  1332. {
  1333. int i;
  1334. struct sdhci_pci_chip *chip;
  1335. chip = pci_get_drvdata(pdev);
  1336. if (chip) {
  1337. if (chip->allow_runtime_pm)
  1338. sdhci_pci_runtime_pm_forbid(&pdev->dev);
  1339. for (i = 0; i < chip->num_slots; i++)
  1340. sdhci_pci_remove_slot(chip->slots[i]);
  1341. pci_set_drvdata(pdev, NULL);
  1342. kfree(chip);
  1343. }
  1344. pci_disable_device(pdev);
  1345. }
  1346. static struct pci_driver sdhci_driver = {
  1347. .name = "sdhci-pci",
  1348. .id_table = pci_ids,
  1349. .probe = sdhci_pci_probe,
  1350. .remove = sdhci_pci_remove,
  1351. .driver = {
  1352. .pm = &sdhci_pci_pm_ops
  1353. },
  1354. };
  1355. module_pci_driver(sdhci_driver);
  1356. MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
  1357. MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
  1358. MODULE_LICENSE("GPL");