adb_direct.c revision 1.19.6.2 1 1.19.6.2 nathanw /* $NetBSD: adb_direct.c,v 1.19.6.2 2002/01/11 23:38:34 nathanw Exp $ */
2 1.19.6.2 nathanw
3 1.19.6.2 nathanw /* From: adb_direct.c 2.02 4/18/97 jpw */
4 1.19.6.2 nathanw
5 1.19.6.2 nathanw /*
6 1.19.6.2 nathanw * Copyright (C) 1996, 1997 John P. Wittkoski
7 1.19.6.2 nathanw * All rights reserved.
8 1.19.6.2 nathanw *
9 1.19.6.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.19.6.2 nathanw * modification, are permitted provided that the following conditions
11 1.19.6.2 nathanw * are met:
12 1.19.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.19.6.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.19.6.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.19.6.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.19.6.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.19.6.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.19.6.2 nathanw * must display the following acknowledgement:
19 1.19.6.2 nathanw * This product includes software developed by John P. Wittkoski.
20 1.19.6.2 nathanw * 4. The name of the author may not be used to endorse or promote products
21 1.19.6.2 nathanw * derived from this software without specific prior written permission.
22 1.19.6.2 nathanw *
23 1.19.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.19.6.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.19.6.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.19.6.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.19.6.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.19.6.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.19.6.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.19.6.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.19.6.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 1.19.6.2 nathanw * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.19.6.2 nathanw */
34 1.19.6.2 nathanw
35 1.19.6.2 nathanw /*
36 1.19.6.2 nathanw * This code is rather messy, but I don't have time right now
37 1.19.6.2 nathanw * to clean it up as much as I would like.
38 1.19.6.2 nathanw * But it works, so I'm happy. :-) jpw
39 1.19.6.2 nathanw */
40 1.19.6.2 nathanw
41 1.19.6.2 nathanw /*
42 1.19.6.2 nathanw * TO DO:
43 1.19.6.2 nathanw * - We could reduce the time spent in the adb_intr_* routines
44 1.19.6.2 nathanw * by having them save the incoming and outgoing data directly
45 1.19.6.2 nathanw * in the adbInbound and adbOutbound queues, as it would reduce
46 1.19.6.2 nathanw * the number of times we need to copy the data around. It
47 1.19.6.2 nathanw * would also make the code more readable and easier to follow.
48 1.19.6.2 nathanw * - (Related to above) Use the header part of adbCommand to
49 1.19.6.2 nathanw * reduce the number of copies we have to do of the data.
50 1.19.6.2 nathanw * - (Related to above) Actually implement the adbOutbound queue.
51 1.19.6.2 nathanw * This is fairly easy once you switch all the intr routines
52 1.19.6.2 nathanw * over to using adbCommand structs directly.
53 1.19.6.2 nathanw * - There is a bug in the state machine of adb_intr_cuda
54 1.19.6.2 nathanw * code that causes hangs, especially on 030 machines, probably
55 1.19.6.2 nathanw * because of some timing issues. Because I have been unable to
56 1.19.6.2 nathanw * determine the exact cause of this bug, I used the timeout function
57 1.19.6.2 nathanw * to check for and recover from this condition. If anyone finds
58 1.19.6.2 nathanw * the actual cause of this bug, the calls to timeout and the
59 1.19.6.2 nathanw * adb_cuda_tickle routine can be removed.
60 1.19.6.2 nathanw */
61 1.19.6.2 nathanw
62 1.19.6.2 nathanw #include <sys/param.h>
63 1.19.6.2 nathanw #include <sys/cdefs.h>
64 1.19.6.2 nathanw #include <sys/systm.h>
65 1.19.6.2 nathanw #include <sys/callout.h>
66 1.19.6.2 nathanw #include <sys/device.h>
67 1.19.6.2 nathanw
68 1.19.6.2 nathanw #include <machine/param.h>
69 1.19.6.2 nathanw #include <machine/cpu.h>
70 1.19.6.2 nathanw #include <machine/adbsys.h>
71 1.19.6.2 nathanw
72 1.19.6.2 nathanw #include <macppc/dev/viareg.h>
73 1.19.6.2 nathanw #include <macppc/dev/adbvar.h>
74 1.19.6.2 nathanw #include <macppc/dev/pm_direct.h>
75 1.19.6.2 nathanw
76 1.19.6.2 nathanw #define printf_intr printf
77 1.19.6.2 nathanw
78 1.19.6.2 nathanw #ifdef DEBUG
79 1.19.6.2 nathanw #ifndef ADB_DEBUG
80 1.19.6.2 nathanw #define ADB_DEBUG
81 1.19.6.2 nathanw #endif
82 1.19.6.2 nathanw #endif
83 1.19.6.2 nathanw
84 1.19.6.2 nathanw /* some misc. leftovers */
85 1.19.6.2 nathanw #define vPB 0x0000
86 1.19.6.2 nathanw #define vPB3 0x08
87 1.19.6.2 nathanw #define vPB4 0x10
88 1.19.6.2 nathanw #define vPB5 0x20
89 1.19.6.2 nathanw #define vSR_INT 0x04
90 1.19.6.2 nathanw #define vSR_OUT 0x10
91 1.19.6.2 nathanw
92 1.19.6.2 nathanw /* the type of ADB action that we are currently preforming */
93 1.19.6.2 nathanw #define ADB_ACTION_NOTREADY 0x1 /* has not been initialized yet */
94 1.19.6.2 nathanw #define ADB_ACTION_IDLE 0x2 /* the bus is currently idle */
95 1.19.6.2 nathanw #define ADB_ACTION_OUT 0x3 /* sending out a command */
96 1.19.6.2 nathanw #define ADB_ACTION_IN 0x4 /* receiving data */
97 1.19.6.2 nathanw #define ADB_ACTION_POLLING 0x5 /* polling - II only */
98 1.19.6.2 nathanw
99 1.19.6.2 nathanw /*
100 1.19.6.2 nathanw * These describe the state of the ADB bus itself, although they
101 1.19.6.2 nathanw * don't necessarily correspond directly to ADB states.
102 1.19.6.2 nathanw * Note: these are not really used in the IIsi code.
103 1.19.6.2 nathanw */
104 1.19.6.2 nathanw #define ADB_BUS_UNKNOWN 0x1 /* we don't know yet - all models */
105 1.19.6.2 nathanw #define ADB_BUS_IDLE 0x2 /* bus is idle - all models */
106 1.19.6.2 nathanw #define ADB_BUS_CMD 0x3 /* starting a command - II models */
107 1.19.6.2 nathanw #define ADB_BUS_ODD 0x4 /* the "odd" state - II models */
108 1.19.6.2 nathanw #define ADB_BUS_EVEN 0x5 /* the "even" state - II models */
109 1.19.6.2 nathanw #define ADB_BUS_ACTIVE 0x6 /* active state - IIsi models */
110 1.19.6.2 nathanw #define ADB_BUS_ACK 0x7 /* currently ACKing - IIsi models */
111 1.19.6.2 nathanw
112 1.19.6.2 nathanw /*
113 1.19.6.2 nathanw * Shortcuts for setting or testing the VIA bit states.
114 1.19.6.2 nathanw * Not all shortcuts are used for every type of ADB hardware.
115 1.19.6.2 nathanw */
116 1.19.6.2 nathanw #define ADB_SET_STATE_IDLE_II() via_reg_or(VIA1, vBufB, (vPB4 | vPB5))
117 1.19.6.2 nathanw #define ADB_SET_STATE_IDLE_IISI() via_reg_and(VIA1, vBufB, ~(vPB4 | vPB5))
118 1.19.6.2 nathanw #define ADB_SET_STATE_IDLE_CUDA() via_reg_or(VIA1, vBufB, (vPB4 | vPB5))
119 1.19.6.2 nathanw #define ADB_SET_STATE_CMD() via_reg_and(VIA1, vBufB, ~(vPB4 | vPB5))
120 1.19.6.2 nathanw #define ADB_SET_STATE_EVEN() write_via_reg(VIA1, vBufB, \
121 1.19.6.2 nathanw (read_via_reg(VIA1, vBufB) | vPB4) & ~vPB5)
122 1.19.6.2 nathanw #define ADB_SET_STATE_ODD() write_via_reg(VIA1, vBufB, \
123 1.19.6.2 nathanw (read_via_reg(VIA1, vBufB) | vPB5) & ~vPB4 )
124 1.19.6.2 nathanw #define ADB_SET_STATE_ACTIVE() via_reg_or(VIA1, vBufB, vPB5)
125 1.19.6.2 nathanw #define ADB_SET_STATE_INACTIVE() via_reg_and(VIA1, vBufB, ~vPB5)
126 1.19.6.2 nathanw #define ADB_SET_STATE_TIP() via_reg_and(VIA1, vBufB, ~vPB5)
127 1.19.6.2 nathanw #define ADB_CLR_STATE_TIP() via_reg_or(VIA1, vBufB, vPB5)
128 1.19.6.2 nathanw #define ADB_SET_STATE_ACKON() via_reg_or(VIA1, vBufB, vPB4)
129 1.19.6.2 nathanw #define ADB_SET_STATE_ACKOFF() via_reg_and(VIA1, vBufB, ~vPB4)
130 1.19.6.2 nathanw #define ADB_TOGGLE_STATE_ACK_CUDA() via_reg_xor(VIA1, vBufB, vPB4)
131 1.19.6.2 nathanw #define ADB_SET_STATE_ACKON_CUDA() via_reg_and(VIA1, vBufB, ~vPB4)
132 1.19.6.2 nathanw #define ADB_SET_STATE_ACKOFF_CUDA() via_reg_or(VIA1, vBufB, vPB4)
133 1.19.6.2 nathanw #define ADB_SET_SR_INPUT() via_reg_and(VIA1, vACR, ~vSR_OUT)
134 1.19.6.2 nathanw #define ADB_SET_SR_OUTPUT() via_reg_or(VIA1, vACR, vSR_OUT)
135 1.19.6.2 nathanw #define ADB_SR() read_via_reg(VIA1, vSR)
136 1.19.6.2 nathanw #define ADB_VIA_INTR_ENABLE() write_via_reg(VIA1, vIER, 0x84)
137 1.19.6.2 nathanw #define ADB_VIA_INTR_DISABLE() write_via_reg(VIA1, vIER, 0x04)
138 1.19.6.2 nathanw #define ADB_VIA_CLR_INTR() write_via_reg(VIA1, vIFR, 0x04)
139 1.19.6.2 nathanw #define ADB_INTR_IS_OFF (vPB3 == (read_via_reg(VIA1, vBufB) & vPB3))
140 1.19.6.2 nathanw #define ADB_INTR_IS_ON (0 == (read_via_reg(VIA1, vBufB) & vPB3))
141 1.19.6.2 nathanw #define ADB_SR_INTR_IS_OFF (0 == (read_via_reg(VIA1, vIFR) & vSR_INT))
142 1.19.6.2 nathanw #define ADB_SR_INTR_IS_ON (vSR_INT == (read_via_reg(VIA1, \
143 1.19.6.2 nathanw vIFR) & vSR_INT))
144 1.19.6.2 nathanw
145 1.19.6.2 nathanw /*
146 1.19.6.2 nathanw * This is the delay that is required (in uS) between certain
147 1.19.6.2 nathanw * ADB transactions. The actual timing delay for for each uS is
148 1.19.6.2 nathanw * calculated at boot time to account for differences in machine speed.
149 1.19.6.2 nathanw */
150 1.19.6.2 nathanw #define ADB_DELAY 150
151 1.19.6.2 nathanw
152 1.19.6.2 nathanw /*
153 1.19.6.2 nathanw * Maximum ADB message length; includes space for data, result, and
154 1.19.6.2 nathanw * device code - plus a little for safety.
155 1.19.6.2 nathanw */
156 1.19.6.2 nathanw #define ADB_MAX_MSG_LENGTH 16
157 1.19.6.2 nathanw #define ADB_MAX_HDR_LENGTH 8
158 1.19.6.2 nathanw
159 1.19.6.2 nathanw #define ADB_QUEUE 32
160 1.19.6.2 nathanw #define ADB_TICKLE_TICKS 4
161 1.19.6.2 nathanw
162 1.19.6.2 nathanw /*
163 1.19.6.2 nathanw * A structure for storing information about each ADB device.
164 1.19.6.2 nathanw */
165 1.19.6.2 nathanw struct ADBDevEntry {
166 1.19.6.2 nathanw void (*ServiceRtPtr) __P((void));
167 1.19.6.2 nathanw void *DataAreaAddr;
168 1.19.6.2 nathanw int devType;
169 1.19.6.2 nathanw int origAddr;
170 1.19.6.2 nathanw int currentAddr;
171 1.19.6.2 nathanw };
172 1.19.6.2 nathanw
173 1.19.6.2 nathanw /*
174 1.19.6.2 nathanw * Used to hold ADB commands that are waiting to be sent out.
175 1.19.6.2 nathanw */
176 1.19.6.2 nathanw struct adbCmdHoldEntry {
177 1.19.6.2 nathanw u_char outBuf[ADB_MAX_MSG_LENGTH]; /* our message */
178 1.19.6.2 nathanw u_char *saveBuf; /* buffer to know where to save result */
179 1.19.6.2 nathanw u_char *compRout; /* completion routine pointer */
180 1.19.6.2 nathanw u_char *data; /* completion routine data pointer */
181 1.19.6.2 nathanw };
182 1.19.6.2 nathanw
183 1.19.6.2 nathanw /*
184 1.19.6.2 nathanw * Eventually used for two separate queues, the queue between
185 1.19.6.2 nathanw * the upper and lower halves, and the outgoing packet queue.
186 1.19.6.2 nathanw * TO DO: adbCommand can replace all of adbCmdHoldEntry eventually
187 1.19.6.2 nathanw */
188 1.19.6.2 nathanw struct adbCommand {
189 1.19.6.2 nathanw u_char header[ADB_MAX_HDR_LENGTH]; /* not used yet */
190 1.19.6.2 nathanw u_char data[ADB_MAX_MSG_LENGTH]; /* packet data only */
191 1.19.6.2 nathanw u_char *saveBuf; /* where to save result */
192 1.19.6.2 nathanw u_char *compRout; /* completion routine pointer */
193 1.19.6.2 nathanw u_char *compData; /* completion routine data pointer */
194 1.19.6.2 nathanw u_int cmd; /* the original command for this data */
195 1.19.6.2 nathanw u_int unsol; /* 1 if packet was unsolicited */
196 1.19.6.2 nathanw u_int ack_only; /* 1 for no special processing */
197 1.19.6.2 nathanw };
198 1.19.6.2 nathanw
199 1.19.6.2 nathanw /*
200 1.19.6.2 nathanw * A few variables that we need and their initial values.
201 1.19.6.2 nathanw */
202 1.19.6.2 nathanw int adbHardware = ADB_HW_UNKNOWN;
203 1.19.6.2 nathanw int adbActionState = ADB_ACTION_NOTREADY;
204 1.19.6.2 nathanw int adbBusState = ADB_BUS_UNKNOWN;
205 1.19.6.2 nathanw int adbWaiting = 0; /* waiting for return data from the device */
206 1.19.6.2 nathanw int adbWriteDelay = 0; /* working on (or waiting to do) a write */
207 1.19.6.2 nathanw int adbOutQueueHasData = 0; /* something in the queue waiting to go out */
208 1.19.6.2 nathanw int adbNextEnd = 0; /* the next incoming bute is the last (II) */
209 1.19.6.2 nathanw int adbSoftPower = 0; /* machine supports soft power */
210 1.19.6.2 nathanw
211 1.19.6.2 nathanw int adbWaitingCmd = 0; /* ADB command we are waiting for */
212 1.19.6.2 nathanw u_char *adbBuffer = (long)0; /* pointer to user data area */
213 1.19.6.2 nathanw void *adbCompRout = (long)0; /* pointer to the completion routine */
214 1.19.6.2 nathanw void *adbCompData = (long)0; /* pointer to the completion routine data */
215 1.19.6.2 nathanw long adbFakeInts = 0; /* keeps track of fake ADB interrupts for
216 1.19.6.2 nathanw * timeouts (II) */
217 1.19.6.2 nathanw int adbStarting = 1; /* doing ADBReInit so do polling differently */
218 1.19.6.2 nathanw int adbSendTalk = 0; /* the intr routine is sending the talk, not
219 1.19.6.2 nathanw * the user (II) */
220 1.19.6.2 nathanw int adbPolling = 0; /* we are polling for service request */
221 1.19.6.2 nathanw int adbPollCmd = 0; /* the last poll command we sent */
222 1.19.6.2 nathanw
223 1.19.6.2 nathanw u_char adbInputBuffer[ADB_MAX_MSG_LENGTH]; /* data input buffer */
224 1.19.6.2 nathanw u_char adbOutputBuffer[ADB_MAX_MSG_LENGTH]; /* data output buffer */
225 1.19.6.2 nathanw struct adbCmdHoldEntry adbOutQueue; /* our 1 entry output queue */
226 1.19.6.2 nathanw
227 1.19.6.2 nathanw int adbSentChars = 0; /* how many characters we have sent */
228 1.19.6.2 nathanw int adbLastDevice = 0; /* last ADB dev we heard from (II ONLY) */
229 1.19.6.2 nathanw int adbLastDevIndex = 0; /* last ADB dev loc in dev table (II ONLY) */
230 1.19.6.2 nathanw int adbLastCommand = 0; /* the last ADB command we sent (II) */
231 1.19.6.2 nathanw
232 1.19.6.2 nathanw struct ADBDevEntry ADBDevTable[16]; /* our ADB device table */
233 1.19.6.2 nathanw int ADBNumDevices; /* num. of ADB devices found with ADBReInit */
234 1.19.6.2 nathanw
235 1.19.6.2 nathanw struct adbCommand adbInbound[ADB_QUEUE]; /* incoming queue */
236 1.19.6.2 nathanw int adbInCount = 0; /* how many packets in in queue */
237 1.19.6.2 nathanw int adbInHead = 0; /* head of in queue */
238 1.19.6.2 nathanw int adbInTail = 0; /* tail of in queue */
239 1.19.6.2 nathanw struct adbCommand adbOutbound[ADB_QUEUE]; /* outgoing queue - not used yet */
240 1.19.6.2 nathanw int adbOutCount = 0; /* how many packets in out queue */
241 1.19.6.2 nathanw int adbOutHead = 0; /* head of out queue */
242 1.19.6.2 nathanw int adbOutTail = 0; /* tail of out queue */
243 1.19.6.2 nathanw
244 1.19.6.2 nathanw int tickle_count = 0; /* how many tickles seen for this packet? */
245 1.19.6.2 nathanw int tickle_serial = 0; /* the last packet tickled */
246 1.19.6.2 nathanw int adb_cuda_serial = 0; /* the current packet */
247 1.19.6.2 nathanw
248 1.19.6.2 nathanw struct callout adb_cuda_tickle_ch = CALLOUT_INITIALIZER;
249 1.19.6.2 nathanw struct callout adb_soft_intr_ch = CALLOUT_INITIALIZER;
250 1.19.6.2 nathanw
251 1.19.6.2 nathanw volatile u_char *Via1Base;
252 1.19.6.2 nathanw extern int adb_polling; /* Are we polling? */
253 1.19.6.2 nathanw
254 1.19.6.2 nathanw void pm_setup_adb __P((void));
255 1.19.6.2 nathanw void pm_check_adb_devices __P((int));
256 1.19.6.2 nathanw void pm_intr __P((void));
257 1.19.6.2 nathanw int pm_adb_op __P((u_char *, void *, void *, int));
258 1.19.6.2 nathanw void pm_init_adb_device __P((void));
259 1.19.6.2 nathanw
260 1.19.6.2 nathanw /*
261 1.19.6.2 nathanw * The following are private routines.
262 1.19.6.2 nathanw */
263 1.19.6.2 nathanw #ifdef ADB_DEBUG
264 1.19.6.2 nathanw void print_single __P((u_char *));
265 1.19.6.2 nathanw #endif
266 1.19.6.2 nathanw void adb_intr __P((void));
267 1.19.6.2 nathanw void adb_intr_II __P((void));
268 1.19.6.2 nathanw void adb_intr_IIsi __P((void));
269 1.19.6.2 nathanw void adb_intr_cuda __P((void));
270 1.19.6.2 nathanw void adb_soft_intr __P((void));
271 1.19.6.2 nathanw int send_adb_II __P((u_char *, u_char *, void *, void *, int));
272 1.19.6.2 nathanw int send_adb_IIsi __P((u_char *, u_char *, void *, void *, int));
273 1.19.6.2 nathanw int send_adb_cuda __P((u_char *, u_char *, void *, void *, int));
274 1.19.6.2 nathanw void adb_intr_cuda_test __P((void));
275 1.19.6.2 nathanw void adb_cuda_tickle __P((void));
276 1.19.6.2 nathanw void adb_pass_up __P((struct adbCommand *));
277 1.19.6.2 nathanw void adb_op_comprout __P((caddr_t, caddr_t, int));
278 1.19.6.2 nathanw void adb_reinit __P((void));
279 1.19.6.2 nathanw int count_adbs __P((void));
280 1.19.6.2 nathanw int get_ind_adb_info __P((ADBDataBlock *, int));
281 1.19.6.2 nathanw int get_adb_info __P((ADBDataBlock *, int));
282 1.19.6.2 nathanw int set_adb_info __P((ADBSetInfoBlock *, int));
283 1.19.6.2 nathanw void adb_setup_hw_type __P((void));
284 1.19.6.2 nathanw int adb_op __P((Ptr, Ptr, Ptr, short));
285 1.19.6.2 nathanw int adb_op_sync __P((Ptr, Ptr, Ptr, short));
286 1.19.6.2 nathanw void adb_read_II __P((u_char *));
287 1.19.6.2 nathanw void adb_hw_setup __P((void));
288 1.19.6.2 nathanw void adb_hw_setup_IIsi __P((u_char *));
289 1.19.6.2 nathanw int adb_cmd_result __P((u_char *));
290 1.19.6.2 nathanw int adb_cmd_extra __P((u_char *));
291 1.19.6.2 nathanw int adb_guess_next_device __P((void));
292 1.19.6.2 nathanw int adb_prog_switch_enable __P((void));
293 1.19.6.2 nathanw int adb_prog_switch_disable __P((void));
294 1.19.6.2 nathanw /* we should create this and it will be the public version */
295 1.19.6.2 nathanw int send_adb __P((u_char *, void *, void *));
296 1.19.6.2 nathanw
297 1.19.6.2 nathanw int setsoftadb __P((void));
298 1.19.6.2 nathanw
299 1.19.6.2 nathanw #ifdef ADB_DEBUG
300 1.19.6.2 nathanw /*
301 1.19.6.2 nathanw * print_single
302 1.19.6.2 nathanw * Diagnostic display routine. Displays the hex values of the
303 1.19.6.2 nathanw * specified elements of the u_char. The length of the "string"
304 1.19.6.2 nathanw * is in [0].
305 1.19.6.2 nathanw */
306 1.19.6.2 nathanw void
307 1.19.6.2 nathanw print_single(str)
308 1.19.6.2 nathanw u_char *str;
309 1.19.6.2 nathanw {
310 1.19.6.2 nathanw int x;
311 1.19.6.2 nathanw
312 1.19.6.2 nathanw if (str == 0) {
313 1.19.6.2 nathanw printf_intr("no data - null pointer\n");
314 1.19.6.2 nathanw return;
315 1.19.6.2 nathanw }
316 1.19.6.2 nathanw if (*str == 0) {
317 1.19.6.2 nathanw printf_intr("nothing returned\n");
318 1.19.6.2 nathanw return;
319 1.19.6.2 nathanw }
320 1.19.6.2 nathanw if (*str > 20) {
321 1.19.6.2 nathanw printf_intr("ADB: ACK > 20 no way!\n");
322 1.19.6.2 nathanw *str = 20;
323 1.19.6.2 nathanw }
324 1.19.6.2 nathanw printf_intr("(length=0x%x):", *str);
325 1.19.6.2 nathanw for (x = 1; x <= *str; x++)
326 1.19.6.2 nathanw printf_intr(" 0x%02x", str[x]);
327 1.19.6.2 nathanw printf_intr("\n");
328 1.19.6.2 nathanw }
329 1.19.6.2 nathanw #endif
330 1.19.6.2 nathanw
331 1.19.6.2 nathanw void
332 1.19.6.2 nathanw adb_cuda_tickle(void)
333 1.19.6.2 nathanw {
334 1.19.6.2 nathanw volatile int s;
335 1.19.6.2 nathanw
336 1.19.6.2 nathanw if (adbActionState == ADB_ACTION_IN) {
337 1.19.6.2 nathanw if (tickle_serial == adb_cuda_serial) {
338 1.19.6.2 nathanw if (++tickle_count > 0) {
339 1.19.6.2 nathanw s = splhigh();
340 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE;
341 1.19.6.2 nathanw adbInputBuffer[0] = 0;
342 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA();
343 1.19.6.2 nathanw splx(s);
344 1.19.6.2 nathanw }
345 1.19.6.2 nathanw } else {
346 1.19.6.2 nathanw tickle_serial = adb_cuda_serial;
347 1.19.6.2 nathanw tickle_count = 0;
348 1.19.6.2 nathanw }
349 1.19.6.2 nathanw } else {
350 1.19.6.2 nathanw tickle_serial = adb_cuda_serial;
351 1.19.6.2 nathanw tickle_count = 0;
352 1.19.6.2 nathanw }
353 1.19.6.2 nathanw
354 1.19.6.2 nathanw callout_reset(&adb_cuda_tickle_ch, ADB_TICKLE_TICKS,
355 1.19.6.2 nathanw (void *)adb_cuda_tickle, NULL);
356 1.19.6.2 nathanw }
357 1.19.6.2 nathanw
358 1.19.6.2 nathanw /*
359 1.19.6.2 nathanw * called when when an adb interrupt happens
360 1.19.6.2 nathanw *
361 1.19.6.2 nathanw * Cuda version of adb_intr
362 1.19.6.2 nathanw * TO DO: do we want to add some calls to intr_dispatch() here to
363 1.19.6.2 nathanw * grab serial interrupts?
364 1.19.6.2 nathanw */
365 1.19.6.2 nathanw void
366 1.19.6.2 nathanw adb_intr_cuda(void)
367 1.19.6.2 nathanw {
368 1.19.6.2 nathanw volatile int i, ending;
369 1.19.6.2 nathanw volatile unsigned int s;
370 1.19.6.2 nathanw struct adbCommand packet;
371 1.19.6.2 nathanw
372 1.19.6.2 nathanw s = splhigh(); /* can't be too careful - might be called */
373 1.19.6.2 nathanw /* from a routine, NOT an interrupt */
374 1.19.6.2 nathanw
375 1.19.6.2 nathanw ADB_VIA_CLR_INTR(); /* clear interrupt */
376 1.19.6.2 nathanw ADB_VIA_INTR_DISABLE(); /* disable ADB interrupt on IIs. */
377 1.19.6.2 nathanw
378 1.19.6.2 nathanw switch_start:
379 1.19.6.2 nathanw switch (adbActionState) {
380 1.19.6.2 nathanw case ADB_ACTION_IDLE:
381 1.19.6.2 nathanw /*
382 1.19.6.2 nathanw * This is an unexpected packet, so grab the first (dummy)
383 1.19.6.2 nathanw * byte, set up the proper vars, and tell the chip we are
384 1.19.6.2 nathanw * starting to receive the packet by setting the TIP bit.
385 1.19.6.2 nathanw */
386 1.19.6.2 nathanw adbInputBuffer[1] = ADB_SR();
387 1.19.6.2 nathanw adb_cuda_serial++;
388 1.19.6.2 nathanw if (ADB_INTR_IS_OFF) /* must have been a fake start */
389 1.19.6.2 nathanw break;
390 1.19.6.2 nathanw
391 1.19.6.2 nathanw ADB_SET_SR_INPUT();
392 1.19.6.2 nathanw ADB_SET_STATE_TIP();
393 1.19.6.2 nathanw
394 1.19.6.2 nathanw adbInputBuffer[0] = 1;
395 1.19.6.2 nathanw adbActionState = ADB_ACTION_IN;
396 1.19.6.2 nathanw #ifdef ADB_DEBUG
397 1.19.6.2 nathanw if (adb_debug)
398 1.19.6.2 nathanw printf_intr("idle 0x%02x ", adbInputBuffer[1]);
399 1.19.6.2 nathanw #endif
400 1.19.6.2 nathanw break;
401 1.19.6.2 nathanw
402 1.19.6.2 nathanw case ADB_ACTION_IN:
403 1.19.6.2 nathanw adbInputBuffer[++adbInputBuffer[0]] = ADB_SR();
404 1.19.6.2 nathanw /* intr off means this is the last byte (end of frame) */
405 1.19.6.2 nathanw if (ADB_INTR_IS_OFF)
406 1.19.6.2 nathanw ending = 1;
407 1.19.6.2 nathanw else
408 1.19.6.2 nathanw ending = 0;
409 1.19.6.2 nathanw
410 1.19.6.2 nathanw if (1 == ending) { /* end of message? */
411 1.19.6.2 nathanw #ifdef ADB_DEBUG
412 1.19.6.2 nathanw if (adb_debug) {
413 1.19.6.2 nathanw printf_intr("in end 0x%02x ",
414 1.19.6.2 nathanw adbInputBuffer[adbInputBuffer[0]]);
415 1.19.6.2 nathanw print_single(adbInputBuffer);
416 1.19.6.2 nathanw }
417 1.19.6.2 nathanw #endif
418 1.19.6.2 nathanw
419 1.19.6.2 nathanw /*
420 1.19.6.2 nathanw * Are we waiting AND does this packet match what we
421 1.19.6.2 nathanw * are waiting for AND is it coming from either the
422 1.19.6.2 nathanw * ADB or RTC/PRAM sub-device? This section _should_
423 1.19.6.2 nathanw * recognize all ADB and RTC/PRAM type commands, but
424 1.19.6.2 nathanw * there may be more... NOTE: commands are always at
425 1.19.6.2 nathanw * [4], even for RTC/PRAM commands.
426 1.19.6.2 nathanw */
427 1.19.6.2 nathanw /* set up data for adb_pass_up */
428 1.19.6.2 nathanw memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1);
429 1.19.6.2 nathanw
430 1.19.6.2 nathanw if ((adbWaiting == 1) &&
431 1.19.6.2 nathanw (adbInputBuffer[4] == adbWaitingCmd) &&
432 1.19.6.2 nathanw ((adbInputBuffer[2] == 0x00) ||
433 1.19.6.2 nathanw (adbInputBuffer[2] == 0x01))) {
434 1.19.6.2 nathanw packet.saveBuf = adbBuffer;
435 1.19.6.2 nathanw packet.compRout = adbCompRout;
436 1.19.6.2 nathanw packet.compData = adbCompData;
437 1.19.6.2 nathanw packet.unsol = 0;
438 1.19.6.2 nathanw packet.ack_only = 0;
439 1.19.6.2 nathanw adb_pass_up(&packet);
440 1.19.6.2 nathanw
441 1.19.6.2 nathanw adbWaitingCmd = 0; /* reset "waiting" vars */
442 1.19.6.2 nathanw adbWaiting = 0;
443 1.19.6.2 nathanw adbBuffer = (long)0;
444 1.19.6.2 nathanw adbCompRout = (long)0;
445 1.19.6.2 nathanw adbCompData = (long)0;
446 1.19.6.2 nathanw } else {
447 1.19.6.2 nathanw packet.unsol = 1;
448 1.19.6.2 nathanw packet.ack_only = 0;
449 1.19.6.2 nathanw adb_pass_up(&packet);
450 1.19.6.2 nathanw }
451 1.19.6.2 nathanw
452 1.19.6.2 nathanw
453 1.19.6.2 nathanw /* reset vars and signal the end of this frame */
454 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE;
455 1.19.6.2 nathanw adbInputBuffer[0] = 0;
456 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA();
457 1.19.6.2 nathanw /*ADB_SET_SR_INPUT();*/
458 1.19.6.2 nathanw
459 1.19.6.2 nathanw /*
460 1.19.6.2 nathanw * If there is something waiting to be sent out,
461 1.19.6.2 nathanw * the set everything up and send the first byte.
462 1.19.6.2 nathanw */
463 1.19.6.2 nathanw if (adbWriteDelay == 1) {
464 1.19.6.2 nathanw delay(ADB_DELAY); /* required */
465 1.19.6.2 nathanw adbSentChars = 0;
466 1.19.6.2 nathanw adbActionState = ADB_ACTION_OUT;
467 1.19.6.2 nathanw /*
468 1.19.6.2 nathanw * If the interrupt is on, we were too slow
469 1.19.6.2 nathanw * and the chip has already started to send
470 1.19.6.2 nathanw * something to us, so back out of the write
471 1.19.6.2 nathanw * and start a read cycle.
472 1.19.6.2 nathanw */
473 1.19.6.2 nathanw if (ADB_INTR_IS_ON) {
474 1.19.6.2 nathanw ADB_SET_SR_INPUT();
475 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA();
476 1.19.6.2 nathanw adbSentChars = 0;
477 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE;
478 1.19.6.2 nathanw adbInputBuffer[0] = 0;
479 1.19.6.2 nathanw break;
480 1.19.6.2 nathanw }
481 1.19.6.2 nathanw /*
482 1.19.6.2 nathanw * If we got here, it's ok to start sending
483 1.19.6.2 nathanw * so load the first byte and tell the chip
484 1.19.6.2 nathanw * we want to send.
485 1.19.6.2 nathanw */
486 1.19.6.2 nathanw ADB_SET_STATE_TIP();
487 1.19.6.2 nathanw ADB_SET_SR_OUTPUT();
488 1.19.6.2 nathanw write_via_reg(VIA1, vSR, adbOutputBuffer[adbSentChars + 1]);
489 1.19.6.2 nathanw }
490 1.19.6.2 nathanw } else {
491 1.19.6.2 nathanw ADB_TOGGLE_STATE_ACK_CUDA();
492 1.19.6.2 nathanw #ifdef ADB_DEBUG
493 1.19.6.2 nathanw if (adb_debug)
494 1.19.6.2 nathanw printf_intr("in 0x%02x ",
495 1.19.6.2 nathanw adbInputBuffer[adbInputBuffer[0]]);
496 1.19.6.2 nathanw #endif
497 1.19.6.2 nathanw }
498 1.19.6.2 nathanw break;
499 1.19.6.2 nathanw
500 1.19.6.2 nathanw case ADB_ACTION_OUT:
501 1.19.6.2 nathanw i = ADB_SR(); /* reset SR-intr in IFR */
502 1.19.6.2 nathanw #ifdef ADB_DEBUG
503 1.19.6.2 nathanw if (adb_debug)
504 1.19.6.2 nathanw printf_intr("intr out 0x%02x ", i);
505 1.19.6.2 nathanw #endif
506 1.19.6.2 nathanw
507 1.19.6.2 nathanw adbSentChars++;
508 1.19.6.2 nathanw if (ADB_INTR_IS_ON) { /* ADB intr low during write */
509 1.19.6.2 nathanw #ifdef ADB_DEBUG
510 1.19.6.2 nathanw if (adb_debug)
511 1.19.6.2 nathanw printf_intr("intr was on ");
512 1.19.6.2 nathanw #endif
513 1.19.6.2 nathanw ADB_SET_SR_INPUT(); /* make sure SR is set to IN */
514 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA();
515 1.19.6.2 nathanw adbSentChars = 0; /* must start all over */
516 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE; /* new state */
517 1.19.6.2 nathanw adbInputBuffer[0] = 0;
518 1.19.6.2 nathanw adbWriteDelay = 1; /* must retry when done with
519 1.19.6.2 nathanw * read */
520 1.19.6.2 nathanw delay(ADB_DELAY);
521 1.19.6.2 nathanw goto switch_start; /* process next state right
522 1.19.6.2 nathanw * now */
523 1.19.6.2 nathanw break;
524 1.19.6.2 nathanw }
525 1.19.6.2 nathanw if (adbOutputBuffer[0] == adbSentChars) { /* check for done */
526 1.19.6.2 nathanw if (0 == adb_cmd_result(adbOutputBuffer)) { /* do we expect data
527 1.19.6.2 nathanw * back? */
528 1.19.6.2 nathanw adbWaiting = 1; /* signal waiting for return */
529 1.19.6.2 nathanw adbWaitingCmd = adbOutputBuffer[2]; /* save waiting command */
530 1.19.6.2 nathanw } else { /* no talk, so done */
531 1.19.6.2 nathanw /* set up stuff for adb_pass_up */
532 1.19.6.2 nathanw memcpy(packet.data, adbInputBuffer, adbInputBuffer[0] + 1);
533 1.19.6.2 nathanw packet.saveBuf = adbBuffer;
534 1.19.6.2 nathanw packet.compRout = adbCompRout;
535 1.19.6.2 nathanw packet.compData = adbCompData;
536 1.19.6.2 nathanw packet.cmd = adbWaitingCmd;
537 1.19.6.2 nathanw packet.unsol = 0;
538 1.19.6.2 nathanw packet.ack_only = 1;
539 1.19.6.2 nathanw adb_pass_up(&packet);
540 1.19.6.2 nathanw
541 1.19.6.2 nathanw /* reset "waiting" vars, just in case */
542 1.19.6.2 nathanw adbWaitingCmd = 0;
543 1.19.6.2 nathanw adbBuffer = (long)0;
544 1.19.6.2 nathanw adbCompRout = (long)0;
545 1.19.6.2 nathanw adbCompData = (long)0;
546 1.19.6.2 nathanw }
547 1.19.6.2 nathanw
548 1.19.6.2 nathanw adbWriteDelay = 0; /* done writing */
549 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE; /* signal bus is idle */
550 1.19.6.2 nathanw ADB_SET_SR_INPUT();
551 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA();
552 1.19.6.2 nathanw #ifdef ADB_DEBUG
553 1.19.6.2 nathanw if (adb_debug)
554 1.19.6.2 nathanw printf_intr("write done ");
555 1.19.6.2 nathanw #endif
556 1.19.6.2 nathanw } else {
557 1.19.6.2 nathanw write_via_reg(VIA1, vSR, adbOutputBuffer[adbSentChars + 1]); /* send next byte */
558 1.19.6.2 nathanw ADB_TOGGLE_STATE_ACK_CUDA(); /* signal byte ready to
559 1.19.6.2 nathanw * shift */
560 1.19.6.2 nathanw #ifdef ADB_DEBUG
561 1.19.6.2 nathanw if (adb_debug)
562 1.19.6.2 nathanw printf_intr("toggle ");
563 1.19.6.2 nathanw #endif
564 1.19.6.2 nathanw }
565 1.19.6.2 nathanw break;
566 1.19.6.2 nathanw
567 1.19.6.2 nathanw case ADB_ACTION_NOTREADY:
568 1.19.6.2 nathanw #ifdef ADB_DEBUG
569 1.19.6.2 nathanw if (adb_debug)
570 1.19.6.2 nathanw printf_intr("adb: not yet initialized\n");
571 1.19.6.2 nathanw #endif
572 1.19.6.2 nathanw break;
573 1.19.6.2 nathanw
574 1.19.6.2 nathanw default:
575 1.19.6.2 nathanw #ifdef ADB_DEBUG
576 1.19.6.2 nathanw if (adb_debug)
577 1.19.6.2 nathanw printf_intr("intr: unknown ADB state\n");
578 1.19.6.2 nathanw #endif
579 1.19.6.2 nathanw break;
580 1.19.6.2 nathanw }
581 1.19.6.2 nathanw
582 1.19.6.2 nathanw ADB_VIA_INTR_ENABLE(); /* enable ADB interrupt on IIs. */
583 1.19.6.2 nathanw
584 1.19.6.2 nathanw splx(s); /* restore */
585 1.19.6.2 nathanw
586 1.19.6.2 nathanw return;
587 1.19.6.2 nathanw } /* end adb_intr_cuda */
588 1.19.6.2 nathanw
589 1.19.6.2 nathanw
590 1.19.6.2 nathanw int
591 1.19.6.2 nathanw send_adb_cuda(u_char * in, u_char * buffer, void *compRout, void *data, int
592 1.19.6.2 nathanw command)
593 1.19.6.2 nathanw {
594 1.19.6.2 nathanw int s, len;
595 1.19.6.2 nathanw
596 1.19.6.2 nathanw #ifdef ADB_DEBUG
597 1.19.6.2 nathanw if (adb_debug)
598 1.19.6.2 nathanw printf_intr("SEND\n");
599 1.19.6.2 nathanw #endif
600 1.19.6.2 nathanw
601 1.19.6.2 nathanw if (adbActionState == ADB_ACTION_NOTREADY)
602 1.19.6.2 nathanw return 1;
603 1.19.6.2 nathanw
604 1.19.6.2 nathanw /* Don't interrupt while we are messing with the ADB */
605 1.19.6.2 nathanw s = splhigh();
606 1.19.6.2 nathanw
607 1.19.6.2 nathanw if ((adbActionState == ADB_ACTION_IDLE) && /* ADB available? */
608 1.19.6.2 nathanw (ADB_INTR_IS_OFF)) { /* and no incoming interrupt? */
609 1.19.6.2 nathanw } else
610 1.19.6.2 nathanw if (adbWriteDelay == 0) /* it's busy, but is anything waiting? */
611 1.19.6.2 nathanw adbWriteDelay = 1; /* if no, then we'll "queue"
612 1.19.6.2 nathanw * it up */
613 1.19.6.2 nathanw else {
614 1.19.6.2 nathanw splx(s);
615 1.19.6.2 nathanw return 1; /* really busy! */
616 1.19.6.2 nathanw }
617 1.19.6.2 nathanw
618 1.19.6.2 nathanw #ifdef ADB_DEBUG
619 1.19.6.2 nathanw if (adb_debug)
620 1.19.6.2 nathanw printf_intr("QUEUE\n");
621 1.19.6.2 nathanw #endif
622 1.19.6.2 nathanw if ((long)in == (long)0) { /* need to convert? */
623 1.19.6.2 nathanw /*
624 1.19.6.2 nathanw * Don't need to use adb_cmd_extra here because this section
625 1.19.6.2 nathanw * will be called ONLY when it is an ADB command (no RTC or
626 1.19.6.2 nathanw * PRAM)
627 1.19.6.2 nathanw */
628 1.19.6.2 nathanw if ((command & 0x0c) == 0x08) /* copy addl data ONLY if
629 1.19.6.2 nathanw * doing a listen! */
630 1.19.6.2 nathanw len = buffer[0]; /* length of additional data */
631 1.19.6.2 nathanw else
632 1.19.6.2 nathanw len = 0;/* no additional data */
633 1.19.6.2 nathanw
634 1.19.6.2 nathanw adbOutputBuffer[0] = 2 + len; /* dev. type + command + addl.
635 1.19.6.2 nathanw * data */
636 1.19.6.2 nathanw adbOutputBuffer[1] = 0x00; /* mark as an ADB command */
637 1.19.6.2 nathanw adbOutputBuffer[2] = (u_char)command; /* load command */
638 1.19.6.2 nathanw
639 1.19.6.2 nathanw /* copy additional output data, if any */
640 1.19.6.2 nathanw memcpy(adbOutputBuffer + 3, buffer + 1, len);
641 1.19.6.2 nathanw } else
642 1.19.6.2 nathanw /* if data ready, just copy over */
643 1.19.6.2 nathanw memcpy(adbOutputBuffer, in, in[0] + 2);
644 1.19.6.2 nathanw
645 1.19.6.2 nathanw adbSentChars = 0; /* nothing sent yet */
646 1.19.6.2 nathanw adbBuffer = buffer; /* save buffer to know where to save result */
647 1.19.6.2 nathanw adbCompRout = compRout; /* save completion routine pointer */
648 1.19.6.2 nathanw adbCompData = data; /* save completion routine data pointer */
649 1.19.6.2 nathanw adbWaitingCmd = adbOutputBuffer[2]; /* save wait command */
650 1.19.6.2 nathanw
651 1.19.6.2 nathanw if (adbWriteDelay != 1) { /* start command now? */
652 1.19.6.2 nathanw #ifdef ADB_DEBUG
653 1.19.6.2 nathanw if (adb_debug)
654 1.19.6.2 nathanw printf_intr("out start NOW");
655 1.19.6.2 nathanw #endif
656 1.19.6.2 nathanw delay(ADB_DELAY);
657 1.19.6.2 nathanw adbActionState = ADB_ACTION_OUT; /* set next state */
658 1.19.6.2 nathanw ADB_SET_SR_OUTPUT(); /* set shift register for OUT */
659 1.19.6.2 nathanw write_via_reg(VIA1, vSR, adbOutputBuffer[adbSentChars + 1]); /* load byte for output */
660 1.19.6.2 nathanw ADB_SET_STATE_ACKOFF_CUDA();
661 1.19.6.2 nathanw ADB_SET_STATE_TIP(); /* tell ADB that we want to send */
662 1.19.6.2 nathanw }
663 1.19.6.2 nathanw adbWriteDelay = 1; /* something in the write "queue" */
664 1.19.6.2 nathanw
665 1.19.6.2 nathanw splx(s);
666 1.19.6.2 nathanw
667 1.19.6.2 nathanw if ((s & (1 << 18)) || adb_polling) /* XXX were VIA1 interrupts blocked ? */
668 1.19.6.2 nathanw /* poll until byte done */
669 1.19.6.2 nathanw while ((adbActionState != ADB_ACTION_IDLE) || (ADB_INTR_IS_ON)
670 1.19.6.2 nathanw || (adbWaiting == 1))
671 1.19.6.2 nathanw if (ADB_SR_INTR_IS_ON) { /* wait for "interrupt" */
672 1.19.6.2 nathanw adb_intr_cuda(); /* process it */
673 1.19.6.2 nathanw adb_soft_intr();
674 1.19.6.2 nathanw }
675 1.19.6.2 nathanw
676 1.19.6.2 nathanw return 0;
677 1.19.6.2 nathanw } /* send_adb_cuda */
678 1.19.6.2 nathanw
679 1.19.6.2 nathanw
680 1.19.6.2 nathanw void
681 1.19.6.2 nathanw adb_intr_II(void)
682 1.19.6.2 nathanw {
683 1.19.6.2 nathanw panic("adb_intr_II");
684 1.19.6.2 nathanw }
685 1.19.6.2 nathanw
686 1.19.6.2 nathanw
687 1.19.6.2 nathanw /*
688 1.19.6.2 nathanw * send_adb version for II series machines
689 1.19.6.2 nathanw */
690 1.19.6.2 nathanw int
691 1.19.6.2 nathanw send_adb_II(u_char * in, u_char * buffer, void *compRout, void *data, int command)
692 1.19.6.2 nathanw {
693 1.19.6.2 nathanw panic("send_adb_II");
694 1.19.6.2 nathanw }
695 1.19.6.2 nathanw
696 1.19.6.2 nathanw
697 1.19.6.2 nathanw /*
698 1.19.6.2 nathanw * This routine is called from the II series interrupt routine
699 1.19.6.2 nathanw * to determine what the "next" device is that should be polled.
700 1.19.6.2 nathanw */
701 1.19.6.2 nathanw int
702 1.19.6.2 nathanw adb_guess_next_device(void)
703 1.19.6.2 nathanw {
704 1.19.6.2 nathanw int last, i, dummy;
705 1.19.6.2 nathanw
706 1.19.6.2 nathanw if (adbStarting) {
707 1.19.6.2 nathanw /*
708 1.19.6.2 nathanw * Start polling EVERY device, since we can't be sure there is
709 1.19.6.2 nathanw * anything in the device table yet
710 1.19.6.2 nathanw */
711 1.19.6.2 nathanw if (adbLastDevice < 1 || adbLastDevice > 15)
712 1.19.6.2 nathanw adbLastDevice = 1;
713 1.19.6.2 nathanw if (++adbLastDevice > 15) /* point to next one */
714 1.19.6.2 nathanw adbLastDevice = 1;
715 1.19.6.2 nathanw } else {
716 1.19.6.2 nathanw /* find the next device using the device table */
717 1.19.6.2 nathanw if (adbLastDevice < 1 || adbLastDevice > 15) /* let's be parinoid */
718 1.19.6.2 nathanw adbLastDevice = 2;
719 1.19.6.2 nathanw last = 1; /* default index location */
720 1.19.6.2 nathanw
721 1.19.6.2 nathanw for (i = 1; i < 16; i++) /* find index entry */
722 1.19.6.2 nathanw if (ADBDevTable[i].currentAddr == adbLastDevice) { /* look for device */
723 1.19.6.2 nathanw last = i; /* found it */
724 1.19.6.2 nathanw break;
725 1.19.6.2 nathanw }
726 1.19.6.2 nathanw dummy = last; /* index to start at */
727 1.19.6.2 nathanw for (;;) { /* find next device in index */
728 1.19.6.2 nathanw if (++dummy > 15) /* wrap around if needed */
729 1.19.6.2 nathanw dummy = 1;
730 1.19.6.2 nathanw if (dummy == last) { /* didn't find any other
731 1.19.6.2 nathanw * device! This can happen if
732 1.19.6.2 nathanw * there are no devices on the
733 1.19.6.2 nathanw * bus */
734 1.19.6.2 nathanw dummy = 1;
735 1.19.6.2 nathanw break;
736 1.19.6.2 nathanw }
737 1.19.6.2 nathanw /* found the next device */
738 1.19.6.2 nathanw if (ADBDevTable[dummy].devType != 0)
739 1.19.6.2 nathanw break;
740 1.19.6.2 nathanw }
741 1.19.6.2 nathanw adbLastDevice = ADBDevTable[dummy].currentAddr;
742 1.19.6.2 nathanw }
743 1.19.6.2 nathanw return adbLastDevice;
744 1.19.6.2 nathanw }
745 1.19.6.2 nathanw
746 1.19.6.2 nathanw
747 1.19.6.2 nathanw /*
748 1.19.6.2 nathanw * Called when when an adb interrupt happens.
749 1.19.6.2 nathanw * This routine simply transfers control over to the appropriate
750 1.19.6.2 nathanw * code for the machine we are running on.
751 1.19.6.2 nathanw */
752 1.19.6.2 nathanw void
753 1.19.6.2 nathanw adb_intr(void)
754 1.19.6.2 nathanw {
755 1.19.6.2 nathanw switch (adbHardware) {
756 1.19.6.2 nathanw case ADB_HW_II:
757 1.19.6.2 nathanw adb_intr_II();
758 1.19.6.2 nathanw break;
759 1.19.6.2 nathanw
760 1.19.6.2 nathanw case ADB_HW_IISI:
761 1.19.6.2 nathanw adb_intr_IIsi();
762 1.19.6.2 nathanw break;
763 1.19.6.2 nathanw
764 1.19.6.2 nathanw case ADB_HW_PB:
765 1.19.6.2 nathanw pm_intr();
766 1.19.6.2 nathanw break;
767 1.19.6.2 nathanw
768 1.19.6.2 nathanw case ADB_HW_CUDA:
769 1.19.6.2 nathanw adb_intr_cuda();
770 1.19.6.2 nathanw break;
771 1.19.6.2 nathanw
772 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
773 1.19.6.2 nathanw break;
774 1.19.6.2 nathanw }
775 1.19.6.2 nathanw }
776 1.19.6.2 nathanw
777 1.19.6.2 nathanw
778 1.19.6.2 nathanw /*
779 1.19.6.2 nathanw * called when when an adb interrupt happens
780 1.19.6.2 nathanw *
781 1.19.6.2 nathanw * IIsi version of adb_intr
782 1.19.6.2 nathanw *
783 1.19.6.2 nathanw */
784 1.19.6.2 nathanw void
785 1.19.6.2 nathanw adb_intr_IIsi(void)
786 1.19.6.2 nathanw {
787 1.19.6.2 nathanw panic("adb_intr_IIsi");
788 1.19.6.2 nathanw }
789 1.19.6.2 nathanw
790 1.19.6.2 nathanw
791 1.19.6.2 nathanw /*****************************************************************************
792 1.19.6.2 nathanw * if the device is currently busy, and there is no data waiting to go out, then
793 1.19.6.2 nathanw * the data is "queued" in the outgoing buffer. If we are already waiting, then
794 1.19.6.2 nathanw * we return.
795 1.19.6.2 nathanw * in: if (in == 0) then the command string is built from command and buffer
796 1.19.6.2 nathanw * if (in != 0) then in is used as the command string
797 1.19.6.2 nathanw * buffer: additional data to be sent (used only if in == 0)
798 1.19.6.2 nathanw * this is also where return data is stored
799 1.19.6.2 nathanw * compRout: the completion routine that is called when then return value
800 1.19.6.2 nathanw * is received (if a return value is expected)
801 1.19.6.2 nathanw * data: a data pointer that can be used by the completion routine
802 1.19.6.2 nathanw * command: an ADB command to be sent (used only if in == 0)
803 1.19.6.2 nathanw *
804 1.19.6.2 nathanw */
805 1.19.6.2 nathanw int
806 1.19.6.2 nathanw send_adb_IIsi(u_char * in, u_char * buffer, void *compRout, void *data, int
807 1.19.6.2 nathanw command)
808 1.19.6.2 nathanw {
809 1.19.6.2 nathanw panic("send_adb_IIsi");
810 1.19.6.2 nathanw }
811 1.19.6.2 nathanw
812 1.19.6.2 nathanw
813 1.19.6.2 nathanw /*
814 1.19.6.2 nathanw * adb_pass_up is called by the interrupt-time routines.
815 1.19.6.2 nathanw * It takes the raw packet data that was received from the
816 1.19.6.2 nathanw * device and puts it into the queue that the upper half
817 1.19.6.2 nathanw * processes. It then signals for a soft ADB interrupt which
818 1.19.6.2 nathanw * will eventually call the upper half routine (adb_soft_intr).
819 1.19.6.2 nathanw *
820 1.19.6.2 nathanw * If in->unsol is 0, then this is either the notification
821 1.19.6.2 nathanw * that the packet was sent (on a LISTEN, for example), or the
822 1.19.6.2 nathanw * response from the device (on a TALK). The completion routine
823 1.19.6.2 nathanw * is called only if the user specified one.
824 1.19.6.2 nathanw *
825 1.19.6.2 nathanw * If in->unsol is 1, then this packet was unsolicited and
826 1.19.6.2 nathanw * so we look up the device in the ADB device table to determine
827 1.19.6.2 nathanw * what it's default service routine is.
828 1.19.6.2 nathanw *
829 1.19.6.2 nathanw * If in->ack_only is 1, then we really only need to call
830 1.19.6.2 nathanw * the completion routine, so don't do any other stuff.
831 1.19.6.2 nathanw *
832 1.19.6.2 nathanw * Note that in->data contains the packet header AND data,
833 1.19.6.2 nathanw * while adbInbound[]->data contains ONLY data.
834 1.19.6.2 nathanw *
835 1.19.6.2 nathanw * Note: Called only at interrupt time. Assumes this.
836 1.19.6.2 nathanw */
837 1.19.6.2 nathanw void
838 1.19.6.2 nathanw adb_pass_up(struct adbCommand *in)
839 1.19.6.2 nathanw {
840 1.19.6.2 nathanw int start = 0, len = 0, cmd = 0;
841 1.19.6.2 nathanw ADBDataBlock block;
842 1.19.6.2 nathanw
843 1.19.6.2 nathanw /* temp for testing */
844 1.19.6.2 nathanw /*u_char *buffer = 0;*/
845 1.19.6.2 nathanw /*u_char *compdata = 0;*/
846 1.19.6.2 nathanw /*u_char *comprout = 0;*/
847 1.19.6.2 nathanw
848 1.19.6.2 nathanw if (adbInCount >= ADB_QUEUE) {
849 1.19.6.2 nathanw #ifdef ADB_DEBUG
850 1.19.6.2 nathanw if (adb_debug)
851 1.19.6.2 nathanw printf_intr("adb: ring buffer overflow\n");
852 1.19.6.2 nathanw #endif
853 1.19.6.2 nathanw return;
854 1.19.6.2 nathanw }
855 1.19.6.2 nathanw
856 1.19.6.2 nathanw if (in->ack_only) {
857 1.19.6.2 nathanw len = in->data[0];
858 1.19.6.2 nathanw cmd = in->cmd;
859 1.19.6.2 nathanw start = 0;
860 1.19.6.2 nathanw } else {
861 1.19.6.2 nathanw switch (adbHardware) {
862 1.19.6.2 nathanw case ADB_HW_II:
863 1.19.6.2 nathanw cmd = in->data[1];
864 1.19.6.2 nathanw if (in->data[0] < 2)
865 1.19.6.2 nathanw len = 0;
866 1.19.6.2 nathanw else
867 1.19.6.2 nathanw len = in->data[0]-1;
868 1.19.6.2 nathanw start = 1;
869 1.19.6.2 nathanw break;
870 1.19.6.2 nathanw
871 1.19.6.2 nathanw case ADB_HW_IISI:
872 1.19.6.2 nathanw case ADB_HW_CUDA:
873 1.19.6.2 nathanw /* If it's unsolicited, accept only ADB data for now */
874 1.19.6.2 nathanw if (in->unsol)
875 1.19.6.2 nathanw if (0 != in->data[2])
876 1.19.6.2 nathanw return;
877 1.19.6.2 nathanw cmd = in->data[4];
878 1.19.6.2 nathanw if (in->data[0] < 5)
879 1.19.6.2 nathanw len = 0;
880 1.19.6.2 nathanw else
881 1.19.6.2 nathanw len = in->data[0]-4;
882 1.19.6.2 nathanw start = 4;
883 1.19.6.2 nathanw break;
884 1.19.6.2 nathanw
885 1.19.6.2 nathanw case ADB_HW_PB:
886 1.19.6.2 nathanw cmd = in->data[1];
887 1.19.6.2 nathanw if (in->data[0] < 2)
888 1.19.6.2 nathanw len = 0;
889 1.19.6.2 nathanw else
890 1.19.6.2 nathanw len = in->data[0]-1;
891 1.19.6.2 nathanw start = 1;
892 1.19.6.2 nathanw break;
893 1.19.6.2 nathanw
894 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
895 1.19.6.2 nathanw return;
896 1.19.6.2 nathanw }
897 1.19.6.2 nathanw
898 1.19.6.2 nathanw /* Make sure there is a valid device entry for this device */
899 1.19.6.2 nathanw if (in->unsol) {
900 1.19.6.2 nathanw /* ignore unsolicited data during adbreinit */
901 1.19.6.2 nathanw if (adbStarting)
902 1.19.6.2 nathanw return;
903 1.19.6.2 nathanw /* get device's comp. routine and data area */
904 1.19.6.2 nathanw if (-1 == get_adb_info(&block, ADB_CMDADDR(cmd)))
905 1.19.6.2 nathanw return;
906 1.19.6.2 nathanw }
907 1.19.6.2 nathanw }
908 1.19.6.2 nathanw
909 1.19.6.2 nathanw /*
910 1.19.6.2 nathanw * If this is an unsolicited packet, we need to fill in
911 1.19.6.2 nathanw * some info so adb_soft_intr can process this packet
912 1.19.6.2 nathanw * properly. If it's not unsolicited, then use what
913 1.19.6.2 nathanw * the caller sent us.
914 1.19.6.2 nathanw */
915 1.19.6.2 nathanw if (in->unsol) {
916 1.19.6.2 nathanw adbInbound[adbInTail].compRout = (void *)block.dbServiceRtPtr;
917 1.19.6.2 nathanw adbInbound[adbInTail].compData = (void *)block.dbDataAreaAddr;
918 1.19.6.2 nathanw adbInbound[adbInTail].saveBuf = (void *)adbInbound[adbInTail].data;
919 1.19.6.2 nathanw } else {
920 1.19.6.2 nathanw adbInbound[adbInTail].compRout = (void *)in->compRout;
921 1.19.6.2 nathanw adbInbound[adbInTail].compData = (void *)in->compData;
922 1.19.6.2 nathanw adbInbound[adbInTail].saveBuf = (void *)in->saveBuf;
923 1.19.6.2 nathanw }
924 1.19.6.2 nathanw
925 1.19.6.2 nathanw #ifdef ADB_DEBUG
926 1.19.6.2 nathanw if (adb_debug && in->data[1] == 2)
927 1.19.6.2 nathanw printf_intr("adb: caught error\n");
928 1.19.6.2 nathanw #endif
929 1.19.6.2 nathanw
930 1.19.6.2 nathanw /* copy the packet data over */
931 1.19.6.2 nathanw /*
932 1.19.6.2 nathanw * TO DO: If the *_intr routines fed their incoming data
933 1.19.6.2 nathanw * directly into an adbCommand struct, which is passed to
934 1.19.6.2 nathanw * this routine, then we could eliminate this copy.
935 1.19.6.2 nathanw */
936 1.19.6.2 nathanw memcpy(adbInbound[adbInTail].data + 1, in->data + start + 1, len);
937 1.19.6.2 nathanw adbInbound[adbInTail].data[0] = len;
938 1.19.6.2 nathanw adbInbound[adbInTail].cmd = cmd;
939 1.19.6.2 nathanw
940 1.19.6.2 nathanw adbInCount++;
941 1.19.6.2 nathanw if (++adbInTail >= ADB_QUEUE)
942 1.19.6.2 nathanw adbInTail = 0;
943 1.19.6.2 nathanw
944 1.19.6.2 nathanw /*
945 1.19.6.2 nathanw * If the debugger is running, call upper half manually.
946 1.19.6.2 nathanw * Otherwise, trigger a soft interrupt to handle the rest later.
947 1.19.6.2 nathanw */
948 1.19.6.2 nathanw if (adb_polling)
949 1.19.6.2 nathanw adb_soft_intr();
950 1.19.6.2 nathanw else
951 1.19.6.2 nathanw setsoftadb();
952 1.19.6.2 nathanw
953 1.19.6.2 nathanw return;
954 1.19.6.2 nathanw }
955 1.19.6.2 nathanw
956 1.19.6.2 nathanw
957 1.19.6.2 nathanw /*
958 1.19.6.2 nathanw * Called to process the packets after they have been
959 1.19.6.2 nathanw * placed in the incoming queue.
960 1.19.6.2 nathanw *
961 1.19.6.2 nathanw */
962 1.19.6.2 nathanw void
963 1.19.6.2 nathanw adb_soft_intr(void)
964 1.19.6.2 nathanw {
965 1.19.6.2 nathanw int s;
966 1.19.6.2 nathanw int cmd = 0;
967 1.19.6.2 nathanw u_char *buffer = 0;
968 1.19.6.2 nathanw u_char *comprout = 0;
969 1.19.6.2 nathanw u_char *compdata = 0;
970 1.19.6.2 nathanw
971 1.19.6.2 nathanw #if 0
972 1.19.6.2 nathanw s = splhigh();
973 1.19.6.2 nathanw printf_intr("sr: %x\n", (s & 0x0700));
974 1.19.6.2 nathanw splx(s);
975 1.19.6.2 nathanw #endif
976 1.19.6.2 nathanw
977 1.19.6.2 nathanw /*delay(2*ADB_DELAY);*/
978 1.19.6.2 nathanw
979 1.19.6.2 nathanw while (adbInCount) {
980 1.19.6.2 nathanw #ifdef ADB_DEBUG
981 1.19.6.2 nathanw if (adb_debug & 0x80)
982 1.19.6.2 nathanw printf_intr("%x %x %x ",
983 1.19.6.2 nathanw adbInCount, adbInHead, adbInTail);
984 1.19.6.2 nathanw #endif
985 1.19.6.2 nathanw /* get the data we need from the queue */
986 1.19.6.2 nathanw buffer = adbInbound[adbInHead].saveBuf;
987 1.19.6.2 nathanw comprout = adbInbound[adbInHead].compRout;
988 1.19.6.2 nathanw compdata = adbInbound[adbInHead].compData;
989 1.19.6.2 nathanw cmd = adbInbound[adbInHead].cmd;
990 1.19.6.2 nathanw
991 1.19.6.2 nathanw /* copy over data to data area if it's valid */
992 1.19.6.2 nathanw /*
993 1.19.6.2 nathanw * Note that for unsol packets we don't want to copy the
994 1.19.6.2 nathanw * data anywhere, so buffer was already set to 0.
995 1.19.6.2 nathanw * For ack_only buffer was set to 0, so don't copy.
996 1.19.6.2 nathanw */
997 1.19.6.2 nathanw if (buffer)
998 1.19.6.2 nathanw memcpy(buffer, adbInbound[adbInHead].data,
999 1.19.6.2 nathanw adbInbound[adbInHead].data[0] + 1);
1000 1.19.6.2 nathanw
1001 1.19.6.2 nathanw #ifdef ADB_DEBUG
1002 1.19.6.2 nathanw if (adb_debug & 0x80) {
1003 1.19.6.2 nathanw printf_intr("%p %p %p %x ",
1004 1.19.6.2 nathanw buffer, comprout, compdata, (short)cmd);
1005 1.19.6.2 nathanw printf_intr("buf: ");
1006 1.19.6.2 nathanw print_single(adbInbound[adbInHead].data);
1007 1.19.6.2 nathanw }
1008 1.19.6.2 nathanw #endif
1009 1.19.6.2 nathanw
1010 1.19.6.2 nathanw /* call default completion routine if it's valid */
1011 1.19.6.2 nathanw if (comprout) {
1012 1.19.6.2 nathanw void (*f)(caddr_t, caddr_t, int) =
1013 1.19.6.2 nathanw (void (*)(caddr_t, caddr_t, int))comprout;
1014 1.19.6.2 nathanw
1015 1.19.6.2 nathanw (*f)(buffer, compdata, cmd);
1016 1.19.6.2 nathanw }
1017 1.19.6.2 nathanw
1018 1.19.6.2 nathanw s = splhigh();
1019 1.19.6.2 nathanw adbInCount--;
1020 1.19.6.2 nathanw if (++adbInHead >= ADB_QUEUE)
1021 1.19.6.2 nathanw adbInHead = 0;
1022 1.19.6.2 nathanw splx(s);
1023 1.19.6.2 nathanw
1024 1.19.6.2 nathanw }
1025 1.19.6.2 nathanw return;
1026 1.19.6.2 nathanw }
1027 1.19.6.2 nathanw
1028 1.19.6.2 nathanw
1029 1.19.6.2 nathanw /*
1030 1.19.6.2 nathanw * This is my version of the ADBOp routine. It mainly just calls the
1031 1.19.6.2 nathanw * hardware-specific routine.
1032 1.19.6.2 nathanw *
1033 1.19.6.2 nathanw * data : pointer to data area to be used by compRout
1034 1.19.6.2 nathanw * compRout : completion routine
1035 1.19.6.2 nathanw * buffer : for LISTEN: points to data to send - MAX 8 data bytes,
1036 1.19.6.2 nathanw * byte 0 = # of bytes
1037 1.19.6.2 nathanw * : for TALK: points to place to save return data
1038 1.19.6.2 nathanw * command : the adb command to send
1039 1.19.6.2 nathanw * result : 0 = success
1040 1.19.6.2 nathanw * : -1 = could not complete
1041 1.19.6.2 nathanw */
1042 1.19.6.2 nathanw int
1043 1.19.6.2 nathanw adb_op(Ptr buffer, Ptr compRout, Ptr data, short command)
1044 1.19.6.2 nathanw {
1045 1.19.6.2 nathanw int result;
1046 1.19.6.2 nathanw
1047 1.19.6.2 nathanw switch (adbHardware) {
1048 1.19.6.2 nathanw case ADB_HW_II:
1049 1.19.6.2 nathanw result = send_adb_II((u_char *)0, (u_char *)buffer,
1050 1.19.6.2 nathanw (void *)compRout, (void *)data, (int)command);
1051 1.19.6.2 nathanw if (result == 0)
1052 1.19.6.2 nathanw return 0;
1053 1.19.6.2 nathanw else
1054 1.19.6.2 nathanw return -1;
1055 1.19.6.2 nathanw break;
1056 1.19.6.2 nathanw
1057 1.19.6.2 nathanw case ADB_HW_IISI:
1058 1.19.6.2 nathanw result = send_adb_IIsi((u_char *)0, (u_char *)buffer,
1059 1.19.6.2 nathanw (void *)compRout, (void *)data, (int)command);
1060 1.19.6.2 nathanw /*
1061 1.19.6.2 nathanw * I wish I knew why this delay is needed. It usually needs to
1062 1.19.6.2 nathanw * be here when several commands are sent in close succession,
1063 1.19.6.2 nathanw * especially early in device probes when doing collision
1064 1.19.6.2 nathanw * detection. It must be some race condition. Sigh. - jpw
1065 1.19.6.2 nathanw */
1066 1.19.6.2 nathanw delay(100);
1067 1.19.6.2 nathanw if (result == 0)
1068 1.19.6.2 nathanw return 0;
1069 1.19.6.2 nathanw else
1070 1.19.6.2 nathanw return -1;
1071 1.19.6.2 nathanw break;
1072 1.19.6.2 nathanw
1073 1.19.6.2 nathanw case ADB_HW_PB:
1074 1.19.6.2 nathanw result = pm_adb_op((u_char *)buffer, (void *)compRout,
1075 1.19.6.2 nathanw (void *)data, (int)command);
1076 1.19.6.2 nathanw
1077 1.19.6.2 nathanw if (result == 0)
1078 1.19.6.2 nathanw return 0;
1079 1.19.6.2 nathanw else
1080 1.19.6.2 nathanw return -1;
1081 1.19.6.2 nathanw break;
1082 1.19.6.2 nathanw
1083 1.19.6.2 nathanw case ADB_HW_CUDA:
1084 1.19.6.2 nathanw result = send_adb_cuda((u_char *)0, (u_char *)buffer,
1085 1.19.6.2 nathanw (void *)compRout, (void *)data, (int)command);
1086 1.19.6.2 nathanw if (result == 0)
1087 1.19.6.2 nathanw return 0;
1088 1.19.6.2 nathanw else
1089 1.19.6.2 nathanw return -1;
1090 1.19.6.2 nathanw break;
1091 1.19.6.2 nathanw
1092 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1093 1.19.6.2 nathanw default:
1094 1.19.6.2 nathanw return -1;
1095 1.19.6.2 nathanw }
1096 1.19.6.2 nathanw }
1097 1.19.6.2 nathanw
1098 1.19.6.2 nathanw
1099 1.19.6.2 nathanw /*
1100 1.19.6.2 nathanw * adb_hw_setup
1101 1.19.6.2 nathanw * This routine sets up the possible machine specific hardware
1102 1.19.6.2 nathanw * config (mainly VIA settings) for the various models.
1103 1.19.6.2 nathanw */
1104 1.19.6.2 nathanw void
1105 1.19.6.2 nathanw adb_hw_setup(void)
1106 1.19.6.2 nathanw {
1107 1.19.6.2 nathanw volatile int i;
1108 1.19.6.2 nathanw u_char send_string[ADB_MAX_MSG_LENGTH];
1109 1.19.6.2 nathanw
1110 1.19.6.2 nathanw switch (adbHardware) {
1111 1.19.6.2 nathanw case ADB_HW_II:
1112 1.19.6.2 nathanw via_reg_or(VIA1, vDirB, 0x30); /* register B bits 4 and 5:
1113 1.19.6.2 nathanw * outputs */
1114 1.19.6.2 nathanw via_reg_and(VIA1, vDirB, 0xf7); /* register B bit 3: input */
1115 1.19.6.2 nathanw via_reg_and(VIA1, vACR, ~vSR_OUT); /* make sure SR is set
1116 1.19.6.2 nathanw * to IN (II, IIsi) */
1117 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE; /* used by all types of
1118 1.19.6.2 nathanw * hardware (II, IIsi) */
1119 1.19.6.2 nathanw adbBusState = ADB_BUS_IDLE; /* this var. used in II-series
1120 1.19.6.2 nathanw * code only */
1121 1.19.6.2 nathanw write_via_reg(VIA1, vIER, 0x84);/* make sure VIA interrupts
1122 1.19.6.2 nathanw * are on (II, IIsi) */
1123 1.19.6.2 nathanw ADB_SET_STATE_IDLE_II(); /* set ADB bus state to idle */
1124 1.19.6.2 nathanw
1125 1.19.6.2 nathanw ADB_VIA_CLR_INTR(); /* clear interrupt */
1126 1.19.6.2 nathanw break;
1127 1.19.6.2 nathanw
1128 1.19.6.2 nathanw case ADB_HW_IISI:
1129 1.19.6.2 nathanw via_reg_or(VIA1, vDirB, 0x30); /* register B bits 4 and 5:
1130 1.19.6.2 nathanw * outputs */
1131 1.19.6.2 nathanw via_reg_and(VIA1, vDirB, 0xf7); /* register B bit 3: input */
1132 1.19.6.2 nathanw via_reg_and(VIA1, vACR, ~vSR_OUT); /* make sure SR is set
1133 1.19.6.2 nathanw * to IN (II, IIsi) */
1134 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE; /* used by all types of
1135 1.19.6.2 nathanw * hardware (II, IIsi) */
1136 1.19.6.2 nathanw adbBusState = ADB_BUS_IDLE; /* this var. used in II-series
1137 1.19.6.2 nathanw * code only */
1138 1.19.6.2 nathanw write_via_reg(VIA1, vIER, 0x84);/* make sure VIA interrupts
1139 1.19.6.2 nathanw * are on (II, IIsi) */
1140 1.19.6.2 nathanw ADB_SET_STATE_IDLE_IISI(); /* set ADB bus state to idle */
1141 1.19.6.2 nathanw
1142 1.19.6.2 nathanw /* get those pesky clock ticks we missed while booting */
1143 1.19.6.2 nathanw for (i = 0; i < 30; i++) {
1144 1.19.6.2 nathanw delay(ADB_DELAY);
1145 1.19.6.2 nathanw adb_hw_setup_IIsi(send_string);
1146 1.19.6.2 nathanw #ifdef ADB_DEBUG
1147 1.19.6.2 nathanw if (adb_debug) {
1148 1.19.6.2 nathanw printf_intr("adb: cleanup: ");
1149 1.19.6.2 nathanw print_single(send_string);
1150 1.19.6.2 nathanw }
1151 1.19.6.2 nathanw #endif
1152 1.19.6.2 nathanw delay(ADB_DELAY);
1153 1.19.6.2 nathanw if (ADB_INTR_IS_OFF)
1154 1.19.6.2 nathanw break;
1155 1.19.6.2 nathanw }
1156 1.19.6.2 nathanw break;
1157 1.19.6.2 nathanw
1158 1.19.6.2 nathanw case ADB_HW_PB:
1159 1.19.6.2 nathanw /*
1160 1.19.6.2 nathanw * XXX - really PM_VIA_CLR_INTR - should we put it in
1161 1.19.6.2 nathanw * pm_direct.h?
1162 1.19.6.2 nathanw */
1163 1.19.6.2 nathanw write_via_reg(VIA1, vIFR, 0x90); /* clear interrupt */
1164 1.19.6.2 nathanw break;
1165 1.19.6.2 nathanw
1166 1.19.6.2 nathanw case ADB_HW_CUDA:
1167 1.19.6.2 nathanw via_reg_or(VIA1, vDirB, 0x30); /* register B bits 4 and 5:
1168 1.19.6.2 nathanw * outputs */
1169 1.19.6.2 nathanw via_reg_and(VIA1, vDirB, 0xf7); /* register B bit 3: input */
1170 1.19.6.2 nathanw via_reg_and(VIA1, vACR, ~vSR_OUT); /* make sure SR is set
1171 1.19.6.2 nathanw * to IN */
1172 1.19.6.2 nathanw write_via_reg(VIA1, vACR, (read_via_reg(VIA1, vACR) | 0x0c) & ~0x10);
1173 1.19.6.2 nathanw adbActionState = ADB_ACTION_IDLE; /* used by all types of
1174 1.19.6.2 nathanw * hardware */
1175 1.19.6.2 nathanw adbBusState = ADB_BUS_IDLE; /* this var. used in II-series
1176 1.19.6.2 nathanw * code only */
1177 1.19.6.2 nathanw write_via_reg(VIA1, vIER, 0x84);/* make sure VIA interrupts
1178 1.19.6.2 nathanw * are on */
1179 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA(); /* set ADB bus state to idle */
1180 1.19.6.2 nathanw
1181 1.19.6.2 nathanw /* sort of a device reset */
1182 1.19.6.2 nathanw i = ADB_SR(); /* clear interrupt */
1183 1.19.6.2 nathanw ADB_VIA_INTR_DISABLE(); /* no interrupts while clearing */
1184 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA(); /* reset state to idle */
1185 1.19.6.2 nathanw delay(ADB_DELAY);
1186 1.19.6.2 nathanw ADB_SET_STATE_TIP(); /* signal start of frame */
1187 1.19.6.2 nathanw delay(ADB_DELAY);
1188 1.19.6.2 nathanw ADB_TOGGLE_STATE_ACK_CUDA();
1189 1.19.6.2 nathanw delay(ADB_DELAY);
1190 1.19.6.2 nathanw ADB_CLR_STATE_TIP();
1191 1.19.6.2 nathanw delay(ADB_DELAY);
1192 1.19.6.2 nathanw ADB_SET_STATE_IDLE_CUDA(); /* back to idle state */
1193 1.19.6.2 nathanw i = ADB_SR(); /* clear interrupt */
1194 1.19.6.2 nathanw ADB_VIA_INTR_ENABLE(); /* ints ok now */
1195 1.19.6.2 nathanw break;
1196 1.19.6.2 nathanw
1197 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1198 1.19.6.2 nathanw default:
1199 1.19.6.2 nathanw write_via_reg(VIA1, vIER, 0x04);/* turn interrupts off - TO
1200 1.19.6.2 nathanw * DO: turn PB ints off? */
1201 1.19.6.2 nathanw return;
1202 1.19.6.2 nathanw break;
1203 1.19.6.2 nathanw }
1204 1.19.6.2 nathanw }
1205 1.19.6.2 nathanw
1206 1.19.6.2 nathanw
1207 1.19.6.2 nathanw /*
1208 1.19.6.2 nathanw * adb_hw_setup_IIsi
1209 1.19.6.2 nathanw * This is sort of a "read" routine that forces the adb hardware through a read cycle
1210 1.19.6.2 nathanw * if there is something waiting. This helps "clean up" any commands that may have gotten
1211 1.19.6.2 nathanw * stuck or stopped during the boot process.
1212 1.19.6.2 nathanw *
1213 1.19.6.2 nathanw */
1214 1.19.6.2 nathanw void
1215 1.19.6.2 nathanw adb_hw_setup_IIsi(u_char * buffer)
1216 1.19.6.2 nathanw {
1217 1.19.6.2 nathanw panic("adb_hw_setup_IIsi");
1218 1.19.6.2 nathanw }
1219 1.19.6.2 nathanw
1220 1.19.6.2 nathanw
1221 1.19.6.2 nathanw /*
1222 1.19.6.2 nathanw * adb_reinit sets up the adb stuff
1223 1.19.6.2 nathanw *
1224 1.19.6.2 nathanw */
1225 1.19.6.2 nathanw void
1226 1.19.6.2 nathanw adb_reinit(void)
1227 1.19.6.2 nathanw {
1228 1.19.6.2 nathanw u_char send_string[ADB_MAX_MSG_LENGTH];
1229 1.19.6.2 nathanw ADBDataBlock data; /* temp. holder for getting device info */
1230 1.19.6.2 nathanw volatile int i, x;
1231 1.19.6.2 nathanw int s;
1232 1.19.6.2 nathanw int command;
1233 1.19.6.2 nathanw int result;
1234 1.19.6.2 nathanw int saveptr; /* point to next free relocation address */
1235 1.19.6.2 nathanw int device;
1236 1.19.6.2 nathanw int nonewtimes; /* times thru loop w/o any new devices */
1237 1.19.6.2 nathanw
1238 1.19.6.2 nathanw /* Make sure we are not interrupted while building the table. */
1239 1.19.6.2 nathanw if (adbHardware != ADB_HW_PB) /* ints must be on for PB? */
1240 1.19.6.2 nathanw s = splhigh();
1241 1.19.6.2 nathanw
1242 1.19.6.2 nathanw ADBNumDevices = 0; /* no devices yet */
1243 1.19.6.2 nathanw
1244 1.19.6.2 nathanw /* Let intr routines know we are running reinit */
1245 1.19.6.2 nathanw adbStarting = 1;
1246 1.19.6.2 nathanw
1247 1.19.6.2 nathanw /*
1248 1.19.6.2 nathanw * Initialize the ADB table. For now, we'll always use the same table
1249 1.19.6.2 nathanw * that is defined at the beginning of this file - no mallocs.
1250 1.19.6.2 nathanw */
1251 1.19.6.2 nathanw for (i = 0; i < 16; i++)
1252 1.19.6.2 nathanw ADBDevTable[i].devType = 0;
1253 1.19.6.2 nathanw
1254 1.19.6.2 nathanw adb_setup_hw_type(); /* setup hardware type */
1255 1.19.6.2 nathanw
1256 1.19.6.2 nathanw adb_hw_setup(); /* init the VIA bits and hard reset ADB */
1257 1.19.6.2 nathanw
1258 1.19.6.2 nathanw delay(1000);
1259 1.19.6.2 nathanw
1260 1.19.6.2 nathanw /* send an ADB reset first */
1261 1.19.6.2 nathanw result = adb_op_sync((Ptr)0, (Ptr)0, (Ptr)0, (short)0x00);
1262 1.19.6.2 nathanw delay(200000);
1263 1.19.6.2 nathanw
1264 1.19.6.2 nathanw #ifdef ADB_DEBUG
1265 1.19.6.2 nathanw if (result && adb_debug) {
1266 1.19.6.2 nathanw printf_intr("adb_reinit: failed to reset, result = %d\n",result);
1267 1.19.6.2 nathanw }
1268 1.19.6.2 nathanw #endif
1269 1.19.6.2 nathanw
1270 1.19.6.2 nathanw /*
1271 1.19.6.2 nathanw * Probe for ADB devices. Probe devices 1-15 quickly to determine
1272 1.19.6.2 nathanw * which device addresses are in use and which are free. For each
1273 1.19.6.2 nathanw * address that is in use, move the device at that address to a higher
1274 1.19.6.2 nathanw * free address. Continue doing this at that address until no device
1275 1.19.6.2 nathanw * responds at that address. Then move the last device that was moved
1276 1.19.6.2 nathanw * back to the original address. Do this for the remaining addresses
1277 1.19.6.2 nathanw * that we determined were in use.
1278 1.19.6.2 nathanw *
1279 1.19.6.2 nathanw * When finished, do this entire process over again with the updated
1280 1.19.6.2 nathanw * list of in use addresses. Do this until no new devices have been
1281 1.19.6.2 nathanw * found in 20 passes though the in use address list. (This probably
1282 1.19.6.2 nathanw * seems long and complicated, but it's the best way to detect multiple
1283 1.19.6.2 nathanw * devices at the same address - sometimes it takes a couple of tries
1284 1.19.6.2 nathanw * before the collision is detected.)
1285 1.19.6.2 nathanw */
1286 1.19.6.2 nathanw
1287 1.19.6.2 nathanw /* initial scan through the devices */
1288 1.19.6.2 nathanw for (i = 1; i < 16; i++) {
1289 1.19.6.2 nathanw send_string[0] = 0;
1290 1.19.6.2 nathanw command = ADBTALK(i, 3);
1291 1.19.6.2 nathanw result = adb_op_sync((Ptr)send_string, (Ptr)0,
1292 1.19.6.2 nathanw (Ptr)0, (short)command);
1293 1.19.6.2 nathanw
1294 1.19.6.2 nathanw #ifdef ADB_DEBUG
1295 1.19.6.2 nathanw if (result && adb_debug) {
1296 1.19.6.2 nathanw printf_intr("adb_reinit: scan of device %d, result = %d, str = 0x%x\n",
1297 1.19.6.2 nathanw i,result,send_string[0]);
1298 1.19.6.2 nathanw }
1299 1.19.6.2 nathanw #endif
1300 1.19.6.2 nathanw
1301 1.19.6.2 nathanw if (send_string[0] != 0) {
1302 1.19.6.2 nathanw /* check for valid device handler */
1303 1.19.6.2 nathanw switch (send_string[2]) {
1304 1.19.6.2 nathanw case 0:
1305 1.19.6.2 nathanw case 0xfd:
1306 1.19.6.2 nathanw case 0xfe:
1307 1.19.6.2 nathanw case 0xff:
1308 1.19.6.2 nathanw continue; /* invalid, skip */
1309 1.19.6.2 nathanw }
1310 1.19.6.2 nathanw
1311 1.19.6.2 nathanw /* found a device */
1312 1.19.6.2 nathanw ++ADBNumDevices;
1313 1.19.6.2 nathanw KASSERT(ADBNumDevices < 16);
1314 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].devType =
1315 1.19.6.2 nathanw (int)send_string[2];
1316 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].origAddr = i;
1317 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].currentAddr = i;
1318 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].DataAreaAddr =
1319 1.19.6.2 nathanw (long)0;
1320 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].ServiceRtPtr = (void *)0;
1321 1.19.6.2 nathanw pm_check_adb_devices(i); /* tell pm driver device
1322 1.19.6.2 nathanw * is here */
1323 1.19.6.2 nathanw }
1324 1.19.6.2 nathanw }
1325 1.19.6.2 nathanw
1326 1.19.6.2 nathanw /* find highest unused address */
1327 1.19.6.2 nathanw for (saveptr = 15; saveptr > 0; saveptr--)
1328 1.19.6.2 nathanw if (-1 == get_adb_info(&data, saveptr))
1329 1.19.6.2 nathanw break;
1330 1.19.6.2 nathanw
1331 1.19.6.2 nathanw #ifdef ADB_DEBUG
1332 1.19.6.2 nathanw if (adb_debug & 0x80) {
1333 1.19.6.2 nathanw printf_intr("first free is: 0x%02x\n", saveptr);
1334 1.19.6.2 nathanw printf_intr("devices: %i\n", ADBNumDevices);
1335 1.19.6.2 nathanw }
1336 1.19.6.2 nathanw #endif
1337 1.19.6.2 nathanw
1338 1.19.6.2 nathanw nonewtimes = 0; /* no loops w/o new devices */
1339 1.19.6.2 nathanw while (saveptr > 0 && nonewtimes++ < 11) {
1340 1.19.6.2 nathanw for (i = 1; i <= ADBNumDevices; i++) {
1341 1.19.6.2 nathanw device = ADBDevTable[i].currentAddr;
1342 1.19.6.2 nathanw #ifdef ADB_DEBUG
1343 1.19.6.2 nathanw if (adb_debug & 0x80)
1344 1.19.6.2 nathanw printf_intr("moving device 0x%02x to 0x%02x "
1345 1.19.6.2 nathanw "(index 0x%02x) ", device, saveptr, i);
1346 1.19.6.2 nathanw #endif
1347 1.19.6.2 nathanw
1348 1.19.6.2 nathanw /* send TALK R3 to address */
1349 1.19.6.2 nathanw command = ADBTALK(device, 3);
1350 1.19.6.2 nathanw adb_op_sync((Ptr)send_string, (Ptr)0,
1351 1.19.6.2 nathanw (Ptr)0, (short)command);
1352 1.19.6.2 nathanw
1353 1.19.6.2 nathanw /* move device to higher address */
1354 1.19.6.2 nathanw command = ADBLISTEN(device, 3);
1355 1.19.6.2 nathanw send_string[0] = 2;
1356 1.19.6.2 nathanw send_string[1] = (u_char)(saveptr | 0x60);
1357 1.19.6.2 nathanw send_string[2] = 0xfe;
1358 1.19.6.2 nathanw adb_op_sync((Ptr)send_string, (Ptr)0,
1359 1.19.6.2 nathanw (Ptr)0, (short)command);
1360 1.19.6.2 nathanw delay(500);
1361 1.19.6.2 nathanw
1362 1.19.6.2 nathanw /* send TALK R3 - anything at new address? */
1363 1.19.6.2 nathanw command = ADBTALK(saveptr, 3);
1364 1.19.6.2 nathanw adb_op_sync((Ptr)send_string, (Ptr)0,
1365 1.19.6.2 nathanw (Ptr)0, (short)command);
1366 1.19.6.2 nathanw delay(500);
1367 1.19.6.2 nathanw
1368 1.19.6.2 nathanw if (send_string[0] == 0) {
1369 1.19.6.2 nathanw #ifdef ADB_DEBUG
1370 1.19.6.2 nathanw if (adb_debug & 0x80)
1371 1.19.6.2 nathanw printf_intr("failed, continuing\n");
1372 1.19.6.2 nathanw #endif
1373 1.19.6.2 nathanw continue;
1374 1.19.6.2 nathanw }
1375 1.19.6.2 nathanw
1376 1.19.6.2 nathanw /* send TALK R3 - anything at old address? */
1377 1.19.6.2 nathanw command = ADBTALK(device, 3);
1378 1.19.6.2 nathanw result = adb_op_sync((Ptr)send_string, (Ptr)0,
1379 1.19.6.2 nathanw (Ptr)0, (short)command);
1380 1.19.6.2 nathanw if (send_string[0] != 0) {
1381 1.19.6.2 nathanw /* check for valid device handler */
1382 1.19.6.2 nathanw switch (send_string[2]) {
1383 1.19.6.2 nathanw case 0:
1384 1.19.6.2 nathanw case 0xfd:
1385 1.19.6.2 nathanw case 0xfe:
1386 1.19.6.2 nathanw case 0xff:
1387 1.19.6.2 nathanw continue; /* invalid, skip */
1388 1.19.6.2 nathanw }
1389 1.19.6.2 nathanw
1390 1.19.6.2 nathanw /* new device found */
1391 1.19.6.2 nathanw /* update data for previously moved device */
1392 1.19.6.2 nathanw ADBDevTable[i].currentAddr = saveptr;
1393 1.19.6.2 nathanw #ifdef ADB_DEBUG
1394 1.19.6.2 nathanw if (adb_debug & 0x80)
1395 1.19.6.2 nathanw printf_intr("old device at index %i\n",i);
1396 1.19.6.2 nathanw #endif
1397 1.19.6.2 nathanw /* add new device in table */
1398 1.19.6.2 nathanw #ifdef ADB_DEBUG
1399 1.19.6.2 nathanw if (adb_debug & 0x80)
1400 1.19.6.2 nathanw printf_intr("new device found\n");
1401 1.19.6.2 nathanw #endif
1402 1.19.6.2 nathanw if (saveptr > ADBNumDevices) {
1403 1.19.6.2 nathanw ++ADBNumDevices;
1404 1.19.6.2 nathanw KASSERT(ADBNumDevices < 16);
1405 1.19.6.2 nathanw }
1406 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].devType =
1407 1.19.6.2 nathanw (int)send_string[2];
1408 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].origAddr = device;
1409 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].currentAddr = device;
1410 1.19.6.2 nathanw /* These will be set correctly in adbsys.c */
1411 1.19.6.2 nathanw /* Until then, unsol. data will be ignored. */
1412 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].DataAreaAddr =
1413 1.19.6.2 nathanw (long)0;
1414 1.19.6.2 nathanw ADBDevTable[ADBNumDevices].ServiceRtPtr =
1415 1.19.6.2 nathanw (void *)0;
1416 1.19.6.2 nathanw /* find next unused address */
1417 1.19.6.2 nathanw for (x = saveptr; x > 0; x--) {
1418 1.19.6.2 nathanw if (-1 == get_adb_info(&data, x)) {
1419 1.19.6.2 nathanw saveptr = x;
1420 1.19.6.2 nathanw break;
1421 1.19.6.2 nathanw }
1422 1.19.6.2 nathanw }
1423 1.19.6.2 nathanw if (x == 0)
1424 1.19.6.2 nathanw saveptr = 0;
1425 1.19.6.2 nathanw #ifdef ADB_DEBUG
1426 1.19.6.2 nathanw if (adb_debug & 0x80)
1427 1.19.6.2 nathanw printf_intr("new free is 0x%02x\n",
1428 1.19.6.2 nathanw saveptr);
1429 1.19.6.2 nathanw #endif
1430 1.19.6.2 nathanw nonewtimes = 0;
1431 1.19.6.2 nathanw /* tell pm driver device is here */
1432 1.19.6.2 nathanw pm_check_adb_devices(device);
1433 1.19.6.2 nathanw } else {
1434 1.19.6.2 nathanw #ifdef ADB_DEBUG
1435 1.19.6.2 nathanw if (adb_debug & 0x80)
1436 1.19.6.2 nathanw printf_intr("moving back...\n");
1437 1.19.6.2 nathanw #endif
1438 1.19.6.2 nathanw /* move old device back */
1439 1.19.6.2 nathanw command = ADBLISTEN(saveptr, 3);
1440 1.19.6.2 nathanw send_string[0] = 2;
1441 1.19.6.2 nathanw send_string[1] = (u_char)(device | 0x60);
1442 1.19.6.2 nathanw send_string[2] = 0xfe;
1443 1.19.6.2 nathanw adb_op_sync((Ptr)send_string, (Ptr)0,
1444 1.19.6.2 nathanw (Ptr)0, (short)command);
1445 1.19.6.2 nathanw delay(1000);
1446 1.19.6.2 nathanw }
1447 1.19.6.2 nathanw }
1448 1.19.6.2 nathanw }
1449 1.19.6.2 nathanw
1450 1.19.6.2 nathanw #ifdef ADB_DEBUG
1451 1.19.6.2 nathanw if (adb_debug) {
1452 1.19.6.2 nathanw for (i = 1; i <= ADBNumDevices; i++) {
1453 1.19.6.2 nathanw x = get_ind_adb_info(&data, i);
1454 1.19.6.2 nathanw if (x != -1)
1455 1.19.6.2 nathanw printf_intr("index 0x%x, addr 0x%x, type 0x%x\n",
1456 1.19.6.2 nathanw i, x, data.devType);
1457 1.19.6.2 nathanw }
1458 1.19.6.2 nathanw }
1459 1.19.6.2 nathanw #endif
1460 1.19.6.2 nathanw
1461 1.19.6.2 nathanw #ifndef MRG_ADB
1462 1.19.6.2 nathanw /* enable the programmer's switch, if we have one */
1463 1.19.6.2 nathanw adb_prog_switch_enable();
1464 1.19.6.2 nathanw #endif
1465 1.19.6.2 nathanw
1466 1.19.6.2 nathanw #ifdef ADB_DEBUG
1467 1.19.6.2 nathanw if (adb_debug) {
1468 1.19.6.2 nathanw if (0 == ADBNumDevices) /* tell user if no devices found */
1469 1.19.6.2 nathanw printf_intr("adb: no devices found\n");
1470 1.19.6.2 nathanw }
1471 1.19.6.2 nathanw #endif
1472 1.19.6.2 nathanw
1473 1.19.6.2 nathanw adbStarting = 0; /* not starting anymore */
1474 1.19.6.2 nathanw #ifdef ADB_DEBUG
1475 1.19.6.2 nathanw if (adb_debug)
1476 1.19.6.2 nathanw printf_intr("adb: ADBReInit complete\n");
1477 1.19.6.2 nathanw #endif
1478 1.19.6.2 nathanw
1479 1.19.6.2 nathanw if (adbHardware == ADB_HW_CUDA)
1480 1.19.6.2 nathanw callout_reset(&adb_cuda_tickle_ch, ADB_TICKLE_TICKS,
1481 1.19.6.2 nathanw (void *)adb_cuda_tickle, NULL);
1482 1.19.6.2 nathanw
1483 1.19.6.2 nathanw if (adbHardware != ADB_HW_PB) /* ints must be on for PB? */
1484 1.19.6.2 nathanw splx(s);
1485 1.19.6.2 nathanw }
1486 1.19.6.2 nathanw
1487 1.19.6.2 nathanw /*
1488 1.19.6.2 nathanw * adb_cmd_result
1489 1.19.6.2 nathanw *
1490 1.19.6.2 nathanw * This routine lets the caller know whether the specified adb command string
1491 1.19.6.2 nathanw * should expect a returned result, such as a TALK command.
1492 1.19.6.2 nathanw *
1493 1.19.6.2 nathanw * returns: 0 if a result should be expected
1494 1.19.6.2 nathanw * 1 if a result should NOT be expected
1495 1.19.6.2 nathanw */
1496 1.19.6.2 nathanw int
1497 1.19.6.2 nathanw adb_cmd_result(u_char *in)
1498 1.19.6.2 nathanw {
1499 1.19.6.2 nathanw switch (adbHardware) {
1500 1.19.6.2 nathanw case ADB_HW_II:
1501 1.19.6.2 nathanw /* was it an ADB talk command? */
1502 1.19.6.2 nathanw if ((in[1] & 0x0c) == 0x0c)
1503 1.19.6.2 nathanw return 0;
1504 1.19.6.2 nathanw return 1;
1505 1.19.6.2 nathanw
1506 1.19.6.2 nathanw case ADB_HW_IISI:
1507 1.19.6.2 nathanw case ADB_HW_CUDA:
1508 1.19.6.2 nathanw /* was it an ADB talk command? */
1509 1.19.6.2 nathanw if ((in[1] == 0x00) && ((in[2] & 0x0c) == 0x0c))
1510 1.19.6.2 nathanw return 0;
1511 1.19.6.2 nathanw /* was it an RTC/PRAM read date/time? */
1512 1.19.6.2 nathanw if ((in[1] == 0x01) && (in[2] == 0x03))
1513 1.19.6.2 nathanw return 0;
1514 1.19.6.2 nathanw return 1;
1515 1.19.6.2 nathanw
1516 1.19.6.2 nathanw case ADB_HW_PB:
1517 1.19.6.2 nathanw return 1;
1518 1.19.6.2 nathanw
1519 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1520 1.19.6.2 nathanw default:
1521 1.19.6.2 nathanw return 1;
1522 1.19.6.2 nathanw }
1523 1.19.6.2 nathanw }
1524 1.19.6.2 nathanw
1525 1.19.6.2 nathanw
1526 1.19.6.2 nathanw /*
1527 1.19.6.2 nathanw * adb_cmd_extra
1528 1.19.6.2 nathanw *
1529 1.19.6.2 nathanw * This routine lets the caller know whether the specified adb command string
1530 1.19.6.2 nathanw * may have extra data appended to the end of it, such as a LISTEN command.
1531 1.19.6.2 nathanw *
1532 1.19.6.2 nathanw * returns: 0 if extra data is allowed
1533 1.19.6.2 nathanw * 1 if extra data is NOT allowed
1534 1.19.6.2 nathanw */
1535 1.19.6.2 nathanw int
1536 1.19.6.2 nathanw adb_cmd_extra(u_char *in)
1537 1.19.6.2 nathanw {
1538 1.19.6.2 nathanw switch (adbHardware) {
1539 1.19.6.2 nathanw case ADB_HW_II:
1540 1.19.6.2 nathanw if ((in[1] & 0x0c) == 0x08) /* was it a listen command? */
1541 1.19.6.2 nathanw return 0;
1542 1.19.6.2 nathanw return 1;
1543 1.19.6.2 nathanw
1544 1.19.6.2 nathanw case ADB_HW_IISI:
1545 1.19.6.2 nathanw case ADB_HW_CUDA:
1546 1.19.6.2 nathanw /*
1547 1.19.6.2 nathanw * TO DO: support needs to be added to recognize RTC and PRAM
1548 1.19.6.2 nathanw * commands
1549 1.19.6.2 nathanw */
1550 1.19.6.2 nathanw if ((in[2] & 0x0c) == 0x08) /* was it a listen command? */
1551 1.19.6.2 nathanw return 0;
1552 1.19.6.2 nathanw /* add others later */
1553 1.19.6.2 nathanw return 1;
1554 1.19.6.2 nathanw
1555 1.19.6.2 nathanw case ADB_HW_PB:
1556 1.19.6.2 nathanw return 1;
1557 1.19.6.2 nathanw
1558 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1559 1.19.6.2 nathanw default:
1560 1.19.6.2 nathanw return 1;
1561 1.19.6.2 nathanw }
1562 1.19.6.2 nathanw }
1563 1.19.6.2 nathanw
1564 1.19.6.2 nathanw /*
1565 1.19.6.2 nathanw * adb_op_sync
1566 1.19.6.2 nathanw *
1567 1.19.6.2 nathanw * This routine does exactly what the adb_op routine does, except that after
1568 1.19.6.2 nathanw * the adb_op is called, it waits until the return value is present before
1569 1.19.6.2 nathanw * returning.
1570 1.19.6.2 nathanw *
1571 1.19.6.2 nathanw * NOTE: The user specified compRout is ignored, since this routine specifies
1572 1.19.6.2 nathanw * it's own to adb_op, which is why you really called this in the first place
1573 1.19.6.2 nathanw * anyway.
1574 1.19.6.2 nathanw */
1575 1.19.6.2 nathanw int
1576 1.19.6.2 nathanw adb_op_sync(Ptr buffer, Ptr compRout, Ptr data, short command)
1577 1.19.6.2 nathanw {
1578 1.19.6.2 nathanw int tmout;
1579 1.19.6.2 nathanw int result;
1580 1.19.6.2 nathanw volatile int flag = 0;
1581 1.19.6.2 nathanw
1582 1.19.6.2 nathanw result = adb_op(buffer, (void *)adb_op_comprout,
1583 1.19.6.2 nathanw (void *)&flag, command); /* send command */
1584 1.19.6.2 nathanw if (result == 0) { /* send ok? */
1585 1.19.6.2 nathanw /*
1586 1.19.6.2 nathanw * Total time to wait is calculated as follows:
1587 1.19.6.2 nathanw * - Tlt (stop to start time): 260 usec
1588 1.19.6.2 nathanw * - start bit: 100 usec
1589 1.19.6.2 nathanw * - up to 8 data bytes: 64 * 100 usec = 6400 usec
1590 1.19.6.2 nathanw * - stop bit (with SRQ): 140 usec
1591 1.19.6.2 nathanw * Total: 6900 usec
1592 1.19.6.2 nathanw *
1593 1.19.6.2 nathanw * This is the total time allowed by the specification. Any
1594 1.19.6.2 nathanw * device that doesn't conform to this will fail to operate
1595 1.19.6.2 nathanw * properly on some Apple systems. In spite of this we
1596 1.19.6.2 nathanw * double the time to wait; some Cuda-based apparently
1597 1.19.6.2 nathanw * queues some commands and allows the main CPU to continue
1598 1.19.6.2 nathanw * processing (radical concept, eh?). To be safe, allow
1599 1.19.6.2 nathanw * time for two complete ADB transactions to occur.
1600 1.19.6.2 nathanw */
1601 1.19.6.2 nathanw for (tmout = 13800; !flag && tmout >= 10; tmout -= 10)
1602 1.19.6.2 nathanw delay(10);
1603 1.19.6.2 nathanw if (!flag && tmout > 0)
1604 1.19.6.2 nathanw delay(tmout);
1605 1.19.6.2 nathanw
1606 1.19.6.2 nathanw if (!flag)
1607 1.19.6.2 nathanw result = -2;
1608 1.19.6.2 nathanw }
1609 1.19.6.2 nathanw
1610 1.19.6.2 nathanw return result;
1611 1.19.6.2 nathanw }
1612 1.19.6.2 nathanw
1613 1.19.6.2 nathanw /*
1614 1.19.6.2 nathanw * adb_op_comprout
1615 1.19.6.2 nathanw *
1616 1.19.6.2 nathanw * This function is used by the adb_op_sync routine so it knows when the
1617 1.19.6.2 nathanw * function is done.
1618 1.19.6.2 nathanw */
1619 1.19.6.2 nathanw void
1620 1.19.6.2 nathanw adb_op_comprout(buffer, compdata, cmd)
1621 1.19.6.2 nathanw caddr_t buffer, compdata;
1622 1.19.6.2 nathanw int cmd;
1623 1.19.6.2 nathanw {
1624 1.19.6.2 nathanw short *p = (short *)compdata;
1625 1.19.6.2 nathanw
1626 1.19.6.2 nathanw *p = 1;
1627 1.19.6.2 nathanw }
1628 1.19.6.2 nathanw
1629 1.19.6.2 nathanw void
1630 1.19.6.2 nathanw adb_setup_hw_type(void)
1631 1.19.6.2 nathanw {
1632 1.19.6.2 nathanw switch (adbHardware) {
1633 1.19.6.2 nathanw case ADB_HW_CUDA:
1634 1.19.6.2 nathanw adbSoftPower = 1;
1635 1.19.6.2 nathanw return;
1636 1.19.6.2 nathanw
1637 1.19.6.2 nathanw case ADB_HW_PB:
1638 1.19.6.2 nathanw adbSoftPower = 1;
1639 1.19.6.2 nathanw pm_setup_adb();
1640 1.19.6.2 nathanw return;
1641 1.19.6.2 nathanw
1642 1.19.6.2 nathanw default:
1643 1.19.6.2 nathanw panic("unknown adb hardware");
1644 1.19.6.2 nathanw }
1645 1.19.6.2 nathanw #if 0
1646 1.19.6.2 nathanw response = 0; /*mac68k_machine.machineid;*/
1647 1.19.6.2 nathanw
1648 1.19.6.2 nathanw /*
1649 1.19.6.2 nathanw * Determine what type of ADB hardware we are running on.
1650 1.19.6.2 nathanw */
1651 1.19.6.2 nathanw switch (response) {
1652 1.19.6.2 nathanw case MACH_MACC610: /* Centris 610 */
1653 1.19.6.2 nathanw case MACH_MACC650: /* Centris 650 */
1654 1.19.6.2 nathanw case MACH_MACII: /* II */
1655 1.19.6.2 nathanw case MACH_MACIICI: /* IIci */
1656 1.19.6.2 nathanw case MACH_MACIICX: /* IIcx */
1657 1.19.6.2 nathanw case MACH_MACIIX: /* IIx */
1658 1.19.6.2 nathanw case MACH_MACQ610: /* Quadra 610 */
1659 1.19.6.2 nathanw case MACH_MACQ650: /* Quadra 650 */
1660 1.19.6.2 nathanw case MACH_MACQ700: /* Quadra 700 */
1661 1.19.6.2 nathanw case MACH_MACQ800: /* Quadra 800 */
1662 1.19.6.2 nathanw case MACH_MACSE30: /* SE/30 */
1663 1.19.6.2 nathanw adbHardware = ADB_HW_II;
1664 1.19.6.2 nathanw #ifdef ADB_DEBUG
1665 1.19.6.2 nathanw if (adb_debug)
1666 1.19.6.2 nathanw printf_intr("adb: using II series hardware support\n");
1667 1.19.6.2 nathanw #endif
1668 1.19.6.2 nathanw break;
1669 1.19.6.2 nathanw
1670 1.19.6.2 nathanw case MACH_MACCLASSICII: /* Classic II */
1671 1.19.6.2 nathanw case MACH_MACLCII: /* LC II, Performa 400/405/430 */
1672 1.19.6.2 nathanw case MACH_MACLCIII: /* LC III, Performa 450 */
1673 1.19.6.2 nathanw case MACH_MACIISI: /* IIsi */
1674 1.19.6.2 nathanw case MACH_MACIIVI: /* IIvi */
1675 1.19.6.2 nathanw case MACH_MACIIVX: /* IIvx */
1676 1.19.6.2 nathanw case MACH_MACP460: /* Performa 460/465/467 */
1677 1.19.6.2 nathanw case MACH_MACP600: /* Performa 600 */
1678 1.19.6.2 nathanw adbHardware = ADB_HW_IISI;
1679 1.19.6.2 nathanw #ifdef ADB_DEBUG
1680 1.19.6.2 nathanw if (adb_debug)
1681 1.19.6.2 nathanw printf_intr("adb: using IIsi series hardware support\n");
1682 1.19.6.2 nathanw #endif
1683 1.19.6.2 nathanw break;
1684 1.19.6.2 nathanw
1685 1.19.6.2 nathanw case MACH_MACPB140: /* PowerBook 140 */
1686 1.19.6.2 nathanw case MACH_MACPB145: /* PowerBook 145 */
1687 1.19.6.2 nathanw case MACH_MACPB150: /* PowerBook 150 */
1688 1.19.6.2 nathanw case MACH_MACPB160: /* PowerBook 160 */
1689 1.19.6.2 nathanw case MACH_MACPB165: /* PowerBook 165 */
1690 1.19.6.2 nathanw case MACH_MACPB165C: /* PowerBook 165c */
1691 1.19.6.2 nathanw case MACH_MACPB170: /* PowerBook 170 */
1692 1.19.6.2 nathanw case MACH_MACPB180: /* PowerBook 180 */
1693 1.19.6.2 nathanw case MACH_MACPB180C: /* PowerBook 180c */
1694 1.19.6.2 nathanw adbHardware = ADB_HW_PB;
1695 1.19.6.2 nathanw pm_setup_adb();
1696 1.19.6.2 nathanw #ifdef ADB_DEBUG
1697 1.19.6.2 nathanw if (adb_debug)
1698 1.19.6.2 nathanw printf_intr("adb: using PowerBook 100-series hardware support\n");
1699 1.19.6.2 nathanw #endif
1700 1.19.6.2 nathanw break;
1701 1.19.6.2 nathanw
1702 1.19.6.2 nathanw case MACH_MACPB210: /* PowerBook Duo 210 */
1703 1.19.6.2 nathanw case MACH_MACPB230: /* PowerBook Duo 230 */
1704 1.19.6.2 nathanw case MACH_MACPB250: /* PowerBook Duo 250 */
1705 1.19.6.2 nathanw case MACH_MACPB270: /* PowerBook Duo 270 */
1706 1.19.6.2 nathanw case MACH_MACPB280: /* PowerBook Duo 280 */
1707 1.19.6.2 nathanw case MACH_MACPB280C: /* PowerBook Duo 280c */
1708 1.19.6.2 nathanw case MACH_MACPB500: /* PowerBook 500 series */
1709 1.19.6.2 nathanw adbHardware = ADB_HW_PB;
1710 1.19.6.2 nathanw pm_setup_adb();
1711 1.19.6.2 nathanw #ifdef ADB_DEBUG
1712 1.19.6.2 nathanw if (adb_debug)
1713 1.19.6.2 nathanw printf_intr("adb: using PowerBook Duo-series and PowerBook 500-series hardware support\n");
1714 1.19.6.2 nathanw #endif
1715 1.19.6.2 nathanw break;
1716 1.19.6.2 nathanw
1717 1.19.6.2 nathanw case MACH_MACC660AV: /* Centris 660AV */
1718 1.19.6.2 nathanw case MACH_MACCCLASSIC: /* Color Classic */
1719 1.19.6.2 nathanw case MACH_MACCCLASSICII: /* Color Classic II */
1720 1.19.6.2 nathanw case MACH_MACLC475: /* LC 475, Performa 475/476 */
1721 1.19.6.2 nathanw case MACH_MACLC475_33: /* Clock-chipped 47x */
1722 1.19.6.2 nathanw case MACH_MACLC520: /* LC 520 */
1723 1.19.6.2 nathanw case MACH_MACLC575: /* LC 575, Performa 575/577/578 */
1724 1.19.6.2 nathanw case MACH_MACP550: /* LC 550, Performa 550 */
1725 1.19.6.2 nathanw case MACH_MACP580: /* Performa 580/588 */
1726 1.19.6.2 nathanw case MACH_MACQ605: /* Quadra 605 */
1727 1.19.6.2 nathanw case MACH_MACQ605_33: /* Clock-chipped Quadra 605 */
1728 1.19.6.2 nathanw case MACH_MACQ630: /* LC 630, Performa 630, Quadra 630 */
1729 1.19.6.2 nathanw case MACH_MACQ840AV: /* Quadra 840AV */
1730 1.19.6.2 nathanw adbHardware = ADB_HW_CUDA;
1731 1.19.6.2 nathanw #ifdef ADB_DEBUG
1732 1.19.6.2 nathanw if (adb_debug)
1733 1.19.6.2 nathanw printf_intr("adb: using Cuda series hardware support\n");
1734 1.19.6.2 nathanw #endif
1735 1.19.6.2 nathanw break;
1736 1.19.6.2 nathanw default:
1737 1.19.6.2 nathanw adbHardware = ADB_HW_UNKNOWN;
1738 1.19.6.2 nathanw #ifdef ADB_DEBUG
1739 1.19.6.2 nathanw if (adb_debug) {
1740 1.19.6.2 nathanw printf_intr("adb: hardware type unknown for this machine\n");
1741 1.19.6.2 nathanw printf_intr("adb: ADB support is disabled\n");
1742 1.19.6.2 nathanw }
1743 1.19.6.2 nathanw #endif
1744 1.19.6.2 nathanw break;
1745 1.19.6.2 nathanw }
1746 1.19.6.2 nathanw
1747 1.19.6.2 nathanw /*
1748 1.19.6.2 nathanw * Determine whether this machine has ADB based soft power.
1749 1.19.6.2 nathanw */
1750 1.19.6.2 nathanw switch (response) {
1751 1.19.6.2 nathanw case MACH_MACCCLASSIC: /* Color Classic */
1752 1.19.6.2 nathanw case MACH_MACCCLASSICII: /* Color Classic II */
1753 1.19.6.2 nathanw case MACH_MACIISI: /* IIsi */
1754 1.19.6.2 nathanw case MACH_MACIIVI: /* IIvi */
1755 1.19.6.2 nathanw case MACH_MACIIVX: /* IIvx */
1756 1.19.6.2 nathanw case MACH_MACLC520: /* LC 520 */
1757 1.19.6.2 nathanw case MACH_MACLC575: /* LC 575, Performa 575/577/578 */
1758 1.19.6.2 nathanw case MACH_MACP550: /* LC 550, Performa 550 */
1759 1.19.6.2 nathanw case MACH_MACP600: /* Performa 600 */
1760 1.19.6.2 nathanw case MACH_MACQ630: /* LC 630, Performa 630, Quadra 630 */
1761 1.19.6.2 nathanw case MACH_MACQ840AV: /* Quadra 840AV */
1762 1.19.6.2 nathanw adbSoftPower = 1;
1763 1.19.6.2 nathanw break;
1764 1.19.6.2 nathanw }
1765 1.19.6.2 nathanw #endif
1766 1.19.6.2 nathanw }
1767 1.19.6.2 nathanw
1768 1.19.6.2 nathanw int
1769 1.19.6.2 nathanw count_adbs(void)
1770 1.19.6.2 nathanw {
1771 1.19.6.2 nathanw int i;
1772 1.19.6.2 nathanw int found;
1773 1.19.6.2 nathanw
1774 1.19.6.2 nathanw found = 0;
1775 1.19.6.2 nathanw
1776 1.19.6.2 nathanw for (i = 1; i < 16; i++)
1777 1.19.6.2 nathanw if (0 != ADBDevTable[i].devType)
1778 1.19.6.2 nathanw found++;
1779 1.19.6.2 nathanw
1780 1.19.6.2 nathanw return found;
1781 1.19.6.2 nathanw }
1782 1.19.6.2 nathanw
1783 1.19.6.2 nathanw int
1784 1.19.6.2 nathanw get_ind_adb_info(ADBDataBlock * info, int index)
1785 1.19.6.2 nathanw {
1786 1.19.6.2 nathanw if ((index < 1) || (index > 15)) /* check range 1-15 */
1787 1.19.6.2 nathanw return (-1);
1788 1.19.6.2 nathanw
1789 1.19.6.2 nathanw #ifdef ADB_DEBUG
1790 1.19.6.2 nathanw if (adb_debug & 0x80)
1791 1.19.6.2 nathanw printf_intr("index 0x%x devType is: 0x%x\n", index,
1792 1.19.6.2 nathanw ADBDevTable[index].devType);
1793 1.19.6.2 nathanw #endif
1794 1.19.6.2 nathanw if (0 == ADBDevTable[index].devType) /* make sure it's a valid entry */
1795 1.19.6.2 nathanw return (-1);
1796 1.19.6.2 nathanw
1797 1.19.6.2 nathanw info->devType = ADBDevTable[index].devType;
1798 1.19.6.2 nathanw info->origADBAddr = ADBDevTable[index].origAddr;
1799 1.19.6.2 nathanw info->dbServiceRtPtr = (Ptr)ADBDevTable[index].ServiceRtPtr;
1800 1.19.6.2 nathanw info->dbDataAreaAddr = (Ptr)ADBDevTable[index].DataAreaAddr;
1801 1.19.6.2 nathanw
1802 1.19.6.2 nathanw return (ADBDevTable[index].currentAddr);
1803 1.19.6.2 nathanw }
1804 1.19.6.2 nathanw
1805 1.19.6.2 nathanw int
1806 1.19.6.2 nathanw get_adb_info(ADBDataBlock * info, int adbAddr)
1807 1.19.6.2 nathanw {
1808 1.19.6.2 nathanw int i;
1809 1.19.6.2 nathanw
1810 1.19.6.2 nathanw if ((adbAddr < 1) || (adbAddr > 15)) /* check range 1-15 */
1811 1.19.6.2 nathanw return (-1);
1812 1.19.6.2 nathanw
1813 1.19.6.2 nathanw for (i = 1; i < 15; i++)
1814 1.19.6.2 nathanw if (ADBDevTable[i].currentAddr == adbAddr) {
1815 1.19.6.2 nathanw info->devType = ADBDevTable[i].devType;
1816 1.19.6.2 nathanw info->origADBAddr = ADBDevTable[i].origAddr;
1817 1.19.6.2 nathanw info->dbServiceRtPtr = (Ptr)ADBDevTable[i].ServiceRtPtr;
1818 1.19.6.2 nathanw info->dbDataAreaAddr = ADBDevTable[i].DataAreaAddr;
1819 1.19.6.2 nathanw return 0; /* found */
1820 1.19.6.2 nathanw }
1821 1.19.6.2 nathanw
1822 1.19.6.2 nathanw return (-1); /* not found */
1823 1.19.6.2 nathanw }
1824 1.19.6.2 nathanw
1825 1.19.6.2 nathanw int
1826 1.19.6.2 nathanw set_adb_info(ADBSetInfoBlock * info, int adbAddr)
1827 1.19.6.2 nathanw {
1828 1.19.6.2 nathanw int i;
1829 1.19.6.2 nathanw
1830 1.19.6.2 nathanw if ((adbAddr < 1) || (adbAddr > 15)) /* check range 1-15 */
1831 1.19.6.2 nathanw return (-1);
1832 1.19.6.2 nathanw
1833 1.19.6.2 nathanw for (i = 1; i < 15; i++)
1834 1.19.6.2 nathanw if (ADBDevTable[i].currentAddr == adbAddr) {
1835 1.19.6.2 nathanw ADBDevTable[i].ServiceRtPtr =
1836 1.19.6.2 nathanw (void *)(info->siServiceRtPtr);
1837 1.19.6.2 nathanw ADBDevTable[i].DataAreaAddr = info->siDataAreaAddr;
1838 1.19.6.2 nathanw return 0; /* found */
1839 1.19.6.2 nathanw }
1840 1.19.6.2 nathanw
1841 1.19.6.2 nathanw return (-1); /* not found */
1842 1.19.6.2 nathanw
1843 1.19.6.2 nathanw }
1844 1.19.6.2 nathanw
1845 1.19.6.2 nathanw #ifndef MRG_ADB
1846 1.19.6.2 nathanw
1847 1.19.6.2 nathanw /* caller should really use machine-independant version: getPramTime */
1848 1.19.6.2 nathanw /* this version does pseudo-adb access only */
1849 1.19.6.2 nathanw int
1850 1.19.6.2 nathanw adb_read_date_time(unsigned long *time)
1851 1.19.6.2 nathanw {
1852 1.19.6.2 nathanw u_char output[ADB_MAX_MSG_LENGTH];
1853 1.19.6.2 nathanw int result;
1854 1.19.6.2 nathanw volatile int flag = 0;
1855 1.19.6.2 nathanw
1856 1.19.6.2 nathanw switch (adbHardware) {
1857 1.19.6.2 nathanw case ADB_HW_II:
1858 1.19.6.2 nathanw return -1;
1859 1.19.6.2 nathanw
1860 1.19.6.2 nathanw case ADB_HW_IISI:
1861 1.19.6.2 nathanw output[0] = 0x02; /* 2 byte message */
1862 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc device */
1863 1.19.6.2 nathanw output[2] = 0x03; /* read date/time */
1864 1.19.6.2 nathanw result = send_adb_IIsi((u_char *)output, (u_char *)output,
1865 1.19.6.2 nathanw (void *)adb_op_comprout, (int *)&flag, (int)0);
1866 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
1867 1.19.6.2 nathanw return -1;
1868 1.19.6.2 nathanw
1869 1.19.6.2 nathanw while (0 == flag) /* wait for result */
1870 1.19.6.2 nathanw ;
1871 1.19.6.2 nathanw
1872 1.19.6.2 nathanw *time = (long)(*(long *)(output + 1));
1873 1.19.6.2 nathanw return 0;
1874 1.19.6.2 nathanw
1875 1.19.6.2 nathanw case ADB_HW_PB:
1876 1.19.6.2 nathanw pm_read_date_time(time);
1877 1.19.6.2 nathanw return 0;
1878 1.19.6.2 nathanw
1879 1.19.6.2 nathanw case ADB_HW_CUDA:
1880 1.19.6.2 nathanw output[0] = 0x02; /* 2 byte message */
1881 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc device */
1882 1.19.6.2 nathanw output[2] = 0x03; /* read date/time */
1883 1.19.6.2 nathanw result = send_adb_cuda((u_char *)output, (u_char *)output,
1884 1.19.6.2 nathanw (void *)adb_op_comprout, (void *)&flag, (int)0);
1885 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
1886 1.19.6.2 nathanw return -1;
1887 1.19.6.2 nathanw
1888 1.19.6.2 nathanw while (0 == flag) /* wait for result */
1889 1.19.6.2 nathanw ;
1890 1.19.6.2 nathanw
1891 1.19.6.2 nathanw memcpy(time, output + 1, 4);
1892 1.19.6.2 nathanw return 0;
1893 1.19.6.2 nathanw
1894 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1895 1.19.6.2 nathanw default:
1896 1.19.6.2 nathanw return -1;
1897 1.19.6.2 nathanw }
1898 1.19.6.2 nathanw }
1899 1.19.6.2 nathanw
1900 1.19.6.2 nathanw /* caller should really use machine-independant version: setPramTime */
1901 1.19.6.2 nathanw /* this version does pseudo-adb access only */
1902 1.19.6.2 nathanw int
1903 1.19.6.2 nathanw adb_set_date_time(unsigned long time)
1904 1.19.6.2 nathanw {
1905 1.19.6.2 nathanw u_char output[ADB_MAX_MSG_LENGTH];
1906 1.19.6.2 nathanw int result;
1907 1.19.6.2 nathanw volatile int flag = 0;
1908 1.19.6.2 nathanw
1909 1.19.6.2 nathanw switch (adbHardware) {
1910 1.19.6.2 nathanw
1911 1.19.6.2 nathanw case ADB_HW_CUDA:
1912 1.19.6.2 nathanw output[0] = 0x06; /* 6 byte message */
1913 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc device */
1914 1.19.6.2 nathanw output[2] = 0x09; /* set date/time */
1915 1.19.6.2 nathanw output[3] = (u_char)(time >> 24);
1916 1.19.6.2 nathanw output[4] = (u_char)(time >> 16);
1917 1.19.6.2 nathanw output[5] = (u_char)(time >> 8);
1918 1.19.6.2 nathanw output[6] = (u_char)(time);
1919 1.19.6.2 nathanw result = send_adb_cuda((u_char *)output, (u_char *)0,
1920 1.19.6.2 nathanw (void *)adb_op_comprout, (void *)&flag, (int)0);
1921 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
1922 1.19.6.2 nathanw return -1;
1923 1.19.6.2 nathanw
1924 1.19.6.2 nathanw while (0 == flag) /* wait for send to finish */
1925 1.19.6.2 nathanw ;
1926 1.19.6.2 nathanw
1927 1.19.6.2 nathanw return 0;
1928 1.19.6.2 nathanw
1929 1.19.6.2 nathanw case ADB_HW_PB:
1930 1.19.6.2 nathanw pm_set_date_time(time);
1931 1.19.6.2 nathanw return 0;
1932 1.19.6.2 nathanw
1933 1.19.6.2 nathanw case ADB_HW_II:
1934 1.19.6.2 nathanw case ADB_HW_IISI:
1935 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1936 1.19.6.2 nathanw default:
1937 1.19.6.2 nathanw return -1;
1938 1.19.6.2 nathanw }
1939 1.19.6.2 nathanw }
1940 1.19.6.2 nathanw
1941 1.19.6.2 nathanw
1942 1.19.6.2 nathanw int
1943 1.19.6.2 nathanw adb_poweroff(void)
1944 1.19.6.2 nathanw {
1945 1.19.6.2 nathanw u_char output[ADB_MAX_MSG_LENGTH];
1946 1.19.6.2 nathanw int result;
1947 1.19.6.2 nathanw
1948 1.19.6.2 nathanw if (!adbSoftPower)
1949 1.19.6.2 nathanw return -1;
1950 1.19.6.2 nathanw
1951 1.19.6.2 nathanw adb_polling = 1;
1952 1.19.6.2 nathanw
1953 1.19.6.2 nathanw switch (adbHardware) {
1954 1.19.6.2 nathanw case ADB_HW_IISI:
1955 1.19.6.2 nathanw output[0] = 0x02; /* 2 byte message */
1956 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc/soft-power device */
1957 1.19.6.2 nathanw output[2] = 0x0a; /* set date/time */
1958 1.19.6.2 nathanw result = send_adb_IIsi((u_char *)output, (u_char *)0,
1959 1.19.6.2 nathanw (void *)0, (void *)0, (int)0);
1960 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
1961 1.19.6.2 nathanw return -1;
1962 1.19.6.2 nathanw
1963 1.19.6.2 nathanw for (;;); /* wait for power off */
1964 1.19.6.2 nathanw
1965 1.19.6.2 nathanw return 0;
1966 1.19.6.2 nathanw
1967 1.19.6.2 nathanw case ADB_HW_PB:
1968 1.19.6.2 nathanw pm_adb_poweroff();
1969 1.19.6.2 nathanw
1970 1.19.6.2 nathanw for (;;); /* wait for power off */
1971 1.19.6.2 nathanw
1972 1.19.6.2 nathanw return 0;
1973 1.19.6.2 nathanw
1974 1.19.6.2 nathanw case ADB_HW_CUDA:
1975 1.19.6.2 nathanw output[0] = 0x02; /* 2 byte message */
1976 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc/soft-power device */
1977 1.19.6.2 nathanw output[2] = 0x0a; /* set date/time */
1978 1.19.6.2 nathanw result = send_adb_cuda((u_char *)output, (u_char *)0,
1979 1.19.6.2 nathanw (void *)0, (void *)0, (int)0);
1980 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
1981 1.19.6.2 nathanw return -1;
1982 1.19.6.2 nathanw
1983 1.19.6.2 nathanw for (;;); /* wait for power off */
1984 1.19.6.2 nathanw
1985 1.19.6.2 nathanw return 0;
1986 1.19.6.2 nathanw
1987 1.19.6.2 nathanw case ADB_HW_II: /* II models don't do ADB soft power */
1988 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
1989 1.19.6.2 nathanw default:
1990 1.19.6.2 nathanw return -1;
1991 1.19.6.2 nathanw }
1992 1.19.6.2 nathanw }
1993 1.19.6.2 nathanw
1994 1.19.6.2 nathanw int
1995 1.19.6.2 nathanw adb_prog_switch_enable(void)
1996 1.19.6.2 nathanw {
1997 1.19.6.2 nathanw u_char output[ADB_MAX_MSG_LENGTH];
1998 1.19.6.2 nathanw int result;
1999 1.19.6.2 nathanw volatile int flag = 0;
2000 1.19.6.2 nathanw
2001 1.19.6.2 nathanw switch (adbHardware) {
2002 1.19.6.2 nathanw case ADB_HW_IISI:
2003 1.19.6.2 nathanw output[0] = 0x03; /* 3 byte message */
2004 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc/soft-power device */
2005 1.19.6.2 nathanw output[2] = 0x1c; /* prog. switch control */
2006 1.19.6.2 nathanw output[3] = 0x01; /* enable */
2007 1.19.6.2 nathanw result = send_adb_IIsi((u_char *)output, (u_char *)0,
2008 1.19.6.2 nathanw (void *)adb_op_comprout, (void *)&flag, (int)0);
2009 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
2010 1.19.6.2 nathanw return -1;
2011 1.19.6.2 nathanw
2012 1.19.6.2 nathanw while (0 == flag) /* wait for send to finish */
2013 1.19.6.2 nathanw ;
2014 1.19.6.2 nathanw
2015 1.19.6.2 nathanw return 0;
2016 1.19.6.2 nathanw
2017 1.19.6.2 nathanw case ADB_HW_PB:
2018 1.19.6.2 nathanw return -1;
2019 1.19.6.2 nathanw
2020 1.19.6.2 nathanw case ADB_HW_II: /* II models don't do prog. switch */
2021 1.19.6.2 nathanw case ADB_HW_CUDA: /* cuda doesn't do prog. switch TO DO: verify this */
2022 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
2023 1.19.6.2 nathanw default:
2024 1.19.6.2 nathanw return -1;
2025 1.19.6.2 nathanw }
2026 1.19.6.2 nathanw }
2027 1.19.6.2 nathanw
2028 1.19.6.2 nathanw int
2029 1.19.6.2 nathanw adb_prog_switch_disable(void)
2030 1.19.6.2 nathanw {
2031 1.19.6.2 nathanw u_char output[ADB_MAX_MSG_LENGTH];
2032 1.19.6.2 nathanw int result;
2033 1.19.6.2 nathanw volatile int flag = 0;
2034 1.19.6.2 nathanw
2035 1.19.6.2 nathanw switch (adbHardware) {
2036 1.19.6.2 nathanw case ADB_HW_IISI:
2037 1.19.6.2 nathanw output[0] = 0x03; /* 3 byte message */
2038 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc/soft-power device */
2039 1.19.6.2 nathanw output[2] = 0x1c; /* prog. switch control */
2040 1.19.6.2 nathanw output[3] = 0x01; /* disable */
2041 1.19.6.2 nathanw result = send_adb_IIsi((u_char *)output, (u_char *)0,
2042 1.19.6.2 nathanw (void *)adb_op_comprout, (void *)&flag, (int)0);
2043 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
2044 1.19.6.2 nathanw return -1;
2045 1.19.6.2 nathanw
2046 1.19.6.2 nathanw while (0 == flag) /* wait for send to finish */
2047 1.19.6.2 nathanw ;
2048 1.19.6.2 nathanw
2049 1.19.6.2 nathanw return 0;
2050 1.19.6.2 nathanw
2051 1.19.6.2 nathanw case ADB_HW_PB:
2052 1.19.6.2 nathanw return -1;
2053 1.19.6.2 nathanw
2054 1.19.6.2 nathanw case ADB_HW_II: /* II models don't do prog. switch */
2055 1.19.6.2 nathanw case ADB_HW_CUDA: /* cuda doesn't do prog. switch */
2056 1.19.6.2 nathanw case ADB_HW_UNKNOWN:
2057 1.19.6.2 nathanw default:
2058 1.19.6.2 nathanw return -1;
2059 1.19.6.2 nathanw }
2060 1.19.6.2 nathanw }
2061 1.19.6.2 nathanw
2062 1.19.6.2 nathanw int
2063 1.19.6.2 nathanw CountADBs(void)
2064 1.19.6.2 nathanw {
2065 1.19.6.2 nathanw return (count_adbs());
2066 1.19.6.2 nathanw }
2067 1.19.6.2 nathanw
2068 1.19.6.2 nathanw void
2069 1.19.6.2 nathanw ADBReInit(void)
2070 1.19.6.2 nathanw {
2071 1.19.6.2 nathanw adb_reinit();
2072 1.19.6.2 nathanw }
2073 1.19.6.2 nathanw
2074 1.19.6.2 nathanw int
2075 1.19.6.2 nathanw GetIndADB(ADBDataBlock * info, int index)
2076 1.19.6.2 nathanw {
2077 1.19.6.2 nathanw return (get_ind_adb_info(info, index));
2078 1.19.6.2 nathanw }
2079 1.19.6.2 nathanw
2080 1.19.6.2 nathanw int
2081 1.19.6.2 nathanw GetADBInfo(ADBDataBlock * info, int adbAddr)
2082 1.19.6.2 nathanw {
2083 1.19.6.2 nathanw return (get_adb_info(info, adbAddr));
2084 1.19.6.2 nathanw }
2085 1.19.6.2 nathanw
2086 1.19.6.2 nathanw int
2087 1.19.6.2 nathanw SetADBInfo(ADBSetInfoBlock * info, int adbAddr)
2088 1.19.6.2 nathanw {
2089 1.19.6.2 nathanw return (set_adb_info(info, adbAddr));
2090 1.19.6.2 nathanw }
2091 1.19.6.2 nathanw
2092 1.19.6.2 nathanw int
2093 1.19.6.2 nathanw ADBOp(Ptr buffer, Ptr compRout, Ptr data, short commandNum)
2094 1.19.6.2 nathanw {
2095 1.19.6.2 nathanw return (adb_op(buffer, compRout, data, commandNum));
2096 1.19.6.2 nathanw }
2097 1.19.6.2 nathanw
2098 1.19.6.2 nathanw #endif
2099 1.19.6.2 nathanw
2100 1.19.6.2 nathanw int
2101 1.19.6.2 nathanw setsoftadb()
2102 1.19.6.2 nathanw {
2103 1.19.6.2 nathanw callout_reset(&adb_soft_intr_ch, 1, (void *)adb_soft_intr, NULL);
2104 1.19.6.2 nathanw return 0;
2105 1.19.6.2 nathanw }
2106 1.19.6.2 nathanw
2107 1.19.6.2 nathanw void
2108 1.19.6.2 nathanw adb_cuda_autopoll()
2109 1.19.6.2 nathanw {
2110 1.19.6.2 nathanw volatile int flag = 0;
2111 1.19.6.2 nathanw int result;
2112 1.19.6.2 nathanw u_char output[16];
2113 1.19.6.2 nathanw
2114 1.19.6.2 nathanw output[0] = 0x03; /* 3-byte message */
2115 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc device */
2116 1.19.6.2 nathanw output[2] = 0x01; /* cuda autopoll */
2117 1.19.6.2 nathanw output[3] = 0x01;
2118 1.19.6.2 nathanw result = send_adb_cuda(output, output, adb_op_comprout, (void *)&flag,
2119 1.19.6.2 nathanw 0);
2120 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
2121 1.19.6.2 nathanw return;
2122 1.19.6.2 nathanw
2123 1.19.6.2 nathanw while (flag == 0); /* wait for result */
2124 1.19.6.2 nathanw }
2125 1.19.6.2 nathanw
2126 1.19.6.2 nathanw void
2127 1.19.6.2 nathanw adb_restart(void)
2128 1.19.6.2 nathanw {
2129 1.19.6.2 nathanw int result;
2130 1.19.6.2 nathanw u_char output[16];
2131 1.19.6.2 nathanw
2132 1.19.6.2 nathanw adb_polling = 1;
2133 1.19.6.2 nathanw
2134 1.19.6.2 nathanw switch (adbHardware) {
2135 1.19.6.2 nathanw case ADB_HW_CUDA:
2136 1.19.6.2 nathanw output[0] = 0x02; /* 2 byte message */
2137 1.19.6.2 nathanw output[1] = 0x01; /* to pram/rtc/soft-power device */
2138 1.19.6.2 nathanw output[2] = 0x11; /* restart */
2139 1.19.6.2 nathanw result = send_adb_cuda(output, NULL, NULL, NULL, 0);
2140 1.19.6.2 nathanw if (result != 0) /* exit if not sent */
2141 1.19.6.2 nathanw return;
2142 1.19.6.2 nathanw while (1); /* not return */
2143 1.19.6.2 nathanw
2144 1.19.6.2 nathanw case ADB_HW_PB:
2145 1.19.6.2 nathanw pm_adb_restart();
2146 1.19.6.2 nathanw while (1); /* not return */
2147 1.19.6.2 nathanw }
2148 1.19.6.2 nathanw }
2149