2009-07-03 17:08:05 +07:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <asm/suspend.h>
|
|
|
|
#include <asm/hwblk.h>
|
|
|
|
#include <asm/clock.h>
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(hwblk_lock);
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
static void hwblk_area_mod_cnt(struct hwblk_info *info,
|
|
|
|
int area, int counter, int value, int goal)
|
2009-07-03 17:08:05 +07:00
|
|
|
{
|
|
|
|
struct hwblk_area *hap = info->areas + area;
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
hap->cnt[counter] += value;
|
|
|
|
|
|
|
|
if (hap->cnt[counter] != goal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (hap->flags & HWBLK_AREA_FLAG_PARENT)
|
|
|
|
hwblk_area_mod_cnt(info, hap->parent, counter, value, goal);
|
2009-07-03 17:08:05 +07:00
|
|
|
}
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
|
|
|
|
static int __hwblk_mod_cnt(struct hwblk_info *info, int hwblk,
|
|
|
|
int counter, int value, int goal)
|
2009-07-03 17:08:05 +07:00
|
|
|
{
|
2009-07-17 21:24:55 +07:00
|
|
|
struct hwblk *hp = info->hwblks + hwblk;
|
|
|
|
|
|
|
|
hp->cnt[counter] += value;
|
|
|
|
if (hp->cnt[counter] == goal)
|
|
|
|
hwblk_area_mod_cnt(info, hp->area, counter, value, goal);
|
2009-07-03 17:08:05 +07:00
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
return hp->cnt[counter];
|
2009-07-03 17:08:05 +07:00
|
|
|
}
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
static void hwblk_mod_cnt(struct hwblk_info *info, int hwblk,
|
|
|
|
int counter, int value, int goal)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hwblk_lock, flags);
|
|
|
|
__hwblk_mod_cnt(info, hwblk, counter, value, goal);
|
|
|
|
spin_unlock_irqrestore(&hwblk_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hwblk_cnt_inc(struct hwblk_info *info, int hwblk, int counter)
|
|
|
|
{
|
|
|
|
hwblk_mod_cnt(info, hwblk, counter, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hwblk_cnt_dec(struct hwblk_info *info, int hwblk, int counter)
|
|
|
|
{
|
|
|
|
hwblk_mod_cnt(info, hwblk, counter, -1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hwblk_enable(struct hwblk_info *info, int hwblk)
|
2009-07-03 17:08:05 +07:00
|
|
|
{
|
|
|
|
struct hwblk *hp = info->hwblks + hwblk;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned long flags;
|
2009-07-17 21:24:55 +07:00
|
|
|
int ret;
|
2009-07-03 17:08:05 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&hwblk_lock, flags);
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
ret = __hwblk_mod_cnt(info, hwblk, HWBLK_CNT_USAGE, 1, 1);
|
|
|
|
if (ret == 1) {
|
2009-07-03 17:08:05 +07:00
|
|
|
tmp = __raw_readl(hp->mstp);
|
|
|
|
tmp &= ~(1 << hp->bit);
|
|
|
|
__raw_writel(tmp, hp->mstp);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&hwblk_lock, flags);
|
|
|
|
}
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
void hwblk_disable(struct hwblk_info *info, int hwblk)
|
2009-07-03 17:08:05 +07:00
|
|
|
{
|
|
|
|
struct hwblk *hp = info->hwblks + hwblk;
|
|
|
|
unsigned long tmp;
|
|
|
|
unsigned long flags;
|
2009-07-17 21:24:55 +07:00
|
|
|
int ret;
|
2009-07-03 17:08:05 +07:00
|
|
|
|
|
|
|
spin_lock_irqsave(&hwblk_lock, flags);
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
ret = __hwblk_mod_cnt(info, hwblk, HWBLK_CNT_USAGE, -1, 0);
|
|
|
|
if (ret == 0) {
|
2009-07-03 17:08:05 +07:00
|
|
|
tmp = __raw_readl(hp->mstp);
|
|
|
|
tmp |= 1 << hp->bit;
|
|
|
|
__raw_writel(tmp, hp->mstp);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&hwblk_lock, flags);
|
|
|
|
}
|
|
|
|
|
2009-07-17 21:24:55 +07:00
|
|
|
struct hwblk_info *hwblk_info;
|
2009-07-03 17:08:05 +07:00
|
|
|
|
|
|
|
int __init hwblk_register(struct hwblk_info *info)
|
|
|
|
{
|
|
|
|
hwblk_info = info;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init __weak arch_hwblk_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __weak arch_hwblk_sleep_mode(void)
|
|
|
|
{
|
|
|
|
return SUSP_SH_SLEEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init hwblk_init(void)
|
|
|
|
{
|
|
|
|
return arch_hwblk_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allow clocks to enable and disable hardware blocks */
|
|
|
|
static int sh_hwblk_clk_enable(struct clk *clk)
|
|
|
|
{
|
|
|
|
if (!hwblk_info)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
hwblk_enable(hwblk_info, clk->arch_flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_hwblk_clk_disable(struct clk *clk)
|
|
|
|
{
|
|
|
|
if (hwblk_info)
|
|
|
|
hwblk_disable(hwblk_info, clk->arch_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct clk_ops sh_hwblk_clk_ops = {
|
|
|
|
.enable = sh_hwblk_clk_enable,
|
|
|
|
.disable = sh_hwblk_clk_disable,
|
|
|
|
.recalc = followparent_recalc,
|
|
|
|
};
|
|
|
|
|
|
|
|
int __init sh_hwblk_clk_register(struct clk *clks, int nr)
|
|
|
|
{
|
|
|
|
struct clk *clkp;
|
|
|
|
int ret = 0;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
for (k = 0; !ret && (k < nr); k++) {
|
|
|
|
clkp = clks + k;
|
2010-05-10 21:01:02 +07:00
|
|
|
|
|
|
|
/* skip over clocks using hwblk 0 (HWBLK_UNKNOWN) */
|
|
|
|
if (!clkp->arch_flags)
|
|
|
|
continue;
|
|
|
|
|
2009-07-03 17:08:05 +07:00
|
|
|
clkp->ops = &sh_hwblk_clk_ops;
|
|
|
|
ret |= clk_register(clkp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|