blob: af78405aa4e976b1cdc5a94a8ba7212f51c465af [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +01002#include <linux/kernel.h>
3#include <linux/module.h>
4#include <linux/delay.h>
5#include <linux/gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +01006#include <linux/io.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +01007#include <asm/proc-fns.h>
David Howells9f97da72012-03-28 18:30:01 +01008#include <asm/system_misc.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +01009
Eric Miao5bf3df32009-01-20 11:04:16 +080010#include <mach/regs-ost.h>
Russell Kingafd2fc02008-08-07 11:05:25 +010011#include <mach/reset.h>
Sergei Ianovichff88b472013-12-10 08:39:15 +040012#include <mach/smemc.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010013
Eric Miao04fef222008-07-29 14:26:00 +080014unsigned int reset_status;
15EXPORT_SYMBOL(reset_status);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010016
17static void do_hw_reset(void);
18
19static int reset_gpio = -1;
20
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030021int init_gpio_reset(int gpio, int output, int level)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010022{
23 int rc;
24
25 rc = gpio_request(gpio, "reset generator");
26 if (rc) {
27 printk(KERN_ERR "Can't request reset_gpio\n");
28 goto out;
29 }
30
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010031 if (output)
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030032 rc = gpio_direction_output(gpio, level);
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010033 else
34 rc = gpio_direction_input(gpio);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010035 if (rc) {
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010036 printk(KERN_ERR "Can't configure reset_gpio\n");
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010037 gpio_free(gpio);
38 goto out;
39 }
40
41out:
42 if (!rc)
43 reset_gpio = gpio;
44
45 return rc;
46}
47
48/*
49 * Trigger GPIO reset.
50 * This covers various types of logic connecting gpio pin
51 * to RESET pins (nRESET or GPIO_RESET):
52 */
53static void do_gpio_reset(void)
54{
55 BUG_ON(reset_gpio == -1);
56
57 /* drive it low */
58 gpio_direction_output(reset_gpio, 0);
59 mdelay(2);
60 /* rising edge or drive high */
61 gpio_set_value(reset_gpio, 1);
62 mdelay(2);
63 /* falling edge */
64 gpio_set_value(reset_gpio, 0);
65
66 /* give it some time */
67 mdelay(10);
68
69 WARN_ON(1);
70 /* fallback */
71 do_hw_reset();
72}
73
74static void do_hw_reset(void)
75{
76 /* Initialize the watchdog and let it fire */
Russell King31696632012-06-06 11:42:36 +010077 writel_relaxed(OWER_WME, OWER);
78 writel_relaxed(OSSR_M3, OSSR);
79 /* ... in 100 ms */
80 writel_relaxed(readl_relaxed(OSCR) + 368640, OSMR3);
Sergei Ianovichff88b472013-12-10 08:39:15 +040081 /*
82 * SDRAM hangs on watchdog reset on Marvell PXA270 (erratum 71)
83 * we put SDRAM into self-refresh to prevent that
84 */
85 while (1)
86 writel_relaxed(MDREFR_SLFRSH, MDREFR);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010087}
88
Robin Holt7b6d8642013-07-08 16:01:40 -070089void pxa_restart(enum reboot_mode mode, const char *cmd)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010090{
Russell King271a74f2011-11-04 14:15:53 +000091 local_irq_disable();
92 local_fiq_disable();
93
Eric Miao04fef222008-07-29 14:26:00 +080094 clear_reset_status(RESET_STATUS_ALL);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010095
96 switch (mode) {
Robin Holt7b6d8642013-07-08 16:01:40 -070097 case REBOOT_SOFT:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010098 /* Jump into ROM at address 0 */
Russell Kinge879c862011-11-01 13:16:26 +000099 soft_restart(0);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100100 break;
Robin Holt7b6d8642013-07-08 16:01:40 -0700101 case REBOOT_GPIO:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100102 do_gpio_reset();
103 break;
Robin Holt7b6d8642013-07-08 16:01:40 -0700104 case REBOOT_HARD:
Jaya Kumar28105fd2008-11-11 12:17:05 +0100105 default:
106 do_hw_reset();
107 break;
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100108 }
109}