blob: 94fb8a67b50300546ea2ce8bc7f11e9d76c2918a [file] [log] [blame]
Paul Walmsleyd8a94452009-12-08 16:21:29 -07001/*
Paul Walmsleyda4d2902010-01-26 20:13:10 -07002 * clock2xxx.c - OMAP2xxx-specific clock integration code
Paul Walmsleyd8a94452009-12-08 16:21:29 -07003 *
Paul Walmsleyda4d2902010-01-26 20:13:10 -07004 * Copyright (C) 2005-2008 Texas Instruments, Inc.
5 * Copyright (C) 2004-2010 Nokia Corporation
Paul Walmsleyd8a94452009-12-08 16:21:29 -07006 *
Paul Walmsleyda4d2902010-01-26 20:13:10 -07007 * Contacts:
8 * Richard Woodruff <r-woodruff2@ti.com>
9 * Paul Walmsley
Paul Walmsleyd8a94452009-12-08 16:21:29 -070010 *
Paul Walmsleyda4d2902010-01-26 20:13:10 -070011 * Based on earlier work by Tuukka Tikkanen, Tony Lindgren,
12 * Gordon McNutt and RidgeRun, Inc.
Paul Walmsleyd8a94452009-12-08 16:21:29 -070013 *
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
Paul Walmsleyd8a94452009-12-08 16:21:29 -070020#include <linux/kernel.h>
Paul Walmsleyd8a94452009-12-08 16:21:29 -070021#include <linux/errno.h>
Paul Walmsleyd8a94452009-12-08 16:21:29 -070022#include <linux/clk.h>
23#include <linux/io.h>
Paul Walmsleyd8a94452009-12-08 16:21:29 -070024
25#include <plat/clock.h>
Paul Walmsleyd8a94452009-12-08 16:21:29 -070026
Paul Walmsleyd8a94452009-12-08 16:21:29 -070027#include "clock.h"
28#include "clock2xxx.h"
Paul Walmsleyd8a94452009-12-08 16:21:29 -070029#include "cm.h"
30#include "cm-regbits-24xx.h"
31
Paul Walmsleyd8a94452009-12-08 16:21:29 -070032struct clk *vclk, *sclk, *dclk;
33
Paul Walmsleyda4d2902010-01-26 20:13:10 -070034/*
Paul Walmsleyd8a94452009-12-08 16:21:29 -070035 * Omap24xx specific clock functions
Paul Walmsleyda4d2902010-01-26 20:13:10 -070036 */
Paul Walmsleyd8a94452009-12-08 16:21:29 -070037
Paul Walmsley6ebe0d82010-01-26 20:13:09 -070038#ifdef CONFIG_ARCH_OMAP2430
39
Paul Walmsleyd8a94452009-12-08 16:21:29 -070040/**
41 * omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS
42 * @clk: struct clk * being enabled
43 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
44 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -070045 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
Paul Walmsleyd8a94452009-12-08 16:21:29 -070046 *
47 * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
48 * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
49 * passes back the correct CM_IDLEST register address for I2CHS
50 * modules. No return value.
51 */
52static void omap2430_clk_i2chs_find_idlest(struct clk *clk,
53 void __iomem **idlest_reg,
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -070054 u8 *idlest_bit,
55 u8 *idlest_val)
Paul Walmsleyd8a94452009-12-08 16:21:29 -070056{
57 *idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST);
58 *idlest_bit = clk->enable_bit;
Ranjith Lohithakshan419cc972010-02-24 12:05:54 -070059 *idlest_val = OMAP24XX_CM_IDLEST_VAL;
Paul Walmsleyd8a94452009-12-08 16:21:29 -070060}
61
Paul Walmsley6ebe0d82010-01-26 20:13:09 -070062#else
63#define omap2430_clk_i2chs_find_idlest NULL
64#endif
65
Paul Walmsleyd8a94452009-12-08 16:21:29 -070066/* 2430 I2CHS has non-standard IDLEST register */
67const struct clkops clkops_omap2430_i2chs_wait = {
68 .enable = omap2_dflt_clk_enable,
69 .disable = omap2_dflt_clk_disable,
70 .find_idlest = omap2430_clk_i2chs_find_idlest,
71 .find_companion = omap2_clk_dflt_find_companion,
72};
73
Paul Walmsleyd8a94452009-12-08 16:21:29 -070074/*
75 * Set clocks for bypass mode for reboot to work.
76 */
Paul Walmsleyfeec1272010-01-26 20:13:11 -070077void omap2xxx_clk_prepare_for_reboot(void)
Paul Walmsleyd8a94452009-12-08 16:21:29 -070078{
79 u32 rate;
80
81 if (vclk == NULL || sclk == NULL)
82 return;
83
84 rate = clk_get_rate(sclk);
85 clk_set_rate(vclk, rate);
86}
87
88/*
89 * Switch the MPU rate if specified on cmdline.
90 * We cannot do this early until cmdline is parsed.
91 */
Paul Walmsley4680c292010-01-26 20:13:09 -070092static int __init omap2xxx_clk_arch_init(void)
Paul Walmsleyd8a94452009-12-08 16:21:29 -070093{
94 struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck;
95 unsigned long sys_ck_rate;
96
Paul Walmsley4680c292010-01-26 20:13:09 -070097 if (!cpu_is_omap24xx())
98 return 0;
99
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700100 if (!mpurate)
101 return -EINVAL;
102
103 virt_prcm_set = clk_get(NULL, "virt_prcm_set");
104 sys_ck = clk_get(NULL, "sys_ck");
105 dpll_ck = clk_get(NULL, "dpll_ck");
106 mpu_ck = clk_get(NULL, "mpu_ck");
107
108 if (clk_set_rate(virt_prcm_set, mpurate))
109 printk(KERN_ERR "Could not find matching MPU rate\n");
110
111 recalculate_root_clocks();
112
113 sys_ck_rate = clk_get_rate(sys_ck);
114
115 pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): "
116 "%ld.%01ld/%ld/%ld MHz\n",
117 (sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10,
118 (clk_get_rate(dpll_ck) / 1000000),
119 (clk_get_rate(mpu_ck) / 1000000));
120
121 return 0;
122}
Paul Walmsley4680c292010-01-26 20:13:09 -0700123arch_initcall(omap2xxx_clk_arch_init);
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700124
125