From patchwork Wed Apr 25 12:09:32 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: 134261 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp781723lji; Wed, 25 Apr 2018 05:12:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/dnzozKqtIJhXilSy0zXv5Un8hOZiVVmLTM6VHlkijILvQ7zuaJjT/hnsNiY1zPGNIkq+1 X-Received: by 2002:a17:902:a704:: with SMTP id w4-v6mr28889307plq.5.1524658360143; Wed, 25 Apr 2018 05:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524658360; cv=none; d=google.com; s=arc-20160816; b=et2eha73Ra/XIeKjgmO/DigwuKVpY08Hm4KCCPJvsT5jNdanlkAIvbpzxOS+5VWf2h 4VBpUtmcwoSIAlhfO91pu8R8plW6M8qvhh5Iz0pRBolxkrrklkp2raxvZCukfYm/ekL1 ydx+A5uhh1xsx6frLpa5UBu1FW3TKJif0XjqAhsV9M5ZAtNJ8hJiGOTa3W3sgNWbf3ak fil8u02ym0ivxfIv6yu4lCAmobYwQxjoJTqDr4kdVIug7YoyYileKOZR/uCApK/hmD85 aCzd2UjGk9B8Hankg8aP2maQuDft46m7L4EuH9WUVNBqpvd/KtGPFUqzM/vmcRW7FDVL qBbg== 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=vDmcHJWToBqOYh8duOj2QMiu91OEs93gfQ8kurTSqU4=; b=XNN2ZnXpW/au0RZRrdyrUhE3Hto8DISpI9gGhdAm0udO7VemLWCTjIrOnGaOPNtY4j 81s8UAhV28ixFvpONRedL8h9bHRirqC2un31JJGEVZe/155aDXTaWu6YpZ4E7pMMEgsr tUL4gDN8ZGGIRUmY4sm/7SXJ71jfZcED07cXQoLsD4PQcK1nl4sQIplmLSqRJYJW1Wkz uwxvbfobd6fhPc+exEialVXNJKcqKIyrjCzQzhocCO1lWDtYbv3D5XLG6spf7Xi6Hsfl uFTnFBKBQw3FxbSQcAhjgANbxetv9LvTARwfC6A5t+thhAETRuUvs25XUAekfBZwg9dm TV8A== 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=xsDbjDLP; 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 u14-v6si1757669plq.439.2018.04.25.05.12.39; Wed, 25 Apr 2018 05:12:40 -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=xsDbjDLP; 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 S1753329AbeDYMMi (ORCPT + 6 others); Wed, 25 Apr 2018 08:12:38 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:13748 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753110AbeDYMKR (ORCPT ); Wed, 25 Apr 2018 08:10:17 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3PCAAXf017442; Wed, 25 Apr 2018 07:10:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524658210; bh=/JoDwUQXlRqzfDR/Jbbn3G6wLg9UjQ+jGXfrCrAUztU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=xsDbjDLP6Flsur4DZbrMRlRrNidBjTV6p4bi0JmzDUojNiFDzFdqGkTIKBU6O4aS9 7Jl3dGKU5EXt2Zt7DKb5Gayf36PXW0Eg7wlhsKGAf0mIxZgmCcAg9dPsP5ZPXbgMqp 16HTzog91c91RfEZeYXs8neiWeBbJVERmvLJScwA= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3PCAAhu016474; Wed, 25 Apr 2018 07:10:10 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Wed, 25 Apr 2018 07:10:09 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE102.ent.ti.com (10.64.6.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Wed, 25 Apr 2018 07:10:09 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3PC9hhU009970; Wed, 25 Apr 2018 07:10:06 -0500 From: Kishon Vijay Abraham I To: Ulf Hansson , Adrian Hunter CC: , Rob Herring , Mark Rutland , , , , , Tony Lindgren Subject: [PATCH v4 07/12] mmc: sdhci: Factor out target_timeout calculation Date: Wed, 25 Apr 2018 17:39:32 +0530 Message-ID: <20180425120937.29867-8-kishon@ti.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425120937.29867-1-kishon@ti.com> References: <20180425120937.29867-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 b91163de4da4..c432ec3644aa 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.