From patchwork Wed May 28 13:47:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 31071 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 10D9520068 for ; Wed, 28 May 2014 13:48:18 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id oz11sf44268468veb.10 for ; Wed, 28 May 2014 06:48:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=EGL5A59jIfE3i6uBaccYLGsCQ4o+o0dSD8nhDQLnYng=; b=DX1z2YS5KfWyZ1EE1OjCvItlmeefWsEtqmi26SCgPoEkqDMYDq7yCBSxayV/hd9Nng 7ksWHMg7VrpcDXzB4kZhIfUVUpRCiEkWVlihRifNNnHn2g8TmQvNWZG1HA4N+SJ4312T W/pHcCSoUr0ifB/MGsm8hgQIolIexLvbTIFz0odxOMrCpDSFFuHnWH1MjESP51fndSl4 N+M07aaOykIS9bGV0H1g5/uTLHWbYe9SSI02s5+tnGP3PSapGc//KTUJOTq8THrb5sOl fdeTQUDwdrqGBR0PjDgwSlsBndeiYyiL/nr3ycHYaGw5cUtUadKzcnYBBqaRTWRi9bjI MWWw== X-Gm-Message-State: ALoCoQkjYAzw++UsaarAW253V3SdgqpoGfPERbnD3ErcBhf+CHF20gip+WYn5x7VwI4BCgoczuB7 X-Received: by 10.58.68.106 with SMTP id v10mr16184211vet.24.1401284898807; Wed, 28 May 2014 06:48:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.180 with SMTP id w49ls105337qge.3.gmail; Wed, 28 May 2014 06:48:18 -0700 (PDT) X-Received: by 10.220.44.141 with SMTP id a13mr1040221vcf.71.1401284898692; Wed, 28 May 2014 06:48:18 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id e8si10546470vdv.65.2014.05.28.06.48.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 May 2014 06:48:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jw12so12348149veb.6 for ; Wed, 28 May 2014 06:48:18 -0700 (PDT) X-Received: by 10.58.34.72 with SMTP id x8mr1286824vei.61.1401284898510; Wed, 28 May 2014 06:48:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp204439vcb; Wed, 28 May 2014 06:48:18 -0700 (PDT) X-Received: by 10.68.239.137 with SMTP id vs9mr46767838pbc.84.1401284897512; Wed, 28 May 2014 06:48:17 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id su6si3047429pab.177.2014.05.28.06.48.16 for ; Wed, 28 May 2014 06:48:16 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754434AbaE1NsH (ORCPT + 27 others); Wed, 28 May 2014 09:48:07 -0400 Received: from mail-we0-f177.google.com ([74.125.82.177]:49716 "EHLO mail-we0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754394AbaE1NsE (ORCPT ); Wed, 28 May 2014 09:48:04 -0400 Received: by mail-we0-f177.google.com with SMTP id x48so10907241wes.8 for ; Wed, 28 May 2014 06:48:02 -0700 (PDT) X-Received: by 10.194.89.40 with SMTP id bl8mr35490062wjb.90.1401284882804; Wed, 28 May 2014 06:48:02 -0700 (PDT) Received: from srini-ThinkPad-X1-Carbon-2nd.dlink.com (host-78-149-4-211.as13285.net. [78.149.4.211]) by mx.google.com with ESMTPSA id fq2sm17064839wib.2.2014.05.28.06.48.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 May 2014 06:48:01 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: Russell King , Ulf Hansson , linux-mmc@vger.kernel.org Cc: Chris Ball , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linus.walleij@linaro.org, Srinivas Kandagatla Subject: [PATCH v4 12/13] mmc: mmci: add explicit clk control Date: Wed, 28 May 2014 14:47:58 +0100 Message-Id: <1401284878-16937-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401284608-16428-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1401284608-16428-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Srinivas Kandagatla On Controllers like Qcom SD card controller where cclk is mclk and mclk should be directly controlled by the driver. This patch adds support to control mclk directly in the driver, and also adds explicit_mclk_control flag in variant structure giving more flexibility to the driver. Signed-off-by: Srinivas Kandagatla --- drivers/mmc/host/mmci.c | 96 ++++++++++++++++++++++++++++++++----------------- drivers/mmc/host/mmci.h | 2 ++ 2 files changed, 65 insertions(+), 33 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 202f2d5..6eb0a29 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -72,6 +72,7 @@ static unsigned int fmax = 515633; * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock * @busy_detect: true if busy detection on dat0 is supported * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply + * @explicit_mclk_control: enable explicit mclk control in driver. */ struct variant_data { unsigned int clkreg; @@ -93,6 +94,7 @@ struct variant_data { bool pwrreg_clkgate; bool busy_detect; bool pwrreg_nopower; + bool explicit_mclk_control; }; static struct variant_data variant_arm = { @@ -199,6 +201,7 @@ static struct variant_data variant_qcom = { .datalength_bits = 24, .pwrreg_powerup = MCI_PWR_UP, .f_max = 208000000, + .explicit_mclk_control = true, }; static int mmci_card_busy(struct mmc_host *mmc) @@ -301,7 +304,9 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) host->cclk = 0; if (desired) { - if (desired >= host->mclk) { + if (variant->explicit_mclk_control) { + host->cclk = host->mclk; + } else if (desired >= host->mclk) { clk = MCI_CLK_BYPASS; if (variant->st_clkdiv) clk |= MCI_ST_UX500_NEG_EDGE; @@ -1340,6 +1345,18 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (!ios->clock && variant->pwrreg_clkgate) pwr &= ~MCI_PWR_ON; + if ((host->variant->explicit_mclk_control) && + (ios->clock != host->mclk_req)) { + int rc = clk_set_rate(host->clk, ios->clock); + if (rc < 0) { + dev_err(mmc_dev(host->mmc), + "Error setting clock rate (%d)\n", rc); + } else { + host->mclk = clk_get_rate(host->clk); + host->mclk_req = ios->clock; + } + } + spin_lock_irqsave(&host->lock, flags); mmci_set_clkreg(host, ios->clock); @@ -1490,19 +1507,6 @@ static int mmci_probe(struct amba_device *dev, host->plat = plat; host->variant = variant; host->mclk = clk_get_rate(host->clk); - /* - * According to the spec, mclk is max 100 MHz, - * so we try to adjust the clock down to this, - * (if possible). - */ - if (host->mclk > host->variant->f_max) { - ret = clk_set_rate(host->clk, host->variant->f_max); - if (ret < 0) - goto clk_disable; - host->mclk = clk_get_rate(host->clk); - dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n", - host->mclk); - } host->phybase = dev->res.start; host->base = devm_ioremap_resource(&dev->dev, &dev->res); @@ -1511,25 +1515,51 @@ static int mmci_probe(struct amba_device *dev, goto clk_disable; } - /* - * The ARM and ST versions of the block have slightly different - * clock divider equations which means that the minimum divider - * differs too. - */ - if (variant->st_clkdiv) - mmc->f_min = DIV_ROUND_UP(host->mclk, 257); - else - mmc->f_min = DIV_ROUND_UP(host->mclk, 512); - /* - * If no maximum operating frequency is supplied, fall back to use - * the module parameter, which has a (low) default value in case it - * is not specified. Either value must not exceed the clock rate into - * the block, of course. - */ - if (mmc->f_max) - mmc->f_max = min(host->mclk, mmc->f_max); - else - mmc->f_max = min(host->mclk, fmax); + if (variant->explicit_mclk_control) { + /* get the nearest minimum clock to 100Khz */ + mmc->f_min = clk_round_rate(host->clk, 100000); + + if (mmc->f_max) + mmc->f_max = min(host->variant->f_max, mmc->f_max); + else + mmc->f_max = min(host->variant->f_max, fmax); + + } else { + /* + * According to the spec, mclk is max 100 MHz, + * so we try to adjust the clock down to this, + * (if possible). + */ + if (host->mclk > host->variant->f_max) { + ret = clk_set_rate(host->clk, host->variant->f_max); + if (ret < 0) + goto clk_disable; + host->mclk = clk_get_rate(host->clk); + dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n", + host->mclk); + } + /* + * The ARM and ST versions of the block have slightly different + * clock divider equations which means that the minimum divider + * differs too. + */ + if (variant->st_clkdiv) + mmc->f_min = DIV_ROUND_UP(host->mclk, 257); + else + mmc->f_min = DIV_ROUND_UP(host->mclk, 512); + /* + * If no maximum operating frequency is supplied, fall back to + * use the module parameter, which has a (low) default value in + * case it is not specified. Either value must not exceed the + * clock rate into the block, of course. + */ + if (mmc->f_max) + mmc->f_max = min(host->mclk, mmc->f_max); + else + mmc->f_max = min(host->mclk, fmax); + + } + dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max); /* Get regulators and the supported OCR mask */ diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index 706eb513..1882e20 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -208,6 +208,8 @@ struct mmci_host { spinlock_t lock; unsigned int mclk; + /* cached value of requested clk in set_ios */ + unsigned int mclk_req; unsigned int cclk; u32 pwr_reg; u32 pwr_reg_add;