18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Clock framework definitions for SPEAr platform
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2012 ST Microelectronics
58c2ecf20Sopenharmony_ci * Viresh Kumar <vireshk@kernel.org>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public
88c2ecf20Sopenharmony_ci * License version 2. This program is licensed "as is" without any
98c2ecf20Sopenharmony_ci * warranty of any kind, whether express or implied.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __SPEAR_CLK_H
138c2ecf20Sopenharmony_ci#define __SPEAR_CLK_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
168c2ecf20Sopenharmony_ci#include <linux/spinlock_types.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* Auxiliary Synth clk */
208c2ecf20Sopenharmony_ci/* Default masks */
218c2ecf20Sopenharmony_ci#define AUX_EQ_SEL_SHIFT	30
228c2ecf20Sopenharmony_ci#define AUX_EQ_SEL_MASK		1
238c2ecf20Sopenharmony_ci#define AUX_EQ1_SEL		0
248c2ecf20Sopenharmony_ci#define AUX_EQ2_SEL		1
258c2ecf20Sopenharmony_ci#define AUX_XSCALE_SHIFT	16
268c2ecf20Sopenharmony_ci#define AUX_XSCALE_MASK		0xFFF
278c2ecf20Sopenharmony_ci#define AUX_YSCALE_SHIFT	0
288c2ecf20Sopenharmony_ci#define AUX_YSCALE_MASK		0xFFF
298c2ecf20Sopenharmony_ci#define AUX_SYNT_ENB		31
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistruct aux_clk_masks {
328c2ecf20Sopenharmony_ci	u32 eq_sel_mask;
338c2ecf20Sopenharmony_ci	u32 eq_sel_shift;
348c2ecf20Sopenharmony_ci	u32 eq1_mask;
358c2ecf20Sopenharmony_ci	u32 eq2_mask;
368c2ecf20Sopenharmony_ci	u32 xscale_sel_mask;
378c2ecf20Sopenharmony_ci	u32 xscale_sel_shift;
388c2ecf20Sopenharmony_ci	u32 yscale_sel_mask;
398c2ecf20Sopenharmony_ci	u32 yscale_sel_shift;
408c2ecf20Sopenharmony_ci	u32 enable_bit;
418c2ecf20Sopenharmony_ci};
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct aux_rate_tbl {
448c2ecf20Sopenharmony_ci	u16 xscale;
458c2ecf20Sopenharmony_ci	u16 yscale;
468c2ecf20Sopenharmony_ci	u8 eq;
478c2ecf20Sopenharmony_ci};
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct clk_aux {
508c2ecf20Sopenharmony_ci	struct			clk_hw hw;
518c2ecf20Sopenharmony_ci	void __iomem		*reg;
528c2ecf20Sopenharmony_ci	const struct aux_clk_masks *masks;
538c2ecf20Sopenharmony_ci	struct aux_rate_tbl	*rtbl;
548c2ecf20Sopenharmony_ci	u8			rtbl_cnt;
558c2ecf20Sopenharmony_ci	spinlock_t		*lock;
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* Fractional Synth clk */
598c2ecf20Sopenharmony_cistruct frac_rate_tbl {
608c2ecf20Sopenharmony_ci	u32 div;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct clk_frac {
648c2ecf20Sopenharmony_ci	struct			clk_hw hw;
658c2ecf20Sopenharmony_ci	void __iomem		*reg;
668c2ecf20Sopenharmony_ci	struct frac_rate_tbl	*rtbl;
678c2ecf20Sopenharmony_ci	u8			rtbl_cnt;
688c2ecf20Sopenharmony_ci	spinlock_t		*lock;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* GPT clk */
728c2ecf20Sopenharmony_cistruct gpt_rate_tbl {
738c2ecf20Sopenharmony_ci	u16 mscale;
748c2ecf20Sopenharmony_ci	u16 nscale;
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistruct clk_gpt {
788c2ecf20Sopenharmony_ci	struct			clk_hw hw;
798c2ecf20Sopenharmony_ci	void __iomem		*reg;
808c2ecf20Sopenharmony_ci	struct gpt_rate_tbl	*rtbl;
818c2ecf20Sopenharmony_ci	u8			rtbl_cnt;
828c2ecf20Sopenharmony_ci	spinlock_t		*lock;
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* VCO-PLL clk */
868c2ecf20Sopenharmony_cistruct pll_rate_tbl {
878c2ecf20Sopenharmony_ci	u8 mode;
888c2ecf20Sopenharmony_ci	u16 m;
898c2ecf20Sopenharmony_ci	u8 n;
908c2ecf20Sopenharmony_ci	u8 p;
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct clk_vco {
948c2ecf20Sopenharmony_ci	struct			clk_hw hw;
958c2ecf20Sopenharmony_ci	void __iomem		*mode_reg;
968c2ecf20Sopenharmony_ci	void __iomem		*cfg_reg;
978c2ecf20Sopenharmony_ci	struct pll_rate_tbl	*rtbl;
988c2ecf20Sopenharmony_ci	u8			rtbl_cnt;
998c2ecf20Sopenharmony_ci	spinlock_t		*lock;
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct clk_pll {
1038c2ecf20Sopenharmony_ci	struct			clk_hw hw;
1048c2ecf20Sopenharmony_ci	struct clk_vco		*vco;
1058c2ecf20Sopenharmony_ci	const char		*parent[1];
1068c2ecf20Sopenharmony_ci	spinlock_t		*lock;
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_citypedef unsigned long (*clk_calc_rate)(struct clk_hw *hw, unsigned long prate,
1108c2ecf20Sopenharmony_ci		int index);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/* clk register routines */
1138c2ecf20Sopenharmony_cistruct clk *clk_register_aux(const char *aux_name, const char *gate_name,
1148c2ecf20Sopenharmony_ci		const char *parent_name, unsigned long flags, void __iomem *reg,
1158c2ecf20Sopenharmony_ci		const struct aux_clk_masks *masks, struct aux_rate_tbl *rtbl,
1168c2ecf20Sopenharmony_ci		u8 rtbl_cnt, spinlock_t *lock, struct clk **gate_clk);
1178c2ecf20Sopenharmony_cistruct clk *clk_register_frac(const char *name, const char *parent_name,
1188c2ecf20Sopenharmony_ci		unsigned long flags, void __iomem *reg,
1198c2ecf20Sopenharmony_ci		struct frac_rate_tbl *rtbl, u8 rtbl_cnt, spinlock_t *lock);
1208c2ecf20Sopenharmony_cistruct clk *clk_register_gpt(const char *name, const char *parent_name, unsigned
1218c2ecf20Sopenharmony_ci		long flags, void __iomem *reg, struct gpt_rate_tbl *rtbl, u8
1228c2ecf20Sopenharmony_ci		rtbl_cnt, spinlock_t *lock);
1238c2ecf20Sopenharmony_cistruct clk *clk_register_vco_pll(const char *vco_name, const char *pll_name,
1248c2ecf20Sopenharmony_ci		const char *vco_gate_name, const char *parent_name,
1258c2ecf20Sopenharmony_ci		unsigned long flags, void __iomem *mode_reg, void __iomem
1268c2ecf20Sopenharmony_ci		*cfg_reg, struct pll_rate_tbl *rtbl, u8 rtbl_cnt,
1278c2ecf20Sopenharmony_ci		spinlock_t *lock, struct clk **pll_clk,
1288c2ecf20Sopenharmony_ci		struct clk **vco_gate_clk);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_cilong clk_round_rate_index(struct clk_hw *hw, unsigned long drate,
1318c2ecf20Sopenharmony_ci		unsigned long parent_rate, clk_calc_rate calc_rate, u8 rtbl_cnt,
1328c2ecf20Sopenharmony_ci		int *index);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#endif /* __SPEAR_CLK_H */
135