devide: Add the ability to have a mix of 8 and 16bit interfaces
authorAlan Cox <alan@linux.intel.com>
Sun, 19 Aug 2018 14:18:51 +0000 (15:18 +0100)
committerAlan Cox <alan@linux.intel.com>
Sun, 19 Aug 2018 14:18:51 +0000 (15:18 +0100)
The SAM we need to do this and RC2014 will also eventually need it.

Kernel/dev/devide.h
Kernel/dev/devide_discard.c

index 7e35034..0f56abd 100644 (file)
@@ -12,7 +12,8 @@
    supports (at most 16) - defaults to 2 if undefined.
 
    Define IDE_8BIT_ONLY if the system implements only half of the 16-bit data
-   bus (eg n8vem-mark4).
+   bus (eg n8vem-mark4). You can define IDE_IS_8BIT(iface) if you have a mix
+   of types. FIXME: we should rename IDE_8BIT_ONLY.
 
    Define IDE_REG_INDIRECT if the IDE registers are not directly addressable on
    your platform. If you do not define IDE_REG_INDIRECT then IDE registers
@@ -101,6 +102,11 @@ void devide_writeb(uint8_t regaddr, uint8_t value);
 #define IDE_DRIVE_COUNT 2       /* at most 16 drives without adjusting IDE_DRIVE_NR_MASK */
 #endif
 
+/* Only used when 8BIT_ONLY defined */
+#ifndef IDE_IS_8BIT
+#define IDE_IS_8BIT(x) (1)
+#endif
+
 /* we use the bits in the driver_data field of blkdev_t as follows: */
 #define FLAG_CACHE_DIRTY 0x40
 #define FLAG_WRITE_CACHE 0x80
index c9e52e6..f10b481 100644 (file)
@@ -71,16 +71,18 @@ void devide_init_drive(uint8_t drive)
     kprintf("IDE drive %d: ", drive);
 
 #ifdef IDE_8BIT_ONLY
+    if (IDE_IS_8BIT(drive)) {
     /* set 8-bit mode -- mostly only supported by CF cards */
-    if (!devide_wait(IDE_STATUS_READY))
-        goto out;
+        if (!devide_wait(IDE_STATUS_READY))
+            goto out;
 
-    devide_writeb(ide_reg_devhead, select);
-    if (!devide_wait(IDE_STATUS_READY))
-        goto out;
+        devide_writeb(ide_reg_devhead, select);
+        if (!devide_wait(IDE_STATUS_READY))
+            goto out;
 
-    devide_writeb(ide_reg_features, 0x01); /* Enable 8-bit PIO transfer mode (CFA feature set only) */
-    devide_writeb(ide_reg_command, IDE_CMD_SET_FEATURES);
+        devide_writeb(ide_reg_features, 0x01); /* Enable 8-bit PIO transfer mode (CFA feature set only) */
+        devide_writeb(ide_reg_command, IDE_CMD_SET_FEATURES);
+    }
 #endif
 
     /* confirm drive has LBA support */