Home | History | Annotate | Line # | Download | only in imx
imx23_apbx.c revision 1.1.56.1
      1 /* $Id: imx23_apbx.c,v 1.1.56.1 2021/03/20 19:33:31 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	apbx_match(device_t, cfdata_t, void *);
     44 static void	apbx_attach(device_t, device_t, void *);
     45 static int	apbx_detach(device_t, int);
     46 static int	apbx_activate(device_t, enum devact );
     47 
     48 static int	apbx_search_cb(device_t, cfdata_t, const int *, void *);
     49 static int	apbx_search_crit_cb(device_t, cfdata_t, const int *, void *);
     50 static int	apbx_print(void *,const char *);
     51 
     52 struct apbx_softc {
     53 	device_t	sc_dev;
     54 	device_t	dmac; /* DMA controller device for this bus. */
     55 };
     56 
     57 CFATTACH_DECL3_NEW(apbx,
     58 	sizeof(struct apbx_softc),
     59 	apbx_match,
     60 	apbx_attach,
     61 	apbx_detach,
     62 	apbx_activate,
     63 	NULL,
     64 	NULL,
     65 	0);
     66 
     67 static int
     68 apbx_match(device_t parent, cfdata_t match, void *aux)
     69 {
     70 	struct mainbus_attach_args *mb = aux;
     71 
     72 	if ((mb->mb_iobase == APBX_BASE) && (mb->mb_iosize == APBX_SIZE))
     73 		return 1;
     74 
     75 	return 0;
     76 }
     77 
     78 static void
     79 apbx_attach(device_t parent, device_t self, void *aux)
     80 {
     81 	struct apb_attach_args aa;
     82 	static int apbx_attached = 0;
     83 
     84 	if (apbx_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 	    CFARG_SUBMATCH, apbx_search_crit_cb,
     94 	    CFARG_IATTR, "apbx",
     95 	    CFARG_EOL);
     96 	config_search(self, &aa,
     97 	    CFARG_SUBMATCH, apbx_search_cb,
     98 	    CFARG_IATTR, "apbx",
     99 	    CFARG_EOL);
    100 
    101 	apbx_attached = 1;
    102 
    103 	return;
    104 }
    105 
    106 static int
    107 apbx_detach(device_t self, int flags)
    108 {
    109 	return 0;
    110 }
    111 
    112 static int
    113 apbx_activate(device_t self, enum devact act)
    114 {
    115 	return EOPNOTSUPP;
    116 }
    117 
    118 /*
    119  * config_search_ia() callback function.
    120  */
    121 static int
    122 apbx_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    123 {
    124 	struct apb_attach_args *aa = aux;
    125 
    126 	aa->aa_name = cf->cf_name;
    127 	aa->aa_addr = cf->cf_loc[APBXCF_ADDR];
    128 	aa->aa_size = cf->cf_loc[APBXCF_SIZE];
    129 	aa->aa_irq = cf->cf_loc[APBXCF_IRQ];
    130 
    131 	if (config_match(parent, cf, aux) > 0)
    132 		config_attach(parent, cf, aux, apbx_print);
    133 
    134 	return 0;
    135 }
    136 
    137 /*
    138  * config_search_ia() callback function which only applies to critical devices.
    139  */
    140 static int
    141 apbx_search_crit_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    142 {
    143 	struct apb_attach_args *aa = aux;
    144 
    145 	/* Return if not critical device. */
    146 	if ((strcmp(cf->cf_name, "timrot") != 0)
    147 	    && (strcmp(cf->cf_name, "apbdma") != 0))
    148 		return 0;
    149 
    150 	aa->aa_name = cf->cf_name;
    151 	aa->aa_addr = cf->cf_loc[APBXCF_ADDR];
    152 	aa->aa_size = cf->cf_loc[APBXCF_SIZE];
    153 	aa->aa_irq = cf->cf_loc[APBXCF_IRQ];
    154 
    155 	if (config_match(parent, cf, aux) > 0)
    156 		config_attach(parent, cf, aux, apbx_print);
    157 
    158 	return 0;
    159 }
    160 
    161 /*
    162  * Called from config_attach()
    163  */
    164 static int
    165 apbx_print(void *aux, const char *name __unused)
    166 {
    167 	struct apb_attach_args *aa = aux;
    168 
    169 	if (aa->aa_addr != APBXCF_ADDR_DEFAULT) {
    170 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    171 		if (aa->aa_size > APBXCF_SIZE_DEFAULT)
    172 			aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
    173 	}
    174 
    175 	if (aa->aa_irq != APBXCF_IRQ_DEFAULT)
    176 		aprint_normal(" irq %d", aa->aa_irq);
    177 
    178 	return UNCONF;
    179 }
    180