Commit 1bdf0232 authored by Boris Brezillon's avatar Boris Brezillon Committed by Alexandre Belloni

clk: at91: make use of syscon/regmap internally

Use the regmap coming from syscon to access the registers instead of using
pmc_read/pmc_write. This allows to avoid passing the at91_pmc structure to
the child nodes of the PMC.

The final benefit is to have each clock register itself instead of having
to iterate over the children.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent 863a81c3
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
#include "pmc.h" #include "pmc.h"
...@@ -28,8 +30,9 @@ ...@@ -28,8 +30,9 @@
struct clk_generated { struct clk_generated {
struct clk_hw hw; struct clk_hw hw;
struct at91_pmc *pmc; struct regmap *regmap;
struct clk_range range; struct clk_range range;
spinlock_t *lock;
u32 id; u32 id;
u32 gckdiv; u32 gckdiv;
u8 parent_id; u8 parent_id;
...@@ -41,49 +44,52 @@ struct clk_generated { ...@@ -41,49 +44,52 @@ struct clk_generated {
static int clk_generated_enable(struct clk_hw *hw) static int clk_generated_enable(struct clk_hw *hw)
{ {
struct clk_generated *gck = to_clk_generated(hw); struct clk_generated *gck = to_clk_generated(hw);
struct at91_pmc *pmc = gck->pmc; unsigned long flags;
u32 tmp;
pr_debug("GCLK: %s, gckdiv = %d, parent id = %d\n", pr_debug("GCLK: %s, gckdiv = %d, parent id = %d\n",
__func__, gck->gckdiv, gck->parent_id); __func__, gck->gckdiv, gck->parent_id);
pmc_lock(pmc); spin_lock_irqsave(gck->lock, flags);
pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); regmap_write(gck->regmap, AT91_PMC_PCR,
tmp = pmc_read(pmc, AT91_PMC_PCR) & (gck->id & AT91_PMC_PCR_PID_MASK));
~(AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK); regmap_update_bits(gck->regmap, AT91_PMC_PCR,
pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_GCKCSS(gck->parent_id) AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK |
| AT91_PMC_PCR_CMD AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN,
| AT91_PMC_PCR_GCKDIV(gck->gckdiv) AT91_PMC_PCR_GCKCSS(gck->parent_id) |
| AT91_PMC_PCR_GCKEN); AT91_PMC_PCR_CMD |
pmc_unlock(pmc); AT91_PMC_PCR_GCKDIV(gck->gckdiv) |
AT91_PMC_PCR_GCKEN);
spin_unlock_irqrestore(gck->lock, flags);
return 0; return 0;
} }
static void clk_generated_disable(struct clk_hw *hw) static void clk_generated_disable(struct clk_hw *hw)
{ {
struct clk_generated *gck = to_clk_generated(hw); struct clk_generated *gck = to_clk_generated(hw);
struct at91_pmc *pmc = gck->pmc; unsigned long flags;
u32 tmp;
spin_lock_irqsave(gck->lock, flags);
pmc_lock(pmc); regmap_write(gck->regmap, AT91_PMC_PCR,
pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); (gck->id & AT91_PMC_PCR_PID_MASK));
tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_GCKEN; regmap_update_bits(gck->regmap, AT91_PMC_PCR,
pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD); AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN,
pmc_unlock(pmc); AT91_PMC_PCR_CMD);
spin_unlock_irqrestore(gck->lock, flags);
} }
static int clk_generated_is_enabled(struct clk_hw *hw) static int clk_generated_is_enabled(struct clk_hw *hw)
{ {
struct clk_generated *gck = to_clk_generated(hw); struct clk_generated *gck = to_clk_generated(hw);
struct at91_pmc *pmc = gck->pmc; unsigned long flags;
int ret; unsigned int status;
pmc_lock(pmc); spin_lock_irqsave(gck->lock, flags);
pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); regmap_write(gck->regmap, AT91_PMC_PCR,
ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_GCKEN); (gck->id & AT91_PMC_PCR_PID_MASK));
pmc_unlock(pmc); regmap_read(gck->regmap, AT91_PMC_PCR, &status);
spin_unlock_irqrestore(gck->lock, flags);
return ret; return status & AT91_PMC_PCR_GCKEN ? 1 : 0;
} }
static unsigned long static unsigned long
...@@ -214,13 +220,14 @@ static const struct clk_ops generated_ops = { ...@@ -214,13 +220,14 @@ static const struct clk_ops generated_ops = {
*/ */
static void clk_generated_startup(struct clk_generated *gck) static void clk_generated_startup(struct clk_generated *gck)
{ {
struct at91_pmc *pmc = gck->pmc;
u32 tmp; u32 tmp;
unsigned long flags;
pmc_lock(pmc); spin_lock_irqsave(gck->lock, flags);
pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK)); regmap_write(gck->regmap, AT91_PMC_PCR,
tmp = pmc_read(pmc, AT91_PMC_PCR); (gck->id & AT91_PMC_PCR_PID_MASK));
pmc_unlock(pmc); regmap_read(gck->regmap, AT91_PMC_PCR, &tmp);
spin_unlock_irqrestore(gck->lock, flags);
gck->parent_id = (tmp & AT91_PMC_PCR_GCKCSS_MASK) gck->parent_id = (tmp & AT91_PMC_PCR_GCKCSS_MASK)
>> AT91_PMC_PCR_GCKCSS_OFFSET; >> AT91_PMC_PCR_GCKCSS_OFFSET;
...@@ -229,8 +236,8 @@ static void clk_generated_startup(struct clk_generated *gck) ...@@ -229,8 +236,8 @@ static void clk_generated_startup(struct clk_generated *gck)
} }
static struct clk * __init static struct clk * __init
at91_clk_register_generated(struct at91_pmc *pmc, const char *name, at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
const char **parent_names, u8 num_parents, *name, const char **parent_names, u8 num_parents,
u8 id, const struct clk_range *range) u8 id, const struct clk_range *range)
{ {
struct clk_generated *gck; struct clk_generated *gck;
...@@ -249,7 +256,8 @@ at91_clk_register_generated(struct at91_pmc *pmc, const char *name, ...@@ -249,7 +256,8 @@ at91_clk_register_generated(struct at91_pmc *pmc, const char *name,
gck->id = id; gck->id = id;
gck->hw.init = &init; gck->hw.init = &init;
gck->pmc = pmc; gck->regmap = regmap;
gck->lock = lock;
gck->range = *range; gck->range = *range;
clk = clk_register(NULL, &gck->hw); clk = clk_register(NULL, &gck->hw);
...@@ -261,8 +269,7 @@ at91_clk_register_generated(struct at91_pmc *pmc, const char *name, ...@@ -261,8 +269,7 @@ at91_clk_register_generated(struct at91_pmc *pmc, const char *name,
return clk; return clk;
} }
void __init of_sama5d2_clk_generated_setup(struct device_node *np, void __init of_sama5d2_clk_generated_setup(struct device_node *np)
struct at91_pmc *pmc)
{ {
int num; int num;
u32 id; u32 id;
...@@ -272,6 +279,7 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np, ...@@ -272,6 +279,7 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np,
const char *parent_names[GENERATED_SOURCE_MAX]; const char *parent_names[GENERATED_SOURCE_MAX];
struct device_node *gcknp; struct device_node *gcknp;
struct clk_range range = CLK_RANGE(0, 0); struct clk_range range = CLK_RANGE(0, 0);
struct regmap *regmap;
num_parents = of_clk_get_parent_count(np); num_parents = of_clk_get_parent_count(np);
if (num_parents <= 0 || num_parents > GENERATED_SOURCE_MAX) if (num_parents <= 0 || num_parents > GENERATED_SOURCE_MAX)
...@@ -283,6 +291,10 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np, ...@@ -283,6 +291,10 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np,
if (!num || num > PERIPHERAL_MAX) if (!num || num > PERIPHERAL_MAX)
return; return;
regmap = syscon_node_to_regmap(of_get_parent(np));
if (IS_ERR(regmap))
return;
for_each_child_of_node(np, gcknp) { for_each_child_of_node(np, gcknp) {
if (of_property_read_u32(gcknp, "reg", &id)) if (of_property_read_u32(gcknp, "reg", &id))
continue; continue;
...@@ -296,11 +308,14 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np, ...@@ -296,11 +308,14 @@ void __init of_sama5d2_clk_generated_setup(struct device_node *np,
of_at91_get_clk_range(gcknp, "atmel,clk-output-range", of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
&range); &range);
clk = at91_clk_register_generated(pmc, name, parent_names, clk = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
num_parents, id, &range); parent_names, num_parents,
id, &range);
if (IS_ERR(clk)) if (IS_ERR(clk))
continue; continue;
of_clk_add_provider(gcknp, of_clk_src_simple_get, clk); of_clk_add_provider(gcknp, of_clk_src_simple_get, clk);
} }
} }
CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",
of_sama5d2_clk_generated_setup);
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/regmap.h>
#include <linux/mfd/syscon.h>
#include "pmc.h" #include "pmc.h"
...@@ -31,7 +33,7 @@ ...@@ -31,7 +33,7 @@
struct clk_sama5d4_h32mx { struct clk_sama5d4_h32mx {
struct clk_hw hw; struct clk_hw hw;
struct at91_pmc *pmc; struct regmap *regmap;
}; };
#define to_clk_sama5d4_h32mx(hw) container_of(hw, struct clk_sama5d4_h32mx, hw) #define to_clk_sama5d4_h32mx(hw) container_of(hw, struct clk_sama5d4_h32mx, hw)
...@@ -40,8 +42,10 @@ static unsigned long clk_sama5d4_h32mx_recalc_rate(struct clk_hw *hw, ...@@ -40,8 +42,10 @@ static unsigned long clk_sama5d4_h32mx_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate) unsigned long parent_rate)
{ {
struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw); struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
unsigned int mckr;
if (pmc_read(h32mxclk->pmc, AT91_PMC_MCKR) & AT91_PMC_H32MXDIV) regmap_read(h32mxclk->regmap, AT91_PMC_MCKR, &mckr);
if (mckr & AT91_PMC_H32MXDIV)
return parent_rate / 2; return parent_rate / 2;
if (parent_rate > H32MX_MAX_FREQ) if (parent_rate > H32MX_MAX_FREQ)
...@@ -70,18 +74,16 @@ static int clk_sama5d4_h32mx_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -70,18 +74,16 @@ static int clk_sama5d4_h32mx_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate) unsigned long parent_rate)
{ {
struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw); struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
struct at91_pmc *pmc = h32mxclk->pmc; u32 mckr = 0;
u32 tmp;
if (parent_rate != rate && (parent_rate / 2) != rate) if (parent_rate != rate && (parent_rate / 2) != rate)
return -EINVAL; return -EINVAL;
pmc_lock(pmc);
tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_H32MXDIV;
if ((parent_rate / 2) == rate) if ((parent_rate / 2) == rate)
tmp |= AT91_PMC_H32MXDIV; mckr = AT91_PMC_H32MXDIV;
pmc_write(pmc, AT91_PMC_MCKR, tmp);
pmc_unlock(pmc); regmap_update_bits(h32mxclk->regmap, AT91_PMC_MCKR,
AT91_PMC_H32MXDIV, mckr);
return 0; return 0;
} }
...@@ -92,14 +94,18 @@ static const struct clk_ops h32mx_ops = { ...@@ -92,14 +94,18 @@ static const struct clk_ops h32mx_ops = {
.set_rate = clk_sama5d4_h32mx_set_rate, .set_rate = clk_sama5d4_h32mx_set_rate,
}; };
void __init of_sama5d4_clk_h32mx_setup(struct device_node *np, static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
struct at91_pmc *pmc)
{ {
struct clk_sama5d4_h32mx *h32mxclk; struct clk_sama5d4_h32mx *h32mxclk;
struct clk_init_data init; struct clk_init_data init;
const char *parent_name; const char *parent_name;
struct regmap *regmap;
struct clk *clk; struct clk *clk;
regmap = syscon_node_to_regmap(of_get_parent(np));
if (IS_ERR(regmap))
return;
h32mxclk = kzalloc(sizeof(*h32mxclk), GFP_KERNEL); h32mxclk = kzalloc(sizeof(*h32mxclk), GFP_KERNEL);
if (!h32mxclk) if (!h32mxclk)
return; return;
...@@ -113,7 +119,7 @@ void __init of_sama5d4_clk_h32mx_setup(struct device_node *np, ...@@ -113,7 +119,7 @@ void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
init.flags = CLK_SET_RATE_GATE; init.flags = CLK_SET_RATE_GATE;
h32mxclk->hw.init = &init; h32mxclk->hw.init = &init;
h32mxclk->pmc = pmc; h32mxclk->regmap = regmap;
clk = clk_register(NULL, &h32mxclk->hw); clk = clk_register(NULL, &h32mxclk->hw);
if (!clk) { if (!clk) {
...@@ -123,3 +129,5 @@ void __init of_sama5d4_clk_h32mx_setup(struct device_node *np, ...@@ -123,3 +129,5 @@ void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
of_clk_add_provider(np, of_clk_src_simple_get, clk); of_clk_add_provider(np, of_clk_src_simple_get, clk);
} }
CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
of_sama5d4_clk_h32mx_setup);
This diff is collapsed.
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
#include "pmc.h" #include "pmc.h"
...@@ -44,7 +46,7 @@ struct clk_master_layout { ...@@ -44,7 +46,7 @@ struct clk_master_layout {
struct clk_master { struct clk_master {
struct clk_hw hw; struct clk_hw hw;
struct at91_pmc *pmc; struct regmap *regmap;
unsigned int irq; unsigned int irq;
wait_queue_head_t wait; wait_queue_head_t wait;
const struct clk_master_layout *layout; const struct clk_master_layout *layout;
...@@ -60,15 +62,24 @@ static irqreturn_t clk_master_irq_handler(int irq, void *dev_id) ...@@ -60,15 +62,24 @@ static irqreturn_t clk_master_irq_handler(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static inline bool clk_master_ready(struct regmap *regmap)
{
unsigned int status;
regmap_read(regmap, AT91_PMC_SR, &status);
return status & AT91_PMC_MCKRDY ? 1 : 0;
}
static int clk_master_prepare(struct clk_hw *hw) static int clk_master_prepare(struct clk_hw *hw)
{ {
struct clk_master *master = to_clk_master(hw); struct clk_master *master = to_clk_master(hw);
struct at91_pmc *pmc = master->pmc;
while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY)) { while (!clk_master_ready(master->regmap)) {
enable_irq(master->irq); enable_irq(master->irq);
wait_event(master->wait, wait_event(master->wait,
pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY); clk_master_ready(master->regmap));
} }
return 0; return 0;
...@@ -78,7 +89,7 @@ static int clk_master_is_prepared(struct clk_hw *hw) ...@@ -78,7 +89,7 @@ static int clk_master_is_prepared(struct clk_hw *hw)
{ {
struct clk_master *master = to_clk_master(hw); struct clk_master *master = to_clk_master(hw);
return !!(pmc_read(master->pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY); return clk_master_ready(master->regmap);
} }
static unsigned long clk_master_recalc_rate(struct clk_hw *hw, static unsigned long clk_master_recalc_rate(struct clk_hw *hw,
...@@ -88,18 +99,16 @@ static unsigned long clk_master_recalc_rate(struct clk_hw *hw, ...@@ -88,18 +99,16 @@ static unsigned long clk_master_recalc_rate(struct clk_hw *hw,
u8 div; u8 div;
unsigned long rate = parent_rate; unsigned long rate = parent_rate;
struct clk_master *master = to_clk_master(hw); struct clk_master *master = to_clk_master(hw);
struct at91_pmc *pmc = master->pmc;
const struct clk_master_layout *layout = master->layout; const struct clk_master_layout *layout = master->layout;
const struct clk_master_characteristics *characteristics = const struct clk_master_characteristics *characteristics =
master->characteristics; master->characteristics;
u32 tmp; unsigned int mckr;
pmc_lock(pmc); regmap_read(master->regmap, AT91_PMC_MCKR, &mckr);
tmp = pmc_read(pmc, AT91_PMC_MCKR) & layout->mask; mckr &= layout->mask;
pmc_unlock(pmc);
pres = (tmp >> layout->pres_shift) & MASTER_PRES_MASK; pres = (mckr >> layout->pres_shift) & MASTER_PRES_MASK;
div = (tmp >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK; div = (mckr >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK;
if (characteristics->have_div3_pres && pres == MASTER_PRES_MAX) if (characteristics->have_div3_pres && pres == MASTER_PRES_MAX)
rate /= 3; rate /= 3;
...@@ -119,9 +128,11 @@ static unsigned long clk_master_recalc_rate(struct clk_hw *hw, ...@@ -119,9 +128,11 @@ static unsigned long clk_master_recalc_rate(struct clk_hw *hw,
static u8 clk_master_get_parent(struct clk_hw *hw) static u8 clk_master_get_parent(struct clk_hw *hw)
{ {
struct clk_master *master = to_clk_master(hw); struct clk_master *master = to_clk_master(hw);
struct at91_pmc *pmc = master->pmc; unsigned int mckr;
regmap_read(master->regmap, AT91_PMC_MCKR, &mckr);
return pmc_read(pmc, AT91_PMC_MCKR) & AT91_PMC_CSS; return mckr & AT91_PMC_CSS;
} }
static const struct clk_ops master_ops = { static const struct clk_ops master_ops = {
...@@ -132,7 +143,7 @@ static const struct clk_ops master_ops = { ...@@ -132,7 +143,7 @@ static const struct clk_ops master_ops = {
}; };
static struct clk * __init static struct clk * __init
at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq, at91_clk_register_master(struct regmap *regmap, unsigned int irq,
const char *name, int num_parents, const char *name, int num_parents,
const char **parent_names, const char **parent_names,
const struct clk_master_layout *layout, const struct clk_master_layout *layout,
...@@ -143,7 +154,7 @@ at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq, ...@@ -143,7 +154,7 @@ at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq,
struct clk *clk = NULL; struct clk *clk = NULL;
struct clk_init_data init; struct clk_init_data init;
if (!pmc || !irq || !name || !num_parents || !parent_names) if (!name || !num_parents || !parent_names)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
master = kzalloc(sizeof(*master), GFP_KERNEL); master = kzalloc(sizeof(*master), GFP_KERNEL);
...@@ -159,7 +170,7 @@ at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq, ...@@ -159,7 +170,7 @@ at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq,
master->hw.init = &init; master->hw.init = &init;
master->layout = layout; master->layout = layout;
master->characteristics = characteristics; master->characteristics = characteristics;
master->pmc = pmc; master->regmap = regmap;
master->irq = irq; master->irq = irq;
init_waitqueue_head(&master->wait); init_waitqueue_head(&master->wait);
irq_set_status_flags(master->irq, IRQ_NOAUTOEN); irq_set_status_flags(master->irq, IRQ_NOAUTOEN);
...@@ -217,7 +228,7 @@ out_free_characteristics: ...@@ -217,7 +228,7 @@ out_free_characteristics:
} }
static void __init static void __init
of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc, of_at91_clk_master_setup(struct device_node *np,
const struct clk_master_layout *layout) const struct clk_master_layout *layout)
{ {
struct clk *clk; struct clk *clk;
...@@ -226,6 +237,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc, ...@@ -226,6 +237,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,
const char *parent_names[MASTER_SOURCE_MAX]; const char *parent_names[MASTER_SOURCE_MAX];
const char *name = np->name; const char *name = np->name;
struct clk_master_characteristics *characteristics; struct clk_master_characteristics *characteristics;
struct regmap *regmap;
num_parents = of_clk_get_parent_count(np); num_parents = of_clk_get_parent_count(np);
if (num_parents <= 0 || num_parents > MASTER_SOURCE_MAX) if (num_parents <= 0 || num_parents > MASTER_SOURCE_MAX)
...@@ -239,11 +251,15 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc, ...@@ -239,11 +251,15 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,
if (!characteristics) if (!characteristics)
return; return;
regmap = syscon_node_to_regmap(of_get_parent(np));
if (IS_ERR(regmap))
return;
irq = irq_of_parse_and_map(np, 0); irq = irq_of_parse_and_map(np, 0);
if (!irq) if (!irq)
goto out_free_characteristics; goto out_free_characteristics;
clk = at91_clk_register_master(pmc, irq, name, num_parents, clk = at91_clk_register_master(regmap, irq, name, num_parents,
parent_names, layout, parent_names, layout,
characteristics); characteristics);
if (IS_ERR(clk)) if (IS_ERR(clk))
...@@ -256,14 +272,16 @@ out_free_characteristics: ...@@ -256,14 +272,16 @@ out_free_characteristics:
kfree(characteristics); kfree(characteristics);
} }
void __init of_at91rm9200_clk_master_setup(struct device_node *np, static void __init of_at91rm9200_clk_master_setup(struct device_node *np)
struct at91_pmc *pmc)
{ {
of_at91_clk_master_setup(np, pmc, &at91rm9200_master_layout); of_at91_clk_master_setup(np, &at91rm9200_master_layout);
} }
CLK_OF_DECLARE(at91rm9200_clk_master, "atmel,at91rm9200-clk-master",
of_at91rm9200_clk_master_setup);
void __init of_at91sam9x5_clk_master_setup(struct device_node *np, static void __init of_at91sam9x5_clk_master_setup(struct device_node *np)
struct at91_pmc *pmc)
{ {
of_at91_clk_master_setup(np, pmc, &at91sam9x5_master_layout); of_at91_clk_master_setup(np, &at91sam9x5_master_layout);
} }
CLK_OF_DECLARE(at91sam9x5_clk_master, "atmel,at91sam9x5-clk-master",
of_at91sam9x5_clk_master_setup);
...@@ -14,9 +14,13 @@ ...@@ -14,9 +14,13 @@
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mfd/syscon.h>
#include <linux/regmap.h>
#include "pmc.h" #include "pmc.h"
DEFINE_SPINLOCK(pmc_pcr_lock);
#define PERIPHERAL_MAX 64 #define PERIPHERAL_MAX 64
#define PERIPHERAL_AT91RM9200 0 #define PERIPHERAL_AT91RM9200 0
...@@ -33,7 +37,7 @@ ...@@ -33,7 +37,7 @@
struct clk_peripheral { struct clk_peripheral {
struct clk_hw hw; struct clk_hw hw;
struct at91_pmc *pmc; struct regmap *regmap;
u32 id; u32 id;
}; };
...@@ -41,8 +45,9 @@ struct clk_peripheral { ...@@ -41,8 +45,9 @@ struct clk_peripheral {
struct clk_sam9x5_peripheral { struct clk_sam9x5_peripheral {
struct clk_hw hw; struct clk_hw hw;
struct at91_pmc *pmc; struct regmap *regmap;
struct clk_range range; struct clk_range range;
spinlock_t *lock;
u32 id; u32 id;
u32 div; u32 div;
bool auto_div; bool auto_div;
...@@ -54,7 +59,6 @@ struct clk_sam9x5_peripheral { ...@@ -54,7 +59,6 @@ struct clk_sam9x5_peripheral {
static int clk_peripheral_enable(struct clk_hw *hw) static int clk_peripheral_enable(struct clk_hw *hw)
{ {
struct clk_peripheral *periph = to_clk_peripheral(hw); struct clk_peripheral *periph = to_clk_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
int offset = AT91_PMC_PCER; int offset = AT91_PMC_PCER;
u32 id = periph->id; u32 id = periph->id;
...@@ -62,14 +66,14 @@ static int clk_peripheral_enable(struct clk_hw *hw) ...@@ -62,14 +66,14 @@ static int clk_peripheral_enable(struct clk_hw *hw)
return 0; return 0;
if (id > PERIPHERAL_ID_MAX) if (id > PERIPHERAL_ID_MAX)
offset = AT91_PMC_PCER1; offset = AT91_PMC_PCER1;
pmc_write(pmc, offset, PERIPHERAL_MASK(id)); regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id));
return 0; return 0;
} }
static void clk_peripheral_disable(struct clk_hw *hw) static void clk_peripheral_disable(struct clk_hw *hw)
{ {
struct clk_peripheral *periph = to_clk_peripheral(hw); struct clk_peripheral *periph = to_clk_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
int offset = AT91_PMC_PCDR; int offset = AT91_PMC_PCDR;
u32 id = periph->id; u32 id = periph->id;
...@@ -77,21 +81,23 @@ static void clk_peripheral_disable(struct clk_hw *hw) ...@@ -77,21 +81,23 @@ static void clk_peripheral_disable(struct clk_hw *hw)
return; return;
if (id > PERIPHERAL_ID_MAX) if (id > PERIPHERAL_ID_MAX)
offset = AT91_PMC_PCDR1; offset = AT91_PMC_PCDR1;
pmc_write(pmc, offset, PERIPHERAL_MASK(id)); regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id));
} }
static int clk_peripheral_is_enabled(struct clk_hw *hw) static int clk_peripheral_is_enabled(struct clk_hw *hw)
{ {
struct clk_peripheral *periph = to_clk_peripheral(hw); struct clk_peripheral *periph = to_clk_peripheral(hw);
struct at91_pmc *pmc = periph->pmc;
int offset = AT91_PMC_PCSR; int offset = AT91_PMC_PCSR;
unsigned int status;
u32 id = periph->id; u32 id = periph->id;
if (id < PERIPHERAL_ID_MIN) if (id < PERIPHERAL_ID_MIN)
return 1; return 1;
if (id > PERIPHERAL_ID_MAX) if (id > PERIPHERAL_ID_MAX)
offset = AT91_PMC_PCSR1; offset = AT91_PMC_PCSR1