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

drivers: flash: add Andes qspi-nor driver #58718

Merged
merged 4 commits into from Aug 3, 2023

Conversation

wtlee1995
Copy link
Contributor

Added Andes qspi-nor driver which supports jedec sfdp parameters on adp_xc7k_ae350 board.

Signed-off-by: Wei-Tai Lee wtlee@andestech.com

@zephyrbot zephyrbot added area: RISCV RISCV Architecture (32-bit & 64-bit) area: Devicetree Binding PR modifies or adds a Device Tree binding area: Flash labels Jun 1, 2023
@wtlee1995 wtlee1995 force-pushed the andes_flash_upstream branch 2 times, most recently from 0fdad92 to 3ab2d14 Compare June 2, 2023 10:03
@@ -26,7 +26,8 @@
zephyr,console = &uart1;
zephyr,shell-uart = &uart1;
zephyr,sram = &dram;
zephyr,flash = &flash0;
zephyr,flash = &mx25u16;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit message is confusing - is flash or i2c driver being supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've edited the commit message.

* @param addr The address to send
* @param data The buffer to store or read the value
* @param length The size of the buffer
* @return 0 on success, negative errno code otherwise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to actually always return 0 - maybe the goto exit below need to set a negative return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I haven't identified the specific error case that this function should handle, I have temporarily set it to always return 0.
I've temporarily removed the comment ', negative errno code otherwise' until I identify the case that requires the function to return an error code.

(0x2 << TFMAT_ADDR_LEN_OFFSET)), QSPI_TFMAT(dev));
sys_write32(addr, QSPI_ADDR(dev));
/* Address phase enable */
tctrl |= TCTRL_ADDR_EN_MSK;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if is_addressed is true and length is 0? It would exit early but it would had set the "address" access. Would something bad happen on next access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wouldn't. is_addressed is true and length is 0 is a common usage for andes flash driver.

Using Andes flash controller IP, I can split a spi transaction into three phases: command, address, and data. is_addressed means whether the address phase exists. length means the length of the data phase.
Some flash commands contain only the command and address phase, like erase commands, which don't contain data phase.


/* Don't write across a page boundary */
if (((addr + to_write - 1U) / page_size)
!= (addr / page_size)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really peculiar indentation... maybe != should follow the second ( above?

release_device(dev);
return ret;
}
static int flash_andes_qspi_erase(const struct device *dev,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing newline before this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've edited it.

@wtlee1995 wtlee1995 force-pushed the andes_flash_upstream branch 2 times, most recently from 81682d1 to 9d0898c Compare July 21, 2023 01:24
Comment on lines 7 to 11
description:
Properties supporting Zephyr qspi-nor flash driver control of
flash memories using the standard M25P80-based command set.

compatible: "andestech,qspi-nor"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compatible before description

select FLASH_HAS_PAGE_LAYOUT
select FLASH_JESD216
select FLASH_HAS_DRIVER_ENABLED
depends on !(SPI_NOR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useless ( )

Comment on lines 56 to 59
uint32_t tx_fifo_size;
uint32_t rx_fifo_size;
uint8_t *tx_buf;
uint8_t *rx_buf;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd indentation

Comment on lines 200 to 210
#define flash_andes_qspi_cmd_read(dev, opcode, dest, length) \
flash_andes_qspi_access(dev, opcode, 0, 0, dest, length)
#define flash_andes_qspi_cmd_addr_read(dev, opcode, addr, dest, length) \
flash_andes_qspi_access(dev, opcode, \
ANDES_ACCESS_ADDRESSED, addr, dest, length)
#define flash_andes_qspi_cmd_write(dev, opcode) \
flash_andes_qspi_access(dev, opcode, ANDES_ACCESS_WRITE, 0, NULL, 0)
#define flash_andes_qspi_cmd_addr_write(dev, opcode, addr, src, length) \
flash_andes_qspi_access(dev, opcode, \
ANDES_ACCESS_WRITE | ANDES_ACCESS_ADDRESSED, \
addr, (void *)src, length)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this on top, and make this looking better please.

Comment on lines 247 to 248
#if defined(CONFIG_FLASH_ANDES_QSPI_SFDP_RUNTIME) \
|| defined(CONFIG_FLASH_JESD216_API)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, make the code looks nicer:

#if defined(....) || \
    defined(....) 

Comment on lines 458 to 463
int ret;

ret = flash_andes_qspi_cmd_write(dev, (write_protect) ?
FLASH_ANDES_CMD_WRDI : FLASH_ANDES_CMD_WREN);

return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret not needed

Comment on lines 13 to 14
#define FLASH_ANDES_CMD_WRDI 0x04 /* Write disable */
#define FLASH_ANDES_CMD_PP 0x02 /* Page program */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the indentation here and in this file

#define REG_TIMIN 0x40
#define REG_CONFIG 0x7c

#define QSPI_BASE (((const struct flash_andes_qspi_config *) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QSPI_BASE(dev)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!
I've fixed the problems.

drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
drivers/flash/flash_andes_qspi.c Outdated Show resolved Hide resolved
Support flash driver on Andes adp_xc7k_ae350.

Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Add dts binding for Andes qspi-nor.

Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
carlocaione
carlocaione previously approved these changes Aug 2, 2023
Copy link
Collaborator

@carlocaione carlocaione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM

Comment on lines 310 to 311
if ((addr < 0 || addr >= flash_size ||
size > flash_size || (flash_size - addr) < size)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am really sorry, this is my mistake: the last condition should be (flash_size - addr) > size and you can drop the size > flash_size..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(flash_size - addr) < size) is the case that if I write a chunk of data that exceed the flash size. And I should return error code in the case.
Following is the example: flash_size is 4KB, addr is 0, and size is 5KB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Drop the size > flash_size

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.

Add flash driver for Andes qspi.

Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Add adp_xc7k_ae350 support in spi_flash driver sample

Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment left. Otherwise OK.

Comment on lines +340 to +342
if (size == 0) {
return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be before checking for error condition: if there is no work to do there is no reason to error out first. In read, write and erase.

Comment on lines 310 to 311
if ((addr < 0 || addr >= flash_size ||
size > flash_size || (flash_size - addr) < size)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.

@carlescufi carlescufi merged commit e6d6df5 into zephyrproject-rtos:main Aug 3, 2023
18 checks passed
@wtlee1995 wtlee1995 deleted the andes_flash_upstream branch August 9, 2023 07:54
@kartben
Copy link
Collaborator

kartben commented Aug 11, 2023

@wtlee1995
Copy link
Contributor Author

Hi @kartben,
Two drivers for adp_xc7k_ae350 are currently under review. Once they are merged, we will proceed to update the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Flash area: RISCV RISCV Architecture (32-bit & 64-bit)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants