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 |
| 42 | int omap2_clk_apll96_enable(struct clk_hw *hw) |
| 43 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 44 | static int _apll96_enable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 45 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 46 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 47 | return omap2xxx_cm_apll96_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 50 | #ifdef CONFIG_COMMON_CLK |
| 51 | int omap2_clk_apll54_enable(struct clk_hw *hw) |
| 52 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 53 | static int _apll54_enable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 54 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 55 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 56 | return omap2xxx_cm_apll54_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 59 | #ifdef CONFIG_COMMON_CLK |
| 60 | static void _apll96_allow_idle(struct clk_hw_omap *clk) |
| 61 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 62 | static void _apll96_allow_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 63 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 64 | { |
| 65 | omap2xxx_cm_set_apll96_auto_low_power_stop(); |
| 66 | } |
| 67 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 68 | #ifdef CONFIG_COMMON_CLK |
| 69 | static void _apll96_deny_idle(struct clk_hw_omap *clk) |
| 70 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 71 | static void _apll96_deny_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 72 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 73 | { |
| 74 | omap2xxx_cm_set_apll96_disable_autoidle(); |
| 75 | } |
| 76 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 77 | #ifdef CONFIG_COMMON_CLK |
| 78 | static void _apll54_allow_idle(struct clk_hw_omap *clk) |
| 79 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 80 | static void _apll54_allow_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 81 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 82 | { |
| 83 | omap2xxx_cm_set_apll54_auto_low_power_stop(); |
| 84 | } |
| 85 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 86 | #ifdef CONFIG_COMMON_CLK |
| 87 | static void _apll54_deny_idle(struct clk_hw_omap *clk) |
| 88 | #else |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 89 | static void _apll54_deny_idle(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 90 | #endif |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 91 | { |
| 92 | omap2xxx_cm_set_apll54_disable_autoidle(); |
| 93 | } |
| 94 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 95 | #ifdef CONFIG_COMMON_CLK |
| 96 | void omap2_clk_apll96_disable(struct clk_hw *hw) |
| 97 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 98 | static void _apll96_disable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 99 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 100 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 101 | omap2xxx_cm_apll96_disable(); |
| 102 | } |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 103 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 104 | #ifdef CONFIG_COMMON_CLK |
| 105 | void omap2_clk_apll54_disable(struct clk_hw *hw) |
| 106 | #else |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 107 | static void _apll54_disable(struct clk *clk) |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 108 | #endif |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 109 | { |
| 110 | omap2xxx_cm_apll54_disable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /* Public data */ |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 114 | #ifdef CONFIG_COMMON_CLK |
| 115 | const struct clk_hw_omap_ops clkhwops_apll54 = { |
| 116 | .allow_idle = _apll54_allow_idle, |
| 117 | .deny_idle = _apll54_deny_idle, |
| 118 | }; |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 119 | |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 120 | const struct clk_hw_omap_ops clkhwops_apll96 = { |
| 121 | .allow_idle = _apll96_allow_idle, |
| 122 | .deny_idle = _apll96_deny_idle, |
| 123 | }; |
| 124 | #else |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 125 | const struct clkops clkops_apll96 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 126 | .enable = _apll96_enable, |
| 127 | .disable = _apll96_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 128 | .allow_idle = _apll96_allow_idle, |
| 129 | .deny_idle = _apll96_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | const struct clkops clkops_apll54 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame] | 133 | .enable = _apll54_enable, |
| 134 | .disable = _apll54_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 135 | .allow_idle = _apll54_allow_idle, |
| 136 | .deny_idle = _apll54_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 137 | }; |
Rajendra Nayak | ed1ebc4 | 2012-04-27 15:59:32 +0530 | [diff] [blame^] | 138 | #endif |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 139 | |
| 140 | /* Public functions */ |
| 141 | |
| 142 | u32 omap2xxx_get_apll_clkin(void) |
| 143 | { |
| 144 | u32 aplls, srate = 0; |
| 145 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 146 | aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 147 | aplls &= OMAP24XX_APLLS_CLKIN_MASK; |
| 148 | aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT; |
| 149 | |
| 150 | if (aplls == APLLS_CLKIN_19_2MHZ) |
| 151 | srate = 19200000; |
| 152 | else if (aplls == APLLS_CLKIN_13MHZ) |
| 153 | srate = 13000000; |
| 154 | else if (aplls == APLLS_CLKIN_12MHZ) |
| 155 | srate = 12000000; |
| 156 | |
| 157 | return srate; |
| 158 | } |
| 159 | |