Skip to content

Commit 9fabc1a

Browse files
Tero Kristotmlind
authored andcommitted
ARM: OMAP2+: hwmod: fetch main_clk based on hwmod name
With the transition to hwmod module clocks, all hwmods will have their main clocks named <hwmod_name>_mod_ck. Use this info to fetch main_clk, and use it if found. Also, if a main_clk is found based on the hwmod name, disable the direct PRCM modulemode access from hwmod. Signed-off-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Tony Lindgren <tony@atomide.com>
1 parent 59dcfc4 commit 9fabc1a

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

arch/arm/mach-omap2/omap_hwmod.c

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@
178178
*/
179179
#define OMAP4_RST_CTRL_ST_OFFSET 4
180180

181+
/*
182+
* Maximum length for module clock handle names
183+
*/
184+
#define MOD_CLK_MAX_NAME_LEN 32
185+
181186
/**
182187
* struct omap_hwmod_soc_ops - fn ptrs for some SoC-specific operations
183188
* @enable_module: function to enable a module (via MODULEMODE)
@@ -200,6 +205,7 @@ struct omap_hwmod_soc_ops {
200205
int (*init_clkdm)(struct omap_hwmod *oh);
201206
void (*update_context_lost)(struct omap_hwmod *oh);
202207
int (*get_context_lost)(struct omap_hwmod *oh);
208+
int (*disable_direct_prcm)(struct omap_hwmod *oh);
203209
};
204210

205211
/* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
@@ -776,17 +782,35 @@ static int _del_initiator_dep(struct omap_hwmod *oh, struct omap_hwmod *init_oh)
776782
* @oh: struct omap_hwmod *
777783
*
778784
* Called from _init_clocks(). Populates the @oh _clk (main
779-
* functional clock pointer) if a main_clk is present. Returns 0 on
780-
* success or -EINVAL on error.
785+
* functional clock pointer) if a clock matching the hwmod name is found,
786+
* or a main_clk is present. Returns 0 on success or -EINVAL on error.
781787
*/
782788
static int _init_main_clk(struct omap_hwmod *oh)
783789
{
784790
int ret = 0;
791+
char name[MOD_CLK_MAX_NAME_LEN];
792+
struct clk *clk;
785793

786-
if (!oh->main_clk)
787-
return 0;
794+
/* +7 magic comes from '_mod_ck' suffix */
795+
if (strlen(oh->name) + 7 > MOD_CLK_MAX_NAME_LEN)
796+
pr_warn("%s: warning: cropping name for %s\n", __func__,
797+
oh->name);
798+
799+
strncpy(name, oh->name, MOD_CLK_MAX_NAME_LEN - 7);
800+
strcat(name, "_mod_ck");
801+
802+
clk = clk_get(NULL, name);
803+
if (!IS_ERR(clk)) {
804+
oh->_clk = clk;
805+
soc_ops.disable_direct_prcm(oh);
806+
oh->main_clk = kstrdup(name, GFP_KERNEL);
807+
} else {
808+
if (!oh->main_clk)
809+
return 0;
810+
811+
oh->_clk = clk_get(NULL, oh->main_clk);
812+
}
788813

789-
oh->_clk = clk_get(NULL, oh->main_clk);
790814
if (IS_ERR(oh->_clk)) {
791815
pr_warn("omap_hwmod: %s: cannot clk_get main_clk %s\n",
792816
oh->name, oh->main_clk);
@@ -3090,6 +3114,25 @@ static int _omap4_is_hardreset_asserted(struct omap_hwmod *oh,
30903114
oh->prcm.omap4.rstctrl_offs);
30913115
}
30923116

3117+
/**
3118+
* _omap4_disable_direct_prcm - disable direct PRCM control for hwmod
3119+
* @oh: struct omap_hwmod * to disable control for
3120+
*
3121+
* Disables direct PRCM clkctrl done by hwmod core. Instead, the hwmod
3122+
* will be using its main_clk to enable/disable the module. Returns
3123+
* 0 if successful.
3124+
*/
3125+
static int _omap4_disable_direct_prcm(struct omap_hwmod *oh)
3126+
{
3127+
if (!oh)
3128+
return -EINVAL;
3129+
3130+
oh->prcm.omap4.clkctrl_offs = 0;
3131+
oh->prcm.omap4.modulemode = 0;
3132+
3133+
return 0;
3134+
}
3135+
30933136
/**
30943137
* _am33xx_deassert_hardreset - call AM33XX PRM hardreset fn with hwmod args
30953138
* @oh: struct omap_hwmod * to deassert hardreset
@@ -3913,6 +3956,7 @@ void __init omap_hwmod_init(void)
39133956
soc_ops.init_clkdm = _init_clkdm;
39143957
soc_ops.update_context_lost = _omap4_update_context_lost;
39153958
soc_ops.get_context_lost = _omap4_get_context_lost;
3959+
soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
39163960
} else if (cpu_is_ti814x() || cpu_is_ti816x() || soc_is_am33xx() ||
39173961
soc_is_am43xx()) {
39183962
soc_ops.enable_module = _omap4_enable_module;
@@ -3922,6 +3966,7 @@ void __init omap_hwmod_init(void)
39223966
soc_ops.deassert_hardreset = _am33xx_deassert_hardreset;
39233967
soc_ops.is_hardreset_asserted = _omap4_is_hardreset_asserted;
39243968
soc_ops.init_clkdm = _init_clkdm;
3969+
soc_ops.disable_direct_prcm = _omap4_disable_direct_prcm;
39253970
} else {
39263971
WARN(1, "omap_hwmod: unknown SoC type\n");
39273972
}

0 commit comments

Comments
 (0)