xref: /netbsd/sys/arch/hpcmips/dev/ucbio.c (revision c4a72b64)
1 /*	$NetBSD: ucbio.c,v 1.7 2002/10/02 05:26:47 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
41  *	General Purpose I/O part.
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 
48 #include <machine/bus.h>
49 #include <machine/intr.h>
50 
51 #include <hpcmips/tx/tx39var.h>
52 #include <hpcmips/tx/tx39sibvar.h>
53 #include <hpcmips/tx/tx39sibreg.h>
54 
55 #include <hpcmips/dev/ucb1200var.h>
56 #include <hpcmips/dev/ucb1200reg.h>
57 
58 #include <dev/hpc/hpciovar.h>	/* I/O manager */
59 
60 #include <machine/debug.h>
61 
62 int ucbio_match(struct device*, struct cfdata *, void *);
63 void ucbio_attach(struct device*, struct device *, void *);
64 
65 struct betty_port_status {
66 	u_int16_t dir;
67 	u_int16_t in, out;
68 };
69 
70 struct ucbio_softc {
71 	struct device sc_dev;
72 	tx_chipset_tag_t sc_tc;
73 
74 	struct betty_port_status sc_stat, sc_ostat;
75 	struct hpcio_chip sc_hc;
76 };
77 
78 CFATTACH_DECL(ucbio, sizeof(struct ucbio_softc),
79     ucbio_match, ucbio_attach, NULL, NULL);
80 
81 /* I/O */
82 static int betty_in(hpcio_chip_t, int);
83 static void betty_out(hpcio_chip_t, int, int);
84 /* interrupt */
85 static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
86     int (*)(void *), void *);
87 static void betty_intr_disestablish(hpcio_chip_t, void *);
88 /* debug */
89 static void betty_update(hpcio_chip_t);
90 static void betty_dump(hpcio_chip_t);
91 
92 int
93 ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
94 {
95 	return (1);
96 }
97 
98 void
99 ucbio_attach(struct device *parent, struct device *self, void *aux)
100 {
101 	struct ucb1200_attach_args *ucba = aux;
102 	struct ucbio_softc *sc = (void *)self;
103 	struct hpcio_chip *hc = &sc->sc_hc;
104 
105 	sc->sc_tc = ucba->ucba_tc;
106 	printf("\n");
107 
108 	hc->hc_sc		 = sc;
109 	hc->hc_chipid		 = 2;
110 	hc->hc_name		 = "UCB1200";
111 	hc->hc_portread		 = betty_in;
112 	hc->hc_portwrite	 = betty_out;
113 	hc->hc_intr_establish	 = betty_intr_establish;
114 	hc->hc_intr_disestablish = betty_intr_disestablish;
115 	hc->hc_update		 = betty_update;
116 	hc->hc_dump		 = betty_dump;
117 
118 	tx_conf_register_ioman(sc->sc_tc, hc);
119 
120 	hpcio_update(hc);
121 	hpcio_dump(hc);
122 }
123 
124 /* basic I/O */
125 static void
126 betty_out(hpcio_chip_t hc, int port, int onoff)
127 {
128 	struct ucbio_softc *sc = hc->hc_sc;
129 	tx_chipset_tag_t tc = sc->sc_tc;
130 	txreg_t reg, pos;
131 
132 	pos = 1 << port;
133 	reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
134 	if (onoff)
135 		reg |= pos;
136 	else
137 		reg &= ~pos;
138 	txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
139 }
140 
141 static int
142 betty_in(hpcio_chip_t hc, int port)
143 {
144 	struct ucbio_softc *sc = hc->hc_sc;
145 	tx_chipset_tag_t tc = sc->sc_tc;
146 	txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
147 
148 	return (reg & (1 << port));
149 }
150 
151 /* interrupt method not implemented */
152 static hpcio_intr_handle_t
153 betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
154     void *func_arg)
155 {
156 	struct ucbio_softc *sc = hc->hc_sc;
157 
158 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
159 	    __FUNCTION__);
160 
161 	return (0);
162 }
163 
164 static void
165 betty_intr_disestablish(hpcio_chip_t hc, void *ih)
166 {
167 	struct ucbio_softc *sc = hc->hc_sc;
168 
169 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
170 	    __FUNCTION__);
171 }
172 
173 /* debug */
174 static void
175 betty_update(hpcio_chip_t hc)
176 {
177 	struct ucbio_softc *sc = hc->hc_sc;
178 	tx_chipset_tag_t tc = sc->sc_tc;
179 	struct betty_port_status *stat = &sc->sc_stat;
180 	u_int16_t dir, data;
181 
182 	sc->sc_ostat = *stat; /* save old status */
183 	dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
184 	data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
185 	stat->out = data & dir;
186 	stat->in = data & ~dir;
187 }
188 
189 static void
190 betty_dump(hpcio_chip_t hc)
191 {
192 #ifdef UCBIO_DEBUG
193 	struct ucbio_softc *sc = hc->hc_sc;
194 	struct betty_port_status *stat = &sc->sc_stat;
195 
196 	printf("[BETTY I/O]\n");
197 	printf("IN  ");
198 	dbg_bit_print(stat->in);
199 	printf("OUT ");
200 	dbg_bit_print(stat->out);
201 	printf("DIR ");
202 	dbg_bit_print(stat->dir);
203 #endif /* UCBIO_DEBUG */
204 }
205