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: 9662445 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 D727E6032D for ; Tue, 4 Apr 2017 19:11:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAA8428549 for ; Tue, 4 Apr 2017 19:11:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFA5828554; Tue, 4 Apr 2017 19:11:37 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5665328549 for ; Tue, 4 Apr 2017 19:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753852AbdDDTLa (ORCPT ); Tue, 4 Apr 2017 15:11:30 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33226 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753124AbdDDTL2 (ORCPT ); Tue, 4 Apr 2017 15:11:28 -0400 Received: by mail-wm0-f67.google.com with SMTP id o81so7452322wmb.0 for ; Tue, 04 Apr 2017 12:11:27 -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=ghwLW+ifyRHOtnPbrsv6WNzsAkOa2xyDs0o7dFR1BatC2FJMkPHVVliFmuGn5yOF2u qvfl47fgtQ5Ow/GCrJEbir6ob5HtWvnhFkFo24m+Yc0DLkN2ScE8pI4I4OTvmuBxdx9V ndc0JL7Hecfzkf7pCXtsjZ9LIV4ZqAmX9FBwzJuN60csoVZHiImqytIjyLCTSnk/RJwP jZfzAW/zdcycJu/oeeOUSTjmAMT48Zr9WZbwntmQl7k6gvIxv8nPeFiP72Grk1hykiq4 6AVVdqp4idlBfFJvVsV9Fdh1adk5VmxEiJhLskrZaBfh2iRIvRFGvT47B/tsoI0lrMpH OfjQ== X-Gm-Message-State: AFeK/H20LZ/fXpKcmYdeJQxj/bVolhe4MEJmPW1S0NoReJcSlY8iMByR sin15ls602euYg== 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> Cc: "linux-mmc@vger.kernel.org" , linux-amlogic@lists.infradead.org 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> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.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)