2018-12-01 03:52:14 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright 2018 NXP
|
|
|
|
*/
|
|
|
|
|
2019-04-18 15:20:22 -07:00
|
|
|
#include <linux/clk-provider.h>
|
2018-12-01 03:52:14 -07:00
|
|
|
#include <linux/errno.h>
|
2020-07-29 18:22:51 -07:00
|
|
|
#include <linux/export.h>
|
2019-04-18 15:20:22 -07:00
|
|
|
#include <linux/io.h>
|
2018-12-01 03:52:14 -07:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include "clk.h"
|
|
|
|
|
|
|
|
#define PCG_PREDIV_SHIFT 16
|
|
|
|
#define PCG_PREDIV_WIDTH 3
|
|
|
|
#define PCG_PREDIV_MAX 8
|
|
|
|
|
|
|
|
#define PCG_DIV_SHIFT 0
|
2020-01-27 22:28:36 -07:00
|
|
|
#define PCG_CORE_DIV_WIDTH 3
|
2018-12-01 03:52:14 -07:00
|
|
|
#define PCG_DIV_WIDTH 6
|
|
|
|
#define PCG_DIV_MAX 64
|
|
|
|
|
|
|
|
#define PCG_PCS_SHIFT 24
|
|
|
|
#define PCG_PCS_MASK 0x7
|
|
|
|
|
|
|
|
#define PCG_CGC_SHIFT 28
|
|
|
|
|
|
|
|
static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_divider *divider = to_clk_divider(hw);
|
|
|
|
unsigned long prediv_rate;
|
|
|
|
unsigned int prediv_value;
|
|
|
|
unsigned int div_value;
|
|
|
|
|
|
|
|
prediv_value = readl(divider->reg) >> divider->shift;
|
|
|
|
prediv_value &= clk_div_mask(divider->width);
|
|
|
|
|
|
|
|
prediv_rate = divider_recalc_rate(hw, parent_rate, prediv_value,
|
|
|
|
NULL, divider->flags,
|
|
|
|
divider->width);
|
|
|
|
|
|
|
|
div_value = readl(divider->reg) >> PCG_DIV_SHIFT;
|
|
|
|
div_value &= clk_div_mask(PCG_DIV_WIDTH);
|
|
|
|
|
|
|
|
return divider_recalc_rate(hw, prediv_rate, div_value, NULL,
|
|
|
|
divider->flags, PCG_DIV_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx8m_clk_composite_compute_dividers(unsigned long rate,
|
|
|
|
unsigned long parent_rate,
|
|
|
|
int *prediv, int *postdiv)
|
|
|
|
{
|
|
|
|
int div1, div2;
|
|
|
|
int error = INT_MAX;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
*prediv = 1;
|
|
|
|
*postdiv = 1;
|
|
|
|
|
|
|
|
for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
|
|
|
|
for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
|
|
|
|
int new_error = ((parent_rate / div1) / div2) - rate;
|
|
|
|
|
|
|
|
if (abs(new_error) < abs(error)) {
|
|
|
|
*prediv = div1;
|
|
|
|
*postdiv = div2;
|
|
|
|
error = new_error;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long imx8m_clk_composite_divider_round_rate(struct clk_hw *hw,
|
|
|
|
unsigned long rate,
|
|
|
|
unsigned long *prate)
|
|
|
|
{
|
|
|
|
int prediv_value;
|
|
|
|
int div_value;
|
|
|
|
|
|
|
|
imx8m_clk_composite_compute_dividers(rate, *prate,
|
|
|
|
&prediv_value, &div_value);
|
|
|
|
rate = DIV_ROUND_UP(*prate, prediv_value);
|
|
|
|
|
|
|
|
return DIV_ROUND_UP(rate, div_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
|
|
|
|
unsigned long rate,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_divider *divider = to_clk_divider(hw);
|
2020-02-12 02:03:00 -07:00
|
|
|
unsigned long flags;
|
2018-12-01 03:52:14 -07:00
|
|
|
int prediv_value;
|
|
|
|
int div_value;
|
2018-12-09 08:08:32 -07:00
|
|
|
int ret;
|
2023-08-07 01:22:00 -07:00
|
|
|
u32 orig, val;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
|
|
|
|
&prediv_value, &div_value);
|
|
|
|
if (ret)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(divider->lock, flags);
|
|
|
|
|
2023-08-07 01:22:00 -07:00
|
|
|
orig = readl(divider->reg);
|
|
|
|
val = orig & ~((clk_div_mask(divider->width) << divider->shift) |
|
|
|
|
(clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT));
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
val |= (u32)(prediv_value - 1) << divider->shift;
|
|
|
|
val |= (u32)(div_value - 1) << PCG_DIV_SHIFT;
|
2023-08-07 01:22:00 -07:00
|
|
|
|
|
|
|
if (val != orig)
|
|
|
|
writel(val, divider->reg);
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(divider->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
clk: imx: composite-8m: Add imx8m_divider_determine_rate
Currently, certain clocks are derrived as a divider from their
parent clock. For some clocks, even when CLK_SET_RATE_PARENT
is set, the parent clock is not properly set which can lead
to some relatively inaccurate clock values.
Unlike imx/clk-composite-93 and imx/clk-divider-gate, it
cannot rely on calling a standard determine_rate function,
because the 8m composite clocks have a pre-divider and
post-divider. Because of this, a custom determine_rate
function is necessary to determine the maximum clock
division which is equivalent to pre-divider * the
post-divider.
With this added, the system can attempt to adjust the parent rate
when the proper flags are set which can lead to a more precise clock
value.
On the imx8mplus, no clock changes are present.
On the Mini and Nano, this can help achieve more accurate
lcdif clocks. When trying to get a pixel clock of 31.500MHz
on an imx8m Nano, the clocks divided the 594MHz down, but
left the parent rate untouched which caused a calulation error.
Before:
video_pll 594000000
video_pll_bypass 594000000
video_pll_out 594000000
disp_pixel 31263158
disp_pixel_clk 31263158
Variance = -236842 Hz
After this patch:
video_pll 31500000
video_pll_bypass 31500000
video_pll_out 31500000
disp_pixel 31500000
disp_pixel_clk 31500000
Variance = 0 Hz
All other clocks rates and parent were the same.
Similar results on imx8mm were found.
Fixes: 690dccc4a0bf ("Revert "clk: imx: composite-8m: Add support to determine_rate"")
Signed-off-by: Adam Ford <aford173@gmail.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20230506195325.876871-1-aford173@gmail.com
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
2023-05-06 12:53:25 -07:00
|
|
|
static int imx8m_divider_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
|
|
|
struct clk_divider *divider = to_clk_divider(hw);
|
|
|
|
int prediv_value;
|
|
|
|
int div_value;
|
|
|
|
|
|
|
|
/* if read only, just return current value */
|
|
|
|
if (divider->flags & CLK_DIVIDER_READ_ONLY) {
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = readl(divider->reg);
|
|
|
|
prediv_value = val >> divider->shift;
|
|
|
|
prediv_value &= clk_div_mask(divider->width);
|
|
|
|
prediv_value++;
|
|
|
|
|
|
|
|
div_value = val >> PCG_DIV_SHIFT;
|
|
|
|
div_value &= clk_div_mask(PCG_DIV_WIDTH);
|
|
|
|
div_value++;
|
|
|
|
|
|
|
|
return divider_ro_determine_rate(hw, req, divider->table,
|
|
|
|
PCG_PREDIV_WIDTH + PCG_DIV_WIDTH,
|
|
|
|
divider->flags, prediv_value * div_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return divider_determine_rate(hw, req, divider->table,
|
|
|
|
PCG_PREDIV_WIDTH + PCG_DIV_WIDTH,
|
|
|
|
divider->flags);
|
|
|
|
}
|
|
|
|
|
2018-12-01 03:52:14 -07:00
|
|
|
static const struct clk_ops imx8m_clk_composite_divider_ops = {
|
|
|
|
.recalc_rate = imx8m_clk_composite_divider_recalc_rate,
|
|
|
|
.round_rate = imx8m_clk_composite_divider_round_rate,
|
|
|
|
.set_rate = imx8m_clk_composite_divider_set_rate,
|
clk: imx: composite-8m: Add imx8m_divider_determine_rate
Currently, certain clocks are derrived as a divider from their
parent clock. For some clocks, even when CLK_SET_RATE_PARENT
is set, the parent clock is not properly set which can lead
to some relatively inaccurate clock values.
Unlike imx/clk-composite-93 and imx/clk-divider-gate, it
cannot rely on calling a standard determine_rate function,
because the 8m composite clocks have a pre-divider and
post-divider. Because of this, a custom determine_rate
function is necessary to determine the maximum clock
division which is equivalent to pre-divider * the
post-divider.
With this added, the system can attempt to adjust the parent rate
when the proper flags are set which can lead to a more precise clock
value.
On the imx8mplus, no clock changes are present.
On the Mini and Nano, this can help achieve more accurate
lcdif clocks. When trying to get a pixel clock of 31.500MHz
on an imx8m Nano, the clocks divided the 594MHz down, but
left the parent rate untouched which caused a calulation error.
Before:
video_pll 594000000
video_pll_bypass 594000000
video_pll_out 594000000
disp_pixel 31263158
disp_pixel_clk 31263158
Variance = -236842 Hz
After this patch:
video_pll 31500000
video_pll_bypass 31500000
video_pll_out 31500000
disp_pixel 31500000
disp_pixel_clk 31500000
Variance = 0 Hz
All other clocks rates and parent were the same.
Similar results on imx8mm were found.
Fixes: 690dccc4a0bf ("Revert "clk: imx: composite-8m: Add support to determine_rate"")
Signed-off-by: Adam Ford <aford173@gmail.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20230506195325.876871-1-aford173@gmail.com
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
2023-05-06 12:53:25 -07:00
|
|
|
.determine_rate = imx8m_divider_determine_rate,
|
2018-12-01 03:52:14 -07:00
|
|
|
};
|
|
|
|
|
clk: imx: add mux ops for i.MX8M composite clk
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface
is exported for programmer easy to configure ccm root. Normal interface
is also exported, but we not use it in our driver, because it will
introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GB
The mux in the upper pic is not the target interface MUX, target
interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7],
you are actually writing SEL_A or SEL_B depends on the internal
counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the
target clock source is active, it means when setting SEL_A, the
current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need
configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter
choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1.
SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. swtich from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2,
however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to
target interface MUX, it will make SEL_A/SEL_B both sources
from clk1, then no need to care about the state of clk0. And
finally system performs well.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-05-06 22:56:16 -07:00
|
|
|
static u8 imx8m_clk_composite_mux_get_parent(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
return clk_mux_ops.get_parent(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx8m_clk_composite_mux_set_parent(struct clk_hw *hw, u8 index)
|
|
|
|
{
|
|
|
|
struct clk_mux *mux = to_clk_mux(hw);
|
|
|
|
u32 val = clk_mux_index_to_val(mux->table, mux->flags, index);
|
|
|
|
unsigned long flags = 0;
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
if (mux->lock)
|
|
|
|
spin_lock_irqsave(mux->lock, flags);
|
|
|
|
|
|
|
|
reg = readl(mux->reg);
|
|
|
|
reg &= ~(mux->mask << mux->shift);
|
|
|
|
val = val << mux->shift;
|
|
|
|
reg |= val;
|
|
|
|
/*
|
|
|
|
* write twice to make sure non-target interface
|
|
|
|
* SEL_A/B point the same clk input.
|
|
|
|
*/
|
|
|
|
writel(reg, mux->reg);
|
|
|
|
writel(reg, mux->reg);
|
|
|
|
|
|
|
|
if (mux->lock)
|
|
|
|
spin_unlock_irqrestore(mux->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
imx8m_clk_composite_mux_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
|
|
|
{
|
|
|
|
return clk_mux_ops.determine_rate(hw, req);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct clk_ops imx8m_clk_composite_mux_ops = {
|
|
|
|
.get_parent = imx8m_clk_composite_mux_get_parent,
|
|
|
|
.set_parent = imx8m_clk_composite_mux_set_parent,
|
|
|
|
.determine_rate = imx8m_clk_composite_mux_determine_rate,
|
|
|
|
};
|
|
|
|
|
2024-06-07 06:33:33 -07:00
|
|
|
static int imx8m_clk_composite_gate_enable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_gate *gate = to_clk_gate(hw);
|
|
|
|
unsigned long flags;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
spin_lock_irqsave(gate->lock, flags);
|
|
|
|
|
|
|
|
val = readl(gate->reg);
|
|
|
|
val |= BIT(gate->bit_idx);
|
|
|
|
writel(val, gate->reg);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(gate->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx8m_clk_composite_gate_disable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
/* composite clk requires the disable hook */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops imx8m_clk_composite_gate_ops = {
|
|
|
|
.enable = imx8m_clk_composite_gate_enable,
|
|
|
|
.disable = imx8m_clk_composite_gate_disable,
|
|
|
|
.is_enabled = clk_gate_is_enabled,
|
|
|
|
};
|
|
|
|
|
2021-09-13 01:24:49 -07:00
|
|
|
struct clk_hw *__imx8m_clk_hw_composite(const char *name,
|
2018-12-14 08:30:09 -07:00
|
|
|
const char * const *parent_names,
|
2018-12-01 03:52:14 -07:00
|
|
|
int num_parents, void __iomem *reg,
|
2020-01-27 22:28:36 -07:00
|
|
|
u32 composite_flags,
|
2018-12-01 03:52:14 -07:00
|
|
|
unsigned long flags)
|
|
|
|
{
|
|
|
|
struct clk_hw *hw = ERR_PTR(-ENOMEM), *mux_hw;
|
2022-02-28 05:41:12 -07:00
|
|
|
struct clk_hw *div_hw, *gate_hw = NULL;
|
2023-12-22 09:11:03 -07:00
|
|
|
struct clk_divider *div;
|
2018-12-01 03:52:14 -07:00
|
|
|
struct clk_gate *gate = NULL;
|
2023-12-22 09:11:03 -07:00
|
|
|
struct clk_mux *mux;
|
2020-01-27 22:28:36 -07:00
|
|
|
const struct clk_ops *divider_ops;
|
clk: imx: add mux ops for i.MX8M composite clk
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface
is exported for programmer easy to configure ccm root. Normal interface
is also exported, but we not use it in our driver, because it will
introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GB
The mux in the upper pic is not the target interface MUX, target
interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7],
you are actually writing SEL_A or SEL_B depends on the internal
counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the
target clock source is active, it means when setting SEL_A, the
current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need
configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter
choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1.
SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. swtich from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2,
however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to
target interface MUX, it will make SEL_A/SEL_B both sources
from clk1, then no need to care about the state of clk0. And
finally system performs well.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-05-06 22:56:16 -07:00
|
|
|
const struct clk_ops *mux_ops;
|
2024-06-07 06:33:33 -07:00
|
|
|
const struct clk_ops *gate_ops;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
mux = kzalloc(sizeof(*mux), GFP_KERNEL);
|
|
|
|
if (!mux)
|
2023-12-22 08:48:24 -07:00
|
|
|
return ERR_CAST(hw);
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
mux_hw = &mux->hw;
|
|
|
|
mux->reg = reg;
|
|
|
|
mux->shift = PCG_PCS_SHIFT;
|
|
|
|
mux->mask = PCG_PCS_MASK;
|
2019-11-01 03:16:19 -07:00
|
|
|
mux->lock = &imx_ccm_lock;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
div = kzalloc(sizeof(*div), GFP_KERNEL);
|
|
|
|
if (!div)
|
2023-12-22 08:48:24 -07:00
|
|
|
goto free_mux;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
div_hw = &div->hw;
|
|
|
|
div->reg = reg;
|
2020-01-27 22:28:36 -07:00
|
|
|
if (composite_flags & IMX_COMPOSITE_CORE) {
|
|
|
|
div->shift = PCG_DIV_SHIFT;
|
|
|
|
div->width = PCG_CORE_DIV_WIDTH;
|
|
|
|
divider_ops = &clk_divider_ops;
|
clk: imx: add mux ops for i.MX8M composite clk
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface
is exported for programmer easy to configure ccm root. Normal interface
is also exported, but we not use it in our driver, because it will
introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GB
The mux in the upper pic is not the target interface MUX, target
interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7],
you are actually writing SEL_A or SEL_B depends on the internal
counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the
target clock source is active, it means when setting SEL_A, the
current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need
configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter
choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1.
SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. swtich from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2,
however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to
target interface MUX, it will make SEL_A/SEL_B both sources
from clk1, then no need to care about the state of clk0. And
finally system performs well.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-05-06 22:56:16 -07:00
|
|
|
mux_ops = &imx8m_clk_composite_mux_ops;
|
2020-05-06 22:56:17 -07:00
|
|
|
} else if (composite_flags & IMX_COMPOSITE_BUS) {
|
|
|
|
div->shift = PCG_PREDIV_SHIFT;
|
|
|
|
div->width = PCG_PREDIV_WIDTH;
|
|
|
|
divider_ops = &imx8m_clk_composite_divider_ops;
|
|
|
|
mux_ops = &imx8m_clk_composite_mux_ops;
|
2020-01-27 22:28:36 -07:00
|
|
|
} else {
|
|
|
|
div->shift = PCG_PREDIV_SHIFT;
|
|
|
|
div->width = PCG_PREDIV_WIDTH;
|
|
|
|
divider_ops = &imx8m_clk_composite_divider_ops;
|
clk: imx: add mux ops for i.MX8M composite clk
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface
is exported for programmer easy to configure ccm root. Normal interface
is also exported, but we not use it in our driver, because it will
introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GB
The mux in the upper pic is not the target interface MUX, target
interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7],
you are actually writing SEL_A or SEL_B depends on the internal
counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the
target clock source is active, it means when setting SEL_A, the
current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need
configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter
choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1.
SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. swtich from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2,
however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to
target interface MUX, it will make SEL_A/SEL_B both sources
from clk1, then no need to care about the state of clk0. And
finally system performs well.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-05-06 22:56:16 -07:00
|
|
|
mux_ops = &clk_mux_ops;
|
2021-08-10 08:14:33 -07:00
|
|
|
if (!(composite_flags & IMX_COMPOSITE_FW_MANAGED))
|
|
|
|
flags |= CLK_SET_PARENT_GATE;
|
2020-01-27 22:28:36 -07:00
|
|
|
}
|
|
|
|
|
2018-12-01 03:52:14 -07:00
|
|
|
div->lock = &imx_ccm_lock;
|
|
|
|
div->flags = CLK_DIVIDER_ROUND_CLOSEST;
|
|
|
|
|
2022-02-28 05:41:12 -07:00
|
|
|
/* skip registering the gate ops if M4 is enabled */
|
2024-06-07 06:33:33 -07:00
|
|
|
gate = kzalloc(sizeof(*gate), GFP_KERNEL);
|
|
|
|
if (!gate)
|
|
|
|
goto free_div;
|
|
|
|
|
|
|
|
gate_hw = &gate->hw;
|
|
|
|
gate->reg = reg;
|
|
|
|
gate->bit_idx = PCG_CGC_SHIFT;
|
|
|
|
gate->lock = &imx_ccm_lock;
|
|
|
|
if (!mcore_booted)
|
|
|
|
gate_ops = &clk_gate_ops;
|
|
|
|
else
|
|
|
|
gate_ops = &imx8m_clk_composite_gate_ops;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
|
|
|
hw = clk_hw_register_composite(NULL, name, parent_names, num_parents,
|
clk: imx: add mux ops for i.MX8M composite clk
The CORE/BUS root slice has following design, simplied graph:
The difference is core not have pre_div block.
A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7].
It support target(smart) interface and normal interface. Target interface
is exported for programmer easy to configure ccm root. Normal interface
is also exported, but we not use it in our driver, because it will
introduce more complexity compared with target interface.
The normal interface simplified as below:
SEL_A GA
+--+ +-+
| +->+ +------+
CLK[0-7]--->+ | +-+ |
| | | +----v---+ +----+
| +--+ |pre_diva+----> | +---------+
| +--------+ |mux +--+post_div |
| +--+ |pre_divb+--->+ | +---------+
| | | +----^---+ +----+
+--->+ | +-+ |
| +->+ +------+
+--+ +-+
SEL_B GB
The mux in the upper pic is not the target interface MUX, target
interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7],
you are actually writing SEL_A or SEL_B depends on the internal
counter which will also control the internal "mux".
The target interface simplified as below which is used by Linux Kernel:
CLK[0-7]--->MUX-->Gate-->pre_div-->post_div
A requirement of the Target Interface's software is that the
target clock source is active, it means when setting SEL_A, the
current input clk to SEL_A must be active, same to SEL_B.
We touch target interface, but hardware logic actually also need
configure normal interface.
There will be system hang, when doing the following steps:
The initial state:
SEL_A/SEL_B are both sourcing from clk0, the internal counter
choose SEL_A.
1. switch mux from clk0 to clk1
The hardware logic will choose SEL_B and configure SEL_B to clk1.
SEL_A no changed.
2. gate off clk0
Disable clk0, then the input to SEL_A is off.
3. swtich from clk1 to clk2
The hardware logic will choose SEL_A and configure SEL_A to clk2,
however the current SEL_A input clk0 is off, the system hang.
The solution to fix the issue is in step 1, write twice to
target interface MUX, it will make SEL_A/SEL_B both sources
from clk1, then no need to care about the state of clk0. And
finally system performs well.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Dong Aisheng <aisheng.dong@nxp.com>
Signed-off-by: Shawn Guo <shawnguo@kernel.org>
2020-05-06 22:56:16 -07:00
|
|
|
mux_hw, mux_ops, div_hw,
|
2024-06-07 06:33:33 -07:00
|
|
|
divider_ops, gate_hw, gate_ops, flags);
|
2018-12-01 03:52:14 -07:00
|
|
|
if (IS_ERR(hw))
|
2023-12-22 08:48:24 -07:00
|
|
|
goto free_gate;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
2019-12-11 19:58:48 -07:00
|
|
|
return hw;
|
2018-12-01 03:52:14 -07:00
|
|
|
|
2023-12-22 08:48:24 -07:00
|
|
|
free_gate:
|
2018-12-01 03:52:14 -07:00
|
|
|
kfree(gate);
|
2023-12-22 08:48:24 -07:00
|
|
|
free_div:
|
2018-12-01 03:52:14 -07:00
|
|
|
kfree(div);
|
2023-12-22 08:48:24 -07:00
|
|
|
free_mux:
|
2018-12-01 03:52:14 -07:00
|
|
|
kfree(mux);
|
|
|
|
return ERR_CAST(hw);
|
|
|
|
}
|
2021-09-13 01:24:49 -07:00
|
|
|
EXPORT_SYMBOL_GPL(__imx8m_clk_hw_composite);
|