sysreset_gpio.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Xilinx, Inc. - Michal Simek
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <log.h>
  9. #include <sysreset.h>
  10. #include <asm/gpio.h>
  11. struct gpio_reboot_priv {
  12. struct gpio_desc gpio;
  13. };
  14. static int gpio_reboot_request(struct udevice *dev, enum sysreset_t type)
  15. {
  16. struct gpio_reboot_priv *priv = dev_get_priv(dev);
  17. /*
  18. * When debug log is enabled please make sure that chars won't end up
  19. * in output fifo. Or you can append udelay(); to get enough time
  20. * to HW to emit output fifo.
  21. */
  22. debug("GPIO reset\n");
  23. /* Writing 1 respects polarity (active high/low) based on gpio->flags */
  24. return dm_gpio_set_value(&priv->gpio, 1);
  25. }
  26. static struct sysreset_ops gpio_reboot_ops = {
  27. .request = gpio_reboot_request,
  28. };
  29. int gpio_reboot_probe(struct udevice *dev)
  30. {
  31. struct gpio_reboot_priv *priv = dev_get_priv(dev);
  32. /*
  33. * Linux kernel DT binding contain others optional properties
  34. * which are not supported now
  35. */
  36. return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
  37. }
  38. static const struct udevice_id led_gpio_ids[] = {
  39. { .compatible = "gpio-restart" },
  40. { }
  41. };
  42. U_BOOT_DRIVER(gpio_reboot) = {
  43. .id = UCLASS_SYSRESET,
  44. .name = "gpio_restart",
  45. .of_match = led_gpio_ids,
  46. .ops = &gpio_reboot_ops,
  47. .priv_auto = sizeof(struct gpio_reboot_priv),
  48. .probe = gpio_reboot_probe,
  49. };