Date: Mon, 1 Jun 1998 11:40:13 +0200 (CEST)
From: Geert Uytterhoeven <Geert.Uytterhoeven@cs.kuleuven.ac.be>
To: Linux/m68k <linux-m68k@lists.linux-m68k.org>
Subject: L68K: CD1200 controller diff (fwd)
Sender: owner-linux-m68k@phil.uni-sb.de


The patch is for 2.0.x.

---------- Forwarded message ----------
Date: 30 May 98 13:46:46 +0000
From: Andreas Kemnade <akemnade@t-online.de>
To: Geert.Uytterhoeven@cs.kuleuven.ac.be
Subject: CD1200 controller diff


I have cleaned up my code and added proper detection.
Here is the diff:


--- drivers/block/ide.c.orig  Thu Sep 11 23:19:28 1997
+++ drivers/block/ide.c Sat May 30 09:50:50 1998
@@ -302,7 +302,6 @@
 #include <asm/irq.h>
 #include <asm/segment.h>
 #include <asm/io.h>
-
 #ifdef CONFIG_PCI
 #include <linux/bios32.h>
 #include <linux/pci.h>
@@ -310,7 +309,9 @@
 
 #include "ide.h"
 #include "ide_modes.h"
-
+#ifdef CONFIG_CD1200
+#include <asm/amipcmcia.h>
+#endif /* CONFIG_CD1200 */
 #ifdef CONFIG_BLK_DEV_PROMISE
 #include "promise.h"
 #define IS_PROMISE_DRIVE (HWIF(drive)->chipset == ide_promise)
@@ -2006,12 +2007,28 @@
      unsigned char ch;
      ide_drive_t *drive = hwgroup->drive;
      ch = inb(IDE_IRQ_REG);
+#ifdef CONFIG_CD1200
+                if (!(ch & 0x84))
+        return;
+                if ((AMIGAHW_PRESENT(A1200_IDE))&&(ch &0x80)) {
+                        
+                        (void) GET_STAT();
+                        outb(0x7c | (ch & 0x03), IDE_IRQ_REG);
+                 }
+                if (ch & 0x04)
+                          {
+                                pcmcia_ack_int(ch);
+                          }
+                
+#else
      if (!(ch & 0x80))
         return;
      if (AMIGAHW_PRESENT(A1200_IDE)) {
         (void) GET_STAT();
         outb(0x7c | (ch & 0x03), IDE_IRQ_REG);
      }
+#endif
+
   }
 #endif /* CONFIG_AMIGA */
 
@@ -3770,6 +3787,40 @@
 #endif /* CONFIG_PCI */
 
 #ifdef CONFIG_AMIGA
+#ifdef CONFIG_CD1200
+static void probe_cd1200 (void)
+{
+        static long tuple[4];
+        static long cd1200altstatus = 0L;
+        ide_hwif_t *hwif = &ide_hwifs[1];
+        
+        if (PCMCIA_INSERTED) {
+               pcmcia_access_speed(PCMCIA_SPEED_250NS);
+               pcmcia_copy_tuple(CISTPL_LINKTARGET,&tuple[0],12);
+               if ((tuple[1]!=0x41420041)||(tuple[2]>>24!=0x54)) {
+                  hwif->noprobe=1;
+                  return;
+               }
+        } 
+        else {
+    hwif->noprobe=1;
+          return;
+        }
+        printk("CD1200 controller detected\n");
+  hwif->io_base = (unsigned char *)ZTWO_VADDR(0xa21000);
+        hwif->hd_regs.hd_error   = hwif->io_base + 0x200; /* ? */
+        hwif->hd_regs.hd_nsector = hwif->io_base + 0x400; /* ? */
+        hwif->hd_regs.hd_sector  = hwif->io_base + 0x600; /* ? */
+        hwif->hd_regs.hd_lcyl    = hwif->io_base + 0x800;
+        hwif->hd_regs.hd_hcyl    = hwif->io_base + 0xa00;
+        hwif->hd_regs.hd_select  = hwif->io_base + 0xc00;
+        hwif->hd_regs.hd_status  = hwif->io_base + 0xe00;
+        hwif->ctl_port           = &cd1200altstatus;
+        pcmcia_write_enable(); 
+        hwif->irq = IRQ_AMIGA_PORTS;
+        hwif->hd_regs.hd_irq = (unsigned char *)ZTWO_VADDR(HD_A1200_IRQ);
+}
+#endif /* CONFIG_CD1200 */
 static void ide_probe_amiga (void)
 {
   ide_hwif_t *hwif = &ide_hwifs[0];
@@ -3807,6 +3858,9 @@
 
   /* Disable interrupt for probing */
   disable_irq(hwif->irq);
+#ifdef CONFIG_CD1200
+  probe_cd1200();
+#endif /* CONFIG_CD1200 */
 }
 #endif /* CONFIG_AMIGA */
 
@@ -3953,11 +4007,17 @@
      printk("%s: UNABLE TO GET IRQ %d\n", hwif->name, hwif->irq);
      (void) unregister_blkdev (hwif->major, hwif->name);
   } else {
+#ifdef CONFIG_CD1200
+                pcmcia_enable_irq();
+#endif 
      init_gendisk(hwif);
      blk_dev[hwif->major].request_fn = rfn;
      read_ahead[hwif->major] = 8;  /* (4kB) */
      hwif->present = 1;   /* success */
-  }
+#ifdef CONFIG_CD1200
+                pcmcia_disable_irq();
+#endif  
+        }
 #ifdef __mc68000__
   if (post_ident_reset) {
       printk("ide: Doing a post identification reset...\n");
@@ -3988,7 +4048,9 @@
      probe_hwif (&ide_hwifs[index]);
   for (index = 0; index < MAX_HWIFS; ++index)
      hwif_init (index);
-
+#ifdef CONFIG_CD1200
+        pcmcia_enable_irq();
+#endif
 #ifdef CONFIG_BLK_DEV_IDETAPE
   idetape_register_chrdev(); /* Register character device interface to the ide tape */
 #endif /* CONFIG_BLK_DEV_IDETAPE */
--- drivers/block/ide-cd.c.orig  Thu Sep 11 23:19:25 1997
+++ drivers/block/ide-cd.c Thu May 28 18:50:46 1998
@@ -702,7 +702,10 @@
 
   if (OK_STAT (stat, good_stat, BAD_R_STAT))
      return 0;
-
+#ifdef CONFIG_CD1200
+        if (stat==0xd0)
+     return 0;
+#endif
   /* Got an error. */
   err = IN_BYTE (IDE_ERROR_REG);
   sense_key = err >> 4;
--- include/asm-m68k/ide.h.orig  Tue May 26 19:13:52 1998
+++ include/asm-m68k/ide.h Fri May 29 17:54:14 1998
@@ -28,7 +28,10 @@
 #ifndef MAX_HWIFS
 #define MAX_HWIFS   1
 #endif
-
+#ifdef CONFIG_CD1200
+#undef MAX_HWIFS
+#define MAX_HWIFS 2
+#endif /* CONFIG_CD1200 */
 #undef SUPPORT_VLB_SYNC
 #define SUPPORT_VLB_SYNC 0
 #undef SUPPORT_SLOW_DATA_PORTS
--- arch/m68k/config.in.orig  Wed Dec 17 13:08:04 1997
+++ arch/m68k/config.in Fri May 29 17:42:04 1998
@@ -83,6 +83,11 @@
 bool 'IDE harddisk support' CONFIG_BLK_DEV_IDE
 if [ "$CONFIG_BLK_DEV_IDE" = "y" ]; then
   bool '   Include IDE/ATAPI CDROM support' CONFIG_BLK_DEV_IDECD
+  if [ "$CONFIG_AMIGA_PCMCIA" = "y" ]; then
+    if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+      bool '   PCMCIA CD1200 support' CONFIG_CD1200
+    fi
+  fi
 fi
 if [ "$CONFIG_AMIGA" = "y" ]; then
 tristate 'Amiga Zorro II ramdisk support' CONFIG_AMIGA_Z2RAM

