blob: 4392c4ed0183cb2c5819194f67cc23f509a25d6c [file] [log] [blame]
Sekhar Noriefc1bb82009-12-17 18:29:31 +05301/*
2 * DaVinci Power Management Routines
3 *
4 * Copyright (C) 2009 Texas Instruments, Inc. http://www.ti.com/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/pm.h>
12#include <linux/suspend.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/clk.h>
16#include <linux/spinlock.h>
17
18#include <asm/cacheflush.h>
19#include <asm/delay.h>
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000020#include <asm/io.h>
Sekhar Noriefc1bb82009-12-17 18:29:31 +053021
Sekhar Nori215a0842013-04-10 14:57:15 +053022#include <mach/common.h>
Sekhar Noriefc1bb82009-12-17 18:29:31 +053023#include <mach/da8xx.h>
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -080024#include <mach/mux.h>
Sekhar Noriefc1bb82009-12-17 18:29:31 +053025#include <mach/pm.h>
26
27#include "clock.h"
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -080028#include "psc.h"
29#include "sram.h"
Sekhar Noriefc1bb82009-12-17 18:29:31 +053030
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -080031#define DA850_PLL1_BASE 0x01e1a000
Sekhar Noriefc1bb82009-12-17 18:29:31 +053032#define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -080033#define DEEPSLEEP_SLEEPCOUNT 128
Sekhar Noriefc1bb82009-12-17 18:29:31 +053034
35static void (*davinci_sram_suspend) (struct davinci_pm_config *);
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -080036static struct davinci_pm_config pm_config = {
37 .sleepcount = DEEPSLEEP_SLEEPCOUNT,
38 .ddrpsc_num = DA8XX_LPSC1_EMIF3C,
39};
40
41static struct davinci_pm_config *pdata = &pm_config;
Sekhar Noriefc1bb82009-12-17 18:29:31 +053042
43static void davinci_sram_push(void *dest, void *src, unsigned int size)
44{
45 memcpy(dest, src, size);
46 flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
47}
48
49static void davinci_pm_suspend(void)
50{
51 unsigned val;
52
53 if (pdata->cpupll_reg_base != pdata->ddrpll_reg_base) {
54
55 /* Switch CPU PLL to bypass mode */
56 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
57 val &= ~(PLLCTL_PLLENSRC | PLLCTL_PLLEN);
58 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
59
60 udelay(PLL_BYPASS_TIME);
61
62 /* Powerdown CPU PLL */
63 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
64 val |= PLLCTL_PLLPWRDN;
65 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
66 }
67
68 /* Configure sleep count in deep sleep register */
69 val = __raw_readl(pdata->deepsleep_reg);
70 val &= ~DEEPSLEEP_SLEEPCOUNT_MASK,
71 val |= pdata->sleepcount;
72 __raw_writel(val, pdata->deepsleep_reg);
73
74 /* System goes to sleep in this call */
75 davinci_sram_suspend(pdata);
76
77 if (pdata->cpupll_reg_base != pdata->ddrpll_reg_base) {
78
79 /* put CPU PLL in reset */
80 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
81 val &= ~PLLCTL_PLLRST;
82 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
83
84 /* put CPU PLL in power down */
85 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
86 val &= ~PLLCTL_PLLPWRDN;
87 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
88
89 /* wait for CPU PLL reset */
90 udelay(PLL_RESET_TIME);
91
92 /* bring CPU PLL out of reset */
93 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
94 val |= PLLCTL_PLLRST;
95 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
96
97 /* Wait for CPU PLL to lock */
98 udelay(PLL_LOCK_TIME);
99
100 /* Remove CPU PLL from bypass mode */
101 val = __raw_readl(pdata->cpupll_reg_base + PLLCTL);
102 val &= ~PLLCTL_PLLENSRC;
103 val |= PLLCTL_PLLEN;
104 __raw_writel(val, pdata->cpupll_reg_base + PLLCTL);
105 }
106}
107
108static int davinci_pm_enter(suspend_state_t state)
109{
110 int ret = 0;
111
112 switch (state) {
113 case PM_SUSPEND_STANDBY:
114 case PM_SUSPEND_MEM:
115 davinci_pm_suspend();
116 break;
117 default:
118 ret = -EINVAL;
119 }
120
121 return ret;
122}
123
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100124static const struct platform_suspend_ops davinci_pm_ops = {
Sekhar Noriefc1bb82009-12-17 18:29:31 +0530125 .enter = davinci_pm_enter,
126 .valid = suspend_valid_only_mem,
127};
128
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -0800129int __init davinci_pm_init(void)
Sekhar Noriefc1bb82009-12-17 18:29:31 +0530130{
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -0800131 int ret;
132
133 ret = davinci_cfg_reg(DA850_RTC_ALARM);
134 if (ret)
135 return ret;
136
137 pdata->ddr2_ctlr_base = da8xx_get_mem_ctlr();
138 pdata->deepsleep_reg = DA8XX_SYSCFG1_VIRT(DA8XX_DEEPSLEEP_REG);
139
140 pdata->cpupll_reg_base = ioremap(DA8XX_PLL0_BASE, SZ_4K);
141 if (!pdata->cpupll_reg_base)
142 return -ENOMEM;
143
144 pdata->ddrpll_reg_base = ioremap(DA850_PLL1_BASE, SZ_4K);
145 if (!pdata->ddrpll_reg_base) {
146 ret = -ENOMEM;
147 goto no_ddrpll_mem;
148 }
149
150 pdata->ddrpsc_reg_base = ioremap(DA8XX_PSC1_BASE, SZ_4K);
151 if (!pdata->ddrpsc_reg_base) {
152 ret = -ENOMEM;
153 goto no_ddrpsc_mem;
Sekhar Noriefc1bb82009-12-17 18:29:31 +0530154 }
155
156 davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
157 if (!davinci_sram_suspend) {
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -0800158 pr_err("PM: cannot allocate SRAM memory\n");
Sekhar Noriefc1bb82009-12-17 18:29:31 +0530159 return -ENOMEM;
160 }
161
162 davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
163 davinci_cpu_suspend_sz);
164
165 suspend_set_ops(&davinci_pm_ops);
166
Kevin Hilmanaa9aa1e2016-11-15 11:54:19 -0800167no_ddrpsc_mem:
168 iounmap(pdata->ddrpll_reg_base);
169no_ddrpll_mem:
170 iounmap(pdata->cpupll_reg_base);
171 return ret;
Sekhar Noriefc1bb82009-12-17 18:29:31 +0530172}