Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1450427
| From | Chen-Yu Tsai <wens@csie.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 7/9] clk: sunxi-ng: mux: Add clk notifier functions |
| Date | 2016-07-26 09:10 +0200 |
| Message-ID | <rZ4F3-7pO-17@gated-at.bofh.it> (permalink) |
| References | <rZ4F3-7pO-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On sunxi we support cpufreq by changing the clock rate of PLL-CPU.
It's possible the clock output of the PLL goes out of the CPU's
operational limits when the PLL's multipliers / dividers are changed
and it hasn't stabilized yet. This would result in the CPU hanging.
To circumvent this, we temporarily switch the CPU mux clock to another
stable clock before the rate change, and switch it back after the PLL
stabilizes. This is done with clk notifiers registered on the PLL.
This patch adds common functions for notifiers to reparent mux clocks.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
drivers/clk/sunxi-ng/ccu_mux.c | 36 ++++++++++++++++++++++++++++++++++++
drivers/clk/sunxi-ng/ccu_mux.h | 14 ++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c
index f96eabb5d1f3..8a6e9065cb85 100644
--- a/drivers/clk/sunxi-ng/ccu_mux.c
+++ b/drivers/clk/sunxi-ng/ccu_mux.c
@@ -8,7 +8,9 @@
* the License, or (at your option) any later version.
*/
+#include <linux/clk.h>
#include <linux/clk-provider.h>
+#include <linux/delay.h>
#include "ccu_gate.h"
#include "ccu_mux.h"
@@ -199,3 +201,37 @@ const struct clk_ops ccu_mux_ops = {
.determine_rate = __clk_mux_determine_rate,
.recalc_rate = ccu_mux_recalc_rate,
};
+
+/*
+ * This clock notifier is called when the frequency of the of the parent
+ * PLL clock is to be changed. The idea is to switch the parent to a
+ * stable clock, such as the main oscillator, while the PLL frequency
+ * stabilizes.
+ */
+static int ccu_mux_notifier_cb(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct ccu_mux_nb *mux = to_ccu_mux_nb(nb);
+ int ret = 0;
+
+ if (event == PRE_RATE_CHANGE) {
+ mux->original_index = ccu_mux_helper_get_parent(mux->common,
+ mux->cm);
+ ret = ccu_mux_helper_set_parent(mux->common, mux->cm,
+ mux->bypass_index);
+ } else if (event == POST_RATE_CHANGE) {
+ ret = ccu_mux_helper_set_parent(mux->common, mux->cm,
+ mux->original_index);
+ }
+
+ udelay(mux->delay_us);
+
+ return notifier_from_errno(ret);
+}
+
+int ccu_mux_notifier_register(struct clk *clk, struct ccu_mux_nb *mux_nb)
+{
+ mux_nb->clk_nb.notifier_call = ccu_mux_notifier_cb;
+
+ return clk_notifier_register(clk, &mux_nb->clk_nb);
+}
diff --git a/drivers/clk/sunxi-ng/ccu_mux.h b/drivers/clk/sunxi-ng/ccu_mux.h
index 28d16ec18d55..7ddd9b2c6dbc 100644
--- a/drivers/clk/sunxi-ng/ccu_mux.h
+++ b/drivers/clk/sunxi-ng/ccu_mux.h
@@ -98,4 +98,18 @@ int ccu_mux_helper_set_parent(struct ccu_common *common,
struct ccu_mux_internal *cm,
u8 index);
+struct ccu_mux_nb {
+ struct notifier_block clk_nb;
+ struct ccu_common *common;
+ struct ccu_mux_internal *cm;
+
+ u32 delay_us; /* How many us to wait after reparenting */
+ u8 bypass_index; /* Which parent to temporarily use */
+ u8 original_index; /* This is set by the notifier callback */
+};
+
+#define to_ccu_mux_nb(_nb) container_of(_nb, struct ccu_mux_nb, clk_nb)
+
+int ccu_mux_notifier_register(struct clk *clk, struct ccu_mux_nb *mux_nb);
+
#endif /* _CCU_MUX_H_ */
--
2.8.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/9] clk: sunxi-ng: Support A31/A31s CCU Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
[PATCH 2/9] clk: sunxi-ng: nk: Make ccu_nk_find_best static Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
Re: [PATCH 2/9] clk: sunxi-ng: nk: Make ccu_nk_find_best static Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-26 11:00 +0200
[PATCH 7/9] clk: sunxi-ng: mux: Add clk notifier functions Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
Re: [PATCH 7/9] clk: sunxi-ng: mux: Add clk notifier functions Chen-Yu Tsai <wens@csie.org> - 2016-07-27 09:40 +0200
Re: [PATCH 7/9] clk: sunxi-ng: mux: Add clk notifier functions Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-27 09:50 +0200
Re: [PATCH 7/9] clk: sunxi-ng: mux: Add clk notifier functions Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-27 09:40 +0200
[PATCH resend 1/9] clk: sunxi-ng: Fix inverted test condition in ccu_helper_wait_for_lock Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
Re: [PATCH resend 1/9] clk: sunxi-ng: Fix inverted test condition in ccu_helper_wait_for_lock Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-26 11:00 +0200
[PATCH 9/9] ARM: dts: sun6i: switch A31/A31s to new CCU clock bindings Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
[PATCH 3/9] clk: sunxi-ng: mux: Increase fixed pre-divider div size Chen-Yu Tsai <wens@csie.org> - 2016-07-26 09:10 +0200
Re: [PATCH 3/9] clk: sunxi-ng: mux: Increase fixed pre-divider div size Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-27 08:50 +0200
Re: [PATCH 8/9] clk: sunxi-ng: Add A31/A31s clocks Jean-Francois Moine <moinejf@free.fr> - 2016-07-26 10:40 +0200
Re: [PATCH 8/9] clk: sunxi-ng: Add A31/A31s clocks Rob Herring <robh@kernel.org> - 2016-07-27 17:00 +0200
Re: [PATCH 8/9] clk: sunxi-ng: Add A31/A31s clocks Maxime Ripard <maxime.ripard@free-electrons.com> - 2016-07-28 15:40 +0200
csiph-web