reset.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /* Trigger specific functions */
  12. #ifdef CONFIG_GPIOLIB
  13. #include <linux/of_gpio.h>
  14. static int handle; /* reset pin handle */
  15. static unsigned int reset_val;
  16. void of_platform_reset_gpio_probe(void)
  17. {
  18. int ret;
  19. handle = of_get_named_gpio(of_find_node_by_path("/"),
  20. "hard-reset-gpios", 0);
  21. if (!gpio_is_valid(handle)) {
  22. pr_info("Skipping unavailable RESET gpio %d (%s)\n",
  23. handle, "reset");
  24. return;
  25. }
  26. ret = gpio_request(handle, "reset");
  27. if (ret < 0) {
  28. pr_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. pr_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. if (gpio_is_valid(handle))
  51. gpio_set_value(handle, 1 - reset_val);
  52. else
  53. pr_notice("Reset GPIO unavailable - halting!\n");
  54. }
  55. #else
  56. static void gpio_system_reset(void)
  57. {
  58. pr_notice("No reset GPIO present - halting!\n");
  59. }
  60. void of_platform_reset_gpio_probe(void)
  61. {
  62. return;
  63. }
  64. #endif
  65. void machine_restart(char *cmd)
  66. {
  67. pr_notice("Machine restart...\n");
  68. gpio_system_reset();
  69. while (1)
  70. ;
  71. }
  72. void machine_shutdown(void)
  73. {
  74. pr_notice("Machine shutdown...\n");
  75. while (1)
  76. ;
  77. }
  78. void machine_halt(void)
  79. {
  80. pr_notice("Machine halt...\n");
  81. while (1)
  82. ;
  83. }
  84. void machine_power_off(void)
  85. {
  86. pr_notice("Machine power off...\n");
  87. while (1)
  88. ;
  89. }