Skip to contentSkip to conversation

sf: probe: Add support Atmel AT45DB series devices special commands

PATCH New Haikun Wang 2 participants 6 messages Mar 25, 2015 – Mar 26, 2015 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

 drivers/mtd/spi/sf_internal.h |  7 +++++++
 drivers/mtd/spi/sf_ops.c      |  2 +-
 drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +7 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
 	SST_BP		= 1 << 3,
 	SST_WP		= 1 << 4,
 	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
 };
 
 #define SST_WR		(SST_BP | SST_WP)
@@ -106,6 +107,12 @@ enum {
 #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
 #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
 /* SST specific */
 #ifdef CONFIG_SPI_FLASH_SST
 # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
 	u8 poll_bit = STATUS_WIP;
 	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
 		poll_bit = STATUS_PEC;
 		check_status = poll_bit;
 	}
drivers/mtd/spi/sf_probe.c +10 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
 		flash->poll_cmd = CMD_FLAG_STATUS;
 #endif
 
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+
 	/* Configure the BAR - discover bank cmds and read current bank */
 #ifdef CONFIG_SPI_FLASH_BAR
 	u8 curr_bank = 0;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

Hi Haikun,

Quoted 29 lines · Haikun Wang

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

  drivers/mtd/spi/sf_internal.h |  7 +++++++
  drivers/mtd/spi/sf_ops.c      |  2 +-
  drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
  3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
  	SST_BP		= 1 << 3,
  	SST_WP		= 1 << 4,
  	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
  };
 
  #define SST_WR		(SST_BP | SST_WP)

drivers/mtd/spi/sf_internal.h enum { · line 111

Quoted 5 lines
drivers/mtd/spi/sf_internal.h +2 -0
@@ -106,6 +107,12 @@ enum {
  #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
  #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82

Why not use 0x2 to align with current mtd/spi framework?

Quoted 28 lines
drivers/mtd/spi/sf_internal.h +4 -0
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
  /* SST specific */
  #ifdef CONFIG_SPI_FLASH_SST
  # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
  	u8 poll_bit = STATUS_WIP;
  	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
  		poll_bit = STATUS_PEC;
  		check_status = poll_bit;
  	}
drivers/mtd/spi/sf_probe.c +0 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
  		flash->poll_cmd = CMD_FLAG_STATUS;
  #endif
 

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 238

Quoted 10 lines
drivers/mtd/spi/sf_probe.c +10 -0
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+

The SPI Flash's default page size is 264 bytes, but mtd/spi framework supports 256 and 512 bytes for one page. In your patch, you does not handle such case, can your driver works as expected?

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 241

Quoted 3 lines
drivers/mtd/spi/sf_probe.c +0 -0
  	/* Configure the BAR - discover bank cmds and read current bank */
  #ifdef CONFIG_SPI_FLASH_BAR
  	u8 curr_bank = 0;

Regards,
Peng.

#2 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

Quoted 30 lines · On 3/25/2015 10:10 PM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 27 lines · Haikun Wang

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

   drivers/mtd/spi/sf_internal.h |  7 +++++++
   drivers/mtd/spi/sf_ops.c      |  2 +-
   drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
   3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
   	SST_BP		= 1 << 3,
   	SST_WP		= 1 << 4,
   	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
   };
 
Quoted 8 lines

drivers/mtd/spi/sf_internal.h enum { · line 111

Quoted 7 lines
drivers/mtd/spi/sf_internal.h +2 -0
   #define SST_WR		(SST_BP | SST_WP)
@@ -106,6 +107,12 @@ enum {
   #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
   #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82

Why not use 0x2 to align with current mtd/spi framework?

I didn't find the program command '0x2' in AT45DB021D datasheet. Do you ever use it in AT45DBxxxx flash chip?

Quoted 28 lines
Quoted 28 lines
drivers/mtd/spi/sf_internal.h +4 -0
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
   /* SST specific */
   #ifdef CONFIG_SPI_FLASH_SST
   # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
   	u8 poll_bit = STATUS_WIP;
   	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
   		poll_bit = STATUS_PEC;
   		check_status = poll_bit;
   	}
drivers/mtd/spi/sf_probe.c +0 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
   		flash->poll_cmd = CMD_FLAG_STATUS;
   #endif
 
Quoted 13 lines

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 238

Quoted 10 lines
drivers/mtd/spi/sf_probe.c +10 -0
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+

The SPI Flash's default page size is 264 bytes, but mtd/spi framework supports 256 and 512 bytes for one page. In your patch, you does not handle such case, can your driver works as expected?

Fine, I know mtd/spi framework doesn't support page-size of 264bytes. In fact we change the chip's page-size to 256bytes before using it. It is a big work to adjust the framework support 264bytes. So how about add a check here, if the chip has a page-size of 264bytes, we just return an error.
Or I will add a AT45DB special flash driver under Driver Model.

Signature · 2 lines
Best regards,
Wang Haikun
Quoted 6 lines

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 241

Quoted 3 lines
drivers/mtd/spi/sf_probe.c +0 -0
   	/* Configure the BAR - discover bank cmds and read current bank */
   #ifdef CONFIG_SPI_FLASH_BAR
   	u8 curr_bank = 0;

Regards,
Peng.

#3 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

Hi Haikun,

Quoted 36 lines · On 3/26/2015 10:39 AM, Wang Haikun-B53464 wrote:
Quoted 35 lines · On 3/25/2015 10:10 PM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 32 lines · Haikun Wang

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

    drivers/mtd/spi/sf_internal.h |  7 +++++++
    drivers/mtd/spi/sf_ops.c      |  2 +-
    drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
    3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
    	SST_BP		= 1 << 3,
    	SST_WP		= 1 << 4,
    	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
    };
 
    #define SST_WR		(SST_BP | SST_WP)
@@ -106,6 +107,12 @@ enum {
    #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
    #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
Quoted 4 lines
Quoted 3 lines

drivers/mtd/spi/sf_internal.h enum { · line 111

Quoted 2 lines
drivers/mtd/spi/sf_internal.h +2 -0
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82

Why not use 0x2 to align with current mtd/spi framework?

I didn't find the program command '0x2' in AT45DB021D datasheet.

My fault. 0x2h is supported by AT45DB021E, but not AT45DB021D. You can use 0x82.

Quoted 1 line

Do you ever use it in AT45DBxxxx flash chip?

I used a similar chip AT45DB021E, not AT45DB021D. And I have a local patch for this chip.

Quoted 41 lines
Quoted 28 lines
Quoted 28 lines
drivers/mtd/spi/sf_internal.h +4 -0
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
    /* SST specific */
    #ifdef CONFIG_SPI_FLASH_SST
    # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
    	u8 poll_bit = STATUS_WIP;
    	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
    		poll_bit = STATUS_PEC;
    		check_status = poll_bit;
    	}
drivers/mtd/spi/sf_probe.c +0 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
    		flash->poll_cmd = CMD_FLAG_STATUS;
    #endif
 
Quoted 13 lines

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 238

Quoted 10 lines
drivers/mtd/spi/sf_probe.c +10 -0
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+

The SPI Flash's default page size is 264 bytes, but mtd/spi framework supports 256 and 512 bytes for one page. In your patch, you does not handle such case, can your driver works as expected?

Quoted 2 lines

Fine, I know mtd/spi framework doesn't support page-size of 264bytes. In fact we change the chip's page-size to 256bytes before using it.

If others use a same chip, he/she has no idea about this.

Quoted 1 line

It is a big work to adjust the framework support 264bytes.

No big work, just send a configuration command to the chip.

Quoted 2 lines

So how about add a check here, if the chip has a page-size of 264bytes, we just return an error.

This AT45XXD chip's page size can only be configured once. you can check the status register, BIT 0's meaning is PAGE SIZE is 256 or 264. If the page size is 264, you can configure the chip to 256 seeing "11.1 Programming the Configuration Register". If the page size is already 256, no need to configure it again.
You can added related function in sf_ops.c and invoke this function in sf_probe.c when probe.
you can take the following piece of code as a reference as you like, it works for AT45DB021E. About read status, I suppose you can use the FLAG_STATUS to get the correct value.

#if defined(CONFIG_SPI_FLASH_ATMEL)
/*
* For the AT45DB021E, there are an extra eight bytes
* of memory in each page for a total of an extra 8KB
* (64-Kbits) of user-accessible memory.
* In order to be compatible with spi framework, we use 256bytes. */

int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)

{
     u8 data[3];
     u8 cmd;
     int ret;

     ret = spi_flash_cmd_read_status(flash, &data[0]);
     if (ret < 0)
         return ret;

     /*
      * PAGE SIZE Page Size, bit 0.
      * 0 Device is configured for standard DataFlash page size (264 bytes).
      * 1 Device is configured for ?power of 2? binary page size (256 
bytes).
      */
     if (wc == SPI_FLASH_PAGE_256) {
         /* Already 256? */
         if (data[0] & 1)
             return 0;
     } else if (wc == SPI_FLASH_PAGE_264) {
         /* Already 264? */
         if ((data[0] & 1) == 0)
             return 0;
     } else {
         debug("Unsupport page configuration!\n");
         return -1;
     }

     /*
      * 3D, 2A, 80, A6 command seq will configure flash page size 256.
      * 3D, 2A, 80, A7 command seq will configure flash page size 264.
      */
     cmd = 0x3D;
     if (wc == SPI_FLASH_PAGE_256)
         data[2] = 0xA6;
     else if (wc == SPI_FLASH_PAGE_264)
         data[2] = 0xA7;
     data[1] = 0x80;
     data[0] = 0x2A;
     ret = spi_flash_write_common(flash, &cmd, 1, data, 3);
     if (ret) {
         debug("SF: fail to write config register\n");
         return ret;
     }

     /* Check again  the page size*/
    xxxxxxxxxxxxxxxxxx

     return 0;
}

#endif

Quoted 1 line

Or I will add a AT45DB special flash driver under Driver Model.

Regards,
Peng.

#4 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

Quoted 39 lines · On 3/26/2015 11:05 AM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 36 lines · On 3/26/2015 10:39 AM, Wang Haikun-B53464 wrote:
Quoted 35 lines · On 3/25/2015 10:10 PM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 32 lines · Haikun Wang

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

     drivers/mtd/spi/sf_internal.h |  7 +++++++
     drivers/mtd/spi/sf_ops.c      |  2 +-
     drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
     3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
     	SST_BP		= 1 << 3,
     	SST_WP		= 1 << 4,
     	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
     };
 
     #define SST_WR		(SST_BP | SST_WP)
@@ -106,6 +107,12 @@ enum {
     #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
     #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

drivers/mtd/spi/sf_internal.h enum { · line 111

Quoted 2 lines
drivers/mtd/spi/sf_internal.h +2 -0
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82

Why not use 0x2 to align with current mtd/spi framework?

I didn't find the program command '0x2' in AT45DB021D datasheet.

My fault. 0x2h is supported by AT45DB021E, but not AT45DB021D. You can use 0x82.

Does AT45DB021E support '0x82'?

Quoted 45 lines
Quoted 1 line

Do you ever use it in AT45DBxxxx flash chip?

I used a similar chip AT45DB021E, not AT45DB021D. And I have a local patch for this chip.

Quoted 41 lines
Quoted 41 lines
Quoted 28 lines
drivers/mtd/spi/sf_internal.h +4 -0
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
     /* SST specific */
     #ifdef CONFIG_SPI_FLASH_SST
     # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
     	u8 poll_bit = STATUS_WIP;
     	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
     		poll_bit = STATUS_PEC;
     		check_status = poll_bit;
     	}
drivers/mtd/spi/sf_probe.c +0 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
     		flash->poll_cmd = CMD_FLAG_STATUS;
     #endif
 

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 238

Quoted 10 lines
drivers/mtd/spi/sf_probe.c +10 -0
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+

The SPI Flash's default page size is 264 bytes, but mtd/spi framework supports 256 and 512 bytes for one page. In your patch, you does not handle such case, can your driver works as expected?

Quoted 5 lines
Quoted 2 lines

Fine, I know mtd/spi framework doesn't support page-size of 264bytes. In fact we change the chip's page-size to 256bytes before using it.

If others use a same chip, he/she has no idea about this.

Quoted 1 line

It is a big work to adjust the framework support 264bytes.

No big work, just send a configuration command to the chip.

I am not true whether others approve this.
As you said chips only can be configured once and it is irreversible. At least we should let user choice configure or not.

Best regards,
Wang Haikun

Quoted 78 lines
Quoted 2 lines

So how about add a check here, if the chip has a page-size of 264bytes, we just return an error.

This AT45XXD chip's page size can only be configured once. you can check the status register, BIT 0's meaning is PAGE SIZE is 256 or 264. If the page size is 264, you can configure the chip to 256 seeing "11.1 Programming the Configuration Register". If the page size is already 256, no need to configure it again.
You can added related function in sf_ops.c and invoke this function in sf_probe.c when probe.
you can take the following piece of code as a reference as you like, it works for AT45DB021E. About read status, I suppose you can use the FLAG_STATUS to get the correct value.

#if defined(CONFIG_SPI_FLASH_ATMEL)
/*
* For the AT45DB021E, there are an extra eight bytes
* of memory in each page for a total of an extra 8KB
* (64-Kbits) of user-accessible memory.
* In order to be compatible with spi framework, we use 256bytes. */

int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)

{
      u8 data[3];
      u8 cmd;
      int ret;

      ret = spi_flash_cmd_read_status(flash, &data[0]);
      if (ret < 0)
          return ret;

      /*
       * PAGE SIZE Page Size, bit 0.
       * 0 Device is configured for standard DataFlash page size (264 bytes).
       * 1 Device is configured for ?power of 2? binary page size (256
bytes).
       */
      if (wc == SPI_FLASH_PAGE_256) {
          /* Already 256? */
          if (data[0] & 1)
              return 0;
      } else if (wc == SPI_FLASH_PAGE_264) {
          /* Already 264? */
          if ((data[0] & 1) == 0)
              return 0;
      } else {
          debug("Unsupport page configuration!\n");
          return -1;
      }

      /*
       * 3D, 2A, 80, A6 command seq will configure flash page size 256.
       * 3D, 2A, 80, A7 command seq will configure flash page size 264.
       */
      cmd = 0x3D;
      if (wc == SPI_FLASH_PAGE_256)
          data[2] = 0xA6;
      else if (wc == SPI_FLASH_PAGE_264)
          data[2] = 0xA7;
      data[1] = 0x80;
      data[0] = 0x2A;
      ret = spi_flash_write_common(flash, &cmd, 1, data, 3);
      if (ret) {
          debug("SF: fail to write config register\n");
          return ret;
      }

      /* Check again  the page size*/
     xxxxxxxxxxxxxxxxxx

      return 0;
}

#endif

Quoted 1 line

Or I will add a AT45DB special flash driver under Driver Model.

Regards,
Peng.

#5 lore raw

PATCH 1/2 sf: probe: Add support Atmel AT45DB series devices special commands

Quoted 40 lines · On 3/26/2015 6:50 PM, Wang Haikun-B53464 wrote:
Quoted 39 lines · On 3/26/2015 11:05 AM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 36 lines · On 3/26/2015 10:39 AM, Wang Haikun-B53464 wrote:
Quoted 35 lines · On 3/25/2015 10:10 PM, Fan Peng-B51431 wrote:

Hi Haikun,

Quoted 32 lines · Haikun Wang

From: Haikun Wang <[email protected]>

Atmel AT45DB series devices commands is different from common spi flash commands. This patch add support for AT45DB special commands. Add a flag AT45DB_CMD to control whether use those commands.

---

Changes in v1: None

      drivers/mtd/spi/sf_internal.h |  7 +++++++
      drivers/mtd/spi/sf_ops.c      |  2 +-
      drivers/mtd/spi/sf_probe.c    | 10 ++++++++++
      3 files changed, 18 insertions(+), 1 deletion(-)
drivers/mtd/spi/sf_internal.h +1 -0
index 785f7a9..234af21 100644
@@ -43,6 +43,7 @@ enum {
      	SST_BP		= 1 << 3,
      	SST_WP		= 1 << 4,
      	WR_QPP		= 1 << 5,
+	AT45DB_CMD	= 1 << 6,
      };
 
      #define SST_WR		(SST_BP | SST_WP)
@@ -106,6 +107,12 @@ enum {
      #define SPI_FLASH_PAGE_ERASE_TIMEOUT		(5 * CONFIG_SYS_HZ)
      #define SPI_FLASH_SECTOR_ERASE_TIMEOUT	(10 * CONFIG_SYS_HZ)
 
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

drivers/mtd/spi/sf_internal.h enum { · line 111

Quoted 2 lines
drivers/mtd/spi/sf_internal.h +2 -0
+/* Atmel AT45DB specific */
+#define CMD_ATMEL_PAGE_PROGRAM		0x82

Why not use 0x2 to align with current mtd/spi framework?

I didn't find the program command '0x2' in AT45DB021D datasheet.

My fault. 0x2h is supported by AT45DB021E, but not AT45DB021D. You can use 0x82.

Does AT45DB021E support '0x82'?

Yeah. 0x82h "Main Memory Page Program through Buffer with Built-In Erase"

Quoted 45 lines
Quoted 45 lines
Quoted 1 line

Do you ever use it in AT45DBxxxx flash chip?

I used a similar chip AT45DB021E, not AT45DB021D. And I have a local patch for this chip.

Quoted 41 lines
Quoted 41 lines
Quoted 28 lines
drivers/mtd/spi/sf_internal.h +4 -0
+#define CMD_ATMEL_READ_STATUS		0xd7
+#define CMD_ATMEL_FLAG_STATUS		0xd7
+#define CMD_ATMEL_BLK_ERASE	        0x50
+
      /* SST specific */
      #ifdef CONFIG_SPI_FLASH_SST
      # define CMD_SST_BP		0x02    /* Byte Program */
drivers/mtd/spi/sf_ops.c +1 -1
index 34bc54e..27ce5f9 100644
@@ -165,7 +165,7 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
      	u8 poll_bit = STATUS_WIP;
      	u8 cmd = flash->poll_cmd;
 
-	if (cmd == CMD_FLAG_STATUS) {
+	if (cmd == CMD_FLAG_STATUS || cmd == CMD_ATMEL_FLAG_STATUS) {
      		poll_bit = STATUS_PEC;
      		check_status = poll_bit;
      	}
drivers/mtd/spi/sf_probe.c +0 -0
index 4103723..2ccddf2 100644
@@ -226,6 +226,16 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode,
      		flash->poll_cmd = CMD_FLAG_STATUS;
      #endif
 

drivers/mtd/spi/sf_probe.c static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, · line 238

Quoted 10 lines
drivers/mtd/spi/sf_probe.c +10 -0
+#ifdef CONFIG_SPI_FLASH_ATMEL
+	if (params->flags & AT45DB_CMD) {
+		flash->poll_cmd = CMD_ATMEL_READ_STATUS;
+		flash->write_cmd = CMD_ATMEL_PAGE_PROGRAM;
+		/* use block-erase command, eight pages */
+		flash->erase_cmd = CMD_ATMEL_BLK_ERASE;
+		flash->erase_size = flash->page_size * 8;
+	}
+#endif
+

The SPI Flash's default page size is 264 bytes, but mtd/spi framework supports 256 and 512 bytes for one page. In your patch, you does not handle such case, can your driver works as expected?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Fine, I know mtd/spi framework doesn't support page-size of 264bytes. In fact we change the chip's page-size to 256bytes before using it.

If others use a same chip, he/she has no idea about this.

Quoted 1 line

It is a big work to adjust the framework support 264bytes.

No big work, just send a configuration command to the chip.

I am not true whether others approve this.
As you said chips only can be configured once and it is irreversible. At least we should let user choice configure or not.

Hmm.. then you can add the checking page size stuff there as you like.

Quoted 77 lines

Best regards,
Wang Haikun

Quoted 74 lines
Quoted 2 lines

So how about add a check here, if the chip has a page-size of 264bytes, we just return an error.

This AT45XXD chip's page size can only be configured once. you can check the status register, BIT 0's meaning is PAGE SIZE is 256 or 264. If the page size is 264, you can configure the chip to 256 seeing "11.1 Programming the Configuration Register". If the page size is already 256, no need to configure it again.
You can added related function in sf_ops.c and invoke this function in sf_probe.c when probe.
you can take the following piece of code as a reference as you like, it works for AT45DB021E. About read status, I suppose you can use the FLAG_STATUS to get the correct value.

#if defined(CONFIG_SPI_FLASH_ATMEL)
/*
* For the AT45DB021E, there are an extra eight bytes
* of memory in each page for a total of an extra 8KB
* (64-Kbits) of user-accessible memory.
* In order to be compatible with spi framework, we use 256bytes. */

int spi_flash_cmd_write_config(struct spi_flash *flash, u8 wc)

{
       u8 data[3];
       u8 cmd;
       int ret;

       ret = spi_flash_cmd_read_status(flash, &data[0]);
       if (ret < 0)
           return ret;

       /*
        * PAGE SIZE Page Size, bit 0.
        * 0 Device is configured for standard DataFlash page size (264 bytes).
        * 1 Device is configured for ?power of 2? binary page size (256
bytes).
        */
       if (wc == SPI_FLASH_PAGE_256) {
           /* Already 256? */
           if (data[0] & 1)
               return 0;
       } else if (wc == SPI_FLASH_PAGE_264) {
           /* Already 264? */
           if ((data[0] & 1) == 0)
               return 0;
       } else {
           debug("Unsupport page configuration!\n");
           return -1;
       }

       /*
        * 3D, 2A, 80, A6 command seq will configure flash page size 256.
        * 3D, 2A, 80, A7 command seq will configure flash page size 264.
        */
       cmd = 0x3D;
       if (wc == SPI_FLASH_PAGE_256)
           data[2] = 0xA6;
       else if (wc == SPI_FLASH_PAGE_264)
           data[2] = 0xA7;
       data[1] = 0x80;
       data[0] = 0x2A;
       ret = spi_flash_write_common(flash, &cmd, 1, data, 3);
       if (ret) {
           debug("SF: fail to write config register\n");
           return ret;
       }

       /* Check again  the page size*/
      xxxxxxxxxxxxxxxxxx

       return 0;
}

#endif

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Or I will add a AT45DB special flash driver under Driver Model.

Regards,
Peng.

.

Regards,
Peng.