xref: /openbmc/linux/drivers/clk/at91/pmc.h (revision 7a110b9107ed8fe27277988cdb4d18e7043b7252)
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 
161bdf0232SBoris Brezillon extern spinlock_t pmc_pcr_lock;
171bdf0232SBoris Brezillon 
18b00cd8e4SAlexandre Belloni struct pmc_data {
19b00cd8e4SAlexandre Belloni 	unsigned int ncore;
20b00cd8e4SAlexandre Belloni 	struct clk_hw **chws;
21b00cd8e4SAlexandre Belloni 	unsigned int nsystem;
22b00cd8e4SAlexandre Belloni 	struct clk_hw **shws;
23b00cd8e4SAlexandre Belloni 	unsigned int nperiph;
24b00cd8e4SAlexandre Belloni 	struct clk_hw **phws;
25b00cd8e4SAlexandre Belloni 	unsigned int ngck;
26b00cd8e4SAlexandre Belloni 	struct clk_hw **ghws;
2799767cd4SMichał Mirosław 	unsigned int npck;
2899767cd4SMichał Mirosław 	struct clk_hw **pchws;
297425f246SMichał Mirosław 
307425f246SMichał Mirosław 	struct clk_hw *hwtable[];
31b00cd8e4SAlexandre Belloni };
32b00cd8e4SAlexandre Belloni 
330ad6125bSBoris BREZILLON struct clk_range {
340ad6125bSBoris BREZILLON 	unsigned long min;
350ad6125bSBoris BREZILLON 	unsigned long max;
360ad6125bSBoris BREZILLON };
370ad6125bSBoris BREZILLON 
380ad6125bSBoris BREZILLON #define CLK_RANGE(MIN, MAX) {.min = MIN, .max = MAX,}
390ad6125bSBoris BREZILLON 
40b2e39dc0SAlexandre Belloni struct clk_master_layout {
41e5be5370SAlexandre Belloni 	u32 offset;
42b2e39dc0SAlexandre Belloni 	u32 mask;
43b2e39dc0SAlexandre Belloni 	u8 pres_shift;
44b2e39dc0SAlexandre Belloni };
45b2e39dc0SAlexandre Belloni 
46b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91rm9200_master_layout;
47b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91sam9x5_master_layout;
48b2e39dc0SAlexandre Belloni 
49b2e39dc0SAlexandre Belloni struct clk_master_characteristics {
50b2e39dc0SAlexandre Belloni 	struct clk_range output;
51e26b3006SEugen Hristev 	u32 divisors[5];
52b2e39dc0SAlexandre Belloni 	u8 have_div3_pres;
53b2e39dc0SAlexandre Belloni };
54b2e39dc0SAlexandre Belloni 
55b2e39dc0SAlexandre Belloni struct clk_pll_layout {
56b2e39dc0SAlexandre Belloni 	u32 pllr_mask;
5743b1bb4aSClaudiu Beznea 	u32 mul_mask;
5843b1bb4aSClaudiu Beznea 	u32 frac_mask;
5943b1bb4aSClaudiu Beznea 	u32 div_mask;
6043b1bb4aSClaudiu Beznea 	u32 endiv_mask;
61b2e39dc0SAlexandre Belloni 	u8 mul_shift;
6243b1bb4aSClaudiu Beznea 	u8 frac_shift;
6343b1bb4aSClaudiu Beznea 	u8 div_shift;
6443b1bb4aSClaudiu Beznea 	u8 endiv_shift;
65b2e39dc0SAlexandre Belloni };
66b2e39dc0SAlexandre Belloni 
67b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91rm9200_pll_layout;
68b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g45_pll_layout;
69b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g20_pllb_layout;
70b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout sama5d3_pll_layout;
71b2e39dc0SAlexandre Belloni 
72b2e39dc0SAlexandre Belloni struct clk_pll_characteristics {
73b2e39dc0SAlexandre Belloni 	struct clk_range input;
74b2e39dc0SAlexandre Belloni 	int num_output;
757b4c162eSStephen Boyd 	const struct clk_range *output;
76b2e39dc0SAlexandre Belloni 	u16 *icpll;
77b2e39dc0SAlexandre Belloni 	u8 *out;
78a436c2a4SAlexandre Belloni 	u8 upll : 1;
79b2e39dc0SAlexandre Belloni };
80b2e39dc0SAlexandre Belloni 
81b2e39dc0SAlexandre Belloni struct clk_programmable_layout {
8245b06682SMatthias Wieloch 	u8 pres_mask;
83b2e39dc0SAlexandre Belloni 	u8 pres_shift;
84b2e39dc0SAlexandre Belloni 	u8 css_mask;
85b2e39dc0SAlexandre Belloni 	u8 have_slck_mck;
8645b06682SMatthias Wieloch 	u8 is_pres_direct;
87b2e39dc0SAlexandre Belloni };
88b2e39dc0SAlexandre Belloni 
89b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91rm9200_programmable_layout;
90b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9g45_programmable_layout;
91b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9x5_programmable_layout;
92b2e39dc0SAlexandre Belloni 
93cb4f4949SAlexandre Belloni struct clk_pcr_layout {
94cb4f4949SAlexandre Belloni 	u32 offset;
95cb4f4949SAlexandre Belloni 	u32 cmd;
96cb4f4949SAlexandre Belloni 	u32 div_mask;
97cb4f4949SAlexandre Belloni 	u32 gckcss_mask;
98cb4f4949SAlexandre Belloni 	u32 pid_mask;
99cb4f4949SAlexandre Belloni };
100cb4f4949SAlexandre Belloni 
101cb4f4949SAlexandre Belloni #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
102cb4f4949SAlexandre Belloni #define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
103cb4f4949SAlexandre Belloni 
104b00cd8e4SAlexandre Belloni #define ndck(a, s) (a[s - 1].id + 1)
105b00cd8e4SAlexandre Belloni #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1)
106b00cd8e4SAlexandre Belloni struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
10799767cd4SMichał Mirosław 				   unsigned int nperiph, unsigned int ngck,
10899767cd4SMichał Mirosław 				   unsigned int npck);
109b00cd8e4SAlexandre Belloni 
1100ad6125bSBoris BREZILLON int of_at91_get_clk_range(struct device_node *np, const char *propname,
1110ad6125bSBoris BREZILLON 			  struct clk_range *range);
1120ad6125bSBoris BREZILLON 
113b2e39dc0SAlexandre Belloni struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data);
114b2e39dc0SAlexandre Belloni 
115b2e39dc0SAlexandre Belloni struct clk_hw * __init
116b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name,
117b2e39dc0SAlexandre Belloni 				 const char *parent_name);
118b2e39dc0SAlexandre Belloni 
119b2e39dc0SAlexandre Belloni struct clk_hw * __init
120b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name,
121b2e39dc0SAlexandre Belloni 				const char *parent_name);
122b2e39dc0SAlexandre Belloni 
123b2e39dc0SAlexandre Belloni struct clk_hw * __init
124b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name,
125b2e39dc0SAlexandre Belloni 				const char *parent_name);
126b2e39dc0SAlexandre Belloni 
127b2e39dc0SAlexandre Belloni struct clk_hw * __init
128b2e39dc0SAlexandre Belloni at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
129e4cfb823SAlexandre Belloni 			    const struct clk_pcr_layout *layout,
130b2e39dc0SAlexandre Belloni 			    const char *name, const char **parent_names,
13122a1dfe9SClaudiu Beznea 			    u32 *mux_table, u8 num_parents, u8 id,
13264c9247bSClaudiu Beznea 			    const struct clk_range *range, int chg_pid);
133b2e39dc0SAlexandre Belloni 
134b2e39dc0SAlexandre Belloni struct clk_hw * __init
135b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name,
136b2e39dc0SAlexandre Belloni 			const char *parent_name);
137b2e39dc0SAlexandre Belloni 
138b2e39dc0SAlexandre Belloni struct clk_hw * __init
139b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name,
140b2e39dc0SAlexandre Belloni 			  const char * const *parent_names,
141b2e39dc0SAlexandre Belloni 			  unsigned int num_parents, u8 bus_id);
142b2e39dc0SAlexandre Belloni 
143b2e39dc0SAlexandre Belloni struct clk_hw * __init
144b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name,
145b2e39dc0SAlexandre Belloni 			      u32 frequency, u32 accuracy);
146b2e39dc0SAlexandre Belloni struct clk_hw * __init
147b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name,
148b2e39dc0SAlexandre Belloni 			   const char *parent_name, bool bypass);
149b2e39dc0SAlexandre Belloni struct clk_hw * __init
150b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap,
151b2e39dc0SAlexandre Belloni 			      const char *name,
152b2e39dc0SAlexandre Belloni 			      const char *parent_name);
153b2e39dc0SAlexandre Belloni struct clk_hw * __init
154b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name,
155b2e39dc0SAlexandre Belloni 			      const char **parent_names, int num_parents);
156b2e39dc0SAlexandre Belloni 
157b2e39dc0SAlexandre Belloni struct clk_hw * __init
158*7a110b91SClaudiu Beznea at91_clk_register_master_pres(struct regmap *regmap, const char *name,
159b2e39dc0SAlexandre Belloni 			      int num_parents, const char **parent_names,
160b2e39dc0SAlexandre Belloni 			      const struct clk_master_layout *layout,
161*7a110b91SClaudiu Beznea 			      const struct clk_master_characteristics *characteristics,
162*7a110b91SClaudiu Beznea 			      spinlock_t *lock, u32 flags, int chg_pid);
163*7a110b91SClaudiu Beznea 
164*7a110b91SClaudiu Beznea struct clk_hw * __init
165*7a110b91SClaudiu Beznea at91_clk_register_master_div(struct regmap *regmap, const char *name,
166*7a110b91SClaudiu Beznea 			     const char *parent_names,
167*7a110b91SClaudiu Beznea 			     const struct clk_master_layout *layout,
168*7a110b91SClaudiu Beznea 			     const struct clk_master_characteristics *characteristics,
169*7a110b91SClaudiu Beznea 			     spinlock_t *lock, u32 flags);
170b2e39dc0SAlexandre Belloni 
171b2e39dc0SAlexandre Belloni struct clk_hw * __init
17275c88143SClaudiu Beznea at91_clk_sama7g5_register_master(struct regmap *regmap,
17375c88143SClaudiu Beznea 				 const char *name, int num_parents,
17475c88143SClaudiu Beznea 				 const char **parent_names, u32 *mux_table,
17575c88143SClaudiu Beznea 				 spinlock_t *lock, u8 id, bool critical,
17675c88143SClaudiu Beznea 				 int chg_pid);
17775c88143SClaudiu Beznea 
17875c88143SClaudiu Beznea struct clk_hw * __init
179b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name,
180b2e39dc0SAlexandre Belloni 			     const char *parent_name, u32 id);
181b2e39dc0SAlexandre Belloni struct clk_hw * __init
182b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock,
183cb4f4949SAlexandre Belloni 				    const struct clk_pcr_layout *layout,
184b2e39dc0SAlexandre Belloni 				    const char *name, const char *parent_name,
185b4c115c7SClaudiu Beznea 				    u32 id, const struct clk_range *range,
186b4c115c7SClaudiu Beznea 				    int chg_pid);
187b2e39dc0SAlexandre Belloni 
188b2e39dc0SAlexandre Belloni struct clk_hw * __init
189b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name,
190b2e39dc0SAlexandre Belloni 		      const char *parent_name, u8 id,
191b2e39dc0SAlexandre Belloni 		      const struct clk_pll_layout *layout,
192b2e39dc0SAlexandre Belloni 		      const struct clk_pll_characteristics *characteristics);
193b2e39dc0SAlexandre Belloni struct clk_hw * __init
194b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name,
195b2e39dc0SAlexandre Belloni 			 const char *parent_name);
196b2e39dc0SAlexandre Belloni 
197b2e39dc0SAlexandre Belloni struct clk_hw * __init
19843b1bb4aSClaudiu Beznea sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock,
199a436c2a4SAlexandre Belloni 			     const char *name, const char *parent_name, u8 id,
20043b1bb4aSClaudiu Beznea 			     const struct clk_pll_characteristics *characteristics,
2018dc4af8bSClaudiu Beznea 			     const struct clk_pll_layout *layout, u32 flags);
20243b1bb4aSClaudiu Beznea 
20343b1bb4aSClaudiu Beznea struct clk_hw * __init
20443b1bb4aSClaudiu Beznea sam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock,
20543b1bb4aSClaudiu Beznea 			      const char *name, const char *parent_name,
20643b1bb4aSClaudiu Beznea 			      struct clk_hw *parent_hw, u8 id,
20743b1bb4aSClaudiu Beznea 			      const struct clk_pll_characteristics *characteristics,
2088dc4af8bSClaudiu Beznea 			      const struct clk_pll_layout *layout, u32 flags);
209a436c2a4SAlexandre Belloni 
210a436c2a4SAlexandre Belloni struct clk_hw * __init
211b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name,
212b2e39dc0SAlexandre Belloni 			       const char **parent_names, u8 num_parents, u8 id,
213c57aaaa2SClaudiu Beznea 			       const struct clk_programmable_layout *layout,
214c57aaaa2SClaudiu Beznea 			       u32 *mux_table);
215b2e39dc0SAlexandre Belloni 
216b2e39dc0SAlexandre Belloni struct clk_hw * __init
217b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap,
218b2e39dc0SAlexandre Belloni 			       const char *name,
219b2e39dc0SAlexandre Belloni 			       const char **parent_names,
220b2e39dc0SAlexandre Belloni 			       int num_parents);
221b2e39dc0SAlexandre Belloni 
222b2e39dc0SAlexandre Belloni struct clk_hw * __init
223b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
224b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
225b2e39dc0SAlexandre Belloni 
226b2e39dc0SAlexandre Belloni struct clk_hw * __init
227b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name,
228b2e39dc0SAlexandre Belloni 			 const char *parent_name, u8 id);
229b2e39dc0SAlexandre Belloni 
230b2e39dc0SAlexandre Belloni struct clk_hw * __init
231b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name,
232b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
233b2e39dc0SAlexandre Belloni struct clk_hw * __init
234b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
235b2e39dc0SAlexandre Belloni 			     const char *parent_name);
236b2e39dc0SAlexandre Belloni struct clk_hw * __init
2372423eeaeSAlexandre Belloni sam9x60_clk_register_usb(struct regmap *regmap, const char *name,
2382423eeaeSAlexandre Belloni 			 const char **parent_names, u8 num_parents);
2392423eeaeSAlexandre Belloni struct clk_hw * __init
240b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
241b2e39dc0SAlexandre Belloni 			    const char *parent_name, const u32 *divisors);
242b2e39dc0SAlexandre Belloni 
243b2e39dc0SAlexandre Belloni struct clk_hw * __init
244b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr,
245b2e39dc0SAlexandre Belloni 		       const char *name, const char *parent_name);
246b2e39dc0SAlexandre Belloni 
247ef396df9SClaudiu Beznea struct clk_hw * __init
248ef396df9SClaudiu Beznea at91_clk_sama7g5_register_utmi(struct regmap *regmap, const char *name,
249ef396df9SClaudiu Beznea 			       const char *parent_name);
250ef396df9SClaudiu Beznea 
251b3b02eacSAlexandre Belloni #ifdef CONFIG_PM
252b3b02eacSAlexandre Belloni void pmc_register_id(u8 id);
25313967beaSRomain Izard void pmc_register_pck(u8 pck);
254b3b02eacSAlexandre Belloni #else
255b3b02eacSAlexandre Belloni static inline void pmc_register_id(u8 id) {}
25613967beaSRomain Izard static inline void pmc_register_pck(u8 pck) {}
257b3b02eacSAlexandre Belloni #endif
258b3b02eacSAlexandre Belloni 
2590ad6125bSBoris BREZILLON #endif /* __PMC_H_ */
260