From patchwork Sun Jul 25 04:25:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 12397973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80D75C4338F for ; Sun, 25 Jul 2021 04:28:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5138660E77 for ; Sun, 25 Jul 2021 04:28:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5138660E77 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Subject:From: References:In-Reply-To:Message-Id:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=X6HTLkxwgFUGTfGhHXQaelkMeD82RUhmS5nbrViKNu8=; b=i2fAH4DeVhaMJBya73MfDAK0Aq /5UlqX6nakE6BvHtZA555QEwWM06KPXqFwKFz/OL+I4KBJNRiTKPeioRc5aUWaQQGRf2SqhvQu5CM WjZQcRgZhU9HwNUMXbCNr5x0JRGJL46XCRiXxipK4svwmQrZBeVp2CtCpyAtgvjuVR4SjIYbOzvJi m8Yk4AnD4qjQGqyKl12BTxf3iJgWSCVR05lcuAptl3w8wrbcuE04aIus+e1ZnUFVG68eNNLVuysHk kDUooh6utRDA5oMRyJSqbYK/WHesHv9Ea6kpjCU8slqGdJIuUm+LVwqrlJPIaFlyGMo1aitMtuoQo FecovJ5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Vi6-0088zf-5x; Sun, 25 Jul 2021 04:25:54 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7VhX-0088vW-7a for linux-arm-kernel@lists.infradead.org; Sun, 25 Jul 2021 04:25:22 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4GXVMw2gk7zQ4; Sun, 25 Jul 2021 06:25:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1627187116; bh=n4tm9awV3n8UWCA4HHMvEDV8yXB7gzSUySmWHxD0+vs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=DX3eQvrVT8ICox9QlqW7PUFy/rzo0ebRf53PlNHU6soL7KwQresQvwAGU27L/gHsj 0G+nBF1seKdAXZJpcE1uKgjals/C3tK6IRWp6SZyjcvxTu2FXjLfUmjfJBsj3J6v2K KYRVf2h+rssZI4wGr3VSP03OUzOaQ5CPM/EOLNRr+xcy5Hpi/zUp6q4KMVqCN+B8V7 xWly68niUwUnd4sybkhgONKpCaocVuxDpE9lqFoe/I6Q9V1f3nfOSlyGtvTex2beto wbOtg2gn8HfdgxpxbYoT7hEqICih/sTV6qy+F4C8hgVTdF5Y2lc+6oLZBfRa3HuyGi EsHK+QR9bHzTw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.2 at mail Date: Sun, 25 Jul 2021 06:25:16 +0200 Message-Id: <2fea541c7e679dcda64b5a128bf8ff301fdf1af7.1627186831.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 1/5] mmc: sdhci: fix base clock usage in preset value MIME-Version: 1.0 To: Ulf Hansson , Kevin Liu , Suneel Garapati Cc: Adrian Hunter , Chris Ball , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michal Simek X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_212519_557340_C38F37DA X-CRM114-Status: GOOD ( 10.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fixed commit added an unnecessary read of CLOCK_CONTROL. The value read is overwritten for programmable clock preset, but is carried over for divided clock preset. This can confuse sdhci_enable_clk() if the register has enable bits set for some reason at time time of clock calculation. Remove the read. Quoting Al Cooper: sdhci_brcmstb_set_clock() assumed that sdhci_calc_clk() would always return the divider value without the enable set, so this fixes a case for DDR52 where the enable was not being cleared when the divider value was changed. Cc: stable@kernel.vger.org Fixes: 52983382c74f ("mmc: sdhci: enhance preset value function") Signed-off-by: Michał Mirosław Acked-by: Al Cooper --- v3: updated commit message v2: removed truncated sentence from commitmsg Signed-off-by: Michał Mirosław --- drivers/mmc/host/sdhci.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index aba6e10b8605..c7438dd13e3e 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1857,7 +1857,6 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, if (host->preset_enabled) { u16 pre_val; - clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); pre_val = sdhci_get_preset_value(host); div = FIELD_GET(SDHCI_PRESET_SDCLK_FREQ_MASK, pre_val); if (host->clk_mul && From patchwork Sun Jul 25 04:25:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 12397969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07F50C4338F for ; Sun, 25 Jul 2021 04:27:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC04060E77 for ; Sun, 25 Jul 2021 04:27:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BC04060E77 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Subject:From: References:In-Reply-To:Message-Id:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Osh9rcxHK0dJvlML00ZxHgodR4orTyvb/xpBVz8rMeU=; b=3DJEO/XWPSfDQr2APMGzJvEgtH cOzbzIa4DhugxpXfJqqYF7xd7p0P1I+BUFL8YYFMssjQAOmGy2ySeqyj74u1Tu8kWeHwaEruuFKHq WZCq+bT5gUKPBPj/DeotLsVmSmZGQDkVvwelINFya60cJGUcz5GegdjPQi+rnFE4fU9E9Z6ijWe5E I9kZGrZLZoSISuZTKCj1rSG/AHzHBxY+FI/nP4PO/BBQDqHbatshAua4ieHnmcXA2x30QheLhgFZi PcawVfOCS4Xa60JGmjnmieWA3y5F2arR3GoPEN6KFm4HJRlc6JdwVrI/IKjcRXjTngGZQmAcAHQXa X/7W203A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Vhb-0088wy-6H; Sun, 25 Jul 2021 04:25:23 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7VhX-0088vX-7X for linux-arm-kernel@lists.infradead.org; Sun, 25 Jul 2021 04:25:20 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4GXVMw5tY7zWx; Sun, 25 Jul 2021 06:25:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1627187116; bh=heq1Nrofd2BQKP+4WIO5NxEzHqe39kUnYWVEiXv6rW0=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Y2HEpcdbQreqce7yHTVI3ebiKNVIzLSd9s+J5JhHu3tcvjwdZLY4EvvA0WwK+/+sB qfTG6E+50eN+Ob1RTN3FMADZaRm9/S9ubrKsG9orZXDIZzgaW1jgmn4/XsQSDqMEyz cGAFONr1HY85Ws+inBjEPlmF1ilI4NSBBTZXlS7nZwx1qQLkvmnf1WU0BZeO/TDzHM ENEN+ij5NQZgGvS6Puv8+zYXD4T/I57MHbqZ6tVBTuCOxsufRgHqEbZqM8DggRJDKZ cllyTO325ExBTeNI74PvO95xi/N7gEy3Js2fF3dZvDmuog7VLNr9TW7OJh9OeYBM0W i6QKrRsxdnuKA== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.2 at mail Date: Sun, 25 Jul 2021 06:25:16 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 2/5] mmc: sdhci: always obey programmable clock config in preset value MIME-Version: 1.0 To: Kevin Liu , Suneel Garapati , Ulf Hansson Cc: Adrian Hunter , Chris Ball , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Michal Simek X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_212519_557334_AA03F57A X-CRM114-Status: GOOD ( 10.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When host controller uses programmable clock presets but doesn't advertise programmable clock support, we can only guess what frequency it generates. Let's at least return correct SDHCI_PROG_CLOCK_MODE bit value in this case. Fixes: 52983382c74f ("mmc: sdhci: enhance preset value function") Signed-off-by: Michał Mirosław --- v3: added a comment for this case v2: no changes --- drivers/mmc/host/sdhci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index c7438dd13e3e..3ab60e7f936b 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1859,11 +1859,14 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, pre_val = sdhci_get_preset_value(host); div = FIELD_GET(SDHCI_PRESET_SDCLK_FREQ_MASK, pre_val); - if (host->clk_mul && - (pre_val & SDHCI_PRESET_CLKGEN_SEL)) { + if (pre_val & SDHCI_PRESET_CLKGEN_SEL) { clk = SDHCI_PROG_CLOCK_MODE; real_div = div + 1; clk_mul = host->clk_mul; + if (!clk_mul) { + /* The clock frequency is unknown. Assume undivided base. */ + clk_mul = 1; + } } else { real_div = max_t(int, 1, div << 1); } From patchwork Sun Jul 25 04:25:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 12397967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A62CC432BE for ; Sun, 25 Jul 2021 04:27:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC23260F23 for ; Sun, 25 Jul 2021 04:27:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CC23260F23 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Subject:From: References:In-Reply-To:Message-Id:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vRCSi1onH4D3npmAH92p1ylOLa3xzg8mYFGX748TYjc=; b=12RpPFtk9bMxubA04OOQvCN2uR kOb6c7TzrttKfDZl9mdKvG6zE86s61y1QlqBfdMkJgFq9W9RFkLfERB70bI5I6b2U1iimFEZzLLwC m57FCWNejFfDu4yuiG2X22Mnh2ZYuwKy9zf0LfZ00sz52aBztMSgkQW1JGuTnHQptPpCzOypPN5ow piu3BMqdCsVuCFrBju9B3tUsoR+8PPU/nrYLWB3raM7rlANBjrVv4/giwRgidf5tJrS87UTBaiOdX xhxzYmPmSNkBD/4yhtnpnV/QqNA/+2MLXoKdxV9V24TKhaPxkHJytAYdPYD3f17rKmEBeQtC3XSVZ WCAkI+nA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Vhv-0088y4-Ne; Sun, 25 Jul 2021 04:25:43 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7VhX-0088vb-7Z for linux-arm-kernel@lists.infradead.org; Sun, 25 Jul 2021 04:25:22 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4GXVMx3YbFzX8; Sun, 25 Jul 2021 06:25:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1627187117; bh=j17GcKmlnE8dNVYM8Ye986ikoYzsb1uGAdqmnn6MswM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Rj4CcHtMtjgf2wc4QRN5AIBbNP6v9zKW6AS5crkSmit8XZtmxkWPCciRMUo2OjMdx seKWPXzqj49NnHmLUwQt8GVDyo+F2zj7EIPF8lDeKnT+eW8CcjwK2/KP2LI7lqYoNp w8iwNzJFOc10kTxQDrNJrJJhZeSUb624fqPHrmVYHrrJMoFhaN2nUuNGgI7ML9enmK V+dq2ePDhn7zSddB+ptraTD62PRN1jV/KY9dtpzA9gNnqcXrZRyBgaUlgN40kqc/Uw FXlLgdGloAh/x/Aqy7k1AWkMp0PosZ19SAhxPiqk5b+PUsH8cR2wFMo7v7sswLH5z/ kFIZWcB3qL9HQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.2 at mail Date: Sun, 25 Jul 2021 06:25:16 +0200 Message-Id: <198e2af8eb70212cdd6d85d7fb8ff547e295fa77.1627186831.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 3/5] mmc: sdhci: fix SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN MIME-Version: 1.0 To: Suneel Garapati , Kevin Liu , Ulf Hansson Cc: Adrian Hunter , Chris Ball , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Michal Simek X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_212519_560069_C1EA58E8 X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix returned clock rate for SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN case. This fixes real_div value that was calculated as 1 (meaning no division) instead of 2 with the quirk enabled. Cc: stable@kernel.vger.org Fixes: d1955c3a9a1d ("mmc: sdhci: add quirk SDHCI_QUIRK_CLOCK_DIV_ZERO_BROKEN") Signed-off-by: Michał Mirosław --- v3: updated commit message v2: no changes --- drivers/mmc/host/sdhci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 3ab60e7f936b..0993f7d0ce8e 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1903,9 +1903,12 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, if (!host->clk_mul || switch_base_clk) { /* Version 3.00 divisors must be a multiple of 2. */ - if (host->max_clk <= clock) + if (host->max_clk <= clock) { div = 1; - else { + if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) + && host->max_clk <= 25000000) + div = 2; + } else { for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; div += 2) { if ((host->max_clk / div) <= clock) @@ -1914,9 +1917,6 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, } real_div = div; div >>= 1; - if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) - && !div && host->max_clk <= 25000000) - div = 1; } } else { /* Version 2.00 divisors must be a power of 2. */ From patchwork Sun Jul 25 04:25:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 12397975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A68BDC4338F for ; Sun, 25 Jul 2021 04:28:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 77B5960BD3 for ; Sun, 25 Jul 2021 04:28:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 77B5960BD3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Subject:From: References:In-Reply-To:Message-Id:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3k0nErt/QRpL4VSEjKDaKdxe/qcPPWliaddzlQ42NTY=; b=oVQ/7sCtShdAuhrqLmX2R8iItG RM734MvRgsIChGkxdCCFZWIIDK0ESzhP7unyP8DmbdlWhF2lmUfjZGpNT0Vfze/yjKa+T+S3Tgew0 bKZXZNVp2jXjI8ydv8gdYGxSLz2VIuZR37hVyDM9UkpvtT2vmllhXZe/N5ESclrHUYTBGmWzqWrR/ ckZjEa4KBqRRN8npHbQulWzO5S2liBzbmkbZJcZnvcTgXbXdr5/CuDu3XbXixH2QI/HdCpFN12FNk /CuQy/0W8ylSeV1487qzE6wjkMGLg6R6sDeRcBBV1v2TBpUOgNauDwEs2kNR4vp65eq9xNVmmPnMZ nExTm2Fw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7ViG-00890W-Gx; Sun, 25 Jul 2021 04:26:04 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7VhX-0088ve-J4 for linux-arm-kernel@lists.infradead.org; Sun, 25 Jul 2021 04:25:22 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4GXVMy0Y69zht; Sun, 25 Jul 2021 06:25:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1627187118; bh=JnzVxee475iBfiNH+BjjYvpu8JabHTVnK4JSdiy7rOQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=rxz6wYb4WRweGi8n2z7mteZ+sk6ZvxhBTnsecurPUOGrxAcb8GQqn2ftNMDUXaYqk fcOUb82fqcaS08c1Wn8RzGIj4AprqWahdu4lxOPav04pkdE/oGMGGktVy93LmutLw2 Ymd5GCHWXDXJFlklha6aRZBC3U0/6tOsIF/L+WO3wjYUaaTNnFSKArBT270VmyOE4x jvxVxfk2lJKCIB3id8TlMkfmAN2pTQRTKLHIxObRSev3IiTDORniCB9wutEPz8AP4H En1MTJPnt/Y0Yuolycs6yC43ofz9J42v/b1e9oi5ZWz/iJrD6wGsGtsYj3vO5h1Ss9 HoNsitbusJDWQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.2 at mail Date: Sun, 25 Jul 2021 06:25:17 +0200 Message-Id: <0b1e358630223252dffa02f2dd50470e44e294ba.1627186831.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 4/5] mmc: sdhci: move SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN frequency limit MIME-Version: 1.0 To: Kevin Liu , Suneel Garapati , Ulf Hansson Cc: Michal Simek , linux-arm-kernel@lists.infradead.org, Adrian Hunter , Chris Ball , linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_212520_015246_F073F841 X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Push handling of clock frequency dependence for SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN quirk to the drivers that use it. Signed-off-by: Michał Mirosław Reported-by: kernel test robot Reported-by: kernel test robot --- v3: rebased on v5.14-rc2 and reworded commitmsg v2: reworded commitmsg --- drivers/mmc/host/sdhci-of-arasan.c | 11 ++++------- drivers/mmc/host/sdhci-of-dwcmshc.c | 9 ++++++--- drivers/mmc/host/sdhci.c | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c index 737e2bfdedc2..f2a6441ab540 100644 --- a/drivers/mmc/host/sdhci-of-arasan.c +++ b/drivers/mmc/host/sdhci-of-arasan.c @@ -452,8 +452,7 @@ static const struct sdhci_ops sdhci_arasan_cqe_ops = { static const struct sdhci_pltfm_data sdhci_arasan_cqe_pdata = { .ops = &sdhci_arasan_cqe_ops, .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, - .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN, + .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN, }; #ifdef CONFIG_PM_SLEEP @@ -1118,7 +1117,6 @@ static const struct sdhci_pltfm_data sdhci_arasan_pdata = { .ops = &sdhci_arasan_ops, .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, }; @@ -1141,7 +1139,6 @@ static const struct sdhci_pltfm_data sdhci_keembay_emmc_pdata = { SDHCI_QUIRK_32BIT_DMA_SIZE | SDHCI_QUIRK_32BIT_ADMA_SIZE, .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN | SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 | SDHCI_QUIRK2_STOP_WITH_TC | SDHCI_QUIRK2_BROKEN_64_BIT_DMA, @@ -1156,7 +1153,6 @@ static const struct sdhci_pltfm_data sdhci_keembay_sd_pdata = { SDHCI_QUIRK_32BIT_DMA_SIZE | SDHCI_QUIRK_32BIT_ADMA_SIZE, .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN | SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | SDHCI_QUIRK2_STOP_WITH_TC | SDHCI_QUIRK2_BROKEN_64_BIT_DMA, @@ -1171,7 +1167,6 @@ static const struct sdhci_pltfm_data sdhci_keembay_sdio_pdata = { SDHCI_QUIRK_32BIT_DMA_SIZE | SDHCI_QUIRK_32BIT_ADMA_SIZE, .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN | SDHCI_QUIRK2_HOST_OFF_CARD_ON | SDHCI_QUIRK2_BROKEN_64_BIT_DMA, }; @@ -1197,7 +1192,6 @@ static struct sdhci_arasan_of_data intel_lgm_sdxc_data = { static const struct sdhci_pltfm_data sdhci_arasan_zynqmp_pdata = { .ops = &sdhci_arasan_ops, .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, }; @@ -1502,6 +1496,9 @@ static int sdhci_arasan_add_host(struct sdhci_arasan_data *sdhci_arasan) bool dma64; int ret; + if (sdhci_pltfm_clk_get_max_clock(host) <= 25000000) + host->quirks2 |= SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN; + if (!sdhci_arasan->has_cqe) return sdhci_add_host(host); diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index bac874ab0b33..9bca7cf1d1da 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -283,14 +283,14 @@ static const struct sdhci_pltfm_data sdhci_dwcmshc_rk3568_pdata = { .ops = &sdhci_dwcmshc_rk3568_ops, .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, - .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | - SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN, + .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN; }; static int dwcmshc_rk3568_init(struct sdhci_host *host, struct dwcmshc_priv *dwc_priv) { - int err; + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct rk3568_priv *priv = dwc_priv->priv; + int err; priv->rockchip_clks[0].id = "axi"; priv->rockchip_clks[1].id = "block"; @@ -318,6 +318,9 @@ static int dwcmshc_rk3568_init(struct sdhci_host *host, struct dwcmshc_priv *dwc sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_TXCLK); sdhci_writel(host, 0, DWCMSHC_EMMC_DLL_STRBIN); + if (sdhci_pltfm_clk_get_max_clock(pltfm_host) <= 25000000) + host->quirks2 |= SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN; + return 0; } diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 0993f7d0ce8e..cfa314e659bc 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1905,8 +1905,7 @@ u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, /* Version 3.00 divisors must be a multiple of 2. */ if (host->max_clk <= clock) { div = 1; - if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) - && host->max_clk <= 25000000) + if (host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) div = 2; } else { for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; From patchwork Sun Jul 25 04:25:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 12397977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA184C4338F for ; Sun, 25 Jul 2021 04:28:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A24260E77 for ; Sun, 25 Jul 2021 04:28:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9A24260E77 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:MIME-Version:Subject:From: References:In-Reply-To:Message-Id:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=gznRK26TDECYMpsb7XvLq4x1Y8r7wFN08Wn8N3rK67c=; b=R9w/ZswsZfqcf48MzMRFyvQB+M L8/Hfsp3y8okyMAI9Ahjxj/h4N92CZD+o95wtddkeut6e0EJfbLxB9sUj4YB0EmTqV7oRr0TygnFW WRNJgjuOdaS/yXdM2XLS+QkQbtAujRfchl1drG4UVBMh5HELZOjEwcesXKBDHGFWYnCkKJ9ZCQB36 deHyHNGqVudsLh+UsXNFMQVbE/I0soZwKLapKJyp2nUo42vUIDcXiDs9NKwGVUPIlFq2BlJlfqJP/ BNXVekW4yb/qAt7W8tfLesBDUr76zkvkqkipAWoeB33p09FLCXkyXZ1ocZsmyFZn0b5AUf6P6vO0U Ey4y6JzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7ViR-00891y-SB; Sun, 25 Jul 2021 04:26:16 +0000 Received: from rere.qmqm.pl ([91.227.64.183]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7Vha-0088wv-Eo for linux-arm-kernel@lists.infradead.org; Sun, 25 Jul 2021 04:25:24 +0000 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4GXVMy2jlHzwg; Sun, 25 Jul 2021 06:25:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1627187118; bh=7aLr1DcvH9n5VyrTP2IaJJvojTP4sCPPtY6zdO/RZU4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=r0gQ6/bSunpdszUfoQuNTcVee1+16h6NzOT8R42K8/M7tmbIW9SSYZdaoN6hK2Iul ZzT4iWpFbi317/8LKsc4s/6pdoWne+aeleBHPc132bIgkRBg/9YkM1TQeQLsGf7Ikk FDg6uEYLu4oKXaD/v47SMAu+7e8JN00b0GEsOP4JL7B2iAx9iUQ7d6eo07ZYRLZksF Lj9eHf16vt7WbnanwuQvBBqfHZ18e2I4xBglZuT92xGie9rfidbdYGfIQUB6IuHXTl KRkN1FnFAk1ZY111zi4iqDhAi/D7CY2DVtr/3z45SVE92xBmY0Pf2wpglNLsb2ryh6 MR+Frz3u98UNw== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.2 at mail Date: Sun, 25 Jul 2021 06:25:18 +0200 Message-Id: In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v3 5/5] mmc: sdhci: simplify v2/v3+ clock calculation MIME-Version: 1.0 To: Kevin Liu , Suneel Garapati , Ulf Hansson Cc: Adrian Hunter , Chris Ball , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, Michal Simek X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210724_212522_903286_388E3B6C X-CRM114-Status: GOOD ( 18.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For base clock setting, SDHCI V2 differs from V3+ only in allowed divisor values. Remove the duplicate version of code and reduce indentation levels. We can see now, that 'real_div' can't be zero, so the check is removed. While at it, replace divisor search loops with divide-and-clamp to make the code even more readable. Signed-off-by: Michał Mirosław --- v3: squashed div-conversion and deduplication patches to avoid code churn v2: no changes --- drivers/mmc/host/sdhci.c | 124 ++++++++++++++++++--------------------- drivers/mmc/host/sdhci.h | 4 +- 2 files changed, 58 insertions(+), 70 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index cfa314e659bc..90bda4150083 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1848,88 +1848,76 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host) u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, unsigned int *actual_clock) { - int div = 0; /* Initialized for compiler warning */ - int real_div = div, clk_mul = 1; + unsigned int div, real_div, clk_mul = 1; u16 clk = 0; - bool switch_base_clk = false; - if (host->version >= SDHCI_SPEC_300) { - if (host->preset_enabled) { - u16 pre_val; + if (clock == 0) + return clk; + + if (host->preset_enabled) { + /* Only version 3.00+ can have preset_enabled */ + u16 pre_val; + + pre_val = sdhci_get_preset_value(host); + div = FIELD_GET(SDHCI_PRESET_SDCLK_FREQ_MASK, pre_val); + if (!(pre_val & SDHCI_PRESET_CLKGEN_SEL)) + goto base_div_set; + + clk = SDHCI_PROG_CLOCK_MODE; + real_div = div + 1; + clk_mul = host->clk_mul; + if (!clk_mul) { + /* The clock frequency is unknown. Assume undivided base. */ + clk_mul = 1; + } + + goto clock_set; + } + + /* + * Check if the Host Controller supports Programmable Clock + * Mode. + */ + if (host->version >= SDHCI_SPEC_300 && host->clk_mul) { + div = DIV_ROUND_UP(host->max_clk * host->clk_mul, clock); + if (div <= SDHCI_MAX_DIV_SPEC_300 / 2 + 1) { + /* + * Set Programmable Clock Mode in the Clock + * Control register. + */ + clk = SDHCI_PROG_CLOCK_MODE; + clk_mul = host->clk_mul; + real_div = div--; - pre_val = sdhci_get_preset_value(host); - div = FIELD_GET(SDHCI_PRESET_SDCLK_FREQ_MASK, pre_val); - if (pre_val & SDHCI_PRESET_CLKGEN_SEL) { - clk = SDHCI_PROG_CLOCK_MODE; - real_div = div + 1; - clk_mul = host->clk_mul; - if (!clk_mul) { - /* The clock frequency is unknown. Assume undivided base. */ - clk_mul = 1; - } - } else { - real_div = max_t(int, 1, div << 1); - } goto clock_set; } /* - * Check if the Host Controller supports Programmable Clock - * Mode. + * Divisor is too big for requested clock rate. + * Fall back to the base clock. */ - if (host->clk_mul) { - for (div = 1; div <= 1024; div++) { - if ((host->max_clk * host->clk_mul / div) - <= clock) - break; - } - if ((host->max_clk * host->clk_mul / div) <= clock) { - /* - * Set Programmable Clock Mode in the Clock - * Control register. - */ - clk = SDHCI_PROG_CLOCK_MODE; - real_div = div; - clk_mul = host->clk_mul; - div--; - } else { - /* - * Divisor can be too small to reach clock - * speed requirement. Then use the base clock. - */ - switch_base_clk = true; - } - } + } - if (!host->clk_mul || switch_base_clk) { - /* Version 3.00 divisors must be a multiple of 2. */ - if (host->max_clk <= clock) { - div = 1; - if (host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) - div = 2; - } else { - for (div = 2; div < SDHCI_MAX_DIV_SPEC_300; - div += 2) { - if ((host->max_clk / div) <= clock) - break; - } - } - real_div = div; - div >>= 1; - } + div = DIV_ROUND_UP(host->max_clk, clock); + + if (div == 1 && (host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN)) + div = 2; + + if (host->version >= SDHCI_SPEC_300) { + /* Version 3.00 divisors must be a multiple of 2. */ + div = min(div, SDHCI_MAX_DIV_SPEC_300); + div = DIV_ROUND_UP(div, 2); } else { /* Version 2.00 divisors must be a power of 2. */ - for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) { - if ((host->max_clk / div) <= clock) - break; - } - real_div = div; - div >>= 1; + div = min(div, SDHCI_MAX_DIV_SPEC_200); + div = roundup_pow_of_two(div) / 2; } +base_div_set: + real_div = div * 2 + !div; + clock_set: - if (real_div) - *actual_clock = (host->max_clk * clk_mul) / real_div; + *actual_clock = (host->max_clk * clk_mul) / real_div; clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN) << SDHCI_DIVIDER_HI_SHIFT; diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 074dc182b184..a3fa70d91410 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -284,8 +284,8 @@ * End of controller registers. */ -#define SDHCI_MAX_DIV_SPEC_200 256 -#define SDHCI_MAX_DIV_SPEC_300 2046 +#define SDHCI_MAX_DIV_SPEC_200 256u +#define SDHCI_MAX_DIV_SPEC_300 2046u /* * Host SDMA buffer boundary. Valid values from 4K to 512K in powers of 2.