27 #include <linux/module.h>
34 static u8 twl4030_start_script_address = 0x2b;
36 #define PWR_P1_SW_EVENTS 0x10
37 #define PWR_DEVOFF (1 << 0)
38 #define SEQ_OFFSYNC (1 << 0)
40 #define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
41 #define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b)
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_S2A12 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)
73 #define DEV_GRP_OFFSET 0
75 #define REMAP_OFFSET 2
76 #define DEDICATED_OFFSET 3
81 #define DEV_GRP_SHIFT 5
82 #define DEV_GRP_MASK (7 << DEV_GRP_SHIFT)
86 #define TYPE_MASK (7 << TYPE_SHIFT)
88 #define TYPE2_MASK (3 << TYPE2_SHIFT)
91 #define SLEEP_STATE_SHIFT 0
92 #define SLEEP_STATE_MASK (0xf << SLEEP_STATE_SHIFT)
93 #define OFF_STATE_SHIFT 4
94 #define OFF_STATE_MASK (0xf << OFF_STATE_SHIFT)
96 static u8 res_config_addrs[] = {
141 static int __devinit twl4030_write_script_ins(
u8 address,
u16 pmb_message,
147 err = twl4030_write_script_byte(address++, pmb_message >> 8);
150 err = twl4030_write_script_byte(address++, pmb_message & 0xff);
153 err = twl4030_write_script_byte(address++, delay);
156 err = twl4030_write_script_byte(address++, next);
166 for (; len; len--, address++, script++) {
168 err = twl4030_write_script_ins(address,
175 err = twl4030_write_script_ins(address,
186 static int __devinit twl4030_config_wakeup3_sequence(
u8 address)
207 pr_err(
"TWL4030 wakeup sequence for P3 config error\n");
211 static int __devinit twl4030_config_wakeup12_sequence(
u8 address)
245 if (machine_is_omap_3430sdp() || machine_is_omap_ldp()) {
260 pr_err(
"TWL4030 wakeup sequence for P1 and P2" \
265 static int __devinit twl4030_config_sleep_sequence(
u8 address)
274 pr_err(
"TWL4030 sleep sequence config error\n");
279 static int __devinit twl4030_config_warmreset_sequence(
u8 address)
323 pr_err(
"TWL4030 warmreset seq config error\n");
336 pr_err(
"TWL4030 Resource %d does not exist\n",
341 rconfig_addr = res_config_addrs[rconfig->
resource];
347 pr_err(
"TWL4030 Resource %d group could not be read\n",
358 pr_err(
"TWL4030 failed to program devgroup\n");
367 pr_err(
"TWL4030 Resource %d type could not be read\n",
385 pr_err(
"TWL4030 failed to program resource type\n");
393 pr_err(
"TWL4030 Resource %d remap could not be read\n",
412 pr_err(
"TWL4030 failed to program remap\n");
427 pr_err(
"TWL4030 scripts too big error\n");
431 err = twl4030_write_script(address, tscript->
script, tscript->
size);
436 err = twl4030_config_warmreset_sequence(address);
441 err = twl4030_config_wakeup12_sequence(address);
447 err = twl4030_config_wakeup3_sequence(address);
453 pr_warning(
"TWL4030: Bad order of scripts (sleep "\
454 "script before wakeup) Leads to boot"\
455 "failure on some boards\n");
456 err = twl4030_config_sleep_sequence(address);
470 pr_err(
"twl4030: unable to unlock PROTECT_KEY\n");
478 pr_err(
"twl4030: unable to unlock PROTECT_KEY\n");
510 pr_err(
"TWL4030 Unable to relock registers\n");
527 pr_err(
"TWL4030 Unable to power off\n");
535 u8 val, address = twl4030_start_script_address;
549 for (i = 0; i < twl4030_scripts->
num; i++) {
550 err = load_twl4030_script(twl4030_scripts->
scripts[i], address);
553 address += twl4030_scripts->
scripts[
i]->size;
559 err = twl4030_configure_resource(resconfig);
573 pr_warning(
"TWL4030 Unable to read registers\n");
580 pr_err(
"TWL4030 Unable to setup SEQ_OFFSYNC\n");
592 pr_err(
"TWL4030 Unable to relock registers\n");
597 pr_err(
"TWL4030 Unable to unlock registers\n");
601 pr_err(
"TWL4030 failed to load scripts\n");
605 pr_err(
"TWL4030 failed to configure resource\n");