2 * Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2009 PetaLogix
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
10 #include <linux/init.h>
11 #include <linux/of_platform.h>
14 /* Trigger specific functions */
17 #include <linux/of_gpio.h>
19 static int handle
; /* reset pin handle */
20 static unsigned int reset_val
;
22 static int of_reset_gpio_handle(void)
24 int ret
; /* variable which stored handle reset gpio pin */
25 struct device_node
*root
; /* root node */
26 struct device_node
*gpio
; /* gpio node */
29 const void *gpio_spec
;
31 /* find out root node */
32 root
= of_find_node_by_path("/");
34 /* give me handle for gpio node to be possible allocate pin */
35 ret
= of_parse_phandles_with_args(root
, "hard-reset-gpios",
36 "#gpio-cells", 0, &gpio
, &gpio_spec
);
38 pr_debug("%s: can't parse gpios property\n", __func__
);
42 gc
= of_node_to_gpiochip(gpio
);
44 pr_debug("%s: gpio controller %s isn't registered\n",
45 root
->full_name
, gpio
->full_name
);
50 ret
= gc
->of_xlate(gc
, root
, gpio_spec
, &flags
);
58 pr_debug("%s exited with status %d\n", __func__
, ret
);
62 void of_platform_reset_gpio_probe(void)
65 handle
= of_reset_gpio_handle();
67 if (!gpio_is_valid(handle
)) {
68 printk(KERN_INFO
"Skipping unavailable RESET gpio %d (%s)\n",
72 ret
= gpio_request(handle
, "reset");
74 printk(KERN_INFO
"GPIO pin is already allocated\n");
78 /* get current setup value */
79 reset_val
= gpio_get_value(handle
);
80 /* FIXME maybe worth to perform any action */
81 pr_debug("Reset: Gpio output state: 0x%x\n", reset_val
);
83 /* Setup GPIO as output */
84 ret
= gpio_direction_output(handle
, 0);
88 /* Setup output direction */
89 gpio_set_value(handle
, 0);
91 printk(KERN_INFO
"RESET: Registered gpio device: %d, current val: %d\n",
100 static void gpio_system_reset(void)
102 gpio_set_value(handle
, 1 - reset_val
);
105 #define gpio_system_reset() do {} while (0)
106 void of_platform_reset_gpio_probe(void)
112 void machine_restart(char *cmd
)
114 printk(KERN_NOTICE
"Machine restart...\n");
121 void machine_shutdown(void)
123 printk(KERN_NOTICE
"Machine shutdown...\n");
128 void machine_halt(void)
130 printk(KERN_NOTICE
"Machine halt...\n");
135 void machine_power_off(void)
137 printk(KERN_NOTICE
"Machine power off...\n");