mmci.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. /*
  2. * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
  3. *
  4. * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
  5. * Copyright (C) 2010 ST-Ericsson SA
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/init.h>
  14. #include <linux/ioport.h>
  15. #include <linux/device.h>
  16. #include <linux/io.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/kernel.h>
  19. #include <linux/slab.h>
  20. #include <linux/delay.h>
  21. #include <linux/err.h>
  22. #include <linux/highmem.h>
  23. #include <linux/log2.h>
  24. #include <linux/mmc/pm.h>
  25. #include <linux/mmc/host.h>
  26. #include <linux/mmc/card.h>
  27. #include <linux/mmc/slot-gpio.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/clk.h>
  30. #include <linux/scatterlist.h>
  31. #include <linux/gpio.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/dmaengine.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/amba/mmci.h>
  37. #include <linux/pm_runtime.h>
  38. #include <linux/types.h>
  39. #include <linux/pinctrl/consumer.h>
  40. #include <asm/div64.h>
  41. #include <asm/io.h>
  42. #include <asm/sizes.h>
  43. #include "mmci.h"
  44. #include "mmci_qcom_dml.h"
  45. #define DRIVER_NAME "mmci-pl18x"
  46. static unsigned int fmax = 515633;
  47. /**
  48. * struct variant_data - MMCI variant-specific quirks
  49. * @clkreg: default value for MCICLOCK register
  50. * @clkreg_enable: enable value for MMCICLOCK register
  51. * @clkreg_8bit_bus_enable: enable value for 8 bit bus
  52. * @clkreg_neg_edge_enable: enable value for inverted data/cmd output
  53. * @datalength_bits: number of bits in the MMCIDATALENGTH register
  54. * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
  55. * is asserted (likewise for RX)
  56. * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
  57. * is asserted (likewise for RX)
  58. * @data_cmd_enable: enable value for data commands.
  59. * @sdio: variant supports SDIO
  60. * @st_clkdiv: true if using a ST-specific clock divider algorithm
  61. * @datactrl_mask_ddrmode: ddr mode mask in datactrl register.
  62. * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
  63. * @blksz_datactrl4: true if Block size is at b4..b16 position in datactrl
  64. * register
  65. * @pwrreg_powerup: power up value for MMCIPOWER register
  66. * @f_max: maximum clk frequency supported by the controller.
  67. * @signal_direction: input/out direction of bus signals can be indicated
  68. * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock
  69. * @busy_detect: true if busy detection on dat0 is supported
  70. * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply
  71. * @explicit_mclk_control: enable explicit mclk control in driver.
  72. * @qcom_fifo: enables qcom specific fifo pio read logic.
  73. * @qcom_dml: enables qcom specific dma glue for dma transfers.
  74. * @reversed_irq_handling: handle data irq before cmd irq.
  75. */
  76. struct variant_data {
  77. unsigned int clkreg;
  78. unsigned int clkreg_enable;
  79. unsigned int clkreg_8bit_bus_enable;
  80. unsigned int clkreg_neg_edge_enable;
  81. unsigned int datalength_bits;
  82. unsigned int fifosize;
  83. unsigned int fifohalfsize;
  84. unsigned int data_cmd_enable;
  85. unsigned int datactrl_mask_ddrmode;
  86. bool sdio;
  87. bool st_clkdiv;
  88. bool blksz_datactrl16;
  89. bool blksz_datactrl4;
  90. u32 pwrreg_powerup;
  91. u32 f_max;
  92. bool signal_direction;
  93. bool pwrreg_clkgate;
  94. bool busy_detect;
  95. bool pwrreg_nopower;
  96. bool explicit_mclk_control;
  97. bool qcom_fifo;
  98. bool qcom_dml;
  99. bool reversed_irq_handling;
  100. };
  101. static struct variant_data variant_arm = {
  102. .fifosize = 16 * 4,
  103. .fifohalfsize = 8 * 4,
  104. .datalength_bits = 16,
  105. .pwrreg_powerup = MCI_PWR_UP,
  106. .f_max = 100000000,
  107. .reversed_irq_handling = true,
  108. };
  109. static struct variant_data variant_arm_extended_fifo = {
  110. .fifosize = 128 * 4,
  111. .fifohalfsize = 64 * 4,
  112. .datalength_bits = 16,
  113. .pwrreg_powerup = MCI_PWR_UP,
  114. .f_max = 100000000,
  115. };
  116. static struct variant_data variant_arm_extended_fifo_hwfc = {
  117. .fifosize = 128 * 4,
  118. .fifohalfsize = 64 * 4,
  119. .clkreg_enable = MCI_ARM_HWFCEN,
  120. .datalength_bits = 16,
  121. .pwrreg_powerup = MCI_PWR_UP,
  122. .f_max = 100000000,
  123. };
  124. static struct variant_data variant_u300 = {
  125. .fifosize = 16 * 4,
  126. .fifohalfsize = 8 * 4,
  127. .clkreg_enable = MCI_ST_U300_HWFCEN,
  128. .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
  129. .datalength_bits = 16,
  130. .sdio = true,
  131. .pwrreg_powerup = MCI_PWR_ON,
  132. .f_max = 100000000,
  133. .signal_direction = true,
  134. .pwrreg_clkgate = true,
  135. .pwrreg_nopower = true,
  136. };
  137. static struct variant_data variant_nomadik = {
  138. .fifosize = 16 * 4,
  139. .fifohalfsize = 8 * 4,
  140. .clkreg = MCI_CLK_ENABLE,
  141. .datalength_bits = 24,
  142. .sdio = true,
  143. .st_clkdiv = true,
  144. .pwrreg_powerup = MCI_PWR_ON,
  145. .f_max = 100000000,
  146. .signal_direction = true,
  147. .pwrreg_clkgate = true,
  148. .pwrreg_nopower = true,
  149. };
  150. static struct variant_data variant_ux500 = {
  151. .fifosize = 30 * 4,
  152. .fifohalfsize = 8 * 4,
  153. .clkreg = MCI_CLK_ENABLE,
  154. .clkreg_enable = MCI_ST_UX500_HWFCEN,
  155. .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
  156. .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
  157. .datalength_bits = 24,
  158. .sdio = true,
  159. .st_clkdiv = true,
  160. .pwrreg_powerup = MCI_PWR_ON,
  161. .f_max = 100000000,
  162. .signal_direction = true,
  163. .pwrreg_clkgate = true,
  164. .busy_detect = true,
  165. .pwrreg_nopower = true,
  166. };
  167. static struct variant_data variant_ux500v2 = {
  168. .fifosize = 30 * 4,
  169. .fifohalfsize = 8 * 4,
  170. .clkreg = MCI_CLK_ENABLE,
  171. .clkreg_enable = MCI_ST_UX500_HWFCEN,
  172. .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
  173. .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
  174. .datactrl_mask_ddrmode = MCI_ST_DPSM_DDRMODE,
  175. .datalength_bits = 24,
  176. .sdio = true,
  177. .st_clkdiv = true,
  178. .blksz_datactrl16 = true,
  179. .pwrreg_powerup = MCI_PWR_ON,
  180. .f_max = 100000000,
  181. .signal_direction = true,
  182. .pwrreg_clkgate = true,
  183. .busy_detect = true,
  184. .pwrreg_nopower = true,
  185. };
  186. static struct variant_data variant_qcom = {
  187. .fifosize = 16 * 4,
  188. .fifohalfsize = 8 * 4,
  189. .clkreg = MCI_CLK_ENABLE,
  190. .clkreg_enable = MCI_QCOM_CLK_FLOWENA |
  191. MCI_QCOM_CLK_SELECT_IN_FBCLK,
  192. .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8,
  193. .datactrl_mask_ddrmode = MCI_QCOM_CLK_SELECT_IN_DDR_MODE,
  194. .data_cmd_enable = MCI_QCOM_CSPM_DATCMD,
  195. .blksz_datactrl4 = true,
  196. .datalength_bits = 24,
  197. .pwrreg_powerup = MCI_PWR_UP,
  198. .f_max = 208000000,
  199. .explicit_mclk_control = true,
  200. .qcom_fifo = true,
  201. .qcom_dml = true,
  202. };
  203. static int mmci_card_busy(struct mmc_host *mmc)
  204. {
  205. struct mmci_host *host = mmc_priv(mmc);
  206. unsigned long flags;
  207. int busy = 0;
  208. pm_runtime_get_sync(mmc_dev(mmc));
  209. spin_lock_irqsave(&host->lock, flags);
  210. if (readl(host->base + MMCISTATUS) & MCI_ST_CARDBUSY)
  211. busy = 1;
  212. spin_unlock_irqrestore(&host->lock, flags);
  213. pm_runtime_mark_last_busy(mmc_dev(mmc));
  214. pm_runtime_put_autosuspend(mmc_dev(mmc));
  215. return busy;
  216. }
  217. /*
  218. * Validate mmc prerequisites
  219. */
  220. static int mmci_validate_data(struct mmci_host *host,
  221. struct mmc_data *data)
  222. {
  223. if (!data)
  224. return 0;
  225. if (!is_power_of_2(data->blksz)) {
  226. dev_err(mmc_dev(host->mmc),
  227. "unsupported block size (%d bytes)\n", data->blksz);
  228. return -EINVAL;
  229. }
  230. return 0;
  231. }
  232. static void mmci_reg_delay(struct mmci_host *host)
  233. {
  234. /*
  235. * According to the spec, at least three feedback clock cycles
  236. * of max 52 MHz must pass between two writes to the MMCICLOCK reg.
  237. * Three MCLK clock cycles must pass between two MMCIPOWER reg writes.
  238. * Worst delay time during card init is at 100 kHz => 30 us.
  239. * Worst delay time when up and running is at 25 MHz => 120 ns.
  240. */
  241. if (host->cclk < 25000000)
  242. udelay(30);
  243. else
  244. ndelay(120);
  245. }
  246. /*
  247. * This must be called with host->lock held
  248. */
  249. static void mmci_write_clkreg(struct mmci_host *host, u32 clk)
  250. {
  251. if (host->clk_reg != clk) {
  252. host->clk_reg = clk;
  253. writel(clk, host->base + MMCICLOCK);
  254. }
  255. }
  256. /*
  257. * This must be called with host->lock held
  258. */
  259. static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
  260. {
  261. if (host->pwr_reg != pwr) {
  262. host->pwr_reg = pwr;
  263. writel(pwr, host->base + MMCIPOWER);
  264. }
  265. }
  266. /*
  267. * This must be called with host->lock held
  268. */
  269. static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl)
  270. {
  271. /* Keep ST Micro busy mode if enabled */
  272. datactrl |= host->datactrl_reg & MCI_ST_DPSM_BUSYMODE;
  273. if (host->datactrl_reg != datactrl) {
  274. host->datactrl_reg = datactrl;
  275. writel(datactrl, host->base + MMCIDATACTRL);
  276. }
  277. }
  278. /*
  279. * This must be called with host->lock held
  280. */
  281. static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
  282. {
  283. struct variant_data *variant = host->variant;
  284. u32 clk = variant->clkreg;
  285. /* Make sure cclk reflects the current calculated clock */
  286. host->cclk = 0;
  287. if (desired) {
  288. if (variant->explicit_mclk_control) {
  289. host->cclk = host->mclk;
  290. } else if (desired >= host->mclk) {
  291. clk = MCI_CLK_BYPASS;
  292. if (variant->st_clkdiv)
  293. clk |= MCI_ST_UX500_NEG_EDGE;
  294. host->cclk = host->mclk;
  295. } else if (variant->st_clkdiv) {
  296. /*
  297. * DB8500 TRM says f = mclk / (clkdiv + 2)
  298. * => clkdiv = (mclk / f) - 2
  299. * Round the divider up so we don't exceed the max
  300. * frequency
  301. */
  302. clk = DIV_ROUND_UP(host->mclk, desired) - 2;
  303. if (clk >= 256)
  304. clk = 255;
  305. host->cclk = host->mclk / (clk + 2);
  306. } else {
  307. /*
  308. * PL180 TRM says f = mclk / (2 * (clkdiv + 1))
  309. * => clkdiv = mclk / (2 * f) - 1
  310. */
  311. clk = host->mclk / (2 * desired) - 1;
  312. if (clk >= 256)
  313. clk = 255;
  314. host->cclk = host->mclk / (2 * (clk + 1));
  315. }
  316. clk |= variant->clkreg_enable;
  317. clk |= MCI_CLK_ENABLE;
  318. /* This hasn't proven to be worthwhile */
  319. /* clk |= MCI_CLK_PWRSAVE; */
  320. }
  321. /* Set actual clock for debug */
  322. host->mmc->actual_clock = host->cclk;
  323. if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
  324. clk |= MCI_4BIT_BUS;
  325. if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
  326. clk |= variant->clkreg_8bit_bus_enable;
  327. if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
  328. host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
  329. clk |= variant->clkreg_neg_edge_enable;
  330. mmci_write_clkreg(host, clk);
  331. }
  332. static void
  333. mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
  334. {
  335. writel(0, host->base + MMCICOMMAND);
  336. BUG_ON(host->data);
  337. host->mrq = NULL;
  338. host->cmd = NULL;
  339. mmc_request_done(host->mmc, mrq);
  340. pm_runtime_mark_last_busy(mmc_dev(host->mmc));
  341. pm_runtime_put_autosuspend(mmc_dev(host->mmc));
  342. }
  343. static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
  344. {
  345. void __iomem *base = host->base;
  346. if (host->singleirq) {
  347. unsigned int mask0 = readl(base + MMCIMASK0);
  348. mask0 &= ~MCI_IRQ1MASK;
  349. mask0 |= mask;
  350. writel(mask0, base + MMCIMASK0);
  351. }
  352. writel(mask, base + MMCIMASK1);
  353. }
  354. static void mmci_stop_data(struct mmci_host *host)
  355. {
  356. mmci_write_datactrlreg(host, 0);
  357. mmci_set_mask1(host, 0);
  358. host->data = NULL;
  359. }
  360. static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
  361. {
  362. unsigned int flags = SG_MITER_ATOMIC;
  363. if (data->flags & MMC_DATA_READ)
  364. flags |= SG_MITER_TO_SG;
  365. else
  366. flags |= SG_MITER_FROM_SG;
  367. sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
  368. }
  369. /*
  370. * All the DMA operation mode stuff goes inside this ifdef.
  371. * This assumes that you have a generic DMA device interface,
  372. * no custom DMA interfaces are supported.
  373. */
  374. #ifdef CONFIG_DMA_ENGINE
  375. static void mmci_dma_setup(struct mmci_host *host)
  376. {
  377. const char *rxname, *txname;
  378. dma_cap_mask_t mask;
  379. struct variant_data *variant = host->variant;
  380. host->dma_rx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "rx");
  381. host->dma_tx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "tx");
  382. /* initialize pre request cookie */
  383. host->next_data.cookie = 1;
  384. /* Try to acquire a generic DMA engine slave channel */
  385. dma_cap_zero(mask);
  386. dma_cap_set(DMA_SLAVE, mask);
  387. /*
  388. * If only an RX channel is specified, the driver will
  389. * attempt to use it bidirectionally, however if it is
  390. * is specified but cannot be located, DMA will be disabled.
  391. */
  392. if (host->dma_rx_channel && !host->dma_tx_channel)
  393. host->dma_tx_channel = host->dma_rx_channel;
  394. if (host->dma_rx_channel)
  395. rxname = dma_chan_name(host->dma_rx_channel);
  396. else
  397. rxname = "none";
  398. if (host->dma_tx_channel)
  399. txname = dma_chan_name(host->dma_tx_channel);
  400. else
  401. txname = "none";
  402. dev_info(mmc_dev(host->mmc), "DMA channels RX %s, TX %s\n",
  403. rxname, txname);
  404. /*
  405. * Limit the maximum segment size in any SG entry according to
  406. * the parameters of the DMA engine device.
  407. */
  408. if (host->dma_tx_channel) {
  409. struct device *dev = host->dma_tx_channel->device->dev;
  410. unsigned int max_seg_size = dma_get_max_seg_size(dev);
  411. if (max_seg_size < host->mmc->max_seg_size)
  412. host->mmc->max_seg_size = max_seg_size;
  413. }
  414. if (host->dma_rx_channel) {
  415. struct device *dev = host->dma_rx_channel->device->dev;
  416. unsigned int max_seg_size = dma_get_max_seg_size(dev);
  417. if (max_seg_size < host->mmc->max_seg_size)
  418. host->mmc->max_seg_size = max_seg_size;
  419. }
  420. if (variant->qcom_dml && host->dma_rx_channel && host->dma_tx_channel)
  421. if (dml_hw_init(host, host->mmc->parent->of_node))
  422. variant->qcom_dml = false;
  423. }
  424. /*
  425. * This is used in or so inline it
  426. * so it can be discarded.
  427. */
  428. static inline void mmci_dma_release(struct mmci_host *host)
  429. {
  430. if (host->dma_rx_channel)
  431. dma_release_channel(host->dma_rx_channel);
  432. if (host->dma_tx_channel)
  433. dma_release_channel(host->dma_tx_channel);
  434. host->dma_rx_channel = host->dma_tx_channel = NULL;
  435. }
  436. static void mmci_dma_data_error(struct mmci_host *host)
  437. {
  438. dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n");
  439. dmaengine_terminate_all(host->dma_current);
  440. host->dma_current = NULL;
  441. host->dma_desc_current = NULL;
  442. host->data->host_cookie = 0;
  443. }
  444. static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
  445. {
  446. struct dma_chan *chan;
  447. enum dma_data_direction dir;
  448. if (data->flags & MMC_DATA_READ) {
  449. dir = DMA_FROM_DEVICE;
  450. chan = host->dma_rx_channel;
  451. } else {
  452. dir = DMA_TO_DEVICE;
  453. chan = host->dma_tx_channel;
  454. }
  455. dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, dir);
  456. }
  457. static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data)
  458. {
  459. u32 status;
  460. int i;
  461. /* Wait up to 1ms for the DMA to complete */
  462. for (i = 0; ; i++) {
  463. status = readl(host->base + MMCISTATUS);
  464. if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100)
  465. break;
  466. udelay(10);
  467. }
  468. /*
  469. * Check to see whether we still have some data left in the FIFO -
  470. * this catches DMA controllers which are unable to monitor the
  471. * DMALBREQ and DMALSREQ signals while allowing us to DMA to non-
  472. * contiguous buffers. On TX, we'll get a FIFO underrun error.
  473. */
  474. if (status & MCI_RXDATAAVLBLMASK) {
  475. mmci_dma_data_error(host);
  476. if (!data->error)
  477. data->error = -EIO;
  478. }
  479. if (!data->host_cookie)
  480. mmci_dma_unmap(host, data);
  481. /*
  482. * Use of DMA with scatter-gather is impossible.
  483. * Give up with DMA and switch back to PIO mode.
  484. */
  485. if (status & MCI_RXDATAAVLBLMASK) {
  486. dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n");
  487. mmci_dma_release(host);
  488. }
  489. host->dma_current = NULL;
  490. host->dma_desc_current = NULL;
  491. }
  492. /* prepares DMA channel and DMA descriptor, returns non-zero on failure */
  493. static int __mmci_dma_prep_data(struct mmci_host *host, struct mmc_data *data,
  494. struct dma_chan **dma_chan,
  495. struct dma_async_tx_descriptor **dma_desc)
  496. {
  497. struct variant_data *variant = host->variant;
  498. struct dma_slave_config conf = {
  499. .src_addr = host->phybase + MMCIFIFO,
  500. .dst_addr = host->phybase + MMCIFIFO,
  501. .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  502. .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  503. .src_maxburst = variant->fifohalfsize >> 2, /* # of words */
  504. .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
  505. .device_fc = false,
  506. };
  507. struct dma_chan *chan;
  508. struct dma_device *device;
  509. struct dma_async_tx_descriptor *desc;
  510. enum dma_data_direction buffer_dirn;
  511. int nr_sg;
  512. unsigned long flags = DMA_CTRL_ACK;
  513. if (data->flags & MMC_DATA_READ) {
  514. conf.direction = DMA_DEV_TO_MEM;
  515. buffer_dirn = DMA_FROM_DEVICE;
  516. chan = host->dma_rx_channel;
  517. } else {
  518. conf.direction = DMA_MEM_TO_DEV;
  519. buffer_dirn = DMA_TO_DEVICE;
  520. chan = host->dma_tx_channel;
  521. }
  522. /* If there's no DMA channel, fall back to PIO */
  523. if (!chan)
  524. return -EINVAL;
  525. /* If less than or equal to the fifo size, don't bother with DMA */
  526. if (data->blksz * data->blocks <= variant->fifosize)
  527. return -EINVAL;
  528. device = chan->device;
  529. nr_sg = dma_map_sg(device->dev, data->sg, data->sg_len, buffer_dirn);
  530. if (nr_sg == 0)
  531. return -EINVAL;
  532. if (host->variant->qcom_dml)
  533. flags |= DMA_PREP_INTERRUPT;
  534. dmaengine_slave_config(chan, &conf);
  535. desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg,
  536. conf.direction, flags);
  537. if (!desc)
  538. goto unmap_exit;
  539. *dma_chan = chan;
  540. *dma_desc = desc;
  541. return 0;
  542. unmap_exit:
  543. dma_unmap_sg(device->dev, data->sg, data->sg_len, buffer_dirn);
  544. return -ENOMEM;
  545. }
  546. static inline int mmci_dma_prep_data(struct mmci_host *host,
  547. struct mmc_data *data)
  548. {
  549. /* Check if next job is already prepared. */
  550. if (host->dma_current && host->dma_desc_current)
  551. return 0;
  552. /* No job were prepared thus do it now. */
  553. return __mmci_dma_prep_data(host, data, &host->dma_current,
  554. &host->dma_desc_current);
  555. }
  556. static inline int mmci_dma_prep_next(struct mmci_host *host,
  557. struct mmc_data *data)
  558. {
  559. struct mmci_host_next *nd = &host->next_data;
  560. return __mmci_dma_prep_data(host, data, &nd->dma_chan, &nd->dma_desc);
  561. }
  562. static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
  563. {
  564. int ret;
  565. struct mmc_data *data = host->data;
  566. ret = mmci_dma_prep_data(host, host->data);
  567. if (ret)
  568. return ret;
  569. /* Okay, go for it. */
  570. dev_vdbg(mmc_dev(host->mmc),
  571. "Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n",
  572. data->sg_len, data->blksz, data->blocks, data->flags);
  573. dmaengine_submit(host->dma_desc_current);
  574. dma_async_issue_pending(host->dma_current);
  575. if (host->variant->qcom_dml)
  576. dml_start_xfer(host, data);
  577. datactrl |= MCI_DPSM_DMAENABLE;
  578. /* Trigger the DMA transfer */
  579. mmci_write_datactrlreg(host, datactrl);
  580. /*
  581. * Let the MMCI say when the data is ended and it's time
  582. * to fire next DMA request. When that happens, MMCI will
  583. * call mmci_data_end()
  584. */
  585. writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK,
  586. host->base + MMCIMASK0);
  587. return 0;
  588. }
  589. static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
  590. {
  591. struct mmci_host_next *next = &host->next_data;
  592. WARN_ON(data->host_cookie && data->host_cookie != next->cookie);
  593. WARN_ON(!data->host_cookie && (next->dma_desc || next->dma_chan));
  594. host->dma_desc_current = next->dma_desc;
  595. host->dma_current = next->dma_chan;
  596. next->dma_desc = NULL;
  597. next->dma_chan = NULL;
  598. }
  599. static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq,
  600. bool is_first_req)
  601. {
  602. struct mmci_host *host = mmc_priv(mmc);
  603. struct mmc_data *data = mrq->data;
  604. struct mmci_host_next *nd = &host->next_data;
  605. if (!data)
  606. return;
  607. BUG_ON(data->host_cookie);
  608. if (mmci_validate_data(host, data))
  609. return;
  610. if (!mmci_dma_prep_next(host, data))
  611. data->host_cookie = ++nd->cookie < 0 ? 1 : nd->cookie;
  612. }
  613. static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
  614. int err)
  615. {
  616. struct mmci_host *host = mmc_priv(mmc);
  617. struct mmc_data *data = mrq->data;
  618. if (!data || !data->host_cookie)
  619. return;
  620. mmci_dma_unmap(host, data);
  621. if (err) {
  622. struct mmci_host_next *next = &host->next_data;
  623. struct dma_chan *chan;
  624. if (data->flags & MMC_DATA_READ)
  625. chan = host->dma_rx_channel;
  626. else
  627. chan = host->dma_tx_channel;
  628. dmaengine_terminate_all(chan);
  629. next->dma_desc = NULL;
  630. next->dma_chan = NULL;
  631. }
  632. }
  633. #else
  634. /* Blank functions if the DMA engine is not available */
  635. static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
  636. {
  637. }
  638. static inline void mmci_dma_setup(struct mmci_host *host)
  639. {
  640. }
  641. static inline void mmci_dma_release(struct mmci_host *host)
  642. {
  643. }
  644. static inline void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
  645. {
  646. }
  647. static inline void mmci_dma_finalize(struct mmci_host *host,
  648. struct mmc_data *data)
  649. {
  650. }
  651. static inline void mmci_dma_data_error(struct mmci_host *host)
  652. {
  653. }
  654. static inline int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
  655. {
  656. return -ENOSYS;
  657. }
  658. #define mmci_pre_request NULL
  659. #define mmci_post_request NULL
  660. #endif
  661. static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
  662. {
  663. struct variant_data *variant = host->variant;
  664. unsigned int datactrl, timeout, irqmask;
  665. unsigned long long clks;
  666. void __iomem *base;
  667. int blksz_bits;
  668. dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n",
  669. data->blksz, data->blocks, data->flags);
  670. host->data = data;
  671. host->size = data->blksz * data->blocks;
  672. data->bytes_xfered = 0;
  673. clks = (unsigned long long)data->timeout_ns * host->cclk;
  674. do_div(clks, NSEC_PER_SEC);
  675. timeout = data->timeout_clks + (unsigned int)clks;
  676. base = host->base;
  677. writel(timeout, base + MMCIDATATIMER);
  678. writel(host->size, base + MMCIDATALENGTH);
  679. blksz_bits = ffs(data->blksz) - 1;
  680. BUG_ON(1 << blksz_bits != data->blksz);
  681. if (variant->blksz_datactrl16)
  682. datactrl = MCI_DPSM_ENABLE | (data->blksz << 16);
  683. else if (variant->blksz_datactrl4)
  684. datactrl = MCI_DPSM_ENABLE | (data->blksz << 4);
  685. else
  686. datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
  687. if (data->flags & MMC_DATA_READ)
  688. datactrl |= MCI_DPSM_DIRECTION;
  689. /* The ST Micro variants has a special bit to enable SDIO */
  690. if (variant->sdio && host->mmc->card)
  691. if (mmc_card_sdio(host->mmc->card)) {
  692. /*
  693. * The ST Micro variants has a special bit
  694. * to enable SDIO.
  695. */
  696. u32 clk;
  697. datactrl |= MCI_ST_DPSM_SDIOEN;
  698. /*
  699. * The ST Micro variant for SDIO small write transfers
  700. * needs to have clock H/W flow control disabled,
  701. * otherwise the transfer will not start. The threshold
  702. * depends on the rate of MCLK.
  703. */
  704. if (data->flags & MMC_DATA_WRITE &&
  705. (host->size < 8 ||
  706. (host->size <= 8 && host->mclk > 50000000)))
  707. clk = host->clk_reg & ~variant->clkreg_enable;
  708. else
  709. clk = host->clk_reg | variant->clkreg_enable;
  710. mmci_write_clkreg(host, clk);
  711. }
  712. if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
  713. host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
  714. datactrl |= variant->datactrl_mask_ddrmode;
  715. /*
  716. * Attempt to use DMA operation mode, if this
  717. * should fail, fall back to PIO mode
  718. */
  719. if (!mmci_dma_start_data(host, datactrl))
  720. return;
  721. /* IRQ mode, map the SG list for CPU reading/writing */
  722. mmci_init_sg(host, data);
  723. if (data->flags & MMC_DATA_READ) {
  724. irqmask = MCI_RXFIFOHALFFULLMASK;
  725. /*
  726. * If we have less than the fifo 'half-full' threshold to
  727. * transfer, trigger a PIO interrupt as soon as any data
  728. * is available.
  729. */
  730. if (host->size < variant->fifohalfsize)
  731. irqmask |= MCI_RXDATAAVLBLMASK;
  732. } else {
  733. /*
  734. * We don't actually need to include "FIFO empty" here
  735. * since its implicit in "FIFO half empty".
  736. */
  737. irqmask = MCI_TXFIFOHALFEMPTYMASK;
  738. }
  739. mmci_write_datactrlreg(host, datactrl);
  740. writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
  741. mmci_set_mask1(host, irqmask);
  742. }
  743. static void
  744. mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c)
  745. {
  746. void __iomem *base = host->base;
  747. dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n",
  748. cmd->opcode, cmd->arg, cmd->flags);
  749. if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) {
  750. writel(0, base + MMCICOMMAND);
  751. mmci_reg_delay(host);
  752. }
  753. c |= cmd->opcode | MCI_CPSM_ENABLE;
  754. if (cmd->flags & MMC_RSP_PRESENT) {
  755. if (cmd->flags & MMC_RSP_136)
  756. c |= MCI_CPSM_LONGRSP;
  757. c |= MCI_CPSM_RESPONSE;
  758. }
  759. if (/*interrupt*/0)
  760. c |= MCI_CPSM_INTERRUPT;
  761. if (mmc_cmd_type(cmd) == MMC_CMD_ADTC)
  762. c |= host->variant->data_cmd_enable;
  763. host->cmd = cmd;
  764. writel(cmd->arg, base + MMCIARGUMENT);
  765. writel(c, base + MMCICOMMAND);
  766. }
  767. static void
  768. mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
  769. unsigned int status)
  770. {
  771. /* Make sure we have data to handle */
  772. if (!data)
  773. return;
  774. /* First check for errors */
  775. if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_STARTBITERR|
  776. MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
  777. u32 remain, success;
  778. /* Terminate the DMA transfer */
  779. if (dma_inprogress(host)) {
  780. mmci_dma_data_error(host);
  781. mmci_dma_unmap(host, data);
  782. }
  783. /*
  784. * Calculate how far we are into the transfer. Note that
  785. * the data counter gives the number of bytes transferred
  786. * on the MMC bus, not on the host side. On reads, this
  787. * can be as much as a FIFO-worth of data ahead. This
  788. * matters for FIFO overruns only.
  789. */
  790. remain = readl(host->base + MMCIDATACNT);
  791. success = data->blksz * data->blocks - remain;
  792. dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n",
  793. status, success);
  794. if (status & MCI_DATACRCFAIL) {
  795. /* Last block was not successful */
  796. success -= 1;
  797. data->error = -EILSEQ;
  798. } else if (status & MCI_DATATIMEOUT) {
  799. data->error = -ETIMEDOUT;
  800. } else if (status & MCI_STARTBITERR) {
  801. data->error = -ECOMM;
  802. } else if (status & MCI_TXUNDERRUN) {
  803. data->error = -EIO;
  804. } else if (status & MCI_RXOVERRUN) {
  805. if (success > host->variant->fifosize)
  806. success -= host->variant->fifosize;
  807. else
  808. success = 0;
  809. data->error = -EIO;
  810. }
  811. data->bytes_xfered = round_down(success, data->blksz);
  812. }
  813. if (status & MCI_DATABLOCKEND)
  814. dev_err(mmc_dev(host->mmc), "stray MCI_DATABLOCKEND interrupt\n");
  815. if (status & MCI_DATAEND || data->error) {
  816. if (dma_inprogress(host))
  817. mmci_dma_finalize(host, data);
  818. mmci_stop_data(host);
  819. if (!data->error)
  820. /* The error clause is handled above, success! */
  821. data->bytes_xfered = data->blksz * data->blocks;
  822. if (!data->stop || host->mrq->sbc) {
  823. mmci_request_end(host, data->mrq);
  824. } else {
  825. mmci_start_command(host, data->stop, 0);
  826. }
  827. }
  828. }
  829. static void
  830. mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
  831. unsigned int status)
  832. {
  833. void __iomem *base = host->base;
  834. bool sbc, busy_resp;
  835. if (!cmd)
  836. return;
  837. sbc = (cmd == host->mrq->sbc);
  838. busy_resp = host->variant->busy_detect && (cmd->flags & MMC_RSP_BUSY);
  839. if (!((status|host->busy_status) & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|
  840. MCI_CMDSENT|MCI_CMDRESPEND)))
  841. return;
  842. /* Check if we need to wait for busy completion. */
  843. if (host->busy_status && (status & MCI_ST_CARDBUSY))
  844. return;
  845. /* Enable busy completion if needed and supported. */
  846. if (!host->busy_status && busy_resp &&
  847. !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) &&
  848. (readl(base + MMCISTATUS) & MCI_ST_CARDBUSY)) {
  849. writel(readl(base + MMCIMASK0) | MCI_ST_BUSYEND,
  850. base + MMCIMASK0);
  851. host->busy_status = status & (MCI_CMDSENT|MCI_CMDRESPEND);
  852. return;
  853. }
  854. /* At busy completion, mask the IRQ and complete the request. */
  855. if (host->busy_status) {
  856. writel(readl(base + MMCIMASK0) & ~MCI_ST_BUSYEND,
  857. base + MMCIMASK0);
  858. host->busy_status = 0;
  859. }
  860. host->cmd = NULL;
  861. if (status & MCI_CMDTIMEOUT) {
  862. cmd->error = -ETIMEDOUT;
  863. } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
  864. cmd->error = -EILSEQ;
  865. } else {
  866. cmd->resp[0] = readl(base + MMCIRESPONSE0);
  867. cmd->resp[1] = readl(base + MMCIRESPONSE1);
  868. cmd->resp[2] = readl(base + MMCIRESPONSE2);
  869. cmd->resp[3] = readl(base + MMCIRESPONSE3);
  870. }
  871. if ((!sbc && !cmd->data) || cmd->error) {
  872. if (host->data) {
  873. /* Terminate the DMA transfer */
  874. if (dma_inprogress(host)) {
  875. mmci_dma_data_error(host);
  876. mmci_dma_unmap(host, host->data);
  877. }
  878. mmci_stop_data(host);
  879. }
  880. mmci_request_end(host, host->mrq);
  881. } else if (sbc) {
  882. mmci_start_command(host, host->mrq->cmd, 0);
  883. } else if (!(cmd->data->flags & MMC_DATA_READ)) {
  884. mmci_start_data(host, cmd->data);
  885. }
  886. }
  887. static int mmci_get_rx_fifocnt(struct mmci_host *host, u32 status, int remain)
  888. {
  889. return remain - (readl(host->base + MMCIFIFOCNT) << 2);
  890. }
  891. static int mmci_qcom_get_rx_fifocnt(struct mmci_host *host, u32 status, int r)
  892. {
  893. /*
  894. * on qcom SDCC4 only 8 words are used in each burst so only 8 addresses
  895. * from the fifo range should be used
  896. */
  897. if (status & MCI_RXFIFOHALFFULL)
  898. return host->variant->fifohalfsize;
  899. else if (status & MCI_RXDATAAVLBL)
  900. return 4;
  901. return 0;
  902. }
  903. static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain)
  904. {
  905. void __iomem *base = host->base;
  906. char *ptr = buffer;
  907. u32 status = readl(host->base + MMCISTATUS);
  908. int host_remain = host->size;
  909. do {
  910. int count = host->get_rx_fifocnt(host, status, host_remain);
  911. if (count > remain)
  912. count = remain;
  913. if (count <= 0)
  914. break;
  915. /*
  916. * SDIO especially may want to send something that is
  917. * not divisible by 4 (as opposed to card sectors
  918. * etc). Therefore make sure to always read the last bytes
  919. * while only doing full 32-bit reads towards the FIFO.
  920. */
  921. if (unlikely(count & 0x3)) {
  922. if (count < 4) {
  923. unsigned char buf[4];
  924. ioread32_rep(base + MMCIFIFO, buf, 1);
  925. memcpy(ptr, buf, count);
  926. } else {
  927. ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
  928. count &= ~0x3;
  929. }
  930. } else {
  931. ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
  932. }
  933. ptr += count;
  934. remain -= count;
  935. host_remain -= count;
  936. if (remain == 0)
  937. break;
  938. status = readl(base + MMCISTATUS);
  939. } while (status & MCI_RXDATAAVLBL);
  940. return ptr - buffer;
  941. }
  942. static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status)
  943. {
  944. struct variant_data *variant = host->variant;
  945. void __iomem *base = host->base;
  946. char *ptr = buffer;
  947. do {
  948. unsigned int count, maxcnt;
  949. maxcnt = status & MCI_TXFIFOEMPTY ?
  950. variant->fifosize : variant->fifohalfsize;
  951. count = min(remain, maxcnt);
  952. /*
  953. * SDIO especially may want to send something that is
  954. * not divisible by 4 (as opposed to card sectors
  955. * etc), and the FIFO only accept full 32-bit writes.
  956. * So compensate by adding +3 on the count, a single
  957. * byte become a 32bit write, 7 bytes will be two
  958. * 32bit writes etc.
  959. */
  960. iowrite32_rep(base + MMCIFIFO, ptr, (count + 3) >> 2);
  961. ptr += count;
  962. remain -= count;
  963. if (remain == 0)
  964. break;
  965. status = readl(base + MMCISTATUS);
  966. } while (status & MCI_TXFIFOHALFEMPTY);
  967. return ptr - buffer;
  968. }
  969. /*
  970. * PIO data transfer IRQ handler.
  971. */
  972. static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
  973. {
  974. struct mmci_host *host = dev_id;
  975. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  976. struct variant_data *variant = host->variant;
  977. void __iomem *base = host->base;
  978. unsigned long flags;
  979. u32 status;
  980. status = readl(base + MMCISTATUS);
  981. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  982. local_irq_save(flags);
  983. do {
  984. unsigned int remain, len;
  985. char *buffer;
  986. /*
  987. * For write, we only need to test the half-empty flag
  988. * here - if the FIFO is completely empty, then by
  989. * definition it is more than half empty.
  990. *
  991. * For read, check for data available.
  992. */
  993. if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
  994. break;
  995. if (!sg_miter_next(sg_miter))
  996. break;
  997. buffer = sg_miter->addr;
  998. remain = sg_miter->length;
  999. len = 0;
  1000. if (status & MCI_RXACTIVE)
  1001. len = mmci_pio_read(host, buffer, remain);
  1002. if (status & MCI_TXACTIVE)
  1003. len = mmci_pio_write(host, buffer, remain, status);
  1004. sg_miter->consumed = len;
  1005. host->size -= len;
  1006. remain -= len;
  1007. if (remain)
  1008. break;
  1009. status = readl(base + MMCISTATUS);
  1010. } while (1);
  1011. sg_miter_stop(sg_miter);
  1012. local_irq_restore(flags);
  1013. /*
  1014. * If we have less than the fifo 'half-full' threshold to transfer,
  1015. * trigger a PIO interrupt as soon as any data is available.
  1016. */
  1017. if (status & MCI_RXACTIVE && host->size < variant->fifohalfsize)
  1018. mmci_set_mask1(host, MCI_RXDATAAVLBLMASK);
  1019. /*
  1020. * If we run out of data, disable the data IRQs; this
  1021. * prevents a race where the FIFO becomes empty before
  1022. * the chip itself has disabled the data path, and
  1023. * stops us racing with our data end IRQ.
  1024. */
  1025. if (host->size == 0) {
  1026. mmci_set_mask1(host, 0);
  1027. writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0);
  1028. }
  1029. return IRQ_HANDLED;
  1030. }
  1031. /*
  1032. * Handle completion of command and data transfers.
  1033. */
  1034. static irqreturn_t mmci_irq(int irq, void *dev_id)
  1035. {
  1036. struct mmci_host *host = dev_id;
  1037. u32 status;
  1038. int ret = 0;
  1039. spin_lock(&host->lock);
  1040. do {
  1041. status = readl(host->base + MMCISTATUS);
  1042. if (host->singleirq) {
  1043. if (status & readl(host->base + MMCIMASK1))
  1044. mmci_pio_irq(irq, dev_id);
  1045. status &= ~MCI_IRQ1MASK;
  1046. }
  1047. /*
  1048. * We intentionally clear the MCI_ST_CARDBUSY IRQ here (if it's
  1049. * enabled) since the HW seems to be triggering the IRQ on both
  1050. * edges while monitoring DAT0 for busy completion.
  1051. */
  1052. status &= readl(host->base + MMCIMASK0);
  1053. writel(status, host->base + MMCICLEAR);
  1054. dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status);
  1055. if (host->variant->reversed_irq_handling) {
  1056. mmci_data_irq(host, host->data, status);
  1057. mmci_cmd_irq(host, host->cmd, status);
  1058. } else {
  1059. mmci_cmd_irq(host, host->cmd, status);
  1060. mmci_data_irq(host, host->data, status);
  1061. }
  1062. /* Don't poll for busy completion in irq context. */
  1063. if (host->busy_status)
  1064. status &= ~MCI_ST_CARDBUSY;
  1065. ret = 1;
  1066. } while (status);
  1067. spin_unlock(&host->lock);
  1068. return IRQ_RETVAL(ret);
  1069. }
  1070. static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
  1071. {
  1072. struct mmci_host *host = mmc_priv(mmc);
  1073. unsigned long flags;
  1074. WARN_ON(host->mrq != NULL);
  1075. mrq->cmd->error = mmci_validate_data(host, mrq->data);
  1076. if (mrq->cmd->error) {
  1077. mmc_request_done(mmc, mrq);
  1078. return;
  1079. }
  1080. pm_runtime_get_sync(mmc_dev(mmc));
  1081. spin_lock_irqsave(&host->lock, flags);
  1082. host->mrq = mrq;
  1083. if (mrq->data)
  1084. mmci_get_next_data(host, mrq->data);
  1085. if (mrq->data && mrq->data->flags & MMC_DATA_READ)
  1086. mmci_start_data(host, mrq->data);
  1087. if (mrq->sbc)
  1088. mmci_start_command(host, mrq->sbc, 0);
  1089. else
  1090. mmci_start_command(host, mrq->cmd, 0);
  1091. spin_unlock_irqrestore(&host->lock, flags);
  1092. }
  1093. static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  1094. {
  1095. struct mmci_host *host = mmc_priv(mmc);
  1096. struct variant_data *variant = host->variant;
  1097. u32 pwr = 0;
  1098. unsigned long flags;
  1099. int ret;
  1100. pm_runtime_get_sync(mmc_dev(mmc));
  1101. if (host->plat->ios_handler &&
  1102. host->plat->ios_handler(mmc_dev(mmc), ios))
  1103. dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
  1104. switch (ios->power_mode) {
  1105. case MMC_POWER_OFF:
  1106. if (!IS_ERR(mmc->supply.vmmc))
  1107. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
  1108. if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
  1109. regulator_disable(mmc->supply.vqmmc);
  1110. host->vqmmc_enabled = false;
  1111. }
  1112. break;
  1113. case MMC_POWER_UP:
  1114. if (!IS_ERR(mmc->supply.vmmc))
  1115. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
  1116. /*
  1117. * The ST Micro variant doesn't have the PL180s MCI_PWR_UP
  1118. * and instead uses MCI_PWR_ON so apply whatever value is
  1119. * configured in the variant data.
  1120. */
  1121. pwr |= variant->pwrreg_powerup;
  1122. break;
  1123. case MMC_POWER_ON:
  1124. if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
  1125. ret = regulator_enable(mmc->supply.vqmmc);
  1126. if (ret < 0)
  1127. dev_err(mmc_dev(mmc),
  1128. "failed to enable vqmmc regulator\n");
  1129. else
  1130. host->vqmmc_enabled = true;
  1131. }
  1132. pwr |= MCI_PWR_ON;
  1133. break;
  1134. }
  1135. if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) {
  1136. /*
  1137. * The ST Micro variant has some additional bits
  1138. * indicating signal direction for the signals in
  1139. * the SD/MMC bus and feedback-clock usage.
  1140. */
  1141. pwr |= host->pwr_reg_add;
  1142. if (ios->bus_width == MMC_BUS_WIDTH_4)
  1143. pwr &= ~MCI_ST_DATA74DIREN;
  1144. else if (ios->bus_width == MMC_BUS_WIDTH_1)
  1145. pwr &= (~MCI_ST_DATA74DIREN &
  1146. ~MCI_ST_DATA31DIREN &
  1147. ~MCI_ST_DATA2DIREN);
  1148. }
  1149. if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
  1150. if (host->hw_designer != AMBA_VENDOR_ST)
  1151. pwr |= MCI_ROD;
  1152. else {
  1153. /*
  1154. * The ST Micro variant use the ROD bit for something
  1155. * else and only has OD (Open Drain).
  1156. */
  1157. pwr |= MCI_OD;
  1158. }
  1159. }
  1160. /*
  1161. * If clock = 0 and the variant requires the MMCIPOWER to be used for
  1162. * gating the clock, the MCI_PWR_ON bit is cleared.
  1163. */
  1164. if (!ios->clock && variant->pwrreg_clkgate)
  1165. pwr &= ~MCI_PWR_ON;
  1166. if (host->variant->explicit_mclk_control &&
  1167. ios->clock != host->clock_cache) {
  1168. ret = clk_set_rate(host->clk, ios->clock);
  1169. if (ret < 0)
  1170. dev_err(mmc_dev(host->mmc),
  1171. "Error setting clock rate (%d)\n", ret);
  1172. else
  1173. host->mclk = clk_get_rate(host->clk);
  1174. }
  1175. host->clock_cache = ios->clock;
  1176. spin_lock_irqsave(&host->lock, flags);
  1177. mmci_set_clkreg(host, ios->clock);
  1178. mmci_write_pwrreg(host, pwr);
  1179. mmci_reg_delay(host);
  1180. spin_unlock_irqrestore(&host->lock, flags);
  1181. pm_runtime_mark_last_busy(mmc_dev(mmc));
  1182. pm_runtime_put_autosuspend(mmc_dev(mmc));
  1183. }
  1184. static int mmci_get_cd(struct mmc_host *mmc)
  1185. {
  1186. struct mmci_host *host = mmc_priv(mmc);
  1187. struct mmci_platform_data *plat = host->plat;
  1188. unsigned int status = mmc_gpio_get_cd(mmc);
  1189. if (status == -ENOSYS) {
  1190. if (!plat->status)
  1191. return 1; /* Assume always present */
  1192. status = plat->status(mmc_dev(host->mmc));
  1193. }
  1194. return status;
  1195. }
  1196. static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
  1197. {
  1198. int ret = 0;
  1199. if (!IS_ERR(mmc->supply.vqmmc)) {
  1200. pm_runtime_get_sync(mmc_dev(mmc));
  1201. switch (ios->signal_voltage) {
  1202. case MMC_SIGNAL_VOLTAGE_330:
  1203. ret = regulator_set_voltage(mmc->supply.vqmmc,
  1204. 2700000, 3600000);
  1205. break;
  1206. case MMC_SIGNAL_VOLTAGE_180:
  1207. ret = regulator_set_voltage(mmc->supply.vqmmc,
  1208. 1700000, 1950000);
  1209. break;
  1210. case MMC_SIGNAL_VOLTAGE_120:
  1211. ret = regulator_set_voltage(mmc->supply.vqmmc,
  1212. 1100000, 1300000);
  1213. break;
  1214. }
  1215. if (ret)
  1216. dev_warn(mmc_dev(mmc), "Voltage switch failed\n");
  1217. pm_runtime_mark_last_busy(mmc_dev(mmc));
  1218. pm_runtime_put_autosuspend(mmc_dev(mmc));
  1219. }
  1220. return ret;
  1221. }
  1222. static struct mmc_host_ops mmci_ops = {
  1223. .request = mmci_request,
  1224. .pre_req = mmci_pre_request,
  1225. .post_req = mmci_post_request,
  1226. .set_ios = mmci_set_ios,
  1227. .get_ro = mmc_gpio_get_ro,
  1228. .get_cd = mmci_get_cd,
  1229. .start_signal_voltage_switch = mmci_sig_volt_switch,
  1230. };
  1231. static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
  1232. {
  1233. struct mmci_host *host = mmc_priv(mmc);
  1234. int ret = mmc_of_parse(mmc);
  1235. if (ret)
  1236. return ret;
  1237. if (of_get_property(np, "st,sig-dir-dat0", NULL))
  1238. host->pwr_reg_add |= MCI_ST_DATA0DIREN;
  1239. if (of_get_property(np, "st,sig-dir-dat2", NULL))
  1240. host->pwr_reg_add |= MCI_ST_DATA2DIREN;
  1241. if (of_get_property(np, "st,sig-dir-dat31", NULL))
  1242. host->pwr_reg_add |= MCI_ST_DATA31DIREN;
  1243. if (of_get_property(np, "st,sig-dir-dat74", NULL))
  1244. host->pwr_reg_add |= MCI_ST_DATA74DIREN;
  1245. if (of_get_property(np, "st,sig-dir-cmd", NULL))
  1246. host->pwr_reg_add |= MCI_ST_CMDDIREN;
  1247. if (of_get_property(np, "st,sig-pin-fbclk", NULL))
  1248. host->pwr_reg_add |= MCI_ST_FBCLKEN;
  1249. if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
  1250. mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
  1251. if (of_get_property(np, "mmc-cap-sd-highspeed", NULL))
  1252. mmc->caps |= MMC_CAP_SD_HIGHSPEED;
  1253. return 0;
  1254. }
  1255. static int mmci_probe(struct amba_device *dev,
  1256. const struct amba_id *id)
  1257. {
  1258. struct mmci_platform_data *plat = dev->dev.platform_data;
  1259. struct device_node *np = dev->dev.of_node;
  1260. struct variant_data *variant = id->data;
  1261. struct mmci_host *host;
  1262. struct mmc_host *mmc;
  1263. int ret;
  1264. /* Must have platform data or Device Tree. */
  1265. if (!plat && !np) {
  1266. dev_err(&dev->dev, "No plat data or DT found\n");
  1267. return -EINVAL;
  1268. }
  1269. if (!plat) {
  1270. plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL);
  1271. if (!plat)
  1272. return -ENOMEM;
  1273. }
  1274. mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
  1275. if (!mmc)
  1276. return -ENOMEM;
  1277. ret = mmci_of_parse(np, mmc);
  1278. if (ret)
  1279. goto host_free;
  1280. host = mmc_priv(mmc);
  1281. host->mmc = mmc;
  1282. host->hw_designer = amba_manf(dev);
  1283. host->hw_revision = amba_rev(dev);
  1284. dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
  1285. dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision);
  1286. host->clk = devm_clk_get(&dev->dev, NULL);
  1287. if (IS_ERR(host->clk)) {
  1288. ret = PTR_ERR(host->clk);
  1289. goto host_free;
  1290. }
  1291. ret = clk_prepare_enable(host->clk);
  1292. if (ret)
  1293. goto host_free;
  1294. if (variant->qcom_fifo)
  1295. host->get_rx_fifocnt = mmci_qcom_get_rx_fifocnt;
  1296. else
  1297. host->get_rx_fifocnt = mmci_get_rx_fifocnt;
  1298. host->plat = plat;
  1299. host->variant = variant;
  1300. host->mclk = clk_get_rate(host->clk);
  1301. /*
  1302. * According to the spec, mclk is max 100 MHz,
  1303. * so we try to adjust the clock down to this,
  1304. * (if possible).
  1305. */
  1306. if (host->mclk > variant->f_max) {
  1307. ret = clk_set_rate(host->clk, variant->f_max);
  1308. if (ret < 0)
  1309. goto clk_disable;
  1310. host->mclk = clk_get_rate(host->clk);
  1311. dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n",
  1312. host->mclk);
  1313. }
  1314. host->phybase = dev->res.start;
  1315. host->base = devm_ioremap_resource(&dev->dev, &dev->res);
  1316. if (IS_ERR(host->base)) {
  1317. ret = PTR_ERR(host->base);
  1318. goto clk_disable;
  1319. }
  1320. /*
  1321. * The ARM and ST versions of the block have slightly different
  1322. * clock divider equations which means that the minimum divider
  1323. * differs too.
  1324. * on Qualcomm like controllers get the nearest minimum clock to 100Khz
  1325. */
  1326. if (variant->st_clkdiv)
  1327. mmc->f_min = DIV_ROUND_UP(host->mclk, 257);
  1328. else if (variant->explicit_mclk_control)
  1329. mmc->f_min = clk_round_rate(host->clk, 100000);
  1330. else
  1331. mmc->f_min = DIV_ROUND_UP(host->mclk, 512);
  1332. /*
  1333. * If no maximum operating frequency is supplied, fall back to use
  1334. * the module parameter, which has a (low) default value in case it
  1335. * is not specified. Either value must not exceed the clock rate into
  1336. * the block, of course.
  1337. */
  1338. if (mmc->f_max)
  1339. mmc->f_max = variant->explicit_mclk_control ?
  1340. min(variant->f_max, mmc->f_max) :
  1341. min(host->mclk, mmc->f_max);
  1342. else
  1343. mmc->f_max = variant->explicit_mclk_control ?
  1344. fmax : min(host->mclk, fmax);
  1345. dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
  1346. /* Get regulators and the supported OCR mask */
  1347. mmc_regulator_get_supply(mmc);
  1348. if (!mmc->ocr_avail)
  1349. mmc->ocr_avail = plat->ocr_mask;
  1350. else if (plat->ocr_mask)
  1351. dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
  1352. /* DT takes precedence over platform data. */
  1353. if (!np) {
  1354. if (!plat->cd_invert)
  1355. mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
  1356. mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
  1357. }
  1358. /* We support these capabilities. */
  1359. mmc->caps |= MMC_CAP_CMD23;
  1360. if (variant->busy_detect) {
  1361. mmci_ops.card_busy = mmci_card_busy;
  1362. mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
  1363. mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
  1364. mmc->max_busy_timeout = 0;
  1365. }
  1366. mmc->ops = &mmci_ops;
  1367. /* We support these PM capabilities. */
  1368. mmc->pm_caps |= MMC_PM_KEEP_POWER;
  1369. /*
  1370. * We can do SGIO
  1371. */
  1372. mmc->max_segs = NR_SG;
  1373. /*
  1374. * Since only a certain number of bits are valid in the data length
  1375. * register, we must ensure that we don't exceed 2^num-1 bytes in a
  1376. * single request.
  1377. */
  1378. mmc->max_req_size = (1 << variant->datalength_bits) - 1;
  1379. /*
  1380. * Set the maximum segment size. Since we aren't doing DMA
  1381. * (yet) we are only limited by the data length register.
  1382. */
  1383. mmc->max_seg_size = mmc->max_req_size;
  1384. /*
  1385. * Block size can be up to 2048 bytes, but must be a power of two.
  1386. */
  1387. mmc->max_blk_size = 1 << 11;
  1388. /*
  1389. * Limit the number of blocks transferred so that we don't overflow
  1390. * the maximum request size.
  1391. */
  1392. mmc->max_blk_count = mmc->max_req_size >> 11;
  1393. spin_lock_init(&host->lock);
  1394. writel(0, host->base + MMCIMASK0);
  1395. writel(0, host->base + MMCIMASK1);
  1396. writel(0xfff, host->base + MMCICLEAR);
  1397. /* If DT, cd/wp gpios must be supplied through it. */
  1398. if (!np && gpio_is_valid(plat->gpio_cd)) {
  1399. ret = mmc_gpio_request_cd(mmc, plat->gpio_cd, 0);
  1400. if (ret)
  1401. goto clk_disable;
  1402. }
  1403. if (!np && gpio_is_valid(plat->gpio_wp)) {
  1404. ret = mmc_gpio_request_ro(mmc, plat->gpio_wp);
  1405. if (ret)
  1406. goto clk_disable;
  1407. }
  1408. ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED,
  1409. DRIVER_NAME " (cmd)", host);
  1410. if (ret)
  1411. goto clk_disable;
  1412. if (!dev->irq[1])
  1413. host->singleirq = true;
  1414. else {
  1415. ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq,
  1416. IRQF_SHARED, DRIVER_NAME " (pio)", host);
  1417. if (ret)
  1418. goto clk_disable;
  1419. }
  1420. writel(MCI_IRQENABLE, host->base + MMCIMASK0);
  1421. amba_set_drvdata(dev, mmc);
  1422. dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
  1423. mmc_hostname(mmc), amba_part(dev), amba_manf(dev),
  1424. amba_rev(dev), (unsigned long long)dev->res.start,
  1425. dev->irq[0], dev->irq[1]);
  1426. mmci_dma_setup(host);
  1427. pm_runtime_set_autosuspend_delay(&dev->dev, 50);
  1428. pm_runtime_use_autosuspend(&dev->dev);
  1429. pm_runtime_put(&dev->dev);
  1430. mmc_add_host(mmc);
  1431. return 0;
  1432. clk_disable:
  1433. clk_disable_unprepare(host->clk);
  1434. host_free:
  1435. mmc_free_host(mmc);
  1436. return ret;
  1437. }
  1438. static int mmci_remove(struct amba_device *dev)
  1439. {
  1440. struct mmc_host *mmc = amba_get_drvdata(dev);
  1441. if (mmc) {
  1442. struct mmci_host *host = mmc_priv(mmc);
  1443. /*
  1444. * Undo pm_runtime_put() in probe. We use the _sync
  1445. * version here so that we can access the primecell.
  1446. */
  1447. pm_runtime_get_sync(&dev->dev);
  1448. mmc_remove_host(mmc);
  1449. writel(0, host->base + MMCIMASK0);
  1450. writel(0, host->base + MMCIMASK1);
  1451. writel(0, host->base + MMCICOMMAND);
  1452. writel(0, host->base + MMCIDATACTRL);
  1453. mmci_dma_release(host);
  1454. clk_disable_unprepare(host->clk);
  1455. mmc_free_host(mmc);
  1456. }
  1457. return 0;
  1458. }
  1459. #ifdef CONFIG_PM
  1460. static void mmci_save(struct mmci_host *host)
  1461. {
  1462. unsigned long flags;
  1463. spin_lock_irqsave(&host->lock, flags);
  1464. writel(0, host->base + MMCIMASK0);
  1465. if (host->variant->pwrreg_nopower) {
  1466. writel(0, host->base + MMCIDATACTRL);
  1467. writel(0, host->base + MMCIPOWER);
  1468. writel(0, host->base + MMCICLOCK);
  1469. }
  1470. mmci_reg_delay(host);
  1471. spin_unlock_irqrestore(&host->lock, flags);
  1472. }
  1473. static void mmci_restore(struct mmci_host *host)
  1474. {
  1475. unsigned long flags;
  1476. spin_lock_irqsave(&host->lock, flags);
  1477. if (host->variant->pwrreg_nopower) {
  1478. writel(host->clk_reg, host->base + MMCICLOCK);
  1479. writel(host->datactrl_reg, host->base + MMCIDATACTRL);
  1480. writel(host->pwr_reg, host->base + MMCIPOWER);
  1481. }
  1482. writel(MCI_IRQENABLE, host->base + MMCIMASK0);
  1483. mmci_reg_delay(host);
  1484. spin_unlock_irqrestore(&host->lock, flags);
  1485. }
  1486. static int mmci_runtime_suspend(struct device *dev)
  1487. {
  1488. struct amba_device *adev = to_amba_device(dev);
  1489. struct mmc_host *mmc = amba_get_drvdata(adev);
  1490. if (mmc) {
  1491. struct mmci_host *host = mmc_priv(mmc);
  1492. pinctrl_pm_select_sleep_state(dev);
  1493. mmci_save(host);
  1494. clk_disable_unprepare(host->clk);
  1495. }
  1496. return 0;
  1497. }
  1498. static int mmci_runtime_resume(struct device *dev)
  1499. {
  1500. struct amba_device *adev = to_amba_device(dev);
  1501. struct mmc_host *mmc = amba_get_drvdata(adev);
  1502. if (mmc) {
  1503. struct mmci_host *host = mmc_priv(mmc);
  1504. clk_prepare_enable(host->clk);
  1505. mmci_restore(host);
  1506. pinctrl_pm_select_default_state(dev);
  1507. }
  1508. return 0;
  1509. }
  1510. #endif
  1511. static const struct dev_pm_ops mmci_dev_pm_ops = {
  1512. SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  1513. pm_runtime_force_resume)
  1514. SET_PM_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL)
  1515. };
  1516. static struct amba_id mmci_ids[] = {
  1517. {
  1518. .id = 0x00041180,
  1519. .mask = 0xff0fffff,
  1520. .data = &variant_arm,
  1521. },
  1522. {
  1523. .id = 0x01041180,
  1524. .mask = 0xff0fffff,
  1525. .data = &variant_arm_extended_fifo,
  1526. },
  1527. {
  1528. .id = 0x02041180,
  1529. .mask = 0xff0fffff,
  1530. .data = &variant_arm_extended_fifo_hwfc,
  1531. },
  1532. {
  1533. .id = 0x00041181,
  1534. .mask = 0x000fffff,
  1535. .data = &variant_arm,
  1536. },
  1537. /* ST Micro variants */
  1538. {
  1539. .id = 0x00180180,
  1540. .mask = 0x00ffffff,
  1541. .data = &variant_u300,
  1542. },
  1543. {
  1544. .id = 0x10180180,
  1545. .mask = 0xf0ffffff,
  1546. .data = &variant_nomadik,
  1547. },
  1548. {
  1549. .id = 0x00280180,
  1550. .mask = 0x00ffffff,
  1551. .data = &variant_u300,
  1552. },
  1553. {
  1554. .id = 0x00480180,
  1555. .mask = 0xf0ffffff,
  1556. .data = &variant_ux500,
  1557. },
  1558. {
  1559. .id = 0x10480180,
  1560. .mask = 0xf0ffffff,
  1561. .data = &variant_ux500v2,
  1562. },
  1563. /* Qualcomm variants */
  1564. {
  1565. .id = 0x00051180,
  1566. .mask = 0x000fffff,
  1567. .data = &variant_qcom,
  1568. },
  1569. { 0, 0 },
  1570. };
  1571. MODULE_DEVICE_TABLE(amba, mmci_ids);
  1572. static struct amba_driver mmci_driver = {
  1573. .drv = {
  1574. .name = DRIVER_NAME,
  1575. .pm = &mmci_dev_pm_ops,
  1576. },
  1577. .probe = mmci_probe,
  1578. .remove = mmci_remove,
  1579. .id_table = mmci_ids,
  1580. };
  1581. module_amba_driver(mmci_driver);
  1582. module_param(fmax, uint, 0444);
  1583. MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
  1584. MODULE_LICENSE("GPL");