2 * linux/include/linux/clk-private.h
4 * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
5 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #ifndef __LINUX_CLK_PRIVATE_H
12 #define __LINUX_CLK_PRIVATE_H
14 #include <linux/clk-provider.h>
15 #include <linux/list.h>
18 * WARNING: Do not include clk-private.h from any file that implements struct
19 * clk_ops. Doing so is a layering violation!
21 * This header exists only to allow for statically initialized clock data. Any
22 * static clock data must be defined in a separate file from the logic that
23 * implements the clock operations for that same data.
26 #ifdef CONFIG_COMMON_CLK
30 const struct clk_ops *ops;
33 const char **parent_names;
38 unsigned long new_rate;
39 struct clk *new_parent;
40 struct clk *new_child;
42 unsigned int enable_count;
43 unsigned int prepare_count;
44 unsigned long accuracy;
45 struct hlist_head children;
46 struct hlist_node child_node;
47 unsigned int notifier_count;
48 #ifdef CONFIG_DEBUG_FS
49 struct dentry *dentry;
54 * DOC: Basic clock implementations common to many platforms
56 * Each basic clock hardware type is comprised of a structure describing the
57 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
58 * unique flags for that hardware type, a registration function and an
59 * alternative macro for static initialization
62 #define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
64 static struct clk _name = { \
67 .hw = &_name##_hw.hw, \
68 .parent_names = _parent_names, \
69 .num_parents = ARRAY_SIZE(_parent_names), \
70 .parents = _parents, \
71 .flags = _flags | CLK_IS_BASIC, \
74 #define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
76 static struct clk _name; \
77 static const char *_name##_parent_names[] = {}; \
78 static struct clk_fixed_rate _name##_hw = { \
82 .fixed_rate = _rate, \
83 .flags = _fixed_rate_flags, \
85 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
86 _name##_parent_names, NULL);
88 #define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
89 _flags, _reg, _bit_idx, \
91 static struct clk _name; \
92 static const char *_name##_parent_names[] = { \
95 static struct clk *_name##_parents[] = { \
98 static struct clk_gate _name##_hw = { \
103 .bit_idx = _bit_idx, \
104 .flags = _gate_flags, \
107 DEFINE_CLK(_name, clk_gate_ops, _flags, \
108 _name##_parent_names, _name##_parents);
110 #define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
111 _flags, _reg, _shift, _width, \
112 _divider_flags, _table, _lock) \
113 static struct clk _name; \
114 static const char *_name##_parent_names[] = { \
117 static struct clk *_name##_parents[] = { \
120 static struct clk_divider _name##_hw = { \
127 .flags = _divider_flags, \
131 DEFINE_CLK(_name, clk_divider_ops, _flags, \
132 _name##_parent_names, _name##_parents);
134 #define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
135 _flags, _reg, _shift, _width, \
136 _divider_flags, _lock) \
137 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
138 _flags, _reg, _shift, _width, \
139 _divider_flags, NULL, _lock)
141 #define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
142 _parent_ptr, _flags, _reg, \
143 _shift, _width, _divider_flags, \
145 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
146 _flags, _reg, _shift, _width, \
147 _divider_flags, _table, _lock) \
149 #define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
150 _reg, _shift, _width, \
152 static struct clk _name; \
153 static struct clk_mux _name##_hw = { \
159 .mask = BIT(_width) - 1, \
160 .flags = _mux_flags, \
163 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
166 #define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
167 _parent_ptr, _flags, \
169 static struct clk _name; \
170 static const char *_name##_parent_names[] = { \
173 static struct clk *_name##_parents[] = { \
176 static struct clk_fixed_factor _name##_hw = { \
183 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
184 _name##_parent_names, _name##_parents);
187 * __clk_init - initialize the data structures in a struct clk
188 * @dev: device initializing this clk, placeholder for now
189 * @clk: clk being initialized
191 * Initializes the lists in struct clk, queries the hardware for the
192 * parent and rate and sets them both.
194 * Any struct clk passed into __clk_init must have the following members
203 * It is not necessary to call clk_register if __clk_init is used directly with
204 * statically initialized clock data.
206 * Returns 0 on success, otherwise an error code.
208 int __clk_init(struct device *dev, struct clk *clk);
210 struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
212 #endif /* CONFIG_COMMON_CLK */
213 #endif /* CLK_PRIVATE_H */