1 /* $NetBSD: sbobio.c,v 1.1 2002/03/05 23:46:42 simonb Exp $ */ 2 3 /* 4 * Copyright 2000, 2001 5 * Broadcom Corporation. All rights reserved. 6 * 7 * This software is furnished under license and may be used and copied only 8 * in accordance with the following terms and conditions. Subject to these 9 * conditions, you may download, copy, install, use, modify and distribute 10 * modified or unmodified copies of this software in source and/or binary 11 * form. No title or ownership is transferred hereby. 12 * 13 * 1) Any source code used, modified or distributed must reproduce and 14 * retain this copyright notice and list of conditions as they appear in 15 * the source file. 16 * 17 * 2) No right is granted to use any trade name, trademark, or logo of 18 * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any 19 * trademark or logo of Broadcom Corporation may be used to endorse or 20 * promote products derived from this software without the prior written 21 * permission of Broadcom Corporation. 22 * 23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #include <sys/param.h> 37 #include <sys/device.h> 38 #include <sys/systm.h> 39 40 #include <mips/sibyte/include/zbbusvar.h> 41 #include <mips/sibyte/dev/sbobiovar.h> 42 43 #include "locators.h" 44 45 static int sbobio_match(struct device *, struct cfdata *, void *); 46 static void sbobio_attach(struct device *, struct device *, void *); 47 48 struct cfattach sbobio_ca = { 49 sizeof(struct device), sbobio_match, sbobio_attach 50 }; 51 52 static int sbobio_print(void *, const char *); 53 static int sbobio_submatch(struct device *, struct cfdata *, void *); 54 static const char *sbobio_device_type_name(enum sbobio_device_type type); 55 56 static const struct sbobio_attach_locs sb1250_sbobio_devs[] = { 57 { 0x0000, {6,7}, SBOBIO_DEVTYPE_SMBUS }, 58 { 0x0100, {8,9}, SBOBIO_DEVTYPE_DUART }, 59 { 0x0400, {10,-1}, SBOBIO_DEVTYPE_SYNCSERIAL }, 60 { 0x0800, {11,-1}, SBOBIO_DEVTYPE_SYNCSERIAL }, 61 #if 0 62 { 0x1000, {-1,-1}, SBOBIO_DEVTYPE_GBUS, }, /* XXXCGD ??? */ 63 #endif 64 { 0x4000, {19,-1}, SBOBIO_DEVTYPE_MAC, }, 65 { 0x5000, {20,-1}, SBOBIO_DEVTYPE_MAC, }, 66 { 0x6000, {21,-1}, SBOBIO_DEVTYPE_MAC, }, 67 }; 68 static const int sb1250_sbobio_dev_count = 69 sizeof sb1250_sbobio_devs / sizeof sb1250_sbobio_devs[0]; 70 71 static int 72 sbobio_match(struct device *parent, struct cfdata *match, void *aux) 73 { 74 struct zbbus_attach_args *zap = aux; 75 76 if (zap->za_locs.za_type != ZBBUS_ENTTYPE_OBIO) 77 return (0); 78 79 return 1; 80 } 81 82 static void 83 sbobio_attach(struct device *parent, struct device *self, void *aux) 84 { 85 struct sbobio_attach_args sa; 86 int i; 87 88 printf("\n"); 89 90 for (i = 0; i < sb1250_sbobio_dev_count; i++) { 91 memset(&sa, 0, sizeof sa); 92 sa.sa_base = 0x10060000; /* XXXCGD */ 93 sa.sa_locs = sb1250_sbobio_devs[i]; 94 config_found_sm(self, &sa, sbobio_print, sbobio_submatch); 95 } 96 return; 97 } 98 99 int 100 sbobio_print(void *aux, const char *pnp) 101 { 102 struct sbobio_attach_args *sap = aux; 103 int i; 104 105 if (pnp) 106 printf("%s at %s", 107 sbobio_device_type_name(sap->sa_locs.sa_type), pnp); 108 printf(" offset 0x%lx", (long)sap->sa_locs.sa_offset); 109 for (i = 0; i < 2; i++) { 110 if (sap->sa_locs.sa_intr[i] != -1) 111 printf("%s%ld", i == 0 ? " intr " : ",", 112 (long)sap->sa_locs.sa_intr[i]); 113 } 114 return (UNCONF); 115 } 116 117 static int 118 sbobio_submatch(struct device *parent, struct cfdata *cf, void *aux) 119 { 120 struct sbobio_attach_args *sap = aux; 121 int i; 122 123 if (cf->cf_loc[SBOBIOCF_OFFSET] != SBOBIOCF_OFFSET_DEFAULT && 124 cf->cf_loc[SBOBIOCF_OFFSET] != sap->sa_locs.sa_offset) 125 return (0); 126 127 for (i = 0; i < 2; i++) { 128 if (cf->cf_loc[SBOBIOCF_INTR + i] != SBOBIOCF_INTR_DEFAULT && 129 cf->cf_loc[SBOBIOCF_INTR + i] != sap->sa_locs.sa_intr[i]) 130 return (0); 131 } 132 133 return ((*cf->cf_attach->ca_match)(parent, cf, aux)); 134 } 135 136 static const char * 137 sbobio_device_type_name(enum sbobio_device_type type) 138 { 139 140 switch (type) { 141 case SBOBIO_DEVTYPE_SMBUS: 142 return ("sbsmbus"); 143 case SBOBIO_DEVTYPE_DUART: 144 return ("sbscn"); 145 case SBOBIO_DEVTYPE_SYNCSERIAL: 146 return ("sbsync"); 147 case SBOBIO_DEVTYPE_GBUS: 148 return ("sbgbus"); 149 case SBOBIO_DEVTYPE_MAC: 150 return ("sbmac"); 151 } 152 panic("sbobio_device_type_name"); 153 return ("panic"); 154 } 155