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>
This commit is contained in:
parent
7c3603a199
commit
c7e41dac4f
|
@ -20,13 +20,12 @@
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
|
||||||
struct clk_divider {
|
static unsigned int clk_divider_maxdiv(struct clk_divider *div)
|
||||||
struct clk clk;
|
{
|
||||||
u8 shift;
|
if (div->flags & CLK_DIVIDER_ONE_BASED)
|
||||||
u8 width;
|
return (1 << div->width) - 1;
|
||||||
void __iomem *reg;
|
return 1 << div->width;
|
||||||
const char *parent;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
|
static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
|
||||||
unsigned long parent_rate)
|
unsigned long parent_rate)
|
||||||
|
@ -40,11 +39,11 @@ static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
|
||||||
rate = 1;
|
rate = 1;
|
||||||
|
|
||||||
divval = DIV_ROUND_UP(parent_rate, rate);
|
divval = DIV_ROUND_UP(parent_rate, rate);
|
||||||
|
if (divval > clk_divider_maxdiv(div))
|
||||||
|
divval = clk_divider_maxdiv(div);
|
||||||
|
|
||||||
if (divval > (1 << div->width))
|
if (!(div->flags & CLK_DIVIDER_ONE_BASED))
|
||||||
divval = 1 << (div->width);
|
divval--;
|
||||||
|
|
||||||
divval--;
|
|
||||||
|
|
||||||
val = readl(div->reg);
|
val = readl(div->reg);
|
||||||
val &= ~(((1 << div->width) - 1) << div->shift);
|
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 = readl(div->reg) >> div->shift;
|
||||||
val &= (1 << div->width) - 1;
|
val &= (1 << div->width) - 1;
|
||||||
|
|
||||||
val++;
|
if (div->flags & CLK_DIVIDER_ONE_BASED) {
|
||||||
|
if (!val)
|
||||||
|
val++;
|
||||||
|
} else {
|
||||||
|
val++;
|
||||||
|
}
|
||||||
|
|
||||||
return parent_rate / val;
|
return parent_rate / val;
|
||||||
}
|
}
|
||||||
|
@ -96,3 +100,19 @@ struct clk *clk_divider(const char *name, const char *parent,
|
||||||
|
|
||||||
return &div->clk;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -188,8 +188,23 @@ struct clk_div_table {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct clk *clk_fixed(const char *name, int rate);
|
struct clk *clk_fixed(const char *name, int rate);
|
||||||
|
|
||||||
|
struct clk_divider {
|
||||||
|
struct clk clk;
|
||||||
|
u8 shift;
|
||||||
|
u8 width;
|
||||||
|
void __iomem *reg;
|
||||||
|
const char *parent;
|
||||||
|
#define CLK_DIVIDER_ONE_BASED (1 << 0)
|
||||||
|
unsigned flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct clk_ops clk_divider_ops;
|
||||||
|
|
||||||
struct clk *clk_divider(const char *name, const char *parent,
|
struct clk *clk_divider(const char *name, const char *parent,
|
||||||
void __iomem *reg, u8 shift, u8 width);
|
void __iomem *reg, u8 shift, u8 width);
|
||||||
|
struct clk *clk_divider_one_based(const char *name, const char *parent,
|
||||||
|
void __iomem *reg, u8 shift, u8 width);
|
||||||
struct clk *clk_divider_table(const char *name,
|
struct clk *clk_divider_table(const char *name,
|
||||||
const char *parent, void __iomem *reg, u8 shift, u8 width,
|
const char *parent, void __iomem *reg, u8 shift, u8 width,
|
||||||
const struct clk_div_table *table);
|
const struct clk_div_table *table);
|
||||||
|
|
Loading…
Reference in New Issue