Skip to content

Commit

Permalink
clk: at91: Migrate to clk_hw based registration and OF APIs
Browse files Browse the repository at this point in the history
Now that we have clk_hw based provider APIs to register clks, we
can get rid of struct clk pointers in this driver, allowing us to
move closer to a clear split of consumer and provider clk APIs.

Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Tested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  • Loading branch information
Stephen Boyd authored and Stephen Boyd committed Sep 15, 2016
1 parent b19f009 commit f5644f1
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 199 deletions.
30 changes: 17 additions & 13 deletions drivers/clk/at91/clk-generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,16 @@ static void clk_generated_startup(struct clk_generated *gck)
>> AT91_PMC_PCR_GCKDIV_OFFSET;
}

static struct clk * __init
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
*name, const char **parent_names, u8 num_parents,
u8 id, const struct clk_range *range)
static struct clk_hw * __init
at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
const char *name, const char **parent_names,
u8 num_parents, u8 id,
const struct clk_range *range)
{
struct clk_generated *gck;
struct clk *clk = NULL;
struct clk_init_data init;
struct clk_hw *hw;
int ret;

gck = kzalloc(sizeof(*gck), GFP_KERNEL);
if (!gck)
Expand All @@ -258,21 +260,23 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
gck->lock = lock;
gck->range = *range;

clk = clk_register(NULL, &gck->hw);
if (IS_ERR(clk))
hw = &gck->hw;
ret = clk_hw_register(NULL, &gck->hw);
if (ret) {
kfree(gck);
else
hw = ERR_PTR(ret);
} else
clk_generated_startup(gck);

return clk;
return hw;
}

static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
{
int num;
u32 id;
const char *name;
struct clk *clk;
struct clk_hw *hw;
unsigned int num_parents;
const char *parent_names[GENERATED_SOURCE_MAX];
struct device_node *gcknp;
Expand Down Expand Up @@ -306,13 +310,13 @@ static void __init of_sama5d2_clk_generated_setup(struct device_node *np)
of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
&range);

clk = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
hw = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
parent_names, num_parents,
id, &range);
if (IS_ERR(clk))
if (IS_ERR(hw))
continue;

of_clk_add_provider(gcknp, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(gcknp, of_clk_hw_simple_get, hw);
}
}
CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",
Expand Down
8 changes: 4 additions & 4 deletions drivers/clk/at91/clk-h32mx.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
struct clk_init_data init;
const char *parent_name;
struct regmap *regmap;
struct clk *clk;
int ret;

regmap = syscon_node_to_regmap(of_get_parent(np));
if (IS_ERR(regmap))
Expand All @@ -113,13 +113,13 @@ static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
h32mxclk->hw.init = &init;
h32mxclk->regmap = regmap;

clk = clk_register(NULL, &h32mxclk->hw);
if (IS_ERR(clk)) {
ret = clk_hw_register(NULL, &h32mxclk->hw);
if (ret) {
kfree(h32mxclk);
return;
}

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, &h32mxclk->hw);
}
CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
of_sama5d4_clk_h32mx_setup);
88 changes: 52 additions & 36 deletions drivers/clk/at91/clk-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ static const struct clk_ops main_osc_ops = {
.is_prepared = clk_main_osc_is_prepared,
};

static struct clk * __init
static struct clk_hw * __init
at91_clk_register_main_osc(struct regmap *regmap,
const char *name,
const char *parent_name,
bool bypass)
{
struct clk_main_osc *osc;
struct clk *clk = NULL;
struct clk_init_data init;
struct clk_hw *hw;
int ret;

if (!name || !parent_name)
return ERR_PTR(-EINVAL);
Expand All @@ -160,16 +161,19 @@ at91_clk_register_main_osc(struct regmap *regmap,
AT91_PMC_MOSCEN,
AT91_PMC_OSCBYPASS | AT91_PMC_KEY);

clk = clk_register(NULL, &osc->hw);
if (IS_ERR(clk))
hw = &osc->hw;
ret = clk_hw_register(NULL, &osc->hw);
if (ret) {
kfree(osc);
hw = ERR_PTR(ret);
}

return clk;
return hw;
}

static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
{
struct clk *clk;
struct clk_hw *hw;
const char *name = np->name;
const char *parent_name;
struct regmap *regmap;
Expand All @@ -183,11 +187,11 @@ static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
if (IS_ERR(regmap))
return;

clk = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
if (IS_ERR(clk))
hw = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
if (IS_ERR(hw))
return;

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
}
CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc",
of_at91rm9200_clk_main_osc_setup);
Expand Down Expand Up @@ -271,14 +275,15 @@ static const struct clk_ops main_rc_osc_ops = {
.recalc_accuracy = clk_main_rc_osc_recalc_accuracy,
};

static struct clk * __init
static struct clk_hw * __init
at91_clk_register_main_rc_osc(struct regmap *regmap,
const char *name,
u32 frequency, u32 accuracy)
{
struct clk_main_rc_osc *osc;
struct clk *clk = NULL;
struct clk_init_data init;
struct clk_hw *hw;
int ret;

if (!name || !frequency)
return ERR_PTR(-EINVAL);
Expand All @@ -298,16 +303,19 @@ at91_clk_register_main_rc_osc(struct regmap *regmap,
osc->frequency = frequency;
osc->accuracy = accuracy;

clk = clk_register(NULL, &osc->hw);
if (IS_ERR(clk))
hw = &osc->hw;
ret = clk_hw_register(NULL, hw);
if (ret) {
kfree(osc);
hw = ERR_PTR(ret);
}

return clk;
return hw;
}

static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
{
struct clk *clk;
struct clk_hw *hw;
u32 frequency = 0;
u32 accuracy = 0;
const char *name = np->name;
Expand All @@ -321,11 +329,11 @@ static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
if (IS_ERR(regmap))
return;

clk = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
if (IS_ERR(clk))
hw = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
if (IS_ERR(hw))
return;

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
}
CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc",
of_at91sam9x5_clk_main_rc_osc_setup);
Expand Down Expand Up @@ -395,14 +403,15 @@ static const struct clk_ops rm9200_main_ops = {
.recalc_rate = clk_rm9200_main_recalc_rate,
};

static struct clk * __init
static struct clk_hw * __init
at91_clk_register_rm9200_main(struct regmap *regmap,
const char *name,
const char *parent_name)
{
struct clk_rm9200_main *clkmain;
struct clk *clk = NULL;
struct clk_init_data init;
struct clk_hw *hw;
int ret;

if (!name)
return ERR_PTR(-EINVAL);
Expand All @@ -423,16 +432,19 @@ at91_clk_register_rm9200_main(struct regmap *regmap,
clkmain->hw.init = &init;
clkmain->regmap = regmap;

clk = clk_register(NULL, &clkmain->hw);
if (IS_ERR(clk))
hw = &clkmain->hw;
ret = clk_hw_register(NULL, &clkmain->hw);
if (ret) {
kfree(clkmain);
hw = ERR_PTR(ret);
}

return clk;
return hw;
}

static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
{
struct clk *clk;
struct clk_hw *hw;
const char *parent_name;
const char *name = np->name;
struct regmap *regmap;
Expand All @@ -444,11 +456,11 @@ static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
if (IS_ERR(regmap))
return;

clk = at91_clk_register_rm9200_main(regmap, name, parent_name);
if (IS_ERR(clk))
hw = at91_clk_register_rm9200_main(regmap, name, parent_name);
if (IS_ERR(hw))
return;

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
}
CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main",
of_at91rm9200_clk_main_setup);
Expand Down Expand Up @@ -529,16 +541,17 @@ static const struct clk_ops sam9x5_main_ops = {
.get_parent = clk_sam9x5_main_get_parent,
};

static struct clk * __init
static struct clk_hw * __init
at91_clk_register_sam9x5_main(struct regmap *regmap,
const char *name,
const char **parent_names,
int num_parents)
{
struct clk_sam9x5_main *clkmain;
struct clk *clk = NULL;
struct clk_init_data init;
unsigned int status;
struct clk_hw *hw;
int ret;

if (!name)
return ERR_PTR(-EINVAL);
Expand All @@ -561,16 +574,19 @@ at91_clk_register_sam9x5_main(struct regmap *regmap,
regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status);
clkmain->parent = status & AT91_PMC_MOSCEN ? 1 : 0;

clk = clk_register(NULL, &clkmain->hw);
if (IS_ERR(clk))
hw = &clkmain->hw;
ret = clk_hw_register(NULL, &clkmain->hw);
if (ret) {
kfree(clkmain);
hw = ERR_PTR(ret);
}

return clk;
return hw;
}

static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
{
struct clk *clk;
struct clk_hw *hw;
const char *parent_names[2];
unsigned int num_parents;
const char *name = np->name;
Expand All @@ -587,12 +603,12 @@ static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)

of_property_read_string(np, "clock-output-names", &name);

clk = at91_clk_register_sam9x5_main(regmap, name, parent_names,
hw = at91_clk_register_sam9x5_main(regmap, name, parent_names,
num_parents);
if (IS_ERR(clk))
if (IS_ERR(hw))
return;

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
}
CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main",
of_at91sam9x5_clk_main_setup);
21 changes: 12 additions & 9 deletions drivers/clk/at91/clk-master.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,17 @@ static const struct clk_ops master_ops = {
.get_parent = clk_master_get_parent,
};

static struct clk * __init
static struct clk_hw * __init
at91_clk_register_master(struct regmap *regmap,
const char *name, int num_parents,
const char **parent_names,
const struct clk_master_layout *layout,
const struct clk_master_characteristics *characteristics)
{
struct clk_master *master;
struct clk *clk = NULL;
struct clk_init_data init;
struct clk_hw *hw;
int ret;

if (!name || !num_parents || !parent_names)
return ERR_PTR(-EINVAL);
Expand All @@ -149,12 +150,14 @@ at91_clk_register_master(struct regmap *regmap,
master->characteristics = characteristics;
master->regmap = regmap;

clk = clk_register(NULL, &master->hw);
if (IS_ERR(clk)) {
hw = &master->hw;
ret = clk_hw_register(NULL, &master->hw);
if (ret) {
kfree(master);
hw = ERR_PTR(ret);
}

return clk;
return hw;
}


Expand Down Expand Up @@ -198,7 +201,7 @@ static void __init
of_at91_clk_master_setup(struct device_node *np,
const struct clk_master_layout *layout)
{
struct clk *clk;
struct clk_hw *hw;
unsigned int num_parents;
const char *parent_names[MASTER_SOURCE_MAX];
const char *name = np->name;
Expand All @@ -221,13 +224,13 @@ of_at91_clk_master_setup(struct device_node *np,
if (IS_ERR(regmap))
return;

clk = at91_clk_register_master(regmap, name, num_parents,
hw = at91_clk_register_master(regmap, name, num_parents,
parent_names, layout,
characteristics);
if (IS_ERR(clk))
if (IS_ERR(hw))
goto out_free_characteristics;

of_clk_add_provider(np, of_clk_src_simple_get, clk);
of_clk_add_hw_provider(np, of_clk_hw_simple_get, hw);
return;

out_free_characteristics:
Expand Down
Loading

0 comments on commit f5644f1

Please sign in to comment.