fdtvar.h revision 1.4.2.2 1 1.4.2.2 skrll /* $NetBSD: fdtvar.h,v 1.4.2.2 2015/12/27 12:09:49 skrll Exp $ */
2 1.4.2.2 skrll
3 1.4.2.2 skrll /*-
4 1.4.2.2 skrll * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.4.2.2 skrll * All rights reserved.
6 1.4.2.2 skrll *
7 1.4.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.4.2.2 skrll * modification, are permitted provided that the following conditions
9 1.4.2.2 skrll * are met:
10 1.4.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.4.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.4.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.4.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.4.2.2 skrll *
16 1.4.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.4.2.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.4.2.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.4.2.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.4.2.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.4.2.2 skrll * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.4.2.2 skrll * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.4.2.2 skrll * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.4.2.2 skrll * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.4.2.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.4.2.2 skrll * SUCH DAMAGE.
27 1.4.2.2 skrll */
28 1.4.2.2 skrll
29 1.4.2.2 skrll #ifndef _DEV_FDT_FDTVAR_H
30 1.4.2.2 skrll #define _DEV_FDT_FDTVAR_H
31 1.4.2.2 skrll
32 1.4.2.2 skrll #include <sys/types.h>
33 1.4.2.2 skrll #include <sys/bus.h>
34 1.4.2.2 skrll
35 1.4.2.2 skrll #include <dev/i2c/i2cvar.h>
36 1.4.2.2 skrll #include <dev/clk/clk.h>
37 1.4.2.2 skrll
38 1.4.2.2 skrll #include <dev/ofw/openfirm.h>
39 1.4.2.2 skrll
40 1.4.2.2 skrll struct fdt_attach_args {
41 1.4.2.2 skrll const char *faa_name;
42 1.4.2.2 skrll bus_space_tag_t faa_bst;
43 1.4.2.2 skrll bus_space_tag_t faa_a4x_bst;
44 1.4.2.2 skrll bus_dma_tag_t faa_dmat;
45 1.4.2.2 skrll int faa_phandle;
46 1.4.2.2 skrll
47 1.4.2.2 skrll const char **faa_init;
48 1.4.2.2 skrll int faa_ninit;
49 1.4.2.2 skrll };
50 1.4.2.2 skrll
51 1.4.2.2 skrll /* flags for fdtbus_intr_establish */
52 1.4.2.2 skrll #define FDT_INTR_MPSAFE __BIT(0)
53 1.4.2.2 skrll
54 1.4.2.2 skrll struct fdtbus_interrupt_controller_func {
55 1.4.2.2 skrll void * (*establish)(device_t, int, u_int, int, int,
56 1.4.2.2 skrll int (*)(void *), void *);
57 1.4.2.2 skrll void (*disestablish)(device_t, void *);
58 1.4.2.2 skrll bool (*intrstr)(device_t, int, u_int, char *, size_t);
59 1.4.2.2 skrll };
60 1.4.2.2 skrll
61 1.4.2.2 skrll struct fdtbus_i2c_controller_func {
62 1.4.2.2 skrll i2c_tag_t (*get_tag)(device_t);
63 1.4.2.2 skrll };
64 1.4.2.2 skrll
65 1.4.2.2 skrll struct fdtbus_gpio_controller;
66 1.4.2.2 skrll
67 1.4.2.2 skrll struct fdtbus_gpio_pin {
68 1.4.2.2 skrll struct fdtbus_gpio_controller *gp_gc;
69 1.4.2.2 skrll void *gp_priv;
70 1.4.2.2 skrll };
71 1.4.2.2 skrll
72 1.4.2.2 skrll struct fdtbus_gpio_controller_func {
73 1.4.2.2 skrll void * (*acquire)(device_t, const void *, size_t, int);
74 1.4.2.2 skrll void (*release)(device_t, void *);
75 1.4.2.2 skrll int (*read)(device_t, void *, bool);
76 1.4.2.2 skrll void (*write)(device_t, void *, int, bool);
77 1.4.2.2 skrll };
78 1.4.2.2 skrll
79 1.4.2.2 skrll struct fdtbus_regulator_controller;
80 1.4.2.2 skrll
81 1.4.2.2 skrll struct fdtbus_regulator {
82 1.4.2.2 skrll struct fdtbus_regulator_controller *reg_rc;
83 1.4.2.2 skrll };
84 1.4.2.2 skrll
85 1.4.2.2 skrll struct fdtbus_regulator_controller_func {
86 1.4.2.2 skrll int (*acquire)(device_t);
87 1.4.2.2 skrll void (*release)(device_t);
88 1.4.2.2 skrll int (*enable)(device_t, bool);
89 1.4.2.2 skrll };
90 1.4.2.2 skrll
91 1.4.2.2 skrll struct fdtbus_clock_controller_func {
92 1.4.2.2 skrll struct clk * (*decode)(device_t, const void *, size_t);
93 1.4.2.2 skrll };
94 1.4.2.2 skrll
95 1.4.2.2 skrll struct fdtbus_reset_controller;
96 1.4.2.2 skrll
97 1.4.2.2 skrll struct fdtbus_reset {
98 1.4.2.2 skrll struct fdtbus_reset_controller *rst_rc;
99 1.4.2.2 skrll void *rst_priv;
100 1.4.2.2 skrll };
101 1.4.2.2 skrll
102 1.4.2.2 skrll struct fdtbus_reset_controller_func {
103 1.4.2.2 skrll void * (*acquire)(device_t, const void *, size_t);
104 1.4.2.2 skrll void (*release)(device_t, void *);
105 1.4.2.2 skrll int (*reset_assert)(device_t, void *);
106 1.4.2.2 skrll int (*reset_deassert)(device_t, void *);
107 1.4.2.2 skrll };
108 1.4.2.2 skrll
109 1.4.2.2 skrll int fdtbus_register_interrupt_controller(device_t, int,
110 1.4.2.2 skrll const struct fdtbus_interrupt_controller_func *);
111 1.4.2.2 skrll int fdtbus_register_i2c_controller(device_t, int,
112 1.4.2.2 skrll const struct fdtbus_i2c_controller_func *);
113 1.4.2.2 skrll int fdtbus_register_gpio_controller(device_t, int,
114 1.4.2.2 skrll const struct fdtbus_gpio_controller_func *);
115 1.4.2.2 skrll int fdtbus_register_regulator_controller(device_t, int,
116 1.4.2.2 skrll const struct fdtbus_regulator_controller_func *);
117 1.4.2.2 skrll int fdtbus_register_clock_controller(device_t, int,
118 1.4.2.2 skrll const struct fdtbus_clock_controller_func *);
119 1.4.2.2 skrll int fdtbus_register_reset_controller(device_t, int,
120 1.4.2.2 skrll const struct fdtbus_reset_controller_func *);
121 1.4.2.2 skrll
122 1.4.2.2 skrll int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
123 1.4.2.2 skrll int fdtbus_get_phandle(int, const char *);
124 1.4.2.2 skrll int fdtbus_get_phandle_from_native(int);
125 1.4.2.2 skrll i2c_tag_t fdtbus_get_i2c_tag(int);
126 1.4.2.2 skrll void * fdtbus_intr_establish(int, u_int, int, int,
127 1.4.2.2 skrll int (*func)(void *), void *arg);
128 1.4.2.2 skrll void fdtbus_intr_disestablish(int, void *);
129 1.4.2.2 skrll bool fdtbus_intr_str(int, u_int, char *, size_t);
130 1.4.2.2 skrll struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
131 1.4.2.2 skrll void fdtbus_gpio_release(struct fdtbus_gpio_pin *);
132 1.4.2.2 skrll int fdtbus_gpio_read(struct fdtbus_gpio_pin *);
133 1.4.2.2 skrll void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
134 1.4.2.2 skrll int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
135 1.4.2.2 skrll void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
136 1.4.2.2 skrll struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
137 1.4.2.2 skrll void fdtbus_regulator_release(struct fdtbus_regulator *);
138 1.4.2.2 skrll int fdtbus_regulator_enable(struct fdtbus_regulator *);
139 1.4.2.2 skrll int fdtbus_regulator_disable(struct fdtbus_regulator *);
140 1.4.2.2 skrll
141 1.4.2.2 skrll struct clk * fdtbus_clock_get(int, const char *);
142 1.4.2.2 skrll struct clk * fdtbus_clock_get_index(int, u_int);
143 1.4.2.2 skrll
144 1.4.2.2 skrll struct fdtbus_reset *fdtbus_reset_get(int, const char *);
145 1.4.2.2 skrll struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
146 1.4.2.2 skrll void fdtbus_reset_put(struct fdtbus_reset *);
147 1.4.2.2 skrll int fdtbus_reset_assert(struct fdtbus_reset *);
148 1.4.2.2 skrll int fdtbus_reset_deassert(struct fdtbus_reset *);
149 1.4.2.2 skrll
150 1.4.2.2 skrll bool fdtbus_set_data(const void *);
151 1.4.2.2 skrll const void * fdtbus_get_data(void);
152 1.4.2.2 skrll int fdtbus_phandle2offset(int);
153 1.4.2.2 skrll int fdtbus_offset2phandle(int);
154 1.4.2.2 skrll
155 1.4.2.2 skrll #endif /* _DEV_FDT_FDTVAR_H */
156