3 /* From: adb_direct.c 2.02 4/18/97 jpw */
6 * Copyright (C) 1996, 1997 John P. Wittkoski
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by John P. Wittkoski.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * This code is rather messy, but I don't have time right now
37 * to clean it up as much as I would like.
38 * But it works, so I'm happy. :-) jpw
43 * - We could reduce the time spent in the adb_intr_* routines
44 * by having them save the incoming and outgoing data directly
45 * in the adbInbound and adbOutbound queues, as it would reduce
46 * the number of times we need to copy the data around. It
47 * would also make the code more readable and easier to follow.
48 * - (Related to above) Use the header part of adbCommand to
49 * reduce the number of copies we have to do of the data.
50 * - (Related to above) Actually implement the adbOutbound queue.
51 * This is fairly easy once you switch all the intr routines
52 * over to using adbCommand structs directly.
53 * - There is a bug in the state machine of adb_intr_cuda
54 * code that causes hangs, especially on 030 machines, probably
55 * because of some timing issues. Because I have been unable to
56 * determine the exact cause of this bug, I used the timeout function
57 * to check for and recover from this condition. If anyone finds
58 * the actual cause of this bug, the calls to timeout and the
59 * adb_cuda_tickle routine can be removed.
64 #include <sys/cdefs.h>
65 __KERNEL_RCSID(0, "$NetBSD$");
69 #include <sys/param.h>
71 #include <sys/queue.h>
72 #include <sys/systm.h>
73 #include <sys/callout.h>
77 #include <machine/viareg.h>
78 #include <machine/param.h>
79 #include <machine/adbsys.h> /* required for adbvar.h */
80 #include <machine/iopreg.h> /* required for IOP support */
82 #include <mac68k/mac68k/macrom.h>
83 #include <mac68k/dev/adbvar.h>
84 #define printf_intr printf
85 #else /* !__NetBSD__, i.e. Mac OS */
86 #include "via.h" /* for macos based testing */
87 /* #define ADB_DEBUG */ /* more verbose for testing */
89 /* Types of ADB hardware that we support */
90 #define ADB_HW_UNKNOWN 0x0 /* don't know */
91 #define ADB_HW_II 0x1 /* Mac II series */
92 #define ADB_HW_IISI 0x2 /* Mac IIsi series */
93 #define ADB_HW_PB 0x3 /* PowerBook series */
94 #define ADB_HW_CUDA 0x4 /* Machines with a Cuda chip */
95 #endif /* __NetBSD__ */
97 /* some misc. leftovers */
105 /* the type of ADB action that we are currently preforming */
106 #define ADB_ACTION_NOTREADY 0x1 /* has not been initialized yet */
107 #define ADB_ACTION_IDLE 0x2 /* the bus is currently idle */
108 #define ADB_ACTION_OUT 0x3 /* sending out a command */
109 #define ADB_ACTION_IN 0x4 /* receiving data */
110 #define ADB_ACTION_POLLING 0x5 /* polling - II only */
111 #define ADB_ACTION_RUNNING 0x6 /* running - IOP only */
114 * These describe the state of the ADB bus itself, although they
115 * don't necessarily correspond directly to ADB states.
116 * Note: these are not really used in the IIsi code.
118 #define ADB_BUS_UNKNOWN 0x1 /* we don't know yet - all models */
119 #define ADB_BUS_IDLE 0x2 /* bus is idle - all models */
120 #define ADB_BUS_CMD 0x3 /* starting a command - II models */
121 #define ADB_BUS_ODD 0x4 /* the "odd" state - II models */
122 #define ADB_BUS_EVEN 0x5 /* the "even" state - II models */
123 #define ADB_BUS_ACTIVE 0x6 /* active state - IIsi models */
124 #define ADB_BUS_ACK 0x7 /* currently ACKing - IIsi models */
127 * Shortcuts for setting or testing the VIA bit states.
128 * Not all shortcuts are used for every type of ADB hardware.
130 #define ADB_SET_STATE_IDLE_II() via_reg(VIA1, vBufB) |= (vPB4 | vPB5)
131 #define ADB_SET_STATE_IDLE_IISI() via_reg(VIA1, vBufB) &= ~(vPB4 | vPB5)
132 #define ADB_SET_STATE_IDLE_CUDA() via_reg(VIA1, vBufB) |= (vPB4 | vPB5)
133 #define ADB_SET_STATE_CMD() via_reg(VIA1, vBufB) &= ~(vPB4 | vPB5)
134 #define ADB_SET_STATE_EVEN() via_reg(VIA1, vBufB) = ((via_reg(VIA1, \
135 vBufB) | vPB4) & ~vPB5)
136 #define ADB_SET_STATE_ODD() via_reg(VIA1, vBufB) = ((via_reg(VIA1, \
137 vBufB) | vPB5) & ~vPB4)
138 #define ADB_SET_STATE_ACTIVE() via_reg(VIA1, vBufB) |= vPB5
139 #define ADB_SET_STATE_INACTIVE() via_reg(VIA1, vBufB) &= ~vPB5
140 #define ADB_SET_STATE_TIP() via_reg(VIA1, vBufB) &= ~vPB5
141 #define ADB_CLR_STATE_TIP() via_reg(VIA1, vBufB) |= vPB5
142 #define ADB_SET_STATE_ACKON() via_reg(VIA1, vBufB) |= vPB4
143 #define ADB_SET_STATE_ACKOFF() via_reg(VIA1, vBufB) &= ~vPB4
144 #define ADB_TOGGLE_STATE_ACK_CUDA() via_reg(VIA1, vBufB) ^= vPB4
145 #define ADB_SET_STATE_ACKON_CUDA() via_reg(VIA1, vBufB) &= ~vPB4
146 #define ADB_SET_STATE_ACKOFF_CUDA() via_reg(VIA1, vBufB) |= vPB4
147 #define ADB_SET_SR_INPUT() via_reg(VIA1, vACR) &= ~vSR_OUT
148 #define ADB_SET_SR_OUTPUT() via_reg(VIA1, vACR) |= vSR_OUT
149 #define ADB_SR() via_reg(VIA1, vSR)
150 #define ADB_VIA_INTR_ENABLE() via_reg(VIA1, vIER) = 0x84
151 #define ADB_VIA_INTR_DISABLE() via_reg(VIA1, vIER) = 0x04
152 #define ADB_VIA_CLR_INTR() via_reg(VIA1, vIFR) = 0x04
153 #define ADB_INTR_IS_OFF (vPB3 == (via_reg(VIA1, vBufB) & vPB3))
154 #define ADB_INTR_IS_ON (0 == (via_reg(VIA1, vBufB) & vPB3))
155 #define ADB_SR_INTR_IS_OFF (0 == (via_reg(VIA1, vIFR) & vSR_INT))
156 #define ADB_SR_INTR_IS_ON (vSR_INT == (via_reg(VIA1, \
160 * This is the delay that is required (in uS) between certain
161 * ADB transactions. The actual timing delay for for each uS is
162 * calculated at boot time to account for differences in machine speed.
164 #define ADB_DELAY 150
167 * Maximum ADB message length; includes space for data, result, and
168 * device code - plus a little for safety.
170 #define ADB_MAX_MSG_LENGTH 16
171 #define ADB_MAX_HDR_LENGTH 8
174 #define ADB_TICKLE_TICKS 4
177 * A structure for storing information about each ADB device.
180 void (*ServiceRtPtr
)(void);
188 * Used to hold ADB commands that are waiting to be sent out.
190 struct adbCmdHoldEntry
{
191 u_char outBuf
[ADB_MAX_MSG_LENGTH
]; /* our message */
192 u_char
*saveBuf
; /* buffer to know where to save result */
193 u_char
*compRout
; /* completion routine pointer */
194 u_char
*data
; /* completion routine data pointer */
198 * Eventually used for two separate queues, the queue between
199 * the upper and lower halves, and the outgoing packet queue.
200 * TO DO: adbCommand can replace all of adbCmdHoldEntry eventually
203 u_char header
[ADB_MAX_HDR_LENGTH
]; /* not used yet */
204 u_char data
[ADB_MAX_MSG_LENGTH
]; /* packet data only */
205 u_char
*saveBuf
; /* where to save result */
206 u_char
*compRout
; /* completion routine pointer */
207 u_char
*compData
; /* completion routine data pointer */
208 u_int cmd
; /* the original command for this data */
209 u_int unsol
; /* 1 if packet was unsolicited */
210 u_int ack_only
; /* 1 for no special processing */
214 * Text representations of each hardware class
216 const char *adbHardwareDescr
[MAX_ADB_HW
+ 1] = {
226 * A few variables that we need and their initial values.
228 int adbHardware
= ADB_HW_UNKNOWN
;
229 int adbActionState
= ADB_ACTION_NOTREADY
;
230 int adbBusState
= ADB_BUS_UNKNOWN
;
231 int adbWaiting
= 0; /* waiting for return data from the device */
232 int adbWriteDelay
= 0; /* working on (or waiting to do) a write */
233 int adbOutQueueHasData
= 0; /* something in the queue waiting to go out */
234 int adbNextEnd
= 0; /* the next incoming bute is the last (II) */
235 int adbSoftPower
= 0; /* machine supports soft power */
237 int adbWaitingCmd
= 0; /* ADB command we are waiting for */
238 u_char
*adbBuffer
= (long)0; /* pointer to user data area */
239 void *adbCompRout
= (long)0; /* pointer to the completion routine */
240 void *adbCompData
= (long)0; /* pointer to the completion routine data */
241 long adbFakeInts
= 0; /* keeps track of fake ADB interrupts for
243 int adbStarting
= 1; /* doing ADBReInit so do polling differently */
244 int adbSendTalk
= 0; /* the intr routine is sending the talk, not
246 int adbPolling
= 0; /* we are polling for service request */
247 int adbPollCmd
= 0; /* the last poll command we sent */
249 u_char adbInputBuffer
[ADB_MAX_MSG_LENGTH
]; /* data input buffer */
250 u_char adbOutputBuffer
[ADB_MAX_MSG_LENGTH
]; /* data output buffer */
251 struct adbCmdHoldEntry adbOutQueue
; /* our 1 entry output queue */
253 int adbSentChars
= 0; /* how many characters we have sent */
254 int adbLastDevice
= 0; /* last ADB dev we heard from (II ONLY) */
255 int adbLastDevIndex
= 0; /* last ADB dev loc in dev table (II ONLY) */
256 int adbLastCommand
= 0; /* the last ADB command we sent (II) */
258 struct ADBDevEntry ADBDevTable
[16]; /* our ADB device table */
259 int ADBNumDevices
; /* num. of ADB devices found with ADBReInit */
261 struct adbCommand adbInbound
[ADB_QUEUE
]; /* incoming queue */
262 volatile int adbInCount
= 0; /* how many packets in in queue */
263 int adbInHead
= 0; /* head of in queue */
264 int adbInTail
= 0; /* tail of in queue */
265 struct adbCommand adbOutbound
[ADB_QUEUE
]; /* outgoing queue - not used yet */
266 int adbOutCount
= 0; /* how many packets in out queue */
267 int adbOutHead
= 0; /* head of out queue */
268 int adbOutTail
= 0; /* tail of out queue */
270 int tickle_count
= 0; /* how many tickles seen for this packet? */
271 int tickle_serial
= 0; /* the last packet tickled */
272 int adb_cuda_serial
= 0; /* the current packet */
274 callout_t adb_cuda_tickle_ch
;
276 void *adb_softintr_cookie
;
278 extern struct mac68k_machine_S mac68k_machine
;
280 void pm_setup_adb(void);
281 void pm_hw_setup(void);
282 void pm_check_adb_devices(int);
283 void pm_intr(void *);
284 int pm_adb_op(u_char
*, void *, void *, int);
285 void pm_init_adb_device(void);
288 * The following are private routines.
291 void print_single(u_char
*);
293 void adb_intr(void *);
294 void adb_intr_II(void *);
295 void adb_intr_IIsi(void *);
296 void adb_intr_cuda(void *);
297 void adb_soft_intr(void);
298 int send_adb_II(u_char
*, u_char
*, void *, void *, int);
299 int send_adb_IIsi(u_char
*, u_char
*, void *, void *, int);
300 int send_adb_cuda(u_char
*, u_char
*, void *, void *, int);
301 void adb_intr_cuda_test(void);
302 void adb_cuda_tickle(void);
303 void adb_pass_up(struct adbCommand
*);
304 void adb_op_comprout(void);
305 void adb_reinit(void);
306 int count_adbs(void);
307 int get_ind_adb_info(ADBDataBlock
*, int);
308 int get_adb_info(ADBDataBlock
*, int);
309 int set_adb_info(ADBSetInfoBlock
*, int);
310 void adb_setup_hw_type(void);
311 int adb_op(Ptr
, Ptr
, Ptr
, short);
312 void adb_read_II(u_char
*);
313 void adb_hw_setup(void);
314 void adb_hw_setup_IIsi(u_char
*);
315 void adb_comp_exec(void);
316 int adb_cmd_result(u_char
*);
317 int adb_cmd_extra(u_char
*);
318 int adb_guess_next_device(void);
319 int adb_prog_switch_enable(void);
320 int adb_prog_switch_disable(void);
321 /* we should create this and it will be the public version */
322 int send_adb(u_char
*, void *, void *);
323 void adb_iop_recv(IOP
*, struct iop_msg
*);
324 int send_adb_iop(int, u_char
*, void *, void *);
329 * Diagnostic display routine. Displays the hex values of the
330 * specified elements of the u_char. The length of the "string"
334 print_single(u_char
*str
)
339 printf_intr("no data - null pointer\n");
343 printf_intr("nothing returned\n");
347 printf_intr("ADB: ACK > 20 no way!\n");
350 printf_intr("(length=0x%x):", (u_int
)*str
);
351 for (x
= 1; x
<= *str
; x
++)
352 printf_intr(" 0x%02x", (u_int
)*(str
+ x
));
358 adb_cuda_tickle(void)
362 if (adbActionState
== ADB_ACTION_IN
) {
363 if (tickle_serial
== adb_cuda_serial
) {
364 if (++tickle_count
> 0) {
366 adbActionState
= ADB_ACTION_IDLE
;
367 adbInputBuffer
[0] = 0;
368 ADB_SET_STATE_IDLE_CUDA();
372 tickle_serial
= adb_cuda_serial
;
376 tickle_serial
= adb_cuda_serial
;
380 callout_reset(&adb_cuda_tickle_ch
, ADB_TICKLE_TICKS
,
381 (void *)adb_cuda_tickle
, NULL
);
385 * called when when an adb interrupt happens
387 * Cuda version of adb_intr
388 * TO DO: do we want to add some calls to intr_dispatch() here to
389 * grab serial interrupts?
392 adb_intr_cuda(void *arg
)
394 volatile int i
, ending
;
395 volatile unsigned int s
;
396 struct adbCommand packet
;
398 s
= splhigh(); /* can't be too careful - might be called */
399 /* from a routine, NOT an interrupt */
401 ADB_VIA_CLR_INTR(); /* clear interrupt */
402 ADB_VIA_INTR_DISABLE(); /* disable ADB interrupt on IIs. */
405 switch (adbActionState
) {
406 case ADB_ACTION_IDLE
:
408 * This is an unexpected packet, so grab the first (dummy)
409 * byte, set up the proper vars, and tell the chip we are
410 * starting to receive the packet by setting the TIP bit.
412 adbInputBuffer
[1] = ADB_SR();
414 if (ADB_INTR_IS_OFF
) /* must have been a fake start */
420 adbInputBuffer
[0] = 1;
421 adbActionState
= ADB_ACTION_IN
;
424 printf_intr("idle 0x%02x ", adbInputBuffer
[1]);
429 adbInputBuffer
[++adbInputBuffer
[0]] = ADB_SR();
430 /* intr off means this is the last byte (end of frame) */
436 if (1 == ending
) { /* end of message? */
439 printf_intr("in end 0x%02x ",
440 adbInputBuffer
[adbInputBuffer
[0]]);
441 print_single(adbInputBuffer
);
446 * Are we waiting AND does this packet match what we
447 * are waiting for AND is it coming from either the
448 * ADB or RTC/PRAM sub-device? This section _should_
449 * recognize all ADB and RTC/PRAM type commands, but
450 * there may be more... NOTE: commands are always at
451 * [4], even for RTC/PRAM commands.
453 /* set up data for adb_pass_up */
454 memcpy(packet
.data
, adbInputBuffer
, adbInputBuffer
[0] + 1);
456 if ((adbWaiting
== 1) &&
457 (adbInputBuffer
[4] == adbWaitingCmd
) &&
458 ((adbInputBuffer
[2] == 0x00) ||
459 (adbInputBuffer
[2] == 0x01))) {
460 packet
.saveBuf
= adbBuffer
;
461 packet
.compRout
= adbCompRout
;
462 packet
.compData
= adbCompData
;
465 adb_pass_up(&packet
);
467 adbWaitingCmd
= 0; /* reset "waiting" vars */
470 adbCompRout
= (long)0;
471 adbCompData
= (long)0;
475 adb_pass_up(&packet
);
479 /* reset vars and signal the end of this frame */
480 adbActionState
= ADB_ACTION_IDLE
;
481 adbInputBuffer
[0] = 0;
482 ADB_SET_STATE_IDLE_CUDA();
483 /*ADB_SET_SR_INPUT();*/
486 * If there is something waiting to be sent out,
487 * the set everything up and send the first byte.
489 if (adbWriteDelay
== 1) {
490 delay(ADB_DELAY
); /* required */
492 adbActionState
= ADB_ACTION_OUT
;
494 * If the interrupt is on, we were too slow
495 * and the chip has already started to send
496 * something to us, so back out of the write
497 * and start a read cycle.
499 if (ADB_INTR_IS_ON
) {
501 ADB_SET_STATE_IDLE_CUDA();
503 adbActionState
= ADB_ACTION_IDLE
;
504 adbInputBuffer
[0] = 0;
508 * If we got here, it's ok to start sending
509 * so load the first byte and tell the chip
514 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1];
517 ADB_TOGGLE_STATE_ACK_CUDA();
520 printf_intr("in 0x%02x ",
521 adbInputBuffer
[adbInputBuffer
[0]]);
527 i
= ADB_SR(); /* reset SR-intr in IFR */
530 printf_intr("intr out 0x%02x ", i
);
534 if (ADB_INTR_IS_ON
) { /* ADB intr low during write */
537 printf_intr("intr was on ");
539 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
540 ADB_SET_STATE_IDLE_CUDA();
541 adbSentChars
= 0; /* must start all over */
542 adbActionState
= ADB_ACTION_IDLE
; /* new state */
543 adbInputBuffer
[0] = 0;
544 adbWriteDelay
= 1; /* must retry when done with
547 goto switch_start
; /* process next state right
551 if (adbOutputBuffer
[0] == adbSentChars
) { /* check for done */
552 if (0 == adb_cmd_result(adbOutputBuffer
)) { /* do we expect data
554 adbWaiting
= 1; /* signal waiting for return */
555 adbWaitingCmd
= adbOutputBuffer
[2]; /* save waiting command */
556 } else { /* no talk, so done */
557 /* set up stuff for adb_pass_up */
558 memcpy(packet
.data
, adbInputBuffer
, adbInputBuffer
[0] + 1);
559 packet
.saveBuf
= adbBuffer
;
560 packet
.compRout
= adbCompRout
;
561 packet
.compData
= adbCompData
;
562 packet
.cmd
= adbWaitingCmd
;
565 adb_pass_up(&packet
);
567 /* reset "waiting" vars, just in case */
570 adbCompRout
= (long)0;
571 adbCompData
= (long)0;
574 adbWriteDelay
= 0; /* done writing */
575 adbActionState
= ADB_ACTION_IDLE
; /* signal bus is idle */
577 ADB_SET_STATE_IDLE_CUDA();
580 printf_intr("write done ");
583 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1]; /* send next byte */
584 ADB_TOGGLE_STATE_ACK_CUDA(); /* signal byte ready to
588 printf_intr("toggle ");
593 case ADB_ACTION_NOTREADY
:
596 printf_intr("adb: not yet initialized\n");
603 printf_intr("intr: unknown ADB state\n");
608 ADB_VIA_INTR_ENABLE(); /* enable ADB interrupt on IIs. */
610 splx(s
); /* restore */
613 } /* end adb_intr_cuda */
617 send_adb_cuda(u_char
*in
, u_char
*buffer
, void *compRout
, void *data
, int
624 printf_intr("SEND\n");
627 if (adbActionState
== ADB_ACTION_NOTREADY
)
630 /* Don't interrupt while we are messing with the ADB */
633 if ((adbActionState
== ADB_ACTION_IDLE
) && /* ADB available? */
634 (ADB_INTR_IS_OFF
)) { /* and no incoming interrupt? */
636 if (adbWriteDelay
== 0) /* it's busy, but is anything waiting? */
637 adbWriteDelay
= 1; /* if no, then we'll "queue"
641 return 1; /* really busy! */
646 printf_intr("QUEUE\n");
648 if ((long)in
== (long)0) { /* need to convert? */
650 * Don't need to use adb_cmd_extra here because this section
651 * will be called ONLY when it is an ADB command (no RTC or
654 if ((command
& 0x0c) == 0x08) /* copy addl data ONLY if
656 len
= buffer
[0]; /* length of additional data */
658 len
= 0;/* no additional data */
660 adbOutputBuffer
[0] = 2 + len
; /* dev. type + command + addl.
662 adbOutputBuffer
[1] = 0x00; /* mark as an ADB command */
663 adbOutputBuffer
[2] = (u_char
)command
; /* load command */
665 /* copy additional output data, if any */
666 memcpy(adbOutputBuffer
+ 3, buffer
+ 1, len
);
668 /* if data ready, just copy over */
669 memcpy(adbOutputBuffer
, in
, in
[0] + 2);
671 adbSentChars
= 0; /* nothing sent yet */
672 adbBuffer
= buffer
; /* save buffer to know where to save result */
673 adbCompRout
= compRout
; /* save completion routine pointer */
674 adbCompData
= data
; /* save completion routine data pointer */
675 adbWaitingCmd
= adbOutputBuffer
[2]; /* save wait command */
677 if (adbWriteDelay
!= 1) { /* start command now? */
680 printf_intr("out start NOW");
683 adbActionState
= ADB_ACTION_OUT
; /* set next state */
684 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
685 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1]; /* load byte for output */
686 ADB_SET_STATE_ACKOFF_CUDA();
687 ADB_SET_STATE_TIP(); /* tell ADB that we want to send */
689 adbWriteDelay
= 1; /* something in the write "queue" */
693 if (0x0100 <= (s
& 0x0700)) /* were VIA1 interrupts blocked? */
694 /* poll until byte done */
695 while ((adbActionState
!= ADB_ACTION_IDLE
) || (ADB_INTR_IS_ON
)
696 || (adbWaiting
== 1))
697 if (ADB_SR_INTR_IS_ON
) { /* wait for "interrupt" */
698 adb_intr_cuda(NULL
); /* go process it */
704 } /* send_adb_cuda */
708 adb_intr_II(void *arg
)
710 struct adbCommand packet
;
715 s
= splhigh(); /* can't be too careful - might be called */
716 /* from a routine, NOT an interrupt */
718 ADB_VIA_CLR_INTR(); /* clear interrupt */
720 ADB_VIA_INTR_DISABLE(); /* disable ADB interrupt on IIs. */
722 delay(ADB_DELAY
); /* yuck (don't remove) */
724 (void)intr_dispatch(0x70); /* grab any serial interrupts */
727 intr_on
= 1; /* save for later */
730 switch (adbActionState
) {
731 case ADB_ACTION_POLLING
:
733 if (adbOutQueueHasData
) {
735 if (adb_debug
& 0x80)
736 printf_intr("POLL-doing-out-queue. ");
738 ADB_SET_STATE_IDLE_II();
742 memcpy(adbOutputBuffer
, adbOutQueue
.outBuf
,
743 adbOutQueue
.outBuf
[0] + 2);
745 adbBuffer
= adbOutQueue
.saveBuf
; /* user data area */
746 adbCompRout
= adbOutQueue
.compRout
; /* completion routine */
747 adbCompData
= adbOutQueue
.data
; /* comp. rout. data */
748 adbOutQueueHasData
= 0; /* currently processing
750 adbSentChars
= 0; /* nothing sent yet */
751 adbActionState
= ADB_ACTION_OUT
; /* set next state */
752 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
753 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
754 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
755 ADB_SET_STATE_CMD(); /* tell ADB that we want to send */
760 printf_intr("pIDLE ");
762 adbActionState
= ADB_ACTION_IDLE
;
766 if (adb_debug
& 0x80)
769 adbActionState
= ADB_ACTION_IN
;
772 (void)intr_dispatch(0x70); /* grab any serial interrupts */
775 case ADB_ACTION_IDLE
:
778 adbBusState
= ADB_BUS_IDLE
;
779 adbActionState
= ADB_ACTION_IDLE
;
780 ADB_SET_STATE_IDLE_II();
783 adbInputBuffer
[0] = 1;
784 adbInputBuffer
[1] = ADB_SR(); /* get first byte */
786 if (adb_debug
& 0x80)
787 printf_intr("idle 0x%02x ", adbInputBuffer
[1]);
789 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
790 adbActionState
= ADB_ACTION_IN
; /* set next state */
791 ADB_SET_STATE_EVEN(); /* set bus state to even */
792 adbBusState
= ADB_BUS_EVEN
;
796 adbInputBuffer
[++adbInputBuffer
[0]] = ADB_SR(); /* get byte */
798 if (adb_debug
& 0x80)
799 printf_intr("in 0x%02x ",
800 adbInputBuffer
[adbInputBuffer
[0]]);
802 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
804 if (intr_on
) { /* process last byte of packet */
805 adbInputBuffer
[0]--; /* minus one */
807 * If intr_on was true, and it's the second byte, then
808 * the byte we just discarded is really valid, so
811 if (adbInputBuffer
[0] == 2) {
816 if (adb_debug
& 0x80) {
817 printf_intr("done: ");
818 print_single(adbInputBuffer
);
822 adbLastDevice
= ADB_CMDADDR(adbInputBuffer
[1]);
824 if (adbInputBuffer
[0] == 1 && !adbWaiting
) { /* SRQ!!!*/
826 if (adb_debug
& 0x80)
827 printf_intr(" xSRQ! ");
829 adb_guess_next_device();
831 if (adb_debug
& 0x80)
832 printf_intr("try 0x%0x ",
835 adbOutputBuffer
[0] = 1;
836 adbOutputBuffer
[1] = ADBTALK(adbLastDevice
, 0);
838 adbSentChars
= 0; /* nothing sent yet */
839 adbActionState
= ADB_ACTION_POLLING
; /* set next state */
840 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
841 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
842 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
843 ADB_SET_STATE_CMD(); /* tell ADB that we want to */
847 /* set up data for adb_pass_up */
848 memcpy(packet
.data
, adbInputBuffer
, adbInputBuffer
[0] + 1);
850 if (!adbWaiting
&& (adbInputBuffer
[0] != 0)) {
853 adb_pass_up(&packet
);
855 packet
.saveBuf
= adbBuffer
;
856 packet
.compRout
= adbCompRout
;
857 packet
.compData
= adbCompData
;
860 adb_pass_up(&packet
);
864 adbInputBuffer
[0] = 0;
866 adbCompRout
= (long)0;
867 adbCompData
= (long)0;
869 * Since we are done, check whether there is any data
870 * waiting to do out. If so, start the sending the data.
872 if (adbOutQueueHasData
== 1) {
874 if (adb_debug
& 0x80)
875 printf_intr("XXX: DOING OUT QUEUE\n");
878 memcpy(adbOutputBuffer
, adbOutQueue
.outBuf
,
879 adbOutQueue
.outBuf
[0] + 2);
880 adbBuffer
= adbOutQueue
.saveBuf
; /* user data area */
881 adbCompRout
= adbOutQueue
.compRout
; /* completion routine */
882 adbCompData
= adbOutQueue
.data
; /* comp. rout. data */
883 adbOutQueueHasData
= 0; /* currently processing
888 if (adb_debug
& 0x80)
889 printf_intr("XXending ");
891 adb_guess_next_device();
892 adbOutputBuffer
[0] = 1;
893 adbOutputBuffer
[1] = ((adbLastDevice
& 0x0f) << 4) | 0x0c;
894 adbSentChars
= 0; /* nothing sent yet */
895 adbActionState
= ADB_ACTION_POLLING
; /* set next state */
896 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
897 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
898 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
899 ADB_SET_STATE_CMD(); /* tell ADB that we want to */
905 * If send is true then something above determined that
906 * the message has ended and we need to start sending out
907 * a new message immediately. This could be because there
908 * is data waiting to go out or because an SRQ was seen.
911 adbSentChars
= 0; /* nothing sent yet */
912 adbActionState
= ADB_ACTION_OUT
; /* set next state */
913 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
914 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
915 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
916 ADB_SET_STATE_CMD(); /* tell ADB that we want to
920 /* We only get this far if the message hasn't ended yet. */
921 switch (adbBusState
) { /* set to next state */
923 ADB_SET_STATE_ODD(); /* set state to odd */
924 adbBusState
= ADB_BUS_ODD
;
928 ADB_SET_STATE_EVEN(); /* set state to even */
929 adbBusState
= ADB_BUS_EVEN
;
932 printf_intr("strange state!!!\n"); /* huh? */
938 i
= ADB_SR(); /* clear interrupt */
941 * If the outgoing data was a TALK, we must
942 * switch to input mode to get the result.
944 if ((adbOutputBuffer
[1] & 0x0c) == 0x0c) {
945 adbInputBuffer
[0] = 1;
946 adbInputBuffer
[1] = i
;
947 adbActionState
= ADB_ACTION_IN
;
949 adbBusState
= ADB_BUS_EVEN
;
950 ADB_SET_STATE_EVEN();
952 if (adb_debug
& 0x80)
953 printf_intr("talk out 0x%02x ", i
);
955 /* we want something back */
960 * If it's not a TALK, check whether all data has been sent.
961 * If so, call the completion routine and clean up. If not,
962 * advance to the next state.
965 if (adb_debug
& 0x80)
966 printf_intr("non-talk out 0x%0x ", i
);
969 if (adbOutputBuffer
[0] == adbSentChars
) { /* check for done */
971 if (adb_debug
& 0x80)
972 printf_intr("done \n");
974 /* set up stuff for adb_pass_up */
975 memcpy(packet
.data
, adbOutputBuffer
, adbOutputBuffer
[0] + 1);
976 packet
.saveBuf
= adbBuffer
;
977 packet
.compRout
= adbCompRout
;
978 packet
.compData
= adbCompData
;
979 packet
.cmd
= adbWaitingCmd
;
982 adb_pass_up(&packet
);
984 /* reset "waiting" vars, just in case */
986 adbCompRout
= (long)0;
987 adbCompData
= (long)0;
988 if (adbOutQueueHasData
== 1) {
990 memcpy(adbOutputBuffer
, adbOutQueue
.outBuf
,
991 adbOutQueue
.outBuf
[0] + 2);
992 adbBuffer
= adbOutQueue
.saveBuf
; /* user data area */
993 adbCompRout
= adbOutQueue
.compRout
; /* completion routine */
994 adbCompData
= adbOutQueue
.data
; /* comp. rout. data */
995 adbOutQueueHasData
= 0; /* currently processing
997 adbSentChars
= 0; /* nothing sent yet */
998 adbActionState
= ADB_ACTION_OUT
; /* set next state */
999 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
1000 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
1001 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
1002 ADB_SET_STATE_CMD(); /* tell ADB that we want to
1006 /* send talk to last device instead */
1007 adbOutputBuffer
[0] = 1;
1008 adbOutputBuffer
[1] =
1009 ADBTALK(ADB_CMDADDR(adbOutputBuffer
[1]), 0);
1011 adbSentChars
= 0; /* nothing sent yet */
1012 adbActionState
= ADB_ACTION_IDLE
; /* set next state */
1013 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
1014 ADB_SR() = adbOutputBuffer
[1]; /* load byte for output */
1015 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
1016 ADB_SET_STATE_CMD(); /* tell ADB that we want to */
1020 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1];
1021 switch (adbBusState
) { /* advance to next state */
1023 ADB_SET_STATE_ODD(); /* set state to odd */
1024 adbBusState
= ADB_BUS_ODD
;
1029 ADB_SET_STATE_EVEN(); /* set state to even */
1030 adbBusState
= ADB_BUS_EVEN
;
1036 printf_intr("strange state!!! (0x%x)\n",
1047 printf_intr("adb: unknown ADB state (during intr)\n");
1052 ADB_VIA_INTR_ENABLE(); /* enable ADB interrupt on IIs. */
1054 splx(s
); /* restore */
1062 * send_adb version for II series machines
1065 send_adb_II(u_char
*in
, u_char
*buffer
, void *compRout
, void *data
, int command
)
1069 if (adbActionState
== ADB_ACTION_NOTREADY
) /* return if ADB not
1073 /* Don't interrupt while we are messing with the ADB */
1076 if (0 != adbOutQueueHasData
) { /* right now, "has data" means "full" */
1077 splx(s
); /* sorry, try again later */
1080 if ((long)in
== (long)0) { /* need to convert? */
1082 * Don't need to use adb_cmd_extra here because this section
1083 * will be called ONLY when it is an ADB command (no RTC or
1084 * PRAM), especially on II series!
1086 if ((command
& 0x0c) == 0x08) /* copy addl data ONLY if
1087 * doing a listen! */
1088 len
= buffer
[0]; /* length of additional data */
1090 len
= 0;/* no additional data */
1092 adbOutQueue
.outBuf
[0] = 1 + len
; /* command + addl. data */
1093 adbOutQueue
.outBuf
[1] = (u_char
)command
; /* load command */
1095 /* copy additional output data, if any */
1096 memcpy(adbOutQueue
.outBuf
+ 2, buffer
+ 1, len
);
1098 /* if data ready, just copy over */
1099 memcpy(adbOutQueue
.outBuf
, in
, in
[0] + 2);
1101 adbOutQueue
.saveBuf
= buffer
; /* save buffer to know where to save
1103 adbOutQueue
.compRout
= compRout
; /* save completion routine
1105 adbOutQueue
.data
= data
;/* save completion routine data pointer */
1107 if ((adbActionState
== ADB_ACTION_IDLE
) && /* is ADB available? */
1108 (ADB_INTR_IS_OFF
)) { /* and no incoming interrupts? */
1109 /* then start command now */
1110 memcpy(adbOutputBuffer
, adbOutQueue
.outBuf
,
1111 adbOutQueue
.outBuf
[0] + 2); /* copy over data */
1113 adbBuffer
= adbOutQueue
.saveBuf
; /* pointer to user data
1115 adbCompRout
= adbOutQueue
.compRout
; /* pointer to the
1116 * completion routine */
1117 adbCompData
= adbOutQueue
.data
; /* pointer to the completion
1120 adbSentChars
= 0; /* nothing sent yet */
1121 adbActionState
= ADB_ACTION_OUT
; /* set next state */
1122 adbBusState
= ADB_BUS_CMD
; /* set bus to cmd state */
1124 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
1126 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1]; /* load byte for output */
1127 ADB_SET_STATE_CMD(); /* tell ADB that we want to send */
1128 adbOutQueueHasData
= 0; /* currently processing "queue" entry */
1130 adbOutQueueHasData
= 1; /* something in the write "queue" */
1134 if (0x0100 <= (s
& 0x0700)) /* were VIA1 interrupts blocked? */
1135 /* poll until message done */
1136 while ((adbActionState
!= ADB_ACTION_IDLE
) || (ADB_INTR_IS_ON
)
1137 || (adbWaiting
== 1))
1138 if (ADB_SR_INTR_IS_ON
) { /* wait for "interrupt" */
1139 adb_intr_II(NULL
); /* go process it */
1149 * This routine is called from the II series interrupt routine
1150 * to determine what the "next" device is that should be polled.
1153 adb_guess_next_device(void)
1159 * Start polling EVERY device, since we can't be sure there is
1160 * anything in the device table yet
1162 if (adbLastDevice
< 1 || adbLastDevice
> 15)
1164 if (++adbLastDevice
> 15) /* point to next one */
1167 /* find the next device using the device table */
1168 if (adbLastDevice
< 1 || adbLastDevice
> 15) /* let's be parinoid */
1170 last
= 1; /* default index location */
1172 for (i
= 1; i
< 16; i
++) /* find index entry */
1173 if (ADBDevTable
[i
].currentAddr
== adbLastDevice
) { /* look for device */
1174 last
= i
; /* found it */
1177 dummy
= last
; /* index to start at */
1178 for (;;) { /* find next device in index */
1179 if (++dummy
> 15) /* wrap around if needed */
1181 if (dummy
== last
) { /* didn't find any other
1182 * device! This can happen if
1183 * there are no devices on the
1188 /* found the next device */
1189 if (ADBDevTable
[dummy
].devType
!= 0)
1192 adbLastDevice
= ADBDevTable
[dummy
].currentAddr
;
1194 return adbLastDevice
;
1199 * Called when when an adb interrupt happens.
1200 * This routine simply transfers control over to the appropriate
1201 * code for the machine we are running on.
1206 switch (adbHardware
) {
1215 case ADB_HW_PB
: /* Should not come through here. */
1222 case ADB_HW_IOP
: /* Should not come through here. */
1225 case ADB_HW_UNKNOWN
:
1232 * called when when an adb interrupt happens
1234 * IIsi version of adb_intr
1238 adb_intr_IIsi(void *arg
)
1240 struct adbCommand packet
;
1244 s
= splhigh(); /* can't be too careful - might be called */
1245 /* from a routine, NOT an interrupt */
1247 ADB_VIA_CLR_INTR(); /* clear interrupt */
1249 ADB_VIA_INTR_DISABLE(); /* disable ADB interrupt on IIs. */
1252 switch (adbActionState
) {
1253 case ADB_ACTION_IDLE
:
1254 delay(ADB_DELAY
); /* short delay is required before the
1257 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
1258 ADB_SET_STATE_ACTIVE(); /* signal start of data frame */
1259 adbInputBuffer
[1] = ADB_SR(); /* get byte */
1260 adbInputBuffer
[0] = 1;
1261 adbActionState
= ADB_ACTION_IN
; /* set next state */
1263 ADB_SET_STATE_ACKON(); /* start ACK to ADB chip */
1264 delay(ADB_DELAY
); /* delay */
1265 ADB_SET_STATE_ACKOFF(); /* end ACK to ADB chip */
1266 (void)intr_dispatch(0x70); /* grab any serial interrupts */
1270 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
1271 adbInputBuffer
[++adbInputBuffer
[0]] = ADB_SR(); /* get byte */
1272 if (ADB_INTR_IS_OFF
) /* check for end of frame */
1277 ADB_SET_STATE_ACKON(); /* start ACK to ADB chip */
1278 delay(ADB_DELAY
); /* delay */
1279 ADB_SET_STATE_ACKOFF(); /* end ACK to ADB chip */
1280 (void)intr_dispatch(0x70); /* grab any serial interrupts */
1282 if (1 == ending
) { /* end of message? */
1283 ADB_SET_STATE_INACTIVE(); /* signal end of frame */
1285 * This section _should_ handle all ADB and RTC/PRAM
1286 * type commands, but there may be more... Note:
1287 * commands are always at [4], even for rtc/pram
1290 /* set up data for adb_pass_up */
1291 memcpy(packet
.data
, adbInputBuffer
, adbInputBuffer
[0] + 1);
1293 if ((adbWaiting
== 1) && /* are we waiting AND */
1294 (adbInputBuffer
[4] == adbWaitingCmd
) && /* the cmd we sent AND */
1295 ((adbInputBuffer
[2] == 0x00) || /* it's from the ADB
1297 (adbInputBuffer
[2] == 0x01))) { /* it's from the
1298 * PRAM/RTC device */
1300 packet
.saveBuf
= adbBuffer
;
1301 packet
.compRout
= adbCompRout
;
1302 packet
.compData
= adbCompData
;
1304 packet
.ack_only
= 0;
1305 adb_pass_up(&packet
);
1307 adbWaitingCmd
= 0; /* reset "waiting" vars */
1309 adbBuffer
= (long)0;
1310 adbCompRout
= (long)0;
1311 adbCompData
= (long)0;
1314 packet
.ack_only
= 0;
1315 adb_pass_up(&packet
);
1318 adbActionState
= ADB_ACTION_IDLE
;
1319 adbInputBuffer
[0] = 0; /* reset length */
1321 if (adbWriteDelay
== 1) { /* were we waiting to
1323 adbSentChars
= 0; /* nothing sent yet */
1324 adbActionState
= ADB_ACTION_OUT
; /* set next state */
1326 delay(ADB_DELAY
); /* delay */
1327 (void)intr_dispatch(0x70); /* grab any serial interrupts */
1329 if (ADB_INTR_IS_ON
) { /* ADB intr low during
1331 ADB_SET_STATE_IDLE_IISI(); /* reset */
1332 ADB_SET_SR_INPUT(); /* make sure SR is set
1334 adbSentChars
= 0; /* must start all over */
1335 adbActionState
= ADB_ACTION_IDLE
; /* new state */
1336 adbInputBuffer
[0] = 0;
1337 /* may be able to take this out later */
1338 delay(ADB_DELAY
); /* delay */
1341 ADB_SET_STATE_ACTIVE(); /* tell ADB that we want
1343 ADB_SET_STATE_ACKOFF(); /* make sure */
1344 ADB_SET_SR_OUTPUT(); /* set shift register
1346 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1];
1347 ADB_SET_STATE_ACKON(); /* tell ADB byte ready
1353 case ADB_ACTION_OUT
:
1354 i
= ADB_SR(); /* reset SR-intr in IFR */
1355 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
1357 ADB_SET_STATE_ACKOFF(); /* finish ACK */
1359 if (ADB_INTR_IS_ON
) { /* ADB intr low during write */
1360 ADB_SET_STATE_IDLE_IISI(); /* reset */
1361 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
1362 adbSentChars
= 0; /* must start all over */
1363 adbActionState
= ADB_ACTION_IDLE
; /* new state */
1364 adbInputBuffer
[0] = 0;
1365 adbWriteDelay
= 1; /* must retry when done with
1367 delay(ADB_DELAY
); /* delay */
1368 (void)intr_dispatch(0x70); /* grab any serial interrupts */
1369 goto switch_start
; /* process next state right
1373 delay(ADB_DELAY
); /* required delay */
1374 (void)intr_dispatch(0x70); /* grab any serial interrupts */
1376 if (adbOutputBuffer
[0] == adbSentChars
) { /* check for done */
1377 if (0 == adb_cmd_result(adbOutputBuffer
)) { /* do we expect data
1379 adbWaiting
= 1; /* signal waiting for return */
1380 adbWaitingCmd
= adbOutputBuffer
[2]; /* save waiting command */
1381 } else {/* no talk, so done */
1382 /* set up stuff for adb_pass_up */
1383 memcpy(packet
.data
, adbInputBuffer
,
1384 adbInputBuffer
[0] + 1);
1385 packet
.saveBuf
= adbBuffer
;
1386 packet
.compRout
= adbCompRout
;
1387 packet
.compData
= adbCompData
;
1388 packet
.cmd
= adbWaitingCmd
;
1390 packet
.ack_only
= 1;
1391 adb_pass_up(&packet
);
1393 /* reset "waiting" vars, just in case */
1395 adbBuffer
= (long)0;
1396 adbCompRout
= (long)0;
1397 adbCompData
= (long)0;
1400 adbWriteDelay
= 0; /* done writing */
1401 adbActionState
= ADB_ACTION_IDLE
; /* signal bus is idle */
1402 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
1403 ADB_SET_STATE_INACTIVE(); /* end of frame */
1405 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1]; /* send next byte */
1406 ADB_SET_STATE_ACKON(); /* signal byte ready to shift */
1410 case ADB_ACTION_NOTREADY
:
1413 printf_intr("adb: not yet initialized\n");
1420 printf_intr("intr: unknown ADB state\n");
1425 ADB_VIA_INTR_ENABLE(); /* enable ADB interrupt on IIs. */
1427 splx(s
); /* restore */
1430 } /* end adb_intr_IIsi */
1433 /*****************************************************************************
1434 * if the device is currently busy, and there is no data waiting to go out, then
1435 * the data is "queued" in the outgoing buffer. If we are already waiting, then
1437 * in: if (in == 0) then the command string is built from command and buffer
1438 * if (in != 0) then in is used as the command string
1439 * buffer: additional data to be sent (used only if in == 0)
1440 * this is also where return data is stored
1441 * compRout: the completion routine that is called when then return value
1442 * is received (if a return value is expected)
1443 * data: a data pointer that can be used by the completion routine
1444 * command: an ADB command to be sent (used only if in == 0)
1448 send_adb_IIsi(u_char
*in
, u_char
*buffer
, void *compRout
, void *data
, int
1453 if (adbActionState
== ADB_ACTION_NOTREADY
)
1456 /* Don't interrupt while we are messing with the ADB */
1459 if ((adbActionState
== ADB_ACTION_IDLE
) && /* ADB available? */
1460 (ADB_INTR_IS_OFF
)) {/* and no incoming interrupt? */
1463 if (adbWriteDelay
== 0) /* it's busy, but is anything waiting? */
1464 adbWriteDelay
= 1; /* if no, then we'll "queue"
1468 return 1; /* really busy! */
1471 if ((long)in
== (long)0) { /* need to convert? */
1473 * Don't need to use adb_cmd_extra here because this section
1474 * will be called ONLY when it is an ADB command (no RTC or
1477 if ((command
& 0x0c) == 0x08) /* copy addl data ONLY if
1478 * doing a listen! */
1479 len
= buffer
[0]; /* length of additional data */
1481 len
= 0;/* no additional data */
1483 adbOutputBuffer
[0] = 2 + len
; /* dev. type + command + addl.
1485 adbOutputBuffer
[1] = 0x00; /* mark as an ADB command */
1486 adbOutputBuffer
[2] = (u_char
)command
; /* load command */
1488 /* copy additional output data, if any */
1489 memcpy(adbOutputBuffer
+ 3, buffer
+ 1, len
);
1491 /* if data ready, just copy over */
1492 memcpy(adbOutputBuffer
, in
, in
[0] + 2);
1494 adbSentChars
= 0; /* nothing sent yet */
1495 adbBuffer
= buffer
; /* save buffer to know where to save result */
1496 adbCompRout
= compRout
; /* save completion routine pointer */
1497 adbCompData
= data
; /* save completion routine data pointer */
1498 adbWaitingCmd
= adbOutputBuffer
[2]; /* save wait command */
1500 if (adbWriteDelay
!= 1) { /* start command now? */
1501 adbActionState
= ADB_ACTION_OUT
; /* set next state */
1503 ADB_SET_STATE_ACTIVE(); /* tell ADB that we want to send */
1504 ADB_SET_STATE_ACKOFF(); /* make sure */
1506 ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
1508 ADB_SR() = adbOutputBuffer
[adbSentChars
+ 1]; /* load byte for output */
1510 ADB_SET_STATE_ACKON(); /* tell ADB byte ready to shift */
1512 adbWriteDelay
= 1; /* something in the write "queue" */
1516 if (0x0100 <= (s
& 0x0700)) /* were VIA1 interrupts blocked? */
1517 /* poll until byte done */
1518 while ((adbActionState
!= ADB_ACTION_IDLE
) || (ADB_INTR_IS_ON
)
1519 || (adbWaiting
== 1))
1520 if (ADB_SR_INTR_IS_ON
) { /* wait for "interrupt" */
1521 adb_intr_IIsi(NULL
); /* go process it */
1527 } /* send_adb_IIsi */
1530 adb_iop_recv(IOP
*iop
, struct iop_msg
*msg
)
1532 struct adbCommand pkt
;
1535 if (adbActionState
!= ADB_ACTION_RUNNING
)
1538 switch (msg
->status
) {
1539 case IOP_MSGSTAT_SENT
:
1540 if (0 == adb_cmd_result(msg
->msg
+ 1)) {
1542 adbWaitingCmd
= msg
->msg
[2];
1545 case IOP_MSGSTAT_RECEIVED
:
1546 case IOP_MSGSTAT_UNEXPECTED
:
1547 flags
= msg
->msg
[0];
1549 printf("ADB FLAGS 0x%x", flags
);
1553 (msg
->msg
[2] == adbWaitingCmd
)) {
1554 pkt
.saveBuf
= msg
->msg
+ 1;
1555 pkt
.compRout
= adbCompRout
;
1556 pkt
.compData
= adbCompData
;
1575 send_adb_iop(int cmd
, u_char
* buffer
, void *compRout
, void *data
)
1580 if (adbActionState
!= ADB_ACTION_RUNNING
)
1583 buff
[0] = IOP_ADB_FL_EXPLICIT
;
1584 buff
[1] = buffer
[0];
1586 cnt
= (int) buff
[1];
1587 memcpy(buff
+ 3, buffer
+ 1, cnt
);
1588 return iop_send_msg(ISM_IOP
, IOP_CHAN_ADB
, buff
, cnt
+3,
1589 adb_iop_recv
, NULL
);
1593 * adb_pass_up is called by the interrupt-time routines.
1594 * It takes the raw packet data that was received from the
1595 * device and puts it into the queue that the upper half
1596 * processes. It then signals for a soft ADB interrupt which
1597 * will eventually call the upper half routine (adb_soft_intr).
1599 * If in->unsol is 0, then this is either the notification
1600 * that the packet was sent (on a LISTEN, for example), or the
1601 * response from the device (on a TALK). The completion routine
1602 * is called only if the user specified one.
1604 * If in->unsol is 1, then this packet was unsolicited and
1605 * so we look up the device in the ADB device table to determine
1606 * what it's default service routine is.
1608 * If in->ack_only is 1, then we really only need to call
1609 * the completion routine, so don't do any other stuff.
1611 * Note that in->data contains the packet header AND data,
1612 * while adbInbound[]->data contains ONLY data.
1614 * Note: Called only at interrupt time. Assumes this.
1617 adb_pass_up(struct adbCommand
*in
)
1619 int start
= 0, len
= 0, cmd
= 0;
1622 /* temp for testing */
1623 /*u_char *buffer = 0;*/
1624 /*u_char *compdata = 0;*/
1625 /*u_char *comprout = 0;*/
1627 if (adbInCount
>= ADB_QUEUE
) {
1630 printf_intr("adb: ring buffer overflow\n");
1640 switch (adbHardware
) {
1644 if (in
->data
[0] < 2)
1647 len
= in
->data
[0]-1;
1653 /* If it's unsolicited, accept only ADB data for now */
1655 if (0 != in
->data
[2])
1658 if (in
->data
[0] < 5)
1661 len
= in
->data
[0]-4;
1667 if (in
->data
[0] < 2)
1670 len
= in
->data
[0]-1;
1674 case ADB_HW_UNKNOWN
:
1678 /* Make sure there is a valid device entry for this device */
1680 /* ignore unsolicited data during adbreinit */
1683 /* get device's comp. routine and data area */
1684 if (-1 == get_adb_info(&block
, ADB_CMDADDR(cmd
)))
1690 * If this is an unsolicited packet, we need to fill in
1691 * some info so adb_soft_intr can process this packet
1692 * properly. If it's not unsolicited, then use what
1693 * the caller sent us.
1696 adbInbound
[adbInTail
].compRout
= (void *)block
.dbServiceRtPtr
;
1697 adbInbound
[adbInTail
].compData
= (void *)block
.dbDataAreaAddr
;
1698 adbInbound
[adbInTail
].saveBuf
= (void *)adbInbound
[adbInTail
].data
;
1700 adbInbound
[adbInTail
].compRout
= (void *)in
->compRout
;
1701 adbInbound
[adbInTail
].compData
= (void *)in
->compData
;
1702 adbInbound
[adbInTail
].saveBuf
= (void *)in
->saveBuf
;
1706 if (adb_debug
&& in
->data
[1] == 2)
1707 printf_intr("adb: caught error\n");
1710 /* copy the packet data over */
1712 * TO DO: If the *_intr routines fed their incoming data
1713 * directly into an adbCommand struct, which is passed to
1714 * this routine, then we could eliminate this copy.
1716 memcpy(adbInbound
[adbInTail
].data
+ 1, in
->data
+ start
+ 1, len
);
1717 adbInbound
[adbInTail
].data
[0] = len
;
1718 adbInbound
[adbInTail
].cmd
= cmd
;
1721 if (++adbInTail
>= ADB_QUEUE
)
1725 * If the debugger is running, call upper half manually.
1726 * Otherwise, trigger a soft interrupt to handle the rest later.
1731 softint_schedule(adb_softintr_cookie
);
1738 * Called to process the packets after they have been
1739 * placed in the incoming queue.
1748 u_char
*comprout
= 0;
1749 u_char
*compdata
= 0;
1753 printf_intr("sr: %x\n", (s
& 0x0700));
1757 /*delay(2*ADB_DELAY);*/
1759 while (adbInCount
) {
1761 if (adb_debug
& 0x80)
1762 printf_intr("%x %x %x ",
1763 adbInCount
, adbInHead
, adbInTail
);
1765 /* get the data we need from the queue */
1766 buffer
= adbInbound
[adbInHead
].saveBuf
;
1767 comprout
= adbInbound
[adbInHead
].compRout
;
1768 compdata
= adbInbound
[adbInHead
].compData
;
1769 cmd
= adbInbound
[adbInHead
].cmd
;
1771 /* copy over data to data area if it's valid */
1773 * Note that for unsol packets we don't want to copy the
1774 * data anywhere, so buffer was already set to 0.
1775 * For ack_only buffer was set to 0, so don't copy.
1778 memcpy(buffer
, adbInbound
[adbInHead
].data
,
1779 adbInbound
[adbInHead
].data
[0] + 1);
1782 if (adb_debug
& 0x80) {
1783 printf_intr("%p %p %p %x ",
1784 buffer
, comprout
, compdata
, (short)cmd
);
1785 printf_intr("buf: ");
1786 print_single(adbInbound
[adbInHead
].data
);
1790 /* call default completion routine if it's valid */
1794 " movml #0xffff,%%sp@- \n" /* save all regs */
1795 " movl %0,%%a2 \n" /* compdata */
1796 " movl %1,%%a1 \n" /* comprout */
1797 " movl %2,%%a0 \n" /* buffer */
1798 " movl %3,%%d0 \n" /* cmd */
1799 " jbsr %%a1@ \n" /* go call routine */
1800 " movml %%sp@+,#0xffff" /* restore all regs */
1802 : "g"(compdata
), "g"(comprout
),
1803 "g"(buffer
), "g"(cmd
)
1804 : "d0", "a0", "a1", "a2");
1805 #else /* for macos based testing */
1808 movem
.l a0
/a1
/a2
/d0
, -(a7
)
1814 movem
.l(a7
)+, d0
/a2
/a1
/a0
1822 if (++adbInHead
>= ADB_QUEUE
)
1832 * This is my version of the ADBOp routine. It mainly just calls the
1833 * hardware-specific routine.
1835 * data : pointer to data area to be used by compRout
1836 * compRout : completion routine
1837 * buffer : for LISTEN: points to data to send - MAX 8 data bytes,
1838 * byte 0 = # of bytes
1839 * : for TALK: points to place to save return data
1840 * command : the adb command to send
1841 * result : 0 = success
1842 * : -1 = could not complete
1845 adb_op(Ptr buffer
, Ptr compRout
, Ptr data
, short command
)
1849 switch (adbHardware
) {
1851 result
= send_adb_II((u_char
*)0, (u_char
*)buffer
,
1852 (void *)compRout
, (void *)data
, (int)command
);
1861 result
= send_adb_iop((int)command
, (u_char
*)buffer
,
1862 (void *)compRout
, (void *)data
);
1871 result
= send_adb_IIsi((u_char
*)0, (u_char
*)buffer
,
1872 (void *)compRout
, (void *)data
, (int)command
);
1874 * I wish I knew why this delay is needed. It usually needs to
1875 * be here when several commands are sent in close succession,
1876 * especially early in device probes when doing collision
1877 * detection. It must be some race condition. Sigh. - jpw
1887 result
= pm_adb_op((u_char
*)buffer
, (void *)compRout
,
1888 (void *)data
, (int)command
);
1897 result
= send_adb_cuda((u_char
*)0, (u_char
*)buffer
,
1898 (void *)compRout
, (void *)data
, (int)command
);
1905 case ADB_HW_UNKNOWN
:
1914 * This routine sets up the possible machine specific hardware
1915 * config (mainly VIA settings) for the various models.
1921 u_char send_string
[ADB_MAX_MSG_LENGTH
];
1923 switch (adbHardware
) {
1925 via1_register_irq(2, adb_intr_II
, NULL
);
1927 via_reg(VIA1
, vDirB
) |= 0x30; /* register B bits 4 and 5:
1929 via_reg(VIA1
, vDirB
) &= 0xf7; /* register B bit 3: input */
1930 via_reg(VIA1
, vACR
) &= ~vSR_OUT
; /* make sure SR is set
1931 * to IN (II, IIsi) */
1932 adbActionState
= ADB_ACTION_IDLE
; /* used by all types of
1933 * hardware (II, IIsi) */
1934 adbBusState
= ADB_BUS_IDLE
; /* this var. used in II-series
1936 via_reg(VIA1
, vIER
) = 0x84; /* make sure VIA interrupts
1937 * are on (II, IIsi) */
1938 ADB_SET_STATE_IDLE_II(); /* set ADB bus state to idle */
1940 ADB_VIA_CLR_INTR(); /* clear interrupt */
1944 via_reg(VIA1
, vIER
) = 0x84;
1945 via_reg(VIA1
, vIFR
) = 0x04;
1947 adbActionState
= ADB_ACTION_RUNNING
;
1952 via1_register_irq(2, adb_intr_IIsi
, NULL
);
1953 via_reg(VIA1
, vDirB
) |= 0x30; /* register B bits 4 and 5:
1955 via_reg(VIA1
, vDirB
) &= 0xf7; /* register B bit 3: input */
1956 via_reg(VIA1
, vACR
) &= ~vSR_OUT
; /* make sure SR is set
1957 * to IN (II, IIsi) */
1958 adbActionState
= ADB_ACTION_IDLE
; /* used by all types of
1959 * hardware (II, IIsi) */
1960 adbBusState
= ADB_BUS_IDLE
; /* this var. used in II-series
1962 via_reg(VIA1
, vIER
) = 0x84; /* make sure VIA interrupts
1963 * are on (II, IIsi) */
1964 ADB_SET_STATE_IDLE_IISI(); /* set ADB bus state to idle */
1966 /* get those pesky clock ticks we missed while booting */
1967 for (i
= 0; i
< 30; i
++) {
1969 adb_hw_setup_IIsi(send_string
);
1972 printf_intr("adb: cleanup: ");
1973 print_single(send_string
);
1977 if (ADB_INTR_IS_OFF
)
1984 * XXX - really PM_VIA_CLR_INTR - should we put it in
1991 via1_register_irq(2, adb_intr_cuda
, NULL
);
1992 via_reg(VIA1
, vDirB
) |= 0x30; /* register B bits 4 and 5:
1994 via_reg(VIA1
, vDirB
) &= 0xf7; /* register B bit 3: input */
1995 via_reg(VIA1
, vACR
) &= ~vSR_OUT
; /* make sure SR is set
1997 via_reg(VIA1
, vACR
) = (via_reg(VIA1
, vACR
) | 0x0c) & ~0x10;
1998 adbActionState
= ADB_ACTION_IDLE
; /* used by all types of
2000 adbBusState
= ADB_BUS_IDLE
; /* this var. used in II-series
2002 via_reg(VIA1
, vIER
) = 0x84; /* make sure VIA interrupts
2004 ADB_SET_STATE_IDLE_CUDA(); /* set ADB bus state to idle */
2006 /* sort of a device reset */
2007 i
= ADB_SR(); /* clear interrupt */
2008 ADB_VIA_INTR_DISABLE(); /* no interrupts while clearing */
2009 ADB_SET_STATE_IDLE_CUDA(); /* reset state to idle */
2011 ADB_SET_STATE_TIP(); /* signal start of frame */
2013 ADB_TOGGLE_STATE_ACK_CUDA();
2015 ADB_CLR_STATE_TIP();
2017 ADB_SET_STATE_IDLE_CUDA(); /* back to idle state */
2018 i
= ADB_SR(); /* clear interrupt */
2019 ADB_VIA_INTR_ENABLE(); /* ints ok now */
2022 case ADB_HW_UNKNOWN
:
2024 via_reg(VIA1
, vIER
) = 0x04; /* turn interrupts off - TO
2025 * DO: turn PB ints off? */
2034 * This is sort of a "read" routine that forces the adb hardware through a read cycle
2035 * if there is something waiting. This helps "clean up" any commands that may have gotten
2036 * stuck or stopped during the boot process.
2040 adb_hw_setup_IIsi(u_char
*buffer
)
2050 i
= 1; /* skip over [0] */
2051 s
= splhigh(); /* block ALL interrupts while we are working */
2052 ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
2053 ADB_VIA_INTR_DISABLE(); /* disable ADB interrupt on IIs. */
2054 /* this is required, especially on faster machines */
2057 if (ADB_INTR_IS_ON
) {
2058 ADB_SET_STATE_ACTIVE(); /* signal start of data frame */
2061 while (0 == endofframe
) {
2063 * Poll for ADB interrupt and watch for timeout.
2064 * If time out, keep going in hopes of not hanging
2065 * the ADB chip - I think
2067 my_time
= ADB_DELAY
* 5;
2068 while ((ADB_SR_INTR_IS_OFF
) && (my_time
-- > 0))
2069 dummy
= via_reg(VIA1
, vBufB
);
2071 buffer
[i
++] = ADB_SR(); /* reset interrupt flag by
2074 * Perhaps put in a check here that ignores all data
2075 * after the first ADB_MAX_MSG_LENGTH bytes ???
2077 if (ADB_INTR_IS_OFF
) /* check for end of frame */
2080 ADB_SET_STATE_ACKON(); /* send ACK to ADB chip */
2081 delay(ADB_DELAY
); /* delay */
2082 ADB_SET_STATE_ACKOFF(); /* send ACK to ADB chip */
2084 ADB_SET_STATE_INACTIVE(); /* signal end of frame and
2087 /* probably don't need to delay this long */
2090 buffer
[0] = --i
; /* [0] is length of message */
2091 ADB_VIA_INTR_ENABLE(); /* enable ADB interrupt on IIs. */
2092 splx(s
); /* restore interrupts */
2095 } /* adb_hw_setup_IIsi */
2100 * adb_reinit sets up the adb stuff
2106 u_char send_string
[ADB_MAX_MSG_LENGTH
];
2107 ADBDataBlock data
; /* temp. holder for getting device info */
2112 int saveptr
; /* point to next free relocation address */
2114 int nonewtimes
; /* times thru loop w/o any new devices */
2118 callout_init(&adb_cuda_tickle_ch
, 0);
2122 adb_setup_hw_type(); /* setup hardware type */
2124 /* Make sure we are not interrupted while building the table. */
2125 /* ints must be on for PB & IOP (at least, for now) */
2126 if (adbHardware
!= ADB_HW_PB
&& adbHardware
!= ADB_HW_IOP
)
2129 s
= 0; /* XXX shut the compiler up*/
2131 ADBNumDevices
= 0; /* no devices yet */
2133 /* Let intr routines know we are running reinit */
2137 * Initialize the ADB table. For now, we'll always use the same table
2138 * that is defined at the beginning of this file - no mallocs.
2140 for (i
= 0; i
< 16; i
++) {
2141 ADBDevTable
[i
].devType
= 0;
2142 ADBDevTable
[i
].origAddr
= ADBDevTable
[i
].currentAddr
= 0;
2145 adb_hw_setup(); /* init the VIA bits and hard reset ADB */
2149 /* send an ADB reset first */
2150 (void)adb_op_sync((Ptr
)0, (Ptr
)0, (Ptr
)0, (short)0x00);
2154 * Probe for ADB devices. Probe devices 1-15 quickly to determine
2155 * which device addresses are in use and which are free. For each
2156 * address that is in use, move the device at that address to a higher
2157 * free address. Continue doing this at that address until no device
2158 * responds at that address. Then move the last device that was moved
2159 * back to the original address. Do this for the remaining addresses
2160 * that we determined were in use.
2162 * When finished, do this entire process over again with the updated
2163 * list of in use addresses. Do this until no new devices have been
2164 * found in 20 passes though the in use address list. (This probably
2165 * seems long and complicated, but it's the best way to detect multiple
2166 * devices at the same address - sometimes it takes a couple of tries
2167 * before the collision is detected.)
2170 /* initial scan through the devices */
2171 for (i
= 1; i
< 16; i
++) {
2172 command
= ADBTALK(i
, 3);
2173 result
= adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2174 (Ptr
)0, (short)command
);
2176 if (result
== 0 && send_string
[0] != 0) {
2177 /* found a device */
2179 KASSERT(ADBNumDevices
< 16);
2180 ADBDevTable
[ADBNumDevices
].devType
=
2181 (int)(send_string
[2]);
2182 ADBDevTable
[ADBNumDevices
].origAddr
= i
;
2183 ADBDevTable
[ADBNumDevices
].currentAddr
= i
;
2184 ADBDevTable
[ADBNumDevices
].DataAreaAddr
=
2186 ADBDevTable
[ADBNumDevices
].ServiceRtPtr
= (void *)0;
2187 pm_check_adb_devices(i
); /* tell pm driver device
2192 /* find highest unused address */
2193 for (saveptr
= 15; saveptr
> 0; saveptr
--)
2194 if (-1 == get_adb_info(&data
, saveptr
))
2198 if (adb_debug
& 0x80) {
2199 printf_intr("first free is: 0x%02x\n", saveptr
);
2200 printf_intr("devices: %i\n", ADBNumDevices
);
2204 nonewtimes
= 0; /* no loops w/o new devices */
2205 while (saveptr
> 0 && nonewtimes
++ < 11) {
2206 for (i
= 1;saveptr
> 0 && i
<= ADBNumDevices
; i
++) {
2207 device
= ADBDevTable
[i
].currentAddr
;
2209 if (adb_debug
& 0x80)
2210 printf_intr("moving device 0x%02x to 0x%02x "
2211 "(index 0x%02x) ", device
, saveptr
, i
);
2214 /* send TALK R3 to address */
2215 command
= ADBTALK(device
, 3);
2216 (void)adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2217 (Ptr
)0, (short)command
);
2219 /* move device to higher address */
2220 command
= ADBLISTEN(device
, 3);
2222 send_string
[1] = (u_char
)(saveptr
| 0x60);
2223 send_string
[2] = 0xfe;
2224 (void)adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2225 (Ptr
)0, (short)command
);
2228 /* send TALK R3 - anthing at new address? */
2229 command
= ADBTALK(saveptr
, 3);
2231 result
= adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2232 (Ptr
)0, (short)command
);
2235 if (result
!= 0 || send_string
[0] == 0) {
2237 * maybe there's a communication breakdown;
2238 * just in case, move it back from whence it
2239 * came, and we'll try again later
2241 command
= ADBLISTEN(saveptr
, 3);
2243 send_string
[1] = (u_char
)(device
| 0x60);
2244 send_string
[2] = 0x00;
2245 (void)adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2246 (Ptr
)0, (short)command
);
2248 if (adb_debug
& 0x80)
2249 printf_intr("failed, continuing\n");
2255 /* send TALK R3 - anything at old address? */
2256 command
= ADBTALK(device
, 3);
2258 result
= adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2259 (Ptr
)0, (short)command
);
2260 if (result
== 0 && send_string
[0] != 0) {
2261 /* new device found */
2262 /* update data for previously moved device */
2263 ADBDevTable
[i
].currentAddr
= saveptr
;
2265 if (adb_debug
& 0x80)
2266 printf_intr("old device at index %i\n",i
);
2268 /* add new device in table */
2270 if (adb_debug
& 0x80)
2271 printf_intr("new device found\n");
2273 if (saveptr
> ADBNumDevices
) {
2275 KASSERT(ADBNumDevices
< 16);
2277 ADBDevTable
[ADBNumDevices
].devType
=
2278 (int)(send_string
[2]);
2279 ADBDevTable
[ADBNumDevices
].origAddr
= device
;
2280 ADBDevTable
[ADBNumDevices
].currentAddr
= device
;
2281 /* These will be set correctly in adbsys.c */
2282 /* Until then, unsol. data will be ignored. */
2283 ADBDevTable
[ADBNumDevices
].DataAreaAddr
=
2285 ADBDevTable
[ADBNumDevices
].ServiceRtPtr
=
2287 /* find next unused address */
2288 for (x
= saveptr
; x
> 0; x
--) {
2289 if (-1 == get_adb_info(&data
, x
)) {
2297 if (adb_debug
& 0x80)
2298 printf_intr("new free is 0x%02x\n",
2302 /* tell pm driver device is here */
2303 pm_check_adb_devices(device
);
2306 if (adb_debug
& 0x80)
2307 printf_intr("moving back...\n");
2309 /* move old device back */
2310 command
= ADBLISTEN(saveptr
, 3);
2312 send_string
[1] = (u_char
)(device
| 0x60);
2313 send_string
[2] = 0xfe;
2314 (void)adb_op_sync((Ptr
)send_string
, (Ptr
)0,
2315 (Ptr
)0, (short)command
);
2323 for (i
= 1; i
<= ADBNumDevices
; i
++) {
2324 x
= get_ind_adb_info(&data
, i
);
2326 printf_intr("index 0x%x, addr 0x%x, type 0x%hx\n",
2327 i
, x
, data
.devType
);
2333 /* enable the programmer's switch, if we have one */
2334 adb_prog_switch_enable();
2339 if (0 == ADBNumDevices
) /* tell user if no devices found */
2340 printf_intr("adb: no devices found\n");
2344 adbStarting
= 0; /* not starting anymore */
2347 printf_intr("adb: ADBReInit complete\n");
2350 if (adbHardware
== ADB_HW_CUDA
)
2351 callout_reset(&adb_cuda_tickle_ch
, ADB_TICKLE_TICKS
,
2352 (void *)adb_cuda_tickle
, NULL
);
2354 /* ints must be on for PB & IOP (at least, for now) */
2355 if (adbHardware
!= ADB_HW_PB
&& adbHardware
!= ADB_HW_IOP
)
2364 * This is a general routine that calls the completion routine if there is one.
2365 * NOTE: This routine is now only used by pm_direct.c
2366 * All the code in this file (adb_direct.c) uses
2367 * the adb_pass_up routine now.
2372 if ((long)0 != adbCompRout
) /* don't call if empty return location */
2375 " movml #0xffff,%%sp@- \n" /* save all registers */
2376 " movl %0,%%a2 \n" /* adbCompData */
2377 " movl %1,%%a1 \n" /* adbCompRout */
2378 " movl %2,%%a0 \n" /* adbBuffer */
2379 " movl %3,%%d0 \n" /* adbWaitingCmd */
2380 " jbsr %%a1@ \n" /* go call the routine */
2381 " movml %%sp@+,#0xffff" /* restore all registers */
2383 : "g"(adbCompData
), "g"(adbCompRout
),
2384 "g"(adbBuffer
), "g"(adbWaitingCmd
)
2385 : "d0", "a0", "a1", "a2");
2386 #else /* for Mac OS-based testing */
2388 movem
.l a0
/a1
/a2
/d0
, -(a7
)
2389 move
.l adbCompData
, a2
2390 move
.l adbCompRout
, a1
2391 move
.l adbBuffer
, a0
2392 move
.w adbWaitingCmd
, d0
2394 movem
.l(a7
) +, d0
/a2
/a1
/a0
2403 * This routine lets the caller know whether the specified adb command string
2404 * should expect a returned result, such as a TALK command.
2406 * returns: 0 if a result should be expected
2407 * 1 if a result should NOT be expected
2410 adb_cmd_result(u_char
*in
)
2412 switch (adbHardware
) {
2415 /* was it an ADB talk command? */
2416 if ((in
[1] & 0x0c) == 0x0c)
2422 /* was it an ADB talk command? */
2423 if ((in
[1] == 0x00) && ((in
[2] & 0x0c) == 0x0c))
2425 /* was it an RTC/PRAM read date/time? */
2426 if ((in
[1] == 0x01) && (in
[2] == 0x03))
2433 case ADB_HW_UNKNOWN
:
2443 * This routine lets the caller know whether the specified adb command string
2444 * may have extra data appended to the end of it, such as a LISTEN command.
2446 * returns: 0 if extra data is allowed
2447 * 1 if extra data is NOT allowed
2450 adb_cmd_extra(u_char
*in
)
2452 switch (adbHardware
) {
2455 if ((in
[1] & 0x0c) == 0x08) /* was it a listen command? */
2462 * TO DO: support needs to be added to recognize RTC and PRAM
2465 if ((in
[2] & 0x0c) == 0x08) /* was it a listen command? */
2467 /* add others later */
2473 case ADB_HW_UNKNOWN
:
2481 adb_setup_hw_type(void)
2485 response
= mac68k_machine
.machineid
;
2488 * Determine what type of ADB hardware we are running on.
2491 case MACH_MACC610
: /* Centris 610 */
2492 case MACH_MACC650
: /* Centris 650 */
2493 case MACH_MACII
: /* II */
2494 case MACH_MACIICI
: /* IIci */
2495 case MACH_MACIICX
: /* IIcx */
2496 case MACH_MACIIX
: /* IIx */
2497 case MACH_MACQ610
: /* Quadra 610 */
2498 case MACH_MACQ650
: /* Quadra 650 */
2499 case MACH_MACQ700
: /* Quadra 700 */
2500 case MACH_MACQ800
: /* Quadra 800 */
2501 case MACH_MACSE30
: /* SE/30 */
2502 adbHardware
= ADB_HW_II
;
2505 printf_intr("adb: using II series hardware support\n");
2509 case MACH_MACCLASSICII
: /* Classic II */
2510 case MACH_MACLCII
: /* LC II, Performa 400/405/430 */
2511 case MACH_MACLCIII
: /* LC III, Performa 450 */
2512 case MACH_MACIISI
: /* IIsi */
2513 case MACH_MACIIVI
: /* IIvi */
2514 case MACH_MACIIVX
: /* IIvx */
2515 case MACH_MACP460
: /* Performa 460/465/467 */
2516 case MACH_MACP600
: /* Performa 600 */
2517 adbHardware
= ADB_HW_IISI
;
2520 printf_intr("adb: using IIsi series hardware support\n");
2524 case MACH_MACPB140
: /* PowerBook 140 */
2525 case MACH_MACPB145
: /* PowerBook 145 */
2526 case MACH_MACPB160
: /* PowerBook 160 */
2527 case MACH_MACPB165
: /* PowerBook 165 */
2528 case MACH_MACPB165C
: /* PowerBook 165c */
2529 case MACH_MACPB170
: /* PowerBook 170 */
2530 case MACH_MACPB180
: /* PowerBook 180 */
2531 case MACH_MACPB180C
: /* PowerBook 180c */
2532 adbHardware
= ADB_HW_PB
;
2536 printf_intr("adb: using PowerBook 100-series hardware support\n");
2540 case MACH_MACPB150
: /* PowerBook 150 */
2541 case MACH_MACPB210
: /* PowerBook Duo 210 */
2542 case MACH_MACPB230
: /* PowerBook Duo 230 */
2543 case MACH_MACPB250
: /* PowerBook Duo 250 */
2544 case MACH_MACPB270
: /* PowerBook Duo 270 */
2545 case MACH_MACPB280
: /* PowerBook Duo 280 */
2546 case MACH_MACPB280C
: /* PowerBook Duo 280c */
2547 case MACH_MACPB500
: /* PowerBook 500 series */
2548 case MACH_MACPB190
: /* PowerBook 190 */
2549 case MACH_MACPB190CS
: /* PowerBook 190cs */
2550 adbHardware
= ADB_HW_PB
;
2554 printf_intr("adb: using PowerBook Duo-series and PowerBook 500-series hardware support\n");
2558 case MACH_MACC660AV
: /* Centris 660AV */
2559 case MACH_MACCCLASSIC
: /* Color Classic */
2560 case MACH_MACCCLASSICII
: /* Color Classic II */
2561 case MACH_MACLC475
: /* LC 475, Performa 475/476 */
2562 case MACH_MACLC475_33
: /* Clock-chipped 47x */
2563 case MACH_MACLC520
: /* LC 520 */
2564 case MACH_MACLC575
: /* LC 575, Performa 575/577/578 */
2565 case MACH_MACP550
: /* LC 550, Performa 550 */
2566 case MACH_MACTV
: /* Macintosh TV */
2567 case MACH_MACP580
: /* Performa 580/588 */
2568 case MACH_MACQ605
: /* Quadra 605 */
2569 case MACH_MACQ605_33
: /* Clock-chipped Quadra 605 */
2570 case MACH_MACQ630
: /* LC 630, Performa 630, Quadra 630 */
2571 case MACH_MACQ840AV
: /* Quadra 840AV */
2572 adbHardware
= ADB_HW_CUDA
;
2575 printf_intr("adb: using Cuda series hardware support\n");
2579 case MACH_MACQ900
: /* Quadra 900 */
2580 case MACH_MACQ950
: /* Quadra 950 */
2581 case MACH_MACIIFX
: /* Mac IIfx */
2582 adbHardware
= ADB_HW_IOP
;
2583 iop_register_listener(ISM_IOP
, IOP_CHAN_ADB
, adb_iop_recv
, NULL
);
2586 printf_intr("adb: using IOP-based ADB\n");
2591 adbHardware
= ADB_HW_UNKNOWN
;
2594 printf_intr("adb: hardware type unknown for this machine\n");
2595 printf_intr("adb: ADB support is disabled\n");
2602 * Determine whether this machine has ADB based soft power.
2605 case MACH_MACCCLASSIC
: /* Color Classic */
2606 case MACH_MACCCLASSICII
: /* Color Classic II */
2607 case MACH_MACIISI
: /* IIsi */
2608 case MACH_MACIIVI
: /* IIvi */
2609 case MACH_MACIIVX
: /* IIvx */
2610 case MACH_MACLC520
: /* LC 520 */
2611 case MACH_MACLC575
: /* LC 575, Performa 575/577/578 */
2612 case MACH_MACP550
: /* LC 550, Performa 550 */
2613 case MACH_MACTV
: /* Macintosh TV */
2614 case MACH_MACP580
: /* Performa 580/588 */
2615 case MACH_MACP600
: /* Performa 600 */
2616 case MACH_MACQ630
: /* LC 630, Performa 630, Quadra 630 */
2617 case MACH_MACQ840AV
: /* Quadra 840AV */
2631 for (i
= 1; i
< 16; i
++)
2632 if (0 != ADBDevTable
[i
].currentAddr
)
2639 get_ind_adb_info(ADBDataBlock
*info
, int index
)
2641 if ((index
< 1) || (index
> 15)) /* check range 1-15 */
2645 if (adb_debug
& 0x80)
2646 printf_intr("index 0x%x devType is: 0x%x\n", index
,
2647 ADBDevTable
[index
].devType
);
2649 if (0 == ADBDevTable
[index
].devType
) /* make sure it's a valid entry */
2652 info
->devType
= (unsigned char)(ADBDevTable
[index
].devType
);
2653 info
->origADBAddr
= (unsigned char)(ADBDevTable
[index
].origAddr
);
2654 info
->dbServiceRtPtr
= (Ptr
)ADBDevTable
[index
].ServiceRtPtr
;
2655 info
->dbDataAreaAddr
= (Ptr
)ADBDevTable
[index
].DataAreaAddr
;
2657 return (ADBDevTable
[index
].currentAddr
);
2661 get_adb_info(ADBDataBlock
*info
, int adbAddr
)
2665 if ((adbAddr
< 1) || (adbAddr
> 15)) /* check range 1-15 */
2668 for (i
= 1; i
< 15; i
++)
2669 if (ADBDevTable
[i
].currentAddr
== adbAddr
) {
2670 info
->devType
= (unsigned char)(ADBDevTable
[i
].devType
);
2671 info
->origADBAddr
= (unsigned char)(ADBDevTable
[i
].origAddr
);
2672 info
->dbServiceRtPtr
= (Ptr
)ADBDevTable
[i
].ServiceRtPtr
;
2673 info
->dbDataAreaAddr
= ADBDevTable
[i
].DataAreaAddr
;
2674 return 0; /* found */
2677 return (-1); /* not found */
2681 set_adb_info(ADBSetInfoBlock
*info
, int adbAddr
)
2685 if ((adbAddr
< 1) || (adbAddr
> 15)) /* check range 1-15 */
2688 for (i
= 1; i
< 15; i
++)
2689 if (ADBDevTable
[i
].currentAddr
== adbAddr
) {
2690 ADBDevTable
[i
].ServiceRtPtr
=
2691 (void *)(info
->siServiceRtPtr
);
2692 ADBDevTable
[i
].DataAreaAddr
= info
->siDataAreaAddr
;
2693 return 0; /* found */
2696 return (-1); /* not found */
2705 return 1; /* mimic mrg_adbintr in macrom.h just in case */
2712 return 1; /* mimic mrg_pmintr in macrom.h just in case */
2715 /* caller should really use machine-independent version: getPramTime */
2716 /* this version does pseudo-adb access only */
2718 adb_read_date_time(unsigned long *curtime
)
2720 u_char output
[ADB_MAX_MSG_LENGTH
];
2722 volatile int flag
= 0;
2724 switch (adbHardware
) {
2732 output
[0] = 0x02; /* 2 byte message */
2733 output
[1] = 0x01; /* to pram/rtc device */
2734 output
[2] = 0x03; /* read date/time */
2735 result
= send_adb_IIsi((u_char
*)output
, (u_char
*)output
,
2736 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2737 if (result
!= 0) /* exit if not sent */
2740 adb_spin(&flag
); /* wait for result */
2741 if (flag
== 0) /* exit it timeout */
2744 *curtime
= (long)(*(long *)(output
+ 1));
2751 output
[0] = 0x02; /* 2 byte message */
2752 output
[1] = 0x01; /* to pram/rtc device */
2753 output
[2] = 0x03; /* read date/time */
2754 result
= send_adb_cuda((u_char
*)output
, (u_char
*)output
,
2755 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2756 if (result
!= 0) /* exit if not sent */
2759 adb_spin(&flag
); /* wait for result */
2760 if (flag
== 0) /* exit it timeout */
2763 *curtime
= (long)(*(long *)(output
+ 1));
2766 case ADB_HW_UNKNOWN
:
2772 /* caller should really use machine-independent version: setPramTime */
2773 /* this version does pseudo-adb access only */
2775 adb_set_date_time(unsigned long curtime
)
2777 u_char output
[ADB_MAX_MSG_LENGTH
];
2779 volatile int flag
= 0;
2781 switch (adbHardware
) {
2789 output
[0] = 0x06; /* 6 byte message */
2790 output
[1] = 0x01; /* to pram/rtc device */
2791 output
[2] = 0x09; /* set date/time */
2792 output
[3] = (u_char
)(curtime
>> 24);
2793 output
[4] = (u_char
)(curtime
>> 16);
2794 output
[5] = (u_char
)(curtime
>> 8);
2795 output
[6] = (u_char
)(curtime
);
2796 result
= send_adb_IIsi((u_char
*)output
, (u_char
*)0,
2797 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2798 if (result
!= 0) /* exit if not sent */
2801 adb_spin(&flag
); /* wait for result */
2802 if (flag
== 0) /* exit it timeout */
2811 output
[0] = 0x06; /* 6 byte message */
2812 output
[1] = 0x01; /* to pram/rtc device */
2813 output
[2] = 0x09; /* set date/time */
2814 output
[3] = (u_char
)(curtime
>> 24);
2815 output
[4] = (u_char
)(curtime
>> 16);
2816 output
[5] = (u_char
)(curtime
>> 8);
2817 output
[6] = (u_char
)(curtime
);
2818 result
= send_adb_cuda((u_char
*)output
, (u_char
*)0,
2819 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2820 if (result
!= 0) /* exit if not sent */
2823 adb_spin(&flag
); /* wait for result */
2824 if (flag
== 0) /* exit it timeout */
2829 case ADB_HW_UNKNOWN
:
2839 u_char output
[ADB_MAX_MSG_LENGTH
];
2847 switch (adbHardware
) {
2849 output
[0] = 0x02; /* 2 byte message */
2850 output
[1] = 0x01; /* to pram/rtc/soft-power device */
2851 output
[2] = 0x0a; /* set date/time */
2852 result
= send_adb_IIsi((u_char
*)output
, (u_char
*)0,
2853 (void *)0, (void *)0, (int)0);
2854 if (result
!= 0) /* exit if not sent */
2857 for (;;); /* wait for power off */
2865 output
[0] = 0x02; /* 2 byte message */
2866 output
[1] = 0x01; /* to pram/rtc/soft-power device */
2867 output
[2] = 0x0a; /* set date/time */
2868 result
= send_adb_cuda((u_char
*)output
, (u_char
*)0,
2869 (void *)0, (void *)0, (int)0);
2870 if (result
!= 0) /* exit if not sent */
2873 for (;;); /* wait for power off */
2877 case ADB_HW_II
: /* II models don't do ADB soft power */
2878 case ADB_HW_IOP
: /* IOP models don't do ADB soft power */
2879 case ADB_HW_UNKNOWN
:
2886 adb_prog_switch_enable(void)
2888 u_char output
[ADB_MAX_MSG_LENGTH
];
2890 volatile int flag
= 0;
2892 switch (adbHardware
) {
2894 output
[0] = 0x03; /* 3 byte message */
2895 output
[1] = 0x01; /* to pram/rtc/soft-power device */
2896 output
[2] = 0x1c; /* prog. switch control */
2897 output
[3] = 0x01; /* enable */
2898 result
= send_adb_IIsi((u_char
*)output
, (u_char
*)0,
2899 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2900 if (result
!= 0) /* exit if not sent */
2903 adb_spin(&flag
); /* wait for result */
2904 if (flag
== 0) /* exit it timeout */
2912 case ADB_HW_II
: /* II models don't do prog. switch */
2913 case ADB_HW_IOP
: /* IOP models don't do prog. switch */
2914 case ADB_HW_CUDA
: /* cuda doesn't do prog. switch TO DO: verify this */
2915 case ADB_HW_UNKNOWN
:
2922 adb_prog_switch_disable(void)
2924 u_char output
[ADB_MAX_MSG_LENGTH
];
2926 volatile int flag
= 0;
2928 switch (adbHardware
) {
2930 output
[0] = 0x03; /* 3 byte message */
2931 output
[1] = 0x01; /* to pram/rtc/soft-power device */
2932 output
[2] = 0x1c; /* prog. switch control */
2933 output
[3] = 0x01; /* disable */
2934 result
= send_adb_IIsi((u_char
*)output
, (u_char
*)0,
2935 (void *)adb_op_comprout
, __UNVOLATILE(&flag
), (int)0);
2936 if (result
!= 0) /* exit if not sent */
2939 adb_spin(&flag
); /* wait for result */
2940 if (flag
== 0) /* exit it timeout */
2948 case ADB_HW_II
: /* II models don't do prog. switch */
2949 case ADB_HW_IOP
: /* IOP models don't do prog. switch */
2950 case ADB_HW_CUDA
: /* cuda doesn't do prog. switch */
2951 case ADB_HW_UNKNOWN
:
2960 return (count_adbs());
2970 GetIndADB(ADBDataBlock
*info
, int index
)
2972 return (get_ind_adb_info(info
, index
));
2976 GetADBInfo(ADBDataBlock
*info
, int adbAddr
)
2978 return (get_adb_info(info
, adbAddr
));
2982 SetADBInfo(ADBSetInfoBlock
*info
, int adbAddr
)
2984 return (set_adb_info(info
, adbAddr
));
2988 ADBOp(Ptr buffer
, Ptr compRout
, Ptr data
, short commandNum
)
2990 return (adb_op(buffer
, compRout
, data
, commandNum
));