From patchwork Thu Nov 3 13:49:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13030011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 472FAC4332F for ; Thu, 3 Nov 2022 13:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiKCNuH (ORCPT ); Thu, 3 Nov 2022 09:50:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiKCNuG (ORCPT ); Thu, 3 Nov 2022 09:50:06 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D07D95B8; Thu, 3 Nov 2022 06:50:06 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id bs21so2878026wrb.4; Thu, 03 Nov 2022 06:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=A37ZMyjpowuBe5MIQCPdhqkQNV0cmCgOXOGo/5OfEzI=; b=FW0aTI7nEnBdu0iXyT1ZmpklKbrCtLZZguo/PWau6OjNRKqe6nZsE4H8rvx9b5Tus5 wPMVC7ZxTWE8VqxFK1lOKImJwhQ5vzYTyEiYb619yHBDdcwrB2a9UMAZMmKoZc8ghn2Z OsXqDyIo19ypM3/IBE6c+nkFpXRFSJdmOSxRaMaM14kAoZYGzzX5O76oEjALfacSfQcw SVUv2IhFWhtCnS1MEnirlQVX15oPbbOlK7fx8qflHM4X35zRwX0IWUaM0oT6zWTaaWuc hkPNiGB0cO5YQ9aGuCqUj4nbvqdCWrERoXgsgZd49AGUPgUWIHBTtUm0sXL5HjQuZyI2 dItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=A37ZMyjpowuBe5MIQCPdhqkQNV0cmCgOXOGo/5OfEzI=; b=4cay0xNQqvYBLxKIPBiFf+GjpcZOwWbsfDosI9wccnl64/r7GDqbmkYtxpdGNQmjI3 whkrJZ5JbANVgx/M55xmfYrxXJ+gJScKtM1YWgcJQaahGc2keQ/t3vnNhRfJZgH5m9aq xBfyZnela6ybHkL+d4p/4QyPNtIjXfPndm5JJUxB4Dd1asnbfNHUJ+CQPW4iVGunByjL flq0KhpZtXoTNWvgp91uv+c6CAOEEEmB37Kv/ibqDkUxTzRzj7oPQJwWCKwq1Hhr0PPB qq3W1VoJ6npu+5SPZgnskGKc/eVazH88Fbygs0x2+kIq6xoNDS79TNj5LByZ1IoNtRbX r2sw== X-Gm-Message-State: ACrzQf3q3CgirsGyktTJgyAnzISUD01nhvqniud2fomsABzvYsWoqjIf EKP9Y/9bL93Ucr/VbShud9g2vr3g8xQ= X-Google-Smtp-Source: AMsMyM7AhTVOSV+Ga94VoTuFy4oB9Ti5NKQx5CTsfoWVYAb0mTQIMkTiwF3qvlj8qgyipv9+1AwDIg== X-Received: by 2002:a5d:4e88:0:b0:236:590:f5a9 with SMTP id e8-20020a5d4e88000000b002360590f5a9mr17658547wru.126.1667483404655; Thu, 03 Nov 2022 06:50:04 -0700 (PDT) Received: from localhost.localdomain (93-42-71-18.ip85.fastwebnet.it. [93.42.71.18]) by smtp.googlemail.com with ESMTPSA id bt12-20020a056000080c00b00236576c8eddsm957414wrb.12.2022.11.03.06.50.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:50:04 -0700 (PDT) From: Christian Marangi To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v2 1/4] clk: qcom: gcc-ipq6018: drop redundant F define Date: Thu, 3 Nov 2022 14:49:41 +0100 Message-Id: <20221103134944.23275-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221103134944.23275-1-ansuelsmth@gmail.com> References: <20221103134944.23275-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The same exact F frequency table entry is defined in clk-rcg.h Drop the redundant define to cleanup code. Signed-off-by: Christian Marangi --- drivers/clk/qcom/gcc-ipq6018.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/clk/qcom/gcc-ipq6018.c b/drivers/clk/qcom/gcc-ipq6018.c index 3f9c2f61a5d9..350ead66914c 100644 --- a/drivers/clk/qcom/gcc-ipq6018.c +++ b/drivers/clk/qcom/gcc-ipq6018.c @@ -26,8 +26,6 @@ #include "clk-regmap-mux.h" #include "reset.h" -#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } - enum { P_XO, P_BIAS_PLL, From patchwork Thu Nov 3 13:49:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13030012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75A62C43219 for ; Thu, 3 Nov 2022 13:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbiKCNuJ (ORCPT ); Thu, 3 Nov 2022 09:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230254AbiKCNuI (ORCPT ); Thu, 3 Nov 2022 09:50:08 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91EA595B8; Thu, 3 Nov 2022 06:50:07 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v1so2837512wrt.11; Thu, 03 Nov 2022 06:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=THbX1EhgVaNh83+sx5ydTUKPbkRpoGl3oIFhFRQm/vs=; b=ajsjzDRCTwC4tLwlV6oQlpoQBt6VGNxiinVyYG876NsWH5cpgnWZSQcX/ZBAxixFSq FiiTWm4D4rVmAW6h9SbBWQhuFZmWq5Utq27tZtWj8gEW9ktcf6i64kdMnDHz+0Gjrgs6 pkjLe0hF+XqcBKTD/s614z5Pl+DMH5sE1W9MFqj1IiufRizNXIp+UeLrJzvZ5i2qY6Nk 4DTpePodRvS/BoAFNaUmF5EnDdeQdSHZej2wzQiEUta+U4+m2V4l7wi+BzPtyuj9Dx9V EKMUz/R11LZcS8AbL3TnR3P0yA7r6ATvpKd0NkIoe16lD+CIRiHCQ1puy2mFj91sJ0de Coig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=THbX1EhgVaNh83+sx5ydTUKPbkRpoGl3oIFhFRQm/vs=; b=UdRGLJsQKE9Y6JmT131C4nrkmmbWrrePgayk5Xl5XRtDCjGloETAdFsO5cBSjfBwn5 ZgCVJ6lOeDMsLFjyUb1+bxBZ0zZPGjgaqEgc9gCNNQ4aVh3AZHZq5OTBJMvyFDe0caBw maPrBZbux7vZDMH3dr/k6udMrq3PGJO7YPPBysQPuLoIN1rpSHWuga73l+dWyta727z9 v/8sDRWJWlIEy0UZDCVnef0DK6voKKoBBB8pK8lqasqCrZuhJ4dCPiNVEkLp0P2vBQJr P8RmgzEKGuS+I382QMdd+l90SjmKmhj0pCTKZjv8X3tBurkQDkscQ6rHOF9iwy1Y1qdv Yw7g== X-Gm-Message-State: ACrzQf0TsayYXCioglKHdq+oKSa/CiDqHboDqAsakM4R/PYCrqDO9NHm 07P31VufhnPV0h/lAi0oVF/6mtP+nlo= X-Google-Smtp-Source: AMsMyM4yIgJaQxba4QvDvKfMkGAxJxaOLKXNeC2uHrFj5CPn929hQ920/v7wPgWne6gNSqTfyRPw4Q== X-Received: by 2002:a5d:65cf:0:b0:236:9119:be3 with SMTP id e15-20020a5d65cf000000b0023691190be3mr18412969wrw.602.1667483405892; Thu, 03 Nov 2022 06:50:05 -0700 (PDT) Received: from localhost.localdomain (93-42-71-18.ip85.fastwebnet.it. [93.42.71.18]) by smtp.googlemail.com with ESMTPSA id bt12-20020a056000080c00b00236576c8eddsm957414wrb.12.2022.11.03.06.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:50:05 -0700 (PDT) From: Christian Marangi To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH v2 2/4] clk: qcom: gcc-sdm660: drop redundant F define Date: Thu, 3 Nov 2022 14:49:42 +0100 Message-Id: <20221103134944.23275-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221103134944.23275-1-ansuelsmth@gmail.com> References: <20221103134944.23275-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The same exact F frequency table entry is defined in clk-rcg.h Drop the redundant define to cleanup code. Signed-off-by: Christian Marangi --- drivers/clk/qcom/gcc-sdm660.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/clk/qcom/gcc-sdm660.c b/drivers/clk/qcom/gcc-sdm660.c index db918c92a522..6afce8e42ede 100644 --- a/drivers/clk/qcom/gcc-sdm660.c +++ b/drivers/clk/qcom/gcc-sdm660.c @@ -25,8 +25,6 @@ #include "reset.h" #include "gdsc.h" -#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } - enum { P_XO, P_SLEEP_CLK, From patchwork Thu Nov 3 13:49:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13030014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B133DC433FE for ; Thu, 3 Nov 2022 13:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231304AbiKCNuL (ORCPT ); Thu, 3 Nov 2022 09:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiKCNuK (ORCPT ); Thu, 3 Nov 2022 09:50:10 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4CD295B2; Thu, 3 Nov 2022 06:50:08 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id p13-20020a05600c468d00b003cf8859ed1bso1234844wmo.1; Thu, 03 Nov 2022 06:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=CyBu08uMqErM+zzJyPRDJRWX5ryfOT/RoKB9om6pnjA=; b=awoHeQm77Q2sEwFmeaP/zTCfE4p3UeAyEhRPoVQGkiPDQsE8QAnSk9J0Kl/PkKu86l ooHjplSVxdl6D9QiynlkaHEoq6tAcc/6f683gmHjX/kwraDu99XoxTqZdZSb6f2QjCbf FJZHvGMj0fjaOaR8VE6mDoQtmP86CRLMYyV/HuMdJccH4XcG+/+wkfbIOsN9K3WpBqpW ET+Uprgk1LBvQXbmgnKQMoNPI309LyYpy2S6R0KZ7r0oo6UZWCKANjk/aYdBeTEpGzZC k5ZJ+vAknNsLiYiwNnZsqT0LYL7AtSJEZA8bMO22oYyHVSb3YQU3toTAfmhKdnGvQPAH QBFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=CyBu08uMqErM+zzJyPRDJRWX5ryfOT/RoKB9om6pnjA=; b=zH756Lx8q/KBC9Eq5KtuUH9jGMLmntbNWHcbBUlZG5enEBA5vUkgMjRzdo+73lUVjc It2yvKLcFdAx1q9hgdiVnCsZjjK/fxMB+YcDFp49Pivvj5JWD3VnLICZMCxWNoT2w0Pa PHyliE4QuH2UGVuhrEiWtAiF1pZU+gcxak0QPHOk4wpoDdv3/6CWFU/fZE2En3TcNCDK 985dv8wboozutd7uB3xg8XnBURmlzzfppDjJBIt30OO8eRrUKtlWbSUxBrUQiFQ8vFJ8 SmI03WItCD+K6W47wdlO1/TEg/iBdWTEAXn3tFlNAykCa1h9RuyEkhJqMbmeLhfAYi05 qpkg== X-Gm-Message-State: ACrzQf3UpN/khcRgosHsWRokVWWnEM/GS0etO9G5QS12r0SuFaoXhEvY G3VqjUPcIEBrFQG+CDKJ/Eo= X-Google-Smtp-Source: AMsMyM5e5TzekpmgBPAXruk8u090hzwn+qYrYB8f9WNqNhrE+txPgc5FO9oa7pn9FQO/1jr444m6fA== X-Received: by 2002:a05:600c:6890:b0:3c6:c323:878d with SMTP id fn16-20020a05600c689000b003c6c323878dmr29585056wmb.87.1667483407046; Thu, 03 Nov 2022 06:50:07 -0700 (PDT) Received: from localhost.localdomain (93-42-71-18.ip85.fastwebnet.it. [93.42.71.18]) by smtp.googlemail.com with ESMTPSA id bt12-20020a056000080c00b00236576c8eddsm957414wrb.12.2022.11.03.06.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:50:06 -0700 (PDT) From: Christian Marangi To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , Robert Marko Subject: [PATCH v2 3/4] clk: qcom: clk-rcg2: introduce support for multiple conf for same freq Date: Thu, 3 Nov 2022 14:49:43 +0100 Message-Id: <20221103134944.23275-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221103134944.23275-1-ansuelsmth@gmail.com> References: <20221103134944.23275-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Some RCG frequency can be reached by multiple configuration. We currently declare multiple configuration for the same frequency but that is not supported and always the first configuration will be taken. These multiple configuration are needed as based on the current parent configuration, it may be needed to use a different configuration to reach the same frequency. To handle this introduce 2 new macro, FM and C. - FM is used to declare an empty freq_tbl with just the frequency and an array of confs to insert all the config for the provided frequency. - C is used to declare a fre_conf where src, pre_div, m and n are provided. The driver is changed to handle this special freq_tbl and select the correct config by calculating the final rate and deciding based on the one that is less different than the requested one. Tested-by: Robert Marko Signed-off-by: Christian Marangi --- drivers/clk/qcom/clk-rcg.h | 14 ++++++- drivers/clk/qcom/clk-rcg2.c | 84 +++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 10 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h index 01581f4d2c39..18f4f7b59f36 100644 --- a/drivers/clk/qcom/clk-rcg.h +++ b/drivers/clk/qcom/clk-rcg.h @@ -7,7 +7,17 @@ #include #include "clk-regmap.h" -#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } +#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n), 0, NULL } + +#define FM(_f, _confs) { .freq = (_f), .confs_num = ARRAY_SIZE(_confs), .confs = (_confs) } +#define C(s, h, m, n) { (s), (2 * (h) - 1), (m), (n) } + +struct freq_conf { + u8 src; + u8 pre_div; + u16 m; + u16 n; +}; struct freq_tbl { unsigned long freq; @@ -15,6 +25,8 @@ struct freq_tbl { u8 pre_div; u16 m; u16 n; + int confs_num; + const struct freq_conf *confs; }; /** diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 76551534f10d..7d3b59ec2b50 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -209,11 +209,60 @@ clk_rcg2_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) return __clk_rcg2_recalc_rate(hw, parent_rate, cfg); } +static void +clk_rcg2_select_conf(struct clk_hw *hw, struct freq_tbl *f_tbl, + const struct freq_tbl *f, unsigned long req_rate) +{ + unsigned long best_rate = 0, parent_rate, rate; + const struct freq_conf *conf, *best_conf; + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + struct clk_hw *p; + int index, i; + + /* Search in each provided config the one that is near the wanted rate */ + for (i = 0, conf = f->confs; i < f->confs_num; i++, conf++) { + index = qcom_find_src_index(hw, rcg->parent_map, conf->src); + if (index < 0) + continue; + + p = clk_hw_get_parent_by_index(hw, index); + if (!p) + continue; + + parent_rate = clk_hw_get_rate(p); + rate = calc_rate(parent_rate, conf->n, conf->m, conf->n, conf->pre_div); + + if (rate == req_rate) { + best_conf = conf; + break; + } + + if (abs(req_rate - rate) < abs(best_rate - rate)) { + best_rate = rate; + best_conf = conf; + } + } + + /* + * Very unlikely. + * Force the first conf if we can't find a correct config. + */ + if (unlikely(i == f->confs_num)) + best_conf = f->confs; + + /* Apply the config */ + f_tbl->src = best_conf->src; + f_tbl->pre_div = best_conf->pre_div; + f_tbl->m = best_conf->m; + f_tbl->n = best_conf->n; +} + static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f, struct clk_rate_request *req, enum freq_policy policy) { unsigned long clk_flags, rate = req->rate; + struct freq_tbl f_tbl; struct clk_hw *p; struct clk_rcg2 *rcg = to_clk_rcg2(hw); int index; @@ -232,7 +281,15 @@ static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f, if (!f) return -EINVAL; - index = qcom_find_src_index(hw, rcg->parent_map, f->src); + f_tbl = *f; + /* + * A single freq may be reached by multiple configuration. + * Try to find the bast one if we have this kind of freq_table. + */ + if (f->confs) + clk_rcg2_select_conf(hw, &f_tbl, f, rate); + + index = qcom_find_src_index(hw, rcg->parent_map, f_tbl.src); if (index < 0) return index; @@ -242,18 +299,18 @@ static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f, return -EINVAL; if (clk_flags & CLK_SET_RATE_PARENT) { - rate = f->freq; - if (f->pre_div) { + rate = f_tbl.freq; + if (f_tbl.pre_div) { if (!rate) rate = req->rate; rate /= 2; - rate *= f->pre_div + 1; + rate *= f_tbl.pre_div + 1; } - if (f->n) { + if (f_tbl.n) { u64 tmp = rate; - tmp = tmp * f->n; - do_div(tmp, f->m); + tmp = tmp * f_tbl.n; + do_div(tmp, f_tbl.m); rate = tmp; } } else { @@ -261,7 +318,7 @@ static int _freq_tbl_determine_rate(struct clk_hw *hw, const struct freq_tbl *f, } req->best_parent_hw = p; req->best_parent_rate = rate; - req->rate = f->freq; + req->rate = f_tbl.freq; return 0; } @@ -357,6 +414,7 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate, { struct clk_rcg2 *rcg = to_clk_rcg2(hw); const struct freq_tbl *f; + struct freq_tbl f_tbl; switch (policy) { case FLOOR: @@ -372,7 +430,15 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate, if (!f) return -EINVAL; - return clk_rcg2_configure(rcg, f); + f_tbl = *f; + /* + * A single freq may be reached by multiple configuration. + * Try to find the best one if we have this kind of freq_table. + */ + if (f->confs) + clk_rcg2_select_conf(hw, &f_tbl, f, rate); + + return clk_rcg2_configure(rcg, &f_tbl); } static int clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate, From patchwork Thu Nov 3 13:49:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13030015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AE4BC43219 for ; Thu, 3 Nov 2022 13:50:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231360AbiKCNuM (ORCPT ); Thu, 3 Nov 2022 09:50:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbiKCNuK (ORCPT ); Thu, 3 Nov 2022 09:50:10 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A53CE1A; Thu, 3 Nov 2022 06:50:09 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id m7-20020a05600c090700b003cf8a105d9eso1219625wmp.5; Thu, 03 Nov 2022 06:50:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=UYevc0/VBCj9wBQRWlQ/9Q4O5TfPY8fJu+BvNTU/yG0=; b=d6OJjLYkTVYyj0VjESkE5EWtHiqvjt0kEB6y4IcY77JYyXS8Cup8RaMvRDnHOpxbuo qZP+vizPDK6fdps12oaywwU12KIKc0tuOvkUyAZul6wIbilxp0khBz1Yxhk0+E+lx7N0 Z3+99s0lgMYRiABw7VCPiVb/n3XN1D+q/blvLsKNl0KooCakYtysUGBgbLLm9yMYKoRt P0slatV+1Ltu5yG2zPhN85umCFptMKDj+yvRMFdNebJ8XvqLVcL4Hd9HgramtTo4HhRr m+dWOa/xNLX5/7THOGCWVkA7yCRysyzS2P+hAS4hb4hPJJBKvHSsHman05tp74IxcMsF CUFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UYevc0/VBCj9wBQRWlQ/9Q4O5TfPY8fJu+BvNTU/yG0=; b=bpUu/62kN4vZu8dGrvTWdXQZA+sWGGigyCezg8vw5MpU1nHY7qTX5lVGIBgfrB/WJw q6g/PgCEuUnipPdpTdhRH/2UOIggxu+vOHF49Oru/0grNzYzw7kl9D2em7Tcpg1FlAVC z3DtVWAOl3N7TdQ9DArcpuHaLWuCJ2o+2NVfPUdWBzT6UeDFi/djZaYJ5HI0CtL5vhY5 g+mQ35zua1Ldb/yBsyDTPdrVsTzjSu1xvW9bjiNDh705hDlH9cu5GGor/gqNWrVSwSEE KUzNoQnVh+uDVuVToG6AlPfgasKqifwPPJORX1YKA+yB7qTt1QfHbK9rSOBQAzX6I0Q9 ICvQ== X-Gm-Message-State: ACrzQf0QqBk3DuI1T5pITJD9TS7AA2M/E970HIZ7NLzFNUSC3FElP6Wq jCtRqi0LnRtnZNvaWUl2Qu6dUTUH5GA= X-Google-Smtp-Source: AMsMyM4/0Te6wr50IuSG1FJMDHBgSFNQGAvNEOPXZCEAfIgiGu6IIqEGLirF2PjMzHvLqkN7xp5pnA== X-Received: by 2002:a05:600c:a04:b0:3b4:f20e:63f4 with SMTP id z4-20020a05600c0a0400b003b4f20e63f4mr19678312wmp.201.1667483408237; Thu, 03 Nov 2022 06:50:08 -0700 (PDT) Received: from localhost.localdomain (93-42-71-18.ip85.fastwebnet.it. [93.42.71.18]) by smtp.googlemail.com with ESMTPSA id bt12-20020a056000080c00b00236576c8eddsm957414wrb.12.2022.11.03.06.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 06:50:07 -0700 (PDT) From: Christian Marangi To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Michael Turquette , Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , Robert Marko Subject: [PATCH v2 4/4] clk: qcom: gcc-ipq8074: rework nss_port5/6 clock to multiple conf Date: Thu, 3 Nov 2022 14:49:44 +0100 Message-Id: <20221103134944.23275-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221103134944.23275-1-ansuelsmth@gmail.com> References: <20221103134944.23275-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Rework nss_port5/6 to use the new multiple configuration implementation and correctly fix the clocks for these port under some corner case. This is particularly relevant for device that have 2.5G or 10G port connected to port5 or port 6 on ipq8074. As the parent are shared across multiple port it may be required to select the correct configuration to accomplish the desired clock. Without this patch such port doesn't work in some specific ethernet speed as the clock will be set to the wrong frequency as we just select the first configuration for the related frequency instead of selecting the best one. Tested-by: Robert Marko # ipq8074 Qnap QHora-301W Signed-off-by: Christian Marangi --- drivers/clk/qcom/gcc-ipq8074.c | 64 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/clk/qcom/gcc-ipq8074.c b/drivers/clk/qcom/gcc-ipq8074.c index 42d185fe19c8..02d04a552b78 100644 --- a/drivers/clk/qcom/gcc-ipq8074.c +++ b/drivers/clk/qcom/gcc-ipq8074.c @@ -1787,13 +1787,21 @@ static struct clk_regmap_div nss_port4_tx_div_clk_src = { }, }; +static const struct freq_conf ftbl_nss_port5_rx_clk_src_25[] = { + C(P_UNIPHY1_RX, 12.5, 0, 0), + C(P_UNIPHY0_RX, 5, 0, 0), +}; + +static const struct freq_conf ftbl_nss_port5_rx_clk_src_125[] = { + C(P_UNIPHY1_RX, 2.5, 0, 0), + C(P_UNIPHY0_RX, 1, 0, 0), +}; + static const struct freq_tbl ftbl_nss_port5_rx_clk_src[] = { F(19200000, P_XO, 1, 0, 0), - F(25000000, P_UNIPHY1_RX, 12.5, 0, 0), - F(25000000, P_UNIPHY0_RX, 5, 0, 0), + FM(25000000, ftbl_nss_port5_rx_clk_src_25), F(78125000, P_UNIPHY1_RX, 4, 0, 0), - F(125000000, P_UNIPHY1_RX, 2.5, 0, 0), - F(125000000, P_UNIPHY0_RX, 1, 0, 0), + FM(125000000, ftbl_nss_port5_rx_clk_src_125), F(156250000, P_UNIPHY1_RX, 2, 0, 0), F(312500000, P_UNIPHY1_RX, 1, 0, 0), { } @@ -1829,13 +1837,21 @@ static struct clk_regmap_div nss_port5_rx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port5_tx_clk_src_25[] = { + C(P_UNIPHY1_TX, 12.5, 0, 0), + C(P_UNIPHY0_TX, 5, 0, 0), +}; + +static struct freq_conf ftbl_nss_port5_tx_clk_src_125[] = { + C(P_UNIPHY1_TX, 2.5, 0, 0), + C(P_UNIPHY0_TX, 1, 0, 0), +}; + static const struct freq_tbl ftbl_nss_port5_tx_clk_src[] = { F(19200000, P_XO, 1, 0, 0), - F(25000000, P_UNIPHY1_TX, 12.5, 0, 0), - F(25000000, P_UNIPHY0_TX, 5, 0, 0), + FM(25000000, ftbl_nss_port5_tx_clk_src_25), F(78125000, P_UNIPHY1_TX, 4, 0, 0), - F(125000000, P_UNIPHY1_TX, 2.5, 0, 0), - F(125000000, P_UNIPHY0_TX, 1, 0, 0), + FM(125000000, ftbl_nss_port5_tx_clk_src_125), F(156250000, P_UNIPHY1_TX, 2, 0, 0), F(312500000, P_UNIPHY1_TX, 1, 0, 0), { } @@ -1871,13 +1887,21 @@ static struct clk_regmap_div nss_port5_tx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port6_rx_clk_src_25[] = { + C(P_UNIPHY2_RX, 5, 0, 0), + C(P_UNIPHY2_RX, 12.5, 0, 0), +}; + +static struct freq_conf ftbl_nss_port6_rx_clk_src_125[] = { + C(P_UNIPHY2_RX, 1, 0, 0), + C(P_UNIPHY2_RX, 2.5, 0, 0), +}; + static const struct freq_tbl ftbl_nss_port6_rx_clk_src[] = { F(19200000, P_XO, 1, 0, 0), - F(25000000, P_UNIPHY2_RX, 5, 0, 0), - F(25000000, P_UNIPHY2_RX, 12.5, 0, 0), + FM(25000000, ftbl_nss_port6_rx_clk_src_25), F(78125000, P_UNIPHY2_RX, 4, 0, 0), - F(125000000, P_UNIPHY2_RX, 1, 0, 0), - F(125000000, P_UNIPHY2_RX, 2.5, 0, 0), + FM(125000000, ftbl_nss_port6_rx_clk_src_125), F(156250000, P_UNIPHY2_RX, 2, 0, 0), F(312500000, P_UNIPHY2_RX, 1, 0, 0), { } @@ -1913,13 +1937,21 @@ static struct clk_regmap_div nss_port6_rx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port6_tx_clk_src_25[] = { + C(P_UNIPHY2_TX, 5, 0, 0), + C(P_UNIPHY2_TX, 12.5, 0, 0), +}; + +static struct freq_conf ftbl_nss_port6_tx_clk_src_125[] = { + C(P_UNIPHY2_TX, 1, 0, 0), + C(P_UNIPHY2_TX, 2.5, 0, 0), +}; + static const struct freq_tbl ftbl_nss_port6_tx_clk_src[] = { F(19200000, P_XO, 1, 0, 0), - F(25000000, P_UNIPHY2_TX, 5, 0, 0), - F(25000000, P_UNIPHY2_TX, 12.5, 0, 0), + FM(25000000, ftbl_nss_port6_tx_clk_src_25), F(78125000, P_UNIPHY2_TX, 4, 0, 0), - F(125000000, P_UNIPHY2_TX, 1, 0, 0), - F(125000000, P_UNIPHY2_TX, 2.5, 0, 0), + FM(125000000, ftbl_nss_port6_tx_clk_src_125), F(156250000, P_UNIPHY2_TX, 2, 0, 0), F(312500000, P_UNIPHY2_TX, 1, 0, 0), { }