xref: /openbmc/linux/drivers/clk/at91/pmc.h (revision b00cd8e41979267e067ad858b62b5e8b1b94c945)
10ad6125bSBoris BREZILLON /*
20ad6125bSBoris BREZILLON  * drivers/clk/at91/pmc.h
30ad6125bSBoris BREZILLON  *
40ad6125bSBoris BREZILLON  *  Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
50ad6125bSBoris BREZILLON  *
60ad6125bSBoris BREZILLON  * This program is free software; you can redistribute it and/or modify
70ad6125bSBoris BREZILLON  * it under the terms of the GNU General Public License as published by
80ad6125bSBoris BREZILLON  * the Free Software Foundation; either version 2 of the License, or
90ad6125bSBoris BREZILLON  * (at your option) any later version.
100ad6125bSBoris BREZILLON  */
110ad6125bSBoris BREZILLON 
120ad6125bSBoris BREZILLON #ifndef __PMC_H_
130ad6125bSBoris BREZILLON #define __PMC_H_
140ad6125bSBoris BREZILLON 
150ad6125bSBoris BREZILLON #include <linux/io.h>
160ad6125bSBoris BREZILLON #include <linux/irqdomain.h>
17863a81c3SBoris Brezillon #include <linux/regmap.h>
180ad6125bSBoris BREZILLON #include <linux/spinlock.h>
190ad6125bSBoris BREZILLON 
201bdf0232SBoris Brezillon extern spinlock_t pmc_pcr_lock;
211bdf0232SBoris Brezillon 
22*b00cd8e4SAlexandre Belloni struct pmc_data {
23*b00cd8e4SAlexandre Belloni 	unsigned int ncore;
24*b00cd8e4SAlexandre Belloni 	struct clk_hw **chws;
25*b00cd8e4SAlexandre Belloni 	unsigned int nsystem;
26*b00cd8e4SAlexandre Belloni 	struct clk_hw **shws;
27*b00cd8e4SAlexandre Belloni 	unsigned int nperiph;
28*b00cd8e4SAlexandre Belloni 	struct clk_hw **phws;
29*b00cd8e4SAlexandre Belloni 	unsigned int ngck;
30*b00cd8e4SAlexandre Belloni 	struct clk_hw **ghws;
31*b00cd8e4SAlexandre Belloni };
32*b00cd8e4SAlexandre 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 {
41b2e39dc0SAlexandre Belloni 	u32 mask;
42b2e39dc0SAlexandre Belloni 	u8 pres_shift;
43b2e39dc0SAlexandre Belloni };
44b2e39dc0SAlexandre Belloni 
45b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91rm9200_master_layout;
46b2e39dc0SAlexandre Belloni extern const struct clk_master_layout at91sam9x5_master_layout;
47b2e39dc0SAlexandre Belloni 
48b2e39dc0SAlexandre Belloni struct clk_master_characteristics {
49b2e39dc0SAlexandre Belloni 	struct clk_range output;
50b2e39dc0SAlexandre Belloni 	u32 divisors[4];
51b2e39dc0SAlexandre Belloni 	u8 have_div3_pres;
52b2e39dc0SAlexandre Belloni };
53b2e39dc0SAlexandre Belloni 
54b2e39dc0SAlexandre Belloni struct clk_pll_layout {
55b2e39dc0SAlexandre Belloni 	u32 pllr_mask;
56b2e39dc0SAlexandre Belloni 	u16 mul_mask;
57b2e39dc0SAlexandre Belloni 	u8 mul_shift;
58b2e39dc0SAlexandre Belloni };
59b2e39dc0SAlexandre Belloni 
60b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91rm9200_pll_layout;
61b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g45_pll_layout;
62b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout at91sam9g20_pllb_layout;
63b2e39dc0SAlexandre Belloni extern const struct clk_pll_layout sama5d3_pll_layout;
64b2e39dc0SAlexandre Belloni 
65b2e39dc0SAlexandre Belloni struct clk_pll_characteristics {
66b2e39dc0SAlexandre Belloni 	struct clk_range input;
67b2e39dc0SAlexandre Belloni 	int num_output;
68b2e39dc0SAlexandre Belloni 	struct clk_range *output;
69b2e39dc0SAlexandre Belloni 	u16 *icpll;
70b2e39dc0SAlexandre Belloni 	u8 *out;
71b2e39dc0SAlexandre Belloni };
72b2e39dc0SAlexandre Belloni 
73b2e39dc0SAlexandre Belloni struct clk_programmable_layout {
74b2e39dc0SAlexandre Belloni 	u8 pres_shift;
75b2e39dc0SAlexandre Belloni 	u8 css_mask;
76b2e39dc0SAlexandre Belloni 	u8 have_slck_mck;
77b2e39dc0SAlexandre Belloni };
78b2e39dc0SAlexandre Belloni 
79b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91rm9200_programmable_layout;
80b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9g45_programmable_layout;
81b2e39dc0SAlexandre Belloni extern const struct clk_programmable_layout at91sam9x5_programmable_layout;
82b2e39dc0SAlexandre Belloni 
83*b00cd8e4SAlexandre Belloni #define ndck(a, s) (a[s - 1].id + 1)
84*b00cd8e4SAlexandre Belloni #define nck(a) (a[ARRAY_SIZE(a) - 1].id + 1)
85*b00cd8e4SAlexandre Belloni struct pmc_data *pmc_data_allocate(unsigned int ncore, unsigned int nsystem,
86*b00cd8e4SAlexandre Belloni 				   unsigned int nperiph, unsigned int ngck);
87*b00cd8e4SAlexandre Belloni void pmc_data_free(struct pmc_data *pmc_data);
88*b00cd8e4SAlexandre Belloni 
890ad6125bSBoris BREZILLON int of_at91_get_clk_range(struct device_node *np, const char *propname,
900ad6125bSBoris BREZILLON 			  struct clk_range *range);
910ad6125bSBoris BREZILLON 
92b2e39dc0SAlexandre Belloni struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data);
93b2e39dc0SAlexandre Belloni 
94b2e39dc0SAlexandre Belloni struct clk_hw * __init
95b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_frac(struct regmap *regmap, const char *name,
96b2e39dc0SAlexandre Belloni 				 const char *parent_name);
97b2e39dc0SAlexandre Belloni 
98b2e39dc0SAlexandre Belloni struct clk_hw * __init
99b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pad(struct regmap *regmap, const char *name,
100b2e39dc0SAlexandre Belloni 				const char *parent_name);
101b2e39dc0SAlexandre Belloni 
102b2e39dc0SAlexandre Belloni struct clk_hw * __init
103b2e39dc0SAlexandre Belloni at91_clk_register_audio_pll_pmc(struct regmap *regmap, const char *name,
104b2e39dc0SAlexandre Belloni 				const char *parent_name);
105b2e39dc0SAlexandre Belloni 
106b2e39dc0SAlexandre Belloni struct clk_hw * __init
107b2e39dc0SAlexandre Belloni at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock,
108b2e39dc0SAlexandre Belloni 			    const char *name, const char **parent_names,
109b2e39dc0SAlexandre Belloni 			    u8 num_parents, u8 id, bool pll_audio,
110b2e39dc0SAlexandre Belloni 			    const struct clk_range *range);
111b2e39dc0SAlexandre Belloni 
112b2e39dc0SAlexandre Belloni struct clk_hw * __init
113b2e39dc0SAlexandre Belloni at91_clk_register_h32mx(struct regmap *regmap, const char *name,
114b2e39dc0SAlexandre Belloni 			const char *parent_name);
115b2e39dc0SAlexandre Belloni 
116b2e39dc0SAlexandre Belloni struct clk_hw * __init
117b2e39dc0SAlexandre Belloni at91_clk_i2s_mux_register(struct regmap *regmap, const char *name,
118b2e39dc0SAlexandre Belloni 			  const char * const *parent_names,
119b2e39dc0SAlexandre Belloni 			  unsigned int num_parents, u8 bus_id);
120b2e39dc0SAlexandre Belloni 
121b2e39dc0SAlexandre Belloni struct clk_hw * __init
122b2e39dc0SAlexandre Belloni at91_clk_register_main_rc_osc(struct regmap *regmap, const char *name,
123b2e39dc0SAlexandre Belloni 			      u32 frequency, u32 accuracy);
124b2e39dc0SAlexandre Belloni struct clk_hw * __init
125b2e39dc0SAlexandre Belloni at91_clk_register_main_osc(struct regmap *regmap, const char *name,
126b2e39dc0SAlexandre Belloni 			   const char *parent_name, bool bypass);
127b2e39dc0SAlexandre Belloni struct clk_hw * __init
128b2e39dc0SAlexandre Belloni at91_clk_register_rm9200_main(struct regmap *regmap,
129b2e39dc0SAlexandre Belloni 			      const char *name,
130b2e39dc0SAlexandre Belloni 			      const char *parent_name);
131b2e39dc0SAlexandre Belloni struct clk_hw * __init
132b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_main(struct regmap *regmap, const char *name,
133b2e39dc0SAlexandre Belloni 			      const char **parent_names, int num_parents);
134b2e39dc0SAlexandre Belloni 
135b2e39dc0SAlexandre Belloni struct clk_hw * __init
136b2e39dc0SAlexandre Belloni at91_clk_register_master(struct regmap *regmap, const char *name,
137b2e39dc0SAlexandre Belloni 			 int num_parents, const char **parent_names,
138b2e39dc0SAlexandre Belloni 			 const struct clk_master_layout *layout,
139b2e39dc0SAlexandre Belloni 			 const struct clk_master_characteristics *characteristics);
140b2e39dc0SAlexandre Belloni 
141b2e39dc0SAlexandre Belloni struct clk_hw * __init
142b2e39dc0SAlexandre Belloni at91_clk_register_peripheral(struct regmap *regmap, const char *name,
143b2e39dc0SAlexandre Belloni 			     const char *parent_name, u32 id);
144b2e39dc0SAlexandre Belloni struct clk_hw * __init
145b2e39dc0SAlexandre Belloni at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock,
146b2e39dc0SAlexandre Belloni 				    const char *name, const char *parent_name,
147b2e39dc0SAlexandre Belloni 				    u32 id, const struct clk_range *range);
148b2e39dc0SAlexandre Belloni 
149b2e39dc0SAlexandre Belloni struct clk_hw * __init
150b2e39dc0SAlexandre Belloni at91_clk_register_pll(struct regmap *regmap, const char *name,
151b2e39dc0SAlexandre Belloni 		      const char *parent_name, u8 id,
152b2e39dc0SAlexandre Belloni 		      const struct clk_pll_layout *layout,
153b2e39dc0SAlexandre Belloni 		      const struct clk_pll_characteristics *characteristics);
154b2e39dc0SAlexandre Belloni struct clk_hw * __init
155b2e39dc0SAlexandre Belloni at91_clk_register_plldiv(struct regmap *regmap, const char *name,
156b2e39dc0SAlexandre Belloni 			 const char *parent_name);
157b2e39dc0SAlexandre Belloni 
158b2e39dc0SAlexandre Belloni struct clk_hw * __init
159b2e39dc0SAlexandre Belloni at91_clk_register_programmable(struct regmap *regmap, const char *name,
160b2e39dc0SAlexandre Belloni 			       const char **parent_names, u8 num_parents, u8 id,
161b2e39dc0SAlexandre Belloni 			       const struct clk_programmable_layout *layout);
162b2e39dc0SAlexandre Belloni 
163b2e39dc0SAlexandre Belloni struct clk_hw * __init
164b2e39dc0SAlexandre Belloni at91_clk_register_sam9260_slow(struct regmap *regmap,
165b2e39dc0SAlexandre Belloni 			       const char *name,
166b2e39dc0SAlexandre Belloni 			       const char **parent_names,
167b2e39dc0SAlexandre Belloni 			       int num_parents);
168b2e39dc0SAlexandre Belloni 
169b2e39dc0SAlexandre Belloni struct clk_hw * __init
170b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
171b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
172b2e39dc0SAlexandre Belloni 
173b2e39dc0SAlexandre Belloni struct clk_hw * __init
174b2e39dc0SAlexandre Belloni at91_clk_register_system(struct regmap *regmap, const char *name,
175b2e39dc0SAlexandre Belloni 			 const char *parent_name, u8 id);
176b2e39dc0SAlexandre Belloni 
177b2e39dc0SAlexandre Belloni struct clk_hw * __init
178b2e39dc0SAlexandre Belloni at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name,
179b2e39dc0SAlexandre Belloni 			    const char **parent_names, u8 num_parents);
180b2e39dc0SAlexandre Belloni struct clk_hw * __init
181b2e39dc0SAlexandre Belloni at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
182b2e39dc0SAlexandre Belloni 			     const char *parent_name);
183b2e39dc0SAlexandre Belloni struct clk_hw * __init
184b2e39dc0SAlexandre Belloni at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
185b2e39dc0SAlexandre Belloni 			    const char *parent_name, const u32 *divisors);
186b2e39dc0SAlexandre Belloni 
187b2e39dc0SAlexandre Belloni struct clk_hw * __init
188b2e39dc0SAlexandre Belloni at91_clk_register_utmi(struct regmap *regmap_pmc, struct regmap *regmap_sfr,
189b2e39dc0SAlexandre Belloni 		       const char *name, const char *parent_name);
190b2e39dc0SAlexandre Belloni 
191b3b02eacSAlexandre Belloni #ifdef CONFIG_PM
192b3b02eacSAlexandre Belloni void pmc_register_id(u8 id);
19313967beaSRomain Izard void pmc_register_pck(u8 pck);
194b3b02eacSAlexandre Belloni #else
195b3b02eacSAlexandre Belloni static inline void pmc_register_id(u8 id) {}
19613967beaSRomain Izard static inline void pmc_register_pck(u8 pck) {}
197b3b02eacSAlexandre Belloni #endif
198b3b02eacSAlexandre Belloni 
1990ad6125bSBoris BREZILLON #endif /* __PMC_H_ */
200