1*c7fb772bSthorpej /* $NetBSD: pbus.c,v 1.15 2021/08/07 16:18:52 thorpej Exp $ */
25448df2eSscw
35448df2eSscw /*
45448df2eSscw * Copyright 2001 Wasabi Systems, Inc.
55448df2eSscw * All rights reserved.
65448df2eSscw *
75448df2eSscw * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
85448df2eSscw *
95448df2eSscw * Redistribution and use in source and binary forms, with or without
105448df2eSscw * modification, are permitted provided that the following conditions
115448df2eSscw * are met:
125448df2eSscw * 1. Redistributions of source code must retain the above copyright
135448df2eSscw * notice, this list of conditions and the following disclaimer.
145448df2eSscw * 2. Redistributions in binary form must reproduce the above copyright
155448df2eSscw * notice, this list of conditions and the following disclaimer in the
165448df2eSscw * documentation and/or other materials provided with the distribution.
175448df2eSscw * 3. All advertising materials mentioning features or use of this software
185448df2eSscw * must display the following acknowledgement:
195448df2eSscw * This product includes software developed for the NetBSD Project by
205448df2eSscw * Wasabi Systems, Inc.
215448df2eSscw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
225448df2eSscw * or promote products derived from this software without specific prior
235448df2eSscw * written permission.
245448df2eSscw *
255448df2eSscw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
265448df2eSscw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
275448df2eSscw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
285448df2eSscw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
295448df2eSscw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
305448df2eSscw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
315448df2eSscw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
325448df2eSscw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
335448df2eSscw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
345448df2eSscw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
355448df2eSscw * POSSIBILITY OF SUCH DAMAGE.
365448df2eSscw */
375448df2eSscw
385448df2eSscw /*
395448df2eSscw * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
405448df2eSscw *
415448df2eSscw * Redistribution and use in source and binary forms, with or without
425448df2eSscw * modification, are permitted provided that the following conditions
435448df2eSscw * are met:
445448df2eSscw * 1. Redistributions of source code must retain the above copyright
455448df2eSscw * notice, this list of conditions and the following disclaimer.
465448df2eSscw * 2. Redistributions in binary form must reproduce the above copyright
475448df2eSscw * notice, this list of conditions and the following disclaimer in the
485448df2eSscw * documentation and/or other materials provided with the distribution.
495448df2eSscw * 3. All advertising materials mentioning features or use of this software
505448df2eSscw * must display the following acknowledgement:
515448df2eSscw * This product includes software developed by Christopher G. Demetriou
525448df2eSscw * for the NetBSD Project.
535448df2eSscw * 4. The name of the author may not be used to endorse or promote products
545448df2eSscw * derived from this software without specific prior written permission
555448df2eSscw *
565448df2eSscw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
575448df2eSscw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
585448df2eSscw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
595448df2eSscw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
605448df2eSscw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
615448df2eSscw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
625448df2eSscw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
635448df2eSscw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
645448df2eSscw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
655448df2eSscw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
665448df2eSscw */
675448df2eSscw
6814172728Slukem #include <sys/cdefs.h>
69*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: pbus.c,v 1.15 2021/08/07 16:18:52 thorpej Exp $");
7014172728Slukem
715448df2eSscw #include "locators.h"
725448df2eSscw #include "pckbc.h"
735448df2eSscw
745448df2eSscw #include <sys/param.h>
755448df2eSscw #include <sys/systm.h>
765448df2eSscw #include <sys/device.h>
775448df2eSscw
78cf10107dSdyoung #include <sys/bus.h>
795448df2eSscw #include <machine/walnut.h>
805448df2eSscw
815448df2eSscw #include <evbppc/walnut/dev/pbusvar.h>
825448df2eSscw
835448df2eSscw #include <powerpc/ibm4xx/ibm405gp.h>
845448df2eSscw #include <powerpc/ibm4xx/dev/plbvar.h>
855448df2eSscw
865448df2eSscw /*
8716f1ab81Ssimonb * The external devices on the Walnut 405GP evaluation board.
885448df2eSscw */
895448df2eSscw const struct pbus_dev {
905448df2eSscw const char *name;
915448df2eSscw bus_addr_t addr;
925448df2eSscw int irq;
935448df2eSscw } pbus_devs [] = {
9483f1167aSsimonb { "ds1743rtc", NVRAM_BASE, -1 },
955448df2eSscw { "pckbc", KEY_MOUSE_BASE, 25 }, /* XXX: really irq x..x+1 */
965448df2eSscw { NULL }
975448df2eSscw };
985448df2eSscw
99ec1797c1Smatt static int pbus_match(device_t, cfdata_t, void *);
100ec1797c1Smatt static void pbus_attach(device_t, device_t, void *);
1015448df2eSscw static int pbus_print(void *, const char *);
1025448df2eSscw
103ec1797c1Smatt CFATTACH_DECL_NEW(pbus, 0,
1045448df2eSscw pbus_match, pbus_attach, NULL, NULL);
1055448df2eSscw
1060b0e493eSscw static struct powerpc_bus_space pbus_tag = {
1070b0e493eSscw _BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
1080b0e493eSscw 0x00000000,
1090b0e493eSscw NVRAM_BASE,
1100b0e493eSscw NVRAM_BASE + 0x0300010 /* Cover from NVRAM_BASE -> FPGA_BASE */
1110b0e493eSscw };
1120b0e493eSscw
1135448df2eSscw /*
1145448df2eSscw * Probe for the peripheral bus.
1155448df2eSscw */
1165448df2eSscw static int
pbus_match(device_t parent,cfdata_t cf,void * aux)117ec1797c1Smatt pbus_match(device_t parent, cfdata_t cf, void *aux)
1185448df2eSscw {
1195448df2eSscw struct pbus_attach_args *pba = aux;
1205448df2eSscw
1215448df2eSscw /* match only pbus devices */
1225448df2eSscw if (strcmp(pba->pb_name, cf->cf_name) != 0)
1235448df2eSscw return (0);
1245448df2eSscw
1255448df2eSscw return (1);
1265448df2eSscw }
1275448df2eSscw
1285448df2eSscw /*
1295448df2eSscw * Attach the peripheral bus.
1305448df2eSscw */
1315448df2eSscw static void
pbus_attach(device_t parent,device_t self,void * aux)132ec1797c1Smatt pbus_attach(device_t parent, device_t self, void *aux)
1335448df2eSscw {
1345448df2eSscw struct plb_attach_args *paa = aux;
1355448df2eSscw struct pbus_attach_args pba;
1365448df2eSscw int i;
1375448df2eSscw #if NPCKBC > 0
1385448df2eSscw bus_space_handle_t ioh_fpga;
1390b0e493eSscw bus_space_tag_t iot_fpga = &pbus_tag;
1405448df2eSscw uint8_t fpga_reg;
1415448df2eSscw #endif
1425448df2eSscw
1435448df2eSscw printf("\n");
1445448df2eSscw
1450b0e493eSscw if (bus_space_init(&pbus_tag, "pbus", NULL, 0))
1460b0e493eSscw panic("pbus_attach: can't init tag");
1470b0e493eSscw
1485448df2eSscw for (i = 0; pbus_devs[i].name != NULL; i++) {
1495448df2eSscw pba.pb_name = pbus_devs[i].name;
1505448df2eSscw pba.pb_addr = pbus_devs[i].addr;
1515448df2eSscw pba.pb_irq = pbus_devs[i].irq;
1520b0e493eSscw pba.pb_bt = &pbus_tag;
1535448df2eSscw pba.pb_dmat = paa->plb_dmat;
1545448df2eSscw
1552a3a47a6Scliff const int locs[PBUSCF_NLOCS] = {
1562a3a47a6Scliff [PBUSCF_ADDR] = pba.pb_addr,
1572a3a47a6Scliff [PBUSCF_IRQ] = pba.pb_irq
1582a3a47a6Scliff };
1592a3a47a6Scliff
1602685996bSthorpej config_found(self, &pba, pbus_print,
161*c7fb772bSthorpej CFARGS(.submatch = config_stdsubmatch,
162*c7fb772bSthorpej .locators = locs));
1635448df2eSscw }
1645448df2eSscw
1655448df2eSscw #if NPCKBC > 0
1665448df2eSscw /* Configure FPGA */
1675448df2eSscw if (bus_space_map(iot_fpga, FPGA_BASE, FPGA_SIZE, 0, &ioh_fpga)) {
1685448df2eSscw printf("pbus_attach: can't map FPGA\n");
1695448df2eSscw /* XXX - disable keyboard probe? */
1705448df2eSscw } else {
1715448df2eSscw /* Use separate interrupts for keyboard and mouse */
1725448df2eSscw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_BRDC);
1735448df2eSscw fpga_reg |= FPGA_BRDC_INT;
1745448df2eSscw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_BRDC, fpga_reg);
1755448df2eSscw
1765448df2eSscw /* Set interrupts to active high */
1775448df2eSscw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_POL);
1785448df2eSscw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
1795448df2eSscw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_POL, fpga_reg);
1805448df2eSscw
1815448df2eSscw /* Set interrupts to level triggered */
1825448df2eSscw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG);
1835448df2eSscw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
1845448df2eSscw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG, fpga_reg);
1855448df2eSscw
1865448df2eSscw /* Enable interrupts */
1875448df2eSscw fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE);
1885448df2eSscw fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
1895448df2eSscw bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE, fpga_reg);
1905448df2eSscw
1915448df2eSscw bus_space_unmap(&iot_fpga, ioh_fpga, 2);
1925448df2eSscw }
1935448df2eSscw #endif
1945448df2eSscw
1955448df2eSscw }
1965448df2eSscw
1975448df2eSscw static int
pbus_print(void * aux,const char * pnp)1985448df2eSscw pbus_print(void *aux, const char *pnp)
1995448df2eSscw {
2005448df2eSscw struct pbus_attach_args *pba = aux;
2015448df2eSscw
2025448df2eSscw if (pnp)
2035448df2eSscw printf("%s at %s", pba->pb_name, pnp);
2045448df2eSscw
2055448df2eSscw if (pba->pb_addr != PBUSCF_ADDR_DEFAULT)
2061132348bSthorpej aprint_normal(" addr 0x%08lx", pba->pb_addr);
2075448df2eSscw if (pba->pb_irq != PBUSCF_IRQ_DEFAULT)
2081132348bSthorpej aprint_normal(" irq %d", pba->pb_irq);
2095448df2eSscw
2105448df2eSscw return (UNCONF);
2115448df2eSscw }
212