bulk.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/interconnect-provider.h>
  3. #include <linux/device.h>
  4. #include <linux/export.h>
  5. /**
  6. * of_icc_bulk_get() - get interconnect paths
  7. * @dev: the device requesting the path
  8. * @num_paths: the number of icc_bulk_data
  9. * @paths: the table with the paths we want to get
  10. *
  11. * Returns 0 on success or negative errno otherwise.
  12. */
  13. int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
  14. struct icc_bulk_data *paths)
  15. {
  16. int ret, i;
  17. for (i = 0; i < num_paths; i++) {
  18. paths[i].path = of_icc_get(dev, paths[i].name);
  19. if (IS_ERR(paths[i].path)) {
  20. ret = PTR_ERR(paths[i].path);
  21. if (ret != -EPROBE_DEFER)
  22. dev_err(dev, "of_icc_get() failed on path %s (%d)\n",
  23. paths[i].name, ret);
  24. paths[i].path = NULL;
  25. goto err;
  26. }
  27. }
  28. return 0;
  29. err:
  30. icc_bulk_put(i, paths);
  31. return ret;
  32. }
  33. EXPORT_SYMBOL_GPL(of_icc_bulk_get);
  34. /**
  35. * icc_bulk_put() - put a list of interconnect paths
  36. * @num_paths: the number of icc_bulk_data
  37. * @paths: the icc_bulk_data table with the paths being put
  38. */
  39. void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
  40. {
  41. while (--num_paths >= 0) {
  42. icc_put(paths[num_paths].path);
  43. paths[num_paths].path = NULL;
  44. }
  45. }
  46. EXPORT_SYMBOL_GPL(icc_bulk_put);
  47. /**
  48. * icc_bulk_set() - set bandwidth to a set of paths
  49. * @num_paths: the number of icc_bulk_data
  50. * @paths: the icc_bulk_data table containing the paths and bandwidth
  51. *
  52. * Returns 0 on success or negative errno otherwise.
  53. */
  54. int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
  55. {
  56. int ret = 0;
  57. int i;
  58. for (i = 0; i < num_paths; i++) {
  59. ret = icc_set_bw(paths[i].path, paths[i].avg_bw, paths[i].peak_bw);
  60. if (ret) {
  61. pr_err("icc_set_bw() failed on path %s (%d)\n", paths[i].name, ret);
  62. return ret;
  63. }
  64. }
  65. return ret;
  66. }
  67. EXPORT_SYMBOL_GPL(icc_bulk_set_bw);
  68. /**
  69. * icc_bulk_enable() - enable a previously disabled set of paths
  70. * @num_paths: the number of icc_bulk_data
  71. * @paths: the icc_bulk_data table containing the paths and bandwidth
  72. *
  73. * Returns 0 on success or negative errno otherwise.
  74. */
  75. int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
  76. {
  77. int ret, i;
  78. for (i = 0; i < num_paths; i++) {
  79. ret = icc_enable(paths[i].path);
  80. if (ret) {
  81. pr_err("icc_enable() failed on path %s (%d)\n", paths[i].name, ret);
  82. goto err;
  83. }
  84. }
  85. return 0;
  86. err:
  87. icc_bulk_disable(i, paths);
  88. return ret;
  89. }
  90. EXPORT_SYMBOL_GPL(icc_bulk_enable);
  91. /**
  92. * icc_bulk_disable() - disable a set of interconnect paths
  93. * @num_paths: the number of icc_bulk_data
  94. * @paths: the icc_bulk_data table containing the paths and bandwidth
  95. */
  96. void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
  97. {
  98. while (--num_paths >= 0)
  99. icc_disable(paths[num_paths].path);
  100. }
  101. EXPORT_SYMBOL_GPL(icc_bulk_disable);