reset-hisilicon.c 2.1 KB

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