From patchwork Sat Jan 24 21:51:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Walmsley X-Patchwork-Id: 5700391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 57E83C058D for ; Sat, 24 Jan 2015 21:53:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 200102012B for ; Sat, 24 Jan 2015 21:53:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0308D2011D for ; Sat, 24 Jan 2015 21:53:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YF8c5-0006nz-H4; Sat, 24 Jan 2015 21:51:29 +0000 Received: from utopia.booyaka.com ([74.50.51.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YF8c2-0006lD-6x for linux-arm-kernel@lists.infradead.org; Sat, 24 Jan 2015 21:51:27 +0000 Received: (qmail 26657 invoked by uid 1019); 24 Jan 2015 21:51:03 -0000 Date: Sat, 24 Jan 2015 21:51:03 +0000 (UTC) From: Paul Walmsley To: Tero Kristo Subject: Re: [PATCH 01/23] ARM: OMAP2+: clock: move clock provider infrastructure to clock driver In-Reply-To: <1417103514-17027-2-git-send-email-t-kristo@ti.com> Message-ID: References: <1417103514-17027-1-git-send-email-t-kristo@ti.com> <1417103514-17027-2-git-send-email-t-kristo@ti.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150124_135126_382036_7C4DC9AF X-CRM114-Status: GOOD ( 25.80 ) X-Spam-Score: -0.0 (/) Cc: tony@atomide.com, nm@ti.com, tomi.valkeinen@ti.com, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP + Tomi On Thu, 27 Nov 2014, Tero Kristo wrote: > Splits the clock provider init out of the PRM driver and moves it to > clock driver. This is needed so that once the PRCM drivers are separated, > they can logically just access the clock driver not needing to go through > common PRM code. This would be wrong in the case of control module for > example. > > Signed-off-by: Tero Kristo This patch moves things in the wrong direction (ie, rather than keeping the PRM register accesses in the PRM code, it moves PRM register accesses into the clock code). But I see that a subsequent patch in this series moves them back. So this change is temporary and that seems reasonable to me. However, as long as the clock code wants to do low-level register accesses to PRM/CM/SCM registers, there needs to be some way to keep register updates originating from the clock code from racing with register updates coming from other code (e.g. non-clock-related PRM/CM/SCM accesses). So I've changed this patch to use regmap (as below), and the followup patch later in the series will be changed too. Seems to work so far but let's see how things go with the rest of the series. - Paul --- arch/arm/mach-omap2/clock.c | 103 ++++++++++++++++++++++++++++++++++---- arch/arm/mach-omap2/clock.h | 4 +- arch/arm/mach-omap2/prcm-common.h | 2 + arch/arm/mach-omap2/prm_common.c | 34 +------------ 4 files changed, 97 insertions(+), 46 deletions(-) diff --git a/arch/arm/mach-omap2/clock.c b/arch/arm/mach-omap2/clock.c index 6ad5b4dbd33e..5fd03e17560f 100644 --- a/arch/arm/mach-omap2/clock.c +++ b/arch/arm/mach-omap2/clock.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -73,32 +75,111 @@ struct ti_clk_features ti_clk_features; static bool clkdm_control = true; static LIST_HEAD(clk_hw_omap_clocks); -void __iomem *clk_memmaps[CLK_MAX_MEMMAPS]; +static struct regmap *clk_memmaps[CLK_MAX_MEMMAPS]; + +static struct regmap_config prcm_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .fast_io = 1, +}; + +static void clk_memmap_writel(u32 val, void __iomem *reg) +{ + struct clk_omap_reg *r = (struct clk_omap_reg *)® + + /* + * XXX Can't really continue if an error occurred here, since + * this function assumes that the write will always succeed + */ + if (regmap_write(clk_memmaps[r->index], r->offset, val)) { + WARN(1, "omap clock regmap write to %d %d failed\n", + r->index, r->offset); + BUG(); + } +} + +static u32 clk_memmap_readl(void __iomem *reg) +{ + struct clk_omap_reg *r = (struct clk_omap_reg *)® + unsigned int val = 0; + + /* + * XXX Can't really continue if an error occurred here, since + * this function assumes that the read will always succeed + */ + if (regmap_read(clk_memmaps[r->index], r->offset, &val)) { + WARN(1, "omap clock regmap read from %d %d failed\n", + r->index, r->offset); + BUG(); + } + + return val; +} void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg) { - if (clk->flags & MEMMAP_ADDRESSING) { - struct clk_omap_reg *r = (struct clk_omap_reg *)® - writel_relaxed(val, clk_memmaps[r->index] + r->offset); - } else { + if (clk->flags & MEMMAP_ADDRESSING) + clk_memmap_writel(val, reg); + else writel_relaxed(val, reg); - } } u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg) { u32 val; - if (clk->flags & MEMMAP_ADDRESSING) { - struct clk_omap_reg *r = (struct clk_omap_reg *)® - val = readl_relaxed(clk_memmaps[r->index] + r->offset); - } else { + if (clk->flags & MEMMAP_ADDRESSING) + val = clk_memmap_readl(reg); + else val = readl_relaxed(reg); - } return val; } +static struct ti_clk_ll_ops omap_clk_ll_ops = { + .clk_readl = clk_memmap_readl, + .clk_writel = clk_memmap_writel, +}; + +/** + * omap2_clk_provider_init - initialize a clock provider + * @match_table: DT device table to match for devices to init + * + * Initializes a clock provider module (CM/PRM etc.), allocating the + * memory mapping, allocating the mapping index and initializing the + * low level driver infrastructure. Returns 0 in success, -ENOMEM in + * failure. + */ +int __init omap2_clk_provider_init(const struct of_device_id *match_table) +{ + struct device_node *np; + void __iomem *mem; + static int memmap_index; + struct regmap *regmap; + + ti_clk_ll_ops = &omap_clk_ll_ops; + + for_each_matching_node(np, match_table) { + mem = of_iomap(np, 0); + if (!mem) + return -ENOMEM; + + regmap = regmap_init_mmio(NULL, mem, &prcm_regmap_config); + if (IS_ERR(regmap)) { + pr_err("omap2 clock: could not create regmap for %s\n", + of_node_full_name(np)); + continue; + } + + clk_memmaps[memmap_index] = regmap; + ti_dt_clk_init_provider(np, memmap_index); + memmap_index++; + } + + return 0; +} + /* * OMAP2+ specific clock functions */ diff --git a/arch/arm/mach-omap2/clock.h b/arch/arm/mach-omap2/clock.h index 1cf9dd85248a..a3b634978a0f 100644 --- a/arch/arm/mach-omap2/clock.h +++ b/arch/arm/mach-omap2/clock.h @@ -267,12 +267,12 @@ extern const struct clksel_rate div_1_3_rates[]; extern const struct clksel_rate div_1_4_rates[]; extern const struct clksel_rate div31_1to31_rates[]; -extern void __iomem *clk_memmaps[]; - extern int omap2_clkops_enable_clkdm(struct clk_hw *hw); extern void omap2_clkops_disable_clkdm(struct clk_hw *hw); extern void omap_clocks_register(struct omap_clk *oclks, int cnt); +int __init omap2_clk_provider_init(const struct of_device_id *match_table); + void __init ti_clk_init_features(void); #endif diff --git a/arch/arm/mach-omap2/prcm-common.h b/arch/arm/mach-omap2/prcm-common.h index a8e4b582c527..22afef0a4794 100644 --- a/arch/arm/mach-omap2/prcm-common.h +++ b/arch/arm/mach-omap2/prcm-common.h @@ -517,6 +517,8 @@ struct omap_prcm_irq_setup { .priority = _priority \ } +struct of_device_id; + extern void omap_prcm_irq_cleanup(void); extern int omap_prcm_register_chain_handler( struct omap_prcm_irq_setup *irq_setup); diff --git a/arch/arm/mach-omap2/prm_common.c b/arch/arm/mach-omap2/prm_common.c index 779940cb6e56..9f736d282303 100644 --- a/arch/arm/mach-omap2/prm_common.c +++ b/arch/arm/mach-omap2/prm_common.c @@ -590,41 +590,9 @@ static const struct of_device_id omap_prcm_dt_match_table[] = { { } }; -static struct clk_hw_omap memmap_dummy_ck = { - .flags = MEMMAP_ADDRESSING, -}; - -static u32 prm_clk_readl(void __iomem *reg) -{ - return omap2_clk_readl(&memmap_dummy_ck, reg); -} - -static void prm_clk_writel(u32 val, void __iomem *reg) -{ - omap2_clk_writel(val, &memmap_dummy_ck, reg); -} - -static struct ti_clk_ll_ops omap_clk_ll_ops = { - .clk_readl = prm_clk_readl, - .clk_writel = prm_clk_writel, -}; - int __init of_prcm_init(void) { - struct device_node *np; - void __iomem *mem; - int memmap_index = 0; - - ti_clk_ll_ops = &omap_clk_ll_ops; - - for_each_matching_node(np, omap_prcm_dt_match_table) { - mem = of_iomap(np, 0); - clk_memmaps[memmap_index] = mem; - ti_dt_clk_init_provider(np, memmap_index); - memmap_index++; - } - - return 0; + return omap2_clk_provider_init(omap_prcm_dt_match_table); } static int __init prm_late_init(void)