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