summaryrefslogtreecommitdiffstats
path: root/drivers/clk/tegra/clk.h
blob: 10d03573fd0b67f3615383b5786b8e49f1c29ed7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright (C) 2013 Lucas Stach <l.stach@pengutronix.de>
 *
 * Based on the Linux Tegra clock code
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/* struct tegra_clk_frac_div - fractional divider */
struct tegra_clk_frac_div {
	struct clk	hw;
	void __iomem	*reg;
	u8		flags;
	u8		shift;
	u8		width;
	u8		frac_width;
	const char	*parent;
};

#define TEGRA_DIVIDER_ROUND_UP	BIT(0)
#define TEGRA_DIVIDER_FIXED	BIT(1)
#define TEGRA_DIVIDER_INT	BIT(2)
#define TEGRA_DIVIDER_UART	BIT(3)

struct clk *tegra_clk_divider_alloc(const char *name, const char *parent_name,
		void __iomem *reg, unsigned long flags, u8 clk_divider_flags,
		u8 shift, u8 width, u8 frac_width);

void tegra_clk_divider_free(struct clk *divider);

struct clk *tegra_clk_register_divider(const char *name,
		const char *parent_name, void __iomem *reg, unsigned long flags,
		u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width);

/* struct tegra_clk_pll_freq_table - PLL frequecy table */
struct tegra_clk_pll_freq_table {
	unsigned long	input_rate;
	unsigned long	output_rate;
	u16		n;
	u16		m;
	u8		p;
	u8		cpcon;
};

/* struct clk_pll_params - PLL parameters */
struct tegra_clk_pll_params {
	unsigned long	input_min;
	unsigned long	input_max;
	unsigned long	cf_min;
	unsigned long	cf_max;
	unsigned long	vco_min;
	unsigned long	vco_max;

	u32		base_reg;
	u32		misc_reg;
	u32		aux_reg;
	u32		lock_reg;
	u8		lock_bit_idx;
	u8		lock_enable_bit_idx;
	int		lock_delay;
};

/* struct tegra_clk_pll - Tegra PLL clock */
struct tegra_clk_pll {
	struct clk	hw;
	void __iomem	*clk_base;
	u8		flags;
	unsigned long	fixed_rate;
	u8		divn_shift;
	u8		divn_width;
	u8		divm_shift;
	u8		divm_width;
	u8		divp_shift;
	u8		divp_width;
	struct tegra_clk_pll_freq_table	*freq_table;
	struct tegra_clk_pll_params	*params;
	const char	*parent;
};

#define TEGRA_PLL_USE_LOCK	BIT(0)
#define TEGRA_PLL_HAS_CPCON	BIT(1)
#define TEGRA_PLL_SET_LFCON	BIT(2)
#define TEGRA_PLL_SET_DCCON	BIT(3)
#define TEGRA_PLLU		BIT(4)
#define TEGRA_PLLM		BIT(5)
#define TEGRA_PLL_FIXED		BIT(6)
#define TEGRA_PLLE_CONFIGURE	BIT(7)

struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
		void __iomem *clk_base,
		unsigned long flags, unsigned long fixed_rate,
		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
		struct tegra_clk_pll_freq_table *freq_table);

struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
		void __iomem *clk_base,
		unsigned long flags, unsigned long fixed_rate,
		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
		struct tegra_clk_pll_freq_table *freq_table);

struct clk *tegra_clk_register_plle_tegra114(const char *name,
		const char *parent_name, void __iomem *clk_base,
		unsigned long flags, unsigned long fixed_rate,
		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
		struct tegra_clk_pll_freq_table *freq_table);

/* struct tegra_clk_pll_out - PLL output divider */
struct tegra_clk_pll_out {
	struct clk	hw;
	struct clk	*div;
	void __iomem	*reg;
	u8		enb_bit_idx;
	u8		rst_bit_idx;
	const char	*parent;
};

struct clk *tegra_clk_register_pll_out(const char *name,
		const char *parent_name, void __iomem *reg, u8 shift,
		u8 divider_flags);

/* struct clk-periph - peripheral clock */
struct tegra_clk_periph {
	struct clk	hw;
	struct clk	*gate;
	struct clk	*mux;
	struct clk	*div;
	u8 		flags;
	u8		rst_shift;
	void __iomem	*rst_reg;
};

#define TEGRA_PERIPH_NO_RESET BIT(0)
#define TEGRA_PERIPH_MANUAL_RESET BIT(1)
#define TEGRA_PERIPH_ON_APB BIT(2)

struct clk *tegra_clk_register_periph_nodiv(const char *name,
		const char **parent_names, int num_parents,
		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);

struct clk *tegra_clk_register_periph(const char *name,
		const char **parent_names, int num_parents,
		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);

struct clk *tegra_clk_register_periph_div16(const char *name,
		const char **parent_names, int num_parents,
		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);

/* struct clk_init_table - clock initialization table */
struct tegra_clk_init_table {
	unsigned int	clk_id;
	unsigned int	parent_id;
	unsigned long	rate;
	int		state;
};

void tegra_init_from_table(struct tegra_clk_init_table *tbl,
		struct clk *clks[], int clk_max);

struct tegra_clk_periph_regs {
	u32 enb_reg;
	u32 enb_set_reg;
	u32 enb_clr_reg;
	u32 rst_reg;
	u32 rst_set_reg;
	u32 rst_clr_reg;
};

void tegra_clk_init_rst_controller(void __iomem *base, struct device_node *np,
		unsigned int num);

void tegra_clk_reset_uarts(void);