From patchwork Tue Oct 16 14:21:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 10643711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0DCA109C for ; Tue, 16 Oct 2018 14:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB9E029EB9 for ; Tue, 16 Oct 2018 14:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF4E029EC2; Tue, 16 Oct 2018 14:50:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0222D28CBE for ; Tue, 16 Oct 2018 14:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=VbmvGlSrHxJKkXeW6L8gDiuRzRp478IhjV/kojYv1U0=; b=rVDQD6iZ3XY3cm CEadr5uFlieBNF93kA2cApnWQt24hToVQCu66K1AkES03fWaTljjXLONEYJdpdON9w2cYMahU9CxJ g3or/o9YWXUF8lPYSXuHQXtO3PqPZvfYrfjo8yBOgjkOTD21siCN701G8uK0pjHIcScwK9ub+2NVR 7K9qHD3cwnH075fnxrhL0ZBbERFRi1eLh4dKN1prSrLErKY9955go0jwV1fo2tLcbYhLLMsL/pvVW eMkWw9Z7hSWr9aHBcC4H9RbO3CvOVjaz53ySjsuZf812p6QyeMa0t3/nOkcUCjFhRD3dEvGPezSpQ 7XqbesVd4c2Kf62mciAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCQfx-0002ug-NT; Tue, 16 Oct 2018 14:50:25 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCQch-0000TX-Rj for linux-arm-kernel@bombadil.infradead.org; Tue, 16 Oct 2018 14:47:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rtFJMzwp9zGT3ZzxNb8S0mzMKdSAVYjXmZc73CAPKSA=; b=CUZPZandZFO+/vvTHTvCGJ8mW9 PevcTvA5EHjWIAnHDNWCe5d3qJoTnSbJ6OqmKL7omqZle20AvwbHXDN9/wAZwvLAl+qto4wc0GbSe n3AtmbVIaH+Vxgtt9fweUg1iJyv25X2jkl/5gCUs9ANDcFSSPo1cEulKr9ljr8d5kR+PNtegS700j V1/JK2T5ogAIu6z/wK6b9SxkHXG53DhmV4QqqVR77ms2RNBaCdLbkmcqBNlrQOb8qrrfCQOCSXRiK 5BmkyS5Wq/ulWipmjZb8fCqg9Ze93cv6v1ebRNRZSEiNl0I+ANdTpBvau9BFB2XP0djxezcChrR9c JY1A8toQ==; Received: from mail.bootlin.com ([62.4.15.54]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gCQFJ-00028d-9O for linux-arm-kernel@lists.infradead.org; Tue, 16 Oct 2018 14:22:54 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 0468D20DB5; Tue, 16 Oct 2018 16:22:21 +0200 (CEST) Received: from localhost (242.171.71.37.rev.sfr.net [37.71.171.242]) by mail.bootlin.com (Postfix) with ESMTPSA id 6A61720DBD; Tue, 16 Oct 2018 16:22:02 +0200 (CEST) From: Alexandre Belloni To: Stephen Boyd Subject: [PATCH v2 07/22] clk: at91: add pmc_data struct and helpers Date: Tue, 16 Oct 2018 16:21:45 +0200 Message-Id: <20181016142200.19741-8-alexandre.belloni@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181016142200.19741-1-alexandre.belloni@bootlin.com> References: <20181016142200.19741-1-alexandre.belloni@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181016_102253_526910_45F57CA3 X-CRM114-Status: GOOD ( 12.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Alexandre Belloni , Michael Turquette , linux-kernel@vger.kernel.org, Thomas Petazzoni , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new strut to handle references to all the PMC clocks and implement allocation/free helpers. Signed-off-by: Alexandre Belloni --- drivers/clk/at91/pmc.c | 44 ++++++++++++++++++++++++++++++++++++++++++ drivers/clk/at91/pmc.h | 17 ++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c index 1fa27f4ea538..0f8b3add1b04 100644 --- a/drivers/clk/at91/pmc.c +++ b/drivers/clk/at91/pmc.c @@ -47,6 +47,50 @@ int of_at91_get_clk_range(struct device_node *np, const char *propname, } EXPORT_SYMBOL_GPL(of_at91_get_clk_range); +void pmc_data_free(struct pmc_data *pmc_data) +{ + kfree(pmc_data->chws); + kfree(pmc_data->shws); + kfree(pmc_data->phws); + kfree(pmc_data->ghws); +} + +struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, + unsigned int nperiph, unsigned int ngck) +{ + struct pmc_data *pmc_data = kzalloc(sizeof(*pmc_data), GFP_KERNEL); + + if (!pmc_data) + return NULL; + + pmc_data->ncore = ncore; + pmc_data->chws = kcalloc(ncore, sizeof(struct clk_hw *), GFP_KERNEL); + if (!pmc_data->chws) + goto err; + + pmc_data->nsystem = nsystem; + pmc_data->shws = kcalloc(nsystem, sizeof(struct clk_hw *), GFP_KERNEL); + if (!pmc_data->shws) + goto err; + + pmc_data->nperiph = nperiph; + pmc_data->phws = kcalloc(nperiph, sizeof(struct clk_hw *), GFP_KERNEL); + if (!pmc_data->phws) + goto err; + + pmc_data->ngck = ngck; + pmc_data->ghws = kcalloc(ngck, sizeof(struct clk_hw *), GFP_KERNEL); + if (!pmc_data->ghws) + goto err; + + return pmc_data; + +err: + pmc_data_free(pmc_data); + + return NULL; +} + #ifdef CONFIG_PM static struct regmap *pmcreg; diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index 3dc50267a458..672a79bda88c 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h @@ -19,6 +19,17 @@ extern spinlock_t pmc_pcr_lock; +struct pmc_data { + unsigned int ncore; + struct clk_hw **chws; + unsigned int nsystem; + struct clk_hw **shws; + unsigned int nperiph; + struct clk_hw **phws; + unsigned int ngck; + struct clk_hw **ghws; +}; + struct clk_range { unsigned long min; unsigned long max; @@ -69,6 +80,12 @@ extern const struct clk_programmable_layout at91rm9200_programmable_layout; extern const struct clk_programmable_layout at91sam9g45_programmable_layout; extern const struct clk_programmable_layout at91sam9x5_programmable_layout; +#define ndck(a, s) (a[s - 1].id + 1) +#define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1) +struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem, + unsigned int nperiph, unsigned int ngck); +void pmc_data_free(struct pmc_data *pmc_data); + int of_at91_get_clk_range(struct device_node *np, const char *propname, struct clk_range *range);