blob: 72c65e05450b2d48df70716d2a694b4d624177a9 [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>
Sylwester Nawrockifcb0ee62013-08-24 15:00:10 +020015#include <linux/kref.h>
Mike Turquetteb24764902012-03-15 23:11:19 -070016#include <linux/list.h>
17
18/*
19 * WARNING: Do not include clk-private.h from any file that implements struct
20 * clk_ops. Doing so is a layering violation!
21 *
22 * This header exists only to allow for statically initialized clock data. Any
23 * static clock data must be defined in a separate file from the logic that
24 * implements the clock operations for that same data.
25 */
26
27#ifdef CONFIG_COMMON_CLK
28
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020029struct module;
30
Mike Turquetteb24764902012-03-15 23:11:19 -070031struct clk {
32 const char *name;
33 const struct clk_ops *ops;
34 struct clk_hw *hw;
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020035 struct module *owner;
Mike Turquetteb24764902012-03-15 23:11:19 -070036 struct clk *parent;
Mark Brownd305fb72012-03-21 20:01:20 +000037 const char **parent_names;
Mike Turquetteb24764902012-03-15 23:11:19 -070038 struct clk **parents;
39 u8 num_parents;
James Hogan71472c02013-07-29 12:25:00 +010040 u8 new_parent_index;
Mike Turquetteb24764902012-03-15 23:11:19 -070041 unsigned long rate;
42 unsigned long new_rate;
James Hogan71472c02013-07-29 12:25:00 +010043 struct clk *new_parent;
44 struct clk *new_child;
Mike Turquetteb24764902012-03-15 23:11:19 -070045 unsigned long flags;
46 unsigned int enable_count;
47 unsigned int prepare_count;
48 struct hlist_head children;
49 struct hlist_node child_node;
50 unsigned int notifier_count;
51#ifdef CONFIG_COMMON_CLK_DEBUG
52 struct dentry *dentry;
53#endif
Sylwester Nawrockifcb0ee62013-08-24 15:00:10 +020054 struct kref ref;
Mike Turquetteb24764902012-03-15 23:11:19 -070055};
56
Mike Turquette9d9f78e2012-03-15 23:11:20 -070057/*
58 * DOC: Basic clock implementations common to many platforms
59 *
60 * Each basic clock hardware type is comprised of a structure describing the
61 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
62 * unique flags for that hardware type, a registration function and an
63 * alternative macro for static initialization
64 */
65
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053066#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
67 _parents) \
68 static struct clk _name = { \
69 .name = #_name, \
70 .ops = &_ops, \
71 .hw = &_name##_hw.hw, \
72 .parent_names = _parent_names, \
73 .num_parents = ARRAY_SIZE(_parent_names), \
74 .parents = _parents, \
Rajendra Nayakf7d8caa2012-06-01 14:02:47 +053075 .flags = _flags | CLK_IS_BASIC, \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053076 }
77
Mike Turquette9d9f78e2012-03-15 23:11:20 -070078#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
79 _fixed_rate_flags) \
80 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053081 static const char *_name##_parent_names[] = {}; \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070082 static struct clk_fixed_rate _name##_hw = { \
83 .hw = { \
84 .clk = &_name, \
85 }, \
86 .fixed_rate = _rate, \
87 .flags = _fixed_rate_flags, \
88 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053089 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
90 _name##_parent_names, NULL);
Mike Turquette9d9f78e2012-03-15 23:11:20 -070091
Mike Turquette9d9f78e2012-03-15 23:11:20 -070092#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
93 _flags, _reg, _bit_idx, \
94 _gate_flags, _lock) \
95 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053096 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070097 _parent_name, \
98 }; \
99 static struct clk *_name##_parents[] = { \
100 _parent_ptr, \
101 }; \
102 static struct clk_gate _name##_hw = { \
103 .hw = { \
104 .clk = &_name, \
105 }, \
106 .reg = _reg, \
107 .bit_idx = _bit_idx, \
108 .flags = _gate_flags, \
109 .lock = _lock, \
110 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530111 DEFINE_CLK(_name, clk_gate_ops, _flags, \
112 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700113
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530114#define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700115 _flags, _reg, _shift, _width, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530116 _divider_flags, _table, _lock) \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700117 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +0530118 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700119 _parent_name, \
120 }; \
121 static struct clk *_name##_parents[] = { \
122 _parent_ptr, \
123 }; \
124 static struct clk_divider _name##_hw = { \
125 .hw = { \
126 .clk = &_name, \
127 }, \
128 .reg = _reg, \
129 .shift = _shift, \
130 .width = _width, \
131 .flags = _divider_flags, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530132 .table = _table, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700133 .lock = _lock, \
134 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530135 DEFINE_CLK(_name, clk_divider_ops, _flags, \
136 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700137
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530138#define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
139 _flags, _reg, _shift, _width, \
140 _divider_flags, _lock) \
141 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
142 _flags, _reg, _shift, _width, \
143 _divider_flags, NULL, _lock)
144
145#define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
146 _parent_ptr, _flags, _reg, \
147 _shift, _width, _divider_flags, \
148 _table, _lock) \
149 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
150 _flags, _reg, _shift, _width, \
151 _divider_flags, _table, _lock) \
152
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700153#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
154 _reg, _shift, _width, \
155 _mux_flags, _lock) \
156 static struct clk _name; \
157 static struct clk_mux _name##_hw = { \
158 .hw = { \
159 .clk = &_name, \
160 }, \
161 .reg = _reg, \
162 .shift = _shift, \
Peter De Schrijverce4f3312013-03-22 14:07:53 +0200163 .mask = BIT(_width) - 1, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700164 .flags = _mux_flags, \
165 .lock = _lock, \
166 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530167 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
168 _parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700169
Sascha Hauerf0948f52012-05-03 15:36:14 +0530170#define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
171 _parent_ptr, _flags, \
172 _mult, _div) \
173 static struct clk _name; \
174 static const char *_name##_parent_names[] = { \
175 _parent_name, \
176 }; \
177 static struct clk *_name##_parents[] = { \
178 _parent_ptr, \
179 }; \
180 static struct clk_fixed_factor _name##_hw = { \
181 .hw = { \
182 .clk = &_name, \
183 }, \
184 .mult = _mult, \
185 .div = _div, \
186 }; \
187 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
188 _name##_parent_names, _name##_parents);
189
Mike Turquetteb24764902012-03-15 23:11:19 -0700190/**
191 * __clk_init - initialize the data structures in a struct clk
192 * @dev: device initializing this clk, placeholder for now
193 * @clk: clk being initialized
194 *
195 * Initializes the lists in struct clk, queries the hardware for the
196 * parent and rate and sets them both.
197 *
198 * Any struct clk passed into __clk_init must have the following members
199 * populated:
200 * .name
201 * .ops
202 * .hw
203 * .parent_names
204 * .num_parents
205 * .flags
206 *
207 * It is not necessary to call clk_register if __clk_init is used directly with
208 * statically initialized clock data.
Mike Turquetted1302a32012-03-29 14:30:40 -0700209 *
210 * Returns 0 on success, otherwise an error code.
Mike Turquetteb24764902012-03-15 23:11:19 -0700211 */
Mike Turquetted1302a32012-03-29 14:30:40 -0700212int __clk_init(struct device *dev, struct clk *clk);
Mike Turquetteb24764902012-03-15 23:11:19 -0700213
Saravana Kannan0197b3e2012-04-25 22:58:56 -0700214struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
215
Mike Turquetteb24764902012-03-15 23:11:19 -0700216#endif /* CONFIG_COMMON_CLK */
217#endif /* CLK_PRIVATE_H */