sdhci-pci-core.c 47 KB

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