2014-02-27 15:24:14 +00: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>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/of_address.h>
|
2015-06-19 22:00:46 +00:00
|
|
|
#include <linux/clk.h>
|
2014-02-27 15:24:14 +00:00
|
|
|
#include <linux/clk-provider.h>
|
2015-10-07 09:08:57 +00:00
|
|
|
#include "clkgen.h"
|
2014-02-27 15:24:14 +00:00
|
|
|
|
|
|
|
static const char ** __init clkgen_mux_get_parents(struct device_node *np,
|
|
|
|
int *num_parents)
|
|
|
|
{
|
|
|
|
const char **parents;
|
2016-02-20 01:43:30 +00:00
|
|
|
unsigned int nparents;
|
2014-02-27 15:24:14 +00:00
|
|
|
|
2015-05-29 09:25:46 +00:00
|
|
|
nparents = of_clk_get_parent_count(np);
|
2016-02-20 01:43:30 +00:00
|
|
|
if (WARN_ON(!nparents))
|
2014-02-27 15:24:14 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
2015-07-08 01:30:05 +00:00
|
|
|
parents = kcalloc(nparents, sizeof(const char *), GFP_KERNEL);
|
2014-02-27 15:24:14 +00:00
|
|
|
if (!parents)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2015-07-07 03:59:04 +00:00
|
|
|
*num_parents = of_clk_parent_fill(np, parents, nparents);
|
2014-02-27 15:24:14 +00:00
|
|
|
return parents;
|
|
|
|
}
|
|
|
|
|
2014-02-27 15:24:16 +00:00
|
|
|
struct clkgen_mux_data {
|
|
|
|
u32 offset;
|
|
|
|
u8 shift;
|
|
|
|
u8 width;
|
|
|
|
spinlock_t *lock;
|
|
|
|
unsigned long clk_flags;
|
|
|
|
u8 mux_flags;
|
|
|
|
};
|
|
|
|
|
2014-07-15 15:20:23 +00:00
|
|
|
static struct clkgen_mux_data stih407_a9_mux_data = {
|
|
|
|
.offset = 0x1a4,
|
2015-06-23 14:09:25 +00:00
|
|
|
.shift = 0,
|
2014-07-15 15:20:23 +00:00
|
|
|
.width = 2,
|
2015-10-07 09:08:57 +00:00
|
|
|
.lock = &clkgen_a9_lock,
|
2014-07-15 15:20:23 +00:00
|
|
|
};
|
2014-02-27 15:24:19 +00:00
|
|
|
|
2015-03-31 18:50:42 +00:00
|
|
|
static const struct of_device_id mux_of_match[] = {
|
2014-07-15 15:20:23 +00:00
|
|
|
{
|
|
|
|
.compatible = "st,stih407-clkgen-a9-mux",
|
|
|
|
.data = &stih407_a9_mux_data,
|
|
|
|
},
|
2014-02-27 15:24:16 +00:00
|
|
|
{}
|
|
|
|
};
|
2015-05-01 19:45:53 +00:00
|
|
|
static void __init st_of_clkgen_mux_setup(struct device_node *np)
|
2014-02-27 15:24:16 +00:00
|
|
|
{
|
|
|
|
const struct of_device_id *match;
|
|
|
|
struct clk *clk;
|
|
|
|
void __iomem *reg;
|
|
|
|
const char **parents;
|
2016-08-29 12:26:53 +00:00
|
|
|
int num_parents = 0;
|
2015-07-08 01:30:05 +00:00
|
|
|
const struct clkgen_mux_data *data;
|
2014-02-27 15:24:16 +00:00
|
|
|
|
|
|
|
match = of_match_node(mux_of_match, np);
|
|
|
|
if (!match) {
|
|
|
|
pr_err("%s: No matching data\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-08 01:30:05 +00:00
|
|
|
data = match->data;
|
2014-02-27 15:24:16 +00: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 01:30:05 +00:00
|
|
|
goto err_parents;
|
2014-02-27 15:24:16 +00: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 01:30:05 +00:00
|
|
|
kfree(parents);
|
2014-02-27 15:24:16 +00:00
|
|
|
of_clk_add_provider(np, of_clk_src_simple_get, clk);
|
2015-07-08 01:30:05 +00:00
|
|
|
return;
|
2014-02-27 15:24:16 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
kfree(parents);
|
2015-07-08 01:30:05 +00:00
|
|
|
err_parents:
|
|
|
|
iounmap(reg);
|
2014-02-27 15:24:16 +00:00
|
|
|
}
|
|
|
|
CLK_OF_DECLARE(clkgen_mux, "st,clkgen-mux", st_of_clkgen_mux_setup);
|