Commit | Line | Data |
---|---|---|
42a2478b MS |
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 | ||
19 | static int handle; /* reset pin handle */ | |
20 | ||
21 | static 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; | |
54 | err1: | |
55 | of_node_put(gpio); | |
56 | err0: | |
57 | pr_debug("%s exited with status %d\n", __func__, ret); | |
58 | return ret; | |
59 | } | |
60 | ||
61 | void 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 | ||
75375830 | 90 | printk(KERN_INFO "RESET: Registered gpio device: %d\n", handle); |
42a2478b MS |
91 | return; |
92 | err: | |
93 | gpio_free(handle); | |
94 | return; | |
95 | } | |
96 | ||
97 | ||
98 | static void gpio_system_reset(void) | |
99 | { | |
100 | gpio_set_value(handle, 1); | |
101 | } | |
102 | #else | |
103 | #define gpio_system_reset() do {} while (0) | |
104 | void of_platform_reset_gpio_probe(void) | |
105 | { | |
106 | return; | |
107 | } | |
108 | #endif | |
109 | ||
110 | void 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 | ||
119 | void machine_shutdown(void) | |
120 | { | |
121 | printk(KERN_NOTICE "Machine shutdown...\n"); | |
122 | while (1) | |
123 | ; | |
124 | } | |
125 | ||
126 | void machine_halt(void) | |
127 | { | |
128 | printk(KERN_NOTICE "Machine halt...\n"); | |
129 | while (1) | |
130 | ; | |
131 | } | |
132 | ||
133 | void machine_power_off(void) | |
134 | { | |
135 | printk(KERN_NOTICE "Machine power off...\n"); | |
136 | while (1) | |
137 | ; | |
138 | } |