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