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