clk: tegra: refactor 7.1 div calculation
Subsystems (3)
PATCH v2 1/3 clk: tegra: refactor 7.1 div calculation
From: Peter De Schrijver <[email protected]>
Move this to a separate file so it can be used to calculate the sdmmc clock dividers.
--- drivers/clk/tegra/Makefile | 1 + drivers/clk/tegra/clk-divider.c | 30 ++++------------------- drivers/clk/tegra/clk.h | 3 +++ drivers/clk/tegra/div71.c | 54 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 drivers/clk/tegra/div71.c
drivers/clk/tegra/Makefile +1 -0
@@ -24,3 +24,4 @@ obj-$(CONFIG_ARCH_TEGRA_132_SOC) += clk-tegra124.o obj-y += cvb.o obj-$(CONFIG_ARCH_TEGRA_210_SOC) += clk-tegra210.o obj-$(CONFIG_CLK_TEGRA_BPMP) += clk-bpmp.o +obj-y += div71.o
drivers/clk/tegra/clk-divider.c +5 -25
@@ -32,35 +32,15 @@static int get_div (struct tegra_clk_frac_div *divider,unsigned long rate,unsigned long parent_rate) { -u64 divider_ux1 = parent_rate; -u8 flags = divider->flags; -int mul; - -if (!rate) -return 0 ; - - mul =get_mul (divider); - -if (!(flags &TEGRA_DIVIDER_INT )) - divider_ux1 *= mul; - -if (flags &TEGRA_DIVIDER_ROUND_UP ) - divider_ux1 += rate -1 ; - -do_div (divider_ux1, rate); - -if (flags &TEGRA_DIVIDER_INT ) - divider_ux1 *= mul; +int div; - divider_ux1 -= mul; + div =div71_get (rate, parent_rate, divider->width, divider->frac_width, + divider->flags); -if ((s64 )divider_ux1 <0 ) +if (div <0 )return 0 ; -if (divider_ux1 >get_max_div (divider)) -return get_max_div (divider); - -return divider_ux1; +return div; } static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw,
drivers/clk/tegra/clk.h +3 -0
@@ -811,6 +811,9 @@ extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;int tegra_pll_wait_for_lock (struct tegra_clk_pll *pll);u16 tegra_pll_get_fixed_mdiv (struct clk_hw *hw,unsigned long input_rate);int tegra_pll_p_div_to_hw (struct tegra_clk_pll *pll,u8 p_div); +int div71_get (unsigned long rate,unsigned parent_rate,u8 width, +u8 frac_width,u8 flags); +/* Combined read fence with delay */ #define fence_udelay (delay, reg) \
drivers/clk/tegra/div71.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/3 clk: tegra: Add sdmmc mux divider clock
From: Peter De-Schrijver <[email protected]>
Add a clock type to model the sdmmc switch divider clocks which have paths to source clocks bypassing the divider (Low Jitter paths). These are handled by selecting the lj path when the divider is 1 (ie the rate is the parent rate), otherwise the normal path with divider will be selected. Otherwise this clock behaves as a normal peripheral clock.
--- drivers/clk/tegra/Makefile | 1 + drivers/clk/tegra/clk-sdmmc-mux.c | 254 ++++++++++++++++++++++++++++++++++++++ drivers/clk/tegra/clk.h | 27 ++++ 3 files changed, 282 insertions(+) create mode 100644 drivers/clk/tegra/clk-sdmmc-mux.c
drivers/clk/tegra/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y += clk-periph-fixed.o obj-y += clk-periph-gate.o obj-y += clk-pll.o obj-y += clk-pll-out.o +obj-y += clk-sdmmc-mux.o obj-y += clk-super.o obj-y += clk-tegra-audio.o obj-y += clk-tegra-periph.o
drivers/clk/tegra/clk-sdmmc-mux.c new file +254 -0
254 lines not on this page · raw message
drivers/clk/tegra/clk.h +27 -0
@@ -19,6 +19,7 @@#include <linux/clk-provider.h> #include <linux/clkdev.h> +#include <linux/delay.h> /** * struct tegra_clk_sync_source - external clock source from codec
@@ -705,6 +706,32 @@ struct clk *tegra_clk_register_super_clk(const char *name, const char * const *parent_names, u8 num_parents, unsigned long flags, void __iomem *reg, u8 clk_super_flags, spinlock_t *lock); + +/** +* struct tegra_sdmmc_mux - switch divider with Low Jitter inputs for SDMMC +* +* @hw: handle between common and hardware-specific interfaces +* @reg: register controlling mux and divider +* @flags: hardware-specific flags +* @lock: optional register lock +* @gate: gate clock +* @gate_ops: gate clock ops +*/ +struct tegra_sdmmc_mux { +struct clk_hw hw; +void __iomem *reg; +spinlock_t *lock; +const struct clk_ops *gate_ops; +struct tegra_clk_periph_gate gate; +u8 div_flags; +}; + +#define to_clk_sdmmc_mux (_hw) container_of(_hw, struct tegra_sdmmc_mux, hw) + +struct clk *tegra_clk_register_sdmmc_mux_div (const char *name, +void __iomem *clk_base,u32 offset,u32 clk_num,u8 div_flags, +unsigned long flags,void *lock); +/** * struct clk_init_table - clock initialization table * @clk_id: clock id as mentioned in device tree bindings
Signature · 1 line
2.7.4
Stephen Boyd
maintainerRe: [PATCH v2 2/3] clk: tegra: Add sdmmc mux divider clock
Quoting Aapo Vienamo (2018-07-04 03:17:34)
drivers/clk/tegra/clk-sd=
Quoted 1 line
drivers/clk/tegra/clk-sd= renamed from drivers/clk/tegra/clk-sdmmc-mux.c +0
-0
mmc-mux.c
drivers/clk/tegra/clk-sdmmc-mux.c line 8
Quoted 13 lines
new file mode 100644
index 0000000..8e19cb3drivers/clk/tegra/clk-sdmmc-mux.c new file +8
-0@@ -0,0 +1,254 @@ +/* +* Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. +* +* based on clk-mux.c + +* Copyright (C) 2011 Sascha Hauer, Pengutronix <[email protected]> +* Copyright (C) 2011 Richard Zhao, Linaro <[email protected]> +* Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro=
.org>
drivers/clk/tegra/clk-sdmmc-mux.c line 10
Quoted 2 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +2
-0+* +* This program is free software; you can redistribute it and/or modify =
it
drivers/clk/tegra/clk-sdmmc-mux.c
Quoted 6 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +6
-0+* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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
drivers/clk/tegra/clk-sdmmc-mux.c line 20
Quoted 4 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +4
-0+* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>.
Any chance we can get SPDX tags here instead of all the boiler plate?
Quoted 7 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +7
-0+*/ + +#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/types.h> + +#include "clk.h"
drivers/clk/tegra/clk-sdmmc-mux.c
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+ +#define DIV_MASK GENMASK(7, 0) +#define MUX_SHIFT 29 +#define MUX_MASK GENMASK(MUX_SHIFT + 2, MUX_SHIFT) + +#define get_max_div (d) DIV_MASK +#define get_div_field (val) ((val) & DIV_MASK) +#define get_mux_field (val) (((val) & MUX_MASK) >> MUX_SHIFT) + +static const char * const mux_sdmmc_parents[] =3D { "pll_p", "pll_c4_out=
2",
drivers/clk/tegra/clk-sdmmc-mux.c line 38
Quoted 1 line
drivers/clk/tegra/clk-sdmmc-mux.c new file +1
-0+ "pll_c4_out0", "pll_c4_=
out1",
drivers/clk/tegra/clk-sdmmc-mux.c line 40
Quoted 2 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +2
-0+ "clk_m" }; +static u8 mux_lj_idx[] =3D { [0] =3D 0, [1] =3D 1, [2] =3D 2, [3] =3D 5,=
[4] =3D 6 };
drivers/clk/tegra/clk-sdmmc-mux.c line 41
Quoted 1 line
drivers/clk/tegra/clk-sdmmc-mux.c new file +1
-0+static u8 mux_non_lj_idx[] =3D { [0] =3D 0, [1] =3D 3, [2] =3D 7, [3] =
=3D 4, [4] =3D 6 };
These can be const?
Quoted 3 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +3
-0+ +static u8 clk_sdmmc_mux_get_parent (struct clk_hw *hw) +{
[...]
Quoted 19 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +19
-0+static int clk_sdmmc_mux_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ + struct tegra_sdmmc_mux *sdmmc_mux =3D to_clk_sdmmc_mux(hw); +int div; + unsigned long flags =3D 0; +u32 val; +u8 src; + + div =3D div71_get(rate, parent_rate, 8, 1, sdmmc_mux->div_flags); +if (div <0 ) +return div; + +if (sdmmc_mux->lock) +spin_lock_irqsave (sdmmc_mux->lock, flags); + + src =3D clk_sdmmc_mux_get_parent(hw); +if (div) + src =3D mux_non_lj_idx[src];
drivers/clk/tegra/clk-sdmmc-mux.c line 164
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+else + src =3D mux_lj_idx[src]; + + val =3D src << MUX_SHIFT; + val |=3D div; +writel (val, sdmmc_mux->reg); +fence_udelay (2 , sdmmc_mux->reg); + +if (sdmmc_mux->lock) +spin_unlock_irqrestore (sdmmc_mux->lock, flags);
This conditional locking will give sparse a headache. O well.
Quoted 26 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +26
-0+ +return 0 ; +} + +static int clk_sdmmc_mux_is_enabled (struct clk_hw *hw) +{ + struct tegra_sdmmc_mux *sdmmc_mux =3D to_clk_sdmmc_mux(hw); + const struct clk_ops *gate_ops =3D sdmmc_mux->gate_ops; +struct clk_hw *gate_hw =3D &sdmmc_mux->gate.hw; + +__clk_hw_set_clk (gate_hw, hw); + +return gate_ops->is_enabled (gate_hw); +} + +static int clk_sdmmc_mux_enable (struct clk_hw *hw) +{ + struct tegra_sdmmc_mux *sdmmc_mux =3D to_clk_sdmmc_mux(hw); + const struct clk_ops *gate_ops =3D sdmmc_mux->gate_ops; +struct clk_hw *gate_hw =3D &sdmmc_mux->gate.hw; + +__clk_hw_set_clk (gate_hw, hw); + +return gate_ops->enable (gate_hw); +} +
drivers/clk/tegra/clk-sdmmc-mux.c
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+static void clk_sdmmc_mux_disable (struct clk_hw *hw) +{ + struct tegra_sdmmc_mux *sdmmc_mux =3D to_clk_sdmmc_mux(hw); + const struct clk_ops *gate_ops =3D sdmmc_mux->gate_ops; +struct clk_hw *gate_hw =3D &sdmmc_mux->gate.hw; + + gate_ops->disable (gate_hw); +} + +const struct clk_ops tegra_clk_sdmmc_mux_ops =3D {
static?
Quoted 15 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+ .get_parent =3D clk_sdmmc_mux_get_parent, + .set_parent =3D clk_sdmmc_mux_set_parent, + .determine_rate =3D clk_sdmmc_mux_determine_rate, + .recalc_rate =3D clk_sdmmc_mux_recalc_rate, + .set_rate =3D clk_sdmmc_mux_set_rate, + .is_enabled =3D clk_sdmmc_mux_is_enabled, + .enable =3D clk_sdmmc_mux_enable, + .disable =3D clk_sdmmc_mux_disable, +}; +drivers/clk/tegra/clk.h +0
-0
drivers/clk/tegra/clk.h line 23
Quoted 5 lines
drivers/clk/tegra/clk.h +1
-0@@ -19,6 +19,7 @@ =#include <linux/clk-provider.h> #include <linux/clkdev.h> +#include <linux/delay.h>
Why? Include this in the C file that cares please.
Quoted 4 lines
drivers/clk/tegra/clk.h +0
-0=/**
* structtegra_clk_sync_source- external clock source from codec
Re: [PATCH v2 2/3] clk: tegra: Add sdmmc mux divider clock
Quoted 145 lines · Stephen Boyd
Quoting Aapo Vienamo (2018-07-04 03:17:34)
Quoted 16 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0@@ -0,0 +1,254 @@ +/* +* Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved. +* +* based on clk-mux.c + +* Copyright (C) 2011 Sascha Hauer, Pengutronix <[email protected]> +* Copyright (C) 2011 Richard Zhao, Linaro <[email protected]> +* Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it drivers/clk/tegra/clk-sdmmc-mux.c line 20
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. Any chance we can get SPDX tags here instead of all the boiler plate?
Quoted 11 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +11
-0+*/ + +#include <linux/clk-provider.h> +#include <linux/err.h> +#include <linux/types.h> + +#include "clk.h" + +#define DIV_MASK GENMASK(7, 0) +#define MUX_SHIFT 29 +#define MUX_MASK GENMASK(MUX_SHIFT + 2, MUX_SHIFT)drivers/clk/tegra/clk-sdmmc-mux.c line 41
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+ +#define get_max_div (d) DIV_MASK +#define get_div_field (val) ((val) & DIV_MASK) +#define get_mux_field (val) (((val) & MUX_MASK) >> MUX_SHIFT) + +static const char *const mux_sdmmc_parents[] = {"pll_p" ,"pll_c4_out2" , +"pll_c4_out0" ,"pll_c4_out1" , +"clk_m" }; +static u8 mux_lj_idx[] = { [0 ] =0 , [1 ] =1 , [2 ] =2 , [3 ] =5 , [4 ] =6 }; +static u8 mux_non_lj_idx[] = { [0 ] =0 , [1 ] =3 , [2 ] =7 , [3 ] =4 , [4 ] =6 };These can be const?
Quoted 3 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +3
-0+ +static u8 clk_sdmmc_mux_get_parent (struct clk_hw *hw) +{[...]
Quoted 19 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +19
-0+static int clk_sdmmc_mux_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate) +{ +struct tegra_sdmmc_mux *sdmmc_mux =to_clk_sdmmc_mux (hw); +int div; +unsigned long flags =0 ; +u32 val; +u8 src; + + div =div71_get (rate, parent_rate,8 ,1 , sdmmc_mux->div_flags); +if (div <0 ) +return div; + +if (sdmmc_mux->lock) +spin_lock_irqsave (sdmmc_mux->lock, flags); + + src =clk_sdmmc_mux_get_parent (hw); +if (div) + src = mux_non_lj_idx[src];drivers/clk/tegra/clk-sdmmc-mux.c line 164
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+else + src = mux_lj_idx[src]; + + val = src <<MUX_SHIFT ; + val |= div; +writel (val, sdmmc_mux->reg); +fence_udelay (2 , sdmmc_mux->reg); + +if (sdmmc_mux->lock) +spin_unlock_irqrestore (sdmmc_mux->lock, flags);This conditional locking will give sparse a headache. O well.
Quoted 26 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +26
-0+ +return 0 ; +} + +static int clk_sdmmc_mux_is_enabled (struct clk_hw *hw) +{ +struct tegra_sdmmc_mux *sdmmc_mux =to_clk_sdmmc_mux (hw); +const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; +struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; + +__clk_hw_set_clk (gate_hw, hw); + +return gate_ops->is_enabled (gate_hw); +} + +static int clk_sdmmc_mux_enable (struct clk_hw *hw) +{ +struct tegra_sdmmc_mux *sdmmc_mux =to_clk_sdmmc_mux (hw); +const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; +struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; + +__clk_hw_set_clk (gate_hw, hw); + +return gate_ops->enable (gate_hw); +} +drivers/clk/tegra/clk-sdmmc-mux.c line 200
Quoted 10 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+static void clk_sdmmc_mux_disable (struct clk_hw *hw) +{ +struct tegra_sdmmc_mux *sdmmc_mux =to_clk_sdmmc_mux (hw); +const struct clk_ops *gate_ops = sdmmc_mux->gate_ops; +struct clk_hw *gate_hw = &sdmmc_mux->gate.hw; + + gate_ops->disable (gate_hw); +} + +const struct clk_ops tegra_clk_sdmmc_mux_ops = {static?
Quoted 16 lines
drivers/clk/tegra/clk-sdmmc-mux.c new file +10
-0+ .get_parent = clk_sdmmc_mux_get_parent, + .set_parent = clk_sdmmc_mux_set_parent, + .determine_rate = clk_sdmmc_mux_determine_rate, + .recalc_rate = clk_sdmmc_mux_recalc_rate, + .set_rate = clk_sdmmc_mux_set_rate, + .is_enabled = clk_sdmmc_mux_is_enabled, + .enable = clk_sdmmc_mux_enable, + .disable = clk_sdmmc_mux_disable, +}; +drivers/clk/tegra/clk.h +0
-0@@ -19,6 +19,7 @@
Quoted 6 lines
drivers/clk/tegra/clk.h line 22
Quoted 3 lines
drivers/clk/tegra/clk.h +1
-0#include <linux/clk-provider.h> #include <linux/clkdev.h> +#include <linux/delay.h> Why? Include this in the C file that cares please.
The fence_udelay macro uses udelay and is used in clk-sdmmc-mux.c. However it seems more appropriate to include delay.h here rather than in every single user of the macro.
Peter.
PATCH v2 3/3 clk: tegra: make sdmmc2 and sdmmc4 as sdmmc clocks
In reply to Aapo VienamoFrom: Peter De-Schrijver <[email protected]>
These clock have low jitter paths to certain parents. To model these correctly, use the sdmmc mux divider clock type.
--- drivers/clk/tegra/clk-id.h | 2 -- drivers/clk/tegra/clk-tegra-periph.c | 11 ----------- drivers/clk/tegra/clk-tegra210.c | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 15 deletions(-)
drivers/clk/tegra/clk-id.h +0 -2
@@ -227,13 +227,11 @@ enum clk_id { tegra_clk_sdmmc1_9, tegra_clk_sdmmc2, tegra_clk_sdmmc2_8, - tegra_clk_sdmmc2_9, tegra_clk_sdmmc3, tegra_clk_sdmmc3_8, tegra_clk_sdmmc3_9, tegra_clk_sdmmc4, tegra_clk_sdmmc4_8, - tegra_clk_sdmmc4_9, tegra_clk_se, tegra_clk_soc_therm, tegra_clk_soc_therm_8,
drivers/clk/tegra/clk-tegra-periph.c +0 -11
@@ -451,15 +451,6 @@ static u32 mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0_idx[] = { [0] = 0, [1] = 3, [2] = 4, [3] = 6, [4] = 7, }; -static const char *mux_pllp_clkm_pllc4_out2_out1_out0_lj[] = { -"pll_p" , -"pll_c4_out2" ,"pll_c4_out0" ,/* LJ input */ -"pll_c4_out2" ,"pll_c4_out1" , -"pll_c4_out1" ,/* LJ input */ -"clk_m" ,"pll_c4_out0" -}; -#define mux_pllp_clkm_pllc4_out2_out1_out0_lj_idx NULL -static const char *mux_pllp_pllc2_c_c3_clkm[] = {"pll_p" ,"pll_c2" ,"pll_c" ,"pll_c3" ,"clk_m" };
@@ -686,9 +677,7 @@ static struct tegra_periph_init_data periph_clks[] = {MUX ("sdmmc3" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_SDMMC3 ,69 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc3),MUX ("sdmmc4" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_SDMMC4 ,15 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc4),MUX8 ("sdmmc1" , mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0,CLK_SOURCE_SDMMC1 ,14 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc1_9), -MUX8 ("sdmmc2" , mux_pllp_clkm_pllc4_out2_out1_out0_lj,CLK_SOURCE_SDMMC2 ,9 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc2_9),MUX8 ("sdmmc3" , mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0,CLK_SOURCE_SDMMC3 ,69 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc3_9), -MUX8 ("sdmmc4" , mux_pllp_clkm_pllc4_out2_out1_out0_lj,CLK_SOURCE_SDMMC4 ,15 ,TEGRA_PERIPH_ON_APB , tegra_clk_sdmmc4_9),MUX ("la" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_LA ,76 ,TEGRA_PERIPH_ON_APB , tegra_clk_la),MUX ("trace" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_TRACE ,77 ,TEGRA_PERIPH_ON_APB , tegra_clk_trace), MUX("owr", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_OWR, 71, TEGRA_PERIPH_ON_APB, tegra_clk_owr),
drivers/clk/tegra/clk-tegra210.c +12 -2
@@ -44,6 +44,8 @@#define CLK_SOURCE_EMC 0x19c#define CLK_SOURCE_SOR1 0x410#define CLK_SOURCE_LA 0x1f8 +#define CLK_SOURCE_SDMMC2 0x154 +#define CLK_SOURCE_SDMMC4 0x164#define PLLC_BASE 0x80#define PLLC_OUT 0x84
@@ -2286,11 +2288,9 @@ static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = { [tegra_clk_rtc] = { .dt_id = TEGRA210_CLK_RTC, .present = true }, [tegra_clk_timer] = { .dt_id = TEGRA210_CLK_TIMER, .present = true }, [tegra_clk_uarta_8] = { .dt_id = TEGRA210_CLK_UARTA, .present = true }, - [tegra_clk_sdmmc2_9] = { .dt_id = TEGRA210_CLK_SDMMC2, .present = true }, [tegra_clk_i2s1] = { .dt_id = TEGRA210_CLK_I2S1, .present = true }, [tegra_clk_i2c1] = { .dt_id = TEGRA210_CLK_I2C1, .present = true }, [tegra_clk_sdmmc1_9] = { .dt_id = TEGRA210_CLK_SDMMC1, .present = true }, - [tegra_clk_sdmmc4_9] = { .dt_id = TEGRA210_CLK_SDMMC4, .present = true }, [tegra_clk_pwm] = { .dt_id = TEGRA210_CLK_PWM, .present = true }, [tegra_clk_i2s2] = { .dt_id = TEGRA210_CLK_I2S2, .present = true }, [tegra_clk_usbd] = { .dt_id = TEGRA210_CLK_USBD, .present = true },
@@ -3030,6 +3030,16 @@ static __init void tegra210_periph_clk_init(void __iomem *clk_base, 0, NULL); clks[TEGRA210_CLK_ACLK ] = clk; + clk =tegra_clk_register_sdmmc_mux_div ("sdmmc2" , clk_base, +CLK_SOURCE_SDMMC2 ,9 , +TEGRA_DIVIDER_ROUND_UP ,0 ,NULL ); + clks[TEGRA210_CLK_SDMMC2 ] = clk; + + clk =tegra_clk_register_sdmmc_mux_div ("sdmmc4" , clk_base, +CLK_SOURCE_SDMMC4 ,15 , +TEGRA_DIVIDER_ROUND_UP ,0 ,NULL ); + clks[TEGRA210_CLK_SDMMC4 ] = clk; +for (i =0 ; i <ARRAY_SIZE (tegra210_periph); i++) {struct tegra_periph_init_data *init = &tegra210_periph[i];struct clk **clkp;
Signature · 1 line
2.7.4
Quoted 5 lines · Aapo Vienamo
From: Peter De Schrijver <[email protected]>
Move this to a separate file so it can be used to calculate the sdmmc clock dividers.
Series Acked-By: Peter De Schrijver <[email protected]>
Quoted 141 lines
Signed-off-by Peter De-Schrijver <[email protected]>Signed-off-by Aapo Vienamo <[email protected]>--- drivers/clk/tegra/Makefile | 1 + drivers/clk/tegra/clk-divider.c | 30 ++++------------------- drivers/clk/tegra/clk.h | 3 +++ drivers/clk/tegra/div71.c | 54 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 drivers/clk/tegra/div71.cdrivers/clk/tegra/Makefile +1
-0@@ -24,3 +24,4 @@ obj-$(CONFIG_ARCH_TEGRA_132_SOC) += clk-tegra124.o obj-y += cvb.o obj-$(CONFIG_ARCH_TEGRA_210_SOC) += clk-tegra210.o obj-$(CONFIG_CLK_TEGRA_BPMP) += clk-bpmp.o +obj-y += div71.odrivers/clk/tegra/clk-divider.c +5
-25@@ -32,35 +32,15 @@static int get_div (struct tegra_clk_frac_div *divider,unsigned long rate,unsigned long parent_rate) { -u64 divider_ux1 = parent_rate; -u8 flags = divider->flags; -int mul; - -if (!rate) -return 0 ; - - mul =get_mul (divider); - -if (!(flags &TEGRA_DIVIDER_INT )) - divider_ux1 *= mul; - -if (flags &TEGRA_DIVIDER_ROUND_UP ) - divider_ux1 += rate -1 ; - -do_div (divider_ux1, rate); - -if (flags &TEGRA_DIVIDER_INT ) - divider_ux1 *= mul; +int div; - divider_ux1 -= mul; + div =div71_get (rate, parent_rate, divider->width, divider->frac_width, + divider->flags); -if ((s64 )divider_ux1 <0 ) +if (div <0 )return 0 ; -if (divider_ux1 >get_max_div (divider)) -return get_max_div (divider); - -return divider_ux1; +return div; } static unsigned long clk_frac_div_recalc_rate(struct clk_hw *hw,drivers/clk/tegra/clk.h +3
-0@@ -811,6 +811,9 @@ extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;int tegra_pll_wait_for_lock (struct tegra_clk_pll *pll);u16 tegra_pll_get_fixed_mdiv (struct clk_hw *hw,unsigned long input_rate);int tegra_pll_p_div_to_hw (struct tegra_clk_pll *pll,u8 p_div); +int div71_get (unsigned long rate,unsigned parent_rate,u8 width, +u8 frac_width,u8 flags); +/* Combined read fence with delay */ #define fence_udelay (delay, reg) \drivers/clk/tegra/div71.c new file +54
-0@@ -0,0 +1,54 @@ +/* +* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kernel.h> + +#include "clk.h" + +#define div_mask (w) ((1 << (w)) - 1) + +int div71_get (unsigned long rate,unsigned parent_rate,u8 width, +u8 frac_width,u8 flags) +{ +u64 divider_ux1 = parent_rate; +int mul; + +if (!rate) +return 0 ; + + mul =1 << frac_width; + +if (!(flags &TEGRA_DIVIDER_INT )) + divider_ux1 *= mul; + +if (flags &TEGRA_DIVIDER_ROUND_UP ) + divider_ux1 += rate -1 ; + +do_div (divider_ux1, rate); + +if (flags &TEGRA_DIVIDER_INT ) + divider_ux1 *= mul; + +if (divider_ux1 < mul) +return 0 ; + + divider_ux1 -= mul; + +if (divider_ux1 >div_mask (width)) +return div_mask (width); + +return divider_ux1; +}Signature · 1 line
2.7.4
Stephen Boyd
maintainerQuoting Aapo Vienamo (2018-07-04 03:17:33)
drivers/clk/tegra/div71.c line 4
Quoted 10 lines
drivers/clk/tegra/div71.c new file +4
-0@@ -0,0 +1,54 @@ +/* +* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify =
it
drivers/clk/tegra/div71.c
Quoted 6 lines
drivers/clk/tegra/div71.c new file +6
-0+* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope 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
drivers/clk/tegra/div71.c line 17
Quoted 7 lines
drivers/clk/tegra/div71.c new file +7
-0+* more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kernel.h>
You can include <asm/div64.h> instead.
drivers/clk/tegra/div71.c
Quoted 9 lines
drivers/clk/tegra/div71.c new file +9
-0+ +#include "clk.h" + +#define div_mask (w) ((1 << (w)) - 1) + +int div71_get (unsigned long rate,unsigned parent_rate,u8 width, +u8 frac_width,u8 flags) +{ + u64 divider_ux1 =3D parent_rate;
Hmm ok, now it's unsigned. That's works too.
Quoted 28 lines
drivers/clk/tegra/div71.c new file +28
-0+int mul; + +if (!rate) +return 0 ; + + mul =3D 1 << frac_width; + +if (!(flags &TEGRA_DIVIDER_INT )) + divider_ux1 *=3D mul; + +if (flags &TEGRA_DIVIDER_ROUND_UP ) + divider_ux1 +=3D rate - 1; + +do_div (divider_ux1, rate); + +if (flags &TEGRA_DIVIDER_INT ) + divider_ux1 *=3D mul; + +if (divider_ux1 < mul) +return 0 ; + + divider_ux1 -=3D mul; + +if (divider_ux1 >div_mask (width)) +return div_mask (width); + +return divider_ux1; +}