Skip to content

Commit 815f0e7

Browse files
HoratiuVulturnoglitch
authored andcommitted
clk: gate: Add devm_clk_hw_register_gate()
Add devm_clk_hw_register_gate() - devres-managed version of clk_hw_register_gate() Suggested-by: Stephen Boyd <[email protected]> Signed-off-by: Horatiu Vultur <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Signed-off-by: Nicolas Ferre <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 54104ee commit 815f0e7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

drivers/clk/clk-gate.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/clk-provider.h>
10+
#include <linux/device.h>
1011
#include <linux/module.h>
1112
#include <linux/slab.h>
1213
#include <linux/io.h>
@@ -222,3 +223,37 @@ void clk_hw_unregister_gate(struct clk_hw *hw)
222223
kfree(gate);
223224
}
224225
EXPORT_SYMBOL_GPL(clk_hw_unregister_gate);
226+
227+
static void devm_clk_hw_release_gate(struct device *dev, void *res)
228+
{
229+
clk_hw_unregister_gate(*(struct clk_hw **)res);
230+
}
231+
232+
struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
233+
struct device_node *np, const char *name,
234+
const char *parent_name, const struct clk_hw *parent_hw,
235+
const struct clk_parent_data *parent_data,
236+
unsigned long flags,
237+
void __iomem *reg, u8 bit_idx,
238+
u8 clk_gate_flags, spinlock_t *lock)
239+
{
240+
struct clk_hw **ptr, *hw;
241+
242+
ptr = devres_alloc(devm_clk_hw_release_gate, sizeof(*ptr), GFP_KERNEL);
243+
if (!ptr)
244+
return ERR_PTR(-ENOMEM);
245+
246+
hw = __clk_hw_register_gate(dev, np, name, parent_name, parent_hw,
247+
parent_data, flags, reg, bit_idx,
248+
clk_gate_flags, lock);
249+
250+
if (!IS_ERR(hw)) {
251+
*ptr = hw;
252+
devres_add(dev, ptr);
253+
} else {
254+
devres_free(ptr);
255+
}
256+
257+
return hw;
258+
}
259+
EXPORT_SYMBOL_GPL(__devm_clk_hw_register_gate);

include/linux/clk-provider.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,13 @@ struct clk_hw *__clk_hw_register_gate(struct device *dev,
490490
unsigned long flags,
491491
void __iomem *reg, u8 bit_idx,
492492
u8 clk_gate_flags, spinlock_t *lock);
493+
struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
494+
struct device_node *np, const char *name,
495+
const char *parent_name, const struct clk_hw *parent_hw,
496+
const struct clk_parent_data *parent_data,
497+
unsigned long flags,
498+
void __iomem *reg, u8 bit_idx,
499+
u8 clk_gate_flags, spinlock_t *lock);
493500
struct clk *clk_register_gate(struct device *dev, const char *name,
494501
const char *parent_name, unsigned long flags,
495502
void __iomem *reg, u8 bit_idx,
@@ -544,6 +551,22 @@ struct clk *clk_register_gate(struct device *dev, const char *name,
544551
__clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
545552
(flags), (reg), (bit_idx), \
546553
(clk_gate_flags), (lock))
554+
/**
555+
* devm_clk_hw_register_gate - register a gate clock with the clock framework
556+
* @dev: device that is registering this clock
557+
* @name: name of this clock
558+
* @parent_name: name of this clock's parent
559+
* @flags: framework-specific flags for this clock
560+
* @reg: register address to control gating of this clock
561+
* @bit_idx: which bit in the register controls gating of this clock
562+
* @clk_gate_flags: gate-specific flags for this clock
563+
* @lock: shared register lock for this clock
564+
*/
565+
#define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
566+
clk_gate_flags, lock) \
567+
__devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
568+
NULL, (flags), (reg), (bit_idx), \
569+
(clk_gate_flags), (lock))
547570
void clk_unregister_gate(struct clk *clk);
548571
void clk_hw_unregister_gate(struct clk_hw *hw);
549572
int clk_gate_is_enabled(struct clk_hw *hw);

0 commit comments

Comments
 (0)