blob: 2e5079ab53d22f061dd1d1d1e1c992652d74b881 [file] [log] [blame]
Michal Simek42a24782009-10-02 12:48:47 +02001/*
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 */
Michal Simek67bf8762009-10-29 10:12:59 +010020static unsigned int reset_val;
Michal Simek42a24782009-10-02 12:48:47 +020021
Michal Simek42a24782009-10-02 12:48:47 +020022void of_platform_reset_gpio_probe(void)
23{
24 int ret;
Grant Likelyfe9f6842011-12-12 09:25:56 -070025 handle = of_get_named_gpio(of_find_node_by_path("/"),
26 "hard-reset-gpios", 0);
Michal Simek42a24782009-10-02 12:48:47 +020027
28 if (!gpio_is_valid(handle)) {
Michal Simekaaa52412012-10-04 14:24:58 +020029 pr_info("Skipping unavailable RESET gpio %d (%s)\n",
Michal Simek42a24782009-10-02 12:48:47 +020030 handle, "reset");
Stephan Linz191d5ec2012-06-20 22:36:37 +020031 return;
Michal Simek42a24782009-10-02 12:48:47 +020032 }
33
34 ret = gpio_request(handle, "reset");
35 if (ret < 0) {
Michal Simekaaa52412012-10-04 14:24:58 +020036 pr_info("GPIO pin is already allocated\n");
Michal Simek42a24782009-10-02 12:48:47 +020037 return;
38 }
39
40 /* get current setup value */
Michal Simek67bf8762009-10-29 10:12:59 +010041 reset_val = gpio_get_value(handle);
Michal Simek42a24782009-10-02 12:48:47 +020042 /* FIXME maybe worth to perform any action */
Michal Simek67bf8762009-10-29 10:12:59 +010043 pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
Michal Simek42a24782009-10-02 12:48:47 +020044
45 /* Setup GPIO as output */
46 ret = gpio_direction_output(handle, 0);
47 if (ret < 0)
48 goto err;
49
50 /* Setup output direction */
51 gpio_set_value(handle, 0);
52
Michal Simekaaa52412012-10-04 14:24:58 +020053 pr_info("RESET: Registered gpio device: %d, current val: %d\n",
Michal Simek67bf8762009-10-29 10:12:59 +010054 handle, reset_val);
Michal Simek42a24782009-10-02 12:48:47 +020055 return;
56err:
57 gpio_free(handle);
58 return;
59}
60
61
62static void gpio_system_reset(void)
63{
Stephan Linz191d5ec2012-06-20 22:36:37 +020064 if (gpio_is_valid(handle))
65 gpio_set_value(handle, 1 - reset_val);
66 else
67 pr_notice("Reset GPIO unavailable - halting!\n");
Michal Simek42a24782009-10-02 12:48:47 +020068}
69#else
70#define gpio_system_reset() do {} while (0)
71void of_platform_reset_gpio_probe(void)
72{
73 return;
74}
75#endif
76
77void machine_restart(char *cmd)
78{
Michal Simekaaa52412012-10-04 14:24:58 +020079 pr_notice("Machine restart...\n");
Michal Simek42a24782009-10-02 12:48:47 +020080 gpio_system_reset();
Michal Simek42a24782009-10-02 12:48:47 +020081 while (1)
82 ;
83}
84
85void machine_shutdown(void)
86{
Michal Simekaaa52412012-10-04 14:24:58 +020087 pr_notice("Machine shutdown...\n");
Michal Simek42a24782009-10-02 12:48:47 +020088 while (1)
89 ;
90}
91
92void machine_halt(void)
93{
Michal Simekaaa52412012-10-04 14:24:58 +020094 pr_notice("Machine halt...\n");
Michal Simek42a24782009-10-02 12:48:47 +020095 while (1)
96 ;
97}
98
99void machine_power_off(void)
100{
Michal Simekaaa52412012-10-04 14:24:58 +0200101 pr_notice("Machine power off...\n");
Michal Simek42a24782009-10-02 12:48:47 +0200102 while (1)
103 ;
104}