1 /* $NetBSD: aubus.c,v 1.5 2002/11/11 16:39:18 simonb 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 "locators.h" 69 70 #include <sys/param.h> 71 #include <sys/systm.h> 72 #include <sys/device.h> 73 #include <sys/extent.h> 74 #include <sys/malloc.h> 75 76 #include <machine/bus.h> 77 #include <machine/locore.h> 78 #include <mips/alchemy/include/aureg.h> 79 #include <mips/alchemy/include/aubusvar.h> 80 81 struct au1x00_dev { 82 const char *name; 83 bus_addr_t addr[3]; 84 int irq[2]; 85 }; 86 87 /* 88 * The devices built in to the Au1000 cpu. 89 */ 90 const struct au1x00_dev au1000_devs [] = { 91 { "aucom", { UART0_BASE }, { 0, -1 }}, 92 { "aucom", { UART1_BASE }, { 1, -1 }}, 93 { "aucom", { UART2_BASE }, { 2, -1 }}, 94 { "aucom", { UART3_BASE }, { 3, -1 }}, 95 { "aurtc", { }, { -1, -1 }}, 96 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 28, -1 }}, 97 { "aumac", { MAC1_BASE, MAC1_ENABLE, MAC1_DMA_BASE }, { 29, -1 }}, 98 { "auaudio", { AC97_BASE }, { 27, 31 }}, 99 { "ohci", { USBH_BASE }, { 26, -1 }}, 100 { "usbd", { USBD_BASE }, { 24, 25 }}, 101 { "irda", { IRDA_BASE }, { 22, 23 }}, 102 { "gpio", { SYS_BASE }, { -1, -1 }}, 103 { "i2s", { I2S_BASE }, { -1, -1 }}, 104 { "ssi", { SSI0_BASE }, { 4, -1 }}, 105 { "ssi", { SSI1_BASE }, { 5, -1 }}, 106 { NULL } 107 }; 108 109 /* 110 * The devices built in to the Au1500 cpu. 111 */ 112 const struct au1x00_dev au1500_devs [] = { 113 { "aucom", { UART0_BASE }, { 0, -1 }}, 114 { "aucom", { UART3_BASE }, { 3, -1 }}, 115 { "aurtc", { }, { -1, -1 }}, 116 { "aumac", { AU1500_MAC0_BASE, AU1500_MAC0_ENABLE, 117 MAC0_DMA_BASE }, { 28, -1 }}, 118 { "aumac", { AU1500_MAC1_BASE, AU1500_MAC1_ENABLE, 119 MAC1_DMA_BASE }, { 29, -1 }}, 120 { "auaudio", { AC97_BASE }, { 27, 31 }}, 121 { "ohci", { USBH_BASE }, { 26, -1 }}, 122 { "usbd", { USBD_BASE }, { 24, 25 }}, 123 { "gpio", { SYS_BASE }, { -1, -1 }}, 124 { "gpio2", { GPIO2_BASE }, { -1, -1 }}, 125 { "i2s", { I2S_BASE }, { -1, -1 }}, 126 { "aupci", { }, { -1, -1 }}, 127 { NULL } 128 }; 129 130 131 /* 132 * The devices built in to the Au1100 cpu. 133 */ 134 const struct au1x00_dev au1100_devs [] = { 135 { "aucom", { UART0_BASE }, { 0, -1 }}, 136 { "aucom", { UART1_BASE }, { 1, -1 }}, 137 { "aucom", { UART3_BASE }, { 3, -1 }}, 138 { "aurtc", { }, { -1, -1 }}, 139 { "aumac", { MAC0_BASE, MAC0_ENABLE, MAC0_DMA_BASE }, { 28, -1 }}, 140 { "auaudio", { AC97_BASE }, { 27, 31 }}, 141 { "ohci", { USBH_BASE }, { 26, -1 }}, 142 { "usbd", { USBD_BASE }, { 24, 25 }}, 143 { "irda", { IRDA_BASE }, { 22, 23 }}, 144 { "gpio", { SYS_BASE }, { -1, -1 }}, 145 { "gpio2", { GPIO2_BASE }, { 29, -1 }}, 146 { "i2s", { I2S_BASE }, { 30, -1 }}, 147 { "ssi", { SSI0_BASE }, { 4, -1 }}, 148 { "ssi", { SSI1_BASE }, { 5, -1 }}, 149 { "sd0", { SD0_BASE }, { 5, -1 }}, 150 { "sd1", { SD1_BASE }, { 5, -1 }}, 151 { NULL } 152 }; 153 154 155 static int aubus_match(struct device *, struct cfdata *, void *); 156 static void aubus_attach(struct device *, struct device *, void *); 157 static int aubus_submatch(struct device *, struct cfdata *, void *); 158 static int aubus_print(void *, const char *); 159 160 CFATTACH_DECL(aubus, sizeof(struct device), 161 aubus_match, aubus_attach, NULL, NULL); 162 163 bus_space_tag_t aubus_st; /* XXX */ 164 165 /* 166 * Probe for the aubus; always succeeds. 167 */ 168 static int 169 aubus_match(struct device *parent, struct cfdata *match, void *aux) 170 { 171 172 return 1; 173 } 174 175 static int 176 aubus_submatch(struct device *parent, struct cfdata *cf, void *aux) 177 { 178 struct aubus_attach_args *aa = aux; 179 180 if (cf->cf_loc[AUBUSCF_ADDR] != AUBUSCF_ADDR_DEFAULT && 181 cf->cf_loc[AUBUSCF_ADDR] != aa->aa_addr) 182 return (0); 183 184 return (config_match(parent, cf, aux)); 185 } 186 187 /* 188 * Attach the aubus. 189 */ 190 static void 191 aubus_attach(struct device *parent, struct device *self, void *aux) 192 { 193 struct aubus_attach_args aa; 194 const struct au1x00_dev *ad; 195 196 printf("\n"); 197 198 switch (MIPS_PRID_COPTS(cpu_id)) { 199 case MIPS_AU1000: 200 ad = au1000_devs; 201 break; 202 case MIPS_AU1500: 203 ad = au1500_devs; 204 break; 205 case MIPS_AU1100: 206 ad = au1100_devs; 207 break; 208 default: 209 panic("Unknown Alchemy SOC identification %d", 210 MIPS_PRID_COPTS(cpu_id)); 211 } 212 213 for (; ad->name != NULL; ad++) { 214 aa.aa_name = ad->name; 215 aa.aa_st = aubus_st; 216 aa.aa_addrs[0] = ad->addr[0]; 217 aa.aa_addrs[1] = ad->addr[1]; 218 aa.aa_addrs[2] = ad->addr[2]; 219 aa.aa_irq[0] = ad->irq[0]; 220 aa.aa_irq[1] = ad->irq[1]; 221 222 (void) config_found_sm(self, &aa, aubus_print, aubus_submatch); 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 printf("%s at %s", aa->aa_name, pnp); 233 234 if (aa->aa_addr != AUBUSCF_ADDR_DEFAULT) 235 printf(" %s 0x%lx", aubuscf_locnames[AUBUSCF_ADDR], 236 aa->aa_addr); 237 if (aa->aa_irq[0] >= 0) 238 printf(" irq %d", aa->aa_irq[0]); 239 if (aa->aa_irq[1] >= 0) 240 printf(",%d", aa->aa_irq[1]); 241 return (UNCONF); 242 } 243