Home | History | Annotate | Line # | Download | only in dev
sbobio.c revision 1.12
      1 /* $NetBSD: sbobio.c,v 1.12 2003/07/15 02:43:40 lukem 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.  The "Broadcom Corporation" name may not be
     19  *    used to endorse or promote products derived from this software
     20  *    without the prior written permission of Broadcom Corporation.
     21  *
     22  * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
     23  *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
     24  *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
     25  *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
     26  *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
     27  *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     30  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     31  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     32  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: sbobio.c,v 1.12 2003/07/15 02:43:40 lukem Exp $");
     37 
     38 #include <sys/param.h>
     39 #include <sys/device.h>
     40 #include <sys/systm.h>
     41 
     42 #include <machine/locore.h>
     43 #include <mips/sibyte/include/sb1250_regs.h>
     44 #include <mips/sibyte/include/sb1250_scd.h>
     45 #include <mips/sibyte/include/zbbusvar.h>
     46 #include <mips/sibyte/dev/sbobiovar.h>
     47 
     48 #include "locators.h"
     49 
     50 static int	sbobio_match(struct device *, struct cfdata *, void *);
     51 static void	sbobio_attach(struct device *, struct device *, void *);
     52 
     53 CFATTACH_DECL(sbobio, sizeof(struct device),
     54     sbobio_match, sbobio_attach, NULL, NULL);
     55 
     56 static int	sbobio_print(void *, const char *);
     57 static int	sbobio_submatch(struct device *, struct cfdata *, void *);
     58 static const char *sbobio_device_type_name(enum sbobio_device_type type);
     59 
     60 static const struct sbobio_attach_locs sb1250_rev1_sbobio_devs[] = {
     61 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     62 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     63 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     64 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     65 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     66 #if 0
     67 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
     68 #endif
     69 	{ 0x4000, {19,-1},	SBOBIO_DEVTYPE_MAC,		},
     70 	{ 0x5000, {20,-1},	SBOBIO_DEVTYPE_MAC,		},
     71 	{ 0x6000, {21,-1},	SBOBIO_DEVTYPE_MAC,		},
     72 };
     73 static const int sb1250_rev1_sbobio_dev_count =
     74     sizeof sb1250_rev1_sbobio_devs / sizeof sb1250_rev1_sbobio_devs[0];
     75 
     76 static const struct sbobio_attach_locs sb1250_sbobio_devs[] = {
     77 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     78 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     79 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     80 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     81 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     82 #if 0
     83 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
     84 #endif
     85 	{ 0x4000, {19,61},	SBOBIO_DEVTYPE_MAC,		},
     86 	{ 0x5000, {20,62},	SBOBIO_DEVTYPE_MAC,		},
     87 	{ 0x6000, {21,63},	SBOBIO_DEVTYPE_MAC,		},
     88 };
     89 static const int sb1250_sbobio_dev_count =
     90     sizeof sb1250_sbobio_devs / sizeof sb1250_sbobio_devs[0];
     91 
     92 static const struct sbobio_attach_locs sb112x_sbobio_devs[] = {
     93 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     94 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     95 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     96 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     97 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     98 #if 0
     99 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
    100 #endif
    101 	{ 0x4000, {19,61},	SBOBIO_DEVTYPE_MAC,		},
    102 	{ 0x5000, {20,62},	SBOBIO_DEVTYPE_MAC,		},
    103 };
    104 static const int sb112x_sbobio_dev_count =
    105     sizeof sb112x_sbobio_devs / sizeof sb112x_sbobio_devs[0];
    106 
    107 static int
    108 sbobio_match(struct device *parent, struct cfdata *match, void *aux)
    109 {
    110 	struct zbbus_attach_args *zap = aux;
    111 	uint64_t sysrev;
    112 
    113 	if (zap->za_locs.za_type != ZBBUS_ENTTYPE_OBIO)
    114 		return (0);
    115 
    116 	sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
    117 	switch (SYS_SOC_TYPE(sysrev)) {
    118 	case K_SYS_SOC_TYPE_BCM1120:
    119 	case K_SYS_SOC_TYPE_BCM1125:
    120 	case K_SYS_SOC_TYPE_BCM1125H:
    121 	case K_SYS_SOC_TYPE_BCM1250:
    122 		break;
    123 
    124 	default:
    125 		return (0);
    126 	}
    127 
    128 	return (1);
    129 }
    130 
    131 static void
    132 sbobio_attach(struct device *parent, struct device *self, void *aux)
    133 {
    134 	struct sbobio_attach_args sa;
    135 	const char *dscr;
    136 	const struct sbobio_attach_locs *devs;
    137 	uint64_t sysrev;
    138 	int i, devcount;
    139 
    140 	sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
    141 	switch (SYS_SOC_TYPE(sysrev)) {
    142 	case K_SYS_SOC_TYPE_BCM1120:
    143 	case K_SYS_SOC_TYPE_BCM1125:
    144 	case K_SYS_SOC_TYPE_BCM1125H:
    145 		dscr = "BCM112x";
    146 		devs = sb112x_sbobio_devs;
    147 		devcount = sb112x_sbobio_dev_count;
    148 		break;
    149 
    150 	case K_SYS_SOC_TYPE_BCM1250:
    151 		if (G_SYS_REVISION(sysrev) >= K_SYS_REVISION_BCM1250_PASS2) {
    152 			dscr = "BCM1250 (rev2 and later)";
    153 			devs = sb1250_sbobio_devs;
    154 			devcount = sb1250_sbobio_dev_count;
    155 		} else {
    156 			dscr = "BCM1250 rev1";
    157 			devs = sb1250_rev1_sbobio_devs;
    158 			devcount = sb1250_rev1_sbobio_dev_count;
    159 		}
    160 		break;
    161 #ifdef DIAGNOSTIC
    162 	default:
    163 		panic("un-matched in sbobio_attach");
    164 		break;
    165 #endif
    166 	}
    167 
    168 	printf(": %s peripherals\n", dscr);
    169 
    170 	for (i = 0; i < devcount; i++) {
    171 		memset(&sa, 0, sizeof sa);
    172 		sa.sa_base = A_PHYS_IO_SYSTEM;
    173 		sa.sa_locs = devs[i];
    174 		config_found_sm(self, &sa, sbobio_print, sbobio_submatch);
    175 	}
    176 	return;
    177 }
    178 
    179 int
    180 sbobio_print(void *aux, const char *pnp)
    181 {
    182 	struct sbobio_attach_args *sap = aux;
    183 	int i;
    184 
    185 	if (pnp)
    186 		aprint_normal("%s at %s",
    187 		    sbobio_device_type_name(sap->sa_locs.sa_type), pnp);
    188 	aprint_normal(" offset 0x%lx", (long)sap->sa_locs.sa_offset);
    189 	for (i = 0; i < 2; i++) {
    190 		if (sap->sa_locs.sa_intr[i] != SBOBIOCF_INTR_DEFAULT)
    191 			aprint_normal("%s%ld", i == 0 ? " intr " : ",",
    192 			    (long)sap->sa_locs.sa_intr[i]);
    193 	}
    194 	return (UNCONF);
    195 }
    196 
    197 static int
    198 sbobio_submatch(struct device *parent, struct cfdata *cf, void *aux)
    199 {
    200 	struct sbobio_attach_args *sap = aux;
    201 	int i;
    202 
    203 	if (cf->cf_loc[SBOBIOCF_OFFSET] != SBOBIOCF_OFFSET_DEFAULT &&
    204 	    cf->cf_loc[SBOBIOCF_OFFSET] != sap->sa_locs.sa_offset)
    205 		return (0);
    206 
    207 	for (i = 0; i < 2; i++) {
    208 		if (cf->cf_loc[SBOBIOCF_INTR + i] != SBOBIOCF_INTR_DEFAULT &&
    209 		    cf->cf_loc[SBOBIOCF_INTR + i] != sap->sa_locs.sa_intr[i])
    210 			return (0);
    211 	}
    212 
    213 	return (config_match(parent, cf, aux));
    214 }
    215 
    216 static const char *
    217 sbobio_device_type_name(enum sbobio_device_type type)
    218 {
    219 
    220 	switch (type) {
    221 	case SBOBIO_DEVTYPE_SMBUS:
    222 		return ("sbsmbus");
    223 	case SBOBIO_DEVTYPE_DUART:
    224 		return ("sbscn");
    225 	case SBOBIO_DEVTYPE_SYNCSERIAL:
    226 		return ("sbsync");
    227 	case SBOBIO_DEVTYPE_GBUS:
    228 		return ("sbgbus");
    229 	case SBOBIO_DEVTYPE_MAC:
    230 		return ("sbmac");
    231 	}
    232 	panic("sbobio_device_type_name");
    233 	return ("panic");
    234 }
    235