Home | History | Annotate | Line # | Download | only in imx
imx23_ahb.c revision 1.1
      1  1.1  matt /* $Id: imx23_ahb.c,v 1.1 2013/10/07 17:36:40 matt Exp $ */
      2  1.1  matt 
      3  1.1  matt /*
      4  1.1  matt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.1  matt  * All rights reserved.
      6  1.1  matt  *
      7  1.1  matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  matt  * by Petri Laakso.
      9  1.1  matt  *
     10  1.1  matt  * Redistribution and use in source and binary forms, with or without
     11  1.1  matt  * modification, are permitted provided that the following conditions
     12  1.1  matt  * are met:
     13  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  matt  *    documentation and/or other materials provided with the distribution.
     18  1.1  matt  *
     19  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  matt  */
     31  1.1  matt 
     32  1.1  matt #include <sys/param.h>
     33  1.1  matt #include <sys/bus.h>
     34  1.1  matt #include <sys/device.h>
     35  1.1  matt #include <sys/errno.h>
     36  1.1  matt 
     37  1.1  matt #include <arm/mainbus/mainbus.h>
     38  1.1  matt 
     39  1.1  matt #include <arm/imx/imx23var.h>
     40  1.1  matt 
     41  1.1  matt #include "locators.h"
     42  1.1  matt 
     43  1.1  matt static int	ahb_match(device_t, cfdata_t, void *);
     44  1.1  matt static void	ahb_attach(device_t, device_t, void *);
     45  1.1  matt static int	ahb_detach(device_t, int);
     46  1.1  matt static int	ahb_activate(device_t, enum devact);
     47  1.1  matt 
     48  1.1  matt static int	ahb_search_cb(device_t, cfdata_t, const int *, void *);
     49  1.1  matt static int	ahb_print(void *,const char *);
     50  1.1  matt 
     51  1.1  matt CFATTACH_DECL3_NEW(ahb,
     52  1.1  matt 	sizeof(struct ahb_softc),
     53  1.1  matt 	ahb_match,
     54  1.1  matt 	ahb_attach,
     55  1.1  matt 	ahb_detach,
     56  1.1  matt 	ahb_activate,
     57  1.1  matt 	NULL,
     58  1.1  matt 	NULL,
     59  1.1  matt 	0);
     60  1.1  matt 
     61  1.1  matt static int
     62  1.1  matt ahb_match(device_t parent, cfdata_t match, void *aux)
     63  1.1  matt {
     64  1.1  matt 	struct mainbus_attach_args *mb = aux;
     65  1.1  matt 
     66  1.1  matt 	if ((mb->mb_iobase == AHB_BASE) && (mb->mb_iosize == AHB_SIZE))
     67  1.1  matt 		return 1;
     68  1.1  matt 
     69  1.1  matt 	return 0;
     70  1.1  matt }
     71  1.1  matt 
     72  1.1  matt static void
     73  1.1  matt ahb_attach(device_t parent, device_t self, void *aux)
     74  1.1  matt {
     75  1.1  matt 	struct ahb_attach_args aa;
     76  1.1  matt 	static int ahb_attached = 0;
     77  1.1  matt 
     78  1.1  matt 	if (ahb_attached)
     79  1.1  matt 		return;
     80  1.1  matt 
     81  1.1  matt 	aa.aa_iot = &imx23_bus_space;
     82  1.1  matt 	aa.aa_dmat = &imx23_bus_dma_tag;
     83  1.1  matt 
     84  1.1  matt 	aprint_normal("\n");
     85  1.1  matt 
     86  1.1  matt 	config_search_ia(ahb_search_cb, self, "ahb", &aa);
     87  1.1  matt 
     88  1.1  matt 	ahb_attached = 1;
     89  1.1  matt 
     90  1.1  matt 	return;
     91  1.1  matt }
     92  1.1  matt 
     93  1.1  matt static int
     94  1.1  matt ahb_detach(device_t self, int flags)
     95  1.1  matt {
     96  1.1  matt 	return 0;
     97  1.1  matt }
     98  1.1  matt 
     99  1.1  matt static int
    100  1.1  matt ahb_activate(device_t self, enum devact act)
    101  1.1  matt {
    102  1.1  matt 	return EOPNOTSUPP;
    103  1.1  matt }
    104  1.1  matt 
    105  1.1  matt /*
    106  1.1  matt  * config_search_ia() callback function.
    107  1.1  matt  */
    108  1.1  matt static int
    109  1.1  matt ahb_search_cb(device_t parent, cfdata_t cf, const int *locs, void *aux)
    110  1.1  matt {
    111  1.1  matt 	struct apb_attach_args *aa = aux;
    112  1.1  matt 
    113  1.1  matt 	aa->aa_name = cf->cf_name;
    114  1.1  matt 	aa->aa_addr = cf->cf_loc[AHBCF_ADDR];
    115  1.1  matt 	aa->aa_size = cf->cf_loc[AHBCF_SIZE];
    116  1.1  matt 	aa->aa_irq = cf->cf_loc[AHBCF_IRQ];
    117  1.1  matt 
    118  1.1  matt 	if (config_match(parent, cf, aux) > 0)
    119  1.1  matt 		config_attach(parent, cf, aux, ahb_print);
    120  1.1  matt 
    121  1.1  matt 	return 0;
    122  1.1  matt }
    123  1.1  matt 
    124  1.1  matt /*
    125  1.1  matt  * Called from config_attach()
    126  1.1  matt  */
    127  1.1  matt static int
    128  1.1  matt ahb_print(void *aux, const char *name __unused)
    129  1.1  matt {
    130  1.1  matt 	struct apb_attach_args *aa = aux;
    131  1.1  matt 
    132  1.1  matt 	if (aa->aa_addr != AHBCF_ADDR_DEFAULT) {
    133  1.1  matt 		aprint_normal(" addr 0x%lx", aa->aa_addr);
    134  1.1  matt 		if (aa->aa_size > AHBCF_SIZE_DEFAULT)
    135  1.1  matt 			aprint_normal("-0x%lx", aa->aa_addr + aa->aa_size-1);
    136  1.1  matt 	}
    137  1.1  matt 
    138  1.1  matt 	if (aa->aa_irq != AHBCF_IRQ_DEFAULT)
    139  1.1  matt 		aprint_normal(" irq %d", aa->aa_irq);
    140  1.1  matt 
    141  1.1  matt 	return UNCONF;
    142  1.1  matt }
    143