1*90313c06Smsaitoh /* $NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh Exp $ */
248914f07Sbsh
348914f07Sbsh /*-
4*90313c06Smsaitoh * Copyright (c) 2010 SHIMIZU Ryo
548914f07Sbsh * All rights reserved.
648914f07Sbsh *
748914f07Sbsh * Redistribution and use in source and binary forms, with or without
848914f07Sbsh * modification, are permitted provided that the following conditions
948914f07Sbsh * are met:
1048914f07Sbsh * 1. Redistributions of source code must retain the above copyright
1148914f07Sbsh * notice, this list of conditions and the following disclaimer.
1248914f07Sbsh * 2. Redistributions in binary form must reproduce the above copyright
1348914f07Sbsh * notice, this list of conditions and the following disclaimer in the
1448914f07Sbsh * documentation and/or other materials provided with the distribution.
1548914f07Sbsh *
1648914f07Sbsh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1748914f07Sbsh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1848914f07Sbsh * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1948914f07Sbsh * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2048914f07Sbsh * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2148914f07Sbsh * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2248914f07Sbsh * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2348914f07Sbsh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2448914f07Sbsh * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
2548914f07Sbsh * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2648914f07Sbsh * POSSIBILITY OF SUCH DAMAGE.
2748914f07Sbsh */
2848914f07Sbsh
2948914f07Sbsh #include <sys/cdefs.h>
30*90313c06Smsaitoh __KERNEL_RCSID(0, "$NetBSD: imx51_axi.c,v 1.10 2024/02/07 04:20:26 msaitoh Exp $");
3148914f07Sbsh
3248914f07Sbsh #include <sys/param.h>
3348914f07Sbsh #include <sys/bus.h>
3448914f07Sbsh #include <sys/device.h>
3548914f07Sbsh
3648914f07Sbsh #include <uvm/uvm_extern.h>
3748914f07Sbsh
3848914f07Sbsh #include <arm/imx/imx51reg.h>
3948914f07Sbsh #include <arm/imx/imx51var.h>
4048914f07Sbsh
41056b7b23Sbsh #include "bus_dma_generic.h"
4248914f07Sbsh #include "locators.h"
4348914f07Sbsh
4448914f07Sbsh struct axi_softc {
4548914f07Sbsh device_t sc_dev;
4648914f07Sbsh bus_space_tag_t sc_iot;
4748914f07Sbsh bus_dma_tag_t sc_dmat;
4848914f07Sbsh };
4948914f07Sbsh
5048914f07Sbsh static int axi_match(device_t, struct cfdata *, void *);
5148914f07Sbsh static void axi_attach(device_t, device_t, void *);
5248914f07Sbsh static int axi_search(device_t, struct cfdata *, const int *, void *);
5348914f07Sbsh static int axi_critical_search(device_t, struct cfdata *, const int *, void *);
5448914f07Sbsh static int axi_search(device_t, struct cfdata *, const int *, void *);
5548914f07Sbsh static int axi_print(void *, const char *);
5648914f07Sbsh
5748914f07Sbsh CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc),
5848914f07Sbsh axi_match, axi_attach, NULL, NULL);
5948914f07Sbsh
6048914f07Sbsh /* ARGSUSED */
6148914f07Sbsh static int
axi_match(device_t parent __unused,struct cfdata * match __unused,void * aux __unused)6248914f07Sbsh axi_match(device_t parent __unused, struct cfdata *match __unused,
6348914f07Sbsh void *aux __unused)
6448914f07Sbsh {
6548914f07Sbsh return 1;
6648914f07Sbsh }
6748914f07Sbsh
6848914f07Sbsh /* ARGSUSED */
6948914f07Sbsh static void
axi_attach(device_t parent __unused,device_t self,void * aux __unused)7048914f07Sbsh axi_attach(device_t parent __unused, device_t self, void *aux __unused)
7148914f07Sbsh {
7248914f07Sbsh struct axi_softc *sc;
7348914f07Sbsh struct axi_attach_args aa;
7448914f07Sbsh
7548914f07Sbsh aprint_normal(": Advanced eXtensible Interface\n");
7648914f07Sbsh aprint_naive("\n");
7748914f07Sbsh
7848914f07Sbsh sc = device_private(self);
7927505554Shkenken sc->sc_iot = &armv7_generic_bs_tag;
8048914f07Sbsh #if NBUS_DMA_GENERIC > 0
81eabbe28cSryo sc->sc_dmat = &arm_generic_dma_tag;
8248914f07Sbsh #else
8348914f07Sbsh sc->sc_dmat = 0;
8448914f07Sbsh #endif
8548914f07Sbsh
8648914f07Sbsh aa.aa_name = "axi";
8748914f07Sbsh aa.aa_iot = sc->sc_iot;
8848914f07Sbsh aa.aa_dmat = sc->sc_dmat;
892685996bSthorpej config_search(self, &aa,
90c7fb772bSthorpej CFARGS(.search = axi_critical_search));
912685996bSthorpej config_search(self, &aa,
92c7fb772bSthorpej CFARGS(.search = axi_search));
9348914f07Sbsh }
9448914f07Sbsh
9548914f07Sbsh /* ARGSUSED */
9648914f07Sbsh static int
axi_critical_search(device_t parent,struct cfdata * cf,const int * ldesc __unused,void * aux)9748914f07Sbsh axi_critical_search(device_t parent, struct cfdata *cf,
9848914f07Sbsh const int *ldesc __unused, void *aux)
9948914f07Sbsh {
10048914f07Sbsh struct axi_attach_args *aa;
10148914f07Sbsh
10248914f07Sbsh aa = aux;
10348914f07Sbsh
10448914f07Sbsh if ((strcmp(cf->cf_name, "tzic") != 0) &&
105c1719a03Sbsh (strcmp(cf->cf_name, "imxuart") != 0) &&
106056b7b23Sbsh (strcmp(cf->cf_name, "imxccm") != 0) &&
107c1719a03Sbsh (strcmp(cf->cf_name, "imxgpio") != 0))
10848914f07Sbsh return 0;
10948914f07Sbsh
110c1719a03Sbsh aa->aa_name = cf->cf_name;
11148914f07Sbsh aa->aa_addr = cf->cf_loc[AXICF_ADDR];
11248914f07Sbsh aa->aa_size = cf->cf_loc[AXICF_SIZE];
11348914f07Sbsh aa->aa_irq = cf->cf_loc[AXICF_IRQ];
11448914f07Sbsh aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
11548914f07Sbsh
1162685996bSthorpej if (config_probe(parent, cf, aux))
117c7fb772bSthorpej config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
11848914f07Sbsh
11948914f07Sbsh return 0;
12048914f07Sbsh }
12148914f07Sbsh
12248914f07Sbsh
12348914f07Sbsh /* ARGSUSED */
12448914f07Sbsh static int
axi_search(device_t parent,struct cfdata * cf,const int * ldesc __unused,void * aux)12548914f07Sbsh axi_search(device_t parent, struct cfdata *cf, const int *ldesc __unused,
12648914f07Sbsh void *aux)
12748914f07Sbsh {
12848914f07Sbsh struct axi_attach_args *aa;
12948914f07Sbsh
13048914f07Sbsh aa = aux;
13148914f07Sbsh
13248914f07Sbsh aa->aa_addr = cf->cf_loc[AXICF_ADDR];
13348914f07Sbsh aa->aa_size = cf->cf_loc[AXICF_SIZE];
13448914f07Sbsh aa->aa_irq = cf->cf_loc[AXICF_IRQ];
13548914f07Sbsh aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE];
13648914f07Sbsh
1372685996bSthorpej if (config_probe(parent, cf, aux))
138c7fb772bSthorpej config_attach(parent, cf, aux, axi_print, CFARGS_NONE);
13948914f07Sbsh
14048914f07Sbsh return 0;
14148914f07Sbsh }
14248914f07Sbsh
14348914f07Sbsh /* ARGSUSED */
14448914f07Sbsh static int
axi_print(void * aux,const char * name __unused)14548914f07Sbsh axi_print(void *aux, const char *name __unused)
14648914f07Sbsh {
14748914f07Sbsh struct axi_attach_args *aa = (struct axi_attach_args *)aux;
14848914f07Sbsh
14948914f07Sbsh if (aa->aa_addr != AXICF_ADDR_DEFAULT) {
15048914f07Sbsh aprint_normal(" addr 0x%lx", aa->aa_addr);
15148914f07Sbsh if (aa->aa_size > AXICF_SIZE_DEFAULT)
15248914f07Sbsh aprint_normal("-0x%lx",
15348914f07Sbsh aa->aa_addr + aa->aa_size-1);
15448914f07Sbsh }
15548914f07Sbsh if (aa->aa_irq != AXICF_IRQ_DEFAULT)
15648914f07Sbsh aprint_normal(" intr %d", aa->aa_irq);
15748914f07Sbsh if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT)
15848914f07Sbsh aprint_normal(" irqbase %d", aa->aa_irqbase);
15948914f07Sbsh
16048914f07Sbsh return (UNCONF);
16148914f07Sbsh }
162