Home | History | Annotate | Line # | Download | only in imx
      1 /* $Id: imx23_ahb.c,v 1.3 2021/08/07 16:18:44 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2013 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	ahb_match(device_t, cfdata_t, void *);
     44 static void	ahb_attach(device_t, device_t, void *);
     45 static int	ahb_detach(device_t, int);
     46 static int	ahb_activate(device_t, enum devact);
     47 
     48 static int	ahb_search_cb(device_t, cfdata_t, const int *, void *);
     49 static int	ahb_print(void *,const char *);
     50 
     51 CFATTACH_DECL3_NEW(ahb,
     52 	sizeof(struct ahb_softc),
     53 	ahb_match,
     54 	ahb_attach,
     55 	ahb_detach,
     56 	ahb_activate,
     57 	NULL,
     58 	NULL,
     59 	0);
     60 
     61 static int
     62 ahb_match(device_t parent, cfdata_t match, void *aux)
     63 {
     64 	struct mainbus_attach_args *mb = aux;
     65 
     66 	if ((mb->mb_iobase == AHB_BASE) && (mb->mb_iosize == AHB_SIZE))
     67 		return 1;
     68 
     69 	return 0;
     70 }
     71 
     72 static void
     73 ahb_attach(device_t parent, device_t self, void *aux)
     74 {
     75 	struct ahb_attach_args aa;
     76 	static int ahb_attached = 0;
     77 
     78 	if (ahb_attached)
     79 		return;
     80 
     81 	aa.aa_iot = &imx23_bus_space;
     82 	aa.aa_dmat = &imx23_bus_dma_tag;
     83 
     84 	aprint_normal("\n");
     85 
     86 	config_search(self, &aa,
     87 	    CFARGS(.search = ahb_search_cb));
     88 
     89 	ahb_attached = 1;
     90 
     91 	return;
     92 }
     93 
     94 static int
     95 ahb_detach(device_t self, int flags)
     96 {
     97 	return 0;
     98 }
     99 
    100 static int
    101 ahb_activate(device_t self, enum devact act)
    102 {
    103 	return EOPNOTSUPP;
    104 }
    105 
    106 /*
    107  * config_search_ia() callback function.
    108  */
    109 static int
    110 ahb_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    111 {
    112 	struct apb_attach_args *aa = aux;
    113 
    114 	aa->aa_name = cf->cf_name;
    115 	aa->aa_addr = cf->cf_loc[AHBCF_ADDR];
    116 	aa->aa_size = cf->cf_loc[AHBCF_SIZE];
    117 	aa->aa_irq = cf->cf_loc[AHBCF_IRQ];
    118 
    119 	if (config_probe(parent, cf, aux))
    120 		config_attach(parent, cf, aux, ahb_print, CFARGS_NONE);
    121 
    122 	return 0;
    123 }
    124 
    125 /*
    126  * Called from config_attach()
    127  */
    128 static int
    129 ahb_print(void *aux, const char *name __unused)
    130 {
    131 	struct apb_attach_args *aa = aux;
    132 
    133 	if (aa->aa_addr != AHBCF_ADDR_DEFAULT) {
    134 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    135 		if (aa->aa_size > AHBCF_SIZE_DEFAULT)
    136 			aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
    137 	}
    138 
    139 	if (aa->aa_irq != AHBCF_IRQ_DEFAULT)
    140 		aprint_normal(" irq %d", aa->aa_irq);
    141 
    142 	return UNCONF;
    143 }
    144