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 struct hlist_head children;
45 struct hlist_node child_node;
46 unsigned int notifier_count;
47 #ifdef CONFIG_COMMON_CLK_DEBUG
48 struct dentry *dentry;
53 * DOC: Basic clock implementations common to many platforms
55 * Each basic clock hardware type is comprised of a structure describing the
56 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
57 * unique flags for that hardware type, a registration function and an
58 * alternative macro for static initialization
61 #define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
63 static struct clk _name = { \
66 .hw = &_name##_hw.hw, \
67 .parent_names = _parent_names, \
68 .num_parents = ARRAY_SIZE(_parent_names), \
69 .parents = _parents, \
70 .flags = _flags | CLK_IS_BASIC, \
73 #define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
75 static struct clk _name; \
76 static const char *_name##_parent_names[] = {}; \
77 static struct clk_fixed_rate _name##_hw = { \
81 .fixed_rate = _rate, \
82 .flags = _fixed_rate_flags, \
84 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
85 _name##_parent_names, NULL);
87 #define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
88 _flags, _reg, _bit_idx, \
90 static struct clk _name; \
91 static const char *_name##_parent_names[] = { \
94 static struct clk *_name##_parents[] = { \
97 static struct clk_gate _name##_hw = { \
102 .bit_idx = _bit_idx, \
103 .flags = _gate_flags, \
106 DEFINE_CLK(_name, clk_gate_ops, _flags, \
107 _name##_parent_names, _name##_parents);
109 #define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
110 _flags, _reg, _shift, _width, \
111 _divider_flags, _table, _lock) \
112 static struct clk _name; \
113 static const char *_name##_parent_names[] = { \
116 static struct clk *_name##_parents[] = { \
119 static struct clk_divider _name##_hw = { \
126 .flags = _divider_flags, \
130 DEFINE_CLK(_name, clk_divider_ops, _flags, \
131 _name##_parent_names, _name##_parents);
133 #define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
134 _flags, _reg, _shift, _width, \
135 _divider_flags, _lock) \
136 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
137 _flags, _reg, _shift, _width, \
138 _divider_flags, NULL, _lock)
140 #define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
141 _parent_ptr, _flags, _reg, \
142 _shift, _width, _divider_flags, \
144 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
145 _flags, _reg, _shift, _width, \
146 _divider_flags, _table, _lock) \
148 #define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
149 _reg, _shift, _width, \
151 static struct clk _name; \
152 static struct clk_mux _name##_hw = { \
158 .mask = BIT(_width) - 1, \
159 .flags = _mux_flags, \
162 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
165 #define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
166 _parent_ptr, _flags, \
168 static struct clk _name; \
169 static const char *_name##_parent_names[] = { \
172 static struct clk *_name##_parents[] = { \
175 static struct clk_fixed_factor _name##_hw = { \
182 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
183 _name##_parent_names, _name##_parents);
186 * __clk_init - initialize the data structures in a struct clk
187 * @dev: device initializing this clk, placeholder for now
188 * @clk: clk being initialized
190 * Initializes the lists in struct clk, queries the hardware for the
191 * parent and rate and sets them both.
193 * Any struct clk passed into __clk_init must have the following members
202 * It is not necessary to call clk_register if __clk_init is used directly with
203 * statically initialized clock data.
205 * Returns 0 on success, otherwise an error code.
207 int __clk_init(struct device *dev, struct clk *clk);
209 struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
211 #endif /* CONFIG_COMMON_CLK */
212 #endif /* CLK_PRIVATE_H */