Home | History | Annotate | Line # | Download | only in sa11x0
sa11x0.c revision 1.1
      1 /*	$NetBSD: sa11x0.c,v 1.1 2001/07/08 23:37:52 rjs Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001, The NetBSD Foundation, Inc.  All rights reserved.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
      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 by the NetBSD
     20  *      Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  */
     25 /*-
     26  * Copyright (c) 1999
     27  *         Shin Takemura and PocketBSD Project. All rights reserved.
     28  *
     29  * Redistribution and use in source and binary forms, with or without
     30  * modification, are permitted provided that the following conditions
     31  * are met:
     32  * 1. Redistributions of source code must retain the above copyright
     33  *    notice, this list of conditions and the following disclaimer.
     34  * 2. Redistributions in binary form must reproduce the above copyright
     35  *    notice, this list of conditions and the following disclaimer in the
     36  *    documentation and/or other materials provided with the distribution.
     37  * 3. All advertising materials mentioning features or use of this software
     38  *    must display the following acknowledgement:
     39  *	This product includes software developed by the PocketBSD project
     40  *	and its contributors.
     41  * 4. Neither the name of the project nor the names of its contributors
     42  *    may be used to endorse or promote products derived from this software
     43  *    without specific prior written permission.
     44  *
     45  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55  * SUCH DAMAGE.
     56  *
     57  */
     58 #include <sys/param.h>
     59 #include <sys/systm.h>
     60 #include <sys/device.h>
     61 #include <sys/kernel.h>
     62 #include <sys/reboot.h>
     63 
     64 #include <machine/cpu.h>
     65 #include <machine/bus.h>
     66 
     67 #include <arm/mainbus/mainbus.h>
     68 #include <arm/sa11x0/sa11x0_reg.h>
     69 #include <arm/sa11x0/sa11x0_var.h>
     70 #include <arm/sa11x0/sa11x0_dmacreg.h>
     71 #include <arm/sa11x0/sa11x0_ppcreg.h>
     72 #include <arm/sa11x0/sa11x0_gpioreg.h>
     73 
     74 #ifdef hpcarm
     75 #include <hpc/hpc/config_hook.h>
     76 #include <hpc/hpc/platid.h>
     77 #include <hpc/include/platid_mask.h>
     78 #endif
     79 
     80 #include "locators.h"
     81 
     82 /* prototypes */
     83 static int	sa11x0_match(struct device *, struct cfdata *, void *);
     84 static void	sa11x0_attach(struct device *, struct device *, void *);
     85 static int 	sa11x0_search(struct device *, struct cfdata *, void *);
     86 static int	sa11x0_print(void *, const char *);
     87 
     88 /* attach structures */
     89 struct cfattach saip_ca = {
     90 	sizeof(struct sa11x0_softc), sa11x0_match, sa11x0_attach
     91 };
     92 
     93 extern struct bus_space sa11x0_bs_tag;
     94 extern vaddr_t saipic_base;
     95 
     96 extern int SetCPSR(int, int);
     97 
     98 /*
     99  * int sa11x0_print(void *aux, const char *name)
    100  * print configuration info for children
    101  */
    102 
    103 static int
    104 sa11x0_print(aux, name)
    105 	void *aux;
    106 	const char *name;
    107 {
    108 	struct sa11x0_attach_args *sa = (struct sa11x0_attach_args*)aux;
    109 
    110 	if (sa->sa_size)
    111                 printf(" addr 0x%lx", sa->sa_addr);
    112         if (sa->sa_size > 1)
    113                 printf("-0x%lx", sa->sa_addr + sa->sa_size - 1);
    114 	if (sa->sa_memsize)
    115 		printf(" membase 0x%lx", sa->sa_membase);
    116 	if (sa->sa_memsize > 1)
    117 		printf("-0x%lx", sa->sa_membase + sa->sa_memsize - 1);
    118         if (sa->sa_intr > 1)
    119                 printf(" intr %d", sa->sa_intr);
    120 	if (sa->sa_gpio != -1)
    121 		printf(" gpio %d", sa->sa_gpio);
    122 
    123         return (UNCONF);
    124 }
    125 
    126 int
    127 sa11x0_match(parent, match, aux)
    128 	struct device *parent;
    129 	struct cfdata *match;
    130 	void *aux;
    131 {
    132 	return 1;
    133 }
    134 
    135 void
    136 sa11x0_attach(parent, self, aux)
    137 	struct device *parent;
    138 	struct device *self;
    139 	void *aux;
    140 {
    141 	struct sa11x0_softc *sc = (struct sa11x0_softc*)self;
    142 
    143 	sc->sc_iot = &sa11x0_bs_tag;
    144 
    145 	/* Map the SAIP */
    146 	if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
    147 			0, &sc->sc_ioh))
    148 		panic("%s: Cannot map registers\n", self->dv_xname);
    149 	saipic_base = sc->sc_ioh;
    150 
    151 	/* Map the GPIO registers */
    152 	if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
    153 			  0, &sc->sc_gpioh))
    154 		panic("%s: unable to map GPIO registers\n", self->dv_xname);
    155 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
    156 
    157 #ifdef SAEGPIO_BASE
    158 	/* Map the iPAQ Extended GPIO registers */
    159 	if (bus_space_map(sc->sc_iot, SAEGPIO_BASE, 1, 0, &sc->sc_egpioh))
    160 		panic("%s: unable to map Extended GPIO registers\n",
    161 			self->dv_xname);
    162 # if 0
    163 	bus_space_write_2(sc->sc_iot, sc->sc_egpioh, 0, EGPIO_INIT);
    164 # endif
    165 #endif
    166 
    167 	/* Map the PPC registers */
    168 	if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
    169 			  0, &sc->sc_ppch))
    170 		panic("%s: unable to map PPC registers\n", self->dv_xname);
    171 
    172 	/* Map the DMA controller registers */
    173 	if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
    174 			  0, &sc->sc_dmach))
    175 		panic("%s: unable to map DMAC registers\n", self->dv_xname);
    176 
    177 	printf("\n");
    178 
    179 	/*
    180 	 *  Mask all interrupts.
    181 	 *  They are later unmasked at each device's attach routine.
    182 	 */
    183 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
    184 
    185 	/* Route all bits to IRQ */
    186 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
    187 
    188 	/* Exit idle mode only when unmasked intr is received */
    189 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
    190 
    191 	/* disable all DMAC channels */
    192 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
    193 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
    194 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
    195 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
    196 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
    197 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
    198 
    199 	/*
    200 	 * XXX this is probably a bad place, but intr bit shouldn't be
    201 	 * XXX enabled before intr mask is set.
    202 	 * XXX Having sane imask[] suffice??
    203 	 */
    204 	SetCPSR(I32_bit, 0);
    205 
    206 	/*
    207 	 *  Attach each devices
    208 	 */
    209 	config_search(sa11x0_search, self, NULL);
    210 }
    211 
    212 int
    213 sa11x0_search(parent, cf, aux)
    214 	struct device *parent;
    215 	struct cfdata *cf;
    216 	void *aux;
    217 {
    218 	struct sa11x0_softc *sc = (struct sa11x0_softc *)parent;
    219 	struct sa11x0_attach_args sa;
    220 
    221 	sa.sa_sc = sc;
    222         sa.sa_iot = sc->sc_iot;
    223         sa.sa_addr = cf->cf_loc[SAIPCF_ADDR];
    224         sa.sa_size = cf->cf_loc[SAIPCF_SIZE];
    225 	sa.sa_membase = cf->cf_loc[SAIPCF_MEMBASE];
    226         sa.sa_memsize = cf->cf_loc[SAIPCF_MEMSIZE];
    227         sa.sa_intr = cf->cf_loc[SAIPCF_INTR];
    228 	sa.sa_gpio = cf->cf_loc[SAIPCF_GPIO];
    229 
    230         if ((*cf->cf_attach->ca_match)(parent, cf, &sa) > 0)
    231                 config_attach(parent, cf, &sa, sa11x0_print);
    232 
    233         return 0;
    234 }
    235