xref: /netbsd-src/sys/arch/hpcmips/dev/ucb1200.c (revision 1ca5c1b28139779176bd5c13ad7c5f25c0bcd5f8)
1 /*	$NetBSD: ucb1200.c,v 1.6 2001/09/15 12:47:07 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  */
42 #define UCB1200DEBUG
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 #ifdef UCB1200DEBUG
60 int	ucb1200debug = 1;
61 #define	DPRINTF(arg) if (ucb1200debug) printf arg;
62 #define	DPRINTFN(n, arg) if (ucb1200debug > (n)) printf arg;
63 #else
64 #define	DPRINTF(arg)
65 #define DPRINTFN(n, arg)
66 #endif
67 
68 struct ucbchild_state {
69 	int (*cs_busy)(void *);
70 	void *cs_arg;
71 };
72 
73 struct ucb1200_softc {
74 	struct device	sc_dev;
75 	struct device	*sc_parent; /* parent (TX39 SIB module) */
76 	tx_chipset_tag_t sc_tc;
77 
78 	int		sc_snd_rate; /* passed down from SIB module */
79 	int		sc_tel_rate;
80 
81 	/* inquire child module state */
82 	struct ucbchild_state sc_child[UCB1200_MODULE_MAX];
83 };
84 
85 int	ucb1200_match(struct device *, struct cfdata *, void *);
86 void	ucb1200_attach(struct device *, struct device *, void *);
87 int	ucb1200_print(void *, const char *);
88 int	ucb1200_search(struct device *, struct cfdata *, void *);
89 int	ucb1200_check_id(u_int16_t, int);
90 
91 #ifdef UCB1200DEBUG
92 void	ucb1200_dump(struct ucb1200_softc *);
93 #endif
94 
95 struct cfattach ucb_ca = {
96 	sizeof(struct ucb1200_softc), ucb1200_match, ucb1200_attach
97 };
98 
99 const struct ucb_id {
100 	u_int16_t	id;
101 	const char	*product;
102 } ucb_id[] = {
103 	{ UCB1100_ID,	"PHILIPS UCB1100" },
104 	{ UCB1200_ID,	"PHILIPS UCB1200" },
105 	{ UCB1300_ID,	"PHILIPS UCB1300" },
106 	{ TC35413F_ID,	"TOSHIBA TC35413F" },
107 	{ 0, 0 }
108 };
109 
110 int
111 ucb1200_match(struct device *parent, struct cfdata *cf, void *aux)
112 {
113 	struct txsib_attach_args *sa = aux;
114 	u_int16_t reg;
115 
116 	if (sa->sa_slot != 0) /* UCB1200 must be subframe 0 */
117 		return (0);
118 	reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
119 
120 	return (ucb1200_check_id(reg, 0));
121 }
122 
123 void
124 ucb1200_attach(struct device *parent, struct device *self, void *aux)
125 {
126 	struct txsib_attach_args *sa = aux;
127 	struct ucb1200_softc *sc = (void*)self;
128 	u_int16_t reg;
129 
130 	printf(": ");
131 	sc->sc_tc = sa->sa_tc;
132 	sc->sc_parent = parent;
133 	sc->sc_snd_rate = sa->sa_snd_rate;
134 	sc->sc_tel_rate = sa->sa_tel_rate;
135 
136 	tx39sib_enable1(sc->sc_parent);
137 	tx39sib_enable2(sc->sc_parent);
138 
139 #ifdef UCB1200DEBUG
140 	if (ucb1200debug)
141 		ucb1200_dump(sc);
142 #endif
143 	reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
144 	(void)ucb1200_check_id(reg, 1);
145 	printf("\n");
146 
147 	config_search(ucb1200_search, self, ucb1200_print);
148 }
149 
150 int
151 ucb1200_search(struct device *parent, struct cfdata *cf, void *aux)
152 {
153 	struct ucb1200_softc *sc = (void*)parent;
154 	struct ucb1200_attach_args ucba;
155 
156 	ucba.ucba_tc = sc->sc_tc;
157 	ucba.ucba_snd_rate = sc->sc_snd_rate;
158 	ucba.ucba_tel_rate = sc->sc_tel_rate;
159 	ucba.ucba_sib	   = sc->sc_parent;
160 	ucba.ucba_ucb	   = parent;
161 
162 	if ((*cf->cf_attach->ca_match)(parent, cf, &ucba))
163 		config_attach(parent, cf, &ucba, ucb1200_print);
164 
165 	return (0);
166 }
167 
168 int
169 ucb1200_print(void *aux, const char *pnp)
170 {
171 
172 	return (pnp ? QUIET : UNCONF);
173 }
174 
175 int
176 ucb1200_check_id(u_int16_t idreg, int print)
177 {
178 	int i;
179 
180 	for (i = 0; ucb_id[i].product; i++) {
181 		if (ucb_id[i].id == idreg) {
182 			if (print) {
183 				printf("%s", ucb_id[i].product);
184 			}
185 
186 			return (1);
187 		}
188 	}
189 
190 	return (0);
191 }
192 
193 void
194 ucb1200_state_install(struct device *dev, int (*sfun)(void *), void *sarg,
195     int sid)
196 {
197 	struct ucb1200_softc *sc = (void*)dev;
198 
199 	sc->sc_child[sid].cs_busy = sfun;
200 	sc->sc_child[sid].cs_arg = sarg;
201 }
202 
203 int
204 ucb1200_state_idle(dev)
205 	struct device *dev;
206 {
207 	struct ucb1200_softc *sc = (void*)dev;
208 	struct ucbchild_state *cs;
209 	int i;
210 
211 	cs = sc->sc_child;
212 	for (i = 0; i < UCB1200_MODULE_MAX; i++, cs++)
213 		if (cs->cs_busy)
214 			if ((*cs->cs_busy)(cs->cs_arg))
215 				return (0);
216 
217 	return (1); /* idle state */
218 }
219 
220 #ifdef UCB1200DEBUG
221 void
222 ucb1200_dump(struct ucb1200_softc *sc)
223 {
224         const char *regname[] = {
225                 "IO_DATA        ",
226                 "IO_DIR         ",
227                 "POSINTEN       ",
228                 "NEGINTEN       ",
229                 "INTSTAT        ",
230                 "TELECOMCTRLA   ",
231                 "TELECOMCTRLB   ",
232                 "AUDIOCTRLA     ",
233                 "AUDIOCTRLB     ",
234                 "TOUCHSCREENCTRL",
235                 "ADCCTRL        ",
236                 "ADCDATA        ",
237                 "ID             ",
238                 "MODE           ",
239                 "RESERVED       ",
240                 "NULL           "
241         };
242 	tx_chipset_tag_t tc;
243 	u_int16_t reg;
244 	int i;
245 
246 	tc = sc->sc_tc;
247 
248 	printf("\n\t[UCB1200 register]\n");
249 	for (i = 0; i < 16; i++) {
250 		reg = txsibsf0_reg_read(tc, i);
251 		printf("%s(%02d) 0x%04x ", regname[i], i, reg);
252 		bitdisp(reg);
253 	}
254 }
255 #endif /* UCB1200DEBUG */
256