sdhci-pci.c 41 KB

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