Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2409192imm; Mon, 16 Jul 2018 07:35:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfTvTb88NFwTwoBLA9kGong3NEhsaBteB6zNwUKNxmX8eGthcny9c8sj/515zJx1R/zhRRq X-Received: by 2002:a17:902:246a:: with SMTP id m39-v6mr16945628plg.141.1531751737299; Mon, 16 Jul 2018 07:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531751737; cv=none; d=google.com; s=arc-20160816; b=ho2Nj+csjrinmmYQlNIT4ChO2gBPsxSOGoBwYYV+lxvoy2CkwW0CkxegxrPIPVZ/1g J3yzftruQTVqTZoCh2WMRJTLcHoFpjKSgIX/IwovrH8gc+32PvmbHJwZcPxDPDjLHC9l 0fAu/Q5Jo1FTUtam3Rjdkcss43yy343RUMBYhMPPokv2A53S/rxa/1VBfTqM4Acvwehq jlPPCdPmThLn62PRyrmMJ17YF3Pq9XdJfNC905T9QyHUOROnIYHfIUIEPYOrNdUfGK7b dFOOGvrXhjIKWpw/fbxpij/2HolHAduJOP0D8yjEn7x6WAo1nde9sHiPFcBNONOwm2Af 7p+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=B8A4sm+Lid3odrN192z13GINhupIJCj1uajgx8zMepY=; b=jHOPDGe5nzDeHWVs24UZbL2EE28PHSQMCBV/c25vw68ga7L6Bat4OlFeWLjM0tFn8S j/RquxRgsSmU1cH0YCajnHAKnRPoMqbVw1pqayTgk7CXkM47T8ubxhtj23G2NDyYxO0R RSyR1kjYnDD0Wkt2FSwxpeQK9bKP6/rH5DXoeaZ1/kAlcVqe3Z5oaOrP1tFUpX4xwtr3 A0qPjxhiZG4kSW3zojq9V8vz+JJFYtsEG7VO/GuoEZEwdK01oLCsGK/vWRaQey7Pll0W r/2atxsRN2PcGzRoHYB8Mq3HJGztbCsuH5EFU/aa1HusU5eoWkbvVbVv0tSjTui5BdO+ m4Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32-v6si30316381plc.452.2018.07.16.07.35.20; Mon, 16 Jul 2018 07:35:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728300AbeGPPCZ (ORCPT + 99 others); Mon, 16 Jul 2018 11:02:25 -0400 Received: from hqemgate15.nvidia.com ([216.228.121.64]:4238 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727342AbeGPPCZ (ORCPT ); Mon, 16 Jul 2018 11:02:25 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Mon, 16 Jul 2018 07:33:53 -0700 Received: from HQMAIL106.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 16 Jul 2018 07:34:42 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 16 Jul 2018 07:34:42 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 16 Jul 2018 14:34:42 +0000 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2 via Frontend Transport; Mon, 16 Jul 2018 14:34:42 +0000 Received: from dhcp-10-21-25-168.Nvidia.com (Not Verified[10.21.25.201]) by hqnvemgw02.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Mon, 16 Jul 2018 07:34:42 -0700 From: Aapo Vienamo To: Adrian Hunter , Ulf Hansson , Thierry Reding , Jonathan Hunter , Marcel Ziswiler , Stefan Agner CC: , , , Aapo Vienamo Subject: [PATCH] mmc: tegra: Force correct divider calculation on DDR50/52 Date: Mon, 16 Jul 2018 17:34:29 +0300 Message-ID: <1531751669-26584-1-git-send-email-avienamo@nvidia.com> X-Mailer: git-send-email 2.7.4 X-NVConfidentiality: public MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tegra SDHCI controllers require the SDHCI clock divider to be configured to divide the clock by two in DDR50/52 modes. Incorrectly configured clock divider results in corrupted data. Prevent the possibility of incorrectly calculating the divider value due to clock rate rounding or low parent clock frequency by not assigning host->max_clk to clk_get_rate() on tegra_sdhci_set_clock(). See the comments for further details. Fixes: a8e326a ("mmc: tegra: implement module external clock change") Signed-off-by: Aapo Vienamo --- drivers/mmc/host/sdhci-tegra.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index ddf00166..908b23e 100644 --- a/drivers/mmc/host/sdhci-tegra.c +++ b/drivers/mmc/host/sdhci-tegra.c @@ -210,9 +210,24 @@ static void tegra_sdhci_set_clock(struct sdhci_host *host, unsigned int clock) if (!clock) return sdhci_set_clock(host, clock); + /* + * In DDR50/52 modes the Tegra SDHCI controllers require the SDHCI + * divider to be configured to divided the host clock by two. The SDHCI + * clock divider is calculated as part of sdhci_set_clock() by + * sdhci_calc_clk(). The divider is calculated from host->max_clk and + * the requested clock rate. + * + * By setting the host->max_clk to clock * 2 the divider calculation + * will always result in the correct value for DDR50/52 modes, + * regardless of clock rate rounding, which may happen if the value + * from clk_get_rate() is used. + */ host_clk = tegra_host->ddr_signaling ? clock * 2 : clock; clk_set_rate(pltfm_host->clk, host_clk); - host->max_clk = clk_get_rate(pltfm_host->clk); + if (tegra_host->ddr_signaling) + host->max_clk = host_clk; + else + host->max_clk = clk_get_rate(pltfm_host->clk); sdhci_set_clock(host, clock); -- 2.7.4