blob: 0521efbc48c95bca3bcc0700330c637723a4c192 [file] [log] [blame]
wanzongshuna62e9032009-12-31 15:06:05 +01001/*
2 * linux/arch/arm/mach-nuc93x/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
28static DEFINE_SPINLOCK(clocks_lock);
29
30int clk_enable(struct clk *clk)
31{
32 unsigned long flags;
33
34 spin_lock_irqsave(&clocks_lock, flags);
35 if (clk->enabled++ == 0)
36 (clk->enable)(clk, 1);
37 spin_unlock_irqrestore(&clocks_lock, flags);
38
39 return 0;
40}
41EXPORT_SYMBOL(clk_enable);
42
43void clk_disable(struct clk *clk)
44{
45 unsigned long flags;
46
47 WARN_ON(clk->enabled == 0);
48
49 spin_lock_irqsave(&clocks_lock, flags);
50 if (--clk->enabled == 0)
51 (clk->enable)(clk, 0);
52 spin_unlock_irqrestore(&clocks_lock, flags);
53}
54EXPORT_SYMBOL(clk_disable);
55
56unsigned long clk_get_rate(struct clk *clk)
57{
58 return 27000000;
59}
60EXPORT_SYMBOL(clk_get_rate);
61
62void nuc93x_clk_enable(struct clk *clk, int enable)
63{
64 unsigned int clocks = clk->cken;
65 unsigned long clken;
66
67 clken = __raw_readl(NUC93X_VA_CLKPWR);
68
69 if (enable)
70 clken |= clocks;
71 else
72 clken &= ~clocks;
73
74 __raw_writel(clken, NUC93X_VA_CLKPWR);
75}
76
77void clks_register(struct clk_lookup *clks, size_t num)
78{
79 int i;
80
81 for (i = 0; i < num; i++)
82 clkdev_add(&clks[i]);
83}