142a2478bSMichal Simek /* 242a2478bSMichal Simek * Copyright (C) 2009 Michal Simek <[email protected]> 342a2478bSMichal Simek * Copyright (C) 2009 PetaLogix 442a2478bSMichal Simek * 542a2478bSMichal Simek * This file is subject to the terms and conditions of the GNU General Public 642a2478bSMichal Simek * License. See the file "COPYING" in the main directory of this archive 742a2478bSMichal Simek * for more details. 842a2478bSMichal Simek */ 942a2478bSMichal Simek 1042a2478bSMichal Simek #include <linux/init.h> 1142a2478bSMichal Simek #include <linux/of_platform.h> 1242a2478bSMichal Simek #include <asm/prom.h> 1342a2478bSMichal Simek 1442a2478bSMichal Simek /* Trigger specific functions */ 1542a2478bSMichal Simek #ifdef CONFIG_GPIOLIB 1642a2478bSMichal Simek 1742a2478bSMichal Simek #include <linux/of_gpio.h> 1842a2478bSMichal Simek 1942a2478bSMichal Simek static int handle; /* reset pin handle */ 2067bf8766SMichal Simek static unsigned int reset_val; 2142a2478bSMichal Simek 2242a2478bSMichal Simek void of_platform_reset_gpio_probe(void) 2342a2478bSMichal Simek { 2442a2478bSMichal Simek int ret; 25*fe9f6844SGrant Likely handle = of_get_named_gpio(of_find_node_by_path("/"), 26*fe9f6844SGrant Likely "hard-reset-gpios", 0); 2742a2478bSMichal Simek 2842a2478bSMichal Simek if (!gpio_is_valid(handle)) { 2942a2478bSMichal Simek printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n", 3042a2478bSMichal Simek handle, "reset"); 3142a2478bSMichal Simek } 3242a2478bSMichal Simek 3342a2478bSMichal Simek ret = gpio_request(handle, "reset"); 3442a2478bSMichal Simek if (ret < 0) { 3542a2478bSMichal Simek printk(KERN_INFO "GPIO pin is already allocated\n"); 3642a2478bSMichal Simek return; 3742a2478bSMichal Simek } 3842a2478bSMichal Simek 3942a2478bSMichal Simek /* get current setup value */ 4067bf8766SMichal Simek reset_val = gpio_get_value(handle); 4142a2478bSMichal Simek /* FIXME maybe worth to perform any action */ 4267bf8766SMichal Simek pr_debug("Reset: Gpio output state: 0x%x\n", reset_val); 4342a2478bSMichal Simek 4442a2478bSMichal Simek /* Setup GPIO as output */ 4542a2478bSMichal Simek ret = gpio_direction_output(handle, 0); 4642a2478bSMichal Simek if (ret < 0) 4742a2478bSMichal Simek goto err; 4842a2478bSMichal Simek 4942a2478bSMichal Simek /* Setup output direction */ 5042a2478bSMichal Simek gpio_set_value(handle, 0); 5142a2478bSMichal Simek 5267bf8766SMichal Simek printk(KERN_INFO "RESET: Registered gpio device: %d, current val: %d\n", 5367bf8766SMichal Simek handle, reset_val); 5442a2478bSMichal Simek return; 5542a2478bSMichal Simek err: 5642a2478bSMichal Simek gpio_free(handle); 5742a2478bSMichal Simek return; 5842a2478bSMichal Simek } 5942a2478bSMichal Simek 6042a2478bSMichal Simek 6142a2478bSMichal Simek static void gpio_system_reset(void) 6242a2478bSMichal Simek { 6367bf8766SMichal Simek gpio_set_value(handle, 1 - reset_val); 6442a2478bSMichal Simek } 6542a2478bSMichal Simek #else 6642a2478bSMichal Simek #define gpio_system_reset() do {} while (0) 6742a2478bSMichal Simek void of_platform_reset_gpio_probe(void) 6842a2478bSMichal Simek { 6942a2478bSMichal Simek return; 7042a2478bSMichal Simek } 7142a2478bSMichal Simek #endif 7242a2478bSMichal Simek 7342a2478bSMichal Simek void machine_restart(char *cmd) 7442a2478bSMichal Simek { 7542a2478bSMichal Simek printk(KERN_NOTICE "Machine restart...\n"); 7642a2478bSMichal Simek gpio_system_reset(); 7742a2478bSMichal Simek dump_stack(); 7842a2478bSMichal Simek while (1) 7942a2478bSMichal Simek ; 8042a2478bSMichal Simek } 8142a2478bSMichal Simek 8242a2478bSMichal Simek void machine_shutdown(void) 8342a2478bSMichal Simek { 8442a2478bSMichal Simek printk(KERN_NOTICE "Machine shutdown...\n"); 8542a2478bSMichal Simek while (1) 8642a2478bSMichal Simek ; 8742a2478bSMichal Simek } 8842a2478bSMichal Simek 8942a2478bSMichal Simek void machine_halt(void) 9042a2478bSMichal Simek { 9142a2478bSMichal Simek printk(KERN_NOTICE "Machine halt...\n"); 9242a2478bSMichal Simek while (1) 9342a2478bSMichal Simek ; 9442a2478bSMichal Simek } 9542a2478bSMichal Simek 9642a2478bSMichal Simek void machine_power_off(void) 9742a2478bSMichal Simek { 9842a2478bSMichal Simek printk(KERN_NOTICE "Machine power off...\n"); 9942a2478bSMichal Simek while (1) 10042a2478bSMichal Simek ; 10142a2478bSMichal Simek } 102