Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mtd/*: drop .write() if .write_page() is implemented #15380

Merged
merged 11 commits into from
Dec 13, 2023
Prev Previous commit
Next Next commit
drivers/mtd_spi_nor: drop .write()
The old .write() function is only used as a fall-back if .write_page()
is not implemented.
We can drop it.
  • Loading branch information
benpicco committed Dec 13, 2023
commit ea105d34ece9402d9bdff38e31a77abc4abcd74e
40 changes: 0 additions & 40 deletions drivers/mtd_spi_nor/mtd_spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,45 +621,6 @@ static int mtd_spi_nor_read(mtd_dev_t *mtd, void *dest, uint32_t addr, uint32_t
return 0;
}

static int mtd_spi_nor_write(mtd_dev_t *mtd, const void *src, uint32_t addr, uint32_t size)
{
uint32_t total_size = mtd->page_size * mtd->pages_per_sector * mtd->sector_count;

DEBUG("mtd_spi_nor_write: %p, %p, 0x%" PRIx32 ", 0x%" PRIx32 "\n",
(void *)mtd, src, addr, size);
if (size == 0) {
return 0;
}
const mtd_spi_nor_t *dev = (mtd_spi_nor_t *)mtd;
if (size > mtd->page_size) {
DEBUG("mtd_spi_nor_write: ERR: page program >1 page (%" PRIu32 ")!\n", mtd->page_size);
return -EOVERFLOW;
}
if (dev->page_addr_mask &&
((addr & dev->page_addr_mask) != ((addr + size - 1) & dev->page_addr_mask))) {
DEBUG("mtd_spi_nor_write: ERR: page program spans page boundary!\n");
return -EOVERFLOW;
}
if (addr + size > total_size) {
return -EOVERFLOW;
}

mtd_spi_acquire(dev);

/* write enable */
mtd_spi_cmd(dev, dev->params->opcode->wren);

/* Page program */
mtd_spi_cmd_addr_write(dev, dev->params->opcode->page_program, addr, src, size);

/* waiting for the command to complete before returning */
wait_for_write_complete(dev, 0);

mtd_spi_release(dev);

return 0;
}

static int mtd_spi_nor_write_page(mtd_dev_t *mtd, const void *src, uint32_t page, uint32_t offset,
uint32_t size)
{
Expand Down Expand Up @@ -768,7 +729,6 @@ static int mtd_spi_nor_erase(mtd_dev_t *mtd, uint32_t addr, uint32_t size)
const mtd_desc_t mtd_spi_nor_driver = {
.init = mtd_spi_nor_init,
.read = mtd_spi_nor_read,
.write = mtd_spi_nor_write,
.write_page = mtd_spi_nor_write_page,
.erase = mtd_spi_nor_erase,
.power = mtd_spi_nor_power,
Expand Down