Home | History | Annotate | Line # | Download | only in imx
imx51_axi.c revision 1.2
      1  1.2  bsh /*	$NetBSD: imx51_axi.c,v 1.2 2010/11/30 13:05:27 bsh 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  bsh __KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.2 2010/11/30 13:05:27 bsh 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.1  bsh #include "locators.h"
     42  1.1  bsh 
     43  1.1  bsh struct axi_softc {
     44  1.1  bsh 	device_t sc_dev;
     45  1.1  bsh 	bus_space_tag_t sc_iot;
     46  1.1  bsh 	bus_dma_tag_t sc_dmat;
     47  1.1  bsh };
     48  1.1  bsh 
     49  1.1  bsh static int axi_match(device_t, struct cfdata *, void *);
     50  1.1  bsh static void axi_attach(device_t, device_t, void *);
     51  1.1  bsh static int axi_search(device_t, struct cfdata *, const int *, void *);
     52  1.1  bsh static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
     53  1.1  bsh static int axi_search(device_t, struct cfdata *, const int *, void *);
     54  1.1  bsh static int axi_print(void *, const char *);
     55  1.1  bsh 
     56  1.1  bsh CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
     57  1.1  bsh     axi_match, axi_attach, NULL, NULL);
     58  1.1  bsh 
     59  1.1  bsh /* ARGSUSED */
     60  1.1  bsh static int
     61  1.1  bsh axi_match(device_t parent __unused, struct cfdata *match __unused,
     62  1.1  bsh     void *aux __unused)
     63  1.1  bsh {
     64  1.1  bsh 	return 1;
     65  1.1  bsh }
     66  1.1  bsh 
     67  1.1  bsh /* ARGSUSED */
     68  1.1  bsh static void
     69  1.1  bsh axi_attach(device_t parent __unused, device_t self, void *aux __unused)
     70  1.1  bsh {
     71  1.1  bsh 	struct axi_softc *sc;
     72  1.1  bsh 	struct axi_attach_args aa;
     73  1.1  bsh 
     74  1.1  bsh 	aprint_normal(": Advanced eXtensible Interface\n");
     75  1.1  bsh 	aprint_naive("\n");
     76  1.1  bsh 
     77  1.1  bsh 	sc = device_private(self);
     78  1.1  bsh 	sc->sc_iot = &imx_bs_tag;
     79  1.1  bsh #if NBUS_DMA_GENERIC > 0
     80  1.1  bsh 	sc->sc_dmat = &imx_bus_dma_tag;
     81  1.1  bsh #else
     82  1.1  bsh 	sc->sc_dmat = 0;
     83  1.1  bsh #endif
     84  1.1  bsh 
     85  1.1  bsh 	aa.aa_name = "axi";
     86  1.1  bsh 	aa.aa_iot = sc->sc_iot;
     87  1.1  bsh 	aa.aa_dmat = sc->sc_dmat;
     88  1.1  bsh 	config_search_ia(axi_critical_search, self, "axi", &aa);
     89  1.1  bsh 	config_search_ia(axi_search, self, "axi", &aa);
     90  1.1  bsh }
     91  1.1  bsh 
     92  1.1  bsh /* ARGSUSED */
     93  1.1  bsh static int
     94  1.1  bsh axi_critical_search(device_t parent, struct cfdata *cf,
     95  1.1  bsh     const int *ldesc __unused, void *aux)
     96  1.1  bsh {
     97  1.1  bsh 	struct axi_softc *sc;
     98  1.1  bsh 	struct axi_attach_args *aa;
     99  1.1  bsh 
    100  1.1  bsh 	sc = device_private(parent);
    101  1.1  bsh 	aa = aux;
    102  1.1  bsh 
    103  1.1  bsh 	if ((strcmp(cf->cf_name, "tzic") != 0) &&
    104  1.2  bsh 	    (strcmp(cf->cf_name, "imxuart") != 0) &&
    105  1.2  bsh 	    (strcmp(cf->cf_name, "imxgpio") != 0))
    106  1.1  bsh 		return 0;
    107  1.1  bsh 
    108  1.2  bsh 	aa->aa_name = cf->cf_name;
    109  1.1  bsh 	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
    110  1.1  bsh 	aa->aa_size = cf->cf_loc[AXICF_SIZE];
    111  1.1  bsh 	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
    112  1.1  bsh 	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
    113  1.1  bsh 
    114  1.1  bsh 	if (config_match(parent, cf, aux) > 0)
    115  1.1  bsh 		config_attach(parent, cf, aux, axi_print);
    116  1.1  bsh 
    117  1.1  bsh 	return 0;
    118  1.1  bsh }
    119  1.1  bsh 
    120  1.1  bsh 
    121  1.1  bsh /* ARGSUSED */
    122  1.1  bsh static int
    123  1.1  bsh axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
    124  1.1  bsh     void *aux)
    125  1.1  bsh {
    126  1.1  bsh 	struct axi_softc *sc;
    127  1.1  bsh 	struct axi_attach_args *aa;
    128  1.1  bsh 
    129  1.1  bsh 	sc = device_private(parent);
    130  1.1  bsh 	aa = aux;
    131  1.1  bsh 
    132  1.1  bsh 	aa->aa_addr = cf->cf_loc[AXICF_ADDR];
    133  1.1  bsh 	aa->aa_size = cf->cf_loc[AXICF_SIZE];
    134  1.1  bsh 	aa->aa_irq = cf->cf_loc[AXICF_IRQ];
    135  1.1  bsh 	aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
    136  1.1  bsh 
    137  1.1  bsh 	if (config_match(parent, cf, aux) > 0)
    138  1.1  bsh 		config_attach(parent, cf, aux, axi_print);
    139  1.1  bsh 
    140  1.1  bsh 	return 0;
    141  1.1  bsh }
    142  1.1  bsh 
    143  1.1  bsh /* ARGSUSED */
    144  1.1  bsh static int
    145  1.1  bsh axi_print(void *aux, const char *name __unused)
    146  1.1  bsh {
    147  1.1  bsh 	struct axi_attach_args *aa = (struct axi_attach_args *)aux;
    148  1.1  bsh 
    149  1.1  bsh 	if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
    150  1.1  bsh 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    151  1.1  bsh 		if (aa->aa_size > AXICF_SIZE_DEFAULT)
    152  1.1  bsh 			aprint_normal("-0x%lx",
    153  1.1  bsh 			    aa->aa_addr + aa->aa_size-1);
    154  1.1  bsh 	}
    155  1.1  bsh 	if (aa->aa_irq != AXICF_IRQ_DEFAULT)
    156  1.1  bsh 		aprint_normal(" intr %d", aa->aa_irq);
    157  1.1  bsh 	if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
    158  1.1  bsh 		aprint_normal(" irqbase %d", aa->aa_irqbase);
    159  1.1  bsh 
    160  1.1  bsh 	return (UNCONF);
    161  1.1  bsh }
    162