2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-12-17 12:59:31 +00:00
|
|
|
/*
|
|
|
|
* DaVinci Power Management Routines
|
|
|
|
*
|
2020-07-19 10:20:20 +00:00
|
|
|
* Copyright (C) 2009 Texas Instruments, Inc. https://www.ti.com/
|
2009-12-17 12:59:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/delay.h>
|
2011-06-16 11:01:34 +00:00
|
|
|
#include <asm/io.h>
|
2009-12-17 12:59:31 +00:00
|
|
|
|
2022-04-28 07:32:09 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "da8xx.h"
|
|
|
|
#include "mux.h"
|
|
|
|
#include "pm.h"
|
2009-12-17 12:59:31 +00:00
|
|
|
#include "clock.h"
|
2016-11-15 19:54:19 +00:00
|
|
|
#include "psc.h"
|
|
|
|
#include "sram.h"
|
2009-12-17 12:59:31 +00:00
|
|
|
|
2016-11-15 19:54:19 +00:00
|
|
|
#define DA850_PLL1_BASE 0x01e1a000
|
2009-12-17 12:59:31 +00:00
|
|
|
#define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
|
2016-11-15 19:54:19 +00:00
|
|
|
#define DEEPSLEEP_SLEEPCOUNT 128
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
static void (*davinci_sram_suspend) (struct davinci_pm_config *);
|
2016-11-15 19:54:19 +00:00
|
|
|
static struct davinci_pm_config pm_config = {
|
|
|
|
.sleepcount = DEEPSLEEP_SLEEPCOUNT,
|
|
|
|
.ddrpsc_num = DA8XX_LPSC1_EMIF3C,
|
|
|
|
};
|
|
|
|
|
2009-12-17 12:59:31 +00:00
|
|
|
static void davinci_sram_push(void *dest, void *src, unsigned int size)
|
|
|
|
{
|
|
|
|
memcpy(dest, src, size);
|
|
|
|
flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void davinci_pm_suspend(void)
|
|
|
|
{
|
|
|
|
unsigned val;
|
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
if (pm_config.cpupll_reg_base != pm_config.ddrpll_reg_base) {
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* Switch CPU PLL to bypass mode */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
udelay(PLL_BYPASS_TIME);
|
|
|
|
|
|
|
|
/* Powerdown CPU PLL */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val |= PLLCTL_PLLPWRDN;
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure sleep count in deep sleep register */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.deepsleep_reg);
|
2009-12-17 12:59:31 +00:00
|
|
|
val &= ~DEEPSLEEP_SLEEPCOUNT_MASK,
|
2016-11-15 19:54:20 +00:00
|
|
|
val |= pm_config.sleepcount;
|
|
|
|
__raw_writel(val, pm_config.deepsleep_reg);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* System goes to sleep in this call */
|
2016-11-15 19:54:20 +00:00
|
|
|
davinci_sram_suspend(&pm_config);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
if (pm_config.cpupll_reg_base != pm_config.ddrpll_reg_base) {
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* put CPU PLL in reset */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val &= ~PLLCTL_PLLRST;
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* put CPU PLL in power down */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val &= ~PLLCTL_PLLPWRDN;
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* wait for CPU PLL reset */
|
|
|
|
udelay(PLL_RESET_TIME);
|
|
|
|
|
|
|
|
/* bring CPU PLL out of reset */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val |= PLLCTL_PLLRST;
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
|
|
|
|
/* Wait for CPU PLL to lock */
|
|
|
|
udelay(PLL_LOCK_TIME);
|
|
|
|
|
|
|
|
/* Remove CPU PLL from bypass mode */
|
2016-11-15 19:54:20 +00:00
|
|
|
val = __raw_readl(pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
val &= ~PLLCTL_PLLENSRC;
|
|
|
|
val |= PLLCTL_PLLEN;
|
2016-11-15 19:54:20 +00:00
|
|
|
__raw_writel(val, pm_config.cpupll_reg_base + PLLCTL);
|
2009-12-17 12:59:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int davinci_pm_enter(suspend_state_t state)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case PM_SUSPEND_MEM:
|
|
|
|
davinci_pm_suspend();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-16 13:14:02 +00:00
|
|
|
static const struct platform_suspend_ops davinci_pm_ops = {
|
2009-12-17 12:59:31 +00:00
|
|
|
.enter = davinci_pm_enter,
|
|
|
|
.valid = suspend_valid_only_mem,
|
|
|
|
};
|
|
|
|
|
2016-11-15 19:54:19 +00:00
|
|
|
int __init davinci_pm_init(void)
|
2009-12-17 12:59:31 +00:00
|
|
|
{
|
2016-11-15 19:54:19 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = davinci_cfg_reg(DA850_RTC_ALARM);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
pm_config.ddr2_ctlr_base = da8xx_get_mem_ctlr();
|
|
|
|
pm_config.deepsleep_reg = DA8XX_SYSCFG1_VIRT(DA8XX_DEEPSLEEP_REG);
|
2016-11-15 19:54:19 +00:00
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
pm_config.cpupll_reg_base = ioremap(DA8XX_PLL0_BASE, SZ_4K);
|
|
|
|
if (!pm_config.cpupll_reg_base)
|
2016-11-15 19:54:19 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
pm_config.ddrpll_reg_base = ioremap(DA850_PLL1_BASE, SZ_4K);
|
|
|
|
if (!pm_config.ddrpll_reg_base) {
|
2016-11-15 19:54:19 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto no_ddrpll_mem;
|
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:20 +00:00
|
|
|
pm_config.ddrpsc_reg_base = ioremap(DA8XX_PSC1_BASE, SZ_4K);
|
|
|
|
if (!pm_config.ddrpsc_reg_base) {
|
2016-11-15 19:54:19 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto no_ddrpsc_mem;
|
2009-12-17 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
|
|
|
|
if (!davinci_sram_suspend) {
|
2016-11-15 19:54:19 +00:00
|
|
|
pr_err("PM: cannot allocate SRAM memory\n");
|
2017-05-13 11:40:05 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto no_sram_mem;
|
2009-12-17 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
|
|
|
|
davinci_cpu_suspend_sz);
|
|
|
|
|
|
|
|
suspend_set_ops(&davinci_pm_ops);
|
|
|
|
|
2017-05-13 11:40:20 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-05-13 11:40:05 +00:00
|
|
|
no_sram_mem:
|
|
|
|
iounmap(pm_config.ddrpsc_reg_base);
|
2016-11-15 19:54:19 +00:00
|
|
|
no_ddrpsc_mem:
|
2016-11-15 19:54:20 +00:00
|
|
|
iounmap(pm_config.ddrpll_reg_base);
|
2016-11-15 19:54:19 +00:00
|
|
|
no_ddrpll_mem:
|
2016-11-15 19:54:20 +00:00
|
|
|
iounmap(pm_config.cpupll_reg_base);
|
2016-11-15 19:54:19 +00:00
|
|
|
return ret;
|
2009-12-17 12:59:31 +00:00
|
|
|
}
|