sdhci-pci-core.c 45 KB

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