fdtvar.h revision 1.40 1 /* $NetBSD: fdtvar.h,v 1.40 2018/09/09 07:21:18 aymeric Exp $ */
2
3 /*-
4 * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #ifndef _DEV_FDT_FDTVAR_H
30 #define _DEV_FDT_FDTVAR_H
31
32 #include <sys/types.h>
33 #include <sys/bus.h>
34 #include <sys/termios.h>
35
36 #include <dev/i2c/i2cvar.h>
37 #include <dev/pwm/pwmvar.h>
38 #include <dev/clk/clk.h>
39
40 #include "audio.h"
41 #if NAUDIO > 0
42 #include <dev/audio_dai.h>
43 #else
44 typedef void *audio_dai_tag_t;
45 #endif
46
47 #include <dev/clock_subr.h>
48
49 #include <dev/ofw/openfirm.h>
50
51 struct fdt_attach_args {
52 const char *faa_name;
53 bus_space_tag_t faa_bst;
54 bus_space_tag_t faa_a4x_bst;
55 bus_dma_tag_t faa_dmat;
56 int faa_phandle;
57 int faa_quiet;
58 };
59
60 /* flags for fdtbus_intr_establish */
61 #define FDT_INTR_MPSAFE __BIT(0)
62
63 struct fdtbus_interrupt_controller_func {
64 void * (*establish)(device_t, u_int *, int, int,
65 int (*)(void *), void *);
66 void (*disestablish)(device_t, void *);
67 bool (*intrstr)(device_t, u_int *, char *, size_t);
68 };
69
70 struct fdtbus_i2c_controller_func {
71 i2c_tag_t (*get_tag)(device_t);
72 };
73
74 struct fdtbus_gpio_controller;
75
76 struct fdtbus_gpio_pin {
77 struct fdtbus_gpio_controller *gp_gc;
78 void *gp_priv;
79 };
80
81 struct fdtbus_gpio_controller_func {
82 void * (*acquire)(device_t, const void *, size_t, int);
83 void (*release)(device_t, void *);
84 int (*read)(device_t, void *, bool);
85 void (*write)(device_t, void *, int, bool);
86 };
87
88 struct fdtbus_pinctrl_controller;
89
90 struct fdtbus_pinctrl_pin {
91 struct fdtbus_pinctrl_controller *pp_pc;
92 void *pp_priv;
93 };
94
95 struct fdtbus_pinctrl_controller_func {
96 int (*set_config)(device_t, const void *, size_t);
97 };
98
99 struct fdtbus_regulator_controller;
100
101 struct fdtbus_regulator {
102 struct fdtbus_regulator_controller *reg_rc;
103 };
104
105 struct fdtbus_regulator_controller_func {
106 int (*acquire)(device_t);
107 void (*release)(device_t);
108 int (*enable)(device_t, bool);
109 int (*set_voltage)(device_t, u_int, u_int);
110 int (*get_voltage)(device_t, u_int *);
111 };
112
113 struct fdtbus_clock_controller_func {
114 struct clk * (*decode)(device_t, int, const void *, size_t);
115 };
116
117 struct fdtbus_reset_controller;
118
119 struct fdtbus_reset {
120 struct fdtbus_reset_controller *rst_rc;
121 void *rst_priv;
122 };
123
124 struct fdtbus_reset_controller_func {
125 void * (*acquire)(device_t, const void *, size_t);
126 void (*release)(device_t, void *);
127 int (*reset_assert)(device_t, void *);
128 int (*reset_deassert)(device_t, void *);
129 };
130
131 struct fdtbus_dai_controller_func {
132 audio_dai_tag_t (*get_tag)(device_t, const void *, size_t);
133 };
134
135 struct fdtbus_dma_controller;
136
137 struct fdtbus_dma {
138 struct fdtbus_dma_controller *dma_dc;
139 void *dma_priv;
140 };
141
142 enum fdtbus_dma_dir {
143 FDT_DMA_READ, /* device -> memory */
144 FDT_DMA_WRITE /* memory -> device */
145 };
146
147 struct fdtbus_dma_opt {
148 int opt_bus_width; /* Bus width */
149 int opt_burst_len; /* Burst length */
150 int opt_swap; /* Enable data swapping */
151 int opt_dblbuf; /* Enable double buffering */
152 int opt_wrap_len; /* Address wrap-around window */
153 };
154
155 struct fdtbus_dma_req {
156 bus_dma_segment_t *dreq_segs; /* Memory */
157 int dreq_nsegs;
158
159 bus_addr_t dreq_dev_phys; /* Device */
160 int dreq_sel; /* Device selector */
161
162 enum fdtbus_dma_dir dreq_dir; /* Transfer direction */
163
164 int dreq_block_irq; /* Enable IRQ at end of block */
165 int dreq_block_multi; /* Enable multiple block transfers */
166 int dreq_flow; /* Enable flow control */
167
168 struct fdtbus_dma_opt dreq_mem_opt; /* Memory options */
169 struct fdtbus_dma_opt dreq_dev_opt; /* Device options */
170 };
171
172 struct fdtbus_dma_controller_func {
173 void * (*acquire)(device_t, const void *, size_t,
174 void (*)(void *), void *);
175 void (*release)(device_t, void *);
176 int (*transfer)(device_t, void *, struct fdtbus_dma_req *);
177 void (*halt)(device_t, void *);
178 };
179
180 struct fdtbus_power_controller;
181
182 struct fdtbus_power_controller_func {
183 void (*reset)(device_t);
184 void (*poweroff)(device_t);
185 };
186
187 struct fdtbus_phy_controller;
188
189 struct fdtbus_phy {
190 struct fdtbus_phy_controller *phy_pc;
191 void *phy_priv;
192 };
193
194 struct fdtbus_phy_controller_func {
195 void * (*acquire)(device_t, const void *, size_t);
196 void (*release)(device_t, void *);
197 int (*enable)(device_t, void *, bool);
198 };
199
200 struct fdtbus_pwm_controller_func {
201 pwm_tag_t (*get_tag)(device_t, const void *, size_t);
202 };
203
204 struct fdtbus_mmc_pwrseq;
205
206 struct fdtbus_mmc_pwrseq_func {
207 void (*pre_power_on)(device_t);
208 void (*post_power_on)(device_t);
209 void (*power_off)(device_t);
210 void (*reset)(device_t);
211 };
212
213 struct syscon;
214
215 struct fdt_console {
216 int (*match)(int);
217 void (*consinit)(struct fdt_attach_args *, u_int);
218 };
219
220 struct fdt_console_info {
221 const struct fdt_console *ops;
222 };
223
224 #define _FDT_CONSOLE_REGISTER(name) \
225 __link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
226
227 #define FDT_CONSOLE(_name, _ops) \
228 static const struct fdt_console_info __CONCAT(_name,_consinfo) = { \
229 .ops = (_ops) \
230 }; \
231 _FDT_CONSOLE_REGISTER(_name)
232
233 TAILQ_HEAD(fdt_conslist, fdt_console_info);
234
235 int fdtbus_register_interrupt_controller(device_t, int,
236 const struct fdtbus_interrupt_controller_func *);
237 int fdtbus_register_i2c_controller(device_t, int,
238 const struct fdtbus_i2c_controller_func *);
239 int fdtbus_register_gpio_controller(device_t, int,
240 const struct fdtbus_gpio_controller_func *);
241 int fdtbus_register_pinctrl_config(device_t, int,
242 const struct fdtbus_pinctrl_controller_func *);
243 int fdtbus_register_regulator_controller(device_t, int,
244 const struct fdtbus_regulator_controller_func *);
245 int fdtbus_register_clock_controller(device_t, int,
246 const struct fdtbus_clock_controller_func *);
247 int fdtbus_register_reset_controller(device_t, int,
248 const struct fdtbus_reset_controller_func *);
249 int fdtbus_register_dai_controller(device_t, int,
250 const struct fdtbus_dai_controller_func *);
251 int fdtbus_register_dma_controller(device_t, int,
252 const struct fdtbus_dma_controller_func *);
253 int fdtbus_register_power_controller(device_t, int,
254 const struct fdtbus_power_controller_func *);
255 int fdtbus_register_phy_controller(device_t, int,
256 const struct fdtbus_phy_controller_func *);
257 int fdtbus_register_pwm_controller(device_t, int,
258 const struct fdtbus_pwm_controller_func *);
259 int fdtbus_register_mmc_pwrseq(device_t, int,
260 const struct fdtbus_mmc_pwrseq_func *);
261 int fdtbus_register_syscon(device_t, int, struct syscon *);
262
263 void fdtbus_set_decoderegprop(bool);
264
265 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
266 int fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
267 bus_size_t *);
268 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
269 int fdtbus_get_phandle(int, const char *);
270 int fdtbus_get_phandle_from_native(int);
271 i2c_tag_t fdtbus_get_i2c_tag(int);
272 void * fdtbus_intr_establish(int, u_int, int, int,
273 int (*func)(void *), void *arg);
274 void * fdtbus_intr_establish_raw(int, const u_int *, int, int,
275 int (*func)(void *), void *arg);
276 void fdtbus_intr_disestablish(int, void *);
277 bool fdtbus_intr_str(int, u_int, char *, size_t);
278 bool fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
279 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
280 struct fdtbus_gpio_pin *fdtbus_gpio_acquire_index(int, const char *, int, int);
281 void fdtbus_gpio_release(struct fdtbus_gpio_pin *);
282 int fdtbus_gpio_read(struct fdtbus_gpio_pin *);
283 void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
284 int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
285 void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
286 audio_dai_tag_t fdtbus_dai_acquire(int, const char *);
287 audio_dai_tag_t fdtbus_dai_acquire_index(int, const char *, int);
288 pwm_tag_t fdtbus_pwm_acquire(int, const char *);
289 pwm_tag_t fdtbus_pwm_acquire_index(int, const char *, int);
290 void fdtbus_pinctrl_configure(void);
291 int fdtbus_pinctrl_set_config_index(int, u_int);
292 int fdtbus_pinctrl_set_config(int, const char *);
293 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
294 void fdtbus_regulator_release(struct fdtbus_regulator *);
295 int fdtbus_regulator_enable(struct fdtbus_regulator *);
296 int fdtbus_regulator_disable(struct fdtbus_regulator *);
297 int fdtbus_regulator_set_voltage(struct fdtbus_regulator *,
298 u_int, u_int);
299 int fdtbus_regulator_get_voltage(struct fdtbus_regulator *,
300 u_int *);
301 struct syscon * fdtbus_syscon_acquire(int, const char *);
302 struct syscon * fdtbus_syscon_lookup(int);
303
304 struct fdtbus_dma *fdtbus_dma_get(int, const char *, void (*)(void *), void *);
305 struct fdtbus_dma *fdtbus_dma_get_index(int, u_int, void (*)(void *),
306 void *);
307 void fdtbus_dma_put(struct fdtbus_dma *);
308 int fdtbus_dma_transfer(struct fdtbus_dma *,
309 struct fdtbus_dma_req *);
310 void fdtbus_dma_halt(struct fdtbus_dma *);
311
312 struct clk * fdtbus_clock_get(int, const char *);
313 struct clk * fdtbus_clock_get_index(int, u_int);
314 struct clk * fdtbus_clock_byname(const char *);
315 void fdtbus_clock_assign(int);
316
317 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
318 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
319 void fdtbus_reset_put(struct fdtbus_reset *);
320 int fdtbus_reset_assert(struct fdtbus_reset *);
321 int fdtbus_reset_deassert(struct fdtbus_reset *);
322
323 struct fdtbus_phy *fdtbus_phy_get(int, const char *);
324 struct fdtbus_phy *fdtbus_phy_get_index(int, u_int);
325 void fdtbus_phy_put(struct fdtbus_phy *);
326 int fdtbus_phy_enable(struct fdtbus_phy *, bool);
327
328 struct fdtbus_mmc_pwrseq *fdtbus_mmc_pwrseq_get(int);
329 void fdtbus_mmc_pwrseq_pre_power_on(struct fdtbus_mmc_pwrseq *);
330 void fdtbus_mmc_pwrseq_post_power_on(struct fdtbus_mmc_pwrseq *);
331 void fdtbus_mmc_pwrseq_power_off(struct fdtbus_mmc_pwrseq *);
332 void fdtbus_mmc_pwrseq_reset(struct fdtbus_mmc_pwrseq *);
333
334 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
335
336 void fdtbus_power_reset(void);
337 void fdtbus_power_poweroff(void);
338
339 device_t fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t);
340
341 bool fdtbus_set_data(const void *);
342 const void * fdtbus_get_data(void);
343 int fdtbus_phandle2offset(int);
344 int fdtbus_offset2phandle(int);
345 bool fdtbus_get_path(int, char *, size_t);
346
347 const struct fdt_console *fdtbus_get_console(void);
348
349 const char * fdtbus_get_stdout_path(void);
350 int fdtbus_get_stdout_phandle(void);
351 int fdtbus_get_stdout_speed(void);
352 tcflag_t fdtbus_get_stdout_flags(void);
353
354 bool fdtbus_status_okay(int);
355
356 const void * fdtbus_get_prop(int, const char *, int *);
357 const char * fdtbus_get_string(int, const char *);
358 const char * fdtbus_get_string_index(int, const char *, u_int);
359
360 void fdt_add_bus(device_t, int, struct fdt_attach_args *);
361
362 void fdt_remove_byhandle(int);
363 void fdt_remove_bycompat(const char *[]);
364 int fdtbus_print(void *, const char *);
365
366 #endif /* _DEV_FDT_FDTVAR_H */
367