aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2012-05-25 02:21:43 -0400
committerPaul Mundt <lethal@linux-sh.org>2012-05-25 02:21:43 -0400
commit1111cc1e8080b5ff46f5b945acb2f99d6176b2d1 (patch)
tree0a8333a7f46236e53ce3f520ceb35b7dd8cfe76f
parenta60977a51333a8108f0574aa26094d66b7fedf34 (diff)
sh: clkfwk: Introduce a div_mask for variable div types.
This plugs in a div_mask for the clock and sets it up for the existing div6/4 cases. This will make it possible to support other div types, as well as share more div6/4 infrastructure. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
-rw-r--r--drivers/sh/clk/cpg.c10
-rw-r--r--include/linux/sh_clk.h8
2 files changed, 13 insertions, 5 deletions
diff --git a/drivers/sh/clk/cpg.c b/drivers/sh/clk/cpg.c
index 9dea32907795..9386bd21c003 100644
--- a/drivers/sh/clk/cpg.c
+++ b/drivers/sh/clk/cpg.c
@@ -111,7 +111,7 @@ static unsigned long sh_clk_div6_recalc(struct clk *clk)
111 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors, 111 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
112 table, NULL); 112 table, NULL);
113 113
114 idx = sh_clk_read(clk) & 0x003f; 114 idx = sh_clk_read(clk) & clk->div_mask;
115 115
116 return clk->freq_table[idx].frequency; 116 return clk->freq_table[idx].frequency;
117} 117}
@@ -159,7 +159,7 @@ static int sh_clk_div6_set_rate(struct clk *clk, unsigned long rate)
159 return idx; 159 return idx;
160 160
161 value = sh_clk_read(clk); 161 value = sh_clk_read(clk);
162 value &= ~0x3f; 162 value &= ~clk->div_mask;
163 value |= idx; 163 value |= idx;
164 sh_clk_write(value, clk); 164 sh_clk_write(value, clk);
165 return 0; 165 return 0;
@@ -185,7 +185,7 @@ static void sh_clk_div6_disable(struct clk *clk)
185 185
186 value = sh_clk_read(clk); 186 value = sh_clk_read(clk);
187 value |= 0x100; /* stop clock */ 187 value |= 0x100; /* stop clock */
188 value |= 0x3f; /* VDIV bits must be non-zero, overwrite divider */ 188 value |= clk->div_mask; /* VDIV bits must be non-zero, overwrite divider */
189 sh_clk_write(value, clk); 189 sh_clk_write(value, clk);
190} 190}
191 191
@@ -295,7 +295,7 @@ static unsigned long sh_clk_div4_recalc(struct clk *clk)
295 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors, 295 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
296 table, &clk->arch_flags); 296 table, &clk->arch_flags);
297 297
298 idx = (sh_clk_read(clk) >> clk->enable_bit) & 0x000f; 298 idx = (sh_clk_read(clk) >> clk->enable_bit) & clk->div_mask;
299 299
300 return clk->freq_table[idx].frequency; 300 return clk->freq_table[idx].frequency;
301} 301}
@@ -338,7 +338,7 @@ static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate)
338 return idx; 338 return idx;
339 339
340 value = sh_clk_read(clk); 340 value = sh_clk_read(clk);
341 value &= ~(0xf << clk->enable_bit); 341 value &= ~(clk->div_mask << clk->enable_bit);
342 value |= (idx << clk->enable_bit); 342 value |= (idx << clk->enable_bit);
343 sh_clk_write(value, clk); 343 sh_clk_write(value, clk);
344 344
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
index 706b803df7b7..d540b8153178 100644
--- a/include/linux/sh_clk.h
+++ b/include/linux/sh_clk.h
@@ -30,6 +30,10 @@ struct sh_clk_ops {
30 long (*round_rate)(struct clk *clk, unsigned long rate); 30 long (*round_rate)(struct clk *clk, unsigned long rate);
31}; 31};
32 32
33#define SH_CLK_DIV_MSK(div) ((1 << (div)) - 1)
34#define SH_CLK_DIV4_MSK SH_CLK_DIV_MSK(4)
35#define SH_CLK_DIV6_MSK SH_CLK_DIV_MSK(6)
36
33struct clk { 37struct clk {
34 struct list_head node; 38 struct list_head node;
35 struct clk *parent; 39 struct clk *parent;
@@ -51,6 +55,7 @@ struct clk {
51 unsigned int enable_bit; 55 unsigned int enable_bit;
52 void __iomem *mapped_reg; 56 void __iomem *mapped_reg;
53 57
58 unsigned int div_mask;
54 unsigned long arch_flags; 59 unsigned long arch_flags;
55 void *priv; 60 void *priv;
56 struct clk_mapping *mapping; 61 struct clk_mapping *mapping;
@@ -145,6 +150,7 @@ static inline int __deprecated sh_clk_mstp32_register(struct clk *clks, int nr)
145 .enable_reg = (void __iomem *)_reg, \ 150 .enable_reg = (void __iomem *)_reg, \
146 .enable_bit = _shift, \ 151 .enable_bit = _shift, \
147 .arch_flags = _div_bitmap, \ 152 .arch_flags = _div_bitmap, \
153 .div_mask = SH_CLK_DIV4_MSK, \
148 .flags = _flags, \ 154 .flags = _flags, \
149} 155}
150 156
@@ -167,6 +173,7 @@ int sh_clk_div4_reparent_register(struct clk *clks, int nr,
167{ \ 173{ \
168 .enable_reg = (void __iomem *)_reg, \ 174 .enable_reg = (void __iomem *)_reg, \
169 .flags = _flags, \ 175 .flags = _flags, \
176 .div_mask = SH_CLK_DIV6_MSK, \
170 .parent_table = _parents, \ 177 .parent_table = _parents, \
171 .parent_num = _num_parents, \ 178 .parent_num = _num_parents, \
172 .src_shift = _src_shift, \ 179 .src_shift = _src_shift, \
@@ -177,6 +184,7 @@ int sh_clk_div4_reparent_register(struct clk *clks, int nr,
177{ \ 184{ \
178 .parent = _parent, \ 185 .parent = _parent, \
179 .enable_reg = (void __iomem *)_reg, \ 186 .enable_reg = (void __iomem *)_reg, \
187 .div_mask = SH_CLK_DIV6_MSK, \
180 .flags = _flags, \ 188 .flags = _flags, \
181} 189}
182 190