blob: f6b0bfd4e191666b6c89d6ad764bd8b8a14b193c [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 Mundtb68d82012009-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 Mundt4ff29ff2009-05-12 05:14:53 +090048#define CLK_ENABLE_ON_INIT (1 << 0)
Paul Mundt36ddf312006-01-16 22:14:17 -080049
50/* Should be defined by processor-specific code */
Paul Mundt253b0882009-05-13 17:38:11 +090051void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
Paul Mundtfa439722008-09-04 18:53:58 +090052int __init arch_clk_init(void);
Paul Mundt36ddf312006-01-16 22:14:17 -080053
54/* arch/sh/kernel/cpu/clock.c */
55int clk_init(void);
Paul Mundtb1f6cfe2009-05-12 04:27:43 +090056unsigned long followparent_recalc(struct clk *);
57void recalculate_root_clocks(void);
58void propagate_rate(struct clk *);
Paul Mundtaa87aa32009-05-12 05:51:05 +090059int clk_reparent(struct clk *child, struct clk *parent);
Paul Mundt36ddf312006-01-16 22:14:17 -080060int clk_register(struct clk *);
61void clk_unregister(struct clk *);
62
Paul Mundt253b0882009-05-13 17:38:11 +090063/* arch/sh/kernel/cpu/clock-cpg.c */
64int __init __deprecated cpg_clk_init(void);
65
dmitry pervushin1929cb32007-04-24 13:39:09 +090066/* the exported API, in addition to clk_set_rate */
67/**
68 * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
69 * @clk: clock source
70 * @rate: desired clock rate in Hz
71 * @algo_id: algorithm id to be passed down to ops->set_rate
72 *
73 * Returns success (0) or negative errno.
74 */
75int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
76
77enum clk_sh_algo_id {
78 NO_CHANGE = 0,
79
80 IUS_N1_N1,
81 IUS_322,
82 IUS_522,
83 IUS_N11,
84
85 SB_N1,
86
87 SB3_N1,
88 SB3_32,
89 SB3_43,
90 SB3_54,
91
92 BP_N1,
93
94 IP_N1,
95};
Paul Mundtb68d82012009-05-12 03:45:08 +090096
Magnus Dammc94a8572009-05-25 08:10:28 +000097struct clk_div_mult_table {
98 unsigned int *divisors;
99 unsigned int nr_divisors;
100 unsigned int *multipliers;
101 unsigned int nr_multipliers;
102};
103
104struct cpufreq_frequency_table;
105void clk_rate_table_build(struct clk *clk,
106 struct cpufreq_frequency_table *freq_table,
107 int nr_freqs,
108 struct clk_div_mult_table *src_table,
109 unsigned long *bitmap);
110
111long clk_rate_table_round(struct clk *clk,
112 struct cpufreq_frequency_table *freq_table,
113 unsigned long rate);
114
Magnus Damm098dee92009-06-04 05:31:41 +0000115int clk_rate_table_find(struct clk *clk,
116 struct cpufreq_frequency_table *freq_table,
117 unsigned long rate);
118
Magnus Dammc77a9c32010-05-11 05:00:47 +0000119#define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags) \
120{ \
121 .parent = _parent, \
122 .enable_reg = (void __iomem *)_enable_reg, \
123 .enable_bit = _enable_bit, \
124 .flags = _flags, \
Magnus Damm6881e8b2009-05-28 12:52:29 +0000125}
126
127int sh_clk_mstp32_register(struct clk *clks, int nr);
128
Magnus Damm914ebf02010-05-11 07:06:13 +0000129#define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
130{ \
131 .parent = _parent, \
132 .enable_reg = (void __iomem *)_reg, \
133 .enable_bit = _shift, \
134 .arch_flags = _div_bitmap, \
135 .flags = _flags, \
Magnus Damma1153e22009-05-28 13:11:31 +0000136}
137
Magnus Damm0a5f3372010-02-19 09:22:25 +0000138struct clk_div4_table {
139 struct clk_div_mult_table *div_mult_table;
Magnus Damm7be85c62010-02-19 09:26:56 +0000140 void (*kick)(struct clk *clk);
Magnus Damm0a5f3372010-02-19 09:22:25 +0000141};
142
Magnus Damma1153e22009-05-28 13:11:31 +0000143int sh_clk_div4_register(struct clk *clks, int nr,
Magnus Damm0a5f3372010-02-19 09:22:25 +0000144 struct clk_div4_table *table);
Guennadi Liakhovetski31c3af52010-01-19 11:14:31 +0000145int sh_clk_div4_enable_register(struct clk *clks, int nr,
Magnus Damm0a5f3372010-02-19 09:22:25 +0000146 struct clk_div4_table *table);
Guennadi Liakhovetski31c3af52010-01-19 11:14:31 +0000147int sh_clk_div4_reparent_register(struct clk *clks, int nr,
Magnus Damm0a5f3372010-02-19 09:22:25 +0000148 struct clk_div4_table *table);
Magnus Damma1153e22009-05-28 13:11:31 +0000149
Magnus Damm9e1985e2010-05-10 14:02:09 +0000150#define SH_CLK_DIV6(_parent, _reg, _flags) \
151{ \
152 .parent = _parent, \
153 .enable_reg = (void __iomem *)_reg, \
154 .flags = _flags, \
Magnus Damm2693e272009-06-02 08:53:54 +0000155}
156
157int sh_clk_div6_register(struct clk *clks, int nr);
158
Paul Mundt36ddf312006-01-16 22:14:17 -0800159#endif /* __ASM_SH_CLOCK_H */