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
drivers: flash: add Andes qspi-nor driver #58718
Conversation
0fdad92
to
3ab2d14
Compare
3ab2d14
to
359b497
Compare
@@ -26,7 +26,8 @@ | |||
zephyr,console = &uart1; | |||
zephyr,shell-uart = &uart1; | |||
zephyr,sram = &dram; | |||
zephyr,flash = &flash0; | |||
zephyr,flash = &mx25u16; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
359b497
to
4813260
Compare
0502f7f
to
562b698
Compare
drivers/flash/flash_andes_qspi.c
Outdated
* @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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
drivers/flash/flash_andes_qspi.c
Outdated
|
||
/* Don't write across a page boundary */ | ||
if (((addr + to_write - 1U) / page_size) | ||
!= (addr / page_size)) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
81682d1
to
9d0898c
Compare
description: | ||
Properties supporting Zephyr qspi-nor flash driver control of | ||
flash memories using the standard M25P80-based command set. | ||
|
||
compatible: "andestech,qspi-nor" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compatible
before description
drivers/flash/Kconfig.andes
Outdated
select FLASH_HAS_PAGE_LAYOUT | ||
select FLASH_JESD216 | ||
select FLASH_HAS_DRIVER_ENABLED | ||
depends on !(SPI_NOR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless (
)
drivers/flash/flash_andes_qspi.c
Outdated
uint32_t tx_fifo_size; | ||
uint32_t rx_fifo_size; | ||
uint8_t *tx_buf; | ||
uint8_t *rx_buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odd indentation
drivers/flash/flash_andes_qspi.c
Outdated
#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) |
There was a problem hiding this comment.
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.
drivers/flash/flash_andes_qspi.c
Outdated
#if defined(CONFIG_FLASH_ANDES_QSPI_SFDP_RUNTIME) \ | ||
|| defined(CONFIG_FLASH_JESD216_API) |
There was a problem hiding this comment.
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(....)
drivers/flash/flash_andes_qspi.c
Outdated
int ret; | ||
|
||
ret = flash_andes_qspi_cmd_write(dev, (write_protect) ? | ||
FLASH_ANDES_CMD_WRDI : FLASH_ANDES_CMD_WREN); | ||
|
||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret
not needed
drivers/flash/flash_andes_qspi.h
Outdated
#define FLASH_ANDES_CMD_WRDI 0x04 /* Write disable */ | ||
#define FLASH_ANDES_CMD_PP 0x02 /* Page program */ |
There was a problem hiding this comment.
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
drivers/flash/flash_andes_qspi.h
Outdated
#define REG_TIMIN 0x40 | ||
#define REG_CONFIG 0x7c | ||
|
||
#define QSPI_BASE (((const struct flash_andes_qspi_config *) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QSPI_BASE(dev)
There was a problem hiding this comment.
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.
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>
9d0898c
to
0538eb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM
drivers/flash/flash_andes_qspi.c
Outdated
if ((addr < 0 || addr >= flash_size || | ||
size > flash_size || (flash_size - addr) < size)) { |
There was a problem hiding this comment.
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
..
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
0538eb3
to
d846c8b
Compare
There was a problem hiding this 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.
if (size == 0) { | ||
return 0; | ||
} |
There was a problem hiding this comment.
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
.
drivers/flash/flash_andes_qspi.c
Outdated
if ((addr < 0 || addr >= flash_size || | ||
size > flash_size || (flash_size - addr) < size)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right.
@wtlee1995 can you update supported features for https://docs.zephyrproject.org/latest/boards/riscv/adp_xc7k_ae350/doc/index.html#supported-features? |
Hi @kartben, |
Added Andes qspi-nor driver which supports jedec sfdp parameters on adp_xc7k_ae350 board.
Signed-off-by: Wei-Tai Lee wtlee@andestech.com