reset-hisilicon.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_of_xlate(struct reset_ctl *rst,
  41. struct ofnode_phandle_args *args)
  42. {
  43. if (args->args_count != 3) {
  44. debug("Invalid args_count: %d\n", args->args_count);
  45. return -EINVAL;
  46. }
  47. /* Use .data field as register offset and .id field as bit shift */
  48. rst->data = args->args[0];
  49. rst->id = args->args[1];
  50. rst->polarity = args->args[2];
  51. return 0;
  52. }
  53. static const struct reset_ops hisi_reset_reset_ops = {
  54. .of_xlate = hisi_reset_of_xlate,
  55. .rst_assert = hisi_reset_assert,
  56. .rst_deassert = hisi_reset_deassert,
  57. };
  58. static const struct udevice_id hisi_reset_ids[] = {
  59. { .compatible = "hisilicon,hi3798cv200-reset" },
  60. { }
  61. };
  62. static int hisi_reset_probe(struct udevice *dev)
  63. {
  64. struct hisi_reset_priv *priv = dev_get_priv(dev);
  65. priv->base = dev_remap_addr(dev);
  66. if (!priv->base)
  67. return -ENOMEM;
  68. return 0;
  69. }
  70. U_BOOT_DRIVER(hisi_reset) = {
  71. .name = "hisilicon_reset",
  72. .id = UCLASS_RESET,
  73. .of_match = hisi_reset_ids,
  74. .ops = &hisi_reset_reset_ops,
  75. .probe = hisi_reset_probe,
  76. .priv_auto = sizeof(struct hisi_reset_priv),
  77. };