ucbio.c revision 1.2 1 /* $NetBSD: ucbio.c,v 1.2 2000/10/22 10:42:32 uch 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 #include "opt_tx39_debug.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/device.h>
48
49 #include <machine/bus.h>
50 #include <machine/intr.h>
51
52 #include <hpcmips/tx/tx39var.h>
53 #include <hpcmips/tx/tx39sibvar.h>
54 #include <hpcmips/tx/tx39sibreg.h>
55
56 #include <hpcmips/dev/ucb1200var.h>
57 #include <hpcmips/dev/ucb1200reg.h>
58
59 int ucbio_match(struct device*, struct cfdata *, void *);
60 void ucbio_attach(struct device*, struct device *, void *);
61
62 struct betty_port_status {
63 u_int16_t dir;
64 u_int16_t in, out;
65 };
66
67 struct ucbio_softc {
68 struct device sc_dev;
69 tx_chipset_tag_t sc_tc;
70
71 struct betty_port_status sc_stat, sc_ostat;
72 struct txio_ops sc_betty_ops;
73 };
74
75 struct cfattach ucbio_ca = {
76 sizeof(struct ucbio_softc), ucbio_match, ucbio_attach
77 };
78
79 /* I/O */
80 static int betty_in(void *, int);
81 static void betty_out(void *, int, int);
82 /* interrupt */
83 static void betty_intr_map(void *, int, int *, int *);
84 static void *betty_intr_establish(void *, int, int (*)(void *), void *);
85 static void betty_intr_disestablish(void *, void *);
86 /* debug */
87 static void betty_update(void *);
88 static void betty_dump(void *);
89
90 int
91 ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
92 {
93 return 1;
94 }
95
96 void
97 ucbio_attach(struct device *parent, struct device *self, void *aux)
98 {
99 struct ucb1200_attach_args *ucba = aux;
100 struct ucbio_softc *sc = (void *)self;
101 struct txio_ops *ops = &sc->sc_betty_ops;
102
103 sc->sc_tc = ucba->ucba_tc;
104 printf("\n");
105
106 ops->_v = sc;
107 ops->_group = BETTY;
108 ops->_in = betty_in;
109 ops->_out = betty_out;
110 ops->_intr_map = betty_intr_map;
111 ops->_intr_establish = betty_intr_establish;
112 ops->_intr_disestablish = betty_intr_disestablish;
113 ops->_update = betty_update;
114 ops->_dump = betty_dump;
115
116 tx_conf_register_ioman(sc->sc_tc, ops);
117
118 tx_ioman_update(BETTY);
119 tx_ioman_dump(BETTY);
120 }
121
122 /* basic I/O */
123 static void
124 betty_out(void *arg, int port, int onoff)
125 {
126 struct ucbio_softc *sc = arg;
127 tx_chipset_tag_t tc = sc->sc_tc;
128 txreg_t reg, pos;
129
130 pos = 1 << port;
131 reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
132 if (onoff)
133 reg |= pos;
134 else
135 reg &= ~pos;
136 txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
137 }
138
139 static int
140 betty_in(void *arg, int port)
141 {
142 struct ucbio_softc *sc = arg;
143 tx_chipset_tag_t tc = sc->sc_tc;
144 txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
145 return reg & (1 << port);
146 }
147
148 /* interrupt method not implemented */
149 static void
150 betty_intr_map(void *arg, int port, int *pedge, int *nedge)
151 {
152 }
153
154 static void *
155 betty_intr_establish(void *arg, int edge, int (*func)(void *), void *func_arg)
156 {
157 struct ucbio_softc *sc = arg;
158 printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
159 __FUNCTION__);
160 return 0;
161 }
162
163 static void
164 betty_intr_disestablish(void *arg, void *ih)
165 {
166 struct ucbio_softc *sc = arg;
167 printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
168 __FUNCTION__);
169 }
170
171 /* debug */
172 static void
173 betty_update(void *arg)
174 {
175 struct ucbio_softc *sc = arg;
176 tx_chipset_tag_t tc = sc->sc_tc;
177 struct betty_port_status *stat = &sc->sc_stat;
178 u_int16_t dir, data;
179
180 sc->sc_ostat = *stat; /* save old status */
181 dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
182 data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
183 stat->out = data & dir;
184 stat->in = data & ~dir;
185 }
186
187 static void
188 betty_dump(void *arg)
189 {
190 struct ucbio_softc *sc = arg;
191 struct betty_port_status *stat = &sc->sc_stat;
192
193 printf("[BETTY I/O]\n");
194 printf("IN ");
195 bitdisp(stat->in);
196 printf("OUT ");
197 bitdisp(stat->out);
198 printf("DIR ");
199 bitdisp(stat->dir);
200 }
201
202
203
204
205