2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-04-04 17:16:53 +00:00
|
|
|
/*
|
|
|
|
* Keystone: PSC configuration module
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012-2014
|
|
|
|
* Texas Instruments Incorporated, <www.ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-09-21 02:28:57 +00:00
|
|
|
#include <linux/errno.h>
|
2014-04-04 17:16:53 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/arch/psc_defs.h>
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_delay() - delay for psc
|
|
|
|
*
|
|
|
|
* Return: 10
|
|
|
|
*/
|
2014-04-04 17:16:53 +00:00
|
|
|
int psc_delay(void)
|
|
|
|
{
|
|
|
|
udelay(10);
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_wait() - Wait for end of transitional state
|
|
|
|
* @domain_num: GPSC domain number
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Polls pstat for the selected domain and waits for transitions to be complete.
|
|
|
|
* Since this is boot loader code it is *ASSUMED* that interrupts are disabled
|
|
|
|
* and no other core is mucking around with the psc at the same time.
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Return: 0 when the domain is free. Returns -1 if a timeout occurred waiting
|
|
|
|
* for the completion.
|
2014-04-04 17:16:53 +00:00
|
|
|
*/
|
|
|
|
int psc_wait(u32 domain_num)
|
|
|
|
{
|
|
|
|
u32 retry;
|
|
|
|
u32 ptstat;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing if the power domain is in transition. This should never
|
|
|
|
* happen since the boot code is the only software accesses psc.
|
|
|
|
* It's still remotely possible that the hardware state machines
|
|
|
|
* initiate transitions.
|
|
|
|
* Don't trap if the domain (or a module in this domain) is
|
|
|
|
* stuck in transition.
|
|
|
|
*/
|
|
|
|
retry = 0;
|
|
|
|
|
|
|
|
do {
|
2014-08-28 13:07:45 +00:00
|
|
|
ptstat = __raw_readl(KS2_PSC_BASE + PSC_REG_PSTAT);
|
2014-04-04 17:16:53 +00:00
|
|
|
ptstat = ptstat & (1 << domain_num);
|
|
|
|
} while ((ptstat != 0) && ((retry += psc_delay()) <
|
|
|
|
PSC_PTSTAT_TIMEOUT_LIMIT));
|
|
|
|
|
|
|
|
if (retry >= PSC_PTSTAT_TIMEOUT_LIMIT)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_get_domain_num() - Get the domain number
|
|
|
|
* @mod_num: LPSC module number
|
|
|
|
*/
|
2014-04-04 17:16:53 +00:00
|
|
|
u32 psc_get_domain_num(u32 mod_num)
|
|
|
|
{
|
|
|
|
u32 domain_num;
|
|
|
|
|
|
|
|
/* Get the power domain associated with the module number */
|
2014-08-28 13:07:45 +00:00
|
|
|
domain_num = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCFG(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
domain_num = PSC_REG_MDCFG_GET_PD(domain_num);
|
|
|
|
|
|
|
|
return domain_num;
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_set_state() - powers up/down a module
|
|
|
|
* @mod_num: LPSC module number
|
|
|
|
* @state: 1 to enable, 0 to disable.
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Powers up/down the requested module and the associated power domain if
|
|
|
|
* required. No action is taken it the module is already powered up/down.
|
|
|
|
* This only controls modules. The domain in which the module resides will
|
|
|
|
* be left in the power on state. Multiple modules can exist in a power
|
|
|
|
* domain, so powering down the domain based on a single module is not done.
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Return: 0 on success, -1 if the module can't be powered up, or if there is a
|
|
|
|
* timeout waiting for the transition.
|
2014-04-04 17:16:53 +00:00
|
|
|
*/
|
|
|
|
int psc_set_state(u32 mod_num, u32 state)
|
|
|
|
{
|
|
|
|
u32 domain_num;
|
|
|
|
u32 pdctl;
|
|
|
|
u32 mdctl;
|
|
|
|
u32 ptcmd;
|
|
|
|
u32 reset_iso;
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the power domain associated with the module number, and reset
|
|
|
|
* isolation functionality
|
|
|
|
*/
|
2014-08-28 13:07:45 +00:00
|
|
|
v = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCFG(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
domain_num = PSC_REG_MDCFG_GET_PD(v);
|
|
|
|
reset_iso = PSC_REG_MDCFG_GET_RESET_ISO(v);
|
|
|
|
|
|
|
|
/* Wait for the status of the domain/module to be non-transitional */
|
|
|
|
if (psc_wait(domain_num) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform configuration even if the current status matches the
|
|
|
|
* existing state
|
|
|
|
*
|
|
|
|
* Set the next state of the power domain to on. It's OK if the domain
|
|
|
|
* is always on. This code will not ever power down a domain, so no
|
|
|
|
* change is made if the new state is power down.
|
|
|
|
*/
|
|
|
|
if (state == PSC_REG_VAL_MDCTL_NEXT_ON) {
|
2014-08-28 13:07:45 +00:00
|
|
|
pdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_PDCTL(domain_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
pdctl = PSC_REG_PDCTL_SET_NEXT(pdctl,
|
|
|
|
PSC_REG_VAL_PDCTL_NEXT_ON);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(pdctl, KS2_PSC_BASE + PSC_REG_PDCTL(domain_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the next state for the module to enabled/disabled */
|
2014-08-28 13:07:45 +00:00
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
mdctl = PSC_REG_MDCTL_SET_NEXT(mdctl, state);
|
|
|
|
mdctl = PSC_REG_MDCTL_SET_RESET_ISO(mdctl, reset_iso);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
/* Trigger the enable */
|
2014-08-28 13:07:45 +00:00
|
|
|
ptcmd = __raw_readl(KS2_PSC_BASE + PSC_REG_PTCMD);
|
2014-04-04 17:16:53 +00:00
|
|
|
ptcmd |= (u32)(1<<domain_num);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(ptcmd, KS2_PSC_BASE + PSC_REG_PTCMD);
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
/* Wait on the complete */
|
|
|
|
return psc_wait(domain_num);
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_enable_module() - power up a module
|
|
|
|
* @mod_num: LPSC module number
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Powers up the requested module and the associated power domain
|
|
|
|
* if required. No action is taken it the module is already powered up.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, -1 if the module can't be powered up, or
|
|
|
|
* if there is a timeout waiting for the transition.
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
int psc_enable_module(u32 mod_num)
|
|
|
|
{
|
|
|
|
u32 mdctl;
|
|
|
|
|
|
|
|
/* Set the bit to apply reset */
|
2014-08-28 13:07:45 +00:00
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
if ((mdctl & 0x3f) == PSC_REG_VAL_MDSTAT_STATE_ON)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return psc_set_state(mod_num, PSC_REG_VAL_MDCTL_NEXT_ON);
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_disable_module() - Power down a module
|
|
|
|
* @mod_num: LPSC module number
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* Return: 0 on success, -1 on failure or timeout.
|
2014-04-04 17:16:53 +00:00
|
|
|
*/
|
|
|
|
int psc_disable_module(u32 mod_num)
|
|
|
|
{
|
|
|
|
u32 mdctl;
|
|
|
|
|
|
|
|
/* Set the bit to apply reset */
|
2014-08-28 13:07:45 +00:00
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
if ((mdctl & 0x3f) == 0)
|
|
|
|
return 0;
|
|
|
|
mdctl = PSC_REG_MDCTL_SET_LRSTZ(mdctl, 0);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
return psc_set_state(mod_num, PSC_REG_VAL_MDCTL_NEXT_SWRSTDISABLE);
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_set_reset_iso() - Set the reset isolation bit in mdctl
|
|
|
|
* @mod_num: LPSC module number
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2016-02-25 18:53:42 +00:00
|
|
|
* The reset isolation enable bit is set. The state of the module is not
|
|
|
|
* changed.
|
|
|
|
*
|
|
|
|
* Return: 0 if the module config showed that reset isolation is supported.
|
|
|
|
* Returns 1 otherwise. This is not an error, but setting the bit in mdctl
|
|
|
|
* has no effect.
|
2014-04-04 17:16:53 +00:00
|
|
|
*/
|
|
|
|
int psc_set_reset_iso(u32 mod_num)
|
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
u32 mdctl;
|
|
|
|
|
|
|
|
/* Set the reset isolation bit */
|
2014-08-28 13:07:45 +00:00
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
mdctl = PSC_REG_MDCTL_SET_RESET_ISO(mdctl, 1);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
|
2014-08-28 13:07:45 +00:00
|
|
|
v = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCFG(mod_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
if (PSC_REG_MDCFG_GET_RESET_ISO(v) == 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-25 18:53:42 +00:00
|
|
|
/**
|
|
|
|
* psc_disable_domain() - Disable a power domain
|
|
|
|
* @domain_num: GPSC domain number
|
2014-04-04 17:16:53 +00:00
|
|
|
*/
|
|
|
|
int psc_disable_domain(u32 domain_num)
|
|
|
|
{
|
|
|
|
u32 pdctl;
|
|
|
|
u32 ptcmd;
|
|
|
|
|
2014-08-28 13:07:45 +00:00
|
|
|
pdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_PDCTL(domain_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
pdctl = PSC_REG_PDCTL_SET_NEXT(pdctl, PSC_REG_VAL_PDCTL_NEXT_OFF);
|
|
|
|
pdctl = PSC_REG_PDCTL_SET_PDMODE(pdctl, PSC_REG_VAL_PDCTL_PDMODE_SLEEP);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(pdctl, KS2_PSC_BASE + PSC_REG_PDCTL(domain_num));
|
2014-04-04 17:16:53 +00:00
|
|
|
|
2014-08-28 13:07:45 +00:00
|
|
|
ptcmd = __raw_readl(KS2_PSC_BASE + PSC_REG_PTCMD);
|
2014-04-04 17:16:53 +00:00
|
|
|
ptcmd |= (u32)(1 << domain_num);
|
2014-08-28 13:07:45 +00:00
|
|
|
__raw_writel(ptcmd, KS2_PSC_BASE + PSC_REG_PTCMD);
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
return psc_wait(domain_num);
|
|
|
|
}
|
2016-02-25 18:53:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* psc_module_keep_in_reset_enabled() - Keep module in enabled,in-reset state
|
|
|
|
* @mod_num: LPSC module number
|
|
|
|
* @gate_clocks: Can the clocks be gated on this module?
|
|
|
|
*
|
|
|
|
* Enable the module, but do not release the module from local reset. This is
|
|
|
|
* necessary for many processor systems on keystone SoCs to allow for system
|
|
|
|
* initialization from a master processor prior to releasing the processor
|
|
|
|
* from reset.
|
|
|
|
*/
|
|
|
|
int psc_module_keep_in_reset_enabled(u32 mod_num, bool gate_clocks)
|
|
|
|
{
|
|
|
|
u32 mdctl, ptcmd, mdstat;
|
|
|
|
u32 next_state;
|
|
|
|
int domain_num = psc_get_domain_num(mod_num);
|
|
|
|
int timeout = 100000;
|
|
|
|
|
|
|
|
/* Wait for any previous transitions to complete */
|
|
|
|
psc_wait(domain_num);
|
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
/* Should be set 0 to assert Local reset */
|
|
|
|
if ((mdctl & PSC_REG_MDCTL_SET_LRSTZ(mdctl, 1))) {
|
|
|
|
mdctl = PSC_REG_MDCTL_SET_LRSTZ(mdctl, 0);
|
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
/* Wait for transition to take place */
|
|
|
|
psc_wait(domain_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear Module reset */
|
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
next_state = gate_clocks ? PSC_REG_VAL_MDCTL_NEXT_OFF :
|
|
|
|
PSC_REG_VAL_MDCTL_NEXT_ON;
|
|
|
|
mdctl = PSC_REG_MDCTL_SET_NEXT(mdctl, next_state);
|
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
/* Trigger PD transition */
|
|
|
|
ptcmd = __raw_readl(KS2_PSC_BASE + PSC_REG_PTCMD);
|
|
|
|
ptcmd |= (u32)(1 << domain_num);
|
|
|
|
__raw_writel(ptcmd, KS2_PSC_BASE + PSC_REG_PTCMD);
|
|
|
|
psc_wait(domain_num);
|
|
|
|
|
|
|
|
mdstat = __raw_readl(KS2_PSC_BASE + PSC_REG_MDSTAT(mod_num));
|
|
|
|
while (timeout) {
|
|
|
|
mdstat = __raw_readl(KS2_PSC_BASE + PSC_REG_MDSTAT(mod_num));
|
|
|
|
|
|
|
|
if (!(PSC_REG_MDSTAT_GET_STATUS(mdstat) & 0x30) &&
|
|
|
|
PSC_REG_MDSTAT_GET_MRSTDONE(mdstat) &&
|
|
|
|
PSC_REG_MDSTAT_GET_LRSTDONE(mdstat))
|
|
|
|
break;
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
printf("%s: Timedout waiting for mdstat(0x%08x) to change\n",
|
|
|
|
__func__, mdstat);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* psc_module_release_from_reset() - Release the module from reset
|
|
|
|
* @mod_num: LPSC module number
|
|
|
|
*
|
|
|
|
* This is the follow through for the command 'psc_module_keep_in_reset_enabled'
|
|
|
|
* Allowing the module to be released from reset once all required inits are
|
|
|
|
* complete for the module. Typically, this allows the processor module to start
|
|
|
|
* execution.
|
|
|
|
*/
|
|
|
|
int psc_module_release_from_reset(u32 mod_num)
|
|
|
|
{
|
|
|
|
u32 mdctl, mdstat;
|
|
|
|
int domain_num = psc_get_domain_num(mod_num);
|
|
|
|
int timeout = 100000;
|
|
|
|
|
|
|
|
/* Wait for any previous transitions to complete */
|
|
|
|
psc_wait(domain_num);
|
|
|
|
mdctl = __raw_readl(KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
/* Should be set to 1 to de-assert Local reset */
|
|
|
|
if ((mdctl & PSC_REG_MDCTL_SET_LRSTZ(mdctl, 0))) {
|
|
|
|
mdctl = PSC_REG_MDCTL_SET_LRSTZ(mdctl, 1);
|
|
|
|
__raw_writel(mdctl, KS2_PSC_BASE + PSC_REG_MDCTL(mod_num));
|
|
|
|
/* Wait for transition to take place */
|
|
|
|
psc_wait(domain_num);
|
|
|
|
}
|
|
|
|
mdstat = __raw_readl(KS2_PSC_BASE + PSC_REG_MDSTAT(mod_num));
|
|
|
|
while (timeout) {
|
|
|
|
mdstat = __raw_readl(KS2_PSC_BASE + PSC_REG_MDSTAT(mod_num));
|
|
|
|
|
|
|
|
if (!(PSC_REG_MDSTAT_GET_STATUS(mdstat) & 0x30) &&
|
|
|
|
PSC_REG_MDSTAT_GET_MRSTDONE(mdstat) &&
|
|
|
|
PSC_REG_MDSTAT_GET_LRSTDONE(mdstat))
|
|
|
|
break;
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
printf("%s: Timedout waiting for mdstat(0x%08x) to change\n",
|
|
|
|
__func__, mdstat);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|