Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clk-provider.h
Go to the documentation of this file.
1 /*
2  * linux/include/linux/clk-provider.h
3  *
4  * Copyright (c) 2010-2011 Jeremy Kerr <[email protected]>
5  * Copyright (C) 2011-2012 Linaro Ltd <[email protected]>
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_PROVIDER_H
12 #define __LINUX_CLK_PROVIDER_H
13 
14 #include <linux/clk.h>
15 
16 #ifdef CONFIG_COMMON_CLK
17 
18 /*
19  * flags used across common struct clk. these flags should only affect the
20  * top-level framework. custom flags for dealing with hardware specifics
21  * belong in struct clk_foo
22  */
23 #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
24 #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
25 #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
26 #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
27 #define CLK_IS_ROOT BIT(4) /* root clk, has no parent */
28 #define CLK_IS_BASIC BIT(5) /* Basic clk, can't do a to_clk_foo() */
29 #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
30 
31 struct clk_hw;
32 
99 struct clk_ops {
100  int (*prepare)(struct clk_hw *hw);
101  void (*unprepare)(struct clk_hw *hw);
102  int (*enable)(struct clk_hw *hw);
103  void (*disable)(struct clk_hw *hw);
104  int (*is_enabled)(struct clk_hw *hw);
105  unsigned long (*recalc_rate)(struct clk_hw *hw,
106  unsigned long parent_rate);
107  long (*round_rate)(struct clk_hw *hw, unsigned long,
108  unsigned long *);
109  int (*set_parent)(struct clk_hw *hw, u8 index);
110  u8 (*get_parent)(struct clk_hw *hw);
111  int (*set_rate)(struct clk_hw *hw, unsigned long,
112  unsigned long);
113  void (*init)(struct clk_hw *hw);
114 };
115 
126 struct clk_init_data {
127  const char *name;
128  const struct clk_ops *ops;
129  const char **parent_names;
130  u8 num_parents;
131  unsigned long flags;
132 };
133 
146 struct clk_hw {
147  struct clk *clk;
148  const struct clk_init_data *init;
149 };
150 
151 /*
152  * DOC: Basic clock implementations common to many platforms
153  *
154  * Each basic clock hardware type is comprised of a structure describing the
155  * clock hardware, implementations of the relevant callbacks in struct clk_ops,
156  * unique flags for that hardware type, a registration function and an
157  * alternative macro for static initialization
158  */
159 
165 struct clk_fixed_rate {
166  struct clk_hw hw;
167  unsigned long fixed_rate;
168  u8 flags;
169 };
170 
171 extern const struct clk_ops clk_fixed_rate_ops;
172 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
173  const char *parent_name, unsigned long flags,
174  unsigned long fixed_rate);
175 
176 void of_fixed_clk_setup(struct device_node *np);
177 
194 struct clk_gate {
195  struct clk_hw hw;
196  void __iomem *reg;
197  u8 bit_idx;
198  u8 flags;
199  spinlock_t *lock;
200 };
201 
202 #define CLK_GATE_SET_TO_DISABLE BIT(0)
203 
204 extern const struct clk_ops clk_gate_ops;
205 struct clk *clk_register_gate(struct device *dev, const char *name,
206  const char *parent_name, unsigned long flags,
207  void __iomem *reg, u8 bit_idx,
208  u8 clk_gate_flags, spinlock_t *lock);
209 
210 struct clk_div_table {
211  unsigned int val;
212  unsigned int div;
213 };
214 
236 struct clk_divider {
237  struct clk_hw hw;
238  void __iomem *reg;
239  u8 shift;
240  u8 width;
241  u8 flags;
242  const struct clk_div_table *table;
243  spinlock_t *lock;
244 };
245 
246 #define CLK_DIVIDER_ONE_BASED BIT(0)
247 #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
248 
249 extern const struct clk_ops clk_divider_ops;
250 struct clk *clk_register_divider(struct device *dev, const char *name,
251  const char *parent_name, unsigned long flags,
252  void __iomem *reg, u8 shift, u8 width,
253  u8 clk_divider_flags, spinlock_t *lock);
254 struct clk *clk_register_divider_table(struct device *dev, const char *name,
255  const char *parent_name, unsigned long flags,
256  void __iomem *reg, u8 shift, u8 width,
257  u8 clk_divider_flags, const struct clk_div_table *table,
258  spinlock_t *lock);
259 
277 struct clk_mux {
278  struct clk_hw hw;
279  void __iomem *reg;
280  u8 shift;
281  u8 width;
282  u8 flags;
283  spinlock_t *lock;
284 };
285 
286 #define CLK_MUX_INDEX_ONE BIT(0)
287 #define CLK_MUX_INDEX_BIT BIT(1)
288 
289 extern const struct clk_ops clk_mux_ops;
290 struct clk *clk_register_mux(struct device *dev, const char *name,
291  const char **parent_names, u8 num_parents, unsigned long flags,
292  void __iomem *reg, u8 shift, u8 width,
293  u8 clk_mux_flags, spinlock_t *lock);
294 
307 struct clk_fixed_factor {
308  struct clk_hw hw;
309  unsigned int mult;
310  unsigned int div;
311 };
312 
313 extern struct clk_ops clk_fixed_factor_ops;
314 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
315  const char *parent_name, unsigned long flags,
316  unsigned int mult, unsigned int div);
317 
329 struct clk *clk_register(struct device *dev, struct clk_hw *hw);
330 
331 void clk_unregister(struct clk *clk);
332 
333 /* helper functions */
334 const char *__clk_get_name(struct clk *clk);
335 struct clk_hw *__clk_get_hw(struct clk *clk);
337 struct clk *__clk_get_parent(struct clk *clk);
338 int __clk_get_enable_count(struct clk *clk);
339 int __clk_get_prepare_count(struct clk *clk);
340 unsigned long __clk_get_rate(struct clk *clk);
341 unsigned long __clk_get_flags(struct clk *clk);
342 int __clk_is_enabled(struct clk *clk);
343 struct clk *__clk_lookup(const char *name);
344 
345 /*
346  * FIXME clock api without lock protection
347  */
348 int __clk_prepare(struct clk *clk);
349 void __clk_unprepare(struct clk *clk);
350 void __clk_reparent(struct clk *clk, struct clk *new_parent);
351 unsigned long __clk_round_rate(struct clk *clk, unsigned long rate);
352 
353 struct of_device_id;
354 
355 typedef void (*of_clk_init_cb_t)(struct device_node *);
356 
357 int of_clk_add_provider(struct device_node *np,
358  struct clk *(*clk_src_get)(struct of_phandle_args *args,
359  void *data),
360  void *data);
361 void of_clk_del_provider(struct device_node *np);
362 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
363  void *data);
364 struct clk_onecell_data {
365  struct clk **clks;
366  unsigned int clk_num;
367 };
368 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
369 const char *of_clk_get_parent_name(struct device_node *np, int index);
370 void of_clk_init(const struct of_device_id *matches);
371 
372 #endif /* CONFIG_COMMON_CLK */
373 #endif /* CLK_PROVIDER_H */