Skip to content

Commit

Permalink
ARM: OMAP2+: Fix overwriting of clkctrl and modulemode values
Browse files Browse the repository at this point in the history
We are currently overwiting the hwmod clkctrl registers if we
configure a clock ctrl clock from device tree.

While this does not expose any bugs except for kernel coders
when debugging things, it should be fixed for correctness.
It is now impossible to use the hwmod data for checking the
clkctrl register values after booting for debugging or
generating dts data from hwmod data.

Let's fix the issue by adding a helper to detect if clkctrl
clock is configured.

Cc: Lokesh Vutla <lokeshvutla@ti.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
  • Loading branch information
Tony Lindgren committed Sep 19, 2017
1 parent 6963c58 commit 8823ddf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
49 changes: 41 additions & 8 deletions arch/arm/mach-omap2/omap_hwmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,34 @@ static int _enable_clocks(struct omap_hwmod *oh)
return 0;
}

/**
* _omap4_clkctrl_managed_by_clkfwk - true if clkctrl managed by clock framework
* @oh: struct omap_hwmod *
*/
static bool _omap4_clkctrl_managed_by_clkfwk(struct omap_hwmod *oh)
{
if (oh->prcm.omap4.flags & HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK)
return true;

return false;
}

/**
* _omap4_has_clkctrl_clock - returns true if a module has clkctrl clock
* @oh: struct omap_hwmod *
*/
static bool _omap4_has_clkctrl_clock(struct omap_hwmod *oh)
{
if (oh->prcm.omap4.clkctrl_offs)
return true;

if (!oh->prcm.omap4.clkctrl_offs &&
oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET)
return true;

return false;
}

/**
* _disable_clocks - disable hwmod main clock and interface clocks
* @oh: struct omap_hwmod *
Expand Down Expand Up @@ -1030,7 +1058,8 @@ static int _disable_clocks(struct omap_hwmod *oh)
*/
static void _omap4_enable_module(struct omap_hwmod *oh)
{
if (!oh->clkdm || !oh->prcm.omap4.modulemode)
if (!oh->clkdm || !oh->prcm.omap4.modulemode ||
_omap4_clkctrl_managed_by_clkfwk(oh))
return;

pr_debug("omap_hwmod: %s: %s: %d\n",
Expand Down Expand Up @@ -1061,8 +1090,10 @@ static int _omap4_wait_target_disable(struct omap_hwmod *oh)
if (oh->flags & HWMOD_NO_IDLEST)
return 0;

if (!oh->prcm.omap4.clkctrl_offs &&
!(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
if (_omap4_clkctrl_managed_by_clkfwk(oh))
return 0;

if (!_omap4_has_clkctrl_clock(oh))
return 0;

return omap_cm_wait_module_idle(oh->clkdm->prcm_partition,
Expand Down Expand Up @@ -1847,7 +1878,8 @@ static int _omap4_disable_module(struct omap_hwmod *oh)
{
int v;

if (!oh->clkdm || !oh->prcm.omap4.modulemode)
if (!oh->clkdm || !oh->prcm.omap4.modulemode ||
_omap4_clkctrl_managed_by_clkfwk(oh))
return -EINVAL;

/*
Expand Down Expand Up @@ -2829,8 +2861,10 @@ static int _omap4_wait_target_ready(struct omap_hwmod *oh)
if (!_find_mpu_rt_port(oh))
return 0;

if (!oh->prcm.omap4.clkctrl_offs &&
!(oh->prcm.omap4.flags & HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET))
if (_omap4_clkctrl_managed_by_clkfwk(oh))
return 0;

if (!_omap4_has_clkctrl_clock(oh))
return 0;

/* XXX check module SIDLEMODE, hardreset status */
Expand Down Expand Up @@ -2986,8 +3020,7 @@ static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
if (!oh)
return -EINVAL;

oh->prcm.omap4.clkctrl_offs = 0;
oh->prcm.omap4.modulemode = 0;
oh->prcm.omap4.flags |= HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK;

return 0;
}
Expand Down
3 changes: 3 additions & 0 deletions arch/arm/mach-omap2/omap_hwmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,12 @@ struct omap_hwmod_omap2_prcm {
* HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET: Some IP blocks have a valid CLKCTRL
* offset of zero; this flag bit should be set in those cases to
* distinguish from hwmods that have no clkctrl offset.
* HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK: Module clockctrl clock is managed
* by the common clock framework and not hwmod.
*/
#define HWMOD_OMAP4_NO_CONTEXT_LOSS_BIT (1 << 0)
#define HWMOD_OMAP4_ZERO_CLKCTRL_OFFSET (1 << 1)
#define HWMOD_OMAP4_CLKFWK_CLKCTR_CLOCK (1 << 2)

/**
* struct omap_hwmod_omap4_prcm - OMAP4-specific PRCM data
Expand Down

0 comments on commit 8823ddf

Please sign in to comment.