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> |
| 12 | |
Eric Miao | 5bf3df3 | 2009-01-20 11:04:16 +0800 | [diff] [blame] | 13 | #include <mach/regs-ost.h> |
Russell King | afd2fc0 | 2008-08-07 11:05:25 +0100 | [diff] [blame] | 14 | #include <mach/reset.h> |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 15 | |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 16 | unsigned int reset_status; |
| 17 | EXPORT_SYMBOL(reset_status); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 18 | |
| 19 | static void do_hw_reset(void); |
| 20 | |
| 21 | static int reset_gpio = -1; |
| 22 | |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 23 | int init_gpio_reset(int gpio, int output, int level) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 24 | { |
| 25 | int rc; |
| 26 | |
| 27 | rc = gpio_request(gpio, "reset generator"); |
| 28 | if (rc) { |
| 29 | printk(KERN_ERR "Can't request reset_gpio\n"); |
| 30 | goto out; |
| 31 | } |
| 32 | |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 33 | if (output) |
Daniel Ribeiro | 216e3b7 | 2009-05-05 22:43:18 -0300 | [diff] [blame] | 34 | rc = gpio_direction_output(gpio, level); |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 35 | else |
| 36 | rc = gpio_direction_input(gpio); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 37 | if (rc) { |
Dmitry Baryshkov | 69fc7ee | 2008-10-09 16:58:13 +0100 | [diff] [blame] | 38 | printk(KERN_ERR "Can't configure reset_gpio\n"); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 39 | gpio_free(gpio); |
| 40 | goto out; |
| 41 | } |
| 42 | |
| 43 | out: |
| 44 | if (!rc) |
| 45 | reset_gpio = gpio; |
| 46 | |
| 47 | return rc; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Trigger GPIO reset. |
| 52 | * This covers various types of logic connecting gpio pin |
| 53 | * to RESET pins (nRESET or GPIO_RESET): |
| 54 | */ |
| 55 | static void do_gpio_reset(void) |
| 56 | { |
| 57 | BUG_ON(reset_gpio == -1); |
| 58 | |
| 59 | /* drive it low */ |
| 60 | gpio_direction_output(reset_gpio, 0); |
| 61 | mdelay(2); |
| 62 | /* rising edge or drive high */ |
| 63 | gpio_set_value(reset_gpio, 1); |
| 64 | mdelay(2); |
| 65 | /* falling edge */ |
| 66 | gpio_set_value(reset_gpio, 0); |
| 67 | |
| 68 | /* give it some time */ |
| 69 | mdelay(10); |
| 70 | |
| 71 | WARN_ON(1); |
| 72 | /* fallback */ |
| 73 | do_hw_reset(); |
| 74 | } |
| 75 | |
| 76 | static void do_hw_reset(void) |
| 77 | { |
| 78 | /* Initialize the watchdog and let it fire */ |
| 79 | OWER = OWER_WME; |
| 80 | OSSR = OSSR_M3; |
| 81 | OSMR3 = OSCR + 368640; /* ... in 100 ms */ |
| 82 | } |
| 83 | |
Russell King | be093be | 2009-03-19 16:20:24 +0000 | [diff] [blame] | 84 | void arch_reset(char mode, const char *cmd) |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 85 | { |
Eric Miao | 04fef22 | 2008-07-29 14:26:00 +0800 | [diff] [blame] | 86 | clear_reset_status(RESET_STATUS_ALL); |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 87 | |
| 88 | switch (mode) { |
| 89 | case 's': |
| 90 | /* Jump into ROM at address 0 */ |
| 91 | cpu_reset(0); |
| 92 | break; |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 93 | case 'g': |
| 94 | do_gpio_reset(); |
| 95 | break; |
Jaya Kumar | 28105fd | 2008-11-11 12:17:05 +0100 | [diff] [blame] | 96 | case 'h': |
| 97 | default: |
| 98 | do_hw_reset(); |
| 99 | break; |
Dmitry Baryshkov | 75f10b4 | 2008-05-22 16:20:18 +0100 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |