Home | History | Annotate | Line # | Download | only in dev
sbobio.c revision 1.9
      1 /* $NetBSD: sbobio.c,v 1.9 2003/02/07 17:38:49 cgd 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/param.h>
     36 #include <sys/device.h>
     37 #include <sys/systm.h>
     38 
     39 #include <machine/locore.h>
     40 #include <mips/sibyte/include/sb1250_regs.h>
     41 #include <mips/sibyte/include/sb1250_scd.h>
     42 #include <mips/sibyte/include/zbbusvar.h>
     43 #include <mips/sibyte/dev/sbobiovar.h>
     44 
     45 #include "locators.h"
     46 
     47 static int	sbobio_match(struct device *, struct cfdata *, void *);
     48 static void	sbobio_attach(struct device *, struct device *, void *);
     49 
     50 CFATTACH_DECL(sbobio, sizeof(struct device),
     51     sbobio_match, sbobio_attach, NULL, NULL);
     52 
     53 static int	sbobio_print(void *, const char *);
     54 static int	sbobio_submatch(struct device *, struct cfdata *, void *);
     55 static const char *sbobio_device_type_name(enum sbobio_device_type type);
     56 
     57 static const struct sbobio_attach_locs sb1250_rev1_sbobio_devs[] = {
     58 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     59 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     60 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     61 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     62 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     63 #if 0
     64 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
     65 #endif
     66 	{ 0x4000, {19,-1},	SBOBIO_DEVTYPE_MAC,		},
     67 	{ 0x5000, {20,-1},	SBOBIO_DEVTYPE_MAC,		},
     68 	{ 0x6000, {21,-1},	SBOBIO_DEVTYPE_MAC,		},
     69 };
     70 static const int sb1250_rev1_sbobio_dev_count =
     71     sizeof sb1250_rev1_sbobio_devs / sizeof sb1250_rev1_sbobio_devs[0];
     72 
     73 static const struct sbobio_attach_locs sb1250_sbobio_devs[] = {
     74 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     75 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     76 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     77 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     78 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     79 #if 0
     80 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
     81 #endif
     82 	{ 0x4000, {19,61},	SBOBIO_DEVTYPE_MAC,		},
     83 	{ 0x5000, {20,62},	SBOBIO_DEVTYPE_MAC,		},
     84 	{ 0x6000, {21,63},	SBOBIO_DEVTYPE_MAC,		},
     85 };
     86 static const int sb1250_sbobio_dev_count =
     87     sizeof sb1250_sbobio_devs / sizeof sb1250_sbobio_devs[0];
     88 
     89 static const struct sbobio_attach_locs sb112x_sbobio_devs[] = {
     90 	{ 0x0000, {6,-1},	SBOBIO_DEVTYPE_SMBUS		},
     91 	{ 0x0008, {7,-1},	SBOBIO_DEVTYPE_SMBUS		},
     92 	{ 0x0100, {8,9},	SBOBIO_DEVTYPE_DUART		},
     93 	{ 0x0400, {10,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     94 	{ 0x0800, {11,-1},	SBOBIO_DEVTYPE_SYNCSERIAL	},
     95 #if 0
     96 	{ 0x1000, {-1,-1},	SBOBIO_DEVTYPE_GBUS,		}, /* XXXCGD ??? */
     97 #endif
     98 	{ 0x4000, {19,61},	SBOBIO_DEVTYPE_MAC,		},
     99 	{ 0x5000, {20,62},	SBOBIO_DEVTYPE_MAC,		},
    100 };
    101 static const int sb112x_sbobio_dev_count =
    102     sizeof sb112x_sbobio_devs / sizeof sb112x_sbobio_devs[0];
    103 
    104 static int
    105 sbobio_match(struct device *parent, struct cfdata *match, void *aux)
    106 {
    107 	struct zbbus_attach_args *zap = aux;
    108 	uint64_t sysrev;
    109 
    110 	if (zap->za_locs.za_type != ZBBUS_ENTTYPE_OBIO)
    111 		return (0);
    112 
    113 	sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
    114 	switch (SYS_SOC_TYPE(sysrev)) {
    115 	case K_SYS_SOC_TYPE_BCM1120:
    116 	case K_SYS_SOC_TYPE_BCM1125:
    117 	case K_SYS_SOC_TYPE_BCM1125H:
    118 	case K_SYS_SOC_TYPE_BCM1250:
    119 		break;
    120 
    121 	default:
    122 		return 0;
    123 	}
    124 
    125 	return 1;
    126 }
    127 
    128 static void
    129 sbobio_attach(struct device *parent, struct device *self, void *aux)
    130 {
    131 	struct sbobio_attach_args sa;
    132 	const char *dscr;
    133 	const struct sbobio_attach_locs *devs;
    134 	uint64_t sysrev;
    135 	int i, devcount;
    136 
    137 	sysrev = mips3_ld((u_int64_t *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_REVISION));
    138 	switch (SYS_SOC_TYPE(sysrev)) {
    139 	case K_SYS_SOC_TYPE_BCM1120:
    140 	case K_SYS_SOC_TYPE_BCM1125:
    141 	case K_SYS_SOC_TYPE_BCM1125H:
    142 		dscr = "BCM112x";
    143 		devs = sb112x_sbobio_devs;
    144 		devcount = sb112x_sbobio_dev_count;
    145 		break;
    146 
    147 	case K_SYS_SOC_TYPE_BCM1250:
    148 		if (G_SYS_REVISION(sysrev) >= K_SYS_REVISION_BCM1250_PASS2) {
    149 			dscr = "BCM1250 (rev2 and later)";
    150 			devs = sb1250_sbobio_devs;
    151 			devcount = sb1250_sbobio_dev_count;
    152 		} else {
    153 			dscr = "BCM1250 rev1";
    154 			devs = sb1250_rev1_sbobio_devs;
    155 			devcount = sb1250_rev1_sbobio_dev_count;
    156 		}
    157 		break;
    158 #ifdef DIAGNOSTIC
    159 	default:
    160 		panic("un-matched in sbobio_attach");
    161 		break;
    162 #endif
    163 	}
    164 
    165 	printf(": %s peripherals\n", dscr);
    166 
    167 	for (i = 0; i < devcount; i++) {
    168 		memset(&sa, 0, sizeof sa);
    169 		sa.sa_base = A_PHYS_IO_SYSTEM;
    170 		sa.sa_locs = devs[i];
    171 		config_found_sm(self, &sa, sbobio_print, sbobio_submatch);
    172 	}
    173 	return;
    174 }
    175 
    176 int
    177 sbobio_print(void *aux, const char *pnp)
    178 {
    179 	struct sbobio_attach_args *sap = aux;
    180 	int i;
    181 
    182 	if (pnp)
    183 		aprint_normal("%s at %s",
    184 		    sbobio_device_type_name(sap->sa_locs.sa_type), pnp);
    185 	aprint_normal(" offset 0x%lx", (long)sap->sa_locs.sa_offset);
    186 	for (i = 0; i < 2; i++) {
    187 		if (sap->sa_locs.sa_intr[i] != SBOBIOCF_INTR_DEFAULT)
    188 			aprint_normal("%s%ld", i == 0 ? " intr " : ",",
    189 			    (long)sap->sa_locs.sa_intr[i]);
    190 	}
    191 	return (UNCONF);
    192 }
    193 
    194 static int
    195 sbobio_submatch(struct device *parent, struct cfdata *cf, void *aux)
    196 {
    197 	struct sbobio_attach_args *sap = aux;
    198 	int i;
    199 
    200 	if (cf->cf_loc[SBOBIOCF_OFFSET] != SBOBIOCF_OFFSET_DEFAULT &&
    201 	    cf->cf_loc[SBOBIOCF_OFFSET] != sap->sa_locs.sa_offset)
    202 		return (0);
    203 
    204 	for (i = 0; i < 2; i++) {
    205 		if (cf->cf_loc[SBOBIOCF_INTR + i] != SBOBIOCF_INTR_DEFAULT &&
    206 		    cf->cf_loc[SBOBIOCF_INTR + i] != sap->sa_locs.sa_intr[i])
    207 			return (0);
    208 	}
    209 
    210 	return (config_match(parent, cf, aux));
    211 }
    212 
    213 static const char *
    214 sbobio_device_type_name(enum sbobio_device_type type)
    215 {
    216 
    217 	switch (type) {
    218 	case SBOBIO_DEVTYPE_SMBUS:
    219 		return ("sbsmbus");
    220 	case SBOBIO_DEVTYPE_DUART:
    221 		return ("sbscn");
    222 	case SBOBIO_DEVTYPE_SYNCSERIAL:
    223 		return ("sbsync");
    224 	case SBOBIO_DEVTYPE_GBUS:
    225 		return ("sbgbus");
    226 	case SBOBIO_DEVTYPE_MAC:
    227 		return ("sbmac");
    228 	}
    229 	panic("sbobio_device_type_name");
    230 	return ("panic");
    231 }
    232