Home | History | Annotate | Line # | Download | only in imx
imx51_axi.c revision 1.2.10.1
      1  1.2.10.1  yamt /*	$NetBSD: imx51_axi.c,v 1.2.10.1 2012/05/23 10:07:41 yamt Exp $	*/
      2       1.1   bsh 
      3       1.1   bsh /*-
      4       1.1   bsh  * Copyright (c) 2010 SHIMIZU Ryo <ryo (at) nerv.org>
      5       1.1   bsh  * All rights reserved.
      6       1.1   bsh  *
      7       1.1   bsh  * Redistribution and use in source and binary forms, with or without
      8       1.1   bsh  * modification, are permitted provided that the following conditions
      9       1.1   bsh  * are met:
     10       1.1   bsh  * 1. Redistributions of source code must retain the above copyright
     11       1.1   bsh  *    notice, this list of conditions and the following disclaimer.
     12       1.1   bsh  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   bsh  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   bsh  *    documentation and/or other materials provided with the distribution.
     15       1.1   bsh  *
     16       1.1   bsh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1   bsh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18       1.1   bsh  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19       1.1   bsh  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20       1.1   bsh  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21       1.1   bsh  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22       1.1   bsh  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23       1.1   bsh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24       1.1   bsh  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25       1.1   bsh  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1   bsh  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1   bsh  */
     28       1.1   bsh 
     29       1.1   bsh #include <sys/cdefs.h>
     30  1.2.10.1  yamt __KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.2.10.1 2012/05/23 10:07:41 yamt Exp $");
     31       1.1   bsh 
     32       1.1   bsh #include <sys/param.h>
     33       1.1   bsh #include <sys/bus.h>
     34       1.1   bsh #include <sys/device.h>
     35       1.1   bsh 
     36       1.1   bsh #include <uvm/uvm_extern.h>
     37       1.1   bsh 
     38       1.1   bsh #include <arm/imx/imx51reg.h>
     39       1.1   bsh #include <arm/imx/imx51var.h>
     40       1.1   bsh 
     41  1.2.10.1  yamt #include "bus_dma_generic.h"
     42       1.1   bsh #include "locators.h"
     43       1.1   bsh 
     44       1.1   bsh struct axi_softc {
     45       1.1   bsh 	device_t sc_dev;
     46       1.1   bsh 	bus_space_tag_t sc_iot;
     47       1.1   bsh 	bus_dma_tag_t sc_dmat;
     48       1.1   bsh };
     49       1.1   bsh 
     50       1.1   bsh static int axi_match(device_t, struct cfdata *, void *);
     51       1.1   bsh static void axi_attach(device_t, device_t, void *);
     52       1.1   bsh static int axi_search(device_t, struct cfdata *, const int *, void *);
     53       1.1   bsh static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
     54       1.1   bsh static int axi_search(device_t, struct cfdata *, const int *, void *);
     55       1.1   bsh static int axi_print(void *, const char *);
     56       1.1   bsh 
     57       1.1   bsh CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
     58       1.1   bsh     axi_match, axi_attach, NULL, NULL);
     59       1.1   bsh 
     60       1.1   bsh /* ARGSUSED */
     61       1.1   bsh static int
     62       1.1   bsh axi_match(device_t parent __unused, struct cfdata *match __unused,
     63       1.1   bsh     void *aux __unused)
     64       1.1   bsh {
     65       1.1   bsh 	return 1;
     66       1.1   bsh }
     67       1.1   bsh 
     68       1.1   bsh /* ARGSUSED */
     69       1.1   bsh static void
     70       1.1   bsh axi_attach(device_t parent __unused, device_t self, void *aux __unused)
     71       1.1   bsh {
     72       1.1   bsh 	struct axi_softc *sc;
     73       1.1   bsh 	struct axi_attach_args aa;
     74       1.1   bsh 
     75       1.1   bsh 	aprint_normal(": Advanced eXtensible Interface\n");
     76       1.1   bsh 	aprint_naive("\n");
     77       1.1   bsh 
     78       1.1   bsh 	sc = device_private(self);
     79       1.1   bsh 	sc->sc_iot = &imx_bs_tag;
     80       1.1   bsh #if NBUS_DMA_GENERIC > 0
     81       1.1   bsh 	sc->sc_dmat = &imx_bus_dma_tag;
     82       1.1   bsh #else
     83       1.1   bsh 	sc->sc_dmat = 0;
     84       1.1   bsh #endif
     85       1.1   bsh 
     86       1.1   bsh 	aa.aa_name = "axi";
     87       1.1   bsh 	aa.aa_iot = sc->sc_iot;
     88       1.1   bsh 	aa.aa_dmat = sc->sc_dmat;
     89       1.1   bsh 	config_search_ia(axi_critical_search, self, "axi", &aa);
     90       1.1   bsh 	config_search_ia(axi_search, self, "axi", &aa);
     91       1.1   bsh }
     92       1.1   bsh 
     93       1.1   bsh /* ARGSUSED */
     94       1.1   bsh static int
     95       1.1   bsh axi_critical_search(device_t parent, struct cfdata *cf,
     96       1.1   bsh     const int *ldesc __unused, void *aux)
     97       1.1   bsh {
     98       1.1   bsh 	struct axi_softc *sc;
     99       1.1   bsh 	struct axi_attach_args *aa;
    100       1.1   bsh 
    101       1.1   bsh 	sc = device_private(parent);
    102       1.1   bsh 	aa = aux;
    103       1.1   bsh 
    104       1.1   bsh 	if ((strcmp(cf->cf_name, "tzic") != 0) &&
    105       1.2   bsh 	    (strcmp(cf->cf_name, "imxuart") != 0) &&
    106  1.2.10.1  yamt 	    (strcmp(cf->cf_name, "imxccm") != 0) &&
    107       1.2   bsh 	    (strcmp(cf->cf_name, "imxgpio") != 0))
    108       1.1   bsh 		return 0;
    109       1.1   bsh 
    110       1.2   bsh 	aa->aa_name = cf->cf_name;
    111       1.1   bsh 	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
    112       1.1   bsh 	aa->aa_size = cf->cf_loc[AXICF_SIZE];
    113       1.1   bsh 	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
    114       1.1   bsh 	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
    115       1.1   bsh 
    116       1.1   bsh 	if (config_match(parent, cf, aux) > 0)
    117       1.1   bsh 		config_attach(parent, cf, aux, axi_print);
    118       1.1   bsh 
    119       1.1   bsh 	return 0;
    120       1.1   bsh }
    121       1.1   bsh 
    122       1.1   bsh 
    123       1.1   bsh /* ARGSUSED */
    124       1.1   bsh static int
    125       1.1   bsh axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
    126       1.1   bsh     void *aux)
    127       1.1   bsh {
    128       1.1   bsh 	struct axi_softc *sc;
    129       1.1   bsh 	struct axi_attach_args *aa;
    130       1.1   bsh 
    131       1.1   bsh 	sc = device_private(parent);
    132       1.1   bsh 	aa = aux;
    133       1.1   bsh 
    134       1.1   bsh 	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
    135       1.1   bsh 	aa->aa_size = cf->cf_loc[AXICF_SIZE];
    136       1.1   bsh 	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
    137       1.1   bsh 	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
    138       1.1   bsh 
    139       1.1   bsh 	if (config_match(parent, cf, aux) > 0)
    140       1.1   bsh 		config_attach(parent, cf, aux, axi_print);
    141       1.1   bsh 
    142       1.1   bsh 	return 0;
    143       1.1   bsh }
    144       1.1   bsh 
    145       1.1   bsh /* ARGSUSED */
    146       1.1   bsh static int
    147       1.1   bsh axi_print(void *aux, const char *name __unused)
    148       1.1   bsh {
    149       1.1   bsh 	struct axi_attach_args *aa = (struct axi_attach_args *)aux;
    150       1.1   bsh 
    151       1.1   bsh 	if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
    152       1.1   bsh 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    153       1.1   bsh 		if (aa->aa_size > AXICF_SIZE_DEFAULT)
    154       1.1   bsh 			aprint_normal("-0x%lx",
    155       1.1   bsh 			    aa->aa_addr + aa->aa_size-1);
    156       1.1   bsh 	}
    157       1.1   bsh 	if (aa->aa_irq != AXICF_IRQ_DEFAULT)
    158       1.1   bsh 		aprint_normal(" intr %d", aa->aa_irq);
    159       1.1   bsh 	if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
    160       1.1   bsh 		aprint_normal(" irqbase %d", aa->aa_irqbase);
    161       1.1   bsh 
    162       1.1   bsh 	return (UNCONF);
    163       1.1   bsh }
    164