xref: /netbsd-src/sys/arch/hpcmips/dev/ucbio.c (revision 481fca6e59249d8ffcf24fef7cfbe7b131bfb080)
1 /*	$NetBSD: ucbio.c,v 1.1 2000/02/27 16:34:13 uch Exp $	*/
2 
3 /*
4  * Copyright (c) 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 
29 /*
30  * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
31  *	General Purpose I/O part.
32  */
33 #include "opt_tx39_debug.h"
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <machine/bus.h>
40 #include <machine/intr.h>
41 #include <machine/platid.h>
42 #include <machine/platid_mask.h>
43 
44 #include <hpcmips/tx/tx39var.h>
45 #include <hpcmips/tx/tx39sibvar.h>
46 #include <hpcmips/tx/tx39sibreg.h>
47 
48 #include <hpcmips/dev/ucb1200var.h>
49 #include <hpcmips/dev/ucb1200reg.h>
50 
51 #include "locators.h"
52 
53 extern char*	btnmgr_name __P((long));
54 
55 int	ucbio_match	__P((struct device*, struct cfdata*, void*));
56 void	ucbio_attach	__P((struct device*, struct device*, void*));
57 
58 struct ucbio_softc {
59 	struct device	sc_dev;
60 };
61 
62 struct cfattach ucbio_ca = {
63 	sizeof(struct ucbio_softc), ucbio_match, ucbio_attach
64 };
65 
66 int	ucbio_print	__P((void*, const char*));
67 int	ucbio_submatch	__P((struct device*, struct cfdata*, void*));
68 
69 int
70 ucbio_match(parent, cf, aux)
71 	struct device *parent;
72 	struct cfdata *cf;
73 	void *aux;
74 {
75 	return (1);
76 }
77 
78 void
79 ucbio_attach(parent, self, aux)
80 	struct device *parent;
81 	struct device *self;
82 	void *aux;
83 {
84 	struct ucb1200_attach_args *ucba = aux;
85 	struct ucbio_attach_args uia;
86 	int port;
87 
88 	printf("\n");
89 
90 	uia.uia_tc = ucba->ucba_tc;
91 	for (port = 0; port < UCB1200_IOPORT_MAX; port++) {
92 		uia.uia_port = port;
93 		config_found_sm(self, &uia, ucbio_print, ucbio_submatch);
94 	}
95 }
96 
97 int
98 ucbio_submatch(parent, cf, aux)
99 	struct device *parent;
100 	struct cfdata *cf;
101 	void *aux;
102 {
103 	struct ucbio_attach_args *uia = aux;
104 	platid_mask_t mask;
105 
106 	if (cf->cf_loc[NEWGPBUSIFCF_PORT] != uia->uia_port)
107 		return (0);
108 
109 	mask = PLATID_DEREF(cf->cf_loc[NEWGPBUSIFCF_PLATFORM]);
110 	if (!platid_match(&platid, &mask))
111 		return (0);
112 
113 	uia->uia_id = cf->cf_loc[NEWGPBUSIFCF_ID];
114 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
115 }
116 
117 int
118 ucbio_print(aux, pnp)
119 	void *aux;
120 	const char *pnp;
121 {
122 	struct ucbio_attach_args *uia = aux;
123 
124 	if (!pnp)
125 		printf(" port %d \"%s\"", uia->uia_port,
126 		       btnmgr_name(uia->uia_id));
127 
128 	return (QUIET);
129 }
130