Merge tag 'lsk-v3.10-15.05-android' into develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / mfd / twl6030-poweroff.c
1 /*
2  * /drivers/mfd/twl6030-poweroff.c
3  *
4  * Power off device
5  *
6  * Copyright (C) 2011 Texas Instruments Corporation
7  *
8  * Written by Rajeev Kulkarni <rajeevk@ti.com>
9  *
10  * This file is subject to the terms and conditions of the GNU General
11  * Public License. See the file "COPYING" in the main directory of this
12  * archive for more details.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <linux/module.h>
25 #include <linux/pm.h>
26 #include <linux/i2c/twl.h>
27
28 #define APP_DEVOFF      (1<<0)
29 #define CON_DEVOFF      (1<<1)
30 #define MOD_DEVOFF      (1<<2)
31
32 void twl6030_poweroff(void)
33 {
34         u8 val = 0;
35         int err = 0;
36
37         err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val,
38                                   TWL6030_PHOENIX_DEV_ON);
39         if (err) {
40                 pr_warning("I2C error %d reading PHOENIX_DEV_ON\n", err);
41                 return;
42         }
43
44         val |= APP_DEVOFF | CON_DEVOFF | MOD_DEVOFF;
45
46         err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val,
47                                    TWL6030_PHOENIX_DEV_ON);
48
49         if (err) {
50                 pr_warning("I2C error %d writing PHOENIX_DEV_ON\n", err);
51                 return;
52         }
53
54         return;
55 }
56
57 static int __init twl6030_poweroff_init(void)
58 {
59         pm_power_off = twl6030_poweroff;
60
61         return 0;
62 }
63
64 static void __exit twl6030_poweroff_exit(void)
65 {
66         pm_power_off = NULL;
67 }
68
69 module_init(twl6030_poweroff_init);
70 module_exit(twl6030_poweroff_exit);
71
72 MODULE_DESCRIPTION("TLW6030 device power off");
73 MODULE_LICENSE("GPL");
74 MODULE_AUTHOR("Rajeev Kulkarni");