1a702c8abSZhangfei Gao /* 2a702c8abSZhangfei Gao * Copyright (C) 2010 Marvell International Ltd. 3a702c8abSZhangfei Gao * Zhangfei Gao <zhangfei.gao@marvell.com> 4a702c8abSZhangfei Gao * Kevin Wang <dwang4@marvell.com> 5a702c8abSZhangfei Gao * Mingwei Wang <mwwang@marvell.com> 6a702c8abSZhangfei Gao * Philip Rakity <prakity@marvell.com> 7a702c8abSZhangfei Gao * Mark Brown <markb@marvell.com> 8a702c8abSZhangfei Gao * 9a702c8abSZhangfei Gao * This software is licensed under the terms of the GNU General Public 10a702c8abSZhangfei Gao * License version 2, as published by the Free Software Foundation, and 11a702c8abSZhangfei Gao * may be copied, distributed, and modified under those terms. 12a702c8abSZhangfei Gao * 13a702c8abSZhangfei Gao * This program is distributed in the hope that it will be useful, 14a702c8abSZhangfei Gao * but WITHOUT ANY WARRANTY; without even the implied warranty of 15a702c8abSZhangfei Gao * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a702c8abSZhangfei Gao * GNU General Public License for more details. 17a702c8abSZhangfei Gao * 18a702c8abSZhangfei Gao */ 19a702c8abSZhangfei Gao #include <linux/err.h> 20a702c8abSZhangfei Gao #include <linux/init.h> 21a702c8abSZhangfei Gao #include <linux/platform_device.h> 22a702c8abSZhangfei Gao #include <linux/clk.h> 23a702c8abSZhangfei Gao #include <linux/io.h> 24a702c8abSZhangfei Gao #include <linux/gpio.h> 25a702c8abSZhangfei Gao #include <linux/mmc/card.h> 26a702c8abSZhangfei Gao #include <linux/mmc/host.h> 278f63795cSChris Ball #include <linux/mmc/slot-gpio.h> 28bfed345eSZhangfei Gao #include <linux/platform_data/pxa_sdhci.h> 29a702c8abSZhangfei Gao #include <linux/slab.h> 30a702c8abSZhangfei Gao #include <linux/delay.h> 3188b47679SPaul Gortmaker #include <linux/module.h> 32b650352dSChris Ball #include <linux/of.h> 33b650352dSChris Ball #include <linux/of_device.h> 348f63795cSChris Ball #include <linux/of_gpio.h> 35bb691ae4SKevin Liu #include <linux/pm.h> 36bb691ae4SKevin Liu #include <linux/pm_runtime.h> 375491ce3fSMarcin Wojtas #include <linux/mbus.h> 38b650352dSChris Ball 39a702c8abSZhangfei Gao #include "sdhci.h" 40a702c8abSZhangfei Gao #include "sdhci-pltfm.h" 41a702c8abSZhangfei Gao 42bb691ae4SKevin Liu #define PXAV3_RPM_DELAY_MS 50 43bb691ae4SKevin Liu 44a702c8abSZhangfei Gao #define SD_CLOCK_BURST_SIZE_SETUP 0x10A 45a702c8abSZhangfei Gao #define SDCLK_SEL 0x100 46a702c8abSZhangfei Gao #define SDCLK_DELAY_SHIFT 9 47a702c8abSZhangfei Gao #define SDCLK_DELAY_MASK 0x1f 48a702c8abSZhangfei Gao 49a702c8abSZhangfei Gao #define SD_CFG_FIFO_PARAM 0x100 50a702c8abSZhangfei Gao #define SDCFG_GEN_PAD_CLK_ON (1<<6) 51a702c8abSZhangfei Gao #define SDCFG_GEN_PAD_CLK_CNT_MASK 0xFF 52a702c8abSZhangfei Gao #define SDCFG_GEN_PAD_CLK_CNT_SHIFT 24 53a702c8abSZhangfei Gao 54a702c8abSZhangfei Gao #define SD_SPI_MODE 0x108 55a702c8abSZhangfei Gao #define SD_CE_ATA_1 0x10C 56a702c8abSZhangfei Gao 57a702c8abSZhangfei Gao #define SD_CE_ATA_2 0x10E 58a702c8abSZhangfei Gao #define SDCE_MISC_INT (1<<2) 59a702c8abSZhangfei Gao #define SDCE_MISC_INT_EN (1<<1) 60a702c8abSZhangfei Gao 61cc9571e8SSebastian Hesselbarth struct sdhci_pxa { 628afdc9ccSSebastian Hesselbarth struct clk *clk_core; 638c96a7a3SSebastian Hesselbarth struct clk *clk_io; 64cc9571e8SSebastian Hesselbarth u8 power_mode; 65cc9571e8SSebastian Hesselbarth }; 66cc9571e8SSebastian Hesselbarth 675491ce3fSMarcin Wojtas /* 685491ce3fSMarcin Wojtas * These registers are relative to the second register region, for the 695491ce3fSMarcin Wojtas * MBus bridge. 705491ce3fSMarcin Wojtas */ 715491ce3fSMarcin Wojtas #define SDHCI_WINDOW_CTRL(i) (0x80 + ((i) << 3)) 725491ce3fSMarcin Wojtas #define SDHCI_WINDOW_BASE(i) (0x84 + ((i) << 3)) 735491ce3fSMarcin Wojtas #define SDHCI_MAX_WIN_NUM 8 745491ce3fSMarcin Wojtas 755491ce3fSMarcin Wojtas static int mv_conf_mbus_windows(struct platform_device *pdev, 765491ce3fSMarcin Wojtas const struct mbus_dram_target_info *dram) 775491ce3fSMarcin Wojtas { 785491ce3fSMarcin Wojtas int i; 795491ce3fSMarcin Wojtas void __iomem *regs; 805491ce3fSMarcin Wojtas struct resource *res; 815491ce3fSMarcin Wojtas 825491ce3fSMarcin Wojtas if (!dram) { 835491ce3fSMarcin Wojtas dev_err(&pdev->dev, "no mbus dram info\n"); 845491ce3fSMarcin Wojtas return -EINVAL; 855491ce3fSMarcin Wojtas } 865491ce3fSMarcin Wojtas 875491ce3fSMarcin Wojtas res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 885491ce3fSMarcin Wojtas if (!res) { 895491ce3fSMarcin Wojtas dev_err(&pdev->dev, "cannot get mbus registers\n"); 905491ce3fSMarcin Wojtas return -EINVAL; 915491ce3fSMarcin Wojtas } 925491ce3fSMarcin Wojtas 935491ce3fSMarcin Wojtas regs = ioremap(res->start, resource_size(res)); 945491ce3fSMarcin Wojtas if (!regs) { 955491ce3fSMarcin Wojtas dev_err(&pdev->dev, "cannot map mbus registers\n"); 965491ce3fSMarcin Wojtas return -ENOMEM; 975491ce3fSMarcin Wojtas } 985491ce3fSMarcin Wojtas 995491ce3fSMarcin Wojtas for (i = 0; i < SDHCI_MAX_WIN_NUM; i++) { 1005491ce3fSMarcin Wojtas writel(0, regs + SDHCI_WINDOW_CTRL(i)); 1015491ce3fSMarcin Wojtas writel(0, regs + SDHCI_WINDOW_BASE(i)); 1025491ce3fSMarcin Wojtas } 1035491ce3fSMarcin Wojtas 1045491ce3fSMarcin Wojtas for (i = 0; i < dram->num_cs; i++) { 1055491ce3fSMarcin Wojtas const struct mbus_dram_window *cs = dram->cs + i; 1065491ce3fSMarcin Wojtas 1075491ce3fSMarcin Wojtas /* Write size, attributes and target id to control register */ 1085491ce3fSMarcin Wojtas writel(((cs->size - 1) & 0xffff0000) | 1095491ce3fSMarcin Wojtas (cs->mbus_attr << 8) | 1105491ce3fSMarcin Wojtas (dram->mbus_dram_target_id << 4) | 1, 1115491ce3fSMarcin Wojtas regs + SDHCI_WINDOW_CTRL(i)); 1125491ce3fSMarcin Wojtas /* Write base address to base register */ 1135491ce3fSMarcin Wojtas writel(cs->base, regs + SDHCI_WINDOW_BASE(i)); 1145491ce3fSMarcin Wojtas } 1155491ce3fSMarcin Wojtas 1165491ce3fSMarcin Wojtas iounmap(regs); 1175491ce3fSMarcin Wojtas 1185491ce3fSMarcin Wojtas return 0; 1195491ce3fSMarcin Wojtas } 1205491ce3fSMarcin Wojtas 121*a39128bcSMarcin Wojtas static int armada_38x_quirks(struct platform_device *pdev, 122*a39128bcSMarcin Wojtas struct sdhci_host *host) 123d4b803c5SGregory CLEMENT { 124*a39128bcSMarcin Wojtas struct device_node *np = pdev->dev.of_node; 125*a39128bcSMarcin Wojtas 126d4b803c5SGregory CLEMENT host->quirks |= SDHCI_QUIRK_MISSING_CAPS; 127d4b803c5SGregory CLEMENT /* 128d4b803c5SGregory CLEMENT * According to erratum 'FE-2946959' both SDR50 and DDR50 129d4b803c5SGregory CLEMENT * modes require specific clock adjustments in SDIO3 130d4b803c5SGregory CLEMENT * Configuration register, if the adjustment is not done, 131d4b803c5SGregory CLEMENT * remove them from the capabilities. 132d4b803c5SGregory CLEMENT */ 133d4b803c5SGregory CLEMENT host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); 134d4b803c5SGregory CLEMENT host->caps1 &= ~(SDHCI_SUPPORT_SDR50 | SDHCI_SUPPORT_DDR50); 135*a39128bcSMarcin Wojtas 136*a39128bcSMarcin Wojtas /* 137*a39128bcSMarcin Wojtas * According to erratum 'ERR-7878951' Armada 38x SDHCI 138*a39128bcSMarcin Wojtas * controller has different capabilities than the ones shown 139*a39128bcSMarcin Wojtas * in its registers 140*a39128bcSMarcin Wojtas */ 141*a39128bcSMarcin Wojtas host->caps = sdhci_readl(host, SDHCI_CAPABILITIES); 142*a39128bcSMarcin Wojtas if (of_property_read_bool(np, "no-1-8-v")) { 143*a39128bcSMarcin Wojtas host->caps &= ~SDHCI_CAN_VDD_180; 144*a39128bcSMarcin Wojtas host->mmc->caps &= ~MMC_CAP_1_8V_DDR; 145*a39128bcSMarcin Wojtas } else { 146*a39128bcSMarcin Wojtas host->caps &= ~SDHCI_CAN_VDD_330; 147*a39128bcSMarcin Wojtas } 148*a39128bcSMarcin Wojtas host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_USE_SDR50_TUNING); 149*a39128bcSMarcin Wojtas 150d4b803c5SGregory CLEMENT return 0; 151d4b803c5SGregory CLEMENT } 152d4b803c5SGregory CLEMENT 15303231f9bSRussell King static void pxav3_reset(struct sdhci_host *host, u8 mask) 154a702c8abSZhangfei Gao { 155a702c8abSZhangfei Gao struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc)); 156a702c8abSZhangfei Gao struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data; 157a702c8abSZhangfei Gao 15803231f9bSRussell King sdhci_reset(host, mask); 15903231f9bSRussell King 160a702c8abSZhangfei Gao if (mask == SDHCI_RESET_ALL) { 161a702c8abSZhangfei Gao /* 162a702c8abSZhangfei Gao * tune timing of read data/command when crc error happen 163a702c8abSZhangfei Gao * no performance impact 164a702c8abSZhangfei Gao */ 165a702c8abSZhangfei Gao if (pdata && 0 != pdata->clk_delay_cycles) { 166a702c8abSZhangfei Gao u16 tmp; 167a702c8abSZhangfei Gao 168a702c8abSZhangfei Gao tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP); 169a702c8abSZhangfei Gao tmp |= (pdata->clk_delay_cycles & SDCLK_DELAY_MASK) 170a702c8abSZhangfei Gao << SDCLK_DELAY_SHIFT; 171a702c8abSZhangfei Gao tmp |= SDCLK_SEL; 172a702c8abSZhangfei Gao writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP); 173a702c8abSZhangfei Gao } 174a702c8abSZhangfei Gao } 175a702c8abSZhangfei Gao } 176a702c8abSZhangfei Gao 177a702c8abSZhangfei Gao #define MAX_WAIT_COUNT 5 178a702c8abSZhangfei Gao static void pxav3_gen_init_74_clocks(struct sdhci_host *host, u8 power_mode) 179a702c8abSZhangfei Gao { 180a702c8abSZhangfei Gao struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 181a702c8abSZhangfei Gao struct sdhci_pxa *pxa = pltfm_host->priv; 182a702c8abSZhangfei Gao u16 tmp; 183a702c8abSZhangfei Gao int count; 184a702c8abSZhangfei Gao 185a702c8abSZhangfei Gao if (pxa->power_mode == MMC_POWER_UP 186a702c8abSZhangfei Gao && power_mode == MMC_POWER_ON) { 187a702c8abSZhangfei Gao 188a702c8abSZhangfei Gao dev_dbg(mmc_dev(host->mmc), 189a702c8abSZhangfei Gao "%s: slot->power_mode = %d," 190a702c8abSZhangfei Gao "ios->power_mode = %d\n", 191a702c8abSZhangfei Gao __func__, 192a702c8abSZhangfei Gao pxa->power_mode, 193a702c8abSZhangfei Gao power_mode); 194a702c8abSZhangfei Gao 195a702c8abSZhangfei Gao /* set we want notice of when 74 clocks are sent */ 196a702c8abSZhangfei Gao tmp = readw(host->ioaddr + SD_CE_ATA_2); 197a702c8abSZhangfei Gao tmp |= SDCE_MISC_INT_EN; 198a702c8abSZhangfei Gao writew(tmp, host->ioaddr + SD_CE_ATA_2); 199a702c8abSZhangfei Gao 200a702c8abSZhangfei Gao /* start sending the 74 clocks */ 201a702c8abSZhangfei Gao tmp = readw(host->ioaddr + SD_CFG_FIFO_PARAM); 202a702c8abSZhangfei Gao tmp |= SDCFG_GEN_PAD_CLK_ON; 203a702c8abSZhangfei Gao writew(tmp, host->ioaddr + SD_CFG_FIFO_PARAM); 204a702c8abSZhangfei Gao 205a702c8abSZhangfei Gao /* slowest speed is about 100KHz or 10usec per clock */ 206a702c8abSZhangfei Gao udelay(740); 207a702c8abSZhangfei Gao count = 0; 208a702c8abSZhangfei Gao 209a702c8abSZhangfei Gao while (count++ < MAX_WAIT_COUNT) { 210a702c8abSZhangfei Gao if ((readw(host->ioaddr + SD_CE_ATA_2) 211a702c8abSZhangfei Gao & SDCE_MISC_INT) == 0) 212a702c8abSZhangfei Gao break; 213a702c8abSZhangfei Gao udelay(10); 214a702c8abSZhangfei Gao } 215a702c8abSZhangfei Gao 216a702c8abSZhangfei Gao if (count == MAX_WAIT_COUNT) 217a702c8abSZhangfei Gao dev_warn(mmc_dev(host->mmc), "74 clock interrupt not cleared\n"); 218a702c8abSZhangfei Gao 219a702c8abSZhangfei Gao /* clear the interrupt bit if posted */ 220a702c8abSZhangfei Gao tmp = readw(host->ioaddr + SD_CE_ATA_2); 221a702c8abSZhangfei Gao tmp |= SDCE_MISC_INT; 222a702c8abSZhangfei Gao writew(tmp, host->ioaddr + SD_CE_ATA_2); 223a702c8abSZhangfei Gao } 224a702c8abSZhangfei Gao pxa->power_mode = power_mode; 225a702c8abSZhangfei Gao } 226a702c8abSZhangfei Gao 22713e64501SRussell King static void pxav3_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs) 228a702c8abSZhangfei Gao { 229a702c8abSZhangfei Gao u16 ctrl_2; 230a702c8abSZhangfei Gao 231a702c8abSZhangfei Gao /* 232a702c8abSZhangfei Gao * Set V18_EN -- UHS modes do not work without this. 233a702c8abSZhangfei Gao * does not change signaling voltage 234a702c8abSZhangfei Gao */ 235a702c8abSZhangfei Gao ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 236a702c8abSZhangfei Gao 237a702c8abSZhangfei Gao /* Select Bus Speed Mode for host */ 238a702c8abSZhangfei Gao ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; 239a702c8abSZhangfei Gao switch (uhs) { 240a702c8abSZhangfei Gao case MMC_TIMING_UHS_SDR12: 241a702c8abSZhangfei Gao ctrl_2 |= SDHCI_CTRL_UHS_SDR12; 242a702c8abSZhangfei Gao break; 243a702c8abSZhangfei Gao case MMC_TIMING_UHS_SDR25: 244a702c8abSZhangfei Gao ctrl_2 |= SDHCI_CTRL_UHS_SDR25; 245a702c8abSZhangfei Gao break; 246a702c8abSZhangfei Gao case MMC_TIMING_UHS_SDR50: 247a702c8abSZhangfei Gao ctrl_2 |= SDHCI_CTRL_UHS_SDR50 | SDHCI_CTRL_VDD_180; 248a702c8abSZhangfei Gao break; 249a702c8abSZhangfei Gao case MMC_TIMING_UHS_SDR104: 250a702c8abSZhangfei Gao ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180; 251a702c8abSZhangfei Gao break; 252668e84b2SSebastian Hesselbarth case MMC_TIMING_MMC_DDR52: 253a702c8abSZhangfei Gao case MMC_TIMING_UHS_DDR50: 254a702c8abSZhangfei Gao ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180; 255a702c8abSZhangfei Gao break; 256a702c8abSZhangfei Gao } 257a702c8abSZhangfei Gao 258a702c8abSZhangfei Gao sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); 259a702c8abSZhangfei Gao dev_dbg(mmc_dev(host->mmc), 260a702c8abSZhangfei Gao "%s uhs = %d, ctrl_2 = %04X\n", 261a702c8abSZhangfei Gao __func__, uhs, ctrl_2); 262a702c8abSZhangfei Gao } 263a702c8abSZhangfei Gao 264c915568dSLars-Peter Clausen static const struct sdhci_ops pxav3_sdhci_ops = { 2651771059cSRussell King .set_clock = sdhci_set_clock, 266a702c8abSZhangfei Gao .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, 267d005d943SLars-Peter Clausen .get_max_clock = sdhci_pltfm_clk_get_max_clock, 2682317f56cSRussell King .set_bus_width = sdhci_set_bus_width, 26903231f9bSRussell King .reset = pxav3_reset, 270b3153765SPeter Griffin .set_uhs_signaling = pxav3_set_uhs_signaling, 271a702c8abSZhangfei Gao }; 272a702c8abSZhangfei Gao 27373b7afb9SKevin Liu static struct sdhci_pltfm_data sdhci_pxav3_pdata = { 274e065162aSKevin Liu .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK 27573b7afb9SKevin Liu | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC 27673b7afb9SKevin Liu | SDHCI_QUIRK_32BIT_ADMA_SIZE 27773b7afb9SKevin Liu | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, 27873b7afb9SKevin Liu .ops = &pxav3_sdhci_ops, 27973b7afb9SKevin Liu }; 28073b7afb9SKevin Liu 281b650352dSChris Ball #ifdef CONFIG_OF 282b650352dSChris Ball static const struct of_device_id sdhci_pxav3_of_match[] = { 283b650352dSChris Ball { 284b650352dSChris Ball .compatible = "mrvl,pxav3-mmc", 285b650352dSChris Ball }, 2865491ce3fSMarcin Wojtas { 2875491ce3fSMarcin Wojtas .compatible = "marvell,armada-380-sdhci", 2885491ce3fSMarcin Wojtas }, 289b650352dSChris Ball {}, 290b650352dSChris Ball }; 291b650352dSChris Ball MODULE_DEVICE_TABLE(of, sdhci_pxav3_of_match); 292b650352dSChris Ball 293b650352dSChris Ball static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev) 294b650352dSChris Ball { 295b650352dSChris Ball struct sdhci_pxa_platdata *pdata; 296b650352dSChris Ball struct device_node *np = dev->of_node; 297b650352dSChris Ball u32 clk_delay_cycles; 298b650352dSChris Ball 299b650352dSChris Ball pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 300b650352dSChris Ball if (!pdata) 301b650352dSChris Ball return NULL; 302b650352dSChris Ball 30314460dbaSJisheng Zhang if (!of_property_read_u32(np, "mrvl,clk-delay-cycles", 30414460dbaSJisheng Zhang &clk_delay_cycles)) 305b650352dSChris Ball pdata->clk_delay_cycles = clk_delay_cycles; 306b650352dSChris Ball 307b650352dSChris Ball return pdata; 308b650352dSChris Ball } 309b650352dSChris Ball #else 310b650352dSChris Ball static inline struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev) 311b650352dSChris Ball { 312b650352dSChris Ball return NULL; 313b650352dSChris Ball } 314b650352dSChris Ball #endif 315b650352dSChris Ball 316c3be1efdSBill Pemberton static int sdhci_pxav3_probe(struct platform_device *pdev) 317a702c8abSZhangfei Gao { 318a702c8abSZhangfei Gao struct sdhci_pltfm_host *pltfm_host; 319a702c8abSZhangfei Gao struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data; 320a702c8abSZhangfei Gao struct device *dev = &pdev->dev; 3215491ce3fSMarcin Wojtas struct device_node *np = pdev->dev.of_node; 322a702c8abSZhangfei Gao struct sdhci_host *host = NULL; 323a702c8abSZhangfei Gao struct sdhci_pxa *pxa = NULL; 324b650352dSChris Ball const struct of_device_id *match; 325a702c8abSZhangfei Gao int ret; 326a702c8abSZhangfei Gao 3273df5b281SLaurent Pinchart pxa = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_pxa), GFP_KERNEL); 328a702c8abSZhangfei Gao if (!pxa) 329a702c8abSZhangfei Gao return -ENOMEM; 330a702c8abSZhangfei Gao 3310e748234SChristian Daudt host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata, 0); 3323df5b281SLaurent Pinchart if (IS_ERR(host)) 333a702c8abSZhangfei Gao return PTR_ERR(host); 3345491ce3fSMarcin Wojtas 335a702c8abSZhangfei Gao pltfm_host = sdhci_priv(host); 336a702c8abSZhangfei Gao pltfm_host->priv = pxa; 337a702c8abSZhangfei Gao 33801ae1070SSebastian Hesselbarth pxa->clk_io = devm_clk_get(dev, "io"); 33901ae1070SSebastian Hesselbarth if (IS_ERR(pxa->clk_io)) 3408c96a7a3SSebastian Hesselbarth pxa->clk_io = devm_clk_get(dev, NULL); 3418c96a7a3SSebastian Hesselbarth if (IS_ERR(pxa->clk_io)) { 342a702c8abSZhangfei Gao dev_err(dev, "failed to get io clock\n"); 3438c96a7a3SSebastian Hesselbarth ret = PTR_ERR(pxa->clk_io); 344a702c8abSZhangfei Gao goto err_clk_get; 345a702c8abSZhangfei Gao } 3468c96a7a3SSebastian Hesselbarth pltfm_host->clk = pxa->clk_io; 3478c96a7a3SSebastian Hesselbarth clk_prepare_enable(pxa->clk_io); 348a702c8abSZhangfei Gao 3498afdc9ccSSebastian Hesselbarth pxa->clk_core = devm_clk_get(dev, "core"); 3508afdc9ccSSebastian Hesselbarth if (!IS_ERR(pxa->clk_core)) 3518afdc9ccSSebastian Hesselbarth clk_prepare_enable(pxa->clk_core); 3528afdc9ccSSebastian Hesselbarth 353*a39128bcSMarcin Wojtas /* enable 1/8V DDR capable */ 354*a39128bcSMarcin Wojtas host->mmc->caps |= MMC_CAP_1_8V_DDR; 355*a39128bcSMarcin Wojtas 356aa8165f9SThomas Petazzoni if (of_device_is_compatible(np, "marvell,armada-380-sdhci")) { 357*a39128bcSMarcin Wojtas ret = armada_38x_quirks(pdev, host); 358d4b803c5SGregory CLEMENT if (ret < 0) 359d4b803c5SGregory CLEMENT goto err_clk_get; 360aa8165f9SThomas Petazzoni ret = mv_conf_mbus_windows(pdev, mv_mbus_dram_info()); 361aa8165f9SThomas Petazzoni if (ret < 0) 362aa8165f9SThomas Petazzoni goto err_mbus_win; 363aa8165f9SThomas Petazzoni } 364aa8165f9SThomas Petazzoni 365b650352dSChris Ball match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev); 366943647f6SKevin Liu if (match) { 367d2cf6071SSimon Baatz ret = mmc_of_parse(host->mmc); 368d2cf6071SSimon Baatz if (ret) 369d2cf6071SSimon Baatz goto err_of_parse; 370943647f6SKevin Liu sdhci_get_of_property(pdev); 371b650352dSChris Ball pdata = pxav3_get_mmc_pdata(dev); 372943647f6SKevin Liu } else if (pdata) { 373a702c8abSZhangfei Gao /* on-chip device */ 374c844a46fSKevin Liu if (pdata->flags & PXA_FLAG_CARD_PERMANENT) 375a702c8abSZhangfei Gao host->mmc->caps |= MMC_CAP_NONREMOVABLE; 376a702c8abSZhangfei Gao 377a702c8abSZhangfei Gao /* If slot design supports 8 bit data, indicate this to MMC. */ 378a702c8abSZhangfei Gao if (pdata->flags & PXA_FLAG_SD_8_BIT_CAPABLE_SLOT) 379a702c8abSZhangfei Gao host->mmc->caps |= MMC_CAP_8_BIT_DATA; 380a702c8abSZhangfei Gao 381a702c8abSZhangfei Gao if (pdata->quirks) 382a702c8abSZhangfei Gao host->quirks |= pdata->quirks; 3837c52d7bbSKevin Liu if (pdata->quirks2) 3847c52d7bbSKevin Liu host->quirks2 |= pdata->quirks2; 385a702c8abSZhangfei Gao if (pdata->host_caps) 386a702c8abSZhangfei Gao host->mmc->caps |= pdata->host_caps; 3878f63795cSChris Ball if (pdata->host_caps2) 3888f63795cSChris Ball host->mmc->caps2 |= pdata->host_caps2; 389a702c8abSZhangfei Gao if (pdata->pm_caps) 390a702c8abSZhangfei Gao host->mmc->pm_caps |= pdata->pm_caps; 3918f63795cSChris Ball 3928f63795cSChris Ball if (gpio_is_valid(pdata->ext_cd_gpio)) { 393214fc309SLaurent Pinchart ret = mmc_gpio_request_cd(host->mmc, pdata->ext_cd_gpio, 394214fc309SLaurent Pinchart 0); 3958f63795cSChris Ball if (ret) { 3968f63795cSChris Ball dev_err(mmc_dev(host->mmc), 3978f63795cSChris Ball "failed to allocate card detect gpio\n"); 3988f63795cSChris Ball goto err_cd_req; 3998f63795cSChris Ball } 4008f63795cSChris Ball } 401a702c8abSZhangfei Gao } 402a702c8abSZhangfei Gao 40362cf983aSJisheng Zhang pm_runtime_get_noresume(&pdev->dev); 40462cf983aSJisheng Zhang pm_runtime_set_active(&pdev->dev); 405bb691ae4SKevin Liu pm_runtime_set_autosuspend_delay(&pdev->dev, PXAV3_RPM_DELAY_MS); 406bb691ae4SKevin Liu pm_runtime_use_autosuspend(&pdev->dev); 40762cf983aSJisheng Zhang pm_runtime_enable(&pdev->dev); 408bb691ae4SKevin Liu pm_suspend_ignore_children(&pdev->dev, 1); 409bb691ae4SKevin Liu 410a702c8abSZhangfei Gao ret = sdhci_add_host(host); 411a702c8abSZhangfei Gao if (ret) { 412a702c8abSZhangfei Gao dev_err(&pdev->dev, "failed to add host\n"); 413a702c8abSZhangfei Gao goto err_add_host; 414a702c8abSZhangfei Gao } 415a702c8abSZhangfei Gao 416a702c8abSZhangfei Gao platform_set_drvdata(pdev, host); 417a702c8abSZhangfei Gao 418943647f6SKevin Liu if (host->mmc->pm_caps & MMC_PM_KEEP_POWER) { 419740b7a44SKevin Liu device_init_wakeup(&pdev->dev, 1); 420740b7a44SKevin Liu host->mmc->pm_flags |= MMC_PM_WAKE_SDIO_IRQ; 421740b7a44SKevin Liu } else { 422740b7a44SKevin Liu device_init_wakeup(&pdev->dev, 0); 423740b7a44SKevin Liu } 424740b7a44SKevin Liu 425bb691ae4SKevin Liu pm_runtime_put_autosuspend(&pdev->dev); 426bb691ae4SKevin Liu 427a702c8abSZhangfei Gao return 0; 428a702c8abSZhangfei Gao 429a702c8abSZhangfei Gao err_add_host: 4300dcaa249SDaniel Drake pm_runtime_disable(&pdev->dev); 43162cf983aSJisheng Zhang pm_runtime_put_noidle(&pdev->dev); 43287d2163dSXiang Wang err_of_parse: 43387d2163dSXiang Wang err_cd_req: 434aa8165f9SThomas Petazzoni err_mbus_win: 4358c96a7a3SSebastian Hesselbarth clk_disable_unprepare(pxa->clk_io); 4368afdc9ccSSebastian Hesselbarth clk_disable_unprepare(pxa->clk_core); 437a702c8abSZhangfei Gao err_clk_get: 438a702c8abSZhangfei Gao sdhci_pltfm_free(pdev); 439a702c8abSZhangfei Gao return ret; 440a702c8abSZhangfei Gao } 441a702c8abSZhangfei Gao 4426e0ee714SBill Pemberton static int sdhci_pxav3_remove(struct platform_device *pdev) 443a702c8abSZhangfei Gao { 444a702c8abSZhangfei Gao struct sdhci_host *host = platform_get_drvdata(pdev); 445a702c8abSZhangfei Gao struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 4468c96a7a3SSebastian Hesselbarth struct sdhci_pxa *pxa = pltfm_host->priv; 447a702c8abSZhangfei Gao 448bb691ae4SKevin Liu pm_runtime_get_sync(&pdev->dev); 449bb691ae4SKevin Liu pm_runtime_disable(&pdev->dev); 45020f1f2d7SJisheng Zhang pm_runtime_put_noidle(&pdev->dev); 45120f1f2d7SJisheng Zhang 45220f1f2d7SJisheng Zhang sdhci_remove_host(host, 1); 453a702c8abSZhangfei Gao 4548c96a7a3SSebastian Hesselbarth clk_disable_unprepare(pxa->clk_io); 4558afdc9ccSSebastian Hesselbarth clk_disable_unprepare(pxa->clk_core); 4568f63795cSChris Ball 457a702c8abSZhangfei Gao sdhci_pltfm_free(pdev); 458a702c8abSZhangfei Gao 459a702c8abSZhangfei Gao return 0; 460a702c8abSZhangfei Gao } 461a702c8abSZhangfei Gao 462bb691ae4SKevin Liu #ifdef CONFIG_PM_SLEEP 463bb691ae4SKevin Liu static int sdhci_pxav3_suspend(struct device *dev) 464bb691ae4SKevin Liu { 465bb691ae4SKevin Liu int ret; 466bb691ae4SKevin Liu struct sdhci_host *host = dev_get_drvdata(dev); 467bb691ae4SKevin Liu 468bb691ae4SKevin Liu pm_runtime_get_sync(dev); 469bb691ae4SKevin Liu ret = sdhci_suspend_host(host); 470bb691ae4SKevin Liu pm_runtime_mark_last_busy(dev); 471bb691ae4SKevin Liu pm_runtime_put_autosuspend(dev); 472bb691ae4SKevin Liu 473bb691ae4SKevin Liu return ret; 474bb691ae4SKevin Liu } 475bb691ae4SKevin Liu 476bb691ae4SKevin Liu static int sdhci_pxav3_resume(struct device *dev) 477bb691ae4SKevin Liu { 478bb691ae4SKevin Liu int ret; 479bb691ae4SKevin Liu struct sdhci_host *host = dev_get_drvdata(dev); 480bb691ae4SKevin Liu 481bb691ae4SKevin Liu pm_runtime_get_sync(dev); 482bb691ae4SKevin Liu ret = sdhci_resume_host(host); 483bb691ae4SKevin Liu pm_runtime_mark_last_busy(dev); 484bb691ae4SKevin Liu pm_runtime_put_autosuspend(dev); 485bb691ae4SKevin Liu 486bb691ae4SKevin Liu return ret; 487bb691ae4SKevin Liu } 488bb691ae4SKevin Liu #endif 489bb691ae4SKevin Liu 490162d6f98SRafael J. Wysocki #ifdef CONFIG_PM 491bb691ae4SKevin Liu static int sdhci_pxav3_runtime_suspend(struct device *dev) 492bb691ae4SKevin Liu { 493bb691ae4SKevin Liu struct sdhci_host *host = dev_get_drvdata(dev); 494bb691ae4SKevin Liu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 4958c96a7a3SSebastian Hesselbarth struct sdhci_pxa *pxa = pltfm_host->priv; 4963bb10f60SJisheng Zhang int ret; 497bb691ae4SKevin Liu 4983bb10f60SJisheng Zhang ret = sdhci_runtime_suspend_host(host); 4993bb10f60SJisheng Zhang if (ret) 5003bb10f60SJisheng Zhang return ret; 501bb691ae4SKevin Liu 5028c96a7a3SSebastian Hesselbarth clk_disable_unprepare(pxa->clk_io); 5038afdc9ccSSebastian Hesselbarth if (!IS_ERR(pxa->clk_core)) 5048afdc9ccSSebastian Hesselbarth clk_disable_unprepare(pxa->clk_core); 505bb691ae4SKevin Liu 506bb691ae4SKevin Liu return 0; 507bb691ae4SKevin Liu } 508bb691ae4SKevin Liu 509bb691ae4SKevin Liu static int sdhci_pxav3_runtime_resume(struct device *dev) 510bb691ae4SKevin Liu { 511bb691ae4SKevin Liu struct sdhci_host *host = dev_get_drvdata(dev); 512bb691ae4SKevin Liu struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 5138c96a7a3SSebastian Hesselbarth struct sdhci_pxa *pxa = pltfm_host->priv; 514bb691ae4SKevin Liu 5158c96a7a3SSebastian Hesselbarth clk_prepare_enable(pxa->clk_io); 5168afdc9ccSSebastian Hesselbarth if (!IS_ERR(pxa->clk_core)) 5178afdc9ccSSebastian Hesselbarth clk_prepare_enable(pxa->clk_core); 518bb691ae4SKevin Liu 5193bb10f60SJisheng Zhang return sdhci_runtime_resume_host(host); 520bb691ae4SKevin Liu } 521bb691ae4SKevin Liu #endif 522bb691ae4SKevin Liu 523bb691ae4SKevin Liu #ifdef CONFIG_PM 524bb691ae4SKevin Liu static const struct dev_pm_ops sdhci_pxav3_pmops = { 525bb691ae4SKevin Liu SET_SYSTEM_SLEEP_PM_OPS(sdhci_pxav3_suspend, sdhci_pxav3_resume) 526bb691ae4SKevin Liu SET_RUNTIME_PM_OPS(sdhci_pxav3_runtime_suspend, 527bb691ae4SKevin Liu sdhci_pxav3_runtime_resume, NULL) 528bb691ae4SKevin Liu }; 529bb691ae4SKevin Liu 530bb691ae4SKevin Liu #define SDHCI_PXAV3_PMOPS (&sdhci_pxav3_pmops) 531bb691ae4SKevin Liu 532bb691ae4SKevin Liu #else 533bb691ae4SKevin Liu #define SDHCI_PXAV3_PMOPS NULL 534bb691ae4SKevin Liu #endif 535bb691ae4SKevin Liu 536a702c8abSZhangfei Gao static struct platform_driver sdhci_pxav3_driver = { 537a702c8abSZhangfei Gao .driver = { 538a702c8abSZhangfei Gao .name = "sdhci-pxav3", 539b650352dSChris Ball #ifdef CONFIG_OF 540b650352dSChris Ball .of_match_table = sdhci_pxav3_of_match, 541b650352dSChris Ball #endif 542bb691ae4SKevin Liu .pm = SDHCI_PXAV3_PMOPS, 543a702c8abSZhangfei Gao }, 544a702c8abSZhangfei Gao .probe = sdhci_pxav3_probe, 5450433c143SBill Pemberton .remove = sdhci_pxav3_remove, 546a702c8abSZhangfei Gao }; 547a702c8abSZhangfei Gao 548d1f81a64SAxel Lin module_platform_driver(sdhci_pxav3_driver); 549a702c8abSZhangfei Gao 550a702c8abSZhangfei Gao MODULE_DESCRIPTION("SDHCI driver for pxav3"); 551a702c8abSZhangfei Gao MODULE_AUTHOR("Marvell International Ltd."); 552a702c8abSZhangfei Gao MODULE_LICENSE("GPL v2"); 553a702c8abSZhangfei Gao 554