1 /* $NetBSD: aubus.c,v 1.17 2005/12/20 21:06:42 tron 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.17 2005/12/20 21:06:42 tron 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, USBH_ENABLE, USBH_SIZE }, { 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, USBH_ENABLE, USBH_SIZE }, { 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 Au1550 CPU. 137 */ 138 const struct au1x00_dev au1550_devs [] = { 139 { "aucom", { UART0_BASE }, { 0, -1 }}, 140 { "aucom", { UART1_BASE }, { 8, -1 }}, 141 { "aucom", { UART3_BASE }, { 9, -1 }}, 142 { "aurtc", { }, { -1, -1 }}, 143 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 27, -1 }}, 144 { "aumac", { MAC1_BASE, MAC1_ENABLE, MAC1_DMA_BASE }, { 28, -1 }}, 145 { "auaudio", { AC97_BASE }, { 27, 31 }}, 146 { "ohci", { AU1550_USBH_BASE, AU1550_USBH_ENABLE, 147 AU1550_USBH_SIZE }, { 26, -1 }}, 148 { "usbd", { USBD_BASE }, { 24, 25 }}, 149 { "gpio", { SYS_BASE }, { -1, -1 }}, 150 { "gpio2", { GPIO2_BASE }, { -1, -1 }}, 151 { "aupci", { }, { -1, -1 }}, 152 { NULL } 153 }; 154 155 /* 156 * The devices built in to the Au1100 CPU. 157 */ 158 const struct au1x00_dev au1100_devs [] = { 159 { "aucom", { UART0_BASE }, { 0, -1 }}, 160 { "aucom", { UART1_BASE }, { 1, -1 }}, 161 { "aucom", { UART3_BASE }, { 3, -1 }}, 162 { "aurtc", { }, { -1, -1 }}, 163 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 28, -1 }}, 164 { "auaudio", { AC97_BASE }, { 27, 31 }}, 165 { "ohci", { USBH_BASE, USBH_ENABLE, USBH_SIZE }, { 26, -1 }}, 166 { "usbd", { USBD_BASE }, { 24, 25 }}, 167 { "irda", { IRDA_BASE }, { 22, 23 }}, 168 { "gpio", { SYS_BASE }, { -1, -1 }}, 169 { "gpio2", { GPIO2_BASE }, { 29, -1 }}, 170 { "i2s", { I2S_BASE }, { 30, -1 }}, 171 { "ssi", { SSI0_BASE }, { 4, -1 }}, 172 { "ssi", { SSI1_BASE }, { 5, -1 }}, 173 { "sd0", { SD0_BASE }, { 5, -1 }}, 174 { "sd1", { SD1_BASE }, { 5, -1 }}, 175 { NULL } 176 }; 177 178 179 static int aubus_match(struct device *, struct cfdata *, void *); 180 static void aubus_attach(struct device *, struct device *, void *); 181 static int aubus_print(void *, const char *); 182 static void aubus_alloc_dma_tag(struct device *, bus_dma_tag_t); 183 184 CFATTACH_DECL(aubus, sizeof(struct device), 185 aubus_match, aubus_attach, NULL, NULL); 186 187 bus_space_tag_t aubus_st; /* XXX */ 188 struct mips_bus_dma_tag aubus_mdt; 189 190 /* 191 * Probe for the aubus; always succeeds. 192 */ 193 static int 194 aubus_match(struct device *parent, struct cfdata *match, void *aux) 195 { 196 197 return 1; 198 } 199 200 /* 201 * Attach the aubus. 202 */ 203 static void 204 aubus_attach(struct device *parent, struct device *self, void *aux) 205 { 206 struct aubus_attach_args aa; 207 struct device *sc = (struct device *)self; 208 const struct au1x00_dev *ad; 209 int locs[AUBUSCF_NLOCS]; 210 211 printf("\n"); 212 213 switch (MIPS_PRID_COPTS(cpu_id)) { 214 case MIPS_AU1000: 215 ad = au1000_devs; 216 break; 217 case MIPS_AU1500: 218 ad = au1500_devs; 219 break; 220 case MIPS_AU1100: 221 ad = au1100_devs; 222 break; 223 case MIPS_AU1550: 224 ad = au1550_devs; 225 break; 226 default: 227 panic("Unknown Alchemy SOC identification %d", 228 MIPS_PRID_COPTS(cpu_id)); 229 } 230 231 for (; ad->name != NULL; ad++) { 232 aa.aa_name = ad->name; 233 aa.aa_st = aubus_st; 234 aa.aa_dt = &aubus_mdt; 235 aubus_alloc_dma_tag(sc, aa.aa_dt); 236 aa.aa_addrs[0] = ad->addr[0]; 237 aa.aa_addrs[1] = ad->addr[1]; 238 aa.aa_addrs[2] = ad->addr[2]; 239 aa.aa_irq[0] = ad->irq[0]; 240 aa.aa_irq[1] = ad->irq[1]; 241 242 locs[AUBUSCF_ADDR] = ad->addr[0]; 243 244 (void) config_found_sm_loc(self, "aubus", locs, &aa, 245 aubus_print, config_stdsubmatch); 246 } 247 } 248 249 static int 250 aubus_print(void *aux, const char *pnp) 251 { 252 struct aubus_attach_args *aa = aux; 253 254 if (pnp) 255 aprint_normal("%s at %s", aa->aa_name, pnp); 256 257 if (aa->aa_addr != AUBUSCF_ADDR_DEFAULT) 258 aprint_normal(" addr 0x%lx", aa->aa_addr); 259 if (aa->aa_irq[0] >= 0) 260 aprint_normal(" irq %d", aa->aa_irq[0]); 261 if (aa->aa_irq[1] >= 0) 262 aprint_normal(",%d", aa->aa_irq[1]); 263 return (UNCONF); 264 } 265 266 void 267 aubus_alloc_dma_tag(sc, pdt) 268 struct device *sc; 269 bus_dma_tag_t pdt; 270 { 271 bus_dma_tag_t t; 272 273 t = pdt; 274 t->_cookie = sc; 275 t->_wbase = 0; /* XXX */ 276 t->_physbase = 0; /* XXX */ 277 t->_wsize = MIPS_KSEG1_START - MIPS_KSEG0_START; 278 t->_dmamap_create = _bus_dmamap_create; 279 t->_dmamap_destroy = _bus_dmamap_destroy; 280 t->_dmamap_load = _bus_dmamap_load; 281 t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf; 282 t->_dmamap_load_uio = _bus_dmamap_load_uio; 283 t->_dmamap_load_raw = _bus_dmamap_load_raw; 284 t->_dmamap_unload = _bus_dmamap_unload; 285 t->_dmamap_sync = _bus_dmamap_sync; 286 t->_dmamem_alloc = _bus_dmamem_alloc; 287 t->_dmamem_free = _bus_dmamem_free; 288 t->_dmamem_map = _bus_dmamem_map; 289 t->_dmamem_unmap = _bus_dmamem_unmap; 290 t->_dmamem_mmap = _bus_dmamem_mmap; 291 } 292