Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1 | /* |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #ifndef __TEGRA_CLK_H |
| 18 | #define __TEGRA_CLK_H |
| 19 | |
| 20 | #include <linux/clk-provider.h> |
| 21 | #include <linux/clkdev.h> |
| 22 | |
| 23 | /** |
| 24 | * struct tegra_clk_sync_source - external clock source from codec |
| 25 | * |
| 26 | * @hw: handle between common and hardware-specific interfaces |
| 27 | * @rate: input frequency from source |
| 28 | * @max_rate: max rate allowed |
| 29 | */ |
| 30 | struct tegra_clk_sync_source { |
| 31 | struct clk_hw hw; |
| 32 | unsigned long rate; |
| 33 | unsigned long max_rate; |
| 34 | }; |
| 35 | |
| 36 | #define to_clk_sync_source(_hw) \ |
| 37 | container_of(_hw, struct tegra_clk_sync_source, hw) |
| 38 | |
| 39 | extern const struct clk_ops tegra_clk_sync_source_ops; |
| 40 | struct clk *tegra_clk_register_sync_source(const char *name, |
| 41 | unsigned long fixed_rate, unsigned long max_rate); |
| 42 | |
| 43 | /** |
| 44 | * struct tegra_clk_frac_div - fractional divider clock |
| 45 | * |
| 46 | * @hw: handle between common and hardware-specific interfaces |
| 47 | * @reg: register containing divider |
| 48 | * @flags: hardware-specific flags |
| 49 | * @shift: shift to the divider bit field |
| 50 | * @width: width of the divider bit field |
| 51 | * @frac_width: width of the fractional bit field |
| 52 | * @lock: register lock |
| 53 | * |
| 54 | * Flags: |
| 55 | * TEGRA_DIVIDER_ROUND_UP - This flags indicates to round up the divider value. |
| 56 | * TEGRA_DIVIDER_FIXED - Fixed rate PLL dividers has addition override bit, this |
| 57 | * flag indicates that this divider is for fixed rate PLL. |
| 58 | * TEGRA_DIVIDER_INT - Some modules can not cope with the duty cycle when |
| 59 | * fraction bit is set. This flags indicates to calculate divider for which |
| 60 | * fracton bit will be zero. |
| 61 | * TEGRA_DIVIDER_UART - UART module divider has additional enable bit which is |
| 62 | * set when divider value is not 0. This flags indicates that the divider |
| 63 | * is for UART module. |
| 64 | */ |
| 65 | struct tegra_clk_frac_div { |
| 66 | struct clk_hw hw; |
| 67 | void __iomem *reg; |
| 68 | u8 flags; |
| 69 | u8 shift; |
| 70 | u8 width; |
| 71 | u8 frac_width; |
| 72 | spinlock_t *lock; |
| 73 | }; |
| 74 | |
| 75 | #define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw) |
| 76 | |
| 77 | #define TEGRA_DIVIDER_ROUND_UP BIT(0) |
| 78 | #define TEGRA_DIVIDER_FIXED BIT(1) |
| 79 | #define TEGRA_DIVIDER_INT BIT(2) |
| 80 | #define TEGRA_DIVIDER_UART BIT(3) |
| 81 | |
| 82 | extern const struct clk_ops tegra_clk_frac_div_ops; |
| 83 | struct clk *tegra_clk_register_divider(const char *name, |
| 84 | const char *parent_name, void __iomem *reg, |
| 85 | unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width, |
| 86 | u8 frac_width, spinlock_t *lock); |
| 87 | |
| 88 | /* |
| 89 | * Tegra PLL: |
| 90 | * |
| 91 | * In general, there are 3 requirements for each PLL |
| 92 | * that SW needs to be comply with. |
| 93 | * (1) Input frequency range (REF). |
| 94 | * (2) Comparison frequency range (CF). CF = REF/DIVM. |
| 95 | * (3) VCO frequency range (VCO). VCO = CF * DIVN. |
| 96 | * |
| 97 | * The final PLL output frequency (FO) = VCO >> DIVP. |
| 98 | */ |
| 99 | |
| 100 | /** |
| 101 | * struct tegra_clk_pll_freq_table - PLL frequecy table |
| 102 | * |
| 103 | * @input_rate: input rate from source |
| 104 | * @output_rate: output rate from PLL for the input rate |
| 105 | * @n: feedback divider |
| 106 | * @m: input divider |
| 107 | * @p: post divider |
| 108 | * @cpcon: charge pump current |
| 109 | */ |
| 110 | struct tegra_clk_pll_freq_table { |
| 111 | unsigned long input_rate; |
| 112 | unsigned long output_rate; |
| 113 | u16 n; |
| 114 | u16 m; |
| 115 | u8 p; |
| 116 | u8 cpcon; |
| 117 | }; |
| 118 | |
| 119 | /** |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 120 | * struct pdiv_map - map post divider to hw value |
| 121 | * |
| 122 | * @pdiv: post divider |
| 123 | * @hw_val: value to be written to the PLL hw |
| 124 | */ |
| 125 | struct pdiv_map { |
| 126 | u8 pdiv; |
| 127 | u8 hw_val; |
| 128 | }; |
| 129 | |
| 130 | /** |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame^] | 131 | * struct div_nmp - offset and width of m,n and p fields |
| 132 | * |
| 133 | * @divn_shift: shift to the feedback divider bit field |
| 134 | * @divn_width: width of the feedback divider bit field |
| 135 | * @divm_shift: shift to the input divider bit field |
| 136 | * @divm_width: width of the input divider bit field |
| 137 | * @divp_shift: shift to the post divider bit field |
| 138 | * @divp_width: width of the post divider bit field |
| 139 | */ |
| 140 | struct div_nmp { |
| 141 | u8 divn_shift; |
| 142 | u8 divn_width; |
| 143 | u8 divm_shift; |
| 144 | u8 divm_width; |
| 145 | u8 divp_shift; |
| 146 | u8 divp_width; |
| 147 | }; |
| 148 | |
| 149 | /** |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 150 | * struct clk_pll_params - PLL parameters |
| 151 | * |
| 152 | * @input_min: Minimum input frequency |
| 153 | * @input_max: Maximum input frequency |
| 154 | * @cf_min: Minimum comparison frequency |
| 155 | * @cf_max: Maximum comparison frequency |
| 156 | * @vco_min: Minimum VCO frequency |
| 157 | * @vco_max: Maximum VCO frequency |
| 158 | * @base_reg: PLL base reg offset |
| 159 | * @misc_reg: PLL misc reg offset |
| 160 | * @lock_reg: PLL lock reg offset |
| 161 | * @lock_bit_idx: Bit index for PLL lock status |
| 162 | * @lock_enable_bit_idx: Bit index to enable PLL lock |
| 163 | * @lock_delay: Delay in us if PLL lock is not used |
| 164 | */ |
| 165 | struct tegra_clk_pll_params { |
| 166 | unsigned long input_min; |
| 167 | unsigned long input_max; |
| 168 | unsigned long cf_min; |
| 169 | unsigned long cf_max; |
| 170 | unsigned long vco_min; |
| 171 | unsigned long vco_max; |
| 172 | |
| 173 | u32 base_reg; |
| 174 | u32 misc_reg; |
| 175 | u32 lock_reg; |
Peter De Schrijver | 3e72771 | 2013-04-03 17:40:40 +0300 | [diff] [blame] | 176 | u32 lock_mask; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 177 | u32 lock_enable_bit_idx; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 178 | u32 iddq_reg; |
| 179 | u32 iddq_bit_idx; |
| 180 | u32 aux_reg; |
| 181 | u32 dyn_ramp_reg; |
| 182 | u32 ext_misc_reg[3]; |
| 183 | int stepa_shift; |
| 184 | int stepb_shift; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 185 | int lock_delay; |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 186 | int max_p; |
| 187 | struct pdiv_map *pdiv_tohw; |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame^] | 188 | struct div_nmp *div_nmp; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | /** |
| 192 | * struct tegra_clk_pll - Tegra PLL clock |
| 193 | * |
| 194 | * @hw: handle between common and hardware-specifix interfaces |
| 195 | * @clk_base: address of CAR controller |
| 196 | * @pmc: address of PMC, required to read override bits |
| 197 | * @freq_table: array of frequencies supported by PLL |
| 198 | * @params: PLL parameters |
| 199 | * @flags: PLL flags |
| 200 | * @fixed_rate: PLL rate if it is fixed |
| 201 | * @lock: register lock |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 202 | * |
| 203 | * Flags: |
| 204 | * TEGRA_PLL_USE_LOCK - This flag indicated to use lock bits for |
| 205 | * PLL locking. If not set it will use lock_delay value to wait. |
| 206 | * TEGRA_PLL_HAS_CPCON - This flag indicates that CPCON value needs |
| 207 | * to be programmed to change output frequency of the PLL. |
| 208 | * TEGRA_PLL_SET_LFCON - This flag indicates that LFCON value needs |
| 209 | * to be programmed to change output frequency of the PLL. |
| 210 | * TEGRA_PLL_SET_DCCON - This flag indicates that DCCON value needs |
| 211 | * to be programmed to change output frequency of the PLL. |
| 212 | * TEGRA_PLLU - PLLU has inverted post divider. This flags indicated |
| 213 | * that it is PLLU and invert post divider value. |
| 214 | * TEGRA_PLLM - PLLM has additional override settings in PMC. This |
| 215 | * flag indicates that it is PLLM and use override settings. |
| 216 | * TEGRA_PLL_FIXED - We are not supposed to change output frequency |
| 217 | * of some plls. |
| 218 | * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling. |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 219 | * TEGRA_PLL_LOCK_MISC - Lock bit is in the misc register instead of the |
| 220 | * base register. |
Peter De Schrijver | dd93587 | 2013-04-03 17:40:37 +0300 | [diff] [blame] | 221 | * TEGRA_PLL_BYPASS - PLL has bypass bit |
Peter De Schrijver | 7ba2881 | 2013-04-03 17:40:38 +0300 | [diff] [blame] | 222 | * TEGRA_PLL_HAS_LOCK_ENABLE - PLL has bit to enable lock monitoring |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 223 | */ |
| 224 | struct tegra_clk_pll { |
| 225 | struct clk_hw hw; |
| 226 | void __iomem *clk_base; |
| 227 | void __iomem *pmc; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 228 | u32 flags; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 229 | unsigned long fixed_rate; |
| 230 | spinlock_t *lock; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 231 | struct tegra_clk_pll_freq_table *freq_table; |
| 232 | struct tegra_clk_pll_params *params; |
| 233 | }; |
| 234 | |
| 235 | #define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw) |
| 236 | |
| 237 | #define TEGRA_PLL_USE_LOCK BIT(0) |
| 238 | #define TEGRA_PLL_HAS_CPCON BIT(1) |
| 239 | #define TEGRA_PLL_SET_LFCON BIT(2) |
| 240 | #define TEGRA_PLL_SET_DCCON BIT(3) |
| 241 | #define TEGRA_PLLU BIT(4) |
| 242 | #define TEGRA_PLLM BIT(5) |
| 243 | #define TEGRA_PLL_FIXED BIT(6) |
| 244 | #define TEGRA_PLLE_CONFIGURE BIT(7) |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 245 | #define TEGRA_PLL_LOCK_MISC BIT(8) |
Peter De Schrijver | dd93587 | 2013-04-03 17:40:37 +0300 | [diff] [blame] | 246 | #define TEGRA_PLL_BYPASS BIT(9) |
Peter De Schrijver | 7ba2881 | 2013-04-03 17:40:38 +0300 | [diff] [blame] | 247 | #define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 248 | |
| 249 | extern const struct clk_ops tegra_clk_pll_ops; |
| 250 | extern const struct clk_ops tegra_clk_plle_ops; |
| 251 | struct clk *tegra_clk_register_pll(const char *name, const char *parent_name, |
| 252 | void __iomem *clk_base, void __iomem *pmc, |
| 253 | unsigned long flags, unsigned long fixed_rate, |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 254 | struct tegra_clk_pll_params *pll_params, u32 pll_flags, |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 255 | struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 256 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 257 | struct clk *tegra_clk_register_plle(const char *name, const char *parent_name, |
| 258 | void __iomem *clk_base, void __iomem *pmc, |
| 259 | unsigned long flags, unsigned long fixed_rate, |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 260 | struct tegra_clk_pll_params *pll_params, u32 pll_flags, |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 261 | struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock); |
| 262 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 263 | struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name, |
| 264 | void __iomem *clk_base, void __iomem *pmc, |
| 265 | unsigned long flags, unsigned long fixed_rate, |
| 266 | struct tegra_clk_pll_params *pll_params, |
| 267 | u32 pll_flags, |
| 268 | struct tegra_clk_pll_freq_table *freq_table, |
| 269 | spinlock_t *lock); |
| 270 | |
| 271 | struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name, |
| 272 | void __iomem *clk_base, void __iomem *pmc, |
| 273 | unsigned long flags, unsigned long fixed_rate, |
| 274 | struct tegra_clk_pll_params *pll_params, |
| 275 | u32 pll_flags, |
| 276 | struct tegra_clk_pll_freq_table *freq_table, |
| 277 | spinlock_t *lock); |
| 278 | |
| 279 | struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name, |
| 280 | void __iomem *clk_base, void __iomem *pmc, |
| 281 | unsigned long flags, unsigned long fixed_rate, |
| 282 | struct tegra_clk_pll_params *pll_params, |
| 283 | u32 pll_flags, |
| 284 | struct tegra_clk_pll_freq_table *freq_table, |
| 285 | spinlock_t *lock); |
| 286 | |
| 287 | struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name, |
| 288 | void __iomem *clk_base, void __iomem *pmc, |
| 289 | unsigned long flags, unsigned long fixed_rate, |
| 290 | struct tegra_clk_pll_params *pll_params, |
| 291 | u32 pll_flags, |
| 292 | struct tegra_clk_pll_freq_table *freq_table, |
| 293 | spinlock_t *lock, unsigned long parent_rate); |
| 294 | |
| 295 | struct clk *tegra_clk_register_plle_tegra114(const char *name, |
| 296 | const char *parent_name, |
| 297 | void __iomem *clk_base, unsigned long flags, |
| 298 | unsigned long fixed_rate, |
| 299 | struct tegra_clk_pll_params *pll_params, |
| 300 | struct tegra_clk_pll_freq_table *freq_table, |
| 301 | spinlock_t *lock); |
| 302 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 303 | /** |
| 304 | * struct tegra_clk_pll_out - PLL divider down clock |
| 305 | * |
| 306 | * @hw: handle between common and hardware-specific interfaces |
| 307 | * @reg: register containing the PLL divider |
| 308 | * @enb_bit_idx: bit to enable/disable PLL divider |
| 309 | * @rst_bit_idx: bit to reset PLL divider |
| 310 | * @lock: register lock |
| 311 | * @flags: hardware-specific flags |
| 312 | */ |
| 313 | struct tegra_clk_pll_out { |
| 314 | struct clk_hw hw; |
| 315 | void __iomem *reg; |
| 316 | u8 enb_bit_idx; |
| 317 | u8 rst_bit_idx; |
| 318 | spinlock_t *lock; |
| 319 | u8 flags; |
| 320 | }; |
| 321 | |
| 322 | #define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw) |
| 323 | |
| 324 | extern const struct clk_ops tegra_clk_pll_out_ops; |
| 325 | struct clk *tegra_clk_register_pll_out(const char *name, |
| 326 | const char *parent_name, void __iomem *reg, u8 enb_bit_idx, |
| 327 | u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags, |
| 328 | spinlock_t *lock); |
| 329 | |
| 330 | /** |
| 331 | * struct tegra_clk_periph_regs - Registers controlling peripheral clock |
| 332 | * |
| 333 | * @enb_reg: read the enable status |
| 334 | * @enb_set_reg: write 1 to enable clock |
| 335 | * @enb_clr_reg: write 1 to disable clock |
| 336 | * @rst_reg: read the reset status |
| 337 | * @rst_set_reg: write 1 to assert the reset of peripheral |
| 338 | * @rst_clr_reg: write 1 to deassert the reset of peripheral |
| 339 | */ |
| 340 | struct tegra_clk_periph_regs { |
| 341 | u32 enb_reg; |
| 342 | u32 enb_set_reg; |
| 343 | u32 enb_clr_reg; |
| 344 | u32 rst_reg; |
| 345 | u32 rst_set_reg; |
| 346 | u32 rst_clr_reg; |
| 347 | }; |
| 348 | |
| 349 | /** |
| 350 | * struct tegra_clk_periph_gate - peripheral gate clock |
| 351 | * |
| 352 | * @magic: magic number to validate type |
| 353 | * @hw: handle between common and hardware-specific interfaces |
| 354 | * @clk_base: address of CAR controller |
| 355 | * @regs: Registers to control the peripheral |
| 356 | * @flags: hardware-specific flags |
| 357 | * @clk_num: Clock number |
| 358 | * @enable_refcnt: array to maintain reference count of the clock |
| 359 | * |
| 360 | * Flags: |
| 361 | * TEGRA_PERIPH_NO_RESET - This flag indicates that reset is not allowed |
| 362 | * for this module. |
| 363 | * TEGRA_PERIPH_MANUAL_RESET - This flag indicates not to reset module |
| 364 | * after clock enable and driver for the module is responsible for |
| 365 | * doing reset. |
| 366 | * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the |
| 367 | * bus to flush the write operation in apb bus. This flag indicates |
| 368 | * that this peripheral is in apb bus. |
Peter De Schrijver | fdcccbd | 2013-04-03 17:40:44 +0300 | [diff] [blame] | 369 | * TEGRA_PERIPH_WAR_1005168 - Apply workaround for Tegra114 MSENC bug |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 370 | */ |
| 371 | struct tegra_clk_periph_gate { |
| 372 | u32 magic; |
| 373 | struct clk_hw hw; |
| 374 | void __iomem *clk_base; |
| 375 | u8 flags; |
| 376 | int clk_num; |
| 377 | int *enable_refcnt; |
| 378 | struct tegra_clk_periph_regs *regs; |
| 379 | }; |
| 380 | |
| 381 | #define to_clk_periph_gate(_hw) \ |
| 382 | container_of(_hw, struct tegra_clk_periph_gate, hw) |
| 383 | |
| 384 | #define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309 |
| 385 | |
| 386 | #define TEGRA_PERIPH_NO_RESET BIT(0) |
| 387 | #define TEGRA_PERIPH_MANUAL_RESET BIT(1) |
| 388 | #define TEGRA_PERIPH_ON_APB BIT(2) |
Peter De Schrijver | fdcccbd | 2013-04-03 17:40:44 +0300 | [diff] [blame] | 389 | #define TEGRA_PERIPH_WAR_1005168 BIT(3) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 390 | |
| 391 | void tegra_periph_reset(struct tegra_clk_periph_gate *gate, bool assert); |
| 392 | extern const struct clk_ops tegra_clk_periph_gate_ops; |
| 393 | struct clk *tegra_clk_register_periph_gate(const char *name, |
| 394 | const char *parent_name, u8 gate_flags, void __iomem *clk_base, |
| 395 | unsigned long flags, int clk_num, |
| 396 | struct tegra_clk_periph_regs *pregs, int *enable_refcnt); |
| 397 | |
| 398 | /** |
| 399 | * struct clk-periph - peripheral clock |
| 400 | * |
| 401 | * @magic: magic number to validate type |
| 402 | * @hw: handle between common and hardware-specific interfaces |
| 403 | * @mux: mux clock |
| 404 | * @divider: divider clock |
| 405 | * @gate: gate clock |
| 406 | * @mux_ops: mux clock ops |
| 407 | * @div_ops: divider clock ops |
| 408 | * @gate_ops: gate clock ops |
| 409 | */ |
| 410 | struct tegra_clk_periph { |
| 411 | u32 magic; |
| 412 | struct clk_hw hw; |
| 413 | struct clk_mux mux; |
| 414 | struct tegra_clk_frac_div divider; |
| 415 | struct tegra_clk_periph_gate gate; |
| 416 | |
| 417 | const struct clk_ops *mux_ops; |
| 418 | const struct clk_ops *div_ops; |
| 419 | const struct clk_ops *gate_ops; |
| 420 | }; |
| 421 | |
| 422 | #define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw) |
| 423 | |
| 424 | #define TEGRA_CLK_PERIPH_MAGIC 0x18221223 |
| 425 | |
| 426 | extern const struct clk_ops tegra_clk_periph_ops; |
| 427 | struct clk *tegra_clk_register_periph(const char *name, |
| 428 | const char **parent_names, int num_parents, |
| 429 | struct tegra_clk_periph *periph, void __iomem *clk_base, |
Peter De Schrijver | a26a029 | 2013-04-03 17:40:42 +0300 | [diff] [blame] | 430 | u32 offset, unsigned long flags); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 431 | struct clk *tegra_clk_register_periph_nodiv(const char *name, |
| 432 | const char **parent_names, int num_parents, |
| 433 | struct tegra_clk_periph *periph, void __iomem *clk_base, |
| 434 | u32 offset); |
| 435 | |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 436 | #define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags, \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 437 | _div_shift, _div_width, _div_frac_width, \ |
| 438 | _div_flags, _clk_num, _enb_refcnt, _regs, \ |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 439 | _gate_flags, _table) \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 440 | { \ |
| 441 | .mux = { \ |
| 442 | .flags = _mux_flags, \ |
| 443 | .shift = _mux_shift, \ |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 444 | .mask = _mux_mask, \ |
| 445 | .table = _table, \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 446 | }, \ |
| 447 | .divider = { \ |
| 448 | .flags = _div_flags, \ |
| 449 | .shift = _div_shift, \ |
| 450 | .width = _div_width, \ |
| 451 | .frac_width = _div_frac_width, \ |
| 452 | }, \ |
| 453 | .gate = { \ |
| 454 | .flags = _gate_flags, \ |
| 455 | .clk_num = _clk_num, \ |
| 456 | .enable_refcnt = _enb_refcnt, \ |
| 457 | .regs = _regs, \ |
| 458 | }, \ |
| 459 | .mux_ops = &clk_mux_ops, \ |
| 460 | .div_ops = &tegra_clk_frac_div_ops, \ |
| 461 | .gate_ops = &tegra_clk_periph_gate_ops, \ |
| 462 | } |
| 463 | |
| 464 | struct tegra_periph_init_data { |
| 465 | const char *name; |
| 466 | int clk_id; |
| 467 | const char **parent_names; |
| 468 | int num_parents; |
| 469 | struct tegra_clk_periph periph; |
| 470 | u32 offset; |
| 471 | const char *con_id; |
| 472 | const char *dev_id; |
Peter De Schrijver | a26a029 | 2013-04-03 17:40:42 +0300 | [diff] [blame] | 473 | unsigned long flags; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 474 | }; |
| 475 | |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 476 | #define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\ |
| 477 | _mux_shift, _mux_mask, _mux_flags, _div_shift, \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 478 | _div_width, _div_frac_width, _div_flags, _regs, \ |
Peter De Schrijver | a26a029 | 2013-04-03 17:40:42 +0300 | [diff] [blame] | 479 | _clk_num, _enb_refcnt, _gate_flags, _clk_id, _table,\ |
| 480 | _flags) \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 481 | { \ |
| 482 | .name = _name, \ |
| 483 | .clk_id = _clk_id, \ |
| 484 | .parent_names = _parent_names, \ |
| 485 | .num_parents = ARRAY_SIZE(_parent_names), \ |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 486 | .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 487 | _mux_flags, _div_shift, \ |
| 488 | _div_width, _div_frac_width, \ |
| 489 | _div_flags, _clk_num, \ |
| 490 | _enb_refcnt, _regs, \ |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 491 | _gate_flags, _table), \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 492 | .offset = _offset, \ |
| 493 | .con_id = _con_id, \ |
| 494 | .dev_id = _dev_id, \ |
Peter De Schrijver | a26a029 | 2013-04-03 17:40:42 +0300 | [diff] [blame] | 495 | .flags = _flags \ |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 496 | } |
| 497 | |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 498 | #define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\ |
| 499 | _mux_shift, _mux_width, _mux_flags, _div_shift, \ |
| 500 | _div_width, _div_frac_width, _div_flags, _regs, \ |
| 501 | _clk_num, _enb_refcnt, _gate_flags, _clk_id) \ |
| 502 | TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\ |
| 503 | _mux_shift, BIT(_mux_width) - 1, _mux_flags, \ |
| 504 | _div_shift, _div_width, _div_frac_width, _div_flags, \ |
| 505 | _regs, _clk_num, _enb_refcnt, _gate_flags, _clk_id,\ |
Peter De Schrijver | a26a029 | 2013-04-03 17:40:42 +0300 | [diff] [blame] | 506 | NULL, 0) |
Peter De Schrijver | ce4f331 | 2013-03-22 14:07:53 +0200 | [diff] [blame] | 507 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 508 | /** |
| 509 | * struct clk_super_mux - super clock |
| 510 | * |
| 511 | * @hw: handle between common and hardware-specific interfaces |
| 512 | * @reg: register controlling multiplexer |
| 513 | * @width: width of the multiplexer bit field |
| 514 | * @flags: hardware-specific flags |
| 515 | * @div2_index: bit controlling divide-by-2 |
| 516 | * @pllx_index: PLLX index in the parent list |
| 517 | * @lock: register lock |
| 518 | * |
| 519 | * Flags: |
| 520 | * TEGRA_DIVIDER_2 - LP cluster has additional divider. This flag indicates |
| 521 | * that this is LP cluster clock. |
| 522 | */ |
| 523 | struct tegra_clk_super_mux { |
| 524 | struct clk_hw hw; |
| 525 | void __iomem *reg; |
| 526 | u8 width; |
| 527 | u8 flags; |
| 528 | u8 div2_index; |
| 529 | u8 pllx_index; |
| 530 | spinlock_t *lock; |
| 531 | }; |
| 532 | |
| 533 | #define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw) |
| 534 | |
| 535 | #define TEGRA_DIVIDER_2 BIT(0) |
| 536 | |
| 537 | extern const struct clk_ops tegra_clk_super_ops; |
| 538 | struct clk *tegra_clk_register_super_mux(const char *name, |
| 539 | const char **parent_names, u8 num_parents, |
| 540 | unsigned long flags, void __iomem *reg, u8 clk_super_flags, |
| 541 | u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock); |
| 542 | |
| 543 | /** |
| 544 | * struct clk_init_tabel - clock initialization table |
| 545 | * @clk_id: clock id as mentioned in device tree bindings |
| 546 | * @parent_id: parent clock id as mentioned in device tree bindings |
| 547 | * @rate: rate to set |
| 548 | * @state: enable/disable |
| 549 | */ |
| 550 | struct tegra_clk_init_table { |
| 551 | unsigned int clk_id; |
| 552 | unsigned int parent_id; |
| 553 | unsigned long rate; |
| 554 | int state; |
| 555 | }; |
| 556 | |
| 557 | /** |
| 558 | * struct clk_duplicate - duplicate clocks |
| 559 | * @clk_id: clock id as mentioned in device tree bindings |
| 560 | * @lookup: duplicate lookup entry for the clock |
| 561 | */ |
| 562 | struct tegra_clk_duplicate { |
| 563 | int clk_id; |
| 564 | struct clk_lookup lookup; |
| 565 | }; |
| 566 | |
| 567 | #define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \ |
| 568 | { \ |
| 569 | .clk_id = _clk_id, \ |
| 570 | .lookup = { \ |
| 571 | .dev_id = _dev, \ |
| 572 | .con_id = _con, \ |
| 573 | }, \ |
| 574 | } |
| 575 | |
| 576 | void tegra_init_from_table(struct tegra_clk_init_table *tbl, |
| 577 | struct clk *clks[], int clk_max); |
| 578 | |
| 579 | void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list, |
| 580 | struct clk *clks[], int clk_max); |
| 581 | |
Stephen Warren | 441f199 | 2013-03-25 13:22:24 -0600 | [diff] [blame] | 582 | typedef void (*tegra_clk_apply_init_table_func)(void); |
| 583 | extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table; |
| 584 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 585 | #endif /* TEGRA_CLK_H */ |