Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 1 | /* |
| 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 King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 10 | #include <linux/io.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 11 | #include <asm/proc-fns.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 12 | #include <asm/system_misc.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 13 | |
Eric Miao | 5bf3df3 | 2009-01-20 11:04:16 +0800 | [diff] [blame] | 14 | #include <mach/regs-ost.h> |
Russell King | afd2fc0 | 2008-08-07 11:05:25 +0100 | [diff] [blame] | 15 | #include <mach/reset.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 16 | |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 17 | unsigned int reset_status; |
| 18 | EXPORT_SYMBOL(reset_status); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 19 | |
| 20 | static void do_hw_reset(void); |
| 21 | |
| 22 | static int reset_gpio = -1; |
| 23 | |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 24 | int init_gpio_reset(int gpio, int output, int level) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 25 | { |
| 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 Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 34 | if (output) |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 35 | rc = gpio_direction_output(gpio, level); |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 36 | else |
| 37 | rc = gpio_direction_input(gpio); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 38 | if (rc) { |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 39 | printk(KERN_ERR "Can't configure reset_gpio\n"); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 40 | gpio_free(gpio); |
| 41 | goto out; |
| 42 | } |
| 43 | |
| 44 | out: |
| 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 | */ |
| 56 | static 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 | |
| 77 | static void do_hw_reset(void) |
| 78 | { |
| 79 | /* Initialize the watchdog and let it fire */ |
| 80 | OWER = OWER_WME; |
| 81 | OSSR = OSSR_M3; |
| 82 | OSMR3 = OSCR + 368640; /* ... in 100 ms */ |
| 83 | } |
| 84 | |
Russell King | 271a74f | 2011-11-04 14:15:53 +0000 | [diff] [blame] | 85 | void pxa_restart(char mode, const char *cmd) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 86 | { |
Russell King | 271a74f | 2011-11-04 14:15:53 +0000 | [diff] [blame] | 87 | local_irq_disable(); |
| 88 | local_fiq_disable(); |
| 89 | |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 90 | clear_reset_status(RESET_STATUS_ALL); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 91 | |
| 92 | switch (mode) { |
| 93 | case 's': |
| 94 | /* Jump into ROM at address 0 */ |
Russell King | e879c86 | 2011-11-01 13:16:26 +0000 | [diff] [blame] | 95 | soft_restart(0); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 96 | break; |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 97 | case 'g': |
| 98 | do_gpio_reset(); |
| 99 | break; |
Jaya Kumar | 28105fd | 2008-11-11 12:17:05 +0100 | [diff] [blame] | 100 | case 'h': |
| 101 | default: |
| 102 | do_hw_reset(); |
| 103 | break; |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |