Commit ed0df3ce authored by Stephen Boyd's avatar Stephen Boyd

Merge tag 'v4.17-rockchip-clk-1' of...

Merge tag 'v4.17-rockchip-clk-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip into clk-rockchip

Pull Rockchip clk driver updates from Heiko Stuebner:

The rk3328 got the most love this time, preparing it for supplying actual
display output in the future and actually protecting all necessary clocks.
The rk3399 simply got a special 1.6GHz rate that is going to be needed
for a board and the core code got a fix to actually free allocated memory
in error case as well as making sure the clock-phases don't return bad
values and stay the same on rate changes.

* tag 'v4.17-rockchip-clk-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip:
  clk: rockchip: Add 1.6GHz PLL rate for rk3399
  clk: rockchip: Restore the clock phase after the rate was changed
  clk: rockchip: Prevent calculating mmc phase if clock rate is zero
  clk: rockchip: Free the memory on the error path
  clk: rockchip: document hdmi_phy external input for rk3328
  clk: rockchip: add flags for rk3328 dclk_lcdc
  clk: rockchip: remove ignore_unused flag from rk3328 vio_h2p clocks
  clk: rockchip: protect all remaining rk3328 interconnect clocks
  clk: rockchip: export sclk_hdmi_sfc on rk3328
  clk: rockchip: remove HCLK_VIO from rk3328 dt header
  clk: rockchip: fix hclk_vio_niu on rk3328
parents 7928b2cb 4ee3fd4a
...@@ -32,6 +32,7 @@ clock-output-names: ...@@ -32,6 +32,7 @@ clock-output-names:
- "clkin_i2s" - external I2S clock - optional, - "clkin_i2s" - external I2S clock - optional,
- "gmac_clkin" - external GMAC clock - optional - "gmac_clkin" - external GMAC clock - optional
- "phy_50m_out" - output clock of the pll in the mac phy - "phy_50m_out" - output clock of the pll in the mac phy
- "hdmi_phy" - output clock of the hdmi phy pll - optional
Example: Clock controller node: Example: Clock controller node:
......
...@@ -25,6 +25,8 @@ struct rockchip_mmc_clock { ...@@ -25,6 +25,8 @@ struct rockchip_mmc_clock {
void __iomem *reg; void __iomem *reg;
int id; int id;
int shift; int shift;
int cached_phase;
struct notifier_block clk_rate_change_nb;
}; };
#define to_mmc_clock(_hw) container_of(_hw, struct rockchip_mmc_clock, hw) #define to_mmc_clock(_hw) container_of(_hw, struct rockchip_mmc_clock, hw)
...@@ -58,6 +60,12 @@ static int rockchip_mmc_get_phase(struct clk_hw *hw) ...@@ -58,6 +60,12 @@ static int rockchip_mmc_get_phase(struct clk_hw *hw)
u16 degrees; u16 degrees;
u32 delay_num = 0; u32 delay_num = 0;
/* See the comment for rockchip_mmc_set_phase below */
if (!rate) {
pr_err("%s: invalid clk rate\n", __func__);
return -EINVAL;
}
raw_value = readl(mmc_clock->reg) >> (mmc_clock->shift); raw_value = readl(mmc_clock->reg) >> (mmc_clock->shift);
degrees = (raw_value & ROCKCHIP_MMC_DEGREE_MASK) * 90; degrees = (raw_value & ROCKCHIP_MMC_DEGREE_MASK) * 90;
...@@ -84,6 +92,23 @@ static int rockchip_mmc_set_phase(struct clk_hw *hw, int degrees) ...@@ -84,6 +92,23 @@ static int rockchip_mmc_set_phase(struct clk_hw *hw, int degrees)
u32 raw_value; u32 raw_value;
u32 delay; u32 delay;
/*
* The below calculation is based on the output clock from
* MMC host to the card, which expects the phase clock inherits
* the clock rate from its parent, namely the output clock
* provider of MMC host. However, things may go wrong if
* (1) It is orphan.
* (2) It is assigned to the wrong parent.
*
* This check help debug the case (1), which seems to be the
* most likely problem we often face and which makes it difficult
* for people to debug unstable mmc tuning results.
*/
if (!rate) {
pr_err("%s: invalid clk rate\n", __func__);
return -EINVAL;
}
nineties = degrees / 90; nineties = degrees / 90;
remainder = (degrees % 90); remainder = (degrees % 90);
...@@ -139,6 +164,29 @@ static const struct clk_ops rockchip_mmc_clk_ops = { ...@@ -139,6 +164,29 @@ static const struct clk_ops rockchip_mmc_clk_ops = {
.set_phase = rockchip_mmc_set_phase, .set_phase = rockchip_mmc_set_phase,
}; };
#define to_rockchip_mmc_clock(x) \
container_of(x, struct rockchip_mmc_clock, clk_rate_change_nb)
static int rockchip_mmc_clk_rate_notify(struct notifier_block *nb,
unsigned long event, void *data)
{
struct rockchip_mmc_clock *mmc_clock = to_rockchip_mmc_clock(nb);
/*
* rockchip_mmc_clk is mostly used by mmc controllers to sample
* the intput data, which expects the fixed phase after the tuning
* process. However if the clock rate is changed, the phase is stale
* and may break the data sampling. So here we try to restore the phase
* for that case.
*/
if (event == PRE_RATE_CHANGE)
mmc_clock->cached_phase =
rockchip_mmc_get_phase(&mmc_clock->hw);
else if (event == POST_RATE_CHANGE)
rockchip_mmc_set_phase(&mmc_clock->hw, mmc_clock->cached_phase);
return NOTIFY_DONE;
}
struct clk *rockchip_clk_register_mmc(const char *name, struct clk *rockchip_clk_register_mmc(const char *name,
const char *const *parent_names, u8 num_parents, const char *const *parent_names, u8 num_parents,
void __iomem *reg, int shift) void __iomem *reg, int shift)
...@@ -146,6 +194,7 @@ struct clk *rockchip_clk_register_mmc(const char *name, ...@@ -146,6 +194,7 @@ struct clk *rockchip_clk_register_mmc(const char *name,
struct clk_init_data init; struct clk_init_data init;
struct rockchip_mmc_clock *mmc_clock; struct rockchip_mmc_clock *mmc_clock;
struct clk *clk; struct clk *clk;
int ret;
mmc_clock = kmalloc(sizeof(*mmc_clock), GFP_KERNEL); mmc_clock = kmalloc(sizeof(*mmc_clock), GFP_KERNEL);
if (!mmc_clock) if (!mmc_clock)
...@@ -163,7 +212,18 @@ struct clk *rockchip_clk_register_mmc(const char *name, ...@@ -163,7 +212,18 @@ struct clk *rockchip_clk_register_mmc(const char *name,
clk = clk_register(NULL, &mmc_clock->hw); clk = clk_register(NULL, &mmc_clock->hw);
if (IS_ERR(clk)) if (IS_ERR(clk))
kfree(mmc_clock); goto err_register;
mmc_clock->clk_rate_change_nb.notifier_call =
&rockchip_mmc_clk_rate_notify;
ret = clk_notifier_register(clk, &mmc_clock->clk_rate_change_nb);
if (ret)
goto err_notifier;
return clk;
err_notifier:
clk_unregister(clk);
err_register:
kfree(mmc_clock);
return clk; return clk;
} }
This diff is collapsed.
...@@ -57,6 +57,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = { ...@@ -57,6 +57,7 @@ static struct rockchip_pll_rate_table rk3399_pll_rates[] = {
RK3036_PLL_RATE(1656000000, 1, 69, 1, 1, 1, 0), RK3036_PLL_RATE(1656000000, 1, 69, 1, 1, 1, 0),
RK3036_PLL_RATE(1632000000, 1, 68, 1, 1, 1, 0), RK3036_PLL_RATE(1632000000, 1, 68, 1, 1, 1, 0),
RK3036_PLL_RATE(1608000000, 1, 67, 1, 1, 1, 0), RK3036_PLL_RATE(1608000000, 1, 67, 1, 1, 1, 0),
RK3036_PLL_RATE(1600000000, 3, 200, 1, 1, 1, 0),
RK3036_PLL_RATE(1584000000, 1, 66, 1, 1, 1, 0), RK3036_PLL_RATE(1584000000, 1, 66, 1, 1, 1, 0),
RK3036_PLL_RATE(1560000000, 1, 65, 1, 1, 1, 0), RK3036_PLL_RATE(1560000000, 1, 65, 1, 1, 1, 0),
RK3036_PLL_RATE(1536000000, 1, 64, 1, 1, 1, 0), RK3036_PLL_RATE(1536000000, 1, 64, 1, 1, 1, 0),
......
...@@ -57,6 +57,7 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -57,6 +57,7 @@ static struct clk *rockchip_clk_register_branch(const char *name,
struct clk_divider *div = NULL; struct clk_divider *div = NULL;
const struct clk_ops *mux_ops = NULL, *div_ops = NULL, const struct clk_ops *mux_ops = NULL, *div_ops = NULL,
*gate_ops = NULL; *gate_ops = NULL;
int ret;
if (num_parents > 1) { if (num_parents > 1) {
mux = kzalloc(sizeof(*mux), GFP_KERNEL); mux = kzalloc(sizeof(*mux), GFP_KERNEL);
...@@ -74,8 +75,10 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -74,8 +75,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (gate_offset >= 0) { if (gate_offset >= 0) {
gate = kzalloc(sizeof(*gate), GFP_KERNEL); gate = kzalloc(sizeof(*gate), GFP_KERNEL);
if (!gate) if (!gate) {
ret = -ENOMEM;
goto err_gate; goto err_gate;
}
gate->flags = gate_flags; gate->flags = gate_flags;
gate->reg = base + gate_offset; gate->reg = base + gate_offset;
...@@ -86,8 +89,10 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -86,8 +89,10 @@ static struct clk *rockchip_clk_register_branch(const char *name,
if (div_width > 0) { if (div_width > 0) {
div = kzalloc(sizeof(*div), GFP_KERNEL); div = kzalloc(sizeof(*div), GFP_KERNEL);
if (!div) if (!div) {
ret = -ENOMEM;
goto err_div; goto err_div;
}
div->flags = div_flags; div->flags = div_flags;
div->reg = base + muxdiv_offset; div->reg = base + muxdiv_offset;
...@@ -106,12 +111,19 @@ static struct clk *rockchip_clk_register_branch(const char *name, ...@@ -106,12 +111,19 @@ static struct clk *rockchip_clk_register_branch(const char *name,
gate ? &gate->hw : NULL, gate_ops, gate ? &gate->hw : NULL, gate_ops,
flags); flags);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
goto err_composite;
}
return clk; return clk;
err_composite:
kfree(div);
err_div: err_div:
kfree(gate); kfree(gate);
err_gate: err_gate:
kfree(mux); kfree(mux);
return ERR_PTR(-ENOMEM); return ERR_PTR(ret);
} }
struct rockchip_clk_frac { struct rockchip_clk_frac {
...@@ -291,8 +303,10 @@ static struct clk *rockchip_clk_register_frac_branch( ...@@ -291,8 +303,10 @@ static struct clk *rockchip_clk_register_frac_branch(
init.num_parents = child->num_parents; init.num_parents = child->num_parents;
mux_clk = clk_register(NULL, &frac_mux->hw); mux_clk = clk_register(NULL, &frac_mux->hw);
if (IS_ERR(mux_clk)) if (IS_ERR(mux_clk)) {
kfree(frac);
return clk; return clk;
}
rockchip_clk_add_lookup(ctx, mux_clk, child->id); rockchip_clk_add_lookup(ctx, mux_clk, child->id);
......
...@@ -193,7 +193,6 @@ ...@@ -193,7 +193,6 @@
#define HCLK_VPU_PRE 324 #define HCLK_VPU_PRE 324
#define HCLK_VIO_PRE 325 #define HCLK_VIO_PRE 325
#define HCLK_VPU 326 #define HCLK_VPU 326
#define HCLK_VIO 327
#define HCLK_BUS_PRE 328 #define HCLK_BUS_PRE 328
#define HCLK_PERI_PRE 329 #define HCLK_PERI_PRE 329
#define HCLK_H264 330 #define HCLK_H264 330
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment