reset.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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>
  10. #include <asm/io.h>
  11. #include <asm/proc-fns.h>
  12. #include <mach/pxa-regs.h>
  13. #include <mach/reset.h>
  14. unsigned int reset_status;
  15. EXPORT_SYMBOL(reset_status);
  16. static void do_hw_reset(void);
  17. static int reset_gpio = -1;
  18. int init_gpio_reset(int gpio)
  19. {
  20. int rc;
  21. rc = gpio_request(gpio, "reset generator");
  22. if (rc) {
  23. printk(KERN_ERR "Can't request reset_gpio\n");
  24. goto out;
  25. }
  26. rc = gpio_direction_input(gpio);
  27. if (rc) {
  28. printk(KERN_ERR "Can't configure reset_gpio for input\n");
  29. gpio_free(gpio);
  30. goto out;
  31. }
  32. out:
  33. if (!rc)
  34. reset_gpio = gpio;
  35. return rc;
  36. }
  37. /*
  38. * Trigger GPIO reset.
  39. * This covers various types of logic connecting gpio pin
  40. * to RESET pins (nRESET or GPIO_RESET):
  41. */
  42. static void do_gpio_reset(void)
  43. {
  44. BUG_ON(reset_gpio == -1);
  45. /* drive it low */
  46. gpio_direction_output(reset_gpio, 0);
  47. mdelay(2);
  48. /* rising edge or drive high */
  49. gpio_set_value(reset_gpio, 1);
  50. mdelay(2);
  51. /* falling edge */
  52. gpio_set_value(reset_gpio, 0);
  53. /* give it some time */
  54. mdelay(10);
  55. WARN_ON(1);
  56. /* fallback */
  57. do_hw_reset();
  58. }
  59. static void do_hw_reset(void)
  60. {
  61. /* Initialize the watchdog and let it fire */
  62. OWER = OWER_WME;
  63. OSSR = OSSR_M3;
  64. OSMR3 = OSCR + 368640; /* ... in 100 ms */
  65. }
  66. void arch_reset(char mode)
  67. {
  68. clear_reset_status(RESET_STATUS_ALL);
  69. switch (mode) {
  70. case 's':
  71. /* Jump into ROM at address 0 */
  72. cpu_reset(0);
  73. break;
  74. case 'h':
  75. do_hw_reset();
  76. break;
  77. case 'g':
  78. do_gpio_reset();
  79. break;
  80. }
  81. }