aboutsummaryrefslogtreecommitdiffstats
path: root/arch/microblaze
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
parentf40542532e96dda5506eb76badea322f2ae4731c (diff)
microblaze: GPIO reset support
Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch/microblaze')
-rw-r--r--arch/microblaze/include/asm/setup.h2
-rw-r--r--arch/microblaze/kernel/Makefile2
-rw-r--r--arch/microblaze/kernel/reset.c138
-rw-r--r--arch/microblaze/kernel/setup.c29
-rw-r--r--arch/microblaze/platform/generic/system.dts28
-rw-r--r--arch/microblaze/platform/platform.c2
6 files changed, 171 insertions, 30 deletions
diff --git a/arch/microblaze/include/asm/setup.h b/arch/microblaze/include/asm/setup.h
index ed67c9ed15b..7f31394985e 100644
--- a/arch/microblaze/include/asm/setup.h
+++ b/arch/microblaze/include/asm/setup.h
@@ -35,6 +35,8 @@ extern void mmu_reset(void);
35extern void early_console_reg_tlb_alloc(unsigned int addr); 35extern void early_console_reg_tlb_alloc(unsigned int addr);
36# endif /* CONFIG_MMU */ 36# endif /* CONFIG_MMU */
37 37
38extern void of_platform_reset_gpio_probe(void);
39
38void time_init(void); 40void time_init(void);
39void init_IRQ(void); 41void init_IRQ(void);
40void machine_early_init(const char *cmdline, unsigned int ram, 42void machine_early_init(const char *cmdline, unsigned int ram,
diff --git a/arch/microblaze/kernel/Makefile b/arch/microblaze/kernel/Makefile
index d487729683d..fddd0c403d4 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 00000000000..ce74a6f436e
--- /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 8c1e0f4dcf1..367ad330148 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}
diff --git a/arch/microblaze/platform/generic/system.dts b/arch/microblaze/platform/generic/system.dts
index 29993f62b30..e00da8971c3 100644
--- a/arch/microblaze/platform/generic/system.dts
+++ b/arch/microblaze/platform/generic/system.dts
@@ -32,6 +32,7 @@
32 #address-cells = <1>; 32 #address-cells = <1>;
33 #size-cells = <1>; 33 #size-cells = <1>;
34 compatible = "xlnx,microblaze"; 34 compatible = "xlnx,microblaze";
35 hard-reset-gpios = <&LEDs_8Bit 2 1>;
35 model = "testing"; 36 model = "testing";
36 DDR2_SDRAM: memory@90000000 { 37 DDR2_SDRAM: memory@90000000 {
37 device_type = "memory"; 38 device_type = "memory";
@@ -261,6 +262,33 @@
261 xlnx,is-dual = <0x0>; 262 xlnx,is-dual = <0x0>;
262 xlnx,tri-default = <0xffffffff>; 263 xlnx,tri-default = <0xffffffff>;
263 xlnx,tri-default-2 = <0xffffffff>; 264 xlnx,tri-default-2 = <0xffffffff>;
265 #gpio-cells = <2>;
266 gpio-controller;
267 } ;
268
269 gpio-leds {
270 compatible = "gpio-leds";
271
272 heartbeat {
273 label = "Heartbeat";
274 gpios = <&LEDs_8Bit 4 1>;
275 linux,default-trigger = "heartbeat";
276 };
277
278 yellow {
279 label = "Yellow";
280 gpios = <&LEDs_8Bit 5 1>;
281 };
282
283 red {
284 label = "Red";
285 gpios = <&LEDs_8Bit 6 1>;
286 };
287
288 green {
289 label = "Green";
290 gpios = <&LEDs_8Bit 7 1>;
291 };
264 } ; 292 } ;
265 RS232_Uart_1: serial@84000000 { 293 RS232_Uart_1: serial@84000000 {
266 clock-frequency = <125000000>; 294 clock-frequency = <125000000>;
diff --git a/arch/microblaze/platform/platform.c b/arch/microblaze/platform/platform.c
index 56e0234fa34..5b89b58c5ae 100644
--- a/arch/microblaze/platform/platform.c
+++ b/arch/microblaze/platform/platform.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/of_platform.h> 14#include <linux/of_platform.h>
15#include <asm/prom.h> 15#include <asm/prom.h>
16#include <asm/setup.h>
16 17
17static struct of_device_id xilinx_of_bus_ids[] __initdata = { 18static struct of_device_id xilinx_of_bus_ids[] __initdata = {
18 { .compatible = "simple-bus", }, 19 { .compatible = "simple-bus", },
@@ -26,6 +27,7 @@ static struct of_device_id xilinx_of_bus_ids[] __initdata = {
26static int __init microblaze_device_probe(void) 27static int __init microblaze_device_probe(void)
27{ 28{
28 of_platform_bus_probe(NULL, xilinx_of_bus_ids, NULL); 29 of_platform_bus_probe(NULL, xilinx_of_bus_ids, NULL);
30 of_platform_reset_gpio_probe();
29 return 0; 31 return 0;
30} 32}
31device_initcall(microblaze_device_probe); 33device_initcall(microblaze_device_probe);