Commit 2b2f7def authored by Tony Lindgren's avatar Tony Lindgren

bus: ti-sysc: Add support for missing clockdomain handling

We need to let ti-sysc driver manage clockdomain autoidle for the
duration of of reset, enable and idle. And we need to do it before we
enable the clock and after we disable it. Currently we are still
relying on platform callbacks indirectly managing clockdomain autoidle.
But I noticed that for device tree only probed drivers it now happens
only after we enabling the clocks and before we disable the clocks,
while it should be the other way around. So far I have not noticed
any issues with this though.

Let's add new ti_sysc_clkdm_deny_idle() and ti_sysc_clkdm_allow_idle()
functions for ti-sysc driver to use to manage clockdomains directly via
platform data callbacks. Note that we can implement the clockdomain
functions in pdata-quirks.c as for probing devices without "ti,hwmods"
custom property we don't need to use the other platform data callbacks.

Let's do this in one patch as there's is still an unlikely chance we
may need to apply this as a fix for v5.2 for dropping legacy platform
data for some devices. We also do have the option of adding back the
platform data if needed in case of trouble.
Tested-by: default avatarKeerthy <j-keerthy@ti.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
parent 4ee23cd7
...@@ -3445,6 +3445,7 @@ static int omap_hwmod_check_module(struct device *dev, ...@@ -3445,6 +3445,7 @@ static int omap_hwmod_check_module(struct device *dev,
* @dev: struct device * @dev: struct device
* @oh: module * @oh: module
* @sysc_fields: sysc register bits * @sysc_fields: sysc register bits
* @clockdomain: clockdomain
* @rev_offs: revision register offset * @rev_offs: revision register offset
* @sysc_offs: sysconfig register offset * @sysc_offs: sysconfig register offset
* @syss_offs: sysstatus register offset * @syss_offs: sysstatus register offset
...@@ -3456,6 +3457,7 @@ static int omap_hwmod_check_module(struct device *dev, ...@@ -3456,6 +3457,7 @@ static int omap_hwmod_check_module(struct device *dev,
static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh,
const struct ti_sysc_module_data *data, const struct ti_sysc_module_data *data,
struct sysc_regbits *sysc_fields, struct sysc_regbits *sysc_fields,
struct clockdomain *clkdm,
s32 rev_offs, s32 sysc_offs, s32 rev_offs, s32 sysc_offs,
s32 syss_offs, u32 sysc_flags, s32 syss_offs, u32 sysc_flags,
u32 idlemodes) u32 idlemodes)
...@@ -3463,8 +3465,6 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, ...@@ -3463,8 +3465,6 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh,
struct omap_hwmod_class_sysconfig *sysc; struct omap_hwmod_class_sysconfig *sysc;
struct omap_hwmod_class *class = NULL; struct omap_hwmod_class *class = NULL;
struct omap_hwmod_ocp_if *oi = NULL; struct omap_hwmod_ocp_if *oi = NULL;
struct clockdomain *clkdm = NULL;
struct clk *clk = NULL;
void __iomem *regs = NULL; void __iomem *regs = NULL;
unsigned long flags; unsigned long flags;
...@@ -3511,36 +3511,6 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, ...@@ -3511,36 +3511,6 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh,
oi->user = OCP_USER_MPU | OCP_USER_SDMA; oi->user = OCP_USER_MPU | OCP_USER_SDMA;
} }
if (!oh->_clk) {
struct clk_hw_omap *hwclk;
clk = of_clk_get_by_name(dev->of_node, "fck");
if (!IS_ERR(clk))
clk_prepare(clk);
else
clk = NULL;
/*
* Populate clockdomain based on dts clock. It is needed for
* clkdm_deny_idle() and clkdm_allow_idle() until we have have
* interconnect driver and reset driver capable of blocking
* clockdomain idle during reset, enable and idle.
*/
if (clk) {
hwclk = to_clk_hw_omap(__clk_get_hw(clk));
if (hwclk && hwclk->clkdm_name)
clkdm = clkdm_lookup(hwclk->clkdm_name);
}
/*
* Note that we assume interconnect driver manages the clocks
* and do not need to populate oh->_clk for dynamically
* allocated modules.
*/
clk_unprepare(clk);
clk_put(clk);
}
spin_lock_irqsave(&oh->_lock, flags); spin_lock_irqsave(&oh->_lock, flags);
if (regs) if (regs)
oh->_mpu_rt_va = regs; oh->_mpu_rt_va = regs;
...@@ -3626,7 +3596,7 @@ int omap_hwmod_init_module(struct device *dev, ...@@ -3626,7 +3596,7 @@ int omap_hwmod_init_module(struct device *dev,
u32 sysc_flags, idlemodes; u32 sysc_flags, idlemodes;
int error; int error;
if (!dev || !data) if (!dev || !data || !data->name || !cookie)
return -EINVAL; return -EINVAL;
oh = _lookup(data->name); oh = _lookup(data->name);
...@@ -3697,7 +3667,8 @@ int omap_hwmod_init_module(struct device *dev, ...@@ -3697,7 +3667,8 @@ int omap_hwmod_init_module(struct device *dev,
return error; return error;
return omap_hwmod_allocate_module(dev, oh, data, sysc_fields, return omap_hwmod_allocate_module(dev, oh, data, sysc_fields,
rev_offs, sysc_offs, syss_offs, cookie->clkdm, rev_offs,
sysc_offs, syss_offs,
sysc_flags, idlemodes); sysc_flags, idlemodes);
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/platform_data/wkup_m3.h> #include <linux/platform_data/wkup_m3.h>
#include <linux/platform_data/asoc-ti-mcbsp.h> #include <linux/platform_data/asoc-ti-mcbsp.h>
#include "clockdomain.h"
#include "common.h" #include "common.h"
#include "common-board-devices.h" #include "common-board-devices.h"
#include "control.h" #include "control.h"
...@@ -463,6 +464,62 @@ static void __init dra7x_evm_mmc_quirk(void) ...@@ -463,6 +464,62 @@ static void __init dra7x_evm_mmc_quirk(void)
} }
#endif #endif
static struct clockdomain *ti_sysc_find_one_clockdomain(struct clk *clk)
{
struct clockdomain *clkdm = NULL;
struct clk_hw_omap *hwclk;
hwclk = to_clk_hw_omap(__clk_get_hw(clk));
if (hwclk && hwclk->clkdm_name)
clkdm = clkdm_lookup(hwclk->clkdm_name);
return clkdm;
}
/**
* ti_sysc_clkdm_init - find clockdomain based on clock
* @fck: device functional clock
* @ick: device interface clock
* @dev: struct device
*
* Populate clockdomain based on clock. It is needed for
* clkdm_deny_idle() and clkdm_allow_idle() for blocking clockdomain
* clockdomain idle during reset, enable and idle.
*
* Note that we assume interconnect driver manages the clocks
* and do not need to populate oh->_clk for dynamically
* allocated modules.
*/
static int ti_sysc_clkdm_init(struct device *dev,
struct clk *fck, struct clk *ick,
struct ti_sysc_cookie *cookie)
{
if (fck)
cookie->clkdm = ti_sysc_find_one_clockdomain(fck);
if (cookie->clkdm)
return 0;
if (ick)
cookie->clkdm = ti_sysc_find_one_clockdomain(ick);
if (cookie->clkdm)
return 0;
return -ENODEV;
}
static void ti_sysc_clkdm_deny_idle(struct device *dev,
const struct ti_sysc_cookie *cookie)
{
if (cookie->clkdm)
clkdm_deny_idle(cookie->clkdm);
}
static void ti_sysc_clkdm_allow_idle(struct device *dev,
const struct ti_sysc_cookie *cookie)
{
if (cookie->clkdm)
clkdm_allow_idle(cookie->clkdm);
}
static int ti_sysc_enable_module(struct device *dev, static int ti_sysc_enable_module(struct device *dev,
const struct ti_sysc_cookie *cookie) const struct ti_sysc_cookie *cookie)
{ {
...@@ -494,6 +551,9 @@ static struct of_dev_auxdata omap_auxdata_lookup[]; ...@@ -494,6 +551,9 @@ static struct of_dev_auxdata omap_auxdata_lookup[];
static struct ti_sysc_platform_data ti_sysc_pdata = { static struct ti_sysc_platform_data ti_sysc_pdata = {
.auxdata = omap_auxdata_lookup, .auxdata = omap_auxdata_lookup,
.init_clockdomain = ti_sysc_clkdm_init,
.clkdm_deny_idle = ti_sysc_clkdm_deny_idle,
.clkdm_allow_idle = ti_sysc_clkdm_allow_idle,
.init_module = omap_hwmod_init_module, .init_module = omap_hwmod_init_module,
.enable_module = ti_sysc_enable_module, .enable_module = ti_sysc_enable_module,
.idle_module = ti_sysc_idle_module, .idle_module = ti_sysc_idle_module,
......
...@@ -422,6 +422,30 @@ static void sysc_disable_opt_clocks(struct sysc *ddata) ...@@ -422,6 +422,30 @@ static void sysc_disable_opt_clocks(struct sysc *ddata)
} }
} }
static void sysc_clkdm_deny_idle(struct sysc *ddata)
{
struct ti_sysc_platform_data *pdata;
if (ddata->legacy_mode)
return;
pdata = dev_get_platdata(ddata->dev);
if (pdata && pdata->clkdm_deny_idle)
pdata->clkdm_deny_idle(ddata->dev, &ddata->cookie);
}
static void sysc_clkdm_allow_idle(struct sysc *ddata)
{
struct ti_sysc_platform_data *pdata;
if (ddata->legacy_mode)
return;
pdata = dev_get_platdata(ddata->dev);
if (pdata && pdata->clkdm_allow_idle)
pdata->clkdm_allow_idle(ddata->dev, &ddata->cookie);
}
/** /**
* sysc_init_resets - init rstctrl reset line if configured * sysc_init_resets - init rstctrl reset line if configured
* @ddata: device driver data * @ddata: device driver data
...@@ -795,6 +819,7 @@ static void sysc_show_registers(struct sysc *ddata) ...@@ -795,6 +819,7 @@ static void sysc_show_registers(struct sysc *ddata)
#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1) #define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1)
/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
static int sysc_enable_module(struct device *dev) static int sysc_enable_module(struct device *dev)
{ {
struct sysc *ddata; struct sysc *ddata;
...@@ -805,11 +830,6 @@ static int sysc_enable_module(struct device *dev) ...@@ -805,11 +830,6 @@ static int sysc_enable_module(struct device *dev)
if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
return 0; return 0;
/*
* TODO: Need to prevent clockdomain autoidle?
* See clkdm_deny_idle() in arch/mach-omap2/omap_hwmod.c
*/
regbits = ddata->cap->regbits; regbits = ddata->cap->regbits;
reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
...@@ -861,6 +881,7 @@ static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode) ...@@ -861,6 +881,7 @@ static int sysc_best_idle_mode(u32 idlemodes, u32 *best_mode)
return 0; return 0;
} }
/* Caller needs to manage sysc_clkdm_deny_idle() and sysc_clkdm_allow_idle() */
static int sysc_disable_module(struct device *dev) static int sysc_disable_module(struct device *dev)
{ {
struct sysc *ddata; struct sysc *ddata;
...@@ -872,11 +893,6 @@ static int sysc_disable_module(struct device *dev) ...@@ -872,11 +893,6 @@ static int sysc_disable_module(struct device *dev)
if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV)
return 0; return 0;
/*
* TODO: Need to prevent clockdomain autoidle?
* See clkdm_deny_idle() in arch/mach-omap2/omap_hwmod.c
*/
regbits = ddata->cap->regbits; regbits = ddata->cap->regbits;
reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]);
...@@ -966,14 +982,16 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev) ...@@ -966,14 +982,16 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev)
if (!ddata->enabled) if (!ddata->enabled)
return 0; return 0;
sysc_clkdm_deny_idle(ddata);
if (ddata->legacy_mode) { if (ddata->legacy_mode) {
error = sysc_runtime_suspend_legacy(dev, ddata); error = sysc_runtime_suspend_legacy(dev, ddata);
if (error) if (error)
return error; goto err_allow_idle;
} else { } else {
error = sysc_disable_module(dev); error = sysc_disable_module(dev);
if (error) if (error)
return error; goto err_allow_idle;
} }
sysc_disable_main_clocks(ddata); sysc_disable_main_clocks(ddata);
...@@ -983,6 +1001,9 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev) ...@@ -983,6 +1001,9 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev)
ddata->enabled = false; ddata->enabled = false;
err_allow_idle:
sysc_clkdm_allow_idle(ddata);
return error; return error;
} }
...@@ -996,10 +1017,12 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev) ...@@ -996,10 +1017,12 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev)
if (ddata->enabled) if (ddata->enabled)
return 0; return 0;
sysc_clkdm_deny_idle(ddata);
if (sysc_opt_clks_needed(ddata)) { if (sysc_opt_clks_needed(ddata)) {
error = sysc_enable_opt_clocks(ddata); error = sysc_enable_opt_clocks(ddata);
if (error) if (error)
return error; goto err_allow_idle;
} }
error = sysc_enable_main_clocks(ddata); error = sysc_enable_main_clocks(ddata);
...@@ -1018,6 +1041,8 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev) ...@@ -1018,6 +1041,8 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev)
ddata->enabled = true; ddata->enabled = true;
sysc_clkdm_allow_idle(ddata);
return 0; return 0;
err_main_clocks: err_main_clocks:
...@@ -1025,6 +1050,8 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev) ...@@ -1025,6 +1050,8 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev)
err_opt_clocks: err_opt_clocks:
if (sysc_opt_clks_needed(ddata)) if (sysc_opt_clks_needed(ddata))
sysc_disable_opt_clocks(ddata); sysc_disable_opt_clocks(ddata);
err_allow_idle:
sysc_clkdm_allow_idle(ddata);
return error; return error;
} }
...@@ -1245,6 +1272,33 @@ static void sysc_init_revision_quirks(struct sysc *ddata) ...@@ -1245,6 +1272,33 @@ static void sysc_init_revision_quirks(struct sysc *ddata)
} }
} }
static int sysc_clockdomain_init(struct sysc *ddata)
{
struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
struct clk *fck = NULL, *ick = NULL;
int error;
if (!pdata || !pdata->init_clockdomain)
return 0;
switch (ddata->nr_clocks) {
case 2:
ick = ddata->clocks[SYSC_ICK];
/* fallthrough */
case 1:
fck = ddata->clocks[SYSC_FCK];
break;
case 0:
return 0;
}
error = pdata->init_clockdomain(ddata->dev, fck, ick, &ddata->cookie);
if (!error || error == -ENODEV)
return 0;
return error;
}
/* /*
* Note that pdata->init_module() typically does a reset first. After * Note that pdata->init_module() typically does a reset first. After
* pdata->init_module() is done, PM runtime can be used for the interconnect * pdata->init_module() is done, PM runtime can be used for the interconnect
...@@ -1255,7 +1309,7 @@ static int sysc_legacy_init(struct sysc *ddata) ...@@ -1255,7 +1309,7 @@ static int sysc_legacy_init(struct sysc *ddata)
struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
int error; int error;
if (!ddata->legacy_mode || !pdata || !pdata->init_module) if (!pdata || !pdata->init_module)
return 0; return 0;
error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie); error = pdata->init_module(ddata->dev, ddata->mdata, &ddata->cookie);
...@@ -1347,7 +1401,13 @@ static int sysc_init_module(struct sysc *ddata) ...@@ -1347,7 +1401,13 @@ static int sysc_init_module(struct sysc *ddata)
(SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT)) (SYSC_QUIRK_NO_IDLE | SYSC_QUIRK_NO_IDLE_ON_INIT))
manage_clocks = false; manage_clocks = false;
error = sysc_clockdomain_init(ddata);
if (error)
return error;
if (manage_clocks) { if (manage_clocks) {
sysc_clkdm_deny_idle(ddata);
error = sysc_enable_opt_clocks(ddata); error = sysc_enable_opt_clocks(ddata);
if (error) if (error)
return error; return error;
...@@ -1360,20 +1420,33 @@ static int sysc_init_module(struct sysc *ddata) ...@@ -1360,20 +1420,33 @@ static int sysc_init_module(struct sysc *ddata)
ddata->revision = sysc_read_revision(ddata); ddata->revision = sysc_read_revision(ddata);
sysc_init_revision_quirks(ddata); sysc_init_revision_quirks(ddata);
error = sysc_legacy_init(ddata); if (ddata->legacy_mode) {
if (error) error = sysc_legacy_init(ddata);
goto err_main_clocks; if (error)
goto err_main_clocks;
}
if (!ddata->legacy_mode && manage_clocks) {
error = sysc_enable_module(ddata->dev);
if (error)
goto err_main_clocks;
}
error = sysc_reset(ddata); error = sysc_reset(ddata);
if (error) if (error)
dev_err(ddata->dev, "Reset failed with %d\n", error); dev_err(ddata->dev, "Reset failed with %d\n", error);
if (!ddata->legacy_mode && manage_clocks)
sysc_disable_module(ddata->dev);
err_main_clocks: err_main_clocks:
if (manage_clocks) if (manage_clocks)
sysc_disable_main_clocks(ddata); sysc_disable_main_clocks(ddata);
err_opt_clocks: err_opt_clocks:
if (manage_clocks) if (manage_clocks) {
sysc_disable_opt_clocks(ddata); sysc_disable_opt_clocks(ddata);
sysc_clkdm_allow_idle(ddata);
}
return error; return error;
} }
...@@ -2012,20 +2085,22 @@ static int sysc_init_pdata(struct sysc *ddata) ...@@ -2012,20 +2085,22 @@ static int sysc_init_pdata(struct sysc *ddata)
struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev); struct ti_sysc_platform_data *pdata = dev_get_platdata(ddata->dev);
struct ti_sysc_module_data *mdata; struct ti_sysc_module_data *mdata;
if (!pdata || !ddata->legacy_mode) if (!pdata)
return 0; return 0;
mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL); mdata = devm_kzalloc(ddata->dev, sizeof(*mdata), GFP_KERNEL);
if (!mdata) if (!mdata)
return -ENOMEM; return -ENOMEM;
mdata->name = ddata->legacy_mode; if (ddata->legacy_mode) {
mdata->module_pa = ddata->module_pa; mdata->name = ddata->legacy_mode;
mdata->module_size = ddata->module_size; mdata->module_pa = ddata->module_pa;
mdata->offsets = ddata->offsets; mdata->module_size = ddata->module_size;
mdata->nr_offsets = SYSC_MAX_REGS; mdata->offsets = ddata->offsets;
mdata->cap = ddata->cap; mdata->nr_offsets = SYSC_MAX_REGS;
mdata->cfg = &ddata->cfg; mdata->cap = ddata->cap;
mdata->cfg = &ddata->cfg;
}
ddata->mdata = mdata; ddata->mdata = mdata;
......
...@@ -19,6 +19,7 @@ enum ti_sysc_module_type { ...@@ -19,6 +19,7 @@ enum ti_sysc_module_type {
struct ti_sysc_cookie { struct ti_sysc_cookie {
void *data; void *data;
void *clkdm;
}; };
/** /**
...@@ -125,9 +126,16 @@ struct ti_sysc_module_data { ...@@ -125,9 +126,16 @@ struct ti_sysc_module_data {
}; };
struct device; struct device;
struct clk;
struct ti_sysc_platform_data { struct ti_sysc_platform_data {
struct of_dev_auxdata *auxdata; struct of_dev_auxdata *auxdata;
int (*init_clockdomain)(struct device *dev, struct clk *fck,
struct clk *ick, struct ti_sysc_cookie *cookie);
void (*clkdm_deny_idle)(struct device *dev,
const struct ti_sysc_cookie *cookie);
void (*clkdm_allow_idle)(struct device *dev,
const struct ti_sysc_cookie *cookie);
int (*init_module)(struct device *dev, int (*init_module)(struct device *dev,
const struct ti_sysc_module_data *data, const struct ti_sysc_module_data *data,
struct ti_sysc_cookie *cookie); struct ti_sysc_cookie *cookie);
......
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