162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2014 MediaTek Inc. 462306a36Sopenharmony_ci * Author: James Liao <jamesjj.liao@mediatek.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef __DRV_CLK_MTK_PLL_H 862306a36Sopenharmony_ci#define __DRV_CLK_MTK_PLL_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/clk-provider.h> 1162306a36Sopenharmony_ci#include <linux/types.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_cistruct clk_ops; 1462306a36Sopenharmony_cistruct clk_hw_onecell_data; 1562306a36Sopenharmony_cistruct device_node; 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistruct mtk_pll_div_table { 1862306a36Sopenharmony_ci u32 div; 1962306a36Sopenharmony_ci unsigned long freq; 2062306a36Sopenharmony_ci}; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#define HAVE_RST_BAR BIT(0) 2362306a36Sopenharmony_ci#define PLL_AO BIT(1) 2462306a36Sopenharmony_ci#define POSTDIV_MASK GENMASK(2, 0) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cistruct mtk_pll_data { 2762306a36Sopenharmony_ci int id; 2862306a36Sopenharmony_ci const char *name; 2962306a36Sopenharmony_ci u32 reg; 3062306a36Sopenharmony_ci u32 pwr_reg; 3162306a36Sopenharmony_ci u32 en_mask; 3262306a36Sopenharmony_ci u32 pd_reg; 3362306a36Sopenharmony_ci u32 tuner_reg; 3462306a36Sopenharmony_ci u32 tuner_en_reg; 3562306a36Sopenharmony_ci u8 tuner_en_bit; 3662306a36Sopenharmony_ci int pd_shift; 3762306a36Sopenharmony_ci unsigned int flags; 3862306a36Sopenharmony_ci const struct clk_ops *ops; 3962306a36Sopenharmony_ci u32 rst_bar_mask; 4062306a36Sopenharmony_ci unsigned long fmin; 4162306a36Sopenharmony_ci unsigned long fmax; 4262306a36Sopenharmony_ci int pcwbits; 4362306a36Sopenharmony_ci int pcwibits; 4462306a36Sopenharmony_ci u32 pcw_reg; 4562306a36Sopenharmony_ci int pcw_shift; 4662306a36Sopenharmony_ci u32 pcw_chg_reg; 4762306a36Sopenharmony_ci const struct mtk_pll_div_table *div_table; 4862306a36Sopenharmony_ci const char *parent_name; 4962306a36Sopenharmony_ci u32 en_reg; 5062306a36Sopenharmony_ci u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */ 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/* 5462306a36Sopenharmony_ci * MediaTek PLLs are configured through their pcw value. The pcw value describes 5562306a36Sopenharmony_ci * a divider in the PLL feedback loop which consists of 7 bits for the integer 5662306a36Sopenharmony_ci * part and the remaining bits (if present) for the fractional part. Also they 5762306a36Sopenharmony_ci * have a 3 bit power-of-two post divider. 5862306a36Sopenharmony_ci */ 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistruct mtk_clk_pll { 6162306a36Sopenharmony_ci struct clk_hw hw; 6262306a36Sopenharmony_ci void __iomem *base_addr; 6362306a36Sopenharmony_ci void __iomem *pd_addr; 6462306a36Sopenharmony_ci void __iomem *pwr_addr; 6562306a36Sopenharmony_ci void __iomem *tuner_addr; 6662306a36Sopenharmony_ci void __iomem *tuner_en_addr; 6762306a36Sopenharmony_ci void __iomem *pcw_addr; 6862306a36Sopenharmony_ci void __iomem *pcw_chg_addr; 6962306a36Sopenharmony_ci void __iomem *en_addr; 7062306a36Sopenharmony_ci const struct mtk_pll_data *data; 7162306a36Sopenharmony_ci}; 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciint mtk_clk_register_plls(struct device_node *node, 7462306a36Sopenharmony_ci const struct mtk_pll_data *plls, int num_plls, 7562306a36Sopenharmony_ci struct clk_hw_onecell_data *clk_data); 7662306a36Sopenharmony_civoid mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls, 7762306a36Sopenharmony_ci struct clk_hw_onecell_data *clk_data); 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciextern const struct clk_ops mtk_pll_ops; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_cistatic inline struct mtk_clk_pll *to_mtk_clk_pll(struct clk_hw *hw) 8262306a36Sopenharmony_ci{ 8362306a36Sopenharmony_ci return container_of(hw, struct mtk_clk_pll, hw); 8462306a36Sopenharmony_ci} 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciint mtk_pll_is_prepared(struct clk_hw *hw); 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciint mtk_pll_prepare(struct clk_hw *hw); 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_civoid mtk_pll_unprepare(struct clk_hw *hw); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciunsigned long mtk_pll_recalc_rate(struct clk_hw *hw, unsigned long parent_rate); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_civoid mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv, 9562306a36Sopenharmony_ci u32 freq, u32 fin); 9662306a36Sopenharmony_ciint mtk_pll_set_rate(struct clk_hw *hw, unsigned long rate, 9762306a36Sopenharmony_ci unsigned long parent_rate); 9862306a36Sopenharmony_cilong mtk_pll_round_rate(struct clk_hw *hw, unsigned long rate, 9962306a36Sopenharmony_ci unsigned long *prate); 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistruct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll, 10262306a36Sopenharmony_ci const struct mtk_pll_data *data, 10362306a36Sopenharmony_ci void __iomem *base, 10462306a36Sopenharmony_ci const struct clk_ops *pll_ops); 10562306a36Sopenharmony_cistruct clk_hw *mtk_clk_register_pll(const struct mtk_pll_data *data, 10662306a36Sopenharmony_ci void __iomem *base); 10762306a36Sopenharmony_civoid mtk_clk_unregister_pll(struct clk_hw *hw); 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci__iomem void *mtk_clk_pll_get_base(struct clk_hw *hw, 11062306a36Sopenharmony_ci const struct mtk_pll_data *data); 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#endif /* __DRV_CLK_MTK_PLL_H */ 113