blob: c62f6fa6763db3123dbcd6e76c7414f43abecc81 [file] [log] [blame]
Tero Kristoa8acecc2013-07-18 11:52:33 +03001/*
2 * TI clock drivers support
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15#ifndef __LINUX_CLK_TI_H__
16#define __LINUX_CLK_TI_H__
17
Stephen Boyde3870882015-01-22 15:40:20 -080018#include <linux/clk-provider.h>
Tero Kristoa8acecc2013-07-18 11:52:33 +030019#include <linux/clkdev.h>
20
21/**
Tero Kristo6c0afb52017-02-09 11:24:37 +020022 * struct clk_omap_reg - OMAP register declaration
23 * @offset: offset from the master IP module base address
24 * @index: index of the master IP module
25 */
26struct clk_omap_reg {
27 void __iomem *ptr;
28 u16 offset;
29 u8 index;
30 u8 flags;
31};
32
33/**
Tero Kristof38b0dd2013-06-12 16:04:34 +030034 * struct dpll_data - DPLL registers and integration data
35 * @mult_div1_reg: register containing the DPLL M and N bitfields
36 * @mult_mask: mask of the DPLL M bitfield in @mult_div1_reg
37 * @div1_mask: mask of the DPLL N bitfield in @mult_div1_reg
Tero Kristob6f51282016-02-20 13:24:26 +020038 * @clk_bypass: struct clk_hw pointer to the clock's bypass clock input
39 * @clk_ref: struct clk_hw pointer to the clock's reference clock input
Tero Kristof38b0dd2013-06-12 16:04:34 +030040 * @control_reg: register containing the DPLL mode bitfield
41 * @enable_mask: mask of the DPLL mode bitfield in @control_reg
42 * @last_rounded_rate: cache of the last rate result of omap2_dpll_round_rate()
43 * @last_rounded_m: cache of the last M result of omap2_dpll_round_rate()
44 * @last_rounded_m4xen: cache of the last M4X result of
45 * omap4_dpll_regm4xen_round_rate()
46 * @last_rounded_lpmode: cache of the last lpmode result of
47 * omap4_dpll_lpmode_recalc()
48 * @max_multiplier: maximum valid non-bypass multiplier value (actual)
49 * @last_rounded_n: cache of the last N result of omap2_dpll_round_rate()
50 * @min_divider: minimum valid non-bypass divider value (actual)
51 * @max_divider: maximum valid non-bypass divider value (actual)
Tero Kristoc5cc2a0b2016-03-16 21:54:55 +020052 * @max_rate: maximum clock rate for the DPLL
Tero Kristof38b0dd2013-06-12 16:04:34 +030053 * @modes: possible values of @enable_mask
54 * @autoidle_reg: register containing the DPLL autoidle mode bitfield
55 * @idlest_reg: register containing the DPLL idle status bitfield
56 * @autoidle_mask: mask of the DPLL autoidle mode bitfield in @autoidle_reg
57 * @freqsel_mask: mask of the DPLL jitter correction bitfield in @control_reg
Andrii Tseglytskyice369a52014-05-16 05:45:58 -050058 * @dcc_mask: mask of the DPLL DCC correction bitfield @mult_div1_reg
59 * @dcc_rate: rate atleast which DCC @dcc_mask must be set
Tero Kristof38b0dd2013-06-12 16:04:34 +030060 * @idlest_mask: mask of the DPLL idle status bitfield in @idlest_reg
61 * @lpmode_mask: mask of the DPLL low-power mode bitfield in @control_reg
62 * @m4xen_mask: mask of the DPLL M4X multiplier bitfield in @control_reg
63 * @auto_recal_bit: bitshift of the driftguard enable bit in @control_reg
64 * @recal_en_bit: bitshift of the PRM_IRQENABLE_* bit for recalibration IRQs
65 * @recal_st_bit: bitshift of the PRM_IRQSTATUS_* bit for recalibration IRQs
66 * @flags: DPLL type/features (see below)
67 *
68 * Possible values for @flags:
69 * DPLL_J_TYPE: "J-type DPLL" (only some 36xx, 4xxx DPLLs)
70 *
71 * @freqsel_mask is only used on the OMAP34xx family and AM35xx.
72 *
73 * XXX Some DPLLs have multiple bypass inputs, so it's not technically
74 * correct to only have one @clk_bypass pointer.
75 *
76 * XXX The runtime-variable fields (@last_rounded_rate, @last_rounded_m,
77 * @last_rounded_n) should be separated from the runtime-fixed fields
78 * and placed into a different structure, so that the runtime-fixed data
79 * can be placed into read-only space.
80 */
81struct dpll_data {
Tero Kristo6c0afb52017-02-09 11:24:37 +020082 struct clk_omap_reg mult_div1_reg;
Tero Kristof38b0dd2013-06-12 16:04:34 +030083 u32 mult_mask;
84 u32 div1_mask;
Tero Kristob6f51282016-02-20 13:24:26 +020085 struct clk_hw *clk_bypass;
86 struct clk_hw *clk_ref;
Tero Kristo6c0afb52017-02-09 11:24:37 +020087 struct clk_omap_reg control_reg;
Tero Kristof38b0dd2013-06-12 16:04:34 +030088 u32 enable_mask;
89 unsigned long last_rounded_rate;
90 u16 last_rounded_m;
91 u8 last_rounded_m4xen;
92 u8 last_rounded_lpmode;
93 u16 max_multiplier;
94 u8 last_rounded_n;
95 u8 min_divider;
96 u16 max_divider;
Tero Kristoc5cc2a0b2016-03-16 21:54:55 +020097 unsigned long max_rate;
Tero Kristof38b0dd2013-06-12 16:04:34 +030098 u8 modes;
Tero Kristo6c0afb52017-02-09 11:24:37 +020099 struct clk_omap_reg autoidle_reg;
100 struct clk_omap_reg idlest_reg;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300101 u32 autoidle_mask;
102 u32 freqsel_mask;
103 u32 idlest_mask;
104 u32 dco_mask;
105 u32 sddiv_mask;
Andrii Tseglytskyice369a52014-05-16 05:45:58 -0500106 u32 dcc_mask;
107 unsigned long dcc_rate;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300108 u32 lpmode_mask;
109 u32 m4xen_mask;
110 u8 auto_recal_bit;
111 u8 recal_en_bit;
112 u8 recal_st_bit;
113 u8 flags;
114};
115
Tero Kristo4d008582014-02-24 16:06:34 +0200116struct clk_hw_omap;
117
118/**
119 * struct clk_hw_omap_ops - OMAP clk ops
120 * @find_idlest: find idlest register information for a clock
121 * @find_companion: find companion clock register information for a clock,
122 * basically converts CM_ICLKEN* <-> CM_FCLKEN*
123 * @allow_idle: enables autoidle hardware functionality for a clock
124 * @deny_idle: prevent autoidle hardware functionality for a clock
125 */
126struct clk_hw_omap_ops {
127 void (*find_idlest)(struct clk_hw_omap *oclk,
Tero Kristo6c0afb52017-02-09 11:24:37 +0200128 struct clk_omap_reg *idlest_reg,
Tero Kristo4d008582014-02-24 16:06:34 +0200129 u8 *idlest_bit, u8 *idlest_val);
130 void (*find_companion)(struct clk_hw_omap *oclk,
Tero Kristo6c0afb52017-02-09 11:24:37 +0200131 struct clk_omap_reg *other_reg,
Tero Kristo4d008582014-02-24 16:06:34 +0200132 u8 *other_bit);
133 void (*allow_idle)(struct clk_hw_omap *oclk);
134 void (*deny_idle)(struct clk_hw_omap *oclk);
135};
Tero Kristof38b0dd2013-06-12 16:04:34 +0300136
137/**
138 * struct clk_hw_omap - OMAP struct clk
139 * @node: list_head connecting this clock into the full clock list
140 * @enable_reg: register to write to enable the clock (see @enable_bit)
141 * @enable_bit: bitshift to write to enable/disable the clock (see @enable_reg)
142 * @flags: see "struct clk.flags possibilities" above
143 * @clksel_reg: for clksel clks, register va containing src/divisor select
Tero Kristof38b0dd2013-06-12 16:04:34 +0300144 * @dpll_data: for DPLLs, pointer to struct dpll_data for this clock
145 * @clkdm_name: clockdomain name that this clock is contained in
146 * @clkdm: pointer to struct clockdomain, resolved from @clkdm_name at runtime
147 * @ops: clock ops for this clock
148 */
149struct clk_hw_omap {
150 struct clk_hw hw;
151 struct list_head node;
152 unsigned long fixed_rate;
153 u8 fixed_div;
Tero Kristo6c0afb52017-02-09 11:24:37 +0200154 struct clk_omap_reg enable_reg;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300155 u8 enable_bit;
Tero Kristo22a65642019-09-12 16:26:05 +0300156 unsigned long flags;
Tero Kristo6c0afb52017-02-09 11:24:37 +0200157 struct clk_omap_reg clksel_reg;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300158 struct dpll_data *dpll_data;
159 const char *clkdm_name;
160 struct clockdomain *clkdm;
161 const struct clk_hw_omap_ops *ops;
Russ Dilld6e7bbc2018-09-04 12:19:37 +0530162 u32 context;
Andreas Kemnaded277ce22019-01-16 23:04:27 +0100163 int autoidle_count;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300164};
165
166/*
167 * struct clk_hw_omap.flags possibilities
168 *
169 * XXX document the rest of the clock flags here
170 *
171 * ENABLE_REG_32BIT: (OMAP1 only) clock control register must be accessed
172 * with 32bit ops, by default OMAP1 uses 16bit ops.
173 * CLOCK_IDLE_CONTROL: (OMAP1 only) clock has autoidle support.
174 * CLOCK_NO_IDLE_PARENT: (OMAP1 only) when clock is enabled, its parent
175 * clock is put to no-idle mode.
176 * ENABLE_ON_INIT: Clock is enabled on init.
177 * INVERT_ENABLE: By default, clock enable bit behavior is '1' enable, '0'
178 * disable. This inverts the behavior making '0' enable and '1' disable.
179 * CLOCK_CLKOUTX2: (OMAP4 only) DPLL CLKOUT and CLKOUTX2 GATE_CTRL
180 * bits share the same register. This flag allows the
181 * omap4_dpllmx*() code to determine which GATE_CTRL bit field
182 * should be used. This is a temporary solution - a better approach
183 * would be to associate clock type-specific data with the clock,
184 * similar to the struct dpll_data approach.
Tero Kristof38b0dd2013-06-12 16:04:34 +0300185 */
186#define ENABLE_REG_32BIT (1 << 0) /* Use 32-bit access */
187#define CLOCK_IDLE_CONTROL (1 << 1)
188#define CLOCK_NO_IDLE_PARENT (1 << 2)
189#define ENABLE_ON_INIT (1 << 3) /* Enable upon framework init */
190#define INVERT_ENABLE (1 << 4) /* 0 enables, 1 disables */
191#define CLOCK_CLKOUTX2 (1 << 5)
Tero Kristof38b0dd2013-06-12 16:04:34 +0300192
193/* CM_CLKEN_PLL*.EN* bit values - not all are available for every DPLL */
194#define DPLL_LOW_POWER_STOP 0x1
195#define DPLL_LOW_POWER_BYPASS 0x5
196#define DPLL_LOCKED 0x7
197
198/* DPLL Type and DCO Selection Flags */
199#define DPLL_J_TYPE 0x1
200
Tero Kristo74807df2015-01-29 22:25:40 +0200201/* Static memmap indices */
202enum {
203 TI_CLKM_CM = 0,
Tero Kristo3a3e1c82015-02-23 15:57:32 +0200204 TI_CLKM_CM2,
Tero Kristo74807df2015-01-29 22:25:40 +0200205 TI_CLKM_PRM,
206 TI_CLKM_SCRM,
Tero Kristofe874142014-03-12 18:33:45 +0200207 TI_CLKM_CTRL,
Tero Kristo04dfac02018-03-14 15:53:10 +0200208 TI_CLKM_CTRL_AUX,
Tony Lindgren4e34df0c2015-12-03 12:02:31 -0800209 TI_CLKM_PLLSS,
Tero Kristofe874142014-03-12 18:33:45 +0200210 CLK_MAX_MEMMAPS
Tero Kristo74807df2015-01-29 22:25:40 +0200211};
212
Tero Kristo819b4862013-10-22 11:39:36 +0300213/**
Tero Kristo9a356d62015-03-03 11:14:31 +0200214 * struct ti_clk_ll_ops - low-level ops for clocks
Tero Kristo819b4862013-10-22 11:39:36 +0300215 * @clk_readl: pointer to register read function
216 * @clk_writel: pointer to register write function
Tero Kristo4902c2022017-07-26 16:47:27 +0300217 * @clk_rmw: pointer to register read-modify-write function
Tero Kristo9a356d62015-03-03 11:14:31 +0200218 * @clkdm_clk_enable: pointer to clockdomain enable function
219 * @clkdm_clk_disable: pointer to clockdomain disable function
Tero Kristob6f27b22016-09-30 14:10:11 +0300220 * @clkdm_lookup: pointer to clockdomain lookup function
Tero Kristo192383d2015-03-03 13:47:08 +0200221 * @cm_wait_module_ready: pointer to CM module wait ready function
222 * @cm_split_idlest_reg: pointer to CM module function to split idlest reg
Tero Kristo819b4862013-10-22 11:39:36 +0300223 *
Tero Kristo9a356d62015-03-03 11:14:31 +0200224 * Low-level ops are generally used by the basic clock types (clk-gate,
225 * clk-mux, clk-divider etc.) to provide support for various low-level
226 * hadrware interfaces (direct MMIO, regmap etc.), and is initialized
227 * by board code. Low-level ops also contain some other platform specific
228 * operations not provided directly by clock drivers.
Tero Kristo819b4862013-10-22 11:39:36 +0300229 */
230struct ti_clk_ll_ops {
Tero Kristo6c0afb52017-02-09 11:24:37 +0200231 u32 (*clk_readl)(const struct clk_omap_reg *reg);
232 void (*clk_writel)(u32 val, const struct clk_omap_reg *reg);
Tero Kristo4902c2022017-07-26 16:47:27 +0300233 void (*clk_rmw)(u32 val, u32 mask, const struct clk_omap_reg *reg);
Tero Kristo9a356d62015-03-03 11:14:31 +0200234 int (*clkdm_clk_enable)(struct clockdomain *clkdm, struct clk *clk);
235 int (*clkdm_clk_disable)(struct clockdomain *clkdm,
236 struct clk *clk);
Tero Kristob6f27b22016-09-30 14:10:11 +0300237 struct clockdomain * (*clkdm_lookup)(const char *name);
Tero Kristo192383d2015-03-03 13:47:08 +0200238 int (*cm_wait_module_ready)(u8 part, s16 prcm_mod, u16 idlest_reg,
239 u8 idlest_shift);
Tero Kristo6c0afb52017-02-09 11:24:37 +0200240 int (*cm_split_idlest_reg)(struct clk_omap_reg *idlest_reg,
241 s16 *prcm_inst, u8 *idlest_reg_id);
Tero Kristo819b4862013-10-22 11:39:36 +0300242};
243
Tero Kristof38b0dd2013-06-12 16:04:34 +0300244#define to_clk_hw_omap(_hw) container_of(_hw, struct clk_hw_omap, hw)
245
Tero Kristob88b5b72019-04-04 11:11:02 +0300246bool omap2_clk_is_hw_omap(struct clk_hw *hw);
Tero Kristo21876ea2013-07-18 15:57:51 +0300247int omap2_clk_disable_autoidle_all(void);
Tero Kristobf22bae2015-03-02 19:06:54 +0200248int omap2_clk_enable_autoidle_all(void);
249int omap2_clk_allow_idle(struct clk *clk);
250int omap2_clk_deny_idle(struct clk *clk);
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200251unsigned long omap2_dpllcore_recalc(struct clk_hw *hw,
252 unsigned long parent_rate);
253int omap2_reprogram_dpllcore(struct clk_hw *clk, unsigned long rate,
254 unsigned long parent_rate);
255void omap2xxx_clkt_dpllcore_init(struct clk_hw *hw);
Tero Kristo61f25ca2014-02-24 18:49:35 +0200256void omap2xxx_clkt_vps_init(void);
Tero Kristo59245ce2015-03-02 11:07:35 +0200257unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
Tero Kristof38b0dd2013-06-12 16:04:34 +0300258
Tero Kristoc08ee142014-09-12 15:01:57 +0300259void ti_dt_clk_init_retry_clks(void);
Tero Kristo3cd4a592013-08-21 19:39:15 +0300260void ti_dt_clockdomains_setup(void);
Tero Kristoe9e63082015-04-27 21:55:42 +0300261int ti_clk_setup_ll_ops(struct ti_clk_ll_ops *ops);
Tero Kristob1a07b42013-06-18 16:27:57 +0300262
Tero Kristo989feaf2015-04-27 22:23:06 +0300263struct regmap;
264
265int omap2_clk_provider_init(struct device_node *parent, int index,
266 struct regmap *syscon, void __iomem *mem);
267void omap2_clk_legacy_provider_init(int index, void __iomem *mem);
268
Tero Kristoaafd9002013-08-02 14:04:19 +0300269int omap3430_dt_clk_init(void);
270int omap3630_dt_clk_init(void);
271int am35xx_dt_clk_init(void);
Tony Lindgren9cf705d2015-07-16 01:55:57 -0700272int dm814x_dt_clk_init(void);
273int dm816x_dt_clk_init(void);
Tero Kristo21876ea2013-07-18 15:57:51 +0300274int omap4xxx_dt_clk_init(void);
Tero Kristo52b14722013-07-18 17:15:51 +0300275int omap5xxx_dt_clk_init(void);
Tero Kristo251a449d2013-07-18 17:41:00 +0300276int dra7xx_dt_clk_init(void);
Tero Kristo45622e22013-07-19 11:36:01 +0300277int am33xx_dt_clk_init(void);
Tero Kristoffab2392013-09-20 17:02:40 +0300278int am43xx_dt_clk_init(void);
Tero Kristobe67c3b2014-02-24 17:52:57 +0200279int omap2420_dt_clk_init(void);
280int omap2430_dt_clk_init(void);
Tero Kristo21876ea2013-07-18 15:57:51 +0300281
Tero Kristof3b19aa2015-02-27 17:54:14 +0200282struct ti_clk_features {
283 u32 flags;
284 long fint_min;
285 long fint_max;
286 long fint_band1_max;
287 long fint_band2_min;
288 u8 dpll_bypass_vals;
289 u8 cm_idlest_val;
290};
291
292#define TI_CLK_DPLL_HAS_FREQSEL BIT(0)
293#define TI_CLK_DPLL4_DENY_REPROGRAM BIT(1)
Tero Kristo046b7c32015-03-03 15:13:50 +0200294#define TI_CLK_DISABLE_CLKDM_CONTROL BIT(2)
Tero Kristo07ff73a2015-11-30 16:43:25 +0200295#define TI_CLK_ERRATA_I810 BIT(3)
Tero Kristo47b00dc2018-08-10 11:29:09 +0300296#define TI_CLK_CLKCTRL_COMPAT BIT(4)
Tero Kristo869decd2019-04-04 11:11:05 +0300297#define TI_CLK_DEVICE_TYPE_GP BIT(5)
Tero Kristof3b19aa2015-02-27 17:54:14 +0200298
299void ti_clk_setup_features(struct ti_clk_features *features);
300const struct ti_clk_features *ti_clk_get_features(void);
Tero Kristo2209b722019-09-12 16:26:06 +0300301bool ti_clk_is_in_standby(struct clk *clk);
Russ Dilld6e7bbc2018-09-04 12:19:37 +0530302int omap3_noncore_dpll_save_context(struct clk_hw *hw);
303void omap3_noncore_dpll_restore_context(struct clk_hw *hw);
304
305int omap3_core_dpll_save_context(struct clk_hw *hw);
306void omap3_core_dpll_restore_context(struct clk_hw *hw);
Tero Kristof3b19aa2015-02-27 17:54:14 +0200307
Tero Kristoaa76fcf2014-02-21 17:36:21 +0200308extern const struct clk_hw_omap_ops clkhwops_omap2xxx_dpll;
Tero Kristof38b0dd2013-06-12 16:04:34 +0300309
Arnd Bergmann6793a30a2015-02-03 17:59:32 +0100310#ifdef CONFIG_ATAGS
Tero Kristo74807df2015-01-29 22:25:40 +0200311int omap3430_clk_legacy_init(void);
312int omap3430es1_clk_legacy_init(void);
313int omap36xx_clk_legacy_init(void);
314int am35xx_clk_legacy_init(void);
Arnd Bergmann6793a30a2015-02-03 17:59:32 +0100315#else
316static inline int omap3430_clk_legacy_init(void) { return -ENXIO; }
317static inline int omap3430es1_clk_legacy_init(void) { return -ENXIO; }
318static inline int omap36xx_clk_legacy_init(void) { return -ENXIO; }
319static inline int am35xx_clk_legacy_init(void) { return -ENXIO; }
320#endif
321
Tero Kristo74807df2015-01-29 22:25:40 +0200322
Tero Kristoa8acecc2013-07-18 11:52:33 +0300323#endif