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 19static int handle; /* reset pin handle */ 20static unsigned int reset_val; 21 22static int of_reset_gpio_handle(void) 23{ 24 int ret; /* variable which stored handle reset gpio pin */ 25 struct device_node *root; /* root node */ 26 struct device_node *gpio; /* gpio node */ 27 struct gpio_chip *gc; 28 u32 flags; 29 const void *gpio_spec; 30 31 /* find out root node */ 32 root = of_find_node_by_path("/"); 33 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); 37 if (ret) { 38 pr_debug("%s: can't parse gpios property\n", __func__); 39 goto err0; 40 } 41 42 gc = of_node_to_gpiochip(gpio); 43 if (!gc) { 44 pr_debug("%s: gpio controller %s isn't registered\n", 45 root->full_name, gpio->full_name); 46 ret = -ENODEV; 47 goto err1; 48 } 49 50 ret = gc->of_xlate(gc, root, gpio_spec, &flags); 51 if (ret < 0) 52 goto err1; 53 54 ret += gc->base; 55err1: 56 of_node_put(gpio); 57err0: 58 pr_debug("%s exited with status %d\n", __func__, ret); 59 return ret; 60} 61 62void of_platform_reset_gpio_probe(void) 63{ 64 int ret; 65 handle = of_reset_gpio_handle(); 66 67 if (!gpio_is_valid(handle)) { 68 printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n", 69 handle, "reset"); 70 } 71 72 ret = gpio_request(handle, "reset"); 73 if (ret < 0) { 74 printk(KERN_INFO "GPIO pin is already allocated\n"); 75 return; 76 } 77 78 /* get current setup value */ 79 reset_val = gpio_get_value(handle); 80 pr_debug("Reset: Gpio output state: 0x%x\n", reset_val); 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 90 printk(KERN_INFO "RESET: Registered gpio device: %d, current val: %d\n", 91 handle, reset_val); 92 return; 93err: 94 gpio_free(handle); 95 return; 96} 97 98 99static void gpio_system_reset(void) 100{ 101 gpio_set_value(handle, 1 - reset_val); 102} 103#else 104#define gpio_system_reset() do {} while (0) 105void of_platform_reset_gpio_probe(void) 106{ 107 return; 108} 109#endif 110 111void machine_restart(char *cmd) 112{ 113 printk(KERN_NOTICE "Machine restart...\n"); 114 gpio_system_reset(); 115 dump_stack(); 116 while (1) 117 ; 118} 119 120void machine_shutdown(void) 121{ 122 printk(KERN_NOTICE "Machine shutdown...\n"); 123 while (1) 124 ; 125} 126 127void machine_halt(void) 128{ 129 printk(KERN_NOTICE "Machine halt...\n"); 130 while (1) 131 ; 132} 133 134void machine_power_off(void) 135{ 136 printk(KERN_NOTICE "Machine power off...\n"); 137 while (1) 138 ; 139} 140