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 | #include <plat/prcm.h> |
| 25 | |
| 26 | #include "clock.h" |
| 27 | #include "clock2xxx.h" |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 28 | #include "cm2xxx.h" |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 29 | #include "cm-regbits-24xx.h" |
| 30 | |
| 31 | /* CM_CLKEN_PLL.EN_{54,96}M_PLL options (24XX) */ |
| 32 | #define EN_APLL_STOPPED 0 |
| 33 | #define EN_APLL_LOCKED 3 |
| 34 | |
| 35 | /* CM_CLKSEL1_PLL.APLLS_CLKIN options (24XX) */ |
| 36 | #define APLLS_CLKIN_19_2MHZ 0 |
| 37 | #define APLLS_CLKIN_13MHZ 2 |
| 38 | #define APLLS_CLKIN_12MHZ 3 |
| 39 | |
| 40 | /* Private functions */ |
| 41 | |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 42 | static int _apll96_enable(struct clk *clk) |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 43 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 44 | return omap2xxx_cm_apll96_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 47 | static int _apll54_enable(struct clk *clk) |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 48 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 49 | return omap2xxx_cm_apll54_enable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 52 | static void _apll96_allow_idle(struct clk *clk) |
| 53 | { |
| 54 | omap2xxx_cm_set_apll96_auto_low_power_stop(); |
| 55 | } |
| 56 | |
| 57 | static void _apll96_deny_idle(struct clk *clk) |
| 58 | { |
| 59 | omap2xxx_cm_set_apll96_disable_autoidle(); |
| 60 | } |
| 61 | |
| 62 | static void _apll54_allow_idle(struct clk *clk) |
| 63 | { |
| 64 | omap2xxx_cm_set_apll54_auto_low_power_stop(); |
| 65 | } |
| 66 | |
| 67 | static void _apll54_deny_idle(struct clk *clk) |
| 68 | { |
| 69 | omap2xxx_cm_set_apll54_disable_autoidle(); |
| 70 | } |
| 71 | |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 72 | static void _apll96_disable(struct clk *clk) |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 73 | { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 74 | omap2xxx_cm_apll96_disable(); |
| 75 | } |
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 | static void _apll54_disable(struct clk *clk) |
| 78 | { |
| 79 | omap2xxx_cm_apll54_disable(); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Public data */ |
| 83 | |
| 84 | const struct clkops clkops_apll96 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 85 | .enable = _apll96_enable, |
| 86 | .disable = _apll96_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 87 | .allow_idle = _apll96_allow_idle, |
| 88 | .deny_idle = _apll96_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | const struct clkops clkops_apll54 = { |
Paul Walmsley | b6ffa05 | 2012-10-29 20:56:17 -0600 | [diff] [blame^] | 92 | .enable = _apll54_enable, |
| 93 | .disable = _apll54_disable, |
Paul Walmsley | 92618ff | 2011-02-25 15:39:27 -0700 | [diff] [blame] | 94 | .allow_idle = _apll54_allow_idle, |
| 95 | .deny_idle = _apll54_deny_idle, |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /* Public functions */ |
| 99 | |
| 100 | u32 omap2xxx_get_apll_clkin(void) |
| 101 | { |
| 102 | u32 aplls, srate = 0; |
| 103 | |
Paul Walmsley | c4d7e58 | 2010-12-21 21:05:14 -0700 | [diff] [blame] | 104 | aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1); |
Paul Walmsley | 4921464 | 2010-01-26 20:13:06 -0700 | [diff] [blame] | 105 | aplls &= OMAP24XX_APLLS_CLKIN_MASK; |
| 106 | aplls >>= OMAP24XX_APLLS_CLKIN_SHIFT; |
| 107 | |
| 108 | if (aplls == APLLS_CLKIN_19_2MHZ) |
| 109 | srate = 19200000; |
| 110 | else if (aplls == APLLS_CLKIN_13MHZ) |
| 111 | srate = 13000000; |
| 112 | else if (aplls == APLLS_CLKIN_12MHZ) |
| 113 | srate = 12000000; |
| 114 | |
| 115 | return srate; |
| 116 | } |
| 117 | |