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