diff options
author | Laxman Dewangan <ldewangan@nvidia.com> | 2013-12-20 08:24:00 -0500 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-12-23 20:20:37 -0500 |
commit | 56fb8de53e20a853e1a919bf9fb25148ef7560cb (patch) | |
tree | ea837ff715f4e627905f7af969079a29f6fbeb41 /drivers | |
parent | 0c59cc7a68741008dbc571648ca1f32764ba6ff8 (diff) |
power: reset: Add as3722 power-off driver
ams AS3722 supports the power off functionality to turn off system.
This commit adds power off driver for ams AS3722.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/power/reset/Kconfig | 6 | ||||
-rw-r--r-- | drivers/power/reset/Makefile | 1 | ||||
-rw-r--r-- | drivers/power/reset/as3722-poweroff.c | 96 |
3 files changed, 103 insertions, 0 deletions
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 9b3ea535b472..6d452a78b19c 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig | |||
@@ -6,6 +6,12 @@ menuconfig POWER_RESET | |||
6 | 6 | ||
7 | Say Y here to enable board reset and power off | 7 | Say Y here to enable board reset and power off |
8 | 8 | ||
9 | config POWER_RESET_AS3722 | ||
10 | bool "ams AS3722 power-off driver" | ||
11 | depends on MFD_AS3722 && POWER_RESET | ||
12 | help | ||
13 | This driver supports turning off board via a ams AS3722 power-off. | ||
14 | |||
9 | config POWER_RESET_GPIO | 15 | config POWER_RESET_GPIO |
10 | bool "GPIO power-off driver" | 16 | bool "GPIO power-off driver" |
11 | depends on OF_GPIO && POWER_RESET | 17 | depends on OF_GPIO && POWER_RESET |
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 3e6ed88725ac..a5b4a77d1a41 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-$(CONFIG_POWER_RESET_AS3722) += as3722-poweroff.o | ||
1 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o | 2 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o |
2 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o | 3 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o |
3 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o | 4 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o |
diff --git a/drivers/power/reset/as3722-poweroff.c b/drivers/power/reset/as3722-poweroff.c new file mode 100644 index 000000000000..684971199bd3 --- /dev/null +++ b/drivers/power/reset/as3722-poweroff.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Power off driver for ams AS3722 device. | ||
3 | * | ||
4 | * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved. | ||
5 | * | ||
6 | * Author: Laxman Dewangan <ldewangan@nvidia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms and conditions of the GNU General Public License, | ||
10 | * version 2, as published by the Free Software Foundation. | ||
11 | * | ||
12 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
15 | * more details. | ||
16 | */ | ||
17 | |||
18 | #include <linux/mfd/as3722.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/of_device.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/slab.h> | ||
24 | |||
25 | struct as3722_poweroff { | ||
26 | struct device *dev; | ||
27 | struct as3722 *as3722; | ||
28 | }; | ||
29 | |||
30 | static struct as3722_poweroff *as3722_pm_poweroff; | ||
31 | |||
32 | static void as3722_pm_power_off(void) | ||
33 | { | ||
34 | int ret; | ||
35 | |||
36 | if (!as3722_pm_poweroff) { | ||
37 | pr_err("AS3722 poweroff is not initialised\n"); | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | ret = as3722_update_bits(as3722_pm_poweroff->as3722, | ||
42 | AS3722_RESET_CONTROL_REG, AS3722_POWER_OFF, AS3722_POWER_OFF); | ||
43 | if (ret < 0) | ||
44 | dev_err(as3722_pm_poweroff->dev, | ||
45 | "RESET_CONTROL_REG update failed, %d\n", ret); | ||
46 | } | ||
47 | |||
48 | static int as3722_poweroff_probe(struct platform_device *pdev) | ||
49 | { | ||
50 | struct as3722_poweroff *as3722_poweroff; | ||
51 | struct device_node *np = pdev->dev.parent->of_node; | ||
52 | |||
53 | if (!np) | ||
54 | return -EINVAL; | ||
55 | |||
56 | if (!of_property_read_bool(np, "ams,system-power-controller")) | ||
57 | return 0; | ||
58 | |||
59 | as3722_poweroff = devm_kzalloc(&pdev->dev, sizeof(*as3722_poweroff), | ||
60 | GFP_KERNEL); | ||
61 | if (!as3722_poweroff) | ||
62 | return -ENOMEM; | ||
63 | |||
64 | as3722_poweroff->as3722 = dev_get_drvdata(pdev->dev.parent); | ||
65 | as3722_poweroff->dev = &pdev->dev; | ||
66 | as3722_pm_poweroff = as3722_poweroff; | ||
67 | if (!pm_power_off) | ||
68 | pm_power_off = as3722_pm_power_off; | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int as3722_poweroff_remove(struct platform_device *pdev) | ||
74 | { | ||
75 | if (pm_power_off == as3722_pm_power_off) | ||
76 | pm_power_off = NULL; | ||
77 | as3722_pm_poweroff = NULL; | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | static struct platform_driver as3722_poweroff_driver = { | ||
83 | .driver = { | ||
84 | .name = "as3722-power-off", | ||
85 | .owner = THIS_MODULE, | ||
86 | }, | ||
87 | .probe = as3722_poweroff_probe, | ||
88 | .remove = as3722_poweroff_remove, | ||
89 | }; | ||
90 | |||
91 | module_platform_driver(as3722_poweroff_driver); | ||
92 | |||
93 | MODULE_DESCRIPTION("Power off driver for ams AS3722 PMIC Device"); | ||
94 | MODULE_ALIAS("platform:as3722-power-off"); | ||
95 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
96 | MODULE_LICENSE("GPL v2"); | ||