Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/module.h> |
| 4 | #include <linux/delay.h> |
| 5 | #include <linux/gpio.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 6 | #include <linux/io.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 7 | #include <asm/proc-fns.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 8 | #include <asm/system_misc.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 9 | |
Eric Miao | 5bf3df3 | 2009-01-20 11:04:16 +0800 | [diff] [blame] | 10 | #include <mach/regs-ost.h> |
Russell King | afd2fc0 | 2008-08-07 11:05:25 +0100 | [diff] [blame] | 11 | #include <mach/reset.h> |
Sergei Ianovich | ff88b47 | 2013-12-10 08:39:15 +0400 | [diff] [blame] | 12 | #include <mach/smemc.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 13 | |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 14 | unsigned int reset_status; |
| 15 | EXPORT_SYMBOL(reset_status); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 16 | |
| 17 | static void do_hw_reset(void); |
| 18 | |
| 19 | static int reset_gpio = -1; |
| 20 | |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 21 | int init_gpio_reset(int gpio, int output, int level) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 22 | { |
| 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 Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 31 | if (output) |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 32 | rc = gpio_direction_output(gpio, level); |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 33 | else |
| 34 | rc = gpio_direction_input(gpio); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 35 | if (rc) { |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 36 | printk(KERN_ERR "Can't configure reset_gpio\n"); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 37 | gpio_free(gpio); |
| 38 | goto out; |
| 39 | } |
| 40 | |
| 41 | out: |
| 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 | */ |
| 53 | static 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 | |
| 74 | static void do_hw_reset(void) |
| 75 | { |
| 76 | /* Initialize the watchdog and let it fire */ |
Russell King | 3169663 | 2012-06-06 11:42:36 +0100 | [diff] [blame] | 77 | writel_relaxed(OWER_WME, OWER); |
| 78 | writel_relaxed(OSSR_M3, OSSR); |
| 79 | /* ... in 100 ms */ |
| 80 | writel_relaxed(readl_relaxed(OSCR) + 368640, OSMR3); |
Sergei Ianovich | ff88b47 | 2013-12-10 08:39:15 +0400 | [diff] [blame] | 81 | /* |
| 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 Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 89 | void pxa_restart(enum reboot_mode mode, const char *cmd) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 90 | { |
Russell King | 271a74f | 2011-11-04 14:15:53 +0000 | [diff] [blame] | 91 | local_irq_disable(); |
| 92 | local_fiq_disable(); |
| 93 | |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 94 | clear_reset_status(RESET_STATUS_ALL); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 95 | |
| 96 | switch (mode) { |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 97 | case REBOOT_SOFT: |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 98 | /* Jump into ROM at address 0 */ |
Russell King | e879c86 | 2011-11-01 13:16:26 +0000 | [diff] [blame] | 99 | soft_restart(0); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 100 | break; |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 101 | case REBOOT_GPIO: |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 102 | do_gpio_reset(); |
| 103 | break; |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 104 | case REBOOT_HARD: |
Jaya Kumar | 28105fd | 2008-11-11 12:17:05 +0100 | [diff] [blame] | 105 | default: |
| 106 | do_hw_reset(); |
| 107 | break; |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 108 | } |
| 109 | } |