2011-04-19 10:33:45 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
|
|
|
|
* Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Gated clock implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/string.h>
|
2013-03-25 16:20:35 +04:00
|
|
|
#include "clk.h"
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: basic gatable clock which can gate and ungate it's ouput
|
|
|
|
*
|
|
|
|
* Traits of this clock:
|
|
|
|
* prepare - clk_(un)prepare only ensures parent is (un)prepared
|
|
|
|
* enable - clk_enable and clk_disable are functional & control gating
|
|
|
|
* rate - inherits rate from parent. No clk_set_rate support
|
|
|
|
* parent - fixed parent. No clk_set_parent support
|
|
|
|
*/
|
|
|
|
|
2014-04-18 11:55:16 +04:00
|
|
|
struct clk_gate2 {
|
|
|
|
struct clk_hw hw;
|
|
|
|
void __iomem *reg;
|
|
|
|
u8 bit_idx;
|
|
|
|
u8 flags;
|
|
|
|
spinlock_t *lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_gate2(_hw) container_of(_hw, struct clk_gate2, hw)
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
static int clk_gate2_enable(struct clk_hw *hw)
|
|
|
|
{
|
2014-04-18 11:55:16 +04:00
|
|
|
struct clk_gate2 *gate = to_clk_gate2(hw);
|
2011-04-19 10:33:45 +04:00
|
|
|
u32 reg;
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
2014-04-18 12:07:44 +04:00
|
|
|
spin_lock_irqsave(gate->lock, flags);
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
reg = readl(gate->reg);
|
|
|
|
reg |= 3 << gate->bit_idx;
|
|
|
|
writel(reg, gate->reg);
|
|
|
|
|
2014-04-18 12:07:44 +04:00
|
|
|
spin_unlock_irqrestore(gate->lock, flags);
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void clk_gate2_disable(struct clk_hw *hw)
|
|
|
|
{
|
2014-04-18 11:55:16 +04:00
|
|
|
struct clk_gate2 *gate = to_clk_gate2(hw);
|
2011-04-19 10:33:45 +04:00
|
|
|
u32 reg;
|
|
|
|
unsigned long flags = 0;
|
|
|
|
|
2014-04-18 12:07:44 +04:00
|
|
|
spin_lock_irqsave(gate->lock, flags);
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
reg = readl(gate->reg);
|
|
|
|
reg &= ~(3 << gate->bit_idx);
|
|
|
|
writel(reg, gate->reg);
|
|
|
|
|
2014-04-18 12:07:44 +04:00
|
|
|
spin_unlock_irqrestore(gate->lock, flags);
|
2011-04-19 10:33:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_gate2_is_enabled(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
u32 reg;
|
2014-04-18 11:55:16 +04:00
|
|
|
struct clk_gate2 *gate = to_clk_gate2(hw);
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
reg = readl(gate->reg);
|
|
|
|
|
2013-12-24 23:21:27 +04:00
|
|
|
if (((reg >> gate->bit_idx) & 1) == 1)
|
2011-04-19 10:33:45 +04:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct clk_ops clk_gate2_ops = {
|
|
|
|
.enable = clk_gate2_enable,
|
|
|
|
.disable = clk_gate2_disable,
|
|
|
|
.is_enabled = clk_gate2_is_enabled,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct clk *clk_register_gate2(struct device *dev, const char *name,
|
|
|
|
const char *parent_name, unsigned long flags,
|
|
|
|
void __iomem *reg, u8 bit_idx,
|
|
|
|
u8 clk_gate2_flags, spinlock_t *lock)
|
|
|
|
{
|
2014-04-18 11:55:16 +04:00
|
|
|
struct clk_gate2 *gate;
|
2011-04-19 10:33:45 +04:00
|
|
|
struct clk *clk;
|
|
|
|
struct clk_init_data init;
|
|
|
|
|
2014-04-18 11:55:16 +04:00
|
|
|
gate = kzalloc(sizeof(struct clk_gate2), GFP_KERNEL);
|
2011-04-19 10:33:45 +04:00
|
|
|
if (!gate)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2014-04-18 11:55:16 +04:00
|
|
|
/* struct clk_gate2 assignments */
|
2011-04-19 10:33:45 +04:00
|
|
|
gate->reg = reg;
|
|
|
|
gate->bit_idx = bit_idx;
|
|
|
|
gate->flags = clk_gate2_flags;
|
|
|
|
gate->lock = lock;
|
|
|
|
|
|
|
|
init.name = name;
|
|
|
|
init.ops = &clk_gate2_ops;
|
|
|
|
init.flags = flags;
|
|
|
|
init.parent_names = parent_name ? &parent_name : NULL;
|
|
|
|
init.num_parents = parent_name ? 1 : 0;
|
|
|
|
|
|
|
|
gate->hw.init = &init;
|
|
|
|
|
|
|
|
clk = clk_register(dev, &gate->hw);
|
|
|
|
if (IS_ERR(clk))
|
2012-10-25 19:02:18 +04:00
|
|
|
kfree(gate);
|
2011-04-19 10:33:45 +04:00
|
|
|
|
|
|
|
return clk;
|
|
|
|
}
|