Subject: Poking around in PCMCIA, t6-rmk5-np2

From: I-Gene Leong <[email-masked]>
Date: Thu, 24 Aug 2000 12:22:29 -0700 (PDT)

I saw Erik Mouw's changes to include/asm-arm/arch-sa1100/ide.h and stuffed
in a printk to see what was being passed in. The t4-rmk1-np1 ide.h just
used the port that was sent in, while the t6-rmk5-np2 ide.h added a base
value to it that corresponds to PCMCIA slot 0.

What I'm talking about:

--- t4-rmk1-np1
static __inline__ void
ide_init_hwif_ports(hw_regs_t *hw, int data_port, int ctrl_port, int *irq)
{
        ide_ioreg_t reg;
        int i;
        int ioshift = 0;

        /* The Empeg board has the first two address lines unused */
        if (machine_is_empeg())
                ioshift = 2;

        memset(hw, 0, sizeof(*hw));

        reg = (ide_ioreg_t) (data_port << ioshift);
        for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
                hw->io_ports[i] = reg;
                reg += (1 << ioshift);
        }
---

--- t6-rmk5-np2
#define PCMCIA_IO_0_BASE 0xe0000000
#define PCMCIA_IO_1_BASE 0xe4000000

/*
 * Set up a hw structure for a specified data port, control port and IRQ.
 * This should follow whatever the default interface uses.
 */
static __inline__ void
ide_init_hwif_ports(hw_regs_t *hw, int data_port, int ctrl_port, int *irq)
{
        ide_ioreg_t reg; 
        int i;
        int ioshift = 0; 
        int base = PCMCIA_IO_0_BASE;

        /* The Empeg board has the first two address lines unused */
        if (machine_is_empeg())
                ioshift = 2;
  
        /* The LART doesn't use A0 for IDE */
        if (machine_is_lart())
                ioshift = 1;
 
        memset(hw, 0, sizeof(*hw));

        reg = (ide_ioreg_t) (base + (data_port << ioshift));
        for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
                hw->io_ports[i] = reg;
                reg += (1 << ioshift);
        }
---

Now, the ide/pcmcia driver code passes in the actual absolute address for
the dataport.

I'm guessing that dataport is meant to be relative, since it's shifted by
ioshift.

Anyway, for the Cerf, which has one CF+ slot, data_port is passed
in as e4000000 (PCMCIA slot 1). For t4-rmk1-np1 it stays as e4000000,
while t6-rmk5-np2 adds PCMCIA_IO_0_BASE (e0000000) to it, giving me
c4000000. So there's where my kernel oops is coming from.

The question is, how should it be fixed? I can think of a quick
fix: editing ide.h not to add base on. But it doesn't look to me as though
that's the intention because data_port is shifted, which makes no sense
for an absolute address. The alternative is to go digging through the
pcmcia code to find out where this port is set... in which case, how will
I indicate that it's PCMCIA slot 1 I want, and not PCMCIA slot 0?

-- 
I-Gene Leong
[email-masked] / 604-646-6962
"We see Linux as being much of a fad as the Internet was in 1995."
  - Irving Wladawsky-Berger, IBM VP of technology and strategy

unsubscribe: body of `unsubscribe linux-arm-kernel' to [email-masked]

---

From: Erik Mouw <[email-masked]>
Date: Thu 24 Aug 2000 22:38:17 +0100 (MDT)

> value to it that corresponds to PCMCIA slot 0.

[...]

> --- t6-rmk5-np2

[...]

> I'm guessing that dataport is meant to be relative, since it's shifted by

Yes, it was meant to be relative.

> c4000000. So there's where my kernel oops is coming from.

I see. Well, Cerf was not mentioned in the ide.h file, so I didn't think
of it. I also didn't realize that the PCMCIA code used this function,
sorry.

> I indicate that it's PCMCIA slot 1 I want, and not PCMCIA slot 0?

Try my attached patch, it makes the address absolute again. I tested it
with the LART (it boots, ship it ;-) ), it should also work for the Cerf,
Empeg and the Victor.

Nico, please apply this patch.

Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2783635  Fax: +31-15-2781843  Email: [email-masked]
WWW: http://www-ict.its.tudelft.nl/~erik/

--- linux-2.4.0-test6-rmk5-np2-vanilla/include/asm-arm/arch-sa1100/ide.h	Thu Aug 24 13:49:09 2000
+++ linux-2.4.0-test6-rmk5-np2/include/asm-arm/arch-sa1100/ide.h	Thu Aug 24 22:32:30 2000
@@ -28,27 +28,26 @@
 {
 	ide_ioreg_t reg;
 	int i;
-	int ioshift = 0;
-	int base = PCMCIA_IO_0_BASE;
-
+	int regincr = 1;
+	
 	/* The Empeg board has the first two address lines unused */
 	if (machine_is_empeg())
-		ioshift = 2;
+		regincr = 1 << 2;
 
-		ioshift = 1;
+		regincr = 1 << 1;

-	reg = (ide_ioreg_t) (base + (data_port << ioshift));
+	reg = (ide_ioreg_t)data_port;
+
 	for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
 		hw->io_ports[i] = reg;
-		reg += (1 << ioshift);
+		reg += regincr;
 	}
 	
-	hw->io_ports[IDE_CONTROL_OFFSET] = 
-		(ide_ioreg_t) (base + (ctrl_port << ioshift));
+	hw->io_ports[IDE_CONTROL_OFFSET] = (ide_ioreg_t) ctrl_port;
 	
 	if (irq)
 		*irq = 0;
@@ -87,10 +86,10 @@
 	/* MAC 23/4/1999, swap these round so that the left hand
 	   hard disk is hda when viewed from the front. This
 	   doesn't match the silkscreen however. */
-	ide_init_hwif_ports(&hw, 0x10, 0x1e, NULL);
+	ide_init_hwif_ports(&hw, PCMCIA_IO_0_BASE + 0x40, PCMCIA_IO_0_BASE + 0x78, NULL);
 	hw.irq = EMPEG_IRQ_IDE2;
 	ide_register_hw(&hw, NULL);
-	ide_init_hwif_ports(&hw, 0x00, 0x0e, NULL);
+	ide_init_hwif_ports(&hw, PCMCIA_IO_0_BASE + 0x00, PCMCIA_IO_0_BASE + 0x38, NULL);
 	hw.irq = ,EMPEG_IRQ_IDE1;
 	ide_register_hw(&hw, NULL);
 #endif
@@ -107,7 +106,7 @@
 	/* set the pcmcia interface timing */
 	MECR = 0x00060006;
 
-	ide_init_hwif_ports(&hw, 0x1f0, 0x3f6, NULL);
+	ide_init_hwif_ports(&hw, PCMCIA_IO_0_BASE + 0x1f0, PCMCIA_IO_0_BASE + 0x3f6, NULL);
 	hw.irq = IRQ_GPIO7;
 	ide_register_hw(&hw, NULL);
 #endif
@@ -124,7 +123,7 @@
         MECR = 0x00060006;
 
         /* init the interface */
-	ide_init_hwif_ports(&hw, 0x0000, 0x0800, NULL);
+	ide_init_hwif_ports(&hw, PCMCIA_IO_0_BASE + 0x0000, PCMCIA_IO_0_BASE + 0x1000, NULL);
         hw.irq = IRQ_GPIO1;
         ide_register_hw(&hw, NULL);
 #endif

---

From: I-Gene Leong <[email-masked]>
Date: Thu, 24 Aug 2000 13:51:23 -0700 (PDT)

Your patch works here, thanks. Disregard my pathetic-excuse-for-a-patch,
everyone. :)