From patchwork Fri Oct 16 09:18:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zong Li X-Patchwork-Id: 11841129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 224B561C for ; Fri, 16 Oct 2020 09:19:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 CA55B20872 for ; Fri, 16 Oct 2020 09:19:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LQzMIRwW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="lagTdDTl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA55B20872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dYMCcI90UABmDPSuNdmJ/8cfGDbQMzYWEurmAYJjzXs=; b=LQzMIRwWt60OmY2XicjvpaPWb gcV5lCR1nI2stgTCkbwyATZVbXF0bHboT3g4rqej8T6ZT0PyVmNRxc5FRmPeMs0oMPeDvBWatebek 7S6W5yUtQJkrS2wxOW6uFH5JmsEVLM/tIr0GiZeadOyCERaMgabUywtxDeeb1Y+NOAGKWkobPYDeY A4Bjc0dVzVHXuKNgNzc4TO6t6fn1H17y+gk434Qfeig3sSaFap0w9M4R0znLIYUZ87hn1zfC30Q20 n+IJobjd2iZaEWHYDmyanlIFh5uNx2+n+ZfRRYrda60XApMmBKBT2oolp1uxIC9b6EmxF25dzItuy 6qFnq9CXg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTLss-0001HB-7P; Fri, 16 Oct 2020 09:18:46 +0000 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTLsp-0001Fw-Mp for linux-riscv@lists.infradead.org; Fri, 16 Oct 2020 09:18:44 +0000 Received: by mail-pj1-x1043.google.com with SMTP id j8so1133153pjy.5 for ; Fri, 16 Oct 2020 02:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hserBQdTEW9AsTQ36FTR+4nQGY1DffaxGbmIC1KLT7s=; b=lagTdDTlSZMSt6s3AWUZJg1jTmR1sY7a3/MhohEjooPBDyTBLQ3jy4Bvk/z4AWXh68 q7vr0OOAMEACFFcMaujXlurc2C3ICisMchCrTj/cBuCFB6kqe1FS1DaVatoTZGYj+9dK E+6SW+fpDyfHnb+7UeItIZrMDcDdrpQffmexxmgvPoNNZ16sB2E+NXAiXnQir//LVqS2 TMFNrL9tR+0TuN5OupbEIk2ypei9EPNvzvAA4kqSSgBXeTyis6B5MwpH32xFAOYtCmyv 7crEDlC7YHEN6g41D6tB4UhdM+i1EUA/3BH3S1flBClYZGvexByYkFUT/4s3WK3E+Q9s sztw== 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:mime-version:content-transfer-encoding; bh=hserBQdTEW9AsTQ36FTR+4nQGY1DffaxGbmIC1KLT7s=; b=q/zGXW949k+/cb1jpOko8Qq0exGZ4R43efvMUZ/CZ2pOTZCvS4N7tIw9nzN/YtTf51 bGDIueNlyCde8a46wN1989xbuMUKVt290jbnQjuZB3tbsVjEa3HTVynsU+cF2bYsQMkh AJRZNyphsHW8adTwLSOsfHpGkQnSfK54kwfoiLQ/XGvHj2Ko4+SX/nTOlOZeDwcZP4zf Dn4larOBrJh+ZWvYY2GRHf1cAuNkUQqGnw67x2VoylXT8IzFifWOorTflb8/5EhQ6LlD sZeCRhTSe0EB3AvvItF5697c3K1pKkD8CFNSFjgIUxjTWc28MPtg4wQ3U0WVD/KeH7tn EdsQ== X-Gm-Message-State: AOAM5322qrHB4BZFxLvbUiAQc9U6uQy8pds05pPIAwGpZIWkfVzn+QnO B7t6VABc/qL3FEOg+Eo1edICIw== X-Google-Smtp-Source: ABdhPJxNv1gd8tfR31PlXHnSFmHYU4xv0VUQkEBD5xr0qZ/Ge1q0o4e0BcAwYuA39IssTNsypJSVSg== X-Received: by 2002:a17:902:7042:b029:d5:c0e6:8e35 with SMTP id h2-20020a1709027042b02900d5c0e68e35mr2934273plt.9.1602839921352; Fri, 16 Oct 2020 02:18:41 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id h5sm2093263pfh.9.2020.10.16.02.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2020 02:18:40 -0700 (PDT) From: Zong Li To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, mturquette@baylibre.com, sboyd@kernel.org, yash.shah@sifive.com, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH 4/4] clk: sifive: Refactor __prci_clock array by using macro Date: Fri, 16 Oct 2020 17:18:26 +0800 Message-Id: <8ad64f9814137c5255d43d4ba670b5fcd15837ab.1602838910.git.zong.li@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201016_051843_753830_610524AC X-CRM114-Status: GOOD ( 13.74 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1043 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zong Li Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org Refactor code by using DEFINE_PRCI_CLOCK to define each clock and reduce duplicate code. Signed-off-by: Zong Li --- drivers/clk/sifive/fu540-prci.c | 38 ++++++---------- drivers/clk/sifive/fu540-prci.h | 2 +- drivers/clk/sifive/fu740-prci.c | 74 ++++++++++++-------------------- drivers/clk/sifive/fu740-prci.h | 2 +- drivers/clk/sifive/sifive-prci.c | 2 +- drivers/clk/sifive/sifive-prci.h | 10 ++++- 6 files changed, 53 insertions(+), 75 deletions(-) diff --git a/drivers/clk/sifive/fu540-prci.c b/drivers/clk/sifive/fu540-prci.c index 840b97bfff85..d43b9a9984f6 100644 --- a/drivers/clk/sifive/fu540-prci.c +++ b/drivers/clk/sifive/fu540-prci.c @@ -54,29 +54,19 @@ static const struct clk_ops sifive_fu540_prci_tlclksel_clk_ops = { .recalc_rate = sifive_prci_tlclksel_recalc_rate, }; +DEFINE_PRCI_CLOCK(fu540, corepll, hfclk, + &sifive_fu540_prci_wrpll_clk_ops, &__prci_corepll_data); +DEFINE_PRCI_CLOCK(fu540, ddrpll, hfclk, + &sifive_fu540_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data); +DEFINE_PRCI_CLOCK(fu540, gemgxlpll, hfclk, + &sifive_fu540_prci_wrpll_clk_ops, &__prci_gemgxlpll_data); +DEFINE_PRCI_CLOCK(fu540, tlclk, corepll, + &sifive_fu540_prci_tlclksel_clk_ops, NULL); + /* List of clock controls provided by the PRCI */ -struct __prci_clock __prci_init_clocks_fu540[] = { - [PRCI_CLK_COREPLL] = { - .name = "corepll", - .parent_name = "hfclk", - .ops = &sifive_fu540_prci_wrpll_clk_ops, - .pwd = &__prci_corepll_data, - }, - [PRCI_CLK_DDRPLL] = { - .name = "ddrpll", - .parent_name = "hfclk", - .ops = &sifive_fu540_prci_wrpll_ro_clk_ops, - .pwd = &__prci_ddrpll_data, - }, - [PRCI_CLK_GEMGXLPLL] = { - .name = "gemgxlpll", - .parent_name = "hfclk", - .ops = &sifive_fu540_prci_wrpll_clk_ops, - .pwd = &__prci_gemgxlpll_data, - }, - [PRCI_CLK_TLCLK] = { - .name = "tlclk", - .parent_name = "corepll", - .ops = &sifive_fu540_prci_tlclksel_clk_ops, - }, +struct __prci_clock *__prci_init_clocks_fu540[] = { + [PRCI_CLK_COREPLL] = &fu540_corepll, + [PRCI_CLK_DDRPLL] = &fu540_ddrpll, + [PRCI_CLK_GEMGXLPLL] = &fu540_gemgxlpll, + [PRCI_CLK_TLCLK] = &fu540_tlclk, }; diff --git a/drivers/clk/sifive/fu540-prci.h b/drivers/clk/sifive/fu540-prci.h index c8271efa7bdc..281200cd8848 100644 --- a/drivers/clk/sifive/fu540-prci.h +++ b/drivers/clk/sifive/fu540-prci.h @@ -11,7 +11,7 @@ #define NUM_CLOCK_FU540 4 -extern struct __prci_clock __prci_init_clocks_fu540[NUM_CLOCK_FU540]; +extern struct __prci_clock *__prci_init_clocks_fu540[NUM_CLOCK_FU540]; static const struct prci_clk_desc prci_clk_fu540 = { .clks = __prci_init_clocks_fu540, diff --git a/drivers/clk/sifive/fu740-prci.c b/drivers/clk/sifive/fu740-prci.c index 3b87e273c3eb..676cad2c3886 100644 --- a/drivers/clk/sifive/fu740-prci.c +++ b/drivers/clk/sifive/fu740-prci.c @@ -71,52 +71,32 @@ static const struct clk_ops sifive_fu740_prci_hfpclkplldiv_clk_ops = { .recalc_rate = sifive_prci_hfpclkplldiv_recalc_rate, }; + +DEFINE_PRCI_CLOCK(fu740, corepll, hfclk, + &sifive_fu740_prci_wrpll_clk_ops, &__prci_corepll_data); +DEFINE_PRCI_CLOCK(fu740, ddrpll, hfclk, + &sifive_fu740_prci_wrpll_ro_clk_ops, &__prci_ddrpll_data); +DEFINE_PRCI_CLOCK(fu740, gemgxlpll, hfclk, + &sifive_fu740_prci_wrpll_clk_ops, &__prci_gemgxlpll_data); +DEFINE_PRCI_CLOCK(fu740, dvfscorepll, hfclk, + &sifive_fu740_prci_wrpll_clk_ops, &__prci_dvfscorepll_data); +DEFINE_PRCI_CLOCK(fu740, hfpclkpll, hfclk, + &sifive_fu740_prci_wrpll_clk_ops, &__prci_hfpclkpll_data); +DEFINE_PRCI_CLOCK(fu740, cltxpll, hfclk, + &sifive_fu740_prci_wrpll_clk_ops, &__prci_cltxpll_data); +DEFINE_PRCI_CLOCK(fu740, tlclk, corepll, + &sifive_fu740_prci_tlclksel_clk_ops, NULL); +DEFINE_PRCI_CLOCK(fu740, pclk, hfpclkpll, + &sifive_fu740_prci_hfpclkplldiv_clk_ops, NULL); + /* List of clock controls provided by the PRCI */ -struct __prci_clock __prci_init_clocks_fu740[] = { - [PRCI_CLK_COREPLL] = { - .name = "corepll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_clk_ops, - .pwd = &__prci_corepll_data, - }, - [PRCI_CLK_DDRPLL] = { - .name = "ddrpll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_ro_clk_ops, - .pwd = &__prci_ddrpll_data, - }, - [PRCI_CLK_GEMGXLPLL] = { - .name = "gemgxlpll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_clk_ops, - .pwd = &__prci_gemgxlpll_data, - }, - [PRCI_CLK_DVFSCOREPLL] = { - .name = "dvfscorepll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_clk_ops, - .pwd = &__prci_dvfscorepll_data, - }, - [PRCI_CLK_HFPCLKPLL] = { - .name = "hfpclkpll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_clk_ops, - .pwd = &__prci_hfpclkpll_data, - }, - [PRCI_CLK_CLTXPLL] = { - .name = "cltxpll", - .parent_name = "hfclk", - .ops = &sifive_fu740_prci_wrpll_clk_ops, - .pwd = &__prci_cltxpll_data, - }, - [PRCI_CLK_TLCLK] = { - .name = "tlclk", - .parent_name = "corepll", - .ops = &sifive_fu740_prci_tlclksel_clk_ops, - }, - [PRCI_CLK_PCLK] = { - .name = "pclk", - .parent_name = "hfpclkpll", - .ops = &sifive_fu740_prci_hfpclkplldiv_clk_ops, - }, +struct __prci_clock *__prci_init_clocks_fu740[] = { + [PRCI_CLK_COREPLL] = &fu740_corepll, + [PRCI_CLK_DDRPLL] = &fu740_ddrpll, + [PRCI_CLK_GEMGXLPLL] = &fu740_gemgxlpll, + [PRCI_CLK_DVFSCOREPLL] = &fu740_dvfscorepll, + [PRCI_CLK_HFPCLKPLL] = &fu740_hfpclkpll, + [PRCI_CLK_CLTXPLL] = &fu740_cltxpll, + [PRCI_CLK_TLCLK] = &fu740_tlclk, + [PRCI_CLK_PCLK] = &fu740_pclk, }; diff --git a/drivers/clk/sifive/fu740-prci.h b/drivers/clk/sifive/fu740-prci.h index 13ef971f7764..3f03295f719a 100644 --- a/drivers/clk/sifive/fu740-prci.h +++ b/drivers/clk/sifive/fu740-prci.h @@ -11,7 +11,7 @@ #define NUM_CLOCK_FU740 8 -extern struct __prci_clock __prci_init_clocks_fu740[NUM_CLOCK_FU740]; +extern struct __prci_clock *__prci_init_clocks_fu740[NUM_CLOCK_FU740]; static const struct prci_clk_desc prci_clk_fu740 = { .clks = __prci_init_clocks_fu740, diff --git a/drivers/clk/sifive/sifive-prci.c b/drivers/clk/sifive/sifive-prci.c index 4098dbc5881a..2ef3f9f91b33 100644 --- a/drivers/clk/sifive/sifive-prci.c +++ b/drivers/clk/sifive/sifive-prci.c @@ -431,7 +431,7 @@ static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, /* Register PLLs */ for (i = 0; i < desc->num_clks; ++i) { - pic = &(desc->clks[i]); + pic = desc->clks[i]; init.name = pic->name; init.parent_names = &pic->parent_name; diff --git a/drivers/clk/sifive/sifive-prci.h b/drivers/clk/sifive/sifive-prci.h index bc0646bc9c3e..e6c9f72e20de 100644 --- a/drivers/clk/sifive/sifive-prci.h +++ b/drivers/clk/sifive/sifive-prci.h @@ -253,6 +253,14 @@ struct __prci_clock { struct __prci_data *pd; }; +#define DEFINE_PRCI_CLOCK(_platform, _name, _parent, _ops, _pwd) \ + static struct __prci_clock _platform##_##_name = { \ + .name = #_name, \ + .parent_name = #_parent, \ + .ops = _ops, \ + .pwd = _pwd, \ + } \ + #define clk_hw_to_prci_clock(pwd) container_of(pwd, struct __prci_clock, hw) /* @@ -261,7 +269,7 @@ struct __prci_clock { * @num_clks: the number of element of clks */ struct prci_clk_desc { - struct __prci_clock *clks; + struct __prci_clock **clks; size_t num_clks; };