blob: 8cb1865e7d9d2098173173254f81aed96a8991f7 [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
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020028struct module;
29
Mike Turquetteb24764902012-03-15 23:11:19 -070030struct clk {
31 const char *name;
32 const struct clk_ops *ops;
33 struct clk_hw *hw;
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020034 struct module *owner;
Mike Turquetteb24764902012-03-15 23:11:19 -070035 struct clk *parent;
Mark Brownd305fb72012-03-21 20:01:20 +000036 const char **parent_names;
Mike Turquetteb24764902012-03-15 23:11:19 -070037 struct clk **parents;
38 u8 num_parents;
James Hogan71472c02013-07-29 12:25:00 +010039 u8 new_parent_index;
Mike Turquetteb24764902012-03-15 23:11:19 -070040 unsigned long rate;
41 unsigned long new_rate;
James Hogan71472c02013-07-29 12:25:00 +010042 struct clk *new_parent;
43 struct clk *new_child;
Mike Turquetteb24764902012-03-15 23:11:19 -070044 unsigned long flags;
45 unsigned int enable_count;
46 unsigned int prepare_count;
47 struct hlist_head children;
48 struct hlist_node child_node;
49 unsigned int notifier_count;
50#ifdef CONFIG_COMMON_CLK_DEBUG
51 struct dentry *dentry;
52#endif
53};
54
Mike Turquette9d9f78e2012-03-15 23:11:20 -070055/*
56 * DOC: Basic clock implementations common to many platforms
57 *
58 * Each basic clock hardware type is comprised of a structure describing the
59 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
60 * unique flags for that hardware type, a registration function and an
61 * alternative macro for static initialization
62 */
63
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053064#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
65 _parents) \
66 static struct clk _name = { \
67 .name = #_name, \
68 .ops = &_ops, \
69 .hw = &_name##_hw.hw, \
70 .parent_names = _parent_names, \
71 .num_parents = ARRAY_SIZE(_parent_names), \
72 .parents = _parents, \
Rajendra Nayakf7d8caa2012-06-01 14:02:47 +053073 .flags = _flags | CLK_IS_BASIC, \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053074 }
75
Mike Turquette9d9f78e2012-03-15 23:11:20 -070076#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
77 _fixed_rate_flags) \
78 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053079 static const char *_name##_parent_names[] = {}; \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070080 static struct clk_fixed_rate _name##_hw = { \
81 .hw = { \
82 .clk = &_name, \
83 }, \
84 .fixed_rate = _rate, \
85 .flags = _fixed_rate_flags, \
86 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053087 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
88 _name##_parent_names, NULL);
Mike Turquette9d9f78e2012-03-15 23:11:20 -070089
Mike Turquette9d9f78e2012-03-15 23:11:20 -070090#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
91 _flags, _reg, _bit_idx, \
92 _gate_flags, _lock) \
93 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053094 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070095 _parent_name, \
96 }; \
97 static struct clk *_name##_parents[] = { \
98 _parent_ptr, \
99 }; \
100 static struct clk_gate _name##_hw = { \
101 .hw = { \
102 .clk = &_name, \
103 }, \
104 .reg = _reg, \
105 .bit_idx = _bit_idx, \
106 .flags = _gate_flags, \
107 .lock = _lock, \
108 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530109 DEFINE_CLK(_name, clk_gate_ops, _flags, \
110 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700111
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530112#define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700113 _flags, _reg, _shift, _width, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530114 _divider_flags, _table, _lock) \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700115 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +0530116 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700117 _parent_name, \
118 }; \
119 static struct clk *_name##_parents[] = { \
120 _parent_ptr, \
121 }; \
122 static struct clk_divider _name##_hw = { \
123 .hw = { \
124 .clk = &_name, \
125 }, \
126 .reg = _reg, \
127 .shift = _shift, \
128 .width = _width, \
129 .flags = _divider_flags, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530130 .table = _table, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700131 .lock = _lock, \
132 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530133 DEFINE_CLK(_name, clk_divider_ops, _flags, \
134 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700135
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530136#define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
137 _flags, _reg, _shift, _width, \
138 _divider_flags, _lock) \
139 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
140 _flags, _reg, _shift, _width, \
141 _divider_flags, NULL, _lock)
142
143#define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
144 _parent_ptr, _flags, _reg, \
145 _shift, _width, _divider_flags, \
146 _table, _lock) \
147 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
148 _flags, _reg, _shift, _width, \
149 _divider_flags, _table, _lock) \
150
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700151#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
152 _reg, _shift, _width, \
153 _mux_flags, _lock) \
154 static struct clk _name; \
155 static struct clk_mux _name##_hw = { \
156 .hw = { \
157 .clk = &_name, \
158 }, \
159 .reg = _reg, \
160 .shift = _shift, \
Peter De Schrijverce4f3312013-03-22 14:07:53 +0200161 .mask = BIT(_width) - 1, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700162 .flags = _mux_flags, \
163 .lock = _lock, \
164 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530165 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
166 _parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700167
Sascha Hauerf0948f52012-05-03 15:36:14 +0530168#define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
169 _parent_ptr, _flags, \
170 _mult, _div) \
171 static struct clk _name; \
172 static const char *_name##_parent_names[] = { \
173 _parent_name, \
174 }; \
175 static struct clk *_name##_parents[] = { \
176 _parent_ptr, \
177 }; \
178 static struct clk_fixed_factor _name##_hw = { \
179 .hw = { \
180 .clk = &_name, \
181 }, \
182 .mult = _mult, \
183 .div = _div, \
184 }; \
185 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
186 _name##_parent_names, _name##_parents);
187
Mike Turquetteb24764902012-03-15 23:11:19 -0700188/**
189 * __clk_init - initialize the data structures in a struct clk
190 * @dev: device initializing this clk, placeholder for now
191 * @clk: clk being initialized
192 *
193 * Initializes the lists in struct clk, queries the hardware for the
194 * parent and rate and sets them both.
195 *
196 * Any struct clk passed into __clk_init must have the following members
197 * populated:
198 * .name
199 * .ops
200 * .hw
201 * .parent_names
202 * .num_parents
203 * .flags
204 *
205 * It is not necessary to call clk_register if __clk_init is used directly with
206 * statically initialized clock data.
Mike Turquetted1302a32012-03-29 14:30:40 -0700207 *
208 * Returns 0 on success, otherwise an error code.
Mike Turquetteb24764902012-03-15 23:11:19 -0700209 */
Mike Turquetted1302a32012-03-29 14:30:40 -0700210int __clk_init(struct device *dev, struct clk *clk);
Mike Turquetteb24764902012-03-15 23:11:19 -0700211
Saravana Kannan0197b3e2012-04-25 22:58:56 -0700212struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
213
Mike Turquetteb24764902012-03-15 23:11:19 -0700214#endif /* CONFIG_COMMON_CLK */
215#endif /* CLK_PRIVATE_H */