blob: d8957592fdc4d5eaf1f96b72d0c0a9ce70efc971 [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* linux/arch/arm/mach-s3c2440/clock.c
Ben Dooksa8d11e32005-07-26 22:39:14 +01002 *
3 * Copyright (c) 2004-2005 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C2440 Clock support
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/list.h>
28#include <linux/errno.h>
29#include <linux/err.h>
30#include <linux/device.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010031#include <linux/interrupt.h>
32#include <linux/ioport.h>
Ben Dooks36c64af2006-03-20 21:00:48 +000033#include <linux/mutex.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000034#include <linux/clk.h>
Russell Kingfced80c2008-09-06 12:10:45 +010035#include <linux/io.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010036
Russell Kinga09e64f2008-08-05 16:14:15 +010037#include <mach/hardware.h>
Arun Sharma600634972011-07-26 16:09:06 -070038#include <linux/atomic.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010039#include <asm/irq.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010040
Russell Kinga09e64f2008-08-05 16:14:15 +010041#include <mach/regs-clock.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010042
Ben Dooksd5120ae2008-10-07 23:09:51 +010043#include <plat/clock.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010044#include <plat/cpu.h>
Ben Dooksa8d11e32005-07-26 22:39:14 +010045
46/* S3C2440 extended clock support */
47
Ben Dookse44c0392006-03-20 21:00:12 +000048static unsigned long s3c2440_camif_upll_round(struct clk *clk,
49 unsigned long rate)
50{
51 unsigned long parent_rate = clk_get_rate(clk->parent);
52 int div;
53
54 if (rate > parent_rate)
55 return parent_rate;
56
57 /* note, we remove the +/- 1 calculations for the divisor */
58
59 div = (parent_rate / rate) / 2;
60
61 if (div < 1)
62 div = 1;
63 else if (div > 16)
64 div = 16;
65
66 return parent_rate / (div * 2);
67}
68
69static int s3c2440_camif_upll_setrate(struct clk *clk, unsigned long rate)
70{
71 unsigned long parent_rate = clk_get_rate(clk->parent);
72 unsigned long camdivn = __raw_readl(S3C2440_CAMDIVN);
73
74 rate = s3c2440_camif_upll_round(clk, rate);
75
76 camdivn &= ~(S3C2440_CAMDIVN_CAMCLK_SEL | S3C2440_CAMDIVN_CAMCLK_MASK);
77
78 if (rate != parent_rate) {
79 camdivn |= S3C2440_CAMDIVN_CAMCLK_SEL;
80 camdivn |= (((parent_rate / rate) / 2) - 1);
81 }
82
83 __raw_writel(camdivn, S3C2440_CAMDIVN);
84
85 return 0;
86}
87
88/* Extra S3C2440 clocks */
89
Ben Dooksa8d11e32005-07-26 22:39:14 +010090static struct clk s3c2440_clk_cam = {
91 .name = "camif",
Ben Dooks99c13852006-06-22 22:18:20 +010092 .enable = s3c2410_clkcon_enable,
Ben Dooksa8d11e32005-07-26 22:39:14 +010093 .ctrlbit = S3C2440_CLKCON_CAMERA,
94};
95
Ben Dookse44c0392006-03-20 21:00:12 +000096static struct clk s3c2440_clk_cam_upll = {
97 .name = "camif-upll",
Ben Dooksb3bf41b2009-12-01 01:24:37 +000098 .ops = &(struct clk_ops) {
99 .set_rate = s3c2440_camif_upll_setrate,
100 .round_rate = s3c2440_camif_upll_round,
101 },
Ben Dookse44c0392006-03-20 21:00:12 +0000102};
103
Ben Dooksa8d11e32005-07-26 22:39:14 +0100104static struct clk s3c2440_clk_ac97 = {
105 .name = "ac97",
Ben Dooks99c13852006-06-22 22:18:20 +0100106 .enable = s3c2410_clkcon_enable,
Ben Dooksa8d11e32005-07-26 22:39:14 +0100107 .ctrlbit = S3C2440_CLKCON_CAMERA,
108};
109
Kay Sievers4a858cf2011-12-21 16:01:38 -0800110static int s3c2440_clk_add(struct device *dev)
Ben Dooksa8d11e32005-07-26 22:39:14 +0100111{
Ben Dooks3a38e4b2008-01-28 13:01:34 +0100112 struct clk *clock_upll;
Ben Dookse546e8a2006-12-17 20:38:14 +0100113 struct clk *clock_h;
114 struct clk *clock_p;
Ben Dooksa8d11e32005-07-26 22:39:14 +0100115
Ben Dookse546e8a2006-12-17 20:38:14 +0100116 clock_p = clk_get(NULL, "pclk");
117 clock_h = clk_get(NULL, "hclk");
118 clock_upll = clk_get(NULL, "upll");
Ben Dooksa8d11e32005-07-26 22:39:14 +0100119
Ben Dookse546e8a2006-12-17 20:38:14 +0100120 if (IS_ERR(clock_p) || IS_ERR(clock_h) || IS_ERR(clock_upll)) {
Ben Dooksa8d11e32005-07-26 22:39:14 +0100121 printk(KERN_ERR "S3C2440: Failed to get parent clocks\n");
122 return -EINVAL;
123 }
124
Ben Dookse546e8a2006-12-17 20:38:14 +0100125 s3c2440_clk_cam.parent = clock_h;
126 s3c2440_clk_ac97.parent = clock_p;
127 s3c2440_clk_cam_upll.parent = clock_upll;
Ben Dooksa8d11e32005-07-26 22:39:14 +0100128
129 s3c24xx_register_clock(&s3c2440_clk_ac97);
130 s3c24xx_register_clock(&s3c2440_clk_cam);
Ben Dookse44c0392006-03-20 21:00:12 +0000131 s3c24xx_register_clock(&s3c2440_clk_cam_upll);
Ben Dooksa8d11e32005-07-26 22:39:14 +0100132
133 clk_disable(&s3c2440_clk_ac97);
134 clk_disable(&s3c2440_clk_cam);
135
136 return 0;
137}
138
Kay Sievers4a858cf2011-12-21 16:01:38 -0800139static struct subsys_interface s3c2440_clk_interface = {
140 .name = "s3c2440_clk",
141 .subsys = &s3c2440_subsys,
142 .add_dev = s3c2440_clk_add,
Ben Dooksa8d11e32005-07-26 22:39:14 +0100143};
144
Kay Sievers4a858cf2011-12-21 16:01:38 -0800145static __init int s3c24xx_clk_init(void)
Ben Dooksa8d11e32005-07-26 22:39:14 +0100146{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800147 return subsys_interface_register(&s3c2440_clk_interface);
Ben Dooksa8d11e32005-07-26 22:39:14 +0100148}
149
Kay Sievers4a858cf2011-12-21 16:01:38 -0800150arch_initcall(s3c24xx_clk_init);