diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2013-01-15 06:24:14 -0500 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2013-03-21 11:17:39 -0400 |
commit | 2655f51d0afd2087fb3e0e6a996610e06032d754 (patch) | |
tree | 21dd5114f9a5a89ecbab24cf98193f151e4bb9fb /drivers/power | |
parent | a937536b868b8369b98967929045f1df54234323 (diff) |
arm: vexpress: Move the poweroff/restart code to drivers/power/reset
This patch moves the arch/arm/mach-vexpress/reset.c functionality to
drivers/platform/reset/ and adds the necessary Kconfig wiring.
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Pawel Moll <pawel.moll@arm.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/reset/Kconfig | 7 | ||||
-rw-r--r-- | drivers/power/reset/Makefile | 3 | ||||
-rw-r--r-- | drivers/power/reset/vexpress-poweroff.c | 141 |
3 files changed, 150 insertions, 1 deletions
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 1ae65b822864..349e9ae8090a 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig | |||
@@ -30,3 +30,10 @@ config POWER_RESET_RESTART | |||
30 | Some boards don't actually have the ability to power off. | 30 | Some boards don't actually have the ability to power off. |
31 | Instead they restart, and u-boot holds the SoC until the | 31 | Instead they restart, and u-boot holds the SoC until the |
32 | user presses a key. u-boot then boots into Linux. | 32 | user presses a key. u-boot then boots into Linux. |
33 | |||
34 | config POWER_RESET_VEXPRESS | ||
35 | bool | ||
36 | depends on POWER_RESET | ||
37 | help | ||
38 | Power off and reset support for the ARM Ltd. Versatile | ||
39 | Express boards. | ||
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 0f317f50c56f..372807fd83f7 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o | 1 | obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o |
2 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o | 2 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o |
3 | obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o \ No newline at end of file | 3 | obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o |
4 | obj-$(CONFIG_POWER_RESET_VEXPRESS) += vexpress-poweroff.o | ||
diff --git a/drivers/power/reset/vexpress-poweroff.c b/drivers/power/reset/vexpress-poweroff.c new file mode 100644 index 000000000000..465923aa3819 --- /dev/null +++ b/drivers/power/reset/vexpress-poweroff.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License version 2 as | ||
4 | * published by the Free Software Foundation. | ||
5 | * | ||
6 | * This program is distributed in the hope that it will be useful, | ||
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
9 | * GNU General Public License for more details. | ||
10 | * | ||
11 | * Copyright (C) 2012 ARM Limited | ||
12 | */ | ||
13 | |||
14 | #include <linux/jiffies.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_device.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/stat.h> | ||
19 | #include <linux/vexpress.h> | ||
20 | |||
21 | static void vexpress_reset_do(struct device *dev, const char *what) | ||
22 | { | ||
23 | int err = -ENOENT; | ||
24 | struct vexpress_config_func *func = | ||
25 | vexpress_config_func_get_by_dev(dev); | ||
26 | |||
27 | if (func) { | ||
28 | unsigned long timeout; | ||
29 | |||
30 | err = vexpress_config_write(func, 0, 0); | ||
31 | |||
32 | timeout = jiffies + HZ; | ||
33 | while (time_before(jiffies, timeout)) | ||
34 | cpu_relax(); | ||
35 | } | ||
36 | |||
37 | dev_emerg(dev, "Unable to %s (%d)\n", what, err); | ||
38 | } | ||
39 | |||
40 | static struct device *vexpress_power_off_device; | ||
41 | |||
42 | void vexpress_power_off(void) | ||
43 | { | ||
44 | vexpress_reset_do(vexpress_power_off_device, "power off"); | ||
45 | } | ||
46 | |||
47 | static struct device *vexpress_restart_device; | ||
48 | |||
49 | void vexpress_restart(char str, const char *cmd) | ||
50 | { | ||
51 | vexpress_reset_do(vexpress_restart_device, "restart"); | ||
52 | } | ||
53 | |||
54 | static ssize_t vexpress_reset_active_show(struct device *dev, | ||
55 | struct device_attribute *attr, char *buf) | ||
56 | { | ||
57 | return sprintf(buf, "%d\n", vexpress_restart_device == dev); | ||
58 | } | ||
59 | |||
60 | static ssize_t vexpress_reset_active_store(struct device *dev, | ||
61 | struct device_attribute *attr, const char *buf, size_t count) | ||
62 | { | ||
63 | long value; | ||
64 | int err = kstrtol(buf, 0, &value); | ||
65 | |||
66 | if (!err && value) | ||
67 | vexpress_restart_device = dev; | ||
68 | |||
69 | return err ? err : count; | ||
70 | } | ||
71 | |||
72 | DEVICE_ATTR(active, S_IRUGO | S_IWUSR, vexpress_reset_active_show, | ||
73 | vexpress_reset_active_store); | ||
74 | |||
75 | |||
76 | enum vexpress_reset_func { FUNC_RESET, FUNC_SHUTDOWN, FUNC_REBOOT }; | ||
77 | |||
78 | static struct of_device_id vexpress_reset_of_match[] = { | ||
79 | { | ||
80 | .compatible = "arm,vexpress-reset", | ||
81 | .data = (void *)FUNC_RESET, | ||
82 | }, { | ||
83 | .compatible = "arm,vexpress-shutdown", | ||
84 | .data = (void *)FUNC_SHUTDOWN | ||
85 | }, { | ||
86 | .compatible = "arm,vexpress-reboot", | ||
87 | .data = (void *)FUNC_REBOOT | ||
88 | }, | ||
89 | {} | ||
90 | }; | ||
91 | |||
92 | static int vexpress_reset_probe(struct platform_device *pdev) | ||
93 | { | ||
94 | enum vexpress_reset_func func; | ||
95 | const struct of_device_id *match = | ||
96 | of_match_device(vexpress_reset_of_match, &pdev->dev); | ||
97 | |||
98 | if (match) | ||
99 | func = (enum vexpress_reset_func)match->data; | ||
100 | else | ||
101 | func = pdev->id_entry->driver_data; | ||
102 | |||
103 | switch (func) { | ||
104 | case FUNC_SHUTDOWN: | ||
105 | vexpress_power_off_device = &pdev->dev; | ||
106 | break; | ||
107 | case FUNC_RESET: | ||
108 | if (!vexpress_restart_device) | ||
109 | vexpress_restart_device = &pdev->dev; | ||
110 | device_create_file(&pdev->dev, &dev_attr_active); | ||
111 | break; | ||
112 | case FUNC_REBOOT: | ||
113 | vexpress_restart_device = &pdev->dev; | ||
114 | device_create_file(&pdev->dev, &dev_attr_active); | ||
115 | break; | ||
116 | }; | ||
117 | |||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | static const struct platform_device_id vexpress_reset_id_table[] = { | ||
122 | { .name = "vexpress-reset", .driver_data = FUNC_RESET, }, | ||
123 | { .name = "vexpress-shutdown", .driver_data = FUNC_SHUTDOWN, }, | ||
124 | { .name = "vexpress-reboot", .driver_data = FUNC_REBOOT, }, | ||
125 | {} | ||
126 | }; | ||
127 | |||
128 | static struct platform_driver vexpress_reset_driver = { | ||
129 | .probe = vexpress_reset_probe, | ||
130 | .driver = { | ||
131 | .name = "vexpress-reset", | ||
132 | .of_match_table = vexpress_reset_of_match, | ||
133 | }, | ||
134 | .id_table = vexpress_reset_id_table, | ||
135 | }; | ||
136 | |||
137 | static int __init vexpress_reset_init(void) | ||
138 | { | ||
139 | return platform_driver_register(&vexpress_reset_driver); | ||
140 | } | ||
141 | device_initcall(vexpress_reset_init); | ||