1 /* $NetBSD: aubus.c,v 1.12 2004/09/13 14:57:31 drochner Exp $ */ 2 3 /* 4 * Copyright 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Simon Burge for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 40 * 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * 1. Redistributions of source code must retain the above copyright 45 * notice, this list of conditions and the following disclaimer. 46 * 2. Redistributions in binary form must reproduce the above copyright 47 * notice, this list of conditions and the following disclaimer in the 48 * documentation and/or other materials provided with the distribution. 49 * 3. All advertising materials mentioning features or use of this software 50 * must display the following acknowledgement: 51 * This product includes software developed by Christopher G. Demetriou 52 * for the NetBSD Project. 53 * 4. The name of the author may not be used to endorse or promote products 54 * derived from this software without specific prior written permission 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 */ 67 68 #include <sys/cdefs.h> 69 __KERNEL_RCSID(0, "$NetBSD: aubus.c,v 1.12 2004/09/13 14:57:31 drochner Exp $"); 70 71 #include "locators.h" 72 73 #include <sys/param.h> 74 #include <sys/systm.h> 75 #include <sys/device.h> 76 #include <sys/extent.h> 77 #include <sys/malloc.h> 78 79 #define _MIPS_BUS_DMA_PRIVATE 80 #include <machine/bus.h> 81 #include <machine/locore.h> 82 #include <mips/alchemy/include/aureg.h> 83 #include <mips/alchemy/include/aubusvar.h> 84 85 86 struct au1x00_dev { 87 const char *name; 88 bus_addr_t addr[3]; 89 int irq[2]; 90 }; 91 92 /* 93 * The devices built in to the Au1000 CPU. 94 */ 95 const struct au1x00_dev au1000_devs [] = { 96 { "aucom", { UART0_BASE }, { 0, -1 }}, 97 { "aucom", { UART1_BASE }, { 1, -1 }}, 98 { "aucom", { UART2_BASE }, { 2, -1 }}, 99 { "aucom", { UART3_BASE }, { 3, -1 }}, 100 { "aurtc", { }, { -1, -1 }}, 101 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 28, -1 }}, 102 { "aumac", { MAC1_BASE, MAC1_ENABLE, MAC1_DMA_BASE }, { 29, -1 }}, 103 { "auaudio", { AC97_BASE }, { 27, 31 }}, 104 { "ohci", { USBH_BASE }, { 26, -1 }}, 105 { "usbd", { USBD_BASE }, { 24, 25 }}, 106 { "irda", { IRDA_BASE }, { 22, 23 }}, 107 { "gpio", { SYS_BASE }, { -1, -1 }}, 108 { "i2s", { I2S_BASE }, { -1, -1 }}, 109 { "ssi", { SSI0_BASE }, { 4, -1 }}, 110 { "ssi", { SSI1_BASE }, { 5, -1 }}, 111 { NULL } 112 }; 113 114 /* 115 * The devices built in to the Au1500 CPU. 116 */ 117 const struct au1x00_dev au1500_devs [] = { 118 { "aucom", { UART0_BASE }, { 0, -1 }}, 119 { "aucom", { UART3_BASE }, { 3, -1 }}, 120 { "aurtc", { }, { -1, -1 }}, 121 { "aumac", { AU1500_MAC0_BASE, AU1500_MAC0_ENABLE, 122 MAC0_DMA_BASE }, { 28, -1 }}, 123 { "aumac", { AU1500_MAC1_BASE, AU1500_MAC1_ENABLE, 124 MAC1_DMA_BASE }, { 29, -1 }}, 125 { "auaudio", { AC97_BASE }, { 27, 31 }}, 126 { "ohci", { USBH_BASE }, { 26, -1 }}, 127 { "usbd", { USBD_BASE }, { 24, 25 }}, 128 { "gpio", { SYS_BASE }, { -1, -1 }}, 129 { "gpio2", { GPIO2_BASE }, { -1, -1 }}, 130 { "aupci", { }, { -1, -1 }}, 131 { NULL } 132 }; 133 134 135 /* 136 * The devices built in to the Au1100 CPU. 137 */ 138 const struct au1x00_dev au1100_devs [] = { 139 { "aucom", { UART0_BASE }, { 0, -1 }}, 140 { "aucom", { UART1_BASE }, { 1, -1 }}, 141 { "aucom", { UART3_BASE }, { 3, -1 }}, 142 { "aurtc", { }, { -1, -1 }}, 143 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 28, -1 }}, 144 { "auaudio", { AC97_BASE }, { 27, 31 }}, 145 { "ohci", { USBH_BASE }, { 26, -1 }}, 146 { "usbd", { USBD_BASE }, { 24, 25 }}, 147 { "irda", { IRDA_BASE }, { 22, 23 }}, 148 { "gpio", { SYS_BASE }, { -1, -1 }}, 149 { "gpio2", { GPIO2_BASE }, { 29, -1 }}, 150 { "i2s", { I2S_BASE }, { 30, -1 }}, 151 { "ssi", { SSI0_BASE }, { 4, -1 }}, 152 { "ssi", { SSI1_BASE }, { 5, -1 }}, 153 { "sd0", { SD0_BASE }, { 5, -1 }}, 154 { "sd1", { SD1_BASE }, { 5, -1 }}, 155 { NULL } 156 }; 157 158 159 static int aubus_match(struct device *, struct cfdata *, void *); 160 static void aubus_attach(struct device *, struct device *, void *); 161 static int aubus_submatch(struct device *, struct cfdata *, 162 const locdesc_t *, void *); 163 static int aubus_print(void *, const char *); 164 static void aubus_alloc_dma_tag(struct device *, bus_dma_tag_t); 165 166 CFATTACH_DECL(aubus, sizeof(struct device), 167 aubus_match, aubus_attach, NULL, NULL); 168 169 bus_space_tag_t aubus_st; /* XXX */ 170 struct mips_bus_dma_tag aubus_mdt; 171 172 /* 173 * Probe for the aubus; always succeeds. 174 */ 175 static int 176 aubus_match(struct device *parent, struct cfdata *match, void *aux) 177 { 178 179 return 1; 180 } 181 182 static int 183 aubus_submatch(struct device *parent, struct cfdata *cf, 184 const locdesc_t *ldesc, void *aux) 185 { 186 187 if (cf->cf_loc[AUBUSCF_ADDR] != AUBUSCF_ADDR_DEFAULT && 188 cf->cf_loc[AUBUSCF_ADDR] != ldesc->locs[AUBUSCF_ADDR]) 189 return (0); 190 191 return (config_match(parent, cf, aux)); 192 } 193 194 /* 195 * Attach the aubus. 196 */ 197 static void 198 aubus_attach(struct device *parent, struct device *self, void *aux) 199 { 200 struct aubus_attach_args aa; 201 struct device *sc = (struct device *)self; 202 const struct au1x00_dev *ad; 203 int help[2]; 204 locdesc_t *ldesc = (void *)help; /* XXX */ 205 206 printf("\n"); 207 208 switch (MIPS_PRID_COPTS(cpu_id)) { 209 case MIPS_AU1000: 210 ad = au1000_devs; 211 break; 212 case MIPS_AU1500: 213 ad = au1500_devs; 214 break; 215 case MIPS_AU1100: 216 ad = au1100_devs; 217 break; 218 default: 219 panic("Unknown Alchemy SOC identification %d", 220 MIPS_PRID_COPTS(cpu_id)); 221 } 222 223 for (; ad->name != NULL; ad++) { 224 aa.aa_name = ad->name; 225 aa.aa_st = aubus_st; 226 aa.aa_dt = &aubus_mdt; 227 aubus_alloc_dma_tag(sc, aa.aa_dt); 228 aa.aa_addrs[0] = ad->addr[0]; 229 aa.aa_addrs[1] = ad->addr[1]; 230 aa.aa_addrs[2] = ad->addr[2]; 231 aa.aa_irq[0] = ad->irq[0]; 232 aa.aa_irq[1] = ad->irq[1]; 233 234 ldesc->len = 1; 235 ldesc->locs[AUBUSCF_ADDR] = ad->addr[0]; 236 237 (void) config_found_sm_loc(self, "aubus", ldesc, &aa, 238 aubus_print, aubus_submatch); 239 } 240 } 241 242 static int 243 aubus_print(void *aux, const char *pnp) 244 { 245 struct aubus_attach_args *aa = aux; 246 247 if (pnp) 248 aprint_normal("%s at %s", aa->aa_name, pnp); 249 250 if (aa->aa_addr != AUBUSCF_ADDR_DEFAULT) 251 aprint_normal(" %s 0x%lx", aubuscf_locnames[AUBUSCF_ADDR], 252 aa->aa_addr); 253 if (aa->aa_irq[0] >= 0) 254 aprint_normal(" irq %d", aa->aa_irq[0]); 255 if (aa->aa_irq[1] >= 0) 256 aprint_normal(",%d", aa->aa_irq[1]); 257 return (UNCONF); 258 } 259 260 void 261 aubus_alloc_dma_tag(sc, pdt) 262 struct device *sc; 263 bus_dma_tag_t pdt; 264 { 265 bus_dma_tag_t t; 266 267 t = pdt; 268 t->_cookie = sc; 269 t->_wbase = 0; /* XXX */ 270 t->_physbase = 0; /* XXX */ 271 t->_wsize = MIPS_KSEG1_START - MIPS_KSEG0_START; 272 t->_dmamap_create = _bus_dmamap_create; 273 t->_dmamap_destroy = _bus_dmamap_destroy; 274 t->_dmamap_load = _bus_dmamap_load; 275 t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf; 276 t->_dmamap_load_uio = _bus_dmamap_load_uio; 277 t->_dmamap_load_raw = _bus_dmamap_load_raw; 278 t->_dmamap_unload = _bus_dmamap_unload; 279 t->_dmamap_sync = _bus_dmamap_sync; 280 t->_dmamem_alloc = _bus_dmamem_alloc; 281 t->_dmamem_free = _bus_dmamem_free; 282 t->_dmamem_map = _bus_dmamem_map; 283 t->_dmamem_unmap = _bus_dmamem_unmap; 284 t->_dmamem_mmap = _bus_dmamem_mmap; 285 } 286