Commit ffbf9cf3 authored by Yoshihiro Shimoda's avatar Yoshihiro Shimoda Committed by Geert Uytterhoeven

clk: renesas: cpg-mssr: Use enum clk_reg_layout instead of a boolean flag

Geert suggested defining multiple register layout variants using an enum
[1] to support further devices like R-Car V3U.  So, use enum
clk_reg_layout instead of a boolean .stbyctrl flag.  No behavioral
change.

[1] https://lore.kernel.org/linux-renesas-soc/CAMuHMdVAgN69p9FFnQdO4iHk2CHkeNaVui2Q-FOY6_BFVjQ-Nw@mail.gmail.com/Signed-off-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/1599810232-29035-2-git-send-email-yoshihiro.shimoda.uh@renesas.comSigned-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
parent a69f802e
...@@ -214,7 +214,7 @@ const struct cpg_mssr_info r7s9210_cpg_mssr_info __initconst = { ...@@ -214,7 +214,7 @@ const struct cpg_mssr_info r7s9210_cpg_mssr_info __initconst = {
.cpg_clk_register = rza2_cpg_clk_register, .cpg_clk_register = rza2_cpg_clk_register,
/* RZ/A2 has Standby Control Registers */ /* RZ/A2 has Standby Control Registers */
.stbyctrl = true, .reg_layout = CLK_REG_LAYOUT_RZ_A,
}; };
static void __init r7s9210_cpg_mssr_early_init(struct device_node *np) static void __init r7s9210_cpg_mssr_early_init(struct device_node *np)
......
...@@ -111,12 +111,12 @@ static const u16 srcr[] = { ...@@ -111,12 +111,12 @@ static const u16 srcr[] = {
* @rcdev: Optional reset controller entity * @rcdev: Optional reset controller entity
* @dev: CPG/MSSR device * @dev: CPG/MSSR device
* @base: CPG/MSSR register block base address * @base: CPG/MSSR register block base address
* @reg_layout: CPG/MSSR register layout
* @rmw_lock: protects RMW register accesses * @rmw_lock: protects RMW register accesses
* @np: Device node in DT for this CPG/MSSR module * @np: Device node in DT for this CPG/MSSR module
* @num_core_clks: Number of Core Clocks in clks[] * @num_core_clks: Number of Core Clocks in clks[]
* @num_mod_clks: Number of Module Clocks in clks[] * @num_mod_clks: Number of Module Clocks in clks[]
* @last_dt_core_clk: ID of the last Core Clock exported to DT * @last_dt_core_clk: ID of the last Core Clock exported to DT
* @stbyctrl: This device has Standby Control Registers
* @notifiers: Notifier chain to save/restore clock state for system resume * @notifiers: Notifier chain to save/restore clock state for system resume
* @smstpcr_saved[].mask: Mask of SMSTPCR[] bits under our control * @smstpcr_saved[].mask: Mask of SMSTPCR[] bits under our control
* @smstpcr_saved[].val: Saved values of SMSTPCR[] * @smstpcr_saved[].val: Saved values of SMSTPCR[]
...@@ -128,13 +128,13 @@ struct cpg_mssr_priv { ...@@ -128,13 +128,13 @@ struct cpg_mssr_priv {
#endif #endif
struct device *dev; struct device *dev;
void __iomem *base; void __iomem *base;
enum clk_reg_layout reg_layout;
spinlock_t rmw_lock; spinlock_t rmw_lock;
struct device_node *np; struct device_node *np;
unsigned int num_core_clks; unsigned int num_core_clks;
unsigned int num_mod_clks; unsigned int num_mod_clks;
unsigned int last_dt_core_clk; unsigned int last_dt_core_clk;
bool stbyctrl;
struct raw_notifier_head notifiers; struct raw_notifier_head notifiers;
struct { struct {
...@@ -177,7 +177,7 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) ...@@ -177,7 +177,7 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
enable ? "ON" : "OFF"); enable ? "ON" : "OFF");
spin_lock_irqsave(&priv->rmw_lock, flags); spin_lock_irqsave(&priv->rmw_lock, flags);
if (priv->stbyctrl) { if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
value = readb(priv->base + STBCR(reg)); value = readb(priv->base + STBCR(reg));
if (enable) if (enable)
value &= ~bitmask; value &= ~bitmask;
...@@ -199,7 +199,7 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable) ...@@ -199,7 +199,7 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
spin_unlock_irqrestore(&priv->rmw_lock, flags); spin_unlock_irqrestore(&priv->rmw_lock, flags);
if (!enable || priv->stbyctrl) if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
return 0; return 0;
for (i = 1000; i > 0; --i) { for (i = 1000; i > 0; --i) {
...@@ -233,7 +233,7 @@ static int cpg_mstp_clock_is_enabled(struct clk_hw *hw) ...@@ -233,7 +233,7 @@ static int cpg_mstp_clock_is_enabled(struct clk_hw *hw)
struct cpg_mssr_priv *priv = clock->priv; struct cpg_mssr_priv *priv = clock->priv;
u32 value; u32 value;
if (priv->stbyctrl) if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
value = readb(priv->base + STBCR(clock->index / 32)); value = readb(priv->base + STBCR(clock->index / 32));
else else
value = readl(priv->base + MSTPSR(clock->index / 32)); value = readl(priv->base + MSTPSR(clock->index / 32));
...@@ -272,7 +272,7 @@ struct clk *cpg_mssr_clk_src_twocell_get(struct of_phandle_args *clkspec, ...@@ -272,7 +272,7 @@ struct clk *cpg_mssr_clk_src_twocell_get(struct of_phandle_args *clkspec,
case CPG_MOD: case CPG_MOD:
type = "module"; type = "module";
if (priv->stbyctrl) { if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
idx = MOD_CLK_PACK_10(clkidx); idx = MOD_CLK_PACK_10(clkidx);
range_check = 7 - (clkidx % 10); range_check = 7 - (clkidx % 10);
} else { } else {
...@@ -825,7 +825,8 @@ static int cpg_mssr_suspend_noirq(struct device *dev) ...@@ -825,7 +825,8 @@ static int cpg_mssr_suspend_noirq(struct device *dev)
/* Save module registers with bits under our control */ /* Save module registers with bits under our control */
for (reg = 0; reg < ARRAY_SIZE(priv->smstpcr_saved); reg++) { for (reg = 0; reg < ARRAY_SIZE(priv->smstpcr_saved); reg++) {
if (priv->smstpcr_saved[reg].mask) if (priv->smstpcr_saved[reg].mask)
priv->smstpcr_saved[reg].val = priv->stbyctrl ? priv->smstpcr_saved[reg].val =
priv->reg_layout == CLK_REG_LAYOUT_RZ_A ?
readb(priv->base + STBCR(reg)) : readb(priv->base + STBCR(reg)) :
readl(priv->base + SMSTPCR(reg)); readl(priv->base + SMSTPCR(reg));
} }
...@@ -855,7 +856,7 @@ static int cpg_mssr_resume_noirq(struct device *dev) ...@@ -855,7 +856,7 @@ static int cpg_mssr_resume_noirq(struct device *dev)
if (!mask) if (!mask)
continue; continue;
if (priv->stbyctrl) if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
oldval = readb(priv->base + STBCR(reg)); oldval = readb(priv->base + STBCR(reg));
else else
oldval = readl(priv->base + SMSTPCR(reg)); oldval = readl(priv->base + SMSTPCR(reg));
...@@ -864,7 +865,7 @@ static int cpg_mssr_resume_noirq(struct device *dev) ...@@ -864,7 +865,7 @@ static int cpg_mssr_resume_noirq(struct device *dev)
if (newval == oldval) if (newval == oldval)
continue; continue;
if (priv->stbyctrl) { if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
writeb(newval, priv->base + STBCR(reg)); writeb(newval, priv->base + STBCR(reg));
/* dummy read to ensure write has completed */ /* dummy read to ensure write has completed */
readb(priv->base + STBCR(reg)); readb(priv->base + STBCR(reg));
...@@ -887,8 +888,8 @@ static int cpg_mssr_resume_noirq(struct device *dev) ...@@ -887,8 +888,8 @@ static int cpg_mssr_resume_noirq(struct device *dev)
if (!i) if (!i)
dev_warn(dev, "Failed to enable %s%u[0x%x]\n", dev_warn(dev, "Failed to enable %s%u[0x%x]\n",
priv->stbyctrl ? "STB" : "SMSTP", reg, priv->reg_layout == CLK_REG_LAYOUT_RZ_A ?
oldval & mask); "STB" : "SMSTP", reg, oldval & mask);
} }
return 0; return 0;
...@@ -937,7 +938,7 @@ static int __init cpg_mssr_common_init(struct device *dev, ...@@ -937,7 +938,7 @@ static int __init cpg_mssr_common_init(struct device *dev,
priv->num_mod_clks = info->num_hw_mod_clks; priv->num_mod_clks = info->num_hw_mod_clks;
priv->last_dt_core_clk = info->last_dt_core_clk; priv->last_dt_core_clk = info->last_dt_core_clk;
RAW_INIT_NOTIFIER_HEAD(&priv->notifiers); RAW_INIT_NOTIFIER_HEAD(&priv->notifiers);
priv->stbyctrl = info->stbyctrl; priv->reg_layout = info->reg_layout;
for (i = 0; i < nclks; i++) for (i = 0; i < nclks; i++)
priv->clks[i] = ERR_PTR(-ENOENT); priv->clks[i] = ERR_PTR(-ENOENT);
...@@ -1015,7 +1016,7 @@ static int __init cpg_mssr_probe(struct platform_device *pdev) ...@@ -1015,7 +1016,7 @@ static int __init cpg_mssr_probe(struct platform_device *pdev)
return error; return error;
/* Reset Controller not supported for Standby Control SoCs */ /* Reset Controller not supported for Standby Control SoCs */
if (info->stbyctrl) if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
return 0; return 0;
error = cpg_mssr_reset_controller_register(priv); error = cpg_mssr_reset_controller_register(priv);
......
...@@ -85,6 +85,11 @@ struct mssr_mod_clk { ...@@ -85,6 +85,11 @@ struct mssr_mod_clk {
struct device_node; struct device_node;
enum clk_reg_layout {
CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3 = 0,
CLK_REG_LAYOUT_RZ_A,
};
/** /**
* SoC-specific CPG/MSSR Description * SoC-specific CPG/MSSR Description
* *
...@@ -105,6 +110,7 @@ struct device_node; ...@@ -105,6 +110,7 @@ struct device_node;
* @crit_mod_clks: Array with Module Clock IDs of critical clocks that * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
* should not be disabled without a knowledgeable driver * should not be disabled without a knowledgeable driver
* @num_crit_mod_clks: Number of entries in crit_mod_clks[] * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
* @reg_layout: CPG/MSSR register layout from enum clk_reg_layout
* *
* @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power * @core_pm_clks: Array with IDs of Core Clocks that are suitable for Power
* Management, in addition to Module Clocks * Management, in addition to Module Clocks
...@@ -112,10 +118,6 @@ struct device_node; ...@@ -112,10 +118,6 @@ struct device_node;
* *
* @init: Optional callback to perform SoC-specific initialization * @init: Optional callback to perform SoC-specific initialization
* @cpg_clk_register: Optional callback to handle special Core Clock types * @cpg_clk_register: Optional callback to handle special Core Clock types
*
* @stbyctrl: This device has Standby Control Registers which are 8-bits
* wide, no status registers (MSTPSR) and have different address
* offsets.
*/ */
struct cpg_mssr_info { struct cpg_mssr_info {
...@@ -130,7 +132,7 @@ struct cpg_mssr_info { ...@@ -130,7 +132,7 @@ struct cpg_mssr_info {
unsigned int num_core_clks; unsigned int num_core_clks;
unsigned int last_dt_core_clk; unsigned int last_dt_core_clk;
unsigned int num_total_core_clks; unsigned int num_total_core_clks;
bool stbyctrl; enum clk_reg_layout reg_layout;
/* Module Clocks */ /* Module Clocks */
const struct mssr_mod_clk *mod_clks; const struct mssr_mod_clk *mod_clks;
......
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