blob: c513b73cd7cb8499a7ac61edb3789e7e24a8bfab [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
Magnus Damm84c36ff2012-02-29 22:18:19 +090022struct sh_clk_ops {
Paul Mundt549015c2010-11-15 18:48:25 +090023#ifdef CONFIG_SH_CLK_CPG_LEGACY
Magnus Dammd28bdf02010-05-11 13:29:17 +000024 void (*init)(struct clk *clk);
Paul Mundt549015c2010-11-15 18:48:25 +090025#endif
Magnus Dammd28bdf02010-05-11 13:29:17 +000026 int (*enable)(struct clk *clk);
27 void (*disable)(struct clk *clk);
28 unsigned long (*recalc)(struct clk *clk);
Paul Mundt35a96c72010-11-15 18:18:32 +090029 int (*set_rate)(struct clk *clk, unsigned long rate);
Magnus Dammd28bdf02010-05-11 13:29:17 +000030 int (*set_parent)(struct clk *clk, struct clk *parent);
31 long (*round_rate)(struct clk *clk, unsigned long rate);
32};
33
34struct clk {
35 struct list_head node;
Magnus Dammd28bdf02010-05-11 13:29:17 +000036 struct clk *parent;
Guennadi Liakhovetskib5272b502010-07-21 10:13:06 +000037 struct clk **parent_table; /* list of parents to */
38 unsigned short parent_num; /* choose between */
39 unsigned char src_shift; /* source clock field in the */
40 unsigned char src_width; /* configuration register */
Magnus Damm84c36ff2012-02-29 22:18:19 +090041 struct sh_clk_ops *ops;
Magnus Dammd28bdf02010-05-11 13:29:17 +000042
43 struct list_head children;
44 struct list_head sibling; /* node for children */
45
46 int usecount;
47
48 unsigned long rate;
49 unsigned long flags;
50
51 void __iomem *enable_reg;
52 unsigned int enable_bit;
Magnus Dammeda20302011-12-08 22:58:54 +090053 void __iomem *mapped_reg;
Magnus Dammd28bdf02010-05-11 13:29:17 +000054
55 unsigned long arch_flags;
56 void *priv;
Paul Mundt28085bc2010-10-15 16:46:37 +090057 struct clk_mapping *mapping;
Magnus Dammd28bdf02010-05-11 13:29:17 +000058 struct cpufreq_frequency_table *freq_table;
Paul Mundtf5869032010-10-15 18:17:35 +090059 unsigned int nr_freqs;
Magnus Dammd28bdf02010-05-11 13:29:17 +000060};
61
Paul Mundt4d6ddb02012-04-11 12:05:50 +090062#define CLK_ENABLE_ON_INIT BIT(0)
63
64#define CLK_ENABLE_REG_32BIT BIT(1) /* default access size */
65#define CLK_ENABLE_REG_16BIT BIT(2)
66#define CLK_ENABLE_REG_8BIT BIT(3)
67
68#define CLK_ENABLE_REG_MASK (CLK_ENABLE_REG_32BIT | \
69 CLK_ENABLE_REG_16BIT | \
70 CLK_ENABLE_REG_8BIT)
Magnus Dammd28bdf02010-05-11 13:29:17 +000071
Paul Mundta71ba092010-05-13 18:42:25 +090072/* drivers/sh/clk.c */
Magnus Dammd28bdf02010-05-11 13:29:17 +000073unsigned long followparent_recalc(struct clk *);
74void recalculate_root_clocks(void);
75void propagate_rate(struct clk *);
76int clk_reparent(struct clk *child, struct clk *parent);
77int clk_register(struct clk *);
78void clk_unregister(struct clk *);
Magnus Damm8b5ee112010-05-11 13:29:25 +000079void clk_enable_init_clocks(void);
Magnus Dammd28bdf02010-05-11 13:29:17 +000080
Magnus Dammd28bdf02010-05-11 13:29:17 +000081struct clk_div_mult_table {
82 unsigned int *divisors;
83 unsigned int nr_divisors;
84 unsigned int *multipliers;
85 unsigned int nr_multipliers;
86};
87
88struct cpufreq_frequency_table;
89void clk_rate_table_build(struct clk *clk,
90 struct cpufreq_frequency_table *freq_table,
91 int nr_freqs,
92 struct clk_div_mult_table *src_table,
93 unsigned long *bitmap);
94
95long clk_rate_table_round(struct clk *clk,
96 struct cpufreq_frequency_table *freq_table,
97 unsigned long rate);
98
99int clk_rate_table_find(struct clk *clk,
100 struct cpufreq_frequency_table *freq_table,
101 unsigned long rate);
102
Paul Mundt8e122db2010-10-15 18:33:24 +0900103long clk_rate_div_range_round(struct clk *clk, unsigned int div_min,
104 unsigned int div_max, unsigned long rate);
105
Kuninori Morimotodd2c0ca2011-09-19 18:51:13 -0700106long clk_rate_mult_range_round(struct clk *clk, unsigned int mult_min,
107 unsigned int mult_max, unsigned long rate);
108
Guennadi Liakhovetski6af26c62010-11-02 11:27:24 +0000109long clk_round_parent(struct clk *clk, unsigned long target,
110 unsigned long *best_freq, unsigned long *parent_freq,
111 unsigned int div_min, unsigned int div_max);
112
Paul Mundt4d6ddb02012-04-11 12:05:50 +0900113#define SH_CLK_MSTP(_parent, _enable_reg, _enable_bit, _flags) \
Magnus Dammd28bdf02010-05-11 13:29:17 +0000114{ \
115 .parent = _parent, \
116 .enable_reg = (void __iomem *)_enable_reg, \
117 .enable_bit = _enable_bit, \
118 .flags = _flags, \
119}
120
Paul Mundt4d6ddb02012-04-11 12:05:50 +0900121#define SH_CLK_MSTP32(_p, _r, _b, _f) \
122 SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_32BIT)
123
124#define SH_CLK_MSTP16(_p, _r, _b, _f) \
125 SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_16BIT)
126
127#define SH_CLK_MSTP8(_p, _r, _b, _f) \
128 SH_CLK_MSTP(_p, _r, _b, _f | CLK_ENABLE_REG_8BIT)
129
130int sh_clk_mstp_register(struct clk *clks, int nr);
131
132/*
133 * MSTP registration never really cared about access size, despite the
134 * original enable/disable pairs assuming a 32-bit access. Clocks are
135 * responsible for defining their access sizes either directly or via the
136 * clock definition wrappers.
137 */
138static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr)
139{
140 return sh_clk_mstp_register(clks, nr);
141}
Magnus Dammd28bdf02010-05-11 13:29:17 +0000142
143#define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags) \
144{ \
145 .parent = _parent, \
146 .enable_reg = (void __iomem *)_reg, \
147 .enable_bit = _shift, \
148 .arch_flags = _div_bitmap, \
149 .flags = _flags, \
150}
151
152struct clk_div4_table {
153 struct clk_div_mult_table *div_mult_table;
154 void (*kick)(struct clk *clk);
155};
156
157int sh_clk_div4_register(struct clk *clks, int nr,
158 struct clk_div4_table *table);
159int sh_clk_div4_enable_register(struct clk *clks, int nr,
160 struct clk_div4_table *table);
161int sh_clk_div4_reparent_register(struct clk *clks, int nr,
162 struct clk_div4_table *table);
163
Kuninori Morimoto56242a12011-11-21 21:33:18 -0800164#define SH_CLK_DIV6_EXT(_reg, _flags, _parents, \
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000165 _num_parents, _src_shift, _src_width) \
166{ \
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000167 .enable_reg = (void __iomem *)_reg, \
168 .flags = _flags, \
169 .parent_table = _parents, \
170 .parent_num = _num_parents, \
171 .src_shift = _src_shift, \
172 .src_width = _src_width, \
Magnus Dammd28bdf02010-05-11 13:29:17 +0000173}
174
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000175#define SH_CLK_DIV6(_parent, _reg, _flags) \
Kuninori Morimoto56242a12011-11-21 21:33:18 -0800176{ \
177 .parent = _parent, \
178 .enable_reg = (void __iomem *)_reg, \
179 .flags = _flags, \
180}
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000181
Magnus Dammd28bdf02010-05-11 13:29:17 +0000182int sh_clk_div6_register(struct clk *clks, int nr);
Guennadi Liakhovetskib3dd51a2010-07-21 10:13:10 +0000183int sh_clk_div6_reparent_register(struct clk *clks, int nr);
Magnus Dammd28bdf02010-05-11 13:29:17 +0000184
Kuninori Morimoto15220432011-07-06 02:54:11 +0000185#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
186#define CLKDEV_DEV_ID(_id, _clk) { .dev_id = _id, .clk = _clk }
187#define CLKDEV_ICK_ID(_cid, _did, _clk) { .con_id = _cid, .dev_id = _did, .clk = _clk }
188
Magnus Dammd28bdf02010-05-11 13:29:17 +0000189#endif /* __SH_CLOCK_H */