blob: 76a958c6e5bcf0a0c3e0f406727ce6574b9fa00c [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
Paul Walmsley7a2bd1c2012-09-14 23:18:20 -060042/**
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 */
49static 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 Nayaked1ebc42012-04-27 15:59:32 +053063int omap2_clk_apll96_enable(struct clk_hw *hw)
64#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060065static int _apll96_enable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053066#endif
Paul Walmsley49214642010-01-26 20:13:06 -070067{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060068 return omap2xxx_cm_apll96_enable();
Paul Walmsley49214642010-01-26 20:13:06 -070069}
70
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053071#ifdef CONFIG_COMMON_CLK
72int omap2_clk_apll54_enable(struct clk_hw *hw)
73#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060074static int _apll54_enable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053075#endif
Paul Walmsley49214642010-01-26 20:13:06 -070076{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -060077 return omap2xxx_cm_apll54_enable();
Paul Walmsley49214642010-01-26 20:13:06 -070078}
79
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053080#ifdef CONFIG_COMMON_CLK
81static void _apll96_allow_idle(struct clk_hw_omap *clk)
82#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070083static void _apll96_allow_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053084#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070085{
86 omap2xxx_cm_set_apll96_auto_low_power_stop();
87}
88
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053089#ifdef CONFIG_COMMON_CLK
90static void _apll96_deny_idle(struct clk_hw_omap *clk)
91#else
Paul Walmsley92618ff2011-02-25 15:39:27 -070092static void _apll96_deny_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053093#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -070094{
95 omap2xxx_cm_set_apll96_disable_autoidle();
96}
97
Rajendra Nayaked1ebc42012-04-27 15:59:32 +053098#ifdef CONFIG_COMMON_CLK
99static void _apll54_allow_idle(struct clk_hw_omap *clk)
100#else
Paul Walmsley92618ff2011-02-25 15:39:27 -0700101static void _apll54_allow_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530102#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -0700103{
104 omap2xxx_cm_set_apll54_auto_low_power_stop();
105}
106
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530107#ifdef CONFIG_COMMON_CLK
108static void _apll54_deny_idle(struct clk_hw_omap *clk)
109#else
Paul Walmsley92618ff2011-02-25 15:39:27 -0700110static void _apll54_deny_idle(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530111#endif
Paul Walmsley92618ff2011-02-25 15:39:27 -0700112{
113 omap2xxx_cm_set_apll54_disable_autoidle();
114}
115
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530116#ifdef CONFIG_COMMON_CLK
117void omap2_clk_apll96_disable(struct clk_hw *hw)
118#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600119static void _apll96_disable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530120#endif
Paul Walmsley49214642010-01-26 20:13:06 -0700121{
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600122 omap2xxx_cm_apll96_disable();
123}
Paul Walmsley49214642010-01-26 20:13:06 -0700124
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530125#ifdef CONFIG_COMMON_CLK
126void omap2_clk_apll54_disable(struct clk_hw *hw)
127#else
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600128static void _apll54_disable(struct clk *clk)
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530129#endif
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600130{
131 omap2xxx_cm_apll54_disable();
Paul Walmsley49214642010-01-26 20:13:06 -0700132}
133
Paul Walmsley7a2bd1c2012-09-14 23:18:20 -0600134#ifdef CONFIG_COMMON_CLK
135unsigned 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
141unsigned 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 Walmsley49214642010-01-26 20:13:06 -0700148/* Public data */
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530149#ifdef CONFIG_COMMON_CLK
150const struct clk_hw_omap_ops clkhwops_apll54 = {
151 .allow_idle = _apll54_allow_idle,
152 .deny_idle = _apll54_deny_idle,
153};
Paul Walmsley49214642010-01-26 20:13:06 -0700154
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530155const struct clk_hw_omap_ops clkhwops_apll96 = {
156 .allow_idle = _apll96_allow_idle,
157 .deny_idle = _apll96_deny_idle,
158};
159#else
Paul Walmsley49214642010-01-26 20:13:06 -0700160const struct clkops clkops_apll96 = {
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600161 .enable = _apll96_enable,
162 .disable = _apll96_disable,
Paul Walmsley92618ff2011-02-25 15:39:27 -0700163 .allow_idle = _apll96_allow_idle,
164 .deny_idle = _apll96_deny_idle,
Paul Walmsley49214642010-01-26 20:13:06 -0700165};
166
167const struct clkops clkops_apll54 = {
Paul Walmsleyb6ffa052012-10-29 20:56:17 -0600168 .enable = _apll54_enable,
169 .disable = _apll54_disable,
Paul Walmsley92618ff2011-02-25 15:39:27 -0700170 .allow_idle = _apll54_allow_idle,
171 .deny_idle = _apll54_deny_idle,
Paul Walmsley49214642010-01-26 20:13:06 -0700172};
Rajendra Nayaked1ebc42012-04-27 15:59:32 +0530173#endif
Paul Walmsley49214642010-01-26 20:13:06 -0700174
175/* Public functions */
176
177u32 omap2xxx_get_apll_clkin(void)
178{
179 u32 aplls, srate = 0;
180
Paul Walmsleyc4d7e582010-12-21 21:05:14 -0700181 aplls = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL1);
Paul Walmsley49214642010-01-26 20:13:06 -0700182 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