[PATCH] update board config for jupiter Board:
[oweals/u-boot.git] / common / cmd_ace.c
index 555fbe398821b833e4d33c56f02f8e536b213bdf..b6d61057fdebe10e34a80d9746f0ede1a758c565 100644 (file)
  * available to cmd_fat.c:get_dev and filling in a block device
  * description that has all the bits needed for FAT support to
  * read sectors.
+ *
+ * According to Xilinx technical support, before accessing the
+ * SystemACE CF you need to set the following control bits:
+ *     FORCECFGMODE : 1
+ *     CFGMODE : 0
+ *     CFGSTART : 0
  */
 
 # include  <common.h>
  */
 static unsigned ace_readw(unsigned offset)
 {
-      return readw(CFG_SYSTEMACE_BASE+offset);
+#if (CFG_SYSTEMACE_WIDTH == 8)
+  u16 temp;
+
+#if !defined(__BIG_ENDIAN)
+  temp =((u16)readb(CFG_SYSTEMACE_BASE+offset) << 8);
+  temp |= (u16)readb(CFG_SYSTEMACE_BASE+offset+1);
+#else
+  temp = (u16)readb(CFG_SYSTEMACE_BASE+offset);
+  temp |=((u16)readb(CFG_SYSTEMACE_BASE+offset+1) << 8);
+#endif
+  return temp;
+#else
+  return readw(CFG_SYSTEMACE_BASE+offset);
+#endif
 }
 
-static unsigned ace_writew(unsigned val, unsigned offset)
+static void ace_writew(unsigned val, unsigned offset)
 {
-      writew(val, CFG_SYSTEMACE_BASE+offset);
+#if (CFG_SYSTEMACE_WIDTH == 8)
+#if !defined(__BIG_ENDIAN)
+  writeb((u8)(val>>8), CFG_SYSTEMACE_BASE+offset);
+  writeb((u8)val, CFG_SYSTEMACE_BASE+offset+1);
+#else
+  writeb((u8)val, CFG_SYSTEMACE_BASE+offset);
+  writeb((u8)(val>>8), CFG_SYSTEMACE_BASE+offset+1);
+#endif
+#else
+  writew(val, CFG_SYSTEMACE_BASE+offset);
+#endif
 }
 
 /* */
@@ -72,7 +101,9 @@ static int get_cf_lock(void)
       int retry = 10;
 
        /* CONTROLREG = LOCKREG */
-      ace_writew(0x0002, 0x18);
+      unsigned val=ace_readw(0x18);
+      val|=0x0002;
+      ace_writew((val&0xffff), 0x18);
 
        /* Wait for MPULOCK in STATUSREG[15:0] */
       while (! (ace_readw(0x04) & 0x0002)) {
@@ -89,8 +120,9 @@ static int get_cf_lock(void)
 
 static void release_cf_lock(void)
 {
-       /* CONTROLREG = none */
-      ace_writew(0x0000, 0x18);
+       unsigned val=ace_readw(0x18);
+       val&=~(0x0002);
+       ace_writew((val&0xffff), 0x18);
 }
 
 block_dev_desc_t *  systemace_get_dev(int dev)
@@ -99,11 +131,15 @@ block_dev_desc_t *  systemace_get_dev(int dev)
           not yet initialized. In that case, fill it in. */
       if (systemace_dev.blksz == 0) {
            systemace_dev.if_type   = IF_TYPE_UNKNOWN;
+           systemace_dev.dev       = 0;
            systemace_dev.part_type = PART_TYPE_UNKNOWN;
            systemace_dev.type      = DEV_TYPE_HARDDISK;
            systemace_dev.blksz     = 512;
            systemace_dev.removable = 1;
            systemace_dev.block_read = systemace_read;
+
+           init_part(&systemace_dev);
+
       }
 
       return &systemace_dev;
@@ -119,9 +155,10 @@ static unsigned long systemace_read(int dev,
                                    unsigned long blkcnt,
                                    unsigned long *buffer)
 {
-      unsigned val;
       int retry;
+      unsigned blk_countdown;
       unsigned char*dp = (unsigned char*)buffer;
+      unsigned val;
 
       if (get_cf_lock() < 0) {
            unsigned status = ace_readw(0x04);
@@ -136,9 +173,13 @@ static unsigned long systemace_read(int dev,
            return 0;
       }
 
+#ifdef DEBUG_SYSTEMACE
+      printf("... systemace read %lu sectors at %lu\n", blkcnt, start);
+#endif
+
       retry = 2000;
       for (;;) {
-           unsigned val = ace_readw(0x04);
+           val = ace_readw(0x04);
 
              /* If CFDETECT is false, card is missing. */
            if (! (val & 0x0010)) {
@@ -161,38 +202,66 @@ static unsigned long systemace_read(int dev,
            retry -= 1;
       }
 
-       /* Write LBA block address */
-      ace_writew(start & 0xffff, 0x10);
-      start >>= 16;
-      ace_writew(start & 0xff, 0x12);
-
-       /* Write sector count | ReadMemCardData. */
-      ace_writew(blkcnt | 0x0300, 0x14);
+       /* The SystemACE can only transfer 256 sectors at a time, so
+          limit the current chunk of sectors. The blk_countdown
+          variable is the number of sectors left to transfer. */
 
-       /* CONTROLREG = CFGRESET|LOCKREQ */
-      ace_writew(0x0082, 0x18);
+      blk_countdown = blkcnt;
+      while (blk_countdown > 0) {
+           unsigned trans = blk_countdown;
 
-      retry = blkcnt * 16;
-      while (retry > 0) {
-           int idx;
+           if (trans > 256) trans = 256;
 
-             /* Wait for buffer to become ready. */
-           while (! (ace_readw(0x04) & 0x0020)) {
-                 udelay(1000);
+#ifdef DEBUG_SYSTEMACE
+           printf("... transfer %lu sector in a chunk\n", trans);
+#endif
+             /* Write LBA block address */
+           ace_writew((start>> 0) & 0xffff, 0x10);
+           ace_writew((start>>16) & 0x00ff, 0x12);
+
+             /* NOTE: in the Write Sector count below, a count of 0
+                causes a transfer of 256, so &0xff gives the right
+                value for whatever transfer count we want. */
+
+             /* Write sector count | ReadMemCardData. */
+           ace_writew((trans&0xff) | 0x0300, 0x14);
+
+           /* Reset the configruation controller */
+           val = ace_readw(0x18);
+           val|=0x0080;
+           ace_writew(val, 0x18);
+
+           retry = trans * 16;
+           while (retry > 0) {
+                 int idx;
+
+                   /* Wait for buffer to become ready. */
+                 while (! (ace_readw(0x04) & 0x0020)) {
+                       udelay(100);
+                 }
+
+                   /* Read 16 words of 2bytes from the sector buffer. */
+                 for (idx = 0 ;  idx < 16 ;  idx += 1) {
+                       unsigned short val = ace_readw(0x40);
+                       *dp++ = val & 0xff;
+                       *dp++ = (val>>8) & 0xff;
+                 }
+
+                 retry -= 1;
            }
 
-             /* Read 16 words of 2bytes from the sector buffer. */
-           for (idx = 0 ;  idx < 16 ;  idx += 1) {
-                 unsigned short val = ace_readw(0x40);
-                 *dp++ = val & 0xff;
-                 *dp++ = (val>>8) & 0xff;
-           }
+           /* Clear the configruation controller reset */
+           val = ace_readw(0x18);
+           val&=~0x0080;
+           ace_writew(val, 0x18);
 
-           retry -= 1;
+             /* Count the blocks we transfer this time. */
+           start += trans;
+           blk_countdown -= trans;
       }
 
       release_cf_lock();
 
       return blkcnt;
 }
-#endif
+#endif /* CONFIG_SYSTEMACE */