From patchwork Fri Jan 12 09:10:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 124260 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1816261qgn; Fri, 12 Jan 2018 01:11:10 -0800 (PST) X-Google-Smtp-Source: ACJfBov93jRDMUMr494VyYXBOA2DJRIwpvO8Pi+JpPm4UL4/7edD5XZFyq3wVXAvJbxKptkhbL59 X-Received: by 10.80.221.1 with SMTP id t1mr35767333edk.198.1515748270632; Fri, 12 Jan 2018 01:11:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515748270; cv=none; d=google.com; s=arc-20160816; b=c5IRaYTK5eJ/IdIUkO7GUlPHCS+tcfsho1Nz2GP+iAnCbGcAKIXQlGaVUOgKGU2CIx gS1hKDbpUoh5/WUsEd37N05hnnxMq/JJXwE/a50ilKesaFbDb10MioYvKef6sHFW2p7v PZtfiyKTlOrwd9dopB0UJcM2RwSj5FJIg1I9ENS+VNvakRwwuaUCDwedMwM5wVScgY2p x3wFtnkTXQW8MtWsNgrCeeu51o3YPF2rCRXw/Sc/doZNYj0mdsSfGPSKjTtqpUajeT1a gJ8edNk/Tdvbu1vpW/wbrElf5JJ7sJwdnar0vAK3u/SWPOrX0dJu9m53Iz6kEsRUvux9 +76g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=YQb9/0BPp2vULi5XgxgSkrP7rCSazKEP7tLrZBlaj0o=; b=HBSqFQ9hsKLOh1EFInkOHJf06Q0tm7THB7r1ls0i5E87xM1fSDpMtP6moe3ESZ1P/8 OeNKIaz5fo6AjVCSTzJleNz7oxTI5j7LxPByIYdrrHB2i8xh1utW5jdx6C8o+FR6zl1Q GSSwSJq3y11eSTGxPO3Wp/QyRNGX53WIGAiiHOTNrdCfrYebiwMww9VEWJWvOFxRYN33 fQMN4maoPIIcIgE6Z2pe/X8wBjojFJ+33Pc0viesd66sAXhYuJqUVbXzp/fbdCstNs/0 1ZgYMZGXs76IbpyhwJKAe7NPXqGqO6G9muGciH9DlwXCosLe8JT794CGrxkhOkwp/1jS 7Pdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Z3ezFnd+; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id f27si2631559edj.412.2018.01.12.01.11.10; Fri, 12 Jan 2018 01:11:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=Z3ezFnd+; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 40185C21E6C; Fri, 12 Jan 2018 09:11:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0828EC21DD9; Fri, 12 Jan 2018 09:11:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6D2E7C21DD9; Fri, 12 Jan 2018 09:11:03 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 63F2FC21C62 for ; Fri, 12 Jan 2018 09:11:02 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w0C9AjQR018957; Fri, 12 Jan 2018 18:10:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w0C9AjQR018957 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1515748245; bh=ucdnVtGsCR4il7olZO5gQOTjv7j+oydh50oiAYHVSNY=; h=From:To:Cc:Subject:Date:From; b=Z3ezFnd+GYesBmoEC32U4wzfLE7HhiuVLNXU63BpRnjnE0hoHWNQtQ4wZ7Fta9+if e3XBBr/HTisJVkb6jUQjcZsIfrlzDFaDxoKBSYw7pKVLceyxks1O/SfhXt6cRP7gn5 c+bTGd/M3UtFOkppqIy9CADxoqL52Rdhw31LPE7NTaYlFbzmybVMYQHoM03fPBXafz zWnW5ELqXce+8+Mo6Deh6J4h2jfWvkbTevVwVRNLwRRX3qdkaUlUw8lHCdKB3Em0gN EjTOPKXb3VV3WICgCPm6lYOQaTshAJrpwi+tVUAqF1ygCgnESvz5HeL21FV/6pvKvn G5eDInXx/H+Yg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Fri, 12 Jan 2018 18:10:38 +0900 Message-Id: <1515748238-30417-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Cc: Tom Rini Subject: [U-Boot] [PATCH v2] mmc: sdhci-cadence: add HS200 support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add HS200 timing setting and the MMC tuning callback. Signed-off-by: Masahiro Yamada --- Changes in v2: - Surround .execute_tuning hook with #ifdef MMC_SUPPORTS_TUNING drivers/mmc/sdhci-cadence.c | 90 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/sdhci-cadence.c b/drivers/mmc/sdhci-cadence.c index 921095b..8960f6f 100644 --- a/drivers/mmc/sdhci-cadence.c +++ b/drivers/mmc/sdhci-cadence.c @@ -52,6 +52,13 @@ #define SDHCI_CDNS_PHY_DLY_HSMMC 0x0c #define SDHCI_CDNS_PHY_DLY_STROBE 0x0d +/* + * The tuned val register is 6 bit-wide, but not the whole of the range is + * available. The range 0-42 seems to be available (then 43 wraps around to 0) + * but I am not quite sure if it is official. Use only 0 to 39 for safety. + */ +#define SDHCI_CDNS_MAX_TUNING_LOOP 40 + struct sdhci_cdns_plat { struct mmc_config cfg; struct mmc mmc; @@ -135,20 +142,18 @@ static void sdhci_cdns_set_control_reg(struct sdhci_host *host) * The mode should be decided by MMC_TIMING_* like Linux, but * U-Boot does not support timing. Use the clock frequency instead. */ - if (clock <= 26000000) + if (clock <= 26000000) { mode = SDHCI_CDNS_HRS06_MODE_SD; /* use this for Legacy */ - else if (clock <= 52000000) { + } else if (clock <= 52000000) { if (mmc->ddr_mode) mode = SDHCI_CDNS_HRS06_MODE_MMC_DDR; else mode = SDHCI_CDNS_HRS06_MODE_MMC_SDR; } else { - /* - * REVISIT: - * The IP supports HS200/HS400, revisit once U-Boot support it - */ - printf("unsupported frequency %d\n", clock); - return; + if (mmc->ddr_mode) + mode = SDHCI_CDNS_HRS06_MODE_MMC_HS400; + else + mode = SDHCI_CDNS_HRS06_MODE_MMC_HS200; } tmp = readl(plat->hrs_addr + SDHCI_CDNS_HRS06); @@ -161,6 +166,69 @@ static const struct sdhci_ops sdhci_cdns_ops = { .set_control_reg = sdhci_cdns_set_control_reg, }; +static int sdhci_cdns_set_tune_val(struct sdhci_cdns_plat *plat, + unsigned int val) +{ + void __iomem *reg = plat->hrs_addr + SDHCI_CDNS_HRS06; + u32 tmp; + + if (WARN_ON(!FIELD_FIT(SDHCI_CDNS_HRS06_TUNE, val))) + return -EINVAL; + + tmp = readl(reg); + tmp &= ~SDHCI_CDNS_HRS06_TUNE; + tmp |= FIELD_PREP(SDHCI_CDNS_HRS06_TUNE, val); + tmp |= SDHCI_CDNS_HRS06_TUNE_UP; + writel(tmp, reg); + + return readl_poll_timeout(reg, tmp, !(tmp & SDHCI_CDNS_HRS06_TUNE_UP), + 1); +} + +static int __maybe_unused sdhci_cdns_execute_tuning(struct udevice *dev, + unsigned int opcode) +{ + struct sdhci_cdns_plat *plat = dev_get_platdata(dev); + struct mmc *mmc = &plat->mmc; + int cur_streak = 0; + int max_streak = 0; + int end_of_streak = 0; + int i; + + /* + * This handler only implements the eMMC tuning that is specific to + * this controller. The tuning for SD timing should be handled by the + * SDHCI core. + */ + if (!IS_MMC(mmc)) + return -ENOSYS; + + if (WARN_ON(opcode != MMC_CMD_SEND_TUNING_BLOCK_HS200)) + return -EINVAL; + + for (i = 0; i < SDHCI_CDNS_MAX_TUNING_LOOP; i++) { + if (sdhci_cdns_set_tune_val(plat, i) || + mmc_send_tuning(mmc, opcode, NULL)) { /* bad */ + cur_streak = 0; + } else { /* good */ + cur_streak++; + if (cur_streak > max_streak) { + max_streak = cur_streak; + end_of_streak = i; + } + } + } + + if (!max_streak) { + dev_err(dev, "no tuning point found\n"); + return -EIO; + } + + return sdhci_cdns_set_tune_val(plat, end_of_streak - max_streak / 2); +} + +static struct dm_mmc_ops sdhci_cdns_mmc_ops; + static int sdhci_cdns_bind(struct udevice *dev) { struct sdhci_cdns_plat *plat = dev_get_platdata(dev); @@ -189,6 +257,10 @@ static int sdhci_cdns_probe(struct udevice *dev) host->ioaddr = plat->hrs_addr + SDHCI_CDNS_SRS_BASE; host->ops = &sdhci_cdns_ops; host->quirks |= SDHCI_QUIRK_WAIT_SEND_CMD; + sdhci_cdns_mmc_ops = sdhci_ops; +#ifdef MMC_SUPPORTS_TUNING + sdhci_cdns_mmc_ops.execute_tuning = sdhci_cdns_execute_tuning; +#endif ret = mmc_of_parse(dev, &plat->cfg); if (ret) @@ -223,5 +295,5 @@ U_BOOT_DRIVER(sdhci_cdns) = { .probe = sdhci_cdns_probe, .priv_auto_alloc_size = sizeof(struct sdhci_host), .platdata_auto_alloc_size = sizeof(struct sdhci_cdns_plat), - .ops = &sdhci_ops, + .ops = &sdhci_cdns_mmc_ops, };