From patchwork Sun Jul 4 02:40:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 470032 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2785061jao; Sat, 3 Jul 2021 19:40:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyibZlS2helwpJ6M8TYzzHLHqTUFJqWb0/0DFiWM2M+gFeZLULdo9csN1uYoPJlY906/0ke X-Received: by 2002:a17:907:2bd1:: with SMTP id gv17mr6901542ejc.15.1625366457885; Sat, 03 Jul 2021 19:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625366457; cv=none; d=google.com; s=arc-20160816; b=WAp6/5blA+1rciOB2UV0ovXNq3Fk6uKd8bkP2KXdfbI42G6eJfeVcNmjolWr69j3sN FM4rRNSf8qy9KWIGoargkMF4Om/0JAmswywUpucdGzhFwP4M+SOVYccdm9OpY0+iA1tE 3Cs5mGBtFBupmjtrQ2Y8rE8yCS19mhwtWS7KLOfwfglCRsqO6Gun140rThyB/GJWBALJ hpyuyTZs2zqeAnFyB2gFZAnY3Nsv69vCutnolL+Nf18GPPcI2Bmm7o5rPQTTTQzZxfP3 C3qzRZ97VBfqfNte8tyVpMExLT2+h+Dr2PP9BMa9YDGwK3Bo6H0/8gay0yPvUE+Eo95D NP/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=d8JSTZ8+AJaTgMTmOHganaZdhQwLLSMBu10AnlPFiu8=; b=W6G7QRgaNnIscFtcSc/z5M1AMgAyd4X+2qCctdC9i/sXaOQZpVjJC4bdv2RxCtzfd2 ny1Pgqo4Z17w3jXPphvOYegqIZK0XNvxSzwzldxCUIo5aBsY3wgPj7MR1KL+8ryApgEn NweSLy62yyyC57I/Lu7BBvJnC1+FKy5oqssl3/CRoahompoXvp8Ivu5JGN7Dzfz1HL2i f1cmJb5N/wYQ0NEO83GfAg389dChsvNsoWRxpnYnRW1NpztLRJqN2iIk1OJIs2dI/JTG JmB7645nWFvKLpyNJEPv1XS3Rr9qyo+Xlaty/s5TZp8dT7i+FH+A72lBROFEeo0EZ+Nc bVrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PnY/ZDSC"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s19si7656569ejj.534.2021.07.03.19.40.57; Sat, 03 Jul 2021 19:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PnY/ZDSC"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229732AbhGDCna (ORCPT + 7 others); Sat, 3 Jul 2021 22:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbhGDCna (ORCPT ); Sat, 3 Jul 2021 22:43:30 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 899B4C061762 for ; Sat, 3 Jul 2021 19:40:55 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id y4so13256299pfi.9 for ; Sat, 03 Jul 2021 19:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d8JSTZ8+AJaTgMTmOHganaZdhQwLLSMBu10AnlPFiu8=; b=PnY/ZDSCQHF9HQBdG9c1eAxBf+DvgnK/Fp3L2oNhBpUlIXGXseKmWkKH0t83FxzfVe 6ySklp1/zytHkgSkwaFl+PtOvzK/zeYaE8DzjHDdUO/KrLZ9it8CaaTNZO2zlfWNZWy+ FMHC6JMpOOTIJ937i3DJBh/BHNj53v3u5zIoZE5FUNJXVLB9EWjrDMB/xX1djQqgfRtu c5gRdUHkyGOl4wRVekD2GYVZtFN96P8u0tIIDKs9Q8AuHAYaJSEOq25vKcrh9L4XN5I+ lebw/BuVFLpsGTt6mdDce1WSNKnJ181mNdFOB92XdxjLet+OptG0oPA8K9c5pKZldc4h W62A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=d8JSTZ8+AJaTgMTmOHganaZdhQwLLSMBu10AnlPFiu8=; b=uUoQouBmqE1tPZ0+chhPdI31Vt/PxgMNTXP+pLJ9YwOhE+EbDbIlg+GOOIqSUvGULM +cqpIoL8eGY6rmSVEn8g3RmqWy3xEzNIm+h6e/Wdh2OvmJ1uah+eEStU02fgQorKMtYN cbN+CEhFt7ex2eHLXqf182kih35xxXY+EhkQUGP8CrLtBE/jx4hB7FaLkT6Elb6ag+W6 pK4pV9pDn+HvXCHxBRVPl3I8+VyvL13euNQb8eYPgDmIivU8yhynZI3HvrmNaWoVhI0g ZougTZb269x/3DXtF7s525G0FKyNZ1zrezXD8ypz3v3JemXUiaSUz1/eeXKwfO0A+fBA xGTw== X-Gm-Message-State: AOAM5310Q5bI9XeLfJd2WEmY3lqKFJ0A8Woib55+smY2eF3T0mUu8yBM eUcQtTpQDJynU5CDe4RyP68i9Q== X-Received: by 2002:a63:de45:: with SMTP id y5mr1273481pgi.261.1625366454995; Sat, 03 Jul 2021 19:40:54 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id g17sm9394624pgh.61.2021.07.03.19.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jul 2021 19:40:54 -0700 (PDT) From: Shawn Guo To: Stephen Boyd Cc: Bjorn Andersson , Rob Herring , Sivaprakash Murugesan , Benjamin Li , devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, Shawn Guo Subject: [PATCH v2 4/4] clk: qcom: a53-pll: Add MSM8939 a53pll support Date: Sun, 4 Jul 2021 10:40:32 +0800 Message-Id: <20210704024032.11559-5-shawn.guo@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210704024032.11559-1-shawn.guo@linaro.org> References: <20210704024032.11559-1-shawn.guo@linaro.org> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org MSM8939 has 3 a53pll clocks with different frequency table for Cluster0, Cluster1 and CCI. It adds function qcom_a53pll_get_freq_tbl() to create pll_freq_tbl from OPP, so that those a53pll frequencies can be defined in DT with operating-points-v2 bindings rather than being coded in the driver. In this case, one compatible rather than three would be needed for these 3 a53pll clocks. Signed-off-by: Shawn Guo --- drivers/clk/qcom/a53-pll.c | 59 +++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/clk/qcom/a53-pll.c b/drivers/clk/qcom/a53-pll.c index 96a118be912d..9e6decb9c26f 100644 --- a/drivers/clk/qcom/a53-pll.c +++ b/drivers/clk/qcom/a53-pll.c @@ -6,9 +6,11 @@ * Author: Georgi Djakov */ +#include #include #include #include +#include #include #include @@ -34,6 +36,55 @@ static const struct regmap_config a53pll_regmap_config = { .fast_io = true, }; +static struct pll_freq_tbl *qcom_a53pll_get_freq_tbl(struct device *dev) +{ + struct pll_freq_tbl *freq_tbl; + unsigned long xo_freq; + unsigned long freq; + struct clk *xo_clk; + int count; + int ret; + int i; + + xo_clk = devm_clk_get(dev, "xo"); + if (IS_ERR(xo_clk)) + return NULL; + + xo_freq = clk_get_rate(xo_clk); + + ret = devm_pm_opp_of_add_table(dev); + if (ret) + return NULL; + + count = dev_pm_opp_get_opp_count(dev); + if (count <= 0) + return NULL; + + freq_tbl = devm_kcalloc(dev, count + 1, sizeof(*freq_tbl), GFP_KERNEL); + if (!freq_tbl) + return NULL; + + for (i = 0, freq = 0; i < count; i++, freq++) { + struct dev_pm_opp *opp; + + opp = dev_pm_opp_find_freq_ceil(dev, &freq); + if (IS_ERR(opp)) + return NULL; + + /* Skip the freq that is not divisible */ + if (freq % xo_freq) + continue; + + freq_tbl[i].freq = freq; + freq_tbl[i].l = freq / xo_freq; + freq_tbl[i].n = 1; + + dev_pm_opp_put(opp); + } + + return freq_tbl; +} + static int qcom_a53pll_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -65,7 +116,12 @@ static int qcom_a53pll_probe(struct platform_device *pdev) pll->mode_reg = 0x00; pll->status_reg = 0x1c; pll->status_bit = 16; - pll->freq_tbl = a53pll_freq; + + pll->freq_tbl = qcom_a53pll_get_freq_tbl(dev); + if (!pll->freq_tbl) { + /* Fall on a53pll_freq if no freq_tbl is found from OPP */ + pll->freq_tbl = a53pll_freq; + } /* Use an unique name by appending @unit-address */ init.name = devm_kasprintf(dev, GFP_KERNEL, "a53pll%s", @@ -96,6 +152,7 @@ static int qcom_a53pll_probe(struct platform_device *pdev) static const struct of_device_id qcom_a53pll_match_table[] = { { .compatible = "qcom,msm8916-a53pll" }, + { .compatible = "qcom,msm8939-a53pll" }, { } }; MODULE_DEVICE_TABLE(of, qcom_a53pll_match_table);