reset-bpmp.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2016 NVIDIA Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/reset-controller.h>
  9. #include <soc/tegra/bpmp.h>
  10. #include <soc/tegra/bpmp-abi.h>
  11. static struct tegra_bpmp *to_tegra_bpmp(struct reset_controller_dev *rstc)
  12. {
  13. return container_of(rstc, struct tegra_bpmp, rstc);
  14. }
  15. static int tegra_bpmp_reset_common(struct reset_controller_dev *rstc,
  16. enum mrq_reset_commands command,
  17. unsigned int id)
  18. {
  19. struct tegra_bpmp *bpmp = to_tegra_bpmp(rstc);
  20. struct mrq_reset_request request;
  21. struct tegra_bpmp_message msg;
  22. memset(&request, 0, sizeof(request));
  23. request.cmd = command;
  24. request.reset_id = id;
  25. memset(&msg, 0, sizeof(msg));
  26. msg.mrq = MRQ_RESET;
  27. msg.tx.data = &request;
  28. msg.tx.size = sizeof(request);
  29. return tegra_bpmp_transfer(bpmp, &msg);
  30. }
  31. static int tegra_bpmp_reset_module(struct reset_controller_dev *rstc,
  32. unsigned long id)
  33. {
  34. return tegra_bpmp_reset_common(rstc, CMD_RESET_MODULE, id);
  35. }
  36. static int tegra_bpmp_reset_assert(struct reset_controller_dev *rstc,
  37. unsigned long id)
  38. {
  39. return tegra_bpmp_reset_common(rstc, CMD_RESET_ASSERT, id);
  40. }
  41. static int tegra_bpmp_reset_deassert(struct reset_controller_dev *rstc,
  42. unsigned long id)
  43. {
  44. return tegra_bpmp_reset_common(rstc, CMD_RESET_DEASSERT, id);
  45. }
  46. static const struct reset_control_ops tegra_bpmp_reset_ops = {
  47. .reset = tegra_bpmp_reset_module,
  48. .assert = tegra_bpmp_reset_assert,
  49. .deassert = tegra_bpmp_reset_deassert,
  50. };
  51. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  52. {
  53. bpmp->rstc.ops = &tegra_bpmp_reset_ops;
  54. bpmp->rstc.owner = THIS_MODULE;
  55. bpmp->rstc.of_node = bpmp->dev->of_node;
  56. bpmp->rstc.nr_resets = bpmp->soc->num_resets;
  57. return devm_reset_controller_register(bpmp->dev, &bpmp->rstc);
  58. }