tx39uart.c revision 1.2       1  1.2  uch /*	$NetBSD: tx39uart.c,v 1.2 1999/12/07 17:08:10 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.1  uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.1  uch  * Redistribution and use in source and binary forms, with or without
      8  1.1  uch  * modification, are permitted provided that the following conditions
      9  1.1  uch  * are met:
     10  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.1  uch  *    derived from this software without specific prior written permission.
     14  1.1  uch  *
     15  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  uch  * SUCH DAMAGE.
     26  1.1  uch  *
     27  1.1  uch  */
     28  1.1  uch #include "opt_tx39_debug.h"
     29  1.1  uch #include "opt_tx39uartdebug.h"
     30  1.1  uch 
     31  1.1  uch #include <sys/param.h>
     32  1.1  uch #include <sys/systm.h>
     33  1.1  uch #include <sys/device.h>
     34  1.1  uch 
     35  1.1  uch #include <machine/bus.h>
     36  1.1  uch #include <machine/intr.h>
     37  1.1  uch 
     38  1.1  uch #include <hpcmips/tx/tx39var.h>
     39  1.1  uch #include <hpcmips/tx/tx39uartvar.h>
     40  1.1  uch 
     41  1.1  uch #include "locators.h"
     42  1.1  uch 
     43  1.1  uch int	tx39uart_match __P((struct device*, struct cfdata*, void*));
     44  1.1  uch void	tx39uart_attach __P((struct device*, struct device*, void*));
     45  1.1  uch int	tx39uart_print __P((void*, const char*));
     46  1.1  uch int	tx39uart_search __P((struct device*, struct cfdata*, void*));
     47  1.1  uch 
     48  1.1  uch struct tx39uart_softc {
     49  1.1  uch 	struct	device sc_dev;
     50  1.1  uch 	tx_chipset_tag_t sc_tc;
     51  1.1  uch 	int sc_enabled;
     52  1.1  uch };
     53  1.1  uch 
     54  1.1  uch struct cfattach tx39uart_ca = {
     55  1.1  uch 	sizeof(struct tx39uart_softc), tx39uart_match, tx39uart_attach
     56  1.1  uch };
     57  1.1  uch 
     58  1.1  uch int
     59  1.1  uch tx39uart_match(parent, cf, aux)
     60  1.1  uch 	struct device *parent;
     61  1.1  uch 	struct cfdata *cf;
     62  1.1  uch 	void *aux;
     63  1.1  uch {
     64  1.1  uch 	return 1;
     65  1.1  uch }
     66  1.1  uch 
     67  1.1  uch void
     68  1.1  uch tx39uart_attach(parent, self, aux)
     69  1.1  uch 	struct device *parent;
     70  1.1  uch 	struct device *self;
     71  1.1  uch 	void *aux;
     72  1.1  uch {
     73  1.1  uch 	struct txsim_attach_args *ta = aux;
     74  1.1  uch 	struct tx39uart_softc *sc = (void*)self;
     75  1.1  uch 	tx_chipset_tag_t tc;
     76  1.1  uch 
     77  1.1  uch 	printf("\n");
     78  1.1  uch 	sc->sc_tc = tc = ta->ta_tc;
     79  1.1  uch 
     80  1.1  uch 	config_search(tx39uart_search, self, tx39uart_print);
     81  1.1  uch }
     82  1.1  uch 
     83  1.1  uch int
     84  1.1  uch tx39uart_search(parent, cf, aux)
     85  1.1  uch 	struct device *parent;
     86  1.1  uch 	struct cfdata *cf;
     87  1.1  uch 	void *aux;
     88  1.1  uch {
     89  1.1  uch 	struct tx39uart_softc *sc = (void*)parent;
     90  1.1  uch 	struct tx39uart_attach_args ua;
     91  1.1  uch 
     92  1.1  uch 	ua.ua_tc	= sc->sc_tc;
     93  1.1  uch 	ua.ua_slot	= cf->cf_loc[TXCOMIFCF_SLOT];
     94  1.1  uch 
     95  1.1  uch 	if (ua.ua_slot == TXCOMIFCF_SLOT_DEFAULT) {
     96  1.1  uch 		printf("tx39uart_search: wildcarded slot, skipping\n");
     97  1.1  uch 		return 0;
     98  1.1  uch 	}
     99  1.1  uch 
    100  1.1  uch 	if (!(sc->sc_enabled & (1 << ua.ua_slot)) && /* not attached slot */
    101  1.1  uch 	    (*cf->cf_attach->ca_match)(parent, cf, &ua)) {
    102  1.1  uch 		config_attach(parent, cf, &ua, tx39uart_print);
    103  1.1  uch 		sc->sc_enabled |= (1 << ua.ua_slot);
    104  1.1  uch 	}
    105  1.1  uch 
    106  1.1  uch 	return 0;
    107  1.1  uch }
    108  1.1  uch 
    109  1.1  uch int
    110  1.1  uch tx39uart_print(aux, pnp)
    111  1.1  uch 	void *aux;
    112  1.1  uch 	const char *pnp;
    113  1.1  uch {
    114  1.2  uch 	struct tx39uart_attach_args *ua = aux;
    115  1.2  uch 
    116  1.2  uch 	printf(" slot %d", ua->ua_slot);
    117  1.2  uch 
    118  1.2  uch 	return QUIET;
    119  1.1  uch }
    120