18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// Spreadtrum pll clock driver 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright (C) 2015~2017 Spreadtrum, Inc. 68c2ecf20Sopenharmony_ci// Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _SPRD_PLL_H_ 98c2ecf20Sopenharmony_ci#define _SPRD_PLL_H_ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include "common.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct reg_cfg { 148c2ecf20Sopenharmony_ci u32 val; 158c2ecf20Sopenharmony_ci u32 msk; 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cistruct clk_bit_field { 198c2ecf20Sopenharmony_ci u8 shift; 208c2ecf20Sopenharmony_ci u8 width; 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cienum { 248c2ecf20Sopenharmony_ci PLL_LOCK_DONE, 258c2ecf20Sopenharmony_ci PLL_DIV_S, 268c2ecf20Sopenharmony_ci PLL_MOD_EN, 278c2ecf20Sopenharmony_ci PLL_SDM_EN, 288c2ecf20Sopenharmony_ci PLL_REFIN, 298c2ecf20Sopenharmony_ci PLL_IBIAS, 308c2ecf20Sopenharmony_ci PLL_N, 318c2ecf20Sopenharmony_ci PLL_NINT, 328c2ecf20Sopenharmony_ci PLL_KINT, 338c2ecf20Sopenharmony_ci PLL_PREDIV, 348c2ecf20Sopenharmony_ci PLL_POSTDIV, 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci PLL_FACT_MAX 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * struct sprd_pll - definition of adjustable pll clock 418c2ecf20Sopenharmony_ci * 428c2ecf20Sopenharmony_ci * @reg: registers used to set the configuration of pll clock, 438c2ecf20Sopenharmony_ci * reg[0] shows how many registers this pll clock uses. 448c2ecf20Sopenharmony_ci * @itable: pll ibias table, itable[0] means how many items this 458c2ecf20Sopenharmony_ci * table includes 468c2ecf20Sopenharmony_ci * @udelay delay time after setting rate 478c2ecf20Sopenharmony_ci * @factors used to calculate the pll clock rate 488c2ecf20Sopenharmony_ci * @fvco: fvco threshold rate 498c2ecf20Sopenharmony_ci * @fflag: fvco flag 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_cistruct sprd_pll { 528c2ecf20Sopenharmony_ci u32 regs_num; 538c2ecf20Sopenharmony_ci const u64 *itable; 548c2ecf20Sopenharmony_ci const struct clk_bit_field *factors; 558c2ecf20Sopenharmony_ci u16 udelay; 568c2ecf20Sopenharmony_ci u16 k1; 578c2ecf20Sopenharmony_ci u16 k2; 588c2ecf20Sopenharmony_ci u16 fflag; 598c2ecf20Sopenharmony_ci u64 fvco; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci struct sprd_clk_common common; 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, \ 658c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, \ 668c2ecf20Sopenharmony_ci _udelay, _k1, _k2, _fflag, \ 678c2ecf20Sopenharmony_ci _fvco, _fn) \ 688c2ecf20Sopenharmony_ci struct sprd_pll _struct = { \ 698c2ecf20Sopenharmony_ci .regs_num = _regs_num, \ 708c2ecf20Sopenharmony_ci .itable = _itable, \ 718c2ecf20Sopenharmony_ci .factors = _factors, \ 728c2ecf20Sopenharmony_ci .udelay = _udelay, \ 738c2ecf20Sopenharmony_ci .k1 = _k1, \ 748c2ecf20Sopenharmony_ci .k2 = _k2, \ 758c2ecf20Sopenharmony_ci .fflag = _fflag, \ 768c2ecf20Sopenharmony_ci .fvco = _fvco, \ 778c2ecf20Sopenharmony_ci .common = { \ 788c2ecf20Sopenharmony_ci .regmap = NULL, \ 798c2ecf20Sopenharmony_ci .reg = _reg, \ 808c2ecf20Sopenharmony_ci .hw.init = _fn(_name, _parent, \ 818c2ecf20Sopenharmony_ci &sprd_pll_ops, 0),\ 828c2ecf20Sopenharmony_ci }, \ 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg, \ 868c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, \ 878c2ecf20Sopenharmony_ci _udelay, _k1, _k2, _fflag, _fvco) \ 888c2ecf20Sopenharmony_ci SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num, \ 898c2ecf20Sopenharmony_ci _itable, _factors, _udelay, _k1, _k2, \ 908c2ecf20Sopenharmony_ci _fflag, _fvco, CLK_HW_INIT) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define SPRD_PLL_WITH_ITABLE_K(_struct, _name, _parent, _reg, \ 938c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, \ 948c2ecf20Sopenharmony_ci _udelay, _k1, _k2) \ 958c2ecf20Sopenharmony_ci SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg, \ 968c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, \ 978c2ecf20Sopenharmony_ci _udelay, _k1, _k2, 0, 0) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define SPRD_PLL_WITH_ITABLE_1K(_struct, _name, _parent, _reg, \ 1008c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, _udelay) \ 1018c2ecf20Sopenharmony_ci SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg, \ 1028c2ecf20Sopenharmony_ci _regs_num, _itable, _factors, \ 1038c2ecf20Sopenharmony_ci _udelay, 1000, 1000, 0, 0) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define SPRD_PLL_FW_NAME(_struct, _name, _parent, _reg, _regs_num, \ 1068c2ecf20Sopenharmony_ci _itable, _factors, _udelay, _k1, _k2, \ 1078c2ecf20Sopenharmony_ci _fflag, _fvco) \ 1088c2ecf20Sopenharmony_ci SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num, \ 1098c2ecf20Sopenharmony_ci _itable, _factors, _udelay, _k1, _k2, \ 1108c2ecf20Sopenharmony_ci _fflag, _fvco, CLK_HW_INIT_FW_NAME) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define SPRD_PLL_HW(_struct, _name, _parent, _reg, _regs_num, _itable, \ 1138c2ecf20Sopenharmony_ci _factors, _udelay, _k1, _k2, _fflag, _fvco) \ 1148c2ecf20Sopenharmony_ci SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num, \ 1158c2ecf20Sopenharmony_ci _itable, _factors, _udelay, _k1, _k2, \ 1168c2ecf20Sopenharmony_ci _fflag, _fvco, CLK_HW_INIT_HW) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistatic inline struct sprd_pll *hw_to_sprd_pll(struct clk_hw *hw) 1198c2ecf20Sopenharmony_ci{ 1208c2ecf20Sopenharmony_ci struct sprd_clk_common *common = hw_to_sprd_clk_common(hw); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci return container_of(common, struct sprd_pll, common); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ciextern const struct clk_ops sprd_pll_ops; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#endif /* _SPRD_PLL_H_ */ 128