sdhci-pci.c 43 KB

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