162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * TI Clock driver internal definitions 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2014 Texas Instruments, Inc 662306a36Sopenharmony_ci * Tero Kristo (t-kristo@ti.com) 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci#ifndef __DRIVERS_CLK_TI_CLOCK__ 962306a36Sopenharmony_ci#define __DRIVERS_CLK_TI_CLOCK__ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_cistruct clk_omap_divider { 1262306a36Sopenharmony_ci struct clk_hw hw; 1362306a36Sopenharmony_ci struct clk_omap_reg reg; 1462306a36Sopenharmony_ci u8 shift; 1562306a36Sopenharmony_ci u8 flags; 1662306a36Sopenharmony_ci s8 latch; 1762306a36Sopenharmony_ci u16 min; 1862306a36Sopenharmony_ci u16 max; 1962306a36Sopenharmony_ci u16 mask; 2062306a36Sopenharmony_ci const struct clk_div_table *table; 2162306a36Sopenharmony_ci u32 context; 2262306a36Sopenharmony_ci}; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define to_clk_omap_divider(_hw) container_of(_hw, struct clk_omap_divider, hw) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cistruct clk_omap_mux { 2762306a36Sopenharmony_ci struct clk_hw hw; 2862306a36Sopenharmony_ci struct clk_omap_reg reg; 2962306a36Sopenharmony_ci u32 *table; 3062306a36Sopenharmony_ci u32 mask; 3162306a36Sopenharmony_ci u8 shift; 3262306a36Sopenharmony_ci s8 latch; 3362306a36Sopenharmony_ci u8 flags; 3462306a36Sopenharmony_ci u8 saved_parent; 3562306a36Sopenharmony_ci}; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define to_clk_omap_mux(_hw) container_of(_hw, struct clk_omap_mux, hw) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cienum { 4062306a36Sopenharmony_ci TI_CLK_FIXED, 4162306a36Sopenharmony_ci TI_CLK_MUX, 4262306a36Sopenharmony_ci TI_CLK_DIVIDER, 4362306a36Sopenharmony_ci TI_CLK_COMPOSITE, 4462306a36Sopenharmony_ci TI_CLK_FIXED_FACTOR, 4562306a36Sopenharmony_ci TI_CLK_GATE, 4662306a36Sopenharmony_ci TI_CLK_DPLL, 4762306a36Sopenharmony_ci}; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* Global flags */ 5062306a36Sopenharmony_ci#define CLKF_INDEX_POWER_OF_TWO (1 << 0) 5162306a36Sopenharmony_ci#define CLKF_INDEX_STARTS_AT_ONE (1 << 1) 5262306a36Sopenharmony_ci#define CLKF_SET_RATE_PARENT (1 << 2) 5362306a36Sopenharmony_ci#define CLKF_OMAP3 (1 << 3) 5462306a36Sopenharmony_ci#define CLKF_AM35XX (1 << 4) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* Gate flags */ 5762306a36Sopenharmony_ci#define CLKF_SET_BIT_TO_DISABLE (1 << 5) 5862306a36Sopenharmony_ci#define CLKF_INTERFACE (1 << 6) 5962306a36Sopenharmony_ci#define CLKF_SSI (1 << 7) 6062306a36Sopenharmony_ci#define CLKF_DSS (1 << 8) 6162306a36Sopenharmony_ci#define CLKF_HSOTGUSB (1 << 9) 6262306a36Sopenharmony_ci#define CLKF_WAIT (1 << 10) 6362306a36Sopenharmony_ci#define CLKF_NO_WAIT (1 << 11) 6462306a36Sopenharmony_ci#define CLKF_HSDIV (1 << 12) 6562306a36Sopenharmony_ci#define CLKF_CLKDM (1 << 13) 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/* DPLL flags */ 6862306a36Sopenharmony_ci#define CLKF_LOW_POWER_STOP (1 << 5) 6962306a36Sopenharmony_ci#define CLKF_LOCK (1 << 6) 7062306a36Sopenharmony_ci#define CLKF_LOW_POWER_BYPASS (1 << 7) 7162306a36Sopenharmony_ci#define CLKF_PER (1 << 8) 7262306a36Sopenharmony_ci#define CLKF_CORE (1 << 9) 7362306a36Sopenharmony_ci#define CLKF_J_TYPE (1 << 10) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* CLKCTRL flags */ 7662306a36Sopenharmony_ci#define CLKF_SW_SUP BIT(5) 7762306a36Sopenharmony_ci#define CLKF_HW_SUP BIT(6) 7862306a36Sopenharmony_ci#define CLKF_NO_IDLEST BIT(7) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci#define CLKF_SOC_MASK GENMASK(11, 8) 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#define CLKF_SOC_NONSEC BIT(8) 8362306a36Sopenharmony_ci#define CLKF_SOC_DRA72 BIT(9) 8462306a36Sopenharmony_ci#define CLKF_SOC_DRA74 BIT(10) 8562306a36Sopenharmony_ci#define CLKF_SOC_DRA76 BIT(11) 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define CLK(dev, con, ck) \ 8862306a36Sopenharmony_ci { \ 8962306a36Sopenharmony_ci .lk = { \ 9062306a36Sopenharmony_ci .dev_id = dev, \ 9162306a36Sopenharmony_ci .con_id = con, \ 9262306a36Sopenharmony_ci }, \ 9362306a36Sopenharmony_ci .clk = ck, \ 9462306a36Sopenharmony_ci } 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_cistruct ti_clk { 9762306a36Sopenharmony_ci const char *name; 9862306a36Sopenharmony_ci const char *clkdm_name; 9962306a36Sopenharmony_ci int type; 10062306a36Sopenharmony_ci void *data; 10162306a36Sopenharmony_ci struct ti_clk *patch; 10262306a36Sopenharmony_ci struct clk *clk; 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistruct ti_clk_mux { 10662306a36Sopenharmony_ci u8 bit_shift; 10762306a36Sopenharmony_ci int num_parents; 10862306a36Sopenharmony_ci u16 reg; 10962306a36Sopenharmony_ci u8 module; 11062306a36Sopenharmony_ci const char * const *parents; 11162306a36Sopenharmony_ci u16 flags; 11262306a36Sopenharmony_ci}; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_cistruct ti_clk_divider { 11562306a36Sopenharmony_ci const char *parent; 11662306a36Sopenharmony_ci u8 bit_shift; 11762306a36Sopenharmony_ci u16 max_div; 11862306a36Sopenharmony_ci u16 reg; 11962306a36Sopenharmony_ci u8 module; 12062306a36Sopenharmony_ci int *dividers; 12162306a36Sopenharmony_ci int num_dividers; 12262306a36Sopenharmony_ci u16 flags; 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_cistruct ti_clk_gate { 12662306a36Sopenharmony_ci const char *parent; 12762306a36Sopenharmony_ci u8 bit_shift; 12862306a36Sopenharmony_ci u16 reg; 12962306a36Sopenharmony_ci u8 module; 13062306a36Sopenharmony_ci u16 flags; 13162306a36Sopenharmony_ci}; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci/* Composite clock component types */ 13462306a36Sopenharmony_cienum { 13562306a36Sopenharmony_ci CLK_COMPONENT_TYPE_GATE = 0, 13662306a36Sopenharmony_ci CLK_COMPONENT_TYPE_DIVIDER, 13762306a36Sopenharmony_ci CLK_COMPONENT_TYPE_MUX, 13862306a36Sopenharmony_ci CLK_COMPONENT_TYPE_MAX, 13962306a36Sopenharmony_ci}; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/** 14262306a36Sopenharmony_ci * struct ti_dt_clk - OMAP DT clock alias declarations 14362306a36Sopenharmony_ci * @lk: clock lookup definition 14462306a36Sopenharmony_ci * @node_name: clock DT node to map to 14562306a36Sopenharmony_ci */ 14662306a36Sopenharmony_cistruct ti_dt_clk { 14762306a36Sopenharmony_ci struct clk_lookup lk; 14862306a36Sopenharmony_ci char *node_name; 14962306a36Sopenharmony_ci}; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#define DT_CLK(dev, con, name) \ 15262306a36Sopenharmony_ci { \ 15362306a36Sopenharmony_ci .lk = { \ 15462306a36Sopenharmony_ci .dev_id = dev, \ 15562306a36Sopenharmony_ci .con_id = con, \ 15662306a36Sopenharmony_ci }, \ 15762306a36Sopenharmony_ci .node_name = name, \ 15862306a36Sopenharmony_ci } 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/* CLKCTRL type definitions */ 16162306a36Sopenharmony_cistruct omap_clkctrl_div_data { 16262306a36Sopenharmony_ci const int *dividers; 16362306a36Sopenharmony_ci int max_div; 16462306a36Sopenharmony_ci u32 flags; 16562306a36Sopenharmony_ci}; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cistruct omap_clkctrl_bit_data { 16862306a36Sopenharmony_ci u8 bit; 16962306a36Sopenharmony_ci u8 type; 17062306a36Sopenharmony_ci const char * const *parents; 17162306a36Sopenharmony_ci const void *data; 17262306a36Sopenharmony_ci}; 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_cistruct omap_clkctrl_reg_data { 17562306a36Sopenharmony_ci u16 offset; 17662306a36Sopenharmony_ci const struct omap_clkctrl_bit_data *bit_data; 17762306a36Sopenharmony_ci u16 flags; 17862306a36Sopenharmony_ci const char *parent; 17962306a36Sopenharmony_ci const char *clkdm_name; 18062306a36Sopenharmony_ci}; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_cistruct omap_clkctrl_data { 18362306a36Sopenharmony_ci u32 addr; 18462306a36Sopenharmony_ci const struct omap_clkctrl_reg_data *regs; 18562306a36Sopenharmony_ci}; 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ciextern const struct omap_clkctrl_data omap4_clkctrl_data[]; 18862306a36Sopenharmony_ciextern const struct omap_clkctrl_data omap5_clkctrl_data[]; 18962306a36Sopenharmony_ciextern const struct omap_clkctrl_data dra7_clkctrl_data[]; 19062306a36Sopenharmony_ciextern const struct omap_clkctrl_data dra7_clkctrl_compat_data[]; 19162306a36Sopenharmony_ciextern struct ti_dt_clk dra7xx_compat_clks[]; 19262306a36Sopenharmony_ciextern const struct omap_clkctrl_data am3_clkctrl_data[]; 19362306a36Sopenharmony_ciextern const struct omap_clkctrl_data am3_clkctrl_compat_data[]; 19462306a36Sopenharmony_ciextern struct ti_dt_clk am33xx_compat_clks[]; 19562306a36Sopenharmony_ciextern const struct omap_clkctrl_data am4_clkctrl_data[]; 19662306a36Sopenharmony_ciextern const struct omap_clkctrl_data am438x_clkctrl_data[]; 19762306a36Sopenharmony_ciextern const struct omap_clkctrl_data dm814_clkctrl_data[]; 19862306a36Sopenharmony_ciextern const struct omap_clkctrl_data dm816_clkctrl_data[]; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_citypedef void (*ti_of_clk_init_cb_t)(void *, struct device_node *); 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_cistruct clk *of_ti_clk_register(struct device_node *node, struct clk_hw *hw, 20362306a36Sopenharmony_ci const char *con); 20462306a36Sopenharmony_cistruct clk *of_ti_clk_register_omap_hw(struct device_node *node, 20562306a36Sopenharmony_ci struct clk_hw *hw, const char *con); 20662306a36Sopenharmony_ciconst char *ti_dt_clk_name(struct device_node *np); 20762306a36Sopenharmony_ciint ti_clk_add_alias(struct clk *clk, const char *con); 20862306a36Sopenharmony_civoid ti_clk_add_aliases(void); 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_civoid ti_clk_latch(struct clk_omap_reg *reg, s8 shift); 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_cistruct clk_hw *ti_clk_build_component_mux(struct ti_clk_mux *setup); 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ciint ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div, 21562306a36Sopenharmony_ci u8 flags, struct clk_omap_divider *div); 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ciint ti_clk_get_reg_addr(struct device_node *node, int index, 21862306a36Sopenharmony_ci struct clk_omap_reg *reg); 21962306a36Sopenharmony_civoid ti_dt_clocks_register(struct ti_dt_clk *oclks); 22062306a36Sopenharmony_ciint ti_clk_retry_init(struct device_node *node, void *user, 22162306a36Sopenharmony_ci ti_of_clk_init_cb_t func); 22262306a36Sopenharmony_ciint ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type); 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ciint of_ti_clk_autoidle_setup(struct device_node *node); 22562306a36Sopenharmony_civoid omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks); 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap3_dpll; 22862306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx; 22962306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_wait; 23062306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_iclk; 23162306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_iclk_wait; 23262306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait; 23362306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait; 23462306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait; 23562306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait; 23662306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait; 23762306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait; 23862306a36Sopenharmony_ciextern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait; 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ciextern const struct clk_ops ti_clk_divider_ops; 24162306a36Sopenharmony_ciextern const struct clk_ops ti_clk_mux_ops; 24262306a36Sopenharmony_ciextern const struct clk_ops omap_gate_clk_ops; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ciextern struct ti_clk_features ti_clk_features; 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ciint omap2_init_clk_clkdm(struct clk_hw *hw); 24762306a36Sopenharmony_ciint omap2_clkops_enable_clkdm(struct clk_hw *hw); 24862306a36Sopenharmony_civoid omap2_clkops_disable_clkdm(struct clk_hw *hw); 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ciint omap2_dflt_clk_enable(struct clk_hw *hw); 25162306a36Sopenharmony_civoid omap2_dflt_clk_disable(struct clk_hw *hw); 25262306a36Sopenharmony_ciint omap2_dflt_clk_is_enabled(struct clk_hw *hw); 25362306a36Sopenharmony_civoid omap2_clk_dflt_find_companion(struct clk_hw_omap *clk, 25462306a36Sopenharmony_ci struct clk_omap_reg *other_reg, 25562306a36Sopenharmony_ci u8 *other_bit); 25662306a36Sopenharmony_civoid omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk, 25762306a36Sopenharmony_ci struct clk_omap_reg *idlest_reg, 25862306a36Sopenharmony_ci u8 *idlest_bit, u8 *idlest_val); 25962306a36Sopenharmony_ci 26062306a36Sopenharmony_civoid omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk); 26162306a36Sopenharmony_civoid omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk); 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ciu8 omap2_init_dpll_parent(struct clk_hw *hw); 26462306a36Sopenharmony_ciint omap3_noncore_dpll_enable(struct clk_hw *hw); 26562306a36Sopenharmony_civoid omap3_noncore_dpll_disable(struct clk_hw *hw); 26662306a36Sopenharmony_ciint omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index); 26762306a36Sopenharmony_ciint omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate, 26862306a36Sopenharmony_ci unsigned long parent_rate); 26962306a36Sopenharmony_ciint omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw, 27062306a36Sopenharmony_ci unsigned long rate, 27162306a36Sopenharmony_ci unsigned long parent_rate, 27262306a36Sopenharmony_ci u8 index); 27362306a36Sopenharmony_ciint omap3_noncore_dpll_determine_rate(struct clk_hw *hw, 27462306a36Sopenharmony_ci struct clk_rate_request *req); 27562306a36Sopenharmony_cilong omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate, 27662306a36Sopenharmony_ci unsigned long *parent_rate); 27762306a36Sopenharmony_ciunsigned long omap3_clkoutx2_recalc(struct clk_hw *hw, 27862306a36Sopenharmony_ci unsigned long parent_rate); 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci/* 28162306a36Sopenharmony_ci * OMAP3_DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks 28262306a36Sopenharmony_ci * that are sourced by DPLL5, and both of these require this clock 28362306a36Sopenharmony_ci * to be at 120 MHz for proper operation. 28462306a36Sopenharmony_ci */ 28562306a36Sopenharmony_ci#define OMAP3_DPLL5_FREQ_FOR_USBHOST 120000000 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ciunsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate); 28862306a36Sopenharmony_ciint omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate, 28962306a36Sopenharmony_ci unsigned long parent_rate); 29062306a36Sopenharmony_ciint omap3_dpll4_set_rate_and_parent(struct clk_hw *hw, unsigned long rate, 29162306a36Sopenharmony_ci unsigned long parent_rate, u8 index); 29262306a36Sopenharmony_ciint omap3_dpll5_set_rate(struct clk_hw *hw, unsigned long rate, 29362306a36Sopenharmony_ci unsigned long parent_rate); 29462306a36Sopenharmony_civoid omap3_clk_lock_dpll5(void); 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ciunsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw, 29762306a36Sopenharmony_ci unsigned long parent_rate); 29862306a36Sopenharmony_cilong omap4_dpll_regm4xen_round_rate(struct clk_hw *hw, 29962306a36Sopenharmony_ci unsigned long target_rate, 30062306a36Sopenharmony_ci unsigned long *parent_rate); 30162306a36Sopenharmony_ciint omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw, 30262306a36Sopenharmony_ci struct clk_rate_request *req); 30362306a36Sopenharmony_ciint omap2_clk_for_each(int (*fn)(struct clk_hw_omap *hw)); 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_ciextern struct ti_clk_ll_ops *ti_clk_ll_ops; 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci#endif 308