platform.h revision 1.1 1 1.1 matt /* $NetBSD: platform.h,v 1.1 2011/07/07 05:06:44 matt Exp $ */
2 1.1 matt /*
3 1.1 matt * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 1.1 matt * Copyright (c) 2006 Garrett D'Amore.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code was written by Garrett D'Amore for the Champaign-Urbana
8 1.1 matt * Community Wireless Network Project.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or
11 1.1 matt * without modification, are permitted provided that the following
12 1.1 matt * conditions are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above
16 1.1 matt * copyright notice, this list of conditions and the following
17 1.1 matt * disclaimer in the documentation and/or other materials provided
18 1.1 matt * with the distribution.
19 1.1 matt * 3. All advertising materials mentioning features or use of this
20 1.1 matt * software must display the following acknowledgements:
21 1.1 matt * This product includes software developed by the Urbana-Champaign
22 1.1 matt * Independent Media Center.
23 1.1 matt * This product includes software developed by Garrett D'Amore.
24 1.1 matt * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 1.1 matt * D'Amore's name may not be used to endorse or promote products
26 1.1 matt * derived from this software without specific prior written permission.
27 1.1 matt *
28 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 1.1 matt * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 1.1 matt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.1 matt * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 1.1 matt * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 1.1 matt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 1.1 matt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 1.1 matt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 1.1 matt * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 1.1 matt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 1.1 matt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 1.1 matt */
42 1.1 matt
43 1.1 matt #ifndef _MIPS_ATHEROS_PLATFORM_H_
44 1.1 matt #define _MIPS_ATHEROS_PLATFORM_H_
45 1.1 matt
46 1.1 matt #include <sys/param.h>
47 1.1 matt #include <sys/bus.h>
48 1.1 matt
49 1.1 matt struct atheros_device {
50 1.1 matt const char *adv_name;
51 1.1 matt bus_addr_t adv_addr;
52 1.1 matt bus_size_t adv_size;
53 1.1 matt u_int adv_cirq;
54 1.1 matt u_int adv_mirq;
55 1.1 matt uint32_t adv_mask;
56 1.1 matt uint32_t adv_reset;
57 1.1 matt uint32_t adv_enable;
58 1.1 matt };
59 1.1 matt
60 1.1 matt /*
61 1.1 matt * Board specific things.
62 1.1 matt */
63 1.1 matt struct atheros_boarddata;
64 1.1 matt struct atheros_config;
65 1.1 matt
66 1.1 matt struct atheros_intrsw {
67 1.1 matt void (*aisw_init)(void);
68 1.1 matt void *(*aisw_cpu_establish)(int, int (*)(void *), void *);
69 1.1 matt void (*aisw_cpu_disestablish)(void *);
70 1.1 matt void *(*aisw_misc_establish)(int, int (*)(void *), void *);
71 1.1 matt void (*aisw_misc_disestablish)(void *);
72 1.1 matt void (*aisw_cpuintr)(int, vaddr_t, uint32_t);
73 1.1 matt void (*aisw_iointr)(int, vaddr_t, uint32_t);
74 1.1 matt };
75 1.1 matt
76 1.1 matt struct arfreqs {
77 1.1 matt uint32_t freq_bus;
78 1.1 matt uint32_t freq_cpu;
79 1.1 matt uint32_t freq_mem;
80 1.1 matt uint32_t freq_pll;
81 1.1 matt uint32_t freq_ref;
82 1.1 matt };
83 1.1 matt
84 1.1 matt struct atheros_platformsw {
85 1.1 matt const struct atheros_intrsw *apsw_intrsw;
86 1.1 matt
87 1.1 matt void (*apsw_intr_init)(void);
88 1.1 matt const char * const * apsw_cpu_intrnames;
89 1.1 matt const char * const * apsw_misc_intrnames;
90 1.1 matt size_t apsw_cpu_nintrs;
91 1.1 matt size_t apsw_misc_nintrs;
92 1.1 matt u_int apsw_cpuirq_misc;
93 1.1 matt
94 1.1 matt bus_addr_t apsw_misc_intmask;
95 1.1 matt bus_addr_t apsw_misc_intstat;
96 1.1 matt
97 1.1 matt const struct ipl_sr_map *apsw_ipl_sr_map;
98 1.1 matt
99 1.1 matt /*
100 1.1 matt * CPU specific routines.
101 1.1 matt */
102 1.1 matt size_t (*apsw_get_memsize)(void);
103 1.1 matt void (*apsw_wdog_reload)(uint32_t);
104 1.1 matt void (*apsw_bus_init)(void);
105 1.1 matt void (*apsw_get_freqs)(struct arfreqs *);
106 1.1 matt void (*apsw_device_register)(device_t, void *);
107 1.1 matt int (*apsw_enable_device)(const struct atheros_device *);
108 1.1 matt void (*apsw_reset)(void);
109 1.1 matt const struct atheros_device *apsw_devices;
110 1.1 matt
111 1.1 matt /*
112 1.1 matt * Early console support.
113 1.1 matt */
114 1.1 matt bus_addr_t apsw_uart0_base;
115 1.1 matt bus_addr_t apsw_revision_id_addr;
116 1.1 matt };
117 1.1 matt
118 1.1 matt /*
119 1.1 matt * Board specific data.
120 1.1 matt */
121 1.1 matt struct ar531x_config;
122 1.1 matt struct ar531x_boarddata;
123 1.1 matt struct atheros_boardsw {
124 1.1 matt const struct ar531x_boarddata *(*absw_get_board_info)(void);
125 1.1 matt const void *(*absw_get_radio_info)(void);
126 1.1 matt };
127 1.1 matt
128 1.1 matt #ifdef _KERNEL
129 1.1 matt void atheros_consinit(void);
130 1.1 matt void atheros_early_consinit(void);
131 1.1 matt
132 1.1 matt void atheros_set_platformsw(void);
133 1.1 matt const char *
134 1.1 matt atheros_get_cpuname(void);
135 1.1 matt u_int atheros_get_chipid(void);
136 1.1 matt
137 1.1 matt uint32_t atheros_get_bus_freq(void);
138 1.1 matt uint32_t atheros_get_cpu_freq(void);
139 1.1 matt uint32_t atheros_get_mem_freq(void);
140 1.1 matt
141 1.1 matt const struct ar531x_boarddata *
142 1.1 matt atheros_get_board_info(void);
143 1.1 matt int atheros_get_board_config(struct ar531x_config *);
144 1.1 matt
145 1.1 matt extern const struct atheros_boardsw ar5312_boardsw;
146 1.1 matt extern const struct atheros_boardsw ar5315_boardsw;
147 1.1 matt
148 1.1 matt extern const struct atheros_platformsw ar5312_platformsw;
149 1.1 matt extern const struct atheros_platformsw ar5315_platformsw;
150 1.1 matt extern const struct atheros_platformsw ar7100_platformsw;
151 1.1 matt extern const struct atheros_platformsw ar9344_platformsw;
152 1.1 matt extern const struct atheros_platformsw *platformsw;
153 1.1 matt
154 1.1 matt extern const struct atheros_intrsw atheros_intrsw;
155 1.1 matt
156 1.1 matt static inline uint32_t
157 1.1 matt atheros_get_memsize(void)
158 1.1 matt {
159 1.1 matt return (*platformsw->apsw_get_memsize)();
160 1.1 matt }
161 1.1 matt
162 1.1 matt static inline void
163 1.1 matt atheros_wdog_reload(uint32_t period)
164 1.1 matt {
165 1.1 matt (*platformsw->apsw_wdog_reload)(period);
166 1.1 matt }
167 1.1 matt
168 1.1 matt static inline void
169 1.1 matt atheros_bus_init(void)
170 1.1 matt {
171 1.1 matt return (*platformsw->apsw_bus_init)();
172 1.1 matt }
173 1.1 matt
174 1.1 matt static inline void
175 1.1 matt atheros_intr_init(void)
176 1.1 matt {
177 1.1 matt (*platformsw->apsw_intrsw->aisw_init)();
178 1.1 matt }
179 1.1 matt
180 1.1 matt static inline void *
181 1.1 matt atheros_cpu_intr_establish(int irq, int (*func)(void *), void *arg)
182 1.1 matt {
183 1.1 matt return (*platformsw->apsw_intrsw->aisw_cpu_establish)(irq, func, arg);
184 1.1 matt }
185 1.1 matt
186 1.1 matt static inline void
187 1.1 matt atheros_cpu_intr_disestablish(void *cookie)
188 1.1 matt {
189 1.1 matt (*platformsw->apsw_intrsw->aisw_cpu_disestablish)(cookie);
190 1.1 matt }
191 1.1 matt
192 1.1 matt static inline void *
193 1.1 matt atheros_misc_intr_establish(int irq, int (*func)(void *), void *arg)
194 1.1 matt {
195 1.1 matt return (*platformsw->apsw_intrsw->aisw_misc_establish)(irq, func, arg);
196 1.1 matt }
197 1.1 matt
198 1.1 matt static inline void
199 1.1 matt atheros_misc_intr_disestablish(void *cookie)
200 1.1 matt {
201 1.1 matt (*platformsw->apsw_intrsw->aisw_misc_disestablish)(cookie);
202 1.1 matt }
203 1.1 matt
204 1.1 matt static inline int
205 1.1 matt atheros_enable_device(const struct atheros_device *adv)
206 1.1 matt {
207 1.1 matt return (*platformsw->apsw_enable_device)(adv);
208 1.1 matt }
209 1.1 matt
210 1.1 matt static inline void
211 1.1 matt atheros_reset(void)
212 1.1 matt {
213 1.1 matt return (*platformsw->apsw_reset)();
214 1.1 matt }
215 1.1 matt
216 1.1 matt #endif /* _KERNEL */
217 1.1 matt
218 1.1 matt #endif /* _MIPS_ATHEROS_PLATFORM_H_ */
219