162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Marvell PXA family clocks
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2014 Robert Jarzmik
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Common clock code for PXA clocks ("CKEN" type clocks + DT)
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci#ifndef _CLK_PXA_
1062306a36Sopenharmony_ci#define _CLK_PXA_
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define CLKCFG_TURBO		0x1
1362306a36Sopenharmony_ci#define CLKCFG_FCS		0x2
1462306a36Sopenharmony_ci#define CLKCFG_HALFTURBO	0x4
1562306a36Sopenharmony_ci#define CLKCFG_FASTBUS		0x8
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define PARENTS(name) \
1862306a36Sopenharmony_ci	static const char *const name ## _parents[] __initconst
1962306a36Sopenharmony_ci#define MUX_RO_RATE_RO_OPS(name, clk_name)			\
2062306a36Sopenharmony_ci	static struct clk_hw name ## _mux_hw;			\
2162306a36Sopenharmony_ci	static struct clk_hw name ## _rate_hw;			\
2262306a36Sopenharmony_ci	static const struct clk_ops name ## _mux_ops = {	\
2362306a36Sopenharmony_ci		.get_parent = name ## _get_parent,		\
2462306a36Sopenharmony_ci		.set_parent = dummy_clk_set_parent,		\
2562306a36Sopenharmony_ci	};							\
2662306a36Sopenharmony_ci	static const struct clk_ops name ## _rate_ops = {	\
2762306a36Sopenharmony_ci		.recalc_rate = name ## _get_rate,		\
2862306a36Sopenharmony_ci	};							\
2962306a36Sopenharmony_ci	static struct clk * __init clk_register_ ## name(void)	\
3062306a36Sopenharmony_ci	{							\
3162306a36Sopenharmony_ci		return clk_register_composite(NULL, clk_name,	\
3262306a36Sopenharmony_ci			name ## _parents,			\
3362306a36Sopenharmony_ci			ARRAY_SIZE(name ## _parents),		\
3462306a36Sopenharmony_ci			&name ## _mux_hw, &name ## _mux_ops,	\
3562306a36Sopenharmony_ci			&name ## _rate_hw, &name ## _rate_ops,	\
3662306a36Sopenharmony_ci			NULL, NULL, CLK_GET_RATE_NOCACHE);	\
3762306a36Sopenharmony_ci	}
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define RATE_RO_OPS(name, clk_name)				\
4062306a36Sopenharmony_ci	static struct clk_hw name ## _rate_hw;			\
4162306a36Sopenharmony_ci	static const struct clk_ops name ## _rate_ops = {	\
4262306a36Sopenharmony_ci		.recalc_rate = name ## _get_rate,		\
4362306a36Sopenharmony_ci	};							\
4462306a36Sopenharmony_ci	static struct clk * __init clk_register_ ## name(void)	\
4562306a36Sopenharmony_ci	{							\
4662306a36Sopenharmony_ci		return clk_register_composite(NULL, clk_name,	\
4762306a36Sopenharmony_ci			name ## _parents,			\
4862306a36Sopenharmony_ci			ARRAY_SIZE(name ## _parents),		\
4962306a36Sopenharmony_ci			NULL, NULL,				\
5062306a36Sopenharmony_ci			&name ## _rate_hw, &name ## _rate_ops,	\
5162306a36Sopenharmony_ci			NULL, NULL, CLK_GET_RATE_NOCACHE);	\
5262306a36Sopenharmony_ci	}
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define RATE_OPS(name, clk_name)				\
5562306a36Sopenharmony_ci	static struct clk_hw name ## _rate_hw;			\
5662306a36Sopenharmony_ci	static const struct clk_ops name ## _rate_ops = {	\
5762306a36Sopenharmony_ci		.recalc_rate = name ## _get_rate,		\
5862306a36Sopenharmony_ci		.set_rate = name ## _set_rate,			\
5962306a36Sopenharmony_ci		.determine_rate = name ## _determine_rate,	\
6062306a36Sopenharmony_ci	};							\
6162306a36Sopenharmony_ci	static struct clk * __init clk_register_ ## name(void)	\
6262306a36Sopenharmony_ci	{							\
6362306a36Sopenharmony_ci		return clk_register_composite(NULL, clk_name,	\
6462306a36Sopenharmony_ci			name ## _parents,			\
6562306a36Sopenharmony_ci			ARRAY_SIZE(name ## _parents),		\
6662306a36Sopenharmony_ci			NULL, NULL,				\
6762306a36Sopenharmony_ci			&name ## _rate_hw, &name ## _rate_ops,	\
6862306a36Sopenharmony_ci			NULL, NULL, CLK_GET_RATE_NOCACHE);	\
6962306a36Sopenharmony_ci	}
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define MUX_OPS(name, clk_name, flags)				\
7262306a36Sopenharmony_ci	static struct clk_hw name ## _mux_hw;			\
7362306a36Sopenharmony_ci	static const struct clk_ops name ## _mux_ops = {	\
7462306a36Sopenharmony_ci		.get_parent = name ## _get_parent,		\
7562306a36Sopenharmony_ci		.set_parent = name ## _set_parent,		\
7662306a36Sopenharmony_ci		.determine_rate = name ## _determine_rate,	\
7762306a36Sopenharmony_ci	};							\
7862306a36Sopenharmony_ci	static struct clk * __init clk_register_ ## name(void)	\
7962306a36Sopenharmony_ci	{							\
8062306a36Sopenharmony_ci		return clk_register_composite(NULL, clk_name,	\
8162306a36Sopenharmony_ci			name ## _parents,			\
8262306a36Sopenharmony_ci			ARRAY_SIZE(name ## _parents),		\
8362306a36Sopenharmony_ci			&name ## _mux_hw, &name ## _mux_ops,	\
8462306a36Sopenharmony_ci			NULL, NULL,				\
8562306a36Sopenharmony_ci			NULL, NULL,				\
8662306a36Sopenharmony_ci			CLK_GET_RATE_NOCACHE | flags); \
8762306a36Sopenharmony_ci	}
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/*
9062306a36Sopenharmony_ci * CKEN clock type
9162306a36Sopenharmony_ci * This clock takes it source from 2 possible parents :
9262306a36Sopenharmony_ci *  - a low power parent
9362306a36Sopenharmony_ci *  - a normal parent
9462306a36Sopenharmony_ci *
9562306a36Sopenharmony_ci *  +------------+     +-----------+
9662306a36Sopenharmony_ci *  |  Low Power | --- | x mult_lp |
9762306a36Sopenharmony_ci *  |    Clock   |     | / div_lp  |\
9862306a36Sopenharmony_ci *  +------------+     +-----------+ \+-----+   +-----------+
9962306a36Sopenharmony_ci *                                    | Mux |---| CKEN gate |
10062306a36Sopenharmony_ci *  +------------+     +-----------+ /+-----+   +-----------+
10162306a36Sopenharmony_ci *  | High Power |     | x mult_hp |/
10262306a36Sopenharmony_ci *  |    Clock   | --- | / div_hp  |
10362306a36Sopenharmony_ci *  +------------+     +-----------+
10462306a36Sopenharmony_ci */
10562306a36Sopenharmony_cistruct desc_clk_cken {
10662306a36Sopenharmony_ci	struct clk_hw hw;
10762306a36Sopenharmony_ci	int ckid;
10862306a36Sopenharmony_ci	int cken_reg;
10962306a36Sopenharmony_ci	const char *name;
11062306a36Sopenharmony_ci	const char *dev_id;
11162306a36Sopenharmony_ci	const char *con_id;
11262306a36Sopenharmony_ci	const char * const *parent_names;
11362306a36Sopenharmony_ci	struct clk_fixed_factor lp;
11462306a36Sopenharmony_ci	struct clk_fixed_factor hp;
11562306a36Sopenharmony_ci	struct clk_gate gate;
11662306a36Sopenharmony_ci	bool (*is_in_low_power)(void);
11762306a36Sopenharmony_ci	const unsigned long flags;
11862306a36Sopenharmony_ci};
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define PXA_CKEN(_dev_id, _con_id, _name, parents, _mult_lp, _div_lp,	\
12162306a36Sopenharmony_ci		 _mult_hp, _div_hp, is_lp, _cken_reg, _cken_bit, flag)	\
12262306a36Sopenharmony_ci	{ .ckid = CLK_ ## _name, .name = #_name,			\
12362306a36Sopenharmony_ci	  .cken_reg = _cken_reg,					\
12462306a36Sopenharmony_ci	  .dev_id = _dev_id, .con_id = _con_id,	.parent_names = parents,\
12562306a36Sopenharmony_ci	  .lp = { .mult = _mult_lp, .div = _div_lp },			\
12662306a36Sopenharmony_ci	  .hp = { .mult = _mult_hp, .div = _div_hp },			\
12762306a36Sopenharmony_ci	  .is_in_low_power = is_lp,					\
12862306a36Sopenharmony_ci	  .gate = { .bit_idx = _cken_bit }, \
12962306a36Sopenharmony_ci	  .flags = flag,						\
13062306a36Sopenharmony_ci	}
13162306a36Sopenharmony_ci#define PXA_CKEN_1RATE(dev_id, con_id, name, parents, cken_reg,		\
13262306a36Sopenharmony_ci			    cken_bit, flag)				\
13362306a36Sopenharmony_ci	PXA_CKEN(dev_id, con_id, name, parents, 1, 1, 1, 1,		\
13462306a36Sopenharmony_ci		 NULL, cken_reg, cken_bit, flag)
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cistruct pxa2xx_freq {
13762306a36Sopenharmony_ci	unsigned long cpll;
13862306a36Sopenharmony_ci	unsigned int membus_khz;
13962306a36Sopenharmony_ci	unsigned int cccr;
14062306a36Sopenharmony_ci	unsigned int div2;
14162306a36Sopenharmony_ci	unsigned int clkcfg;
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistatic inline int dummy_clk_set_parent(struct clk_hw *hw, u8 index)
14562306a36Sopenharmony_ci{
14662306a36Sopenharmony_ci	return 0;
14762306a36Sopenharmony_ci}
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ciextern void clkdev_pxa_register(int ckid, const char *con_id,
15062306a36Sopenharmony_ci				const char *dev_id, struct clk *clk);
15162306a36Sopenharmony_ciextern int clk_pxa_cken_init(const struct desc_clk_cken *clks,
15262306a36Sopenharmony_ci			     int nb_clks, void __iomem *clk_regs);
15362306a36Sopenharmony_civoid clk_pxa_dt_common_init(struct device_node *np);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_civoid pxa2xx_core_turbo_switch(bool on);
15662306a36Sopenharmony_civoid pxa2xx_cpll_change(struct pxa2xx_freq *freq,
15762306a36Sopenharmony_ci			u32 (*mdrefr_dri)(unsigned int),
15862306a36Sopenharmony_ci			void __iomem *cccr);
15962306a36Sopenharmony_ciint pxa2xx_determine_rate(struct clk_rate_request *req,
16062306a36Sopenharmony_ci			  struct pxa2xx_freq *freqs,  int nb_freqs);
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci#endif
163