From patchwork Tue Apr 4 19:11:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9662447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 748F86032D for ; Tue, 4 Apr 2017 19:12:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 680D11FF1E for ; Tue, 4 Apr 2017 19:12:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C76F1FF60; Tue, 4 Apr 2017 19:12:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D85D21FF73 for ; Tue, 4 Apr 2017 19:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RkXB06B1qZPzrPHuEW9lOSGlku2WL14jyQaPAFHsdGk=; b=Hw8OcGO3I8y4by elsHWVmaNKdjSKzcFNh+48LWX3jAmgern9klO2PSErIXPMrkBemXjpjrFeONN7gKKRevCu4PDkkyd LK1L1JTXDylKZxp09K/FgzCVLiIRQsBhtpSrfRf8IipMVxMnxg7udNReSknXAxmoSO53HibX2S9af 0tpInAl/c1EDafCKY60zSfADdpnGrqKoe22K2aU2s4VD4Octa1IrCEi/LdqeE4jVzUfyq2PfYAzXK QTFuQYLE0XXKR8E71L7DX/Qu8prW20HakmlA/THJABxx1SQk+Xr6tAaQUlqgmGDIwtzurELIpNyQQ tseFvVz5Cs++Q18RTsLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cvTrw-0004RK-S5; Tue, 04 Apr 2017 19:11:56 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvTrq-00049K-5P for linux-amlogic@lists.infradead.org; Tue, 04 Apr 2017 19:11:53 +0000 Received: by mail-wm0-x243.google.com with SMTP id o81so7452343wmb.0 for ; Tue, 04 Apr 2017 12:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=gFa09uaiKeX/6X3k2JZrYoZocyGn9jOf2qAOJKf3Oxg=; b=nWkB37b5P3JVruCtXL9xPBRaHCcSkW+PLkHJEq/cIpeKfrpk5HRGkNMQqps/2zho66 Rj8NR7Ic1K42Y0HvzFtjuRKJjgTobw0rLEZ1/Wib8JlEo31jA1ZUewLQ9zYqv5IpUYa+ 2DYhqnRcMyAEQzteUu2bYew3W+4Dft5KztR+16mLNBl7au9ZUi9xohJWVqMX2Ox3pbIr 3UDp9cz0tAez3+vzNe0P89x8GSCFswOE65ngx6VjbLhejpFuiFOH/0Q1YE75YtJ59EyU OrLht3lghy0DMWjKKE2ufk/C7SP8XAeL2Rl6/XI3gAeCcws4sSdXw528djwYIkHlhbX1 H0LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=gFa09uaiKeX/6X3k2JZrYoZocyGn9jOf2qAOJKf3Oxg=; b=Drt0EtbFhRFqNjbCPyU0e31PVgpHrUQmlcHapDRRX9hlL+jxgea+R3jOZfGOPui4Yk xq31fTs93b8L4E92K/grOofKGA8TdIaIKydl1Yu+RZj0H30BJNxy/NZ6FMrp5oKyH8HQ F9NIkE5tCeXD/qMO6Cvi7EJl6Xj1NnMGkQdAMpTQ/O09Dk/xvx7WEOun0fZOptymrDsS EUFGB9hMQZ9NjLC6GO0xr3EOdvyzg3yd64/4lIm6ee7AzRFoSz15/zAzqiu/9YPB0fhf s81MvdxgWFDqguqBuzM+6VVGFbdJU4a5baIkzfJqoWf7PvetghasIgi3/j0AKALA1vNB EQrQ== X-Gm-Message-State: AFeK/H0yoaWNcu7WieLdQoRp+qbEIWkexMy2ANK6sJu0kNd3Q/RcNLag zgQ767E+MWnAlJnw X-Received: by 10.28.199.129 with SMTP id x123mr16106525wmf.7.1491333087032; Tue, 04 Apr 2017 12:11:27 -0700 (PDT) Received: from ?IPv6:2003:c6:ebdc:4000:c0d5:60a1:c236:c60b? (p200300C6EBDC4000C0D560A1C236C60B.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:c0d5:60a1:c236:c60b]) by smtp.googlemail.com with ESMTPSA id v7sm11264375wrd.0.2017.04.04.12.11.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 12:11:26 -0700 (PDT) Subject: [PATCH 2/2] mmc: meson-gx: add basic tuning for rx clock phase To: Ulf Hansson , Kevin Hilman References: <1d60ec2c-54c9-6b1c-7eaa-40e96fcd5be5@gmail.com> From: Heiner Kallweit Message-ID: <7a2da0fd-d529-ae23-9fc5-900ae2b26610@gmail.com> Date: Tue, 4 Apr 2017 21:11:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1d60ec2c-54c9-6b1c-7eaa-40e96fcd5be5@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170404_121151_009646_22727465 X-CRM114-Status: GOOD ( 12.80 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, "linux-mmc@vger.kernel.org" Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds basic tuning which changes the rx clock phase only until a working setting is found. On a Odroid C2 with 128GB eMMC card and 200 MHz MMC clock only 180° rx clock phase make the system boot w/o CRC errors. With other MMC devices / clock speeds this might be different, therefore don't change the driver config in general. When retuning skip the currently active parameter set. This avoids the current problematic config to be chosen again if it causes CRC errors just occasionally. Signed-off-by: Heiner Kallweit --- drivers/mmc/host/meson-gx-mmc.c | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 3a6e51c8..eb5ee68d 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -349,6 +349,31 @@ static int meson_mmc_clk_init(struct meson_host *host) return ret; } +static void meson_mmc_set_tuning_params(struct mmc_host *mmc) +{ + struct meson_host *host = mmc_priv(mmc); + u32 regval; + + /* stop clock */ + regval = readl(host->regs + SD_EMMC_CFG); + regval |= CFG_STOP_CLOCK; + writel(regval, host->regs + SD_EMMC_CFG); + + regval = readl(host->regs + SD_EMMC_CLOCK); + regval &= ~CLK_CORE_PHASE_MASK; + regval |= FIELD_PREP(CLK_CORE_PHASE_MASK, host->tp.core_phase); + regval &= ~CLK_TX_PHASE_MASK; + regval |= FIELD_PREP(CLK_TX_PHASE_MASK, host->tp.tx_phase); + regval &= ~CLK_RX_PHASE_MASK; + regval |= FIELD_PREP(CLK_RX_PHASE_MASK, host->tp.rx_phase); + writel(regval, host->regs + SD_EMMC_CLOCK); + + /* start clock */ + regval = readl(host->regs + SD_EMMC_CFG); + regval &= ~CFG_STOP_CLOCK; + writel(regval, host->regs + SD_EMMC_CFG); +} + static void meson_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) { struct meson_host *host = mmc_priv(mmc); @@ -682,6 +707,29 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id) return IRQ_HANDLED; } +static int meson_mmc_execute_tuning(struct mmc_host *mmc, u32 opcode) +{ + struct meson_host *host = mmc_priv(mmc); + struct meson_tuning_params tp_old = host->tp; + int ret = -EINVAL, i, cmd_error; + + dev_info(mmc_dev(mmc), "(re)tuning...\n"); + + for (i = CLK_PHASE_0; i <= CLK_PHASE_270; i++) { + host->tp.rx_phase = i; + /* exclude the active parameter set if retuning */ + if (!memcmp(&tp_old, &host->tp, sizeof(tp_old)) && + mmc->doing_retune) + continue; + meson_mmc_set_tuning_params(mmc); + ret = mmc_send_tuning(mmc, opcode, &cmd_error); + if (!ret) + break; + } + + return ret; +} + /* * NOTE: we only need this until the GPIO/pinctrl driver can handle * interrupts. For now, the MMC core will use this for polling. @@ -712,6 +760,7 @@ static const struct mmc_host_ops meson_mmc_ops = { .request = meson_mmc_request, .set_ios = meson_mmc_set_ios, .get_cd = meson_mmc_get_cd, + .execute_tuning = meson_mmc_execute_tuning, }; static int meson_mmc_probe(struct platform_device *pdev)