From patchwork Tue Sep 6 17:31:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 9317713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DCA8C607D3 for ; Tue, 6 Sep 2016 17:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4C1428E17 for ; Tue, 6 Sep 2016 17:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8DDA28E2A; Tue, 6 Sep 2016 17:24:25 +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=-4.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 3F06A28E17 for ; Tue, 6 Sep 2016 17:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938804AbcIFRYY (ORCPT ); Tue, 6 Sep 2016 13:24:24 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35914 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938754AbcIFRYU (ORCPT ); Tue, 6 Sep 2016 13:24:20 -0400 Received: by mail-lf0-f50.google.com with SMTP id g62so151390574lfe.3 for ; Tue, 06 Sep 2016 10:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bL1PTLYiRjf3PssrrMhVP/46GDvRBiH7v7Xntm1bp64=; b=Dsj/GDc6lyFGqy/r8BqdADKHLrdpptK7tUx8NEo8bZBM8haLWNzCbtC70D52QOHSBH 1TCdIdHFI4DIm4YM3KUqDHZdA4aCoNmFDjqGqGDGztyEtSi7howGpECqV/wKxhbLfWe7 Ds1zGuUgSqUje1RcBtiyXG94npKKY6RKTExigJmBWj4iuwxUg01rIwQGKuya2JqHJFuF UeTBASWoQwbZInzIp/BC8hxI+Gx85uJa8xNq/jWRLoCejF13liDHF+rPfjhaRnNABO9o MWq5AXIooXBsxyP5E1h9UMJ01dp5bLXzWn9OEoTYmJACVAV3KO3PDavHcm8vOjRBvajF VgSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bL1PTLYiRjf3PssrrMhVP/46GDvRBiH7v7Xntm1bp64=; b=PSBAC4qgylDe033G8XmMU7ORApP9mBj1UrzkiqWXK+kSjf75uTNUHhotIeQDDbmpxv 7dRJJpPUFrS8Rmf6U56S4u70jsKnDjwszKNz+QVDn6x8QMWMJufpuowp+qJdnSjh321R U17hn2mdX9cVmNA9amKZJYhb2Ite9BlLa8lQTxXGkyd8DCmXBdY+O2xBnFb+LJ02sLXV MROuWRIO+4ZE+sQtZ/2cq+VUHqC2qGwJTivTt9b7dbQaC7wJgh8uXnd7xLgd9xNT1opa m3yvUHs5zp4yy0k2asqWBRfSYPSNKAoNez8PVv4GPQUiV1DsfDQeZ9E6yYJ7GDFPeue3 KtJg== X-Gm-Message-State: AE9vXwNltNCsAowD8RFqkyued2M7NqQrJbEZR93tvofXGT7VsEechpq5gEire0V7gK6yJg== X-Received: by 10.46.9.76 with SMTP id 73mr11205522ljj.61.1473182658782; Tue, 06 Sep 2016 10:24:18 -0700 (PDT) Received: from enkidu.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id 4sm5398990ljf.33.2016.09.06.10.24.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Sep 2016 10:24:18 -0700 (PDT) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, sboyd@codeaurora.org, mturquette@baylibre.com Cc: sebastian.hesselbarth@gmail.com, andrew@lunn.ch, jason@lakedaemon.net, thomas.petazzoni@free-electrons.com, gregory.clement@free-electrons.com, nadavh@marvell.com, alior@marvell.com, tn@semihalf.com, jaz@semihalf.com, Marcin Wojtas , Subject: [PATCH v2 2/3] clk: mvebu: dynamically allocate resources in Armada CP110 system controller Date: Tue, 6 Sep 2016 19:31:56 +0200 Message-Id: <1473183117-11889-3-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1473183117-11889-1-git-send-email-mw@semihalf.com> References: <1473183117-11889-1-git-send-email-mw@semihalf.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 Original commit, which added support for Armada CP110 system controller used global variables for storing all clock information. It worked fine for Armada 7k SoC, with single CP110 block. After dual-CP110 Armada 8k was introduced, the data got overwritten and corrupted. This patch fixes the issue by allocating resources dynamically in the driver probe and storing it as platform drvdata. Fixes: d3da3eaef7f4 ("clk: mvebu: new driver for Armada CP110 system ...") Signed-off-by: Marcin Wojtas Reviewed-by: Thomas Petazzoni CC: --- drivers/clk/mvebu/cp110-system-controller.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/clk/mvebu/cp110-system-controller.c b/drivers/clk/mvebu/cp110-system-controller.c index 59fe76e..5e68d24 100644 --- a/drivers/clk/mvebu/cp110-system-controller.c +++ b/drivers/clk/mvebu/cp110-system-controller.c @@ -81,13 +81,6 @@ enum { #define CP110_GATE_EIP150 25 #define CP110_GATE_EIP197 26 -static struct clk *cp110_clks[CP110_CLK_NUM]; - -static struct clk_onecell_data cp110_clk_data = { - .clks = cp110_clks, - .clk_num = CP110_CLK_NUM, -}; - struct cp110_gate_clk { struct clk_hw hw; struct regmap *regmap; @@ -196,7 +189,8 @@ static int cp110_syscon_clk_probe(struct platform_device *pdev) struct regmap *regmap; struct device_node *np = pdev->dev.of_node; const char *ppv2_name, *apll_name, *core_name, *eip_name, *nand_name; - struct clk *clk; + struct clk_onecell_data *cp110_clk_data; + struct clk *clk, **cp110_clks; u32 nand_clk_ctrl; int i, ret; @@ -209,6 +203,20 @@ static int cp110_syscon_clk_probe(struct platform_device *pdev) if (ret) return ret; + cp110_clks = devm_kcalloc(&pdev->dev, sizeof(struct clk *), + CP110_CLK_NUM, GFP_KERNEL); + if (!cp110_clks) + return PTR_ERR(cp110_clks); + + cp110_clk_data = devm_kzalloc(&pdev->dev, + sizeof(*cp110_clk_data), + GFP_KERNEL); + if (!cp110_clk_data) + return PTR_ERR(cp110_clk_data); + + cp110_clk_data->clks = cp110_clks; + cp110_clk_data->clk_num = CP110_CLK_NUM; + /* Register the APLL which is the root of the clk tree */ of_property_read_string_index(np, "core-clock-output-names", CP110_CORE_APLL, &apll_name); @@ -336,10 +344,12 @@ static int cp110_syscon_clk_probe(struct platform_device *pdev) cp110_clks[CP110_MAX_CORE_CLOCKS + i] = clk; } - ret = of_clk_add_provider(np, cp110_of_clk_get, &cp110_clk_data); + ret = of_clk_add_provider(np, cp110_of_clk_get, cp110_clk_data); if (ret) goto fail_clk_add; + platform_set_drvdata(pdev, cp110_clks); + return 0; fail_clk_add: @@ -366,6 +376,7 @@ fail0: static int cp110_syscon_clk_remove(struct platform_device *pdev) { + struct clk **cp110_clks = platform_get_drvdata(pdev); int i; of_clk_del_provider(pdev->dev.of_node);