blob: e7032fdd45eb67f177e6d28808ba95cee411f18e [file] [log] [blame]
Mike Turquetteb24764902012-03-15 23:11:19 -07001/*
2 * linux/include/linux/clk-private.h
3 *
4 * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
5 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
6 *
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.
10 */
11#ifndef __LINUX_CLK_PRIVATE_H
12#define __LINUX_CLK_PRIVATE_H
13
14#include <linux/clk-provider.h>
15#include <linux/list.h>
16
17/*
18 * WARNING: Do not include clk-private.h from any file that implements struct
19 * clk_ops. Doing so is a layering violation!
20 *
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.
24 */
25
26#ifdef CONFIG_COMMON_CLK
27
28struct clk {
29 const char *name;
30 const struct clk_ops *ops;
31 struct clk_hw *hw;
32 struct clk *parent;
Mark Brownd305fb72012-03-21 20:01:20 +000033 const char **parent_names;
Mike Turquetteb24764902012-03-15 23:11:19 -070034 struct clk **parents;
35 u8 num_parents;
36 unsigned long rate;
37 unsigned long new_rate;
38 unsigned long flags;
39 unsigned int enable_count;
40 unsigned int prepare_count;
41 struct hlist_head children;
42 struct hlist_node child_node;
43 unsigned int notifier_count;
44#ifdef CONFIG_COMMON_CLK_DEBUG
45 struct dentry *dentry;
46#endif
47};
48
Mike Turquette9d9f78e2012-03-15 23:11:20 -070049/*
50 * DOC: Basic clock implementations common to many platforms
51 *
52 * Each basic clock hardware type is comprised of a structure describing the
53 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
54 * unique flags for that hardware type, a registration function and an
55 * alternative macro for static initialization
56 */
57
Mike Turquette9d9f78e2012-03-15 23:11:20 -070058#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
59 _fixed_rate_flags) \
60 static struct clk _name; \
61 static char *_name##_parent_names[] = {}; \
62 static struct clk_fixed_rate _name##_hw = { \
63 .hw = { \
64 .clk = &_name, \
65 }, \
66 .fixed_rate = _rate, \
67 .flags = _fixed_rate_flags, \
68 }; \
69 static struct clk _name = { \
70 .name = #_name, \
71 .ops = &clk_fixed_rate_ops, \
72 .hw = &_name##_hw.hw, \
73 .parent_names = _name##_parent_names, \
74 .num_parents = \
75 ARRAY_SIZE(_name##_parent_names), \
76 .flags = _flags, \
77 };
78
Mike Turquette9d9f78e2012-03-15 23:11:20 -070079#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
80 _flags, _reg, _bit_idx, \
81 _gate_flags, _lock) \
82 static struct clk _name; \
83 static char *_name##_parent_names[] = { \
84 _parent_name, \
85 }; \
86 static struct clk *_name##_parents[] = { \
87 _parent_ptr, \
88 }; \
89 static struct clk_gate _name##_hw = { \
90 .hw = { \
91 .clk = &_name, \
92 }, \
93 .reg = _reg, \
94 .bit_idx = _bit_idx, \
95 .flags = _gate_flags, \
96 .lock = _lock, \
97 }; \
98 static struct clk _name = { \
99 .name = #_name, \
100 .ops = &clk_gate_ops, \
101 .hw = &_name##_hw.hw, \
102 .parent_names = _name##_parent_names, \
103 .num_parents = \
104 ARRAY_SIZE(_name##_parent_names), \
105 .parents = _name##_parents, \
106 .flags = _flags, \
107 };
108
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700109#define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
110 _flags, _reg, _shift, _width, \
111 _divider_flags, _lock) \
112 static struct clk _name; \
113 static char *_name##_parent_names[] = { \
114 _parent_name, \
115 }; \
116 static struct clk *_name##_parents[] = { \
117 _parent_ptr, \
118 }; \
119 static struct clk_divider _name##_hw = { \
120 .hw = { \
121 .clk = &_name, \
122 }, \
123 .reg = _reg, \
124 .shift = _shift, \
125 .width = _width, \
126 .flags = _divider_flags, \
127 .lock = _lock, \
128 }; \
129 static struct clk _name = { \
130 .name = #_name, \
131 .ops = &clk_divider_ops, \
132 .hw = &_name##_hw.hw, \
133 .parent_names = _name##_parent_names, \
134 .num_parents = \
135 ARRAY_SIZE(_name##_parent_names), \
136 .parents = _name##_parents, \
137 .flags = _flags, \
138 };
139
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700140#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
141 _reg, _shift, _width, \
142 _mux_flags, _lock) \
143 static struct clk _name; \
144 static struct clk_mux _name##_hw = { \
145 .hw = { \
146 .clk = &_name, \
147 }, \
148 .reg = _reg, \
149 .shift = _shift, \
150 .width = _width, \
151 .flags = _mux_flags, \
152 .lock = _lock, \
153 }; \
154 static struct clk _name = { \
155 .name = #_name, \
156 .ops = &clk_mux_ops, \
157 .hw = &_name##_hw.hw, \
158 .parent_names = _parent_names, \
159 .num_parents = \
160 ARRAY_SIZE(_parent_names), \
161 .parents = _parents, \
162 .flags = _flags, \
163 };
164
Mike Turquetteb24764902012-03-15 23:11:19 -0700165/**
166 * __clk_init - initialize the data structures in a struct clk
167 * @dev: device initializing this clk, placeholder for now
168 * @clk: clk being initialized
169 *
170 * Initializes the lists in struct clk, queries the hardware for the
171 * parent and rate and sets them both.
172 *
173 * Any struct clk passed into __clk_init must have the following members
174 * populated:
175 * .name
176 * .ops
177 * .hw
178 * .parent_names
179 * .num_parents
180 * .flags
181 *
182 * It is not necessary to call clk_register if __clk_init is used directly with
183 * statically initialized clock data.
Mike Turquetted1302a32012-03-29 14:30:40 -0700184 *
185 * Returns 0 on success, otherwise an error code.
Mike Turquetteb24764902012-03-15 23:11:19 -0700186 */
Mike Turquetted1302a32012-03-29 14:30:40 -0700187int __clk_init(struct device *dev, struct clk *clk);
Mike Turquetteb24764902012-03-15 23:11:19 -0700188
189#endif /* CONFIG_COMMON_CLK */
190#endif /* CLK_PRIVATE_H */