reset-hisilicon.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2019, Linaro Limited
  4. */
  5. #include <log.h>
  6. #include <malloc.h>
  7. #include <asm/io.h>
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <dt-bindings/reset/ti-syscon.h>
  11. #include <reset-uclass.h>
  12. #include <linux/bitops.h>
  13. struct hisi_reset_priv {
  14. void __iomem *base;
  15. };
  16. static int hisi_reset_deassert(struct reset_ctl *rst)
  17. {
  18. struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
  19. u32 val;
  20. val = readl(priv->base + rst->data);
  21. if (rst->polarity & DEASSERT_SET)
  22. val |= BIT(rst->id);
  23. else
  24. val &= ~BIT(rst->id);
  25. writel(val, priv->base + rst->data);
  26. return 0;
  27. }
  28. static int hisi_reset_assert(struct reset_ctl *rst)
  29. {
  30. struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
  31. u32 val;
  32. val = readl(priv->base + rst->data);
  33. if (rst->polarity & ASSERT_SET)
  34. val |= BIT(rst->id);
  35. else
  36. val &= ~BIT(rst->id);
  37. writel(val, priv->base + rst->data);
  38. return 0;
  39. }
  40. static int hisi_reset_free(struct reset_ctl *rst)
  41. {
  42. return 0;
  43. }
  44. static int hisi_reset_request(struct reset_ctl *rst)
  45. {
  46. return 0;
  47. }
  48. static int hisi_reset_of_xlate(struct reset_ctl *rst,
  49. struct ofnode_phandle_args *args)
  50. {
  51. if (args->args_count != 3) {
  52. debug("Invalid args_count: %d\n", args->args_count);
  53. return -EINVAL;
  54. }
  55. /* Use .data field as register offset and .id field as bit shift */
  56. rst->data = args->args[0];
  57. rst->id = args->args[1];
  58. rst->polarity = args->args[2];
  59. return 0;
  60. }
  61. static const struct reset_ops hisi_reset_reset_ops = {
  62. .of_xlate = hisi_reset_of_xlate,
  63. .request = hisi_reset_request,
  64. .rfree = hisi_reset_free,
  65. .rst_assert = hisi_reset_assert,
  66. .rst_deassert = hisi_reset_deassert,
  67. };
  68. static const struct udevice_id hisi_reset_ids[] = {
  69. { .compatible = "hisilicon,hi3798cv200-reset" },
  70. { }
  71. };
  72. static int hisi_reset_probe(struct udevice *dev)
  73. {
  74. struct hisi_reset_priv *priv = dev_get_priv(dev);
  75. priv->base = dev_remap_addr(dev);
  76. if (!priv->base)
  77. return -ENOMEM;
  78. return 0;
  79. }
  80. U_BOOT_DRIVER(hisi_reset) = {
  81. .name = "hisilicon_reset",
  82. .id = UCLASS_RESET,
  83. .of_match = hisi_reset_ids,
  84. .ops = &hisi_reset_reset_ops,
  85. .probe = hisi_reset_probe,
  86. .priv_auto_alloc_size = sizeof(struct hisi_reset_priv),
  87. };