Home | History | Annotate | Line # | Download | only in imx
      1 /* $Id: imx23_apbh.c,v 1.3 2021/08/07 16:18:44 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Petri Laakso.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/param.h>
     33 #include <sys/bus.h>
     34 #include <sys/device.h>
     35 #include <sys/errno.h>
     36 
     37 #include <arm/mainbus/mainbus.h>
     38 
     39 #include <arm/imx/imx23var.h>
     40 
     41 #include "locators.h"
     42 
     43 static int	apbh_match(device_t, cfdata_t, void *);
     44 static void	apbh_attach(device_t, device_t, void *);
     45 static int	apbh_detach(device_t, int);
     46 static int	apbh_activate(device_t, enum devact);
     47 
     48 static int	apbh_search_cb(device_t, cfdata_t, const int *, void *);
     49 static int	apbh_search_crit_cb(device_t, cfdata_t, const int *, void *);
     50 static int	apbh_print(void *,const char *);
     51 
     52 struct apbh_softc {
     53 	device_t	sc_dev;
     54 	device_t	dmac; /* DMA controller device for this bus. */
     55 };
     56 
     57 CFATTACH_DECL3_NEW(apbh,
     58 	sizeof(struct apbh_softc),
     59 	apbh_match,
     60 	apbh_attach,
     61 	apbh_detach,
     62 	apbh_activate,
     63 	NULL,
     64 	NULL,
     65 	0);
     66 
     67 static int
     68 apbh_match(device_t parent, cfdata_t match, void *aux)
     69 {
     70 	struct mainbus_attach_args *mb = aux;
     71 
     72 	if ((mb->mb_iobase == APBH_BASE) && (mb->mb_iosize == APBH_SIZE))
     73 		return 1;
     74 
     75 	return 0;
     76 }
     77 
     78 static void
     79 apbh_attach(device_t parent, device_t self, void *aux)
     80 {
     81 	struct apb_attach_args aa;
     82 	static int apbh_attached = 0;
     83 
     84 	if (apbh_attached)
     85 		return;
     86 
     87 	aa.aa_iot = &imx23_bus_space;
     88 	aa.aa_dmat = &imx23_bus_dma_tag;
     89 
     90 	aprint_normal("\n");
     91 
     92 	config_search(self, &aa,
     93 	    CFARGS(.search = apbh_search_crit_cb));
     94 	config_search(self, &aa,
     95 	    CFARGS(.search = apbh_search_cb));
     96 
     97 	apbh_attached = 1;
     98 
     99 	return;
    100 }
    101 
    102 static int
    103 apbh_detach(device_t self, int flags)
    104 {
    105 	return 0;
    106 }
    107 
    108 static int
    109 apbh_activate(device_t self, enum devact act)
    110 {
    111 	return EOPNOTSUPP;
    112 }
    113 
    114 /*
    115  * config_search_ia() callback function.
    116  */
    117 static int
    118 apbh_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    119 {
    120 	struct apb_attach_args *aa = aux;
    121 
    122 	aa->aa_name = cf->cf_name;
    123 	aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
    124 	aa->aa_size = cf->cf_loc[APBHCF_SIZE];
    125 	aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
    126 
    127 	if (config_probe(parent, cf, aux))
    128 		config_attach(parent, cf, aux, apbh_print, CFARGS_NONE);
    129 
    130 	return 0;
    131 }
    132 
    133 /*
    134  * config_search_ia() callback function which only applies to critical devices.
    135  */
    136 static int
    137 apbh_search_crit_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    138 {
    139 	struct apb_attach_args *aa = aux;
    140 
    141 	/* Return if not critical device. */
    142 	if ((strcmp(cf->cf_name, "icoll") != 0)
    143 	    && (strcmp(cf->cf_name, "apbdma") != 0))
    144 		return 0;
    145 
    146 	aa->aa_name = cf->cf_name;
    147 	aa->aa_addr = cf->cf_loc[APBHCF_ADDR];
    148 	aa->aa_size = cf->cf_loc[APBHCF_SIZE];
    149 	aa->aa_irq = cf->cf_loc[APBHCF_IRQ];
    150 
    151 	if (config_probe(parent, cf, aux))
    152 		config_attach(parent, cf, aux, apbh_print, CFARGS_NONE);
    153 
    154 	return 0;
    155 }
    156 
    157 /*
    158  * Called from config_attach()
    159  */
    160 static int
    161 apbh_print(void *aux, const char *name __unused)
    162 {
    163 	struct apb_attach_args *aa = aux;
    164 
    165 	if (aa->aa_addr != APBHCF_ADDR_DEFAULT) {
    166 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    167 		if (aa->aa_size > APBHCF_SIZE_DEFAULT)
    168 			aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
    169 	}
    170 
    171 	if (aa->aa_irq != APBHCF_IRQ_DEFAULT)
    172 		aprint_normal(" irq %d", aa->aa_irq);
    173 
    174 	return UNCONF;
    175 }
    176