|
@@ -14,13 +14,6 @@
|
|
|
#include <linux/syscore_ops.h>
|
|
#include <linux/syscore_ops.h>
|
|
|
#include "clk.h"
|
|
#include "clk.h"
|
|
|
|
|
|
|
|
-static DEFINE_SPINLOCK(lock);
|
|
|
|
|
-static struct clk **clk_table;
|
|
|
|
|
-static void __iomem *reg_base;
|
|
|
|
|
-#ifdef CONFIG_OF
|
|
|
|
|
-static struct clk_onecell_data clk_data;
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
void samsung_clk_save(void __iomem *base,
|
|
void samsung_clk_save(void __iomem *base,
|
|
|
struct samsung_clk_reg_dump *rd,
|
|
struct samsung_clk_reg_dump *rd,
|
|
|
unsigned int num_regs)
|
|
unsigned int num_regs)
|
|
@@ -55,40 +48,53 @@ struct samsung_clk_reg_dump *samsung_clk_alloc_reg_dump(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* setup the essentials required to support clock lookup using ccf */
|
|
/* setup the essentials required to support clock lookup using ccf */
|
|
|
-void __init samsung_clk_init(struct device_node *np, void __iomem *base,
|
|
|
|
|
- unsigned long nr_clks)
|
|
|
|
|
|
|
+struct samsung_clk_provider *__init samsung_clk_init(struct device_node *np,
|
|
|
|
|
+ void __iomem *base, unsigned long nr_clks)
|
|
|
{
|
|
{
|
|
|
- reg_base = base;
|
|
|
|
|
|
|
+ struct samsung_clk_provider *ctx;
|
|
|
|
|
+ struct clk **clk_table;
|
|
|
|
|
+ int ret;
|
|
|
|
|
+ ctx = kzalloc(sizeof(struct samsung_clk_provider), GFP_KERNEL);
|
|
|
|
|
+ if (!ctx)
|
|
|
|
|
+ panic("could not allocate clock provider context.\n");
|
|
|
|
|
|
|
|
clk_table = kzalloc(sizeof(struct clk *) * nr_clks, GFP_KERNEL);
|
|
clk_table = kzalloc(sizeof(struct clk *) * nr_clks, GFP_KERNEL);
|
|
|
if (!clk_table)
|
|
if (!clk_table)
|
|
|
panic("could not allocate clock lookup table\n");
|
|
panic("could not allocate clock lookup table\n");
|
|
|
|
|
|
|
|
|
|
+ ctx->reg_base = base;
|
|
|
|
|
+ ctx->clk_data.clks = clk_table;
|
|
|
|
|
+ ctx->clk_data.clk_num = nr_clks;
|
|
|
|
|
+ spin_lock_init(&ctx->lock);
|
|
|
|
|
+
|
|
|
if (!np)
|
|
if (!np)
|
|
|
- return;
|
|
|
|
|
|
|
+ return ctx;
|
|
|
|
|
|
|
|
-#ifdef CONFIG_OF
|
|
|
|
|
- clk_data.clks = clk_table;
|
|
|
|
|
- clk_data.clk_num = nr_clks;
|
|
|
|
|
- of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ ret = of_clk_add_provider(np, of_clk_src_onecell_get,
|
|
|
|
|
+ &ctx->clk_data);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ panic("could not register clock provide\n");
|
|
|
|
|
+
|
|
|
|
|
+ return ctx;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* add a clock instance to the clock lookup table used for dt based lookup */
|
|
/* add a clock instance to the clock lookup table used for dt based lookup */
|
|
|
-void samsung_clk_add_lookup(struct clk *clk, unsigned int id)
|
|
|
|
|
|
|
+void samsung_clk_add_lookup(struct samsung_clk_provider *ctx, struct clk *clk,
|
|
|
|
|
+ unsigned int id)
|
|
|
{
|
|
{
|
|
|
- if (clk_table && id)
|
|
|
|
|
- clk_table[id] = clk;
|
|
|
|
|
|
|
+ if (ctx->clk_data.clks && id)
|
|
|
|
|
+ ctx->clk_data.clks[id] = clk;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of aliases */
|
|
/* register a list of aliases */
|
|
|
-void __init samsung_clk_register_alias(struct samsung_clock_alias *list,
|
|
|
|
|
- unsigned int nr_clk)
|
|
|
|
|
|
|
+void __init samsung_clk_register_alias(struct samsung_clk_provider *ctx,
|
|
|
|
|
+ struct samsung_clock_alias *list,
|
|
|
|
|
+ unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
|
unsigned int idx, ret;
|
|
unsigned int idx, ret;
|
|
|
|
|
|
|
|
- if (!clk_table) {
|
|
|
|
|
|
|
+ if (!ctx->clk_data.clks) {
|
|
|
pr_err("%s: clock table missing\n", __func__);
|
|
pr_err("%s: clock table missing\n", __func__);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -100,7 +106,7 @@ void __init samsung_clk_register_alias(struct samsung_clock_alias *list,
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- clk = clk_table[list->id];
|
|
|
|
|
|
|
+ clk = ctx->clk_data.clks[list->id];
|
|
|
if (!clk) {
|
|
if (!clk) {
|
|
|
pr_err("%s: failed to find clock %d\n", __func__,
|
|
pr_err("%s: failed to find clock %d\n", __func__,
|
|
|
list->id);
|
|
list->id);
|
|
@@ -115,7 +121,7 @@ void __init samsung_clk_register_alias(struct samsung_clock_alias *list,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of fixed clocks */
|
|
/* register a list of fixed clocks */
|
|
|
-void __init samsung_clk_register_fixed_rate(
|
|
|
|
|
|
|
+void __init samsung_clk_register_fixed_rate(struct samsung_clk_provider *ctx,
|
|
|
struct samsung_fixed_rate_clock *list, unsigned int nr_clk)
|
|
struct samsung_fixed_rate_clock *list, unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
@@ -130,7 +136,7 @@ void __init samsung_clk_register_fixed_rate(
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- samsung_clk_add_lookup(clk, list->id);
|
|
|
|
|
|
|
+ samsung_clk_add_lookup(ctx, clk, list->id);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* Unconditionally add a clock lookup for the fixed rate clocks.
|
|
* Unconditionally add a clock lookup for the fixed rate clocks.
|
|
@@ -144,7 +150,7 @@ void __init samsung_clk_register_fixed_rate(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of fixed factor clocks */
|
|
/* register a list of fixed factor clocks */
|
|
|
-void __init samsung_clk_register_fixed_factor(
|
|
|
|
|
|
|
+void __init samsung_clk_register_fixed_factor(struct samsung_clk_provider *ctx,
|
|
|
struct samsung_fixed_factor_clock *list, unsigned int nr_clk)
|
|
struct samsung_fixed_factor_clock *list, unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
@@ -159,28 +165,30 @@ void __init samsung_clk_register_fixed_factor(
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- samsung_clk_add_lookup(clk, list->id);
|
|
|
|
|
|
|
+ samsung_clk_add_lookup(ctx, clk, list->id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of mux clocks */
|
|
/* register a list of mux clocks */
|
|
|
-void __init samsung_clk_register_mux(struct samsung_mux_clock *list,
|
|
|
|
|
- unsigned int nr_clk)
|
|
|
|
|
|
|
+void __init samsung_clk_register_mux(struct samsung_clk_provider *ctx,
|
|
|
|
|
+ struct samsung_mux_clock *list,
|
|
|
|
|
+ unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
|
unsigned int idx, ret;
|
|
unsigned int idx, ret;
|
|
|
|
|
|
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
|
clk = clk_register_mux(NULL, list->name, list->parent_names,
|
|
clk = clk_register_mux(NULL, list->name, list->parent_names,
|
|
|
- list->num_parents, list->flags, reg_base + list->offset,
|
|
|
|
|
- list->shift, list->width, list->mux_flags, &lock);
|
|
|
|
|
|
|
+ list->num_parents, list->flags,
|
|
|
|
|
+ ctx->reg_base + list->offset,
|
|
|
|
|
+ list->shift, list->width, list->mux_flags, &ctx->lock);
|
|
|
if (IS_ERR(clk)) {
|
|
if (IS_ERR(clk)) {
|
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
|
list->name);
|
|
list->name);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- samsung_clk_add_lookup(clk, list->id);
|
|
|
|
|
|
|
+ samsung_clk_add_lookup(ctx, clk, list->id);
|
|
|
|
|
|
|
|
/* register a clock lookup only if a clock alias is specified */
|
|
/* register a clock lookup only if a clock alias is specified */
|
|
|
if (list->alias) {
|
|
if (list->alias) {
|
|
@@ -194,8 +202,9 @@ void __init samsung_clk_register_mux(struct samsung_mux_clock *list,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of div clocks */
|
|
/* register a list of div clocks */
|
|
|
-void __init samsung_clk_register_div(struct samsung_div_clock *list,
|
|
|
|
|
- unsigned int nr_clk)
|
|
|
|
|
|
|
+void __init samsung_clk_register_div(struct samsung_clk_provider *ctx,
|
|
|
|
|
+ struct samsung_div_clock *list,
|
|
|
|
|
+ unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
|
unsigned int idx, ret;
|
|
unsigned int idx, ret;
|
|
@@ -203,22 +212,22 @@ void __init samsung_clk_register_div(struct samsung_div_clock *list,
|
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
|
if (list->table)
|
|
if (list->table)
|
|
|
clk = clk_register_divider_table(NULL, list->name,
|
|
clk = clk_register_divider_table(NULL, list->name,
|
|
|
- list->parent_name, list->flags,
|
|
|
|
|
- reg_base + list->offset, list->shift,
|
|
|
|
|
- list->width, list->div_flags,
|
|
|
|
|
- list->table, &lock);
|
|
|
|
|
|
|
+ list->parent_name, list->flags,
|
|
|
|
|
+ ctx->reg_base + list->offset,
|
|
|
|
|
+ list->shift, list->width, list->div_flags,
|
|
|
|
|
+ list->table, &ctx->lock);
|
|
|
else
|
|
else
|
|
|
clk = clk_register_divider(NULL, list->name,
|
|
clk = clk_register_divider(NULL, list->name,
|
|
|
- list->parent_name, list->flags,
|
|
|
|
|
- reg_base + list->offset, list->shift,
|
|
|
|
|
- list->width, list->div_flags, &lock);
|
|
|
|
|
|
|
+ list->parent_name, list->flags,
|
|
|
|
|
+ ctx->reg_base + list->offset, list->shift,
|
|
|
|
|
+ list->width, list->div_flags, &ctx->lock);
|
|
|
if (IS_ERR(clk)) {
|
|
if (IS_ERR(clk)) {
|
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
|
list->name);
|
|
list->name);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- samsung_clk_add_lookup(clk, list->id);
|
|
|
|
|
|
|
+ samsung_clk_add_lookup(ctx, clk, list->id);
|
|
|
|
|
|
|
|
/* register a clock lookup only if a clock alias is specified */
|
|
/* register a clock lookup only if a clock alias is specified */
|
|
|
if (list->alias) {
|
|
if (list->alias) {
|
|
@@ -232,16 +241,17 @@ void __init samsung_clk_register_div(struct samsung_div_clock *list,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* register a list of gate clocks */
|
|
/* register a list of gate clocks */
|
|
|
-void __init samsung_clk_register_gate(struct samsung_gate_clock *list,
|
|
|
|
|
- unsigned int nr_clk)
|
|
|
|
|
|
|
+void __init samsung_clk_register_gate(struct samsung_clk_provider *ctx,
|
|
|
|
|
+ struct samsung_gate_clock *list,
|
|
|
|
|
+ unsigned int nr_clk)
|
|
|
{
|
|
{
|
|
|
struct clk *clk;
|
|
struct clk *clk;
|
|
|
unsigned int idx, ret;
|
|
unsigned int idx, ret;
|
|
|
|
|
|
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
for (idx = 0; idx < nr_clk; idx++, list++) {
|
|
|
clk = clk_register_gate(NULL, list->name, list->parent_name,
|
|
clk = clk_register_gate(NULL, list->name, list->parent_name,
|
|
|
- list->flags, reg_base + list->offset,
|
|
|
|
|
- list->bit_idx, list->gate_flags, &lock);
|
|
|
|
|
|
|
+ list->flags, ctx->reg_base + list->offset,
|
|
|
|
|
+ list->bit_idx, list->gate_flags, &ctx->lock);
|
|
|
if (IS_ERR(clk)) {
|
|
if (IS_ERR(clk)) {
|
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
pr_err("%s: failed to register clock %s\n", __func__,
|
|
|
list->name);
|
|
list->name);
|
|
@@ -257,7 +267,7 @@ void __init samsung_clk_register_gate(struct samsung_gate_clock *list,
|
|
|
__func__, list->alias);
|
|
__func__, list->alias);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- samsung_clk_add_lookup(clk, list->id);
|
|
|
|
|
|
|
+ samsung_clk_add_lookup(ctx, clk, list->id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -266,21 +276,21 @@ void __init samsung_clk_register_gate(struct samsung_gate_clock *list,
|
|
|
* tree and register it
|
|
* tree and register it
|
|
|
*/
|
|
*/
|
|
|
#ifdef CONFIG_OF
|
|
#ifdef CONFIG_OF
|
|
|
-void __init samsung_clk_of_register_fixed_ext(
|
|
|
|
|
|
|
+void __init samsung_clk_of_register_fixed_ext(struct samsung_clk_provider *ctx,
|
|
|
struct samsung_fixed_rate_clock *fixed_rate_clk,
|
|
struct samsung_fixed_rate_clock *fixed_rate_clk,
|
|
|
unsigned int nr_fixed_rate_clk,
|
|
unsigned int nr_fixed_rate_clk,
|
|
|
struct of_device_id *clk_matches)
|
|
struct of_device_id *clk_matches)
|
|
|
{
|
|
{
|
|
|
const struct of_device_id *match;
|
|
const struct of_device_id *match;
|
|
|
- struct device_node *np;
|
|
|
|
|
|
|
+ struct device_node *clk_np;
|
|
|
u32 freq;
|
|
u32 freq;
|
|
|
|
|
|
|
|
- for_each_matching_node_and_match(np, clk_matches, &match) {
|
|
|
|
|
- if (of_property_read_u32(np, "clock-frequency", &freq))
|
|
|
|
|
|
|
+ for_each_matching_node_and_match(clk_np, clk_matches, &match) {
|
|
|
|
|
+ if (of_property_read_u32(clk_np, "clock-frequency", &freq))
|
|
|
continue;
|
|
continue;
|
|
|
fixed_rate_clk[(u32)match->data].fixed_rate = freq;
|
|
fixed_rate_clk[(u32)match->data].fixed_rate = freq;
|
|
|
}
|
|
}
|
|
|
- samsung_clk_register_fixed_rate(fixed_rate_clk, nr_fixed_rate_clk);
|
|
|
|
|
|
|
+ samsung_clk_register_fixed_rate(ctx, fixed_rate_clk, nr_fixed_rate_clk);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|