2009-10-02 17:48:47 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
|
|
|
|
* Copyright (C) 2009 PetaLogix
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
|
|
|
|
/* Trigger specific functions */
|
|
|
|
#ifdef CONFIG_GPIOLIB
|
|
|
|
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
|
|
|
|
static int handle; /* reset pin handle */
|
2009-10-29 16:12:59 +07:00
|
|
|
static unsigned int reset_val;
|
2009-10-02 17:48:47 +07:00
|
|
|
|
2018-06-20 04:36:20 +07:00
|
|
|
static int of_platform_reset_gpio_probe(void)
|
2009-10-02 17:48:47 +07:00
|
|
|
{
|
|
|
|
int ret;
|
2011-12-12 23:25:56 +07:00
|
|
|
handle = of_get_named_gpio(of_find_node_by_path("/"),
|
|
|
|
"hard-reset-gpios", 0);
|
2009-10-02 17:48:47 +07:00
|
|
|
|
|
|
|
if (!gpio_is_valid(handle)) {
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_info("Skipping unavailable RESET gpio %d (%s)\n",
|
2009-10-02 17:48:47 +07:00
|
|
|
handle, "reset");
|
2018-06-20 04:36:20 +07:00
|
|
|
return -ENODEV;
|
2009-10-02 17:48:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = gpio_request(handle, "reset");
|
|
|
|
if (ret < 0) {
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_info("GPIO pin is already allocated\n");
|
2018-06-20 04:36:20 +07:00
|
|
|
return ret;
|
2009-10-02 17:48:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get current setup value */
|
2009-10-29 16:12:59 +07:00
|
|
|
reset_val = gpio_get_value(handle);
|
2009-10-02 17:48:47 +07:00
|
|
|
/* FIXME maybe worth to perform any action */
|
2009-10-29 16:12:59 +07:00
|
|
|
pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
|
2009-10-02 17:48:47 +07:00
|
|
|
|
|
|
|
/* Setup GPIO as output */
|
|
|
|
ret = gpio_direction_output(handle, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Setup output direction */
|
|
|
|
gpio_set_value(handle, 0);
|
|
|
|
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_info("RESET: Registered gpio device: %d, current val: %d\n",
|
2009-10-29 16:12:59 +07:00
|
|
|
handle, reset_val);
|
2018-06-20 04:36:20 +07:00
|
|
|
return 0;
|
2009-10-02 17:48:47 +07:00
|
|
|
err:
|
|
|
|
gpio_free(handle);
|
2018-06-20 04:36:20 +07:00
|
|
|
return ret;
|
2009-10-02 17:48:47 +07:00
|
|
|
}
|
2018-06-20 04:36:20 +07:00
|
|
|
device_initcall(of_platform_reset_gpio_probe);
|
2009-10-02 17:48:47 +07:00
|
|
|
|
|
|
|
|
|
|
|
static void gpio_system_reset(void)
|
|
|
|
{
|
microblaze: Improve failure handling for GPIO reset
Early exit from of_platform_reset_gpio_probe() if there
was no GPIO reset line configured.
Avoid kernel oops in gpio_system_reset():
[ 27.413294] Restarting system.
[ 27.415674] Machine restart...
[ 27.418787] Oops: kernel access of bad area, sig: 11
[ 27.423252] Registers dump: mode=83871D1C
[ 27.427428] r1=00000000, r2=00000000, r3=FFFFFEF8, r4=00000000
[ 27.433310] r5=C026AED0, r6=00000001, r7=00000068, r8=00000000
[ 27.439189] r9=C3871DAC, r10=000011A5, r11=00000000, r12=0000000A
[ 27.445318] r13=00000000, r14=0000000F, r15=C00029BC, r16=00000000
[ 27.451558] r17=C011DE8C, r18=80000115, r19=0000000F, r20=48184ED8
[ 27.457770] r21=00000000, r22=FFFFFFEA, r23=00000001, r24=FEE1DEAD
[ 27.463982] r25=00000054, r26=1000B1C8, r27=00000000, r28=00000000
[ 27.470208] r29=00000000, r30=00000000, r31=C32D30C0, rPC=C011DE8C
[ 27.476433] msr=000042A2, ear=0000004B, esr=00000872, fsr=342E3732
And remove useless dump_stack from machine_restart.
Signed-off-by: Stephan Linz <linz@li-pro.net>
Signed-off-by: Michal Simek <monstr@monstr.eu>
2012-06-21 03:36:37 +07:00
|
|
|
if (gpio_is_valid(handle))
|
|
|
|
gpio_set_value(handle, 1 - reset_val);
|
|
|
|
else
|
|
|
|
pr_notice("Reset GPIO unavailable - halting!\n");
|
2009-10-02 17:48:47 +07:00
|
|
|
}
|
|
|
|
#else
|
2012-05-28 14:56:40 +07:00
|
|
|
static void gpio_system_reset(void)
|
|
|
|
{
|
|
|
|
pr_notice("No reset GPIO present - halting!\n");
|
|
|
|
}
|
|
|
|
|
2009-10-02 17:48:47 +07:00
|
|
|
void of_platform_reset_gpio_probe(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void machine_restart(char *cmd)
|
|
|
|
{
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_notice("Machine restart...\n");
|
2009-10-02 17:48:47 +07:00
|
|
|
gpio_system_reset();
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void machine_shutdown(void)
|
|
|
|
{
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_notice("Machine shutdown...\n");
|
2009-10-02 17:48:47 +07:00
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void machine_halt(void)
|
|
|
|
{
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_notice("Machine halt...\n");
|
2009-10-02 17:48:47 +07:00
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void machine_power_off(void)
|
|
|
|
{
|
2012-10-04 19:24:58 +07:00
|
|
|
pr_notice("Machine power off...\n");
|
2009-10-02 17:48:47 +07:00
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|