reset.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2009 PetaLogix
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/of_platform.h>
  11. #include <asm/prom.h>
  12. /* Trigger specific functions */
  13. #ifdef CONFIG_GPIOLIB
  14. #include <linux/of_gpio.h>
  15. static int handle; /* reset pin handle */
  16. static unsigned int reset_val;
  17. void of_platform_reset_gpio_probe(void)
  18. {
  19. int ret;
  20. handle = of_get_named_gpio(of_find_node_by_path("/"),
  21. "hard-reset-gpios", 0);
  22. if (!gpio_is_valid(handle)) {
  23. printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n",
  24. handle, "reset");
  25. }
  26. ret = gpio_request(handle, "reset");
  27. if (ret < 0) {
  28. printk(KERN_INFO "GPIO pin is already allocated\n");
  29. return;
  30. }
  31. /* get current setup value */
  32. reset_val = gpio_get_value(handle);
  33. /* FIXME maybe worth to perform any action */
  34. pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
  35. /* Setup GPIO as output */
  36. ret = gpio_direction_output(handle, 0);
  37. if (ret < 0)
  38. goto err;
  39. /* Setup output direction */
  40. gpio_set_value(handle, 0);
  41. printk(KERN_INFO "RESET: Registered gpio device: %d, current val: %d\n",
  42. handle, reset_val);
  43. return;
  44. err:
  45. gpio_free(handle);
  46. return;
  47. }
  48. static void gpio_system_reset(void)
  49. {
  50. gpio_set_value(handle, 1 - reset_val);
  51. }
  52. #else
  53. #define gpio_system_reset() do {} while (0)
  54. void of_platform_reset_gpio_probe(void)
  55. {
  56. return;
  57. }
  58. #endif
  59. void machine_restart(char *cmd)
  60. {
  61. printk(KERN_NOTICE "Machine restart...\n");
  62. gpio_system_reset();
  63. dump_stack();
  64. while (1)
  65. ;
  66. }
  67. void machine_shutdown(void)
  68. {
  69. printk(KERN_NOTICE "Machine shutdown...\n");
  70. while (1)
  71. ;
  72. }
  73. void machine_halt(void)
  74. {
  75. printk(KERN_NOTICE "Machine halt...\n");
  76. while (1)
  77. ;
  78. }
  79. void machine_power_off(void)
  80. {
  81. printk(KERN_NOTICE "Machine power off...\n");
  82. while (1)
  83. ;
  84. }