Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/mac68k/dev Stabilize ADB support for some non-Apple...



details:   https://anonhg.NetBSD.org/src/rev/5a5a3bd8e0d1
branches:  trunk
changeset: 494189:5a5a3bd8e0d1
user:      scottr <scottr%NetBSD.org@localhost>
date:      Mon Jul 03 08:59:26 2000 +0000

description:
Stabilize ADB support for some non-Apple ADB peripherals.  This is the
second (and final) part of the fix for PR 10086.  (There are no longer
any infinite-wait busy loops in the ADB driver!)

diffstat:

 sys/arch/mac68k/dev/adb.c        |   63 ++++++++++++++++++++-
 sys/arch/mac68k/dev/adb_direct.c |  109 ++++++++++-------------------------
 sys/arch/mac68k/dev/adbvar.h     |    5 +-
 sys/arch/mac68k/dev/akbd.c       |   59 +++++-------------
 sys/arch/mac68k/dev/ams.c        |  119 +++++++++++++-------------------------
 sys/arch/mac68k/dev/pm_direct.c  |   44 ++++++-------
 6 files changed, 178 insertions(+), 221 deletions(-)

diffs (truncated from 751 to 300 lines):

diff -r 52d14e9b0295 -r 5a5a3bd8e0d1 sys/arch/mac68k/dev/adb.c
--- a/sys/arch/mac68k/dev/adb.c Mon Jul 03 08:55:14 2000 +0000
+++ b/sys/arch/mac68k/dev/adb.c Mon Jul 03 08:59:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adb.c,v 1.36 2000/06/18 22:58:45 scottr Exp $  */
+/*     $NetBSD: adb.c,v 1.37 2000/07/03 08:59:26 scottr Exp $  */
 
 /*
  * Copyright (C) 1994  Bradley A. Grantham
@@ -255,3 +255,64 @@
 
        return (rv);
 }
+
+
+/*
+ * adb_op_sync
+ *
+ * This routine does exactly what the adb_op routine does, except that after
+ * the adb_op is called, it waits until the return value is present before
+ * returning.
+ *
+ * NOTE: The user specified compRout is ignored, since this routine specifies
+ * it's own to adb_op, which is why you really called this in the first place
+ * anyway.
+ */
+int
+adb_op_sync(Ptr buffer, Ptr compRout, Ptr data, short command)
+{
+       int tmout;
+       int result;
+       volatile int flag = 0;
+
+       result = ADBOp(buffer, (void *)adb_op_comprout,
+           (void *)&flag, command);    /* send command */
+       if (result == 0) {              /* send ok? */
+               /*
+                * Total time to wait is calculated as follows:
+                *  - Tlt (stop to start time): 260 usec
+                *  - start bit: 100 usec
+                *  - up to 8 data bytes: 64 * 100 usec = 6400 usec
+                *  - stop bit (with SRQ): 140 usec
+                * Total: 6900 usec
+                */
+               tmout = 6900;
+               for (tmout = 6900; !flag && tmout >= 10; tmout -= 10)
+                       delay(10);
+               if (!flag && tmout > 0)
+                       delay(tmout);
+
+               if (!flag)
+                       result = -2;
+       }
+
+       return result;
+}
+
+
+/*
+ * adb_op_comprout
+ *
+ * This function is used by the adb_op_sync routine so it knows when the
+ * function is done.
+ */
+void 
+adb_op_comprout(void)
+{
+#ifdef __NetBSD__
+       asm("movw       #1,a2@                  | update flag value");
+#else                          /* for macos based testing */
+       asm {
+               move.w #1,(a2) }                /* update flag value */
+#endif
+}
diff -r 52d14e9b0295 -r 5a5a3bd8e0d1 sys/arch/mac68k/dev/adb_direct.c
--- a/sys/arch/mac68k/dev/adb_direct.c  Mon Jul 03 08:55:14 2000 +0000
+++ b/sys/arch/mac68k/dev/adb_direct.c  Mon Jul 03 08:59:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adb_direct.c,v 1.42 2000/03/23 06:39:55 thorpej Exp $  */
+/*     $NetBSD: adb_direct.c,v 1.43 2000/07/03 08:59:26 scottr Exp $   */
 
 /* From: adb_direct.c 2.02 4/18/97 jpw */
 
@@ -303,7 +303,6 @@
 int    set_adb_info __P((ADBSetInfoBlock *, int));
 void   adb_setup_hw_type __P((void));
 int    adb_op __P((Ptr, Ptr, Ptr, short));
-int    adb_op_sync __P((Ptr, Ptr, Ptr, short));
 void   adb_read_II __P((u_char *));
 void   adb_hw_setup __P((void));
 void   adb_hw_setup_IIsi __P((u_char *));
@@ -2120,8 +2119,10 @@
         * Initialize the ADB table.  For now, we'll always use the same table
         * that is defined at the beginning of this file - no mallocs.
         */
-       for (i = 0; i < 16; i++)
+       for (i = 0; i < 16; i++) {
                ADBDevTable[i].devType = 0;
+               ADBDevTable[i].origAddr = ADBDevTable[i].currentAddr = 0;
+       }
 
        adb_setup_hw_type();    /* setup hardware type */
 
@@ -2130,7 +2131,7 @@
        delay(1000);
 
        /* send an ADB reset first */
-       adb_op_sync((Ptr)0, (Ptr)0, (Ptr)0, (short)0x00);
+       (void)adb_op_sync((Ptr)0, (Ptr)0, (Ptr)0, (short)0x00);
        delay(3000);
 
        /*
@@ -2156,16 +2157,7 @@
                result = adb_op_sync((Ptr)send_string, (Ptr)0,
                    (Ptr)0, (short)command);
 
-               if (send_string[0] != 0) {
-                       /* check for valid device handler */
-                       switch (send_string[2]) {
-                       case 0:
-                       case 0xfd:
-                       case 0xfe:
-                       case 0xff:
-                               continue;       /* invalid, skip */
-                       }
-
+               if (result == 0 && send_string[0] != 0) {
                        /* found a device */
                        ++ADBNumDevices;
                        KASSERT(ADBNumDevices < 16);
@@ -2195,7 +2187,7 @@
 
        nonewtimes = 0;         /* no loops w/o new devices */
        while (saveptr > 0 && nonewtimes++ < 11) {
-               for (i = 1; i <= ADBNumDevices; i++) {
+               for (i = 1;saveptr > 0 && i <= ADBNumDevices; i++) {
                        device = ADBDevTable[i].currentAddr;
 #ifdef ADB_DEBUG
                        if (adb_debug & 0x80)
@@ -2205,7 +2197,7 @@
 
                        /* send TALK R3 to address */
                        command = ADBTALK(device, 3);
-                       adb_op_sync((Ptr)send_string, (Ptr)0,
+                       (void)adb_op_sync((Ptr)send_string, (Ptr)0,
                            (Ptr)0, (short)command);
 
                        /* move device to higher address */
@@ -2213,38 +2205,43 @@
                        send_string[0] = 2;
                        send_string[1] = (u_char)(saveptr | 0x60);
                        send_string[2] = 0xfe;
-                       adb_op_sync((Ptr)send_string, (Ptr)0,
+                       (void)adb_op_sync((Ptr)send_string, (Ptr)0,
                            (Ptr)0, (short)command);
-                       delay(500);
+                       delay(1000);
 
                        /* send TALK R3 - anthing at new address? */
                        command = ADBTALK(saveptr, 3);
-                       adb_op_sync((Ptr)send_string, (Ptr)0,
+                       send_string[0] = 0;
+                       result = adb_op_sync((Ptr)send_string, (Ptr)0,
                            (Ptr)0, (short)command);
-                       delay(500);
-
-                       if (send_string[0] == 0) {
+                       delay(1000);
+
+                       if (result != 0 || send_string[0] == 0) {
+                               /*
+                                * maybe there's a communication breakdown;
+                                * just in case, move it back from whence it
+                                * came, and we'll try again later
+                                */
+                               command = ADBLISTEN(saveptr, 3);
+                               send_string[0] = 2;
+                               send_string[1] = (u_char)(device | 0x60);
+                               send_string[2] = 0x00;
+                               (void)adb_op_sync((Ptr)send_string, (Ptr)0,
+                                   (Ptr)0, (short)command);
 #ifdef ADB_DEBUG
                                if (adb_debug & 0x80)
                                        printf_intr("failed, continuing\n");
 #endif
+                               delay(1000);
                                continue;
                        }
 
                        /* send TALK R3 - anything at old address? */
                        command = ADBTALK(device, 3);
+                       send_string[0] = 0;
                        result = adb_op_sync((Ptr)send_string, (Ptr)0,
                            (Ptr)0, (short)command);
-                       if (send_string[0] != 0) {
-                               /* check for valid device handler */
-                               switch (send_string[2]) {
-                               case 0:
-                               case 0xfd:
-                               case 0xfe:
-                               case 0xff:
-                                       continue;       /* invalid, skip */
-                               }
-
+                       if (result == 0 && send_string[0] != 0) {
                                /* new device found */
                                /* update data for previously moved device */
                                ADBDevTable[i].currentAddr = saveptr;
@@ -2298,7 +2295,7 @@
                                send_string[0] = 2;
                                send_string[1] = (u_char)(device | 0x60);
                                send_string[2] = 0xfe;
-                               adb_op_sync((Ptr)send_string, (Ptr)0,
+                               (void)adb_op_sync((Ptr)send_string, (Ptr)0,
                                    (Ptr)0, (short)command);
                                delay(1000);
                        }
@@ -2463,50 +2460,6 @@
 }
 
 
-/*
- * adb_op_sync
- *
- * This routine does exactly what the adb_op routine does, except that after
- * the adb_op is called, it waits until the return value is present before
- * returning.
- *
- * NOTE: The user specified compRout is ignored, since this routine specifies
- * it's own to adb_op, which is why you really called this in the first place
- * anyway.
- */
-int
-adb_op_sync(Ptr buffer, Ptr compRout, Ptr data, short command)
-{
-       int result;
-       volatile int flag = 0;
-
-       result = adb_op(buffer, (void *)adb_op_comprout,
-           (void *)&flag, command);    /* send command */
-       if (result == 0)                /* send ok? */
-               while (0 == flag)
-                       /* wait for compl. routine */;
-
-       return result;
-}
-
-
-/*
- * adb_op_comprout
- *
- * This function is used by the adb_op_sync routine so it knows when the
- * function is done.
- */
-void 
-adb_op_comprout(void)
-{
-#ifdef __NetBSD__
-       asm("movw       #1,a2@                  | update flag value");
-#else                          /* for macos based testing */
-       asm {
-               move.w #1,(a2) }                /* update flag value */
-#endif
-}
-
 void 
 adb_setup_hw_type(void)
 {
@@ -2657,7 +2610,7 @@
        found = 0;
 
        for (i = 1; i < 16; i++)
-               if (0 != ADBDevTable[i].devType)
+               if (0 != ADBDevTable[i].currentAddr)
                        found++;
 
        return found;
diff -r 52d14e9b0295 -r 5a5a3bd8e0d1 sys/arch/mac68k/dev/adbvar.h
--- a/sys/arch/mac68k/dev/adbvar.h      Mon Jul 03 08:55:14 2000 +0000
+++ b/sys/arch/mac68k/dev/adbvar.h      Mon Jul 03 08:59:26 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adbvar.h,v 1.18 2000/03/19 07:44:58 scottr Exp $       */
+/*     $NetBSD: adbvar.h,v 1.19 2000/07/03 08:59:27 scottr Exp $       */
 
 /*
  * Copyright (C) 1994  Bradley A. Grantham
@@ -73,6 +73,9 @@
 int    adbioctl __P((dev_t , int , caddr_t , int , struct proc *));
 int    adbpoll __P((dev_t dev, int events, struct proc *p));
 
+int    adb_op_sync __P((Ptr, Ptr, Ptr, short));
+void   adb_op_comprout __P((void));
+
 /* adbsysasm.s */
 void   adb_kbd_asmcomplete __P((void));
 void   adb_ms_asmcomplete __P((void));
diff -r 52d14e9b0295 -r 5a5a3bd8e0d1 sys/arch/mac68k/dev/akbd.c
--- a/sys/arch/mac68k/dev/akbd.c        Mon Jul 03 08:55:14 2000 +0000
+++ b/sys/arch/mac68k/dev/akbd.c        Mon Jul 03 08:59:26 2000 +0000
@@ -1,4 +1,4 @@



Home | Main Index | Thread Index | Old Index