From patchwork Fri Apr 27 11:47:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 134589 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp617631lji; Fri, 27 Apr 2018 04:48:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqID8nZxP9+2gldDw5/Lx20Eu+3qgu/kVS74vL0AP6EWsWmeHK6D900vbPOOqTLVac81s3/ X-Received: by 2002:a17:902:76c1:: with SMTP id j1-v6mr2017569plt.284.1524829684462; Fri, 27 Apr 2018 04:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524829684; cv=none; d=google.com; s=arc-20160816; b=wd1UT/gMTa3NjU0z8pWr6xQEf2xM/dy2H6FpkfK8tgooIulzo3lXYTlszxJcGMIIbj h7oMSrjZ3JoRhpu+WeFVqePLLB1j9gofm1+hOPfyZ7NtUh8/48tDq7A0azVVR3IBjZ6o 391sZ+GaYURCt6bJNOmhNeBj+wBG4zss4W5BY5oQVBuEblkH+Mm0XA4GgoLnOn+25srX 3n9ODucflYYdnWxH8K/MVikZNviTlA/xNy3kVWtI8RkSLhxsI4z8ExMhIhn520dwLVxB xpQ8velE8CI63N4PasJUefdV28oAiUI0MN2/XO9YGIfy6w96IgzxBqWn7A9wwvAF20s4 XCRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=zyPrL2Zqy3Kp/oKnaz6pqzl4t3thDnhkVWqgNre3Dpo=; b=K9vXsscnCM9Yw3ccwfy7jBQQ5H1OmiRM/7DkDln+vYn+T+MsqJjw8tudSbqbcCisT/ cnbZpeE4wgZlruZuLFQNfPd9vcYEwQ96QYV0rqShWR3lMpz6MKkroxVvWgOSanfQCGup Z79qCJsUYkJ/cpxJ7wqNtGehCJLxP+OFe+X1nXKNdMwFj2MDrvPykfn2Gdh5BRS4y/47 MUWFI0F5SzlpDF80hTHqxwXs3x/3VmFno4vKjWHgUE+5oAe7E5nWLVHmK9HDiqjOj7AZ Z+IAJqcF9SAN7eZAqEK3FlZPeeTwPjgwOXnDRbXSUmWRHr8YZaiPoD8k7xolZ/wpiA+v vS6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=xKJvfPnw; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9-v6si1118288pgc.205.2018.04.27.04.48.04; Fri, 27 Apr 2018 04:48:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ti.com header.s=ti-com-17Q1 header.b=xKJvfPnw; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=QUARANTINE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757690AbeD0LsB (ORCPT + 6 others); Fri, 27 Apr 2018 07:48:01 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:46572 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758058AbeD0Lr5 (ORCPT ); Fri, 27 Apr 2018 07:47:57 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx210.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3RBlqln009517; Fri, 27 Apr 2018 06:47:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524829672; bh=62KBgDOrYk0C8h+6suJm7ipXR11n2jZtKAih2SViZyg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=xKJvfPnwNkqJ8Lt+DqX6FmMDA6LnZkq7rOk/dOto02K+evziZ3Q+Qs0sokggYF9+Z Q20fPTedY5KSTWnAtxcM4gTDQ6NCrVrYIaKGLa1fIsMY8uXFzm8BW0oUX3iGXYvLyU lCnAexKysNcfSMZSlw2Vr6T9Hgu10nUd9GopBdIk= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3RBlqKd015032; Fri, 27 Apr 2018 06:47:52 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 27 Apr 2018 06:47:51 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 27 Apr 2018 06:47:51 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3RBlRSL014207; Fri, 27 Apr 2018 06:47:49 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Adrian Hunter CC: Rob Herring , Mark Rutland , , , , , Subject: [PATCH v5 07/14] mmc: sdhci: Factor out target_timeout calculation Date: Fri, 27 Apr 2018 17:17:16 +0530 Message-ID: <20180427114723.2687-8-kishon@ti.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427114723.2687-1-kishon@ti.com> References: <20180427114723.2687-1-kishon@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: Adrian Hunter Factor out the target_timeout calculation so it can be re-used. Signed-off-by: Adrian Hunter Signed-off-by: Kishon Vijay Abraham I --- drivers/mmc/host/sdhci.c | 48 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 18 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 8da118d0d2c4..b229354e5b88 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -709,6 +709,35 @@ static u32 sdhci_sdma_address(struct sdhci_host *host) return sg_dma_address(host->data->sg); } +static unsigned int sdhci_target_timeout(struct sdhci_host *host, + struct mmc_command *cmd, + struct mmc_data *data) +{ + unsigned int target_timeout; + + /* timeout in us */ + if (!data) { + target_timeout = cmd->busy_timeout * 1000; + } else { + target_timeout = DIV_ROUND_UP(data->timeout_ns, 1000); + if (host->clock && data->timeout_clks) { + unsigned long long val; + + /* + * data->timeout_clks is in units of clock cycles. + * host->clock is in Hz. target_timeout is in us. + * Hence, us = 1000000 * cycles / Hz. Round up. + */ + val = 1000000ULL * data->timeout_clks; + if (do_div(val, host->clock)) + target_timeout++; + target_timeout += val; + } + } + + return target_timeout; +} + static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, bool *too_big) { @@ -732,24 +761,7 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, return 0xE; /* timeout in us */ - if (!data) - target_timeout = cmd->busy_timeout * 1000; - else { - target_timeout = DIV_ROUND_UP(data->timeout_ns, 1000); - if (host->clock && data->timeout_clks) { - unsigned long long val; - - /* - * data->timeout_clks is in units of clock cycles. - * host->clock is in Hz. target_timeout is in us. - * Hence, us = 1000000 * cycles / Hz. Round up. - */ - val = 1000000ULL * data->timeout_clks; - if (do_div(val, host->clock)) - target_timeout++; - target_timeout += val; - } - } + target_timeout = sdhci_target_timeout(host, cmd, data); /* * Figure out needed cycles.