Skip to contentSkip to conversation

AT91: initialize Compact Flash on AT91SAM9263 cpu

PATCH Superseded Stanislaw Gruszka 4 participants 11 messages Feb 9, 2009 – Feb 17, 2009

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 3/3 AT91: initialize Compact Flash on AT91SAM9263 cpu

---
 arch/arm/mach-at91/at91sam9263_devices.c |  104 ++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)
arch/arm/mach-at91/at91sam9263_devices.c +104 -0
index b753cb8..8e46abe 100644
@@ -15,6 +15,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/i2c-gpio.h>
+#include <linux/delay.h>
 
 #include <linux/fb.h>
 #include <video/atmel_lcdc.h>
@@ -347,6 +348,109 @@ void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data)
 void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) {}
 #endif
 
+/* --------------------------------------------------------------------
+ *  Compact Flash (PCMCIA or IDE)
+ * -------------------------------------------------------------------- */
+
+#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE) || \
+    defined(CONFIG_BLK_DEV_IDE_AT91) || defined(CONFIG_BLK_DEV_IDE_AT91_MODULE)
+
+static struct resource cf_resources[] = {
+	[0] = {
+		.start	= 0,
+		.end	= 0,
+		.flags	= IORESOURCE_MEM,
+	},
+};
+
+static struct at91_cf_data cf_data;
+
+static struct platform_device at91_cf_device = {
+	.id 	= -1,
+	.dev	= {
+		.platform_data = &cf_data,
+	},
+	.resource = cf_resources,
+	.num_resources = ARRAY_SIZE(cf_resources),
+};
+
+void __init at91_add_device_cf(struct at91_cf_data *data)
+{
+	unsigned long ebi0_csa, addr_space;
+
+	if (!data)
+		return;
+
+	/*
+	 * assign CS4 or CS5 to SMC with Compact Flash logic support,
+	 * we assume SMC timings are configured by board code,
+	 * except True IDE where timings are controlled by driver
+	 */
+	ebi0_csa = at91_sys_read(AT91_MATRIX_EBI0CSA);
+	switch (data->chipselect) {
+	case 4:
+		at91_set_A_periph(AT91_PIN_PD6, 0);  /* EBI0_NCS4/CFCS0 */
+		ebi0_csa |= AT91_MATRIX_EBI0_CS4A_SMC_CF1;
+		addr_space = AT91_CHIPSELECT_4;
+		break;
+	case 5:
+		at91_set_A_periph(AT91_PIN_PD7, 0);  /* EBI0_NCS5/CFCS1 */
+		ebi0_csa |= AT91_MATRIX_EBI0_CS5A_SMC_CF2;
+		addr_space = AT91_CHIPSELECT_5;
+		break;
+	default:
+		printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
+		       data->chipselect);
+		return;
+	}
+	at91_sys_write(AT91_MATRIX_EBI0CSA, ebi0_csa);
+
+	cf_resources[0].start = addr_space;
+	cf_resources[0].end = addr_space + SZ_256M - 1;
+
+	if (data->det_pin) {
+		at91_set_gpio_input(data->det_pin, 1);
+		at91_set_deglitch(data->det_pin, 1);
+	}
+
+	if (data->irq_pin) {
+		at91_set_gpio_input(data->irq_pin, 1);
+		at91_set_deglitch(data->irq_pin, 1);
+	}
+
+	if (data->vcc_pin)
+		/* initially off */
+		at91_set_gpio_output(data->vcc_pin, 0);
+
+	/* enable EBI controlled pins */
+	at91_set_A_periph(AT91_PIN_PD5, 1);  /* NWAIT */
+	at91_set_A_periph(AT91_PIN_PD8, 0);  /* CFCE1 */
+	at91_set_A_periph(AT91_PIN_PD9, 0);  /* CFCE2 */
+	at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */
+
+	if (data->flags & AT91_CF_TRUE_IDE) {
+		/* check if device is present */
+		if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+			return;
+		}
+		if (data->rst_pin) {
+			/* reset the card */
+			at91_set_gpio_output(data->rst_pin, 0);
+			/* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+			udelay(25);
+			at91_set_gpio_output(data->rst_pin, 1);
+		}
+		at91_cf_device.name = "at91_ide";
+	} else
+		at91_cf_device.name = "at91_cf";
+
+	cf_data = *data;
+	platform_device_register(&at91_cf_device);
+}
+#else
+void __init at91_add_device_cf(struct at91_cf_data *data) {}
+#endif
 
 /* --------------------------------------------------------------------
  *  NAND / SmartMedia
Signature · 1 line
1.5.2.5
Acked-by on v3 3/3
#1 lore raw

Hello.

Quoted 2 lines · Stanislaw Gruszka
Quoted 4 lines

index b753cb8..8e46abe 100644

arch/arm/mach-at91/at91sam9263_devices.c +0 -0

[...]

Quoted 4 lines
arch/arm/mach-at91/at91sam9263_devices.c +3 -0
+void __init at91_add_device_cf(struct at91_cf_data *data)
+{
+	unsigned long ebi0_csa, addr_space;

[...]

arch/arm/mach-at91/at91sam9263_devices.c void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) · line 442

Quoted 13 lines
arch/arm/mach-at91/at91sam9263_devices.c +12 -0
+	if (data->flags & AT91_CF_TRUE_IDE) {
+		/* check if device is present */
+		if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+			return;
+		}
+		if (data->rst_pin) {
+			/* reset the card */
+			at91_set_gpio_output(data->rst_pin, 0);
+			/* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+			udelay(25);
+			at91_set_gpio_output(data->rst_pin, 1);

I'm still not sure why this is needed. Do you think thta power-on
reset is not enough?

MBR, Sergei

#7 lore raw
In reply to Stanislaw Gruszka

hi Stanislaw,

arch/arm/mach-at91/at91sam9263_devices.c void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) · line 443

Quoted 13 lines
arch/arm/mach-at91/at91sam9263_devices.c +13 -0
+       if (data->flags & AT91_CF_TRUE_IDE) {
+               /* check if device is present */
+               if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+                       printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+                       return;
+               }
+               if (data->rst_pin) {
+                       /* reset the card */
+                       at91_set_gpio_output(data->rst_pin, 0);
+                       /* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+                       udelay(25);
+                       at91_set_gpio_output(data->rst_pin, 1);
+               }

Shouldn't this rather be done in the at91_ide driver?
I don't want to duplicate it in all the different at91sam9XX_devices.c files.

You could also define two separate "CF type" devices - one for CS4, another for CS5.
That would allow for two independent "CF type" interfaces to be used at the same time (see at91sam9260_devices.c in maxim.org.za patches).

Regards,
Andrew Victor

#4 lore raw
In reply to Sergei Shtylyov

Hi.

Wednesday 11 February 2009 14:59:00 Sergei Shtylyov napisał(a):

Quoted 17 lines

[...]

arch/arm/mach-at91/at91sam9263_devices.c void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) · line 442

Quoted 13 lines
arch/arm/mach-at91/at91sam9263_devices.c +12 -0
+	if (data->flags & AT91_CF_TRUE_IDE) {
+		/* check if device is present */
+		if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+			return;
+		}
+		if (data->rst_pin) {
+			/* reset the card */
+			at91_set_gpio_output(data->rst_pin, 0);
+			/* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+			udelay(25);
+			at91_set_gpio_output(data->rst_pin, 1);

I'm still not sure why this is needed. Do you think thta power-on
reset is not enough?

HW reset is not needed when board is powered-on. But situation is diffrent when we have reboot due to board reset booton press. There are configuration where signal from reset button is connected to CF card (or disk), in some cases device reset signal is connected to GPIO with assumption to be asserted by software.

I don't know if we can remove this. In hw reset case system/driver will run with undefined device state, in example device can generate interrupts.

Stanislaw Gruszka

#8 lore raw
In reply to Andrew Victor

Hi

Wednesday 11 February 2009 21:03:29 Andrew Victor napisał(a):

Quoted 14 lines

arch/arm/mach-at91/at91sam9263_devices.c void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) · line 443

Quoted 13 lines
arch/arm/mach-at91/at91sam9263_devices.c +13 -0
+       if (data->flags & AT91_CF_TRUE_IDE) {
+               /* check if device is present */
+               if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+                       printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+                       return;
+               }
+               if (data->rst_pin) {
+                       /* reset the card */
+                       at91_set_gpio_output(data->rst_pin, 0);
+                       /* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+                       udelay(25);
+                       at91_set_gpio_output(data->rst_pin, 1);
+               }
Quoted 2 lines

Shouldn't this rather be done in the at91_ide driver?
I don't want to duplicate it in all the different at91sam9XX_devices.c files.

Ok, I'll move detection stuff to the driver. Not sure about reset, see my previous mail on this issue. Could we move the reset into driver and risk system boot with device which possibly generate interrupts? Or perhaps we can remove reset as whole?

Quoted 4 lines

You could also define two separate "CF type" devices - one for CS4, another for CS5.
That would allow for two independent "CF type" interfaces to be used at the same time (see at91sam9260_devices.c in maxim.org.za patches).

I saw sam9260 code before and I refused idea of doing two CF devices interfaces. AFAIK there are no boards we two CF slots (or separate one IDE and one CF slot), are they? I don't think someone really need such board (I could be wrong). If there become a board with two interfaces, then new patch can be done which extend the code.

Cheers
Stanislaw Gruszka

#5 lore raw
In reply to Stanislaw Gruszka

Hello.

Quoted 18 lines · Stanislaw Gruszka
Quoted 17 lines

[...]

arch/arm/mach-at91/at91sam9263_devices.c void __init at91_add_device_mmc(short mmc_id, struct at91_mmc_data *data) · line 442

Quoted 12 lines
arch/arm/mach-at91/at91sam9263_devices.c +12 -0
+	if (data->flags & AT91_CF_TRUE_IDE) {
+		/* check if device is present */
+		if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+			return;
+		}
+		if (data->rst_pin) {
+			/* reset the card */
+			at91_set_gpio_output(data->rst_pin, 0);
+			/* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+			udelay(25);
+			at91_set_gpio_output(data->rst_pin, 1);

I'm still not sure why this is needed. Do you think thta power-on
reset is not enough?

Quoted 5 lines

HW reset is not needed when board is powered-on. But situation is diffrent when we have reboot due to board reset booton press. There are configuration where signal from reset button is connected to CF card (or disk), in some cases device reset signal is connected to GPIO with assumption to be asserted by software.

OK, thanks for the explanation.

Quoted 1 line

I don't know if we can remove this.

Well, seems worth keeping.

Quoted 1 line

In hw reset case system/driver will run with undefined device state,

What do you mean by undefined? It could have not come out of reset which
shoiuld mean that the IDE probing code will have to wait some time before BSY clears -- see ide_port_wait_ready().

Quoted 1 line

in example device can generate interrupts.

Interrupts after any kind of reset? That just shouldn't happen -- it's
against the ATA spec at least.

Quoted 1 line

Stanislaw Gruszka

MBR, Sergei

#6 lore raw

Hi.

Thursday 12 February 2009 17:33:08 Sergei Shtylyov napisał(a):

Quoted 17 lines
Quoted 8 lines
Quoted 2 lines

I'm still not sure why this is needed. Do you think thta power-on
reset is not enough?

HW reset is not needed when board is powered-on. But situation is diffrent when we have reboot due to board reset booton press. There are configuration where signal from reset button is connected to CF card (or disk), in some cases device reset signal is connected to GPIO with assumption to be asserted by software.

OK, thanks for the explanation.

Quoted 1 line

I don't know if we can remove this.

Well, seems worth keeping.

Quoted 1 line

In hw reset case system/driver will run with undefined device state,

Quoted 8 lines

What do you mean by undefined? It could have not come out of reset which
shoiuld mean that the IDE probing code will have to wait some time before BSY clears -- see ide_port_wait_ready().

Quoted 1 line

in example device can generate interrupts.

Interrupts after any kind of reset? That just shouldn't happen -- it's
against the ATA spec at least.

I mean undefined state and interrupts where is _no_ IDE device reset and system boots because of board button h/w reset (or watchdog reset).

Ok, IDE layer will cope with any registers state during initialization, but when not handled interrupt is generated we have spurious interrupt which is some trouble for kernel.

Cheers
Stanislaw Gruszka

#9 lore raw
In reply to Stanislaw Gruszka

Hello.

Quoted 14 lines · Stanislaw Gruszka
Quoted 14 lines
Quoted 14 lines
arch/arm/mach-at91/at91sam9263_devices.c +13 -0
+       if (data->flags & AT91_CF_TRUE_IDE) {
+               /* check if device is present */
+               if (data->det_pin && at91_get_gpio_value(data->det_pin) != 0) {
+                       printk(KERN_ERR "AT91 CF True IDE: no device detected\n");
+                       return;
+               }
+               if (data->rst_pin) {
+                       /* reset the card */
+                       at91_set_gpio_output(data->rst_pin, 0);
+                       /* wait as defined in ATA7 vol2 (rev 4a) figure 36 */
+                       udelay(25);
+                       at91_set_gpio_output(data->rst_pin, 1);
+               }
Quoted 6 lines
Quoted 3 lines

Shouldn't this rather be done in the at91_ide driver?
I don't want to duplicate it in all the different at91sam9XX_devices.c files.

Ok, I'll move detection stuff to the driver. Not sure about reset, see my

AT91_CF_TRUE_IDE then can possibly be eliminated. There's not dire
need for this device to have different names...

Quoted 3 lines

previous mail on this issue. Could we move the reset into driver and risk system boot with device which possibly generate interrupts?

I don't see how keeping hardware reset in the platfrom code helps
here -- you have that code inside #ifdef, so it's only executed when the driver is enabled anyway. Hm, except when the driver is built as a module -- in this case it should help...

MBR, Sergei

#10 lore raw
In reply to Stanislaw Gruszka

Thursday 12 February 2009 10:33:56 Stanislaw Gruszka napisał(a):

Quoted 7 lines
Quoted 2 lines

Shouldn't this rather be done in the at91_ide driver?
I don't want to duplicate it in all the different at91sam9XX_devices.c files.

Ok, I'll move detection stuff to the driver. Not sure about reset, see my previous mail on this issue. Could we move the reset into driver and risk system boot with device which possibly generate interrupts? Or perhaps we can remove reset as whole?

I'll finally move resetting stuff into board specific file and detect code into driver.

Quoted 10 lines
Quoted 4 lines

You could also define two separate "CF type" devices - one for CS4, another for CS5.
That would allow for two independent "CF type" interfaces to be used at the same time (see at91sam9260_devices.c in maxim.org.za patches).

I saw sam9260 code before and I refused idea of doing two CF devices interfaces. AFAIK there are no boards we two CF slots (or separate one IDE and one CF slot), are they? I don't think someone really need such board (I could be wrong). If there become a board with two interfaces, then new patch can be done which extend the code.

I see no discussion here is possible :) , ok I'll revrite the code in form like at91sam9260_devices.c has.

Cheers
Stanislaw Gruszka