Skip to contentSkip to conversation

AT91: initialize Compact Flash on AT91SAM9263 cpu

PATCH Superseded Stanislaw Gruszka 2 participants 8 messages Feb 6, 2009 – Feb 15, 2009

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

---
 arch/arm/mach-at91/at91sam9263_devices.c |  106 ++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)
arch/arm/mach-at91/at91sam9263_devices.c +106 -0
index b753cb8..7c950f1 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,111 @@ 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) {
+		/* check if device is present */
+		at91_set_gpio_input(data->det_pin, 1);
+		at91_set_deglitch(data->det_pin, 1);
+		if (at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91: no CF card detected\n");
+			return;
+		}
+	}
+
+	if (data->rst_pin) {
+		/* reset the card */
+		int reset = (data->flags & AT91_CF_TRUE_IDE) ? 0 : 1;
+
+		at91_set_gpio_output(data->rst_pin, reset);
+		udelay(25); /* taken from ATA docs, CFA not specify it ? */
+		at91_set_gpio_output(data->rst_pin, !reset);
+	}
+
+	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)
+		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_ide_data *data) {}
+#endif
 
 /* --------------------------------------------------------------------
  *  NAND / SmartMedia
Signature · 1 line
1.5.2.5
#1 lore raw

Hello.

Quoted 2 lines · Stanislaw Gruszka

[...]

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

Quoted 11 lines
arch/arm/mach-at91/at91sam9263_devices.c +6 -0
@@ -347,6 +348,111 @@ 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)
 

Ugh... what are trying to achieve with this, marginal memory save?

Quoted 22 lines
arch/arm/mach-at91/at91sam9263_devices.c +21 -0
+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)
+{
 

[...]

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

Quoted 3 lines
arch/arm/mach-at91/at91sam9263_devices.c +2 -0
+	cf_resources[0].start = addr_space;
+	cf_resources[0].end = addr_space + SZ_256M - 1;

In the datasheet the CF mode address space is just 0x1000000, i.e. 16
MB, not 256. Moreover, address lines above A22 are not connected to CF at all.

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

Quoted 11 lines
arch/arm/mach-at91/at91sam9263_devices.c +10 -0
+
+	if (data->det_pin) {
+		/* check if device is present */
+		at91_set_gpio_input(data->det_pin, 1);
+		at91_set_deglitch(data->det_pin, 1);
+		if (at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91: no CF card detected\n");
+			return;
+		}
+	}

Bart, I'm not sure: don't we support warm-plug now? Or it won't avail
us with CF?

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

Quoted 9 lines
arch/arm/mach-at91/at91sam9263_devices.c +8 -0
+	if (data->rst_pin) {
+		/* reset the card */
+		int reset = (data->flags & AT91_CF_TRUE_IDE) ? 0 : 1;
+
+		at91_set_gpio_output(data->rst_pin, reset);
+		udelay(25); /* taken from ATA docs, CFA not specify it ? */
+		at91_set_gpio_output(data->rst_pin, !reset);
+	}

Is there really a need to hard reset CF on every reboot?

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

Quoted 4 lines
arch/arm/mach-at91/at91sam9263_devices.c +3 -0
+	if (data->vcc_pin)
+		/* initially off */
+		at91_set_gpio_output(data->vcc_pin, 0);

Why? Moreover, resetting CF without power applied (or cutting off
power afterwards) just doesn't make sense...

MBR, Sergei

#5 lore raw
In reply to Stanislaw Gruszka

Hello.

Quoted 2 lines · Stanislaw Gruszka

[...]

Quoted 4 lines
arch/arm/mach-at91/at91sam9263_devices.c +0 -0
index b753cb8..7c950f1 100644

[...]

Quoted 3 lines
arch/arm/mach-at91/at91sam9263_devices.c +2 -0
+void __init at91_add_device_cf(struct at91_cf_data *data)
+{

[...]

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

Quoted 8 lines
arch/arm/mach-at91/at91sam9263_devices.c +7 -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)

Again, I've probably missed something but this structre doesn't have
the 'flags' field. How is this suppoed to compile?

MBR, Sergei

#2 lore raw
In reply to Sergei Shtylyov

Friday 06 February 2009 13:03:54 Sergei Shtylyov napisał(a):

Quoted 9 lines

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

Quoted 7 lines
arch/arm/mach-at91/at91sam9263_devices.c +6 -0
+/* --------------------------------------------------------------------
+ *  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)

Ugh... what are trying to achieve with this, marginal memory save?

Some memory save. There are users which count every byte.

Quoted 7 lines

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

Quoted 3 lines
arch/arm/mach-at91/at91sam9263_devices.c +2 -0
+	cf_resources[0].start = addr_space;
+	cf_resources[0].end = addr_space + SZ_256M - 1;

In the datasheet the CF mode address space is just 0x1000000, i.e. 16
MB, not 256. Moreover, address lines above A22 are not connected to CF at all.

We take here all particular chip select address space
CS5: 0x50000000 - 0x5fffffff
CS6: 0x60000000 - 0x6fffffff

Quoted 5 lines
Quoted 5 lines
arch/arm/mach-at91/at91sam9263_devices.c +5 -0
+	if (data->det_pin) {
+		/* check if device is present */
+		at91_set_gpio_input(data->det_pin, 1);
+		at91_set_deglitch(data->det_pin, 1);
+		if (at91_get_gpio_value(data->det_pin) != 0) {
Quoted 8 lines

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

Quoted 5 lines
arch/arm/mach-at91/at91sam9263_devices.c +4 -0
+			printk(KERN_ERR "AT91: no CF card detected\n");
+			return;
+		}
+	}

Bart, I'm not sure: don't we support warm-plug now? Or it won't avail
us with CF?

Uhh, this code is wrong at least for PCMCIA as we hotplug there. I don't think hotplug is supported for ATA devices.

Quoted 11 lines

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

Quoted 9 lines
arch/arm/mach-at91/at91sam9263_devices.c +8 -0
+	if (data->rst_pin) {
+		/* reset the card */
+		int reset = (data->flags & AT91_CF_TRUE_IDE) ? 0 : 1;
+
+		at91_set_gpio_output(data->rst_pin, reset);
+		udelay(25); /* taken from ATA docs, CFA not specify it ? */
+		at91_set_gpio_output(data->rst_pin, !reset);
+	}

Is there really a need to hard reset CF on every reboot?

I think this have sense for ATA devices.

Quoted 7 lines

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

Quoted 4 lines
arch/arm/mach-at91/at91sam9263_devices.c +3 -0
+	if (data->vcc_pin)
+		/* initially off */
+		at91_set_gpio_output(data->vcc_pin, 0);

Why? Moreover, resetting CF without power applied (or cutting off
power afterwards) just doesn't make sense...

Right.

Stanislaw Gruszka

#6 lore raw
In reply to Sergei Shtylyov

Friday 06 February 2009 13:17:27 Sergei Shtylyov napisał(a):

Quoted 4 lines
Quoted 3 lines
arch/arm/mach-at91/at91sam9263_devices.c +2 -0
+void __init at91_add_device_cf(struct at91_cf_data *data)
+{

[...]

Quoted 11 lines

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

Quoted 8 lines
arch/arm/mach-at91/at91sam9263_devices.c +7 -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)

Again, I've probably missed something but this structre doesn't have
the 'flags' field. How is this suppoed to compile?

Patch 2/3 add flags to the at91_cf_data structure.

Stanislaw Gruszka

#7 lore raw
Quoted 16 lines · Stanislaw Gruszka
Quoted 5 lines
Quoted 2 lines
arch/arm/mach-at91/at91sam9263_devices.c +2 -0
+void __init at91_add_device_cf(struct at91_cf_data *data)
+{

[...]

Quoted 10 lines

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

Quoted 7 lines
arch/arm/mach-at91/at91sam9263_devices.c +7 -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)

Again, I've probably missed something but this structre doesn't have
the 'flags' field. How is this suppoed to compile?

Quoted 1 line

Patch 2/3 add flags to the at91_cf_data structure.

Ah, stupid me. Haven't looked at that patch yet. :-<

Quoted 1 line

Stanislaw Gruszka

MBR, Sergei

#3 lore raw
In reply to Stanislaw Gruszka

Hello.

Quoted 13 lines · Stanislaw Gruszka
Quoted 4 lines
Quoted 4 lines
arch/arm/mach-at91/at91sam9263_devices.c +4 -0
+	if (data->det_pin) {
+		/* check if device is present */
+		at91_set_gpio_input(data->det_pin, 1);
+		at91_set_deglitch(data->det_pin, 1);
Quoted 8 lines

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

Quoted 5 lines
arch/arm/mach-at91/at91sam9263_devices.c +5 -0
+		if (at91_get_gpio_value(data->det_pin) != 0) {
+			printk(KERN_ERR "AT91: no CF card detected\n");
+			return;
+		}
+	}

Bart, I'm not sure: don't we support warm-plug now? Or it won't avail
us with CF?

Quoted 2 lines

Uhh, this code is wrong at least for PCMCIA as we hotplug there. I don't think hotplug is supported for ATA devices.

I didn't say hot plug, I said *warm* plug. You can force port probing via
sysfs, if I don't mistake... Bart?

MBR, Sergei

#4 lore raw
Quoted 10 lines · Hello, I wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
arch/arm/mach-at91/at91sam9263_devices.c +9 -0
+    if (data->det_pin) {
+        /* check if device is present */
+        at91_set_gpio_input(data->det_pin, 1);
+        at91_set_deglitch(data->det_pin, 1);
+        if (at91_get_gpio_value(data->det_pin) != 0) {
+            printk(KERN_ERR "AT91: no CF card detected\n");
+            return;
+        }
+    }
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Bart, I'm not sure: don't we support warm-plug now? Or it won't
avail us with CF?

Uhh, this code is wrong at least for PCMCIA as we hotplug there. I don't think hotplug is supported for ATA devices.

I didn't say hot plug, I said *warm* plug. You can force port probing
via sysfs, if I don't mistake... Bart?

See Documentation/ide/warm-plug-howto.txt

MBR, Sergei