sysreset_at91.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
  4. */
  5. #include <asm/arch/hardware.h>
  6. #include <asm/io.h>
  7. #include <asm/arch/at91_rstc.h>
  8. #include <clk.h>
  9. #include <common.h>
  10. #include <cpu_func.h>
  11. #include <dm.h>
  12. #include <dm/device_compat.h>
  13. #include <dm/device-internal.h>
  14. #include <sysreset.h>
  15. static int at91_sysreset_request(struct udevice *dev, enum sysreset_t type)
  16. {
  17. at91_rstc_t *rstc = (at91_rstc_t *)dev_get_priv(dev);
  18. writel(AT91_RSTC_KEY
  19. | AT91_RSTC_CR_PROCRST /* Processor Reset */
  20. | AT91_RSTC_CR_PERRST /* Peripheral Reset */
  21. #ifdef CONFIG_AT91RESET_EXTRST
  22. | AT91_RSTC_CR_EXTRST /* External Reset (assert nRST pin) */
  23. #endif
  24. , &rstc->cr);
  25. return -EINPROGRESS;
  26. }
  27. static int at91_sysreset_probe(struct udevice *dev)
  28. {
  29. struct clk slck;
  30. void *priv;
  31. int ret;
  32. priv = dev_remap_addr(dev);
  33. if (!priv)
  34. return -EINVAL;
  35. dev_set_priv(dev, priv);
  36. ret = clk_get_by_index(dev, 0, &slck);
  37. if (ret)
  38. return ret;
  39. ret = clk_prepare_enable(&slck);
  40. if (ret)
  41. return ret;
  42. return 0;
  43. }
  44. static struct sysreset_ops at91_sysreset = {
  45. .request = at91_sysreset_request,
  46. };
  47. U_BOOT_DRIVER(sysreset_at91) = {
  48. .id = UCLASS_SYSRESET,
  49. .name = "at91_sysreset",
  50. .ops = &at91_sysreset,
  51. .probe = at91_sysreset_probe,
  52. };