175-reset-add-of_reset_control_get.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From bfea2b9be28b20e076d5df8863c25e966f413fa3 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <maxime.ripard@free-electrons.com>
  3. Date: Fri, 20 Dec 2013 22:41:07 +0100
  4. Subject: [PATCH] reset: Add of_reset_control_get
  5. In some cases, you might need to deassert from reset an hardware block that
  6. doesn't associated to a struct device (CPUs, timers, etc.).
  7. Add a small helper to retrieve the reset controller from the device tree
  8. without the need to pass a struct device.
  9. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
  10. ---
  11. drivers/reset/core.c | 39 ++++++++++++++++++++++++++++++---------
  12. include/linux/reset.h | 4 ++++
  13. 2 files changed, 34 insertions(+), 9 deletions(-)
  14. --- a/drivers/reset/core.c
  15. +++ b/drivers/reset/core.c
  16. @@ -127,15 +127,16 @@ int reset_control_deassert(struct reset_
  17. EXPORT_SYMBOL_GPL(reset_control_deassert);
  18. /**
  19. - * reset_control_get - Lookup and obtain a reference to a reset controller.
  20. - * @dev: device to be reset by the controller
  21. + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
  22. + * @node: device to be reset by the controller
  23. * @id: reset line name
  24. *
  25. * Returns a struct reset_control or IS_ERR() condition containing errno.
  26. *
  27. * Use of id names is optional.
  28. */
  29. -struct reset_control *reset_control_get(struct device *dev, const char *id)
  30. +struct reset_control *of_reset_control_get(struct device_node *node,
  31. + const char *id)
  32. {
  33. struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
  34. struct reset_controller_dev *r, *rcdev;
  35. @@ -144,13 +145,10 @@ struct reset_control *reset_control_get(
  36. int rstc_id;
  37. int ret;
  38. - if (!dev)
  39. - return ERR_PTR(-EINVAL);
  40. -
  41. if (id)
  42. - index = of_property_match_string(dev->of_node,
  43. + index = of_property_match_string(node,
  44. "reset-names", id);
  45. - ret = of_parse_phandle_with_args(dev->of_node, "resets", "#reset-cells",
  46. + ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
  47. index, &args);
  48. if (ret)
  49. return ERR_PTR(ret);
  50. @@ -185,12 +183,35 @@ struct reset_control *reset_control_get(
  51. return ERR_PTR(-ENOMEM);
  52. }
  53. - rstc->dev = dev;
  54. rstc->rcdev = rcdev;
  55. rstc->id = rstc_id;
  56. return rstc;
  57. }
  58. +EXPORT_SYMBOL_GPL(of_reset_control_get);
  59. +
  60. +/**
  61. + * reset_control_get - Lookup and obtain a reference to a reset controller.
  62. + * @dev: device to be reset by the controller
  63. + * @id: reset line name
  64. + *
  65. + * Returns a struct reset_control or IS_ERR() condition containing errno.
  66. + *
  67. + * Use of id names is optional.
  68. + */
  69. +struct reset_control *reset_control_get(struct device *dev, const char *id)
  70. +{
  71. + struct reset_control *rstc;
  72. +
  73. + if (!dev)
  74. + return ERR_PTR(-EINVAL);
  75. +
  76. + rstc = of_reset_control_get(dev->of_node, id);
  77. + if (!IS_ERR(rstc))
  78. + rstc->dev = dev;
  79. +
  80. + return rstc;
  81. +}
  82. EXPORT_SYMBOL_GPL(reset_control_get);
  83. /**
  84. --- a/include/linux/reset.h
  85. +++ b/include/linux/reset.h
  86. @@ -1,6 +1,8 @@
  87. #ifndef _LINUX_RESET_H_
  88. #define _LINUX_RESET_H_
  89. +#include <linux/of.h>
  90. +
  91. struct device;
  92. struct reset_control;
  93. @@ -8,6 +10,8 @@ int reset_control_reset(struct reset_con
  94. int reset_control_assert(struct reset_control *rstc);
  95. int reset_control_deassert(struct reset_control *rstc);
  96. +struct reset_control *of_reset_control_get(struct device_node *node,
  97. + const char *id);
  98. struct reset_control *reset_control_get(struct device *dev, const char *id);
  99. void reset_control_put(struct reset_control *rstc);
  100. struct reset_control *devm_reset_control_get(struct device *dev, const char *id);