blob: 0d5dd646f61fa7d5aa743d4c68f162a2453d00e0 [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>
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010016
Eric Miao04fef222008-07-29 14:26:00 +080017unsigned int reset_status;
18EXPORT_SYMBOL(reset_status);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010019
20static void do_hw_reset(void);
21
22static int reset_gpio = -1;
23
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030024int init_gpio_reset(int gpio, int output, int level)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010025{
26 int rc;
27
28 rc = gpio_request(gpio, "reset generator");
29 if (rc) {
30 printk(KERN_ERR "Can't request reset_gpio\n");
31 goto out;
32 }
33
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010034 if (output)
Daniel Ribeiro216e3b72009-05-05 22:43:18 -030035 rc = gpio_direction_output(gpio, level);
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010036 else
37 rc = gpio_direction_input(gpio);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010038 if (rc) {
Dmitry Baryshkov69fc7ee2008-10-09 16:58:13 +010039 printk(KERN_ERR "Can't configure reset_gpio\n");
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010040 gpio_free(gpio);
41 goto out;
42 }
43
44out:
45 if (!rc)
46 reset_gpio = gpio;
47
48 return rc;
49}
50
51/*
52 * Trigger GPIO reset.
53 * This covers various types of logic connecting gpio pin
54 * to RESET pins (nRESET or GPIO_RESET):
55 */
56static void do_gpio_reset(void)
57{
58 BUG_ON(reset_gpio == -1);
59
60 /* drive it low */
61 gpio_direction_output(reset_gpio, 0);
62 mdelay(2);
63 /* rising edge or drive high */
64 gpio_set_value(reset_gpio, 1);
65 mdelay(2);
66 /* falling edge */
67 gpio_set_value(reset_gpio, 0);
68
69 /* give it some time */
70 mdelay(10);
71
72 WARN_ON(1);
73 /* fallback */
74 do_hw_reset();
75}
76
77static void do_hw_reset(void)
78{
79 /* Initialize the watchdog and let it fire */
Russell King31696632012-06-06 11:42:36 +010080 writel_relaxed(OWER_WME, OWER);
81 writel_relaxed(OSSR_M3, OSSR);
82 /* ... in 100 ms */
83 writel_relaxed(readl_relaxed(OSCR) + 368640, OSMR3);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010084}
85
Robin Holt7b6d8642013-07-08 16:01:40 -070086void pxa_restart(enum reboot_mode mode, const char *cmd)
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010087{
Russell King271a74f2011-11-04 14:15:53 +000088 local_irq_disable();
89 local_fiq_disable();
90
Eric Miao04fef222008-07-29 14:26:00 +080091 clear_reset_status(RESET_STATUS_ALL);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010092
93 switch (mode) {
Robin Holt7b6d8642013-07-08 16:01:40 -070094 case REBOOT_SOFT:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010095 /* Jump into ROM at address 0 */
Russell Kinge879c862011-11-01 13:16:26 +000096 soft_restart(0);
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010097 break;
Robin Holt7b6d8642013-07-08 16:01:40 -070098 case REBOOT_GPIO:
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +010099 do_gpio_reset();
100 break;
Robin Holt7b6d8642013-07-08 16:01:40 -0700101 case REBOOT_HARD:
Jaya Kumar28105fd2008-11-11 12:17:05 +0100102 default:
103 do_hw_reset();
104 break;
Dmitry Baryshkov75f10b42008-05-22 16:20:18 +0100105 }
106}
107