reset.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. static int of_reset_gpio_handle(void)
  18. {
  19. int ret; /* variable which stored handle reset gpio pin */
  20. struct device_node *root; /* root node */
  21. struct device_node *gpio; /* gpio node */
  22. struct gpio_chip *gc;
  23. u32 flags;
  24. const void *gpio_spec;
  25. /* find out root node */
  26. root = of_find_node_by_path("/");
  27. /* give me handle for gpio node to be possible allocate pin */
  28. ret = of_parse_phandles_with_args(root, "hard-reset-gpios",
  29. "#gpio-cells", 0, &gpio, &gpio_spec);
  30. if (ret) {
  31. pr_debug("%s: can't parse gpios property\n", __func__);
  32. goto err0;
  33. }
  34. gc = of_node_to_gpiochip(gpio);
  35. if (!gc) {
  36. pr_debug("%s: gpio controller %s isn't registered\n",
  37. root->full_name, gpio->full_name);
  38. ret = -ENODEV;
  39. goto err1;
  40. }
  41. ret = gc->of_xlate(gc, root, gpio_spec, &flags);
  42. if (ret < 0)
  43. goto err1;
  44. ret += gc->base;
  45. err1:
  46. of_node_put(gpio);
  47. err0:
  48. pr_debug("%s exited with status %d\n", __func__, ret);
  49. return ret;
  50. }
  51. void of_platform_reset_gpio_probe(void)
  52. {
  53. int ret;
  54. handle = of_reset_gpio_handle();
  55. if (!gpio_is_valid(handle)) {
  56. printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n",
  57. handle, "reset");
  58. }
  59. ret = gpio_request(handle, "reset");
  60. if (ret < 0) {
  61. printk(KERN_INFO "GPIO pin is already allocated\n");
  62. return;
  63. }
  64. /* get current setup value */
  65. reset_val = gpio_get_value(handle);
  66. /* FIXME maybe worth to perform any action */
  67. pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
  68. /* Setup GPIO as output */
  69. ret = gpio_direction_output(handle, 0);
  70. if (ret < 0)
  71. goto err;
  72. /* Setup output direction */
  73. gpio_set_value(handle, 0);
  74. printk(KERN_INFO "RESET: Registered gpio device: %d, current val: %d\n",
  75. handle, reset_val);
  76. return;
  77. err:
  78. gpio_free(handle);
  79. return;
  80. }
  81. static void gpio_system_reset(void)
  82. {
  83. gpio_set_value(handle, 1 - reset_val);
  84. }
  85. #else
  86. #define gpio_system_reset() do {} while (0)
  87. void of_platform_reset_gpio_probe(void)
  88. {
  89. return;
  90. }
  91. #endif
  92. void machine_restart(char *cmd)
  93. {
  94. printk(KERN_NOTICE "Machine restart...\n");
  95. gpio_system_reset();
  96. dump_stack();
  97. while (1)
  98. ;
  99. }
  100. void machine_shutdown(void)
  101. {
  102. printk(KERN_NOTICE "Machine shutdown...\n");
  103. while (1)
  104. ;
  105. }
  106. void machine_halt(void)
  107. {
  108. printk(KERN_NOTICE "Machine halt...\n");
  109. while (1)
  110. ;
  111. }
  112. void machine_power_off(void)
  113. {
  114. printk(KERN_NOTICE "Machine power off...\n");
  115. while (1)
  116. ;
  117. }