blob: 026b9daa5584d6916750df7e64387f729610a50d [file] [log] [blame]
Paul Mundt36ddf312006-01-16 22:14:17 -08001#ifndef __ASM_SH_CLOCK_H
2#define __ASM_SH_CLOCK_H
3
Paul Mundt36ddf312006-01-16 22:14:17 -08004#include <linux/list.h>
5#include <linux/seq_file.h>
Magnus Damma1153e22009-05-28 13:11:31 +00006#include <linux/cpufreq.h>
Paul Mundt1d118562006-12-01 13:15:14 +09007#include <linux/clk.h>
Magnus Dammde925422008-07-17 19:09:51 +09008#include <linux/err.h>
Paul Mundt36ddf312006-01-16 22:14:17 -08009
10struct clk;
11
12struct clk_ops {
13 void (*init)(struct clk *clk);
Paul Mundtae891a42009-05-12 05:30:10 +090014 int (*enable)(struct clk *clk);
Paul Mundt36ddf312006-01-16 22:14:17 -080015 void (*disable)(struct clk *clk);
Paul Mundtb68d8202009-05-12 03:45:08 +090016 unsigned long (*recalc)(struct clk *clk);
dmitry pervushin1929cb32007-04-24 13:39:09 +090017 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
Francesco VIRLINZId680c762009-03-11 07:40:54 +000018 int (*set_parent)(struct clk *clk, struct clk *parent);
Paul Mundtf6991b02007-07-20 13:29:09 +090019 long (*round_rate)(struct clk *clk, unsigned long rate);
Paul Mundt36ddf312006-01-16 22:14:17 -080020};
21
22struct clk {
23 struct list_head node;
24 const char *name;
Paul Mundt1d118562006-12-01 13:15:14 +090025 int id;
Paul Mundt36ddf312006-01-16 22:14:17 -080026 struct module *owner;
27
28 struct clk *parent;
29 struct clk_ops *ops;
30
Paul Mundtb1f6cfe2009-05-12 04:27:43 +090031 struct list_head children;
32 struct list_head sibling; /* node for children */
33
Magnus Damm4f5ecaa2009-05-08 08:23:29 +000034 int usecount;
Paul Mundt36ddf312006-01-16 22:14:17 -080035
36 unsigned long rate;
37 unsigned long flags;
Paul Mundta77b5ac2009-05-13 17:55:00 +090038
Paul Mundt549b5e32009-05-14 17:38:46 +090039 void __iomem *enable_reg;
40 unsigned int enable_bit;
41
Magnus Damm5c8f9d92008-07-17 18:48:57 +090042 unsigned long arch_flags;
Paul Mundta77b5ac2009-05-13 17:55:00 +090043 void *priv;
Paul Mundtcedcf332009-05-13 21:51:28 +090044 struct dentry *dentry;
Magnus Damma1153e22009-05-28 13:11:31 +000045 struct cpufreq_frequency_table *freq_table;
Paul Mundt36ddf312006-01-16 22:14:17 -080046};
47
Paul Mundt0dae8952009-05-12 06:18:09 +090048struct clk_lookup {
49 struct list_head node;
50 const char *dev_id;
51 const char *con_id;
52 struct clk *clk;
53};
54
Paul Mundt4ff29ff2009-05-12 05:14:53 +090055#define CLK_ENABLE_ON_INIT (1 << 0)
Paul Mundt36ddf312006-01-16 22:14:17 -080056
57/* Should be defined by processor-specific code */
Paul Mundt253b0882009-05-13 17:38:11 +090058void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
Paul Mundtfa439722008-09-04 18:53:58 +090059int __init arch_clk_init(void);
Paul Mundt36ddf312006-01-16 22:14:17 -080060
61/* arch/sh/kernel/cpu/clock.c */
62int clk_init(void);
Paul Mundtb1f6cfe2009-05-12 04:27:43 +090063unsigned long followparent_recalc(struct clk *);
64void recalculate_root_clocks(void);
65void propagate_rate(struct clk *);
Paul Mundtaa87aa32009-05-12 05:51:05 +090066int clk_reparent(struct clk *child, struct clk *parent);
Paul Mundt36ddf312006-01-16 22:14:17 -080067int clk_register(struct clk *);
68void clk_unregister(struct clk *);
69
Paul Mundt253b0882009-05-13 17:38:11 +090070/* arch/sh/kernel/cpu/clock-cpg.c */
71int __init __deprecated cpg_clk_init(void);
72
dmitry pervushin1929cb32007-04-24 13:39:09 +090073/* the exported API, in addition to clk_set_rate */
74/**
75 * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
76 * @clk: clock source
77 * @rate: desired clock rate in Hz
78 * @algo_id: algorithm id to be passed down to ops->set_rate
79 *
80 * Returns success (0) or negative errno.
81 */
82int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
83
84enum clk_sh_algo_id {
85 NO_CHANGE = 0,
86
87 IUS_N1_N1,
88 IUS_322,
89 IUS_522,
90 IUS_N11,
91
92 SB_N1,
93
94 SB3_N1,
95 SB3_32,
96 SB3_43,
97 SB3_54,
98
99 BP_N1,
100
101 IP_N1,
102};
Paul Mundtb68d8202009-05-12 03:45:08 +0900103
Magnus Dammc94a8572009-05-25 08:10:28 +0000104struct clk_div_mult_table {
105 unsigned int *divisors;
106 unsigned int nr_divisors;
107 unsigned int *multipliers;
108 unsigned int nr_multipliers;
109};
110
111struct cpufreq_frequency_table;
112void clk_rate_table_build(struct clk *clk,
113 struct cpufreq_frequency_table *freq_table,
114 int nr_freqs,
115 struct clk_div_mult_table *src_table,
116 unsigned long *bitmap);
117
118long clk_rate_table_round(struct clk *clk,
119 struct cpufreq_frequency_table *freq_table,
120 unsigned long rate);
121
Magnus Damm6881e8b2009-05-28 12:52:29 +0000122#define SH_CLK_MSTP32(_name, _id, _parent, _enable_reg, \
123 _enable_bit, _flags) \
124{ \
125 .name = _name, \
126 .id = _id, \
127 .parent = _parent, \
128 .enable_reg = (void __iomem *)_enable_reg, \
129 .enable_bit = _enable_bit, \
130 .flags = _flags, \
131}
132
133int sh_clk_mstp32_register(struct clk *clks, int nr);
134
Magnus Damma1153e22009-05-28 13:11:31 +0000135#define SH_CLK_DIV4(_name, _parent, _reg, _shift, _div_bitmap, _flags) \
136{ \
137 .name = _name, \
138 .parent = _parent, \
139 .enable_reg = (void __iomem *)_reg, \
140 .enable_bit = _shift, \
141 .arch_flags = _div_bitmap, \
142 .flags = _flags, \
143}
144
145int sh_clk_div4_register(struct clk *clks, int nr,
146 struct clk_div_mult_table *table);
147
Magnus Damm2693e272009-06-02 08:53:54 +0000148#define SH_CLK_DIV6(_name, _parent, _reg, _flags) \
149{ \
150 .name = _name, \
151 .parent = _parent, \
152 .enable_reg = (void __iomem *)_reg, \
153 .flags = _flags, \
154}
155
156int sh_clk_div6_register(struct clk *clks, int nr);
157
Paul Mundt36ddf312006-01-16 22:14:17 -0800158#endif /* __ASM_SH_CLOCK_H */