sdhci-pci-core.c 45 KB

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