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