blob: 228a98724b1e3f4cf0ee67b07c3e81e9cf724af8 [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>
Badhri Jagan Sridharan3a3804b2015-03-19 11:53:29 -070016#include <linux/ktime.h>
Mike Turquetteb24764902012-03-15 23:11:19 -070017#include <linux/list.h>
Badhri Jagan Sridharan3a3804b2015-03-19 11:53:29 -070018#include <linux/rbtree.h>
Mike Turquetteb24764902012-03-15 23:11:19 -070019
20/*
21 * WARNING: Do not include clk-private.h from any file that implements struct
22 * clk_ops. Doing so is a layering violation!
23 *
24 * This header exists only to allow for statically initialized clock data. Any
25 * static clock data must be defined in a separate file from the logic that
26 * implements the clock operations for that same data.
27 */
28
29#ifdef CONFIG_COMMON_CLK
30
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020031struct module;
32
Badhri Jagan Sridharan3a3804b2015-03-19 11:53:29 -070033#ifdef CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING
34struct freq_stats {
35 ktime_t time_spent;
36 unsigned long rate;
37 struct rb_node node;
38};
39#endif /*CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING*/
40
Mike Turquetteb24764902012-03-15 23:11:19 -070041struct clk {
42 const char *name;
43 const struct clk_ops *ops;
44 struct clk_hw *hw;
Sylwester Nawrockiac2df522013-08-24 20:10:41 +020045 struct module *owner;
Mike Turquetteb24764902012-03-15 23:11:19 -070046 struct clk *parent;
Mark Brownd305fb72012-03-21 20:01:20 +000047 const char **parent_names;
Mike Turquetteb24764902012-03-15 23:11:19 -070048 struct clk **parents;
49 u8 num_parents;
James Hogan71472c02013-07-29 12:25:00 +010050 u8 new_parent_index;
Mike Turquetteb24764902012-03-15 23:11:19 -070051 unsigned long rate;
52 unsigned long new_rate;
James Hogan71472c02013-07-29 12:25:00 +010053 struct clk *new_parent;
54 struct clk *new_child;
Mike Turquetteb24764902012-03-15 23:11:19 -070055 unsigned long flags;
56 unsigned int enable_count;
57 unsigned int prepare_count;
Boris BREZILLON5279fc42013-12-21 10:34:47 +010058 unsigned long accuracy;
Mike Turquettee59c5372014-02-18 21:21:25 -080059 int phase;
Mike Turquetteb24764902012-03-15 23:11:19 -070060 struct hlist_head children;
61 struct hlist_node child_node;
Stephen Boyd6314b672014-09-04 23:37:49 -070062 struct hlist_node debug_node;
Mike Turquetteb24764902012-03-15 23:11:19 -070063 unsigned int notifier_count;
Mike Turquetteea72dc22013-12-18 21:38:52 -080064#ifdef CONFIG_DEBUG_FS
Mike Turquetteb24764902012-03-15 23:11:19 -070065 struct dentry *dentry;
Badhri Jagan Sridharan3a3804b2015-03-19 11:53:29 -070066#ifdef CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING
67 struct rb_root freq_stats_table;
68 struct freq_stats *current_freq_stats;
69 ktime_t default_freq_time;
70 ktime_t start_time;
71#endif /* CONFIG_COMMON_CLK_FREQ_STATS_ACCOUNTING*/
72
Mike Turquetteb24764902012-03-15 23:11:19 -070073#endif
Sylwester Nawrockifcb0ee62013-08-24 15:00:10 +020074 struct kref ref;
Mike Turquetteb24764902012-03-15 23:11:19 -070075};
76
Mike Turquette9d9f78e2012-03-15 23:11:20 -070077/*
78 * DOC: Basic clock implementations common to many platforms
79 *
80 * Each basic clock hardware type is comprised of a structure describing the
81 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
82 * unique flags for that hardware type, a registration function and an
83 * alternative macro for static initialization
84 */
85
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053086#define DEFINE_CLK(_name, _ops, _flags, _parent_names, \
87 _parents) \
88 static struct clk _name = { \
89 .name = #_name, \
90 .ops = &_ops, \
91 .hw = &_name##_hw.hw, \
92 .parent_names = _parent_names, \
93 .num_parents = ARRAY_SIZE(_parent_names), \
94 .parents = _parents, \
Rajendra Nayakf7d8caa2012-06-01 14:02:47 +053095 .flags = _flags | CLK_IS_BASIC, \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +053096 }
97
Mike Turquette9d9f78e2012-03-15 23:11:20 -070098#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, \
99 _fixed_rate_flags) \
100 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +0530101 static const char *_name##_parent_names[] = {}; \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700102 static struct clk_fixed_rate _name##_hw = { \
103 .hw = { \
104 .clk = &_name, \
105 }, \
106 .fixed_rate = _rate, \
107 .flags = _fixed_rate_flags, \
108 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530109 DEFINE_CLK(_name, clk_fixed_rate_ops, _flags, \
110 _name##_parent_names, NULL);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700111
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700112#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, \
113 _flags, _reg, _bit_idx, \
114 _gate_flags, _lock) \
115 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_gate _name##_hw = { \
123 .hw = { \
124 .clk = &_name, \
125 }, \
126 .reg = _reg, \
127 .bit_idx = _bit_idx, \
128 .flags = _gate_flags, \
129 .lock = _lock, \
130 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530131 DEFINE_CLK(_name, clk_gate_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, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700135 _flags, _reg, _shift, _width, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530136 _divider_flags, _table, _lock) \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700137 static struct clk _name; \
Rajendra Nayake447c502012-04-27 17:58:13 +0530138 static const char *_name##_parent_names[] = { \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700139 _parent_name, \
140 }; \
141 static struct clk *_name##_parents[] = { \
142 _parent_ptr, \
143 }; \
144 static struct clk_divider _name##_hw = { \
145 .hw = { \
146 .clk = &_name, \
147 }, \
148 .reg = _reg, \
149 .shift = _shift, \
150 .width = _width, \
151 .flags = _divider_flags, \
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530152 .table = _table, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700153 .lock = _lock, \
154 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530155 DEFINE_CLK(_name, clk_divider_ops, _flags, \
156 _name##_parent_names, _name##_parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700157
Rajendra Nayak357c3f02012-06-29 19:06:32 +0530158#define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
159 _flags, _reg, _shift, _width, \
160 _divider_flags, _lock) \
161 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
162 _flags, _reg, _shift, _width, \
163 _divider_flags, NULL, _lock)
164
165#define DEFINE_CLK_DIVIDER_TABLE(_name, _parent_name, \
166 _parent_ptr, _flags, _reg, \
167 _shift, _width, _divider_flags, \
168 _table, _lock) \
169 _DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, \
170 _flags, _reg, _shift, _width, \
171 _divider_flags, _table, _lock) \
172
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700173#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
174 _reg, _shift, _width, \
175 _mux_flags, _lock) \
176 static struct clk _name; \
177 static struct clk_mux _name##_hw = { \
178 .hw = { \
179 .clk = &_name, \
180 }, \
181 .reg = _reg, \
182 .shift = _shift, \
Peter De Schrijverce4f3312013-03-22 14:07:53 +0200183 .mask = BIT(_width) - 1, \
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700184 .flags = _mux_flags, \
185 .lock = _lock, \
186 }; \
Viresh Kumar182f9e8c2012-04-17 16:45:36 +0530187 DEFINE_CLK(_name, clk_mux_ops, _flags, _parent_names, \
188 _parents);
Mike Turquette9d9f78e2012-03-15 23:11:20 -0700189
Sascha Hauerf0948f52012-05-03 15:36:14 +0530190#define DEFINE_CLK_FIXED_FACTOR(_name, _parent_name, \
191 _parent_ptr, _flags, \
192 _mult, _div) \
193 static struct clk _name; \
194 static const char *_name##_parent_names[] = { \
195 _parent_name, \
196 }; \
197 static struct clk *_name##_parents[] = { \
198 _parent_ptr, \
199 }; \
200 static struct clk_fixed_factor _name##_hw = { \
201 .hw = { \
202 .clk = &_name, \
203 }, \
204 .mult = _mult, \
205 .div = _div, \
206 }; \
207 DEFINE_CLK(_name, clk_fixed_factor_ops, _flags, \
208 _name##_parent_names, _name##_parents);
209
Mike Turquetteb24764902012-03-15 23:11:19 -0700210/**
211 * __clk_init - initialize the data structures in a struct clk
212 * @dev: device initializing this clk, placeholder for now
213 * @clk: clk being initialized
214 *
215 * Initializes the lists in struct clk, queries the hardware for the
216 * parent and rate and sets them both.
217 *
218 * Any struct clk passed into __clk_init must have the following members
219 * populated:
220 * .name
221 * .ops
222 * .hw
223 * .parent_names
224 * .num_parents
225 * .flags
226 *
227 * It is not necessary to call clk_register if __clk_init is used directly with
228 * statically initialized clock data.
Mike Turquetted1302a32012-03-29 14:30:40 -0700229 *
230 * Returns 0 on success, otherwise an error code.
Mike Turquetteb24764902012-03-15 23:11:19 -0700231 */
Mike Turquetted1302a32012-03-29 14:30:40 -0700232int __clk_init(struct device *dev, struct clk *clk);
Mike Turquetteb24764902012-03-15 23:11:19 -0700233
Saravana Kannan0197b3e2012-04-25 22:58:56 -0700234struct clk *__clk_register(struct device *dev, struct clk_hw *hw);
235
Mike Turquetteb24764902012-03-15 23:11:19 -0700236#endif /* CONFIG_COMMON_CLK */
237#endif /* CLK_PRIVATE_H */