sdhci-pci.c 41 KB

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