Home | History | Annotate | Line # | Download | only in dev
pbus.c revision 1.6
      1  1.6   simonb /*	$NetBSD: pbus.c,v 1.6 2003/10/10 07:01:50 simonb 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.6   simonb __KERNEL_RCSID(0, "$NetBSD: pbus.c,v 1.6 2003/10/10 07:01:50 simonb 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.1      scw #include <machine/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.1      scw static int	pbus_match(struct device *, struct cfdata *, void *);
    100  1.1      scw static void	pbus_attach(struct device *, struct device *, void *);
    101  1.1      scw static int	pbus_submatch(struct device *, struct cfdata *, void *);
    102  1.1      scw static int	pbus_print(void *, const char *);
    103  1.1      scw 
    104  1.1      scw CFATTACH_DECL(pbus, sizeof(struct device),
    105  1.1      scw     pbus_match, pbus_attach, NULL, NULL);
    106  1.1      scw 
    107  1.5      scw static struct powerpc_bus_space pbus_tag = {
    108  1.5      scw 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
    109  1.5      scw 	0x00000000,
    110  1.5      scw 	NVRAM_BASE,
    111  1.5      scw 	NVRAM_BASE + 0x0300010	/* Cover from NVRAM_BASE -> FPGA_BASE */
    112  1.5      scw };
    113  1.5      scw 
    114  1.1      scw /*
    115  1.1      scw  * Probe for the peripheral bus.
    116  1.1      scw  */
    117  1.1      scw static int
    118  1.1      scw pbus_match(struct device *parent, struct cfdata *cf, void *aux)
    119  1.1      scw {
    120  1.1      scw 	struct pbus_attach_args *pba = aux;
    121  1.1      scw 
    122  1.1      scw 	/* match only pbus devices */
    123  1.1      scw 	if (strcmp(pba->pb_name, cf->cf_name) != 0)
    124  1.1      scw 		return (0);
    125  1.1      scw 
    126  1.1      scw 	return (1);
    127  1.1      scw }
    128  1.1      scw 
    129  1.1      scw static int
    130  1.1      scw pbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
    131  1.1      scw {
    132  1.1      scw 	struct pbus_attach_args *pba = aux;
    133  1.1      scw 
    134  1.1      scw 	if (cf->cf_loc[PBUSCF_ADDR] != PBUSCF_ADDR_DEFAULT &&
    135  1.1      scw 	    cf->cf_loc[PBUSCF_ADDR] != pba->pb_addr)
    136  1.1      scw 		return (0);
    137  1.1      scw 
    138  1.1      scw 	return (config_match(parent, cf, aux));
    139  1.1      scw }
    140  1.1      scw 
    141  1.1      scw /*
    142  1.1      scw  * Attach the peripheral bus.
    143  1.1      scw  */
    144  1.1      scw static void
    145  1.1      scw pbus_attach(struct device *parent, struct device *self, void *aux)
    146  1.1      scw {
    147  1.1      scw 	struct plb_attach_args *paa = aux;
    148  1.1      scw 	struct pbus_attach_args pba;
    149  1.1      scw 	int i;
    150  1.1      scw #if NPCKBC > 0
    151  1.1      scw 	bus_space_handle_t ioh_fpga;
    152  1.5      scw 	bus_space_tag_t iot_fpga = &pbus_tag;
    153  1.1      scw 	uint8_t fpga_reg;
    154  1.1      scw #endif
    155  1.1      scw 
    156  1.1      scw 	printf("\n");
    157  1.1      scw 
    158  1.5      scw 	if (bus_space_init(&pbus_tag, "pbus", NULL, 0))
    159  1.5      scw 		panic("pbus_attach: can't init tag");
    160  1.5      scw 
    161  1.1      scw 	for (i = 0; pbus_devs[i].name != NULL; i++) {
    162  1.1      scw 		pba.pb_name = pbus_devs[i].name;
    163  1.1      scw 		pba.pb_addr = pbus_devs[i].addr;
    164  1.1      scw 		pba.pb_irq = pbus_devs[i].irq;
    165  1.5      scw 		pba.pb_bt = &pbus_tag;
    166  1.1      scw 		pba.pb_dmat = paa->plb_dmat;
    167  1.1      scw 
    168  1.1      scw 		(void) config_found_sm(self, &pba, pbus_print, pbus_submatch);
    169  1.1      scw 	}
    170  1.1      scw 
    171  1.1      scw #if NPCKBC > 0
    172  1.1      scw 	/* Configure FPGA */
    173  1.1      scw 	if (bus_space_map(iot_fpga, FPGA_BASE, FPGA_SIZE, 0, &ioh_fpga)) {
    174  1.1      scw 		printf("pbus_attach: can't map FPGA\n");
    175  1.1      scw 		/* XXX - disable keyboard probe? */
    176  1.1      scw 	} else {
    177  1.1      scw 		/* Use separate interrupts for keyboard and mouse */
    178  1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_BRDC);
    179  1.1      scw 		fpga_reg |= FPGA_BRDC_INT;
    180  1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_BRDC, fpga_reg);
    181  1.1      scw 
    182  1.1      scw 		/* Set interrupts to active high */
    183  1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_POL);
    184  1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    185  1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_POL, fpga_reg);
    186  1.1      scw 
    187  1.1      scw 		/* Set interrupts to level triggered */
    188  1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG);
    189  1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    190  1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_TRIG, fpga_reg);
    191  1.1      scw 
    192  1.1      scw 		/* Enable interrupts */
    193  1.1      scw 		fpga_reg = bus_space_read_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE);
    194  1.1      scw 		fpga_reg |= (FPGA_IRQ_KYBD | FPGA_IRQ_MOUSE);
    195  1.1      scw 		bus_space_write_1(iot_fpga, ioh_fpga, FPGA_INT_ENABLE, fpga_reg);
    196  1.1      scw 
    197  1.1      scw 		bus_space_unmap(&iot_fpga, ioh_fpga, 2);
    198  1.1      scw 	}
    199  1.1      scw #endif
    200  1.1      scw 
    201  1.1      scw }
    202  1.1      scw 
    203  1.1      scw static int
    204  1.1      scw pbus_print(void *aux, const char *pnp)
    205  1.1      scw {
    206  1.1      scw 	struct pbus_attach_args *pba = aux;
    207  1.1      scw 
    208  1.1      scw 	if (pnp)
    209  1.1      scw 		printf("%s at %s", pba->pb_name, pnp);
    210  1.1      scw 
    211  1.1      scw 	if (pba->pb_addr != PBUSCF_ADDR_DEFAULT)
    212  1.2  thorpej 		aprint_normal(" addr 0x%08lx", pba->pb_addr);
    213  1.1      scw 	if (pba->pb_irq != PBUSCF_IRQ_DEFAULT)
    214  1.2  thorpej 		aprint_normal(" irq %d", pba->pb_irq);
    215  1.1      scw 
    216  1.1      scw 	return (UNCONF);
    217  1.1      scw }
    218