isa_machdep.c revision 1.15
11.15Senami/*	$NetBSD: isa_machdep.c,v 1.15 2001/06/11 05:22:10 enami Exp $	*/
21.1Stakemura
31.1Stakemura/*
41.1Stakemura * Copyright (c) 1999, by UCHIYAMA Yasushi
51.1Stakemura * All rights reserved.
61.1Stakemura *
71.1Stakemura * Redistribution and use in source and binary forms, with or without
81.1Stakemura * modification, are permitted provided that the following conditions
91.1Stakemura * are met:
101.1Stakemura * 1. Redistributions of source code must retain the above copyright
111.1Stakemura *    notice, this list of conditions and the following disclaimer.
121.1Stakemura * 2. The name of the developer may NOT be used to endorse or promote products
131.1Stakemura *    derived from this software without specific prior written permission.
141.1Stakemura *
151.1Stakemura * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161.1Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171.1Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181.1Stakemura * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211.1Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Stakemura * SUCH DAMAGE.
261.1Stakemura *
271.1Stakemura */
281.1Stakemura#include <sys/param.h>
291.1Stakemura#include <sys/systm.h>
301.1Stakemura#include <sys/device.h>
311.10Ssato#include <sys/reboot.h>
321.1Stakemura
331.1Stakemura#include <machine/bus.h>
341.1Stakemura
351.1Stakemura#include <dev/isa/isavar.h>
361.1Stakemura#include <dev/isa/isareg.h>
371.1Stakemura
381.1Stakemura#include <machine/platid.h>
391.1Stakemura#include <machine/platid_mask.h>
401.1Stakemura
411.13Stakemura#include <dev/hpc/hpciovar.h>
421.13Stakemura
431.5Ssato#include <hpcmips/hpcmips/machdep.h>
441.12Ssato#include "opt_vr41xx.h"
451.12Ssato#include <hpcmips/vr/vrcpudef.h>
461.1Stakemura#include <hpcmips/vr/vripreg.h>
471.1Stakemura#include <hpcmips/vr/vripvar.h>
481.1Stakemura
491.1Stakemura#include "locators.h"
501.1Stakemura
511.4Ssato#define VRISADEBUG
521.4Ssato
531.4Ssato#ifdef VRISADEBUG
541.4Ssato#ifndef VRISADEBUG_CONF
551.4Ssato#define VRISADEBUG_CONF 0
561.4Ssato#endif /* VRISADEBUG_CONF */
571.4Ssatoint vrisa_debug = VRISADEBUG_CONF;
581.4Ssato#define DPRINTF(arg) if (vrisa_debug) printf arg;
591.4Ssato#define DBITDISP32(mask) if (vrisa_debug) bitdisp32(mask);
601.8Sjdolecek#define VPRINTF(arg) if (bootverbose || vrisa_debug) printf arg;
611.4Ssato#else /* VRISADEBUG */
621.4Ssato#define DPRINTF(arg)
631.4Ssato#define DBITDISP32(mask)
641.8Sjdolecek#define VPRINTF(arg) if (bootverbose) printf arg;
651.4Ssato#endif /* VRISADEBUG */
661.4Ssato
671.13Stakemura/*
681.13Stakemura * intrrupt no. encoding:
691.13Stakemura *
701.13Stakemura * 0x0000000f ISA IRQ#
711.13Stakemura * 0x00ff0000 GPIO port#
721.13Stakemura * 0x01000000 interrupt signal hold/through	(1:hold/0:though)
731.13Stakemura * 0x02000000 interrupt detection level		(1:low /0:high	)
741.13Stakemura * 0x04000000 interrupt detection trigger	(1:edge/0:level	)
751.13Stakemura */
761.13Stakemura#define INTR_IRQ(i)	(((i)>> 0) & 0x0f)
771.13Stakemura#define INTR_PORT(i)	(((i)>>16) & 0xff)
781.13Stakemura#define INTR_MODE(i)	(((i)>>24) & 0x07)
791.13Stakemura#define INTR_NIRQS	16
801.13Stakemura
811.1Stakemuraint	vrisabprint __P((void*, const char*));
821.1Stakemuraint	vrisabmatch __P((struct device*, struct cfdata*, void*));
831.1Stakemuravoid	vrisabattach __P((struct device*, struct device*, void*));
841.1Stakemura
851.1Stakemurastruct vrisab_softc {
861.1Stakemura	struct device sc_dev;
871.13Stakemura	hpcio_chip_t sc_hc;
881.13Stakemura	int sc_intr_map[INTR_NIRQS]; /* ISA <-> GIU inerrupt line mapping */
891.3Stakemura	struct hpcmips_isa_chipset sc_isa_ic;
901.1Stakemura};
911.1Stakemura
921.1Stakemurastruct cfattach vrisab_ca = {
931.1Stakemura	sizeof(struct vrisab_softc), vrisabmatch, vrisabattach
941.1Stakemura};
951.1Stakemura
961.1Stakemura#ifdef DEBUG_FIND_PCIC
971.1Stakemura#include <mips/cpuregs.h>
981.1Stakemura#warning DEBUG_FIND_PCIC
991.1Stakemurastatic void __find_pcic __P((void));
1001.1Stakemura#endif
1011.1Stakemura
1021.11Ssato#ifdef DEBUG_FIND_COMPORT
1031.11Ssato#include <mips/cpuregs.h>
1041.11Ssato#include <dev/ic/ns16550reg.h>
1051.11Ssato#include <dev/ic/comreg.h>
1061.11Ssato#warning DEBUG_FIND_COMPORT
1071.11Ssatostatic void __find_comport __P((void));
1081.11Ssato#endif
1091.11Ssato
1101.11Ssato
1111.1Stakemuraint
1121.1Stakemuravrisabmatch(parent, match, aux)
1131.1Stakemura	struct device *parent;
1141.1Stakemura	struct cfdata *match;
1151.1Stakemura	void *aux;
1161.1Stakemura{
1171.13Stakemura	struct hpcio_attach_args *haa = aux;
1181.1Stakemura	platid_mask_t mask;
1191.1Stakemura
1201.13Stakemura	if (strcmp(haa->haa_busname, match->cf_driver->cd_name))
1211.1Stakemura		return 0;
1221.13Stakemura	if (match->cf_loc[HPCIOIFCF_PLATFORM] == HPCIOIFCF_PLATFORM_DEFAULT)
1231.1Stakemura		return 1;
1241.13Stakemura	mask = PLATID_DEREF(match->cf_loc[HPCIOIFCF_PLATFORM]);
1251.1Stakemura	if (platid_match(&platid, &mask))
1261.1Stakemura		return 2;
1271.1Stakemura	return 0;
1281.1Stakemura}
1291.1Stakemura
1301.1Stakemuravoid
1311.1Stakemuravrisabattach(parent, self, aux)
1321.1Stakemura	struct device *parent;
1331.1Stakemura	struct device *self;
1341.1Stakemura	void *aux;
1351.1Stakemura{
1361.13Stakemura	struct hpcio_attach_args *haa = aux;
1371.1Stakemura	struct vrisab_softc *sc = (void*)self;
1381.1Stakemura	struct isabus_attach_args iba;
1391.1Stakemura	bus_addr_t offset;
1401.1Stakemura	int i;
1411.1Stakemura
1421.13Stakemura	sc->sc_hc = (*haa->haa_getchip)(haa->haa_sc, VRIP_IOCHIP_VRGIU);
1431.3Stakemura	sc->sc_isa_ic.ic_sc = sc;
1441.1Stakemura
1451.1Stakemura	iba.iba_busname = "isa";
1461.3Stakemura	iba.iba_ic	= &sc->sc_isa_ic;
1471.1Stakemura	iba.iba_dmat    = 0; /* XXX not yet */
1481.1Stakemura
1491.1Stakemura	/* Allocate ISA memory space */
1501.1Stakemura	iba.iba_memt    = hpcmips_alloc_bus_space_tag();
1511.1Stakemura	strcpy(iba.iba_memt->t_name, "ISA mem");
1521.1Stakemura	offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAMEMOFFSET];
1531.1Stakemura	iba.iba_memt->t_base = VR_ISA_MEM_BASE + offset;
1541.1Stakemura	iba.iba_memt->t_size = VR_ISA_MEM_SIZE - offset;
1551.1Stakemura	hpcmips_init_bus_space_extent(iba.iba_memt);
1561.1Stakemura
1571.1Stakemura	/* Allocate ISA port space */
1581.1Stakemura	iba.iba_iot     = hpcmips_alloc_bus_space_tag();
1591.1Stakemura	strcpy(iba.iba_iot->t_name, "ISA port");
1601.1Stakemura	/* Platform dependent setting. */
1611.1Stakemura	offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAPORTOFFSET];
1621.1Stakemura	iba.iba_iot->t_base = VR_ISA_PORT_BASE + offset;
1631.1Stakemura	iba.iba_iot->t_size = VR_ISA_PORT_SIZE - offset;
1641.1Stakemura
1651.1Stakemura	hpcmips_init_bus_space_extent(iba.iba_iot);
1661.1Stakemura
1671.1Stakemura#ifdef DEBUG_FIND_PCIC
1681.1Stakemura#warning DEBUG_FIND_PCIC
1691.1Stakemura	__find_pcic();
1701.1Stakemura#else
1711.1Stakemura	/* Initialize ISA IRQ <-> GPIO mapping */
1721.13Stakemura	for (i = 0; i < INTR_NIRQS; i++)
1731.1Stakemura		sc->sc_intr_map[i] = -1;
1741.15Senami	printf(": ISA port %#x-%#x mem %#x-%#x\n",
1751.15Senami	    iba.iba_iot->t_base, iba.iba_iot->t_base + iba.iba_iot->t_size,
1761.15Senami	    iba.iba_memt->t_base, iba.iba_memt->t_base + iba.iba_memt->t_size);
1771.1Stakemura	config_found(self, &iba, vrisabprint);
1781.1Stakemura#endif
1791.11Ssato
1801.11Ssato#ifdef DEBUG_FIND_COMPORT
1811.11Ssato#warning DEBUG_FIND_COMPORT
1821.11Ssato	__find_comport();
1831.11Ssato#endif
1841.1Stakemura}
1851.1Stakemura
1861.1Stakemuraint
1871.1Stakemuravrisabprint(aux, pnp)
1881.1Stakemura	void *aux;
1891.1Stakemura	const char *pnp;
1901.1Stakemura{
1911.1Stakemura	if (pnp)
1921.1Stakemura		return (QUIET);
1931.1Stakemura	return (UNCONF);
1941.1Stakemura}
1951.1Stakemura
1961.1Stakemuravoid
1971.1Stakemuraisa_attach_hook(parent, self, iba)
1981.1Stakemura	struct device *parent, *self;
1991.1Stakemura	struct isabus_attach_args *iba;
2001.1Stakemura{
2011.6Scgd}
2021.6Scgd
2031.6Scgdconst struct evcnt *
2041.6Scgdisa_intr_evcnt(isa_chipset_tag_t ic, int irq)
2051.6Scgd{
2061.6Scgd
2071.6Scgd	/* XXX for now, no evcnt parent reported */
2081.6Scgd	return NULL;
2091.1Stakemura}
2101.1Stakemura
2111.1Stakemuravoid *
2121.2Stakemuraisa_intr_establish(ic, intr, type, level, ih_fun, ih_arg)
2131.1Stakemura	isa_chipset_tag_t ic;
2141.2Stakemura	int intr;
2151.1Stakemura	int type;  /* XXX not yet */
2161.1Stakemura	int level;  /* XXX not yet */
2171.1Stakemura	int (*ih_fun) __P((void*));
2181.1Stakemura	void *ih_arg;
2191.1Stakemura{
2201.3Stakemura	struct vrisab_softc *sc = ic->ic_sc;
2211.3Stakemura	int port, irq, mode;
2221.2Stakemura
2231.2Stakemura	static int intr_modes[8] = {
2241.13Stakemura		HPCIO_INTR_LEVEL_HIGH_THROUGH,
2251.13Stakemura		HPCIO_INTR_LEVEL_HIGH_HOLD,
2261.13Stakemura		HPCIO_INTR_LEVEL_LOW_THROUGH,
2271.13Stakemura		HPCIO_INTR_LEVEL_LOW_HOLD,
2281.13Stakemura		HPCIO_INTR_EDGE_THROUGH,
2291.13Stakemura		HPCIO_INTR_EDGE_HOLD,
2301.13Stakemura		HPCIO_INTR_EDGE_THROUGH,
2311.13Stakemura		HPCIO_INTR_EDGE_HOLD,
2321.2Stakemura	};
2331.4Ssato#ifdef VRISADEBUG
2341.2Stakemura	static char* intr_mode_names[8] = {
2351.2Stakemura		"level high through",
2361.2Stakemura		"level high hold",
2371.2Stakemura		"level low through",
2381.2Stakemura		"level low hold",
2391.2Stakemura		"edge through",
2401.2Stakemura		"edge hold",
2411.2Stakemura		"edge through",
2421.2Stakemura		"edge hold",
2431.2Stakemura	};
2441.4Ssato#endif /* VRISADEBUG */
2451.1Stakemura	/*
2461.1Stakemura	 * ISA IRQ <-> GPIO port mapping
2471.1Stakemura	 */
2481.2Stakemura	irq = INTR_IRQ(intr);
2491.3Stakemura	if (sc->sc_intr_map[irq] != -1) {
2501.3Stakemura		/* already mapped */
2511.3Stakemura		intr = sc->sc_intr_map[irq];
2521.2Stakemura	} else {
2531.3Stakemura		/* not mapped yet */
2541.3Stakemura		sc->sc_intr_map[irq] = intr; /* Register it */
2551.1Stakemura	}
2561.3Stakemura	mode = INTR_MODE(intr);
2571.3Stakemura	port = INTR_PORT(intr);
2581.3Stakemura
2591.14Stakemura	VPRINTF(("ISA IRQ %d -> %s port %d, %s\n",
2601.14Stakemura	       irq, sc->sc_hc->hc_name, port, intr_mode_names[mode]));
2611.3Stakemura
2621.1Stakemura	/* Call Vr routine */
2631.13Stakemura	return hpcio_intr_establish(sc->sc_hc, port, intr_modes[mode],
2641.13Stakemura				    ih_fun, ih_arg);
2651.1Stakemura}
2661.1Stakemura
2671.1Stakemuravoid
2681.1Stakemuraisa_intr_disestablish(ic, arg)
2691.1Stakemura	isa_chipset_tag_t ic;
2701.1Stakemura	void *arg;
2711.1Stakemura{
2721.3Stakemura	struct vrisab_softc *sc = ic->ic_sc;
2731.1Stakemura	/* Call Vr routine */
2741.13Stakemura	hpcio_intr_disestablish(sc->sc_hc, arg);
2751.1Stakemura}
2761.1Stakemura
2771.1Stakemuraint
2781.1Stakemuraisa_intr_alloc(ic, mask, type, irq)
2791.1Stakemura	isa_chipset_tag_t ic;
2801.1Stakemura	int mask;
2811.1Stakemura	int type;
2821.1Stakemura	int *irq;
2831.1Stakemura{
2841.1Stakemura	/* XXX not coded yet. this is temporary XXX */
2851.4Ssato	DPRINTF(("isa_intr_alloc:"));
2861.4Ssato	DBITDISP32(mask);
2871.3Stakemura	*irq = (ffs(mask) -1); /* XXX */
2881.1Stakemura	return 0;
2891.1Stakemura}
2901.1Stakemura
2911.11Ssato
2921.1Stakemura#ifdef DEBUG_FIND_PCIC
2931.1Stakemura#warning DEBUG_FIND_PCIC
2941.1Stakemurastatic void
2951.1Stakemura__find_pcic(void)
2961.1Stakemura{
2971.1Stakemura	int i, j, step, found;
2981.1Stakemura	u_int32_t addr;
2991.1Stakemura	u_int8_t reg;
3001.1Stakemura	int __read_revid (u_int32_t port)
3011.1Stakemura		{
3021.1Stakemura			addr = MIPS_PHYS_TO_KSEG1(i + port);
3031.1Stakemura			printf("%#x\r", i);
3041.1Stakemura			for (found = 0, j = 0; j < 0x100; j += 0x40) {
3051.1Stakemura				*((volatile u_int8_t*)addr) = j;
3061.1Stakemura				reg = *((volatile u_int8_t*)(addr + 1));
3071.1Stakemura#ifdef DEBUG_FIND_PCIC_I82365SL_ONLY
3081.1Stakemura				if (reg == 0x82 || reg == 0x83) {
3091.1Stakemura#else
3101.1Stakemura				if ((reg & 0xc0) == 0x80) {
3111.1Stakemura#endif
3121.1Stakemura					found++;
3131.1Stakemura				}
3141.1Stakemura			}
3151.1Stakemura			if (found)
3161.1Stakemura				printf("\nfound %d socket at %#x (base from %#x)\n", found, addr,
3171.1Stakemura				       i + port - VR_ISA_PORT_BASE);
3181.1Stakemura		};
3191.1Stakemura	step = 0x1000000;
3201.1Stakemura	printf("\nFinding PCIC. Trying ISA port %#x-%#x step %#x\n",
3211.1Stakemura	       VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE, step);
3221.1Stakemura	for (i = VR_ISA_PORT_BASE; i < VR_ISA_PORT_BASE+VR_ISA_PORT_SIZE; i+= step) {
3231.1Stakemura		__read_revid (0x3e0);
3241.1Stakemura		__read_revid (0x3e2);
3251.11Ssato	}
3261.11Ssato}
3271.11Ssato#endif
3281.11Ssato
3291.11Ssato
3301.11Ssato#ifdef DEBUG_FIND_COMPORT
3311.11Ssato#warning DEBUG_FIND_COMPORT
3321.11Ssato
3331.11Ssatostatic int probe_com __P((u_int32_t));
3341.11Ssato
3351.11Ssatostatic int  probe_com( port_addr )
3361.11Ssato	u_int32_t	port_addr;
3371.11Ssato{
3381.11Ssato	u_int32_t	addr;
3391.11Ssato	u_int8_t	ubtmp1;
3401.11Ssato	u_int8_t	ubtmp2;
3411.11Ssato
3421.11Ssato	addr = MIPS_PHYS_TO_KSEG1( port_addr );
3431.11Ssato
3441.11Ssato	*((volatile u_int8_t*)(addr + com_cfcr)) = LCR_8BITS;
3451.11Ssato	*((volatile u_int8_t*)(addr + com_iir)) = 0;
3461.11Ssato
3471.11Ssato	ubtmp1 = *((volatile u_int8_t*)(addr + com_cfcr));
3481.11Ssato	ubtmp2 = *((volatile u_int8_t*)(addr + com_iir));
3491.11Ssato
3501.11Ssato	if( (ubtmp1 != LCR_8BITS) || ((ubtmp2 & 0x38) != 0) ){
3511.11Ssato		return( 0 );
3521.11Ssato	}
3531.11Ssato
3541.11Ssato	return( 1 );
3551.11Ssato}
3561.11Ssato
3571.11Ssatostatic void
3581.11Ssato__find_comport(void)
3591.11Ssato{
3601.11Ssato	int	found;
3611.11Ssato	u_int32_t	port;
3621.11Ssato	u_int32_t	step;
3631.11Ssato
3641.11Ssato	found = 0;
3651.11Ssato	step = 0x08;
3661.11Ssato
3671.11Ssato	printf("Searching COM port. Trying ISA port %#x-%#x step %#x\n",
3681.11Ssato		   VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE - 1, step );
3691.11Ssato
3701.11Ssato	for( port = VR_ISA_PORT_BASE ; port < (VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE) ; port += step ){
3711.11Ssato		if( probe_com( port ) ){
3721.11Ssato			found++;
3731.11Ssato			printf("found %d at %#x\n",found,port);
3741.11Ssato		}
3751.1Stakemura	}
3761.1Stakemura}
3771.1Stakemura#endif
378