reset.c 2.7 KB

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