Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Igor Grinberg and committed by
Samuel Ortiz
26cc3ab9 aeb5032b

+42 -2
+40 -2
drivers/mfd/twl4030-power.c
··· 34 34 static u8 twl4030_start_script_address = 0x2b; 35 35 36 36 #define PWR_P1_SW_EVENTS 0x10 37 - #define PWR_DEVOFF (1<<0) 37 + #define PWR_DEVOFF (1 << 0) 38 + #define SEQ_OFFSYNC (1 << 0) 38 39 39 40 #define PHY_TO_OFF_PM_MASTER(p) (p - 0x36) 40 41 #define PHY_TO_OFF_PM_RECEIVER(p) (p - 0x5b) ··· 512 511 return err; 513 512 } 514 513 514 + /* 515 + * In master mode, start the power off sequence. 516 + * After a successful execution, TWL shuts down the power to the SoC 517 + * and all peripherals connected to it. 518 + */ 519 + void twl4030_power_off(void) 520 + { 521 + int err; 522 + 523 + err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, PWR_DEVOFF, 524 + TWL4030_PM_MASTER_P1_SW_EVENTS); 525 + if (err) 526 + pr_err("TWL4030 Unable to power off\n"); 527 + } 528 + 515 529 void __init twl4030_power_init(struct twl4030_power_data *twl4030_scripts) 516 530 { 517 531 int err = 0; 518 532 int i; 519 533 struct twl4030_resconfig *resconfig; 520 - u8 address = twl4030_start_script_address; 534 + u8 val, address = twl4030_start_script_address; 521 535 522 536 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 523 537 TWL4030_PM_MASTER_KEY_CFG1, ··· 564 548 } 565 549 } 566 550 551 + /* Board has to be wired properly to use this feature */ 552 + if (twl4030_scripts->use_poweroff && !pm_power_off) { 553 + /* Default for SEQ_OFFSYNC is set, lets ensure this */ 554 + err = twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &val, 555 + TWL4030_PM_MASTER_CFG_P123_TRANSITION); 556 + if (err) { 557 + pr_warning("TWL4030 Unable to read registers\n"); 558 + 559 + } else if (!(val & SEQ_OFFSYNC)) { 560 + val |= SEQ_OFFSYNC; 561 + err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, val, 562 + TWL4030_PM_MASTER_CFG_P123_TRANSITION); 563 + if (err) { 564 + pr_err("TWL4030 Unable to setup SEQ_OFFSYNC\n"); 565 + goto relock; 566 + } 567 + } 568 + 569 + pm_power_off = twl4030_power_off; 570 + } 571 + 572 + relock: 567 573 err = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, 568 574 TWL4030_PM_MASTER_PROTECT_KEY); 569 575 if (err)
+2
include/linux/i2c/twl.h
··· 652 652 unsigned num; 653 653 struct twl4030_resconfig *resource_config; 654 654 #define TWL4030_RESCONFIG_UNDEF ((u8)-1) 655 + bool use_poweroff; /* Board is wired for TWL poweroff */ 655 656 }; 656 657 657 658 extern void twl4030_power_init(struct twl4030_power_data *triton2_scripts); 658 659 extern int twl4030_remove_script(u8 flags); 660 + extern void twl4030_power_off(void); 659 661 660 662 struct twl4030_codec_data { 661 663 unsigned int digimic_delay; /* in ms */