blob: 49cf1fbc14eb476cfb766f46dcf921a3cf4ac29c [file] [log] [blame]
wanzongshun0e4a34b2009-06-10 15:50:44 +01001/*
2 * linux/arch/arm/mach-w90x900/clock.c
3 *
4 * Copyright (c) 2008 Nuvoton technology corporation
5 *
6 * Wan ZongShun <mcuos.com@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License.
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/list.h>
16#include <linux/errno.h>
17#include <linux/err.h>
18#include <linux/string.h>
19#include <linux/clk.h>
20#include <linux/spinlock.h>
21#include <linux/platform_device.h>
22#include <linux/io.h>
23
24#include <mach/hardware.h>
25
26#include "clock.h"
27
wanzongshundb58e902009-07-14 15:10:43 +010028#define SUBCLK 0x24
29
wanzongshun0e4a34b2009-06-10 15:50:44 +010030static DEFINE_SPINLOCK(clocks_lock);
31
32int clk_enable(struct clk *clk)
33{
34 unsigned long flags;
35
36 spin_lock_irqsave(&clocks_lock, flags);
37 if (clk->enabled++ == 0)
38 (clk->enable)(clk, 1);
39 spin_unlock_irqrestore(&clocks_lock, flags);
40
41 return 0;
42}
43EXPORT_SYMBOL(clk_enable);
44
45void clk_disable(struct clk *clk)
46{
47 unsigned long flags;
48
49 WARN_ON(clk->enabled == 0);
50
51 spin_lock_irqsave(&clocks_lock, flags);
52 if (--clk->enabled == 0)
53 (clk->enable)(clk, 0);
54 spin_unlock_irqrestore(&clocks_lock, flags);
55}
56EXPORT_SYMBOL(clk_disable);
57
58void w90x900_clk_enable(struct clk *clk, int enable)
59{
60 unsigned int clocks = clk->cken;
61 unsigned long clken;
62
63 clken = __raw_readl(W90X900_VA_CLKPWR);
64
65 if (enable)
66 clken |= clocks;
67 else
68 clken &= ~clocks;
69
70 __raw_writel(clken, W90X900_VA_CLKPWR);
71}
72
wanzongshundb58e902009-07-14 15:10:43 +010073void w90x900_subclk_enable(struct clk *clk, int enable)
74{
75 unsigned int clocks = clk->cken;
76 unsigned long clken;
77
78 clken = __raw_readl(W90X900_VA_CLKPWR + SUBCLK);
79
80 if (enable)
81 clken |= clocks;
82 else
83 clken &= ~clocks;
84
85 __raw_writel(clken, W90X900_VA_CLKPWR + SUBCLK);
86}
87
88
wanzongshun0e4a34b2009-06-10 15:50:44 +010089void clks_register(struct clk_lookup *clks, size_t num)
90{
91 int i;
92
93 for (i = 0; i < num; i++)
94 clkdev_add(&clks[i]);
95}