/* This timeout should be sufficent for core to reset */
timeout = jiffies + msecs_to_jiffies(100);
/* reset the host using the top level reset */
val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
val |= KONA_SDHOST_RESET;
sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
while (!(sdhci_readl(host, KONA_SDHOST_CORECTRL) & KONA_SDHOST_RESET)) { if (time_is_before_jiffies(timeout)) {
pr_err("Error: sd host is stuck in reset!!!\n"); return -EFAULT;
}
}
/* bring the host out of reset */
val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
val &= ~KONA_SDHOST_RESET;
/* * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS) * Back-to-Back writes to same register needs delay when SD bus clock * is very low w.r.t AHB clock, mainly during boot-time and during card * insert-removal.
*/
usleep_range(1000, 5000);
sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
/* enable the interrupt from the IP core */
val = sdhci_readl(host, KONA_SDHOST_COREIMR);
val |= KONA_SDHOST_IP;
sdhci_writel(host, val, KONA_SDHOST_COREIMR);
/* Enable the AHB clock gating module to the host */
val = sdhci_readl(host, KONA_SDHOST_CORECTRL);
val |= KONA_SDHOST_EN;
/* * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS) * Back-to-Back writes to same register needs delay when SD bus clock * is very low w.r.t AHB clock, mainly during boot-time and during card * insert-removal.
*/
usleep_range(1000, 5000);
sdhci_writel(host, val, KONA_SDHOST_CORECTRL);
}
/* * Software emulation of the SD card insertion/removal. Set insert=1 for insert * and insert=0 for removal. The card detection is done by GPIO. For Broadcom * IP to function properly the bit 0 of CORESTAT register needs to be set/reset * to generate the CD IRQ handled in sdhci.c
*/ staticint sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
{ struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host); struct sdhci_bcm_kona_dev *kona_dev = sdhci_pltfm_priv(pltfm_priv);
u32 val;
/* * Back-to-Back register write needs a delay of min 10uS. * Back-to-Back writes to same register needs delay when SD bus clock * is very low w.r.t AHB clock, mainly during boot-time and during card * insert-removal. * We keep 20uS
*/
mutex_lock(&kona_dev->write_lock);
udelay(20);
val = sdhci_readl(host, KONA_SDHOST_CORESTAT);
if (insert) { int ret;
ret = mmc_gpio_get_ro(host->mmc); if (ret >= 0)
val = (val & ~KONA_SDHOST_WP) |
((ret) ? KONA_SDHOST_WP : 0);
val |= KONA_SDHOST_CD_SW;
sdhci_writel(host, val, KONA_SDHOST_CORESTAT);
} else {
val &= ~KONA_SDHOST_CD_SW;
sdhci_writel(host, val, KONA_SDHOST_CORESTAT);
}
mutex_unlock(&kona_dev->write_lock);
staticvoid sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host,
u8 power_mode)
{ /* * JEDEC and SD spec specify supplying 74 continuous clocks to * device after power up. With minimum bus (100KHz) that * translates to 740us
*/ if (power_mode != MMC_POWER_OFF)
udelay(740);
}
ret = mmc_of_parse(host->mmc); if (ret) goto err_pltfm_free;
if (!host->mmc->f_max) {
dev_err(&pdev->dev, "Missing max-freq for SDHCI cfg\n");
ret = -ENXIO; goto err_pltfm_free;
}
/* Get and enable the core clock */
pltfm_priv->clk = devm_clk_get(dev, NULL); if (IS_ERR(pltfm_priv->clk)) {
dev_err(dev, "Failed to get core clock\n");
ret = PTR_ERR(pltfm_priv->clk); goto err_pltfm_free;
}
ret = clk_set_rate(pltfm_priv->clk, host->mmc->f_max); if (ret) {
dev_err(dev, "Failed to set rate core clock\n"); goto err_pltfm_free;
}
ret = clk_prepare_enable(pltfm_priv->clk); if (ret) {
dev_err(dev, "Failed to enable core clock\n"); goto err_pltfm_free;
}
ret = sdhci_bcm_kona_sd_reset(host); if (ret) goto err_clk_disable;
sdhci_bcm_kona_sd_init(host);
ret = sdhci_add_host(host); if (ret) goto err_reset;
/* if device is eMMC, emulate card insert right here */ if (!mmc_card_is_removable(host->mmc)) {
ret = sdhci_bcm_kona_sd_card_emulate(host, 1); if (ret) {
dev_err(dev, "unable to emulate card insertion\n"); goto err_remove_host;
}
} /* * Since the card detection GPIO interrupt is configured to be * edge sensitive, check the initial GPIO value here, emulate * only if the card is present
*/ if (mmc_gpio_get_cd(host->mmc) > 0)
sdhci_bcm_kona_sd_card_emulate(host, 1);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.