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