1*5f819ca3Schs /* $NetBSD: mq200_pci.c,v 1.5 2012/10/27 17:17:52 chs Exp $ */
2108ae856Stakemura
3108ae856Stakemura /*-
4108ae856Stakemura * Copyright (c) 2002 TAKEMURA Shin
5108ae856Stakemura * All rights reserved.
6108ae856Stakemura *
7108ae856Stakemura * Redistribution and use in source and binary forms, with or without
8108ae856Stakemura * modification, are permitted provided that the following conditions
9108ae856Stakemura * are met:
10108ae856Stakemura * 1. Redistributions of source code must retain the above copyright
11108ae856Stakemura * notice, this list of conditions and the following disclaimer.
12108ae856Stakemura * 2. Redistributions in binary form must reproduce the above copyright
13108ae856Stakemura * notice, this list of conditions and the following disclaimer in the
14108ae856Stakemura * documentation and/or other materials provided with the distribution.
15108ae856Stakemura * 3. The name of the author may not be used to endorse or promote products
16108ae856Stakemura * derived from this software without specific prior written permission.
17108ae856Stakemura *
18108ae856Stakemura * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19108ae856Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20108ae856Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21108ae856Stakemura * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22108ae856Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23108ae856Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24108ae856Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25108ae856Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26108ae856Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27108ae856Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28108ae856Stakemura * SUCH DAMAGE.
29108ae856Stakemura *
30108ae856Stakemura */
31108ae856Stakemura
32108ae856Stakemura #include <sys/cdefs.h>
33*5f819ca3Schs __KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.5 2012/10/27 17:17:52 chs Exp $");
34108ae856Stakemura
35108ae856Stakemura #include <sys/param.h>
36108ae856Stakemura #include <sys/systm.h>
37108ae856Stakemura #include <sys/kernel.h>
38108ae856Stakemura #include <sys/device.h>
39108ae856Stakemura #include <sys/malloc.h>
40108ae856Stakemura
41108ae856Stakemura #include <dev/pci/pcireg.h>
42108ae856Stakemura #include <dev/pci/pcivar.h>
43108ae856Stakemura #include <dev/pci/pcidevs.h>
44108ae856Stakemura #include <dev/pci/pciio.h>
45108ae856Stakemura
46108ae856Stakemura #include <hpcmips/dev/mq200var.h>
47108ae856Stakemura
48108ae856Stakemura struct mq200_pci_softc {
49108ae856Stakemura struct mq200_softc sc_mq200;
50108ae856Stakemura pci_chipset_tag_t sc_pc;
51108ae856Stakemura pcitag_t sc_pcitag;
52108ae856Stakemura };
53108ae856Stakemura
54*5f819ca3Schs int mq200_pci_match(device_t, cfdata_t, void *);
55*5f819ca3Schs void mq200_pci_attach(device_t, device_t, void *);
56108ae856Stakemura
57*5f819ca3Schs CFATTACH_DECL_NEW(mqvideo_pci, sizeof(struct mq200_pci_softc),
58c5e91d44Sthorpej mq200_pci_match, mq200_pci_attach, NULL, NULL);
59108ae856Stakemura
60108ae856Stakemura int
mq200_pci_match(device_t parent,cfdata_t match,void * aux)61*5f819ca3Schs mq200_pci_match(device_t parent, cfdata_t match, void *aux)
62108ae856Stakemura {
63108ae856Stakemura struct pci_attach_args *pa = aux;
64108ae856Stakemura
65108ae856Stakemura /* check vendor id and product id */
66108ae856Stakemura if (pa->pa_id !=
67108ae856Stakemura PCI_ID_CODE(PCI_VENDOR_MEDIAQ, PCI_PRODUCT_MEDIAQ_MQ200))
68108ae856Stakemura return (0);
69108ae856Stakemura
70108ae856Stakemura return (1);
71108ae856Stakemura }
72108ae856Stakemura
73108ae856Stakemura void
mq200_pci_attach(device_t parent,device_t self,void * aux)74*5f819ca3Schs mq200_pci_attach(device_t parent, device_t self, void *aux)
75108ae856Stakemura {
76*5f819ca3Schs struct mq200_pci_softc *psc = device_private(self);
77108ae856Stakemura struct mq200_softc *sc = &psc->sc_mq200;
78108ae856Stakemura struct pci_attach_args *pa = aux;
79108ae856Stakemura int res;
80108ae856Stakemura
81*5f819ca3Schs sc->sc_dev = self;
82108ae856Stakemura psc->sc_pc = pa->pa_pc;
83108ae856Stakemura psc->sc_pcitag = pa->pa_tag;
84108ae856Stakemura
85108ae856Stakemura /* check whether it is disabled by firmware */
86108ae856Stakemura if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) &
87108ae856Stakemura PCI_COMMAND_MEM_ENABLE)) {
88*5f819ca3Schs printf("%s: disabled\n", device_xname(sc->sc_dev));
89108ae856Stakemura return;
90108ae856Stakemura }
91108ae856Stakemura
92108ae856Stakemura /* Base Address Register 0: base address of control registers */
93108ae856Stakemura res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
94108ae856Stakemura 0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL);
95108ae856Stakemura if (res != 0) {
96*5f819ca3Schs printf("%s: can't map registers\n", device_xname(sc->sc_dev));
97108ae856Stakemura return;
98108ae856Stakemura }
99108ae856Stakemura
100108ae856Stakemura /* Base Address Register 1: base address of frame buffer */
101108ae856Stakemura res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4,
102108ae856Stakemura PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL);
103108ae856Stakemura if (res != 0) {
104*5f819ca3Schs printf("%s: can't map frame buffer\n", device_xname(sc->sc_dev));
105108ae856Stakemura return;
106108ae856Stakemura }
107108ae856Stakemura
108108ae856Stakemura mq200_attach(sc);
109108ae856Stakemura }
110