提交 ac2df527 编写于 作者: S Sylwester Nawrocki

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: NSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: NKyungmin Park <kyungmin.park@samsung.com>
Acked-by: NRussell King <rmk+kernel@arm.linux.org.uk>
上级 3a3d2b05
...@@ -14,12 +14,14 @@ ...@@ -14,12 +14,14 @@
#include <linux/slab.h> #include <linux/slab.h>
#ifndef CONFIG_COMMON_CLK
#ifdef CONFIG_HAVE_MACH_CLKDEV #ifdef CONFIG_HAVE_MACH_CLKDEV
#include <mach/clkdev.h> #include <mach/clkdev.h>
#else #else
#define __clk_get(clk) ({ 1; }) #define __clk_get(clk) ({ 1; })
#define __clk_put(clk) do { } while (0) #define __clk_put(clk) do { } while (0)
#endif #endif
#endif
static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
{ {
......
...@@ -8,7 +8,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) ...@@ -8,7 +8,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
return kzalloc(size, GFP_KERNEL); return kzalloc(size, GFP_KERNEL);
} }
#ifndef CONFIG_COMMON_CLK
#define __clk_put(clk) #define __clk_put(clk)
#define __clk_get(clk) ({ 1; }) #define __clk_get(clk) ({ 1; })
#endif
#endif #endif
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
#include <linux/slab.h> #include <linux/slab.h>
#ifndef CONFIG_COMMON_CLK
#define __clk_get(clk) ({ 1; }) #define __clk_get(clk) ({ 1; })
#define __clk_put(clk) do { } while (0) #define __clk_put(clk) do { } while (0)
#endif
static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
{ {
......
...@@ -25,7 +25,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size) ...@@ -25,7 +25,9 @@ static inline struct clk_lookup_alloc *__clkdev_alloc(size_t size)
return kzalloc(size, GFP_KERNEL); return kzalloc(size, GFP_KERNEL);
} }
#ifndef CONFIG_COMMON_CLK
#define __clk_put(clk) #define __clk_put(clk)
#define __clk_get(clk) ({ 1; }) #define __clk_get(clk) ({ 1; })
#endif
#endif /* __CLKDEV_H__ */ #endif /* __CLKDEV_H__ */
...@@ -1813,6 +1813,10 @@ struct clk *__clk_register(struct device *dev, struct clk_hw *hw) ...@@ -1813,6 +1813,10 @@ struct clk *__clk_register(struct device *dev, struct clk_hw *hw)
clk->flags = hw->init->flags; clk->flags = hw->init->flags;
clk->parent_names = hw->init->parent_names; clk->parent_names = hw->init->parent_names;
clk->num_parents = hw->init->num_parents; clk->num_parents = hw->init->num_parents;
if (dev && dev->driver)
clk->owner = dev->driver->owner;
else
clk->owner = NULL;
ret = __clk_init(dev, clk); ret = __clk_init(dev, clk);
if (ret) if (ret)
...@@ -1833,6 +1837,8 @@ static int _clk_register(struct device *dev, struct clk_hw *hw, struct clk *clk) ...@@ -1833,6 +1837,8 @@ static int _clk_register(struct device *dev, struct clk_hw *hw, struct clk *clk)
goto fail_name; goto fail_name;
} }
clk->ops = hw->init->ops; clk->ops = hw->init->ops;
if (dev && dev->driver)
clk->owner = dev->driver->owner;
clk->hw = hw; clk->hw = hw;
clk->flags = hw->init->flags; clk->flags = hw->init->flags;
clk->num_parents = hw->init->num_parents; clk->num_parents = hw->init->num_parents;
...@@ -1973,6 +1979,26 @@ void devm_clk_unregister(struct device *dev, struct clk *clk) ...@@ -1973,6 +1979,26 @@ void devm_clk_unregister(struct device *dev, struct clk *clk)
} }
EXPORT_SYMBOL_GPL(devm_clk_unregister); EXPORT_SYMBOL_GPL(devm_clk_unregister);
/*
* clkdev helpers
*/
int __clk_get(struct clk *clk)
{
if (clk && !try_module_get(clk->owner))
return 0;
return 1;
}
void __clk_put(struct clk *clk)
{
if (WARN_ON_ONCE(IS_ERR(clk)))
return;
if (clk)
module_put(clk->owner);
}
/*** clk rate change notifiers ***/ /*** clk rate change notifiers ***/
/** /**
......
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
#ifdef CONFIG_COMMON_CLK #ifdef CONFIG_COMMON_CLK
struct module;
struct clk { struct clk {
const char *name; const char *name;
const struct clk_ops *ops; const struct clk_ops *ops;
struct clk_hw *hw; struct clk_hw *hw;
struct module *owner;
struct clk *parent; struct clk *parent;
const char **parent_names; const char **parent_names;
struct clk **parents; struct clk **parents;
......
...@@ -43,4 +43,9 @@ int clk_add_alias(const char *, const char *, char *, struct device *); ...@@ -43,4 +43,9 @@ int clk_add_alias(const char *, const char *, char *, struct device *);
int clk_register_clkdev(struct clk *, const char *, const char *, ...); int clk_register_clkdev(struct clk *, const char *, const char *, ...);
int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t); int clk_register_clkdevs(struct clk *, struct clk_lookup *, size_t);
#ifdef CONFIG_COMMON_CLK
int __clk_get(struct clk *clk);
void __clk_put(struct clk *clk);
#endif
#endif #endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册