From patchwork Wed Dec 5 19:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tali Perry X-Patchwork-Id: 10714773 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 AE38C13BB for ; Wed, 5 Dec 2018 19:48:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F32F2E32C for ; Wed, 5 Dec 2018 19:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 901EF2E33D; Wed, 5 Dec 2018 19:48:20 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 237092E32C for ; Wed, 5 Dec 2018 19:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbeLETsN (ORCPT ); Wed, 5 Dec 2018 14:48:13 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:55911 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728653AbeLETru (ORCPT ); Wed, 5 Dec 2018 14:47:50 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id wB5JHVXm013011; Wed, 5 Dec 2018 21:17:31 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 20088) id 5C5F162DA6; Wed, 5 Dec 2018 21:47:29 +0200 (IST) From: Tali Perry To: avifishman70@gmail.com, tmaimon77@gmail.com, venture@google.com, yuenn@google.com, brendanhiggins@google.com, mturquette@baylibre.com, sboyd@kernel.org Cc: openbmc@lists.ozlabs.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Tali Perry Subject: [PATCH v1 1/1] clk: npcm: get fixed input clks from DT Date: Wed, 5 Dec 2018 21:47:02 +0200 Message-Id: <20181205194702.257430-3-tali.perry1@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20181205194702.257430-1-tali.perry1@gmail.com> References: <20181205194702.257430-1-tali.perry1@gmail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- drivers/clk/clk-npcm7xx.c | 64 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/drivers/clk/clk-npcm7xx.c b/drivers/clk/clk-npcm7xx.c index 27a86b7a34db..25f8ccaa3d2f 100644 --- a/drivers/clk/clk-npcm7xx.c +++ b/drivers/clk/clk-npcm7xx.c @@ -8,17 +8,23 @@ */ #include +#include #include +#include #include #include #include +#include +#include #include +#include #include #include +#include #include - #include + struct npcm7xx_clk_pll { struct clk_hw hw; void __iomem *pllcon; @@ -44,7 +50,8 @@ static unsigned long npcm7xx_clk_pll_recalc_rate(struct clk_hw *hw, u64 ret; if (parent_rate == 0) { - pr_err("%s: parent rate is zero", __func__); + pr_err("%s: parent rate is zero. reg=%s\n", __func__, + hw->init->name); return 0; } @@ -65,9 +72,10 @@ static const struct clk_ops npcm7xx_clk_pll_ops = { .recalc_rate = npcm7xx_clk_pll_recalc_rate, }; -static struct clk_hw * -npcm7xx_clk_register_pll(void __iomem *pllcon, const char *name, - const char *parent_name, unsigned long flags) +static struct clk_hw *npcm7xx_clk_register_pll(void __iomem *pllcon, + const char *name, + const char *parent_name, + unsigned long flags) { struct npcm7xx_clk_pll *pll; struct clk_init_data init; @@ -544,12 +552,14 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np) void __iomem *clk_base; struct resource res; struct clk_hw *hw; + struct clk *clk; int ret; int i; + clk_base = NULL; ret = of_address_to_resource(clk_np, 0, &res); if (ret) { - pr_err("%pOFn: failed to get resource, ret %d\n", clk_np, + pr_err("%s: failed to get resource, ret %d\n", clk_np->name, ret); return; } @@ -558,9 +568,10 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np) if (!clk_base) goto npcm7xx_init_error; - npcm7xx_clk_data = kzalloc(struct_size(npcm7xx_clk_data, hws, - NPCM7XX_NUM_CLOCKS), GFP_KERNEL); - if (!npcm7xx_clk_data) + npcm7xx_clk_data = kzalloc(sizeof(*npcm7xx_clk_data->hws) * + NPCM7XX_NUM_CLOCKS + sizeof(npcm7xx_clk_data), GFP_KERNEL); + + if (!npcm7xx_clk_data->hws) goto npcm7xx_init_np_err; npcm7xx_clk_data->num = NPCM7XX_NUM_CLOCKS; @@ -568,6 +579,31 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np) for (i = 0; i < NPCM7XX_NUM_CLOCKS; i++) npcm7xx_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); + /* Read fixed clocks. These 3 clocks must be defined in DT */ + clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_REFCLK); + if (IS_ERR(clk)) { + pr_err("failed to find external REFCLK on device tree, err=%ld\n", + PTR_ERR(clk)); + clk_put(clk); + goto npcm7xx_init_fail_no_clk_on_dt; + } + + clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_SYSBYPCK); + if (IS_ERR(clk)) { + pr_err("failed to find external SYSBYPCK on device tree, err=%ld\n", + PTR_ERR(clk)); + clk_put(clk); + goto npcm7xx_init_fail_no_clk_on_dt; + } + + clk = of_clk_get_by_name(clk_np, NPCM7XX_CLK_S_MCBYPCK); + if (IS_ERR(clk)) { + pr_err("failed to find external MCBYPCK on device tree, err=%ld\n", + PTR_ERR(clk)); + clk_put(clk); + goto npcm7xx_init_fail_no_clk_on_dt; + } + /* Register plls */ for (i = 0; i < ARRAY_SIZE(npcm7xx_plls); i++) { const struct npcm7xx_clk_pll_data *pll_data = &npcm7xx_plls[i]; @@ -646,11 +682,17 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np) return; +npcm7xx_init_fail_no_clk_on_dt: + pr_err("see Documentation/devicetree/bindings/clock/"); + pr_err("nuvoton,npcm750-clk.txt for details\n"); npcm7xx_init_fail: - kfree(npcm7xx_clk_data->hws); + if (npcm7xx_clk_data->num) + kfree(npcm7xx_clk_data->hws); npcm7xx_init_np_err: - iounmap(clk_base); + if (clk_base != NULL) + iounmap(clk_base); npcm7xx_init_error: of_node_put(clk_np); + pr_err("clk setup fail\n"); } CLK_OF_DECLARE(npcm7xx_clk_init, "nuvoton,npcm750-clk", npcm7xx_clk_init);