From patchwork Tue Jan 23 06:28:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 190739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp152321dyi; Mon, 22 Jan 2024 22:32:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEOLvLBOeFQolxpz7vc4xntoTwKb5wnDHbxrwH2ufLmpz11vzs6u2A/7ZbX/BPiigtRH1I X-Received: by 2002:a0c:aad7:0:b0:680:b72b:7d7f with SMTP id g23-20020a0caad7000000b00680b72b7d7fmr344901qvb.127.1705991556117; Mon, 22 Jan 2024 22:32:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705991556; cv=pass; d=google.com; s=arc-20160816; b=cJo4mShcEB/aDD6xjaVuymnzHBAzZWXxuFRDHUIhzKfuywIRZBBdBAuBe9A+l/JNQx 4fdrXJFBkpxGssnFiQazVwlyZORfD8aThpg/NcotwlWHChTl9u6I5xYtq6ELDgjCaCvz quLPAOFYknZe2Oc4sJC8BT4BRJmDolqUA93Up/WRAT1KR4qn3w0gar5OCPjOOS9e1qTh 3tHTEzHknFj6lGaSUkQTFag04h1glexEeMQgbuI6p1ZW7hzsh53tuQDt4i/MfkYmHkia a2CJrf7llod9VU8HJJIbgktc7pYI/ZjXVdiCADYY9fyKZ7eU2Sx3mYv15dmSuG5YWJ0c 9XQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CVVK8PYza3PZw2RU4jEmSGH0po6YzhMl/TtdR6VRTik=; fh=y5fk6vguAkbcel7KoRWpitGO8B8BpGYTQpzSdaI/dY4=; b=sgdL0K2D5NXyQPx38RGd+mSBdXTAu9Dx30Zl6PCgLXoqN7F18JEwChsq32b5/aeBY2 3Mmu5/gRDgJ83QJMf1IIoNtRkLAHiJBImSmNDasw1k3Cx1RtnU/QWjj+a8uxrgnSwAZr mf1eFeV/3Uguo9Y6kBu9Xmm3nLc0I/w3ccmRR9VN+PX7cksh7WfJFFVUFzrniWhNWoFy Ou2f4EHq7rPYrN8b0Q/2OEdL+oWDenKnjN6aYe6aMKc/e3latAiT3m2fDsdHIQl1TbRH ZYToNBz5XRwuZXet1Ql9chiTKYcOaY17jQruOQrpdh7Iyi/5KWLu963s6PE+SX84SYGW mP2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IWjzyMbW; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34783-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34783-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l25-20020a0c9799000000b0068182baee1asi7365800qvd.407.2024.01.22.22.32.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:32:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34783-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IWjzyMbW; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-34783-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34783-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D66421C22ACB for ; Tue, 23 Jan 2024 06:32:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B176A56B68; Tue, 23 Jan 2024 06:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IWjzyMbW" Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FA89524A3; Tue, 23 Jan 2024 06:29:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991363; cv=none; b=rpPDSMetgMM+1Iz834ccXmXMNKtoshDo2kjGQqCQqdvfn89ajwyaIzTVtolQV3QL08bsOATEoGF2flVGfYoCLvt+Lw/FtRytEqFLZzBSxtoa/FDvRwP1+rJNv2VibF5LoBTQvw/arm/rJz2GYMaffKOxJnm2DGRZLVPbwEAkxeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705991363; c=relaxed/simple; bh=PVJAmPMR8F0OrJe+kXHRPDYfd5+hxfvCB2BI4WrJFxw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z0epwaZvI+DLNYcGrld/uSZeus8kaPKditnxQDp6rphbZ0lrZqIWOKAiccBCgjyh80uEmZ8EAOknykhcwwPhij+UOHik5WZVU4atbXi5ixA0quawIQ7qF8HNhF9f4iAvq66knEyHOXyT0qHCO0SEdBHJrgUgp6HnwTfUPjhgTFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IWjzyMbW; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6db599d5cb8so2996720b3a.0; Mon, 22 Jan 2024 22:29:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705991362; x=1706596162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CVVK8PYza3PZw2RU4jEmSGH0po6YzhMl/TtdR6VRTik=; b=IWjzyMbWWDunO3siVK82t1CoqH+KHbzJODCBTI597JXhOkEr7675EZ7VA7Yk02o36H JbIWelDjSJhg3f9TLnDDZMDcdN941f3rKdc8nTSVKpMl6z+KSRy1mHfyh5iV8pFJZiN/ j0JrC4/xPe03Cry5ATlgMAEY/Li5gy3Eo1GAeGhK40AfIfcZV+IXMgk4E7tU4W4zkbDu FxkX8ZYsQrPcdqmOtJ4LqTCv2YoWuzHuBXroGOoul8ANNaQRsuSq3dhCj3UzLiYBG19O 5Xkcqo1FusEkV5wqyNh4tKDLoWXAOaKyzgdHV+W5vRl4nL+txIL82lKsNfJP2NQQZ9VI XEBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705991362; x=1706596162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CVVK8PYza3PZw2RU4jEmSGH0po6YzhMl/TtdR6VRTik=; b=MPcn2TIcdSCq0N9XRuS3Bbur+a+am6sgzTCXcHNx7bPluQbxtuwPuSIYuj5BgQQawi bZR0JaJktCiaNd14seBPaK8JL+XspQeTrJtimrXX7BeuaLknj7p1OQyZ/WhCqbfskoLQ JkNeovgpzrBxVL5fZNO0kCA+hlkPBmT4jSq5Ki6zbLnxDLi6nPcMbnF8dv56fh28EWX+ PbjJCBBTtwGH2QfVQDULbSkkv2wI3SNBU0Qz4XJZI08gNqJGguMcJ8mOZJ5xhISKId80 DblJPbvPC/M4auEyJ0HQwwIBBA6hfMhyp1bO4vAajqi/efqDJaZXeN+NaF3w/lCD3vG1 BOmw== X-Gm-Message-State: AOJu0YyXQQror9P74wabZHKpHoCVXUoVP0SJIVsNHyz//y8+FsJcsCuJ 10EuIW2JtxWR88cm9j45jxSjVL3hXO5xNEcVMmD6h8MZyrhYnfgIIlHqpXveUgk= X-Received: by 2002:a05:6a00:3ccd:b0:6db:ea97:bcd with SMTP id ln13-20020a056a003ccd00b006dbea970bcdmr1905149pfb.41.1705991361706; Mon, 22 Jan 2024 22:29:21 -0800 (PST) Received: from localhost.localdomain (2001-b400-e2ac-a4c6-7d2b-d8b3-ed27-1f50.emome-ip6.hinet.net. [2001:b400:e2ac:a4c6:7d2b:d8b3:ed27:1f50]) by smtp.gmail.com with ESMTPSA id l10-20020a056a00140a00b006d9b2694b0csm10595188pfu.200.2024.01.22.22.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 22:29:21 -0800 (PST) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Victor Shih , Ben Chuang , Victor Shih Subject: [PATCH V14 13/21] mmc: sdhci-uhs2: add set_timeout() Date: Tue, 23 Jan 2024 14:28:19 +0800 Message-Id: <20240123062827.8525-14-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240123062827.8525-1-victorshihgli@gmail.com> References: <20240123062827.8525-1-victorshihgli@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788861802100670111 X-GMAIL-MSGID: 1788861802100670111 From: Victor Shih This is a UHS-II version of sdhci's set_timeout() operation. Use sdhci_uhs2_set_timeout() to set and calculate the timeout time. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_set_timeout(). Updates in V13: - Modify comment message. Updates in V8: - Initialization be combined with declaration and realigned in sdhci_calc_timeout_uhs2(). - Forward declare struct mmc_command in sdhci_uhs2.h. Updates in V6: - Use GENMASK() and FIELD_PREP() in some case. - Use sdhci_uhs2_mode() to simplify code. - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 + 2 files changed, 74 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 4fe106e2ba8c..a2df109b49d8 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "sdhci.h" #include "sdhci-uhs2.h" @@ -134,6 +135,77 @@ static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, un } } +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, u8 *dead_lock) +{ + /* timeout in us */ + unsigned int dead_lock_timeout = 1 * 1000 * 1000; + unsigned int cmd_res_timeout = 5 * 1000; + unsigned int current_timeout; + u8 count; + + /* + * 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 |= FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock); + 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 (mmc_card_uhs2(host->mmc)) + __sdhci_uhs2_set_timeout(host); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); + /*****************************************************************************\ * * * Driver init/exit * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index caaf9fba4975..089a6c0cabda 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -175,8 +175,10 @@ #define SDHCI_UHS2_VENDOR_PTR 0xE8 struct sdhci_host; +struct mmc_command; void sdhci_uhs2_dump_regs(struct sdhci_host *host); void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); #endif /* __SDHCI_UHS2_H */