clk: qcom: Add support for RCG to register for DFS
Subsystems (3)
v2 cover clk: qcom: Add support for RCG to register for DFS
[v2]
* Move the dfs register function 'qcom_cc_register_rcg_dfs'
to clk-rcg2.c instead of common.c
* At boot read the DFS enable register and override the clk_ops to be used for dfs or non-dfs RCGs.
* Remove flag 'dfs_enabled'.
* Remove functions 'clk_rcg2_dfs_determine_rate_lazy'
* Remove 'struct dfs_table *dfs_entry'
* Remove '_freq_tbl_determine_dfs_rate'
* Combine the function 'clk_index_pre_div_and_mode' and 'calculate_m_and_n' to a single function and named it 'clk_rcg2_calculate_m_and_n'.
* Remove taking M/N/PERF offsets as function arguments.
* Add clocks in gcc-sdm845.c the DFS clock array to register.
[v1]
* Update SPDX for files.
* Add new clk_ops for DFS mode which would be used if dfs is enabled, else fall back to the clk_rcg2_shared_ops.
* Use kcalloc in place kzalloc.
* Fixed the return type for 'clk_parent_index_pre_div_and_mode' which is now renamed to 'clk_index_pre_div_and_mode'.
* Removed return of -EPERM from 'clk_rcg2_set_rate' and new dfs clk_ops is introduced.
* Pass frequency table entry structure to function calculate_m_and_n.
* Remove desc from qcom_cc_register_rcg_dfs and instead pass array of
clk_rcg2.
* Add a dfs_enable flag to identify if dfs mode is enabled.
In the cases where a RCG requires a Dynamic Frequency switch support requires to register which would at runtime read the clock perf level registers to identify the frequencies supported and update the frequency table accordingly.
Taniya Das (2):
clk: qcom: Add support for RCG to register for DFS
clk: qcom: gcc: Register QUPv3 RCGs for DFS on SDM845
drivers/clk/qcom/clk-rcg.h | 5 + drivers/clk/qcom/clk-rcg2.c | 214 ++++++++++++++++++++++++++++++++++++++++++ drivers/clk/qcom/common.c | 14 +-- drivers/clk/qcom/common.h | 16 +--- drivers/clk/qcom/gcc-sdm845.c | 27 +++++- 5 files changed, 250 insertions(+), 26 deletions(-)
--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.
PATCH v2 1/2 clk: qcom: Add support for RCG to register for DFS
Dynamic Frequency switch is a feature of clock controller by which request from peripherals allows automatic switching frequency of input clock. There are various performance levels associated to a root clock generator. Register the root clock generators(RCG) to switch to use the dfs clock ops in the cases where DFS is enabled.
The DFS clock ops would at runtime read the clock perf level registers to identify the frequencies supported and update the frequency table accordingly.
--- drivers/clk/qcom/clk-rcg.h | 5 ++ drivers/clk/qcom/clk-rcg2.c | 214 ++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/qcom/common.c | 14 +-- drivers/clk/qcom/common.h | 16 +--- 4 files changed, 224 insertions(+), 25 deletions(-)
drivers/clk/qcom/clk-rcg.h +5 -0
@@ -5,6 +5,7 @@#define __QCOM_CLK_RCG_H__#include <linux/clk-provider.h> +#include <linux/platform_device.h> #include "clk-regmap.h" struct freq_tbl {
@@ -160,5 +161,9 @@ struct clk_rcg2 {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; +extern const struct clk_ops clk_rcg2_dfs_ops; + +extern int qcom_cc_register_rcg_dfs (struct platform_device *pdev, +struct clk_rcg2 **rcgs,int num_clks);#endif
drivers/clk/qcom/clk-rcg2.c +214 -0
229 lines not on this page · raw message
drivers/clk/qcom/common.c +2 -12
@@ -1,15 +1,5 @@ -/* -* Copyright (c) 2013-2014, 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 -* may be copied, distributed, and modified under those terms. -* -* 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. -*/ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. */ #include <linux/export.h> #include <linux/module.h>
drivers/clk/qcom/common.h +3 -13
@@ -1,15 +1,6 @@ -/* -* Copyright (c) 2014, 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 -* may be copied, distributed, and modified under those terms. -* -* 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. -*/ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2014, 2018, The Linux Foundation. All rights reserved. */ +#ifndef __QCOM_CLK_COMMON_H__#define __QCOM_CLK_COMMON_H__
@@ -68,5 +59,4 @@ extern int qcom_cc_really_probe(struct platform_device *pdev, struct regmap *regmap);extern int qcom_cc_probe (struct platform_device *pdev,const struct qcom_cc_desc *desc); -#endif
--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.
PATCH v2 2/2 clk: qcom: gcc: Register QUPv3 RCGs for DFS on SDM845
In reply to Taniya DasQUPv3 clocks support DFS and thus register the RCGs which require support for the same.
--- drivers/clk/qcom/gcc-sdm845.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/clk/qcom/gcc-sdm845.c +26 -1
@@ -3421,9 +3421,29 @@ enum { };MODULE_DEVICE_TABLE (of, gcc_sdm845_match_table); +static struct clk_rcg2 *gcc_dfs_clocks[] = { + &gcc_qupv3_wrap0_s0_clk_src, + &gcc_qupv3_wrap0_s1_clk_src, + &gcc_qupv3_wrap0_s2_clk_src, + &gcc_qupv3_wrap0_s3_clk_src, + &gcc_qupv3_wrap0_s4_clk_src, + &gcc_qupv3_wrap0_s5_clk_src, + &gcc_qupv3_wrap0_s6_clk_src, + &gcc_qupv3_wrap0_s7_clk_src, + &gcc_qupv3_wrap1_s0_clk_src, + &gcc_qupv3_wrap1_s1_clk_src, + &gcc_qupv3_wrap1_s2_clk_src, + &gcc_qupv3_wrap1_s3_clk_src, + &gcc_qupv3_wrap1_s4_clk_src, + &gcc_qupv3_wrap1_s5_clk_src, + &gcc_qupv3_wrap1_s6_clk_src, + &gcc_qupv3_wrap1_s7_clk_src, +}; +static int gcc_sdm845_probe (struct platform_device *pdev) {struct regmap *regmap; +int ret; regmap =qcom_cc_map (pdev, &gcc_sdm845_desc);if (IS_ERR (regmap))
@@ -3437,7 +3457,12 @@ static int gcc_sdm845_probe(struct platform_device *pdev)regmap_update_bits (regmap,0x48190 ,BIT (0 ),0x1 );regmap_update_bits (regmap,0x52004 ,BIT (22 ),0x1 ); -return qcom_cc_really_probe (pdev, &gcc_sdm845_desc, regmap); + ret =qcom_cc_really_probe (pdev, &gcc_sdm845_desc, regmap); +if (ret) +return ret; + +return qcom_cc_register_rcg_dfs (pdev, gcc_dfs_clocks, +ARRAY_SIZE (gcc_dfs_clocks)); }static struct platform_driver gcc_sdm845_driver = {
--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.
Stephen Boyd
maintainerRe: [PATCH v2 2/2] clk: qcom: gcc: Register QUPv3 RCGs for DFS on SDM845
Quoting Taniya Das (2018-06-28 04:47:31)
drivers/clk/qcom/gcc-sdm845.c static int gcc_sdm845_probe(struct platform_device *pdev) · line 3465
Quoted 11 lines
drivers/clk/qcom/gcc-sdm845.c +6
-1@@ -3437,7 +3457,12 @@ static int gcc_sdm845_probe(struct platform_device *pdev)regmap_update_bits (regmap,0x48190 ,BIT (0 ),0x1 );regmap_update_bits (regmap,0x52004 ,BIT (22 ),0x1 ); -return qcom_cc_really_probe (pdev, &gcc_sdm845_desc, regmap); + ret =qcom_cc_really_probe (pdev, &gcc_sdm845_desc, regmap); +if (ret) +return ret; + +return qcom_cc_register_rcg_dfs (pdev, gcc_dfs_clocks, +ARRAY_SIZE (gcc_dfs_clocks));
This looks backwards. We shouldn't expose the clks to drivers and then make their functionality work by registering dfs clks. The order should be swapped.
Stephen Boyd
maintainerQuoting Taniya Das (2018-06-28 04:47:30)
Quoted 8 lines
Dynamic Frequency switch is a feature of clock controller by which request from peripherals allows automatic switching frequency of input clock. There are various performance levels associated to a root clock generator. Register the root clock generators(RCG) to switch to use the dfs clock ops in the cases where DFS is enabled.
The DFS clock ops would at runtime read the clock perf level registers to identify the frequencies supported and update the frequency table accordingly.
But nobody is really using the frequency table except for clk_round_rate()? Can you add some comments into the commit text and the code indicating how it works in hardware? I think the way it works is by having DFS enabled in the clock controller, and then another register in the QUP register space controls the index that the clk configures itself for. But I'm not clear on if the RCG registers are updated when DFS frequency is set, or if anything is visible from the clk controller hardware besides being in DFS mode and the frequency plan.
Quoted 7 lines
Signed-off-by Taniya Das <[email protected]>drivers/clk/qcom/clk-rcg2.c +0
-0
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 947
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +7
-0@@ -929,3 +938,208 @@ static void clk_rcg2_shared_disable(struct clk_hw *hw) .set_rate_and_parent = clk_rcg2_shared_set_rate_and_parent, };EXPORT_SYMBOL_GPL (clk_rcg2_shared_ops); + +/* Common APIs to be used for DFS based RCGR */ +static int clk_rcg2_calculate_m_and_n (struct clk_hw *hw,u32 *mode, +unsigned long *prate,int level,struct freq_tbl *f) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct clk_hw *phw;
Just 'p' for parent is good.
Quoted 25 lines
drivers/clk/qcom/clk-rcg2.c +25
-0+u32 val, mask, cfg, m_off, n_off, offset; +int i, ret, num_parents; + + offset =SE_PERF_DFSR (level); + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + offset, &cfg); +if (ret) +return ret; + + mask =BIT (rcg->hid_width) -1 ; + f->pre_div = cfg & mask ? (cfg & mask) :1 ; + + *mode = cfg &CFG_MODE_MASK ; + *mode >>=CFG_MODE_SHIFT ; + + cfg &=CFG_SRC_SEL_MASK ; + cfg >>=CFG_SRC_SEL_SHIFT ; + + num_parents =clk_hw_get_num_parents (hw); +for (i =0 ; i < num_parents; i++) { +if (cfg == rcg->parent_map[i].cfg) { + f->src = rcg->parent_map[i].src; + phw =clk_hw_get_parent_by_index (&rcg->clkr.hw, i); + *prate =clk_hw_get_rate (phw); + } + }
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 982
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+ +if (!*mode) +return 0 ; + +/* Calculate M & N values */ + m_off =SE_PERF_M_DFSR (level); + n_off =SE_PERF_N_DFSR (level); + + mask =BIT (rcg->mnd_width) -1 ; + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + m_off, &val);
Why weird space before regmap_read?
Quoted 19 lines
drivers/clk/qcom/clk-rcg2.c +19
-0+if (ret) { +pr_err ("Failed to read M offset register\n" ); +return ret; + } + val &= mask; + f->m = val; + + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + n_off, &val); +if (ret) { +pr_err ("Failed to read N offset register\n" ); +return ret; + } +/* val ~(N-M) */ + val = ~val; + val &= mask; + val += f->m; + f->n = val; + +return 0 ;
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1011
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+} + +static int clk_rcg2_dfs_populate_freq_table (struct clk_rcg2 *rcg) +{ +struct freq_tbl *dfs_freq_tbl; +int i, j, ret =0 ; +unsigned long calc_freq, prate =0 ; +u32 mode =0 ; + + dfs_freq_tbl = kcalloc(MAX_PERF_LEVEL, sizeof(struct freq_tbl),
sizeof(*dfs_freq_tbl) or just call it freq_tbl. We know it's dfs already.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1018
Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ GFP_KERNEL); +if (!dfs_freq_tbl) +return -ENOMEM ; + +for (i =0 ; i <MAX_PERF_LEVEL ; i++) { + ret =clk_rcg2_calculate_m_and_n (&rcg->clkr.hw, &mode, &prate, + i, &dfs_freq_tbl[i]);
Why can't this function return the frequency? Or 0 if it failed for some reason?
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1026
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+if (ret) { +kfree (dfs_freq_tbl); +return ret; + } + + calc_freq =calc_rate (prate, dfs_freq_tbl[i].m, + dfs_freq_tbl[i].n, mode, + dfs_freq_tbl[i].pre_div);
Because this is not so good looking.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1029
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+/* Check for duplicate frequencies to end table */ +for (j =0 ; j < i; j++) {
Duplicate space after j here should be cleaned up.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1030
Quoted 1 line
drivers/clk/qcom/clk-rcg2.c +1
-0+if (dfs_freq_tbl[j].freq == calc_freq)
Is it sometimes a duplicate frequency that came earlier in the table? Why isn't this just a check for the same frequency in succession while going through the table? Or even a frequency that's lower than the previous one?
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+ goto done; + } + + dfs_freq_tbl[i].freq = calc_freq; + } +done: + rcg->freq_tbl = dfs_freq_tbl; +
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1048
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+return 0 ; +} + +static int clk_rcg2_dfs_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int ret; + +if (rcg->freq_tbl ==NULL ) {
if (!rcg->freq_tbl) is preferred style.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1051
Quoted 3 lines
drivers/clk/qcom/clk-rcg2.c +3
-0+ ret =clk_rcg2_dfs_populate_freq_table (rcg); +if (ret) { +pr_err ("Failed to update DFS tables\n" );
Also print the clk name? Who knows which one this happens for otherwise.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1059
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+return ret; + } + } + +return clk_rcg2_shared_ops.determine_rate (hw, req); +} + +static int clk_rcg2_dfs_set_rate(struct clk_hw *hw, unsigned long rate,
We can't set the rate?
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1066
Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ unsigned long prate) +{ +return 0 ; +} + +static unsigned long +clk_rcg2_dfs_recalc_rate (struct clk_hw *hw,unsigned long parent_rate)
Huh? How will we know what frequency the clk is running at? We can't?
Why are these even implemented then? Just implement determine_rate() op so that clk_round_rate() can be called in a loop to figure out the frequency plan index? Or if the registers are actually updated when QUP asks for an index, then recalc_rate() should be implemented and the nocache flag should be added to the clk so we know to recalculate each time clk_get_rate() is called.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1071
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+{ +return 0 ; +} + +const struct clk_ops clk_rcg2_dfs_ops = {
static?
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c +11
-0+ .is_enabled = clk_rcg2_is_enabled, + .get_parent = clk_rcg2_get_parent, + .recalc_rate = clk_rcg2_dfs_recalc_rate, + .determine_rate = clk_rcg2_dfs_determine_rate, + .set_rate = clk_rcg2_dfs_set_rate, +}; +EXPORT_SYMBOL_GPL (clk_rcg2_dfs_ops); + +static int clk_rcg2_enable_dfs (struct clk_rcg2 *rcg,struct device *dev) +{ +struct regmap *regmap;
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1092
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+struct clk_init_data *init; +struct clk_rate_request req = { }; +u32 val; +int ret; + + regmap =dev_get_regmap (dev,NULL ); +if (!regmap) +return -EINVAL ; + + init =kzalloc (sizeof (struct clk_init_data ),GFP_KERNEL );
Use sizeof(*init) so type doesn't matter.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1097
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+if (!init) +return -ENOMEM ; + + init->name = rcg->clkr.hw.init->name; + init->ops = &clk_rcg2_shared_ops;
These should already be done statically.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1101
Quoted 4 lines
drivers/clk/qcom/clk-rcg2.c +4
-0+ init->flags = rcg->clkr.hw.init->flags; + init->parent_names = rcg->clkr.hw.init->parent_names; + init->num_parents = rcg->clkr.hw.init->num_parents; + rcg->clkr.hw.init = init;
In fact, the whole init structure should just be whatever is there already.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1106
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+ + ret =regmap_read (regmap, rcg->cmd_rcgr +SE_CMD_DFSR_OFFSET , + &val); +if (ret) { +dev_err (dev,"Failed to read DFS enable register\n" );
For which clk? And do we even care? The regmap_read most likely never fails.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1114
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+return -EINVAL ; + } + +if (!(val &SE_CMD_DFS_EN )) +return 0 ; + + init->ops = &clk_rcg2_dfs_ops; + rcg->clkr.hw.init = init;
The clks were already registered. I don't know how this works.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1122
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+ rcg->freq_tbl =NULL ; + +/* +* In case the clocks are registered earlier than determine the dfs +* rates. +*/ +if (__clk_lookup (rcg->clkr.hw.init->name)) +return clk_rcg2_dfs_determine_rate (&rcg->clkr.hw, &req);
Remove this. Do the DFS enabled probing before registering the clks.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1127
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+ +return 0 ; +} + +int qcom_cc_register_rcg_dfs(struct platform_device *pdev,
Please don't pass the device. Pass the regmap.
Quoted 51 lines
drivers/clk/qcom/clk-rcg2.c +18
-0+ struct clk_rcg2 **rcgs, int num_clks) +{ + int i, ret = 0; + +for (i =0 ; i < num_clks; i++) { + ret =clk_rcg2_enable_dfs (rcgs[i], &pdev->dev); +if (ret) { +const char *name = rcgs[i]->clkr.hw.init->name; + +dev_err (&pdev->dev, +"%s DFS frequencies update failed\n" , name); +break ; + } + } + +return ret; +} +EXPORT_SYMBOL_GPL (qcom_cc_register_rcg_dfs);drivers/clk/qcom/common.c +2
-12@@ -1,15 +1,5 @@ -/* -* Copyright (c) 2013-2014, 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 -* may be copied, distributed, and modified under those terms. -* -* 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. -*/ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. */ #include <linux/export.h> #include <linux/module.h> drivers/clk/qcom/common.h +0
-5@@ -1,15 +1,6 @@ -/* -* Copyright (c) 2014, 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
drivers/clk/qcom/common.h line 3
Quoted 10 lines
drivers/clk/qcom/common.h +3
-7-* may be copied, distributed, and modified under those terms. -* -* 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. -*/ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2014, 2018, The Linux Foundation. All rights reserved. */ +
Can you split these last two file hunks into another patch to update common for SPDX? I can apply that without anything else.
drivers/clk/qcom/common.h extern int qcom_cc_really_probe(struct platform_device *pdev, · line 71
Quoted 8 lines
drivers/clk/qcom/common.h +0
-1#ifndef __QCOM_CLK_COMMON_H__#define __QCOM_CLK_COMMON_H__@@ -68,5 +59,4 @@ extern int qcom_cc_really_probe(struct platform_device *pdev, struct regmap *regmap);extern int qcom_cc_probe (struct platform_device *pdev,const struct qcom_cc_desc *desc); -
No.
Quoted 2 lines
drivers/clk/qcom/common.h +0
-1#endif --
Hello Stephen,
Thanks for your review comments.
Quoted 10 lines · Stephen Boyd
Quoting Taniya Das (2018-06-28 04:47:30)
Quoted 8 lines
Dynamic Frequency switch is a feature of clock controller by which request from peripherals allows automatic switching frequency of input clock. There are various performance levels associated to a root clock generator. Register the root clock generators(RCG) to switch to use the dfs clock ops in the cases where DFS is enabled.
The DFS clock ops would at runtime read the clock perf level registers to identify the frequencies supported and update the frequency table accordingly.
Quoted 10 lines
But nobody is really using the frequency table except for
clk_round_rate()? Can you add some comments into the commit text and the code indicating how it works in hardware? I think the way it works is by having DFS enabled in the clock controller, and then another register in the QUP register space controls the index that the clk configures itself for. But I'm not clear on if the RCG registers are updated when DFS frequency is set, or if anything is visible from the clk controller hardware besides being in DFS mode and the frequency plan.Quoted 1 line
Sure, added few more details in the next series.
Quoted 10 lines
Quoted 10 lines
Signed-off-by Taniya Das <[email protected]>drivers/clk/qcom/clk-rcg2.c +1
-0@@ -929,3 +938,208 @@ static void clk_rcg2_shared_disable(struct clk_hw *hw) .set_rate_and_parent = clk_rcg2_shared_set_rate_and_parent, };EXPORT_SYMBOL_GPL (clk_rcg2_shared_ops); +
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 947
Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +6
-0+/* Common APIs to be used for DFS based RCGR */ +static int clk_rcg2_calculate_m_and_n (struct clk_hw *hw,u32 *mode, +unsigned long *prate,int level,struct freq_tbl *f) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct clk_hw *phw;Just 'p' for parent is good.
Taken care in the next patch.
Quoted 29 lines
Quoted 29 lines
drivers/clk/qcom/clk-rcg2.c +29
-0+u32 val, mask, cfg, m_off, n_off, offset; +int i, ret, num_parents; + + offset =SE_PERF_DFSR (level); + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + offset, &cfg); +if (ret) +return ret; + + mask =BIT (rcg->hid_width) -1 ; + f->pre_div = cfg & mask ? (cfg & mask) :1 ; + + *mode = cfg &CFG_MODE_MASK ; + *mode >>=CFG_MODE_SHIFT ; + + cfg &=CFG_SRC_SEL_MASK ; + cfg >>=CFG_SRC_SEL_SHIFT ; + + num_parents =clk_hw_get_num_parents (hw); +for (i =0 ; i < num_parents; i++) { +if (cfg == rcg->parent_map[i].cfg) { + f->src = rcg->parent_map[i].src; + phw =clk_hw_get_parent_by_index (&rcg->clkr.hw, i); + *prate =clk_hw_get_rate (phw); + } + } + +if (!*mode) +return 0 ; +
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 982
Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +6
-0+/* Calculate M & N values */ + m_off =SE_PERF_M_DFSR (level); + n_off =SE_PERF_N_DFSR (level); + + mask =BIT (rcg->mnd_width) -1 ; + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + m_off, &val);Why weird space before
regmap_read?
removed.
Quoted 24 lines
Quoted 24 lines
drivers/clk/qcom/clk-rcg2.c +24
-0+if (ret) { +pr_err ("Failed to read M offset register\n" ); +return ret; + } + val &= mask; + f->m = val; + + ret =regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr + n_off, &val); +if (ret) { +pr_err ("Failed to read N offset register\n" ); +return ret; + } +/* val ~(N-M) */ + val = ~val; + val &= mask; + val += f->m; + f->n = val; + +return 0 ; +} + +static int clk_rcg2_dfs_populate_freq_table (struct clk_rcg2 *rcg) +{ +struct freq_tbl *dfs_freq_tbl;
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1011
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+int i, j, ret =0 ; +unsigned long calc_freq, prate =0 ; +u32 mode =0 ; + + dfs_freq_tbl = kcalloc(MAX_PERF_LEVEL, sizeof(struct freq_tbl),
sizeof(*dfs_freq_tbl)or just call itfreq_tbl. We know it's dfs already.
Fixed in the next patch.
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1018
Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ GFP_KERNEL); +if (!dfs_freq_tbl) +return -ENOMEM ; + +for (i =0 ; i <MAX_PERF_LEVEL ; i++) { + ret =clk_rcg2_calculate_m_and_n (&rcg->clkr.hw, &mode, &prate, + i, &dfs_freq_tbl[i]);Why can't this function return the frequency? Or 0 if it failed for some reason?
Sure, have taken care in the next patch.
Quoted 14 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1026
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+if (ret) { +kfree (dfs_freq_tbl); +return ret; + } + + calc_freq =calc_rate (prate, dfs_freq_tbl[i].m, + dfs_freq_tbl[i].n, mode, + dfs_freq_tbl[i].pre_div);Because this is not so good looking.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1029
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+/* Check for duplicate frequencies to end table */ +for (j =0 ; j < i; j++) {
Quoted 9 lines
Duplicate space after j here should be cleaned up.
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1030
Quoted 1 line
drivers/clk/qcom/clk-rcg2.c +1
-0+if (dfs_freq_tbl[j].freq == calc_freq)Is it sometimes a duplicate frequency that came earlier in the table? Why isn't this just a check for the same frequency in succession while going through the table? Or even a frequency that's lower than the previous one?
I was trimming the table based on the last frequencies, say we have multiple 19.2MHz calculated at the end, so I was trimming the table, but I don't think it is really required. So I have removed this logic.
Quoted 21 lines
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+ goto done; + } + + dfs_freq_tbl[i].freq = calc_freq; + } +done: + rcg->freq_tbl = dfs_freq_tbl; +drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1048
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+return 0 ; +} + +static int clk_rcg2_dfs_determine_rate (struct clk_hw *hw, +struct clk_rate_request *req) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int ret; + +if (rcg->freq_tbl ==NULL ) {if (!rcg->freq_tbl) is preferred style.
Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1051
Quoted 3 lines
drivers/clk/qcom/clk-rcg2.c +3
-0+ ret =clk_rcg2_dfs_populate_freq_table (rcg); +if (ret) { +pr_err ("Failed to update DFS tables\n" );Also print the clk name? Who knows which one this happens for otherwise.
Taken care in the next patch.
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1059
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+return ret; + } + } + +return clk_rcg2_shared_ops.determine_rate (hw, req); +} + +static int clk_rcg2_dfs_set_rate(struct clk_hw *hw, unsigned long rate,We can't set the rate?
No, if it is DFS mode, SW would not be allowed to update the RCG. I have removed the set_rate in the next series.
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1066
Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ unsigned long prate) +{ +return 0 ; +} + +static unsigned long +clk_rcg2_dfs_recalc_rate (struct clk_hw *hw,unsigned long parent_rate)Huh? How will we know what frequency the clk is running at? We can't?
Quoted 7 lines
Why are these even implemented then? Just implement
determine_rate()op so thatclk_round_rate()can be called in a loop to figure out the frequency plan index? Or if the registers are actually updated when QUP asks for an index, thenrecalc_rate()should be implemented and the nocache flag should be added to the clk so we know to recalculate each timeclk_get_rate()is called.
No, we can't read any registers to know the frequency at which the clock is running. I have removed this too in the next series.
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1071
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+{ +return 0 ; +} + +const struct clk_ops clk_rcg2_dfs_ops = {static?
Done.
Quoted 15 lines
Quoted 15 lines
drivers/clk/qcom/clk-rcg2.c +15
-0+ .is_enabled = clk_rcg2_is_enabled, + .get_parent = clk_rcg2_get_parent, + .recalc_rate = clk_rcg2_dfs_recalc_rate, + .determine_rate = clk_rcg2_dfs_determine_rate, + .set_rate = clk_rcg2_dfs_set_rate, +}; +EXPORT_SYMBOL_GPL (clk_rcg2_dfs_ops); + +static int clk_rcg2_enable_dfs (struct clk_rcg2 *rcg,struct device *dev) +{ +struct regmap *regmap; +struct clk_init_data *init; +struct clk_rate_request req = { }; +u32 val; +int ret;
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1092
Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +6
-0+ + regmap =dev_get_regmap (dev,NULL ); +if (!regmap) +return -EINVAL ; + + init =kzalloc (sizeof (struct clk_init_data ),GFP_KERNEL );Use
sizeof(*init)so type doesn't matter.
Done.
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1097
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+if (!init) +return -ENOMEM ; + + init->name = rcg->clkr.hw.init->name; + init->ops = &clk_rcg2_shared_ops;These should already be done statically.
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1101
Quoted 4 lines
drivers/clk/qcom/clk-rcg2.c +4
-0+ init->flags = rcg->clkr.hw.init->flags; + init->parent_names = rcg->clkr.hw.init->parent_names; + init->num_parents = rcg->clkr.hw.init->num_parents; + rcg->clkr.hw.init = init;In fact, the whole init structure should just be whatever is there already.
I would override it now, only if DFS ops is required.
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1106
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+ + ret =regmap_read (regmap, rcg->cmd_rcgr +SE_CMD_DFSR_OFFSET , + &val); +if (ret) { +dev_err (dev,"Failed to read DFS enable register\n" );For which clk? And do we even care? The
regmap_readmost likely never fails.
Removed the print.
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1114
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+return -EINVAL ; + } + +if (!(val &SE_CMD_DFS_EN )) +return 0 ; + + init->ops = &clk_rcg2_dfs_ops; + rcg->clkr.hw.init = init;The clks were already registered. I don't know how this works.
Yes, it worked and it updated the ops.
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1122
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+ rcg->freq_tbl =NULL ; + +/* +* In case the clocks are registered earlier than determine the dfs +* rates. +*/ +if (__clk_lookup (rcg->clkr.hw.init->name)) +return clk_rcg2_dfs_determine_rate (&rcg->clkr.hw, &req);Remove this. Do the DFS enabled probing before registering the clks.
Removed.
Quoted 64 lines
drivers/clk/qcom/clk-rcg2.c static void clk_rcg2_shared_disable(struct clk_hw *hw) · line 1127
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +5
-0+ +return 0 ; +} + +int qcom_cc_register_rcg_dfs(struct platform_device *pdev,Please don't pass the device. Pass the regmap.
Quoted 56 lines
drivers/clk/qcom/clk-rcg2.c +18
-0+ struct clk_rcg2 **rcgs, int num_clks) +{ + int i, ret = 0; + +for (i =0 ; i < num_clks; i++) { + ret =clk_rcg2_enable_dfs (rcgs[i], &pdev->dev); +if (ret) { +const char *name = rcgs[i]->clkr.hw.init->name; + +dev_err (&pdev->dev, +"%s DFS frequencies update failed\n" , name); +break ; + } + } + +return ret; +} +EXPORT_SYMBOL_GPL (qcom_cc_register_rcg_dfs);drivers/clk/qcom/common.c +2
-12@@ -1,15 +1,5 @@ -/* -* Copyright (c) 2013-2014, 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 -* may be copied, distributed, and modified under those terms. -* -* 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. -*/ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. */ #include <linux/export.h> #include <linux/module.h> drivers/clk/qcom/common.h +0
-10@@ -1,15 +1,6 @@ -/* -* Copyright (c) 2014, 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 -* may be copied, distributed, and modified under those terms. -* -* 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
Quoted 9 lines
drivers/clk/qcom/common.h line 3
Quoted 5 lines
drivers/clk/qcom/common.h +3
-2-* GNU General Public License for more details. -*/ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2014, 2018, The Linux Foundation. All rights reserved. */ +Can you split these last two file hunks into another patch to update common for SPDX? I can apply that without anything else.
Removed these patches.
Quoted 13 lines
drivers/clk/qcom/common.h extern int qcom_cc_really_probe(struct platform_device *pdev, · line 71
Quoted 8 lines
drivers/clk/qcom/common.h +0
-1#ifndef __QCOM_CLK_COMMON_H__#define __QCOM_CLK_COMMON_H__@@ -68,5 +59,4 @@ extern int qcom_cc_really_probe(struct platform_device *pdev, struct regmap *regmap);extern int qcom_cc_probe (struct platform_device *pdev,const struct qcom_cc_desc *desc); -No.
Quoted 2 lines
drivers/clk/qcom/common.h +0
-1#endif --
Signature · 4 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation. --