Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / evbppc / explora / dev / elb.c
blobf4d3b25c27563363d236f433aad63951c68c0946
1 /* $NetBSD: elb.c,v 1.5 2005/12/11 12:17:12 christos Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: elb.c,v 1.5 2005/12/11 12:17:12 christos Exp $");
35 #include <sys/param.h>
36 #include <sys/conf.h>
37 #include <sys/device.h>
38 #include <sys/systm.h>
39 #include <sys/extent.h>
41 #include <machine/explora.h>
42 #define _POWERPC_BUS_DMA_PRIVATE
43 #include <machine/bus.h>
45 #include <powerpc/ibm4xx/dcr403cgx.h>
47 #include <evbppc/explora/dev/elbvar.h>
49 struct elb_dev {
50 const char *elb_name;
51 int elb_addr;
52 int elb_addr2;
53 int elb_irq;
54 bus_space_tag_t elb_bt;
57 static int elb_match(struct device *, struct cfdata *, void *);
58 static void elb_attach(struct device *, struct device *, void *);
59 static int elb_print(void *, const char *);
61 static struct powerpc_bus_space elb_tag = {
62 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE | 1, /* stride 1 */
63 0x00000000,
64 BASE_PCKBC,
65 BASE_PCKBC + 0x6ff
67 static char elb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
68 __attribute__((aligned(8)));
69 static int elb_tag_init_done;
71 static struct powerpc_bus_space elb_fb_tag = {
72 _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
73 0x00000000,
74 BASE_FB,
75 BASE_FB2 + SIZE_FB - 1
77 static char elbfb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
78 __attribute__((aligned(8)));
79 static int elbfb_tag_init_done;
82 * DMA struct, nothing special.
84 static struct powerpc_bus_dma_tag elb_bus_dma_tag = {
85 0, /* _bounce_thresh */
86 _bus_dmamap_create,
87 _bus_dmamap_destroy,
88 _bus_dmamap_load,
89 _bus_dmamap_load_mbuf,
90 _bus_dmamap_load_uio,
91 _bus_dmamap_load_raw,
92 _bus_dmamap_unload,
93 _bus_dmamap_sync,
94 _bus_dmamem_alloc,
95 _bus_dmamem_free,
96 _bus_dmamem_map,
97 _bus_dmamem_unmap,
98 _bus_dmamem_mmap,
99 _bus_dma_phys_to_bus_mem_generic,
100 _bus_dma_bus_mem_to_phys_generic,
103 static struct elb_dev elb_devs[] = {
104 { "cpu", 0, 0, -1, NULL },
105 { "pckbc", BASE_PCKBC, BASE_PCKBC2, 31, &elb_tag },
106 { "com", BASE_COM, 0, 30, &elb_tag },
107 { "lpt", BASE_LPT, 0, -1, &elb_tag },
108 { "fb", BASE_FB, BASE_FB2, -1, &elb_fb_tag },
109 { "le", BASE_LE, 0, 28, &elb_fb_tag },
112 CFATTACH_DECL(elb, sizeof(struct device),
113 elb_match, elb_attach, NULL, NULL);
116 * Probe for the elb; always succeeds.
118 static int
119 elb_match(struct device *parent, struct cfdata *cf, void *aux)
121 return (1);
125 * Attach the Explora local bus.
127 static void
128 elb_attach(struct device *parent, struct device *self, void *aux)
130 struct elb_attach_args eaa;
131 int i;
133 printf("\n");
134 for (i = 0; i < sizeof(elb_devs)/sizeof(elb_devs[0]); i++) {
135 eaa.elb_name = elb_devs[i].elb_name;
136 eaa.elb_bt = elb_get_bus_space_tag(elb_devs[i].elb_addr);
137 eaa.elb_dmat = &elb_bus_dma_tag;
138 eaa.elb_base = elb_devs[i].elb_addr;
139 eaa.elb_base2 = elb_devs[i].elb_addr2;
140 eaa.elb_irq = elb_devs[i].elb_irq;
142 (void) config_found(self, &eaa, elb_print);
146 static int
147 elb_print(void *aux, const char *pnp)
149 struct elb_attach_args *eaa = aux;
151 if (pnp)
152 aprint_normal("%s at %s", eaa->elb_name, pnp);
153 if (eaa->elb_irq != -1)
154 aprint_normal(" irq %d", eaa->elb_irq);
156 return (UNCONF);
159 bus_space_tag_t
160 elb_get_bus_space_tag(bus_addr_t addr)
163 if ((addr & 0xff000000) == 0x74000000) {
164 if (!elb_tag_init_done) {
165 if (bus_space_init(&elb_tag, "elbtag",
166 elb_ex_storage, sizeof(elb_ex_storage)))
167 panic("elb_get_bus_space_tag: elb_tag");
169 elb_tag_init_done = 1;
171 return (&elb_tag);
172 } else {
173 if (!elbfb_tag_init_done) {
174 if (bus_space_init(&elb_fb_tag, "elbfbtag",
175 elbfb_ex_storage, sizeof(elbfb_ex_storage)))
176 panic("elb_get_bus_space_tag: elb_fb_tag");
178 elbfb_tag_init_done = 1;
180 return (&elb_fb_tag);