Home | History | Annotate | Line # | Download | only in imx
imx31_ahb.c revision 1.1.2.2
      1 /*	$Id: imx31_ahb.c,v 1.1.2.2 2007/09/11 16:39:20 matt Exp $	*/
      2 
      3 /* derived from:	*/
      4 /*	$NetBSD: imx31_ahb.c,v 1.1.2.2 2007/09/11 16:39:20 matt Exp $ */
      5 
      6 /*
      7  * Copyright (c) 2002, 2005  Genetec Corporation.  All rights reserved.
      8  * Written by Hiroyuki Bessho for Genetec Corporation.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed for the NetBSD Project by
     21  *	Genetec Corporation.
     22  * 4. The name of Genetec Corporation may not be used to endorse or
     23  *    promote products derived from this software without specific prior
     24  *    written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  *
     38  *
     39  * Autoconfiguration support for the Intel PXA2[15]0 application
     40  * processor. This code is derived from arm/sa11x0/sa11x0.c
     41  */
     42 
     43 /*-
     44  * Copyright (c) 2001, The NetBSD Foundation, Inc.  All rights reserved.
     45  *
     46  * This code is derived from software contributed to The NetBSD Foundation
     47  * by IWAMOTO Toshihiro and Ichiro FUKUHARA.
     48  *
     49  * Redistribution and use in source and binary forms, with or without
     50  * modification, are permitted provided that the following conditions
     51  * are met:
     52  * 1. Redistributions of source code must retain the above copyright
     53  *    notice, this list of conditions and the following disclaimer.
     54  * 2. Redistributions in binary form must reproduce the above copyright
     55  *    notice, this list of conditions and the following disclaimer in the
     56  *    documentation and/or other materials provided with the distribution.
     57  * 3. All advertising materials mentioning features or use of this software
     58  *    must display the following acknowledgement:
     59  *      This product includes software developed by the NetBSD
     60  *      Foundation, Inc. and its contributors.
     61  * 4. Neither the name of The NetBSD Foundation nor the names of its
     62  *    contributors may be used to endorse or promote products derived
     63  *    from this software without specific prior written permission.
     64  */
     65 /*-
     66  * Copyright (c) 1999
     67  *         Shin Takemura and PocketBSD Project. All rights reserved.
     68  *
     69  * Redistribution and use in source and binary forms, with or without
     70  * modification, are permitted provided that the following conditions
     71  * are met:
     72  * 1. Redistributions of source code must retain the above copyright
     73  *    notice, this list of conditions and the following disclaimer.
     74  * 2. Redistributions in binary form must reproduce the above copyright
     75  *    notice, this list of conditions and the following disclaimer in the
     76  *    documentation and/or other materials provided with the distribution.
     77  * 3. All advertising materials mentioning features or use of this software
     78  *    must display the following acknowledgement:
     79  *	This product includes software developed by the PocketBSD project
     80  *	and its contributors.
     81  * 4. Neither the name of the project nor the names of its contributors
     82  *    may be used to endorse or promote products derived from this software
     83  *    without specific prior written permission.
     84  *
     85  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     86  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     87  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     88  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     89  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     90  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     91  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     92  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     93  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     94  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     95  * SUCH DAMAGE.
     96  *
     97  */
     98 
     99 #include <sys/cdefs.h>
    100 __KERNEL_RCSID(0, "$Id: imx31_ahb.c,v 1.1.2.2 2007/09/11 16:39:20 matt Exp $");
    101 
    102 #include "locators.h"
    103 #include "avic.h"
    104 #include "imxgpio.h"
    105 
    106 #include <sys/param.h>
    107 #include <sys/systm.h>
    108 #include <sys/device.h>
    109 #include <sys/kernel.h>
    110 #include <sys/reboot.h>
    111 
    112 #include <machine/cpu.h>
    113 #include <machine/bus.h>
    114 
    115 #include <arm/cpufunc.h>
    116 #include <arm/mainbus/mainbus.h>
    117 
    118 #include <machine/intr.h>
    119 
    120 #include <arm/imx/imx31reg.h>
    121 #include <arm/imx/imx31var.h>
    122 
    123 struct ahb_softc {
    124 	struct device sc_dev;
    125 	bus_dma_tag_t sc_dmat;
    126 	bus_space_tag_t sc_memt;
    127 	bus_space_handle_t sc_memh;
    128 };
    129 
    130 /* prototypes */
    131 static int	ahb_match(device_t, cfdata_t, void *);
    132 static void	ahb_attach(device_t, device_t, void *);
    133 static int 	ahb_search(device_t, cfdata_t, const int *, void *);
    134 static void	ahb_attach_critical(struct ahb_softc *);
    135 static int	ahbbus_print(void *, const char *);
    136 
    137 /* attach structures */
    138 CFATTACH_DECL(ahb, sizeof(struct ahb_softc),
    139     ahb_match, ahb_attach, NULL, NULL);
    140 
    141 static struct ahb_softc *ahb_sc;
    142 
    143 static int
    144 ahb_match(device_t parent, cfdata_t match, void *aux)
    145 {
    146 	return 1;
    147 }
    148 
    149 static void
    150 ahb_attach(device_t parent, device_t self, void *aux)
    151 {
    152 	struct ahb_softc *sc = (struct ahb_softc *)self;
    153 	extern struct bus_space imx31_bs_tag;
    154 	struct ahb_attach_args ahba;
    155 
    156 	ahb_sc = sc;
    157 	sc->sc_memt = &imx31_bs_tag;
    158 #if NBUS_DMA_GENERIC > 0
    159 	sc->sc_dmat = &imx31_bus_dma_tag;
    160 #else
    161 	sc->sc_dmat = 0;
    162 #endif
    163 
    164 	aprint_normal(": AHB-Lite 2.v6 bus interface\n");
    165 
    166 	/*
    167 	 * Attach critical devices
    168 	 */
    169 	ahb_attach_critical(sc);
    170 
    171 	/*
    172 	 * Attach all other devices
    173 	 */
    174 	ahba.ahba_name = "ahb";
    175 	ahba.ahba_memt = sc->sc_memt;
    176 	ahba.ahba_dmat = sc->sc_dmat;
    177 	config_search_ia(ahb_search, self, "ahb", &ahba);
    178 }
    179 
    180 static int
    181 ahb_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    182 {
    183 	struct ahb_attach_args * const ahba = aux;
    184 
    185 	ahba->ahba_addr = cf->cf_loc[AHBCF_ADDR];
    186 	ahba->ahba_size = cf->cf_loc[AHBCF_SIZE];
    187 	ahba->ahba_intr = cf->cf_loc[AHBCF_INTR];
    188 	ahba->ahba_irqbase = cf->cf_loc[AHBCF_IRQBASE];
    189 
    190 	if (config_match(parent, cf, ahba))
    191 		config_attach(parent, cf, ahba, ahbbus_print);
    192 
    193 	return 0;
    194 }
    195 
    196 static void
    197 ahb_attach_critical(struct ahb_softc *sc)
    198 {
    199 	struct ahb_attach_args ahba;
    200 
    201 	ahba.ahba_name = "ahb";
    202 	ahba.ahba_memt = sc->sc_memt;
    203 	ahba.ahba_dmat = sc->sc_dmat;
    204 
    205 #if NAVIC == 0
    206 #error no avic present in config file
    207 #endif
    208 	ahba.ahba_addr = INTC_BASE;
    209 	ahba.ahba_size = INTC_SIZE;
    210 	ahba.ahba_intr = AHBCF_INTR_DEFAULT;
    211 	ahba.ahba_irqbase = AHBCF_IRQBASE_DEFAULT;
    212 	if (config_found(&sc->sc_dev, &ahba, ahbbus_print) == NULL)
    213 		panic("ahb_attach_critical: failed to attach INTC!");
    214 
    215 #if NIMXGPIO == 0
    216 #error no imxgpio present in config file
    217 #endif
    218 #if NIMXGPIO > 0
    219 	ahba.ahba_addr = GPIO1_BASE;
    220 	ahba.ahba_size = GPIO_SIZE;
    221 	ahba.ahba_intr = IRQ_GPIO1;
    222 	ahba.ahba_irqbase = AHBCF_IRQBASE_DEFAULT;
    223 	if (config_found(&sc->sc_dev, &ahba, ahbbus_print) == NULL)
    224 		panic("ahb_attach_critical: failed to attach GPIO0!");
    225 #endif
    226 
    227 #if NIMXDMAC > 0
    228 	ahba.ahba_addr = IMX31_DMAC_BASE;
    229 	ahba.ahba_size = IMX31_DMAC_SIZE;
    230 	ahba.ahba_intr = IMX31_INT_DMA;
    231 	ahba.ahba_irqbase = AHBCF_IRQBASE_DEFAULT;
    232 	if (config_found(&sc->sc_dev, &ahba, ahbbus_print) == NULL)
    233 		panic("ahb_attach_critical: failed to attach DMAC!");
    234 #endif
    235 }
    236 
    237 static int
    238 ahbbus_print(void *aux, const char *name)
    239 {
    240 	struct ahb_attach_args *ahba = (struct ahb_attach_args*)aux;
    241 
    242 	if (ahba->ahba_addr != AHBCF_ADDR_DEFAULT) {
    243 		aprint_normal(" addr 0x%lx", ahba->ahba_addr);
    244 		if (ahba->ahba_size > AHBCF_SIZE_DEFAULT)
    245 			aprint_normal("-0x%lx",
    246 			    ahba->ahba_addr + ahba->ahba_size-1);
    247 	}
    248 	if (ahba->ahba_intr != AHBCF_INTR_DEFAULT)
    249 		aprint_normal(" intr %d", ahba->ahba_intr);
    250 	if (ahba->ahba_intr != AHBCF_IRQBASE_DEFAULT)
    251 		aprint_normal(" irqbase %d", ahba->ahba_irqbase);
    252 
    253 	return (UNCONF);
    254 }
    255 
    256 static inline uint32_t
    257 read_clock_counter_xsc1(void)
    258 {
    259 	uint32_t x;
    260 	__asm volatile("mrc	p14, 0, %0, c1, c0, 0" : "=r" (x) );
    261 
    262 	return x;
    263 }
    264 
    265 static inline uint32_t
    266 read_clock_counter_xsc2(void)
    267 {
    268 	uint32_t x;
    269 	__asm volatile("mrc	p14, 0, %0, c1, c1, 0" : "=r" (x) );
    270 
    271 	return x;
    272 }
    273 
    274