fdtvar.h revision 1.4.2.2 1 /* $NetBSD: fdtvar.h,v 1.4.2.2 2015/12/27 12:09:49 skrll 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/ofw/openfirm.h>
39
40 struct fdt_attach_args {
41 const char *faa_name;
42 bus_space_tag_t faa_bst;
43 bus_space_tag_t faa_a4x_bst;
44 bus_dma_tag_t faa_dmat;
45 int faa_phandle;
46
47 const char **faa_init;
48 int faa_ninit;
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, int, u_int, int, int,
56 int (*)(void *), void *);
57 void (*disestablish)(device_t, void *);
58 bool (*intrstr)(device_t, int, 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_regulator_controller;
80
81 struct fdtbus_regulator {
82 struct fdtbus_regulator_controller *reg_rc;
83 };
84
85 struct fdtbus_regulator_controller_func {
86 int (*acquire)(device_t);
87 void (*release)(device_t);
88 int (*enable)(device_t, bool);
89 };
90
91 struct fdtbus_clock_controller_func {
92 struct clk * (*decode)(device_t, const void *, size_t);
93 };
94
95 struct fdtbus_reset_controller;
96
97 struct fdtbus_reset {
98 struct fdtbus_reset_controller *rst_rc;
99 void *rst_priv;
100 };
101
102 struct fdtbus_reset_controller_func {
103 void * (*acquire)(device_t, const void *, size_t);
104 void (*release)(device_t, void *);
105 int (*reset_assert)(device_t, void *);
106 int (*reset_deassert)(device_t, void *);
107 };
108
109 int fdtbus_register_interrupt_controller(device_t, int,
110 const struct fdtbus_interrupt_controller_func *);
111 int fdtbus_register_i2c_controller(device_t, int,
112 const struct fdtbus_i2c_controller_func *);
113 int fdtbus_register_gpio_controller(device_t, int,
114 const struct fdtbus_gpio_controller_func *);
115 int fdtbus_register_regulator_controller(device_t, int,
116 const struct fdtbus_regulator_controller_func *);
117 int fdtbus_register_clock_controller(device_t, int,
118 const struct fdtbus_clock_controller_func *);
119 int fdtbus_register_reset_controller(device_t, int,
120 const struct fdtbus_reset_controller_func *);
121
122 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
123 int fdtbus_get_phandle(int, const char *);
124 int fdtbus_get_phandle_from_native(int);
125 i2c_tag_t fdtbus_get_i2c_tag(int);
126 void * fdtbus_intr_establish(int, u_int, int, int,
127 int (*func)(void *), void *arg);
128 void fdtbus_intr_disestablish(int, void *);
129 bool fdtbus_intr_str(int, u_int, char *, size_t);
130 struct fdtbus_gpio_pin *fdtbus_gpio_acquire(int, const char *, int);
131 void fdtbus_gpio_release(struct fdtbus_gpio_pin *);
132 int fdtbus_gpio_read(struct fdtbus_gpio_pin *);
133 void fdtbus_gpio_write(struct fdtbus_gpio_pin *, int);
134 int fdtbus_gpio_read_raw(struct fdtbus_gpio_pin *);
135 void fdtbus_gpio_write_raw(struct fdtbus_gpio_pin *, int);
136 struct fdtbus_regulator *fdtbus_regulator_acquire(int, const char *);
137 void fdtbus_regulator_release(struct fdtbus_regulator *);
138 int fdtbus_regulator_enable(struct fdtbus_regulator *);
139 int fdtbus_regulator_disable(struct fdtbus_regulator *);
140
141 struct clk * fdtbus_clock_get(int, const char *);
142 struct clk * fdtbus_clock_get_index(int, u_int);
143
144 struct fdtbus_reset *fdtbus_reset_get(int, const char *);
145 struct fdtbus_reset *fdtbus_reset_get_index(int, u_int);
146 void fdtbus_reset_put(struct fdtbus_reset *);
147 int fdtbus_reset_assert(struct fdtbus_reset *);
148 int fdtbus_reset_deassert(struct fdtbus_reset *);
149
150 bool fdtbus_set_data(const void *);
151 const void * fdtbus_get_data(void);
152 int fdtbus_phandle2offset(int);
153 int fdtbus_offset2phandle(int);
154
155 #endif /* _DEV_FDT_FDTVAR_H */
156