Skip to contentSkip to conversation

Misc patches to support clocks for SDM845

PATCH Applied Amit Nischal 2 participants 14 messages Mar 8, 2018 – Apr 9, 2018

Subsystems (4)

v2 of 7 Applied Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Misc patches to support clocks for SDM845

Changes in v2:
Fixup for recalc_rate ops for clk_rcg2_shared_ops:
There could be few scenarios where shared clocks are configured at rate other than CXO by boot. In those cases there would be a mismatch between the rate calculated by the recalc shared ops and the actual HW register configuration. Fix the same by adding an additional check to read current src from CFG register and make a decision based on that.

Changes in v1:
https://lkml.org/lkml/2018/1/31/209

This patch series does the miscellaneous changes to support clock nodes for SDM845. Below are the major changes for which the existing code does not have support.

1. Clear hardware clock control bit of RCGs where HW clock control bit is set by default so that software can control those root clocks.
2. Introduces clk_rcg2_shared_ops to support clock controller drivers for SDM845. With new shared ops, RCGs with shared branches will be configured to a safe source in disable path and actual RCG update configuration will be done in enable path instead of doing config update in set_rate. In set_rate(), just cache the rate instead of doing actual configuration update. Also each RCG in clock controller driver will have their own safe configuration frequency table to switch to safe frequency.
3. Add support for controlling Fabia PLL for which the support is not available in existing alpha PLL code.
4. Add Global Clock controller (GCC) driver for SDM845. This should allow most non-multimedia device drivers to probe and control their clocks.

Amit Nischal (3):
clk: qcom: Clear hardware clock control bit of RCG
clk: qcom: Configure the RCGs to a safe source as needed
clk: qcom: Add support for controlling Fabia PLL

Taniya Das (1):
clk: qcom: Add Global Clock controller (GCC) driver for SDM845

 .../devicetree/bindings/clock/qcom,gcc.txt         |    1 +
 drivers/clk/qcom/Kconfig                           |   11 +
 drivers/clk/qcom/Makefile                          |    1 +
 drivers/clk/qcom/clk-alpha-pll.c                   |  324 +-
 drivers/clk/qcom/clk-alpha-pll.h                   |   18 +-
 drivers/clk/qcom/clk-rcg.h                         |    8 +-
 drivers/clk/qcom/clk-rcg2.c                        |  160 +-
 drivers/clk/qcom/gcc-sdm845.c                      | 3619 ++++++++++++++++++++
 include/dt-bindings/clock/qcom,gcc-sdm845.h        |  242 ++
 9 files changed, 4373 insertions(+), 11 deletions(-)
 create mode 100644 drivers/clk/qcom/gcc-sdm845.c
 create mode 100644 include/dt-bindings/clock/qcom,gcc-sdm845.h

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#1 lore raw

PATCH v2 1/4 clk: qcom: Clear hardware clock control bit of RCG

For upcoming targets like sdm845, POR value of the hardware clock control bit is set for most of root clocks which needs to be cleared for software to be able to control. For older targets like MSM8996, this bit is reserved bit and having POR value as 0 so this patch will work for the older targets too. So update the configuration mask to take care of the same to clear hardware clock control bit.

---
 drivers/clk/qcom/clk-rcg2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg2.c +3 -2
index bbeaf9c..e63db10 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -42,6 +42,7 @@
 #define CFG_MODE_SHIFT		12
 #define CFG_MODE_MASK		(0x3 << CFG_MODE_SHIFT)
 #define CFG_MODE_DUAL_EDGE	(0x2 << CFG_MODE_SHIFT)
+#define CFG_HW_CLK_CTRL_MASK	BIT(20)
 
 #define M_REG			0x8
 #define N_REG			0xc
@@ -276,7 +277,7 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
 	}
 
 	mask = BIT(rcg->hid_width) - 1;
-	mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
+	mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
 	cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
 	cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
 	if (rcg->mnd_width && f->n && (f->m != f->n))

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

maintainer
#2 lore raw

Re: [PATCH v2 1/4] clk: qcom: Clear hardware clock control bit of RCG

Quoting Amit Nischal (2018-03-07 23:18:12)

Quoted 17 lines

For upcoming targets like sdm845, POR value of the hardware clock control bit is set for most of root clocks which needs to be cleared for software to be able to control. For older targets like MSM8996, this bit is reserved bit and having POR value as 0 so this patch will work for the older targets too. So update the configuration mask to take care of the same to clear hardware clock control bit.

---
 drivers/clk/qcom/clk-rcg2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg2.c +0 -0
index bbeaf9c..e63db10 100644

drivers/clk/qcom/clk-rcg2.c line 2

Quoted 3 lines
drivers/clk/qcom/clk-rcg2.c +1 -1
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved.

It would be nice if lawyers over there could avoid forcing copyright date updates when less than half the file changes.

Quoted 12 lines
drivers/clk/qcom/clk-rcg2.c +1 -0
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -42,6 +42,7 @@
 #define CFG_MODE_SHIFT         12
 #define CFG_MODE_MASK          (0x3 << CFG_MODE_SHIFT)
 #define CFG_MODE_DUAL_EDGE     (0x2 << CFG_MODE_SHIFT)
+#define CFG_HW_CLK_CTRL_MASK   BIT(20)
 
 #define M_REG                  0x8
 #define N_REG                  0xc

drivers/clk/qcom/clk-rcg2.c static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f) · line 283

Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +1 -1
@@ -276,7 +277,7 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
        }
 
        mask = BIT(rcg->hid_width) - 1;
-       mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
+       mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
        cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
        cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
        if (rcg->mnd_width && f->n && (f->m != f->n))

Is there going to be a future patch to update the RCGs to indicate they support hardware control or not?

#3 lore raw

Re: [PATCH v2 1/4] clk: qcom: Clear hardware clock control bit of RCG

Quoted 13 lines · Stephen Boyd

Quoting Amit Nischal (2018-03-07 23:18:12)

Quoted 12 lines

For upcoming targets like sdm845, POR value of the hardware clock control bit is set for most of root clocks which needs to be cleared for software to be able to control. For older targets like MSM8996, this bit is reserved bit and having POR value as 0 so this patch will work for the older targets too. So update the configuration mask to take care of the same to clear hardware clock control bit.

---
  drivers/clk/qcom/clk-rcg2.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 10 lines

drivers/clk/qcom/clk-rcg2.c line 2

Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +1 -1
index bbeaf9c..e63db10 100644
@@ -1,5 +1,5 @@
  /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved.

It would be nice if lawyers over there could avoid forcing copyright date updates when less than half the file changes.

Thanks for the review.
I will address the above in the next patch series.

Quoted 15 lines
Quoted 15 lines
drivers/clk/qcom/clk-rcg2.c +1 -0
   *
   * This software is licensed under the terms of the GNU General Public
   * License version 2, as published by the Free Software Foundation, and
@@ -42,6 +42,7 @@
  #define CFG_MODE_SHIFT         12
  #define CFG_MODE_MASK          (0x3 << CFG_MODE_SHIFT)
  #define CFG_MODE_DUAL_EDGE     (0x2 << CFG_MODE_SHIFT)
+#define CFG_HW_CLK_CTRL_MASK   BIT(20)
 
  #define M_REG                  0x8
  #define N_REG                  0xc
@@ -276,7 +277,7 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
         }
 
Quoted 8 lines

drivers/clk/qcom/clk-rcg2.c static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f) · line 283

Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +1 -1
         mask = BIT(rcg->hid_width) - 1;
-       mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
+       mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
         cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
         cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
         if (rcg->mnd_width && f->n && (f->m != f->n))

Is there going to be a future patch to update the RCGs to indicate they support hardware control or not?

As of now, there will not be any patch to update the RCGs to support HW control.

#4 lore raw

PATCH v2 2/4 clk: qcom: Configure the RCGs to a safe source as needed

In reply to Amit Nischal

For some root clock generators, there could be child branches which are controlled by an entity other than application processor subsystem. For such RCGs, as per application processor subsystem clock driver, all of its downstream clocks are disabled and RCG is in disabled state but in actual downstream clocks can be left enabled before.

So in this scenario, when RCG is disabled as per clock driver's point of view and when rate scaling request comes before downstream clock enable request, then RCG fails to update its configuration because in actual RCG is on and it expects its new source to alredy in enable state but in reality new source is in off state. In order to avoid letting the RCG to go into an invalid state, add support to just cache the rate of RCG during set_rate(), defer actual RCG configuration update to be done during clk_enable() as at this point of time, both its new parent and safe source will be already enabled and RCG can safely switch to new parent.

During clk_disable() request, configure it to safe source as both its parents, safe source and current parent will be enabled and RCG can safely execute a switch. Also add support to have safe configuration frequency table structure for each shared RCG.

---
 drivers/clk/qcom/clk-rcg.h  |   8 ++-
 drivers/clk/qcom/clk-rcg2.c | 155 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+), 1 deletion(-)
drivers/clk/qcom/clk-rcg.h +7 -1
index 2a7489a..205fa34 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -146,6 +146,9 @@ struct clk_dyn_rcg {
  * @hid_width: number of bits in half integer divider
  * @parent_map: map from software's parent index to hardware's src_sel field
  * @freq_tbl: frequency table
+ * @current_freq: last cached frequency when using branches with shared RCGs
+ * @safe_src_freq_tbl : frequency table of safe source when using branches
+ *			with shared RCGs
  * @clkr: regmap clock handle
  *
  */
@@ -155,6 +158,8 @@ struct clk_rcg2 {
 	u8			hid_width;
 	const struct parent_map	*parent_map;
 	const struct freq_tbl	*freq_tbl;
+	unsigned long		current_freq;
+	const struct freq_tbl	*safe_src_freq_tbl;
 	struct clk_regmap	clkr;
 };
 
@@ -167,5 +172,6 @@ struct clk_rcg2 {
 extern const struct clk_ops clk_byte2_ops;
 extern const struct clk_ops clk_pixel_ops;
 extern const struct clk_ops clk_gfx3d_ops;
+extern const struct clk_ops clk_rcg2_shared_ops;
 
 #endif
drivers/clk/qcom/clk-rcg2.c +155 -0

158 lines not on this page · raw message

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

maintainer
#5 lore raw

Re: [PATCH v2 2/4] clk: qcom: Configure the RCGs to a safe source as needed

Quoting Amit Nischal (2018-03-07 23:18:13)

Quoted 5 lines

For some root clock generators, there could be child branches which are controlled by an entity other than application processor subsystem. For such RCGs, as per application processor subsystem clock driver, all of its downstream clocks are disabled and RCG is in disabled state but in actual downstream clocks can be left enabled before.

s/actual/reality?

Quoted 4 lines

So in this scenario, when RCG is disabled as per clock driver's point of view and when rate scaling request comes before downstream clock enable request, then RCG fails to update its configuration because in actual RCG

s/actual/reality?

Quoted 1 line

is on and it expects its new source to alredy in enable state but in

s/alredy/already be/

Quoted 1 line

reality new source is in off state. In order to avoid letting the RCG to

s/is in off state/is off/
s/letting/having/

Quoted 1 line

go into an invalid state, add support to just cache the rate of RCG during

s/just//

Quoted 27 lines

set_rate(), defer actual RCG configuration update to be done during clk_enable() as at this point of time, both its new parent and safe source will be already enabled and RCG can safely switch to new parent.

During clk_disable() request, configure it to safe source as both its parents, safe source and current parent will be enabled and RCG can safely execute a switch. Also add support to have safe configuration frequency table structure for each shared RCG.

---

drivers/clk/qcom/clk-rcg.h +3 -0
index 2a7489a..205fa34 100644
@@ -146,6 +146,9 @@ struct clk_dyn_rcg {
  * @hid_width: number of bits in half integer divider
  * @parent_map: map from software's parent index to hardware's src_sel field
  * @freq_tbl: frequency table
+ * @current_freq: last cached frequency when using branches with shared RCGs
+ * @safe_src_freq_tbl : frequency table of safe source when using branches
+ *                     with shared RCGs
  * @clkr: regmap clock handle
  *
  */

drivers/clk/qcom/clk-rcg.h struct clk_rcg2 { · line 162

Quoted 5 lines
drivers/clk/qcom/clk-rcg.h +2 -0
@@ -155,6 +158,8 @@ struct clk_rcg2 {
        u8                      hid_width;
        const struct parent_map *parent_map;
        const struct freq_tbl   *freq_tbl;
+       unsigned long           current_freq;
+       const struct freq_tbl   *safe_src_freq_tbl;

Can we store safe_src index instead? And then construct the frequency table entry on the fly at the call site? I think it would greatly clarify that we don't really care about the rate of the clk at all. Instead, all we care about is making sure the mux is set to whatever source selection can provide an always on signal.

Quoted 16 lines
drivers/clk/qcom/clk-rcg.h +1 -0
        struct clk_regmap       clkr;
 };
 
@@ -167,5 +172,6 @@ struct clk_rcg2 {
 extern const struct clk_ops clk_byte2_ops;
 extern const struct clk_ops clk_pixel_ops;
 extern const struct clk_ops clk_gfx3d_ops;
+extern const struct clk_ops clk_rcg2_shared_ops;
 
 #endif
drivers/clk/qcom/clk-rcg2.c +0 -0
index e63db10..a52de54 100644
@@ -790,3 +790,158 @@ static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate,
        .determine_rate = clk_gfx3d_determine_rate,

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 800

Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +9 -0
 };
+
+static unsigned long
+clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       if (!__clk_is_enabled(hw->clk)) {
+               if (!rcg->current_freq) {
+                       if (!clk_rcg2_get_parent(hw))

This is checking for 0 source selection of parent? So basically if source is XO selected then return what we know is the XO speed? We should be able to do that by returning parent_rate though?

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 895

Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c +11 -0
+                               rcg->current_freq =
+                                       rcg->safe_src_freq_tbl->freq;
+                       else
+                               rcg->current_freq =
+                                       clk_rcg2_recalc_rate(hw, parent_rate);
+               }
+
+               return rcg->current_freq;
+       }
+
+       return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate);

I don't get this function.

To simplify just return cached rate if it's set and clk is off, otherwise read the hardware?

	if (!__clk_is_enabled(hw->clk) && rcg->current_freq)
		return rcg->current_freq;

	return clk_rcg2_recalc_rate(hw, parent_rate);

I would also rename current_freq to something like cached_freq and then *only* assign it when someone calls clk_set_rate() (and save around the frequency table pointer instead of raw frequency). Out of boot, we will return the right frequency and clk_set_rate() called before enable will cache the rate to what we want.

Quoted 12 lines
drivers/clk/qcom/clk-rcg2.c +12 -0
+}
+
+static int clk_rcg2_shared_enable(struct clk_hw *hw)
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       if (rcg->current_freq == rcg->safe_src_freq_tbl->freq) {
+               clk_rcg2_set_force_enable(hw);
+               clk_rcg2_configure(rcg, rcg->safe_src_freq_tbl);
+               clk_rcg2_clear_force_enable(hw);
+
+               return 0;

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 917

Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10 -0
+       }
+
+       /*
+        * Switch from safe source to the stashed mux selection. The current
+        * parent has already been prepared and enabled at this point, and
+        * the safe source is always on while application processor subsystem
+        * is online. Therefore, the RCG can safely switch its source.
+        */
+
+       return clk_rcg2_shared_force_enable_clear(hw, rcg->current_freq);

Not much is different between clk_rcg2_shared_force_enable_clear() and the three lines above inside that if condition. The only difference is we don't search for a rate in the frequency table. Ugh, but we can't change the frequency table because of hw clk control stuff that relies on the table in software matching the table in hardware? Sad.

Can we at least change the if condition above to be something like:

	if (rcg->force_safe_src) {
		clk_rcg2_set_force_enable(...

And then set the force_safe_src bool when we want enable to skip normal rate restoration behavior? We should be able to use that flag in other places too, like where we check for the clk being enabled in software or not.

Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c +9 -0
+}
+
+static void clk_rcg2_shared_disable(struct clk_hw *hw)
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       /*
+        * Park the RCG at a safe configuration - sourced off from safe source.
+        * Force enable and disable the RCG while configuring it to safeguard

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 936

Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10 -0
+        * against any update signal coming from the downstream clock.
+        * The current parent is still prepared and enabled at this point, and
+        * the safe source is always on while application processor subsystem
+        * is online. Therefore, the RCG can safely switch its parent.
+        */
+       clk_rcg2_set_force_enable(hw);
+       clk_rcg2_configure(rcg, rcg->safe_src_freq_tbl);
+       clk_rcg2_clear_force_enable(hw);
+}
+

Yeah, all this stuff would get simpler if we stopped using frequencies. Hopefully I made sense!

#6 lore raw

Re: [PATCH v2 2/4] clk: qcom: Configure the RCGs to a safe source as needed

Quoted 8 lines · Stephen Boyd

Quoting Amit Nischal (2018-03-07 23:18:13)

Quoted 5 lines

For some root clock generators, there could be child branches which are controlled by an entity other than application processor subsystem. For such RCGs, as per application processor subsystem clock driver, all of its downstream clocks are disabled and RCG is in disabled state but in actual downstream clocks can be left enabled before.

s/actual/reality?

Thanks for the review. I will address this in next patch series.

Quoted 8 lines
Quoted 5 lines

So in this scenario, when RCG is disabled as per clock driver's point of view and when rate scaling request comes before downstream clock enable request, then RCG fails to update its configuration because in actual RCG

s/actual/reality?

I will address this in next patch series.

Quoted 3 lines
Quoted 1 line

is on and it expects its new source to alredy in enable state but in

s/alredy/already be/

I will address this in next patch series.

Quoted 5 lines
Quoted 2 lines

reality new source is in off state. In order to avoid letting the RCG to

s/is in off state/is off/
s/letting/having/

I will address this in next patch series.

Quoted 4 lines
Quoted 2 lines

go into an invalid state, add support to just cache the rate of RCG during

s/just//

I will address this in next patch series.

Quoted 34 lines
Quoted 34 lines

set_rate(), defer actual RCG configuration update to be done during clk_enable() as at this point of time, both its new parent and safe source will be already enabled and RCG can safely switch to new parent.

During clk_disable() request, configure it to safe source as both its parents, safe source and current parent will be enabled and RCG can safely execute a switch. Also add support to have safe configuration frequency table structure for each shared RCG.

---

drivers/clk/qcom/clk-rcg.h +0 -0
index 2a7489a..205fa34 100644
@@ -146,6 +146,9 @@ struct clk_dyn_rcg {
  * @hid_width: number of bits in half integer divider
  * @parent_map: map from software's parent index to hardware's 

src_sel field
* @freq_tbl: frequency table
+ * @current_freq: last cached frequency when using branches with shared RCGs
+ * @safe_src_freq_tbl : frequency table of safe source when using branches
+ * with shared RCGs
* @clkr: regmap clock handle
*
*/

drivers/clk/qcom/clk-rcg.h +0 -0
@@ -155,6 +158,8 @@ struct clk_rcg2 {
        u8                      hid_width;
        const struct parent_map *parent_map;
        const struct freq_tbl   *freq_tbl;
Quoted 9 lines

drivers/clk/qcom/clk-rcg.h struct clk_rcg2 { · line 162

Quoted 2 lines
drivers/clk/qcom/clk-rcg.h +2 -0
+       unsigned long           current_freq;
+       const struct freq_tbl   *safe_src_freq_tbl;

Can we store safe_src index instead? And then construct the frequency table entry on the fly at the call site? I think it would greatly clarify that we don't really care about the rate of the clk at all. Instead, all we care about is making sure the mux is set to whatever source selection can provide an always on signal.

We will address the above in the V3 series of the patch set. We will be generating the safe frequency table on the fly taking the safe source frequency index input from the RCG clock.

Quoted 57 lines
Quoted 22 lines
drivers/clk/qcom/clk-rcg.h +1 -0
        struct clk_regmap       clkr;
 };
 
@@ -167,5 +172,6 @@ struct clk_rcg2 {
 extern const struct clk_ops clk_byte2_ops;
 extern const struct clk_ops clk_pixel_ops;
 extern const struct clk_ops clk_gfx3d_ops;
+extern const struct clk_ops clk_rcg2_shared_ops;
 
 #endif
drivers/clk/qcom/clk-rcg2.c +3 -0
index e63db10..a52de54 100644
@@ -790,3 +790,158 @@ static int clk_gfx3d_set_rate(struct clk_hw *hw, 
 unsigned long rate,
        .determine_rate = clk_gfx3d_determine_rate,
 };
+
+static unsigned long
+clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long 

parent_rate)

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 884

Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +6 -0
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       if (!__clk_is_enabled(hw->clk)) {
+               if (!rcg->current_freq) {
+                       if (!clk_rcg2_get_parent(hw))

This is checking for 0 source selection of parent? So basically if source is XO selected then return what we know is the XO speed? We should be able to do that by returning parent_rate though?

Quoted 12 lines
drivers/clk/qcom/clk-rcg2.c +5 -0
+                               rcg->current_freq =
+                                       rcg->safe_src_freq_tbl->freq;
+                       else
+                               rcg->current_freq =
+                                       clk_rcg2_recalc_rate(hw, 

parent_rate);

drivers/clk/qcom/clk-rcg2.c +6 -0
+               }
+
+               return rcg->current_freq;
+       }
+
+       return rcg->current_freq = clk_rcg2_recalc_rate(hw, 
Quoted 1 line

parent_rate);

I don't get this function.

To simplify just return cached rate if it's set and clk is off, otherwise read the hardware?

	if (!__clk_is_enabled(hw->clk) && rcg->current_freq)
		return rcg->current_freq;

	return clk_rcg2_recalc_rate(hw, parent_rate);
Quoted 5 lines

I would also rename current_freq to something like cached_freq and then *only* assign it when someone calls clk_set_rate() (and save around the frequency table pointer instead of raw frequency). Out of boot, we will return the right frequency and clk_set_rate() called before enable will cache the rate to what we want.

Thanks for your valuable suggestion. We will fix this in the next patch series. But we would like to have one modification i.e. to update the current_freq value with the clk_rcg2_recalc_rate(). Reason for the same is given below. So the final logic would be:

static unsigned long
clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) {
...
if (!__clk_is_enabled(hw->clk) && rcg->current_freq)

      return rcg->current_freq;

return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate);
}

Updation of current_freq is required in recalc_rate() because in a case where clk_enable() is called before the set_rate()[which actually updates the current_freq] then inside the clk_rcg2_shared_enable(), current_freq value will be 0 and clk_rcg2_shared_force_enable_clear() will configure the RCG with the first frequency entry in the frequency table and RCG will get enable at rate which BOOT has not configured.

Quoted 36 lines
Quoted 26 lines
drivers/clk/qcom/clk-rcg2.c +16 -0
+}
+
+static int clk_rcg2_shared_enable(struct clk_hw *hw)
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       if (rcg->current_freq == rcg->safe_src_freq_tbl->freq) {
+               clk_rcg2_set_force_enable(hw);
+               clk_rcg2_configure(rcg, rcg->safe_src_freq_tbl);
+               clk_rcg2_clear_force_enable(hw);
+
+               return 0;
+       }
+
+       /*
+        * Switch from safe source to the stashed mux selection. The 

current
+ * parent has already been prepared and enabled at this point,
and
+ * the safe source is always on while application processor
subsystem

drivers/clk/qcom/clk-rcg2.c +4 -0
+        * is online. Therefore, the RCG can safely switch its source.
+        */
+
+       return clk_rcg2_shared_force_enable_clear(hw, 
Quoted 1 line

rcg->current_freq);

Not much is different between clk_rcg2_shared_force_enable_clear() and the three lines above inside that if condition. The only difference is we don't search for a rate in the frequency table. Ugh, but we can't change the frequency table because of hw clk control stuff that relies on the table in software matching the table in hardware? Sad.

Can we at least change the if condition above to be something like:

Quoted 7 lines
	if (rcg->force_safe_src) {
		clk_rcg2_set_force_enable(...

And then set the force_safe_src bool when we want enable to skip normal rate restoration behavior? We should be able to use that flag in other places too, like where we check for the clk being enabled in software or not.

As per the new implementation in V3 series, we think there is no need to have one new flag.

Quoted 32 lines
Quoted 17 lines
drivers/clk/qcom/clk-rcg2.c +8 -0
+}
+
+static void clk_rcg2_shared_disable(struct clk_hw *hw)
+{
+       struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+       /*
+        * Park the RCG at a safe configuration - sourced off from 

safe source.
+ * Force enable and disable the RCG while configuring it to
safeguard

drivers/clk/qcom/clk-rcg2.c +2 -0
+        * against any update signal coming from the downstream clock.
+        * The current parent is still prepared and enabled at this 

point, and
+ * the safe source is always on while application processor
subsystem

drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 936

Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7 -0
+        * is online. Therefore, the RCG can safely switch its parent.
+        */
+       clk_rcg2_set_force_enable(hw);
+       clk_rcg2_configure(rcg, rcg->safe_src_freq_tbl);
+       clk_rcg2_clear_force_enable(hw);
+}
+

Yeah, all this stuff would get simpler if we stopped using frequencies. Hopefully I made sense!

--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

PATCH v2 3/4 clk: qcom: Add support for controlling Fabia PLL

In reply to Amit Nischal

Fabia PLL is a Digital Frequency Locked Loop (DFLL) clock generator which has a wide range of frequency output. It supports dynamic updating of the output frequency ("frequency slewing") without need to turn off the PLL before configuration. Add support for initial configuration and programming sequence to control fabia PLLs.

---
 drivers/clk/qcom/clk-alpha-pll.c | 324 ++++++++++++++++++++++++++++++++++++++-
 drivers/clk/qcom/clk-alpha-pll.h |  18 ++-
 2 files changed, 334 insertions(+), 8 deletions(-)
drivers/clk/qcom/clk-alpha-pll.c +317 -7
index 6d04cd9..e6b8d62 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015, 2018, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -58,6 +58,8 @@
 #define PLL_TEST_CTL(p)		((p)->offset + (p)->regs[PLL_OFF_TEST_CTL])
 #define PLL_TEST_CTL_U(p)	((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U])
 #define PLL_STATUS(p)		((p)->offset + (p)->regs[PLL_OFF_STATUS])
+#define PLL_OPMODE(p)		((p)->offset + (p)->regs[PLL_OFF_OPMODE])
+#define PLL_FRAC(p)		((p)->offset + (p)->regs[PLL_OFF_FRAC])
 
 const u8 clk_alpha_pll_regs[][PLL_OFF_MAX_REGS] = {
 	[CLK_ALPHA_PLL_TYPE_DEFAULT] =  {
@@ -90,6 +92,18 @@
 		[PLL_OFF_TEST_CTL] = 0x1c,
 		[PLL_OFF_STATUS] = 0x24,
 	},
+	[CLK_ALPHA_PLL_TYPE_FABIA] =  {
+		[PLL_OFF_L_VAL] = 0x04,
+		[PLL_OFF_USER_CTL] = 0x0c,
+		[PLL_OFF_USER_CTL_U] = 0x10,
+		[PLL_OFF_CONFIG_CTL] = 0x14,
+		[PLL_OFF_CONFIG_CTL_U] = 0x18,
+		[PLL_OFF_TEST_CTL] = 0x1c,
+		[PLL_OFF_TEST_CTL_U] = 0x20,
+		[PLL_OFF_STATUS] = 0x24,
+		[PLL_OFF_OPMODE] = 0x2c,
+		[PLL_OFF_FRAC] = 0x38,
+	},
 };
 EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);
 
@@ -108,6 +122,12 @@
 #define PLL_HUAYRA_N_MASK		0xff
 #define PLL_HUAYRA_ALPHA_WIDTH		16
 
+#define FABIA_OPMODE_STANDBY	0x0
+#define FABIA_OPMODE_RUN	0x1
+
+#define FABIA_PLL_OUT_MASK	0x7
+#define FABIA_PLL_RATE_MARGIN	500
+
 #define pll_alpha_width(p)					\
 		((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ?	\
 				 ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH)
@@ -441,16 +461,12 @@ static void clk_alpha_pll_disable(struct clk_hw *hw)
 	return alpha_pll_calc_rate(prate, l, a, alpha_width);
 }
 
-static int clk_alpha_pll_update_latch(struct clk_alpha_pll *pll,
-				      int (*is_enabled)(struct clk_hw *))
+
+static int __clk_alpha_pll_update_latch(struct clk_alpha_pll *pll)
 {
 	int ret;
 	u32 mode;
 
-	if (!is_enabled(&pll->clkr.hw) ||
-	    !(pll->flags & SUPPORTS_DYNAMIC_UPDATE))
-		return 0;
-
 	regmap_read(pll->clkr.regmap, PLL_MODE(pll), &mode);
 
 	/* Latch the input to the PLL */
@@ -489,6 +505,16 @@ static int clk_alpha_pll_update_latch(struct clk_alpha_pll *pll,
 	return 0;
 }
 
+static int clk_alpha_pll_update_latch(struct clk_alpha_pll *pll,
+				      int (*is_enabled)(struct clk_hw *))
+{
+	if (!is_enabled(&pll->clkr.hw) ||
+	    !(pll->flags & SUPPORTS_DYNAMIC_UPDATE))
+		return 0;
+
+	return __clk_alpha_pll_update_latch(pll);
+}
+
 static int __clk_alpha_pll_set_rate(struct clk_hw *hw, unsigned long rate,
 				    unsigned long prate,
 				    int (*is_enabled)(struct clk_hw *))
@@ -832,3 +858,287 @@ static int clk_alpha_pll_postdiv_set_rate(struct clk_hw *hw, unsigned long rate,
 	.recalc_rate = clk_alpha_pll_postdiv_recalc_rate,
 };
 EXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_ro_ops);
+
+void clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
+			     const struct alpha_pll_config *config)
+{
+	u32 val, mask;
+
+	if (config->l)
+		regmap_write(regmap, PLL_L_VAL(pll), config->l);
+
+	if (config->alpha)
+		regmap_write(regmap, PLL_FRAC(pll), config->alpha);
+
+	if (config->config_ctl_val)
+		regmap_write(regmap, PLL_CONFIG_CTL(pll),
+						config->config_ctl_val);
+
+	if (config->post_div_mask) {
+		mask = config->post_div_mask;
+		val = config->post_div_val;
+		regmap_update_bits(regmap, PLL_USER_CTL(pll), mask, val);
+	}
+
+	regmap_update_bits(regmap, PLL_MODE(pll), PLL_UPDATE_BYPASS,
+							PLL_UPDATE_BYPASS);
+
+	regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N);
+}
+
+static int alpha_pll_fabia_enable(struct clk_hw *hw)
+{
+	int ret;
+	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
+	u32 val, opmode_val;
+
+	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	if (ret)
+		return ret;
+
+	/* If in FSM mode, just vote for it */
+	if (val & PLL_VOTE_FSM_ENA) {
+		ret = clk_enable_regmap(hw);
+		if (ret)
+			return ret;
+		return wait_for_pll_enable_active(pll);
+	}
+
+	/* Read opmode value */
+	ret = regmap_read(pll->clkr.regmap, PLL_OPMODE(pll), &opmode_val);
+	if (ret)
+		return ret;
+
+	/* Skip If PLL is already running */
+	if ((opmode_val & FABIA_OPMODE_RUN) && (val & PLL_OUTCTRL))
+		return 0;
+
+	/* Disable PLL output */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
+							PLL_OUTCTRL, 0);
+	if (ret)
+		return ret;
+
+	/* Set Operation mode to STANBY */
+	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
+							FABIA_OPMODE_STANDBY);
+	if (ret)
+		return ret;
+
+	/* PLL should be in STANDBY mode before continuing */
+	mb();
+
+	/* Bring PLL out of reset */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
+						PLL_RESET_N, PLL_RESET_N);
+	if (ret)
+		return ret;
+
+	/* Set Operation mode to RUN */
+	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
+							FABIA_OPMODE_RUN);
+	if (ret)
+		return ret;
+
+	ret = wait_for_pll_enable_lock(pll);
+	if (ret)
+		return ret;
+
+	/* Enable the main PLL output */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),
+				FABIA_PLL_OUT_MASK, FABIA_PLL_OUT_MASK);
+	if (ret)
+		return ret;
+
+	/* Enable PLL outputs */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
+						PLL_OUTCTRL, PLL_OUTCTRL);
+	if (ret)
+		return ret;
+
+	/* Ensure that the write above goes through before returning. */
+	mb();
+
+	return ret;
+}
+
+static void alpha_pll_fabia_disable(struct clk_hw *hw)
+{
+	int ret;
+	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
+	u32 val;
+
+	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	if (ret)
+		return;
+
+	/* If in FSM mode, just unvote it */
+	if (val & PLL_FSM_ENA) {
+		clk_disable_regmap(hw);
+		return;
+	}
+
+	/* Disable PLL outputs */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
+							PLL_OUTCTRL, 0);
+	if (ret)
+		return;
+
+	/* Disable main outputs */
+	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),
+							FABIA_PLL_OUT_MASK, 0);
+	if (ret)
+		return;
+
+	/* Place the PLL in STANDBY */
+	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
+							FABIA_OPMODE_STANDBY);
+	if (ret)
+		return;
+}
+
+static unsigned long alpha_pll_fabia_recalc_rate(struct clk_hw *hw,
+						unsigned long parent_rate)
+{
+	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
+	u32 l, frac, alpha_width = pll_alpha_width(pll);
+
+	regmap_read(pll->clkr.regmap, PLL_L_VAL(pll), &l);
+	regmap_read(pll->clkr.regmap, PLL_FRAC(pll), &frac);
+
+	return alpha_pll_calc_rate(parent_rate, l, frac, alpha_width);
+}
+
+static int alpha_pll_fabia_set_rate(struct clk_hw *hw, unsigned long rate,
+						unsigned long prate)
+{
+	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
+	u32 val, l, alpha_width = pll_alpha_width(pll);
+	u64 a;
+	unsigned long rrate;
+	int ret = 0;
+
+	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	if (ret)
+		return ret;
+
+	rrate = alpha_pll_round_rate(rate, prate, &l, &a, alpha_width);
+
+	/*
+	 * Due to limited number of bits for fractional rate programming, the
+	 * rounded up rate could be marginally higher than the requested rate.
+	 */
+	if (rrate > (rate + FABIA_PLL_RATE_MARGIN) || rrate < rate) {
+		pr_err("Call set rate on the PLL with rounded rates!\n");
+		return -EINVAL;
+	}
+
+	regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l);
+	regmap_write(pll->clkr.regmap, PLL_FRAC(pll), a);
+
+	return __clk_alpha_pll_update_latch(pll);
+}
+
+const struct clk_ops clk_alpha_pll_fabia_ops = {
+	.enable = alpha_pll_fabia_enable,
+	.disable = alpha_pll_fabia_disable,
+	.is_enabled = clk_alpha_pll_is_enabled,
+	.set_rate = alpha_pll_fabia_set_rate,
+	.recalc_rate = alpha_pll_fabia_recalc_rate,
+	.round_rate = clk_alpha_pll_round_rate,
+};
+EXPORT_SYMBOL_GPL(clk_alpha_pll_fabia_ops);
+
+const struct clk_ops clk_alpha_pll_fixed_fabia_ops = {
+	.enable = alpha_pll_fabia_enable,
+	.disable = alpha_pll_fabia_disable,
+	.is_enabled = clk_alpha_pll_is_enabled,
+	.recalc_rate = alpha_pll_fabia_recalc_rate,
+	.round_rate = clk_alpha_pll_round_rate,
+};
+EXPORT_SYMBOL_GPL(clk_alpha_pll_fixed_fabia_ops);
+
+static unsigned long clk_alpha_pll_postdiv_fabia_recalc_rate(struct clk_hw *hw,
+					unsigned long parent_rate)
+{
+	struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw);
+	u32 i, div = 1, val;
+	int ret;
+
+	if (!pll->post_div_table) {
+		pr_err("Missing the post_div_table for the PLL\n");
+		return -EINVAL;
+	}
+
+	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);
+	if (ret)
+		return ret;
+
+	val >>= pll->post_div_shift;
+	val &= BIT(pll->width) - 1;
+
+	for (i = 0; i < pll->num_post_div; i++) {
+		if (pll->post_div_table[i].val == val) {
+			div = pll->post_div_table[i].div;
+			break;
+		}
+	}
+
+	return (parent_rate / div);
+}
+
+static long clk_alpha_pll_postdiv_fabia_round_rate(struct clk_hw *hw,
+				unsigned long rate, unsigned long *prate)
+{
+	struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw);
+
+	if (!pll->post_div_table) {
+		pr_err("Missing the post_div_table for the PLL\n");
+		return -EINVAL;
+	}
+
+	return divider_round_rate(hw, rate, prate, pll->post_div_table,
+				pll->width, CLK_DIVIDER_ROUND_CLOSEST);
+}
+
+static int clk_alpha_pll_postdiv_fabia_set_rate(struct clk_hw *hw,
+				unsigned long rate, unsigned long parent_rate)
+{
+	struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw);
+	int i, val = 0, div, ret;
+
+	/*
+	 * If the PLL is in FSM mode, then treat set_rate callback as a
+	 * no-operation.
+	 */
+	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	if (ret)
+		return ret;
+
+	if (val & PLL_VOTE_FSM_ENA)
+		return 0;
+
+	if (!pll->post_div_table) {
+		pr_err("Missing the post_div_table for the PLL\n");
+		return -EINVAL;
+	}
+
+	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
+	for (i = 0; i < pll->num_post_div; i++) {
+		if (pll->post_div_table[i].div == div) {
+			val = pll->post_div_table[i].val;
+			break;
+		}
+	}
+
+	return regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),
+				(BIT(pll->width) - 1) << pll->post_div_shift,
+				val << pll->post_div_shift);
+}
+
+const struct clk_ops clk_alpha_pll_postdiv_fabia_ops = {
+	.recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate,
+	.round_rate = clk_alpha_pll_postdiv_fabia_round_rate,
+	.set_rate = clk_alpha_pll_postdiv_fabia_set_rate,
+};
+EXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_fabia_ops);
drivers/clk/qcom/clk-alpha-pll.h +17 -1
index 7593e8a..f981b48 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015, 2018, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -22,6 +22,7 @@ enum {
 	CLK_ALPHA_PLL_TYPE_DEFAULT,
 	CLK_ALPHA_PLL_TYPE_HUAYRA,
 	CLK_ALPHA_PLL_TYPE_BRAMMO,
+	CLK_ALPHA_PLL_TYPE_FABIA,
 	CLK_ALPHA_PLL_TYPE_MAX,
 };
 
@@ -36,6 +37,8 @@ enum {
 	PLL_OFF_TEST_CTL,
 	PLL_OFF_TEST_CTL_U,
 	PLL_OFF_STATUS,
+	PLL_OFF_OPMODE,
+	PLL_OFF_FRAC,
 	PLL_OFF_MAX_REGS
 };
 
@@ -73,6 +76,10 @@ struct clk_alpha_pll {
  * @offset: base address of registers
  * @regs: alpha pll register map (see @clk_alpha_pll_regs)
  * @width: width of post-divider
+ * @post_div_shift: shift to differentiate between odd & even post-divider
+ * @post_div_table: table with PLL odd and even post-divider settings
+ * @num_post_div: Number of PLL post-divider settings
+ *
  * @clkr: regmap clock handle
  */
 struct clk_alpha_pll_postdiv {
@@ -81,6 +88,9 @@ struct clk_alpha_pll_postdiv {
 	const u8 *regs;
 
 	struct clk_regmap clkr;
+	int post_div_shift;
+	const struct clk_div_table *post_div_table;
+	size_t num_post_div;
 };
 
 struct alpha_pll_config {
@@ -109,7 +119,13 @@ struct alpha_pll_config {
 extern const struct clk_ops clk_alpha_pll_huayra_ops;
 extern const struct clk_ops clk_alpha_pll_postdiv_ro_ops;
 
+extern const struct clk_ops clk_alpha_pll_fabia_ops;
+extern const struct clk_ops clk_alpha_pll_fixed_fabia_ops;
+extern const struct clk_ops clk_alpha_pll_postdiv_fabia_ops;
+
 void clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
 			     const struct alpha_pll_config *config);
+void clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
+				const struct alpha_pll_config *config);
 
 #endif

--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

maintainer Applied
#8 lore raw

Re: [PATCH v2 3/4] clk: qcom: Add support for controlling Fabia PLL

Quoting Amit Nischal (2018-03-07 23:18:14)

Quoted 9 lines

Fabia PLL is a Digital Frequency Locked Loop (DFLL) clock generator which has a wide range of frequency output. It supports dynamic updating of the output frequency ("frequency slewing") without need to turn off the PLL before configuration. Add support for initial configuration and programming sequence to control fabia PLLs.

---

Applied to clk-next with a little adjustment below:

drivers/clk/qcom/clk-alpha-pll.c +18 -41
index e6b8d62e5175..9722b701fbdb 100644
@@ -891,8 +891,9 @@ static int alpha_pll_fabia_enable(struct clk_hw *hw)
 	int ret;
 	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
 	u32 val, opmode_val;
+	struct regmap *regmap = pll->clkr.regmap;
 
-	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	ret = regmap_read(regmap, PLL_MODE(pll), &val);
 	if (ret)
 		return ret;
 
@@ -904,8 +905,7 @@ static int alpha_pll_fabia_enable(struct clk_hw *hw)
 		return wait_for_pll_enable_active(pll);
 	}
 
-	/* Read opmode value */
-	ret = regmap_read(pll->clkr.regmap, PLL_OPMODE(pll), &opmode_val);
+	ret = regmap_read(regmap, PLL_OPMODE(pll), &opmode_val);
 	if (ret)
 		return ret;
 
@@ -913,30 +913,20 @@ static int alpha_pll_fabia_enable(struct clk_hw *hw)
 	if ((opmode_val & FABIA_OPMODE_RUN) && (val & PLL_OUTCTRL))
 		return 0;
 
-	/* Disable PLL output */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
-							PLL_OUTCTRL, 0);
+	ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0);
 	if (ret)
 		return ret;
 
-	/* Set Operation mode to STANBY */
-	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
-							FABIA_OPMODE_STANDBY);
+	ret = regmap_write(regmap, PLL_OPMODE(pll), FABIA_OPMODE_STANDBY);
 	if (ret)
 		return ret;
 
-	/* PLL should be in STANDBY mode before continuing */
-	mb();
-
-	/* Bring PLL out of reset */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
-						PLL_RESET_N, PLL_RESET_N);
+	ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N,
+				 PLL_RESET_N);
 	if (ret)
 		return ret;
 
-	/* Set Operation mode to RUN */
-	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
-							FABIA_OPMODE_RUN);
+	ret = regmap_write(regmap, PLL_OPMODE(pll), FABIA_OPMODE_RUN);
 	if (ret)
 		return ret;
 
@@ -944,22 +934,13 @@ static int alpha_pll_fabia_enable(struct clk_hw *hw)
 	if (ret)
 		return ret;
 
-	/* Enable the main PLL output */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),
-				FABIA_PLL_OUT_MASK, FABIA_PLL_OUT_MASK);
-	if (ret)
-		return ret;
-
-	/* Enable PLL outputs */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
-						PLL_OUTCTRL, PLL_OUTCTRL);
+	ret = regmap_update_bits(regmap, PLL_USER_CTL(pll),
+				 FABIA_PLL_OUT_MASK, FABIA_PLL_OUT_MASK);
 	if (ret)
 		return ret;
 
-	/* Ensure that the write above goes through before returning. */
-	mb();
-
-	return ret;
+	return regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL,
+				 PLL_OUTCTRL);
 }
 
 static void alpha_pll_fabia_disable(struct clk_hw *hw)
@@ -967,8 +948,9 @@ static void alpha_pll_fabia_disable(struct clk_hw *hw)
 	int ret;
 	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
 	u32 val;
+	struct regmap *regmap = pll->clkr.regmap;
 
-	ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
+	ret = regmap_read(regmap, PLL_MODE(pll), &val);
 	if (ret)
 		return;
 
@@ -978,23 +960,18 @@ static void alpha_pll_fabia_disable(struct clk_hw *hw)
 		return;
 	}
 
-	/* Disable PLL outputs */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
-							PLL_OUTCTRL, 0);
+	ret = regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0);
 	if (ret)
 		return;
 
 	/* Disable main outputs */
-	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),
-							FABIA_PLL_OUT_MASK, 0);
+	ret = regmap_update_bits(regmap, PLL_USER_CTL(pll), FABIA_PLL_OUT_MASK,
+				 0);
 	if (ret)
 		return;
 
 	/* Place the PLL in STANDBY */
-	ret = regmap_write(pll->clkr.regmap, PLL_OPMODE(pll),
-							FABIA_OPMODE_STANDBY);
-	if (ret)
-		return;
+	regmap_write(regmap, PLL_OPMODE(pll), FABIA_OPMODE_STANDBY);
 }
 
 static unsigned long alpha_pll_fabia_recalc_rate(struct clk_hw *hw,
#9 lore raw

PATCH v2 4/4 clk: qcom: Add Global Clock controller (GCC) driver for SDM845

In reply to Amit Nischal

From: Taniya Das <[email protected]>

Add support for the global clock controller found on SDM845 based devices. This should allow most non-multimedia device drivers to probe and control their clocks.

---
 .../devicetree/bindings/clock/qcom,gcc.txt         |    1 +
 drivers/clk/qcom/Kconfig                           |   11 +
 drivers/clk/qcom/Makefile                          |    1 +
 drivers/clk/qcom/gcc-sdm845.c                      | 3619 ++++++++++++++++++++
 include/dt-bindings/clock/qcom,gcc-sdm845.h        |  242 ++
 5 files changed, 3874 insertions(+)
 create mode 100644 drivers/clk/qcom/gcc-sdm845.c
 create mode 100644 include/dt-bindings/clock/qcom,gcc-sdm845.h
Documentation/devicetree/bindings/clock/qcom,gcc.txt +1 -0
index 551d03b..bf2355d 100644
@@ -18,6 +18,7 @@ Required properties :
 			"qcom,gcc-msm8994"
 			"qcom,gcc-msm8996"
 			"qcom,gcc-mdm9615"
+			"qcom,gcc-sdm845"
 
 - reg : shall contain base register location and length
 - #clock-cells : shall contain 1
drivers/clk/qcom/Kconfig +11 -0
index fbf4532..54d0545 100644
@@ -218,6 +218,16 @@ config MSM_MMCC_8996
 	  Say Y if you want to support multimedia devices such as display,
 	  graphics, video encode/decode, camera, etc.
 
+config SDM_GCC_845
+	tristate "SDM845 Global Clock Controller"
+	depends on COMMON_CLK_QCOM
+	help
+	  Support for the global clock controller on Qualcomm Technologies, Inc
+	  sdm845 devices.
+	  Say Y if you want to use peripheral devices such as UART, SPI,
+	  i2c, USB, UFS, SD/eMMC, PCIe, etc.
+
+
 config SPMI_PMIC_CLKDIV
 	tristate "SPMI PMIC clkdiv Support"
 	depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST
@@ -226,3 +236,4 @@ config SPMI_PMIC_CLKDIV
 	  Technologies, Inc. SPMI PMIC. It configures the frequency of
 	  clkdiv outputs of the PMIC. These clocks are typically wired
 	  through alternate functions on GPIO pins.
+
drivers/clk/qcom/Makefile +1 -0
index 230332c..1fc934dd 100644
@@ -37,4 +37,5 @@ obj-$(CONFIG_QCOM_A53PLL) += a53-pll.o
 obj-$(CONFIG_QCOM_CLK_APCS_MSM8916) += apcs-msm8916.o
 obj-$(CONFIG_QCOM_CLK_RPM) += clk-rpm.o
 obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o
+obj-$(CONFIG_SDM_GCC_845)  += gcc-sdm845.o
 obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
drivers/clk/qcom/gcc-sdm845.c new file +3619 -0

2,968 lines not on this page · raw message

include/dt-bindings/clock/qcom,gcc-sdm845.h new file +242 -0

242 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

Part of the diff is not shown here. View the raw message.

maintainer
#10 lore raw

Re: [PATCH v2 4/4] clk: qcom: Add Global Clock controller (GCC) driver for SDM845

Quoting Amit Nischal (2018-03-07 23:18:15)

Quoted 8 lines
drivers/clk/qcom/Kconfig +0 -0
index fbf4532..54d0545 100644
@@ -218,6 +218,16 @@ config MSM_MMCC_8996
          Say Y if you want to support multimedia devices such as display,
          graphics, video encode/decode, camera, etc.
 

drivers/clk/qcom/Kconfig config MSM_MMCC_8996 · line 230

Quoted 10 lines
drivers/clk/qcom/Kconfig +10 -0
+config SDM_GCC_845
+       tristate "SDM845 Global Clock Controller"
+       depends on COMMON_CLK_QCOM
+       help
+         Support for the global clock controller on Qualcomm Technologies, Inc
+         sdm845 devices.
+         Say Y if you want to use peripheral devices such as UART, SPI,
+         i2c, USB, UFS, SD/eMMC, PCIe, etc.
+
+

Drop the double newline here please.

drivers/clk/qcom/Kconfig config SPMI_PMIC_CLKDIV · line 239

Quoted 8 lines
drivers/clk/qcom/Kconfig +1 -0
 config SPMI_PMIC_CLKDIV
        tristate "SPMI PMIC clkdiv Support"
        depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST
@@ -226,3 +236,4 @@ config SPMI_PMIC_CLKDIV
          Technologies, Inc. SPMI PMIC. It configures the frequency of
          clkdiv outputs of the PMIC. These clocks are typically wired
          through alternate functions on GPIO pins.
+

Noise?

Quoted 29 lines
drivers/clk/qcom/gcc-sdm845.c new file +23 -0
new file mode 100644
index 0000000..3ffa098
@@ -0,0 +1,3619 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+#include <dt-bindings/clock/qcom,gcc-sdm845.h>
+
+#include "common.h"
+#include "clk-regmap.h"
+#include "clk-pll.h"
+#include "clk-rcg.h"

drivers/clk/qcom/gcc-sdm845.c line 33

Quoted 10 lines
drivers/clk/qcom/gcc-sdm845.c new file +10 -0
+#include "clk-branch.h"
+#include "clk-alpha-pll.h"
+#include "gdsc.h"
+#include "reset.h"
+
+#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
+
+static struct freq_tbl cxo_safe_src_f = {
+       .pre_div = 1,
+};

Still hoping this goes away.

Quoted 10 lines
drivers/clk/qcom/gcc-sdm845.c new file +10 -0
+
+enum {
+       P_BI_TCXO,
+       P_AUD_REF_CLK,
+       P_CORE_BI_PLL_TEST_SE,
+       P_GPLL0_OUT_EVEN,
+       P_GPLL0_OUT_MAIN,
+       P_GPLL4_OUT_MAIN,
+       P_SLEEP_CLK,
+};

[...]

Quoted 6 lines
drivers/clk/qcom/gcc-sdm845.c new file +6 -0
+       F(400000, P_BI_TCXO, 12, 1, 4),
+       F(9600000, P_BI_TCXO, 2, 0, 0),
+       F(19200000, P_BI_TCXO, 1, 0, 0),
+       F(25000000, P_GPLL0_OUT_MAIN, 12, 1, 2),
+       F(50000000, P_GPLL0_OUT_MAIN, 12, 0, 0),
+       F(100000000, P_GPLL0_OUT_MAIN, 6, 0, 0),

drivers/clk/qcom/gcc-sdm845.c line 725

Quoted 10 lines
drivers/clk/qcom/gcc-sdm845.c new file +10 -0
+       { }
+};
+
+static struct clk_rcg2 gcc_sdcc4_apps_clk_src = {
+       .cmd_rcgr = 0x1600c,
+       .mnd_width = 8,
+       .hid_width = 5,
+       .parent_map = gcc_parent_map_0,
+       .freq_tbl = ftbl_gcc_sdcc4_apps_clk_src,
+       .safe_src_freq_tbl = &cxo_safe_src_f,

Why does sdcc have safe src stuff? Is something turning on the sdcc clk outside of our control?

Quoted 9 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+       .clkr.hw.init = &(struct clk_init_data){
+               .name = "gcc_sdcc4_apps_clk_src",
+               .parent_names = gcc_parent_names_0,
+               .num_parents = 4,
+               .flags = CLK_SET_RATE_PARENT,
+               .ops = &clk_rcg2_shared_ops,
+       },
+};
+

[...]

drivers/clk/qcom/gcc-sdm845.c line 3158

Quoted 12 lines
drivers/clk/qcom/gcc-sdm845.c new file +12 -0
+
+static struct clk_branch gcc_video_xo_clk = {
+       .halt_reg = 0xb028,
+       .halt_check = BRANCH_HALT,
+       .clkr = {
+               .enable_reg = 0xb028,
+               .enable_mask = BIT(0),
+               .hw.init = &(struct clk_init_data){
+                       .name = "gcc_video_xo_clk",
+                       .flags = CLK_IS_CRITICAL,
+                       .ops = &clk_branch2_ops,
+

These things have no parents and we mark them critical. Why are we even exposing them to the kernel? Are they not on by default? Are we going to change these to non-critical at some point in the future?

drivers/clk/qcom/gcc-sdm845.c line 3551

Quoted 5 lines
drivers/clk/qcom/gcc-sdm845.c new file +5 -0
+static const struct regmap_config gcc_sdm845_regmap_config = {
+       .reg_bits       = 32,
+       .reg_stride     = 4,
+       .val_bits       = 32,
+       .max_register   = 0x182090,

Huge! :P

Quoted 27 lines
drivers/clk/qcom/gcc-sdm845.c new file +27 -0
+       .fast_io        = true,
+};
+
+static const struct qcom_cc_desc gcc_sdm845_desc = {
+       .config = &gcc_sdm845_regmap_config,
+       .clks = gcc_sdm845_clocks,
+       .num_clks = ARRAY_SIZE(gcc_sdm845_clocks),
+       .resets = gcc_sdm845_resets,
+       .num_resets = ARRAY_SIZE(gcc_sdm845_resets),
+       .gdscs = gcc_sdm845_gdscs,
+       .num_gdscs = ARRAY_SIZE(gcc_sdm845_gdscs),
+};
+
+static const struct of_device_id gcc_sdm845_match_table[] = {
+       { .compatible = "qcom,gcc-sdm845" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, gcc_sdm845_match_table);
+
+static int gcc_sdm845_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct regmap *regmap;
+       int i, ret;
+
+       regmap = qcom_cc_map(pdev, &gcc_sdm845_desc);
+       if (IS_ERR(regmap))

drivers/clk/qcom/gcc-sdm845.c line 3588

Quoted 10 lines
drivers/clk/qcom/gcc-sdm845.c new file +10 -0
+               return PTR_ERR(regmap);
+
+       for (i = 0; i < ARRAY_SIZE(gcc_sdm845_hws); i++) {
+               ret = devm_clk_hw_register(dev, gcc_sdm845_hws[i]);
+               if (ret)
+                       return ret;
+       }
+
+       /* Get the rate for safe source */
+       cxo_safe_src_f.freq = clk_get_rate(bi_tcxo.hw.clk);

Hopefully this can be dropped too.

drivers/clk/qcom/gcc-sdm845.c line 3592

Quoted 4 lines
drivers/clk/qcom/gcc-sdm845.c new file +4 -0
+
+       /* Disable the GPLL0 active input to MMSS and GPU via MISC registers */
+       regmap_update_bits(regmap, 0x09FFC, 0x3, 0x3);
+       regmap_update_bits(regmap, 0x71028, 0x3, 0x3);

Lowercase hex please.

Quoted 3 lines
drivers/clk/qcom/gcc-sdm845.c new file +3 -0
+
+       return qcom_cc_really_probe(pdev, &gcc_sdm845_desc, regmap);
+}
#11 lore raw

Re: [PATCH v2 4/4] clk: qcom: Add Global Clock controller (GCC) driver for SDM845

Quoted 10 lines · Stephen Boyd

Quoting Amit Nischal (2018-03-07 23:18:15)

Quoted 9 lines
drivers/clk/qcom/Kconfig +0 -0
index fbf4532..54d0545 100644
@@ -218,6 +218,16 @@ config MSM_MMCC_8996
          Say Y if you want to support multimedia devices such as 
 display,
          graphics, video encode/decode, camera, etc.
 
Quoted 14 lines

drivers/clk/qcom/Kconfig config MSM_MMCC_8996 · line 230

Quoted 12 lines
drivers/clk/qcom/Kconfig +5 -0
+config SDM_GCC_845
+       tristate "SDM845 Global Clock Controller"
+       depends on COMMON_CLK_QCOM
+       help
+         Support for the global clock controller on Qualcomm 

Technologies, Inc

drivers/clk/qcom/Kconfig +2 -0
+         sdm845 devices.
+         Say Y if you want to use peripheral devices such as UART, 

SPI,

drivers/clk/qcom/Kconfig +3 -0
+         i2c, USB, UFS, SD/eMMC, PCIe, etc.
+
+

Drop the double newline here please.

Thanks for the review. We will fix this in next patch series.

Quoted 11 lines

drivers/clk/qcom/Kconfig config SPMI_PMIC_CLKDIV · line 239

Quoted 9 lines

config SPMI_PMIC_CLKDIV
tristate "SPMI PMIC clkdiv Support" depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST

drivers/clk/qcom/Kconfig +1 -0
@@ -226,3 +236,4 @@ config SPMI_PMIC_CLKDIV
          Technologies, Inc. SPMI PMIC. It configures the frequency of
          clkdiv outputs of the PMIC. These clocks are typically wired
          through alternate functions on GPIO pins.
+

Noise?

We will fix this in next patch series.

Quoted 34 lines
Quoted 34 lines
drivers/clk/qcom/gcc-sdm845.c new file +27 -0
new file mode 100644
index 0000000..3ffa098
@@ -0,0 +1,3619 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/kernel.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+
+#include <dt-bindings/clock/qcom,gcc-sdm845.h>
+
+#include "common.h"
+#include "clk-regmap.h"
+#include "clk-pll.h"
+#include "clk-rcg.h"
+#include "clk-branch.h"
+#include "clk-alpha-pll.h"
+#include "gdsc.h"
+#include "reset.h"
Quoted 8 lines

drivers/clk/qcom/gcc-sdm845.c line 33

Quoted 6 lines
drivers/clk/qcom/gcc-sdm845.c new file +6 -0
+
+#define F(f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) }
+
+static struct freq_tbl cxo_safe_src_f = {
+       .pre_div = 1,
+};

Still hoping this goes away.

With new implementation of rcg2 shared ops, there is no need to pass safe source frequency table from the driver so we will address this in V3 patch series.

Quoted 23 lines
Quoted 11 lines
drivers/clk/qcom/gcc-sdm845.c new file +10 -0
+
+enum {
+       P_BI_TCXO,
+       P_AUD_REF_CLK,
+       P_CORE_BI_PLL_TEST_SE,
+       P_GPLL0_OUT_EVEN,
+       P_GPLL0_OUT_MAIN,
+       P_GPLL4_OUT_MAIN,
+       P_SLEEP_CLK,
+};

[...]

Quoted 11 lines
drivers/clk/qcom/gcc-sdm845.c new file +11 -0
+       F(400000, P_BI_TCXO, 12, 1, 4),
+       F(9600000, P_BI_TCXO, 2, 0, 0),
+       F(19200000, P_BI_TCXO, 1, 0, 0),
+       F(25000000, P_GPLL0_OUT_MAIN, 12, 1, 2),
+       F(50000000, P_GPLL0_OUT_MAIN, 12, 0, 0),
+       F(100000000, P_GPLL0_OUT_MAIN, 6, 0, 0),
+       { }
+};
+
+static struct clk_rcg2 gcc_sdcc4_apps_clk_src = {
+       .cmd_rcgr = 0x1600c,
Quoted 8 lines

drivers/clk/qcom/gcc-sdm845.c line 725

Quoted 5 lines
drivers/clk/qcom/gcc-sdm845.c new file +5 -0
+       .mnd_width = 8,
+       .hid_width = 5,
+       .parent_map = gcc_parent_map_0,
+       .freq_tbl = ftbl_gcc_sdcc4_apps_clk_src,
+       .safe_src_freq_tbl = &cxo_safe_src_f,

Why does sdcc have safe src stuff? Is something turning on the sdcc clk outside of our control?

I will get more details on this and will get back.

Quoted 11 lines
Quoted 10 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+       .clkr.hw.init = &(struct clk_init_data){
+               .name = "gcc_sdcc4_apps_clk_src",
+               .parent_names = gcc_parent_names_0,
+               .num_parents = 4,
+               .flags = CLK_SET_RATE_PARENT,
+               .ops = &clk_rcg2_shared_ops,
+       },
+};
+

[...]

Quoted 16 lines

drivers/clk/qcom/gcc-sdm845.c line 3158

Quoted 12 lines
drivers/clk/qcom/gcc-sdm845.c new file +12 -0
+
+static struct clk_branch gcc_video_xo_clk = {
+       .halt_reg = 0xb028,
+       .halt_check = BRANCH_HALT,
+       .clkr = {
+               .enable_reg = 0xb028,
+               .enable_mask = BIT(0),
+               .hw.init = &(struct clk_init_data){
+                       .name = "gcc_video_xo_clk",
+                       .flags = CLK_IS_CRITICAL,
+                       .ops = &clk_branch2_ops,
+

These things have no parents and we mark them critical. Why are we even exposing them to the kernel? Are they not on by default? Are we going to change these to non-critical at some point in the future?

These clocks are not enabled by default and going to video or other multimedia cores so we are marking them as critical and need to expose to the kernel. As of now, there is no plan to change these to non-critical.

Quoted 40 lines

drivers/clk/qcom/gcc-sdm845.c line 3551

Quoted 6 lines
drivers/clk/qcom/gcc-sdm845.c new file +5 -0
+static const struct regmap_config gcc_sdm845_regmap_config = {
+       .reg_bits       = 32,
+       .reg_stride     = 4,
+       .val_bits       = 32,
+       .max_register   = 0x182090,

Huge! :P

Quoted 31 lines
drivers/clk/qcom/gcc-sdm845.c new file +31 -0
+       .fast_io        = true,
+};
+
+static const struct qcom_cc_desc gcc_sdm845_desc = {
+       .config = &gcc_sdm845_regmap_config,
+       .clks = gcc_sdm845_clocks,
+       .num_clks = ARRAY_SIZE(gcc_sdm845_clocks),
+       .resets = gcc_sdm845_resets,
+       .num_resets = ARRAY_SIZE(gcc_sdm845_resets),
+       .gdscs = gcc_sdm845_gdscs,
+       .num_gdscs = ARRAY_SIZE(gcc_sdm845_gdscs),
+};
+
+static const struct of_device_id gcc_sdm845_match_table[] = {
+       { .compatible = "qcom,gcc-sdm845" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, gcc_sdm845_match_table);
+
+static int gcc_sdm845_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct regmap *regmap;
+       int i, ret;
+
+       regmap = qcom_cc_map(pdev, &gcc_sdm845_desc);
+       if (IS_ERR(regmap))
+               return PTR_ERR(regmap);
+
+       for (i = 0; i < ARRAY_SIZE(gcc_sdm845_hws); i++) {
+               ret = devm_clk_hw_register(dev, gcc_sdm845_hws[i]);
Quoted 8 lines

drivers/clk/qcom/gcc-sdm845.c line 3588

Quoted 6 lines
drivers/clk/qcom/gcc-sdm845.c new file +6 -0
+               if (ret)
+                       return ret;
+       }
+
+       /* Get the rate for safe source */
+       cxo_safe_src_f.freq = clk_get_rate(bi_tcxo.hw.clk);

Hopefully this can be dropped too.

Yes, we will fix this in next patch series.

Quoted 8 lines

drivers/clk/qcom/gcc-sdm845.c line 3592

Quoted 6 lines
drivers/clk/qcom/gcc-sdm845.c new file +2 -0
+
+       /* Disable the GPLL0 active input to MMSS and GPU via MISC 

registers */

drivers/clk/qcom/gcc-sdm845.c new file +2 -0
+       regmap_update_bits(regmap, 0x09FFC, 0x3, 0x3);
+       regmap_update_bits(regmap, 0x71028, 0x3, 0x3);

Lowercase hex please.

We will fix this in next patch series.

Quoted 8 lines

drivers/clk/qcom/gcc-sdm845.c line 3595

Quoted 4 lines
drivers/clk/qcom/gcc-sdm845.c new file +3 -0
+
+       return qcom_cc_really_probe(pdev, &gcc_sdm845_desc, regmap);
+}

--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#12 lore raw

Re: [PATCH v2 4/4] clk: qcom: Add Global Clock controller (GCC) driver for SDM845

Quoting Amit Nischal (2018-04-03 05:24:41)

Quoted 15 lines · Stephen Boyd
Quoted 13 lines

Quoting Amit Nischal (2018-03-07 23:18:15)

drivers/clk/qcom/gcc-sdm845.c line 725

Quoted 9 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+};
+
+static struct clk_rcg2 gcc_sdcc4_apps_clk_src = {
+       .cmd_rcgr = 0x1600c,
+       .mnd_width = 8,
+       .hid_width = 5,
+       .parent_map = gcc_parent_map_0,
+       .freq_tbl = ftbl_gcc_sdcc4_apps_clk_src,
+       .safe_src_freq_tbl = &cxo_safe_src_f,

Why does sdcc have safe src stuff? Is something turning on the sdcc clk outside of our control?

Quoted 1 line

I will get more details on this and will get back.

Any news?

Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+       .clkr.hw.init = &(struct clk_init_data){
+               .name = "gcc_sdcc4_apps_clk_src",
+               .parent_names = gcc_parent_names_0,
+               .num_parents = 4,
+               .flags = CLK_SET_RATE_PARENT,
+               .ops = &clk_rcg2_shared_ops,
+       },
+};
+

[...]

Quoted 16 lines

drivers/clk/qcom/gcc-sdm845.c line 3158

Quoted 12 lines
drivers/clk/qcom/gcc-sdm845.c new file +12 -0
+
+static struct clk_branch gcc_video_xo_clk = {
+       .halt_reg = 0xb028,
+       .halt_check = BRANCH_HALT,
+       .clkr = {
+               .enable_reg = 0xb028,
+               .enable_mask = BIT(0),
+               .hw.init = &(struct clk_init_data){
+                       .name = "gcc_video_xo_clk",
+                       .flags = CLK_IS_CRITICAL,
+                       .ops = &clk_branch2_ops,
+

These things have no parents and we mark them critical. Why are we even exposing them to the kernel? Are they not on by default? Are we going to change these to non-critical at some point in the future?

Quoted 4 lines

These clocks are not enabled by default and going to video or other multimedia cores so we are marking them as critical and need to expose to the kernel. As of now, there is no plan to change these to non-critical.

Ok. Can we open code enabling these branches in the driver probe then? Still seems wasteful if nobody uses these.

Put another way, either a driver (or other clk controller) should be toggling these gates at runtime or we should enable them once and leave them out of the framework. If the driver approach is taken, then the drivers should be able to turn the clks on and off to save some power.

#13 lore raw

Re: [PATCH v2 4/4] clk: qcom: Add Global Clock controller (GCC) driver for SDM845

Quoted 16 lines · Stephen Boyd

Quoting Amit Nischal (2018-04-03 05:24:41)

Quoted 15 lines · Stephen Boyd
Quoted 13 lines

Quoting Amit Nischal (2018-03-07 23:18:15)

drivers/clk/qcom/gcc-sdm845.c line 725

Quoted 9 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+};
+
+static struct clk_rcg2 gcc_sdcc4_apps_clk_src = {
+       .cmd_rcgr = 0x1600c,
+       .mnd_width = 8,
+       .hid_width = 5,
+       .parent_map = gcc_parent_map_0,
+       .freq_tbl = ftbl_gcc_sdcc4_apps_clk_src,
+       .safe_src_freq_tbl = &cxo_safe_src_f,

Why does sdcc have safe src stuff? Is something turning on the sdcc clk outside of our control?

Quoted 4 lines
Quoted 1 line

I will get more details on this and will get back.

Any news?

I am removing the safe src for SDCC, but I am trying to get details from teams as to why this was added, if it would be required I will add back the safe src index again and submit the patch.

Quoted 34 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
drivers/clk/qcom/gcc-sdm845.c new file +9 -0
+       .clkr.hw.init = &(struct clk_init_data){
+               .name = "gcc_sdcc4_apps_clk_src",
+               .parent_names = gcc_parent_names_0,
+               .num_parents = 4,
+               .flags = CLK_SET_RATE_PARENT,
+               .ops = &clk_rcg2_shared_ops,
+       },
+};
+

[...]

Quoted 16 lines

drivers/clk/qcom/gcc-sdm845.c line 3158

Quoted 12 lines
drivers/clk/qcom/gcc-sdm845.c new file +12 -0
+
+static struct clk_branch gcc_video_xo_clk = {
+       .halt_reg = 0xb028,
+       .halt_check = BRANCH_HALT,
+       .clkr = {
+               .enable_reg = 0xb028,
+               .enable_mask = BIT(0),
+               .hw.init = &(struct clk_init_data){
+                       .name = "gcc_video_xo_clk",
+                       .flags = CLK_IS_CRITICAL,
+                       .ops = &clk_branch2_ops,
+

These things have no parents and we mark them critical. Why are we even exposing them to the kernel? Are they not on by default? Are we going to change these to non-critical at some point in the future?

Quoted 4 lines

These clocks are not enabled by default and going to video or other multimedia cores so we are marking them as critical and need to expose to the kernel. As of now, there is no plan to change these to non-critical.

Quoted 7 lines

Ok. Can we open code enabling these branches in the driver probe then? Still seems wasteful if nobody uses these.

Put another way, either a driver (or other clk controller) should be toggling these gates at runtime or we should enable them once and leave them out of the framework. If the driver approach is taken, then the drivers should be able to turn the clks on and off to save some power.

As of now, no client driver is taking care of toggling these gates at runtime. We want these clocks to be always on and that's why marked them as CRITICAL so that if any user tries to unprepare/disable then it won't happen and framework generates the warning.
Once the client drivers will take care of above, then we will submit a cleanup patch.

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html