Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp950780pxb; Thu, 5 Nov 2020 18:32:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbA7bxHaLMCIcNur8NxsHX2g7Z9++GGyH2SKPjS5JcKn2r8OCprK2UPdoFcUaVdiUWHGqY X-Received: by 2002:a17:906:7190:: with SMTP id h16mr5280305ejk.221.1604629922666; Thu, 05 Nov 2020 18:32:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604629922; cv=none; d=google.com; s=arc-20160816; b=FYWNFUpP4QrNmD9/sLhubzX4MEp62Kd7WUcvwnDJMcfSGI5RY5Ps6Lxy8sPBaXa0Dv jeloG7arAzJebrh/ZT4QvhJyzXUMy+fFpgmi3KxlYbss4jpvexY7+fM7vE04WqIyVOrJ UtrKTEfPekfW4pMzQiPiE9bfFaZtV5CyigK3aO+aFXniij/o/lt35RszXw9EsRqewat2 R9q18MSJLd3m7HWgT+14AWMRt4/vRDWFUC2eX+VCQLK4gUCuQ3LuxgSDmtJiH+79Kdf1 mY/Ztd8AnrY/awiXM029lHN/AjSncDcnWBiTyMbz1crtzK8ovs3IzMCSSmJJeYgEc1n3 np3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0nsPN94n1n+TqzMZKBqH2HrUDrXH3mf0VWWmS8hMBwk=; b=q7ivkQ/eiE5FVTrA4xKvzwBIXLMWVOLXjGDiv8jA+QFVTV41dShMGUJSt2rmR/eXeU TWz5svYcdIooox+ufOXVKNnouIivvpxCN229uPOdqAw1vCh+0DjGvU5OdszSyBYxanp4 l3rsSzPGLC0nx6Dxbl6nfL+2flBwLVkfLkaZXxQjRbQyno3PP8KQWiDjs/oeH15s8jYu j3E31SeMlS4MY1H23MarU7aEH+AhWUaPJ3SF7r7L1XJess4UNVKydBM10yPhk+ViEY8i QgLNcVMV3X43oZXwyvhVL48Bdo52BJUiTcmFbw83soXu7+Ro2Q73b4NyFL1qj4S3r7oi Jo5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A4l5b9za; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si2663453edr.154.2020.11.05.18.31.40; Thu, 05 Nov 2020 18:32:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A4l5b9za; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726198AbgKFC2r (ORCPT + 99 others); Thu, 5 Nov 2020 21:28:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbgKFC2n (ORCPT ); Thu, 5 Nov 2020 21:28:43 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67A50C0613CF for ; Thu, 5 Nov 2020 18:28:43 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id f21so1725568plr.5 for ; Thu, 05 Nov 2020 18:28:43 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=0nsPN94n1n+TqzMZKBqH2HrUDrXH3mf0VWWmS8hMBwk=; b=A4l5b9zaNAXv2mt7fjgN5ByMw8GOCnqvGz2Zk5X0V71U4aDo4pcNanfPaugat51Ity B4P5/HGcT3RNxrmLVwoqjl3S2dtmLr+V88OQBHbjsR7eHrelAm9iFSX/MkV+fOeLH2Ur gh9XDLCJ3/wVMBJbk7LJWHp+B3BvRi6p+gB2X57+luYxsR/VMao1dAkWIWe74rGaLp20 RdtAVu+4SWi40cFdFM5xZU9BTc7IRohFbRx8cs1gwcgvyrZah7cj6Jw0k7J4JAwD61m0 2RjFHEl/IluRkVamhKEvkEVqcvb7iWxBUNh2C1TTea4gzYk+hkDhEHjszsrA1eCnmL/x hN6g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=0nsPN94n1n+TqzMZKBqH2HrUDrXH3mf0VWWmS8hMBwk=; b=YVwLYr9BB1+YGJ+curs10o3VSs1tQ0QxlMBPDOd1nb+w/uVzgtSvUhWwqLyUgnFwu+ a2VSLvT709xEbEIC1RWPYmpqchVsm4b/BoiO+Hfvclte5ASCTL/1YNbS/Six6EaD67g9 lQypVnCBEqRcELuf2nqOTN/Kzb+r5dG28FxIPmCM6OaXlzAoD2qURhtyI15fb1IkDGWg 56YRbsU/3iXfLPu+7jkZD9eit3JkSwwc7kpniLRKGT6Skt1zPQG/LIOIhaVB0Ez7cDvU R2csIOmojsKZtygjl38wrSnP3P2x00o1OfLsbpSq9sA54dA5M0Ve7xI8MasSWXTeS7Du kQQw== X-Gm-Message-State: AOAM531Fhjs0zxPmbCaFagXjmFoqUYnZwgcpzPOW8cgr22+b7dHgNJWC wTsz56YzPpyAthc2cgYK/UX7Vw== X-Received: by 2002:a17:902:9a44:b029:d3:f10c:944a with SMTP id x4-20020a1709029a44b02900d3f10c944amr5044928plv.11.1604629722925; Thu, 05 Nov 2020 18:28:42 -0800 (PST) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id m13sm3703040pjr.30.2020.11.05.18.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 18:28:42 -0800 (PST) From: AKASHI Takahiro To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, ben.chuang@genesyslogic.com.tw, greg.tu@genesyslogic.com.tw, AKASHI Takahiro Subject: [RFC PATCH v3.1 15/27] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 6 Nov 2020 11:27:14 +0900 Message-Id: <20201106022726.19831-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201106022726.19831-1-takahiro.akashi@linaro.org> References: <20201106022726.19831-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a UHS-II version of sdhci's set_timeout() operation. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro --- drivers/mmc/host/sdhci-uhs2.c | 85 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + 2 files changed, 86 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 1eca89359351..d9e98c097bfe 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -178,6 +178,91 @@ void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, } EXPORT_SYMBOL_GPL(sdhci_uhs2_set_power); +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, + u8 *dead_lock) +{ + u8 count; + unsigned int cmd_res_timeout, dead_lock_timeout, current_timeout; + + /* + * If the host controller provides us with an incorrect timeout + * value, just skip the check and use 0xE. The hardware may take + * longer to time out, but that's much better than having a too-short + * timeout value. + */ + if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) { + *cmd_res = 0xE; + *dead_lock = 0xE; + return 0xE; + } + + /* timeout in us */ + cmd_res_timeout = 5 * 1000; + dead_lock_timeout = 1 * 1000 * 1000; + + /* + * Figure out needed cycles. + * We do this in steps in order to fit inside a 32 bit int. + * The first step is the minimum timeout, which will have a + * minimum resolution of 6 bits: + * (1) 2^13*1000 > 2^22, + * (2) host->timeout_clk < 2^16 + * => + * (1) / (2) > 2^6 + */ + count = 0; + current_timeout = (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < cmd_res_timeout) { + count++; + current_timeout <<= 1; + if (count >= 0xF) + break; + } + + if (count >= 0xF) { + DBG("%s: Too large timeout 0x%x requested for CMD_RES!\n", + mmc_hostname(host->mmc), count); + count = 0xE; + } + *cmd_res = count; + + count = 0; + current_timeout = (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < dead_lock_timeout) { + count++; + current_timeout <<= 1; + if (count >= 0xF) + break; + } + + if (count >= 0xF) { + DBG("%s: Too large timeout 0x%x requested for DEADLOCK!\n", + mmc_hostname(host->mmc), count); + count = 0xE; + } + *dead_lock = count; + + return count; +} + +static void __sdhci_uhs2_set_timeout(struct sdhci_host *host) +{ + u8 cmd_res, dead_lock; + + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock); + cmd_res |= dead_lock << SDHCI_UHS2_TIMER_CTRL_DEADLOCK_SHIFT; + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL); +} + +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) +{ + __sdhci_set_timeout(host, cmd); + + if (host->mmc->flags & MMC_UHS2_SUPPORT) + __sdhci_uhs2_set_timeout(host); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); + /*****************************************************************************\ * * * MMC callbacks * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 3c19d8e44c36..efe70577bc74 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -213,5 +213,6 @@ void sdhci_uhs2_dump_regs(struct sdhci_host *host); void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, unsigned short vdd); +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); #endif /* __SDHCI_UHS2_H */ -- 2.28.0