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. #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. static void gpio_system_reset(void)
  58. {
  59. pr_notice("No reset GPIO present - halting!\n");
  60. }
  61. void of_platform_reset_gpio_probe(void)
  62. {
  63. return;
  64. }
  65. #endif
  66. void machine_restart(char *cmd)
  67. {
  68. pr_notice("Machine restart...\n");
  69. gpio_system_reset();
  70. while (1)
  71. ;
  72. }
  73. void machine_shutdown(void)
  74. {
  75. pr_notice("Machine shutdown...\n");
  76. while (1)
  77. ;
  78. }
  79. void machine_halt(void)
  80. {
  81. pr_notice("Machine halt...\n");
  82. while (1)
  83. ;
  84. }
  85. void machine_power_off(void)
  86. {
  87. pr_notice("Machine power off...\n");
  88. while (1)
  89. ;
  90. }