Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2xxx APLL clock control functions |
| 3 | * |
| 4 | * Copyright (C) 2005-2008 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2004-2010 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/kernel.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/io.h> |
| 23 | |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 24 | |
| 25 | #include "clock.h" |
| 26 | #include "clock2xxx.h" |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 27 | #include "cm2xxx.h" |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 28 | #include "cm-regbits-24xx.h" |
| 29 | |
| 30 | /* CM_CLKEN_PLL.EN_{54,96}M_PLL options (24XX) */ |
| 31 | #define EN_APLL_STOPPED 0 |
| 32 | #define EN_APLL_LOCKED 3 |
| 33 | |
| 34 | /* CM_CLKSEL1_PLL.APLLS_CLKIN options (24XX) */ |
| 35 | #define APLLS_CLKIN_19_2MHZ 0 |
| 36 | #define APLLS_CLKIN_13MHZ 2 |
| 37 | #define APLLS_CLKIN_12MHZ 3 |
| 38 | |
| 39 | /* Private functions */ |
| 40 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 41 | #ifdef CONFIG_COMMON_CLK |
Paul Walmsley | 7a2bd1c | 2012-09-14 23:18:20 -0600 | [diff] [blame^] | 42 | /** |
| 43 | * omap2xxx_clk_apll_locked - is the APLL locked? |
| 44 | * @hw: struct clk_hw * of the APLL to check |
| 45 | * |
| 46 | * If the APLL IP block referred to by @hw indicates that it's locked, |
| 47 | * return true; otherwise, return false. |
| 48 | */ |
| 49 | static bool omap2xxx_clk_apll_locked(struct clk_hw *hw) |
| 50 | { |
| 51 | struct clk_hw_omap *clk = to_clk_hw_omap(hw); |
| 52 | u32 r, apll_mask; |
| 53 | |
| 54 | apll_mask = EN_APLL_LOCKED << clk->enable_bit; |
| 55 | |
| 56 | r = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKEN); |
| 57 | |
| 58 | return ((r & apll_mask) == apll_mask) ? true : false; |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | #ifdef CONFIG_COMMON_CLK |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 63 | int omap2_clk_apll96_enable(struct clk_hw *hw) |
| 64 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 65 | static int _apll96_enable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 66 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 67 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 68 | return omap2xxx_cm_apll96_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 71 | #ifdef CONFIG_COMMON_CLK |
| 72 | int omap2_clk_apll54_enable(struct clk_hw *hw) |
| 73 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 74 | static int _apll54_enable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 75 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 76 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 77 | return omap2xxx_cm_apll54_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 80 | #ifdef CONFIG_COMMON_CLK |
| 81 | static void _apll96_allow_idle(struct clk_hw_omap *clk) |
| 82 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 83 | static void _apll96_allow_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 84 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 85 | { |
| 86 | omap2xxx_cm_set_apll96_auto_low_power_stop(); |
| 87 | } |
| 88 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 89 | #ifdef CONFIG_COMMON_CLK |
| 90 | static void _apll96_deny_idle(struct clk_hw_omap *clk) |
| 91 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 92 | static void _apll96_deny_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 93 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 94 | { |
| 95 | omap2xxx_cm_set_apll96_disable_autoidle(); |
| 96 | } |
| 97 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 98 | #ifdef CONFIG_COMMON_CLK |
| 99 | static void _apll54_allow_idle(struct clk_hw_omap *clk) |
| 100 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 101 | static void _apll54_allow_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 102 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 103 | { |
| 104 | omap2xxx_cm_set_apll54_auto_low_power_stop(); |
| 105 | } |
| 106 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 107 | #ifdef CONFIG_COMMON_CLK |
| 108 | static void _apll54_deny_idle(struct clk_hw_omap *clk) |
| 109 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 110 | static void _apll54_deny_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 111 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 112 | { |
| 113 | omap2xxx_cm_set_apll54_disable_autoidle(); |
| 114 | } |
| 115 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 116 | #ifdef CONFIG_COMMON_CLK |
| 117 | void omap2_clk_apll96_disable(struct clk_hw *hw) |
| 118 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 119 | static void _apll96_disable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 120 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 121 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 122 | omap2xxx_cm_apll96_disable(); |
| 123 | } |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 124 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 125 | #ifdef CONFIG_COMMON_CLK |
| 126 | void omap2_clk_apll54_disable(struct clk_hw *hw) |
| 127 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 128 | static void _apll54_disable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 129 | #endif |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 130 | { |
| 131 | omap2xxx_cm_apll54_disable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Paul Walmsley | 7a2bd1c | 2012-09-14 23:18:20 -0600 | [diff] [blame^] | 134 | #ifdef CONFIG_COMMON_CLK |
| 135 | unsigned long omap2_clk_apll54_recalc(struct clk_hw *hw, |
| 136 | unsigned long parent_rate) |
| 137 | { |
| 138 | return (omap2xxx_clk_apll_locked(hw)) ? 54000000 : 0; |
| 139 | } |
| 140 | |
| 141 | unsigned long omap2_clk_apll96_recalc(struct clk_hw *hw, |
| 142 | unsigned long parent_rate) |
| 143 | { |
| 144 | return (omap2xxx_clk_apll_locked(hw)) ? 96000000 : 0; |
| 145 | } |
| 146 | #endif |
| 147 | |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 148 | /* Public data */ |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 149 | #ifdef CONFIG_COMMON_CLK |
| 150 | const struct clk_hw_omap_ops clkhwops_apll54 = { |
| 151 | .allow_idle = _apll54_allow_idle, |
| 152 | .deny_idle = _apll54_deny_idle, |
| 153 | }; |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 154 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 155 | const struct clk_hw_omap_ops clkhwops_apll96 = { |
| 156 | .allow_idle = _apll96_allow_idle, |
| 157 | .deny_idle = _apll96_deny_idle, |
| 158 | }; |
| 159 | #else |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 160 | const struct clkops clkops_apll96 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 161 | .enable = _apll96_enable, |
| 162 | .disable = _apll96_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 163 | .allow_idle = _apll96_allow_idle, |
| 164 | .deny_idle = _apll96_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | const struct clkops clkops_apll54 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 168 | .enable = _apll54_enable, |
| 169 | .disable = _apll54_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 170 | .allow_idle = _apll54_allow_idle, |
| 171 | .deny_idle = _apll54_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 172 | }; |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame] | 173 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 174 | |
| 175 | /* Public functions */ |
| 176 | |
| 177 | u32 omap2xxx_get_apll_clkin(void) |
| 178 | { |
| 179 | u32 aplls, srate = 0; |
| 180 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 181 | aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 182 | aplls &= OMAP24XX_APLLS_CLKIN_MASK; |
| 183 | aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT; |
| 184 | |
| 185 | if (aplls == APLLS_CLKIN_19_2MHZ) |
| 186 | srate = 19200000; |
| 187 | else if (aplls == APLLS_CLKIN_13MHZ) |
| 188 | srate = 13000000; |
| 189 | else if (aplls == APLLS_CLKIN_12MHZ) |
| 190 | srate = 12000000; |
| 191 | |
| 192 | return srate; |
| 193 | } |
| 194 | |