Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+42
+2
arch/arm/include/asm/clkdev.h
··· 14 14 15 15 #include <linux/slab.h> 16 16 17 + #ifndef CONFIG_COMMON_CLK 17 18 #ifdef CONFIG_HAVE_MACH_CLKDEV 18 19 #include <mach/clkdev.h> 19 20 #else 20 21 #define __clk_get(clk) ({ 1; }) 21 22 #define __clk_put(clk) do { } while (0) 23 + #endif 22 24 #endif 23 25 24 26 static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
+2
arch/blackfin/include/asm/clkdev.h
··· 8 8 return kzalloc(size, GFP_KERNEL); 9 9 } 10 10 11 + #ifndef CONFIG_COMMON_CLK 11 12 #define __clk_put(clk) 12 13 #define __clk_get(clk) ({ 1; }) 14 + #endif 13 15 14 16 #endif
+2
arch/mips/include/asm/clkdev.h
··· 14 14 15 15 #include <linux/slab.h> 16 16 17 + #ifndef CONFIG_COMMON_CLK 17 18 #define __clk_get(clk) ({ 1; }) 18 19 #define __clk_put(clk) do { } while (0) 20 + #endif 19 21 20 22 static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) 21 23 {
+2
arch/sh/include/asm/clkdev.h
··· 25 25 return kzalloc(size, GFP_KERNEL); 26 26 } 27 27 28 + #ifndef CONFIG_COMMON_CLK 28 29 #define __clk_put(clk) 29 30 #define __clk_get(clk) ({ 1; }) 31 + #endif 30 32 31 33 #endif /* __CLKDEV_H__ */
+26
drivers/clk/clk.c
··· 1813 1813 clk->flags = hw->init->flags; 1814 1814 clk->parent_names = hw->init->parent_names; 1815 1815 clk->num_parents = hw->init->num_parents; 1816 + if (dev && dev->driver) 1817 + clk->owner = dev->driver->owner; 1818 + else 1819 + clk->owner = NULL; 1816 1820 1817 1821 ret = __clk_init(dev, clk); 1818 1822 if (ret) ··· 1837 1833 goto fail_name; 1838 1834 } 1839 1835 clk->ops = hw->init->ops; 1836 + if (dev && dev->driver) 1837 + clk->owner = dev->driver->owner; 1840 1838 clk->hw = hw; 1841 1839 clk->flags = hw->init->flags; 1842 1840 clk->num_parents = hw->init->num_parents; ··· 1978 1972 WARN_ON(devres_release(dev, devm_clk_release, devm_clk_match, clk)); 1979 1973 } 1980 1974 EXPORT_SYMBOL_GPL(devm_clk_unregister); 1975 + 1976 + /* 1977 + * clkdev helpers 1978 + */ 1979 + int __clk_get(struct clk *clk) 1980 + { 1981 + if (clk && !try_module_get(clk->owner)) 1982 + return 0; 1983 + 1984 + return 1; 1985 + } 1986 + 1987 + void __clk_put(struct clk *clk) 1988 + { 1989 + if (WARN_ON_ONCE(IS_ERR(clk))) 1990 + return; 1991 + 1992 + if (clk) 1993 + module_put(clk->owner); 1994 + } 1981 1995 1982 1996 /*** clk rate change notifiers ***/ 1983 1997
+3
include/linux/clk-private.h
··· 25 25 26 26 #ifdef CONFIG_COMMON_CLK 27 27 28 + struct module; 29 + 28 30 struct clk { 29 31 const char *name; 30 32 const struct clk_ops *ops; 31 33 struct clk_hw *hw; 34 + struct module *owner; 32 35 struct clk *parent; 33 36 const char **parent_names; 34 37 struct clk **parents;
+5
include/linux/clkdev.h
··· 43 43 int clk_register_clkdev(struct clk *, const char *, const char *, ...); 44 44 int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t); 45 45 46 + #ifdef CONFIG_COMMON_CLK 47 + int __clk_get(struct clk *clk); 48 + void __clk_put(struct clk *clk); 49 + #endif 50 + 46 51 #endif