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