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; 25fe9f6844SGrant Likely handle = of_get_named_gpio(of_find_node_by_path("/"), 26fe9f6844SGrant Likely "hard-reset-gpios", 0); 2742a2478bSMichal Simek 2842a2478bSMichal Simek if (!gpio_is_valid(handle)) { 29*aaa5241eSMichal Simek pr_info("Skipping unavailable RESET gpio %d (%s)\n", 3042a2478bSMichal Simek handle, "reset"); 31191d5ecaSStephan Linz return; 3242a2478bSMichal Simek } 3342a2478bSMichal Simek 3442a2478bSMichal Simek ret = gpio_request(handle, "reset"); 3542a2478bSMichal Simek if (ret < 0) { 36*aaa5241eSMichal Simek pr_info("GPIO pin is already allocated\n"); 3742a2478bSMichal Simek return; 3842a2478bSMichal Simek } 3942a2478bSMichal Simek 4042a2478bSMichal Simek /* get current setup value */ 4167bf8766SMichal Simek reset_val = gpio_get_value(handle); 4242a2478bSMichal Simek /* FIXME maybe worth to perform any action */ 4367bf8766SMichal Simek pr_debug("Reset: Gpio output state: 0x%x\n", reset_val); 4442a2478bSMichal Simek 4542a2478bSMichal Simek /* Setup GPIO as output */ 4642a2478bSMichal Simek ret = gpio_direction_output(handle, 0); 4742a2478bSMichal Simek if (ret < 0) 4842a2478bSMichal Simek goto err; 4942a2478bSMichal Simek 5042a2478bSMichal Simek /* Setup output direction */ 5142a2478bSMichal Simek gpio_set_value(handle, 0); 5242a2478bSMichal Simek 53*aaa5241eSMichal Simek pr_info("RESET: Registered gpio device: %d, current val: %d\n", 5467bf8766SMichal Simek handle, reset_val); 5542a2478bSMichal Simek return; 5642a2478bSMichal Simek err: 5742a2478bSMichal Simek gpio_free(handle); 5842a2478bSMichal Simek return; 5942a2478bSMichal Simek } 6042a2478bSMichal Simek 6142a2478bSMichal Simek 6242a2478bSMichal Simek static void gpio_system_reset(void) 6342a2478bSMichal Simek { 64191d5ecaSStephan Linz if (gpio_is_valid(handle)) 6567bf8766SMichal Simek gpio_set_value(handle, 1 - reset_val); 66191d5ecaSStephan Linz else 67191d5ecaSStephan Linz pr_notice("Reset GPIO unavailable - halting!\n"); 6842a2478bSMichal Simek } 6942a2478bSMichal Simek #else 7042a2478bSMichal Simek #define gpio_system_reset() do {} while (0) 7142a2478bSMichal Simek void of_platform_reset_gpio_probe(void) 7242a2478bSMichal Simek { 7342a2478bSMichal Simek return; 7442a2478bSMichal Simek } 7542a2478bSMichal Simek #endif 7642a2478bSMichal Simek 7742a2478bSMichal Simek void machine_restart(char *cmd) 7842a2478bSMichal Simek { 79*aaa5241eSMichal Simek pr_notice("Machine restart...\n"); 8042a2478bSMichal Simek gpio_system_reset(); 8142a2478bSMichal Simek while (1) 8242a2478bSMichal Simek ; 8342a2478bSMichal Simek } 8442a2478bSMichal Simek 8542a2478bSMichal Simek void machine_shutdown(void) 8642a2478bSMichal Simek { 87*aaa5241eSMichal Simek pr_notice("Machine shutdown...\n"); 8842a2478bSMichal Simek while (1) 8942a2478bSMichal Simek ; 9042a2478bSMichal Simek } 9142a2478bSMichal Simek 9242a2478bSMichal Simek void machine_halt(void) 9342a2478bSMichal Simek { 94*aaa5241eSMichal Simek pr_notice("Machine halt...\n"); 9542a2478bSMichal Simek while (1) 9642a2478bSMichal Simek ; 9742a2478bSMichal Simek } 9842a2478bSMichal Simek 9942a2478bSMichal Simek void machine_power_off(void) 10042a2478bSMichal Simek { 101*aaa5241eSMichal Simek pr_notice("Machine power off...\n"); 10242a2478bSMichal Simek while (1) 10342a2478bSMichal Simek ; 10442a2478bSMichal Simek } 105