fdtvar.h revision 1.82 1 1.82 thorpej /* $NetBSD: fdtvar.h,v 1.82 2025/09/06 21:02:42 thorpej Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.62 skrll #ifndef _DEV_FDT_FDTVAR_H_
30 1.62 skrll #define _DEV_FDT_FDTVAR_H_
31 1.1 jmcneill
32 1.1 jmcneill #include <sys/types.h>
33 1.1 jmcneill #include <sys/bus.h>
34 1.19 jmcneill #include <sys/termios.h>
35 1.1 jmcneill
36 1.11 jmcneill #include <dev/clock_subr.h>
37 1.11 jmcneill
38 1.1 jmcneill #include <dev/ofw/openfirm.h>
39 1.1 jmcneill
40 1.81 thorpej #include <dev/fdt/fdt_clock.h>
41 1.81 thorpej #include <dev/fdt/fdt_dai.h>
42 1.81 thorpej #include <dev/fdt/fdt_dma.h>
43 1.81 thorpej #include <dev/fdt/fdt_gpio.h>
44 1.81 thorpej #include <dev/fdt/fdt_i2c.h>
45 1.81 thorpej #include <dev/fdt/fdt_intr.h>
46 1.81 thorpej #include <dev/fdt/fdt_iommu.h>
47 1.81 thorpej #include <dev/fdt/fdt_mbox.h>
48 1.81 thorpej #include <dev/fdt/fdt_mmc_pwrseq.h>
49 1.81 thorpej #include <dev/fdt/fdt_phy.h>
50 1.81 thorpej #include <dev/fdt/fdt_pinctrl.h>
51 1.81 thorpej #include <dev/fdt/fdt_power.h>
52 1.81 thorpej #include <dev/fdt/fdt_powerdomain.h>
53 1.81 thorpej #include <dev/fdt/fdt_pwm.h>
54 1.81 thorpej #include <dev/fdt/fdt_regulator.h>
55 1.81 thorpej #include <dev/fdt/fdt_reset.h>
56 1.81 thorpej #include <dev/fdt/fdt_spi.h>
57 1.81 thorpej #include <dev/fdt/fdt_syscon.h>
58 1.81 thorpej
59 1.1 jmcneill struct fdt_attach_args {
60 1.1 jmcneill const char *faa_name;
61 1.1 jmcneill bus_space_tag_t faa_bst;
62 1.1 jmcneill bus_dma_tag_t faa_dmat;
63 1.1 jmcneill int faa_phandle;
64 1.13 jmcneill int faa_quiet;
65 1.1 jmcneill };
66 1.1 jmcneill
67 1.19 jmcneill struct fdt_console {
68 1.19 jmcneill int (*match)(int);
69 1.20 jmcneill void (*consinit)(struct fdt_attach_args *, u_int);
70 1.19 jmcneill };
71 1.19 jmcneill
72 1.19 jmcneill struct fdt_console_info {
73 1.19 jmcneill const struct fdt_console *ops;
74 1.19 jmcneill };
75 1.19 jmcneill
76 1.52 hkenken struct fdt_phandle_data {
77 1.52 hkenken int phandle;
78 1.52 hkenken int count;
79 1.52 hkenken const u_int *values;
80 1.52 hkenken };
81 1.52 hkenken
82 1.19 jmcneill #define _FDT_CONSOLE_REGISTER(name) \
83 1.19 jmcneill __link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
84 1.19 jmcneill
85 1.19 jmcneill #define FDT_CONSOLE(_name, _ops) \
86 1.19 jmcneill static const struct fdt_console_info __CONCAT(_name,_consinfo) = { \
87 1.19 jmcneill .ops = (_ops) \
88 1.19 jmcneill }; \
89 1.19 jmcneill _FDT_CONSOLE_REGISTER(_name)
90 1.19 jmcneill
91 1.55 jmcneill struct fdt_opp_info {
92 1.55 jmcneill const char * opp_compat;
93 1.55 jmcneill bool (*opp_supported)(const int, const int);
94 1.55 jmcneill };
95 1.55 jmcneill
96 1.55 jmcneill #define _FDT_OPP_REGISTER(name) \
97 1.55 jmcneill __link_set_add_rodata(fdt_opps, __CONCAT(name,_oppinfo));
98 1.55 jmcneill
99 1.55 jmcneill #define FDT_OPP(_name, _compat, _suppfn) \
100 1.55 jmcneill static const struct fdt_opp_info __CONCAT(_name,_oppinfo) = { \
101 1.55 jmcneill .opp_compat = (_compat), \
102 1.55 jmcneill .opp_supported = (_suppfn) \
103 1.55 jmcneill }; \
104 1.55 jmcneill _FDT_OPP_REGISTER(_name)
105 1.55 jmcneill
106 1.19 jmcneill TAILQ_HEAD(fdt_conslist, fdt_console_info);
107 1.19 jmcneill
108 1.60 jmcneill struct fdt_dma_range {
109 1.60 jmcneill paddr_t dr_sysbase;
110 1.60 jmcneill bus_addr_t dr_busbase;
111 1.60 jmcneill bus_size_t dr_len;
112 1.60 jmcneill };
113 1.60 jmcneill
114 1.72 jmcneill #define FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO __BIT(0)
115 1.72 jmcneill
116 1.28 skrll void fdtbus_set_decoderegprop(bool);
117 1.28 skrll
118 1.2 jmcneill int fdtbus_get_reg(int, u_int, bus_addr_t *, bus_size_t *);
119 1.26 jmcneill int fdtbus_get_reg_byname(int, const char *, bus_addr_t *,
120 1.26 jmcneill bus_size_t *);
121 1.17 jmcneill int fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
122 1.60 jmcneill int fdtbus_get_addr_cells(int);
123 1.60 jmcneill int fdtbus_get_size_cells(int);
124 1.60 jmcneill uint64_t fdtbus_get_cells(const uint8_t *, int);
125 1.2 jmcneill int fdtbus_get_phandle(int, const char *);
126 1.52 hkenken int fdtbus_get_phandle_with_data(int, const char *, const char *,
127 1.52 hkenken int, struct fdt_phandle_data *);
128 1.3 jmcneill int fdtbus_get_phandle_from_native(int);
129 1.74 skrll
130 1.11 jmcneill int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
131 1.11 jmcneill
132 1.58 thorpej bool fdtbus_init(const void *);
133 1.2 jmcneill const void * fdtbus_get_data(void);
134 1.2 jmcneill int fdtbus_phandle2offset(int);
135 1.2 jmcneill int fdtbus_offset2phandle(int);
136 1.8 jmcneill bool fdtbus_get_path(int, char *, size_t);
137 1.1 jmcneill
138 1.74 skrll const struct fdt_console *
139 1.74 skrll fdtbus_get_console(void);
140 1.19 jmcneill
141 1.10 jmcneill const char * fdtbus_get_stdout_path(void);
142 1.10 jmcneill int fdtbus_get_stdout_phandle(void);
143 1.10 jmcneill int fdtbus_get_stdout_speed(void);
144 1.19 jmcneill tcflag_t fdtbus_get_stdout_flags(void);
145 1.10 jmcneill
146 1.15 jmcneill bool fdtbus_status_okay(int);
147 1.15 jmcneill
148 1.23 jmcneill const void * fdtbus_get_prop(int, const char *, int *);
149 1.22 jmcneill const char * fdtbus_get_string(int, const char *);
150 1.24 jmcneill const char * fdtbus_get_string_index(int, const char *, u_int);
151 1.49 jakllsch int fdtbus_get_index(int, const char *, const char *, u_int *);
152 1.22 jmcneill
153 1.79 skrll void fdtbus_cpus_md_attach(device_t, device_t, void *);
154 1.79 skrll
155 1.36 jmcneill void fdt_add_bus(device_t, int, struct fdt_attach_args *);
156 1.41 jmcneill void fdt_add_bus_match(device_t, int, struct fdt_attach_args *,
157 1.74 skrll bool (*)(void *, int), void *);
158 1.43 jmcneill void fdt_add_child(device_t, int, struct fdt_attach_args *, u_int);
159 1.36 jmcneill
160 1.29 bouyer void fdt_remove_byhandle(int);
161 1.29 bouyer void fdt_remove_bycompat(const char *[]);
162 1.45 jmcneill int fdt_find_with_property(const char *, int *);
163 1.69 thorpej
164 1.16 jmcneill int fdtbus_print(void *, const char *);
165 1.16 jmcneill
166 1.60 jmcneill bus_dma_tag_t fdtbus_dma_tag_create(int, const struct fdt_dma_range *,
167 1.60 jmcneill u_int);
168 1.72 jmcneill bus_space_tag_t fdtbus_bus_tag_create(int, uint32_t);
169 1.60 jmcneill
170 1.76 skrll
171 1.62 skrll #endif /* _DEV_FDT_FDTVAR_H_ */
172