mq200_pci.c revision 1.5
11.5Schs/* $NetBSD: mq200_pci.c,v 1.5 2012/10/27 17:17:52 chs 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.5Schs__KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.5 2012/10/27 17:17:52 chs 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.5Schsint mq200_pci_match(device_t, cfdata_t, void *); 551.5Schsvoid mq200_pci_attach(device_t, device_t, void *); 561.1Stakemura 571.5SchsCFATTACH_DECL_NEW(mqvideo_pci, sizeof(struct mq200_pci_softc), 581.4Sthorpej mq200_pci_match, mq200_pci_attach, NULL, NULL); 591.1Stakemura 601.1Stakemuraint 611.5Schsmq200_pci_match(device_t parent, cfdata_t 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.5Schsmq200_pci_attach(device_t parent, device_t self, void *aux) 751.1Stakemura{ 761.5Schs struct mq200_pci_softc *psc = device_private(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.5Schs sc->sc_dev = self; 821.1Stakemura psc->sc_pc = pa->pa_pc; 831.1Stakemura psc->sc_pcitag = pa->pa_tag; 841.1Stakemura 851.1Stakemura /* check whether it is disabled by firmware */ 861.1Stakemura if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) & 871.1Stakemura PCI_COMMAND_MEM_ENABLE)) { 881.5Schs printf("%s: disabled\n", device_xname(sc->sc_dev)); 891.1Stakemura return; 901.1Stakemura } 911.1Stakemura 921.1Stakemura /* Base Address Register 0: base address of control registers */ 931.1Stakemura res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM, 941.1Stakemura 0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL); 951.1Stakemura if (res != 0) { 961.5Schs printf("%s: can't map registers\n", device_xname(sc->sc_dev)); 971.1Stakemura return; 981.1Stakemura } 991.1Stakemura 1001.1Stakemura /* Base Address Register 1: base address of frame buffer */ 1011.1Stakemura res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4, 1021.1Stakemura PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL); 1031.1Stakemura if (res != 0) { 1041.5Schs printf("%s: can't map frame buffer\n", device_xname(sc->sc_dev)); 1051.1Stakemura return; 1061.1Stakemura } 1071.1Stakemura 1081.1Stakemura mq200_attach(sc); 1091.1Stakemura} 110