2019-05-27 13:55:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-27 22:24:14 +07:00
|
|
|
/*
|
|
|
|
* clkgen-mux.c: ST GEN-MUX Clock driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 STMicroelectronics (R&D) Limited
|
|
|
|
*
|
|
|
|
* Authors: Stephen Gallimore <stephen.gallimore@st.com>
|
|
|
|
* Pankaj Dev <pankaj.dev@st.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
2019-04-19 05:20:22 +07:00
|
|
|
#include <linux/io.h>
|
2014-02-27 22:24:14 +07:00
|
|
|
#include <linux/of_address.h>
|
2015-06-20 05:00:46 +07:00
|
|
|
#include <linux/clk.h>
|
2014-02-27 22:24:14 +07:00
|
|
|
#include <linux/clk-provider.h>
|
2015-10-07 16:08:57 +07:00
|
|
|
#include "clkgen.h"
|
2014-02-27 22:24:14 +07:00
|
|
|
|
|
|
|
static const char ** __init clkgen_mux_get_parents(struct device_node *np,
|
|
|
|
int *num_parents)
|
|
|
|
{
|
|
|
|
const char **parents;
|
2016-02-20 08:43:30 +07:00
|
|
|
unsigned int nparents;
|
2014-02-27 22:24:14 +07:00
|
|
|
|
2015-05-29 16:25:46 +07:00
|
|
|
nparents = of_clk_get_parent_count(np);
|
2016-02-20 08:43:30 +07:00
|
|
|
if (WARN_ON(!nparents))
|
2014-02-27 22:24:14 +07:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2015-07-08 08:30:05 +07:00
|
|
|
parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL);
|
2014-02-27 22:24:14 +07:00
|
|
|
if (!parents)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2015-07-07 10:59:04 +07:00
|
|
|
*num_parents = of_clk_parent_fill(np, parents, nparents);
|
2014-02-27 22:24:14 +07:00
|
|
|
return parents;
|
|
|
|
}
|
|
|
|
|
2014-02-27 22:24:16 +07:00
|
|
|
struct clkgen_mux_data {
|
|
|
|
u32 offset;
|
|
|
|
u8 shift;
|
|
|
|
u8 width;
|
|
|
|
spinlock_t *lock;
|
|
|
|
unsigned long clk_flags;
|
|
|
|
u8 mux_flags;
|
|
|
|
};
|
|
|
|
|
2014-07-15 22:20:23 +07:00
|
|
|
static struct clkgen_mux_data stih407_a9_mux_data = {
|
|
|
|
.offset = 0x1a4,
|
2015-06-23 21:09:25 +07:00
|
|
|
.shift = 0,
|
2014-07-15 22:20:23 +07:00
|
|
|
.width = 2,
|
2015-10-07 16:08:57 +07:00
|
|
|
.lock = &clkgen_a9_lock,
|
2014-07-15 22:20:23 +07:00
|
|
|
};
|
2014-02-27 22:24:19 +07:00
|
|
|
|
2016-08-29 19:26:54 +07:00
|
|
|
static void __init st_of_clkgen_mux_setup(struct device_node *np,
|
|
|
|
struct clkgen_mux_data *data)
|
2014-02-27 22:24:16 +07:00
|
|
|
{
|
|
|
|
struct clk *clk;
|
|
|
|
void __iomem *reg;
|
|
|
|
const char **parents;
|
2016-08-29 19:26:53 +07:00
|
|
|
int num_parents = 0;
|
2014-02-27 22:24:16 +07:00
|
|
|
|
|
|
|
reg = of_iomap(np, 0);
|
|
|
|
if (!reg) {
|
|
|
|
pr_err("%s: Failed to get base address\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parents = clkgen_mux_get_parents(np, &num_parents);
|
|
|
|
if (IS_ERR(parents)) {
|
|
|
|
pr_err("%s: Failed to get parents (%ld)\n",
|
|
|
|
__func__, PTR_ERR(parents));
|
2015-07-08 08:30:05 +07:00
|
|
|
goto err_parents;
|
2014-02-27 22:24:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
clk = clk_register_mux(NULL, np->name, parents, num_parents,
|
|
|
|
data->clk_flags | CLK_SET_RATE_PARENT,
|
|
|
|
reg + data->offset,
|
|
|
|
data->shift, data->width, data->mux_flags,
|
|
|
|
data->lock);
|
|
|
|
if (IS_ERR(clk))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
pr_debug("%s: parent %s rate %u\n",
|
|
|
|
__clk_get_name(clk),
|
|
|
|
__clk_get_name(clk_get_parent(clk)),
|
|
|
|
(unsigned int)clk_get_rate(clk));
|
|
|
|
|
2015-07-08 08:30:05 +07:00
|
|
|
kfree(parents);
|
2014-02-27 22:24:16 +07:00
|
|
|
of_clk_add_provider(np, of_clk_src_simple_get, clk);
|
2015-07-08 08:30:05 +07:00
|
|
|
return;
|
2014-02-27 22:24:16 +07:00
|
|
|
|
|
|
|
err:
|
|
|
|
kfree(parents);
|
2015-07-08 08:30:05 +07:00
|
|
|
err_parents:
|
|
|
|
iounmap(reg);
|
2014-02-27 22:24:16 +07:00
|
|
|
}
|
2016-08-29 19:26:54 +07:00
|
|
|
|
|
|
|
static void __init st_of_clkgen_a9_mux_setup(struct device_node *np)
|
|
|
|
{
|
|
|
|
st_of_clkgen_mux_setup(np, &stih407_a9_mux_data);
|
|
|
|
}
|
|
|
|
CLK_OF_DECLARE(clkgen_a9mux, "st,stih407-clkgen-a9-mux",
|
|
|
|
st_of_clkgen_a9_mux_setup);
|