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