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: 93149 Delivered-To: patches@linaro.org Received: by 10.140.20.99 with SMTP id 90csp490094qgi; Fri, 3 Feb 2017 00:28:26 -0800 (PST) X-Received: by 10.25.201.71 with SMTP id z68mr3786734lff.3.1486110506059; Fri, 03 Feb 2017 00:28:26 -0800 (PST) Return-Path: Received: from mail-lf0-x22e.google.com (mail-lf0-x22e.google.com. [2a00:1450:4010:c07::22e]) by mx.google.com with ESMTPS id u193si15927107lja.77.2017.02.03.00.28.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Feb 2017 00:28:25 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) client-ip=2a00:1450:4010:c07::22e; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22e as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x22e.google.com with SMTP id z134so6218300lff.3 for ; Fri, 03 Feb 2017 00:28:25 -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=Z7XpY3vc19nP38z5Wg764/zpR6OL2jhSMwhUfLZKcAdAHC7GvOMePviQZdCQyvdwHO KrDcyCda444ax+U2VeQCYR2XQf1plpUcmFIa1fe6gBHFQsvKk/DrkOibDWRB6QXOO3kB 0vK/Cv5rpdIFNPvS04TQ5OFo8scvy2PZDceZ2b5nsdx4pfBlXA+ggURLFFsM4Rbz2zGf 8ZYP0e6oow3n6ple7kWaKtJSW1XSMwUum+qJuJZnPsizNHZJsmmiMU1799XCz/qJ2CoQ HwfY9dkoBfze4YULFJgrQECXcA0FW7IPy58u5y8j5FThWBDzCg3lVrkwjgwa2bL81vIe l5aQ== X-Gm-Message-State: AIkVDXLJCcnVN60ptO+cPUTsWLt4UQgeb2hrY3GpCphB0Ln15+nyPjNG7TJ+o+k/17GhElyUAEg= X-Received: by 10.46.21.23 with SMTP id s23mr4847980ljd.54.1486110505591; Fri, 03 Feb 2017 00:28:25 -0800 (PST) Return-Path: 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 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 --- 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(-) -- 1.9.1 Tested-by: Kevin Hilman 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);