stm32-reset.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2017
  3. * Author(s): Patrice CHOTARD, <patrice.chotard@st.com> for STMicroelectronics.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <reset-uclass.h>
  11. #include <asm/io.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. struct stm32_reset_priv {
  14. fdt_addr_t base;
  15. };
  16. static int stm32_reset_request(struct reset_ctl *reset_ctl)
  17. {
  18. return 0;
  19. }
  20. static int stm32_reset_free(struct reset_ctl *reset_ctl)
  21. {
  22. return 0;
  23. }
  24. static int stm32_reset_assert(struct reset_ctl *reset_ctl)
  25. {
  26. struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  27. int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
  28. int offset = reset_ctl->id % BITS_PER_LONG;
  29. debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
  30. reset_ctl->id, bank, offset);
  31. setbits_le32(priv->base + bank, BIT(offset));
  32. return 0;
  33. }
  34. static int stm32_reset_deassert(struct reset_ctl *reset_ctl)
  35. {
  36. struct stm32_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  37. int bank = (reset_ctl->id / BITS_PER_LONG) * 4;
  38. int offset = reset_ctl->id % BITS_PER_LONG;
  39. debug("%s: reset id = %ld bank = %d offset = %d)\n", __func__,
  40. reset_ctl->id, bank, offset);
  41. clrbits_le32(priv->base + bank, BIT(offset));
  42. return 0;
  43. }
  44. static const struct reset_ops stm32_reset_ops = {
  45. .request = stm32_reset_request,
  46. .free = stm32_reset_free,
  47. .rst_assert = stm32_reset_assert,
  48. .rst_deassert = stm32_reset_deassert,
  49. };
  50. static int stm32_reset_probe(struct udevice *dev)
  51. {
  52. struct stm32_reset_priv *priv = dev_get_priv(dev);
  53. priv->base = devfdt_get_addr(dev);
  54. if (priv->base == FDT_ADDR_T_NONE)
  55. return -EINVAL;
  56. return 0;
  57. }
  58. U_BOOT_DRIVER(stm32_rcc_reset) = {
  59. .name = "stm32_rcc_reset",
  60. .id = UCLASS_RESET,
  61. .probe = stm32_reset_probe,
  62. .priv_auto_alloc_size = sizeof(struct stm32_reset_priv),
  63. .ops = &stm32_reset_ops,
  64. };