fdtvar.h revision 1.17 1 /* $NetBSD: fdtvar.h,v 1.17 2017/05/26 18:56:27 jmcneill 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
35 #include <dev/i2c/i2cvar.h>
36 #include <dev/clk/clk.h>
37
38 #include <dev/clock_subr.h>
39
40 #include <dev/ofw/openfirm.h>
41
42 struct fdt_attach_args {
43 const char *faa_name;
44 bus_space_tag_t faa_bst;
45 bus_space_tag_t faa_a4x_bst;
46 bus_dma_tag_t faa_dmat;
47 int faa_phandle;
48 int faa_quiet;
49 };
50
51 /* flags for fdtbus_intr_establish */
52 #define FDT_INTR_MPSAFE __BIT(0)
53
54 struct fdtbus_interrupt_controller_func {
55 void * (*establish)(device_t, u_int *, int, int,
56 int (*)(void *), void *);
57 void (*disestablish)(device_t, void *);
58 bool (*intrstr)(device_t, u_int *, char *, size_t);
59 };
60
61 struct fdtbus_i2c_controller_func {
62 i2c_tag_t (*get_tag)(device_t);
63 };
64
65 struct fdtbus_gpio_controller;
66
67 struct fdtbus_gpio_pin {
68 struct fdtbus_gpio_controller *gp_gc;
69 void *gp_priv;
70 };
71
72 struct fdtbus_gpio_controller_func {
73 void * (*acquire)(device_t, const void *, size_t, int);
74 void (*release)(device_t, void *);
75 int (*read)(device_t, void *, bool);
76 void (*write)(device_t, void *, int, bool);
77 };
78
79 struct fdtbus_pinctrl_controller;
80
81 struct fdtbus_pinctrl_pin {
82 struct fdtbus_pinctrl_controller *pp_pc;
83 void *pp_priv;
84 };
85
86 struct fdtbus_pinctrl_controller_func {
87 int (*set_config)(void *);
88 };
89
90 struct fdtbus_regulator_controller;
91
92 struct fdtbus_regulator {
93 struct fdtbus_regulator_controller *reg_rc;
94 };
95
96 struct fdtbus_regulator_controller_func {
97 int (*acquire)(device_t);
98 void (*release)(device_t);
99 int (*enable)(device_t, bool);
100 int (*set_voltage)(device_t, u_int, u_int);
101 int (*get_voltage)(device_t, u_int *);
102 };
103
104 struct fdtbus_clock_controller_func {
105 struct clk * (*decode)(device_t, const void *, size_t);
106 };
107
108 struct fdtbus_reset_controller;
109
110 struct fdtbus_reset {
111 struct fdtbus_reset_controller *rst_rc;
112 void *rst_priv;
113 };
114
115 struct fdtbus_reset_controller_func {
116 void * (*acquire)(device_t, const void *, size_t);
117 void (*release)(device_t, void *);
118 int (*reset_assert)(device_t, void *);
119 int (*reset_deassert)(device_t, void *);
120 };
121
122 struct fdtbus_dma_controller;
123
124 struct fdtbus_dma {
125 struct fdtbus_dma_controller *dma_dc;
126 void *dma_priv;
127 };
128
129 enum fdtbus_dma_dir {
130 FDT_DMA_READ, /* device -> memory */
131 FDT_DMA_WRITE /* memory -> device */
132 };
133
134 struct fdtbus_dma_opt {
135 int opt_bus_width; /* Bus width */
136 int opt_burst_len; /* Burst length */
137 int opt_swap; /* Enable data swapping */
138 int opt_dblbuf; /* Enable double buffering */
139 int opt_wrap_len; /* Address wrap-around window */
140 };
141
142 struct fdtbus_dma_req {
143 bus_dma_segment_t *dreq_segs; /* Memory */
144 int dreq_nsegs;
145
146 bus_addr_t dreq_dev_phys; /* Device */
147 int dreq_sel; /* Device selector */
148
149 enum fdtbus_dma_dir dreq_dir; /* Transfer direction */
150
151 int dreq_block_irq; /* Enable IRQ at end of block */
152 int dreq_block_multi; /* Enable multiple block transfers */
153 int dreq_flow; /* Enable flow control */
154
155 struct fdtbus_dma_opt dreq_mem_opt; /* Memory options */
156 struct fdtbus_dma_opt dreq_dev_opt; /* Device options */
157 };
158
159 struct fdtbus_dma_controller_func {
160 void * (*acquire)(device_t, const void *, size_t,
161 void (*)(void *), void *);
162 void (*release)(device_t, void *);
163 int (*transfer)(device_t, void *, struct fdtbus_dma_req *);
164 void (*halt)(device_t, void *);
165 };
166
167 int fdtbus_register_interrupt_controller(device_t, int,
168 const struct fdtbus_interrupt_controller_func *);
169 int fdtbus_register_i2c_controller(device_t, int,
170 const struct fdtbus_i2c_controller_func *);
171 int fdtbus_register_gpio_controller(device_t, int,
172 const struct fdtbus_gpio_controller_func *);
173 int fdtbus_register_pinctrl_config(void *, int,
174 const struct fdtbus_pinctrl_controller_func *);
175 int fdtbus_register_regulator_controller(device_t, int,
176 const struct fdtbus_regulator_controller_func *);
177 int fdtbus_register_clock_controller(device_t, int,
178 const struct fdtbus_clock_controller_func *);
179 int fdtbus_register_reset_controller(device_t, int,
180 const struct fdtbus_reset_controller_func *);
181 int fdtbus_register_dma_controller(device_t, int,
182 const struct fdtbus_dma_controller_func *);
183
184 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
185 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
186 int fdtbus_get_phandle(int, const char *);
187 int fdtbus_get_phandle_from_native(int);
188 i2c_tag_t fdtbus_get_i2c_tag(int);
189 void * fdtbus_intr_establish(int, u_int, int, int,
190 int (*func)(void *), void *arg);
191 void fdtbus_intr_disestablish(int, void *);
192 bool fdtbus_intr_str(int, u_int, char *, size_t);
193 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
194 void fdtbus_gpio_release(struct fdtbus_gpio_pin *);
195 int fdtbus_gpio_read(struct fdtbus_gpio_pin *);
196 void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
197 int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
198 void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
199 int fdtbus_pinctrl_set_config_index(int, u_int);
200 int fdtbus_pinctrl_set_config(int, const char *);
201 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
202 void fdtbus_regulator_release(struct fdtbus_regulator *);
203 int fdtbus_regulator_enable(struct fdtbus_regulator *);
204 int fdtbus_regulator_disable(struct fdtbus_regulator *);
205 int fdtbus_regulator_set_voltage(struct fdtbus_regulator *,
206 u_int, u_int);
207 int fdtbus_regulator_get_voltage(struct fdtbus_regulator *,
208 u_int *);
209
210 struct fdtbus_dma *fdtbus_dma_get(int, const char *, void (*)(void *), void *);
211 struct fdtbus_dma *fdtbus_dma_get_index(int, u_int, void (*)(void *),
212 void *);
213 void fdtbus_dma_put(struct fdtbus_dma *);
214 int fdtbus_dma_transfer(struct fdtbus_dma *,
215 struct fdtbus_dma_req *);
216 void fdtbus_dma_halt(struct fdtbus_dma *);
217
218 struct clk * fdtbus_clock_get(int, const char *);
219 struct clk * fdtbus_clock_get_index(int, u_int);
220
221 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
222 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
223 void fdtbus_reset_put(struct fdtbus_reset *);
224 int fdtbus_reset_assert(struct fdtbus_reset *);
225 int fdtbus_reset_deassert(struct fdtbus_reset *);
226
227 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
228
229 bool fdtbus_set_data(const void *);
230 const void * fdtbus_get_data(void);
231 int fdtbus_phandle2offset(int);
232 int fdtbus_offset2phandle(int);
233 bool fdtbus_get_path(int, char *, size_t);
234
235 const char * fdtbus_get_stdout_path(void);
236 int fdtbus_get_stdout_phandle(void);
237 int fdtbus_get_stdout_speed(void);
238
239 bool fdtbus_status_okay(int);
240
241 int fdtbus_print(void *, const char *);
242
243 #endif /* _DEV_FDT_FDTVAR_H */
244