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