2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2005-07-10 11:58:14 -07:00
|
|
|
* linux/arch/arm/plat-omap/clock.c
|
2005-04-16 15:20:36 -07:00
|
|
|
*
|
2008-07-03 02:24:41 -07:00
|
|
|
* Copyright (C) 2004 - 2008 Nokia corporation
|
2005-04-16 15:20:36 -07:00
|
|
|
* Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
|
|
|
|
*
|
2005-11-10 07:26:50 -07:00
|
|
|
* Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
|
|
|
|
*
|
2005-04-16 15:20:36 -07:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
2005-11-10 07:26:50 -07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/err.h>
|
2005-10-30 16:03:48 -07:00
|
|
|
#include <linux/string.h>
|
2006-01-07 09:15:52 -07:00
|
|
|
#include <linux/clk.h>
|
2006-01-12 11:42:23 -07:00
|
|
|
#include <linux/mutex.h>
|
2006-04-02 09:46:20 -07:00
|
|
|
#include <linux/platform_device.h>
|
2008-05-22 08:38:50 -07:00
|
|
|
#include <linux/cpufreq.h>
|
2008-07-03 02:24:41 -07:00
|
|
|
#include <linux/debugfs.h>
|
2008-09-06 04:10:45 -07:00
|
|
|
#include <linux/io.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2008-08-05 08:14:15 -07:00
|
|
|
#include <mach/clock.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-06-26 16:16:22 -07:00
|
|
|
static LIST_HEAD(clocks);
|
2006-01-12 11:42:23 -07:00
|
|
|
static DEFINE_MUTEX(clocks_mutex);
|
2006-06-26 16:16:22 -07:00
|
|
|
static DEFINE_SPINLOCK(clockfw_lock);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
static struct clk_functions *arch_clock;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/*-------------------------------------------------------------------------
|
2006-01-17 16:27:09 -07:00
|
|
|
* Standard clock functions defined in include/linux/clk.h
|
2005-11-10 07:26:50 -07:00
|
|
|
*-------------------------------------------------------------------------*/
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
/*
|
|
|
|
* Returns a clock. Note that we first try to use device id on the bus
|
|
|
|
* and clock name. If this fails, we try to use clock name only.
|
|
|
|
*/
|
2005-11-10 07:26:50 -07:00
|
|
|
struct clk * clk_get(struct device *dev, const char *id)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct clk *p, *clk = ERR_PTR(-ENOENT);
|
2006-04-02 09:46:20 -07:00
|
|
|
int idno;
|
|
|
|
|
|
|
|
if (dev == NULL || dev->bus != &platform_bus_type)
|
|
|
|
idno = -1;
|
|
|
|
else
|
|
|
|
idno = to_platform_device(dev)->id;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_lock(&clocks_mutex);
|
2006-04-02 09:46:20 -07:00
|
|
|
|
|
|
|
list_for_each_entry(p, &clocks, node) {
|
|
|
|
if (p->id == idno &&
|
|
|
|
strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
|
|
|
|
clk = p;
|
2006-04-09 14:21:05 -07:00
|
|
|
goto found;
|
2006-04-02 09:46:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
list_for_each_entry(p, &clocks, node) {
|
|
|
|
if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
|
|
|
|
clk = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-04-02 09:46:20 -07:00
|
|
|
|
2006-04-09 14:21:05 -07:00
|
|
|
found:
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_unlock(&clocks_mutex);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return clk;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_get);
|
|
|
|
|
|
|
|
int clk_enable(struct clk *clk)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2005-11-10 07:26:50 -07:00
|
|
|
int ret = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
2006-01-17 16:27:09 -07:00
|
|
|
if (arch_clock->clk_enable)
|
2005-11-10 07:26:50 -07:00
|
|
|
ret = arch_clock->clk_enable(clk);
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-11-10 07:26:50 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_enable);
|
|
|
|
|
|
|
|
void clk_disable(struct clk *clk)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return;
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
2007-08-07 05:20:00 -07:00
|
|
|
if (clk->usecount == 0) {
|
|
|
|
printk(KERN_ERR "Trying disable clock %s with 0 usecount\n",
|
|
|
|
clk->name);
|
|
|
|
WARN_ON(1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2006-01-17 16:27:09 -07:00
|
|
|
if (arch_clock->clk_disable)
|
2005-11-10 07:26:50 -07:00
|
|
|
arch_clock->clk_disable(clk);
|
2007-08-07 05:20:00 -07:00
|
|
|
|
|
|
|
out:
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_disable);
|
|
|
|
|
|
|
|
int clk_get_usecount(struct clk *clk)
|
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return 0;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
ret = clk->usecount;
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_get_usecount);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long clk_get_rate(struct clk *clk)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long ret = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return 0;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
ret = clk->rate;
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_get_rate);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
void clk_put(struct clk *clk)
|
2005-07-10 11:58:18 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
if (clk && !IS_ERR(clk))
|
|
|
|
module_put(clk->owner);
|
2005-07-10 11:58:18 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_put);
|
2005-07-10 11:58:18 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/*-------------------------------------------------------------------------
|
2006-01-17 16:27:09 -07:00
|
|
|
* Optional clock functions defined in include/linux/clk.h
|
2005-11-10 07:26:50 -07:00
|
|
|
*-------------------------------------------------------------------------*/
|
2005-07-10 11:58:18 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
long clk_round_rate(struct clk *clk, unsigned long rate)
|
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
|
|
|
long ret = 0;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return ret;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_round_rate)
|
|
|
|
ret = arch_clock->clk_round_rate(clk, rate);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_round_rate);
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
int clk_set_rate(struct clk *clk, unsigned long rate)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
2006-04-02 09:46:20 -07:00
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return ret;
|
2005-07-10 11:58:18 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_set_rate)
|
|
|
|
ret = arch_clock->clk_set_rate(clk, rate);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_set_rate);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
int clk_set_parent(struct clk *clk, struct clk *parent)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
2006-04-02 09:46:20 -07:00
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
if (clk == NULL || IS_ERR(clk) || parent == NULL || IS_ERR(parent))
|
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_set_parent)
|
|
|
|
ret = arch_clock->clk_set_parent(clk, parent);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return ret;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_set_parent);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
struct clk *clk_get_parent(struct clk *clk)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
|
|
|
struct clk * ret = NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return ret;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_get_parent)
|
|
|
|
ret = arch_clock->clk_get_parent(clk);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_get_parent);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* OMAP specific clock functions shared between omap1 and omap2
|
|
|
|
*-------------------------------------------------------------------------*/
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned int __initdata mpurate;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/*
|
|
|
|
* By default we use the rate set by the bootloader.
|
|
|
|
* You can override this with mpurate= cmdline option.
|
|
|
|
*/
|
|
|
|
static int __init omap_clk_setup(char *str)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
get_option(&str, &mpurate);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
if (!mpurate)
|
|
|
|
return 1;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
if (mpurate < 1000)
|
|
|
|
mpurate *= 1000000;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
return 1;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
__setup("mpurate=", omap_clk_setup);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/* Used for clocks that always have same value as the parent clock */
|
|
|
|
void followparent_recalc(struct clk *clk)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
clk->rate = clk->parent->rate;
|
2007-03-06 04:52:01 -07:00
|
|
|
if (unlikely(clk->flags & RATE_PROPAGATES))
|
|
|
|
propagate_rate(clk);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/* Propagate rate to children */
|
|
|
|
void propagate_rate(struct clk * tclk)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
struct clk *clkp;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (tclk == NULL || IS_ERR(tclk))
|
|
|
|
return;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
list_for_each_entry(clkp, &clocks, node) {
|
|
|
|
if (likely(clkp->parent != tclk))
|
|
|
|
continue;
|
|
|
|
if (likely((u32)clkp->recalc))
|
|
|
|
clkp->recalc(clkp);
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2008-03-18 01:35:15 -07:00
|
|
|
/**
|
|
|
|
* recalculate_root_clocks - recalculate and propagate all root clocks
|
|
|
|
*
|
|
|
|
* Recalculates all root clocks (clocks with no parent), which if the
|
|
|
|
* clock's .recalc is set correctly, should also propagate their rates.
|
|
|
|
* Called at init.
|
|
|
|
*/
|
|
|
|
void recalculate_root_clocks(void)
|
|
|
|
{
|
|
|
|
struct clk *clkp;
|
|
|
|
|
|
|
|
list_for_each_entry(clkp, &clocks, node) {
|
|
|
|
if (unlikely(!clkp->parent) && likely((u32)clkp->recalc))
|
|
|
|
clkp->recalc(clkp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
int clk_register(struct clk *clk)
|
|
|
|
{
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_lock(&clocks_mutex);
|
2005-04-16 15:20:36 -07:00
|
|
|
list_add(&clk->node, &clocks);
|
|
|
|
if (clk->init)
|
|
|
|
clk->init(clk);
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_unlock(&clocks_mutex);
|
2005-11-10 07:26:50 -07:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_register);
|
|
|
|
|
|
|
|
void clk_unregister(struct clk *clk)
|
|
|
|
{
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return;
|
|
|
|
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_lock(&clocks_mutex);
|
2005-04-16 15:20:36 -07:00
|
|
|
list_del(&clk->node);
|
2006-01-12 11:42:23 -07:00
|
|
|
mutex_unlock(&clocks_mutex);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_unregister);
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
void clk_deny_idle(struct clk *clk)
|
2005-07-10 11:58:18 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_deny_idle)
|
|
|
|
arch_clock->clk_deny_idle(clk);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-07-10 11:58:18 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_deny_idle);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
void clk_allow_idle(struct clk *clk)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
unsigned long flags;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-04-02 09:46:20 -07:00
|
|
|
if (clk == NULL || IS_ERR(clk))
|
|
|
|
return;
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_allow_idle)
|
|
|
|
arch_clock->clk_allow_idle(clk);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2005-11-10 07:26:50 -07:00
|
|
|
EXPORT_SYMBOL(clk_allow_idle);
|
2005-07-10 11:58:18 -07:00
|
|
|
|
2008-03-18 01:35:15 -07:00
|
|
|
void clk_enable_init_clocks(void)
|
|
|
|
{
|
|
|
|
struct clk *clkp;
|
|
|
|
|
|
|
|
list_for_each_entry(clkp, &clocks, node) {
|
|
|
|
if (clkp->flags & ENABLE_ON_INIT)
|
|
|
|
clk_enable(clkp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_enable_init_clocks);
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPU_FREQ
|
|
|
|
void clk_init_cpufreq_table(struct cpufreq_frequency_table **table)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_init_cpufreq_table)
|
|
|
|
arch_clock->clk_init_cpufreq_table(table);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(clk_init_cpufreq_table);
|
|
|
|
#endif
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
2005-07-10 11:58:18 -07:00
|
|
|
|
2006-09-25 03:27:20 -07:00
|
|
|
#ifdef CONFIG_OMAP_RESET_CLOCKS
|
|
|
|
/*
|
|
|
|
* Disable any unused clocks left on by the bootloader
|
|
|
|
*/
|
|
|
|
static int __init clk_disable_unused(void)
|
|
|
|
{
|
|
|
|
struct clk *ck;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
list_for_each_entry(ck, &clocks, node) {
|
|
|
|
if (ck->usecount > 0 || (ck->flags & ALWAYS_ENABLED) ||
|
|
|
|
ck->enable_reg == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&clockfw_lock, flags);
|
|
|
|
if (arch_clock->clk_disable_unused)
|
|
|
|
arch_clock->clk_disable_unused(ck);
|
|
|
|
spin_unlock_irqrestore(&clockfw_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
late_initcall(clk_disable_unused);
|
|
|
|
#endif
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
int __init clk_init(struct clk_functions * custom_clocks)
|
2005-07-10 11:58:18 -07:00
|
|
|
{
|
2005-11-10 07:26:50 -07:00
|
|
|
if (!custom_clocks) {
|
|
|
|
printk(KERN_ERR "No custom clock functions registered\n");
|
|
|
|
BUG();
|
2005-07-10 11:58:18 -07:00
|
|
|
}
|
|
|
|
|
2005-11-10 07:26:50 -07:00
|
|
|
arch_clock = custom_clocks;
|
|
|
|
|
2005-07-10 11:58:18 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2008-03-18 01:35:15 -07:00
|
|
|
|
2008-07-03 02:24:41 -07:00
|
|
|
#if defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS)
|
|
|
|
/*
|
|
|
|
* debugfs support to trace clock tree hierarchy and attributes
|
|
|
|
*/
|
|
|
|
static struct dentry *clk_debugfs_root;
|
|
|
|
|
|
|
|
static int clk_debugfs_register_one(struct clk *c)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct dentry *d, *child;
|
|
|
|
struct clk *pa = c->parent;
|
|
|
|
char s[255];
|
|
|
|
char *p = s;
|
|
|
|
|
|
|
|
p += sprintf(p, "%s", c->name);
|
|
|
|
if (c->id != 0)
|
|
|
|
sprintf(p, ":%d", c->id);
|
|
|
|
d = debugfs_create_dir(s, pa ? pa->dent : clk_debugfs_root);
|
2008-11-04 14:35:07 -07:00
|
|
|
if (!d)
|
|
|
|
return -ENOMEM;
|
2008-07-03 02:24:41 -07:00
|
|
|
c->dent = d;
|
|
|
|
|
|
|
|
d = debugfs_create_u8("usecount", S_IRUGO, c->dent, (u8 *)&c->usecount);
|
2008-11-04 14:35:07 -07:00
|
|
|
if (!d) {
|
|
|
|
err = -ENOMEM;
|
2008-07-03 02:24:41 -07:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate);
|
2008-11-04 14:35:07 -07:00
|
|
|
if (!d) {
|
|
|
|
err = -ENOMEM;
|
2008-07-03 02:24:41 -07:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags);
|
2008-11-04 14:35:07 -07:00
|
|
|
if (!d) {
|
|
|
|
err = -ENOMEM;
|
2008-07-03 02:24:41 -07:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
d = c->dent;
|
|
|
|
list_for_each_entry(child, &d->d_subdirs, d_u.d_child)
|
|
|
|
debugfs_remove(child);
|
|
|
|
debugfs_remove(c->dent);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clk_debugfs_register(struct clk *c)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct clk *pa = c->parent;
|
|
|
|
|
|
|
|
if (pa && !pa->dent) {
|
|
|
|
err = clk_debugfs_register(pa);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!c->dent) {
|
|
|
|
err = clk_debugfs_register_one(c);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init clk_debugfs_init(void)
|
|
|
|
{
|
|
|
|
struct clk *c;
|
|
|
|
struct dentry *d;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
d = debugfs_create_dir("clock", NULL);
|
2008-11-04 14:35:07 -07:00
|
|
|
if (!d)
|
|
|
|
return -ENOMEM;
|
2008-07-03 02:24:41 -07:00
|
|
|
clk_debugfs_root = d;
|
|
|
|
|
|
|
|
list_for_each_entry(c, &clocks, node) {
|
|
|
|
err = clk_debugfs_register(c);
|
|
|
|
if (err)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_out:
|
|
|
|
debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
late_initcall(clk_debugfs_init);
|
|
|
|
|
|
|
|
#endif /* defined(CONFIG_PM_DEBUG) && defined(CONFIG_DEBUG_FS) */
|