1*c7fb772bSthorpej /* $Id: imx23_ahb.c,v 1.3 2021/08/07 16:18:44 thorpej Exp $ */
294de0730Smatt
394de0730Smatt /*
494de0730Smatt * Copyright (c) 2013 The NetBSD Foundation, Inc.
594de0730Smatt * All rights reserved.
694de0730Smatt *
794de0730Smatt * This code is derived from software contributed to The NetBSD Foundation
894de0730Smatt * by Petri Laakso.
994de0730Smatt *
1094de0730Smatt * Redistribution and use in source and binary forms, with or without
1194de0730Smatt * modification, are permitted provided that the following conditions
1294de0730Smatt * are met:
1394de0730Smatt * 1. Redistributions of source code must retain the above copyright
1494de0730Smatt * notice, this list of conditions and the following disclaimer.
1594de0730Smatt * 2. Redistributions in binary form must reproduce the above copyright
1694de0730Smatt * notice, this list of conditions and the following disclaimer in the
1794de0730Smatt * documentation and/or other materials provided with the distribution.
1894de0730Smatt *
1994de0730Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2094de0730Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2194de0730Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2294de0730Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2394de0730Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2494de0730Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2594de0730Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2694de0730Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2794de0730Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2894de0730Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2994de0730Smatt * POSSIBILITY OF SUCH DAMAGE.
3094de0730Smatt */
3194de0730Smatt
3294de0730Smatt #include <sys/param.h>
3394de0730Smatt #include <sys/bus.h>
3494de0730Smatt #include <sys/device.h>
3594de0730Smatt #include <sys/errno.h>
3694de0730Smatt
3794de0730Smatt #include <arm/mainbus/mainbus.h>
3894de0730Smatt
3994de0730Smatt #include <arm/imx/imx23var.h>
4094de0730Smatt
4194de0730Smatt #include "locators.h"
4294de0730Smatt
4394de0730Smatt static int ahb_match(device_t, cfdata_t, void *);
4494de0730Smatt static void ahb_attach(device_t, device_t, void *);
4594de0730Smatt static int ahb_detach(device_t, int);
4694de0730Smatt static int ahb_activate(device_t, enum devact);
4794de0730Smatt
4894de0730Smatt static int ahb_search_cb(device_t, cfdata_t, const int *, void *);
4994de0730Smatt static int ahb_print(void *,const char *);
5094de0730Smatt
5194de0730Smatt CFATTACH_DECL3_NEW(ahb,
5294de0730Smatt sizeof(struct ahb_softc),
5394de0730Smatt ahb_match,
5494de0730Smatt ahb_attach,
5594de0730Smatt ahb_detach,
5694de0730Smatt ahb_activate,
5794de0730Smatt NULL,
5894de0730Smatt NULL,
5994de0730Smatt 0);
6094de0730Smatt
6194de0730Smatt static int
ahb_match(device_t parent,cfdata_t match,void * aux)6294de0730Smatt ahb_match(device_t parent, cfdata_t match, void *aux)
6394de0730Smatt {
6494de0730Smatt struct mainbus_attach_args *mb = aux;
6594de0730Smatt
6694de0730Smatt if ((mb->mb_iobase == AHB_BASE) && (mb->mb_iosize == AHB_SIZE))
6794de0730Smatt return 1;
6894de0730Smatt
6994de0730Smatt return 0;
7094de0730Smatt }
7194de0730Smatt
7294de0730Smatt static void
ahb_attach(device_t parent,device_t self,void * aux)7394de0730Smatt ahb_attach(device_t parent, device_t self, void *aux)
7494de0730Smatt {
7594de0730Smatt struct ahb_attach_args aa;
7694de0730Smatt static int ahb_attached = 0;
7794de0730Smatt
7894de0730Smatt if (ahb_attached)
7994de0730Smatt return;
8094de0730Smatt
8194de0730Smatt aa.aa_iot = &imx23_bus_space;
8294de0730Smatt aa.aa_dmat = &imx23_bus_dma_tag;
8394de0730Smatt
8494de0730Smatt aprint_normal("\n");
8594de0730Smatt
862685996bSthorpej config_search(self, &aa,
87*c7fb772bSthorpej CFARGS(.search = ahb_search_cb));
8894de0730Smatt
8994de0730Smatt ahb_attached = 1;
9094de0730Smatt
9194de0730Smatt return;
9294de0730Smatt }
9394de0730Smatt
9494de0730Smatt static int
ahb_detach(device_t self,int flags)9594de0730Smatt ahb_detach(device_t self, int flags)
9694de0730Smatt {
9794de0730Smatt return 0;
9894de0730Smatt }
9994de0730Smatt
10094de0730Smatt static int
ahb_activate(device_t self,enum devact act)10194de0730Smatt ahb_activate(device_t self, enum devact act)
10294de0730Smatt {
10394de0730Smatt return EOPNOTSUPP;
10494de0730Smatt }
10594de0730Smatt
10694de0730Smatt /*
10794de0730Smatt * config_search_ia() callback function.
10894de0730Smatt */
10994de0730Smatt static int
ahb_search_cb(device_t parent,cfdata_t cf,const int * locs,void * aux)11094de0730Smatt ahb_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
11194de0730Smatt {
11294de0730Smatt struct apb_attach_args *aa = aux;
11394de0730Smatt
11494de0730Smatt aa->aa_name = cf->cf_name;
11594de0730Smatt aa->aa_addr = cf->cf_loc[AHBCF_ADDR];
11694de0730Smatt aa->aa_size = cf->cf_loc[AHBCF_SIZE];
11794de0730Smatt aa->aa_irq = cf->cf_loc[AHBCF_IRQ];
11894de0730Smatt
1192685996bSthorpej if (config_probe(parent, cf, aux))
120*c7fb772bSthorpej config_attach(parent, cf, aux, ahb_print, CFARGS_NONE);
12194de0730Smatt
12294de0730Smatt return 0;
12394de0730Smatt }
12494de0730Smatt
12594de0730Smatt /*
12694de0730Smatt * Called from config_attach()
12794de0730Smatt */
12894de0730Smatt static int
ahb_print(void * aux,const char * name __unused)12994de0730Smatt ahb_print(void *aux, const char *name __unused)
13094de0730Smatt {
13194de0730Smatt struct apb_attach_args *aa = aux;
13294de0730Smatt
13394de0730Smatt if (aa->aa_addr != AHBCF_ADDR_DEFAULT) {
13494de0730Smatt aprint_normal(" addr 0x%lx", aa->aa_addr);
13594de0730Smatt if (aa->aa_size > AHBCF_SIZE_DEFAULT)
13694de0730Smatt aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
13794de0730Smatt }
13894de0730Smatt
13994de0730Smatt if (aa->aa_irq != AHBCF_IRQ_DEFAULT)
14094de0730Smatt aprint_normal(" irq %d", aa->aa_irq);
14194de0730Smatt
14294de0730Smatt return UNCONF;
14394de0730Smatt }
144