152e6676eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2c82f8957STero Kristo /* 3c82f8957STero Kristo * TI Clock driver internal definitions 4c82f8957STero Kristo * 5c82f8957STero Kristo * Copyright (C) 2014 Texas Instruments, Inc 6c82f8957STero Kristo * Tero Kristo (t-kristo@ti.com) 7c82f8957STero Kristo */ 8c82f8957STero Kristo #ifndef __DRIVERS_CLK_TI_CLOCK__ 9c82f8957STero Kristo #define __DRIVERS_CLK_TI_CLOCK__ 10c82f8957STero Kristo 116dbde947STero Kristo struct clk_omap_divider { 126dbde947STero Kristo struct clk_hw hw; 136c0afb50STero Kristo struct clk_omap_reg reg; 146dbde947STero Kristo u8 shift; 156dbde947STero Kristo u8 flags; 16b44a0300STero Kristo s8 latch; 178ffea6eeSTero Kristo u16 min; 188ffea6eeSTero Kristo u16 max; 198ffea6eeSTero Kristo u16 mask; 206dbde947STero Kristo const struct clk_div_table *table; 21d6e7bbc1SRuss Dill u32 context; 226dbde947STero Kristo }; 236dbde947STero Kristo 246dbde947STero Kristo #define to_clk_omap_divider(_hw) container_of(_hw, struct clk_omap_divider, hw) 256dbde947STero Kristo 26d83bc5b6STero Kristo struct clk_omap_mux { 27d83bc5b6STero Kristo struct clk_hw hw; 286c0afb50STero Kristo struct clk_omap_reg reg; 29d83bc5b6STero Kristo u32 *table; 30d83bc5b6STero Kristo u32 mask; 31d83bc5b6STero Kristo u8 shift; 32ee2fc3c5STero Kristo s8 latch; 33d83bc5b6STero Kristo u8 flags; 34d6e7bbc1SRuss Dill u8 saved_parent; 35d83bc5b6STero Kristo }; 36d83bc5b6STero Kristo 37d83bc5b6STero Kristo #define to_clk_omap_mux(_hw) container_of(_hw, struct clk_omap_mux, hw) 38d83bc5b6STero Kristo 39c82f8957STero Kristo enum { 40c82f8957STero Kristo TI_CLK_FIXED, 41c82f8957STero Kristo TI_CLK_MUX, 42c82f8957STero Kristo TI_CLK_DIVIDER, 43c82f8957STero Kristo TI_CLK_COMPOSITE, 44c82f8957STero Kristo TI_CLK_FIXED_FACTOR, 45c82f8957STero Kristo TI_CLK_GATE, 46c82f8957STero Kristo TI_CLK_DPLL, 47c82f8957STero Kristo }; 48c82f8957STero Kristo 49c82f8957STero Kristo /* Global flags */ 50c82f8957STero Kristo #define CLKF_INDEX_POWER_OF_TWO (1 << 0) 51c82f8957STero Kristo #define CLKF_INDEX_STARTS_AT_ONE (1 << 1) 52c82f8957STero Kristo #define CLKF_SET_RATE_PARENT (1 << 2) 53c82f8957STero Kristo #define CLKF_OMAP3 (1 << 3) 54c82f8957STero Kristo #define CLKF_AM35XX (1 << 4) 55c82f8957STero Kristo 56c82f8957STero Kristo /* Gate flags */ 57c82f8957STero Kristo #define CLKF_SET_BIT_TO_DISABLE (1 << 5) 58c82f8957STero Kristo #define CLKF_INTERFACE (1 << 6) 59c82f8957STero Kristo #define CLKF_SSI (1 << 7) 60c82f8957STero Kristo #define CLKF_DSS (1 << 8) 61c82f8957STero Kristo #define CLKF_HSOTGUSB (1 << 9) 62c82f8957STero Kristo #define CLKF_WAIT (1 << 10) 63c82f8957STero Kristo #define CLKF_NO_WAIT (1 << 11) 64c82f8957STero Kristo #define CLKF_HSDIV (1 << 12) 65c82f8957STero Kristo #define CLKF_CLKDM (1 << 13) 66c82f8957STero Kristo 67c82f8957STero Kristo /* DPLL flags */ 68c82f8957STero Kristo #define CLKF_LOW_POWER_STOP (1 << 5) 69c82f8957STero Kristo #define CLKF_LOCK (1 << 6) 70c82f8957STero Kristo #define CLKF_LOW_POWER_BYPASS (1 << 7) 71c82f8957STero Kristo #define CLKF_PER (1 << 8) 72c82f8957STero Kristo #define CLKF_CORE (1 << 9) 73c82f8957STero Kristo #define CLKF_J_TYPE (1 << 10) 74c82f8957STero Kristo 75269bd202STero Kristo /* CLKCTRL flags */ 76269bd202STero Kristo #define CLKF_SW_SUP BIT(5) 77269bd202STero Kristo #define CLKF_HW_SUP BIT(6) 78269bd202STero Kristo #define CLKF_NO_IDLEST BIT(7) 79269bd202STero Kristo 80869decd1STero Kristo #define CLKF_SOC_MASK GENMASK(11, 8) 812b1202d7STero Kristo 82869decd1STero Kristo #define CLKF_SOC_NONSEC BIT(8) 83869decd1STero Kristo #define CLKF_SOC_DRA72 BIT(9) 84869decd1STero Kristo #define CLKF_SOC_DRA74 BIT(10) 85869decd1STero Kristo #define CLKF_SOC_DRA76 BIT(11) 862b1202d7STero Kristo 87c82f8957STero Kristo #define CLK(dev, con, ck) \ 88c82f8957STero Kristo { \ 89c82f8957STero Kristo .lk = { \ 90c82f8957STero Kristo .dev_id = dev, \ 91c82f8957STero Kristo .con_id = con, \ 92c82f8957STero Kristo }, \ 93c82f8957STero Kristo .clk = ck, \ 94c82f8957STero Kristo } 95c82f8957STero Kristo 96c82f8957STero Kristo struct ti_clk { 97c82f8957STero Kristo const char *name; 98c82f8957STero Kristo const char *clkdm_name; 99c82f8957STero Kristo int type; 100c82f8957STero Kristo void *data; 101c82f8957STero Kristo struct ti_clk *patch; 102c82f8957STero Kristo struct clk *clk; 103c82f8957STero Kristo }; 104c82f8957STero Kristo 105c82f8957STero Kristo struct ti_clk_mux { 106c82f8957STero Kristo u8 bit_shift; 107c82f8957STero Kristo int num_parents; 108c82f8957STero Kristo u16 reg; 109c82f8957STero Kristo u8 module; 110ce382d47STero Kristo const char * const *parents; 111c82f8957STero Kristo u16 flags; 112c82f8957STero Kristo }; 113c82f8957STero Kristo 114c82f8957STero Kristo struct ti_clk_divider { 115c82f8957STero Kristo const char *parent; 116c82f8957STero Kristo u8 bit_shift; 117c82f8957STero Kristo u16 max_div; 118c82f8957STero Kristo u16 reg; 119c82f8957STero Kristo u8 module; 120c82f8957STero Kristo int *dividers; 121c82f8957STero Kristo int num_dividers; 122c82f8957STero Kristo u16 flags; 123c82f8957STero Kristo }; 124c82f8957STero Kristo 125c82f8957STero Kristo struct ti_clk_gate { 126c82f8957STero Kristo const char *parent; 127c82f8957STero Kristo u8 bit_shift; 128c82f8957STero Kristo u16 reg; 129c82f8957STero Kristo u8 module; 130c82f8957STero Kristo u16 flags; 131c82f8957STero Kristo }; 132c82f8957STero Kristo 133a3314e9cSTero Kristo /* Composite clock component types */ 134a3314e9cSTero Kristo enum { 135a3314e9cSTero Kristo CLK_COMPONENT_TYPE_GATE = 0, 136a3314e9cSTero Kristo CLK_COMPONENT_TYPE_DIVIDER, 137a3314e9cSTero Kristo CLK_COMPONENT_TYPE_MUX, 138a3314e9cSTero Kristo CLK_COMPONENT_TYPE_MAX, 139a3314e9cSTero Kristo }; 140a3314e9cSTero Kristo 141a3314e9cSTero Kristo /** 142a3314e9cSTero Kristo * struct ti_dt_clk - OMAP DT clock alias declarations 143a3314e9cSTero Kristo * @lk: clock lookup definition 144a3314e9cSTero Kristo * @node_name: clock DT node to map to 145a3314e9cSTero Kristo */ 146a3314e9cSTero Kristo struct ti_dt_clk { 147a3314e9cSTero Kristo struct clk_lookup lk; 148a3314e9cSTero Kristo char *node_name; 149a3314e9cSTero Kristo }; 150a3314e9cSTero Kristo 151a3314e9cSTero Kristo #define DT_CLK(dev, con, name) \ 152a3314e9cSTero Kristo { \ 153a3314e9cSTero Kristo .lk = { \ 154a3314e9cSTero Kristo .dev_id = dev, \ 155a3314e9cSTero Kristo .con_id = con, \ 156a3314e9cSTero Kristo }, \ 157a3314e9cSTero Kristo .node_name = name, \ 158a3314e9cSTero Kristo } 159a3314e9cSTero Kristo 16088a17252STero Kristo /* CLKCTRL type definitions */ 16188a17252STero Kristo struct omap_clkctrl_div_data { 16288a17252STero Kristo const int *dividers; 16388a17252STero Kristo int max_div; 16449eec6fbSTero Kristo u32 flags; 16588a17252STero Kristo }; 16688a17252STero Kristo 16788a17252STero Kristo struct omap_clkctrl_bit_data { 16888a17252STero Kristo u8 bit; 16988a17252STero Kristo u8 type; 17088a17252STero Kristo const char * const *parents; 17188a17252STero Kristo const void *data; 17288a17252STero Kristo }; 17388a17252STero Kristo 17488a17252STero Kristo struct omap_clkctrl_reg_data { 17588a17252STero Kristo u16 offset; 17688a17252STero Kristo const struct omap_clkctrl_bit_data *bit_data; 17788a17252STero Kristo u16 flags; 17888a17252STero Kristo const char *parent; 179ddfb183eSTero Kristo const char *clkdm_name; 18088a17252STero Kristo }; 18188a17252STero Kristo 18288a17252STero Kristo struct omap_clkctrl_data { 18388a17252STero Kristo u32 addr; 18488a17252STero Kristo const struct omap_clkctrl_reg_data *regs; 18588a17252STero Kristo }; 18688a17252STero Kristo 1871c881b5aSTero Kristo extern const struct omap_clkctrl_data omap4_clkctrl_data[]; 1880ad902f6STero Kristo extern const struct omap_clkctrl_data omap5_clkctrl_data[]; 189dffa9051STero Kristo extern const struct omap_clkctrl_data dra7_clkctrl_data[]; 19043c56e04STero Kristo extern const struct omap_clkctrl_data dra7_clkctrl_compat_data[]; 19143c56e04STero Kristo extern struct ti_dt_clk dra7xx_compat_clks[]; 192296e583eSTero Kristo extern const struct omap_clkctrl_data am3_clkctrl_data[]; 193e97017f9STero Kristo extern const struct omap_clkctrl_data am3_clkctrl_compat_data[]; 194e97017f9STero Kristo extern struct ti_dt_clk am33xx_compat_clks[]; 19576a1049bSTero Kristo extern const struct omap_clkctrl_data am4_clkctrl_data[]; 19676a1049bSTero Kristo extern const struct omap_clkctrl_data am438x_clkctrl_data[]; 19726ca2e97STero Kristo extern const struct omap_clkctrl_data dm814_clkctrl_data[]; 19850ef5089STero Kristo extern const struct omap_clkctrl_data dm816_clkctrl_data[]; 1991c881b5aSTero Kristo 200ffb009b2STero Kristo typedef void (*ti_of_clk_init_cb_t)(void *, struct device_node *); 201a3314e9cSTero Kristo 202*3400d546SDario Binacchi struct clk *of_ti_clk_register(struct device_node *node, struct clk_hw *hw, 20321f0bf2dSTero Kristo const char *con); 204*3400d546SDario Binacchi struct clk *of_ti_clk_register_omap_hw(struct device_node *node, 205*3400d546SDario Binacchi struct clk_hw *hw, const char *con); 2062c159332STony Lindgren const char *ti_dt_clk_name(struct device_node *np); 207*3400d546SDario Binacchi int ti_clk_add_alias(struct clk *clk, const char *con); 208c17435c5STero Kristo void ti_clk_add_aliases(void); 2097c18a65cSTero Kristo 210e31922edSTero Kristo void ti_clk_latch(struct clk_omap_reg *reg, s8 shift); 211e31922edSTero Kristo 2127c18a65cSTero Kristo struct clk_hw *ti_clk_build_component_mux(struct ti_clk_mux *setup); 2137c18a65cSTero Kristo 2144f6be565STero Kristo int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div, 215a229965cSTero Kristo u8 flags, struct clk_omap_divider *div); 2164f6be565STero Kristo 2176c0afb50STero Kristo int ti_clk_get_reg_addr(struct device_node *node, int index, 2186c0afb50STero Kristo struct clk_omap_reg *reg); 219a3314e9cSTero Kristo void ti_dt_clocks_register(struct ti_dt_clk *oclks); 220ffb009b2STero Kristo int ti_clk_retry_init(struct device_node *node, void *user, 221a3314e9cSTero Kristo ti_of_clk_init_cb_t func); 222a3314e9cSTero Kristo int ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type); 223a3314e9cSTero Kristo 224bf22bae7STero Kristo int of_ti_clk_autoidle_setup(struct device_node *node); 225a5aa8a60STero Kristo void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks); 226bf22bae7STero Kristo 2270565fb16STero Kristo extern const struct clk_hw_omap_ops clkhwops_omap3_dpll; 22859245ce0STero Kristo extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx; 2299f37e90eSTero Kristo extern const struct clk_hw_omap_ops clkhwops_wait; 230ef14db09STero Kristo extern const struct clk_hw_omap_ops clkhwops_iclk; 231ef14db09STero Kristo extern const struct clk_hw_omap_ops clkhwops_iclk_wait; 232d5a04dddSTero Kristo extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait; 233f2671d5cSTero Kristo extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait; 234f2671d5cSTero Kristo extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait; 235f2671d5cSTero Kristo extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait; 236f2671d5cSTero Kristo extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait; 237c9a58b0aSTero Kristo extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait; 238c9a58b0aSTero Kristo extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait; 23959245ce0STero Kristo 240a3314e9cSTero Kristo extern const struct clk_ops ti_clk_divider_ops; 241a3314e9cSTero Kristo extern const struct clk_ops ti_clk_mux_ops; 2429a00fa68STero Kristo extern const struct clk_ops omap_gate_clk_ops; 243a3314e9cSTero Kristo 24447b00dcfSTero Kristo extern struct ti_clk_features ti_clk_features; 24547b00dcfSTero Kristo 24689d079dcSJerome Brunet int omap2_init_clk_clkdm(struct clk_hw *hw); 247bd86cfdcSTero Kristo int omap2_clkops_enable_clkdm(struct clk_hw *hw); 248bd86cfdcSTero Kristo void omap2_clkops_disable_clkdm(struct clk_hw *hw); 249bd86cfdcSTero Kristo 2509f37e90eSTero Kristo int omap2_dflt_clk_enable(struct clk_hw *hw); 2519f37e90eSTero Kristo void omap2_dflt_clk_disable(struct clk_hw *hw); 2529f37e90eSTero Kristo int omap2_dflt_clk_is_enabled(struct clk_hw *hw); 253a3314e9cSTero Kristo void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk, 2546c0afb50STero Kristo struct clk_omap_reg *other_reg, 255a3314e9cSTero Kristo u8 *other_bit); 256a3314e9cSTero Kristo void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk, 2576c0afb50STero Kristo struct clk_omap_reg *idlest_reg, 258a3314e9cSTero Kristo u8 *idlest_bit, u8 *idlest_val); 259a3314e9cSTero Kristo 260a3314e9cSTero Kristo void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk); 261a3314e9cSTero Kristo void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk); 2629f37e90eSTero Kristo 263b138b028STero Kristo u8 omap2_init_dpll_parent(struct clk_hw *hw); 2640565fb16STero Kristo int omap3_noncore_dpll_enable(struct clk_hw *hw); 2650565fb16STero Kristo void omap3_noncore_dpll_disable(struct clk_hw *hw); 2660565fb16STero Kristo int omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index); 2670565fb16STero Kristo int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate, 2680565fb16STero Kristo unsigned long parent_rate); 2690565fb16STero Kristo int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw, 2700565fb16STero Kristo unsigned long rate, 2710565fb16STero Kristo unsigned long parent_rate, 2720565fb16STero Kristo u8 index); 2734d341056SStephen Boyd int omap3_noncore_dpll_determine_rate(struct clk_hw *hw, 2744d341056SStephen Boyd struct clk_rate_request *req); 2750565fb16STero Kristo long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, 2760565fb16STero Kristo unsigned long *parent_rate); 2770565fb16STero Kristo unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw, 2780565fb16STero Kristo unsigned long parent_rate); 2790565fb16STero Kristo 280035cd485SRichard Watts /* 281035cd485SRichard Watts * OMAP3_DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks 282035cd485SRichard Watts * that are sourced by DPLL5, and both of these require this clock 283035cd485SRichard Watts * to be at 120 MHz for proper operation. 284035cd485SRichard Watts */ 285035cd485SRichard Watts #define OMAP3_DPLL5_FREQ_FOR_USBHOST 120000000 286035cd485SRichard Watts 2870565fb16STero Kristo unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate); 2880565fb16STero Kristo int omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate, 2890565fb16STero Kristo unsigned long parent_rate); 2900565fb16STero Kristo int omap3_dpll4_set_rate_and_parent(struct clk_hw *hw, unsigned long rate, 2910565fb16STero Kristo unsigned long parent_rate, u8 index); 292035cd485SRichard Watts int omap3_dpll5_set_rate(struct clk_hw *hw, unsigned long rate, 293035cd485SRichard Watts unsigned long parent_rate); 2940565fb16STero Kristo void omap3_clk_lock_dpll5(void); 295b138b028STero Kristo 29659245ce0STero Kristo unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw, 29759245ce0STero Kristo unsigned long parent_rate); 29859245ce0STero Kristo long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw, 29959245ce0STero Kristo unsigned long target_rate, 30059245ce0STero Kristo unsigned long *parent_rate); 3014d341056SStephen Boyd int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw, 3024d341056SStephen Boyd struct clk_rate_request *req); 30377b773aeSTero Kristo int omap2_clk_for_each(int (*fn)(struct clk_hw_omap *hw)); 30459245ce0STero Kristo 305e9e63088STero Kristo extern struct ti_clk_ll_ops *ti_clk_ll_ops; 306e9e63088STero Kristo 307c82f8957STero Kristo #endif 308