xref: /openbmc/u-boot/drivers/clk/renesas/renesas-cpg-mssr.h (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2f77b5a4cSMarek Vasut /*
3f77b5a4cSMarek Vasut  * Renesas RCar Gen3 CPG MSSR driver
4f77b5a4cSMarek Vasut  *
5f77b5a4cSMarek Vasut  * Copyright (C) 2017-2018 Marek Vasut <marek.vasut@gmail.com>
6f77b5a4cSMarek Vasut  *
7f77b5a4cSMarek Vasut  * Based on the following driver from Linux kernel:
8f77b5a4cSMarek Vasut  * r8a7796 Clock Pulse Generator / Module Standby and Software Reset
9f77b5a4cSMarek Vasut  *
10f77b5a4cSMarek Vasut  * Copyright (C) 2016 Glider bvba
11f77b5a4cSMarek Vasut  */
12f77b5a4cSMarek Vasut 
13f77b5a4cSMarek Vasut #ifndef __DRIVERS_CLK_RENESAS_CPG_MSSR__
14f77b5a4cSMarek Vasut #define __DRIVERS_CLK_RENESAS_CPG_MSSR__
15f77b5a4cSMarek Vasut 
16f77b5a4cSMarek Vasut struct cpg_mssr_info {
17f77b5a4cSMarek Vasut 	const struct cpg_core_clk	*core_clk;
18f77b5a4cSMarek Vasut 	unsigned int			core_clk_size;
19f77b5a4cSMarek Vasut 	const struct mssr_mod_clk	*mod_clk;
20f77b5a4cSMarek Vasut 	unsigned int			mod_clk_size;
21f77b5a4cSMarek Vasut 	const struct mstp_stop_table	*mstp_table;
22f77b5a4cSMarek Vasut 	unsigned int			mstp_table_size;
23f77b5a4cSMarek Vasut 	const char			*reset_node;
24f77b5a4cSMarek Vasut 	const char			*extalr_node;
25dedb60fbSMarek Vasut 	const char			*extal_usb_node;
26f11c9679SMarek Vasut 	unsigned int			mod_clk_base;
27f11c9679SMarek Vasut 	unsigned int			clk_extal_id;
28f11c9679SMarek Vasut 	unsigned int			clk_extalr_id;
29dedb60fbSMarek Vasut 	unsigned int			clk_extal_usb_id;
30dedb60fbSMarek Vasut 	unsigned int			pll0_div;
317c885563SMarek Vasut 	const void			*(*get_pll_config)(const u32 cpg_mode);
32f77b5a4cSMarek Vasut };
33f77b5a4cSMarek Vasut 
34f77b5a4cSMarek Vasut /*
35f77b5a4cSMarek Vasut  * Definitions of CPG Core Clocks
36f77b5a4cSMarek Vasut  *
37f77b5a4cSMarek Vasut  * These include:
38f77b5a4cSMarek Vasut  *   - Clock outputs exported to DT
39f77b5a4cSMarek Vasut  *   - External input clocks
40f77b5a4cSMarek Vasut  *   - Internal CPG clocks
41f77b5a4cSMarek Vasut  */
42f77b5a4cSMarek Vasut struct cpg_core_clk {
43f77b5a4cSMarek Vasut 	/* Common */
44f77b5a4cSMarek Vasut 	const char *name;
45f77b5a4cSMarek Vasut 	unsigned int id;
46f77b5a4cSMarek Vasut 	unsigned int type;
47f77b5a4cSMarek Vasut 	/* Depending on type */
48f77b5a4cSMarek Vasut 	unsigned int parent;	/* Core Clocks only */
49f77b5a4cSMarek Vasut 	unsigned int div;
50f77b5a4cSMarek Vasut 	unsigned int mult;
51f77b5a4cSMarek Vasut 	unsigned int offset;
52f77b5a4cSMarek Vasut };
53f77b5a4cSMarek Vasut 
54f77b5a4cSMarek Vasut enum clk_types {
55f77b5a4cSMarek Vasut 	/* Generic */
56f77b5a4cSMarek Vasut 	CLK_TYPE_IN,		/* External Clock Input */
57f77b5a4cSMarek Vasut 	CLK_TYPE_FF,		/* Fixed Factor Clock */
5828b8f225SMarek Vasut 	CLK_TYPE_DIV6P1,	/* DIV6 Clock with 1 parent clock */
5928b8f225SMarek Vasut 	CLK_TYPE_DIV6_RO,	/* DIV6 Clock read only with extra divisor */
60f77b5a4cSMarek Vasut 
61f77b5a4cSMarek Vasut 	/* Custom definitions start here */
62f77b5a4cSMarek Vasut 	CLK_TYPE_CUSTOM,
63f77b5a4cSMarek Vasut };
64f77b5a4cSMarek Vasut 
65f77b5a4cSMarek Vasut #define DEF_TYPE(_name, _id, _type...)	\
66f77b5a4cSMarek Vasut 	{ .name = _name, .id = _id, .type = _type }
67f77b5a4cSMarek Vasut #define DEF_BASE(_name, _id, _type, _parent...)	\
68f77b5a4cSMarek Vasut 	DEF_TYPE(_name, _id, _type, .parent = _parent)
69f77b5a4cSMarek Vasut 
70f77b5a4cSMarek Vasut #define DEF_INPUT(_name, _id) \
71f77b5a4cSMarek Vasut 	DEF_TYPE(_name, _id, CLK_TYPE_IN)
72f77b5a4cSMarek Vasut #define DEF_FIXED(_name, _id, _parent, _div, _mult)	\
73f77b5a4cSMarek Vasut 	DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
7428b8f225SMarek Vasut #define DEF_DIV6P1(_name, _id, _parent, _offset)	\
7528b8f225SMarek Vasut 	DEF_BASE(_name, _id, CLK_TYPE_DIV6P1, _parent, .offset = _offset)
7628b8f225SMarek Vasut #define DEF_DIV6_RO(_name, _id, _parent, _offset, _div)	\
7728b8f225SMarek Vasut 	DEF_BASE(_name, _id, CLK_TYPE_DIV6_RO, _parent, .offset = _offset, .div = _div, .mult = 1)
78f77b5a4cSMarek Vasut 
79f77b5a4cSMarek Vasut /*
80f77b5a4cSMarek Vasut  * Definitions of Module Clocks
81f77b5a4cSMarek Vasut  */
82f77b5a4cSMarek Vasut struct mssr_mod_clk {
83f77b5a4cSMarek Vasut 	const char *name;
84f77b5a4cSMarek Vasut 	unsigned int id;
85f77b5a4cSMarek Vasut 	unsigned int parent;	/* Add MOD_CLK_BASE for Module Clocks */
86f77b5a4cSMarek Vasut };
87f77b5a4cSMarek Vasut 
88f77b5a4cSMarek Vasut /* Convert from sparse base-100 to packed index space */
89f77b5a4cSMarek Vasut #define MOD_CLK_PACK(x)	((x) - ((x) / 100) * (100 - 32))
90f77b5a4cSMarek Vasut 
91f77b5a4cSMarek Vasut #define MOD_CLK_ID(x)	(MOD_CLK_BASE + MOD_CLK_PACK(x))
92f77b5a4cSMarek Vasut 
93f77b5a4cSMarek Vasut #define DEF_MOD(_name, _mod, _parent...)	\
94f77b5a4cSMarek Vasut 	{ .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
95f77b5a4cSMarek Vasut 
96f77b5a4cSMarek Vasut struct mstp_stop_table {
97ff50b323SMarek Vasut 	u32	sdis;
98ff50b323SMarek Vasut 	u32	sen;
99ff50b323SMarek Vasut 	u32	rdis;
100ff50b323SMarek Vasut 	u32	ren;
101f77b5a4cSMarek Vasut };
102f77b5a4cSMarek Vasut 
103f77b5a4cSMarek Vasut #define TSTR0		0x04
104f77b5a4cSMarek Vasut #define TSTR0_STR0	BIT(0)
105f77b5a4cSMarek Vasut 
106d2628671SMarek Vasut bool renesas_clk_is_mod(struct clk *clk);
107d2628671SMarek Vasut int renesas_clk_get_mod(struct clk *clk, struct cpg_mssr_info *info,
108d2628671SMarek Vasut 			const struct mssr_mod_clk **mssr);
109d2628671SMarek Vasut int renesas_clk_get_core(struct clk *clk, struct cpg_mssr_info *info,
110d2628671SMarek Vasut 			 const struct cpg_core_clk **core);
111d2628671SMarek Vasut int renesas_clk_get_parent(struct clk *clk, struct cpg_mssr_info *info,
112d2628671SMarek Vasut 			   struct clk *parent);
113d2628671SMarek Vasut int renesas_clk_endisable(struct clk *clk, void __iomem *base, bool enable);
114d2628671SMarek Vasut int renesas_clk_remove(void __iomem *base, struct cpg_mssr_info *info);
115d2628671SMarek Vasut 
116f77b5a4cSMarek Vasut #endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */
117