140-reset-add-of_reset_control_get_by_index.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. From b4faa163a7ebae9faab5d0aefe70143e3379178b Mon Sep 17 00:00:00 2001
  2. From: Vince Hsu <vinceh@nvidia.com>
  3. Date: Mon, 13 Jul 2015 13:39:39 +0100
  4. Subject: [PATCH] reset: add of_reset_control_get_by_index()
  5. Add of_reset_control_get_by_index() to allow the drivers to get reset
  6. device without knowing its name.
  7. Signed-off-by: Vince Hsu <vinceh@nvidia.com>
  8. [jonathanh@nvidia.com: Updated stub function to return -ENOTSUPP instead
  9. of -ENOSYS which should only be used for system calls.]
  10. Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
  11. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
  12. ---
  13. drivers/reset/core.c | 40 +++++++++++++++++++++++++++++-----------
  14. include/linux/reset.h | 9 +++++++++
  15. 2 files changed, 38 insertions(+), 11 deletions(-)
  16. --- a/drivers/reset/core.c
  17. +++ b/drivers/reset/core.c
  18. @@ -141,27 +141,24 @@ int reset_control_status(struct reset_co
  19. EXPORT_SYMBOL_GPL(reset_control_status);
  20. /**
  21. - * of_reset_control_get - Lookup and obtain a reference to a reset controller.
  22. + * of_reset_control_get_by_index - Lookup and obtain a reference to a reset
  23. + * controller by index.
  24. * @node: device to be reset by the controller
  25. - * @id: reset line name
  26. - *
  27. - * Returns a struct reset_control or IS_ERR() condition containing errno.
  28. + * @index: index of the reset controller
  29. *
  30. - * Use of id names is optional.
  31. + * This is to be used to perform a list of resets for a device or power domain
  32. + * in whatever order. Returns a struct reset_control or IS_ERR() condition
  33. + * containing errno.
  34. */
  35. -struct reset_control *of_reset_control_get(struct device_node *node,
  36. - const char *id)
  37. +struct reset_control *of_reset_control_get_by_index(struct device_node *node,
  38. + int index)
  39. {
  40. struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
  41. struct reset_controller_dev *r, *rcdev;
  42. struct of_phandle_args args;
  43. - int index = 0;
  44. int rstc_id;
  45. int ret;
  46. - if (id)
  47. - index = of_property_match_string(node,
  48. - "reset-names", id);
  49. ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
  50. index, &args);
  51. if (ret)
  52. @@ -202,6 +199,27 @@ struct reset_control *of_reset_control_g
  53. return rstc;
  54. }
  55. +EXPORT_SYMBOL_GPL(of_reset_control_get_by_index);
  56. +
  57. +/**
  58. + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
  59. + * @node: device to be reset by the controller
  60. + * @id: reset line name
  61. + *
  62. + * Returns a struct reset_control or IS_ERR() condition containing errno.
  63. + *
  64. + * Use of id names is optional.
  65. + */
  66. +struct reset_control *of_reset_control_get(struct device_node *node,
  67. + const char *id)
  68. +{
  69. + int index = 0;
  70. +
  71. + if (id)
  72. + index = of_property_match_string(node,
  73. + "reset-names", id);
  74. + return of_reset_control_get_by_index(node, index);
  75. +}
  76. EXPORT_SYMBOL_GPL(of_reset_control_get);
  77. /**
  78. --- a/include/linux/reset.h
  79. +++ b/include/linux/reset.h
  80. @@ -38,6 +38,9 @@ static inline struct reset_control *devm
  81. struct reset_control *of_reset_control_get(struct device_node *node,
  82. const char *id);
  83. +struct reset_control *of_reset_control_get_by_index(
  84. + struct device_node *node, int index);
  85. +
  86. #else
  87. static inline int reset_control_reset(struct reset_control *rstc)
  88. @@ -106,6 +109,12 @@ static inline struct reset_control *of_r
  89. return ERR_PTR(-ENOSYS);
  90. }
  91. +static inline struct reset_control *of_reset_control_get_by_index(
  92. + struct device_node *node, int index)
  93. +{
  94. + return ERR_PTR(-ENOTSUPP);
  95. +}
  96. +
  97. #endif /* CONFIG_RESET_CONTROLLER */
  98. #endif