xref: /netbsd-src/sys/arch/hpcmips/dev/ucbio.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: ucbio.c,v 1.8 2003/07/15 02:29:30 lukem 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/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: ucbio.c,v 1.8 2003/07/15 02:29:30 lukem Exp $");
46 
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 
51 #include <machine/bus.h>
52 #include <machine/intr.h>
53 
54 #include <hpcmips/tx/tx39var.h>
55 #include <hpcmips/tx/tx39sibvar.h>
56 #include <hpcmips/tx/tx39sibreg.h>
57 
58 #include <hpcmips/dev/ucb1200var.h>
59 #include <hpcmips/dev/ucb1200reg.h>
60 
61 #include <dev/hpc/hpciovar.h>	/* I/O manager */
62 
63 #include <machine/debug.h>
64 
65 int ucbio_match(struct device*, struct cfdata *, void *);
66 void ucbio_attach(struct device*, struct device *, void *);
67 
68 struct betty_port_status {
69 	u_int16_t dir;
70 	u_int16_t in, out;
71 };
72 
73 struct ucbio_softc {
74 	struct device sc_dev;
75 	tx_chipset_tag_t sc_tc;
76 
77 	struct betty_port_status sc_stat, sc_ostat;
78 	struct hpcio_chip sc_hc;
79 };
80 
81 CFATTACH_DECL(ucbio, sizeof(struct ucbio_softc),
82     ucbio_match, ucbio_attach, NULL, NULL);
83 
84 /* I/O */
85 static int betty_in(hpcio_chip_t, int);
86 static void betty_out(hpcio_chip_t, int, int);
87 /* interrupt */
88 static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
89     int (*)(void *), void *);
90 static void betty_intr_disestablish(hpcio_chip_t, void *);
91 /* debug */
92 static void betty_update(hpcio_chip_t);
93 static void betty_dump(hpcio_chip_t);
94 
95 int
96 ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
97 {
98 	return (1);
99 }
100 
101 void
102 ucbio_attach(struct device *parent, struct device *self, void *aux)
103 {
104 	struct ucb1200_attach_args *ucba = aux;
105 	struct ucbio_softc *sc = (void *)self;
106 	struct hpcio_chip *hc = &sc->sc_hc;
107 
108 	sc->sc_tc = ucba->ucba_tc;
109 	printf("\n");
110 
111 	hc->hc_sc		 = sc;
112 	hc->hc_chipid		 = 2;
113 	hc->hc_name		 = "UCB1200";
114 	hc->hc_portread		 = betty_in;
115 	hc->hc_portwrite	 = betty_out;
116 	hc->hc_intr_establish	 = betty_intr_establish;
117 	hc->hc_intr_disestablish = betty_intr_disestablish;
118 	hc->hc_update		 = betty_update;
119 	hc->hc_dump		 = betty_dump;
120 
121 	tx_conf_register_ioman(sc->sc_tc, hc);
122 
123 	hpcio_update(hc);
124 	hpcio_dump(hc);
125 }
126 
127 /* basic I/O */
128 static void
129 betty_out(hpcio_chip_t hc, int port, int onoff)
130 {
131 	struct ucbio_softc *sc = hc->hc_sc;
132 	tx_chipset_tag_t tc = sc->sc_tc;
133 	txreg_t reg, pos;
134 
135 	pos = 1 << port;
136 	reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
137 	if (onoff)
138 		reg |= pos;
139 	else
140 		reg &= ~pos;
141 	txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
142 }
143 
144 static int
145 betty_in(hpcio_chip_t hc, int port)
146 {
147 	struct ucbio_softc *sc = hc->hc_sc;
148 	tx_chipset_tag_t tc = sc->sc_tc;
149 	txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
150 
151 	return (reg & (1 << port));
152 }
153 
154 /* interrupt method not implemented */
155 static hpcio_intr_handle_t
156 betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
157     void *func_arg)
158 {
159 	struct ucbio_softc *sc = hc->hc_sc;
160 
161 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
162 	    __FUNCTION__);
163 
164 	return (0);
165 }
166 
167 static void
168 betty_intr_disestablish(hpcio_chip_t hc, void *ih)
169 {
170 	struct ucbio_softc *sc = hc->hc_sc;
171 
172 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
173 	    __FUNCTION__);
174 }
175 
176 /* debug */
177 static void
178 betty_update(hpcio_chip_t hc)
179 {
180 	struct ucbio_softc *sc = hc->hc_sc;
181 	tx_chipset_tag_t tc = sc->sc_tc;
182 	struct betty_port_status *stat = &sc->sc_stat;
183 	u_int16_t dir, data;
184 
185 	sc->sc_ostat = *stat; /* save old status */
186 	dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
187 	data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
188 	stat->out = data & dir;
189 	stat->in = data & ~dir;
190 }
191 
192 static void
193 betty_dump(hpcio_chip_t hc)
194 {
195 #ifdef UCBIO_DEBUG
196 	struct ucbio_softc *sc = hc->hc_sc;
197 	struct betty_port_status *stat = &sc->sc_stat;
198 
199 	printf("[BETTY I/O]\n");
200 	printf("IN  ");
201 	dbg_bit_print(stat->in);
202 	printf("OUT ");
203 	dbg_bit_print(stat->out);
204 	printf("DIR ");
205 	dbg_bit_print(stat->dir);
206 #endif /* UCBIO_DEBUG */
207 }
208