Skip to content

Commit

Permalink
Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/clk/linux

Pull clk fixes from Stephen Boyd:
 "One small build fix, a couple do_div() fixes, and a fix for the gpio
  basic clock type are the major changes here.  There's also a couple
  fixes for the TI, sunxi, and scpi clock drivers"

* tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux:
  clk: sunxi: pll2: Fix clock running too fast
  clk: scpi: add missing of_node_put
  clk: qoriq: fix memory leak
  imx/clk-pllv2: fix wrong do_div() usage
  imx/clk-pllv1: fix wrong do_div() usage
  clk: mmp: add linux/clk.h includes
  clk: ti: drop locking code from mux/divider drivers
  clk: ti816x: Add missing dmtimer clkdev entries
  clk: ti: fapll: fix wrong do_div() usage
  clk: ti: clkt_dpll: fix wrong do_div() usage
  clk: gpio: Get parent clk names in of_gpio_clk_setup()
  • Loading branch information
Linus Torvalds committed Dec 10, 2015
2 parents 9a0f76f + 59f0ec2 commit abb7e2b
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 75 deletions.
33 changes: 17 additions & 16 deletions drivers/clk/clk-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ EXPORT_SYMBOL_GPL(clk_register_gpio_mux);

struct clk_gpio_delayed_register_data {
const char *gpio_name;
int num_parents;
const char **parent_names;
struct device_node *node;
struct mutex lock;
struct clk *clk;
Expand All @@ -222,8 +224,6 @@ static struct clk *of_clk_gpio_delayed_register_get(
{
struct clk_gpio_delayed_register_data *data = _data;
struct clk *clk;
const char **parent_names;
int i, num_parents;
int gpio;
enum of_gpio_flags of_flags;

Expand All @@ -248,26 +248,14 @@ static struct clk *of_clk_gpio_delayed_register_get(
return ERR_PTR(gpio);
}

num_parents = of_clk_get_parent_count(data->node);

parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
if (!parent_names) {
clk = ERR_PTR(-ENOMEM);
goto out;
}

for (i = 0; i < num_parents; i++)
parent_names[i] = of_clk_get_parent_name(data->node, i);

clk = data->clk_register_get(data->node->name, parent_names,
num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
clk = data->clk_register_get(data->node->name, data->parent_names,
data->num_parents, gpio, of_flags & OF_GPIO_ACTIVE_LOW);
if (IS_ERR(clk))
goto out;

data->clk = clk;
out:
mutex_unlock(&data->lock);
kfree(parent_names);

return clk;
}
Expand Down Expand Up @@ -296,11 +284,24 @@ static void __init of_gpio_clk_setup(struct device_node *node,
unsigned gpio, bool active_low))
{
struct clk_gpio_delayed_register_data *data;
const char **parent_names;
int i, num_parents;

data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return;

num_parents = of_clk_get_parent_count(node);

parent_names = kcalloc(num_parents, sizeof(char *), GFP_KERNEL);
if (!parent_names)
return;

for (i = 0; i < num_parents; i++)
parent_names[i] = of_clk_get_parent_name(node, i);

data->num_parents = num_parents;
data->parent_names = parent_names;
data->node = node;
data->gpio_name = gpio_name;
data->clk_register_get = clk_register_get;
Expand Down
4 changes: 3 additions & 1 deletion drivers/clk/clk-qoriq.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,10 @@ static struct clk * __init create_one_cmux(struct clockgen *cg, int idx)
*/
clksel = (cg_in(cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT;
div = get_pll_div(cg, hwc, clksel);
if (!div)
if (!div) {
kfree(hwc);
return NULL;
}

pct80_rate = clk_get_rate(div->clk);
pct80_rate *= 8;
Expand Down
1 change: 1 addition & 0 deletions drivers/clk/clk-scpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static int scpi_clocks_probe(struct platform_device *pdev)
ret = scpi_clk_add(dev, child, match);
if (ret) {
scpi_clocks_remove(pdev);
of_node_put(child);
return ret;
}
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/clk/imx/clk-pllv1.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_pllv1 *pll = to_clk_pllv1(hw);
long long ll;
unsigned long long ull;
int mfn_abs;
unsigned int mfi, mfn, mfd, pd;
u32 reg;
Expand Down Expand Up @@ -94,16 +94,16 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
rate = parent_rate * 2;
rate /= pd + 1;

ll = (unsigned long long)rate * mfn_abs;
ull = (unsigned long long)rate * mfn_abs;

do_div(ll, mfd + 1);
do_div(ull, mfd + 1);

if (mfn_is_negative(pll, mfn))
ll = -ll;
ull = (rate * mfi) - ull;
else
ull = (rate * mfi) + ull;

ll = (rate * mfi) + ll;

return ll;
return ull;
}

static struct clk_ops clk_pllv1_ops = {
Expand Down
9 changes: 5 additions & 4 deletions drivers/clk/imx/clk-pllv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static unsigned long __clk_pllv2_recalc_rate(unsigned long parent_rate,
{
long mfi, mfn, mfd, pdf, ref_clk;
unsigned long dbl;
s64 temp;
u64 temp;

dbl = dp_ctl & MXC_PLL_DP_CTL_DPDCK0_2_EN;

Expand All @@ -98,8 +98,9 @@ static unsigned long __clk_pllv2_recalc_rate(unsigned long parent_rate,
temp = (u64) ref_clk * abs(mfn);
do_div(temp, mfd + 1);
if (mfn < 0)
temp = -temp;
temp = (ref_clk * mfi) + temp;
temp = (ref_clk * mfi) - temp;
else
temp = (ref_clk * mfi) + temp;

return temp;
}
Expand All @@ -126,7 +127,7 @@ static int __clk_pllv2_set_rate(unsigned long rate, unsigned long parent_rate,
{
u32 reg;
long mfi, pdf, mfn, mfd = 999999;
s64 temp64;
u64 temp64;
unsigned long quad_parent_rate;

quad_parent_rate = 4 * parent_rate;
Expand Down
1 change: 1 addition & 0 deletions drivers/clk/mmp/clk-mmp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* warranty of any kind, whether express or implied.
*/

#include <linux/clk.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/spinlock.h>
Expand Down
1 change: 1 addition & 0 deletions drivers/clk/mmp/clk-pxa168.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* warranty of any kind, whether express or implied.
*/

#include <linux/clk.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/spinlock.h>
Expand Down
1 change: 1 addition & 0 deletions drivers/clk/mmp/clk-pxa910.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* warranty of any kind, whether express or implied.
*/

#include <linux/clk.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/spinlock.h>
Expand Down
23 changes: 5 additions & 18 deletions drivers/clk/sunxi/clk-a10-pll2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@

#define SUN4I_PLL2_OUTPUTS 4

struct sun4i_pll2_data {
u32 post_div_offset;
u32 pre_div_flags;
};

static DEFINE_SPINLOCK(sun4i_a10_pll2_lock);

static void __init sun4i_pll2_setup(struct device_node *node,
struct sun4i_pll2_data *data)
int post_div_offset)
{
const char *clk_name = node->name, *parent;
struct clk **clks, *base_clk, *prediv_clk;
Expand All @@ -76,7 +71,7 @@ static void __init sun4i_pll2_setup(struct device_node *node,
parent, 0, reg,
SUN4I_PLL2_PRE_DIV_SHIFT,
SUN4I_PLL2_PRE_DIV_WIDTH,
data->pre_div_flags,
CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO,
&sun4i_a10_pll2_lock);
if (!prediv_clk) {
pr_err("Couldn't register the prediv clock\n");
Expand Down Expand Up @@ -127,7 +122,7 @@ static void __init sun4i_pll2_setup(struct device_node *node,
*/
val = readl(reg);
val &= ~(SUN4I_PLL2_POST_DIV_MASK << SUN4I_PLL2_POST_DIV_SHIFT);
val |= (SUN4I_PLL2_POST_DIV_VALUE - data->post_div_offset) << SUN4I_PLL2_POST_DIV_SHIFT;
val |= (SUN4I_PLL2_POST_DIV_VALUE - post_div_offset) << SUN4I_PLL2_POST_DIV_SHIFT;
writel(val, reg);

of_property_read_string_index(node, "clock-output-names",
Expand Down Expand Up @@ -191,25 +186,17 @@ static void __init sun4i_pll2_setup(struct device_node *node,
iounmap(reg);
}

static struct sun4i_pll2_data sun4i_a10_pll2_data = {
.pre_div_flags = CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ALLOW_ZERO,
};

static void __init sun4i_a10_pll2_setup(struct device_node *node)
{
sun4i_pll2_setup(node, &sun4i_a10_pll2_data);
sun4i_pll2_setup(node, 0);
}

CLK_OF_DECLARE(sun4i_a10_pll2, "allwinner,sun4i-a10-pll2-clk",
sun4i_a10_pll2_setup);

static struct sun4i_pll2_data sun5i_a13_pll2_data = {
.post_div_offset = 1,
};

static void __init sun5i_a13_pll2_setup(struct device_node *node)
{
sun4i_pll2_setup(node, &sun5i_a13_pll2_data);
sun4i_pll2_setup(node, 1);
}

CLK_OF_DECLARE(sun5i_a13_pll2, "allwinner,sun5i-a13-pll2-clk",
Expand Down
2 changes: 2 additions & 0 deletions drivers/clk/ti/clk-816x.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ static struct ti_dt_clk dm816x_clks[] = {
DT_CLK(NULL, "sys_clkin", "sys_clkin_ck"),
DT_CLK(NULL, "timer_sys_ck", "sys_clkin_ck"),
DT_CLK(NULL, "sys_32k_ck", "sys_32k_ck"),
DT_CLK(NULL, "timer_32k_ck", "sysclk18_ck"),
DT_CLK(NULL, "timer_ext_ck", "tclkin_ck"),
DT_CLK(NULL, "mpu_ck", "mpu_ck"),
DT_CLK(NULL, "timer1_fck", "timer1_fck"),
DT_CLK(NULL, "timer2_fck", "timer2_fck"),
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/ti/clkt_dpll.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ u8 omap2_init_dpll_parent(struct clk_hw *hw)
*/
unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk)
{
long long dpll_clk;
u64 dpll_clk;
u32 dpll_mult, dpll_div, v;
struct dpll_data *dd;

Expand All @@ -262,7 +262,7 @@ unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk)
dpll_div = v & dd->div1_mask;
dpll_div >>= __ffs(dd->div1_mask);

dpll_clk = (long long)clk_get_rate(dd->clk_ref) * dpll_mult;
dpll_clk = (u64)clk_get_rate(dd->clk_ref) * dpll_mult;
do_div(dpll_clk, dpll_div + 1);

return dpll_clk;
Expand Down
16 changes: 3 additions & 13 deletions drivers/clk/ti/divider.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ static int ti_clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
{
struct clk_divider *divider;
unsigned int div, value;
unsigned long flags = 0;
u32 val;

if (!hw || !rate)
Expand All @@ -228,9 +227,6 @@ static int ti_clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
if (value > div_mask(divider))
value = div_mask(divider);

if (divider->lock)
spin_lock_irqsave(divider->lock, flags);

if (divider->flags & CLK_DIVIDER_HIWORD_MASK) {
val = div_mask(divider) << (divider->shift + 16);
} else {
Expand All @@ -240,9 +236,6 @@ static int ti_clk_divider_set_rate(struct clk_hw *hw, unsigned long rate,
val |= value << divider->shift;
ti_clk_ll_ops->clk_writel(val, divider->reg);

if (divider->lock)
spin_unlock_irqrestore(divider->lock, flags);

return 0;
}

Expand All @@ -256,8 +249,7 @@ static struct clk *_register_divider(struct device *dev, const char *name,
const char *parent_name,
unsigned long flags, void __iomem *reg,
u8 shift, u8 width, u8 clk_divider_flags,
const struct clk_div_table *table,
spinlock_t *lock)
const struct clk_div_table *table)
{
struct clk_divider *div;
struct clk *clk;
Expand Down Expand Up @@ -288,7 +280,6 @@ static struct clk *_register_divider(struct device *dev, const char *name,
div->shift = shift;
div->width = width;
div->flags = clk_divider_flags;
div->lock = lock;
div->hw.init = &init;
div->table = table;

Expand Down Expand Up @@ -421,7 +412,7 @@ struct clk *ti_clk_register_divider(struct ti_clk *setup)

clk = _register_divider(NULL, setup->name, div->parent,
flags, (void __iomem *)reg, div->bit_shift,
width, div_flags, table, NULL);
width, div_flags, table);

if (IS_ERR(clk))
kfree(table);
Expand Down Expand Up @@ -584,8 +575,7 @@ static void __init of_ti_divider_clk_setup(struct device_node *node)
goto cleanup;

clk = _register_divider(NULL, node->name, parent_name, flags, reg,
shift, width, clk_divider_flags, table,
NULL);
shift, width, clk_divider_flags, table);

if (!IS_ERR(clk)) {
of_clk_add_provider(node, of_clk_src_simple_get, clk);
Expand Down
4 changes: 2 additions & 2 deletions drivers/clk/ti/fapll.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static unsigned long ti_fapll_recalc_rate(struct clk_hw *hw,
{
struct fapll_data *fd = to_fapll(hw);
u32 fapll_n, fapll_p, v;
long long rate;
u64 rate;

if (ti_fapll_clock_is_bypass(fd))
return parent_rate;
Expand Down Expand Up @@ -314,7 +314,7 @@ static unsigned long ti_fapll_synth_recalc_rate(struct clk_hw *hw,
{
struct fapll_synth *synth = to_synth(hw);
u32 synth_div_m;
long long rate;
u64 rate;

/* The audio_pll_clk1 is hardwired to produce 32.768KiHz clock */
if (!synth->div)
Expand Down
Loading

0 comments on commit abb7e2b

Please sign in to comment.