blob: a48b01ab0e359fe2736c96554ada04a11c6399ac [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
45 *
46 * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
47 * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
48 * passes back the correct CM_IDLEST register address for I2CHS
49 * modules. No return value.
50 */
51static void omap2430_clk_i2chs_find_idlest(struct clk *clk,
52 void __iomem **idlest_reg,
53 u8 *idlest_bit)
54{
55 *idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST);
56 *idlest_bit = clk->enable_bit;
57}
58
Paul Walmsley6ebe0d82010-01-26 20:13:09 -070059#else
60#define omap2430_clk_i2chs_find_idlest NULL
61#endif
62
Paul Walmsleyd8a94452009-12-08 16:21:29 -070063/* 2430 I2CHS has non-standard IDLEST register */
64const struct clkops clkops_omap2430_i2chs_wait = {
65 .enable = omap2_dflt_clk_enable,
66 .disable = omap2_dflt_clk_disable,
67 .find_idlest = omap2430_clk_i2chs_find_idlest,
68 .find_companion = omap2_clk_dflt_find_companion,
69};
70
Paul Walmsleyd8a94452009-12-08 16:21:29 -070071/*
72 * Set clocks for bypass mode for reboot to work.
73 */
Paul Walmsleyfeec1272010-01-26 20:13:11 -070074void omap2xxx_clk_prepare_for_reboot(void)
Paul Walmsleyd8a94452009-12-08 16:21:29 -070075{
76 u32 rate;
77
78 if (vclk == NULL || sclk == NULL)
79 return;
80
81 rate = clk_get_rate(sclk);
82 clk_set_rate(vclk, rate);
83}
84
85/*
86 * Switch the MPU rate if specified on cmdline.
87 * We cannot do this early until cmdline is parsed.
88 */
Paul Walmsley4680c292010-01-26 20:13:09 -070089static int __init omap2xxx_clk_arch_init(void)
Paul Walmsleyd8a94452009-12-08 16:21:29 -070090{
91 struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck;
92 unsigned long sys_ck_rate;
93
Paul Walmsley4680c292010-01-26 20:13:09 -070094 if (!cpu_is_omap24xx())
95 return 0;
96
Paul Walmsleyd8a94452009-12-08 16:21:29 -070097 if (!mpurate)
98 return -EINVAL;
99
100 virt_prcm_set = clk_get(NULL, "virt_prcm_set");
101 sys_ck = clk_get(NULL, "sys_ck");
102 dpll_ck = clk_get(NULL, "dpll_ck");
103 mpu_ck = clk_get(NULL, "mpu_ck");
104
105 if (clk_set_rate(virt_prcm_set, mpurate))
106 printk(KERN_ERR "Could not find matching MPU rate\n");
107
108 recalculate_root_clocks();
109
110 sys_ck_rate = clk_get_rate(sys_ck);
111
112 pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): "
113 "%ld.%01ld/%ld/%ld MHz\n",
114 (sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10,
115 (clk_get_rate(dpll_ck) / 1000000),
116 (clk_get_rate(mpu_ck) / 1000000));
117
118 return 0;
119}
Paul Walmsley4680c292010-01-26 20:13:09 -0700120arch_initcall(omap2xxx_clk_arch_init);
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700121
122