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