Skip to content

Commit 26cc3ab

Browse files
Igor GrinbergSamuel Ortiz
authored andcommitted
mfd: Add power off functionality to TWL
TWL family of PMICs, used in master mode, have a power off functionality. The resulting power off sequence shuts down all the SoC supplies, LDOs, etc. The sequence is described in the datasheets chapter "Power-Off Sequence". Note, that board must be wired correctly for the power off to work as expected. Signed-off-by: Igor Grinberg <grinberg@compulab.co.il> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent aeb5032 commit 26cc3ab

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎drivers/mfd/twl4030-power.c‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
static u8 twl4030_start_script_address = 0x2b;
3535

3636
#define PWR_P1_SW_EVENTS 0x10
37-
#define PWR_DEVOFF (1<<0)
37+
#define PWR_DEVOFF (1 << 0)
38+
#define SEQ_OFFSYNC (1 << 0)
3839

3940
#define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
4041
#define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b)
@@ -511,12 +512,27 @@ int twl4030_remove_script(u8 flags)
511512
return err;
512513
}
513514

515+
/*
516+
* In master mode, start the power off sequence.
517+
* After a successful execution, TWL shuts down the power to the SoC
518+
* and all peripherals connected to it.
519+
*/
520+
void twl4030_power_off(void)
521+
{
522+
int err;
523+
524+
err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, PWR_DEVOFF,
525+
TWL4030_PM_MASTER_P1_SW_EVENTS);
526+
if (err)
527+
pr_err("TWL4030 Unable to power off\n");
528+
}
529+
514530
void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts)
515531
{
516532
int err = 0;
517533
int i;
518534
struct twl4030_resconfig *resconfig;
519-
u8 address = twl4030_start_script_address;
535+
u8 val, address = twl4030_start_script_address;
520536

521537
err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
522538
TWL4030_PM_MASTER_KEY_CFG1,
@@ -548,6 +564,28 @@ void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts)
548564
}
549565
}
550566

567+
/* Board has to be wired properly to use this feature */
568+
if (twl4030_scripts->use_poweroff && !pm_power_off) {
569+
/* Default for SEQ_OFFSYNC is set, lets ensure this */
570+
err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val,
571+
TWL4030_PM_MASTER_CFG_P123_TRANSITION);
572+
if (err) {
573+
pr_warning("TWL4030 Unable to read registers\n");
574+
575+
} else if (!(val & SEQ_OFFSYNC)) {
576+
val |= SEQ_OFFSYNC;
577+
err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val,
578+
TWL4030_PM_MASTER_CFG_P123_TRANSITION);
579+
if (err) {
580+
pr_err("TWL4030 Unable to setup SEQ_OFFSYNC\n");
581+
goto relock;
582+
}
583+
}
584+
585+
pm_power_off = twl4030_power_off;
586+
}
587+
588+
relock:
551589
err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
552590
TWL4030_PM_MASTER_PROTECT_KEY);
553591
if (err)

‎include/linux/i2c/twl.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,12 @@ struct twl4030_power_data {
652652
unsigned num;
653653
struct twl4030_resconfig *resource_config;
654654
#define TWL4030_RESCONFIG_UNDEF ((u8)-1)
655+
bool use_poweroff; /* Board is wired for TWL poweroff */
655656
};
656657

657658
extern void twl4030_power_init(struct twl4030_power_data *triton2_scripts);
658659
extern int twl4030_remove_script(u8 flags);
660+
extern void twl4030_power_off(void);
659661

660662
struct twl4030_codec_data {
661663
unsigned int digimic_delay; /* in ms */

0 commit comments

Comments
 (0)