blob: 1bd15275dbf9105593954172c083ef26800cee38 [file] [log] [blame]
Paul Walmsley49214642010-01-26 20:13:06 -07001/*
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 Walmsley49214642010-01-26 20:13:06 -070024
25#include "clock.h"
26#include "clock2xxx.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -060027#include "cm2xxx.h"
Paul Walmsley49214642010-01-26 20:13:06 -070028#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 Nayaked1ebc42012-04-27 15:59:32 +053041#ifdef CONFIG_COMMON_CLK
42int omap2_clk_apll96_enable(struct clk_hw *hw)
43#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060044static int _apll96_enable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053045#endif
Paul Walmsley49214642010-01-26 20:13:06 -070046{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060047 return omap2xxx_cm_apll96_enable();
Paul Walmsley49214642010-01-26 20:13:06 -070048}
49
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053050#ifdef CONFIG_COMMON_CLK
51int omap2_clk_apll54_enable(struct clk_hw *hw)
52#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060053static int _apll54_enable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053054#endif
Paul Walmsley49214642010-01-26 20:13:06 -070055{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060056 return omap2xxx_cm_apll54_enable();
Paul Walmsley49214642010-01-26 20:13:06 -070057}
58
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053059#ifdef CONFIG_COMMON_CLK
60static void _apll96_allow_idle(struct clk_hw_omap *clk)
61#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070062static void _apll96_allow_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053063#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070064{
65 omap2xxx_cm_set_apll96_auto_low_power_stop();
66}
67
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053068#ifdef CONFIG_COMMON_CLK
69static void _apll96_deny_idle(struct clk_hw_omap *clk)
70#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070071static void _apll96_deny_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053072#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070073{
74 omap2xxx_cm_set_apll96_disable_autoidle();
75}
76
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053077#ifdef CONFIG_COMMON_CLK
78static void _apll54_allow_idle(struct clk_hw_omap *clk)
79#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070080static void _apll54_allow_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053081#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070082{
83 omap2xxx_cm_set_apll54_auto_low_power_stop();
84}
85
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053086#ifdef CONFIG_COMMON_CLK
87static void _apll54_deny_idle(struct clk_hw_omap *clk)
88#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070089static void _apll54_deny_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053090#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070091{
92 omap2xxx_cm_set_apll54_disable_autoidle();
93}
94
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053095#ifdef CONFIG_COMMON_CLK
96void omap2_clk_apll96_disable(struct clk_hw *hw)
97#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060098static void _apll96_disable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053099#endif
Paul Walmsley49214642010-01-26 20:13:06 -0700100{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600101 omap2xxx_cm_apll96_disable();
102}
Paul Walmsley49214642010-01-26 20:13:06 -0700103
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530104#ifdef CONFIG_COMMON_CLK
105void omap2_clk_apll54_disable(struct clk_hw *hw)
106#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600107static void _apll54_disable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530108#endif
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600109{
110 omap2xxx_cm_apll54_disable();
Paul Walmsley49214642010-01-26 20:13:06 -0700111}
112
113/* Public data */
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530114#ifdef CONFIG_COMMON_CLK
115const struct clk_hw_omap_ops clkhwops_apll54 = {
116 .allow_idle = _apll54_allow_idle,
117 .deny_idle = _apll54_deny_idle,
118};
Paul Walmsley49214642010-01-26 20:13:06 -0700119
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530120const struct clk_hw_omap_ops clkhwops_apll96 = {
121 .allow_idle = _apll96_allow_idle,
122 .deny_idle = _apll96_deny_idle,
123};
124#else
Paul Walmsley49214642010-01-26 20:13:06 -0700125const struct clkops clkops_apll96 = {
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600126 .enable = _apll96_enable,
127 .disable = _apll96_disable,
Paul Walmsley92618ff2011-02-25 15:39:27 -0700128 .allow_idle = _apll96_allow_idle,
129 .deny_idle = _apll96_deny_idle,
Paul Walmsley49214642010-01-26 20:13:06 -0700130};
131
132const struct clkops clkops_apll54 = {
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600133 .enable = _apll54_enable,
134 .disable = _apll54_disable,
Paul Walmsley92618ff2011-02-25 15:39:27 -0700135 .allow_idle = _apll54_allow_idle,
136 .deny_idle = _apll54_deny_idle,
Paul Walmsley49214642010-01-26 20:13:06 -0700137};
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530138#endif
Paul Walmsley49214642010-01-26 20:13:06 -0700139
140/* Public functions */
141
142u32 omap2xxx_get_apll_clkin(void)
143{
144 u32 aplls, srate = 0;
145
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700146 aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1);
Paul Walmsley49214642010-01-26 20:13:06 -0700147 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