mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-23 15:32:33 +00:00
65de91a884
It keeps failing (R7800) with the stack trace below
BUG: scheduling while atomic: kworker/0:1/26/0x00000002
(unwind_backtrace) from [<c02121d0>] (show_stack+0x10/0x14)
(show_stack) from [<c03932e4>] (dump_stack+0x7c/0x9c)
(dump_stack) from [<c0239b90>] (__schedule_bug+0x5c/0x80)
(__schedule_bug) from [<c05b7260>] (__schedule+0x50/0x3f4)
(__schedule) from [<c05b76a8>] (schedule+0xa4/0xd4)
(schedule) from [<c05ba430>] (schedule_hrtimeout_range_clock+0xc8/0x100)
(schedule_hrtimeout_range_clock) from [<c05ba480>]
(schedule_hrtimeout_range+0x18/0x20)
(schedule_hrtimeout_range) from [<c05b9f78>] (usleep_range+0x48/0x50)
(usleep_range) from [<c03f333c>] (__clk_hfpll_enable+0x44/0xd0)
(__clk_hfpll_enable) from [<c03f3474>] (clk_hfpll_set_rate+0xac/0xc4)
(clk_hfpll_set_rate) from [<c03ec390>] (clk_change_rate+0xf4/0x1fc)
(clk_change_rate) from [<c03ec510>] (clk_core_set_rate_nolock+0x78/0x94)
(clk_core_set_rate_nolock) from [<c03ec54c>] (clk_set_rate+0x20/0x30)
(clk_set_rate) from [<c0424168>] (dev_pm_opp_set_rate+0x190/0x26c)
(dev_pm_opp_set_rate) from [<c04a8548>] (set_target+0x40/0x108)
(set_target) from [<c04a4.140>] (__cpufreq_driver_target+0x3f4/0x488)
(__cpufreq_driver_target) from [<c04a7494>] (od_dbs_timer+0xcc/0x154)
(od_dbs_timer) from [<c04a7998>] (dbs_work_handler+0x2c/0x54)
(dbs_work_handler) from [<c02309e8>] (process_one_work+0x1c0/0x2f0)
(process_one_work) from [<c02319a8>] (worker_thread+0x2a4/0x404)
(worker_thread) from [<c0235944>] (kthread+0xd8/0xe8)
(kthread) from [<c020eef0>] (ret_from_fork+0x14/0x24)
Signed-off-by: Marc Benoit <marcb62185@gmail.com>
[slh: rebase for kernel v4.14 as well]
Signed-off-by: Stefan Lippers-Hollmann <s.l-h@gmx.de>
(cherry picked from commit e40db2907e
)
353 lines
9.3 KiB
Diff
353 lines
9.3 KiB
Diff
From patchwork Fri Dec 8 09:42:21 2017
|
|
Content-Type: text/plain; charset="utf-8"
|
|
MIME-Version: 1.0
|
|
Content-Transfer-Encoding: 7bit
|
|
Subject: [v4,03/12] clk: qcom: Add support for High-Frequency PLLs (HFPLLs)
|
|
From: Sricharan R <sricharan@codeaurora.org>
|
|
X-Patchwork-Id: 10102083
|
|
Message-Id: <1512726150-7204-4-git-send-email-sricharan@codeaurora.org>
|
|
To: mturquette@baylibre.com, sboyd@codeaurora.org,
|
|
devicetree@vger.kernel.org, linux-pm@vger.kernel.org,
|
|
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
|
|
viresh.kumar@linaro.org, linux-arm-kernel@lists.infradead.org
|
|
Cc: sricharan@codeaurora.org
|
|
Date: Fri, 8 Dec 2017 15:12:21 +0530
|
|
|
|
From: Stephen Boyd <sboyd@codeaurora.org>
|
|
|
|
HFPLLs are the main frequency source for Krait CPU clocks. Add
|
|
support for changing the rate of these PLLs.
|
|
|
|
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
|
|
---
|
|
drivers/clk/qcom/Makefile | 1 +
|
|
drivers/clk/qcom/clk-hfpll.c | 253 +++++++++++++++++++++++++++++++++++++++++++
|
|
drivers/clk/qcom/clk-hfpll.h | 54 +++++++++
|
|
3 files changed, 308 insertions(+)
|
|
create mode 100644 drivers/clk/qcom/clk-hfpll.c
|
|
create mode 100644 drivers/clk/qcom/clk-hfpll.h
|
|
|
|
--- a/drivers/clk/qcom/Makefile
|
|
+++ b/drivers/clk/qcom/Makefile
|
|
@@ -10,6 +10,7 @@ clk-qcom-y += clk-rcg2.o
|
|
clk-qcom-y += clk-branch.o
|
|
clk-qcom-y += clk-regmap-divider.o
|
|
clk-qcom-y += clk-regmap-mux.o
|
|
+clk-qcom-y += clk-hfpll.o
|
|
clk-qcom-y += reset.o
|
|
clk-qcom-$(CONFIG_QCOM_GDSC) += gdsc.o
|
|
|
|
--- /dev/null
|
|
+++ b/drivers/clk/qcom/clk-hfpll.c
|
|
@@ -0,0 +1,253 @@
|
|
+/*
|
|
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
+ * it under the terms of the GNU General Public License version 2 and
|
|
+ * only version 2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
+ * GNU General Public License for more details.
|
|
+ */
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/export.h>
|
|
+#include <linux/regmap.h>
|
|
+#include <linux/delay.h>
|
|
+#include <linux/err.h>
|
|
+#include <linux/clk-provider.h>
|
|
+#include <linux/spinlock.h>
|
|
+
|
|
+#include "clk-regmap.h"
|
|
+#include "clk-hfpll.h"
|
|
+
|
|
+#define PLL_OUTCTRL BIT(0)
|
|
+#define PLL_BYPASSNL BIT(1)
|
|
+#define PLL_RESET_N BIT(2)
|
|
+
|
|
+/* Initialize a HFPLL at a given rate and enable it. */
|
|
+static void __clk_hfpll_init_once(struct clk_hw *hw)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+
|
|
+ if (likely(h->init_done))
|
|
+ return;
|
|
+
|
|
+ /* Configure PLL parameters for integer mode. */
|
|
+ if (hd->config_val)
|
|
+ regmap_write(regmap, hd->config_reg, hd->config_val);
|
|
+ regmap_write(regmap, hd->m_reg, 0);
|
|
+ regmap_write(regmap, hd->n_reg, 1);
|
|
+
|
|
+ if (hd->user_reg) {
|
|
+ u32 regval = hd->user_val;
|
|
+ unsigned long rate;
|
|
+
|
|
+ rate = clk_hw_get_rate(hw);
|
|
+
|
|
+ /* Pick the right VCO. */
|
|
+ if (hd->user_vco_mask && rate > hd->low_vco_max_rate)
|
|
+ regval |= hd->user_vco_mask;
|
|
+ regmap_write(regmap, hd->user_reg, regval);
|
|
+ }
|
|
+
|
|
+ if (hd->droop_reg)
|
|
+ regmap_write(regmap, hd->droop_reg, hd->droop_val);
|
|
+
|
|
+ h->init_done = true;
|
|
+}
|
|
+
|
|
+static void __clk_hfpll_enable(struct clk_hw *hw)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ u32 val;
|
|
+
|
|
+ __clk_hfpll_init_once(hw);
|
|
+
|
|
+ /* Disable PLL bypass mode. */
|
|
+ regmap_update_bits(regmap, hd->mode_reg, PLL_BYPASSNL, PLL_BYPASSNL);
|
|
+
|
|
+ /*
|
|
+ * H/W requires a 5us delay between disabling the bypass and
|
|
+ * de-asserting the reset. Delay 10us just to be safe.
|
|
+ */
|
|
+ udelay(10);
|
|
+
|
|
+ /* De-assert active-low PLL reset. */
|
|
+ regmap_update_bits(regmap, hd->mode_reg, PLL_RESET_N, PLL_RESET_N);
|
|
+
|
|
+ /* Wait for PLL to lock. */
|
|
+ if (hd->status_reg) {
|
|
+ do {
|
|
+ regmap_read(regmap, hd->status_reg, &val);
|
|
+ } while (!(val & BIT(hd->lock_bit)));
|
|
+ } else {
|
|
+ udelay(60);
|
|
+ }
|
|
+
|
|
+ /* Enable PLL output. */
|
|
+ regmap_update_bits(regmap, hd->mode_reg, PLL_OUTCTRL, PLL_OUTCTRL);
|
|
+}
|
|
+
|
|
+/* Enable an already-configured HFPLL. */
|
|
+static int clk_hfpll_enable(struct clk_hw *hw)
|
|
+{
|
|
+ unsigned long flags;
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ u32 mode;
|
|
+
|
|
+ spin_lock_irqsave(&h->lock, flags);
|
|
+ regmap_read(regmap, hd->mode_reg, &mode);
|
|
+ if (!(mode & (PLL_BYPASSNL | PLL_RESET_N | PLL_OUTCTRL)))
|
|
+ __clk_hfpll_enable(hw);
|
|
+ spin_unlock_irqrestore(&h->lock, flags);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static void __clk_hfpll_disable(struct clk_hfpll *h)
|
|
+{
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+
|
|
+ /*
|
|
+ * Disable the PLL output, disable test mode, enable the bypass mode,
|
|
+ * and assert the reset.
|
|
+ */
|
|
+ regmap_update_bits(regmap, hd->mode_reg,
|
|
+ PLL_BYPASSNL | PLL_RESET_N | PLL_OUTCTRL, 0);
|
|
+}
|
|
+
|
|
+static void clk_hfpll_disable(struct clk_hw *hw)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ unsigned long flags;
|
|
+
|
|
+ spin_lock_irqsave(&h->lock, flags);
|
|
+ __clk_hfpll_disable(h);
|
|
+ spin_unlock_irqrestore(&h->lock, flags);
|
|
+}
|
|
+
|
|
+static long clk_hfpll_round_rate(struct clk_hw *hw, unsigned long rate,
|
|
+ unsigned long *parent_rate)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ unsigned long rrate;
|
|
+
|
|
+ rate = clamp(rate, hd->min_rate, hd->max_rate);
|
|
+
|
|
+ rrate = DIV_ROUND_UP(rate, *parent_rate) * *parent_rate;
|
|
+ if (rrate > hd->max_rate)
|
|
+ rrate -= *parent_rate;
|
|
+
|
|
+ return rrate;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * For optimization reasons, assumes no downstream clocks are actively using
|
|
+ * it.
|
|
+ */
|
|
+static int clk_hfpll_set_rate(struct clk_hw *hw, unsigned long rate,
|
|
+ unsigned long parent_rate)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ unsigned long flags;
|
|
+ u32 l_val, val;
|
|
+ bool enabled;
|
|
+
|
|
+ l_val = rate / parent_rate;
|
|
+
|
|
+ spin_lock_irqsave(&h->lock, flags);
|
|
+
|
|
+ enabled = __clk_is_enabled(hw->clk);
|
|
+ if (enabled)
|
|
+ __clk_hfpll_disable(h);
|
|
+
|
|
+ /* Pick the right VCO. */
|
|
+ if (hd->user_reg && hd->user_vco_mask) {
|
|
+ regmap_read(regmap, hd->user_reg, &val);
|
|
+ if (rate <= hd->low_vco_max_rate)
|
|
+ val &= ~hd->user_vco_mask;
|
|
+ else
|
|
+ val |= hd->user_vco_mask;
|
|
+ regmap_write(regmap, hd->user_reg, val);
|
|
+ }
|
|
+
|
|
+ regmap_write(regmap, hd->l_reg, l_val);
|
|
+
|
|
+ if (enabled)
|
|
+ __clk_hfpll_enable(hw);
|
|
+
|
|
+ spin_unlock_irqrestore(&h->lock, flags);
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+static unsigned long clk_hfpll_recalc_rate(struct clk_hw *hw,
|
|
+ unsigned long parent_rate)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ u32 l_val;
|
|
+
|
|
+ regmap_read(regmap, hd->l_reg, &l_val);
|
|
+
|
|
+ return l_val * parent_rate;
|
|
+}
|
|
+
|
|
+static void clk_hfpll_init(struct clk_hw *hw)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ u32 mode, status;
|
|
+
|
|
+ regmap_read(regmap, hd->mode_reg, &mode);
|
|
+ if (mode != (PLL_BYPASSNL | PLL_RESET_N | PLL_OUTCTRL)) {
|
|
+ __clk_hfpll_init_once(hw);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (hd->status_reg) {
|
|
+ regmap_read(regmap, hd->status_reg, &status);
|
|
+ if (!(status & BIT(hd->lock_bit))) {
|
|
+ WARN(1, "HFPLL %s is ON, but not locked!\n",
|
|
+ __clk_get_name(hw->clk));
|
|
+ clk_hfpll_disable(hw);
|
|
+ __clk_hfpll_init_once(hw);
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
+static int hfpll_is_enabled(struct clk_hw *hw)
|
|
+{
|
|
+ struct clk_hfpll *h = to_clk_hfpll(hw);
|
|
+ struct hfpll_data const *hd = h->d;
|
|
+ struct regmap *regmap = h->clkr.regmap;
|
|
+ u32 mode;
|
|
+
|
|
+ regmap_read(regmap, hd->mode_reg, &mode);
|
|
+ mode &= 0x7;
|
|
+ return mode == (PLL_BYPASSNL | PLL_RESET_N | PLL_OUTCTRL);
|
|
+}
|
|
+
|
|
+const struct clk_ops clk_ops_hfpll = {
|
|
+ .enable = clk_hfpll_enable,
|
|
+ .disable = clk_hfpll_disable,
|
|
+ .is_enabled = hfpll_is_enabled,
|
|
+ .round_rate = clk_hfpll_round_rate,
|
|
+ .set_rate = clk_hfpll_set_rate,
|
|
+ .recalc_rate = clk_hfpll_recalc_rate,
|
|
+ .init = clk_hfpll_init,
|
|
+};
|
|
+EXPORT_SYMBOL_GPL(clk_ops_hfpll);
|
|
--- /dev/null
|
|
+++ b/drivers/clk/qcom/clk-hfpll.h
|
|
@@ -0,0 +1,54 @@
|
|
+/*
|
|
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
|
|
+ *
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
+ * it under the terms of the GNU General Public License version 2 and
|
|
+ * only version 2 as published by the Free Software Foundation.
|
|
+ *
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
+ * GNU General Public License for more details.
|
|
+ */
|
|
+#ifndef __QCOM_CLK_HFPLL_H__
|
|
+#define __QCOM_CLK_HFPLL_H__
|
|
+
|
|
+#include <linux/clk-provider.h>
|
|
+#include <linux/spinlock.h>
|
|
+#include "clk-regmap.h"
|
|
+
|
|
+struct hfpll_data {
|
|
+ u32 mode_reg;
|
|
+ u32 l_reg;
|
|
+ u32 m_reg;
|
|
+ u32 n_reg;
|
|
+ u32 user_reg;
|
|
+ u32 droop_reg;
|
|
+ u32 config_reg;
|
|
+ u32 status_reg;
|
|
+ u8 lock_bit;
|
|
+
|
|
+ u32 droop_val;
|
|
+ u32 config_val;
|
|
+ u32 user_val;
|
|
+ u32 user_vco_mask;
|
|
+ unsigned long low_vco_max_rate;
|
|
+
|
|
+ unsigned long min_rate;
|
|
+ unsigned long max_rate;
|
|
+};
|
|
+
|
|
+struct clk_hfpll {
|
|
+ struct hfpll_data const *d;
|
|
+ int init_done;
|
|
+
|
|
+ struct clk_regmap clkr;
|
|
+ spinlock_t lock;
|
|
+};
|
|
+
|
|
+#define to_clk_hfpll(_hw) \
|
|
+ container_of(to_clk_regmap(_hw), struct clk_hfpll, clkr)
|
|
+
|
|
+extern const struct clk_ops clk_ops_hfpll;
|
|
+
|
|
+#endif
|