Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp754449rwd; Thu, 15 Jun 2023 01:21:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bebyupFuagqQiN+Bu2zzu+9jW30OigwTE4YqTdRzOKnAGC21Htvtg+qiUx71hT2Pe+eiT X-Received: by 2002:a17:907:168f:b0:94f:449e:75db with SMTP id hc15-20020a170907168f00b0094f449e75dbmr18167897ejc.52.1686817308285; Thu, 15 Jun 2023 01:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686817308; cv=none; d=google.com; s=arc-20160816; b=pE6XjwqiAcb8TFZwOYfRs+6Zl0bOYKWDc6skx1BkPZ+YXiY9oRsyGisXx+SgzMtDk2 uIWPrcbxBO3SZkc5yxAMsr3apOurOER+rPbfyFhDVJeWwPLr/C4l8cVN7IoGqskXb5WM mlxs/Dg9UQG+7dX12RUg2Fyco4TyWBhAEqcnwLS3zgURPEog9xBUekcAt1cRz5G9eHcv GZGpcAlrYfAuIaGPo1KrJ5f5gAnxh0dr5Du596gJ1TibL81ble7ZiVNQV/u1Z6QDiZ7m 6K4LK8GYpBBejiDn6NIw598AklW/R2auEI9Fc40Sac16F2dGKqC04jmDXT7YceoZ+FQS zytg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Zw3zcxm+tSNXMALLNMETfkuZB5PYayZDTauwewfC3CE=; b=GKiS++IjOqztXYnNAzlr6cFx2c+QB/VLxsUd2YrZRwjLJ47OQuinxS2pLmWkPKIR7w 5srClirDVy3kwyYWzkmCNXPrW/U13Ul0hjS2ShczIxAhCyBKZNhFxNlcgwwk1z32K6Sb N6/bUT34uJcTg/inM9QT22ij1qm8r0r8pTzlqiRXdcdE94oBhwZuFcP+QAlmZYm6ViSL 5GzbY76WYwNoylW/yr7YEtm2hHdr6pyVaq2qe19FhfLuodvbfJh2BMAG0YUKL3qcs+N4 vYo8L2M9HFo9V8dzxTj1x85eGlxfljk6XqrYFU2hO8nKULF3851xrdcNStH160apAAg+ qBjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LsZ2eID+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020a1709061b0800b009746375dc3esi8332692ejg.485.2023.06.15.01.21.23; Thu, 15 Jun 2023 01:21:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LsZ2eID+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245108AbjFOHrc (ORCPT + 99 others); Thu, 15 Jun 2023 03:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245171AbjFOHrW (ORCPT ); Thu, 15 Jun 2023 03:47:22 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0496DE69; Thu, 15 Jun 2023 00:47:09 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id A548E6606F5A; Thu, 15 Jun 2023 08:47:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1686815228; bh=INbAkaTkqa0MJxcHxqulN2VnoNlZzC16MoB2u0RY2YI=; h=From:To:Cc:Subject:Date:From; b=LsZ2eID+Ql8YnSljnLZg+w7emxAC5F45c/bvjMsh+4YhC3FOIKmvLSE13s89x4MXh aPaSGRx7SGV0X7Xf0Y1jo/HxG8XoLVMHTjUkuKc1hO6yGU/bYtiFB0vlF3zx2MbAsv M9jItEzs3N705jPLRFv29XgKwoBFkU5jF+FrhyqNQI3MwE/upOo6JP+yE49jpD31VY pCZvVPO1//s9x7+jENzES18fZDwlDCNWkAMcwQuu7LcqZnIGXAl5JFFjG+Jlk7y193 f2KBwbpcQSZm/OF5MQp5OnEP9wnksCzF9aPwNRamswiKLZs7IrY+Oq6S+H6LSES5EN dKWDgxeUJdzog== From: AngeloGioacchino Del Regno To: chaotian.jing@mediatek.com Cc: ulf.hansson@linaro.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, wenst@chromium.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com Subject: [PATCH] mmc: mtk-sd: Set src_clk rate/parent for accurate clock rate Date: Thu, 15 Jun 2023 09:47:01 +0200 Message-Id: <20230615074701.34063-1-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 The MediaTek MSDC controller has an internal divider for the input (source) clock, but that may not be enough: as there's no multiplier it is impossible to achieve certain clock rates depending on the source clock rate. This is especially seen with the SDR104 mode, where a clock source typically of 200MHz or 400MHz will make us able to achieve 200MHz (depending on the SoC's MSDCPLL, this will be more likely ~199MHz) instead of the optimal 208MHz. In order to solve this issue and achieve an accurate clock rate for all modes, call clk_set_rate() on the source clock, so that the clock framework will either change the PLL's rate or, more likely, will switch the clock parent to the "best" one. Since some platforms share one MSDCPLL for multiple MMC/SD "MSDC" controllers, making sure that shared PLLs won't get their rate changed (and devices over/underclocked) is obviously done in the SoC-specific clock drivers, starting with commit f235f6ae59e5 ("clk: mediatek: Remove CLK_SET_PARENT from all MSDC core clocks"). As an example, on MT8195, an accurate frequency will be achieved by reparenting of the source clock from msdcpll div2 to univpll div6-div2, giving out exactly 208000000Hz. Signed-off-by: AngeloGioacchino Del Regno --- drivers/mmc/host/mtk-sd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index 8ce864169986..e0217783d22d 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -886,6 +886,13 @@ static void msdc_set_mclk(struct msdc_host *host, unsigned char timing, u32 hz) return; } + /* + * Select the best clock rate for src_clk: this is done in order + * to save power and/or achieve an accurate rate for DDR52/SDR104. + */ + clk_set_rate(host->src_clk, hz); + host->src_clk_freq = clk_get_rate(host->src_clk); + flags = readl(host->base + MSDC_INTEN); sdr_clr_bits(host->base + MSDC_INTEN, flags); if (host->dev_comp->clk_div_bits == 8) -- 2.40.1