blob: b7e81ec3d8193b6f346fdb4cdbd8a2df3a0357d0 [file] [log] [blame]
Paul Walmsleyd8a94452009-12-08 16:21:29 -07001/*
2 * linux/arch/arm/mach-omap2/clock.c
3 *
4 * Copyright (C) 2005-2008 Texas Instruments, Inc.
5 * Copyright (C) 2004-2008 Nokia Corporation
6 *
7 * Contacts:
8 * Richard Woodruff <r-woodruff2@ti.com>
9 * Paul Walmsley
10 *
11 * Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
12 * Gordon McNutt and RidgeRun, Inc.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18#undef DEBUG
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/device.h>
23#include <linux/list.h>
24#include <linux/errno.h>
25#include <linux/delay.h>
26#include <linux/clk.h>
27#include <linux/io.h>
28#include <linux/cpufreq.h>
29#include <linux/bitops.h>
30
31#include <plat/clock.h>
32#include <plat/sram.h>
33#include <plat/prcm.h>
34#include <plat/clkdev_omap.h>
35#include <asm/div64.h>
36#include <asm/clkdev.h>
37
38#include <plat/sdrc.h>
39#include "clock.h"
40#include "clock2xxx.h"
41#include "opp2xxx.h"
42#include "prm.h"
43#include "prm-regbits-24xx.h"
44#include "cm.h"
45#include "cm-regbits-24xx.h"
46
Paul Walmsleyd8a94452009-12-08 16:21:29 -070047struct clk *vclk, *sclk, *dclk;
48
Paul Walmsleyd8a94452009-12-08 16:21:29 -070049/*-------------------------------------------------------------------------
50 * Omap24xx specific clock functions
51 *-------------------------------------------------------------------------*/
52
Paul Walmsley6ebe0d82010-01-26 20:13:09 -070053#ifdef CONFIG_ARCH_OMAP2430
54
Paul Walmsleyd8a94452009-12-08 16:21:29 -070055/**
56 * omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS
57 * @clk: struct clk * being enabled
58 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
59 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
60 *
61 * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
62 * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
63 * passes back the correct CM_IDLEST register address for I2CHS
64 * modules. No return value.
65 */
66static void omap2430_clk_i2chs_find_idlest(struct clk *clk,
67 void __iomem **idlest_reg,
68 u8 *idlest_bit)
69{
70 *idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST);
71 *idlest_bit = clk->enable_bit;
72}
73
Paul Walmsley6ebe0d82010-01-26 20:13:09 -070074#else
75#define omap2430_clk_i2chs_find_idlest NULL
76#endif
77
Paul Walmsleyd8a94452009-12-08 16:21:29 -070078/* 2430 I2CHS has non-standard IDLEST register */
79const struct clkops clkops_omap2430_i2chs_wait = {
80 .enable = omap2_dflt_clk_enable,
81 .disable = omap2_dflt_clk_disable,
82 .find_idlest = omap2430_clk_i2chs_find_idlest,
83 .find_companion = omap2_clk_dflt_find_companion,
84};
85
Paul Walmsleyd8a94452009-12-08 16:21:29 -070086/*
87 * Set clocks for bypass mode for reboot to work.
88 */
89void omap2_clk_prepare_for_reboot(void)
90{
91 u32 rate;
92
93 if (vclk == NULL || sclk == NULL)
94 return;
95
96 rate = clk_get_rate(sclk);
97 clk_set_rate(vclk, rate);
98}
99
100/*
101 * Switch the MPU rate if specified on cmdline.
102 * We cannot do this early until cmdline is parsed.
103 */
Paul Walmsley4680c292010-01-26 20:13:09 -0700104static int __init omap2xxx_clk_arch_init(void)
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700105{
106 struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck;
107 unsigned long sys_ck_rate;
108
Paul Walmsley4680c292010-01-26 20:13:09 -0700109 if (!cpu_is_omap24xx())
110 return 0;
111
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700112 if (!mpurate)
113 return -EINVAL;
114
115 virt_prcm_set = clk_get(NULL, "virt_prcm_set");
116 sys_ck = clk_get(NULL, "sys_ck");
117 dpll_ck = clk_get(NULL, "dpll_ck");
118 mpu_ck = clk_get(NULL, "mpu_ck");
119
120 if (clk_set_rate(virt_prcm_set, mpurate))
121 printk(KERN_ERR "Could not find matching MPU rate\n");
122
123 recalculate_root_clocks();
124
125 sys_ck_rate = clk_get_rate(sys_ck);
126
127 pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): "
128 "%ld.%01ld/%ld/%ld MHz\n",
129 (sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10,
130 (clk_get_rate(dpll_ck) / 1000000),
131 (clk_get_rate(mpu_ck) / 1000000));
132
133 return 0;
134}
Paul Walmsley4680c292010-01-26 20:13:09 -0700135arch_initcall(omap2xxx_clk_arch_init);
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700136
137