fdtvar.h revision 1.12 1 /* $NetBSD: fdtvar.h,v 1.12 2017/04/22 21:47:41 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 };
49
50 /* flags for fdtbus_intr_establish */
51 #define FDT_INTR_MPSAFE __BIT(0)
52
53 struct fdtbus_interrupt_controller_func {
54 void * (*establish)(device_t, u_int *, int, int,
55 int (*)(void *), void *);
56 void (*disestablish)(device_t, void *);
57 bool (*intrstr)(device_t, u_int *, char *, size_t);
58 };
59
60 struct fdtbus_i2c_controller_func {
61 i2c_tag_t (*get_tag)(device_t);
62 };
63
64 struct fdtbus_gpio_controller;
65
66 struct fdtbus_gpio_pin {
67 struct fdtbus_gpio_controller *gp_gc;
68 void *gp_priv;
69 };
70
71 struct fdtbus_gpio_controller_func {
72 void * (*acquire)(device_t, const void *, size_t, int);
73 void (*release)(device_t, void *);
74 int (*read)(device_t, void *, bool);
75 void (*write)(device_t, void *, int, bool);
76 };
77
78 struct fdtbus_pinctrl_controller;
79
80 struct fdtbus_pinctrl_pin {
81 struct fdtbus_pinctrl_controller *pp_pc;
82 void *pp_priv;
83 };
84
85 struct fdtbus_pinctrl_controller_func {
86 int (*set_config)(void *);
87 };
88
89 struct fdtbus_regulator_controller;
90
91 struct fdtbus_regulator {
92 struct fdtbus_regulator_controller *reg_rc;
93 };
94
95 struct fdtbus_regulator_controller_func {
96 int (*acquire)(device_t);
97 void (*release)(device_t);
98 int (*enable)(device_t, bool);
99 int (*set_voltage)(device_t, u_int, u_int);
100 int (*get_voltage)(device_t, u_int *);
101 };
102
103 struct fdtbus_clock_controller_func {
104 struct clk * (*decode)(device_t, const void *, size_t);
105 };
106
107 struct fdtbus_reset_controller;
108
109 struct fdtbus_reset {
110 struct fdtbus_reset_controller *rst_rc;
111 void *rst_priv;
112 };
113
114 struct fdtbus_reset_controller_func {
115 void * (*acquire)(device_t, const void *, size_t);
116 void (*release)(device_t, void *);
117 int (*reset_assert)(device_t, void *);
118 int (*reset_deassert)(device_t, void *);
119 };
120
121 int fdtbus_register_interrupt_controller(device_t, int,
122 const struct fdtbus_interrupt_controller_func *);
123 int fdtbus_register_i2c_controller(device_t, int,
124 const struct fdtbus_i2c_controller_func *);
125 int fdtbus_register_gpio_controller(device_t, int,
126 const struct fdtbus_gpio_controller_func *);
127 int fdtbus_register_pinctrl_config(void *, int,
128 const struct fdtbus_pinctrl_controller_func *);
129 int fdtbus_register_regulator_controller(device_t, int,
130 const struct fdtbus_regulator_controller_func *);
131 int fdtbus_register_clock_controller(device_t, int,
132 const struct fdtbus_clock_controller_func *);
133 int fdtbus_register_reset_controller(device_t, int,
134 const struct fdtbus_reset_controller_func *);
135
136 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
137 int fdtbus_get_phandle(int, const char *);
138 int fdtbus_get_phandle_from_native(int);
139 i2c_tag_t fdtbus_get_i2c_tag(int);
140 void * fdtbus_intr_establish(int, u_int, int, int,
141 int (*func)(void *), void *arg);
142 void fdtbus_intr_disestablish(int, void *);
143 bool fdtbus_intr_str(int, u_int, char *, size_t);
144 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
145 void fdtbus_gpio_release(struct fdtbus_gpio_pin *);
146 int fdtbus_gpio_read(struct fdtbus_gpio_pin *);
147 void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
148 int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
149 void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
150 int fdtbus_pinctrl_set_config_index(int, u_int);
151 int fdtbus_pinctrl_set_config(int, const char *);
152 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
153 void fdtbus_regulator_release(struct fdtbus_regulator *);
154 int fdtbus_regulator_enable(struct fdtbus_regulator *);
155 int fdtbus_regulator_disable(struct fdtbus_regulator *);
156 int fdtbus_regulator_set_voltage(struct fdtbus_regulator *,
157 u_int, u_int);
158 int fdtbus_regulator_get_voltage(struct fdtbus_regulator *,
159 u_int *);
160
161 struct clk * fdtbus_clock_get(int, const char *);
162 struct clk * fdtbus_clock_get_index(int, u_int);
163
164 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
165 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
166 void fdtbus_reset_put(struct fdtbus_reset *);
167 int fdtbus_reset_assert(struct fdtbus_reset *);
168 int fdtbus_reset_deassert(struct fdtbus_reset *);
169
170 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
171
172 bool fdtbus_set_data(const void *);
173 const void * fdtbus_get_data(void);
174 int fdtbus_phandle2offset(int);
175 int fdtbus_offset2phandle(int);
176 bool fdtbus_get_path(int, char *, size_t);
177
178 const char * fdtbus_get_stdout_path(void);
179 int fdtbus_get_stdout_phandle(void);
180 int fdtbus_get_stdout_speed(void);
181
182 #endif /* _DEV_FDT_FDTVAR_H */
183