xref: /openbmc/linux/drivers/clk/at91/pmc.h (revision 7029db09b2025f863f191b3d5b1d7859a5e26a8d)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
20ad6125bSBoris BREZILLON /*
30ad6125bSBoris BREZILLON  * drivers/clk/at91/pmc.h
40ad6125bSBoris BREZILLON  *
50ad6125bSBoris BREZILLON  *  Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
60ad6125bSBoris BREZILLON  */
70ad6125bSBoris BREZILLON 
80ad6125bSBoris BREZILLON #ifndef __PMC_H_
90ad6125bSBoris BREZILLON #define __PMC_H_
100ad6125bSBoris BREZILLON 
110ad6125bSBoris BREZILLON #include <linux/io.h>
120ad6125bSBoris BREZILLON #include <linux/irqdomain.h>
13863a81c3SBoris Brezillon #include <linux/regmap.h>
140ad6125bSBoris BREZILLON #include <linux/spinlock.h>
150ad6125bSBoris BREZILLON 
1636971566SClaudiu Beznea #include <dt-bindings/clock/at91.h>
1736971566SClaudiu Beznea 
181bdf0232SBoris Brezillon extern spinlock_t pmc_pcr_lock;
191bdf0232SBoris Brezillon 
20b00cd8e4SAlexandre Belloni struct pmc_data {
21b00cd8e4SAlexandre Belloni 	unsigned int ncore;
22b00cd8e4SAlexandre Belloni 	struct clk_hw **chws;
23b00cd8e4SAlexandre Belloni 	unsigned int nsystem;
24b00cd8e4SAlexandre Belloni 	struct clk_hw **shws;
25b00cd8e4SAlexandre Belloni 	unsigned int nperiph;
26b00cd8e4SAlexandre Belloni 	struct clk_hw **phws;
27b00cd8e4SAlexandre Belloni 	unsigned int ngck;
28b00cd8e4SAlexandre Belloni 	struct clk_hw **ghws;
2999767cd4SMichał Mirosław 	unsigned int npck;
3099767cd4SMichał Mirosław 	struct clk_hw **pchws;
317425f246SMichał Mirosław 
327425f246SMichał Mirosław 	struct clk_hw *hwtable[];
33b00cd8e4SAlexandre Belloni };
34b00cd8e4SAlexandre Belloni 
350ad6125bSBoris BREZILLON struct clk_range {
360ad6125bSBoris BREZILLON 	unsigned long min;
370ad6125bSBoris BREZILLON 	unsigned long max;
380ad6125bSBoris BREZILLON };
390ad6125bSBoris BREZILLON 
400ad6125bSBoris BREZILLON #define CLK_RANGE(MIN, MAX) {.min = MIN, .max = MAX,}
410ad6125bSBoris BREZILLON 
42b2e39dc0SAlexandre Belloni struct clk_master_layout {
43e5be5370SAlexandre Belloni 	u32 offset;
44b2e39dc0SAlexandre Belloni 	u32 mask;
45b2e39dc0SAlexandre Belloni 	u8 pres_shift;
46b2e39dc0SAlexandre Belloni };
47b2e39dc0SAlexandre Belloni 
48b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91rm9200_master_layout;
49b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91sam9x5_master_layout;
50b2e39dc0SAlexandre Belloni 
51b2e39dc0SAlexandre Belloni struct clk_master_characteristics {
52b2e39dc0SAlexandre Belloni 	struct clk_range output;
53e26b3006SEugen Hristev 	u32 divisors[5];
54b2e39dc0SAlexandre Belloni 	u8 have_div3_pres;
55b2e39dc0SAlexandre Belloni };
56b2e39dc0SAlexandre Belloni 
57b2e39dc0SAlexandre Belloni struct clk_pll_layout {
58b2e39dc0SAlexandre Belloni 	u32 pllr_mask;
5943b1bb4aSClaudiu Beznea 	u32 mul_mask;
6043b1bb4aSClaudiu Beznea 	u32 frac_mask;
6143b1bb4aSClaudiu Beznea 	u32 div_mask;
6243b1bb4aSClaudiu Beznea 	u32 endiv_mask;
63b2e39dc0SAlexandre Belloni 	u8 mul_shift;
6443b1bb4aSClaudiu Beznea 	u8 frac_shift;
6543b1bb4aSClaudiu Beznea 	u8 div_shift;
6643b1bb4aSClaudiu Beznea 	u8 endiv_shift;
67b2e39dc0SAlexandre Belloni };
68b2e39dc0SAlexandre Belloni 
69b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91rm9200_pll_layout;
70b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g45_pll_layout;
71b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g20_pllb_layout;
72b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout sama5d3_pll_layout;
73b2e39dc0SAlexandre Belloni 
74b2e39dc0SAlexandre Belloni struct clk_pll_characteristics {
75b2e39dc0SAlexandre Belloni 	struct clk_range input;
76b2e39dc0SAlexandre Belloni 	int num_output;
777b4c162eSStephen Boyd 	const struct clk_range *output;
78b2e39dc0SAlexandre Belloni 	u16 *icpll;
79b2e39dc0SAlexandre Belloni 	u8 *out;
80a436c2a4SAlexandre Belloni 	u8 upll : 1;
81b2e39dc0SAlexandre Belloni };
82b2e39dc0SAlexandre Belloni 
83b2e39dc0SAlexandre Belloni struct clk_programmable_layout {
8445b06682SMatthias Wieloch 	u8 pres_mask;
85b2e39dc0SAlexandre Belloni 	u8 pres_shift;
86b2e39dc0SAlexandre Belloni 	u8 css_mask;
87b2e39dc0SAlexandre Belloni 	u8 have_slck_mck;
8845b06682SMatthias Wieloch 	u8 is_pres_direct;
89b2e39dc0SAlexandre Belloni };
90b2e39dc0SAlexandre Belloni 
91b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91rm9200_programmable_layout;
92b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9g45_programmable_layout;
93b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9x5_programmable_layout;
94b2e39dc0SAlexandre Belloni 
95cb4f4949SAlexandre Belloni struct clk_pcr_layout {
96cb4f4949SAlexandre Belloni 	u32 offset;
97cb4f4949SAlexandre Belloni 	u32 cmd;
98cb4f4949SAlexandre Belloni 	u32 div_mask;
99cb4f4949SAlexandre Belloni 	u32 gckcss_mask;
100cb4f4949SAlexandre Belloni 	u32 pid_mask;
101cb4f4949SAlexandre Belloni };
102cb4f4949SAlexandre Belloni 
10336971566SClaudiu Beznea /**
10436971566SClaudiu Beznea  * struct at91_clk_pms - Power management state for AT91 clock
10536971566SClaudiu Beznea  * @rate: clock rate
10636971566SClaudiu Beznea  * @parent_rate: clock parent rate
10736971566SClaudiu Beznea  * @status: clock status (enabled or disabled)
10836971566SClaudiu Beznea  * @parent: clock parent index
10936971566SClaudiu Beznea  */
11036971566SClaudiu Beznea struct at91_clk_pms {
11136971566SClaudiu Beznea 	unsigned long rate;
11236971566SClaudiu Beznea 	unsigned long parent_rate;
11336971566SClaudiu Beznea 	unsigned int status;
11436971566SClaudiu Beznea 	unsigned int parent;
11536971566SClaudiu Beznea };
11636971566SClaudiu Beznea 
117cb4f4949SAlexandre Belloni #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
118cb4f4949SAlexandre Belloni #define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
119cb4f4949SAlexandre Belloni 
120b00cd8e4SAlexandre Belloni #define ndck(a, s) (a[s - 1].id + 1)
121b00cd8e4SAlexandre Belloni #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1)
122b00cd8e4SAlexandre Belloni struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
12399767cd4SMichał Mirosław 				   unsigned int nperiph, unsigned int ngck,
12499767cd4SMichał Mirosław 				   unsigned int npck);
125b00cd8e4SAlexandre Belloni 
1260ad6125bSBoris BREZILLON int of_at91_get_clk_range(struct device_node *np, const char *propname,
1270ad6125bSBoris BREZILLON 			  struct clk_range *range);
1280ad6125bSBoris BREZILLON 
129b2e39dc0SAlexandre Belloni struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data);
130b2e39dc0SAlexandre Belloni 
131b2e39dc0SAlexandre Belloni struct clk_hw * __init
132b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name,
133b2e39dc0SAlexandre Belloni 				 const char *parent_name);
134b2e39dc0SAlexandre Belloni 
135b2e39dc0SAlexandre Belloni struct clk_hw * __init
136b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name,
137b2e39dc0SAlexandre Belloni 				const char *parent_name);
138b2e39dc0SAlexandre Belloni 
139b2e39dc0SAlexandre Belloni struct clk_hw * __init
140b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name,
141b2e39dc0SAlexandre Belloni 				const char *parent_name);
142b2e39dc0SAlexandre Belloni 
143b2e39dc0SAlexandre Belloni struct clk_hw * __init
144b2e39dc0SAlexandre Belloni at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
145e4cfb823SAlexandre Belloni 			    const struct clk_pcr_layout *layout,
146b2e39dc0SAlexandre Belloni 			    const char *name, const char **parent_names,
14722a1dfe9SClaudiu Beznea 			    u32 *mux_table, u8 num_parents, u8 id,
14864c9247bSClaudiu Beznea 			    const struct clk_range *range, int chg_pid);
149b2e39dc0SAlexandre Belloni 
150b2e39dc0SAlexandre Belloni struct clk_hw * __init
151b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name,
152b2e39dc0SAlexandre Belloni 			const char *parent_name);
153b2e39dc0SAlexandre Belloni 
154b2e39dc0SAlexandre Belloni struct clk_hw * __init
155b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name,
156b2e39dc0SAlexandre Belloni 			  const char * const *parent_names,
157b2e39dc0SAlexandre Belloni 			  unsigned int num_parents, u8 bus_id);
158b2e39dc0SAlexandre Belloni 
159b2e39dc0SAlexandre Belloni struct clk_hw * __init
160b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name,
161b2e39dc0SAlexandre Belloni 			      u32 frequency, u32 accuracy);
162b2e39dc0SAlexandre Belloni struct clk_hw * __init
163b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name,
164b2e39dc0SAlexandre Belloni 			   const char *parent_name, bool bypass);
165b2e39dc0SAlexandre Belloni struct clk_hw * __init
166b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap,
167b2e39dc0SAlexandre Belloni 			      const char *name,
168b2e39dc0SAlexandre Belloni 			      const char *parent_name);
169b2e39dc0SAlexandre Belloni struct clk_hw * __init
170b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name,
171b2e39dc0SAlexandre Belloni 			      const char **parent_names, int num_parents);
172b2e39dc0SAlexandre Belloni 
173b2e39dc0SAlexandre Belloni struct clk_hw * __init
1747a110b91SClaudiu Beznea at91_clk_register_master_pres(struct regmap *regmap, const char *name,
175b2e39dc0SAlexandre Belloni 			      int num_parents, const char **parent_names,
176b2e39dc0SAlexandre Belloni 			      const struct clk_master_layout *layout,
1777a110b91SClaudiu Beznea 			      const struct clk_master_characteristics *characteristics,
1787a110b91SClaudiu Beznea 			      spinlock_t *lock, u32 flags, int chg_pid);
1797a110b91SClaudiu Beznea 
1807a110b91SClaudiu Beznea struct clk_hw * __init
1817a110b91SClaudiu Beznea at91_clk_register_master_div(struct regmap *regmap, const char *name,
1827a110b91SClaudiu Beznea 			     const char *parent_names,
1837a110b91SClaudiu Beznea 			     const struct clk_master_layout *layout,
1847a110b91SClaudiu Beznea 			     const struct clk_master_characteristics *characteristics,
185*7029db09SClaudiu Beznea 			     spinlock_t *lock, u32 flags, u32 safe_div);
186b2e39dc0SAlexandre Belloni 
187b2e39dc0SAlexandre Belloni struct clk_hw * __init
18875c88143SClaudiu Beznea at91_clk_sama7g5_register_master(struct regmap *regmap,
18975c88143SClaudiu Beznea 				 const char *name, int num_parents,
19075c88143SClaudiu Beznea 				 const char **parent_names, u32 *mux_table,
19175c88143SClaudiu Beznea 				 spinlock_t *lock, u8 id, bool critical,
19275c88143SClaudiu Beznea 				 int chg_pid);
19375c88143SClaudiu Beznea 
19475c88143SClaudiu Beznea struct clk_hw * __init
195b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name,
196b2e39dc0SAlexandre Belloni 			     const char *parent_name, u32 id);
197b2e39dc0SAlexandre Belloni struct clk_hw * __init
198b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock,
199cb4f4949SAlexandre Belloni 				    const struct clk_pcr_layout *layout,
200b2e39dc0SAlexandre Belloni 				    const char *name, const char *parent_name,
201b4c115c7SClaudiu Beznea 				    u32 id, const struct clk_range *range,
202b4c115c7SClaudiu Beznea 				    int chg_pid);
203b2e39dc0SAlexandre Belloni 
204b2e39dc0SAlexandre Belloni struct clk_hw * __init
205b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name,
206b2e39dc0SAlexandre Belloni 		      const char *parent_name, u8 id,
207b2e39dc0SAlexandre Belloni 		      const struct clk_pll_layout *layout,
208b2e39dc0SAlexandre Belloni 		      const struct clk_pll_characteristics *characteristics);
209b2e39dc0SAlexandre Belloni struct clk_hw * __init
210b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name,
211b2e39dc0SAlexandre Belloni 			 const char *parent_name);
212b2e39dc0SAlexandre Belloni 
213b2e39dc0SAlexandre Belloni struct clk_hw * __init
21443b1bb4aSClaudiu Beznea sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock,
215a436c2a4SAlexandre Belloni 			     const char *name, const char *parent_name, u8 id,
21643b1bb4aSClaudiu Beznea 			     const struct clk_pll_characteristics *characteristics,
2171e229c21SClaudiu Beznea 			     const struct clk_pll_layout *layout, u32 flags,
2181e229c21SClaudiu Beznea 			     u32 safe_div);
21943b1bb4aSClaudiu Beznea 
22043b1bb4aSClaudiu Beznea struct clk_hw * __init
22143b1bb4aSClaudiu Beznea sam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock,
22243b1bb4aSClaudiu Beznea 			      const char *name, const char *parent_name,
22343b1bb4aSClaudiu Beznea 			      struct clk_hw *parent_hw, u8 id,
22443b1bb4aSClaudiu Beznea 			      const struct clk_pll_characteristics *characteristics,
2258dc4af8bSClaudiu Beznea 			      const struct clk_pll_layout *layout, u32 flags);
226a436c2a4SAlexandre Belloni 
227a436c2a4SAlexandre Belloni struct clk_hw * __init
228b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name,
229b2e39dc0SAlexandre Belloni 			       const char **parent_names, u8 num_parents, u8 id,
230c57aaaa2SClaudiu Beznea 			       const struct clk_programmable_layout *layout,
231c57aaaa2SClaudiu Beznea 			       u32 *mux_table);
232b2e39dc0SAlexandre Belloni 
233b2e39dc0SAlexandre Belloni struct clk_hw * __init
234b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap,
235b2e39dc0SAlexandre Belloni 			       const char *name,
236b2e39dc0SAlexandre Belloni 			       const char **parent_names,
237b2e39dc0SAlexandre Belloni 			       int num_parents);
238b2e39dc0SAlexandre Belloni 
239b2e39dc0SAlexandre Belloni struct clk_hw * __init
240b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
241b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
242b2e39dc0SAlexandre Belloni 
243b2e39dc0SAlexandre Belloni struct clk_hw * __init
244b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name,
245b2e39dc0SAlexandre Belloni 			 const char *parent_name, u8 id);
246b2e39dc0SAlexandre Belloni 
247b2e39dc0SAlexandre Belloni struct clk_hw * __init
248b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name,
249b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
250b2e39dc0SAlexandre Belloni struct clk_hw * __init
251b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
252b2e39dc0SAlexandre Belloni 			     const char *parent_name);
253b2e39dc0SAlexandre Belloni struct clk_hw * __init
2542423eeaeSAlexandre Belloni sam9x60_clk_register_usb(struct regmap *regmap, const char *name,
2552423eeaeSAlexandre Belloni 			 const char **parent_names, u8 num_parents);
2562423eeaeSAlexandre Belloni struct clk_hw * __init
257b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
258b2e39dc0SAlexandre Belloni 			    const char *parent_name, const u32 *divisors);
259b2e39dc0SAlexandre Belloni 
260b2e39dc0SAlexandre Belloni struct clk_hw * __init
261b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr,
262b2e39dc0SAlexandre Belloni 		       const char *name, const char *parent_name);
263b2e39dc0SAlexandre Belloni 
264ef396df9SClaudiu Beznea struct clk_hw * __init
265ef396df9SClaudiu Beznea at91_clk_sama7g5_register_utmi(struct regmap *regmap, const char *name,
266ef396df9SClaudiu Beznea 			       const char *parent_name);
267ef396df9SClaudiu Beznea 
2680ad6125bSBoris BREZILLON #endif /* __PMC_H_ */
269