blob: 706c005cd4ba470398aa032ff6a8bd25c1cfe445 [file] [log] [blame]
Magnus Dammd28bdf02010-05-11 13:29:17 +00001#ifndef __SH_CLOCK_H
2#define __SH_CLOCK_H
3
4#include <linux/list.h>
5#include <linux/seq_file.h>
6#include <linux/cpufreq.h>
Paul Mundt28085bc2010-10-15 16:46:37 +09007#include <linux/types.h>
8#include <linux/kref.h>
Magnus Dammd28bdf02010-05-11 13:29:17 +00009#include <linux/clk.h>
10#include <linux/err.h>
11
12struct clk;
13
Paul Mundt28085bc2010-10-15 16:46:37 +090014struct clk_mapping {
15 phys_addr_t phys;
16 void __iomem *base;
17 unsigned long len;
18 struct kref ref;
19};
20
Magnus Damme3482822012-02-29 22:16:13 +090021#define sh_clk_ops clk_ops
22
Magnus Dammd28bdf02010-05-11 13:29:17 +000023struct clk_ops {
Paul Mundt549015c2010-11-15 18:48:25 +090024#ifdef CONFIG_SH_CLK_CPG_LEGACY
Magnus Dammd28bdf02010-05-11 13:29:17 +000025 void (*init)(struct clk *clk);
Paul Mundt549015c2010-11-15 18:48:25 +090026#endif
Magnus Dammd28bdf02010-05-11 13:29:17 +000027 int (*enable)(struct clk *clk);
28 void (*disable)(struct clk *clk);
29 unsigned long (*recalc)(struct clk *clk);
Paul Mundt35a96c72010-11-15 18:18:32 +090030 int (*set_rate)(struct clk *clk, unsigned long rate);
Magnus Dammd28bdf02010-05-11 13:29:17 +000031 int (*set_parent)(struct clk *clk, struct clk *parent);
32 long (*round_rate)(struct clk *clk, unsigned long rate);
33};
34
35struct clk {
36 struct list_head node;
Magnus Dammd28bdf02010-05-11 13:29:17 +000037 struct clk *parent;
Guennadi Liakhovetskib5272b502010-07-21 10:13:06 +000038 struct clk **parent_table; /* list of parents to */
39 unsigned short parent_num; /* choose between */
40 unsigned char src_shift; /* source clock field in the */
41 unsigned char src_width; /* configuration register */
Magnus Dammd28bdf02010-05-11 13:29:17 +000042 struct clk_ops *ops;
43
44 struct list_head children;
45 struct list_head sibling; /* node for children */
46
47 int usecount;
48
49 unsigned long rate;
50 unsigned long flags;
51
52 void __iomem *enable_reg;
53 unsigned int enable_bit;
Magnus Dammeda20302011-12-08 22:58:54 +090054 void __iomem *mapped_reg;
Magnus Dammd28bdf02010-05-11 13:29:17 +000055
56 unsigned long arch_flags;
57 void *priv;
Paul Mundt28085bc2010-10-15 16:46:37 +090058 struct clk_mapping *mapping;
Magnus Dammd28bdf02010-05-11 13:29:17 +000059 struct cpufreq_frequency_table *freq_table;
Paul Mundtf5869032010-10-15 18:17:35 +090060 unsigned int nr_freqs;
Magnus Dammd28bdf02010-05-11 13:29:17 +000061};
62
63#define CLK_ENABLE_ON_INIT (1 << 0)
64
Paul Mundta71ba092010-05-13 18:42:25 +090065/* drivers/sh/clk.c */
Magnus Dammd28bdf02010-05-11 13:29:17 +000066unsigned long followparent_recalc(struct clk *);
67void recalculate_root_clocks(void);
68void propagate_rate(struct clk *);
69int clk_reparent(struct clk *child, struct clk *parent);
70int clk_register(struct clk *);
71void clk_unregister(struct clk *);
Magnus Damm8b5ee112010-05-11 13:29:25 +000072void clk_enable_init_clocks(void);
Magnus Dammd28bdf02010-05-11 13:29:17 +000073
Magnus Dammd28bdf02010-05-11 13:29:17 +000074struct clk_div_mult_table {
75 unsigned int *divisors;
76 unsigned int nr_divisors;
77 unsigned int *multipliers;
78 unsigned int nr_multipliers;
79};
80
81struct cpufreq_frequency_table;
82void clk_rate_table_build(struct clk *clk,
83 struct cpufreq_frequency_table *freq_table,
84 int nr_freqs,
85 struct clk_div_mult_table *src_table,
86 unsigned long *bitmap);
87
88long clk_rate_table_round(struct clk *clk,
89 struct cpufreq_frequency_table *freq_table,
90 unsigned long rate);
91
92int clk_rate_table_find(struct clk *clk,
93 struct cpufreq_frequency_table *freq_table,
94 unsigned long rate);
95
Paul Mundt8e122db2010-10-15 18:33:24 +090096long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
97 unsigned int div_max, unsigned long rate);
98
Kuninori Morimotodd2c0ca2011-09-19 18:51:13 -070099long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
100 unsigned int mult_max, unsigned long rate);
101
Guennadi Liakhovetski6af26c62010-11-02 11:27:24 +0000102long clk_round_parent(struct clk *clk, unsigned long target,
103 unsigned long *best_freq, unsigned long *parent_freq,
104 unsigned int div_min, unsigned int div_max);
105
Magnus Dammd28bdf02010-05-11 13:29:17 +0000106#define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
107{ \
108 .parent = _parent, \
109 .enable_reg = (void __iomem *)_enable_reg, \
110 .enable_bit = _enable_bit, \
111 .flags = _flags, \
112}
113
114int sh_clk_mstp32_register(struct clk *clks, int nr);
115
116#define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
117{ \
118 .parent = _parent, \
119 .enable_reg = (void __iomem *)_reg, \
120 .enable_bit = _shift, \
121 .arch_flags = _div_bitmap, \
122 .flags = _flags, \
123}
124
125struct clk_div4_table {
126 struct clk_div_mult_table *div_mult_table;
127 void (*kick)(struct clk *clk);
128};
129
130int sh_clk_div4_register(struct clk *clks, int nr,
131 struct clk_div4_table *table);
132int sh_clk_div4_enable_register(struct clk *clks, int nr,
133 struct clk_div4_table *table);
134int sh_clk_div4_reparent_register(struct clk *clks, int nr,
135 struct clk_div4_table *table);
136
Kuninori Morimoto56242a12011-11-21 21:33:18 -0800137#define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000138 _num_parents, _src_shift, _src_width) \
139{ \
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000140 .enable_reg = (void __iomem *)_reg, \
141 .flags = _flags, \
142 .parent_table = _parents, \
143 .parent_num = _num_parents, \
144 .src_shift = _src_shift, \
145 .src_width = _src_width, \
Magnus Dammd28bdf02010-05-11 13:29:17 +0000146}
147
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000148#define SH_CLK_DIV6(_parent, _reg, _flags) \
Kuninori Morimoto56242a12011-11-21 21:33:18 -0800149{ \
150 .parent = _parent, \
151 .enable_reg = (void __iomem *)_reg, \
152 .flags = _flags, \
153}
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000154
Magnus Dammd28bdf02010-05-11 13:29:17 +0000155int sh_clk_div6_register(struct clk *clks, int nr);
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000156int sh_clk_div6_reparent_register(struct clk *clks, int nr);
Magnus Dammd28bdf02010-05-11 13:29:17 +0000157
Kuninori Morimoto15220432011-07-06 02:54:11 +0000158#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
159#define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
160#define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk }
161
Magnus Dammd28bdf02010-05-11 13:29:17 +0000162#endif /* __SH_CLOCK_H */