sdhci-pci.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  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 int amd_probe(struct sdhci_pci_chip *chip)
  541. {
  542. struct pci_dev *smbus_dev;
  543. smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
  544. PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
  545. if (smbus_dev && (smbus_dev->revision < 0x51))
  546. chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
  547. return 0;
  548. }
  549. static const struct sdhci_pci_fixes sdhci_amd = {
  550. .probe = amd_probe,
  551. };
  552. static const struct pci_device_id pci_ids[] = {
  553. {
  554. .vendor = PCI_VENDOR_ID_RICOH,
  555. .device = PCI_DEVICE_ID_RICOH_R5C822,
  556. .subvendor = PCI_ANY_ID,
  557. .subdevice = PCI_ANY_ID,
  558. .driver_data = (kernel_ulong_t)&sdhci_ricoh,
  559. },
  560. {
  561. .vendor = PCI_VENDOR_ID_RICOH,
  562. .device = 0x843,
  563. .subvendor = PCI_ANY_ID,
  564. .subdevice = PCI_ANY_ID,
  565. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  566. },
  567. {
  568. .vendor = PCI_VENDOR_ID_RICOH,
  569. .device = 0xe822,
  570. .subvendor = PCI_ANY_ID,
  571. .subdevice = PCI_ANY_ID,
  572. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  573. },
  574. {
  575. .vendor = PCI_VENDOR_ID_RICOH,
  576. .device = 0xe823,
  577. .subvendor = PCI_ANY_ID,
  578. .subdevice = PCI_ANY_ID,
  579. .driver_data = (kernel_ulong_t)&sdhci_ricoh_mmc,
  580. },
  581. {
  582. .vendor = PCI_VENDOR_ID_ENE,
  583. .device = PCI_DEVICE_ID_ENE_CB712_SD,
  584. .subvendor = PCI_ANY_ID,
  585. .subdevice = PCI_ANY_ID,
  586. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  587. },
  588. {
  589. .vendor = PCI_VENDOR_ID_ENE,
  590. .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
  591. .subvendor = PCI_ANY_ID,
  592. .subdevice = PCI_ANY_ID,
  593. .driver_data = (kernel_ulong_t)&sdhci_ene_712,
  594. },
  595. {
  596. .vendor = PCI_VENDOR_ID_ENE,
  597. .device = PCI_DEVICE_ID_ENE_CB714_SD,
  598. .subvendor = PCI_ANY_ID,
  599. .subdevice = PCI_ANY_ID,
  600. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  601. },
  602. {
  603. .vendor = PCI_VENDOR_ID_ENE,
  604. .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
  605. .subvendor = PCI_ANY_ID,
  606. .subdevice = PCI_ANY_ID,
  607. .driver_data = (kernel_ulong_t)&sdhci_ene_714,
  608. },
  609. {
  610. .vendor = PCI_VENDOR_ID_MARVELL,
  611. .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
  612. .subvendor = PCI_ANY_ID,
  613. .subdevice = PCI_ANY_ID,
  614. .driver_data = (kernel_ulong_t)&sdhci_cafe,
  615. },
  616. {
  617. .vendor = PCI_VENDOR_ID_JMICRON,
  618. .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD,
  619. .subvendor = PCI_ANY_ID,
  620. .subdevice = PCI_ANY_ID,
  621. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  622. },
  623. {
  624. .vendor = PCI_VENDOR_ID_JMICRON,
  625. .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC,
  626. .subvendor = PCI_ANY_ID,
  627. .subdevice = PCI_ANY_ID,
  628. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  629. },
  630. {
  631. .vendor = PCI_VENDOR_ID_JMICRON,
  632. .device = PCI_DEVICE_ID_JMICRON_JMB388_SD,
  633. .subvendor = PCI_ANY_ID,
  634. .subdevice = PCI_ANY_ID,
  635. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  636. },
  637. {
  638. .vendor = PCI_VENDOR_ID_JMICRON,
  639. .device = PCI_DEVICE_ID_JMICRON_JMB388_ESD,
  640. .subvendor = PCI_ANY_ID,
  641. .subdevice = PCI_ANY_ID,
  642. .driver_data = (kernel_ulong_t)&sdhci_jmicron,
  643. },
  644. {
  645. .vendor = PCI_VENDOR_ID_SYSKONNECT,
  646. .device = 0x8000,
  647. .subvendor = PCI_ANY_ID,
  648. .subdevice = PCI_ANY_ID,
  649. .driver_data = (kernel_ulong_t)&sdhci_syskt,
  650. },
  651. {
  652. .vendor = PCI_VENDOR_ID_VIA,
  653. .device = 0x95d0,
  654. .subvendor = PCI_ANY_ID,
  655. .subdevice = PCI_ANY_ID,
  656. .driver_data = (kernel_ulong_t)&sdhci_via,
  657. },
  658. {
  659. .vendor = PCI_VENDOR_ID_REALTEK,
  660. .device = 0x5250,
  661. .subvendor = PCI_ANY_ID,
  662. .subdevice = PCI_ANY_ID,
  663. .driver_data = (kernel_ulong_t)&sdhci_rtsx,
  664. },
  665. {
  666. .vendor = PCI_VENDOR_ID_INTEL,
  667. .device = PCI_DEVICE_ID_INTEL_QRK_SD,
  668. .subvendor = PCI_ANY_ID,
  669. .subdevice = PCI_ANY_ID,
  670. .driver_data = (kernel_ulong_t)&sdhci_intel_qrk,
  671. },
  672. {
  673. .vendor = PCI_VENDOR_ID_INTEL,
  674. .device = PCI_DEVICE_ID_INTEL_MRST_SD0,
  675. .subvendor = PCI_ANY_ID,
  676. .subdevice = PCI_ANY_ID,
  677. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc0,
  678. },
  679. {
  680. .vendor = PCI_VENDOR_ID_INTEL,
  681. .device = PCI_DEVICE_ID_INTEL_MRST_SD1,
  682. .subvendor = PCI_ANY_ID,
  683. .subdevice = PCI_ANY_ID,
  684. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  685. },
  686. {
  687. .vendor = PCI_VENDOR_ID_INTEL,
  688. .device = PCI_DEVICE_ID_INTEL_MRST_SD2,
  689. .subvendor = PCI_ANY_ID,
  690. .subdevice = PCI_ANY_ID,
  691. .driver_data = (kernel_ulong_t)&sdhci_intel_mrst_hc1_hc2,
  692. },
  693. {
  694. .vendor = PCI_VENDOR_ID_INTEL,
  695. .device = PCI_DEVICE_ID_INTEL_MFD_SD,
  696. .subvendor = PCI_ANY_ID,
  697. .subdevice = PCI_ANY_ID,
  698. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  699. },
  700. {
  701. .vendor = PCI_VENDOR_ID_INTEL,
  702. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO1,
  703. .subvendor = PCI_ANY_ID,
  704. .subdevice = PCI_ANY_ID,
  705. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  706. },
  707. {
  708. .vendor = PCI_VENDOR_ID_INTEL,
  709. .device = PCI_DEVICE_ID_INTEL_MFD_SDIO2,
  710. .subvendor = PCI_ANY_ID,
  711. .subdevice = PCI_ANY_ID,
  712. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  713. },
  714. {
  715. .vendor = PCI_VENDOR_ID_INTEL,
  716. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC0,
  717. .subvendor = PCI_ANY_ID,
  718. .subdevice = PCI_ANY_ID,
  719. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  720. },
  721. {
  722. .vendor = PCI_VENDOR_ID_INTEL,
  723. .device = PCI_DEVICE_ID_INTEL_MFD_EMMC1,
  724. .subvendor = PCI_ANY_ID,
  725. .subdevice = PCI_ANY_ID,
  726. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  727. },
  728. {
  729. .vendor = PCI_VENDOR_ID_INTEL,
  730. .device = PCI_DEVICE_ID_INTEL_PCH_SDIO0,
  731. .subvendor = PCI_ANY_ID,
  732. .subdevice = PCI_ANY_ID,
  733. .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
  734. },
  735. {
  736. .vendor = PCI_VENDOR_ID_INTEL,
  737. .device = PCI_DEVICE_ID_INTEL_PCH_SDIO1,
  738. .subvendor = PCI_ANY_ID,
  739. .subdevice = PCI_ANY_ID,
  740. .driver_data = (kernel_ulong_t)&sdhci_intel_pch_sdio,
  741. },
  742. {
  743. .vendor = PCI_VENDOR_ID_INTEL,
  744. .device = PCI_DEVICE_ID_INTEL_BYT_EMMC,
  745. .subvendor = PCI_ANY_ID,
  746. .subdevice = PCI_ANY_ID,
  747. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  748. },
  749. {
  750. .vendor = PCI_VENDOR_ID_INTEL,
  751. .device = PCI_DEVICE_ID_INTEL_BYT_SDIO,
  752. .subvendor = PCI_ANY_ID,
  753. .subdevice = PCI_ANY_ID,
  754. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  755. },
  756. {
  757. .vendor = PCI_VENDOR_ID_INTEL,
  758. .device = PCI_DEVICE_ID_INTEL_BYT_SD,
  759. .subvendor = PCI_ANY_ID,
  760. .subdevice = PCI_ANY_ID,
  761. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  762. },
  763. {
  764. .vendor = PCI_VENDOR_ID_INTEL,
  765. .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2,
  766. .subvendor = PCI_ANY_ID,
  767. .subdevice = PCI_ANY_ID,
  768. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  769. },
  770. {
  771. .vendor = PCI_VENDOR_ID_INTEL,
  772. .device = PCI_DEVICE_ID_INTEL_BSW_EMMC,
  773. .subvendor = PCI_ANY_ID,
  774. .subdevice = PCI_ANY_ID,
  775. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc,
  776. },
  777. {
  778. .vendor = PCI_VENDOR_ID_INTEL,
  779. .device = PCI_DEVICE_ID_INTEL_BSW_SDIO,
  780. .subvendor = PCI_ANY_ID,
  781. .subdevice = PCI_ANY_ID,
  782. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sdio,
  783. },
  784. {
  785. .vendor = PCI_VENDOR_ID_INTEL,
  786. .device = PCI_DEVICE_ID_INTEL_BSW_SD,
  787. .subvendor = PCI_ANY_ID,
  788. .subdevice = PCI_ANY_ID,
  789. .driver_data = (kernel_ulong_t)&sdhci_intel_byt_sd,
  790. },
  791. {
  792. .vendor = PCI_VENDOR_ID_INTEL,
  793. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO0,
  794. .subvendor = PCI_ANY_ID,
  795. .subdevice = PCI_ANY_ID,
  796. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sd,
  797. },
  798. {
  799. .vendor = PCI_VENDOR_ID_INTEL,
  800. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO1,
  801. .subvendor = PCI_ANY_ID,
  802. .subdevice = PCI_ANY_ID,
  803. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  804. },
  805. {
  806. .vendor = PCI_VENDOR_ID_INTEL,
  807. .device = PCI_DEVICE_ID_INTEL_CLV_SDIO2,
  808. .subvendor = PCI_ANY_ID,
  809. .subdevice = PCI_ANY_ID,
  810. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_sdio,
  811. },
  812. {
  813. .vendor = PCI_VENDOR_ID_INTEL,
  814. .device = PCI_DEVICE_ID_INTEL_CLV_EMMC0,
  815. .subvendor = PCI_ANY_ID,
  816. .subdevice = PCI_ANY_ID,
  817. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  818. },
  819. {
  820. .vendor = PCI_VENDOR_ID_INTEL,
  821. .device = PCI_DEVICE_ID_INTEL_CLV_EMMC1,
  822. .subvendor = PCI_ANY_ID,
  823. .subdevice = PCI_ANY_ID,
  824. .driver_data = (kernel_ulong_t)&sdhci_intel_mfd_emmc,
  825. },
  826. {
  827. .vendor = PCI_VENDOR_ID_INTEL,
  828. .device = PCI_DEVICE_ID_INTEL_MRFL_MMC,
  829. .subvendor = PCI_ANY_ID,
  830. .subdevice = PCI_ANY_ID,
  831. .driver_data = (kernel_ulong_t)&sdhci_intel_mrfl_mmc,
  832. },
  833. {
  834. .vendor = PCI_VENDOR_ID_O2,
  835. .device = PCI_DEVICE_ID_O2_8120,
  836. .subvendor = PCI_ANY_ID,
  837. .subdevice = PCI_ANY_ID,
  838. .driver_data = (kernel_ulong_t)&sdhci_o2,
  839. },
  840. {
  841. .vendor = PCI_VENDOR_ID_O2,
  842. .device = PCI_DEVICE_ID_O2_8220,
  843. .subvendor = PCI_ANY_ID,
  844. .subdevice = PCI_ANY_ID,
  845. .driver_data = (kernel_ulong_t)&sdhci_o2,
  846. },
  847. {
  848. .vendor = PCI_VENDOR_ID_O2,
  849. .device = PCI_DEVICE_ID_O2_8221,
  850. .subvendor = PCI_ANY_ID,
  851. .subdevice = PCI_ANY_ID,
  852. .driver_data = (kernel_ulong_t)&sdhci_o2,
  853. },
  854. {
  855. .vendor = PCI_VENDOR_ID_O2,
  856. .device = PCI_DEVICE_ID_O2_8320,
  857. .subvendor = PCI_ANY_ID,
  858. .subdevice = PCI_ANY_ID,
  859. .driver_data = (kernel_ulong_t)&sdhci_o2,
  860. },
  861. {
  862. .vendor = PCI_VENDOR_ID_O2,
  863. .device = PCI_DEVICE_ID_O2_8321,
  864. .subvendor = PCI_ANY_ID,
  865. .subdevice = PCI_ANY_ID,
  866. .driver_data = (kernel_ulong_t)&sdhci_o2,
  867. },
  868. {
  869. .vendor = PCI_VENDOR_ID_O2,
  870. .device = PCI_DEVICE_ID_O2_FUJIN2,
  871. .subvendor = PCI_ANY_ID,
  872. .subdevice = PCI_ANY_ID,
  873. .driver_data = (kernel_ulong_t)&sdhci_o2,
  874. },
  875. {
  876. .vendor = PCI_VENDOR_ID_O2,
  877. .device = PCI_DEVICE_ID_O2_SDS0,
  878. .subvendor = PCI_ANY_ID,
  879. .subdevice = PCI_ANY_ID,
  880. .driver_data = (kernel_ulong_t)&sdhci_o2,
  881. },
  882. {
  883. .vendor = PCI_VENDOR_ID_O2,
  884. .device = PCI_DEVICE_ID_O2_SDS1,
  885. .subvendor = PCI_ANY_ID,
  886. .subdevice = PCI_ANY_ID,
  887. .driver_data = (kernel_ulong_t)&sdhci_o2,
  888. },
  889. {
  890. .vendor = PCI_VENDOR_ID_O2,
  891. .device = PCI_DEVICE_ID_O2_SEABIRD0,
  892. .subvendor = PCI_ANY_ID,
  893. .subdevice = PCI_ANY_ID,
  894. .driver_data = (kernel_ulong_t)&sdhci_o2,
  895. },
  896. {
  897. .vendor = PCI_VENDOR_ID_O2,
  898. .device = PCI_DEVICE_ID_O2_SEABIRD1,
  899. .subvendor = PCI_ANY_ID,
  900. .subdevice = PCI_ANY_ID,
  901. .driver_data = (kernel_ulong_t)&sdhci_o2,
  902. },
  903. {
  904. .vendor = PCI_VENDOR_ID_AMD,
  905. .device = PCI_ANY_ID,
  906. .class = PCI_CLASS_SYSTEM_SDHCI << 8,
  907. .class_mask = 0xFFFF00,
  908. .subvendor = PCI_ANY_ID,
  909. .subdevice = PCI_ANY_ID,
  910. .driver_data = (kernel_ulong_t)&sdhci_amd,
  911. },
  912. { /* Generic SD host controller */
  913. PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
  914. },
  915. { /* end: all zeroes */ },
  916. };
  917. MODULE_DEVICE_TABLE(pci, pci_ids);
  918. /*****************************************************************************\
  919. * *
  920. * SDHCI core callbacks *
  921. * *
  922. \*****************************************************************************/
  923. static int sdhci_pci_enable_dma(struct sdhci_host *host)
  924. {
  925. struct sdhci_pci_slot *slot;
  926. struct pci_dev *pdev;
  927. int ret = -1;
  928. slot = sdhci_priv(host);
  929. pdev = slot->chip->pdev;
  930. if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) &&
  931. ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
  932. (host->flags & SDHCI_USE_SDMA)) {
  933. dev_warn(&pdev->dev, "Will use DMA mode even though HW "
  934. "doesn't fully claim to support it.\n");
  935. }
  936. if (host->flags & SDHCI_USE_64_BIT_DMA) {
  937. if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) {
  938. host->flags &= ~SDHCI_USE_64_BIT_DMA;
  939. } else {
  940. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  941. if (ret)
  942. dev_warn(&pdev->dev, "Failed to set 64-bit DMA mask\n");
  943. }
  944. }
  945. if (ret)
  946. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  947. if (ret)
  948. return ret;
  949. pci_set_master(pdev);
  950. return 0;
  951. }
  952. static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width)
  953. {
  954. u8 ctrl;
  955. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  956. switch (width) {
  957. case MMC_BUS_WIDTH_8:
  958. ctrl |= SDHCI_CTRL_8BITBUS;
  959. ctrl &= ~SDHCI_CTRL_4BITBUS;
  960. break;
  961. case MMC_BUS_WIDTH_4:
  962. ctrl |= SDHCI_CTRL_4BITBUS;
  963. ctrl &= ~SDHCI_CTRL_8BITBUS;
  964. break;
  965. default:
  966. ctrl &= ~(SDHCI_CTRL_8BITBUS | SDHCI_CTRL_4BITBUS);
  967. break;
  968. }
  969. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  970. }
  971. static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host)
  972. {
  973. struct sdhci_pci_slot *slot = sdhci_priv(host);
  974. int rst_n_gpio = slot->rst_n_gpio;
  975. if (!gpio_is_valid(rst_n_gpio))
  976. return;
  977. gpio_set_value_cansleep(rst_n_gpio, 0);
  978. /* For eMMC, minimum is 1us but give it 10us for good measure */
  979. udelay(10);
  980. gpio_set_value_cansleep(rst_n_gpio, 1);
  981. /* For eMMC, minimum is 200us but give it 300us for good measure */
  982. usleep_range(300, 1000);
  983. }
  984. static void sdhci_pci_hw_reset(struct sdhci_host *host)
  985. {
  986. struct sdhci_pci_slot *slot = sdhci_priv(host);
  987. if (slot->hw_reset)
  988. slot->hw_reset(host);
  989. }
  990. static const struct sdhci_ops sdhci_pci_ops = {
  991. .set_clock = sdhci_set_clock,
  992. .enable_dma = sdhci_pci_enable_dma,
  993. .set_bus_width = sdhci_pci_set_bus_width,
  994. .reset = sdhci_reset,
  995. .set_uhs_signaling = sdhci_set_uhs_signaling,
  996. .hw_reset = sdhci_pci_hw_reset,
  997. };
  998. /*****************************************************************************\
  999. * *
  1000. * Suspend/resume *
  1001. * *
  1002. \*****************************************************************************/
  1003. #ifdef CONFIG_PM
  1004. static int sdhci_pci_suspend(struct device *dev)
  1005. {
  1006. struct pci_dev *pdev = to_pci_dev(dev);
  1007. struct sdhci_pci_chip *chip;
  1008. struct sdhci_pci_slot *slot;
  1009. mmc_pm_flag_t slot_pm_flags;
  1010. mmc_pm_flag_t pm_flags = 0;
  1011. int i, ret;
  1012. chip = pci_get_drvdata(pdev);
  1013. if (!chip)
  1014. return 0;
  1015. for (i = 0; i < chip->num_slots; i++) {
  1016. slot = chip->slots[i];
  1017. if (!slot)
  1018. continue;
  1019. ret = sdhci_suspend_host(slot->host);
  1020. if (ret)
  1021. goto err_pci_suspend;
  1022. slot_pm_flags = slot->host->mmc->pm_flags;
  1023. if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  1024. sdhci_enable_irq_wakeups(slot->host);
  1025. pm_flags |= slot_pm_flags;
  1026. }
  1027. if (chip->fixes && chip->fixes->suspend) {
  1028. ret = chip->fixes->suspend(chip);
  1029. if (ret)
  1030. goto err_pci_suspend;
  1031. }
  1032. if (pm_flags & MMC_PM_KEEP_POWER) {
  1033. if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
  1034. device_init_wakeup(dev, true);
  1035. else
  1036. device_init_wakeup(dev, false);
  1037. } else
  1038. device_init_wakeup(dev, false);
  1039. return 0;
  1040. err_pci_suspend:
  1041. while (--i >= 0)
  1042. sdhci_resume_host(chip->slots[i]->host);
  1043. return ret;
  1044. }
  1045. static int sdhci_pci_resume(struct device *dev)
  1046. {
  1047. struct pci_dev *pdev = to_pci_dev(dev);
  1048. struct sdhci_pci_chip *chip;
  1049. struct sdhci_pci_slot *slot;
  1050. int i, ret;
  1051. chip = pci_get_drvdata(pdev);
  1052. if (!chip)
  1053. return 0;
  1054. if (chip->fixes && chip->fixes->resume) {
  1055. ret = chip->fixes->resume(chip);
  1056. if (ret)
  1057. return ret;
  1058. }
  1059. for (i = 0; i < chip->num_slots; i++) {
  1060. slot = chip->slots[i];
  1061. if (!slot)
  1062. continue;
  1063. ret = sdhci_resume_host(slot->host);
  1064. if (ret)
  1065. return ret;
  1066. }
  1067. return 0;
  1068. }
  1069. #else /* CONFIG_PM */
  1070. #define sdhci_pci_suspend NULL
  1071. #define sdhci_pci_resume NULL
  1072. #endif /* CONFIG_PM */
  1073. #ifdef CONFIG_PM_RUNTIME
  1074. static int sdhci_pci_runtime_suspend(struct device *dev)
  1075. {
  1076. struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
  1077. struct sdhci_pci_chip *chip;
  1078. struct sdhci_pci_slot *slot;
  1079. int i, ret;
  1080. chip = pci_get_drvdata(pdev);
  1081. if (!chip)
  1082. return 0;
  1083. for (i = 0; i < chip->num_slots; i++) {
  1084. slot = chip->slots[i];
  1085. if (!slot)
  1086. continue;
  1087. ret = sdhci_runtime_suspend_host(slot->host);
  1088. if (ret)
  1089. goto err_pci_runtime_suspend;
  1090. }
  1091. if (chip->fixes && chip->fixes->suspend) {
  1092. ret = chip->fixes->suspend(chip);
  1093. if (ret)
  1094. goto err_pci_runtime_suspend;
  1095. }
  1096. return 0;
  1097. err_pci_runtime_suspend:
  1098. while (--i >= 0)
  1099. sdhci_runtime_resume_host(chip->slots[i]->host);
  1100. return ret;
  1101. }
  1102. static int sdhci_pci_runtime_resume(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. if (chip->fixes && chip->fixes->resume) {
  1112. ret = chip->fixes->resume(chip);
  1113. if (ret)
  1114. return ret;
  1115. }
  1116. for (i = 0; i < chip->num_slots; i++) {
  1117. slot = chip->slots[i];
  1118. if (!slot)
  1119. continue;
  1120. ret = sdhci_runtime_resume_host(slot->host);
  1121. if (ret)
  1122. return ret;
  1123. }
  1124. return 0;
  1125. }
  1126. static int sdhci_pci_runtime_idle(struct device *dev)
  1127. {
  1128. return 0;
  1129. }
  1130. #endif
  1131. static const struct dev_pm_ops sdhci_pci_pm_ops = {
  1132. .suspend = sdhci_pci_suspend,
  1133. .resume = sdhci_pci_resume,
  1134. SET_RUNTIME_PM_OPS(sdhci_pci_runtime_suspend,
  1135. sdhci_pci_runtime_resume, sdhci_pci_runtime_idle)
  1136. };
  1137. /*****************************************************************************\
  1138. * *
  1139. * Device probing/removal *
  1140. * *
  1141. \*****************************************************************************/
  1142. static struct sdhci_pci_slot *sdhci_pci_probe_slot(
  1143. struct pci_dev *pdev, struct sdhci_pci_chip *chip, int first_bar,
  1144. int slotno)
  1145. {
  1146. struct sdhci_pci_slot *slot;
  1147. struct sdhci_host *host;
  1148. int ret, bar = first_bar + slotno;
  1149. if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) {
  1150. dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar);
  1151. return ERR_PTR(-ENODEV);
  1152. }
  1153. if (pci_resource_len(pdev, bar) < 0x100) {
  1154. dev_err(&pdev->dev, "Invalid iomem size. You may "
  1155. "experience problems.\n");
  1156. }
  1157. if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
  1158. dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n");
  1159. return ERR_PTR(-ENODEV);
  1160. }
  1161. if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) {
  1162. dev_err(&pdev->dev, "Unknown interface. Aborting.\n");
  1163. return ERR_PTR(-ENODEV);
  1164. }
  1165. host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot));
  1166. if (IS_ERR(host)) {
  1167. dev_err(&pdev->dev, "cannot allocate host\n");
  1168. return ERR_CAST(host);
  1169. }
  1170. slot = sdhci_priv(host);
  1171. slot->chip = chip;
  1172. slot->host = host;
  1173. slot->pci_bar = bar;
  1174. slot->rst_n_gpio = -EINVAL;
  1175. slot->cd_gpio = -EINVAL;
  1176. slot->cd_idx = -1;
  1177. /* Retrieve platform data if there is any */
  1178. if (*sdhci_pci_get_data)
  1179. slot->data = sdhci_pci_get_data(pdev, slotno);
  1180. if (slot->data) {
  1181. if (slot->data->setup) {
  1182. ret = slot->data->setup(slot->data);
  1183. if (ret) {
  1184. dev_err(&pdev->dev, "platform setup failed\n");
  1185. goto free;
  1186. }
  1187. }
  1188. slot->rst_n_gpio = slot->data->rst_n_gpio;
  1189. slot->cd_gpio = slot->data->cd_gpio;
  1190. }
  1191. host->hw_name = "PCI";
  1192. host->ops = &sdhci_pci_ops;
  1193. host->quirks = chip->quirks;
  1194. host->quirks2 = chip->quirks2;
  1195. host->irq = pdev->irq;
  1196. ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc));
  1197. if (ret) {
  1198. dev_err(&pdev->dev, "cannot request region\n");
  1199. goto cleanup;
  1200. }
  1201. host->ioaddr = pci_ioremap_bar(pdev, bar);
  1202. if (!host->ioaddr) {
  1203. dev_err(&pdev->dev, "failed to remap registers\n");
  1204. ret = -ENOMEM;
  1205. goto release;
  1206. }
  1207. if (chip->fixes && chip->fixes->probe_slot) {
  1208. ret = chip->fixes->probe_slot(slot);
  1209. if (ret)
  1210. goto unmap;
  1211. }
  1212. if (gpio_is_valid(slot->rst_n_gpio)) {
  1213. if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) {
  1214. gpio_direction_output(slot->rst_n_gpio, 1);
  1215. slot->host->mmc->caps |= MMC_CAP_HW_RESET;
  1216. slot->hw_reset = sdhci_pci_gpio_hw_reset;
  1217. } else {
  1218. dev_warn(&pdev->dev, "failed to request rst_n_gpio\n");
  1219. slot->rst_n_gpio = -EINVAL;
  1220. }
  1221. }
  1222. host->mmc->pm_caps = MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ;
  1223. host->mmc->slotno = slotno;
  1224. host->mmc->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP;
  1225. if (slot->cd_idx >= 0 &&
  1226. mmc_gpiod_request_cd(host->mmc, slot->cd_con_id, slot->cd_idx,
  1227. slot->cd_override_level, 0, NULL)) {
  1228. dev_warn(&pdev->dev, "failed to setup card detect gpio\n");
  1229. slot->cd_idx = -1;
  1230. }
  1231. ret = sdhci_add_host(host);
  1232. if (ret)
  1233. goto remove;
  1234. sdhci_pci_add_own_cd(slot);
  1235. /*
  1236. * Check if the chip needs a separate GPIO for card detect to wake up
  1237. * from runtime suspend. If it is not there, don't allow runtime PM.
  1238. * Note sdhci_pci_add_own_cd() sets slot->cd_gpio to -EINVAL on failure.
  1239. */
  1240. if (chip->fixes && chip->fixes->own_cd_for_runtime_pm &&
  1241. !gpio_is_valid(slot->cd_gpio) && slot->cd_idx < 0)
  1242. chip->allow_runtime_pm = false;
  1243. return slot;
  1244. remove:
  1245. if (gpio_is_valid(slot->rst_n_gpio))
  1246. gpio_free(slot->rst_n_gpio);
  1247. if (chip->fixes && chip->fixes->remove_slot)
  1248. chip->fixes->remove_slot(slot, 0);
  1249. unmap:
  1250. iounmap(host->ioaddr);
  1251. release:
  1252. pci_release_region(pdev, bar);
  1253. cleanup:
  1254. if (slot->data && slot->data->cleanup)
  1255. slot->data->cleanup(slot->data);
  1256. free:
  1257. sdhci_free_host(host);
  1258. return ERR_PTR(ret);
  1259. }
  1260. static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
  1261. {
  1262. int dead;
  1263. u32 scratch;
  1264. sdhci_pci_remove_own_cd(slot);
  1265. dead = 0;
  1266. scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS);
  1267. if (scratch == (u32)-1)
  1268. dead = 1;
  1269. sdhci_remove_host(slot->host, dead);
  1270. if (gpio_is_valid(slot->rst_n_gpio))
  1271. gpio_free(slot->rst_n_gpio);
  1272. if (slot->chip->fixes && slot->chip->fixes->remove_slot)
  1273. slot->chip->fixes->remove_slot(slot, dead);
  1274. if (slot->data && slot->data->cleanup)
  1275. slot->data->cleanup(slot->data);
  1276. pci_release_region(slot->chip->pdev, slot->pci_bar);
  1277. sdhci_free_host(slot->host);
  1278. }
  1279. static void sdhci_pci_runtime_pm_allow(struct device *dev)
  1280. {
  1281. pm_runtime_put_noidle(dev);
  1282. pm_runtime_allow(dev);
  1283. pm_runtime_set_autosuspend_delay(dev, 50);
  1284. pm_runtime_use_autosuspend(dev);
  1285. pm_suspend_ignore_children(dev, 1);
  1286. }
  1287. static void sdhci_pci_runtime_pm_forbid(struct device *dev)
  1288. {
  1289. pm_runtime_forbid(dev);
  1290. pm_runtime_get_noresume(dev);
  1291. }
  1292. static int sdhci_pci_probe(struct pci_dev *pdev,
  1293. const struct pci_device_id *ent)
  1294. {
  1295. struct sdhci_pci_chip *chip;
  1296. struct sdhci_pci_slot *slot;
  1297. u8 slots, first_bar;
  1298. int ret, i;
  1299. BUG_ON(pdev == NULL);
  1300. BUG_ON(ent == NULL);
  1301. dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n",
  1302. (int)pdev->vendor, (int)pdev->device, (int)pdev->revision);
  1303. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots);
  1304. if (ret)
  1305. return ret;
  1306. slots = PCI_SLOT_INFO_SLOTS(slots) + 1;
  1307. dev_dbg(&pdev->dev, "found %d slot(s)\n", slots);
  1308. if (slots == 0)
  1309. return -ENODEV;
  1310. BUG_ON(slots > MAX_SLOTS);
  1311. ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar);
  1312. if (ret)
  1313. return ret;
  1314. first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK;
  1315. if (first_bar > 5) {
  1316. dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n");
  1317. return -ENODEV;
  1318. }
  1319. ret = pci_enable_device(pdev);
  1320. if (ret)
  1321. return ret;
  1322. chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL);
  1323. if (!chip) {
  1324. ret = -ENOMEM;
  1325. goto err;
  1326. }
  1327. chip->pdev = pdev;
  1328. chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
  1329. if (chip->fixes) {
  1330. chip->quirks = chip->fixes->quirks;
  1331. chip->quirks2 = chip->fixes->quirks2;
  1332. chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
  1333. }
  1334. chip->num_slots = slots;
  1335. pci_set_drvdata(pdev, chip);
  1336. if (chip->fixes && chip->fixes->probe) {
  1337. ret = chip->fixes->probe(chip);
  1338. if (ret)
  1339. goto free;
  1340. }
  1341. slots = chip->num_slots; /* Quirk may have changed this */
  1342. for (i = 0; i < slots; i++) {
  1343. slot = sdhci_pci_probe_slot(pdev, chip, first_bar, i);
  1344. if (IS_ERR(slot)) {
  1345. for (i--; i >= 0; i--)
  1346. sdhci_pci_remove_slot(chip->slots[i]);
  1347. ret = PTR_ERR(slot);
  1348. goto free;
  1349. }
  1350. chip->slots[i] = slot;
  1351. }
  1352. if (chip->allow_runtime_pm)
  1353. sdhci_pci_runtime_pm_allow(&pdev->dev);
  1354. return 0;
  1355. free:
  1356. pci_set_drvdata(pdev, NULL);
  1357. kfree(chip);
  1358. err:
  1359. pci_disable_device(pdev);
  1360. return ret;
  1361. }
  1362. static void sdhci_pci_remove(struct pci_dev *pdev)
  1363. {
  1364. int i;
  1365. struct sdhci_pci_chip *chip;
  1366. chip = pci_get_drvdata(pdev);
  1367. if (chip) {
  1368. if (chip->allow_runtime_pm)
  1369. sdhci_pci_runtime_pm_forbid(&pdev->dev);
  1370. for (i = 0; i < chip->num_slots; i++)
  1371. sdhci_pci_remove_slot(chip->slots[i]);
  1372. pci_set_drvdata(pdev, NULL);
  1373. kfree(chip);
  1374. }
  1375. pci_disable_device(pdev);
  1376. }
  1377. static struct pci_driver sdhci_driver = {
  1378. .name = "sdhci-pci",
  1379. .id_table = pci_ids,
  1380. .probe = sdhci_pci_probe,
  1381. .remove = sdhci_pci_remove,
  1382. .driver = {
  1383. .pm = &sdhci_pci_pm_ops
  1384. },
  1385. };
  1386. module_pci_driver(sdhci_driver);
  1387. MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
  1388. MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver");
  1389. MODULE_LICENSE("GPL");