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