Home | History | Annotate | Line # | Download | only in dev
      1  1.15  thorpej /*	$NetBSD: pbus.c,v 1.15 2021/08/07 16:18:52 thorpej Exp $	*/
      2   1.1      scw 
      3   1.1      scw /*
      4   1.1      scw  * Copyright 2001 Wasabi Systems, Inc.
      5   1.1      scw  * All rights reserved.
      6   1.1      scw  *
      7   1.1      scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8   1.1      scw  *
      9   1.1      scw  * Redistribution and use in source and binary forms, with or without
     10   1.1      scw  * modification, are permitted provided that the following conditions
     11   1.1      scw  * are met:
     12   1.1      scw  * 1. Redistributions of source code must retain the above copyright
     13   1.1      scw  *    notice, this list of conditions and the following disclaimer.
     14   1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     16   1.1      scw  *    documentation and/or other materials provided with the distribution.
     17   1.1      scw  * 3. All advertising materials mentioning features or use of this software
     18   1.1      scw  *    must display the following acknowledgement:
     19   1.1      scw  *      This product includes software developed for the NetBSD Project by
     20   1.1      scw  *      Wasabi Systems, Inc.
     21   1.1      scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.1      scw  *    or promote products derived from this software without specific prior
     23   1.1      scw  *    written permission.
     24   1.1      scw  *
     25   1.1      scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.1      scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.1      scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.1      scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.1      scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.1      scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.1      scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.1      scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.1      scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.1      scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.1      scw  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1      scw  */
     37   1.1      scw 
     38   1.1      scw /*
     39   1.1      scw  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     40   1.1      scw  *
     41   1.1      scw  * Redistribution and use in source and binary forms, with or without
     42   1.1      scw  * modification, are permitted provided that the following conditions
     43   1.1      scw  * are met:
     44   1.1      scw  * 1. Redistributions of source code must retain the above copyright
     45   1.1      scw  *    notice, this list of conditions and the following disclaimer.
     46   1.1      scw  * 2. Redistributions in binary form must reproduce the above copyright
     47   1.1      scw  *    notice, this list of conditions and the following disclaimer in the
     48   1.1      scw  *    documentation and/or other materials provided with the distribution.
     49   1.1      scw  * 3. All advertising materials mentioning features or use of this software
     50   1.1      scw  *    must display the following acknowledgement:
     51   1.1      scw  *      This product includes software developed by Christopher G. Demetriou
     52   1.1      scw  *	for the NetBSD Project.
     53   1.1      scw  * 4. The name of the author may not be used to endorse or promote products
     54   1.1      scw  *    derived from this software without specific prior written permission
     55   1.1      scw  *
     56   1.1      scw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     57   1.1      scw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     58   1.1      scw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59   1.1      scw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     60   1.1      scw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     61   1.1      scw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     62   1.1      scw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     63   1.1      scw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     64   1.1      scw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     65   1.1      scw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     66   1.1      scw  */
     67   1.3    lukem 
     68   1.3    lukem #include <sys/cdefs.h>
     69  1.15  thorpej __KERNEL_RCSID(0, "$NetBSD: pbus.c,v 1.15 2021/08/07 16:18:52 thorpej Exp $");
     70   1.1      scw 
     71   1.1      scw #include "locators.h"
     72   1.1      scw #include "pckbc.h"
     73   1.1      scw 
     74   1.1      scw #include <sys/param.h>
     75   1.1      scw #include <sys/systm.h>
     76   1.1      scw #include <sys/device.h>
     77   1.1      scw 
     78  1.13   dyoung #include <sys/bus.h>
     79   1.1      scw #include <machine/walnut.h>
     80   1.1      scw 
     81   1.1      scw #include <evbppc/walnut/dev/pbusvar.h>
     82   1.1      scw 
     83   1.1      scw #include <powerpc/ibm4xx/ibm405gp.h>
     84   1.1      scw #include <powerpc/ibm4xx/dev/plbvar.h>
     85   1.1      scw 
     86   1.1      scw /*
     87   1.4   simonb  * The external devices on the Walnut 405GP evaluation board.
     88   1.1      scw  */
     89   1.1      scw const struct pbus_dev {
     90   1.1      scw 	const char *name;
     91   1.1      scw 	bus_addr_t addr;
     92   1.1      scw 	int irq;
     93   1.1      scw } pbus_devs [] = {
     94   1.6   simonb 	{ "ds1743rtc",	NVRAM_BASE,	-1 },
     95   1.1      scw 	{ "pckbc",	KEY_MOUSE_BASE,	25 }, /* XXX: really irq x..x+1 */
     96   1.1      scw 	{ NULL }
     97   1.1      scw };
     98   1.1      scw 
     99  1.11     matt static int	pbus_match(device_t, cfdata_t, void *);
    100  1.11     matt static void	pbus_attach(device_t, device_t, void *);
    101   1.1      scw static int	pbus_print(void *, const char *);
    102   1.1      scw 
    103  1.11     matt CFATTACH_DECL_NEW(pbus, 0,
    104   1.1      scw     pbus_match, pbus_attach, NULL, NULL);
    105   1.1      scw 
    106   1.5      scw static struct powerpc_bus_space pbus_tag = {
    107   1.5      scw 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
    108   1.5      scw 	0x00000000,
    109   1.5      scw 	NVRAM_BASE,
    110   1.5      scw 	NVRAM_BASE + 0x0300010	/* Cover from NVRAM_BASE -> FPGA_BASE */
    111   1.5      scw };
    112   1.5      scw 
    113   1.1      scw /*
    114   1.1      scw  * Probe for the peripheral bus.
    115   1.1      scw  */
    116   1.1      scw static int
    117  1.11     matt pbus_match(device_t parent, cfdata_t cf, void *aux)
    118   1.1      scw {
    119   1.1      scw 	struct pbus_attach_args *pba = aux;
    120   1.1      scw 
    121   1.1      scw 	/* match only pbus devices */
    122   1.1      scw 	if (strcmp(pba->pb_name, cf->cf_name) != 0)
    123   1.1      scw 		return (0);
    124   1.1      scw 
    125   1.1      scw 	return (1);
    126   1.1      scw }
    127   1.1      scw 
    128   1.1      scw /*
    129   1.1      scw  * Attach the peripheral bus.
    130   1.1      scw  */
    131   1.1      scw static void
    132  1.11     matt pbus_attach(device_t parent, device_t self, void *aux)
    133   1.1      scw {
    134   1.1      scw 	struct plb_attach_args *paa = aux;
    135   1.1      scw 	struct pbus_attach_args pba;
    136   1.1      scw 	int i;
    137   1.1      scw #if NPCKBC > 0
    138   1.1      scw 	bus_space_handle_t ioh_fpga;
    139   1.5      scw 	bus_space_tag_t iot_fpga = &pbus_tag;
    140   1.1      scw 	uint8_t fpga_reg;
    141   1.1      scw #endif
    142   1.1      scw 
    143   1.1      scw 	printf("\n");
    144   1.1      scw 
    145   1.5      scw 	if (bus_space_init(&pbus_tag, "pbus", NULL, 0))
    146   1.5      scw 		panic("pbus_attach: can't init tag");
    147   1.5      scw 
    148   1.1      scw 	for (i = 0; pbus_devs[i].name != NULL; i++) {
    149   1.1      scw 		pba.pb_name = pbus_devs[i].name;
    150   1.1      scw 		pba.pb_addr = pbus_devs[i].addr;
    151   1.1      scw 		pba.pb_irq = pbus_devs[i].irq;
    152   1.5      scw 		pba.pb_bt = &pbus_tag;
    153   1.1      scw 		pba.pb_dmat = paa->plb_dmat;
    154   1.1      scw 
    155  1.12    cliff 		const int locs[PBUSCF_NLOCS] = {
    156  1.12    cliff 		    [PBUSCF_ADDR] = pba.pb_addr,
    157  1.12    cliff 		    [PBUSCF_IRQ] = pba.pb_irq
    158  1.12    cliff 		};
    159  1.12    cliff 
    160  1.14  thorpej 		config_found(self, &pba, pbus_print,
    161  1.15  thorpej 		    CFARGS(.submatch = config_stdsubmatch,
    162  1.15  thorpej 			   .locators = locs));
    163   1.1      scw 	}
    164   1.1      scw 
    165   1.1      scw #if NPCKBC > 0
    166   1.1      scw 	/* Configure FPGA */
    167   1.1      scw 	if (bus_space_map(iot_fpga, FPGA_BASE, FPGA_SIZE, 0, &ioh_fpga)) {
    168   1.1      scw 		printf("pbus_attach: can't map FPGA\n");
    169   1.1      scw 		/* XXX - disable keyboard probe? */
    170   1.1      scw 	} else {
    171   1.1      scw 		/* Use separate interrupts for keyboard and mouse */
    172   1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_BRDC);
    173   1.1      scw 		fpga_reg |= FPGA_BRDC_INT;
    174   1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_BRDC, fpga_reg);
    175   1.1      scw 
    176   1.1      scw 		/* Set interrupts to active high */
    177   1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_POL);
    178   1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    179   1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_POL, fpga_reg);
    180   1.1      scw 
    181   1.1      scw 		/* Set interrupts to level triggered */
    182   1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG);
    183   1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    184   1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG, fpga_reg);
    185   1.1      scw 
    186   1.1      scw 		/* Enable interrupts */
    187   1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE);
    188   1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    189   1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE, fpga_reg);
    190   1.1      scw 
    191   1.1      scw 		bus_space_unmap(&iot_fpga, ioh_fpga, 2);
    192   1.1      scw 	}
    193   1.1      scw #endif
    194   1.1      scw 
    195   1.1      scw }
    196   1.1      scw 
    197   1.1      scw static int
    198   1.1      scw pbus_print(void *aux, const char *pnp)
    199   1.1      scw {
    200   1.1      scw 	struct pbus_attach_args *pba = aux;
    201   1.1      scw 
    202   1.1      scw 	if (pnp)
    203   1.1      scw 		printf("%s at %s", pba->pb_name, pnp);
    204   1.1      scw 
    205   1.1      scw 	if (pba->pb_addr != PBUSCF_ADDR_DEFAULT)
    206   1.2  thorpej 		aprint_normal(" addr 0x%08lx", pba->pb_addr);
    207   1.1      scw 	if (pba->pb_irq != PBUSCF_IRQ_DEFAULT)
    208   1.2  thorpej 		aprint_normal(" irq %d", pba->pb_irq);
    209   1.1      scw 
    210   1.1      scw 	return (UNCONF);
    211   1.1      scw }
    212