From: Paul Cercueil <paul@crapouillou.net>
To: Ralf Baechle <ralf@linux-mips.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@codeaurora.org>,
Rob Herring <robh+dt@kernel.org>
Cc: Paul Burton <paul.burton@imgtec.com>,
Maarten ter Huurne <maarten@treewalker.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mips@linux-mips.org, linux-clk@vger.kernel.org,
Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH v2 04/17] clk: ingenic: Add code to enable/disable PLLs
Date: Tue, 20 Jun 2017 17:18:42 +0200 [thread overview]
Message-ID: <20170620151855.19399-4-paul@crapouillou.net> (raw)
In-Reply-To: <20170620151855.19399-1-paul@crapouillou.net>
This commit permits the PLLs to be dynamically enabled and disabled when
their children clocks are enabled and disabled.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
drivers/clk/ingenic/cgu.c | 89 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 74 insertions(+), 15 deletions(-)
v2: No change
diff --git a/drivers/clk/ingenic/cgu.c b/drivers/clk/ingenic/cgu.c
index 75b083ba294c..08613b803b14 100644
--- a/drivers/clk/ingenic/cgu.c
+++ b/drivers/clk/ingenic/cgu.c
@@ -107,9 +107,6 @@ ingenic_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
if (bypass)
return parent_rate;
- if (!enable)
- return 0;
-
for (od = 0; od < pll_info->od_max; od++) {
if (pll_info->od_encoding[od] == od_enc)
break;
@@ -153,17 +150,25 @@ ingenic_pll_calc(const struct ingenic_cgu_clk_info *clk_info,
return div_u64((u64)parent_rate * m, n * od);
}
-static long
-ingenic_pll_round_rate(struct clk_hw *hw, unsigned long req_rate,
- unsigned long *prate)
+static inline const struct ingenic_cgu_clk_info *to_clk_info(
+ struct ingenic_clk *ingenic_clk)
{
- struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
struct ingenic_cgu *cgu = ingenic_clk->cgu;
const struct ingenic_cgu_clk_info *clk_info;
clk_info = &cgu->clock_info[ingenic_clk->idx];
BUG_ON(clk_info->type != CGU_CLK_PLL);
+ return clk_info;
+}
+
+static long
+ingenic_pll_round_rate(struct clk_hw *hw, unsigned long req_rate,
+ unsigned long *prate)
+{
+ struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
+ const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
+
return ingenic_pll_calc(clk_info, req_rate, *prate, NULL, NULL, NULL);
}
@@ -171,19 +176,14 @@ static int
ingenic_pll_set_rate(struct clk_hw *hw, unsigned long req_rate,
unsigned long parent_rate)
{
- const unsigned timeout = 100;
struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
struct ingenic_cgu *cgu = ingenic_clk->cgu;
- const struct ingenic_cgu_clk_info *clk_info;
- const struct ingenic_cgu_pll_info *pll_info;
+ const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
+ const struct ingenic_cgu_pll_info *pll_info = &clk_info->pll;
unsigned long rate, flags;
- unsigned m, n, od, i;
+ unsigned int m, n, od;
u32 ctl;
- clk_info = &cgu->clock_info[ingenic_clk->idx];
- BUG_ON(clk_info->type != CGU_CLK_PLL);
- pll_info = &clk_info->pll;
-
rate = ingenic_pll_calc(clk_info, req_rate, parent_rate,
&m, &n, &od);
if (rate != req_rate)
@@ -202,6 +202,26 @@ ingenic_pll_set_rate(struct clk_hw *hw, unsigned long req_rate,
ctl &= ~(GENMASK(pll_info->od_bits - 1, 0) << pll_info->od_shift);
ctl |= pll_info->od_encoding[od - 1] << pll_info->od_shift;
+ writel(ctl, cgu->base + pll_info->reg);
+ spin_unlock_irqrestore(&cgu->lock, flags);
+
+ return 0;
+}
+
+static int ingenic_pll_enable(struct clk_hw *hw)
+{
+ struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
+ struct ingenic_cgu *cgu = ingenic_clk->cgu;
+ const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
+ const struct ingenic_cgu_pll_info *pll_info = &clk_info->pll;
+ const unsigned int timeout = 100;
+ unsigned long flags;
+ unsigned int i;
+ u32 ctl;
+
+ spin_lock_irqsave(&cgu->lock, flags);
+ ctl = readl(cgu->base + pll_info->reg);
+
ctl &= ~BIT(pll_info->bypass_bit);
ctl |= BIT(pll_info->enable_bit);
@@ -223,10 +243,48 @@ ingenic_pll_set_rate(struct clk_hw *hw, unsigned long req_rate,
return 0;
}
+static void ingenic_pll_disable(struct clk_hw *hw)
+{
+ struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
+ struct ingenic_cgu *cgu = ingenic_clk->cgu;
+ const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
+ const struct ingenic_cgu_pll_info *pll_info = &clk_info->pll;
+ unsigned long flags;
+ u32 ctl;
+
+ spin_lock_irqsave(&cgu->lock, flags);
+ ctl = readl(cgu->base + pll_info->reg);
+
+ ctl &= ~BIT(pll_info->enable_bit);
+
+ writel(ctl, cgu->base + pll_info->reg);
+ spin_unlock_irqrestore(&cgu->lock, flags);
+}
+
+static int ingenic_pll_is_enabled(struct clk_hw *hw)
+{
+ struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
+ struct ingenic_cgu *cgu = ingenic_clk->cgu;
+ const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
+ const struct ingenic_cgu_pll_info *pll_info = &clk_info->pll;
+ unsigned long flags;
+ u32 ctl;
+
+ spin_lock_irqsave(&cgu->lock, flags);
+ ctl = readl(cgu->base + pll_info->reg);
+ spin_unlock_irqrestore(&cgu->lock, flags);
+
+ return !!(ctl & BIT(pll_info->enable_bit));
+}
+
static const struct clk_ops ingenic_pll_ops = {
.recalc_rate = ingenic_pll_recalc_rate,
.round_rate = ingenic_pll_round_rate,
.set_rate = ingenic_pll_set_rate,
+
+ .enable = ingenic_pll_enable,
+ .disable = ingenic_pll_disable,
+ .is_enabled = ingenic_pll_is_enabled,
};
/*
@@ -601,6 +659,7 @@ static int ingenic_register_clock(struct ingenic_cgu *cgu, unsigned idx)
}
} else if (caps & CGU_CLK_PLL) {
clk_init.ops = &ingenic_pll_ops;
+ clk_init.flags |= CLK_SET_RATE_GATE;
caps &= ~CGU_CLK_PLL;
--
2.11.0
next prev parent reply other threads:[~2017-06-20 15:22 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-07 20:04 [PATCH 00/15] Ingenic JZ4770 and GCW Zero patchset Paul Cercueil
2017-06-07 20:04 ` [PATCH 01/15] clk: ingenic: Fix recalc_rate for clocks with fixed divider Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 01/17] clk: ingenic: Use const pointer to clk_ops in struct Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 02/17] clk: ingenic: Fix recalc_rate for clocks with fixed divider Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 03/17] clk: ingenic: support PLLs with no bypass bit Paul Cercueil
2017-06-20 15:18 ` Paul Cercueil [this message]
2017-06-20 15:18 ` [PATCH v2 05/17] clk: Add Ingenic jz4770 CGU driver Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 06/17] serial: core: Make uart_parse_options take const char* argument Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 07/17] serial: 8250_ingenic: Add support for the JZ4770 SoC Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 08/17] serial: 8250_ingenic: Parse earlycon options Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 09/17] MIPS: Setup boot_command_line before plat_mem_setup Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 10/17] MIPS: ingenic: Use common cmdline handling code Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 11/17] MIPS: platform: add machtype IDs for more Ingenic SoCs Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 12/17] MIPS: ingenic: Add machine info for supported boards Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 13/17] MIPS: ingenic: Initial JZ4770 support Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 14/17] MIPS: JZ4770: Work around config2 misreporting associativity Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 15/17] MIPS: JZ4770: Workaround for corrupted DMA transfers Paul Cercueil
2017-06-22 7:21 ` Marcin Nowakowski
2017-06-26 13:32 ` Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 16/17] devicetree/bindings: Add GCW vendor prefix Paul Cercueil
2017-06-20 15:18 ` [PATCH v2 17/17] MIPS: ingenic: Initial GCW Zero support Paul Cercueil
2017-06-21 21:50 ` [PATCH v2 01/17] clk: ingenic: Use const pointer to clk_ops in struct Stephen Boyd
2017-06-26 13:34 ` Paul Cercueil
2017-07-02 16:29 ` [PATCH v3 00/18] JZ4770 support Paul Cercueil
2017-07-02 16:29 ` [PATCH v3 01/18] clk: ingenic: Use const pointer to clk_ops in struct Paul Cercueil
2017-07-12 23:20 ` Stephen Boyd
2017-07-13 10:07 ` [PATCH v3 01/18] clk: ingenic: Use const pointer to clk_ops in struct, Paul Cercueil
2017-07-13 11:49 ` [PATCH v3 01/18] clk: ingenic: Use const pointer to clk_ops in struct Ralf Baechle
2017-07-13 17:50 ` Stephen Boyd
2017-12-28 13:56 ` [PATCH v4 00/15] Ingenic JZ4770 and GCW Zero support Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 01/15] clk: ingenic: Use const pointer to clk_ops in struct Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 02/15] clk: ingenic: Fix recalc_rate for clocks with fixed divider Paul Cercueil
2017-12-28 18:36 ` Stephen Boyd
2017-12-28 13:56 ` [PATCH v4 03/15] clk: ingenic: support PLLs with no bypass bit Paul Cercueil
2017-12-28 18:36 ` Stephen Boyd
2017-12-28 13:56 ` [PATCH v4 04/15] clk: ingenic: Add code to enable/disable PLLs Paul Cercueil
2017-12-28 18:39 ` Stephen Boyd
2017-12-28 13:56 ` [PATCH v4 05/15] dt-bindings: clock: Add jz4770-cgu.h header Paul Cercueil
2017-12-28 18:36 ` Stephen Boyd
2017-12-28 13:56 ` [PATCH v4 06/15] clk: Add Ingenic jz4770 CGU driver Paul Cercueil
2017-12-28 18:38 ` Stephen Boyd
2017-12-29 12:55 ` Philippe Ombredanne
2017-12-29 15:02 ` Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 07/15] MIPS: Setup boot_command_line before plat_mem_setup Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 08/15] MIPS: ingenic: Use common cmdline handling code Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 09/15] MIPS: platform: add machtype IDs for more Ingenic SoCs Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 10/15] MIPS: ingenic: Add machine info for supported boards Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 11/15] MIPS: ingenic: Initial JZ4770 support Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 12/15] MIPS: JZ4770: Work around config2 misreporting associativity Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 13/15] MIPS: JZ4770: Workaround for corrupted DMA transfers Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 14/15] devicetree/bindings: Add GCW vendor prefix Paul Cercueil
2017-12-28 13:56 ` [PATCH v4 15/15] MIPS: ingenic: Initial GCW Zero support Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 02/18] clk: ingenic: Fix recalc_rate for clocks with fixed divider Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 03/18] clk: ingenic: support PLLs with no bypass bit Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 04/18] clk: ingenic: Add code to enable/disable PLLs Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 05/18] dt-bindings: clock: Add jz4770-cgu.h header Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 06/18] clk: Add Ingenic jz4770 CGU driver Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 07/18] serial: core: Make uart_parse_options take const char* argument Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 08/18] serial: 8250_ingenic: Add support for the JZ4770 SoC Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 09/18] serial: 8250_ingenic: Parse earlycon options Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 10/18] MIPS: Setup boot_command_line before plat_mem_setup Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 11/18] MIPS: ingenic: Use common cmdline handling code Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 12/18] MIPS: platform: add machtype IDs for more Ingenic SoCs Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 13/18] MIPS: ingenic: Add machine info for supported boards Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 14/18] MIPS: ingenic: Initial JZ4770 support Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 15/18] MIPS: JZ4770: Work around config2 misreporting associativity Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 16/18] MIPS: JZ4770: Workaround for corrupted DMA transfers Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 17/18] devicetree/bindings: Add GCW vendor prefix Paul Cercueil
2017-07-02 16:30 ` [PATCH v3 18/18] MIPS: ingenic: Initial GCW Zero support Paul Cercueil
2017-06-07 20:04 ` [PATCH 02/15] clk: ingenic: support PLLs with no bypass bit Paul Cercueil
2017-06-07 20:04 ` [PATCH 03/15] clk: ingenic: Add code to enable/disable PLLs Paul Cercueil
2017-06-07 20:04 ` [PATCH 04/15] clk: Add Ingenic jz4770 CGU driver Paul Cercueil
2017-06-07 20:59 ` Stephen Boyd
2017-06-08 8:40 ` Maarten ter Huurne
2017-06-08 21:10 ` Paul Cercueil
2017-06-26 13:50 ` Paul Cercueil
2017-06-26 22:49 ` Stephen Boyd
2017-06-07 20:04 ` [PATCH 05/15] serial: 8250_ingenic: Add support for the JZ4770 SoC Paul Cercueil
2017-06-09 14:22 ` Rob Herring
2017-06-07 20:04 ` [PATCH 06/15] serial: 8250_ingenic: Parse earlycon options Paul Cercueil
2017-06-08 7:31 ` Marcin Nowakowski
2017-06-08 21:12 ` Paul Cercueil
2017-06-07 20:04 ` [PATCH 07/15] MIPS: Setup boot_command_line before plat_mem_setup Paul Cercueil
2017-06-07 20:04 ` [PATCH 08/15] MIPS: ingenic: Use common cmdline handling code Paul Cercueil
2017-06-07 20:04 ` [PATCH 09/15] MIPS: platform: add machtype IDs for more Ingenic SoCs Paul Cercueil
2017-06-07 20:04 ` [PATCH 10/15] MIPS: ingenic: Add machine info for supported boards Paul Cercueil
2017-06-07 20:04 ` [PATCH 11/15] MIPS: ingenic: Initial JZ4770 support Paul Cercueil
2017-06-07 20:04 ` [PATCH 12/15] MIPS: JZ4770: Work around config2 misreporting associativity Paul Cercueil
2017-06-07 20:04 ` [PATCH 13/15] MIPS: JZ4770: Workaround for corrupted DMA transfers Paul Cercueil
2017-06-07 20:04 ` [PATCH 14/15] devicetree/bindings: Add GCW vendor prefix Paul Cercueil
2017-06-09 14:24 ` Rob Herring
2017-06-07 20:04 ` [PATCH 15/15] MIPS: ingenic: Initial GCW Zero support Paul Cercueil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170620151855.19399-4-paul@crapouillou.net \
--to=paul@crapouillou.net \
--cc=devicetree@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=maarten@treewalker.org \
--cc=mturquette@baylibre.com \
--cc=paul.burton@imgtec.com \
--cc=ralf@linux-mips.org \
--cc=robh+dt@kernel.org \
--cc=sboyd@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®