Lines Matching +full:cpg +full:- +full:div6 +full:- +full:clock

2  * Helper routines for SuperH Clock Pulse Generator blocks (CPG).
5 * Copyright (C) 2010 - 2012 Paul Mundt
21 if (clk->flags & CLK_ENABLE_REG_8BIT) in sh_clk_read()
22 return ioread8(clk->mapped_reg); in sh_clk_read()
23 else if (clk->flags & CLK_ENABLE_REG_16BIT) in sh_clk_read()
24 return ioread16(clk->mapped_reg); in sh_clk_read()
26 return ioread32(clk->mapped_reg); in sh_clk_read()
31 if (clk->flags & CLK_ENABLE_REG_8BIT) in sh_clk_write()
32 iowrite8(value, clk->mapped_reg); in sh_clk_write()
33 else if (clk->flags & CLK_ENABLE_REG_16BIT) in sh_clk_write()
34 iowrite16(value, clk->mapped_reg); in sh_clk_write()
36 iowrite32(value, clk->mapped_reg); in sh_clk_write()
41 sh_clk_write(sh_clk_read(clk) & ~(1 << clk->enable_bit), clk); in sh_clk_mstp_enable()
42 if (clk->status_reg) { in sh_clk_mstp_enable()
45 void __iomem *mapped_status = (phys_addr_t)clk->status_reg - in sh_clk_mstp_enable()
46 (phys_addr_t)clk->enable_reg + clk->mapped_reg; in sh_clk_mstp_enable()
48 if (clk->flags & CLK_ENABLE_REG_8BIT) in sh_clk_mstp_enable()
50 else if (clk->flags & CLK_ENABLE_REG_16BIT) in sh_clk_mstp_enable()
56 (read(mapped_status) & (1 << clk->enable_bit)) && i; in sh_clk_mstp_enable()
57 i--) in sh_clk_mstp_enable()
60 pr_err("cpg: failed to enable %p[%d]\n", in sh_clk_mstp_enable()
61 clk->enable_reg, clk->enable_bit); in sh_clk_mstp_enable()
62 return -ETIMEDOUT; in sh_clk_mstp_enable()
70 sh_clk_write(sh_clk_read(clk) | (1 << clk->enable_bit), clk); in sh_clk_mstp_disable()
87 clkp->ops = &sh_clk_mstp_clk_ops; in sh_clk_mstp_register()
99 return clk->priv; in clk_to_div_table()
104 return clk_to_div_table(clk)->div_mult_table; in clk_to_div_mult_table()
112 return clk_rate_table_round(clk, clk->freq_table, rate); in sh_clk_div_round_rate()
120 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors, in sh_clk_div_recalc()
121 table, clk->arch_flags ? &clk->arch_flags : NULL); in sh_clk_div_recalc()
123 idx = (sh_clk_read(clk) >> clk->enable_bit) & clk->div_mask; in sh_clk_div_recalc()
125 return clk->freq_table[idx].frequency; in sh_clk_div_recalc()
134 idx = clk_rate_table_find(clk, clk->freq_table, rate); in sh_clk_div_set_rate()
139 value &= ~(clk->div_mask << clk->enable_bit); in sh_clk_div_set_rate()
140 value |= (idx << clk->enable_bit); in sh_clk_div_set_rate()
143 /* XXX: Should use a post-change notifier */ in sh_clk_div_set_rate()
144 if (dt->kick) in sh_clk_div_set_rate()
145 dt->kick(clk); in sh_clk_div_set_rate()
152 if (clk->div_mask == SH_CLK_DIV6_MSK) { in sh_clk_div_enable()
153 int ret = sh_clk_div_set_rate(clk, clk->rate); in sh_clk_div_enable()
170 * div6 clocks require the divisor field to be non-zero or the in sh_clk_div_disable()
174 if (clk->flags & CLK_MASK_DIV_ON_DISABLE) in sh_clk_div_disable()
175 val |= clk->div_mask; in sh_clk_div_disable()
198 if (clk->parent) in sh_clk_init_parent()
201 if (!clk->parent_table || !clk->parent_num) in sh_clk_init_parent()
204 if (!clk->src_width) { in sh_clk_init_parent()
205 pr_err("sh_clk_init_parent: cannot select parent clock\n"); in sh_clk_init_parent()
206 return -EINVAL; in sh_clk_init_parent()
209 val = (sh_clk_read(clk) >> clk->src_shift); in sh_clk_init_parent()
210 val &= (1 << clk->src_width) - 1; in sh_clk_init_parent()
212 if (val >= clk->parent_num) { in sh_clk_init_parent()
214 return -EINVAL; in sh_clk_init_parent()
217 clk_reparent(clk, clk->parent_table[val]); in sh_clk_init_parent()
218 if (!clk->parent) { in sh_clk_init_parent()
220 return -EINVAL; in sh_clk_init_parent()
231 int nr_divs = table->div_mult_table->nr_divisors; in sh_clk_div_register_ops()
240 return -ENOMEM; in sh_clk_div_register_ops()
246 clkp->ops = ops; in sh_clk_div_register_ops()
247 clkp->priv = table; in sh_clk_div_register_ops()
249 clkp->freq_table = freq_table + (k * freq_table_size); in sh_clk_div_register_ops()
250 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END; in sh_clk_div_register_ops()
261 * div6 support
285 if (!clk->parent_table || !clk->parent_num) in sh_clk_div6_set_parent()
286 return -EINVAL; in sh_clk_div6_set_parent()
289 for (i = 0; i < clk->parent_num; i++) in sh_clk_div6_set_parent()
290 if (clk->parent_table[i] == parent) in sh_clk_div6_set_parent()
293 if (i == clk->parent_num) in sh_clk_div6_set_parent()
294 return -ENODEV; in sh_clk_div6_set_parent()
301 ~(((1 << clk->src_width) - 1) << clk->src_shift); in sh_clk_div6_set_parent()
303 sh_clk_write(value | (i << clk->src_shift), clk); in sh_clk_div6_set_parent()
306 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors, in sh_clk_div6_set_parent()
344 * no CLK_ENABLE_ON_INIT means external clock... in sh_clk_div4_set_parent()
347 if (parent->flags & CLK_ENABLE_ON_INIT) in sh_clk_div4_set_parent()
359 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors, in sh_clk_div4_set_parent()
360 table, &clk->arch_flags); in sh_clk_div4_set_parent()
394 /* FSI-DIV */
399 value = __raw_readl(clk->mapping->base); in fsidiv_recalc()
403 return clk->parent->rate; in fsidiv_recalc()
405 return clk->parent->rate / value; in fsidiv_recalc()
415 __raw_writel(0, clk->mapping->base); in fsidiv_disable()
422 value = __raw_readl(clk->mapping->base) >> 16; in fsidiv_enable()
426 __raw_writel((value << 16) | 0x3, clk->mapping->base); in fsidiv_enable()
435 idx = (clk->parent->rate / rate) & 0xffff; in fsidiv_set_rate()
437 __raw_writel(0, clk->mapping->base); in fsidiv_set_rate()
439 __raw_writel(idx << 16, clk->mapping->base); in fsidiv_set_rate()
462 return -ENOMEM; in sh_clk_fsidiv_register()
466 map->phys = (phys_addr_t)clks[i].enable_reg; in sh_clk_fsidiv_register()
467 map->len = 8; in sh_clk_fsidiv_register()