summaryrefstree
path: root/kernel/arch/arm64/mach-exynos/include/mach/exynos-powermode.h
blob: 8f703c1c6cb898d230fb7cda2d7dcf0c0565848a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
171
172
173
174
175
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com/
 *
 * EXYNOS - PMU(Power Management Unit) support
 *
 * 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.
*/

#ifndef __EXYNOS_POWERMODE_H
#define __EXYNOS_POWERMODE_H __FILE__

#include <asm/io.h>

/* system power down configuration */
enum sys_powerdown {
	SYS_AFTR,
	SYS_STOP,
	SYS_DSTOP,
	SYS_DSTOP_PSR,
	SYS_LPD,
	SYS_LPA,
	SYS_ALPA,
	SYS_SLEEP,
	NUM_SYS_POWERDOWN,
};

struct exynos_pmu_conf {
	void __iomem *reg;
	unsigned int val[NUM_SYS_POWERDOWN];
};

/* SFR bit control to enter system power down */
struct sfr_bit_ctrl {
	void __iomem	*reg;
	unsigned int	mask;
	unsigned int	val;
};

struct sfr_save {
	void __iomem	*reg;
	unsigned int	val;
};

#define SFR_CTRL(_reg, _mask, _val)	\
	{				\
		.reg	= _reg,		\
		.mask	= _mask,	\
		.val	= _val,		\
	}

#define SFR_SAVE(_reg)			\
	{				\
		.reg	= _reg,		\
	}

/* setting SFR helper function */
static inline void exynos_set_sfr(struct sfr_bit_ctrl *ptr, int count)
{
	unsigned int tmp;

	for (; count > 0; count--, ptr++) {
		tmp = __raw_readl(ptr->reg);
		__raw_writel((tmp & ~ptr->mask) | ptr->val, ptr->reg);
	}
}

static inline void exynos_save_sfr(struct sfr_save *ptr, int count)
{
	for (; count > 0; count--, ptr++)
		ptr->val = __raw_readl(ptr->reg);
}

static inline void exynos_restore_sfr(struct sfr_save *ptr, int count)
{
	for (; count > 0; count--, ptr++)
		__raw_writel(ptr->val, ptr->reg);
}

/* power mode check flag */
#define EXYNOS_CHECK_DIDLE	0xBAD00000
#define EXYNOS_CHECK_LPA	0xABAD0000
#define EXYNOS_CHECK_DSTOP	0xABAE0000
#define EXYNOS_CHECK_SLEEP	0x00000BAD

/* system power down function */
extern void exynos_prepare_sys_powerdown(enum sys_powerdown mode);
extern void exynos_wakeup_sys_powerdown(enum sys_powerdown mode, bool early_wakeup);
extern bool exynos_sys_powerdown_enabled(void);

/* functions for cpuidle */
extern int determine_lpm(void);
extern int enter_c2(unsigned int cpu, int index, int *sub_state);
extern void wakeup_from_c2(unsigned int cpu);

/* cpuidle profile state */
#define C2_STATE		0x1
#define LPM_STATE		0x2

#define LPM_SUB_STATE_OFFSET	24
#define LPM_SUB_STATE		(0xF << LPM_SUB_STATE_OFFSET)
#define C2_SUB_STATE_OFFSET	16
#define C2_SUB_STATE		(0xF << C2_SUB_STATE_OFFSET)
#define MAJOR_STATE		(0xF)

#define SUB_STATE_OFFSET	16
#define SUB_STATE		(0xF << SUB_STATE_OFFSET)
#define CPD_STATE		(1 << SUB_STATE_OFFSET)
#define LPC_STATE		(2 << SUB_STATE_OFFSET)

/* cpuidle profile helper function */
#ifdef CONFIG_CPU_IDLE_EXYNOS
extern void lpa_blocking_counter(int);
#else
static inline void lpa_blocking_counter(int blocker)
{
	return;
}
#endif

/* Max length of check register list */
#define LIST_MAX_LENGTH	20

/* register check */
struct check_reg {
	void __iomem	*reg;
	unsigned int	check_bit;
};

static inline int check_reg_status(struct check_reg *list, unsigned int count)
{
	unsigned int i, tmp;

	for (i = 0; i < count; i++) {
		if (!list[i].reg)
			return 0;

		tmp = __raw_readl(list[i].reg);
		if (tmp & list[i].check_bit)
			return -EBUSY;
	}

	return 0;
}

/* functions for LPC */
#if defined(CONFIG_PWM_SAMSUNG)
extern int pwm_check_enable_cnt(void);
#else
static inline int pwm_check_enable_cnt(void)
{
	return 0;
}
#endif

#ifdef CONFIG_SERIAL_SAMSUNG
extern void s3c24xx_serial_fifo_wait(void);
#else
static inline void s3c24xx_serial_fifo_wait(void) { }
#endif

#ifdef CONFIG_PM_DEVFREQ
extern int is_dll_on(void);
#else
static inline int is_dll_on(void)
{
	return -EINVAL;
}
#endif

#define EXYNOS_SS_LPC_INDEX		('L' + 'P' + 'C')		/* 223 */

#endif /* __EXYNOS_POWERMODE_H */