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