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