ucb1200.c revision 1.6.4.4 1 1.6.4.4 nathanw /* $NetBSD: ucb1200.c,v 1.6.4.4 2002/10/18 02:37:08 nathanw Exp $ */
2 1.6.4.2 nathanw
3 1.6.4.2 nathanw /*-
4 1.6.4.2 nathanw * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.6.4.2 nathanw * All rights reserved.
6 1.6.4.2 nathanw *
7 1.6.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.6.4.2 nathanw * by UCHIYAMA Yasushi.
9 1.6.4.2 nathanw *
10 1.6.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.6.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.6.4.2 nathanw * are met:
13 1.6.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.6.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.6.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.6.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.6.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.6.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.6.4.2 nathanw * must display the following acknowledgement:
20 1.6.4.2 nathanw * This product includes software developed by the NetBSD
21 1.6.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.6.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.6.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.6.4.2 nathanw * from this software without specific prior written permission.
25 1.6.4.2 nathanw *
26 1.6.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.6.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.6.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.6.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.6.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.6.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.6.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.6.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.6.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.6.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.6.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.6.4.2 nathanw */
38 1.6.4.2 nathanw
39 1.6.4.2 nathanw /*
40 1.6.4.2 nathanw * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
41 1.6.4.2 nathanw */
42 1.6.4.2 nathanw
43 1.6.4.2 nathanw #include <sys/param.h>
44 1.6.4.2 nathanw #include <sys/systm.h>
45 1.6.4.2 nathanw #include <sys/device.h>
46 1.6.4.2 nathanw
47 1.6.4.2 nathanw #include <machine/bus.h>
48 1.6.4.2 nathanw #include <machine/intr.h>
49 1.6.4.2 nathanw
50 1.6.4.2 nathanw #include <hpcmips/tx/tx39var.h>
51 1.6.4.2 nathanw #include <hpcmips/tx/tx39sibvar.h>
52 1.6.4.2 nathanw #include <hpcmips/tx/tx39sibreg.h>
53 1.6.4.2 nathanw
54 1.6.4.2 nathanw #include <hpcmips/dev/ucb1200var.h>
55 1.6.4.2 nathanw #include <hpcmips/dev/ucb1200reg.h>
56 1.6.4.2 nathanw
57 1.6.4.2 nathanw #ifdef UCB1200_DEBUG
58 1.6.4.2 nathanw #define DPRINTF_ENABLE
59 1.6.4.2 nathanw #define DPRINTF_DEBUG ucb1200_debug
60 1.6.4.2 nathanw #endif
61 1.6.4.2 nathanw #include <machine/debug.h>
62 1.6.4.2 nathanw
63 1.6.4.2 nathanw struct ucbchild_state {
64 1.6.4.2 nathanw int (*cs_busy)(void *);
65 1.6.4.2 nathanw void *cs_arg;
66 1.6.4.2 nathanw };
67 1.6.4.2 nathanw
68 1.6.4.2 nathanw struct ucb1200_softc {
69 1.6.4.2 nathanw struct device sc_dev;
70 1.6.4.2 nathanw struct device *sc_parent; /* parent (TX39 SIB module) */
71 1.6.4.2 nathanw tx_chipset_tag_t sc_tc;
72 1.6.4.2 nathanw
73 1.6.4.2 nathanw int sc_snd_rate; /* passed down from SIB module */
74 1.6.4.2 nathanw int sc_tel_rate;
75 1.6.4.2 nathanw
76 1.6.4.2 nathanw /* inquire child module state */
77 1.6.4.2 nathanw struct ucbchild_state sc_child[UCB1200_MODULE_MAX];
78 1.6.4.2 nathanw };
79 1.6.4.2 nathanw
80 1.6.4.2 nathanw int ucb1200_match(struct device *, struct cfdata *, void *);
81 1.6.4.2 nathanw void ucb1200_attach(struct device *, struct device *, void *);
82 1.6.4.2 nathanw int ucb1200_print(void *, const char *);
83 1.6.4.2 nathanw int ucb1200_search(struct device *, struct cfdata *, void *);
84 1.6.4.2 nathanw int ucb1200_check_id(u_int16_t, int);
85 1.6.4.2 nathanw
86 1.6.4.2 nathanw #ifdef UCB1200_DEBUG
87 1.6.4.2 nathanw void ucb1200_dump(struct ucb1200_softc *);
88 1.6.4.2 nathanw #endif
89 1.6.4.2 nathanw
90 1.6.4.4 nathanw CFATTACH_DECL(ucb, sizeof(struct ucb1200_softc),
91 1.6.4.4 nathanw ucb1200_match, ucb1200_attach, NULL, NULL);
92 1.6.4.2 nathanw
93 1.6.4.2 nathanw const struct ucb_id {
94 1.6.4.2 nathanw u_int16_t id;
95 1.6.4.2 nathanw const char *product;
96 1.6.4.2 nathanw } ucb_id[] = {
97 1.6.4.2 nathanw { UCB1100_ID, "PHILIPS UCB1100" },
98 1.6.4.2 nathanw { UCB1200_ID, "PHILIPS UCB1200" },
99 1.6.4.2 nathanw { UCB1300_ID, "PHILIPS UCB1300" },
100 1.6.4.2 nathanw { TC35413F_ID, "TOSHIBA TC35413F" },
101 1.6.4.2 nathanw { 0, 0 }
102 1.6.4.2 nathanw };
103 1.6.4.2 nathanw
104 1.6.4.2 nathanw int
105 1.6.4.2 nathanw ucb1200_match(struct device *parent, struct cfdata *cf, void *aux)
106 1.6.4.2 nathanw {
107 1.6.4.2 nathanw struct txsib_attach_args *sa = aux;
108 1.6.4.2 nathanw u_int16_t reg;
109 1.6.4.2 nathanw
110 1.6.4.2 nathanw if (sa->sa_slot != 0) /* UCB1200 must be subframe 0 */
111 1.6.4.2 nathanw return (0);
112 1.6.4.2 nathanw reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
113 1.6.4.2 nathanw
114 1.6.4.2 nathanw return (ucb1200_check_id(reg, 0));
115 1.6.4.2 nathanw }
116 1.6.4.2 nathanw
117 1.6.4.2 nathanw void
118 1.6.4.2 nathanw ucb1200_attach(struct device *parent, struct device *self, void *aux)
119 1.6.4.2 nathanw {
120 1.6.4.2 nathanw struct txsib_attach_args *sa = aux;
121 1.6.4.2 nathanw struct ucb1200_softc *sc = (void*)self;
122 1.6.4.2 nathanw u_int16_t reg;
123 1.6.4.2 nathanw
124 1.6.4.2 nathanw printf(": ");
125 1.6.4.2 nathanw sc->sc_tc = sa->sa_tc;
126 1.6.4.2 nathanw sc->sc_parent = parent;
127 1.6.4.2 nathanw sc->sc_snd_rate = sa->sa_snd_rate;
128 1.6.4.2 nathanw sc->sc_tel_rate = sa->sa_tel_rate;
129 1.6.4.2 nathanw
130 1.6.4.2 nathanw tx39sib_enable1(sc->sc_parent);
131 1.6.4.2 nathanw tx39sib_enable2(sc->sc_parent);
132 1.6.4.2 nathanw
133 1.6.4.2 nathanw #ifdef UCB1200_DEBUG
134 1.6.4.2 nathanw if (ucb1200_debug)
135 1.6.4.2 nathanw ucb1200_dump(sc);
136 1.6.4.2 nathanw #endif
137 1.6.4.2 nathanw reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
138 1.6.4.2 nathanw (void)ucb1200_check_id(reg, 1);
139 1.6.4.2 nathanw printf("\n");
140 1.6.4.2 nathanw
141 1.6.4.2 nathanw config_search(ucb1200_search, self, ucb1200_print);
142 1.6.4.2 nathanw }
143 1.6.4.2 nathanw
144 1.6.4.2 nathanw int
145 1.6.4.2 nathanw ucb1200_search(struct device *parent, struct cfdata *cf, void *aux)
146 1.6.4.2 nathanw {
147 1.6.4.2 nathanw struct ucb1200_softc *sc = (void*)parent;
148 1.6.4.2 nathanw struct ucb1200_attach_args ucba;
149 1.6.4.2 nathanw
150 1.6.4.2 nathanw ucba.ucba_tc = sc->sc_tc;
151 1.6.4.2 nathanw ucba.ucba_snd_rate = sc->sc_snd_rate;
152 1.6.4.2 nathanw ucba.ucba_tel_rate = sc->sc_tel_rate;
153 1.6.4.2 nathanw ucba.ucba_sib = sc->sc_parent;
154 1.6.4.2 nathanw ucba.ucba_ucb = parent;
155 1.6.4.2 nathanw
156 1.6.4.4 nathanw if (config_match(parent, cf, &ucba))
157 1.6.4.2 nathanw config_attach(parent, cf, &ucba, ucb1200_print);
158 1.6.4.2 nathanw
159 1.6.4.2 nathanw return (0);
160 1.6.4.2 nathanw }
161 1.6.4.2 nathanw
162 1.6.4.2 nathanw int
163 1.6.4.2 nathanw ucb1200_print(void *aux, const char *pnp)
164 1.6.4.2 nathanw {
165 1.6.4.2 nathanw
166 1.6.4.2 nathanw return (pnp ? QUIET : UNCONF);
167 1.6.4.2 nathanw }
168 1.6.4.2 nathanw
169 1.6.4.2 nathanw int
170 1.6.4.2 nathanw ucb1200_check_id(u_int16_t idreg, int print)
171 1.6.4.2 nathanw {
172 1.6.4.2 nathanw int i;
173 1.6.4.2 nathanw
174 1.6.4.2 nathanw for (i = 0; ucb_id[i].product; i++) {
175 1.6.4.2 nathanw if (ucb_id[i].id == idreg) {
176 1.6.4.2 nathanw if (print) {
177 1.6.4.2 nathanw printf("%s", ucb_id[i].product);
178 1.6.4.2 nathanw }
179 1.6.4.2 nathanw
180 1.6.4.2 nathanw return (1);
181 1.6.4.2 nathanw }
182 1.6.4.2 nathanw }
183 1.6.4.2 nathanw
184 1.6.4.2 nathanw return (0);
185 1.6.4.2 nathanw }
186 1.6.4.2 nathanw
187 1.6.4.2 nathanw void
188 1.6.4.2 nathanw ucb1200_state_install(struct device *dev, int (*sfun)(void *), void *sarg,
189 1.6.4.2 nathanw int sid)
190 1.6.4.2 nathanw {
191 1.6.4.2 nathanw struct ucb1200_softc *sc = (void*)dev;
192 1.6.4.2 nathanw
193 1.6.4.2 nathanw sc->sc_child[sid].cs_busy = sfun;
194 1.6.4.2 nathanw sc->sc_child[sid].cs_arg = sarg;
195 1.6.4.2 nathanw }
196 1.6.4.2 nathanw
197 1.6.4.2 nathanw int
198 1.6.4.2 nathanw ucb1200_state_idle(dev)
199 1.6.4.2 nathanw struct device *dev;
200 1.6.4.2 nathanw {
201 1.6.4.2 nathanw struct ucb1200_softc *sc = (void*)dev;
202 1.6.4.2 nathanw struct ucbchild_state *cs;
203 1.6.4.2 nathanw int i;
204 1.6.4.2 nathanw
205 1.6.4.2 nathanw cs = sc->sc_child;
206 1.6.4.2 nathanw for (i = 0; i < UCB1200_MODULE_MAX; i++, cs++)
207 1.6.4.2 nathanw if (cs->cs_busy)
208 1.6.4.2 nathanw if ((*cs->cs_busy)(cs->cs_arg))
209 1.6.4.2 nathanw return (0);
210 1.6.4.2 nathanw
211 1.6.4.2 nathanw return (1); /* idle state */
212 1.6.4.2 nathanw }
213 1.6.4.2 nathanw
214 1.6.4.2 nathanw #ifdef UCB1200_DEBUG
215 1.6.4.2 nathanw void
216 1.6.4.2 nathanw ucb1200_dump(struct ucb1200_softc *sc)
217 1.6.4.2 nathanw {
218 1.6.4.3 nathanw static const char *const regname[] = {
219 1.6.4.2 nathanw "IO_DATA ",
220 1.6.4.2 nathanw "IO_DIR ",
221 1.6.4.2 nathanw "POSINTEN ",
222 1.6.4.2 nathanw "NEGINTEN ",
223 1.6.4.2 nathanw "INTSTAT ",
224 1.6.4.2 nathanw "TELECOMCTRLA ",
225 1.6.4.2 nathanw "TELECOMCTRLB ",
226 1.6.4.2 nathanw "AUDIOCTRLA ",
227 1.6.4.2 nathanw "AUDIOCTRLB ",
228 1.6.4.2 nathanw "TOUCHSCREENCTRL",
229 1.6.4.2 nathanw "ADCCTRL ",
230 1.6.4.2 nathanw "ADCDATA ",
231 1.6.4.2 nathanw "ID ",
232 1.6.4.2 nathanw "MODE ",
233 1.6.4.2 nathanw "RESERVED ",
234 1.6.4.2 nathanw "NULL "
235 1.6.4.3 nathanw };
236 1.6.4.2 nathanw tx_chipset_tag_t tc;
237 1.6.4.2 nathanw u_int16_t reg;
238 1.6.4.2 nathanw int i;
239 1.6.4.2 nathanw
240 1.6.4.2 nathanw tc = sc->sc_tc;
241 1.6.4.2 nathanw
242 1.6.4.2 nathanw printf("\n\t[UCB1200 register]\n");
243 1.6.4.2 nathanw for (i = 0; i < 16; i++) {
244 1.6.4.2 nathanw reg = txsibsf0_reg_read(tc, i);
245 1.6.4.2 nathanw printf("%s(%02d) 0x%04x ", regname[i], i, reg);
246 1.6.4.2 nathanw dbg_bit_print(reg);
247 1.6.4.2 nathanw }
248 1.6.4.2 nathanw }
249 1.6.4.2 nathanw #endif /* UCB1200_DEBUG */
250