2 * linux/drivers/i2c/chips/twl4030-power.c
4 * Handle TWL4030 Power initialization
6 * Copyright (C) 2008 Nokia Corporation
7 * Copyright (C) 2006 Texas Instruments, Inc
9 * Written by Kalle Jokiniemi
10 * Peter De Schrijver <peter.de-schrijver@nokia.com>
12 * This file is subject to the terms and conditions of the GNU General
13 * Public License. See the file "COPYING" in the main directory of this
14 * archive for more details.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/module.h>
28 #include <linux/i2c/twl4030.h>
30 #include <asm/mach-types.h>
32 #define PWR_P1_SW_EVENTS 0x10
33 #define PWR_DEVOFF (1<<0)
35 #define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
36 #define PHY_TO_OFF_PM_RECIEVER(p) (p - 0x5b)
38 /* resource - hfclk */
39 #define R_HFCLKOUT_DEV_GRP PHY_TO_OFF_PM_RECIEVER(0xe6)
42 #define R_P1_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x46)
43 #define R_P2_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x47)
44 #define R_P3_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x48)
45 #define R_CFG_P1_TRANSITION PHY_TO_OFF_PM_MASTER(0x36)
46 #define R_CFG_P2_TRANSITION PHY_TO_OFF_PM_MASTER(0x37)
47 #define R_CFG_P3_TRANSITION PHY_TO_OFF_PM_MASTER(0x38)
49 #define LVL_WAKEUP 0x08
51 #define ENABLE_WARMRESET (1<<4)
55 #define END_OF_SCRIPT 0x3f
57 #define R_SEQ_ADD_A2S PHY_TO_OFF_PM_MASTER(0x55)
58 #define R_SEQ_ADD_SA12 PHY_TO_OFF_PM_MASTER(0x56)
59 #define R_SEQ_ADD_S2A3 PHY_TO_OFF_PM_MASTER(0x57)
60 #define R_SEQ_ADD_WARM PHY_TO_OFF_PM_MASTER(0x58)
61 #define R_MEMORY_ADDRESS PHY_TO_OFF_PM_MASTER(0x59)
62 #define R_MEMORY_DATA PHY_TO_OFF_PM_MASTER(0x5a)
64 /* Power bus message definitions */
66 #define DEV_GRP_NULL 0x0
67 #define DEV_GRP_P1 0x1
68 #define DEV_GRP_P2 0x2
69 #define DEV_GRP_P3 0x4
71 #define RES_GRP_RES 0x0
72 #define RES_GRP_PP 0x1
73 #define RES_GRP_RC 0x2
74 #define RES_GRP_PP_RC 0x3
75 #define RES_GRP_PR 0x4
76 #define RES_GRP_PP_PR 0x5
77 #define RES_GRP_RC_PR 0x6
78 #define RES_GRP_ALL 0x7
80 #define RES_TYPE2_R0 0x0
82 #define RES_TYPE_ALL 0x7
84 #define RES_STATE_WRST 0xF
85 #define RES_STATE_ACTIVE 0xE
86 #define RES_STATE_SLEEP 0x8
87 #define RES_STATE_OFF 0x0
90 * Power Bus Message Format
92 * Broadcast Message (16 Bits)
93 * DEV_GRP[15:13] MT[12] RES_GRP[11:9] RES_TYPE2[8:7] RES_TYPE[6:4]
96 * Singular Message (16 Bits)
97 * DEV_GRP[15:13] MT[12] RES_ID[11:4] RES_STATE[3:0]
101 #define MSG_BROADCAST(devgrp, grp, type, type2, state) \
102 (devgrp << 13 | 1 << 12 | grp << 9 | type2 << 7 | type << 4 | state)
104 #define MSG_SINGULAR(devgrp, id, state) \
105 (devgrp << 13 | 0 << 12 | id << 4 | state)
107 #define R_PROTECT_KEY 0x0E
117 #define CONFIG_DISABLE_HFCLK 1
119 #if defined(CONFIG_MACH_OMAP_3430SDP) || defined(CONFIG_MACH_OMAP_3430LABRADOR)
121 struct triton_ins sleep_on_seq[] __initdata = {
122 {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_OFF), 4},
123 {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_OFF), 2},
124 #ifdef CONFIG_DISABLE_HFCLK
125 {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_OFF), 3},
126 {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_OFF), 3},
127 #endif /* #ifdef CONFIG_DISABLE_HFCLK */
130 struct triton_ins sleep_off_seq[] __initdata = {
131 #ifndef CONFIG_DISABLE_HFCLK
132 {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 4},
133 {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 2},
135 {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_ACTIVE), 0x30},
136 {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_ACTIVE), 0x30},
137 {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_ACTIVE), 0x37},
138 {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 3},
139 #endif /* #ifndef CONFIG_DISABLE_HFCLK */
142 struct triton_ins t2_wrst_seq[] __initdata = {
143 {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_OFF), 2},
144 {MSG_SINGULAR(DEV_GRP_P1, 0xf, RES_STATE_WRST), 15},
145 {MSG_SINGULAR(DEV_GRP_P1, 0x10, RES_STATE_WRST), 15},
146 {MSG_SINGULAR(DEV_GRP_P1, 0x7, RES_STATE_WRST), 0x60},
147 {MSG_SINGULAR(DEV_GRP_P1, 0x19, RES_STATE_ACTIVE), 2},
148 {MSG_SINGULAR(DEV_GRP_NULL, 0x1b, RES_STATE_ACTIVE), 2},
151 struct triton_ins sleep_on_seq[] __initdata = {
152 {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_RC, RES_TYPE_ALL, RES_TYPE2_R0,
153 RES_STATE_SLEEP), 4},
154 {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, RES_TYPE_ALL, RES_TYPE2_R0,
155 RES_STATE_SLEEP), 4},
158 struct triton_ins sleep_off_seq[] __initdata = {
159 {MSG_SINGULAR(DEV_GRP_NULL, 0x17, RES_STATE_ACTIVE), 0x30},
160 {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_PP_PR, RES_TYPE_ALL, RES_TYPE2_R0,
161 RES_STATE_ACTIVE), 0x37},
162 {MSG_BROADCAST(DEV_GRP_NULL, RES_GRP_ALL, RES_TYPE_ALL, RES_TYPE2_R0,
163 RES_STATE_ACTIVE), 0x2},
166 struct triton_ins t2_wrst_seq[] __initdata = { };
170 static int __init twl4030_write_script_byte(u8 address, u8 byte)
174 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
176 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, byte,
182 static int __init twl4030_write_script_ins(u8 address, u16 pmb_message,
188 err |= twl4030_write_script_byte(address++, pmb_message >> 8);
189 err |= twl4030_write_script_byte(address++, pmb_message & 0xff);
190 err |= twl4030_write_script_byte(address++, delay);
191 err |= twl4030_write_script_byte(address++, next);
196 static int __init twl4030_write_script(u8 address, struct triton_ins *script,
201 for (; len; len--, address++, script++) {
203 err |= twl4030_write_script_ins(address,
208 err |= twl4030_write_script_ins(address,
217 static int __init config_sleep_wake_sequence(void)
222 * CLKREQ is pulled high on the 2430SDP, therefore, we need to take
223 * it out of the HFCLKOUT DEV_GRP for P1 else HFCLKOUT can't be stopped.
226 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
227 0x20, R_HFCLKOUT_DEV_GRP);
229 /* Set ACTIVE to SLEEP SEQ address in T2 memory*/
230 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x2B,
233 /* Set SLEEP to ACTIVE SEQ address for P1 and P2 */
234 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x2F,
237 /* Set SLEEP to ACTIVE SEQ address for P3 */
238 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x2F,
241 /* Install Active->Sleep (A2S) sequence */
242 err |= twl4030_write_script(0x2B, sleep_on_seq,
243 ARRAY_SIZE(sleep_on_seq));
245 /* Install Sleep->Active (S2A) sequence */
246 err |= twl4030_write_script(0x2F, sleep_off_seq,
247 ARRAY_SIZE(sleep_off_seq));
249 if (machine_is_omap_3430sdp() || machine_is_omap_ldp()) {
251 /* Disabling AC charger effect on sleep-active transitions */
252 err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data,
253 R_CFG_P1_TRANSITION);
255 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data ,
256 R_CFG_P1_TRANSITION);
259 /* P1/P2/P3 LVL_WAKEUP should be on LEVEL */
260 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
262 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
264 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
268 printk(KERN_ERR "TWL4030 sleep-wake sequence config error\n");
274 /* Programming the WARMRESET Sequence on TRITON */
275 static int __init config_warmreset_sequence(void)
281 if (!ARRAY_SIZE(t2_wrst_seq))
284 /* Set WARM RESET SEQ address for P1 */
285 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x38,
288 /* Install Warm Reset sequence */
289 e |= twl4030_write_script(0x38, t2_wrst_seq,
290 ARRAY_SIZE(t2_wrst_seq));
292 /* P1/P2/P3 enable WARMRESET */
293 e |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
295 rd_data |= ENABLE_WARMRESET;
296 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
299 e |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
301 rd_data |= ENABLE_WARMRESET;
302 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
305 e |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
307 rd_data |= ENABLE_WARMRESET;
308 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
313 "TWL4030 Power Companion Warmreset seq config error\n");
317 static int __init twl4030_power_init(void)
321 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_1,
323 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_2,
329 err = config_sleep_wake_sequence();
333 err = config_warmreset_sequence();
337 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, R_PROTECT_KEY);
343 module_init(twl4030_power_init);