fdtvar.h revision 1.82 1 /* $NetBSD: fdtvar.h,v 1.82 2025/09/06 21:02:42 thorpej 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/clock_subr.h>
37
38 #include <dev/ofw/openfirm.h>
39
40 #include <dev/fdt/fdt_clock.h>
41 #include <dev/fdt/fdt_dai.h>
42 #include <dev/fdt/fdt_dma.h>
43 #include <dev/fdt/fdt_gpio.h>
44 #include <dev/fdt/fdt_i2c.h>
45 #include <dev/fdt/fdt_intr.h>
46 #include <dev/fdt/fdt_iommu.h>
47 #include <dev/fdt/fdt_mbox.h>
48 #include <dev/fdt/fdt_mmc_pwrseq.h>
49 #include <dev/fdt/fdt_phy.h>
50 #include <dev/fdt/fdt_pinctrl.h>
51 #include <dev/fdt/fdt_power.h>
52 #include <dev/fdt/fdt_powerdomain.h>
53 #include <dev/fdt/fdt_pwm.h>
54 #include <dev/fdt/fdt_regulator.h>
55 #include <dev/fdt/fdt_reset.h>
56 #include <dev/fdt/fdt_spi.h>
57 #include <dev/fdt/fdt_syscon.h>
58
59 struct fdt_attach_args {
60 const char *faa_name;
61 bus_space_tag_t faa_bst;
62 bus_dma_tag_t faa_dmat;
63 int faa_phandle;
64 int faa_quiet;
65 };
66
67 struct fdt_console {
68 int (*match)(int);
69 void (*consinit)(struct fdt_attach_args *, u_int);
70 };
71
72 struct fdt_console_info {
73 const struct fdt_console *ops;
74 };
75
76 struct fdt_phandle_data {
77 int phandle;
78 int count;
79 const u_int *values;
80 };
81
82 #define _FDT_CONSOLE_REGISTER(name) \
83 __link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
84
85 #define FDT_CONSOLE(_name, _ops) \
86 static const struct fdt_console_info __CONCAT(_name,_consinfo) = { \
87 .ops = (_ops) \
88 }; \
89 _FDT_CONSOLE_REGISTER(_name)
90
91 struct fdt_opp_info {
92 const char * opp_compat;
93 bool (*opp_supported)(const int, const int);
94 };
95
96 #define _FDT_OPP_REGISTER(name) \
97 __link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
98
99 #define FDT_OPP(_name, _compat, _suppfn) \
100 static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = { \
101 .opp_compat = (_compat), \
102 .opp_supported = (_suppfn) \
103 }; \
104 _FDT_OPP_REGISTER(_name)
105
106 TAILQ_HEAD(fdt_conslist, fdt_console_info);
107
108 struct fdt_dma_range {
109 paddr_t dr_sysbase;
110 bus_addr_t dr_busbase;
111 bus_size_t dr_len;
112 };
113
114 #define FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO __BIT(0)
115
116 void fdtbus_set_decoderegprop(bool);
117
118 int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
119 int fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
120 bus_size_t *);
121 int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
122 int fdtbus_get_addr_cells(int);
123 int fdtbus_get_size_cells(int);
124 uint64_t fdtbus_get_cells(const uint8_t *, int);
125 int fdtbus_get_phandle(int, const char *);
126 int fdtbus_get_phandle_with_data(int, const char *, const char *,
127 int, struct fdt_phandle_data *);
128 int fdtbus_get_phandle_from_native(int);
129
130 int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
131
132 bool fdtbus_init(const void *);
133 const void * fdtbus_get_data(void);
134 int fdtbus_phandle2offset(int);
135 int fdtbus_offset2phandle(int);
136 bool fdtbus_get_path(int, char *, size_t);
137
138 const struct fdt_console *
139 fdtbus_get_console(void);
140
141 const char * fdtbus_get_stdout_path(void);
142 int fdtbus_get_stdout_phandle(void);
143 int fdtbus_get_stdout_speed(void);
144 tcflag_t fdtbus_get_stdout_flags(void);
145
146 bool fdtbus_status_okay(int);
147
148 const void * fdtbus_get_prop(int, const char *, int *);
149 const char * fdtbus_get_string(int, const char *);
150 const char * fdtbus_get_string_index(int, const char *, u_int);
151 int fdtbus_get_index(int, const char *, const char *, u_int *);
152
153 void fdtbus_cpus_md_attach(device_t, device_t, void *);
154
155 void fdt_add_bus(device_t, int, struct fdt_attach_args *);
156 void fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
157 bool (*)(void *, int), void *);
158 void fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
159
160 void fdt_remove_byhandle(int);
161 void fdt_remove_bycompat(const char *[]);
162 int fdt_find_with_property(const char *, int *);
163
164 int fdtbus_print(void *, const char *);
165
166 bus_dma_tag_t fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
167 u_int);
168 bus_space_tag_t fdtbus_bus_tag_create(int, uint32_t);
169
170
171 #endif /* _DEV_FDT_FDTVAR_H_ */
172