From patchwork Fri Feb 3 08:28:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9553599 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 48229604A7 for ; Fri, 3 Feb 2017 08:28:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 394D5284F0 for ; Fri, 3 Feb 2017 08:28:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AA8E284F3; Fri, 3 Feb 2017 08:28:29 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 AE625284F0 for ; Fri, 3 Feb 2017 08:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163AbdBCI22 (ORCPT ); Fri, 3 Feb 2017 03:28:28 -0500 Received: from mail-lf0-f47.google.com ([209.85.215.47]:35729 "EHLO mail-lf0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbdBCI21 (ORCPT ); Fri, 3 Feb 2017 03:28:27 -0500 Received: by mail-lf0-f47.google.com with SMTP id n124so6226728lfd.2 for ; Fri, 03 Feb 2017 00:28:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=lZ5iIheK+WeSreMqdTOX/rlB1IQ3uTj85zmWSU6Sx1o=; b=kByFeiYXzTtef1VLNVSSHNiiZ48P5r0plwRJcP5qtYczxQzEAqm16Q6RVF/r1cRrnu CurKPgKArx7mVlobMd2uxa9OvBadB0DMGusbimEU/08L36SQZIGlCyxD5IrfaNqwaaVC YdAXVMY8jKGiM3HnsvSwXAxjte7tW36c06rkc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lZ5iIheK+WeSreMqdTOX/rlB1IQ3uTj85zmWSU6Sx1o=; b=Jm6ek31aIfeIPPfJRAyXygDJKRgm3yXlLKuotIaLSiZNll6hgGGEmIcznh95sDEnVw DULrMefVNk7YDcu+dpHTfZ9BbZf6Ql5Fky3v5cc12fNCpjwwuLmaQOks53o5ZMySdx+8 dmwO45oSjhqpfnjJce/+wr7zGNi/pwL4RB+YJHSLhdyFUQPTPWy/HRVQWJamEGumvgBH 8dgiiehFTSKmLhEz4Ozs8ZHfAcof3Vy6iuVvMHI52cAsFqUEL7ec74dUypsWAXUBQQ5R WyiESIl2/jT75uogRdrP+z7k06XpZSWcpKN4WCXcibVx7P4lfVGsrifiUtiy9UIyY+uI U6ug== X-Gm-Message-State: AIkVDXL9OcZepOhHuL/1pUAK/f4LfGagbYBE8QKoc/THHbbTc6i1h8XwW8KFv/VcP8werUeB X-Received: by 10.46.21.23 with SMTP id s23mr4847980ljd.54.1486110505591; Fri, 03 Feb 2017 00:28:25 -0800 (PST) Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id s28sm1420804ljd.6.2017.02.03.00.28.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 00:28:24 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Heiner Kallweit , Carlo Caione , Kevin Hilman , linux-amlogic@lists.infradead.org Subject: [PATCH] mmc: meson: Assign the minimum clk rate as close to 100KHz as possible Date: Fri, 3 Feb 2017 09:28:11 +0100 Message-Id: <1486110491-8921-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 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 The current code dealing with calculating mmc->f_min is a bit complicated. Additionally, the attempt to set an initial clock rate should explicitly use a rate between 100KHz to 400 KHz, according the (e)MMC/SD specs, which it doesn't. Fix the problem and clean up the code by using clk_round_rate() to pick the nearest minimum rate to 100KHz. Signed-off-by: Ulf Hansson Tested-by: Kevin Hilman --- Note, this is compile tested only so I hope someone with the HW can give it a go. --- drivers/mmc/host/meson-gx-mmc.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 5eca88b..c672e01 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -240,7 +240,6 @@ static int meson_mmc_clk_init(struct meson_host *host) const char *mux_parent_names[MUX_CLK_NUM_PARENTS]; unsigned int mux_parent_count = 0; const char *clk_div_parents[1]; - unsigned int f_min = UINT_MAX; u32 clk_reg, cfg; /* get the mux parents */ @@ -257,20 +256,10 @@ static int meson_mmc_clk_init(struct meson_host *host) return ret; } - host->mux_parent_rate[i] = clk_get_rate(host->mux_parent[i]); mux_parent_names[i] = __clk_get_name(host->mux_parent[i]); mux_parent_count++; - if (host->mux_parent_rate[i] < f_min) - f_min = host->mux_parent_rate[i]; } - /* cacluate f_min based on input clocks, and max divider value */ - if (f_min != UINT_MAX) - f_min = DIV_ROUND_UP(CLK_SRC_XTAL_RATE, CLK_DIV_MAX); - else - f_min = 4000000; /* default min: 400 MHz */ - host->mmc->f_min = f_min; - /* create the mux */ snprintf(clk_name, sizeof(clk_name), "%s#mux", dev_name(host->dev)); init.name = clk_name; @@ -325,9 +314,13 @@ static int meson_mmc_clk_init(struct meson_host *host) writel(cfg, host->regs + SD_EMMC_CFG); ret = clk_prepare_enable(host->cfg_div_clk); - if (!ret) - ret = meson_mmc_clk_set(host, f_min); + if (ret) + return ret; + + /* Get the nearest minimum clock to 100KHz */ + host->mmc->f_min = clk_round_rate(host->cfg_div_clk, 100000); + ret = meson_mmc_clk_set(host, host->mmc->f_min); if (!ret) clk_disable_unprepare(host->cfg_div_clk);