blob: 263b15249b5b803436709e1e5e268b9552bedef0 [file] [log] [blame]
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +01001/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/delay.h>
9#include <linux/gpio.h>
Russell Kingfced80c2008-09-06 12:10:45 +010010#include <linux/io.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010011#include <asm/proc-fns.h>
David Howells9f97da72012-03-28 18:30:01 +010012#include <asm/system_misc.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010013
Eric Miao5bf3df32009-01-20 11:04:16 +080014#include <mach/regs-ost.h>
Russell Kingafd2fc02008-08-07 11:05:25 +010015#include <mach/reset.h>
Sergei Ianovichff88b472013-12-10 08:39:15 +040016#include <mach/smemc.h>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010017
Eric Miao04fef222008-07-29 14:26:00 +080018unsigned int reset_status;
19EXPORT_SYMBOL(reset_status);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010020
21static void do_hw_reset(void);
22
23static int reset_gpio = -1;
24
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030025int init_gpio_reset(int gpio, int output, int level)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010026{
27 int rc;
28
29 rc = gpio_request(gpio, "reset generator");
30 if (rc) {
31 printk(KERN_ERR "Can't request reset_gpio\n");
32 goto out;
33 }
34
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010035 if (output)
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030036 rc = gpio_direction_output(gpio, level);
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010037 else
38 rc = gpio_direction_input(gpio);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010039 if (rc) {
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010040 printk(KERN_ERR "Can't configure reset_gpio\n");
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010041 gpio_free(gpio);
42 goto out;
43 }
44
45out:
46 if (!rc)
47 reset_gpio = gpio;
48
49 return rc;
50}
51
52/*
53 * Trigger GPIO reset.
54 * This covers various types of logic connecting gpio pin
55 * to RESET pins (nRESET or GPIO_RESET):
56 */
57static void do_gpio_reset(void)
58{
59 BUG_ON(reset_gpio == -1);
60
61 /* drive it low */
62 gpio_direction_output(reset_gpio, 0);
63 mdelay(2);
64 /* rising edge or drive high */
65 gpio_set_value(reset_gpio, 1);
66 mdelay(2);
67 /* falling edge */
68 gpio_set_value(reset_gpio, 0);
69
70 /* give it some time */
71 mdelay(10);
72
73 WARN_ON(1);
74 /* fallback */
75 do_hw_reset();
76}
77
78static void do_hw_reset(void)
79{
80 /* Initialize the watchdog and let it fire */
Russell King31696632012-06-06 11:42:36 +010081 writel_relaxed(OWER_WME, OWER);
82 writel_relaxed(OSSR_M3, OSSR);
83 /* ... in 100 ms */
84 writel_relaxed(readl_relaxed(OSCR) + 368640, OSMR3);
Sergei Ianovichff88b472013-12-10 08:39:15 +040085 /*
86 * SDRAM hangs on watchdog reset on Marvell PXA270 (erratum 71)
87 * we put SDRAM into self-refresh to prevent that
88 */
89 while (1)
90 writel_relaxed(MDREFR_SLFRSH, MDREFR);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010091}
92
Robin Holt7b6d8642013-07-08 16:01:40 -070093void pxa_restart(enum reboot_mode mode, const char *cmd)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010094{
Russell King271a74f2011-11-04 14:15:53 +000095 local_irq_disable();
96 local_fiq_disable();
97
Eric Miao04fef222008-07-29 14:26:00 +080098 clear_reset_status(RESET_STATUS_ALL);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010099
100 switch (mode) {
Robin Holt7b6d8642013-07-08 16:01:40 -0700101 case REBOOT_SOFT:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100102 /* Jump into ROM at address 0 */
Russell Kinge879c862011-11-01 13:16:26 +0000103 soft_restart(0);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100104 break;
Robin Holt7b6d8642013-07-08 16:01:40 -0700105 case REBOOT_GPIO:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100106 do_gpio_reset();
107 break;
Robin Holt7b6d8642013-07-08 16:01:40 -0700108 case REBOOT_HARD:
Jaya Kumar28105fd2008-11-11 12:17:05 +0100109 default:
110 do_hw_reset();
111 break;
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100112 }
113}