reset.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. pr_info("Skipping unavailable RESET gpio %d (%s)\n",
  24. handle, "reset");
  25. return;
  26. }
  27. ret = gpio_request(handle, "reset");
  28. if (ret < 0) {
  29. pr_info("GPIO pin is already allocated\n");
  30. return;
  31. }
  32. /* get current setup value */
  33. reset_val = gpio_get_value(handle);
  34. /* FIXME maybe worth to perform any action */
  35. pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
  36. /* Setup GPIO as output */
  37. ret = gpio_direction_output(handle, 0);
  38. if (ret < 0)
  39. goto err;
  40. /* Setup output direction */
  41. gpio_set_value(handle, 0);
  42. pr_info("RESET: Registered gpio device: %d, current val: %d\n",
  43. handle, reset_val);
  44. return;
  45. err:
  46. gpio_free(handle);
  47. return;
  48. }
  49. static void gpio_system_reset(void)
  50. {
  51. if (gpio_is_valid(handle))
  52. gpio_set_value(handle, 1 - reset_val);
  53. else
  54. pr_notice("Reset GPIO unavailable - halting!\n");
  55. }
  56. #else
  57. #define gpio_system_reset() do {} while (0)
  58. void of_platform_reset_gpio_probe(void)
  59. {
  60. return;
  61. }
  62. #endif
  63. void machine_restart(char *cmd)
  64. {
  65. pr_notice("Machine restart...\n");
  66. gpio_system_reset();
  67. while (1)
  68. ;
  69. }
  70. void machine_shutdown(void)
  71. {
  72. pr_notice("Machine shutdown...\n");
  73. while (1)
  74. ;
  75. }
  76. void machine_halt(void)
  77. {
  78. pr_notice("Machine halt...\n");
  79. while (1)
  80. ;
  81. }
  82. void machine_power_off(void)
  83. {
  84. pr_notice("Machine power off...\n");
  85. while (1)
  86. ;
  87. }