080-v5.17-clk-gate-Add-devm_clk_hw_register_gate.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 815f0e738a8d5663a02350e2580706829144a722 Mon Sep 17 00:00:00 2001
  2. From: Horatiu Vultur <[email protected]>
  3. Date: Wed, 3 Nov 2021 09:50:59 +0100
  4. Subject: [PATCH] clk: gate: Add devm_clk_hw_register_gate()
  5. Add devm_clk_hw_register_gate() - devres-managed version of
  6. clk_hw_register_gate()
  7. Suggested-by: Stephen Boyd <[email protected]>
  8. Signed-off-by: Horatiu Vultur <[email protected]>
  9. Acked-by: Nicolas Ferre <[email protected]>
  10. Signed-off-by: Nicolas Ferre <[email protected]>
  11. Link: https://lore.kernel.org/r/[email protected]
  12. ---
  13. drivers/clk/clk-gate.c | 35 +++++++++++++++++++++++++++++++++++
  14. include/linux/clk-provider.h | 23 +++++++++++++++++++++++
  15. 2 files changed, 58 insertions(+)
  16. --- a/drivers/clk/clk-gate.c
  17. +++ b/drivers/clk/clk-gate.c
  18. @@ -7,6 +7,7 @@
  19. */
  20. #include <linux/clk-provider.h>
  21. +#include <linux/device.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/io.h>
  25. @@ -222,3 +223,37 @@ void clk_hw_unregister_gate(struct clk_h
  26. kfree(gate);
  27. }
  28. EXPORT_SYMBOL_GPL(clk_hw_unregister_gate);
  29. +
  30. +static void devm_clk_hw_release_gate(struct device *dev, void *res)
  31. +{
  32. + clk_hw_unregister_gate(*(struct clk_hw **)res);
  33. +}
  34. +
  35. +struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
  36. + struct device_node *np, const char *name,
  37. + const char *parent_name, const struct clk_hw *parent_hw,
  38. + const struct clk_parent_data *parent_data,
  39. + unsigned long flags,
  40. + void __iomem *reg, u8 bit_idx,
  41. + u8 clk_gate_flags, spinlock_t *lock)
  42. +{
  43. + struct clk_hw **ptr, *hw;
  44. +
  45. + ptr = devres_alloc(devm_clk_hw_release_gate, sizeof(*ptr), GFP_KERNEL);
  46. + if (!ptr)
  47. + return ERR_PTR(-ENOMEM);
  48. +
  49. + hw = __clk_hw_register_gate(dev, np, name, parent_name, parent_hw,
  50. + parent_data, flags, reg, bit_idx,
  51. + clk_gate_flags, lock);
  52. +
  53. + if (!IS_ERR(hw)) {
  54. + *ptr = hw;
  55. + devres_add(dev, ptr);
  56. + } else {
  57. + devres_free(ptr);
  58. + }
  59. +
  60. + return hw;
  61. +}
  62. +EXPORT_SYMBOL_GPL(__devm_clk_hw_register_gate);
  63. --- a/include/linux/clk-provider.h
  64. +++ b/include/linux/clk-provider.h
  65. @@ -517,6 +517,13 @@ struct clk_hw *__clk_hw_register_gate(st
  66. unsigned long flags,
  67. void __iomem *reg, u8 bit_idx,
  68. u8 clk_gate_flags, spinlock_t *lock);
  69. +struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
  70. + struct device_node *np, const char *name,
  71. + const char *parent_name, const struct clk_hw *parent_hw,
  72. + const struct clk_parent_data *parent_data,
  73. + unsigned long flags,
  74. + void __iomem *reg, u8 bit_idx,
  75. + u8 clk_gate_flags, spinlock_t *lock);
  76. struct clk *clk_register_gate(struct device *dev, const char *name,
  77. const char *parent_name, unsigned long flags,
  78. void __iomem *reg, u8 bit_idx,
  79. @@ -571,6 +578,22 @@ struct clk *clk_register_gate(struct dev
  80. __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
  81. (flags), (reg), (bit_idx), \
  82. (clk_gate_flags), (lock))
  83. +/**
  84. + * devm_clk_hw_register_gate - register a gate clock with the clock framework
  85. + * @dev: device that is registering this clock
  86. + * @name: name of this clock
  87. + * @parent_name: name of this clock's parent
  88. + * @flags: framework-specific flags for this clock
  89. + * @reg: register address to control gating of this clock
  90. + * @bit_idx: which bit in the register controls gating of this clock
  91. + * @clk_gate_flags: gate-specific flags for this clock
  92. + * @lock: shared register lock for this clock
  93. + */
  94. +#define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
  95. + clk_gate_flags, lock) \
  96. + __devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
  97. + NULL, (flags), (reg), (bit_idx), \
  98. + (clk_gate_flags), (lock))
  99. void clk_unregister_gate(struct clk *clk);
  100. void clk_hw_unregister_gate(struct clk_hw *hw);
  101. int clk_gate_is_enabled(struct clk_hw *hw);