2 * Copyright (c) 2001 Cubical Solutions Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * capi/iavc/iavc_lli.c
26 * The AVM ISDN controllers' Low Level Interface.
28 * $FreeBSD: src/sys/i4b/capi/iavc/iavc_lli.c,v 1.2.2.1 2001/08/10 14:08:34 obrien Exp $
29 * $DragonFly: src/sys/net/i4b/capi/iavc/iavc_lli.c,v 1.9 2006/10/25 20:56:03 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
36 #include <sys/socket.h>
37 #include <sys/malloc.h>
40 #include <sys/thread2.h>
42 #include <machine/clock.h>
48 #include <net/i4b/include/machine/i4b_debug.h>
49 #include <net/i4b/include/machine/i4b_ioctl.h>
50 #include <net/i4b/include/machine/i4b_trace.h>
52 #include "../../include/i4b_global.h"
53 #include "../../include/i4b_l3l4.h"
54 #include "../../include/i4b_mbuf.h"
56 #include "../capi_msgs.h"
60 /* Forward declarations of local subroutines... */
62 static int iavc_send_init(iavc_softc_t *);
64 static void iavc_handle_rx(iavc_softc_t *);
65 static void iavc_start_tx(iavc_softc_t *);
68 // Callbacks from the upper (capi) layer:
69 // --------------------------------------
72 // Resets the board and loads the firmware, then initiates
76 // Registers a CAPI application id.
79 // Releases a CAPI application id.
82 // Sends a capi message.
86 iavc_load(capi_softc_t *capi_sc, int len, u_int8_t *cp)
88 iavc_softc_t *sc = (iavc_softc_t*) capi_sc->ctx;
92 printf("iavc%d: reset card ....\n", sc->sc_unit);
95 b1dma_reset(sc); /* PCI cards */
97 t1_reset(sc); /* ISA attachment T1 */
99 b1_reset(sc); /* ISA attachment B1 */
104 printf("iavc%d: start loading %d bytes firmware ....\n", sc->sc_unit, len);
106 while (len && b1io_save_put_byte(sc, *cp++) == 0)
110 printf("iavc%d: loading failed, can't write to card, len = %d\n",
116 printf("iavc%d: firmware loaded, wait for ACK ....\n", sc->sc_unit);
118 if(sc->sc_capi.card_type == CARD_TYPEC_AVM_B1_ISA)
119 iavc_put_byte(sc, SEND_POLL);
121 iavc_put_byte(sc, SEND_POLLACK);
123 for (len = 0; len < 1000 && !iavc_rx_full(sc); len++)
126 if (!iavc_rx_full(sc)) {
127 printf("iavc%d: loading failed, no ack\n", sc->sc_unit);
131 val = iavc_get_byte(sc);
133 if ((sc->sc_dma && val != RECEIVE_POLLDWORD) ||
134 (!sc->sc_dma && val != RECEIVE_POLL)) {
135 printf("iavc%d: loading failed, bad ack = %02x\n", sc->sc_unit, val);
140 printf("iavc%d: got ACK = 0x%02x\n", sc->sc_unit, val);
143 /* Start the DMA engine */
147 sc->sc_csr = AVM_FLAG;
148 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
149 AMCC_WRITE(sc, AMCC_MCSR, (EN_A2P_TRANSFERS|EN_P2A_TRANSFERS|
150 A2P_HI_PRIORITY|P2A_HI_PRIORITY|
151 RESET_A2P_FLAGS|RESET_P2A_FLAGS));
153 iavc_write_port(sc, 0x07, 0x30); /* XXX magic numbers from */
154 iavc_write_port(sc, 0x10, 0xf0); /* XXX the linux driver */
157 AMCC_WRITE(sc, AMCC_RXPTR, vtophys(&sc->sc_recvbuf[0]));
158 AMCC_WRITE(sc, AMCC_RXLEN, 4);
159 sc->sc_csr |= EN_RX_TC_INT|EN_TX_TC_INT;
160 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
165 if(sc->sc_capi.card_type == CARD_TYPEC_AVM_B1_ISA)
174 iavc_register(capi_softc_t *capi_sc, int applid, int nchan)
176 iavc_softc_t *sc = (iavc_softc_t*) capi_sc->ctx;
177 struct mbuf *m = i4b_Dgetmbuf(23);
181 printf("iavc%d: can't get memory\n", sc->sc_unit);
186 * byte 0x12 = SEND_REGISTER
189 * dword NumB3Connections 0..nbch
194 p = amcc_put_byte(mtod(m, u_int8_t*), 0);
195 p = amcc_put_byte(p, 0);
196 p = amcc_put_byte(p, SEND_REGISTER);
197 p = amcc_put_word(p, applid);
199 p = amcc_put_word(p, 1024 + (nchan + 1));
201 p = amcc_put_word(p, 1024 * (nchan + 1));
203 p = amcc_put_word(p, nchan);
204 p = amcc_put_word(p, 8);
205 p = amcc_put_word(p, 2048);
207 IF_ENQUEUE(&sc->sc_txq, m);
215 iavc_release(capi_softc_t *capi_sc, int applid)
217 iavc_softc_t *sc = (iavc_softc_t*) capi_sc->ctx;
218 struct mbuf *m = i4b_Dgetmbuf(7);
222 printf("iavc%d: can't get memory\n", sc->sc_unit);
227 * byte 0x14 = SEND_RELEASE
231 p = amcc_put_byte(mtod(m, u_int8_t*), 0);
232 p = amcc_put_byte(p, 0);
233 p = amcc_put_byte(p, SEND_RELEASE);
234 p = amcc_put_word(p, applid);
236 IF_ENQUEUE(&sc->sc_txq, m);
243 iavc_send(capi_softc_t *capi_sc, struct mbuf *m)
245 iavc_softc_t *sc = (iavc_softc_t*) capi_sc->ctx;
247 if (sc->sc_state != IAVC_UP) {
248 printf("iavc%d: attempt to send before device up\n", sc->sc_unit);
250 if (m->m_next) i4b_Bfreembuf(m->m_next);
256 if (IF_QFULL(&sc->sc_txq)) {
257 IF_DROP(&sc->sc_txq);
259 printf("iavc%d: tx overflow, message dropped\n", sc->sc_unit);
261 if (m->m_next) i4b_Bfreembuf(m->m_next);
265 IF_ENQUEUE(&sc->sc_txq, m);
274 // Functions called by ourself during the initialization sequence:
275 // ---------------------------------------------------------------
278 // Sends the system initialization message to a newly loaded
279 // board, and sets state to INIT.
283 iavc_send_init(iavc_softc_t *sc)
285 struct mbuf *m = i4b_Dgetmbuf(15);
289 printf("iavc%d: can't get memory\n", sc->sc_unit);
294 * byte 0x11 = SEND_INIT
295 * dword NumApplications
300 p = amcc_put_byte(mtod(m, u_int8_t*), 0);
301 p = amcc_put_byte(p, 0);
302 p = amcc_put_byte(p, SEND_INIT);
303 p = amcc_put_word(p, 1); /* XXX MaxAppl XXX */
304 p = amcc_put_word(p, sc->sc_capi.sc_nbch);
305 p = amcc_put_word(p, sc->sc_unit);
308 IF_ENQUEUE(&sc->sc_txq, m);
312 sc->sc_state = IAVC_INIT;
318 // Functions called during normal operation:
319 // -----------------------------------------
322 // Reads the initialization reply and calls capi_ll_control().
324 // iavc_receive_new_ncci
325 // Reads a new NCCI notification and calls capi_ll_control().
327 // iavc_receive_free_ncci
328 // Reads a freed NCCI notification and calls capi_ll_control().
330 // iavc_receive_task_ready
331 // Reads a task ready message -- which should not occur XXX.
333 // iavc_receive_debugmsg
334 // Reads a debug message -- which should not occur XXX.
336 // iavc_receive_start
337 // Reads a START TRANSMIT message and unblocks device.
340 // Reads a STOP TRANSMIT message and blocks device.
343 // Reads an incoming message and calls capi_ll_receive().
347 iavc_receive_init(iavc_softc_t *sc, u_int8_t *dmabuf)
351 u_int8_t *cardtype, *serial, *profile, *version, *caps, *prot;
354 p = amcc_get_word(dmabuf, &Length);
356 Length = iavc_get_slice(sc, sc->sc_recvbuf);
363 printf("iavc%d: rx_init: ", sc->sc_unit);
364 while (len < Length) {
365 printf(" %02x", p[len]);
366 if (len && (len % 16) == 0) printf("\n");
369 if (len % 16) printf("\n");
374 p += (*p + 1); /* driver version */
376 p += (*p + 1); /* card type */
377 p += (*p + 1); /* hardware ID */
379 p += (*p + 1); /* serial number */
381 p += (*p + 1); /* supported options */
383 p += (*p + 1); /* supported protocols */
386 if (cardtype && serial && profile) {
387 int nbch = ((profile[3]<<8) | profile[2]);
389 printf("iavc%d: AVM %s, s/n %s, %d chans, f/w rev %s, prot %s\n",
390 sc->sc_unit, cardtype, serial, nbch, version, prot);
393 printf("iavc%d: %s\n", sc->sc_unit, caps);
395 capi_ll_control(&sc->sc_capi, CAPI_CTRL_PROFILE, (int) profile);
398 printf("iavc%d: no profile data in info response?\n", sc->sc_unit);
401 sc->sc_blocked = TRUE; /* controller will send START when ready */
406 iavc_receive_start(iavc_softc_t *sc, u_int8_t *dmabuf)
408 struct mbuf *m = i4b_Dgetmbuf(3);
411 if (sc->sc_blocked && sc->sc_state == IAVC_UP)
412 printf("iavc%d: receive_start\n", sc->sc_unit);
415 printf("iavc%d: can't get memory\n", sc->sc_unit);
420 * byte 0x73 = SEND_POLLACK
423 p = amcc_put_byte(mtod(m, u_int8_t*), 0);
424 p = amcc_put_byte(p, 0);
425 p = amcc_put_byte(p, SEND_POLLACK);
427 IF_PREPEND(&sc->sc_txq, m);
429 NDBGL4(L4_IAVCDBG, "iavc%d: blocked = %d, state = %d",
430 sc->sc_unit, sc->sc_blocked, sc->sc_state);
432 sc->sc_blocked = FALSE;
435 /* If this was our first START, register our readiness */
437 if (sc->sc_state != IAVC_UP) {
438 sc->sc_state = IAVC_UP;
439 capi_ll_control(&sc->sc_capi, CAPI_CTRL_READY, TRUE);
446 iavc_receive_stop(iavc_softc_t *sc, u_int8_t *dmabuf)
448 printf("iavc%d: receive_stop\n", sc->sc_unit);
449 sc->sc_blocked = TRUE;
454 iavc_receive_new_ncci(iavc_softc_t *sc, u_int8_t *dmabuf)
456 u_int32_t ApplId, NCCI, WindowSize;
459 dmabuf = amcc_get_word(dmabuf, &ApplId);
460 dmabuf = amcc_get_word(dmabuf, &NCCI);
461 dmabuf = amcc_get_word(dmabuf, &WindowSize);
463 ApplId = iavc_get_word(sc);
464 NCCI = iavc_get_word(sc);
465 WindowSize = iavc_get_word(sc);
468 capi_ll_control(&sc->sc_capi, CAPI_CTRL_NEW_NCCI, NCCI);
473 iavc_receive_free_ncci(iavc_softc_t *sc, u_int8_t *dmabuf)
475 u_int32_t ApplId, NCCI;
478 dmabuf = amcc_get_word(dmabuf, &ApplId);
479 dmabuf = amcc_get_word(dmabuf, &NCCI);
481 ApplId = iavc_get_word(sc);
482 NCCI = iavc_get_word(sc);
485 capi_ll_control(&sc->sc_capi, CAPI_CTRL_FREE_NCCI, NCCI);
490 iavc_receive_task_ready(iavc_softc_t *sc, u_int8_t *dmabuf)
492 u_int32_t TaskId, Length;
494 printf("iavc%d: receive_task_ready\n", sc->sc_unit);
497 p = amcc_get_word(dmabuf, &TaskId);
498 p = amcc_get_word(p, &Length);
500 TaskId = iavc_get_word(sc);
501 Length = iavc_get_slice(sc, sc->sc_recvbuf);
505 /* XXX could show the message if trace enabled? XXX */
510 iavc_receive_debugmsg(iavc_softc_t *sc, u_int8_t *dmabuf)
514 printf("iavc%d: receive_debugmsg\n", sc->sc_unit);
517 p = amcc_get_word(dmabuf, &Length);
519 Length = iavc_get_slice(sc, sc->sc_recvbuf);
523 /* XXX could show the message if trace enabled? XXX */
528 iavc_receive(iavc_softc_t *sc, u_int8_t *dmabuf, int b3data)
531 u_int32_t ApplId, Length;
534 * byte 0x21 = RECEIVE_MESSAGE
541 * byte 0x22 = RECEIVE_DATA_B3_IND
550 dmabuf = amcc_get_word(dmabuf, &ApplId);
551 dmabuf = amcc_get_word(dmabuf, &Length);
553 ApplId = iavc_get_word(sc);
554 Length = iavc_get_slice(sc, sc->sc_recvbuf);
555 dmabuf = sc->sc_recvbuf;
558 m = i4b_Dgetmbuf(Length);
560 printf("iavc%d: can't get memory for receive\n", sc->sc_unit);
564 bcopy(dmabuf, mtod(m, u_int8_t*), Length);
568 u_int8_t *p = mtod(m, u_int8_t*);
570 printf("iavc%d: applid=%d, len=%d\n", sc->sc_unit, ApplId, Length);
571 while (len < m->m_len) {
572 printf(" %02x", p[len]);
573 if (len && (len % 16) == 0) printf("\n");
576 if (len % 16) printf("\n");
582 dmabuf = amcc_get_word(dmabuf + Length, &Length);
584 Length = iavc_get_slice(sc, sc->sc_recvbuf);
585 dmabuf = sc->sc_recvbuf;
588 m->m_next = i4b_Bgetmbuf(Length);
590 printf("iavc%d: can't get memory for receive\n", sc->sc_unit);
595 bcopy(dmabuf, mtod(m->m_next, u_int8_t*), Length);
598 capi_ll_receive(&sc->sc_capi, m);
604 // Checks device interrupt status and calls iavc_handle_{rx,tx}()
608 // Reads in the command byte and calls the subroutines above.
611 // Initiates DMA on the next queued message if possible.
615 iavc_handle_intr(iavc_softc_t *sc)
621 while (iavc_rx_full(sc))
626 status = AMCC_READ(sc, AMCC_INTCSR);
627 if ((status & ANY_S5933_INT) == 0)
630 newcsr = sc->sc_csr | (status & ALL_INT);
631 if (status & TX_TC_INT) newcsr &= ~EN_TX_TC_INT;
632 if (status & RX_TC_INT) newcsr &= ~EN_RX_TC_INT;
633 AMCC_WRITE(sc, AMCC_INTCSR, newcsr);
636 if (status & RX_TC_INT) {
639 if (sc->sc_recvlen == 0) {
640 sc->sc_recvlen = *((u_int32_t*)(&sc->sc_recvbuf[0]));
641 rxlen = (sc->sc_recvlen + 3) & ~3;
642 AMCC_WRITE(sc, AMCC_RXPTR, vtophys(&sc->sc_recvbuf[4]));
643 AMCC_WRITE(sc, AMCC_RXLEN, rxlen);
647 AMCC_WRITE(sc, AMCC_RXPTR, vtophys(&sc->sc_recvbuf[0]));
648 AMCC_WRITE(sc, AMCC_RXLEN, 4);
652 if (status & TX_TC_INT) {
653 sc->sc_csr &= ~EN_TX_TC_INT;
657 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
662 iavc_handle_rx(iavc_softc_t *sc)
664 u_int8_t *dmabuf = 0, cmd;
667 dmabuf = amcc_get_byte(&sc->sc_recvbuf[4], &cmd);
669 cmd = iavc_get_byte(sc);
672 NDBGL4(L4_IAVCDBG, "iavc%d: command = 0x%02x", sc->sc_unit, cmd);
675 case RECEIVE_DATA_B3_IND:
676 iavc_receive(sc, dmabuf, TRUE);
679 case RECEIVE_MESSAGE:
680 iavc_receive(sc, dmabuf, FALSE);
683 case RECEIVE_NEW_NCCI:
684 iavc_receive_new_ncci(sc, dmabuf);
687 case RECEIVE_FREE_NCCI:
688 iavc_receive_free_ncci(sc, dmabuf);
692 iavc_receive_start(sc, dmabuf);
696 iavc_receive_stop(sc, dmabuf);
700 iavc_receive_init(sc, dmabuf);
703 case RECEIVE_TASK_READY:
704 iavc_receive_task_ready(sc, dmabuf);
707 case RECEIVE_DEBUGMSG:
708 iavc_receive_debugmsg(sc, dmabuf);
712 printf("iavc%d: unknown msg %02x\n", sc->sc_unit, cmd);
717 iavc_start_tx(iavc_softc_t *sc)
723 /* If device has put us on hold, punt. */
725 if (sc->sc_blocked) {
729 /* If using DMA and transmitter busy, punt. */
731 if (sc->sc_dma && (sc->sc_csr & EN_TX_TC_INT)) {
735 /* Else, see if we have messages to send. */
737 IF_DEQUEUE(&sc->sc_txq, m);
742 /* Have message, will send. */
744 if (CAPIMSG_LEN(m->m_data)) {
745 /* A proper CAPI message, possibly with B3 data */
748 /* Copy message to DMA buffer. */
751 dmabuf = amcc_put_byte(&sc->sc_sendbuf[0], SEND_DATA_B3_REQ);
753 dmabuf = amcc_put_byte(&sc->sc_sendbuf[0], SEND_MESSAGE);
756 dmabuf = amcc_put_word(dmabuf, m->m_len);
757 bcopy(m->m_data, dmabuf, m->m_len);
759 txlen = 5 + m->m_len;
762 dmabuf = amcc_put_word(dmabuf, m->m_next->m_len);
763 bcopy(m->m_next->m_data, dmabuf, m->m_next->m_len);
764 txlen += 4 + m->m_next->m_len;
771 iavc_put_byte(sc, SEND_DATA_B3_REQ);
772 NDBGL4(L4_IAVCDBG, "iavc%d: tx SDB3R msg, len = %d", sc->sc_unit, m->m_len);
774 iavc_put_byte(sc, SEND_MESSAGE);
775 NDBGL4(L4_IAVCDBG, "iavc%d: tx SM msg, len = %d", sc->sc_unit, m->m_len);
779 u_int8_t *p = mtod(m, u_int8_t*);
781 for (len = 0; len < m->m_len; len++) {
782 printf(" %02x", *p++);
783 if (len && (len % 16) == 0) printf("\n");
785 if (len % 16) printf("\n");
789 iavc_put_slice(sc, m->m_data, m->m_len);
792 iavc_put_slice(sc, m->m_next->m_data, m->m_next->m_len);
797 /* A board control message to be sent as is */
800 bcopy(m->m_data + 2, &sc->sc_sendbuf[0], m->m_len - 2);
801 txlen = m->m_len - 2;
806 u_int8_t *p = mtod(m, u_int8_t*) + 2;
808 printf("iavc%d: tx BDC msg, len = %d, msg =", sc->sc_unit, m->m_len-2);
809 for (len = 0; len < m->m_len-2; len++) {
810 printf(" %02x", *p++);
811 if (len && (len % 16) == 0) printf("\n");
813 if (len % 16) printf("\n");
817 txlen = m->m_len - 2;
818 dmabuf = mtod(m, char*) + 2;
820 b1io_put_byte(sc, *dmabuf++);
825 i4b_Bfreembuf(m->m_next);
831 /* Start transmitter */
833 txlen = (txlen + 3) & ~3;
834 AMCC_WRITE(sc, AMCC_TXPTR, vtophys(&sc->sc_sendbuf[0]));
835 AMCC_WRITE(sc, AMCC_TXLEN, txlen);
836 sc->sc_csr |= EN_TX_TC_INT;
839 AMCC_WRITE(sc, AMCC_INTCSR, sc->sc_csr);
844 t1io_get_slice(iavc_softc_t *sc, u_int8_t *dp)
847 len = i = b1io_get_word(sc);
848 if (t1io_isfastlink(sc)) {
851 status = t1io_fifostatus(sc) & (T1F_IREADY|T1F_IHALF);
852 if (i >= FIFO_INPBSIZE) status |= T1F_IFULL;
855 case T1F_IREADY|T1F_IHALF|T1F_IFULL:
856 bus_space_read_multi_1(sc->sc_io_bt, sc->sc_io_bh,
857 T1_READ, dp, FIFO_INPBSIZE);
862 case T1F_IREADY|T1F_IHALF:
863 bus_space_read_multi_1(sc->sc_io_bt, sc->sc_io_bh,
870 *dp++ = b1io_get_byte(sc);
874 } else { /* not fastlink */
875 if (i--) *dp++ = b1io_get_byte(sc);
881 t1io_put_slice(iavc_softc_t *sc, u_int8_t *dp, int len)
884 b1io_put_word(sc, i);
885 if (t1io_isfastlink(sc)) {
888 status = t1io_fifostatus(sc) & (T1F_OREADY|T1F_OHALF);
889 if (i >= FIFO_OUTBSIZE) status |= T1F_OFULL;
892 case T1F_OREADY|T1F_OHALF|T1F_OFULL:
893 bus_space_write_multi_1(sc->sc_io_bt, sc->sc_io_bh,
894 T1_WRITE, dp, FIFO_OUTBSIZE);
899 case T1F_OREADY|T1F_OHALF:
900 bus_space_write_multi_1(sc->sc_io_bt, sc->sc_io_bh,
907 b1io_put_byte(sc, *dp++);
912 while (i--) b1io_put_byte(sc, *dp++);
917 b1io_get_word(iavc_softc_t *sc)
920 val |= b1io_get_byte(sc);
921 val |= (b1io_get_byte(sc) << 8);
922 val |= (b1io_get_byte(sc) << 16);
923 val |= (b1io_get_byte(sc) << 24);
928 b1io_put_word(iavc_softc_t *sc, u_int32_t val)
930 b1io_put_byte(sc, (val & 0xff));
931 b1io_put_byte(sc, (val >> 8) & 0xff);
932 b1io_put_byte(sc, (val >> 16) & 0xff);
933 b1io_put_byte(sc, (val >> 24) & 0xff);
937 b1io_get_slice(iavc_softc_t *sc, u_int8_t *dp)
940 len = i = b1io_get_word(sc);
941 while (i--) *dp++ = b1io_get_byte(sc);
946 b1io_put_slice(iavc_softc_t *sc, u_int8_t *dp, int len)
948 b1io_put_word(sc, len);
949 while (len--) b1io_put_byte(sc, *dp++);
953 b1io_read_reg(iavc_softc_t *sc, int reg)
955 b1io_put_byte(sc, READ_REGISTER);
956 b1io_put_word(sc, reg);
957 return b1io_get_word(sc);
961 b1io_write_reg(iavc_softc_t *sc, int reg, u_int32_t val)
963 b1io_put_byte(sc, WRITE_REGISTER);
964 b1io_put_word(sc, reg);
965 b1io_put_word(sc, val);
966 return b1io_get_word(sc);
970 b1io_get_byte(iavc_softc_t *sc)
973 while (!b1io_rx_full(sc) && spin < B1IO_WAIT_MAX) {
974 spin++; DELAY(B1IO_WAIT_DLY);
976 if (b1io_rx_full(sc))
977 return bus_space_read_1(sc->sc_io_bt, sc->sc_io_bh, B1_READ);
978 printf("iavc%d: rx not completed\n", sc->sc_unit);
983 b1io_put_byte(iavc_softc_t *sc, u_int8_t val)
986 while (!b1io_tx_empty(sc) && spin < B1IO_WAIT_MAX) {
987 spin++; DELAY(B1IO_WAIT_DLY);
989 if (b1io_tx_empty(sc)) {
990 bus_space_write_1(sc->sc_io_bt, sc->sc_io_bh, B1_WRITE, val);
993 printf("iavc%d: tx not emptied\n", sc->sc_unit);
998 b1io_save_put_byte(iavc_softc_t *sc, u_int8_t val)
1001 while (!b1io_tx_empty(sc) && spin < B1IO_WAIT_MAX) {
1002 spin++; DELAY(B1IO_WAIT_DLY);
1004 if (b1io_tx_empty(sc)) {
1005 b1io_outp(sc, B1_WRITE, val);
1008 printf("iavc%d: tx not emptied\n", sc->sc_unit);