From patchwork Thu Feb 5 17:24:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 5786041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7F75F9F336 for ; Thu, 5 Feb 2015 17:27:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4048420225 for ; Thu, 5 Feb 2015 17:27:36 +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 141E62011E for ; Thu, 5 Feb 2015 17:27:35 +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 1YJQB7-0006Me-GS; Thu, 05 Feb 2015 17:25:21 +0000 Received: from mail-lb0-x234.google.com ([2a00:1450:4010:c04::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YJQB3-0004tk-C3; Thu, 05 Feb 2015 17:25:18 +0000 Received: by mail-lb0-f180.google.com with SMTP id b6so9585907lbj.11; Thu, 05 Feb 2015 09:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=jETT7SxPBZpV+29X/q/6bRsHpxmlt6QFLupBXJykBBc=; b=lJsG2OgYdlhvQ7Fe2SyvTAA6z76/fJ8lwcFTuRrDWs71uWM6UWon8og98l+uCVLxO6 4Mmlx7bDOCQw/b8pjY+bEajghAV5L3Eqnz2z+LNtdGESY3Ap2VgXwb0L6Y+Vi/gvz1z7 r9hcYWykd0LQDx92QStVkN5UW3ijR8eVl9/6egePxqIL+z1tfm32TUyKue00qoMAUqFG e5XESj6nqiZbMDFj9ls7uhqmGvupFI3RyZ/mcXTnLQACNF4n1BwT+lQdKomv9yaZviyx CmTy5poQ0UuXuyood9L4lP9xBGmW6WrI+h+SlP18HzjBd6rNaOqWTk4O9fdF0B25CpA8 v1Yg== MIME-Version: 1.0 X-Received: by 10.112.184.198 with SMTP id ew6mr4936556lbc.71.1423157095027; Thu, 05 Feb 2015 09:24:55 -0800 (PST) Received: by 10.25.150.148 with HTTP; Thu, 5 Feb 2015 09:24:54 -0800 (PST) In-Reply-To: <1422594798-13375-1-git-send-email-henryc.chen@mediatek.com> References: <1422594798-13375-1-git-send-email-henryc.chen@mediatek.com> Date: Thu, 5 Feb 2015 18:24:54 +0100 Message-ID: Subject: Re: [PATCH v4 0/7] clk: Add common clock support for Mediatek MT8135 and MT8173. From: Matthias Brugger To: Henry Chen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150205_092517_788827_A4BD5BC8 X-CRM114-Status: GOOD ( 24.37 ) X-Spam-Score: -0.8 (/) Cc: Mark Rutland , James Liao , Vladimir Murzin , Mike Turquette , Pawel Moll , srv_heupstream , Ian Campbell , Catalin Marinas , Sascha Hauer , Ashwin Chaugule , "linux-kernel@vger.kernel.org" , "Joe.C" , "devicetree@vger.kernel.org" , Rob Herring , linux-mediatek@lists.infradead.org, Sascha Hauer , Kumar Gala , Russell King , huang eddie , "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.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 Hi Henry, 2015-01-30 6:13 GMT+01:00 Henry Chen : > This patchset contains the initial common clock support for Mediatek SoCs. > Mediatek SoC's clock architecture comprises of various PLLs, dividers, muxes and clock gates. > > This patchset also contains a basic clock support for Mediatek MT8135 and MT8173. > > This driver is based on 3.19-rc1 + MT8135 and MT8173 basic support. > > Changes in v2: > - Re-ordered patchset. Fold include/dt-bindings and DT document in 1st patch. > > Changes in v3: > - Rebase to 3.19-rc1. > - Refine code. Remove unneed functions, debug logs and comments, and fine tune error logs. > > Changes in v4: > - Support MT8173 platform. > - Re-ordered patchset. driver/clk/Makefile in 2nd patch. > - Extract the common part definition(mtk_gate/mtk_pll/mtk_mux) from clk-mt8135.c/clk-mt8173.c to clk-mtk.c. > - Refine code. Rmove unnessacary debug information and unsed defines, add prefix "mtk_" for static functions. > - Remove flag CLK_IGNORE_UNUSED and set flag CLK_SET_RATE_PARENT on gate/mux/fixed-factor. > - Use spin_lock_irqsave(&clk_ops_lock, flags) instead of mtk_clk_lock. > - Example above include a node for the clock controller itself, followed by the i2c controller example above. You use pericfg and infracfg which will be used by other drivers as well. So please use syscon for this driver. As it is no longer a platform device it is present early in boot. The changes should look something like the patch beneath. Please beware that it does only show the general concept and may not even compile. I asked Sascha to implement the reset controller as part of the clk driver, as the registers addresses are mixed between both, clock and reset controller. Please coordinate with him to get them integrated (even as one series or as incremental series). > > James Liao (7): > clk: dts: mediatek: add Mediatek MT8135 clock bindings > clk: mediatek: Add initial common clock support for Mediatek SoCs. > clk: mediatek: Add basic clocks for Mediatek MT8135. > dts: mediatek: Enable clock support for Mediatek MT8135. > clk: dts: mediatek: add Mediatek MT8173 clock bindings > clk: mediatek: Add basic clocks for Mediatek MT8173. > dts: mediatek: Enable clock support for Mediatek MT8173. > > .../bindings/clock/mediatek,mt8135-clock.txt | 44 + > .../bindings/clock/mediatek,mt8173-clock.txt | 42 + > arch/arm/boot/dts/mt8135.dtsi | 47 + > arch/arm64/boot/dts/mediatek/mt8173.dtsi | 46 + > drivers/clk/Makefile | 1 + > drivers/clk/mediatek/Makefile | 3 + > drivers/clk/mediatek/clk-gate.c | 140 +++ > drivers/clk/mediatek/clk-gate.h | 49 + > drivers/clk/mediatek/clk-mt8135-pll.c | 860 ++++++++++++++++ > drivers/clk/mediatek/clk-mt8135-pll.h | 28 + > drivers/clk/mediatek/clk-mt8135.c | 866 +++++++++++++++++ > drivers/clk/mediatek/clk-mt8173-pll.c | 807 +++++++++++++++ > drivers/clk/mediatek/clk-mt8173-pll.h | 14 + > drivers/clk/mediatek/clk-mt8173.c | 1028 ++++++++++++++++++++ > drivers/clk/mediatek/clk-mtk.c | 154 +++ > drivers/clk/mediatek/clk-mtk.h | 132 +++ > drivers/clk/mediatek/clk-pll.c | 63 ++ > drivers/clk/mediatek/clk-pll.h | 52 + > include/dt-bindings/clock/mt8135-clk.h | 190 ++++ > include/dt-bindings/clock/mt8173-clk.h | 214 ++++ > 20 files changed, 4780 insertions(+) > create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt8135-clock.txt > create mode 100644 Documentation/devicetree/bindings/clock/mediatek,mt8173-clock.txt > create mode 100644 drivers/clk/mediatek/Makefile > create mode 100644 drivers/clk/mediatek/clk-gate.c > create mode 100644 drivers/clk/mediatek/clk-gate.h > create mode 100644 drivers/clk/mediatek/clk-mt8135-pll.c > create mode 100644 drivers/clk/mediatek/clk-mt8135-pll.h > create mode 100644 drivers/clk/mediatek/clk-mt8135.c > create mode 100644 drivers/clk/mediatek/clk-mt8173-pll.c > create mode 100644 drivers/clk/mediatek/clk-mt8173-pll.h > create mode 100644 drivers/clk/mediatek/clk-mt8173.c > create mode 100644 drivers/clk/mediatek/clk-mtk.c > create mode 100644 drivers/clk/mediatek/clk-mtk.h > create mode 100644 drivers/clk/mediatek/clk-pll.c > create mode 100644 drivers/clk/mediatek/clk-pll.h > create mode 100644 include/dt-bindings/clock/mt8135-clk.h > create mode 100644 include/dt-bindings/clock/mt8173-clk.h > > -- > 1.8.1.1.dirty > diff --git a/arch/arm/boot/dts/mt8135.dtsi b/arch/arm/boot/dts/mt8135.dtsi index 76562ba..886a816 100644 --- a/arch/arm/boot/dts/mt8135.dtsi +++ b/arch/arm/boot/dts/mt8135.dtsi @@ -128,7 +128,7 @@ infracfg: infracfg@10001000 { #address-cells = <1>; #size-cells = <1>; - compatible = "mediatek,mt8135-infracfg"; + compatible = "mediatek,mt8135-infracfg", "syscon"; reg = <0 0x10001000 0 0x1000>; #clock-cells = <1>; }; @@ -136,7 +136,7 @@ pericfg: pericfg@10003000 { #address-cells = <1>; #size-cells = <1>; - compatible = "mediatek,mt8135-pericfg"; + compatible = "mediatek,mt8135-pericfg", "syscon"; reg = <0 0x10003000 0 0x1000>; #clock-cells = <1>; }; diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index f05507a..8af91d9 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -28,11 +28,15 @@ static int mtk_cg_bit_is_cleared(struct clk_hw *hw) struct mtk_clk_gate *cg = to_clk_gate(hw); u32 mask; u32 val; + int ret; mask = BIT(cg->bit); - val = mask & readl(cg->sta_addr); + ret = regmap_read(cg->base, cg->sta_addr, &val); - return val == 0; + if (ret < 0) + return ret; + + return (val & mask) == 0; } static int mtk_cg_bit_is_set(struct clk_hw *hw) @@ -40,25 +44,29 @@ static int mtk_cg_bit_is_set(struct clk_hw *hw) struct mtk_clk_gate *cg = to_clk_gate(hw); u32 mask; u32 val; + int ret; mask = BIT(cg->bit); - val = mask & readl(cg->sta_addr); + ret = regmap_read(cg->base, cg->sta_addr, &val); + + if (ret < 0) + return ret; - return val != 0; + return (val & mask) != 0; } static void mtk_cg_set_bit(struct clk_hw *hw) { struct mtk_clk_gate *cg = to_clk_gate(hw); - writel_relaxed(BIT(cg->bit), cg->set_addr); + regmap_write(cg->base, cg->set_addr, BIT(cg->bit)); } static void mtk_cg_clr_bit(struct clk_hw *hw) { struct mtk_clk_gate *cg = to_clk_gate(hw); - writel_relaxed(BIT(cg->bit), cg->clr_addr); + regmap_write(cg->base, cg->clr_addr, BIT(cg->bit)); } static int mtk_cg_enable(struct clk_hw *hw) @@ -100,9 +108,10 @@ const struct clk_ops mtk_clk_gate_ops_setclr_inv = { struct clk *mtk_clk_register_gate( const char *name, const char *parent_name, - void __iomem *set_addr, - void __iomem *clr_addr, - void __iomem *sta_addr, + struct regmap *base, + int set_addr, + int clr_addr, + int sta_addr, u8 bit, const struct clk_ops *ops, spinlock_t *lock) @@ -124,6 +133,7 @@ struct clk *mtk_clk_register_gate( init.num_parents = parent_name ? 1 : 0; init.ops = ops; + cg->base = base; cg->set_addr = set_addr; cg->clr_addr = clr_addr; cg->sta_addr = sta_addr; diff --git a/drivers/clk/mediatek/clk-gate.h b/drivers/clk/mediatek/clk-gate.h index d67a574..75fcb6709 100644 --- a/drivers/clk/mediatek/clk-gate.h +++ b/drivers/clk/mediatek/clk-gate.h @@ -24,9 +24,10 @@ struct mtk_clk_gate { struct clk_hw hw; - void __iomem *set_addr; - void __iomem *clr_addr; - void __iomem *sta_addr; + struct regmap *base; + int set_addr; + int clr_addr; + int sta_addr; u8 bit; spinlock_t *lock; }; diff --git a/drivers/clk/mediatek/clk-mt8135.c b/drivers/clk/mediatek/clk-mt8135.c index e212bfd..d24dd3b 100644 --- a/drivers/clk/mediatek/clk-mt8135.c +++ b/drivers/clk/mediatek/clk-mt8135.c @@ -844,13 +844,13 @@ CLK_OF_DECLARE(mtk_infrasys, "mediatek,mt8135-infracfg", mtk_infrasys_init); static void __init mtk_pericfg_init(struct device_node *node) { struct clk_onecell_data *clk_data; - void __iomem *base; + static struct regmap *base; int r; - base = of_iomap(node, 0); - if (!base) { - pr_err("%s(): ioremap failed\n", __func__); - return; + base = syscon_node_to_regmap(node); + if (IS_ERR(base)) { + pr_err("%s(): failed to retrieve gpbr regmap, aborting.\n", __func__); + return -ENOMEM; } clk_data = mtk_alloc_clk_data(PERI_NR_CLK); @@ -862,5 +862,6 @@ static void __init mtk_pericfg_init(struct device_node *node) if (r) pr_err("%s(): could not register clock provider: %d\n", __func__, r); + mtk_register_softrst(np, 12, base, RK3288_SOFTRST); } CLK_OF_DECLARE(mtk_pericfg, "mediatek,mt8135-pericfg", mtk_pericfg_init); diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index ce4f2ac..0923a3a 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -46,7 +46,7 @@ void mtk_init_factors(struct mtk_fixed_factor *clks, int num, } } -void mtk_init_clk_gates(void __iomem *reg_base, +void mtk_init_clk_gates(struct regmap *base, struct mtk_gate *clks, int num, struct clk_onecell_data *clk_data, spinlock_t *lock) { @@ -57,9 +57,10 @@ void mtk_init_clk_gates(void __iomem *reg_base, struct mtk_gate *gate = &clks[i]; clk = mtk_clk_register_gate(gate->name, gate->parent_name, - reg_base + gate->regs->set_ofs, - reg_base + gate->regs->clr_ofs, - reg_base + gate->regs->sta_ofs, + base, + gate->regs->set_ofs, + gate->regs->clr_ofs, + gate->regs->sta_ofs, gate->shift, gate->ops, lock); if (IS_ERR(clk)) {