diff mbox

[U-Boot,v1,06/10] spl, nand, atmel_nand: add erase one block function

Message ID 1412142894-997-7-git-send-email-hs@denx.de
State Superseded, archived
Delegated to: Andreas Bießmann
Headers show

Commit Message

Heiko Schocher Oct. 1, 2014, 5:54 a.m. UTC
erase one nand block in spl code. keep it simple, as size matters
This is used on the upcoming taurus spl support.

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Andreas Bießmann <andreas.devel@googlemail.com>
Cc: Bo Shen <voice.shen@atmel.com>
Cc: Scott Wood <scottwood@freescale.com>
Cc: Josh Wu <josh.wu@atmel.com>
---
 drivers/mtd/nand/atmel_nand.c | 33 +++++++++++++++++++++++++++++++++
 include/linux/mtd/nand.h      |  1 +
 2 files changed, 34 insertions(+)

Comments

Scott Wood Oct. 2, 2014, 1:17 a.m. UTC | #1
On Wed, 2014-10-01 at 07:54 +0200, Heiko Schocher wrote:
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index 8438490..ee2c3fe 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -1020,5 +1020,6 @@ void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
>  void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
>  void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
>  uint8_t nand_read_byte(struct mtd_info *mtd);
> +int nand_erase_one(int block, int page);

This doesn't belong under the heading "Standard NAND functions from
nand_base.c", and probably doesn't belong in this file.

-Scott
Heiko Schocher Oct. 2, 2014, 5:21 a.m. UTC | #2
Hello Scott,

Am 02.10.2014 03:17, schrieb Scott Wood:
> On Wed, 2014-10-01 at 07:54 +0200, Heiko Schocher wrote:
>> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
>> index 8438490..ee2c3fe 100644
>> --- a/include/linux/mtd/nand.h
>> +++ b/include/linux/mtd/nand.h
>> @@ -1020,5 +1020,6 @@ void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
>>   void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
>>   void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
>>   uint8_t nand_read_byte(struct mtd_info *mtd);
>> +int nand_erase_one(int block, int page);
>
> This doesn't belong under the heading "Standard NAND functions from
> nand_base.c", and probably doesn't belong in this file.

Ah, ok. Where would be a correct place for it?

bye,
Heiko
Scott Wood Oct. 2, 2014, 11:45 p.m. UTC | #3
On Thu, 2014-10-02 at 07:21 +0200, Heiko Schocher wrote:
> Hello Scott,
> 
> Am 02.10.2014 03:17, schrieb Scott Wood:
> > On Wed, 2014-10-01 at 07:54 +0200, Heiko Schocher wrote:
> >> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> >> index 8438490..ee2c3fe 100644
> >> --- a/include/linux/mtd/nand.h
> >> +++ b/include/linux/mtd/nand.h
> >> @@ -1020,5 +1020,6 @@ void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
> >>   void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
> >>   void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
> >>   uint8_t nand_read_byte(struct mtd_info *mtd);
> >> +int nand_erase_one(int block, int page);
> >
> > This doesn't belong under the heading "Standard NAND functions from
> > nand_base.c", and probably doesn't belong in this file.
> 
> Ah, ok. Where would be a correct place for it?

If you don't want to make it atmel-specific, put an "spl" in the name
and put it in include/nand.h.

-Scott
diff mbox

Patch

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index d506e42..276d820 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -1274,6 +1274,39 @@  static int nand_read_page(int block, int page, void *dst)
 
 	return 0;
 }
+
+int nand_erase_one(int block, int page)
+{
+	struct nand_chip *this = mtd.priv;
+	void (*hwctrl)(struct mtd_info *mtd, int cmd,
+			unsigned int ctrl) = this->cmd_ctrl;
+	int page_addr;
+
+	if (nand_chip.select_chip)
+		nand_chip.select_chip(&mtd, 0);
+
+	page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT;
+	hwctrl(&mtd, NAND_CMD_ERASE1, NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+	/* Row address */
+	hwctrl(&mtd, (page_addr & 0xff), NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+	hwctrl(&mtd, ((page_addr >> 8) & 0xff),
+	       NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+#ifdef CONFIG_SYS_NAND_5_ADDR_CYCLE
+	/* One more address cycle for devices > 128MiB */
+	hwctrl(&mtd, (page_addr >> 16) & 0x0f,
+	       NAND_CTRL_ALE | NAND_CTRL_CHANGE);
+#endif
+
+	hwctrl(&mtd, NAND_CMD_ERASE2, NAND_CTRL_CLE | NAND_CTRL_CHANGE);
+	udelay(2000);
+
+	while (!this->dev_ready(&mtd))
+		;
+
+	nand_deselect();
+
+	return 0;
+}
 #else
 static int nand_read_page(int block, int page, void *dst)
 {
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 8438490..ee2c3fe 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -1020,5 +1020,6 @@  void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
 void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
 void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
 uint8_t nand_read_byte(struct mtd_info *mtd);
+int nand_erase_one(int block, int page);
 #endif
 #endif /* __LINUX_MTD_NAND_H */