2006-03-15 15:54:37 +00:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/mach-sa1100/clock.c
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/spinlock.h>
|
2007-08-20 09:18:02 +00:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/delay.h>
|
2006-03-15 15:54:37 +00:00
|
|
|
|
2008-11-08 20:25:21 +00:00
|
|
|
#include <asm/clkdev.h>
|
2008-08-05 15:14:15 +00:00
|
|
|
#include <mach/pxa2xx-regs.h>
|
|
|
|
#include <mach/hardware.h>
|
2006-03-15 15:54:37 +00:00
|
|
|
|
2007-08-20 09:18:02 +00:00
|
|
|
#include "devices.h"
|
|
|
|
#include "generic.h"
|
|
|
|
#include "clock.h"
|
2006-03-15 15:54:37 +00:00
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(clocks_lock);
|
|
|
|
|
|
|
|
int clk_enable(struct clk *clk)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&clocks_lock, flags);
|
|
|
|
if (clk->enabled++ == 0)
|
2007-08-20 09:18:02 +00:00
|
|
|
clk->ops->enable(clk);
|
2006-03-15 15:54:37 +00:00
|
|
|
spin_unlock_irqrestore(&clocks_lock, flags);
|
2007-08-20 09:18:02 +00:00
|
|
|
|
|
|
|
if (clk->delay)
|
|
|
|
udelay(clk->delay);
|
|
|
|
|
2006-03-15 15:54:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_enable);
|
|
|
|
|
|
|
|
void clk_disable(struct clk *clk)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
WARN_ON(clk->enabled == 0);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&clocks_lock, flags);
|
|
|
|
if (--clk->enabled == 0)
|
2007-08-20 09:18:02 +00:00
|
|
|
clk->ops->disable(clk);
|
2006-03-15 15:54:37 +00:00
|
|
|
spin_unlock_irqrestore(&clocks_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_disable);
|
|
|
|
|
|
|
|
unsigned long clk_get_rate(struct clk *clk)
|
|
|
|
{
|
2007-08-20 09:18:02 +00:00
|
|
|
unsigned long rate;
|
|
|
|
|
|
|
|
rate = clk->rate;
|
|
|
|
if (clk->ops->getrate)
|
|
|
|
rate = clk->ops->getrate(clk);
|
|
|
|
|
|
|
|
return rate;
|
2006-03-15 15:54:37 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_get_rate);
|
|
|
|
|
|
|
|
|
2007-08-20 09:18:02 +00:00
|
|
|
void clk_cken_enable(struct clk *clk)
|
2006-03-15 15:54:37 +00:00
|
|
|
{
|
2007-08-20 09:18:02 +00:00
|
|
|
CKEN |= 1 << clk->cken;
|
2006-03-15 15:54:37 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 09:18:02 +00:00
|
|
|
void clk_cken_disable(struct clk *clk)
|
2006-03-15 15:54:37 +00:00
|
|
|
{
|
2007-08-20 09:18:02 +00:00
|
|
|
CKEN &= ~(1 << clk->cken);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct clkops clk_cken_ops = {
|
|
|
|
.enable = clk_cken_enable,
|
|
|
|
.disable = clk_cken_disable,
|
|
|
|
};
|
|
|
|
|
2008-11-08 20:25:21 +00:00
|
|
|
void clks_register(struct clk_lookup *clks, size_t num)
|
2007-08-20 09:18:02 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++)
|
2008-11-08 20:25:21 +00:00
|
|
|
clkdev_add(&clks[i]);
|
2006-03-15 15:54:37 +00:00
|
|
|
}
|
2008-07-25 11:02:31 +00:00
|
|
|
|
2009-03-05 15:17:53 +00:00
|
|
|
int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
|
2008-07-25 11:02:31 +00:00
|
|
|
struct device *dev)
|
|
|
|
{
|
2008-11-08 20:25:21 +00:00
|
|
|
struct clk *r = clk_get(dev, id);
|
|
|
|
struct clk_lookup *l;
|
2008-07-25 11:02:31 +00:00
|
|
|
|
|
|
|
if (!r)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2009-03-05 15:17:53 +00:00
|
|
|
l = clkdev_alloc(r, alias, alias_dev_name);
|
2008-11-08 20:25:21 +00:00
|
|
|
clk_put(r);
|
|
|
|
if (!l)
|
|
|
|
return -ENODEV;
|
|
|
|
clkdev_add(l);
|
2008-07-25 11:02:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|