aboutsummaryrefslogtreecommitdiffstats
path: root/arch/microblaze/kernel
diff options
context:
space:
mode:
authorMichal Simek <monstr@monstr.eu>2009-10-02 06:48:47 -0400
committerMichal Simek <monstr@monstr.eu>2009-12-14 02:40:08 -0500
commit42a2478b789cb1b4335909e0fecc721c07be7d90 (patch)
tree1769ac33d86287054af07bbae99dca61140e3364 /arch/microblaze/kernel
parentf40542532e96dda5506eb76badea322f2ae4731c (diff)
microblaze: GPIO reset support
Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch/microblaze/kernel')
-rw-r--r--arch/microblaze/kernel/Makefile2
-rw-r--r--arch/microblaze/kernel/reset.c138
-rw-r--r--arch/microblaze/kernel/setup.c29
3 files changed, 139 insertions, 30 deletions
diff --git a/arch/microblaze/kernel/Makefile b/arch/microblaze/kernel/Makefile
index d487729683de..fddd0c403d40 100644
--- a/arch/microblaze/kernel/Makefile
+++ b/arch/microblaze/kernel/Makefile
@@ -7,7 +7,7 @@ extra-y := head.o vmlinux.lds
7obj-y += exceptions.o \ 7obj-y += exceptions.o \
8 hw_exception_handler.o init_task.o intc.o irq.o of_device.o \ 8 hw_exception_handler.o init_task.o intc.o irq.o of_device.o \
9 of_platform.o process.o prom.o prom_parse.o ptrace.o \ 9 of_platform.o process.o prom.o prom_parse.o ptrace.o \
10 setup.o signal.o sys_microblaze.o timer.o traps.o 10 setup.o signal.o sys_microblaze.o timer.o traps.o reset.o
11 11
12obj-y += cpu/ 12obj-y += cpu/
13 13
diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
new file mode 100644
index 000000000000..ce74a6f436e3
--- /dev/null
+++ b/arch/microblaze/kernel/reset.c
@@ -0,0 +1,138 @@
1/*
2 * Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2009 PetaLogix
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/init.h>
11#include <linux/of_platform.h>
12#include <asm/prom.h>
13
14/* Trigger specific functions */
15#ifdef CONFIG_GPIOLIB
16
17#include <linux/of_gpio.h>
18
19static int handle; /* reset pin handle */
20
21static int of_reset_gpio_handle(void)
22{
23 int ret; /* variable which stored handle reset gpio pin */
24 struct device_node *root; /* root node */
25 struct device_node *gpio; /* gpio node */
26 struct of_gpio_chip *of_gc = NULL;
27 enum of_gpio_flags flags ;
28 const void *gpio_spec;
29
30 /* find out root node */
31 root = of_find_node_by_path("/");
32
33 /* give me handle for gpio node to be possible allocate pin */
34 ret = of_parse_phandles_with_args(root, "hard-reset-gpios",
35 "#gpio-cells", 0, &gpio, &gpio_spec);
36 if (ret) {
37 pr_debug("%s: can't parse gpios property\n", __func__);
38 goto err0;
39 }
40
41 of_gc = gpio->data;
42 if (!of_gc) {
43 pr_debug("%s: gpio controller %s isn't registered\n",
44 root->full_name, gpio->full_name);
45 ret = -ENODEV;
46 goto err1;
47 }
48
49 ret = of_gc->xlate(of_gc, root, gpio_spec, &flags);
50 if (ret < 0)
51 goto err1;
52
53 ret += of_gc->gc.base;
54err1:
55 of_node_put(gpio);
56err0:
57 pr_debug("%s exited with status %d\n", __func__, ret);
58 return ret;
59}
60
61void of_platform_reset_gpio_probe(void)
62{
63 int ret;
64 handle = of_reset_gpio_handle();
65
66 if (!gpio_is_valid(handle)) {
67 printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n",
68 handle, "reset");
69 }
70
71 ret = gpio_request(handle, "reset");
72 if (ret < 0) {
73 printk(KERN_INFO "GPIO pin is already allocated\n");
74 return;
75 }
76
77 /* get current setup value */
78 ret = gpio_get_value(handle);
79 /* FIXME maybe worth to perform any action */
80 pr_debug("Reset: Gpio output state: 0x%x\n", ret);
81
82 /* Setup GPIO as output */
83 ret = gpio_direction_output(handle, 0);
84 if (ret < 0)
85 goto err;
86
87 /* Setup output direction */
88 gpio_set_value(handle, 0);
89
90 printk(KERN_INFO "Registered reset device: %d\n", handle);
91 return;
92err:
93 gpio_free(handle);
94 return;
95}
96
97
98static void gpio_system_reset(void)
99{
100 gpio_set_value(handle, 1);
101}
102#else
103#define gpio_system_reset() do {} while (0)
104void of_platform_reset_gpio_probe(void)
105{
106 return;
107}
108#endif
109
110void machine_restart(char *cmd)
111{
112 printk(KERN_NOTICE "Machine restart...\n");
113 gpio_system_reset();
114 dump_stack();
115 while (1)
116 ;
117}
118
119void machine_shutdown(void)
120{
121 printk(KERN_NOTICE "Machine shutdown...\n");
122 while (1)
123 ;
124}
125
126void machine_halt(void)
127{
128 printk(KERN_NOTICE "Machine halt...\n");
129 while (1)
130 ;
131}
132
133void machine_power_off(void)
134{
135 printk(KERN_NOTICE "Machine power off...\n");
136 while (1)
137 ;
138}
diff --git a/arch/microblaze/kernel/setup.c b/arch/microblaze/kernel/setup.c
index 8c1e0f4dcf18..367ad330148e 100644
--- a/arch/microblaze/kernel/setup.c
+++ b/arch/microblaze/kernel/setup.c
@@ -186,32 +186,3 @@ static int microblaze_debugfs_init(void)
186} 186}
187arch_initcall(microblaze_debugfs_init); 187arch_initcall(microblaze_debugfs_init);
188#endif 188#endif
189
190void machine_restart(char *cmd)
191{
192 printk(KERN_NOTICE "Machine restart...\n");
193 dump_stack();
194 while (1)
195 ;
196}
197
198void machine_shutdown(void)
199{
200 printk(KERN_NOTICE "Machine shutdown...\n");
201 while (1)
202 ;
203}
204
205void machine_halt(void)
206{
207 printk(KERN_NOTICE "Machine halt...\n");
208 while (1)
209 ;
210}
211
212void machine_power_off(void)
213{
214 printk(KERN_NOTICE "Machine power off...\n");
215 while (1)
216 ;
217}