Commit | Line | Data |
---|---|---|
d28bdf05 MD |
1 | #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> | |
28085bc5 PM |
7 | #include <linux/types.h> |
8 | #include <linux/kref.h> | |
d28bdf05 MD |
9 | #include <linux/clk.h> |
10 | #include <linux/err.h> | |
11 | ||
12 | struct clk; | |
13 | ||
28085bc5 PM |
14 | struct clk_mapping { |
15 | phys_addr_t phys; | |
16 | void __iomem *base; | |
17 | unsigned long len; | |
18 | struct kref ref; | |
19 | }; | |
20 | ||
d28bdf05 MD |
21 | struct clk_ops { |
22 | void (*init)(struct clk *clk); | |
23 | int (*enable)(struct clk *clk); | |
24 | void (*disable)(struct clk *clk); | |
25 | unsigned long (*recalc)(struct clk *clk); | |
35a96c73 | 26 | int (*set_rate)(struct clk *clk, unsigned long rate); |
d28bdf05 MD |
27 | int (*set_parent)(struct clk *clk, struct clk *parent); |
28 | long (*round_rate)(struct clk *clk, unsigned long rate); | |
29 | }; | |
30 | ||
31 | struct clk { | |
32 | struct list_head node; | |
d28bdf05 | 33 | struct clk *parent; |
b5272b50 GL |
34 | struct clk **parent_table; /* list of parents to */ |
35 | unsigned short parent_num; /* choose between */ | |
36 | unsigned char src_shift; /* source clock field in the */ | |
37 | unsigned char src_width; /* configuration register */ | |
d28bdf05 MD |
38 | struct clk_ops *ops; |
39 | ||
40 | struct list_head children; | |
41 | struct list_head sibling; /* node for children */ | |
42 | ||
43 | int usecount; | |
44 | ||
45 | unsigned long rate; | |
46 | unsigned long flags; | |
47 | ||
48 | void __iomem *enable_reg; | |
49 | unsigned int enable_bit; | |
50 | ||
51 | unsigned long arch_flags; | |
52 | void *priv; | |
53 | struct dentry *dentry; | |
28085bc5 | 54 | struct clk_mapping *mapping; |
d28bdf05 | 55 | struct cpufreq_frequency_table *freq_table; |
f586903d | 56 | unsigned int nr_freqs; |
d28bdf05 MD |
57 | }; |
58 | ||
59 | #define CLK_ENABLE_ON_INIT (1 << 0) | |
60 | ||
a71ba096 | 61 | /* drivers/sh/clk.c */ |
d28bdf05 MD |
62 | unsigned long followparent_recalc(struct clk *); |
63 | void recalculate_root_clocks(void); | |
64 | void propagate_rate(struct clk *); | |
65 | int clk_reparent(struct clk *child, struct clk *parent); | |
66 | int clk_register(struct clk *); | |
67 | void clk_unregister(struct clk *); | |
8b5ee113 | 68 | void clk_enable_init_clocks(void); |
d28bdf05 | 69 | |
d28bdf05 MD |
70 | struct clk_div_mult_table { |
71 | unsigned int *divisors; | |
72 | unsigned int nr_divisors; | |
73 | unsigned int *multipliers; | |
74 | unsigned int nr_multipliers; | |
75 | }; | |
76 | ||
77 | struct cpufreq_frequency_table; | |
78 | void clk_rate_table_build(struct clk *clk, | |
79 | struct cpufreq_frequency_table *freq_table, | |
80 | int nr_freqs, | |
81 | struct clk_div_mult_table *src_table, | |
82 | unsigned long *bitmap); | |
83 | ||
84 | long clk_rate_table_round(struct clk *clk, | |
85 | struct cpufreq_frequency_table *freq_table, | |
86 | unsigned long rate); | |
87 | ||
88 | int clk_rate_table_find(struct clk *clk, | |
89 | struct cpufreq_frequency_table *freq_table, | |
90 | unsigned long rate); | |
91 | ||
8e122db6 PM |
92 | long clk_rate_div_range_round(struct clk *clk, unsigned int div_min, |
93 | unsigned int div_max, unsigned long rate); | |
94 | ||
6af26c6c GL |
95 | long clk_round_parent(struct clk *clk, unsigned long target, |
96 | unsigned long *best_freq, unsigned long *parent_freq, | |
97 | unsigned int div_min, unsigned int div_max); | |
98 | ||
d28bdf05 MD |
99 | #define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \ |
100 | { \ | |
101 | .parent = _parent, \ | |
102 | .enable_reg = (void __iomem *)_enable_reg, \ | |
103 | .enable_bit = _enable_bit, \ | |
104 | .flags = _flags, \ | |
105 | } | |
106 | ||
107 | int sh_clk_mstp32_register(struct clk *clks, int nr); | |
108 | ||
109 | #define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \ | |
110 | { \ | |
111 | .parent = _parent, \ | |
112 | .enable_reg = (void __iomem *)_reg, \ | |
113 | .enable_bit = _shift, \ | |
114 | .arch_flags = _div_bitmap, \ | |
115 | .flags = _flags, \ | |
116 | } | |
117 | ||
118 | struct clk_div4_table { | |
119 | struct clk_div_mult_table *div_mult_table; | |
120 | void (*kick)(struct clk *clk); | |
121 | }; | |
122 | ||
123 | int sh_clk_div4_register(struct clk *clks, int nr, | |
124 | struct clk_div4_table *table); | |
125 | int sh_clk_div4_enable_register(struct clk *clks, int nr, | |
126 | struct clk_div4_table *table); | |
127 | int sh_clk_div4_reparent_register(struct clk *clks, int nr, | |
128 | struct clk_div4_table *table); | |
129 | ||
b3dd51a8 GL |
130 | #define SH_CLK_DIV6_EXT(_parent, _reg, _flags, _parents, \ |
131 | _num_parents, _src_shift, _src_width) \ | |
132 | { \ | |
133 | .parent = _parent, \ | |
134 | .enable_reg = (void __iomem *)_reg, \ | |
135 | .flags = _flags, \ | |
136 | .parent_table = _parents, \ | |
137 | .parent_num = _num_parents, \ | |
138 | .src_shift = _src_shift, \ | |
139 | .src_width = _src_width, \ | |
d28bdf05 MD |
140 | } |
141 | ||
b3dd51a8 GL |
142 | #define SH_CLK_DIV6(_parent, _reg, _flags) \ |
143 | SH_CLK_DIV6_EXT(_parent, _reg, _flags, NULL, 0, 0, 0) | |
144 | ||
d28bdf05 | 145 | int sh_clk_div6_register(struct clk *clks, int nr); |
b3dd51a8 | 146 | int sh_clk_div6_reparent_register(struct clk *clks, int nr); |
d28bdf05 MD |
147 | |
148 | #endif /* __SH_CLOCK_H */ |