Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * OMAP3-specific clock framework functions |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2007-2010 Nokia Corporation |
| 6 | * |
| 7 | * Paul Walmsley |
| 8 | * Jouni Högander |
| 9 | * |
| 10 | * Parts of this code are based on code written by |
| 11 | * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | #undef DEBUG |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/errno.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/err.h> |
| 25 | |
| 26 | #include <plat/cpu.h> |
| 27 | #include <plat/clock.h> |
| 28 | |
| 29 | #include "clock.h" |
| 30 | #include "clock3xxx.h" |
| 31 | #include "prm.h" |
| 32 | #include "prm-regbits-34xx.h" |
| 33 | #include "cm.h" |
| 34 | #include "cm-regbits-34xx.h" |
| 35 | |
| 36 | /* |
| 37 | * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks |
| 38 | * that are sourced by DPLL5, and both of these require this clock |
| 39 | * to be at 120 MHz for proper operation. |
| 40 | */ |
| 41 | #define DPLL5_FREQ_FOR_USBHOST 120000000 |
| 42 | |
| 43 | /* needed by omap3_core_dpll_m2_set_rate() */ |
| 44 | struct clk *sdrc_ick_p, *arm_fck_p; |
| 45 | |
| 46 | int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate) |
| 47 | { |
| 48 | /* |
| 49 | * According to the 12-5 CDP code from TI, "Limitation 2.5" |
| 50 | * on 3430ES1 prevents us from changing DPLL multipliers or dividers |
| 51 | * on DPLL4. |
| 52 | */ |
| 53 | if (omap_rev() == OMAP3430_REV_ES1_0) { |
| 54 | pr_err("clock: DPLL4 cannot change rate due to " |
| 55 | "silicon 'Limitation 2.5' on 3430ES1.\n"); |
| 56 | return -EINVAL; |
| 57 | } |
| 58 | |
| 59 | return omap3_noncore_dpll_set_rate(clk, rate); |
| 60 | } |
| 61 | |
| 62 | void __init omap3_clk_lock_dpll5(void) |
| 63 | { |
| 64 | struct clk *dpll5_clk; |
| 65 | struct clk *dpll5_m2_clk; |
| 66 | |
| 67 | dpll5_clk = clk_get(NULL, "dpll5_ck"); |
| 68 | clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST); |
| 69 | clk_enable(dpll5_clk); |
| 70 | |
| 71 | /* Enable autoidle to allow it to enter low power bypass */ |
| 72 | omap3_dpll_allow_idle(dpll5_clk); |
| 73 | |
| 74 | /* Program dpll5_m2_clk divider for no division */ |
| 75 | dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck"); |
| 76 | clk_enable(dpll5_m2_clk); |
| 77 | clk_set_rate(dpll5_m2_clk, DPLL5_FREQ_FOR_USBHOST); |
| 78 | |
| 79 | clk_disable(dpll5_m2_clk); |
| 80 | clk_disable(dpll5_clk); |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | /* Common clock code */ |
| 85 | |
| 86 | /* REVISIT: Move this init stuff out into clock.c */ |
| 87 | |
| 88 | /* |
| 89 | * Switch the MPU rate if specified on cmdline. |
| 90 | * We cannot do this early until cmdline is parsed. |
| 91 | */ |
| 92 | static int __init omap3xxx_clk_arch_init(void) |
| 93 | { |
| 94 | struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck; |
| 95 | unsigned long osc_sys_rate; |
| 96 | bool err = 0; |
| 97 | |
| 98 | if (!cpu_is_omap34xx()) |
| 99 | return 0; |
| 100 | |
| 101 | if (!mpurate) |
| 102 | return -EINVAL; |
| 103 | |
| 104 | /* XXX test these for success */ |
| 105 | dpll1_ck = clk_get(NULL, "dpll1_ck"); |
| 106 | if (WARN(IS_ERR(dpll1_ck), "Failed to get dpll1_ck.\n")) |
| 107 | err = 1; |
| 108 | |
| 109 | arm_fck = clk_get(NULL, "arm_fck"); |
| 110 | if (WARN(IS_ERR(arm_fck), "Failed to get arm_fck.\n")) |
| 111 | err = 1; |
| 112 | |
| 113 | core_ck = clk_get(NULL, "core_ck"); |
| 114 | if (WARN(IS_ERR(core_ck), "Failed to get core_ck.\n")) |
| 115 | err = 1; |
| 116 | |
| 117 | osc_sys_ck = clk_get(NULL, "osc_sys_ck"); |
| 118 | if (WARN(IS_ERR(osc_sys_ck), "Failed to get osc_sys_ck.\n")) |
| 119 | err = 1; |
| 120 | |
| 121 | if (err) |
| 122 | return -ENOENT; |
| 123 | |
| 124 | /* REVISIT: not yet ready for 343x */ |
| 125 | if (clk_set_rate(dpll1_ck, mpurate)) |
| 126 | printk(KERN_ERR "*** Unable to set MPU rate\n"); |
| 127 | |
| 128 | recalculate_root_clocks(); |
| 129 | |
| 130 | osc_sys_rate = clk_get_rate(osc_sys_ck); |
| 131 | |
| 132 | pr_info("Switched to new clocking rate (Crystal/Core/MPU): " |
| 133 | "%ld.%01ld/%ld/%ld MHz\n", |
| 134 | (osc_sys_rate / 1000000), |
| 135 | ((osc_sys_rate / 100000) % 10), |
| 136 | (clk_get_rate(core_ck) / 1000000), |
| 137 | (clk_get_rate(arm_fck) / 1000000)); |
| 138 | |
| 139 | calibrate_delay(); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | arch_initcall(omap3xxx_clk_arch_init); |
| 144 | |
| 145 | |