Skip to content

Commit ac2df52

Browse files
author
Sylwester Nawrocki
committed
clk: Add common __clk_get(), __clk_put() implementations
This patch adds common __clk_get(), __clk_put() clkdev helpers that replace their platform specific counterparts when the common clock API is used. The owner module pointer field is added to struct clk so a reference to the clock supplier module can be taken by the clock consumers. The owner module is assigned while the clock is being registered, in functions _clk_register() and __clk_register(). Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 3a3d2b0 commit ac2df52

File tree

7 files changed

+42
-0
lines changed

7 files changed

+42
-0
lines changed

arch/arm/include/asm/clkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
#include <linux/slab.h>
1616

17+
#ifndef CONFIG_COMMON_CLK
1718
#ifdef CONFIG_HAVE_MACH_CLKDEV
1819
#include <mach/clkdev.h>
1920
#else
2021
#define __clk_get(clk) ({ 1; })
2122
#define __clk_put(clk) do { } while (0)
2223
#endif
24+
#endif
2325

2426
static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
2527
{

arch/blackfin/include/asm/clkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
88
return kzalloc(size, GFP_KERNEL);
99
}
1010

11+
#ifndef CONFIG_COMMON_CLK
1112
#define __clk_put(clk)
1213
#define __clk_get(clk) ({ 1; })
14+
#endif
1315

1416
#endif

arch/mips/include/asm/clkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
#include <linux/slab.h>
1616

17+
#ifndef CONFIG_COMMON_CLK
1718
#define __clk_get(clk) ({ 1; })
1819
#define __clk_put(clk) do { } while (0)
20+
#endif
1921

2022
static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
2123
{

arch/sh/include/asm/clkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
2525
return kzalloc(size, GFP_KERNEL);
2626
}
2727

28+
#ifndef CONFIG_COMMON_CLK
2829
#define __clk_put(clk)
2930
#define __clk_get(clk) ({ 1; })
31+
#endif
3032

3133
#endif /* __CLKDEV_H__ */

drivers/clk/clk.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,10 @@ struct clk *__clk_register(struct device *dev, struct clk_hw *hw)
18131813
clk->flags = hw->init->flags;
18141814
clk->parent_names = hw->init->parent_names;
18151815
clk->num_parents = hw->init->num_parents;
1816+
if (dev && dev->driver)
1817+
clk->owner = dev->driver->owner;
1818+
else
1819+
clk->owner = NULL;
18161820

18171821
ret = __clk_init(dev, clk);
18181822
if (ret)
@@ -1833,6 +1837,8 @@ static int _clk_register(struct device *dev, struct clk_hw *hw, struct clk *clk)
18331837
goto fail_name;
18341838
}
18351839
clk->ops = hw->init->ops;
1840+
if (dev && dev->driver)
1841+
clk->owner = dev->driver->owner;
18361842
clk->hw = hw;
18371843
clk->flags = hw->init->flags;
18381844
clk->num_parents = hw->init->num_parents;
@@ -1973,6 +1979,26 @@ void devm_clk_unregister(struct device *dev, struct clk *clk)
19731979
}
19741980
EXPORT_SYMBOL_GPL(devm_clk_unregister);
19751981

1982+
/*
1983+
* clkdev helpers
1984+
*/
1985+
int __clk_get(struct clk *clk)
1986+
{
1987+
if (clk && !try_module_get(clk->owner))
1988+
return 0;
1989+
1990+
return 1;
1991+
}
1992+
1993+
void __clk_put(struct clk *clk)
1994+
{
1995+
if (WARN_ON_ONCE(IS_ERR(clk)))
1996+
return;
1997+
1998+
if (clk)
1999+
module_put(clk->owner);
2000+
}
2001+
19762002
/*** clk rate change notifiers ***/
19772003

19782004
/**

include/linux/clk-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525

2626
#ifdef CONFIG_COMMON_CLK
2727

28+
struct module;
29+
2830
struct clk {
2931
const char *name;
3032
const struct clk_ops *ops;
3133
struct clk_hw *hw;
34+
struct module *owner;
3235
struct clk *parent;
3336
const char **parent_names;
3437
struct clk **parents;

include/linux/clkdev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ int clk_add_alias(const char *, const char *, char *, struct device *);
4343
int clk_register_clkdev(struct clk *, const char *, const char *, ...);
4444
int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t);
4545

46+
#ifdef CONFIG_COMMON_CLK
47+
int __clk_get(struct clk *clk);
48+
void __clk_put(struct clk *clk);
49+
#endif
50+
4651
#endif

0 commit comments

Comments
 (0)