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