From patchwork Fri Nov 17 11:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Shih X-Patchwork-Id: 166125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp460299vqn; Fri, 17 Nov 2023 03:33:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXgTlgSoeM+weOj//tF8OvADXL8tVTDmox8qSoBXxIHJ1oADMfzFFKYnS1q3wJEszgolbL X-Received: by 2002:a05:6a20:4294:b0:188:f3d:ea35 with SMTP id o20-20020a056a20429400b001880f3dea35mr1557893pzj.50.1700220825314; Fri, 17 Nov 2023 03:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700220825; cv=none; d=google.com; s=arc-20160816; b=di9qGbG+mziU6AA1tqZJ7MdcqXQ6x7TiRjWnP+ESRSbL+UvewJd3aoCGRgc9abHfD5 oAu/FLiBYlWBmLEzTQiZplYYKgiZDq7zjk1rrQOtwbQHO7wNItnZTivO26wkAcFNAoWo XzRA+Z8WAFSQg0WDk5QobGrx+teUgqwNqoi9kQ5QQUv0PMHGjS8grwZeg3UnD5sSJyM5 wrnwAZI3WJYrQWJHioW5qNll2V9qiVor367moHC1/nXgNWgZIg2igoJbDvD4WflAPtzB ufow6+cAs+Dzcbzh2o5s5Ih9H57jZHu/k+689qDQIS6W7Gn2FdX7qQ8BiaAWOr0hE7d9 A6+w== 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=dJwiZzyyuf7v6cs+ljTqumzmP5sE6MhjQFfT9zkmMoQ=; fh=y5fk6vguAkbcel7KoRWpitGO8B8BpGYTQpzSdaI/dY4=; b=bctGZAE7qbLnZ0hpoG3KNPxtKiINLyaGAPO9Kk3kEsmRtwMxOOpGBOQ21ET31omq+4 UixIHEDSNOqTxwb8/fo8k1SGILKYeDRWyc+yU+HA/Jw3MyWn24Ku/rYuaFFuY2S093I0 IPflaZ5V/OyodSDymIKvmn5oKzzRE4fcvxQ0e97UGSRFViCl20ryiYIv+9ETtzPAS2N+ /LRmNTT0MBcqRj7cDXfq/Nc+6QQUeBBlfWdbsRwXs2m3i4bq7f9UYJnwUl/pCPpucQLf I5sJvpp5Jl+fElUum9jUDGQR0Up7QXBSVMqMTAVNDEAAA4i4zZ4B143eAWZymELii5u+ QLRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dhPnJfPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id o11-20020a056a0015cb00b0068a557febfcsi1789495pfu.111.2023.11.17.03.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 03:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dhPnJfPr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9F67F8294B7E; Fri, 17 Nov 2023 03:33:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345908AbjKQLdf (ORCPT + 30 others); Fri, 17 Nov 2023 06:33:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346015AbjKQLdK (ORCPT ); Fri, 17 Nov 2023 06:33:10 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51E1AD4D; Fri, 17 Nov 2023 03:32:39 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3b2f4a5ccebso1179778b6e.3; Fri, 17 Nov 2023 03:32:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700220758; x=1700825558; 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=dJwiZzyyuf7v6cs+ljTqumzmP5sE6MhjQFfT9zkmMoQ=; b=dhPnJfPrMEyqRVqqWmKsFqCxAbP9bSi9gxC0PQ2gxIoZy5C9jvG7cZj2NU7LLFQ+m/ i5CGhVdawNQ0AQ+yMxml0bnBZNRMZuXbUQ7uvnKWDxBNfhfAwJ/uyYFp6wDgZmVn/JCL I/LK2LUZnYcx87jELf4/r+fAin48CVWOx+UI4RY+T+1ITH9cESd2Jf2Gq+zcVCUgOYBs CkKaE66svE4oHRy/GaY9w0ulu1OGoZNdPtKgXBtL9wS0k6wEHiar07IietoZZZeGGwnK h/CE+Ky6uv62Cki1ZQnVVCldWJdSIMbi2OVPvKNSLcEUEp8TZqXan7cmnAwJlrOn2C1j Rx8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700220758; x=1700825558; 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=dJwiZzyyuf7v6cs+ljTqumzmP5sE6MhjQFfT9zkmMoQ=; b=a3uMDKgeiEasiLuMt4phauQ1YvS1198aNN5Oq7pG1kLrEp4Q0XmIZvjz/3C9hIUzQ+ iz64wJ1uaMTZXN1slncHGRYxmrDYmutVAKMq6NB/iViiq1igvpmPoV20jdYd4F06LqVh tRJEKYrZewJgt2J67l2xalL+1I6M3D2aHoVfEt0qFRGzACY9bQyYXEmXSA6d4GIVDQlw emtjapqR/p0ABy8GFcTSDvdqSWietFPVWEwMjn/OQIlKSPzMek6gewrw2bgQjjux9fn9 4M97Jole6akRurftza5BRWq2NqNY3wcBOJlBaR4PtlomFK5Ilh0WzZgSJxiXDGju2ib7 MmrA== X-Gm-Message-State: AOJu0YwLgejnXW5odxjUJ3X2mUqEUOkMXEV9MA3q9jv9jNC3j5tVnaQG JjvS4kv8LsPg4+1IlXxhCQI= X-Received: by 2002:aca:2206:0:b0:3af:8ed3:d7a3 with SMTP id b6-20020aca2206000000b003af8ed3d7a3mr20384941oic.54.1700220758555; Fri, 17 Nov 2023 03:32:38 -0800 (PST) Received: from localhost.localdomain (2001-b400-e286-d458-bc89-d4cd-bd42-ffb5.emome-ip6.hinet.net. [2001:b400:e286:d458:bc89:d4cd:bd42:ffb5]) by smtp.gmail.com with ESMTPSA id u2-20020a631402000000b005b4b70738e5sm1229224pgl.8.2023.11.17.03.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 03:32:38 -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 V13 13/21] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 17 Nov 2023 19:31:41 +0800 Message-Id: <20231117113149.9069-14-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231117113149.9069-1-victorshihgli@gmail.com> References: <20231117113149.9069-1-victorshihgli@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 03:33:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782810751967119294 X-GMAIL-MSGID: 1782810751967119294 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 Acked-by: Adrian Hunter --- 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 7d5070f58d00..5a79dd29aa38 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" @@ -142,6 +143,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 (sdhci_uhs2_mode(host)) + __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 8253d50f7852..ccf4e1834c2d 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -175,9 +175,11 @@ #define SDHCI_UHS2_VENDOR_PTR 0xE8 struct sdhci_host; +struct mmc_command; void sdhci_uhs2_dump_regs(struct sdhci_host *host); bool sdhci_uhs2_mode(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 */