mtd: docg3: add erase functions
Add erase capability to the docg3 driver. The erase block is made of 2 physical blocks, as both share all 64 pages. That makes an erase block of at least 64 kBytes. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Reviewed-by: Ivan Djelic <ivan.djelic@parrot.com> Reviewed-by: Mike Dunn <mikedunn@newsguy.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
parent
fb50b58e48
commit
de03cd716b
1 changed files with 90 additions and 0 deletions
|
@ -1032,6 +1032,96 @@ static int doc_write_erase_wait_status(struct docg3 *docg3)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* doc_erase_block - Erase a couple of blocks
|
||||||
|
* @docg3: the device
|
||||||
|
* @block0: the first block to erase (leftmost plane)
|
||||||
|
* @block1: the second block to erase (rightmost plane)
|
||||||
|
*
|
||||||
|
* Erase both blocks, and return operation status
|
||||||
|
*
|
||||||
|
* Returns 0 if erase successful, -EIO if erase issue, -ETIMEOUT if chip not
|
||||||
|
* ready for too long
|
||||||
|
*/
|
||||||
|
static int doc_erase_block(struct docg3 *docg3, int block0, int block1)
|
||||||
|
{
|
||||||
|
int ret, sector;
|
||||||
|
|
||||||
|
doc_dbg("doc_erase_block(blocks=(%d,%d))\n", block0, block1);
|
||||||
|
ret = doc_reset_seq(docg3);
|
||||||
|
if (ret)
|
||||||
|
return -EIO;
|
||||||
|
|
||||||
|
doc_set_reliable_mode(docg3);
|
||||||
|
doc_flash_sequence(docg3, DOC_SEQ_ERASE);
|
||||||
|
|
||||||
|
sector = block0 << DOC_ADDR_BLOCK_SHIFT;
|
||||||
|
doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR);
|
||||||
|
doc_setup_addr_sector(docg3, sector);
|
||||||
|
sector = block1 << DOC_ADDR_BLOCK_SHIFT;
|
||||||
|
doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR);
|
||||||
|
doc_setup_addr_sector(docg3, sector);
|
||||||
|
doc_delay(docg3, 1);
|
||||||
|
|
||||||
|
doc_flash_command(docg3, DOC_CMD_ERASECYCLE2);
|
||||||
|
doc_delay(docg3, 2);
|
||||||
|
|
||||||
|
if (is_prot_seq_error(docg3)) {
|
||||||
|
doc_err("Erase blocks %d,%d error\n", block0, block1);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc_write_erase_wait_status(docg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* doc_erase - Erase a portion of the chip
|
||||||
|
* @mtd: the device
|
||||||
|
* @info: the erase info
|
||||||
|
*
|
||||||
|
* Erase a bunch of contiguous blocks, by pairs, as a "mtd" page of 1024 is
|
||||||
|
* split into 2 pages of 512 bytes on 2 contiguous blocks.
|
||||||
|
*
|
||||||
|
* Returns 0 if erase successful, -EINVAL if adressing error, -EIO if erase
|
||||||
|
* issue
|
||||||
|
*/
|
||||||
|
static int doc_erase(struct mtd_info *mtd, struct erase_info *info)
|
||||||
|
{
|
||||||
|
struct docg3 *docg3 = mtd->priv;
|
||||||
|
uint64_t len;
|
||||||
|
int block0, block1, page, ret, ofs = 0;
|
||||||
|
|
||||||
|
doc_dbg("doc_erase(from=%lld, len=%lld\n", info->addr, info->len);
|
||||||
|
doc_set_device_id(docg3, docg3->device_id);
|
||||||
|
|
||||||
|
info->state = MTD_ERASE_PENDING;
|
||||||
|
calc_block_sector(info->addr + info->len,
|
||||||
|
&block0, &block1, &page, &ofs);
|
||||||
|
ret = -EINVAL;
|
||||||
|
if (block1 > docg3->max_block || page || ofs)
|
||||||
|
goto reset_err;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
calc_block_sector(info->addr, &block0, &block1, &page, &ofs);
|
||||||
|
doc_set_reliable_mode(docg3);
|
||||||
|
for (len = info->len; !ret && len > 0; len -= mtd->erasesize) {
|
||||||
|
info->state = MTD_ERASING;
|
||||||
|
ret = doc_erase_block(docg3, block0, block1);
|
||||||
|
block0 += 2;
|
||||||
|
block1 += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto reset_err;
|
||||||
|
|
||||||
|
info->state = MTD_ERASE_DONE;
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
reset_err:
|
||||||
|
info->state = MTD_ERASE_FAILED;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* doc_write_page - Write a single page to the chip
|
* doc_write_page - Write a single page to the chip
|
||||||
* @docg3: the device
|
* @docg3: the device
|
||||||
|
|
Loading…
Reference in a new issue