sysreset_gpio.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. int ret;
  18. /*
  19. * When debug log is enabled please make sure that chars won't end up
  20. * in output fifo. Or you can append udelay(); to get enough time
  21. * to HW to emit output fifo.
  22. */
  23. debug("GPIO reset\n");
  24. /* Writing 1 respects polarity (active high/low) based on gpio->flags */
  25. ret = dm_gpio_set_value(&priv->gpio, 1);
  26. if (ret < 0)
  27. return ret;
  28. return -EINPROGRESS;
  29. }
  30. static struct sysreset_ops gpio_reboot_ops = {
  31. .request = gpio_reboot_request,
  32. };
  33. static int gpio_reboot_probe(struct udevice *dev)
  34. {
  35. struct gpio_reboot_priv *priv = dev_get_priv(dev);
  36. /*
  37. * Linux kernel DT binding contain others optional properties
  38. * which are not supported now
  39. */
  40. return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
  41. }
  42. static const struct udevice_id led_gpio_ids[] = {
  43. { .compatible = "gpio-restart" },
  44. { }
  45. };
  46. U_BOOT_DRIVER(gpio_reboot) = {
  47. .id = UCLASS_SYSRESET,
  48. .name = "gpio_restart",
  49. .of_match = led_gpio_ids,
  50. .ops = &gpio_reboot_ops,
  51. .priv_auto = sizeof(struct gpio_reboot_priv),
  52. .probe = gpio_reboot_probe,
  53. };