blob: 4340ba6524d1b9517a150a300500bf6824503894 [file] [log] [blame]
Paul Walmsley543d9372008-03-18 10:22:06 +02001/*
2 * linux/arch/arm/mach-omap2/clock.c
3 *
Tony Lindgrena16e9702008-03-18 11:56:39 +02004 * Copyright (C) 2005-2008 Texas Instruments, Inc.
Paul Walmsley8c349742010-02-22 22:09:24 -07005 * Copyright (C) 2004-2010 Nokia Corporation
Tony Lindgrena16e9702008-03-18 11:56:39 +02006 *
7 * Contacts:
Paul Walmsley543d9372008-03-18 10:22:06 +02008 * Richard Woodruff <r-woodruff2@ti.com>
Paul Walmsley543d9372008-03-18 10:22:06 +02009 * Paul Walmsley
10 *
Paul Walmsley543d9372008-03-18 10:22:06 +020011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15#undef DEBUG
16
Paul Walmsley543d9372008-03-18 10:22:06 +020017#include <linux/kernel.h>
Paul Walmsley1fe9be82012-09-27 10:33:33 -060018#include <linux/export.h>
Paul Walmsley543d9372008-03-18 10:22:06 +020019#include <linux/list.h>
20#include <linux/errno.h>
Paul Walmsley4d30e822010-02-22 22:09:36 -070021#include <linux/err.h>
22#include <linux/delay.h>
Mike Turquette32cc0022012-11-10 16:58:41 -070023#include <linux/clk-provider.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Russell Kingfbd3bdb2008-09-06 12:13:59 +010025#include <linux/bitops.h>
Tero Kristo9f029b12014-10-22 15:15:36 +030026#include <linux/of_address.h>
Jean Pihet5e7c58d2011-03-03 11:25:43 +010027#include <asm/cpu.h>
Tony Lindgrendbc04162012-08-31 10:59:07 -070028
Tony Lindgrendbc04162012-08-31 10:59:07 -070029#include <trace/events/power.h>
30
31#include "soc.h"
32#include "clockdomain.h"
Paul Walmsley543d9372008-03-18 10:22:06 +020033#include "clock.h"
Paul Walmsleyc4ceedc2012-10-29 20:56:29 -060034#include "cm.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -060035#include "cm2xxx.h"
36#include "cm3xxx.h"
Paul Walmsley543d9372008-03-18 10:22:06 +020037#include "cm-regbits-24xx.h"
38#include "cm-regbits-34xx.h"
Paul Walmsleyc4ceedc2012-10-29 20:56:29 -060039#include "common.h"
40
Afzal Mohammed99541192011-12-13 10:46:43 -080041u16 cpu_mask;
Paul Walmsley543d9372008-03-18 10:22:06 +020042
Tero Kristoa24886e2014-07-02 11:47:40 +030043/* DPLL valid Fint frequency band limits - from 34xx TRM Section 4.7.6.2 */
44#define OMAP3430_DPLL_FINT_BAND1_MIN 750000
45#define OMAP3430_DPLL_FINT_BAND1_MAX 2100000
46#define OMAP3430_DPLL_FINT_BAND2_MIN 7500000
47#define OMAP3430_DPLL_FINT_BAND2_MAX 21000000
48
49/*
50 * DPLL valid Fint frequency range for OMAP36xx and OMAP4xxx.
51 * From device data manual section 4.3 "DPLL and DLL Specifications".
52 */
53#define OMAP3PLUS_DPLL_FINT_MIN 32000
54#define OMAP3PLUS_DPLL_FINT_MAX 52000000
55
Tero Kristo9f029b12014-10-22 15:15:36 +030056static struct ti_clk_ll_ops omap_clk_ll_ops = {
Tero Kristo9a356d62015-03-03 11:14:31 +020057 .clkdm_clk_enable = clkdm_clk_enable,
58 .clkdm_clk_disable = clkdm_clk_disable,
Tero Kristo192383d2015-03-03 13:47:08 +020059 .cm_wait_module_ready = omap_cm_wait_module_ready,
60 .cm_split_idlest_reg = cm_split_idlest_reg,
Tero Kristo9f029b12014-10-22 15:15:36 +030061};
Tero Kristo3ada6b102013-10-22 11:47:08 +030062
Tero Kristo9f029b12014-10-22 15:15:36 +030063/**
Tero Kristoe9e63082015-04-27 21:55:42 +030064 * omap2_clk_setup_ll_ops - setup clock driver low-level ops
65 *
66 * Sets up clock driver low-level platform ops. These are needed
67 * for register accesses and various other misc platform operations.
68 * Returns 0 on success, -EBUSY if low level ops have been registered
69 * already.
70 */
71int __init omap2_clk_setup_ll_ops(void)
72{
73 return ti_clk_setup_ll_ops(&omap_clk_ll_ops);
74}
75
Mike Turquette32cc0022012-11-10 16:58:41 -070076/*
Paul Walmsley30962d92010-02-22 22:09:38 -070077 * OMAP2+ specific clock functions
78 */
Paul Walmsley543d9372008-03-18 10:22:06 +020079
Paul Walmsley4b1f76e2010-01-26 20:13:04 -070080/* Private functions */
81
Paul Walmsley4b1f76e2010-01-26 20:13:04 -070082/* Public functions */
83
Paul Walmsley543d9372008-03-18 10:22:06 +020084/**
Paul Walmsley333943b2008-08-19 11:08:45 +030085 * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk
86 * @clk: OMAP clock struct ptr to use
87 *
88 * Convert a clockdomain name stored in a struct clk 'clk' into a
89 * clockdomain pointer, and save it into the struct clk. Intended to be
90 * called during clk_register(). No return value.
91 */
Mike Turquette32cc0022012-11-10 16:58:41 -070092void omap2_init_clk_clkdm(struct clk_hw *hw)
93{
94 struct clk_hw_omap *clk = to_clk_hw_omap(hw);
Paul Walmsley333943b2008-08-19 11:08:45 +030095 struct clockdomain *clkdm;
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -060096 const char *clk_name;
Paul Walmsley333943b2008-08-19 11:08:45 +030097
98 if (!clk->clkdm_name)
99 return;
100
Mike Turquette32cc0022012-11-10 16:58:41 -0700101 clk_name = __clk_get_name(hw->clk);
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600102
Paul Walmsley333943b2008-08-19 11:08:45 +0300103 clkdm = clkdm_lookup(clk->clkdm_name);
104 if (clkdm) {
105 pr_debug("clock: associated clk %s to clkdm %s\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600106 clk_name, clk->clkdm_name);
Paul Walmsley333943b2008-08-19 11:08:45 +0300107 clk->clkdm = clkdm;
108 } else {
Paul Walmsley7852ec02012-07-26 00:54:26 -0600109 pr_debug("clock: could not associate clk %s to clkdm %s\n",
Rajendra Nayak5dcc3b92012-09-22 02:24:17 -0600110 clk_name, clk->clkdm_name);
Paul Walmsley333943b2008-08-19 11:08:45 +0300111 }
112}
113
Mike Turquette32cc0022012-11-10 16:58:41 -0700114static int __initdata mpurate;
115
116/*
117 * By default we use the rate set by the bootloader.
118 * You can override this with mpurate= cmdline option.
119 */
120static int __init omap_clk_setup(char *str)
121{
122 get_option(&str, &mpurate);
123
124 if (!mpurate)
125 return 1;
126
127 if (mpurate < 1000)
128 mpurate *= 1000000;
129
130 return 1;
131}
132__setup("mpurate=", omap_clk_setup);
133
Paul Walmsley4d30e822010-02-22 22:09:36 -0700134/**
Paul Walmsley4d30e822010-02-22 22:09:36 -0700135 * omap2_clk_print_new_rates - print summary of current clock tree rates
136 * @hfclkin_ck_name: clk name for the off-chip HF oscillator
137 * @core_ck_name: clk name for the on-chip CORE_CLK
138 * @mpu_ck_name: clk name for the ARM MPU clock
139 *
140 * Prints a short message to the console with the HFCLKIN oscillator
141 * rate, the rate of the CORE clock, and the rate of the ARM MPU clock.
142 * Called by the boot-time MPU rate switching code. XXX This is intended
143 * to be handled by the OPP layer code in the near future and should be
144 * removed from the clock code. No return value.
145 */
146void __init omap2_clk_print_new_rates(const char *hfclkin_ck_name,
147 const char *core_ck_name,
148 const char *mpu_ck_name)
149{
150 struct clk *hfclkin_ck, *core_ck, *mpu_ck;
151 unsigned long hfclkin_rate;
152
153 mpu_ck = clk_get(NULL, mpu_ck_name);
154 if (WARN(IS_ERR(mpu_ck), "clock: failed to get %s.\n", mpu_ck_name))
155 return;
156
157 core_ck = clk_get(NULL, core_ck_name);
158 if (WARN(IS_ERR(core_ck), "clock: failed to get %s.\n", core_ck_name))
159 return;
160
161 hfclkin_ck = clk_get(NULL, hfclkin_ck_name);
162 if (WARN(IS_ERR(hfclkin_ck), "Failed to get %s.\n", hfclkin_ck_name))
163 return;
164
165 hfclkin_rate = clk_get_rate(hfclkin_ck);
166
Paul Walmsley7852ec02012-07-26 00:54:26 -0600167 pr_info("Switched to new clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
168 (hfclkin_rate / 1000000), ((hfclkin_rate / 100000) % 10),
Paul Walmsley4d30e822010-02-22 22:09:36 -0700169 (clk_get_rate(core_ck) / 1000000),
170 (clk_get_rate(mpu_ck) / 1000000));
171}
Tero Kristo8111e012014-07-02 11:47:39 +0300172
173/**
174 * ti_clk_init_features - init clock features struct for the SoC
175 *
176 * Initializes the clock features struct based on the SoC type.
177 */
178void __init ti_clk_init_features(void)
179{
Tero Kristof3b19aa2015-02-27 17:54:14 +0200180 struct ti_clk_features features = { 0 };
Tero Kristoa24886e2014-07-02 11:47:40 +0300181 /* Fint setup for DPLLs */
182 if (cpu_is_omap3430()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200183 features.fint_min = OMAP3430_DPLL_FINT_BAND1_MIN;
184 features.fint_max = OMAP3430_DPLL_FINT_BAND2_MAX;
185 features.fint_band1_max = OMAP3430_DPLL_FINT_BAND1_MAX;
186 features.fint_band2_min = OMAP3430_DPLL_FINT_BAND2_MIN;
Tero Kristoa24886e2014-07-02 11:47:40 +0300187 } else {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200188 features.fint_min = OMAP3PLUS_DPLL_FINT_MIN;
189 features.fint_max = OMAP3PLUS_DPLL_FINT_MAX;
Tero Kristoa24886e2014-07-02 11:47:40 +0300190 }
Tero Kristo512d91c2014-07-02 11:47:42 +0300191
192 /* Bypass value setup for DPLLs */
193 if (cpu_is_omap24xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200194 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300195 (1 << OMAP2XXX_EN_DPLL_LPBYPASS) |
196 (1 << OMAP2XXX_EN_DPLL_FRBYPASS);
197 } else if (cpu_is_omap34xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200198 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300199 (1 << OMAP3XXX_EN_DPLL_LPBYPASS) |
200 (1 << OMAP3XXX_EN_DPLL_FRBYPASS);
201 } else if (soc_is_am33xx() || cpu_is_omap44xx() || soc_is_am43xx() ||
202 soc_is_omap54xx() || soc_is_dra7xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200203 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300204 (1 << OMAP4XXX_EN_DPLL_LPBYPASS) |
205 (1 << OMAP4XXX_EN_DPLL_FRBYPASS) |
206 (1 << OMAP4XXX_EN_DPLL_MNBYPASS);
207 }
Tero Kristo2337c5b2014-07-02 11:47:43 +0300208
209 /* Jitter correction only available on OMAP343X */
210 if (cpu_is_omap343x())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200211 features.flags |= TI_CLK_DPLL_HAS_FREQSEL;
Tero Kristo066edb22014-07-02 11:47:44 +0300212
213 /* Idlest value for interface clocks.
214 * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
215 * 34xx reverses this, just to keep us on our toes
216 * AM35xx uses both, depending on the module.
217 */
218 if (cpu_is_omap24xx())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200219 features.cm_idlest_val = OMAP24XX_CM_IDLEST_VAL;
Tero Kristo066edb22014-07-02 11:47:44 +0300220 else if (cpu_is_omap34xx())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200221 features.cm_idlest_val = OMAP34XX_CM_IDLEST_VAL;
Tero Kristof0d2f682014-10-03 16:57:10 +0300222
223 /* On OMAP3430 ES1.0, DPLL4 can't be re-programmed */
224 if (omap_rev() == OMAP3430_REV_ES1_0)
Tero Kristof3b19aa2015-02-27 17:54:14 +0200225 features.flags |= TI_CLK_DPLL4_DENY_REPROGRAM;
226
227 ti_clk_setup_features(&features);
Tero Kristo8111e012014-07-02 11:47:39 +0300228}