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>
29 #include <linux/platform_device.h>
31 #include <asm/mach-types.h>
33 static u8 triton_next_free_address = 0x2b;
35 #define PWR_P1_SW_EVENTS 0x10
36 #define PWR_DEVOFF (1<<0)
38 #define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
39 #define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b)
41 #define NUM_OF_RESOURCES 28
43 /* resource - hfclk */
44 #define R_HFCLKOUT_DEV_GRP PHY_TO_OFF_PM_RECEIVER(0xe6)
47 #define R_P1_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x46)
48 #define R_P2_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x47)
49 #define R_P3_SW_EVENTS PHY_TO_OFF_PM_MASTER(0x48)
50 #define R_CFG_P1_TRANSITION PHY_TO_OFF_PM_MASTER(0x36)
51 #define R_CFG_P2_TRANSITION PHY_TO_OFF_PM_MASTER(0x37)
52 #define R_CFG_P3_TRANSITION PHY_TO_OFF_PM_MASTER(0x38)
54 #define LVL_WAKEUP 0x08
56 #define ENABLE_WARMRESET (1<<4)
58 #define END_OF_SCRIPT 0x3f
60 #define R_SEQ_ADD_A2S PHY_TO_OFF_PM_MASTER(0x55)
61 #define R_SEQ_ADD_SA12 PHY_TO_OFF_PM_MASTER(0x56)
62 #define R_SEQ_ADD_S2A3 PHY_TO_OFF_PM_MASTER(0x57)
63 #define R_SEQ_ADD_WARM PHY_TO_OFF_PM_MASTER(0x58)
64 #define R_MEMORY_ADDRESS PHY_TO_OFF_PM_MASTER(0x59)
65 #define R_MEMORY_DATA PHY_TO_OFF_PM_MASTER(0x5a)
67 #define R_PROTECT_KEY 0x0E
71 /* resource configuration registers */
73 #define DEVGROUP_OFFSET 0
76 static u8 res_config_addrs[] = {
87 [RES_VINTANA1] = 0x3f,
88 [RES_VINTANA2] = 0x43,
93 [RES_VUSB_1V5] = 0x71,
94 [RES_VUSB_1V8] = 0x74,
95 [RES_VUSB_3V1] = 0x77,
98 [RES_NRES_PWRON] = 0x82,
101 [RES_HFCLKOUT] = 0x8b,
102 [RES_32KCLKOUT] = 0x8e,
104 [RES_Main_Ref] = 0x94,
107 static int __init twl4030_write_script_byte(u8 address, u8 byte)
111 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
113 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, byte,
119 static int __init twl4030_write_script_ins(u8 address, u16 pmb_message,
125 err |= twl4030_write_script_byte(address++, pmb_message >> 8);
126 err |= twl4030_write_script_byte(address++, pmb_message & 0xff);
127 err |= twl4030_write_script_byte(address++, delay);
128 err |= twl4030_write_script_byte(address++, next);
133 static int __init twl4030_write_script(u8 address, struct twl4030_ins *script,
138 for (; len; len--, address++, script++) {
140 err |= twl4030_write_script_ins(address,
145 err |= twl4030_write_script_ins(address,
154 static int __init config_wakeup3_sequence(u8 address)
159 /* Set SLEEP to ACTIVE SEQ address for P3 */
160 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
163 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
166 printk(KERN_ERR "TWL4030 wakeup sequence for P3" \
172 static int __init config_wakeup12_sequence(u8 address)
176 /* Set SLEEP to ACTIVE SEQ address for P1 and P2 */
177 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
180 /* P1/P2/P3 LVL_WAKEUP should be on LEVEL */
181 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
183 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, LVL_WAKEUP,
186 if (machine_is_omap_3430sdp() || machine_is_omap_ldp()) {
188 /* Disabling AC charger effect on sleep-active transitions */
189 err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &data,
190 R_CFG_P1_TRANSITION);
192 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, data ,
193 R_CFG_P1_TRANSITION);
197 printk(KERN_ERR "TWL4030 wakeup sequence for P1 and P2" \
203 static int __init config_sleep_sequence(u8 address)
208 * CLKREQ is pulled high on the 2430SDP, therefore, we need to take
209 * it out of the HFCLKOUT DEV_GRP for P1 else HFCLKOUT can't be stopped.
212 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
213 0x20, R_HFCLKOUT_DEV_GRP);
215 /* Set ACTIVE to SLEEP SEQ address in T2 memory*/
216 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
220 printk(KERN_ERR "TWL4030 sleep sequence config error\n");
225 static int __init config_warmreset_sequence(u8 address)
231 /* Set WARM RESET SEQ address for P1 */
232 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, address,
235 /* P1/P2/P3 enable WARMRESET */
236 err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
238 rd_data |= ENABLE_WARMRESET;
239 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
242 err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
244 rd_data |= ENABLE_WARMRESET;
245 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
248 err |= twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &rd_data,
250 rd_data |= ENABLE_WARMRESET;
251 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, rd_data,
256 "TWL4030 warmreset seq config error\n");
260 void twl4030_configure_resource(struct twl4030_resconfig *rconfig)
265 if (rconfig->resource > NUM_OF_RESOURCES) {
267 "TWL4030 Resource %d does not exist\n",
272 rconfig_addr = res_config_addrs[rconfig->resource];
274 /* Set resource group */
276 if (rconfig->devgroup >= 0)
277 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
278 rconfig->devgroup << 5,
279 rconfig_addr + DEVGROUP_OFFSET);
281 /* Set resource types */
283 if (twl4030_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER,
285 rconfig_addr + TYPE_OFFSET) < 0) {
287 "TWL4030 Resource %d type could not read\n",
292 if (rconfig->type >= 0) {
294 type |= rconfig->type;
297 if (rconfig->type2 >= 0) {
299 type |= rconfig->type2 << 3;
302 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER,
303 type, rconfig_addr + TYPE_OFFSET);
307 static int __init load_triton_script(struct twl4030_script *tscript)
309 u8 address = triton_next_free_address;
312 err = twl4030_write_script(address, tscript->script, tscript->size);
316 triton_next_free_address += tscript->size;
318 if (tscript->flags & TRITON_WRST_SCRIPT)
319 err |= config_warmreset_sequence(address);
321 if (tscript->flags & TRITON_WAKEUP12_SCRIPT)
322 err |= config_wakeup12_sequence(address);
324 if (tscript->flags & TRITON_WAKEUP3_SCRIPT)
325 err |= config_wakeup3_sequence(address);
327 if (tscript->flags & TRITON_SLEEP_SCRIPT)
328 err |= config_sleep_sequence(address);
333 void __init twl4030_power_init(struct twl4030_power_data *triton2_scripts)
337 struct twl4030_resconfig *resconfig;
339 err = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_1,
341 err |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_2,
345 "TWL4030 Unable to unlock registers\n");
347 for (i = 0; i < triton2_scripts->size; i++) {
348 err = load_triton_script(triton2_scripts->scripts[i]);
353 resconfig = triton2_scripts->resource_config;
355 while (resconfig->resource) {
356 twl4030_configure_resource(resconfig);
361 if (twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, R_PROTECT_KEY))
363 "TWL4030 Unable to relock registers\n");