From patchwork Fri Oct 21 18:06:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 6921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp839320wrr; Fri, 21 Oct 2022 11:15:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EY6hf+6TculomDLFBnPlcqhd7vjq7oJuhK1cMNYstpVOwh4TGNz0B94DSUU6plAxhHEF4 X-Received: by 2002:a17:90b:4c48:b0:20d:5c55:b8a8 with SMTP id np8-20020a17090b4c4800b0020d5c55b8a8mr24089154pjb.207.1666376148704; Fri, 21 Oct 2022 11:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666376148; cv=none; d=google.com; s=arc-20160816; b=HmfezIA1Alm2K1XBjZjBYfnPcO+J4Py+PWTdVzBtZs74cbgc/DaP4bYk0XUjbX+SPr KBvxMvrJNkWqOe+VDJP58e2C9nWGUMye/FdaIuG7XSKudCWToN2Bq8UB6rgIb0j2Nl4U Qc+IuJzIlPGlHdZy4b5tDlByBiKcPYRrOghBZ1qCAHk71TqN1wA9sTnRwkJsPhfUjrHR NcwpAYAf5/h4aCoQJEasqlMln4fgD8QZfC7sgtBpVyJTWdgSNaYkGoVq8FBZtS017vo1 SrKjgBep2qJPjIJR8Ph/hyXHwp3ks20I302iRz/h1jmgAsGczPfuGxDEinUPc4mMR4/C nqNg== 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=CyBu08uMqErM+zzJyPRDJRWX5ryfOT/RoKB9om6pnjA=; b=xPqz6EwY14ZtBNpb67yWsD06kg2Yo3/0jBVc5taXr8sn0LUXiXob72zH5TNnk957s0 5o6B7WRWzcanJfzACh64XEcJIeQtVgf/GcwGI5LuhbTWu+c/jCLkhHP0ZMb6pUlDwTdL Xmso2k8ef+DGHi7xIrJLtypgi4AVzt7z3WAZPABr7Cp2U9dvST7pRbAxEYgcugt4CMyK BX0zDHq5GzVROye4edIycrzVYs8cfYukCbEL3zzqKj4suKh0Lq8xsD9x5lRpzPcRtMZC K4lasx0arDv/QqjdvMTkjBdgwXhAfn19ZJPpU9rDNZ/x0Hj0QjHL0TPOO5faPu6SBTn1 00wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="A/BU/jZi"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t19-20020a63d253000000b0042c3a5b699asi6991074pgi.783.2022.10.21.11.15.35; Fri, 21 Oct 2022 11:15: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=@gmail.com header.s=20210112 header.b="A/BU/jZi"; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbiJUSHQ (ORCPT + 99 others); Fri, 21 Oct 2022 14:07:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbiJUSHO (ORCPT ); Fri, 21 Oct 2022 14:07:14 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9212545074; Fri, 21 Oct 2022 11:07:13 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 186-20020a1c02c3000000b003c6c154d528so5639982wmc.4; Fri, 21 Oct 2022 11:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=CyBu08uMqErM+zzJyPRDJRWX5ryfOT/RoKB9om6pnjA=; b=A/BU/jZiRtB32rNRZ3uk42wlCkZ0q5PYCdjXNM5anDN7uP4ZkMc+gHIYVpSLGiJujW +AgImTmEJnNvDv1Jpx8EZ/FhjCSNge/11n3AJFH/izDKCZq18pYny4VBmWNqv/y+gLhD vrqAoskm8yozPhHQwjqkv3GoMUFNYOUoS16Ezwe8z1V/VRI6pExhvduSLI8uqoeYCK9a WgcqCMSlOK/OtG5twSUk7+tVoAwU4W4EntifuFzEnL9cbU4K2oR2YwokH1gFAb9RCDQH XhG8edIbwb4dz0pStwGxHzbNC9bf4ZqExq1f/k9u5dYcvJfmf8TGogKvPMzCs0AvBH5u 6H7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=XmwEsjkGy4vHGxotgOw/c+/NC6iBZcMYsZv4+SZkNHXoovYmGaESM9j1tWfqUy7tZH fDmnecmFMlZFvuYp7IZdVtxhj1FLdRZ9HzjAFNnhkWD74FOPl7hroyZtQSd9BjRQaAjg 6AjiIPIhWjsYxWcpVyKs91MYXhQRgb6qb1sJ6eveVTtqJoWMxH+dc/rJlepA48iaFXn3 ntPQOZWOaYdAbtlls1ArLlq+sqQmriHHzCsFsEafiKEdkJ1uoqqGcjvAk1g8LkDJxt0x nD/qNWaal+daGCzrwJiAd99Yc4vuaMv6mU4pRhUdIibQ86/vw+M/d+ipVDf1cjeHsbr4 FptQ== X-Gm-Message-State: ACrzQf1sHJ5b7OKZowmVJZ6j/0H74VYgcnIXJFaoOjiHj+PiIkYxmA6t Gisi+dtZ6dkujt7ab/D61y5MtA5p8us= X-Received: by 2002:a05:600c:4449:b0:3c6:fb65:2463 with SMTP id v9-20020a05600c444900b003c6fb652463mr14122585wmn.128.1666375631691; Fri, 21 Oct 2022 11:07:11 -0700 (PDT) Received: from localhost.localdomain (93-42-70-134.ip85.fastwebnet.it. [93.42.70.134]) by smtp.googlemail.com with ESMTPSA id n4-20020a1ca404000000b003c41144b3cfsm280348wme.20.2022.10.21.11.07.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 11:07:11 -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: [RFC PATCH 1/2] clk: qcom: clk-rcg2: introduce support for multiple conf for same freq Date: Fri, 21 Oct 2022 20:06:56 +0200 Message-Id: <20221021180657.13474-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 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 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747322036385915259?= X-GMAIL-MSGID: =?utf-8?q?1747322036385915259?= 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 Fri Oct 21 18:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 6919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp838791wrr; Fri, 21 Oct 2022 11:14:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6VVSf64TuaZqjnFw02nQI0UfP66CcO5mx2uxMnlswxBmnuDx9U1tWL53+tk+YkeMWLyP3E X-Received: by 2002:a05:6a00:174c:b0:565:c73a:9117 with SMTP id j12-20020a056a00174c00b00565c73a9117mr20133092pfc.23.1666376077593; Fri, 21 Oct 2022 11:14:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666376077; cv=none; d=google.com; s=arc-20160816; b=D10EeZV5XBOz6gbNa7kGDw09os5mD9enKgiMPqlHdOao4tsxjmq1YoW/lMbMUhlS2i 3lnajd8PDiKcDUoGIioHDypFcmclZ3b1l6dGlTI8RQEwhPFEeMHh55qAQIIqErsQCaoh rh/XheJhcsXlwEuozdz0J1/Vbc51MhWSUdnHuh2WxG/EmxSc1vNqrJbrcxLLIyuEk7BZ +zakngqsXYIHiwXrgZkiZI9ZZ5sCBs2eJLNZbuV9aEWzDMNiHtr3Fhe61d59bz3vJtb9 asHOzLXMYg//RjMRP/rOsmExRHR1Q88a9cG92j9op2daRW7++9ciIul2fXH5qr9JGPDe 2ZSw== 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=UYevc0/VBCj9wBQRWlQ/9Q4O5TfPY8fJu+BvNTU/yG0=; b=TkaLQDj+DfQ7suPuc7to1cvD/AUJabcupVYaCS8UEwMH2aMAWmzxXXQQa4dxISNQ3e gaFXKCK3OV5oMqPMtDUvF/BkjoPYo8tfnaMVq2A/ZsUgCUEOL3FqJiGONAjUo5ZyicUl 6Xx4IZNmDMyARalvtgCiBQur5C/vYn84mj/63qAZfShQHS9rNNGGWGKdzz1eMuLzAKhv cwuVol1WgDHDoru3wtv/r7pKRh9CVNbZajyUrChGgNbPUrr12ITutMlEaNmLQHPhzVI+ 32+QN1+u+RuKiXF5Wq4xNOcwWb+lgkMILNwqMVz5sM9iNNCMkwmvJVRCNcEaMWvX6IFQ yRGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dUVoeS+r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z20-20020a17090ab11400b00212ce534ef7si2703357pjq.22.2022.10.21.11.14.22; Fri, 21 Oct 2022 11:14:37 -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=@gmail.com header.s=20210112 header.b=dUVoeS+r; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbiJUSHU (ORCPT + 99 others); Fri, 21 Oct 2022 14:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbiJUSHP (ORCPT ); Fri, 21 Oct 2022 14:07:15 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CBCB256401; Fri, 21 Oct 2022 11:07:14 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id e18so2772101wmq.3; Fri, 21 Oct 2022 11:07:14 -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=dUVoeS+r4UdeGMB+N1lX6A7ISaf2eJpRGohWDvas5cCg0h0Gcp5He+TmxRMkDkCqvT x5exD9Oic5lyVKj6i8H3WukULH5PJz9XPMOnmH77GtSIazHzwhXfmjZASyEE+ukZOhbm 6sUznWCYsz2v2vNCrxoGZP+vqL6QIV8PTs4VBrEp/WJdWrpH014xO8b2+sTu8EKBv/tw iUQtQT+WdP2Gxqe4/b85aahP4ag8EC1ZZtlEvVygVgsYrUF5L1PDUoJ/aE+mK56wW1km /CYGqwoUG3V5AhkYby8nsvlPOZlpLY+evbCp4u8ZhKwdJRa9XuIoLwi5E1QTbqVBzYX1 nVRw== 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=jmXSeIEys6KSmwS/8sGo8Wr2iX8nglh9Tt38AnMLtqx9DEXAwSP9gX5vJYEN/q8yWq No/qOV9Bv6xoitfWJuIqYSEU4Mj+4YYITDleO0rgkYxrNBYxOemGpiA59rqMkbhQWWZ9 0p6y2QSncPqiU/3wiMFO1auLh8e7tEz8o3IiwMDv7J/I0tq0qj1hqElTRHYadcbCiQvX vqrnuII9odf/dF1bkHAazi9DiaVt7dETLX/wg0s6lEs1/ErHO94PoITiUu9bWtkOPyb1 MEOw3XCmHg21CyhIU/wh9iRbUXYww+zXL66YpS3aR4jRD/RJEZL0qbZCFmqdS/cWbg6a CpEw== X-Gm-Message-State: ACrzQf36DyTlLCI77OHe78bwgk0aRlSDebwBmZQm+tzTzwd+ewApmuPY Qcp+xWSfQYtlARH8XySAkOek5rBi+NA= X-Received: by 2002:a1c:f20e:0:b0:3c2:5062:4017 with SMTP id s14-20020a1cf20e000000b003c250624017mr34025752wmc.175.1666375632872; Fri, 21 Oct 2022 11:07:12 -0700 (PDT) Received: from localhost.localdomain (93-42-70-134.ip85.fastwebnet.it. [93.42.70.134]) by smtp.googlemail.com with ESMTPSA id n4-20020a1ca404000000b003c41144b3cfsm280348wme.20.2022.10.21.11.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 11:07:12 -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: [RFC PATCH 2/2] clk: qcom: gcc-ipq8074: rework nss_port5/6 clock to multiple conf Date: Fri, 21 Oct 2022 20:06:57 +0200 Message-Id: <20221021180657.13474-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221021180657.13474-1-ansuelsmth@gmail.com> References: <20221021180657.13474-1-ansuelsmth@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 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747321961844001948?= X-GMAIL-MSGID: =?utf-8?q?1747321961844001948?= 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), { }