xref: /netbsd/sys/arch/hpcmips/dev/ucbio.c (revision bf9ec67e)
1 /*	$NetBSD: ucbio.c,v 1.5 2002/01/29 18:53:12 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 
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 struct cfattach ucbio_ca = {
79 	sizeof(struct ucbio_softc), ucbio_match, ucbio_attach
80 };
81 
82 /* I/O */
83 static int betty_in(hpcio_chip_t, int);
84 static void betty_out(hpcio_chip_t, int, int);
85 /* interrupt */
86 static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
87     int (*)(void *), void *);
88 static void betty_intr_disestablish(hpcio_chip_t, void *);
89 /* debug */
90 static void betty_update(hpcio_chip_t);
91 static void betty_dump(hpcio_chip_t);
92 
93 int
94 ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
95 {
96 	return (1);
97 }
98 
99 void
100 ucbio_attach(struct device *parent, struct device *self, void *aux)
101 {
102 	struct ucb1200_attach_args *ucba = aux;
103 	struct ucbio_softc *sc = (void *)self;
104 	struct hpcio_chip *hc = &sc->sc_hc;
105 
106 	sc->sc_tc = ucba->ucba_tc;
107 	printf("\n");
108 
109 	hc->hc_sc		 = sc;
110 	hc->hc_chipid		 = 2;
111 	hc->hc_name		 = "UCB1200";
112 	hc->hc_portread		 = betty_in;
113 	hc->hc_portwrite	 = betty_out;
114 	hc->hc_intr_establish	 = betty_intr_establish;
115 	hc->hc_intr_disestablish = betty_intr_disestablish;
116 	hc->hc_update		 = betty_update;
117 	hc->hc_dump		 = betty_dump;
118 
119 	tx_conf_register_ioman(sc->sc_tc, hc);
120 
121 	hpcio_update(hc);
122 	hpcio_dump(hc);
123 }
124 
125 /* basic I/O */
126 static void
127 betty_out(hpcio_chip_t hc, int port, int onoff)
128 {
129 	struct ucbio_softc *sc = hc->hc_sc;
130 	tx_chipset_tag_t tc = sc->sc_tc;
131 	txreg_t reg, pos;
132 
133 	pos = 1 << port;
134 	reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
135 	if (onoff)
136 		reg |= pos;
137 	else
138 		reg &= ~pos;
139 	txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
140 }
141 
142 static int
143 betty_in(hpcio_chip_t hc, int port)
144 {
145 	struct ucbio_softc *sc = hc->hc_sc;
146 	tx_chipset_tag_t tc = sc->sc_tc;
147 	txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
148 
149 	return (reg & (1 << port));
150 }
151 
152 /* interrupt method not implemented */
153 static hpcio_intr_handle_t
154 betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
155     void *func_arg)
156 {
157 	struct ucbio_softc *sc = hc->hc_sc;
158 
159 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
160 	    __FUNCTION__);
161 
162 	return (0);
163 }
164 
165 static void
166 betty_intr_disestablish(hpcio_chip_t hc, void *ih)
167 {
168 	struct ucbio_softc *sc = hc->hc_sc;
169 
170 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
171 	    __FUNCTION__);
172 }
173 
174 /* debug */
175 static void
176 betty_update(hpcio_chip_t hc)
177 {
178 	struct ucbio_softc *sc = hc->hc_sc;
179 	tx_chipset_tag_t tc = sc->sc_tc;
180 	struct betty_port_status *stat = &sc->sc_stat;
181 	u_int16_t dir, data;
182 
183 	sc->sc_ostat = *stat; /* save old status */
184 	dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
185 	data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
186 	stat->out = data & dir;
187 	stat->in = data & ~dir;
188 }
189 
190 static void
191 betty_dump(hpcio_chip_t hc)
192 {
193 #ifdef UCBIO_DEBUG
194 	struct ucbio_softc *sc = hc->hc_sc;
195 	struct betty_port_status *stat = &sc->sc_stat;
196 
197 	printf("[BETTY I/O]\n");
198 	printf("IN  ");
199 	dbg_bit_print(stat->in);
200 	printf("OUT ");
201 	dbg_bit_print(stat->out);
202 	printf("DIR ");
203 	dbg_bit_print(stat->dir);
204 #endif /* UCBIO_DEBUG */
205 }
206