No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpcmips / dev / ucb1200.c
blob7fa888f3ca0f789926e7f2eb9b164617d66f22a7
1 /* $NetBSD: ucb1200.c,v 1.17 2008/04/28 20:23:21 martin Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Device driver for PHILIPS UCB1200 Advanced modem/audio analog front-end
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: ucb1200.c,v 1.17 2008/04/28 20:23:21 martin Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
43 #include <machine/bus.h>
44 #include <machine/intr.h>
46 #include <hpcmips/tx/tx39var.h>
47 #include <hpcmips/tx/tx39sibvar.h>
48 #include <hpcmips/tx/tx39sibreg.h>
50 #include <hpcmips/dev/ucb1200var.h>
51 #include <hpcmips/dev/ucb1200reg.h>
53 #ifdef UCB1200_DEBUG
54 #define DPRINTF_ENABLE
55 #define DPRINTF_DEBUG ucb1200_debug
56 #endif
57 #include <machine/debug.h>
59 struct ucbchild_state {
60 int (*cs_busy)(void *);
61 void *cs_arg;
64 struct ucb1200_softc {
65 struct device sc_dev;
66 struct device *sc_parent; /* parent (TX39 SIB module) */
67 tx_chipset_tag_t sc_tc;
69 int sc_snd_rate; /* passed down from SIB module */
70 int sc_tel_rate;
72 /* inquire child module state */
73 struct ucbchild_state sc_child[UCB1200_MODULE_MAX];
76 int ucb1200_match(struct device *, struct cfdata *, void *);
77 void ucb1200_attach(struct device *, struct device *, void *);
78 int ucb1200_print(void *, const char *);
79 int ucb1200_search(struct device *, struct cfdata *,
80 const int *, void *);
81 int ucb1200_check_id(u_int16_t, int);
83 #ifdef UCB1200_DEBUG
84 void ucb1200_dump(struct ucb1200_softc *);
85 #endif
87 CFATTACH_DECL(ucb, sizeof(struct ucb1200_softc),
88 ucb1200_match, ucb1200_attach, NULL, NULL);
90 const struct ucb_id {
91 u_int16_t id;
92 const char *product;
93 } ucb_id[] = {
94 { UCB1100_ID, "PHILIPS UCB1100" },
95 { UCB1200_ID, "PHILIPS UCB1200" },
96 { UCB1300_ID, "PHILIPS UCB1300" },
97 { TC35413F_ID, "TOSHIBA TC35413F" },
98 { 0, 0 }
102 ucb1200_match(struct device *parent, struct cfdata *cf, void *aux)
104 struct txsib_attach_args *sa = aux;
105 u_int16_t reg;
107 if (sa->sa_slot != 0) /* UCB1200 must be subframe 0 */
108 return (0);
109 reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
111 return (ucb1200_check_id(reg, 0));
114 void
115 ucb1200_attach(struct device *parent, struct device *self, void *aux)
117 struct txsib_attach_args *sa = aux;
118 struct ucb1200_softc *sc = (void*)self;
119 u_int16_t reg;
121 printf(": ");
122 sc->sc_tc = sa->sa_tc;
123 sc->sc_parent = parent;
124 sc->sc_snd_rate = sa->sa_snd_rate;
125 sc->sc_tel_rate = sa->sa_tel_rate;
127 tx39sib_enable1(sc->sc_parent);
128 tx39sib_enable2(sc->sc_parent);
130 #ifdef UCB1200_DEBUG
131 if (ucb1200_debug)
132 ucb1200_dump(sc);
133 #endif
134 reg = txsibsf0_reg_read(sa->sa_tc, UCB1200_ID_REG);
135 (void)ucb1200_check_id(reg, 1);
136 printf("\n");
138 config_search_ia(ucb1200_search, self, "ucbif", ucb1200_print);
142 ucb1200_search(struct device *parent, struct cfdata *cf,
143 const int *ldesc, void *aux)
145 struct ucb1200_softc *sc = (void*)parent;
146 struct ucb1200_attach_args ucba;
148 ucba.ucba_tc = sc->sc_tc;
149 ucba.ucba_snd_rate = sc->sc_snd_rate;
150 ucba.ucba_tel_rate = sc->sc_tel_rate;
151 ucba.ucba_sib = sc->sc_parent;
152 ucba.ucba_ucb = parent;
154 if (config_match(parent, cf, &ucba))
155 config_attach(parent, cf, &ucba, ucb1200_print);
157 return (0);
161 ucb1200_print(void *aux, const char *pnp)
164 return (pnp ? QUIET : UNCONF);
168 ucb1200_check_id(u_int16_t idreg, int print)
170 int i;
172 for (i = 0; ucb_id[i].product; i++) {
173 if (ucb_id[i].id == idreg) {
174 if (print) {
175 printf("%s", ucb_id[i].product);
178 return (1);
182 return (0);
185 void
186 ucb1200_state_install(struct device *dev, int (*sfun)(void *), void *sarg,
187 int sid)
189 struct ucb1200_softc *sc = (void*)dev;
191 sc->sc_child[sid].cs_busy = sfun;
192 sc->sc_child[sid].cs_arg = sarg;
196 ucb1200_state_idle(struct device *dev)
198 struct ucb1200_softc *sc = (void*)dev;
199 struct ucbchild_state *cs;
200 int i;
202 cs = sc->sc_child;
203 for (i = 0; i < UCB1200_MODULE_MAX; i++, cs++)
204 if (cs->cs_busy)
205 if ((*cs->cs_busy)(cs->cs_arg))
206 return (0);
208 return (1); /* idle state */
211 #ifdef UCB1200_DEBUG
212 void
213 ucb1200_dump(struct ucb1200_softc *sc)
215 static const char *const regname[] = {
216 "IO_DATA ",
217 "IO_DIR ",
218 "POSINTEN ",
219 "NEGINTEN ",
220 "INTSTAT ",
221 "TELECOMCTRLA ",
222 "TELECOMCTRLB ",
223 "AUDIOCTRLA ",
224 "AUDIOCTRLB ",
225 "TOUCHSCREENCTRL",
226 "ADCCTRL ",
227 "ADCDATA ",
228 "ID ",
229 "MODE ",
230 "RESERVED ",
231 "NULL "
233 tx_chipset_tag_t tc;
234 u_int16_t reg;
235 int i;
237 tc = sc->sc_tc;
239 printf("\n\t[UCB1200 register]\n");
240 for (i = 0; i < 16; i++) {
241 reg = txsibsf0_reg_read(tc, i);
242 printf("%s(%02d) 0x%04x ", regname[i], i, reg);
243 dbg_bit_print(reg);
246 #endif /* UCB1200_DEBUG */