blob: 485550af250623109eca94fa0e9442dea99b08fe [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Rajendra Nayak5643aeb2010-08-02 13:18:18 +03002/*
Santosh Shilimkar705814b2012-04-12 16:51:47 +05303 * OMAP4+ Power Management Routines
Rajendra Nayak5643aeb2010-08-02 13:18:18 +03004 *
Santosh Shilimkar705814b2012-04-12 16:51:47 +05305 * Copyright (C) 2010-2013 Texas Instruments, Inc.
Rajendra Nayak5643aeb2010-08-02 13:18:18 +03006 * Rajendra Nayak <rnayak@ti.com>
Santosh Shilimkare44f9a72010-06-16 22:19:49 +05307 * Santosh Shilimkar <santosh.shilimkar@ti.com>
Rajendra Nayak5643aeb2010-08-02 13:18:18 +03008 */
9
10#include <linux/pm.h>
11#include <linux/suspend.h>
12#include <linux/module.h>
13#include <linux/list.h>
14#include <linux/err.h>
15#include <linux/slab.h>
David Howells9f97da72012-03-28 18:30:01 +010016#include <asm/system_misc.h>
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030017
Tony Lindgrene4c060d2012-10-05 13:25:59 -070018#include "soc.h"
Tony Lindgren4e653312011-11-10 22:45:17 +010019#include "common.h"
Santosh Shilimkar3c507292011-01-05 22:03:17 +053020#include "clockdomain.h"
Paul Walmsley72e06d02010-12-21 21:05:16 -070021#include "powerdomain.h"
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053022#include "pm.h"
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030023
Nishanth Menonde70af42014-01-20 14:06:37 -060024u16 pm44xx_errata;
25
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030026struct power_state {
27 struct powerdomain *pwrdm;
28 u32 next_state;
Nishanth Menon46ba5522014-06-05 21:40:39 -050029 u32 next_logic_state;
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030030#ifdef CONFIG_SUSPEND
31 u32 saved_state;
Santosh Shilimkar3ba2a732011-06-06 14:33:29 +053032 u32 saved_logic_state;
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030033#endif
34 struct list_head node;
35};
36
Nishanth Menonb9f5fe62014-10-21 15:22:29 -050037/**
38 * struct static_dep_map - Static dependency map
39 * @from: from clockdomain
40 * @to: to clockdomain
41 */
42struct static_dep_map {
43 const char *from;
44 const char *to;
45};
46
Rajendra Nayak6099dd32013-05-27 15:46:44 +053047static u32 cpu_suspend_state = PWRDM_POWER_OFF;
48
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030049static LIST_HEAD(pwrst_list);
50
51#ifdef CONFIG_SUSPEND
Rajendra Nayak5643aeb2010-08-02 13:18:18 +030052static int omap4_pm_suspend(void)
53{
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053054 struct power_state *pwrst;
55 int state, ret = 0;
56 u32 cpu_id = smp_processor_id();
57
58 /* Save current powerdomain state */
59 list_for_each_entry(pwrst, &pwrst_list, node) {
60 pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
Santosh Shilimkar3ba2a732011-06-06 14:33:29 +053061 pwrst->saved_logic_state = pwrdm_read_logic_retst(pwrst->pwrdm);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053062 }
63
64 /* Set targeted power domain states by suspend */
65 list_for_each_entry(pwrst, &pwrst_list, node) {
66 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Nishanth Menon46ba5522014-06-05 21:40:39 -050067 pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->next_logic_state);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053068 }
69
70 /*
71 * For MPUSS to hit power domain retention(CSWR or OSWR),
72 * CPU0 and CPU1 power domains need to be in OFF or DORMANT state,
73 * since CPU power domain CSWR is not supported by hardware
74 * Only master CPU follows suspend path. All other CPUs follow
75 * CPU hotplug path in system wide suspend. On OMAP4, CPU power
76 * domain CSWR is not supported by hardware.
77 * More details can be found in OMAP4430 TRM section 4.3.4.2.
78 */
Rajendra Nayak6099dd32013-05-27 15:46:44 +053079 omap4_enter_lowpower(cpu_id, cpu_suspend_state);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053080
81 /* Restore next powerdomain state */
82 list_for_each_entry(pwrst, &pwrst_list, node) {
83 state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
84 if (state > pwrst->next_state) {
Paul Walmsley7852ec02012-07-26 00:54:26 -060085 pr_info("Powerdomain (%s) didn't enter target state %d\n",
86 pwrst->pwrdm->name, pwrst->next_state);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053087 ret = -1;
88 }
89 omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
Santosh Shilimkar3ba2a732011-06-06 14:33:29 +053090 pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->saved_logic_state);
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053091 }
Rajendra Nayak60480092013-02-04 17:54:43 +053092 if (ret) {
Santosh Shilimkare44f9a72010-06-16 22:19:49 +053093 pr_crit("Could not enter target state in pm_suspend\n");
Rajendra Nayak60480092013-02-04 17:54:43 +053094 /*
95 * OMAP4 chip PM currently works only with certain (newer)
96 * versions of bootloaders. This is due to missing code in the
97 * kernel to properly reset and initialize some devices.
98 * Warn the user about the bootloader version being one of the
99 * possible causes.
100 * http://www.spinics.net/lists/arm-kernel/msg218641.html
101 */
102 pr_warn("A possible cause could be an old bootloader - try u-boot >= v2012.07\n");
103 } else {
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530104 pr_info("Successfully put all powerdomains to target state\n");
Rajendra Nayak60480092013-02-04 17:54:43 +0530105 }
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530106
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300107 return 0;
108}
Dave Gerlach2e4b62d2014-05-12 13:33:21 -0500109#else
110#define omap4_pm_suspend NULL
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300111#endif /* CONFIG_SUSPEND */
112
113static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
114{
115 struct power_state *pwrst;
116
117 if (!pwrdm->pwrsts)
118 return 0;
119
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530120 /*
121 * Skip CPU0 and CPU1 power domains. CPU1 is programmed
122 * through hotplug path and CPU0 explicitly programmed
123 * further down in the code path
124 */
Rajendra Nayak6099dd32013-05-27 15:46:44 +0530125 if (!strncmp(pwrdm->name, "cpu", 3)) {
126 if (IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE))
127 cpu_suspend_state = PWRDM_POWER_RET;
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530128 return 0;
Rajendra Nayak6099dd32013-05-27 15:46:44 +0530129 }
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530130
Tony Lindgrenf74297d2018-05-17 15:36:20 -0700131 /*
132 * Bootloader or kexec boot may have LOGICRETSTATE cleared
133 * for some domains. This is the case when kexec booting from
134 * Android kernels that support off mode for example.
135 * Make sure it's set at least for core and per, otherwise
136 * we currently will see lost GPIO interrupts for wlcore and
137 * smsc911x at least if per hits retention during idle.
138 */
139 if (!strncmp(pwrdm->name, "core", 4) ||
140 !strncmp(pwrdm->name, "l4per", 5) ||
141 !strncmp(pwrdm->name, "wkup", 4))
142 pwrdm_set_logic_retst(pwrdm, PWRDM_POWER_RET);
143
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300144 pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
145 if (!pwrst)
146 return -ENOMEM;
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530147
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300148 pwrst->pwrdm = pwrdm;
Nishanth Menonbd7593c2014-06-06 01:17:37 -0500149 pwrst->next_state = pwrdm_get_valid_lp_state(pwrdm, false,
150 PWRDM_POWER_RET);
151 pwrst->next_logic_state = pwrdm_get_valid_lp_state(pwrdm, true,
152 PWRDM_POWER_OFF);
Nishanth Menon46ba5522014-06-05 21:40:39 -0500153
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300154 list_add(&pwrst->node, &pwrst_list);
155
Santosh Shilimkare44f9a72010-06-16 22:19:49 +0530156 return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300157}
158
159/**
Santosh Shilimkar72826b92011-07-18 12:25:10 +0530160 * omap_default_idle - OMAP4 default ilde routine.'
161 *
162 * Implements OMAP4 memory, IO ordering requirements which can't be addressed
Paul Bolle62006322013-03-29 21:35:01 +0100163 * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPU_IDLE and
164 * by secondary CPU with CONFIG_CPU_IDLE.
Santosh Shilimkar72826b92011-07-18 12:25:10 +0530165 */
166static void omap_default_idle(void)
167{
Santosh Shilimkar72826b92011-07-18 12:25:10 +0530168 omap_do_wfi();
Santosh Shilimkar72826b92011-07-18 12:25:10 +0530169}
170
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500171/*
172 * The dynamic dependency between MPUSS -> MEMIF and
173 * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
174 * expected. The hardware recommendation is to enable static
175 * dependencies for these to avoid system lock ups or random crashes.
176 * The L4 wakeup depedency is added to workaround the OCP sync hardware
177 * BUG with 32K synctimer which lead to incorrect timer value read
178 * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
179 * are part of L4 wakeup clockdomain.
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300180 */
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500181static const struct static_dep_map omap4_static_dep_map[] = {
182 {.from = "mpuss_clkdm", .to = "l3_emif_clkdm"},
183 {.from = "mpuss_clkdm", .to = "l3_1_clkdm"},
184 {.from = "mpuss_clkdm", .to = "l3_2_clkdm"},
185 {.from = "ducati_clkdm", .to = "l3_1_clkdm"},
186 {.from = "ducati_clkdm", .to = "l3_2_clkdm"},
187 {.from = NULL} /* TERMINATION */
188};
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300189
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500190static const struct static_dep_map omap5_dra7_static_dep_map[] = {
191 {.from = "mpu_clkdm", .to = "emif_clkdm"},
192 {.from = NULL} /* TERMINATION */
193};
Santosh Shilimkar705814b2012-04-12 16:51:47 +0530194
195/**
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500196 * omap4plus_init_static_deps() - Initialize a static dependency map
197 * @map: Mapping of clock domains
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530198 */
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500199static inline int omap4plus_init_static_deps(const struct static_dep_map *map)
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530200{
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530201 int ret;
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500202 struct clockdomain *from, *to;
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530203
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500204 if (!map)
205 return 0;
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530206
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500207 while (map->from) {
208 from = clkdm_lookup(map->from);
209 to = clkdm_lookup(map->to);
210 if (!from || !to) {
211 pr_err("Failed lookup %s or %s for wakeup dependency\n",
212 map->from, map->to);
213 return -EINVAL;
214 }
215 ret = clkdm_add_wkdep(from, to);
216 if (ret) {
217 pr_err("Failed to add %s -> %s wakeup dependency(%d)\n",
218 map->from, map->to, ret);
219 return ret;
220 }
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530221
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500222 map++;
Javier Martinez Canillasae428a72015-09-17 15:38:05 +0200223 }
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500224
225 return 0;
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530226}
227
228/**
Nishanth Menonde70af42014-01-20 14:06:37 -0600229 * omap4_pm_init_early - Does early initialization necessary for OMAP4+ devices
230 *
231 * Initializes basic stuff for power management functionality.
232 */
233int __init omap4_pm_init_early(void)
234{
235 if (cpu_is_omap446x())
236 pm44xx_errata |= PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD;
237
Rajendra Nayak6099dd32013-05-27 15:46:44 +0530238 if (soc_is_omap54xx() || soc_is_dra7xx())
239 pm44xx_errata |= PM_OMAP4_CPU_OSWR_DISABLE;
240
Nishanth Menonde70af42014-01-20 14:06:37 -0600241 return 0;
242}
243
244/**
Santosh Shilimkar705814b2012-04-12 16:51:47 +0530245 * omap4_pm_init - Init routine for OMAP4+ devices
246 *
247 * Initializes all powerdomain and clockdomain target states
248 * and all PRCM settings.
249 * Return: Returns the error code returned by called functions.
250 */
251int __init omap4_pm_init(void)
252{
253 int ret = 0;
254
255 if (omap_rev() == OMAP4430_REV_ES1_0) {
256 WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
257 return -ENODEV;
258 }
259
260 pr_info("Power Management for TI OMAP4+ devices.\n");
261
Nishanth Menon9008d832014-10-21 15:22:28 -0500262 /*
263 * OMAP4 chip PM currently works only with certain (newer)
264 * versions of bootloaders. This is due to missing code in the
265 * kernel to properly reset and initialize some devices.
266 * http://www.spinics.net/lists/arm-kernel/msg218641.html
267 */
268 if (cpu_is_omap44xx())
269 pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
270
Santosh Shilimkar705814b2012-04-12 16:51:47 +0530271 ret = pwrdm_for_each(pwrdms_setup, NULL);
272 if (ret) {
273 pr_err("Failed to setup powerdomains.\n");
Santosh Shilimkar12f27822011-03-08 18:24:30 +0530274 goto err2;
275 }
276
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530277 if (cpu_is_omap44xx())
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500278 ret = omap4plus_init_static_deps(omap4_static_dep_map);
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530279 else if (soc_is_omap54xx() || soc_is_dra7xx())
Nishanth Menonb9f5fe62014-10-21 15:22:29 -0500280 ret = omap4plus_init_static_deps(omap5_dra7_static_dep_map);
Santosh Shilimkard2136bc2013-02-06 15:51:45 +0530281
282 if (ret) {
283 pr_err("Failed to initialise static dependencies.\n");
284 goto err2;
Santosh Shilimkar705814b2012-04-12 16:51:47 +0530285 }
286
Santosh Shilimkarb2b97622010-06-16 22:19:48 +0530287 ret = omap4_mpuss_init();
288 if (ret) {
289 pr_err("Failed to initialise OMAP4 MPUSS\n");
290 goto err2;
291 }
292
Paul Walmsley92206fd2012-02-02 02:38:50 -0700293 (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
Santosh Shilimkar3c507292011-01-05 22:03:17 +0530294
Dave Gerlach2e4b62d2014-05-12 13:33:21 -0500295 omap_common_suspend_init(omap4_pm_suspend);
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300296
Nicolas Pitreae940912011-12-19 03:03:58 -0500297 /* Overwrite the default cpu_do_idle() */
Nicolas Pitre0bcd24b2012-01-04 16:27:48 -0500298 arm_pm_idle = omap_default_idle;
Santosh Shilimkar72826b92011-07-18 12:25:10 +0530299
Santosh Shilimkar7abdb0e2016-11-07 16:50:11 -0700300 if (cpu_is_omap44xx() || soc_is_omap54xx())
Santosh Shilimkar705814b2012-04-12 16:51:47 +0530301 omap4_idle_init();
Santosh Shilimkar982726602011-08-16 17:31:40 +0530302
Rajendra Nayak5643aeb2010-08-02 13:18:18 +0300303err2:
304 return ret;
305}