xref: /netbsd-src/sys/arch/hpcmips/dev/mq200_pci.c (revision 7433666e375b3ac4cc764df5a6726be98bc1cdd5)
1*7433666eSthorpej /*	$NetBSD: mq200_pci.c,v 1.6 2023/12/20 14:50:02 thorpej 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*7433666eSthorpej __KERNEL_RCSID(0, "$NetBSD: mq200_pci.c,v 1.6 2023/12/20 14:50:02 thorpej Exp $");
34108ae856Stakemura 
35108ae856Stakemura #include <sys/param.h>
36108ae856Stakemura #include <sys/systm.h>
37108ae856Stakemura #include <sys/kernel.h>
38108ae856Stakemura #include <sys/device.h>
39108ae856Stakemura 
40108ae856Stakemura #include <dev/pci/pcireg.h>
41108ae856Stakemura #include <dev/pci/pcivar.h>
42108ae856Stakemura #include <dev/pci/pcidevs.h>
43108ae856Stakemura #include <dev/pci/pciio.h>
44108ae856Stakemura 
45108ae856Stakemura #include <hpcmips/dev/mq200var.h>
46108ae856Stakemura 
47108ae856Stakemura struct mq200_pci_softc {
48108ae856Stakemura 	struct mq200_softc	sc_mq200;
49108ae856Stakemura 	pci_chipset_tag_t sc_pc;
50108ae856Stakemura 	pcitag_t sc_pcitag;
51108ae856Stakemura };
52108ae856Stakemura 
53cbab9cadSchs int	mq200_pci_match(device_t, cfdata_t, void *);
54cbab9cadSchs void	mq200_pci_attach(device_t, device_t, void *);
55108ae856Stakemura 
56cbab9cadSchs CFATTACH_DECL_NEW(mqvideo_pci, sizeof(struct mq200_pci_softc),
57c5e91d44Sthorpej     mq200_pci_match, mq200_pci_attach, NULL, NULL);
58108ae856Stakemura 
59108ae856Stakemura int
mq200_pci_match(device_t parent,cfdata_t match,void * aux)60cbab9cadSchs mq200_pci_match(device_t parent, cfdata_t match, void *aux)
61108ae856Stakemura {
62108ae856Stakemura 	struct pci_attach_args *pa = aux;
63108ae856Stakemura 
64108ae856Stakemura 	/* check vendor id and product id */
65108ae856Stakemura 	if (pa->pa_id !=
66108ae856Stakemura 	    PCI_ID_CODE(PCI_VENDOR_MEDIAQ, PCI_PRODUCT_MEDIAQ_MQ200))
67108ae856Stakemura 		return (0);
68108ae856Stakemura 
69108ae856Stakemura 	return (1);
70108ae856Stakemura }
71108ae856Stakemura 
72108ae856Stakemura void
mq200_pci_attach(device_t parent,device_t self,void * aux)73cbab9cadSchs mq200_pci_attach(device_t parent, device_t self, void *aux)
74108ae856Stakemura {
75cbab9cadSchs 	struct mq200_pci_softc *psc = device_private(self);
76108ae856Stakemura 	struct mq200_softc *sc = &psc->sc_mq200;
77108ae856Stakemura 	struct pci_attach_args *pa = aux;
78108ae856Stakemura 	int res;
79108ae856Stakemura 
80cbab9cadSchs 	sc->sc_dev = self;
81108ae856Stakemura 	psc->sc_pc = pa->pa_pc;
82108ae856Stakemura 	psc->sc_pcitag = pa->pa_tag;
83108ae856Stakemura 
84108ae856Stakemura 	/* check whether it is disabled by firmware */
85108ae856Stakemura 	if (!(pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) &
86108ae856Stakemura 	    PCI_COMMAND_MEM_ENABLE)) {
87cbab9cadSchs 		printf("%s: disabled\n", device_xname(sc->sc_dev));
88108ae856Stakemura 		return;
89108ae856Stakemura 	}
90108ae856Stakemura 
91108ae856Stakemura 	/* Base Address Register 0: base address of control registers */
92108ae856Stakemura 	res = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
93108ae856Stakemura 	    0, &sc->sc_iot, &sc->sc_ioh, NULL, NULL);
94108ae856Stakemura 	if (res != 0) {
95cbab9cadSchs 		printf("%s: can't map registers\n", device_xname(sc->sc_dev));
96108ae856Stakemura 		return;
97108ae856Stakemura 	}
98108ae856Stakemura 
99108ae856Stakemura 	/* Base Address Register 1: base address of frame buffer */
100108ae856Stakemura 	res = pci_mapreg_info(psc->sc_pc, psc->sc_pcitag, PCI_MAPREG_START+4,
101108ae856Stakemura 	    PCI_MAPREG_TYPE_MEM, &sc->sc_baseaddr, NULL, NULL);
102108ae856Stakemura 	if (res != 0) {
103cbab9cadSchs 		printf("%s: can't map frame buffer\n", device_xname(sc->sc_dev));
104108ae856Stakemura 		return;
105108ae856Stakemura 	}
106108ae856Stakemura 
107108ae856Stakemura 	mq200_attach(sc);
108108ae856Stakemura }
109