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> | |
42a2478b MS |
12 | |
13 | /* Trigger specific functions */ | |
14 | #ifdef CONFIG_GPIOLIB | |
15 | ||
16 | #include <linux/of_gpio.h> | |
17 | ||
18 | static int handle; /* reset pin handle */ | |
67bf8766 | 19 | static unsigned int reset_val; |
42a2478b | 20 | |
42a2478b MS |
21 | void of_platform_reset_gpio_probe(void) |
22 | { | |
23 | int ret; | |
fe9f6844 GL |
24 | handle = of_get_named_gpio(of_find_node_by_path("/"), |
25 | "hard-reset-gpios", 0); | |
42a2478b MS |
26 | |
27 | if (!gpio_is_valid(handle)) { | |
aaa5241e | 28 | pr_info("Skipping unavailable RESET gpio %d (%s)\n", |
42a2478b | 29 | handle, "reset"); |
191d5eca | 30 | return; |
42a2478b MS |
31 | } |
32 | ||
33 | ret = gpio_request(handle, "reset"); | |
34 | if (ret < 0) { | |
aaa5241e | 35 | pr_info("GPIO pin is already allocated\n"); |
42a2478b MS |
36 | return; |
37 | } | |
38 | ||
39 | /* get current setup value */ | |
67bf8766 | 40 | reset_val = gpio_get_value(handle); |
42a2478b | 41 | /* FIXME maybe worth to perform any action */ |
67bf8766 | 42 | pr_debug("Reset: Gpio output state: 0x%x\n", reset_val); |
42a2478b MS |
43 | |
44 | /* Setup GPIO as output */ | |
45 | ret = gpio_direction_output(handle, 0); | |
46 | if (ret < 0) | |
47 | goto err; | |
48 | ||
49 | /* Setup output direction */ | |
50 | gpio_set_value(handle, 0); | |
51 | ||
aaa5241e | 52 | pr_info("RESET: Registered gpio device: %d, current val: %d\n", |
67bf8766 | 53 | handle, reset_val); |
42a2478b MS |
54 | return; |
55 | err: | |
56 | gpio_free(handle); | |
57 | return; | |
58 | } | |
59 | ||
60 | ||
61 | static void gpio_system_reset(void) | |
62 | { | |
191d5eca SL |
63 | if (gpio_is_valid(handle)) |
64 | gpio_set_value(handle, 1 - reset_val); | |
65 | else | |
66 | pr_notice("Reset GPIO unavailable - halting!\n"); | |
42a2478b MS |
67 | } |
68 | #else | |
54ea21f0 MS |
69 | static void gpio_system_reset(void) |
70 | { | |
71 | pr_notice("No reset GPIO present - halting!\n"); | |
72 | } | |
73 | ||
42a2478b MS |
74 | void of_platform_reset_gpio_probe(void) |
75 | { | |
76 | return; | |
77 | } | |
78 | #endif | |
79 | ||
80 | void machine_restart(char *cmd) | |
81 | { | |
aaa5241e | 82 | pr_notice("Machine restart...\n"); |
42a2478b | 83 | gpio_system_reset(); |
42a2478b MS |
84 | while (1) |
85 | ; | |
86 | } | |
87 | ||
88 | void machine_shutdown(void) | |
89 | { | |
aaa5241e | 90 | pr_notice("Machine shutdown...\n"); |
42a2478b MS |
91 | while (1) |
92 | ; | |
93 | } | |
94 | ||
95 | void machine_halt(void) | |
96 | { | |
aaa5241e | 97 | pr_notice("Machine halt...\n"); |
42a2478b MS |
98 | while (1) |
99 | ; | |
100 | } | |
101 | ||
102 | void machine_power_off(void) | |
103 | { | |
aaa5241e | 104 | pr_notice("Machine power off...\n"); |
42a2478b MS |
105 | while (1) |
106 | ; | |
107 | } |