1170530Ssam/* SPDX-License-Identifier: GPL-2.0 */
2178354Ssam//
3170530Ssam// Spreadtrum pll clock driver
4170530Ssam//
5170530Ssam// Copyright (C) 2015~2017 Spreadtrum, Inc.
6170530Ssam// Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
7170530Ssam
8170530Ssam#ifndef _SPRD_PLL_H_
9170530Ssam#define _SPRD_PLL_H_
10170530Ssam
11170530Ssam#include "common.h"
12170530Ssam
13170530Ssamstruct reg_cfg {
14170530Ssam	u32 val;
15170530Ssam	u32 msk;
16170530Ssam};
17170530Ssam
18170530Ssamstruct clk_bit_field {
19170530Ssam	u8 shift;
20170530Ssam	u8 width;
21170530Ssam};
22170530Ssam
23170530Ssamenum {
24170530Ssam	PLL_LOCK_DONE,
25170530Ssam	PLL_DIV_S,
26170530Ssam	PLL_MOD_EN,
27170530Ssam	PLL_SDM_EN,
28170530Ssam	PLL_REFIN,
29170530Ssam	PLL_IBIAS,
30170530Ssam	PLL_N,
31170530Ssam	PLL_NINT,
32178354Ssam	PLL_KINT,
33178354Ssam	PLL_PREDIV,
34170530Ssam	PLL_POSTDIV,
35170530Ssam
36191746Sthompsa	PLL_FACT_MAX
37170530Ssam};
38295126Sglebius
39191746Sthompsa/*
40170530Ssam * struct sprd_pll - definition of adjustable pll clock
41170530Ssam *
42170530Ssam * @reg:	registers used to set the configuration of pll clock,
43170530Ssam *		reg[0] shows how many registers this pll clock uses.
44257176Sglebius * @itable:	pll ibias table, itable[0] means how many items this
45170530Ssam *		table includes
46170530Ssam * @udelay	delay time after setting rate
47170530Ssam * @factors	used to calculate the pll clock rate
48170530Ssam * @fvco:	fvco threshold rate
49170530Ssam * @fflag:	fvco flag
50276730Sadrian */
51276730Sadrianstruct sprd_pll {
52276730Sadrian	u32 regs_num;
53170530Ssam	const u64 *itable;
54170530Ssam	const struct clk_bit_field *factors;
55170530Ssam	u16 udelay;
56170530Ssam	u16 k1;
57188776Ssam	u16 k2;
58178354Ssam	u16 fflag;
59170530Ssam	u64 fvco;
60188776Ssam
61188776Ssam	struct sprd_clk_common	common;
62188776Ssam};
63188776Ssam
64188776Ssam#define SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg,	\
65188776Ssam			    _regs_num, _itable, _factors,	\
66188776Ssam			    _udelay, _k1, _k2, _fflag,		\
67188776Ssam			    _fvco, _fn)				\
68188782Ssam	struct sprd_pll _struct = {				\
69188782Ssam		.regs_num	= _regs_num,			\
70188776Ssam		.itable		= _itable,			\
71170530Ssam		.factors	= _factors,			\
72170530Ssam		.udelay		= _udelay,			\
73170530Ssam		.k1		= _k1,				\
74170530Ssam		.k2		= _k2,				\
75276730Sadrian		.fflag		= _fflag,			\
76284143Sadrian		.fvco		= _fvco,			\
77284143Sadrian		.common		= {				\
78276730Sadrian			.regmap		= NULL,			\
79284143Sadrian			.reg		= _reg,			\
80284143Sadrian			.hw.init	= _fn(_name, _parent,	\
81284143Sadrian					      &sprd_pll_ops, 0),\
82284143Sadrian		},						\
83170530Ssam	}
84170530Ssam
85170530Ssam#define SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg,	\
86170530Ssam				    _regs_num, _itable, _factors,	\
87170530Ssam				    _udelay, _k1, _k2, _fflag, _fvco)	\
88170530Ssam	SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num,	\
89276730Sadrian			    _itable, _factors, _udelay, _k1, _k2,	\
90276730Sadrian			    _fflag, _fvco, CLK_HW_INIT)
91284143Sadrian
92276730Sadrian#define SPRD_PLL_WITH_ITABLE_K(_struct, _name, _parent, _reg,		\
93276730Sadrian			       _regs_num, _itable, _factors,		\
94276730Sadrian			       _udelay, _k1, _k2)			\
95284143Sadrian	SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg,	\
96170530Ssam				    _regs_num, _itable, _factors,	\
97170530Ssam				    _udelay, _k1, _k2, 0, 0)
98188776Ssam
99188776Ssam#define SPRD_PLL_WITH_ITABLE_1K(_struct, _name, _parent, _reg,		\
100188776Ssam				_regs_num, _itable, _factors, _udelay)	\
101188776Ssam	SPRD_PLL_WITH_ITABLE_K_FVCO(_struct, _name, _parent, _reg,	\
102188776Ssam				    _regs_num, _itable, _factors,	\
103188776Ssam				    _udelay, 1000, 1000, 0, 0)
104188776Ssam
105188776Ssam#define SPRD_PLL_FW_NAME(_struct, _name, _parent, _reg, _regs_num,	\
106188776Ssam			 _itable, _factors, _udelay, _k1, _k2,		\
107188776Ssam			 _fflag, _fvco)					\
108188776Ssam	SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num,	\
109188776Ssam			    _itable, _factors, _udelay, _k1, _k2,	\
110188776Ssam			    _fflag, _fvco, CLK_HW_INIT_FW_NAME)
111188782Ssam
112188782Ssam#define SPRD_PLL_HW(_struct, _name, _parent, _reg, _regs_num, _itable,	\
113188782Ssam		    _factors, _udelay, _k1, _k2, _fflag, _fvco)		\
114188782Ssam	SPRD_PLL_HW_INIT_FN(_struct, _name, _parent, _reg, _regs_num,	\
115188776Ssam			    _itable, _factors, _udelay, _k1, _k2,	\
116188776Ssam			    _fflag, _fvco, CLK_HW_INIT_HW)
117188776Ssam
118188776Ssamstatic inline struct sprd_pll *hw_to_sprd_pll(struct clk_hw *hw)
119188776Ssam{
120178354Ssam	struct sprd_clk_common *common = hw_to_sprd_clk_common(hw);
121178354Ssam
122178354Ssam	return container_of(common, struct sprd_pll, common);
123178354Ssam}
124284143Sadrian
125344223Savosextern const struct clk_ops sprd_pll_ops;
126284143Sadrian
127178354Ssam#endif /* _SPRD_PLL_H_ */
128178354Ssam