13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/list.h>
16 #include <linux/errno.h>
22 #include <mach/hardware.h>
26 #include <plat/clock.h>
76 static struct clk clk_timer_scaler[];
78 static unsigned long clk_pwm_scaler_get_rate(
struct clk *
clk)
82 if (clk == &clk_timer_scaler[1]) {
92 static unsigned long clk_pwm_scaler_round_rate(
struct clk *clk,
100 else if (divisor < 2)
106 static int clk_pwm_scaler_set_rate(
struct clk *clk,
unsigned long rate)
108 unsigned long round = clk_pwm_scaler_round_rate(clk, rate);
119 if (clk == &clk_timer_scaler[1]) {
133 static struct clk_ops clk_pwm_scaler_ops = {
134 .get_rate = clk_pwm_scaler_get_rate,
135 .set_rate = clk_pwm_scaler_set_rate,
136 .round_rate = clk_pwm_scaler_round_rate,
139 static struct clk clk_timer_scaler[] = {
141 .name =
"pwm-scaler0",
143 .ops = &clk_pwm_scaler_ops,
146 .name =
"pwm-scaler1",
148 .ops = &clk_pwm_scaler_ops,
152 static struct clk clk_timer_tclk[] = {
168 static inline struct pwm_tdiv_clk *to_tdiv(
struct clk *clk)
173 static unsigned long clk_pwm_tdiv_get_rate(
struct clk *clk)
181 if (pwm_cfg_src_is_tclk(tcfg1))
182 divisor = to_tdiv(clk)->divisor;
184 divisor = tcfg_to_divisor(tcfg1);
189 static unsigned long clk_pwm_tdiv_round_rate(
struct clk *clk,
192 unsigned long parent_rate;
196 divisor = parent_rate /
rate;
198 if (divisor <= 1 && pwm_tdiv_has_div1())
200 else if (divisor <= 2)
202 else if (divisor <= 4)
204 else if (divisor <= 8)
212 static unsigned long clk_pwm_tdiv_bits(
struct pwm_tdiv_clk *divclk)
214 return pwm_tdiv_div_bits(divclk->
divisor);
217 static void clk_pwm_tdiv_update(
struct pwm_tdiv_clk *divclk)
220 unsigned long bits = clk_pwm_tdiv_bits(divclk);
228 tcfg1 |= bits << shift;
234 static int clk_pwm_tdiv_set_rate(
struct clk *clk,
unsigned long rate)
245 divisor = parent_rate /
rate;
255 if (!pwm_cfg_src_is_tclk(tcfg1))
256 clk_pwm_tdiv_update(divclk);
261 static struct clk_ops clk_tdiv_ops = {
262 .get_rate = clk_pwm_tdiv_get_rate,
263 .set_rate = clk_pwm_tdiv_set_rate,
264 .round_rate = clk_pwm_tdiv_round_rate,
271 .devname =
"s3c24xx-pwm.0",
272 .ops = &clk_tdiv_ops,
273 .parent = &clk_timer_scaler[0],
279 .devname =
"s3c24xx-pwm.1",
280 .ops = &clk_tdiv_ops,
281 .parent = &clk_timer_scaler[0],
287 .devname =
"s3c24xx-pwm.2",
288 .ops = &clk_tdiv_ops,
289 .parent = &clk_timer_scaler[1],
295 .devname =
"s3c24xx-pwm.3",
296 .ops = &clk_tdiv_ops,
297 .parent = &clk_timer_scaler[1],
303 .devname =
"s3c24xx-pwm.4",
304 .ops = &clk_tdiv_ops,
305 .parent = &clk_timer_scaler[1],
310 static int __init clk_pwm_tdiv_register(
unsigned int id)
319 divclk->
divisor = tcfg_to_divisor(tcfg1);
324 static inline struct clk *s3c24xx_pwmclk_tclk(
unsigned int id)
326 return (
id >= 2) ? &clk_timer_tclk[1] : &clk_timer_tclk[0];
329 static inline struct clk *s3c24xx_pwmclk_tdiv(
unsigned int id)
331 return &clk_timer_tdiv[
id].
clk;
334 static int clk_pwm_tin_set_parent(
struct clk *clk,
struct clk *
parent)
336 unsigned int id = clk->
id;
342 unsigned long mux_tclk;
351 if (parent == s3c24xx_pwmclk_tclk(
id))
352 bits = mux_tclk <<
shift;
353 else if (parent == s3c24xx_pwmclk_tdiv(
id))
354 bits = clk_pwm_tdiv_bits(to_tdiv(parent)) <<
shift;
371 static struct clk_ops clk_tin_ops = {
372 .set_parent = clk_pwm_tin_set_parent,
375 static struct clk clk_tin[] = {
378 .devname =
"s3c24xx-pwm.0",
384 .devname =
"s3c24xx-pwm.1",
390 .devname =
"s3c24xx-pwm.2",
396 .devname =
"s3c24xx-pwm.3",
402 .devname =
"s3c24xx-pwm.4",
408 static __init int clk_pwm_tin_register(
struct clk *
pwm)
411 unsigned int id = pwm->
id;
423 if (pwm_cfg_src_is_tclk(tcfg1))
424 parent = s3c24xx_pwmclk_tclk(
id);
426 parent = s3c24xx_pwmclk_tdiv(
id);
442 struct clk *clk_timers;
447 if (IS_ERR(clk_timers)) {
452 for (clk = 0; clk <
ARRAY_SIZE(clk_timer_scaler); clk++)
453 clk_timer_scaler[clk].parent = clk_timers;
458 for (clk = 0; clk <
ARRAY_SIZE(clk_timer_tdiv); clk++) {
459 ret = clk_pwm_tdiv_register(clk);
467 for (clk = 0; clk <
ARRAY_SIZE(clk_tin); clk++) {
468 ret = clk_pwm_tin_register(&clk_tin[clk]);