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