Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-tegra/include/mach/clock.h |
| 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 5 | * Copyright (c) 2012 NVIDIA CORPORATION. All rights reserved. |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 6 | * |
| 7 | * Author: |
| 8 | * Colin Cross <ccross@google.com> |
| 9 | * |
| 10 | * This software is licensed under the terms of the GNU General Public |
| 11 | * License version 2, as published by the Free Software Foundation, and |
| 12 | * may be copied, distributed, and modified under those terms. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef __MACH_TEGRA_CLOCK_H |
| 22 | #define __MACH_TEGRA_CLOCK_H |
| 23 | |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 24 | #include <linux/clk-provider.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 25 | #include <linux/clkdev.h> |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 26 | #include <linux/list.h> |
| 27 | #include <linux/spinlock.h> |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 28 | |
Peter De Schrijver | 4fccf75 | 2012-01-09 05:35:11 +0000 | [diff] [blame] | 29 | #include <mach/clk.h> |
| 30 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 31 | #define DIV_BUS (1 << 0) |
| 32 | #define DIV_U71 (1 << 1) |
| 33 | #define DIV_U71_FIXED (1 << 2) |
| 34 | #define DIV_2 (1 << 3) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 35 | #define DIV_U16 (1 << 4) |
| 36 | #define PLL_FIXED (1 << 5) |
| 37 | #define PLL_HAS_CPCON (1 << 6) |
| 38 | #define MUX (1 << 7) |
| 39 | #define PLLD (1 << 8) |
| 40 | #define PERIPH_NO_RESET (1 << 9) |
| 41 | #define PERIPH_NO_ENB (1 << 10) |
| 42 | #define PERIPH_EMC_ENB (1 << 11) |
| 43 | #define PERIPH_MANUAL_RESET (1 << 12) |
| 44 | #define PLL_ALT_MISC_REG (1 << 13) |
| 45 | #define PLLU (1 << 14) |
Peter De Schrijver | 4fccf75 | 2012-01-09 05:35:11 +0000 | [diff] [blame] | 46 | #define PLLX (1 << 15) |
| 47 | #define MUX_PWM (1 << 16) |
| 48 | #define MUX8 (1 << 17) |
| 49 | #define DIV_U71_UART (1 << 18) |
| 50 | #define MUX_CLK_OUT (1 << 19) |
| 51 | #define PLLM (1 << 20) |
| 52 | #define DIV_U71_INT (1 << 21) |
| 53 | #define DIV_U71_IDLE (1 << 22) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 54 | #define ENABLE_ON_INIT (1 << 28) |
Peter De Schrijver | 4fccf75 | 2012-01-09 05:35:11 +0000 | [diff] [blame] | 55 | #define PERIPH_ON_APB (1 << 29) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 56 | |
| 57 | struct clk; |
| 58 | |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 59 | #ifdef CONFIG_COMMON_CLK |
| 60 | struct clk_tegra; |
| 61 | #define to_clk_tegra(_hw) container_of(_hw, struct clk_tegra, hw) |
| 62 | #endif |
| 63 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 64 | struct clk_mux_sel { |
| 65 | struct clk *input; |
| 66 | u32 value; |
| 67 | }; |
| 68 | |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 69 | struct clk_pll_freq_table { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 70 | unsigned long input_rate; |
| 71 | unsigned long output_rate; |
| 72 | u16 n; |
| 73 | u16 m; |
| 74 | u8 p; |
| 75 | u8 cpcon; |
| 76 | }; |
| 77 | |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 78 | enum clk_state { |
| 79 | UNINITIALIZED = 0, |
| 80 | ON, |
| 81 | OFF, |
| 82 | }; |
| 83 | |
| 84 | #ifndef CONFIG_COMMON_CLK |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 85 | struct clk_ops { |
| 86 | void (*init)(struct clk *); |
| 87 | int (*enable)(struct clk *); |
| 88 | void (*disable)(struct clk *); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 89 | int (*set_parent)(struct clk *, struct clk *); |
| 90 | int (*set_rate)(struct clk *, unsigned long); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 91 | long (*round_rate)(struct clk *, unsigned long); |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame] | 92 | void (*reset)(struct clk *, bool); |
Peter De Schrijver | 4fccf75 | 2012-01-09 05:35:11 +0000 | [diff] [blame] | 93 | int (*clk_cfg_ex)(struct clk *, |
| 94 | enum tegra_clk_ex_param, u32); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 97 | struct clk { |
| 98 | /* node for master clocks list */ |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 99 | struct list_head node; /* node for list of all clocks */ |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 100 | struct clk_lookup lookup; |
| 101 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 102 | #ifdef CONFIG_DEBUG_FS |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 103 | struct dentry *dent; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 104 | #endif |
Colin Cross | 4db4afb | 2011-02-20 23:35:07 -0800 | [diff] [blame] | 105 | bool set; |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 106 | struct clk_ops *ops; |
| 107 | unsigned long rate; |
| 108 | unsigned long max_rate; |
Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 109 | unsigned long min_rate; |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 110 | u32 flags; |
| 111 | const char *name; |
| 112 | |
| 113 | u32 refcnt; |
| 114 | enum clk_state state; |
| 115 | struct clk *parent; |
| 116 | u32 div; |
| 117 | u32 mul; |
| 118 | |
| 119 | const struct clk_mux_sel *inputs; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 120 | u32 reg; |
| 121 | u32 reg_shift; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 122 | |
Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 123 | struct list_head shared_bus_list; |
| 124 | |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 125 | union { |
| 126 | struct { |
| 127 | unsigned int clk_num; |
| 128 | } periph; |
| 129 | struct { |
| 130 | unsigned long input_min; |
| 131 | unsigned long input_max; |
| 132 | unsigned long cf_min; |
| 133 | unsigned long cf_max; |
| 134 | unsigned long vco_min; |
| 135 | unsigned long vco_max; |
| 136 | const struct clk_pll_freq_table *freq_table; |
| 137 | int lock_delay; |
Peter De Schrijver | 4fccf75 | 2012-01-09 05:35:11 +0000 | [diff] [blame] | 138 | unsigned long fixed_rate; |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 139 | } pll; |
| 140 | struct { |
| 141 | u32 sel; |
| 142 | u32 reg_mask; |
| 143 | } mux; |
| 144 | struct { |
| 145 | struct clk *main; |
| 146 | struct clk *backup; |
| 147 | } cpu; |
Colin Cross | 310992c | 2011-02-12 16:14:03 -0800 | [diff] [blame] | 148 | struct { |
| 149 | struct list_head node; |
| 150 | bool enabled; |
| 151 | unsigned long rate; |
| 152 | } shared_bus_user; |
Colin Cross | f151961 | 2011-02-12 16:05:31 -0800 | [diff] [blame] | 153 | } u; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 154 | |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 155 | spinlock_t spinlock; |
| 156 | }; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 157 | |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 158 | #else |
| 159 | |
| 160 | struct clk_tegra { |
| 161 | /* node for master clocks list */ |
| 162 | struct list_head node; /* node for list of all clocks */ |
| 163 | struct clk_lookup lookup; |
| 164 | struct clk_hw hw; |
| 165 | |
| 166 | bool set; |
| 167 | unsigned long fixed_rate; |
| 168 | unsigned long max_rate; |
| 169 | unsigned long min_rate; |
| 170 | u32 flags; |
| 171 | const char *name; |
| 172 | |
| 173 | enum clk_state state; |
| 174 | u32 div; |
| 175 | u32 mul; |
| 176 | |
| 177 | u32 reg; |
| 178 | u32 reg_shift; |
| 179 | |
| 180 | struct list_head shared_bus_list; |
| 181 | |
| 182 | union { |
| 183 | struct { |
| 184 | unsigned int clk_num; |
| 185 | } periph; |
| 186 | struct { |
| 187 | unsigned long input_min; |
| 188 | unsigned long input_max; |
| 189 | unsigned long cf_min; |
| 190 | unsigned long cf_max; |
| 191 | unsigned long vco_min; |
| 192 | unsigned long vco_max; |
| 193 | const struct clk_pll_freq_table *freq_table; |
| 194 | int lock_delay; |
| 195 | unsigned long fixed_rate; |
| 196 | } pll; |
| 197 | struct { |
| 198 | u32 sel; |
| 199 | u32 reg_mask; |
| 200 | } mux; |
| 201 | struct { |
| 202 | struct clk *main; |
| 203 | struct clk *backup; |
| 204 | } cpu; |
| 205 | struct { |
| 206 | struct list_head node; |
| 207 | bool enabled; |
| 208 | unsigned long rate; |
| 209 | } shared_bus_user; |
| 210 | } u; |
| 211 | |
| 212 | void (*reset)(struct clk_hw *, bool); |
| 213 | int (*clk_cfg_ex)(struct clk_hw *, enum tegra_clk_ex_param, u32); |
| 214 | }; |
| 215 | #endif /* !CONFIG_COMMON_CLK */ |
| 216 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 217 | struct clk_duplicate { |
| 218 | const char *name; |
| 219 | struct clk_lookup lookup; |
| 220 | }; |
| 221 | |
| 222 | struct tegra_clk_init_table { |
| 223 | const char *name; |
| 224 | const char *parent; |
| 225 | unsigned long rate; |
| 226 | bool enabled; |
| 227 | }; |
| 228 | |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 229 | #ifndef CONFIG_COMMON_CLK |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 230 | void clk_init(struct clk *clk); |
Colin Cross | 4729fd7 | 2011-02-12 16:43:05 -0800 | [diff] [blame] | 231 | unsigned long clk_get_rate_locked(struct clk *c); |
| 232 | int clk_set_rate_locked(struct clk *c, unsigned long rate); |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 233 | int clk_reparent(struct clk *c, struct clk *parent); |
| 234 | #endif /* !CONFIG_COMMON_CLK */ |
| 235 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame^] | 236 | void tegra_clk_add(struct clk *c); |
Prashant Gaikwad | 96a1bd1 | 2012-08-06 11:57:42 +0530 | [diff] [blame] | 237 | void tegra2_init_clocks(void); |
| 238 | void tegra30_init_clocks(void); |
| 239 | struct clk *tegra_get_clock_by_name(const char *name); |
| 240 | void tegra_clk_init_from_table(struct tegra_clk_init_table *table); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 241 | |
| 242 | #endif |