powerdomain.h 8.9 KB
Newer Older
1
/*
2
 * OMAP2/3/4 powerdomain control
3
 *
4
 * Copyright (C) 2007-2008, 2010 Texas Instruments, Inc.
5
 * Copyright (C) 2007-2011 Nokia Corporation
6
 *
7
 * Paul Walmsley
8 9 10 11
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
12 13 14
 *
 * XXX This should be moved to the mach-omap2/ directory at the earliest
 * opportunity.
15 16
 */

17 18
#ifndef __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
#define __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
19 20 21 22

#include <linux/types.h>
#include <linux/list.h>

23
#include <linux/atomic.h>
24

25
#include <plat/cpu.h>
26

27 28
#include "voltage.h"

29 30 31 32 33 34
/* Powerdomain basic power states */
#define PWRDM_POWER_OFF		0x0
#define PWRDM_POWER_RET		0x1
#define PWRDM_POWER_INACTIVE	0x2
#define PWRDM_POWER_ON		0x3

35 36
#define PWRDM_MAX_PWRSTS	4

37
/* Powerdomain allowable state bitfields */
38
#define PWRSTS_ON		(1 << PWRDM_POWER_ON)
39 40
#define PWRSTS_INACTIVE		(1 << PWRDM_POWER_INACTIVE)
#define PWRSTS_RET		(1 << PWRDM_POWER_RET)
41
#define PWRSTS_OFF		(1 << PWRDM_POWER_OFF)
42

43 44 45 46
#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
#define PWRSTS_OFF_RET		(PWRSTS_OFF | PWRSTS_RET)
#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
#define PWRSTS_OFF_RET_ON	(PWRSTS_OFF_RET | PWRSTS_ON)
47 48


49 50
/* Powerdomain flags */
#define PWRDM_HAS_HDWR_SAR	(1 << 0) /* hardware save-and-restore support */
51 52 53 54
#define PWRDM_HAS_MPU_QUIRK	(1 << 1) /* MPU pwr domain has MEM bank 0 bits
					  * in MEM bank 1 position. This is
					  * true for OMAP3430
					  */
55 56 57 58 59 60
#define PWRDM_HAS_LOWPOWERSTATECHANGE	(1 << 2) /*
						  * support to transition from a
						  * sleep state to a lower sleep
						  * state without waking up the
						  * powerdomain
						  */
61

62
/*
63 64
 * Number of memory banks that are power-controllable.	On OMAP4430, the
 * maximum is 5.
65
 */
66
#define PWRDM_MAX_MEM_BANKS	5
67

68 69
/*
 * Maximum number of clockdomains that can be associated with a powerdomain.
70
 * CORE powerdomain on OMAP4 is the worst case
71
 */
72
#define PWRDM_MAX_CLKDMS	9
73

74 75 76
/* XXX A completely arbitrary number. What is reasonable here? */
#define PWRDM_TRANSITION_BAILOUT 100000

77
struct clockdomain;
78 79
struct powerdomain;

80 81 82
/**
 * struct powerdomain - OMAP powerdomain
 * @name: Powerdomain name
83
 * @voltdm: voltagedomain containing this powerdomain
84
 * @prcm_offs: the address offset from CM_BASE/PRM_BASE
85
 * @prcm_partition: (OMAP4 only) the PRCM partition ID containing @prcm_offs
86 87 88 89 90 91 92 93
 * @pwrsts: Possible powerdomain power states
 * @pwrsts_logic_ret: Possible logic power states when pwrdm in RETENTION
 * @flags: Powerdomain flags
 * @banks: Number of software-controllable memory banks in this powerdomain
 * @pwrsts_mem_ret: Possible memory bank pwrstates when pwrdm in RETENTION
 * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON
 * @pwrdm_clkdms: Clockdomains in this powerdomain
 * @node: list_head linking all powerdomains
94
 * @voltdm_node: list_head linking all powerdomains in a voltagedomain
95 96 97 98
 * @state:
 * @state_counter:
 * @timer:
 * @state_timer:
99 100
 *
 * @prcm_partition possible values are defined in mach-omap2/prcm44xx.h.
101
 */
102 103
struct powerdomain {
	const char *name;
104 105 106 107
	union {
		const char *name;
		struct voltagedomain *ptr;
	} voltdm;
108
	const s16 prcm_offs;
109 110
	const u8 pwrsts;
	const u8 pwrsts_logic_ret;
111
	const u8 flags;
112 113 114
	const u8 banks;
	const u8 pwrsts_mem_ret[PWRDM_MAX_MEM_BANKS];
	const u8 pwrsts_mem_on[PWRDM_MAX_MEM_BANKS];
115
	const u8 prcm_partition;
116
	struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS];
117
	struct list_head node;
118
	struct list_head voltdm_node;
119
	int state;
120
	unsigned state_counter[PWRDM_MAX_PWRSTS];
121 122
	unsigned ret_logic_off_counter;
	unsigned ret_mem_off_counter[PWRDM_MAX_MEM_BANKS];
123 124 125

#ifdef CONFIG_PM_DEBUG
	s64 timer;
126
	s64 state_timer[PWRDM_MAX_PWRSTS];
127
#endif
128 129
};

130
/**
L
Lucas De Marchi 已提交
131
 * struct pwrdm_ops - Arch specific function implementations
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
 * @pwrdm_set_next_pwrst: Set the target power state for a pd
 * @pwrdm_read_next_pwrst: Read the target power state set for a pd
 * @pwrdm_read_pwrst: Read the current power state of a pd
 * @pwrdm_read_prev_pwrst: Read the prev power state entered by the pd
 * @pwrdm_set_logic_retst: Set the logic state in RET for a pd
 * @pwrdm_set_mem_onst: Set the Memory state in ON for a pd
 * @pwrdm_set_mem_retst: Set the Memory state in RET for a pd
 * @pwrdm_read_logic_pwrst: Read the current logic state of a pd
 * @pwrdm_read_prev_logic_pwrst: Read the previous logic state entered by a pd
 * @pwrdm_read_logic_retst: Read the logic state in RET for a pd
 * @pwrdm_read_mem_pwrst: Read the current memory state of a pd
 * @pwrdm_read_prev_mem_pwrst: Read the previous memory state entered by a pd
 * @pwrdm_read_mem_retst: Read the memory state in RET for a pd
 * @pwrdm_clear_all_prev_pwrst: Clear all previous power states logged for a pd
 * @pwrdm_enable_hdwr_sar: Enable Hardware Save-Restore feature for the pd
 * @pwrdm_disable_hdwr_sar: Disable Hardware Save-Restore feature for a pd
 * @pwrdm_set_lowpwrstchange: Enable pd transitions from a shallow to deep sleep
 * @pwrdm_wait_transition: Wait for a pd state transition to complete
 */
struct pwrdm_ops {
	int	(*pwrdm_set_next_pwrst)(struct powerdomain *pwrdm, u8 pwrst);
	int	(*pwrdm_read_next_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_read_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_read_prev_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_set_logic_retst)(struct powerdomain *pwrdm, u8 pwrst);
	int	(*pwrdm_set_mem_onst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
	int	(*pwrdm_set_mem_retst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
	int	(*pwrdm_read_logic_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_read_prev_logic_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_read_logic_retst)(struct powerdomain *pwrdm);
	int	(*pwrdm_read_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
	int	(*pwrdm_read_prev_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
	int	(*pwrdm_read_mem_retst)(struct powerdomain *pwrdm, u8 bank);
	int	(*pwrdm_clear_all_prev_pwrst)(struct powerdomain *pwrdm);
	int	(*pwrdm_enable_hdwr_sar)(struct powerdomain *pwrdm);
	int	(*pwrdm_disable_hdwr_sar)(struct powerdomain *pwrdm);
	int	(*pwrdm_set_lowpwrstchange)(struct powerdomain *pwrdm);
	int	(*pwrdm_wait_transition)(struct powerdomain *pwrdm);
};
171

172 173 174
int pwrdm_register_platform_funcs(struct pwrdm_ops *custom_funcs);
int pwrdm_register_pwrdms(struct powerdomain **pwrdm_list);
int pwrdm_complete_init(void);
175 176 177

struct powerdomain *pwrdm_lookup(const char *name);

178 179
int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
			void *user);
180 181
int pwrdm_for_each_nolock(int (*fn)(struct powerdomain *pwrdm, void *user),
			void *user);
182

183 184 185 186 187
int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm);
int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm);
int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
			 int (*fn)(struct powerdomain *pwrdm,
				   struct clockdomain *clkdm));
188
struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm);
189

190 191 192 193
int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm);

int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst);
int pwrdm_read_next_pwrst(struct powerdomain *pwrdm);
194
int pwrdm_read_pwrst(struct powerdomain *pwrdm);
195 196 197 198 199 200 201 202 203
int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm);
int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm);

int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst);
int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);

int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm);
int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm);
204
int pwrdm_read_logic_retst(struct powerdomain *pwrdm);
205 206
int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
207
int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank);
208

209 210 211 212
int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm);
int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm);
bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm);

213 214
int pwrdm_wait_transition(struct powerdomain *pwrdm);

215 216 217 218
int pwrdm_state_switch(struct powerdomain *pwrdm);
int pwrdm_clkdm_state_switch(struct clockdomain *clkdm);
int pwrdm_pre_transition(void);
int pwrdm_post_transition(void);
219
int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm);
220
u32 pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
221
bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
222

223 224
extern void omap242x_powerdomains_init(void);
extern void omap243x_powerdomains_init(void);
225 226 227
extern void omap3xxx_powerdomains_init(void);
extern void omap44xx_powerdomains_init(void);

228 229 230 231 232 233 234 235 236 237 238 239 240
extern struct pwrdm_ops omap2_pwrdm_operations;
extern struct pwrdm_ops omap3_pwrdm_operations;
extern struct pwrdm_ops omap4_pwrdm_operations;

/* Common Internal functions used across OMAP rev's */
extern u32 omap2_pwrdm_get_mem_bank_onstate_mask(u8 bank);
extern u32 omap2_pwrdm_get_mem_bank_retst_mask(u8 bank);
extern u32 omap2_pwrdm_get_mem_bank_stst_mask(u8 bank);

extern struct powerdomain wkup_omap2_pwrdm;
extern struct powerdomain gfx_omap2_pwrdm;


241
#endif