sdhci-pci-core.c 49 KB

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