sysreset_gpio.c 1.3 KB

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