xref: /netbsd-src/sys/arch/hpcmips/dev/ucbio.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: ucbio.c,v 1.11 2008/04/28 20:23:21 martin 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
34  *	General Purpose I/O part.
35  */
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: ucbio.c,v 1.11 2008/04/28 20:23:21 martin Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 
47 #include <hpcmips/tx/tx39var.h>
48 #include <hpcmips/tx/tx39sibvar.h>
49 #include <hpcmips/tx/tx39sibreg.h>
50 
51 #include <hpcmips/dev/ucb1200var.h>
52 #include <hpcmips/dev/ucb1200reg.h>
53 
54 #include <dev/hpc/hpciovar.h>	/* I/O manager */
55 
56 #include <machine/debug.h>
57 
58 int ucbio_match(struct device*, struct cfdata *, void *);
59 void ucbio_attach(struct device*, struct device *, void *);
60 
61 struct betty_port_status {
62 	u_int16_t dir;
63 	u_int16_t in, out;
64 };
65 
66 struct ucbio_softc {
67 	struct device sc_dev;
68 	tx_chipset_tag_t sc_tc;
69 
70 	struct betty_port_status sc_stat, sc_ostat;
71 	struct hpcio_chip sc_hc;
72 };
73 
74 CFATTACH_DECL(ucbio, sizeof(struct ucbio_softc),
75     ucbio_match, ucbio_attach, NULL, NULL);
76 
77 /* I/O */
78 static int betty_in(hpcio_chip_t, int);
79 static void betty_out(hpcio_chip_t, int, int);
80 /* interrupt */
81 static hpcio_intr_handle_t betty_intr_establish(hpcio_chip_t, int, int,
82     int (*)(void *), void *);
83 static void betty_intr_disestablish(hpcio_chip_t, void *);
84 /* debug */
85 static void betty_update(hpcio_chip_t);
86 static void betty_dump(hpcio_chip_t);
87 
88 int
89 ucbio_match(struct device *parent, struct cfdata *cf, void *aux)
90 {
91 	return (1);
92 }
93 
94 void
95 ucbio_attach(struct device *parent, struct device *self, void *aux)
96 {
97 	struct ucb1200_attach_args *ucba = aux;
98 	struct ucbio_softc *sc = (void *)self;
99 	struct hpcio_chip *hc = &sc->sc_hc;
100 
101 	sc->sc_tc = ucba->ucba_tc;
102 	printf("\n");
103 
104 	hc->hc_sc		 = sc;
105 	hc->hc_chipid		 = 2;
106 	hc->hc_name		 = "UCB1200";
107 	hc->hc_portread		 = betty_in;
108 	hc->hc_portwrite	 = betty_out;
109 	hc->hc_intr_establish	 = betty_intr_establish;
110 	hc->hc_intr_disestablish = betty_intr_disestablish;
111 	hc->hc_update		 = betty_update;
112 	hc->hc_dump		 = betty_dump;
113 
114 	tx_conf_register_ioman(sc->sc_tc, hc);
115 
116 	hpcio_update(hc);
117 	hpcio_dump(hc);
118 }
119 
120 /* basic I/O */
121 static void
122 betty_out(hpcio_chip_t hc, int port, int onoff)
123 {
124 	struct ucbio_softc *sc = hc->hc_sc;
125 	tx_chipset_tag_t tc = sc->sc_tc;
126 	txreg_t reg, pos;
127 
128 	pos = 1 << port;
129 	reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
130 	if (onoff)
131 		reg |= pos;
132 	else
133 		reg &= ~pos;
134 	txsibsf0_reg_write(tc, UCB1200_IO_DATA_REG, reg);
135 }
136 
137 static int
138 betty_in(hpcio_chip_t hc, int port)
139 {
140 	struct ucbio_softc *sc = hc->hc_sc;
141 	tx_chipset_tag_t tc = sc->sc_tc;
142 	txreg_t reg = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
143 
144 	return (reg & (1 << port));
145 }
146 
147 /* interrupt method not implemented */
148 static hpcio_intr_handle_t
149 betty_intr_establish(hpcio_chip_t hc, int port, int mode, int (*func)(void *),
150     void *func_arg)
151 {
152 	struct ucbio_softc *sc = hc->hc_sc;
153 
154 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
155 	    __func__);
156 
157 	return (0);
158 }
159 
160 static void
161 betty_intr_disestablish(hpcio_chip_t hc, void *ih)
162 {
163 	struct ucbio_softc *sc = hc->hc_sc;
164 
165 	printf("%s: %s not implemented.\n", sc->sc_dev.dv_xname,
166 	    __func__);
167 }
168 
169 /* debug */
170 static void
171 betty_update(hpcio_chip_t hc)
172 {
173 	struct ucbio_softc *sc = hc->hc_sc;
174 	tx_chipset_tag_t tc = sc->sc_tc;
175 	struct betty_port_status *stat = &sc->sc_stat;
176 	u_int16_t dir, data;
177 
178 	sc->sc_ostat = *stat; /* save old status */
179 	dir = stat->dir = txsibsf0_reg_read(tc, UCB1200_IO_DIR_REG);
180 	data = txsibsf0_reg_read(tc, UCB1200_IO_DATA_REG);
181 	stat->out = data & dir;
182 	stat->in = data & ~dir;
183 }
184 
185 static void
186 betty_dump(hpcio_chip_t hc)
187 {
188 #ifdef UCBIO_DEBUG
189 	struct ucbio_softc *sc = hc->hc_sc;
190 	struct betty_port_status *stat = &sc->sc_stat;
191 
192 	printf("[BETTY I/O]\n");
193 	printf("IN  ");
194 	dbg_bit_print(stat->in);
195 	printf("OUT ");
196 	dbg_bit_print(stat->out);
197 	printf("DIR ");
198 	dbg_bit_print(stat->dir);
199 #endif /* UCBIO_DEBUG */
200 }
201