diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-04-15 14:06:28 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-06-20 08:44:22 +0200 |
commit | c7e41dac4fdb297be6a542389f017d725947649f (patch) | |
tree | c2a95c4353c936db51242b54060756a2cb8dd51d /drivers/clk/clk-divider.c | |
parent | 7c3603a199873319cbff82fe07a887ccf3452b9b (diff) | |
download | barebox-c7e41dac4fdb297be6a542389f017d725947649f.tar.gz barebox-c7e41dac4fdb297be6a542389f017d725947649f.tar.xz |
clk: divider: Add onebased divider support
In some dividers the register value matches the divider value. This
patch adds support for them.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/clk/clk-divider.c')
-rw-r--r-- | drivers/clk/clk-divider.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 58a7ea564c..3bf8105a8b 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -20,13 +20,12 @@ #include <linux/clk.h> #include <linux/err.h> -struct clk_divider { - struct clk clk; - u8 shift; - u8 width; - void __iomem *reg; - const char *parent; -}; +static unsigned int clk_divider_maxdiv(struct clk_divider *div) +{ + if (div->flags & CLK_DIVIDER_ONE_BASED) + return (1 << div->width) - 1; + return 1 << div->width; +} static int clk_divider_set_rate(struct clk *clk, unsigned long rate, unsigned long parent_rate) @@ -40,11 +39,11 @@ static int clk_divider_set_rate(struct clk *clk, unsigned long rate, rate = 1; divval = DIV_ROUND_UP(parent_rate, rate); + if (divval > clk_divider_maxdiv(div)) + divval = clk_divider_maxdiv(div); - if (divval > (1 << div->width)) - divval = 1 << (div->width); - - divval--; + if (!(div->flags & CLK_DIVIDER_ONE_BASED)) + divval--; val = readl(div->reg); val &= ~(((1 << div->width) - 1) << div->shift); @@ -63,7 +62,12 @@ static unsigned long clk_divider_recalc_rate(struct clk *clk, val = readl(div->reg) >> div->shift; val &= (1 << div->width) - 1; - val++; + if (div->flags & CLK_DIVIDER_ONE_BASED) { + if (!val) + val++; + } else { + val++; + } return parent_rate / val; } @@ -96,3 +100,19 @@ struct clk *clk_divider(const char *name, const char *parent, return &div->clk; } + +struct clk *clk_divider_one_based(const char *name, const char *parent, + void __iomem *reg, u8 shift, u8 width) +{ + struct clk_divider *div; + struct clk *clk; + + clk = clk_divider(name, parent, reg, shift, width); + if (IS_ERR(clk)) + return clk; + + div = container_of(clk, struct clk_divider, clk); + div->flags |= CLK_DIVIDER_ONE_BASED; + + return clk; +} |