tx39sib.c revision 1.7.2.2 1 1.7.2.2 bouyer /* $NetBSD: tx39sib.c,v 1.7.2.2 2000/11/20 20:47:27 bouyer Exp $ */
2 1.7.2.2 bouyer
3 1.7.2.2 bouyer /*
4 1.7.2.2 bouyer * Copyright (c) 2000, by UCHIYAMA Yasushi
5 1.7.2.2 bouyer * All rights reserved.
6 1.7.2.2 bouyer *
7 1.7.2.2 bouyer * Redistribution and use in source and binary forms, with or without
8 1.7.2.2 bouyer * modification, are permitted provided that the following conditions
9 1.7.2.2 bouyer * are met:
10 1.7.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
11 1.7.2.2 bouyer * notice, this list of conditions and the following disclaimer.
12 1.7.2.2 bouyer * 2. The name of the developer may NOT be used to endorse or promote products
13 1.7.2.2 bouyer * derived from this software without specific prior written permission.
14 1.7.2.2 bouyer *
15 1.7.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.7.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.7.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.7.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.7.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.7.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.7.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.7.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.7.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.7.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.7.2.2 bouyer * SUCH DAMAGE.
26 1.7.2.2 bouyer *
27 1.7.2.2 bouyer */
28 1.7.2.2 bouyer
29 1.7.2.2 bouyer /*
30 1.7.2.2 bouyer * TX39 SIB (Serial Interface Bus) module.
31 1.7.2.2 bouyer */
32 1.7.2.2 bouyer #undef TX39SIBDEBUG
33 1.7.2.2 bouyer #include "opt_tx39_debug.h"
34 1.7.2.2 bouyer
35 1.7.2.2 bouyer #include <sys/param.h>
36 1.7.2.2 bouyer #include <sys/systm.h>
37 1.7.2.2 bouyer #include <sys/device.h>
38 1.7.2.2 bouyer
39 1.7.2.2 bouyer #include <machine/bus.h>
40 1.7.2.2 bouyer #include <machine/intr.h>
41 1.7.2.2 bouyer
42 1.7.2.2 bouyer #include <hpcmips/tx/tx39var.h>
43 1.7.2.2 bouyer #include <hpcmips/tx/tx39icureg.h>
44 1.7.2.2 bouyer #include <hpcmips/tx/tx39sibvar.h>
45 1.7.2.2 bouyer #include <hpcmips/tx/tx39sibreg.h>
46 1.7.2.2 bouyer
47 1.7.2.2 bouyer #include "locators.h"
48 1.7.2.2 bouyer
49 1.7.2.2 bouyer #ifdef TX39SIBDEBUG
50 1.7.2.2 bouyer int tx39sibdebug = 0;
51 1.7.2.2 bouyer #define DPRINTF(arg) if (tx39sibdebug) printf arg;
52 1.7.2.2 bouyer #else
53 1.7.2.2 bouyer #define DPRINTF(arg)
54 1.7.2.2 bouyer #endif
55 1.7.2.2 bouyer
56 1.7.2.2 bouyer int tx39sib_match __P((struct device*, struct cfdata*, void*));
57 1.7.2.2 bouyer void tx39sib_attach __P((struct device*, struct device*, void*));
58 1.7.2.2 bouyer int tx39sib_print __P((void*, const char*));
59 1.7.2.2 bouyer int tx39sib_search __P((struct device*, struct cfdata*, void*));
60 1.7.2.2 bouyer
61 1.7.2.2 bouyer #define TX39_CLK2X 18432000
62 1.7.2.2 bouyer const int sibsclk_divide_table[8] = {
63 1.7.2.2 bouyer 2, 3, 4, 5, 6, 8, 10, 12
64 1.7.2.2 bouyer };
65 1.7.2.2 bouyer
66 1.7.2.2 bouyer struct tx39sib_param {
67 1.7.2.2 bouyer /* SIB clock rate */
68 1.7.2.2 bouyer int sp_clock;
69 1.7.2.2 bouyer /*
70 1.7.2.2 bouyer * SIBMCLK = 18.432MHz = (CLK2X /4)
71 1.7.2.2 bouyer * SIBSCLK = SIBMCLK / sp_clock
72 1.7.2.2 bouyer * sp_clock start end divide module
73 1.7.2.2 bouyer * 0 7 8 2
74 1.7.2.2 bouyer * 1 6 8 3
75 1.7.2.2 bouyer * 2 6 9 4
76 1.7.2.2 bouyer * 3 5 9 5
77 1.7.2.2 bouyer * 4 5 10 6
78 1.7.2.2 bouyer * 5 4 11 8
79 1.7.2.2 bouyer * 6 3 12 10
80 1.7.2.2 bouyer * 7 2 13 12
81 1.7.2.2 bouyer */
82 1.7.2.2 bouyer /* sampling rate */
83 1.7.2.2 bouyer int sp_snd_rate; /* SNDFSDIV + 1 */
84 1.7.2.2 bouyer int sp_tel_rate; /* TELFSDIV + 1 */
85 1.7.2.2 bouyer /*
86 1.7.2.2 bouyer * Fs = (SIBSCLK * 2) / ((FSDIV + 1) * 64)
87 1.7.2.2 bouyer * FSDIV + 1 sampling rate
88 1.7.2.2 bouyer * 15 19.2k (1.6% error vs. CD-XA)
89 1.7.2.2 bouyer * 13 22.154k (0.47% error vs. CD-Audio)
90 1.7.2.2 bouyer * 22 7.85k (1.8% error vs. 8k)
91 1.7.2.2 bouyer */
92 1.7.2.2 bouyer /* data format 16/8bit */
93 1.7.2.2 bouyer int sp_sf0sndmode;
94 1.7.2.2 bouyer int sp_sf0telmode;
95 1.7.2.2 bouyer };
96 1.7.2.2 bouyer
97 1.7.2.2 bouyer struct tx39sib_param tx39sib_param_default_3912 = {
98 1.7.2.2 bouyer 0, /* SIBSCLK = 9.216MHz (div2) */
99 1.7.2.2 bouyer #if 0 /* setting sample */
100 1.7.2.2 bouyer 40, /* audio: 7.2kHz */
101 1.7.2.2 bouyer 26, /* audio: CD-Audio(/4) 11.077kHz*/
102 1.7.2.2 bouyer 6, /* audio: 48kHz */
103 1.7.2.2 bouyer #endif
104 1.7.2.2 bouyer 13, /* audio: CD-Audio(/2 = 22.050) 22.154kHz*/
105 1.7.2.2 bouyer 40, /* telecom: 7.2kHz */
106 1.7.2.2 bouyer TX39_SIBCTRL_SND16, /* Audio 16bit mono */
107 1.7.2.2 bouyer TX39_SIBCTRL_TEL16 /* Telecom 16bit mono */
108 1.7.2.2 bouyer };
109 1.7.2.2 bouyer
110 1.7.2.2 bouyer struct tx39sib_param tx39sib_param_default_3922 = {
111 1.7.2.2 bouyer 7, /* SIBSCLK = 9.216MHz (div1) */
112 1.7.2.2 bouyer 13, /* audio: CD-Audio(/2 = 22.050) 22.154kHz*/
113 1.7.2.2 bouyer 40, /* telecom: 7.2kHz */
114 1.7.2.2 bouyer TX39_SIBCTRL_SND16, /* Audio 16bit mono */
115 1.7.2.2 bouyer TX39_SIBCTRL_TEL16 /* Telecom 16bit mono */
116 1.7.2.2 bouyer };
117 1.7.2.2 bouyer
118 1.7.2.2 bouyer struct tx39sib_softc {
119 1.7.2.2 bouyer struct device sc_dev;
120 1.7.2.2 bouyer tx_chipset_tag_t sc_tc;
121 1.7.2.2 bouyer
122 1.7.2.2 bouyer struct tx39sib_param sc_param;
123 1.7.2.2 bouyer int sc_attached;
124 1.7.2.2 bouyer };
125 1.7.2.2 bouyer
126 1.7.2.2 bouyer __inline int __txsibsf0_ready __P((tx_chipset_tag_t));
127 1.7.2.2 bouyer #ifdef TX39SIBDEBUG
128 1.7.2.2 bouyer void tx39sib_dump __P((struct tx39sib_softc*));
129 1.7.2.2 bouyer #endif
130 1.7.2.2 bouyer
131 1.7.2.2 bouyer struct cfattach tx39sib_ca = {
132 1.7.2.2 bouyer sizeof(struct tx39sib_softc), tx39sib_match, tx39sib_attach
133 1.7.2.2 bouyer };
134 1.7.2.2 bouyer
135 1.7.2.2 bouyer int
136 1.7.2.2 bouyer tx39sib_match(parent, cf, aux)
137 1.7.2.2 bouyer struct device *parent;
138 1.7.2.2 bouyer struct cfdata *cf;
139 1.7.2.2 bouyer void *aux;
140 1.7.2.2 bouyer {
141 1.7.2.2 bouyer return ATTACH_FIRST;
142 1.7.2.2 bouyer }
143 1.7.2.2 bouyer
144 1.7.2.2 bouyer void
145 1.7.2.2 bouyer tx39sib_attach(parent, self, aux)
146 1.7.2.2 bouyer struct device *parent;
147 1.7.2.2 bouyer struct device *self;
148 1.7.2.2 bouyer void *aux;
149 1.7.2.2 bouyer {
150 1.7.2.2 bouyer struct txsim_attach_args *ta = aux;
151 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)self;
152 1.7.2.2 bouyer tx_chipset_tag_t tc;
153 1.7.2.2 bouyer
154 1.7.2.2 bouyer sc->sc_tc = tc = ta->ta_tc;
155 1.7.2.2 bouyer
156 1.7.2.2 bouyer /* set default param */
157 1.7.2.2 bouyer #ifdef TX391X
158 1.7.2.2 bouyer sc->sc_param = tx39sib_param_default_3912;
159 1.7.2.2 bouyer #endif /* TX391X */
160 1.7.2.2 bouyer #ifdef TX392X
161 1.7.2.2 bouyer sc->sc_param = tx39sib_param_default_3922;
162 1.7.2.2 bouyer #endif /* TX392X */
163 1.7.2.2 bouyer
164 1.7.2.2 bouyer #define MHZ(a) ((a) / 1000000), (((a) % 1000000) / 1000)
165 1.7.2.2 bouyer printf(": %d.%03d MHz", MHZ(tx39sib_clock(self)));
166 1.7.2.2 bouyer
167 1.7.2.2 bouyer printf("\n");
168 1.7.2.2 bouyer #ifdef TX39SIBDEBUG
169 1.7.2.2 bouyer if (tx39sibdebug)
170 1.7.2.2 bouyer tx39sib_dump(sc);
171 1.7.2.2 bouyer #endif
172 1.7.2.2 bouyer /* enable subframe0 */
173 1.7.2.2 bouyer tx39sib_enable1(self);
174 1.7.2.2 bouyer /* enable SIB */
175 1.7.2.2 bouyer tx39sib_enable2(self);
176 1.7.2.2 bouyer
177 1.7.2.2 bouyer #ifdef TX39SIBDEBUG
178 1.7.2.2 bouyer if (tx39sibdebug)
179 1.7.2.2 bouyer tx39sib_dump(sc);
180 1.7.2.2 bouyer #endif
181 1.7.2.2 bouyer
182 1.7.2.2 bouyer config_search(tx39sib_search, self, tx39sib_print);
183 1.7.2.2 bouyer }
184 1.7.2.2 bouyer
185 1.7.2.2 bouyer void
186 1.7.2.2 bouyer tx39sib_enable1(dev)
187 1.7.2.2 bouyer struct device *dev;
188 1.7.2.2 bouyer {
189 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)dev;
190 1.7.2.2 bouyer struct tx39sib_param *param = &sc->sc_param;
191 1.7.2.2 bouyer tx_chipset_tag_t tc = sc->sc_tc;
192 1.7.2.2 bouyer
193 1.7.2.2 bouyer txreg_t reg;
194 1.7.2.2 bouyer
195 1.7.2.2 bouyer /* disable SIB */
196 1.7.2.2 bouyer tx39sib_disable(dev);
197 1.7.2.2 bouyer
198 1.7.2.2 bouyer /* setup */
199 1.7.2.2 bouyer reg = 0;
200 1.7.2.2 bouyer /* SIB clock rate */
201 1.7.2.2 bouyer reg = TX39_SIBCTRL_SCLKDIV_SET(reg, param->sp_clock);
202 1.7.2.2 bouyer /* sampling rate (sound) */
203 1.7.2.2 bouyer reg = TX39_SIBCTRL_SNDFSDIV_SET(reg, param->sp_snd_rate - 1);
204 1.7.2.2 bouyer /* sampling rate (telecom) */
205 1.7.2.2 bouyer reg = TX39_SIBCTRL_TELFSDIV_SET(reg, param->sp_tel_rate - 1);
206 1.7.2.2 bouyer /* data format (8/16bit) */
207 1.7.2.2 bouyer reg |= param->sp_sf0sndmode;
208 1.7.2.2 bouyer reg |= param->sp_sf0telmode;
209 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
210 1.7.2.2 bouyer
211 1.7.2.2 bouyer /* DMA */
212 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBDMACTRL_REG);
213 1.7.2.2 bouyer reg &= ~(TX39_SIBDMACTRL_ENDMARXSND |
214 1.7.2.2 bouyer TX39_SIBDMACTRL_ENDMATXSND |
215 1.7.2.2 bouyer TX39_SIBDMACTRL_ENDMARXTEL |
216 1.7.2.2 bouyer TX39_SIBDMACTRL_ENDMATXTEL);
217 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBDMACTRL_REG, reg);
218 1.7.2.2 bouyer
219 1.7.2.2 bouyer /*
220 1.7.2.2 bouyer * Enable subframe0 (BETTY)
221 1.7.2.2 bouyer */
222 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBCTRL_REG);
223 1.7.2.2 bouyer reg |= TX39_SIBCTRL_ENSF0;
224 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
225 1.7.2.2 bouyer }
226 1.7.2.2 bouyer
227 1.7.2.2 bouyer void
228 1.7.2.2 bouyer tx39sib_enable2(dev)
229 1.7.2.2 bouyer struct device *dev;
230 1.7.2.2 bouyer {
231 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)dev;
232 1.7.2.2 bouyer tx_chipset_tag_t tc = sc->sc_tc;
233 1.7.2.2 bouyer txreg_t reg;
234 1.7.2.2 bouyer
235 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBCTRL_REG);
236 1.7.2.2 bouyer reg |= TX39_SIBCTRL_ENSIB;
237 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
238 1.7.2.2 bouyer }
239 1.7.2.2 bouyer
240 1.7.2.2 bouyer void
241 1.7.2.2 bouyer tx39sib_disable(dev)
242 1.7.2.2 bouyer struct device *dev;
243 1.7.2.2 bouyer {
244 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)dev;
245 1.7.2.2 bouyer tx_chipset_tag_t tc = sc->sc_tc;
246 1.7.2.2 bouyer txreg_t reg;
247 1.7.2.2 bouyer /* disable codec side */
248 1.7.2.2 bouyer /* notyet */
249 1.7.2.2 bouyer
250 1.7.2.2 bouyer /* disable TX39 side */
251 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBCTRL_REG);
252 1.7.2.2 bouyer reg &= ~(TX39_SIBCTRL_ENTEL | TX39_SIBCTRL_ENSND);
253 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
254 1.7.2.2 bouyer
255 1.7.2.2 bouyer /*
256 1.7.2.2 bouyer * Disable subframe0/1 (BETTY/external codec)
257 1.7.2.2 bouyer */
258 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBCTRL_REG);
259 1.7.2.2 bouyer reg &= ~TX39_SIBCTRL_ENSF0;
260 1.7.2.2 bouyer reg &= ~(TX39_SIBCTRL_ENSF1 | TX39_SIBCTRL_SELTELSF1 |
261 1.7.2.2 bouyer TX39_SIBCTRL_SELSNDSF1);
262 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
263 1.7.2.2 bouyer
264 1.7.2.2 bouyer /* disable TX39SIB module */
265 1.7.2.2 bouyer reg &= ~TX39_SIBCTRL_ENSIB;
266 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBCTRL_REG, reg);
267 1.7.2.2 bouyer }
268 1.7.2.2 bouyer
269 1.7.2.2 bouyer int
270 1.7.2.2 bouyer tx39sib_clock(dev)
271 1.7.2.2 bouyer struct device *dev;
272 1.7.2.2 bouyer {
273 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)dev;
274 1.7.2.2 bouyer
275 1.7.2.2 bouyer return TX39_CLK2X / sibsclk_divide_table[sc->sc_param.sp_clock];
276 1.7.2.2 bouyer }
277 1.7.2.2 bouyer
278 1.7.2.2 bouyer int
279 1.7.2.2 bouyer tx39sib_search(parent, cf, aux)
280 1.7.2.2 bouyer struct device *parent;
281 1.7.2.2 bouyer struct cfdata *cf;
282 1.7.2.2 bouyer void *aux;
283 1.7.2.2 bouyer {
284 1.7.2.2 bouyer struct tx39sib_softc *sc = (void*)parent;
285 1.7.2.2 bouyer struct txsib_attach_args sa;
286 1.7.2.2 bouyer
287 1.7.2.2 bouyer sa.sa_tc = sc->sc_tc;
288 1.7.2.2 bouyer sa.sa_slot = cf->cf_loc[TXSIBIFCF_SLOT];
289 1.7.2.2 bouyer sa.sa_snd_rate = sc->sc_param.sp_snd_rate;
290 1.7.2.2 bouyer sa.sa_tel_rate = sc->sc_param.sp_tel_rate;
291 1.7.2.2 bouyer
292 1.7.2.2 bouyer if (sa.sa_slot == TXSIBIFCF_SLOT_DEFAULT) {
293 1.7.2.2 bouyer printf("tx39sib_search: wildcarded slot, skipping\n");
294 1.7.2.2 bouyer return 0;
295 1.7.2.2 bouyer }
296 1.7.2.2 bouyer
297 1.7.2.2 bouyer if (!(sc->sc_attached & (1 << sa.sa_slot)) &&/* not attached slot */
298 1.7.2.2 bouyer (*cf->cf_attach->ca_match)(parent, cf, &sa)) {
299 1.7.2.2 bouyer config_attach(parent, cf, &sa, tx39sib_print);
300 1.7.2.2 bouyer sc->sc_attached |= (1 << sa.sa_slot);
301 1.7.2.2 bouyer }
302 1.7.2.2 bouyer
303 1.7.2.2 bouyer return 0;
304 1.7.2.2 bouyer }
305 1.7.2.2 bouyer
306 1.7.2.2 bouyer int
307 1.7.2.2 bouyer tx39sib_print(aux, pnp)
308 1.7.2.2 bouyer void *aux;
309 1.7.2.2 bouyer const char *pnp;
310 1.7.2.2 bouyer {
311 1.7.2.2 bouyer struct txsib_attach_args *sa = aux;
312 1.7.2.2 bouyer
313 1.7.2.2 bouyer printf(" slot %d", sa->sa_slot);
314 1.7.2.2 bouyer
315 1.7.2.2 bouyer return QUIET;
316 1.7.2.2 bouyer }
317 1.7.2.2 bouyer
318 1.7.2.2 bouyer /*
319 1.7.2.2 bouyer * sync access method. don't use runtime.
320 1.7.2.2 bouyer */
321 1.7.2.2 bouyer
322 1.7.2.2 bouyer __inline int
323 1.7.2.2 bouyer __txsibsf0_ready(tc)
324 1.7.2.2 bouyer tx_chipset_tag_t tc;
325 1.7.2.2 bouyer {
326 1.7.2.2 bouyer int i;
327 1.7.2.2 bouyer
328 1.7.2.2 bouyer tx_conf_write(tc, TX39_INTRSTATUS1_REG, TX39_INTRSTATUS1_SIBSF0INT);
329 1.7.2.2 bouyer for (i = 0; (!(tx_conf_read(tc, TX39_INTRSTATUS1_REG) &
330 1.7.2.2 bouyer TX39_INTRSTATUS1_SIBSF0INT)) && i < 1000; i++) {
331 1.7.2.2 bouyer if (i > 100 && !(i % 100)) {
332 1.7.2.2 bouyer printf("sf0 busy loop: retry count %d\n", i);
333 1.7.2.2 bouyer }
334 1.7.2.2 bouyer }
335 1.7.2.2 bouyer
336 1.7.2.2 bouyer if (i >= 1000) {
337 1.7.2.2 bouyer printf("sf0 busy\n");
338 1.7.2.2 bouyer return 0;
339 1.7.2.2 bouyer }
340 1.7.2.2 bouyer
341 1.7.2.2 bouyer return 1;
342 1.7.2.2 bouyer }
343 1.7.2.2 bouyer
344 1.7.2.2 bouyer void
345 1.7.2.2 bouyer txsibsf0_reg_write(tc, addr, val)
346 1.7.2.2 bouyer tx_chipset_tag_t tc;
347 1.7.2.2 bouyer int addr;
348 1.7.2.2 bouyer u_int16_t val;
349 1.7.2.2 bouyer {
350 1.7.2.2 bouyer txreg_t reg;
351 1.7.2.2 bouyer
352 1.7.2.2 bouyer reg = txsibsf0_read(tc, addr);
353 1.7.2.2 bouyer reg |= TX39_SIBSF0_WRITE;
354 1.7.2.2 bouyer TX39_SIBSF0_REGDATA_CLR(reg);
355 1.7.2.2 bouyer reg = TX39_SIBSF0_REGDATA_SET(reg, val);
356 1.7.2.2 bouyer
357 1.7.2.2 bouyer __txsibsf0_ready(tc);
358 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBSF0CTRL_REG, reg);
359 1.7.2.2 bouyer }
360 1.7.2.2 bouyer
361 1.7.2.2 bouyer u_int16_t
362 1.7.2.2 bouyer txsibsf0_reg_read(tc, addr)
363 1.7.2.2 bouyer tx_chipset_tag_t tc;
364 1.7.2.2 bouyer int addr;
365 1.7.2.2 bouyer {
366 1.7.2.2 bouyer return TX39_SIBSF0_REGDATA(txsibsf0_read(tc, addr));
367 1.7.2.2 bouyer }
368 1.7.2.2 bouyer
369 1.7.2.2 bouyer u_int32_t
370 1.7.2.2 bouyer txsibsf0_read(tc, addr)
371 1.7.2.2 bouyer tx_chipset_tag_t tc;
372 1.7.2.2 bouyer int addr;
373 1.7.2.2 bouyer {
374 1.7.2.2 bouyer txreg_t reg;
375 1.7.2.2 bouyer int retry = 3;
376 1.7.2.2 bouyer
377 1.7.2.2 bouyer do {
378 1.7.2.2 bouyer reg = TX39_SIBSF0_REGADDR_SET(0, addr);
379 1.7.2.2 bouyer __txsibsf0_ready(tc);
380 1.7.2.2 bouyer tx_conf_write(tc, TX39_SIBSF0CTRL_REG, reg);
381 1.7.2.2 bouyer
382 1.7.2.2 bouyer __txsibsf0_ready(tc);
383 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBSF0STAT_REG);
384 1.7.2.2 bouyer
385 1.7.2.2 bouyer } while ((TX39_SIBSF0_REGADDR(reg) != addr) && --retry > 0);
386 1.7.2.2 bouyer
387 1.7.2.2 bouyer if (retry <= 0)
388 1.7.2.2 bouyer printf("txsibsf0_read: command failed\n");
389 1.7.2.2 bouyer
390 1.7.2.2 bouyer return reg;
391 1.7.2.2 bouyer }
392 1.7.2.2 bouyer
393 1.7.2.2 bouyer #ifdef TX39SIBDEBUG
394 1.7.2.2 bouyer #define ISSETPRINT_CTRL(r, m) \
395 1.7.2.2 bouyer __is_set_print(r, TX39_SIBCTRL_##m, #m)
396 1.7.2.2 bouyer #define ISSETPRINT_DMACTRL(r, m) \
397 1.7.2.2 bouyer __is_set_print(r, TX39_SIBDMACTRL_##m, #m)
398 1.7.2.2 bouyer
399 1.7.2.2 bouyer void
400 1.7.2.2 bouyer tx39sib_dump(sc)
401 1.7.2.2 bouyer struct tx39sib_softc *sc;
402 1.7.2.2 bouyer {
403 1.7.2.2 bouyer tx_chipset_tag_t tc = sc->sc_tc;
404 1.7.2.2 bouyer txreg_t reg;
405 1.7.2.2 bouyer
406 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBCTRL_REG);
407 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SIBIRQ);
408 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENCNTTEST);
409 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENDMATEST);
410 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SNDMONO);
411 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, RMONOSNDIN);
412 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, TEL16);
413 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SND16);
414 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SELTELSF1);
415 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SELSNDSF1);
416 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENTEL);
417 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENSND);
418 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, SIBLOOP);
419 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENSF1);
420 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENSF0);
421 1.7.2.2 bouyer ISSETPRINT_CTRL(reg, ENSIB);
422 1.7.2.2 bouyer printf("\n");
423 1.7.2.2 bouyer printf("SCLKDIV %d\n", TX39_SIBCTRL_SCLKDIV(reg));
424 1.7.2.2 bouyer printf("TELFSDIV %d\n", TX39_SIBCTRL_TELFSDIV(reg));
425 1.7.2.2 bouyer printf("SNDFSDIV %d\n", TX39_SIBCTRL_SNDFSDIV(reg));
426 1.7.2.2 bouyer
427 1.7.2.2 bouyer reg = tx_conf_read(tc, TX39_SIBDMACTRL_REG);
428 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, SNDBUFF1TIME);
429 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, SNDDMALOOP);
430 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, ENDMARXSND);
431 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, ENDMATXSND);
432 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, TELBUFF1TIME);
433 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, TELDMALOOP);
434 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, ENDMARXTEL);
435 1.7.2.2 bouyer ISSETPRINT_DMACTRL(reg, ENDMATXTEL);
436 1.7.2.2 bouyer printf("\n");
437 1.7.2.2 bouyer printf("SNDDMAPTR %d\n", TX39_SIBDMACTRL_TELDMAPTR(reg));
438 1.7.2.2 bouyer printf("TELDMAPTR %d\n", TX39_SIBDMACTRL_SNDDMAPTR(reg));
439 1.7.2.2 bouyer
440 1.7.2.2 bouyer }
441 1.7.2.2 bouyer #endif /* TX39SIBDEBUG */
442