clk: tegra: Fix clock rate computation
PATCH 1/5 clk: tegra: Fix clock rate computation
The PLL output frequency is multiplied during the P-divider computation, so it needs to be divided by the P-divider again before returning.
This fixes an issue where clk_round_rate() would return the multiplied frequency instead of the real one after the P-divider.
--- drivers/clk/tegra/clk-pll.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/tegra/clk-pll.c +2 -0
@@ -441,6 +441,8 @@ static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,return -EINVAL ; } + cfg->output_rate >>= p_div; +if (pll->params->pdiv_tohw) { ret =_p_div_to_hw (hw,1 << p_div);if (ret <0 )
Signature · 1 line
1.8.4.2
A message that is not in the archive (sent off-list or not yet received): 1384787499-26994-1-git-send-email-treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
PATCH 2/5 clk: tegra: Initialize DSI low-power clocks
The low-power DSI clocks are used during host-driven transactions on the DSI bus. Documentation recommends that they be children of PLLP and run at a frequency of at least 52 MHz.
---
Note: The 68 MHz that they are configured to is what the downstream kernel uses. It seems as good a default as any.
drivers/clk/tegra/clk-tegra114.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/tegra/clk-tegra114.c +2 -0
@@ -1305,6 +1305,8 @@ static struct tegra_clk_init_table init_table[] __initdata = { {TEGRA114_CLK_DISP2, TEGRA114_CLK_PLL_P, 600000000, 0}, {TEGRA114_CLK_GR2D, TEGRA114_CLK_PLL_C2, 300000000, 0}, {TEGRA114_CLK_GR3D, TEGRA114_CLK_PLL_C2, 300000000, 0}, + {TEGRA114_CLK_DSIALP, TEGRA114_CLK_PLL_P, 68000000, 0}, + {TEGRA114_CLK_DSIBLP, TEGRA114_CLK_PLL_P, 68000000, 0},/* This MUST be the last entry. */ {TEGRA114_CLK_CLK_MAX, TEGRA114_CLK_CLK_MAX, 0, 0},
Signature · 1 line
1.8.4.2
PATCH 3/5 clk: tegra: add locking to periph clks
In reply to a message not in the archiveFrom: Peter De Schrijver <[email protected]>
Tegra124 has periph clocks which share the hw register. Hence locking is required.
--- drivers/clk/tegra/clk-tegra-periph.c | 36 +++++++++++++++++++++--------------- drivers/clk/tegra/clk.h | 10 ++++++---- 2 files changed, 27 insertions(+), 19 deletions(-)
drivers/clk/tegra/clk-tegra-periph.c +21 -15
@@ -132,69 +132,75 @@ _clk_num, _gate_flags, _clk_id) \TEGRA_INIT_DATA_TABLE (_name,NULL ,NULL , _parents, _offset,\30 ,MASK (2 ),0 ,0 ,8 ,1 ,0 , \ - _clk_num, _gate_flags, _clk_id, _parents##_idx, 0) + _clk_num, _gate_flags, _clk_id, _parents##_idx, 0, \ + NULL)#define MUX_FLAGS (_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id, flags)\ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, 0, _clk_num, \ - _gate_flags, _clk_id, _parents##_idx, flags) + _gate_flags, _clk_id, _parents##_idx, flags, NULL)#define MUX8 (_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 8, 1, 0, _clk_num, \ - _gate_flags, _clk_id, _parents##_idx, 0) + _gate_flags, _clk_id, _parents##_idx, 0, NULL)#define INT (_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT,\ - _clk_num, _gate_flags, _clk_id, _parents##_idx, 0) + _clk_num, _gate_flags, _clk_id, _parents##_idx, 0, \ + NULL)#define INT_FLAGS (_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id, flags)\ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 8, 1, TEGRA_DIVIDER_INT,\ - _clk_num, _gate_flags, _clk_id, _parents##_idx, flags) + _clk_num, _gate_flags, _clk_id, _parents##_idx, \ + flags, NULL)#define INT8 (_name, _parents, _offset,\ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT,\ - _clk_num, _gate_flags, _clk_id, _parents##_idx, 0) + _clk_num, _gate_flags, _clk_id, _parents##_idx, 0, \ + NULL)#define UART (_name, _parents, _offset,\ _clk_num, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 16, 1, TEGRA_DIVIDER_UART,\ - _clk_num, 0, _clk_id, _parents##_idx, 0) + _clk_num, 0, _clk_id, _parents##_idx, 0, NULL)#define I2C (_name, _parents, _offset,\ _clk_num, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ 30, MASK(2), 0, 0, 16, 0, 0, _clk_num, \ - 0, _clk_id, _parents##_idx, 0) + 0, _clk_id, _parents##_idx, 0, NULL)#define XUSB (_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_INT,\ - _clk_num, _gate_flags, _clk_id, _parents##_idx, 0) + _clk_num, _gate_flags, _clk_id, _parents##_idx, 0, \ + NULL)#define AUDIO (_name, _offset, _clk_num,\ _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, mux_d_audio_clk, \ _offset, 16, 0xE01F, 0, 0, 8, 1, 0, _clk_num, \ - _gate_flags , _clk_id, mux_d_audio_clk_idx, 0) + _gate_flags , _clk_id, mux_d_audio_clk_idx, 0, \ + NULL)#define NODIV (_name, _parents, _offset, \ _mux_shift, _mux_mask, _clk_num, \ - _gate_flags, _clk_id) \ + _gate_flags, _clk_id, _lock) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\ _mux_shift, _mux_mask, 0, 0, 0, 0, 0,\ _clk_num, (_gate_flags) | TEGRA_PERIPH_NO_DIV,\ - _clk_id, _parents##_idx, 0) + _clk_id, _parents##_idx, 0, _lock)#define GATE (_name, _parent_name, \ _clk_num, _gate_flags, _clk_id, _flags) \
@@ -203,7 +209,7 @@ .clk_id = _clk_id, \ .p.parent_name = _parent_name, \ .periph =TEGRA_CLK_PERIPH (0 ,0 ,0 ,0 ,0 ,0 ,0 , \ - _clk_num, _gate_flags, 0), \ + _clk_num, _gate_flags, 0, NULL), \ .flags = _flags \ }
@@ -456,8 +462,8 @@ static struct tegra_periph_init_data periph_clks[] = {MUX8 ("clk72mhz" , mux_pllp3_pllc_clkm,CLK_SOURCE_CLK72MHZ ,177 ,TEGRA_PERIPH_NO_RESET , tegra_clk_clk72Mhz),MUX8 ("sor0" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_SOR0 ,182 ,0 , tegra_clk_sor0),MUX_FLAGS ("csite" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_CSITE ,73 ,TEGRA_PERIPH_ON_APB , tegra_clk_csite,CLK_IGNORE_UNUSED ), -NODIV ("disp1" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP1 ,29 ,7 ,27 ,0 , tegra_clk_disp1), -NODIV ("disp2" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP2 ,29 ,7 ,26 ,0 , tegra_clk_disp2), +NODIV ("disp1" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP1 ,29 ,7 ,27 ,0 , tegra_clk_disp1,NULL ), +NODIV ("disp2" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP2 ,29 ,7 ,26 ,0 , tegra_clk_disp2,NULL ),UART ("uarta" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_UARTA ,6 , tegra_clk_uarta),UART ("uartb" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_UARTB ,7 , tegra_clk_uartb), UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc),
drivers/clk/tegra/clk.h +6 -4
@@ -439,19 +439,21 @@ struct clk *tegra_clk_register_periph_nodiv(const char *name,#define TEGRA_CLK_PERIPH (_mux_shift, _mux_mask, _mux_flags, \ _div_shift, _div_width, _div_frac_width, \ _div_flags, _clk_num,\ - _gate_flags, _table) \ + _gate_flags, _table, _lock) \ { \ .mux = { \ .flags = _mux_flags, \ .shift = _mux_shift, \ .mask = _mux_mask, \ .table = _table, \ + .lock = _lock, \ }, \ .divider = { \ .flags = _div_flags, \ .shift = _div_shift, \ .width = _div_width, \ .frac_width = _div_frac_width, \ + .lock = _lock, \ }, \ .gate = { \ .flags = _gate_flags, \
@@ -481,7 +483,7 @@ struct tegra_periph_init_data { _mux_shift, _mux_mask, _mux_flags, _div_shift, \ _div_width, _div_frac_width, _div_flags, \ _clk_num, _gate_flags, _clk_id, _table, \ - _flags) \ + _flags, _lock) \ { \ .name = _name, \ .clk_id = _clk_id, \
@@ -491,7 +493,7 @@ struct tegra_periph_init_data { _mux_flags, _div_shift, \ _div_width, _div_frac_width, \ _div_flags, _clk_num, \ - _gate_flags, _table), \ + _gate_flags, _table, _lock), \ .offset = _offset, \ .con_id = _con_id, \ .dev_id = _dev_id, \
@@ -506,7 +508,7 @@ struct tegra_periph_init_data { _mux_shift,BIT (_mux_width) -1 , _mux_flags, \ _div_shift, _div_width, _div_frac_width, _div_flags, \ _clk_num, _gate_flags, _clk_id,\ - NULL, 0) + NULL, 0, NULL)/** * struct clk_super_mux - super clock
Signature · 1 line
1.8.4.2
PATCH 4/5 clk: tegra: add TEGRA_PERIPH_NO_GATE
In reply to a message not in the archiveFrom: Peter De Schrijver <[email protected]>
Tegra124 has a clock which consists of a mux and a fractional divider. Add support for this.
--- drivers/clk/tegra/clk-periph.c | 18 +++++++++++++++--- drivers/clk/tegra/clk-tegra-periph.c | 6 ++++++ drivers/clk/tegra/clk.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-)
drivers/clk/tegra/clk-periph.c +15 -3
@@ -170,6 +170,14 @@ const struct clk_ops tegra_clk_periph_nodiv_ops = { .disable = clk_periph_disable, }; +const struct clk_ops tegra_clk_periph_no_gate_ops = { + .get_parent = clk_periph_get_parent, + .set_parent = clk_periph_set_parent, + .recalc_rate = clk_periph_recalc_rate, + .round_rate = clk_periph_round_rate, + .set_rate = clk_periph_set_rate, +}; + static struct clk *_tegra_clk_register_periph(const char *name, const char **parent_names, int num_parents, struct tegra_clk_periph *periph,
@@ -181,11 +189,15 @@ static struct clk *_tegra_clk_register_periph(const char *name,struct tegra_clk_periph_regs *bank;bool div = !(periph->gate.flags &TEGRA_PERIPH_NO_DIV ); - flags |= periph->gate.flags &TEGRA_PERIPH_NO_DIV ? -CLK_SET_RATE_PARENT :0 ; +if (periph->gate.flags &TEGRA_PERIPH_NO_DIV ) { + flags |=CLK_SET_RATE_PARENT ; + init.ops = &tegra_clk_periph_nodiv_ops; + }else if (periph->gate.flags &TEGRA_PERIPH_NO_GATE ) + init.ops = &tegra_clk_periph_no_gate_ops; +else + init.ops = &tegra_clk_periph_ops; init.name = name; - init.ops = div ? &tegra_clk_periph_ops : &tegra_clk_periph_nodiv_ops; init.flags = flags; init.parent_names = parent_names; init.num_parents = num_parents;
drivers/clk/tegra/clk-tegra-periph.c +6 -0
@@ -147,6 +147,12 @@ 29, MASK(3), 0, 0, 8, 1, 0, _clk_num, \ _gate_flags, _clk_id, _parents##_idx, 0, NULL) +#define MUX8_NOGATE_LOCK (_name, _parents, _offset, _clk_id, _lock) \ + TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset, \ + 29, MASK(3), 0, 0, 8, 1, 0, 0, \ + TEGRA_PERIPH_NO_GATE, _clk_id, \ + _parents##_idx, 0, _lock) +#define INT (_name, _parents, _offset, \ _clk_num, _gate_flags, _clk_id) \ TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\
drivers/clk/tegra/clk.h +1 -0
@@ -391,6 +391,7 @@ struct tegra_clk_periph_gate {#define TEGRA_PERIPH_ON_APB BIT(2)#define TEGRA_PERIPH_WAR_1005168 BIT(3)#define TEGRA_PERIPH_NO_DIV BIT(4) +#define TEGRA_PERIPH_NO_GATE BIT(5)void tegra_periph_reset (struct tegra_clk_periph_gate *gate,bool assert);extern const struct clk_ops tegra_clk_periph_gate_ops;
Signature · 1 line
1.8.4.2
PATCH 5/5 clk: tegra: rework sor0 clock for Tegra124
In reply to a message not in the archiveFrom: Peter De Schrijver <[email protected]>
Rework the sor0 clock as 2 clocks: sor0, which comprises the 2nd level mux and the gate and sor0_lvds which comprises the 1st level mux and the fractional divider.
--- drivers/clk/tegra/clk-id.h | 1 + drivers/clk/tegra/clk-tegra-periph.c | 10 +++++++++- drivers/clk/tegra/clk-tegra124.c | 1 + include/dt-bindings/clock/tegra124-car.h | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-)
drivers/clk/tegra/clk-id.h +1 -0
@@ -186,6 +186,7 @@ enum clk_id { tegra_clk_se, tegra_clk_soc_therm, tegra_clk_sor0, + tegra_clk_sor0_lvds, tegra_clk_spdif, tegra_clk_spdif_2x, tegra_clk_spdif_in,
drivers/clk/tegra/clk-tegra-periph.c +9 -1
@@ -231,6 +231,7 @@static DEFINE_SPINLOCK (PLLP_OUTA_lock);static DEFINE_SPINLOCK (PLLP_OUTB_lock);static DEFINE_SPINLOCK (PLLP_OUTC_lock); +static DEFINE_SPINLOCK (sor0_lock);#define MUX_I2S_SPDIF (_id) \ static const char *mux_pllaout0_##_id##_2x_pllp_clkm[] = { "pll_a_out0", \
@@ -371,6 +372,12 @@ static u32 mux_pllm_pllc_pllp_plla_pllc2_c3_clkm_idx[] = { [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6, }; +static const char *mux_clkm_plldp_sor0lvds[] = { +"clk_m" ,"pll_dp" ,"sor0_lvds" , +}; + +#define mux_clkm_plldp_sor0lvds_idx NULL +static struct tegra_periph_init_data periph_clks[] = {AUDIO ("d_audio" ,CLK_SOURCE_D_AUDIO ,106 ,TEGRA_PERIPH_ON_APB , tegra_clk_d_audio),AUDIO ("dam0" ,CLK_SOURCE_DAM0 ,108 ,TEGRA_PERIPH_ON_APB , tegra_clk_dam0),
@@ -466,10 +473,11 @@ static struct tegra_periph_init_data periph_clks[] = {MUX8 ("entropy" , mux_pllp_clkm1,CLK_SOURCE_ENTROPY ,149 ,0 , tegra_clk_entropy),MUX8 ("hdmi_audio" , mux_pllp3_pllc_clkm,CLK_SOURCE_HDMI_AUDIO ,176 ,TEGRA_PERIPH_NO_RESET , tegra_clk_hdmi_audio),MUX8 ("clk72mhz" , mux_pllp3_pllc_clkm,CLK_SOURCE_CLK72MHZ ,177 ,TEGRA_PERIPH_NO_RESET , tegra_clk_clk72Mhz), -MUX8 ("sor0" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_SOR0 ,182 ,0 , tegra_clk_sor0), +MUX8_NOGATE_LOCK ("sor0_lvds" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_SOR0 , tegra_clk_sor0_lvds, &sor0_lock),MUX_FLAGS ("csite" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_CSITE ,73 ,TEGRA_PERIPH_ON_APB , tegra_clk_csite,CLK_IGNORE_UNUSED ),NODIV ("disp1" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP1 ,29 ,7 ,27 ,0 , tegra_clk_disp1,NULL ),NODIV ("disp2" , mux_pllp_pllm_plld_plla_pllc_plld2_clkm,CLK_SOURCE_DISP2 ,29 ,7 ,26 ,0 , tegra_clk_disp2,NULL ), +NODIV ("sor0" , mux_clkm_plldp_sor0lvds,CLK_SOURCE_SOR0 ,14 ,3 ,182 ,0 , tegra_clk_sor0, &sor0_lock),UART ("uarta" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_UARTA ,6 , tegra_clk_uarta),UART ("uartb" , mux_pllp_pllc_pllm_clkm,CLK_SOURCE_UARTB ,7 , tegra_clk_uartb), UART("uartc", mux_pllp_pllc_pllm_clkm, CLK_SOURCE_UARTC, 55, tegra_clk_uartc),
drivers/clk/tegra/clk-tegra124.c +1 -0
@@ -857,6 +857,7 @@ static struct tegra_clk tegra124_clks[tegra_clk_max] __initdata = { [tegra_clk_adx1] = { .dt_id = TEGRA124_CLK_ADX1, .present = true }, [tegra_clk_dpaux] = { .dt_id = TEGRA124_CLK_DPAUX, .present = true }, [tegra_clk_sor0] = { .dt_id = TEGRA124_CLK_SOR0, .present = true }, + [tegra_clk_sor0_lvds] = { .dt_id = TEGRA124_CLK_SOR0_LVDS, .present = true }, [tegra_clk_gpu] = { .dt_id = TEGRA124_CLK_GPU, .present = true }, [tegra_clk_amx1] = { .dt_id = TEGRA124_CLK_AMX1, .present = true }, [tegra_clk_uartb] = { .dt_id = TEGRA124_CLK_UARTB, .present = true },
include/dt-bindings/clock/tegra124-car.h +2 -1
@@ -335,6 +335,7 @@#define TEGRA124_CLK_CLK_OUT_3_MUX 308#define TEGRA124_CLK_DSIA_MUX 309#define TEGRA124_CLK_DSIB_MUX 310 -#define TEGRA124_CLK_CLK_MAX 311 +#define TEGRA124_CLK_SOR0_LVDS 311 +#define TEGRA124_CLK_CLK_MAX 312#endif /* _DT_BINDINGS_CLOCK_TEGRA124_CAR_H */
Signature · 1 line
1.8.4.2
Quoted 6 lines · Thierry Reding
The PLL output frequency is multiplied during the P-divider computation, so it needs to be divided by the P-divider again before returning.
This fixes an issue where
clk_round_rate()would return the multiplied frequency instead of the real one after the P-divider.
Series Acked-by: Peter De Schrijver <[email protected]> I will squash the Tegra124 fixes in the Tegra124 series.
Cheers,
Peter.
A message that is not in the archive (sent off-list or not yet received): 20131125140910.GI26617-Rysk9IDjsxmJz7etNGeUX8VPkgjIgRvpAL8bYrjMMd8@public.gmane.org
Quoted 10 lines · Peter De Schrijver
Quoted 6 lines · Thierry Reding
The PLL output frequency is multiplied during the P-divider computation, so it needs to be divided by the P-divider again before returning.
This fixes an issue where
clk_round_rate()would return the multiplied frequency instead of the real one after the P-divider.Series Acked-by: Peter De Schrijver <[email protected]> I will squash the Tegra124 fixes in the Tegra124 series.
BTW, as a maintainer of some code, you usually do one of:
a) Apply the patch yourself.
b) Ack the patch for someone else to apply.
It's unusual to do both, unless there's some confusion which tree the patch will go through, so you do e.g. (b) first then later find out that
(a) was more correct, or vice-versa.
Also, in the past I've been asked to make sure that all ARM-related patches go to the main ARM list as well as the Tegra-specific list, to make sure they get full visibility.