blob: bab4c8330ef4f3f165ad2992d9660776fb0e3c41 [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>
Michal Simek42a24782009-10-02 12:48:47 +020012
13/* Trigger specific functions */
14#ifdef CONFIG_GPIOLIB
15
16#include <linux/of_gpio.h>
17
18static int handle; /* reset pin handle */
Michal Simek67bf8762009-10-29 10:12:59 +010019static unsigned int reset_val;
Michal Simek42a24782009-10-02 12:48:47 +020020
Michal Simek42a24782009-10-02 12:48:47 +020021void of_platform_reset_gpio_probe(void)
22{
23 int ret;
Grant Likelyfe9f6842011-12-12 09:25:56 -070024 handle = of_get_named_gpio(of_find_node_by_path("/"),
25 "hard-reset-gpios", 0);
Michal Simek42a24782009-10-02 12:48:47 +020026
27 if (!gpio_is_valid(handle)) {
Michal Simekaaa52412012-10-04 14:24:58 +020028 pr_info("Skipping unavailable RESET gpio %d (%s)\n",
Michal Simek42a24782009-10-02 12:48:47 +020029 handle, "reset");
Stephan Linz191d5ec2012-06-20 22:36:37 +020030 return;
Michal Simek42a24782009-10-02 12:48:47 +020031 }
32
33 ret = gpio_request(handle, "reset");
34 if (ret < 0) {
Michal Simekaaa52412012-10-04 14:24:58 +020035 pr_info("GPIO pin is already allocated\n");
Michal Simek42a24782009-10-02 12:48:47 +020036 return;
37 }
38
39 /* get current setup value */
Michal Simek67bf8762009-10-29 10:12:59 +010040 reset_val = gpio_get_value(handle);
Michal Simek42a24782009-10-02 12:48:47 +020041 /* FIXME maybe worth to perform any action */
Michal Simek67bf8762009-10-29 10:12:59 +010042 pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
Michal Simek42a24782009-10-02 12:48:47 +020043
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
Michal Simekaaa52412012-10-04 14:24:58 +020052 pr_info("RESET: Registered gpio device: %d, current val: %d\n",
Michal Simek67bf8762009-10-29 10:12:59 +010053 handle, reset_val);
Michal Simek42a24782009-10-02 12:48:47 +020054 return;
55err:
56 gpio_free(handle);
57 return;
58}
59
60
61static void gpio_system_reset(void)
62{
Stephan Linz191d5ec2012-06-20 22:36:37 +020063 if (gpio_is_valid(handle))
64 gpio_set_value(handle, 1 - reset_val);
65 else
66 pr_notice("Reset GPIO unavailable - halting!\n");
Michal Simek42a24782009-10-02 12:48:47 +020067}
68#else
Michal Simek54ea21f2012-05-28 09:56:40 +020069static void gpio_system_reset(void)
70{
71 pr_notice("No reset GPIO present - halting!\n");
72}
73
Michal Simek42a24782009-10-02 12:48:47 +020074void of_platform_reset_gpio_probe(void)
75{
76 return;
77}
78#endif
79
80void machine_restart(char *cmd)
81{
Michal Simekaaa52412012-10-04 14:24:58 +020082 pr_notice("Machine restart...\n");
Michal Simek42a24782009-10-02 12:48:47 +020083 gpio_system_reset();
Michal Simek42a24782009-10-02 12:48:47 +020084 while (1)
85 ;
86}
87
88void machine_shutdown(void)
89{
Michal Simekaaa52412012-10-04 14:24:58 +020090 pr_notice("Machine shutdown...\n");
Michal Simek42a24782009-10-02 12:48:47 +020091 while (1)
92 ;
93}
94
95void machine_halt(void)
96{
Michal Simekaaa52412012-10-04 14:24:58 +020097 pr_notice("Machine halt...\n");
Michal Simek42a24782009-10-02 12:48:47 +020098 while (1)
99 ;
100}
101
102void machine_power_off(void)
103{
Michal Simekaaa52412012-10-04 14:24:58 +0200104 pr_notice("Machine power off...\n");
Michal Simek42a24782009-10-02 12:48:47 +0200105 while (1)
106 ;
107}