xref: /openbmc/linux/drivers/clk/at91/pmc.h (revision a673dae8)
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,
14700bd581bSClaudiu Beznea 			    struct clk_hw **parent_hws, u32 *mux_table,
14800bd581bSClaudiu Beznea 			    u8 num_parents, u8 id,
14964c9247bSClaudiu Beznea 			    const struct clk_range *range, int chg_pid);
150b2e39dc0SAlexandre Belloni 
151b2e39dc0SAlexandre Belloni struct clk_hw * __init
152b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name,
153b2e39dc0SAlexandre Belloni 			const char *parent_name);
154b2e39dc0SAlexandre Belloni 
155b2e39dc0SAlexandre Belloni struct clk_hw * __init
156b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name,
157b2e39dc0SAlexandre Belloni 			  const char * const *parent_names,
158b2e39dc0SAlexandre Belloni 			  unsigned int num_parents, u8 bus_id);
159b2e39dc0SAlexandre Belloni 
160b2e39dc0SAlexandre Belloni struct clk_hw * __init
161b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name,
162b2e39dc0SAlexandre Belloni 			      u32 frequency, u32 accuracy);
163b2e39dc0SAlexandre Belloni struct clk_hw * __init
164b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name,
165b5105e37SClaudiu Beznea 			   const char *parent_name,
166b5105e37SClaudiu Beznea 			   struct clk_parent_data *parent_data, bool bypass);
167b2e39dc0SAlexandre Belloni struct clk_hw * __init
168b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap,
169b2e39dc0SAlexandre Belloni 			      const char *name,
170b5105e37SClaudiu Beznea 			      const char *parent_name,
171b5105e37SClaudiu Beznea 			      struct clk_hw *parent_hw);
172b2e39dc0SAlexandre Belloni struct clk_hw * __init
173b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name,
174b5105e37SClaudiu Beznea 			      const char **parent_names,
175b5105e37SClaudiu Beznea 			      struct clk_hw **parent_hws, int num_parents);
176b2e39dc0SAlexandre Belloni 
177b2e39dc0SAlexandre Belloni struct clk_hw * __init
1787a110b91SClaudiu Beznea at91_clk_register_master_pres(struct regmap *regmap, const char *name,
179b2e39dc0SAlexandre Belloni 			      int num_parents, const char **parent_names,
180171e502cSClaudiu Beznea 			      struct clk_hw **parent_hws,
181b2e39dc0SAlexandre Belloni 			      const struct clk_master_layout *layout,
1827a110b91SClaudiu Beznea 			      const struct clk_master_characteristics *characteristics,
1838e842f02SClaudiu Beznea 			      spinlock_t *lock);
1847a110b91SClaudiu Beznea 
1857a110b91SClaudiu Beznea struct clk_hw * __init
1867a110b91SClaudiu Beznea at91_clk_register_master_div(struct regmap *regmap, const char *name,
187171e502cSClaudiu Beznea 			     const char *parent_names, struct clk_hw *parent_hw,
1887a110b91SClaudiu Beznea 			     const struct clk_master_layout *layout,
1897a110b91SClaudiu Beznea 			     const struct clk_master_characteristics *characteristics,
1907029db09SClaudiu Beznea 			     spinlock_t *lock, u32 flags, u32 safe_div);
191b2e39dc0SAlexandre Belloni 
192b2e39dc0SAlexandre Belloni struct clk_hw * __init
19375c88143SClaudiu Beznea at91_clk_sama7g5_register_master(struct regmap *regmap,
19475c88143SClaudiu Beznea 				 const char *name, int num_parents,
195171e502cSClaudiu Beznea 				 const char **parent_names,
196171e502cSClaudiu Beznea 				 struct clk_hw **parent_hws, u32 *mux_table,
19775c88143SClaudiu Beznea 				 spinlock_t *lock, u8 id, bool critical,
19875c88143SClaudiu Beznea 				 int chg_pid);
19975c88143SClaudiu Beznea 
20075c88143SClaudiu Beznea struct clk_hw * __init
201b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name,
202c2f2ca0bSClaudiu Beznea 			     const char *parent_name, struct clk_hw *parent_hw,
203c2f2ca0bSClaudiu Beznea 			     u32 id);
204b2e39dc0SAlexandre Belloni struct clk_hw * __init
205b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock,
206cb4f4949SAlexandre Belloni 				    const struct clk_pcr_layout *layout,
207b2e39dc0SAlexandre Belloni 				    const char *name, const char *parent_name,
208c2f2ca0bSClaudiu Beznea 				    struct clk_hw *parent_hw,
209b4c115c7SClaudiu Beznea 				    u32 id, const struct clk_range *range,
21068b3b6f1SClaudiu Beznea 				    int chg_pid, unsigned long flags);
211b2e39dc0SAlexandre Belloni 
212b2e39dc0SAlexandre Belloni struct clk_hw * __init
213b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name,
214b2e39dc0SAlexandre Belloni 		      const char *parent_name, u8 id,
215b2e39dc0SAlexandre Belloni 		      const struct clk_pll_layout *layout,
216b2e39dc0SAlexandre Belloni 		      const struct clk_pll_characteristics *characteristics);
217b2e39dc0SAlexandre Belloni struct clk_hw * __init
218b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name,
219b2e39dc0SAlexandre Belloni 			 const char *parent_name);
220b2e39dc0SAlexandre Belloni 
221b2e39dc0SAlexandre Belloni struct clk_hw * __init
22243b1bb4aSClaudiu Beznea sam9x60_clk_register_div_pll(struct regmap *regmap, spinlock_t *lock,
223*a673dae8SClaudiu Beznea 			     const char *name, const char *parent_name,
224*a673dae8SClaudiu Beznea 			     struct clk_hw *parent_hw, u8 id,
22543b1bb4aSClaudiu Beznea 			     const struct clk_pll_characteristics *characteristics,
2261e229c21SClaudiu Beznea 			     const struct clk_pll_layout *layout, u32 flags,
2271e229c21SClaudiu Beznea 			     u32 safe_div);
22843b1bb4aSClaudiu Beznea 
22943b1bb4aSClaudiu Beznea struct clk_hw * __init
23043b1bb4aSClaudiu Beznea sam9x60_clk_register_frac_pll(struct regmap *regmap, spinlock_t *lock,
23143b1bb4aSClaudiu Beznea 			      const char *name, const char *parent_name,
23243b1bb4aSClaudiu Beznea 			      struct clk_hw *parent_hw, u8 id,
23343b1bb4aSClaudiu Beznea 			      const struct clk_pll_characteristics *characteristics,
2348dc4af8bSClaudiu Beznea 			      const struct clk_pll_layout *layout, u32 flags);
235a436c2a4SAlexandre Belloni 
236a436c2a4SAlexandre Belloni struct clk_hw * __init
237b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name,
2381a2669dfSClaudiu Beznea 			       const char **parent_names, struct clk_hw **parent_hws,
2391a2669dfSClaudiu Beznea 			       u8 num_parents, u8 id,
240c57aaaa2SClaudiu Beznea 			       const struct clk_programmable_layout *layout,
241c57aaaa2SClaudiu Beznea 			       u32 *mux_table);
242b2e39dc0SAlexandre Belloni 
243b2e39dc0SAlexandre Belloni struct clk_hw * __init
244b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap,
245b2e39dc0SAlexandre Belloni 			       const char *name,
246b2e39dc0SAlexandre Belloni 			       const char **parent_names,
247b2e39dc0SAlexandre Belloni 			       int num_parents);
248b2e39dc0SAlexandre Belloni 
249b2e39dc0SAlexandre Belloni struct clk_hw * __init
250b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
251b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
252b2e39dc0SAlexandre Belloni 
253b2e39dc0SAlexandre Belloni struct clk_hw * __init
254b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name,
2551a537f62SClaudiu Beznea 			 const char *parent_name, struct clk_hw *parent_hw,
2561a537f62SClaudiu Beznea 			 u8 id, unsigned long flags);
257b2e39dc0SAlexandre Belloni 
258b2e39dc0SAlexandre Belloni struct clk_hw * __init
259b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name,
260b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
261b2e39dc0SAlexandre Belloni struct clk_hw * __init
262b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
263b2e39dc0SAlexandre Belloni 			     const char *parent_name);
264b2e39dc0SAlexandre Belloni struct clk_hw * __init
2652423eeaeSAlexandre Belloni sam9x60_clk_register_usb(struct regmap *regmap, const char *name,
2662423eeaeSAlexandre Belloni 			 const char **parent_names, u8 num_parents);
2672423eeaeSAlexandre Belloni struct clk_hw * __init
268b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
269b2e39dc0SAlexandre Belloni 			    const char *parent_name, const u32 *divisors);
270b2e39dc0SAlexandre Belloni 
271b2e39dc0SAlexandre Belloni struct clk_hw * __init
272b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr,
273077782e3SClaudiu Beznea 		       const char *name, const char *parent_name,
274077782e3SClaudiu Beznea 		       struct clk_hw *parent_hw);
275b2e39dc0SAlexandre Belloni 
276ef396df9SClaudiu Beznea struct clk_hw * __init
277ef396df9SClaudiu Beznea at91_clk_sama7g5_register_utmi(struct regmap *regmap, const char *name,
278077782e3SClaudiu Beznea 			       const char *parent_name, struct clk_hw *parent_hw);
279ef396df9SClaudiu Beznea 
2800ad6125bSBoris BREZILLON #endif /* __PMC_H_ */
281