Home | History | Annotate | Line # | Download | only in adi_brh
obio.c revision 1.1
      1 /*	$NetBSD: obio.c,v 1.1 2003/01/25 02:00:17 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * On-board device autoconfiguration support for ADI BRH
     40  * evaluation boards.
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 
     47 #include <machine/autoconf.h>
     48 #include <machine/bus.h>
     49 
     50 #include <arm/xscale/beccreg.h>
     51 #include <arm/xscale/beccvar.h>
     52 
     53 #include <evbarm/adi_brh/brhreg.h>
     54 #include <evbarm/adi_brh/obiovar.h>
     55 
     56 #include "locators.h"
     57 
     58 int	obio_match(struct device *, struct cfdata *, void *);
     59 void	obio_attach(struct device *, struct device *, void *);
     60 
     61 CFATTACH_DECL(obio, sizeof(struct device),
     62     obio_match, obio_attach, NULL, NULL);
     63 
     64 int	obio_print(void *, const char *);
     65 int	obio_search(struct device *, struct cfdata *, void *);
     66 
     67 /* there can be only one */
     68 int	obio_found;
     69 
     70 int
     71 obio_match(struct device *parent, struct cfdata *cf, void *aux)
     72 {
     73 #if 0
     74 	struct mainbus_attach_args *ma = aux;
     75 #endif
     76 
     77 	if (obio_found)
     78 		return (0);
     79 
     80 #if 1
     81 	/* XXX Shoot arch/arm/mainbus in the head. */
     82 	return (1);
     83 #else
     84 	if (strcmp(cf->cf_name, ma->ma_name) == 0)
     85 		return (1);
     86 
     87 	return (0);
     88 #endif
     89 }
     90 
     91 void
     92 obio_attach(struct device *parent, struct device *self, void *aux)
     93 {
     94 
     95 	obio_found = 1;
     96 
     97 	printf("\n");
     98 
     99 	/*
    100 	 * Attach all on-board devices as described in the kernel
    101 	 * configuration file.
    102 	 */
    103 	config_search(obio_search, self, NULL);
    104 }
    105 
    106 int
    107 obio_print(void *aux, const char *pnp)
    108 {
    109 	struct obio_attach_args *oba = aux;
    110 
    111 	aprint_normal(" addr 0x%08lx", oba->oba_addr);
    112 	if (oba->oba_irq != -1)
    113 		aprint_normal(" irq %d", oba->oba_irq);
    114 
    115 	return (UNCONF);
    116 }
    117 
    118 int
    119 obio_search(struct device *parent, struct cfdata *cf, void *aux)
    120 {
    121 	struct obio_attach_args oba;
    122 
    123 	oba.oba_st = &obio_bs_tag;
    124 
    125 	oba.oba_addr = cf->cf_loc[OBIOCF_ADDR];
    126 	oba.oba_irq = cf->cf_loc[OBIOCF_IRQ];
    127 
    128 	if (config_match(parent, cf, &oba) > 0)
    129 		config_attach(parent, cf, &oba, obio_print);
    130 
    131 	return (0);
    132 }
    133