Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002     /*
0003  * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
0004  */
0005 
0006 #ifndef __TEGRA_CLK_H
0007 #define __TEGRA_CLK_H
0008 
0009 #include <linux/clk-provider.h>
0010 #include <linux/clkdev.h>
0011 #include <linux/delay.h>
0012 
0013 #define CLK_OUT_ENB_L           0x010
0014 #define CLK_OUT_ENB_H           0x014
0015 #define CLK_OUT_ENB_U           0x018
0016 #define CLK_OUT_ENB_V           0x360
0017 #define CLK_OUT_ENB_W           0x364
0018 #define CLK_OUT_ENB_X           0x280
0019 #define CLK_OUT_ENB_Y           0x298
0020 #define CLK_ENB_PLLP_OUT_CPU        BIT(31)
0021 #define CLK_OUT_ENB_SET_L       0x320
0022 #define CLK_OUT_ENB_CLR_L       0x324
0023 #define CLK_OUT_ENB_SET_H       0x328
0024 #define CLK_OUT_ENB_CLR_H       0x32c
0025 #define CLK_OUT_ENB_SET_U       0x330
0026 #define CLK_OUT_ENB_CLR_U       0x334
0027 #define CLK_OUT_ENB_SET_V       0x440
0028 #define CLK_OUT_ENB_CLR_V       0x444
0029 #define CLK_OUT_ENB_SET_W       0x448
0030 #define CLK_OUT_ENB_CLR_W       0x44c
0031 #define CLK_OUT_ENB_SET_X       0x284
0032 #define CLK_OUT_ENB_CLR_X       0x288
0033 #define CLK_OUT_ENB_SET_Y       0x29c
0034 #define CLK_OUT_ENB_CLR_Y       0x2a0
0035 
0036 #define RST_DEVICES_L           0x004
0037 #define RST_DEVICES_H           0x008
0038 #define RST_DEVICES_U           0x00C
0039 #define RST_DEVICES_V           0x358
0040 #define RST_DEVICES_W           0x35C
0041 #define RST_DEVICES_X           0x28C
0042 #define RST_DEVICES_Y           0x2a4
0043 #define RST_DEVICES_SET_L       0x300
0044 #define RST_DEVICES_CLR_L       0x304
0045 #define RST_DEVICES_SET_H       0x308
0046 #define RST_DEVICES_CLR_H       0x30c
0047 #define RST_DEVICES_SET_U       0x310
0048 #define RST_DEVICES_CLR_U       0x314
0049 #define RST_DEVICES_SET_V       0x430
0050 #define RST_DEVICES_CLR_V       0x434
0051 #define RST_DEVICES_SET_W       0x438
0052 #define RST_DEVICES_CLR_W       0x43c
0053 #define RST_DEVICES_SET_X       0x290
0054 #define RST_DEVICES_CLR_X       0x294
0055 #define RST_DEVICES_SET_Y       0x2a8
0056 #define RST_DEVICES_CLR_Y       0x2ac
0057 
0058 /*
0059  * Tegra CLK_OUT_ENB registers have some undefined bits which are not used and
0060  * any accidental write of 1 to these bits can cause PSLVERR.
0061  * So below are the valid mask defines for each CLK_OUT_ENB register used to
0062  * turn ON only the valid clocks.
0063  */
0064 #define TEGRA210_CLK_ENB_VLD_MSK_L  0xdcd7dff9
0065 #define TEGRA210_CLK_ENB_VLD_MSK_H  0x87d1f3e7
0066 #define TEGRA210_CLK_ENB_VLD_MSK_U  0xf3fed3fa
0067 #define TEGRA210_CLK_ENB_VLD_MSK_V  0xffc18cfb
0068 #define TEGRA210_CLK_ENB_VLD_MSK_W  0x793fb7ff
0069 #define TEGRA210_CLK_ENB_VLD_MSK_X  0x3fe66fff
0070 #define TEGRA210_CLK_ENB_VLD_MSK_Y  0xfc1fc7ff
0071 
0072 /**
0073  * struct tegra_clk_sync_source - external clock source from codec
0074  *
0075  * @hw: handle between common and hardware-specific interfaces
0076  * @rate: input frequency from source
0077  * @max_rate: max rate allowed
0078  */
0079 struct tegra_clk_sync_source {
0080     struct      clk_hw hw;
0081     unsigned long   rate;
0082     unsigned long   max_rate;
0083 };
0084 
0085 #define to_clk_sync_source(_hw)                 \
0086     container_of(_hw, struct tegra_clk_sync_source, hw)
0087 
0088 extern const struct clk_ops tegra_clk_sync_source_ops;
0089 extern int *periph_clk_enb_refcnt;
0090 
0091 struct clk *tegra_clk_register_sync_source(const char *name,
0092                        unsigned long max_rate);
0093 
0094 /**
0095  * struct tegra_clk_frac_div - fractional divider clock
0096  *
0097  * @hw:     handle between common and hardware-specific interfaces
0098  * @reg:    register containing divider
0099  * @flags:  hardware-specific flags
0100  * @shift:  shift to the divider bit field
0101  * @width:  width of the divider bit field
0102  * @frac_width: width of the fractional bit field
0103  * @lock:   register lock
0104  *
0105  * Flags:
0106  * TEGRA_DIVIDER_ROUND_UP - This flags indicates to round up the divider value.
0107  * TEGRA_DIVIDER_FIXED - Fixed rate PLL dividers has addition override bit, this
0108  *      flag indicates that this divider is for fixed rate PLL.
0109  * TEGRA_DIVIDER_INT - Some modules can not cope with the duty cycle when
0110  *      fraction bit is set. This flags indicates to calculate divider for which
0111  *      fracton bit will be zero.
0112  * TEGRA_DIVIDER_UART - UART module divider has additional enable bit which is
0113  *      set when divider value is not 0. This flags indicates that the divider
0114  *      is for UART module.
0115  */
0116 struct tegra_clk_frac_div {
0117     struct clk_hw   hw;
0118     void __iomem    *reg;
0119     u8      flags;
0120     u8      shift;
0121     u8      width;
0122     u8      frac_width;
0123     spinlock_t  *lock;
0124 };
0125 
0126 #define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
0127 
0128 #define TEGRA_DIVIDER_ROUND_UP BIT(0)
0129 #define TEGRA_DIVIDER_FIXED BIT(1)
0130 #define TEGRA_DIVIDER_INT BIT(2)
0131 #define TEGRA_DIVIDER_UART BIT(3)
0132 
0133 extern const struct clk_ops tegra_clk_frac_div_ops;
0134 struct clk *tegra_clk_register_divider(const char *name,
0135         const char *parent_name, void __iomem *reg,
0136         unsigned long flags, u8 clk_divider_flags, u8 shift, u8 width,
0137         u8 frac_width, spinlock_t *lock);
0138 struct clk *tegra_clk_register_mc(const char *name, const char *parent_name,
0139                   void __iomem *reg, spinlock_t *lock);
0140 
0141 /*
0142  * Tegra PLL:
0143  *
0144  * In general, there are 3 requirements for each PLL
0145  * that SW needs to be comply with.
0146  * (1) Input frequency range (REF).
0147  * (2) Comparison frequency range (CF). CF = REF/DIVM.
0148  * (3) VCO frequency range (VCO).  VCO = CF * DIVN.
0149  *
0150  * The final PLL output frequency (FO) = VCO >> DIVP.
0151  */
0152 
0153 /**
0154  * struct tegra_clk_pll_freq_table - PLL frequecy table
0155  *
0156  * @input_rate:     input rate from source
0157  * @output_rate:    output rate from PLL for the input rate
0158  * @n:          feedback divider
0159  * @m:          input divider
0160  * @p:          post divider
0161  * @cpcon:      charge pump current
0162  * @sdm_data:       fraction divider setting (0 = disabled)
0163  */
0164 struct tegra_clk_pll_freq_table {
0165     unsigned long   input_rate;
0166     unsigned long   output_rate;
0167     u32     n;
0168     u32     m;
0169     u8      p;
0170     u8      cpcon;
0171     u16     sdm_data;
0172 };
0173 
0174 /**
0175  * struct pdiv_map - map post divider to hw value
0176  *
0177  * @pdiv:       post divider
0178  * @hw_val:     value to be written to the PLL hw
0179  */
0180 struct pdiv_map {
0181     u8 pdiv;
0182     u8 hw_val;
0183 };
0184 
0185 /**
0186  * struct div_nmp - offset and width of m,n and p fields
0187  *
0188  * @divn_shift: shift to the feedback divider bit field
0189  * @divn_width: width of the feedback divider bit field
0190  * @divm_shift: shift to the input divider bit field
0191  * @divm_width: width of the input divider bit field
0192  * @divp_shift: shift to the post divider bit field
0193  * @divp_width: width of the post divider bit field
0194  * @override_divn_shift: shift to the feedback divider bitfield in override reg
0195  * @override_divm_shift: shift to the input divider bitfield in override reg
0196  * @override_divp_shift: shift to the post divider bitfield in override reg
0197  */
0198 struct div_nmp {
0199     u8      divn_shift;
0200     u8      divn_width;
0201     u8      divm_shift;
0202     u8      divm_width;
0203     u8      divp_shift;
0204     u8      divp_width;
0205     u8      override_divn_shift;
0206     u8      override_divm_shift;
0207     u8      override_divp_shift;
0208 };
0209 
0210 #define MAX_PLL_MISC_REG_COUNT  6
0211 
0212 struct tegra_clk_pll;
0213 
0214 /**
0215  * struct tegra_clk_pll_params - PLL parameters
0216  *
0217  * @input_min:          Minimum input frequency
0218  * @input_max:          Maximum input frequency
0219  * @cf_min:         Minimum comparison frequency
0220  * @cf_max:         Maximum comparison frequency
0221  * @vco_min:            Minimum VCO frequency
0222  * @vco_max:            Maximum VCO frequency
0223  * @base_reg:           PLL base reg offset
0224  * @misc_reg:           PLL misc reg offset
0225  * @lock_reg:           PLL lock reg offset
0226  * @lock_mask:          Bitmask for PLL lock status
0227  * @lock_enable_bit_idx:    Bit index to enable PLL lock
0228  * @iddq_reg:           PLL IDDQ register offset
0229  * @iddq_bit_idx:       Bit index to enable PLL IDDQ
0230  * @reset_reg:          Register offset of where RESET bit is
0231  * @reset_bit_idx:      Shift of reset bit in reset_reg
0232  * @sdm_din_reg:        Register offset where SDM settings are
0233  * @sdm_din_mask:       Mask of SDM divider bits
0234  * @sdm_ctrl_reg:       Register offset where SDM enable is
0235  * @sdm_ctrl_en_mask:       Mask of SDM enable bit
0236  * @ssc_ctrl_reg:       Register offset where SSC settings are
0237  * @ssc_ctrl_en_mask:       Mask of SSC enable bit
0238  * @aux_reg:            AUX register offset
0239  * @dyn_ramp_reg:       Dynamic ramp control register offset
0240  * @ext_misc_reg:       Miscellaneous control register offsets
0241  * @pmc_divnm_reg:      n, m divider PMC override register offset (PLLM)
0242  * @pmc_divp_reg:       p divider PMC override register offset (PLLM)
0243  * @flags:          PLL flags
0244  * @stepa_shift:        Dynamic ramp step A field shift
0245  * @stepb_shift:        Dynamic ramp step B field shift
0246  * @lock_delay:         Delay in us if PLL lock is not used
0247  * @max_p:          maximum value for the p divider
0248  * @defaults_set:       Boolean signaling all reg defaults for PLL set.
0249  * @pdiv_tohw:          mapping of p divider to register values
0250  * @div_nmp:            offsets and widths on n, m and p fields
0251  * @freq_table:         array of frequencies supported by PLL
0252  * @fixed_rate:         PLL rate if it is fixed
0253  * @mdiv_default:       Default value for fixed mdiv for this PLL
0254  * @round_p_to_pdiv:        Callback used to round p to the closed pdiv
0255  * @set_gain:           Callback to adjust N div for SDM enabled
0256  *              PLL's based on fractional divider value.
0257  * @calc_rate:          Callback used to change how out of table
0258  *              rates (dividers and multipler) are calculated.
0259  * @adjust_vco:         Callback to adjust the programming range of the
0260  *              divider range (if SDM is present)
0261  * @set_defaults:       Callback which will try to initialize PLL
0262  *              registers to sane default values. This is first
0263  *              tried during PLL registration, but if the PLL
0264  *              is already enabled, it will be done the first
0265  *              time the rate is changed while the PLL is
0266  *              disabled.
0267  * @dyn_ramp:           Callback which can be used to define a custom
0268  *              dynamic ramp function for a given PLL.
0269  * @pre_rate_change:        Callback which is invoked just before changing
0270  *              PLL's rate.
0271  * @post_rate_change:       Callback which is invoked right after changing
0272  *              PLL's rate.
0273  *
0274  * Flags:
0275  * TEGRA_PLL_USE_LOCK - This flag indicated to use lock bits for
0276  *     PLL locking. If not set it will use lock_delay value to wait.
0277  * TEGRA_PLL_HAS_CPCON - This flag indicates that CPCON value needs
0278  *     to be programmed to change output frequency of the PLL.
0279  * TEGRA_PLL_SET_LFCON - This flag indicates that LFCON value needs
0280  *     to be programmed to change output frequency of the PLL.
0281  * TEGRA_PLL_SET_DCCON - This flag indicates that DCCON value needs
0282  *     to be programmed to change output frequency of the PLL.
0283  * TEGRA_PLLU - PLLU has inverted post divider. This flags indicated
0284  *     that it is PLLU and invert post divider value.
0285  * TEGRA_PLLM - PLLM has additional override settings in PMC. This
0286  *     flag indicates that it is PLLM and use override settings.
0287  * TEGRA_PLL_FIXED - We are not supposed to change output frequency
0288  *     of some plls.
0289  * TEGRA_PLLE_CONFIGURE - Configure PLLE when enabling.
0290  * TEGRA_PLL_LOCK_MISC - Lock bit is in the misc register instead of the
0291  *     base register.
0292  * TEGRA_PLL_BYPASS - PLL has bypass bit
0293  * TEGRA_PLL_HAS_LOCK_ENABLE - PLL has bit to enable lock monitoring
0294  * TEGRA_MDIV_NEW - Switch to new method for calculating fixed mdiv
0295  *     it may be more accurate (especially if SDM present)
0296  * TEGRA_PLLMB - PLLMB has should be treated similar to PLLM. This
0297  *     flag indicated that it is PLLMB.
0298  * TEGRA_PLL_VCO_OUT - Used to indicate that the PLL has a VCO output
0299  */
0300 struct tegra_clk_pll_params {
0301     unsigned long   input_min;
0302     unsigned long   input_max;
0303     unsigned long   cf_min;
0304     unsigned long   cf_max;
0305     unsigned long   vco_min;
0306     unsigned long   vco_max;
0307 
0308     u32     base_reg;
0309     u32     misc_reg;
0310     u32     lock_reg;
0311     u32     lock_mask;
0312     u32     lock_enable_bit_idx;
0313     u32     iddq_reg;
0314     u32     iddq_bit_idx;
0315     u32     reset_reg;
0316     u32     reset_bit_idx;
0317     u32     sdm_din_reg;
0318     u32     sdm_din_mask;
0319     u32     sdm_ctrl_reg;
0320     u32     sdm_ctrl_en_mask;
0321     u32     ssc_ctrl_reg;
0322     u32     ssc_ctrl_en_mask;
0323     u32     aux_reg;
0324     u32     dyn_ramp_reg;
0325     u32     ext_misc_reg[MAX_PLL_MISC_REG_COUNT];
0326     u32     pmc_divnm_reg;
0327     u32     pmc_divp_reg;
0328     u32     flags;
0329     int     stepa_shift;
0330     int     stepb_shift;
0331     int     lock_delay;
0332     int     max_p;
0333     bool        defaults_set;
0334     const struct pdiv_map *pdiv_tohw;
0335     struct div_nmp  *div_nmp;
0336     struct tegra_clk_pll_freq_table *freq_table;
0337     unsigned long   fixed_rate;
0338     u16     mdiv_default;
0339     u32 (*round_p_to_pdiv)(u32 p, u32 *pdiv);
0340     void    (*set_gain)(struct tegra_clk_pll_freq_table *cfg);
0341     int (*calc_rate)(struct clk_hw *hw,
0342             struct tegra_clk_pll_freq_table *cfg,
0343             unsigned long rate, unsigned long parent_rate);
0344     unsigned long   (*adjust_vco)(struct tegra_clk_pll_params *pll_params,
0345                 unsigned long parent_rate);
0346     void    (*set_defaults)(struct tegra_clk_pll *pll);
0347     int (*dyn_ramp)(struct tegra_clk_pll *pll,
0348             struct tegra_clk_pll_freq_table *cfg);
0349     int (*pre_rate_change)(void);
0350     void    (*post_rate_change)(void);
0351 };
0352 
0353 #define TEGRA_PLL_USE_LOCK BIT(0)
0354 #define TEGRA_PLL_HAS_CPCON BIT(1)
0355 #define TEGRA_PLL_SET_LFCON BIT(2)
0356 #define TEGRA_PLL_SET_DCCON BIT(3)
0357 #define TEGRA_PLLU BIT(4)
0358 #define TEGRA_PLLM BIT(5)
0359 #define TEGRA_PLL_FIXED BIT(6)
0360 #define TEGRA_PLLE_CONFIGURE BIT(7)
0361 #define TEGRA_PLL_LOCK_MISC BIT(8)
0362 #define TEGRA_PLL_BYPASS BIT(9)
0363 #define TEGRA_PLL_HAS_LOCK_ENABLE BIT(10)
0364 #define TEGRA_MDIV_NEW BIT(11)
0365 #define TEGRA_PLLMB BIT(12)
0366 #define TEGRA_PLL_VCO_OUT BIT(13)
0367 
0368 /**
0369  * struct tegra_clk_pll - Tegra PLL clock
0370  *
0371  * @hw:     handle between common and hardware-specifix interfaces
0372  * @clk_base:   address of CAR controller
0373  * @pmc:    address of PMC, required to read override bits
0374  * @lock:   register lock
0375  * @params: PLL parameters
0376  */
0377 struct tegra_clk_pll {
0378     struct clk_hw   hw;
0379     void __iomem    *clk_base;
0380     void __iomem    *pmc;
0381     spinlock_t  *lock;
0382     struct tegra_clk_pll_params *params;
0383 };
0384 
0385 #define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
0386 
0387 /**
0388  * struct tegra_audio_clk_info - Tegra Audio Clk Information
0389  *
0390  * @name:   name for the audio pll
0391  * @pll_params: pll_params for audio pll
0392  * @clk_id: clk_ids for the audio pll
0393  * @parent: name of the parent of the audio pll
0394  */
0395 struct tegra_audio_clk_info {
0396     char *name;
0397     struct tegra_clk_pll_params *pll_params;
0398     int clk_id;
0399     char *parent;
0400 };
0401 
0402 extern const struct clk_ops tegra_clk_pll_ops;
0403 extern const struct clk_ops tegra_clk_plle_ops;
0404 struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
0405         void __iomem *clk_base, void __iomem *pmc,
0406         unsigned long flags, struct tegra_clk_pll_params *pll_params,
0407         spinlock_t *lock);
0408 
0409 struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
0410         void __iomem *clk_base, void __iomem *pmc,
0411         unsigned long flags, struct tegra_clk_pll_params *pll_params,
0412         spinlock_t *lock);
0413 
0414 struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
0415                 void __iomem *clk_base, void __iomem *pmc,
0416                 unsigned long flags,
0417                 struct tegra_clk_pll_params *pll_params,
0418                 spinlock_t *lock);
0419 
0420 struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
0421                void __iomem *clk_base, void __iomem *pmc,
0422                unsigned long flags,
0423                struct tegra_clk_pll_params *pll_params,
0424                spinlock_t *lock);
0425 
0426 struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
0427                void __iomem *clk_base, void __iomem *pmc,
0428                unsigned long flags,
0429                struct tegra_clk_pll_params *pll_params,
0430                spinlock_t *lock);
0431 
0432 struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
0433                void __iomem *clk_base, void __iomem *pmc,
0434                unsigned long flags,
0435                struct tegra_clk_pll_params *pll_params,
0436                spinlock_t *lock, unsigned long parent_rate);
0437 
0438 struct clk *tegra_clk_register_pllre_tegra210(const char *name,
0439                const char *parent_name, void __iomem *clk_base,
0440                void __iomem *pmc, unsigned long flags,
0441                struct tegra_clk_pll_params *pll_params,
0442                spinlock_t *lock, unsigned long parent_rate);
0443 
0444 struct clk *tegra_clk_register_plle_tegra114(const char *name,
0445                 const char *parent_name,
0446                 void __iomem *clk_base, unsigned long flags,
0447                 struct tegra_clk_pll_params *pll_params,
0448                 spinlock_t *lock);
0449 
0450 struct clk *tegra_clk_register_plle_tegra210(const char *name,
0451                 const char *parent_name,
0452                 void __iomem *clk_base, unsigned long flags,
0453                 struct tegra_clk_pll_params *pll_params,
0454                 spinlock_t *lock);
0455 
0456 struct clk *tegra_clk_register_pllc_tegra210(const char *name,
0457                 const char *parent_name, void __iomem *clk_base,
0458                 void __iomem *pmc, unsigned long flags,
0459                 struct tegra_clk_pll_params *pll_params,
0460                 spinlock_t *lock);
0461 
0462 struct clk *tegra_clk_register_pllss_tegra210(const char *name,
0463                 const char *parent_name, void __iomem *clk_base,
0464                 unsigned long flags,
0465                 struct tegra_clk_pll_params *pll_params,
0466                 spinlock_t *lock);
0467 
0468 struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name,
0469                void __iomem *clk_base, unsigned long flags,
0470                struct tegra_clk_pll_params *pll_params,
0471                spinlock_t *lock);
0472 
0473 struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name,
0474                void __iomem *clk_base, void __iomem *pmc,
0475                unsigned long flags,
0476                struct tegra_clk_pll_params *pll_params,
0477                spinlock_t *lock);
0478 
0479 struct clk *tegra_clk_register_pllu(const char *name, const char *parent_name,
0480                 void __iomem *clk_base, unsigned long flags,
0481                 struct tegra_clk_pll_params *pll_params,
0482                 spinlock_t *lock);
0483 
0484 struct clk *tegra_clk_register_pllu_tegra114(const char *name,
0485                 const char *parent_name,
0486                 void __iomem *clk_base, unsigned long flags,
0487                 struct tegra_clk_pll_params *pll_params,
0488                 spinlock_t *lock);
0489 
0490 struct clk *tegra_clk_register_pllu_tegra210(const char *name,
0491                 const char *parent_name,
0492                 void __iomem *clk_base, unsigned long flags,
0493                 struct tegra_clk_pll_params *pll_params,
0494                 spinlock_t *lock);
0495 
0496 /**
0497  * struct tegra_clk_pll_out - PLL divider down clock
0498  *
0499  * @hw:         handle between common and hardware-specific interfaces
0500  * @reg:        register containing the PLL divider
0501  * @enb_bit_idx:    bit to enable/disable PLL divider
0502  * @rst_bit_idx:    bit to reset PLL divider
0503  * @lock:       register lock
0504  * @flags:      hardware-specific flags
0505  */
0506 struct tegra_clk_pll_out {
0507     struct clk_hw   hw;
0508     void __iomem    *reg;
0509     u8      enb_bit_idx;
0510     u8      rst_bit_idx;
0511     spinlock_t  *lock;
0512     u8      flags;
0513 };
0514 
0515 #define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
0516 
0517 extern const struct clk_ops tegra_clk_pll_out_ops;
0518 struct clk *tegra_clk_register_pll_out(const char *name,
0519         const char *parent_name, void __iomem *reg, u8 enb_bit_idx,
0520         u8 rst_bit_idx, unsigned long flags, u8 pll_div_flags,
0521         spinlock_t *lock);
0522 
0523 /**
0524  * struct tegra_clk_periph_regs -  Registers controlling peripheral clock
0525  *
0526  * @enb_reg:        read the enable status
0527  * @enb_set_reg:    write 1 to enable clock
0528  * @enb_clr_reg:    write 1 to disable clock
0529  * @rst_reg:        read the reset status
0530  * @rst_set_reg:    write 1 to assert the reset of peripheral
0531  * @rst_clr_reg:    write 1 to deassert the reset of peripheral
0532  */
0533 struct tegra_clk_periph_regs {
0534     u32 enb_reg;
0535     u32 enb_set_reg;
0536     u32 enb_clr_reg;
0537     u32 rst_reg;
0538     u32 rst_set_reg;
0539     u32 rst_clr_reg;
0540 };
0541 
0542 /**
0543  * struct tegra_clk_periph_gate - peripheral gate clock
0544  *
0545  * @magic:      magic number to validate type
0546  * @hw:         handle between common and hardware-specific interfaces
0547  * @clk_base:       address of CAR controller
0548  * @regs:       Registers to control the peripheral
0549  * @flags:      hardware-specific flags
0550  * @clk_num:        Clock number
0551  * @enable_refcnt:  array to maintain reference count of the clock
0552  *
0553  * Flags:
0554  * TEGRA_PERIPH_NO_RESET - This flag indicates that reset is not allowed
0555  *     for this module.
0556  * TEGRA_PERIPH_ON_APB - If peripheral is in the APB bus then read the
0557  *     bus to flush the write operation in apb bus. This flag indicates
0558  *     that this peripheral is in apb bus.
0559  * TEGRA_PERIPH_WAR_1005168 - Apply workaround for Tegra114 MSENC bug
0560  */
0561 struct tegra_clk_periph_gate {
0562     u32         magic;
0563     struct clk_hw       hw;
0564     void __iomem        *clk_base;
0565     u8          flags;
0566     int         clk_num;
0567     int         *enable_refcnt;
0568     const struct tegra_clk_periph_regs *regs;
0569 };
0570 
0571 #define to_clk_periph_gate(_hw)                 \
0572     container_of(_hw, struct tegra_clk_periph_gate, hw)
0573 
0574 #define TEGRA_CLK_PERIPH_GATE_MAGIC 0x17760309
0575 
0576 #define TEGRA_PERIPH_NO_RESET BIT(0)
0577 #define TEGRA_PERIPH_ON_APB BIT(2)
0578 #define TEGRA_PERIPH_WAR_1005168 BIT(3)
0579 #define TEGRA_PERIPH_NO_DIV BIT(4)
0580 #define TEGRA_PERIPH_NO_GATE BIT(5)
0581 
0582 extern const struct clk_ops tegra_clk_periph_gate_ops;
0583 struct clk *tegra_clk_register_periph_gate(const char *name,
0584         const char *parent_name, u8 gate_flags, void __iomem *clk_base,
0585         unsigned long flags, int clk_num, int *enable_refcnt);
0586 
0587 struct tegra_clk_periph_fixed {
0588     struct clk_hw hw;
0589     void __iomem *base;
0590     const struct tegra_clk_periph_regs *regs;
0591     unsigned int mul;
0592     unsigned int div;
0593     unsigned int num;
0594 };
0595 
0596 struct clk *tegra_clk_register_periph_fixed(const char *name,
0597                         const char *parent,
0598                         unsigned long flags,
0599                         void __iomem *base,
0600                         unsigned int mul,
0601                         unsigned int div,
0602                         unsigned int num);
0603 
0604 /**
0605  * struct clk-periph - peripheral clock
0606  *
0607  * @magic:  magic number to validate type
0608  * @hw:     handle between common and hardware-specific interfaces
0609  * @mux:    mux clock
0610  * @divider:    divider clock
0611  * @gate:   gate clock
0612  * @mux_ops:    mux clock ops
0613  * @div_ops:    divider clock ops
0614  * @gate_ops:   gate clock ops
0615  */
0616 struct tegra_clk_periph {
0617     u32         magic;
0618     struct clk_hw       hw;
0619     struct clk_mux      mux;
0620     struct tegra_clk_frac_div   divider;
0621     struct tegra_clk_periph_gate    gate;
0622 
0623     const struct clk_ops    *mux_ops;
0624     const struct clk_ops    *div_ops;
0625     const struct clk_ops    *gate_ops;
0626 };
0627 
0628 #define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
0629 
0630 #define TEGRA_CLK_PERIPH_MAGIC 0x18221223
0631 
0632 extern const struct clk_ops tegra_clk_periph_ops;
0633 struct clk *tegra_clk_register_periph(const char *name,
0634         const char * const *parent_names, int num_parents,
0635         struct tegra_clk_periph *periph, void __iomem *clk_base,
0636         u32 offset, unsigned long flags);
0637 struct clk *tegra_clk_register_periph_nodiv(const char *name,
0638         const char * const *parent_names, int num_parents,
0639         struct tegra_clk_periph *periph, void __iomem *clk_base,
0640         u32 offset);
0641 
0642 #define TEGRA_CLK_PERIPH(_mux_shift, _mux_mask, _mux_flags,     \
0643              _div_shift, _div_width, _div_frac_width,   \
0644              _div_flags, _clk_num,\
0645              _gate_flags, _table, _lock)            \
0646     {                               \
0647         .mux = {                        \
0648             .flags = _mux_flags,                \
0649             .shift = _mux_shift,                \
0650             .mask = _mux_mask,              \
0651             .table = _table,                \
0652             .lock = _lock,                  \
0653         },                          \
0654         .divider = {                        \
0655             .flags = _div_flags,                \
0656             .shift = _div_shift,                \
0657             .width = _div_width,                \
0658             .frac_width = _div_frac_width,          \
0659             .lock = _lock,                  \
0660         },                          \
0661         .gate = {                       \
0662             .flags = _gate_flags,               \
0663             .clk_num = _clk_num,                \
0664         },                          \
0665         .mux_ops = &clk_mux_ops,                \
0666         .div_ops = &tegra_clk_frac_div_ops,         \
0667         .gate_ops = &tegra_clk_periph_gate_ops,         \
0668     }
0669 
0670 struct tegra_periph_init_data {
0671     const char *name;
0672     int clk_id;
0673     union {
0674         const char *const *parent_names;
0675         const char *parent_name;
0676     } p;
0677     int num_parents;
0678     struct tegra_clk_periph periph;
0679     u32 offset;
0680     const char *con_id;
0681     const char *dev_id;
0682     unsigned long flags;
0683 };
0684 
0685 #define TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
0686             _mux_shift, _mux_mask, _mux_flags, _div_shift,  \
0687             _div_width, _div_frac_width, _div_flags,    \
0688             _clk_num, _gate_flags, _clk_id, _table,     \
0689             _flags, _lock) \
0690     {                               \
0691         .name = _name,                      \
0692         .clk_id = _clk_id,                  \
0693         .p.parent_names = _parent_names,            \
0694         .num_parents = ARRAY_SIZE(_parent_names),       \
0695         .periph = TEGRA_CLK_PERIPH(_mux_shift, _mux_mask,   \
0696                        _mux_flags, _div_shift,  \
0697                        _div_width, _div_frac_width, \
0698                        _div_flags, _clk_num,    \
0699                        _gate_flags, _table, _lock), \
0700         .offset = _offset,                  \
0701         .con_id = _con_id,                  \
0702         .dev_id = _dev_id,                  \
0703         .flags = _flags                     \
0704     }
0705 
0706 #define TEGRA_INIT_DATA(_name, _con_id, _dev_id, _parent_names, _offset,\
0707             _mux_shift, _mux_width, _mux_flags, _div_shift, \
0708             _div_width, _div_frac_width, _div_flags, \
0709             _clk_num, _gate_flags, _clk_id) \
0710     TEGRA_INIT_DATA_TABLE(_name, _con_id, _dev_id, _parent_names, _offset,\
0711             _mux_shift, BIT(_mux_width) - 1, _mux_flags,    \
0712             _div_shift, _div_width, _div_frac_width, _div_flags, \
0713             _clk_num, _gate_flags, _clk_id,\
0714             NULL, 0, NULL)
0715 
0716 struct clk *tegra_clk_register_periph_data(void __iomem *clk_base,
0717                        struct tegra_periph_init_data *init);
0718 
0719 /**
0720  * struct clk_super_mux - super clock
0721  *
0722  * @hw:     handle between common and hardware-specific interfaces
0723  * @reg:    register controlling multiplexer
0724  * @width:  width of the multiplexer bit field
0725  * @flags:  hardware-specific flags
0726  * @div2_index: bit controlling divide-by-2
0727  * @pllx_index: PLLX index in the parent list
0728  * @lock:   register lock
0729  *
0730  * Flags:
0731  * TEGRA_DIVIDER_2 - LP cluster has additional divider. This flag indicates
0732  *     that this is LP cluster clock.
0733  * TEGRA210_CPU_CLK - This flag is used to identify CPU cluster for gen5
0734  *     super mux parent using PLLP branches. To use PLLP branches to CPU, need
0735  *     to configure additional bit PLLP_OUT_CPU in the clock registers.
0736  * TEGRA20_SUPER_CLK - Tegra20 doesn't have a dedicated divider for Super
0737  *     clocks, it only has a clock-skipper.
0738  */
0739 struct tegra_clk_super_mux {
0740     struct clk_hw   hw;
0741     void __iomem    *reg;
0742     struct tegra_clk_frac_div frac_div;
0743     const struct clk_ops    *div_ops;
0744     u8      width;
0745     u8      flags;
0746     u8      div2_index;
0747     u8      pllx_index;
0748     spinlock_t  *lock;
0749 };
0750 
0751 #define to_clk_super_mux(_hw) container_of(_hw, struct tegra_clk_super_mux, hw)
0752 
0753 #define TEGRA_DIVIDER_2 BIT(0)
0754 #define TEGRA210_CPU_CLK BIT(1)
0755 #define TEGRA20_SUPER_CLK BIT(2)
0756 
0757 extern const struct clk_ops tegra_clk_super_ops;
0758 struct clk *tegra_clk_register_super_mux(const char *name,
0759         const char **parent_names, u8 num_parents,
0760         unsigned long flags, void __iomem *reg, u8 clk_super_flags,
0761         u8 width, u8 pllx_index, u8 div2_index, spinlock_t *lock);
0762 struct clk *tegra_clk_register_super_clk(const char *name,
0763         const char * const *parent_names, u8 num_parents,
0764         unsigned long flags, void __iomem *reg, u8 clk_super_flags,
0765         spinlock_t *lock);
0766 struct clk *tegra_clk_register_super_cclk(const char *name,
0767         const char * const *parent_names, u8 num_parents,
0768         unsigned long flags, void __iomem *reg, u8 clk_super_flags,
0769         spinlock_t *lock);
0770 int tegra_cclk_pre_pllx_rate_change(void);
0771 void tegra_cclk_post_pllx_rate_change(void);
0772 
0773 /**
0774  * struct tegra_sdmmc_mux - switch divider with Low Jitter inputs for SDMMC
0775  *
0776  * @hw:     handle between common and hardware-specific interfaces
0777  * @reg:    register controlling mux and divider
0778  * @flags:  hardware-specific flags
0779  * @lock:   optional register lock
0780  * @gate:   gate clock
0781  * @gate_ops:   gate clock ops
0782  */
0783 struct tegra_sdmmc_mux {
0784     struct clk_hw       hw;
0785     void __iomem        *reg;
0786     spinlock_t      *lock;
0787     const struct clk_ops    *gate_ops;
0788     struct tegra_clk_periph_gate    gate;
0789     u8          div_flags;
0790 };
0791 
0792 #define to_clk_sdmmc_mux(_hw) container_of(_hw, struct tegra_sdmmc_mux, hw)
0793 
0794 struct clk *tegra_clk_register_sdmmc_mux_div(const char *name,
0795         void __iomem *clk_base, u32 offset, u32 clk_num, u8 div_flags,
0796         unsigned long flags, void *lock);
0797 
0798 /**
0799  * struct clk_init_table - clock initialization table
0800  * @clk_id: clock id as mentioned in device tree bindings
0801  * @parent_id:  parent clock id as mentioned in device tree bindings
0802  * @rate:   rate to set
0803  * @state:  enable/disable
0804  */
0805 struct tegra_clk_init_table {
0806     unsigned int    clk_id;
0807     unsigned int    parent_id;
0808     unsigned long   rate;
0809     int     state;
0810 };
0811 
0812 /**
0813  * struct clk_duplicate - duplicate clocks
0814  * @clk_id: clock id as mentioned in device tree bindings
0815  * @lookup: duplicate lookup entry for the clock
0816  */
0817 struct tegra_clk_duplicate {
0818     int         clk_id;
0819     struct clk_lookup   lookup;
0820 };
0821 
0822 #define TEGRA_CLK_DUPLICATE(_clk_id, _dev, _con) \
0823     {                   \
0824         .clk_id = _clk_id,      \
0825         .lookup = {         \
0826             .dev_id = _dev,     \
0827             .con_id = _con,     \
0828         },              \
0829     }
0830 
0831 struct tegra_clk {
0832     int         dt_id;
0833     bool            present;
0834 };
0835 
0836 struct tegra_devclk {
0837     int     dt_id;
0838     char        *dev_id;
0839     char        *con_id;
0840 };
0841 
0842 void tegra_init_special_resets(unsigned int num, int (*assert)(unsigned long),
0843                    int (*deassert)(unsigned long));
0844 
0845 void tegra_init_from_table(struct tegra_clk_init_table *tbl,
0846         struct clk *clks[], int clk_max);
0847 
0848 void tegra_init_dup_clks(struct tegra_clk_duplicate *dup_list,
0849         struct clk *clks[], int clk_max);
0850 
0851 const struct tegra_clk_periph_regs *get_reg_bank(int clkid);
0852 struct clk **tegra_clk_init(void __iomem *clk_base, int num, int periph_banks);
0853 
0854 struct clk **tegra_lookup_dt_id(int clk_id, struct tegra_clk *tegra_clk);
0855 
0856 void tegra_add_of_provider(struct device_node *np, void *clk_src_onecell_get);
0857 void tegra_register_devclks(struct tegra_devclk *dev_clks, int num);
0858 
0859 void tegra_audio_clk_init(void __iomem *clk_base,
0860             void __iomem *pmc_base, struct tegra_clk *tegra_clks,
0861             struct tegra_audio_clk_info *audio_info,
0862             unsigned int num_plls, unsigned long sync_max_rate);
0863 
0864 void tegra_periph_clk_init(void __iomem *clk_base, void __iomem *pmc_base,
0865             struct tegra_clk *tegra_clks,
0866             struct tegra_clk_pll_params *pll_params);
0867 
0868 void tegra_fixed_clk_init(struct tegra_clk *tegra_clks);
0869 int tegra_osc_clk_init(void __iomem *clk_base, struct tegra_clk *clks,
0870                unsigned long *input_freqs, unsigned int num,
0871                unsigned int clk_m_div, unsigned long *osc_freq,
0872                unsigned long *pll_ref_freq);
0873 void tegra_super_clk_gen4_init(void __iomem *clk_base,
0874             void __iomem *pmc_base, struct tegra_clk *tegra_clks,
0875             struct tegra_clk_pll_params *pll_params);
0876 void tegra_super_clk_gen5_init(void __iomem *clk_base,
0877             void __iomem *pmc_base, struct tegra_clk *tegra_clks,
0878             struct tegra_clk_pll_params *pll_params);
0879 
0880 #ifdef CONFIG_TEGRA124_CLK_EMC
0881 struct clk *tegra124_clk_register_emc(void __iomem *base, struct device_node *np,
0882                       spinlock_t *lock);
0883 bool tegra124_clk_emc_driver_available(struct clk_hw *emc_hw);
0884 #else
0885 static inline struct clk *
0886 tegra124_clk_register_emc(void __iomem *base, struct device_node *np,
0887               spinlock_t *lock)
0888 {
0889     return NULL;
0890 }
0891 
0892 static inline bool tegra124_clk_emc_driver_available(struct clk_hw *emc_hw)
0893 {
0894     return false;
0895 }
0896 #endif
0897 
0898 void tegra114_clock_tune_cpu_trimmers_high(void);
0899 void tegra114_clock_tune_cpu_trimmers_low(void);
0900 void tegra114_clock_tune_cpu_trimmers_init(void);
0901 void tegra114_clock_assert_dfll_dvco_reset(void);
0902 void tegra114_clock_deassert_dfll_dvco_reset(void);
0903 
0904 typedef void (*tegra_clk_apply_init_table_func)(void);
0905 extern tegra_clk_apply_init_table_func tegra_clk_apply_init_table;
0906 int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll);
0907 u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate);
0908 int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div);
0909 int div_frac_get(unsigned long rate, unsigned parent_rate, u8 width,
0910          u8 frac_width, u8 flags);
0911 void tegra_clk_osc_resume(void __iomem *clk_base);
0912 void tegra_clk_set_pllp_out_cpu(bool enable);
0913 void tegra_clk_periph_suspend(void);
0914 void tegra_clk_periph_resume(void);
0915 
0916 
0917 /* Combined read fence with delay */
0918 #define fence_udelay(delay, reg)    \
0919     do {                \
0920         readl(reg);     \
0921         udelay(delay);      \
0922     } while (0)
0923 
0924 bool tegra20_clk_emc_driver_available(struct clk_hw *emc_hw);
0925 struct clk *tegra20_clk_register_emc(void __iomem *ioaddr, bool low_jitter);
0926 
0927 struct clk *tegra210_clk_register_emc(struct device_node *np,
0928                       void __iomem *regs);
0929 
0930 struct clk *tegra_clk_dev_register(struct clk_hw *hw);
0931 
0932 #endif /* TEGRA_CLK_H */