Home | History | Annotate | Line # | Download | only in imx
imx51_axi.c revision 1.10
      1  1.10  msaitoh /*	$NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh Exp $	*/
      2   1.1      bsh 
      3   1.1      bsh /*-
      4  1.10  msaitoh  * Copyright (c) 2010 SHIMIZU Ryo
      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.10  msaitoh __KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh 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.3      bsh #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.5  hkenken 	sc->sc_iot = &armv7_generic_bs_tag;
     80   1.1      bsh #if NBUS_DMA_GENERIC > 0
     81   1.7      ryo 	sc->sc_dmat = &arm_generic_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.8  thorpej 	config_search(self, &aa,
     90   1.9  thorpej 	    CFARGS(.search = axi_critical_search));
     91   1.8  thorpej 	config_search(self, &aa,
     92   1.9  thorpej 	    CFARGS(.search = axi_search));
     93   1.1      bsh }
     94   1.1      bsh 
     95   1.1      bsh /* ARGSUSED */
     96   1.1      bsh static int
     97   1.1      bsh axi_critical_search(device_t parent, struct cfdata *cf,
     98   1.1      bsh     const int *ldesc __unused, void *aux)
     99   1.1      bsh {
    100   1.1      bsh 	struct axi_attach_args *aa;
    101   1.1      bsh 
    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.3      bsh 	    (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.8  thorpej 	if (config_probe(parent, cf, aux))
    117   1.9  thorpej 		config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
    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_attach_args *aa;
    129   1.1      bsh 
    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.8  thorpej 	if (config_probe(parent, cf, aux))
    138   1.9  thorpej 		config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
    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