sdhci-pxav3.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2010 Marvell International Ltd.
  4. * Zhangfei Gao <zhangfei.gao@marvell.com>
  5. * Kevin Wang <dwang4@marvell.com>
  6. * Mingwei Wang <mwwang@marvell.com>
  7. * Philip Rakity <prakity@marvell.com>
  8. * Mark Brown <markb@marvell.com>
  9. */
  10. #include <linux/err.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/clk.h>
  14. #include <linux/io.h>
  15. #include <linux/mmc/card.h>
  16. #include <linux/mmc/host.h>
  17. #include <linux/platform_data/pxa_sdhci.h>
  18. #include <linux/slab.h>
  19. #include <linux/delay.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. #include <linux/pinctrl/consumer.h>
  24. #include <linux/pm.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/mbus.h>
  27. #include <linux/units.h>
  28. #include "sdhci.h"
  29. #include "sdhci-pltfm.h"
  30. #define PXAV3_RPM_DELAY_MS 50
  31. #define SD_CLOCK_BURST_SIZE_SETUP 0x10A
  32. #define SDCLK_SEL 0x100
  33. #define SDCLK_DELAY_SHIFT 9
  34. #define SDCLK_DELAY_MASK 0x1f
  35. #define SD_CFG_FIFO_PARAM 0x100
  36. #define SDCFG_GEN_PAD_CLK_ON (1<<6)
  37. #define SDCFG_GEN_PAD_CLK_CNT_MASK 0xFF
  38. #define SDCFG_GEN_PAD_CLK_CNT_SHIFT 24
  39. #define SD_SPI_MODE 0x108
  40. #define SD_CE_ATA_1 0x10C
  41. #define SD_CE_ATA_2 0x10E
  42. #define SDCE_MISC_INT (1<<2)
  43. #define SDCE_MISC_INT_EN (1<<1)
  44. struct sdhci_pxa {
  45. struct clk *clk_core;
  46. struct clk *clk_io;
  47. u8 power_mode;
  48. void __iomem *sdio3_conf_reg;
  49. struct pinctrl *pinctrl;
  50. struct pinctrl_state *pins_default;
  51. struct pinctrl_state *pins_uhs;
  52. };
  53. /*
  54. * These registers are relative to the second register region, for the
  55. * MBus bridge.
  56. */
  57. #define SDHCI_WINDOW_CTRL(i) (0x80 + ((i) << 3))
  58. #define SDHCI_WINDOW_BASE(i) (0x84 + ((i) << 3))
  59. #define SDHCI_MAX_WIN_NUM 8
  60. /*
  61. * Fields below belong to SDIO3 Configuration Register (third register
  62. * region for the Armada 38x flavor)
  63. */
  64. #define SDIO3_CONF_CLK_INV BIT(0)
  65. #define SDIO3_CONF_SD_FB_CLK BIT(2)
  66. static int mv_conf_mbus_windows(struct platform_device *pdev,
  67. const struct mbus_dram_target_info *dram)
  68. {
  69. int i;
  70. void __iomem *regs;
  71. struct resource *res;
  72. if (!dram) {
  73. dev_err(&pdev->dev, "no mbus dram info\n");
  74. return -EINVAL;
  75. }
  76. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  77. if (!res) {
  78. dev_err(&pdev->dev, "cannot get mbus registers\n");
  79. return -EINVAL;
  80. }
  81. regs = ioremap(res->start, resource_size(res));
  82. if (!regs) {
  83. dev_err(&pdev->dev, "cannot map mbus registers\n");
  84. return -ENOMEM;
  85. }
  86. for (i = 0; i < SDHCI_MAX_WIN_NUM; i++) {
  87. writel(0, regs + SDHCI_WINDOW_CTRL(i));
  88. writel(0, regs + SDHCI_WINDOW_BASE(i));
  89. }
  90. for (i = 0; i < dram->num_cs; i++) {
  91. const struct mbus_dram_window *cs = dram->cs + i;
  92. /* Write size, attributes and target id to control register */
  93. writel(((cs->size - 1) & 0xffff0000) |
  94. (cs->mbus_attr << 8) |
  95. (dram->mbus_dram_target_id << 4) | 1,
  96. regs + SDHCI_WINDOW_CTRL(i));
  97. /* Write base address to base register */
  98. writel(cs->base, regs + SDHCI_WINDOW_BASE(i));
  99. }
  100. iounmap(regs);
  101. return 0;
  102. }
  103. static int armada_38x_quirks(struct platform_device *pdev,
  104. struct sdhci_host *host)
  105. {
  106. struct device_node *np = pdev->dev.of_node;
  107. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  108. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  109. struct resource *res;
  110. host->quirks &= ~SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN;
  111. sdhci_read_caps(host);
  112. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  113. "conf-sdio3");
  114. if (res) {
  115. pxa->sdio3_conf_reg = devm_ioremap_resource(&pdev->dev, res);
  116. if (IS_ERR(pxa->sdio3_conf_reg))
  117. return PTR_ERR(pxa->sdio3_conf_reg);
  118. } else {
  119. /*
  120. * According to erratum 'FE-2946959' both SDR50 and DDR50
  121. * modes require specific clock adjustments in SDIO3
  122. * Configuration register, if the adjustment is not done,
  123. * remove them from the capabilities.
  124. */
  125. host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_DDR50);
  126. dev_warn(&pdev->dev, "conf-sdio3 register not found: disabling SDR50 and DDR50 modes.\nConsider updating your dtb\n");
  127. }
  128. /*
  129. * According to erratum 'ERR-7878951' Armada 38x SDHCI
  130. * controller has different capabilities than the ones shown
  131. * in its registers
  132. */
  133. if (of_property_read_bool(np, "no-1-8-v")) {
  134. host->caps &= ~SDHCI_CAN_VDD_180;
  135. host->mmc->caps &= ~MMC_CAP_1_8V_DDR;
  136. } else {
  137. host->caps &= ~SDHCI_CAN_VDD_330;
  138. }
  139. host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_USE_SDR50_TUNING);
  140. return 0;
  141. }
  142. static void pxav3_reset(struct sdhci_host *host, u8 mask)
  143. {
  144. struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
  145. struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
  146. sdhci_reset(host, mask);
  147. if (mask == SDHCI_RESET_ALL) {
  148. /*
  149. * tune timing of read data/command when crc error happen
  150. * no performance impact
  151. */
  152. if (pdata && 0 != pdata->clk_delay_cycles) {
  153. u16 tmp;
  154. tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
  155. tmp |= (pdata->clk_delay_cycles & SDCLK_DELAY_MASK)
  156. << SDCLK_DELAY_SHIFT;
  157. tmp |= SDCLK_SEL;
  158. writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
  159. }
  160. }
  161. }
  162. #define MAX_WAIT_COUNT 5
  163. static void pxav3_gen_init_74_clocks(struct sdhci_host *host, u8 power_mode)
  164. {
  165. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  166. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  167. u16 tmp;
  168. int count;
  169. if (pxa->power_mode == MMC_POWER_UP
  170. && power_mode == MMC_POWER_ON) {
  171. dev_dbg(mmc_dev(host->mmc),
  172. "%s: slot->power_mode = %d,"
  173. "ios->power_mode = %d\n",
  174. __func__,
  175. pxa->power_mode,
  176. power_mode);
  177. /* set we want notice of when 74 clocks are sent */
  178. tmp = readw(host->ioaddr + SD_CE_ATA_2);
  179. tmp |= SDCE_MISC_INT_EN;
  180. writew(tmp, host->ioaddr + SD_CE_ATA_2);
  181. /* start sending the 74 clocks */
  182. tmp = readw(host->ioaddr + SD_CFG_FIFO_PARAM);
  183. tmp |= SDCFG_GEN_PAD_CLK_ON;
  184. writew(tmp, host->ioaddr + SD_CFG_FIFO_PARAM);
  185. /* slowest speed is about 100KHz or 10usec per clock */
  186. udelay(740);
  187. count = 0;
  188. while (count++ < MAX_WAIT_COUNT) {
  189. if ((readw(host->ioaddr + SD_CE_ATA_2)
  190. & SDCE_MISC_INT) == 0)
  191. break;
  192. udelay(10);
  193. }
  194. if (count == MAX_WAIT_COUNT)
  195. dev_warn(mmc_dev(host->mmc), "74 clock interrupt not cleared\n");
  196. /* clear the interrupt bit if posted */
  197. tmp = readw(host->ioaddr + SD_CE_ATA_2);
  198. tmp |= SDCE_MISC_INT;
  199. writew(tmp, host->ioaddr + SD_CE_ATA_2);
  200. }
  201. pxa->power_mode = power_mode;
  202. }
  203. static void pxav3_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
  204. {
  205. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  206. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  207. u16 ctrl_2;
  208. /*
  209. * Set V18_EN -- UHS modes do not work without this.
  210. * does not change signaling voltage
  211. */
  212. ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2);
  213. /* Select Bus Speed Mode for host */
  214. ctrl_2 &= ~SDHCI_CTRL_UHS_MASK;
  215. switch (uhs) {
  216. case MMC_TIMING_UHS_SDR12:
  217. ctrl_2 |= SDHCI_CTRL_UHS_SDR12;
  218. break;
  219. case MMC_TIMING_UHS_SDR25:
  220. ctrl_2 |= SDHCI_CTRL_UHS_SDR25;
  221. break;
  222. case MMC_TIMING_UHS_SDR50:
  223. ctrl_2 |= SDHCI_CTRL_UHS_SDR50 | SDHCI_CTRL_VDD_180;
  224. break;
  225. case MMC_TIMING_UHS_SDR104:
  226. ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180;
  227. break;
  228. case MMC_TIMING_MMC_DDR52:
  229. case MMC_TIMING_UHS_DDR50:
  230. ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180;
  231. break;
  232. }
  233. /*
  234. * Update SDIO3 Configuration register according to erratum
  235. * FE-2946959
  236. */
  237. if (pxa->sdio3_conf_reg) {
  238. u8 reg_val = readb(pxa->sdio3_conf_reg);
  239. if (uhs == MMC_TIMING_UHS_SDR50 ||
  240. uhs == MMC_TIMING_UHS_DDR50) {
  241. reg_val &= ~SDIO3_CONF_CLK_INV;
  242. reg_val |= SDIO3_CONF_SD_FB_CLK;
  243. } else if (uhs == MMC_TIMING_MMC_HS) {
  244. reg_val &= ~SDIO3_CONF_CLK_INV;
  245. reg_val &= ~SDIO3_CONF_SD_FB_CLK;
  246. } else {
  247. reg_val |= SDIO3_CONF_CLK_INV;
  248. reg_val &= ~SDIO3_CONF_SD_FB_CLK;
  249. }
  250. writeb(reg_val, pxa->sdio3_conf_reg);
  251. }
  252. sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
  253. dev_dbg(mmc_dev(host->mmc),
  254. "%s uhs = %d, ctrl_2 = %04X\n",
  255. __func__, uhs, ctrl_2);
  256. }
  257. static void pxav3_set_power(struct sdhci_host *host, unsigned char mode,
  258. unsigned short vdd)
  259. {
  260. struct mmc_host *mmc = host->mmc;
  261. u8 pwr = host->pwr;
  262. sdhci_set_power_noreg(host, mode, vdd);
  263. if (host->pwr == pwr)
  264. return;
  265. if (host->pwr == 0)
  266. vdd = 0;
  267. if (!IS_ERR(mmc->supply.vmmc))
  268. mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd);
  269. }
  270. static void pxav3_set_clock(struct sdhci_host *host, unsigned int clock)
  271. {
  272. struct sdhci_pltfm_host *phost = sdhci_priv(host);
  273. struct sdhci_pxa *pxa = sdhci_pltfm_priv(phost);
  274. struct pinctrl_state *pins = clock < 100 * HZ_PER_MHZ ? pxa->pins_default : pxa->pins_uhs;
  275. if (pins)
  276. pinctrl_select_state(pxa->pinctrl, pins);
  277. sdhci_set_clock(host, clock);
  278. }
  279. static const struct sdhci_ops pxav3_sdhci_ops = {
  280. .set_clock = pxav3_set_clock,
  281. .set_power = pxav3_set_power,
  282. .platform_send_init_74_clocks = pxav3_gen_init_74_clocks,
  283. .get_max_clock = sdhci_pltfm_clk_get_max_clock,
  284. .set_bus_width = sdhci_set_bus_width,
  285. .reset = pxav3_reset,
  286. .set_uhs_signaling = pxav3_set_uhs_signaling,
  287. };
  288. static const struct sdhci_pltfm_data sdhci_pxav3_pdata = {
  289. .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK
  290. | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
  291. | SDHCI_QUIRK_32BIT_ADMA_SIZE
  292. | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
  293. .ops = &pxav3_sdhci_ops,
  294. };
  295. #ifdef CONFIG_OF
  296. static const struct of_device_id sdhci_pxav3_of_match[] = {
  297. {
  298. .compatible = "mrvl,pxav3-mmc",
  299. },
  300. {
  301. .compatible = "marvell,armada-380-sdhci",
  302. },
  303. {},
  304. };
  305. MODULE_DEVICE_TABLE(of, sdhci_pxav3_of_match);
  306. static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
  307. {
  308. struct sdhci_pxa_platdata *pdata;
  309. struct device_node *np = dev->of_node;
  310. u32 clk_delay_cycles;
  311. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  312. if (!pdata)
  313. return NULL;
  314. if (!of_property_read_u32(np, "mrvl,clk-delay-cycles",
  315. &clk_delay_cycles))
  316. pdata->clk_delay_cycles = clk_delay_cycles;
  317. return pdata;
  318. }
  319. #else
  320. static inline struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
  321. {
  322. return NULL;
  323. }
  324. #endif
  325. static struct pinctrl_state *pxav3_lookup_pinstate(struct device *dev, struct pinctrl *pinctrl,
  326. const char *name)
  327. {
  328. struct pinctrl_state *pins = pinctrl_lookup_state(pinctrl, name);
  329. if (IS_ERR(pins)) {
  330. dev_dbg(dev, "could not get pinstate '%s': %ld\n", name, PTR_ERR(pins));
  331. return NULL;
  332. }
  333. return pins;
  334. }
  335. static int sdhci_pxav3_probe(struct platform_device *pdev)
  336. {
  337. struct sdhci_pltfm_host *pltfm_host;
  338. struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
  339. struct device *dev = &pdev->dev;
  340. struct device_node *np = pdev->dev.of_node;
  341. struct sdhci_host *host = NULL;
  342. struct sdhci_pxa *pxa = NULL;
  343. const struct of_device_id *match;
  344. int ret;
  345. host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata, sizeof(*pxa));
  346. if (IS_ERR(host))
  347. return PTR_ERR(host);
  348. pltfm_host = sdhci_priv(host);
  349. pxa = sdhci_pltfm_priv(pltfm_host);
  350. pxa->clk_io = devm_clk_get(dev, "io");
  351. if (IS_ERR(pxa->clk_io))
  352. pxa->clk_io = devm_clk_get(dev, NULL);
  353. if (IS_ERR(pxa->clk_io)) {
  354. dev_err(dev, "failed to get io clock\n");
  355. return PTR_ERR(pxa->clk_io);
  356. }
  357. pltfm_host->clk = pxa->clk_io;
  358. clk_prepare_enable(pxa->clk_io);
  359. pxa->clk_core = devm_clk_get(dev, "core");
  360. if (!IS_ERR(pxa->clk_core))
  361. clk_prepare_enable(pxa->clk_core);
  362. host->mmc->caps |= MMC_CAP_NEED_RSP_BUSY;
  363. /* enable 1/8V DDR capable */
  364. host->mmc->caps |= MMC_CAP_1_8V_DDR;
  365. if (of_device_is_compatible(np, "marvell,armada-380-sdhci")) {
  366. ret = armada_38x_quirks(pdev, host);
  367. if (ret < 0)
  368. goto err_mbus_win;
  369. ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info());
  370. if (ret < 0)
  371. goto err_mbus_win;
  372. }
  373. match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev);
  374. if (match) {
  375. ret = mmc_of_parse(host->mmc);
  376. if (ret)
  377. goto err_of_parse;
  378. sdhci_get_of_property(pdev);
  379. pdata = pxav3_get_mmc_pdata(dev);
  380. pdev->dev.platform_data = pdata;
  381. } else if (pdata) {
  382. /* on-chip device */
  383. if (pdata->flags & PXA_FLAG_CARD_PERMANENT)
  384. host->mmc->caps |= MMC_CAP_NONREMOVABLE;
  385. /* If slot design supports 8 bit data, indicate this to MMC. */
  386. if (pdata->flags & PXA_FLAG_SD_8_BIT_CAPABLE_SLOT)
  387. host->mmc->caps |= MMC_CAP_8_BIT_DATA;
  388. if (pdata->quirks)
  389. host->quirks |= pdata->quirks;
  390. if (pdata->quirks2)
  391. host->quirks2 |= pdata->quirks2;
  392. if (pdata->host_caps)
  393. host->mmc->caps |= pdata->host_caps;
  394. if (pdata->host_caps2)
  395. host->mmc->caps2 |= pdata->host_caps2;
  396. if (pdata->pm_caps)
  397. host->mmc->pm_caps |= pdata->pm_caps;
  398. }
  399. pxa->pinctrl = devm_pinctrl_get(dev);
  400. if (!IS_ERR(pxa->pinctrl)) {
  401. pxa->pins_default = pxav3_lookup_pinstate(dev, pxa->pinctrl, "default");
  402. if (pxa->pins_default)
  403. pxa->pins_uhs = pxav3_lookup_pinstate(dev, pxa->pinctrl, "state_uhs");
  404. } else {
  405. dev_dbg(dev, "could not get pinctrl handle: %ld\n", PTR_ERR(pxa->pinctrl));
  406. }
  407. pm_runtime_get_noresume(&pdev->dev);
  408. pm_runtime_set_active(&pdev->dev);
  409. pm_runtime_set_autosuspend_delay(&pdev->dev, PXAV3_RPM_DELAY_MS);
  410. pm_runtime_use_autosuspend(&pdev->dev);
  411. pm_runtime_enable(&pdev->dev);
  412. pm_suspend_ignore_children(&pdev->dev, 1);
  413. ret = sdhci_add_host(host);
  414. if (ret)
  415. goto err_add_host;
  416. if (host->mmc->pm_caps & MMC_PM_WAKE_SDIO_IRQ)
  417. device_init_wakeup(&pdev->dev, 1);
  418. pm_runtime_put_autosuspend(&pdev->dev);
  419. return 0;
  420. err_add_host:
  421. pm_runtime_disable(&pdev->dev);
  422. pm_runtime_put_noidle(&pdev->dev);
  423. err_of_parse:
  424. err_mbus_win:
  425. clk_disable_unprepare(pxa->clk_io);
  426. clk_disable_unprepare(pxa->clk_core);
  427. return ret;
  428. }
  429. static void sdhci_pxav3_remove(struct platform_device *pdev)
  430. {
  431. struct sdhci_host *host = platform_get_drvdata(pdev);
  432. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  433. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  434. pm_runtime_get_sync(&pdev->dev);
  435. pm_runtime_disable(&pdev->dev);
  436. pm_runtime_put_noidle(&pdev->dev);
  437. sdhci_remove_host(host, 1);
  438. clk_disable_unprepare(pxa->clk_io);
  439. clk_disable_unprepare(pxa->clk_core);
  440. }
  441. static int sdhci_pxav3_suspend(struct device *dev)
  442. {
  443. int ret;
  444. struct sdhci_host *host = dev_get_drvdata(dev);
  445. pm_runtime_get_sync(dev);
  446. if (host->tuning_mode != SDHCI_TUNING_MODE_3)
  447. mmc_retune_needed(host->mmc);
  448. ret = sdhci_suspend_host(host);
  449. pm_runtime_put_autosuspend(dev);
  450. return ret;
  451. }
  452. static int sdhci_pxav3_resume(struct device *dev)
  453. {
  454. int ret;
  455. struct sdhci_host *host = dev_get_drvdata(dev);
  456. pm_runtime_get_sync(dev);
  457. ret = sdhci_resume_host(host);
  458. pm_runtime_put_autosuspend(dev);
  459. return ret;
  460. }
  461. static int sdhci_pxav3_runtime_suspend(struct device *dev)
  462. {
  463. struct sdhci_host *host = dev_get_drvdata(dev);
  464. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  465. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  466. sdhci_runtime_suspend_host(host);
  467. if (host->tuning_mode != SDHCI_TUNING_MODE_3)
  468. mmc_retune_needed(host->mmc);
  469. clk_disable_unprepare(pxa->clk_io);
  470. if (!IS_ERR(pxa->clk_core))
  471. clk_disable_unprepare(pxa->clk_core);
  472. return 0;
  473. }
  474. static int sdhci_pxav3_runtime_resume(struct device *dev)
  475. {
  476. struct sdhci_host *host = dev_get_drvdata(dev);
  477. struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
  478. struct sdhci_pxa *pxa = sdhci_pltfm_priv(pltfm_host);
  479. clk_prepare_enable(pxa->clk_io);
  480. if (!IS_ERR(pxa->clk_core))
  481. clk_prepare_enable(pxa->clk_core);
  482. sdhci_runtime_resume_host(host, 0);
  483. return 0;
  484. }
  485. static const struct dev_pm_ops sdhci_pxav3_pmops = {
  486. SYSTEM_SLEEP_PM_OPS(sdhci_pxav3_suspend, sdhci_pxav3_resume)
  487. RUNTIME_PM_OPS(sdhci_pxav3_runtime_suspend, sdhci_pxav3_runtime_resume, NULL)
  488. };
  489. static struct platform_driver sdhci_pxav3_driver = {
  490. .driver = {
  491. .name = "sdhci-pxav3",
  492. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  493. .of_match_table = of_match_ptr(sdhci_pxav3_of_match),
  494. .pm = pm_ptr(&sdhci_pxav3_pmops),
  495. },
  496. .probe = sdhci_pxav3_probe,
  497. .remove = sdhci_pxav3_remove,
  498. };
  499. module_platform_driver(sdhci_pxav3_driver);
  500. MODULE_DESCRIPTION("SDHCI driver for pxav3");
  501. MODULE_AUTHOR("Marvell International Ltd.");
  502. MODULE_LICENSE("GPL v2");