blob: 3c1d12dc8ff3fa10d5495aa388089aa91361d6f4 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Paul Walmsley543d9372008-03-18 10:22:06 +02002/*
3 * linux/arch/arm/mach-omap2/clock.c
4 *
Tony Lindgrena16e9702008-03-18 11:56:39 +02005 * Copyright (C) 2005-2008 Texas Instruments, Inc.
Paul Walmsley8c349742010-02-22 22:09:24 -07006 * Copyright (C) 2004-2010 Nokia Corporation
Tony Lindgrena16e9702008-03-18 11:56:39 +02007 *
8 * Contacts:
Paul Walmsley543d9372008-03-18 10:22:06 +02009 * Richard Woodruff <r-woodruff2@ti.com>
Paul Walmsley543d9372008-03-18 10:22:06 +020010 * Paul Walmsley
Paul Walmsley543d9372008-03-18 10:22:06 +020011 */
12#undef DEBUG
13
Paul Walmsley543d9372008-03-18 10:22:06 +020014#include <linux/kernel.h>
Paul Walmsley1fe9be82012-09-27 10:33:33 -060015#include <linux/export.h>
Paul Walmsley543d9372008-03-18 10:22:06 +020016#include <linux/list.h>
17#include <linux/errno.h>
Paul Walmsley4d30e822010-02-22 22:09:36 -070018#include <linux/err.h>
19#include <linux/delay.h>
Stephen Boydf5b00f62015-06-22 17:05:21 -070020#include <linux/clk.h>
Mike Turquette32cc0022012-11-10 16:58:41 -070021#include <linux/clk-provider.h>
Russell Kingfced80c2008-09-06 12:10:45 +010022#include <linux/io.h>
Russell Kingfbd3bdb2008-09-06 12:13:59 +010023#include <linux/bitops.h>
Tero Kristo9f029b12014-10-22 15:15:36 +030024#include <linux/of_address.h>
Jean Pihet5e7c58d2011-03-03 11:25:43 +010025#include <asm/cpu.h>
Tony Lindgrendbc04162012-08-31 10:59:07 -070026
Tony Lindgrendbc04162012-08-31 10:59:07 -070027#include <trace/events/power.h>
28
29#include "soc.h"
30#include "clockdomain.h"
Paul Walmsley543d9372008-03-18 10:22:06 +020031#include "clock.h"
Paul Walmsleyc4ceedc2012-10-29 20:56:29 -060032#include "cm.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -060033#include "cm2xxx.h"
34#include "cm3xxx.h"
Paul Walmsley543d9372008-03-18 10:22:06 +020035#include "cm-regbits-24xx.h"
36#include "cm-regbits-34xx.h"
Paul Walmsleyc4ceedc2012-10-29 20:56:29 -060037#include "common.h"
38
Afzal Mohammed99541192011-12-13 10:46:43 -080039u16 cpu_mask;
Paul Walmsley543d9372008-03-18 10:22:06 +020040
Tero Kristoa24886e2014-07-02 11:47:40 +030041/* DPLL valid Fint frequency band limits - from 34xx TRM Section 4.7.6.2 */
42#define OMAP3430_DPLL_FINT_BAND1_MIN 750000
43#define OMAP3430_DPLL_FINT_BAND1_MAX 2100000
44#define OMAP3430_DPLL_FINT_BAND2_MIN 7500000
45#define OMAP3430_DPLL_FINT_BAND2_MAX 21000000
46
47/*
48 * DPLL valid Fint frequency range for OMAP36xx and OMAP4xxx.
49 * From device data manual section 4.3 "DPLL and DLL Specifications".
50 */
51#define OMAP3PLUS_DPLL_FINT_MIN 32000
52#define OMAP3PLUS_DPLL_FINT_MAX 52000000
53
Tero Kristo6c0afb52017-02-09 11:24:37 +020054struct ti_clk_ll_ops omap_clk_ll_ops = {
Tero Kristo9a356d62015-03-03 11:14:31 +020055 .clkdm_clk_enable = clkdm_clk_enable,
56 .clkdm_clk_disable = clkdm_clk_disable,
Tero Kristob6f27b22016-09-30 14:10:11 +030057 .clkdm_lookup = clkdm_lookup,
Tero Kristo192383d2015-03-03 13:47:08 +020058 .cm_wait_module_ready = omap_cm_wait_module_ready,
59 .cm_split_idlest_reg = cm_split_idlest_reg,
Tero Kristo9f029b12014-10-22 15:15:36 +030060};
Tero Kristo3ada6b102013-10-22 11:47:08 +030061
Tero Kristo9f029b12014-10-22 15:15:36 +030062/**
Tero Kristoe9e63082015-04-27 21:55:42 +030063 * omap2_clk_setup_ll_ops - setup clock driver low-level ops
64 *
65 * Sets up clock driver low-level platform ops. These are needed
66 * for register accesses and various other misc platform operations.
67 * Returns 0 on success, -EBUSY if low level ops have been registered
68 * already.
69 */
70int __init omap2_clk_setup_ll_ops(void)
71{
72 return ti_clk_setup_ll_ops(&omap_clk_ll_ops);
73}
74
Mike Turquette32cc0022012-11-10 16:58:41 -070075/*
Paul Walmsley30962d92010-02-22 22:09:38 -070076 * OMAP2+ specific clock functions
77 */
Paul Walmsley543d9372008-03-18 10:22:06 +020078
Tero Kristo8111e012014-07-02 11:47:39 +030079/**
80 * ti_clk_init_features - init clock features struct for the SoC
81 *
82 * Initializes the clock features struct based on the SoC type.
83 */
84void __init ti_clk_init_features(void)
85{
Tero Kristof3b19aa2015-02-27 17:54:14 +020086 struct ti_clk_features features = { 0 };
Tero Kristoa24886e2014-07-02 11:47:40 +030087 /* Fint setup for DPLLs */
88 if (cpu_is_omap3430()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +020089 features.fint_min = OMAP3430_DPLL_FINT_BAND1_MIN;
90 features.fint_max = OMAP3430_DPLL_FINT_BAND2_MAX;
91 features.fint_band1_max = OMAP3430_DPLL_FINT_BAND1_MAX;
92 features.fint_band2_min = OMAP3430_DPLL_FINT_BAND2_MIN;
Tero Kristoa24886e2014-07-02 11:47:40 +030093 } else {
Tero Kristof3b19aa2015-02-27 17:54:14 +020094 features.fint_min = OMAP3PLUS_DPLL_FINT_MIN;
95 features.fint_max = OMAP3PLUS_DPLL_FINT_MAX;
Tero Kristoa24886e2014-07-02 11:47:40 +030096 }
Tero Kristo512d91c2014-07-02 11:47:42 +030097
98 /* Bypass value setup for DPLLs */
99 if (cpu_is_omap24xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200100 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300101 (1 << OMAP2XXX_EN_DPLL_LPBYPASS) |
102 (1 << OMAP2XXX_EN_DPLL_FRBYPASS);
103 } else if (cpu_is_omap34xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200104 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300105 (1 << OMAP3XXX_EN_DPLL_LPBYPASS) |
106 (1 << OMAP3XXX_EN_DPLL_FRBYPASS);
107 } else if (soc_is_am33xx() || cpu_is_omap44xx() || soc_is_am43xx() ||
108 soc_is_omap54xx() || soc_is_dra7xx()) {
Tero Kristof3b19aa2015-02-27 17:54:14 +0200109 features.dpll_bypass_vals |=
Tero Kristo512d91c2014-07-02 11:47:42 +0300110 (1 << OMAP4XXX_EN_DPLL_LPBYPASS) |
111 (1 << OMAP4XXX_EN_DPLL_FRBYPASS) |
112 (1 << OMAP4XXX_EN_DPLL_MNBYPASS);
113 }
Tero Kristo2337c5b2014-07-02 11:47:43 +0300114
115 /* Jitter correction only available on OMAP343X */
116 if (cpu_is_omap343x())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200117 features.flags |= TI_CLK_DPLL_HAS_FREQSEL;
Tero Kristo066edb22014-07-02 11:47:44 +0300118
Tero Kristo869decd2019-04-04 11:11:05 +0300119 if (omap_type() == OMAP2_DEVICE_TYPE_GP)
120 features.flags |= TI_CLK_DEVICE_TYPE_GP;
121
Tero Kristo066edb22014-07-02 11:47:44 +0300122 /* Idlest value for interface clocks.
123 * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
124 * 34xx reverses this, just to keep us on our toes
125 * AM35xx uses both, depending on the module.
126 */
127 if (cpu_is_omap24xx())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200128 features.cm_idlest_val = OMAP24XX_CM_IDLEST_VAL;
Tero Kristo066edb22014-07-02 11:47:44 +0300129 else if (cpu_is_omap34xx())
Tero Kristof3b19aa2015-02-27 17:54:14 +0200130 features.cm_idlest_val = OMAP34XX_CM_IDLEST_VAL;
Tero Kristof0d2f682014-10-03 16:57:10 +0300131
132 /* On OMAP3430 ES1.0, DPLL4 can't be re-programmed */
133 if (omap_rev() == OMAP3430_REV_ES1_0)
Tero Kristof3b19aa2015-02-27 17:54:14 +0200134 features.flags |= TI_CLK_DPLL4_DENY_REPROGRAM;
135
Tero Kristo07ff73a2015-11-30 16:43:25 +0200136 /* Errata I810 for omap5 / dra7 */
137 if (soc_is_omap54xx() || soc_is_dra7xx())
138 features.flags |= TI_CLK_ERRATA_I810;
139
Tero Kristof3b19aa2015-02-27 17:54:14 +0200140 ti_clk_setup_features(&features);
Tero Kristo8111e012014-07-02 11:47:39 +0300141}