From patchwork Fri Apr 27 00:17:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10367123 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 8C24160542 for ; Fri, 27 Apr 2018 00:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E0BD29272 for ; Fri, 27 Apr 2018 00:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7248E292A8; Fri, 27 Apr 2018 00:23: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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham 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 91F7D29272 for ; Fri, 27 Apr 2018 00:23:24 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Gok7/Mf3UuEKEw+tb+FcevAlxsSBGYAVwMZUtsHSVf0=; b=tmsrI678/kJ/e64XwV5COtEW3m Duw9rRY0jWF+WH09FyZUkaBwrc7os8srv/XK00OQAF38F+4Ex/U9q94IHqo49leTTQS98zusyeOL7 ce10TbQ3UBz2vQlMEEKuU5q4Ao4rXOGCwgWUNder/5XCCzarDuuNdHOU6U9B1CG0JA890xQpJcXXj Ozk2YYuSgHN1iJLgELG1dK4sSx2DL5NyqQuV//gh71+pcv254JfXaDei2CEEgrTsjAl57omJwKSE9 2CR+h9R2zlB4N11IYss//CYCAp9fUZYawZ1wNVSWiBZmqqAAQNvzzZrJdh/AIXzVpFWDJF74GegCT toY2iXGg==; 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 1fBrAO-0004C7-Lm; Fri, 27 Apr 2018 00:23:12 +0000 Received: from vern.gendns.com ([206.190.152.46]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBr6a-0001IK-MG for linux-arm-kernel@lists.infradead.org; Fri, 27 Apr 2018 00:19:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding: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=WgRF0yaGtJ/v4VMh0LNlz6bqovCqA5BzS0JVRXD2e1U=; b=O9gRCb515LLWufXbcOBk5W6A8 /kVtNAePkHkZqNzWz8HU1Em4ieo5OvQVSY6R+/de2dNcwBm73GM0jSkuDEE8Jblr7YxSZ6JeEZWCZ LQ8A5b9M5czpqQ9Z99MOP3sntQF9fyTYoNjGgk1RP0Q0V2fFDkgIQ87zyFenIMcCgAf0Hezw+G90+ Hp9fm8Y7ONHNg3ChCs21Vm4tQqjaxWyaIxDsHFGg1zFyCtZKA0sNPaoF0LqQ9U6jvoAxORpPKByvF k5Mtvyh1q5073AymQ+9ra456h722fKZbvFB3XV/i5gmvvOI22W+p/eOWj/dkejotX5VaX3xrO+Kgg w+pb5vELQ==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:39016 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1fBr5m-000iph-8G; Thu, 26 Apr 2018 20:18:26 -0400 From: David Lechner To: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v9 03/27] clk: davinci: psc: allow for dev == NULL Date: Thu, 26 Apr 2018 19:17:21 -0500 Message-Id: <20180427001745.4116-4-david@lechnology.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427001745.4116-1-david@lechnology.com> References: <20180427001745.4116-1-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180426_171916_852945_8F43B706 X-CRM114-Status: GOOD ( 13.12 ) 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: Mark Rutland , David Lechner , Kevin Hilman , Stephen Boyd , Michael Turquette , Sekhar Nori , linux-kernel@vger.kernel.org, Bartosz Golaszewski , Rob Herring , Adam Ford MIME-Version: 1.0 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 On some davinci SoCs, we need to register the PSC clocks during early boot because they are needed for clocksource/clockevent. These changes allow for dev == NULL because in this case, we won't have a platform device for the clocks. Signed-off-by: David Lechner --- v9 changes: - new patch in v9 drivers/clk/davinci/psc-dm355.c | 2 +- drivers/clk/davinci/psc-dm365.c | 2 +- drivers/clk/davinci/psc-dm644x.c | 2 +- drivers/clk/davinci/psc-dm646x.c | 2 +- drivers/clk/davinci/psc.c | 70 ++++++++++++++++++++++++++++---- include/linux/clk/davinci.h | 5 +++ 6 files changed, 72 insertions(+), 11 deletions(-) diff --git a/drivers/clk/davinci/psc-dm355.c b/drivers/clk/davinci/psc-dm355.c index 6995ecea2677..001288dfdfb1 100644 --- a/drivers/clk/davinci/psc-dm355.c +++ b/drivers/clk/davinci/psc-dm355.c @@ -68,7 +68,7 @@ static const struct davinci_lpsc_clk_info dm355_psc_info[] = { { } }; -static int dm355_psc_init(struct device *dev, void __iomem *base) +int dm355_psc_init(struct device *dev, void __iomem *base) { return davinci_psc_register_clocks(dev, dm355_psc_info, 42, base); } diff --git a/drivers/clk/davinci/psc-dm365.c b/drivers/clk/davinci/psc-dm365.c index 3ad915f37376..5b5b55b0b59a 100644 --- a/drivers/clk/davinci/psc-dm365.c +++ b/drivers/clk/davinci/psc-dm365.c @@ -73,7 +73,7 @@ static const struct davinci_lpsc_clk_info dm365_psc_info[] = { { } }; -static int dm365_psc_init(struct device *dev, void __iomem *base) +int dm365_psc_init(struct device *dev, void __iomem *base) { return davinci_psc_register_clocks(dev, dm365_psc_info, 52, base); } diff --git a/drivers/clk/davinci/psc-dm644x.c b/drivers/clk/davinci/psc-dm644x.c index c22367baa46f..74668931be48 100644 --- a/drivers/clk/davinci/psc-dm644x.c +++ b/drivers/clk/davinci/psc-dm644x.c @@ -63,7 +63,7 @@ static const struct davinci_lpsc_clk_info dm644x_psc_info[] = { { } }; -static int dm644x_psc_init(struct device *dev, void __iomem *base) +int dm644x_psc_init(struct device *dev, void __iomem *base) { return davinci_psc_register_clocks(dev, dm644x_psc_info, 41, base); } diff --git a/drivers/clk/davinci/psc-dm646x.c b/drivers/clk/davinci/psc-dm646x.c index 468ef86ea40b..22473affa7cf 100644 --- a/drivers/clk/davinci/psc-dm646x.c +++ b/drivers/clk/davinci/psc-dm646x.c @@ -58,7 +58,7 @@ static const struct davinci_lpsc_clk_info dm646x_psc_info[] = { { } }; -static int dm646x_psc_init(struct device *dev, void __iomem *base) +int dm646x_psc_init(struct device *dev, void __iomem *base) { return davinci_psc_register_clocks(dev, dm646x_psc_info, 46, base); } diff --git a/drivers/clk/davinci/psc.c b/drivers/clk/davinci/psc.c index ce170e600f09..1d4bcdd6bba0 100644 --- a/drivers/clk/davinci/psc.c +++ b/drivers/clk/davinci/psc.c @@ -63,7 +63,7 @@ struct davinci_psc_data { /** * struct davinci_lpsc_clk - LPSC clock structure - * @dev: the device that provides this LPSC + * @dev: the device that provides this LPSC or NULL * @hw: clk_hw for the LPSC * @pm_domain: power domain for the LPSC * @genpd_clk: clock reference owned by @pm_domain @@ -86,6 +86,50 @@ struct davinci_lpsc_clk { #define to_davinci_psc_data(x) container_of(x, struct davinci_psc_data, x) #define to_davinci_lpsc_clk(x) container_of(x, struct davinci_lpsc_clk, x) +static inline void *_devm_kzalloc(struct device *dev, size_t size, gfp_t flags) +{ + if (dev) + return devm_kzalloc(dev, size, flags); + + return kzalloc(size, flags); +} + +static inline void *_devm_kcalloc(struct device *dev, size_t n, size_t size, + gfp_t flags) +{ + if (dev) + return devm_kcalloc(dev, n, size, flags); + + return kcalloc(n, size, flags); +} + +static inline void *_devm_kmalloc_array(struct device *dev, size_t n, + size_t size, gfp_t flags) +{ + if (dev) + return devm_kmalloc_array(dev, n, size, flags); + + return kmalloc_array(n, size, flags); +} + +static inline int _devm_clk_hw_register(struct device *dev, struct clk_hw *hw) +{ + if (dev) + return devm_clk_hw_register(dev, hw); + + return clk_hw_register(NULL, hw); +} + +static inline struct regmap +*_devm_regmap_init_mmio(struct device *dev, void __iomem *regs, + const struct regmap_config *config) +{ + if (dev) + return devm_regmap_init_mmio(dev, regs, config); + + return regmap_init_mmio(NULL, regs, config); +} + /** * best_dev_name - get the "best" device name. * @dev: the device @@ -221,6 +265,7 @@ static void davinci_psc_genpd_detach_dev(struct generic_pm_domain *pm_domain, /** * davinci_lpsc_clk_register - register LPSC clock + * @dev: the clocks's device or NULL * @name: name of this clock * @parent_name: name of clock's parent * @regmap: PSC MMIO region @@ -238,7 +283,7 @@ davinci_lpsc_clk_register(struct device *dev, const char *name, int ret; bool is_on; - lpsc = devm_kzalloc(dev, sizeof(*lpsc), GFP_KERNEL); + lpsc = _devm_kzalloc(dev, sizeof(*lpsc), GFP_KERNEL); if (!lpsc) return ERR_PTR(-ENOMEM); @@ -261,10 +306,14 @@ davinci_lpsc_clk_register(struct device *dev, const char *name, lpsc->pd = pd; lpsc->flags = flags; - ret = devm_clk_hw_register(dev, &lpsc->hw); + ret = _devm_clk_hw_register(dev, &lpsc->hw); if (ret < 0) return ERR_PTR(ret); + /* for now, genpd is only registered when using device-tree */ + if (!dev || !dev->of_node) + return lpsc; + /* genpd attach needs a way to look up this clock */ ret = clk_hw_register_clkdev(&lpsc->hw, name, best_dev_name(dev)); @@ -378,11 +427,11 @@ __davinci_psc_register_clocks(struct device *dev, struct regmap *regmap; int i, ret; - psc = devm_kzalloc(dev, sizeof(*psc), GFP_KERNEL); + psc = _devm_kzalloc(dev, sizeof(*psc), GFP_KERNEL); if (!psc) return ERR_PTR(-ENOMEM); - clks = devm_kmalloc_array(dev, num_clks, sizeof(*clks), GFP_KERNEL); + clks = _devm_kmalloc_array(dev, num_clks, sizeof(*clks), GFP_KERNEL); if (!clks) return ERR_PTR(-ENOMEM); @@ -396,14 +445,14 @@ __davinci_psc_register_clocks(struct device *dev, for (i = 0; i < num_clks; i++) clks[i] = ERR_PTR(-ENOENT); - pm_domains = devm_kcalloc(dev, num_clks, sizeof(*pm_domains), GFP_KERNEL); + pm_domains = _devm_kcalloc(dev, num_clks, sizeof(*pm_domains), GFP_KERNEL); if (!pm_domains) return ERR_PTR(-ENOMEM); psc->pm_data.domains = pm_domains; psc->pm_data.num_domains = num_clks; - regmap = devm_regmap_init_mmio(dev, base, &davinci_psc_regmap_config); + regmap = _devm_regmap_init_mmio(dev, base, &davinci_psc_regmap_config); if (IS_ERR(regmap)) return ERR_CAST(regmap); @@ -423,6 +472,13 @@ __davinci_psc_register_clocks(struct device *dev, pm_domains[info->md] = &lpsc->pm_domain; } + /* + * for now, a reset controller is only registered when there is a device + * to associate it with. + */ + if (!dev) + return psc; + psc->rcdev.ops = &davinci_psc_reset_ops; psc->rcdev.owner = THIS_MODULE; psc->rcdev.dev = dev; diff --git a/include/linux/clk/davinci.h b/include/linux/clk/davinci.h index 1298cca509ac..b32dd3f53ecc 100644 --- a/include/linux/clk/davinci.h +++ b/include/linux/clk/davinci.h @@ -21,4 +21,9 @@ int dm365_pll2_init(struct device *dev, void __iomem *base, struct regmap *cfgch int dm644x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); int dm646x_pll1_init(struct device *dev, void __iomem *base, struct regmap *cfgchip); +int dm355_psc_init(struct device *dev, void __iomem *base); +int dm365_psc_init(struct device *dev, void __iomem *base); +int dm644x_psc_init(struct device *dev, void __iomem *base); +int dm646x_psc_init(struct device *dev, void __iomem *base); + #endif /* __LINUX_CLK_DAVINCI_PLL_H___ */