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