mq200_pci.c revision 1.1
11.1Stakemura/*	$NetBSD: mq200_pci.c,v 1.1 2002/05/11 14:10:06 takemura Exp $	*/
21.1Stakemura
31.1Stakemura/*-
41.1Stakemura * Copyright (c) 2002 TAKEMURA Shin
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. Redistributions in binary form must reproduce the above copyright
131.1Stakemura *    notice, this list of conditions and the following disclaimer in the
141.1Stakemura *    documentation and/or other materials provided with the distribution.
151.1Stakemura * 3. The name of the author may not be used to endorse or promote products
161.1Stakemura *    derived from this software without specific prior written permission.
171.1Stakemura *
181.1Stakemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
191.1Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201.1Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211.1Stakemura * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221.1Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231.1Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241.1Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251.1Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261.1Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271.1Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281.1Stakemura * SUCH DAMAGE.
291.1Stakemura *
301.1Stakemura */
311.1Stakemura
321.1Stakemura#include <sys/cdefs.h>
331.1Stakemura__KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.1 2002/05/11 14:10:06 takemura Exp $");
341.1Stakemura
351.1Stakemura#include <sys/param.h>
361.1Stakemura#include <sys/systm.h>
371.1Stakemura#include <sys/kernel.h>
381.1Stakemura#include <sys/device.h>
391.1Stakemura#include <sys/malloc.h>
401.1Stakemura
411.1Stakemura#include <dev/pci/pcireg.h>
421.1Stakemura#include <dev/pci/pcivar.h>
431.1Stakemura#include <dev/pci/pcidevs.h>
441.1Stakemura#include <dev/pci/pciio.h>
451.1Stakemura
461.1Stakemura#include <hpcmips/dev/mq200var.h>
471.1Stakemura
481.1Stakemurastruct mq200_pci_softc {
491.1Stakemura	struct mq200_softc	sc_mq200;
501.1Stakemura	pci_chipset_tag_t sc_pc;
511.1Stakemura	pcitag_t sc_pcitag;
521.1Stakemura};
531.1Stakemura
541.1Stakemuraint	mq200_pci_match(struct device *, struct cfdata *, void *);
551.1Stakemuravoid	mq200_pci_attach(struct device *, struct device *, void *);
561.1Stakemura
571.1Stakemurastruct cfattach mqvideo_pci_ca = {
581.1Stakemura	sizeof(struct mq200_pci_softc),
591.1Stakemura	mq200_pci_match,
601.1Stakemura	mq200_pci_attach,
611.1Stakemura};
621.1Stakemura
631.1Stakemuraint
641.1Stakemuramq200_pci_match(struct device *parent, struct cfdata *match, void *aux)
651.1Stakemura{
661.1Stakemura	struct pci_attach_args *pa = aux;
671.1Stakemura
681.1Stakemura	/* check vendor id and product id */
691.1Stakemura	if (pa->pa_id !=
701.1Stakemura	    PCI_ID_CODE(PCI_VENDOR_MEDIAQ, PCI_PRODUCT_MEDIAQ_MQ200))
711.1Stakemura		return (0);
721.1Stakemura
731.1Stakemura	return (1);
741.1Stakemura}
751.1Stakemura
761.1Stakemuravoid
771.1Stakemuramq200_pci_attach(struct device *parent, struct device *self, void *aux)
781.1Stakemura{
791.1Stakemura	struct mq200_pci_softc *psc = (void *) self;
801.1Stakemura	struct mq200_softc *sc = &psc->sc_mq200;
811.1Stakemura	struct pci_attach_args *pa = aux;
821.1Stakemura//	char devinfo[256];
831.1Stakemura	int res;
841.1Stakemura
851.1Stakemura	psc->sc_pc = pa->pa_pc;
861.1Stakemura	psc->sc_pcitag = pa->pa_tag;
871.1Stakemura
881.1Stakemura#if 0
891.1Stakemura	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
901.1Stakemura	printf(": %s (rev. 0x%02x)\n", devinfo,
911.1Stakemura	    PCI_REVISION(pa->pa_class));
921.1Stakemura#endif
931.1Stakemura	/* check whether it is disabled by firmware */
941.1Stakemura	if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) &
951.1Stakemura	    PCI_COMMAND_MEM_ENABLE)) {
961.1Stakemura		printf("%s: disabled\n", sc->sc_dev.dv_xname);
971.1Stakemura		return;
981.1Stakemura	}
991.1Stakemura
1001.1Stakemura	/* Base Address Register 0: base address of control registers */
1011.1Stakemura	res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
1021.1Stakemura	    0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL);
1031.1Stakemura	if (res != 0) {
1041.1Stakemura		printf("%s: can't map registers\n", sc->sc_dev.dv_xname);
1051.1Stakemura		return;
1061.1Stakemura	}
1071.1Stakemura
1081.1Stakemura	/* Base Address Register 1: base address of frame buffer */
1091.1Stakemura	res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4,
1101.1Stakemura	    PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL);
1111.1Stakemura	if (res != 0) {
1121.1Stakemura		printf("%s: can't map frame buffer\n", sc->sc_dev.dv_xname);
1131.1Stakemura		return;
1141.1Stakemura	}
1151.1Stakemura
1161.1Stakemura	mq200_attach(sc);
1171.1Stakemura}
118