Home | History | Annotate | Line # | Download | only in sa11x0
      1 /*	$NetBSD: sa11x0.c,v 1.29 2021/08/07 16:18:45 thorpej 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.29 2021/08/07 16:18:45 thorpej 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 <sys/bus.h>
     77 
     78 #include <arm/arm32/psl.h>
     79 #include <arm/arm32/machdep.h>
     80 #include <arm/mainbus/mainbus.h>
     81 #include <arm/sa11x0/sa11x0_reg.h>
     82 #include <arm/sa11x0/sa11x0_var.h>
     83 #include <arm/sa11x0/sa11x0_dmacreg.h>
     84 #include <arm/sa11x0/sa11x0_ppcreg.h>
     85 #include <arm/sa11x0/sa11x0_gpioreg.h>
     86 
     87 #include "locators.h"
     88 
     89 /* prototypes */
     90 static int	sa11x0_match(device_t, cfdata_t, void *);
     91 static void	sa11x0_attach(device_t, device_t, void *);
     92 static int 	sa11x0_search(device_t, cfdata_t, const int *, void *);
     93 static int	sa11x0_print(void *, const char *);
     94 
     95 /* attach structures */
     96 CFATTACH_DECL_NEW(saip, sizeof(struct sa11x0_softc),
     97     sa11x0_match, sa11x0_attach, NULL, NULL);
     98 
     99 extern struct bus_space sa11x0_bs_tag;
    100 extern vaddr_t saipic_base;
    101 
    102 /*
    103  * int sa11x0_print(void *aux, const char *name)
    104  * print configuration info for children
    105  */
    106 
    107 static int
    108 sa11x0_print(void *aux, const char *name)
    109 {
    110 	struct sa11x0_attach_args *sa = (struct sa11x0_attach_args*)aux;
    111 
    112 	if (sa->sa_size)
    113                 aprint_normal(" addr 0x%lx", sa->sa_addr);
    114         if (sa->sa_size > 1)
    115                 aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
    116         if (sa->sa_intr > 1)
    117                 aprint_normal(" intr %d", sa->sa_intr);
    118 	if (sa->sa_gpio != -1)
    119 		aprint_normal(" gpio %d", sa->sa_gpio);
    120 
    121         return UNCONF;
    122 }
    123 
    124 int
    125 sa11x0_match(device_t parent, cfdata_t match, void *aux)
    126 {
    127 
    128 	return 1;
    129 }
    130 
    131 void
    132 sa11x0_attach(device_t parent, device_t self, void *aux)
    133 {
    134 	struct sa11x0_softc *sc = device_private(self);
    135 
    136 	sc->sc_dev = self;
    137 	sc->sc_iot = &sa11x0_bs_tag;
    138 
    139 	/* Map the SAIP */
    140 	if (bus_space_map(sc->sc_iot, SAIPIC_BASE, SAIPIC_NPORTS,
    141 			0, &sc->sc_ioh))
    142 		panic("%s: Cannot map registers", device_xname(self));
    143 	saipic_base = sc->sc_ioh;
    144 
    145 	/* Map the GPIO registers */
    146 	if (bus_space_map(sc->sc_iot, SAGPIO_BASE, SAGPIO_NPORTS,
    147 			  0, &sc->sc_gpioh))
    148 		panic("%s: unable to map GPIO registers", device_xname(self));
    149 	bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_EDR, 0xffffffff);
    150 
    151 	/* Map the PPC registers */
    152 	if (bus_space_map(sc->sc_iot, SAPPC_BASE, SAPPC_NPORTS,
    153 			  0, &sc->sc_ppch))
    154 		panic("%s: unable to map PPC registers", device_xname(self));
    155 
    156 	/* Map the DMA controller registers */
    157 	if (bus_space_map(sc->sc_iot, SADMAC_BASE, SADMAC_NPORTS,
    158 			  0, &sc->sc_dmach))
    159 		panic("%s: unable to map DMAC registers", device_xname(self));
    160 
    161 	/* Map the reset controller registers */
    162 	if (bus_space_map(sc->sc_iot, SARCR_BASE, PAGE_SIZE,
    163 			  0, &sc->sc_reseth))
    164 		panic("%s: unable to map reset registers", device_xname(self));
    165 
    166 	printf("\n");
    167 
    168 	/*
    169 	 *  Mask all interrupts.
    170 	 *  They are later unmasked at each device's attach routine.
    171 	 */
    172 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_MR, 0);
    173 
    174 	/* Route all bits to IRQ */
    175 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_LR, 0);
    176 
    177 	/* Exit idle mode only when unmasked intr is received */
    178 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, SAIPIC_CR, 1);
    179 
    180 	/* disable all DMAC channels */
    181 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR0_CLR, 1);
    182 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR1_CLR, 1);
    183 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR2_CLR, 1);
    184 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR3_CLR, 1);
    185 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR4_CLR, 1);
    186 	bus_space_write_4(sc->sc_iot, sc->sc_dmach, SADMAC_DCR5_CLR, 1);
    187 
    188 	/* Make sure to init spl masks, note we set the mask to 0 above */
    189 	set_spl_masks();
    190 
    191 	SetCPSR(I32_bit, 0);
    192 
    193 	/*
    194 	 *  Attach each devices
    195 	 */
    196 	config_search(self, NULL,
    197 	    CFARGS(.search = sa11x0_search));
    198 }
    199 
    200 int
    201 sa11x0_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    202 {
    203 	struct sa11x0_softc *sc = device_private(parent);
    204 	struct sa11x0_attach_args sa;
    205 
    206 	sa.sa_sc = sc;
    207 	sa.sa_iot = sc->sc_iot;
    208 	sa.sa_name = cf->cf_name;
    209 	sa.sa_addr = cf->cf_loc[SAIPCF_ADDR];
    210 	sa.sa_size = cf->cf_loc[SAIPCF_SIZE];
    211 	sa.sa_intr = cf->cf_loc[SAIPCF_INTR];
    212 	sa.sa_gpio = cf->cf_loc[SAIPCF_GPIO];
    213 
    214         if (config_probe(parent, cf, &sa))
    215                 config_attach(parent, cf, &sa, sa11x0_print, CFARGS_NONE);
    216 
    217         return 0;
    218 }
    219