1 /* $Id: arbus.c,v 1.10 2006/09/04 05:17:26 gdamore Exp $ */
3 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
4 * Copyright (c) 2006 Garrett D'Amore.
7 * This code was written by Garrett D'Amore for the Champaign-Urbana
8 * Community Wireless Network Project.
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgements:
21 * This product includes software developed by the Urbana-Champaign
22 * Independent Media Center.
23 * This product includes software developed by Garrett D'Amore.
24 * 4. Urbana-Champaign Independent Media Center's name and Garrett
25 * D'Amore's name may not be used to endorse or promote products
26 * derived from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
29 * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
33 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: arbus.c,v 1.9 2006/08/28 07:21:15 gdamore Exp $");
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 #include <sys/extent.h>
51 #include <sys/malloc.h>
53 #define _MIPS_BUS_DMA_PRIVATE
54 #include <machine/bus.h>
55 #include <mips/atheros/include/ar5312reg.h>
56 #include <mips/atheros/include/ar531xvar.h>
57 #include <mips/atheros/include/arbusvar.h>
59 static int arbus_match(struct device
*, struct cfdata
*, void *);
60 static void arbus_attach(struct device
*, struct device
*, void *);
61 static int arbus_print(void *, const char *);
62 static void arbus_bus_mem_init(bus_space_tag_t
, void *);
63 static void arbus_dma_init(struct device
*, bus_dma_tag_t
);
65 struct arbus_intrhand
{
71 CFATTACH_DECL(arbus
, sizeof(struct device
), arbus_match
, arbus_attach
,
74 struct mips_bus_space arbus_mbst
;
75 struct mips_bus_dma_tag arbus_mdt
;
85 arbus_bus_mem_init(&arbus_mbst
, NULL
);
86 arbus_dma_init(NULL
, &arbus_mdt
);
89 /* this primarily exists so we can get to the console... */
91 arbus_get_bus_space_tag(void)
98 arbus_get_bus_dma_tag(void)
105 arbus_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
112 arbus_attach(struct device
*parent
, struct device
*self
, void *aux
)
114 struct arbus_attach_args aa
;
115 const struct ar531x_device
*devices
;
119 int locs
[ARBUSCF_NLOCS
];
123 for (i
= 0, devices
= ar531x_get_devices(); devices
[i
].name
; i
++) {
125 aa
.aa_name
= devices
[i
].name
;
126 aa
.aa_size
= devices
[i
].size
;
127 aa
.aa_dmat
= &arbus_mdt
;
128 aa
.aa_bst
= &arbus_mbst
;
129 aa
.aa_cirq
= devices
[i
].cirq
;
130 aa
.aa_mirq
= devices
[i
].mirq
;
131 aa
.aa_addr
= devices
[i
].addr
;
133 locs
[ARBUSCF_ADDR
] = aa
.aa_addr
;
135 if (ar531x_enable_device(&devices
[i
]) != 0) {
139 (void) config_found_sm_loc(self
, "arbus", locs
, &aa
,
140 arbus_print
, config_stdsubmatch
);
145 arbus_print(void *aux
, const char *pnp
)
147 struct arbus_attach_args
*aa
= aux
;
150 aprint_normal("%s at %s", aa
->aa_name
, pnp
);
153 aprint_normal(" addr 0x%lx", aa
->aa_addr
);
155 if (aa
->aa_cirq
>= 0)
156 aprint_normal(" cpu irq %d", aa
->aa_cirq
);
158 if (aa
->aa_mirq
>= 0)
159 aprint_normal(" misc irq %d", aa
->aa_mirq
);
165 arbus_intr_establish(int cirq
, int mirq
, int (*handler
)(void *), void *arg
)
167 struct arbus_intrhand
*ih
;
169 ih
= malloc(sizeof(*ih
), M_DEVBUF
, M_NOWAIT
);
173 ih
->ih_cirq
= ih
->ih_mirq
= -1;
174 ih
->ih_cookie
= NULL
;
178 ih
->ih_cookie
= ar531x_misc_intr_establish(mirq
, handler
, arg
);
179 } else if (cirq
>= 0) {
181 ih
->ih_cookie
= ar531x_cpu_intr_establish(cirq
, handler
, arg
);
185 if (ih
->ih_cookie
== NULL
) {
193 arbus_intr_disestablish(void *arg
)
195 struct arbus_intrhand
*ih
= arg
;
196 if (ih
->ih_mirq
>= 0)
197 ar531x_misc_intr_disestablish(ih
->ih_cookie
);
198 else if (ih
->ih_cirq
>= 0)
199 ar531x_cpu_intr_disestablish(ih
->ih_cookie
);
205 arbus_dma_init(struct device
*sc
, bus_dma_tag_t pdt
)
213 t
->_wsize
= MIPS_KSEG1_START
- MIPS_KSEG0_START
;
214 t
->_dmamap_create
= _bus_dmamap_create
;
215 t
->_dmamap_destroy
= _bus_dmamap_destroy
;
216 t
->_dmamap_load
= _bus_dmamap_load
;
217 t
->_dmamap_load_mbuf
= _bus_dmamap_load_mbuf
;
218 t
->_dmamap_load_uio
= _bus_dmamap_load_uio
;
219 t
->_dmamap_load_raw
= _bus_dmamap_load_raw
;
220 t
->_dmamap_unload
= _bus_dmamap_unload
;
221 t
->_dmamap_sync
= _bus_dmamap_sync
;
222 t
->_dmamem_alloc
= _bus_dmamem_alloc
;
223 t
->_dmamem_free
= _bus_dmamem_free
;
224 t
->_dmamem_map
= _bus_dmamem_map
;
225 t
->_dmamem_unmap
= _bus_dmamem_unmap
;
226 t
->_dmamem_mmap
= _bus_dmamem_mmap
;
230 * CPU memory/register stuff
234 #define CHIP_MEM /* defined */
235 #define CHIP_W1_BUS_START(v) 0x00000000UL
236 #define CHIP_W1_BUS_END(v) 0x1fffffffUL
237 #define CHIP_W1_SYS_START(v) CHIP_W1_BUS_START(v)
238 #define CHIP_W1_SYS_END(v) CHIP_W1_BUS_END(v)
240 #include <mips/mips/bus_space_alignstride_chipdep.c>