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. static int 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 -ENODEV;
  25. }
  26. ret = gpio_request(handle, "reset");
  27. if (ret < 0) {
  28. pr_info("GPIO pin is already allocated\n");
  29. return ret;
  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 0;
  44. err:
  45. gpio_free(handle);
  46. return ret;
  47. }
  48. device_initcall(of_platform_reset_gpio_probe);
  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. }