Re: [U-Boot] [PATCH v5 1/4] dm: sf: Add Atmel DataFlash spi flash driver

2015-06-19 Thread Chakra D
On Tue, May 19, 2015 at 8:26 AM, Wang Haikun haikun.w...@freescale.com
wrote:

 On 5/18/2015 9:28 PM, Haikun Wang wrote:
  Atmel DataFlash chips have commands different from common spi
  flash commands.
  Atmel DataFlash also have special page-size.
  This driver add support for accessing Atmel DataFlash.
  It is based on the Driver Model.
  Example:
  = sf probe 1:0
  SPI DataFlash: Detected AT45DB021B with page size 264 Bytes, erase size
 264 Bytes, total 264 KiB, revision d
  = sf erase 0 42000
  SF: 270336 bytes @ 0x0 Erased: OK
  = mw.l 8200 45444342 2
  = sf write 8200 0 42000
  SF: 270336 bytes @ 0x0 Written: OK
  = sf read 8300 0 42000
  SF: 270336 bytes @ 0x0 Read: OK
  = cmp.b 8200 8300 42000
  Total of 270336 byte(s) were the same
 
  Signed-off-by: Haikun Wang haikun.w...@freescale.com
  ---
  Verified with AT45DB021B on LS1021AQDS.
  Changes in v5:
  - Change CONFIG_DM_SF_DATAFLASH to CONFIG_SF_DATAFLASH
 
  Changes in v4:
  - Use dev_get_priv and dev_get_uclass_priv
  - Add test log to commit message
 
  Changes in v3:
  - 1. Rename file spi_dataflash.c to sf_dataflash.c
  - 2. Add comment for array dataflash_data
 
  Changes in v2:
  - 1. Correct comment style
  - 2. Use get_timer in dataflash_waitready to check whether timeout
  - 3. Remove struct spi_flash * in struct dataflash, and get it from
 udevice-uclass_priv
  - 4. Replace spi_flash_write_common with spi_flash_cmd_write
  - 5. Replace spi_flash_read with spi_flash_cmd_read
  - 6. Change type of varible status form char to u8 in dataflash_status
  - 7. Change add_dataflash's argument type due to change 3
  - 8. Add claim_bus and release_bus in erase/write/read due to change 4
  5
 
  Changes in v1: None
drivers/mtd/spi/Makefile   |   1 +
drivers/mtd/spi/sf_dataflash.c | 711
 +
2 files changed, 712 insertions(+)
create mode 100644 drivers/mtd/spi/sf_dataflash.c



 Reviewed by: Chakra Divi cd...@openedev.com

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v5 1/4] dm: sf: Add Atmel DataFlash spi flash driver

2015-05-18 Thread Haikun Wang
Atmel DataFlash chips have commands different from common spi
flash commands.
Atmel DataFlash also have special page-size.
This driver add support for accessing Atmel DataFlash.
It is based on the Driver Model.
Example:
= sf probe 1:0
SPI DataFlash: Detected AT45DB021B with page size 264 Bytes, erase size 264 
Bytes, total 264 KiB, revision d
= sf erase 0 42000
SF: 270336 bytes @ 0x0 Erased: OK
= mw.l 8200 45444342 2
= sf write 8200 0 42000
SF: 270336 bytes @ 0x0 Written: OK
= sf read 8300 0 42000
SF: 270336 bytes @ 0x0 Read: OK
= cmp.b 8200 8300 42000
Total of 270336 byte(s) were the same

Signed-off-by: Haikun Wang haikun.w...@freescale.com
---
Verified with AT45DB021B on LS1021AQDS.
Changes in v5:
- Change CONFIG_DM_SF_DATAFLASH to CONFIG_SF_DATAFLASH

Changes in v4:
- Use dev_get_priv and dev_get_uclass_priv
- Add test log to commit message

Changes in v3:
- 1. Rename file spi_dataflash.c to sf_dataflash.c
- 2. Add comment for array dataflash_data

Changes in v2:
- 1. Correct comment style
- 2. Use get_timer in dataflash_waitready to check whether timeout
- 3. Remove struct spi_flash * in struct dataflash, and get it from 
udevice-uclass_priv
- 4. Replace spi_flash_write_common with spi_flash_cmd_write 
- 5. Replace spi_flash_read with spi_flash_cmd_read 
- 6. Change type of varible status form char to u8 in dataflash_status
- 7. Change add_dataflash's argument type due to change 3
- 8. Add claim_bus and release_bus in erase/write/read due to change 4  5

Changes in v1: None
 drivers/mtd/spi/Makefile   |   1 +
 drivers/mtd/spi/sf_dataflash.c | 711 +
 2 files changed, 712 insertions(+)
 create mode 100644 drivers/mtd/spi/sf_dataflash.c

diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
index c61b784..87f20bc 100644
--- a/drivers/mtd/spi/Makefile
+++ b/drivers/mtd/spi/Makefile
@@ -15,6 +15,7 @@ endif
 #ifndef CONFIG_DM_SPI
 obj-$(CONFIG_SPI_FLASH) += sf_probe.o
 #endif
+obj-$(CONFIG_SF_DATAFLASH) += sf_dataflash.o
 obj-$(CONFIG_CMD_SF) += sf.o
 obj-$(CONFIG_SPI_FLASH) += sf_ops.o sf_params.o
 obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
diff --git a/drivers/mtd/spi/sf_dataflash.c b/drivers/mtd/spi/sf_dataflash.c
new file mode 100644
index 000..d287db8
--- /dev/null
+++ b/drivers/mtd/spi/sf_dataflash.c
@@ -0,0 +1,711 @@
+/*
+ *
+ * Atmel DataFlash probing
+ *
+ * Copyright (C) 2004-2009, 2015 Freescale Semiconductor, Inc.
+ * Haikun Wang (haikun.w...@freescale.com)
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+*/
+#include common.h
+#include dm.h
+#include errno.h
+#include fdtdec.h
+#include spi.h
+#include spi_flash.h
+#include div64.h
+#include linux/err.h
+#include linux/math64.h
+
+#include sf_internal.h
+
+/*
+ * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
+ * each chip, which may be used for double buffered I/O; but this driver
+ * doesn't (yet) use these for any kind of i/o overlap or prefetching.
+ *
+ * Sometimes DataFlash is packaged in MMC-format cards, although the
+ * MMC stack can't (yet?) distinguish between MMC and DataFlash
+ * protocols during enumeration.
+ */
+
+/* reads can bypass the buffers */
+#define OP_READ_CONTINUOUS 0xE8
+#define OP_READ_PAGE   0xD2
+
+/* group B requests can run even while status reports busy */
+#define OP_READ_STATUS 0xD7/* group B */
+
+/* move data between host and buffer */
+#define OP_READ_BUFFER10xD4/* group B */
+#define OP_READ_BUFFER20xD6/* group B */
+#define OP_WRITE_BUFFER1   0x84/* group B */
+#define OP_WRITE_BUFFER2   0x87/* group B */
+
+/* erasing flash */
+#define OP_ERASE_PAGE  0x81
+#define OP_ERASE_BLOCK 0x50
+
+/* move data between buffer and flash */
+#define OP_TRANSFER_BUF1   0x53
+#define OP_TRANSFER_BUF2   0x55
+#define OP_MREAD_BUFFER1   0xD4
+#define OP_MREAD_BUFFER2   0xD6
+#define OP_MWERASE_BUFFER1 0x83
+#define OP_MWERASE_BUFFER2 0x86
+#define OP_MWRITE_BUFFER1  0x88/* sector must be pre-erased */
+#define OP_MWRITE_BUFFER2  0x89/* sector must be pre-erased */
+
+/* write to buffer, then write-erase to flash */
+#define OP_PROGRAM_VIA_BUF10x82
+#define OP_PROGRAM_VIA_BUF20x85
+
+/* compare buffer to flash */
+#define OP_COMPARE_BUF10x60
+#define OP_COMPARE_BUF20x61
+
+/* read flash to buffer, then write-erase to flash */
+#define OP_REWRITE_VIA_BUF10x58
+#define OP_REWRITE_VIA_BUF20x59
+
+/*
+ * newer chips report JEDEC manufacturer and device IDs; chip
+ * serial number and OTP bits; and per-sector writeprotect.
+ */
+#define OP_READ_ID 0x9F
+#define OP_READ_SECURITY   0x77
+#define OP_WRITE_SECURITY_REVC 0x9A
+#define OP_WRITE_SECURITY  0x9B/* revision D */
+
+
+struct dataflash {
+   uint8_t command[16];
+   unsigned short  page_offset;/* offset in flash address */
+};
+

Re: [U-Boot] [PATCH v5 1/4] dm: sf: Add Atmel DataFlash spi flash driver

2015-05-18 Thread Wang Haikun
On 5/18/2015 9:28 PM, Haikun Wang wrote:
 Atmel DataFlash chips have commands different from common spi
 flash commands.
 Atmel DataFlash also have special page-size.
 This driver add support for accessing Atmel DataFlash.
 It is based on the Driver Model.
 Example:
 = sf probe 1:0
 SPI DataFlash: Detected AT45DB021B with page size 264 Bytes, erase size 264 
 Bytes, total 264 KiB, revision d
 = sf erase 0 42000
 SF: 270336 bytes @ 0x0 Erased: OK
 = mw.l 8200 45444342 2
 = sf write 8200 0 42000
 SF: 270336 bytes @ 0x0 Written: OK
 = sf read 8300 0 42000
 SF: 270336 bytes @ 0x0 Read: OK
 = cmp.b 8200 8300 42000
 Total of 270336 byte(s) were the same

 Signed-off-by: Haikun Wang haikun.w...@freescale.com
 ---
 Verified with AT45DB021B on LS1021AQDS.
 Changes in v5:
 - Change CONFIG_DM_SF_DATAFLASH to CONFIG_SF_DATAFLASH

 Changes in v4:
 - Use dev_get_priv and dev_get_uclass_priv
 - Add test log to commit message

 Changes in v3:
 - 1. Rename file spi_dataflash.c to sf_dataflash.c
 - 2. Add comment for array dataflash_data

 Changes in v2:
 - 1. Correct comment style
 - 2. Use get_timer in dataflash_waitready to check whether timeout
 - 3. Remove struct spi_flash * in struct dataflash, and get it from 
 udevice-uclass_priv
 - 4. Replace spi_flash_write_common with spi_flash_cmd_write
 - 5. Replace spi_flash_read with spi_flash_cmd_read
 - 6. Change type of varible status form char to u8 in dataflash_status
 - 7. Change add_dataflash's argument type due to change 3
 - 8. Add claim_bus and release_bus in erase/write/read due to change 4  5

 Changes in v1: None
   drivers/mtd/spi/Makefile   |   1 +
   drivers/mtd/spi/sf_dataflash.c | 711 
 +
   2 files changed, 712 insertions(+)
   create mode 100644 drivers/mtd/spi/sf_dataflash.c
+ York Sun
Help him review the rest patches of this set.

 diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile
 index c61b784..87f20bc 100644
 --- a/drivers/mtd/spi/Makefile
 +++ b/drivers/mtd/spi/Makefile
 @@ -15,6 +15,7 @@ endif
   #ifndef CONFIG_DM_SPI
   obj-$(CONFIG_SPI_FLASH) += sf_probe.o
   #endif
 +obj-$(CONFIG_SF_DATAFLASH) += sf_dataflash.o
   obj-$(CONFIG_CMD_SF) += sf.o
   obj-$(CONFIG_SPI_FLASH) += sf_ops.o sf_params.o
   obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o
 diff --git a/drivers/mtd/spi/sf_dataflash.c b/drivers/mtd/spi/sf_dataflash.c
 new file mode 100644
 index 000..d287db8
 --- /dev/null
 +++ b/drivers/mtd/spi/sf_dataflash.c
 @@ -0,0 +1,711 @@
 +/*
 + *
 + * Atmel DataFlash probing
 + *
 + * Copyright (C) 2004-2009, 2015 Freescale Semiconductor, Inc.
 + * Haikun Wang (haikun.w...@freescale.com)
 + *
 + * SPDX-License-Identifier:  GPL-2.0+
 +*/
 +#include common.h
 +#include dm.h
 +#include errno.h
 +#include fdtdec.h
 +#include spi.h
 +#include spi_flash.h
 +#include div64.h
 +#include linux/err.h
 +#include linux/math64.h
 +
 +#include sf_internal.h
 +
 +/*
 + * DataFlash is a kind of SPI flash.  Most AT45 chips have two buffers in
 + * each chip, which may be used for double buffered I/O; but this driver
 + * doesn't (yet) use these for any kind of i/o overlap or prefetching.
 + *
 + * Sometimes DataFlash is packaged in MMC-format cards, although the
 + * MMC stack can't (yet?) distinguish between MMC and DataFlash
 + * protocols during enumeration.
 + */
 +
 +/* reads can bypass the buffers */
 +#define OP_READ_CONTINUOUS   0xE8
 +#define OP_READ_PAGE 0xD2
 +
 +/* group B requests can run even while status reports busy */
 +#define OP_READ_STATUS   0xD7/* group B */
 +
 +/* move data between host and buffer */
 +#define OP_READ_BUFFER1  0xD4/* group B */
 +#define OP_READ_BUFFER2  0xD6/* group B */
 +#define OP_WRITE_BUFFER1 0x84/* group B */
 +#define OP_WRITE_BUFFER2 0x87/* group B */
 +
 +/* erasing flash */
 +#define OP_ERASE_PAGE0x81
 +#define OP_ERASE_BLOCK   0x50
 +
 +/* move data between buffer and flash */
 +#define OP_TRANSFER_BUF1 0x53
 +#define OP_TRANSFER_BUF2 0x55
 +#define OP_MREAD_BUFFER1 0xD4
 +#define OP_MREAD_BUFFER2 0xD6
 +#define OP_MWERASE_BUFFER1   0x83
 +#define OP_MWERASE_BUFFER2   0x86
 +#define OP_MWRITE_BUFFER10x88/* sector must be pre-erased */
 +#define OP_MWRITE_BUFFER20x89/* sector must be pre-erased */
 +
 +/* write to buffer, then write-erase to flash */
 +#define OP_PROGRAM_VIA_BUF1  0x82
 +#define OP_PROGRAM_VIA_BUF2  0x85
 +
 +/* compare buffer to flash */
 +#define OP_COMPARE_BUF1  0x60
 +#define OP_COMPARE_BUF2  0x61
 +
 +/* read flash to buffer, then write-erase to flash */
 +#define OP_REWRITE_VIA_BUF1  0x58
 +#define OP_REWRITE_VIA_BUF2  0x59
 +
 +/*
 + * newer chips report JEDEC manufacturer and device IDs; chip
 + * serial number and OTP bits; and per-sector writeprotect.
 + */
 +#define OP_READ_ID   0x9F
 +#define OP_READ_SECURITY 0x77
 +#define 

Re: [U-Boot] [PATCH v5 1/4] dm: sf: Add Atmel DataFlash spi flash driver

2015-05-18 Thread Simon Glass
On 18 May 2015 at 07:24, Haikun Wang haikun.w...@freescale.com wrote:
 Atmel DataFlash chips have commands different from common spi
 flash commands.
 Atmel DataFlash also have special page-size.
 This driver add support for accessing Atmel DataFlash.
 It is based on the Driver Model.
 Example:
 = sf probe 1:0
 SPI DataFlash: Detected AT45DB021B with page size 264 Bytes, erase size 264 
 Bytes, total 264 KiB, revision d
 = sf erase 0 42000
 SF: 270336 bytes @ 0x0 Erased: OK
 = mw.l 8200 45444342 2
 = sf write 8200 0 42000
 SF: 270336 bytes @ 0x0 Written: OK
 = sf read 8300 0 42000
 SF: 270336 bytes @ 0x0 Read: OK
 = cmp.b 8200 8300 42000
 Total of 270336 byte(s) were the same

 Signed-off-by: Haikun Wang haikun.w...@freescale.com

Reviewed-by: Simon Glass s...@chromium.org
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot