1 /* $NetBSD: aubus.c,v 1.16 2005/12/11 12:18:06 christos 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.16 2005/12/11 12:18:06 christos 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_print(void *, const char *); 162 static void aubus_alloc_dma_tag(struct device *, bus_dma_tag_t); 163 164 CFATTACH_DECL(aubus, sizeof(struct device), 165 aubus_match, aubus_attach, NULL, NULL); 166 167 bus_space_tag_t aubus_st; /* XXX */ 168 struct mips_bus_dma_tag aubus_mdt; 169 170 /* 171 * Probe for the aubus; always succeeds. 172 */ 173 static int 174 aubus_match(struct device *parent, struct cfdata *match, void *aux) 175 { 176 177 return 1; 178 } 179 180 /* 181 * Attach the aubus. 182 */ 183 static void 184 aubus_attach(struct device *parent, struct device *self, void *aux) 185 { 186 struct aubus_attach_args aa; 187 struct device *sc = (struct device *)self; 188 const struct au1x00_dev *ad; 189 int locs[AUBUSCF_NLOCS]; 190 191 printf("\n"); 192 193 switch (MIPS_PRID_COPTS(cpu_id)) { 194 case MIPS_AU1000: 195 ad = au1000_devs; 196 break; 197 case MIPS_AU1500: 198 ad = au1500_devs; 199 break; 200 case MIPS_AU1100: 201 ad = au1100_devs; 202 break; 203 default: 204 panic("Unknown Alchemy SOC identification %d", 205 MIPS_PRID_COPTS(cpu_id)); 206 } 207 208 for (; ad->name != NULL; ad++) { 209 aa.aa_name = ad->name; 210 aa.aa_st = aubus_st; 211 aa.aa_dt = &aubus_mdt; 212 aubus_alloc_dma_tag(sc, aa.aa_dt); 213 aa.aa_addrs[0] = ad->addr[0]; 214 aa.aa_addrs[1] = ad->addr[1]; 215 aa.aa_addrs[2] = ad->addr[2]; 216 aa.aa_irq[0] = ad->irq[0]; 217 aa.aa_irq[1] = ad->irq[1]; 218 219 locs[AUBUSCF_ADDR] = ad->addr[0]; 220 221 (void) config_found_sm_loc(self, "aubus", locs, &aa, 222 aubus_print, config_stdsubmatch); 223 } 224 } 225 226 static int 227 aubus_print(void *aux, const char *pnp) 228 { 229 struct aubus_attach_args *aa = aux; 230 231 if (pnp) 232 aprint_normal("%s at %s", aa->aa_name, pnp); 233 234 if (aa->aa_addr != AUBUSCF_ADDR_DEFAULT) 235 aprint_normal(" addr 0x%lx", aa->aa_addr); 236 if (aa->aa_irq[0] >= 0) 237 aprint_normal(" irq %d", aa->aa_irq[0]); 238 if (aa->aa_irq[1] >= 0) 239 aprint_normal(",%d", aa->aa_irq[1]); 240 return (UNCONF); 241 } 242 243 void 244 aubus_alloc_dma_tag(sc, pdt) 245 struct device *sc; 246 bus_dma_tag_t pdt; 247 { 248 bus_dma_tag_t t; 249 250 t = pdt; 251 t->_cookie = sc; 252 t->_wbase = 0; /* XXX */ 253 t->_physbase = 0; /* XXX */ 254 t->_wsize = MIPS_KSEG1_START - MIPS_KSEG0_START; 255 t->_dmamap_create = _bus_dmamap_create; 256 t->_dmamap_destroy = _bus_dmamap_destroy; 257 t->_dmamap_load = _bus_dmamap_load; 258 t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf; 259 t->_dmamap_load_uio = _bus_dmamap_load_uio; 260 t->_dmamap_load_raw = _bus_dmamap_load_raw; 261 t->_dmamap_unload = _bus_dmamap_unload; 262 t->_dmamap_sync = _bus_dmamap_sync; 263 t->_dmamem_alloc = _bus_dmamem_alloc; 264 t->_dmamem_free = _bus_dmamem_free; 265 t->_dmamem_map = _bus_dmamem_map; 266 t->_dmamem_unmap = _bus_dmamem_unmap; 267 t->_dmamem_mmap = _bus_dmamem_mmap; 268 } 269