sdhci-pci.c 43 KB

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