blob: accb517e77e953cdb48e99a80b9a6f7c3ccb8ffd [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;
James Hogan71472c02013-07-29 12:25:00 +010036 u8 new_parent_index;
Mike Turquetteb24764902012-03-15 23:11:19 -070037 unsigned long rate;
38 unsigned long new_rate;
James Hogan71472c02013-07-29 12:25:00 +010039 struct clk *new_parent;
40 struct clk *new_child;
Mike Turquetteb24764902012-03-15 23:11:19 -070041 unsigned long flags;
42 unsigned int enable_count;
43 unsigned int prepare_count;
Boris BREZILLON5279fc42013-12-21 10:34:47 +010044 unsigned long accuracy;
Mike Turquetteb24764902012-03-15 23:11:19 -070045 struct hlist_head children;
46 struct hlist_node child_node;
47 unsigned int notifier_count;
48#ifdef CONFIG_COMMON_CLK_DEBUG
49 struct dentry *dentry;
50#endif
51};
52
Mike Turquette9d9f78e2012-03-15 23:11:20 -070053/*
54 * DOC: Basic clock implementations common to many platforms
55 *
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
60 */
61
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053062#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
63 _parents) \
64 static struct clk _name = { \
65 .name = #_name, \
66 .ops = &_ops, \
67 .hw = &_name##_hw.hw, \
68 .parent_names = _parent_names, \
69 .num_parents = ARRAY_SIZE(_parent_names), \
70 .parents = _parents, \
Rajendra Nayakf7d8caa2012-06-01 14:02:47 +053071 .flags = _flags | CLK_IS_BASIC, \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053072 }
73
Mike Turquette9d9f78e2012-03-15 23:11:20 -070074#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
75 _fixed_rate_flags) \
76 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053077 static const char *_name##_parent_names[] = {}; \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070078 static struct clk_fixed_rate _name##_hw = { \
79 .hw = { \
80 .clk = &_name, \
81 }, \
82 .fixed_rate = _rate, \
83 .flags = _fixed_rate_flags, \
84 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053085 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
86 _name##_parent_names, NULL);
Mike Turquette9d9f78e2012-03-15 23:11:20 -070087
Mike Turquette9d9f78e2012-03-15 23:11:20 -070088#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
89 _flags, _reg, _bit_idx, \
90 _gate_flags, _lock) \
91 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +053092 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -070093 _parent_name, \
94 }; \
95 static struct clk *_name##_parents[] = { \
96 _parent_ptr, \
97 }; \
98 static struct clk_gate _name##_hw = { \
99 .hw = { \
100 .clk = &_name, \
101 }, \
102 .reg = _reg, \
103 .bit_idx = _bit_idx, \
104 .flags = _gate_flags, \
105 .lock = _lock, \
106 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530107 DEFINE_CLK(_name, clk_gate_ops, _flags, \
108 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700109
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530110#define _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700111 _flags, _reg, _shift, _width, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530112 _divider_flags, _table, _lock) \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700113 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +0530114 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700115 _parent_name, \
116 }; \
117 static struct clk *_name##_parents[] = { \
118 _parent_ptr, \
119 }; \
120 static struct clk_divider _name##_hw = { \
121 .hw = { \
122 .clk = &_name, \
123 }, \
124 .reg = _reg, \
125 .shift = _shift, \
126 .width = _width, \
127 .flags = _divider_flags, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530128 .table = _table, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700129 .lock = _lock, \
130 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530131 DEFINE_CLK(_name, clk_divider_ops, _flags, \
132 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700133
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530134#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)
140
141#define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
142 _parent_ptr, _flags, _reg, \
143 _shift, _width, _divider_flags, \
144 _table, _lock) \
145 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
146 _flags, _reg, _shift, _width, \
147 _divider_flags, _table, _lock) \
148
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700149#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
150 _reg, _shift, _width, \
151 _mux_flags, _lock) \
152 static struct clk _name; \
153 static struct clk_mux _name##_hw = { \
154 .hw = { \
155 .clk = &_name, \
156 }, \
157 .reg = _reg, \
158 .shift = _shift, \
Peter De Schrijverce4f3312013-03-22 14:07:53 +0200159 .mask = BIT(_width) - 1, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700160 .flags = _mux_flags, \
161 .lock = _lock, \
162 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530163 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
164 _parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700165
Sascha Hauerf0948f52012-05-03 15:36:14 +0530166#define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
167 _parent_ptr, _flags, \
168 _mult, _div) \
169 static struct clk _name; \
170 static const char *_name##_parent_names[] = { \
171 _parent_name, \
172 }; \
173 static struct clk *_name##_parents[] = { \
174 _parent_ptr, \
175 }; \
176 static struct clk_fixed_factor _name##_hw = { \
177 .hw = { \
178 .clk = &_name, \
179 }, \
180 .mult = _mult, \
181 .div = _div, \
182 }; \
183 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
184 _name##_parent_names, _name##_parents);
185
Mike Turquetteb24764902012-03-15 23:11:19 -0700186/**
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
190 *
191 * Initializes the lists in struct clk, queries the hardware for the
192 * parent and rate and sets them both.
193 *
194 * Any struct clk passed into __clk_init must have the following members
195 * populated:
196 * .name
197 * .ops
198 * .hw
199 * .parent_names
200 * .num_parents
201 * .flags
202 *
203 * It is not necessary to call clk_register if __clk_init is used directly with
204 * statically initialized clock data.
Mike Turquetted1302a32012-03-29 14:30:40 -0700205 *
206 * Returns 0 on success, otherwise an error code.
Mike Turquetteb24764902012-03-15 23:11:19 -0700207 */
Mike Turquetted1302a32012-03-29 14:30:40 -0700208int __clk_init(struct device *dev, struct clk *clk);
Mike Turquetteb24764902012-03-15 23:11:19 -0700209
Saravana Kannan0197b3e2012-04-25 22:58:56 -0700210struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
211
Mike Turquetteb24764902012-03-15 23:11:19 -0700212#endif /* CONFIG_COMMON_CLK */
213#endif /* CLK_PRIVATE_H */