Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 47 | struct clk *vclk, *sclk, *dclk; |
| 48 | |
Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 49 | /*------------------------------------------------------------------------- |
| 50 | * Omap24xx specific clock functions |
| 51 | *-------------------------------------------------------------------------*/ |
| 52 | |
| 53 | /** |
| 54 | * omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS |
| 55 | * @clk: struct clk * being enabled |
| 56 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
| 57 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
| 58 | * |
| 59 | * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the |
| 60 | * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function |
| 61 | * passes back the correct CM_IDLEST register address for I2CHS |
| 62 | * modules. No return value. |
| 63 | */ |
| 64 | static void omap2430_clk_i2chs_find_idlest(struct clk *clk, |
| 65 | void __iomem **idlest_reg, |
| 66 | u8 *idlest_bit) |
| 67 | { |
| 68 | *idlest_reg = OMAP_CM_REGADDR(CORE_MOD, CM_IDLEST); |
| 69 | *idlest_bit = clk->enable_bit; |
| 70 | } |
| 71 | |
| 72 | /* 2430 I2CHS has non-standard IDLEST register */ |
| 73 | const struct clkops clkops_omap2430_i2chs_wait = { |
| 74 | .enable = omap2_dflt_clk_enable, |
| 75 | .disable = omap2_dflt_clk_disable, |
| 76 | .find_idlest = omap2430_clk_i2chs_find_idlest, |
| 77 | .find_companion = omap2_clk_dflt_find_companion, |
| 78 | }; |
| 79 | |
Paul Walmsley | d8a9445 | 2009-12-08 16:21:29 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Set clocks for bypass mode for reboot to work. |
| 82 | */ |
| 83 | void omap2_clk_prepare_for_reboot(void) |
| 84 | { |
| 85 | u32 rate; |
| 86 | |
| 87 | if (vclk == NULL || sclk == NULL) |
| 88 | return; |
| 89 | |
| 90 | rate = clk_get_rate(sclk); |
| 91 | clk_set_rate(vclk, rate); |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Switch the MPU rate if specified on cmdline. |
| 96 | * We cannot do this early until cmdline is parsed. |
| 97 | */ |
| 98 | static int __init omap2_clk_arch_init(void) |
| 99 | { |
| 100 | struct clk *virt_prcm_set, *sys_ck, *dpll_ck, *mpu_ck; |
| 101 | unsigned long sys_ck_rate; |
| 102 | |
| 103 | if (!mpurate) |
| 104 | return -EINVAL; |
| 105 | |
| 106 | virt_prcm_set = clk_get(NULL, "virt_prcm_set"); |
| 107 | sys_ck = clk_get(NULL, "sys_ck"); |
| 108 | dpll_ck = clk_get(NULL, "dpll_ck"); |
| 109 | mpu_ck = clk_get(NULL, "mpu_ck"); |
| 110 | |
| 111 | if (clk_set_rate(virt_prcm_set, mpurate)) |
| 112 | printk(KERN_ERR "Could not find matching MPU rate\n"); |
| 113 | |
| 114 | recalculate_root_clocks(); |
| 115 | |
| 116 | sys_ck_rate = clk_get_rate(sys_ck); |
| 117 | |
| 118 | pr_info("Switched to new clocking rate (Crystal/DPLL/MPU): " |
| 119 | "%ld.%01ld/%ld/%ld MHz\n", |
| 120 | (sys_ck_rate / 1000000), (sys_ck_rate / 100000) % 10, |
| 121 | (clk_get_rate(dpll_ck) / 1000000), |
| 122 | (clk_get_rate(mpu_ck) / 1000000)); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | arch_initcall(omap2_clk_arch_init); |
| 127 | |
| 128 | |