blob: 0d72a8a8ce4d36a00ce23fcfbe297d6087854c0f [file] [log] [blame]
Paul Walmsleyad67ef62008-08-19 11:08:40 +03001/*
Paul Walmsleya64bb9c2010-12-21 21:05:14 -07002 * OMAP2/3/4 powerdomain control
Paul Walmsleyad67ef62008-08-19 11:08:40 +03003 *
Paul Walmsley72e06d02010-12-21 21:05:16 -07004 * Copyright (C) 2007-2008, 2010 Texas Instruments, Inc.
Paul Walmsley694606c2011-03-07 19:28:15 -07005 * Copyright (C) 2007-2011 Nokia Corporation
Paul Walmsleyad67ef62008-08-19 11:08:40 +03006 *
Paul Walmsley72e06d02010-12-21 21:05:16 -07007 * Paul Walmsley
Paul Walmsleyad67ef62008-08-19 11:08:40 +03008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
Paul Walmsley6e014782010-12-21 20:01:20 -070012 *
13 * XXX This should be moved to the mach-omap2/ directory at the earliest
14 * opportunity.
Paul Walmsleyad67ef62008-08-19 11:08:40 +030015 */
16
Paul Walmsley72e06d02010-12-21 21:05:16 -070017#ifndef __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
18#define __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
Paul Walmsleyad67ef62008-08-19 11:08:40 +030019
20#include <linux/types.h>
21#include <linux/list.h>
22
Paul Walmsley72e06d02010-12-21 21:05:16 -070023#include <linux/atomic.h>
Paul Walmsleyad67ef62008-08-19 11:08:40 +030024
Tony Lindgrence491cf2009-10-20 09:40:47 -070025#include <plat/cpu.h>
Paul Walmsleyad67ef62008-08-19 11:08:40 +030026
Kevin Hilman8f1bec22011-03-23 07:22:23 -070027#include "voltage.h"
28
Paul Walmsleyad67ef62008-08-19 11:08:40 +030029/* Powerdomain basic power states */
30#define PWRDM_POWER_OFF 0x0
31#define PWRDM_POWER_RET 0x1
32#define PWRDM_POWER_INACTIVE 0x2
33#define PWRDM_POWER_ON 0x3
34
Paul Walmsley2354eb52009-12-08 16:33:12 -070035#define PWRDM_MAX_PWRSTS 4
36
Paul Walmsleyad67ef62008-08-19 11:08:40 +030037/* Powerdomain allowable state bitfields */
Rajendra Nayakd3353e12010-05-18 20:24:01 -060038#define PWRSTS_ON (1 << PWRDM_POWER_ON)
Paul Walmsley694606c2011-03-07 19:28:15 -070039#define PWRSTS_INACTIVE (1 << PWRDM_POWER_INACTIVE)
40#define PWRSTS_RET (1 << PWRDM_POWER_RET)
Rajendra Nayakbb722f32010-09-27 14:02:56 -060041#define PWRSTS_OFF (1 << PWRDM_POWER_OFF)
Paul Walmsleyad67ef62008-08-19 11:08:40 +030042
Paul Walmsley694606c2011-03-07 19:28:15 -070043#define PWRSTS_OFF_ON (PWRSTS_OFF | PWRSTS_ON)
44#define PWRSTS_OFF_RET (PWRSTS_OFF | PWRSTS_RET)
45#define PWRSTS_RET_ON (PWRSTS_RET | PWRSTS_ON)
46#define PWRSTS_OFF_RET_ON (PWRSTS_OFF_RET | PWRSTS_ON)
Paul Walmsleyad67ef62008-08-19 11:08:40 +030047
48
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -060049/* Powerdomain flags */
50#define PWRDM_HAS_HDWR_SAR (1 << 0) /* hardware save-and-restore support */
Thara Gopinath3863c742009-12-08 16:33:15 -070051#define PWRDM_HAS_MPU_QUIRK (1 << 1) /* MPU pwr domain has MEM bank 0 bits
52 * in MEM bank 1 position. This is
53 * true for OMAP3430
54 */
Rajendra Nayak90dbc7b2010-05-18 20:24:03 -060055#define PWRDM_HAS_LOWPOWERSTATECHANGE (1 << 2) /*
56 * support to transition from a
57 * sleep state to a lower sleep
58 * state without waking up the
59 * powerdomain
60 */
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -060061
Paul Walmsleyad67ef62008-08-19 11:08:40 +030062/*
Abhijit Pagare38900c22010-01-26 20:12:52 -070063 * Number of memory banks that are power-controllable. On OMAP4430, the
64 * maximum is 5.
Paul Walmsleyad67ef62008-08-19 11:08:40 +030065 */
Abhijit Pagare38900c22010-01-26 20:12:52 -070066#define PWRDM_MAX_MEM_BANKS 5
Paul Walmsleyad67ef62008-08-19 11:08:40 +030067
Paul Walmsley8420bb12008-08-19 11:08:44 +030068/*
69 * Maximum number of clockdomains that can be associated with a powerdomain.
Abhijit Pagare38900c22010-01-26 20:12:52 -070070 * CORE powerdomain on OMAP4 is the worst case
Paul Walmsley8420bb12008-08-19 11:08:44 +030071 */
Abhijit Pagare38900c22010-01-26 20:12:52 -070072#define PWRDM_MAX_CLKDMS 9
Paul Walmsley8420bb12008-08-19 11:08:44 +030073
Paul Walmsleyad67ef62008-08-19 11:08:40 +030074/* XXX A completely arbitrary number. What is reasonable here? */
75#define PWRDM_TRANSITION_BAILOUT 100000
76
Paul Walmsley8420bb12008-08-19 11:08:44 +030077struct clockdomain;
Paul Walmsleyad67ef62008-08-19 11:08:40 +030078struct powerdomain;
79
Paul Walmsleyf0271d62010-01-26 20:13:02 -070080/**
81 * struct powerdomain - OMAP powerdomain
82 * @name: Powerdomain name
Kevin Hilman8f1bec22011-03-23 07:22:23 -070083 * @voltdm: voltagedomain containing this powerdomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -070084 * @prcm_offs: the address offset from CM_BASE/PRM_BASE
Paul Walmsleya64bb9c2010-12-21 21:05:14 -070085 * @prcm_partition: (OMAP4 only) the PRCM partition ID containing @prcm_offs
Paul Walmsleyf0271d62010-01-26 20:13:02 -070086 * @pwrsts: Possible powerdomain power states
87 * @pwrsts_logic_ret: Possible logic power states when pwrdm in RETENTION
88 * @flags: Powerdomain flags
89 * @banks: Number of software-controllable memory banks in this powerdomain
90 * @pwrsts_mem_ret: Possible memory bank pwrstates when pwrdm in RETENTION
91 * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON
92 * @pwrdm_clkdms: Clockdomains in this powerdomain
93 * @node: list_head linking all powerdomains
Kevin Hilmane69c22b2011-03-16 16:13:15 -070094 * @voltdm_node: list_head linking all powerdomains in a voltagedomain
Paul Walmsleyf0271d62010-01-26 20:13:02 -070095 * @state:
96 * @state_counter:
97 * @timer:
98 * @state_timer:
Paul Walmsleya64bb9c2010-12-21 21:05:14 -070099 *
100 * @prcm_partition possible values are defined in mach-omap2/prcm44xx.h.
Paul Walmsleyf0271d62010-01-26 20:13:02 -0700101 */
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300102struct powerdomain {
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300103 const char *name;
Kevin Hilman8f1bec22011-03-23 07:22:23 -0700104 union {
105 const char *name;
106 struct voltagedomain *ptr;
107 } voltdm;
Paul Walmsleye0594b42010-01-26 20:13:01 -0700108 const s16 prcm_offs;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300109 const u8 pwrsts;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300110 const u8 pwrsts_logic_ret;
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -0600111 const u8 flags;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300112 const u8 banks;
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300113 const u8 pwrsts_mem_ret[PWRDM_MAX_MEM_BANKS];
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300114 const u8 pwrsts_mem_on[PWRDM_MAX_MEM_BANKS];
Paul Walmsleya64bb9c2010-12-21 21:05:14 -0700115 const u8 prcm_partition;
Paul Walmsley8420bb12008-08-19 11:08:44 +0300116 struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS];
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300117 struct list_head node;
Kevin Hilmane69c22b2011-03-16 16:13:15 -0700118 struct list_head voltdm_node;
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300119 int state;
Paul Walmsley2354eb52009-12-08 16:33:12 -0700120 unsigned state_counter[PWRDM_MAX_PWRSTS];
Thara Gopinathcde08f82010-02-24 12:05:50 -0700121 unsigned ret_logic_off_counter;
122 unsigned ret_mem_off_counter[PWRDM_MAX_MEM_BANKS];
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300123
124#ifdef CONFIG_PM_DEBUG
125 s64 timer;
Paul Walmsley2354eb52009-12-08 16:33:12 -0700126 s64 state_timer[PWRDM_MAX_PWRSTS];
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300127#endif
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300128};
129
Rajendra Nayak3b1e8b22010-12-21 20:01:18 -0700130/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300131 * struct pwrdm_ops - Arch specific function implementations
Rajendra Nayak3b1e8b22010-12-21 20:01:18 -0700132 * @pwrdm_set_next_pwrst: Set the target power state for a pd
133 * @pwrdm_read_next_pwrst: Read the target power state set for a pd
134 * @pwrdm_read_pwrst: Read the current power state of a pd
135 * @pwrdm_read_prev_pwrst: Read the prev power state entered by the pd
136 * @pwrdm_set_logic_retst: Set the logic state in RET for a pd
137 * @pwrdm_set_mem_onst: Set the Memory state in ON for a pd
138 * @pwrdm_set_mem_retst: Set the Memory state in RET for a pd
139 * @pwrdm_read_logic_pwrst: Read the current logic state of a pd
140 * @pwrdm_read_prev_logic_pwrst: Read the previous logic state entered by a pd
141 * @pwrdm_read_logic_retst: Read the logic state in RET for a pd
142 * @pwrdm_read_mem_pwrst: Read the current memory state of a pd
143 * @pwrdm_read_prev_mem_pwrst: Read the previous memory state entered by a pd
144 * @pwrdm_read_mem_retst: Read the memory state in RET for a pd
145 * @pwrdm_clear_all_prev_pwrst: Clear all previous power states logged for a pd
146 * @pwrdm_enable_hdwr_sar: Enable Hardware Save-Restore feature for the pd
147 * @pwrdm_disable_hdwr_sar: Disable Hardware Save-Restore feature for a pd
148 * @pwrdm_set_lowpwrstchange: Enable pd transitions from a shallow to deep sleep
149 * @pwrdm_wait_transition: Wait for a pd state transition to complete
150 */
151struct pwrdm_ops {
152 int (*pwrdm_set_next_pwrst)(struct powerdomain *pwrdm, u8 pwrst);
153 int (*pwrdm_read_next_pwrst)(struct powerdomain *pwrdm);
154 int (*pwrdm_read_pwrst)(struct powerdomain *pwrdm);
155 int (*pwrdm_read_prev_pwrst)(struct powerdomain *pwrdm);
156 int (*pwrdm_set_logic_retst)(struct powerdomain *pwrdm, u8 pwrst);
157 int (*pwrdm_set_mem_onst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
158 int (*pwrdm_set_mem_retst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
159 int (*pwrdm_read_logic_pwrst)(struct powerdomain *pwrdm);
160 int (*pwrdm_read_prev_logic_pwrst)(struct powerdomain *pwrdm);
161 int (*pwrdm_read_logic_retst)(struct powerdomain *pwrdm);
162 int (*pwrdm_read_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
163 int (*pwrdm_read_prev_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
164 int (*pwrdm_read_mem_retst)(struct powerdomain *pwrdm, u8 bank);
165 int (*pwrdm_clear_all_prev_pwrst)(struct powerdomain *pwrdm);
166 int (*pwrdm_enable_hdwr_sar)(struct powerdomain *pwrdm);
167 int (*pwrdm_disable_hdwr_sar)(struct powerdomain *pwrdm);
168 int (*pwrdm_set_lowpwrstchange)(struct powerdomain *pwrdm);
169 int (*pwrdm_wait_transition)(struct powerdomain *pwrdm);
170};
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300171
Paul Walmsley129c65e2011-09-14 16:01:21 -0600172int pwrdm_register_platform_funcs(struct pwrdm_ops *custom_funcs);
173int pwrdm_register_pwrdms(struct powerdomain **pwrdm_list);
174int pwrdm_complete_init(void);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300175
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300176struct powerdomain *pwrdm_lookup(const char *name);
177
Peter 'p2' De Schrijvera23456e2008-10-15 18:13:47 +0300178int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
179 void *user);
Artem Bityutskiyee894b12009-10-01 10:01:55 +0300180int pwrdm_for_each_nolock(int (*fn)(struct powerdomain *pwrdm, void *user),
181 void *user);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300182
Paul Walmsley8420bb12008-08-19 11:08:44 +0300183int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm);
184int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm);
185int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
186 int (*fn)(struct powerdomain *pwrdm,
187 struct clockdomain *clkdm));
Kevin Hilman048a7032011-03-16 15:52:47 -0700188struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm);
Paul Walmsley8420bb12008-08-19 11:08:44 +0300189
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300190int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm);
191
192int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst);
193int pwrdm_read_next_pwrst(struct powerdomain *pwrdm);
Paul Walmsleyfecb4942009-01-27 19:12:50 -0700194int pwrdm_read_pwrst(struct powerdomain *pwrdm);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300195int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm);
196int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm);
197
198int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst);
199int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
200int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
201
202int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm);
203int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm);
Thara Gopinath1e3d0d22010-02-24 12:05:49 -0700204int pwrdm_read_logic_retst(struct powerdomain *pwrdm);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300205int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
206int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
Thara Gopinath1e3d0d22010-02-24 12:05:49 -0700207int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank);
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300208
Paul Walmsley0b7cbfb2008-06-25 18:09:37 -0600209int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm);
210int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm);
211bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm);
212
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300213int pwrdm_wait_transition(struct powerdomain *pwrdm);
214
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300215int pwrdm_state_switch(struct powerdomain *pwrdm);
216int pwrdm_clkdm_state_switch(struct clockdomain *clkdm);
217int pwrdm_pre_transition(void);
218int pwrdm_post_transition(void);
Manjunath Kondaiah G04aeae72010-10-08 09:58:35 -0700219int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm);
Tomi Valkeinenfc013872011-06-09 16:56:23 +0300220int pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
Paul Walmsley694606c2011-03-07 19:28:15 -0700221bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
Peter 'p2' De Schrijverba20bb12008-10-15 17:48:43 +0300222
Paul Walmsley81794882011-09-14 11:34:21 -0600223extern void omap242x_powerdomains_init(void);
224extern void omap243x_powerdomains_init(void);
Paul Walmsley6e014782010-12-21 20:01:20 -0700225extern void omap3xxx_powerdomains_init(void);
226extern void omap44xx_powerdomains_init(void);
227
Paul Walmsley72e06d02010-12-21 21:05:16 -0700228extern struct pwrdm_ops omap2_pwrdm_operations;
229extern struct pwrdm_ops omap3_pwrdm_operations;
230extern struct pwrdm_ops omap4_pwrdm_operations;
231
232/* Common Internal functions used across OMAP rev's */
233extern u32 omap2_pwrdm_get_mem_bank_onstate_mask(u8 bank);
234extern u32 omap2_pwrdm_get_mem_bank_retst_mask(u8 bank);
235extern u32 omap2_pwrdm_get_mem_bank_stst_mask(u8 bank);
236
237extern struct powerdomain wkup_omap2_pwrdm;
238extern struct powerdomain gfx_omap2_pwrdm;
239
240
Paul Walmsleyad67ef62008-08-19 11:08:40 +0300241#endif