mq200_pci.c revision 1.4
11.4Sthorpej/* $NetBSD: mq200_pci.c,v 1.4 2002/10/02 05:26:46 thorpej 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.4Sthorpej__KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.4 2002/10/02 05:26:46 thorpej 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.4SthorpejCFATTACH_DECL(mqvideo_pci, sizeof(struct mq200_pci_softc), 581.4Sthorpej mq200_pci_match, mq200_pci_attach, NULL, NULL); 591.1Stakemura 601.1Stakemuraint 611.1Stakemuramq200_pci_match(struct device *parent, struct cfdata *match, void *aux) 621.1Stakemura{ 631.1Stakemura struct pci_attach_args *pa = aux; 641.1Stakemura 651.1Stakemura /* check vendor id and product id */ 661.1Stakemura if (pa->pa_id != 671.1Stakemura PCI_ID_CODE(PCI_VENDOR_MEDIAQ, PCI_PRODUCT_MEDIAQ_MQ200)) 681.1Stakemura return (0); 691.1Stakemura 701.1Stakemura return (1); 711.1Stakemura} 721.1Stakemura 731.1Stakemuravoid 741.1Stakemuramq200_pci_attach(struct device *parent, struct device *self, void *aux) 751.1Stakemura{ 761.1Stakemura struct mq200_pci_softc *psc = (void *) self; 771.1Stakemura struct mq200_softc *sc = &psc->sc_mq200; 781.1Stakemura struct pci_attach_args *pa = aux; 791.1Stakemura int res; 801.1Stakemura 811.1Stakemura psc->sc_pc = pa->pa_pc; 821.1Stakemura psc->sc_pcitag = pa->pa_tag; 831.1Stakemura 841.1Stakemura /* check whether it is disabled by firmware */ 851.1Stakemura if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) & 861.1Stakemura PCI_COMMAND_MEM_ENABLE)) { 871.1Stakemura printf("%s: disabled\n", sc->sc_dev.dv_xname); 881.1Stakemura return; 891.1Stakemura } 901.1Stakemura 911.1Stakemura /* Base Address Register 0: base address of control registers */ 921.1Stakemura res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM, 931.1Stakemura 0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL); 941.1Stakemura if (res != 0) { 951.1Stakemura printf("%s: can't map registers\n", sc->sc_dev.dv_xname); 961.1Stakemura return; 971.1Stakemura } 981.1Stakemura 991.1Stakemura /* Base Address Register 1: base address of frame buffer */ 1001.1Stakemura res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4, 1011.1Stakemura PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL); 1021.1Stakemura if (res != 0) { 1031.1Stakemura printf("%s: can't map frame buffer\n", sc->sc_dev.dv_xname); 1041.1Stakemura return; 1051.1Stakemura } 1061.1Stakemura 1071.1Stakemura mq200_attach(sc); 1081.1Stakemura} 109